|
1 /* |
|
2 * check.c |
|
3 * |
|
4 * Copyrigth (C) 2010 Nicolas Cornu <nicolas.cornu@ensi-bourges.fr> |
|
5 * |
|
6 * This program is free software; you can redistribute it and/or modify |
|
7 * it under the terms of the GNU General Public License as published by |
|
8 * the Free Software Foundation; either version 2 of the License, or (at |
|
9 * your option) any later version. |
|
10 * |
|
11 * This program is distributed in the hope that it will be useful, but |
|
12 * WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
14 * General Public License for more details. |
|
15 * |
|
16 * You should have received a copy of the GNU General Public License |
|
17 * along with this program; if not, write to the Free Software |
|
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
|
19 * USA |
|
20 */ |
|
21 |
|
22 #include <glib.h> |
|
23 #include <loudmouth/loudmouth.h> |
|
24 |
|
25 #include "check.h" |
|
26 #include "jingle.h" |
|
27 |
|
28 |
|
29 const gchar *jingle_content_creator[] = { |
|
30 "initiator", |
|
31 "responder", |
|
32 NULL |
|
33 }; |
|
34 |
|
35 const gchar *jingle_content_senders[] = { |
|
36 "both", |
|
37 "initiator", |
|
38 "none", |
|
39 "responder", |
|
40 NULL |
|
41 }; |
|
42 |
|
43 |
|
44 /** |
|
45 * Populate a jingle_data struct from a <jingle> element. |
|
46 * Check if the element is in compliance with the XEP. |
|
47 */ |
|
48 gboolean check_jingle(LmMessageNode *node, JingleData *jd, GError **err) |
|
49 { |
|
50 gint nb_reason = 0; |
|
51 LmMessageNode *child = NULL; |
|
52 const gchar *actionstr; |
|
53 |
|
54 actionstr = lm_message_node_get_attribute(node, "action"); |
|
55 jd->initiator = lm_message_node_get_attribute(node, "initiator"); |
|
56 jd->responder = lm_message_node_get_attribute(node, "responder"); |
|
57 jd->sid = lm_message_node_get_attribute(node, "sid"); |
|
58 |
|
59 if (actionstr == NULL || jd->sid == NULL) { |
|
60 g_set_error(err, JINGLE_CHECK_ERROR, JINGLE_CHECK_ERROR_MISSING, |
|
61 "an attribute of the jingle element is missing"); |
|
62 return FALSE; |
|
63 } |
|
64 |
|
65 jd->action = jingle_action_from_str(actionstr); |
|
66 if (jd->action == JINGLE_UNKNOWN_ACTION) { |
|
67 g_set_error(err, JINGLE_CHECK_ERROR, JINGLE_CHECK_ERROR_BADVALUE, |
|
68 "the action attribute is invalid"); |
|
69 return FALSE; |
|
70 } |
|
71 |
|
72 // check childs |
|
73 for (child = node->children; child; child = child->next) { |
|
74 if (!g_strcmp0(child->name, "reason")) |
|
75 nb_reason++; |
|
76 } |
|
77 |
|
78 if (nb_reason > 1) { |
|
79 g_set_error(err, JINGLE_CHECK_ERROR, JINGLE_CHECK_ERROR_BADELEM, |
|
80 "too many reason elements"); |
|
81 return FALSE; |
|
82 } |
|
83 |
|
84 return TRUE; |
|
85 } |
|
86 |
|
87 GQuark jingle_check_error_quark() |
|
88 { |
|
89 return g_quark_from_string("JINGLE_CHECK_ERROR"); |
|
90 } |