Sat, 13 Mar 2021 05:39:22 -0600
Add purple_request_field_choice_add_full
Use `PurpleKeyValuePair`'s `value_destroy_func` to store choice value destroy function.
Testing Done:
Compile and run.
Reviewed at https://reviews.imfreedom.org/r/561/
| 7923 | 1 | /* |
| 15884 | 2 | * purple - Jabber Protocol Plugin |
| 7923 | 3 | * |
|
28322
ac8fec1d2234
Remove specific copyright lines from the XMPP prpl.
Paul Aurich <darkrain42@pidgin.im>
parents:
26565
diff
changeset
|
4 | * Purple is the legal property of its developers, whose names are too numerous |
|
ac8fec1d2234
Remove specific copyright lines from the XMPP prpl.
Paul Aurich <darkrain42@pidgin.im>
parents:
26565
diff
changeset
|
5 | * to list here. Please refer to the COPYRIGHT file distributed with this |
|
ac8fec1d2234
Remove specific copyright lines from the XMPP prpl.
Paul Aurich <darkrain42@pidgin.im>
parents:
26565
diff
changeset
|
6 | * source distribution. |
| 7923 | 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify | |
| 9 | * it under the terms of the GNU General Public License as published by | |
| 10 | * the Free Software Foundation; either version 2 of the License, or | |
| 11 | * (at your option) any later version. | |
| 12 | * | |
| 13 | * This program is distributed in the hope that it will be useful, | |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 16 | * GNU General Public License for more details. | |
| 17 | * | |
| 18 | * You should have received a copy of the GNU General Public License | |
| 19 | * along with this program; if not, write to the Free Software | |
|
19859
71d37b57eff2
The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
19051
diff
changeset
|
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
| 7923 | 21 | * |
| 22 | */ | |
|
40441
f23c7e772667
Make sure we're not including the gettext macros in header files and deal with the repercussions of that.
Gary Kramlich <grim@reaperworld.com>
parents:
40439
diff
changeset
|
23 | |
|
f23c7e772667
Make sure we're not including the gettext macros in header files and deal with the repercussions of that.
Gary Kramlich <grim@reaperworld.com>
parents:
40439
diff
changeset
|
24 | #include <glib/gi18n-lib.h> |
|
f23c7e772667
Make sure we're not including the gettext macros in header files and deal with the repercussions of that.
Gary Kramlich <grim@reaperworld.com>
parents:
40439
diff
changeset
|
25 | |
|
40358
e6fe6fc1f516
move all protocols, purple plugins, and purple tests to use purple.h instead of including files individually
Gary Kramlich <grim@reaperworld.com>
parents:
40062
diff
changeset
|
26 | #include <purple.h> |
| 7923 | 27 | |
| 28 | #include "xdata.h" | |
| 29 | ||
| 30 | typedef enum { | |
| 31 | JABBER_X_DATA_IGNORE = 0, | |
| 32 | JABBER_X_DATA_TEXT_SINGLE, | |
| 33 | JABBER_X_DATA_TEXT_MULTI, | |
| 34 | JABBER_X_DATA_LIST_SINGLE, | |
| 35 | JABBER_X_DATA_LIST_MULTI, | |
| 8295 | 36 | JABBER_X_DATA_BOOLEAN, |
| 37 | JABBER_X_DATA_JID_SINGLE | |
| 7923 | 38 | } jabber_x_data_field_type; |
| 39 | ||
| 40 | struct jabber_x_data_data { | |
| 41 | GHashTable *fields; | |
| 42 | GSList *values; | |
|
17805
5bd417a1c847
Implemented XEP-0050: Ad-Hoc Commands. Note that this XEP requires sending an initial command to the peer, which is not implemented in libpurple itself (since this requires a discovery browser or equivalent).
Andreas Monitzer <am@adiumx.com>
parents:
17774
diff
changeset
|
43 | jabber_x_data_action_cb cb; |
| 7923 | 44 | gpointer user_data; |
| 45 | JabberStream *js; | |
|
17805
5bd417a1c847
Implemented XEP-0050: Ad-Hoc Commands. Note that this XEP requires sending an initial command to the peer, which is not implemented in libpurple itself (since this requires a discovery browser or equivalent).
Andreas Monitzer <am@adiumx.com>
parents:
17774
diff
changeset
|
46 | GList *actions; |
|
5bd417a1c847
Implemented XEP-0050: Ad-Hoc Commands. Note that this XEP requires sending an initial command to the peer, which is not implemented in libpurple itself (since this requires a discovery browser or equivalent).
Andreas Monitzer <am@adiumx.com>
parents:
17774
diff
changeset
|
47 | PurpleRequestFieldGroup *actiongroup; |
| 7923 | 48 | }; |
| 49 | ||
| 15884 | 50 | static void jabber_x_data_ok_cb(struct jabber_x_data_data *data, PurpleRequestFields *fields) { |
|
34935
686fa55b0deb
Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents:
30511
diff
changeset
|
51 | PurpleXmlNode *result = purple_xmlnode_new("x"); |
|
17805
5bd417a1c847
Implemented XEP-0050: Ad-Hoc Commands. Note that this XEP requires sending an initial command to the peer, which is not implemented in libpurple itself (since this requires a discovery browser or equivalent).
Andreas Monitzer <am@adiumx.com>
parents:
17774
diff
changeset
|
52 | jabber_x_data_action_cb cb = data->cb; |
| 7923 | 53 | gpointer user_data = data->user_data; |
| 54 | JabberStream *js = data->js; | |
| 55 | GList *groups, *flds; | |
|
17805
5bd417a1c847
Implemented XEP-0050: Ad-Hoc Commands. Note that this XEP requires sending an initial command to the peer, which is not implemented in libpurple itself (since this requires a discovery browser or equivalent).
Andreas Monitzer <am@adiumx.com>
parents:
17774
diff
changeset
|
56 | char *actionhandle = NULL; |
|
5bd417a1c847
Implemented XEP-0050: Ad-Hoc Commands. Note that this XEP requires sending an initial command to the peer, which is not implemented in libpurple itself (since this requires a discovery browser or equivalent).
Andreas Monitzer <am@adiumx.com>
parents:
17774
diff
changeset
|
57 | gboolean hasActions = (data->actions != NULL); |
| 7923 | 58 | |
|
34935
686fa55b0deb
Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents:
30511
diff
changeset
|
59 | purple_xmlnode_set_namespace(result, "jabber:x:data"); |
|
686fa55b0deb
Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents:
30511
diff
changeset
|
60 | purple_xmlnode_set_attrib(result, "type", "submit"); |
| 7923 | 61 | |
| 15884 | 62 | for(groups = purple_request_fields_get_groups(fields); groups; groups = groups->next) { |
|
17805
5bd417a1c847
Implemented XEP-0050: Ad-Hoc Commands. Note that this XEP requires sending an initial command to the peer, which is not implemented in libpurple itself (since this requires a discovery browser or equivalent).
Andreas Monitzer <am@adiumx.com>
parents:
17774
diff
changeset
|
63 | if(groups->data == data->actiongroup) { |
|
5bd417a1c847
Implemented XEP-0050: Ad-Hoc Commands. Note that this XEP requires sending an initial command to the peer, which is not implemented in libpurple itself (since this requires a discovery browser or equivalent).
Andreas Monitzer <am@adiumx.com>
parents:
17774
diff
changeset
|
64 | for(flds = purple_request_field_group_get_fields(groups->data); flds; flds = flds->next) { |
|
5bd417a1c847
Implemented XEP-0050: Ad-Hoc Commands. Note that this XEP requires sending an initial command to the peer, which is not implemented in libpurple itself (since this requires a discovery browser or equivalent).
Andreas Monitzer <am@adiumx.com>
parents:
17774
diff
changeset
|
65 | PurpleRequestField *field = flds->data; |
|
5bd417a1c847
Implemented XEP-0050: Ad-Hoc Commands. Note that this XEP requires sending an initial command to the peer, which is not implemented in libpurple itself (since this requires a discovery browser or equivalent).
Andreas Monitzer <am@adiumx.com>
parents:
17774
diff
changeset
|
66 | const char *id = purple_request_field_get_id(field); |
|
5bd417a1c847
Implemented XEP-0050: Ad-Hoc Commands. Note that this XEP requires sending an initial command to the peer, which is not implemented in libpurple itself (since this requires a discovery browser or equivalent).
Andreas Monitzer <am@adiumx.com>
parents:
17774
diff
changeset
|
67 | int handleindex; |
|
38259
c593fc9f5438
Replace strcmp() with purple_strequal()
qarkai <qarkai@gmail.com>
parents:
38258
diff
changeset
|
68 | if(!purple_strequal(id, "libpurple:jabber:xdata:actions")) |
|
17805
5bd417a1c847
Implemented XEP-0050: Ad-Hoc Commands. Note that this XEP requires sending an initial command to the peer, which is not implemented in libpurple itself (since this requires a discovery browser or equivalent).
Andreas Monitzer <am@adiumx.com>
parents:
17774
diff
changeset
|
69 | continue; |
|
34338
c652670afac5
Request API refactoring: custom PURPLE_REQUEST_CHOICE values, instead of indexes
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
34332
diff
changeset
|
70 | handleindex = GPOINTER_TO_INT(purple_request_field_choice_get_value(field)); |
|
17805
5bd417a1c847
Implemented XEP-0050: Ad-Hoc Commands. Note that this XEP requires sending an initial command to the peer, which is not implemented in libpurple itself (since this requires a discovery browser or equivalent).
Andreas Monitzer <am@adiumx.com>
parents:
17774
diff
changeset
|
71 | actionhandle = g_strdup(g_list_nth_data(data->actions, handleindex)); |
|
5bd417a1c847
Implemented XEP-0050: Ad-Hoc Commands. Note that this XEP requires sending an initial command to the peer, which is not implemented in libpurple itself (since this requires a discovery browser or equivalent).
Andreas Monitzer <am@adiumx.com>
parents:
17774
diff
changeset
|
72 | break; |
|
5bd417a1c847
Implemented XEP-0050: Ad-Hoc Commands. Note that this XEP requires sending an initial command to the peer, which is not implemented in libpurple itself (since this requires a discovery browser or equivalent).
Andreas Monitzer <am@adiumx.com>
parents:
17774
diff
changeset
|
73 | } |
|
5bd417a1c847
Implemented XEP-0050: Ad-Hoc Commands. Note that this XEP requires sending an initial command to the peer, which is not implemented in libpurple itself (since this requires a discovery browser or equivalent).
Andreas Monitzer <am@adiumx.com>
parents:
17774
diff
changeset
|
74 | continue; |
|
5bd417a1c847
Implemented XEP-0050: Ad-Hoc Commands. Note that this XEP requires sending an initial command to the peer, which is not implemented in libpurple itself (since this requires a discovery browser or equivalent).
Andreas Monitzer <am@adiumx.com>
parents:
17774
diff
changeset
|
75 | } |
| 15884 | 76 | for(flds = purple_request_field_group_get_fields(groups->data); flds; flds = flds->next) { |
|
34935
686fa55b0deb
Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents:
30511
diff
changeset
|
77 | PurpleXmlNode *fieldnode, *valuenode; |
| 15884 | 78 | PurpleRequestField *field = flds->data; |
| 79 | const char *id = purple_request_field_get_id(field); | |
| 7923 | 80 | jabber_x_data_field_type type = GPOINTER_TO_INT(g_hash_table_lookup(data->fields, id)); |
| 81 | ||
| 82 | switch(type) { | |
| 83 | case JABBER_X_DATA_TEXT_SINGLE: | |
| 8295 | 84 | case JABBER_X_DATA_JID_SINGLE: |
| 7923 | 85 | { |
| 15884 | 86 | const char *value = purple_request_field_string_get_value(field); |
|
16398
a895aca0a7ce
Ok I couldn't resist. For iChat and Adium buddies who are advertising
Mark Doliner <markdoliner@pidgin.im>
parents:
16136
diff
changeset
|
87 | if (value == NULL) |
|
a895aca0a7ce
Ok I couldn't resist. For iChat and Adium buddies who are advertising
Mark Doliner <markdoliner@pidgin.im>
parents:
16136
diff
changeset
|
88 | break; |
|
34935
686fa55b0deb
Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents:
30511
diff
changeset
|
89 | fieldnode = purple_xmlnode_new_child(result, "field"); |
|
686fa55b0deb
Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents:
30511
diff
changeset
|
90 | purple_xmlnode_set_attrib(fieldnode, "var", id); |
|
686fa55b0deb
Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents:
30511
diff
changeset
|
91 | valuenode = purple_xmlnode_new_child(fieldnode, "value"); |
|
39913
ce96d4639dc7
Remove redundant conditions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
38358
diff
changeset
|
92 | purple_xmlnode_insert_data(valuenode, value, -1); |
| 7923 | 93 | break; |
| 94 | } | |
| 95 | case JABBER_X_DATA_TEXT_MULTI: | |
| 96 | { | |
| 97 | char **pieces, **p; | |
| 15884 | 98 | const char *value = purple_request_field_string_get_value(field); |
|
16398
a895aca0a7ce
Ok I couldn't resist. For iChat and Adium buddies who are advertising
Mark Doliner <markdoliner@pidgin.im>
parents:
16136
diff
changeset
|
99 | if (value == NULL) |
|
a895aca0a7ce
Ok I couldn't resist. For iChat and Adium buddies who are advertising
Mark Doliner <markdoliner@pidgin.im>
parents:
16136
diff
changeset
|
100 | break; |
|
34935
686fa55b0deb
Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents:
30511
diff
changeset
|
101 | fieldnode = purple_xmlnode_new_child(result, "field"); |
|
686fa55b0deb
Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents:
30511
diff
changeset
|
102 | purple_xmlnode_set_attrib(fieldnode, "var", id); |
| 7923 | 103 | |
| 104 | pieces = g_strsplit(value, "\n", -1); | |
| 105 | for(p = pieces; *p != NULL; p++) { | |
|
34935
686fa55b0deb
Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents:
30511
diff
changeset
|
106 | valuenode = purple_xmlnode_new_child(fieldnode, "value"); |
|
686fa55b0deb
Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents:
30511
diff
changeset
|
107 | purple_xmlnode_insert_data(valuenode, *p, -1); |
| 7923 | 108 | } |
| 109 | g_strfreev(pieces); | |
| 110 | } | |
| 111 | break; | |
| 112 | case JABBER_X_DATA_LIST_SINGLE: | |
| 113 | case JABBER_X_DATA_LIST_MULTI: | |
| 114 | { | |
|
18190
bcf28ef7e8ff
Re-fix the DBus list handling code by killing const GList* / const GSList*
Richard Laager <rlaager@pidgin.im>
parents:
16490
diff
changeset
|
115 | GList *selected = purple_request_field_list_get_selected(field); |
| 7923 | 116 | char *value; |
|
34935
686fa55b0deb
Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents:
30511
diff
changeset
|
117 | fieldnode = purple_xmlnode_new_child(result, "field"); |
|
686fa55b0deb
Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents:
30511
diff
changeset
|
118 | purple_xmlnode_set_attrib(fieldnode, "var", id); |
| 7923 | 119 | |
| 120 | while(selected) { | |
| 15884 | 121 | value = purple_request_field_list_get_data(field, selected->data); |
|
34935
686fa55b0deb
Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents:
30511
diff
changeset
|
122 | valuenode = purple_xmlnode_new_child(fieldnode, "value"); |
| 7923 | 123 | if(value) |
|
34935
686fa55b0deb
Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents:
30511
diff
changeset
|
124 | purple_xmlnode_insert_data(valuenode, value, -1); |
| 7923 | 125 | selected = selected->next; |
| 126 | } | |
| 127 | } | |
| 128 | break; | |
| 129 | case JABBER_X_DATA_BOOLEAN: | |
|
34935
686fa55b0deb
Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents:
30511
diff
changeset
|
130 | fieldnode = purple_xmlnode_new_child(result, "field"); |
|
686fa55b0deb
Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents:
30511
diff
changeset
|
131 | purple_xmlnode_set_attrib(fieldnode, "var", id); |
|
686fa55b0deb
Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents:
30511
diff
changeset
|
132 | valuenode = purple_xmlnode_new_child(fieldnode, "value"); |
| 15884 | 133 | if(purple_request_field_bool_get_value(field)) |
|
34935
686fa55b0deb
Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents:
30511
diff
changeset
|
134 | purple_xmlnode_insert_data(valuenode, "1", -1); |
| 7923 | 135 | else |
|
34935
686fa55b0deb
Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents:
30511
diff
changeset
|
136 | purple_xmlnode_insert_data(valuenode, "0", -1); |
| 7923 | 137 | break; |
| 138 | case JABBER_X_DATA_IGNORE: | |
| 139 | break; | |
| 140 | } | |
| 141 | } | |
| 142 | } | |
| 143 | ||
| 144 | g_hash_table_destroy(data->fields); | |
|
40052
cc03b5af25ea
Use GSList functions instead of manual iterations
qarkai <qarkai@gmail.com>
parents:
40049
diff
changeset
|
145 | g_slist_free_full(data->values, g_free); |
| 40047 | 146 | g_list_free_full(data->actions, g_free); |
| 7923 | 147 | g_free(data); |
| 148 | ||
|
26565
94071f2569f2
Fix a potential memleak by freeing this regardless of whether hasActions
Mark Doliner <markdoliner@pidgin.im>
parents:
26042
diff
changeset
|
149 | if (hasActions) |
|
17805
5bd417a1c847
Implemented XEP-0050: Ad-Hoc Commands. Note that this XEP requires sending an initial command to the peer, which is not implemented in libpurple itself (since this requires a discovery browser or equivalent).
Andreas Monitzer <am@adiumx.com>
parents:
17774
diff
changeset
|
150 | cb(js, result, actionhandle, user_data); |
|
26565
94071f2569f2
Fix a potential memleak by freeing this regardless of whether hasActions
Mark Doliner <markdoliner@pidgin.im>
parents:
26042
diff
changeset
|
151 | else |
|
17805
5bd417a1c847
Implemented XEP-0050: Ad-Hoc Commands. Note that this XEP requires sending an initial command to the peer, which is not implemented in libpurple itself (since this requires a discovery browser or equivalent).
Andreas Monitzer <am@adiumx.com>
parents:
17774
diff
changeset
|
152 | ((jabber_x_data_cb)cb)(js, result, user_data); |
|
26565
94071f2569f2
Fix a potential memleak by freeing this regardless of whether hasActions
Mark Doliner <markdoliner@pidgin.im>
parents:
26042
diff
changeset
|
153 | |
|
94071f2569f2
Fix a potential memleak by freeing this regardless of whether hasActions
Mark Doliner <markdoliner@pidgin.im>
parents:
26042
diff
changeset
|
154 | g_free(actionhandle); |
| 7923 | 155 | } |
| 156 | ||
| 15884 | 157 | static void jabber_x_data_cancel_cb(struct jabber_x_data_data *data, PurpleRequestFields *fields) { |
|
34935
686fa55b0deb
Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents:
30511
diff
changeset
|
158 | PurpleXmlNode *result = purple_xmlnode_new("x"); |
|
17805
5bd417a1c847
Implemented XEP-0050: Ad-Hoc Commands. Note that this XEP requires sending an initial command to the peer, which is not implemented in libpurple itself (since this requires a discovery browser or equivalent).
Andreas Monitzer <am@adiumx.com>
parents:
17774
diff
changeset
|
159 | jabber_x_data_action_cb cb = data->cb; |
| 7923 | 160 | gpointer user_data = data->user_data; |
| 161 | JabberStream *js = data->js; | |
| 40049 | 162 | gboolean hasActions = (data->actions != NULL); |
| 7923 | 163 | g_hash_table_destroy(data->fields); |
|
40052
cc03b5af25ea
Use GSList functions instead of manual iterations
qarkai <qarkai@gmail.com>
parents:
40049
diff
changeset
|
164 | g_slist_free_full(data->values, g_free); |
| 40049 | 165 | g_list_free_full(data->actions, g_free); |
| 7923 | 166 | g_free(data); |
| 167 | ||
|
34935
686fa55b0deb
Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents:
30511
diff
changeset
|
168 | purple_xmlnode_set_namespace(result, "jabber:x:data"); |
|
686fa55b0deb
Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents:
30511
diff
changeset
|
169 | purple_xmlnode_set_attrib(result, "type", "cancel"); |
| 7923 | 170 | |
|
17805
5bd417a1c847
Implemented XEP-0050: Ad-Hoc Commands. Note that this XEP requires sending an initial command to the peer, which is not implemented in libpurple itself (since this requires a discovery browser or equivalent).
Andreas Monitzer <am@adiumx.com>
parents:
17774
diff
changeset
|
171 | if (hasActions) |
|
5bd417a1c847
Implemented XEP-0050: Ad-Hoc Commands. Note that this XEP requires sending an initial command to the peer, which is not implemented in libpurple itself (since this requires a discovery browser or equivalent).
Andreas Monitzer <am@adiumx.com>
parents:
17774
diff
changeset
|
172 | cb(js, result, NULL, user_data); |
|
5bd417a1c847
Implemented XEP-0050: Ad-Hoc Commands. Note that this XEP requires sending an initial command to the peer, which is not implemented in libpurple itself (since this requires a discovery browser or equivalent).
Andreas Monitzer <am@adiumx.com>
parents:
17774
diff
changeset
|
173 | else |
|
5bd417a1c847
Implemented XEP-0050: Ad-Hoc Commands. Note that this XEP requires sending an initial command to the peer, which is not implemented in libpurple itself (since this requires a discovery browser or equivalent).
Andreas Monitzer <am@adiumx.com>
parents:
17774
diff
changeset
|
174 | ((jabber_x_data_cb)cb)(js, result, user_data); |
| 7923 | 175 | } |
| 176 | ||
|
34935
686fa55b0deb
Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents:
30511
diff
changeset
|
177 | void *jabber_x_data_request(JabberStream *js, PurpleXmlNode *packet, jabber_x_data_cb cb, gpointer user_data) |
| 7923 | 178 | { |
|
17805
5bd417a1c847
Implemented XEP-0050: Ad-Hoc Commands. Note that this XEP requires sending an initial command to the peer, which is not implemented in libpurple itself (since this requires a discovery browser or equivalent).
Andreas Monitzer <am@adiumx.com>
parents:
17774
diff
changeset
|
179 | return jabber_x_data_request_with_actions(js, packet, NULL, 0, (jabber_x_data_action_cb)cb, user_data); |
|
5bd417a1c847
Implemented XEP-0050: Ad-Hoc Commands. Note that this XEP requires sending an initial command to the peer, which is not implemented in libpurple itself (since this requires a discovery browser or equivalent).
Andreas Monitzer <am@adiumx.com>
parents:
17774
diff
changeset
|
180 | } |
|
5bd417a1c847
Implemented XEP-0050: Ad-Hoc Commands. Note that this XEP requires sending an initial command to the peer, which is not implemented in libpurple itself (since this requires a discovery browser or equivalent).
Andreas Monitzer <am@adiumx.com>
parents:
17774
diff
changeset
|
181 | |
|
34935
686fa55b0deb
Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents:
30511
diff
changeset
|
182 | void *jabber_x_data_request_with_actions(JabberStream *js, PurpleXmlNode *packet, GList *actions, int defaultaction, jabber_x_data_action_cb cb, gpointer user_data) |
|
17805
5bd417a1c847
Implemented XEP-0050: Ad-Hoc Commands. Note that this XEP requires sending an initial command to the peer, which is not implemented in libpurple itself (since this requires a discovery browser or equivalent).
Andreas Monitzer <am@adiumx.com>
parents:
17774
diff
changeset
|
183 | { |
| 8396 | 184 | void *handle; |
|
34935
686fa55b0deb
Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents:
30511
diff
changeset
|
185 | PurpleXmlNode *fn, *x; |
| 15884 | 186 | PurpleRequestFields *fields; |
| 187 | PurpleRequestFieldGroup *group; | |
|
23493
e04778a3d29a
Kill the warning 'field' may be used uninitialized in this function
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
23176
diff
changeset
|
188 | PurpleRequestField *field = NULL; |
| 7923 | 189 | |
| 190 | char *title = NULL; | |
| 191 | char *instructions = NULL; | |
| 192 | ||
| 193 | struct jabber_x_data_data *data = g_new0(struct jabber_x_data_data, 1); | |
| 194 | ||
| 195 | data->fields = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL); | |
| 196 | data->user_data = user_data; | |
| 197 | data->cb = cb; | |
| 198 | data->js = js; | |
| 199 | ||
| 15884 | 200 | fields = purple_request_fields_new(); |
| 201 | group = purple_request_field_group_new(NULL); | |
| 202 | purple_request_fields_add_group(fields, group); | |
| 7923 | 203 | |
|
34935
686fa55b0deb
Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents:
30511
diff
changeset
|
204 | for(fn = purple_xmlnode_get_child(packet, "field"); fn; fn = purple_xmlnode_get_next_twin(fn)) { |
|
686fa55b0deb
Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents:
30511
diff
changeset
|
205 | PurpleXmlNode *valuenode; |
|
686fa55b0deb
Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents:
30511
diff
changeset
|
206 | const char *type = purple_xmlnode_get_attrib(fn, "type"); |
|
686fa55b0deb
Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents:
30511
diff
changeset
|
207 | const char *label = purple_xmlnode_get_attrib(fn, "label"); |
|
686fa55b0deb
Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents:
30511
diff
changeset
|
208 | const char *var = purple_xmlnode_get_attrib(fn, "var"); |
| 8135 | 209 | char *value = NULL; |
| 210 | ||
| 211 | if(!type) | |
|
17837
a9c447447c06
XEP-0004 says that if no field type is specified, text-single should be assumed.
Andreas Monitzer <am@adiumx.com>
parents:
17805
diff
changeset
|
212 | type = "text-single"; |
| 8135 | 213 | |
|
38259
c593fc9f5438
Replace strcmp() with purple_strequal()
qarkai <qarkai@gmail.com>
parents:
38258
diff
changeset
|
214 | if(!var && !purple_strequal(type, "fixed")) |
| 8135 | 215 | continue; |
| 216 | if(!label) | |
| 217 | label = var; | |
| 218 | ||
|
38258
9a6551eba09c
Replace !strcmp() with purple_strequal()
qarkai <qarkai@gmail.com>
parents:
30511
diff
changeset
|
219 | if(purple_strequal(type, "text-private")) { |
|
34935
686fa55b0deb
Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents:
30511
diff
changeset
|
220 | if((valuenode = purple_xmlnode_get_child(fn, "value"))) |
|
686fa55b0deb
Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents:
30511
diff
changeset
|
221 | value = purple_xmlnode_get_data(valuenode); |
| 8135 | 222 | |
| 15884 | 223 | field = purple_request_field_string_new(var, label, |
| 8135 | 224 | value ? value : "", FALSE); |
| 15884 | 225 | purple_request_field_string_set_masked(field, TRUE); |
| 226 | purple_request_field_group_add_field(group, field); | |
| 8135 | 227 | |
| 228 | g_hash_table_replace(data->fields, g_strdup(var), GINT_TO_POINTER(JABBER_X_DATA_TEXT_SINGLE)); | |
| 229 | ||
|
16136
49ddb8f06d96
I noticed some places where we were doing the whole
Mark Doliner <markdoliner@pidgin.im>
parents:
15884
diff
changeset
|
230 | g_free(value); |
|
38258
9a6551eba09c
Replace !strcmp() with purple_strequal()
qarkai <qarkai@gmail.com>
parents:
30511
diff
changeset
|
231 | } else if(purple_strequal(type, "text-multi") || purple_strequal(type, "jid-multi")) { |
| 8135 | 232 | GString *str = g_string_new(""); |
| 233 | ||
|
34935
686fa55b0deb
Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents:
30511
diff
changeset
|
234 | for(valuenode = purple_xmlnode_get_child(fn, "value"); valuenode; |
|
686fa55b0deb
Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents:
30511
diff
changeset
|
235 | valuenode = purple_xmlnode_get_next_twin(valuenode)) { |
| 8135 | 236 | |
|
34935
686fa55b0deb
Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents:
30511
diff
changeset
|
237 | if(!(value = purple_xmlnode_get_data(valuenode))) |
| 8135 | 238 | continue; |
| 239 | ||
| 240 | g_string_append_printf(str, "%s\n", value); | |
| 241 | g_free(value); | |
| 242 | } | |
| 243 | ||
| 15884 | 244 | field = purple_request_field_string_new(var, label, |
| 8135 | 245 | str->str, TRUE); |
| 15884 | 246 | purple_request_field_group_add_field(group, field); |
| 7923 | 247 | |
| 8135 | 248 | g_hash_table_replace(data->fields, g_strdup(var), GINT_TO_POINTER(JABBER_X_DATA_TEXT_MULTI)); |
| 249 | ||
| 250 | g_string_free(str, TRUE); | |
|
38258
9a6551eba09c
Replace !strcmp() with purple_strequal()
qarkai <qarkai@gmail.com>
parents:
30511
diff
changeset
|
251 | } else if(purple_strequal(type, "list-single") || purple_strequal(type, "list-multi")) { |
|
34935
686fa55b0deb
Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents:
30511
diff
changeset
|
252 | PurpleXmlNode *optnode; |
| 8135 | 253 | GList *selected = NULL; |
| 254 | ||
| 15884 | 255 | field = purple_request_field_list_new(var, label); |
| 8135 | 256 | |
|
38258
9a6551eba09c
Replace !strcmp() with purple_strequal()
qarkai <qarkai@gmail.com>
parents:
30511
diff
changeset
|
257 | if(purple_strequal(type, "list-multi")) { |
| 15884 | 258 | purple_request_field_list_set_multi_select(field, TRUE); |
| 8135 | 259 | g_hash_table_replace(data->fields, g_strdup(var), |
| 260 | GINT_TO_POINTER(JABBER_X_DATA_LIST_MULTI)); | |
| 261 | } else { | |
| 262 | g_hash_table_replace(data->fields, g_strdup(var), | |
| 263 | GINT_TO_POINTER(JABBER_X_DATA_LIST_SINGLE)); | |
| 264 | } | |
| 265 | ||
|
34935
686fa55b0deb
Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents:
30511
diff
changeset
|
266 | for(valuenode = purple_xmlnode_get_child(fn, "value"); valuenode; |
|
686fa55b0deb
Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents:
30511
diff
changeset
|
267 | valuenode = purple_xmlnode_get_next_twin(valuenode)) { |
|
686fa55b0deb
Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents:
30511
diff
changeset
|
268 | char *data = purple_xmlnode_get_data(valuenode); |
|
22664
d2e81c1408ae
If the default value of a list-single or list-multi data forms field is NULL
Etan Reisner <deryni@pidgin.im>
parents:
21653
diff
changeset
|
269 | if (data != NULL) { |
|
d2e81c1408ae
If the default value of a list-single or list-multi data forms field is NULL
Etan Reisner <deryni@pidgin.im>
parents:
21653
diff
changeset
|
270 | selected = g_list_prepend(selected, data); |
|
d2e81c1408ae
If the default value of a list-single or list-multi data forms field is NULL
Etan Reisner <deryni@pidgin.im>
parents:
21653
diff
changeset
|
271 | } |
| 8135 | 272 | } |
| 7923 | 273 | |
|
34935
686fa55b0deb
Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents:
30511
diff
changeset
|
274 | for(optnode = purple_xmlnode_get_child(fn, "option"); optnode; |
|
686fa55b0deb
Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents:
30511
diff
changeset
|
275 | optnode = purple_xmlnode_get_next_twin(optnode)) { |
| 8135 | 276 | const char *lbl; |
| 277 | ||
|
34935
686fa55b0deb
Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents:
30511
diff
changeset
|
278 | if(!(valuenode = purple_xmlnode_get_child(optnode, "value"))) |
| 8135 | 279 | continue; |
| 280 | ||
|
34935
686fa55b0deb
Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents:
30511
diff
changeset
|
281 | if(!(value = purple_xmlnode_get_data(valuenode))) |
| 8135 | 282 | continue; |
| 283 | ||
|
34935
686fa55b0deb
Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents:
30511
diff
changeset
|
284 | if(!(lbl = purple_xmlnode_get_attrib(optnode, "label"))) |
|
19051
b932fc2e28cd
For XMPP multi-selection lists in generic data forms, the intent here
Mark Doliner <markdoliner@pidgin.im>
parents:
18190
diff
changeset
|
285 | lbl = value; |
| 8135 | 286 | |
| 287 | data->values = g_slist_prepend(data->values, value); | |
| 288 | ||
|
24900
a19d983918c2
Deprecate purple_request_field_list_add()
Richard Laager <rlaager@pidgin.im>
parents:
23493
diff
changeset
|
289 | purple_request_field_list_add_icon(field, lbl, NULL, value); |
| 8135 | 290 | if(g_list_find_custom(selected, value, (GCompareFunc)strcmp)) |
| 15884 | 291 | purple_request_field_list_add_selected(field, lbl); |
| 8135 | 292 | } |
| 15884 | 293 | purple_request_field_group_add_field(group, field); |
| 8135 | 294 | |
|
40062
d25228fc7b8e
Use g_list_free_full instead of manual iterations
qarkai <qarkai@gmail.com>
parents:
40052
diff
changeset
|
295 | g_list_free_full(selected, g_free); |
|
38258
9a6551eba09c
Replace !strcmp() with purple_strequal()
qarkai <qarkai@gmail.com>
parents:
30511
diff
changeset
|
296 | } else if(purple_strequal(type, "boolean")) { |
| 8135 | 297 | gboolean def = FALSE; |
| 7923 | 298 | |
|
34935
686fa55b0deb
Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents:
30511
diff
changeset
|
299 | if((valuenode = purple_xmlnode_get_child(fn, "value"))) |
|
686fa55b0deb
Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents:
30511
diff
changeset
|
300 | value = purple_xmlnode_get_data(valuenode); |
| 7923 | 301 | |
|
8390
13e1ff9b2850
[gaim-migrate @ 9119]
Mark Doliner <markdoliner@pidgin.im>
parents:
8385
diff
changeset
|
302 | if(value && (!g_ascii_strcasecmp(value, "yes") || |
|
13e1ff9b2850
[gaim-migrate @ 9119]
Mark Doliner <markdoliner@pidgin.im>
parents:
8385
diff
changeset
|
303 | !g_ascii_strcasecmp(value, "true") || !g_ascii_strcasecmp(value, "1"))) |
| 8135 | 304 | def = TRUE; |
| 7923 | 305 | |
| 15884 | 306 | field = purple_request_field_bool_new(var, label, def); |
| 307 | purple_request_field_group_add_field(group, field); | |
| 7923 | 308 | |
| 8135 | 309 | g_hash_table_replace(data->fields, g_strdup(var), GINT_TO_POINTER(JABBER_X_DATA_BOOLEAN)); |
| 7923 | 310 | |
|
16136
49ddb8f06d96
I noticed some places where we were doing the whole
Mark Doliner <markdoliner@pidgin.im>
parents:
15884
diff
changeset
|
311 | g_free(value); |
|
38258
9a6551eba09c
Replace !strcmp() with purple_strequal()
qarkai <qarkai@gmail.com>
parents:
30511
diff
changeset
|
312 | } else if(purple_strequal(type, "fixed")) { |
|
34935
686fa55b0deb
Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents:
30511
diff
changeset
|
313 | if((valuenode = purple_xmlnode_get_child(fn, "value"))) |
|
686fa55b0deb
Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents:
30511
diff
changeset
|
314 | value = purple_xmlnode_get_data(valuenode); |
| 7923 | 315 | |
|
23176
90f6226370cb
applied changes from 069f197178d158cdd308687095c14d49d8eee0ed
Daniel Atallah <datallah@pidgin.im>
parents:
22664
diff
changeset
|
316 | if(value != NULL) { |
|
90f6226370cb
applied changes from 069f197178d158cdd308687095c14d49d8eee0ed
Daniel Atallah <datallah@pidgin.im>
parents:
22664
diff
changeset
|
317 | field = purple_request_field_label_new("", value); |
|
90f6226370cb
applied changes from 069f197178d158cdd308687095c14d49d8eee0ed
Daniel Atallah <datallah@pidgin.im>
parents:
22664
diff
changeset
|
318 | purple_request_field_group_add_field(group, field); |
| 7923 | 319 | |
|
23176
90f6226370cb
applied changes from 069f197178d158cdd308687095c14d49d8eee0ed
Daniel Atallah <datallah@pidgin.im>
parents:
22664
diff
changeset
|
320 | g_free(value); |
|
90f6226370cb
applied changes from 069f197178d158cdd308687095c14d49d8eee0ed
Daniel Atallah <datallah@pidgin.im>
parents:
22664
diff
changeset
|
321 | } |
|
38258
9a6551eba09c
Replace !strcmp() with purple_strequal()
qarkai <qarkai@gmail.com>
parents:
30511
diff
changeset
|
322 | } else if(purple_strequal(type, "hidden")) { |
|
34935
686fa55b0deb
Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents:
30511
diff
changeset
|
323 | if((valuenode = purple_xmlnode_get_child(fn, "value"))) |
|
686fa55b0deb
Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents:
30511
diff
changeset
|
324 | value = purple_xmlnode_get_data(valuenode); |
| 7923 | 325 | |
| 15884 | 326 | field = purple_request_field_string_new(var, "", value ? value : "", |
| 8135 | 327 | FALSE); |
| 15884 | 328 | purple_request_field_set_visible(field, FALSE); |
| 329 | purple_request_field_group_add_field(group, field); | |
| 7923 | 330 | |
| 8135 | 331 | g_hash_table_replace(data->fields, g_strdup(var), GINT_TO_POINTER(JABBER_X_DATA_TEXT_SINGLE)); |
| 7923 | 332 | |
|
16136
49ddb8f06d96
I noticed some places where we were doing the whole
Mark Doliner <markdoliner@pidgin.im>
parents:
15884
diff
changeset
|
333 | g_free(value); |
| 8135 | 334 | } else { /* text-single, jid-single, and the default */ |
|
34935
686fa55b0deb
Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents:
30511
diff
changeset
|
335 | if((valuenode = purple_xmlnode_get_child(fn, "value"))) |
|
686fa55b0deb
Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents:
30511
diff
changeset
|
336 | value = purple_xmlnode_get_data(valuenode); |
| 7923 | 337 | |
| 15884 | 338 | field = purple_request_field_string_new(var, label, |
| 8135 | 339 | value ? value : "", FALSE); |
| 15884 | 340 | purple_request_field_group_add_field(group, field); |
| 7923 | 341 | |
|
38258
9a6551eba09c
Replace !strcmp() with purple_strequal()
qarkai <qarkai@gmail.com>
parents:
30511
diff
changeset
|
342 | if(purple_strequal(type, "jid-single")) { |
| 15884 | 343 | purple_request_field_set_type_hint(field, "screenname"); |
| 8295 | 344 | g_hash_table_replace(data->fields, g_strdup(var), GINT_TO_POINTER(JABBER_X_DATA_JID_SINGLE)); |
| 345 | } else { | |
| 346 | g_hash_table_replace(data->fields, g_strdup(var), GINT_TO_POINTER(JABBER_X_DATA_TEXT_SINGLE)); | |
| 347 | } | |
| 7923 | 348 | |
|
16136
49ddb8f06d96
I noticed some places where we were doing the whole
Mark Doliner <markdoliner@pidgin.im>
parents:
15884
diff
changeset
|
349 | g_free(value); |
| 7923 | 350 | } |
|
19894
b273d0db2bdd
Fixed code indenting, some spaces were still left and now replaced by tabs.
Andreas Monitzer <am@adiumx.com>
parents:
19203
diff
changeset
|
351 | |
|
34935
686fa55b0deb
Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents:
30511
diff
changeset
|
352 | if(field && purple_xmlnode_get_child(fn, "required")) |
|
19894
b273d0db2bdd
Fixed code indenting, some spaces were still left and now replaced by tabs.
Andreas Monitzer <am@adiumx.com>
parents:
19203
diff
changeset
|
353 | purple_request_field_set_required(field,TRUE); |
| 7923 | 354 | } |
|
26042
4dabdb5fe213
Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
23493
diff
changeset
|
355 | |
|
17805
5bd417a1c847
Implemented XEP-0050: Ad-Hoc Commands. Note that this XEP requires sending an initial command to the peer, which is not implemented in libpurple itself (since this requires a discovery browser or equivalent).
Andreas Monitzer <am@adiumx.com>
parents:
17774
diff
changeset
|
356 | if(actions != NULL) { |
|
5bd417a1c847
Implemented XEP-0050: Ad-Hoc Commands. Note that this XEP requires sending an initial command to the peer, which is not implemented in libpurple itself (since this requires a discovery browser or equivalent).
Andreas Monitzer <am@adiumx.com>
parents:
17774
diff
changeset
|
357 | PurpleRequestField *actionfield; |
|
5bd417a1c847
Implemented XEP-0050: Ad-Hoc Commands. Note that this XEP requires sending an initial command to the peer, which is not implemented in libpurple itself (since this requires a discovery browser or equivalent).
Andreas Monitzer <am@adiumx.com>
parents:
17774
diff
changeset
|
358 | GList *action; |
|
34338
c652670afac5
Request API refactoring: custom PURPLE_REQUEST_CHOICE values, instead of indexes
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
34332
diff
changeset
|
359 | int i; |
|
c652670afac5
Request API refactoring: custom PURPLE_REQUEST_CHOICE values, instead of indexes
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
34332
diff
changeset
|
360 | |
|
17805
5bd417a1c847
Implemented XEP-0050: Ad-Hoc Commands. Note that this XEP requires sending an initial command to the peer, which is not implemented in libpurple itself (since this requires a discovery browser or equivalent).
Andreas Monitzer <am@adiumx.com>
parents:
17774
diff
changeset
|
361 | data->actiongroup = group = purple_request_field_group_new(_("Actions")); |
|
5bd417a1c847
Implemented XEP-0050: Ad-Hoc Commands. Note that this XEP requires sending an initial command to the peer, which is not implemented in libpurple itself (since this requires a discovery browser or equivalent).
Andreas Monitzer <am@adiumx.com>
parents:
17774
diff
changeset
|
362 | purple_request_fields_add_group(fields, group); |
|
34338
c652670afac5
Request API refactoring: custom PURPLE_REQUEST_CHOICE values, instead of indexes
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
34332
diff
changeset
|
363 | actionfield = purple_request_field_choice_new("libpurple:jabber:xdata:actions", _("Select an action"), GINT_TO_POINTER(defaultaction)); |
|
17805
5bd417a1c847
Implemented XEP-0050: Ad-Hoc Commands. Note that this XEP requires sending an initial command to the peer, which is not implemented in libpurple itself (since this requires a discovery browser or equivalent).
Andreas Monitzer <am@adiumx.com>
parents:
17774
diff
changeset
|
364 | |
|
34338
c652670afac5
Request API refactoring: custom PURPLE_REQUEST_CHOICE values, instead of indexes
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
34332
diff
changeset
|
365 | for(i = 0, action = actions; action; action = g_list_next(action), i++) { |
|
17805
5bd417a1c847
Implemented XEP-0050: Ad-Hoc Commands. Note that this XEP requires sending an initial command to the peer, which is not implemented in libpurple itself (since this requires a discovery browser or equivalent).
Andreas Monitzer <am@adiumx.com>
parents:
17774
diff
changeset
|
366 | JabberXDataAction *a = action->data; |
|
26042
4dabdb5fe213
Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
23493
diff
changeset
|
367 | |
|
34338
c652670afac5
Request API refactoring: custom PURPLE_REQUEST_CHOICE values, instead of indexes
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
34332
diff
changeset
|
368 | purple_request_field_choice_add(actionfield, a->name, GINT_TO_POINTER(i)); |
|
17805
5bd417a1c847
Implemented XEP-0050: Ad-Hoc Commands. Note that this XEP requires sending an initial command to the peer, which is not implemented in libpurple itself (since this requires a discovery browser or equivalent).
Andreas Monitzer <am@adiumx.com>
parents:
17774
diff
changeset
|
369 | data->actions = g_list_append(data->actions, g_strdup(a->handle)); |
|
5bd417a1c847
Implemented XEP-0050: Ad-Hoc Commands. Note that this XEP requires sending an initial command to the peer, which is not implemented in libpurple itself (since this requires a discovery browser or equivalent).
Andreas Monitzer <am@adiumx.com>
parents:
17774
diff
changeset
|
370 | } |
|
5bd417a1c847
Implemented XEP-0050: Ad-Hoc Commands. Note that this XEP requires sending an initial command to the peer, which is not implemented in libpurple itself (since this requires a discovery browser or equivalent).
Andreas Monitzer <am@adiumx.com>
parents:
17774
diff
changeset
|
371 | purple_request_field_set_required(actionfield,TRUE); |
|
5bd417a1c847
Implemented XEP-0050: Ad-Hoc Commands. Note that this XEP requires sending an initial command to the peer, which is not implemented in libpurple itself (since this requires a discovery browser or equivalent).
Andreas Monitzer <am@adiumx.com>
parents:
17774
diff
changeset
|
372 | purple_request_field_group_add_field(group, actionfield); |
| 7923 | 373 | } |
| 374 | ||
|
34935
686fa55b0deb
Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents:
30511
diff
changeset
|
375 | if((x = purple_xmlnode_get_child(packet, "title"))) |
|
686fa55b0deb
Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents:
30511
diff
changeset
|
376 | title = purple_xmlnode_get_data(x); |
| 7923 | 377 | |
|
34935
686fa55b0deb
Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents:
30511
diff
changeset
|
378 | if((x = purple_xmlnode_get_child(packet, "instructions"))) |
|
686fa55b0deb
Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents:
30511
diff
changeset
|
379 | instructions = purple_xmlnode_get_data(x); |
| 7923 | 380 | |
|
21653
621c47778132
merge of '73ae9aeda3c58fbf8437421da68d19d06f93e686'
Evan Schoenberg <evands@pidgin.im>
parents:
21233
diff
changeset
|
381 | handle = purple_request_fields(js->gc, title, title, instructions, fields, |
| 8396 | 382 | _("OK"), G_CALLBACK(jabber_x_data_ok_cb), |
|
16490
68c22924d66b
Added account, who, and conversation parameters to the request API calls, and updated all code to match. I can't compile the Perl module, so I'd appreciate it if someone who knows it would verify that this doesn't break Perl.
Evan Schoenberg <evands@pidgin.im>
parents:
16398
diff
changeset
|
383 | _("Cancel"), G_CALLBACK(jabber_x_data_cancel_cb), |
|
34332
876483829700
Request API refactoring: switch purple_request_fields to PurpleRequestCommonParameters
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
30511
diff
changeset
|
384 | purple_request_cpar_from_connection(js->gc), |
|
21653
621c47778132
merge of '73ae9aeda3c58fbf8437421da68d19d06f93e686'
Evan Schoenberg <evands@pidgin.im>
parents:
21233
diff
changeset
|
385 | data); |
| 7923 | 386 | |
|
16136
49ddb8f06d96
I noticed some places where we were doing the whole
Mark Doliner <markdoliner@pidgin.im>
parents:
15884
diff
changeset
|
387 | g_free(title); |
|
49ddb8f06d96
I noticed some places where we were doing the whole
Mark Doliner <markdoliner@pidgin.im>
parents:
15884
diff
changeset
|
388 | g_free(instructions); |
| 7923 | 389 | |
| 8396 | 390 | return handle; |
| 7923 | 391 | } |
| 392 | ||
|
30511
3e43438dbd72
jabber: Move (and harden) a function to xdata.c
Paul Aurich <darkrain42@pidgin.im>
parents:
29304
diff
changeset
|
393 | gchar * |
|
34935
686fa55b0deb
Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents:
30511
diff
changeset
|
394 | jabber_x_data_get_formtype(const PurpleXmlNode *form) |
|
30511
3e43438dbd72
jabber: Move (and harden) a function to xdata.c
Paul Aurich <darkrain42@pidgin.im>
parents:
29304
diff
changeset
|
395 | { |
|
34935
686fa55b0deb
Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents:
30511
diff
changeset
|
396 | PurpleXmlNode *field; |
| 7923 | 397 | |
|
30511
3e43438dbd72
jabber: Move (and harden) a function to xdata.c
Paul Aurich <darkrain42@pidgin.im>
parents:
29304
diff
changeset
|
398 | g_return_val_if_fail(form != NULL, NULL); |
|
3e43438dbd72
jabber: Move (and harden) a function to xdata.c
Paul Aurich <darkrain42@pidgin.im>
parents:
29304
diff
changeset
|
399 | |
|
34935
686fa55b0deb
Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents:
30511
diff
changeset
|
400 | for (field = purple_xmlnode_get_child((PurpleXmlNode *)form, "field"); field; |
|
686fa55b0deb
Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents:
30511
diff
changeset
|
401 | field = purple_xmlnode_get_next_twin(field)) { |
|
686fa55b0deb
Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents:
30511
diff
changeset
|
402 | const char *var = purple_xmlnode_get_attrib(field, "var"); |
|
30511
3e43438dbd72
jabber: Move (and harden) a function to xdata.c
Paul Aurich <darkrain42@pidgin.im>
parents:
29304
diff
changeset
|
403 | if (purple_strequal(var, "FORM_TYPE")) { |
|
34935
686fa55b0deb
Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents:
30511
diff
changeset
|
404 | PurpleXmlNode *value = purple_xmlnode_get_child(field, "value"); |
|
30511
3e43438dbd72
jabber: Move (and harden) a function to xdata.c
Paul Aurich <darkrain42@pidgin.im>
parents:
29304
diff
changeset
|
405 | if (value) |
|
34935
686fa55b0deb
Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents:
30511
diff
changeset
|
406 | return purple_xmlnode_get_data(value); |
|
30511
3e43438dbd72
jabber: Move (and harden) a function to xdata.c
Paul Aurich <darkrain42@pidgin.im>
parents:
29304
diff
changeset
|
407 | else |
|
3e43438dbd72
jabber: Move (and harden) a function to xdata.c
Paul Aurich <darkrain42@pidgin.im>
parents:
29304
diff
changeset
|
408 | /* An interesting corner case... Looking for a second |
|
3e43438dbd72
jabber: Move (and harden) a function to xdata.c
Paul Aurich <darkrain42@pidgin.im>
parents:
29304
diff
changeset
|
409 | * FORM_TYPE would be more considerate, but I'm in favor |
|
3e43438dbd72
jabber: Move (and harden) a function to xdata.c
Paul Aurich <darkrain42@pidgin.im>
parents:
29304
diff
changeset
|
410 | * of not helping broken clients. |
|
3e43438dbd72
jabber: Move (and harden) a function to xdata.c
Paul Aurich <darkrain42@pidgin.im>
parents:
29304
diff
changeset
|
411 | */ |
|
3e43438dbd72
jabber: Move (and harden) a function to xdata.c
Paul Aurich <darkrain42@pidgin.im>
parents:
29304
diff
changeset
|
412 | return NULL; |
|
3e43438dbd72
jabber: Move (and harden) a function to xdata.c
Paul Aurich <darkrain42@pidgin.im>
parents:
29304
diff
changeset
|
413 | } |
|
3e43438dbd72
jabber: Move (and harden) a function to xdata.c
Paul Aurich <darkrain42@pidgin.im>
parents:
29304
diff
changeset
|
414 | } |
|
3e43438dbd72
jabber: Move (and harden) a function to xdata.c
Paul Aurich <darkrain42@pidgin.im>
parents:
29304
diff
changeset
|
415 | |
|
3e43438dbd72
jabber: Move (and harden) a function to xdata.c
Paul Aurich <darkrain42@pidgin.im>
parents:
29304
diff
changeset
|
416 | /* Erm, none found :( */ |
|
3e43438dbd72
jabber: Move (and harden) a function to xdata.c
Paul Aurich <darkrain42@pidgin.im>
parents:
29304
diff
changeset
|
417 | return NULL; |
|
3e43438dbd72
jabber: Move (and harden) a function to xdata.c
Paul Aurich <darkrain42@pidgin.im>
parents:
29304
diff
changeset
|
418 | } |
|
3e43438dbd72
jabber: Move (and harden) a function to xdata.c
Paul Aurich <darkrain42@pidgin.im>
parents:
29304
diff
changeset
|
419 |