mirror of
https://github.com/irssi/irssi.git
synced 2024-12-04 14:46:39 -05:00
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
This commit is contained in:
parent
8c2799b5f8
commit
c1a191955b
@ -19,15 +19,11 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "module.h"
|
#include "module.h"
|
||||||
|
#include "signals.h"
|
||||||
#include "chat-protocols.h"
|
#include "chat-protocols.h"
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
int id;
|
|
||||||
CHAT_PROTOCOL_REC *rec;
|
|
||||||
} PROTOCOL_REC;
|
|
||||||
|
|
||||||
static int id_counter;
|
static int id_counter;
|
||||||
static GSList *protocols;
|
GSList *chat_protocols;
|
||||||
|
|
||||||
void *chat_protocol_check_cast(void *object, int type_pos, const char *id)
|
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;
|
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;
|
GSList *tmp;
|
||||||
|
|
||||||
g_return_val_if_fail(name != NULL, NULL);
|
g_return_val_if_fail(name != NULL, NULL);
|
||||||
|
|
||||||
for (tmp = protocols; tmp != NULL; tmp = tmp->next) {
|
for (tmp = chat_protocols; tmp != NULL; tmp = tmp->next) {
|
||||||
PROTOCOL_REC *rec = tmp->data;
|
CHAT_PROTOCOL_REC *rec = tmp->data;
|
||||||
|
|
||||||
if (g_strcasecmp(rec->rec->name, name) == 0)
|
if (g_strcasecmp(rec->name, name) == 0)
|
||||||
return rec;
|
return rec;
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static PROTOCOL_REC *chat_protocol_find_id(int id)
|
CHAT_PROTOCOL_REC *chat_protocol_find_id(int id)
|
||||||
{
|
{
|
||||||
GSList *tmp;
|
GSList *tmp;
|
||||||
|
|
||||||
g_return_val_if_fail(id > 0, NULL);
|
g_return_val_if_fail(id > 0, NULL);
|
||||||
|
|
||||||
for (tmp = protocols; tmp != NULL; tmp = tmp->next) {
|
for (tmp = chat_protocols; tmp != NULL; tmp = tmp->next) {
|
||||||
PROTOCOL_REC *rec = tmp->data;
|
CHAT_PROTOCOL_REC *rec = tmp->data;
|
||||||
|
|
||||||
if (rec->id == id)
|
if (rec->id == id)
|
||||||
return rec;
|
return rec;
|
||||||
@ -71,32 +78,30 @@ static PROTOCOL_REC *chat_protocol_find_id(int id)
|
|||||||
/* Register new chat protocol. */
|
/* Register new chat protocol. */
|
||||||
void chat_protocol_register(CHAT_PROTOCOL_REC *rec)
|
void chat_protocol_register(CHAT_PROTOCOL_REC *rec)
|
||||||
{
|
{
|
||||||
PROTOCOL_REC *proto;
|
|
||||||
|
|
||||||
g_return_if_fail(rec != NULL);
|
g_return_if_fail(rec != NULL);
|
||||||
|
|
||||||
if (chat_protocol_find(rec->name) != NULL)
|
if (chat_protocol_find(rec->name) != NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
proto = g_new0(PROTOCOL_REC, 1);
|
rec->id = ++id_counter;
|
||||||
proto->id = ++id_counter;
|
chat_protocols = g_slist_append(chat_protocols, rec);
|
||||||
proto->rec = rec;
|
|
||||||
protocols = g_slist_append(protocols, proto);
|
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);
|
g_return_if_fail(rec != NULL);
|
||||||
|
|
||||||
protocols = g_slist_remove(protocols, rec);
|
chat_protocols = g_slist_remove(chat_protocols, rec);
|
||||||
g_free(rec->rec);
|
signal_emit("chat protocol destroyed", 1, rec);
|
||||||
g_free(rec);
|
g_free(rec);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Unregister chat protocol. */
|
/* Unregister chat protocol. */
|
||||||
void chat_protocol_unregister(const char *name)
|
void chat_protocol_unregister(const char *name)
|
||||||
{
|
{
|
||||||
PROTOCOL_REC *rec;
|
CHAT_PROTOCOL_REC *rec;
|
||||||
|
|
||||||
g_return_if_fail(name != NULL);
|
g_return_if_fail(name != NULL);
|
||||||
|
|
||||||
@ -104,36 +109,14 @@ void chat_protocol_unregister(const char *name)
|
|||||||
if (rec != NULL) chat_protocol_destroy(rec);
|
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)
|
void chat_protocols_init(void)
|
||||||
{
|
{
|
||||||
id_counter = 0;
|
id_counter = 0;
|
||||||
protocols = NULL;
|
chat_protocols = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void chat_protocols_deinit(void)
|
void chat_protocols_deinit(void)
|
||||||
{
|
{
|
||||||
while (protocols != NULL)
|
while (chat_protocols != NULL)
|
||||||
chat_protocol_destroy(protocols->data);
|
chat_protocol_destroy(chat_protocols->data);
|
||||||
}
|
}
|
||||||
|
@ -2,11 +2,15 @@
|
|||||||
#define __CHAT_PROTOCOLS_H
|
#define __CHAT_PROTOCOLS_H
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
int id;
|
||||||
|
|
||||||
char *name;
|
char *name;
|
||||||
char *fullname;
|
char *fullname;
|
||||||
char *chatnet;
|
char *chatnet;
|
||||||
} CHAT_PROTOCOL_REC;
|
} CHAT_PROTOCOL_REC;
|
||||||
|
|
||||||
|
extern GSList *chat_protocols;
|
||||||
|
|
||||||
#define PROTO_CHECK_CAST(object, cast, type_field, id) \
|
#define PROTO_CHECK_CAST(object, cast, type_field, id) \
|
||||||
((cast *) chat_protocol_check_cast(object, \
|
((cast *) chat_protocol_check_cast(object, \
|
||||||
offsetof(cast, type_field), id))
|
offsetof(cast, type_field), id))
|
||||||
@ -18,10 +22,10 @@ void chat_protocol_register(CHAT_PROTOCOL_REC *rec);
|
|||||||
/* Unregister chat protocol. */
|
/* Unregister chat protocol. */
|
||||||
void chat_protocol_unregister(const char *name);
|
void chat_protocol_unregister(const char *name);
|
||||||
|
|
||||||
/* Return the ID for the specified chat protocol. */
|
/* Find functions */
|
||||||
int chat_protocol_lookup(const char *name);
|
int chat_protocol_lookup(const char *name);
|
||||||
/* Return the record for the specified chat protocol ID. */
|
CHAT_PROTOCOL_REC *chat_protocol_find(const char *name);
|
||||||
CHAT_PROTOCOL_REC *chat_protocol_get_rec(int id);
|
CHAT_PROTOCOL_REC *chat_protocol_find_id(int id);
|
||||||
|
|
||||||
void chat_protocols_init(void);
|
void chat_protocols_init(void);
|
||||||
void chat_protocols_deinit(void);
|
void chat_protocols_deinit(void);
|
||||||
|
@ -238,22 +238,26 @@ char *module_get_name(const char *path)
|
|||||||
|
|
||||||
GModule *module_open(const char *name)
|
GModule *module_open(const char *name)
|
||||||
{
|
{
|
||||||
|
struct stat statbuf;
|
||||||
GModule *module;
|
GModule *module;
|
||||||
char *path, *str;
|
char *path, *str;
|
||||||
|
|
||||||
if (g_path_is_absolute(name))
|
if (g_path_is_absolute(name))
|
||||||
path = g_strdup(name);
|
path = g_strdup(name);
|
||||||
else {
|
else {
|
||||||
path = g_module_build_path(MODULEDIR, name);
|
/* first try from home dir */
|
||||||
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 */
|
|
||||||
str = g_strdup_printf("%s/.irssi/modules", g_get_home_dir());
|
str = g_strdup_printf("%s/.irssi/modules", g_get_home_dir());
|
||||||
path = g_module_build_path(str, name);
|
path = g_module_build_path(str, name);
|
||||||
g_free(str);
|
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);
|
module = g_module_open(path, 0);
|
||||||
|
@ -102,7 +102,7 @@ static void cmd_server_add(const char *data)
|
|||||||
signal_emit("server add create", 2, &rec, optlist);
|
signal_emit("server add create", 2, &rec, optlist);
|
||||||
if (rec == NULL) {
|
if (rec == NULL) {
|
||||||
/* no chatnet option specified, use the first. */
|
/* 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);
|
signal_emit("server add create", 2, &rec, optlist);
|
||||||
if (rec == NULL) {
|
if (rec == NULL) {
|
||||||
/* bug? */
|
/* bug? */
|
||||||
|
@ -130,7 +130,7 @@ static void window_save_items(WINDOW_REC *window, CONFIG_NODE *node)
|
|||||||
subnode = config_node_section(node, NULL, NODE_TYPE_BLOCK);
|
subnode = config_node_section(node, NULL, NODE_TYPE_BLOCK);
|
||||||
|
|
||||||
iconfig_node_set_str(subnode, "type", type);
|
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, "chat_type", type);
|
||||||
iconfig_node_set_str(subnode, "name", rec->name);
|
iconfig_node_set_str(subnode, "name", rec->name);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user