void cmd_list_create(struct response *rsp, struct request *req, struct command *cmd) { struct item *it; struct bstring *key = _get_key(req); struct element *reply = (struct element *)array_push(rsp->token); INCR(process_metrics, list_create); it = _add_key(rsp, key); if (it == NULL) { log_debug("command '%.*s' '%.*s' failed: cannot store", cmd->bstr.len, cmd->bstr.data, key->len, key->data); return; } /* initialize data structure */ ziplist_reset((ziplist_p)item_data(it)); it->vlen = ZIPLIST_HEADER_SIZE; /* link into index */ item_insert(it, key); rsp->type = reply->type = ELEM_STR; reply->bstr = str2bstr(RSP_OK); log_verb("command '%.*s' '%.*s' succeeded", cmd->bstr.len, cmd->bstr.data, key->len, key->data); }
static ipmi_config_err_t k_r_checkout (ipmi_config_state_data_t *state_data, const char *section_name, struct ipmi_config_keyvalue *kv) { uint8_t k_r[IPMI_MAX_K_R_LENGTH + 1]; ipmi_config_err_t ret; assert (state_data); assert (section_name); assert (kv); memset (k_r, 0, IPMI_MAX_K_R_LENGTH + 1); if ((ret = _get_key (state_data, section_name, IPMI_CHANNEL_SECURITY_KEYS_KEY_ID_K_R, k_r, IPMI_MAX_K_R_LENGTH)) != IPMI_CONFIG_ERR_SUCCESS) return (ret); k_r[IPMI_MAX_K_R_LENGTH] = '\0'; if (ipmi_config_section_update_keyvalue_output (state_data, kv, (char *)k_r) < 0) return (IPMI_CONFIG_ERR_FATAL_ERROR); return (IPMI_CONFIG_ERR_SUCCESS); }
G_MODULE_EXPORT void on_popup_font_activate(GtkMenuItem *menuitem, gpointer user_data) { if (is_dialog) { gchar *url = g_strdup_printf("sword://%s/%s", dialog->mod_name, dialog->key); gui_set_module_font(dialog->mod_name); /* show the change */ main_dialogs_url_handler(dialog, url, TRUE); g_free(url); } else { gchar *key = _get_key(menu_mod_name); if (key) { gchar *url = g_strdup_printf("sword://%s/%s", menu_mod_name, key); gui_set_module_font(menu_mod_name); /* show the change */ main_url_handler(url, TRUE); g_free(url); g_free(key); } } }
static config_err_t k_r_checkout (const char *section_name, struct config_keyvalue *kv, void *arg) { bmc_config_state_data_t *state_data = (bmc_config_state_data_t *)arg; uint8_t k_r[IPMI_MAX_K_R_LENGTH + 1]; config_err_t ret; memset (k_r, 0, IPMI_MAX_K_R_LENGTH + 1); if ((ret = _get_key (state_data, IPMI_CHANNEL_SECURITY_KEYS_KEY_ID_K_R, (uint8_t *)k_r, IPMI_MAX_K_R_LENGTH)) != CONFIG_ERR_SUCCESS) return ret; k_r[IPMI_MAX_K_R_LENGTH] = '\0'; if (config_section_update_keyvalue_output(state_data->pstate, kv, (char *)k_r) < 0) return CONFIG_ERR_FATAL_ERROR; return CONFIG_ERR_SUCCESS; }
static void _process_get(struct response *rsp, struct request *req) { struct bstring *key; struct response *r = rsp; uint32_t i; INCR(process_metrics, get); /* use chained responses, move to the next response if key is found. */ for (i = 0; i < array_nelem(req->keys); ++i) { INCR(process_metrics, get_key); key = array_get(req->keys, i); if (_get_key(r, key)) { req->nfound++; r->cas = false; r = STAILQ_NEXT(r, next); if (r == NULL) { INCR(process_metrics, get_ex); log_warn("get response incomplete due to lack of rsp objects"); return; } INCR(process_metrics, get_key_hit); } else { INCR(process_metrics, get_key_miss); } } r->type = RSP_END; log_verb("get req %p processed, %d out of %d keys found", req, req->nfound, i); }
void prefs_load(void) { GError *err; prefs_loc = _get_preferences_file(); if (g_file_test(prefs_loc, G_FILE_TEST_EXISTS)) { g_chmod(prefs_loc, S_IRUSR | S_IWUSR); } prefs = g_key_file_new(); g_key_file_load_from_file(prefs, prefs_loc, G_KEY_FILE_KEEP_COMMENTS, NULL); err = NULL; log_maxsize = g_key_file_get_integer(prefs, PREF_GROUP_LOGGING, "maxsize", &err); if (err) { log_maxsize = 0; g_error_free(err); } // move pre 0.4.7 otr.warn to enc.warn err = NULL; gboolean otr_warn = g_key_file_get_boolean(prefs, PREF_GROUP_UI, "otr.warn", &err); if (err == NULL) { g_key_file_set_boolean(prefs, PREF_GROUP_UI, _get_key(PREF_ENC_WARN), otr_warn); g_key_file_remove_key(prefs, PREF_GROUP_UI, "otr.warn", NULL); } else { g_error_free(err); } // migrate pre 0.4.7 time settings format if (g_key_file_has_key(prefs, PREF_GROUP_UI, "time", NULL)) { char *time = g_key_file_get_string(prefs, PREF_GROUP_UI, "time", NULL); if (g_strcmp0(time, "minutes") == 0) { g_key_file_set_string(prefs, PREF_GROUP_UI, "time", "%H:%M"); } else if (g_strcmp0(time, "seconds") == 0) { g_key_file_set_string(prefs, PREF_GROUP_UI, "time", "%H:%M:%S"); } else if (g_strcmp0(time, "off") == 0) { g_key_file_set_string(prefs, PREF_GROUP_UI, "time", ""); } } if (g_key_file_has_key(prefs, PREF_GROUP_UI, "time.statusbar", NULL)) { char *time = g_key_file_get_string(prefs, PREF_GROUP_UI, "time.statusbar", NULL); if (g_strcmp0(time, "minutes") == 0) { g_key_file_set_string(prefs, PREF_GROUP_UI, "time.statusbar", "%H:%M"); } else if (g_strcmp0(time, "seconds") == 0) { g_key_file_set_string(prefs, PREF_GROUP_UI, "time.statusbar", "%H:%M:%S"); } else if (g_strcmp0(time, "off") == 0) { g_key_file_set_string(prefs, PREF_GROUP_UI, "time.statusbar", ""); } } _save_prefs(); boolean_choice_ac = autocomplete_new(); autocomplete_add(boolean_choice_ac, "on"); autocomplete_add(boolean_choice_ac, "off"); }
void prefs_set_boolean(preference_t pref, gboolean value) { const char *group = _get_group(pref); const char *key = _get_key(pref); g_key_file_set_boolean(prefs, group, key, value); _save_prefs(); }
static ipmi_config_err_t k_g_checkout (ipmi_config_state_data_t *state_data, const char *section_name, struct ipmi_config_keyvalue *kv) { uint8_t k_g[IPMI_MAX_K_G_LENGTH]; char k_g_str[IPMI_MAX_K_G_LENGTH*2+3]; ipmi_config_err_t ret; assert (state_data); assert (section_name); assert (kv); memset (k_g, 0, IPMI_MAX_K_G_LENGTH); if ((ret = _get_key (state_data, section_name, IPMI_CHANNEL_SECURITY_KEYS_KEY_ID_K_G, k_g, IPMI_MAX_K_G_LENGTH)) != IPMI_CONFIG_ERR_SUCCESS) return (ret); /* a printable k_g key can have two representations, so compare the * binary keys and return what the user passed in if they are the * same. */ if (state_data->prog_data->args->action == IPMI_CONFIG_ACTION_DIFF) { uint8_t kv_k_g[IPMI_MAX_K_G_LENGTH+1]; memset (kv_k_g, '\0', IPMI_MAX_K_G_LENGTH); if (parse_kg (kv_k_g, IPMI_MAX_K_G_LENGTH + 1, kv->value_input) < 0) return (IPMI_CONFIG_ERR_FATAL_ERROR); if (!memcmp (kv_k_g, k_g, IPMI_MAX_K_G_LENGTH)) { if (ipmi_config_section_update_keyvalue_output (state_data, kv, kv->value_input) < 0) return (IPMI_CONFIG_ERR_FATAL_ERROR); return (IPMI_CONFIG_ERR_SUCCESS); } /* else, fall through and return the default checked out value */ } memset (k_g_str, '\0', IPMI_MAX_K_G_LENGTH*2+3); if (!format_kg (k_g_str, IPMI_MAX_K_G_LENGTH*2+3, k_g)) return (IPMI_CONFIG_ERR_FATAL_ERROR); if (ipmi_config_section_update_keyvalue_output (state_data, kv, k_g_str) < 0) return (IPMI_CONFIG_ERR_FATAL_ERROR); return (IPMI_CONFIG_ERR_SUCCESS); }
static config_err_t k_g_checkout (const char *section_name, struct config_keyvalue *kv, void *arg) { bmc_config_state_data_t *state_data = (bmc_config_state_data_t *)arg; uint8_t k_g[IPMI_MAX_K_G_LENGTH]; char k_g_str[IPMI_MAX_K_G_LENGTH*2+3]; config_err_t ret; memset (k_g, 0, IPMI_MAX_K_G_LENGTH); if ((ret = _get_key (state_data, IPMI_CHANNEL_SECURITY_KEYS_KEY_ID_K_G, k_g, IPMI_MAX_K_G_LENGTH)) != CONFIG_ERR_SUCCESS) return ret; /* a printable k_g key can have two representations, so compare the * binary keys and return what the user passed in if they are the * same. */ if (state_data->prog_data->args->config_args.action == CONFIG_ACTION_DIFF) { uint8_t kv_k_g[IPMI_MAX_K_G_LENGTH+1]; memset (kv_k_g, '\0', IPMI_MAX_K_G_LENGTH); if (parse_kg(kv_k_g, IPMI_MAX_K_G_LENGTH + 1, kv->value_input) < 0) return CONFIG_ERR_FATAL_ERROR; if (!memcmp (kv_k_g, k_g, IPMI_MAX_K_G_LENGTH)) { if (config_section_update_keyvalue_output(state_data->pstate, kv, kv->value_input) < 0) return CONFIG_ERR_FATAL_ERROR; return CONFIG_ERR_SUCCESS; } /* else, fall through and return the default checked out value */ } memset(k_g_str, '\0', IPMI_MAX_K_G_LENGTH*2+3); if (!format_kg(k_g_str, IPMI_MAX_K_G_LENGTH*2+3, (unsigned char *)k_g)) return CONFIG_ERR_FATAL_ERROR; if (config_section_update_keyvalue_output(state_data->pstate, kv, (char *)k_g_str) < 0) return CONFIG_ERR_FATAL_ERROR; return CONFIG_ERR_SUCCESS; }
void prefs_set_string(preference_t pref, char *value) { const char *group = _get_group(pref); const char *key = _get_key(pref); if (value == NULL) { g_key_file_remove_key(prefs, group, key, NULL); } else { g_key_file_set_string(prefs, group, key, value); } _save_prefs(); }
gboolean prefs_get_boolean(preference_t pref) { const char *group = _get_group(pref); const char *key = _get_key(pref); gboolean def = _get_default_boolean(pref); if (!g_key_file_has_key(prefs, group, key, NULL)) { return def; } return g_key_file_get_boolean(prefs, group, key, NULL); }
G_MODULE_EXPORT void on_mark_verse_activate(GtkMenuItem *menuitem, gpointer user_data) { gchar *key; if (is_dialog) return; if ((key = _get_key(menu_mod_name))) { gui_mark_verse_dialog(menu_mod_name, key); g_free(key); } }
static void on_edit_percomm_activate(GtkMenuItem *menuitem, gpointer user_data) { gchar *key; if (is_dialog) key = g_strdup(dialog->key); else key = _get_key(menu_mod_name); if (key) { XI_message(("\n\npercomm key: %s\n\n", key)); editor_create_new((gchar *)user_data, (gchar *)key, NOTE_EDITOR); g_free(key); } }
G_MODULE_EXPORT void on_popup_bookmark_activate(GtkMenuItem *menuitem, gpointer user_data) { gchar *key; if (is_dialog) return; if ((key = _get_key(menu_mod_name))) { gchar *label = g_strdup_printf("%s, %s", key, menu_mod_name); gui_bookmark_dialog(label, menu_mod_name, key); g_free(label); g_free(key); } }
static void on_view_mod_activate(GtkMenuItem *menuitem, gpointer user_data) { if (is_dialog) return; gchar *module_name = main_module_name_from_description((gchar *)user_data); gchar *key; if (module_name && (key = _get_key(menu_mod_name))) { gchar *url = g_strdup_printf("sword://%s/%s", module_name, key); main_url_handler(url, TRUE); g_free(url); } g_free(module_name); g_free(key); }
char * prefs_get_string(preference_t pref) { const char *group = _get_group(pref); const char *key = _get_key(pref); char *def = _get_default_string(pref); if (!g_key_file_has_key(prefs, group, key, NULL)) { return def; } char *result = g_key_file_get_string(prefs, group, key, NULL); if (result == NULL) { return def; } else { return result; } }
////////////// // show_for_a_locator // k \t locator ////////////// _show_for_a_locator_subtest(char* buf, istream& in, mark_base* ub) { char* key; if ( strcmp(buf, "show_for_a_locator") == 0 ) { cout << ">>> show_for_a_locator:" << endl; _get_key(in, key); oid_list_handler* z = ub-> get_mark_list(key); if ( z == 0 ) throw(stringException("empty oid_list")); int ind = (*z) -> first(); while (ind) { oid_t id = (*z) -> operator()(ind); if ( id.eq(ground) == false ) { mark_smart_ptr y(ub, id); cout << y.its_oid(); cout << "\n"; cout << y.node_locator(); cout << "\n"; cout << *(y.mark_value()); cout << "\n"; } (*z) -> next(ind); } delete z; cout << "<<< show_for_a_locator" << endl; } else return 1; }
void SG_password__set( SG_context* pCtx, const char *szRepoSpec, SG_string *pstrUserName, SG_string *pstrPassword) { SG_string* pstrTarget = NULL; LPWSTR pwszTarget = NULL; LPWSTR pwszPassword = NULL; SG_uint32 lenPassword = 0; LPWSTR pwszUserName = NULL; CREDENTIAL cred; SG_NULLARGCHECK_RETURN(szRepoSpec); SG_NULLARGCHECK_RETURN(pstrUserName); SG_NULLARGCHECK_RETURN(pstrPassword); if (!SG_string__length_in_bytes(pstrUserName)) SG_ERR_THROW2_RETURN(SG_ERR_INVALIDARG, (pCtx, "%s", "pstrUserName is empty")); SG_ERR_CHECK( _get_key(pCtx, szRepoSpec, SG_string__sz(pstrUserName), &pstrTarget) ); SG_ERR_CHECK( SG_utf8__extern_to_os_buffer__wchar(pCtx, SG_string__sz(pstrTarget), &pwszTarget, NULL) ); SG_ERR_CHECK( SG_utf8__extern_to_os_buffer__wchar(pCtx, SG_string__sz(pstrPassword), &pwszPassword, &lenPassword) ); SG_ERR_CHECK( SG_utf8__extern_to_os_buffer__wchar(pCtx, SG_string__sz(pstrUserName), &pwszUserName, NULL) ); SG_zero(cred); cred.Type = CRED_TYPE_GENERIC; cred.TargetName = pwszTarget; cred.CredentialBlob = (LPBYTE)pwszPassword; cred.CredentialBlobSize = lenPassword*sizeof(wchar_t); cred.Persist = CRED_PERSIST_LOCAL_MACHINE; // unsupported on Windows Vista Home Basic, Windows Vista Home Premium, Windows Vista Starter, and Windows XP Home Edition cred.UserName = pwszUserName; if ( !CredWriteW(&cred, 0) ) SG_ERR_THROW2( SG_ERR_GETLASTERROR(GetLastError()), (pCtx, "%s", "unable to save credentials") ); /* fall through */ fail: SG_STRING_NULLFREE(pCtx, pstrTarget); SG_NULLFREE(pCtx, pwszTarget); SG_NULLFREE(pCtx, pwszPassword); SG_NULLFREE(pCtx, pwszUserName); }
void cmd_list_delete(struct response *rsp, struct request *req, struct command *cmd) { struct bstring *key = _get_key(req); struct element *reply = (struct element *)array_push(rsp->token); INCR(process_metrics, list_delete); if (item_delete(key)) { reply->bstr = str2bstr(RSP_OK); INCR(process_metrics, list_delete_deleted); log_verb("command '%.*s' '%.*s' succeeded", cmd->bstr.len, cmd->bstr.data, key->len, key->data); } else { reply->bstr = str2bstr(RSP_NOTFOUND); INCR(process_metrics, list_delete_notfound); log_verb("command '%.*s' '%.*s' completed as no-op, key not found", cmd->bstr.len, cmd->bstr.data, key->len, key->data); } }
////////////// // get_by_oid // k \t oidInAscii ////////////// _get_by_oid_subtest(char* buf, istream& in, mark_base* ub) { char* key; mark_smart_ptr* x = 0; if ( strcmp(buf, "get_by_oid") == 0 ) { _get_key(in, key); oid_t id(key, true, false); x = new mark_smart_ptr(ub, id); cout << x->node_locator(); cout << "\n"; cout << *(x->mark_value()); cout << "\n"; delete x; } else return 1; }
////////////// // create // k \t locator // d \t data ////////////// int _create_subtest(char* buf, istream& in, mark_base* ub) { char* key, *data; mark_smart_ptr* x = 0; if ( strcmp(buf, "create") == 0 ) { cout << ">>> create:" << endl; _get_key(in, key); _get_data(in, data); cout << "---- new mark smtart_ptr ..." << endl; x = new mark_smart_ptr(ub, key); cout << "---- updating ..." << endl; x -> update_usermark(data, strlen(data)); delete x; cout << "<<< create:" << endl; } else return 1; }
G_MODULE_EXPORT void on_all_readings_activate(GtkCheckMenuItem *menuitem, gpointer user_data) { gchar *key = NULL; if (is_dialog) { reading_selector(dialog->mod_name, dialog->key, dialog, (GtkMenuItem *)menuitem, GINT_TO_POINTER(2)); } else { if ((key = _get_key(menu_mod_name))) { reading_selector(menu_mod_name, key, NULL, (GtkMenuItem *)menuitem, GINT_TO_POINTER(2)); g_free(key); } } }
static void _global_option_main_pane(GtkMenuItem *menuitem, const gchar *option) { gchar *key = _get_key(menu_mod_name); gchar *mod = (gchar *)(is_dialog ? dialog->mod_name : menu_mod_name); XI_message(("module option = %s", option)); if (key) { gchar *url = g_strdup_printf("sword://%s/%s", mod, key); main_save_module_options(mod, (gchar *)option, gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(menuitem))); if (is_dialog) { /* show the change */ main_dialogs_url_handler(dialog, url, TRUE); } else { /* show the change */ main_url_handler(url, TRUE); } g_free(url); g_free(key); } }
static int modkey_key( INSTANCE * my, int * params ) { return ( _get_key( params[0] ) ); }
void SG_password__get( SG_context *pCtx, const char *szRepoSpec, const char *szUsername, SG_string **ppstrPassword) { SG_string* pstrTarget = NULL; SG_string* pstrPassword = NULL; LPWSTR pwszTarget = NULL; SG_byte* pbPassword = NULL; PCREDENTIAL pCred = NULL; BOOL result = FALSE; SG_NULLARGCHECK_RETURN(szRepoSpec); SG_NULLARGCHECK_RETURN(szUsername); SG_NULLARGCHECK_RETURN(ppstrPassword); _get_key(pCtx, szRepoSpec, szUsername, &pstrTarget); if (SG_CONTEXT__HAS_ERR(pCtx)) { SG_error err, err2; err2 = SG_context__get_err(pCtx, &err); if (SG_IS_ERROR(err2)) { SG_ERR_DISCARD; SG_ERR_THROW(err2); } if (err & __SG_ERR__GETLASTERROR__) SG_ERR_DISCARD; else SG_ERR_RETHROW; } if (pstrTarget) { SG_ERR_CHECK( SG_utf8__extern_to_os_buffer__wchar(pCtx, SG_string__sz(pstrTarget), &pwszTarget, NULL) ); result = CredReadW(pwszTarget, CRED_TYPE_GENERIC, 0, &pCred); if (!result) { DWORD err = GetLastError(); if (err != ERROR_NOT_FOUND && err != ERROR_NO_SUCH_LOGON_SESSION) SG_ERR_THROW2( SG_ERR_GETLASTERROR(GetLastError()), (pCtx, "%s", "unable to retrieve saved credentials") ); } else { SG_uint32 size = pCred->CredentialBlobSize+sizeof(wchar_t); SG_ERR_CHECK( SG_allocN(pCtx, pCred->CredentialBlobSize+sizeof(wchar_t), pbPassword) ); memcpy(pbPassword, pCred->CredentialBlob, size); SG_ERR_CHECK( SG_string__alloc(pCtx, &pstrPassword) ); SG_ERR_CHECK( SG_utf8__intern_from_os_buffer__wchar(pCtx, pstrPassword, (const LPWSTR)pbPassword) ); *ppstrPassword = pstrPassword; pstrPassword = NULL; } } /* fall through */ fail: SG_STRING_NULLFREE(pCtx, pstrTarget); SG_STRING_NULLFREE(pCtx, pstrPassword); SG_NULLFREE(pCtx, pwszTarget); SG_NULLFREE(pCtx, pbPassword); if (pCred) CredFree(pCred); }
void pmi_get_key_rem(int rank, char *key_name, int **key_val, int *key_size) { _get_key(rank, key_name, key_val, key_size); }
const void* get_key_ptr(const K* key, size_t *key_length) const { if (G == HashMap__get_key) return key; return _get_key((const uchar*)key, key_length, false); }