comparison src/protocols/msn/msn.c @ 4491:3196d9044a45

[gaim-migrate @ 4766] aim_user is dead. long live gaim_account. committer: Tailor Script <tailor@pidgin.im>
author Nathan Walp <nwalp@pidgin.im>
date Fri, 31 Jan 2003 13:03:47 +0000
parents 8fbf1c989f2b
children 4c40fccbd7c9
comparison
equal deleted inserted replaced
4490:70b892694e0b 4491:3196d9044a45
485 char msgbuf[256]; 485 char msgbuf[256];
486 const char *username; 486 const char *username;
487 struct gaim_conversation *cnv; 487 struct gaim_conversation *cnv;
488 struct buddy *b; 488 struct buddy *b;
489 489
490 if ((b = find_buddy(gc->user, user)) != NULL) 490 if ((b = find_buddy(gc->account, user)) != NULL)
491 username = get_buddy_alias(b); 491 username = get_buddy_alias(b);
492 else 492 else
493 username = user; 493 username = user;
494 494
495 g_snprintf(msgbuf, sizeof(msgbuf), 495 g_snprintf(msgbuf, sizeof(msgbuf),
1100 if (msn_write(md->fd, buf, strlen(buf)) < 0) { 1100 if (msn_write(md->fd, buf, strlen(buf)) < 0) {
1101 hide_login_progress(map->gc, _("Write error")); 1101 hide_login_progress(map->gc, _("Write error"));
1102 signoff(map->gc); 1102 signoff(map->gc);
1103 return; 1103 return;
1104 } 1104 }
1105 gaim_privacy_permit_add(map->gc->user, map->user); 1105 gaim_privacy_permit_add(map->gc->account, map->user);
1106 build_allow_list(); /* er. right. we'll need to have a thing for this in CUI too */ 1106 build_allow_list(); /* er. right. we'll need to have a thing for this in CUI too */
1107 show_got_added(map->gc, NULL, map->user, map->friend, NULL); 1107 show_got_added(map->gc, NULL, map->user, map->friend, NULL);
1108 } 1108 }
1109 1109
1110 g_free(map->user); 1110 g_free(map->user);
1122 if (msn_write(md->fd, buf, strlen(buf)) < 0) { 1122 if (msn_write(md->fd, buf, strlen(buf)) < 0) {
1123 hide_login_progress(map->gc, _("Write error")); 1123 hide_login_progress(map->gc, _("Write error"));
1124 signoff(map->gc); 1124 signoff(map->gc);
1125 return; 1125 return;
1126 } 1126 }
1127 gaim_privacy_deny_add(map->gc->user, map->user); 1127 gaim_privacy_deny_add(map->gc->account, map->user);
1128 build_block_list(); 1128 build_block_list();
1129 } 1129 }
1130 1130
1131 g_free(map->user); 1131 g_free(map->user);
1132 g_free(map->friend); 1132 g_free(map->friend);
1139 char sendbuf[MSN_BUF_LEN]; 1139 char sendbuf[MSN_BUF_LEN];
1140 1140
1141 if (!g_strncasecmp(buf, "ADD", 3)) { 1141 if (!g_strncasecmp(buf, "ADD", 3)) {
1142 char *list, *user, *friend, *tmp = buf; 1142 char *list, *user, *friend, *tmp = buf;
1143 struct msn_add_permit *ap; 1143 struct msn_add_permit *ap;
1144 GSList *perm = gc->user->permit; 1144 GSList *perm = gc->account->permit;
1145 char msg[MSN_BUF_LEN]; 1145 char msg[MSN_BUF_LEN];
1146 1146
1147 GET_NEXT(tmp); 1147 GET_NEXT(tmp);
1148 GET_NEXT(tmp); 1148 GET_NEXT(tmp);
1149 list = tmp; 1149 list = tmp;
1184 if (!g_strcasecmp(type, "AL")) { 1184 if (!g_strcasecmp(type, "AL")) {
1185 /* If the current setting is AL, messages 1185 /* If the current setting is AL, messages
1186 * from users who are not in BL will be delivered 1186 * from users who are not in BL will be delivered
1187 * 1187 *
1188 * In other words, deny some */ 1188 * In other words, deny some */
1189 gc->user->permdeny = DENY_SOME; 1189 gc->account->permdeny = DENY_SOME;
1190 } else { 1190 } else {
1191 /* If the current 1191 /* If the current
1192 * setting is BL, only messages from people who are in the AL will be 1192 * setting is BL, only messages from people who are in the AL will be
1193 * delivered. 1193 * delivered.
1194 * 1194 *
1195 * In other words, permit some */ 1195 * In other words, permit some */
1196 gc->user->permdeny = PERMIT_SOME; 1196 gc->account->permdeny = PERMIT_SOME;
1197 } 1197 }
1198 } else if (!g_strncasecmp(buf, "BPR", 3)) { 1198 } else if (!g_strncasecmp(buf, "BPR", 3)) {
1199 } else if (!g_strncasecmp(buf, "CHG", 3)) { 1199 } else if (!g_strncasecmp(buf, "CHG", 3)) {
1200 } else if (!g_strncasecmp(buf, "CHL", 3)) { 1200 } else if (!g_strncasecmp(buf, "CHL", 3)) {
1201 char *hash = buf; 1201 char *hash = buf;
1264 1264
1265 serv_got_update(gc, user, 1, 0, 0, 0, status, 0); 1265 serv_got_update(gc, user, 1, 0, 0, 0, status, 0);
1266 } else if (!g_strncasecmp(buf, "LST", 3)) { 1266 } else if (!g_strncasecmp(buf, "LST", 3)) {
1267 char *which, *who, *friend, *tmp = buf; 1267 char *which, *who, *friend, *tmp = buf;
1268 struct msn_add_permit *ap; /* for any as yet undealt with buddies who've added you to their buddy list when you were off-line. How dare they! */ 1268 struct msn_add_permit *ap; /* for any as yet undealt with buddies who've added you to their buddy list when you were off-line. How dare they! */
1269 GSList *perm = gc->user->permit; /* current permit list */ 1269 GSList *perm = gc->account->permit; /* current permit list */
1270 GSList *denyl = gc->user->deny; 1270 GSList *denyl = gc->account->deny;
1271 char msg[MSN_BUF_LEN]; 1271 char msg[MSN_BUF_LEN];
1272 int new = 1; 1272 int new = 1;
1273 int pos, tot; 1273 int pos, tot;
1274 1274
1275 GET_NEXT(tmp); 1275 GET_NEXT(tmp);
1291 struct msn_buddy *b = g_new0(struct msn_buddy, 1); 1291 struct msn_buddy *b = g_new0(struct msn_buddy, 1);
1292 b->user = g_strdup(who); 1292 b->user = g_strdup(who);
1293 b->friend = g_strdup(friend); 1293 b->friend = g_strdup(friend);
1294 md->fl = g_slist_append(md->fl, b); 1294 md->fl = g_slist_append(md->fl, b);
1295 } else if (!g_strcasecmp(which, "AL") && pos) { 1295 } else if (!g_strcasecmp(which, "AL") && pos) {
1296 if (g_slist_find_custom(gc->user->deny, who, 1296 if (g_slist_find_custom(gc->account->deny, who,
1297 (GCompareFunc)strcmp)) { 1297 (GCompareFunc)strcmp)) {
1298 debug_printf("moving from deny to permit: %s", who); 1298 debug_printf("moving from deny to permit: %s", who);
1299 gaim_privacy_deny_remove(gc->user, who); 1299 gaim_privacy_deny_remove(gc->account, who);
1300 } 1300 }
1301 gaim_privacy_permit_add(gc->user, who); 1301 gaim_privacy_permit_add(gc->account, who);
1302 } else if (!g_strcasecmp(which, "BL") && pos) { 1302 } else if (!g_strcasecmp(which, "BL") && pos) {
1303 gaim_privacy_deny_add(gc->user, who); 1303 gaim_privacy_deny_add(gc->account, who);
1304 } else if (!g_strcasecmp(which, "RL")) { 1304 } else if (!g_strcasecmp(which, "RL")) {
1305 if (pos) { 1305 if (pos) {
1306 while(perm) { 1306 while(perm) {
1307 if(!g_strcasecmp(perm->data, who)) 1307 if(!g_strcasecmp(perm->data, who))
1308 new = 0; 1308 new = 0;
1336 } 1336 }
1337 1337
1338 account_online(gc); 1338 account_online(gc);
1339 serv_finish_login(gc); 1339 serv_finish_login(gc);
1340 1340
1341 md->permit = g_slist_copy(gc->user->permit); 1341 md->permit = g_slist_copy(gc->account->permit);
1342 md->deny = g_slist_copy(gc->user->deny); 1342 md->deny = g_slist_copy(gc->account->deny);
1343 1343
1344 while (md->fl) { 1344 while (md->fl) {
1345 struct msn_buddy *mb = md->fl->data; 1345 struct msn_buddy *mb = md->fl->data;
1346 struct buddy *b = find_buddy(gc->user, mb->user); 1346 struct buddy *b = find_buddy(gc->account, mb->user);
1347 md->fl = g_slist_remove(md->fl, mb); 1347 md->fl = g_slist_remove(md->fl, mb);
1348 if(!b) 1348 if(!b)
1349 b = add_buddy(gc->user, _("Buddies"), mb->user, NULL); 1349 b = add_buddy(gc->account, _("Buddies"), mb->user, NULL);
1350 serv_got_alias(gc, mb->user, mb->friend); 1350 serv_got_alias(gc, mb->user, mb->friend);
1351 g_free(mb->user); 1351 g_free(mb->user);
1352 g_free(mb->friend); 1352 g_free(mb->friend);
1353 g_free(mb); 1353 g_free(mb);
1354 } 1354 }
1991 1991
1992 md->inpa = gaim_input_add(md->fd, GAIM_INPUT_READ, msn_login_callback, gc); 1992 md->inpa = gaim_input_add(md->fd, GAIM_INPUT_READ, msn_login_callback, gc);
1993 set_login_progress(gc, 2,_("Synching with server")); 1993 set_login_progress(gc, 2,_("Synching with server"));
1994 } 1994 }
1995 1995
1996 static void msn_login(struct aim_user *user) 1996 static void msn_login(struct gaim_account *account)
1997 { 1997 {
1998 struct gaim_connection *gc = new_gaim_conn(user); 1998 struct gaim_connection *gc = new_gaim_conn(account);
1999 gc->proto_data = g_new0(struct msn_data, 1); 1999 gc->proto_data = g_new0(struct msn_data, 1);
2000 2000
2001 set_login_progress(gc, 1, _("Connecting")); 2001 set_login_progress(gc, 1, _("Connecting"));
2002 2002
2003 g_snprintf(gc->username, sizeof(gc->username), "%s", msn_normalize(gc->username)); 2003 g_snprintf(gc->username, sizeof(gc->username), "%s", msn_normalize(gc->username));
2004 2004
2005 if (proxy_connect(user->proto_opt[USEROPT_MSNSERVER][0] ? user->proto_opt[USEROPT_MSNSERVER] : MSN_SERVER, 2005 if (proxy_connect(account->proto_opt[USEROPT_MSNSERVER][0] ?
2006 user->proto_opt[USEROPT_MSNPORT][0] ? atoi(user->proto_opt[USEROPT_MSNPORT]) : MSN_PORT, 2006 account->proto_opt[USEROPT_MSNSERVER] : MSN_SERVER,
2007 msn_login_connect, gc) != 0) { 2007 account->proto_opt[USEROPT_MSNPORT][0] ?
2008 atoi(account->proto_opt[USEROPT_MSNPORT]) : MSN_PORT,
2009 msn_login_connect, gc) != 0) {
2008 hide_login_progress(gc, _("Unable to connect")); 2010 hide_login_progress(gc, _("Unable to connect"));
2009 signoff(gc); 2011 signoff(gc);
2010 } 2012 }
2011 } 2013 }
2012 2014
2471 2473
2472 static GList *msn_buddy_menu(struct gaim_connection *gc, char *who) 2474 static GList *msn_buddy_menu(struct gaim_connection *gc, char *who)
2473 { 2475 {
2474 GList *m = NULL; 2476 GList *m = NULL;
2475 struct proto_buddy_menu *pbm; 2477 struct proto_buddy_menu *pbm;
2476 struct buddy *b = find_buddy(gc->user, who); 2478 struct buddy *b = find_buddy(gc->account, who);
2477 static char buf[MSN_BUF_LEN]; 2479 static char buf[MSN_BUF_LEN];
2478 2480
2479 pbm = g_new0(struct proto_buddy_menu, 1); 2481 pbm = g_new0(struct proto_buddy_menu, 1);
2480 pbm->label = _("Send File"); 2482 pbm->label = _("Send File");
2481 pbm->callback = msn_ask_send_file; 2483 pbm->callback = msn_ask_send_file;
2617 { 2619 {
2618 struct msn_data *md = gc->proto_data; 2620 struct msn_data *md = gc->proto_data;
2619 char buf[MSN_BUF_LEN]; 2621 char buf[MSN_BUF_LEN];
2620 GSList *s, *t = NULL; 2622 GSList *s, *t = NULL;
2621 2623
2622 if (gc->user->permdeny == PERMIT_ALL || gc->user->permdeny == DENY_SOME) 2624 if (gc->account->permdeny == PERMIT_ALL || gc->account->permdeny == DENY_SOME)
2623 g_snprintf(buf, sizeof(buf), "BLP %u AL\r\n", ++md->trId); 2625 g_snprintf(buf, sizeof(buf), "BLP %u AL\r\n", ++md->trId);
2624 else 2626 else
2625 g_snprintf(buf, sizeof(buf), "BLP %u BL\r\n", ++md->trId); 2627 g_snprintf(buf, sizeof(buf), "BLP %u BL\r\n", ++md->trId);
2626 2628
2627 if (msn_write(md->fd, buf, strlen(buf)) < 0) { 2629 if (msn_write(md->fd, buf, strlen(buf)) < 0) {
2631 } 2633 }
2632 2634
2633 /* this is safe because we'll always come here after we've gotten the list off the server, 2635 /* this is safe because we'll always come here after we've gotten the list off the server,
2634 * and data is never removed. So if the lengths are equal we don't know about anyone locally 2636 * and data is never removed. So if the lengths are equal we don't know about anyone locally
2635 * and so there's no sense in going through them all. */ 2637 * and so there's no sense in going through them all. */
2636 if (g_slist_length(gc->user->permit) == g_slist_length(md->permit)) { 2638 if (g_slist_length(gc->account->permit) == g_slist_length(md->permit)) {
2637 g_slist_free(md->permit); 2639 g_slist_free(md->permit);
2638 md->permit = NULL; 2640 md->permit = NULL;
2639 } 2641 }
2640 if (g_slist_length(gc->user->deny) == g_slist_length(md->deny)) { 2642 if (g_slist_length(gc->account->deny) == g_slist_length(md->deny)) {
2641 g_slist_free(md->deny); 2643 g_slist_free(md->deny);
2642 md->deny = NULL; 2644 md->deny = NULL;
2643 } 2645 }
2644 if (!md->permit && !md->deny) 2646 if (!md->permit && !md->deny)
2645 return; 2647 return;
2646 2648
2647 if (md->permit) { 2649 if (md->permit) {
2648 s = g_slist_nth(gc->user->permit, g_slist_length(md->permit)); 2650 s = g_slist_nth(gc->account->permit, g_slist_length(md->permit));
2649 while (s) { 2651 while (s) {
2650 char *who = s->data; 2652 char *who = s->data;
2651 s = s->next; 2653 s = s->next;
2652 if (!strchr(who, '@')) { 2654 if (!strchr(who, '@')) {
2653 t = g_slist_append(t, who); 2655 t = g_slist_append(t, who);
2663 signoff(gc); 2665 signoff(gc);
2664 return; 2666 return;
2665 } 2667 }
2666 } 2668 }
2667 while (t) { 2669 while (t) {
2668 gaim_privacy_permit_remove(gc->user, t->data); 2670 gaim_privacy_permit_remove(gc->account, t->data);
2669 t = t->next; 2671 t = t->next;
2670 } 2672 }
2671 if (t) 2673 if (t)
2672 g_slist_free(t); 2674 g_slist_free(t);
2673 t = NULL; 2675 t = NULL;
2674 g_slist_free(md->permit); 2676 g_slist_free(md->permit);
2675 md->permit = NULL; 2677 md->permit = NULL;
2676 } 2678 }
2677 2679
2678 if (md->deny) { 2680 if (md->deny) {
2679 s = g_slist_nth(gc->user->deny, g_slist_length(md->deny)); 2681 s = g_slist_nth(gc->account->deny, g_slist_length(md->deny));
2680 while (s) { 2682 while (s) {
2681 char *who = s->data; 2683 char *who = s->data;
2682 s = s->next; 2684 s = s->next;
2683 if (!strchr(who, '@')) { 2685 if (!strchr(who, '@')) {
2684 t = g_slist_append(t, who); 2686 t = g_slist_append(t, who);
2694 signoff(gc); 2696 signoff(gc);
2695 return; 2697 return;
2696 } 2698 }
2697 } 2699 }
2698 while (t) { 2700 while (t) {
2699 gaim_privacy_deny_remove(gc->user, t->data); 2701 gaim_privacy_deny_remove(gc->account, t->data);
2700 t = t->next; 2702 t = t->next;
2701 } 2703 }
2702 if (t) 2704 if (t)
2703 g_slist_free(t); 2705 g_slist_free(t);
2704 g_slist_free(md->deny); 2706 g_slist_free(md->deny);
2715 g_snprintf(buf, sizeof(buf), 2717 g_snprintf(buf, sizeof(buf),
2716 _("An MSN screenname must be in the form \"user@server.com\". " 2718 _("An MSN screenname must be in the form \"user@server.com\". "
2717 "Perhaps you meant %s@hotmail.com. No changes were made to your " 2719 "Perhaps you meant %s@hotmail.com. No changes were made to your "
2718 "allow list."), who); 2720 "allow list."), who);
2719 do_error_dialog(_("Invalid MSN screenname"), buf, GAIM_ERROR); 2721 do_error_dialog(_("Invalid MSN screenname"), buf, GAIM_ERROR);
2720 gaim_privacy_permit_remove(gc->user, who); 2722 gaim_privacy_permit_remove(gc->account, who);
2721 return; 2723 return;
2722 } 2724 }
2723 2725
2724 if (g_slist_find_custom(gc->user->deny, who, (GCompareFunc)strcmp)) { 2726 if (g_slist_find_custom(gc->account->deny, who, (GCompareFunc)strcmp)) {
2725 debug_printf("MSN: Moving %s from BL to AL\n", who); 2727 debug_printf("MSN: Moving %s from BL to AL\n", who);
2726 gaim_privacy_deny_remove(gc->user, who); 2728 gaim_privacy_deny_remove(gc->account, who);
2727 g_snprintf(buf, sizeof(buf), "REM %u BL %s\r\n", ++md->trId, who); 2729 g_snprintf(buf, sizeof(buf), "REM %u BL %s\r\n", ++md->trId, who);
2728 if (msn_write(md->fd, buf, strlen(buf)) < 0) { 2730 if (msn_write(md->fd, buf, strlen(buf)) < 0) {
2729 hide_login_progress(gc, _("Write error")); 2731 hide_login_progress(gc, _("Write error"));
2730 signoff(gc); 2732 signoff(gc);
2731 return; 2733 return;
2749 hide_login_progress(gc, _("Write error")); 2751 hide_login_progress(gc, _("Write error"));
2750 signoff(gc); 2752 signoff(gc);
2751 return; 2753 return;
2752 } 2754 }
2753 2755
2754 gaim_privacy_deny_add(gc->user, who); 2756 gaim_privacy_deny_add(gc->account, who);
2755 g_snprintf(buf, sizeof(buf), "ADD %u BL %s %s\r\n", ++md->trId, who, who); 2757 g_snprintf(buf, sizeof(buf), "ADD %u BL %s %s\r\n", ++md->trId, who, who);
2756 if (msn_write(md->fd, buf, strlen(buf)) < 0) { 2758 if (msn_write(md->fd, buf, strlen(buf)) < 0) {
2757 hide_login_progress(gc, _("Write error")); 2759 hide_login_progress(gc, _("Write error"));
2758 signoff(gc); 2760 signoff(gc);
2759 return; 2761 return;
2769 g_snprintf(buf, sizeof(buf), 2771 g_snprintf(buf, sizeof(buf),
2770 _("An MSN screenname must be in the form \"user@server.com\". " 2772 _("An MSN screenname must be in the form \"user@server.com\". "
2771 "Perhaps you meant %s@hotmail.com. No changes were made to your " 2773 "Perhaps you meant %s@hotmail.com. No changes were made to your "
2772 "block list."), who); 2774 "block list."), who);
2773 do_error_dialog(_("Invalid MSN screenname"), buf, GAIM_ERROR); 2775 do_error_dialog(_("Invalid MSN screenname"), buf, GAIM_ERROR);
2774 gaim_privacy_deny_remove(gc->user, who); 2776 gaim_privacy_deny_remove(gc->account, who);
2775 return; 2777 return;
2776 } 2778 }
2777 2779
2778 if (g_slist_find_custom(gc->user->permit, who, (GCompareFunc)strcmp)) { 2780 if (g_slist_find_custom(gc->account->permit, who, (GCompareFunc)strcmp)) {
2779 debug_printf("MSN: Moving %s from AL to BL\n", who); 2781 debug_printf("MSN: Moving %s from AL to BL\n", who);
2780 gaim_privacy_permit_remove(gc->user, who); 2782 gaim_privacy_permit_remove(gc->account, who);
2781 g_snprintf(buf, sizeof(buf), "REM %u AL %s\r\n", ++md->trId, who); 2783 g_snprintf(buf, sizeof(buf), "REM %u AL %s\r\n", ++md->trId, who);
2782 if (msn_write(md->fd, buf, strlen(buf)) < 0) { 2784 if (msn_write(md->fd, buf, strlen(buf)) < 0) {
2783 hide_login_progress(gc, _("Write error")); 2785 hide_login_progress(gc, _("Write error"));
2784 signoff(gc); 2786 signoff(gc);
2785 return; 2787 return;
2805 hide_login_progress(gc, _("Write error")); 2807 hide_login_progress(gc, _("Write error"));
2806 signoff(gc); 2808 signoff(gc);
2807 return; 2809 return;
2808 } 2810 }
2809 2811
2810 gaim_privacy_permit_add(gc->user, who); 2812 gaim_privacy_permit_add(gc->account, who);
2811 g_snprintf(buf, sizeof(buf), "ADD %u AL %s %s\r\n", ++md->trId, who, who); 2813 g_snprintf(buf, sizeof(buf), "ADD %u AL %s %s\r\n", ++md->trId, who, who);
2812 if (msn_write(md->fd, buf, strlen(buf)) < 0) { 2814 if (msn_write(md->fd, buf, strlen(buf)) < 0) {
2813 hide_login_progress(gc, _("Write error")); 2815 hide_login_progress(gc, _("Write error"));
2814 signoff(gc); 2816 signoff(gc);
2815 return; 2817 return;