Skip to content
This repository
tag: 3.2
Fetching contributors…

Cannot retrieve contributors at this time

file 52 lines (34 sloc) 1.371 kb
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
#import "LibIDN.h"
#import "stringprep.h"


@implementation LibIDN

+ (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];
}

@end
Something went wrong with that request. Please try again.