summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTimo Sirainen <cras@irssi.org>2000-08-30 22:29:55 +0000
committercras <cras@dbcabf3a-b0e7-0310-adc4-f8d773084564>2000-08-30 22:29:55 +0000
commitb4bdec4436190d7ccb6252be388b5ee70c5c36f5 (patch)
tree5b80eb0eab42f347575c05dbff3361f9955cd6ee /src
parentcf7eb945ea769b51622a1c1cbbbc7e7a6a494df9 (diff)
downloadirssi-b4bdec4436190d7ccb6252be388b5ee70c5c36f5.zip
Object type checking fixes
git-svn-id: http://svn.irssi.org/repos/irssi/trunk@638 dbcabf3a-b0e7-0310-adc4-f8d773084564
Diffstat (limited to 'src')
-rw-r--r--src/common.h1
-rw-r--r--src/core/channels.h9
-rw-r--r--src/core/chatnets.h9
-rw-r--r--src/core/modules.c6
-rw-r--r--src/core/modules.h26
-rw-r--r--src/core/queries.h9
-rw-r--r--src/core/servers-setup.h9
-rw-r--r--src/core/servers.h17
-rw-r--r--src/irc/core/irc-channels.c2
-rw-r--r--src/irc/core/irc-channels.h10
-rw-r--r--src/irc/core/irc-chatnets.h9
-rw-r--r--src/irc/core/irc-commands.c6
-rw-r--r--src/irc/core/irc-queries.h10
-rw-r--r--src/irc/core/irc-servers-setup.h10
-rw-r--r--src/irc/core/irc-servers.h20
15 files changed, 78 insertions, 75 deletions
diff --git a/src/common.h b/src/common.h
index d0e07b5a..199fb5c1 100644
--- a/src/common.h
+++ b/src/common.h
@@ -9,6 +9,7 @@
#endif
#include <stdio.h>
+#include <stddef.h>
#include <stdarg.h>
#include <ctype.h>
# ifdef HAVE_STRING_H
diff --git a/src/core/channels.h b/src/core/channels.h
index f413e658..36319701 100644
--- a/src/core/channels.h
+++ b/src/core/channels.h
@@ -3,13 +3,12 @@
#include "servers.h"
-#define IS_CHANNEL(channel) \
- ((channel) != NULL && \
- module_find_id("CHANNEL", ((CHANNEL_REC *) (channel))->type) != -1)
-
/* Returns CHANNEL_REC if it's channel, NULL if it isn't. */
#define CHANNEL(channel) \
- (IS_CHANNEL(channel) ? (CHANNEL_REC *) (channel) : NULL)
+ MODULE_CHECK_CAST(channel, CHANNEL_REC, type, "CHANNEL")
+
+#define IS_CHANNEL(channel) \
+ (CHANNEL(channel) ? TRUE : FALSE)
#define STRUCT_SERVER_REC SERVER_REC
typedef struct {
diff --git a/src/core/chatnets.h b/src/core/chatnets.h
index 724421cf..7170c478 100644
--- a/src/core/chatnets.h
+++ b/src/core/chatnets.h
@@ -3,13 +3,12 @@
#include "modules.h"
-#define IS_CHATNET(chatnet) \
- ((chatnet) != NULL && \
- module_find_id("CHATNET", (chatnet)->type) != -1)
-
/* Returns CHATNET_REC if it's chatnet, NULL if it isn't. */
#define CHATNET(chatnet) \
- (IS_CHATNET(chatnet) ? (CHATNET_REC *) (chatnet) : NULL)
+ MODULE_CHECK_CAST(chatnet, CHATNET_REC, type, "CHATNET")
+
+#define IS_CHATNET(chatnet) \
+ (CHATNET(chatnet) ? TRUE : FALSE)
typedef struct {
#include "chatnet-rec.h"
diff --git a/src/core/modules.c b/src/core/modules.c
index fc10487d..85e19f2c 100644
--- a/src/core/modules.c
+++ b/src/core/modules.c
@@ -28,6 +28,12 @@ static GHashTable *uniqids, *uniqstrids;
static GHashTable *idlookup, *stridlookup;
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 unique number across all modules for `id' */
int module_get_uniq_id(const char *module, int id)
{
diff --git a/src/core/modules.h b/src/core/modules.h
index 6ced5387..118e790c 100644
--- a/src/core/modules.h
+++ b/src/core/modules.h
@@ -1,6 +1,18 @@
#ifndef __MODULES_H
#define __MODULES_H
+#define MODULE_DATA_INIT(rec) \
+ (rec)->module_data = g_hash_table_new(g_str_hash, g_str_equal)
+
+#define MODULE_DATA_DEINIT(rec) \
+ g_hash_table_destroy((rec)->module_data)
+
+#define MODULE_DATA_SET(rec, data) \
+ g_hash_table_insert((rec)->module_data, MODULE_NAME, data)
+
+#define MODULE_DATA(rec) \
+ g_hash_table_lookup((rec)->module_data, MODULE_NAME)
+
enum {
MODULE_ERROR_ALREADY_LOADED,
MODULE_ERROR_LOAD,
@@ -19,17 +31,9 @@ MODULE_REC *module_find(const char *name);
int module_load(const char *path);
void module_unload(MODULE_REC *module);
-#define MODULE_DATA_INIT(rec) \
- (rec)->module_data = g_hash_table_new(g_str_hash, g_str_equal)
-
-#define MODULE_DATA_DEINIT(rec) \
- g_hash_table_destroy((rec)->module_data)
-
-#define MODULE_DATA_SET(rec, data) \
- g_hash_table_insert((rec)->module_data, MODULE_NAME, data)
-
-#define MODULE_DATA(rec) \
- g_hash_table_lookup((rec)->module_data, MODULE_NAME)
+#define MODULE_CHECK_CAST(object, cast, type_field, id) \
+ ((cast *) module_check_cast(object, offsetof(cast, type_field), id))
+void *module_check_cast(void *object, int type_pos, 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.h b/src/core/queries.h
index 106b4ca7..5fbe543e 100644
--- a/src/core/queries.h
+++ b/src/core/queries.h
@@ -3,13 +3,12 @@
#include "servers.h"
-#define IS_QUERY(query) \
- ((query) != NULL && \
- module_find_id("QUERY", ((QUERY_REC *) (query))->type) != -1)
-
/* Returns QUERY_REC if it's query, NULL if it isn't. */
#define QUERY(query) \
- (IS_QUERY(query) ? (QUERY_REC *) (query) : NULL)
+ MODULE_CHECK_CAST(query, QUERY_REC, type, "QUERY")
+
+#define IS_QUERY(query) \
+ (QUERY(query) ? TRUE : FALSE)
#define STRUCT_SERVER_REC SERVER_REC
typedef struct {
diff --git a/src/core/servers-setup.h b/src/core/servers-setup.h
index 247189ff..4b22c542 100644
--- a/src/core/servers-setup.h
+++ b/src/core/servers-setup.h
@@ -3,12 +3,11 @@
#include "servers.h"
-#define IS_SERVER_SETUP(server) \
- ((server) != NULL && \
- module_find_id("SERVER SETUP", (server)->type) != -1)
-
#define SERVER_SETUP(server) \
- (IS_SERVER_SETUP(server) ? (SERVER_SETUP_REC *) (server) : NULL)
+ MODULE_CHECK_CAST(server, SERVER_SETUP_REC, type, "SERVER SETUP")
+
+#define IS_SERVER_SETUP(server) \
+ (SERVER_SETUP(server) ? TRUE : FALSE)
/* servers */
typedef struct {
diff --git a/src/core/servers.h b/src/core/servers.h
index 169c8e88..25f6ef5e 100644
--- a/src/core/servers.h
+++ b/src/core/servers.h
@@ -7,20 +7,19 @@
typedef struct _ipaddr IPADDR;
#endif
-#define IS_SERVER(server) \
- ((server) != NULL && module_find_id("SERVER", (server)->type) != -1)
-
-#define IS_SERVER_CONNECT(conn) \
- ((conn) != NULL && \
- module_find_id("SERVER CONNECT", (conn)->type) != -1)
-
/* Returns SERVER_REC if it's server, NULL if it isn't. */
#define SERVER(server) \
- (IS_SERVER(server) ? (SERVER_REC *) (server) : NULL)
+ MODULE_CHECK_CAST(server, SERVER_REC, type, "SERVER")
/* Returns SERVER_CONNECT_REC if it's server connection, NULL if it isn't. */
#define SERVER_CONNECT(conn) \
- (IS_SERVER_CONNECT(conn) ? (SERVER_CONNECT_REC *) (conn) : NULL)
+ MODULE_CHECK_CAST(conn, SERVER_CONNECT_REC, type, "SERVER CONNECT")
+
+#define IS_SERVER(server) \
+ (SERVER(server) ? TRUE : FALSE)
+
+#define IS_SERVER_CONNECT(conn) \
+ (SERVER_CONNECT(conn) ? TRUE : FALSE)
/* all strings should be either NULL or dynamically allocated */
/* address and nick are mandatory, rest are optional */
diff --git a/src/irc/core/irc-channels.c b/src/irc/core/irc-channels.c
index ba44a7d5..de0822bd 100644
--- a/src/irc/core/irc-channels.c
+++ b/src/irc/core/irc-channels.c
@@ -181,6 +181,7 @@ static void sig_connected(SERVER_REC *server)
void irc_channels_init(void)
{
signal_add("server connected", (SIGNAL_FUNC) sig_connected);
+ signal_add("channel destroyed", (SIGNAL_FUNC) sig_channel_destroyed);
channel_events_init();
channel_rejoin_init();
@@ -197,6 +198,7 @@ void irc_channels_init(void)
void irc_channels_deinit(void)
{
signal_remove("server connected", (SIGNAL_FUNC) sig_connected);
+ signal_remove("channel destroyed", (SIGNAL_FUNC) sig_channel_destroyed);
channel_events_deinit();
channel_rejoin_deinit();
diff --git a/src/irc/core/irc-channels.h b/src/irc/core/irc-channels.h
index 9a331082..b4040bf5 100644
--- a/src/irc/core/irc-channels.h
+++ b/src/irc/core/irc-channels.h
@@ -4,14 +4,12 @@
#include "channels.h"
#include "irc-servers.h"
-#define IS_IRC_CHANNEL(channel) \
- ((channel) != NULL && \
- module_find_id("IRC CHANNEL", \
- ((IRC_CHANNEL_REC *) (channel))->chat_type) != -1)
-
/* Returns IRC_CHANNEL_REC if it's IRC channel, NULL if it isn't. */
#define IRC_CHANNEL(channel) \
- (IS_IRC_CHANNEL(channel) ? (IRC_CHANNEL_REC *) (channel) : NULL)
+ MODULE_CHECK_CAST(channel, IRC_CHANNEL_REC, chat_type, "IRC CHANNEL")
+
+#define IS_IRC_CHANNEL(channel) \
+ (IRC_CHANNEL(channel) ? TRUE : FALSE)
#define STRUCT_SERVER_REC IRC_SERVER_REC
typedef struct {
diff --git a/src/irc/core/irc-chatnets.h b/src/irc/core/irc-chatnets.h
index 25ce05e8..151bca8e 100644
--- a/src/irc/core/irc-chatnets.h
+++ b/src/irc/core/irc-chatnets.h
@@ -1,13 +1,14 @@
#ifndef __IRC_CHATNETS_H
#define __IRC_CHATNETS_H
-#define IS_IRC_CHATNET(chatnet) \
- ((chatnet) != NULL && \
- module_find_id("IRC CHATNET", (chatnet)->chat_type) != -1)
+#include "modules.h"
/* returns IRC_CHATNET_REC if it's IRC network, NULL if it isn't */
#define IRC_CHATNET(chatnet) \
- (IS_IRC_CHATNET(chatnet) ? (IRC_CHATNET_REC *) (chatnet) : NULL)
+ MODULE_CHECK_CAST(chatnet, IRC_CHATNET_REC, chat_type, "IRC CHATNET")
+
+#define IS_IRC_CHATNET(chatnet) \
+ (IRC_CHATNET(chatnet) ? TRUE : FALSE)
#define IS_IRCNET(ircnet) IS_IRC_CHATNET(ircnet)
#define IRCNET(ircnet) IRC_CHATNET(ircnet)
diff --git a/src/irc/core/irc-commands.c b/src/irc/core/irc-commands.c
index 860e4737..c5d91ef6 100644
--- a/src/irc/core/irc-commands.c
+++ b/src/irc/core/irc-commands.c
@@ -86,7 +86,7 @@ IRC_SERVER_REC *irccmd_options_get_server(const char *cmd,
return (IRC_SERVER_REC *) server;
}
-static SERVER_REC *connect_server(const char *data)
+static SERVER_REC *irc_connect_server(const char *data)
{
SERVER_CONNECT_REC *conn;
SERVER_REC *server;
@@ -137,7 +137,7 @@ static SERVER_REC *connect_server(const char *data)
static void cmd_connect(const char *data)
{
if (*data == '\0') cmd_return_error(CMDERR_NOT_ENOUGH_PARAMS);
- connect_server(data);
+ irc_connect_server(data);
}
@@ -202,7 +202,7 @@ static void cmd_server(const char *data, IRC_SERVER_REC *server)
cmd_disconnect("* Changing server", server);
}
- server = IRC_SERVER(connect_server(data));
+ server = IRC_SERVER(irc_connect_server(data));
if (*addr == '+' || server == NULL ||
(ircnet != NULL && server->connrec->chatnet != NULL &&
g_strcasecmp(ircnet, server->connrec->chatnet) != 0)) {
diff --git a/src/irc/core/irc-queries.h b/src/irc/core/irc-queries.h
index 5c2725ac..c217c9be 100644
--- a/src/irc/core/irc-queries.h
+++ b/src/irc/core/irc-queries.h
@@ -4,14 +4,12 @@
#include "queries.h"
#include "irc-servers.h"
-#define IS_IRC_QUERY(query) \
- ((query) != NULL && \
- module_find_id("IRC QUERY", \
- ((QUERY_REC *) (query))->chat_type) != -1)
-
/* Returns IRC_QUERY_REC if it's IRC query, NULL if it isn't. */
#define IRC_QUERY(query) \
- (IS_IRC_QUERY(query) ? (QUERY_REC *) (query) : NULL)
+ MODULE_CHECK_CAST(query, QUERY_REC, chat_type, "IRC QUERY")
+
+#define IS_IRC_QUERY(query) \
+ (IRC_QUERY(query) ? TRUE : FALSE)
void irc_queries_init(void);
void irc_queries_deinit(void);
diff --git a/src/irc/core/irc-servers-setup.h b/src/irc/core/irc-servers-setup.h
index f29f55c0..818611fe 100644
--- a/src/irc/core/irc-servers-setup.h
+++ b/src/irc/core/irc-servers-setup.h
@@ -1,13 +1,13 @@
#ifndef __IRC_SERVERS_SETUP_H
#define __IRC_SERVERS_SETUP_H
-#define IS_IRC_SERVER_SETUP(server) \
- ((server) != NULL && \
- module_find_id("IRC SERVER SETUP", (server)->chat_type) != -1)
#define IRC_SERVER_SETUP(server) \
- (IS_IRC_SERVER_SETUP(server) ? \
- (IRC_SERVER_SETUP_REC *) (server) : NULL)
+ MODULE_CHECK_CAST(server, IRC_SERVER_SETUP_REC, \
+ chat_type, "IRC SERVER SETUP")
+
+#define IS_IRC_SERVER_SETUP(server) \
+ (IRC_SERVER_SETUP(server) ? TRUE : FALSE)
typedef struct {
#include "server-setup-rec.h"
diff --git a/src/irc/core/irc-servers.h b/src/irc/core/irc-servers.h
index 9199a698..e1fd333d 100644
--- a/src/irc/core/irc-servers.h
+++ b/src/irc/core/irc-servers.h
@@ -3,21 +3,19 @@
#include "servers.h"
-#define IS_IRC_SERVER(server) \
- ((server) != NULL && \
- module_find_id("IRC SERVER", (server)->chat_type) != -1)
-
-#define IS_IRC_SERVER_CONNECT(conn) \
- ((conn) != NULL && \
- module_find_id("IRC SERVER CONNECT", (conn)->chat_type) != -1)
-
/* returns IRC_SERVER_REC if it's IRC server, NULL if it isn't */
#define IRC_SERVER(server) \
- (IS_IRC_SERVER(server) ? (IRC_SERVER_REC *) (server) : NULL)
+ MODULE_CHECK_CAST(server, IRC_SERVER_REC, chat_type, "IRC SERVER")
#define IRC_SERVER_CONNECT(conn) \
- (IS_IRC_SERVER_CONNECT(conn) ? \
- (IRC_SERVER_CONNECT_REC *) (conn) : NULL)
+ MODULE_CHECK_CAST(conn, IRC_SERVER_CONNECT_REC, \
+ chat_type, "IRC SERVER CONNECT")
+
+#define IS_IRC_SERVER(server) \
+ (IRC_SERVER(server) ? TRUE : FALSE)
+
+#define IS_IRC_SERVER_CONNECT(conn) \
+ (IRC_SERVER_CONNECT(conn) ? TRUE : FALSE)
/* all strings should be either NULL or dynamically allocated */
/* address and nick are mandatory, rest are optional */