ObjXMPP  Diff

Differences From Artifact [99bc6fd072]:

To Artifact [8c0b92b7c2]:


28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#import "XMPPIQ.h"
#import "XMPPJID.h"
#import "namespaces.h"

@implementation XMPPDiscoEntity
@synthesize discoNodes = _discoNodes, capsNode = _capsNode;

+ (instancetype)discoNodeWithJID: (XMPPJID *)JID
			    node: (OFString *)node
{
	OF_UNRECOGNIZED_SELECTOR
}

+ (instancetype)discoNodeWithJID: (XMPPJID *)JID
			    node: (OFString *)node
			    name: (OFString *)name







|
<







28
29
30
31
32
33
34
35

36
37
38
39
40
41
42
#import "XMPPIQ.h"
#import "XMPPJID.h"
#import "namespaces.h"

@implementation XMPPDiscoEntity
@synthesize discoNodes = _discoNodes, capsNode = _capsNode;

+ (instancetype)discoNodeWithJID: (XMPPJID *)JID node: (OFString *)node

{
	OF_UNRECOGNIZED_SELECTOR
}

+ (instancetype)discoNodeWithJID: (XMPPJID *)JID
			    node: (OFString *)node
			    name: (OFString *)name
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
+ (instancetype)discoEntityWithConnection: (XMPPConnection *)connection
				 capsNode: (OFString *)capsNode
{
	return [[[self alloc] initWithConnection: connection
					capsNode: capsNode] autorelease];
}

- (instancetype)initWithJID: (XMPPJID *)JID
		       node: (nullable OFString *)node
{
	OF_INVALID_INIT_METHOD
}

- (instancetype)initWithJID: (XMPPJID *)JID
		       node: (nullable OFString *)node
		       name: (nullable OFString *)name
{
	OF_INVALID_INIT_METHOD
}

- (instancetype)initWithConnection: (XMPPConnection *)connection
{
	return [self initWithConnection: connection
			       capsNode: nil];
}

- (instancetype)initWithConnection: (XMPPConnection *)connection
			  capsNode: (OFString *)capsNode
{
	self = [super initWithJID: [connection JID]
			     node: nil
			     name: nil];

	@try {
		_discoNodes = [[OFMutableDictionary alloc] init];
		_connection = connection;
		_capsNode = [capsNode copy];

		[_connection addDelegate: self];







|
<




















|
<
<







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
77
78
79
80


81
82
83
84
85
86
87
+ (instancetype)discoEntityWithConnection: (XMPPConnection *)connection
				 capsNode: (OFString *)capsNode
{
	return [[[self alloc] initWithConnection: connection
					capsNode: capsNode] autorelease];
}

- (instancetype)initWithJID: (XMPPJID *)JID node: (nullable OFString *)node

{
	OF_INVALID_INIT_METHOD
}

- (instancetype)initWithJID: (XMPPJID *)JID
		       node: (nullable OFString *)node
		       name: (nullable OFString *)name
{
	OF_INVALID_INIT_METHOD
}

- (instancetype)initWithConnection: (XMPPConnection *)connection
{
	return [self initWithConnection: connection
			       capsNode: nil];
}

- (instancetype)initWithConnection: (XMPPConnection *)connection
			  capsNode: (OFString *)capsNode
{
	self = [super initWithJID: [connection JID] node: nil name: nil];



	@try {
		_discoNodes = [[OFMutableDictionary alloc] init];
		_connection = connection;
		_capsNode = [capsNode copy];

		[_connection addDelegate: self];
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
	[_discoNodes release];

	[super dealloc];
}

- (void)addDiscoNode: (XMPPDiscoNode *)node
{
	[_discoNodes setObject: node
			forKey: node.node];
}

- (OFString *)capsHash
{
	OFMutableString *caps = [OFMutableString string];
	OFSHA1Hash *hash = [OFSHA1Hash hashWithAllowsSwappableMemory: true];
	OFData *digest;

	for (XMPPDiscoIdentity *identity in _identities)
		[caps appendFormat: @"%@/%@//%@<",
		    identity.category, identity.type, identity.name];

	for (OFString *feature in _features)
		[caps appendFormat: @"%@<", feature];

	[hash updateWithBuffer: caps.UTF8String
			length: caps.UTF8StringLength];

	digest = [OFData dataWithItems: hash.digest
				 count: hash.digestSize];

	return digest.stringByBase64Encoding;
}

- (void)connection: (XMPPConnection *)connection
     wasBoundToJID: (XMPPJID *)JID
{
	_JID = [JID copy];
}

- (bool)connection: (XMPPConnection *)connection
      didReceiveIQ: (XMPPIQ *)IQ
{
	if (![IQ.to isEqual: _JID])
		return false;

	OFXMLElement *query = [IQ elementForName: @"query"
				       namespace: XMPP_NS_DISCO_ITEMS];

	if (query != nil) {
		OFString *node = [query attributeForName: @"node"].stringValue;
		if (node == nil)
			return [self xmpp_handleItemsIQ: IQ
					     connection: connection];

		XMPPDiscoNode *responder = [_discoNodes objectForKey: node];
		if (responder != nil)
			return [responder xmpp_handleItemsIQ: IQ
						  connection: connection];

		return false;
	}

	query = [IQ elementForName: @"query"
			 namespace: XMPP_NS_DISCO_INFO];

	if (query != nil) {
		OFString *node = [query attributeForName: @"node"].stringValue;

		if (node == nil)
			return [self xmpp_handleInfoIQ: IQ
					    connection: connection];







|
<















|
<

|
<

















|















|
<







99
100
101
102
103
104
105
106

107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122

123
124

125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158

159
160
161
162
163
164
165
	[_discoNodes release];

	[super dealloc];
}

- (void)addDiscoNode: (XMPPDiscoNode *)node
{
	[_discoNodes setObject: node forKey: node.node];

}

- (OFString *)capsHash
{
	OFMutableString *caps = [OFMutableString string];
	OFSHA1Hash *hash = [OFSHA1Hash hashWithAllowsSwappableMemory: true];
	OFData *digest;

	for (XMPPDiscoIdentity *identity in _identities)
		[caps appendFormat: @"%@/%@//%@<",
		    identity.category, identity.type, identity.name];

	for (OFString *feature in _features)
		[caps appendFormat: @"%@<", feature];

	[hash updateWithBuffer: caps.UTF8String length: caps.UTF8StringLength];


	digest = [OFData dataWithItems: hash.digest count: hash.digestSize];


	return digest.stringByBase64Encoding;
}

- (void)connection: (XMPPConnection *)connection
     wasBoundToJID: (XMPPJID *)JID
{
	_JID = [JID copy];
}

- (bool)connection: (XMPPConnection *)connection
      didReceiveIQ: (XMPPIQ *)IQ
{
	if (![IQ.to isEqual: _JID])
		return false;

	OFXMLElement *query = [IQ elementForName: @"query"
				       namespace: XMPPDiscoItemsNS];

	if (query != nil) {
		OFString *node = [query attributeForName: @"node"].stringValue;
		if (node == nil)
			return [self xmpp_handleItemsIQ: IQ
					     connection: connection];

		XMPPDiscoNode *responder = [_discoNodes objectForKey: node];
		if (responder != nil)
			return [responder xmpp_handleItemsIQ: IQ
						  connection: connection];

		return false;
	}

	query = [IQ elementForName: @"query" namespace: XMPPDiscoInfoNS];


	if (query != nil) {
		OFString *node = [query attributeForName: @"node"].stringValue;

		if (node == nil)
			return [self xmpp_handleInfoIQ: IQ
					    connection: connection];