comparison PRPL @ 1086:ce201056e7a6

[gaim-migrate @ 1096] adam is obviously very bored; he hacked gaim. other good prpl-related stuff. committer: Tailor Script <tailor@pidgin.im>
author Eric Warmenhoven <eric@warmenhoven.org>
date Sun, 12 Nov 2000 14:14:12 +0000
parents 38452403563b
children 7aabbbaae829
comparison
equal deleted inserted replaced
1085:8da0bf36fb99 1086:ce201056e7a6
1 Protocol Plugins. What EveryBuddy should have been. 1 Protocol Plugins. What EveryBuddy should have been.
2
3 Protocol Plugins are easier than GUI plugins. This is because there is necessarily a limited set
4 of server functions; protocols are limited. What a programmer can do with a UI is limitless.
5
6 In order to design a framework for which Protocol Plugins can work, we must first think about
7 which protocols can be pluginized. (Henceforth PRPL will stand for both the Protocol Plugin
8 system and an individual Protocol Plugin.)
9
10 Oscar. TOC. Yahoo. MSN. ICQ. FTP. IRC.
11
12 There is a longer list. Note that FTP is in the list presented. FTP has basic functions similar
13 to those of the others. The basic functions that must be performed are:
14
15 Sign on. (log in)
16 Sign off.
17 Send and receive messages.
18
19 There really isn't much more to it than that. There are, then, additional functions that some
20 protocols implement:
21
22 Chat.
23 File Transfer.
24 Away/Idle. (states)
25 Directory Info.
26
27 Before PRPL there was a slight abstraction in the code. The UI simply needed to call serv_login,
28 and that function would decide between the protocols, which function to call. It did that with
29 an if-elseif-else series.
30
31 With PRPL, each PRPL is stored in a struct. The structs are then kept in a GSList. The serv_
32 functions then simply need to search the GSList for the correct protocol, and call the desired
33 function. The struct holds void * references to the desired functions. serv_* simply needs to
34 call that function. (Even better, each connection has a reference to the PRPL struct it uses;
35 this will reduce search time.)
36
37 A new PRPL can be loaded at any time. They can be either static or dynamic code. When a new
38 protocol is loaded, gaim will call its protocol_init function, which is expected to return a
39 pointer to the aforementioned struct. If it returns NULL, the PRPL will not be loaded. (This is
40 not entirely true and needs to be modified in the code to work similarly to how it's decscribed
41 here.)
42 2
43 Each PRPL needs to have a unique identifier. In the pre-PRPL system TOC was 0 and Oscar was 1. 3 Each PRPL needs to have a unique identifier. In the pre-PRPL system TOC was 0 and Oscar was 1.
44 This identifier can be found in prpl.h. They are pre-assigned. PROTO_TOC is still 0, PROTO_OSCAR 4 This identifier can be found in prpl.h. They are pre-assigned. PROTO_TOC is still 0, PROTO_OSCAR
45 is still 1. The protocol_init function is expected to set the struct's protocol member to the 5 is still 1. The protocol_init function is expected to set the struct's protocol member to the
46 appropriate value. If you want to write a new PRPL for gaim, please email one of the maintainers 6 appropriate value. If you want to write a new PRPL for gaim, please email one of the maintainers
47 with the name of the protocol. We'll then reserve a number for it. Please do not use a number 7 with the name of the protocol. We'll then reserve a number for it. Please do not use a number
48 that has not been assigned to your protocol, not even for testing purposes. 8 that has not been assigned to your protocol, not even for testing purposes.
49 9
50 The addition of PRPL to gaim means that gaim now supports multiple connections and multiple (and 10 The addition of PRPL to gaim means that gaim now supports multiple connections and multiple (and
51 dynamically loadable) protocols. 11 dynamically loadable) protocols.
52
53 ======
54
55 In order to test that PRPL was working with as little work as possible I made Oscar a plugin. In
56 order to use Oscar as a plugin, first recompile gaim with the make variable DEBUG_CFLAGS set to
57 -DDYNAMIC_OSCAR, e.g.
58
59 /usr/src/gaim $ make DEBUG_CFLAGS=-DDYNAMIC_OSCAR
60
61 This will then remove Oscar support from the code (though it will still link with libfaim. However,
62 gaim does not need to link to libfaim itself). Making the Oscar plugin is straight-forward; simply
63 make oscar.so in the plugins directory, e.g.
64
65 /usr/src/gaim/plugins $ make oscar.so
66
67 You will then be presented with a gaim binary in src/gaim and the Oscar plugin in plugins/oscar.so.
68 Simply load the oscar.so file from the normal plugin window. This will set up everything necessary.
69 You may unload the plugin at any time, but the protocol will still be loaded. This may or may not
70 be a problem and may or may not be fixed at a later point in time.
71 12
72 ====== 13 ======
73 14
74 I guess I should document how to write a PRPL. 15 I guess I should document how to write a PRPL.
75 16
83 file, and have it call 24 file, and have it call
84 25
85 load_protocol(my_proto_init); 26 load_protocol(my_proto_init);
86 27
87 and return a non-negative int. Then compile as a plugin, load the .so file, and you're set. If you're 28 and return a non-negative int. Then compile as a plugin, load the .so file, and you're set. If you're
88 going to load it dynamically, extern the my_proto_init function, and in prpl.c, call load_protocol. 29 going to load it statically, extern the my_proto_init function, and in prpl.c, call load_protocol.
89 30
90 Your PRPL needs to have a login function, which ideally should set up a gdk_input watcher. When you 31 Your PRPL needs to have a login function, which ideally should set up a gdk_input watcher. When you
91 want to indicate that the account is online, simply call account_online(struct gaim_connection *). 32 want to indicate that the account is online, simply call account_online(struct gaim_connection *).
92 When there is information from the server, you should call the appropriate serv_got function (see 33 When there is information from the server, you should call the appropriate serv_got function (see
93 gaim.h for a (partial?) list). 34 gaim.h for a (partial?) list).
94 35
95 When the UI wants to send something via the server, it will call the appropriate function that you set 36 When the UI wants to send something via the server, it will call the appropriate function that you set
96 in your PRPL, if it's non-NULL. 37 in your PRPL, if it's non-NULL. The only function that is absolutely critical is name. Without name
38 gaim will probably crash. You don't even need login, just name. (You need login to do anything useful
39 though.)
97 40
98 There's currently no way to unload a PRPL, even if compiled dynamically and the plugin is removed. If 41 The best example to copy is probably Rob's IRC plugin, in plugins/irc.c. The most important functions
99 you do remove a dynamic PRPL and try to load a new version of it, you will still be using the old 42 for gaim interaction are at the bottom (irc_init, gaim_plugin_init, and gaim_plugin_remove). The
100 version. Hopefully I can figure out how to fix this. Maybe it's not that important. 43 rest of it is the protocol implementation.
44
45 Sorry for the formatting. My Eterm is 105 characters wide.