libpurple/protocols/mxit/chunk.c

Mon, 22 Aug 2016 03:38:13 -0400

author
Elliott Sales de Andrade <qulogic@pidgin.im>
date
Mon, 22 Aug 2016 03:38:13 -0400
branch
meson
changeset 38445
0e98f0dee5bd
parent 37905
848e16508276
permissions
-rw-r--r--

Add facebook to meson build.

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 * -- handle chunked data (multimedia messages) --
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
33844
e8edfd4e26ae MXit: Cleanup the #includes (no purple.h) so that it atleast compiles within InstantBird.
Andrew Victor <andrew.victor@mxit.com>
parents: 31722
diff changeset
26 #include "internal.h"
e8edfd4e26ae MXit: Cleanup the #includes (no purple.h) so that it atleast compiles within InstantBird.
Andrew Victor <andrew.victor@mxit.com>
parents: 31722
diff changeset
27 #include "debug.h"
e8edfd4e26ae MXit: Cleanup the #includes (no purple.h) so that it atleast compiles within InstantBird.
Andrew Victor <andrew.victor@mxit.com>
parents: 31722
diff changeset
28
36542
30f40ecc4631 Renamed mxit's protocol.[ch] to client.[ch]
Ankit Vani <a@nevitus.org>
parents: 33844
diff changeset
29 #include "client.h"
28841
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 "chunk.h"
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
32 #include "filexfer.h"
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
33
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
34
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
35 /*========================================================================================================================
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
36 * Data-Type encoding
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
37 */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
38
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
39 #if 0
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
40 #include <byteswap.h>
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
41 #if (__BYTE_ORDER == __BIG_ENDIAN)
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
42 #define SWAP_64(x) (x)
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
43 #else
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
44 #define SWAP_64(x) bswap_64(x)
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
45 #endif
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
46 #endif
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 /*------------------------------------------------------------------------
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
49 * Encode a single byte in the chunked data.
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
50 *
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
51 * @param chunkdata The chunked-data buffer
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
52 * @param value The byte
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
53 * @return The number of bytes added.
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
54 */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
55 static int add_int8( char* chunkdata, char value )
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
56 {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
57 *chunkdata = value;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
58
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
59 return sizeof( char );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
60 }
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 * Encode a 16-bit value in the chunked data.
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 chunkdata The chunked-data buffer
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
66 * @param value The 16-bit value
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
67 * @return The number of bytes added.
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
68 */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
69 static int add_int16( char* chunkdata, short value )
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
70 {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
71 value = htons( value ); /* network byte-order */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
72 memcpy( chunkdata, &value, sizeof( short ) );
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 return sizeof( short );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
75 }
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 * Encode a 32-bit value in the chunked data.
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 * @param chunkdata The chunked-data buffer
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
81 * @param value The 32-bit value
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
82 * @return The number of bytes added.
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 static int add_int32( char* chunkdata, int value )
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 value = htonl( value ); /* network byte-order */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
87 memcpy( chunkdata, &value, sizeof( int ) );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
88
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
89 return sizeof( int );
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 #if 0
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 * Encode a 64-bit value in the chunked data.
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 chunkdata The chunked-data buffer
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
97 * @param value The 64-bit value
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
98 * @return The number of bytes added.
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
99 */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
100 static int add_int64( char* chunkdata, int64_t value )
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
101 {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
102 value = SWAP_64( value ); /* network byte-order */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
103 memcpy( chunkdata, &value, sizeof( int64_t ) );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
104
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
105 return sizeof( int64_t );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
106 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
107 #endif
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
108
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
109 /*------------------------------------------------------------------------
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
110 * Encode a block of data in the chunked data.
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
111 *
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
112 * @param chunkdata The chunked-data buffer
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
113 * @param data The data to add
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
114 * @param datalen The length of the data to add
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
115 * @return The number of bytes added.
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
116 */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
117 static int add_data( char* chunkdata, const char* data, int datalen )
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 memcpy( chunkdata, data, datalen );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
120
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
121 return datalen;
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 * Encode a string as UTF-8 in the chunked data.
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 chunkdata The chunked-data buffer
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
128 * @param str The string to encode
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
129 * @return The number of bytes in the string
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 static int add_utf8_string( char* chunkdata, const char* str )
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 int pos = 0;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
134 size_t len = strlen( str );
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 /* utf8 string length [2 bytes] */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
137 pos += add_int16( &chunkdata[pos], len );
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 /* utf8 string */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
140 pos += add_data( &chunkdata[pos], str, len );
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 return pos;
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
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 * Data-Type decoding
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 /*------------------------------------------------------------------------
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
151 * Extract a single byte from the chunked data.
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 * @param chunkdata The chunked-data buffer
37833
fe0e01b28407 Fix for TALOS-CAN-0138
Andrew Victor <andrew.victor@mxit.com>
parents: 37826
diff changeset
154 * @param chunklen The amount of data available in the buffer.
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
155 * @param value The byte
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
156 * @return The number of bytes extracted.
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
157 */
37833
fe0e01b28407 Fix for TALOS-CAN-0138
Andrew Victor <andrew.victor@mxit.com>
parents: 37826
diff changeset
158 static int get_int8( const char* chunkdata, size_t chunklen, char* value )
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
159 {
37833
fe0e01b28407 Fix for TALOS-CAN-0138
Andrew Victor <andrew.victor@mxit.com>
parents: 37826
diff changeset
160 if ( chunklen < sizeof( char ) )
fe0e01b28407 Fix for TALOS-CAN-0138
Andrew Victor <andrew.victor@mxit.com>
parents: 37826
diff changeset
161 return 0;
fe0e01b28407 Fix for TALOS-CAN-0138
Andrew Victor <andrew.victor@mxit.com>
parents: 37826
diff changeset
162
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
163 *value = *chunkdata;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
164
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
165 return sizeof( char );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
166 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
167
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
168 /*------------------------------------------------------------------------
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
169 * Extract a 16-bit value from the chunked data.
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 * @param chunkdata The chunked-data buffer
37833
fe0e01b28407 Fix for TALOS-CAN-0138
Andrew Victor <andrew.victor@mxit.com>
parents: 37826
diff changeset
172 * @param chunklen The amount of data available in the buffer.
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
173 * @param value The 16-bit value
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
174 * @return The number of bytes extracted
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
175 */
37833
fe0e01b28407 Fix for TALOS-CAN-0138
Andrew Victor <andrew.victor@mxit.com>
parents: 37826
diff changeset
176 static int get_int16( const char* chunkdata, size_t chunklen, unsigned short* value )
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
177 {
37833
fe0e01b28407 Fix for TALOS-CAN-0138
Andrew Victor <andrew.victor@mxit.com>
parents: 37826
diff changeset
178 if ( chunklen < sizeof( short ) )
fe0e01b28407 Fix for TALOS-CAN-0138
Andrew Victor <andrew.victor@mxit.com>
parents: 37826
diff changeset
179 return 0;
fe0e01b28407 Fix for TALOS-CAN-0138
Andrew Victor <andrew.victor@mxit.com>
parents: 37826
diff changeset
180
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
181 *value = ntohs( *( (const short*) chunkdata ) ); /* host byte-order */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
182
37905
848e16508276 Fixups for mxit
Gary Kramlich <grim@reaperworld.com>
parents: 37901
diff changeset
183 return sizeof( short );
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
184 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
185
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
186 /*------------------------------------------------------------------------
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
187 * Extract a 32-bit value from the chunked data.
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
188 *
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
189 * @param chunkdata The chunked-data buffer
37833
fe0e01b28407 Fix for TALOS-CAN-0138
Andrew Victor <andrew.victor@mxit.com>
parents: 37826
diff changeset
190 * @param chunklen The amount of data available in the buffer.
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
191 * @param value The 32-bit value
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
192 * @return The number of bytes extracted
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
193 */
37833
fe0e01b28407 Fix for TALOS-CAN-0138
Andrew Victor <andrew.victor@mxit.com>
parents: 37826
diff changeset
194 static int get_int32( const char* chunkdata, size_t chunklen, unsigned int* value )
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
195 {
37833
fe0e01b28407 Fix for TALOS-CAN-0138
Andrew Victor <andrew.victor@mxit.com>
parents: 37826
diff changeset
196 if ( chunklen < sizeof( int ) )
fe0e01b28407 Fix for TALOS-CAN-0138
Andrew Victor <andrew.victor@mxit.com>
parents: 37826
diff changeset
197 return 0;
fe0e01b28407 Fix for TALOS-CAN-0138
Andrew Victor <andrew.victor@mxit.com>
parents: 37826
diff changeset
198
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
199 *value = ntohl( *( (const int*) chunkdata ) ); /* host byte-order */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
200
37905
848e16508276 Fixups for mxit
Gary Kramlich <grim@reaperworld.com>
parents: 37901
diff changeset
201 return sizeof( int );
28841
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
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
204 #if 0
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
205 /*------------------------------------------------------------------------
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
206 * Extract a 64-bit value from the chunked data.
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 * @param chunkdata The chunked-data buffer
37833
fe0e01b28407 Fix for TALOS-CAN-0138
Andrew Victor <andrew.victor@mxit.com>
parents: 37826
diff changeset
209 * @param chunklen The amount of data available in the buffer.
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
210 * @param value The 64-bit value
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
211 * @return The number of bytes extracted
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
212 */
37833
fe0e01b28407 Fix for TALOS-CAN-0138
Andrew Victor <andrew.victor@mxit.com>
parents: 37826
diff changeset
213 static int get_int64( const char* chunkdata, size_t chunklen, int64_t* value )
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
214 {
37833
fe0e01b28407 Fix for TALOS-CAN-0138
Andrew Victor <andrew.victor@mxit.com>
parents: 37826
diff changeset
215 if ( chunklen < sizeof( int64_t ) )
fe0e01b28407 Fix for TALOS-CAN-0138
Andrew Victor <andrew.victor@mxit.com>
parents: 37826
diff changeset
216 return 0;
fe0e01b28407 Fix for TALOS-CAN-0138
Andrew Victor <andrew.victor@mxit.com>
parents: 37826
diff changeset
217
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
218 *value = SWAP_64( *( (const int64_t*) chunkdata ) ); /* host byte-order */
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 return sizeof( int64_t );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
221 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
222 #endif
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 * Copy a block of data from the chunked data.
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
226 *
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
227 * @param chunkdata The chunked-data buffer
37833
fe0e01b28407 Fix for TALOS-CAN-0138
Andrew Victor <andrew.victor@mxit.com>
parents: 37826
diff changeset
228 * @param chunklen The amount of data available in the buffer.
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
229 * @param dest Where to store the extract data
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
230 * @param datalen The length of the data to extract
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
231 * @return The number of bytes extracted
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
232 */
37833
fe0e01b28407 Fix for TALOS-CAN-0138
Andrew Victor <andrew.victor@mxit.com>
parents: 37826
diff changeset
233 static int get_data( const char* chunkdata, size_t chunklen, char* dest, size_t datalen )
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
234 {
37833
fe0e01b28407 Fix for TALOS-CAN-0138
Andrew Victor <andrew.victor@mxit.com>
parents: 37826
diff changeset
235 if ( chunklen < datalen )
fe0e01b28407 Fix for TALOS-CAN-0138
Andrew Victor <andrew.victor@mxit.com>
parents: 37826
diff changeset
236 return 0;
fe0e01b28407 Fix for TALOS-CAN-0138
Andrew Victor <andrew.victor@mxit.com>
parents: 37826
diff changeset
237
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
238 memcpy( dest, chunkdata, datalen );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
239
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
240 return datalen;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
241 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
242
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
243 /*------------------------------------------------------------------------
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
244 * Extract a UTF-8 encoded string from the chunked data.
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 * @param chunkdata The chunked-data buffer
37833
fe0e01b28407 Fix for TALOS-CAN-0138
Andrew Victor <andrew.victor@mxit.com>
parents: 37826
diff changeset
247 * @param chunklen The amount of data available in the buffer.
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
248 * @param str A pointer to extracted string. Must be g_free()'d.
31722
9e4e8315893d * Handle response to SendFile chunk packet, and display the error message
Andrew Victor <andrew.victor@mxit.com>
parents: 31496
diff changeset
249 * @param maxstrlen Maximum size of destination buffer.
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
250 * @return The number of bytes consumed
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
251 */
37833
fe0e01b28407 Fix for TALOS-CAN-0138
Andrew Victor <andrew.victor@mxit.com>
parents: 37826
diff changeset
252 static int get_utf8_string( const char* chunkdata, size_t chunklen, char* str, size_t maxstrlen )
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
253 {
37833
fe0e01b28407 Fix for TALOS-CAN-0138
Andrew Victor <andrew.victor@mxit.com>
parents: 37826
diff changeset
254 size_t pos = 0;
fe0e01b28407 Fix for TALOS-CAN-0138
Andrew Victor <andrew.victor@mxit.com>
parents: 37826
diff changeset
255 unsigned short len = 0;
fe0e01b28407 Fix for TALOS-CAN-0138
Andrew Victor <andrew.victor@mxit.com>
parents: 37826
diff changeset
256 size_t skip = 0;
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
257
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
258 /* string length [2 bytes] */
37833
fe0e01b28407 Fix for TALOS-CAN-0138
Andrew Victor <andrew.victor@mxit.com>
parents: 37826
diff changeset
259 pos += get_int16( &chunkdata[pos], chunklen - pos, &len );
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
260
37833
fe0e01b28407 Fix for TALOS-CAN-0138
Andrew Victor <andrew.victor@mxit.com>
parents: 37826
diff changeset
261 if ( ( len + pos ) > chunklen ) {
fe0e01b28407 Fix for TALOS-CAN-0138
Andrew Victor <andrew.victor@mxit.com>
parents: 37826
diff changeset
262 /* string length is longer than chunk size */
fe0e01b28407 Fix for TALOS-CAN-0138
Andrew Victor <andrew.victor@mxit.com>
parents: 37826
diff changeset
263 return 0;
fe0e01b28407 Fix for TALOS-CAN-0138
Andrew Victor <andrew.victor@mxit.com>
parents: 37826
diff changeset
264 }
fe0e01b28407 Fix for TALOS-CAN-0138
Andrew Victor <andrew.victor@mxit.com>
parents: 37826
diff changeset
265 else if ( len > maxstrlen ) {
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
266 /* possible buffer overflow */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
267 purple_debug_error( MXIT_PLUGIN_ID, "Buffer overflow detected (get_utf8_string)\n" );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
268 skip = len - maxstrlen;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
269 len = maxstrlen;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
270 }
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 /* string data */
37833
fe0e01b28407 Fix for TALOS-CAN-0138
Andrew Victor <andrew.victor@mxit.com>
parents: 37826
diff changeset
273 pos += get_data( &chunkdata[pos], chunklen - pos, str, len );
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
274 str[len] = '\0'; /* terminate string */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
275
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
276 return pos + skip;
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
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
279
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
280 /*========================================================================================================================
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
281 * Chunked Data encoding
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
282 */
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 * Encode a "reject file" chunk. (Chunk type 7)
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 * @param chunkdata Chunked-data buffer
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
288 * @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
289 * @return The number of bytes encoded in the buffer
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
290 */
37822
06278419c703 Fix for TALOS-CAN-0120
Andrew Victor <andrew.victor@mxit.com>
parents: 34457
diff changeset
291 size_t mxit_chunk_create_reject( char* chunkdata, const char* fileid )
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
292 {
37822
06278419c703 Fix for TALOS-CAN-0120
Andrew Victor <andrew.victor@mxit.com>
parents: 34457
diff changeset
293 size_t pos = 0;
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
294
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
295 /* file id [8 bytes] */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
296 pos += add_data( &chunkdata[pos], fileid, MXIT_CHUNK_FILEID_LEN );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
297
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
298 /* rejection reason [1 byte] */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
299 pos += add_int8( &chunkdata[pos], REJECT_BY_USER );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
300
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
301 /* rejection description [UTF-8 (optional)] */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
302 pos += add_utf8_string( &chunkdata[pos], "" );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
303
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
304 return pos;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
305 }
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 /*------------------------------------------------------------------------
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
309 * Encode a "get file" request chunk. (Chunk type 8)
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
310 *
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
311 * @param chunkdata Chunked-data buffer
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
312 * @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
313 * @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
314 * @param offset The start offset in the file
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
315 * @return The number of bytes encoded in the buffer
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
316 */
37822
06278419c703 Fix for TALOS-CAN-0120
Andrew Victor <andrew.victor@mxit.com>
parents: 34457
diff changeset
317 size_t mxit_chunk_create_get( char* chunkdata, const char* fileid, size_t filesize, size_t offset )
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
318 {
37822
06278419c703 Fix for TALOS-CAN-0120
Andrew Victor <andrew.victor@mxit.com>
parents: 34457
diff changeset
319 size_t pos = 0;
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
320
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
321 /* file id [8 bytes] */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
322 pos += add_data( &chunkdata[pos], fileid, MXIT_CHUNK_FILEID_LEN );
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 /* offset [4 bytes] */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
325 pos += add_int32( &chunkdata[pos], offset );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
326
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
327 /* length [4 bytes] */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
328 pos += add_int32( &chunkdata[pos], filesize );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
329
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
330 return pos;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
331 }
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
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 * Encode a "received file" chunk. (Chunk type 9)
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
336 *
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
337 * @param chunkdata Chunked-data buffer
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
338 * @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
339 * @param status The status of the file transfer (see chunk.h)
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
340 * @return The number of bytes encoded in the buffer
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
341 */
37822
06278419c703 Fix for TALOS-CAN-0120
Andrew Victor <andrew.victor@mxit.com>
parents: 34457
diff changeset
342 size_t mxit_chunk_create_received( char* chunkdata, const char* fileid, unsigned char status )
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
343 {
37822
06278419c703 Fix for TALOS-CAN-0120
Andrew Victor <andrew.victor@mxit.com>
parents: 34457
diff changeset
344 size_t pos = 0;
28841
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 /* file id [8 bytes] */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
347 pos += add_data( &chunkdata[pos], fileid, MXIT_CHUNK_FILEID_LEN );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
348
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
349 /* status [1 byte] */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
350 pos += add_int8( &chunkdata[pos], status );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
351
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
352 return pos;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
353 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
354
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
355
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
356 /*------------------------------------------------------------------------
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
357 * Encode a "send file direct" chunk. (Chunk type 10)
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
358 *
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
359 * @param chunkdata Chunked-data buffer
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
360 * @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
361 * @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
362 * @param data The file contents
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
363 * @param datalen The size 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
364 * @return The number of bytes encoded in the buffer
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
365 */
37822
06278419c703 Fix for TALOS-CAN-0120
Andrew Victor <andrew.victor@mxit.com>
parents: 34457
diff changeset
366 size_t mxit_chunk_create_senddirect( char* chunkdata, const char* username, const char* filename, const unsigned char* data, size_t datalen )
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
367 {
37822
06278419c703 Fix for TALOS-CAN-0120
Andrew Victor <andrew.victor@mxit.com>
parents: 34457
diff changeset
368 size_t pos = 0;
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
369 const char* mime = NULL;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
370
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
371 /* data length [4 bytes] */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
372 pos += add_int32( &chunkdata[pos], datalen );
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 /* number of username(s) [2 bytes] */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
375 pos += add_int16( &chunkdata[pos], 1 );
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 /* username(s) [UTF-8] */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
378 pos += add_utf8_string( &chunkdata[pos], username );
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 /* filename [UTF-8] */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
381 pos += add_utf8_string( &chunkdata[pos], filename );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
382
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
383 /* file mime type [UTF-8] */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
384 mime = file_mime_type( filename, (const char*) data, datalen );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
385 pos += add_utf8_string( &chunkdata[pos], mime );
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 /* human readable description [UTF-8 (optional)] */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
388 pos += add_utf8_string( &chunkdata[pos], "" );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
389
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
390 /* crc [4 bytes] (0 = optional) */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
391 pos += add_int32( &chunkdata[pos], 0 );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
392
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
393 /* the actual file data */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
394 pos += add_data( &chunkdata[pos], (const char *) data, datalen );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
395
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
396 return pos;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
397 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
398
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
399
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 * Encode a "set avatar" chunk. (Chunk type 13)
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
402 *
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
403 * @param chunkdata Chunked-data buffer
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
404 * @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
405 * @param datalen The size 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
406 * @return The number of bytes encoded in the buffer
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
407 */
37822
06278419c703 Fix for TALOS-CAN-0120
Andrew Victor <andrew.victor@mxit.com>
parents: 34457
diff changeset
408 size_t mxit_chunk_create_set_avatar( char* chunkdata, const unsigned char* data, size_t datalen )
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
409 {
34457
a9d3726c3a8f Clang warnings: clean up libpurple
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33844
diff changeset
410 char fileid[MXIT_CHUNK_FILEID_LEN];
37822
06278419c703 Fix for TALOS-CAN-0120
Andrew Victor <andrew.victor@mxit.com>
parents: 34457
diff changeset
411 size_t pos = 0;
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
412
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
413 /* id [8 bytes] */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
414 memset( &fileid, 0, sizeof( fileid ) ); /* set to 0 for file upload */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
415 pos += add_data( &chunkdata[pos], fileid, MXIT_CHUNK_FILEID_LEN );
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 /* size [4 bytes] */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
418 pos += add_int32( &chunkdata[pos], datalen );
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 /* crc [4 bytes] (0 = optional) */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
421 pos += add_int32( &chunkdata[pos], 0 );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
422
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
423 /* the actual file data */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
424 pos += add_data( &chunkdata[pos], (const char *) data, datalen );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
425
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
426 return pos;
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
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
430 /*------------------------------------------------------------------------
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
431 * Encode a "get avatar" chunk. (Chunk type 14)
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 * @param chunkdata Chunked-data buffer
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
434 * @param mxitId The username who's avatar to download
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
435 * @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
436 * @return The number of bytes encoded in the buffer
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
437 */
37822
06278419c703 Fix for TALOS-CAN-0120
Andrew Victor <andrew.victor@mxit.com>
parents: 34457
diff changeset
438 size_t mxit_chunk_create_get_avatar( char* chunkdata, const char* mxitId, const char* avatarId )
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
439 {
37822
06278419c703 Fix for TALOS-CAN-0120
Andrew Victor <andrew.victor@mxit.com>
parents: 34457
diff changeset
440 size_t pos = 0;
28841
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 /* number of avatars [4 bytes] */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
443 pos += add_int32( &chunkdata[pos], 1 );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
444
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
445 /* username [UTF-8] */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
446 pos += add_utf8_string( &chunkdata[pos], mxitId );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
447
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
448 /* avatar id [UTF-8] */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
449 pos += add_utf8_string( &chunkdata[pos], avatarId );
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 /* avatar format [UTF-8] */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
452 pos += add_utf8_string( &chunkdata[pos], MXIT_AVATAR_TYPE );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
453
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
454 /* avatar bit depth [1 byte] */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
455 pos += add_int8( &chunkdata[pos], MXIT_AVATAR_BITDEPT );
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 /* number of sizes [2 bytes] */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
458 pos += add_int16( &chunkdata[pos], 1 );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
459
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
460 /* image size [4 bytes] */
30788
da428f8d1f97 * removed unneeded variable passing.
Pieter Loubser <pieter.loubser@mxit.com>
parents: 29106
diff changeset
461 pos += add_int32( &chunkdata[pos], MXIT_AVATAR_SIZE );
28841
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 return pos;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
464 }
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
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
467 /*========================================================================================================================
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
468 * Chunked Data decoding
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
469 */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
470
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 * Parse a received "offer file" chunk. (Chunk 6)
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
473 *
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
474 * @param chunkdata Chunked data buffer
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
475 * @param datalen The length of the chunked data
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
476 * @param offer Decoded offerfile information
37824
5e3601f8bde4 Fix chunk decoding errors
Andrew Victor <andrew.victor@mxit.com>
parents: 37822
diff changeset
477 * @return TRUE if successfully parsed, otherwise FALSE
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
478 */
37824
5e3601f8bde4 Fix chunk decoding errors
Andrew Victor <andrew.victor@mxit.com>
parents: 37822
diff changeset
479 gboolean mxit_chunk_parse_offer( char* chunkdata, size_t datalen, struct offerfile_chunk* offer )
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
480 {
37833
fe0e01b28407 Fix for TALOS-CAN-0138
Andrew Victor <andrew.victor@mxit.com>
parents: 37826
diff changeset
481 size_t pos = 0;
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
482
37822
06278419c703 Fix for TALOS-CAN-0120
Andrew Victor <andrew.victor@mxit.com>
parents: 34457
diff changeset
483 purple_debug_info( MXIT_PLUGIN_ID, "mxit_chunk_parse_offer (%zu bytes)\n", datalen );
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
484
37824
5e3601f8bde4 Fix chunk decoding errors
Andrew Victor <andrew.victor@mxit.com>
parents: 37822
diff changeset
485 memset( offer, 0, sizeof( struct offerfile_chunk ) );
5e3601f8bde4 Fix chunk decoding errors
Andrew Victor <andrew.victor@mxit.com>
parents: 37822
diff changeset
486
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
487 /* id [8 bytes] */
37833
fe0e01b28407 Fix for TALOS-CAN-0138
Andrew Victor <andrew.victor@mxit.com>
parents: 37826
diff changeset
488 pos += get_data( &chunkdata[pos], datalen - pos, offer->fileid, 8);
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
489
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
490 /* from username [UTF-8] */
37833
fe0e01b28407 Fix for TALOS-CAN-0138
Andrew Victor <andrew.victor@mxit.com>
parents: 37826
diff changeset
491 pos += get_utf8_string( &chunkdata[pos], datalen - pos, offer->username, sizeof( offer->username ) );
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
492 mxit_strip_domain( offer->username );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
493
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
494 /* file size [4 bytes] */
37833
fe0e01b28407 Fix for TALOS-CAN-0138
Andrew Victor <andrew.victor@mxit.com>
parents: 37826
diff changeset
495 pos += get_int32( &chunkdata[pos], datalen - pos, &(offer->filesize) );
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
496
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
497 /* filename [UTF-8] */
37833
fe0e01b28407 Fix for TALOS-CAN-0138
Andrew Victor <andrew.victor@mxit.com>
parents: 37826
diff changeset
498 pos += get_utf8_string( &chunkdata[pos], datalen - pos, offer->filename, sizeof( offer->filename ) );
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
499
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
500 /* mime type [UTF-8] */
37833
fe0e01b28407 Fix for TALOS-CAN-0138
Andrew Victor <andrew.victor@mxit.com>
parents: 37826
diff changeset
501 pos += get_utf8_string( &chunkdata[pos], datalen - pos, offer->mimetype, sizeof( offer->mimetype ) );
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
502
35688
3d727b2e6f82 Fix most of libpurple clang scan-build warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35680
diff changeset
503 if (pos > datalen)
3d727b2e6f82 Fix most of libpurple clang scan-build warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35680
diff changeset
504 purple_debug_warning(MXIT_PLUGIN_ID, "pos > datalen");
3d727b2e6f82 Fix most of libpurple clang scan-build warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35680
diff changeset
505
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
506 /* timestamp [8 bytes] */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
507 /* not used by libPurple */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
508
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
509 /* file description [UTF-8] */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
510 /* not used by libPurple */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
511
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
512 /* file alternative [UTF-8] */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
513 /* not used by libPurple */
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 /* flags [4 bytes] */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
516 /* not used by libPurple */
37824
5e3601f8bde4 Fix chunk decoding errors
Andrew Victor <andrew.victor@mxit.com>
parents: 37822
diff changeset
517
5e3601f8bde4 Fix chunk decoding errors
Andrew Victor <andrew.victor@mxit.com>
parents: 37822
diff changeset
518 return TRUE;
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
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
521
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
522 /*------------------------------------------------------------------------
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
523 * Parse a received "get file" response chunk. (Chunk 8)
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
524 *
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
525 * @param chunkdata Chunked data buffer
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
526 * @param datalen The length of the chunked data
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
527 * @param offer Decoded getfile information
37824
5e3601f8bde4 Fix chunk decoding errors
Andrew Victor <andrew.victor@mxit.com>
parents: 37822
diff changeset
528 * @return TRUE if successfully parsed, otherwise FALSE
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
529 */
37824
5e3601f8bde4 Fix chunk decoding errors
Andrew Victor <andrew.victor@mxit.com>
parents: 37822
diff changeset
530 gboolean mxit_chunk_parse_get( char* chunkdata, size_t datalen, struct getfile_chunk* getfile )
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
531 {
37833
fe0e01b28407 Fix for TALOS-CAN-0138
Andrew Victor <andrew.victor@mxit.com>
parents: 37826
diff changeset
532 size_t pos = 0;
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
533
37822
06278419c703 Fix for TALOS-CAN-0120
Andrew Victor <andrew.victor@mxit.com>
parents: 34457
diff changeset
534 purple_debug_info( MXIT_PLUGIN_ID, "mxit_chunk_parse_file (%zu bytes)\n", datalen );
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
535
37824
5e3601f8bde4 Fix chunk decoding errors
Andrew Victor <andrew.victor@mxit.com>
parents: 37822
diff changeset
536 memset( getfile, 0, sizeof( struct getfile_chunk ) );
5e3601f8bde4 Fix chunk decoding errors
Andrew Victor <andrew.victor@mxit.com>
parents: 37822
diff changeset
537
37826
648f667a679c Add a check to make sure the file can have a chunk
Andrew Victor <andrew.victor@mxit.com>
parents: 37824
diff changeset
538 /* ensure that the chunk size is atleast the minimum size for a "get file" chunk */
648f667a679c Add a check to make sure the file can have a chunk
Andrew Victor <andrew.victor@mxit.com>
parents: 37824
diff changeset
539 if ( datalen < 20 )
648f667a679c Add a check to make sure the file can have a chunk
Andrew Victor <andrew.victor@mxit.com>
parents: 37824
diff changeset
540 return FALSE;
648f667a679c Add a check to make sure the file can have a chunk
Andrew Victor <andrew.victor@mxit.com>
parents: 37824
diff changeset
541
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
542 /* id [8 bytes] */
37833
fe0e01b28407 Fix for TALOS-CAN-0138
Andrew Victor <andrew.victor@mxit.com>
parents: 37826
diff changeset
543 pos += get_data( &chunkdata[pos], datalen - pos, getfile->fileid, 8 );
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
544
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
545 /* offset [4 bytes] */
37833
fe0e01b28407 Fix for TALOS-CAN-0138
Andrew Victor <andrew.victor@mxit.com>
parents: 37826
diff changeset
546 pos += get_int32( &chunkdata[pos], datalen - pos, &(getfile->offset) );
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
547
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
548 /* file length [4 bytes] */
37833
fe0e01b28407 Fix for TALOS-CAN-0138
Andrew Victor <andrew.victor@mxit.com>
parents: 37826
diff changeset
549 pos += get_int32( &chunkdata[pos], datalen - pos, &(getfile->length) );
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
550
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
551 /* crc [4 bytes] */
37833
fe0e01b28407 Fix for TALOS-CAN-0138
Andrew Victor <andrew.victor@mxit.com>
parents: 37826
diff changeset
552 pos += get_int32( &chunkdata[pos], datalen - pos, &(getfile->crc) );
fe0e01b28407 Fix for TALOS-CAN-0138
Andrew Victor <andrew.victor@mxit.com>
parents: 37826
diff changeset
553
fe0e01b28407 Fix for TALOS-CAN-0138
Andrew Victor <andrew.victor@mxit.com>
parents: 37826
diff changeset
554 /* check length does not exceed chunked data length */
fe0e01b28407 Fix for TALOS-CAN-0138
Andrew Victor <andrew.victor@mxit.com>
parents: 37826
diff changeset
555 if ( getfile->length > datalen - pos )
fe0e01b28407 Fix for TALOS-CAN-0138
Andrew Victor <andrew.victor@mxit.com>
parents: 37826
diff changeset
556 return FALSE;
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
557
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
558 /* file data */
37833
fe0e01b28407 Fix for TALOS-CAN-0138
Andrew Victor <andrew.victor@mxit.com>
parents: 37826
diff changeset
559 if ( getfile->length > 0 )
fe0e01b28407 Fix for TALOS-CAN-0138
Andrew Victor <andrew.victor@mxit.com>
parents: 37826
diff changeset
560 getfile->data = &chunkdata[pos];
37824
5e3601f8bde4 Fix chunk decoding errors
Andrew Victor <andrew.victor@mxit.com>
parents: 37822
diff changeset
561
5e3601f8bde4 Fix chunk decoding errors
Andrew Victor <andrew.victor@mxit.com>
parents: 37822
diff changeset
562 return TRUE;
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
563 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
564
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
565
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
566 /*------------------------------------------------------------------------
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
567 * Parse a received splash screen chunk. (Chunk 2)
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
568 *
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
569 * @param chunkdata Chunked data buffer
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
570 * @param datalen The length of the chunked data
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
571 * @param splash Decoded splash image information
37824
5e3601f8bde4 Fix chunk decoding errors
Andrew Victor <andrew.victor@mxit.com>
parents: 37822
diff changeset
572 * @return TRUE if successfully parsed, otherwise FALSE
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
573 */
37824
5e3601f8bde4 Fix chunk decoding errors
Andrew Victor <andrew.victor@mxit.com>
parents: 37822
diff changeset
574 gboolean mxit_chunk_parse_splash( char* chunkdata, size_t datalen, struct splash_chunk* splash )
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
575 {
37833
fe0e01b28407 Fix for TALOS-CAN-0138
Andrew Victor <andrew.victor@mxit.com>
parents: 37826
diff changeset
576 size_t pos = 0;
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
577
37822
06278419c703 Fix for TALOS-CAN-0120
Andrew Victor <andrew.victor@mxit.com>
parents: 34457
diff changeset
578 purple_debug_info( MXIT_PLUGIN_ID, "mxit_chunk_parse_splash (%zu bytes)\n", datalen );
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
579
37824
5e3601f8bde4 Fix chunk decoding errors
Andrew Victor <andrew.victor@mxit.com>
parents: 37822
diff changeset
580 memset( splash, 0, sizeof( struct splash_chunk ) );
5e3601f8bde4 Fix chunk decoding errors
Andrew Victor <andrew.victor@mxit.com>
parents: 37822
diff changeset
581
37833
fe0e01b28407 Fix for TALOS-CAN-0138
Andrew Victor <andrew.victor@mxit.com>
parents: 37826
diff changeset
582 /* ensure that the chunk size is atleast the minimum size for a "splash screen" chunk */
fe0e01b28407 Fix for TALOS-CAN-0138
Andrew Victor <andrew.victor@mxit.com>
parents: 37826
diff changeset
583 if ( datalen < 6 )
fe0e01b28407 Fix for TALOS-CAN-0138
Andrew Victor <andrew.victor@mxit.com>
parents: 37826
diff changeset
584 return FALSE;
fe0e01b28407 Fix for TALOS-CAN-0138
Andrew Victor <andrew.victor@mxit.com>
parents: 37826
diff changeset
585
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
586 /* anchor [1 byte] */
37833
fe0e01b28407 Fix for TALOS-CAN-0138
Andrew Victor <andrew.victor@mxit.com>
parents: 37826
diff changeset
587 pos += get_int8( &chunkdata[pos], datalen - pos, &(splash->anchor) );
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
588
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
589 /* time to show [1 byte] */
37833
fe0e01b28407 Fix for TALOS-CAN-0138
Andrew Victor <andrew.victor@mxit.com>
parents: 37826
diff changeset
590 pos += get_int8( &chunkdata[pos], datalen - pos, &(splash->showtime) );
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
591
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
592 /* background color [4 bytes] */
37833
fe0e01b28407 Fix for TALOS-CAN-0138
Andrew Victor <andrew.victor@mxit.com>
parents: 37826
diff changeset
593 pos += get_int32( &chunkdata[pos], datalen - pos, &(splash->bgcolor) );
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
594
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
595 /* file data */
37833
fe0e01b28407 Fix for TALOS-CAN-0138
Andrew Victor <andrew.victor@mxit.com>
parents: 37826
diff changeset
596 if ( pos < datalen )
fe0e01b28407 Fix for TALOS-CAN-0138
Andrew Victor <andrew.victor@mxit.com>
parents: 37826
diff changeset
597 splash->data = &chunkdata[pos];
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
598
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
599 /* data length */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
600 splash->datalen = datalen - pos;
37824
5e3601f8bde4 Fix chunk decoding errors
Andrew Victor <andrew.victor@mxit.com>
parents: 37822
diff changeset
601
5e3601f8bde4 Fix chunk decoding errors
Andrew Victor <andrew.victor@mxit.com>
parents: 37822
diff changeset
602 return TRUE;
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
603 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
604
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
605
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 * Parse a received "custom resource" chunk. (Chunk 1)
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 * @param chunkdata Chunked data buffer
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
610 * @param datalen The length of the chunked data
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
611 * @param offer Decoded custom resource
37824
5e3601f8bde4 Fix chunk decoding errors
Andrew Victor <andrew.victor@mxit.com>
parents: 37822
diff changeset
612 * @return TRUE if successfully parsed, otherwise FALSE
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
613 */
37824
5e3601f8bde4 Fix chunk decoding errors
Andrew Victor <andrew.victor@mxit.com>
parents: 37822
diff changeset
614 gboolean mxit_chunk_parse_cr( char* chunkdata, size_t datalen, struct cr_chunk* cr )
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
615 {
37833
fe0e01b28407 Fix for TALOS-CAN-0138
Andrew Victor <andrew.victor@mxit.com>
parents: 37826
diff changeset
616 size_t pos = 0;
fe0e01b28407 Fix for TALOS-CAN-0138
Andrew Victor <andrew.victor@mxit.com>
parents: 37826
diff changeset
617 unsigned int chunkslen = 0;
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
618
37822
06278419c703 Fix for TALOS-CAN-0120
Andrew Victor <andrew.victor@mxit.com>
parents: 34457
diff changeset
619 purple_debug_info( MXIT_PLUGIN_ID, "mxit_chunk_parse_cr (%zu bytes)\n", datalen );
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
620
37824
5e3601f8bde4 Fix chunk decoding errors
Andrew Victor <andrew.victor@mxit.com>
parents: 37822
diff changeset
621 memset( cr, 0, sizeof( struct cr_chunk ) );
5e3601f8bde4 Fix chunk decoding errors
Andrew Victor <andrew.victor@mxit.com>
parents: 37822
diff changeset
622
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
623 /* id [UTF-8] */
37833
fe0e01b28407 Fix for TALOS-CAN-0138
Andrew Victor <andrew.victor@mxit.com>
parents: 37826
diff changeset
624 pos += get_utf8_string( &chunkdata[pos], datalen - pos, cr->id, sizeof( cr->id ) );
28841
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 /* handle [UTF-8] */
37833
fe0e01b28407 Fix for TALOS-CAN-0138
Andrew Victor <andrew.victor@mxit.com>
parents: 37826
diff changeset
627 pos += get_utf8_string( &chunkdata[pos], datalen - pos, cr->handle, sizeof( cr->handle ) );
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
628
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
629 /* operation [1 byte] */
37833
fe0e01b28407 Fix for TALOS-CAN-0138
Andrew Victor <andrew.victor@mxit.com>
parents: 37826
diff changeset
630 pos += get_int8( &chunkdata[pos], datalen - pos, &(cr->operation) );
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
631
37833
fe0e01b28407 Fix for TALOS-CAN-0138
Andrew Victor <andrew.victor@mxit.com>
parents: 37826
diff changeset
632 /* total length of all the chunks that are included [4 bytes] */
fe0e01b28407 Fix for TALOS-CAN-0138
Andrew Victor <andrew.victor@mxit.com>
parents: 37826
diff changeset
633 pos += get_int32( &chunkdata[pos], datalen - pos, &chunkslen );
fe0e01b28407 Fix for TALOS-CAN-0138
Andrew Victor <andrew.victor@mxit.com>
parents: 37826
diff changeset
634
fe0e01b28407 Fix for TALOS-CAN-0138
Andrew Victor <andrew.victor@mxit.com>
parents: 37826
diff changeset
635 /* ensure the chunks size does not exceed the data size */
fe0e01b28407 Fix for TALOS-CAN-0138
Andrew Victor <andrew.victor@mxit.com>
parents: 37826
diff changeset
636 if ( pos + chunkslen > datalen )
fe0e01b28407 Fix for TALOS-CAN-0138
Andrew Victor <andrew.victor@mxit.com>
parents: 37826
diff changeset
637 return FALSE;
28841
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 /* parse the resource chunks */
37833
fe0e01b28407 Fix for TALOS-CAN-0138
Andrew Victor <andrew.victor@mxit.com>
parents: 37826
diff changeset
640 while ( chunkslen >= MXIT_CHUNK_HEADER_SIZE ) {
fe0e01b28407 Fix for TALOS-CAN-0138
Andrew Victor <andrew.victor@mxit.com>
parents: 37826
diff changeset
641 gchar* chunk = &chunkdata[pos];
fe0e01b28407 Fix for TALOS-CAN-0138
Andrew Victor <andrew.victor@mxit.com>
parents: 37826
diff changeset
642 guint32 chunksize = chunk_length( chunk );
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
643
37833
fe0e01b28407 Fix for TALOS-CAN-0138
Andrew Victor <andrew.victor@mxit.com>
parents: 37826
diff changeset
644 /* check chunk size against length of received data */
fe0e01b28407 Fix for TALOS-CAN-0138
Andrew Victor <andrew.victor@mxit.com>
parents: 37826
diff changeset
645 if ( pos + MXIT_CHUNK_HEADER_SIZE + chunksize > datalen )
fe0e01b28407 Fix for TALOS-CAN-0138
Andrew Victor <andrew.victor@mxit.com>
parents: 37826
diff changeset
646 return FALSE;
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
647
28988
e59ddd6a3942 The "packed" attribute on the raw_chunk data-structure seems to be a GCC extension.
Andrew Victor <andrew.victor@mxit.com>
parents: 28841
diff changeset
648 switch ( chunk_type( chunk ) ) {
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
649 case CP_CHUNK_SPLASH : /* splash image */
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 struct splash_chunk* splash = g_new0( struct splash_chunk, 1 );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
652
37833
fe0e01b28407 Fix for TALOS-CAN-0138
Andrew Victor <andrew.victor@mxit.com>
parents: 37826
diff changeset
653 if ( mxit_chunk_parse_splash( chunk_data( chunk ), chunksize, splash ) )
37824
5e3601f8bde4 Fix chunk decoding errors
Andrew Victor <andrew.victor@mxit.com>
parents: 37822
diff changeset
654 cr->resources = g_list_append( cr->resources, splash );
5e3601f8bde4 Fix chunk decoding errors
Andrew Victor <andrew.victor@mxit.com>
parents: 37822
diff changeset
655 else
5e3601f8bde4 Fix chunk decoding errors
Andrew Victor <andrew.victor@mxit.com>
parents: 37822
diff changeset
656 g_free( splash );
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
657 break;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
658 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
659 case CP_CHUNK_CLICK : /* splash click */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
660 {
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
661 struct splash_click_chunk* click = g_new0( struct splash_click_chunk, 1 );
31294
73607ab89c6f Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents: 29106
diff changeset
662
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
663 cr->resources = g_list_append( cr->resources, click );
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
664 break;
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
665 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
666 default:
28988
e59ddd6a3942 The "packed" attribute on the raw_chunk data-structure seems to be a GCC extension.
Andrew Victor <andrew.victor@mxit.com>
parents: 28841
diff changeset
667 purple_debug_info( MXIT_PLUGIN_ID, "Unsupported custom resource chunk received (%i)\n", chunk_type( chunk) );
28841
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 /* skip over data to next resource chunk */
37833
fe0e01b28407 Fix for TALOS-CAN-0138
Andrew Victor <andrew.victor@mxit.com>
parents: 37826
diff changeset
671 pos += MXIT_CHUNK_HEADER_SIZE + chunksize;
fe0e01b28407 Fix for TALOS-CAN-0138
Andrew Victor <andrew.victor@mxit.com>
parents: 37826
diff changeset
672 chunkslen -= ( MXIT_CHUNK_HEADER_SIZE + chunksize );
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
673 }
37824
5e3601f8bde4 Fix chunk decoding errors
Andrew Victor <andrew.victor@mxit.com>
parents: 37822
diff changeset
674
5e3601f8bde4 Fix chunk decoding errors
Andrew Victor <andrew.victor@mxit.com>
parents: 37822
diff changeset
675 return TRUE;
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
676 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
677
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 /*------------------------------------------------------------------------
31722
9e4e8315893d * Handle response to SendFile chunk packet, and display the error message
Andrew Victor <andrew.victor@mxit.com>
parents: 31496
diff changeset
680 * Parse a received "send file direct" response chunk. (Chunk 10)
9e4e8315893d * Handle response to SendFile chunk packet, and display the error message
Andrew Victor <andrew.victor@mxit.com>
parents: 31496
diff changeset
681 *
9e4e8315893d * Handle response to SendFile chunk packet, and display the error message
Andrew Victor <andrew.victor@mxit.com>
parents: 31496
diff changeset
682 * @param chunkdata Chunked data buffer
9e4e8315893d * Handle response to SendFile chunk packet, and display the error message
Andrew Victor <andrew.victor@mxit.com>
parents: 31496
diff changeset
683 * @param datalen The length of the chunked data
9e4e8315893d * Handle response to SendFile chunk packet, and display the error message
Andrew Victor <andrew.victor@mxit.com>
parents: 31496
diff changeset
684 * @param sendfile Decoded sendfile information
37824
5e3601f8bde4 Fix chunk decoding errors
Andrew Victor <andrew.victor@mxit.com>
parents: 37822
diff changeset
685 * @return TRUE if successfully parsed, otherwise FALSE
31722
9e4e8315893d * Handle response to SendFile chunk packet, and display the error message
Andrew Victor <andrew.victor@mxit.com>
parents: 31496
diff changeset
686 */
37824
5e3601f8bde4 Fix chunk decoding errors
Andrew Victor <andrew.victor@mxit.com>
parents: 37822
diff changeset
687 gboolean mxit_chunk_parse_sendfile( char* chunkdata, size_t datalen, struct sendfile_chunk* sendfile )
31722
9e4e8315893d * Handle response to SendFile chunk packet, and display the error message
Andrew Victor <andrew.victor@mxit.com>
parents: 31496
diff changeset
688 {
37833
fe0e01b28407 Fix for TALOS-CAN-0138
Andrew Victor <andrew.victor@mxit.com>
parents: 37826
diff changeset
689 size_t pos = 0;
37822
06278419c703 Fix for TALOS-CAN-0120
Andrew Victor <andrew.victor@mxit.com>
parents: 34457
diff changeset
690 unsigned short entries = 0;
31722
9e4e8315893d * Handle response to SendFile chunk packet, and display the error message
Andrew Victor <andrew.victor@mxit.com>
parents: 31496
diff changeset
691
37822
06278419c703 Fix for TALOS-CAN-0120
Andrew Victor <andrew.victor@mxit.com>
parents: 34457
diff changeset
692 purple_debug_info( MXIT_PLUGIN_ID, "mxit_chunk_parse_sendfile (%zu bytes)\n", datalen );
31722
9e4e8315893d * Handle response to SendFile chunk packet, and display the error message
Andrew Victor <andrew.victor@mxit.com>
parents: 31496
diff changeset
693
37824
5e3601f8bde4 Fix chunk decoding errors
Andrew Victor <andrew.victor@mxit.com>
parents: 37822
diff changeset
694 memset( sendfile, 0, sizeof( struct sendfile_chunk ) );
5e3601f8bde4 Fix chunk decoding errors
Andrew Victor <andrew.victor@mxit.com>
parents: 37822
diff changeset
695
31722
9e4e8315893d * Handle response to SendFile chunk packet, and display the error message
Andrew Victor <andrew.victor@mxit.com>
parents: 31496
diff changeset
696 /* number of entries [2 bytes] */
37833
fe0e01b28407 Fix for TALOS-CAN-0138
Andrew Victor <andrew.victor@mxit.com>
parents: 37826
diff changeset
697 pos += get_int16( &chunkdata[pos], datalen - pos, &entries );
31722
9e4e8315893d * Handle response to SendFile chunk packet, and display the error message
Andrew Victor <andrew.victor@mxit.com>
parents: 31496
diff changeset
698
9e4e8315893d * Handle response to SendFile chunk packet, and display the error message
Andrew Victor <andrew.victor@mxit.com>
parents: 31496
diff changeset
699 if ( entries < 1 ) /* no data */
37824
5e3601f8bde4 Fix chunk decoding errors
Andrew Victor <andrew.victor@mxit.com>
parents: 37822
diff changeset
700 return FALSE;
31722
9e4e8315893d * Handle response to SendFile chunk packet, and display the error message
Andrew Victor <andrew.victor@mxit.com>
parents: 31496
diff changeset
701
9e4e8315893d * Handle response to SendFile chunk packet, and display the error message
Andrew Victor <andrew.victor@mxit.com>
parents: 31496
diff changeset
702 /* contactAddress [UTF-8 string] */
37833
fe0e01b28407 Fix for TALOS-CAN-0138
Andrew Victor <andrew.victor@mxit.com>
parents: 37826
diff changeset
703 pos += get_utf8_string( &chunkdata[pos], datalen - pos, sendfile->username, sizeof( sendfile->username ) );
31722
9e4e8315893d * Handle response to SendFile chunk packet, and display the error message
Andrew Victor <andrew.victor@mxit.com>
parents: 31496
diff changeset
704
9e4e8315893d * Handle response to SendFile chunk packet, and display the error message
Andrew Victor <andrew.victor@mxit.com>
parents: 31496
diff changeset
705 /* status [4 bytes] */
37833
fe0e01b28407 Fix for TALOS-CAN-0138
Andrew Victor <andrew.victor@mxit.com>
parents: 37826
diff changeset
706 pos += get_int32( &chunkdata[pos], datalen - pos, &(sendfile->status) );
31722
9e4e8315893d * Handle response to SendFile chunk packet, and display the error message
Andrew Victor <andrew.victor@mxit.com>
parents: 31496
diff changeset
707
9e4e8315893d * Handle response to SendFile chunk packet, and display the error message
Andrew Victor <andrew.victor@mxit.com>
parents: 31496
diff changeset
708 /* status message [UTF-8 string] */
37833
fe0e01b28407 Fix for TALOS-CAN-0138
Andrew Victor <andrew.victor@mxit.com>
parents: 37826
diff changeset
709 pos += get_utf8_string( &chunkdata[pos], datalen - pos, sendfile->statusmsg, sizeof( sendfile->statusmsg ) );
37824
5e3601f8bde4 Fix chunk decoding errors
Andrew Victor <andrew.victor@mxit.com>
parents: 37822
diff changeset
710
5e3601f8bde4 Fix chunk decoding errors
Andrew Victor <andrew.victor@mxit.com>
parents: 37822
diff changeset
711 return TRUE;
31722
9e4e8315893d * Handle response to SendFile chunk packet, and display the error message
Andrew Victor <andrew.victor@mxit.com>
parents: 31496
diff changeset
712 }
9e4e8315893d * Handle response to SendFile chunk packet, and display the error message
Andrew Victor <andrew.victor@mxit.com>
parents: 31496
diff changeset
713
9e4e8315893d * Handle response to SendFile chunk packet, and display the error message
Andrew Victor <andrew.victor@mxit.com>
parents: 31496
diff changeset
714
9e4e8315893d * Handle response to SendFile chunk packet, and display the error message
Andrew Victor <andrew.victor@mxit.com>
parents: 31496
diff changeset
715 /*------------------------------------------------------------------------
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
716 * Parse a received "get avatar" response chunk. (Chunk 14)
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
717 *
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
718 * @param chunkdata Chunked data buffer
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
719 * @param datalen The length of the chunked data
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
720 * @param avatar Decoded avatar information
37824
5e3601f8bde4 Fix chunk decoding errors
Andrew Victor <andrew.victor@mxit.com>
parents: 37822
diff changeset
721 * @return TRUE if successfully parsed, otherwise FALSE
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
722 */
37824
5e3601f8bde4 Fix chunk decoding errors
Andrew Victor <andrew.victor@mxit.com>
parents: 37822
diff changeset
723 gboolean mxit_chunk_parse_get_avatar( char* chunkdata, size_t datalen, struct getavatar_chunk* avatar )
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
724 {
37833
fe0e01b28407 Fix for TALOS-CAN-0138
Andrew Victor <andrew.victor@mxit.com>
parents: 37826
diff changeset
725 size_t pos = 0;
37822
06278419c703 Fix for TALOS-CAN-0120
Andrew Victor <andrew.victor@mxit.com>
parents: 34457
diff changeset
726 unsigned int numfiles = 0;
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
727
37822
06278419c703 Fix for TALOS-CAN-0120
Andrew Victor <andrew.victor@mxit.com>
parents: 34457
diff changeset
728 purple_debug_info( MXIT_PLUGIN_ID, "mxit_chunk_parse_get_avatar (%zu bytes)\n", datalen );
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
729
37824
5e3601f8bde4 Fix chunk decoding errors
Andrew Victor <andrew.victor@mxit.com>
parents: 37822
diff changeset
730 memset( avatar, 0, sizeof( struct getavatar_chunk ) );
5e3601f8bde4 Fix chunk decoding errors
Andrew Victor <andrew.victor@mxit.com>
parents: 37822
diff changeset
731
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
732 /* number of files [4 bytes] */
37833
fe0e01b28407 Fix for TALOS-CAN-0138
Andrew Victor <andrew.victor@mxit.com>
parents: 37826
diff changeset
733 pos += get_int32( &chunkdata[pos], datalen - pos, &numfiles );
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 if ( numfiles < 1 ) /* no data */
37824
5e3601f8bde4 Fix chunk decoding errors
Andrew Victor <andrew.victor@mxit.com>
parents: 37822
diff changeset
736 return FALSE;
28841
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 /* mxitId [UTF-8 string] */
37833
fe0e01b28407 Fix for TALOS-CAN-0138
Andrew Victor <andrew.victor@mxit.com>
parents: 37826
diff changeset
739 pos += get_utf8_string( &chunkdata[pos], datalen - pos, avatar->mxitid, sizeof( avatar->mxitid ) );
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
740
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
741 /* avatar id [UTF-8 string] */
37833
fe0e01b28407 Fix for TALOS-CAN-0138
Andrew Victor <andrew.victor@mxit.com>
parents: 37826
diff changeset
742 pos += get_utf8_string( &chunkdata[pos], datalen - pos, avatar->avatarid, sizeof( avatar->avatarid ) );
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
743
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
744 /* format [UTF-8 string] */
37833
fe0e01b28407 Fix for TALOS-CAN-0138
Andrew Victor <andrew.victor@mxit.com>
parents: 37826
diff changeset
745 pos += get_utf8_string( &chunkdata[pos], datalen - pos, avatar->format, sizeof( avatar->format ) );
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
746
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
747 /* bit depth [1 byte] */
37833
fe0e01b28407 Fix for TALOS-CAN-0138
Andrew Victor <andrew.victor@mxit.com>
parents: 37826
diff changeset
748 pos += get_int8( &chunkdata[pos], datalen - pos, &(avatar->bitdepth) );
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
749
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
750 /* crc [4 bytes] */
37833
fe0e01b28407 Fix for TALOS-CAN-0138
Andrew Victor <andrew.victor@mxit.com>
parents: 37826
diff changeset
751 pos += get_int32( &chunkdata[pos], datalen - pos, &(avatar->crc) );
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
752
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
753 /* width [4 bytes] */
37833
fe0e01b28407 Fix for TALOS-CAN-0138
Andrew Victor <andrew.victor@mxit.com>
parents: 37826
diff changeset
754 pos += get_int32( &chunkdata[pos], datalen - pos, &(avatar->width) );
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
755
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
756 /* height [4 bytes] */
37833
fe0e01b28407 Fix for TALOS-CAN-0138
Andrew Victor <andrew.victor@mxit.com>
parents: 37826
diff changeset
757 pos += get_int32( &chunkdata[pos], datalen - pos, &(avatar->height) );
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
758
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
759 /* file length [4 bytes] */
37833
fe0e01b28407 Fix for TALOS-CAN-0138
Andrew Victor <andrew.victor@mxit.com>
parents: 37826
diff changeset
760 pos += get_int32( &chunkdata[pos], datalen - pos, &(avatar->length) );
fe0e01b28407 Fix for TALOS-CAN-0138
Andrew Victor <andrew.victor@mxit.com>
parents: 37826
diff changeset
761
fe0e01b28407 Fix for TALOS-CAN-0138
Andrew Victor <andrew.victor@mxit.com>
parents: 37826
diff changeset
762 /* check length does not exceed chunked data length */
fe0e01b28407 Fix for TALOS-CAN-0138
Andrew Victor <andrew.victor@mxit.com>
parents: 37826
diff changeset
763 if ( avatar->length > datalen - pos )
fe0e01b28407 Fix for TALOS-CAN-0138
Andrew Victor <andrew.victor@mxit.com>
parents: 37826
diff changeset
764 return FALSE;
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
765
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
766 /* file data */
37833
fe0e01b28407 Fix for TALOS-CAN-0138
Andrew Victor <andrew.victor@mxit.com>
parents: 37826
diff changeset
767 if ( avatar->length > 0 )
fe0e01b28407 Fix for TALOS-CAN-0138
Andrew Victor <andrew.victor@mxit.com>
parents: 37826
diff changeset
768 avatar->data = &chunkdata[pos];
37824
5e3601f8bde4 Fix chunk decoding errors
Andrew Victor <andrew.victor@mxit.com>
parents: 37822
diff changeset
769
5e3601f8bde4 Fix chunk decoding errors
Andrew Victor <andrew.victor@mxit.com>
parents: 37822
diff changeset
770 return TRUE;
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
771 }

mercurial