Perform IDNA's ToASCII operation on the server's domain name
This commit is contained in:
parent
bb8d5e5f05
commit
5e8481027e
3 changed files with 94 additions and 7 deletions
|
@ -24,6 +24,7 @@
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
#include <stringprep.h>
|
#include <stringprep.h>
|
||||||
|
#include <idna.h>
|
||||||
|
|
||||||
#import "XMPPConnection.h"
|
#import "XMPPConnection.h"
|
||||||
#import "XMPPStanza.h"
|
#import "XMPPStanza.h"
|
||||||
|
@ -116,14 +117,15 @@
|
||||||
{
|
{
|
||||||
OFString *old = server;
|
OFString *old = server;
|
||||||
char *srv;
|
char *srv;
|
||||||
Stringprep_rc rc;
|
Idna_rc rc;
|
||||||
|
|
||||||
if ((rc = stringprep_profile([server_ cString], &srv,
|
if ((rc = idna_to_ascii_8z([server_ cString],
|
||||||
"Nameprep", 0)) != STRINGPREP_OK)
|
&srv, IDNA_USE_STD3_ASCII_RULES)) != IDNA_SUCCESS)
|
||||||
@throw [XMPPStringPrepFailedException newWithClass: isa
|
@throw [XMPPIDNATranslationFailedException
|
||||||
connection: self
|
newWithClass: isa
|
||||||
profile: @"Nameprep"
|
connection: self
|
||||||
string: server_];
|
operation: @"ToASCII"
|
||||||
|
string: server_];
|
||||||
|
|
||||||
@try {
|
@try {
|
||||||
server = [[OFString alloc] initWithCString: srv];
|
server = [[OFString alloc] initWithCString: srv];
|
||||||
|
|
|
@ -54,3 +54,21 @@
|
||||||
profile: (OFString*)profile
|
profile: (OFString*)profile
|
||||||
string: (OFString*)string;
|
string: (OFString*)string;
|
||||||
@end
|
@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
|
||||||
|
|
|
@ -144,3 +144,70 @@
|
||||||
return description;
|
return description;
|
||||||
}
|
}
|
||||||
@end
|
@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
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue