Esempio n. 1
0
 /**
  * Set URL
  *
  * @param   peer.URL url object
  */
 public function setUrl(URL $url)
 {
     $this->url = $url;
     if ($url->getUser() && $url->getPassword()) {
         $this->setHeader('Authorization', new BasicAuthorization($url->getUser(), $url->getPassword()));
     }
     $port = $this->url->getPort(-1);
     $this->headers['Host'] = [$this->url->getHost() . (-1 == $port ? '' : ':' . $port)];
     $this->target = $this->url->getPath('/');
 }
Esempio n. 2
0
 public function atInUserAndPath()
 {
     $u = new URL('http://user@localhost/@');
     $this->assertEquals('user', $u->getUser());
     $this->assertEquals('/@', $u->getPath());
 }
Esempio n. 3
0
 /**
  * Parse DSN
  *
  * @param   string dsn
  * @return  bool success
  */
 protected function _parsedsn($dsn)
 {
     if (null === $dsn) {
         return true;
     }
     $u = new URL($dsn);
     if (!$u->getHost()) {
         throw new \lang\IllegalArgumentException('DSN parsing failed ["' . $dsn . '"]');
     }
     // Scheme
     switch (strtoupper($u->getScheme())) {
         case 'ESMTP':
             $this->ext = true;
             break;
         case 'SMTP':
             $this->ext = false;
             break;
         default:
             throw new \lang\IllegalArgumentException('Scheme "' . $u->getScheme() . '" not supported');
     }
     // Copy host and port
     $this->host = $u->getHost();
     $this->port = $u->getPort() ? $u->getPort() : 25;
     // User & password
     if ($u->getUser()) {
         $this->auth = $u->getParam('auth', SMTP_AUTH_PLAIN);
         $this->user = $u->getUser();
         $this->pass = $u->getPassword();
     }
 }
Esempio n. 4
0
 private function _sendAuthenticateFrame(URL $url)
 {
     $frame = $this->sendFrame(new LoginFrame($url->getUser(), $url->getPassword(), $url->getParam('vhost', $url->getHost()), $url->hasParam('versions') ? explode(',', $url->getParam('versions')) : ['1.0', '1.1']));
     if (!$frame instanceof Frame) {
         throw new ProtocolException('Did not receive frame, got: ' . \xp::stringOf($frame));
     }
     if ($frame instanceof ErrorFrame) {
         throw new AuthenticationException('Could not establish connection to broker "' . $url->toString() . '": ' . $frame->getBody(), $url->getUser(), strlen($url->getPassword() > 0) ? 'with password' : 'no password');
     }
     if (!$frame instanceof ConnectedFrame) {
         throw new AuthenticationException('Could not log in to stomp broker "' . $url->toString() . '": Got "' . $frame->command() . '" frame', $url->getUser(), strlen($url->getPassword() > 0) ? 'with password' : 'no password');
     }
     $this->debug('~ Connected to server; server ' . ($frame->getProtocolVersion() ? 'chose protocol version ' . $frame->getProtocolVersion() : 'did not indicate protocol version'));
 }
Esempio n. 5
0
 /**
  * Copy authentication if on same host 
  *
  * @param  peer.URL $base
  * @param  peer.URL $url
  * @return peer.URL The given URL
  */
 private function authenticate($base, $url)
 {
     if ($base && $url->getHost() === $base->getHost()) {
         $url->setUser($base->getUser());
         $url->setPassword($base->getPassword());
     }
     return $url;
 }