comparison mcabber/src/jab_iq.c @ 1159:53c0c5be43fa

Small fixes, typos and cleanups
author Mikael Berthe <mikael@lilotux.net>
date Thu, 15 Feb 2007 23:20:24 +0100
parents c30c315dc447
children 3a2ac3d96eed
comparison
equal deleted inserted replaced
1158:c30c315dc447 1159:53c0c5be43fa
69 adhoc_command_callback callback; 69 adhoc_command_callback callback;
70 }; 70 };
71 71
72 const struct adhoc_command adhoc_command_list[] = { 72 const struct adhoc_command adhoc_command_list[] = {
73 { "http://jabber.org/protocol/rc#set-status", 73 { "http://jabber.org/protocol/rc#set-status",
74 "Set the client as away", 74 "Change client status",
75 1, 75 1,
76 &handle_iq_command_set_status }, 76 &handle_iq_command_set_status },
77 { "http://jabber.org/protocol/rc#leave-groupchats", 77 { "http://jabber.org/protocol/rc#leave-groupchats",
78 "Leave groupchats", 78 "Leave groupchat(s)",
79 1, 79 1,
80 &handle_iq_command_leave_groupchats }, 80 &handle_iq_command_leave_groupchats },
81 { NULL, NULL, 0, NULL }, 81 { NULL, NULL, 0, NULL },
82 }; 82 };
83 83
838 jb_setprevstatus(); 838 jb_setprevstatus();
839 } 839 }
840 } 840 }
841 841
842 // FIXME highly duplicated code 842 // FIXME highly duplicated code
843 // factorisation is doable
844 static void send_iq_not_implemented(jconn conn, char *from, xmlnode xmldata) 843 static void send_iq_not_implemented(jconn conn, char *from, xmlnode xmldata)
845 { 844 {
846 xmlnode x, y, z; 845 xmlnode x, y, z;
847 // Not implemented. 846 // Not implemented.
848 x = xmlnode_dup(xmldata); 847 x = xmlnode_dup(xmldata);
1052 "value"); 1051 "value");
1053 message = xmlnode_get_tag_data(xmlnode_get_tag(y, 1052 message = xmlnode_get_tag_data(xmlnode_get_tag(y,
1054 "field?var=status-message"), "value"); 1053 "field?var=status-message"), "value");
1055 for (s = adhoc_status_list; !s->name || strcmp(s->name, value); s++); 1054 for (s = adhoc_status_list; !s->name || strcmp(s->name, value); s++);
1056 if (s->name) { 1055 if (s->name) {
1057 char* status = g_strdup_printf("%s %s", s->status, message); 1056 char *status = g_strdup_printf("%s %s", s->status,
1058 xmlnode_put_attrib(command, "status", "completed"); 1057 message ? message : "");
1059
1060 setstatus(NULL, status); 1058 setstatus(NULL, status);
1061 g_free(status); 1059 g_free(status);
1060 xmlnode_put_attrib(command, "status", "completed");
1062 xmlnode_put_attrib(iq, "type", "result"); 1061 xmlnode_put_attrib(iq, "type", "result");
1063 xmlnode_insert_dataform_result_message(command, "Status was changed"); 1062 xmlnode_insert_dataform_result_message(command,
1063 "Status has been changed");
1064 } 1064 }
1065 } 1065 }
1066 } 1066 }
1067 xmlnode_put_attrib(iq, "to", xmlnode_get_attrib(xmldata, "from")); 1067 xmlnode_put_attrib(iq, "to", xmlnode_get_attrib(xmldata, "from"));
1068 xmlnode_put_attrib(iq, "id", id); 1068 xmlnode_put_attrib(iq, "id", id);
1089 desc = g_strdup_printf("%s on %s", nickname, room_jid); 1089 desc = g_strdup_printf("%s on %s", nickname, room_jid);
1090 xmlnode_put_attrib(option, "label", desc); 1090 xmlnode_put_attrib(option, "label", desc);
1091 g_free(desc); 1091 g_free(desc);
1092 } 1092 }
1093 1093
1094 static void handle_iq_command_leave_groupchats(jconn conn, char *from, const char *id, 1094 static void handle_iq_command_leave_groupchats(jconn conn, char *from,
1095 xmlnode xmldata) 1095 const char *id, xmlnode xmldata)
1096 { 1096 {
1097 char *action, *node, *sessionid; 1097 char *action, *node, *sessionid;
1098 xmlnode iq, command, x; 1098 xmlnode iq, command, x;
1099 1099
1100 x = xmlnode_get_tag(xmldata, "command"); 1100 x = xmlnode_get_tag(xmldata, "command");
1116 x = xmlnode_insert_tag(command, "x"); 1116 x = xmlnode_insert_tag(command, "x");
1117 xmlnode_put_attrib(x, "type", "form"); 1117 xmlnode_put_attrib(x, "type", "form");
1118 xmlnode_put_attrib(x, "xmlns", "jabber:x:data"); 1118 xmlnode_put_attrib(x, "xmlns", "jabber:x:data");
1119 1119
1120 xmlnode title = xmlnode_insert_tag(x, "title"); 1120 xmlnode title = xmlnode_insert_tag(x, "title");
1121 xmlnode_insert_cdata(title, "Leave groupchats", -1); 1121 xmlnode_insert_cdata(title, "Leave groupchat(s)", -1);
1122 1122
1123 xmlnode instructions = xmlnode_insert_tag(x, "instructions"); 1123 xmlnode instructions = xmlnode_insert_tag(x, "instructions");
1124 xmlnode_insert_cdata(instructions, "What groupchats do you want to leave ?", 1124 xmlnode_insert_cdata(instructions, "What groupchats do you want to leave?",
1125 -1); 1125 -1);
1126 1126
1127 xmlnode field = xmlnode_insert_tag(x, "field"); 1127 xmlnode field = xmlnode_insert_tag(x, "field");
1128 xmlnode_put_attrib(field, "type", "hidden"); 1128 xmlnode_put_attrib(field, "type", "hidden");
1129 xmlnode_put_attrib(field, "var", "FORM_TYPE"); 1129 xmlnode_put_attrib(field, "var", "FORM_TYPE");
1132 xmlnode_insert_cdata(value, "http://jabber.org/protocol/rc", -1); 1132 xmlnode_insert_cdata(value, "http://jabber.org/protocol/rc", -1);
1133 1133
1134 field = xmlnode_insert_tag(x, "field"); 1134 field = xmlnode_insert_tag(x, "field");
1135 xmlnode_put_attrib(field, "type", "list-multi"); 1135 xmlnode_put_attrib(field, "type", "list-multi");
1136 xmlnode_put_attrib(field, "var", "groupchats"); 1136 xmlnode_put_attrib(field, "var", "groupchats");
1137 xmlnode_put_attrib(field, "label", "Groupchats : "); 1137 xmlnode_put_attrib(field, "label", "Groupchats: ");
1138 xmlnode_insert_tag(field, "required"); 1138 xmlnode_insert_tag(field, "required");
1139 1139
1140 foreach_buddy(ROSTER_TYPE_ROOM, &_callback_foreach_buddy_groupchat, &field); 1140 foreach_buddy(ROSTER_TYPE_ROOM, &_callback_foreach_buddy_groupchat, &field);
1141 } 1141 }
1142 else // (if sessionid) 1142 else // (if sessionid)
1145 if (form) { 1145 if (form) {
1146 xmlnode_put_attrib(command, "status", "completed"); 1146 xmlnode_put_attrib(command, "status", "completed");
1147 xmlnode gc = xmlnode_get_tag(form, "field?var=groupchats"); 1147 xmlnode gc = xmlnode_get_tag(form, "field?var=groupchats");
1148 xmlnode x; 1148 xmlnode x;
1149 1149
1150 for (x = xmlnode_get_firstchild(gc) ; x ; x = xmlnode_get_nextsibling(x)) { 1150 for (x = xmlnode_get_firstchild(gc) ; x ; x = xmlnode_get_nextsibling(x))
1151 {
1151 char* to_leave = xmlnode_get_tag_data(x, "value"); 1152 char* to_leave = xmlnode_get_tag_data(x, "value");
1152 if (to_leave) { 1153 if (to_leave) {
1153 GList* b = buddy_search_jid(to_leave); 1154 GList* b = buddy_search_jid(to_leave);
1154 if (b) 1155 if (b)
1155 room_leave(b->data, "Asked by remote command"); 1156 room_leave(b->data, "Asked by remote command");
1156 } 1157 }
1157 } 1158 }
1158 xmlnode_put_attrib(iq, "type", "result"); 1159 xmlnode_put_attrib(iq, "type", "result");
1159 xmlnode_insert_dataform_result_message(command, "Groupchats were leaved"); 1160 xmlnode_insert_dataform_result_message(command,
1161 "Groupchats have been left");
1160 } 1162 }
1161 } 1163 }
1162 xmlnode_put_attrib(iq, "to", xmlnode_get_attrib(xmldata, "from")); 1164 xmlnode_put_attrib(iq, "to", xmlnode_get_attrib(xmldata, "from"));
1163 xmlnode_put_attrib(iq, "id", id); 1165 xmlnode_put_attrib(iq, "id", id);
1164 jab_send(jc, iq); 1166 jab_send(jc, iq);
1184 || !strcmp(action, "next") || !strcmp(action, "complete")) { 1186 || !strcmp(action, "next") || !strcmp(action, "complete")) {
1185 for (command = adhoc_command_list; command->name; command++) { 1187 for (command = adhoc_command_list; command->name; command++) {
1186 if (!strcmp(node, command->name)) 1188 if (!strcmp(node, command->name))
1187 command->callback(conn, from, id, xmldata); 1189 command->callback(conn, from, id, xmldata);
1188 } 1190 }
1189 // "prev" action will get there, as we do not implement it, and do not autorise it 1191 // "prev" action will get there, as we do not implement it,
1192 // and do not authorize it
1190 } else { 1193 } else {
1191 send_iq_commands_malformed_action(conn, from, xmldata); 1194 send_iq_commands_malformed_action(conn, from, xmldata);
1192 } 1195 }
1193 } else { 1196 } else {
1194 send_iq_forbidden(conn, from, xmldata); 1197 send_iq_forbidden(conn, from, xmldata);