forked from PsychoticNinja/irssi
mess with server ports
This commit is contained in:
parent
4001871552
commit
49903f4185
@ -457,7 +457,7 @@ static SERVER_SETUP_REC *server_setup_read(CONFIG_NODE *node)
|
|||||||
port = config_node_get_int(node, "port", 0);
|
port = config_node_get_int(node, "port", 0);
|
||||||
chatnet = config_node_get_str(node, "chatnet", NULL);
|
chatnet = config_node_get_str(node, "chatnet", NULL);
|
||||||
|
|
||||||
if (server_setup_find(server, port, chatnet) != NULL) {
|
if ((rec = server_setup_find(server, port, chatnet)) != NULL && rec->port == port) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -548,7 +548,7 @@ static int compare_server_setup (CONFIG_NODE *node, SERVER_SETUP_REC *server)
|
|||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
address = config_node_get_str(node, "address", NULL);
|
address = config_node_get_str(node, "address", NULL);
|
||||||
chatnet = config_node_get_str(node, "chatnet", NULL);
|
chatnet = config_node_get_str(node, "chatnet", "");
|
||||||
port = config_node_get_int(node, "port", 0);
|
port = config_node_get_int(node, "port", 0);
|
||||||
|
|
||||||
if (address == NULL || chatnet == NULL) {
|
if (address == NULL || chatnet == NULL) {
|
||||||
@ -556,7 +556,7 @@ static int compare_server_setup (CONFIG_NODE *node, SERVER_SETUP_REC *server)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (g_ascii_strcasecmp(address, server->address) != 0 ||
|
if (g_ascii_strcasecmp(address, server->address) != 0 ||
|
||||||
g_ascii_strcasecmp(chatnet, server->chatnet) != 0 ||
|
g_ascii_strcasecmp(chatnet, server->chatnet != NULL ? server->chatnet : "") != 0 ||
|
||||||
port != server->port) {
|
port != server->port) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -564,16 +564,20 @@ static int compare_server_setup (CONFIG_NODE *node, SERVER_SETUP_REC *server)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void server_setup_save(SERVER_SETUP_REC *rec)
|
static void server_setup_save(SERVER_SETUP_REC *rec, int old_port, const char *old_chatnet)
|
||||||
{
|
{
|
||||||
CONFIG_NODE *parent_node, *node;
|
CONFIG_NODE *parent_node, *node;
|
||||||
|
SERVER_SETUP_REC search_rec = { 0 };
|
||||||
GSList *config_node;
|
GSList *config_node;
|
||||||
|
|
||||||
parent_node = iconfig_node_traverse("(servers", TRUE);
|
parent_node = iconfig_node_traverse("(servers", TRUE);
|
||||||
|
|
||||||
/* Try to find this channel in the configuration */
|
/* Try to find this channel in the configuration */
|
||||||
config_node = g_slist_find_custom(parent_node->value, rec,
|
search_rec.address = rec->address;
|
||||||
(GCompareFunc)compare_server_setup);
|
search_rec.chatnet = old_chatnet != NULL ? (char *) old_chatnet : rec->chatnet;
|
||||||
|
search_rec.port = old_port;
|
||||||
|
config_node = g_slist_find_custom(parent_node->value, &search_rec,
|
||||||
|
(GCompareFunc) compare_server_setup);
|
||||||
if (config_node != NULL)
|
if (config_node != NULL)
|
||||||
/* Let's update this server record */
|
/* Let's update this server record */
|
||||||
node = config_node->data;
|
node = config_node->data;
|
||||||
@ -654,16 +658,23 @@ static void server_setup_destroy(SERVER_SETUP_REC *rec)
|
|||||||
g_free(rec);
|
g_free(rec);
|
||||||
}
|
}
|
||||||
|
|
||||||
void server_setup_add(SERVER_SETUP_REC *rec)
|
void server_setup_modify(SERVER_SETUP_REC *rec, int old_port, const char *old_chatnet)
|
||||||
{
|
{
|
||||||
|
g_return_if_fail(g_slist_find(setupservers, rec) != NULL);
|
||||||
|
|
||||||
rec->type = module_get_uniq_id("SERVER SETUP", 0);
|
rec->type = module_get_uniq_id("SERVER SETUP", 0);
|
||||||
if (g_slist_find(setupservers, rec) == NULL)
|
server_setup_save(rec, old_port, old_chatnet);
|
||||||
setupservers = g_slist_append(setupservers, rec);
|
|
||||||
server_setup_save(rec);
|
|
||||||
|
|
||||||
signal_emit("server setup updated", 1, rec);
|
signal_emit("server setup updated", 1, rec);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void server_setup_add(SERVER_SETUP_REC *rec)
|
||||||
|
{
|
||||||
|
if (g_slist_find(setupservers, rec) == NULL)
|
||||||
|
setupservers = g_slist_append(setupservers, rec);
|
||||||
|
server_setup_modify(rec, -1, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
void server_setup_remove_chatnet(const char *chatnet)
|
void server_setup_remove_chatnet(const char *chatnet)
|
||||||
{
|
{
|
||||||
GSList *tmp, *next;
|
GSList *tmp, *next;
|
||||||
|
@ -41,6 +41,7 @@ SERVER_SETUP_REC *server_setup_find(const char *address, int port,
|
|||||||
const char *chatnet);
|
const char *chatnet);
|
||||||
|
|
||||||
void server_setup_add(SERVER_SETUP_REC *rec);
|
void server_setup_add(SERVER_SETUP_REC *rec);
|
||||||
|
void server_setup_modify(SERVER_SETUP_REC *rec, int old_port, const char *old_chatnet);
|
||||||
void server_setup_remove(SERVER_SETUP_REC *rec);
|
void server_setup_remove(SERVER_SETUP_REC *rec);
|
||||||
|
|
||||||
/* Remove servers attached to chatne */
|
/* Remove servers attached to chatne */
|
||||||
|
@ -110,11 +110,11 @@ static SERVER_SETUP_REC *create_server_setup(GHashTable *optlist)
|
|||||||
static void cmd_server_add_modify(const char *data, gboolean add)
|
static void cmd_server_add_modify(const char *data, gboolean add)
|
||||||
{
|
{
|
||||||
GHashTable *optlist;
|
GHashTable *optlist;
|
||||||
SERVER_SETUP_REC *rec;
|
SERVER_SETUP_REC *rec, *tmp;
|
||||||
char *addr, *portstr, *password, *value, *chatnet;
|
char *addr, *portstr, *password, *value, *chatnet, *old_chatnet;
|
||||||
void *free_arg;
|
void *free_arg;
|
||||||
gboolean newrec;
|
gboolean newrec;
|
||||||
int port;
|
int port, old_port, add_port;
|
||||||
|
|
||||||
if (!cmd_get_params(data, &free_arg, 3 | PARAM_FLAG_OPTIONS,
|
if (!cmd_get_params(data, &free_arg, 3 | PARAM_FLAG_OPTIONS,
|
||||||
"server add", &optlist, &addr, &portstr, &password))
|
"server add", &optlist, &addr, &portstr, &password))
|
||||||
@ -122,27 +122,39 @@ static void cmd_server_add_modify(const char *data, gboolean add)
|
|||||||
|
|
||||||
if (*addr == '\0') cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);
|
if (*addr == '\0') cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);
|
||||||
|
|
||||||
value = g_hash_table_lookup(optlist, "port");
|
port = old_port = -1;
|
||||||
|
|
||||||
if (*portstr != '\0')
|
if (*portstr != '\0')
|
||||||
port = atoi(portstr);
|
port = add_port = atoi(portstr);
|
||||||
else if (value != NULL && *value != '\0')
|
|
||||||
port = atoi(value);
|
|
||||||
else if (g_hash_table_lookup(optlist, "tls") ||
|
else if (g_hash_table_lookup(optlist, "tls") ||
|
||||||
g_hash_table_lookup(optlist, "ssl"))
|
g_hash_table_lookup(optlist, "ssl"))
|
||||||
port = DEFAULT_SERVER_ADD_TLS_PORT;
|
add_port = DEFAULT_SERVER_ADD_TLS_PORT;
|
||||||
else
|
else
|
||||||
port = DEFAULT_SERVER_ADD_PORT;
|
add_port = DEFAULT_SERVER_ADD_PORT;
|
||||||
|
|
||||||
|
value = g_hash_table_lookup(optlist, "port");
|
||||||
|
if (value != NULL && *value != '\0')
|
||||||
|
old_port = atoi(value);
|
||||||
|
|
||||||
chatnet = g_hash_table_lookup(optlist, "network");
|
chatnet = g_hash_table_lookup(optlist, "network");
|
||||||
|
|
||||||
rec = server_setup_find(addr, port, chatnet);
|
rec = server_setup_find(addr, old_port != -1 ? old_port : add_port, chatnet);
|
||||||
|
if (old_port == -1 && rec != NULL)
|
||||||
|
old_port = rec->port;
|
||||||
|
|
||||||
if (rec == NULL) {
|
if (port == -1)
|
||||||
|
port = old_port != -1 ? old_port : add_port;
|
||||||
|
|
||||||
|
/* make sure the new port doesn't exist */
|
||||||
|
tmp = server_setup_find(addr, port, chatnet);
|
||||||
|
if (tmp != NULL && tmp->port == port)
|
||||||
|
rec = tmp;
|
||||||
|
|
||||||
|
if (rec == NULL || (rec->port != old_port && rec->port != port)) {
|
||||||
newrec = TRUE;
|
newrec = TRUE;
|
||||||
if (add == FALSE) {
|
if (add == FALSE) {
|
||||||
printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE,
|
printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, TXT_SETUPSERVER_NOT_FOUND,
|
||||||
TXT_SETUPSERVER_NOT_FOUND, addr, port);
|
addr, old_port == -1 ? port : old_port);
|
||||||
cmd_params_free(free_arg);
|
cmd_params_free(free_arg);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -156,7 +168,8 @@ static void cmd_server_add_modify(const char *data, gboolean add)
|
|||||||
rec->port = port;
|
rec->port = port;
|
||||||
} else {
|
} else {
|
||||||
newrec = FALSE;
|
newrec = FALSE;
|
||||||
if (*portstr != '\0' || g_hash_table_lookup(optlist, "port"))
|
old_chatnet = g_strdup(rec->chatnet);
|
||||||
|
old_port = rec->port;
|
||||||
rec->port = port;
|
rec->port = port;
|
||||||
|
|
||||||
if (*password != '\0') g_free_and_null(rec->password);
|
if (*password != '\0') g_free_and_null(rec->password);
|
||||||
@ -261,7 +274,13 @@ static void cmd_server_add_modify(const char *data, gboolean add)
|
|||||||
|
|
||||||
signal_emit("server add fill", 3, rec, optlist, GINT_TO_POINTER(add));
|
signal_emit("server add fill", 3, rec, optlist, GINT_TO_POINTER(add));
|
||||||
|
|
||||||
|
if (newrec) {
|
||||||
server_setup_add(rec);
|
server_setup_add(rec);
|
||||||
|
} else {
|
||||||
|
server_setup_modify(rec, old_port, old_chatnet);
|
||||||
|
g_free(old_chatnet);
|
||||||
|
}
|
||||||
|
|
||||||
printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE,
|
printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE,
|
||||||
TXT_SETUPSERVER_ADDED, addr, port);
|
TXT_SETUPSERVER_ADDED, addr, port);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user