From c1a191955ba9903e1dc07b49886a9ce52fdf4207 Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Sun, 1 Oct 2000 20:48:10 +0000 Subject: [PATCH] Chat protocol updates. Module loading tries to load first from home dir, then the global dir. git-svn-id: http://svn.irssi.org/repos/irssi/trunk@704 dbcabf3a-b0e7-0310-adc4-f8d773084564 --- src/core/chat-protocols.c | 79 +++++++++++++------------------- src/core/chat-protocols.h | 10 ++-- src/core/modules.c | 18 +++++--- src/fe-common/core/fe-server.c | 2 +- src/fe-common/core/window-save.c | 2 +- 5 files changed, 51 insertions(+), 60 deletions(-) diff --git a/src/core/chat-protocols.c b/src/core/chat-protocols.c index 40413682..2b3c3205 100644 --- a/src/core/chat-protocols.c +++ b/src/core/chat-protocols.c @@ -19,15 +19,11 @@ */ #include "module.h" +#include "signals.h" #include "chat-protocols.h" -typedef struct { - int id; - CHAT_PROTOCOL_REC *rec; -} PROTOCOL_REC; - static int id_counter; -static GSList *protocols; +GSList *chat_protocols; void *chat_protocol_check_cast(void *object, int type_pos, const char *id) { @@ -36,30 +32,41 @@ void *chat_protocol_check_cast(void *object, int type_pos, const char *id) G_STRUCT_MEMBER(int, object, type_pos) ? NULL : object; } -static PROTOCOL_REC *chat_protocol_find(const char *name) +/* Return the ID for the specified chat protocol. */ +int chat_protocol_lookup(const char *name) +{ + CHAT_PROTOCOL_REC *rec; + + g_return_val_if_fail(name != NULL, -1); + + rec = chat_protocol_find(name); + return rec == NULL ? -1 : rec->id; +} + +CHAT_PROTOCOL_REC *chat_protocol_find(const char *name) { GSList *tmp; g_return_val_if_fail(name != NULL, NULL); - for (tmp = protocols; tmp != NULL; tmp = tmp->next) { - PROTOCOL_REC *rec = tmp->data; + for (tmp = chat_protocols; tmp != NULL; tmp = tmp->next) { + CHAT_PROTOCOL_REC *rec = tmp->data; - if (g_strcasecmp(rec->rec->name, name) == 0) + if (g_strcasecmp(rec->name, name) == 0) return rec; } return NULL; } -static PROTOCOL_REC *chat_protocol_find_id(int id) +CHAT_PROTOCOL_REC *chat_protocol_find_id(int id) { GSList *tmp; g_return_val_if_fail(id > 0, NULL); - for (tmp = protocols; tmp != NULL; tmp = tmp->next) { - PROTOCOL_REC *rec = tmp->data; + for (tmp = chat_protocols; tmp != NULL; tmp = tmp->next) { + CHAT_PROTOCOL_REC *rec = tmp->data; if (rec->id == id) return rec; @@ -71,32 +78,30 @@ static PROTOCOL_REC *chat_protocol_find_id(int id) /* Register new chat protocol. */ void chat_protocol_register(CHAT_PROTOCOL_REC *rec) { - PROTOCOL_REC *proto; - g_return_if_fail(rec != NULL); if (chat_protocol_find(rec->name) != NULL) return; - proto = g_new0(PROTOCOL_REC, 1); - proto->id = ++id_counter; - proto->rec = rec; - protocols = g_slist_append(protocols, proto); + rec->id = ++id_counter; + chat_protocols = g_slist_append(chat_protocols, rec); + + signal_emit("chat protocol created", 1, rec); } -static void chat_protocol_destroy(PROTOCOL_REC *rec) +static void chat_protocol_destroy(CHAT_PROTOCOL_REC *rec) { g_return_if_fail(rec != NULL); - protocols = g_slist_remove(protocols, rec); - g_free(rec->rec); + chat_protocols = g_slist_remove(chat_protocols, rec); + signal_emit("chat protocol destroyed", 1, rec); g_free(rec); } /* Unregister chat protocol. */ void chat_protocol_unregister(const char *name) { - PROTOCOL_REC *rec; + CHAT_PROTOCOL_REC *rec; g_return_if_fail(name != NULL); @@ -104,36 +109,14 @@ void chat_protocol_unregister(const char *name) if (rec != NULL) chat_protocol_destroy(rec); } -/* Return the ID for the specified chat protocol. */ -int chat_protocol_lookup(const char *name) -{ - PROTOCOL_REC *rec; - - g_return_val_if_fail(name != NULL, -1); - - rec = chat_protocol_find(name); - return rec == NULL ? -1 : rec->id; -} - -/* Return the record for the specified chat protocol ID. */ -CHAT_PROTOCOL_REC *chat_protocol_get_rec(int id) -{ - PROTOCOL_REC *rec; - - g_return_val_if_fail(id > 0, NULL); - - rec = chat_protocol_find_id(id); - return rec == NULL ? NULL : rec->rec; -} - void chat_protocols_init(void) { id_counter = 0; - protocols = NULL; + chat_protocols = NULL; } void chat_protocols_deinit(void) { - while (protocols != NULL) - chat_protocol_destroy(protocols->data); + while (chat_protocols != NULL) + chat_protocol_destroy(chat_protocols->data); } diff --git a/src/core/chat-protocols.h b/src/core/chat-protocols.h index 1f38da50..3f614a50 100644 --- a/src/core/chat-protocols.h +++ b/src/core/chat-protocols.h @@ -2,11 +2,15 @@ #define __CHAT_PROTOCOLS_H typedef struct { + int id; + char *name; char *fullname; char *chatnet; } CHAT_PROTOCOL_REC; +extern GSList *chat_protocols; + #define PROTO_CHECK_CAST(object, cast, type_field, id) \ ((cast *) chat_protocol_check_cast(object, \ offsetof(cast, type_field), id)) @@ -18,10 +22,10 @@ void chat_protocol_register(CHAT_PROTOCOL_REC *rec); /* Unregister chat protocol. */ void chat_protocol_unregister(const char *name); -/* Return the ID for the specified chat protocol. */ +/* Find functions */ int chat_protocol_lookup(const char *name); -/* Return the record for the specified chat protocol ID. */ -CHAT_PROTOCOL_REC *chat_protocol_get_rec(int id); +CHAT_PROTOCOL_REC *chat_protocol_find(const char *name); +CHAT_PROTOCOL_REC *chat_protocol_find_id(int id); void chat_protocols_init(void); void chat_protocols_deinit(void); diff --git a/src/core/modules.c b/src/core/modules.c index e95eaf2a..bcb537b1 100644 --- a/src/core/modules.c +++ b/src/core/modules.c @@ -238,22 +238,26 @@ char *module_get_name(const char *path) GModule *module_open(const char *name) { + struct stat statbuf; GModule *module; char *path, *str; if (g_path_is_absolute(name)) path = g_strdup(name); else { - path = g_module_build_path(MODULEDIR, name); - module = g_module_open(path, 0); - g_free(path); - if (module != NULL) return module; - - /* module not found from global module dir, - check from home dir */ + /* first try from home dir */ str = g_strdup_printf("%s/.irssi/modules", g_get_home_dir()); path = g_module_build_path(str, name); g_free(str); + + if (stat(path, &statbuf) == 0) { + module = g_module_open(path, 0); + g_free(path); + return module; + } + + /* module not found from home dir, try global module dir */ + path = g_module_build_path(MODULEDIR, name); } module = g_module_open(path, 0); diff --git a/src/fe-common/core/fe-server.c b/src/fe-common/core/fe-server.c index 32fca57f..53160037 100644 --- a/src/fe-common/core/fe-server.c +++ b/src/fe-common/core/fe-server.c @@ -102,7 +102,7 @@ static void cmd_server_add(const char *data) signal_emit("server add create", 2, &rec, optlist); if (rec == NULL) { /* no chatnet option specified, use the first. */ - g_hash_table_insert(optlist, (char *) chat_protocol_get_rec(1)->name, ""); + g_hash_table_insert(optlist, chat_protocol_find_id(1)->name, ""); signal_emit("server add create", 2, &rec, optlist); if (rec == NULL) { /* bug? */ diff --git a/src/fe-common/core/window-save.c b/src/fe-common/core/window-save.c index 11125b61..61d2bb5e 100644 --- a/src/fe-common/core/window-save.c +++ b/src/fe-common/core/window-save.c @@ -130,7 +130,7 @@ static void window_save_items(WINDOW_REC *window, CONFIG_NODE *node) subnode = config_node_section(node, NULL, NODE_TYPE_BLOCK); iconfig_node_set_str(subnode, "type", type); - type = chat_protocol_get_rec(rec->chat_type)->name; + type = chat_protocol_find_id(rec->chat_type)->name; iconfig_node_set_str(subnode, "chat_type", type); iconfig_node_set_str(subnode, "name", rec->name);