comparison mcabber/mcabber/carbons.c @ 2111:9023a6f2bf6c

Misc. style updates
author Mikael Berthe <mikael@lilotux.net>
date Sun, 11 May 2014 17:18:18 +0200
parents 9b4b7941647c
children 51fde9c25401
comparison
equal deleted inserted replaced
2110:9b4b7941647c 2111:9023a6f2bf6c
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
1 #include "carbons.h" 22 #include "carbons.h"
2 #include "settings.h" 23 #include "settings.h"
3 #include "xmpp_helper.h" 24 #include "xmpp_helper.h"
4 #include "xmpp_defines.h" 25 #include "xmpp_defines.h"
5 #include "logprint.h" 26 #include "logprint.h"
24 } 45 }
25 } 46 }
26 47
27 void carbons_enable() 48 void carbons_enable()
28 { 49 {
50 LmMessage *iq;
51 LmMessageNode *enable;
52 LmMessageHandler *handler;
53 GError *error = NULL;
54
29 //We cannot enable carbons if there is no carbons support 55 //We cannot enable carbons if there is no carbons support
30 if (_carbons_available == 0) { 56 if (_carbons_available == 0) {
31 scr_LogPrint(LPRINT_NORMAL, "Carbons not available on this server!"); 57 scr_log_print(LPRINT_NORMAL, "Carbons not available on this server!");
32 return; 58 return;
33 } 59 }
34 60
35 //We only have to enable carbons once 61 //We only have to enable carbons once
36 if (_carbons_enabled == 1) { 62 if (_carbons_enabled == 1) {
37 return; 63 return;
38 } 64 }
39
40 LmMessage *iq;
41 LmMessageNode *enable;
42 LmMessageHandler *handler;
43 GError *error = NULL;
44 65
45 iq = lm_message_new_with_sub_type(NULL, LM_MESSAGE_TYPE_IQ, 66 iq = lm_message_new_with_sub_type(NULL, LM_MESSAGE_TYPE_IQ,
46 LM_MESSAGE_SUB_TYPE_SET); 67 LM_MESSAGE_SUB_TYPE_SET);
47 68
48 enable = lm_message_node_add_child(iq->node, "enable", NULL); 69 enable = lm_message_node_add_child(iq->node, "enable", NULL);
49 lm_message_node_set_attribute(enable, "xmlns", NS_CARBONS_2); 70 lm_message_node_set_attribute(enable, "xmlns", NS_CARBONS_2);
50 handler = lm_message_handler_new(cb_carbons, NULL, NULL); 71 handler = lm_message_handler_new(cb_carbons, NULL, NULL);
51 72
52 if (!lm_connection_send_with_reply(lconnection, iq, handler, &error)) { 73 if (!lm_connection_send_with_reply(lconnection, iq, handler, &error)) {
53 scr_LogPrint(LPRINT_DEBUG, "Error sending IQ request: %s.", error->message); 74 scr_log_print(LPRINT_DEBUG, "Error sending IQ request: %s.",
75 error->message);
54 g_error_free(error); 76 g_error_free(error);
55 } 77 }
56 78
57 lm_message_handler_unref(handler); 79 lm_message_handler_unref(handler);
58 lm_message_unref(iq); 80 lm_message_unref(iq);
59 } 81 }
60 82
61 void carbons_disable() 83 void carbons_disable()
62 { 84 {
85 LmMessage *iq;
86 LmMessageNode *disable;
87 LmMessageHandler *handler;
88 GError *error = NULL;
89
63 //We cannot disable carbons if there is no carbon support on the server 90 //We cannot disable carbons if there is no carbon support on the server
64 if (_carbons_available == 0) { 91 if (_carbons_available == 0) {
65 scr_LogPrint(LPRINT_NORMAL, "Carbons not available on this server!"); 92 scr_log_print(LPRINT_NORMAL, "Carbons not available on this server!");
66 return; 93 return;
67 } 94 }
68 95
69 //We can only disable carbons if they are disabled 96 //We can only disable carbons if they are disabled
70 if (_carbons_enabled == 0) { 97 if (_carbons_enabled == 0) {
71 return; 98 return;
72 } 99 }
73
74 LmMessage *iq;
75 LmMessageNode *disable;
76 LmMessageHandler *handler;
77 GError *error = NULL;
78 100
79 iq = lm_message_new_with_sub_type(NULL, LM_MESSAGE_TYPE_IQ, 101 iq = lm_message_new_with_sub_type(NULL, LM_MESSAGE_TYPE_IQ,
80 LM_MESSAGE_SUB_TYPE_SET); 102 LM_MESSAGE_SUB_TYPE_SET);
81 103
82 disable = lm_message_node_add_child(iq->node, "disable", NULL); 104 disable = lm_message_node_add_child(iq->node, "disable", NULL);
83 lm_message_node_set_attribute(disable, "xmlns", NS_CARBONS_2); 105 lm_message_node_set_attribute(disable, "xmlns", NS_CARBONS_2);
84 handler = lm_message_handler_new(cb_carbons, NULL, NULL); 106 handler = lm_message_handler_new(cb_carbons, NULL, NULL);
85 107
86 if (!lm_connection_send_with_reply(lconnection, iq, handler, &error)) { 108 if (!lm_connection_send_with_reply(lconnection, iq, handler, &error)) {
87 scr_LogPrint(LPRINT_DEBUG, "Error sending IQ request: %s.", error->message); 109 scr_log_print(LPRINT_DEBUG, "Error sending IQ request: %s.",
110 error->message);
88 g_error_free(error); 111 g_error_free(error);
89 } 112 }
90 113
91 lm_message_handler_unref(handler); 114 lm_message_handler_unref(handler);
92 lm_message_unref(iq); 115 lm_message_unref(iq);
93 116
94 } 117 }
95 118
96 void carbons_info() 119 void carbons_info()
97 { 120 {
98 if (_carbons_enabled) { 121 if (_carbons_enabled) {
99 scr_LogPrint(LPRINT_NORMAL, "Carbons enabled."); 122 scr_log_print(LPRINT_NORMAL, "Carbons enabled.");
100 } else { 123 } else {
101 if (_carbons_available) { 124 if (_carbons_available) {
102 scr_LogPrint(LPRINT_NORMAL, "Carbons available, but not enabled."); 125 scr_log_print(LPRINT_NORMAL, "Carbons available, but not enabled.");
103 } else { 126 } else {
104 scr_LogPrint(LPRINT_NORMAL, "Carbons not available."); 127 scr_log_print(LPRINT_NORMAL, "Carbons not available.");
105 } 128 }
106 } 129 }
107 } 130 }
108 131
109 static LmHandlerResult cb_carbons(LmMessageHandler *h, LmConnection *c, 132 static LmHandlerResult cb_carbons(LmMessageHandler *h, LmConnection *c,
110 LmMessage *m, gpointer user_data) 133 LmMessage *m, gpointer user_data)
111 { 134 {
112 if (lm_message_get_sub_type(m) == LM_MESSAGE_SUB_TYPE_RESULT) { 135 if (lm_message_get_sub_type(m) == LM_MESSAGE_SUB_TYPE_RESULT) {
113 _carbons_enabled = _carbons_enabled == 0 ? 1 : 0; 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 }
114 } else { 142 } else {
115 //Handle error cases 143 //Handle error cases
116 } 144 }
117 145
118 return LM_HANDLER_RESULT_REMOVE_MESSAGE; 146 return LM_HANDLER_RESULT_REMOVE_MESSAGE;
119 } 147 }
120 148
149 /* vim: set et cindent cinoptions=>2\:2(0 ts=2 sw=2: For Vim users... */