2000-08-26 11:39:44 -04:00
|
|
|
/*
|
|
|
|
queries.c : irssi
|
|
|
|
|
|
|
|
Copyright (C) 1999-2000 Timo Sirainen
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "module.h"
|
|
|
|
#include "signals.h"
|
|
|
|
#include "misc.h"
|
|
|
|
|
|
|
|
#include "queries.h"
|
|
|
|
|
|
|
|
GSList *queries;
|
|
|
|
|
|
|
|
typedef QUERY_REC *(*QUERY_FIND_FUNC)(SERVER_REC *, const char *);
|
|
|
|
|
2000-09-02 14:53:58 -04:00
|
|
|
/* Create a new query */
|
|
|
|
QUERY_REC *query_create(int chat_type, SERVER_REC *server,
|
|
|
|
const char *nick, int automatic)
|
|
|
|
{
|
|
|
|
QUERY_REC *query;
|
|
|
|
|
|
|
|
g_return_val_if_fail(server == NULL || IS_SERVER(server), NULL);
|
|
|
|
g_return_val_if_fail(nick != NULL, NULL);
|
|
|
|
|
|
|
|
query = NULL;
|
|
|
|
signal_emit("query create", 5, &query, GINT_TO_POINTER(chat_type),
|
|
|
|
server, nick, GINT_TO_POINTER(automatic));
|
|
|
|
return query;
|
|
|
|
}
|
|
|
|
|
2000-08-26 11:39:44 -04:00
|
|
|
void query_init(QUERY_REC *query, int automatic)
|
|
|
|
{
|
|
|
|
g_return_if_fail(query != NULL);
|
|
|
|
g_return_if_fail(query->name != NULL);
|
|
|
|
|
|
|
|
queries = g_slist_append(queries, query);
|
|
|
|
if (query->server != NULL) {
|
|
|
|
query->server->queries =
|
|
|
|
g_slist_append(query->server->queries, query);
|
|
|
|
}
|
|
|
|
|
|
|
|
MODULE_DATA_INIT(query);
|
2000-09-02 14:53:58 -04:00
|
|
|
query->type = module_get_uniq_id_str("WINDOW ITEM TYPE", "QUERY");
|
2000-08-26 11:39:44 -04:00
|
|
|
if (query->server != NULL)
|
|
|
|
query->server_tag = g_strdup(query->server->tag);
|
|
|
|
|
|
|
|
signal_emit("query created", 2, query, GINT_TO_POINTER(automatic));
|
|
|
|
}
|
|
|
|
|
|
|
|
void query_destroy(QUERY_REC *query)
|
|
|
|
{
|
|
|
|
g_return_if_fail(IS_QUERY(query));
|
|
|
|
|
|
|
|
if (query->destroying) return;
|
|
|
|
query->destroying = TRUE;
|
|
|
|
|
|
|
|
queries = g_slist_remove(queries, query);
|
|
|
|
if (query->server != NULL) {
|
|
|
|
query->server->queries =
|
|
|
|
g_slist_remove(query->server->queries, query);
|
|
|
|
}
|
|
|
|
signal_emit("query destroyed", 1, query);
|
|
|
|
|
|
|
|
MODULE_DATA_DEINIT(query);
|
|
|
|
g_free_not_null(query->address);
|
|
|
|
g_free(query->name);
|
|
|
|
g_free(query->server_tag);
|
|
|
|
g_free(query);
|
|
|
|
}
|
|
|
|
|
|
|
|
static QUERY_REC *query_find_server(SERVER_REC *server, const char *nick)
|
|
|
|
{
|
|
|
|
GSList *tmp;
|
|
|
|
|
|
|
|
g_return_val_if_fail(IS_SERVER(server), NULL);
|
|
|
|
|
|
|
|
if (server->query_find_func != NULL) {
|
|
|
|
/* use the server specific query find function */
|
|
|
|
QUERY_FIND_FUNC query_find_func;
|
|
|
|
query_find_func = (QUERY_FIND_FUNC) server->query_find_func;
|
|
|
|
return query_find_func(server, nick);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (tmp = server->queries; tmp != NULL; tmp = tmp->next) {
|
|
|
|
QUERY_REC *rec = tmp->data;
|
|
|
|
|
2000-08-31 20:26:46 -04:00
|
|
|
if (rec->chat_type == server->chat_type &&
|
2000-08-26 11:39:44 -04:00
|
|
|
g_strcasecmp(nick, rec->name) == 0)
|
|
|
|
return rec;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
QUERY_REC *query_find(SERVER_REC *server, const char *nick)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail(server == NULL || IS_SERVER(server), NULL);
|
|
|
|
g_return_val_if_fail(nick != NULL, NULL);
|
|
|
|
|
|
|
|
if (server != NULL)
|
|
|
|
return query_find_server(server, nick);
|
|
|
|
|
|
|
|
/* find from any server */
|
|
|
|
return gslist_foreach_find(servers,
|
|
|
|
(FOREACH_FIND_FUNC) query_find_server,
|
|
|
|
(void *) nick);
|
|
|
|
}
|
|
|
|
|
|
|
|
void query_change_server(QUERY_REC *query, SERVER_REC *server)
|
|
|
|
{
|
|
|
|
g_return_if_fail(IS_QUERY(query));
|
|
|
|
|
|
|
|
query->server = server;
|
|
|
|
signal_emit("query server changed", 2, query, server);
|
|
|
|
}
|
|
|
|
|
|
|
|
void queries_init(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void queries_deinit(void)
|
|
|
|
{
|
|
|
|
module_uniq_destroy("QUERY");
|
|
|
|
}
|