mirror of
https://github.com/irssi/irssi.git
synced 2024-10-27 05:20:20 -04:00
Object type checking fixes
git-svn-id: http://svn.irssi.org/repos/irssi/trunk@638 dbcabf3a-b0e7-0310-adc4-f8d773084564
This commit is contained in:
parent
cf7eb945ea
commit
b4bdec4436
@ -9,6 +9,7 @@
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stddef.h>
|
||||
#include <stdarg.h>
|
||||
#include <ctype.h>
|
||||
# ifdef HAVE_STRING_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 {
|
||||
|
@ -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"
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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);
|
||||
|
@ -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 {
|
||||
|
@ -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 {
|
||||
|
@ -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 */
|
||||
|
@ -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();
|
||||
|
@ -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 {
|
||||
|
@ -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)
|
||||
|
@ -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)) {
|
||||
|
@ -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);
|
||||
|
@ -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"
|
||||
|
@ -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 */
|
||||
|
Loading…
Reference in New Issue
Block a user