diff options
author | Timo Sirainen <cras@irssi.org> | 2000-06-04 14:52:47 +0000 |
---|---|---|
committer | cras <cras@dbcabf3a-b0e7-0310-adc4-f8d773084564> | 2000-06-04 14:52:47 +0000 |
commit | a7f5540cba46869fda6b3da42199bb85bd6dab8b (patch) | |
tree | e769eb1a127a6706865b470273eb561f6ae72d68 /src/irc | |
parent | ee46dc71ab5fe607851bcc29f836d7f4a3d00a3e (diff) | |
download | irssi-a7f5540cba46869fda6b3da42199bb85bd6dab8b.zip |
/IRCNET command.
PARAM_FLAG_NOQUOTES flag for cmd_get_params()
git-svn-id: http://svn.irssi.org/repos/irssi/trunk@290 dbcabf3a-b0e7-0310-adc4-f8d773084564
Diffstat (limited to 'src/irc')
-rw-r--r-- | src/irc/core/ircnet-setup.c | 91 | ||||
-rw-r--r-- | src/irc/core/ircnet-setup.h | 9 | ||||
-rw-r--r-- | src/irc/core/netsplit.c | 2 | ||||
-rw-r--r-- | src/irc/core/server-setup.c | 53 | ||||
-rw-r--r-- | src/irc/dcc/dcc-files.c | 3 | ||||
-rw-r--r-- | src/irc/dcc/dcc.c | 3 |
6 files changed, 116 insertions, 45 deletions
diff --git a/src/irc/core/ircnet-setup.c b/src/irc/core/ircnet-setup.c index 8296a7e8..bd913705 100644 --- a/src/irc/core/ircnet-setup.c +++ b/src/irc/core/ircnet-setup.c @@ -29,6 +29,64 @@ GSList *ircnets; /* list of available ircnets */ +static void ircnet_config_add(IRCNET_REC *ircnet) +{ + CONFIG_NODE *node; + + node = iconfig_node_traverse("ircnets", TRUE); + iconfig_node_set_str(node, ircnet->name, NULL); + node = config_node_section(node, ircnet->name, NODE_TYPE_BLOCK); + + iconfig_node_set_str(node, "nick", ircnet->nick); + iconfig_node_set_str(node, "username", ircnet->username); + iconfig_node_set_str(node, "realname", ircnet->realname); + iconfig_node_set_str(node, "host", ircnet->own_host); + + if (ircnet->max_cmds_at_once > 0) + config_node_set_int(node, "cmdmax", ircnet->max_cmds_at_once); + if (ircnet->cmd_queue_speed > 0) + config_node_set_int(node, "cmdspeed", ircnet->cmd_queue_speed); + + if (ircnet->max_kicks > 0) + config_node_set_int(node, "max_kicks", ircnet->max_kicks); + if (ircnet->max_msgs > 0) + config_node_set_int(node, "max_msgs", ircnet->max_msgs); + if (ircnet->max_modes > 0) + config_node_set_int(node, "max_modes", ircnet->max_modes); + if (ircnet->max_whois > 0) + config_node_set_int(node, "max_whois", ircnet->max_whois); + +} + +static void ircnet_config_remove(IRCNET_REC *ircnet) +{ + CONFIG_NODE *node; + + node = iconfig_node_traverse("ircnets", FALSE); + if (node != NULL) iconfig_node_set_str(node, ircnet->name, NULL); +} + +void ircnet_create(IRCNET_REC *ircnet) +{ + if (g_slist_find(ircnets, ircnet) == NULL) + ircnets = g_slist_append(ircnets, ircnet); + + ircnet_config_add(ircnet); +} + +void ircnet_destroy(IRCNET_REC *ircnet) +{ + ircnet_config_remove(ircnet); + ircnets = g_slist_remove(ircnets, ircnet); + + g_free(ircnet->name); + g_free_not_null(ircnet->nick); + g_free_not_null(ircnet->username); + g_free_not_null(ircnet->realname); + g_free_not_null(ircnet->own_host); + g_free(ircnet); +} + /* Find the irc network by name */ IRCNET_REC *ircnet_find(const char *name) { @@ -46,42 +104,29 @@ IRCNET_REC *ircnet_find(const char *name) return NULL; } -static void ircnet_destroy(IRCNET_REC *rec) -{ - ircnets = g_slist_remove(ircnets, rec); - - g_free(rec->name); - if (rec->nick != NULL) g_free(rec->nick); - if (rec->username != NULL) g_free(rec->username); - if (rec->realname != NULL) g_free(rec->realname); - g_free(rec); -} - static IRCNET_REC *ircnet_add(CONFIG_NODE *node) { IRCNET_REC *rec; - char *name, *nick, *username, *realname; g_return_val_if_fail(node != NULL, NULL); + if (node->key == NULL) return NULL; + + rec = g_new0(IRCNET_REC, 1); - name = config_node_get_str(node, "name", NULL); - if (name == NULL) return NULL; + rec->name = g_strdup(node->key); + rec->nick = g_strdup(config_node_get_str(node, "nick", NULL)); + rec->username = g_strdup(config_node_get_str(node, "username", NULL)); + rec->realname = g_strdup(config_node_get_str(node, "realname", NULL)); + rec->own_host = g_strdup(config_node_get_str(node, "host", NULL)); - nick = config_node_get_str(node, "nick", NULL); - username = config_node_get_str(node, "username", NULL); - realname = config_node_get_str(node, "realname", NULL); + rec->max_cmds_at_once = config_node_get_int(node, "cmdmax", 0); + rec->cmd_queue_speed = config_node_get_int(node, "cmdspeed", 0); - rec = g_new0(IRCNET_REC, 1); rec->max_kicks = config_node_get_int(node, "max_kicks", 0); rec->max_msgs = config_node_get_int(node, "max_msgs", 0); rec->max_modes = config_node_get_int(node, "max_modes", 0); rec->max_whois = config_node_get_int(node, "max_whois", 0); - rec->name = g_strdup(name); - rec->nick = (nick == NULL || *nick == '\0') ? NULL : g_strdup(nick); - rec->username = (username == NULL || *username == '\0') ? NULL : g_strdup(username); - rec->realname = (realname == NULL || *realname == '\0') ? NULL : g_strdup(realname); - ircnets = g_slist_append(ircnets, rec); return rec; } diff --git a/src/irc/core/ircnet-setup.h b/src/irc/core/ircnet-setup.h index dea530fb..2b82f171 100644 --- a/src/irc/core/ircnet-setup.h +++ b/src/irc/core/ircnet-setup.h @@ -8,12 +8,21 @@ typedef struct { char *username; char *realname; + char *own_host; /* address to use when connecting this server */ + IPADDR *own_ip; /* resolved own_address if not NULL */ + + int max_cmds_at_once; + int cmd_queue_speed; + /* max. number of kicks/msgs/mode/whois per command */ int max_kicks, max_msgs, max_modes, max_whois; } IRCNET_REC; extern GSList *ircnets; /* list of available ircnets */ +void ircnet_create(IRCNET_REC *ircnet); +void ircnet_destroy(IRCNET_REC *ircnet); + /* Find the irc network by name */ IRCNET_REC *ircnet_find(const char *name); diff --git a/src/irc/core/netsplit.c b/src/irc/core/netsplit.c index 5d7d3bf3..bfa40c3c 100644 --- a/src/irc/core/netsplit.c +++ b/src/irc/core/netsplit.c @@ -203,7 +203,7 @@ int quitmsg_is_split(const char *msg) /* get the two hosts */ ok = FALSE; - params = cmd_get_params(msg, 2, &host1, &host2); + params = cmd_get_params(msg, 2 | PARAM_FLAG_NOQUOTES, &host1, &host2); if (g_strcasecmp(host1, host2) != 0) { /* hosts can't be same.. */ /* check that domain length is 2 or 3 */ p = strrchr(host1, '.'); diff --git a/src/irc/core/server-setup.c b/src/irc/core/server-setup.c index 603d7142..66c0a932 100644 --- a/src/irc/core/server-setup.c +++ b/src/irc/core/server-setup.c @@ -49,6 +49,30 @@ static void get_source_host_ip(void) } } +static void conn_set_ip(IRC_SERVER_CONNECT_REC *conn, IPADDR **own_ip, const char *own_host) +{ + IPADDR ip; + + if (*own_ip != NULL) { + /* use already resolved IP */ + if (conn->own_ip == NULL) + conn->own_ip = g_new(IPADDR, 1); + memcpy(conn->own_ip, *own_ip, sizeof(IPADDR)); + return; + } + + + /* resolve the IP and use it */ + if (net_gethostbyname(own_host, &ip) == 0) { + if (conn->own_ip == NULL) + conn->own_ip = g_new(IPADDR, 1); + memcpy(conn->own_ip, &ip, sizeof(IPADDR)); + + *own_ip = g_new(IPADDR, 1); + memcpy(*own_ip, &ip, sizeof(IPADDR)); + } +} + /* Create server connection record. `address' is required, rest can be NULL */ static IRC_SERVER_CONNECT_REC * create_addr_conn(const char *address, int port, const char *password, @@ -91,25 +115,8 @@ create_addr_conn(const char *address, int port, const char *password, sserver = server_setup_find(address, -1); if (sserver == NULL) return conn; - if (sserver->own_ip != NULL) { - /* use already resolved IP */ - if (conn->own_ip == NULL) - conn->own_ip = g_new(IPADDR, 1); - memcpy(conn->own_ip, sserver->own_ip, sizeof(IPADDR)); - } else if (sserver->own_host != NULL) { - /* resolve the IP and use it */ - IPADDR ip; - - if (net_gethostbyname(sserver->own_host, &ip) == 0) { - if (conn->own_ip == NULL) - conn->own_ip = g_new(IPADDR, 1); - memcpy(conn->own_ip, &ip, sizeof(IPADDR)); - - sserver->own_ip = g_new(IPADDR, 1); - memcpy(sserver->own_ip, &ip, sizeof(IPADDR)); - } - } - + if (sserver->own_host != NULL) + conn_set_ip(conn, &sserver->own_ip, sserver->own_host); sserver->last_connect = time(NULL); if (sserver->ircnet) conn->ircnet = g_strdup(sserver->ircnet); @@ -141,6 +148,14 @@ create_addr_conn(const char *address, int port, const char *password, if (ircnet->max_modes > 0) conn->max_modes = ircnet->max_modes; if (ircnet->max_whois > 0) conn->max_whois = ircnet->max_whois; + if (ircnet->max_cmds_at_once > 0 && sserver->max_cmds_at_once <= 0) + conn->max_cmds_at_once = ircnet->max_cmds_at_once; + if (ircnet->cmd_queue_speed > 0 && sserver->cmd_queue_speed <= 0) + conn->cmd_queue_speed = ircnet->cmd_queue_speed; + + if (sserver->own_host == NULL && ircnet->own_host != NULL) + conn_set_ip(conn, &ircnet->own_ip, ircnet->own_host); + return conn; } diff --git a/src/irc/dcc/dcc-files.c b/src/irc/dcc/dcc-files.c index 2fb8d0b4..e2dc732d 100644 --- a/src/irc/dcc/dcc-files.c +++ b/src/irc/dcc/dcc-files.c @@ -272,7 +272,8 @@ static void dcc_ctcp_msg(const char *data, IRC_SERVER_REC *server, g_return_if_fail(data != NULL); g_return_if_fail(sender != NULL); - params = cmd_get_params(data, 4, &type, &arg, &portstr, &sizestr); + params = cmd_get_params(data, 4 | PARAM_FLAG_NOQUOTES, + &type, &arg, &portstr, &sizestr); port = atoi(portstr); size = atol(sizestr); diff --git a/src/irc/dcc/dcc.c b/src/irc/dcc/dcc.c index ae6fd586..4f418555 100644 --- a/src/irc/dcc/dcc.c +++ b/src/irc/dcc/dcc.c @@ -287,7 +287,8 @@ static void dcc_ctcp_msg(char *data, IRC_SERVER_REC *server, char *sender, char g_return_if_fail(data != NULL); g_return_if_fail(sender != NULL); - params = cmd_get_params(data, 5, &type, &arg, &addrstr, &portstr, &sizestr); + params = cmd_get_params(data, 5 | PARAM_FLAG_NOQUOTES, + &type, &arg, &addrstr, &portstr, &sizestr); if (sscanf(portstr, "%d", &port) != 1) port = 0; if (sscanf(sizestr, "%lu", &size) != 1) size = 0; |