Mercurial > pidgin.yaz
comparison libpurple/protocols/msn/xfer.c @ 32827:4a34689eeb33 default tip
merged from im.pidgin.pidgin
author | Yoshiki Yazawa <yaz@honeyplanet.jp> |
---|---|
date | Sat, 19 Nov 2011 14:42:54 +0900 |
parents | f0b5a6f8fded |
children |
comparison
equal
deleted
inserted
replaced
32692:0f94ec89f0bc | 32827:4a34689eeb33 |
---|---|
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); |
175 memcpy(tmp, context->file_name, MAX_FILE_NAME_LEN * 2); | 175 memcpy(tmp, context->file_name, MAX_FILE_NAME_LEN * 2); |
176 tmp += MAX_FILE_NAME_LEN * 2; | 176 tmp += MAX_FILE_NAME_LEN * 2; |
177 #if 0 | |
177 memcpy(tmp, context->unknown1, sizeof(context->unknown1)); | 178 memcpy(tmp, context->unknown1, sizeof(context->unknown1)); |
178 tmp += sizeof(context->unknown1); | 179 tmp += sizeof(context->unknown1); |
179 msn_push32le(tmp, context->unknown2); | 180 msn_push32le(tmp, context->unknown2); |
181 #else | |
182 memset(tmp, 0, sizeof(gchar[30])); | |
183 tmp += sizeof(gchar[30]); | |
184 msn_push32le(tmp, 0xffffffff); | |
185 #endif | |
180 if (context->preview) { | 186 if (context->preview) { |
181 memcpy(tmp, context->preview, context->preview_len); | 187 memcpy(tmp, context->preview, context->preview_len); |
182 } | 188 } |
183 tmp[context->preview_len] = '\0'; | 189 tmp[context->preview_len] = '\0'; |
184 | 190 |
188 MsnFileContext * | 194 MsnFileContext * |
189 msn_file_context_from_wire(const char *buf, gsize len) | 195 msn_file_context_from_wire(const char *buf, gsize len) |
190 { | 196 { |
191 MsnFileContext *context; | 197 MsnFileContext *context; |
192 | 198 |
193 if (!buf || len < MSN_FILE_CONTEXT_SIZE) | 199 if (!buf || len < MSN_FILE_CONTEXT_SIZE_V0) |
194 return NULL; | 200 return NULL; |
195 | 201 |
196 context = g_new(MsnFileContext, 1); | 202 context = g_new(MsnFileContext, 1); |
197 | 203 |
198 context->length = msn_pop32le(buf); | 204 context->length = msn_pop32le(buf); |
199 context->version = msn_pop32le(buf); | 205 context->version = msn_pop32le(buf); |
200 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) { | |
201 /* The length field is broken for this version. No check. */ | 212 /* The length field is broken for this version. No check. */ |
202 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 } | |
203 } else if (context->version == 3) { | 218 } else if (context->version == 3) { |
204 if (context->length != MSN_FILE_CONTEXT_SIZE + 63) { | 219 if (context->length != MSN_FILE_CONTEXT_SIZE_V3) { |
205 g_free(context); | 220 g_free(context); |
206 return NULL; | 221 return NULL; |
207 } else if (len < MSN_FILE_CONTEXT_SIZE + 63) { | 222 } else if (len < MSN_FILE_CONTEXT_SIZE_V3) { |
208 g_free(context); | 223 g_free(context); |
209 return NULL; | 224 return NULL; |
210 } | 225 } |
211 } else { | 226 } else { |
212 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); |
216 | 231 |
217 context->file_size = msn_pop64le(buf); | 232 context->file_size = msn_pop64le(buf); |
218 context->type = msn_pop32le(buf); | 233 context->type = msn_pop32le(buf); |
219 memcpy(context->file_name, buf, MAX_FILE_NAME_LEN * 2); | 234 memcpy(context->file_name, buf, MAX_FILE_NAME_LEN * 2); |
220 buf += MAX_FILE_NAME_LEN * 2; | 235 buf += MAX_FILE_NAME_LEN * 2; |
221 memcpy(context->unknown1, buf, sizeof(context->unknown1)); | 236 if (context->version > 0) { |
222 buf += sizeof(context->unknown1); | 237 #if 0 |
223 context->unknown2 = msn_pop32le(buf); | 238 memcpy(context->unknown1, buf, sizeof(context->unknown1)); |
239 buf += sizeof(context->unknown1); | |
240 context->unknown2 = msn_pop32le(buf); | |
241 #else | |
242 buf += sizeof(gchar[30]) + sizeof(guint32); | |
243 #endif | |
244 } | |
224 | 245 |
225 if (context->type == 0 && len > context->length) { | 246 if (context->type == 0 && len > context->length) { |
226 context->preview_len = len - context->length; | 247 context->preview_len = len - context->length; |
227 context->preview = g_memdup(buf, context->preview_len); | 248 context->preview = g_memdup(buf, context->preview_len); |
228 } else { | 249 } else { |