Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/jsxc.nextcloud.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKlaus <klaus@jsxc.org>2016-01-29 13:46:22 +0300
committerKlaus <klaus@jsxc.org>2016-01-29 13:46:22 +0300
commit142e5f712b2a4653cc9a407ef40814384e711804 (patch)
treebd66167304a7e69ee533e0d8f10890f546de4729 /build/lib/stanzahandlers
parent6c50da5f21c5028d4fff078db1d69140acceb0dd (diff)
build v3.0.0-beta1b
Diffstat (limited to 'build/lib/stanzahandlers')
-rw-r--r--build/lib/stanzahandlers/iq.php53
-rw-r--r--build/lib/stanzahandlers/message.php80
-rw-r--r--build/lib/stanzahandlers/stanzahandler.php53
3 files changed, 186 insertions, 0 deletions
diff --git a/build/lib/stanzahandlers/iq.php b/build/lib/stanzahandlers/iq.php
new file mode 100644
index 0000000..2dafeb7
--- /dev/null
+++ b/build/lib/stanzahandlers/iq.php
@@ -0,0 +1,53 @@
+<?php
+
+namespace OCA\OJSXC\StanzaHandlers;
+
+use OCA\OJSXC\Db\IQRoster;
+use OCP\IUserManager;
+use Sabre\Xml\Reader;
+use Sabre\Xml\Writer;
+
+/**
+ * Class IQ
+ *
+ * @package OCA\OJSXC\StanzaHandlers
+ */
+class IQ extends StanzaHandler {
+
+ /**
+ * IQ constructor.
+ *
+ * @param string $userId
+ * @param string $host
+ * @param IUserManager $userManager
+ */
+ public function __construct($userId, $host, IUserManager $userManager) {
+ parent::__construct($userId, $host);
+ $this->userManager = $userManager;
+ }
+
+
+ /**
+ * @param array $stanza
+ * @return IQRoster
+ */
+ public function handle(array $stanza) {
+ $this->to = $this->getAttribute($stanza, 'to');
+
+ if ($stanza['value'][0]['name'] === '{jabber:iq:roster}query'){
+ $id = $stanza['attributes']['id'];
+ $iqRoster = new IQRoster();
+ $iqRoster->setType('result');
+ $iqRoster->setTo($this->from);
+ $iqRoster->setQid($id);
+ foreach($this->userManager->search('') as $user){
+ if($user->getUID() !== $this->userId) {
+ $iqRoster->addItem($user->getUID() . '@' . $this->host, $user->getDisplayName());
+ }
+ }
+ return $iqRoster;
+ }
+
+ }
+
+} \ No newline at end of file
diff --git a/build/lib/stanzahandlers/message.php b/build/lib/stanzahandlers/message.php
new file mode 100644
index 0000000..32585be
--- /dev/null
+++ b/build/lib/stanzahandlers/message.php
@@ -0,0 +1,80 @@
+<?php
+
+namespace OCA\OJSXC\StanzaHandlers;
+
+use OCA\OJSXC\Db\MessageMapper;
+use Sabre\Xml\Reader;
+use Sabre\Xml\Writer;
+use OCA\OJSXC\Db\Message as MessageEntity;
+
+/**
+ * Class Message
+ *
+ * @package OCA\OJSXC\StanzaHandlers
+ */
+class Message extends StanzaHandler {
+
+ /**
+ * @var MessageMapper $messageMapper
+ */
+ private $messageMapper;
+
+ /**
+ * @var string $type
+ */
+ private $type;
+
+ /**
+ * @var array $values
+ */
+ private $values;
+
+ /**
+ * @var string $msgId
+ */
+ private $msgId;
+
+ /**
+ * Message constructor.
+ *
+ * @param string $userId
+ * @param string $host
+ * @param MessageMapper $messageMapper
+ */
+ public function __construct($userId, $host, MessageMapper $messageMapper) {
+ parent::__construct($userId, $host);
+ $this->messageMapper = $messageMapper;
+ }
+
+ /**
+ * @param array $stanza
+ */
+ public function handle(array $stanza) {
+ $to = $this->getAttribute($stanza, 'to');
+ $pos = strpos($to, '@');
+ $this->to = substr($to, 0, $pos);
+ foreach($stanza['value'] as $keyRaw=>$value) {
+ // remove namespace from key as it is unneeded and cause problems
+ $key = substr($keyRaw, strpos($keyRaw, '}') + 1, strlen($keyRaw));
+ // fetch namespace from key to readd it
+ $ns = substr($keyRaw, 1, strpos($keyRaw, '}')-1);
+
+ $this->values[] = [
+ "name" => $key,
+ "value" => (string)$value,
+ "attributes" => ["xmlns" => $ns]
+ ];
+ }
+ $this->type = $this->getAttribute($stanza, 'type');
+ $this->msgId = $this->getAttribute($stanza, 'id');
+
+ $message = new MessageEntity();
+ $message->setTo($this->to);
+ $message->setFrom($this->from);
+ $message->setValue($this->values);
+ $message->setType($this->type);
+ $this->messageMapper->insert($message);
+ $this->values = [];
+ }
+
+} \ No newline at end of file
diff --git a/build/lib/stanzahandlers/stanzahandler.php b/build/lib/stanzahandlers/stanzahandler.php
new file mode 100644
index 0000000..ee6c79d
--- /dev/null
+++ b/build/lib/stanzahandlers/stanzahandler.php
@@ -0,0 +1,53 @@
+<?php
+namespace OCA\OJSXC\StanzaHandlers;
+
+use Sabre\Xml\Reader;
+use Sabre\Xml\Writer;
+
+/**
+ * Class StanzaHandler
+ *
+ * @package OCA\OJSXC\StanzaHandlers
+ */
+class StanzaHandler {
+
+ /**
+ * @var string $userId
+ */
+ protected $userId;
+
+ /**
+ * @var string $host
+ */
+ protected $host;
+
+ /**
+ * @var string $to
+ */
+ protected $to;
+
+ /**
+ * StanzaHandler constructor.
+ *
+ * @param string 1$userId
+ * @param string $host
+ */
+ public function __construct($userId, $host) {
+ $this->userId = $userId;
+ $this->host = $host;
+ $this->from = $this->userId;
+ }
+
+ /**
+ * @brief Gets an attribute $attr from $stanza, returns null if it doens't
+ * exists.
+ * @param $stanza
+ * @param $attr
+ * @return null|string
+ */
+ protected function getAttribute($stanza, $attr){
+ return isset($stanza['attributes'][$attr]) ? (string) $stanza['attributes'][$attr] : null;
+ }
+
+
+}