| 70 } |
70 } |
| 71 } |
71 } |
| 72 |
72 |
| 73 for(item = query->child; item; item = item->next) { |
73 for(item = query->child; item; item = item->next) { |
| 74 JabberAdHocCommands *cmd; |
74 JabberAdHocCommands *cmd; |
| 75 if(item->type != XMLNODE_TYPE_TAG) |
75 if(item->type != PURPLE_XMLNODE_TYPE_TAG) |
| 76 continue; |
76 continue; |
| 77 if(strcmp(item->name, "item")) |
77 if(strcmp(item->name, "item")) |
| 78 continue; |
78 continue; |
| 79 cmd = g_new0(JabberAdHocCommands, 1); |
79 cmd = g_new0(JabberAdHocCommands, 1); |
| 80 |
80 |
| 81 cmd->jid = g_strdup(xmlnode_get_attrib(item,"jid")); |
81 cmd->jid = g_strdup(purple_xmlnode_get_attrib(item,"jid")); |
| 82 cmd->node = g_strdup(xmlnode_get_attrib(item,"node")); |
82 cmd->node = g_strdup(purple_xmlnode_get_attrib(item,"node")); |
| 83 cmd->name = g_strdup(xmlnode_get_attrib(item,"name")); |
83 cmd->name = g_strdup(purple_xmlnode_get_attrib(item,"name")); |
| 84 |
84 |
| 85 jbr->commands = g_list_append(jbr->commands,cmd); |
85 jbr->commands = g_list_append(jbr->commands,cmd); |
| 86 } |
86 } |
| 87 } |
87 } |
| 88 |
88 |
| 89 void |
89 void |
| 90 jabber_adhoc_disco_result_cb(JabberStream *js, const char *from, |
90 jabber_adhoc_disco_result_cb(JabberStream *js, const char *from, |
| 91 JabberIqType type, const char *id, |
91 JabberIqType type, const char *id, |
| 92 xmlnode *packet, gpointer data) |
92 PurpleXmlNode *packet, gpointer data) |
| 93 { |
93 { |
| 94 xmlnode *query; |
94 PurpleXmlNode *query; |
| 95 const char *node; |
95 const char *node; |
| 96 |
96 |
| 97 if (type == JABBER_IQ_ERROR) |
97 if (type == JABBER_IQ_ERROR) |
| 98 return; |
98 return; |
| 99 |
99 |
| 100 query = xmlnode_get_child_with_namespace(packet, "query", NS_DISCO_ITEMS); |
100 query = purple_xmlnode_get_child_with_namespace(packet, "query", NS_DISCO_ITEMS); |
| 101 if (!query) |
101 if (!query) |
| 102 return; |
102 return; |
| 103 node = xmlnode_get_attrib(query, "node"); |
103 node = purple_xmlnode_get_attrib(query, "node"); |
| 104 if (!purple_strequal(node, "http://jabber.org/protocol/commands")) |
104 if (!purple_strequal(node, "http://jabber.org/protocol/commands")) |
| 105 return; |
105 return; |
| 106 |
106 |
| 107 jabber_adhoc_got_buddy_list(js, from, query); |
107 jabber_adhoc_got_buddy_list(js, from, query); |
| 108 } |
108 } |
| 109 |
109 |
| 110 static void jabber_adhoc_parse(JabberStream *js, const char *from, |
110 static void jabber_adhoc_parse(JabberStream *js, const char *from, |
| 111 JabberIqType type, const char *id, |
111 JabberIqType type, const char *id, |
| 112 xmlnode *packet, gpointer data); |
112 PurpleXmlNode *packet, gpointer data); |
| 113 |
113 |
| 114 static void do_adhoc_action_cb(JabberStream *js, xmlnode *result, const char *actionhandle, gpointer user_data) { |
114 static void do_adhoc_action_cb(JabberStream *js, PurpleXmlNode *result, const char *actionhandle, gpointer user_data) { |
| 115 xmlnode *command; |
115 PurpleXmlNode *command; |
| 116 GList *action; |
116 GList *action; |
| 117 JabberAdHocActionInfo *actionInfo = user_data; |
117 JabberAdHocActionInfo *actionInfo = user_data; |
| 118 JabberIq *iq = jabber_iq_new(js, JABBER_IQ_SET); |
118 JabberIq *iq = jabber_iq_new(js, JABBER_IQ_SET); |
| 119 jabber_iq_set_callback(iq, jabber_adhoc_parse, NULL); |
119 jabber_iq_set_callback(iq, jabber_adhoc_parse, NULL); |
| 120 |
120 |
| 121 xmlnode_set_attrib(iq->node, "to", actionInfo->who); |
121 purple_xmlnode_set_attrib(iq->node, "to", actionInfo->who); |
| 122 command = xmlnode_new_child(iq->node,"command"); |
122 command = purple_xmlnode_new_child(iq->node,"command"); |
| 123 xmlnode_set_namespace(command,"http://jabber.org/protocol/commands"); |
123 purple_xmlnode_set_namespace(command,"http://jabber.org/protocol/commands"); |
| 124 xmlnode_set_attrib(command,"sessionid",actionInfo->sessionid); |
124 purple_xmlnode_set_attrib(command,"sessionid",actionInfo->sessionid); |
| 125 xmlnode_set_attrib(command,"node",actionInfo->node); |
125 purple_xmlnode_set_attrib(command,"node",actionInfo->node); |
| 126 |
126 |
| 127 /* cancel is handled differently on ad-hoc commands than regular forms */ |
127 /* cancel is handled differently on ad-hoc commands than regular forms */ |
| 128 if (purple_strequal(xmlnode_get_namespace(result), "jabber:x:data") && |
128 if (purple_strequal(purple_xmlnode_get_namespace(result), "jabber:x:data") && |
| 129 purple_strequal(xmlnode_get_attrib(result, "type"), "cancel")) { |
129 purple_strequal(purple_xmlnode_get_attrib(result, "type"), "cancel")) { |
| 130 xmlnode_set_attrib(command,"action","cancel"); |
130 purple_xmlnode_set_attrib(command,"action","cancel"); |
| 131 } else { |
131 } else { |
| 132 if(actionhandle) |
132 if(actionhandle) |
| 133 xmlnode_set_attrib(command,"action",actionhandle); |
133 purple_xmlnode_set_attrib(command,"action",actionhandle); |
| 134 xmlnode_insert_child(command,result); |
134 purple_xmlnode_insert_child(command,result); |
| 135 } |
135 } |
| 136 |
136 |
| 137 for(action = actionInfo->actionslist; action; action = g_list_next(action)) { |
137 for(action = actionInfo->actionslist; action; action = g_list_next(action)) { |
| 138 char *handle = action->data; |
138 char *handle = action->data; |
| 139 g_free(handle); |
139 g_free(handle); |
| 147 } |
147 } |
| 148 |
148 |
| 149 static void |
149 static void |
| 150 jabber_adhoc_parse(JabberStream *js, const char *from, |
150 jabber_adhoc_parse(JabberStream *js, const char *from, |
| 151 JabberIqType type, const char *id, |
151 JabberIqType type, const char *id, |
| 152 xmlnode *packet, gpointer data) |
152 PurpleXmlNode *packet, gpointer data) |
| 153 { |
153 { |
| 154 xmlnode *command = xmlnode_get_child_with_namespace(packet, "command", "http://jabber.org/protocol/commands"); |
154 PurpleXmlNode *command = purple_xmlnode_get_child_with_namespace(packet, "command", "http://jabber.org/protocol/commands"); |
| 155 const char *status = xmlnode_get_attrib(command,"status"); |
155 const char *status = purple_xmlnode_get_attrib(command,"status"); |
| 156 xmlnode *xdata = xmlnode_get_child_with_namespace(command,"x","jabber:x:data"); |
156 PurpleXmlNode *xdata = purple_xmlnode_get_child_with_namespace(command,"x","jabber:x:data"); |
| 157 |
157 |
| 158 if (type == JABBER_IQ_ERROR) { |
158 if (type == JABBER_IQ_ERROR) { |
| 159 char *msg = jabber_parse_error(js, packet, NULL); |
159 char *msg = jabber_parse_error(js, packet, NULL); |
| 160 if(!msg) |
160 if(!msg) |
| 161 msg = g_strdup(_("Unknown Error")); |
161 msg = g_strdup(_("Unknown Error")); |
| 169 if(!status) |
169 if(!status) |
| 170 return; |
170 return; |
| 171 |
171 |
| 172 if(!strcmp(status,"completed")) { |
172 if(!strcmp(status,"completed")) { |
| 173 /* display result */ |
173 /* display result */ |
| 174 xmlnode *note = xmlnode_get_child(command,"note"); |
174 PurpleXmlNode *note = purple_xmlnode_get_child(command,"note"); |
| 175 |
175 |
| 176 if(note) { |
176 if(note) { |
| 177 char *data = xmlnode_get_data(note); |
177 char *data = purple_xmlnode_get_data(note); |
| 178 purple_notify_info(NULL, from, data, NULL); |
178 purple_notify_info(NULL, from, data, NULL); |
| 179 g_free(data); |
179 g_free(data); |
| 180 } |
180 } |
| 181 |
181 |
| 182 if(xdata) |
182 if(xdata) |
| 183 jabber_x_data_request(js, xdata, (jabber_x_data_cb)do_adhoc_ignoreme, NULL); |
183 jabber_x_data_request(js, xdata, (jabber_x_data_cb)do_adhoc_ignoreme, NULL); |
| 184 return; |
184 return; |
| 185 } |
185 } |
| 186 if(!strcmp(status,"executing")) { |
186 if(!strcmp(status,"executing")) { |
| 187 /* this command needs more steps */ |
187 /* this command needs more steps */ |
| 188 xmlnode *actions, *action; |
188 PurpleXmlNode *actions, *action; |
| 189 int actionindex = 0; |
189 int actionindex = 0; |
| 190 GList *actionslist = NULL; |
190 GList *actionslist = NULL; |
| 191 JabberAdHocActionInfo *actionInfo; |
191 JabberAdHocActionInfo *actionInfo; |
| 192 if(!xdata) |
192 if(!xdata) |
| 193 return; /* shouldn't happen */ |
193 return; /* shouldn't happen */ |
| 194 |
194 |
| 195 actions = xmlnode_get_child(command,"actions"); |
195 actions = purple_xmlnode_get_child(command,"actions"); |
| 196 if(!actions) { |
196 if(!actions) { |
| 197 JabberXDataAction *defaultaction = g_new0(JabberXDataAction, 1); |
197 JabberXDataAction *defaultaction = g_new0(JabberXDataAction, 1); |
| 198 defaultaction->name = g_strdup(_("execute")); |
198 defaultaction->name = g_strdup(_("execute")); |
| 199 defaultaction->handle = g_strdup("execute"); |
199 defaultaction->handle = g_strdup("execute"); |
| 200 actionslist = g_list_append(actionslist, defaultaction); |
200 actionslist = g_list_append(actionslist, defaultaction); |
| 201 } else { |
201 } else { |
| 202 const char *defaultactionhandle = xmlnode_get_attrib(actions, "execute"); |
202 const char *defaultactionhandle = purple_xmlnode_get_attrib(actions, "execute"); |
| 203 int index = 0; |
203 int index = 0; |
| 204 for(action = actions->child; action; action = action->next, ++index) { |
204 for(action = actions->child; action; action = action->next, ++index) { |
| 205 if(action->type == XMLNODE_TYPE_TAG) { |
205 if(action->type == PURPLE_XMLNODE_TYPE_TAG) { |
| 206 JabberXDataAction *newaction = g_new0(JabberXDataAction, 1); |
206 JabberXDataAction *newaction = g_new0(JabberXDataAction, 1); |
| 207 newaction->name = g_strdup(_(action->name)); |
207 newaction->name = g_strdup(_(action->name)); |
| 208 newaction->handle = g_strdup(action->name); |
208 newaction->handle = g_strdup(action->name); |
| 209 actionslist = g_list_append(actionslist, newaction); |
209 actionslist = g_list_append(actionslist, newaction); |
| 210 if(defaultactionhandle && !strcmp(defaultactionhandle, action->name)) |
210 if(defaultactionhandle && !strcmp(defaultactionhandle, action->name)) |
| 254 } |
254 } |
| 255 |
255 |
| 256 /* re-fill list */ |
256 /* re-fill list */ |
| 257 for(item = query->child; item; item = item->next) { |
257 for(item = query->child; item; item = item->next) { |
| 258 JabberAdHocCommands *cmd; |
258 JabberAdHocCommands *cmd; |
| 259 if(item->type != XMLNODE_TYPE_TAG) |
259 if(item->type != PURPLE_XMLNODE_TYPE_TAG) |
| 260 continue; |
260 continue; |
| 261 if(strcmp(item->name, "item")) |
261 if(strcmp(item->name, "item")) |
| 262 continue; |
262 continue; |
| 263 cmd = g_new0(JabberAdHocCommands, 1); |
263 cmd = g_new0(JabberAdHocCommands, 1); |
| 264 cmd->jid = g_strdup(xmlnode_get_attrib(item,"jid")); |
264 cmd->jid = g_strdup(purple_xmlnode_get_attrib(item,"jid")); |
| 265 cmd->node = g_strdup(xmlnode_get_attrib(item,"node")); |
265 cmd->node = g_strdup(purple_xmlnode_get_attrib(item,"node")); |
| 266 cmd->name = g_strdup(xmlnode_get_attrib(item,"name")); |
266 cmd->name = g_strdup(purple_xmlnode_get_attrib(item,"name")); |
| 267 |
267 |
| 268 js->commands = g_list_append(js->commands,cmd); |
268 js->commands = g_list_append(js->commands,cmd); |
| 269 } |
269 } |
| 270 |
270 |
| 271 if (js->state == JABBER_STREAM_CONNECTED) |
271 if (js->state == JABBER_STREAM_CONNECTED) |
| 273 } |
273 } |
| 274 |
274 |
| 275 static void |
275 static void |
| 276 jabber_adhoc_server_got_list_cb(JabberStream *js, const char *from, |
276 jabber_adhoc_server_got_list_cb(JabberStream *js, const char *from, |
| 277 JabberIqType type, const char *id, |
277 JabberIqType type, const char *id, |
| 278 xmlnode *packet, gpointer data) |
278 PurpleXmlNode *packet, gpointer data) |
| 279 { |
279 { |
| 280 xmlnode *query = xmlnode_get_child_with_namespace(packet, "query", |
280 PurpleXmlNode *query = purple_xmlnode_get_child_with_namespace(packet, "query", |
| 281 NS_DISCO_ITEMS); |
281 NS_DISCO_ITEMS); |
| 282 |
282 |
| 283 jabber_adhoc_got_server_list(js, from, query); |
283 jabber_adhoc_got_server_list(js, from, query); |
| 284 |
284 |
| 285 } |
285 } |
| 286 |
286 |
| 287 void jabber_adhoc_got_list(JabberStream *js, const char *from, xmlnode *query) |
287 void jabber_adhoc_got_list(JabberStream *js, const char *from, PurpleXmlNode *query) |
| 288 { |
288 { |
| 289 if (purple_strequal(from, js->user->domain)) { |
289 if (purple_strequal(from, js->user->domain)) { |
| 290 jabber_adhoc_got_server_list(js, from, query); |
290 jabber_adhoc_got_server_list(js, from, query); |
| 291 } else { |
291 } else { |
| 292 jabber_adhoc_got_buddy_list(js, from, query); |
292 jabber_adhoc_got_buddy_list(js, from, query); |
| 293 } |
293 } |
| 294 } |
294 } |
| 295 |
295 |
| 296 void jabber_adhoc_server_get_list(JabberStream *js) { |
296 void jabber_adhoc_server_get_list(JabberStream *js) { |
| 297 JabberIq *iq = jabber_iq_new_query(js, JABBER_IQ_GET, NS_DISCO_ITEMS); |
297 JabberIq *iq = jabber_iq_new_query(js, JABBER_IQ_GET, NS_DISCO_ITEMS); |
| 298 xmlnode *query = xmlnode_get_child_with_namespace(iq->node, "query", |
298 PurpleXmlNode *query = purple_xmlnode_get_child_with_namespace(iq->node, "query", |
| 299 NS_DISCO_ITEMS); |
299 NS_DISCO_ITEMS); |
| 300 |
300 |
| 301 xmlnode_set_attrib(iq->node,"to",js->user->domain); |
301 purple_xmlnode_set_attrib(iq->node,"to",js->user->domain); |
| 302 xmlnode_set_attrib(query,"node","http://jabber.org/protocol/commands"); |
302 purple_xmlnode_set_attrib(query,"node","http://jabber.org/protocol/commands"); |
| 303 |
303 |
| 304 jabber_iq_set_callback(iq,jabber_adhoc_server_got_list_cb,NULL); |
304 jabber_iq_set_callback(iq,jabber_adhoc_server_got_list_cb,NULL); |
| 305 jabber_iq_send(iq); |
305 jabber_iq_send(iq); |
| 306 } |
306 } |
| 307 |
307 |
| 308 void jabber_adhoc_execute(JabberStream *js, JabberAdHocCommands *cmd) { |
308 void jabber_adhoc_execute(JabberStream *js, JabberAdHocCommands *cmd) { |
| 309 JabberIq *iq = jabber_iq_new(js, JABBER_IQ_SET); |
309 JabberIq *iq = jabber_iq_new(js, JABBER_IQ_SET); |
| 310 xmlnode *command = xmlnode_new_child(iq->node,"command"); |
310 PurpleXmlNode *command = purple_xmlnode_new_child(iq->node,"command"); |
| 311 xmlnode_set_attrib(iq->node,"to",cmd->jid); |
311 purple_xmlnode_set_attrib(iq->node,"to",cmd->jid); |
| 312 xmlnode_set_namespace(command,"http://jabber.org/protocol/commands"); |
312 purple_xmlnode_set_namespace(command,"http://jabber.org/protocol/commands"); |
| 313 xmlnode_set_attrib(command,"node",cmd->node); |
313 purple_xmlnode_set_attrib(command,"node",cmd->node); |
| 314 xmlnode_set_attrib(command,"action","execute"); |
314 purple_xmlnode_set_attrib(command,"action","execute"); |
| 315 |
315 |
| 316 jabber_iq_set_callback(iq,jabber_adhoc_parse,NULL); |
316 jabber_iq_set_callback(iq,jabber_adhoc_parse,NULL); |
| 317 |
317 |
| 318 jabber_iq_send(iq); |
318 jabber_iq_send(iq); |
| 319 } |
319 } |