Mercurial > ~mikael > mcabber > hg
annotate mcabber/mcabber/carbons.c @ 2125:fef71336e429
shorten 'status change' message in MUC
author | sh!zeeg <shizeeque@gmail.com> |
---|---|
date | Wed, 14 May 2014 14:20:44 +0400 |
parents | 9023a6f2bf6c |
children | 51fde9c25401 |
rev | line source |
---|---|
2111 | 1 /* |
2 * carbons.c -- Support for Message Carbons (XEP 0280) | |
3 * | |
4 * Copyright (C) 2013 Roeland Jago Douma <roeland@famdouma.nl> | |
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 | |
2104
c7e9950fa741
Added option to enable carbons (set carbons = 1 in mcabberrc)
Roeland Jago Douma <roeland@famdouma.nl>
parents:
diff
changeset
|
22 #include "carbons.h" |
c7e9950fa741
Added option to enable carbons (set carbons = 1 in mcabberrc)
Roeland Jago Douma <roeland@famdouma.nl>
parents:
diff
changeset
|
23 #include "settings.h" |
c7e9950fa741
Added option to enable carbons (set carbons = 1 in mcabberrc)
Roeland Jago Douma <roeland@famdouma.nl>
parents:
diff
changeset
|
24 #include "xmpp_helper.h" |
c7e9950fa741
Added option to enable carbons (set carbons = 1 in mcabberrc)
Roeland Jago Douma <roeland@famdouma.nl>
parents:
diff
changeset
|
25 #include "xmpp_defines.h" |
c7e9950fa741
Added option to enable carbons (set carbons = 1 in mcabberrc)
Roeland Jago Douma <roeland@famdouma.nl>
parents:
diff
changeset
|
26 #include "logprint.h" |
c7e9950fa741
Added option to enable carbons (set carbons = 1 in mcabberrc)
Roeland Jago Douma <roeland@famdouma.nl>
parents:
diff
changeset
|
27 #include "xmpp.h" |
c7e9950fa741
Added option to enable carbons (set carbons = 1 in mcabberrc)
Roeland Jago Douma <roeland@famdouma.nl>
parents:
diff
changeset
|
28 |
c7e9950fa741
Added option to enable carbons (set carbons = 1 in mcabberrc)
Roeland Jago Douma <roeland@famdouma.nl>
parents:
diff
changeset
|
29 static int _carbons_available = 0; |
2106
72876dcf9094
Bit more checks for enabling carbons
Roeland Jago Douma <roeland@famdouma.nl>
parents:
2105
diff
changeset
|
30 static int _carbons_enabled = 0; |
2104
c7e9950fa741
Added option to enable carbons (set carbons = 1 in mcabberrc)
Roeland Jago Douma <roeland@famdouma.nl>
parents:
diff
changeset
|
31 |
2108
adfd962e1343
Allow the user to enable/disable carbons from the command line
Roeland Jago Douma <roeland@famdouma.nl>
parents:
2106
diff
changeset
|
32 static LmHandlerResult cb_carbons(LmMessageHandler *h, LmConnection *c, |
adfd962e1343
Allow the user to enable/disable carbons from the command line
Roeland Jago Douma <roeland@famdouma.nl>
parents:
2106
diff
changeset
|
33 LmMessage *m, gpointer user_data); |
2104
c7e9950fa741
Added option to enable carbons (set carbons = 1 in mcabberrc)
Roeland Jago Douma <roeland@famdouma.nl>
parents:
diff
changeset
|
34 |
c7e9950fa741
Added option to enable carbons (set carbons = 1 in mcabberrc)
Roeland Jago Douma <roeland@famdouma.nl>
parents:
diff
changeset
|
35 |
c7e9950fa741
Added option to enable carbons (set carbons = 1 in mcabberrc)
Roeland Jago Douma <roeland@famdouma.nl>
parents:
diff
changeset
|
36 void carbons_available() |
c7e9950fa741
Added option to enable carbons (set carbons = 1 in mcabberrc)
Roeland Jago Douma <roeland@famdouma.nl>
parents:
diff
changeset
|
37 { |
c7e9950fa741
Added option to enable carbons (set carbons = 1 in mcabberrc)
Roeland Jago Douma <roeland@famdouma.nl>
parents:
diff
changeset
|
38 int enable = 0; |
c7e9950fa741
Added option to enable carbons (set carbons = 1 in mcabberrc)
Roeland Jago Douma <roeland@famdouma.nl>
parents:
diff
changeset
|
39 _carbons_available = 1; |
c7e9950fa741
Added option to enable carbons (set carbons = 1 in mcabberrc)
Roeland Jago Douma <roeland@famdouma.nl>
parents:
diff
changeset
|
40 |
c7e9950fa741
Added option to enable carbons (set carbons = 1 in mcabberrc)
Roeland Jago Douma <roeland@famdouma.nl>
parents:
diff
changeset
|
41 enable = settings_opt_get_int("carbons"); |
c7e9950fa741
Added option to enable carbons (set carbons = 1 in mcabberrc)
Roeland Jago Douma <roeland@famdouma.nl>
parents:
diff
changeset
|
42 |
c7e9950fa741
Added option to enable carbons (set carbons = 1 in mcabberrc)
Roeland Jago Douma <roeland@famdouma.nl>
parents:
diff
changeset
|
43 if (enable) { |
c7e9950fa741
Added option to enable carbons (set carbons = 1 in mcabberrc)
Roeland Jago Douma <roeland@famdouma.nl>
parents:
diff
changeset
|
44 carbons_enable(); |
c7e9950fa741
Added option to enable carbons (set carbons = 1 in mcabberrc)
Roeland Jago Douma <roeland@famdouma.nl>
parents:
diff
changeset
|
45 } |
c7e9950fa741
Added option to enable carbons (set carbons = 1 in mcabberrc)
Roeland Jago Douma <roeland@famdouma.nl>
parents:
diff
changeset
|
46 } |
c7e9950fa741
Added option to enable carbons (set carbons = 1 in mcabberrc)
Roeland Jago Douma <roeland@famdouma.nl>
parents:
diff
changeset
|
47 |
c7e9950fa741
Added option to enable carbons (set carbons = 1 in mcabberrc)
Roeland Jago Douma <roeland@famdouma.nl>
parents:
diff
changeset
|
48 void carbons_enable() |
c7e9950fa741
Added option to enable carbons (set carbons = 1 in mcabberrc)
Roeland Jago Douma <roeland@famdouma.nl>
parents:
diff
changeset
|
49 { |
2111 | 50 LmMessage *iq; |
51 LmMessageNode *enable; | |
52 LmMessageHandler *handler; | |
53 GError *error = NULL; | |
54 | |
2108
adfd962e1343
Allow the user to enable/disable carbons from the command line
Roeland Jago Douma <roeland@famdouma.nl>
parents:
2106
diff
changeset
|
55 //We cannot enable carbons if there is no carbons support |
2106
72876dcf9094
Bit more checks for enabling carbons
Roeland Jago Douma <roeland@famdouma.nl>
parents:
2105
diff
changeset
|
56 if (_carbons_available == 0) { |
2111 | 57 scr_log_print(LPRINT_NORMAL, "Carbons not available on this server!"); |
2108
adfd962e1343
Allow the user to enable/disable carbons from the command line
Roeland Jago Douma <roeland@famdouma.nl>
parents:
2106
diff
changeset
|
58 return; |
adfd962e1343
Allow the user to enable/disable carbons from the command line
Roeland Jago Douma <roeland@famdouma.nl>
parents:
2106
diff
changeset
|
59 } |
adfd962e1343
Allow the user to enable/disable carbons from the command line
Roeland Jago Douma <roeland@famdouma.nl>
parents:
2106
diff
changeset
|
60 |
adfd962e1343
Allow the user to enable/disable carbons from the command line
Roeland Jago Douma <roeland@famdouma.nl>
parents:
2106
diff
changeset
|
61 //We only have to enable carbons once |
adfd962e1343
Allow the user to enable/disable carbons from the command line
Roeland Jago Douma <roeland@famdouma.nl>
parents:
2106
diff
changeset
|
62 if (_carbons_enabled == 1) { |
2106
72876dcf9094
Bit more checks for enabling carbons
Roeland Jago Douma <roeland@famdouma.nl>
parents:
2105
diff
changeset
|
63 return; |
72876dcf9094
Bit more checks for enabling carbons
Roeland Jago Douma <roeland@famdouma.nl>
parents:
2105
diff
changeset
|
64 } |
72876dcf9094
Bit more checks for enabling carbons
Roeland Jago Douma <roeland@famdouma.nl>
parents:
2105
diff
changeset
|
65 |
2104
c7e9950fa741
Added option to enable carbons (set carbons = 1 in mcabberrc)
Roeland Jago Douma <roeland@famdouma.nl>
parents:
diff
changeset
|
66 iq = lm_message_new_with_sub_type(NULL, LM_MESSAGE_TYPE_IQ, |
c7e9950fa741
Added option to enable carbons (set carbons = 1 in mcabberrc)
Roeland Jago Douma <roeland@famdouma.nl>
parents:
diff
changeset
|
67 LM_MESSAGE_SUB_TYPE_SET); |
c7e9950fa741
Added option to enable carbons (set carbons = 1 in mcabberrc)
Roeland Jago Douma <roeland@famdouma.nl>
parents:
diff
changeset
|
68 |
c7e9950fa741
Added option to enable carbons (set carbons = 1 in mcabberrc)
Roeland Jago Douma <roeland@famdouma.nl>
parents:
diff
changeset
|
69 enable = lm_message_node_add_child(iq->node, "enable", NULL); |
c7e9950fa741
Added option to enable carbons (set carbons = 1 in mcabberrc)
Roeland Jago Douma <roeland@famdouma.nl>
parents:
diff
changeset
|
70 lm_message_node_set_attribute(enable, "xmlns", NS_CARBONS_2); |
2108
adfd962e1343
Allow the user to enable/disable carbons from the command line
Roeland Jago Douma <roeland@famdouma.nl>
parents:
2106
diff
changeset
|
71 handler = lm_message_handler_new(cb_carbons, NULL, NULL); |
2104
c7e9950fa741
Added option to enable carbons (set carbons = 1 in mcabberrc)
Roeland Jago Douma <roeland@famdouma.nl>
parents:
diff
changeset
|
72 |
2106
72876dcf9094
Bit more checks for enabling carbons
Roeland Jago Douma <roeland@famdouma.nl>
parents:
2105
diff
changeset
|
73 if (!lm_connection_send_with_reply(lconnection, iq, handler, &error)) { |
2111 | 74 scr_log_print(LPRINT_DEBUG, "Error sending IQ request: %s.", |
75 error->message); | |
2106
72876dcf9094
Bit more checks for enabling carbons
Roeland Jago Douma <roeland@famdouma.nl>
parents:
2105
diff
changeset
|
76 g_error_free(error); |
72876dcf9094
Bit more checks for enabling carbons
Roeland Jago Douma <roeland@famdouma.nl>
parents:
2105
diff
changeset
|
77 } |
72876dcf9094
Bit more checks for enabling carbons
Roeland Jago Douma <roeland@famdouma.nl>
parents:
2105
diff
changeset
|
78 |
2104
c7e9950fa741
Added option to enable carbons (set carbons = 1 in mcabberrc)
Roeland Jago Douma <roeland@famdouma.nl>
parents:
diff
changeset
|
79 lm_message_handler_unref(handler); |
c7e9950fa741
Added option to enable carbons (set carbons = 1 in mcabberrc)
Roeland Jago Douma <roeland@famdouma.nl>
parents:
diff
changeset
|
80 lm_message_unref(iq); |
c7e9950fa741
Added option to enable carbons (set carbons = 1 in mcabberrc)
Roeland Jago Douma <roeland@famdouma.nl>
parents:
diff
changeset
|
81 } |
c7e9950fa741
Added option to enable carbons (set carbons = 1 in mcabberrc)
Roeland Jago Douma <roeland@famdouma.nl>
parents:
diff
changeset
|
82 |
c7e9950fa741
Added option to enable carbons (set carbons = 1 in mcabberrc)
Roeland Jago Douma <roeland@famdouma.nl>
parents:
diff
changeset
|
83 void carbons_disable() |
c7e9950fa741
Added option to enable carbons (set carbons = 1 in mcabberrc)
Roeland Jago Douma <roeland@famdouma.nl>
parents:
diff
changeset
|
84 { |
2111 | 85 LmMessage *iq; |
86 LmMessageNode *disable; | |
87 LmMessageHandler *handler; | |
88 GError *error = NULL; | |
89 | |
2108
adfd962e1343
Allow the user to enable/disable carbons from the command line
Roeland Jago Douma <roeland@famdouma.nl>
parents:
2106
diff
changeset
|
90 //We cannot disable carbons if there is no carbon support on the server |
2106
72876dcf9094
Bit more checks for enabling carbons
Roeland Jago Douma <roeland@famdouma.nl>
parents:
2105
diff
changeset
|
91 if (_carbons_available == 0) { |
2111 | 92 scr_log_print(LPRINT_NORMAL, "Carbons not available on this server!"); |
2106
72876dcf9094
Bit more checks for enabling carbons
Roeland Jago Douma <roeland@famdouma.nl>
parents:
2105
diff
changeset
|
93 return; |
72876dcf9094
Bit more checks for enabling carbons
Roeland Jago Douma <roeland@famdouma.nl>
parents:
2105
diff
changeset
|
94 } |
2108
adfd962e1343
Allow the user to enable/disable carbons from the command line
Roeland Jago Douma <roeland@famdouma.nl>
parents:
2106
diff
changeset
|
95 |
adfd962e1343
Allow the user to enable/disable carbons from the command line
Roeland Jago Douma <roeland@famdouma.nl>
parents:
2106
diff
changeset
|
96 //We can only disable carbons if they are disabled |
adfd962e1343
Allow the user to enable/disable carbons from the command line
Roeland Jago Douma <roeland@famdouma.nl>
parents:
2106
diff
changeset
|
97 if (_carbons_enabled == 0) { |
adfd962e1343
Allow the user to enable/disable carbons from the command line
Roeland Jago Douma <roeland@famdouma.nl>
parents:
2106
diff
changeset
|
98 return; |
2111 | 99 } |
2108
adfd962e1343
Allow the user to enable/disable carbons from the command line
Roeland Jago Douma <roeland@famdouma.nl>
parents:
2106
diff
changeset
|
100 |
adfd962e1343
Allow the user to enable/disable carbons from the command line
Roeland Jago Douma <roeland@famdouma.nl>
parents:
2106
diff
changeset
|
101 iq = lm_message_new_with_sub_type(NULL, LM_MESSAGE_TYPE_IQ, |
adfd962e1343
Allow the user to enable/disable carbons from the command line
Roeland Jago Douma <roeland@famdouma.nl>
parents:
2106
diff
changeset
|
102 LM_MESSAGE_SUB_TYPE_SET); |
adfd962e1343
Allow the user to enable/disable carbons from the command line
Roeland Jago Douma <roeland@famdouma.nl>
parents:
2106
diff
changeset
|
103 |
adfd962e1343
Allow the user to enable/disable carbons from the command line
Roeland Jago Douma <roeland@famdouma.nl>
parents:
2106
diff
changeset
|
104 disable = lm_message_node_add_child(iq->node, "disable", NULL); |
adfd962e1343
Allow the user to enable/disable carbons from the command line
Roeland Jago Douma <roeland@famdouma.nl>
parents:
2106
diff
changeset
|
105 lm_message_node_set_attribute(disable, "xmlns", NS_CARBONS_2); |
adfd962e1343
Allow the user to enable/disable carbons from the command line
Roeland Jago Douma <roeland@famdouma.nl>
parents:
2106
diff
changeset
|
106 handler = lm_message_handler_new(cb_carbons, NULL, NULL); |
adfd962e1343
Allow the user to enable/disable carbons from the command line
Roeland Jago Douma <roeland@famdouma.nl>
parents:
2106
diff
changeset
|
107 |
adfd962e1343
Allow the user to enable/disable carbons from the command line
Roeland Jago Douma <roeland@famdouma.nl>
parents:
2106
diff
changeset
|
108 if (!lm_connection_send_with_reply(lconnection, iq, handler, &error)) { |
2111 | 109 scr_log_print(LPRINT_DEBUG, "Error sending IQ request: %s.", |
110 error->message); | |
2108
adfd962e1343
Allow the user to enable/disable carbons from the command line
Roeland Jago Douma <roeland@famdouma.nl>
parents:
2106
diff
changeset
|
111 g_error_free(error); |
adfd962e1343
Allow the user to enable/disable carbons from the command line
Roeland Jago Douma <roeland@famdouma.nl>
parents:
2106
diff
changeset
|
112 } |
adfd962e1343
Allow the user to enable/disable carbons from the command line
Roeland Jago Douma <roeland@famdouma.nl>
parents:
2106
diff
changeset
|
113 |
adfd962e1343
Allow the user to enable/disable carbons from the command line
Roeland Jago Douma <roeland@famdouma.nl>
parents:
2106
diff
changeset
|
114 lm_message_handler_unref(handler); |
adfd962e1343
Allow the user to enable/disable carbons from the command line
Roeland Jago Douma <roeland@famdouma.nl>
parents:
2106
diff
changeset
|
115 lm_message_unref(iq); |
2111 | 116 |
2106
72876dcf9094
Bit more checks for enabling carbons
Roeland Jago Douma <roeland@famdouma.nl>
parents:
2105
diff
changeset
|
117 } |
2104
c7e9950fa741
Added option to enable carbons (set carbons = 1 in mcabberrc)
Roeland Jago Douma <roeland@famdouma.nl>
parents:
diff
changeset
|
118 |
2106
72876dcf9094
Bit more checks for enabling carbons
Roeland Jago Douma <roeland@famdouma.nl>
parents:
2105
diff
changeset
|
119 void carbons_info() |
72876dcf9094
Bit more checks for enabling carbons
Roeland Jago Douma <roeland@famdouma.nl>
parents:
2105
diff
changeset
|
120 { |
72876dcf9094
Bit more checks for enabling carbons
Roeland Jago Douma <roeland@famdouma.nl>
parents:
2105
diff
changeset
|
121 if (_carbons_enabled) { |
2111 | 122 scr_log_print(LPRINT_NORMAL, "Carbons enabled."); |
2106
72876dcf9094
Bit more checks for enabling carbons
Roeland Jago Douma <roeland@famdouma.nl>
parents:
2105
diff
changeset
|
123 } else { |
72876dcf9094
Bit more checks for enabling carbons
Roeland Jago Douma <roeland@famdouma.nl>
parents:
2105
diff
changeset
|
124 if (_carbons_available) { |
2111 | 125 scr_log_print(LPRINT_NORMAL, "Carbons available, but not enabled."); |
2106
72876dcf9094
Bit more checks for enabling carbons
Roeland Jago Douma <roeland@famdouma.nl>
parents:
2105
diff
changeset
|
126 } else { |
2111 | 127 scr_log_print(LPRINT_NORMAL, "Carbons not available."); |
2106
72876dcf9094
Bit more checks for enabling carbons
Roeland Jago Douma <roeland@famdouma.nl>
parents:
2105
diff
changeset
|
128 } |
72876dcf9094
Bit more checks for enabling carbons
Roeland Jago Douma <roeland@famdouma.nl>
parents:
2105
diff
changeset
|
129 } |
2104
c7e9950fa741
Added option to enable carbons (set carbons = 1 in mcabberrc)
Roeland Jago Douma <roeland@famdouma.nl>
parents:
diff
changeset
|
130 } |
c7e9950fa741
Added option to enable carbons (set carbons = 1 in mcabberrc)
Roeland Jago Douma <roeland@famdouma.nl>
parents:
diff
changeset
|
131 |
2108
adfd962e1343
Allow the user to enable/disable carbons from the command line
Roeland Jago Douma <roeland@famdouma.nl>
parents:
2106
diff
changeset
|
132 static LmHandlerResult cb_carbons(LmMessageHandler *h, LmConnection *c, |
adfd962e1343
Allow the user to enable/disable carbons from the command line
Roeland Jago Douma <roeland@famdouma.nl>
parents:
2106
diff
changeset
|
133 LmMessage *m, gpointer user_data) |
2104
c7e9950fa741
Added option to enable carbons (set carbons = 1 in mcabberrc)
Roeland Jago Douma <roeland@famdouma.nl>
parents:
diff
changeset
|
134 { |
2106
72876dcf9094
Bit more checks for enabling carbons
Roeland Jago Douma <roeland@famdouma.nl>
parents:
2105
diff
changeset
|
135 if (lm_message_get_sub_type(m) == LM_MESSAGE_SUB_TYPE_RESULT) { |
2111 | 136 _carbons_enabled = (_carbons_enabled == 0 ? 1 : 0); |
137 if (_carbons_enabled) { | |
138 scr_log_print(LPRINT_NORMAL, "Carbons enabled."); | |
139 } else { | |
140 scr_log_print(LPRINT_NORMAL, "Carbons disabled."); | |
141 } | |
2106
72876dcf9094
Bit more checks for enabling carbons
Roeland Jago Douma <roeland@famdouma.nl>
parents:
2105
diff
changeset
|
142 } else { |
72876dcf9094
Bit more checks for enabling carbons
Roeland Jago Douma <roeland@famdouma.nl>
parents:
2105
diff
changeset
|
143 //Handle error cases |
72876dcf9094
Bit more checks for enabling carbons
Roeland Jago Douma <roeland@famdouma.nl>
parents:
2105
diff
changeset
|
144 } |
72876dcf9094
Bit more checks for enabling carbons
Roeland Jago Douma <roeland@famdouma.nl>
parents:
2105
diff
changeset
|
145 |
2104
c7e9950fa741
Added option to enable carbons (set carbons = 1 in mcabberrc)
Roeland Jago Douma <roeland@famdouma.nl>
parents:
diff
changeset
|
146 return LM_HANDLER_RESULT_REMOVE_MESSAGE; |
c7e9950fa741
Added option to enable carbons (set carbons = 1 in mcabberrc)
Roeland Jago Douma <roeland@famdouma.nl>
parents:
diff
changeset
|
147 } |
2106
72876dcf9094
Bit more checks for enabling carbons
Roeland Jago Douma <roeland@famdouma.nl>
parents:
2105
diff
changeset
|
148 |
2111 | 149 /* vim: set et cindent cinoptions=>2\:2(0 ts=2 sw=2: For Vim users... */ |