Mercurial > pidgin.yaz
comparison src/protocols/msn/msg.c @ 7604:43803965ef45
[gaim-migrate @ 8227]
Committing what I have of MSN. It's disabled.
committer: Tailor Script <tailor@pidgin.im>
author | Christian Hammond <chipx86@chipx86.com> |
---|---|
date | Sun, 23 Nov 2003 03:23:02 +0000 |
parents | 582f764b26f6 |
children | 59f9508c9a31 |
comparison
equal
deleted
inserted
replaced
7603:dfebaa14bf67 | 7604:43803965ef45 |
---|---|
132 | 132 |
133 MsnMessage * | 133 MsnMessage * |
134 msn_message_new_from_str(MsnSession *session, const char *str) | 134 msn_message_new_from_str(MsnSession *session, const char *str) |
135 { | 135 { |
136 MsnMessage *msg; | 136 MsnMessage *msg; |
137 char *command_header; | |
137 char *tmp_base, *msg_base, *tmp, *field1, *field2, *c; | 138 char *tmp_base, *msg_base, *tmp, *field1, *field2, *c; |
139 const char *c2; | |
138 | 140 |
139 g_return_val_if_fail(str != NULL, NULL); | 141 g_return_val_if_fail(str != NULL, NULL); |
140 g_return_val_if_fail(!g_ascii_strncasecmp(str, "MSG", 3), NULL); | 142 g_return_val_if_fail(!g_ascii_strncasecmp(str, "MSG", 3), NULL); |
141 | 143 |
142 msg = msn_message_new(); | 144 msg = msn_message_new(); |
144 /* Clear out the old stuff. */ | 146 /* Clear out the old stuff. */ |
145 msn_message_set_attr(msg, "User-Agent", NULL); | 147 msn_message_set_attr(msg, "User-Agent", NULL); |
146 msn_message_set_content_type(msg, NULL); | 148 msn_message_set_content_type(msg, NULL); |
147 msn_message_set_charset(msg, NULL); | 149 msn_message_set_charset(msg, NULL); |
148 | 150 |
149 tmp_base = tmp = g_strdup(str); | 151 /* |
150 | 152 * We need to grab the header and then the size, since this might have |
151 GET_NEXT(tmp); /* Skip MSG */ | 153 * binary data. |
152 field1 = tmp; | 154 */ |
153 | 155 if ((c2 = strchr(str, '\r')) != NULL) |
154 GET_NEXT(tmp); /* Skip the passport or TID */ | 156 { |
155 field2 = tmp; | 157 tmp = command_header = g_strndup(str, (c2 - str)); |
156 | 158 |
157 GET_NEXT(tmp); /* Skip the username or flag */ | 159 GET_NEXT(tmp); /* Skip MSG */ |
158 msg->size = atoi(tmp); | 160 field1 = tmp; |
159 | 161 |
160 #if 0 | 162 GET_NEXT(tmp); /* Skip the passport or TID */ |
161 /* Put this back when we intelligently handle binary strings. */ | 163 field2 = tmp; |
162 if (msg->size != strlen(strchr(str, '\n') + 1)) { | 164 |
163 gaim_debug(GAIM_DEBUG_ERROR, "msn", | 165 GET_NEXT(tmp); /* Skip the username or flag */ |
164 "Incoming message size (%d) and string length (%d) " | 166 msg->size = atoi(tmp); |
165 "do not match!\n", msg->size, strlen(str)); | 167 } |
166 } | 168 else |
167 #endif | 169 { |
170 /* Kind of screwed :) This won't happen. */ | |
171 msn_message_destroy(msg); | |
172 | |
173 return NULL; | |
174 } | |
175 | |
176 tmp_base = g_malloc(msg->size + 1); | |
177 memcpy(tmp_base, c2 + 2, msg->size); | |
178 tmp_base[msg->size] = '\0'; | |
179 | |
180 tmp = tmp_base; | |
168 | 181 |
169 /* | 182 /* |
170 * We're going to make sure this is incoming by checking field1. | 183 * We're going to make sure this is incoming by checking field1. |
171 * If it has any non-numbers in it, it's incoming. Otherwise, outgoing. | 184 * If it has any non-numbers in it, it's incoming. Otherwise, outgoing. |
172 */ | 185 */ |
234 if (!strcmp(msn_message_get_content_type(msg), "application/x-msnmsgrp2p")) | 247 if (!strcmp(msn_message_get_content_type(msg), "application/x-msnmsgrp2p")) |
235 { | 248 { |
236 char header[48]; | 249 char header[48]; |
237 char footer[4]; | 250 char footer[4]; |
238 size_t body_len; | 251 size_t body_len; |
252 char *tmp2; | |
239 | 253 |
240 msg->msnslp_message = TRUE; | 254 msg->msnslp_message = TRUE; |
241 | 255 |
242 memcpy(header, tmp, 48); | 256 memcpy(header, tmp, 48); |
243 | 257 |
244 tmp += 48; | 258 tmp += 48; |
245 | 259 |
246 body_len = msg->size - (tmp - msg_base); | 260 body_len = msg->size - (tmp - tmp_base) - 5; |
247 gaim_debug_misc("msn", "Body len = %d\n", body_len); | |
248 msg->body = g_malloc(body_len + 1); | 261 msg->body = g_malloc(body_len + 1); |
249 | 262 |
250 if (body_len > 0) | 263 if (body_len > 0) |
251 memcpy(msg->body, tmp, body_len); | 264 memcpy(msg->body, tmp, body_len); |
252 | 265 |
254 | 267 |
255 tmp++; | 268 tmp++; |
256 | 269 |
257 memcpy(footer, tmp, 4); | 270 memcpy(footer, tmp, 4); |
258 | 271 |
272 tmp += 4; | |
273 | |
259 /* Import the header. */ | 274 /* Import the header. */ |
260 msg->msnslp_header.session_id = msn_get32(tmp); tmp += 4; | 275 tmp2 = header; |
261 msg->msnslp_header.id = msn_get32(tmp); tmp += 4; | 276 msg->msnslp_header.session_id = msn_get32(tmp2); tmp2 += 4; |
262 msg->msnslp_header.offset_1 = msn_get32(tmp); tmp += 4; | 277 msg->msnslp_header.id = msn_get32(tmp2); tmp2 += 4; |
263 msg->msnslp_header.offset_2 = msn_get32(tmp); tmp += 4; | 278 msg->msnslp_header.offset_1 = msn_get32(tmp2); tmp2 += 4; |
264 msg->msnslp_header.total_size_1 = msn_get32(tmp); tmp += 4; | 279 msg->msnslp_header.offset_2 = msn_get32(tmp2); tmp2 += 4; |
265 msg->msnslp_header.total_size_2 = msn_get32(tmp); tmp += 4; | 280 msg->msnslp_header.total_size_1 = msn_get32(tmp2); tmp2 += 4; |
266 msg->msnslp_header.length = msn_get32(tmp); tmp += 4; | 281 msg->msnslp_header.total_size_2 = msn_get32(tmp2); tmp2 += 4; |
267 msg->msnslp_header.flags = msn_get32(tmp); tmp += 4; | 282 msg->msnslp_header.length = msn_get32(tmp2); tmp2 += 4; |
268 msg->msnslp_header.ack_session_id = msn_get32(tmp); tmp += 4; | 283 msg->msnslp_header.flags = msn_get32(tmp2); tmp2 += 4; |
269 msg->msnslp_header.ack_unique_id = msn_get32(tmp); tmp += 4; | 284 msg->msnslp_header.ack_session_id = msn_get32(tmp2); tmp2 += 4; |
270 msg->msnslp_header.ack_length_1 = msn_get32(tmp); tmp += 4; | 285 msg->msnslp_header.ack_unique_id = msn_get32(tmp2); tmp2 += 4; |
271 msg->msnslp_header.ack_length_2 = msn_get32(tmp); tmp += 4; | 286 msg->msnslp_header.ack_length_1 = msn_get32(tmp2); tmp2 += 4; |
287 msg->msnslp_header.ack_length_2 = msn_get32(tmp2); tmp2 += 4; | |
272 | 288 |
273 /* Convert to the right endianness */ | 289 /* Convert to the right endianness */ |
274 msg->msnslp_header.session_id = ntohl(msg->msnslp_header.session_id); | 290 msg->msnslp_header.session_id = ntohl(msg->msnslp_header.session_id); |
275 msg->msnslp_header.id = ntohl(msg->msnslp_header.id); | 291 msg->msnslp_header.id = ntohl(msg->msnslp_header.id); |
276 msg->msnslp_header.length = ntohl(msg->msnslp_header.length); | 292 msg->msnslp_header.length = ntohl(msg->msnslp_header.length); |
290 else | 306 else |
291 { | 307 { |
292 msn_message_set_body(msg, tmp); | 308 msn_message_set_body(msg, tmp); |
293 } | 309 } |
294 | 310 |
311 g_free(command_header); | |
295 g_free(tmp_base); | 312 g_free(tmp_base); |
296 | 313 |
297 /* Done! */ | 314 /* Done! */ |
298 | 315 |
299 return msg; | 316 return msg; |
474 size_t bin_len; | 491 size_t bin_len; |
475 const void *body = msn_message_get_bin_data(msg, &bin_len); | 492 const void *body = msn_message_get_bin_data(msg, &bin_len); |
476 | 493 |
477 if (body != NULL) | 494 if (body != NULL) |
478 { | 495 { |
479 memcpy(c, body, msg->size - (c - msg_start)); | 496 memcpy(c, body, bin_len); |
480 | 497 |
481 c += bin_len; | 498 c += bin_len; |
482 } | 499 } |
483 } | 500 } |
484 else | 501 else |
624 size_t new_len; | 641 size_t new_len; |
625 | 642 |
626 g_return_if_fail(msg != NULL); | 643 g_return_if_fail(msg != NULL); |
627 | 644 |
628 if (msg->bin_content) | 645 if (msg->bin_content) |
646 { | |
629 msn_message_set_bin_data(msg, NULL, 0); | 647 msn_message_set_bin_data(msg, NULL, 0); |
648 return; | |
649 } | |
630 | 650 |
631 if (msg->body != NULL) { | 651 if (msg->body != NULL) { |
632 msg->size -= strlen(msg->body); | 652 msg->size -= strlen(msg->body); |
633 g_free(msg->body); | 653 g_free(msg->body); |
634 | 654 |