Skip to content

Commit

Permalink
NSXML doesn't output the default namespace (via XMLString) if it was …
Browse files Browse the repository at this point in the history
…set via setURI:. To get around this but I was manually adding an attribute named "xmlns". Now switching to using addNamespace: and supplying a namespace created with an empty string prefix. This is the correct way to do it.

git-svn-id: http://xmppframework.googlecode.com/svn/trunk@43 69bd8580-3047-0410-960a-a116b6c96ec9
  • Loading branch information
deusty committed Sep 29, 2008
1 parent f135e75 commit 634f16e
Show file tree
Hide file tree
Showing 7 changed files with 250 additions and 190 deletions.
5 changes: 4 additions & 1 deletion NSXMLElementAdditions.h
Expand Up @@ -3,11 +3,14 @@

@interface NSXMLElement (XMPPStreamAdditions)

+ (NSXMLElement *)elementWithName:(NSString *)name attribute:(NSString *)attribute stringValue:(NSString *)string;
+ (NSXMLElement *)elementWithName:(NSString *)name xmlns:(NSString *)ns;

- (NSXMLElement *)elementForName:(NSString *)name;
- (NSXMLElement *)elementForName:(NSString *)name xmlns:(NSString *)xmlns;

- (NSString *)xmlns;
- (void)setXmlns:(NSString *)ns;

- (void)addAttributeWithName:(NSString *)name stringValue:(NSString *)string;
- (NSDictionary *)attributesAsDictionary;

Expand Down
12 changes: 10 additions & 2 deletions NSXMLElementAdditions.m
Expand Up @@ -5,10 +5,10 @@ @implementation NSXMLElement (XMPPStreamAdditions)
/**
* Quick method to create an element
**/
+ (NSXMLElement *)elementWithName:(NSString *)name attribute:(NSString *)attribute stringValue:(NSString *)string
+ (NSXMLElement *)elementWithName:(NSString *)name xmlns:(NSString *)ns
{
NSXMLElement *element = [NSXMLElement elementWithName:name];
[element addAttributeWithName:attribute stringValue:string];
[element setXmlns:ns];
return element;
}

Expand Down Expand Up @@ -72,6 +72,14 @@ - (NSString *)xmlns
return [[self namespaceForPrefix:@""] stringValue];
}

- (void)setXmlns:(NSString *)ns
{
// If we use setURI: then the xmlns won't be displayed in the XMLString.
// Adding the namespace this way works properly.

[self addNamespace:[NSXMLNode namespaceWithName:@"" stringValue:ns]];
}

/**
* Shortcut to avoid having to use NSXMLNode everytime
**/
Expand Down
15 changes: 5 additions & 10 deletions XMPPClient.m
Expand Up @@ -327,8 +327,7 @@ - (void)goOffline

- (void)fetchRoster
{
NSXMLElement *query = [NSXMLElement elementWithName:@"query"];
[query addAttributeWithName:@"xmlns" stringValue:@"jabber:iq:roster"];
NSXMLElement *query = [NSXMLElement elementWithName:@"query" xmlns:@"jabber:iq:roster"];

NSXMLElement *iq = [NSXMLElement elementWithName:@"iq"];
[iq addAttributeWithName:@"type" stringValue:@"get"];
Expand All @@ -349,8 +348,7 @@ - (void)addBuddy:(XMPPJID *)jid withNickname:(NSString *)optionalName
[item addAttributeWithName:@"name" stringValue:optionalName];
}

NSXMLElement *query = [NSXMLElement elementWithName:@"query"];
[query addAttributeWithName:@"xmlns" stringValue:@"jabber:iq:roster"];
NSXMLElement *query = [NSXMLElement elementWithName:@"query" xmlns:@"jabber:iq:roster"];
[query addChild:item];

NSXMLElement *iq = [NSXMLElement elementWithName:@"iq"];
Expand Down Expand Up @@ -380,8 +378,7 @@ - (void)removeBuddy:(XMPPJID *)jid
[item addAttributeWithName:@"jid" stringValue:[jid bare]];
[item addAttributeWithName:@"subscription" stringValue:@"remove"];

NSXMLElement *query = [NSXMLElement elementWithName:@"query"];
[query addAttributeWithName:@"xmlns" stringValue:@"jabber:iq:roster"];
NSXMLElement *query = [NSXMLElement elementWithName:@"query" xmlns:@"jabber:iq:roster"];
[query addChild:item];

NSXMLElement *iq = [NSXMLElement elementWithName:@"iq"];
Expand All @@ -399,8 +396,7 @@ - (void)setNickname:(NSString *)nickname forBuddy:(XMPPJID *)jid
[item addAttributeWithName:@"jid" stringValue:[jid bare]];
[item addAttributeWithName:@"name" stringValue:nickname];

