Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

add TNStropheJID

  • Loading branch information...
commit 1c50a121eaf83c33462e6dfd70bb029c78feb114 1 parent 521168d
Antoine Mercadal authored
View
2  Jakefile
@@ -112,7 +112,7 @@ task("test", function()
var tests = new FileList('Test/*Test.j');
var cmd = ["ojtest"].concat(tests.items());
var cmdString = cmd.map(OS.enquote).join(" ");
-
+
var code = OS.system(cmdString);
if (code !== 0)
OS.exit(code);
View
38 MUC/TNStropheMUCRoom.j
@@ -12,7 +12,7 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
- *
+ *
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
@@ -21,6 +21,7 @@
@import <Foundation/Foundation.j>
@import "../TNStropheGlobals.j"
+@import "../TNStropheJID.j"
@import "../TNStropheConnection.j"
@import "../TNStropheStanza.j"
@import "TNStropheMUCRoster.j"
@@ -32,16 +33,14 @@
*/
@implementation TNStropheMUCRoom : CPObject
{
- CPString _roomName @accessors(getter=name);
- CPString _service @accessors(getter=service);
- CPString _nick @accessors(getter=nick);
+ TNStropheJID _roomJID @accessors(getter=roomJID);
+ id _delegate @accessors(property=delegate);
CPString _subject @accessors(getter=subject);
CPArray _messages @accessors(getter=messages);
TNStropheMUCRoster _roster @accessors(getter=roster);
TNStropheConnection _connection;
CPArray _handlerIDs;
- id _delegate @accessors(property=delegate);
}
#pragma mark -
@@ -72,10 +71,8 @@
self = [super init];
if (self)
{
- _roomName = aRoom;
- _service = aService;
_connection = aConnection;
- _nick = aNick;
+ _roomJID = [TNStropheJID stropheJIDWithNode:aRoom domain:aService resource:aNick];
_handlerIDs = [CPArray array];
_messages = [CPArray array];
_roster = [TNStropheMUCRoster rosterWithConnection:_connection forRoom:self];
@@ -87,35 +84,25 @@
#pragma mark -
#pragma mark Membership
-- (CPString)roomJID
-{
- return _roomName + @"@" + _service;
-}
-
-// Includes own nick as resource
-- (CPString)ownRoomJID
-{
- return [self roomJID] + @"/" + _nick;
-}
-
- (TNStropheStanza)directedPresence
{
- return [TNStropheStanza presenceWithAttributes:{"to": [self ownRoomJID]}];
+ return [TNStropheStanza presenceTo:_roomJID];
}
- (void)join
{
+ alert([_roomJID bare]);
// Handle messages sent to room
- var messageParams = [CPDictionary dictionaryWithObjectsAndKeys:@"message",@"name",
- [self roomJID],@"from",
- @"groupchat",@"type",
+ var messageParams = [CPDictionary dictionaryWithObjectsAndKeys:@"message", @"name",
+ [_roomJID bare], @"from",
+ @"groupchat", @"type",
{matchBare: true},@"options"],
messageHandler = [_connection registerSelector:@selector(receiveMessage:) ofObject:self withDict:messageParams];
[_handlerIDs addObject:messageHandler];
// Handle private messages from room roster
var pmParams = [CPDictionary dictionaryWithObjectsAndKeys:@"message",@"name",
- [self roomJID],@"from",
+ [_roomJID bare],@"from",
@"chat",@"type",
{matchBare: true},@"options"],
pmHandler = [_connection registerSelector:@selector(receivePrivateMessage:) ofObject:self withDict:pmParams];
@@ -162,12 +149,13 @@
- (void)sendStanzaToRoom:(TNStropheStanza)aStanza
{
- [aStanza setTo:[self roomJID]];
+ [aStanza setTo:_roomJID];
[_connection send:aStanza];
}
- (BOOL)receiveMessage:(TNStropheStanza)aStanza
{
+ alert("bin");
if ([aStanza containsChildrenWithName:@"subject"])
{
_subject = [[aStanza firstChildWithName:@"subject"] text];
View
6 MUC/TNStropheMUCRoster.j
@@ -12,7 +12,7 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
- *
+ *
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
@@ -63,7 +63,7 @@
_owners = [TNStropheGroup stropheGroupWithName:@"Owners"];
var params = [CPDictionary dictionaryWithObjectsAndKeys:@"presence", @"name",
- [_room roomJID], @"from",
+ [[_room roomJID] bare], @"from",
{matchBare: true}, @"options"];
[_connection registerSelector:@selector(_didReceivePresence:) ofObject:self withDict:params];
}
@@ -127,7 +127,7 @@
@param aGroup the group of the new contact. if nil, it will be _visitors
@return the new TNStropheContact
*/
-- (TNStropheContact)addContact:(CPString)aJID withName:(CPString)aName inGroup:(TNStropheGroup)aGroup
+- (TNStropheContact)addContact:(TNStropheJID)aJID withName:(CPString)aName inGroup:(TNStropheGroup)aGroup
{
if ([self containsJID:aJID] == YES)
return;
View
41 PubSub/TNPubSubController.j
@@ -12,7 +12,7 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
- *
+ *
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
@@ -86,6 +86,7 @@
return node;
}
+
- (TNPubSubNode)nodeWithName:(CPString)aNodeName
{
for (var i = 0; i < [_nodes count]; i++)
@@ -155,6 +156,44 @@
#pragma mark -
#pragma mark Subscription Management
+- (void)retrieveSubscriptionsForNode:(TNPubSubNode)aNode
+{
+ var uid = [_connection getUniqueId],
+ stanza = [TNStropheStanza iqWithAttributes:{"type": "get", "to": _server, "id": uid}],
+ params = [CPDictionary dictionaryWithObjectsAndKeys:uid,@"id"];
+
+ [stanza addChildWithName:@"pubsub" andAttributes:{"xmlns": Strophe.NS.PUBSUB}];
+ [stanza addChildWithName:@"subscriptions"];
+ [stanza setValue:[aNode name] forAttribute:@"node"]
+
+ [_connection registerSelector:@selector(_didRetrieveNodeSubscriptions:userInfo:) ofObject:self withDict:params userInfo:aNode];
+
+ [_connection send:stanza];
+}
+
+- (BOOL)_didRetrieveNodeSubscriptions:(TNStropheStanza)aStanza userInfo:(TNPubSubNode)aNode
+{
+ if ([aStanza type] == @"result")
+ {
+ var subscriptions = [aStanza childrenWithName:@"subscription"];
+
+ for (var i = 0; i < [subscriptions count]; i++)
+ {
+ var subscription = [subscriptions objectAtIndex:i],
+ subid = [subscription valueForAttribute:@"subid"];
+
+ [aNode addSubscriptionID:subid];
+ }
+
+ [[CPNotificationCenter defaultCenter] postNotificationName:TNStrophePubSubSubscriptionsRetrievedNotification object:self];
+ }
+ else
+ CPLog.error("Cannot retrieve the contents of pubsub node with name: " + _nodeName);
+
+ return NO;
+}
+
+
- (void)retrieveAllSubscriptions
{
var uid = [_connection getUniqueId],
View
9 PubSub/TNPubSubNode.j
@@ -12,7 +12,7 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
- *
+ *
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
@@ -87,7 +87,7 @@
{
_nodeName = aNodeName;
_connection = aConnection;
- _pubSubServer = aPubSubServer ? aPubSubServer : [_connection JID].split("@")[1].split("/")[0];
+ _pubSubServer = aPubSubServer ? aPubSubServer : [[_connection JID] domain];
_subscriptionIDs = [CPArray array];
}
@@ -158,6 +158,7 @@
{
_content = [aStanza childrenWithName:@"item"];
[[CPNotificationCenter defaultCenter] postNotificationName:TNStrophePubSubNodeRetrievedNotification object:self];
+
}
else
CPLog.error("Cannot retrieve the contents of pubsub node with name: " + _nodeName);
@@ -427,7 +428,7 @@
[stanza setTo:_pubSubServer];
[stanza addChildWithName:@"pubsub" andAttributes:{@"xmlns": Strophe.NS.PUBSUB}];
- [stanza addChildWithName:@"subscribe" andAttributes:{@"node": _nodeName, @"jid": [_connection JID]}];
+ [stanza addChildWithName:@"subscribe" andAttributes:{@"node": _nodeName, @"jid": [[_connection JID] bare]}];
if (options && [options count] > 0)
{
@@ -503,7 +504,7 @@
[stanza setTo:_pubSubServer];
[stanza addChildWithName:@"pubsub" andAttributes:{"xmlns": Strophe.NS.PUBSUB}];
- [stanza addChildWithName:@"unsubscribe" andAttributes:{"node": _nodeName, "jid": [_connection JID]}];
+ [stanza addChildWithName:@"unsubscribe" andAttributes:{"node": _nodeName, "jid": [[_connection JID] bare]}];
if (aSubID)
[stanza setValue:aSubID forAttribute:@"subid"];
View
1  StropheCappuccino.j
@@ -20,6 +20,7 @@
@import "Resources/Strophe/strophe.js"
@import "Resources/Strophe/sha1.js"
+@import "TNStropheJID.j"
@import "TNStropheStanza.j"
@import "TNStropheGroup.j"
@import "TNStropheConnection.j"
View
80 TNStropheConnection.j
@@ -20,6 +20,7 @@
@import <Foundation/Foundation.j>
+@import "TNStropheJID.j"
@import "TNStropheStanza.j"
@import "Resources/Strophe/sha1.js"
@import "TNStropheGlobals.j"
@@ -70,13 +71,11 @@
BOOL _connected @accessors(getter=isConnected);
CPArray _features @accessors(readonly);
CPString _clientNode @accessors(property=clientNode);
- CPString _fullJID @accessors(property=fullJID);
CPString _identityCategory @accessors(property=identityCategory);
CPString _identityName @accessors(property=identityName);
CPString _identityType @accessors(property=identityType);
- CPString _JID @accessors(property=JID);
+ TNStropheJID _JID @accessors(property=JID);
CPString _password @accessors(property=password);
- CPString _resource @accessors(property=resource);
id _delegate @accessors(property=delegate);
int _maxConnections @accessors(property=maxConnections);
int _connectionTimeout @accessors(property=connectionTimeout);
@@ -113,15 +112,11 @@
@return a valid TNStropheConnection
*/
-+ (TNStropheConnection)connectionWithService:(CPString)aService JID:(CPString)aJID password:(CPString)aPassword
++ (TNStropheConnection)connectionWithService:(CPString)aService JID:(TNStropheJID)aJID password:(CPString)aPassword
{
return [[TNStropheConnection alloc] initWithService:aService JID:aJID password:aPassword];
}
-+ (TNStropheConnection)connectionWithService:(CPString)aService JID:(CPString)aJID resource:(CPString)aResource password:(CPString)aPassword
-{
- return [[TNStropheConnection alloc] initWithService:aService JID:aJID resource:aResource password:aPassword];
-}
#pragma mark -
#pragma mark Initialization
@@ -159,7 +154,7 @@
@param aJID a JID to connect to the XMPP server
@param aPassword the password associated to the JID
*/
-- (id)initWithService:(CPString)aService JID:(CPString)aJID password:(CPString)aPassword
+- (id)initWithService:(CPString)aService JID:(TNStropheJID)aJID password:(CPString)aPassword
{
if (self = [self initWithService:aService])
{
@@ -170,16 +165,6 @@
return self;
}
-- (id)initWithService:(CPString)aService JID:(CPString)aJID resource:(CPString)aResource password:(CPString)aPassword
-{
- if (self = [self initWithService:aService JID:aJID password:aPassword])
- {
- _resource = aResource || [self getUniqueId];
- }
-
- return self;
-}
-
#pragma mark -
#pragma mark Connection
@@ -188,11 +173,9 @@
*/
- (void)connect
{
- _fullJID = _JID + @"/" + _resource;
-
[self registerSelector:@selector(_didReceivePing:) ofObject:self withDict:[CPDictionary dictionaryWithObjectsAndKeys:@"iq", @"name", @"get", @"type"]];
- _connection.connect(_fullJID, _password, function (status, errorCond)
+ _connection.connect([_JID full], _password, function (status, errorCond)
{
var selector,
notificationName;
@@ -287,7 +270,7 @@
if ([aStanza containsChildrenWithName:@"ping"] && [[aStanza firstChildWithName:@"ping"] namespace] == Strophe.NS.PING)
{
CPLog.debug("Ping received. Sending pong.");
- [self send:[TNStropheStanza iqWithAttributes:{'to': [aStanza from], 'id': [aStanza ID], 'type': 'result'}]];
+ [self send:[TNStropheStanza iqWithAttributes:{'to': [[aStanza from] bare], 'id': [aStanza ID], 'type': 'result'}]];
}
return YES;
}
@@ -429,7 +412,8 @@
*/
- (id)registerSelector:(SEL)aSelector ofObject:(CPObject)anObject withDict:(id)aDict
{
- var handlerId = _connection.addHandler(function(stanza) {
+ var from = ([[aDict valueForKey:@"from"] class] == CPString) ? [aDict valueForKey:@"from"] : [[aDict valueForKey:@"from"] stringValue],
+ handlerId = _connection.addHandler(function(stanza) {
var stanzaObject = [TNStropheStanza stanzaWithStanza:stanza];
CPLog.trace("StropheCappuccino stanza received that trigger selector : " + [anObject class] + "." + aSelector);
CPLog.trace(stanzaObject);
@@ -439,7 +423,46 @@
[aDict valueForKey:@"name"],
[aDict valueForKey:@"type"],
[aDict valueForKey:@"id"],
- [aDict valueForKey:@"from"],
+ from,
+ [aDict valueForKey:@"options"]);
+
+ return handlerId;
+}
+
+/*! allows to register a selector for beeing fired on XMPP events, according to the content of a dictionnary parameter.
+ The dictionnary should contains zero to many of the followings :
+ - <b>namespace</b>: the namespace of the stanza or of the first child (like query)
+ - <b>name</b>: the name of the stanza (message, iq or presence)
+ - <b>type</b>: the type of the stanza
+ - <b>id</b>: the unique identifier
+ - <b>from</b>: the stanza sender
+ - <b>options</b>: an array of options. only {MatchBare: True} works.
+ if all the conditions are mets, the selector is fired and the stanza is given as parameter.
+
+ The selector should return YES to not be unregistered. If it returns NO or nothing, it will be
+ unregistered
+
+ @param aSelector the selector to be performed
+ @param anObject the receiver of the selector
+ @param aDict a dictionnary of parameters
+ @param someUserInfo user infos
+
+ @return an id of the handler registration used to remove it
+*/
+- (id)registerSelector:(SEL)aSelector ofObject:(CPObject)anObject withDict:(id)aDict userInfo:(id)someUserInfo
+{
+ var from = ([[aDict valueForKey:@"from"] class] == CPString) ? [aDict valueForKey:@"from"] : [[aDict valueForKey:@"from"] stringValue],
+ handlerId = _connection.addHandler(function(stanza) {
+ var stanzaObject = [TNStropheStanza stanzaWithStanza:stanza];
+ CPLog.trace("StropheCappuccino stanza received that trigger selector : " + [anObject class] + "." + aSelector);
+ CPLog.trace(stanzaObject);
+ return [anObject performSelector:aSelector withObject:stanzaObject withObject:someUserInfo];
+ },
+ [aDict valueForKey:@"namespace"],
+ [aDict valueForKey:@"name"],
+ [aDict valueForKey:@"type"],
+ [aDict valueForKey:@"id"],
+ from,
[aDict valueForKey:@"options"]);
return handlerId;
@@ -457,7 +480,8 @@
*/
- (id)registerTimeoutSelector:(SEL)aTimeoutSelector ofObject:(CPObject)anObject withDict:(id)aDict forTimeout:(float)aTimeout
{
- var handlerId = _connection.addTimedHandler(aTimeout, function(stanza) {
+ var from = ([[aDict valueForKey:@"from"] class] == CPString) ? [aDict valueForKey:@"from"] : [[aDict valueForKey:@"from"] stringValue],
+ handlerId = _connection.addTimedHandler(aTimeout, function(stanza) {
if (!stanza)
{
CPLog.trace("StropheCappuccino stanza timeout that trigger selector : " + [anObject class] + "." + aTimeoutSelector);
@@ -469,7 +493,7 @@
[aDict valueForKey:@"name"],
[aDict valueForKey:@"type"],
[aDict valueForKey:@"id"],
- [aDict valueForKey:@"from"],
+ from,
[aDict valueForKey:@"options"]);
return handlerId;
@@ -519,7 +543,6 @@
{
_JID = [aCoder decodeObjectForKey:@"_JID"];
_password = [aCoder decodeObjectForKey:@"_password"];
- _resource = [aCoder decodeObjectForKey:@"_resource"];
_delegate = [aCoder decodeObjectForKey:@"_delegate"];
_boshService = [aCoder decodeObjectForKey:@"_boshService"];
_connection = [aCoder decodeObjectForKey:@"_connection"];
@@ -533,7 +556,6 @@
{
[aCoder encodeObject:_JID forKey:@"_JID"];
[aCoder encodeObject:_password forKey:@"_password"];
- [aCoder encodeObject:_resource forKey:@"_resource"];
[aCoder encodeObject:_boshService forKey:@"_boshService"];
[aCoder encodeObject:_connection forKey:@"_connection"];
[aCoder encodeObject:_registeredHandlerDict forKey:@"_registeredHandlerDict"];
View
51 TNStropheContact.j
@@ -20,6 +20,7 @@
@import <Foundation/Foundation.j>
+@import "TNStropheJID.j"
@import "TNStropheGroup.j"
@import "TNStropheConnection.j"
@import "TNBase64Image.j"
@@ -35,10 +36,8 @@
CPArray _resources @accessors(property=resources);
CPImage _statusIcon @accessors(property=statusIcon);
CPNumber _numberOfEvents @accessors(property=numberOfEvents);
- CPString _domain @accessors(property=domain);
- CPString _fullJID @accessors(property=fullJID);
+ TNStropheJID _JID @accessors(property=JID);
CPString _groupName @accessors(property=groupName);
- CPString _JID @accessors(property=JID);
CPString _nickname @accessors(property=nickname);
CPString _nodeName @accessors(property=nodeName);
CPString _type @accessors(property=type);
@@ -81,7 +80,7 @@
@return an initialized TNStropheContact
*/
-- (id)initWithConnection:(TNStropheConnection)aConnection JID:(CPString)aJID groupName:(CPString)aGroupName
+- (id)initWithConnection:(TNStropheConnection)aConnection JID:(TNStropheJID)aJID groupName:(CPString)aGroupName
{
if (self = [super init])
{
@@ -107,10 +106,8 @@
_resources = [CPArray array];
_JID = aJID;
+ _nickname = [_JID node];
_groupName = aGroupName;
- _nodeName = aJID.split('@')[0];
- _nickname = aJID.split('@')[0];
- _domain = aJID.split('/')[0].split('@')[1];
}
return self;
@@ -130,9 +127,9 @@
var resource = [aStanza fromResource],
presenceStatus = [aStanza firstChildWithName:@"status"];
- _fullJID = [aStanza from];
+ [_JID setResource:[[aStanza from] resource]]
- if (resource && (resource != @"") && ![_resources containsObject:resource])
+ if ([_JID resource] && ([_JID resource] != @"") && ![_resources containsObject:resource])
[_resources addObject:resource];
switch ([aStanza type])
@@ -214,7 +211,7 @@
- (void)sendStatus:(CPString)aStatus
{
- var statusStanza = [TNStropheStanza messageWithAttributes:{"to": _JID, "from": [_connection JID], "type": "chat"}];
+ var statusStanza = [TNStropheStanza messageTo:_JID withAttributes:{"type": "chat"}];
[statusStanza addChildWithName:aStatus andAttributes:{"xmlns": "http://jabber.org/protocol/chatstates"}];
@@ -250,21 +247,21 @@
*/
- (void)subscribe
{
- [_connection send:[TNStropheStanza presenceWithAttributes:{@"from": [_connection JID], @"type": @"subscribed", @"to": _JID}]];
+ [_connection send:[TNStropheStanza presenceTo:_JID withAttributes:{@"type": @"subscribed"} bare:YES]];
}
/*! unsubscribe from the contact
*/
- (void)unsubscribe
{
- [_connection send:[TNStropheStanza presenceWithAttributes:{@"from": [_connection JID], @"type": @"unsubscribed", @"to": _JID}]];
+ [_connection send:[TNStropheStanza presenceTo:_JID WwthAttributes:{@"type": @"unsubscribed"} bare:YES]];
}
/*! ask subscribtion to the contact
*/
- (void)askSubscription
{
- [_connection send:[TNStropheStanza presenceWithAttributes:{@"type": @"subscribe", @"to": _JID}]];
+ [_connection send:[TNStropheStanza presenceTo:_JID withAttributes:{@"type": @"subscribe"} bare:YES]];
}
@@ -282,10 +279,8 @@
- (void)getVCard
{
var uid = [_connection getUniqueId],
- vcardStanza = [TNStropheStanza iqWithAttributes:{@"from": [_connection JID], @"to": _JID, @"type": @"get", @"id": uid}],
- params = [CPDictionary dictionaryWithObjectsAndKeys:_JID, @"from",
- uid, @"id",
- {matchBare: true}, @"options"];
+ vcardStanza = [TNStropheStanza iqTo:_JID withAttributes:{@"type": @"get", @"id": uid} bare:YES],
+ params = [CPDictionary dictionaryWithObjectsAndKeys: uid, @"id"];
[vcardStanza addChildWithName:@"vCard" andAttributes:{@"xmlns": @"vcard-temp"}];
@@ -314,7 +309,7 @@
if ([aVCard firstChildWithName:@"NAME"])
_nickname = [[aVCard firstChildWithName:@"NAME"] text];
else
- _nickname = _JID.split('@')[0];
+ _nickname = [_JID node]
var photoNode;
if (photoNode = [aVCard firstChildWithName:@"PHOTO"])
@@ -345,7 +340,7 @@
var stanza = [TNStropheStanza iqWithAttributes:{"type": "set"}];
[stanza addChildWithName:@"query" andAttributes: {'xmlns':Strophe.NS.ROSTER}];
- [stanza addChildWithName:@"item" andAttributes:{"JID": _JID, "name": _nickname}];
+ [stanza addChildWithName:@"item" andAttributes:{"JID": [_JID bare], "name": _nickname}];
[stanza addChildWithName:@"group" andAttributes:nil];
[stanza addTextNode:_groupName];
@@ -360,7 +355,7 @@
{
var stanza = [TNStropheStanza iqWithAttributes:{"type": "set"}];
[stanza addChildWithName:@"query" andAttributes: {'xmlns':Strophe.NS.ROSTER}];
- [stanza addChildWithName:@"item" andAttributes:{"JID": _JID, "name": _nickname}];
+ [stanza addChildWithName:@"item" andAttributes:{"JID": [_JID bare], "name": _nickname}];
[stanza addChildWithName:@"group" andAttributes:nil];
[stanza addTextNode:[newGroup name]];
@@ -376,7 +371,7 @@
var stanza = [TNStropheStanza iqWithAttributes:{"type": "set"}];
[stanza addChildWithName:@"query" andAttributes: {'xmlns':Strophe.NS.ROSTER}];
- [stanza addChildWithName:@"item" andAttributes:{"JID": _JID, "name": _nickname}];
+ [stanza addChildWithName:@"item" andAttributes:{"JID": [_JID bare], "name": _nickname}];
[stanza addChildWithName:@"group" andAttributes:nil];
[stanza addTextNode:aNewName];
@@ -398,7 +393,7 @@
- (void)sendStanza:(TNStropheStanza)aStanza withUserInfo:(CPDictionary)userInfo
{
- [aStanza setTo:(_fullJID) ? _fullJID : _JID];
+ [aStanza setTo:_JID];
[_connection send:aStanza];
@@ -451,10 +446,10 @@
- (void)getMessages
{
var params = [CPDictionary dictionaryWithObjectsAndKeys:@"message", @"name",
- _JID, @"from",
+ [_JID bare], @"from",
{matchBare: true}, @"options"];
- [_connection registerSelector:@selector(_didReceivedMessage:) ofObject:self withDict:params];
+ [_connection registerSelector:@selector(_didReceiveMessage:) ofObject:self withDict:params];
}
/*! message sent when contact listening its message (using getMessages) and send appropriates notifications
@@ -464,7 +459,7 @@
@return YES in order to listen again
*/
-- (BOOL)_didReceivedMessage:(id)aStanza
+- (BOOL)_didReceiveMessage:(id)aStanza
{
var center = [CPNotificationCenter defaultCenter],
userInfo = [CPDictionary dictionaryWithObjectsAndKeys:aStanza, @"stanza", [CPDate date], @"date"];
@@ -578,7 +573,6 @@
{
_JID = [aCoder decodeObjectForKey:@"_JID"];
_nodeName = [aCoder decodeObjectForKey:@"_nodeName"];
- _domain = [aCoder decodeObjectForKey:@"_domain"];
_groupName = [aCoder decodeObjectForKey:@"_groupName"];
_nickname = [aCoder decodeObjectForKey:@"_nickname"];
_XMPPStatus = [aCoder decodeObjectForKey:@"_XMPPStatus"];
@@ -586,7 +580,6 @@
_XMPPShow = [aCoder decodeObjectForKey:@"_XMPPShow"];
_statusIcon = [aCoder decodeObjectForKey:@"_statusIcon"];
_type = [aCoder decodeObjectForKey:@"_type"];
- _fullJID = [aCoder decodeObjectForKey:@"_fullJID"];
_vCard = [aCoder decodeObjectForKey:@"_vCard"];
_messageQueue = [aCoder decodeObjectForKey:@"_messagesQueue"];
_numberOfEvents = [aCoder decodeObjectForKey:@"_numberOfEvents"];
@@ -600,7 +593,6 @@
[aCoder encodeObject:_JID forKey:@"_JID"];
[aCoder encodeObject:_nodeName forKey:@"_nodeName"];
[aCoder encodeObject:_groupName forKey:@"_groupName"];
- [aCoder encodeObject:_domain forKey:@"_domain"];
[aCoder encodeObject:_nickname forKey:@"_nickname"];
[aCoder encodeObject:_XMPPStatus forKey:@"_XMPPStatus"];
[aCoder encodeObject:_XMPPShow forKey:@"_XMPPShow"];
@@ -612,9 +604,6 @@
if (_resources)
[aCoder encodeObject:_resources forKey:@"_resources"];
- if (_fullJID)
- [aCoder encodeObject:_fullJID forKey:@"_fullJID"];
-
if (_vCard)
[aCoder encodeObject:_vCard forKey:@"_vCard"];
}
View
3  TNStropheGlobals.j
@@ -12,7 +12,7 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
- *
+ *
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
@@ -288,6 +288,7 @@ TNStrophePubSubVarAccessModelWhitelist = @"whitelist";
*/
TNStrophePubSubNodeRetrievedNotification = @"TNStrophePubSubNodeRetrievedNotification";
+
/*!
@global
@group TNPubSub
View
2  TNStropheGroup.j
@@ -12,7 +12,7 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
- *
+ *
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
View
262 TNStropheJID.j
@@ -0,0 +1,262 @@
+/*
+ * TNStropheJID.j
+ *
+ * Copyright (C) 2010 Antoine Mercadal <antoine.mercadal@inframonde.eu>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3.0 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+@import <Foundation/Foundation.j>
+
+TNStropheJIDExceptionJID = @"TNStropheJIDExceptionJID";
+
+
+/*! @ingroup strophecappuccino
+ This class represents a XMPP JID
+*/
+@implementation TNStropheJID : CPObject
+{
+ CPString _node @accessors(property=node);
+ CPString _domain @accessors(property=domain);
+ CPString _resource @accessors(property=resource);
+ BOOL _isServer @accessors(getter=isServer);
+}
+
+#pragma mark -
+#pragma mark Class methods
+
+/*! return a new TNStropheJID
+ @param aNode the node part of the JID
+ @param aDomain the domain part of the JID
+ @param aResource the resource part of the JID
+*/
++ (TNStropheJID)stropheJIDWithNode:(CPString)aNode domain:(CPString)aDomain resource:(CPString)aResource
+{
+ return [[TNStropheJID alloc] initWithNode:aNode domain:aDomain resource:aResource];
+}
+
+/*! return a new TNStropheJID
+ @param aNode the node part of the JID
+ @param aDomain the domain part of the JID
+ @param aResource the resource part of the JID
+*/
++ (TNStropheJID)stropheJIDWithNode:(CPString)aNode domain:(CPString)aDomain
+{
+ return [[TNStropheJID alloc] initWithNode:aNode domain:aDomain];
+}
+
+/*! return a new TNStropheJID
+ @param aNode the node part of the JID
+ @param aDomain the domain part of the JID
+ @param aResource the resource part of the JID
+*/
++ (TNStropheJID)stropheJIDWithString:(CPString)aStringJID
+{
+ return [[TNStropheJID alloc] initWithString:aStringJID];
+}
+
+
+#pragma mark -
+#pragma mark Initialization
+
+/*! return a new TNStropheJID
+ @param aNode the node part of the JID
+ @param aDomain the domain part of the JID
+ @param aResource the resource part of the JID
+*/
+
+- (TNStropheJID)initWithNode:(CPString)aNode domain:(CPString)aDomain resource:(CPString)aResource
+{
+ if (self = [super init])
+ {
+ _node = aNode;
+ _domain = aDomain;
+ _resource = aResource;
+ _isServer = (!aDomain && !aResource);
+ }
+
+ return self;
+}
+
+/*! return a new TNStropheJID
+ @param aNode the node part of the JID
+ @param aDomain the domain part of the JID
+*/
+- (TNStropheJID)initWithNode:(CPString)aNode domain:(CPString)aDomain
+{
+ return [self initWithNode:aNode domain:aDomain resource:nil];
+}
+
+/*! return a new TNStropheJID
+ @param aNode the node part of the JID
+ @param aDomain the domain part of the JID
+*/
+- (TNStropheJID)initWithString:(CPString)aStringJID
+{
+ var node = aStringJID.split("@")[0],
+ domain,
+ resource;
+
+ if (aStringJID.indexOf("@") != -1) //this is a server
+ {
+ domain = aStringJID.split("@")[1].split("/")[0],
+ resource = aStringJID.split("/")[1];
+ }
+
+ if (!node)
+ [CPException raise:TNStropheJIDExceptionJID reason:aStringJID + @" is not a valid JID"];
+
+ return [self initWithNode:node domain:domain resource:resource];
+}
+
+
+#pragma mark -
+#pragma mark Setters and Getters
+
+/*! return the bare JID (node@domain)
+ @return CPString containing the bare JID
+*/
+- (CPString)bare
+{
+ if (_domain)
+ return _node + @"@" + _domain;
+ else
+ return _node;
+}
+
+/*! set the bare JID from the string.
+ resource, if any remains the same
+ @param aBareJID CPString containing the bare JID
+*/
+- (void)setBare:(CPString)aBareJID
+{
+ var node = aBareJID.split("@")[0],
+ domain = aBareJID.split("@")[1].split("/")[0];
+
+ if (!node || !domain)
+ [CPException raise:TNStropheJIDExceptionJID reason:aBareJID + @" is not a valid JID"];
+
+ _node = node;
+ _domain = domain;
+}
+
+/*! return the full JID (node@domain/resource)
+ @return CPString containing the full JID
+*/
+- (CPString)full
+{
+ if (_resource)
+ return [self bare] + "/" + _resource;
+ else
+ return [self bare];
+}
+
+/*! set the full JID from the string.
+ @param aFullJID CPString containing the full JID
+*/
+- (void)setFull:(CPString)aFullJID
+{
+ [self setBare:aFullJID];
+
+ var resource = aFullJID.split("/")[1];
+
+ if (!resource)
+ [CPException raise:TNStropheJIDExceptionJID reason:aFullJID + @" is not a valid JID"];
+
+ _resource = resource;
+}
+
+/*! description method
+ @return CPString containing the full JID
+*/
+- (CPString)description
+{
+ return [self stringValue];
+}
+
+/*! string value method
+ @return CPString containing the full JID
+*/
+- (CPString)stringValue
+{
+ return [self full];
+}
+
+/*! convenient method
+*/
+- (CPString)uppercaseString
+{
+ return [[self stringValue] uppercaseString];
+}
+
+/*! convenient method
+*/
+- (CPString)lowercaseString
+{
+ return [[self stringValue] lowercaseString];
+}
+
+#pragma mark -
+#pragma mark Operations
+
+/*! check if given TNStropheJID is equals to self
+ @param anotherJID the TNStropheJID to compare
+*/
+- (BOOL)equals:(TNStropheJID)anotherJID
+{
+ return [self fullEquals:anotherJID];
+}
+
+/*! check if given TNStropheJID fullJID is equals to self
+ @param anotherJID the TNStropheJID to compare
+*/
+- (BOOL)fullEquals:(TNStropheJID)anotherJID
+{
+ return ([self bareEquals:anotherJID] && ([[anotherJID resource] uppercaseString] === [[self resource] uppercaseString]))
+}
+
+/*! check if given TNStropheJID's node and domain is equals to self
+ @param anotherJID the TNStropheJID to compare
+*/
+- (BOOL)bareEquals:(TNStropheJID)anotherJID
+{
+ return (([[anotherJID node] uppercaseString] === [[self node] uppercaseString]) && ([[anotherJID domain] uppercaseString] === [[self domain] uppercaseString]));
+}
+
+@end
+
+
+@implementation TNStropheJID (CPCodingCompliance)
+
+- (id)initWithCoder:(CPCoder)aCoder
+{
+ if (self = [super init])
+ {
+ _node = [aCoder decodeObjectForKey:@"_node"];
+ _domain = [aCoder decodeObjectForKey:@"_domain"];
+ _resource = [aCoder decodeObjectForKey:@"_resource"];
+ }
+
+ return self;
+}
+
+- (void)encodeWithCoder:(CPCoder)aCoder
+{
+ [aCoder encodeObject:_node forKey:@"_node"];
+ [aCoder encodeObject:_domain forKey:@"_domain"];
+ [aCoder encodeObject:_resource forKey:@"_resource"];
+}
+
+@end
View
53 TNStropheRoster.j
@@ -12,7 +12,7 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
- *
+ *
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
@@ -20,6 +20,7 @@
@import <Foundation/Foundation.j>
+@import "TNStropheJID.j"
@import "TNStropheRosterBase.j"
/*! @ingroup strophecappuccino
@@ -101,8 +102,8 @@
for (var i = 0; i < [items count]; i++)
{
var item = [items objectAtIndex:i],
- theJID = [item valueForAttribute:@"jid"],
- nickname = theJID;
+ theJID = [TNStropheJID stropheJIDWithString:[item valueForAttribute:@"jid"]],
+ nickname = [theJID node];
if ([item valueForAttribute:@"name"])
nickname = [item valueForAttribute:@"name"];
@@ -144,8 +145,8 @@
}
else
{
- if ([self containsJID:[aStanza fromBare]])
- [[self contactWithJID:[aStanza fromBare]] _didReceiveStatus:aStanza];
+ if ([self containsJID:[aStanza from]])
+ [[self contactWithJID:[aStanza from]] _didReceiveStatus:aStanza];
else
[_pendingPresence addObject:aStanza];
}
@@ -153,13 +154,13 @@
return YES;
}
-- (CPArray)pendingPresenceForJID:(CPString)aJID
+- (CPArray)pendingPresenceForJID:(TNStropheJID)aJID
{
var temp = [CPArray array];
for (var i = 0; i < [_pendingPresence count]; i++)
{
var presence = [_pendingPresence objectAtIndex:i];
- if ([presence fromBare] === aJID)
+ if ([[presence from] bareEquals:aJID])
[temp addObject:presence];
}
return temp;
@@ -278,7 +279,7 @@
@param aGroup the group of the new contact. if nil, it will be "General"
@return the new TNStropheContact
*/
-- (TNStropheContact)addContact:(CPString)aJID withName:(CPString)aName inGroupWithName:(CPString)aGroupName
+- (TNStropheContact)addContact:(TNStropheJID)aJID withName:(CPString)aName inGroupWithName:(CPString)aGroupName
{
if ([self containsJID:aJID] == YES)
return;
@@ -289,7 +290,7 @@
var addReq = [TNStropheStanza iqWithAttributes:{"type": "set", "id": [_connection getUniqueId]}];
[addReq addChildWithName:@"query" andAttributes: {'xmlns':Strophe.NS.ROSTER}];
- [addReq addChildWithName:@"item" andAttributes:{"JID": aJID, "name": aName}];
+ [addReq addChildWithName:@"item" andAttributes:{"JID": [aJID bare], "name": aName}];
[addReq addChildWithName:@"group" andAttributes:nil];
[addReq addTextNode:aGroupName];
@@ -315,29 +316,49 @@
{
[super removeContact:aContact];
- var removeReq = [TNStropheStanza iqWithAttributes:{"type": "set", "id": [_connection getUniqueId]}];
+ var uid = [_connection getUniqueIdWithSuffix:@"roster"],
+ removeReq = [TNStropheStanza iqWithAttributes:{"type": "set", "id": uid}],
+ params = [CPDictionary dictionaryWithObjectsAndKeys:uid, @"id"];
[removeReq addChildWithName:@"query" andAttributes: {'xmlns':Strophe.NS.ROSTER}];
- [removeReq addChildWithName:@"item" andAttributes:{'jid': [aContact JID], 'subscription': 'remove'}];
+ [removeReq addChildWithName:@"item" andAttributes:{'jid': [[aContact JID] bare], 'subscription': 'remove'}];
+ [_connection registerSelector:@selector(_didRemoveContact:userInfo:) ofObject:self withDict:params userInfo:aContact];
[_connection send:removeReq];
+}
- [[CPNotificationCenter defaultCenter] postNotificationName:TNStropheRosterRemovedContactNotification object:aContact];
+- (void)_didRemoveContact:(TNStropheStanza)aStanza userInfo:(TNStropheContact)theContact
+{
+ if ([aStanza type] === @"result")
+ [[CPNotificationCenter defaultCenter] postNotificationName:TNStropheRosterRemovedContactNotification object:theContact];
+ else
+ CPLog.error("Cannot remove contact: " + aStanza)
}
+/*! remove a contact from the roster according to its JID
+
+ @param aJID the JID of the contact to remove
+*/
+- (void)removeContactWithJID:(TNStropheJID)aJID
+{
+ [self removeContact:[self contactWithJID:aJID]];
+}
+
+
+
#pragma mark -
#pragma mark Subscriptions
/*! subscribe to the given JID and add in into the roster if needed
@param aJID the JID to subscribe
*/
-- (void)authorizeJID:(CPString)aJID
+- (void)authorizeJID:(TNStropheJID)aJID
{
var contact = [self contactWithJID:aJID];
if (!contact)
- contact = [self addContact:aJID withName:aJID.split('@')[0] inGroupWithName:@"General"];
+ contact = [self addContact:aJID withName:[aJID node] inGroupWithName:@"General"];
[contact subscribe];
}
@@ -345,7 +366,7 @@
/*! unsubscribe to the given JID
@param aJID the JID to unsubscribe
*/
-- (void)unauthorizeJID:(CPString)aJID
+- (void)unauthorizeJID:(TNStropheJID)aJID
{
[[self contactWithJID:aJID] unsubscribe];
}
@@ -353,7 +374,7 @@
/*! ask subscribtion to the given JID
@param aJID the JID to ask subscribtion
*/
-- (void)askAuthorizationTo:(CPString)aJID
+- (void)askAuthorizationTo:(TNStropheJID)aJID
{
[[self contactWithJID:aJID] askSubscription];
}
View
16 TNStropheRosterBase.j
@@ -12,7 +12,7 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
- *
+ *
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
@@ -20,6 +20,7 @@
@import <Foundation/Foundation.j>
+@import "TNStropheJID.j"
@import "TNStropheConnection.j";
@import "TNStropheStanza.j";
@import "TNStropheGroup.j"
@@ -102,7 +103,7 @@
@param aJID the JID of the contact to remove
*/
-- (void)removeContactWithJID:(CPString)aJID
+- (void)removeContactWithJID:(TNStropheJID)aJID
{
[self removeContact:[self contactWithJID:aJID]];
}
@@ -111,12 +112,12 @@
@param aJID CPString containing the JID
@return TNStropheContact the contact with the given JID
*/
-- (TNStropheContact)contactWithJID:(CPString)aJID
+- (TNStropheContact)contactWithJID:(TNStropheJID)aJID
{
for (var i = 0; i < [_contacts count]; i++)
{
var contact = [_contacts objectAtIndex:i];
- if ([contact JID] == aJID)
+ if ([[contact JID] bareEquals:aJID])
return contact;
}
@@ -127,12 +128,11 @@
@param aJID the JID to search
@return YES is JID is in roster, NO otherwise
*/
-- (BOOL)containsJID:(CPString)aJID
+- (BOOL)containsJID:(TNStropheJID)aJID
{
- //@each (var contact in _contacts)
for (var i = 0; i < [_contacts count]; i++)
{
- if ([[[_contacts objectAtIndex:i] JID] lowercaseString] == [aJID lowercaseString])
+ if ([[[_contacts objectAtIndex:i] JID] bareEquals:aJID])
return YES;
}
return NO;
@@ -151,7 +151,7 @@
@param aName the new nickname
@param aJID the JID of the contact to change the nickname
*/
-- (void)changeNickname:(CPString)aName ofContactWithJID:(CPString)aJID
+- (void)changeNickname:(CPString)aName ofContactWithJID:(TNStropheJID)aJID
{
[self changeNickname:aName ofContact:[self contactWithJID:aJID]];
}
View
182 TNStropheStanza.j
@@ -12,13 +12,15 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
- *
+ *
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@import <Foundation/Foundation.j>
+
+@import "TNStropheJID.j"
@import "TNXMLNode.j"
/*! @ingroup strophecappuccino
@@ -29,6 +31,15 @@
#pragma mark -
#pragma mark Class methods
+/*! instanciate a TNStropheStanza from a Pure XML Dom Element
+ @param aStanza XML Element
+ @return instance of TNStropheStanza
+*/
++ (TNStropheStanza)stanzaWithStanza:(id)aStanza
+{
+ return [[TNStropheStanza alloc] initWithNode:aStanza];
+}
+
/*! instanciate a TNStropheStanza
@param aName the root name
@param attributes CPDictionary of attributes
@@ -39,6 +50,30 @@
return [[TNStropheStanza alloc] initWithName:aName andAttributes:attributes];
}
+/*! instanciate a TNStropheStanza
+ @param aName the root name
+ @param aJID the destination JID
+ @param attributes CPDictionary of attributes
+ @return instance of TNStropheStanza
+*/
++ (TNStropheStanza)stanzaWithName:(CPString)aName to:(TNStropheJID)aJID attributes:(CPDictionary)attributes
+{
+ return [[TNStropheStanza alloc] initWithName:aName to:aJID attributes:attributes bare:NO];
+}
+
+/*! instanciate a TNStropheStanza
+ @param aName the root name
+ @param aJID the destination JID
+ @param attributes CPDictionary of attributes
+ @param sendToBareJID if YES send to bare JID
+ @return instance of TNStropheStanza
+*/
++ (TNStropheStanza)stanzaWithName:(CPString)aName to:(TNStropheJID)aJID attributes:(CPDictionary)attributes bare:(BOOL)sendToBareJID
+{
+ return [[TNStropheStanza alloc] initWithName:aName to:aJID attributes:attributes bare:sendToBareJID];
+}
+
+
/*! instanciate a TNStropheStanza with name IQ
@param attributes CPDictionary of attributes
@return instance of TNStropheStanza
@@ -57,6 +92,15 @@
}
/*! instanciate a TNStropheStanza with name IQ
+ @param aJID the destination JID
+ @return instance of TNStropheStanza
+*/
++ (TNStropheStanza)iqTo:(TNStropheJID)aJID
+{
+ return [TNStropheStanza iqTo:aJID withAttributes:nil];
+}
+
+/*! instanciate a TNStropheStanza with name IQ
@param aType CPString the type of the query
@return instance of TNStropheStanza
*/
@@ -65,6 +109,37 @@
return [TNStropheStanza iqWithAttributes:{"type": aType}];
}
+/*! instanciate a TNStropheStanza with name IQ
+ @param aJID the destination JID
+ @param aType CPString the type of the query
+ @return instance of TNStropheStanza
+*/
++ (TNStropheStanza)iqTo:(TNStropheJID)aJID withType:(CPString)aType
+{
+ return [TNStropheStanza iqTo:aJID withAttributes:{"type": aType}];
+}
+
+/*! instanciate a TNStropheStanza with name IQ
+ @param aJID the destination JID
+ @param attributes CPDictionary of attributes
+ @return instance of TNStropheStanza
+*/
++ (TNStropheStanza)iqTo:(TNStropheJID)aJID withAttributes:(CPDictionary)attributes
+{
+ return [TNStropheStanza stanzaWithName:@"iq" to:aJID attributes:attributes bare:NO];
+}
+
+/*! instanciate a TNStropheStanza with name IQ
+ @param aJID the destination JID
+ @param attributes CPDictionary of attributes
+ @param sendToBareJID if YES send to bare JID
+ @return instance of TNStropheStanza
+*/
++ (TNStropheStanza)iqTo:(TNStropheJID)aJID withAttributes:(CPDictionary)attributes bare:(BOOL)sendToBareJID
+{
+ return [TNStropheStanza stanzaWithName:@"iq" to:aJID attributes:attributes bare:sendToBareJID];
+}
+
/*! instanciate a TNStropheStanza with name presence
@param attributes CPDictionary of attributes
@return instance of TNStropheStanza
@@ -82,6 +157,36 @@
return [TNStropheStanza presenceWithAttributes:nil];
}
+/*! instanciate a TNStropheStanza with name presence
+ @param aJID the destination JID
+ @return instance of TNStropheStanza
+*/
++ (TNStropheStanza)presenceTo:(TNStropheJID)aJID
+{
+ return [TNStropheStanza presenceTo:aJID withAttributes:nil];
+}
+
+/*! instanciate a TNStropheStanza with name presence
+ @param aJID the destination JID
+ @param attributes CPDictionary of attributes
+ @return instance of TNStropheStanza
+*/
++ (TNStropheStanza)presenceTo:(TNStropheJID)aJID withAttributes:(CPDictionary)attributes
+{
+ return [TNStropheStanza stanzaWithName:@"presence" to:aJID attributes:attributes bare:NO];
+}
+
+/*! instanciate a TNStropheStanza with name presence
+ @param aJID the destination JID
+ @param attributes CPDictionary of attributes
+ @param sendToBareJID if YES send to bare JID
+ @return instance of TNStropheStanza
+*/
++ (TNStropheStanza)presenceTo:(TNStropheJID)aJID withAttributes:(CPDictionary)attributes bare:(BOOL)sendToBareJID
+{
+ return [TNStropheStanza stanzaWithName:@"presence" to:aJID attributes:attributes bare:sendToBareJID];
+}
+
/*! instanciate a TNStropheStanza with name message
@param attributes CPDictionary of attributes
@return instance of TNStropheStanza
@@ -99,15 +204,54 @@
return [TNStropheStanza messageWithAttributes:nil];
}
-/*! instanciate a TNStropheStanza from a Pure XML Dom Element
- @param aStanza XML Element
+/*! instanciate a TNStropheStanza with name message
+ @param aJID the destination JID
@return instance of TNStropheStanza
*/
-+ (TNStropheStanza)stanzaWithStanza:(id)aStanza
++ (TNStropheStanza)messageTo:(TNStropheJID)aJID
{
- return [[TNStropheStanza alloc] initWithNode:aStanza];
+ return [TNStropheStanza messageTo:aJID withAttributes:nil];
}
+/*! instanciate a TNStropheStanza with name message
+ @param aJID the destination JID
+ @param attributes CPDictionary of attributes
+ @return instance of TNStropheStanza
+*/
++ (TNStropheStanza)messageTo:(TNStropheJID)aJID withAttributes:(CPDictionary)attributes
+{
+ return [TNStropheStanza stanzaWithName:@"message" to:aJID attributes:attributes];
+}
+
+/*! instanciate a TNStropheStanza with name message
+ @param aJID the destination JID
+ @param attributes CPDictionary of attributes
+ @param sendToBareJID if YES send to bare JID
+ @return instance of TNStropheStanza
+*/
++ (TNStropheStanza)messageTo:(TNStropheJID)aJID withAttributes:(CPDictionary)attributes bare:(BOOL)sendToBareJID
+{
+ return [TNStropheStanza stanzaWithName:@"message" to:aJID attributes:attributes bare:sendToBareJID];
+}
+
+
+#pragma mark -
+#pragma mark Initialization
+
+- (TNStropheStanza)initWithName:(CPString)aName to:(TNStropheJID)aJID attributes:(CPDictionary)someAttributes bare:(BOOL)sendToBareJID
+{
+ if (someAttributes)
+ {
+ if (someAttributes.isa)
+ [someAttributes setValue:((sendToBareJID) ? [aJID bare] : aJID) forKey:"to"]
+ else
+ someAttributes.to = ((sendToBareJID) ? [aJID bare] : [aJID full])
+ }
+
+ return [super initWithName:aName andAttributes:someAttributes];
+}
+
+
#pragma mark -
#pragma mark Attributes
@@ -117,16 +261,19 @@
- (CPString)from
{
while ([self up]);
- return [self valueForAttribute:@"from"];
+ return [TNStropheJID stropheJIDWithString:[self valueForAttribute:@"from"]];
}
/*! set the from field of the stanza
@param the new from value
*/
-- (void)setFrom:(CPString)aFrom
+- (void)setFrom:(id)aFrom
{
+ if ([aFrom class] == CPString)
+ aFrom = [TNStropheJID stropheJIDWithString:aFrom];
+
while ([self up]);
- [self setValue:aFrom forAttribute:@"from"];
+ [self setValue:[aFrom full] forAttribute:@"from"];
}
/*! get the bare from JID of the stanza
@@ -134,7 +281,7 @@
*/
- (CPString)fromBare
{
- return [self from].split("/")[0];
+ return [[self from] bare];
}
/*! return the the bare user name
@@ -142,7 +289,7 @@
*/
- (CPString)fromUser
{
- return [self from].split("/")[0].split("@")[0];
+ return [[self from] node];
}
/*! get the domain of the form field
@@ -150,7 +297,7 @@
*/
- (CPString)fromDomain
{
- return [self from].split("@")[1].split("/")[0]
+ return [[self from] domain];
}
/*! get the resource part of the from field of the stanza
@@ -158,9 +305,7 @@
*/
- (CPString)fromResource
{
- if ([[[self from] componentsSeparatedByString:@"/"] count] > 1)
- return [[[self from] componentsSeparatedByString:@"/"] objectAtIndex:1];
- return nil;
+ return [[self from] resource];
}
/*! get the to field of the stanza
@@ -169,16 +314,19 @@
- (CPString)to
{
while ([self up]);
- return [self valueForAttribute:@"to"];
+ return [TNStropheJID stropheJIDWithString:[self valueForAttribute:@"to"]];
}
/*! set the to field of the stanza
@param the new To value
*/
-- (void)setTo:(CPString)aTo
+- (void)setTo:(id)aTo
{
+ if ([aTo class] == CPString)
+ aTo = [TNStropheJID stropheJIDWithString:aTo];
+
while ([self up]);
- [self setValue:aTo forAttribute:@"to"];
+ [self setValue:[aTo full] forAttribute:@"to"];
}
/*! get the type field of the stanza
View
2  TNXMLNode.j
@@ -12,7 +12,7 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
- *
+ *
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Please sign in to comment.
Something went wrong with that request. Please try again.