From 5e8481027ed07f7215ef07c6982e57cc6783babd Mon Sep 17 00:00:00 2001 From: Florian Zeitz Date: Fri, 18 Feb 2011 01:56:41 +0100 Subject: [PATCH] Perform IDNA's ToASCII operation on the server's domain name --- src/XMPPConnection.m | 16 ++++++----- src/XMPPExceptions.h | 18 ++++++++++++ src/XMPPExceptions.m | 67 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 94 insertions(+), 7 deletions(-) diff --git a/src/XMPPConnection.m b/src/XMPPConnection.m index c072cac..3264682 100644 --- a/src/XMPPConnection.m +++ b/src/XMPPConnection.m @@ -24,6 +24,7 @@ #include #include +#include #import "XMPPConnection.h" #import "XMPPStanza.h" @@ -116,14 +117,15 @@ { OFString *old = server; char *srv; - Stringprep_rc rc; + Idna_rc rc; - if ((rc = stringprep_profile([server_ cString], &srv, - "Nameprep", 0)) != STRINGPREP_OK) - @throw [XMPPStringPrepFailedException newWithClass: isa - connection: self - profile: @"Nameprep" - string: server_]; + if ((rc = idna_to_ascii_8z([server_ cString], + &srv, IDNA_USE_STD3_ASCII_RULES)) != IDNA_SUCCESS) + @throw [XMPPIDNATranslationFailedException + newWithClass: isa + connection: self + operation: @"ToASCII" + string: server_]; @try { server = [[OFString alloc] initWithCString: srv]; diff --git a/src/XMPPExceptions.h b/src/XMPPExceptions.h index 09b2006..7261c0d 100644 --- a/src/XMPPExceptions.h +++ b/src/XMPPExceptions.h @@ -54,3 +54,21 @@ profile: (OFString*)profile string: (OFString*)string; @end + +@interface XMPPIDNATranslationFailedException: XMPPException +{ + OFString *operation; + OFString *string; +} + +@property (readonly, nonatomic) OFString *operation, *string; + ++ newWithClass: (Class)class_ + connection: (XMPPConnection*)conn + operation: (OFString*)operation + string: (OFString*)string; +- initWithClass: (Class)class_ + connection: (XMPPConnection*)conn + operation: (OFString*)operation + string: (OFString*)string; +@end diff --git a/src/XMPPExceptions.m b/src/XMPPExceptions.m index 5be364d..2d81544 100644 --- a/src/XMPPExceptions.m +++ b/src/XMPPExceptions.m @@ -144,3 +144,70 @@ return description; } @end + +@implementation XMPPIDNATranslationFailedException +@synthesize operation, string; + ++ newWithClass: (Class)class_ + connection: (XMPPConnection*)conn + operation: (OFString*)operation + string: (OFString*)string +{ + return [[self alloc] initWithClass: class_ + connection: conn + operation: operation + string: string]; +} + +- initWithClass: (Class)class_ + connection: (XMPPConnection*)conn +{ + Class c = isa; + [self release]; + @throw [OFNotImplementedException newWithClass: c + selector: _cmd]; +} + +- initWithClass: (Class)class_ + connection: (XMPPConnection*)conn + operation: (OFString*)operation_ + string: (OFString*)string_ +{ + self = [super initWithClass: class_ + connection: conn]; + + @try { + operation = [operation_ copy]; + string = [string_ copy]; + } @catch (id e) { + [self release]; + @throw e; + } + + return self; +} + +- (void)dealloc +{ + [operation release]; + [string release]; + + [super dealloc]; +} + +- (OFString*)description +{ + OFAutoreleasePool *pool; + + if (description != nil) + return description; + + pool = [[OFAutoreleasePool alloc] init]; + description = [[OFString alloc] initWithFormat: + @"IDNA operation %@ failed on string '%@'!", + operation, string]; + [pool release]; + + return description; +} +@end