|
1 /* |
|
2 * pep.c -- Common pep routines |
|
3 * |
|
4 * Copyrigth (C) 2009 Myhailo Danylenko <isbear@ukrpost.net> |
|
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 #include <string.h> |
|
25 |
|
26 #include <mcabber/xmpp.h> |
|
27 #include <mcabber/hooks.h> |
|
28 #include <mcabber/modules.h> |
|
29 #include <mcabber/logprint.h> |
|
30 |
|
31 #define NS_JINGLE "urn:xmpp:jingle:1" |
|
32 |
|
33 struct info_iq { |
|
34 const gchar *from, *to, *type, *id; |
|
35 }; |
|
36 struct info_jingle { |
|
37 const gchar *xmlns, *action, *initiator, *sid; |
|
38 }; |
|
39 |
|
40 static void mcjingle_init (void); |
|
41 static void mcjingle_uninit (void); |
|
42 |
|
43 void parse_iq (LmMessageNode *iq, struct info_iq *ii) { |
|
44 if(!strcmp(iq->name, "iq")) { |
|
45 ii->to = ii->from = ii->type = ii->id = NULL; |
|
46 return; |
|
47 } |
|
48 |
|
49 ii->from = lm_message_node_get_attribute (iq, "from"); |
|
50 ii->to = lm_message_node_get_attribute (iq, "to"); |
|
51 ii->type = lm_message_node_get_attribute (iq, "type"); |
|
52 ii->id = lm_message_node_get_attribute (iq, "id"); |
|
53 } |
|
54 void parse_jingle (LmMessageNode *jingle, struct info_jingle *ij) { |
|
55 if(!strcmp(ij->name, "jingle")) { |
|
56 ij->to = ij->from = ij->type = ij->id = NULL; |
|
57 return; |
|
58 } |
|
59 |
|
60 ii->from = lm_message_node_get_attribute (iq, "from"); |
|
61 ii->to = lm_message_node_get_attribute (iq, "to"); |
|
62 ii->type = lm_message_node_get_attribute (iq, "type"); |
|
63 ii->id = lm_message_node_get_attribute (iq, "id"); |
|
64 } |
|
65 |
|
66 |
|
67 LmMessageHandler* lm = NULL; |
|
68 |
|
69 module_info_t info_jingle = { |
|
70 .branch = MCABBER_BRANCH, |
|
71 .api = MCABBER_API_VERSION, |
|
72 .version = MCABBER_VERSION, |
|
73 .description = "A module for jingle", |
|
74 .requires = NULL, |
|
75 .init = mcjingle_init, |
|
76 .uninit = mcjingle_uninit, |
|
77 .next = NULL, |
|
78 }; |
|
79 |
|
80 LmHandlerResult gestionnaire_lm(LmMessageHandler *handler, |
|
81 LmConnection *connection, LmMessage *message, |
|
82 gpointer user_data) |
|
83 { |
|
84 LmMessageNode * test = lm_message_get_node(message)->children; |
|
85 struct info_iq ii; |
|
86 parse_iq(lm_message_get_node(message), &ii); |
|
87 if(!strcmp(test->name, "jingle")) { |
|
88 if(!strcmp(lm_message_node_get_attribute(test, "xmlns"), NS_JINGLE)) { |
|
89 gchar* action = g_strdup(lm_message_node_get_attribute(test, "action")); |
|
90 gchar* initiator = g_strdup(lm_message_node_get_attribute(test, "initiator")); |
|
91 gchar* responder = g_strdup(lm_message_node_get_attribute(test, "responder")); |
|
92 gchar* sid = g_strdup(lm_message_node_get_attribute(test, "sid")); |
|
93 if(!strcmp(action, "content-accept")) { |
|
94 } else if (!strcmp(action, "content-add")) { |
|
95 } else if (!strcmp(action, "content-modify")) { |
|
96 } else if (!strcmp(action, "content-reject")) { |
|
97 } else if (!strcmp(action, "content-remove")) { |
|
98 } else if (!strcmp(action, "description-info")) { |
|
99 } else if (!strcmp(action, "security-info")) { |
|
100 } else if (!strcmp(action, "session-accept")) { |
|
101 } else if (!strcmp(action, "session-info")) { |
|
102 } else if (!strcmp(action, "session-initiate")) { |
|
103 LmMessageNode *child = NULL; |
|
104 gchar* disposition = NULL; |
|
105 for(child = test->children; child; child = child->next) { |
|
106 if(!strcmp((disposition = lm_message_node_get_attribute(child, "disposition")), "session")) |
|
107 break; |
|
108 if(!disposition) { |
|
109 disposition = g_strdup("session"); |
|
110 break; |
|
111 } |
|
112 } |
|
113 if(strcmp(disposition, "session")) { |
|
114 //ERREUR |
|
115 } |
|
116 |
|
117 } else if (!strcmp(action, "session-terminate")) { |
|
118 } else if (!strcmp(action, "transport-accept")) { |
|
119 } else if (!strcmp(action, "transport-info")) { |
|
120 } else if (!strcmp(action, "transport-reject")) { |
|
121 } else if (!strcmp(action, "transport-replace")) { |
|
122 } else { |
|
123 { // action inconnue => réponse XEP 0166 : 7.2 |
|
124 |
|
125 |
|
126 } |
|
127 } |
|
128 } else { |
|
129 scr_log_print(LPRINT_NORMAL, "jingle : Namespace inconnu (%s)", lm_message_node_get_attribute(test, "xmlns")); |
|
130 } |
|
131 } |
|
132 |
|
133 return LM_HANDLER_RESULT_ALLOW_MORE_HANDLERS; |
|
134 } |
|
135 |
|
136 /* Initialization */ |
|
137 static void mcjingle_init(void) |
|
138 { |
|
139 lm = lm_message_handler_new(gestionnaire_lm, NULL, NULL); |
|
140 lm_connection_register_message_handler (lconnection, lm, LM_MESSAGE_TYPE_IQ, LM_HANDLER_PRIORITY_FIRST); |
|
141 } |
|
142 |
|
143 /* Uninitialization */ |
|
144 static void mcjingle_uninit(void) |
|
145 { |
|
146 lm_connection_unregister_message_handler (lconnection, lm, LM_MESSAGE_TYPE_IQ); |
|
147 lm_message_handler_invalidate (lm); |
|
148 lm_message_handler_unref (lm); |
|
149 } |