struct t_relay_server * relay_server_new (enum t_relay_protocol protocol, const char *protocol_args, int port) { struct t_relay_server *new_server; if (relay_server_search_port (port)) { weechat_printf (NULL, _("%s%s: error: port \"%d\" is already used"), weechat_prefix ("error"), RELAY_PLUGIN_NAME, port); return NULL; } new_server = malloc (sizeof (*new_server)); if (new_server) { new_server->protocol = protocol; new_server->protocol_args = (protocol_args) ? strdup (protocol_args) : NULL; new_server->port = port; new_server->sock = -1; new_server->hook_fd = NULL; new_server->start_time = 0; if (!relay_server_create_socket (new_server)) { if (new_server->protocol_args) free (new_server->protocol_args); free (new_server); return NULL; } new_server->prev_server = NULL; new_server->next_server = relay_servers; if (relay_servers) relay_servers->prev_server = new_server; else last_relay_server = new_server; relay_servers = new_server; } else { weechat_printf (NULL, _("%s%s: not enough memory for listening on new port"), weechat_prefix ("error"), RELAY_PLUGIN_NAME); } return new_server; }
static PyObject * weechat_python_output (PyObject *self, PyObject *args) { char *msg, *m, *p; /* make C compiler happy */ (void) self; msg = NULL; if (!PyArg_ParseTuple (args, "s", &msg)) { if (strlen(python_buffer_output) > 0) { weechat_printf (NULL, weechat_gettext ("%s: stdout/stderr: %s%s"), PYTHON_PLUGIN_NAME, python_buffer_output, ""); python_buffer_output[0] = '\0'; } } else { m = msg; while ((p = strchr (m, '\n')) != NULL) { *p = '\0'; if (strlen (m) + strlen (python_buffer_output) > 0) { weechat_printf (NULL, weechat_gettext ("%s: stdout/stderr: %s%s"), PYTHON_PLUGIN_NAME, python_buffer_output, m); } *p = '\n'; python_buffer_output[0] = '\0'; m = ++p; } if (strlen(m) + strlen(python_buffer_output) > sizeof(python_buffer_output)) { weechat_printf (NULL, weechat_gettext ("%s: stdout/stderr: %s%s"), PYTHON_PLUGIN_NAME, python_buffer_output, m); python_buffer_output[0] = '\0'; } else strcat (python_buffer_output, m); } Py_INCREF(Py_None); return Py_None; }
void relay_command_client_list (int full) { struct t_relay_client *ptr_client; int i; char date_start[128], date_activity[128]; struct tm *date_tmp; if (relay_clients) { weechat_printf (NULL, ""); weechat_printf (NULL, _("Clients for relay:")); i = 1; for (ptr_client = relay_clients; ptr_client; ptr_client = ptr_client->next_client) { date_tmp = localtime (&(ptr_client->start_time)); strftime (date_start, sizeof (date_start), "%a, %d %b %Y %H:%M:%S", date_tmp); date_tmp = localtime (&(ptr_client->last_activity)); strftime (date_activity, sizeof (date_activity), "%a, %d %b %Y %H:%M:%S", date_tmp); if (full) { weechat_printf (NULL, _("%3d. %s, started on: %s, last activity: %s, " "bytes: %lu recv, %lu sent"), i, ptr_client->address, date_start, date_activity, ptr_client->bytes_recv, ptr_client->bytes_sent); } else { weechat_printf (NULL, _("%3d. %s, started on: %s"), i, ptr_client->address); } i++; } } else weechat_printf (NULL, _("No client for relay")); }
void weechat_ruby_unload (struct t_plugin_script *script) { int *rc; void *interpreter; if ((weechat_ruby_plugin->debug >= 1) || !ruby_quiet) { weechat_printf (NULL, weechat_gettext ("%s: unloading script \"%s\""), RUBY_PLUGIN_NAME, script->name); } if (script->shutdown_func && script->shutdown_func[0]) { rc = (int *)weechat_ruby_exec (script, WEECHAT_SCRIPT_EXEC_INT, script->shutdown_func, 0, NULL); if (rc) free (rc); } interpreter = script->interpreter; if (ruby_current_script == script) ruby_current_script = (ruby_current_script->prev_script) ? ruby_current_script->prev_script : ruby_current_script->next_script; script_remove (weechat_ruby_plugin, &ruby_scripts, &last_ruby_script, script); if (interpreter) rb_gc_unregister_address (interpreter); }
int relay_config_check_port_cb (void *data, struct t_config_option *option, const char *value) { char *error; long port; struct t_relay_server *ptr_server; /* make C compiler happy */ (void) data; (void) option; error = NULL; port = strtol (value, &error, 10); ptr_server = relay_server_search_port ((int)port); if (ptr_server) { weechat_printf (NULL, _("%s%s: error: port \"%d\" is already used"), weechat_prefix ("error"), RELAY_PLUGIN_NAME, (int)port); return 0; } return 1; }
void relay_server_close_socket (struct t_relay_server *server) { if (server->hook_fd) { weechat_unhook (server->hook_fd); server->hook_fd = NULL; } if (server->sock >= 0) { close (server->sock); server->sock = -1; if (server->unix_socket) unlink (server->path); if (!relay_signal_upgrade_received) { weechat_printf (NULL, _("%s: socket closed for %s (%s: %s)"), RELAY_PLUGIN_NAME, server->protocol_string, (server->unix_socket) ? _("path") : _("port"), server->path); } } }
void relay_network_init () { #ifdef HAVE_GNUTLS /* credentials */ gnutls_certificate_allocate_credentials (&relay_gnutls_x509_cred); relay_network_set_ssl_cert_key (0); /* priority */ relay_gnutls_priority_cache = malloc (sizeof (*relay_gnutls_priority_cache)); if (relay_gnutls_priority_cache) { if (gnutls_priority_init (relay_gnutls_priority_cache, "PERFORMANCE", NULL) != GNUTLS_E_SUCCESS) { weechat_printf (NULL, _("%s%s: unable to initialize priority for SSL"), weechat_prefix ("error"), RELAY_PLUGIN_NAME); free (relay_gnutls_priority_cache); relay_gnutls_priority_cache = NULL; } } #endif relay_network_init_ok = 1; }
void weechat_guile_unload (struct t_plugin_script *script) { int *rc; if ((weechat_guile_plugin->debug >= 1) || !guile_quiet) { weechat_printf (NULL, weechat_gettext ("%s: unloading script \"%s\""), GUILE_PLUGIN_NAME, script->name); } if (script->shutdown_func && script->shutdown_func[0]) { rc = (int *)weechat_guile_exec (script, WEECHAT_SCRIPT_EXEC_INT, script->shutdown_func, NULL, NULL); if (rc) free (rc); } weechat_guile_catch (scm_gc_unprotect_object, script->interpreter); if (guile_current_script == script) guile_current_script = (guile_current_script->prev_script) ? guile_current_script->prev_script : guile_current_script->next_script; script_remove (weechat_guile_plugin, &guile_scripts, &last_guile_script, script); }
void relay_server_close_socket (struct t_relay_server *server) { if (server->hook_fd) { weechat_unhook (server->hook_fd); server->hook_fd = NULL; } if (server->sock >= 0) { close (server->sock); server->sock = -1; if (!relay_signal_upgrade_received) { weechat_printf (NULL, _("%s: socket closed for %s%s%s (port %d)"), RELAY_PLUGIN_NAME, relay_protocol_string[server->protocol], (server->protocol_args) ? "." : "", (server->protocol_args) ? server->protocol_args : "", server->port); } } }
/** * Add a friend request. Return ID on success, -1 on error. */ int twc_sqlite_add_friend_request(struct t_twc_profile *profile, struct t_twc_friend_request *friend_request) { int64_t profile_id; if (!twc_sqlite_profile_id(profile, &profile_id)) { weechat_printf(NULL, "missing profile!"); return -1; } TWC_SQLITE_STMT(statement, "INSERT OR REPLACE INTO friend_requests (tox_id, message, profile_id)" "VALUES (?, ?, ?)"); sqlite3_bind_blob(statement, 1, friend_request->tox_id, TOX_CLIENT_ID_SIZE, NULL); sqlite3_bind_text(statement, 2, friend_request->message, strlen(friend_request->message) + 1, NULL); sqlite3_bind_int(statement, 3, profile_id); int rc = sqlite3_step(statement); TWC_SQLITE_DEBUG_RC(rc, SQLITE_DONE) if (rc != SQLITE_DONE) return -1; else return sqlite3_last_insert_rowid(twc_sqlite_db); }
/** * Return a list of all friend requests for the given profile. */ struct t_twc_list * twc_sqlite_friend_requests(struct t_twc_profile *profile) { int64_t profile_id; if (!twc_sqlite_profile_id(profile, &profile_id)) { weechat_printf(NULL, "missing profile!"); return NULL; } TWC_SQLITE_STMT(statement, "SELECT id, tox_id, message " "FROM friend_requests " "WHERE profile_id == ?"); sqlite3_bind_int(statement, 1, profile_id); struct t_twc_list *friend_requests = twc_list_new(); int rc; while ((rc = sqlite3_step(statement)) == SQLITE_ROW) { struct t_twc_friend_request *request = twc_sqlite_friend_request_row(statement, profile); twc_list_item_new_data_add(friend_requests, request); } TWC_SQLITE_DEBUG_RC(rc, SQLITE_DONE) return friend_requests; }
char * charset_encode_cb (const void *pointer, void *data, const char *modifier, const char *modifier_data, const char *string) { const char *charset; /* make C compiler happy */ (void) pointer; (void) data; (void) modifier; charset = charset_get (charset_config_section_encode, modifier_data, charset_default_encode); if (weechat_charset_plugin->debug) { weechat_printf (NULL, "charset: debug: using 'encode' charset: %s " "(modifier=\"%s\", modifier_data=\"%s\", string=\"%s\")", charset, modifier, modifier_data, string); } if (charset && charset[0]) return weechat_iconv_from_internal (charset, string); return NULL; }
void weechat_perl_unload (struct t_plugin_script *script) { int *rc; void *interpreter; char *filename; if ((weechat_perl_plugin->debug >= 2) || !perl_quiet) { weechat_printf (NULL, weechat_gettext ("%s: unloading script \"%s\""), PERL_PLUGIN_NAME, script->name); } #ifdef MULTIPLICITY PERL_SET_CONTEXT (script->interpreter); #endif /* MULTIPLICITY */ if (script->shutdown_func && script->shutdown_func[0]) { rc = (int *)weechat_perl_exec (script, WEECHAT_SCRIPT_EXEC_INT, script->shutdown_func, NULL, NULL); if (rc) free (rc); } filename = strdup (script->filename); interpreter = script->interpreter; if (perl_current_script == script) { perl_current_script = (perl_current_script->prev_script) ? perl_current_script->prev_script : perl_current_script->next_script; } plugin_script_remove (weechat_perl_plugin, &perl_scripts, &last_perl_script, script); #ifdef MULTIPLICITY if (interpreter) { perl_destruct (interpreter); perl_free (interpreter); } if (perl_current_script) { PERL_SET_CONTEXT (perl_current_script->interpreter); } #else if (interpreter) free (interpreter); #endif /* MULTIPLICITY */ (void) weechat_hook_signal_send ("perl_script_unloaded", WEECHAT_HOOK_SIGNAL_STRING, filename); if (filename) free (filename); }
/** * Initialize connection to SQLite database and create tables if necessary. * Returns 0 on success, -1 on failure. */ int twc_sqlite_init() { char *path = twc_sqlite_db_path(); int rc = sqlite3_open(path, &twc_sqlite_db); free(path); TWC_SQLITE_DEBUG_RC(rc, SQLITE_OK) if (rc != SQLITE_OK) { weechat_printf(NULL, "%s: could not open database: %s\n", weechat_plugin->name, sqlite3_errmsg(twc_sqlite_db)); sqlite3_close(twc_sqlite_db); twc_sqlite_db = NULL; return -1; } // statement list (so we can finalize later) twc_sqlite_statements = twc_list_new(); // initialize tables if (twc_sqlite_init_profiles() != 0 || twc_sqlite_init_friend_requests() != 0) return -1; return 0; }
int alias_config_completion_create_option_cb (void *data, struct t_config_file *config_file, struct t_config_section *section, const char *option_name, const char *value) { struct t_alias *ptr_alias; /* make C compiler happy */ (void) data; (void) config_file; (void) section; ptr_alias = alias_search (option_name); if (!ptr_alias) { weechat_printf (NULL, _("%s%s: error creating completion for alias \"%s\": " "alias not found"), weechat_prefix ("error"), ALIAS_PLUGIN_NAME, option_name); return WEECHAT_CONFIG_OPTION_SET_ERROR; } /* create configuration option */ alias_config_completion_new_option (option_name, value); /* create/update completion in alias */ alias_update_completion (ptr_alias, value); return WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE; }
int weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[]) { /* make C compiler happy */ (void) argc; (void) argv; weechat_plugin = plugin; rmodifier_count = 0; rmodifier_hook_list = weechat_list_new (); if (!rmodifier_config_init ()) { weechat_printf (NULL, _("%s%s: error creating configuration file"), weechat_prefix("error"), RMODIFIER_PLUGIN_NAME); return WEECHAT_RC_ERROR; } rmodifier_config_read (); rmodifier_command_init (); rmodifier_completion_init (); rmodifier_info_init (); rmodifier_debug_init (); return WEECHAT_RC_OK; }
void irc_redirect_init_command (struct t_irc_redirect *redirect, const char *command) { char *pos; if (!redirect) return; if (command) { pos = strchr (command, '\r'); if (!pos) pos = strchr (command, '\n'); if (pos) redirect->command = weechat_strndup (command, pos - command); else redirect->command = strdup (command); } else redirect->command = NULL; redirect->assigned_to_command = 1; redirect->start_time = time (NULL); if (weechat_irc_plugin->debug >= 2) { weechat_printf ( redirect->server->buffer, _("%s: starting redirection for command \"%s\" on server \"%s\" " "(redirect pattern: \"%s\")"), IRC_PLUGIN_NAME, redirect->command, redirect->server->name, redirect->pattern); } }
void charset_display_charsets () { weechat_printf (NULL, _("%s: terminal: %s, internal: %s"), CHARSET_PLUGIN_NAME, charset_terminal, charset_internal); }
void weechat_aspell_speller_check_dictionaries (const char *dict_list) { char **argv; int argc, i; if (dict_list) { argv = weechat_string_split (dict_list, ",", 0, 0, &argc); if (argv) { for (i = 0; i < argc; i++) { if (!weechat_aspell_speller_dict_supported (argv[i])) { weechat_printf (NULL, _("%s: warning: dictionary \"%s\" is not " "available on your system"), ASPELL_PLUGIN_NAME, argv[i]); } } weechat_string_free_split (argv); } } }
void xfer_chat_sendf (struct t_xfer *xfer, const char *format, ...) { char *ptr_msg, *msg_encoded; if (!xfer || (xfer->sock < 0)) return; weechat_va_format (format); if (!vbuffer) return; msg_encoded = (xfer->charset_modifier) ? weechat_hook_modifier_exec ("charset_encode", xfer->charset_modifier, vbuffer) : NULL; ptr_msg = (msg_encoded) ? msg_encoded : vbuffer; if (xfer_chat_send (xfer, ptr_msg, strlen (ptr_msg)) <= 0) { weechat_printf (NULL, _("%s%s: error sending data to \"%s\" via xfer chat"), weechat_prefix ("error"), XFER_PLUGIN_NAME, xfer->remote_nick); xfer_close (xfer, XFER_STATUS_FAILED); } if (msg_encoded) free (msg_encoded); free (vbuffer); }
void weechat_aspell_speller_free_value_cb (struct t_hashtable *hashtable, const void *key, void *value) { #ifdef USE_ENCHANT EnchantDict *ptr_speller; #else AspellSpeller *ptr_speller; #endif /* USE_ENCHANT */ /* make C compiler happy */ (void) hashtable; if (weechat_aspell_plugin->debug) { weechat_printf (NULL, "%s: removing speller for lang \"%s\"", ASPELL_PLUGIN_NAME, (const char *)key); } /* free speller */ #ifdef USE_ENCHANT ptr_speller = (EnchantDict *)value; enchant_broker_free_dict (broker, ptr_speller); #else ptr_speller = (AspellSpeller *)value; aspell_speller_save_all_word_lists (ptr_speller); delete_aspell_speller (ptr_speller); #endif /* USE_ENCHANT */ }
void weechat_tcl_unload (struct t_plugin_script *script) { Tcl_Interp* interp; int *rc; if ((weechat_tcl_plugin->debug >= 1) || !tcl_quiet) { weechat_printf (NULL, weechat_gettext ("%s: unloading script \"%s\""), TCL_PLUGIN_NAME, script->name); } if (script->shutdown_func && script->shutdown_func[0]) { rc = (int *)weechat_tcl_exec (script, WEECHAT_SCRIPT_EXEC_INT, script->shutdown_func, NULL, NULL); if (rc) free (rc); } interp = (Tcl_Interp*)script->interpreter; if (tcl_current_script == script) tcl_current_script = (tcl_current_script->prev_script) ? tcl_current_script->prev_script : tcl_current_script->next_script; script_remove (weechat_tcl_plugin, &tcl_scripts, &last_tcl_script, script); Tcl_DeleteInterp(interp); }
int twc_sqlite_delete_friend_request_with_id(struct t_twc_profile *profile, int64_t id) { int64_t profile_id; if (!twc_sqlite_profile_id(profile, &profile_id)) { weechat_printf(NULL, "missing profile!"); return -1; } TWC_SQLITE_STMT(statement, "DELETE FROM friend_requests " "WHERE id == ? AND profile_id == ?"); sqlite3_bind_int(statement, 1, id); sqlite3_bind_int(statement, 2, profile_id); int rc = sqlite3_step(statement); TWC_SQLITE_DEBUG_RC(rc, SQLITE_DONE) if (rc == SQLITE_DONE) return 0; else return -1; }
struct t_twc_friend_request * twc_sqlite_friend_request_with_id(struct t_twc_profile *profile, int64_t id) { int64_t profile_id; if (!twc_sqlite_profile_id(profile, &profile_id)) { weechat_printf(NULL, "missing profile!"); return NULL; } TWC_SQLITE_STMT(statement, "SELECT id, tox_id, message " "FROM friend_requests " "WHERE id == ? AND profile_id == ?"); sqlite3_bind_int(statement, 1, id); sqlite3_bind_int(statement, 2, profile_id); struct t_twc_friend_request *request; int rc = sqlite3_step(statement); if (rc == SQLITE_ROW) { request = twc_sqlite_friend_request_row(statement, profile); return request; } else TWC_SQLITE_DEBUG_RC(rc, SQLITE_DONE) return NULL; }
void irc_input_send_user_message (struct t_gui_buffer *buffer, char *text) { int max_length; char *pos, *pos_max, *last_space, *pos_next, *next, saved_char; IRC_GET_SERVER_CHANNEL(buffer); if (!ptr_server || !ptr_channel || !text || !text[0]) return; if (!ptr_server->is_connected) { weechat_printf (buffer, _("%s%s: you are not connected to server"), weechat_prefix ("error"), IRC_PLUGIN_NAME); return; } next = NULL; last_space = NULL; saved_char = '\0'; max_length = 512 - 16 - 65 - 10 - strlen (ptr_server->nick) - strlen (ptr_channel->name); if (max_length > 0) { if ((int)strlen (text) > max_length) { pos = text; pos_max = text + max_length; while (pos && pos[0]) { if (pos[0] == ' ') last_space = pos; pos_next = weechat_utf8_next_char (pos); if (pos_next > pos_max) break; pos = pos_next; } if (last_space && (last_space < pos)) pos = last_space + 1; saved_char = pos[0]; pos[0] = '\0'; next = pos; } } irc_server_sendf (ptr_server, 1, "PRIVMSG %s :%s", ptr_channel->name, text); irc_input_user_message_display (buffer, text); if (next) { next[0] = saved_char; irc_input_send_user_message (buffer, next); } }
int irc_input_data (struct t_gui_buffer *buffer, const char *input_data, int flags) { const char *ptr_data; char *data_with_colors, *msg; IRC_BUFFER_GET_SERVER_CHANNEL(buffer); if (buffer == irc_raw_buffer) { if (weechat_strcasecmp (input_data, "q") == 0) weechat_buffer_close (buffer); } else { /* * if send unknown commands is enabled and that input data is a * command, then send this command to IRC server */ if (weechat_config_boolean (irc_config_network_send_unknown_commands) && !weechat_string_input_for_buffer (input_data)) { if (ptr_server) { irc_server_sendf (ptr_server, flags, NULL, "%s", weechat_utf8_next_char (input_data)); } return WEECHAT_RC_OK; } if (ptr_channel) { ptr_data = weechat_string_input_for_buffer (input_data); if (!ptr_data) ptr_data = input_data; data_with_colors = irc_color_encode ( ptr_data, weechat_config_boolean (irc_config_network_colors_send)); msg = strdup ((data_with_colors) ? data_with_colors : ptr_data); if (msg) { irc_input_send_user_message (buffer, flags, NULL, msg); free (msg); } if (data_with_colors) free (data_with_colors); } else { weechat_printf (buffer, _("%s%s: this buffer is not a channel!"), weechat_prefix ("error"), IRC_PLUGIN_NAME); } } return WEECHAT_RC_OK; }
static VALUE weechat_ruby_output (VALUE self, VALUE str) { if (ruby_hide_errors) return Qnil; char *msg, *p, *m; /* make C compiler happy */ (void) self; msg = strdup(StringValuePtr(str)); m = msg; while ((p = strchr (m, '\n')) != NULL) { *p = '\0'; if (strlen (m) + strlen (ruby_buffer_output) > 0) { weechat_printf (NULL, weechat_gettext ("%s%s: stdout/stderr: %s%s"), weechat_prefix ("error"), RUBY_PLUGIN_NAME, ruby_buffer_output, m); } *p = '\n'; ruby_buffer_output[0] = '\0'; m = ++p; } if (strlen(m) + strlen(ruby_buffer_output) > sizeof(ruby_buffer_output)) { weechat_printf (NULL, weechat_gettext ("%s%s: stdout/stderr: %s%s"), weechat_prefix ("error"), RUBY_PLUGIN_NAME, ruby_buffer_output, m); ruby_buffer_output[0] = '\0'; } else strcat (ruby_buffer_output, m); if (msg) free (msg); return Qnil; }
void list_connections(struct t_gui_buffer *buffer) { struct SilcPluginServer *server; server = server_list; while (server->next != NULL) { server = server->next; weechat_printf(buffer, "Connection: %s", server->server_name); } }
void charset_set (struct t_config_section *section, const char *type, const char *name, const char *value) { if (charset_config_create_option (NULL, NULL, charset_config_file, section, name, value) > 0) { if (value && value[0]) weechat_printf (NULL, "%s: %s, \"%s\" => %s", CHARSET_PLUGIN_NAME, type, name, value); else weechat_printf (NULL, _("%s: %s, \"%s\": removed"), CHARSET_PLUGIN_NAME, type, name); } }
int weechat_python_signal_debug_libs_cb (void *data, const char *signal, const char *type_data, void *signal_data) { /* make C compiler happy */ (void) data; (void) signal; (void) type_data; (void) signal_data; #ifdef PY_VERSION weechat_printf (NULL, " %s: %s", PYTHON_PLUGIN_NAME, PY_VERSION); #else weechat_printf (NULL, " %s: (?)", PYTHON_PLUGIN_NAME); #endif return WEECHAT_RC_OK; }