Mercurial > ~mikael > mcabber > hg
comparison mcabber/mcabber/carbons.c @ 2108:adfd962e1343
Allow the user to enable/disable carbons from the command line
author | Roeland Jago Douma <roeland@famdouma.nl> |
---|---|
date | Tue, 15 Oct 2013 19:07:18 +0200 |
parents | 72876dcf9094 |
children | 9b4b7941647c |
comparison
equal
deleted
inserted
replaced
2107:1bd9978ed5d0 | 2108:adfd962e1343 |
---|---|
6 #include "xmpp.h" | 6 #include "xmpp.h" |
7 | 7 |
8 static int _carbons_available = 0; | 8 static int _carbons_available = 0; |
9 static int _carbons_enabled = 0; | 9 static int _carbons_enabled = 0; |
10 | 10 |
11 static LmHandlerResult cb_carbons_enable(LmMessageHandler *h, LmConnection *c, | 11 static LmHandlerResult cb_carbons(LmMessageHandler *h, LmConnection *c, |
12 LmMessage *m, gpointer user_data); | 12 LmMessage *m, gpointer user_data); |
13 | 13 |
14 | 14 |
15 void carbons_init() | 15 void carbons_init() |
16 { | 16 { |
17 | 17 |
29 } | 29 } |
30 } | 30 } |
31 | 31 |
32 void carbons_enable() | 32 void carbons_enable() |
33 { | 33 { |
34 //We cannot enable carbons if there is no carbons support | |
34 if (_carbons_available == 0) { | 35 if (_carbons_available == 0) { |
36 scr_LogPrint(LPRINT_NORMAL, "Carbons not available on this server!"); | |
37 return; | |
38 } | |
39 | |
40 //We only have to enable carbons once | |
41 if (_carbons_enabled == 1) { | |
35 return; | 42 return; |
36 } | 43 } |
37 | 44 |
38 LmMessage *iq; | 45 LmMessage *iq; |
39 LmMessageNode *enable; | 46 LmMessageNode *enable; |
42 | 49 |
43 iq = lm_message_new_with_sub_type(NULL, LM_MESSAGE_TYPE_IQ, | 50 iq = lm_message_new_with_sub_type(NULL, LM_MESSAGE_TYPE_IQ, |
44 LM_MESSAGE_SUB_TYPE_SET); | 51 LM_MESSAGE_SUB_TYPE_SET); |
45 | 52 |
46 enable = lm_message_node_add_child(iq->node, "enable", NULL); | 53 enable = lm_message_node_add_child(iq->node, "enable", NULL); |
47 | |
48 lm_message_node_set_attribute(enable, "xmlns", NS_CARBONS_2); | 54 lm_message_node_set_attribute(enable, "xmlns", NS_CARBONS_2); |
49 | 55 handler = lm_message_handler_new(cb_carbons, NULL, NULL); |
50 handler = lm_message_handler_new(cb_carbons_enable, NULL, NULL); | |
51 | 56 |
52 if (!lm_connection_send_with_reply(lconnection, iq, handler, &error)) { | 57 if (!lm_connection_send_with_reply(lconnection, iq, handler, &error)) { |
53 scr_LogPrint(LPRINT_DEBUG, "Error sending IQ request: %s.", error->message); | 58 scr_LogPrint(LPRINT_DEBUG, "Error sending IQ request: %s.", error->message); |
54 g_error_free(error); | 59 g_error_free(error); |
55 } | 60 } |
58 lm_message_unref(iq); | 63 lm_message_unref(iq); |
59 } | 64 } |
60 | 65 |
61 void carbons_disable() | 66 void carbons_disable() |
62 { | 67 { |
68 //We cannot disable carbons if there is no carbon support on the server | |
63 if (_carbons_available == 0) { | 69 if (_carbons_available == 0) { |
70 scr_LogPrint(LPRINT_NORMAL, "Carbons not available on this server!"); | |
64 return; | 71 return; |
65 } | 72 } |
73 | |
74 //We can only disable carbons if they are disabled | |
75 if (_carbons_enabled == 0) { | |
76 return; | |
77 } | |
78 | |
79 LmMessage *iq; | |
80 LmMessageNode *disable; | |
81 LmMessageHandler *handler; | |
82 GError *error = NULL; | |
83 | |
84 iq = lm_message_new_with_sub_type(NULL, LM_MESSAGE_TYPE_IQ, | |
85 LM_MESSAGE_SUB_TYPE_SET); | |
86 | |
87 disable = lm_message_node_add_child(iq->node, "disable", NULL); | |
88 lm_message_node_set_attribute(disable, "xmlns", NS_CARBONS_2); | |
89 handler = lm_message_handler_new(cb_carbons, NULL, NULL); | |
90 | |
91 if (!lm_connection_send_with_reply(lconnection, iq, handler, &error)) { | |
92 scr_LogPrint(LPRINT_DEBUG, "Error sending IQ request: %s.", error->message); | |
93 g_error_free(error); | |
94 } | |
95 | |
96 lm_message_handler_unref(handler); | |
97 lm_message_unref(iq); | |
98 | |
66 } | 99 } |
67 | 100 |
68 void carbons_info() | 101 void carbons_info() |
69 { | 102 { |
70 if (_carbons_enabled) { | 103 if (_carbons_enabled) { |
76 scr_LogPrint(LPRINT_NORMAL, "Carbons not available."); | 109 scr_LogPrint(LPRINT_NORMAL, "Carbons not available."); |
77 } | 110 } |
78 } | 111 } |
79 } | 112 } |
80 | 113 |
81 static LmHandlerResult cb_carbons_enable(LmMessageHandler *h, LmConnection *c, | 114 static LmHandlerResult cb_carbons(LmMessageHandler *h, LmConnection *c, |
82 LmMessage *m, gpointer user_data) | 115 LmMessage *m, gpointer user_data) |
83 { | 116 { |
84 if (lm_message_get_sub_type(m) == LM_MESSAGE_SUB_TYPE_RESULT) { | 117 if (lm_message_get_sub_type(m) == LM_MESSAGE_SUB_TYPE_RESULT) { |
85 _carbons_enabled = _carbons_enabled == 0 ? 1 : 0; | 118 _carbons_enabled = _carbons_enabled == 0 ? 1 : 0; |
86 } else { | 119 } else { |
87 //Handle error cases | 120 //Handle error cases |