diff options
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/Makefile.am | 2 | ||||
-rw-r--r-- | src/core/channels.c | 3 | ||||
-rw-r--r-- | src/core/chat-protocols.c | 172 | ||||
-rw-r--r-- | src/core/chat-protocols.h | 29 | ||||
-rw-r--r-- | src/core/chatnet-rec.h | 4 | ||||
-rw-r--r-- | src/core/core.c | 3 | ||||
-rw-r--r-- | src/core/queries.c | 2 | ||||
-rw-r--r-- | src/core/server-connect-rec.h | 4 | ||||
-rw-r--r-- | src/core/server-rec.h | 7 | ||||
-rw-r--r-- | src/core/server-setup-rec.h | 4 | ||||
-rw-r--r-- | src/core/window-item-rec.h | 4 |
11 files changed, 219 insertions, 15 deletions
diff --git a/src/core/Makefile.am b/src/core/Makefile.am index d7534ee5..d6dd6e84 100644 --- a/src/core/Makefile.am +++ b/src/core/Makefile.am @@ -18,6 +18,7 @@ libcore_a_SOURCES = \ channels.c \ channels-setup.c \ commands.c \ + chat-protocols.c \ chatnets.c \ core.c \ levels.c \ @@ -57,6 +58,7 @@ noinst_HEADERS = \ channels.h \ channels-setup.h \ commands.h \ + chat-protocols.h \ chatnets.h \ core.h \ levels.h \ diff --git a/src/core/channels.c b/src/core/channels.c index bc3d8c0b..0cbcfa55 100644 --- a/src/core/channels.c +++ b/src/core/channels.c @@ -62,6 +62,7 @@ void channel_destroy(CHANNEL_REC *channel) MODULE_DATA_DEINIT(channel); g_free_not_null(channel->topic); g_free_not_null(channel->key); + g_free(channel->mode); g_free(channel->name); g_free(channel); } @@ -84,7 +85,7 @@ static CHANNEL_REC *channel_find_server(SERVER_REC *server, for (tmp = server->channels; tmp != NULL; tmp = tmp->next) { CHANNEL_REC *rec = tmp->data; - if (rec->chat_type == server->channel_type && + if (rec->chat_type == server->chat_type && g_strcasecmp(name, rec->name) == 0) return rec; } diff --git a/src/core/chat-protocols.c b/src/core/chat-protocols.c new file mode 100644 index 00000000..a5537f88 --- /dev/null +++ b/src/core/chat-protocols.c @@ -0,0 +1,172 @@ +/* + chat-protocol.c : irssi + + Copyright (C) 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 "chat-protocols.h" + +typedef struct { + int id; + char *name; + char *fullname; + char *chatnet; +} PROTOCOL_REC; + +static int id_counter; +static GSList *protocols; + +void *chat_protocol_check_cast(void *object, int type_pos, const char *id) +{ + return object == NULL || + chat_protocol_lookup(id) != + G_STRUCT_MEMBER(int, object, type_pos) ? NULL : object; +} + +static 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; + + if (g_strcasecmp(rec->name, name) == 0) + return rec; + } + + return NULL; +} + +static 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; + + if (rec->id == id) + return rec; + } + + return NULL; +} + +/* Register new chat protocol. */ +void chat_protocol_register(const char *name, + const char *fullname, + const char *chatnet) +{ + PROTOCOL_REC *rec; + + g_return_if_fail(name != NULL); + g_return_if_fail(fullname != NULL); + g_return_if_fail(chatnet != NULL); + + if (chat_protocol_find(name) != NULL) + return; + + rec = g_new0(PROTOCOL_REC, 1); + rec->id = ++id_counter; + rec->name = g_strdup(name); + rec->fullname = g_strdup(fullname); + rec->chatnet = g_strdup(chatnet); + protocols = g_slist_append(protocols, rec); +} + +static void chat_protocol_destroy(PROTOCOL_REC *rec) +{ + g_return_if_fail(rec != NULL); + + protocols = g_slist_remove(protocols, rec); + + g_free(rec->name); + g_free(rec->fullname); + g_free(rec->chatnet); + g_free(rec); +} + +/* Unregister chat protocol. */ +void chat_protocol_unregister(const char *name) +{ + PROTOCOL_REC *rec; + + g_return_if_fail(name != NULL); + + rec = chat_protocol_find(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 name for the specified chat protocol ID. */ +const char *chat_protocol_get_name(int id) +{ + PROTOCOL_REC *rec; + + g_return_val_if_fail(id > 0, NULL); + + rec = chat_protocol_find_id(id); + return rec == NULL ? NULL : rec->name; +} + +/* Return the full name for the specified chat protocol ID. */ +const char *chat_protocol_get_fullname(int id) +{ + PROTOCOL_REC *rec; + + g_return_val_if_fail(id > 0, NULL); + + rec = chat_protocol_find_id(id); + return rec == NULL ? NULL : rec->fullname; +} + +/* Return the chatnet identifier name for the specified chat protocol ID. */ +const char *chat_protocol_get_chatnet(int id) +{ + PROTOCOL_REC *rec; + + g_return_val_if_fail(id > 0, NULL); + + rec = chat_protocol_find_id(id); + return rec == NULL ? NULL : rec->chatnet; +} + +void chat_protocols_init(void) +{ + id_counter = 0; + protocols = NULL; +} + +void chat_protocols_deinit(void) +{ + while (protocols != NULL) + chat_protocol_destroy(protocols->data); +} diff --git a/src/core/chat-protocols.h b/src/core/chat-protocols.h new file mode 100644 index 00000000..42b413cf --- /dev/null +++ b/src/core/chat-protocols.h @@ -0,0 +1,29 @@ +#ifndef __CHAT_PROTOCOLS_H +#define __CHAT_PROTOCOLS_H + +#define PROTO_CHECK_CAST(object, cast, type_field, id) \ + ((cast *) chat_protocol_check_cast(object, \ + offsetof(cast, type_field), id)) +void *chat_protocol_check_cast(void *object, int type_pos, const char *id); + +/* Register new chat protocol. */ +void chat_protocol_register(const char *name, + const char *fullname, + const char *chatnet); + +/* Unregister chat protocol. */ +void chat_protocol_unregister(const char *name); + +/* Return the ID for the specified chat protocol. */ +int chat_protocol_lookup(const char *name); +/* Return the name for the specified chat protocol ID. */ +const char *chat_protocol_get_name(int id); +/* Return the full name for the specified chat protocol ID. */ +const char *chat_protocol_get_fullname(int id); +/* Return the chatnet identifier name for the specified chat protocol ID. */ +const char *chat_protocol_get_chatnet(int id); + +void chat_protocols_init(void); +void chat_protocols_deinit(void); + +#endif diff --git a/src/core/chatnet-rec.h b/src/core/chatnet-rec.h index e166627a..3044643a 100644 --- a/src/core/chatnet-rec.h +++ b/src/core/chatnet-rec.h @@ -1,5 +1,5 @@ -int type; /* should always be "CHATNET" */ -int chat_type; +int type; /* module_get_uniq_id("CHATNET", 0) */ +int chat_type; /* chat_protocol_lookup(xx) */ char *name; diff --git a/src/core/core.c b/src/core/core.c index 48f4af8f..b1103f8c 100644 --- a/src/core/core.c +++ b/src/core/core.c @@ -27,6 +27,7 @@ #include "signals.h" #include "settings.h" +#include "chat-protocols.h" #include "servers.h" #include "chatnets.h" #include "commands.h" @@ -51,6 +52,7 @@ void core_init(void) settings_init(); commands_init(); + chat_protocols_init(); chatnets_init(); servers_init(); log_init(); @@ -73,6 +75,7 @@ void core_deinit(void) log_deinit(); servers_deinit(); chatnets_deinit(); + chat_protocols_deinit(); commands_deinit(); settings_deinit(); diff --git a/src/core/queries.c b/src/core/queries.c index 17a371f9..f3e59184 100644 --- a/src/core/queries.c +++ b/src/core/queries.c @@ -84,7 +84,7 @@ static QUERY_REC *query_find_server(SERVER_REC *server, const char *nick) for (tmp = server->queries; tmp != NULL; tmp = tmp->next) { QUERY_REC *rec = tmp->data; - if (rec->chat_type == server->query_type && + if (rec->chat_type == server->chat_type && g_strcasecmp(nick, rec->name) == 0) return rec; } diff --git a/src/core/server-connect-rec.h b/src/core/server-connect-rec.h index 863235de..eea6739b 100644 --- a/src/core/server-connect-rec.h +++ b/src/core/server-connect-rec.h @@ -1,7 +1,7 @@ /* SERVER_CONNECT_REC definition, used for inheritance */ -int type; -int chat_type; +int type; /* module_get_uniq_id("SERVER CONNECT", 0) */ +int chat_type; /* chat_protocol_lookup(xx) */ /* if we're connecting via proxy, or just NULLs */ char *proxy; diff --git a/src/core/server-rec.h b/src/core/server-rec.h index 8aaabed2..61aaa2d8 100644 --- a/src/core/server-rec.h +++ b/src/core/server-rec.h @@ -1,7 +1,7 @@ /* SERVER_REC definition, used for inheritance */ -int type; /* should always be "SERVER" */ -int chat_type; +int type; /* module_get_uniq_id("SERVER", 0) */ +int chat_type; /* chat_protocol_lookup(xx) */ STRUCT_SERVER_CONNECT_REC *connrec; time_t connect_time; /* connection time */ @@ -42,9 +42,6 @@ GSList *queries; /* support for multiple server types */ void *channel_find_func; void *query_find_func; -int channel_type; -int query_type; - void *mask_match_func; #undef STRUCT_SERVER_CONNECT_REC diff --git a/src/core/server-setup-rec.h b/src/core/server-setup-rec.h index 5158780d..5e6edb7f 100644 --- a/src/core/server-setup-rec.h +++ b/src/core/server-setup-rec.h @@ -1,5 +1,5 @@ -int type; -int chat_type; +int type; /* module_get_uniq_id("SERVER SETUP", 0) */ +int chat_type; /* chat_protocol_lookup(xx) */ char *chatnet; diff --git a/src/core/window-item-rec.h b/src/core/window-item-rec.h index 9cbfbabe..801a471e 100644 --- a/src/core/window-item-rec.h +++ b/src/core/window-item-rec.h @@ -1,7 +1,7 @@ /* WI_ITEM_REC definition, used for inheritance */ -int type; /* window item type - channel/query/.. */ -int chat_type; /* chat server type - irc/silc/.. */ +int type; /* module_get_uniq_id("CHANNEL/QUERY/xxx", 0) */ +int chat_type; /* chat_protocol_lookup(xx) */ GHashTable *module_data; STRUCT_SERVER_REC *server; |