comparison libpurple/protocols/msn/xfer.c @ 32750:f0b5a6f8fded

Add support for file context v0, which is used by older official MSN clients on Macs.
author Elliott Sales de Andrade <qulogic@pidgin.im>
date Sun, 16 Oct 2011 00:15:40 +0000
parents b2b704d658da
children
comparison
equal deleted inserted replaced
32749:b2b704d658da 32750:f0b5a6f8fded
164 gchar * 164 gchar *
165 msn_file_context_to_wire(MsnFileContext *context) 165 msn_file_context_to_wire(MsnFileContext *context)
166 { 166 {
167 gchar *ret, *tmp; 167 gchar *ret, *tmp;
168 168
169 tmp = ret = g_new(gchar, MSN_FILE_CONTEXT_SIZE + context->preview_len + 1); 169 tmp = ret = g_new(gchar, MSN_FILE_CONTEXT_SIZE_V2 + context->preview_len + 1);
170 170
171 msn_push32le(tmp, context->length); 171 msn_push32le(tmp, context->length);
172 msn_push32le(tmp, context->version); 172 msn_push32le(tmp, context->version);
173 msn_push64le(tmp, context->file_size); 173 msn_push64le(tmp, context->file_size);
174 msn_push32le(tmp, context->type); 174 msn_push32le(tmp, context->type);
194 MsnFileContext * 194 MsnFileContext *
195 msn_file_context_from_wire(const char *buf, gsize len) 195 msn_file_context_from_wire(const char *buf, gsize len)
196 { 196 {
197 MsnFileContext *context; 197 MsnFileContext *context;
198 198
199 if (!buf || len < MSN_FILE_CONTEXT_SIZE) 199 if (!buf || len < MSN_FILE_CONTEXT_SIZE_V0)
200 return NULL; 200 return NULL;
201 201
202 context = g_new(MsnFileContext, 1); 202 context = g_new(MsnFileContext, 1);
203 203
204 context->length = msn_pop32le(buf); 204 context->length = msn_pop32le(buf);
205 context->version = msn_pop32le(buf); 205 context->version = msn_pop32le(buf);
206 if (context->version == 2) { 206 if (context->version == 0) {
207 if (context->length != MSN_FILE_CONTEXT_SIZE_V0) {
208 g_free(context);
209 return NULL;
210 }
211 } else if (context->version == 2) {
207 /* The length field is broken for this version. No check. */ 212 /* The length field is broken for this version. No check. */
208 context->length = MSN_FILE_CONTEXT_SIZE; 213 context->length = MSN_FILE_CONTEXT_SIZE_V2;
214 if (len < MSN_FILE_CONTEXT_SIZE_V2) {
215 g_free(context);
216 return NULL;
217 }
209 } else if (context->version == 3) { 218 } else if (context->version == 3) {
210 if (context->length != MSN_FILE_CONTEXT_SIZE + 63) { 219 if (context->length != MSN_FILE_CONTEXT_SIZE_V3) {
211 g_free(context); 220 g_free(context);
212 return NULL; 221 return NULL;
213 } else if (len < MSN_FILE_CONTEXT_SIZE + 63) { 222 } else if (len < MSN_FILE_CONTEXT_SIZE_V3) {
214 g_free(context); 223 g_free(context);
215 return NULL; 224 return NULL;
216 } 225 }
217 } else { 226 } else {
218 purple_debug_warning("msn", "Received MsnFileContext with unknown version: %d\n", context->version); 227 purple_debug_warning("msn", "Received MsnFileContext with unknown version: %d\n", context->version);
222 231
223 context->file_size = msn_pop64le(buf); 232 context->file_size = msn_pop64le(buf);
224 context->type = msn_pop32le(buf); 233 context->type = msn_pop32le(buf);
225 memcpy(context->file_name, buf, MAX_FILE_NAME_LEN * 2); 234 memcpy(context->file_name, buf, MAX_FILE_NAME_LEN * 2);
226 buf += MAX_FILE_NAME_LEN * 2; 235 buf += MAX_FILE_NAME_LEN * 2;
236 if (context->version > 0) {
227 #if 0 237 #if 0
228 memcpy(context->unknown1, buf, sizeof(context->unknown1)); 238 memcpy(context->unknown1, buf, sizeof(context->unknown1));
229 buf += sizeof(context->unknown1); 239 buf += sizeof(context->unknown1);
230 context->unknown2 = msn_pop32le(buf); 240 context->unknown2 = msn_pop32le(buf);
231 #else 241 #else
232 buf += sizeof(gchar[30]) + sizeof(guint32); 242 buf += sizeof(gchar[30]) + sizeof(guint32);
233 #endif 243 #endif
244 }
234 245
235 if (context->type == 0 && len > context->length) { 246 if (context->type == 0 && len > context->length) {
236 context->preview_len = len - context->length; 247 context->preview_len = len - context->length;
237 context->preview = g_memdup(buf, context->preview_len); 248 context->preview = g_memdup(buf, context->preview_len);
238 } else { 249 } else {