int weechat_lua_signal_script_action_cb (void *data, const char *signal, const char *type_data, void *signal_data) { /* make C compiler happy */ (void) data; if (strcmp (type_data, WEECHAT_HOOK_SIGNAL_STRING) == 0) { if (strcmp (signal, "lua_script_install") == 0) { plugin_script_action_add (&lua_action_install_list, (const char *)signal_data); weechat_hook_timer (1, 0, 1, &weechat_lua_timer_action_cb, &lua_action_install_list); } else if (strcmp (signal, "lua_script_remove") == 0) { plugin_script_action_add (&lua_action_remove_list, (const char *)signal_data); weechat_hook_timer (1, 0, 1, &weechat_lua_timer_action_cb, &lua_action_remove_list); } } return WEECHAT_RC_OK; }
void relay_weechat_hook_timer_nicklist (struct t_relay_client *client) { RELAY_WEECHAT_DATA(client, hook_timer_nicklist) = weechat_hook_timer (100, 0, 1, &relay_weechat_protocol_timer_nicklist_cb, client); }
int xfer_network_connect (struct t_xfer *xfer) { if (xfer->type == XFER_TYPE_CHAT_SEND) xfer->status = XFER_STATUS_WAITING; else xfer->status = XFER_STATUS_CONNECTING; if (xfer->sock < 0) { xfer->sock = socket (AF_INET, SOCK_STREAM, 0); if (xfer->sock < 0) return 0; } if (XFER_IS_SEND(xfer->type)) { /* listen to socket */ if (fcntl (xfer->sock, F_SETFL, O_NONBLOCK) == -1) return 0; if (listen (xfer->sock, 1) == -1) return 0; if (fcntl (xfer->sock, F_SETFL, 0) == -1) return 0; xfer->hook_fd = weechat_hook_fd (xfer->sock, 1, 0, 0, &xfer_network_fd_cb, xfer); /* add timeout */ if (weechat_config_integer (xfer_config_network_timeout) > 0) { xfer->hook_timer = weechat_hook_timer (weechat_config_integer (xfer_config_network_timeout) * 1000, 0, 1, &xfer_network_timer_cb, xfer); } } /* for chat receiving, connect to listening host */ if (xfer->type == XFER_TYPE_CHAT_RECV) { if (fcntl (xfer->sock, F_SETFL, O_NONBLOCK) == -1) return 0; weechat_network_connect_to (xfer->proxy, xfer->sock, xfer->address, xfer->port); xfer->hook_fd = weechat_hook_fd (xfer->sock, 1, 0, 0, &xfer_chat_recv_cb, xfer); } /* for file receiving, connection is made in child process (blocking) */ return 1; }
void irc_notify_hook_timer_whois () { if (irc_notify_timer_whois) weechat_unhook (irc_notify_timer_whois); irc_notify_timer_whois = weechat_hook_timer ( 60 * 1000 * weechat_config_integer (irc_config_network_notify_check_whois), 0, 0, &irc_notify_timer_whois_cb, NULL, NULL); }
void irc_notify_hook_timer_ison () { if (irc_notify_timer_ison) weechat_unhook (irc_notify_timer_ison); irc_notify_timer_ison = weechat_hook_timer ( 60 * 1000 * weechat_config_integer (irc_config_network_notify_check_ison), 0, 0, &irc_notify_timer_ison_cb, NULL, NULL); }
int weechat_js_signal_script_action_cb (const void *pointer, void *data, const char *signal, const char *type_data, void *signal_data) { /* make C++ compiler happy */ (void) pointer; (void) data; if (strcmp (type_data, WEECHAT_HOOK_SIGNAL_STRING) == 0) { if (strcmp (signal, "javascript_script_install") == 0) { plugin_script_action_add (&js_action_install_list, (const char *)signal_data); weechat_hook_timer (1, 0, 1, &weechat_js_timer_action_cb, &js_action_install_list, NULL); } else if (strcmp (signal, "javascript_script_remove") == 0) { plugin_script_action_add (&js_action_remove_list, (const char *)signal_data); weechat_hook_timer (1, 0, 1, &weechat_js_timer_action_cb, &js_action_remove_list, NULL); } else if (strcmp (signal, "javascript_script_autoload") == 0) { plugin_script_action_add (&js_action_autoload_list, (const char *)signal_data); weechat_hook_timer (1, 0, 1, &weechat_js_timer_action_cb, &js_action_autoload_list, NULL); } } return WEECHAT_RC_OK; }
int weechat_plugin_init(struct t_weechat_plugin *plugin, int argc, char *argv[]) { weechat_plugin = plugin; SilcClientParams params; if (silc_plugin_config_init() < 0) { weechat_log_printf("could not initialize SILC plugin config"); return WEECHAT_RC_ERROR; } if (silc_plugin_config_read() < 0) { weechat_log_printf("could not read SILC plugin config file"); return WEECHAT_RC_ERROR; } memset(¶ms, 0, sizeof(params)); params.threads = TRUE; silc_plugin = silc_calloc(1, sizeof(*silc_plugin)); if (!silc_plugin) { weechat_log_printf("could not allocate plugin context"); return WEECHAT_RC_ERROR; } weechat_log_printf("SILC plugin context allocated"); silc_plugin->client = silc_client_alloc(&ops, ¶ms, silc_plugin, NULL); if (!silc_plugin->client) { weechat_log_printf("could not allocate SILC client"); return WEECHAT_RC_ERROR; } weechat_log_printf("SILC client allocated"); if (!silc_client_init(silc_plugin->client, weechat_config_string(option_default_username), silc_net_localhost(), weechat_config_string(option_default_realname), silc_running, silc_plugin)) { weechat_log_printf("could not initialize SILC client"); return WEECHAT_RC_ERROR; } // tick the client once to complete the initialization silc_client_run_one(silc_plugin->client); weechat_log_printf("SILC client initialized"); silc_plugin_get_keypair("weechat", "", 1, &silc_plugin->public_key, &silc_plugin->private_key); server_list = malloc(sizeof(struct SilcPluginServer)); memset(server_list, 0, sizeof(struct SilcPluginServer)); weechat_hook_command("silc", "This is the SILC plugin", "", "", NULL, &command_silc, NULL); weechat_hook_timer(50, 0, 0, &timer_silc, NULL); silc_bar_init(); return WEECHAT_RC_OK; }
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 twc_do_timer_cb(void *data, int remaining_calls) { struct t_twc_profile *profile = data; tox_do(profile->tox); struct t_hook *hook = weechat_hook_timer(tox_do_interval(profile->tox), 0, 1, twc_do_timer_cb, profile); profile->tox_do_timer = hook; // check connection status int connected = tox_isconnected(profile->tox); twc_profile_set_online_status(profile, connected); return WEECHAT_RC_OK; }
static gint _wec_try_connect(gconstpointer user_data, gpointer data, gint remaining_calls) { gint error = 0; if ( eventc_light_connection_is_connected(_wec_context.client, &error) ) return WEECHAT_RC_OK; if ( _wec_context.connect_hook != NULL ) return WEECHAT_RC_ERROR; if ( eventc_light_connection_connect(_wec_context.client) < 0 ) { _wec_context.connect_hook = weechat_hook_timer(GPOINTER_TO_UINT(user_data) * 1000, 60, 1, _wec_try_connect, GUINT_TO_POINTER(GPOINTER_TO_UINT(user_data) * 2), NULL); return WEECHAT_RC_ERROR; } _wec_context.connect_hook = NULL; _wec_context.fd = eventc_light_connection_get_socket(_wec_context.client); _wec_context.fd_hook = weechat_hook_fd(_wec_context.fd, 1, 0, 0, _wec_fd_callback, NULL, NULL); return WEECHAT_RC_OK; }
void logger_config_flush_delay_change (const void *pointer, void *data, struct t_config_option *option) { /* make C compiler happy */ (void) pointer; (void) data; (void) option; if (logger_config_loading) return; if (logger_timer) { if (weechat_logger_plugin->debug) { weechat_printf_date_tags ( NULL, 0, "no_log", "%s: stopping timer", LOGGER_PLUGIN_NAME); } weechat_unhook (logger_timer); logger_timer = NULL; } if (weechat_config_integer (logger_config_file_flush_delay) > 0) { if (weechat_logger_plugin->debug) { weechat_printf_date_tags ( NULL, 0, "no_log", "%s: starting timer (interval: %d seconds)", LOGGER_PLUGIN_NAME, weechat_config_integer (logger_config_file_flush_delay)); } logger_timer = weechat_hook_timer (weechat_config_integer (logger_config_file_flush_delay) * 1000, 0, 0, &logger_timer_cb, NULL, NULL); } }
void trigger_hook (struct t_trigger *trigger) { char **argv, **argv_eol, *tags, *message, *error1, *error2, *error3; int i, argc, strip_colors; long interval, align_second, max_calls; trigger_unhook (trigger); argv = weechat_string_split (weechat_config_string (trigger->options[TRIGGER_OPTION_ARGUMENTS]), ";", 0, 0, &argc); argv_eol = weechat_string_split (weechat_config_string (trigger->options[TRIGGER_OPTION_ARGUMENTS]), ";", 1, 0, NULL); switch (weechat_config_integer (trigger->options[TRIGGER_OPTION_HOOK])) { case TRIGGER_HOOK_SIGNAL: if (argv && (argc >= 1)) { trigger->hooks = malloc (argc * sizeof (trigger->hooks[0])); if (trigger->hooks) { trigger->hooks_count = argc; for (i = 0; i < argc; i++) { trigger->hooks[i] = weechat_hook_signal ( argv[i], &trigger_callback_signal_cb, trigger); } } } break; case TRIGGER_HOOK_HSIGNAL: if (argv && (argc >= 1)) { trigger->hooks = malloc (argc * sizeof (trigger->hooks[0])); if (trigger->hooks) { trigger->hooks_count = argc; for (i = 0; i < argc; i++) { trigger->hooks[i] = weechat_hook_hsignal ( argv[i], &trigger_callback_hsignal_cb, trigger); } } } break; case TRIGGER_HOOK_MODIFIER: if (argv && (argc >= 1)) { trigger->hooks = malloc (argc * sizeof (trigger->hooks[0])); if (trigger->hooks) { trigger->hooks_count = argc; for (i = 0; i < argc; i++) { trigger->hooks[i] = weechat_hook_modifier ( argv[i], &trigger_callback_modifier_cb, trigger); } } } break; case TRIGGER_HOOK_PRINT: tags = NULL; message = NULL; strip_colors = 0; if (argv && (argc >= 1)) { if (strcmp (argv[0], "*") != 0) trigger->hook_print_buffers = strdup (argv[0]); if ((argc >= 2) && (strcmp (argv[1], "*") != 0)) tags = argv[1]; if ((argc >= 3) && (strcmp (argv[2], "*") != 0)) message = argv[2]; if (argc >= 4) strip_colors = (strcmp (argv[3], "0") != 0) ? 1 : 0; } trigger->hooks = malloc (sizeof (trigger->hooks[0])); if (trigger->hooks) { trigger->hooks_count = 1; trigger->hooks[0] = weechat_hook_print ( NULL, tags, message, strip_colors, &trigger_callback_print_cb, trigger); } break; case TRIGGER_HOOK_COMMAND: if (argv && (argc >= 1)) { trigger->hooks = malloc (sizeof (trigger->hooks[0])); if (trigger->hooks) { trigger->hooks_count = 1; trigger->hooks[0] = weechat_hook_command ( argv[0], /* command */ (argc > 1) ? argv[1] : "", /* description */ (argc > 2) ? argv[2] : "", /* arguments */ (argc > 3) ? argv[3] : "", /* description of args */ (argc > 4) ? argv[4] : "", /* completion */ &trigger_callback_command_cb, trigger); } } break; case TRIGGER_HOOK_COMMAND_RUN: if (argv && (argc >= 1)) { trigger->hooks = malloc (argc * sizeof (trigger->hooks[0])); if (trigger->hooks) { trigger->hooks_count = argc; for (i = 0; i < argc; i++) { trigger->hooks[i] = weechat_hook_command_run ( argv[i], &trigger_callback_command_run_cb, trigger); } } } break; case TRIGGER_HOOK_TIMER: if (argv && (argc >= 1)) { error1 = NULL; error2 = NULL; error3 = NULL; interval = strtol (argv[0], &error1, 10); align_second = strtol ((argc >= 2) ? argv[1] : "0", &error2, 10); max_calls = strtol ((argc >= 3) ? argv[2] : "0", &error3, 10); if (error1 && !error1[0] && error2 && !error2[0] && error3 && !error3[0] && (interval > 0) && (align_second >= 0) && (max_calls >= 0)) { trigger->hooks = malloc (sizeof (trigger->hooks[0])); if (trigger->hooks) { trigger->hooks_count = 1; trigger->hooks[0] = weechat_hook_timer ( interval, (int)align_second, (int)max_calls, &trigger_callback_timer_cb, trigger); } } } break; case TRIGGER_HOOK_CONFIG: if (argv && (argc >= 1)) { trigger->hooks = malloc (argc * sizeof (trigger->hooks[0])); if (trigger->hooks) { trigger->hooks_count = argc; for (i = 0; i < argc; i++) { trigger->hooks[i] = weechat_hook_config ( argv[i], &trigger_callback_config_cb, trigger); } } } break; case TRIGGER_HOOK_FOCUS: if (argv && (argc >= 1)) { trigger->hooks = malloc (argc * sizeof (trigger->hooks[0])); if (trigger->hooks) { trigger->hooks_count = argc; for (i = 0; i < argc; i++) { trigger->hooks[i] = weechat_hook_focus ( argv[i], &trigger_callback_focus_cb, trigger); } } } break; } if (!trigger->hooks) { weechat_printf (NULL, _("%s%s: unable to create hook for trigger \"%s\" " "(bad arguments)"), weechat_prefix ("error"), TRIGGER_PLUGIN_NAME, trigger->name); } if (argv) weechat_string_free_split (argv); if (argv_eol) weechat_string_free_split (argv_eol); }
void exec_end_command (struct t_exec_cmd *exec_cmd, int return_code) { struct t_gui_buffer *ptr_buffer; struct t_hashtable *hashtable; char str_number[32], *output; int i, buffer_type; if (exec_cmd->hsignal) { hashtable = weechat_hashtable_new (32, WEECHAT_HASHTABLE_STRING, WEECHAT_HASHTABLE_STRING, NULL, NULL); if (hashtable) { weechat_hashtable_set (hashtable, "command", exec_cmd->command); snprintf (str_number, sizeof (str_number), "%d", exec_cmd->number); weechat_hashtable_set (hashtable, "number", str_number); weechat_hashtable_set (hashtable, "name", exec_cmd->name); output = exec_decode_color (exec_cmd, exec_cmd->output[EXEC_STDOUT]); weechat_hashtable_set (hashtable, "out", output); if (output) free (output); output = exec_decode_color (exec_cmd, exec_cmd->output[EXEC_STDERR]); weechat_hashtable_set (hashtable, "err", output); if (output) free (output); snprintf (str_number, sizeof (str_number), "%d", return_code); weechat_hashtable_set (hashtable, "rc", str_number); weechat_hook_hsignal_send (exec_cmd->hsignal, hashtable); weechat_hashtable_free (hashtable); } } else { ptr_buffer = weechat_buffer_search ("==", exec_cmd->buffer_full_name); /* display the last line of output (if not ending with '\n') */ exec_display_line (exec_cmd, ptr_buffer, EXEC_STDOUT, exec_cmd->output[EXEC_STDOUT]); exec_display_line (exec_cmd, ptr_buffer, EXEC_STDERR, exec_cmd->output[EXEC_STDERR]); /* * display return code (only if command is not detached, if output is * NOT sent to buffer, and if command is not piped) */ if (exec_cmd->display_rc && !exec_cmd->detached && !exec_cmd->output_to_buffer && !exec_cmd->pipe_command) { buffer_type = weechat_buffer_get_integer (ptr_buffer, "type"); if (return_code >= 0) { if (buffer_type == 1) { weechat_printf_y (ptr_buffer, -1, ("%s: end of command %d (\"%s\"), " "return code: %d"), EXEC_PLUGIN_NAME, exec_cmd->number, exec_cmd->command, return_code); } else { weechat_printf_date_tags ( ptr_buffer, 0, "exec_rc", _("%s: end of command %d (\"%s\"), " "return code: %d"), EXEC_PLUGIN_NAME, exec_cmd->number, exec_cmd->command, return_code); } } else { if (buffer_type == 1) { weechat_printf_y (ptr_buffer, -1, _("%s: unexpected end of command %d " "(\"%s\")"), EXEC_PLUGIN_NAME, exec_cmd->number, exec_cmd->command); } else { weechat_printf_date_tags ( ptr_buffer, 0, "exec_rc", _("%s: unexpected end of command %d " "(\"%s\")"), EXEC_PLUGIN_NAME, exec_cmd->number, exec_cmd->command); } } } } /* (re)set some variables after the end of command */ exec_cmd->hook = NULL; exec_cmd->pid = 0; exec_cmd->end_time = time (NULL); exec_cmd->return_code = return_code; for (i = 0; i < 2; i++) { if (exec_cmd->output[i]) { free (exec_cmd->output[i]); exec_cmd->output[i] = NULL; } exec_cmd->output_size[i] = 0; } /* schedule a timer to remove the executed command */ if (weechat_config_integer (exec_config_command_purge_delay) >= 0) { weechat_hook_timer (1 + (1000 * weechat_config_integer (exec_config_command_purge_delay)), 0, 1, &exec_timer_delete_cb, exec_cmd, NULL); } }
int xfer_network_connect (struct t_xfer *xfer) { int flags; if (xfer->type == XFER_TYPE_CHAT_SEND) xfer->status = XFER_STATUS_WAITING; else xfer->status = XFER_STATUS_CONNECTING; if (XFER_IS_SEND(xfer->type)) { /* create socket */ if (xfer->sock < 0) { xfer->sock = socket (xfer->local_address->sa_family, SOCK_STREAM, 0); if (xfer->sock < 0) return 0; } /* listen to socket */ flags = fcntl (xfer->sock, F_GETFL); if (flags == -1) flags = 0; if (fcntl (xfer->sock, F_SETFL, flags | O_NONBLOCK) == -1) return 0; if (listen (xfer->sock, 1) == -1) return 0; if (fcntl (xfer->sock, F_SETFL, flags) == -1) return 0; xfer->hook_fd = weechat_hook_fd (xfer->sock, 1, 0, 0, &xfer_network_fd_cb, xfer, NULL); /* add timeout */ if (weechat_config_integer (xfer_config_network_timeout) > 0) { xfer->hook_timer = weechat_hook_timer (weechat_config_integer (xfer_config_network_timeout) * 1000, 0, 1, &xfer_network_timer_cb, xfer, NULL); } } /* for chat receiving, connect to listening host */ if (xfer->type == XFER_TYPE_CHAT_RECV) { xfer->hook_connect = weechat_hook_connect (xfer->proxy, xfer->remote_address_str, xfer->port, 1, 0, NULL, NULL, 0, "NONE", NULL, &xfer_network_connect_chat_recv_cb, xfer, NULL); } /* for file receiving, connection is made in child process (blocking) */ return 1; }