Mercurial > pidgin
annotate plugins/msn/msn.c @ 1585:f367ea8020fb
[gaim-migrate @ 1595]
Works a little better, eh
committer: Tailor Script <tailor@pidgin.im>
| author | Rob Flynn <gaim@robflynn.com> |
|---|---|
| date | Fri, 16 Mar 2001 01:59:31 +0000 |
| parents | 30a4ecea466a |
| children | bb97d3e8a54d |
| rev | line source |
|---|---|
| 1259 | 1 /* |
| 2 * gaim - MSN Protocol Plugin | |
| 3 * | |
| 4 * Copyright (C) 2000, Rob Flynn <rob@tgflinux.com> | |
| 5 * | |
| 6 * This program is free software; you can redistribute it and/or modify | |
| 7 * it under the terms of the GNU General Public License as published by | |
| 8 * the Free Software Foundation; either version 2 of the License, or | |
| 9 * (at your option) any later version. | |
| 10 * | |
| 11 * This program is distributed in the hope that it will be useful, | |
| 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 14 * GNU General Public License for more details. | |
| 15 * | |
| 16 * You should have received a copy of the GNU General Public License | |
| 17 * along with this program; if not, write to the Free Software | |
| 18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 19 * | |
| 20 */ | |
| 21 | |
|
1514
0dd012166152
[gaim-migrate @ 1524]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1499
diff
changeset
|
22 #include "config.h" |
| 1259 | 23 |
| 24 #include <netdb.h> | |
| 25 #include <gtk/gtk.h> | |
| 26 #include <unistd.h> | |
| 27 #include <errno.h> | |
| 28 #include <netinet/in.h> | |
| 29 #include <arpa/inet.h> | |
| 30 #include <string.h> | |
| 31 #include <stdlib.h> | |
| 32 #include <stdio.h> | |
| 33 #include <time.h> | |
| 1567 | 34 #include <fcntl.h> |
| 1259 | 35 #include <sys/socket.h> |
| 36 #include <sys/stat.h> | |
| 1567 | 37 #include <sys/types.h> |
| 1259 | 38 #include "multi.h" |
| 39 #include "prpl.h" | |
| 40 #include "gaim.h" | |
| 41 #include "md5.h" | |
| 42 | |
| 1284 | 43 #include "pixmaps/msn_online.xpm" |
| 1285 | 44 #include "pixmaps/msn_away.xpm" |
| 1284 | 45 |
| 1567 | 46 #define MIME_HEADER "MIME-Version: 1.0\r\nContent-Type: text/plain; charset=UTF-8\r\nX-MMS-IM-Format: FN=MS%20Sans%20Serif; EF=; CO=0; CS=0; PF=0\r\n\r\n" |
| 1259 | 47 |
| 1567 | 48 #define MSN_BUF_LEN 8192 |
| 1259 | 49 |
| 50 #define MSN_ONLINE 1 | |
| 51 #define MSN_BUSY 2 | |
| 52 #define MSN_IDLE 3 | |
| 53 #define MSN_BRB 4 | |
| 54 #define MSN_AWAY 5 | |
| 55 #define MSN_PHONE 6 | |
| 56 #define MSN_LUNCH 7 | |
| 57 #define MSN_OFFLINE 8 | |
| 58 #define MSN_HIDDEN 9 | |
| 59 | |
| 1567 | 60 #define MSN_SIGNON_GOT_XFR 0x0001 |
| 61 #define MSN_SIGNON_SENT_USR 0x0002 | |
| 1259 | 62 |
| 63 struct msn_data { | |
| 64 int fd; | |
| 65 | |
| 66 char protocol[6]; | |
| 67 char *friendly; | |
| 68 gchar *policy; | |
| 1567 | 69 int inpa; |
| 70 int status; | |
| 71 time_t last_trid; | |
| 1259 | 72 }; |
| 73 | |
| 74 struct msn_conn { | |
| 75 gchar *user; | |
| 76 int inpa; | |
| 77 int fd; | |
| 1572 | 78 struct gaim_connection *gc; |
| 79 char *secret; | |
| 80 char *session; | |
| 1584 | 81 time_t last_trid; |
| 82 char *txqueue; | |
| 1259 | 83 }; |
| 84 | |
| 1567 | 85 GSList *msn_connections = NULL; |
| 1259 | 86 |
| 1567 | 87 unsigned long long globalc = 0; |
| 1572 | 88 static void msn_callback(gpointer data, gint source, GdkInputCondition condition); |
| 1259 | 89 |
| 1584 | 90 struct msn_conn *find_msn_conn_by_user(gchar * user) |
| 91 { | |
| 92 struct msn_conn *mc; | |
| 93 GSList *conns = msn_connections; | |
| 94 | |
| 95 while (conns) { | |
| 96 mc = (struct msn_conn *)conns->data; | |
| 97 | |
| 98 if (mc != NULL) { | |
| 99 if (strcasecmp(mc->user, user) == 0) { | |
| 100 return mc; | |
| 101 } | |
| 102 } | |
| 103 | |
| 104 conns = g_slist_next(conns); | |
| 105 } | |
| 106 | |
| 107 return NULL; | |
| 108 } | |
| 109 | |
| 110 struct msn_conn *find_msn_conn_by_trid(time_t trid) | |
| 111 { | |
| 112 struct msn_conn *mc; | |
| 113 GSList *conns = msn_connections; | |
| 114 | |
| 115 while (conns) { | |
| 116 mc = (struct msn_conn *)conns->data; | |
| 117 | |
| 118 if (mc != NULL) { | |
| 119 | |
| 120 printf("Comparing: %d <==> %d\n", mc->last_trid, trid); | |
| 121 if (mc->last_trid == trid) { | |
| 122 return mc; | |
| 123 } | |
| 124 } | |
| 125 | |
| 126 conns = g_slist_next(conns); | |
| 127 } | |
| 128 | |
| 129 return NULL; | |
| 130 } | |
| 131 | |
| 1282 | 132 static char *msn_name() |
| 133 { | |
| 1259 | 134 return "MSN"; |
| 135 } | |
| 136 | |
| 1282 | 137 char *name() |
| 138 { | |
| 1259 | 139 return "MSN"; |
| 140 } | |
| 141 | |
| 1282 | 142 char *description() |
| 143 { | |
| 1259 | 144 return "Allows gaim to use the MSN protocol. For some reason, this frightens me."; |
| 145 } | |
| 146 | |
| 1567 | 147 time_t trId(struct msn_data *md) |
| 1282 | 148 { |
| 1567 | 149 md->last_trid = time((time_t *)NULL) + globalc++; |
| 150 return md->last_trid; | |
| 151 } | |
| 152 | |
| 153 void msn_write(int fd, char *buf) | |
| 154 { | |
| 155 write(fd, buf, strlen(buf)); | |
| 1585 | 156 printf("MSN(%d) <== %s", fd, buf); |
| 1567 | 157 } |
| 1259 | 158 |
| 1572 | 159 static void msn_answer_callback(gpointer data, gint source, GdkInputCondition condition) |
| 160 { | |
| 161 struct msn_conn *mc = data; | |
| 162 char buf[MSN_BUF_LEN]; | |
| 163 | |
| 164 fcntl(source, F_SETFL, 0); | |
| 165 | |
| 166 g_snprintf(buf, MSN_BUF_LEN, "ANS 1 %s %s %s\n", mc->gc->username, mc->secret, mc->session); | |
| 167 msn_write(mc->fd, buf); | |
| 168 | |
| 169 gdk_input_remove(mc->inpa); | |
| 170 mc->inpa = gdk_input_add(mc->fd, GDK_INPUT_READ, msn_callback, mc->gc); | |
| 171 | |
| 172 /* Append our connection */ | |
| 173 msn_connections = g_slist_append(msn_connections, mc); | |
| 174 } | |
| 175 | |
| 1584 | 176 static void msn_invite_callback(gpointer data, gint source, GdkInputCondition condition) |
| 177 { | |
| 178 struct msn_conn *mc = data; | |
| 179 struct msn_data *md = (struct msn_data *)mc->gc->proto_data; | |
| 180 char buf[MSN_BUF_LEN]; | |
| 181 struct gaim_connection *gc = mc->gc; | |
| 182 int i = 0; | |
| 1585 | 183 |
| 184 fcntl(source, F_SETFL, 0); | |
| 1584 | 185 |
| 1585 | 186 printf("GOT HERE|\n"); |
| 1584 | 187 |
| 188 if (condition == GDK_INPUT_WRITE) | |
| 189 { | |
| 190 /* We just got in here */ | |
| 191 gdk_input_remove(mc->inpa); | |
| 192 mc->inpa = gdk_input_add(mc->fd, GDK_INPUT_READ, msn_invite_callback, mc); | |
| 193 | |
| 194 /* Write our signon request */ | |
| 195 g_snprintf(buf, MSN_BUF_LEN, "USR %d %s %s\n", mc->last_trid, mc->gc->username, mc->secret); | |
| 1585 | 196 msn_write(mc->fd, buf); |
| 1584 | 197 return; |
| 198 } | |
| 199 | |
| 200 bzero(buf, MSN_BUF_LEN); | |
| 201 do | |
| 202 { | |
| 203 if (read(source, buf + i, 1) < 0) | |
| 204 { | |
| 205 hide_login_progress(gc, "Read error"); | |
| 206 signoff(gc); | |
| 207 return; | |
| 208 } | |
| 209 | |
| 210 } while (buf[i++] != '\n'); | |
| 211 | |
| 212 g_strchomp(buf); | |
| 213 | |
| 1585 | 214 printf("!!MSN(%d) ==> %s\n", source, buf); |
| 215 printf("Got here.\n"); | |
| 1584 | 216 |
| 217 if (!strncmp("USR ", buf, 4)) | |
| 218 { | |
| 219 char **res; | |
| 220 | |
| 1585 | 221 printf("Got here2.\n"); |
| 222 | |
| 1584 | 223 res = g_strsplit(buf, " ", 0); |
| 1585 | 224 printf("%s\n",res[2]); |
| 1584 | 225 if (strcasecmp("OK", res[2])) |
| 226 { | |
| 227 g_strfreev(res); | |
| 228 close(mc->fd); | |
| 229 return; | |
| 230 } | |
| 231 | |
| 232 /* We've authorized. Let's send an invite request */ | |
| 233 g_snprintf(buf, MSN_BUF_LEN, "CAL %d %s\n", trId(md), mc->user); | |
| 234 msn_write(source, buf); | |
| 235 return; | |
| 236 } | |
| 237 | |
| 238 else if (!strncmp("JOI ", buf, 4)) | |
| 239 { | |
| 240 /* Looks like they just joined! Write their queued message */ | |
| 241 g_snprintf(buf, MSN_BUF_LEN, "MSG %d N %d\r\n%s%s", trId(md), strlen(mc->txqueue) + strlen(MIME_HEADER), MIME_HEADER, mc->txqueue); | |
| 242 | |
| 243 msn_write(source, buf); | |
| 244 | |
| 245 gdk_input_remove(mc->inpa); | |
| 246 mc->inpa = gdk_input_add(mc->fd, GDK_INPUT_READ, msn_callback, mc->gc); | |
| 247 | |
| 248 return; | |
| 249 | |
| 250 } | |
| 251 } | |
| 252 | |
| 1567 | 253 static void msn_callback(gpointer data, gint source, GdkInputCondition condition) |
| 254 { | |
| 255 struct gaim_connection *gc = data; | |
| 256 struct msn_data *md = (struct msn_data *)gc->proto_data; | |
| 257 char buf[MSN_BUF_LEN]; | |
| 258 int i = 0; | |
| 1572 | 259 int num; |
| 1259 | 260 |
| 1567 | 261 bzero(buf, MSN_BUF_LEN); |
| 262 | |
| 263 do | |
| 264 { | |
| 265 if (read(source, buf + i, 1) < 0) | |
| 266 { | |
| 267 hide_login_progress(gc, "Read error"); | |
| 268 signoff(gc); | |
| 269 return; | |
| 1259 | 270 } |
| 271 | |
| 1567 | 272 } while (buf[i++] != '\n'); |
| 273 | |
| 274 g_strchomp(buf); | |
| 275 | |
| 1572 | 276 printf("MSN(%d) ==> %s\n", source, buf); |
| 1567 | 277 |
| 1569 | 278 if (!strncmp("NLN ", buf, 4) || !strncmp("ILN ", buf, 4)) |
| 279 { | |
| 280 int status; | |
| 281 int query; | |
| 282 char **res; | |
| 283 | |
| 284 res = g_strsplit(buf, " ", 0); | |
| 285 | |
| 286 if (!strcmp(res[0], "NLN")) | |
| 287 query = 1; | |
| 288 else | |
| 289 query = 2; | |
| 290 | |
| 291 if (!strcasecmp(res[query], "NLN")) | |
| 292 status = UC_NORMAL; | |
| 293 else if (!strcasecmp(res[query], "BSY")) | |
| 294 status = UC_NORMAL | (MSN_BUSY << 5); | |
| 295 else if (!strcasecmp(res[query], "IDL")) | |
| 296 status = UC_NORMAL | (MSN_IDLE << 5); | |
| 297 else if (!strcasecmp(res[query], "BRB")) | |
| 298 status = UC_NORMAL | (MSN_BRB << 5); | |
| 299 else if (!strcasecmp(res[query], "AWY")) | |
| 300 status = UC_UNAVAILABLE; | |
| 301 else if (!strcasecmp(res[query], "PHN")) | |
| 302 status = UC_NORMAL | (MSN_PHONE << 5); | |
| 303 else if (!strcasecmp(res[query], "LUN")) | |
| 304 status = UC_NORMAL | (MSN_LUNCH << 5); | |
| 305 else | |
| 306 status = UC_NORMAL; | |
| 307 | |
| 308 serv_got_update(gc, res[query+1], 1, 0, 0, 0, status, 0); | |
| 309 | |
| 310 g_strfreev(res); | |
| 311 | |
| 312 return; | |
| 313 | |
| 314 } | |
| 1572 | 315 else if (!strncmp("MSG ", buf, 4)) |
| 316 { | |
| 317 /* We are receiving an incoming message */ | |
| 318 gchar **res; | |
| 319 gchar *user; | |
| 320 gchar *msgdata; | |
| 321 int size; | |
| 322 | |
| 323 res = g_strsplit(buf, " ", 0); | |
| 324 | |
| 325 user = g_strdup(res[1]); | |
| 326 size = atoi(res[3]); | |
| 327 | |
| 328 /* Ok, we know who we're receiving a message from as well as | |
| 329 * how big the message is */ | |
| 330 | |
| 331 msgdata = (gchar *)g_malloc(sizeof(gchar) *(size + 1)); | |
| 332 num = recv(source, msgdata, size, 0); | |
| 333 msgdata[size] = 0; | |
| 334 | |
| 335 if (num < size) | |
| 336 printf("MSN: Uhh .. we gots a problem!. Expected %d but got %d.\n", size, num); | |
| 337 | |
| 338 /* We should ignore messages from the user Hotmail */ | |
| 339 if (!strcasecmp("hotmail", res[1])) | |
| 340 { | |
| 341 g_strfreev(res); | |
| 342 g_free(msgdata); | |
| 343 return; | |
| 344 } | |
| 345 | |
| 346 /* Check to see if any body is in the message */ | |
| 347 if (!strcmp(strstr(msgdata, "\r\n\r\n") + 4, "\r\n")) | |
| 348 { | |
| 349 g_strfreev(res); | |
| 350 g_free(msgdata); | |
| 351 return; | |
| 352 } | |
| 353 | |
| 354 /* Otherwise, everything is ok. Let's show the message. Skipping, | |
| 355 * of course, the header. */ | |
| 356 | |
| 357 serv_got_im(gc, res[1], strstr(msgdata, "\r\n\r\n") + 4, 0); | |
| 358 | |
| 359 g_strfreev(res); | |
| 360 g_free(msgdata); | |
| 361 | |
| 362 return; | |
| 363 } | |
| 364 else if (!strncmp("RNG ", buf, 4)) | |
| 365 { | |
| 366 /* Ok, someone wants to talk to us. Ring ring? Hi!!! */ | |
| 367 gchar **address; | |
| 368 gchar **res; | |
| 369 struct msn_conn *mc = g_new0(struct msn_conn, 1); | |
| 370 | |
| 371 res = g_strsplit(buf, " ", 0); | |
| 372 address = g_strsplit(res[2], ":", 0); | |
| 373 | |
| 374 if (!(mc->fd = msn_connect(address[0], atoi(address[1])))) | |
| 375 { | |
| 376 /* Looks like we had an error connecting. */ | |
| 377 g_strfreev(address); | |
| 378 g_strfreev(res); | |
| 379 g_free(mc); | |
| 380 return; | |
| 381 } | |
| 382 | |
| 383 /* Set up our struct with user and input watcher */ | |
| 384 mc->user = g_strdup(res[5]); | |
| 385 mc->secret = g_strdup(res[4]); | |
| 386 mc->session = g_strdup(res[1]); | |
| 387 mc->gc = gc; | |
| 388 | |
| 389 mc->inpa = gdk_input_add(mc->fd, GDK_INPUT_WRITE, msn_answer_callback, mc); | |
| 390 | |
| 391 g_strfreev(address); | |
| 392 g_strfreev(res); | |
| 393 | |
| 394 return; | |
| 395 } | |
| 1584 | 396 else if (!strncmp("XFR ", buf, 4)) |
| 397 { | |
| 398 char **res; | |
| 399 char *host; | |
| 400 char *port; | |
| 401 struct msn_conn *mc; | |
| 402 | |
| 403 res = g_strsplit(buf, " ", 0); | |
| 404 | |
| 405 printf("Last trid is: %d\n", md->last_trid); | |
| 406 printf("This TrId is: %d\n", atoi(res[1])); | |
| 407 | |
| 408 mc = find_msn_conn_by_trid(atoi(res[1])); | |
| 409 | |
| 410 if (!mc) | |
| 411 { | |
| 412 g_strfreev(res); | |
| 413 return; | |
| 414 } | |
| 415 | |
| 416 strcpy(buf, res[3]); | |
| 417 | |
| 418 mc->secret = g_strdup(res[5]); | |
| 419 mc->session = g_strdup(res[1]); | |
| 420 | |
| 421 g_strfreev(res); | |
| 422 | |
| 423 res = g_strsplit(buf, ":", 0); | |
| 424 | |
| 425 /* Now we have the host and port */ | |
| 1585 | 426 if (!(mc->fd = msn_connect(res[0], atoi(res[1])))) |
| 1584 | 427 return; |
| 428 | |
| 429 printf("Connected to: %s:%s\n", res[0], res[1]); | |
| 430 | |
| 1585 | 431 if (mc->inpa) |
| 432 gdk_input_remove(mc->inpa); | |
| 433 | |
| 1584 | 434 mc->inpa = gdk_input_add(mc->fd, GDK_INPUT_WRITE, msn_invite_callback, mc); |
| 435 | |
| 436 g_strfreev(res); | |
| 437 | |
| 438 return; | |
| 439 } | |
| 1569 | 440 else if (!strncmp("LST ", buf, 4)) |
| 1567 | 441 { |
| 442 char **res; | |
| 443 | |
| 444 res = g_strsplit(buf, " ", 0); | |
| 445 | |
| 1568 | 446 /* If we have zero buddies, abort */ |
| 447 if (atoi(res[5]) == 0) | |
| 448 { | |
| 449 g_strfreev(res); | |
| 450 return; | |
| 451 } | |
| 452 | |
| 1567 | 453 /* First, let's check the list type */ |
| 454 if (!strcmp("FL", res[2])) | |
| 455 { | |
| 456 /* We're dealing with a forward list. Add them | |
| 457 * to our buddylist and continue along our | |
| 458 * merry little way */ | |
| 459 | |
| 460 struct buddy *b; | |
| 461 | |
| 462 b = find_buddy(gc, res[6]); | |
| 463 | |
| 464 if (!b) | |
| 465 add_buddy(gc, "Buddies", res[6], res[7]); | |
| 466 } | |
| 467 | |
| 468 g_strfreev(res); | |
| 469 | |
| 470 return; | |
| 1259 | 471 } |
| 472 | |
| 473 } | |
| 474 | |
| 1567 | 475 static void msn_login_callback(gpointer data, gint source, GdkInputCondition condition) |
| 1282 | 476 { |
| 1567 | 477 struct gaim_connection *gc = data; |
| 478 struct msn_data *md = (struct msn_data *)gc->proto_data; | |
| 479 char buf[MSN_BUF_LEN]; | |
| 1259 | 480 int i = 0; |
| 1282 | 481 |
| 1567 | 482 if (!gc->inpa) |
| 483 { | |
| 484 fcntl(source, F_SETFL, 0); | |
| 485 | |
| 486 gdk_input_remove(md->inpa); | |
| 487 md->inpa = 0; | |
| 488 | |
| 489 gc->inpa = gdk_input_add(md->fd, GDK_INPUT_READ, msn_login_callback, gc); | |
| 1307 | 490 |
| 1567 | 491 if (md->status & MSN_SIGNON_GOT_XFR) |
| 492 { | |
| 493 /* Looks like we were transfered here. Just send a sign on */ | |
| 494 set_login_progress(gc, 3, "Signing On"); | |
| 495 g_snprintf(buf, MSN_BUF_LEN, "USR %d %s I %s\n", md->last_trid, md->policy, gc->username); | |
| 496 msn_write(md->fd, buf); | |
| 497 | |
| 498 /* Reset this bit */ | |
| 499 md->status ^= MSN_SIGNON_GOT_XFR; | |
| 500 } | |
| 501 else | |
| 502 { | |
| 503 /* Otherwise, send an initial request */ | |
| 504 set_login_progress(gc, 2, "Verifiying"); | |
| 1259 | 505 |
| 1567 | 506 g_snprintf(md->protocol, 6, "MSNP2"); |
| 507 | |
| 508 g_snprintf(buf, MSN_BUF_LEN, "VER %d %s\n", trId(md), md->protocol); | |
| 509 msn_write(md->fd, buf); | |
| 510 } | |
| 511 | |
| 512 return; | |
| 513 } | |
| 514 | |
| 515 bzero(buf, MSN_BUF_LEN); | |
| 516 | |
| 517 do | |
| 518 { | |
| 519 if (read(source, buf + i, 1) < 0) | |
| 520 { | |
| 521 hide_login_progress(gc, "Read error"); | |
| 522 signoff(gc); | |
| 1259 | 523 return; |
| 1567 | 524 } |
| 1259 | 525 |
| 1567 | 526 } while (buf[i++] != '\n'); |
| 1259 | 527 |
| 528 g_strchomp(buf); | |
| 529 | |
| 1567 | 530 printf("MSN ==> %s\n", buf); |
| 531 | |
| 532 /* Check to see what was just sent back to us. We should be seeing a VER tag. */ | |
| 533 if (!strncmp("VER ", buf, 4) && (!strstr("MSNP2", buf))) | |
| 534 { | |
| 535 /* Now that we got our ver, we shoudl send a policy request */ | |
| 536 g_snprintf(buf, MSN_BUF_LEN, "INF %d\n", trId(md)); | |
| 537 msn_write(md->fd, buf); | |
| 538 | |
| 539 return; | |
| 540 } | |
| 541 else if (!strncmp("INF ", buf, 4)) | |
| 542 { | |
| 543 char **res; | |
| 544 | |
| 545 /* Make a copy of our resulting policy */ | |
| 546 res = g_strsplit(buf, " ", 0); | |
| 547 md->policy = g_strdup(res[2]); | |
| 548 | |
| 549 /* And send our signon packet */ | |
| 550 set_login_progress(gc, 3, "Signing On"); | |
| 551 | |
| 552 g_snprintf(buf, MSN_BUF_LEN, "USR %d %s I %s\n", trId(md), md->policy, gc->username); | |
| 553 msn_write(md->fd, buf); | |
| 554 | |
| 555 g_strfreev(res); | |
| 556 | |
| 557 return; | |
| 558 } | |
| 559 else if (!strncmp("XFR ", buf, 4)) | |
| 560 { | |
| 561 char **res; | |
| 562 char *host; | |
| 563 char *port; | |
| 564 | |
| 565 res = g_strsplit(buf, " ", 0); | |
| 566 | |
| 567 strcpy(buf, res[3]); | |
| 568 | |
| 569 g_strfreev(res); | |
| 570 | |
| 571 res = g_strsplit(buf, ":", 0); | |
| 572 | |
| 573 close(md->fd); | |
| 574 | |
| 575 set_login_progress(gc, 1, "Connecting"); | |
| 576 | |
| 577 /* Now we have the host and port */ | |
| 578 if (!(md->fd = msn_connect(res[0], atoi(res[1])))) | |
| 579 { | |
| 580 hide_login_progress(gc, "Error connecting to server"); | |
| 581 signoff(gc); | |
| 582 return; | |
| 583 } | |
| 584 | |
| 585 g_strfreev(res); | |
| 586 | |
| 587 md->status |= MSN_SIGNON_GOT_XFR; | |
| 588 | |
| 589 gdk_input_remove(gc->inpa); | |
| 590 gc->inpa = 0; | |
| 591 | |
| 592 md->inpa = gdk_input_add(md->fd, GDK_INPUT_WRITE, msn_login_callback, gc); | |
| 593 | |
| 594 return; | |
| 595 } | |
| 596 else if (!strncmp("USR ", buf, 4)) | |
| 597 { | |
| 598 if (md->status & MSN_SIGNON_SENT_USR) | |
| 599 { | |
| 600 char **res; | |
| 601 | |
| 602 res = g_strsplit(buf, " ", 0); | |
| 603 | |
| 604 if (strcasecmp("OK", res[2])) | |
| 605 { | |
| 606 hide_login_progress(gc, "Error signing on"); | |
| 607 signoff(gc); | |
| 608 } | |
| 609 else | |
| 610 { | |
| 611 md->friendly = g_strdup(res[4]); | |
| 612 | |
| 613 /* Ok, ok. Your account is FINALLY online. Ya think Microsoft | |
| 614 * could have had any more steps involved? */ | |
| 615 | |
| 616 set_login_progress(gc, 4, "Fetching config"); | |
| 617 | |
| 618 /* Sync our buddylist */ | |
| 619 g_snprintf(buf, MSN_BUF_LEN, "SYN %d 0\n", trId(md)); | |
| 620 msn_write(md->fd, buf); | |
| 621 | |
| 622 /* And set ourselves online */ | |
| 623 g_snprintf(buf, MSN_BUF_LEN, "CHG %d NLN\n", trId(md)); | |
| 624 msn_write(md->fd, buf); | |
| 625 | |
| 626 account_online(gc); | |
| 627 serv_finish_login(gc); | |
| 628 | |
| 629 if (bud_list_cache_exists(gc)) | |
| 630 do_import(NULL, gc); | |
| 631 | |
| 632 gdk_input_remove(gc->inpa); | |
| 633 gc->inpa = gdk_input_add(md->fd, GDK_INPUT_READ, msn_callback, gc); | |
| 634 } | |
| 635 | |
| 636 g_strfreev(res); | |
| 637 } | |
| 638 else | |
| 639 { | |
| 640 char **res; | |
| 641 char buf2[MSN_BUF_LEN]; | |
| 642 int j; | |
| 643 md5_state_t st; | |
| 644 md5_byte_t di[16]; | |
| 645 | |
| 646 res = g_strsplit(buf, " ", 0); | |
| 647 | |
| 648 /* Make a copy of our MD5 Hash key */ | |
| 649 strcpy(buf, res[4]); | |
| 650 | |
| 651 /* Generate our secret with our key and password */ | |
| 652 snprintf(buf2, MSN_BUF_LEN, "%s%s", buf, gc->password); | |
| 653 | |
| 654 md5_init(&st); | |
| 655 md5_append(&st, (const md5_byte_t *)buf2, strlen(buf2)); | |
| 656 md5_finish(&st, di); | |
| 657 | |
| 658 /* Now that we have the MD5 Hash, lets' hex encode this bad boy. I smoke bad crack. */ | |
| 659 sprintf(buf, "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", | |
| 660 di[0],di[1],di[2],di[3],di[4],di[5],di[6],di[7],di[8],di[9],di[10],di[11],di[12], | |
| 661 di[13],di[14],di[15]); | |
| 662 | |
| 663 /* And now, send our final sign on packet */ | |
| 664 g_snprintf(buf2, MSN_BUF_LEN, "USR %s %s S %s\n", res[1], md->policy, buf); | |
| 665 msn_write(md->fd, buf2); | |
| 666 | |
| 667 md->status |= MSN_SIGNON_SENT_USR; | |
| 668 | |
| 669 g_strfreev(res); | |
| 670 } | |
| 671 | |
| 672 return; | |
| 673 } | |
| 1259 | 674 } |
| 675 | |
| 1282 | 676 int msn_connect(char *server, int port) |
| 677 { | |
| 1259 | 678 int fd; |
| 679 struct hostent *host; | |
| 680 struct sockaddr_in site; | |
| 681 | |
| 1567 | 682 if (!(host = gethostbyname(server))) |
| 683 { | |
| 684 printf("Could not resolve host name: %s\n", server); | |
| 1259 | 685 return -1; |
| 686 } | |
| 687 | |
| 1567 | 688 bzero(&site, sizeof(struct sockaddr_in)); |
| 689 site.sin_port = htons(port); | |
| 690 memcpy(&site.sin_addr, host->h_addr, host->h_length); | |
| 691 site.sin_family = host->h_addrtype; | |
| 1259 | 692 |
| 1567 | 693 fd = socket(host->h_addrtype, SOCK_STREAM, 0); |
| 1259 | 694 |
| 1567 | 695 fcntl(fd, F_SETFL, O_NONBLOCK); |
| 1259 | 696 |
| 1567 | 697 if (connect(fd, (struct sockaddr *)&site, sizeof(struct sockaddr_in)) < 0) |
| 698 { | |
| 699 if ((errno == EINPROGRESS) || (errno == EINTR)) | |
| 700 { | |
| 701 printf("Connection would block\n"); | |
| 702 return fd; | |
| 1259 | 703 } |
| 704 | |
| 1567 | 705 close(fd); |
| 706 fd = -1; | |
| 1259 | 707 } |
| 1567 | 708 |
| 709 return fd; | |
| 1259 | 710 } |
| 711 | |
| 1282 | 712 void msn_login(struct aim_user *user) |
| 713 { | |
| 1567 | 714 struct gaim_connection *gc = new_gaim_conn(user); |
| 715 struct msn_data *md = gc->proto_data = g_new0(struct msn_data, 1); | |
| 1282 | 716 |
| 1567 | 717 gc->inpa = 0; |
| 1282 | 718 |
| 719 set_login_progress(gc, 1, "Connecting"); | |
| 1259 | 720 |
| 721 while (gtk_events_pending()) | |
| 722 gtk_main_iteration(); | |
| 1567 | 723 |
| 1259 | 724 if (!g_slist_find(connections, gc)) |
| 725 return; | |
| 726 | |
| 1567 | 727 md->status = 0; |
| 1282 | 728 |
| 1567 | 729 if (!(md->fd = msn_connect("messenger.hotmail.com", 1863))) |
| 730 { | |
| 731 hide_login_progress(gc, "Error connecting to server"); | |
| 1259 | 732 signoff(gc); |
| 733 return; | |
| 734 } | |
| 735 | |
| 1567 | 736 md->inpa = gdk_input_add(md->fd, GDK_INPUT_WRITE, msn_login_callback, gc); |
| 1259 | 737 |
| 1567 | 738 printf("Connected.\n"); |
| 1284 | 739 } |
| 740 | |
| 1584 | 741 void msn_send_im(struct gaim_connection *gc, char *who, char *message, int away) |
| 742 { | |
| 743 struct msn_conn *mc; | |
| 744 struct msn_data *md = (struct msn_data *)gc->proto_data; | |
| 745 char buf[MSN_BUF_LEN]; | |
| 746 | |
| 747 if (!g_strcasecmp(who, gc->username)) | |
| 748 { | |
| 749 do_error_dialog("You can not send a message to yourself!", "Gaim: MSN Error"); | |
| 750 return; | |
| 751 } | |
| 752 | |
| 753 mc = find_msn_conn_by_user(who); | |
| 754 | |
| 755 /* If we're not already in a conversation with | |
| 756 * this person then we have to do some tricky things. */ | |
| 757 | |
| 758 if (!mc) | |
| 759 { | |
| 760 gchar buf2[MSN_BUF_LEN]; | |
| 761 gchar *address; | |
| 762 gchar *auth; | |
| 763 gchar **res; | |
| 764 | |
| 765 /* Request a new switchboard connection */ | |
| 766 g_snprintf(buf, MSN_BUF_LEN, "XFR %d SB\n", trId(md)); | |
| 767 msn_write(md->fd, buf); | |
| 768 | |
| 769 mc = g_new0(struct msn_conn, 1); | |
| 770 | |
| 771 mc->user = g_strdup(who); | |
| 772 mc->gc = gc; | |
| 773 mc->last_trid = md->last_trid; | |
| 774 mc->txqueue = g_strdup(message); | |
| 775 | |
| 776 /* Append our connection */ | |
| 777 msn_connections = g_slist_append(msn_connections, mc); | |
| 778 } | |
| 1585 | 779 else |
| 780 { | |
| 781 g_snprintf(buf, MSN_BUF_LEN, "MSG %d N %d\r\n%s%s", trId(md), strlen(message) + strlen(MIME_HEADER), MIME_HEADER, message); | |
| 782 | |
| 783 msn_write(mc->fd, buf); | |
| 784 } | |
| 1584 | 785 |
| 786 } | |
| 787 | |
| 1572 | 788 static char **msn_list_icon(int uc) |
| 789 { | |
| 790 if (uc == UC_UNAVAILABLE) | |
| 791 return msn_away_xpm; | |
| 792 else if (uc == UC_NORMAL) | |
| 793 return msn_online_xpm; | |
| 794 | |
| 795 return msn_online_xpm; | |
| 796 } | |
| 797 | |
| 1259 | 798 static struct prpl *my_protocol = NULL; |
| 799 | |
| 1282 | 800 void msn_init(struct prpl *ret) |
| 801 { | |
| 1259 | 802 ret->protocol = PROTO_MSN; |
| 803 ret->name = msn_name; | |
| 1572 | 804 ret->list_icon = msn_list_icon; |
|
1499
de0b946e86a4
[gaim-migrate @ 1509]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1443
diff
changeset
|
805 ret->buddy_menu = NULL; |
| 1259 | 806 ret->user_opts = NULL; |
| 807 ret->login = msn_login; | |
| 1567 | 808 ret->close = NULL; |
| 1584 | 809 ret->send_im = msn_send_im; |
| 1259 | 810 ret->set_info = NULL; |
| 811 ret->get_info = NULL; | |
| 1567 | 812 ret->set_away = NULL; |
| 1259 | 813 ret->get_away_msg = NULL; |
| 814 ret->set_dir = NULL; | |
| 815 ret->get_dir = NULL; | |
| 816 ret->dir_search = NULL; | |
| 1567 | 817 ret->set_idle = NULL; |
| 1259 | 818 ret->change_passwd = NULL; |
| 1567 | 819 ret->add_buddy = NULL; |
| 1259 | 820 ret->add_buddies = NULL; |
| 1567 | 821 ret->remove_buddy = NULL; |
| 822 ret->add_permit = NULL; | |
| 823 ret->rem_permit = NULL; | |
| 824 ret->add_deny = NULL; | |
| 825 ret->rem_deny = NULL; | |
| 1259 | 826 ret->warn = NULL; |
| 827 ret->accept_chat = NULL; | |
| 828 ret->join_chat = NULL; | |
| 829 ret->chat_invite = NULL; | |
| 830 ret->chat_leave = NULL; | |
| 831 ret->chat_whisper = NULL; | |
| 832 ret->chat_send = NULL; | |
| 833 ret->keepalive = NULL; | |
| 834 | |
| 835 my_protocol = ret; | |
| 836 } | |
| 837 | |
| 1282 | 838 char *gaim_plugin_init(GModule * handle) |
| 839 { | |
|
1443
336fc98b7f90
[gaim-migrate @ 1453]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1327
diff
changeset
|
840 load_protocol(msn_init, sizeof(struct prpl)); |
| 1259 | 841 return NULL; |
| 842 } | |
| 843 | |
| 1282 | 844 void gaim_plugin_remove() |
| 845 { | |
| 1259 | 846 struct prpl *p = find_prpl(PROTO_MSN); |
| 847 if (p == my_protocol) | |
| 848 unload_protocol(p); | |
| 849 } |
