diff options
author | Sebastien Helleu <flashcode@flashtux.org> | 2006-03-25 11:20:37 +0000 |
---|---|---|
committer | Sebastien Helleu <flashcode@flashtux.org> | 2006-03-25 11:20:37 +0000 |
commit | eaa33bfb8e421738ff3b6abd4c9e5a1930362f2d (patch) | |
tree | c8f1472e5d0af9704516b18c05989c13c3254eda /src | |
parent | fcd38093268863f16b92b071e0489d23c26dc436 (diff) | |
download | weechat-eaa33bfb8e421738ff3b6abd4c9e5a1930362f2d.zip |
Added hostname/IP option for connection to server
Diffstat (limited to 'src')
-rw-r--r-- | src/common/command.c | 1 | ||||
-rw-r--r-- | src/common/session.c | 4 | ||||
-rw-r--r-- | src/common/session.h | 3 | ||||
-rw-r--r-- | src/common/weechat.c | 5 | ||||
-rw-r--r-- | src/common/weeconfig.c | 12 | ||||
-rw-r--r-- | src/irc/irc-display.c | 4 | ||||
-rw-r--r-- | src/irc/irc-send.c | 22 | ||||
-rw-r--r-- | src/irc/irc-server.c | 49 | ||||
-rw-r--r-- | src/irc/irc.h | 5 |
9 files changed, 69 insertions, 36 deletions
diff --git a/src/common/command.c b/src/common/command.c index 611c50c1d..9f77b2ccb 100644 --- a/src/common/command.c +++ b/src/common/command.c @@ -2865,6 +2865,7 @@ weechat_cmd_server (t_irc_server *server, t_irc_channel *channel, server_tmp.password, server_tmp.nick1, server_tmp.nick2, server_tmp.nick3, server_tmp.username, server_tmp.realname, + server_tmp.hostname, server_tmp.command, 1, server_tmp.autojoin, 1, NULL, NULL, NULL, NULL); if (new_server) diff --git a/src/common/session.c b/src/common/session.c index 7defd8f94..5985448ca 100644 --- a/src/common/session.c +++ b/src/common/session.c @@ -225,6 +225,7 @@ session_save_servers (FILE *file) rc = rc && (session_write_str (file, SESSION_SERV_NICK3, ptr_server->nick3)); rc = rc && (session_write_str (file, SESSION_SERV_USERNAME, ptr_server->username)); rc = rc && (session_write_str (file, SESSION_SERV_REALNAME, ptr_server->realname)); + rc = rc && (session_write_str (file, SESSION_SERV_HOSTNAME, ptr_server->hostname)); rc = rc && (session_write_str (file, SESSION_SERV_COMMAND, ptr_server->command)); rc = rc && (session_write_int (file, SESSION_SERV_COMMAND_DELAY, ptr_server->command_delay)); rc = rc && (session_write_str (file, SESSION_SERV_AUTOJOIN, ptr_server->autojoin)); @@ -858,6 +859,9 @@ session_load_server (FILE *file) case SESSION_SERV_REALNAME: rc = rc && (session_read_str (file, &(session_current_server->realname))); break; + case SESSION_SERV_HOSTNAME: + rc = rc && (session_read_str (file, &(session_current_server->hostname))); + break; case SESSION_SERV_COMMAND: rc = rc && (session_read_str (file, &(session_current_server->command))); break; diff --git a/src/common/session.h b/src/common/session.h index 9a6e70d27..9062bbb7a 100644 --- a/src/common/session.h +++ b/src/common/session.h @@ -88,7 +88,8 @@ enum t_session_server SESSION_SERV_LAG_NEXT_CHECK, SESSION_SERV_CHARSET_DECODE_ISO, SESSION_SERV_CHARSET_DECODE_UTF, - SESSION_SERV_CHARSET_ENCODE + SESSION_SERV_CHARSET_ENCODE, + SESSION_SERV_HOSTNAME }; enum t_session_channel diff --git a/src/common/weechat.c b/src/common/weechat.c index cea92ad48..6c9392c9e 100644 --- a/src/common/weechat.c +++ b/src/common/weechat.c @@ -687,8 +687,9 @@ weechat_parse_args (int argc, char *argv[]) server_tmp.ipv6, server_tmp.ssl, server_tmp.password, server_tmp.nick1, server_tmp.nick2, server_tmp.nick3, - NULL, NULL, NULL, 0, server_tmp.autojoin, 1, NULL, - NULL, NULL, NULL)) + NULL, NULL, NULL, NULL, 0, + server_tmp.autojoin, 1, NULL, NULL, + NULL, NULL)) fprintf (stderr, _("%s unable to create server ('%s'), ignored\n"), WEECHAT_WARNING, argv[i]); server_destroy (&server_tmp); diff --git a/src/common/weeconfig.c b/src/common/weeconfig.c index e44c5b12e..d346f4a28 100644 --- a/src/common/weeconfig.c +++ b/src/common/weeconfig.c @@ -947,6 +947,10 @@ t_config_option weechat_options_server[] = N_("real name to use on IRC server"), OPTION_TYPE_STRING, 0, 0, 0, "", NULL, NULL, &(cfg_server.realname), NULL }, + { "server_hostname", N_("custom hostname/IP for server"), + N_("custom hostname/IP for server (optional, if empty local hostname is used)"), + OPTION_TYPE_STRING, 0, 0, 0, + "", NULL, NULL, &(cfg_server.hostname), NULL }, { "server_command", N_("command(s) to run when connected to server"), N_("command(s) to run when connected to server (many commands should be " "separated by ';', use '\\;' for a semicolon)"), @@ -1447,6 +1451,8 @@ config_get_server_option_ptr (t_irc_server *server, char *option_name) return (void *)(&server->username); if (ascii_strcasecmp (option_name, "server_realname") == 0) return (void *)(&server->realname); + if (ascii_strcasecmp (option_name, "server_hostname") == 0) + return (void *)(&server->hostname); if (ascii_strcasecmp (option_name, "server_command") == 0) return (void *)(&server->command); if (ascii_strcasecmp (option_name, "server_command_delay") == 0) @@ -1687,7 +1693,8 @@ config_allocate_server (char *filename, int line_number) cfg_server.port, cfg_server.ipv6, cfg_server.ssl, cfg_server.password, cfg_server.nick1, cfg_server.nick2, cfg_server.nick3, cfg_server.username, cfg_server.realname, - cfg_server.command, cfg_server.command_delay, cfg_server.autojoin, + cfg_server.hostname, cfg_server.command, + cfg_server.command_delay, cfg_server.autojoin, cfg_server.autorejoin, cfg_server.notify_levels, cfg_server.charset_decode_iso, cfg_server.charset_decode_utf, cfg_server.charset_encode)) @@ -2223,6 +2230,7 @@ config_create_default () fprintf (file, "server_realname = \"WeeChat default realname\"\n"); } + fprintf (file, "server_hostname = \"\"\n"); fprintf (file, "server_command = \"\"\n"); fprintf (file, "server_command_delay = 0\n"); fprintf (file, "server_autojoin = \"\"\n"); @@ -2409,6 +2417,8 @@ config_write (char *config_name) fprintf (file, "server_nick3 = \"%s\"\n", ptr_server->nick3); fprintf (file, "server_username = \"%s\"\n", ptr_server->username); fprintf (file, "server_realname = \"%s\"\n", ptr_server->realname); + fprintf (file, "server_hostname = \"%s\"\n", + (ptr_server->hostname) ? ptr_server->hostname : ""); fprintf (file, "server_command = \"%s\"\n", (ptr_server->command) ? ptr_server->command : ""); fprintf (file, "server_command_delay = %d\n", ptr_server->command_delay); diff --git a/src/irc/irc-display.c b/src/irc/irc-display.c index 8fd191416..5c0f35399 100644 --- a/src/irc/irc-display.c +++ b/src/irc/irc-display.c @@ -291,7 +291,9 @@ irc_display_server (t_irc_server *server) gui_printf (NULL, " server_username . . . . . : %s\n", server->username); gui_printf (NULL, " server_realname . . . . . : %s\n", - server->realname); + server->realname); + gui_printf (NULL, " server_hostname . . . . . : %s\n", + (server->hostname) ? server->hostname : ""); gui_printf (NULL, " server_command . . . . . . : %s\n", (server->command && server->command[0]) ? server->command : ""); diff --git a/src/irc/irc-send.c b/src/irc/irc-send.c index c1162fadf..92d3fccce 100644 --- a/src/irc/irc-send.c +++ b/src/irc/irc-send.c @@ -48,25 +48,31 @@ void irc_login (t_irc_server *server) { - char hostname[128]; + char hostname[128], *ptr_hostname; if ((server->password) && (server->password[0])) server_sendf (server, "PASS %s\r\n", server->password); - gethostname (hostname, sizeof (hostname) - 1); - hostname[sizeof (hostname) - 1] = '\0'; - if (!hostname[0]) - strcpy (hostname, _("unknown")); + if (server->hostname && server->hostname[0]) + ptr_hostname = server->hostname; + else + { + gethostname (hostname, sizeof (hostname) - 1); + hostname[sizeof (hostname) - 1] = '\0'; + if (!hostname[0]) + strcpy (hostname, _("unknown")); + ptr_hostname = hostname; + } irc_display_prefix (server, server->buffer, PREFIX_INFO); gui_printf (server->buffer, - _("%s: using local hostname \"%s\"\n"), - PACKAGE_NAME, hostname); + _("%s: using hostname \"%s\"\n"), + PACKAGE_NAME, ptr_hostname); if (!server->nick) server->nick = strdup (server->nick1); server_sendf (server, "NICK %s\r\n" "USER %s %s %s :%s\r\n", - server->nick, server->username, hostname, "servername", + server->nick, server->username, ptr_hostname, "servername", server->realname); gui_draw_buffer_input (gui_current_window->buffer, 1); } diff --git a/src/irc/irc-server.c b/src/irc/irc-server.c index 7c00e4687..933598dae 100644 --- a/src/irc/irc-server.c +++ b/src/irc/irc-server.c @@ -79,6 +79,7 @@ server_init (t_irc_server *server) server->nick3 = NULL; server->username = NULL; server->realname = NULL; + server->hostname = NULL; server->command = NULL; server->command_delay = 1; server->autojoin = NULL; @@ -291,6 +292,8 @@ server_destroy (t_irc_server *server) free (server->username); if (server->realname) free (server->realname); + if (server->hostname) + free (server->hostname); if (server->command) free (server->command); if (server->autojoin) @@ -360,12 +363,14 @@ server_free_all () */ t_irc_server * -server_new (char *name, int autoconnect, int autoreconnect, int autoreconnect_delay, - int command_line, char *address, int port, int ipv6, int ssl, char *password, +server_new (char *name, int autoconnect, int autoreconnect, + int autoreconnect_delay, int command_line, char *address, + int port, int ipv6, int ssl, char *password, char *nick1, char *nick2, char *nick3, char *username, - char *realname, char *command, int command_delay, char *autojoin, - int autorejoin, char *notify_levels, char *charset_decode_iso, - char *charset_decode_utf, char *charset_encode) + char *realname, char *hostname, char *command, int command_delay, + char *autojoin, int autorejoin, char *notify_levels, + char *charset_decode_iso, char *charset_decode_utf, + char *charset_encode) { t_irc_server *new_server; @@ -375,13 +380,14 @@ server_new (char *name, int autoconnect, int autoreconnect, int autoreconnect_de #ifdef DEBUG weechat_log_printf ("Creating new server (name:%s, address:%s, port:%d, pwd:%s, " "nick1:%s, nick2:%s, nick3:%s, username:%s, realname:%s, " - "command:%s, autojoin:%s, autorejoin:%s, notify_levels:%s, " - "decode_iso:%s, decode_utf:%s, encode:%s)\n", + "hostname: %s, command:%s, autojoin:%s, autorejoin:%s, " + "notify_levels:%s, decode_iso:%s, decode_utf:%s, encode:%s)\n", name, address, port, (password) ? password : "", (nick1) ? nick1 : "", (nick2) ? nick2 : "", (nick3) ? nick3 : "", (username) ? username : "", (realname) ? realname : "", - (command) ? command : "", (autojoin) ? autojoin : "", - (autorejoin) ? "on" : "off", (notify_levels) ? notify_levels : "", + (hostname) ? hostname : "", (command) ? command : "", + (autojoin) ? autojoin : "", (autorejoin) ? "on" : "off", + (notify_levels) ? notify_levels : "", (charset_decode_iso) ? charset_decode_iso : "", (charset_decode_utf) ? charset_decode_utf : "", (charset_encode) ? charset_encode : ""); @@ -406,6 +412,8 @@ server_new (char *name, int autoconnect, int autoreconnect, int autoreconnect_de (username) ? strdup (username) : strdup ("weechat"); new_server->realname = (realname) ? strdup (realname) : strdup ("realname"); + new_server->hostname = + (hostname) ? strdup (hostname) : NULL; new_server->command = (command) ? strdup (command) : NULL; new_server->command_delay = command_delay; @@ -1086,20 +1094,20 @@ pass_httpproxy(int sock, char *address, int port) { char buffer[256]; - char authbuf[128]; // seems to be enougth to store username + password - char authbuf_base64[196]; // enougth to store base64 encoded authbuf + char authbuf[128]; + char authbuf_base64[196]; int n, m; if (strlen(cfg_proxy_username) > 0) { - // authentification + /* authentification */ snprintf(authbuf, sizeof(authbuf), "%s:%s", cfg_proxy_username, cfg_proxy_password); base64encode(authbuf, authbuf_base64); n = snprintf(buffer, sizeof(buffer), "CONNECT %s:%d HTTP/1.0\r\nProxy-Authorization: Basic %s\r\n\r\n", address, port, authbuf_base64); } else { - // no authentification + /* no authentification */ n = snprintf(buffer, sizeof(buffer), "CONNECT %s:%d HTTP/1.0\r\n\r\n", address, port); } @@ -1109,7 +1117,7 @@ pass_httpproxy(int sock, char *address, int port) n = recv(sock, buffer, sizeof(buffer), 0); - /* success result must be like : "HTTP/1.0 200 OK" */ + /* success result must be like: "HTTP/1.0 200 OK" */ if (n < 12) return 1; @@ -1252,28 +1260,27 @@ pass_socks5proxy(int sock, char *address, int port) * - socks version (buffer[0]) = 5 => socks5 * - socks method (buffer[1]) = 2 => authentication */ - - //if (!(buffer[0] == 5 && buffer[1] == 2)) + if (buffer[0] != 5 || buffer[1] != 2) return 1; - + /* authentication as in RFC 1929 */ username_len = strlen(cfg_proxy_username); password_len = strlen(cfg_proxy_password); - + /* make username/password buffer */ buffer[0] = 1; buffer[1] = (unsigned char) username_len; memcpy(buffer + 2, cfg_proxy_username, username_len); buffer[2 + username_len] = (unsigned char) password_len; memcpy(buffer + 3 + username_len, cfg_proxy_password, password_len); - + send (sock, buffer, 3 + username_len + password_len, 0); - + /* server socks5 must respond with 2 bytes */ if (recv (sock, buffer, 2, 0) != 2) return 1; - + /* buffer[1] = auth state, must be 0 for success */ if (buffer[1] != 0) return 1; diff --git a/src/irc/irc.h b/src/irc/irc.h index 94a116318..71c6b42ab 100644 --- a/src/irc/irc.h +++ b/src/irc/irc.h @@ -142,6 +142,7 @@ struct t_irc_server char *nick3; /* 2nd alternate nickname */ char *username; /* user name */ char *realname; /* real name */ + char *hostname; /* custom hostname */ char *command; /* command to run once connected */ int command_delay; /* delay after execution of command */ char *autojoin; /* channels to automatically join */ @@ -310,8 +311,8 @@ extern void server_free (t_irc_server *); extern void server_free_all (); extern t_irc_server *server_new (char *, int, int, int, int, char *, int, int, int, char *, char *, char *, char *, char *, char *, - char *, int, char *, int, char *, char *, char *, - char *); + char *, char *, int, char *, int, char *, char *, + char *, char *); extern char *server_get_charset_decode_iso (t_irc_server *); extern char *server_get_charset_decode_utf (t_irc_server *); extern char *server_get_charset_encode (t_irc_server *); |