Mercurial > pidgin
comparison libpurple/protocols/msn/xfer.c @ 32819:2c6510167895 default tip
propagate from branch 'im.pidgin.pidgin.2.x.y' (head 3315c5dfbd0ad16511bdcf865e5b07c02d07df24)
to branch 'im.pidgin.pidgin' (head cbd1eda6bcbf0565ae7766396bb8f6f419cb6a9a)
author | Elliott Sales de Andrade <qulogic@pidgin.im> |
---|---|
date | Sat, 02 Jun 2012 02:30:49 +0000 |
parents | f0b5a6f8fded |
children |
comparison
equal
deleted
inserted
replaced
32818:01ff09d4a463 | 32819:2c6510167895 |
---|---|
40 /* MsnSlpLink *slplink; */ | 40 /* MsnSlpLink *slplink; */ |
41 char *content; | 41 char *content; |
42 | 42 |
43 purple_debug_info("msn", "xfer_init\n"); | 43 purple_debug_info("msn", "xfer_init\n"); |
44 | 44 |
45 slpcall = xfer->data; | 45 slpcall = purple_xfer_get_protocol_data(xfer); |
46 | 46 |
47 /* Send Ok */ | 47 /* Send Ok */ |
48 content = g_strdup_printf("SessionID: %lu\r\n\r\n", | 48 content = g_strdup_printf("SessionID: %lu\r\n\r\n", |
49 slpcall->session_id); | 49 slpcall->session_id); |
50 | 50 |
60 { | 60 { |
61 MsnSlpCall *slpcall; | 61 MsnSlpCall *slpcall; |
62 char *content; | 62 char *content; |
63 | 63 |
64 g_return_if_fail(xfer != NULL); | 64 g_return_if_fail(xfer != NULL); |
65 g_return_if_fail(xfer->data != NULL); | 65 |
66 | 66 slpcall = purple_xfer_get_protocol_data(xfer); |
67 slpcall = xfer->data; | 67 g_return_if_fail(slpcall != NULL); |
68 | 68 |
69 if (purple_xfer_get_status(xfer) == PURPLE_XFER_STATUS_CANCEL_LOCAL) | 69 if (purple_xfer_get_status(xfer) == PURPLE_XFER_STATUS_CANCEL_LOCAL) |
70 { | 70 { |
71 if (slpcall->started) | 71 if (slpcall->started) |
72 { | 72 { |
100 g_return_val_if_fail(data != NULL, -1); | 100 g_return_val_if_fail(data != NULL, -1); |
101 g_return_val_if_fail(len > 0, -1); | 101 g_return_val_if_fail(len > 0, -1); |
102 | 102 |
103 g_return_val_if_fail(purple_xfer_get_type(xfer) == PURPLE_XFER_SEND, -1); | 103 g_return_val_if_fail(purple_xfer_get_type(xfer) == PURPLE_XFER_SEND, -1); |
104 | 104 |
105 slpcall = xfer->data; | 105 slpcall = purple_xfer_get_protocol_data(xfer); |
106 /* Not sure I trust it'll be there */ | 106 /* Not sure I trust it'll be there */ |
107 g_return_val_if_fail(slpcall != NULL, -1); | 107 g_return_val_if_fail(slpcall != NULL, -1); |
108 | 108 |
109 g_return_val_if_fail(slpcall->xfer_msg != NULL, -1); | 109 g_return_val_if_fail(slpcall->xfer_msg != NULL, -1); |
110 | 110 |
124 g_return_val_if_fail(xfer != NULL, -1); | 124 g_return_val_if_fail(xfer != NULL, -1); |
125 g_return_val_if_fail(data != NULL, -1); | 125 g_return_val_if_fail(data != NULL, -1); |
126 | 126 |
127 g_return_val_if_fail(purple_xfer_get_type(xfer) == PURPLE_XFER_RECEIVE, -1); | 127 g_return_val_if_fail(purple_xfer_get_type(xfer) == PURPLE_XFER_RECEIVE, -1); |
128 | 128 |
129 slpcall = xfer->data; | 129 slpcall = purple_xfer_get_protocol_data(xfer); |
130 /* Not sure I trust it'll be there */ | 130 /* Not sure I trust it'll be there */ |
131 g_return_val_if_fail(slpcall != NULL, -1); | 131 g_return_val_if_fail(slpcall != NULL, -1); |
132 | 132 |
133 /* Just pass up the whole GByteArray. We'll make another. */ | 133 /* Just pass up the whole GByteArray. We'll make another. */ |
134 *data = slpcall->u.incoming_data->data; | 134 *data = slpcall->u.incoming_data->data; |
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 { |