/** * Load history form the mc_config */ GList * history_load (struct mc_config_t * cfg, const char *name) { size_t i; GList *hist = NULL; char **keys; size_t keys_num = 0; GIConv conv = INVALID_CONV; GString *buffer; if (name == NULL || *name == '\0') return NULL; /* get number of keys */ keys = mc_config_get_keys (cfg, name, &keys_num); g_strfreev (keys); /* create charset conversion handler to convert strings from utf-8 to system codepage */ if (!mc_global.utf8_display) conv = str_crt_conv_from ("UTF-8"); buffer = g_string_sized_new (64); for (i = 0; i < keys_num; i++) { char key[BUF_TINY]; char *this_entry; g_snprintf (key, sizeof (key), "%lu", (unsigned long) i); this_entry = mc_config_get_string_raw (cfg, name, key, ""); if (this_entry == NULL) continue; if (conv == INVALID_CONV) hist = list_append_unique (hist, this_entry); else { g_string_set_size (buffer, 0); if (str_convert (conv, this_entry, buffer) == ESTR_FAILURE) hist = list_append_unique (hist, this_entry); else { hist = list_append_unique (hist, g_strdup (buffer->str)); g_free (this_entry); } } } g_string_free (buffer, TRUE); if (conv != INVALID_CONV) str_close_conv (conv); /* return pointer to the last entry in the list */ return g_list_last (hist); }
static void push_history (WInput * in, const char *text) { /* input widget where urls with passwords are entered without any vfs prefix */ const char *password_input_fields[] = { " Link to a remote machine ", " FTP to machine ", " SMB link to machine " }; const size_t ELEMENTS = (sizeof (password_input_fields) / sizeof (password_input_fields[0])); char *t; size_t i; gboolean empty; if (text == NULL) return; #ifdef ENABLE_NLS for (i = 0; i < ELEMENTS; i++) password_input_fields[i] = _(password_input_fields[i]); #endif t = g_strstrip (g_strdup (text)); empty = *t == '\0'; g_free (t); t = g_strdup (empty ? "" : text); if (in->history_name != NULL) { /* FIXME: It is the strange code. Rewrite is needed. */ const char *p = in->history_name + 3; for (i = 0; i < ELEMENTS; i++) if (strcmp (p, password_input_fields[i]) == 0) break; strip_password (t, i >= ELEMENTS); } if (in->history == NULL || in->history->data == NULL || strcmp (in->history->data, t) != 0 || in->history_changed) { in->history = list_append_unique (in->history, t); in->history_changed = TRUE; } else g_free (t); in->need_push = FALSE; }
static void push_history (WInput * in, const char *text) { char *t; gboolean empty; if (text == NULL) return; t = g_strstrip (g_strdup (text)); empty = *t == '\0'; g_free (t); t = g_strdup (empty ? "" : text); if (!empty && in->history.name != NULL && in->strip_password) { /* We got string user:pass@host without any VFS prefixes and vfs_path_to_str_flags (t, VPF_STRIP_PASSWORD) doesn't work. Therefore we want to strip password in separate algorithm */ char *url_with_stripped_password; url_with_stripped_password = input_history_strip_password (t); g_free (t); t = url_with_stripped_password; } if (in->history.list == NULL || in->history.list->data == NULL || strcmp (in->history.list->data, t) != 0 || in->history.changed) { in->history.list = list_append_unique (in->history.list, t); in->history.current = in->history.list; in->history.changed = TRUE; } else g_free (t); in->need_push = FALSE; }