Debian Codegraph @

src/core/xmpp-queries.c

raw symbols ◀ ▶ SCIP
1 Debian patch touch this file
1 /*
2 * Copyright (C) 2007 Colin DIDIER
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16 */
17
18 #include <string.h>
19
20 #include "module.h"
21 #include "channels.h"
22 #include "nicklist.h"
•23 #include "settings.h"
24 #include "signals.h"
25
26 #include "xmpp-queries.h"
27 #include "rosters-tools.h"
28 #include "tools.h"
29
30 QUERY_REC *
31 xmpp_query_create(const char *server_tag, const char *data, int automatic)
32 {
33 XMPP_QUERY_REC *rec, *rec_tmp;
34 XMPP_SERVER_REC *server;
35 CHANNEL_REC *channel;
36 NICK_REC *nick;
•37 char *str;
38 const char *channel_name;
39
40 g_return_val_if_fail(server_tag != NULL, NULL);
41 g_return_val_if_fail(data != NULL, NULL);
42 if ((server = XMPP_SERVER(server_find_tag(server_tag))) == NULL)
43 return NULL;
44 rec = g_new0(XMPP_QUERY_REC, 1);
45 rec->chat_type = XMPP_PROTOCOL;
46 /* query created from a channel */
47 channel_name = NULL;
48 signal_emit("xmpp windows get active channel", 1, &channel_name);
49 if (channel_name != NULL) {
50 channel = channel_find(SERVER(server), channel_name);
51 if (channel != NULL) {
52 nick = nicklist_find(channel, data);
53 if (nick != NULL)
54 rec->name = g_strdup(nick->host);
55 }
56 }
•57
58 if (rec->name == NULL)
59 rec->name = rosters_resolve_name(server, data);
•60 if (settings_get_bool("xmpp_strip_resource")) {
61 if (rec->name != NULL) {
62 str = xmpp_strip_resource(rec->name);
63 g_free(rec->name);
64 rec->name = NULL;
65 } else {
66 str = xmpp_strip_resource(data);
67 }
68 /* if this not a private message from channel we are
69 on, strip the resource */
70 if (channel_find(SERVER(server), str) == NULL)
71 rec->name = g_strdup(str);
72 g_free(str);
73 }
74 if (rec->name != NULL) {
75 /* test if the query already exist */
76 if ((rec_tmp = xmpp_query_find(server, rec->name)) != NULL) {
77 g_free(rec->name);
78 g_free(rec);
79 signal_emit("xmpp query raise", 2, server, rec_tmp);
80 return NULL;
81 }
82 } else
83 rec->name = g_strdup(data);
84 rec->server_tag = g_strdup(server_tag);
85 query_init((QUERY_REC *)rec, automatic);
86 rec->composing_time = 0;
87 rec->composing_visible = FALSE;
88 return (QUERY_REC *)rec;
89 }