mirror of
https://github.com/weechat/weechat.git
synced 2026-07-04 08:43:13 +02:00
irc: add ${username} in server options "nicks" and "username", change their default values to use it
This commit is contained in:
@@ -25,7 +25,6 @@
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <limits.h>
|
||||
#include <pwd.h>
|
||||
|
||||
#include "../weechat-plugin.h"
|
||||
#include "irc.h"
|
||||
@@ -2128,9 +2127,11 @@ irc_config_server_new_option (struct t_config_file *config_file,
|
||||
config_file, section,
|
||||
option_name, "string",
|
||||
N_("nicknames to use on server (separated by comma) "
|
||||
"(note: content is evaluated, see /help eval; server "
|
||||
"options are evaluated with ${irc_server.xxx} and "
|
||||
"${server} is replaced by the server name)"),
|
||||
"(note: content is evaluated, see /help eval; ${username} "
|
||||
"is replaced by system username (fallback to \"weechat\" "
|
||||
"if not found), server options are evaluated with "
|
||||
"${irc_server.xxx} and ${server} is replaced by the "
|
||||
"server name)"),
|
||||
NULL, 0, 0,
|
||||
default_value, value,
|
||||
null_value_allowed,
|
||||
@@ -2167,9 +2168,11 @@ irc_config_server_new_option (struct t_config_file *config_file,
|
||||
config_file, section,
|
||||
option_name, "string",
|
||||
N_("user name to use on server "
|
||||
"(note: content is evaluated, see /help eval; server "
|
||||
"options are evaluated with ${irc_server.xxx} and "
|
||||
"${server} is replaced by the server name)"),
|
||||
"(note: content is evaluated, see /help eval; ${username} "
|
||||
"is replaced by system username (fallback to \"weechat\" "
|
||||
"if not found), server options are evaluated with "
|
||||
"${irc_server.xxx} and ${server} is replaced by the "
|
||||
"server name)"),
|
||||
NULL, 0, 0,
|
||||
default_value, value,
|
||||
null_value_allowed,
|
||||
@@ -2731,62 +2734,17 @@ irc_config_server_write_cb (const void *pointer, void *data,
|
||||
void
|
||||
irc_config_server_create_default_options (struct t_config_section *section)
|
||||
{
|
||||
int i, length;
|
||||
char *nicks, *username, *realname, *default_value;
|
||||
struct passwd *my_passwd;
|
||||
|
||||
nicks = NULL;
|
||||
username = NULL;
|
||||
realname = strdup ("");
|
||||
|
||||
/* Get the user's name from /etc/passwd */
|
||||
if ((my_passwd = getpwuid (geteuid ())) != NULL)
|
||||
{
|
||||
length = (strlen (my_passwd->pw_name) + 4) * 5;
|
||||
nicks = malloc (length);
|
||||
if (nicks)
|
||||
{
|
||||
snprintf (nicks, length, "%s,%s1,%s2,%s3,%s4",
|
||||
my_passwd->pw_name,
|
||||
my_passwd->pw_name,
|
||||
my_passwd->pw_name,
|
||||
my_passwd->pw_name,
|
||||
my_passwd->pw_name);
|
||||
}
|
||||
username = strdup (my_passwd->pw_name);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* default values if /etc/passwd can't be read */
|
||||
nicks = strdup (IRC_SERVER_DEFAULT_NICKS);
|
||||
username = strdup ("weechat");
|
||||
}
|
||||
int i;
|
||||
|
||||
for (i = 0; i < IRC_SERVER_NUM_OPTIONS; i++)
|
||||
{
|
||||
default_value = NULL;
|
||||
switch (i)
|
||||
{
|
||||
case IRC_SERVER_OPTION_NICKS:
|
||||
default_value = nicks;
|
||||
break;
|
||||
case IRC_SERVER_OPTION_USERNAME:
|
||||
default_value = username;
|
||||
break;
|
||||
case IRC_SERVER_OPTION_REALNAME:
|
||||
default_value = realname;
|
||||
break;
|
||||
}
|
||||
if (!default_value)
|
||||
default_value = irc_server_options[i][1];
|
||||
|
||||
irc_config_server_default[i] = irc_config_server_new_option (
|
||||
irc_config_file,
|
||||
section,
|
||||
i,
|
||||
irc_server_options[i][0],
|
||||
irc_server_options[i][1],
|
||||
default_value,
|
||||
irc_server_options[i][1],
|
||||
0,
|
||||
&irc_config_server_check_value_cb,
|
||||
irc_server_options[i][0],
|
||||
@@ -2795,13 +2753,6 @@ irc_config_server_create_default_options (struct t_config_section *section)
|
||||
irc_server_options[i][0],
|
||||
NULL);
|
||||
}
|
||||
|
||||
if (nicks)
|
||||
free (nicks);
|
||||
if (username)
|
||||
free (username);
|
||||
if (realname)
|
||||
free (realname);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -43,6 +43,7 @@
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/nameser.h>
|
||||
#include <resolv.h>
|
||||
#include <pwd.h>
|
||||
|
||||
#include <gnutls/gnutls.h>
|
||||
#include <gnutls/x509.h>
|
||||
@@ -98,9 +99,11 @@ char *irc_server_options[IRC_SERVER_NUM_OPTIONS][2] =
|
||||
{ "autoconnect", "off" },
|
||||
{ "autoreconnect", "on" },
|
||||
{ "autoreconnect_delay", "10" },
|
||||
{ "nicks", "" },
|
||||
{ "nicks",
|
||||
"${username},${username}2,${username}3,"
|
||||
"${username}4,${username}5" },
|
||||
{ "nicks_alternate", "on" },
|
||||
{ "username", "" },
|
||||
{ "username", "${username}" },
|
||||
{ "realname", "" },
|
||||
{ "local_hostname", "" },
|
||||
{ "usermode", "" },
|
||||
@@ -361,6 +364,7 @@ irc_server_eval_expression (struct t_irc_server *server, const char *string)
|
||||
{
|
||||
struct t_hashtable *pointers, *extra_vars;
|
||||
char *value;
|
||||
struct passwd *my_passwd;
|
||||
|
||||
pointers = weechat_hashtable_new (
|
||||
32,
|
||||
@@ -381,6 +385,11 @@ irc_server_eval_expression (struct t_irc_server *server, const char *string)
|
||||
weechat_hashtable_set (extra_vars, "server", server->name);
|
||||
}
|
||||
|
||||
if ((my_passwd = getpwuid (geteuid ())) != NULL)
|
||||
weechat_hashtable_set (extra_vars, "username", my_passwd->pw_name);
|
||||
else
|
||||
weechat_hashtable_set (extra_vars, "username", "weechat");
|
||||
|
||||
value = weechat_string_eval_expression (string,
|
||||
pointers, extra_vars, NULL);
|
||||
|
||||
@@ -1954,7 +1963,7 @@ irc_server_alloc_with_url (const char *irc_url)
|
||||
if (server_nicks)
|
||||
{
|
||||
snprintf (server_nicks, length,
|
||||
"%s,%s1,%s2,%s3,%s4",
|
||||
"%s,%s2,%s3,%s4,%s5",
|
||||
pos_nick, pos_nick, pos_nick, pos_nick, pos_nick);
|
||||
weechat_config_option_set (
|
||||
ptr_server->options[IRC_SERVER_OPTION_NICKS],
|
||||
|
||||
Reference in New Issue
Block a user