comparison src/protocols/jabber/jabber.c @ 3229:20612da83d8c

[gaim-migrate @ 3246] Approval dialog when somebody wants to subscribe to user's presence. Also gives user the opportunity to add that buddy if not already on the user's buddy list. committer: Tailor Script <tailor@pidgin.im>
author Jim Seymour <jseymour>
date Tue, 07 May 2002 00:51:15 +0000
parents e3cba5bb2d69
children 6a96436a542a
comparison
equal deleted inserted replaced
3228:5da7dae50d87 3229:20612da83d8c
731 } 731 }
732 } 732 }
733 733
734 static time_t iso8601_to_time(char *timestamp) 734 static time_t iso8601_to_time(char *timestamp)
735 { 735 {
736 struct tm t; 736 struct tm t;
737 time_t retval = 0; 737 time_t retval = 0;
738 738
739 if(sscanf(timestamp,"%04d%02d%02dT%02d:%02d:%02d", 739 if(sscanf(timestamp,"%04d%02d%02dT%02d:%02d:%02d",
740 &t.tm_year, &t.tm_mon, &t.tm_mday, &t.tm_hour, &t.tm_min, &t.tm_sec)) 740 &t.tm_year, &t.tm_mon, &t.tm_mday, &t.tm_hour, &t.tm_min, &t.tm_sec))
741 { 741 {
742 t.tm_year -= 1900; 742 t.tm_year -= 1900;
743 t.tm_mon -= 1; 743 t.tm_mon -= 1;
744 t.tm_isdst = 0; 744 t.tm_isdst = 0;
745 retval = mktime(&t); 745 retval = mktime(&t);
746 #ifdef HAVE_TM_GMTOFF 746 # ifdef HAVE_TM_GMTOFF
747 retval += t.tm_gmtoff; 747 retval += t.tm_gmtoff;
748 #else 748 # else
749 # ifdef HAVE_TIMEZONE 749 # ifdef HAVE_TIMEZONE
750 tzset(); /* making sure */ 750 tzset(); /* making sure */
751 retval -= timezone; 751 retval -= timezone;
752 # endif 752 # endif
753 #endif 753 # endif
754 } 754 }
755 return retval; 755
756 return retval;
756 } 757 }
757 758
758 static void jabber_handlemessage(gjconn gjc, jpacket p) 759 static void jabber_handlemessage(gjconn gjc, jpacket p)
759 { 760 {
760 xmlnode y, xmlns, subj, z; 761 xmlnode y, xmlns, subj, z;
1056 g_free(buddy); 1057 g_free(buddy);
1057 1058
1058 return; 1059 return;
1059 } 1060 }
1060 1061
1062 /*
1063 * Used only by Jabber accept/deny add stuff just below
1064 */
1065 struct jabber_add_permit {
1066 gjconn gjc;
1067 gchar *user;
1068 };
1069
1070 /*
1071 * Common part for Jabber accept/deny adds
1072 *
1073 * "type" says whether we'll permit/deny the subscribe request
1074 */
1075 static void jabber_accept_deny_add(struct jabber_add_permit *jap, const char *type)
1076 {
1077 xmlnode g = xmlnode_new_tag("presence");
1078
1079 xmlnode_put_attrib(g, "to", jap->user);
1080 xmlnode_put_attrib(g, "type", type);
1081 gjab_send(jap->gjc, g);
1082
1083 xmlnode_free(g);
1084 }
1085
1086 /*
1087 * Callback from "accept" in do_ask_dialog() invoked by jabber_handles10n()
1088 */
1089 static void jabber_accept_add(gpointer w, struct jabber_add_permit *jap)
1090 {
1091 jabber_accept_deny_add(jap, "subscribed");
1092 /*
1093 * If we don't already have the buddy on *our* buddylist,
1094 * ask if we want him or her added.
1095 */
1096 if(find_buddy(GJ_GC(jap->gjc), jap->user) == NULL) {
1097 show_got_added(GJ_GC(jap->gjc), NULL, jap->user, NULL, NULL);
1098 }
1099 g_free(jap->user);
1100 g_free(jap);
1101 }
1102
1103 /*
1104 * Callback from "deny/cancel" in do_ask_dialog() invoked by jabber_handles10n()
1105 */
1106 static void jabber_deny_add(gpointer w, struct jabber_add_permit *jap)
1107 {
1108 jabber_accept_deny_add(jap, "unsubscribed");
1109 g_free(jap->user);
1110 g_free(jap);
1111 }
1112
1113 /*
1114 * Handle subscription requests
1115 */
1061 static void jabber_handles10n(gjconn gjc, jpacket p) 1116 static void jabber_handles10n(gjconn gjc, jpacket p)
1062 { 1117 {
1063 xmlnode g; 1118 xmlnode g;
1064 char *Jid = xmlnode_get_attrib(p->x, "from"); 1119 char *Jid = xmlnode_get_attrib(p->x, "from");
1065 char *type = xmlnode_get_attrib(p->x, "type"); 1120 char *type = xmlnode_get_attrib(p->x, "type");
1066 1121
1067 g = xmlnode_new_tag("presence"); 1122 g = xmlnode_new_tag("presence");
1068 xmlnode_put_attrib(g, "to", Jid); 1123 xmlnode_put_attrib(g, "to", Jid);
1069 if (!strcmp(type, "subscribe")) 1124
1070 xmlnode_put_attrib(g, "type", "subscribed"); 1125 if (!strcmp(type, "subscribe")) {
1071 else if (!strcmp(type, "unsubscribe")) 1126 /*
1127 * A "subscribe to us" request was received - put up the approval dialog
1128 */
1129 struct jabber_add_permit *jap = g_new0(struct jabber_add_permit, 1);
1130 gchar *msg = g_strdup_printf(_("The user %s wants to add you to their buddy list."),
1131 Jid);
1132
1133 jap->gjc = gjc;
1134 jap->user = g_strdup(Jid);
1135 do_ask_dialog(msg, jap, jabber_accept_add, jabber_deny_add);
1136
1137 g_free(msg);
1138 xmlnode_free(g); /* Never needed it here anyway */
1139 return;
1140
1141 } else if (!strcmp(type, "unsubscribe")) {
1142 /*
1143 * An "unsubscribe to us" was received - simply "approve" it
1144 */
1072 xmlnode_put_attrib(g, "type", "unsubscribed"); 1145 xmlnode_put_attrib(g, "type", "unsubscribed");
1073 else { 1146 } else {
1147 /*
1148 * Did we attempt to subscribe to somebody and they do not exist?
1149 */
1074 if (!strcmp(type, "unsubscribed")) { 1150 if (!strcmp(type, "unsubscribed")) {
1075 xmlnode y; 1151 xmlnode y;
1076 char *status; 1152 char *status;
1077 if((y = xmlnode_get_tag(p->x, "status")) && (status = xmlnode_get_data(y)) && 1153 if((y = xmlnode_get_tag(p->x, "status")) && (status = xmlnode_get_data(y)) &&
1078 !strcmp(status, "Not Found")) { 1154 !strcmp(status, "Not Found")) {