diff options
Diffstat (limited to 'build/lib/db')
-rw-r--r-- | build/lib/db/README.md | 11 | ||||
-rw-r--r-- | build/lib/db/iqrosterpush.php | 17 | ||||
-rw-r--r-- | build/lib/db/presencemapper.php | 10 | ||||
-rw-r--r-- | build/lib/db/stanza.php | 40 | ||||
-rw-r--r-- | build/lib/db/stanzamapper.php | 6 |
5 files changed, 71 insertions, 13 deletions
diff --git a/build/lib/db/README.md b/build/lib/db/README.md index fce2e82..8dea934 100644 --- a/build/lib/db/README.md +++ b/build/lib/db/README.md @@ -14,4 +14,13 @@ The following mappers are used: - StanzaMapper -> parent of all the other mappers - MessageMapper -> used to store Message entities inside the longpolling table. - PresenceMapper -> used to save, update and fetch presences of the users - - IQRoster doesn't have a mapper since this won't be saved in the DB.
\ No newline at end of file + - IQRoster doesn't have a mapper since this won't be saved in the DB. + + +# Important note on userids and jid's + +When users and Stanza's containing users are stored inside the database this must be done using the Nextcloud userid +and not using a jid! So at all times the user 'admin' must be stored as 'admin' and not as 'admin@localhost/internal' even +in the `to` and `from` parameters of raw xml stanzas. This to support multiple domain Nextcloud instances. +The userId's are escaped using the `OCA\OJSXC\AppInfo\Appplication::sanitizeUserId` function to support the XMPP standards. +When the userId is available inside the class the `OJSXC_UserId` paramter of `OCA\OJSXC\AppInfo\Appplication` must be used.
\ No newline at end of file diff --git a/build/lib/db/iqrosterpush.php b/build/lib/db/iqrosterpush.php index 1d8b596..aebf9dc 100644 --- a/build/lib/db/iqrosterpush.php +++ b/build/lib/db/iqrosterpush.php @@ -2,6 +2,7 @@ namespace OCA\OJSXC\Db; +use OCA\OJSXC\AppInfo\Application; use Sabre\Xml\Reader; use Sabre\Xml\Writer; use Sabre\Xml\XmlDeserializable; @@ -13,7 +14,6 @@ use Sabre\Xml\XmlSerializable; * Class IQRosterPush * * @package OCA\OJSXC\Db - * @method void setJid($jid) * @method void setName($name) * @method void setSubscription($subscription) * @method string getJid() @@ -39,6 +39,21 @@ class IQRosterPush extends Stanza implements XmlSerializable */ public $subscription; + /** + * Sets the to user as a `user`. + * + * @see setFullJid + * @param $userId + * @param null $host_and_or_resource + */ + public function setJid($userId, $host_and_or_resource = null) + { + $this->jid = Application::santizeUserId($userId); + if (!is_null($host_and_or_resource)) { + $this->jid .= '@' . $host_and_or_resource; + } + } + public function xmlSerialize(Writer $writer) { $writer->write([ diff --git a/build/lib/db/presencemapper.php b/build/lib/db/presencemapper.php index f34bf92..adc4831 100644 --- a/build/lib/db/presencemapper.php +++ b/build/lib/db/presencemapper.php @@ -109,8 +109,8 @@ class PresenceMapper extends Mapper $stmt = $this->execute("SELECT * FROM `*PREFIX*ojsxc_presence` WHERE `userid` != ?", [$this->userId]); $results = []; while ($row = $stmt->fetch()) { - $row['from'] = $row['userid'] . '@' . $this->host . '/internal'; - $row['to'] = $this->userId . '@' . $this->host . '/internal'; + $row['from'] = [$row['userid'], $this->host . '/internal']; + $row['to'] = [$this->userId, $this->host . '/internal']; $results[] = $this->mapRowToEntity($row); } $stmt->closeCursor(); @@ -196,11 +196,13 @@ class PresenceMapper extends Mapper $presenceToSend->setPresence('unavailable'); $presenceToSend->setFrom($inactiveUser); foreach ($onlineUsers as $user) { + // send to every online user (except the user who initiated the update) $presenceToSend->setTo($user); $this->messageMapper->insert($presenceToSend); } - $presenceToSend->setTo($this->userId . '@' . $this->host . '/internal'); - $presenceToSend->setFrom($inactiveUser . '@' . $this->host . '/internal'); + // and now send it to the user who initiated the update + $presenceToSend->setTo($this->userId, $this->host . '/internal'); + $presenceToSend->setFrom($inactiveUser, $this->host . '/internal'); $this->newContentContainer->addStanza($presenceToSend); } } diff --git a/build/lib/db/stanza.php b/build/lib/db/stanza.php index 673fd02..4998579 100644 --- a/build/lib/db/stanza.php +++ b/build/lib/db/stanza.php @@ -2,6 +2,7 @@ namespace OCA\OJSXC\Db; +use OCA\OJSXC\AppInfo\Application; use \OCP\AppFramework\Db\Entity; use Sabre\Xml\Reader; use Sabre\Xml\Writer; @@ -43,14 +44,45 @@ class Stanza extends Entity implements XmlSerializable return $this->to; } - public function setTo($userId) + /** + * Sets the to user as a `user`. + * + * @see setFullTo + * @param $userId + * @param null $host_and_or_resource + */ + public function setTo($userId, $host_and_or_resource = null) { - $this->to = strtolower($userId); + if (is_array($userId)) { + // support mapFromRow + $host_and_or_resource = $userId[1]; + $userId = $userId[0]; + } + + $this->to = Application::santizeUserId($userId); + if (!is_null($host_and_or_resource)) { + $this->to .= '@' . $host_and_or_resource; + } } - public function setFrom($userId) + /** + * Sets the from user as a `user`. + * + * @see setFullFrom + * @param $userId + * @param null $host_and_or_resource + */ + public function setFrom($userId, $host_and_or_resource = null) { - $this->from = strtolower($userId); + if (is_array($userId)) { + // support mapFromRow + $host_and_or_resource = $userId[1]; + $userId = $userId[0]; + } + $this->from = Application::santizeUserId($userId); + if (!is_null($host_and_or_resource)) { + $this->from .= '@' . $host_and_or_resource; + } } public function getFrom() diff --git a/build/lib/db/stanzamapper.php b/build/lib/db/stanzamapper.php index 6f7ae73..f84a020 100644 --- a/build/lib/db/stanzamapper.php +++ b/build/lib/db/stanzamapper.php @@ -66,9 +66,9 @@ class StanzaMapper extends Mapper $stmt = $this->execute("SELECT stanza, id FROM *PREFIX*ojsxc_stanzas WHERE `to`=?", [$to]); $results = []; while ($row = $stmt->fetch()) { - $row['stanza'] = preg_replace('/to="([^"@]*)"/', "to=\"$1@" .$this->host ."/internal\"", $row['stanza']); - $row['stanza'] = preg_replace('/from="([^"@]*)"/', "from=\"$1@" .$this->host ."/internal\"", $row['stanza']); - $row['stanza'] = preg_replace('/jid="([^"@]*)"/', "jid=\"$1@" .$this->host ."/internal\"", $row['stanza']); + $row['stanza'] = preg_replace('/to="([^"]*)"/', "to=\"$1@" .$this->host ."/internal\"", $row['stanza']); + $row['stanza'] = preg_replace('/from="([^"]*)"/', "from=\"$1@" .$this->host ."/internal\"", $row['stanza']); + $row['stanza'] = preg_replace('/jid="([^"]*)"/', "jid=\"$1@" .$this->host ."\"", $row['stanza']); $results[] = $this->mapRowToEntity($row); } $stmt->closeCursor(); |