libpurple/protocols/mxit/protocol.c

Mon, 01 Apr 2013 10:42:13 +0200

author
Andrew Victor <andrew.victor@mxit.com>
date
Mon, 01 Apr 2013 10:42:13 +0200
branch
release-2.x.y
changeset 33831
d160ede64878
parent 33830
36a1ce60ce7b
child 33832
7e3903a32a1b
permissions
-rw-r--r--

MXit: Whitespace changes for coding-style consistency.
(ie, makes the code more closely match what is in the 3.0.0 tree)

28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1 /*
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2 * MXit Protocol libPurple Plugin
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
3 *
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
4 * -- MXit client protocol implementation --
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
5 *
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
6 * Pieter Loubser <libpurple@mxit.com>
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
7 *
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
8 * (C) Copyright 2009 MXit Lifestyle (Pty) Ltd.
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
9 * <http://www.mxitlifestyle.com>
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
10 *
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
11 * This program is free software; you can redistribute it and/or modify
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
12 * it under the terms of the GNU General Public License as published by
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
13 * the Free Software Foundation; either version 2 of the License, or
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
14 * (at your option) any later version.
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
15 *
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
16 * This program is distributed in the hope that it will be useful,
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
19 * GNU General Public License for more details.
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
20 *
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
21 * You should have received a copy of the GNU General Public License
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
22 * along with this program; if not, write to the Free Software
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
24 */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
25
29106
51c7b2177e42 Fix all the remaining files for which internal.h doesn't end up being the first include.
Paul Aurich <darkrain42@pidgin.im>
parents: 28988
diff changeset
26 #include "internal.h"
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
27 #include "purple.h"
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
28
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
29 #include "protocol.h"
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
30 #include "mxit.h"
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
31 #include "roster.h"
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
32 #include "chunk.h"
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
33 #include "filexfer.h"
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
34 #include "markup.h"
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
35 #include "multimx.h"
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
36 #include "splashscreen.h"
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
37 #include "login.h"
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
38 #include "formcmds.h"
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
39 #include "http.h"
31491
cf74b88370ea The initial protocol infrastructure for MXit Voice/Video support.
Andrew Victor <andrew.victor@mxit.com>
parents: 31294
diff changeset
40 #include "voicevideo.h"
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
41
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
42
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
43 #define MXIT_MS_OFFSET 3
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
44
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
45 /* configure the right record terminator char to use */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
46 #define CP_REC_TERM ( ( session->http ) ? CP_HTTP_REC_TERM : CP_SOCK_REC_TERM )
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
47
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
48
31501
4a96cf0f177a * do not send requests too fast to the mxit server or they will start ignoring you.
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31499
diff changeset
49 /*------------------------------------------------------------------------
4a96cf0f177a * do not send requests too fast to the mxit server or they will start ignoring you.
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31499
diff changeset
50 * return the current timestamp in milliseconds
4a96cf0f177a * do not send requests too fast to the mxit server or they will start ignoring you.
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31499
diff changeset
51 */
4a96cf0f177a * do not send requests too fast to the mxit server or they will start ignoring you.
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31499
diff changeset
52 gint64 mxit_now_milli( void )
4a96cf0f177a * do not send requests too fast to the mxit server or they will start ignoring you.
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31499
diff changeset
53 {
4a96cf0f177a * do not send requests too fast to the mxit server or they will start ignoring you.
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31499
diff changeset
54 GTimeVal now;
4a96cf0f177a * do not send requests too fast to the mxit server or they will start ignoring you.
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31499
diff changeset
55
4a96cf0f177a * do not send requests too fast to the mxit server or they will start ignoring you.
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31499
diff changeset
56 g_get_current_time( &now );
4a96cf0f177a * do not send requests too fast to the mxit server or they will start ignoring you.
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31499
diff changeset
57
4a96cf0f177a * do not send requests too fast to the mxit server or they will start ignoring you.
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31499
diff changeset
58 return ( ( now.tv_sec * 1000 ) + ( now.tv_usec / 1000 ) );
4a96cf0f177a * do not send requests too fast to the mxit server or they will start ignoring you.
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31499
diff changeset
59 }
4a96cf0f177a * do not send requests too fast to the mxit server or they will start ignoring you.
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31499
diff changeset
60
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
61
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
62 /*------------------------------------------------------------------------
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
63 * Display a notification popup message to the user.
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
64 *
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
65 * @param type The type of notification:
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
66 * - info: PURPLE_NOTIFY_MSG_INFO
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
67 * - warning: PURPLE_NOTIFY_MSG_WARNING
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
68 * - error: PURPLE_NOTIFY_MSG_ERROR
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
69 * @param heading Heading text
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
70 * @param message Message text
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
71 */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
72 void mxit_popup( int type, const char* heading, const char* message )
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
73 {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
74 /* (reference: "libpurple/notify.h") */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
75 purple_notify_message( NULL, type, _( MXIT_POPUP_WIN_NAME ), heading, message, NULL, NULL );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
76 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
77
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
78
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
79 /*------------------------------------------------------------------------
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
80 * For compatibility with legacy clients, all usernames are sent from MXit with a domain
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
81 * appended. For MXit contacts, this domain is set to "@m". This function strips
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
82 * those fake domains.
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
83 *
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
84 * @param username The username of the contact
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
85 */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
86 void mxit_strip_domain( char* username )
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
87 {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
88 if ( g_str_has_suffix( username, "@m" ) )
33831
d160ede64878 MXit: Whitespace changes for coding-style consistency.
Andrew Victor <andrew.victor@mxit.com>
parents: 33830
diff changeset
89 username[ strlen( username ) - 2 ] = '\0';
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
90 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
91
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
92
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
93 /*------------------------------------------------------------------------
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
94 * Dump a byte buffer to the console for debugging purposes.
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
95 *
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
96 * @param buf The data
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
97 * @param len The data length
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
98 */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
99 void dump_bytes( struct MXitSession* session, const char* buf, int len )
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
100 {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
101 char msg[( len * 3 ) + 1];
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
102 int i;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
103
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
104 memset( msg, 0x00, sizeof( msg ) );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
105
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
106 for ( i = 0; i < len; i++ ) {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
107 if ( buf[i] == CP_REC_TERM ) /* record terminator */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
108 msg[i] = '!';
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
109 else if ( buf[i] == CP_FLD_TERM ) /* field terminator */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
110 msg[i] = '^';
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
111 else if ( buf[i] == CP_PKT_TERM ) /* packet terminator */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
112 msg[i] = '@';
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
113 else if ( buf[i] < 0x20 )
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
114 msg[i] = '_';
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
115 else
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
116 msg[i] = buf[i];
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
117
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
118 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
119
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
120 purple_debug_info( MXIT_PLUGIN_ID, "DUMP: '%s'\n", msg );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
121 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
122
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
123
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
124 /*------------------------------------------------------------------------
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
125 * Determine if we have an active chat with a specific contact
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
126 *
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
127 * @param session The MXit session object
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
128 * @param who The contact name
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
129 * @return Return true if we have an active chat with the contact
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
130 */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
131 gboolean find_active_chat( const GList* chats, const char* who )
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
132 {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
133 const GList* list = chats;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
134 const char* chat = NULL;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
135
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
136 while ( list ) {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
137 chat = (const char*) list->data;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
138
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
139 if ( strcmp( chat, who ) == 0 )
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
140 return TRUE;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
141
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
142 list = g_list_next( list );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
143 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
144
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
145 return FALSE;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
146 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
147
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
148
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
149 /*========================================================================================================================
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
150 * Low-level Packet transmission
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
151 */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
152
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
153 /*------------------------------------------------------------------------
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
154 * Remove next packet from transmission queue.
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
155 *
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
156 * @param session The MXit session object
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
157 * @return The next packet for transmission (or NULL)
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
158 */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
159 static struct tx_packet* pop_tx_packet( struct MXitSession* session )
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
160 {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
161 struct tx_packet* packet = NULL;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
162
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
163 if ( session->queue.count > 0 ) {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
164 /* dequeue the next packet */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
165 packet = session->queue.packets[session->queue.rd_i];
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
166 session->queue.packets[session->queue.rd_i] = NULL;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
167 session->queue.rd_i = ( session->queue.rd_i + 1 ) % MAX_QUEUE_SIZE;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
168 session->queue.count--;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
169 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
170
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
171 return packet;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
172 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
173
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
174
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
175 /*------------------------------------------------------------------------
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
176 * Add packet to transmission queue.
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
177 *
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
178 * @param session The MXit session object
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
179 * @param packet The packet to transmit
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
180 * @return Return TRUE if packet was enqueue, or FALSE if queue is full.
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
181 */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
182 static gboolean push_tx_packet( struct MXitSession* session, struct tx_packet* packet )
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
183 {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
184 if ( session->queue.count < MAX_QUEUE_SIZE ) {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
185 /* enqueue packet */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
186 session->queue.packets[session->queue.wr_i] = packet;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
187 session->queue.wr_i = ( session->queue.wr_i + 1 ) % MAX_QUEUE_SIZE;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
188 session->queue.count++;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
189 return TRUE;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
190 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
191 else
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
192 return FALSE; /* queue is full */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
193 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
194
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
195
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
196 /*------------------------------------------------------------------------
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
197 * Deallocate transmission packet.
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
198 *
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
199 * @param packet The packet to deallocate.
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
200 */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
201 static void free_tx_packet( struct tx_packet* packet )
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
202 {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
203 g_free( packet->data );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
204 g_free( packet );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
205 packet = NULL;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
206 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
207
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
208
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
209 /*------------------------------------------------------------------------
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
210 * Flush all the packets from the tx queue and release the resources.
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
211 *
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
212 * @param session The MXit session object
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
213 */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
214 static void flush_queue( struct MXitSession* session )
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
215 {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
216 struct tx_packet* packet;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
217
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
218 purple_debug_info( MXIT_PLUGIN_ID, "flushing the tx queue\n" );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
219
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
220 while ( (packet = pop_tx_packet( session ) ) != NULL )
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
221 free_tx_packet( packet );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
222 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
223
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
224
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
225 /*------------------------------------------------------------------------
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
226 * TX Step 3: Write the packet data to the TCP connection.
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
227 *
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
228 * @param fd The file descriptor
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
229 * @param pktdata The packet data
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
230 * @param pktlen The length of the packet data
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
231 * @return Return -1 on error, otherwise 0
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
232 */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
233 static int mxit_write_sock_packet( int fd, const char* pktdata, int pktlen )
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
234 {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
235 int written;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
236 int res;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
237
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
238 written = 0;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
239 while ( written < pktlen ) {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
240 res = write( fd, &pktdata[written], pktlen - written );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
241 if ( res <= 0 ) {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
242 /* error on socket */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
243 if ( errno == EAGAIN )
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
244 continue;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
245
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
246 purple_debug_error( MXIT_PLUGIN_ID, "Error while writing packet to MXit server (%i)\n", res );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
247 return -1;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
248 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
249 written += res;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
250 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
251
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
252 return 0;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
253 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
254
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
255
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
256 /*------------------------------------------------------------------------
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
257 * Callback called for handling a HTTP GET response
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
258 *
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
259 * @param url_data libPurple internal object (see purple_util_fetch_url_request)
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
260 * @param user_data The MXit session object
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
261 * @param url_text The data returned (could be NULL if error)
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
262 * @param len The length of the data returned (0 if error)
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
263 * @param error_message Descriptive error message
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
264 */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
265 static void mxit_cb_http_rx( PurpleUtilFetchUrlData* url_data, gpointer user_data, const gchar* url_text, gsize len, const gchar* error_message )
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
266 {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
267 struct MXitSession* session = (struct MXitSession*) user_data;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
268
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
269 /* clear outstanding request */
33815
094a4b10e8d5 Maintain list of outstanding async calls made so that it can be canceled when the account is disconnected.
Pieter Loubser <pieter.loubser@mxit.com>
parents: 33807
diff changeset
270 session->async_calls = g_slist_remove( session->async_calls, url_data );
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
271
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
272 if ( ( !url_text ) || ( len == 0 ) ) {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
273 /* error with request */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
274 purple_debug_error( MXIT_PLUGIN_ID, "HTTP response error (%s)\n", error_message );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
275 return;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
276 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
277
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
278 /* convert the HTTP result */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
279 memcpy( session->rx_dbuf, url_text, len );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
280 session->rx_i = len;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
281
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
282 mxit_parse_packet( session );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
283 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
284
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
285
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
286 /*------------------------------------------------------------------------
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
287 * TX Step 3: Write the packet data to the HTTP connection (GET style).
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
288 *
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
289 * @param session The MXit session object
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
290 * @param pktdata The packet data
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
291 * @param pktlen The length of the packet data
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
292 * @return Return -1 on error, otherwise 0
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
293 */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
294 static void mxit_write_http_get( struct MXitSession* session, struct tx_packet* packet )
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
295 {
33815
094a4b10e8d5 Maintain list of outstanding async calls made so that it can be canceled when the account is disconnected.
Pieter Loubser <pieter.loubser@mxit.com>
parents: 33807
diff changeset
296 PurpleUtilFetchUrlData* url_data;
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
297 char* part = NULL;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
298 char* url = NULL;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
299
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
300 if ( packet->datalen > 0 ) {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
301 char* tmp = NULL;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
302
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
303 tmp = g_strndup( packet->data, packet->datalen );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
304 part = g_strdup( purple_url_encode( tmp ) );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
305 g_free( tmp );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
306 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
307
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
308 url = g_strdup_printf( "%s?%s%s", session->http_server, purple_url_encode( packet->header ), ( !part ) ? "" : part );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
309
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
310 #ifdef DEBUG_PROTOCOL
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
311 purple_debug_info( MXIT_PLUGIN_ID, "HTTP GET: '%s'\n", url );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
312 #endif
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
313
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
314 /* send the HTTP request */
33815
094a4b10e8d5 Maintain list of outstanding async calls made so that it can be canceled when the account is disconnected.
Pieter Loubser <pieter.loubser@mxit.com>
parents: 33807
diff changeset
315 url_data = purple_util_fetch_url_request( url, TRUE, MXIT_HTTP_USERAGENT, TRUE, NULL, FALSE, mxit_cb_http_rx, session );
094a4b10e8d5 Maintain list of outstanding async calls made so that it can be canceled when the account is disconnected.
Pieter Loubser <pieter.loubser@mxit.com>
parents: 33807
diff changeset
316 if ( url_data )
094a4b10e8d5 Maintain list of outstanding async calls made so that it can be canceled when the account is disconnected.
Pieter Loubser <pieter.loubser@mxit.com>
parents: 33807
diff changeset
317 session->async_calls = g_slist_prepend( session->async_calls, url_data );
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
318
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
319 g_free( url );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
320 if ( part )
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
321 g_free( part );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
322 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
323
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
324
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
325 /*------------------------------------------------------------------------
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
326 * TX Step 3: Write the packet data to the HTTP connection (POST style).
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
327 *
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
328 * @param session The MXit session object
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
329 * @param pktdata The packet data
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
330 * @param pktlen The length of the packet data
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
331 * @return Return -1 on error, otherwise 0
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
332 */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
333 static void mxit_write_http_post( struct MXitSession* session, struct tx_packet* packet )
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
334 {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
335 char request[256 + packet->datalen];
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
336 int reqlen;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
337 char* host_name;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
338 int host_port;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
339 gboolean ok;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
340
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
341 /* extract the HTTP host name and host port number to connect to */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
342 ok = purple_url_parse( session->http_server, &host_name, &host_port, NULL, NULL, NULL );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
343 if ( !ok ) {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
344 purple_debug_error( MXIT_PLUGIN_ID, "HTTP POST error: (host name '%s' not valid)\n", session->http_server );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
345 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
346
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
347 /* strip off the last '&' from the header */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
348 packet->header[packet->headerlen - 1] = '\0';
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
349 packet->headerlen--;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
350
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
351 /* build the HTTP request packet */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
352 reqlen = g_snprintf( request, 256,
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
353 "POST %s?%s HTTP/1.1\r\n"
28961
8d0d6488031f struct tx_packet->datalen is an int, so use %d here instead of G_GSIZE_FORMAT
Mark Doliner <markdoliner@pidgin.im>
parents: 28957
diff changeset
354 "User-Agent: " MXIT_HTTP_USERAGENT "\r\n"
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
355 "Content-Type: application/octet-stream\r\n"
28961
8d0d6488031f struct tx_packet->datalen is an int, so use %d here instead of G_GSIZE_FORMAT
Mark Doliner <markdoliner@pidgin.im>
parents: 28957
diff changeset
356 "Host: %s\r\n"
8d0d6488031f struct tx_packet->datalen is an int, so use %d here instead of G_GSIZE_FORMAT
Mark Doliner <markdoliner@pidgin.im>
parents: 28957
diff changeset
357 "Content-Length: %d\r\n"
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
358 "\r\n",
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
359 session->http_server,
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
360 purple_url_encode( packet->header ),
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
361 host_name,
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
362 packet->datalen - MXIT_MS_OFFSET
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
363 );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
364
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
365 /* copy over the packet body data (could be binary) */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
366 memcpy( request + reqlen, packet->data + MXIT_MS_OFFSET, packet->datalen - MXIT_MS_OFFSET );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
367 reqlen += packet->datalen;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
368
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
369 #ifdef DEBUG_PROTOCOL
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
370 purple_debug_info( MXIT_PLUGIN_ID, "HTTP POST:\n" );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
371 dump_bytes( session, request, reqlen );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
372 #endif
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
373
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
374 /* send the request to the HTTP server */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
375 mxit_http_send_request( session, host_name, host_port, request, reqlen );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
376 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
377
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
378
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
379 /*------------------------------------------------------------------------
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
380 * TX Step 2: Handle the transmission of the packet to the MXit server.
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
381 *
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
382 * @param session The MXit session object
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
383 * @param packet The packet to transmit
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
384 */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
385 static void mxit_send_packet( struct MXitSession* session, struct tx_packet* packet )
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
386 {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
387 int res;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
388
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
389 if ( !( session->flags & MXIT_FLAG_CONNECTED ) ) {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
390 /* we are not connected so ignore all packets to be send */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
391 purple_debug_error( MXIT_PLUGIN_ID, "Dropping TX packet (we are not connected)\n" );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
392 return;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
393 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
394
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
395 purple_debug_info( MXIT_PLUGIN_ID, "Packet send CMD:%i (%i)\n", packet->cmd, packet->headerlen + packet->datalen );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
396 #ifdef DEBUG_PROTOCOL
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
397 dump_bytes( session, packet->header, packet->headerlen );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
398 dump_bytes( session, packet->data, packet->datalen );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
399 #endif
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
400
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
401 if ( !session->http ) {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
402 /* socket connection */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
403 char data[packet->datalen + packet->headerlen];
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
404 int datalen;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
405
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
406 /* create raw data buffer */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
407 memcpy( data, packet->header, packet->headerlen );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
408 memcpy( data + packet->headerlen, packet->data, packet->datalen );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
409 datalen = packet->headerlen + packet->datalen;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
410
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
411 res = mxit_write_sock_packet( session->fd, data, datalen );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
412 if ( res < 0 ) {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
413 /* we must have lost the connection, so terminate it so that we can reconnect */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
414 purple_connection_error( session->con, _( "We have lost the connection to MXit. Please reconnect." ) );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
415 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
416 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
417 else {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
418 /* http connection */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
419
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
420 if ( packet->cmd == CP_CMD_MEDIA ) {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
421 /* multimedia packets must be send with a HTTP POST */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
422 mxit_write_http_post( session, packet );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
423 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
424 else {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
425 mxit_write_http_get( session, packet );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
426 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
427 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
428
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
429 /* update the timestamp of the last-transmitted packet */
31501
4a96cf0f177a * do not send requests too fast to the mxit server or they will start ignoring you.
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31499
diff changeset
430 session->last_tx = mxit_now_milli();
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
431
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
432 /*
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
433 * we need to remember that we are still waiting for the ACK from
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
434 * the server on this request
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
435 */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
436 session->outack = packet->cmd;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
437
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
438 /* free up the packet resources */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
439 free_tx_packet( packet );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
440 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
441
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
442
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
443 /*------------------------------------------------------------------------
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
444 * TX Step 1: Create a new Tx packet and queue it for sending.
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
445 *
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
446 * @param session The MXit session object
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
447 * @param data The packet data (payload)
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
448 * @param datalen The length of the packet data
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
449 * @param cmd The MXit command for this packet
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
450 */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
451 static void mxit_queue_packet( struct MXitSession* session, const char* data, int datalen, int cmd )
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
452 {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
453 struct tx_packet* packet;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
454 char header[256];
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
455 int hlen;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
456
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
457 /* create a packet for sending */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
458 packet = g_new0( struct tx_packet, 1 );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
459 packet->data = g_malloc0( datalen );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
460 packet->cmd = cmd;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
461 packet->headerlen = 0;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
462
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
463 /* create generic packet header */
33830
36a1ce60ce7b MXit: Rather use g_snprintf().
Andrew Victor <andrew.victor@mxit.com>
parents: 33821
diff changeset
464 hlen = g_snprintf( header, sizeof( header ), "id=%s%c", purple_account_get_username( session->acc ), CP_REC_TERM ); /* client mxitid */
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
465
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
466 if ( session->http ) {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
467 /* http connection only */
33830
36a1ce60ce7b MXit: Rather use g_snprintf().
Andrew Victor <andrew.victor@mxit.com>
parents: 33821
diff changeset
468 hlen += g_snprintf( header + hlen, sizeof( header ) - hlen, "s=" );
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
469 if ( session->http_sesid > 0 ) {
33830
36a1ce60ce7b MXit: Rather use g_snprintf().
Andrew Victor <andrew.victor@mxit.com>
parents: 33821
diff changeset
470 hlen += g_snprintf( header + hlen, sizeof( header ) - hlen, "%u%c", session->http_sesid, CP_FLD_TERM ); /* http session id */
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
471 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
472 session->http_seqno++;
33830
36a1ce60ce7b MXit: Rather use g_snprintf().
Andrew Victor <andrew.victor@mxit.com>
parents: 33821
diff changeset
473 hlen += g_snprintf( header + hlen, sizeof( header ) - hlen, "%u%c", session->http_seqno, CP_REC_TERM ); /* http request sequence id */
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
474 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
475
33830
36a1ce60ce7b MXit: Rather use g_snprintf().
Andrew Victor <andrew.victor@mxit.com>
parents: 33821
diff changeset
476 hlen += g_snprintf( header + hlen, sizeof( header ) - hlen, "cm=%i%c", cmd, CP_REC_TERM ); /* packet command */
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
477
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
478 if ( !session->http ) {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
479 /* socket connection only */
33830
36a1ce60ce7b MXit: Rather use g_snprintf().
Andrew Victor <andrew.victor@mxit.com>
parents: 33821
diff changeset
480 packet->headerlen = g_snprintf( packet->header, sizeof( packet->header ), "ln=%i%c", ( datalen + hlen ), CP_REC_TERM ); /* packet length */
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
481 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
482
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
483 /* copy the header to packet */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
484 memcpy( packet->header + packet->headerlen, header, hlen );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
485 packet->headerlen += hlen;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
486
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
487 /* copy payload to packet */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
488 if ( datalen > 0 )
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
489 memcpy( packet->data, data, datalen );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
490 packet->datalen = datalen;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
491
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
492
31501
4a96cf0f177a * do not send requests too fast to the mxit server or they will start ignoring you.
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31499
diff changeset
493 /* shortcut */
4a96cf0f177a * do not send requests too fast to the mxit server or they will start ignoring you.
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31499
diff changeset
494 if ( ( session->queue.count == 0 ) && ( session->outack == 0 ) ) {
4a96cf0f177a * do not send requests too fast to the mxit server or they will start ignoring you.
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31499
diff changeset
495 /* the queue is empty and there are no outstanding acks so we can write it directly */
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
496 mxit_send_packet( session, packet );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
497 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
498 else {
31501
4a96cf0f177a * do not send requests too fast to the mxit server or they will start ignoring you.
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31499
diff changeset
499 /* we need to queue this packet */
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
500
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
501 if ( ( packet->cmd == CP_CMD_PING ) || ( packet->cmd == CP_CMD_POLL ) ) {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
502 /* we do NOT queue HTTP poll nor socket ping packets */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
503 free_tx_packet( packet );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
504 return;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
505 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
506
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
507 purple_debug_info( MXIT_PLUGIN_ID, "queueing packet for later sending cmd=%i\n", cmd );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
508 if ( !push_tx_packet( session, packet ) ) {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
509 /* packet could not be queued for transmission */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
510 mxit_popup( PURPLE_NOTIFY_MSG_ERROR, _( "Message Send Error" ), _( "Unable to process your request at this time" ) );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
511 free_tx_packet( packet );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
512 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
513 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
514 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
515
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
516
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
517 /*------------------------------------------------------------------------
31501
4a96cf0f177a * do not send requests too fast to the mxit server or they will start ignoring you.
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31499
diff changeset
518 * Manage the packet send queue (send next packet, timeout's, etc).
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
519 *
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
520 * @param session The MXit session object
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
521 */
31501
4a96cf0f177a * do not send requests too fast to the mxit server or they will start ignoring you.
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31499
diff changeset
522 static void mxit_manage_queue( struct MXitSession* session )
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
523 {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
524 struct tx_packet* packet = NULL;
31501
4a96cf0f177a * do not send requests too fast to the mxit server or they will start ignoring you.
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31499
diff changeset
525 gint64 now = mxit_now_milli();
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
526
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
527 if ( !( session->flags & MXIT_FLAG_CONNECTED ) ) {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
528 /* we are not connected, so ignore the queue */
31501
4a96cf0f177a * do not send requests too fast to the mxit server or they will start ignoring you.
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31499
diff changeset
529 return;
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
530 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
531 else if ( session->outack > 0 ) {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
532 /* we are still waiting for an outstanding ACK from the MXit server */
31501
4a96cf0f177a * do not send requests too fast to the mxit server or they will start ignoring you.
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31499
diff changeset
533 if ( session->last_tx <= mxit_now_milli() - ( MXIT_ACK_TIMEOUT * 1000 ) ) {
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
534 /* ack timeout! so we close the connection here */
30369
283eb4c5e902 For the debug message:
Andrew Victor <andrew.victor@mxit.com>
parents: 30304
diff changeset
535 purple_debug_info( MXIT_PLUGIN_ID, "mxit_manage_queue: Timeout awaiting ACK for command '%i'\n", session->outack );
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
536 purple_connection_error( session->con, _( "Timeout while waiting for a response from the MXit server." ) );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
537 }
31501
4a96cf0f177a * do not send requests too fast to the mxit server or they will start ignoring you.
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31499
diff changeset
538 return;
4a96cf0f177a * do not send requests too fast to the mxit server or they will start ignoring you.
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31499
diff changeset
539 }
4a96cf0f177a * do not send requests too fast to the mxit server or they will start ignoring you.
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31499
diff changeset
540
31707
a5adda59bea4 Searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31706
diff changeset
541 /*
31501
4a96cf0f177a * do not send requests too fast to the mxit server or they will start ignoring you.
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31499
diff changeset
542 * the mxit server has flood detection and it prevents you from sending messages to fast.
4a96cf0f177a * do not send requests too fast to the mxit server or they will start ignoring you.
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31499
diff changeset
543 * this is a self defense mechanism, a very annoying feature. so the client must ensure that
4a96cf0f177a * do not send requests too fast to the mxit server or they will start ignoring you.
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31499
diff changeset
544 * it does not send messages too fast otherwise mxit will ignore the user for 30 seconds.
4a96cf0f177a * do not send requests too fast to the mxit server or they will start ignoring you.
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31499
diff changeset
545 * this is what we are trying to avoid here..
4a96cf0f177a * do not send requests too fast to the mxit server or they will start ignoring you.
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31499
diff changeset
546 */
31706
a86fb9e2b8d4 * fixed crash caused by entering a wrong password (tx queue management)
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31704
diff changeset
547 if ( session->q_fast_timer_id == 0 ) {
a86fb9e2b8d4 * fixed crash caused by entering a wrong password (tx queue management)
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31704
diff changeset
548 /* the fast timer has not been set yet */
a86fb9e2b8d4 * fixed crash caused by entering a wrong password (tx queue management)
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31704
diff changeset
549 if ( session->last_tx > ( now - MXIT_TX_DELAY ) ) {
a86fb9e2b8d4 * fixed crash caused by entering a wrong password (tx queue management)
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31704
diff changeset
550 /* we need to wait a little before sending the next packet, so schedule a wakeup call */
a86fb9e2b8d4 * fixed crash caused by entering a wrong password (tx queue management)
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31704
diff changeset
551 gint64 tdiff = now - ( session->last_tx );
a86fb9e2b8d4 * fixed crash caused by entering a wrong password (tx queue management)
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31704
diff changeset
552 guint delay = ( MXIT_TX_DELAY - tdiff ) + 9;
a86fb9e2b8d4 * fixed crash caused by entering a wrong password (tx queue management)
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31704
diff changeset
553 if ( delay <= 0 )
a86fb9e2b8d4 * fixed crash caused by entering a wrong password (tx queue management)
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31704
diff changeset
554 delay = MXIT_TX_DELAY;
a86fb9e2b8d4 * fixed crash caused by entering a wrong password (tx queue management)
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31704
diff changeset
555 session->q_fast_timer_id = purple_timeout_add( delay, mxit_manage_queue_fast, session );
a86fb9e2b8d4 * fixed crash caused by entering a wrong password (tx queue management)
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31704
diff changeset
556 }
a86fb9e2b8d4 * fixed crash caused by entering a wrong password (tx queue management)
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31704
diff changeset
557 else {
a86fb9e2b8d4 * fixed crash caused by entering a wrong password (tx queue management)
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31704
diff changeset
558 /* get the next packet from the queue to send */
a86fb9e2b8d4 * fixed crash caused by entering a wrong password (tx queue management)
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31704
diff changeset
559 packet = pop_tx_packet( session );
a86fb9e2b8d4 * fixed crash caused by entering a wrong password (tx queue management)
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31704
diff changeset
560 if ( packet != NULL ) {
a86fb9e2b8d4 * fixed crash caused by entering a wrong password (tx queue management)
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31704
diff changeset
561 /* there was a packet waiting to be sent to the server, now is the time to do something about it */
a86fb9e2b8d4 * fixed crash caused by entering a wrong password (tx queue management)
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31704
diff changeset
562
a86fb9e2b8d4 * fixed crash caused by entering a wrong password (tx queue management)
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31704
diff changeset
563 /* send the packet to MXit server */
a86fb9e2b8d4 * fixed crash caused by entering a wrong password (tx queue management)
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31704
diff changeset
564 mxit_send_packet( session, packet );
a86fb9e2b8d4 * fixed crash caused by entering a wrong password (tx queue management)
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31704
diff changeset
565 }
31501
4a96cf0f177a * do not send requests too fast to the mxit server or they will start ignoring you.
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31499
diff changeset
566 }
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
567 }
31501
4a96cf0f177a * do not send requests too fast to the mxit server or they will start ignoring you.
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31499
diff changeset
568 }
4a96cf0f177a * do not send requests too fast to the mxit server or they will start ignoring you.
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31499
diff changeset
569
4a96cf0f177a * do not send requests too fast to the mxit server or they will start ignoring you.
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31499
diff changeset
570
4a96cf0f177a * do not send requests too fast to the mxit server or they will start ignoring you.
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31499
diff changeset
571 /*------------------------------------------------------------------------
4a96cf0f177a * do not send requests too fast to the mxit server or they will start ignoring you.
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31499
diff changeset
572 * Slow callback to manage the packet send queue.
4a96cf0f177a * do not send requests too fast to the mxit server or they will start ignoring you.
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31499
diff changeset
573 *
4a96cf0f177a * do not send requests too fast to the mxit server or they will start ignoring you.
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31499
diff changeset
574 * @param session The MXit session object
4a96cf0f177a * do not send requests too fast to the mxit server or they will start ignoring you.
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31499
diff changeset
575 */
4a96cf0f177a * do not send requests too fast to the mxit server or they will start ignoring you.
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31499
diff changeset
576 gboolean mxit_manage_queue_slow( gpointer user_data )
4a96cf0f177a * do not send requests too fast to the mxit server or they will start ignoring you.
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31499
diff changeset
577 {
4a96cf0f177a * do not send requests too fast to the mxit server or they will start ignoring you.
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31499
diff changeset
578 struct MXitSession* session = (struct MXitSession*) user_data;
4a96cf0f177a * do not send requests too fast to the mxit server or they will start ignoring you.
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31499
diff changeset
579
4a96cf0f177a * do not send requests too fast to the mxit server or they will start ignoring you.
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31499
diff changeset
580 mxit_manage_queue( session );
4a96cf0f177a * do not send requests too fast to the mxit server or they will start ignoring you.
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31499
diff changeset
581
4a96cf0f177a * do not send requests too fast to the mxit server or they will start ignoring you.
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31499
diff changeset
582 /* continue running */
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
583 return TRUE;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
584 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
585
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
586
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
587 /*------------------------------------------------------------------------
31501
4a96cf0f177a * do not send requests too fast to the mxit server or they will start ignoring you.
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31499
diff changeset
588 * Fast callback to manage the packet send queue.
4a96cf0f177a * do not send requests too fast to the mxit server or they will start ignoring you.
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31499
diff changeset
589 *
4a96cf0f177a * do not send requests too fast to the mxit server or they will start ignoring you.
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31499
diff changeset
590 * @param session The MXit session object
4a96cf0f177a * do not send requests too fast to the mxit server or they will start ignoring you.
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31499
diff changeset
591 */
4a96cf0f177a * do not send requests too fast to the mxit server or they will start ignoring you.
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31499
diff changeset
592 gboolean mxit_manage_queue_fast( gpointer user_data )
4a96cf0f177a * do not send requests too fast to the mxit server or they will start ignoring you.
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31499
diff changeset
593 {
4a96cf0f177a * do not send requests too fast to the mxit server or they will start ignoring you.
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31499
diff changeset
594 struct MXitSession* session = (struct MXitSession*) user_data;
4a96cf0f177a * do not send requests too fast to the mxit server or they will start ignoring you.
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31499
diff changeset
595
31706
a86fb9e2b8d4 * fixed crash caused by entering a wrong password (tx queue management)
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31704
diff changeset
596 session->q_fast_timer_id = 0;
31501
4a96cf0f177a * do not send requests too fast to the mxit server or they will start ignoring you.
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31499
diff changeset
597 mxit_manage_queue( session );
4a96cf0f177a * do not send requests too fast to the mxit server or they will start ignoring you.
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31499
diff changeset
598
4a96cf0f177a * do not send requests too fast to the mxit server or they will start ignoring you.
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31499
diff changeset
599 /* stop running */
4a96cf0f177a * do not send requests too fast to the mxit server or they will start ignoring you.
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31499
diff changeset
600 return FALSE;
4a96cf0f177a * do not send requests too fast to the mxit server or they will start ignoring you.
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31499
diff changeset
601 }
4a96cf0f177a * do not send requests too fast to the mxit server or they will start ignoring you.
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31499
diff changeset
602
4a96cf0f177a * do not send requests too fast to the mxit server or they will start ignoring you.
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31499
diff changeset
603
4a96cf0f177a * do not send requests too fast to the mxit server or they will start ignoring you.
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31499
diff changeset
604 /*------------------------------------------------------------------------
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
605 * Callback to manage HTTP server polling (HTTP connections ONLY)
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
606 *
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
607 * @param session The MXit session object
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
608 */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
609 gboolean mxit_manage_polling( gpointer user_data )
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
610 {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
611 struct MXitSession* session = (struct MXitSession*) user_data;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
612 gboolean poll = FALSE;
31501
4a96cf0f177a * do not send requests too fast to the mxit server or they will start ignoring you.
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31499
diff changeset
613 gint64 now = mxit_now_milli();
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
614 int polldiff;
31501
4a96cf0f177a * do not send requests too fast to the mxit server or they will start ignoring you.
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31499
diff changeset
615 gint64 rxdiff;
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
616
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
617 if ( !( session->flags & MXIT_FLAG_LOGGEDIN ) ) {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
618 /* we only poll if we are actually logged in */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
619 return TRUE;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
620 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
621
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
622 /* calculate the time differences */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
623 rxdiff = now - session->last_rx;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
624 polldiff = now - session->http_last_poll;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
625
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
626 if ( rxdiff < MXIT_HTTP_POLL_MIN ) {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
627 /* we received some reply a few moments ago, so reset the poll interval */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
628 session->http_interval = MXIT_HTTP_POLL_MIN;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
629 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
630 else if ( session->http_last_poll < ( now - session->http_interval ) ) {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
631 /* time to poll again */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
632 poll = TRUE;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
633
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
634 /* back-off some more with the polling */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
635 session->http_interval = session->http_interval + ( session->http_interval / 2 );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
636 if ( session->http_interval > MXIT_HTTP_POLL_MAX )
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
637 session->http_interval = MXIT_HTTP_POLL_MAX;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
638 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
639
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
640 /* debugging */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
641 //purple_debug_info( MXIT_PLUGIN_ID, "POLL TIMER: %i (%i,%i)\n", session->http_interval, rxdiff, polldiff );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
642
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
643 if ( poll ) {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
644 /* send poll request */
31501
4a96cf0f177a * do not send requests too fast to the mxit server or they will start ignoring you.
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31499
diff changeset
645 session->http_last_poll = mxit_now_milli();
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
646 mxit_send_poll( session );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
647 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
648
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
649 return TRUE;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
650 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
651
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
652
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
653 /*========================================================================================================================
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
654 * Send MXit operations.
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
655 */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
656
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
657 /*------------------------------------------------------------------------
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
658 * Send a ping/keepalive packet to MXit server.
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
659 *
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
660 * @param session The MXit session object
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
661 */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
662 void mxit_send_ping( struct MXitSession* session )
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
663 {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
664 /* queue packet for transmission */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
665 mxit_queue_packet( session, NULL, 0, CP_CMD_PING );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
666 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
667
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
668
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
669 /*------------------------------------------------------------------------
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
670 * Send a poll request to the HTTP server (HTTP connections ONLY).
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
671 *
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
672 * @param session The MXit session object
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
673 */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
674 void mxit_send_poll( struct MXitSession* session )
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
675 {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
676 /* queue packet for transmission */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
677 mxit_queue_packet( session, NULL, 0, CP_CMD_POLL );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
678 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
679
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
680
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
681 /*------------------------------------------------------------------------
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
682 * Send a logout packet to the MXit server.
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
683 *
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
684 * @param session The MXit session object
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
685 */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
686 void mxit_send_logout( struct MXitSession* session )
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
687 {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
688 /* queue packet for transmission */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
689 mxit_queue_packet( session, NULL, 0, CP_CMD_LOGOUT );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
690 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
691
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
692
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
693 /*------------------------------------------------------------------------
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
694 * Send a register packet to the MXit server.
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
695 *
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
696 * @param session The MXit session object
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
697 */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
698 void mxit_send_register( struct MXitSession* session )
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
699 {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
700 struct MXitProfile* profile = session->profile;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
701 const char* locale;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
702 char data[CP_MAX_PACKET];
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
703 int datalen;
31499
0e6efdfbe212 * Send the MXit Client version as the libpurple version rather than always "5.9.0".
Andrew Victor <andrew.victor@mxit.com>
parents: 31496
diff changeset
704 char* clientVersion;
31491
cf74b88370ea The initial protocol infrastructure for MXit Voice/Video support.
Andrew Victor <andrew.victor@mxit.com>
parents: 31294
diff changeset
705 unsigned int features = MXIT_CP_FEATURES;
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
706
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
707 locale = purple_account_get_string( session->acc, MXIT_CONFIG_LOCALE, MXIT_DEFAULT_LOCALE );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
708
31491
cf74b88370ea The initial protocol infrastructure for MXit Voice/Video support.
Andrew Victor <andrew.victor@mxit.com>
parents: 31294
diff changeset
709 /* Voice and Video supported */
33831
d160ede64878 MXit: Whitespace changes for coding-style consistency.
Andrew Victor <andrew.victor@mxit.com>
parents: 33830
diff changeset
710 if ( mxit_audio_enabled() && mxit_video_enabled() )
d160ede64878 MXit: Whitespace changes for coding-style consistency.
Andrew Victor <andrew.victor@mxit.com>
parents: 33830
diff changeset
711 features |= ( MXIT_CF_VOICE | MXIT_CF_VIDEO );
d160ede64878 MXit: Whitespace changes for coding-style consistency.
Andrew Victor <andrew.victor@mxit.com>
parents: 33830
diff changeset
712 else if ( mxit_audio_enabled() )
31491
cf74b88370ea The initial protocol infrastructure for MXit Voice/Video support.
Andrew Victor <andrew.victor@mxit.com>
parents: 31294
diff changeset
713 features |= MXIT_CF_VOICE;
cf74b88370ea The initial protocol infrastructure for MXit Voice/Video support.
Andrew Victor <andrew.victor@mxit.com>
parents: 31294
diff changeset
714
31499
0e6efdfbe212 * Send the MXit Client version as the libpurple version rather than always "5.9.0".
Andrew Victor <andrew.victor@mxit.com>
parents: 31496
diff changeset
715 /* generate client version string (eg, P-2.7.10-Y-PURPLE) */
0e6efdfbe212 * Send the MXit Client version as the libpurple version rather than always "5.9.0".
Andrew Victor <andrew.victor@mxit.com>
parents: 31496
diff changeset
716 clientVersion = g_strdup_printf( "%c-%i.%i.%i-%s-%s", MXIT_CP_DISTCODE, PURPLE_MAJOR_VERSION, PURPLE_MINOR_VERSION, PURPLE_MICRO_VERSION, MXIT_CP_ARCH, MXIT_CP_PLATFORM );
0e6efdfbe212 * Send the MXit Client version as the libpurple version rather than always "5.9.0".
Andrew Victor <andrew.victor@mxit.com>
parents: 31496
diff changeset
717
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
718 /* convert the packet to a byte stream */
33830
36a1ce60ce7b MXit: Rather use g_snprintf().
Andrew Victor <andrew.victor@mxit.com>
parents: 33821
diff changeset
719 datalen = g_snprintf( data, sizeof( data ),
30521
44e7b773d9d9 For safety, rather use g_strlcpy() and snprintf() where possible.
Andrew Victor <andrew.victor@mxit.com>
parents: 30520
diff changeset
720 "ms=%s%c%s%c%i%c%s%c" /* "ms"=password\1version\1maxreplyLen\1name\1 */
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
721 "%s%c%i%c%s%c%s%c" /* dateOfBirth\1gender\1location\1capabilities\1 */
31499
0e6efdfbe212 * Send the MXit Client version as the libpurple version rather than always "5.9.0".
Andrew Victor <andrew.victor@mxit.com>
parents: 31496
diff changeset
722 "%s%c%i%c%s%c%s" /* dc\1features\1dialingcode\1locale */
31707
a5adda59bea4 Searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31706
diff changeset
723 "%c%i%c%i", /* \1protocolVer\1lastRosterUpdate */
31499
0e6efdfbe212 * Send the MXit Client version as the libpurple version rather than always "5.9.0".
Andrew Victor <andrew.victor@mxit.com>
parents: 31496
diff changeset
724 session->encpwd, CP_FLD_TERM, clientVersion, CP_FLD_TERM, CP_MAX_FILESIZE, CP_FLD_TERM, profile->nickname, CP_FLD_TERM,
31294
73607ab89c6f Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents: 30522
diff changeset
725 profile->birthday, CP_FLD_TERM, ( profile->male ) ? 1 : 0, CP_FLD_TERM, MXIT_DEFAULT_LOC, CP_FLD_TERM, MXIT_CP_CAP, CP_FLD_TERM,
31499
0e6efdfbe212 * Send the MXit Client version as the libpurple version rather than always "5.9.0".
Andrew Victor <andrew.victor@mxit.com>
parents: 31496
diff changeset
726 session->distcode, CP_FLD_TERM, features, CP_FLD_TERM, session->dialcode, CP_FLD_TERM, locale,
0e6efdfbe212 * Send the MXit Client version as the libpurple version rather than always "5.9.0".
Andrew Victor <andrew.victor@mxit.com>
parents: 31496
diff changeset
727 CP_FLD_TERM, MXIT_CP_PROTO_VESION, CP_FLD_TERM, 0
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
728 );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
729
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
730 /* queue packet for transmission */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
731 mxit_queue_packet( session, data, datalen, CP_CMD_REGISTER );
31499
0e6efdfbe212 * Send the MXit Client version as the libpurple version rather than always "5.9.0".
Andrew Victor <andrew.victor@mxit.com>
parents: 31496
diff changeset
732
0e6efdfbe212 * Send the MXit Client version as the libpurple version rather than always "5.9.0".
Andrew Victor <andrew.victor@mxit.com>
parents: 31496
diff changeset
733 g_free( clientVersion );
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
734 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
735
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
736
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
737 /*------------------------------------------------------------------------
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
738 * Send a login packet to the MXit server.
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
739 *
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
740 * @param session The MXit session object
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
741 */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
742 void mxit_send_login( struct MXitSession* session )
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
743 {
31491
cf74b88370ea The initial protocol infrastructure for MXit Voice/Video support.
Andrew Victor <andrew.victor@mxit.com>
parents: 31294
diff changeset
744 const char* splashId;
cf74b88370ea The initial protocol infrastructure for MXit Voice/Video support.
Andrew Victor <andrew.victor@mxit.com>
parents: 31294
diff changeset
745 const char* locale;
cf74b88370ea The initial protocol infrastructure for MXit Voice/Video support.
Andrew Victor <andrew.victor@mxit.com>
parents: 31294
diff changeset
746 char data[CP_MAX_PACKET];
cf74b88370ea The initial protocol infrastructure for MXit Voice/Video support.
Andrew Victor <andrew.victor@mxit.com>
parents: 31294
diff changeset
747 int datalen;
31499
0e6efdfbe212 * Send the MXit Client version as the libpurple version rather than always "5.9.0".
Andrew Victor <andrew.victor@mxit.com>
parents: 31496
diff changeset
748 char* clientVersion;
31491
cf74b88370ea The initial protocol infrastructure for MXit Voice/Video support.
Andrew Victor <andrew.victor@mxit.com>
parents: 31294
diff changeset
749 unsigned int features = MXIT_CP_FEATURES;
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
750
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
751 locale = purple_account_get_string( session->acc, MXIT_CONFIG_LOCALE, MXIT_DEFAULT_LOCALE );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
752
31491
cf74b88370ea The initial protocol infrastructure for MXit Voice/Video support.
Andrew Victor <andrew.victor@mxit.com>
parents: 31294
diff changeset
753 /* Voice and Video supported */
33831
d160ede64878 MXit: Whitespace changes for coding-style consistency.
Andrew Victor <andrew.victor@mxit.com>
parents: 33830
diff changeset
754 if ( mxit_audio_enabled() && mxit_video_enabled() )
d160ede64878 MXit: Whitespace changes for coding-style consistency.
Andrew Victor <andrew.victor@mxit.com>
parents: 33830
diff changeset
755 features |= ( MXIT_CF_VOICE | MXIT_CF_VIDEO );
31491
cf74b88370ea The initial protocol infrastructure for MXit Voice/Video support.
Andrew Victor <andrew.victor@mxit.com>
parents: 31294
diff changeset
756 else if (mxit_audio_enabled())
cf74b88370ea The initial protocol infrastructure for MXit Voice/Video support.
Andrew Victor <andrew.victor@mxit.com>
parents: 31294
diff changeset
757 features |= MXIT_CF_VOICE;
cf74b88370ea The initial protocol infrastructure for MXit Voice/Video support.
Andrew Victor <andrew.victor@mxit.com>
parents: 31294
diff changeset
758
31499
0e6efdfbe212 * Send the MXit Client version as the libpurple version rather than always "5.9.0".
Andrew Victor <andrew.victor@mxit.com>
parents: 31496
diff changeset
759 /* generate client version string (eg, P-2.7.10-Y-PURPLE) */
0e6efdfbe212 * Send the MXit Client version as the libpurple version rather than always "5.9.0".
Andrew Victor <andrew.victor@mxit.com>
parents: 31496
diff changeset
760 clientVersion = g_strdup_printf( "%c-%i.%i.%i-%s-%s", MXIT_CP_DISTCODE, PURPLE_MAJOR_VERSION, PURPLE_MINOR_VERSION, PURPLE_MICRO_VERSION, MXIT_CP_ARCH, MXIT_CP_PLATFORM );
0e6efdfbe212 * Send the MXit Client version as the libpurple version rather than always "5.9.0".
Andrew Victor <andrew.victor@mxit.com>
parents: 31496
diff changeset
761
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
762 /* convert the packet to a byte stream */
33830
36a1ce60ce7b MXit: Rather use g_snprintf().
Andrew Victor <andrew.victor@mxit.com>
parents: 33821
diff changeset
763 datalen = g_snprintf( data, sizeof( data ),
30521
44e7b773d9d9 For safety, rather use g_strlcpy() and snprintf() where possible.
Andrew Victor <andrew.victor@mxit.com>
parents: 30520
diff changeset
764 "ms=%s%c%s%c%i%c" /* "ms"=password\1version\1getContacts\1 */
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
765 "%s%c%s%c%i%c" /* capabilities\1dc\1features\1 */
30214
4425992b8c92 * Separate the ClientVersion from the supported ProtocolVersion.
Andrew Victor <andrew.victor@mxit.com>
parents: 30212
diff changeset
766 "%s%c%s%c" /* dialingcode\1locale\1 */
4425992b8c92 * Separate the ClientVersion from the supported ProtocolVersion.
Andrew Victor <andrew.victor@mxit.com>
parents: 30212
diff changeset
767 "%i%c%i%c%i", /* maxReplyLen\1protocolVer\1lastRosterUpdate */
31499
0e6efdfbe212 * Send the MXit Client version as the libpurple version rather than always "5.9.0".
Andrew Victor <andrew.victor@mxit.com>
parents: 31496
diff changeset
768 session->encpwd, CP_FLD_TERM, clientVersion, CP_FLD_TERM, 1, CP_FLD_TERM,
31491
cf74b88370ea The initial protocol infrastructure for MXit Voice/Video support.
Andrew Victor <andrew.victor@mxit.com>
parents: 31294
diff changeset
769 MXIT_CP_CAP, CP_FLD_TERM, session->distcode, CP_FLD_TERM, features, CP_FLD_TERM,
30214
4425992b8c92 * Separate the ClientVersion from the supported ProtocolVersion.
Andrew Victor <andrew.victor@mxit.com>
parents: 30212
diff changeset
770 session->dialcode, CP_FLD_TERM, locale, CP_FLD_TERM,
4425992b8c92 * Separate the ClientVersion from the supported ProtocolVersion.
Andrew Victor <andrew.victor@mxit.com>
parents: 30212
diff changeset
771 CP_MAX_FILESIZE, CP_FLD_TERM, MXIT_CP_PROTO_VESION, CP_FLD_TERM, 0
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
772 );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
773
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
774 /* include "custom resource" information */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
775 splashId = splash_current( session );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
776 if ( splashId != NULL )
33830
36a1ce60ce7b MXit: Rather use g_snprintf().
Andrew Victor <andrew.victor@mxit.com>
parents: 33821
diff changeset
777 datalen += g_snprintf( data + datalen, sizeof( data ) - datalen, "%ccr=%s", CP_REC_TERM, splashId );
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
778
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
779 /* queue packet for transmission */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
780 mxit_queue_packet( session, data, datalen, CP_CMD_LOGIN );
31499
0e6efdfbe212 * Send the MXit Client version as the libpurple version rather than always "5.9.0".
Andrew Victor <andrew.victor@mxit.com>
parents: 31496
diff changeset
781
0e6efdfbe212 * Send the MXit Client version as the libpurple version rather than always "5.9.0".
Andrew Victor <andrew.victor@mxit.com>
parents: 31496
diff changeset
782 g_free( clientVersion );
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
783 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
784
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
785
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
786 /*------------------------------------------------------------------------
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
787 * Send a chat message packet to the MXit server.
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
788 *
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
789 * @param session The MXit session object
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
790 * @param to The username of the recipient
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
791 * @param msg The message text
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
792 */
29216
9284748dd744 Add extra parameter to mxit_send_message() function to indicate if the message should be
Andrew Victor <andrew.victor@mxit.com>
parents: 29215
diff changeset
793 void mxit_send_message( struct MXitSession* session, const char* to, const char* msg, gboolean parse_markup, gboolean is_command )
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
794 {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
795 char data[CP_MAX_PACKET];
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
796 char* markuped_msg;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
797 int datalen;
29216
9284748dd744 Add extra parameter to mxit_send_message() function to indicate if the message should be
Andrew Victor <andrew.victor@mxit.com>
parents: 29215
diff changeset
798 int msgtype = ( is_command ? CP_MSGTYPE_COMMAND : CP_MSGTYPE_NORMAL );
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
799
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
800 /* first we need to convert the markup from libPurple to MXit format */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
801 if ( parse_markup )
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
802 markuped_msg = mxit_convert_markup_tx( msg, &msgtype );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
803 else
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
804 markuped_msg = g_strdup( msg );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
805
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
806 /* convert the packet to a byte stream */
33830
36a1ce60ce7b MXit: Rather use g_snprintf().
Andrew Victor <andrew.victor@mxit.com>
parents: 33821
diff changeset
807 datalen = g_snprintf( data, sizeof( data ),
30521
44e7b773d9d9 For safety, rather use g_strlcpy() and snprintf() where possible.
Andrew Victor <andrew.victor@mxit.com>
parents: 30520
diff changeset
808 "ms=%s%c%s%c%i%c%i", /* "ms"=jid\1msg\1type\1flags */
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
809 to, CP_FLD_TERM, markuped_msg, CP_FLD_TERM, msgtype, CP_FLD_TERM, CP_MSG_MARKUP | CP_MSG_EMOTICON
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
810 );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
811
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
812 /* free the resources */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
813 g_free( markuped_msg );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
814
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
815 /* queue packet for transmission */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
816 mxit_queue_packet( session, data, datalen, CP_CMD_TX_MSG );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
817 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
818
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
819
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
820 /*------------------------------------------------------------------------
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
821 * Send a extended profile request packet to the MXit server.
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
822 *
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
823 * @param session The MXit session object
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
824 * @param username Username who's profile is being requested (NULL = our own)
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
825 * @param nr_attribs Number of attributes being requested
31492
0341b27934f5 Defined User Search request packets.
Andrew Victor <andrew.victor@mxit.com>
parents: 31491
diff changeset
826 * @param attribute The names of the attributes
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
827 */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
828 void mxit_send_extprofile_request( struct MXitSession* session, const char* username, unsigned int nr_attrib, const char* attribute[] )
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
829 {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
830 char data[CP_MAX_PACKET];
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
831 int datalen;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
832 unsigned int i;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
833
33830
36a1ce60ce7b MXit: Rather use g_snprintf().
Andrew Victor <andrew.victor@mxit.com>
parents: 33821
diff changeset
834 datalen = g_snprintf( data, sizeof( data ),
30521
44e7b773d9d9 For safety, rather use g_strlcpy() and snprintf() where possible.
Andrew Victor <andrew.victor@mxit.com>
parents: 30520
diff changeset
835 "ms=%s%c%i", /* "ms="mxitid\1nr_attributes */
31492
0341b27934f5 Defined User Search request packets.
Andrew Victor <andrew.victor@mxit.com>
parents: 31491
diff changeset
836 ( username ? username : "" ), CP_FLD_TERM, nr_attrib
0341b27934f5 Defined User Search request packets.
Andrew Victor <andrew.victor@mxit.com>
parents: 31491
diff changeset
837 );
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
838
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
839 /* add attributes */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
840 for ( i = 0; i < nr_attrib; i++ )
33830
36a1ce60ce7b MXit: Rather use g_snprintf().
Andrew Victor <andrew.victor@mxit.com>
parents: 33821
diff changeset
841 datalen += g_snprintf( data + datalen, sizeof( data ) - datalen, "%c%s", CP_FLD_TERM, attribute[i] );
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
842
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
843 /* queue packet for transmission */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
844 mxit_queue_packet( session, data, datalen, CP_CMD_EXTPROFILE_GET );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
845 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
846
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
847
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
848 /*------------------------------------------------------------------------
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
849 * Send an update profile packet to the MXit server.
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
850 *
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
851 * @param session The MXit session object
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
852 * @param password The new password to be used for logging in (optional)
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
853 * @param nr_attrib The number of attributes
31703
7bddd313fb98 Extensions to the user profile.
Andrew Victor <andrew.victor@mxit.com>
parents: 31699
diff changeset
854 * @param attributes String containing the attribute-name, attribute-type and value (seperated by '\01')
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
855 */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
856 void mxit_send_extprofile_update( struct MXitSession* session, const char* password, unsigned int nr_attrib, const char* attributes )
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
857 {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
858 char data[CP_MAX_PACKET];
31719
a0a1e1fe74ef Move the PIN-change option into a separate PluginAction.
Andrew Victor <andrew.victor@mxit.com>
parents: 31718
diff changeset
859 gchar** parts = NULL;
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
860 int datalen;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
861 unsigned int i;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
862
31719
a0a1e1fe74ef Move the PIN-change option into a separate PluginAction.
Andrew Victor <andrew.victor@mxit.com>
parents: 31718
diff changeset
863 if ( attributes )
a0a1e1fe74ef Move the PIN-change option into a separate PluginAction.
Andrew Victor <andrew.victor@mxit.com>
parents: 31718
diff changeset
864 parts = g_strsplit( attributes, "\01", 1 + ( nr_attrib * 3 ) );
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
865
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
866 /* convert the packet to a byte stream */
33830
36a1ce60ce7b MXit: Rather use g_snprintf().
Andrew Victor <andrew.victor@mxit.com>
parents: 33821
diff changeset
867 datalen = g_snprintf( data, sizeof( data ),
30521
44e7b773d9d9 For safety, rather use g_strlcpy() and snprintf() where possible.
Andrew Victor <andrew.victor@mxit.com>
parents: 30520
diff changeset
868 "ms=%s%c%i", /* "ms"=password\1nr_attibutes */
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
869 ( password ) ? password : "", CP_FLD_TERM, nr_attrib
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
870 );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
871
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
872 /* add attributes */
33807
f7939a1534d8 Add some sanity checking to guard against mismatched parameters.
Daniel Atallah <datallah@pidgin.im>
parents: 33706
diff changeset
873 for ( i = 1; i < nr_attrib * 3; i+=3 ) {
f7939a1534d8 Add some sanity checking to guard against mismatched parameters.
Daniel Atallah <datallah@pidgin.im>
parents: 33706
diff changeset
874 if ( parts == NULL || parts[i] == NULL || parts[i + 1] == NULL || parts[i + 2] == NULL ) {
f7939a1534d8 Add some sanity checking to guard against mismatched parameters.
Daniel Atallah <datallah@pidgin.im>
parents: 33706
diff changeset
875 purple_debug_error( MXIT_PLUGIN_ID, "Invalid profile update attributes = '%s' - nbr=%u\n", attributes, nr_attrib );
f7939a1534d8 Add some sanity checking to guard against mismatched parameters.
Daniel Atallah <datallah@pidgin.im>
parents: 33706
diff changeset
876 g_strfreev( parts );
f7939a1534d8 Add some sanity checking to guard against mismatched parameters.
Daniel Atallah <datallah@pidgin.im>
parents: 33706
diff changeset
877 return;
f7939a1534d8 Add some sanity checking to guard against mismatched parameters.
Daniel Atallah <datallah@pidgin.im>
parents: 33706
diff changeset
878 }
33830
36a1ce60ce7b MXit: Rather use g_snprintf().
Andrew Victor <andrew.victor@mxit.com>
parents: 33821
diff changeset
879 datalen += g_snprintf( data + datalen, sizeof( data ) - datalen,
33820
d4800da4da85 MXit: Rather use snprintf() than sprintf().
Andrew Victor <andrew.victor@mxit.com>
parents: 33819
diff changeset
880 "%c%s%c%s%c%s", /* \1name\1type\1value */
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
881 CP_FLD_TERM, parts[i], CP_FLD_TERM, parts[i + 1], CP_FLD_TERM, parts[i + 2] );
33807
f7939a1534d8 Add some sanity checking to guard against mismatched parameters.
Daniel Atallah <datallah@pidgin.im>
parents: 33706
diff changeset
882 }
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
883
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
884 /* queue packet for transmission */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
885 mxit_queue_packet( session, data, datalen, CP_CMD_EXTPROFILE_SET );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
886
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
887 /* freeup the memory */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
888 g_strfreev( parts );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
889 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
890
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
891
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
892 /*------------------------------------------------------------------------
31492
0341b27934f5 Defined User Search request packets.
Andrew Victor <andrew.victor@mxit.com>
parents: 31491
diff changeset
893 * Send packet to request list of suggested friends.
0341b27934f5 Defined User Search request packets.
Andrew Victor <andrew.victor@mxit.com>
parents: 31491
diff changeset
894 *
0341b27934f5 Defined User Search request packets.
Andrew Victor <andrew.victor@mxit.com>
parents: 31491
diff changeset
895 * @param session The MXit session object
0341b27934f5 Defined User Search request packets.
Andrew Victor <andrew.victor@mxit.com>
parents: 31491
diff changeset
896 * @param max Maximum number of results to return
0341b27934f5 Defined User Search request packets.
Andrew Victor <andrew.victor@mxit.com>
parents: 31491
diff changeset
897 * @param nr_attribs Number of attributes being requested
31707
a5adda59bea4 Searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31706
diff changeset
898 * @param attribute The names of the attributes
31492
0341b27934f5 Defined User Search request packets.
Andrew Victor <andrew.victor@mxit.com>
parents: 31491
diff changeset
899 */
0341b27934f5 Defined User Search request packets.
Andrew Victor <andrew.victor@mxit.com>
parents: 31491
diff changeset
900 void mxit_send_suggest_friends( struct MXitSession* session, int max, unsigned int nr_attrib, const char* attribute[] )
0341b27934f5 Defined User Search request packets.
Andrew Victor <andrew.victor@mxit.com>
parents: 31491
diff changeset
901 {
0341b27934f5 Defined User Search request packets.
Andrew Victor <andrew.victor@mxit.com>
parents: 31491
diff changeset
902 char data[CP_MAX_PACKET];
0341b27934f5 Defined User Search request packets.
Andrew Victor <andrew.victor@mxit.com>
parents: 31491
diff changeset
903 int datalen;
0341b27934f5 Defined User Search request packets.
Andrew Victor <andrew.victor@mxit.com>
parents: 31491
diff changeset
904 unsigned int i;
0341b27934f5 Defined User Search request packets.
Andrew Victor <andrew.victor@mxit.com>
parents: 31491
diff changeset
905
0341b27934f5 Defined User Search request packets.
Andrew Victor <andrew.victor@mxit.com>
parents: 31491
diff changeset
906 /* convert the packet to a byte stream */
33830
36a1ce60ce7b MXit: Rather use g_snprintf().
Andrew Victor <andrew.victor@mxit.com>
parents: 33821
diff changeset
907 datalen = g_snprintf( data, sizeof( data ),
31704
5c3b94cb6cba SuggestContacts packets updated.
Andrew Victor <andrew.victor@mxit.com>
parents: 31703
diff changeset
908 "ms=%i%c%s%c%i%c%i%c%i", /* inputType \1 input \1 maxSuggestions \1 startIndex \1 numAttributes \1 name0 \1 name1 ... \1 nameN */
5c3b94cb6cba SuggestContacts packets updated.
Andrew Victor <andrew.victor@mxit.com>
parents: 31703
diff changeset
909 CP_SUGGEST_FRIENDS, CP_FLD_TERM, "", CP_FLD_TERM, max, CP_FLD_TERM, 0, CP_FLD_TERM, nr_attrib );
31492
0341b27934f5 Defined User Search request packets.
Andrew Victor <andrew.victor@mxit.com>
parents: 31491
diff changeset
910
0341b27934f5 Defined User Search request packets.
Andrew Victor <andrew.victor@mxit.com>
parents: 31491
diff changeset
911 /* add attributes */
0341b27934f5 Defined User Search request packets.
Andrew Victor <andrew.victor@mxit.com>
parents: 31491
diff changeset
912 for ( i = 0; i < nr_attrib; i++ )
33830
36a1ce60ce7b MXit: Rather use g_snprintf().
Andrew Victor <andrew.victor@mxit.com>
parents: 33821
diff changeset
913 datalen += g_snprintf( data + datalen, sizeof( data ) - datalen, "%c%s", CP_FLD_TERM, attribute[i] );
31492
0341b27934f5 Defined User Search request packets.
Andrew Victor <andrew.victor@mxit.com>
parents: 31491
diff changeset
914
0341b27934f5 Defined User Search request packets.
Andrew Victor <andrew.victor@mxit.com>
parents: 31491
diff changeset
915 /* queue packet for transmission */
31495
e83a5b4fb633 Was using the incorrect packet type.
Andrew Victor <andrew.victor@mxit.com>
parents: 31492
diff changeset
916 mxit_queue_packet( session, data, datalen, CP_CMD_SUGGESTCONTACTS );
31492
0341b27934f5 Defined User Search request packets.
Andrew Victor <andrew.victor@mxit.com>
parents: 31491
diff changeset
917 }
0341b27934f5 Defined User Search request packets.
Andrew Victor <andrew.victor@mxit.com>
parents: 31491
diff changeset
918
0341b27934f5 Defined User Search request packets.
Andrew Victor <andrew.victor@mxit.com>
parents: 31491
diff changeset
919
0341b27934f5 Defined User Search request packets.
Andrew Victor <andrew.victor@mxit.com>
parents: 31491
diff changeset
920 /*------------------------------------------------------------------------
0341b27934f5 Defined User Search request packets.
Andrew Victor <andrew.victor@mxit.com>
parents: 31491
diff changeset
921 * Send packet to perform a search for users.
0341b27934f5 Defined User Search request packets.
Andrew Victor <andrew.victor@mxit.com>
parents: 31491
diff changeset
922 *
0341b27934f5 Defined User Search request packets.
Andrew Victor <andrew.victor@mxit.com>
parents: 31491
diff changeset
923 * @param session The MXit session object
0341b27934f5 Defined User Search request packets.
Andrew Victor <andrew.victor@mxit.com>
parents: 31491
diff changeset
924 * @param max Maximum number of results to return
0341b27934f5 Defined User Search request packets.
Andrew Victor <andrew.victor@mxit.com>
parents: 31491
diff changeset
925 * @param text The search text
0341b27934f5 Defined User Search request packets.
Andrew Victor <andrew.victor@mxit.com>
parents: 31491
diff changeset
926 * @param nr_attribs Number of attributes being requested
0341b27934f5 Defined User Search request packets.
Andrew Victor <andrew.victor@mxit.com>
parents: 31491
diff changeset
927 * @param attribute The names of the attributes
0341b27934f5 Defined User Search request packets.
Andrew Victor <andrew.victor@mxit.com>
parents: 31491
diff changeset
928 */
0341b27934f5 Defined User Search request packets.
Andrew Victor <andrew.victor@mxit.com>
parents: 31491
diff changeset
929 void mxit_send_suggest_search( struct MXitSession* session, int max, const char* text, unsigned int nr_attrib, const char* attribute[] )
0341b27934f5 Defined User Search request packets.
Andrew Victor <andrew.victor@mxit.com>
parents: 31491
diff changeset
930 {
0341b27934f5 Defined User Search request packets.
Andrew Victor <andrew.victor@mxit.com>
parents: 31491
diff changeset
931 char data[CP_MAX_PACKET];
0341b27934f5 Defined User Search request packets.
Andrew Victor <andrew.victor@mxit.com>
parents: 31491
diff changeset
932 int datalen;
0341b27934f5 Defined User Search request packets.
Andrew Victor <andrew.victor@mxit.com>
parents: 31491
diff changeset
933 unsigned int i;
0341b27934f5 Defined User Search request packets.
Andrew Victor <andrew.victor@mxit.com>
parents: 31491
diff changeset
934
0341b27934f5 Defined User Search request packets.
Andrew Victor <andrew.victor@mxit.com>
parents: 31491
diff changeset
935 /* convert the packet to a byte stream */
33830
36a1ce60ce7b MXit: Rather use g_snprintf().
Andrew Victor <andrew.victor@mxit.com>
parents: 33821
diff changeset
936 datalen = g_snprintf( data, sizeof( data ),
31704
5c3b94cb6cba SuggestContacts packets updated.
Andrew Victor <andrew.victor@mxit.com>
parents: 31703
diff changeset
937 "ms=%i%c%s%c%i%c%i%c%i", /* inputType \1 input \1 maxSuggestions \1 startIndex \1 numAttributes \1 name0 \1 name1 ... \1 nameN */
5c3b94cb6cba SuggestContacts packets updated.
Andrew Victor <andrew.victor@mxit.com>
parents: 31703
diff changeset
938 CP_SUGGEST_SEARCH, CP_FLD_TERM, text, CP_FLD_TERM, max, CP_FLD_TERM, 0, CP_FLD_TERM, nr_attrib );
31492
0341b27934f5 Defined User Search request packets.
Andrew Victor <andrew.victor@mxit.com>
parents: 31491
diff changeset
939
0341b27934f5 Defined User Search request packets.
Andrew Victor <andrew.victor@mxit.com>
parents: 31491
diff changeset
940 /* add attributes */
0341b27934f5 Defined User Search request packets.
Andrew Victor <andrew.victor@mxit.com>
parents: 31491
diff changeset
941 for ( i = 0; i < nr_attrib; i++ )
33830
36a1ce60ce7b MXit: Rather use g_snprintf().
Andrew Victor <andrew.victor@mxit.com>
parents: 33821
diff changeset
942 datalen += g_snprintf( data + datalen, sizeof( data ) - datalen, "%c%s", CP_FLD_TERM, attribute[i] );
31492
0341b27934f5 Defined User Search request packets.
Andrew Victor <andrew.victor@mxit.com>
parents: 31491
diff changeset
943
0341b27934f5 Defined User Search request packets.
Andrew Victor <andrew.victor@mxit.com>
parents: 31491
diff changeset
944 /* queue packet for transmission */
31495
e83a5b4fb633 Was using the incorrect packet type.
Andrew Victor <andrew.victor@mxit.com>
parents: 31492
diff changeset
945 mxit_queue_packet( session, data, datalen, CP_CMD_SUGGESTCONTACTS );
31492
0341b27934f5 Defined User Search request packets.
Andrew Victor <andrew.victor@mxit.com>
parents: 31491
diff changeset
946 }
0341b27934f5 Defined User Search request packets.
Andrew Victor <andrew.victor@mxit.com>
parents: 31491
diff changeset
947
0341b27934f5 Defined User Search request packets.
Andrew Victor <andrew.victor@mxit.com>
parents: 31491
diff changeset
948
0341b27934f5 Defined User Search request packets.
Andrew Victor <andrew.victor@mxit.com>
parents: 31491
diff changeset
949 /*------------------------------------------------------------------------
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
950 * Send a presence update packet to the MXit server.
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
951 *
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
952 * @param session The MXit session object
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
953 * @param presence The presence (as per MXit types)
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
954 * @param statusmsg The status message (can be NULL)
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
955 */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
956 void mxit_send_presence( struct MXitSession* session, int presence, const char* statusmsg )
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
957 {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
958 char data[CP_MAX_PACKET];
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
959 int datalen;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
960
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
961 /* convert the packet to a byte stream */
33830
36a1ce60ce7b MXit: Rather use g_snprintf().
Andrew Victor <andrew.victor@mxit.com>
parents: 33821
diff changeset
962 datalen = g_snprintf( data, sizeof( data ),
30521
44e7b773d9d9 For safety, rather use g_strlcpy() and snprintf() where possible.
Andrew Victor <andrew.victor@mxit.com>
parents: 30520
diff changeset
963 "ms=%i%c", /* "ms"=show\1status */
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
964 presence, CP_FLD_TERM
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
965 );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
966
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
967 /* append status message (if one is set) */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
968 if ( statusmsg )
33830
36a1ce60ce7b MXit: Rather use g_snprintf().
Andrew Victor <andrew.victor@mxit.com>
parents: 33821
diff changeset
969 datalen += g_snprintf( data + datalen, sizeof( data ) - datalen, "%s", statusmsg );
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
970
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
971 /* queue packet for transmission */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
972 mxit_queue_packet( session, data, datalen, CP_CMD_STATUS );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
973 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
974
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
975
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
976 /*------------------------------------------------------------------------
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
977 * Send a mood update packet to the MXit server.
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
978 *
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
979 * @param session The MXit session object
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
980 * @param mood The mood (as per MXit types)
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
981 */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
982 void mxit_send_mood( struct MXitSession* session, int mood )
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
983 {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
984 char data[CP_MAX_PACKET];
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
985 int datalen;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
986
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
987 /* convert the packet to a byte stream */
33830
36a1ce60ce7b MXit: Rather use g_snprintf().
Andrew Victor <andrew.victor@mxit.com>
parents: 33821
diff changeset
988 datalen = g_snprintf( data, sizeof( data ),
30521
44e7b773d9d9 For safety, rather use g_strlcpy() and snprintf() where possible.
Andrew Victor <andrew.victor@mxit.com>
parents: 30520
diff changeset
989 "ms=%i", /* "ms"=mood */
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
990 mood
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
991 );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
992
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
993 /* queue packet for transmission */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
994 mxit_queue_packet( session, data, datalen, CP_CMD_MOOD );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
995 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
996
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
997
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
998 /*------------------------------------------------------------------------
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
999 * Send an invite contact packet to the MXit server.
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1000 *
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1001 * @param session The MXit session object
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1002 * @param username The username of the contact being invited
31720
4047faf09005 Protocol 6.3 change to SubscribeContact packet.
Andrew Victor <andrew.victor@mxit.com>
parents: 31719
diff changeset
1003 * @param mxitid Indicates the username is a MXitId.
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1004 * @param alias Our alias for the contact
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1005 * @param groupname Group in which contact should be stored.
31699
3b50aab9ab9a Add the invite message support to MXit prpl.
Andrew Victor <andrew.victor@mxit.com>
parents: 31501
diff changeset
1006 * @param message Invite message
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1007 */
31720
4047faf09005 Protocol 6.3 change to SubscribeContact packet.
Andrew Victor <andrew.victor@mxit.com>
parents: 31719
diff changeset
1008 void mxit_send_invite( struct MXitSession* session, const char* username, gboolean mxitid, const char* alias, const char* groupname, const char* message )
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1009 {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1010 char data[CP_MAX_PACKET];
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1011 int datalen;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1012
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1013 /* convert the packet to a byte stream */
33830
36a1ce60ce7b MXit: Rather use g_snprintf().
Andrew Victor <andrew.victor@mxit.com>
parents: 33821
diff changeset
1014 datalen = g_snprintf( data, sizeof( data ),
31720
4047faf09005 Protocol 6.3 change to SubscribeContact packet.
Andrew Victor <andrew.victor@mxit.com>
parents: 31719
diff changeset
1015 "ms=%s%c%s%c%s%c%i%c%s%c%i", /* "ms"=group \1 username \1 alias \1 type \1 msg \1 isuserid */
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1016 groupname, CP_FLD_TERM, username, CP_FLD_TERM, alias,
31720
4047faf09005 Protocol 6.3 change to SubscribeContact packet.
Andrew Victor <andrew.victor@mxit.com>
parents: 31719
diff changeset
1017 CP_FLD_TERM, MXIT_TYPE_MXIT, CP_FLD_TERM,
4047faf09005 Protocol 6.3 change to SubscribeContact packet.
Andrew Victor <andrew.victor@mxit.com>
parents: 31719
diff changeset
1018 ( message ? message : "" ), CP_FLD_TERM,
4047faf09005 Protocol 6.3 change to SubscribeContact packet.
Andrew Victor <andrew.victor@mxit.com>
parents: 31719
diff changeset
1019 ( mxitid ? 0 : 1 )
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1020 );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1021
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1022 /* queue packet for transmission */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1023 mxit_queue_packet( session, data, datalen, CP_CMD_INVITE );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1024 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1025
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1026
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1027 /*------------------------------------------------------------------------
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1028 * Send a remove contact packet to the MXit server.
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1029 *
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1030 * @param session The MXit session object
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1031 * @param username The username of the contact being removed
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1032 */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1033 void mxit_send_remove( struct MXitSession* session, const char* username )
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1034 {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1035 char data[CP_MAX_PACKET];
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1036 int datalen;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1037
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1038 /* convert the packet to a byte stream */
33830
36a1ce60ce7b MXit: Rather use g_snprintf().
Andrew Victor <andrew.victor@mxit.com>
parents: 33821
diff changeset
1039 datalen = g_snprintf( data, sizeof( data ),
30521
44e7b773d9d9 For safety, rather use g_strlcpy() and snprintf() where possible.
Andrew Victor <andrew.victor@mxit.com>
parents: 30520
diff changeset
1040 "ms=%s", /* "ms"=username */
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1041 username
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1042 );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1043
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1044 /* queue packet for transmission */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1045 mxit_queue_packet( session, data, datalen, CP_CMD_REMOVE );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1046 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1047
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1048
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1049 /*------------------------------------------------------------------------
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1050 * Send an accept subscription (invite) packet to the MXit server.
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1051 *
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1052 * @param session The MXit session object
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1053 * @param username The username of the contact being accepted
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1054 * @param alias Our alias for the contact
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1055 */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1056 void mxit_send_allow_sub( struct MXitSession* session, const char* username, const char* alias )
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1057 {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1058 char data[CP_MAX_PACKET];
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1059 int datalen;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1060
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1061 /* convert the packet to a byte stream */
33830
36a1ce60ce7b MXit: Rather use g_snprintf().
Andrew Victor <andrew.victor@mxit.com>
parents: 33821
diff changeset
1062 datalen = g_snprintf( data, sizeof( data ),
30521
44e7b773d9d9 For safety, rather use g_strlcpy() and snprintf() where possible.
Andrew Victor <andrew.victor@mxit.com>
parents: 30520
diff changeset
1063 "ms=%s%c%s%c%s", /* "ms"=username\1group\1alias */
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1064 username, CP_FLD_TERM, "", CP_FLD_TERM, alias
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1065 );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1066
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1067 /* queue packet for transmission */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1068 mxit_queue_packet( session, data, datalen, CP_CMD_ALLOW );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1069 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1070
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1071
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1072 /*------------------------------------------------------------------------
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1073 * Send an deny subscription (invite) packet to the MXit server.
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1074 *
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1075 * @param session The MXit session object
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1076 * @param username The username of the contact being denied
33706
d6b2b231d0cf MXit does support including a message when rejecting a subscription request.
Andrew Victor <andrew.victor@mxit.com>
parents: 33679
diff changeset
1077 * @param reason The message describing the reason for the rejection (can be NULL).
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1078 */
33706
d6b2b231d0cf MXit does support including a message when rejecting a subscription request.
Andrew Victor <andrew.victor@mxit.com>
parents: 33679
diff changeset
1079 void mxit_send_deny_sub( struct MXitSession* session, const char* username, const char* reason )
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1080 {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1081 char data[CP_MAX_PACKET];
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1082 int datalen;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1083
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1084 /* convert the packet to a byte stream */
33830
36a1ce60ce7b MXit: Rather use g_snprintf().
Andrew Victor <andrew.victor@mxit.com>
parents: 33821
diff changeset
1085 datalen = g_snprintf( data, sizeof( data ),
30521
44e7b773d9d9 For safety, rather use g_strlcpy() and snprintf() where possible.
Andrew Victor <andrew.victor@mxit.com>
parents: 30520
diff changeset
1086 "ms=%s", /* "ms"=username */
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1087 username
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1088 );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1089
33706
d6b2b231d0cf MXit does support including a message when rejecting a subscription request.
Andrew Victor <andrew.victor@mxit.com>
parents: 33679
diff changeset
1090 /* append reason (if one is set) */
d6b2b231d0cf MXit does support including a message when rejecting a subscription request.
Andrew Victor <andrew.victor@mxit.com>
parents: 33679
diff changeset
1091 if ( reason )
33830
36a1ce60ce7b MXit: Rather use g_snprintf().
Andrew Victor <andrew.victor@mxit.com>
parents: 33821
diff changeset
1092 datalen += g_snprintf( data + datalen, sizeof( data ) - datalen, "%c%s", CP_FLD_TERM, reason );
33706
d6b2b231d0cf MXit does support including a message when rejecting a subscription request.
Andrew Victor <andrew.victor@mxit.com>
parents: 33679
diff changeset
1093
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1094 /* queue packet for transmission */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1095 mxit_queue_packet( session, data, datalen, CP_CMD_DENY );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1096 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1097
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1098
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1099 /*------------------------------------------------------------------------
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1100 * Send an update contact packet to the MXit server.
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1101 *
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1102 * @param session The MXit session object
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1103 * @param username The username of the contact being denied
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1104 * @param alias Our alias for the contact
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1105 * @param groupname Group in which contact should be stored.
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1106 */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1107 void mxit_send_update_contact( struct MXitSession* session, const char* username, const char* alias, const char* groupname )
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1108 {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1109 char data[CP_MAX_PACKET];
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1110 int datalen;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1111
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1112 /* convert the packet to a byte stream */
33830
36a1ce60ce7b MXit: Rather use g_snprintf().
Andrew Victor <andrew.victor@mxit.com>
parents: 33821
diff changeset
1113 datalen = g_snprintf( data, sizeof( data ),
30521
44e7b773d9d9 For safety, rather use g_strlcpy() and snprintf() where possible.
Andrew Victor <andrew.victor@mxit.com>
parents: 30520
diff changeset
1114 "ms=%s%c%s%c%s", /* "ms"=groupname\1username\1alias */
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1115 groupname, CP_FLD_TERM, username, CP_FLD_TERM, alias
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1116 );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1117
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1118 /* queue packet for transmission */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1119 mxit_queue_packet( session, data, datalen, CP_CMD_UPDATE );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1120 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1121
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1122
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1123 /*------------------------------------------------------------------------
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1124 * Send a splash-screen click event packet.
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1125 *
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1126 * @param session The MXit session object
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1127 * @param splashid The identifier of the splash-screen
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1128 */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1129 void mxit_send_splashclick( struct MXitSession* session, const char* splashid )
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1130 {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1131 char data[CP_MAX_PACKET];
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1132 int datalen;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1133
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1134 /* convert the packet to a byte stream */
33830
36a1ce60ce7b MXit: Rather use g_snprintf().
Andrew Victor <andrew.victor@mxit.com>
parents: 33821
diff changeset
1135 datalen = g_snprintf( data, sizeof( data ),
30521
44e7b773d9d9 For safety, rather use g_strlcpy() and snprintf() where possible.
Andrew Victor <andrew.victor@mxit.com>
parents: 30520
diff changeset
1136 "ms=%s", /* "ms"=splashId */
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1137 splashid
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1138 );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1139
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1140 /* queue packet for transmission */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1141 mxit_queue_packet( session, data, datalen, CP_CMD_SPLASHCLICK );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1142 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1143
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1144
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1145 /*------------------------------------------------------------------------
30203
05aeaba91b78 Add support for message delivery notification.
Andrew Victor <andrew.victor@mxit.com>
parents: 30167
diff changeset
1146 * Send a message event packet.
05aeaba91b78 Add support for message delivery notification.
Andrew Victor <andrew.victor@mxit.com>
parents: 30167
diff changeset
1147 *
05aeaba91b78 Add support for message delivery notification.
Andrew Victor <andrew.victor@mxit.com>
parents: 30167
diff changeset
1148 * @param session The MXit session object
05aeaba91b78 Add support for message delivery notification.
Andrew Victor <andrew.victor@mxit.com>
parents: 30167
diff changeset
1149 * @param to The username of the original sender (ie, recipient of the event)
05aeaba91b78 Add support for message delivery notification.
Andrew Victor <andrew.victor@mxit.com>
parents: 30167
diff changeset
1150 * @param id The identifier of the event (received in message)
05aeaba91b78 Add support for message delivery notification.
Andrew Victor <andrew.victor@mxit.com>
parents: 30167
diff changeset
1151 * @param event Identified the type of event
05aeaba91b78 Add support for message delivery notification.
Andrew Victor <andrew.victor@mxit.com>
parents: 30167
diff changeset
1152 */
33831
d160ede64878 MXit: Whitespace changes for coding-style consistency.
Andrew Victor <andrew.victor@mxit.com>
parents: 33830
diff changeset
1153 void mxit_send_msgevent( struct MXitSession* session, const char* to, const char* id, int event )
30203
05aeaba91b78 Add support for message delivery notification.
Andrew Victor <andrew.victor@mxit.com>
parents: 30167
diff changeset
1154 {
05aeaba91b78 Add support for message delivery notification.
Andrew Victor <andrew.victor@mxit.com>
parents: 30167
diff changeset
1155 char data[CP_MAX_PACKET];
05aeaba91b78 Add support for message delivery notification.
Andrew Victor <andrew.victor@mxit.com>
parents: 30167
diff changeset
1156 int datalen;
05aeaba91b78 Add support for message delivery notification.
Andrew Victor <andrew.victor@mxit.com>
parents: 30167
diff changeset
1157
05aeaba91b78 Add support for message delivery notification.
Andrew Victor <andrew.victor@mxit.com>
parents: 30167
diff changeset
1158 purple_debug_info( MXIT_PLUGIN_ID, "mxit_send_msgevent: to=%s id=%s event=%i\n", to, id, event );
05aeaba91b78 Add support for message delivery notification.
Andrew Victor <andrew.victor@mxit.com>
parents: 30167
diff changeset
1159
05aeaba91b78 Add support for message delivery notification.
Andrew Victor <andrew.victor@mxit.com>
parents: 30167
diff changeset
1160 /* convert the packet to a byte stream */
33830
36a1ce60ce7b MXit: Rather use g_snprintf().
Andrew Victor <andrew.victor@mxit.com>
parents: 33821
diff changeset
1161 datalen = g_snprintf( data, sizeof( data ),
30521
44e7b773d9d9 For safety, rather use g_strlcpy() and snprintf() where possible.
Andrew Victor <andrew.victor@mxit.com>
parents: 30520
diff changeset
1162 "ms=%s%c%s%c%i", /* "ms"=contactAddress \1 id \1 event */
30203
05aeaba91b78 Add support for message delivery notification.
Andrew Victor <andrew.victor@mxit.com>
parents: 30167
diff changeset
1163 to, CP_FLD_TERM, id, CP_FLD_TERM, event
05aeaba91b78 Add support for message delivery notification.
Andrew Victor <andrew.victor@mxit.com>
parents: 30167
diff changeset
1164 );
05aeaba91b78 Add support for message delivery notification.
Andrew Victor <andrew.victor@mxit.com>
parents: 30167
diff changeset
1165
05aeaba91b78 Add support for message delivery notification.
Andrew Victor <andrew.victor@mxit.com>
parents: 30167
diff changeset
1166 /* queue packet for transmission */
05aeaba91b78 Add support for message delivery notification.
Andrew Victor <andrew.victor@mxit.com>
parents: 30167
diff changeset
1167 mxit_queue_packet( session, data, datalen, CP_CMD_MSGEVENT );
05aeaba91b78 Add support for message delivery notification.
Andrew Victor <andrew.victor@mxit.com>
parents: 30167
diff changeset
1168 }
05aeaba91b78 Add support for message delivery notification.
Andrew Victor <andrew.victor@mxit.com>
parents: 30167
diff changeset
1169
05aeaba91b78 Add support for message delivery notification.
Andrew Victor <andrew.victor@mxit.com>
parents: 30167
diff changeset
1170
05aeaba91b78 Add support for message delivery notification.
Andrew Victor <andrew.victor@mxit.com>
parents: 30167
diff changeset
1171 /*------------------------------------------------------------------------
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1172 * Send packet to create a MultiMX room.
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1173 *
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1174 * @param session The MXit session object
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1175 * @param groupname Name of the room to create
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1176 * @param nr_usernames Number of users in initial invite
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1177 * @param usernames The usernames of the users in the initial invite
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1178 */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1179 void mxit_send_groupchat_create( struct MXitSession* session, const char* groupname, int nr_usernames, const char* usernames[] )
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1180 {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1181 char data[CP_MAX_PACKET];
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1182 int datalen;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1183 int i;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1184
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1185 /* convert the packet to a byte stream */
33830
36a1ce60ce7b MXit: Rather use g_snprintf().
Andrew Victor <andrew.victor@mxit.com>
parents: 33821
diff changeset
1186 datalen = g_snprintf( data, sizeof( data ),
30521
44e7b773d9d9 For safety, rather use g_strlcpy() and snprintf() where possible.
Andrew Victor <andrew.victor@mxit.com>
parents: 30520
diff changeset
1187 "ms=%s%c%i", /* "ms"=roomname\1nr_jids\1jid0\1..\1jidN */
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1188 groupname, CP_FLD_TERM, nr_usernames
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1189 );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1190
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1191 /* add usernames */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1192 for ( i = 0; i < nr_usernames; i++ )
33830
36a1ce60ce7b MXit: Rather use g_snprintf().
Andrew Victor <andrew.victor@mxit.com>
parents: 33821
diff changeset
1193 datalen += g_snprintf( data + datalen, sizeof( data ) - datalen, "%c%s", CP_FLD_TERM, usernames[i] );
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1194
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1195 /* queue packet for transmission */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1196 mxit_queue_packet( session, data, datalen, CP_CMD_GRPCHAT_CREATE );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1197 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1198
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1199
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1200 /*------------------------------------------------------------------------
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1201 * Send packet to invite users to existing MultiMX room.
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1202 *
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1203 * @param session The MXit session object
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1204 * @param roomid The unique RoomID for the MultiMx room.
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1205 * @param nr_usernames Number of users being invited
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1206 * @param usernames The usernames of the users being invited
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1207 */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1208 void mxit_send_groupchat_invite( struct MXitSession* session, const char* roomid, int nr_usernames, const char* usernames[] )
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1209 {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1210 char data[CP_MAX_PACKET];
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1211 int datalen;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1212 int i;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1213
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1214 /* convert the packet to a byte stream */
33830
36a1ce60ce7b MXit: Rather use g_snprintf().
Andrew Victor <andrew.victor@mxit.com>
parents: 33821
diff changeset
1215 datalen = g_snprintf( data, sizeof( data ),
30521
44e7b773d9d9 For safety, rather use g_strlcpy() and snprintf() where possible.
Andrew Victor <andrew.victor@mxit.com>
parents: 30520
diff changeset
1216 "ms=%s%c%i", /* "ms"=roomid\1nr_jids\1jid0\1..\1jidN */
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1217 roomid, CP_FLD_TERM, nr_usernames
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1218 );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1219
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1220 /* add usernames */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1221 for ( i = 0; i < nr_usernames; i++ )
33830
36a1ce60ce7b MXit: Rather use g_snprintf().
Andrew Victor <andrew.victor@mxit.com>
parents: 33821
diff changeset
1222 datalen += g_snprintf( data + datalen, sizeof( data ) - datalen, "%c%s", CP_FLD_TERM, usernames[i] );
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1223
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1224 /* queue packet for transmission */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1225 mxit_queue_packet( session, data, datalen, CP_CMD_GRPCHAT_INVITE );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1226 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1227
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1228
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1229 /*------------------------------------------------------------------------
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1230 * Send a "send file direct" multimedia packet.
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1231 *
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1232 * @param session The MXit session object
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1233 * @param username The username of the recipient
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1234 * @param filename The name of the file being sent
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1235 * @param buf The content of the file
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1236 * @param buflen The length of the file contents
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1237 */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1238 void mxit_send_file( struct MXitSession* session, const char* username, const char* filename, const unsigned char* buf, int buflen )
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1239 {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1240 char data[CP_MAX_PACKET];
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1241 int datalen = 0;
28988
e59ddd6a3942 The "packed" attribute on the raw_chunk data-structure seems to be a GCC extension.
Andrew Victor <andrew.victor@mxit.com>
parents: 28961
diff changeset
1242 gchar* chunk;
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1243 int size;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1244
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1245 purple_debug_info( MXIT_PLUGIN_ID, "SENDING FILE '%s' of %i bytes to user '%s'\n", filename, buflen, username );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1246
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1247 /* convert the packet to a byte stream */
33830
36a1ce60ce7b MXit: Rather use g_snprintf().
Andrew Victor <andrew.victor@mxit.com>
parents: 33821
diff changeset
1248 datalen = g_snprintf( data, sizeof( data ), "ms=" );
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1249
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1250 /* map chunk header over data buffer */
28988
e59ddd6a3942 The "packed" attribute on the raw_chunk data-structure seems to be a GCC extension.
Andrew Victor <andrew.victor@mxit.com>
parents: 28961
diff changeset
1251 chunk = &data[datalen];
e59ddd6a3942 The "packed" attribute on the raw_chunk data-structure seems to be a GCC extension.
Andrew Victor <andrew.victor@mxit.com>
parents: 28961
diff changeset
1252
e59ddd6a3942 The "packed" attribute on the raw_chunk data-structure seems to be a GCC extension.
Andrew Victor <andrew.victor@mxit.com>
parents: 28961
diff changeset
1253 size = mxit_chunk_create_senddirect( chunk_data( chunk ), username, filename, buf, buflen );
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1254 if ( size < 0 ) {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1255 purple_debug_error( MXIT_PLUGIN_ID, "Error creating senddirect chunk (%i)\n", size );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1256 return;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1257 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1258
28988
e59ddd6a3942 The "packed" attribute on the raw_chunk data-structure seems to be a GCC extension.
Andrew Victor <andrew.victor@mxit.com>
parents: 28961
diff changeset
1259 set_chunk_type( chunk, CP_CHUNK_DIRECT_SND );
e59ddd6a3942 The "packed" attribute on the raw_chunk data-structure seems to be a GCC extension.
Andrew Victor <andrew.victor@mxit.com>
parents: 28961
diff changeset
1260 set_chunk_length( chunk, size );
e59ddd6a3942 The "packed" attribute on the raw_chunk data-structure seems to be a GCC extension.
Andrew Victor <andrew.victor@mxit.com>
parents: 28961
diff changeset
1261 datalen += MXIT_CHUNK_HEADER_SIZE + size;
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1262
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1263 /* send the byte stream to the mxit server */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1264 mxit_queue_packet( session, data, datalen, CP_CMD_MEDIA );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1265 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1266
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1267
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1268 /*------------------------------------------------------------------------
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1269 * Send a "reject file" multimedia packet.
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1270 *
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1271 * @param session The MXit session object
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1272 * @param fileid A unique ID that identifies this file
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1273 */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1274 void mxit_send_file_reject( struct MXitSession* session, const char* fileid )
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1275 {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1276 char data[CP_MAX_PACKET];
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1277 int datalen = 0;
28988
e59ddd6a3942 The "packed" attribute on the raw_chunk data-structure seems to be a GCC extension.
Andrew Victor <andrew.victor@mxit.com>
parents: 28961
diff changeset
1278 gchar* chunk;
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1279 int size;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1280
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1281 purple_debug_info( MXIT_PLUGIN_ID, "mxit_send_file_reject\n" );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1282
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1283 /* convert the packet to a byte stream */
33830
36a1ce60ce7b MXit: Rather use g_snprintf().
Andrew Victor <andrew.victor@mxit.com>
parents: 33821
diff changeset
1284 datalen = g_snprintf( data, sizeof( data ), "ms=" );
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1285
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1286 /* map chunk header over data buffer */
28988
e59ddd6a3942 The "packed" attribute on the raw_chunk data-structure seems to be a GCC extension.
Andrew Victor <andrew.victor@mxit.com>
parents: 28961
diff changeset
1287 chunk = &data[datalen];
e59ddd6a3942 The "packed" attribute on the raw_chunk data-structure seems to be a GCC extension.
Andrew Victor <andrew.victor@mxit.com>
parents: 28961
diff changeset
1288
e59ddd6a3942 The "packed" attribute on the raw_chunk data-structure seems to be a GCC extension.
Andrew Victor <andrew.victor@mxit.com>
parents: 28961
diff changeset
1289 size = mxit_chunk_create_reject( chunk_data( chunk ), fileid );
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1290 if ( size < 0 ) {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1291 purple_debug_error( MXIT_PLUGIN_ID, "Error creating reject chunk (%i)\n", size );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1292 return;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1293 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1294
28988
e59ddd6a3942 The "packed" attribute on the raw_chunk data-structure seems to be a GCC extension.
Andrew Victor <andrew.victor@mxit.com>
parents: 28961
diff changeset
1295 set_chunk_type( chunk, CP_CHUNK_REJECT );
e59ddd6a3942 The "packed" attribute on the raw_chunk data-structure seems to be a GCC extension.
Andrew Victor <andrew.victor@mxit.com>
parents: 28961
diff changeset
1296 set_chunk_length( chunk, size );
e59ddd6a3942 The "packed" attribute on the raw_chunk data-structure seems to be a GCC extension.
Andrew Victor <andrew.victor@mxit.com>
parents: 28961
diff changeset
1297 datalen += MXIT_CHUNK_HEADER_SIZE + size;
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1298
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1299 /* send the byte stream to the mxit server */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1300 mxit_queue_packet( session, data, datalen, CP_CMD_MEDIA );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1301 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1302
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1303
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1304 /*------------------------------------------------------------------------
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1305 * Send a "get file" multimedia packet.
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1306 *
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1307 * @param session The MXit session object
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1308 * @param fileid A unique ID that identifies this file
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1309 * @param filesize The number of bytes to retrieve
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1310 * @param offset Offset in file at which to start retrieving
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1311 */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1312 void mxit_send_file_accept( struct MXitSession* session, const char* fileid, int filesize, int offset )
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1313 {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1314 char data[CP_MAX_PACKET];
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1315 int datalen = 0;
28988
e59ddd6a3942 The "packed" attribute on the raw_chunk data-structure seems to be a GCC extension.
Andrew Victor <andrew.victor@mxit.com>
parents: 28961
diff changeset
1316 gchar* chunk;
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1317 int size;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1318
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1319 purple_debug_info( MXIT_PLUGIN_ID, "mxit_send_file_accept\n" );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1320
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1321 /* convert the packet to a byte stream */
33830
36a1ce60ce7b MXit: Rather use g_snprintf().
Andrew Victor <andrew.victor@mxit.com>
parents: 33821
diff changeset
1322 datalen = g_snprintf( data, sizeof( data ), "ms=" );
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1323
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1324 /* map chunk header over data buffer */
28988
e59ddd6a3942 The "packed" attribute on the raw_chunk data-structure seems to be a GCC extension.
Andrew Victor <andrew.victor@mxit.com>
parents: 28961
diff changeset
1325 chunk = &data[datalen];
e59ddd6a3942 The "packed" attribute on the raw_chunk data-structure seems to be a GCC extension.
Andrew Victor <andrew.victor@mxit.com>
parents: 28961
diff changeset
1326
e59ddd6a3942 The "packed" attribute on the raw_chunk data-structure seems to be a GCC extension.
Andrew Victor <andrew.victor@mxit.com>
parents: 28961
diff changeset
1327 size = mxit_chunk_create_get( chunk_data(chunk), fileid, filesize, offset );
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1328 if ( size < 0 ) {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1329 purple_debug_error( MXIT_PLUGIN_ID, "Error creating getfile chunk (%i)\n", size );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1330 return;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1331 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1332
28988
e59ddd6a3942 The "packed" attribute on the raw_chunk data-structure seems to be a GCC extension.
Andrew Victor <andrew.victor@mxit.com>
parents: 28961
diff changeset
1333 set_chunk_type( chunk, CP_CHUNK_GET );
e59ddd6a3942 The "packed" attribute on the raw_chunk data-structure seems to be a GCC extension.
Andrew Victor <andrew.victor@mxit.com>
parents: 28961
diff changeset
1334 set_chunk_length( chunk, size );
e59ddd6a3942 The "packed" attribute on the raw_chunk data-structure seems to be a GCC extension.
Andrew Victor <andrew.victor@mxit.com>
parents: 28961
diff changeset
1335 datalen += MXIT_CHUNK_HEADER_SIZE + size;
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1336
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1337 /* send the byte stream to the mxit server */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1338 mxit_queue_packet( session, data, datalen, CP_CMD_MEDIA );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1339 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1340
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1341
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1342 /*------------------------------------------------------------------------
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1343 * Send a "received file" multimedia packet.
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1344 *
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1345 * @param session The MXit session object
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1346 * @param status The status of the file-transfer
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1347 */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1348 void mxit_send_file_received( struct MXitSession* session, const char* fileid, short status )
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1349 {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1350 char data[CP_MAX_PACKET];
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1351 int datalen = 0;
28988
e59ddd6a3942 The "packed" attribute on the raw_chunk data-structure seems to be a GCC extension.
Andrew Victor <andrew.victor@mxit.com>
parents: 28961
diff changeset
1352 gchar* chunk;
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1353 int size;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1354
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1355 purple_debug_info( MXIT_PLUGIN_ID, "mxit_send_file_received\n" );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1356
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1357 /* convert the packet to a byte stream */
33830
36a1ce60ce7b MXit: Rather use g_snprintf().
Andrew Victor <andrew.victor@mxit.com>
parents: 33821
diff changeset
1358 datalen = g_snprintf( data, sizeof( data ), "ms=" );
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1359
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1360 /* map chunk header over data buffer */
28988
e59ddd6a3942 The "packed" attribute on the raw_chunk data-structure seems to be a GCC extension.
Andrew Victor <andrew.victor@mxit.com>
parents: 28961
diff changeset
1361 chunk = &data[datalen];
e59ddd6a3942 The "packed" attribute on the raw_chunk data-structure seems to be a GCC extension.
Andrew Victor <andrew.victor@mxit.com>
parents: 28961
diff changeset
1362
e59ddd6a3942 The "packed" attribute on the raw_chunk data-structure seems to be a GCC extension.
Andrew Victor <andrew.victor@mxit.com>
parents: 28961
diff changeset
1363 size = mxit_chunk_create_received( chunk_data(chunk), fileid, status );
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1364 if ( size < 0 ) {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1365 purple_debug_error( MXIT_PLUGIN_ID, "Error creating received chunk (%i)\n", size );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1366 return;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1367 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1368
30270
8380aae8b132 I before E, except after C
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 30203
diff changeset
1369 set_chunk_type( chunk, CP_CHUNK_RECEIVED );
28988
e59ddd6a3942 The "packed" attribute on the raw_chunk data-structure seems to be a GCC extension.
Andrew Victor <andrew.victor@mxit.com>
parents: 28961
diff changeset
1370 set_chunk_length( chunk, size );
e59ddd6a3942 The "packed" attribute on the raw_chunk data-structure seems to be a GCC extension.
Andrew Victor <andrew.victor@mxit.com>
parents: 28961
diff changeset
1371 datalen += MXIT_CHUNK_HEADER_SIZE + size;
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1372
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1373 /* send the byte stream to the mxit server */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1374 mxit_queue_packet( session, data, datalen, CP_CMD_MEDIA );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1375 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1376
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1377
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1378 /*------------------------------------------------------------------------
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1379 * Send a "set avatar" multimedia packet.
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1380 *
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1381 * @param session The MXit session object
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1382 * @param data The avatar data
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1383 * @param buflen The length of the avatar data
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1384 */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1385 void mxit_set_avatar( struct MXitSession* session, const unsigned char* avatar, int avatarlen )
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1386 {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1387 char data[CP_MAX_PACKET];
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1388 int datalen = 0;
28988
e59ddd6a3942 The "packed" attribute on the raw_chunk data-structure seems to be a GCC extension.
Andrew Victor <andrew.victor@mxit.com>
parents: 28961
diff changeset
1389 gchar* chunk;
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1390 int size;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1391
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1392 purple_debug_info( MXIT_PLUGIN_ID, "mxit_set_avatar: %i bytes\n", avatarlen );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1393
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1394 /* convert the packet to a byte stream */
33830
36a1ce60ce7b MXit: Rather use g_snprintf().
Andrew Victor <andrew.victor@mxit.com>
parents: 33821
diff changeset
1395 datalen = g_snprintf( data, sizeof( data ), "ms=" );
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1396
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1397 /* map chunk header over data buffer */
28988
e59ddd6a3942 The "packed" attribute on the raw_chunk data-structure seems to be a GCC extension.
Andrew Victor <andrew.victor@mxit.com>
parents: 28961
diff changeset
1398 chunk = &data[datalen];
e59ddd6a3942 The "packed" attribute on the raw_chunk data-structure seems to be a GCC extension.
Andrew Victor <andrew.victor@mxit.com>
parents: 28961
diff changeset
1399
e59ddd6a3942 The "packed" attribute on the raw_chunk data-structure seems to be a GCC extension.
Andrew Victor <andrew.victor@mxit.com>
parents: 28961
diff changeset
1400 size = mxit_chunk_create_set_avatar( chunk_data(chunk), avatar, avatarlen );
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1401 if ( size < 0 ) {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1402 purple_debug_error( MXIT_PLUGIN_ID, "Error creating set avatar chunk (%i)\n", size );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1403 return;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1404 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1405
28988
e59ddd6a3942 The "packed" attribute on the raw_chunk data-structure seems to be a GCC extension.
Andrew Victor <andrew.victor@mxit.com>
parents: 28961
diff changeset
1406 set_chunk_type( chunk, CP_CHUNK_SET_AVATAR );
e59ddd6a3942 The "packed" attribute on the raw_chunk data-structure seems to be a GCC extension.
Andrew Victor <andrew.victor@mxit.com>
parents: 28961
diff changeset
1407 set_chunk_length( chunk, size );
e59ddd6a3942 The "packed" attribute on the raw_chunk data-structure seems to be a GCC extension.
Andrew Victor <andrew.victor@mxit.com>
parents: 28961
diff changeset
1408 datalen += MXIT_CHUNK_HEADER_SIZE + size;
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1409
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1410 /* send the byte stream to the mxit server */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1411 mxit_queue_packet( session, data, datalen, CP_CMD_MEDIA );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1412 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1413
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1414
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1415 /*------------------------------------------------------------------------
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1416 * Send a "get avatar" multimedia packet.
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1417 *
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1418 * @param session The MXit session object
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1419 * @param mxitId The username who's avatar to request
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1420 * @param avatarId The id of the avatar image (as string)
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1421 * @param data The avatar data
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1422 * @param buflen The length of the avatar data
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1423 */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1424 void mxit_get_avatar( struct MXitSession* session, const char* mxitId, const char* avatarId )
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1425 {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1426 char data[CP_MAX_PACKET];
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1427 int datalen = 0;
28988
e59ddd6a3942 The "packed" attribute on the raw_chunk data-structure seems to be a GCC extension.
Andrew Victor <andrew.victor@mxit.com>
parents: 28961
diff changeset
1428 gchar* chunk;
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1429 int size;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1430
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1431 purple_debug_info( MXIT_PLUGIN_ID, "mxit_get_avatar: %s\n", mxitId );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1432
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1433 /* convert the packet to a byte stream */
33830
36a1ce60ce7b MXit: Rather use g_snprintf().
Andrew Victor <andrew.victor@mxit.com>
parents: 33821
diff changeset
1434 datalen = g_snprintf( data, sizeof( data ), "ms=" );
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1435
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1436 /* map chunk header over data buffer */
28988
e59ddd6a3942 The "packed" attribute on the raw_chunk data-structure seems to be a GCC extension.
Andrew Victor <andrew.victor@mxit.com>
parents: 28961
diff changeset
1437 chunk = &data[datalen];
e59ddd6a3942 The "packed" attribute on the raw_chunk data-structure seems to be a GCC extension.
Andrew Victor <andrew.victor@mxit.com>
parents: 28961
diff changeset
1438
30788
da428f8d1f97 * removed unneeded variable passing.
Pieter Loubser <pieter.loubser@mxit.com>
parents: 30522
diff changeset
1439 size = mxit_chunk_create_get_avatar( chunk_data(chunk), mxitId, avatarId );
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1440 if ( size < 0 ) {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1441 purple_debug_error( MXIT_PLUGIN_ID, "Error creating get avatar chunk (%i)\n", size );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1442 return;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1443 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1444
28988
e59ddd6a3942 The "packed" attribute on the raw_chunk data-structure seems to be a GCC extension.
Andrew Victor <andrew.victor@mxit.com>
parents: 28961
diff changeset
1445 set_chunk_type( chunk, CP_CHUNK_GET_AVATAR );
e59ddd6a3942 The "packed" attribute on the raw_chunk data-structure seems to be a GCC extension.
Andrew Victor <andrew.victor@mxit.com>
parents: 28961
diff changeset
1446 set_chunk_length( chunk, size );
e59ddd6a3942 The "packed" attribute on the raw_chunk data-structure seems to be a GCC extension.
Andrew Victor <andrew.victor@mxit.com>
parents: 28961
diff changeset
1447 datalen += MXIT_CHUNK_HEADER_SIZE + size;
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1448
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1449 /* send the byte stream to the mxit server */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1450 mxit_queue_packet( session, data, datalen, CP_CMD_MEDIA );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1451 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1452
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1453
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1454 /*------------------------------------------------------------------------
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1455 * Process a login message packet.
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1456 *
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1457 * @param session The MXit session object
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1458 * @param records The packet's data records
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1459 * @param rcount The number of data records
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1460 */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1461 static void mxit_parse_cmd_login( struct MXitSession* session, struct record** records, int rcount )
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1462 {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1463 PurpleStatus* status;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1464 int presence;
29215
794a1a1acd40 The default state on the MXit server when connecting is Available (with no status message),
Andrew Victor <andrew.victor@mxit.com>
parents: 29106
diff changeset
1465 const char* statusmsg;
33611
c5bf67fcaad0 MXit: Remove all reference to Hidden Number since it's no longer supported.
Andrew Victor <andrew.victor@mxit.com>
parents: 33555
diff changeset
1466 const char* profilelist[] = { CP_PROFILE_BIRTHDATE, CP_PROFILE_GENDER, CP_PROFILE_FULLNAME,
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1467 CP_PROFILE_TITLE, CP_PROFILE_FIRSTNAME, CP_PROFILE_LASTNAME, CP_PROFILE_EMAIL,
33555
8feb2763abe9 MXit: Add support for the Relationship Status profile attribute.
Andrew Victor <andrew.victor@mxit.com>
parents: 33554
diff changeset
1468 CP_PROFILE_MOBILENR, CP_PROFILE_WHEREAMI, CP_PROFILE_ABOUTME, CP_PROFILE_RELATIONSHIP, CP_PROFILE_FLAGS };
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1469
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1470 purple_account_set_int( session->acc, MXIT_CONFIG_STATE, MXIT_STATE_LOGIN );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1471
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1472 /* we were not yet logged in so we need to complete the login sequence here */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1473 session->flags |= MXIT_FLAG_LOGGEDIN;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1474 purple_connection_update_progress( session->con, _( "Successfully Logged In..." ), 3, 4 );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1475 purple_connection_set_state( session->con, PURPLE_CONNECTED );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1476
30167
bdf1bd968a91 When logging-in with the HTTP protocol, we need to save the HTTP info
Andrew Victor <andrew.victor@mxit.com>
parents: 29216
diff changeset
1477 /* save extra info if this is a HTTP connection */
bdf1bd968a91 When logging-in with the HTTP protocol, we need to save the HTTP info
Andrew Victor <andrew.victor@mxit.com>
parents: 29216
diff changeset
1478 if ( session->http ) {
bdf1bd968a91 When logging-in with the HTTP protocol, we need to save the HTTP info
Andrew Victor <andrew.victor@mxit.com>
parents: 29216
diff changeset
1479 /* save the http server to use for this session */
bdf1bd968a91 When logging-in with the HTTP protocol, we need to save the HTTP info
Andrew Victor <andrew.victor@mxit.com>
parents: 29216
diff changeset
1480 g_strlcpy( session->http_server, records[1]->fields[3]->data, sizeof( session->http_server ) );
bdf1bd968a91 When logging-in with the HTTP protocol, we need to save the HTTP info
Andrew Victor <andrew.victor@mxit.com>
parents: 29216
diff changeset
1481
bdf1bd968a91 When logging-in with the HTTP protocol, we need to save the HTTP info
Andrew Victor <andrew.victor@mxit.com>
parents: 29216
diff changeset
1482 /* save the session id */
bdf1bd968a91 When logging-in with the HTTP protocol, we need to save the HTTP info
Andrew Victor <andrew.victor@mxit.com>
parents: 29216
diff changeset
1483 session->http_sesid = atoi( records[0]->fields[0]->data );
bdf1bd968a91 When logging-in with the HTTP protocol, we need to save the HTTP info
Andrew Victor <andrew.victor@mxit.com>
parents: 29216
diff changeset
1484 }
bdf1bd968a91 When logging-in with the HTTP protocol, we need to save the HTTP info
Andrew Victor <andrew.victor@mxit.com>
parents: 29216
diff changeset
1485
31718
c2de8a92e675 Due to the new alpha-numeric loginnames and auto-generated userId's the
Andrew Victor <andrew.victor@mxit.com>
parents: 31714
diff changeset
1486 /* extract UserId (from protocol 5.9) */
30215
a6860a140f6e Save the user's MXitId received in the login-response packet to the Session.
Andrew Victor <andrew.victor@mxit.com>
parents: 30214
diff changeset
1487 if ( records[1]->fcount >= 9 )
30371
a307496582ab Implemented new naming conventions
Pieter Loubser <pieter.loubser@mxit.com>
parents: 30369
diff changeset
1488 session->uid = g_strdup( records[1]->fields[8]->data );
30215
a6860a140f6e Save the user's MXitId received in the login-response packet to the Session.
Andrew Victor <andrew.victor@mxit.com>
parents: 30214
diff changeset
1489
31491
cf74b88370ea The initial protocol infrastructure for MXit Voice/Video support.
Andrew Victor <andrew.victor@mxit.com>
parents: 31294
diff changeset
1490 /* extract VoIP server (from protocol 6.2) */
cf74b88370ea The initial protocol infrastructure for MXit Voice/Video support.
Andrew Victor <andrew.victor@mxit.com>
parents: 31294
diff changeset
1491 if ( records[1]->fcount >= 11 )
cf74b88370ea The initial protocol infrastructure for MXit Voice/Video support.
Andrew Victor <andrew.victor@mxit.com>
parents: 31294
diff changeset
1492 g_strlcpy( session->voip_server, records[1]->fields[10]->data, sizeof( session->voip_server ) );
cf74b88370ea The initial protocol infrastructure for MXit Voice/Video support.
Andrew Victor <andrew.victor@mxit.com>
parents: 31294
diff changeset
1493
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1494 /* display the current splash-screen */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1495 if ( splash_popup_enabled( session ) )
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1496 splash_display( session );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1497
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1498 /* update presence status */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1499 status = purple_account_get_active_status( session->acc );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1500 presence = mxit_convert_presence( purple_status_get_id( status ) );
29215
794a1a1acd40 The default state on the MXit server when connecting is Available (with no status message),
Andrew Victor <andrew.victor@mxit.com>
parents: 29106
diff changeset
1501 statusmsg = purple_status_get_attr_string( status, "message" );
794a1a1acd40 The default state on the MXit server when connecting is Available (with no status message),
Andrew Victor <andrew.victor@mxit.com>
parents: 29106
diff changeset
1502
794a1a1acd40 The default state on the MXit server when connecting is Available (with no status message),
Andrew Victor <andrew.victor@mxit.com>
parents: 29106
diff changeset
1503 if ( ( presence != MXIT_PRESENCE_ONLINE ) || ( statusmsg ) ) {
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1504 /* when logging into MXit, your default presence is online. but with the UI, one can change
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1505 * the presence to whatever. in the case where its changed to a different presence setting
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1506 * we need to send an update to the server, otherwise the user's presence will be out of
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1507 * sync between the UI and MXit.
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1508 */
29215
794a1a1acd40 The default state on the MXit server when connecting is Available (with no status message),
Andrew Victor <andrew.victor@mxit.com>
parents: 29106
diff changeset
1509 char* statusmsg1 = purple_markup_strip_html( statusmsg );
794a1a1acd40 The default state on the MXit server when connecting is Available (with no status message),
Andrew Victor <andrew.victor@mxit.com>
parents: 29106
diff changeset
1510 char* statusmsg2 = g_strndup( statusmsg1, CP_MAX_STATUS_MSG );
794a1a1acd40 The default state on the MXit server when connecting is Available (with no status message),
Andrew Victor <andrew.victor@mxit.com>
parents: 29106
diff changeset
1511
794a1a1acd40 The default state on the MXit server when connecting is Available (with no status message),
Andrew Victor <andrew.victor@mxit.com>
parents: 29106
diff changeset
1512 mxit_send_presence( session, presence, statusmsg2 );
794a1a1acd40 The default state on the MXit server when connecting is Available (with no status message),
Andrew Victor <andrew.victor@mxit.com>
parents: 29106
diff changeset
1513
794a1a1acd40 The default state on the MXit server when connecting is Available (with no status message),
Andrew Victor <andrew.victor@mxit.com>
parents: 29106
diff changeset
1514 g_free( statusmsg1 );
794a1a1acd40 The default state on the MXit server when connecting is Available (with no status message),
Andrew Victor <andrew.victor@mxit.com>
parents: 29106
diff changeset
1515 g_free( statusmsg2 );
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1516 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1517
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1518 /* retrieve our MXit profile */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1519 mxit_send_extprofile_request( session, NULL, ARRAY_SIZE( profilelist ), profilelist );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1520 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1521
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1522
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1523 /*------------------------------------------------------------------------
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1524 * Process a received message packet.
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1525 *
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1526 * @param session The MXit session object
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1527 * @param records The packet's data records
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1528 * @param rcount The number of data records
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1529 */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1530 static void mxit_parse_cmd_message( struct MXitSession* session, struct record** records, int rcount )
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1531 {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1532 struct RXMsgData* mx = NULL;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1533 char* message = NULL;
33679
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 33616
diff changeset
1534 char* sender = NULL;
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1535 int msglen = 0;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1536 int msgflags = 0;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1537 int msgtype = 0;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1538
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1539 if ( ( rcount == 1 ) || ( records[0]->fcount < 2 ) || ( records[1]->fcount == 0 ) || ( records[1]->fields[0]->len == 0 ) ) {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1540 /* packet contains no message or an empty message */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1541 return;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1542 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1543
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1544 message = records[1]->fields[0]->data;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1545 msglen = strlen( message );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1546
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1547 /* strip off dummy domain */
33679
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 33616
diff changeset
1548 sender = records[0]->fields[0]->data;
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 33616
diff changeset
1549 mxit_strip_domain( sender );
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1550
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1551 #ifdef DEBUG_PROTOCOL
33679
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 33616
diff changeset
1552 purple_debug_info( MXIT_PLUGIN_ID, "Message received from '%s'\n", sender );
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1553 #endif
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1554
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1555 /* decode message flags (if any) */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1556 if ( records[0]->fcount >= 5 )
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1557 msgflags = atoi( records[0]->fields[4]->data );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1558 msgtype = atoi( records[0]->fields[2]->data );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1559
33679
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 33616
diff changeset
1560 if ( msgflags & CP_MSG_PWD_ENCRYPTED ) {
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 33616
diff changeset
1561 /* this is a password encrypted message. we do not currently support those so ignore it */
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1562 PurpleBuddy* buddy;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1563 const char* name;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1564 char msg[128];
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1565
33679
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 33616
diff changeset
1566 buddy = purple_find_buddy( session->acc, sender );
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1567 if ( buddy )
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1568 name = purple_buddy_get_alias( buddy );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1569 else
33679
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 33616
diff changeset
1570 name = sender;
28945
f94c51ec07d9 Mark a bunch of mxit strings for translation
Mark Doliner <markdoliner@pidgin.im>
parents: 28942
diff changeset
1571 g_snprintf( msg, sizeof( msg ), _( "%s sent you an encrypted message, but it is not supported on this client." ), name );
f94c51ec07d9 Mark a bunch of mxit strings for translation
Mark Doliner <markdoliner@pidgin.im>
parents: 28942
diff changeset
1572 mxit_popup( PURPLE_NOTIFY_MSG_WARNING, _( "Message Error" ), msg );
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1573 return;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1574 }
33679
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 33616
diff changeset
1575 else if ( msgflags & CP_MSG_TL_ENCRYPTED ) {
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 33616
diff changeset
1576 /* this is a transport-layer encrypted message. */
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 33616
diff changeset
1577 message = mxit_decrypt_message( session, message );
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 33616
diff changeset
1578 if ( !message ) {
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 33616
diff changeset
1579 /* could not be decrypted */
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 33616
diff changeset
1580 serv_got_im( session->con, sender, _( "An encrypted message was received which could not be decrypted." ), PURPLE_MESSAGE_ERROR, time( NULL ) );
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 33616
diff changeset
1581 return;
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 33616
diff changeset
1582 }
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 33616
diff changeset
1583 }
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1584
30203
05aeaba91b78 Add support for message delivery notification.
Andrew Victor <andrew.victor@mxit.com>
parents: 30167
diff changeset
1585 if ( msgflags & CP_MSG_NOTIFY_DELIVERY ) {
05aeaba91b78 Add support for message delivery notification.
Andrew Victor <andrew.victor@mxit.com>
parents: 30167
diff changeset
1586 /* delivery notification is requested */
05aeaba91b78 Add support for message delivery notification.
Andrew Victor <andrew.victor@mxit.com>
parents: 30167
diff changeset
1587 if ( records[0]->fcount >= 4 )
33679
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 33616
diff changeset
1588 mxit_send_msgevent( session, sender, records[0]->fields[3]->data, CP_MSGEVENT_DELIVERED );
30203
05aeaba91b78 Add support for message delivery notification.
Andrew Victor <andrew.victor@mxit.com>
parents: 30167
diff changeset
1589 }
05aeaba91b78 Add support for message delivery notification.
Andrew Victor <andrew.victor@mxit.com>
parents: 30167
diff changeset
1590
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1591 /* create and initialise new markup struct */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1592 mx = g_new0( struct RXMsgData, 1 );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1593 mx->msg = g_string_sized_new( msglen );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1594 mx->session = session;
33679
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 33616
diff changeset
1595 mx->from = g_strdup( sender );
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1596 mx->timestamp = atoi( records[0]->fields[1]->data );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1597 mx->got_img = FALSE;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1598 mx->chatid = -1;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1599 mx->img_count = 0;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1600
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1601 /* update list of active chats */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1602 if ( !find_active_chat( session->active_chats, mx->from ) ) {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1603 session->active_chats = g_list_append( session->active_chats, g_strdup( mx->from ) );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1604 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1605
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1606 if ( is_multimx_contact( session, mx->from ) ) {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1607 /* this is a MultiMx chatroom message */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1608 multimx_message_received( mx, message, msglen, msgtype, msgflags );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1609 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1610 else {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1611 mxit_parse_markup( mx, message, msglen, msgtype, msgflags );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1612 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1613
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1614 /* we are now done parsing the message */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1615 mx->converted = TRUE;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1616 if ( mx->img_count == 0 ) {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1617 /* we have all the data we need for this message to be displayed now. */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1618 mxit_show_message( mx );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1619 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1620 else {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1621 /* this means there are still images outstanding for this message and
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1622 * still need to wait for them before we can display the message.
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1623 * so the image received callback function will eventually display
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1624 * the message. */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1625 }
33679
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 33616
diff changeset
1626
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 33616
diff changeset
1627 /* cleanup */
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 33616
diff changeset
1628 if ( msgflags & CP_MSG_TL_ENCRYPTED )
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 33616
diff changeset
1629 g_free( message );
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1630 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1631
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1632
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1633 /*------------------------------------------------------------------------
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1634 * Process a received subscription request packet.
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1635 *
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1636 * @param session The MXit session object
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1637 * @param records The packet's data records
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1638 * @param rcount The number of data records
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1639 */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1640 static void mxit_parse_cmd_new_sub( struct MXitSession* session, struct record** records, int rcount )
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1641 {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1642 struct contact* contact;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1643 struct record* rec;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1644 int i;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1645
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1646 purple_debug_info( MXIT_PLUGIN_ID, "mxit_parse_cmd_new_sub (%i recs)\n", rcount );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1647
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1648 for ( i = 0; i < rcount; i++ ) {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1649 rec = records[i];
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1650
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1651 if ( rec->fcount < 4 ) {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1652 purple_debug_error( MXIT_PLUGIN_ID, "BAD SUBSCRIPTION RECORD! %i fields\n", rec->fcount );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1653 break;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1654 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1655
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1656 /* build up a new contact info struct */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1657 contact = g_new0( struct contact, 1 );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1658
30521
44e7b773d9d9 For safety, rather use g_strlcpy() and snprintf() where possible.
Andrew Victor <andrew.victor@mxit.com>
parents: 30520
diff changeset
1659 g_strlcpy( contact->username, rec->fields[0]->data, sizeof( contact->username ) );
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1660 mxit_strip_domain( contact->username ); /* remove dummy domain */
30521
44e7b773d9d9 For safety, rather use g_strlcpy() and snprintf() where possible.
Andrew Victor <andrew.victor@mxit.com>
parents: 30520
diff changeset
1661 g_strlcpy( contact->alias, rec->fields[1]->data, sizeof( contact->alias ) );
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1662 contact->type = atoi( rec->fields[2]->data );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1663
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1664 if ( rec->fcount >= 5 ) {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1665 /* there is a personal invite message attached */
31714
4fb9e95a7c4f * extended the profile information shown for pending invites
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31711
diff changeset
1666 if ( ( rec->fields[4]->data ) && ( strlen( rec->fields[4]->data ) > 0 ) )
4fb9e95a7c4f * extended the profile information shown for pending invites
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31711
diff changeset
1667 contact->msg = strdup( rec->fields[4]->data );
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1668 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1669
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1670 /* handle the subscription */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1671 if ( contact-> type == MXIT_TYPE_MULTIMX ) { /* subscription to a MultiMX room */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1672 char* creator = NULL;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1673
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1674 if ( rec->fcount >= 6 )
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1675 creator = rec->fields[5]->data;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1676
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1677 multimx_invite( session, contact, creator );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1678 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1679 else
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1680 mxit_new_subscription( session, contact );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1681 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1682 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1683
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1684
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1685 /*------------------------------------------------------------------------
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1686 * Process a received contact update packet.
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1687 *
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1688 * @param session The MXit session object
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1689 * @param records The packet's data records
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1690 * @param rcount The number of data records
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1691 */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1692 static void mxit_parse_cmd_contact( struct MXitSession* session, struct record** records, int rcount )
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1693 {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1694 struct contact* contact = NULL;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1695 struct record* rec;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1696 int i;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1697
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1698 purple_debug_info( MXIT_PLUGIN_ID, "mxit_parse_cmd_contact (%i recs)\n", rcount );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1699
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1700 for ( i = 0; i < rcount; i++ ) {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1701 rec = records[i];
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1702
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1703 if ( rec->fcount < 6 ) {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1704 purple_debug_error( MXIT_PLUGIN_ID, "BAD CONTACT RECORD! %i fields\n", rec->fcount );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1705 break;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1706 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1707
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1708 /* build up a new contact info struct */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1709 contact = g_new0( struct contact, 1 );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1710
30521
44e7b773d9d9 For safety, rather use g_strlcpy() and snprintf() where possible.
Andrew Victor <andrew.victor@mxit.com>
parents: 30520
diff changeset
1711 g_strlcpy( contact->groupname, rec->fields[0]->data, sizeof( contact->groupname ) );
44e7b773d9d9 For safety, rather use g_strlcpy() and snprintf() where possible.
Andrew Victor <andrew.victor@mxit.com>
parents: 30520
diff changeset
1712 g_strlcpy( contact->username, rec->fields[1]->data, sizeof( contact->username ) );
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1713 mxit_strip_domain( contact->username ); /* remove dummy domain */
30521
44e7b773d9d9 For safety, rather use g_strlcpy() and snprintf() where possible.
Andrew Victor <andrew.victor@mxit.com>
parents: 30520
diff changeset
1714 g_strlcpy( contact->alias, rec->fields[2]->data, sizeof( contact->alias ) );
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1715
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1716 contact->presence = atoi( rec->fields[3]->data );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1717 contact->type = atoi( rec->fields[4]->data );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1718 contact->mood = atoi( rec->fields[5]->data );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1719
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1720 if ( rec->fcount > 6 ) {
30214
4425992b8c92 * Separate the ClientVersion from the supported ProtocolVersion.
Andrew Victor <andrew.victor@mxit.com>
parents: 30212
diff changeset
1721 /* added in protocol 5.9 - flags & subtype */
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1722 contact->flags = atoi( rec->fields[6]->data );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1723 contact->subtype = rec->fields[7]->data[0];
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1724 }
30214
4425992b8c92 * Separate the ClientVersion from the supported ProtocolVersion.
Andrew Victor <andrew.victor@mxit.com>
parents: 30212
diff changeset
1725 if ( rec->fcount > 8 ) {
4425992b8c92 * Separate the ClientVersion from the supported ProtocolVersion.
Andrew Victor <andrew.victor@mxit.com>
parents: 30212
diff changeset
1726 /* added in protocol 6.0 - reject message */
4425992b8c92 * Separate the ClientVersion from the supported ProtocolVersion.
Andrew Victor <andrew.victor@mxit.com>
parents: 30212
diff changeset
1727 contact->msg = g_strdup( rec->fields[8]->data );
4425992b8c92 * Separate the ClientVersion from the supported ProtocolVersion.
Andrew Victor <andrew.victor@mxit.com>
parents: 30212
diff changeset
1728 }
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1729
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1730 /* add the contact to the buddy list */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1731 if ( contact-> type == MXIT_TYPE_MULTIMX ) /* contact is a MultiMX room */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1732 multimx_created( session, contact );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1733 else
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1734 mxit_update_contact( session, contact );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1735 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1736
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1737 if ( !( session->flags & MXIT_FLAG_FIRSTROSTER ) ) {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1738 session->flags |= MXIT_FLAG_FIRSTROSTER;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1739 mxit_update_blist( session );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1740 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1741 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1742
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1743
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1744 /*------------------------------------------------------------------------
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1745 * Process a received presence update packet.
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1746 *
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1747 * @param session The MXit session object
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1748 * @param records The packet's data records
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1749 * @param rcount The number of data records
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1750 */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1751 static void mxit_parse_cmd_presence( struct MXitSession* session, struct record** records, int rcount )
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1752 {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1753 int i;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1754
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1755 purple_debug_info( MXIT_PLUGIN_ID, "mxit_parse_cmd_presence (%i recs)\n", rcount );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1756
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1757 for ( i = 0; i < rcount; i++ ) {
31491
cf74b88370ea The initial protocol infrastructure for MXit Voice/Video support.
Andrew Victor <andrew.victor@mxit.com>
parents: 31294
diff changeset
1758 struct record* rec = records[i];
cf74b88370ea The initial protocol infrastructure for MXit Voice/Video support.
Andrew Victor <andrew.victor@mxit.com>
parents: 31294
diff changeset
1759 int flags = 0;
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1760
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1761 if ( rec->fcount < 6 ) {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1762 purple_debug_error( MXIT_PLUGIN_ID, "BAD PRESENCE RECORD! %i fields\n", rec->fcount );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1763 break;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1764 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1765
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1766 /*
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1767 * The format of the record is:
31491
cf74b88370ea The initial protocol infrastructure for MXit Voice/Video support.
Andrew Victor <andrew.victor@mxit.com>
parents: 31294
diff changeset
1768 * contactAddressN \1 presenceN \1 moodN \1 customMoodN \1 statusMsgN \1 avatarIdN [ \1 flagsN ]
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1769 */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1770 mxit_strip_domain( rec->fields[0]->data ); /* contactAddress */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1771
31491
cf74b88370ea The initial protocol infrastructure for MXit Voice/Video support.
Andrew Victor <andrew.victor@mxit.com>
parents: 31294
diff changeset
1772 if ( rec->fcount >= 7 ) /* flags field is included */
cf74b88370ea The initial protocol infrastructure for MXit Voice/Video support.
Andrew Victor <andrew.victor@mxit.com>
parents: 31294
diff changeset
1773 flags = atoi( rec->fields[6]->data );
cf74b88370ea The initial protocol infrastructure for MXit Voice/Video support.
Andrew Victor <andrew.victor@mxit.com>
parents: 31294
diff changeset
1774
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1775 mxit_update_buddy_presence( session, rec->fields[0]->data, atoi( rec->fields[1]->data ), atoi( rec->fields[2]->data ),
31491
cf74b88370ea The initial protocol infrastructure for MXit Voice/Video support.
Andrew Victor <andrew.victor@mxit.com>
parents: 31294
diff changeset
1776 rec->fields[3]->data, rec->fields[4]->data, flags );
30522
5b84b44ed654 Since a buddy's avatar information is distributed as part of their online
Andrew Victor <andrew.victor@mxit.com>
parents: 30521
diff changeset
1777 mxit_update_buddy_avatar( session, rec->fields[0]->data, rec->fields[5]->data );
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1778 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1779 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1780
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1781
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1782 /*------------------------------------------------------------------------
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1783 * Process a received extended profile packet.
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1784 *
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1785 * @param session The MXit session object
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1786 * @param records The packet's data records
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1787 * @param rcount The number of data records
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1788 */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1789 static void mxit_parse_cmd_extprofile( struct MXitSession* session, struct record** records, int rcount )
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1790 {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1791 const char* mxitId = records[0]->fields[0]->data;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1792 struct MXitProfile* profile = NULL;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1793 int count;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1794 int i;
30522
5b84b44ed654 Since a buddy's avatar information is distributed as part of their online
Andrew Victor <andrew.victor@mxit.com>
parents: 30521
diff changeset
1795 const char* avatarId = NULL;
31841
b106342b765f When retrieving the users current Status-Message via profile packets,
Andrew Victor <andrew.victor@mxit.com>
parents: 31835
diff changeset
1796 char* statusMsg = NULL;
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1797
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1798 purple_debug_info( MXIT_PLUGIN_ID, "mxit_parse_cmd_extprofile: profile for '%s'\n", mxitId );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1799
30520
f9beda76a902 When setting an Avatar image via the Gallery bot, the MXit server pushes
Andrew Victor <andrew.victor@mxit.com>
parents: 30519
diff changeset
1800 if ( ( records[0]->fields[0]->len == 0 ) || ( session->uid && ( strcmp( session->uid, records[0]->fields[0]->data ) == 0 ) ) ) {
f9beda76a902 When setting an Avatar image via the Gallery bot, the MXit server pushes
Andrew Victor <andrew.victor@mxit.com>
parents: 30519
diff changeset
1801 /* No UserId or Our UserId provided, so this must be our own profile information */
30212
a813a8aa034e When our avatar image is changed, the MXit server will push an ExtendedProfile-Response packet
Andrew Victor <andrew.victor@mxit.com>
parents: 30211
diff changeset
1802 if ( session->profile == NULL )
a813a8aa034e When our avatar image is changed, the MXit server will push an ExtendedProfile-Response packet
Andrew Victor <andrew.victor@mxit.com>
parents: 30211
diff changeset
1803 session->profile = g_new0( struct MXitProfile, 1 );
a813a8aa034e When our avatar image is changed, the MXit server will push an ExtendedProfile-Response packet
Andrew Victor <andrew.victor@mxit.com>
parents: 30211
diff changeset
1804 profile = session->profile;
a813a8aa034e When our avatar image is changed, the MXit server will push an ExtendedProfile-Response packet
Andrew Victor <andrew.victor@mxit.com>
parents: 30211
diff changeset
1805 }
a813a8aa034e When our avatar image is changed, the MXit server will push an ExtendedProfile-Response packet
Andrew Victor <andrew.victor@mxit.com>
parents: 30211
diff changeset
1806 else {
a813a8aa034e When our avatar image is changed, the MXit server will push an ExtendedProfile-Response packet
Andrew Victor <andrew.victor@mxit.com>
parents: 30211
diff changeset
1807 /* is a buddy's profile */
a813a8aa034e When our avatar image is changed, the MXit server will push an ExtendedProfile-Response packet
Andrew Victor <andrew.victor@mxit.com>
parents: 30211
diff changeset
1808 profile = g_new0( struct MXitProfile, 1 );
a813a8aa034e When our avatar image is changed, the MXit server will push an ExtendedProfile-Response packet
Andrew Victor <andrew.victor@mxit.com>
parents: 30211
diff changeset
1809 }
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1810
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1811 /* set the count for attributes */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1812 count = atoi( records[0]->fields[1]->data );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1813
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1814 for ( i = 0; i < count; i++ ) {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1815 char* fname;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1816 char* fvalue;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1817 char* fstatus;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1818 int f = ( i * 3 ) + 2;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1819
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1820 fname = records[0]->fields[f]->data; /* field name */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1821 fvalue = records[0]->fields[f + 1]->data; /* field value */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1822 fstatus = records[0]->fields[f + 2]->data; /* field status */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1823
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1824 /* first check the status on the returned attribute */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1825 if ( fstatus[0] != '0' ) {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1826 /* error: attribute requested was NOT found */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1827 purple_debug_error( MXIT_PLUGIN_ID, "Bad profile status on attribute '%s' \n", fname );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1828 continue;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1829 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1830
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1831 if ( strcmp( CP_PROFILE_BIRTHDATE, fname ) == 0 ) {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1832 /* birthdate */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1833 if ( records[0]->fields[f + 1]->len > 10 ) {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1834 fvalue[10] = '\0';
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1835 records[0]->fields[f + 1]->len = 10;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1836 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1837 memcpy( profile->birthday, fvalue, records[0]->fields[f + 1]->len );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1838 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1839 else if ( strcmp( CP_PROFILE_GENDER, fname ) == 0 ) {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1840 /* gender */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1841 profile->male = ( fvalue[0] == '1' );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1842 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1843 else if ( strcmp( CP_PROFILE_FULLNAME, fname ) == 0 ) {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1844 /* nickname */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1845 g_strlcpy( profile->nickname, fvalue, sizeof( profile->nickname ) );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1846 }
30522
5b84b44ed654 Since a buddy's avatar information is distributed as part of their online
Andrew Victor <andrew.victor@mxit.com>
parents: 30521
diff changeset
1847 else if ( strcmp( CP_PROFILE_STATUS, fname ) == 0 ) {
5b84b44ed654 Since a buddy's avatar information is distributed as part of their online
Andrew Victor <andrew.victor@mxit.com>
parents: 30521
diff changeset
1848 /* status message - just keep a reference to the value */
31841
b106342b765f When retrieving the users current Status-Message via profile packets,
Andrew Victor <andrew.victor@mxit.com>
parents: 31835
diff changeset
1849 statusMsg = g_markup_escape_text( fvalue, -1 );
30522
5b84b44ed654 Since a buddy's avatar information is distributed as part of their online
Andrew Victor <andrew.victor@mxit.com>
parents: 30521
diff changeset
1850 }
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1851 else if ( strcmp( CP_PROFILE_AVATAR, fname ) == 0 ) {
30522
5b84b44ed654 Since a buddy's avatar information is distributed as part of their online
Andrew Victor <andrew.victor@mxit.com>
parents: 30521
diff changeset
1852 /* avatar id - just keep a reference to the value */
5b84b44ed654 Since a buddy's avatar information is distributed as part of their online
Andrew Victor <andrew.victor@mxit.com>
parents: 30521
diff changeset
1853 avatarId = fvalue;
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1854 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1855 else if ( strcmp( CP_PROFILE_TITLE, fname ) == 0 ) {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1856 /* title */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1857 g_strlcpy( profile->title, fvalue, sizeof( profile->title ) );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1858 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1859 else if ( strcmp( CP_PROFILE_FIRSTNAME, fname ) == 0 ) {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1860 /* first name */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1861 g_strlcpy( profile->firstname, fvalue, sizeof( profile->firstname ) );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1862 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1863 else if ( strcmp( CP_PROFILE_LASTNAME, fname ) == 0 ) {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1864 /* last name */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1865 g_strlcpy( profile->lastname, fvalue, sizeof( profile->lastname ) );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1866 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1867 else if ( strcmp( CP_PROFILE_EMAIL, fname ) == 0 ) {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1868 /* email address */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1869 g_strlcpy( profile->email, fvalue, sizeof( profile->email ) );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1870 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1871 else if ( strcmp( CP_PROFILE_MOBILENR, fname ) == 0 ) {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1872 /* mobile number */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1873 g_strlcpy( profile->mobilenr, fvalue, sizeof( profile->mobilenr ) );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1874 }
30211
6c81374b615e * Show the buddy's registration country in their profile.
Andrew Victor <andrew.victor@mxit.com>
parents: 30203
diff changeset
1875 else if ( strcmp( CP_PROFILE_REGCOUNTRY, fname ) == 0 ) {
6c81374b615e * Show the buddy's registration country in their profile.
Andrew Victor <andrew.victor@mxit.com>
parents: 30203
diff changeset
1876 /* registered country */
6c81374b615e * Show the buddy's registration country in their profile.
Andrew Victor <andrew.victor@mxit.com>
parents: 30203
diff changeset
1877 g_strlcpy( profile->regcountry, fvalue, sizeof( profile->regcountry ) );
6c81374b615e * Show the buddy's registration country in their profile.
Andrew Victor <andrew.victor@mxit.com>
parents: 30203
diff changeset
1878 }
30519
de9e72446479 A few changes to the Profile.
Andrew Victor <andrew.victor@mxit.com>
parents: 30371
diff changeset
1879 else if ( strcmp( CP_PROFILE_FLAGS, fname ) == 0 ) {
de9e72446479 A few changes to the Profile.
Andrew Victor <andrew.victor@mxit.com>
parents: 30371
diff changeset
1880 /* profile flags */
de9e72446479 A few changes to the Profile.
Andrew Victor <andrew.victor@mxit.com>
parents: 30371
diff changeset
1881 profile->flags = strtoll( fvalue, NULL, 10 );
de9e72446479 A few changes to the Profile.
Andrew Victor <andrew.victor@mxit.com>
parents: 30371
diff changeset
1882 }
de9e72446479 A few changes to the Profile.
Andrew Victor <andrew.victor@mxit.com>
parents: 30371
diff changeset
1883 else if ( strcmp( CP_PROFILE_LASTSEEN, fname ) == 0 ) {
de9e72446479 A few changes to the Profile.
Andrew Victor <andrew.victor@mxit.com>
parents: 30371
diff changeset
1884 /* last seen online */
de9e72446479 A few changes to the Profile.
Andrew Victor <andrew.victor@mxit.com>
parents: 30371
diff changeset
1885 profile->lastonline = strtoll( fvalue, NULL, 10 );
de9e72446479 A few changes to the Profile.
Andrew Victor <andrew.victor@mxit.com>
parents: 30371
diff changeset
1886 }
31703
7bddd313fb98 Extensions to the user profile.
Andrew Victor <andrew.victor@mxit.com>
parents: 31699
diff changeset
1887 else if ( strcmp( CP_PROFILE_WHEREAMI, fname ) == 0 ) {
7bddd313fb98 Extensions to the user profile.
Andrew Victor <andrew.victor@mxit.com>
parents: 31699
diff changeset
1888 /* where am I */
7bddd313fb98 Extensions to the user profile.
Andrew Victor <andrew.victor@mxit.com>
parents: 31699
diff changeset
1889 g_strlcpy( profile->whereami, fvalue, sizeof( profile->whereami ) );
7bddd313fb98 Extensions to the user profile.
Andrew Victor <andrew.victor@mxit.com>
parents: 31699
diff changeset
1890 }
7bddd313fb98 Extensions to the user profile.
Andrew Victor <andrew.victor@mxit.com>
parents: 31699
diff changeset
1891 else if ( strcmp( CP_PROFILE_ABOUTME, fname ) == 0) {
7bddd313fb98 Extensions to the user profile.
Andrew Victor <andrew.victor@mxit.com>
parents: 31699
diff changeset
1892 /* about me */
7bddd313fb98 Extensions to the user profile.
Andrew Victor <andrew.victor@mxit.com>
parents: 31699
diff changeset
1893 g_strlcpy( profile->aboutme, fvalue, sizeof( profile->aboutme ) );
7bddd313fb98 Extensions to the user profile.
Andrew Victor <andrew.victor@mxit.com>
parents: 31699
diff changeset
1894 }
33555
8feb2763abe9 MXit: Add support for the Relationship Status profile attribute.
Andrew Victor <andrew.victor@mxit.com>
parents: 33554
diff changeset
1895 else if ( strcmp( CP_PROFILE_RELATIONSHIP, fname ) == 0) {
8feb2763abe9 MXit: Add support for the Relationship Status profile attribute.
Andrew Victor <andrew.victor@mxit.com>
parents: 33554
diff changeset
1896 /* relatinship status */
8feb2763abe9 MXit: Add support for the Relationship Status profile attribute.
Andrew Victor <andrew.victor@mxit.com>
parents: 33554
diff changeset
1897 profile->relationship = strtol( fvalue, NULL, 10 );
8feb2763abe9 MXit: Add support for the Relationship Status profile attribute.
Andrew Victor <andrew.victor@mxit.com>
parents: 33554
diff changeset
1898 }
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1899 else {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1900 /* invalid profile attribute */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1901 purple_debug_error( MXIT_PLUGIN_ID, "Invalid profile attribute received '%s' \n", fname );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1902 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1903 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1904
30212
a813a8aa034e When our avatar image is changed, the MXit server will push an ExtendedProfile-Response packet
Andrew Victor <andrew.victor@mxit.com>
parents: 30211
diff changeset
1905 if ( profile != session->profile ) {
31714
4fb9e95a7c4f * extended the profile information shown for pending invites
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31711
diff changeset
1906 /* not our own profile */
4fb9e95a7c4f * extended the profile information shown for pending invites
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31711
diff changeset
1907 struct contact* contact = NULL;
4fb9e95a7c4f * extended the profile information shown for pending invites
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31711
diff changeset
1908
4fb9e95a7c4f * extended the profile information shown for pending invites
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31711
diff changeset
1909 contact = get_mxit_invite_contact( session, mxitId );
4fb9e95a7c4f * extended the profile information shown for pending invites
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31711
diff changeset
1910 if ( contact ) {
4fb9e95a7c4f * extended the profile information shown for pending invites
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31711
diff changeset
1911 /* this is an invite, so update its profile info */
4fb9e95a7c4f * extended the profile information shown for pending invites
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31711
diff changeset
1912 if ( ( statusMsg ) && ( strlen( statusMsg ) > 0 ) ) {
4fb9e95a7c4f * extended the profile information shown for pending invites
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31711
diff changeset
1913 /* update the status message */
4fb9e95a7c4f * extended the profile information shown for pending invites
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31711
diff changeset
1914 if ( contact->statusMsg )
4fb9e95a7c4f * extended the profile information shown for pending invites
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31711
diff changeset
1915 g_free( contact->statusMsg );
4fb9e95a7c4f * extended the profile information shown for pending invites
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31711
diff changeset
1916 contact->statusMsg = strdup( statusMsg );
4fb9e95a7c4f * extended the profile information shown for pending invites
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31711
diff changeset
1917 }
4fb9e95a7c4f * extended the profile information shown for pending invites
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31711
diff changeset
1918 else
4fb9e95a7c4f * extended the profile information shown for pending invites
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31711
diff changeset
1919 contact->statusMsg = NULL;
4fb9e95a7c4f * extended the profile information shown for pending invites
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31711
diff changeset
1920 if ( contact->profile )
4fb9e95a7c4f * extended the profile information shown for pending invites
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31711
diff changeset
1921 g_free( contact->profile );
4fb9e95a7c4f * extended the profile information shown for pending invites
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31711
diff changeset
1922 contact->profile = profile;
4fb9e95a7c4f * extended the profile information shown for pending invites
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31711
diff changeset
1923 if ( ( avatarId ) && ( strlen( avatarId ) > 0 ) ) {
4fb9e95a7c4f * extended the profile information shown for pending invites
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31711
diff changeset
1924 /* avatar must be requested for this invite before we can display it */
4fb9e95a7c4f * extended the profile information shown for pending invites
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31711
diff changeset
1925 mxit_get_avatar( session, mxitId, avatarId );
4fb9e95a7c4f * extended the profile information shown for pending invites
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31711
diff changeset
1926 if ( contact->avatarId )
4fb9e95a7c4f * extended the profile information shown for pending invites
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31711
diff changeset
1927 g_free( contact->avatarId );
4fb9e95a7c4f * extended the profile information shown for pending invites
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31711
diff changeset
1928 contact->avatarId = strdup( avatarId );
4fb9e95a7c4f * extended the profile information shown for pending invites
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31711
diff changeset
1929 }
4fb9e95a7c4f * extended the profile information shown for pending invites
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31711
diff changeset
1930 else {
4fb9e95a7c4f * extended the profile information shown for pending invites
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31711
diff changeset
1931 /* display what we have */
4fb9e95a7c4f * extended the profile information shown for pending invites
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31711
diff changeset
1932 contact->avatarId = NULL;
4fb9e95a7c4f * extended the profile information shown for pending invites
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31711
diff changeset
1933 mxit_show_profile( session, mxitId, profile );
4fb9e95a7c4f * extended the profile information shown for pending invites
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31711
diff changeset
1934 }
4fb9e95a7c4f * extended the profile information shown for pending invites
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31711
diff changeset
1935 }
4fb9e95a7c4f * extended the profile information shown for pending invites
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31711
diff changeset
1936 else {
4fb9e95a7c4f * extended the profile information shown for pending invites
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31711
diff changeset
1937 /* this is a contact */
4fb9e95a7c4f * extended the profile information shown for pending invites
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31711
diff changeset
1938 if ( avatarId )
4fb9e95a7c4f * extended the profile information shown for pending invites
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31711
diff changeset
1939 mxit_update_buddy_avatar( session, mxitId, avatarId );
31835
ba0a391c3911 * show a contact's status message when his offline (with get-info)
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31722
diff changeset
1940
ba0a391c3911 * show a contact's status message when his offline (with get-info)
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31722
diff changeset
1941 if ( ( statusMsg ) && ( strlen( statusMsg ) > 0 ) ) {
ba0a391c3911 * show a contact's status message when his offline (with get-info)
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31722
diff changeset
1942 /* update the status message */
ba0a391c3911 * show a contact's status message when his offline (with get-info)
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31722
diff changeset
1943 PurpleBuddy* buddy = NULL;
ba0a391c3911 * show a contact's status message when his offline (with get-info)
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31722
diff changeset
1944
ba0a391c3911 * show a contact's status message when his offline (with get-info)
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31722
diff changeset
1945 buddy = purple_find_buddy( session->acc, mxitId );
ba0a391c3911 * show a contact's status message when his offline (with get-info)
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31722
diff changeset
1946 if ( buddy ) {
ba0a391c3911 * show a contact's status message when his offline (with get-info)
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31722
diff changeset
1947 contact = purple_buddy_get_protocol_data( buddy );
ba0a391c3911 * show a contact's status message when his offline (with get-info)
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31722
diff changeset
1948 if ( contact ) {
ba0a391c3911 * show a contact's status message when his offline (with get-info)
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31722
diff changeset
1949 if ( contact->statusMsg )
ba0a391c3911 * show a contact's status message when his offline (with get-info)
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31722
diff changeset
1950 g_free( contact->statusMsg );
ba0a391c3911 * show a contact's status message when his offline (with get-info)
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31722
diff changeset
1951 contact->statusMsg = strdup( statusMsg );
ba0a391c3911 * show a contact's status message when his offline (with get-info)
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31722
diff changeset
1952 }
ba0a391c3911 * show a contact's status message when his offline (with get-info)
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31722
diff changeset
1953 }
ba0a391c3911 * show a contact's status message when his offline (with get-info)
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31722
diff changeset
1954 }
ba0a391c3911 * show a contact's status message when his offline (with get-info)
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31722
diff changeset
1955
ba0a391c3911 * show a contact's status message when his offline (with get-info)
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31722
diff changeset
1956 /* show the profile */
31714
4fb9e95a7c4f * extended the profile information shown for pending invites
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31711
diff changeset
1957 mxit_show_profile( session, mxitId, profile );
4fb9e95a7c4f * extended the profile information shown for pending invites
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31711
diff changeset
1958 g_free( profile );
4fb9e95a7c4f * extended the profile information shown for pending invites
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31711
diff changeset
1959 }
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1960 }
31841
b106342b765f When retrieving the users current Status-Message via profile packets,
Andrew Victor <andrew.victor@mxit.com>
parents: 31835
diff changeset
1961
b106342b765f When retrieving the users current Status-Message via profile packets,
Andrew Victor <andrew.victor@mxit.com>
parents: 31835
diff changeset
1962 g_free( statusMsg );
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1963 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1964
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1965
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1966 /*------------------------------------------------------------------------
31707
a5adda59bea4 Searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31706
diff changeset
1967 * Process a received suggest-contacts packet.
a5adda59bea4 Searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31706
diff changeset
1968 *
a5adda59bea4 Searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31706
diff changeset
1969 * @param session The MXit session object
a5adda59bea4 Searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31706
diff changeset
1970 * @param records The packet's data records
a5adda59bea4 Searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31706
diff changeset
1971 * @param rcount The number of data records
a5adda59bea4 Searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31706
diff changeset
1972 */
a5adda59bea4 Searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31706
diff changeset
1973 static void mxit_parse_cmd_suggestcontacts( struct MXitSession* session, struct record** records, int rcount )
a5adda59bea4 Searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31706
diff changeset
1974 {
31711
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
1975 GList* entries = NULL;
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
1976 int searchType;
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
1977 int maxResults;
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
1978 int count;
31707
a5adda59bea4 Searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31706
diff changeset
1979 int i;
a5adda59bea4 Searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31706
diff changeset
1980
a5adda59bea4 Searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31706
diff changeset
1981 /*
a5adda59bea4 Searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31706
diff changeset
1982 * searchType \1 numSuggestions \1 total \1 numAttributes \1 name0 \1 name1 \1 ... \1 nameN \0
a5adda59bea4 Searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31706
diff changeset
1983 * userid \1 contactType \1 value0 \1 value1 ... valueN \0
a5adda59bea4 Searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31706
diff changeset
1984 * ...
a5adda59bea4 Searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31706
diff changeset
1985 * userid \1 contactType \1 value0 \1 value1 ... valueN
a5adda59bea4 Searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31706
diff changeset
1986 */
a5adda59bea4 Searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31706
diff changeset
1987
31711
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
1988 /* the type of results */
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
1989 searchType = atoi( records[0]->fields[0]->data );
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
1990
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
1991 /* the maximum number of results */
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
1992 maxResults = atoi( records[0]->fields[2]->data );
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
1993
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
1994 /* set the count for attributes */
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
1995 count = atoi( records[0]->fields[3]->data );
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
1996
31707
a5adda59bea4 Searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31706
diff changeset
1997 for ( i = 1; i < rcount; i ++ ) {
a5adda59bea4 Searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31706
diff changeset
1998 struct record* rec = records[i];
a5adda59bea4 Searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31706
diff changeset
1999 struct MXitProfile* profile = g_new0( struct MXitProfile, 1 );
31711
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
2000 int j;
31707
a5adda59bea4 Searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31706
diff changeset
2001
a5adda59bea4 Searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31706
diff changeset
2002 g_strlcpy( profile->userid, rec->fields[0]->data, sizeof( profile->userid ) );
31711
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
2003 // TODO: ContactType - User or Service
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
2004
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
2005 for ( j = 0; j < count; j++ ) {
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
2006 char* fname;
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
2007 char* fvalue = "";
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
2008
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
2009 fname = records[0]->fields[4 + j]->data; /* field name */
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
2010 if ( records[i]->fcount > ( 2 + j ) )
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
2011 fvalue = records[i]->fields[2 + j]->data; /* field value */
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
2012
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
2013 purple_debug_info( MXIT_PLUGIN_ID, " %s: field='%s' value='%s'\n", profile->userid, fname, fvalue );
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
2014
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
2015 if ( strcmp( CP_PROFILE_BIRTHDATE, fname ) == 0 ) {
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
2016 /* birthdate */
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
2017 g_strlcpy( profile->birthday, fvalue, sizeof( profile->birthday ) );
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
2018 }
31843
407e4bcd243b Also show FirstName and LastName in search-results and friend-suggestions.
Andrew Victor <andrew.victor@mxit.com>
parents: 31841
diff changeset
2019 else if ( strcmp( CP_PROFILE_FIRSTNAME, fname ) == 0 ) {
407e4bcd243b Also show FirstName and LastName in search-results and friend-suggestions.
Andrew Victor <andrew.victor@mxit.com>
parents: 31841
diff changeset
2020 /* first name */
407e4bcd243b Also show FirstName and LastName in search-results and friend-suggestions.
Andrew Victor <andrew.victor@mxit.com>
parents: 31841
diff changeset
2021 g_strlcpy( profile->firstname, fvalue, sizeof( profile->firstname ) );
407e4bcd243b Also show FirstName and LastName in search-results and friend-suggestions.
Andrew Victor <andrew.victor@mxit.com>
parents: 31841
diff changeset
2022 }
407e4bcd243b Also show FirstName and LastName in search-results and friend-suggestions.
Andrew Victor <andrew.victor@mxit.com>
parents: 31841
diff changeset
2023 else if ( strcmp( CP_PROFILE_LASTNAME, fname ) == 0 ) {
407e4bcd243b Also show FirstName and LastName in search-results and friend-suggestions.
Andrew Victor <andrew.victor@mxit.com>
parents: 31841
diff changeset
2024 /* last name */
407e4bcd243b Also show FirstName and LastName in search-results and friend-suggestions.
Andrew Victor <andrew.victor@mxit.com>
parents: 31841
diff changeset
2025 g_strlcpy( profile->lastname, fvalue, sizeof( profile->lastname ) );
407e4bcd243b Also show FirstName and LastName in search-results and friend-suggestions.
Andrew Victor <andrew.victor@mxit.com>
parents: 31841
diff changeset
2026 }
31711
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
2027 else if ( strcmp( CP_PROFILE_GENDER, fname ) == 0 ) {
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
2028 /* gender */
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
2029 profile->male = ( fvalue[0] == '1' );
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
2030 }
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
2031 else if ( strcmp( CP_PROFILE_FULLNAME, fname ) == 0 ) {
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
2032 /* nickname */
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
2033 g_strlcpy( profile->nickname, fvalue, sizeof( profile->nickname ) );
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
2034 }
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
2035 else if ( strcmp( CP_PROFILE_WHEREAMI, fname ) == 0 ) {
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
2036 /* where am I */
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
2037 g_strlcpy( profile->whereami, fvalue, sizeof( profile->whereami ) );
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
2038 }
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
2039 /* ignore other attibutes */
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
2040 }
31707
a5adda59bea4 Searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31706
diff changeset
2041
a5adda59bea4 Searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31706
diff changeset
2042 entries = g_list_append( entries, profile );
a5adda59bea4 Searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31706
diff changeset
2043 }
a5adda59bea4 Searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31706
diff changeset
2044
a5adda59bea4 Searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31706
diff changeset
2045 /* display */
31711
21baa608701d * More enhancements to user-searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31707
diff changeset
2046 mxit_show_search_results( session, searchType, maxResults, entries );
31707
a5adda59bea4 Searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31706
diff changeset
2047
a5adda59bea4 Searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31706
diff changeset
2048 /* cleanup */
a5adda59bea4 Searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31706
diff changeset
2049 g_list_foreach( entries, (GFunc)g_free, NULL );
a5adda59bea4 Searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31706
diff changeset
2050 }
a5adda59bea4 Searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31706
diff changeset
2051
33554
4a87c767a037 MXit: Add support for typing notification.
Andrew Victor <andrew.victor@mxit.com>
parents: 31847
diff changeset
2052 /*------------------------------------------------------------------------
4a87c767a037 MXit: Add support for typing notification.
Andrew Victor <andrew.victor@mxit.com>
parents: 31847
diff changeset
2053 * Process a received message event packet.
4a87c767a037 MXit: Add support for typing notification.
Andrew Victor <andrew.victor@mxit.com>
parents: 31847
diff changeset
2054 *
4a87c767a037 MXit: Add support for typing notification.
Andrew Victor <andrew.victor@mxit.com>
parents: 31847
diff changeset
2055 * @param session The MXit session object
4a87c767a037 MXit: Add support for typing notification.
Andrew Victor <andrew.victor@mxit.com>
parents: 31847
diff changeset
2056 * @param records The packet's data records
4a87c767a037 MXit: Add support for typing notification.
Andrew Victor <andrew.victor@mxit.com>
parents: 31847
diff changeset
2057 * @param rcount The number of data records
4a87c767a037 MXit: Add support for typing notification.
Andrew Victor <andrew.victor@mxit.com>
parents: 31847
diff changeset
2058 */
4a87c767a037 MXit: Add support for typing notification.
Andrew Victor <andrew.victor@mxit.com>
parents: 31847
diff changeset
2059 static void mxit_parse_cmd_msgevent( struct MXitSession* session, struct record** records, int rcount )
4a87c767a037 MXit: Add support for typing notification.
Andrew Victor <andrew.victor@mxit.com>
parents: 31847
diff changeset
2060 {
4a87c767a037 MXit: Add support for typing notification.
Andrew Victor <andrew.victor@mxit.com>
parents: 31847
diff changeset
2061 int event;
4a87c767a037 MXit: Add support for typing notification.
Andrew Victor <andrew.victor@mxit.com>
parents: 31847
diff changeset
2062
4a87c767a037 MXit: Add support for typing notification.
Andrew Victor <andrew.victor@mxit.com>
parents: 31847
diff changeset
2063 /*
33831
d160ede64878 MXit: Whitespace changes for coding-style consistency.
Andrew Victor <andrew.victor@mxit.com>
parents: 33830
diff changeset
2064 * contactAddress \1 dateTime \1 id \1 event
33554
4a87c767a037 MXit: Add support for typing notification.
Andrew Victor <andrew.victor@mxit.com>
parents: 31847
diff changeset
2065 */
4a87c767a037 MXit: Add support for typing notification.
Andrew Victor <andrew.victor@mxit.com>
parents: 31847
diff changeset
2066
4a87c767a037 MXit: Add support for typing notification.
Andrew Victor <andrew.victor@mxit.com>
parents: 31847
diff changeset
2067 /* strip off dummy domain */
4a87c767a037 MXit: Add support for typing notification.
Andrew Victor <andrew.victor@mxit.com>
parents: 31847
diff changeset
2068 mxit_strip_domain( records[0]->fields[0]->data );
4a87c767a037 MXit: Add support for typing notification.
Andrew Victor <andrew.victor@mxit.com>
parents: 31847
diff changeset
2069
4a87c767a037 MXit: Add support for typing notification.
Andrew Victor <andrew.victor@mxit.com>
parents: 31847
diff changeset
2070 event = atoi( records[0]->fields[3]->data );
4a87c767a037 MXit: Add support for typing notification.
Andrew Victor <andrew.victor@mxit.com>
parents: 31847
diff changeset
2071
4a87c767a037 MXit: Add support for typing notification.
Andrew Victor <andrew.victor@mxit.com>
parents: 31847
diff changeset
2072 switch ( event ) {
4a87c767a037 MXit: Add support for typing notification.
Andrew Victor <andrew.victor@mxit.com>
parents: 31847
diff changeset
2073 case CP_MSGEVENT_TYPING : /* user is typing */
4a87c767a037 MXit: Add support for typing notification.
Andrew Victor <andrew.victor@mxit.com>
parents: 31847
diff changeset
2074 case CP_MSGEVENT_ANGRY : /* user is typing angrily */
4a87c767a037 MXit: Add support for typing notification.
Andrew Victor <andrew.victor@mxit.com>
parents: 31847
diff changeset
2075 serv_got_typing( session->con, records[0]->fields[0]->data, 0, PURPLE_TYPING );
4a87c767a037 MXit: Add support for typing notification.
Andrew Victor <andrew.victor@mxit.com>
parents: 31847
diff changeset
2076 break;
4a87c767a037 MXit: Add support for typing notification.
Andrew Victor <andrew.victor@mxit.com>
parents: 31847
diff changeset
2077
4a87c767a037 MXit: Add support for typing notification.
Andrew Victor <andrew.victor@mxit.com>
parents: 31847
diff changeset
2078 case CP_MSGEVENT_STOPPED : /* user has stopped typing */
4a87c767a037 MXit: Add support for typing notification.
Andrew Victor <andrew.victor@mxit.com>
parents: 31847
diff changeset
2079 serv_got_typing_stopped( session->con, records[0]->fields[0]->data );
4a87c767a037 MXit: Add support for typing notification.
Andrew Victor <andrew.victor@mxit.com>
parents: 31847
diff changeset
2080 break;
4a87c767a037 MXit: Add support for typing notification.
Andrew Victor <andrew.victor@mxit.com>
parents: 31847
diff changeset
2081
4a87c767a037 MXit: Add support for typing notification.
Andrew Victor <andrew.victor@mxit.com>
parents: 31847
diff changeset
2082 case CP_MSGEVENT_ERASING : /* user is erasing text */
4a87c767a037 MXit: Add support for typing notification.
Andrew Victor <andrew.victor@mxit.com>
parents: 31847
diff changeset
2083 case CP_MSGEVENT_DELIVERED : /* message was delivered */
4a87c767a037 MXit: Add support for typing notification.
Andrew Victor <andrew.victor@mxit.com>
parents: 31847
diff changeset
2084 case CP_MSGEVENT_DISPLAYED : /* message was viewed */
4a87c767a037 MXit: Add support for typing notification.
Andrew Victor <andrew.victor@mxit.com>
parents: 31847
diff changeset
2085 /* these are currently not supported by libPurple */
4a87c767a037 MXit: Add support for typing notification.
Andrew Victor <andrew.victor@mxit.com>
parents: 31847
diff changeset
2086 break;
4a87c767a037 MXit: Add support for typing notification.
Andrew Victor <andrew.victor@mxit.com>
parents: 31847
diff changeset
2087
4a87c767a037 MXit: Add support for typing notification.
Andrew Victor <andrew.victor@mxit.com>
parents: 31847
diff changeset
2088 default:
4a87c767a037 MXit: Add support for typing notification.
Andrew Victor <andrew.victor@mxit.com>
parents: 31847
diff changeset
2089 purple_debug_error( MXIT_PLUGIN_ID, "Unknown message event received (%i)\n", event );
4a87c767a037 MXit: Add support for typing notification.
Andrew Victor <andrew.victor@mxit.com>
parents: 31847
diff changeset
2090 }
4a87c767a037 MXit: Add support for typing notification.
Andrew Victor <andrew.victor@mxit.com>
parents: 31847
diff changeset
2091 }
4a87c767a037 MXit: Add support for typing notification.
Andrew Victor <andrew.victor@mxit.com>
parents: 31847
diff changeset
2092
31707
a5adda59bea4 Searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31706
diff changeset
2093
a5adda59bea4 Searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31706
diff changeset
2094 /*------------------------------------------------------------------------
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2095 * Return the length of a multimedia chunk
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2096 *
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2097 * @return The actual chunk data length in bytes
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2098 */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2099 static int get_chunk_len( const char* chunkdata )
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2100 {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2101 int* sizeptr;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2102
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2103 sizeptr = (int*) &chunkdata[1]; /* we skip the first byte (type field) */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2104
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2105 return ntohl( *sizeptr );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2106 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2107
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2108
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2109 /*------------------------------------------------------------------------
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2110 * Process a received multimedia packet.
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2111 *
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2112 * @param session The MXit session object
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2113 * @param records The packet's data records
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2114 * @param rcount The number of data records
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2115 */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2116 static void mxit_parse_cmd_media( struct MXitSession* session, struct record** records, int rcount )
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2117 {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2118 char type;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2119 int size;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2120
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2121 type = records[0]->fields[0]->data[0];
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2122 size = get_chunk_len( records[0]->fields[0]->data );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2123
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2124 purple_debug_info( MXIT_PLUGIN_ID, "mxit_parse_cmd_media (%i records) (%i bytes)\n", rcount, size );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2125
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2126 /* supported chunked data types */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2127 switch ( type ) {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2128 case CP_CHUNK_CUSTOM : /* custom resource */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2129 {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2130 struct cr_chunk chunk;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2131
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2132 /* decode the chunked data */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2133 memset( &chunk, 0, sizeof( struct cr_chunk ) );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2134 mxit_chunk_parse_cr( &records[0]->fields[0]->data[sizeof( char ) + sizeof( int )], records[0]->fields[0]->len, &chunk );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2135
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2136 purple_debug_info( MXIT_PLUGIN_ID, "chunk info id=%s handle=%s op=%i\n", chunk.id, chunk.handle, chunk.operation );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2137
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2138 /* this is a splash-screen operation */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2139 if ( strcmp( chunk.handle, HANDLE_SPLASH2 ) == 0 ) {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2140 if ( chunk.operation == CR_OP_UPDATE ) { /* update the splash-screen */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2141 struct splash_chunk *splash = chunk.resources->data; // TODO: Fix - assuming 1st resource is splash
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2142 gboolean clickable = ( g_list_length( chunk.resources ) > 1 ); // TODO: Fix - if 2 resources, then is clickable
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2143
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2144 if ( splash != NULL )
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2145 splash_update( session, chunk.id, splash->data, splash->datalen, clickable );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2146 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2147 else if ( chunk.operation == CR_OP_REMOVE ) /* remove the splash-screen */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2148 splash_remove( session );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2149 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2150
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2151 /* cleanup custom resources */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2152 g_list_foreach( chunk.resources, (GFunc)g_free, NULL );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2153
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2154 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2155 break;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2156
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2157 case CP_CHUNK_OFFER : /* file offer */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2158 {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2159 struct offerfile_chunk chunk;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2160
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2161 /* decode the chunked data */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2162 memset( &chunk, 0, sizeof( struct offerfile_chunk ) );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2163 mxit_chunk_parse_offer( &records[0]->fields[0]->data[sizeof( char ) + sizeof( int )], records[0]->fields[0]->len, &chunk );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2164
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2165 /* process the offer */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2166 mxit_xfer_rx_offer( session, chunk.username, chunk.filename, chunk.filesize, chunk.fileid );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2167 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2168 break;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2169
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2170 case CP_CHUNK_GET : /* get file response */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2171 {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2172 struct getfile_chunk chunk;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2173
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2174 /* decode the chunked data */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2175 memset( &chunk, 0, sizeof( struct getfile_chunk ) );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2176 mxit_chunk_parse_get( &records[0]->fields[0]->data[sizeof( char ) + sizeof( int )], records[0]->fields[0]->len, &chunk );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2177
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2178 /* process the getfile */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2179 mxit_xfer_rx_file( session, chunk.fileid, chunk.data, chunk.length );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2180 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2181 break;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2182
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2183 case CP_CHUNK_GET_AVATAR : /* get avatars */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2184 {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2185 struct getavatar_chunk chunk;
31714
4fb9e95a7c4f * extended the profile information shown for pending invites
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31711
diff changeset
2186 struct contact* contact = NULL;
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2187
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2188 /* decode the chunked data */
31722
9e4e8315893d * Handle response to SendFile chunk packet, and display the error message
Andrew Victor <andrew.victor@mxit.com>
parents: 31720
diff changeset
2189 memset( &chunk, 0, sizeof( struct getavatar_chunk ) );
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2190 mxit_chunk_parse_get_avatar( &records[0]->fields[0]->data[sizeof( char ) + sizeof( int )], records[0]->fields[0]->len, &chunk );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2191
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2192 /* update avatar image */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2193 if ( chunk.data ) {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2194 purple_debug_info( MXIT_PLUGIN_ID, "updating avatar for contact '%s'\n", chunk.mxitid );
31714
4fb9e95a7c4f * extended the profile information shown for pending invites
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31711
diff changeset
2195
4fb9e95a7c4f * extended the profile information shown for pending invites
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31711
diff changeset
2196 contact = get_mxit_invite_contact( session, chunk.mxitid );
4fb9e95a7c4f * extended the profile information shown for pending invites
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31711
diff changeset
2197 if ( contact ) {
4fb9e95a7c4f * extended the profile information shown for pending invites
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31711
diff changeset
2198 /* this is an invite (add image to the internal image store) */
33616
18f065e935eb MXit: A copy of the data needs to be made here before handing it over to purple_imgstore_add_with_id().
Andrew Victor <andrew.victor@mxit.com>
parents: 33611
diff changeset
2199 contact->imgid = purple_imgstore_add_with_id( g_memdup( chunk.data, chunk.length ), chunk.length, NULL );
31835
ba0a391c3911 * show a contact's status message when his offline (with get-info)
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31722
diff changeset
2200 /* show the profile */
31714
4fb9e95a7c4f * extended the profile information shown for pending invites
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31711
diff changeset
2201 mxit_show_profile( session, chunk.mxitid, contact->profile );
4fb9e95a7c4f * extended the profile information shown for pending invites
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31711
diff changeset
2202 }
4fb9e95a7c4f * extended the profile information shown for pending invites
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31711
diff changeset
2203 else {
4fb9e95a7c4f * extended the profile information shown for pending invites
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31711
diff changeset
2204 /* this is a contact's avatar, so update it */
33831
d160ede64878 MXit: Whitespace changes for coding-style consistency.
Andrew Victor <andrew.victor@mxit.com>
parents: 33830
diff changeset
2205 purple_buddy_icons_set_for_user( session->acc, chunk.mxitid, g_memdup( chunk.data, chunk.length ), chunk.length, chunk.avatarid );
31714
4fb9e95a7c4f * extended the profile information shown for pending invites
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31711
diff changeset
2206 }
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2207 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2208 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2209 break;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2210
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2211 case CP_CHUNK_SET_AVATAR :
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2212 /* this is a reply packet to a set avatar request. no action is required */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2213 break;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2214
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2215 case CP_CHUNK_DIRECT_SND :
31722
9e4e8315893d * Handle response to SendFile chunk packet, and display the error message
Andrew Victor <andrew.victor@mxit.com>
parents: 31720
diff changeset
2216 /* this is a ack for a file send. */
9e4e8315893d * Handle response to SendFile chunk packet, and display the error message
Andrew Victor <andrew.victor@mxit.com>
parents: 31720
diff changeset
2217 {
9e4e8315893d * Handle response to SendFile chunk packet, and display the error message
Andrew Victor <andrew.victor@mxit.com>
parents: 31720
diff changeset
2218 struct sendfile_chunk chunk;
9e4e8315893d * Handle response to SendFile chunk packet, and display the error message
Andrew Victor <andrew.victor@mxit.com>
parents: 31720
diff changeset
2219
9e4e8315893d * Handle response to SendFile chunk packet, and display the error message
Andrew Victor <andrew.victor@mxit.com>
parents: 31720
diff changeset
2220 memset( &chunk, 0, sizeof( struct sendfile_chunk ) );
9e4e8315893d * Handle response to SendFile chunk packet, and display the error message
Andrew Victor <andrew.victor@mxit.com>
parents: 31720
diff changeset
2221 mxit_chunk_parse_sendfile( &records[0]->fields[0]->data[sizeof( char ) + sizeof( int )], records[0]->fields[0]->len, &chunk );
9e4e8315893d * Handle response to SendFile chunk packet, and display the error message
Andrew Victor <andrew.victor@mxit.com>
parents: 31720
diff changeset
2222
9e4e8315893d * Handle response to SendFile chunk packet, and display the error message
Andrew Victor <andrew.victor@mxit.com>
parents: 31720
diff changeset
2223 purple_debug_info( MXIT_PLUGIN_ID, "file-send send to '%s' [status=%i message='%s']\n", chunk.username, chunk.status, chunk.statusmsg );
9e4e8315893d * Handle response to SendFile chunk packet, and display the error message
Andrew Victor <andrew.victor@mxit.com>
parents: 31720
diff changeset
2224
9e4e8315893d * Handle response to SendFile chunk packet, and display the error message
Andrew Victor <andrew.victor@mxit.com>
parents: 31720
diff changeset
2225 if ( chunk.status != 0 ) /* not success */
9e4e8315893d * Handle response to SendFile chunk packet, and display the error message
Andrew Victor <andrew.victor@mxit.com>
parents: 31720
diff changeset
2226 mxit_popup( PURPLE_NOTIFY_MSG_ERROR, _( "File Send Failed" ), chunk.statusmsg );
9e4e8315893d * Handle response to SendFile chunk packet, and display the error message
Andrew Victor <andrew.victor@mxit.com>
parents: 31720
diff changeset
2227 }
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2228 break;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2229
30270
8380aae8b132 I before E, except after C
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 30203
diff changeset
2230 case CP_CHUNK_RECEIVED :
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2231 /* this is a ack for a file received. no action is required */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2232 break;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2233
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2234 default :
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2235 purple_debug_error( MXIT_PLUGIN_ID, "Unsupported chunked data packet type received (%i)\n", type );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2236 break;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2237 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2238 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2239
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2240
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2241 /*------------------------------------------------------------------------
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2242 * Handle a redirect sent from the MXit server.
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2243 *
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2244 * @param session The MXit session object
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2245 * @param url The redirect information
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2246 */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2247 static void mxit_perform_redirect( struct MXitSession* session, const char* url )
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2248 {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2249 gchar** parts;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2250 gchar** host;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2251 int type;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2252
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2253 purple_debug_info( MXIT_PLUGIN_ID, "mxit_perform_redirect: %s\n", url );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2254
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2255 /* tokenize the URL string */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2256 parts = g_strsplit( url, ";", 0 );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2257
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2258 /* Part 1: protocol://host:port */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2259 host = g_strsplit( parts[0], ":", 4 );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2260 if ( strcmp( host[0], "socket" ) == 0 ) {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2261 /* redirect to a MXit socket proxy */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2262 g_strlcpy( session->server, &host[1][2], sizeof( session->server ) );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2263 session->port = atoi( host[2] );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2264 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2265 else {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2266 purple_connection_error( session->con, _( "Cannot perform redirect using the specified protocol" ) );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2267 goto redirect_fail;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2268 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2269
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2270 /* Part 2: type of redirect */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2271 type = atoi( parts[1] );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2272 if ( type == CP_REDIRECT_PERMANENT ) {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2273 /* permanent redirect, so save new MXit server and port */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2274 purple_account_set_string( session->acc, MXIT_CONFIG_SERVER_ADDR, session->server );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2275 purple_account_set_int( session->acc, MXIT_CONFIG_SERVER_PORT, session->port );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2276 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2277
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2278 /* Part 3: message (optional) */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2279 if ( parts[2] != NULL )
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2280 purple_connection_notice( session->con, parts[2] );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2281
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2282 purple_debug_info( MXIT_PLUGIN_ID, "mxit_perform_redirect: %s redirect to %s:%i\n",
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2283 ( type == CP_REDIRECT_PERMANENT ) ? "Permanent" : "Temporary", session->server, session->port );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2284
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2285 /* perform the re-connect to the new MXit server */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2286 mxit_reconnect( session );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2287
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2288 redirect_fail:
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2289 g_strfreev( parts );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2290 g_strfreev( host );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2291 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2292
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2293
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2294 /*------------------------------------------------------------------------
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2295 * Process a success response received from the MXit server.
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2296 *
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2297 * @param session The MXit session object
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2298 * @param packet The received packet
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2299 */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2300 static int process_success_response( struct MXitSession* session, struct rx_packet* packet )
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2301 {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2302 /* ignore ping/poll packets */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2303 if ( ( packet->cmd != CP_CMD_PING ) && ( packet->cmd != CP_CMD_POLL ) )
31501
4a96cf0f177a * do not send requests too fast to the mxit server or they will start ignoring you.
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31499
diff changeset
2304 session->last_rx = mxit_now_milli();
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2305
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2306 /*
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2307 * when we pass the packet records to the next level for parsing
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2308 * we minus 3 records because 1) the first record is the packet
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2309 * type 2) packet reply status 3) the last record is bogus
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2310 */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2311
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2312 /* packet command */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2313 switch ( packet->cmd ) {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2314
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2315 case CP_CMD_REGISTER :
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2316 /* fall through, when registeration successful, MXit will auto login */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2317 case CP_CMD_LOGIN :
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2318 /* login response */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2319 if ( !( session->flags & MXIT_FLAG_LOGGEDIN ) ) {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2320 mxit_parse_cmd_login( session, &packet->records[2], packet->rcount - 3 );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2321 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2322 break;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2323
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2324 case CP_CMD_LOGOUT :
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2325 /* logout response */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2326 session->flags &= ~MXIT_FLAG_LOGGEDIN;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2327 purple_account_disconnect( session->acc );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2328
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2329 /* note:
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2330 * we do not prompt the user here for a reconnect, because this could be the user
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2331 * logging in with his phone. so we just disconnect the account otherwise
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2332 * mxit will start to bounce between the phone and pidgin. also could be a valid
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2333 * disconnect selected by the user.
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2334 */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2335 return -1;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2336
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2337 case CP_CMD_CONTACT :
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2338 /* contact update */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2339 mxit_parse_cmd_contact( session, &packet->records[2], packet->rcount - 3 );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2340 break;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2341
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2342 case CP_CMD_PRESENCE :
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2343 /* presence update */
33831
d160ede64878 MXit: Whitespace changes for coding-style consistency.
Andrew Victor <andrew.victor@mxit.com>
parents: 33830
diff changeset
2344 mxit_parse_cmd_presence( session, &packet->records[2], packet->rcount - 3 );
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2345 break;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2346
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2347 case CP_CMD_RX_MSG :
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2348 /* incoming message (no bogus record) */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2349 mxit_parse_cmd_message( session, &packet->records[2], packet->rcount - 2 );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2350 break;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2351
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2352 case CP_CMD_NEW_SUB :
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2353 /* new subscription request */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2354 mxit_parse_cmd_new_sub( session, &packet->records[2], packet->rcount - 3 );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2355 break;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2356
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2357 case CP_CMD_MEDIA :
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2358 /* multi-media message */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2359 mxit_parse_cmd_media( session, &packet->records[2], packet->rcount - 2 );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2360 break;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2361
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2362 case CP_CMD_EXTPROFILE_GET :
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2363 /* profile update */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2364 mxit_parse_cmd_extprofile( session, &packet->records[2], packet->rcount - 2 );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2365 break;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2366
31707
a5adda59bea4 Searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31706
diff changeset
2367 case CP_CMD_SUGGESTCONTACTS :
a5adda59bea4 Searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31706
diff changeset
2368 /* suggest contacts */
a5adda59bea4 Searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31706
diff changeset
2369 mxit_parse_cmd_suggestcontacts( session, &packet->records[2], packet->rcount - 2 );
a5adda59bea4 Searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31706
diff changeset
2370 break;
a5adda59bea4 Searching.
Andrew Victor <andrew.victor@mxit.com>
parents: 31706
diff changeset
2371
33554
4a87c767a037 MXit: Add support for typing notification.
Andrew Victor <andrew.victor@mxit.com>
parents: 31847
diff changeset
2372 case CP_CMD_GOT_MSGEVENT :
4a87c767a037 MXit: Add support for typing notification.
Andrew Victor <andrew.victor@mxit.com>
parents: 31847
diff changeset
2373 /* received message event */
4a87c767a037 MXit: Add support for typing notification.
Andrew Victor <andrew.victor@mxit.com>
parents: 31847
diff changeset
2374 mxit_parse_cmd_msgevent( session, &packet->records[2], packet->rcount - 2 );
4a87c767a037 MXit: Add support for typing notification.
Andrew Victor <andrew.victor@mxit.com>
parents: 31847
diff changeset
2375 break;
4a87c767a037 MXit: Add support for typing notification.
Andrew Victor <andrew.victor@mxit.com>
parents: 31847
diff changeset
2376
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2377 case CP_CMD_MOOD :
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2378 /* mood update */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2379 case CP_CMD_UPDATE :
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2380 /* update contact information */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2381 case CP_CMD_ALLOW :
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2382 /* allow subscription ack */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2383 case CP_CMD_DENY :
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2384 /* deny subscription ack */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2385 case CP_CMD_INVITE :
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2386 /* invite contact ack */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2387 case CP_CMD_REMOVE :
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2388 /* remove contact ack */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2389 case CP_CMD_TX_MSG :
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2390 /* outgoing message ack */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2391 case CP_CMD_STATUS :
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2392 /* presence update ack */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2393 case CP_CMD_GRPCHAT_CREATE :
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2394 /* create groupchat */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2395 case CP_CMD_GRPCHAT_INVITE :
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2396 /* groupchat invite */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2397 case CP_CMD_PING :
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2398 /* ping reply */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2399 case CP_CMD_POLL :
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2400 /* HTTP poll reply */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2401 case CP_CMD_EXTPROFILE_SET :
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2402 /* profile update */
31722
9e4e8315893d * Handle response to SendFile chunk packet, and display the error message
Andrew Victor <andrew.victor@mxit.com>
parents: 31720
diff changeset
2403 // TODO: Protocol 6.2 indicates status for each attribute, and current value.
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2404 case CP_CMD_SPLASHCLICK :
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2405 /* splash-screen clickthrough */
30203
05aeaba91b78 Add support for message delivery notification.
Andrew Victor <andrew.victor@mxit.com>
parents: 30167
diff changeset
2406 case CP_CMD_MSGEVENT :
05aeaba91b78 Add support for message delivery notification.
Andrew Victor <andrew.victor@mxit.com>
parents: 30167
diff changeset
2407 /* event message */
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2408 break;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2409
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2410 default :
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2411 /* unknown packet */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2412 purple_debug_error( MXIT_PLUGIN_ID, "Received unknown client packet (cmd = %i)\n", packet->cmd );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2413 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2414
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2415 return 0;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2416 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2417
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2418
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2419 /*------------------------------------------------------------------------
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2420 * Process an error response received from the MXit server.
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2421 *
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2422 * @param session The MXit session object
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2423 * @param packet The received packet
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2424 */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2425 static int process_error_response( struct MXitSession* session, struct rx_packet* packet )
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2426 {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2427 char errmsg[256];
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2428 const char* errdesc;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2429
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2430 /* set the error description to be shown to the user */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2431 if ( packet->errmsg )
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2432 errdesc = packet->errmsg;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2433 else
28945
f94c51ec07d9 Mark a bunch of mxit strings for translation
Mark Doliner <markdoliner@pidgin.im>
parents: 28942
diff changeset
2434 errdesc = _( "An internal MXit server error occurred." );
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2435
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2436 purple_debug_info( MXIT_PLUGIN_ID, "Error Reply %i:%s\n", packet->errcode, errdesc );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2437
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2438 if ( packet->errcode == MXIT_ERRCODE_LOGGEDOUT ) {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2439 /* we are not currently logged in, so we need to reconnect */
28942
019308021114 I think errdesc was meant to be used here, not errmsg. errmsg isn't
Mark Doliner <markdoliner@pidgin.im>
parents: 28841
diff changeset
2440 purple_connection_error( session->con, _( errdesc ) );
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2441 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2442
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2443 /* packet command */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2444 switch ( packet->cmd ) {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2445
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2446 case CP_CMD_REGISTER :
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2447 case CP_CMD_LOGIN :
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2448 if ( packet->errcode == MXIT_ERRCODE_REDIRECT ) {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2449 mxit_perform_redirect( session, packet->errmsg );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2450 return 0;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2451 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2452 else {
33821
062af32ae5b7 It is safer to use g_snprintf() for text strings.
Andrew Victor <andrew.victor@mxit.com>
parents: 33820
diff changeset
2453 g_snprintf( errmsg, sizeof( errmsg ), _( "Login error: %s (%i)" ), errdesc, packet->errcode );
28957
72b74fb2c159 A few other minor little translation-related fixes
Mark Doliner <markdoliner@pidgin.im>
parents: 28945
diff changeset
2454 purple_connection_error( session->con, errmsg );
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2455 return -1;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2456 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2457 case CP_CMD_LOGOUT :
33821
062af32ae5b7 It is safer to use g_snprintf() for text strings.
Andrew Victor <andrew.victor@mxit.com>
parents: 33820
diff changeset
2458 g_snprintf( errmsg, sizeof( errmsg ), _( "Logout error: %s (%i)" ), errdesc, packet->errcode );
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2459 purple_connection_error_reason( session->con, PURPLE_CONNECTION_ERROR_NAME_IN_USE, _( errmsg ) );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2460 return -1;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2461 case CP_CMD_CONTACT :
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2462 mxit_popup( PURPLE_NOTIFY_MSG_WARNING, _( "Contact Error" ), _( errdesc ) );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2463 break;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2464 case CP_CMD_RX_MSG :
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2465 mxit_popup( PURPLE_NOTIFY_MSG_WARNING, _( "Message Error" ), _( errdesc ) );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2466 break;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2467 case CP_CMD_TX_MSG :
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2468 mxit_popup( PURPLE_NOTIFY_MSG_WARNING, _( "Message Sending Error" ), _( errdesc ) );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2469 break;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2470 case CP_CMD_STATUS :
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2471 mxit_popup( PURPLE_NOTIFY_MSG_WARNING, _( "Status Error" ), _( errdesc ) );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2472 break;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2473 case CP_CMD_MOOD :
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2474 mxit_popup( PURPLE_NOTIFY_MSG_WARNING, _( "Mood Error" ), _( errdesc ) );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2475 break;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2476 case CP_CMD_KICK :
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2477 /*
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2478 * the MXit server sends this packet if we were idle for too long.
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2479 * to stop the server from closing this connection we need to resend
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2480 * the login packet.
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2481 */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2482 mxit_send_login( session );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2483 break;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2484 case CP_CMD_INVITE :
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2485 mxit_popup( PURPLE_NOTIFY_MSG_WARNING, _( "Invitation Error" ), _( errdesc ) );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2486 break;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2487 case CP_CMD_REMOVE :
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2488 mxit_popup( PURPLE_NOTIFY_MSG_WARNING, _( "Contact Removal Error" ), _( errdesc ) );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2489 break;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2490 case CP_CMD_ALLOW :
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2491 case CP_CMD_DENY :
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2492 mxit_popup( PURPLE_NOTIFY_MSG_WARNING, _( "Subscription Error" ), _( errdesc ) );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2493 break;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2494 case CP_CMD_UPDATE :
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2495 mxit_popup( PURPLE_NOTIFY_MSG_WARNING, _( "Contact Update Error" ), _( errdesc ) );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2496 break;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2497 case CP_CMD_MEDIA :
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2498 mxit_popup( PURPLE_NOTIFY_MSG_WARNING, _( "File Transfer Error" ), _( errdesc ) );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2499 break;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2500 case CP_CMD_GRPCHAT_CREATE :
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2501 mxit_popup( PURPLE_NOTIFY_MSG_WARNING, _( "Cannot create MultiMx room" ), _( errdesc ) );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2502 break;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2503 case CP_CMD_GRPCHAT_INVITE :
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2504 mxit_popup( PURPLE_NOTIFY_MSG_WARNING, _( "MultiMx Invitation Error" ), _( errdesc ) );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2505 break;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2506 case CP_CMD_EXTPROFILE_GET :
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2507 case CP_CMD_EXTPROFILE_SET :
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2508 mxit_popup( PURPLE_NOTIFY_MSG_WARNING, _( "Profile Error" ), _( errdesc ) );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2509 break;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2510 case CP_CMD_SPLASHCLICK :
30203
05aeaba91b78 Add support for message delivery notification.
Andrew Victor <andrew.victor@mxit.com>
parents: 30167
diff changeset
2511 case CP_CMD_MSGEVENT :
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2512 /* ignore error */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2513 break;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2514 case CP_CMD_PING :
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2515 case CP_CMD_POLL :
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2516 break;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2517 default :
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2518 mxit_popup( PURPLE_NOTIFY_MSG_ERROR, _( "Error" ), _( errdesc ) );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2519 break;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2520 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2521
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2522 return 0;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2523 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2524
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2525
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2526 /*========================================================================================================================
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2527 * Low-level Packet receive
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2528 */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2529
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2530 #ifdef DEBUG_PROTOCOL
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2531 /*------------------------------------------------------------------------
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2532 * Dump a received packet structure.
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2533 *
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2534 * @param p The received packet
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2535 */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2536 static void dump_packet( struct rx_packet* p )
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2537 {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2538 struct record* r = NULL;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2539 struct field* f = NULL;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2540 int i;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2541 int j;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2542
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2543 purple_debug_info( MXIT_PLUGIN_ID, "PACKET DUMP: (%i records)\n", p->rcount );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2544
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2545 for ( i = 0; i < p->rcount; i++ ) {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2546 r = p->records[i];
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2547 purple_debug_info( MXIT_PLUGIN_ID, "RECORD: (%i fields)\n", r->fcount );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2548
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2549 for ( j = 0; j < r->fcount; j++ ) {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2550 f = r->fields[j];
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2551 purple_debug_info( MXIT_PLUGIN_ID, "\tFIELD: (len=%i) '%s' \n", f->len, f->data );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2552 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2553 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2554 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2555 #endif
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2556
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2557
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2558 /*------------------------------------------------------------------------
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2559 * Free up memory used by a packet structure.
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2560 *
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2561 * @param p The received packet
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2562 */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2563 static void free_rx_packet( struct rx_packet* p )
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2564 {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2565 struct record* r = NULL;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2566 struct field* f = NULL;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2567 int i;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2568 int j;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2569
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2570 for ( i = 0; i < p->rcount; i++ ) {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2571 r = p->records[i];
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2572
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2573 for ( j = 0; j < r->fcount; j++ ) {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2574 g_free( f );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2575 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2576 g_free( r->fields );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2577 g_free( r );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2578 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2579 g_free( p->records );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2580 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2581
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2582
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2583 /*------------------------------------------------------------------------
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2584 * Add a new field to a record.
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2585 *
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2586 * @param r Parent record object
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2587 * @return The newly created field
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2588 */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2589 static struct field* add_field( struct record* r )
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2590 {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2591 struct field* field;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2592
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2593 field = g_new0( struct field, 1 );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2594
31799
bd26fd17a865 mxit/protocols: Use g_realloc, as these are freed with g_free
Paul Aurich <darkrain42@pidgin.im>
parents: 31722
diff changeset
2595 r->fields = g_realloc( r->fields, sizeof( struct field* ) * ( r->fcount + 1 ) );
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2596 r->fields[r->fcount] = field;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2597 r->fcount++;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2598
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2599 return field;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2600 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2601
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2602
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2603 /*------------------------------------------------------------------------
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2604 * Add a new record to a packet.
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2605 *
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2606 * @param p The packet object
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2607 * @return The newly created record
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2608 */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2609 static struct record* add_record( struct rx_packet* p )
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2610 {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2611 struct record* rec;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2612
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2613 rec = g_new0( struct record, 1 );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2614
31799
bd26fd17a865 mxit/protocols: Use g_realloc, as these are freed with g_free
Paul Aurich <darkrain42@pidgin.im>
parents: 31722
diff changeset
2615 p->records = g_realloc( p->records, sizeof( struct record* ) * ( p->rcount + 1 ) );
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2616 p->records[p->rcount] = rec;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2617 p->rcount++;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2618
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2619 return rec;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2620 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2621
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2622
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2623 /*------------------------------------------------------------------------
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2624 * Parse the received byte stream into a proper client protocol packet.
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2625 *
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2626 * @param session The MXit session object
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2627 * @return Success (0) or Failure (!0)
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2628 */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2629 int mxit_parse_packet( struct MXitSession* session )
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2630 {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2631 struct rx_packet packet;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2632 struct record* rec;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2633 struct field* field;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2634 gboolean pbreak;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2635 unsigned int i;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2636 int res = 0;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2637
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2638 #ifdef DEBUG_PROTOCOL
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2639 purple_debug_info( MXIT_PLUGIN_ID, "Received packet (%i bytes)\n", session->rx_i );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2640 dump_bytes( session, session->rx_dbuf, session->rx_i );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2641 #endif
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2642
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2643 i = 0;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2644 while ( i < session->rx_i ) {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2645
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2646 /* create first record and field */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2647 rec = NULL;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2648 field = NULL;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2649 memset( &packet, 0x00, sizeof( struct rx_packet ) );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2650 rec = add_record( &packet );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2651 pbreak = FALSE;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2652
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2653 /* break up the received packet into fields and records for easy parsing */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2654 while ( ( i < session->rx_i ) && ( !pbreak ) ) {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2655
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2656 switch ( session->rx_dbuf[i] ) {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2657 case CP_SOCK_REC_TERM :
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2658 /* new record */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2659 if ( packet.rcount == 1 ) {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2660 /* packet command */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2661 packet.cmd = atoi( packet.records[0]->fields[0]->data );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2662 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2663 else if ( packet.rcount == 2 ) {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2664 /* special case: binary multimedia packets should not be parsed here */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2665 if ( packet.cmd == CP_CMD_MEDIA ) {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2666 /* add the chunked to new record */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2667 rec = add_record( &packet );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2668 field = add_field( rec );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2669 field->data = &session->rx_dbuf[i + 1];
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2670 field->len = session->rx_i - i;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2671 /* now skip the binary data */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2672 res = get_chunk_len( field->data );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2673 /* determine if we have more packets */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2674 if ( res + 6 + i < session->rx_i ) {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2675 /* we have more than one packet in this stream */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2676 i += res + 6;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2677 pbreak = TRUE;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2678 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2679 else {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2680 i = session->rx_i;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2681 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2682 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2683 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2684 else if ( !field ) {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2685 field = add_field( rec );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2686 field->data = &session->rx_dbuf[i];
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2687 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2688 session->rx_dbuf[i] = '\0';
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2689 rec = add_record( &packet );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2690 field = NULL;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2691
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2692 break;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2693 case CP_FLD_TERM :
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2694 /* new field */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2695 session->rx_dbuf[i] = '\0';
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2696 if ( !field ) {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2697 field = add_field( rec );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2698 field->data = &session->rx_dbuf[i];
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2699 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2700 field = NULL;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2701 break;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2702 case CP_PKT_TERM :
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2703 /* packet is done! */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2704 session->rx_dbuf[i] = '\0';
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2705 pbreak = TRUE;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2706 break;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2707 default :
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2708 /* skip non special characters */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2709 if ( !field ) {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2710 field = add_field( rec );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2711 field->data = &session->rx_dbuf[i];
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2712 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2713 field->len++;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2714 break;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2715 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2716
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2717 i++;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2718 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2719
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2720 if ( packet.rcount < 2 ) {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2721 /* bad packet */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2722 purple_connection_error( session->con, _( "Invalid packet received from MXit." ) );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2723 free_rx_packet( &packet );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2724 continue;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2725 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2726
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2727 session->rx_dbuf[session->rx_i] = '\0';
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2728 packet.errcode = atoi( packet.records[1]->fields[0]->data );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2729
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2730 purple_debug_info( MXIT_PLUGIN_ID, "Packet received CMD:%i (%i)\n", packet.cmd, packet.errcode );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2731 #ifdef DEBUG_PROTOCOL
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2732 /* debug */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2733 dump_packet( &packet );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2734 #endif
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2735
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2736 /* reset the out ack */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2737 if ( session->outack == packet.cmd ) {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2738 /* outstanding ack received from mxit server */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2739 session->outack = 0;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2740 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2741
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2742 /* check packet status */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2743 if ( packet.errcode != MXIT_ERRCODE_SUCCESS ) {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2744 /* error reply! */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2745 if ( ( packet.records[1]->fcount > 1 ) && ( packet.records[1]->fields[1]->data ) )
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2746 packet.errmsg = packet.records[1]->fields[1]->data;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2747 else
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2748 packet.errmsg = NULL;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2749
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2750 res = process_error_response( session, &packet );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2751 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2752 else {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2753 /* success reply! */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2754 res = process_success_response( session, &packet );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2755 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2756
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2757 /* free up the packet resources */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2758 free_rx_packet( &packet );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2759 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2760
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2761 if ( session->outack == 0 )
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2762 mxit_manage_queue( session );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2763
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2764 return res;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2765 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2766
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2767
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2768 /*------------------------------------------------------------------------
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2769 * Callback when data is received from the MXit server.
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2770 *
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2771 * @param user_data The MXit session object
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2772 * @param source The file-descriptor on which data was received
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2773 * @param cond Condition which caused the callback (PURPLE_INPUT_READ)
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2774 */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2775 void mxit_cb_rx( gpointer user_data, gint source, PurpleInputCondition cond )
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2776 {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2777 struct MXitSession* session = (struct MXitSession*) user_data;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2778 char ch;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2779 int res;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2780 int len;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2781
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2782 if ( session->rx_state == RX_STATE_RLEN ) {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2783 /* we are reading in the packet length */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2784 len = read( session->fd, &ch, 1 );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2785 if ( len < 0 ) {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2786 /* connection error */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2787 purple_connection_error( session->con, _( "A connection error occurred to MXit. (read stage 0x01)" ) );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2788 return;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2789 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2790 else if ( len == 0 ) {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2791 /* connection closed */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2792 purple_connection_error( session->con, _( "A connection error occurred to MXit. (read stage 0x02)" ) );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2793 return;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2794 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2795 else {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2796 /* byte read */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2797 if ( ch == CP_REC_TERM ) {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2798 /* the end of the length record found */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2799 session->rx_lbuf[session->rx_i] = '\0';
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2800 session->rx_res = atoi( &session->rx_lbuf[3] );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2801 if ( session->rx_res > CP_MAX_PACKET ) {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2802 purple_connection_error( session->con, _( "A connection error occurred to MXit. (read stage 0x03)" ) );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2803 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2804 session->rx_state = RX_STATE_DATA;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2805 session->rx_i = 0;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2806 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2807 else {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2808 /* still part of the packet length record */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2809 session->rx_lbuf[session->rx_i] = ch;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2810 session->rx_i++;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2811 if ( session->rx_i >= sizeof( session->rx_lbuf ) ) {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2812 /* malformed packet length record (too long) */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2813 purple_connection_error( session->con, _( "A connection error occurred to MXit. (read stage 0x04)" ) );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2814 return;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2815 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2816 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2817 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2818 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2819 else if ( session->rx_state == RX_STATE_DATA ) {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2820 /* we are reading in the packet data */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2821 len = read( session->fd, &session->rx_dbuf[session->rx_i], session->rx_res );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2822 if ( len < 0 ) {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2823 /* connection error */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2824 purple_connection_error( session->con, _( "A connection error occurred to MXit. (read stage 0x05)" ) );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2825 return;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2826 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2827 else if ( len == 0 ) {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2828 /* connection closed */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2829 purple_connection_error( session->con, _( "A connection error occurred to MXit. (read stage 0x06)" ) );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2830 return;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2831 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2832 else {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2833 /* data read */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2834 session->rx_i += len;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2835 session->rx_res -= len;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2836
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2837 if ( session->rx_res == 0 ) {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2838 /* ok, so now we have read in the whole packet */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2839 session->rx_state = RX_STATE_PROC;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2840 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2841 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2842 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2843
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2844 if ( session->rx_state == RX_STATE_PROC ) {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2845 /* we have a full packet, which we now need to process */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2846 res = mxit_parse_packet( session );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2847
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2848 if ( res == 0 ) {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2849 /* we are still logged in */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2850 session->rx_state = RX_STATE_RLEN;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2851 session->rx_res = 0;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2852 session->rx_i = 0;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2853 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2854 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2855 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2856
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2857
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2858 /*------------------------------------------------------------------------
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2859 * Log the user off MXit and close the connection
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2860 *
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2861 * @param session The MXit session object
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2862 */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2863 void mxit_close_connection( struct MXitSession* session )
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2864 {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2865 purple_debug_info( MXIT_PLUGIN_ID, "mxit_close_connection\n" );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2866
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2867 if ( !( session->flags & MXIT_FLAG_CONNECTED ) ) {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2868 /* we are already closed */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2869 return;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2870 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2871 else if ( session->flags & MXIT_FLAG_LOGGEDIN ) {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2872 /* we are currently logged in so we need to send a logout packet */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2873 if ( !session->http ) {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2874 mxit_send_logout( session );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2875 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2876 session->flags &= ~MXIT_FLAG_LOGGEDIN;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2877 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2878 session->flags &= ~MXIT_FLAG_CONNECTED;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2879
33815
094a4b10e8d5 Maintain list of outstanding async calls made so that it can be canceled when the account is disconnected.
Pieter Loubser <pieter.loubser@mxit.com>
parents: 33807
diff changeset
2880 /* cancel all outstanding async calls */
094a4b10e8d5 Maintain list of outstanding async calls made so that it can be canceled when the account is disconnected.
Pieter Loubser <pieter.loubser@mxit.com>
parents: 33807
diff changeset
2881 while ( session->async_calls ) {
094a4b10e8d5 Maintain list of outstanding async calls made so that it can be canceled when the account is disconnected.
Pieter Loubser <pieter.loubser@mxit.com>
parents: 33807
diff changeset
2882 purple_util_fetch_url_cancel( session->async_calls->data );
33831
d160ede64878 MXit: Whitespace changes for coding-style consistency.
Andrew Victor <andrew.victor@mxit.com>
parents: 33830
diff changeset
2883 session->async_calls = g_slist_delete_link( session->async_calls, session->async_calls );
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2884 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2885
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2886 /* remove the input cb function */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2887 if ( session->con->inpa ) {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2888 purple_input_remove( session->con->inpa );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2889 session->con->inpa = 0;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2890 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2891
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2892 /* remove HTTP poll timer */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2893 if ( session->http_timer_id > 0 )
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2894 purple_timeout_remove( session->http_timer_id );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2895
31706
a86fb9e2b8d4 * fixed crash caused by entering a wrong password (tx queue management)
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31704
diff changeset
2896 /* remove slow queue manager timer */
a86fb9e2b8d4 * fixed crash caused by entering a wrong password (tx queue management)
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31704
diff changeset
2897 if ( session->q_slow_timer_id > 0 )
a86fb9e2b8d4 * fixed crash caused by entering a wrong password (tx queue management)
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31704
diff changeset
2898 purple_timeout_remove( session->q_slow_timer_id );
a86fb9e2b8d4 * fixed crash caused by entering a wrong password (tx queue management)
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31704
diff changeset
2899
a86fb9e2b8d4 * fixed crash caused by entering a wrong password (tx queue management)
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31704
diff changeset
2900 /* remove fast queue manager timer */
a86fb9e2b8d4 * fixed crash caused by entering a wrong password (tx queue management)
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31704
diff changeset
2901 if ( session->q_fast_timer_id > 0 )
a86fb9e2b8d4 * fixed crash caused by entering a wrong password (tx queue management)
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31704
diff changeset
2902 purple_timeout_remove( session->q_fast_timer_id );
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2903
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2904 /* remove all groupchat rooms */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2905 while ( session->rooms != NULL ) {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2906 struct multimx* multimx = (struct multimx *) session->rooms->data;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2907
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2908 session->rooms = g_list_remove( session->rooms, multimx );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2909
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2910 free( multimx );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2911 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2912 g_list_free( session->rooms );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2913 session->rooms = NULL;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2914
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2915 /* remove all rx chats names */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2916 while ( session->active_chats != NULL ) {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2917 char* chat = (char*) session->active_chats->data;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2918
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2919 session->active_chats = g_list_remove( session->active_chats, chat );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2920
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2921 g_free( chat );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2922 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2923 g_list_free( session->active_chats );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2924 session->active_chats = NULL;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2925
31714
4fb9e95a7c4f * extended the profile information shown for pending invites
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31711
diff changeset
2926 /* clear the internal invites */
4fb9e95a7c4f * extended the profile information shown for pending invites
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31711
diff changeset
2927 while ( session->invites != NULL ) {
4fb9e95a7c4f * extended the profile information shown for pending invites
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31711
diff changeset
2928 struct contact* contact = (struct contact*) session->invites->data;
4fb9e95a7c4f * extended the profile information shown for pending invites
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31711
diff changeset
2929
4fb9e95a7c4f * extended the profile information shown for pending invites
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31711
diff changeset
2930 session->invites = g_list_remove( session->invites, contact );
4fb9e95a7c4f * extended the profile information shown for pending invites
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31711
diff changeset
2931
4fb9e95a7c4f * extended the profile information shown for pending invites
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31711
diff changeset
2932 if ( contact->msg )
4fb9e95a7c4f * extended the profile information shown for pending invites
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31711
diff changeset
2933 g_free( contact->msg );
4fb9e95a7c4f * extended the profile information shown for pending invites
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31711
diff changeset
2934 if ( contact->statusMsg )
4fb9e95a7c4f * extended the profile information shown for pending invites
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31711
diff changeset
2935 g_free( contact->statusMsg );
4fb9e95a7c4f * extended the profile information shown for pending invites
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31711
diff changeset
2936 if ( contact->profile )
4fb9e95a7c4f * extended the profile information shown for pending invites
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31711
diff changeset
2937 g_free( contact->profile );
4fb9e95a7c4f * extended the profile information shown for pending invites
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31711
diff changeset
2938 g_free( contact );
4fb9e95a7c4f * extended the profile information shown for pending invites
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31711
diff changeset
2939 }
4fb9e95a7c4f * extended the profile information shown for pending invites
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31711
diff changeset
2940 g_list_free( session->invites );
4fb9e95a7c4f * extended the profile information shown for pending invites
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31711
diff changeset
2941 session->invites = NULL;
4fb9e95a7c4f * extended the profile information shown for pending invites
Pieter Loubser <pieter.loubser@mxit.com>
parents: 31711
diff changeset
2942
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2943 /* free profile information */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2944 if ( session->profile )
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2945 free( session->profile );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2946
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2947 /* free custom emoticons */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2948 mxit_free_emoticon_cache( session );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2949
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2950 /* free allocated memory */
30371
a307496582ab Implemented new naming conventions
Pieter Loubser <pieter.loubser@mxit.com>
parents: 30369
diff changeset
2951 if ( session->uid )
a307496582ab Implemented new naming conventions
Pieter Loubser <pieter.loubser@mxit.com>
parents: 30369
diff changeset
2952 g_free( session->uid );
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2953 g_free( session->encpwd );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2954 session->encpwd = NULL;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2955
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2956 /* flush all the commands still in the queue */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2957 flush_queue( session );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2958 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2959

mercurial