annotate src/protocols/jabber/xdata.c @ 13329:1d569233f257

[gaim-migrate @ 15699] fix a stupid bug (SF 1432924) committer: Tailor Script <tailor@pidgin.im>
author Nathan Walp <nwalp@pidgin.im>
date Sun, 26 Feb 2006 19:35:31 +0000
parents 387ba791d5f9
children 25e63008d3bb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7923
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
1 /*
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
2 * gaim - Jabber Protocol Plugin
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
3 *
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
4 * Copyright (C) 2003, Nathan Walp <faceprint@faceprint.com>
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
5 *
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
6 * This program is free software; you can redistribute it and/or modify
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
7 * it under the terms of the GNU General Public License as published by
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
8 * the Free Software Foundation; either version 2 of the License, or
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
9 * (at your option) any later version.
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
10 *
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
11 * This program is distributed in the hope that it will be useful,
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
14 * GNU General Public License for more details.
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
15 *
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
16 * You should have received a copy of the GNU General Public License
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
17 * along with this program; if not, write to the Free Software
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
19 *
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
20 */
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
21 #include "internal.h"
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
22 #include "request.h"
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
23 #include "server.h"
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
24
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
25 #include "xdata.h"
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
26
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
27 typedef enum {
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
28 JABBER_X_DATA_IGNORE = 0,
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
29 JABBER_X_DATA_TEXT_SINGLE,
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
30 JABBER_X_DATA_TEXT_MULTI,
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
31 JABBER_X_DATA_LIST_SINGLE,
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
32 JABBER_X_DATA_LIST_MULTI,
8295
bc850664b559 [gaim-migrate @ 9019]
Nathan Walp <nwalp@pidgin.im>
parents: 8135
diff changeset
33 JABBER_X_DATA_BOOLEAN,
bc850664b559 [gaim-migrate @ 9019]
Nathan Walp <nwalp@pidgin.im>
parents: 8135
diff changeset
34 JABBER_X_DATA_JID_SINGLE
7923
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
35 } jabber_x_data_field_type;
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
36
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
37 struct jabber_x_data_data {
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
38 GHashTable *fields;
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
39 GSList *values;
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
40 jabber_x_data_cb cb;
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
41 gpointer user_data;
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
42 JabberStream *js;
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
43 };
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
44
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
45 static void jabber_x_data_ok_cb(struct jabber_x_data_data *data, GaimRequestFields *fields) {
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
46 xmlnode *result = xmlnode_new("x");
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
47 jabber_x_data_cb cb = data->cb;
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
48 gpointer user_data = data->user_data;
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
49 JabberStream *js = data->js;
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
50 GList *groups, *flds;
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
51
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
52 xmlnode_set_attrib(result, "xmlns", "jabber:x:data");
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
53 xmlnode_set_attrib(result, "type", "submit");
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
54
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
55 for(groups = gaim_request_fields_get_groups(fields); groups; groups = groups->next) {
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
56 for(flds = gaim_request_field_group_get_fields(groups->data); flds; flds = flds->next) {
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
57 xmlnode *fieldnode, *valuenode;
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
58 GaimRequestField *field = flds->data;
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
59 const char *id = gaim_request_field_get_id(field);
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
60 jabber_x_data_field_type type = GPOINTER_TO_INT(g_hash_table_lookup(data->fields, id));
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
61
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
62 switch(type) {
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
63 case JABBER_X_DATA_TEXT_SINGLE:
8295
bc850664b559 [gaim-migrate @ 9019]
Nathan Walp <nwalp@pidgin.im>
parents: 8135
diff changeset
64 case JABBER_X_DATA_JID_SINGLE:
7923
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
65 {
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
66 const char *value = gaim_request_field_string_get_value(field);
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
67 fieldnode = xmlnode_new_child(result, "field");
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
68 xmlnode_set_attrib(fieldnode, "var", id);
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
69 valuenode = xmlnode_new_child(fieldnode, "value");
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
70 if(value)
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
71 xmlnode_insert_data(valuenode, value, -1);
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
72 break;
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
73 }
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
74 case JABBER_X_DATA_TEXT_MULTI:
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
75 {
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
76 char **pieces, **p;
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
77 const char *value = gaim_request_field_string_get_value(field);
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
78 fieldnode = xmlnode_new_child(result, "field");
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
79 xmlnode_set_attrib(fieldnode, "var", id);
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
80
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
81 pieces = g_strsplit(value, "\n", -1);
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
82 for(p = pieces; *p != NULL; p++) {
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
83 valuenode = xmlnode_new_child(fieldnode, "value");
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
84 xmlnode_insert_data(valuenode, *p, -1);
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
85 }
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
86 g_strfreev(pieces);
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
87 }
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
88 break;
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
89 case JABBER_X_DATA_LIST_SINGLE:
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
90 case JABBER_X_DATA_LIST_MULTI:
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
91 {
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
92 const GList *selected = gaim_request_field_list_get_selected(field);
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
93 char *value;
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
94 fieldnode = xmlnode_new_child(result, "field");
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
95 xmlnode_set_attrib(fieldnode, "var", id);
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
96
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
97 while(selected) {
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
98 value = gaim_request_field_list_get_data(field, selected->data);
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
99 valuenode = xmlnode_new_child(fieldnode, "value");
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
100 if(value)
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
101 xmlnode_insert_data(valuenode, value, -1);
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
102 selected = selected->next;
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
103 }
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
104 }
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
105 break;
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
106 case JABBER_X_DATA_BOOLEAN:
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
107 fieldnode = xmlnode_new_child(result, "field");
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
108 xmlnode_set_attrib(fieldnode, "var", id);
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
109 valuenode = xmlnode_new_child(fieldnode, "value");
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
110 if(gaim_request_field_bool_get_value(field))
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
111 xmlnode_insert_data(valuenode, "1", -1);
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
112 else
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
113 xmlnode_insert_data(valuenode, "0", -1);
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
114 break;
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
115 case JABBER_X_DATA_IGNORE:
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
116 break;
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
117 }
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
118 }
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
119 }
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
120
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
121 g_hash_table_destroy(data->fields);
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
122 while(data->values) {
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
123 g_free(data->values->data);
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
124 data->values = g_slist_delete_link(data->values, data->values);
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
125 }
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
126 g_free(data);
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
127
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
128 cb(js, result, user_data);
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
129 }
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
130
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
131 static void jabber_x_data_cancel_cb(struct jabber_x_data_data *data, GaimRequestFields *fields) {
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
132 xmlnode *result = xmlnode_new("x");
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
133 jabber_x_data_cb cb = data->cb;
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
134 gpointer user_data = data->user_data;
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
135 JabberStream *js = data->js;
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
136 g_hash_table_destroy(data->fields);
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
137 while(data->values) {
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
138 g_free(data->values->data);
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
139 data->values = g_slist_delete_link(data->values, data->values);
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
140 }
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
141 g_free(data);
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
142
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
143 xmlnode_set_attrib(result, "xmlns", "jabber:x:data");
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
144 xmlnode_set_attrib(result, "type", "cancel");
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
145
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
146 cb(js, result, user_data);
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
147 }
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
148
8396
387ba791d5f9 [gaim-migrate @ 9125]
Nathan Walp <nwalp@pidgin.im>
parents: 8390
diff changeset
149 void *jabber_x_data_request(JabberStream *js, xmlnode *packet, jabber_x_data_cb cb, gpointer user_data)
7923
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
150 {
8396
387ba791d5f9 [gaim-migrate @ 9125]
Nathan Walp <nwalp@pidgin.im>
parents: 8390
diff changeset
151 void *handle;
7923
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
152 xmlnode *fn, *x;
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
153 GaimRequestFields *fields;
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
154 GaimRequestFieldGroup *group;
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
155 GaimRequestField *field;
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
156
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
157 char *title = NULL;
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
158 char *instructions = NULL;
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
159
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
160 struct jabber_x_data_data *data = g_new0(struct jabber_x_data_data, 1);
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
161
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
162 data->fields = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
163 data->user_data = user_data;
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
164 data->cb = cb;
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
165 data->js = js;
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
166
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
167 fields = gaim_request_fields_new();
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
168 group = gaim_request_field_group_new(NULL);
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
169 gaim_request_fields_add_group(fields, group);
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
170
8135
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
171 for(fn = xmlnode_get_child(packet, "field"); fn; fn = xmlnode_get_next_twin(fn)) {
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
172 xmlnode *valuenode;
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
173 const char *type = xmlnode_get_attrib(fn, "type");
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
174 const char *label = xmlnode_get_attrib(fn, "label");
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
175 const char *var = xmlnode_get_attrib(fn, "var");
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
176 char *value = NULL;
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
177
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
178 if(!type)
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
179 continue;
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
180
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
181 if(!var && strcmp(type, "fixed"))
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
182 continue;
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
183 if(!label)
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
184 label = var;
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
185
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
186 if((valuenode = xmlnode_get_child(fn, "value")))
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
187 value = xmlnode_get_data(valuenode);
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
188
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
189
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
190 /* XXX: handle <required/> */
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
191
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
192 if(!strcmp(type, "text-private")) {
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
193 if((valuenode = xmlnode_get_child(fn, "value")))
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
194 value = xmlnode_get_data(valuenode);
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
195
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
196 field = gaim_request_field_string_new(var, label,
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
197 value ? value : "", FALSE);
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
198 gaim_request_field_string_set_masked(field, TRUE);
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
199 gaim_request_field_group_add_field(group, field);
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
200
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
201 g_hash_table_replace(data->fields, g_strdup(var), GINT_TO_POINTER(JABBER_X_DATA_TEXT_SINGLE));
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
202
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
203 if(value)
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
204 g_free(value);
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
205 } else if(!strcmp(type, "text-multi") || !strcmp(type, "jid-multi")) {
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
206 GString *str = g_string_new("");
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
207
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
208 for(valuenode = xmlnode_get_child(fn, "value"); valuenode;
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
209 valuenode = xmlnode_get_next_twin(valuenode)) {
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
210
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
211 if(!(value = xmlnode_get_data(valuenode)))
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
212 continue;
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
213
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
214 g_string_append_printf(str, "%s\n", value);
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
215 g_free(value);
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
216 }
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
217
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
218 field = gaim_request_field_string_new(var, label,
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
219 str->str, TRUE);
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
220 gaim_request_field_group_add_field(group, field);
7923
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
221
8135
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
222 g_hash_table_replace(data->fields, g_strdup(var), GINT_TO_POINTER(JABBER_X_DATA_TEXT_MULTI));
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
223
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
224 g_string_free(str, TRUE);
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
225 } else if(!strcmp(type, "list-single") || !strcmp(type, "list-multi")) {
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
226 xmlnode *optnode;
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
227 GList *selected = NULL;
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
228
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
229 field = gaim_request_field_list_new(var, label);
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
230
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
231 if(!strcmp(type, "list-multi")) {
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
232 gaim_request_field_list_set_multi_select(field, TRUE);
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
233 g_hash_table_replace(data->fields, g_strdup(var),
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
234 GINT_TO_POINTER(JABBER_X_DATA_LIST_MULTI));
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
235 } else {
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
236 g_hash_table_replace(data->fields, g_strdup(var),
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
237 GINT_TO_POINTER(JABBER_X_DATA_LIST_SINGLE));
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
238 }
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
239
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
240 for(valuenode = xmlnode_get_child(fn, "value"); valuenode;
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
241 valuenode = xmlnode_get_next_twin(valuenode)) {
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
242 selected = g_list_prepend(selected, xmlnode_get_data(valuenode));
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
243 }
7923
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
244
8135
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
245 for(optnode = xmlnode_get_child(fn, "option"); optnode;
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
246 optnode = xmlnode_get_next_twin(optnode)) {
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
247 const char *lbl;
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
248
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
249 if(!(valuenode = xmlnode_get_child(optnode, "value")))
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
250 continue;
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
251
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
252 if(!(value = xmlnode_get_data(valuenode)))
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
253 continue;
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
254
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
255 if(!(lbl = xmlnode_get_attrib(optnode, "label")))
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
256 label = value;
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
257
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
258 data->values = g_slist_prepend(data->values, value);
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
259
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
260 gaim_request_field_list_add(field, lbl, value);
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
261 if(g_list_find_custom(selected, value, (GCompareFunc)strcmp))
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
262 gaim_request_field_list_add_selected(field, lbl);
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
263 }
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
264 gaim_request_field_group_add_field(group, field);
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
265
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
266 while(selected) {
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
267 g_free(selected->data);
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
268 selected = g_list_delete_link(selected, selected);
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
269 }
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
270
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
271 } else if(!strcmp(type, "boolean")) {
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
272 gboolean def = FALSE;
7923
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
273
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
274 if((valuenode = xmlnode_get_child(fn, "value")))
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
275 value = xmlnode_get_data(valuenode);
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
276
8390
f6a5348f7410 [gaim-migrate @ 9119]
Mark Doliner <mark@kingant.net>
parents: 8385
diff changeset
277 if(value && (!g_ascii_strcasecmp(value, "yes") ||
f6a5348f7410 [gaim-migrate @ 9119]
Mark Doliner <mark@kingant.net>
parents: 8385
diff changeset
278 !g_ascii_strcasecmp(value, "true") || !g_ascii_strcasecmp(value, "1")))
8135
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
279 def = TRUE;
7923
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
280
8135
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
281 field = gaim_request_field_bool_new(var, label, def);
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
282 gaim_request_field_group_add_field(group, field);
7923
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
283
8135
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
284 g_hash_table_replace(data->fields, g_strdup(var), GINT_TO_POINTER(JABBER_X_DATA_BOOLEAN));
7923
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
285
8135
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
286 if(value)
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
287 g_free(value);
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
288 } else if(!strcmp(type, "fixed") && value) {
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
289 if((valuenode = xmlnode_get_child(fn, "value")))
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
290 value = xmlnode_get_data(valuenode);
7923
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
291
8135
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
292 field = gaim_request_field_label_new("", value);
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
293 gaim_request_field_group_add_field(group, field);
7923
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
294
8135
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
295 if(value)
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
296 g_free(value);
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
297 } else if(!strcmp(type, "hidden")) {
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
298 if((valuenode = xmlnode_get_child(fn, "value")))
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
299 value = xmlnode_get_data(valuenode);
7923
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
300
8135
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
301 field = gaim_request_field_string_new(var, "", value ? value : "",
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
302 FALSE);
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
303 gaim_request_field_set_visible(field, FALSE);
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
304 gaim_request_field_group_add_field(group, field);
7923
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
305
8135
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
306 g_hash_table_replace(data->fields, g_strdup(var), GINT_TO_POINTER(JABBER_X_DATA_TEXT_SINGLE));
7923
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
307
8135
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
308 if(value)
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
309 g_free(value);
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
310 } else { /* text-single, jid-single, and the default */
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
311 if((valuenode = xmlnode_get_child(fn, "value")))
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
312 value = xmlnode_get_data(valuenode);
7923
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
313
8135
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
314 field = gaim_request_field_string_new(var, label,
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
315 value ? value : "", FALSE);
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
316 gaim_request_field_group_add_field(group, field);
7923
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
317
8295
bc850664b559 [gaim-migrate @ 9019]
Nathan Walp <nwalp@pidgin.im>
parents: 8135
diff changeset
318 if(!strcmp(type, "jid-single")) {
bc850664b559 [gaim-migrate @ 9019]
Nathan Walp <nwalp@pidgin.im>
parents: 8135
diff changeset
319 gaim_request_field_set_type_hint(field, "screenname");
bc850664b559 [gaim-migrate @ 9019]
Nathan Walp <nwalp@pidgin.im>
parents: 8135
diff changeset
320 g_hash_table_replace(data->fields, g_strdup(var), GINT_TO_POINTER(JABBER_X_DATA_JID_SINGLE));
bc850664b559 [gaim-migrate @ 9019]
Nathan Walp <nwalp@pidgin.im>
parents: 8135
diff changeset
321 } else {
bc850664b559 [gaim-migrate @ 9019]
Nathan Walp <nwalp@pidgin.im>
parents: 8135
diff changeset
322 g_hash_table_replace(data->fields, g_strdup(var), GINT_TO_POINTER(JABBER_X_DATA_TEXT_SINGLE));
bc850664b559 [gaim-migrate @ 9019]
Nathan Walp <nwalp@pidgin.im>
parents: 8135
diff changeset
323 }
7923
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
324
8135
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
325 if(value)
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8010
diff changeset
326 g_free(value);
7923
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
327 }
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
328 }
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
329
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
330 if((x = xmlnode_get_child(packet, "title")))
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
331 title = xmlnode_get_data(x);
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
332
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
333 if((x = xmlnode_get_child(packet, "instructions")))
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
334 instructions = xmlnode_get_data(x);
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
335
8396
387ba791d5f9 [gaim-migrate @ 9125]
Nathan Walp <nwalp@pidgin.im>
parents: 8390
diff changeset
336 handle = gaim_request_fields(js->gc, title, title, instructions, fields,
387ba791d5f9 [gaim-migrate @ 9125]
Nathan Walp <nwalp@pidgin.im>
parents: 8390
diff changeset
337 _("OK"), G_CALLBACK(jabber_x_data_ok_cb),
7923
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
338 _("Cancel"), G_CALLBACK(jabber_x_data_cancel_cb), data);
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
339
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
340 if(title)
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
341 g_free(title);
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
342 if(instructions)
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
343 g_free(instructions);
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
344
8396
387ba791d5f9 [gaim-migrate @ 9125]
Nathan Walp <nwalp@pidgin.im>
parents: 8390
diff changeset
345 return handle;
7923
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
346 }
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
347
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
348