Mercurial > pidgin
comparison libpurple/protocols/jabber/xdata.c @ 15822:32c366eeeb99
sed -ie 's/gaim/purple/g'
author | Sean Egan <seanegan@gmail.com> |
---|---|
date | Mon, 19 Mar 2007 07:01:17 +0000 |
parents | 5fe8042783c1 |
children | 0db4eca4a3e0 |
comparison
equal
deleted
inserted
replaced
15821:84b0f9b23ede | 15822:32c366eeeb99 |
---|---|
1 /* | 1 /* |
2 * gaim - Jabber Protocol Plugin | 2 * purple - Jabber Protocol Plugin |
3 * | 3 * |
4 * Copyright (C) 2003, Nathan Walp <faceprint@faceprint.com> | 4 * Copyright (C) 2003, Nathan Walp <faceprint@faceprint.com> |
5 * | 5 * |
6 * This program is free software; you can redistribute it and/or modify | 6 * This program is free software; you can redistribute it and/or modify |
7 * it under the terms of the GNU General Public License as published by | 7 * it under the terms of the GNU General Public License as published by |
40 jabber_x_data_cb cb; | 40 jabber_x_data_cb cb; |
41 gpointer user_data; | 41 gpointer user_data; |
42 JabberStream *js; | 42 JabberStream *js; |
43 }; | 43 }; |
44 | 44 |
45 static void jabber_x_data_ok_cb(struct jabber_x_data_data *data, GaimRequestFields *fields) { | 45 static void jabber_x_data_ok_cb(struct jabber_x_data_data *data, PurpleRequestFields *fields) { |
46 xmlnode *result = xmlnode_new("x"); | 46 xmlnode *result = xmlnode_new("x"); |
47 jabber_x_data_cb cb = data->cb; | 47 jabber_x_data_cb cb = data->cb; |
48 gpointer user_data = data->user_data; | 48 gpointer user_data = data->user_data; |
49 JabberStream *js = data->js; | 49 JabberStream *js = data->js; |
50 GList *groups, *flds; | 50 GList *groups, *flds; |
51 | 51 |
52 xmlnode_set_namespace(result, "jabber:x:data"); | 52 xmlnode_set_namespace(result, "jabber:x:data"); |
53 xmlnode_set_attrib(result, "type", "submit"); | 53 xmlnode_set_attrib(result, "type", "submit"); |
54 | 54 |
55 for(groups = gaim_request_fields_get_groups(fields); groups; groups = groups->next) { | 55 for(groups = purple_request_fields_get_groups(fields); groups; groups = groups->next) { |
56 for(flds = gaim_request_field_group_get_fields(groups->data); flds; flds = flds->next) { | 56 for(flds = purple_request_field_group_get_fields(groups->data); flds; flds = flds->next) { |
57 xmlnode *fieldnode, *valuenode; | 57 xmlnode *fieldnode, *valuenode; |
58 GaimRequestField *field = flds->data; | 58 PurpleRequestField *field = flds->data; |
59 const char *id = gaim_request_field_get_id(field); | 59 const char *id = purple_request_field_get_id(field); |
60 jabber_x_data_field_type type = GPOINTER_TO_INT(g_hash_table_lookup(data->fields, id)); | 60 jabber_x_data_field_type type = GPOINTER_TO_INT(g_hash_table_lookup(data->fields, id)); |
61 | 61 |
62 switch(type) { | 62 switch(type) { |
63 case JABBER_X_DATA_TEXT_SINGLE: | 63 case JABBER_X_DATA_TEXT_SINGLE: |
64 case JABBER_X_DATA_JID_SINGLE: | 64 case JABBER_X_DATA_JID_SINGLE: |
65 { | 65 { |
66 const char *value = gaim_request_field_string_get_value(field); | 66 const char *value = purple_request_field_string_get_value(field); |
67 fieldnode = xmlnode_new_child(result, "field"); | 67 fieldnode = xmlnode_new_child(result, "field"); |
68 xmlnode_set_attrib(fieldnode, "var", id); | 68 xmlnode_set_attrib(fieldnode, "var", id); |
69 valuenode = xmlnode_new_child(fieldnode, "value"); | 69 valuenode = xmlnode_new_child(fieldnode, "value"); |
70 if(value) | 70 if(value) |
71 xmlnode_insert_data(valuenode, value, -1); | 71 xmlnode_insert_data(valuenode, value, -1); |
72 break; | 72 break; |
73 } | 73 } |
74 case JABBER_X_DATA_TEXT_MULTI: | 74 case JABBER_X_DATA_TEXT_MULTI: |
75 { | 75 { |
76 char **pieces, **p; | 76 char **pieces, **p; |
77 const char *value = gaim_request_field_string_get_value(field); | 77 const char *value = purple_request_field_string_get_value(field); |
78 fieldnode = xmlnode_new_child(result, "field"); | 78 fieldnode = xmlnode_new_child(result, "field"); |
79 xmlnode_set_attrib(fieldnode, "var", id); | 79 xmlnode_set_attrib(fieldnode, "var", id); |
80 | 80 |
81 pieces = g_strsplit(value, "\n", -1); | 81 pieces = g_strsplit(value, "\n", -1); |
82 for(p = pieces; *p != NULL; p++) { | 82 for(p = pieces; *p != NULL; p++) { |
87 } | 87 } |
88 break; | 88 break; |
89 case JABBER_X_DATA_LIST_SINGLE: | 89 case JABBER_X_DATA_LIST_SINGLE: |
90 case JABBER_X_DATA_LIST_MULTI: | 90 case JABBER_X_DATA_LIST_MULTI: |
91 { | 91 { |
92 const GList *selected = gaim_request_field_list_get_selected(field); | 92 const GList *selected = purple_request_field_list_get_selected(field); |
93 char *value; | 93 char *value; |
94 fieldnode = xmlnode_new_child(result, "field"); | 94 fieldnode = xmlnode_new_child(result, "field"); |
95 xmlnode_set_attrib(fieldnode, "var", id); | 95 xmlnode_set_attrib(fieldnode, "var", id); |
96 | 96 |
97 while(selected) { | 97 while(selected) { |
98 value = gaim_request_field_list_get_data(field, selected->data); | 98 value = purple_request_field_list_get_data(field, selected->data); |
99 valuenode = xmlnode_new_child(fieldnode, "value"); | 99 valuenode = xmlnode_new_child(fieldnode, "value"); |
100 if(value) | 100 if(value) |
101 xmlnode_insert_data(valuenode, value, -1); | 101 xmlnode_insert_data(valuenode, value, -1); |
102 selected = selected->next; | 102 selected = selected->next; |
103 } | 103 } |
105 break; | 105 break; |
106 case JABBER_X_DATA_BOOLEAN: | 106 case JABBER_X_DATA_BOOLEAN: |
107 fieldnode = xmlnode_new_child(result, "field"); | 107 fieldnode = xmlnode_new_child(result, "field"); |
108 xmlnode_set_attrib(fieldnode, "var", id); | 108 xmlnode_set_attrib(fieldnode, "var", id); |
109 valuenode = xmlnode_new_child(fieldnode, "value"); | 109 valuenode = xmlnode_new_child(fieldnode, "value"); |
110 if(gaim_request_field_bool_get_value(field)) | 110 if(purple_request_field_bool_get_value(field)) |
111 xmlnode_insert_data(valuenode, "1", -1); | 111 xmlnode_insert_data(valuenode, "1", -1); |
112 else | 112 else |
113 xmlnode_insert_data(valuenode, "0", -1); | 113 xmlnode_insert_data(valuenode, "0", -1); |
114 break; | 114 break; |
115 case JABBER_X_DATA_IGNORE: | 115 case JABBER_X_DATA_IGNORE: |
126 g_free(data); | 126 g_free(data); |
127 | 127 |
128 cb(js, result, user_data); | 128 cb(js, result, user_data); |
129 } | 129 } |
130 | 130 |
131 static void jabber_x_data_cancel_cb(struct jabber_x_data_data *data, GaimRequestFields *fields) { | 131 static void jabber_x_data_cancel_cb(struct jabber_x_data_data *data, PurpleRequestFields *fields) { |
132 xmlnode *result = xmlnode_new("x"); | 132 xmlnode *result = xmlnode_new("x"); |
133 jabber_x_data_cb cb = data->cb; | 133 jabber_x_data_cb cb = data->cb; |
134 gpointer user_data = data->user_data; | 134 gpointer user_data = data->user_data; |
135 JabberStream *js = data->js; | 135 JabberStream *js = data->js; |
136 g_hash_table_destroy(data->fields); | 136 g_hash_table_destroy(data->fields); |
148 | 148 |
149 void *jabber_x_data_request(JabberStream *js, xmlnode *packet, jabber_x_data_cb cb, gpointer user_data) | 149 void *jabber_x_data_request(JabberStream *js, xmlnode *packet, jabber_x_data_cb cb, gpointer user_data) |
150 { | 150 { |
151 void *handle; | 151 void *handle; |
152 xmlnode *fn, *x; | 152 xmlnode *fn, *x; |
153 GaimRequestFields *fields; | 153 PurpleRequestFields *fields; |
154 GaimRequestFieldGroup *group; | 154 PurpleRequestFieldGroup *group; |
155 GaimRequestField *field; | 155 PurpleRequestField *field; |
156 | 156 |
157 char *title = NULL; | 157 char *title = NULL; |
158 char *instructions = NULL; | 158 char *instructions = NULL; |
159 | 159 |
160 struct jabber_x_data_data *data = g_new0(struct jabber_x_data_data, 1); | 160 struct jabber_x_data_data *data = g_new0(struct jabber_x_data_data, 1); |
162 data->fields = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL); | 162 data->fields = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL); |
163 data->user_data = user_data; | 163 data->user_data = user_data; |
164 data->cb = cb; | 164 data->cb = cb; |
165 data->js = js; | 165 data->js = js; |
166 | 166 |
167 fields = gaim_request_fields_new(); | 167 fields = purple_request_fields_new(); |
168 group = gaim_request_field_group_new(NULL); | 168 group = purple_request_field_group_new(NULL); |
169 gaim_request_fields_add_group(fields, group); | 169 purple_request_fields_add_group(fields, group); |
170 | 170 |
171 for(fn = xmlnode_get_child(packet, "field"); fn; fn = xmlnode_get_next_twin(fn)) { | 171 for(fn = xmlnode_get_child(packet, "field"); fn; fn = xmlnode_get_next_twin(fn)) { |
172 xmlnode *valuenode; | 172 xmlnode *valuenode; |
173 const char *type = xmlnode_get_attrib(fn, "type"); | 173 const char *type = xmlnode_get_attrib(fn, "type"); |
174 const char *label = xmlnode_get_attrib(fn, "label"); | 174 const char *label = xmlnode_get_attrib(fn, "label"); |
191 | 191 |
192 if(!strcmp(type, "text-private")) { | 192 if(!strcmp(type, "text-private")) { |
193 if((valuenode = xmlnode_get_child(fn, "value"))) | 193 if((valuenode = xmlnode_get_child(fn, "value"))) |
194 value = xmlnode_get_data(valuenode); | 194 value = xmlnode_get_data(valuenode); |
195 | 195 |
196 field = gaim_request_field_string_new(var, label, | 196 field = purple_request_field_string_new(var, label, |
197 value ? value : "", FALSE); | 197 value ? value : "", FALSE); |
198 gaim_request_field_string_set_masked(field, TRUE); | 198 purple_request_field_string_set_masked(field, TRUE); |
199 gaim_request_field_group_add_field(group, field); | 199 purple_request_field_group_add_field(group, field); |
200 | 200 |
201 g_hash_table_replace(data->fields, g_strdup(var), GINT_TO_POINTER(JABBER_X_DATA_TEXT_SINGLE)); | 201 g_hash_table_replace(data->fields, g_strdup(var), GINT_TO_POINTER(JABBER_X_DATA_TEXT_SINGLE)); |
202 | 202 |
203 if(value) | 203 if(value) |
204 g_free(value); | 204 g_free(value); |
213 | 213 |
214 g_string_append_printf(str, "%s\n", value); | 214 g_string_append_printf(str, "%s\n", value); |
215 g_free(value); | 215 g_free(value); |
216 } | 216 } |
217 | 217 |
218 field = gaim_request_field_string_new(var, label, | 218 field = purple_request_field_string_new(var, label, |
219 str->str, TRUE); | 219 str->str, TRUE); |
220 gaim_request_field_group_add_field(group, field); | 220 purple_request_field_group_add_field(group, field); |
221 | 221 |
222 g_hash_table_replace(data->fields, g_strdup(var), GINT_TO_POINTER(JABBER_X_DATA_TEXT_MULTI)); | 222 g_hash_table_replace(data->fields, g_strdup(var), GINT_TO_POINTER(JABBER_X_DATA_TEXT_MULTI)); |
223 | 223 |
224 g_string_free(str, TRUE); | 224 g_string_free(str, TRUE); |
225 } else if(!strcmp(type, "list-single") || !strcmp(type, "list-multi")) { | 225 } else if(!strcmp(type, "list-single") || !strcmp(type, "list-multi")) { |
226 xmlnode *optnode; | 226 xmlnode *optnode; |
227 GList *selected = NULL; | 227 GList *selected = NULL; |
228 | 228 |
229 field = gaim_request_field_list_new(var, label); | 229 field = purple_request_field_list_new(var, label); |
230 | 230 |
231 if(!strcmp(type, "list-multi")) { | 231 if(!strcmp(type, "list-multi")) { |
232 gaim_request_field_list_set_multi_select(field, TRUE); | 232 purple_request_field_list_set_multi_select(field, TRUE); |
233 g_hash_table_replace(data->fields, g_strdup(var), | 233 g_hash_table_replace(data->fields, g_strdup(var), |
234 GINT_TO_POINTER(JABBER_X_DATA_LIST_MULTI)); | 234 GINT_TO_POINTER(JABBER_X_DATA_LIST_MULTI)); |
235 } else { | 235 } else { |
236 g_hash_table_replace(data->fields, g_strdup(var), | 236 g_hash_table_replace(data->fields, g_strdup(var), |
237 GINT_TO_POINTER(JABBER_X_DATA_LIST_SINGLE)); | 237 GINT_TO_POINTER(JABBER_X_DATA_LIST_SINGLE)); |
255 if(!(lbl = xmlnode_get_attrib(optnode, "label"))) | 255 if(!(lbl = xmlnode_get_attrib(optnode, "label"))) |
256 label = value; | 256 label = value; |
257 | 257 |
258 data->values = g_slist_prepend(data->values, value); | 258 data->values = g_slist_prepend(data->values, value); |
259 | 259 |
260 gaim_request_field_list_add(field, lbl, value); | 260 purple_request_field_list_add(field, lbl, value); |
261 if(g_list_find_custom(selected, value, (GCompareFunc)strcmp)) | 261 if(g_list_find_custom(selected, value, (GCompareFunc)strcmp)) |
262 gaim_request_field_list_add_selected(field, lbl); | 262 purple_request_field_list_add_selected(field, lbl); |
263 } | 263 } |
264 gaim_request_field_group_add_field(group, field); | 264 purple_request_field_group_add_field(group, field); |
265 | 265 |
266 while(selected) { | 266 while(selected) { |
267 g_free(selected->data); | 267 g_free(selected->data); |
268 selected = g_list_delete_link(selected, selected); | 268 selected = g_list_delete_link(selected, selected); |
269 } | 269 } |
276 | 276 |
277 if(value && (!g_ascii_strcasecmp(value, "yes") || | 277 if(value && (!g_ascii_strcasecmp(value, "yes") || |
278 !g_ascii_strcasecmp(value, "true") || !g_ascii_strcasecmp(value, "1"))) | 278 !g_ascii_strcasecmp(value, "true") || !g_ascii_strcasecmp(value, "1"))) |
279 def = TRUE; | 279 def = TRUE; |
280 | 280 |
281 field = gaim_request_field_bool_new(var, label, def); | 281 field = purple_request_field_bool_new(var, label, def); |
282 gaim_request_field_group_add_field(group, field); | 282 purple_request_field_group_add_field(group, field); |
283 | 283 |
284 g_hash_table_replace(data->fields, g_strdup(var), GINT_TO_POINTER(JABBER_X_DATA_BOOLEAN)); | 284 g_hash_table_replace(data->fields, g_strdup(var), GINT_TO_POINTER(JABBER_X_DATA_BOOLEAN)); |
285 | 285 |
286 if(value) | 286 if(value) |
287 g_free(value); | 287 g_free(value); |
288 } else if(!strcmp(type, "fixed") && value) { | 288 } else if(!strcmp(type, "fixed") && value) { |
289 if((valuenode = xmlnode_get_child(fn, "value"))) | 289 if((valuenode = xmlnode_get_child(fn, "value"))) |
290 value = xmlnode_get_data(valuenode); | 290 value = xmlnode_get_data(valuenode); |
291 | 291 |
292 field = gaim_request_field_label_new("", value); | 292 field = purple_request_field_label_new("", value); |
293 gaim_request_field_group_add_field(group, field); | 293 purple_request_field_group_add_field(group, field); |
294 | 294 |
295 if(value) | 295 if(value) |
296 g_free(value); | 296 g_free(value); |
297 } else if(!strcmp(type, "hidden")) { | 297 } else if(!strcmp(type, "hidden")) { |
298 if((valuenode = xmlnode_get_child(fn, "value"))) | 298 if((valuenode = xmlnode_get_child(fn, "value"))) |
299 value = xmlnode_get_data(valuenode); | 299 value = xmlnode_get_data(valuenode); |
300 | 300 |
301 field = gaim_request_field_string_new(var, "", value ? value : "", | 301 field = purple_request_field_string_new(var, "", value ? value : "", |
302 FALSE); | 302 FALSE); |
303 gaim_request_field_set_visible(field, FALSE); | 303 purple_request_field_set_visible(field, FALSE); |
304 gaim_request_field_group_add_field(group, field); | 304 purple_request_field_group_add_field(group, field); |
305 | 305 |
306 g_hash_table_replace(data->fields, g_strdup(var), GINT_TO_POINTER(JABBER_X_DATA_TEXT_SINGLE)); | 306 g_hash_table_replace(data->fields, g_strdup(var), GINT_TO_POINTER(JABBER_X_DATA_TEXT_SINGLE)); |
307 | 307 |
308 if(value) | 308 if(value) |
309 g_free(value); | 309 g_free(value); |
310 } else { /* text-single, jid-single, and the default */ | 310 } else { /* text-single, jid-single, and the default */ |
311 if((valuenode = xmlnode_get_child(fn, "value"))) | 311 if((valuenode = xmlnode_get_child(fn, "value"))) |
312 value = xmlnode_get_data(valuenode); | 312 value = xmlnode_get_data(valuenode); |
313 | 313 |
314 field = gaim_request_field_string_new(var, label, | 314 field = purple_request_field_string_new(var, label, |
315 value ? value : "", FALSE); | 315 value ? value : "", FALSE); |
316 gaim_request_field_group_add_field(group, field); | 316 purple_request_field_group_add_field(group, field); |
317 | 317 |
318 if(!strcmp(type, "jid-single")) { | 318 if(!strcmp(type, "jid-single")) { |
319 gaim_request_field_set_type_hint(field, "screenname"); | 319 purple_request_field_set_type_hint(field, "screenname"); |
320 g_hash_table_replace(data->fields, g_strdup(var), GINT_TO_POINTER(JABBER_X_DATA_JID_SINGLE)); | 320 g_hash_table_replace(data->fields, g_strdup(var), GINT_TO_POINTER(JABBER_X_DATA_JID_SINGLE)); |
321 } else { | 321 } else { |
322 g_hash_table_replace(data->fields, g_strdup(var), GINT_TO_POINTER(JABBER_X_DATA_TEXT_SINGLE)); | 322 g_hash_table_replace(data->fields, g_strdup(var), GINT_TO_POINTER(JABBER_X_DATA_TEXT_SINGLE)); |
323 } | 323 } |
324 | 324 |
331 title = xmlnode_get_data(x); | 331 title = xmlnode_get_data(x); |
332 | 332 |
333 if((x = xmlnode_get_child(packet, "instructions"))) | 333 if((x = xmlnode_get_child(packet, "instructions"))) |
334 instructions = xmlnode_get_data(x); | 334 instructions = xmlnode_get_data(x); |
335 | 335 |
336 handle = gaim_request_fields(js->gc, title, title, instructions, fields, | 336 handle = purple_request_fields(js->gc, title, title, instructions, fields, |
337 _("OK"), G_CALLBACK(jabber_x_data_ok_cb), | 337 _("OK"), G_CALLBACK(jabber_x_data_ok_cb), |
338 _("Cancel"), G_CALLBACK(jabber_x_data_cancel_cb), data); | 338 _("Cancel"), G_CALLBACK(jabber_x_data_cancel_cb), data); |
339 | 339 |
340 if(title) | 340 if(title) |
341 g_free(title); | 341 g_free(title); |