int gui_color_timer_warning_pairs_full (void *data, int remaining_calls) { /* make C compiler happy */ (void) data; (void) remaining_calls; gui_chat_printf (NULL, _("Warning: the %d color pairs are used, do " "\"/color reset\" to remove unused pairs"), gui_color_num_pairs); return WEECHAT_RC_OK; }
void debug_hdata_hash_list_map_cb (void *data, struct t_hashtable *hashtable, const void *key, const void *value) { /* make C compiler happy */ (void) data; (void) hashtable; gui_chat_printf (NULL, " list: %s -> 0x%lx", (char *)key, *((void **)value)); }
void debug_hooks () { int i, num_hooks, num_hooks_total; struct t_hook *ptr_hook; gui_chat_printf (NULL, ""); gui_chat_printf (NULL, "hooks in memory:"); num_hooks_total = 0; for (i = 0; i < HOOK_NUM_TYPES; i++) { num_hooks = 0; for (ptr_hook = weechat_hooks[i]; ptr_hook; ptr_hook = ptr_hook->next_hook) { num_hooks++; } gui_chat_printf (NULL, "%17s:%5d", hook_type_string[i], num_hooks); num_hooks_total += num_hooks; } gui_chat_printf (NULL, "%17s------", "---------"); gui_chat_printf (NULL, "%17s:%5d", "total", num_hooks_total); }
void input_exec_data (struct t_gui_buffer *buffer, const char *data) { if (buffer->input_callback) { (void)(buffer->input_callback) (buffer->input_callback_data, buffer, data); } else gui_chat_printf (buffer, _("%sYou can not write text in this " "buffer"), gui_chat_prefix[GUI_CHAT_PREFIX_ERROR]); }
int secure_init () { int rc; char *ptr_phrase; /* try to read passphrase (if not set) from env var "WEECHAT_PASSPHRASE" */ if (!secure_passphrase) { ptr_phrase = getenv (SECURE_ENV_PASSPHRASE); if (ptr_phrase) { if (ptr_phrase[0]) secure_passphrase = strdup (ptr_phrase); unsetenv (SECURE_ENV_PASSPHRASE); } } secure_hashtable_data = hashtable_new (32, WEECHAT_HASHTABLE_STRING, WEECHAT_HASHTABLE_STRING, NULL, NULL); if (!secure_hashtable_data) return 0; secure_hashtable_data_encrypted = hashtable_new (32, WEECHAT_HASHTABLE_STRING, WEECHAT_HASHTABLE_STRING, NULL, NULL); if (!secure_hashtable_data_encrypted) { hashtable_free (secure_hashtable_data); return 0; } rc = secure_init_options (); if (!rc) { gui_chat_printf (NULL, _("FATAL: error initializing configuration options")); } return rc; }
void debug_directories () { gui_chat_printf (NULL, ""); gui_chat_printf (NULL, _("Directories:")); gui_chat_printf (NULL, " home : %s (%s: %s)", weechat_home, _("default"), WEECHAT_HOME); gui_chat_printf (NULL, " lib : %s", WEECHAT_LIBDIR); gui_chat_printf (NULL, " share : %s", WEECHAT_SHAREDIR); gui_chat_printf (NULL, " locale: %s", LOCALEDIR); }
void debug_directories () { char *extra_libdir; extra_libdir = getenv (WEECHAT_EXTRA_LIBDIR); gui_chat_printf (NULL, ""); gui_chat_printf (NULL, _("Directories:")); gui_chat_printf (NULL, " home: %s (%s: %s)", weechat_home, _("default"), WEECHAT_HOME); gui_chat_printf (NULL, " lib: %s", WEECHAT_LIBDIR); gui_chat_printf (NULL, " lib (extra): %s", (extra_libdir && extra_libdir[0]) ? extra_libdir : "-"); gui_chat_printf (NULL, " share: %s", WEECHAT_SHAREDIR); gui_chat_printf (NULL, " locale: %s", LOCALEDIR); }
void secure_get_passphrase_from_user (const char *error) { const char *prompt[5]; char passphrase[1024]; prompt[0] = _("Please enter your passphrase to decrypt the data secured " "by WeeChat:"); prompt[1] = _("(enter just one space to skip the passphrase, but this " "will DISABLE all secured data!)"); prompt[2] = _("(press ctrl-C to exit WeeChat now)"); prompt[3] = error; prompt[4] = NULL; while (1) { gui_main_get_password (prompt, passphrase, sizeof (passphrase)); if (secure_passphrase) { free (secure_passphrase); secure_passphrase = NULL; } if (passphrase[0]) { /* the special value " " (one space) disables passphrase */ if (strcmp (passphrase, " ") == 0) { gui_chat_printf (NULL, _("To recover your secured data, you can " "use /secure decrypt (see /help secure)")); } else if (strcmp (passphrase, "\x03") == 0) { /* ctrl-C pressed, just exit now */ exit (1); } else secure_passphrase = strdup (passphrase); return; } } }
void util_setrlimit () { #ifdef HAVE_SYS_RESOURCE_H char **items, *pos, *error; int num_items, i; long number; items = string_split (CONFIG_STRING(config_startup_sys_rlimit), ",", 0, 0, &num_items); if (items) { for (i = 0; i < num_items; i++) { pos = strchr (items[i], ':'); if (pos) { pos[0] = '\0'; error = NULL; number = strtol (pos + 1, &error, 10); if (error && !error[0]) { util_setrlimit_resource (items[i], number); } else { gui_chat_printf (NULL, _("%sError: invalid limit for resource " "\"%s\": %s (must be >= -1)"), gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], items[i], pos + 1); } } } string_free_split (items); } #endif /* HAVE_SYS_RESOURCE_H */ }
int secure_reload_cb (void *data, struct t_config_file *config_file) { /* make C compiler happy */ (void) data; if (secure_hashtable_data_encrypted->items_count > 0) { gui_chat_printf (NULL, _("%sError: not possible to reload file sec.conf " "because there is still encrypted data (use /secure " "decrypt, see /help secure)"), gui_chat_prefix[GUI_CHAT_PREFIX_ERROR]); return WEECHAT_CONFIG_READ_FILE_NOT_FOUND; } secure_data_encrypted = 0; /* remove all secured data */ hashtable_remove_all (secure_hashtable_data); return config_file_reload (config_file); }
void debug_infolists () { struct t_infolist *ptr_infolist; struct t_infolist_item *ptr_item; struct t_infolist_var *ptr_var; int i, count, count_items, count_vars, size_structs, size_data; int total_items, total_vars, total_size; count = 0; for (ptr_infolist = weechat_infolists; ptr_infolist; ptr_infolist = ptr_infolist->next_infolist) { count++; } gui_chat_printf (NULL, ""); gui_chat_printf (NULL, "%d infolists in memory (%s)", count, (count == 0) ? "this is OK!" : "WARNING: this is probably a memory leak in WeeChat or " "plugins/scripts!"); if (count > 0) { i = 0; total_items = 0; total_vars = 0; total_size = 0; for (ptr_infolist = weechat_infolists; ptr_infolist; ptr_infolist = ptr_infolist->next_infolist) { count_items = 0; count_vars = 0; size_structs = sizeof (*ptr_infolist); size_data = 0; for (ptr_item = ptr_infolist->items; ptr_item; ptr_item = ptr_item->next_item) { count_items++; total_items++; size_structs += sizeof (*ptr_item); for (ptr_var = ptr_item->vars; ptr_var; ptr_var = ptr_var->next_var) { count_vars++; total_vars++; size_structs += sizeof (*ptr_var); if (ptr_var->value) { switch (ptr_var->type) { case INFOLIST_INTEGER: size_data += sizeof (int); break; case INFOLIST_STRING: size_data += strlen ((char *)(ptr_var->value)); break; case INFOLIST_POINTER: size_data += sizeof (void *); break; case INFOLIST_BUFFER: size_data += ptr_var->size; break; case INFOLIST_TIME: size_data += sizeof (time_t); break; } } } } gui_chat_printf (NULL, "%4d: infolist 0x%lx: %d items, %d vars - " "structs: %d, data: %d (total: %d bytes)", i + 1, ptr_infolist, count_items, count_vars, size_structs, size_data, size_structs + size_data); total_size += size_structs + size_data; i++; } gui_chat_printf (NULL, "Total: %d items, %d vars - %d bytes", total_items, total_vars, total_size); } }
void debug_memory () { #ifdef HAVE_MALLINFO struct mallinfo info; info = mallinfo (); gui_chat_printf (NULL, ""); gui_chat_printf (NULL, _("Memory usage (see \"man mallinfo\" for help):")); gui_chat_printf (NULL, " arena :%10d", info.arena); gui_chat_printf (NULL, " ordblks :%10d", info.ordblks); gui_chat_printf (NULL, " smblks :%10d", info.smblks); gui_chat_printf (NULL, " hblks :%10d", info.hblks); gui_chat_printf (NULL, " hblkhd :%10d", info.hblkhd); gui_chat_printf (NULL, " usmblks :%10d", info.usmblks); gui_chat_printf (NULL, " fsmblks :%10d", info.fsmblks); gui_chat_printf (NULL, " uordblks:%10d", info.uordblks); gui_chat_printf (NULL, " fordblks:%10d", info.fordblks); gui_chat_printf (NULL, " keepcost:%10d", info.keepcost); #else gui_chat_printf (NULL, _("Memory usage not available (function \"mallinfo\" not " "found)")); #endif /* HAVE_MALLINFO */ }
void util_setrlimit_resource (const char *resource_name, long limit) { int i; struct rlimit rlim; char str_limit[64]; if (!resource_name) return; if (limit == -1) snprintf (str_limit, sizeof (str_limit), "unlimited"); else snprintf (str_limit, sizeof (str_limit), "%ld", limit); for (i = 0; rlimit_resource[i].name; i++) { if (strcmp (rlimit_resource[i].name, resource_name) == 0) { if (limit < -1) { gui_chat_printf (NULL, _("%sError: invalid limit for resource \"%s\": " "%s (must be >= -1)"), gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], resource_name, str_limit); return; } rlim.rlim_cur = (limit >= 0) ? (rlim_t)limit : RLIM_INFINITY; rlim.rlim_max = rlim.rlim_cur; if (setrlimit (rlimit_resource[i].resource, &rlim) == 0) { log_printf (_("Limit for resource \"%s\" has been set to %s"), resource_name, str_limit); if (gui_init_ok) { gui_chat_printf (NULL, _("Limit for resource \"%s\" has been set " "to %s"), resource_name, str_limit); } } else { gui_chat_printf (NULL, _("%sError: unable to set resource limit " "\"%s\" to %s: error %d %s"), gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], resource_name, str_limit, errno, strerror (errno)); } return; } } gui_chat_printf (NULL, _("%sError: unknown resource limit \"%s\" (see /help " "weechat.startup.sys_rlimit)"), gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], resource_name); }
void weechat_startup_message () { if (weechat_headless) { string_fprintf (stdout, _("WeeChat is running in headless mode " "(Ctrl-C to quit).")); string_fprintf (stdout, "\n"); } if (CONFIG_BOOLEAN(config_startup_display_logo)) { gui_chat_printf ( NULL, "%s ___ __ ______________ _____ \n" "%s __ | / /___________ ____/__ /_______ __ /_\n" "%s __ | /| / /_ _ \\ _ \\ / __ __ \\ __ `/ __/\n" "%s __ |/ |/ / / __/ __/ /___ _ / / / /_/ // /_ \n" "%s ____/|__/ \\___/\\___/\\____/ /_/ /_/\\__,_/ \\__/ ", GUI_COLOR(GUI_COLOR_CHAT_NICK), GUI_COLOR(GUI_COLOR_CHAT_NICK), GUI_COLOR(GUI_COLOR_CHAT_NICK), GUI_COLOR(GUI_COLOR_CHAT_NICK), GUI_COLOR(GUI_COLOR_CHAT_NICK)); } if (CONFIG_BOOLEAN(config_startup_display_version)) { command_version_display (NULL, 0, 0, 0); } if (CONFIG_BOOLEAN(config_startup_display_logo) || CONFIG_BOOLEAN(config_startup_display_version)) { gui_chat_printf ( NULL, "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -"); } if (weechat_first_start) { /* message on first run (when weechat.conf is created) */ gui_chat_printf (NULL, ""); gui_chat_printf ( NULL, _("Welcome to WeeChat!\n" "\n" "If you are discovering WeeChat, it is recommended to read at " "least the quickstart guide, and the user's guide if you have " "some time; they explain main WeeChat concepts.\n" "All WeeChat docs are available at: https://weechat.org/doc\n" "\n" "Moreover, there is inline help with /help on all commands and " "options (use Tab key to complete the name).\n" "The command /fset can help to customize WeeChat.\n" "\n" "You can add and connect to an IRC server with /server and " "/connect commands (see /help server).")); gui_chat_printf (NULL, ""); gui_chat_printf (NULL, "---"); gui_chat_printf (NULL, ""); } }
int secure_data_read_cb (void *data, struct t_config_file *config_file, struct t_config_section *section, const char *option_name, const char *value) { char *buffer, *decrypted, str_error[1024]; int length_buffer, length_decrypted, rc; /* make C compiler happy */ (void) data; (void) config_file; (void) section; if (!option_name || !value || !value[0]) { return WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE; } /* special line indicating if a passphrase must be used to decrypt data */ if (strcmp (option_name, SECURE_DATA_PASSPHRASE_FLAG) == 0) { secure_data_encrypted = config_file_string_to_boolean (value); if (secure_data_encrypted && !secure_passphrase && !gui_init_ok) { /* if a passphrase file is set, use it */ if (CONFIG_STRING(secure_config_crypt_passphrase_file)[0]) secure_passphrase = secure_get_passphrase_from_file (CONFIG_STRING(secure_config_crypt_passphrase_file)); /* ask passphrase to the user (if no file, or file not found) */ if (!secure_passphrase) secure_get_passphrase_from_user (""); } return WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE; } if (!secure_data_encrypted) { /* clear data: just store value in hashtable */ hashtable_set (secure_hashtable_data, option_name, value); return WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE; } /* check that passphrase is set */ if (!secure_passphrase) { gui_chat_printf (NULL, _("%sPassphrase is not set, unable to decrypt data \"%s\""), gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], option_name); hashtable_set (secure_hashtable_data_encrypted, option_name, value); return WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE; } /* decrypt data */ buffer = malloc (strlen (value) + 1); if (!buffer) return WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE; length_buffer = string_decode_base16 (value, buffer); while (1) { decrypted = NULL; length_decrypted = 0; rc = secure_decrypt_data (buffer, length_buffer, secure_hash_algo[CONFIG_INTEGER(secure_config_crypt_hash_algo)], secure_cipher[CONFIG_INTEGER(secure_config_crypt_cipher)], secure_passphrase, &decrypted, &length_decrypted); if (rc == 0) { if (decrypted) { hashtable_set (secure_hashtable_data, option_name, decrypted); free (decrypted); break; } } else { if (decrypted) free (decrypted); if (gui_init_ok) { gui_chat_printf (NULL, _("%sWrong passphrase, unable to decrypt data " "\"%s\""), gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], option_name); break; } snprintf (str_error, sizeof (str_error), _("*** Wrong passphrase (decrypt error: %s) ***"), secure_decrypt_error[(rc * -1) - 1]); secure_get_passphrase_from_user (str_error); if (!secure_passphrase) { gui_chat_printf (NULL, _("%sPassphrase is not set, unable to decrypt " "data \"%s\""), gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], option_name); hashtable_set (secure_hashtable_data_encrypted, option_name, value); break; } } } free (buffer); return WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE; }
void input_exec_command (struct t_gui_buffer *buffer, int any_plugin, struct t_weechat_plugin *plugin, const char *string) { int rc; char *command, *pos, *ptr_args; if ((!string) || (!string[0])) return; command = strdup (string); if (!command) return ; /* look for end of command */ ptr_args = NULL; pos = &command[strlen (command) - 1]; if (pos[0] == ' ') { while ((pos > command) && (pos[0] == ' ')) pos--; pos[1] = '\0'; } rc = hook_command_exec (buffer, any_plugin, plugin, command); pos = strchr (command, ' '); if (pos) { pos[0] = '\0'; pos++; while (pos[0] == ' ') pos++; ptr_args = pos; if (!ptr_args[0]) ptr_args = NULL; } switch (rc) { case 0: /* command hooked, KO */ gui_chat_printf (NULL, _("%sError with command \"%s\" (try /help %s)"), gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], command + 1, command + 1); break; case 1: /* command hooked, OK (executed) */ break; case -2: /* command is ambiguous (exists for other plugins) */ gui_chat_printf (NULL, _("%sError: ambiguous command \"%s\": it exists " "in many plugins and not in \"%s\" plugin"), gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], command + 1, plugin_get_name (plugin)); break; case -3: /* command is running */ gui_chat_printf (NULL, _("%sError: too much calls to command \"%s\" " "(looping)"), gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], command + 1); break; default: /* no command hooked */ /* * if unknown commands are accepted by this buffer, just send * input text as data to buffer, otherwise display error */ if (buffer->input_get_unknown_commands) { input_exec_data (buffer, string); } else { gui_chat_printf (NULL, _("%sError: unknown command \"%s\" (type " "/help for help)"), gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], command + 1); } break; } free (command); }