Example #1
0
 /**
  * {@inheritDoc}
  */
 public function toString()
 {
     return XML::quoteMessage('<message type="%s" id="%s" to="%s"><body>%s</body></message>', $this->getType(), XML::generateId(), $this->getTo(), $this->getMessage());
 }
Example #2
0
 /**
  * {@inheritDoc}
  */
 public function toString()
 {
     return '<iq type="get" id="' . XML::generateId() . '"><query xmlns="jabber:iq:roster"/></iq>';
 }
Example #3
0
 /**
  * Generate response data.
  *
  * @param array $values
  */
 protected function response($values)
 {
     $values['cnonce'] = uniqid(mt_rand(), false);
     $values['nc'] = '00000001';
     $values['qop'] = 'auth';
     if (!isset($values['realm'])) {
         $values['realm'] = $this->getOptions()->getTo();
     }
     if (!isset($values['digest-uri'])) {
         $values['digest-uri'] = 'xmpp/' . $this->getOptions()->getTo();
     }
     $a1 = sprintf('%s:%s:%s', $this->getUsername(), $values['realm'], $this->getPassword());
     if ('md5-sess' === $values['algorithm']) {
         $a1 = pack('H32', md5($a1)) . ':' . $values['nonce'] . ':' . $values['cnonce'];
     }
     $a2 = "AUTHENTICATE:" . $values['digest-uri'];
     $password = md5($a1) . ':' . $values['nonce'] . ':' . $values['nc'] . ':' . $values['cnonce'] . ':' . $values['qop'] . ':' . md5($a2);
     $password = md5($password);
     $response = sprintf('username="******",realm="%s",nonce="%s",cnonce="%s",nc=%s,qop=%s,digest-uri="%s",response=%s,charset=utf-8', $this->getUsername(), $values['realm'], $values['nonce'], $values['cnonce'], $values['nc'], $values['qop'], $values['digest-uri'], $password);
     return XML::base64Encode($response);
 }
Example #4
0
 /**
  * {@inheritDoc}
  */
 public function authenticate($username, $password)
 {
     $authString = XML::quote(base64_encode("" . $username . "" . $password));
     $this->getConnection()->send('<auth xmlns="urn:ietf:params:xml:ns:xmpp-sasl" mechanism="PLAIN">' . $authString . '</auth>');
 }
Example #5
0
 /**
  * {@inheritDoc}
  */
 public function toString()
 {
     $presence = '<presence';
     if (null !== $this->getTo()) {
         $presence .= ' to="' . XML::quote($this->getTo()) . '/' . XML::quote($this->getNickname()) . '"';
     }
     return $presence . '><priority>' . $this->getPriority() . '</priority></presence>';
 }
Example #6
0
 /**
  * {@inheritDoc}
  */
 public function connect()
 {
     if (false === $this->connected) {
         $address = $this->getAddress();
         $this->getSocket()->connect($this->getOptions()->getTimeout());
         $this->getSocket()->setBlocking(true);
         $this->connected = true;
         $this->log("Connected to '{$address}'", LogLevel::DEBUG);
     }
     $this->send(sprintf(static::STREAM_START, XML::quote($this->getOptions()->getTo())));
 }
 /**
  * Get generated id.
  *
  * @return string
  */
 public function getId()
 {
     if (null === $this->id) {
         $this->id = XML::generateId();
     }
     return $this->id;
 }