Make various XMPPConnection setter accept nil

This commit is contained in:
Florian Zeitz 2013-01-03 23:02:57 +01:00
parent a1645303f7
commit 6f1bcd5c6b

View file

@ -163,22 +163,26 @@
- (void)setUsername: (OFString*)username_ - (void)setUsername: (OFString*)username_
{ {
OFString *old = username; OFString *old = username;
char *node;
Stringprep_rc rc;
if ((rc = stringprep_profile([username_ UTF8String], &node, if (username_ != nil) {
"SASLprep", 0)) != STRINGPREP_OK) char *node;
@throw [XMPPStringPrepFailedException Stringprep_rc rc;
exceptionWithClass: [self class]
connection: self
profile: @"SASLprep"
string: username_];
@try { if ((rc = stringprep_profile([username_ UTF8String], &node,
username = [[OFString alloc] initWithUTF8String: node]; "SASLprep", 0)) != STRINGPREP_OK)
} @finally { @throw [XMPPStringPrepFailedException
free(node); exceptionWithClass: [self class]
} connection: self
profile: @"SASLprep"
string: username_];
@try {
username = [[OFString alloc] initWithUTF8String: node];
} @finally {
free(node);
}
} else
username = nil;
[old release]; [old release];
} }
@ -191,22 +195,26 @@
- (void)setResource: (OFString*)resource_ - (void)setResource: (OFString*)resource_
{ {
OFString *old = resource; OFString *old = resource;
char *res;
Stringprep_rc rc;
if ((rc = stringprep_profile([resource_ UTF8String], &res, if (resource_ != nil) {
"Resourceprep", 0)) != STRINGPREP_OK) char *res;
@throw [XMPPStringPrepFailedException Stringprep_rc rc;
exceptionWithClass: [self class]
connection: self
profile: @"Resourceprep"
string: resource_];
@try { if ((rc = stringprep_profile([resource_ UTF8String], &res,
resource = [[OFString alloc] initWithUTF8String: res]; "Resourceprep", 0)) != STRINGPREP_OK)
} @finally { @throw [XMPPStringPrepFailedException
free(res); exceptionWithClass: [self class]
} connection: self
profile: @"Resourceprep"
string: resource_];
@try {
resource = [[OFString alloc] initWithUTF8String: res];
} @finally {
free(res);
}
} else
resource = nil;
[old release]; [old release];
} }
@ -219,7 +227,12 @@
- (void)setServer: (OFString*)server_ - (void)setServer: (OFString*)server_
{ {
OFString *old = server; OFString *old = server;
server = [self XMPP_IDNAToASCII: server_];
if (server_ != nil)
server = [self XMPP_IDNAToASCII: server_];
else
server = nil;
[old release]; [old release];
} }
@ -232,25 +245,32 @@
{ {
OFString *oldDomain = domain; OFString *oldDomain = domain;
OFString *oldDomainToASCII = domainToASCII; OFString *oldDomainToASCII = domainToASCII;
char *srv;
Stringprep_rc rc;
if ((rc = stringprep_profile([domain_ UTF8String], &srv, if (domain_ != nil) {
"Nameprep", 0)) != STRINGPREP_OK) char *srv;
@throw [XMPPStringPrepFailedException Stringprep_rc rc;
exceptionWithClass: [self class]
connection: self
profile: @"Nameprep"
string: domain_];
@try { if ((rc = stringprep_profile([domain_ UTF8String], &srv,
domain = [[OFString alloc] initWithUTF8String: srv]; "Nameprep", 0)) != STRINGPREP_OK)
} @finally { @throw [XMPPStringPrepFailedException
free(srv); exceptionWithClass: [self class]
connection: self
profile: @"Nameprep"
string: domain_];
@try {
domain = [[OFString alloc] initWithUTF8String: srv];
} @finally {
free(srv);
}
domainToASCII = [self XMPP_IDNAToASCII: domain];
} else {
domain = nil;
domainToASCII = nil;
} }
[oldDomain release];
domainToASCII = [self XMPP_IDNAToASCII: domain]; [oldDomain release];
[oldDomainToASCII release]; [oldDomainToASCII release];
} }
@ -262,22 +282,26 @@
- (void)setPassword: (OFString*)password_ - (void)setPassword: (OFString*)password_
{ {
OFString *old = password; OFString *old = password;
char *pass;
Stringprep_rc rc;
if ((rc = stringprep_profile([password_ UTF8String], &pass, if (password_ != nil) {
"SASLprep", 0)) != STRINGPREP_OK) char *pass;
@throw [XMPPStringPrepFailedException Stringprep_rc rc;
exceptionWithClass: [self class]
connection: self
profile: @"SASLprep"
string: password_];
@try { if ((rc = stringprep_profile([password_ UTF8String], &pass,
password = [[OFString alloc] initWithUTF8String: pass]; "SASLprep", 0)) != STRINGPREP_OK)
} @finally { @throw [XMPPStringPrepFailedException
free(pass); exceptionWithClass: [self class]
} connection: self
profile: @"SASLprep"
string: password_];
@try {
password = [[OFString alloc] initWithUTF8String: pass];
} @finally {
free(pass);
}
} else
password = nil;
[old release]; [old release];
} }