comparison src/protocols/msn/msnslp.c @ 8646:1e211dde3cae

[gaim-migrate @ 9398] Added a patch by shx to clean up the message-handling code and split the command stuff from it, among a few other things. Also, I fixed a crash in message parsing, which I think may close a couple bug reports. committer: Tailor Script <tailor@pidgin.im>
author Christian Hammond <chipx86@chipx86.com>
date Tue, 13 Apr 2004 04:08:22 +0000
parents 06f57183e29f
children f32ee2e97b37
comparison
equal deleted inserted replaced
8645:47f647dd2ac3 8646:1e211dde3cae
57 g_free(session); 57 g_free(session);
58 } 58 }
59 59
60 static void 60 static void
61 msn_slp_session_send_message(MsnSlpSession *slpsession, 61 msn_slp_session_send_message(MsnSlpSession *slpsession,
62 MsnMessage *source_msg, 62 const char *local_user, const char *remote_user,
63 MsnUser *local_user, MsnUser *remote_user,
64 const char *header, const char *branch, 63 const char *header, const char *branch,
65 int cseq, const char *call_id, 64 int cseq, const char *call_id,
66 const char *content) 65 const char *content)
67 { 66 {
68 MsnMessage *invite_msg; 67 MsnMessage *invite_msg;
70 69
71 g_return_if_fail(slpsession != NULL); 70 g_return_if_fail(slpsession != NULL);
72 g_return_if_fail(header != NULL); 71 g_return_if_fail(header != NULL);
73 g_return_if_fail(branch != NULL); 72 g_return_if_fail(branch != NULL);
74 g_return_if_fail(call_id != NULL); 73 g_return_if_fail(call_id != NULL);
75
76 if (source_msg != NULL)
77 {
78 if (msn_message_is_incoming(source_msg))
79 remote_user = msn_message_get_sender(source_msg);
80 else
81 remote_user = msn_message_get_receiver(source_msg);
82
83 local_user = slpsession->swboard->servconn->session->user;
84 }
85 74
86 if (branch == NULL) 75 if (branch == NULL)
87 branch = "null"; 76 branch = "null";
88 77
89 body = g_strdup_printf( 78 body = g_strdup_printf(
98 "Content-Length: %d\r\n" 87 "Content-Length: %d\r\n"
99 "\r\n" 88 "\r\n"
100 "%s" 89 "%s"
101 "\r\n\r\n", 90 "\r\n\r\n",
102 header, 91 header,
103 msn_user_get_passport(remote_user), 92 remote_user,
104 msn_user_get_passport(local_user), 93 local_user,
105 branch, cseq, call_id, 94 branch, cseq, call_id,
106 (content == NULL ? 0 : (int)strlen(content) + 5), 95 (content == NULL ? 0 : (int)strlen(content) + 5),
107 (content == NULL ? "" : content)); 96 (content == NULL ? "" : content));
108 97
109 gaim_debug_misc("msn", "Message = {%s}\n", body); 98 gaim_debug_misc("msn", "Message = {%s}\n", body);
110 99
111 invite_msg = msn_message_new_msnslp(); 100 invite_msg = msn_message_new_msnslp();
112 101
113 msn_message_set_sender(invite_msg, local_user);
114 msn_message_set_receiver(invite_msg, remote_user);
115
116 msn_message_set_body(invite_msg, body); 102 msn_message_set_body(invite_msg, body);
117 103
118 g_free(body); 104 g_free(body);
119 105
120 msn_slp_session_send_msg(slpsession, invite_msg); 106 msn_slp_session_send_msg(slpsession, invite_msg);
121 } 107 }
122 108
123 static gboolean 109 static gboolean
124 send_error_500(MsnSlpSession *slpsession, const char *call_id, MsnMessage *msg) 110 send_error_500(MsnSlpSession *slpsession, const char *call_id, MsnMessage *msg)
125 { 111 {
112 MsnUser *local_user;
113
126 g_return_val_if_fail(slpsession != NULL, TRUE); 114 g_return_val_if_fail(slpsession != NULL, TRUE);
127 g_return_val_if_fail(msg != NULL, TRUE); 115 g_return_val_if_fail(msg != NULL, TRUE);
128 116
129 msn_slp_session_send_message(slpsession, msg, NULL, NULL, 117 local_user = slpsession->swboard->servconn->session->user;
118
119 msn_slp_session_send_message(slpsession, msg->passport,
120 msn_user_get_passport(local_user),
130 "MSNSLP/1.0 500 Internal Error", 121 "MSNSLP/1.0 500 Internal Error",
131 slpsession->branch, 1, call_id, NULL); 122 slpsession->branch, 1, call_id, NULL);
132 123
133 return TRUE; 124 return TRUE;
134 } 125 }
144 len = fread(data, 1, 1200, slpsession->send_fp); 135 len = fread(data, 1, 1200, slpsession->send_fp);
145 136
146 slpsession->remaining_size -= len; 137 slpsession->remaining_size -= len;
147 138
148 msg = msn_message_new_msnslp(); 139 msg = msn_message_new_msnslp();
149 msn_message_set_sender(msg, slpsession->receiver);
150 msn_message_set_receiver(msg, slpsession->sender);
151 msn_message_set_bin_data(msg, data, len); 140 msn_message_set_bin_data(msg, data, len);
152 141
153 msn_slp_session_send_msg(slpsession, msg); 142 msn_slp_session_send_msg(slpsession, msg);
154 143
155 if (slpsession->remaining_size <= 0) 144 if (slpsession->remaining_size <= 0)
195 * In theory, if we received something while send_fp is non-NULL, 184 * In theory, if we received something while send_fp is non-NULL,
196 * but remaining_size is 0, then this is a data ack message. 185 * but remaining_size is 0, then this is a data ack message.
197 * 186 *
198 * Say BYE-BYE. 187 * Say BYE-BYE.
199 */ 188 */
189 MsnUser *local_user;
200 char *header; 190 char *header;
201 191
202 fclose(slpsession->send_fp); 192 fclose(slpsession->send_fp);
203 slpsession->send_fp = NULL; 193 slpsession->send_fp = NULL;
204 194
205 header = g_strdup_printf("BYE MSNMSGR:%s MSNSLP/1.0", 195 header = g_strdup_printf("BYE MSNMSGR:%s MSNSLP/1.0",
206 msn_user_get_passport(msn_message_get_sender(msg))); 196 msg->passport);
207 197
208 msn_slp_session_send_message(slpsession, msg, NULL, NULL, header, 198 local_user = slpsession->swboard->servconn->session->user;
199
200 msn_slp_session_send_message(slpsession, msg->passport,
201 msn_user_get_passport(local_user),
202 header,
209 "A0D624A6-6C0C-4283-A9E0-BC97B4B46D32", 203 "A0D624A6-6C0C-4283-A9E0-BC97B4B46D32",
210 0, slpsession->call_id, ""); 204 0, slpsession->call_id, "");
211 205
212 g_free(header); 206 g_free(header);
213 207
298 app_id = atoi(temp); 292 app_id = atoi(temp);
299 g_free(temp); 293 g_free(temp);
300 294
301 if (app_id == 1) 295 if (app_id == 1)
302 { 296 {
297 MsnSession *session;
303 MsnMessage *new_msg; 298 MsnMessage *new_msg;
299 MsnUser *local_user;
300 MsnUser *remote_user;
304 char *content; 301 char *content;
305 char nil_body[4]; 302 char nil_body[4];
306 struct stat st; 303 struct stat st;
307 304
308 /* Send the 200 OK message. */ 305 /* Send the 200 OK message. */
309 content = g_strdup_printf("SessionID: %d", session_id); 306 content = g_strdup_printf("SessionID: %d", session_id);
310 msn_slp_session_send_ack(slpsession, msg); 307 msn_slp_session_send_ack(slpsession, msg);
311 308
312 msn_slp_session_send_message(slpsession, msg, NULL, NULL, 309 session = slpsession->swboard->servconn->session;
310
311 local_user = session->user;
312
313 msn_slp_session_send_message(slpsession, msg->passport,
314 msn_user_get_passport(local_user),
313 "MSNSLP/1.0 200 OK", 315 "MSNSLP/1.0 200 OK",
314 branch, 1, call_id, content); 316 branch, 1, call_id, content);
315 317
316 g_free(content); 318 g_free(content);
317 319
318 /* Send the Data Preparation message. */ 320 /* Send the Data Preparation message. */
319 memset(nil_body, 0, sizeof(nil_body)); 321 memset(nil_body, 0, sizeof(nil_body));
320 322
321 slpsession->session_id = session_id; 323 slpsession->session_id = session_id;
322 slpsession->receiver = msn_message_get_sender(msg); 324
323 slpsession->sender = slpsession->swboard->servconn->session->user; 325 remote_user = msn_user_new(session, msg->passport, NULL);
326
327 slpsession->receiver = remote_user;
328 slpsession->sender = session->user;
324 329
325 new_msg = msn_message_new_msnslp(); 330 new_msg = msn_message_new_msnslp();
326 msn_message_set_sender(new_msg, slpsession->sender);
327 msn_message_set_receiver(new_msg, slpsession->receiver);
328 msn_message_set_bin_data(new_msg, nil_body, 4); 331 msn_message_set_bin_data(new_msg, nil_body, 4);
329 new_msg->msnslp_footer.app_id = 1; 332 new_msg->msnslp_footer.app_id = 1;
330 333
331 msn_slp_session_send_msg(slpsession, new_msg); 334 msn_slp_session_send_msg(slpsession, new_msg);
332 335
530 g_free(msnobj_base64); 533 g_free(msnobj_base64);
531 534
532 header = g_strdup_printf("INVITE MSNMSGR:%s MSNSLP/1.0", 535 header = g_strdup_printf("INVITE MSNMSGR:%s MSNSLP/1.0",
533 msn_user_get_passport(remote_user)); 536 msn_user_get_passport(remote_user));
534 537
535 msn_slp_session_send_message(slpsession, NULL, local_user, remote_user, 538 msn_slp_session_send_message(slpsession,
539 msn_user_get_passport(local_user),
540 msn_user_get_passport(remote_user),
536 header, slpsession->branch, 0, 541 header, slpsession->branch, 0,
537 slpsession->call_id, content); 542 slpsession->call_id, content);
538 543
539 g_free(header); 544 g_free(header);
540 g_free(content); 545 g_free(content);