| 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 "signals.h" |
| 24 |
|
| 25 |
#include "xmpp-queries.h" |
| 26 |
#include "rosters-tools.h" |
| 27 |
#include "tools.h" |
| 28 |
|
| 29 |
QUERY_REC * |
| 30 |
xmpp_query_create(const char *server_tag, const char *data, int automatic) |
| 31 |
{ |
| 32 |
XMPP_QUERY_REC *rec, *rec_tmp; |
| 33 |
XMPP_SERVER_REC *server; |
| 34 |
CHANNEL_REC *channel; |
| 35 |
NICK_REC *nick; |
| 36 |
const char *channel_name; |
| 37 |
|
| 38 |
g_return_val_if_fail(server_tag != NULL, NULL); |
| 39 |
g_return_val_if_fail(data != NULL, NULL); |
| 40 |
if ((server = XMPP_SERVER(server_find_tag(server_tag))) == NULL) |
| 41 |
return NULL; |
| 42 |
rec = g_new0(XMPP_QUERY_REC, 1); |
| 43 |
rec->chat_type = XMPP_PROTOCOL; |
| 44 |
/* query created from a channel */ |
| 45 |
channel_name = NULL; |
| 46 |
signal_emit("xmpp windows get active channel", 1, &channel_name); |
| 47 |
if (channel_name != NULL) { |
| 48 |
channel = channel_find(SERVER(server), channel_name); |
| 49 |
if (channel != NULL) { |
| 50 |
nick = nicklist_find(channel, data); |
| 51 |
if (nick != NULL) |
| 52 |
rec->name = g_strdup(nick->host); |
| 53 |
} |
| 54 |
} |
| 55 |
if (rec->name == NULL) |
| 56 |
rec->name = rosters_resolve_name(server, data); |
| 57 |
if (rec->name != NULL) { |
| 58 |
/* test if the query already exist */ |
| 59 |
if ((rec_tmp = xmpp_query_find(server, rec->name)) != NULL) { |
| 60 |
g_free(rec->name); |
| 61 |
g_free(rec); |
| 62 |
signal_emit("xmpp query raise", 2, server, rec_tmp); |
| 63 |
return NULL; |
| 64 |
} |
| 65 |
} else |
| 66 |
rec->name = g_strdup(data); |
| 67 |
rec->server_tag = g_strdup(server_tag); |
| 68 |
query_init((QUERY_REC *)rec, automatic); |
| 69 |
rec->composing_time = 0; |
| 70 |
rec->composing_visible = FALSE; |
| 71 |
return (QUERY_REC *)rec; |
| 72 |
} |