Mercurial > pidgin.yaz
comparison libpurple/protocols/mxit/protocol.h @ 28903:69aa4660401a
Initial addition of the MXit protocol plugin, provided by the MXit folks
themselves.
author | John Bailey <rekkanoryo@rekkanoryo.org> |
---|---|
date | Sun, 08 Nov 2009 23:55:56 +0000 |
parents | |
children | 81ea740f92a4 |
comparison
equal
deleted
inserted
replaced
28901:13e668ef158d | 28903:69aa4660401a |
---|---|
1 /* | |
2 * MXit Protocol libPurple Plugin | |
3 * | |
4 * -- MXit client protocol implementation -- | |
5 * | |
6 * Pieter Loubser <libpurple@mxit.com> | |
7 * | |
8 * (C) Copyright 2009 MXit Lifestyle (Pty) Ltd. | |
9 * <http://www.mxitlifestyle.com> | |
10 * | |
11 * This program is free software; you can redistribute it and/or modify | |
12 * it under the terms of the GNU General Public License as published by | |
13 * the Free Software Foundation; either version 2 of the License, or | |
14 * (at your option) any later version. | |
15 * | |
16 * This program is distributed in the hope that it will be useful, | |
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 * GNU General Public License for more details. | |
20 * | |
21 * You should have received a copy of the GNU General Public License | |
22 * along with this program; if not, write to the Free Software | |
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA | |
24 */ | |
25 | |
26 #ifndef _MXIT_PROTO_H_ | |
27 #define _MXIT_PROTO_H_ | |
28 | |
29 | |
30 /* Client protocol constants */ | |
31 #define CP_SOCK_REC_TERM '\x00' /* socket record terminator */ | |
32 #define CP_HTTP_REC_TERM '\x26' /* http record terminator '&' */ | |
33 #define CP_FLD_TERM '\x01' /* field terminator */ | |
34 #define CP_PKT_TERM '\x02' /* packet terminator */ | |
35 | |
36 | |
37 #define CP_MAX_PACKET ( 1024 * 1024 ) /* maximum client protocol packet size (1 MiB) */ | |
38 #define CP_MAX_FILESIZE ( 150 * 1000 ) /* maximum client protocol file transfer size (150 KB) */ | |
39 #define MXIT_EMOTICON_SIZE 18 /* icon size for custom emoticons */ | |
40 #define CP_MAX_STATUS_MSG 250 /* maximum status message length (in characters) */ | |
41 | |
42 /* Avatars */ | |
43 #define MXIT_AVATAR_SIZE 96 /* default avatar image size 96x96 */ | |
44 #define MXIT_AVATAR_TYPE "PNG" /* request avatars in this file type (only a suggestion) */ | |
45 #define MXIT_AVATAR_BITDEPT 24 /* request avatars with this bit depth (only a suggestion) */ | |
46 | |
47 /* Protocol error codes */ | |
48 #define MXIT_ERRCODE_SUCCESS 0 | |
49 #define MXIT_ERRCODE_REDIRECT 16 | |
50 #define MXIT_ERRCODE_LOGGEDOUT 42 | |
51 | |
52 /* MXit client features */ | |
53 #define MXIT_CF_NONE 0x000000 | |
54 #define MXIT_CF_FORMS 0x000001 | |
55 #define MXIT_CF_FILE_TRANSFER 0x000002 | |
56 #define MXIT_CF_CAMERA 0x000004 | |
57 #define MXIT_CF_COMMANDS 0x000008 | |
58 #define MXIT_CF_SMS 0x000010 | |
59 #define MXIT_CF_FILE_ACCESS 0x000020 | |
60 #define MXIT_CF_MIDP2 0x000040 | |
61 #define MXIT_CF_SKINS 0x000080 | |
62 #define MXIT_CF_AUDIO 0x000100 | |
63 #define MXIT_CF_ENCRYPTION 0x000200 | |
64 #define MXIT_CF_VOICE_REC 0x000400 | |
65 #define MXIT_CF_VECTOR_GFX 0x000800 | |
66 #define MXIT_CF_IMAGES 0x001000 | |
67 #define MXIT_CF_MARKUP 0x002000 | |
68 #define MXIT_CF_VIBES 0x004000 | |
69 #define MXIT_CF_SELECT_CONTACT 0x008000 | |
70 #define MXIT_CF_CUSTOM_EMO 0x010000 | |
71 #define MXIT_CF_ALERT_PROFILES 0x020000 | |
72 #define MXIT_CF_EXT_MARKUP 0x040000 | |
73 #define MXIT_CF_PLAIN_PWD 0x080000 | |
74 #define MXIT_CF_NO_GATEWAYS 0x100000 | |
75 | |
76 /* Client features supported by this implementation */ | |
77 #define MXIT_CP_FEATURES ( MXIT_CF_FILE_TRANSFER | MXIT_CF_FILE_ACCESS | MXIT_CF_AUDIO | MXIT_CF_MARKUP | MXIT_CF_EXT_MARKUP | MXIT_CF_NO_GATEWAYS | MXIT_CF_IMAGES | MXIT_CF_COMMANDS | MXIT_CF_VIBES | MXIT_CF_MIDP2 ) | |
78 | |
79 | |
80 #define MXIT_PING_INTERVAL ( 5 * 60 ) /* ping the server after X seconds of being idle (5 minutes) */ | |
81 #define MXIT_ACK_TIMEOUT ( 30 ) /* timeout after waiting X seconds for an ack from the server (30 seconds) */ | |
82 | |
83 /* MXit client version */ | |
84 #define MXIT_CP_DISTCODE "P" /* client distribution code (magic, do not touch!) */ | |
85 #define MXIT_CP_RELEASE "5.9.0" /* client protocol release version supported */ | |
86 #define MXIT_CP_ARCH "Y" /* client architecture series (Y not for Yoda but for PC-client) */ | |
87 #define MXIT_CLIENT_ID "LP" /* client ID as specified by MXit */ | |
88 #define MXIT_CP_PLATFORM "PURPLE" /* client platform */ | |
89 #define MXIT_CP_VERSION MXIT_CP_DISTCODE"-"MXIT_CP_RELEASE"-"MXIT_CP_ARCH"-"MXIT_CP_PLATFORM | |
90 | |
91 /* set operating system name */ | |
92 #if defined( __APPLE__ ) | |
93 #define MXIT_CP_OS "apple" | |
94 #elif defined( _WIN32 ) | |
95 #define MXIT_CP_OS "windows" | |
96 #elif defined( __linux__ ) | |
97 #define MXIT_CP_OS "linux" | |
98 #else | |
99 #define MXIT_CP_OS "unknown" | |
100 #endif | |
101 | |
102 /* Client capabilities */ | |
103 #define MXIT_CP_CAP "utf8=true;cid="MXIT_CLIENT_ID | |
104 | |
105 /* Client settings */ | |
106 #define MAX_QUEUE_SIZE ( 1 << 4 ) /* tx queue size (16 packets) */ | |
107 #define MXIT_POPUP_WIN_NAME "MXit Notification" /* popup window name */ | |
108 #define MXIT_MAX_ATTRIBS 10 /* maximum profile attributes supported */ | |
109 #define MXIT_DEFAULT_LOCALE "en" /* default locale setting */ | |
110 #define MXIT_DEFAULT_LOC "planetpurple" /* the default location for registration */ | |
111 | |
112 /* Client protocol commands */ | |
113 #define CP_CMD_LOGIN 0x0001 /* (1) login */ | |
114 #define CP_CMD_LOGOUT 0x0002 /* (2) logout */ | |
115 #define CP_CMD_CONTACT 0x0003 /* (3) get contacts */ | |
116 #define CP_CMD_UPDATE 0x0005 /* (5) update contact information */ | |
117 #define CP_CMD_INVITE 0x0006 /* (6) subscribe to new contact */ | |
118 #define CP_CMD_PRESENCE 0x0007 /* (7) get presence */ | |
119 #define CP_CMD_REMOVE 0x0008 /* (8) remove contact */ | |
120 #define CP_CMD_RX_MSG 0x0009 /* (9) get new messages */ | |
121 #define CP_CMD_TX_MSG 0x000A /* (10) send new message */ | |
122 #define CP_CMD_REGISTER 0x000B /* (11) register */ | |
123 //#define CP_CMD_PROFILE_SET 0x000C /* (12) set profile (DEPRECATED see CP_CMD_EXTPROFILE_SET) */ | |
124 #define CP_CMD_POLL 0x0011 /* (17) poll the HTTP server for an update */ | |
125 //#define CP_CMD_PROFILE_GET 0x001A /* (26) get profile (DEPRECATED see CP_CMD_EXTPROFILE_GET) */ | |
126 #define CP_CMD_MEDIA 0x001B /* (27) get multimedia message */ | |
127 #define CP_CMD_SPLASHCLICK 0x001F /* (31) splash-screen clickthrough */ | |
128 #define CP_CMD_STATUS 0x0020 /* (32) set shown presence & status */ | |
129 #define CP_CMD_MOOD 0x0029 /* (41) set mood */ | |
130 #define CP_CMD_KICK 0x002B /* (43) login kick */ | |
131 #define CP_CMD_GRPCHAT_CREATE 0x002C /* (44) create new groupchat */ | |
132 #define CP_CMD_GRPCHAT_INVITE 0x002D /* (45) add new groupchat member */ | |
133 #define CP_CMD_NEW_SUB 0x0033 /* (51) get new subscription */ | |
134 #define CP_CMD_ALLOW 0x0034 /* (52) allow subscription */ | |
135 #define CP_CMD_DENY 0x0037 /* (55) deny subscription */ | |
136 #define CP_CMD_EXTPROFILE_GET 0x0039 /* (57) get extended profile */ | |
137 #define CP_CMD_EXTPROFILE_SET 0x003A /* (58) set extended profile */ | |
138 #define CP_CMD_PING 0x03E8 /* (1000) ping (keepalive) */ | |
139 | |
140 /* HTTP connection */ | |
141 #define MXIT_HTTP_POLL_MIN 7 /* minimum time between HTTP polls (seconds) */ | |
142 #define MXIT_HTTP_POLL_MAX ( 10 * 60 ) /* maximum time between HTTP polls (seconds) */ | |
143 | |
144 /* receiver states */ | |
145 #define RX_STATE_RLEN 0x01 /* reading packet length section */ | |
146 #define RX_STATE_DATA 0x02 /* reading packet data section */ | |
147 #define RX_STATE_PROC 0x03 /* process read data */ | |
148 | |
149 /* message flags */ | |
150 #define CP_MSG_ENCRYPTED 0x0010 /* message is encrypted */ | |
151 #define CP_MSG_MARKUP 0x0200 /* message may contain markup */ | |
152 #define CP_MSG_EMOTICON 0x0400 /* message may contain custom emoticons */ | |
153 | |
154 /* redirect types */ | |
155 #define CP_REDIRECT_PERMANENT 1 /* permanent redirect */ | |
156 #define CP_REDIRECT_TEMPORARY 2 /* temporary redirect */ | |
157 | |
158 /* message tx types */ | |
159 #define CP_MSGTYPE_NORMAL 0x01 /* normal message */ | |
160 #define CP_MSGTYPE_CHAT 0x02 /* chat message */ | |
161 #define CP_MSGTYPE_HEADLINE 0x03 /* headline message */ | |
162 #define CP_MSGTYPE_ERROR 0x04 /* error message */ | |
163 #define CP_MSGTYPE_GROUPCHAT 0x05 /* groupchat message */ | |
164 #define CP_MSGTYPE_FORM 0x06 /* mxit custom form */ | |
165 #define CP_MSGTYPE_COMMAND 0x07 /* mxit command */ | |
166 | |
167 | |
168 /* extended profile attribute fields */ | |
169 #define CP_PROFILE_BIRTHDATE "birthdate" /* Birthdate (String - ISO 8601 format) */ | |
170 #define CP_PROFILE_GENDER "gender" /* Gender (Boolean - 0=female, 1=male) */ | |
171 #define CP_PROFILE_HIDENUMBER "hidenumber" /* Hide Number (Boolean - 0=false, 1=true) */ | |
172 #define CP_PROFILE_FULLNAME "fullname" /* Fullname (UTF8 String) */ | |
173 #define CP_PROFILE_STATUS "statusmsg" /* Status Message (UTF8 String) */ | |
174 #define CP_PROFILE_PREVSTATUS "prevstatusmsgs" /* Previous Status Messages (UTF8 String) */ | |
175 #define CP_PROFILE_AVATAR "avatarid" /* Avatar ID (String) */ | |
176 #define CP_PROFILE_MODIFIED "lastmodified" /* Last-Modified timestamp */ | |
177 #define CP_PROFILE_TITLE "title" /* Title (UTF8 String) */ | |
178 #define CP_PROFILE_FIRSTNAME "firstname" /* First name (UTF8 String) */ | |
179 #define CP_PROFILE_LASTNAME "lastname" /* Last name (UTF8 String) */ | |
180 #define CP_PROFILE_EMAIL "email" /* Email address (UTF8 String) */ | |
181 #define CP_PROFILE_MOBILENR "mobilenumber" /* Mobile Number (UTF8 String) */ | |
182 | |
183 /* extended profile field types */ | |
184 #define CP_PROF_TYPE_BOOL 0x02 /* boolean profile attribute type */ | |
185 #define CP_PROF_TYPE_INT 0x05 /* integer profile attribute type */ | |
186 #define CP_PROF_TYPE_UTF8 0x0A /* UTF8 string profile attribute type */ | |
187 #define CP_PROF_TYPE_DATE 0x0B /* date-time profile attribute type */ | |
188 | |
189 | |
190 /* define this to enable protocol debugging (very verbose logging) */ | |
191 #define DEBUG_PROTOCOL | |
192 | |
193 | |
194 /* ======================================================================================= */ | |
195 | |
196 struct MXitSession; | |
197 | |
198 /*------------------------------------------*/ | |
199 | |
200 struct field { | |
201 char* data; | |
202 int len; | |
203 }; | |
204 | |
205 struct record { | |
206 struct field** fields; | |
207 int fcount; | |
208 }; | |
209 | |
210 struct rx_packet { | |
211 int cmd; | |
212 int errcode; | |
213 char* errmsg; | |
214 struct record** records; | |
215 int rcount; | |
216 }; | |
217 | |
218 struct tx_packet { | |
219 int cmd; | |
220 char header[256]; | |
221 int headerlen; | |
222 char* data; | |
223 int datalen; | |
224 }; | |
225 | |
226 /*------------------------------------------*/ | |
227 | |
228 | |
229 /* | |
230 * A received message data object | |
231 */ | |
232 struct RXMsgData { | |
233 struct MXitSession* session; /* MXit session object */ | |
234 char* from; /* the sender's name */ | |
235 time_t timestamp; /* time at which the message was sent */ | |
236 GString* msg; /* newly created message converted to libPurple formatting */ | |
237 gboolean got_img; /* flag to say if this message got any images/emoticons embedded */ | |
238 short img_count; /* the amount of images/emoticons still outstanding for the message */ | |
239 int chatid; /* multimx chatroom id */ | |
240 int flags; /* libPurple conversation flags */ | |
241 gboolean converted; /* true if the message has been completely parsed and converted to libPurple markup */ | |
242 gboolean processed; /* the message has been processed completely and should be freed up */ | |
243 }; | |
244 | |
245 | |
246 | |
247 /* | |
248 * The packet transmission queue. | |
249 */ | |
250 struct tx_queue { | |
251 struct tx_packet* packets[MAX_QUEUE_SIZE]; /* array of packet pointers */ | |
252 int count; /* number of packets queued */ | |
253 int rd_i; /* queue current read index (queue offset for reading a packet) */ | |
254 int wr_i; /* queue current write index (queue offset for adding new packet) */ | |
255 }; | |
256 | |
257 | |
258 /* ======================================================================================= */ | |
259 | |
260 void mxit_popup( int type, const char* heading, const char* message ); | |
261 void mxit_strip_domain( char* username ); | |
262 gboolean find_active_chat( const GList* chats, const char* who ); | |
263 | |
264 void mxit_cb_rx( gpointer data, gint source, PurpleInputCondition cond ); | |
265 gboolean mxit_manage_queue( gpointer user_data ); | |
266 gboolean mxit_manage_polling( gpointer user_data ); | |
267 | |
268 void mxit_send_register( struct MXitSession* session ); | |
269 void mxit_send_login( struct MXitSession* session ); | |
270 void mxit_send_logout( struct MXitSession* session ); | |
271 void mxit_send_ping( struct MXitSession* session ); | |
272 void mxit_send_poll( struct MXitSession* session ); | |
273 | |
274 void mxit_send_presence( struct MXitSession* session, int presence, const char* statusmsg ); | |
275 void mxit_send_mood( struct MXitSession* session, int mood ); | |
276 void mxit_send_message( struct MXitSession* session, const char* to, const char* msg, gboolean parse_markup ); | |
277 | |
278 void mxit_send_extprofile_update( struct MXitSession* session, const char* password, unsigned int nr_attrib, const char* attributes ); | |
279 void mxit_send_extprofile_request( struct MXitSession* session, const char* username, unsigned int nr_attrib, const char* attribute[] ); | |
280 | |
281 void mxit_send_invite( struct MXitSession* session, const char* username, const char* alias, const char* groupname ); | |
282 void mxit_send_remove( struct MXitSession* session, const char* username ); | |
283 void mxit_send_allow_sub( struct MXitSession* session, const char* username, const char* alias ); | |
284 void mxit_send_deny_sub( struct MXitSession* session, const char* username ); | |
285 void mxit_send_update_contact( struct MXitSession* session, const char* username, const char* alias, const char* groupname ); | |
286 void mxit_send_splashclick( struct MXitSession* session, const char* splashid ); | |
287 | |
288 void mxit_send_file( struct MXitSession* session, const char* username, const char* filename, const unsigned char* buf, int buflen ); | |
289 void mxit_send_file_reject( struct MXitSession* session, const char* fileid ); | |
290 void mxit_send_file_accept( struct MXitSession* session, const char* fileid, int filesize, int offset ); | |
291 void mxit_send_file_received( struct MXitSession* session, const char* fileid, short status ); | |
292 void mxit_set_avatar( struct MXitSession* session, const unsigned char* avatar, int avatarlen ); | |
293 void mxit_get_avatar( struct MXitSession* session, const char* mxitId, const char* avatarId ); | |
294 | |
295 void mxit_send_groupchat_create( struct MXitSession* session, const char* groupname, int nr_usernames, const char* usernames[] ); | |
296 void mxit_send_groupchat_invite( struct MXitSession* session, const char* roomid, int nr_usernames, const char* usernames[] ); | |
297 | |
298 int mxit_parse_packet( struct MXitSession* session ); | |
299 void dump_bytes( struct MXitSession* session, const char* buf, int len ); | |
300 void mxit_close_connection( struct MXitSession* session ); | |
301 | |
302 | |
303 #endif /* _MXIT_PROTO_H_ */ | |
304 |