]> cgit.babelmonkeys.de Git - mpdbot.git/blobdiff - src/mpdbot.m
Properly declare ivars
[mpdbot.git] / src / mpdbot.m
index ea84079c19eaf7591280e762e886d11744f7ae24..84f864deb653e58f4fa2ef7929dc792d0120cfa8 100644 (file)
@@ -2,7 +2,7 @@
  * Copyright (c) 2010, 2011, Jonathan Schleifer <js@webkeks.org>
  * Copyright (c) 2011, Florian Zeitz <florob@babelmonkeys.de>
  *
- * https://webkeks.org/hg/objxmpp/
+ * http://cgit.babelmonkeys.de/cgit.cgi/mpdbot/
  *
  * Permission to use, copy, modify, and/or distribute this software for any
  * purpose with or without fee is hereby granted, provided that the above
@@ -21,8 +21,6 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
-#include <assert.h>
-
 #import <ObjFW/ObjFW.h>
 #import <ObjXMPP/ObjXMPP.h>
 
 
 #define NS_DISCO_INFO @"http://jabber.org/protocol/disco#info"
 
-@interface AppDelegate: OFObject
-#ifdef OF_HAVE_OPTIONAL_PROTOCOLS
-    <OFApplicationDelegate, XMPPConnectionDelegate>
-#endif
-
+@interface AppDelegate: OFObject <OFApplicationDelegate, XMPPConnectionDelegate>
+{
 OFString *discoID;
 PEPThread *pepper;
+}
 @end
 
 OF_APPLICATION_DELEGATE(AppDelegate)
@@ -48,17 +44,18 @@ OF_APPLICATION_DELEGATE(AppDelegate)
        OFArray *arguments = [OFApplication arguments];
 
        conn = [[XMPPConnection alloc] init];
-       [conn setDelegate: self];
+       conn.delegate = self;
 
-       if ([arguments count] != 3) {
-               of_log(@"Invalid count of command line arguments!");
+       if (arguments.count != 3) {
+               [of_stdout writeFormat: @"Usage: %@ <server> <user> <passwd>\n",
+                   [OFApplication programName]];
                [OFApplication terminateWithStatus: 1];
        }
 
-       [conn setDomain: [arguments objectAtIndex: 0]];
-       [conn setUsername: [arguments objectAtIndex: 1]];
-       [conn setPassword: [arguments objectAtIndex: 2]];
-       [conn setResource: @"ObjXMPP"];
+       conn.domain = [arguments objectAtIndex: 0];
+       conn.username = [arguments objectAtIndex: 1];
+       conn.password = [arguments objectAtIndex: 2];
+       conn.resource = @"ObjXMPP";
 
        @try {
                [conn connect];
@@ -70,7 +67,7 @@ OF_APPLICATION_DELEGATE(AppDelegate)
 
 - (void)connectionWasAuthenticated: (XMPPConnection*)conn
 {
-       of_log(@"Auth successful");
+       [of_stdout writeLine: @"Auth successful"];
 }
 
 - (void)connection: (XMPPConnection*)conn
@@ -79,7 +76,7 @@ OF_APPLICATION_DELEGATE(AppDelegate)
        XMPPPresence *pres;
        XMPPIQ *disco;
 
-       of_log(@"Bound to JID: %@", [jid fullJID]);
+       [of_stdout writeFormat: @"Bound to JID: %@\n", [jid fullJID]];
 
        pres = [XMPPPresence presence];
        [pres addPriority: 0];
@@ -91,8 +88,8 @@ OF_APPLICATION_DELEGATE(AppDelegate)
                                ID: discoID];
        disco.to = [XMPPJID JIDWithString: [[conn JID] bareJID]];
        [disco addChild: [OFXMLElement
-       elementWithName: @"query"
-             namespace: NS_DISCO_INFO]];
+           elementWithName: @"query"
+                 namespace: NS_DISCO_INFO]];
 
        [conn sendStanza: disco];
 }
@@ -102,7 +99,7 @@ OF_APPLICATION_DELEGATE(AppDelegate)
 {
        OFXMLElement *query = [iq elementForName: @"query"
                                       namespace: NS_DISCO_INFO];
-       if ([[iq ID] isEqual: discoID]) {
+       if ([iq.ID isEqual: discoID]) {
                for (OFXMLElement *identity
                    in [query elementsForName: @"identity"
                                    namespace: NS_DISCO_INFO]) {
@@ -113,6 +110,7 @@ OF_APPLICATION_DELEGATE(AppDelegate)
                                pepper = [[PEPThread alloc]
                                    initWithObject: conn];
                                [pepper start];
+
                                return YES;
                        }
                }
@@ -130,11 +128,17 @@ OF_APPLICATION_DELEGATE(AppDelegate)
 -   (void)connection: (XMPPConnection*)conn
   didReceivePresence: (XMPPPresence*)pres
 {
-       of_log(@"Presence: %@", pres);
+       if ([pres.type isEqual: @"subscribe"]) {
+               XMPPPresence *answer;
+               answer = [XMPPPresence presenceWithType: @"subscribed"
+                                                    ID: pres.ID];
+               answer.to = [XMPPJID JIDWithString: [pres.from bareJID]];
+               [conn sendStanza: answer];
+       }
 }
 
 - (void)connectionWasClosed: (XMPPConnection*)conn
 {
-       of_log(@"Connection was closed!");
+       [of_stdout writeLine: @"Connection was closed!"];
 }
 @end