/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
This commit is contained in:
Timo Sirainen 2000-06-04 14:52:47 +00:00 committed by cras
commit a7f5540cba
15 changed files with 173 additions and 68 deletions

View file

@ -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);
name = config_node_get_str(node, "name", NULL);
if (name == NULL) return 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);
if (node->key == NULL) return NULL;
rec = g_new0(IRCNET_REC, 1);
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));
rec->max_cmds_at_once = config_node_get_int(node, "cmdmax", 0);
rec->cmd_queue_speed = config_node_get_int(node, "cmdspeed", 0);
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;
}

View file

@ -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);

View file

@ -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, '.');

View file

@ -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;
}