# HG changeset patch # User Mikael Berthe # Date 1177149973 -7200 # Node ID 7b8765c10abb709903b61e357b16e52ceb7cdf67 # Parent b2ed413d8f3dd05b15afa4dd9285246523564572 New command: /source diff -r b2ed413d8f3d -r 7b8765c10abb mcabber/doc/help/de/hlp.txt --- a/mcabber/doc/help/de/hlp.txt Sat Apr 21 10:18:17 2007 +0200 +++ b/mcabber/doc/help/de/hlp.txt Sat Apr 21 12:06:13 2007 +0200 @@ -3,4 +3,4 @@ Zeigt die Hilfe zu einem Befehl oder ein Thema an. Wenn kein Argument gegeben ist, wird diese Hilfe angezeigt. -Verfügbare Befehle: add, alias, authorization, bind, buffer, chat_disable, clear, connect, del, disconnect, event, group, help, iline, info, move, msay, pgp, quit, rawxml, rename, request, room, roster, say_to, say, screen_refresh, set, status_to, status, version. +Verfügbare Befehle: add, alias, authorization, bind, buffer, chat_disable, clear, connect, del, disconnect, event, group, help, iline, info, move, msay, pgp, quit, rawxml, rename, request, room, roster, say_to, say, screen_refresh, set, source, status_to, status, version. diff -r b2ed413d8f3d -r 7b8765c10abb mcabber/doc/help/en/hlp.txt --- a/mcabber/doc/help/en/hlp.txt Sat Apr 21 10:18:17 2007 +0200 +++ b/mcabber/doc/help/en/hlp.txt Sat Apr 21 12:06:13 2007 +0200 @@ -3,4 +3,4 @@ Display some help about a command or a topic. If no argument provided a usage of this command is printed. -Available commands: add, alias, authorization, bind, buffer, chat_disable, clear, connect, del, disconnect, event, group, help, iline, info, move, msay, pgp, quit, rawxml, rename, request, room, roster, say_to, say, screen_refresh, set, status_to, status, version. +Available commands: add, alias, authorization, bind, buffer, chat_disable, clear, connect, del, disconnect, event, group, help, iline, info, move, msay, pgp, quit, rawxml, rename, request, room, roster, say_to, say, screen_refresh, set, source, status_to, status, version. diff -r b2ed413d8f3d -r 7b8765c10abb mcabber/doc/help/fr/hlp.txt --- a/mcabber/doc/help/fr/hlp.txt Sat Apr 21 10:18:17 2007 +0200 +++ b/mcabber/doc/help/fr/hlp.txt Sat Apr 21 12:06:13 2007 +0200 @@ -2,4 +2,4 @@ /HELP [commande|+sujet] Affiche de l'aide sur la commande ou le sujet demandé. -Les commandes disponibles sont : add, alias, authorization, bind, buffer, chat_disable, clear, connect, del, disconnect, event, group, help, iline, info, move, msay, pgp, quit, rawxml, rename, request, room, roster, say_to, say, screen_refresh, set, status_to, status, version. +Les commandes disponibles sont : add, alias, authorization, bind, buffer, chat_disable, clear, connect, del, disconnect, event, group, help, iline, info, move, msay, pgp, quit, rawxml, rename, request, room, roster, say_to, say, screen_refresh, set, source, status_to, status, version. diff -r b2ed413d8f3d -r 7b8765c10abb mcabber/doc/help/nl/hlp.txt --- a/mcabber/doc/help/nl/hlp.txt Sat Apr 21 10:18:17 2007 +0200 +++ b/mcabber/doc/help/nl/hlp.txt Sat Apr 21 12:06:13 2007 +0200 @@ -3,4 +3,4 @@ Toon informatie over een commando of onderwerp. Als geen argument is meegegeven, wordt een tekst over het gebruik van dit commando getoond. -Beschikbare commando's: add, alias, authorization, bind, buffer, chat_disable, clear, connect, del, disconnect, event, group, help, iline, info, move, msay, pgp, quit, rawxml, rename, request, room, roster, say_to, say, screen_refresh, set, status_to, status, version. +Beschikbare commando's: add, alias, authorization, bind, buffer, chat_disable, clear, connect, del, disconnect, event, group, help, iline, info, move, msay, pgp, quit, rawxml, rename, request, room, roster, say_to, say, screen_refresh, set, source, status_to, status, version. diff -r b2ed413d8f3d -r 7b8765c10abb mcabber/doc/help/pl/hlp.txt --- a/mcabber/doc/help/pl/hlp.txt Sat Apr 21 10:18:17 2007 +0200 +++ b/mcabber/doc/help/pl/hlp.txt Sat Apr 21 12:06:13 2007 +0200 @@ -3,4 +3,4 @@ Wyświetla pomoc dotyczącą danej komendy lub tematu. Jeśli nie podano żadnego argumentu, zostanie wyświetlona pomoc o sposobie użycia danej komendy. -Dostępne komendy: add, alias, authorization, bind, buffer, chat_disable, clear, connect, del, disconnect, event, group, help, iline, info, move, msay, pgp, quit, rawxml, rename, request, room, roster, say_to, say, screen_refresh, set, status_to, status, version. +Dostępne komendy: add, alias, authorization, bind, buffer, chat_disable, clear, connect, del, disconnect, event, group, help, iline, info, move, msay, pgp, quit, rawxml, rename, request, room, roster, say_to, say, screen_refresh, set, source, status_to, status, version. diff -r b2ed413d8f3d -r 7b8765c10abb mcabber/doc/help/ru/hlp.txt --- a/mcabber/doc/help/ru/hlp.txt Sat Apr 21 10:18:17 2007 +0200 +++ b/mcabber/doc/help/ru/hlp.txt Sat Apr 21 12:06:13 2007 +0200 @@ -3,4 +3,4 @@ Отображает файл помощи о запрошенной команде или топике. Если выполнить без аргументов, будут отображены допустимые команды. -Допустимые команды: add, alias, authorization, bind, buffer, chat_disable, clear, connect, del, disconnect, event, group, help, iline, info, move, msay, pgp, quit, rawxml, rename, request, room, roster, say_to, say, screen_refresh, set, status_to, status, version. +Допустимые команды: add, alias, authorization, bind, buffer, chat_disable, clear, connect, del, disconnect, event, group, help, iline, info, move, msay, pgp, quit, rawxml, rename, request, room, roster, say_to, say, screen_refresh, set, source, status_to, status, version. diff -r b2ed413d8f3d -r 7b8765c10abb mcabber/doc/help/uk/hlp.txt --- a/mcabber/doc/help/uk/hlp.txt Sat Apr 21 10:18:17 2007 +0200 +++ b/mcabber/doc/help/uk/hlp.txt Sat Apr 21 12:06:13 2007 +0200 @@ -3,4 +3,4 @@ Друкує допоміжну інформацію про команду або вираз. Без аргументу друкує оце повідомлення. -Наявні команди: add, alias, authorization, bind, buffer, chat_disable, clear, connect, del, disconnect, event, group, help, iline, info, move, msay, pgp, quit, rawxml, rename, request, room, roster, say_to, say, screen_refresh, set, status_to, status, version. +Наявні команди: add, alias, authorization, bind, buffer, chat_disable, clear, connect, del, disconnect, event, group, help, iline, info, move, msay, pgp, quit, rawxml, rename, request, room, roster, say_to, say, screen_refresh, set, source, status_to, status, version. diff -r b2ed413d8f3d -r 7b8765c10abb mcabber/src/commands.c --- a/mcabber/src/commands.c Sat Apr 21 10:18:17 2007 +0200 +++ b/mcabber/src/commands.c Sat Apr 21 12:06:13 2007 +0200 @@ -76,6 +76,7 @@ static void do_iline(char *arg); static void do_screen_refresh(char *arg); static void do_chat_disable(char *arg); +static void do_source(char *arg); // Global variable for the commands list static GSList *Commands; @@ -138,6 +139,7 @@ &do_say_to); //cmd_add("search"); cmd_add("set", "Set/query an option value", 0, 0, &do_set); + cmd_add("source", "Read a configuration file", 0, 0, &do_source); cmd_add("status", "Show or set your status", COMPL_STATUS, 0, &do_status); cmd_add("status_to", "Show or set your status for one recipient", COMPL_JID, COMPL_STATUS, &do_status_to); @@ -2801,6 +2803,26 @@ readline_disable_chat_mode(); } +static void do_source(char *arg) +{ + static int recur_level; + gchar *filename; + if (!*arg) { + scr_LogPrint(LPRINT_NORMAL, "Missing filename."); + return; + } + if (recur_level > 20) { + scr_LogPrint(LPRINT_LOGNORM, "** Too many source commands!"); + return; + } + filename = g_strdup(arg); + strip_arg_special_chars(filename); + recur_level++; + cfg_read_file(filename, FALSE); + recur_level--; + g_free(filename); +} + static void do_connect(char *arg) { mcabber_connect(); diff -r b2ed413d8f3d -r 7b8765c10abb mcabber/src/main.c --- a/mcabber/src/main.c Sat Apr 21 10:18:17 2007 +0200 +++ b/mcabber/src/main.c Sat Apr 21 12:06:13 2007 +0200 @@ -332,7 +332,7 @@ scr_InitLocaleCharSet(); /* Parsing config file... */ - ret = cfg_read_file(configFile); + ret = cfg_read_file(configFile, TRUE); /* free() configFile if it has been allocated during options parsing */ g_free(configFile); /* Leave if there was an error in the config. file */ diff -r b2ed413d8f3d -r 7b8765c10abb mcabber/src/settings.c --- a/mcabber/src/settings.c Sat Apr 21 10:18:17 2007 +0200 +++ b/mcabber/src/settings.c Sat Apr 21 12:06:13 2007 +0200 @@ -61,11 +61,14 @@ #endif } -// cfg_read_file(filename) +// cfg_read_file(filename, mainfile) // Read and parse config file "filename". If filename is NULL, // try to open the configuration file at the default locations. +// mainfile must be set to TRUE for the startup config file. +// If mainfile is TRUE, the permissions of the configuration file will +// be fixed if they're insecure. // -int cfg_read_file(char *filename) +int cfg_read_file(char *filename, guint mainfile) { FILE *fp; char *buf; @@ -75,7 +78,14 @@ if (!filename) { // Use default config file locations - char *home = getenv("HOME"); + char *home; + + if (!mainfile) { + scr_LogPrint(LPRINT_LOGNORM, "No file name provided"); + return -1; + } + + home = getenv("HOME"); if (!home) { scr_LogPrint(LPRINT_LOG, "Can't find home dir!"); fprintf(stderr, "Can't find home dir!\n"); @@ -95,17 +105,25 @@ // Check configuration file permissions // As it could contain sensitive data, we make it user-readable only checkset_perm(filename, TRUE); + scr_LogPrint(LPRINT_LOGNORM, "Reading %s", filename); // Check mcabber dir. There we just warn, we don't change the modes sprintf(filename, "%s/.mcabber/", home); checkset_perm(filename, FALSE); g_free(filename); + filename = NULL; } else { if ((fp = fopen(filename, "r")) == NULL) { - perror("Cannot open configuration file"); + const char *msg = "Cannot open configuration file"; + if (mainfile) + perror(msg); + else + scr_LogPrint(LPRINT_LOGNORM, "%s (%s).", msg, filename); return -2; } // Check configuration file permissions (see above) - checkset_perm(filename, TRUE); + // We don't change the permissions if that's not the main file. + checkset_perm(filename, mainfile); + scr_LogPrint(LPRINT_LOGNORM, "Reading %s", filename); } buf = g_new(char, 512); @@ -133,12 +151,13 @@ if ((*line == '\n') || (*line == '\0') || (*line == '#')) continue; - if ((strchr(line, '=') != NULL) || !strncmp(line, "pgp ", strlen("pgp "))) { - // Only accept the set, alias, bind and pgp commands - if (strncmp(line, "set ", strlen("set ")) && - strncmp(line, "pgp ", strlen("pgp ")) && - strncmp(line, "bind ", strlen("bind ")) && - strncmp(line, "alias ", strlen("alias "))) { + // We only allow assignments line, except for commands "pgp" and "source" + if ((strchr(line, '=') != NULL) || + startswith(line, "pgp ") || startswith(line, "source ")) { + // Only accept the set, alias, bind, pgp and source commands + if (!startswith(line, "set ") && !startswith(line, "bind ") && + !startswith(line, "alias ") && !startswith(line, "pgp ") && + !startswith(line, "source ")) { scr_LogPrint(LPRINT_LOGNORM, "Error in configuration file (l. %d): bad command", ln); err++; @@ -156,6 +175,9 @@ } g_free(buf); fclose(fp); + + if (filename) + scr_LogPrint(LPRINT_LOGNORM, "Loaded %s.", filename); return err; } diff -r b2ed413d8f3d -r 7b8765c10abb mcabber/src/settings.h --- a/mcabber/src/settings.h Sat Apr 21 10:18:17 2007 +0200 +++ b/mcabber/src/settings.h Sat Apr 21 12:06:13 2007 +0200 @@ -24,7 +24,7 @@ #define mkcmdstr(cmd) COMMAND_CHARSTR cmd void settings_init(void); -int cfg_read_file(char *filename); +int cfg_read_file(char *filename, guint mainfile); guint parse_assigment(gchar *assignment, gchar **pkey, gchar **pval); void settings_set(guint type, const gchar *key, const gchar *value); void settings_del(guint type, const gchar *key); diff -r b2ed413d8f3d -r 7b8765c10abb mcabber/src/utils.c --- a/mcabber/src/utils.c Sat Apr 21 10:18:17 2007 +0200 +++ b/mcabber/src/utils.c Sat Apr 21 12:06:13 2007 +0200 @@ -648,4 +648,13 @@ } #endif /* !HAVE_STRCASESTR */ +// startswith(str, word) +// Returns TRUE if string str starts with word. +int startswith(const char *str, const char *word) +{ + if (!strncmp(str, word, strlen(word))) + return TRUE; + return FALSE; +} + /* vim: set expandtab cindent cinoptions=>2\:2(0: For Vim users... */ diff -r b2ed413d8f3d -r 7b8765c10abb mcabber/src/utils.h --- a/mcabber/src/utils.h Sat Apr 21 10:18:17 2007 +0200 +++ b/mcabber/src/utils.h Sat Apr 21 12:06:13 2007 +0200 @@ -43,6 +43,8 @@ char *strcasestr(const char *haystack, const char *needle); #endif +int startswith(const char *str, const char *word); + #endif // __UTILS_H__ /* vim: set expandtab cindent cinoptions=>2\:2(0: For Vim users... */