void caps_init(void) { log_info("Loading capabilities cache"); cache_loc = files_get_data_path(FILE_CAPSCACHE); if (g_file_test(cache_loc, G_FILE_TEST_EXISTS)) { g_chmod(cache_loc, S_IRUSR | S_IWUSR); } cache = g_key_file_new(); g_key_file_load_from_file(cache, cache_loc, G_KEY_FILE_KEEP_COMMENTS, NULL); jid_to_ver = g_hash_table_new_full(g_str_hash, g_str_equal, free, free); jid_to_caps = g_hash_table_new_full(g_str_hash, g_str_equal, free, (GDestroyNotify)caps_destroy); prof_features = g_hash_table_new_full(g_str_hash, g_str_equal, free, NULL); g_hash_table_add(prof_features, strdup(STANZA_NS_CAPS)); g_hash_table_add(prof_features, strdup(XMPP_NS_DISCO_INFO)); g_hash_table_add(prof_features, strdup(XMPP_NS_DISCO_ITEMS)); g_hash_table_add(prof_features, strdup(STANZA_NS_MUC)); g_hash_table_add(prof_features, strdup(STANZA_NS_CONFERENCE)); g_hash_table_add(prof_features, strdup(STANZA_NS_VERSION)); g_hash_table_add(prof_features, strdup(STANZA_NS_CHATSTATES)); g_hash_table_add(prof_features, strdup(STANZA_NS_PING)); if (prefs_get_boolean(PREF_RECEIPTS_SEND)) { g_hash_table_add(prof_features, strdup(STANZA_NS_RECEIPTS)); } if (prefs_get_boolean(PREF_LASTACTIVITY)) { g_hash_table_add(prof_features, strdup(STANZA_NS_LASTACTIVITY)); } my_sha1 = NULL; }
gboolean scripts_exec(const char *const script) { char *scriptsdir = files_get_data_path(DIR_SCRIPTS); GString *scriptpath = g_string_new(scriptsdir); free(scriptsdir); g_string_append(scriptpath, "/"); g_string_append(scriptpath, script); FILE *scriptfile = g_fopen(scriptpath->str, "r"); if (!scriptfile) { log_info("Script not found: %s", scriptpath->str); g_string_free(scriptpath, TRUE); return FALSE; } g_string_free(scriptpath, TRUE); char *line = NULL; size_t len = 0; ssize_t read; while ((read = getline(&line, &len, scriptfile)) != -1) { ProfWin *win = wins_get_current(); cmd_process_input(win, line); session_process_events(); ui_update(); } fclose(scriptfile); if (line) free(line); return TRUE; }
void tlscerts_init(void) { log_info("Loading TLS certificates"); tlscerts_loc = files_get_data_path(FILE_TLSCERTS); if (g_file_test(tlscerts_loc, G_FILE_TEST_EXISTS)) { g_chmod(tlscerts_loc, S_IRUSR | S_IWUSR); } tlscerts = g_key_file_new(); g_key_file_load_from_file(tlscerts, tlscerts_loc, G_KEY_FILE_KEEP_COMMENTS, NULL); certs_ac = autocomplete_new(); gsize len = 0; gchar **groups = g_key_file_get_groups(tlscerts, &len); int i = 0; for (i = 0; i < g_strv_length(groups); i++) { autocomplete_add(certs_ac, groups[i]); } g_strfreev(groups); current_fp = NULL; }
void accounts_load(void) { log_info("Loading accounts"); all_ac = autocomplete_new(); enabled_ac = autocomplete_new(); accounts_loc = files_get_data_path(FILE_ACCOUNTS); if (g_file_test(accounts_loc, G_FILE_TEST_EXISTS)) { g_chmod(accounts_loc, S_IRUSR | S_IWUSR); } accounts = g_key_file_new(); g_key_file_load_from_file(accounts, accounts_loc, G_KEY_FILE_KEEP_COMMENTS, NULL); // create the logins searchable list for autocompletion gsize naccounts; gchar **account_names = g_key_file_get_groups(accounts, &naccounts); gsize i; for (i = 0; i < naccounts; i++) { autocomplete_add(all_ac, account_names[i]); if (g_key_file_get_boolean(accounts, account_names[i], "enabled", NULL)) { autocomplete_add(enabled_ac, account_names[i]); } } g_strfreev(account_names); }
static void _save_settings(void) { gsize g_data_size; gchar *g_data = g_key_file_to_data(settings, &g_data_size, NULL); char *fileloc = files_get_data_path(FILE_PLUGIN_SETTINGS); gchar *base = g_path_get_basename(fileloc); gchar *true_loc = get_file_or_linked(fileloc, base); g_free(base); g_file_set_contents(true_loc, g_data, g_data_size, NULL); free(true_loc); g_free(g_data); g_chmod(fileloc, S_IRUSR | S_IWUSR); free(fileloc); }
void scripts_init(void) { char *scriptsdir = files_get_data_path(DIR_SCRIPTS); // mkdir if doesn't exist errno = 0; int res = g_mkdir_with_parents(scriptsdir, S_IRWXU); if (res == -1) { char *errmsg = strerror(errno); if (errmsg) { log_error("Error creating directory: %s, %s", scriptsdir, errmsg); } else { log_error("Error creating directory: %s", scriptsdir); } } free(scriptsdir); }
void plugin_settings_init(void) { char *settings_file = files_get_data_path(FILE_PLUGIN_SETTINGS); if (g_file_test(settings_file, G_FILE_TEST_EXISTS)) { g_chmod(settings_file, S_IRUSR | S_IWUSR); } settings = g_key_file_new(); g_key_file_load_from_file(settings, settings_file, G_KEY_FILE_KEEP_COMMENTS, NULL); gsize g_data_size; gchar *g_data = g_key_file_to_data(settings, &g_data_size, NULL); g_file_set_contents(settings_file, g_data, g_data_size, NULL); g_chmod(settings_file, S_IRUSR | S_IWUSR); g_free(g_data); free(settings_file); }
void plugin_themes_init(void) { char *themes_file = files_get_data_path(FILE_PLUGIN_THEMES); if (g_file_test(themes_file, G_FILE_TEST_EXISTS)) { g_chmod(themes_file, S_IRUSR | S_IWUSR); } themes = g_key_file_new(); g_key_file_load_from_file(themes, themes_file, G_KEY_FILE_KEEP_COMMENTS, NULL); gsize g_data_size; gchar *g_data = g_key_file_to_data(themes, &g_data_size, NULL); g_file_set_contents(themes_file, g_data, g_data_size, NULL); g_chmod(themes_file, S_IRUSR | S_IWUSR); g_free(g_data); free(themes_file); }
GSList* scripts_list(void) { char *scriptsdir = files_get_data_path(DIR_SCRIPTS); GSList *result = NULL; GDir *scripts = g_dir_open(scriptsdir, 0, NULL); free(scriptsdir); if (scripts) { const gchar *script = g_dir_read_name(scripts); while (script) { result = g_slist_append(result, strdup(script)); script = g_dir_read_name(scripts); } g_dir_close(scripts); } return result; }
void python_env_init(void) { loaded_modules = g_hash_table_new_full(g_str_hash, g_str_equal, free, (GDestroyNotify)_unref_module); python_init_prof(); char *plugins_dir = files_get_data_path(DIR_PLUGINS); GString *path = g_string_new("import sys\n"); g_string_append(path, "sys.path.append(\""); g_string_append(path, plugins_dir); g_string_append(path, "/\")\n"); PyRun_SimpleString(path->str); python_check_error(); g_string_free(path, TRUE); g_free(plugins_dir); allow_python_threads(); }
GSList* scripts_read(const char *const script) { char *scriptsdir = files_get_data_path(DIR_SCRIPTS); GString *scriptpath = g_string_new(scriptsdir); free(scriptsdir); g_string_append(scriptpath, "/"); g_string_append(scriptpath, script); FILE *scriptfile = g_fopen(scriptpath->str, "r"); if (!scriptfile) { log_info("Script not found: %s", scriptpath->str); g_string_free(scriptpath, TRUE); return NULL; } g_string_free(scriptpath, TRUE); char *line = NULL; size_t len = 0; ssize_t read; GSList *result = NULL; while ((read = getline(&line, &len, scriptfile)) != -1) { if (g_str_has_suffix(line, "\n")) { result = g_slist_append(result, g_strndup(line, strlen(line) -1)); } else { result = g_slist_append(result, strdup(line)); } } fclose(scriptfile); if (line) free(line); return result; }
void p_gpg_on_connect(const char *const barejid) { char *pgpdir = files_get_data_path(DIR_PGP); GString *pubsfile = g_string_new(pgpdir); free(pgpdir); gchar *account_dir = str_replace(barejid, "@", "_at_"); g_string_append(pubsfile, "/"); g_string_append(pubsfile, account_dir); free(account_dir); // mkdir if doesn't exist for account errno = 0; int res = g_mkdir_with_parents(pubsfile->str, S_IRWXU); if (res == -1) { char *errmsg = strerror(errno); if (errmsg) { log_error("Error creating directory: %s, %s", pubsfile->str, errmsg); } else { log_error("Error creating directory: %s", pubsfile->str); } } // create or read publickeys g_string_append(pubsfile, "/pubkeys"); pubsloc = pubsfile->str; g_string_free(pubsfile, FALSE); if (g_file_test(pubsloc, G_FILE_TEST_EXISTS)) { g_chmod(pubsloc, S_IRUSR | S_IWUSR); } pubkeyfile = g_key_file_new(); g_key_file_load_from_file(pubkeyfile, pubsloc, G_KEY_FILE_KEEP_COMMENTS, NULL); // load each keyid gsize len = 0; gchar **jids = g_key_file_get_groups(pubkeyfile, &len); gpgme_ctx_t ctx; gpgme_error_t error = gpgme_new(&ctx); if (error) { log_error("GPG: Failed to create gpgme context. %s %s", gpgme_strsource(error), gpgme_strerror(error)); g_strfreev(jids); return; } int i = 0; for (i = 0; i < len; i++) { GError *gerr = NULL; gchar *jid = jids[i]; gchar *keyid = g_key_file_get_string(pubkeyfile, jid, "keyid", &gerr); if (gerr) { log_error("Error loading PGP key id for %s", jid); g_error_free(gerr); g_free(keyid); } else { gpgme_key_t key = NULL; error = gpgme_get_key(ctx, keyid, &key, 0); if (error || key == NULL) { log_warning("GPG: Failed to get key for %s: %s %s", jid, gpgme_strsource(error), gpgme_strerror(error)); continue; } ProfPGPPubKeyId *pubkeyid = malloc(sizeof(ProfPGPPubKeyId)); pubkeyid->id = strdup(keyid); pubkeyid->received = FALSE; g_hash_table_replace(pubkeys, strdup(jid), pubkeyid); g_free(keyid); gpgme_key_unref(key); } } gpgme_release(ctx); g_strfreev(jids); _save_pubkeys(); }