comparison libpurple/protocols/jabber/adhoccommands.c @ 25952:5f9a24d1c25e

Remove some extra trailing whitespace I noticed after merging mlundblad's xmpp branches.
author Elliott Sales de Andrade <qulogic@pidgin.im>
date Mon, 02 Mar 2009 06:37:05 +0000
parents 4b8c4870b13a
children ae41d8e827e3
comparison
equal deleted inserted replaced
25951:13574de83636 25952:5f9a24d1c25e
45 const char *node; 45 const char *node;
46 xmlnode *query, *item; 46 xmlnode *query, *item;
47 JabberID *jabberid; 47 JabberID *jabberid;
48 JabberBuddy *jb; 48 JabberBuddy *jb;
49 JabberBuddyResource *jbr = NULL; 49 JabberBuddyResource *jbr = NULL;
50 50
51 if(strcmp(type, "result")) 51 if(strcmp(type, "result"))
52 return; 52 return;
53 53
54 query = xmlnode_get_child_with_namespace(packet,"query","http://jabber.org/protocol/disco#items"); 54 query = xmlnode_get_child_with_namespace(packet,"query","http://jabber.org/protocol/disco#items");
55 if(!query) 55 if(!query)
56 return; 56 return;
57 node = xmlnode_get_attrib(query,"node"); 57 node = xmlnode_get_attrib(query,"node");
58 if(!node || strcmp(node, "http://jabber.org/protocol/commands")) 58 if(!node || strcmp(node, "http://jabber.org/protocol/commands"))
59 return; 59 return;
60 60
61 if((jabberid = jabber_id_new(from))) { 61 if((jabberid = jabber_id_new(from))) {
62 if(jabberid->resource && (jb = jabber_buddy_find(js, from, TRUE))) 62 if(jabberid->resource && (jb = jabber_buddy_find(js, from, TRUE)))
63 jbr = jabber_buddy_find_resource(jb, jabberid->resource); 63 jbr = jabber_buddy_find_resource(jb, jabberid->resource);
64 jabber_id_free(jabberid); 64 jabber_id_free(jabberid);
65 } 65 }
66 66
67 if(!jbr) 67 if(!jbr)
68 return; 68 return;
69 69
70 if(jbr->commands) { 70 if(jbr->commands) {
71 /* since the list we just received is complete, wipe the old one */ 71 /* since the list we just received is complete, wipe the old one */
72 while(jbr->commands) { 72 while(jbr->commands) {
73 JabberAdHocCommands *cmd = jbr->commands->data; 73 JabberAdHocCommands *cmd = jbr->commands->data;
74 g_free(cmd->jid); 74 g_free(cmd->jid);
76 g_free(cmd->name); 76 g_free(cmd->name);
77 g_free(cmd); 77 g_free(cmd);
78 jbr->commands = g_list_delete_link(jbr->commands, jbr->commands); 78 jbr->commands = g_list_delete_link(jbr->commands, jbr->commands);
79 } 79 }
80 } 80 }
81 81
82 for(item = query->child; item; item = item->next) { 82 for(item = query->child; item; item = item->next) {
83 JabberAdHocCommands *cmd; 83 JabberAdHocCommands *cmd;
84 if(item->type != XMLNODE_TYPE_TAG) 84 if(item->type != XMLNODE_TYPE_TAG)
85 continue; 85 continue;
86 if(strcmp(item->name, "item")) 86 if(strcmp(item->name, "item"))
87 continue; 87 continue;
88 cmd = g_new0(JabberAdHocCommands, 1); 88 cmd = g_new0(JabberAdHocCommands, 1);
89 89
90 cmd->jid = g_strdup(xmlnode_get_attrib(item,"jid")); 90 cmd->jid = g_strdup(xmlnode_get_attrib(item,"jid"));
91 cmd->node = g_strdup(xmlnode_get_attrib(item,"node")); 91 cmd->node = g_strdup(xmlnode_get_attrib(item,"node"));
92 cmd->name = g_strdup(xmlnode_get_attrib(item,"name")); 92 cmd->name = g_strdup(xmlnode_get_attrib(item,"name"));
93 93
94 jbr->commands = g_list_append(jbr->commands,cmd); 94 jbr->commands = g_list_append(jbr->commands,cmd);
95 } 95 }
96 } 96 }
97 97
98 static void jabber_adhoc_parse(JabberStream *js, xmlnode *packet, gpointer data); 98 static void jabber_adhoc_parse(JabberStream *js, xmlnode *packet, gpointer data);
101 xmlnode *command; 101 xmlnode *command;
102 GList *action; 102 GList *action;
103 JabberAdHocActionInfo *actionInfo = user_data; 103 JabberAdHocActionInfo *actionInfo = user_data;
104 JabberIq *iq = jabber_iq_new(js, JABBER_IQ_SET); 104 JabberIq *iq = jabber_iq_new(js, JABBER_IQ_SET);
105 jabber_iq_set_callback(iq, jabber_adhoc_parse, NULL); 105 jabber_iq_set_callback(iq, jabber_adhoc_parse, NULL);
106 106
107 xmlnode_set_attrib(iq->node, "to", actionInfo->who); 107 xmlnode_set_attrib(iq->node, "to", actionInfo->who);
108 command = xmlnode_new_child(iq->node,"command"); 108 command = xmlnode_new_child(iq->node,"command");
109 xmlnode_set_namespace(command,"http://jabber.org/protocol/commands"); 109 xmlnode_set_namespace(command,"http://jabber.org/protocol/commands");
110 xmlnode_set_attrib(command,"sessionid",actionInfo->sessionid); 110 xmlnode_set_attrib(command,"sessionid",actionInfo->sessionid);
111 xmlnode_set_attrib(command,"node",actionInfo->node); 111 xmlnode_set_attrib(command,"node",actionInfo->node);
112 112
113 /* cancel is handled differently on ad-hoc commands than regular forms */ 113 /* cancel is handled differently on ad-hoc commands than regular forms */
114 if(!strcmp(xmlnode_get_namespace(result),"jabber:x:data") && !strcmp(xmlnode_get_attrib(result, "type"),"cancel")) { 114 if(!strcmp(xmlnode_get_namespace(result),"jabber:x:data") && !strcmp(xmlnode_get_attrib(result, "type"),"cancel")) {
115 xmlnode_set_attrib(command,"action","cancel"); 115 xmlnode_set_attrib(command,"action","cancel");
116 } else { 116 } else {
117 if(actionhandle) 117 if(actionhandle)
118 xmlnode_set_attrib(command,"action",actionhandle); 118 xmlnode_set_attrib(command,"action",actionhandle);
119 xmlnode_insert_child(command,result); 119 xmlnode_insert_child(command,result);
120 } 120 }
121 121
122 for(action = actionInfo->actionslist; action; action = g_list_next(action)) { 122 for(action = actionInfo->actionslist; action; action = g_list_next(action)) {
123 char *handle = action->data; 123 char *handle = action->data;
124 g_free(handle); 124 g_free(handle);
125 } 125 }
126 g_list_free(actionInfo->actionslist); 126 g_list_free(actionInfo->actionslist);
127 g_free(actionInfo->sessionid); 127 g_free(actionInfo->sessionid);
128 g_free(actionInfo->who); 128 g_free(actionInfo->who);
129 g_free(actionInfo->node); 129 g_free(actionInfo->node);
130 130
131 jabber_iq_send(iq); 131 jabber_iq_send(iq);
132 } 132 }
133 133
134 static void jabber_adhoc_parse(JabberStream *js, xmlnode *packet, gpointer data) { 134 static void jabber_adhoc_parse(JabberStream *js, xmlnode *packet, gpointer data) {
135 xmlnode *command = xmlnode_get_child_with_namespace(packet, "command", "http://jabber.org/protocol/commands"); 135 xmlnode *command = xmlnode_get_child_with_namespace(packet, "command", "http://jabber.org/protocol/commands");
136 const char *status = xmlnode_get_attrib(command,"status"); 136 const char *status = xmlnode_get_attrib(command,"status");
137 xmlnode *xdata = xmlnode_get_child_with_namespace(command,"x","jabber:x:data"); 137 xmlnode *xdata = xmlnode_get_child_with_namespace(command,"x","jabber:x:data");
138 const char *type = xmlnode_get_attrib(packet,"type"); 138 const char *type = xmlnode_get_attrib(packet,"type");
139 139
140 if(type && !strcmp(type,"error")) { 140 if(type && !strcmp(type,"error")) {
141 char *msg = jabber_parse_error(js, packet, NULL); 141 char *msg = jabber_parse_error(js, packet, NULL);
142 if(!msg) 142 if(!msg)
143 msg = g_strdup(_("Unknown Error")); 143 msg = g_strdup(_("Unknown Error"));
144 144
145 purple_notify_error(NULL, _("Ad-Hoc Command Failed"), 145 purple_notify_error(NULL, _("Ad-Hoc Command Failed"),
146 _("Ad-Hoc Command Failed"), msg); 146 _("Ad-Hoc Command Failed"), msg);
147 g_free(msg); 147 g_free(msg);
148 return; 148 return;
149 } 149 }
150 if(!type || strcmp(type,"result")) 150 if(!type || strcmp(type,"result"))
151 return; 151 return;
152 152
153 if(!status) 153 if(!status)
154 return; 154 return;
155 155
156 if(!strcmp(status,"completed")) { 156 if(!strcmp(status,"completed")) {
157 /* display result */ 157 /* display result */
158 xmlnode *note = xmlnode_get_child(command,"note"); 158 xmlnode *note = xmlnode_get_child(command,"note");
159 159
160 if(note) { 160 if(note) {
161 char *data = xmlnode_get_data(note); 161 char *data = xmlnode_get_data(note);
162 purple_notify_info(NULL, xmlnode_get_attrib(packet, "from"), data, NULL); 162 purple_notify_info(NULL, xmlnode_get_attrib(packet, "from"), data, NULL);
163 g_free(data); 163 g_free(data);
164 } 164 }
165 165
166 if(xdata) 166 if(xdata)
167 jabber_x_data_request(js, xdata, (jabber_x_data_cb)do_adhoc_ignoreme, NULL); 167 jabber_x_data_request(js, xdata, (jabber_x_data_cb)do_adhoc_ignoreme, NULL);
168 return; 168 return;
169 } 169 }
170 if(!strcmp(status,"executing")) { 170 if(!strcmp(status,"executing")) {
173 int actionindex = 0; 173 int actionindex = 0;
174 GList *actionslist = NULL; 174 GList *actionslist = NULL;
175 JabberAdHocActionInfo *actionInfo; 175 JabberAdHocActionInfo *actionInfo;
176 if(!xdata) 176 if(!xdata)
177 return; /* shouldn't happen */ 177 return; /* shouldn't happen */
178 178
179 actions = xmlnode_get_child(command,"actions"); 179 actions = xmlnode_get_child(command,"actions");
180 if(!actions) { 180 if(!actions) {
181 JabberXDataAction *defaultaction = g_new0(JabberXDataAction, 1); 181 JabberXDataAction *defaultaction = g_new0(JabberXDataAction, 1);
182 defaultaction->name = g_strdup(_("execute")); 182 defaultaction->name = g_strdup(_("execute"));
183 defaultaction->handle = g_strdup("execute"); 183 defaultaction->handle = g_strdup("execute");
194 if(defaultactionhandle && !strcmp(defaultactionhandle, action->name)) 194 if(defaultactionhandle && !strcmp(defaultactionhandle, action->name))
195 actionindex = index; 195 actionindex = index;
196 } 196 }
197 } 197 }
198 } 198 }
199 199
200 actionInfo = g_new0(JabberAdHocActionInfo, 1); 200 actionInfo = g_new0(JabberAdHocActionInfo, 1);
201 actionInfo->sessionid = g_strdup(xmlnode_get_attrib(command,"sessionid")); 201 actionInfo->sessionid = g_strdup(xmlnode_get_attrib(command,"sessionid"));
202 actionInfo->who = g_strdup(xmlnode_get_attrib(packet,"from")); 202 actionInfo->who = g_strdup(xmlnode_get_attrib(packet,"from"));
203 actionInfo->node = g_strdup(xmlnode_get_attrib(command,"node")); 203 actionInfo->node = g_strdup(xmlnode_get_attrib(command,"node"));
204 actionInfo->actionslist = actionslist; 204 actionInfo->actionslist = actionslist;
205 205
206 jabber_x_data_request_with_actions(js,xdata,actionslist,actionindex,do_adhoc_action_cb,actionInfo); 206 jabber_x_data_request_with_actions(js,xdata,actionslist,actionindex,do_adhoc_action_cb,actionInfo);
207 } 207 }
208 } 208 }
209 209
210 void jabber_adhoc_execute_action(PurpleBlistNode *node, gpointer data) { 210 void jabber_adhoc_execute_action(PurpleBlistNode *node, gpointer data) {
219 } 219 }
220 220
221 static void jabber_adhoc_server_got_list_cb(JabberStream *js, xmlnode *packet, gpointer data) { 221 static void jabber_adhoc_server_got_list_cb(JabberStream *js, xmlnode *packet, gpointer data) {
222 xmlnode *query = xmlnode_get_child_with_namespace(packet, "query", "http://jabber.org/protocol/disco#items"); 222 xmlnode *query = xmlnode_get_child_with_namespace(packet, "query", "http://jabber.org/protocol/disco#items");
223 xmlnode *item; 223 xmlnode *item;
224 224
225 if(!query) 225 if(!query)
226 return; 226 return;
227 227
228 /* clean current list (just in case there is one) */ 228 /* clean current list (just in case there is one) */
229 while(js->commands) { 229 while(js->commands) {
232 g_free(cmd->node); 232 g_free(cmd->node);
233 g_free(cmd->name); 233 g_free(cmd->name);
234 g_free(cmd); 234 g_free(cmd);
235 js->commands = g_list_delete_link(js->commands, js->commands); 235 js->commands = g_list_delete_link(js->commands, js->commands);
236 } 236 }
237 237
238 /* re-fill list */ 238 /* re-fill list */
239 for(item = query->child; item; item = item->next) { 239 for(item = query->child; item; item = item->next) {
240 JabberAdHocCommands *cmd; 240 JabberAdHocCommands *cmd;
241 if(item->type != XMLNODE_TYPE_TAG) 241 if(item->type != XMLNODE_TYPE_TAG)
242 continue; 242 continue;
244 continue; 244 continue;
245 cmd = g_new0(JabberAdHocCommands, 1); 245 cmd = g_new0(JabberAdHocCommands, 1);
246 cmd->jid = g_strdup(xmlnode_get_attrib(item,"jid")); 246 cmd->jid = g_strdup(xmlnode_get_attrib(item,"jid"));
247 cmd->node = g_strdup(xmlnode_get_attrib(item,"node")); 247 cmd->node = g_strdup(xmlnode_get_attrib(item,"node"));
248 cmd->name = g_strdup(xmlnode_get_attrib(item,"name")); 248 cmd->name = g_strdup(xmlnode_get_attrib(item,"name"));
249 249
250 js->commands = g_list_append(js->commands,cmd); 250 js->commands = g_list_append(js->commands,cmd);
251 } 251 }
252 } 252 }
253 253
254 void jabber_adhoc_server_get_list(JabberStream *js) { 254 void jabber_adhoc_server_get_list(JabberStream *js) {
255 JabberIq *iq = jabber_iq_new_query(js,JABBER_IQ_GET,"http://jabber.org/protocol/disco#items"); 255 JabberIq *iq = jabber_iq_new_query(js,JABBER_IQ_GET,"http://jabber.org/protocol/disco#items");
256 xmlnode *query = xmlnode_get_child_with_namespace(iq->node,"query","http://jabber.org/protocol/disco#items"); 256 xmlnode *query = xmlnode_get_child_with_namespace(iq->node,"query","http://jabber.org/protocol/disco#items");
257 257
258 xmlnode_set_attrib(iq->node,"to",js->user->domain); 258 xmlnode_set_attrib(iq->node,"to",js->user->domain);
259 xmlnode_set_attrib(query,"node","http://jabber.org/protocol/commands"); 259 xmlnode_set_attrib(query,"node","http://jabber.org/protocol/commands");
260 260
261 jabber_iq_set_callback(iq,jabber_adhoc_server_got_list_cb,NULL); 261 jabber_iq_set_callback(iq,jabber_adhoc_server_got_list_cb,NULL);
262 jabber_iq_send(iq); 262 jabber_iq_send(iq);
263 } 263 }
264 264
265 void jabber_adhoc_execute(JabberStream *js, JabberAdHocCommands *cmd) { 265 void jabber_adhoc_execute(JabberStream *js, JabberAdHocCommands *cmd) {
267 xmlnode *command = xmlnode_new_child(iq->node,"command"); 267 xmlnode *command = xmlnode_new_child(iq->node,"command");
268 xmlnode_set_attrib(iq->node,"to",cmd->jid); 268 xmlnode_set_attrib(iq->node,"to",cmd->jid);
269 xmlnode_set_namespace(command,"http://jabber.org/protocol/commands"); 269 xmlnode_set_namespace(command,"http://jabber.org/protocol/commands");
270 xmlnode_set_attrib(command,"node",cmd->node); 270 xmlnode_set_attrib(command,"node",cmd->node);
271 xmlnode_set_attrib(command,"action","execute"); 271 xmlnode_set_attrib(command,"action","execute");
272 272
273 jabber_iq_set_callback(iq,jabber_adhoc_parse,NULL); 273 jabber_iq_set_callback(iq,jabber_adhoc_parse,NULL);
274 274
275 jabber_iq_send(iq); 275 jabber_iq_send(iq);
276 } 276 }
277 277
278 static void jabber_adhoc_server_execute(PurplePluginAction *action) { 278 static void jabber_adhoc_server_execute(PurplePluginAction *action) {
279 JabberAdHocCommands *cmd = action->user_data; 279 JabberAdHocCommands *cmd = action->user_data;
280 if(cmd) { 280 if(cmd) {
281 PurpleConnection *gc = (PurpleConnection *) action->context; 281 PurpleConnection *gc = (PurpleConnection *) action->context;
282 JabberStream *js = gc->proto_data; 282 JabberStream *js = gc->proto_data;
283 283
284 jabber_adhoc_execute(js, cmd); 284 jabber_adhoc_execute(js, cmd);
285 } 285 }
286 } 286 }
287 287
288 void jabber_adhoc_init_server_commands(JabberStream *js, GList **m) { 288 void jabber_adhoc_init_server_commands(JabberStream *js, GList **m) {
289 GList *cmdlst; 289 GList *cmdlst;
290 JabberBuddy *jb; 290 JabberBuddy *jb;
291 291
292 /* also add commands for other clients connected to the same account on another resource */ 292 /* also add commands for other clients connected to the same account on another resource */
293 char *accountname = g_strdup_printf("%s@%s", js->user->node, js->user->domain); 293 char *accountname = g_strdup_printf("%s@%s", js->user->node, js->user->domain);
294 if((jb = jabber_buddy_find(js, accountname, TRUE))) { 294 if((jb = jabber_buddy_find(js, accountname, TRUE))) {
295 GList *iter; 295 GList *iter;
296 for(iter = jb->resources; iter; iter = g_list_next(iter)) { 296 for(iter = jb->resources; iter; iter = g_list_next(iter)) {
305 g_free(cmdname); 305 g_free(cmdname);
306 } 306 }
307 } 307 }
308 } 308 }
309 g_free(accountname); 309 g_free(accountname);
310 310
311 /* now add server commands */ 311 /* now add server commands */
312 for(cmdlst = js->commands; cmdlst; cmdlst = g_list_next(cmdlst)) { 312 for(cmdlst = js->commands; cmdlst; cmdlst = g_list_next(cmdlst)) {
313 JabberAdHocCommands *cmd = cmdlst->data; 313 JabberAdHocCommands *cmd = cmdlst->data;
314 PurplePluginAction *act = purple_plugin_action_new(cmd->name, jabber_adhoc_server_execute); 314 PurplePluginAction *act = purple_plugin_action_new(cmd->name, jabber_adhoc_server_execute);
315 act->user_data = cmd; 315 act->user_data = cmd;