Mercurial > pidgin
comparison plugins/msn/msn.c @ 1282:577b71ae4e2a
[gaim-migrate @ 1292]
Lalala
committer: Tailor Script <tailor@pidgin.im>
author | Rob Flynn <gaim@robflynn.com> |
---|---|
date | Fri, 15 Dec 2000 00:45:25 +0000 |
parents | 8947583de4a1 |
children | 87ad345a6d4f |
comparison
equal
deleted
inserted
replaced
1281:83d8b2078f4c | 1282:577b71ae4e2a |
---|---|
76 int fd; | 76 int fd; |
77 }; | 77 }; |
78 | 78 |
79 void msn_handler(gpointer data, gint source, GdkInputCondition condition); | 79 void msn_handler(gpointer data, gint source, GdkInputCondition condition); |
80 | 80 |
81 GSList * msn_connections = NULL; | 81 GSList *msn_connections = NULL; |
82 | 82 |
83 static char *msn_name() { | 83 static char *msn_name() |
84 { | |
84 return "MSN"; | 85 return "MSN"; |
85 } | 86 } |
86 | 87 |
87 char *name() { | 88 char *name() |
89 { | |
88 return "MSN"; | 90 return "MSN"; |
89 } | 91 } |
90 | 92 |
91 char *description() { | 93 char *description() |
94 { | |
92 return "Allows gaim to use the MSN protocol. For some reason, this frightens me."; | 95 return "Allows gaim to use the MSN protocol. For some reason, this frightens me."; |
93 } | 96 } |
94 | 97 |
95 struct msn_conn *find_msn_conn_by_user(gchar *user) { | 98 struct msn_conn *find_msn_conn_by_user(gchar * user) |
99 { | |
96 struct msn_conn *mc; | 100 struct msn_conn *mc; |
97 GSList *conns = msn_connections; | 101 GSList *conns = msn_connections; |
98 | 102 |
99 while (conns) { | 103 while (conns) { |
100 mc = (struct msn_conn *)conns->data; | 104 mc = (struct msn_conn *)conns->data; |
109 } | 113 } |
110 | 114 |
111 return NULL; | 115 return NULL; |
112 } | 116 } |
113 | 117 |
114 void msn_read_line(char *buf, int fd) { | 118 void msn_read_line(char *buf, int fd) |
119 { | |
115 | 120 |
116 int status; | 121 int status; |
117 char c; | 122 char c; |
118 int i = 0; | 123 int i = 0; |
119 | 124 |
120 do { | 125 do { |
121 status = recv(fd, &c, 1, 0); | 126 status = recv(fd, &c, 1, 0); |
122 | 127 |
123 if (!status) | 128 if (!status) |
124 return; | 129 return; |
132 | 137 |
133 /* I'm a bastard again :-) */ | 138 /* I'm a bastard again :-) */ |
134 printf("MSN: %s\n", buf); | 139 printf("MSN: %s\n", buf); |
135 } | 140 } |
136 | 141 |
137 int msn_connect(char *server, int port) { | 142 int msn_connect(char *server, int port) |
143 { | |
138 int fd; | 144 int fd; |
139 struct hostent *host; | 145 struct hostent *host; |
140 struct sockaddr_in site; | 146 struct sockaddr_in site; |
141 | 147 |
142 printf("Connecting to '%s' on '%d'\n", server, port); | 148 printf("Connecting to '%s' on '%d'\n", server, port); |
159 } | 165 } |
160 | 166 |
161 return fd; | 167 return fd; |
162 } | 168 } |
163 | 169 |
164 static void msn_add_buddy(struct gaim_connection *gc, char *who) { | 170 static void msn_add_buddy(struct gaim_connection *gc, char *who) |
171 { | |
165 struct msn_data *mdata = (struct msn_data *)gc->proto_data; | 172 struct msn_data *mdata = (struct msn_data *)gc->proto_data; |
166 time_t trId = time((time_t *)NULL); | 173 time_t trId = time((time_t *) NULL); |
167 gchar buf[4096]; | 174 gchar buf[4096]; |
168 | 175 |
169 g_snprintf(buf, 4096, "ADD %d FL %s %s\n", trId, who, who); | 176 g_snprintf(buf, 4096, "ADD %d FL %s %s\n", trId, who, who); |
170 write(mdata->fd, buf, strlen(buf)); | 177 write(mdata->fd, buf, strlen(buf)); |
171 } | 178 } |
172 | 179 |
173 static void msn_rem_permit(struct gaim_connection *gc, char *who) { | 180 static void msn_rem_permit(struct gaim_connection *gc, char *who) |
181 { | |
174 struct msn_data *mdata = (struct msn_data *)gc->proto_data; | 182 struct msn_data *mdata = (struct msn_data *)gc->proto_data; |
175 time_t trId = time((time_t *)NULL); | 183 time_t trId = time((time_t *) NULL); |
176 gchar buf[4096]; | 184 gchar buf[4096]; |
177 | 185 |
178 g_snprintf(buf, 4096, "REM %d AL %s %s\n", trId, who, who); | 186 g_snprintf(buf, 4096, "REM %d AL %s %s\n", trId, who, who); |
179 write(mdata->fd, buf, strlen(buf)); | 187 write(mdata->fd, buf, strlen(buf)); |
180 } | 188 } |
181 | 189 |
182 static void msn_add_permit(struct gaim_connection *gc, char *who) { | 190 static void msn_add_permit(struct gaim_connection *gc, char *who) |
191 { | |
183 struct msn_data *mdata = (struct msn_data *)gc->proto_data; | 192 struct msn_data *mdata = (struct msn_data *)gc->proto_data; |
184 time_t trId = time((time_t *)NULL); | 193 time_t trId = time((time_t *) NULL); |
185 gchar buf[4096]; | 194 gchar buf[4096]; |
186 | 195 |
187 g_snprintf(buf, 4096, "ADD %d AL %s %s\n", trId, who, who); | 196 g_snprintf(buf, 4096, "ADD %d AL %s %s\n", trId, who, who); |
188 write(mdata->fd, buf, strlen(buf)); | 197 write(mdata->fd, buf, strlen(buf)); |
189 } | 198 } |
190 | 199 |
191 static void msn_rem_deny(struct gaim_connection *gc, char *who) { | 200 static void msn_rem_deny(struct gaim_connection *gc, char *who) |
201 { | |
192 struct msn_data *mdata = (struct msn_data *)gc->proto_data; | 202 struct msn_data *mdata = (struct msn_data *)gc->proto_data; |
193 time_t trId = time((time_t *)NULL); | 203 time_t trId = time((time_t *) NULL); |
194 gchar buf[4096]; | 204 gchar buf[4096]; |
195 | 205 |
196 g_snprintf(buf, 4096, "REM %d BL %s %s\n", trId, who, who); | 206 g_snprintf(buf, 4096, "REM %d BL %s %s\n", trId, who, who); |
197 write(mdata->fd, buf, strlen(buf)); | 207 write(mdata->fd, buf, strlen(buf)); |
198 } | 208 } |
199 | 209 |
200 static void msn_add_deny(struct gaim_connection *gc, char *who) { | 210 static void msn_add_deny(struct gaim_connection *gc, char *who) |
211 { | |
201 struct msn_data *mdata = (struct msn_data *)gc->proto_data; | 212 struct msn_data *mdata = (struct msn_data *)gc->proto_data; |
202 time_t trId = time((time_t *)NULL); | 213 time_t trId = time((time_t *) NULL); |
203 gchar buf[4096]; | 214 gchar buf[4096]; |
204 | 215 |
205 g_snprintf(buf, 4096, "ADD %d BL %s %s\n", trId, who, who); | 216 g_snprintf(buf, 4096, "ADD %d BL %s %s\n", trId, who, who); |
206 write(mdata->fd, buf, strlen(buf)); | 217 write(mdata->fd, buf, strlen(buf)); |
207 } | 218 } |
208 | 219 |
209 static void msn_remove_buddy(struct gaim_connection *gc, char *who) { | 220 static void msn_remove_buddy(struct gaim_connection *gc, char *who) |
221 { | |
210 struct msn_data *mdata = (struct msn_data *)gc->proto_data; | 222 struct msn_data *mdata = (struct msn_data *)gc->proto_data; |
211 time_t trId = time((time_t *)NULL); | 223 time_t trId = time((time_t *) NULL); |
212 gchar buf[4096]; | 224 gchar buf[4096]; |
213 | 225 |
214 g_snprintf(buf, 4096, "REM %d FL %s\n", trId, who); | 226 g_snprintf(buf, 4096, "REM %d FL %s\n", trId, who); |
215 write(mdata->fd, buf, strlen(buf)); | 227 write(mdata->fd, buf, strlen(buf)); |
216 } | 228 } |
217 | 229 |
218 void msn_accept_add_permit (gpointer w, struct msn_ask_add_permit *ap ) { | 230 void msn_accept_add_permit(gpointer w, struct msn_ask_add_permit *ap) |
231 { | |
219 gchar buf[4096]; | 232 gchar buf[4096]; |
220 | 233 |
221 msn_add_permit(ap->gc, ap->user); | 234 msn_add_permit(ap->gc, ap->user); |
222 } | 235 } |
223 | 236 |
224 void msn_cancel_add_permit (gpointer w, struct msn_ask_add_permit *ap ) { | 237 void msn_cancel_add_permit(gpointer w, struct msn_ask_add_permit *ap) |
225 | 238 { |
239 | |
226 g_free(ap->user); | 240 g_free(ap->user); |
227 g_free(ap->friendly); | 241 g_free(ap->friendly); |
228 g_free(ap); | 242 g_free(ap); |
229 } | 243 } |
230 | 244 |
231 void msn_callback (struct gaim_connection * gc, gint fd) { | 245 void msn_callback(struct gaim_connection *gc, gint fd) |
246 { | |
232 struct msn_data *mdata; | 247 struct msn_data *mdata; |
233 char c; | 248 char c; |
234 int i = 0; | 249 int i = 0; |
235 int status; | 250 int status; |
236 gchar buf[4096]; | 251 gchar buf[4096]; |
237 gchar **resps; | 252 gchar **resps; |
238 | 253 |
239 mdata = (struct msn_data *)gc->proto_data; | 254 mdata = (struct msn_data *)gc->proto_data; |
240 | 255 |
241 do { | 256 do { |
242 /* Read data from whatever connection our inpa | 257 /* Read data from whatever connection our inpa |
243 * refered us from */ | 258 * refered us from */ |
244 status = recv(fd, &c, 1,0); | 259 status = recv(fd, &c, 1, 0); |
245 | 260 |
246 if (!status) | 261 if (!status) |
247 return; | 262 return; |
248 | 263 |
249 buf[i] = c; | 264 buf[i] = c; |
250 i++; | 265 i++; |
251 } while (c != '\n'); | 266 } while (c != '\n'); |
252 | 267 |
253 buf[i] = '\0'; | 268 buf[i] = '\0'; |
254 | 269 |
255 g_strchomp(buf); | 270 g_strchomp(buf); |
256 | 271 |
257 printf("MSN: %s\n", buf); | 272 printf("MSN: %s\n", buf); |
258 | 273 |
259 if (strlen(buf) == 0) { return; } | 274 if (strlen(buf) == 0) { |
260 | 275 return; |
276 } | |
277 | |
261 resps = g_strsplit(buf, " ", 0); | 278 resps = g_strsplit(buf, " ", 0); |
262 | 279 |
263 /* See if someone is bumping us */ | 280 /* See if someone is bumping us */ |
264 if (strcasecmp(resps[0], "BYE") == 0) { | 281 if (strcasecmp(resps[0], "BYE") == 0) { |
265 struct msn_conn *mc; | 282 struct msn_conn *mc; |
266 GSList * conns = msn_connections; | 283 GSList *conns = msn_connections; |
267 | 284 |
268 /* Yup. Let's find their convo and kill it */ | 285 /* Yup. Let's find their convo and kill it */ |
269 | 286 |
270 mc = find_msn_conn_by_user(resps[1]); | 287 mc = find_msn_conn_by_user(resps[1]); |
271 | 288 |
272 /* If we have the convo, remove it */ | 289 /* If we have the convo, remove it */ |
285 g_strfreev(resps); | 302 g_strfreev(resps); |
286 return; | 303 return; |
287 } | 304 } |
288 | 305 |
289 if (strcasecmp(resps[0], "ADD") == 0) { | 306 if (strcasecmp(resps[0], "ADD") == 0) { |
290 | 307 |
291 if (strcasecmp(resps[2], "RL") == 0) { | 308 if (strcasecmp(resps[2], "RL") == 0) { |
292 gchar buf[4096]; | 309 gchar buf[4096]; |
293 struct msn_ask_add_permit *ap = g_new0(struct msn_ask_add_permit, 1); | 310 struct msn_ask_add_permit *ap = g_new0(struct msn_ask_add_permit, 1); |
294 | 311 |
295 g_snprintf(buf, 4096, "The user %s (%s) wants to add you to their buddylist.", resps[4], resps[5]); | 312 g_snprintf(buf, 4096, "The user %s (%s) wants to add you to their buddylist.", |
313 resps[4], resps[5]); | |
296 | 314 |
297 ap->user = g_strdup(resps[4]); | 315 ap->user = g_strdup(resps[4]); |
298 ap->friendly = g_strdup(resps[5]); | 316 ap->friendly = g_strdup(resps[5]); |
299 ap->gc = gc; | 317 ap->gc = gc; |
300 | 318 |
301 do_ask_dialog(buf, ap, (GtkFunction)msn_accept_add_permit, (GtkFunction)msn_cancel_add_permit); | 319 do_ask_dialog(buf, ap, (GtkFunction) msn_accept_add_permit, |
320 (GtkFunction) msn_cancel_add_permit); | |
302 } | 321 } |
303 | 322 |
304 g_strfreev(resps); | 323 g_strfreev(resps); |
305 return; | 324 return; |
306 } | 325 } |
307 | 326 |
308 if (strcasecmp(resps[0], "REM") == 0) { | 327 if (strcasecmp(resps[0], "REM") == 0) { |
309 | 328 |
310 if (strcasecmp(resps[2], "RL") == 0) { | 329 if (strcasecmp(resps[2], "RL") == 0) { |
311 msn_rem_permit(gc, resps[4]); | 330 msn_rem_permit(gc, resps[4]); |
312 } | 331 } |
313 | 332 |
314 g_strfreev(resps); | 333 g_strfreev(resps); |
315 return; | 334 return; |
316 } | 335 } |
317 | 336 |
318 if (strcasecmp(resps[0], "FLN") == 0) { | 337 if (strcasecmp(resps[0], "FLN") == 0) { |
319 serv_got_update(gc, resps[1], 0, 0, 0, 0, MSN_OFFLINE, 0); | 338 serv_got_update(gc, resps[1], 0, 0, 0, 0, MSN_OFFLINE, 0); |
320 } | 339 } |
321 | 340 |
322 if (strcasecmp(resps[0], "ILN") == 0) { | 341 if (strcasecmp(resps[0], "ILN") == 0) { |
341 | 360 |
342 serv_got_update(gc, resps[3], 1, 0, 0, 0, status, 0); | 361 serv_got_update(gc, resps[3], 1, 0, 0, 0, status, 0); |
343 | 362 |
344 g_strfreev(resps); | 363 g_strfreev(resps); |
345 return; | 364 return; |
346 | 365 |
347 } | 366 } |
348 | 367 |
349 /* Check buddy update status */ | 368 /* Check buddy update status */ |
350 if (strcasecmp(resps[0], "NLN") == 0) { | 369 if (strcasecmp(resps[0], "NLN") == 0) { |
351 /* FIXME: We currently dont care if they are busy, | 370 /* FIXME: We currently dont care if they are busy, |
352 * idle, brb, away, phone, our out to lunch. This will | 371 * idle, brb, away, phone, our out to lunch. This will |
353 * be supported eventually (BSY,IDL,BRB,AWY,PHN,LUN) | 372 * be supported eventually (BSY,IDL,BRB,AWY,PHN,LUN) |
354 * respectively */ | 373 * respectively */ |
355 | 374 |
356 serv_got_update(gc, resps[2], 1, 0, 0, 0, MSN_ONLINE, 0); | 375 serv_got_update(gc, resps[2], 1, 0, 0, 0, MSN_ONLINE, 0); |
357 } | 376 } |
358 | 377 |
359 /* Check to see if we have an incoming buddylist */ | 378 /* Check to see if we have an incoming buddylist */ |
360 if (strcasecmp(resps[0], "LST") == 0) { | 379 if (strcasecmp(resps[0], "LST") == 0) { |
361 /* Check to see if there are any buddies in the list */ | 380 /* Check to see if there are any buddies in the list */ |
362 if (atoi(resps[5]) == 0) { | 381 if (atoi(resps[5]) == 0) { |
363 /* No buddies */ | 382 /* No buddies */ |
364 g_strfreev(resps); | 383 g_strfreev(resps); |
365 return; | 384 return; |
374 b = find_buddy(gc, resps[6]); | 393 b = find_buddy(gc, resps[6]); |
375 | 394 |
376 if (!b) | 395 if (!b) |
377 add_buddy(gc, "Buddies", resps[6], resps[6]); | 396 add_buddy(gc, "Buddies", resps[6], resps[6]); |
378 } | 397 } |
379 | 398 |
380 g_strfreev(resps); | 399 g_strfreev(resps); |
381 return; | 400 return; |
382 } | 401 } |
383 | 402 |
384 /* Check to see if we got a message request */ | 403 /* Check to see if we got a message request */ |
385 if (strcasecmp(resps[0], "MSG") == 0) { | 404 if (strcasecmp(resps[0], "MSG") == 0) { |
386 gchar *message; | 405 gchar *message; |
387 gchar *buf2; | 406 gchar *buf2; |
388 int size; | 407 int size; |
389 int status; | 408 int status; |
390 | 409 |
391 if (strcasecmp("hotmail", resps[1]) == 0) { | 410 if (strcasecmp("hotmail", resps[1]) == 0) { |
392 /* We want to ignore these. We can parse them | 411 /* We want to ignore these. We can parse them |
393 * eventually if we ever plan on doing anything | 412 * eventually if we ever plan on doing anything |
394 * with them */ | 413 * with them */ |
395 g_strfreev(resps); | 414 g_strfreev(resps); |
396 return; | 415 return; |
397 } | 416 } |
398 | 417 |
399 /* Determine our message size */ | 418 /* Determine our message size */ |
400 size = atoi(resps[3]); | 419 size = atoi(resps[3]); |
401 | 420 |
402 buf2 = (gchar *)g_malloc(sizeof(gchar) * (size+1)); | 421 buf2 = (gchar *) g_malloc(sizeof(gchar) * (size + 1)); |
403 status = recv(fd, buf2, size, 0); | 422 status = recv(fd, buf2, size, 0); |
404 buf2[size] = 0; | 423 buf2[size] = 0; |
405 | 424 |
406 /* Looks like we got the message. If it's blank, let's bail */ | 425 /* Looks like we got the message. If it's blank, let's bail */ |
407 if (strcasecmp(strstr(buf2, "\r\n\r\n")+4, "\r\n") == 0) { | 426 if (strcasecmp(strstr(buf2, "\r\n\r\n") + 4, "\r\n") == 0) { |
408 g_free(buf2); | 427 g_free(buf2); |
409 g_strfreev(resps); | 428 g_strfreev(resps); |
410 return; | 429 return; |
411 } | 430 } |
412 | 431 |
413 serv_got_im(gc, resps[1], strstr(buf2, "\r\n\r\n")+4, 0); | 432 serv_got_im(gc, resps[1], strstr(buf2, "\r\n\r\n") + 4, 0); |
414 | 433 |
415 g_free(buf2); | 434 g_free(buf2); |
416 g_strfreev(resps); | 435 g_strfreev(resps); |
417 return; | 436 return; |
418 } | 437 } |
419 | 438 |
420 | 439 |
421 /* Check to see if we got a ring request */ | 440 /* Check to see if we got a ring request */ |
422 if (strcasecmp(resps[0], "RNG") == 0) { | 441 if (strcasecmp(resps[0], "RNG") == 0) { |
423 gchar **address; | 442 gchar **address; |
424 struct msn_conn *mc = g_new0(struct msn_conn, 1); | 443 struct msn_conn *mc = g_new0(struct msn_conn, 1); |
434 } | 453 } |
435 | 454 |
436 mc->user = g_strdup(resps[5]); | 455 mc->user = g_strdup(resps[5]); |
437 | 456 |
438 mc->inpa = gdk_input_add(mc->fd, GDK_INPUT_READ, msn_handler, gc); | 457 mc->inpa = gdk_input_add(mc->fd, GDK_INPUT_READ, msn_handler, gc); |
439 | 458 |
440 g_snprintf(buf, 4096, "ANS 1 %s %s %s\n", gc->username, resps[4], resps[1]); | 459 g_snprintf(buf, 4096, "ANS 1 %s %s %s\n", gc->username, resps[4], resps[1]); |
441 write(mc->fd, buf, strlen(buf)); | 460 write(mc->fd, buf, strlen(buf)); |
442 | 461 |
443 msn_connections = g_slist_append(msn_connections, mc); | 462 msn_connections = g_slist_append(msn_connections, mc); |
444 | 463 |
450 g_strfreev(resps); | 469 g_strfreev(resps); |
451 | 470 |
452 } | 471 } |
453 | 472 |
454 | 473 |
455 void msn_handler(gpointer data, gint source, GdkInputCondition condition) { | 474 void msn_handler(gpointer data, gint source, GdkInputCondition condition) |
475 { | |
456 msn_callback(data, source); | 476 msn_callback(data, source); |
457 } | 477 } |
458 | 478 |
459 void msn_login(struct aim_user *user) { | 479 void msn_login(struct aim_user *user) |
460 time_t trId = time((time_t *)NULL); | 480 { |
481 time_t trId = time((time_t *) NULL); | |
461 char buf[4096]; | 482 char buf[4096]; |
462 char buf2[4096]; | 483 char buf2[4096]; |
463 | 484 |
464 struct gaim_connection *gc = new_gaim_conn(user); | 485 struct gaim_connection *gc = new_gaim_conn(user); |
465 struct msn_data *mdata = gc->proto_data = g_new0(struct msn_data, 1); | 486 struct msn_data *mdata = gc->proto_data = g_new0(struct msn_data, 1); |
466 char c; | 487 char c; |
467 int i; | 488 int i; |
468 int status; | 489 int status; |
471 md5_byte_t di[16]; | 492 md5_byte_t di[16]; |
472 int x; | 493 int x; |
473 | 494 |
474 gchar **results; | 495 gchar **results; |
475 | 496 |
476 g_snprintf(mdata->protocol, strlen("MSNP2")+1, "MSNP2"); | 497 g_snprintf(mdata->protocol, strlen("MSNP2") + 1, "MSNP2"); |
477 | 498 |
478 set_login_progress(gc, 1,"Connecting"); | 499 set_login_progress(gc, 1, "Connecting"); |
479 | 500 |
480 while (gtk_events_pending()) | 501 while (gtk_events_pending()) |
481 gtk_main_iteration(); | 502 gtk_main_iteration(); |
482 if (!g_slist_find(connections, gc)) | 503 if (!g_slist_find(connections, gc)) |
483 return; | 504 return; |
484 | 505 |
485 if (!(mdata->fd = msn_connect("messenger.hotmail.com", 1863))) { | 506 if (!(mdata->fd = msn_connect("messenger.hotmail.com", 1863))) { |
486 hide_login_progress(gc, "Error connection to server"); | 507 hide_login_progress(gc, "Error connection to server"); |
487 signoff(gc); | 508 signoff(gc); |
488 return; | 509 return; |
489 } | 510 } |
490 | 511 |
491 g_snprintf(buf, sizeof(buf), "Signon: %s", gc->username); | 512 g_snprintf(buf, sizeof(buf), "Signon: %s", gc->username); |
492 set_login_progress(gc, 2, buf); | 513 set_login_progress(gc, 2, buf); |
514 | |
493 while (gtk_events_pending()) | 515 while (gtk_events_pending()) |
494 gtk_main_iteration(); | 516 gtk_main_iteration(); |
495 | 517 |
496 /* This is where we will attempt to sign on */ | 518 /* This is where we will attempt to sign on */ |
497 g_snprintf(buf, 4096, "VER %d %s\n", trId, mdata->protocol); | 519 g_snprintf(buf, 4096, "VER %d %s\n", trId, mdata->protocol); |
498 write(mdata->fd, buf, strlen(buf)); | 520 write(mdata->fd, buf, strlen(buf)); |
499 | 521 |
500 msn_read_line(&buf2, mdata->fd); | 522 msn_read_line(&buf2, mdata->fd); |
501 | 523 |
502 buf[strlen(buf)-1] = '\0'; | 524 buf[strlen(buf) - 1] = '\0'; |
503 if (strcmp(buf, buf2) != 0) { | 525 if (strcmp(buf, buf2) != 0) { |
504 hide_login_progress(gc, buf2); | 526 hide_login_progress(gc, buf2); |
505 signoff(gc); | 527 signoff(gc); |
506 return; | 528 return; |
507 } | 529 } |
516 results = g_strsplit(buf2, " ", 0); | 538 results = g_strsplit(buf2, " ", 0); |
517 mdata->policy = g_strdup(results[2]); | 539 mdata->policy = g_strdup(results[2]); |
518 g_strfreev(results); | 540 g_strfreev(results); |
519 | 541 |
520 /* We've set our policy. Now, lets attempt a sign on */ | 542 /* We've set our policy. Now, lets attempt a sign on */ |
521 g_snprintf(buf, 4096, "USR %d %s I %s\n", trId, mdata->policy, gc->username); | 543 g_snprintf(buf, 4096, "USR %d %s I %s\n", trId, mdata->policy, gc->username); |
522 write(mdata->fd, buf, strlen(buf)); | 544 write(mdata->fd, buf, strlen(buf)); |
523 | 545 |
524 msn_read_line(&buf2, mdata->fd); | 546 msn_read_line(&buf2, mdata->fd); |
525 | 547 |
526 /* This is where things get kinky */ | 548 /* This is where things get kinky */ |
537 /* Connect to the new server */ | 559 /* Connect to the new server */ |
538 if (!(mdata->fd = msn_connect(results[0], atoi(results[1])))) { | 560 if (!(mdata->fd = msn_connect(results[0], atoi(results[1])))) { |
539 hide_login_progress(gc, "Error connecting to server"); | 561 hide_login_progress(gc, "Error connecting to server"); |
540 signoff(gc); | 562 signoff(gc); |
541 g_strfreev(results); | 563 g_strfreev(results); |
542 return; | 564 return; |
543 } | 565 } |
544 | 566 |
545 | 567 |
546 g_strfreev(results); | 568 g_strfreev(results); |
547 | 569 |
548 /* We're now connected to the new server. Send signon | 570 /* We're now connected to the new server. Send signon |
549 * information again */ | 571 * information again */ |
550 g_snprintf(buf, 4096, "USR %d %s I %s\n", trId, mdata->policy, gc->username); | 572 g_snprintf(buf, 4096, "USR %d %s I %s\n", trId, mdata->policy, gc->username); |
551 write(mdata->fd, buf, strlen(buf)); | 573 write(mdata->fd, buf, strlen(buf)); |
552 | 574 |
553 msn_read_line(&buf, mdata->fd); | 575 msn_read_line(&buf, mdata->fd); |
554 results = g_strsplit(buf, " ", 0); | 576 results = g_strsplit(buf, " ", 0); |
555 | 577 |
556 } | 578 } |
557 | 579 |
558 /* Otherwise, if we have a USR response, let's handle it */ | 580 /* Otherwise, if we have a USR response, let's handle it */ |
559 if (strcasecmp("USR", results[0]) == 0) { | 581 if (strcasecmp("USR", results[0]) == 0) { |
560 /* Looks like we got a response. Let's get our challenge | 582 /* Looks like we got a response. Let's get our challenge |
561 * string */ | 583 * string */ |
562 strcpy(buf, results[4]); | 584 strcpy(buf, results[4]); |
563 | 585 |
564 } | 586 } else { |
565 else { | |
566 g_strfreev(results); | 587 g_strfreev(results); |
567 hide_login_progress(gc, "Error signing on"); | 588 hide_login_progress(gc, "Error signing on"); |
568 signoff(gc); | 589 signoff(gc); |
569 return; | 590 return; |
570 } | 591 } |
594 results = g_strsplit(buf, " ", 0); | 615 results = g_strsplit(buf, " ", 0); |
595 | 616 |
596 if ((strcasecmp("USR", results[0]) == 0) && (strcasecmp("OK", results[2]) == 0)) { | 617 if ((strcasecmp("USR", results[0]) == 0) && (strcasecmp("OK", results[2]) == 0)) { |
597 mdata->friendly = g_strdup(results[4]); | 618 mdata->friendly = g_strdup(results[4]); |
598 g_strfreev(results); | 619 g_strfreev(results); |
599 } | 620 } else { |
600 else { | |
601 g_strfreev(results); | 621 g_strfreev(results); |
602 hide_login_progress(gc, "Error signing on!"); | 622 hide_login_progress(gc, "Error signing on!"); |
603 signoff(gc); | 623 signoff(gc); |
604 return; | 624 return; |
605 | 625 |
623 | 643 |
624 /* We want to do this so that we can read what's going on */ | 644 /* We want to do this so that we can read what's going on */ |
625 gc->inpa = gdk_input_add(mdata->fd, GDK_INPUT_READ, msn_handler, gc); | 645 gc->inpa = gdk_input_add(mdata->fd, GDK_INPUT_READ, msn_handler, gc); |
626 } | 646 } |
627 | 647 |
628 void msn_send_im(struct gaim_connection *gc, char *who, char *message, int away) { | 648 void msn_send_im(struct gaim_connection *gc, char *who, char *message, int away) |
649 { | |
629 struct msn_conn *mc; | 650 struct msn_conn *mc; |
630 struct msn_data *mdata; | 651 struct msn_data *mdata; |
631 time_t trId = time((time_t *)NULL); | 652 time_t trId = time((time_t *) NULL); |
632 char *buf; | 653 char *buf; |
633 | 654 |
634 mdata = (struct msn_data *)gc->proto_data; | 655 mdata = (struct msn_data *)gc->proto_data; |
635 mc = find_msn_conn_by_user(who); | 656 mc = find_msn_conn_by_user(who); |
636 | 657 |
637 if (mc == NULL) | 658 if (mc == NULL) { |
638 { | |
639 gchar buf2[4096]; | 659 gchar buf2[4096]; |
640 gchar *address; | 660 gchar *address; |
641 gchar *auth; | 661 gchar *auth; |
642 gchar **resps; | 662 gchar **resps; |
643 | 663 |
644 /* Request a new switchboard connection */ | 664 /* Request a new switchboard connection */ |
645 g_snprintf(buf2, 4096, "XFR %d SB\n", trId); | 665 g_snprintf(buf2, 4096, "XFR %d SB\n", trId); |
646 write(mdata->fd, buf2, strlen(buf2)); | 666 write(mdata->fd, buf2, strlen(buf2)); |
647 | 667 |
648 /* Read the results */ | 668 /* Read the results */ |
649 msn_read_line(&buf2, mdata->fd); | 669 msn_read_line(&buf2, mdata->fd); |
650 | 670 |
651 resps = g_strsplit(buf2, " ", 0); | 671 resps = g_strsplit(buf2, " ", 0); |
652 | 672 |
671 write(mc->fd, buf2, strlen(buf2)); | 691 write(mc->fd, buf2, strlen(buf2)); |
672 | 692 |
673 /* Read the results */ | 693 /* Read the results */ |
674 msn_read_line(&buf2, mc->fd); | 694 msn_read_line(&buf2, mc->fd); |
675 g_strfreev(resps); | 695 g_strfreev(resps); |
676 | 696 |
677 resps = g_strsplit(buf2, " ", 0); | 697 resps = g_strsplit(buf2, " ", 0); |
678 | 698 |
679 if (!(strcasecmp("OK", resps[2]) == 0)) { | 699 if (!(strcasecmp("OK", resps[2]) == 0)) { |
680 g_free(auth); | 700 g_free(auth); |
681 g_free(address); | 701 g_free(address); |
682 g_strfreev(resps); | 702 g_strfreev(resps); |
683 g_free(mc); | 703 g_free(mc); |
697 * this from being needed */ | 717 * this from being needed */ |
698 | 718 |
699 while (!strstr(buf2, "JOI")) { | 719 while (!strstr(buf2, "JOI")) { |
700 msn_read_line(&buf2, mc->fd); | 720 msn_read_line(&buf2, mc->fd); |
701 } | 721 } |
702 | 722 |
703 g_free(auth); | 723 g_free(auth); |
704 g_free(address); | 724 g_free(address); |
705 g_strfreev(resps); | 725 g_strfreev(resps); |
706 | 726 |
707 } | 727 } |
708 | 728 |
709 /* Always practice safe sets :-) */ | 729 /* Always practice safe sets :-) */ |
710 buf = (gchar *)g_malloc(sizeof(gchar) * (strlen(message) + strlen(MIME_HEADER) + 64)); | 730 buf = (gchar *) g_malloc(sizeof(gchar) * (strlen(message) + strlen(MIME_HEADER) + 64)); |
711 | 731 |
712 g_snprintf(buf, strlen(message) + strlen(MIME_HEADER) + 64, "MSG %d N %d\r\n%s%s", trId, strlen(message)+strlen(MIME_HEADER), MIME_HEADER, message); | 732 g_snprintf(buf, strlen(message) + strlen(MIME_HEADER) + 64, "MSG %d N %d\r\n%s%s", trId, |
733 strlen(message) + strlen(MIME_HEADER), MIME_HEADER, message); | |
713 | 734 |
714 write(mc->fd, buf, strlen(buf)); | 735 write(mc->fd, buf, strlen(buf)); |
715 | 736 |
716 g_free(buf); | 737 g_free(buf); |
717 } | 738 } |
718 | 739 |
719 static void msn_close (struct gaim_connection *gc) { | 740 static void msn_close(struct gaim_connection *gc) |
741 { | |
720 struct msn_data *mdata = (struct msn_data *)gc->proto_data; | 742 struct msn_data *mdata = (struct msn_data *)gc->proto_data; |
721 GSList *conns = msn_connections; | 743 GSList *conns = msn_connections; |
722 struct msn_conn *mc = NULL; | 744 struct msn_conn *mc = NULL; |
723 char buf[4096]; | 745 char buf[4096]; |
724 | 746 |
731 if (mc->fd > 0) | 753 if (mc->fd > 0) |
732 close(mc->fd); | 754 close(mc->fd); |
733 | 755 |
734 if (mc->user != NULL) | 756 if (mc->user != NULL) |
735 g_free(mc->user); | 757 g_free(mc->user); |
736 | 758 |
737 conns = g_slist_remove(conns, mc); | 759 conns = g_slist_remove(conns, mc); |
738 g_free(mc); | 760 g_free(mc); |
739 } | 761 } |
740 | 762 |
741 | 763 |
742 g_snprintf(buf, 4096, "OUT\n"); | 764 g_snprintf(buf, 4096, "OUT\n"); |
743 write(mdata->fd, buf, strlen(buf)); | 765 write(mdata->fd, buf, strlen(buf)); |
744 | 766 |
745 if (gc->inpa > 0) | 767 if (gc->inpa > 0) |
746 gdk_input_remove(gc->inpa); | 768 gdk_input_remove(gc->inpa); |
747 | 769 |
748 close(mdata->fd); | 770 close(mdata->fd); |
749 | 771 |
751 g_free(mdata->friendly); | 773 g_free(mdata->friendly); |
752 | 774 |
753 g_free(gc->proto_data); | 775 g_free(gc->proto_data); |
754 | 776 |
755 debug_printf(_("Signed off.\n")); | 777 debug_printf(_("Signed off.\n")); |
756 | 778 |
757 } | 779 } |
758 | 780 |
759 static void msn_set_away(struct gaim_connection *gc, char *msg) { | 781 static void msn_set_away(struct gaim_connection *gc, char *msg) |
782 { | |
760 struct msn_data *mdata = (struct msn_data *)gc->proto_data; | 783 struct msn_data *mdata = (struct msn_data *)gc->proto_data; |
761 time_t trId = time((time_t *)NULL); | 784 time_t trId = time((time_t *) NULL); |
762 gchar buf[4096]; | 785 gchar buf[4096]; |
763 | 786 |
764 if (msg) { | 787 if (msg) { |
765 g_snprintf(buf, 4096, "CHG %d AWY\n", trId); | 788 g_snprintf(buf, 4096, "CHG %d AWY\n", trId); |
766 } else if (gc->is_idle) { | 789 } else if (gc->is_idle) { |
768 } else { | 791 } else { |
769 g_snprintf(buf, 4096, "CHG %d NLN\n", trId); | 792 g_snprintf(buf, 4096, "CHG %d NLN\n", trId); |
770 } | 793 } |
771 | 794 |
772 write(mdata->fd, buf, strlen(buf)); | 795 write(mdata->fd, buf, strlen(buf)); |
773 | 796 |
774 } | 797 } |
775 | 798 |
776 static void msn_set_idle(struct gaim_connection *gc, int idle) { | 799 static void msn_set_idle(struct gaim_connection *gc, int idle) |
800 { | |
777 struct msn_data *mdata = (struct msn_data *)gc->proto_data; | 801 struct msn_data *mdata = (struct msn_data *)gc->proto_data; |
778 time_t trId = time((time_t *)NULL); | 802 time_t trId = time((time_t *) NULL); |
779 gchar buf[4096]; | 803 gchar buf[4096]; |
780 | 804 |
781 if (idle) { | 805 if (idle) { |
782 g_snprintf(buf, 4096, "CHG %d IDL\n", trId); | 806 g_snprintf(buf, 4096, "CHG %d IDL\n", trId); |
783 } else { | 807 } else { |
784 g_snprintf(buf, 4096, "CHG %d NLN\n", trId); | 808 g_snprintf(buf, 4096, "CHG %d NLN\n", trId); |
785 } | 809 } |
786 | 810 |
787 write(mdata->fd, buf, strlen(buf)); | 811 write(mdata->fd, buf, strlen(buf)); |
788 | 812 |
789 } | 813 } |
790 | 814 |
791 static struct prpl *my_protocol = NULL; | 815 static struct prpl *my_protocol = NULL; |
792 | 816 |
793 void msn_init(struct prpl *ret) { | 817 void msn_init(struct prpl *ret) |
818 { | |
794 ret->protocol = PROTO_MSN; | 819 ret->protocol = PROTO_MSN; |
795 ret->name = msn_name; | 820 ret->name = msn_name; |
796 ret->list_icon = NULL; | 821 ret->list_icon = NULL; |
797 ret->action_menu = NULL; | 822 ret->action_menu = NULL; |
798 ret->user_opts = NULL; | 823 ret->user_opts = NULL; |
825 ret->keepalive = NULL; | 850 ret->keepalive = NULL; |
826 | 851 |
827 my_protocol = ret; | 852 my_protocol = ret; |
828 } | 853 } |
829 | 854 |
830 char *gaim_plugin_init(GModule *handle) { | 855 char *gaim_plugin_init(GModule * handle) |
856 { | |
831 load_protocol(msn_init); | 857 load_protocol(msn_init); |
832 return NULL; | 858 return NULL; |
833 } | 859 } |
834 | 860 |
835 void gaim_plugin_remove() { | 861 void gaim_plugin_remove() |
862 { | |
836 struct prpl *p = find_prpl(PROTO_MSN); | 863 struct prpl *p = find_prpl(PROTO_MSN); |
837 if (p == my_protocol) | 864 if (p == my_protocol) |
838 unload_protocol(p); | 865 unload_protocol(p); |
839 } | 866 } |
840 |