Mercurial > ~mikael > mcabber > hg
comparison mcabber/mcabber/carbons.c @ 2106:72876dcf9094
Bit more checks for enabling carbons
-Make sure we do not enable carbons if they are already enabled
-Return status of carbons
author | Roeland Jago Douma <roeland@famdouma.nl> |
---|---|
date | Tue, 15 Oct 2013 18:51:39 +0200 |
parents | 1cc84780eb5f |
children | adfd962e1343 |
comparison
equal
deleted
inserted
replaced
2105:1cc84780eb5f | 2106:72876dcf9094 |
---|---|
4 #include "xmpp_defines.h" | 4 #include "xmpp_defines.h" |
5 #include "logprint.h" | 5 #include "logprint.h" |
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 | 10 |
10 static LmHandlerResult cb_carbons_enable(LmMessageHandler *h, LmConnection *c, | 11 static LmHandlerResult cb_carbons_enable(LmMessageHandler *h, LmConnection *c, |
11 LmMessage *m, gpointer user_data); | 12 LmMessage *m, gpointer user_data); |
12 | 13 |
13 | 14 |
28 } | 29 } |
29 } | 30 } |
30 | 31 |
31 void carbons_enable() | 32 void carbons_enable() |
32 { | 33 { |
34 if (_carbons_available == 0) { | |
35 return; | |
36 } | |
37 | |
33 LmMessage *iq; | 38 LmMessage *iq; |
34 LmMessageNode *enable; | 39 LmMessageNode *enable; |
35 LmMessageHandler *handler; | 40 LmMessageHandler *handler; |
36 GError *error = NULL; | 41 GError *error = NULL; |
37 | 42 |
42 | 47 |
43 lm_message_node_set_attribute(enable, "xmlns", NS_CARBONS_2); | 48 lm_message_node_set_attribute(enable, "xmlns", NS_CARBONS_2); |
44 | 49 |
45 handler = lm_message_handler_new(cb_carbons_enable, NULL, NULL); | 50 handler = lm_message_handler_new(cb_carbons_enable, NULL, NULL); |
46 | 51 |
47 lm_connection_send_with_reply(lconnection, iq, handler, &error); | 52 if (!lm_connection_send_with_reply(lconnection, iq, handler, &error)) { |
53 scr_LogPrint(LPRINT_DEBUG, "Error sending IQ request: %s.", error->message); | |
54 g_error_free(error); | |
55 } | |
56 | |
48 lm_message_handler_unref(handler); | 57 lm_message_handler_unref(handler); |
49 lm_message_unref(iq); | 58 lm_message_unref(iq); |
50 | |
51 if (error) { | |
52 scr_LogPrint(LPRINT_LOGNORM, "Error sending IQ request: %s.", error->message); | |
53 g_error_free(error); | |
54 } | |
55 } | 59 } |
56 | 60 |
57 void carbons_disable() | 61 void carbons_disable() |
58 { | 62 { |
63 if (_carbons_available == 0) { | |
64 return; | |
65 } | |
66 } | |
59 | 67 |
68 void carbons_info() | |
69 { | |
70 if (_carbons_enabled) { | |
71 scr_LogPrint(LPRINT_NORMAL, "Carbons enabled."); | |
72 } else { | |
73 if (_carbons_available) { | |
74 scr_LogPrint(LPRINT_NORMAL, "Carbons available, but not enabled."); | |
75 } else { | |
76 scr_LogPrint(LPRINT_NORMAL, "Carbons not available."); | |
77 } | |
78 } | |
60 } | 79 } |
61 | 80 |
62 static LmHandlerResult cb_carbons_enable(LmMessageHandler *h, LmConnection *c, | 81 static LmHandlerResult cb_carbons_enable(LmMessageHandler *h, LmConnection *c, |
63 LmMessage *m, gpointer user_data) | 82 LmMessage *m, gpointer user_data) |
64 { | 83 { |
84 if (lm_message_get_sub_type(m) == LM_MESSAGE_SUB_TYPE_RESULT) { | |
85 _carbons_enabled = _carbons_enabled == 0 ? 1 : 0; | |
86 } else { | |
87 //Handle error cases | |
88 } | |
89 | |
65 return LM_HANDLER_RESULT_REMOVE_MESSAGE; | 90 return LM_HANDLER_RESULT_REMOVE_MESSAGE; |
66 } | 91 } |
92 |