NSXMLElement *query = [NSXMLElement elementWithName:@"query"];
[query addAttributeWithName:@"xmlns" stringValue:@"jabber:iq:roster"];
NSXMLElement *query = [NSXMLElement elementWithName:@"query" xmlns:@"jabber:iq:roster"];
[query addChild:item];

NSXMLElement *iq = [NSXMLElement elementWithName:@"iq"];
Expand All @@ -423,8 +419,7 @@ - (void)acceptBuddyRequest:(XMPPJID *)jid
NSXMLElement *item = [NSXMLElement elementWithName:@"item"];
[item addAttributeWithName:@"jid" stringValue:[jid bare]];

NSXMLElement *query = [NSXMLElement elementWithName:@"query"];
[query addAttributeWithName:@"xmlns" stringValue:@"jabber:iq:roster"];
NSXMLElement *query = [NSXMLElement elementWithName:@"query" xmlns:@"jabber:iq:roster"];
[query addChild:item];

NSXMLElement *iq = [NSXMLElement elementWithName:@"iq"];
Expand Down
26 changes: 9 additions & 17 deletions XMPPStream.m
Expand Up @@ -286,8 +286,7 @@ - (void)registerUser:(NSString *)username withPassword:(NSString *)password
{
if([self supportsInBandRegistration])
{
NSXMLElement *queryElement = [NSXMLElement elementWithName:@"query"];
[queryElement addAttributeWithName:@"xmlns" stringValue:@"jabber:iq:register"];
NSXMLElement *queryElement = [NSXMLElement elementWithName:@"query" xmlns:@"jabber:iq:register"];
[queryElement addChild:[NSXMLElement elementWithName:@"username" stringValue:username]];
[queryElement addChild:[NSXMLElement elementWithName:@"password" stringValue:password]];

Expand Down Expand Up @@ -415,8 +414,7 @@ - (void)authenticateUser:(NSString *)username
NSString *payload = [NSString stringWithFormat:@"%C%@%C%@", 0, username, 0, password];
NSString *base64 = [[payload dataUsingEncoding:NSUTF8StringEncoding] base64Encoded];

NSXMLElement *auth = [NSXMLElement elementWithName:@"auth"];
[auth addAttributeWithName:@"xmlns" stringValue:@"urn:ietf:params:xml:ns:xmpp-sasl"];
NSXMLElement *auth = [NSXMLElement elementWithName:@"auth" xmlns:@"urn:ietf:params:xml:ns:xmpp-sasl"];
[auth addAttributeWithName:@"mechanism" stringValue:@"PLAIN"];
[auth setStringValue:base64];

Expand Down Expand Up @@ -448,8 +446,7 @@ - (void)authenticateUser:(NSString *)username

NSString *digest = [[digestData sha1Digest] hexStringValue];

NSXMLElement *queryElement = [NSXMLElement elementWithName:@"query"];
[queryElement addAttributeWithName:@"xmlns" stringValue:@"jabber:iq:auth"];
NSXMLElement *queryElement = [NSXMLElement elementWithName:@"query" xmlns:@"jabber:iq:auth"];
[queryElement addChild:[NSXMLElement elementWithName:@"username" stringValue:username]];
[queryElement addChild:[NSXMLElement elementWithName:@"digest" stringValue:digest]];
[queryElement addChild:[NSXMLElement elementWithName:@"resource" stringValue:resource]];
Expand Down Expand Up @@ -658,8 +655,7 @@ - (void)handleStreamFeatures
NSXMLElement *resource = [NSXMLElement elementWithName:@"resource"];
[resource setStringValue:authResource];

NSXMLElement *bind = [NSXMLElement elementWithName:@"bind"];
[bind addAttributeWithName:@"xmlns" stringValue:@"urn:ietf:params:xml:ns:xmpp-bind"];
NSXMLElement *bind = [NSXMLElement elementWithName:@"bind" xmlns:@"urn:ietf:params:xml:ns:xmpp-bind"];
[bind addChild:resource];

NSXMLElement *iq = [NSXMLElement elementWithName:@"iq"];
Expand All @@ -677,8 +673,7 @@ - (void)handleStreamFeatures
{
// The user didn't specify a resource, so we ask the server to bind one for us

NSXMLElement *bind = [NSXMLElement elementWithName:@"bind"];
[bind addAttributeWithName:@"xmlns" stringValue:@"urn:ietf:params:xml:ns:xmpp-bind"];
NSXMLElement *bind = [NSXMLElement elementWithName:@"bind" xmlns:@"urn:ietf:params:xml:ns:xmpp-bind"];

NSXMLElement *iq = [NSXMLElement elementWithName:@"iq"];
[iq addAttributeWithName:@"type" stringValue:@"set"];
Expand Down Expand Up @@ -838,8 +833,7 @@ - (void)handleAuth1:(NSXMLElement *)response
[auth setUsername:authUsername password:tempPassword];

// Create and send challenge response element
NSXMLElement *cr = [NSXMLElement elementWithName:@"response"];
[cr addAttributeWithName:@"xmlns" stringValue:@"urn:ietf:params:xml:ns:xmpp-sasl"];
NSXMLElement *cr = [NSXMLElement elementWithName:@"response" xmlns:@"urn:ietf:params:xml:ns:xmpp-sasl"];
[cr setStringValue:[auth base64EncodedFullResponse]];

if(DEBUG_SEND) {
Expand Down Expand Up @@ -948,8 +942,7 @@ - (void)handleAuth2:(NSXMLElement *)response
// but many implementations incorrectly send it inside a second challenge request.

// Create and send empty challenge response element
NSXMLElement *cr = [NSXMLElement elementWithName:@"response"];
[cr addAttributeWithName:@"xmlns" stringValue:@"urn:ietf:params:xml:ns:xmpp-sasl"];
NSXMLElement *cr = [NSXMLElement elementWithName:@"response" xmlns:@"urn:ietf:params:xml:ns:xmpp-sasl"];

if(DEBUG_SEND) {
NSLog(@"SEND: %@", [cr XMLString]);
Expand Down Expand Up @@ -1009,7 +1002,7 @@ - (void)handleBinding:(NSXMLElement *)response
if(f_session)
{
NSXMLElement *session = [NSXMLElement elementWithName:@"session"];
[session addAttributeWithName:@"xmlns" stringValue:@"urn:ietf:params:xml:ns:xmpp-session"];
[session setXmlns:@"urn:ietf:params:xml:ns:xmpp-session"];

NSXMLElement *iq = [NSXMLElement elementWithName:@"iq"];
[iq addAttributeWithName:@"type" stringValue:@"set"];
Expand Down Expand Up @@ -1043,8 +1036,7 @@ - (void)handleBinding:(NSXMLElement *)response
// It appears the server didn't allow our resource choice
// We'll simply let the server choose then

NSXMLElement *bind = [NSXMLElement elementWithName:@"bind"];
[bind addAttributeWithName:@"xmlns" stringValue:@"urn:ietf:params:xml:ns:xmpp-bind"];
NSXMLElement *bind = [NSXMLElement elementWithName:@"bind" xmlns:@"urn:ietf:params:xml:ns:xmpp-bind"];

NSXMLElement *iq = [NSXMLElement elementWithName:@"iq"];
[iq addAttributeWithName:@"type" stringValue:@"set"];
Expand Down
54 changes: 32 additions & 22 deletions XMPPStream.xcodeproj/robbie.mode1v3
Expand Up @@ -248,8 +248,6 @@
<key>Layout</key>
<array>
<dict>
<key>BecomeActive</key>
<true/>
<key>ContentConfiguration</key>
<dict>
<key>PBXBottomSmartGroupGIDs</key>
Expand Down Expand Up @@ -302,6 +300,8 @@
<key>PBXSmartGroupTreeModuleOutlineStateSelectionKey</key>
<array>
<array>
<integer>16</integer>
<integer>14</integer>
<integer>13</integer>
<integer>0</integer>
</array>
Expand Down Expand Up @@ -337,48 +337,57 @@
<key>Dock</key>
<array>
<dict>
<key>BecomeActive</key>
<true/>
<key>ContentConfiguration</key>
<dict>
<key>PBXProjectModuleGUID</key>
<string>1CE0B20306471E060097A5F4</string>
<key>PBXProjectModuleLabel</key>
<string>XMPPStream.m</string>
<string>XMPPClient.m</string>
<key>PBXSplitModuleInNavigatorKey</key>
<dict>
<key>Split0</key>
<dict>
<key>PBXProjectModuleGUID</key>
<string>1CE0B20406471E060097A5F4</string>
<key>PBXProjectModuleLabel</key>
<string>XMPPStream.m</string>
<string>XMPPClient.m</string>
<key>_historyCapacity</key>
<integer>10</integer>
<key>bookmark</key>
<string>DC433BAE0E917D4C00F2C4D4</string>
<string>DC433C050E9182B900F2C4D4</string>
<key>history</key>
<array>
<string>DC54413B0E8D566300013051</string>
<string>DC54413C0E8D566300013051</string>
<string>DC54413D0E8D566300013051</string>
<string>DC54413E0E8D566300013051</string>
<string>DC54413F0E8D566300013051</string>
<string>DC5441400E8D566300013051</string>
<string>DC5441410E8D566300013051</string>
<string>DC5441420E8D566300013051</string>
<string>DC5442400E8F331E00013051</string>
<string>DC5442430E8F331E00013051</string>
<string>DC433BC70E91801900F2C4D4</string>
<string>DC433BF40E91828E00F2C4D4</string>
<string>DC433BF50E91828E00F2C4D4</string>
<string>DC433BF60E91828E00F2C4D4</string>
<string>DC433BF70E91828E00F2C4D4</string>
</array>
<key>prevStack</key>
<array>
<string>DC5441450E8D566300013051</string>
<string>DC5441460E8D566300013051</string>
<string>DC5441470E8D566300013051</string>
<string>DC5441480E8D566300013051</string>
<string>DC5441490E8D566300013051</string>
<string>DC54414A0E8D566300013051</string>
<string>DC54414B0E8D566300013051</string>
<string>DC54414C0E8D566300013051</string>
<string>DC5442420E8F331E00013051</string>
<string>DC433BCB0E91801900F2C4D4</string>
<string>DC433BCC0E91801900F2C4D4</string>
<string>DC433BCD0E91801900F2C4D4</string>
<string>DC433BF80E91828E00F2C4D4</string>
<string>DC433BF90E91828E00F2C4D4</string>
<string>DC433BFA0E91828E00F2C4D4</string>
<string>DC433BFB0E91828E00F2C4D4</string>
<string>DC433BFC0E91828E00F2C4D4</string>
<string>DC433BFD0E91828E00F2C4D4</string>
<string>DC433BFE0E91828E00F2C4D4</string>
</array>
</dict>
<key>SplitCount</key>
Expand Down Expand Up @@ -563,7 +572,7 @@
<key>StatusbarIsVisible</key>
<true/>
<key>TimeStamp</key>
<real>244415820.228861</real>
<real>244417209.62928399</real>
<key>ToolbarDisplayMode</key>
<integer>1</integer>
<key>ToolbarIsVisible</key>
Expand All @@ -578,10 +587,11 @@
<integer>5</integer>
<key>WindowOrderList</key>
<array>
<string>1C530D57069F1CE1000CFCEE</string>
<string>1C78EAAD065D492600B07095</string>
<string>1CD10A99069EF8BA00B06720</string>
<string>DCF825810D748AB600BFABDE</string>
<string>/Users/robbie/Programs/Google Code/XMPPFramework/XMPPStream.xcodeproj</string>
<string>1C78EAAD065D492600B07095</string>
</array>
<key>WindowString</key>
<string>64 89 1182 827 0 0 1680 1028 </string>
Expand Down Expand Up @@ -614,7 +624,7 @@
<key>Frame</key>
<string>{{0, 0}, {1080, 0}}</string>
<key>RubberWindowFrame</key>
<string>587 91 1080 379 0 0 1680 1028 </string>
<string>532 -49 1080 379 0 0 1680 1028 </string>
</dict>
<key>Module</key>
<string>PBXNavigatorGroup</string>
Expand All @@ -640,7 +650,7 @@
<key>Frame</key>
<string>{{0, 5}, {1080, 333}}</string>
<key>RubberWindowFrame</key>
<string>587 91 1080 379 0 0 1680 1028 </string>
<string>532 -49 1080 379 0 0 1680 1028 </string>
</dict>
<key>Module</key>
<string>PBXBuildResultsModule</string>
Expand Down Expand Up @@ -670,7 +680,7 @@
<key>ToolbarConfiguration</key>
<string>xcode.toolbar.config.buildV3</string>
<key>WindowString</key>
<string>587 91 1080 379 0 0 1680 1028 </string>
<string>532 -49 1080 379 0 0 1680 1028 </string>
<key>WindowToolGUID</key>
<string>DCF825810D748AB600BFABDE</string>
<key>WindowToolIsVisible</key>
Expand Down Expand Up @@ -821,7 +831,7 @@
<key>PBXProjectModuleGUID</key>
<string>1CDD528C0622207200134675</string>
<key>PBXProjectModuleLabel</key>
<string>XMPPUser.m</string>
<string>XMPPStream.m</string>
<key>StatusBarVisibility</key>
<true/>
</dict>
Expand Down Expand Up @@ -879,8 +889,8 @@
<key>TableOfContents</key>
<array>
<string>1C530D57069F1CE1000CFCEE</string>
<string>DCEFA0070E8D442B006E145E</string>
<string>DCEFA0080E8D442B006E145E</string>
<string>DC433BBC0E91800D00F2C4D4</string>
<string>DC433BBD0E91800D00F2C4D4</string>
<string>1CDD528C0622207200134675</string>
<string>1CD0528E0623707200166675</string>
</array>
Expand Down Expand Up @@ -957,7 +967,7 @@
<key>WindowToolGUID</key>
<string>1C78EAAD065D492600B07095</string>
<key>WindowToolIsVisible</key>
<true/>
<false/>
</dict>
<dict>
<key>Identifier</key>
Expand Down

0 comments on commit 634f16e

Please sign in to comment.