35 |
35 |
36 #define DESCRIPTION ( "Common PEP events listener" ) |
36 #define DESCRIPTION ( "Common PEP events listener" ) |
37 |
37 |
38 static module_info_t info_pep_experimental = { |
38 static module_info_t info_pep_experimental = { |
39 .branch = "experimental", |
39 .branch = "experimental", |
40 .api = 5, |
40 .api = 10, |
41 .version = PROJECT_VERSION, |
41 .version = PROJECT_VERSION, |
42 .description = DESCRIPTION, |
42 .description = DESCRIPTION, |
43 .requires = NULL, |
43 .requires = NULL, |
44 .init = pep_init, |
44 .init = pep_init, |
45 .uninit = pep_uninit, |
45 .uninit = pep_uninit, |
46 .next = NULL, |
46 .next = NULL, |
47 }; |
47 }; |
48 |
48 |
49 module_info_t info_pep = { |
49 module_info_t info_pep = { |
50 .branch = "dev", |
50 .branch = "dev", |
51 .api = 4, |
51 .api = 11, |
52 .version = PROJECT_VERSION, |
52 .version = PROJECT_VERSION, |
53 .description = DESCRIPTION, |
53 .description = DESCRIPTION, |
54 .requires = NULL, |
54 .requires = NULL, |
55 .init = pep_init, |
55 .init = pep_init, |
56 .uninit = pep_uninit, |
56 .uninit = pep_uninit, |
66 GDestroyNotify destroy_notify; |
66 GDestroyNotify destroy_notify; |
67 }; |
67 }; |
68 |
68 |
69 static GSList *pep_xmlns_handlers = NULL; |
69 static GSList *pep_xmlns_handlers = NULL; |
70 |
70 |
|
71 static guint pep_hid_connect = 0; |
|
72 static guint pep_hid_disconnect = 0; |
|
73 |
71 static LmMessageHandler *pep_message_handler = NULL; |
74 static LmMessageHandler *pep_message_handler = NULL; |
72 static LmMessageHandler *pep_iq_handler = NULL; |
75 static LmMessageHandler *pep_iq_handler = NULL; |
73 |
76 |
74 static pep_handler_t *pep_find_handler (const gchar *xmlns) |
77 static pep_handler_t *pep_find_handler (const gchar *xmlns) |
75 { |
78 { |
185 lm_connection_unregister_message_handler (lconnection, pep_iq_handler, LM_MESSAGE_TYPE_IQ); |
188 lm_connection_unregister_message_handler (lconnection, pep_iq_handler, LM_MESSAGE_TYPE_IQ); |
186 } |
189 } |
187 } |
190 } |
188 |
191 |
189 // release handlers before reconnect |
192 // release handlers before reconnect |
190 static void pep_hh (guint32 hid, hk_arg_t *args, gpointer userdata) |
193 static guint pep_hch (const gchar *hid, hk_arg_t *args, gpointer userdata) |
191 { |
194 { |
192 if (hid == HOOK_POST_CONNECT) |
195 pep_register_handlers (); |
193 pep_register_handlers (); |
196 return HOOK_HANDLER_RESULT_ALLOW_MORE_HANDLERS; |
194 else if (hid == HOOK_PRE_DISCONNECT) |
197 } |
195 pep_unregister_handlers (); |
198 |
|
199 static guint pep_hdh (const gchar *hid, hk_arg_t *args, gpointer userdata) |
|
200 { |
|
201 pep_unregister_handlers (); |
|
202 return HOOK_HANDLER_RESULT_ALLOW_MORE_HANDLERS; |
196 } |
203 } |
197 |
204 |
198 static void pep_init (void) |
205 static void pep_init (void) |
199 { |
206 { |
200 // create handlers |
207 // create handlers |
201 pep_message_handler = lm_message_handler_new (pep_message_event_handler, NULL, NULL); |
208 pep_message_handler = lm_message_handler_new (pep_message_event_handler, NULL, NULL); |
202 pep_iq_handler = lm_message_handler_new (pep_iq_pubsub_handler, NULL, NULL); |
209 pep_iq_handler = lm_message_handler_new (pep_iq_pubsub_handler, NULL, NULL); |
203 |
210 |
204 // register hook handler |
211 // register hook handler |
205 hk_add_handler (pep_hh, HOOK_POST_CONNECT | HOOK_PRE_DISCONNECT, NULL); |
212 pep_hid_connect = hk_add_handler (pep_hch, HOOK_POST_CONNECT, G_PRIORITY_DEFAULT, NULL); |
|
213 pep_hid_disconnect = hk_add_handler (pep_hdh, HOOK_PRE_DISCONNECT, G_PRIORITY_DEFAULT, NULL); |
206 |
214 |
207 // register handlers to connection |
215 // register handlers to connection |
208 pep_register_handlers (); |
216 pep_register_handlers (); |
209 } |
217 } |
210 |
218 |
212 { |
220 { |
213 // release handlers |
221 // release handlers |
214 pep_unregister_handlers (); |
222 pep_unregister_handlers (); |
215 |
223 |
216 // remove hook |
224 // remove hook |
217 hk_del_handler (pep_hh, NULL); |
225 hk_del_handler (HOOK_POST_CONNECT, pep_hid_connect); |
|
226 hk_del_handler (HOOK_PRE_DISCONNECT, pep_hid_disconnect); |
218 |
227 |
219 { // unregister xmlns handlers |
228 { // unregister xmlns handlers |
220 GSList *hel; |
229 GSList *hel; |
221 |
230 |
222 for (hel = pep_xmlns_handlers; hel; hel = hel -> next) { |
231 for (hel = pep_xmlns_handlers; hel; hel = hel -> next) { |