forked from robbiehanson/XMPPFramework
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathXMPPStringPrep.m
67 lines (44 loc) · 1.79 KB
/
XMPPStringPrep.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
#import "XMPPStringPrep.h"
#import "stringprep.h"
@implementation XMPPStringPrep
+ (NSString *)prepNode:(NSString *)node
{
if(node == nil) return nil;
// Each allowable portion of a JID MUST NOT be more than 1023 bytes in length.
// We make the buffer just big enough to hold a null-terminated string of this length.
char buf[1024];
strncpy(buf, [node UTF8String], sizeof(buf));
if(stringprep_xmpp_nodeprep(buf, sizeof(buf)) != 0) return nil;
return [NSString stringWithUTF8String:buf];
}
+ (NSString *)prepDomain:(NSString *)domain
{
if(domain == nil) return nil;
// Each allowable portion of a JID MUST NOT be more than 1023 bytes in length.
// We make the buffer just big enough to hold a null-terminated string of this length.
char buf[1024];
strncpy(buf, [domain UTF8String], sizeof(buf));
if(stringprep_nameprep(buf, sizeof(buf)) != 0) return nil;
return [NSString stringWithUTF8String:buf];
}
+ (NSString *)prepResource:(NSString *)resource
{
if(resource == nil) return nil;
// Each allowable portion of a JID MUST NOT be more than 1023 bytes in length.
// We make the buffer just big enough to hold a null-terminated string of this length.
char buf[1024];
strncpy(buf, [resource UTF8String], sizeof(buf));
if(stringprep_xmpp_resourceprep(buf, sizeof(buf)) != 0) return nil;
return [NSString stringWithUTF8String:buf];
}
+ (NSString *)prepPassword:(NSString *)password
{
if(password == nil) return nil;
// Each allowable portion of a JID MUST NOT be more than 1023 bytes in length.
// We make the buffer just big enough to hold a null-terminated string of this length.
char buf[1024];
strncpy(buf, [password UTF8String], sizeof(buf));
if(stringprep(buf, sizeof(buf), 0, stringprep_saslprep) != 0) return nil;
return [NSString stringWithUTF8String:buf];
}
@end