Mercurial > hg
annotate mcabber/mcabber/xmpp_helper.c @ 1797:246c5d359c97
Add "hook-pre-message-in" hook
author | Mikael Berthe <mikael@lilotux.net> |
---|---|
date | Sat, 20 Mar 2010 14:57:03 +0100 |
parents | e6e89b1d7831 |
children | d2747442918a |
rev | line source |
---|---|
1598 | 1 /* |
1599 | 2 * xmpp_helper.c -- Jabber protocol helper functions |
1598 | 3 * |
1599 | 4 * Copyright (C) 2008-2009 Frank Zschockelt <mcabber@freakysoft.de> |
5 * Copyright (C) 2005-2009 Mikael Berthe <mikael@lilotux.net> | |
1598 | 6 * |
7 * This program is free software; you can redistribute it and/or modify | |
8 * it under the terms of the GNU General Public License as published by | |
9 * the Free Software Foundation; either version 2 of the License, or (at | |
10 * your option) any later version. | |
11 * | |
12 * This program is distributed in the hope that it will be useful, but | |
13 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 * General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU General Public License | |
18 * along with this program; if not, write to the Free Software | |
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 | |
20 * USA | |
21 */ | |
22 | |
1604
351427ef0b4b
Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents:
1602
diff
changeset
|
23 #include <string.h> |
351427ef0b4b
Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents:
1602
diff
changeset
|
24 #include <stdlib.h> |
351427ef0b4b
Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents:
1602
diff
changeset
|
25 |
1598 | 26 #include "xmpp_helper.h" |
1604
351427ef0b4b
Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents:
1602
diff
changeset
|
27 #include "settings.h" |
351427ef0b4b
Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents:
1602
diff
changeset
|
28 #include "utils.h" |
351427ef0b4b
Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents:
1602
diff
changeset
|
29 #include "caps.h" |
351427ef0b4b
Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents:
1602
diff
changeset
|
30 #include "logprint.h" |
1607 | 31 #include "config.h" |
1598 | 32 |
33 time_t iqlast; // last message/status change time | |
34 | |
1604
351427ef0b4b
Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents:
1602
diff
changeset
|
35 extern char *imstatus_showmap[]; |
351427ef0b4b
Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents:
1602
diff
changeset
|
36 |
351427ef0b4b
Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents:
1602
diff
changeset
|
37 struct xmpp_error xmpp_errors[] = { |
351427ef0b4b
Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents:
1602
diff
changeset
|
38 {XMPP_ERROR_REDIRECT, "302", |
351427ef0b4b
Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents:
1602
diff
changeset
|
39 "Redirect", "redirect", "modify"}, |
351427ef0b4b
Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents:
1602
diff
changeset
|
40 {XMPP_ERROR_BAD_REQUEST, "400", |
351427ef0b4b
Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents:
1602
diff
changeset
|
41 "Bad Request", "bad-request", "modify"}, |
351427ef0b4b
Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents:
1602
diff
changeset
|
42 {XMPP_ERROR_NOT_AUTHORIZED, "401", |
351427ef0b4b
Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents:
1602
diff
changeset
|
43 "Not Authorized", "not-authorized", "auth"}, |
351427ef0b4b
Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents:
1602
diff
changeset
|
44 {XMPP_ERROR_PAYMENT_REQUIRED, "402", |
351427ef0b4b
Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents:
1602
diff
changeset
|
45 "Payment Required", "payment-required", "auth"}, |
351427ef0b4b
Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents:
1602
diff
changeset
|
46 {XMPP_ERROR_FORBIDDEN, "403", |
351427ef0b4b
Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents:
1602
diff
changeset
|
47 "Forbidden", "forbidden", "auth"}, |
351427ef0b4b
Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents:
1602
diff
changeset
|
48 {XMPP_ERROR_NOT_FOUND, "404", |
351427ef0b4b
Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents:
1602
diff
changeset
|
49 "Not Found", "item-not-found", "cancel"}, |
351427ef0b4b
Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents:
1602
diff
changeset
|
50 {XMPP_ERROR_NOT_ALLOWED, "405", |
351427ef0b4b
Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents:
1602
diff
changeset
|
51 "Not Allowed", "not-allowed", "cancel"}, |
351427ef0b4b
Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents:
1602
diff
changeset
|
52 {XMPP_ERROR_NOT_ACCEPTABLE, "406", |
351427ef0b4b
Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents:
1602
diff
changeset
|
53 "Not Acceptable", "not-acceptable", "modify"}, |
351427ef0b4b
Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents:
1602
diff
changeset
|
54 {XMPP_ERROR_REGISTRATION_REQUIRED, "407", |
351427ef0b4b
Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents:
1602
diff
changeset
|
55 "Registration required", "registration-required", "auth"}, |
351427ef0b4b
Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents:
1602
diff
changeset
|
56 {XMPP_ERROR_REQUEST_TIMEOUT, "408", |
351427ef0b4b
Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents:
1602
diff
changeset
|
57 "Request Timeout", "remote-server-timeout", "wait"}, |
351427ef0b4b
Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents:
1602
diff
changeset
|
58 {XMPP_ERROR_CONFLICT, "409", |
351427ef0b4b
Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents:
1602
diff
changeset
|
59 "Conflict", "conflict", "cancel"}, |
351427ef0b4b
Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents:
1602
diff
changeset
|
60 {XMPP_ERROR_INTERNAL_SERVER_ERROR, "500", |
351427ef0b4b
Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents:
1602
diff
changeset
|
61 "Internal Server Error", "internal-server-error", "wait"}, |
351427ef0b4b
Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents:
1602
diff
changeset
|
62 {XMPP_ERROR_NOT_IMPLEMENTED, "501", |
351427ef0b4b
Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents:
1602
diff
changeset
|
63 "Not Implemented", "feature-not-implemented", "cancel"}, |
351427ef0b4b
Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents:
1602
diff
changeset
|
64 {XMPP_ERROR_REMOTE_SERVER_ERROR, "502", |
351427ef0b4b
Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents:
1602
diff
changeset
|
65 "Remote Server Error", "service-unavailable", "wait"}, |
351427ef0b4b
Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents:
1602
diff
changeset
|
66 {XMPP_ERROR_SERVICE_UNAVAILABLE, "503", |
351427ef0b4b
Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents:
1602
diff
changeset
|
67 "Service Unavailable", "service-unavailable", "cancel"}, |
351427ef0b4b
Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents:
1602
diff
changeset
|
68 {XMPP_ERROR_REMOTE_SERVER_TIMEOUT, "504", |
351427ef0b4b
Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents:
1602
diff
changeset
|
69 "Remote Server Timeout", "remote-server-timeout", "wait"}, |
351427ef0b4b
Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents:
1602
diff
changeset
|
70 {XMPP_ERROR_DISCONNECTED, "510", |
351427ef0b4b
Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents:
1602
diff
changeset
|
71 "Disconnected", "service-unavailable", "cancel"}, |
351427ef0b4b
Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents:
1602
diff
changeset
|
72 {0, NULL, NULL, NULL, NULL} |
351427ef0b4b
Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents:
1602
diff
changeset
|
73 }; |
351427ef0b4b
Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents:
1602
diff
changeset
|
74 |
351427ef0b4b
Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents:
1602
diff
changeset
|
75 |
1607 | 76 #ifdef MODULES_ENABLE |
77 static GSList *xmpp_additional_features = NULL; | |
78 static char *ver, *ver_notavail; | |
79 | |
80 void xmpp_add_feature (const char *xmlns) | |
81 { | |
82 if (xmlns) { | |
83 ver = NULL; | |
84 ver_notavail = NULL; | |
85 xmpp_additional_features = g_slist_append(xmpp_additional_features, | |
86 g_strdup (xmlns)); | |
87 } | |
88 } | |
89 | |
90 void xmpp_del_feature (const char *xmlns) | |
91 { | |
92 GSList *feature = xmpp_additional_features; | |
93 while (feature) { | |
94 if (!strcmp(feature->data, xmlns)) { | |
95 ver = NULL; | |
96 ver_notavail = NULL; | |
97 g_free (feature->data); | |
98 xmpp_additional_features = g_slist_delete_link(xmpp_additional_features, | |
99 feature); | |
100 return; | |
101 } | |
102 feature = g_slist_next (feature); | |
103 } | |
104 } | |
105 #endif | |
106 | |
1598 | 107 const gchar* lm_message_node_get_child_value(LmMessageNode *node, |
108 const gchar *child) | |
109 { | |
110 LmMessageNode *tmp; | |
111 tmp = lm_message_node_find_child(node, child); | |
112 if (tmp) | |
113 return lm_message_node_get_value(tmp); | |
114 else return NULL; | |
115 } | |
116 | |
117 static LmMessageNode *hidden = NULL; | |
118 | |
119 void lm_message_node_hide(LmMessageNode *node) | |
120 { | |
121 LmMessageNode *parent = node->parent, *prev_sibling = node->prev; | |
122 | |
123 if (hidden) { | |
124 hidden->children = hidden->next = hidden->prev = hidden->parent = NULL; | |
125 lm_message_node_unref(hidden); | |
126 } | |
127 | |
128 if (parent->children == node) | |
129 parent->children = node->next; | |
130 if (prev_sibling) | |
131 prev_sibling->next = node->next; | |
132 if (node->next) | |
133 node->next->prev = prev_sibling; | |
134 } | |
135 | |
1729
e6e89b1d7831
Minor style and header updates
Mikael Berthe <mikael@lilotux.net>
parents:
1704
diff
changeset
|
136 // Maybe not a good idea, because it uses internals of loudmouth... |
e6e89b1d7831
Minor style and header updates
Mikael Berthe <mikael@lilotux.net>
parents:
1704
diff
changeset
|
137 // It's used for rosternotes/bookmarks |
1598 | 138 LmMessageNode *lm_message_node_new(const gchar *name, const gchar *xmlns) |
139 { | |
140 LmMessageNode *node; | |
141 | |
142 node = g_new0 (LmMessageNode, 1); | |
143 node->name = g_strdup (name); | |
144 node->value = NULL; | |
145 node->raw_mode = FALSE; | |
146 node->attributes = NULL; | |
147 node->next = NULL; | |
148 node->prev = NULL; | |
149 node->parent = NULL; | |
150 node->children = NULL; | |
151 | |
152 node->ref_count = 1; | |
153 lm_message_node_set_attribute(node, "xmlns", xmlns); | |
154 return node; | |
155 } | |
156 | |
157 void lm_message_node_insert_childnode(LmMessageNode *node, | |
158 LmMessageNode *child) | |
159 { | |
160 LmMessageNode *x; | |
161 lm_message_node_deep_ref(child); | |
162 | |
163 if (node->children == NULL) | |
164 node->children = child; | |
165 else { | |
166 for (x = node->children; x->next; x = x->next) | |
167 ; | |
168 x->next = child; | |
169 } | |
170 } | |
171 | |
172 void lm_message_node_deep_ref(LmMessageNode *node) | |
173 { | |
174 if (node == NULL) | |
175 return; | |
176 lm_message_node_ref(node); | |
177 lm_message_node_deep_ref(node->next); | |
178 lm_message_node_deep_ref(node->children); | |
179 } | |
180 | |
181 const gchar* lm_message_get_from(LmMessage *m) | |
182 { | |
183 return lm_message_node_get_attribute(m->node, "from"); | |
184 } | |
185 | |
186 const gchar* lm_message_get_id(LmMessage *m) | |
187 { | |
188 return lm_message_node_get_attribute(m->node, "id"); | |
189 } | |
190 | |
1604
351427ef0b4b
Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents:
1602
diff
changeset
|
191 LmMessage *lm_message_new_iq_from_query(LmMessage *m, |
351427ef0b4b
Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents:
1602
diff
changeset
|
192 LmMessageSubType type) |
1598 | 193 { |
194 LmMessage *new; | |
195 const char *from = lm_message_node_get_attribute(m->node, "from"); | |
196 const char *id = lm_message_node_get_attribute(m->node, "id"); | |
197 | |
198 new = lm_message_new_with_sub_type(from, LM_MESSAGE_TYPE_IQ, | |
199 type); | |
200 if (id) | |
201 lm_message_node_set_attribute(new->node, "id", id); | |
202 | |
203 return new; | |
204 } | |
205 | |
1600 | 206 // entity_version(enum imstatus status) |
1598 | 207 // Return a static version string for Entity Capabilities. |
208 // It should be specific to the client version, please change the id | |
209 // if you alter mcabber's disco support (or add something to the version | |
210 // number) so that it doesn't conflict with the official client. | |
1600 | 211 const char *entity_version(enum imstatus status) |
1598 | 212 { |
1607 | 213 #ifndef MODULES_ENABLE |
1600 | 214 static char *ver, *ver_notavail; |
1607 | 215 #endif |
1598 | 216 |
1600 | 217 if (ver && (status != notavail)) |
1598 | 218 return ver; |
1600 | 219 if (ver_notavail) |
220 return ver_notavail; | |
1598 | 221 |
1600 | 222 caps_add(""); |
223 caps_set_identity("", "client", PACKAGE_STRING, "pc"); | |
224 caps_add_feature("", NS_DISCO_INFO); | |
225 caps_add_feature("", NS_MUC); | |
226 // advertise ChatStates only if they aren't disabled | |
227 if (!settings_opt_get_int("disable_chatstates")) | |
228 caps_add_feature("", NS_CHATSTATES); | |
229 caps_add_feature("", NS_TIME); | |
230 caps_add_feature("", NS_XMPP_TIME); | |
231 caps_add_feature("", NS_VERSION); | |
232 caps_add_feature("", NS_PING); | |
233 caps_add_feature("", NS_COMMANDS); | |
1602 | 234 caps_add_feature("", NS_RECEIPTS); |
1600 | 235 if (!settings_opt_get_int("iq_last_disable") && |
236 (!settings_opt_get_int("iq_last_disable_when_notavail") || | |
237 status != notavail)) | |
238 caps_add_feature("", NS_LAST); | |
1607 | 239 #ifdef MODULES_ENABLE |
240 { | |
241 GSList *el = xmpp_additional_features; | |
242 while (el) { | |
243 caps_add_feature("", el->data); | |
244 el = g_slist_next (el); | |
245 } | |
246 } | |
247 #endif | |
1598 | 248 |
1600 | 249 if (status == notavail) { |
250 ver_notavail = caps_generate(); | |
251 return ver_notavail; | |
252 } | |
253 | |
254 ver = caps_generate(); | |
1598 | 255 return ver; |
256 } | |
257 | |
1604
351427ef0b4b
Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents:
1602
diff
changeset
|
258 LmMessageNode *lm_message_node_find_xmlns(LmMessageNode *node, |
351427ef0b4b
Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents:
1602
diff
changeset
|
259 const char *xmlns) |
1598 | 260 { |
261 LmMessageNode *x; | |
262 const char *p; | |
263 | |
264 for (x = node->children ; x; x = x->next) { | |
265 if ((p = lm_message_node_get_attribute(x, "xmlns")) && !strcmp(p, xmlns)) | |
266 break; | |
267 } | |
268 return x; | |
269 } | |
270 | |
1604
351427ef0b4b
Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents:
1602
diff
changeset
|
271 time_t lm_message_node_get_timestamp(LmMessageNode *node) |
1598 | 272 { |
273 LmMessageNode *x; | |
274 const char *p; | |
275 | |
276 x = lm_message_node_find_xmlns(node, NS_XMPP_DELAY); | |
277 if (x && (!strcmp(x->name, "delay")) && | |
278 (p = lm_message_node_get_attribute(x, "stamp")) != NULL) | |
279 return from_iso8601(p, 1); | |
280 x = lm_message_node_find_xmlns(node, NS_DELAY); | |
281 if (x && (p = lm_message_node_get_attribute(x, "stamp")) != NULL) | |
282 return from_iso8601(p, 1); | |
283 return 0; | |
284 } | |
285 | |
286 // lm_message_new_presence(status, recipient, message) | |
287 // Create an xmlnode with default presence attributes | |
288 // Note: the caller must free the node after use | |
1604
351427ef0b4b
Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents:
1602
diff
changeset
|
289 LmMessage *lm_message_new_presence(enum imstatus st, |
351427ef0b4b
Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents:
1602
diff
changeset
|
290 const char *recipient, |
351427ef0b4b
Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents:
1602
diff
changeset
|
291 const char *msg) |
1598 | 292 { |
293 unsigned int prio; | |
294 LmMessage *x = lm_message_new(recipient, LM_MESSAGE_TYPE_PRESENCE); | |
295 | |
296 switch(st) { | |
297 case away: | |
298 case notavail: | |
299 case dontdisturb: | |
300 case freeforchat: | |
301 lm_message_node_add_child(x->node, "show", imstatus_showmap[st]); | |
302 break; | |
303 | |
304 case invisible: | |
305 lm_message_node_set_attribute(x->node, "type", "invisible"); | |
306 break; | |
307 | |
308 case offline: | |
309 lm_message_node_set_attribute(x->node, "type", "unavailable"); | |
310 break; | |
311 | |
312 default: | |
313 break; | |
314 } | |
315 | |
316 if (st == away || st == notavail) | |
317 prio = settings_opt_get_int("priority_away"); | |
318 else | |
319 prio = settings_opt_get_int("priority"); | |
320 | |
321 if (prio) { | |
322 char strprio[8]; | |
323 snprintf(strprio, 8, "%d", (int)prio); | |
324 lm_message_node_add_child(x->node, "priority", strprio); | |
325 } | |
326 | |
327 if (msg) | |
328 lm_message_node_add_child(x->node, "status", msg); | |
329 | |
330 return x; | |
331 } | |
332 | |
333 static const char *defaulterrormsg(guint code) | |
334 { | |
1604
351427ef0b4b
Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents:
1602
diff
changeset
|
335 int i; |
1598 | 336 |
337 for (i = 0; xmpp_errors[i].code; ++i) { | |
338 if (xmpp_errors[i].code == code) | |
339 return xmpp_errors[i].meaning; | |
340 } | |
341 return NULL; | |
342 } | |
343 | |
344 // display_server_error(x) | |
345 // Display the error to the user | |
346 // x: error tag xmlnode pointer | |
347 void display_server_error(LmMessageNode *x) | |
348 { | |
1704
ab502d645378
Update display_server_error()
Mikael Berthe <mikael@lilotux.net>
parents:
1697
diff
changeset
|
349 const char *desc = NULL, *errname=NULL, *s; |
1598 | 350 char *sdesc, *tmp; |
351 | |
352 if (!x) return; | |
353 | |
354 /* RFC3920: | |
355 * The <error/> element: | |
356 * o MUST contain a child element corresponding to one of the defined | |
357 * stanza error conditions specified below; this element MUST be | |
358 * qualified by the 'urn:ietf:params:xml:ns:xmpp-stanzas' namespace. | |
359 */ | |
360 if (x->children) | |
1704
ab502d645378
Update display_server_error()
Mikael Berthe <mikael@lilotux.net>
parents:
1697
diff
changeset
|
361 errname = x->children->name; |
ab502d645378
Update display_server_error()
Mikael Berthe <mikael@lilotux.net>
parents:
1697
diff
changeset
|
362 scr_LogPrint(LPRINT_LOGNORM, "Received error packet [%s]", |
ab502d645378
Update display_server_error()
Mikael Berthe <mikael@lilotux.net>
parents:
1697
diff
changeset
|
363 (errname ? errname : "")); |
1598 | 364 |
365 // For backward compatibility | |
1704
ab502d645378
Update display_server_error()
Mikael Berthe <mikael@lilotux.net>
parents:
1697
diff
changeset
|
366 if (!errname && ((s = lm_message_node_get_attribute(x, "code")) != NULL)) { |
1598 | 367 // Default message |
1704
ab502d645378
Update display_server_error()
Mikael Berthe <mikael@lilotux.net>
parents:
1697
diff
changeset
|
368 desc = defaulterrormsg(atoi(s)); |
1598 | 369 } |
370 | |
371 // Error tag data is better, if available | |
372 s = lm_message_node_get_value(x); | |
373 if (s && *s) desc = s; | |
374 | |
375 // And sometimes there is a text message | |
376 s = lm_message_node_get_child_value(x, "text"); | |
377 | |
378 if (s && *s) desc = s; | |
379 | |
380 // If we still have no description, let's give up | |
1704
ab502d645378
Update display_server_error()
Mikael Berthe <mikael@lilotux.net>
parents:
1697
diff
changeset
|
381 if (!desc || !*desc) |
1598 | 382 return; |
383 | |
384 // Strip trailing newlines | |
385 sdesc = g_strdup(desc); | |
386 for (tmp = sdesc; *tmp; tmp++) ; | |
387 if (tmp > sdesc) | |
388 tmp--; | |
389 while (tmp >= sdesc && (*tmp == '\n' || *tmp == '\r')) | |
390 *tmp-- = '\0'; | |
391 | |
1704
ab502d645378
Update display_server_error()
Mikael Berthe <mikael@lilotux.net>
parents:
1697
diff
changeset
|
392 if (*sdesc) |
ab502d645378
Update display_server_error()
Mikael Berthe <mikael@lilotux.net>
parents:
1697
diff
changeset
|
393 scr_LogPrint(LPRINT_LOGNORM, "Error message from server: %s", sdesc); |
1598 | 394 g_free(sdesc); |
395 } | |
396 | |
1599 | 397 /* vim: set expandtab cindent cinoptions=>2\:2(0: For Vim users... */ |