-
Notifications
You must be signed in to change notification settings - Fork 3
/
DiscoDebugController.m
119 lines (103 loc) · 2.89 KB
/
DiscoDebugController.m
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#import "DiscoDebugController.h"
#import "JabberApp.h"
#import <XMPPKit/JID.h>
@implementation DiscoDebugController
- (IBAction) showWindow:(id)_sender
{
/*addObserver for features */
center = [NSNotificationCenter defaultCenter];
[center addObserver:self
selector:@selector(receivedInfoNotification:)
name:@"XMPPDiscoFeaturesFound"
object:nil];
/*addObserver for items*/
[center addObserver:self
selector:@selector(receivedItemsNotification:)
name:@"XMPPDiscoItemsFound"
object:nil];
disco = [[[(JabberApp*)[NSApp delegate ] account] roster] disco];
[super showWindow:_sender];
}
- (void) discoFeaturesLog:(XMPPDiscoInfo*)anInfo
{
NSUInteger index = 0;
NSArray *features = [info features];
NSTextStorage *storage = [discoInfoBox textStorage];
[storage beginEditing];
for(index=0; index < [features count]; index++)
{
[[storage mutableString] appendString:[features objectAtIndex:index]];
[[storage mutableString] appendString:@"\n"];
}
[storage endEditing];
}
- (void) discoItemsLog:(XMPPDiscoItems*)anItem
{
NSUInteger index = 0;
NSTextStorage *storage = [discoItemBox textStorage];
NSArray *itemsSet = [anItem items];
[storage beginEditing];
for (index=0; index < [itemsSet count]; index++)
{
NSEnumerator *enumerator = [[itemsSet objectAtIndex:index] objectEnumerator];
id value;
while ((value = [enumerator nextObject]))
{
[[storage mutableString] appendString:value];
[[storage mutableString] appendString:@"\n"];
}
}
[storage endEditing];
}
- (IBAction) serviceDiscovery:(id)sender
{
NSString * xmlnsXMPPDiscoInfo = @"http://jabber.org/protocol/disco#info";
NSString * xmlnsXMPPDiscoItems = @"http://jabber.org/protocol/disco#items";
info = [disco info];
discoItems = [disco items];
XMPPConnection *connection;
if (discoItems == nil)
{
connection = [[(JabberApp*)[NSApp delegate] account] connection];
NSString *server = [connection server];
[disco sendQueryToJID:server node:nil inNamespace:xmlnsXMPPDiscoItems];
}
else
{
[self discoItemsLog:discoItems];
}
if (info == nil)
{
connection = [[(JabberApp*)[NSApp delegate] account] connection];
NSString *server = [connection server];
[disco sendQueryToJID:server node:nil inNamespace:xmlnsXMPPDiscoInfo];
}
else
{
[self discoFeaturesLog: info];
}
}
- (void) receivedItemsNotification:(NSNotification*) aNotification
{
discoItems = [disco items];
[self discoItemsLog:discoItems];
}
- (void) receivedInfoNotification:(NSNotification*) aNotification
{
info = [disco info];
[self discoFeaturesLog:info];
}
- (IBAction) closeWindow:(id)sender
{
[discoItemBox setString:@""];
[discoInfoBox setString:@""];
[center removeObserver:self
name:@"XMPPDiscoFeaturesFound"
object:nil];
[center removeObserver:self
name:@"XMPPDiscoItemsFound"
object:nil];
if ([[self window] isVisible])
[[self window] orderOut:self];
}
@end