X-Git-Url: http://cgit.babelmonkeys.de/?p=mpdbot.git;a=blobdiff_plain;f=src%2Fmpdbot.m;h=84f864deb653e58f4fa2ef7929dc792d0120cfa8;hp=f55e4b77ec3b23f6cd8e7130b46cba15a8bab010;hb=4119a69a36303a285f2c2472c53f3a0906889fc7;hpb=811f94951f504cabc7f12091bd0f0fdca6ab6240 diff --git a/src/mpdbot.m b/src/mpdbot.m index f55e4b7..84f864d 100644 --- a/src/mpdbot.m +++ b/src/mpdbot.m @@ -28,13 +28,11 @@ #define NS_DISCO_INFO @"http://jabber.org/protocol/disco#info" -@interface AppDelegate: OFObject -#ifdef OF_HAVE_OPTIONAL_PROTOCOLS - -#endif - +@interface AppDelegate: OFObject +{ OFString *discoID; PEPThread *pepper; +} @end OF_APPLICATION_DELEGATE(AppDelegate) @@ -46,18 +44,18 @@ OF_APPLICATION_DELEGATE(AppDelegate) OFArray *arguments = [OFApplication arguments]; conn = [[XMPPConnection alloc] init]; - [conn setDelegate: self]; + conn.delegate = self; - if ([arguments count] != 3) { + if (arguments.count != 3) { [of_stdout writeFormat: @"Usage: %@ \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]; @@ -90,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]; } @@ -101,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]) { @@ -112,6 +110,7 @@ OF_APPLICATION_DELEGATE(AppDelegate) pepper = [[PEPThread alloc] initWithObject: conn]; [pepper start]; + return YES; } } @@ -129,7 +128,13 @@ 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