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

xmppresponse.php « http « lib - github.com/nextcloud/jsxc.nextcloud.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 8680bd7bf1ea2d4c0bc89b5cbd959953cfca4025 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
namespace OCA\OJSXC\Http;

use OCA\OJSXC\StanzaLogger;
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;

	/**
	 * @var StanzaLogger
	 */
	private $stanzaLogger;

	/**
	 * XMPPResponse constructor.
	 *
	 * @param Stanza|null $stanza
	 * @param StanzaLogger $stanzaLogger
	 */
	public function __construct(StanzaLogger $stanzaLogger, Stanza $stanza = null)
	{
		$this->addHeader('Content-Type', 'text/xml');
		$this->writer = new Writer();
		$this->writer->openMemory();
		$this->writer->startElement('body');
		$this->writer->writeAttribute('xmlns', 'http://jabber.org/protocol/httpbind');
		if (!is_null($stanza)) {
			$this->writer->write($stanza);
		}
		$this->stanzaLogger = $stanzaLogger;
	}

	/**
	 * @param Stanza $input
	 */
	public function write(Stanza $input)
	{
		$this->stanzaLogger->log($input, StanzaLogger::SENDING);
		$this->writer->write($input);
	}

	/**
	 * @return string
	 */
	public function render()
	{
		$this->writer->endElement();
		return $this->writer->outputMemory();
	}

	/**
	 * Terminates the Chat connection with the `x-nc-not_allowed_to_chat` condition.
	 */
	public function terminate()
	{
		$this->writer = new Writer();
		$this->writer->openMemory();
		$this->writer->startElement('body');
		$this->writer->writeAttribute('xmlns', 'http://jabber.org/protocol/httpbind');
		$this->writer->writeAttribute('type', 'terminate');
		$this->writer->writeAttribute('condition', 'x-nc-not_allowed_to_chat');
	}
}