summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorTimo Sirainen <cras@irssi.org>2000-09-02 18:53:58 +0000
committercras <cras@dbcabf3a-b0e7-0310-adc4-f8d773084564>2000-09-02 18:53:58 +0000
commit755a8d40eb5f9e0a12b98e4f84332891a3d63b1a (patch)
treeb96a317a11affdb428a121176836cf48e707c286 /src/core
parent28a7908e7372fe0e81dd439b6559bc2abe3ea6e8 (diff)
downloadirssi-755a8d40eb5f9e0a12b98e4f84332891a3d63b1a.zip
Updates.
git-svn-id: http://svn.irssi.org/repos/irssi/trunk@641 dbcabf3a-b0e7-0310-adc4-f8d773084564
Diffstat (limited to 'src/core')
-rw-r--r--src/core/channels.c17
-rw-r--r--src/core/channels.h11
-rw-r--r--src/core/modules.c12
-rw-r--r--src/core/modules.h5
-rw-r--r--src/core/queries.c17
-rw-r--r--src/core/queries.h7
-rw-r--r--src/core/servers-reconnect.c1
-rw-r--r--src/core/servers.c42
-rw-r--r--src/core/servers.h6
9 files changed, 110 insertions, 8 deletions
diff --git a/src/core/channels.c b/src/core/channels.c
index 0cbcfa55..1577472c 100644
--- a/src/core/channels.c
+++ b/src/core/channels.c
@@ -28,6 +28,21 @@ typedef CHANNEL_REC *(*CHANNEL_FIND_FUNC)(SERVER_REC *, const char *);
GSList *channels; /* List of all channels */
+/* Create a new channel */
+CHANNEL_REC *channel_create(int chat_type, SERVER_REC *server,
+ const char *name, int automatic)
+{
+ CHANNEL_REC *channel;
+
+ g_return_val_if_fail(server == NULL || IS_SERVER(server), NULL);
+ g_return_val_if_fail(name != NULL, NULL);
+
+ channel = NULL;
+ signal_emit("channel create", 5, &channel, GINT_TO_POINTER(chat_type),
+ server, name, GINT_TO_POINTER(automatic));
+ return channel;
+}
+
void channel_init(CHANNEL_REC *channel, int automatic)
{
g_return_if_fail(channel != NULL);
@@ -40,7 +55,7 @@ void channel_init(CHANNEL_REC *channel, int automatic)
}
MODULE_DATA_INIT(channel);
- channel->type = module_get_uniq_id("CHANNEL", 0);
+ channel->type = module_get_uniq_id_str("WINDOW ITEM TYPE", "CHANNEL");
channel->mode = g_strdup("");
channel->createtime = time(NULL);
diff --git a/src/core/channels.h b/src/core/channels.h
index 36319701..91a330c1 100644
--- a/src/core/channels.h
+++ b/src/core/channels.h
@@ -5,7 +5,8 @@
/* Returns CHANNEL_REC if it's channel, NULL if it isn't. */
#define CHANNEL(channel) \
- MODULE_CHECK_CAST(channel, CHANNEL_REC, type, "CHANNEL")
+ MODULE_CHECK_CAST_MODULE(channel, CHANNEL_REC, type, \
+ "WINDOW ITEM TYPE", "CHANNEL")
#define IS_CHANNEL(channel) \
(CHANNEL(channel) ? TRUE : FALSE)
@@ -17,8 +18,9 @@ typedef struct {
extern GSList *channels;
-void channels_init(void);
-void channels_deinit(void);
+/* Create a new channel */
+CHANNEL_REC *channel_create(int chat_type, SERVER_REC *server,
+ const char *name, int automatic);
/* Create new channel record */
void channel_init(CHANNEL_REC *channel, int automatic);
@@ -27,4 +29,7 @@ void channel_destroy(CHANNEL_REC *channel);
/* find channel by name, if `server' is NULL, search from all servers */
CHANNEL_REC *channel_find(SERVER_REC *server, const char *name);
+void channels_init(void);
+void channels_deinit(void);
+
#endif
diff --git a/src/core/modules.c b/src/core/modules.c
index 85e19f2c..7b81bff2 100644
--- a/src/core/modules.c
+++ b/src/core/modules.c
@@ -30,8 +30,16 @@ static int next_uniq_id;
void *module_check_cast(void *object, int type_pos, const char *id)
{
- return object == NULL ||
- module_find_id(id, G_STRUCT_MEMBER(int, object, type_pos)) == -1 ? NULL : object;
+ return object == NULL || module_find_id(id,
+ G_STRUCT_MEMBER(int, object, type_pos)) == -1 ? NULL : object;
+}
+
+void *module_check_cast_module(void *object, int type_pos,
+ const char *module, const char *id)
+{
+ return object == NULL || strcmp(module_find_id_str(module,
+ G_STRUCT_MEMBER(int, object, type_pos)), id) == 0 ?
+ NULL : object;
}
/* return unique number across all modules for `id' */
diff --git a/src/core/modules.h b/src/core/modules.h
index 118e790c..61e4f319 100644
--- a/src/core/modules.h
+++ b/src/core/modules.h
@@ -33,7 +33,12 @@ void module_unload(MODULE_REC *module);
#define MODULE_CHECK_CAST(object, cast, type_field, id) \
((cast *) module_check_cast(object, offsetof(cast, type_field), id))
+#define MODULE_CHECK_CAST_MODULE(object, cast, type_field, module, id) \
+ ((cast *) module_check_cast_module(object, \
+ offsetof(cast, type_field), module, id))
void *module_check_cast(void *object, int type_pos, const char *id);
+void *module_check_cast_module(void *object, int type_pos,
+ const char *module, const char *id);
/* return unique number across all modules for `id' */
int module_get_uniq_id(const char *module, int id);
diff --git a/src/core/queries.c b/src/core/queries.c
index f3e59184..c9793f7a 100644
--- a/src/core/queries.c
+++ b/src/core/queries.c
@@ -28,6 +28,21 @@ GSList *queries;
typedef QUERY_REC *(*QUERY_FIND_FUNC)(SERVER_REC *, const char *);
+/* 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;
+}
+
void query_init(QUERY_REC *query, int automatic)
{
g_return_if_fail(query != NULL);
@@ -40,7 +55,7 @@ void query_init(QUERY_REC *query, int automatic)
}
MODULE_DATA_INIT(query);
- query->type = module_get_uniq_id("QUERY", 0);
+ query->type = module_get_uniq_id_str("WINDOW ITEM TYPE", "QUERY");
if (query->server != NULL)
query->server_tag = g_strdup(query->server->tag);
diff --git a/src/core/queries.h b/src/core/queries.h
index 5fbe543e..1709b064 100644
--- a/src/core/queries.h
+++ b/src/core/queries.h
@@ -5,7 +5,8 @@
/* Returns QUERY_REC if it's query, NULL if it isn't. */
#define QUERY(query) \
- MODULE_CHECK_CAST(query, QUERY_REC, type, "QUERY")
+ MODULE_CHECK_CAST_MODULE(query, QUERY_REC, type, \
+ "WINDOW ITEM TYPE", "QUERY")
#define IS_QUERY(query) \
(QUERY(query) ? TRUE : FALSE)
@@ -20,6 +21,10 @@ extern GSList *queries;
void query_init(QUERY_REC *query, int automatic);
void query_destroy(QUERY_REC *query);
+/* Create a new query */
+QUERY_REC *query_create(int chat_type, SERVER_REC *server,
+ const char *nick, int automatic);
+
/* Find query by name, if `server' is NULL, search from all servers */
QUERY_REC *query_find(SERVER_REC *server, const char *nick);
diff --git a/src/core/servers-reconnect.c b/src/core/servers-reconnect.c
index d4d8b942..03db18d8 100644
--- a/src/core/servers-reconnect.c
+++ b/src/core/servers-reconnect.c
@@ -114,6 +114,7 @@ server_connect_copy_skeleton(SERVER_CONNECT_REC *src)
signal_emit("server connect copy", 2, &dest, src);
g_return_val_if_fail(dest != NULL, NULL);
+ dest->type = module_get_uniq_id("SERVER CONNECT", 0);
dest->proxy = g_strdup(src->proxy);
dest->proxy_port = src->proxy_port;
dest->proxy_string = g_strdup(src->proxy_string);
diff --git a/src/core/servers.c b/src/core/servers.c
index b8168f05..2abc7434 100644
--- a/src/core/servers.c
+++ b/src/core/servers.c
@@ -20,6 +20,7 @@
#include "module.h"
#include "signals.h"
+#include "commands.h"
#include "line-split.h"
#include "net-nonblock.h"
#include "net-sendbuffer.h"
@@ -28,6 +29,7 @@
#include "settings.h"
#include "servers.h"
+#include "servers-reconnect.h"
#include "servers-redirect.h"
#include "servers-setup.h"
#include "channels.h"
@@ -397,10 +399,49 @@ void server_connect_free(SERVER_CONNECT_REC *conn)
g_free(conn);
}
+/* `optlist' should contain only one key - the server tag.
+ returns NULL if there was unknown -option */
+SERVER_REC *cmd_options_get_server(const char *cmd,
+ GHashTable *optlist,
+ SERVER_REC *defserver)
+{
+ SERVER_REC *server;
+ GSList *list, *tmp, *next;
+
+ /* get all the options, then remove the known ones. there should
+ be only one left - the server tag. */
+ list = hashtable_get_keys(optlist);
+ for (tmp = list; tmp != NULL; tmp = next) {
+ char *option = tmp->data;
+ next = tmp->next;
+
+ if (command_have_option(cmd, option))
+ list = g_slist_remove(list, option);
+ }
+
+ if (list == NULL)
+ return defserver;
+
+ server = server_find_tag(list->data);
+ if (server == NULL || list->next != NULL) {
+ /* unknown option (not server tag) */
+ signal_emit("error command", 2,
+ GINT_TO_POINTER(CMDERR_OPTION_UNKNOWN),
+ server == NULL ? list->data : list->next->data);
+ signal_stop();
+
+ server = NULL;
+ }
+
+ g_slist_free(list);
+ return server;
+}
+
void servers_init(void)
{
lookup_servers = servers = NULL;
+ servers_reconnect_init();
servers_redirect_init();
servers_setup_init();
}
@@ -414,6 +455,7 @@ void servers_deinit(void)
servers_setup_deinit();
servers_redirect_deinit();
+ servers_reconnect_deinit();
module_uniq_destroy("SERVER");
module_uniq_destroy("SERVER CONNECT");
diff --git a/src/core/servers.h b/src/core/servers.h
index 25f6ef5e..7f033b7e 100644
--- a/src/core/servers.h
+++ b/src/core/servers.h
@@ -48,4 +48,10 @@ SERVER_REC *server_find_chatnet(const char *chatnet);
int server_start_connect(SERVER_REC *server);
void server_connect_free(SERVER_CONNECT_REC *conn);
+/* `optlist' should contain only one key - the server tag.
+ returns NULL if there was unknown -option */
+SERVER_REC *cmd_options_get_server(const char *cmd,
+ GHashTable *optlist,
+ SERVER_REC *defserver);
+
#endif