]> cgit.babelmonkeys.de Git - mpdbot.git/blobdiff - src/mpdbot.m
Use new callback API of objXMPP
[mpdbot.git] / src / mpdbot.m
index dc7689efa59f0c3750fe36d83f64a01abda889c1..eb92876880af712e30f7ee333ce276ed681dea54 100644 (file)
@@ -29,8 +29,9 @@
 #define NS_DISCO_INFO @"http://jabber.org/protocol/disco#info"
 
 @interface AppDelegate: OFObject <OFApplicationDelegate, XMPPConnectionDelegate>
-OFString *discoID;
-PEPThread *pepper;
+{
+       PEPThread *pepper;
+}
 @end
 
 OF_APPLICATION_DELEGATE(AppDelegate)
@@ -42,7 +43,7 @@ OF_APPLICATION_DELEGATE(AppDelegate)
        OFArray *arguments = [OFApplication arguments];
 
        conn = [[XMPPConnection alloc] init];
-       conn.delegate = self;
+       [conn addDelegate: self];
 
        if (arguments.count != 3) {
                [of_stdout writeFormat: @"Usage: %@ <server> <user> <passwd>\n",
@@ -59,7 +60,7 @@ OF_APPLICATION_DELEGATE(AppDelegate)
                [conn connect];
                [conn handleConnection];
        } @catch (id e) {
-               of_log(@"%@", e);
+               [of_stderr writeFormat: @"%@\n", e];
        }
 }
 
@@ -73,6 +74,7 @@ OF_APPLICATION_DELEGATE(AppDelegate)
 {
        XMPPPresence *pres;
        XMPPIQ *disco;
+       OFString *discoID;
 
        [of_stdout writeFormat: @"Bound to JID: %@\n", [jid fullJID]];
 
@@ -89,40 +91,34 @@ OF_APPLICATION_DELEGATE(AppDelegate)
            elementWithName: @"query"
                  namespace: NS_DISCO_INFO]];
 
-       [conn sendStanza: disco];
+       [conn       sendIQ: disco
+       withCallbackObject: self
+                 selector: @selector(mpdbot_handleDiscoForConnection:withIQ:)];
 }
 
-- (BOOL)connection: (XMPPConnection*)conn
-      didReceiveIQ: (XMPPIQ*)iq
+- (BOOL)mpdbot_handleDiscoForConnection: (XMPPConnection*)conn
+                                withIQ: (XMPPIQ*)iq
 {
        OFXMLElement *query = [iq elementForName: @"query"
                                       namespace: NS_DISCO_INFO];
-       if ([iq.ID isEqual: discoID]) {
-               for (OFXMLElement *identity
-                   in [query elementsForName: @"identity"
-                                   namespace: NS_DISCO_INFO]) {
-                       if ([[[identity attributeForName: @"category"]
-                           stringValue] isEqual: @"pubsub"] &&
-                           [[[identity attributeForName: @"type"] stringValue]
-                           isEqual: @"pep"]) {
-                               pepper = [[PEPThread alloc]
-                                   initWithObject: conn];
-                               [pepper start];
-
-                               return YES;
-                       }
+       for (OFXMLElement *identity in [query elementsForName: @"identity"
+                                                   namespace: NS_DISCO_INFO]) {
+               if ([[[identity attributeForName: @"category"]
+                   stringValue] isEqual: @"pubsub"] &&
+                   [[[identity attributeForName: @"type"] stringValue]
+                   isEqual: @"pep"]) {
+                       pepper = [[PEPThread alloc]
+                           initWithObject: conn];
+                       [pepper start];
+
+                       return YES;
                }
        }
+       [of_stderr writeLine: @"Server does NOT support PEP"];
 
        return NO;
 }
 
--  (void)connection: (XMPPConnection*)conn
-  didReceiveMessage: (XMPPMessage*)msg
-{
-       of_log(@"Message: %@", msg);
-}
-
 -   (void)connection: (XMPPConnection*)conn
   didReceivePresence: (XMPPPresence*)pres
 {