summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSebastien Helleu <flashcode@flashtux.org>2004-01-18 23:53:34 +0000
committerSebastien Helleu <flashcode@flashtux.org>2004-01-18 23:53:34 +0000
commit38bf163c173395571ca2772eda23bf162713a912 (patch)
tree0cf263e2f4e03380d02f25e9a0f5508f69ca035a /src
parent09a36a5d8ee6025822acfe6c9ac6d578f98323e4 (diff)
downloadweechat-38bf163c173395571ca2772eda23bf162713a912.zip
Servers allowed on command line (irc://nick:passwd@irc.example.org:port)
Diffstat (limited to 'src')
-rw-r--r--src/common/command.c17
-rw-r--r--src/common/weechat.c170
-rw-r--r--src/common/weechat.h7
-rw-r--r--src/common/weeconfig.c39
-rw-r--r--src/irc/irc-server.c73
-rw-r--r--src/irc/irc.h8
6 files changed, 215 insertions, 99 deletions
diff --git a/src/common/command.c b/src/common/command.c
index 0e2b3d58a..0f6d388f2 100644
--- a/src/common/command.c
+++ b/src/common/command.c
@@ -1167,8 +1167,11 @@ weechat_cmd_server (int argc, char **argv)
irc_display_prefix (NULL, PREFIX_INFO);
gui_printf_color (NULL,
COLOR_WIN_CHAT,
- _(" Autoconnect: %s\n"),
- (ptr_server->autoconnect) ? _("yes") : _("no"));
+ _(" Autoconnect: %s%s\n"),
+ (ptr_server->autoconnect) ? _("yes") : _("no"),
+ (ptr_server->command_line) ?
+ _(" (temporary server, will not be saved)") :
+ "");
irc_display_prefix (NULL, PREFIX_INFO);
gui_printf_color (NULL,
COLOR_WIN_CHAT,
@@ -1399,11 +1402,11 @@ weechat_cmd_server (int argc, char **argv)
}
/* create new server */
- new_server = server_new (server.name, server.autoconnect, server.address,
- server.port, server.password, server.nick1,
- server.nick2, server.nick3, server.username,
- server.realname, server.command,
- server.autojoin);
+ new_server = server_new (server.name, server.autoconnect, 0,
+ server.address, server.port, server.password,
+ server.nick1, server.nick2, server.nick3,
+ server.username, server.realname,
+ server.command, server.autojoin);
if (new_server)
{
irc_display_prefix (NULL, PREFIX_INFO);
diff --git a/src/common/weechat.c b/src/common/weechat.c
index b03ba027c..0de07f37d 100644
--- a/src/common/weechat.c
+++ b/src/common/weechat.c
@@ -63,6 +63,8 @@ int quit_weechat; /* = 1 if quit request from user... why ? :'( */
char *weechat_home; /* WeeChat home dir. (example: /home/toto/.weechat) */
FILE *log_file; /* WeeChat log file (~/.weechat/weechat.log) */
+int server_cmd_line; /* at least one server on WeeChat command line */
+
/*
* my_sigint: SIGINT handler, do nothing (just ignore this signal)
@@ -104,88 +106,103 @@ wee_log_printf (char *message, ...)
}
/*
+ * wee_display_config_options: display config options
+ */
+
+void wee_display_config_options ()
+{
+ int i, j, k;
+
+ printf (_("WeeChat configuration options (~/.weechat/weechat.rc):\n\n"));
+ for (i = 0; i < CONFIG_NUMBER_SECTIONS; i++)
+ {
+ if (weechat_options[i])
+ {
+ j = 0;
+ while (weechat_options[i][j].option_name)
+ {
+ printf ("* %s:\n",
+ weechat_options[i][j].option_name);
+ switch (weechat_options[i][j].option_type)
+ {
+ case OPTION_TYPE_BOOLEAN:
+ printf (_(" . type boolean (values: 'on' or 'off')\n"));
+ printf (_(" . default value: '%s'\n"),
+ (weechat_options[i][j].default_int == BOOL_TRUE) ?
+ "on" : "off");
+ break;
+ case OPTION_TYPE_INT:
+ printf (_(" . type integer (values: between %d and %d)\n"),
+ weechat_options[i][j].min,
+ weechat_options[i][j].max);
+ printf (_(" . default value: %d\n"),
+ weechat_options[i][j].default_int);
+ break;
+ case OPTION_TYPE_INT_WITH_STRING:
+ printf (_(" . type string (values: "));
+ k = 0;
+ while (weechat_options[i][j].array_values[k])
+ {
+ printf ("'%s'",
+ weechat_options[i][j].array_values[k]);
+ if (weechat_options[i][j].array_values[k + 1])
+ printf (", ");
+ k++;
+ }
+ printf (")\n");
+ printf (_(" . default value: '%s'\n"),
+ (weechat_options[i][j].default_string) ?
+ weechat_options[i][j].default_string : _("empty"));
+ break;
+ case OPTION_TYPE_COLOR:
+ printf (_(" . type color (Curses or Gtk color, look at WeeChat doc)\n"));
+ printf (_(" . default value: '%s'\n"),
+ (weechat_options[i][j].default_string) ?
+ weechat_options[i][j].default_string : _("empty"));
+ break;
+ case OPTION_TYPE_STRING:
+ printf (_(" . type string (any string)\n"));
+ printf (_(" . default value: '%s'\n"),
+ (weechat_options[i][j].default_string) ?
+ weechat_options[i][j].default_string : _("empty"));
+ break;
+ }
+ printf (_(" . description: %s\n\n"),
+ gettext (weechat_options[i][j].long_description));
+ j++;
+ }
+ }
+ }
+ printf (_("Moreover, you can define aliases in [alias] section, by adding lines like:\n"));
+ printf ("j=join\n");
+ printf (_("where 'j' is alias name, and 'join' associated command.\n\n"));
+}
+
+/*
* wee_parse_args: parse command line args
*/
void
wee_parse_args (int argc, char *argv[])
{
- int i, j, k, m;
+ int i;
+ t_irc_server server_tmp;
+ server_cmd_line = 0;
+
for (i = 1; i < argc; i++)
{
if ((strcmp (argv[i], "-c") == 0)
|| (strcmp (argv[i], "--config") == 0))
{
- printf(_("WeeChat configuration options (~/.weechat/weechat.rc):\n\n"));
- for (j = 0; j < CONFIG_NUMBER_SECTIONS; j++)
- {
- if (weechat_options[j])
- {
- k = 0;
- while (weechat_options[j][k].option_name)
- {
- printf ("* %s:\n",
- weechat_options[j][k].option_name);
- switch (weechat_options[j][k].option_type)
- {
- case OPTION_TYPE_BOOLEAN:
- printf (_(" . type boolean (values: 'on' or 'off')\n"));
- printf (_(" . default value: '%s'\n"),
- (weechat_options[j][k].default_int == BOOL_TRUE) ?
- "on" : "off");
- break;
- case OPTION_TYPE_INT:
- printf (_(" . type integer (values: between %d and %d)\n"),
- weechat_options[j][k].min,
- weechat_options[j][k].max);
- printf (_(" . default value: %d\n"),
- weechat_options[j][k].default_int);
- break;
- case OPTION_TYPE_INT_WITH_STRING:
- printf (_(" . type string (values: "));
- m = 0;
- while (weechat_options[j][k].array_values[m])
- {
- printf ("'%s'",
- weechat_options[j][k].array_values[m]);
- if (weechat_options[j][k].array_values[m + 1])
- printf (", ");
- m++;
- }
- printf (")\n");
- printf (_(" . default value: '%s'\n"),
- (weechat_options[j][k].default_string) ?
- weechat_options[j][k].default_string : _("empty"));
- break;
- case OPTION_TYPE_COLOR:
- printf (_(" . type color (Curses or Gtk color, look at WeeChat doc)\n"));
- printf (_(" . default value: '%s'\n"),
- (weechat_options[j][k].default_string) ?
- weechat_options[j][k].default_string : _("empty"));
- break;
- case OPTION_TYPE_STRING:
- printf (_(" . type string (any string)\n"));
- printf (_(" . default value: '%s'\n"),
- (weechat_options[j][k].default_string) ?
- weechat_options[j][k].default_string : _("empty"));
- break;
- }
- printf (_(" . description: %s\n\n"),
- gettext (weechat_options[j][k].long_description));
- k++;
- }
- }
- }
- printf (_("Moreover, you can define aliases in [alias] section, by adding lines like:\n"));
- printf ("j=join\n");
- printf (_("where 'j' is alias name, and 'join' associated command.\n\n"));
+ wee_display_config_options ();
exit (0);
}
else if ((strcmp (argv[i], "-h") == 0)
|| (strcmp (argv[i], "--help") == 0))
{
- printf ("\n%s%s", WEE_USAGE);
+ printf ("\n " WEE_USAGE1, argv[0]);
+ printf ("%s", WEE_USAGE2);
exit (0);
}
else if ((strcmp (argv[i], "-l") == 0)
@@ -200,6 +217,26 @@ wee_parse_args (int argc, char *argv[])
printf (PACKAGE_VERSION "\n");
exit (0);
}
+ else if ((strncasecmp (argv[i], "irc://", 6) == 0))
+ {
+ if (server_init_with_url (argv[i], &server_tmp) < 0)
+ {
+ fprintf (stderr, _("%s invalid syntax for IRC server ('%s'), ignored\n"),
+ WEECHAT_WARNING, argv[i]);
+ }
+ else
+ {
+ if (!server_new (server_tmp.name, 0, 1,
+ server_tmp.address, server_tmp.port,
+ server_tmp.password, server_tmp.nick1,
+ server_tmp.nick2, server_tmp.nick3,
+ NULL, NULL, NULL, NULL))
+ fprintf (stderr, _("%s unable to create server ('%s'), ignored\n"),
+ WEECHAT_WARNING, argv[i]);
+ server_destroy (&server_tmp);
+ server_cmd_line = 1;
+ }
+ }
else
{
fprintf (stderr,
@@ -425,7 +462,8 @@ main (int argc, char *argv[])
gui_init (); /* init WeeChat interface */
plugin_init (); /* init plugin interface(s) */
weechat_welcome_message (); /* display WeeChat welcome message */
- server_auto_connect (); /* auto-connect to servers */
+ /* auto-connect to servers */
+ server_auto_connect (server_cmd_line);
gui_main_loop (); /* WeeChat main loop */
diff --git a/src/common/weechat.h b/src/common/weechat.h
index 5ab30e049..58a3b72d9 100644
--- a/src/common/weechat.h
+++ b/src/common/weechat.h
@@ -76,11 +76,14 @@
"along with this program; if not, write to the Free Software\n" \
"Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\n\n"
-#define WEE_USAGE \
+#define WEE_USAGE1 \
PACKAGE_STRING " (c) Copyright 2004, compiled on " __DATE__ " " __TIME__ \
"\nDeveloped by FlashCode, Bounga and Xahlexx - " WEECHAT_WEBSITE "\n\n" \
+ "Usage: %s [options ...] [irc://nick[:passwd]@irc.example.org[:port] ...]\n\n"
+
+#define WEE_USAGE2 \
" -c, --config config file help (list of options)\n" \
- " -h, --help this help screen\n", \
+ " -h, --help this help screen\n" \
" -l, --license display WeeChat license\n" \
" -v, --version display WeeChat version\n\n"
diff --git a/src/common/weeconfig.c b/src/common/weeconfig.c
index 98211aa05..4d91862b6 100644
--- a/src/common/weeconfig.c
+++ b/src/common/weeconfig.c
@@ -658,7 +658,7 @@ config_allocate_server (char *filename, int line_number)
return 0;
}
if (!server_new (cfg_server.name,
- cfg_server.autoconnect, cfg_server.address, cfg_server.port,
+ cfg_server.autoconnect, 0, cfg_server.address, cfg_server.port,
cfg_server.password, cfg_server.nick1, cfg_server.nick2,
cfg_server.nick3, cfg_server.username, cfg_server.realname,
cfg_server.command, cfg_server.autojoin))
@@ -1194,23 +1194,26 @@ config_write (char *config_name)
for (ptr_server = irc_servers; ptr_server;
ptr_server = ptr_server->next_server)
{
- fprintf (file, "\n[server]\n");
- fprintf (file, "server_name=%s\n", ptr_server->name);
- fprintf (file, "server_autoconnect=%s\n",
- (ptr_server->autoconnect) ? "on" : "off");
- fprintf (file, "server_address=%s\n", ptr_server->address);
- fprintf (file, "server_port=%d\n", ptr_server->port);
- fprintf (file, "server_password=%s\n",
- (ptr_server->password) ? ptr_server->password : "");
- fprintf (file, "server_nick1=%s\n", ptr_server->nick1);
- fprintf (file, "server_nick2=%s\n", ptr_server->nick2);
- 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_command=%s\n",
- (ptr_server->command) ? ptr_server->command : "");
- fprintf (file, "server_autojoin=%s\n",
- (ptr_server->autojoin) ? ptr_server->autojoin : "");
+ if (!ptr_server->command_line)
+ {
+ fprintf (file, "\n[server]\n");
+ fprintf (file, "server_name=%s\n", ptr_server->name);
+ fprintf (file, "server_autoconnect=%s\n",
+ (ptr_server->autoconnect) ? "on" : "off");
+ fprintf (file, "server_address=%s\n", ptr_server->address);
+ fprintf (file, "server_port=%d\n", ptr_server->port);
+ fprintf (file, "server_password=%s\n",
+ (ptr_server->password) ? ptr_server->password : "");
+ fprintf (file, "server_nick1=%s\n", ptr_server->nick1);
+ fprintf (file, "server_nick2=%s\n", ptr_server->nick2);
+ 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_command=%s\n",
+ (ptr_server->command) ? ptr_server->command : "");
+ fprintf (file, "server_autojoin=%s\n",
+ (ptr_server->autojoin) ? ptr_server->autojoin : "");
+ }
}
fclose (file);
diff --git a/src/irc/irc-server.c b/src/irc/irc-server.c
index 6e6a014be..88318ff42 100644
--- a/src/irc/irc-server.c
+++ b/src/irc/irc-server.c
@@ -59,6 +59,7 @@ server_init (t_irc_server *server)
{
server->name = NULL;
server->autoconnect = 0;
+ server->command_line = 0;
server->address = NULL;
server->port = -1;
server->password = NULL;
@@ -81,6 +82,68 @@ server_init (t_irc_server *server)
}
/*
+ * server_init_with_url: init a server with url of this form:
+ * irc://nick:pass@irc.toto.org:6667
+ * returns: 0 = ok
+ * -1 = invalid syntax
+ */
+
+int
+server_init_with_url (char *irc_url, t_irc_server *server)
+{
+ char *url, *pos_address, *pos, *pos2;
+
+ server_init (server);
+ if (strncasecmp (irc_url, "irc://", 6) != 0)
+ return -1;
+ url = strdup (irc_url);
+ pos_address = strchr (url, '@');
+ if (!pos_address || !pos_address[1])
+ {
+ free (url);
+ return -1;
+ }
+ pos_address[0] = '\0';
+ pos_address++;
+ pos = url + 6;
+ if (!pos[0])
+ {
+ free (url);
+ return -1;
+ }
+ pos2 = strchr (pos, ':');
+ if (pos2)
+ {
+ pos2[0] = '\0';
+ server->password = strdup (pos2 + 1);
+ }
+ server->nick1 = strdup (pos);
+
+ pos2 = strchr (pos_address, ':');
+ if (pos2)
+ {
+ pos2[0] = '\0';
+ server->port = atoi (pos2 + 1);
+ }
+ server->name = strdup (pos_address);
+ server->address = strdup (pos_address);
+
+ free (url);
+
+ /* some default values */
+ if (server->port < 0)
+ server->port = DEFAULT_IRC_PORT;
+ server->nick2 = (char *) malloc (strlen (server->nick1) + 2);
+ strcpy (server->nick2, server->nick1);
+ server->nick2 = strcat (server->nick2, "1");
+ server->nick3 = (char *) malloc (strlen (server->nick1) + 2);
+ strcpy (server->nick3, server->nick1);
+ server->nick3 = strcat (server->nick3, "2");
+
+ return 0;
+}
+
+/*
* server_alloc: allocate a new server and add it to the servers queue
*/
@@ -193,8 +256,8 @@ server_free_all ()
*/
t_irc_server *
-server_new (char *name, int autoconnect, char *address, int port,
- char *password, char *nick1, char *nick2, char *nick3,
+server_new (char *name, int autoconnect, int command_line, char *address,
+ int port, char *password, char *nick1, char *nick2, char *nick3,
char *username, char *realname, char *command, char *autojoin)
{
t_irc_server *new_server;
@@ -216,6 +279,7 @@ server_new (char *name, int autoconnect, char *address, int port,
{
new_server->name = strdup (name);
new_server->autoconnect = autoconnect;
+ new_server->command_line = command_line;
new_server->address = strdup (address);
new_server->port = port;
new_server->password = (password) ? strdup (password) : strdup ("");
@@ -574,14 +638,15 @@ server_connect (t_irc_server *server)
*/
void
-server_auto_connect ()
+server_auto_connect (int command_line)
{
t_irc_server *ptr_server;
for (ptr_server = irc_servers; ptr_server;
ptr_server = ptr_server->next_server)
{
- if (ptr_server->autoconnect)
+ if ( ((command_line) && (ptr_server->command_line))
+ || ((!command_line) && (ptr_server->autoconnect)) )
{
gui_window_new (ptr_server, NULL, 1);
if (server_connect (ptr_server))
diff --git a/src/irc/irc.h b/src/irc/irc.h
index c1b761e35..f050ce86a 100644
--- a/src/irc/irc.h
+++ b/src/irc/irc.h
@@ -34,6 +34,8 @@
#define CHANNEL_PREFIX "#&+!"
+#define DEFAULT_IRC_PORT 6667
+
/* nick types */
typedef struct t_irc_nick t_irc_nick;
@@ -78,6 +80,7 @@ struct t_irc_server
/* user choices */
char *name; /* name of server (only for display) */
int autoconnect; /* = 1 if auto connect at startup */
+ int command_line; /* server was given on command line */
char *address; /* address of server (IP or name) */
int port; /* port for server (6667 by default) */
char *password; /* password for server */
@@ -140,17 +143,18 @@ extern t_irc_channel *current_channel;
/* server functions (irc-server.c) */
extern void server_init (t_irc_server *);
+extern int server_init_with_url (char *, t_irc_server *);
extern t_irc_server *server_alloc ();
extern void server_destroy (t_irc_server *);
extern void server_free (t_irc_server *);
extern void server_free_all ();
-extern t_irc_server *server_new (char *, int, char *, int, char *, char *,
+extern t_irc_server *server_new (char *, int, int, char *, int, char *, char *,
char *, char *, char *, char *, char *, char *);
extern int server_send (t_irc_server *, char *, int);
extern int server_sendf (t_irc_server *, char *, ...);
extern void server_recv (t_irc_server *);
extern int server_connect ();
-extern void server_auto_connect ();
+extern void server_auto_connect (int);
extern void server_disconnect (t_irc_server *);
extern void server_disconnect_all ();
extern t_irc_server *server_search (char *);