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
120
121
122
123
124
125
126
127
|
{
self = [super init];
size_t nodesep, resourcesep;
nodesep = [str indexOfFirstOccurrenceOfString: @"@"];
resourcesep = [str indexOfFirstOccurrenceOfString: @"/"];
if (nodesep == -1)
[self setNode: @""];
else
[self setNode: [str substringFromIndex: 0
toIndex: nodesep]];
if (resourcesep == -1) {
[self setResource: @""];
resourcesep = [str length];
} else
[self setResource: [str substringFromIndex: resourcesep + 1
toIndex: [str length]]];
[self setDomain: [str substringFromIndex: nodesep + 1
toIndex: resourcesep]];
return self;
}
- (void)setNode: (OFString*)node_
{
OFString *old = node;
char *nodepart;
Stringprep_rc rc;
if ((rc = stringprep_profile([node_ cString], &nodepart, "Nodeprep", 0))
!= STRINGPREP_OK) {
of_log(@"Nodeprep failed: %s", stringprep_strerror(rc));
assert(0);
}
@try {
node = [[OFString alloc] initWithCString: nodepart];
} @finally {
free(nodepart);
}
[old release];
}
- (void)setDomain: (OFString*)domain_
{
OFString *old = domain;
char *srv;
Stringprep_rc rc;
if ((rc = stringprep_profile([domain_ cString], &srv, "Nameprep", 0))
!= STRINGPREP_OK) {
of_log(@"Nameprep failed: %s", stringprep_strerror(rc));
assert(0);
}
@try {
domain = [[OFString alloc] initWithCString: srv];
} @finally {
free(srv);
}
[old release];
}
- (void)setResource: (OFString*)resource_
{
OFString *old = resource;
char *res;
Stringprep_rc rc;
if ((rc = stringprep_profile([resource_ cString], &res,
"Resourceprep", 0)) != STRINGPREP_OK) {
of_log(@"Resourceprep failed: %s", stringprep_strerror(rc));
assert(0);
}
@try {
resource = [[OFString alloc] initWithCString: res];
} @finally {
free(res);
}
[old release];
}
- (OFString*)bareJID
{
if ([node length])
return [OFString stringWithFormat: @"%@@%@", node, domain];
else
return [OFString stringWithFormat: @"%@", domain];
}
- (OFString*)fullJID
{
if ([node length])
return [OFString stringWithFormat: @"%@@%@/%@",
node, domain, resource];
else
return [OFString stringWithFormat: @"%@/%@",
domain, resource];
}
@end
|
|
|
|
|
>
>
>
>
>
>
|
|
|
<
>
|
|
>
>
>
>
>
>
|
|
|
|
|
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
|
{
self = [super init];
size_t nodesep, resourcesep;
nodesep = [str indexOfFirstOccurrenceOfString: @"@"];
resourcesep = [str indexOfFirstOccurrenceOfString: @"/"];
if (nodesep == SIZE_MAX)
[self setNode: nil];
else
[self setNode: [str substringFromIndex: 0
toIndex: nodesep]];
if (resourcesep == SIZE_MAX) {
[self setResource: nil];
resourcesep = [str length];
} else
[self setResource: [str substringFromIndex: resourcesep + 1
toIndex: [str length]]];
[self setDomain: [str substringFromIndex: nodesep + 1
toIndex: resourcesep]];
return self;
}
- (void)setNode: (OFString*)node_
{
OFString *old = node;
char *nodepart;
Stringprep_rc rc;
if (node_ == nil) {
[old release];
node = nil;
return;
}
if ((rc = stringprep_profile([node_ cString], &nodepart,
"Nodeprep", 0)) != STRINGPREP_OK) {
of_log(@"Nodeprep failed: %s", stringprep_strerror(rc));
assert(0);
}
@try {
node = [[OFString alloc] initWithCString: nodepart];
} @finally {
free(nodepart);
}
[old release];
}
- (void)setDomain: (OFString*)domain_
{
OFString *old = domain;
char *srv;
Stringprep_rc rc;
if ((rc = stringprep_profile([domain_ cString], &srv,
"Nameprep", 0)) != STRINGPREP_OK) {
of_log(@"Nameprep failed: %s", stringprep_strerror(rc));
assert(0);
}
@try {
domain = [[OFString alloc] initWithCString: srv];
} @finally {
free(srv);
}
[old release];
}
- (void)setResource: (OFString*)resource_
{
OFString *old = resource;
char *res;
Stringprep_rc rc;
if (resource_ == nil) {
[old release];
resource = nil;
return;
}
if ((rc = stringprep_profile([resource_ cString], &res,
"Resourceprep", 0)) != STRINGPREP_OK) {
of_log(@"Resourceprep failed: %s", stringprep_strerror(rc));
assert(0);
}
@try {
resource = [[OFString alloc] initWithCString: res];
} @finally {
free(res);
}
[old release];
}
- (OFString*)bareJID
{
if (node != nil)
return [OFString stringWithFormat: @"%@@%@", node, domain];
else
return [OFString stringWithFormat: @"%@", domain];
}
- (OFString*)fullJID
{
if (node != nil)
return [OFString stringWithFormat: @"%@@%@/%@",
node, domain, resource];
else
return [OFString stringWithFormat: @"%@/%@",
domain, resource];
}
@end
|