Mercurial > pidgin
comparison src/protocols/zephyr/zephyr.c @ 8212:ad164c1ca79d
[gaim-migrate @ 8935]
a yahoo web auth fix from marv that i debated whether to commit or not (as
he did as well apparently fromt he message he left in the patch post) ;-)
also:
" Here's a large zephyr fix, tested against current CVS
and also 0.75. It does thie following:
Support a few additional zephyr formatting "@" tags,
Using the gaim_chat_set_topic function to allow the
user to set the instance that a zephyr is being sent to.
Listing people in chats (really, the zephyr protocol
doesn't allow for this, but I faked it by seeing who
has sent to a class).
Added proto options allowing for: setting the zephyr
exposure (currently, just by entering the correct text
string), and setting whether you want gaim to export
to .zephyr.subs , and .anyone (buddy list).
You also can add and remove buddies from within gaim.
It also fixes a minor (but annoying bug), where random
buffer garbage is sent with the zephyr, as an
additional zephyr field." --Arun (att) A Tharuvai
committer: Tailor Script <tailor@pidgin.im>
author | Luke Schierer <lschiere@pidgin.im> |
---|---|
date | Thu, 05 Feb 2004 16:28:51 +0000 |
parents | 9d1a984681fe |
children | f24172f53650 |
comparison
equal
deleted
inserted
replaced
8211:99a87d90b570 | 8212:ad164c1ca79d |
---|---|
23 * | 23 * |
24 */ | 24 */ |
25 /* XXX eww */ | 25 /* XXX eww */ |
26 #include "src/internal.h" | 26 #include "src/internal.h" |
27 | 27 |
28 #include "accountopt.h" | |
28 #include "debug.h" | 29 #include "debug.h" |
29 #include "multi.h" | 30 #include "multi.h" |
30 #include "notify.h" | 31 #include "notify.h" |
31 #include "prpl.h" | 32 #include "prpl.h" |
32 #include "server.h" | 33 #include "server.h" |
205 new_f->text = g_string_new("<i>"); | 206 new_f->text = g_string_new("<i>"); |
206 new_f->closing = "</i>"; | 207 new_f->closing = "</i>"; |
207 new_f->has_closer = TRUE; | 208 new_f->has_closer = TRUE; |
208 frames = new_f; | 209 frames = new_f; |
209 cnt += end+1; /* cnt points to char after opener */ | 210 cnt += end+1; /* cnt points to char after opener */ |
210 } else if (!g_ascii_strcasecmp(buf, "bold") | 211 } else if (!g_ascii_strcasecmp(buf,"small")) { |
211 || !g_ascii_strcasecmp(buf, "b")) { | 212 new_f = g_new(zframe,1); |
213 new_f->enclosing = frames; | |
214 new_f->text = g_string_new("<font size=\"1\">"); | |
215 new_f->closing ="</font>"; | |
216 frames = new_f; | |
217 cnt+= end+1; | |
218 } else if (!g_ascii_strcasecmp(buf,"normal")) { | |
219 new_f = g_new(zframe,1); | |
220 new_f->enclosing = frames; | |
221 new_f->text = g_string_new("<font size=\"3\">"); | |
222 new_f->closing ="</font>"; | |
223 frames = new_f; | |
224 cnt+= end+1; | |
225 } else if (!g_ascii_strcasecmp(buf,"large")) { | |
226 new_f = g_new(zframe,1); | |
227 new_f->enclosing = frames; | |
228 new_f->text = g_string_new("<font size=\"5\">"); | |
229 new_f->closing ="</font>"; | |
230 frames = new_f; | |
231 cnt+= end+1; | |
232 } else if (!g_ascii_strcasecmp(buf, "bold") | |
233 || !g_ascii_strcasecmp(buf, "b")) { | |
212 new_f = g_new(zframe, 1); | 234 new_f = g_new(zframe, 1); |
213 new_f->enclosing = frames; | 235 new_f->enclosing = frames; |
214 new_f->text = g_string_new("<b>"); | 236 new_f->text = g_string_new("<b>"); |
215 new_f->closing = "</b>"; | 237 new_f->closing = "</b>"; |
216 new_f->has_closer = TRUE; | 238 new_f->has_closer = TRUE; |
363 } else { | 385 } else { |
364 char *buf, *buf2; | 386 char *buf, *buf2; |
365 char *send_inst; | 387 char *send_inst; |
366 char *realmptr; | 388 char *realmptr; |
367 char *sendertmp; | 389 char *sendertmp; |
390 GaimConversation *gconv1; | |
391 GaimConvChat *gcc; | |
368 char *ptr = notice.z_message + strlen(notice.z_message) + 1; | 392 char *ptr = notice.z_message + strlen(notice.z_message) + 1; |
369 int len = notice.z_message_len - ((int)ptr - (int)notice.z_message); | 393 int len = notice.z_message_len - ((int)ptr - (int)notice.z_message); |
370 GaimConvImFlags flags = 0; | 394 GaimConvImFlags flags = 0; |
371 if (len > 0) { | 395 if (len > 0) { |
372 buf = g_malloc(len + 1); | 396 buf = g_malloc(len + 1); |
385 notice.z_recipient); | 409 notice.z_recipient); |
386 zt2 = find_sub_by_triple(zt1); | 410 zt2 = find_sub_by_triple(zt1); |
387 if (!zt2) { | 411 if (!zt2) { |
388 /* we shouldn't be subscribed to this message. ignore. */ | 412 /* we shouldn't be subscribed to this message. ignore. */ |
389 } else { | 413 } else { |
414 GList *gltmp; | |
415 int found=0; | |
390 if (!zt2->open) { | 416 if (!zt2->open) { |
391 zt2->open = TRUE; | 417 zt2->open = TRUE; |
392 serv_got_joined_chat(zgc, zt2->id, zt2->name); | 418 serv_got_joined_chat(zgc, zt2->id, zt2->name); |
419 gconv1 = gaim_find_conversation_with_account(zt2->name,zgc->account); | |
420 gcc = gaim_conversation_get_chat_data(gconv1); | |
421 gaim_conv_chat_set_topic(gcc,sendertmp,notice.z_class_inst); | |
422 | |
393 } | 423 } |
394 /* If the person is in the default Realm, then strip the | 424 /* If the person is in the default Realm, then strip the |
395 Realm from the sender field */ | 425 Realm from the sender field */ |
396 sendertmp = g_strdup_printf("%s",notice.z_sender); | 426 sendertmp = g_strdup_printf("%s",notice.z_sender); |
397 if ((realmptr = strchr(sendertmp,'@')) != NULL) { | 427 if ((realmptr = strchr(sendertmp,'@')) != NULL) { |
408 } else { | 438 } else { |
409 send_inst = g_strdup_printf("%s %s",sendertmp,notice.z_class_inst); | 439 send_inst = g_strdup_printf("%s %s",sendertmp,notice.z_class_inst); |
410 } | 440 } |
411 serv_got_chat_in(zgc, zt2->id, send_inst, FALSE, | 441 serv_got_chat_in(zgc, zt2->id, send_inst, FALSE, |
412 buf2, time(NULL)); | 442 buf2, time(NULL)); |
443 | |
444 gconv1 = gaim_find_conversation_with_account(zt2->name,zgc->account); | |
445 gcc = gaim_conversation_get_chat_data(gconv1); | |
446 gaim_conv_chat_set_topic(gcc,sendertmp,notice.z_class_inst); | |
447 for(gltmp = gaim_conv_chat_get_users(gcc);gltmp;gltmp=gltmp->next) { | |
448 if (!g_ascii_strcasecmp(gltmp->data,sendertmp) ) | |
449 found = 1; | |
450 } | |
451 if (!found) { | |
452 /* force interpretation in network byte order */ | |
453 unsigned char* addrs = (unsigned char *)&(notice.z_sender_addr.s_addr); | |
454 gaim_conv_chat_add_user(gcc,sendertmp,g_strdup_printf("%hhd.%hhd.%hhd.%hhd", | |
455 (unsigned char)addrs[0], | |
456 (unsigned char)addrs[1], | |
457 (unsigned char)addrs[2], | |
458 (unsigned char)addrs[3])); | |
459 | |
460 } | |
413 g_free(sendertmp); | 461 g_free(sendertmp); |
414 g_free(send_inst); | 462 g_free(send_inst); |
415 } | 463 } |
416 free_triple(zt1); | 464 free_triple(zt1); |
417 } | 465 } |
589 filename = g_strconcat(gaim_home_dir(), "/.anyone", NULL); | 637 filename = g_strconcat(gaim_home_dir(), "/.anyone", NULL); |
590 if ((fd = fopen(filename, "r")) != NULL) { | 638 if ((fd = fopen(filename, "r")) != NULL) { |
591 while (fgets(buff, BUFSIZ, fd)) { | 639 while (fgets(buff, BUFSIZ, fd)) { |
592 strip_comments(buff); | 640 strip_comments(buff); |
593 if (buff[0]) { | 641 if (buff[0]) { |
594 b = gaim_buddy_new(zgc->account, buff, NULL); | 642 if(! (b=gaim_find_buddy(zgc->account,buff))) { |
595 gaim_blist_add_buddy(b, NULL, g, NULL); | 643 b = gaim_buddy_new(zgc->account, buff, NULL); |
644 gaim_blist_add_buddy(b, NULL, g, NULL); | |
645 } | |
596 } | 646 } |
597 } | 647 } |
598 fclose(fd); | 648 fclose(fd); |
599 } | 649 } |
600 g_free(filename); | 650 g_free(filename); |
615 | 665 |
616 zgc = gaim_account_get_connection(account); | 666 zgc = gaim_account_get_connection(account); |
617 | 667 |
618 z_call_s(ZInitialize(), "Couldn't initialize zephyr"); | 668 z_call_s(ZInitialize(), "Couldn't initialize zephyr"); |
619 z_call_s(ZOpenPort(NULL), "Couldn't open port"); | 669 z_call_s(ZOpenPort(NULL), "Couldn't open port"); |
620 z_call_s(ZSetLocation(get_exposure_level()), "Couldn't set location"); | 670 z_call_s(ZSetLocation(gaim_account_get_string(zgc->account,"exposure_level",EXPOSE_REALMVIS)), "Couldn't set location"); |
621 | 671 |
622 sub.zsub_class = "MESSAGE"; | 672 sub.zsub_class = "MESSAGE"; |
623 sub.zsub_classinst = "PERSONAL"; | 673 sub.zsub_classinst = "PERSONAL"; |
624 sub.zsub_recipient = ZGetSender(); | 674 sub.zsub_recipient = ZGetSender(); |
625 | 675 |
694 if(!GAIM_BLIST_NODE_IS_GROUP(gnode)) | 744 if(!GAIM_BLIST_NODE_IS_GROUP(gnode)) |
695 continue; | 745 continue; |
696 for(cnode = gnode->child; cnode; cnode = cnode->next) { | 746 for(cnode = gnode->child; cnode; cnode = cnode->next) { |
697 if(!GAIM_BLIST_NODE_IS_CONTACT(cnode)) | 747 if(!GAIM_BLIST_NODE_IS_CONTACT(cnode)) |
698 continue; | 748 continue; |
699 for(bnode = gnode->child; bnode; bnode = bnode->next) { | 749 for(bnode = cnode->child; bnode; bnode = bnode->next) { |
700 if(!GAIM_BLIST_NODE_IS_BUDDY(bnode)) | 750 if(!GAIM_BLIST_NODE_IS_BUDDY(bnode)) |
701 continue; | 751 continue; |
702 b = (GaimBuddy *)bnode; | 752 b = (GaimBuddy *)bnode; |
703 if(b->account->gc == zgc) { | 753 if(b->account == zgc->account) { |
704 if ((ptr = strchr(b->name, '@')) != NULL) { | 754 if ((ptr = strchr(b->name, '@')) != NULL) { |
705 ptr2 = ptr + 1; | 755 ptr2 = ptr + 1; |
706 /* We should only strip the realm name if the principal | 756 /* We should only strip the realm name if the principal |
707 is in the user's realm | 757 is in the user's realm |
708 */ | 758 */ |
731 g_free((char*)l->data); | 781 g_free((char*)l->data); |
732 l = l->next; | 782 l = l->next; |
733 } | 783 } |
734 g_list_free(pending_zloc_names); | 784 g_list_free(pending_zloc_names); |
735 | 785 |
736 write_anyone(); | 786 if (gaim_account_get_bool(zgc->account,"write_anyone",FALSE)) |
737 write_zsubs(); | 787 write_anyone(); |
788 | |
789 if (gaim_account_get_bool(zgc->account,"write_zsubs",FALSE)) | |
790 write_zsubs(); | |
738 | 791 |
739 s = subscrips; | 792 s = subscrips; |
740 while (s) { | 793 while (s) { |
741 free_triple((zephyr_triple*)s->data); | 794 free_triple((zephyr_triple*)s->data); |
742 s = s->next; | 795 s = s->next; |
753 z_call(ZCancelSubscriptions(0)); | 806 z_call(ZCancelSubscriptions(0)); |
754 z_call(ZUnsetLocation()); | 807 z_call(ZUnsetLocation()); |
755 z_call(ZClosePort()); | 808 z_call(ZClosePort()); |
756 } | 809 } |
757 | 810 |
758 static void zephyr_add_buddy(GaimConnection *gc, const char *buddy, GaimGroup *group) { } | 811 static void zephyr_add_buddy(GaimConnection *gc, const char *buddy, GaimGroup *group) { |
759 static void zephyr_remove_buddy(GaimConnection *gc, const char *buddy, const char *group) { } | 812 GaimBuddy *b; |
813 if(! (b=gaim_find_buddy(zgc->account,buddy))) { | |
814 b = gaim_buddy_new(zgc->account, buddy, NULL); | |
815 gaim_blist_add_buddy(b, NULL, group, NULL); | |
816 } | |
817 | |
818 } | |
819 | |
820 static void zephyr_remove_buddy(GaimConnection *gc, const char *buddy, const char *group) { | |
821 GaimBuddy *b; | |
822 fprintf(stderr,"In zephyr_remove_buddy\n"); | |
823 if ((b=gaim_find_buddy(zgc->account,buddy))) | |
824 gaim_blist_remove_buddy(b); | |
825 else | |
826 fprintf(stderr,"attempt to remove non-existent buddy %s\n",buddy); | |
827 } | |
760 | 828 |
761 static int zephyr_chat_send(GaimConnection *gc, int id, const char *im) | 829 static int zephyr_chat_send(GaimConnection *gc, int id, const char *im) |
762 { | 830 { |
763 ZNotice_t notice; | 831 ZNotice_t notice; |
764 zephyr_triple *zt; | 832 zephyr_triple *zt; |
765 char *buf; | 833 char *buf; |
766 const char *sig; | 834 const char *sig; |
835 GaimConversation * gconv1; | |
836 GaimConvChat* gcc; | |
837 char * inst; | |
767 | 838 |
768 zt = find_sub_by_id(id); | 839 zt = find_sub_by_id(id); |
769 if (!zt) | 840 if (!zt) |
770 /* this should never happen. */ | 841 /* this should never happen. */ |
771 return -EINVAL; | 842 return -EINVAL; |
774 if (!sig) { | 845 if (!sig) { |
775 sig = g_get_real_name(); | 846 sig = g_get_real_name(); |
776 } | 847 } |
777 buf = g_strdup_printf("%s%c%s", sig, '\0', im); | 848 buf = g_strdup_printf("%s%c%s", sig, '\0', im); |
778 | 849 |
850 gconv1 = gaim_find_conversation_with_account(zt->name,zgc->account); | |
851 gcc = gaim_conversation_get_chat_data(gconv1); | |
852 | |
853 if(!(inst = gaim_conv_chat_get_topic(gcc))) | |
854 inst = notice.z_class_inst; | |
855 | |
779 bzero((char *)¬ice, sizeof(notice)); | 856 bzero((char *)¬ice, sizeof(notice)); |
780 notice.z_kind = ACKED; | 857 notice.z_kind = ACKED; |
781 notice.z_port = 0; | 858 notice.z_port = 0; |
782 notice.z_opcode = ""; | 859 notice.z_opcode = ""; |
783 notice.z_class = zt->class; | 860 notice.z_class = zt->class; |
784 notice.z_class_inst = zt->instance; | 861 notice.z_class_inst = inst; |
785 if (!g_ascii_strcasecmp(zt->recipient, "*")) | 862 if (!g_ascii_strcasecmp(zt->recipient, "*")) |
786 notice.z_recipient = zephyr_normalize(gc->account, ""); | 863 notice.z_recipient = zephyr_normalize(gc->account, ""); |
787 else | 864 else |
788 notice.z_recipient = zephyr_normalize(gc->account, zt->recipient); | 865 notice.z_recipient = zephyr_normalize(gc->account, zt->recipient); |
789 notice.z_sender = 0; | 866 notice.z_sender = 0; |
790 notice.z_default_format = | 867 notice.z_default_format = |
791 "Class $class, Instance $instance:\n" | 868 "Class $class, Instance $instance:\n" |
792 "To: @bold($recipient) at $time $date\n" | 869 "To: @bold($recipient) at $time $date\n" |
793 "From: @bold($1) <$sender>\n\n$2"; | 870 "From: @bold($1) <$sender>\n\n$2"; |
794 notice.z_message_len = strlen(im) + strlen(sig) + 4; | 871 notice.z_message_len = strlen(im) + strlen(sig) + 2; |
795 notice.z_message = buf; | 872 notice.z_message = buf; |
796 ZSendNotice(¬ice, ZAUTH); | 873 ZSendNotice(¬ice, ZAUTH); |
797 g_free(buf); | 874 g_free(buf); |
798 return 0; | 875 return 0; |
799 } | 876 } |
823 notice.z_recipient = who; | 900 notice.z_recipient = who; |
824 notice.z_default_format = | 901 notice.z_default_format = |
825 "Class $class, Instance $instance:\n" | 902 "Class $class, Instance $instance:\n" |
826 "To: @bold($recipient) at $time $date\n" | 903 "To: @bold($recipient) at $time $date\n" |
827 "From: @bold($1) <$sender>\n\n$2"; | 904 "From: @bold($1) <$sender>\n\n$2"; |
828 notice.z_message_len = strlen(im) + strlen(sig) + 4; | 905 notice.z_message_len = strlen(im) + strlen(sig) + 2; |
829 notice.z_message = buf; | 906 notice.z_message = buf; |
830 ZSendNotice(¬ice, ZAUTH); | 907 ZSendNotice(¬ice, ZAUTH); |
831 g_free(buf); | 908 g_free(buf); |
832 return 1; | 909 return 1; |
833 } | 910 } |
976 static const char *zephyr_list_icon(GaimAccount *a, GaimBuddy *b) | 1053 static const char *zephyr_list_icon(GaimAccount *a, GaimBuddy *b) |
977 { | 1054 { |
978 return "zephyr"; | 1055 return "zephyr"; |
979 } | 1056 } |
980 | 1057 |
1058 | |
1059 static void zephyr_chat_set_topic(GaimConnection *gc, int id, const char *topic) { | |
1060 zephyr_triple *zt; | |
1061 GaimConversation *gconv; | |
1062 GaimConvChat* gcc; | |
1063 char* sender = ZGetSender(); | |
1064 | |
1065 zt = find_sub_by_id(id); | |
1066 gconv = gaim_find_conversation_with_account(zt->name,zgc->account); | |
1067 gcc = gaim_conversation_get_chat_data(gconv); | |
1068 gaim_conv_chat_set_topic(gcc,sender,topic); | |
1069 | |
1070 } | |
1071 | |
981 static GaimPlugin *my_protocol = NULL; | 1072 static GaimPlugin *my_protocol = NULL; |
982 | 1073 |
983 static GaimPluginProtocolInfo prpl_info = | 1074 static GaimPluginProtocolInfo prpl_info = |
984 { | 1075 { |
985 OPT_PROTO_NO_PASSWORD, | 1076 OPT_PROTO_CHAT_TOPIC | OPT_PROTO_NO_PASSWORD, |
986 NULL, | 1077 NULL, |
987 NULL, | 1078 NULL, |
988 NULL, | 1079 NULL, |
989 zephyr_list_icon, | 1080 zephyr_list_icon, |
990 NULL, | 1081 NULL, |
1028 NULL, | 1119 NULL, |
1029 NULL, | 1120 NULL, |
1030 NULL, | 1121 NULL, |
1031 NULL, | 1122 NULL, |
1032 NULL, | 1123 NULL, |
1033 NULL, | 1124 NULL, |
1034 zephyr_normalize | 1125 zephyr_normalize, |
1126 NULL, | |
1127 NULL, | |
1128 NULL, | |
1129 zephyr_chat_set_topic | |
1035 }; | 1130 }; |
1036 | 1131 |
1037 static GaimPluginInfo info = | 1132 static GaimPluginInfo info = |
1038 { | 1133 { |
1039 2, /**< api_version */ | 1134 2, /**< api_version */ |
1062 }; | 1157 }; |
1063 | 1158 |
1064 static void | 1159 static void |
1065 init_plugin(GaimPlugin *plugin) | 1160 init_plugin(GaimPlugin *plugin) |
1066 { | 1161 { |
1162 GaimAccountOption *option; | |
1163 char* tmp = get_exposure_level(); | |
1164 option = gaim_account_option_bool_new(_("Export to .anyone"),"write_anyone",FALSE); | |
1165 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options,option); | |
1166 | |
1167 option = gaim_account_option_bool_new(_("Export to .zephyr.subs"),"write_zsubs",FALSE); | |
1168 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options,option); | |
1169 | |
1170 option = gaim_account_option_string_new(_("Exposure"),"exposure_level",tmp?tmp:EXPOSE_REALMVIS); | |
1171 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options,option); | |
1172 | |
1067 my_protocol = plugin; | 1173 my_protocol = plugin; |
1068 } | 1174 } |
1069 | 1175 |
1070 GAIM_INIT_PLUGIN(zephyr, init_plugin, info); | 1176 GAIM_INIT_PLUGIN(zephyr, init_plugin, info); |