struct t_hashtable * irc_info_get_info_hashtable_cb (void *data, const char *info_name, struct t_hashtable *hashtable) { const char *server, *message; struct t_irc_server *ptr_server; struct t_hashtable *value; /* make C compiler happy */ (void) data; if (!hashtable) return NULL; if (weechat_strcasecmp (info_name, "irc_message_parse") == 0) { server = weechat_hashtable_get (hashtable, "server"); ptr_server = (server) ? irc_server_search (server) : NULL; message = weechat_hashtable_get (hashtable, "message"); if (message) { value = irc_message_parse_to_hashtable (ptr_server, message); return value; } } else if (weechat_strcasecmp (info_name, "irc_message_split") == 0) { server = weechat_hashtable_get (hashtable, "server"); ptr_server = (server) ? irc_server_search (server) : NULL; message = weechat_hashtable_get (hashtable, "message"); if (message) { value = irc_message_split (ptr_server, message); return value; } } return NULL; }
struct t_infolist * xfer_info_get_infolist_cb (void *data, const char *infolist_name, void *pointer, const char *arguments) { struct t_infolist *ptr_infolist; struct t_xfer *ptr_xfer; /* make C compiler happy */ (void) data; (void) arguments; if (!infolist_name || !infolist_name[0]) return NULL; if (weechat_strcasecmp (infolist_name, "xfer") == 0) { if (pointer && !xfer_valid (pointer)) return NULL; ptr_infolist = weechat_infolist_new (); if (ptr_infolist) { if (pointer) { /* build list with only one xfer */ if (!xfer_add_to_infolist (ptr_infolist, pointer)) { weechat_infolist_free (ptr_infolist); return NULL; } return ptr_infolist; } else { /* build list with all xfers */ for (ptr_xfer = xfer_list; ptr_xfer; ptr_xfer = ptr_xfer->next_xfer) { if (!xfer_add_to_infolist (ptr_infolist, ptr_xfer)) { weechat_infolist_free (ptr_infolist); return NULL; } } return ptr_infolist; } } } return NULL; }
struct t_infolist * relay_info_get_infolist_cb (void *data, const char *infolist_name, void *pointer, const char *arguments) { struct t_infolist *ptr_infolist; struct t_relay_client *ptr_client; /* make C compiler happy */ (void) data; (void) arguments; if (!infolist_name || !infolist_name[0]) return NULL; if (weechat_strcasecmp (infolist_name, "relay") == 0) { if (pointer && !relay_client_valid (pointer)) return NULL; ptr_infolist = weechat_infolist_new (); if (ptr_infolist) { if (pointer) { /* build list with only one relay */ if (!relay_client_add_to_infolist (ptr_infolist, pointer)) { weechat_infolist_free (ptr_infolist); return NULL; } return ptr_infolist; } else { /* build list with all relays */ for (ptr_client = relay_clients; ptr_client; ptr_client = ptr_client->next_client) { if (!relay_client_add_to_infolist (ptr_infolist, ptr_client)) { weechat_infolist_free (ptr_infolist); return NULL; } } return ptr_infolist; } } } return NULL; }
int logger_command_cb (void *data, struct t_gui_buffer *buffer, int argc, char **argv, char **argv_eol) { /* make C compiler happy */ (void) data; (void) argv_eol; if ((argc == 1) || ((argc == 2) && (weechat_strcasecmp (argv[1], "list") == 0))) { logger_list (); return WEECHAT_RC_OK; } if (argc > 1) { if (weechat_strcasecmp (argv[1], "set") == 0) { if (argc > 2) logger_set_buffer (buffer, argv[2]); return WEECHAT_RC_OK; } if (weechat_strcasecmp (argv[1], "flush") == 0) { logger_flush (); return WEECHAT_RC_OK; } if (weechat_strcasecmp (argv[1], "disable") == 0) { logger_set_buffer (buffer, "0"); } } return WEECHAT_RC_OK; }
const char * irc_ctcp_get_default_reply (const char *ctcp) { int i; for (i = 0; irc_ctcp_default_reply[i].name; i++) { if (weechat_strcasecmp (irc_ctcp_default_reply[i].name, ctcp) == 0) return irc_ctcp_default_reply[i].reply; } /* unknown CTCP */ return NULL; }
struct t_alias * alias_find_pos (const char *name) { struct t_alias *ptr_alias; for (ptr_alias = alias_list; ptr_alias; ptr_alias = ptr_alias->next_alias) { if (weechat_strcasecmp (name, ptr_alias->name) < 0) return ptr_alias; } /* position not found (we will add to the end of list) */ return NULL; }
int trigger_search_post_action (const char *post_action) { int i; for (i = 0; i < TRIGGER_NUM_POST_ACTIONS; i++) { if (weechat_strcasecmp (trigger_post_action_string[i], post_action) == 0) return i; } /* post action not found */ return -1; }
int trigger_search_return_code (const char *return_code) { int i; for (i = 0; i < TRIGGER_NUM_RETURN_CODES; i++) { if (weechat_strcasecmp (trigger_return_code_string[i], return_code) == 0) return i; } /* return code not found */ return -1; }
int relay_weechat_compression_search (const char *compression) { int i; for (i = 0; i < RELAY_WEECHAT_NUM_COMPRESSIONS; i++) { if (weechat_strcasecmp (relay_weechat_compression_string[i], compression) == 0) return i; } /* compression not found */ return -1; }
int trigger_search_hook_type (const char *type) { int i; for (i = 0; i < TRIGGER_NUM_HOOK_TYPES; i++) { if (weechat_strcasecmp (trigger_hook_type_string[i], type) == 0) return i; } /* hook type not found */ return -1; }
struct t_trigger * trigger_find_pos (struct t_trigger *trigger, struct t_trigger *list_triggers) { struct t_trigger *ptr_trigger; for (ptr_trigger = list_triggers; ptr_trigger; ptr_trigger = ptr_trigger->next_trigger) { if (weechat_strcasecmp (trigger->name, ptr_trigger->name) < 0) return ptr_trigger; } /* position not found */ return NULL; }
int exec_search_color (const char *color) { int i; if (!color) return -1; for (i = 0; i < EXEC_NUM_COLORS; i++) { if (weechat_strcasecmp (exec_color_string[i], color) == 0) return i; } /* color not found */ return -1; }
int weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[]) { int i, upgrading; /* make C compiler happy */ (void) argc; (void) argv; weechat_plugin = plugin; if (!relay_config_init ()) return WEECHAT_RC_ERROR; relay_config_read (); relay_network_init (); relay_command_init (); /* hook completions */ relay_completion_init (); weechat_hook_signal ("upgrade", &relay_signal_upgrade_cb, NULL, NULL); weechat_hook_signal ("debug_dump", &relay_debug_dump_cb, NULL, NULL); relay_info_init (); /* look at arguments */ upgrading = 0; for (i = 0; i < argc; i++) { if (weechat_strcasecmp (argv[i], "--upgrade") == 0) { upgrading = 1; } } if (upgrading) relay_upgrade_load (); relay_hook_timer = weechat_hook_timer (1 * 1000, 0, 0, &relay_client_timer_cb, NULL, NULL); return WEECHAT_RC_OK; }
int trigger_search_option (const char *option_name) { int i; if (!option_name) return -1; for (i = 0; i < TRIGGER_NUM_OPTIONS; i++) { if (weechat_strcasecmp (trigger_option_string[i], option_name) == 0) return i; } /* trigger option not found */ return -1; }
int weechat_lua_signal_debug_dump_cb (void *data, const char *signal, const char *type_data, void *signal_data) { /* make C compiler happy */ (void) data; (void) signal; (void) type_data; if (!signal_data || (weechat_strcasecmp ((char *)signal_data, LUA_PLUGIN_NAME) == 0)) { plugin_script_print_log (weechat_lua_plugin, lua_scripts); } return WEECHAT_RC_OK; }
struct t_trigger * trigger_search (const char *name) { struct t_trigger *ptr_trigger; if (!name || !name[0]) return NULL; for (ptr_trigger = triggers; ptr_trigger; ptr_trigger = ptr_trigger->next_trigger) { if (weechat_strcasecmp (ptr_trigger->name, name) == 0) return ptr_trigger; } /* trigger not found */ return NULL; }
struct t_infolist * weechat_lua_infolist_cb (void *data, const char *infolist_name, void *pointer, const char *arguments) { /* make C compiler happy */ (void) data; if (!infolist_name || !infolist_name[0]) return NULL; if (weechat_strcasecmp (infolist_name, "lua_script") == 0) { return plugin_script_infolist_list_scripts (weechat_lua_plugin, lua_scripts, pointer, arguments); } return NULL; }
struct t_infolist * weechat_js_infolist_cb (const void *pointer, void *data, const char *infolist_name, void *obj_pointer, const char *arguments) { /* make C++ compiler happy */ (void) pointer; (void) data; if (!infolist_name || !infolist_name[0]) return NULL; if (weechat_strcasecmp (infolist_name, "javascript_script") == 0) { return plugin_script_infolist_list_scripts (weechat_js_plugin, js_scripts, obj_pointer, arguments); } return NULL; }
int weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[]) { int i, upgrading; weechat_plugin = plugin; trigger_callback_init (); trigger_command_init (); if (!trigger_config_init ()) return WEECHAT_RC_ERROR; trigger_config_read (); /* hook some signals */ weechat_hook_signal ("debug_dump", &trigger_debug_dump_cb, NULL); /* hook completions */ trigger_completion_init (); /* look at arguments */ upgrading = 0; for (i = 0; i < argc; i++) { if (weechat_strcasecmp (argv[i], "--upgrade") == 0) { upgrading = 1; } } if (upgrading) trigger_buffer_set_callbacks (); return WEECHAT_RC_OK; }
int weechat_aspell_command_authorized (const char *command) { int length_command, i; if (!command) return 1; length_command = strlen (command); for (i = 0; i < weechat_aspell_count_commands_to_check; i++) { if ((weechat_aspell_length_commands_to_check[i] == length_command) && (weechat_strcasecmp (command, weechat_aspell_commands_to_check[i]) == 0)) { /* command is authorized */ return 1; } } /* command is not authorized */ return 0; }
int weechat_python_command_cb (void *data, struct t_gui_buffer *buffer, int argc, char **argv, char **argv_eol) { char *ptr_name, *path_script; /* make C compiler happy */ (void) data; (void) buffer; if (argc == 1) { plugin_script_display_list (weechat_python_plugin, python_scripts, NULL, 0); } else if (argc == 2) { if (weechat_strcasecmp (argv[1], "list") == 0) { plugin_script_display_list (weechat_python_plugin, python_scripts, NULL, 0); } else if (weechat_strcasecmp (argv[1], "listfull") == 0) { plugin_script_display_list (weechat_python_plugin, python_scripts, NULL, 1); } else if (weechat_strcasecmp (argv[1], "autoload") == 0) { plugin_script_auto_load (weechat_python_plugin, &weechat_python_load_cb); } else if (weechat_strcasecmp (argv[1], "reload") == 0) { weechat_python_unload_all (); plugin_script_auto_load (weechat_python_plugin, &weechat_python_load_cb); } else if (weechat_strcasecmp (argv[1], "unload") == 0) { weechat_python_unload_all (); } else WEECHAT_COMMAND_ERROR; } else { if (weechat_strcasecmp (argv[1], "list") == 0) { plugin_script_display_list (weechat_python_plugin, python_scripts, argv_eol[2], 0); } else if (weechat_strcasecmp (argv[1], "listfull") == 0) { plugin_script_display_list (weechat_python_plugin, python_scripts, argv_eol[2], 1); } else if ((weechat_strcasecmp (argv[1], "load") == 0) || (weechat_strcasecmp (argv[1], "reload") == 0) || (weechat_strcasecmp (argv[1], "unload") == 0)) { ptr_name = argv_eol[2]; if (strncmp (ptr_name, "-q ", 3) == 0) { python_quiet = 1; ptr_name += 3; while (ptr_name[0] == ' ') { ptr_name++; } } if (weechat_strcasecmp (argv[1], "load") == 0) { /* load python script */ path_script = plugin_script_search_path (weechat_python_plugin, ptr_name); weechat_python_load ((path_script) ? path_script : ptr_name); if (path_script) free (path_script); } else if (weechat_strcasecmp (argv[1], "reload") == 0) { /* reload one python script */ weechat_python_reload_name (ptr_name); } else if (weechat_strcasecmp (argv[1], "unload") == 0) { /* unload python script */ weechat_python_unload_name (ptr_name); } python_quiet = 0; } else WEECHAT_COMMAND_ERROR; } return WEECHAT_RC_OK; }
int weechat_lua_command_cb (void *data, struct t_gui_buffer *buffer, int argc, char **argv, char **argv_eol) { char *ptr_name, *path_script; /* make C compiler happy */ (void) data; (void) buffer; if (argc == 1) { plugin_script_display_list (weechat_lua_plugin, lua_scripts, NULL, 0); } else if (argc == 2) { if (weechat_strcasecmp (argv[1], "list") == 0) { plugin_script_display_list (weechat_lua_plugin, lua_scripts, NULL, 0); } else if (weechat_strcasecmp (argv[1], "listfull") == 0) { plugin_script_display_list (weechat_lua_plugin, lua_scripts, NULL, 1); } else if (weechat_strcasecmp (argv[1], "autoload") == 0) { plugin_script_auto_load (weechat_lua_plugin, &weechat_lua_load_cb); } else if (weechat_strcasecmp (argv[1], "reload") == 0) { weechat_lua_unload_all (); plugin_script_auto_load (weechat_lua_plugin, &weechat_lua_load_cb); } else if (weechat_strcasecmp (argv[1], "unload") == 0) { weechat_lua_unload_all (); } } else { if (weechat_strcasecmp (argv[1], "list") == 0) { plugin_script_display_list (weechat_lua_plugin, lua_scripts, argv_eol[2], 0); } else if (weechat_strcasecmp (argv[1], "listfull") == 0) { plugin_script_display_list (weechat_lua_plugin, lua_scripts, argv_eol[2], 1); } else if ((weechat_strcasecmp (argv[1], "load") == 0) || (weechat_strcasecmp (argv[1], "reload") == 0) || (weechat_strcasecmp (argv[1], "unload") == 0)) { ptr_name = argv_eol[2]; if (strncmp (ptr_name, "-q ", 3) == 0) { lua_quiet = 1; ptr_name += 3; while (ptr_name[0] == ' ') { ptr_name++; } } if (weechat_strcasecmp (argv[1], "load") == 0) { /* load Lua script */ path_script = plugin_script_search_path (weechat_lua_plugin, ptr_name); weechat_lua_load ((path_script) ? path_script : ptr_name); if (path_script) free (path_script); } else if (weechat_strcasecmp (argv[1], "reload") == 0) { /* reload one Lua script */ weechat_lua_reload_name (ptr_name); } else if (weechat_strcasecmp (argv[1], "unload") == 0) { /* unload Lua script */ weechat_lua_unload_name (ptr_name); } lua_quiet = 0; } else { weechat_printf (NULL, weechat_gettext ("%s%s: unknown option for " "command \"%s\""), weechat_prefix ("error"), LUA_PLUGIN_NAME, "lua"); } } return WEECHAT_RC_OK; }
int exec_command_parse_options (struct t_exec_cmd_options *cmd_options, int argc, char **argv, int start_arg, int set_command_index) { int i, j, end, length, length_total; char *error; for (i = start_arg; i < argc; i++) { if (weechat_strcasecmp (argv[i], "-sh") == 0) { cmd_options->use_shell = 1; } else if (weechat_strcasecmp (argv[i], "-nosh") == 0) { cmd_options->use_shell = 0; } else if (weechat_strcasecmp (argv[i], "-bg") == 0) { cmd_options->detached = 1; } else if (weechat_strcasecmp (argv[i], "-nobg") == 0) { cmd_options->detached = 0; } else if (weechat_strcasecmp (argv[i], "-stdin") == 0) { cmd_options->pipe_stdin = 1; } else if (weechat_strcasecmp (argv[i], "-nostdin") == 0) { cmd_options->pipe_stdin = 0; } else if (weechat_strcasecmp (argv[i], "-buffer") == 0) { if (i + 1 >= argc) return 0; i++; cmd_options->ptr_buffer_name = argv[i]; cmd_options->ptr_buffer = weechat_buffer_search ("==", argv[i]); if (cmd_options->ptr_buffer && (weechat_buffer_get_integer (cmd_options->ptr_buffer, "type") != 0)) { /* only a buffer with formatted content is allowed */ return 0; } if (!cmd_options->ptr_buffer) cmd_options->new_buffer = 1; } else if (weechat_strcasecmp (argv[i], "-l") == 0) { cmd_options->output_to_buffer = 0; cmd_options->new_buffer = 0; } else if (weechat_strcasecmp (argv[i], "-o") == 0) { cmd_options->output_to_buffer = 1; cmd_options->new_buffer = 0; } else if (weechat_strcasecmp (argv[i], "-n") == 0) { cmd_options->output_to_buffer = 0; cmd_options->new_buffer = 1; } else if (weechat_strcasecmp (argv[i], "-nf") == 0) { cmd_options->output_to_buffer = 0; cmd_options->new_buffer = 2; } else if (weechat_strcasecmp (argv[i], "-cl") == 0) { cmd_options->new_buffer_clear = 1; } else if (weechat_strcasecmp (argv[i], "-nocl") == 0) { cmd_options->new_buffer_clear = 0; } else if (weechat_strcasecmp (argv[i], "-sw") == 0) { cmd_options->switch_to_buffer = 1; } else if (weechat_strcasecmp (argv[i], "-nosw") == 0) { cmd_options->switch_to_buffer = 0; } else if (weechat_strcasecmp (argv[i], "-ln") == 0) { cmd_options->line_numbers = 1; } else if (weechat_strcasecmp (argv[i], "-noln") == 0) { cmd_options->line_numbers = 0; } else if (weechat_strcasecmp (argv[i], "-flush") == 0) { cmd_options->flush = 1; } else if (weechat_strcasecmp (argv[i], "-noflush") == 0) { cmd_options->flush = 0; } else if (weechat_strcasecmp (argv[i], "-color") == 0) { if (i + 1 >= argc) return 0; i++; cmd_options->color = exec_search_color (argv[i]); if (cmd_options->color < 0) return 0; } else if (weechat_strcasecmp (argv[i], "-rc") == 0) { cmd_options->display_rc = 1; } else if (weechat_strcasecmp (argv[i], "-norc") == 0) { cmd_options->display_rc = 0; } else if (weechat_strcasecmp (argv[i], "-timeout") == 0) { if (i + 1 >= argc) return 0; i++; error = NULL; cmd_options->timeout = strtol (argv[i], &error, 10); if (!error || error[0]) return 0; } else if (weechat_strcasecmp (argv[i], "-name") == 0) { if (i + 1 >= argc) return 0; i++; cmd_options->ptr_command_name = argv[i]; } else if (weechat_strcasecmp (argv[i], "-pipe") == 0) { if (i + 1 >= argc) return 0; i++; if (cmd_options->pipe_command) { free (cmd_options->pipe_command); cmd_options->pipe_command = NULL; } if (argv[i][0] == '"') { /* search the ending double quote */ length_total = 1; end = i; while (end < argc) { length = strlen (argv[end]); length_total += length + 1; if ((length > 0) && (argv[end][length - 1] == '"')) break; end++; } if (end == argc) return 0; cmd_options->pipe_command = malloc (length_total); if (!cmd_options->pipe_command) return 0; cmd_options->pipe_command[0] = '\0'; for (j = i; j <= end; j++) { if (cmd_options->pipe_command[0]) strcat (cmd_options->pipe_command, " "); strcat (cmd_options->pipe_command, (j == i) ? argv[j] + 1 : argv[j]); } length = strlen (cmd_options->pipe_command); if (length > 0) cmd_options->pipe_command[length - 1] = '\0'; i = end; } else cmd_options->pipe_command = strdup (argv[i]); } else if (weechat_strcasecmp (argv[i], "-hsignal") == 0) { if (i + 1 >= argc) return 0; i++; if (cmd_options->hsignal) { free (cmd_options->hsignal); cmd_options->hsignal = NULL; } cmd_options->hsignal = strdup (argv[i]); } else { if (set_command_index) { cmd_options->command_index = i; break; } else return 0; } } return 1; }
int exec_command_exec (void *data, struct t_gui_buffer *buffer, int argc, char **argv, char **argv_eol) { int i, length, count; char *text; struct t_exec_cmd *ptr_exec_cmd, *ptr_next_exec_cmd; /* make C compiler happy */ (void) data; (void) buffer; /* list running commands */ if ((argc == 1) || ((argc == 2) && (weechat_strcasecmp (argv[1], "-list") == 0))) { exec_command_list (); return WEECHAT_RC_OK; } /* send text to a running process */ if (weechat_strcasecmp (argv[1], "-in") == 0) { WEECHAT_COMMAND_MIN_ARGS(4, "-in"); ptr_exec_cmd = exec_command_search_running_id (argv[2]); if (ptr_exec_cmd && ptr_exec_cmd->hook) { length = strlen (argv_eol[3]) + 1 + 1; text = malloc (length); if (text) { snprintf (text, length, "%s\n", argv_eol[3]); weechat_hook_set (ptr_exec_cmd->hook, "stdin", text); free (text); } } return WEECHAT_RC_OK; } /* send text to a running process (if given), then close stdin */ if (weechat_strcasecmp (argv[1], "-inclose") == 0) { WEECHAT_COMMAND_MIN_ARGS(3, "-inclose"); ptr_exec_cmd = exec_command_search_running_id (argv[2]); if (ptr_exec_cmd && ptr_exec_cmd->hook) { if (argc > 3) { length = strlen (argv_eol[3]) + 1 + 1; text = malloc (length); if (text) { snprintf (text, length, "%s\n", argv_eol[3]); weechat_hook_set (ptr_exec_cmd->hook, "stdin", text); free (text); } } weechat_hook_set (ptr_exec_cmd->hook, "stdin_close", "1"); } return WEECHAT_RC_OK; } /* send a signal to a running process */ if (weechat_strcasecmp (argv[1], "-signal") == 0) { WEECHAT_COMMAND_MIN_ARGS(4, "-signal"); ptr_exec_cmd = exec_command_search_running_id (argv[2]); if (ptr_exec_cmd) weechat_hook_set (ptr_exec_cmd->hook, "signal", argv[3]); return WEECHAT_RC_OK; } /* send a KILL signal to a running process */ if (weechat_strcasecmp (argv[1], "-kill") == 0) { WEECHAT_COMMAND_MIN_ARGS(3, "-kill"); ptr_exec_cmd = exec_command_search_running_id (argv[2]); if (ptr_exec_cmd) weechat_hook_set (ptr_exec_cmd->hook, "signal", "kill"); return WEECHAT_RC_OK; } /* send a KILL signal to all running processes */ if (weechat_strcasecmp (argv[1], "-killall") == 0) { for (ptr_exec_cmd = exec_cmds; ptr_exec_cmd; ptr_exec_cmd = ptr_exec_cmd->next_cmd) { if (ptr_exec_cmd->hook) { weechat_hook_set (ptr_exec_cmd->hook, "signal", "kill"); } } return WEECHAT_RC_OK; } /* set a hook property */ if (weechat_strcasecmp (argv[1], "-set") == 0) { WEECHAT_COMMAND_MIN_ARGS(5, "-set"); ptr_exec_cmd = exec_command_search_running_id (argv[2]); if (ptr_exec_cmd) weechat_hook_set (ptr_exec_cmd->hook, argv[3], argv_eol[4]); return WEECHAT_RC_OK; } /* delete terminated command(s) */ if (weechat_strcasecmp (argv[1], "-del") == 0) { WEECHAT_COMMAND_MIN_ARGS(3, "-del"); if (weechat_strcasecmp (argv[2], "-all") == 0) { count = 0; ptr_exec_cmd = exec_cmds; while (ptr_exec_cmd) { ptr_next_exec_cmd = ptr_exec_cmd->next_cmd; if (!ptr_exec_cmd->hook) { exec_free (ptr_exec_cmd); count++; } ptr_exec_cmd = ptr_next_exec_cmd; } weechat_printf (NULL, _("%d commands removed"), count); } else { for (i = 2; i < argc; i++) { ptr_exec_cmd = exec_search_by_id (argv[i]); if (ptr_exec_cmd) { if (ptr_exec_cmd->hook) { weechat_printf (NULL, _("%s%s: command with id \"%s\" is still " "running"), weechat_prefix ("error"), EXEC_PLUGIN_NAME, argv[i]); } else { exec_free (ptr_exec_cmd); weechat_printf (NULL, _("Command \"%s\" removed"), argv[i]); } } else { weechat_printf (NULL, _("%s%s: command id \"%s\" not found"), weechat_prefix ("error"), EXEC_PLUGIN_NAME, argv[i]); } } } return WEECHAT_RC_OK; } return exec_command_run (buffer, argc, argv, argv_eol, 1); }
int weechat_js_command_cb (const void *pointer, void *data, struct t_gui_buffer *buffer, int argc, char **argv, char **argv_eol) { char *ptr_name, *ptr_code, *path_script; int i, send_to_buffer_as_input, exec_commands; /* make C++ compiler happy */ (void) pointer; (void) data; if (argc == 1) { plugin_script_display_list (weechat_js_plugin, js_scripts, NULL, 0); } else if (argc == 2) { if (weechat_strcasecmp (argv[1], "list") == 0) { plugin_script_display_list (weechat_js_plugin, js_scripts, NULL, 0); } else if (weechat_strcasecmp (argv[1], "listfull") == 0) { plugin_script_display_list (weechat_js_plugin, js_scripts, NULL, 1); } else if (weechat_strcasecmp (argv[1], "autoload") == 0) { plugin_script_auto_load (weechat_js_plugin, &weechat_js_load_cb); } else if (weechat_strcasecmp (argv[1], "reload") == 0) { weechat_js_unload_all (); plugin_script_auto_load (weechat_js_plugin, &weechat_js_load_cb); } else if (weechat_strcasecmp(argv[1], "unload") == 0) { weechat_js_unload_all (); } else if (weechat_strcasecmp (argv[1], "version") == 0) { plugin_script_display_interpreter (weechat_js_plugin, 0); } else WEECHAT_COMMAND_ERROR; } else { if (weechat_strcasecmp (argv[1], "list") == 0) { plugin_script_display_list (weechat_js_plugin, js_scripts, argv_eol[2], 0); } else if (weechat_strcasecmp (argv[1], "listfull") == 0) { plugin_script_display_list (weechat_js_plugin, js_scripts, argv_eol[2], 1); } else if ((weechat_strcasecmp (argv[1], "load") == 0) || (weechat_strcasecmp (argv[1], "reload") == 0) || (weechat_strcasecmp (argv[1], "unload") == 0)) { ptr_name = argv_eol[2]; if (strncmp (ptr_name, "-q ", 3) == 0) { js_quiet = 1; ptr_name += 3; while (ptr_name[0] == ' ') { ptr_name++; } } if (weechat_strcasecmp (argv[1], "load") == 0) { /* load javascript script */ path_script = plugin_script_search_path (weechat_js_plugin, ptr_name); weechat_js_load ((path_script) ? path_script : ptr_name, NULL); if (path_script) free (path_script); } else if (weechat_strcasecmp (argv[1], "reload") == 0) { /* reload one javascript script */ weechat_js_reload_name (ptr_name); } else if (weechat_strcasecmp (argv[1], "unload") == 0) { /* unload javascript script */ weechat_js_unload_name (ptr_name); } js_quiet = 0; } else if (weechat_strcasecmp (argv[1], "eval") == 0) { send_to_buffer_as_input = 0; exec_commands = 0; ptr_code = argv_eol[2]; for (i = 2; i < argc; i++) { if (argv[i][0] == '-') { if (strcmp (argv[i], "-o") == 0) { if (i + 1 >= argc) WEECHAT_COMMAND_ERROR; send_to_buffer_as_input = 1; exec_commands = 0; ptr_code = argv_eol[i + 1]; } else if (strcmp (argv[i], "-oc") == 0) { if (i + 1 >= argc) WEECHAT_COMMAND_ERROR; send_to_buffer_as_input = 1; exec_commands = 1; ptr_code = argv_eol[i + 1]; } } else break; } if (!weechat_js_eval (buffer, send_to_buffer_as_input, exec_commands, ptr_code)) WEECHAT_COMMAND_ERROR; /* TODO: implement /javascript eval */ weechat_printf (NULL, _("%sCommand \"/%s eval\" is not yet implemented"), weechat_prefix ("error"), weechat_js_plugin->name); } else WEECHAT_COMMAND_ERROR; } return WEECHAT_RC_OK; }
int charset_command_cb (const void *pointer, void *data, struct t_gui_buffer *buffer, int argc, char **argv, char **argv_eol) { struct t_config_section *ptr_section; int length; char *ptr_charset, *option_name; const char *plugin_name, *name, *charset_modifier; /* make C compiler happy */ (void) pointer; (void) data; if (argc < 2) { charset_display_charsets (); return WEECHAT_RC_OK; } ptr_section = NULL; plugin_name = weechat_buffer_get_string (buffer, "plugin"); name = weechat_buffer_get_string (buffer, "name"); charset_modifier = weechat_buffer_get_string (buffer, "localvar_charset_modifier"); if (charset_modifier) option_name = strdup (charset_modifier); else { length = strlen (plugin_name) + 1 + strlen (name) + 1; option_name = malloc (length); if (!option_name) WEECHAT_COMMAND_ERROR; snprintf (option_name, length, "%s.%s", plugin_name, name); } if (weechat_strcasecmp (argv[1], "reset") == 0) { charset_set (charset_config_section_decode, "decode", option_name, NULL); charset_set (charset_config_section_encode, "encode", option_name, NULL); } else { if (argc > 2) { if (weechat_strcasecmp (argv[1], "decode") == 0) { ptr_section = charset_config_section_decode; ptr_charset = argv_eol[2]; } else if (weechat_strcasecmp (argv[1], "encode") == 0) { ptr_section = charset_config_section_encode; ptr_charset = argv_eol[2]; } if (!ptr_section) { weechat_printf (NULL, _("%s%s: wrong charset type (decode or encode " "expected)"), weechat_prefix ("error"), CHARSET_PLUGIN_NAME); if (option_name) free (option_name); return WEECHAT_RC_OK; } } else ptr_charset = argv_eol[1]; if (!charset_check (ptr_charset)) { weechat_printf (NULL, _("%s%s: invalid charset: \"%s\""), weechat_prefix ("error"), CHARSET_PLUGIN_NAME, ptr_charset); if (option_name) free (option_name); return WEECHAT_RC_OK; } if (ptr_section) { charset_set (ptr_section, argv[1], option_name, ptr_charset); } else { charset_set (charset_config_section_decode, "decode", option_name, ptr_charset); charset_set (charset_config_section_encode, "encode", option_name, ptr_charset); } } free (option_name); return WEECHAT_RC_OK; }
int charset_config_init () { struct t_config_section *ptr_section; charset_config_file = weechat_config_new (CHARSET_CONFIG_NAME, &charset_config_reload, NULL, NULL); if (!charset_config_file) return 0; ptr_section = weechat_config_new_section (charset_config_file, "default", 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); if (!ptr_section) { weechat_config_free (charset_config_file); return 0; } charset_default_decode = weechat_config_new_option ( charset_config_file, ptr_section, "decode", "string", N_("global decoding charset: charset used to decode incoming messages " "when they are not UTF-8 valid"), NULL, 0, 0, (charset_terminal && charset_internal && (weechat_strcasecmp (charset_terminal, charset_internal) != 0)) ? charset_terminal : "iso-8859-1", NULL, 0, &charset_check_charset_decode_cb, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); charset_default_encode = weechat_config_new_option ( charset_config_file, ptr_section, "encode", "string", N_("global encoding charset: charset used to encode outgoing messages " "(if empty, default is UTF-8 because it is the WeeChat internal " "charset)"), NULL, 0, 0, "", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); ptr_section = weechat_config_new_section ( charset_config_file, "decode", 1, 1, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &charset_config_create_option, NULL, NULL, NULL, NULL, NULL); if (!ptr_section) { weechat_config_free (charset_config_file); return 0; } charset_config_section_decode = ptr_section; ptr_section = weechat_config_new_section ( charset_config_file, "encode", 1, 1, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &charset_config_create_option, NULL, NULL, NULL, NULL, NULL); if (!ptr_section) { weechat_config_free (charset_config_file); return 0; } charset_config_section_encode = ptr_section; return 1; }
int trigger_command_trigger (void *data, struct t_gui_buffer *buffer, int argc, char **argv, char **argv_eol) { struct t_trigger *ptr_trigger, *ptr_trigger2; struct t_trigger_regex *regex; char *value, **sargv, **items, input[1024], str_pos[16]; int rc, i, type, count, index_option, enable, sargc, num_items, add_rc; int regex_count, regex_rc; /* make C compiler happy */ (void) data; rc = WEECHAT_RC_OK; sargv = NULL; /* list all triggers */ if ((argc == 1) || ((argc == 2) && (weechat_strcasecmp (argv[1], "list") == 0))) { trigger_command_list (_("List of triggers:"), 0); goto end; } /* full list of all triggers */ if ((argc == 2) && (weechat_strcasecmp (argv[1], "listfull") == 0)) { trigger_command_list (_("List of triggers:"), 1); goto end; } /* list of default triggers */ if ((argc == 2) && (weechat_strcasecmp (argv[1], "listdefault") == 0)) { trigger_command_list_default (1); goto end; } /* add a trigger */ if ((weechat_strcasecmp (argv[1], "add") == 0) || (weechat_strcasecmp (argv[1], "addoff") == 0) || (weechat_strcasecmp (argv[1], "addreplace") == 0)) { sargv = weechat_string_split_shell (argv_eol[2], &sargc); if (!sargv || (sargc < 2)) goto error; if (!trigger_name_valid (sargv[0])) { weechat_printf_tags (NULL, "no_trigger", _("%s%s: invalid name for trigger"), weechat_prefix ("error"), TRIGGER_PLUGIN_NAME); goto end; } type = trigger_search_hook_type (sargv[1]); if (type < 0) { weechat_printf_tags (NULL, "no_trigger", _("%s%s: invalid hook type \"%s\""), weechat_prefix ("error"), TRIGGER_PLUGIN_NAME, sargv[1]); goto end; } if ((sargc > 4) && sargv[4][0]) { regex_count = 0; regex = NULL; regex_rc = trigger_regex_split (sargv[4], ®ex_count, ®ex); trigger_regex_free (®ex_count, ®ex); switch (regex_rc) { case 0: /* OK */ break; case -1: /* format error */ weechat_printf (NULL, _("%s%s: invalid format for regular " "expression"), weechat_prefix ("error"), TRIGGER_PLUGIN_NAME); goto end; break; case -2: /* regex compilation error */ weechat_printf (NULL, _("%s%s: invalid regular expression " "(compilation failed)"), weechat_prefix ("error"), TRIGGER_PLUGIN_NAME); goto end; break; case -3: /* memory error */ weechat_printf (NULL, _("%s%s: not enough memory"), weechat_prefix ("error"), TRIGGER_PLUGIN_NAME); goto end; break; } } if ((sargc > 6) && sargv[6][0] && (trigger_search_return_code (sargv[6]) < 0)) { weechat_printf_tags (NULL, "no_trigger", _("%s%s: invalid return code \"%s\""), weechat_prefix ("error"), TRIGGER_PLUGIN_NAME, sargv[6]); goto end; } ptr_trigger = trigger_search (sargv[0]); if (ptr_trigger) { if (weechat_strcasecmp (argv[1], "addreplace") == 0) { if (ptr_trigger) trigger_free (ptr_trigger); } else { weechat_printf_tags (NULL, "no_trigger", _("%s%s: trigger \"%s\" already exists " "(choose another name or use option " "\"addreplace\" to overwrite it)"), weechat_prefix ("error"), TRIGGER_PLUGIN_NAME, sargv[0]); goto end; } } ptr_trigger = trigger_alloc (sargv[0]); if (!ptr_trigger) { weechat_printf_tags (NULL, "no_trigger", _("%s%s: failed to create trigger \"%s\""), weechat_prefix ("error"), TRIGGER_PLUGIN_NAME, sargv[0]); goto end; } ptr_trigger = trigger_new ( sargv[0], /* name */ (weechat_strcasecmp (argv[1], "addoff") == 0) ? "off" : "on", sargv[1], /* hook */ (sargc > 2) ? sargv[2] : "", /* arguments */ (sargc > 3) ? sargv[3] : "", /* conditions */ (sargc > 4) ? sargv[4] : "", /* regex */ (sargc > 5) ? sargv[5] : "", /* command */ (sargc > 6) ? sargv[6] : ""); /* return code */ if (ptr_trigger) { weechat_printf_tags (NULL, "no_trigger", _("Trigger \"%s\" created"), sargv[0]); } else { weechat_printf_tags (NULL, "no_trigger", _("%s%s: failed to create trigger \"%s\""), weechat_prefix ("error"), TRIGGER_PLUGIN_NAME, sargv[0]); } goto end; } /* add trigger command in input (to help trigger creation) */ if (weechat_strcasecmp (argv[1], "addinput") == 0) { type = TRIGGER_HOOK_SIGNAL; if (argc >= 3) { type = trigger_search_hook_type (argv[2]); if (type < 0) { weechat_printf_tags (NULL, "no_trigger", _("%s%s: invalid hook type \"%s\""), weechat_prefix ("error"), TRIGGER_PLUGIN_NAME, argv[2]); goto end; } } items = weechat_string_split (trigger_hook_default_rc[type], ",", 0, 0, &num_items); snprintf (input, sizeof (input), "/trigger add name %s \"%s\" \"%s\" \"%s\" \"%s\"%s%s%s", trigger_hook_type_string[type], trigger_hook_default_arguments[type], TRIGGER_HOOK_DEFAULT_CONDITIONS, TRIGGER_HOOK_DEFAULT_REGEX, TRIGGER_HOOK_DEFAULT_COMMAND, (items && (num_items > 0)) ? " \"" : "", (items && (num_items > 0)) ? items[0] : "", (items && (num_items > 0)) ? "\"" : ""); weechat_buffer_set (buffer, "input", input); weechat_buffer_set (buffer, "input_pos", "13"); goto end; } /* * get command to create a trigger, and according to option: * - input: put the command in input * - output: send the command to the buffer * - recreate: same as input, but the trigger is first deleted */ if ((weechat_strcasecmp (argv[1], "input") == 0) || (weechat_strcasecmp (argv[1], "output") == 0) || (weechat_strcasecmp (argv[1], "recreate") == 0)) { if (argc < 3) goto error; ptr_trigger = trigger_search (argv[2]); if (!ptr_trigger) { weechat_printf_tags (NULL, "no_trigger", _("%s%s: trigger \"%s\" not found"), weechat_prefix ("error"), TRIGGER_PLUGIN_NAME, argv[2]); goto end; } add_rc = trigger_hook_default_rc[weechat_config_integer (ptr_trigger->options[TRIGGER_OPTION_HOOK])][0]; snprintf (input, sizeof (input), "//trigger %s %s %s \"%s\" \"%s\" \"%s\" \"%s\"%s%s%s", (weechat_strcasecmp (argv[1], "recreate") == 0) ? "addreplace" : "add", ptr_trigger->name, weechat_config_string (ptr_trigger->options[TRIGGER_OPTION_HOOK]), weechat_config_string (ptr_trigger->options[TRIGGER_OPTION_ARGUMENTS]), weechat_config_string (ptr_trigger->options[TRIGGER_OPTION_CONDITIONS]), weechat_config_string (ptr_trigger->options[TRIGGER_OPTION_REGEX]), weechat_config_string (ptr_trigger->options[TRIGGER_OPTION_COMMAND]), (add_rc) ? " \"" : "", (add_rc) ? weechat_config_string (ptr_trigger->options[TRIGGER_OPTION_RETURN_CODE]) : "", (add_rc) ? "\"" : ""); if (weechat_strcasecmp (argv[1], "output") == 0) { weechat_command (buffer, input); } else { weechat_buffer_set (buffer, "input", input + 1); snprintf (str_pos, sizeof (str_pos), "%d", weechat_utf8_strlen (input + 1)); weechat_buffer_set (buffer, "input_pos", str_pos); } goto end; } /* set option in a trigger */ if (weechat_strcasecmp (argv[1], "set") == 0) { if (argc < 5) goto error; ptr_trigger = trigger_search (argv[2]); if (!ptr_trigger) { weechat_printf_tags (NULL, "no_trigger", _("%s%s: trigger \"%s\" not found"), weechat_prefix ("error"), TRIGGER_PLUGIN_NAME, argv[2]); goto end; } if (weechat_strcasecmp (argv[3], "name") == 0) { trigger_command_rename (ptr_trigger, argv[4]); goto end; } value = weechat_string_remove_quotes (argv_eol[4], "'\""); if (value) { index_option = trigger_search_option (argv[3]); if (index_option >= 0) { weechat_config_option_set (ptr_trigger->options[index_option], value, 1); weechat_printf_tags (NULL, "no_trigger", _("Trigger \"%s\" updated"), ptr_trigger->name); } else { weechat_printf_tags (NULL, "no_trigger", _("%s%s: trigger option \"%s\" not " "found"), weechat_prefix ("error"), TRIGGER_PLUGIN_NAME, argv[3]); } free (value); } goto end; } /* rename a trigger */ if (weechat_strcasecmp (argv[1], "rename") == 0) { if (argc < 4) goto error; ptr_trigger = trigger_search (argv[2]); if (!ptr_trigger) { weechat_printf_tags (NULL, "no_trigger", _("%s%s: trigger \"%s\" not found"), weechat_prefix ("error"), TRIGGER_PLUGIN_NAME, argv[2]); goto end; } trigger_command_rename (ptr_trigger, argv[3]); goto end; } /* copy a trigger */ if (weechat_strcasecmp (argv[1], "copy") == 0) { if (argc < 4) goto error; ptr_trigger = trigger_search (argv[2]); if (!ptr_trigger) { weechat_printf_tags (NULL, "no_trigger", _("%s%s: trigger \"%s\" not found"), weechat_prefix ("error"), TRIGGER_PLUGIN_NAME, argv[2]); goto end; } /* check that new name is valid */ if (!trigger_name_valid (argv[3])) { weechat_printf_tags (NULL, "no_trigger", _("%s%s: invalid name for trigger"), weechat_prefix ("error"), TRIGGER_PLUGIN_NAME); goto end; } /* check that no trigger already exists with the new name */ if (trigger_search (argv[3])) { weechat_printf_tags (NULL, "no_trigger", _("%s%s: trigger \"%s\" already " "exists"), weechat_prefix ("error"), TRIGGER_PLUGIN_NAME, argv[3]); goto end; } /* copy the trigger */ ptr_trigger2 = trigger_copy (ptr_trigger, argv[3]); if (ptr_trigger2) { weechat_printf_tags (NULL, "no_trigger", _("Trigger \"%s\" copied to \"%s\""), ptr_trigger->name, ptr_trigger2->name); } else { weechat_printf_tags (NULL, "no_trigger", _("%s%s: failed to copy trigger " "\"%s\""), weechat_prefix ("error"), TRIGGER_PLUGIN_NAME, ptr_trigger->name); } goto end; } /* enable/disable/toggle/restart trigger(s) */ if ((weechat_strcasecmp (argv[1], "enable") == 0) || (weechat_strcasecmp (argv[1], "disable") == 0) || (weechat_strcasecmp (argv[1], "toggle") == 0) || (weechat_strcasecmp (argv[1], "restart") == 0)) { if (argc < 3) { if (weechat_strcasecmp (argv[1], "restart") == 0) goto error; if (weechat_strcasecmp (argv[1], "enable") == 0) weechat_config_option_set (trigger_config_look_enabled, "1", 1); else if (weechat_strcasecmp (argv[1], "disable") == 0) weechat_config_option_set (trigger_config_look_enabled, "0", 1); else if (weechat_strcasecmp (argv[1], "toggle") == 0) { weechat_config_option_set (trigger_config_look_enabled, (trigger_enabled) ? "0" : "1", 1); } trigger_command_display_status (); goto end; } enable = -1; if (weechat_strcasecmp (argv[1], "enable") == 0) enable = 1; else if (weechat_strcasecmp (argv[1], "disable") == 0) enable = 0; else if (weechat_strcasecmp (argv[1], "restart") == 0) enable = 2; if (weechat_strcasecmp (argv[2], "-all") == 0) { for (ptr_trigger = triggers; ptr_trigger; ptr_trigger = ptr_trigger->next_trigger) { trigger_command_set_enabled (ptr_trigger, enable, 0); } } else { for (i = 2; i < argc; i++) { ptr_trigger = trigger_search (argv[i]); if (ptr_trigger) trigger_command_set_enabled (ptr_trigger, enable, 1); else { weechat_printf_tags (NULL, "no_trigger", _("%sTrigger \"%s\" not found"), weechat_prefix ("error"), argv[i]); } } } goto end; } /* delete trigger(s) */ if (weechat_strcasecmp (argv[1], "del") == 0) { if (argc < 3) goto error; if (weechat_strcasecmp (argv[2], "-all") == 0) { count = triggers_count; trigger_free_all (); if (count > 0) weechat_printf_tags (NULL, "no_trigger", _("%d triggers removed"), count); } else { for (i = 2; i < argc; i++) { ptr_trigger = trigger_search (argv[i]); if (ptr_trigger) { trigger_free (ptr_trigger); weechat_printf_tags (NULL, "no_trigger", _("Trigger \"%s\" removed"), argv[i]); } else { weechat_printf_tags (NULL, "no_trigger", _("%sTrigger \"%s\" not found"), weechat_prefix ("error"), argv[i]); } } } goto end; } /* show detailed info on a trigger */ if (weechat_strcasecmp (argv[1], "show") == 0) { if (argc < 3) goto error; ptr_trigger = trigger_search (argv[2]); if (!ptr_trigger) { weechat_printf_tags (NULL, "no_trigger", _("%s%s: trigger \"%s\" not found"), weechat_prefix ("error"), TRIGGER_PLUGIN_NAME, argv[2]); goto end; } weechat_printf_tags (NULL, "no_trigger", ""); weechat_printf_tags (NULL, "no_trigger", _("Trigger:")); trigger_command_display_trigger (ptr_trigger, 2); goto end; } /* restore default triggers */ if (weechat_strcasecmp (argv[1], "default") == 0) { if ((argc >= 3) && (weechat_strcasecmp (argv[2], "-yes") == 0)) { trigger_free_all (); trigger_create_default (); trigger_command_list (_("Default triggers restored:"), 0); } else { weechat_printf (NULL, _("%s%s: \"-yes\" argument is required for " "restoring default triggers (security reason)"), weechat_prefix ("error"), TRIGGER_PLUGIN_NAME); } goto end; } /* open the trigger monitor buffer */ if (weechat_strcasecmp (argv[1], "monitor") == 0) { trigger_buffer_open ((argc > 2) ? argv_eol[2] : NULL, 1); goto end; } error: rc = WEECHAT_RC_ERROR; end: if (sargv) weechat_string_free_split (sargv); return rc; }
struct t_hashtable * irc_message_split (struct t_irc_server *server, const char *message) { struct t_hashtable *hashtable; char **argv, **argv_eol, *tags, *host, *command, *arguments, target[512]; char *pos; int split_ok, argc, index_args, max_length_nick, max_length_host; split_ok = 0; tags = NULL; host = NULL; command = NULL; arguments = NULL; index_args = 0; argv = NULL; argv_eol = NULL; /* debug message */ if (weechat_irc_plugin->debug >= 2) weechat_printf (NULL, "irc_message_split: message='%s'", message); hashtable = weechat_hashtable_new (32, WEECHAT_HASHTABLE_STRING, WEECHAT_HASHTABLE_STRING, NULL, NULL); if (!hashtable) return NULL; if (!message || !message[0]) goto end; if (message[0] == '@') { pos = strchr (message, ' '); if (pos) { tags = weechat_strndup (message, pos - message + 1); message = pos + 1; } } argv = weechat_string_split (message, " ", 0, 0, &argc); argv_eol = weechat_string_split (message, " ", 2, 0, NULL); if (argc < 2) goto end; if (argv[0][0] == ':') { if (argc < 3) goto end; host = argv[0]; command = argv[1]; arguments = argv_eol[2]; index_args = 2; } else { command = argv[0]; arguments = argv_eol[1]; index_args = 1; } max_length_nick = (server && (server->nick_max_length > 0)) ? server->nick_max_length : 16; max_length_host = 1 + /* ":" */ max_length_nick + /* nick */ 1 + /* "!" */ 63 + /* host */ 1; /* " " */ if ((weechat_strcasecmp (command, "ison") == 0) || (weechat_strcasecmp (command, "wallops") == 0)) { split_ok = irc_message_split_string (hashtable, tags, host, command, NULL, ":", (argv_eol[index_args][0] == ':') ? argv_eol[index_args] + 1 : argv_eol[index_args], NULL, ' ', max_length_host); } else if (weechat_strcasecmp (command, "join") == 0) { /* split join (if it's more than 510 bytes) */ if (strlen (message) > 510) { split_ok = irc_message_split_join (hashtable, tags, host, arguments); } } else if ((weechat_strcasecmp (command, "privmsg") == 0) || (weechat_strcasecmp (command, "notice") == 0)) { /* split privmsg/notice */ if (index_args + 1 <= argc - 1) { split_ok = irc_message_split_privmsg_notice (hashtable, tags, host, command, argv[index_args], (argv_eol[index_args + 1][0] == ':') ? argv_eol[index_args + 1] + 1 : argv_eol[index_args + 1], max_length_host); } } else if (weechat_strcasecmp (command, "005") == 0) { /* split 005 (isupport) */ if (index_args + 1 <= argc - 1) { split_ok = irc_message_split_005 (hashtable, tags, host, command, argv[index_args], (argv_eol[index_args + 1][0] == ':') ? argv_eol[index_args + 1] + 1 : argv_eol[index_args + 1]); } } else if (weechat_strcasecmp (command, "353") == 0) { /* * split 353 (list of users on channel): * :server 353 mynick = #channel :mynick nick1 @nick2 +nick3 */ if (index_args + 2 <= argc - 1) { if (irc_channel_is_channel (server, argv[index_args + 1])) { snprintf (target, sizeof (target), "%s %s", argv[index_args], argv[index_args + 1]); split_ok = irc_message_split_string (hashtable, tags, host, command, target, ":", (argv_eol[index_args + 2][0] == ':') ? argv_eol[index_args + 2] + 1 : argv_eol[index_args + 2], NULL, ' ', -1); } else { if (index_args + 3 <= argc - 1) { snprintf (target, sizeof (target), "%s %s %s", argv[index_args], argv[index_args + 1], argv[index_args + 2]); split_ok = irc_message_split_string (hashtable, tags, host, command, target, ":", (argv_eol[index_args + 3][0] == ':') ? argv_eol[index_args + 3] + 1 : argv_eol[index_args + 3], NULL, ' ', -1); } } } } end: if (!split_ok || (weechat_hashtable_get_integer (hashtable, "items_count") == 0)) { irc_message_split_add (hashtable, 1, tags, message, arguments); } if (tags) free (tags); if (argv) weechat_string_free_split (argv); if (argv_eol) weechat_string_free_split (argv_eol); return hashtable; }
int weechat_guile_command_cb (void *data, struct t_gui_buffer *buffer, int argc, char **argv, char **argv_eol) { char *ptr_name, *path_script; SCM value; /* make C compiler happy */ (void) data; (void) buffer; if (argc == 1) { plugin_script_display_list (weechat_guile_plugin, guile_scripts, NULL, 0); } else if (argc == 2) { if (weechat_strcasecmp (argv[1], "list") == 0) { plugin_script_display_list (weechat_guile_plugin, guile_scripts, NULL, 0); } else if (weechat_strcasecmp (argv[1], "listfull") == 0) { plugin_script_display_list (weechat_guile_plugin, guile_scripts, NULL, 1); } else if (weechat_strcasecmp (argv[1], "autoload") == 0) { plugin_script_auto_load (weechat_guile_plugin, &weechat_guile_load_cb); } else if (weechat_strcasecmp (argv[1], "reload") == 0) { weechat_guile_unload_all (); plugin_script_auto_load (weechat_guile_plugin, &weechat_guile_load_cb); } else if (weechat_strcasecmp (argv[1], "unload") == 0) { weechat_guile_unload_all (); } else return WEECHAT_RC_ERROR; } else { if (weechat_strcasecmp (argv[1], "list") == 0) { plugin_script_display_list (weechat_guile_plugin, guile_scripts, argv_eol[2], 0); } else if (weechat_strcasecmp (argv[1], "listfull") == 0) { plugin_script_display_list (weechat_guile_plugin, guile_scripts, argv_eol[2], 1); } else if ((weechat_strcasecmp (argv[1], "load") == 0) || (weechat_strcasecmp (argv[1], "reload") == 0) || (weechat_strcasecmp (argv[1], "unload") == 0)) { ptr_name = argv_eol[2]; if (strncmp (ptr_name, "-q ", 3) == 0) { guile_quiet = 1; ptr_name += 3; while (ptr_name[0] == ' ') { ptr_name++; } } if (weechat_strcasecmp (argv[1], "load") == 0) { /* load guile script */ path_script = plugin_script_search_path (weechat_guile_plugin, ptr_name); weechat_guile_load ((path_script) ? path_script : ptr_name); if (path_script) free (path_script); } else if (weechat_strcasecmp (argv[1], "reload") == 0) { /* reload one guile script */ weechat_guile_reload_name (ptr_name); } else if (weechat_strcasecmp (argv[1], "unload") == 0) { /* unload guile script */ weechat_guile_unload_name (ptr_name); } guile_quiet = 0; } else if (weechat_strcasecmp (argv[1], "eval") == 0) { /* eval guile code */ value = weechat_guile_catch (scm_c_eval_string, argv_eol[2]); if (!SCM_EQ_P (value, SCM_UNDEFINED) && !SCM_EQ_P (value, SCM_UNSPECIFIED)) { scm_display (value, guile_port); } weechat_guile_stdout_flush (); } else return WEECHAT_RC_ERROR; } return WEECHAT_RC_OK; }