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
path: root/lib
diff options
context:
space:
mode:
authorLEDfan <tobia@ledfan.be>2016-01-22 10:53:57 +0300
committerLEDfan <tobia@ledfan.be>2016-01-22 10:53:57 +0300
commite5fccf760a788fe184e2fc144bd50e58f05463b8 (patch)
treef285026c95dd3d240fa2bb4e4daf6a9c583e3246 /lib
parentfbd7f8a0865f79b8391602fd8bf138fc71cf50ba (diff)
Code style, cleanup, PHPDoc
Diffstat (limited to 'lib')
-rw-r--r--lib/controller/httpbindcontroller.php39
-rw-r--r--lib/db/iqroster.php21
-rw-r--r--lib/db/message.php7
-rw-r--r--lib/db/messagemapper.php5
-rw-r--r--lib/db/stanzamapper.php23
-rw-r--r--lib/dblock.php25
-rw-r--r--lib/http/xmppresponse.php20
-rw-r--r--lib/ilock.php11
-rw-r--r--lib/memlock.php26
-rw-r--r--lib/stanzahandlers/iq.php20
-rw-r--r--lib/stanzahandlers/message.php27
-rw-r--r--lib/stanzahandlers/stanzahandler.php23
12 files changed, 228 insertions, 19 deletions
diff --git a/lib/controller/httpbindcontroller.php b/lib/controller/httpbindcontroller.php
index d6d8fc3..0b78df4 100644
--- a/lib/controller/httpbindcontroller.php
+++ b/lib/controller/httpbindcontroller.php
@@ -16,17 +16,32 @@ use Sabre\Xml\Writer;
use Sabre\Xml\Reader;
use Sabre\Xml\LibXMLException;
+/**
+ * Class HttpBindController
+ *
+ * @package OCA\OJSXC\Controller
+ */
class HttpBindController extends Controller {
- private $userId;
-
const MESSAGE=0;
const IQ=1;
const PRESENCE=2;
const BODY=2;
+
+ /**
+ * @var string $userId
+ */
+ private $userId;
+
+ /**
+ * @var int $pollingId
+ */
private $pollingId;
+ /**
+ * @var string $host
+ */
private $host;
/**
@@ -79,6 +94,22 @@ class HttpBindController extends Controller {
*/
private $lock;
+ /**
+ * HttpBindController constructor.
+ *
+ * @param string $appName
+ * @param IRequest $request
+ * @param string $userId
+ * @param ISession $session
+ * @param StanzaMapper $stanzaMapper
+ * @param IQ $iqHandler
+ * @param Message $messageHandler
+ * @param string $host
+ * @param ILock $lock
+ * @param string $body
+ * @param int $sleepTime
+ * @param int $maxCicles
+ */
public function __construct($appName,
IRequest $request,
$userId,
@@ -165,6 +196,10 @@ class HttpBindController extends Controller {
return $this->response;
}
+ /**
+ * @param $stanza
+ * @return int
+ */
private function getStanzaType($stanza){
switch($stanza['name']){
case '{jabber:client}message':
diff --git a/lib/db/iqroster.php b/lib/db/iqroster.php
index 363dd78..6068492 100644
--- a/lib/db/iqroster.php
+++ b/lib/db/iqroster.php
@@ -13,11 +13,28 @@ use Sabre\Xml\XmlSerializable;
* Class IQRoster
*
* @package OCA\OJSXC\Db
+ * @method void setType(sting $type)
+ * @method void setQid(sting $qid)
+ * @method void setItems(array $items)
+ * @method string getType()
+ * @method string getQid()
+ * @method array getItems()
*/
class IQRoster extends Stanza implements XmlSerializable{
+ /**
+ * @var string $type
+ */
public $type;
+
+ /**
+ * @var string $qid
+ */
public $qid;
+
+ /**
+ * @var array $items
+ */
public $items;
public function xmlSerialize(Writer $writer) {
@@ -40,6 +57,10 @@ class IQRoster extends Stanza implements XmlSerializable{
]);
}
+ /**
+ * @param string $jid
+ * @param string $name
+ */
public function addItem($jid, $name){
$this->items[] = [
"name" => "item",
diff --git a/lib/db/message.php b/lib/db/message.php
index 683e030..babecd5 100644
--- a/lib/db/message.php
+++ b/lib/db/message.php
@@ -18,7 +18,14 @@ use Sabre\Xml\XmlSerializable;
*/
class Message extends Stanza implements XmlSerializable{
+ /**
+ * @var string $type
+ */
public $type;
+
+ /**
+ * @var array $value
+ */
public $value;
public function xmlSerialize(Writer $writer) {
diff --git a/lib/db/messagemapper.php b/lib/db/messagemapper.php
index 0b6b8fd..9de2392 100644
--- a/lib/db/messagemapper.php
+++ b/lib/db/messagemapper.php
@@ -2,6 +2,11 @@
namespace OCA\OJSXC\Db;
+/**
+ * Class MessageMapper
+ *
+ * @package OCA\OJSXC\Db
+ */
class MessageMapper extends StanzaMapper {
} \ No newline at end of file
diff --git a/lib/db/stanzamapper.php b/lib/db/stanzamapper.php
index 6aff1a1..c112458 100644
--- a/lib/db/stanzamapper.php
+++ b/lib/db/stanzamapper.php
@@ -8,15 +8,30 @@ use OCP\AppFramework\Db\Mapper;
use OCP\IDb;
use Sabre\Xml\Writer;
+/**
+ * Class StanzaMapper
+ *
+ * @package OCA\OJSXC\Db
+ */
class StanzaMapper extends Mapper {
private $host;
+ /**
+ * StanzaMapper constructor.
+ *
+ * @param IDb $db
+ * @param string $host
+ */
public function __construct(IDb $db, $host) {
parent::__construct($db, 'ojsxc_stanzas');
$this->host = $host;
}
+ /**
+ * @param Entity $entity
+ * @return void
+ */
public function insert(Entity $entity) {
$writer = new Writer();
$writer->openMemory();
@@ -28,6 +43,11 @@ class StanzaMapper extends Mapper {
}
+ /**
+ * @param string $to
+ * @return Stanza[]
+ * @throws DoesNotExistException
+ */
public function findByTo($to){
$stmt = $this->execute("SELECT stanza, id FROM *PREFIX*ojsxc_stanzas WHERE `to`=?", [$to]);
$results = [];
@@ -48,7 +68,4 @@ class StanzaMapper extends Mapper {
return $results;
}
- private function replaceHostname($input) {
- return str_replace('@{hostPlaceholder}', '@' . $this->host, $input);
- }
} \ No newline at end of file
diff --git a/lib/dblock.php b/lib/dblock.php
index 7872761..8989122 100644
--- a/lib/dblock.php
+++ b/lib/dblock.php
@@ -5,22 +5,40 @@ namespace OCA\OJSXC;
use OCP\IConfig;
use OCP\IDb;
+/**
+ * Class DbLock
+ *
+ * @package OCA\OJSXC
+ */
class DbLock implements ILock {
/**
- * @var IDb
+ * @var IDb $con
*/
private $con;
/**
- * @var IConfig
+ * @var IConfig $config
*/
private $config;
+ /**
+ * @var string $userId
+ */
private $userId;
+ /**
+ * @var int $pollingId
+ */
private $pollingId;
+ /**
+ * DbLock constructor.
+ *
+ * @param string $userId
+ * @param IDb $con
+ * @param IConfig $config
+ */
public function __construct($userId, IDb $con, IConfig $config) {
$this->con = $con;
$this->userId = $userId;
@@ -32,6 +50,9 @@ class DbLock implements ILock {
$this->config->setUserValue($this->userId, 'ojsxc', 'longpolling', $this->pollingId);
}
+ /**
+ * @return bool
+ */
public function stillLocked() {
$sql = "SELECT `configvalue` FROM `*PREFIX*preferences` WHERE `userid` = ? AND `appid`='ojsxc' AND `configkey`='longpolling'";
$q = $this->con->prepareQuery($sql);
diff --git a/lib/http/xmppresponse.php b/lib/http/xmppresponse.php
index f80cf2f..5ae6069 100644
--- a/lib/http/xmppresponse.php
+++ b/lib/http/xmppresponse.php
@@ -5,11 +5,23 @@ use OCP\AppFramework\Http\Response;
use Sabre\Xml\Writer;
use OCA\OJSXC\Db\Stanza;
-
+/**
+ * Class XMPPResponse
+ *
+ * @package OCA\OJSXC\Http
+ */
class XMPPResponse extends Response {
+ /**
+ * @var Writer $writer
+ */
private $writer;
+ /**
+ * XMPPResponse constructor.
+ *
+ * @param Stanza|null $stanza
+ */
public function __construct(Stanza $stanza=null) {
$this->addHeader('Content-Type', 'text/xml');
$this->writer = new Writer();
@@ -21,10 +33,16 @@ class XMPPResponse extends Response {
}
}
+ /**
+ * @param Stanza $input
+ */
public function write(Stanza $input) {
$this->writer->write($input);
}
+ /**
+ * @return string
+ */
public function render() {
$this->writer->endElement();
return $this->writer->outputMemory();
diff --git a/lib/ilock.php b/lib/ilock.php
index 4ff6499..c0017e0 100644
--- a/lib/ilock.php
+++ b/lib/ilock.php
@@ -2,10 +2,21 @@
namespace OCA\OJSXC;
+/**
+ * Interface ILock
+ *
+ * @package OCA\OJSXC
+ */
interface ILock {
+ /**
+ * @return void
+ */
public function setLock();
+ /**
+ * @return bool
+ */
public function stillLocked();
} \ No newline at end of file
diff --git a/lib/memlock.php b/lib/memlock.php
index 55f3b13..9334141 100644
--- a/lib/memlock.php
+++ b/lib/memlock.php
@@ -4,15 +4,34 @@ namespace OCA\OJSXC;
use OCP\ICache;
+/**
+ * Class MemLock
+ *
+ * @package OCA\OJSXC
+ */
class MemLock implements ILock {
/**
- * @var \OCP\ICache
+ * @var \OCP\ICache $memcache
*/
private $memcache;
+ /**
+ * @var string $userId
+ */
private $userId;
+ /**
+ * @var int $pollingId
+ */
+ private $pollingId;
+
+ /**
+ * MemLock constructor.
+ *
+ * @param $userId
+ * @param ICache $cache
+ */
public function __construct($userId, ICache $cache) {
$this->userId = $userId;
$this->memcache = $cache;
@@ -24,9 +43,12 @@ class MemLock implements ILock {
$this->memcache->add('-' . $this->userId . '-ojxsc-lock', $this->pollingId);
}
+ /**
+ * @return bool
+ */
public function stillLocked() {
$r = $this->memcache->get('-' . $this->userId . '-ojxsc-lock');
- return $r == $this->pollingId;
+ return $r === $this->pollingId;
}
} \ No newline at end of file
diff --git a/lib/stanzahandlers/iq.php b/lib/stanzahandlers/iq.php
index 025f676..d322ab6 100644
--- a/lib/stanzahandlers/iq.php
+++ b/lib/stanzahandlers/iq.php
@@ -3,20 +3,24 @@
namespace OCA\OJSXC\StanzaHandlers;
use OCA\OJSXC\Db\IQRoster;
-use OCA\OJSXC\Db\MessageMapper;
use OCP\IUserManager;
use Sabre\Xml\Reader;
use Sabre\Xml\Writer;
-
+/**
+ * Class IQ
+ *
+ * @package OCA\OJSXC\StanzaHandlers
+ */
class IQ extends StanzaHandler {
- private $type;
-
- private $id;
-
- private $query;
-
+ /**
+ * 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;
diff --git a/lib/stanzahandlers/message.php b/lib/stanzahandlers/message.php
index d79cda1..d81281d 100644
--- a/lib/stanzahandlers/message.php
+++ b/lib/stanzahandlers/message.php
@@ -7,21 +7,48 @@ 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, '@');
diff --git a/lib/stanzahandlers/stanzahandler.php b/lib/stanzahandlers/stanzahandler.php
index bb191d5..ee6c79d 100644
--- a/lib/stanzahandlers/stanzahandler.php
+++ b/lib/stanzahandlers/stanzahandler.php
@@ -1,18 +1,37 @@
<?php
namespace OCA\OJSXC\StanzaHandlers;
-use OCA\OJSXC\Db\MessageMapper;
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;
@@ -20,6 +39,8 @@ class StanzaHandler {
}
/**
+ * @brief Gets an attribute $attr from $stanza, returns null if it doens't
+ * exists.
* @param $stanza
* @param $attr
* @return null|string