[Adium-devl] Adium's Libpurple Implementation
Evan Schoenberg
evan.s at dreskin.net
Sat Sep 8 14:02:13 UTC 2007
Alex et. al,
On Sep 7, 2007, at 6:41 PM, Alex C Schaefer wrote:
> I'm Alex Schaefer of the ApolloIM project, an iphone Instant
> Messenger, and we're looking to get away from firetalk asap in favor
> of libpurple.
>
Welcome :)
> We have gotten libpurple compiled, and we're actually, at this
> point, looking at out implementation. Currently, it's implemented
> in a very dirty fashion inspired by the libpurple nullclient. I
> thought I'd get in contact with you guys before I get down and dirty
> and write my own libpurple interface in objc, and ask where I should
> look in Adium for a good clean example of such code.
>
> Chris had mentioned you have a connector class that Adium uses to
> connect libpurple to the adium-core, and maybe someone could
> elaborate a little more on that for me?
All the code interacting with libpurple is indeed in one place.
Grab the Adium source (http://www.adiumx.com/faq/GettingAdiumSource),
open the xcode project, and navigate in the groups to Plugins (Built-
In) -> Services -> Libpurple -> AdiumLibpurple.
Outgoing data
In that group, we have:
* Classes named like XXPurpleAccount. These are subclasses of the
generic Adium "AIAccount" and are the start of outgoing communication;
the rest of Adium messages the Account, which then passes the
information on to the connector class.
* The next step in information flow is SLPurpleCocoaAdapter, which
will actually be calling the appropriate libpurple functions.
So, for example, to send a message, -[CBPurpleAccount
sendMessageObject:] is called with an AIContentMessage, which
encapsulates all the data needed, including the "encodedMessage" --
that is, the message in HTML (rather than an attributed string) ready
to be sent. The method calls
-[SLPurpleCocoaAdapter sendEncodedMessage:[inContentMessage
encodedMessage]
fromAccount:self
inChat:[inContentMessage chat]
withFlags:flags];
which will get a PurpleConversation and call
purple_conv_im_send_with_flags() or purple_conv_chat_send().
And so on. There's not a class or classes that are appropriate for
dropping in place in another application, but it's well
compartmentalized such that it should hopefully provide a pretty
straightforward working model.
Incoming data
When Adium first needs to create a libpurple account,
SLPurpleCocoaAdapter initializes libpurple in -[SLPurpleCocoaAdapter
initLibPurple], which registers all the different ui_ops needed. These
are how libpurple talks to the UI. Each ui_op has its own file, in
the currently awkwardly named form adiumPurpleXXX (e.g.
adiumPurpleConversation). The callback functions do a lookup to
figure out which CBPurpleAccount subclass instance to talk to and then
pass the new data on; it's converted to a form Adium can use (such as
creating an AIContentMessage from incoming IM, name of the person
sending it, and time it was sent) and passed to the core.
Does that help?
Cheers,
Evan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://adium.im/pipermail/devel_adium.im/attachments/20070908/88d004cf/attachment-0001.html>
More information about the devel
mailing list