comparison src/protocols/zephyr/zephyr.c @ 8354:43dec50d8d51

[gaim-migrate @ 9078] " An update to com_err on debian appears to have broken the ability of the zephyr plugin to compile with krb4. Here's a patch, tested against comerr-dev 2.1-1.34+1.35-WIP-2004.01.31-1 in debian, and an older version of com_err local to MIT, that fixes this. I haven't tested this against non-kerberized zephyr, or against other versions of com_err. A lot of the comerr (error table) related code appears to be unnecessary. This also fixes two other issues: 1) Upon each login, every entry in the "Anyone" group was getting added to the Buddies group. I didn't notice this earlier, since I usually don't restart gaim very often. 2) No more compile warnings. This also replaces occurrences of ZGetSender and ZGetRealm with gaim_zephyr_get_sender and gaim_zephyr_get_realm(), in preparation for getting gaim to alternately use an external program, "tzc" to talk to zephyr." --Arun A Tharuvai, aka, the lone gaim zepher user committer: Tailor Script <tailor@pidgin.im>
author Luke Schierer <lschiere@pidgin.im>
date Fri, 27 Feb 2004 19:25:27 +0000
parents ef881489396e
children 143d0b29ba82
comparison
equal deleted inserted replaced
8353:8ae61bbc479f 8354:43dec50d8d51
70 #define z_call_s(func, err) if (func != ZERR_NONE) {\ 70 #define z_call_s(func, err) if (func != ZERR_NONE) {\
71 gaim_connection_error(zgc, err);\ 71 gaim_connection_error(zgc, err);\
72 return;\ 72 return;\
73 } 73 }
74 74
75 static const char *local_zephyr_normalize(const char *);
75 static const char *zephyr_normalize(const GaimAccount *, const char *); 76 static const char *zephyr_normalize(const GaimAccount *, const char *);
76 77
77 /* this is so bad, and if Zephyr weren't so fucked up to begin with I 78 /* this is so bad, and if Zephyr weren't so fucked up to begin with I
78 * wouldn't do this. but it is so i will. */ 79 * wouldn't do this. but it is so i will. */
79 static guint32 nottimer = 0; 80 static guint32 nottimer = 0;
117 g_free(zt->class); 118 g_free(zt->class);
118 g_free(zt->instance); 119 g_free(zt->instance);
119 g_free(zt->recipient); 120 g_free(zt->recipient);
120 g_free(zt->name); 121 g_free(zt->name);
121 g_free(zt); 122 g_free(zt);
123 }
124
125 static const char* gaim_zephyr_get_sender() {
126 /* will be useful once this plugin can use a backend other
127 than libzephyr */
128 return ZGetSender();
129 }
130
131 static const char* gaim_zephyr_get_realm() {
132 /* will be useful once this plugin can use a backend other
133 than libzephyr */
134 return ZGetRealm();
122 } 135 }
123 136
124 /* returns true if zt1 is a subset of zt2, i.e. zt2 has the same thing or 137 /* returns true if zt1 is a subset of zt2, i.e. zt2 has the same thing or
125 * wildcards in each field of zt1. */ 138 * wildcards in each field of zt1. */
126 static gboolean triple_subset(zephyr_triple *zt1, zephyr_triple *zt2) 139 static gboolean triple_subset(zephyr_triple *zt1, zephyr_triple *zt2)
327 340
328 static gboolean pending_zloc(char *who) 341 static gboolean pending_zloc(char *who)
329 { 342 {
330 GList *curr; 343 GList *curr;
331 for (curr = pending_zloc_names; curr != NULL; curr = curr->next) { 344 for (curr = pending_zloc_names; curr != NULL; curr = curr->next) {
332 if (!g_ascii_strcasecmp(zephyr_normalize(NULL, who), (char*)curr->data)) { 345 if (!g_ascii_strcasecmp(local_zephyr_normalize(who), (char*)curr->data)) {
333 g_free((char*)curr->data); 346 g_free((char*)curr->data);
334 pending_zloc_names = g_list_remove(pending_zloc_names, curr->data); 347 pending_zloc_names = g_list_remove(pending_zloc_names, curr->data);
335 return TRUE; 348 return TRUE;
336 } 349 }
337 } 350 }
384 } 397 }
385 } else { 398 } else {
386 char *buf, *buf2; 399 char *buf, *buf2;
387 char *send_inst; 400 char *send_inst;
388 char *realmptr; 401 char *realmptr;
389 char *sendertmp;
390 GaimConversation *gconv1; 402 GaimConversation *gconv1;
391 GaimConvChat *gcc; 403 GaimConvChat *gcc;
392 char *ptr = notice.z_message + strlen(notice.z_message) + 1; 404 char *ptr = notice.z_message + strlen(notice.z_message) + 1;
393 int len = notice.z_message_len - ((int)ptr - (int)notice.z_message); 405 int len = notice.z_message_len - ((int)ptr - (int)notice.z_message);
406 char *sendertmp = g_strdup_printf("%s",gaim_zephyr_get_sender());
394 GaimConvImFlags flags = 0; 407 GaimConvImFlags flags = 0;
395 if (len > 0) { 408 if (len > 0) {
396 buf = g_malloc(len + 1); 409 buf = g_malloc(len + 1);
397 g_snprintf(buf, len + 1, "%s", ptr); 410 g_snprintf(buf, len + 1, "%s", ptr);
398 g_strchomp(buf); 411 g_strchomp(buf);
424 /* If the person is in the default Realm, then strip the 437 /* If the person is in the default Realm, then strip the
425 Realm from the sender field */ 438 Realm from the sender field */
426 sendertmp = g_strdup_printf("%s",notice.z_sender); 439 sendertmp = g_strdup_printf("%s",notice.z_sender);
427 if ((realmptr = strchr(sendertmp,'@')) != NULL) { 440 if ((realmptr = strchr(sendertmp,'@')) != NULL) {
428 realmptr++; 441 realmptr++;
429 if (!g_ascii_strcasecmp(realmptr,ZGetRealm())) { 442 if (!g_ascii_strcasecmp(realmptr,gaim_zephyr_get_realm())) {
430 realmptr--; 443 realmptr--;
431 sprintf(realmptr,"%c",'\0'); 444 sprintf(realmptr,"%c",'\0');
432 send_inst = g_strdup_printf("%s %s",sendertmp, 445 send_inst = g_strdup_printf("%s %s",sendertmp,
433 notice.z_class_inst); 446 notice.z_class_inst);
434 } else { 447 } else {
441 serv_got_chat_in(zgc, zt2->id, send_inst, FALSE, 454 serv_got_chat_in(zgc, zt2->id, send_inst, FALSE,
442 buf2, time(NULL)); 455 buf2, time(NULL));
443 456
444 gconv1 = gaim_find_conversation_with_account(zt2->name,zgc->account); 457 gconv1 = gaim_find_conversation_with_account(zt2->name,zgc->account);
445 gcc = gaim_conversation_get_chat_data(gconv1); 458 gcc = gaim_conversation_get_chat_data(gconv1);
446 gaim_conv_chat_set_topic(gcc,sendertmp,notice.z_class_inst); 459 /* gaim_conv_chat_set_topic(gcc,sendertmp,notice.z_class_inst); */
447 for(gltmp = gaim_conv_chat_get_users(gcc);gltmp;gltmp=gltmp->next) { 460 for(gltmp = gaim_conv_chat_get_users(gcc);gltmp;gltmp=gltmp->next) {
448 if (!g_ascii_strcasecmp(gltmp->data,sendertmp) ) 461 if (!g_ascii_strcasecmp(gltmp->data,sendertmp) )
449 found = 1; 462 found = 1;
450 } 463 }
451 if (!found) { 464 if (!found) {
512 GaimBuddy *b = (GaimBuddy *)bnode; 525 GaimBuddy *b = (GaimBuddy *)bnode;
513 if(!GAIM_BLIST_NODE_IS_BUDDY(bnode)) 526 if(!GAIM_BLIST_NODE_IS_BUDDY(bnode))
514 continue; 527 continue;
515 if(b->account->gc == zgc) { 528 if(b->account->gc == zgc) {
516 const char *chk; 529 const char *chk;
517 chk = zephyr_normalize(b->account, b->name); 530 chk = local_zephyr_normalize(b->name);
518 /* doesn't matter if this fails or not; we'll just move on to the next one */ 531 /* doesn't matter if this fails or not; we'll just move on to the next one */
519 ZRequestLocations(chk, &ald, UNACKED, ZAUTH); 532 ZRequestLocations(chk, &ald, UNACKED, ZAUTH);
520 free(ald.user); 533 free(ald.user);
521 free(ald.version); 534 free(ald.version);
522 } 535 }
570 while (fgets(buff, BUFSIZ, f)) { 583 while (fgets(buff, BUFSIZ, f)) {
571 strip_comments(buff); 584 strip_comments(buff);
572 if (buff[0]) { 585 if (buff[0]) {
573 triple = g_strsplit(buff, ",", 3); 586 triple = g_strsplit(buff, ",", 3);
574 if (triple[0] && triple[1] ) { 587 if (triple[0] && triple[1] ) {
575 /* char *tmp = g_strdup_printf("%s@%s", g_getenv("USER"), ZGetRealm()); */ 588 char *tmp = g_strdup_printf("%s",gaim_zephyr_get_sender());
576 char *tmp = g_strdup_printf("%s",ZGetSender());
577 char *atptr; 589 char *atptr;
578 sub.zsub_class = triple[0]; 590 sub.zsub_class = triple[0];
579 sub.zsub_classinst = triple[1]; 591 sub.zsub_classinst = triple[1];
580 if(triple[2] == NULL) { 592 if(triple[2] == NULL) {
581 recip = g_malloc0(1); 593 recip = g_malloc0(1);
582 } else if (!g_ascii_strcasecmp(triple[2], "%me%")) { 594 } else if (!g_ascii_strcasecmp(triple[2], "%me%")) {
583 recip = g_strdup_printf("%s",ZGetSender()); 595 recip = g_strdup_printf("%s",gaim_zephyr_get_sender());
584 } else if (!g_ascii_strcasecmp(triple[2], "*")) { 596 } else if (!g_ascii_strcasecmp(triple[2], "*")) {
585 /* wildcard 597 /* wildcard
586 * form of class,instance,* */ 598 * form of class,instance,* */
587 recip = g_malloc0(1); 599 recip = g_malloc0(1);
588 } else if (!g_ascii_strcasecmp(triple[2], tmp)) { 600 } else if (!g_ascii_strcasecmp(triple[2], tmp)) {
592 /* form of class,instance,*@ANDREW.CMU.EDU 604 /* form of class,instance,*@ANDREW.CMU.EDU
593 * class,instance,@ANDREW.CMU.EDU 605 * class,instance,@ANDREW.CMU.EDU
594 * If realm is local realm, blank recipient, else 606 * If realm is local realm, blank recipient, else
595 * @REALM-NAME 607 * @REALM-NAME
596 */ 608 */
597 char *realmat = g_strdup_printf("@%s", ZGetRealm()); 609 char *realmat = g_strdup_printf("@%s", gaim_zephyr_get_realm());
598 if (!g_ascii_strcasecmp(atptr, realmat)) 610 if (!g_ascii_strcasecmp(atptr, realmat))
599 recip = g_malloc0(1); 611 recip = g_malloc0(1);
600 else 612 else
601 recip = g_strdup(atptr); 613 recip = g_strdup(atptr);
602 g_free(realmat); 614 g_free(realmat);
665 677
666 zgc = gaim_account_get_connection(account); 678 zgc = gaim_account_get_connection(account);
667 679
668 z_call_s(ZInitialize(), "Couldn't initialize zephyr"); 680 z_call_s(ZInitialize(), "Couldn't initialize zephyr");
669 z_call_s(ZOpenPort(NULL), "Couldn't open port"); 681 z_call_s(ZOpenPort(NULL), "Couldn't open port");
670 z_call_s(ZSetLocation(gaim_account_get_string(zgc->account,"exposure_level",EXPOSE_REALMVIS)), "Couldn't set location"); 682 z_call_s(ZSetLocation((char *)gaim_account_get_string(zgc->account,"exposure_level",EXPOSE_REALMVIS)), "Couldn't set location");
671 683
672 sub.zsub_class = "MESSAGE"; 684 sub.zsub_class = "MESSAGE";
673 sub.zsub_classinst = "PERSONAL"; 685 sub.zsub_classinst = "PERSONAL";
674 sub.zsub_recipient = ZGetSender(); 686 sub.zsub_recipient = (char *)gaim_zephyr_get_sender();
675 687
676 /* we don't care if this fails. i'm lying right now. */ 688 /* we don't care if this fails. i'm lying right now. */
677 if (ZSubscribeTo(&sub, 1, 0) != ZERR_NONE) { 689 if (ZSubscribeTo(&sub, 1, 0) != ZERR_NONE) {
678 gaim_debug(GAIM_DEBUG_ERROR, "zephyr", 690 gaim_debug(GAIM_DEBUG_ERROR, "zephyr",
679 "Couldn't subscribe to messages!\n"); 691 "Couldn't subscribe to messages!\n");
709 zt = s->data; 721 zt = s->data;
710 triple = g_strsplit(zt->name,",",3); 722 triple = g_strsplit(zt->name,",",3);
711 if (triple[2] != NULL) { 723 if (triple[2] != NULL) {
712 if (!g_ascii_strcasecmp(triple[2], "")) { 724 if (!g_ascii_strcasecmp(triple[2], "")) {
713 fprintf(fd, "%s,%s,*\n", triple[0], triple[1]); 725 fprintf(fd, "%s,%s,*\n", triple[0], triple[1]);
714 } else if (!g_ascii_strcasecmp(triple[2], ZGetSender())) { 726 } else if (!g_ascii_strcasecmp(triple[2], gaim_zephyr_get_sender())) {
715 fprintf(fd, "%s,%s,%%me%%\n",triple[0],triple[1]); 727 fprintf(fd, "%s,%s,%%me%%\n",triple[0],triple[1]);
716 } else { 728 } else {
717 fprintf(fd, "%s\n", zt->name); 729 fprintf(fd, "%s\n", zt->name);
718 } 730 }
719 } else { 731 } else {
754 if ((ptr = strchr(b->name, '@')) != NULL) { 766 if ((ptr = strchr(b->name, '@')) != NULL) {
755 ptr2 = ptr + 1; 767 ptr2 = ptr + 1;
756 /* We should only strip the realm name if the principal 768 /* We should only strip the realm name if the principal
757 is in the user's realm 769 is in the user's realm
758 */ 770 */
759 if (!g_ascii_strcasecmp(ptr2,ZGetRealm())) { 771 if (!g_ascii_strcasecmp(ptr2,gaim_zephyr_get_realm())) {
760 *ptr = '\0'; 772 *ptr = '\0';
761 } 773 }
762 } 774 }
763 fprintf(fd, "%s\n", b->name); 775 fprintf(fd, "%s\n", b->name);
764 if (ptr) 776 if (ptr)
812 GaimBuddy *b; 824 GaimBuddy *b;
813 if(! (b=gaim_find_buddy(zgc->account,buddy))) { 825 if(! (b=gaim_find_buddy(zgc->account,buddy))) {
814 b = gaim_buddy_new(zgc->account, buddy, NULL); 826 b = gaim_buddy_new(zgc->account, buddy, NULL);
815 gaim_blist_add_buddy(b, NULL, group, NULL); 827 gaim_blist_add_buddy(b, NULL, group, NULL);
816 } 828 }
817 829 }
830
831 static void zephyr_add_buddies(GaimConnection *gc, GList* buddies) {
832 GaimGroup *group;
833 if (!(group = gaim_find_group(_("Anyone")))) {
834 group = gaim_group_new(_("Anyone"));
835 gaim_blist_add_group(group, NULL);
836 }
837 while (buddies) {
838 zephyr_add_buddy(gc, buddies->data, group);
839 buddies = buddies->next;
840 }
818 } 841 }
819 842
820 static void zephyr_remove_buddy(GaimConnection *gc, const char *buddy, const char *group) { 843 static void zephyr_remove_buddy(GaimConnection *gc, const char *buddy, const char *group) {
821 GaimBuddy *b; 844 GaimBuddy *b;
822 fprintf(stderr,"In zephyr_remove_buddy\n"); 845 fprintf(stderr,"In zephyr_remove_buddy\n");
823 if ((b=gaim_find_buddy(zgc->account,buddy))) 846 if ((b=gaim_find_buddy(zgc->account,buddy)))
824 gaim_blist_remove_buddy(b); 847 gaim_blist_remove_buddy(b);
825 else 848 else
826 fprintf(stderr,"attempt to remove non-existent buddy %s\n",buddy); 849 fprintf(stderr,"attempt to remove non-existent buddy %s\n",buddy);
850 }
851
852 static void zephyr_remove_buddies(GaimConnection *gc, GList *buddies, const char *group) {
853 GaimBuddy *b;
854 while(buddies) {
855 if ((b=gaim_find_buddy(zgc->account,buddies->data))) {
856 gaim_blist_remove_buddy(b);
857 } else {
858 fprintf(stderr,"attempt to remove non-existent buddy %s\n",(char *)buddies->data);
859 }
860 }
827 } 861 }
828 862
829 static int zephyr_chat_send(GaimConnection *gc, int id, const char *im) 863 static int zephyr_chat_send(GaimConnection *gc, int id, const char *im)
830 { 864 {
831 ZNotice_t notice; 865 ZNotice_t notice;
848 buf = g_strdup_printf("%s%c%s", sig, '\0', im); 882 buf = g_strdup_printf("%s%c%s", sig, '\0', im);
849 883
850 gconv1 = gaim_find_conversation_with_account(zt->name,zgc->account); 884 gconv1 = gaim_find_conversation_with_account(zt->name,zgc->account);
851 gcc = gaim_conversation_get_chat_data(gconv1); 885 gcc = gaim_conversation_get_chat_data(gconv1);
852 886
853 if(!(inst = gaim_conv_chat_get_topic(gcc))) 887 if(!(inst = (char *)gaim_conv_chat_get_topic(gcc)))
854 inst = notice.z_class_inst; 888 inst = (char *)notice.z_class_inst;
855 889
856 bzero((char *)&notice, sizeof(notice)); 890 bzero((char *)&notice, sizeof(notice));
857 notice.z_kind = ACKED; 891 notice.z_kind = ACKED;
858 notice.z_port = 0; 892 notice.z_port = 0;
859 notice.z_opcode = ""; 893 notice.z_opcode = "";
860 notice.z_class = zt->class; 894 notice.z_class = zt->class;
861 notice.z_class_inst = inst; 895 notice.z_class_inst = inst;
862 if (!g_ascii_strcasecmp(zt->recipient, "*")) 896 if (!g_ascii_strcasecmp(zt->recipient, "*"))
863 notice.z_recipient = zephyr_normalize(gc->account, ""); 897 notice.z_recipient = local_zephyr_normalize("");
864 else 898 else
865 notice.z_recipient = zephyr_normalize(gc->account, zt->recipient); 899 notice.z_recipient = local_zephyr_normalize(zt->recipient);
866 notice.z_sender = 0; 900 notice.z_sender = 0;
867 notice.z_default_format = 901 notice.z_default_format =
868 "Class $class, Instance $instance:\n" 902 "Class $class, Instance $instance:\n"
869 "To: @bold($recipient) at $time $date\n" 903 "To: @bold($recipient) at $time $date\n"
870 "From: @bold($1) <$sender>\n\n$2"; 904 "From: @bold($1) <$sender>\n\n$2";
913 { 947 {
914 static char buf[80]; 948 static char buf[80];
915 if (!g_ascii_strcasecmp(orig, "")) { 949 if (!g_ascii_strcasecmp(orig, "")) {
916 buf[0] = '\0'; 950 buf[0] = '\0';
917 return buf; 951 return buf;
918 } 952 } else {
953 g_snprintf(buf,80,"%s",orig);
954 }
955 return buf;
956 }
957
958
959 static const char *local_zephyr_normalize(const char *orig)
960 {
961 static char buf[80];
962 if (!g_ascii_strcasecmp(orig, "")) {
963 buf[0] = '\0';
964 return buf;
965 }
966
919 if (strchr(orig, '@')) { 967 if (strchr(orig, '@')) {
920 g_snprintf(buf, 80, "%s", orig); 968 g_snprintf(buf, 80, "%s", orig);
921 } else { 969 } else {
922 g_snprintf(buf, 80, "%s@%s", orig, ZGetRealm()); 970 g_snprintf(buf,80,"%s@%s",orig,gaim_zephyr_get_realm());
923 } 971 }
924 return buf; 972 return buf;
925 } 973 }
926 974
927 static void zephyr_zloc(GaimConnection *gc, const char *who) 975 static void zephyr_zloc(GaimConnection *gc, const char *who)
928 { 976 {
929 ZAsyncLocateData_t ald; 977 ZAsyncLocateData_t ald;
930 978
931 if (ZRequestLocations(zephyr_normalize(gc->account, who), &ald, UNACKED, ZAUTH) 979 if (ZRequestLocations(local_zephyr_normalize(who), &ald, UNACKED, ZAUTH)
932 != ZERR_NONE) { 980 != ZERR_NONE) {
933 return; 981 return;
934 } 982 }
935 pending_zloc_names = g_list_append(pending_zloc_names, 983 pending_zloc_names = g_list_append(pending_zloc_names,
936 g_strdup(zephyr_normalize(gc->account, who))); 984 g_strdup(local_zephyr_normalize(who)));
937 } 985 }
938 986
939 static GList *zephyr_buddy_menu(GaimConnection *gc, const char *who) 987 static GList *zephyr_buddy_menu(GaimConnection *gc, const char *who)
940 { 988 {
941 GList *m = NULL; 989 GList *m = NULL;
1013 1061
1014 if (!classname || !instname || !recip) 1062 if (!classname || !instname || !recip)
1015 return; 1063 return;
1016 1064
1017 if (!g_ascii_strcasecmp(recip, "%me%")) 1065 if (!g_ascii_strcasecmp(recip, "%me%"))
1018 recip = ZGetSender(); 1066 recip = gaim_zephyr_get_sender();
1019 1067
1020 zt1 = new_triple(classname, instname, recip); 1068 zt1 = new_triple(classname, instname, recip);
1021 zt2 = find_sub_by_triple(zt1); 1069 zt2 = find_sub_by_triple(zt1);
1022 if (zt2) { 1070 if (zt2) {
1023 free_triple(zt1); 1071 free_triple(zt1);
1058 1106
1059 static void zephyr_chat_set_topic(GaimConnection *gc, int id, const char *topic) { 1107 static void zephyr_chat_set_topic(GaimConnection *gc, int id, const char *topic) {
1060 zephyr_triple *zt; 1108 zephyr_triple *zt;
1061 GaimConversation *gconv; 1109 GaimConversation *gconv;
1062 GaimConvChat* gcc; 1110 GaimConvChat* gcc;
1063 char* sender = ZGetSender(); 1111 char* sender = (char *)gaim_zephyr_get_sender();
1064 1112
1065 zt = find_sub_by_id(id); 1113 zt = find_sub_by_id(id);
1066 gconv = gaim_find_conversation_with_account(zt->name,zgc->account); 1114 gconv = gaim_find_conversation_with_account(zt->name,zgc->account);
1067 gcc = gaim_conversation_get_chat_data(gconv); 1115 gcc = gaim_conversation_get_chat_data(gconv);
1068 gaim_conv_chat_set_topic(gcc,sender,topic); 1116 gaim_conv_chat_set_topic(gcc,sender,topic);
1097 NULL, 1145 NULL,
1098 NULL, 1146 NULL,
1099 NULL, 1147 NULL,
1100 NULL, 1148 NULL,
1101 zephyr_add_buddy, 1149 zephyr_add_buddy,
1102 NULL, 1150 zephyr_add_buddies,
1103 zephyr_remove_buddy, 1151 zephyr_remove_buddy,
1104 NULL, 1152 zephyr_remove_buddies,
1105 NULL, 1153 NULL,
1106 NULL, 1154 NULL,
1107 NULL, 1155 NULL,
1108 NULL, 1156 NULL,
1109 NULL, 1157 NULL,