//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //controltype_button_notify //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ void controltype_button_notify(control *c, int notifytype, void *messagedata) { //Variables controltype_button_details *details; bool *newvalueptr; //Get details details = (controltype_button_details *) c->controldetails; //Find out what to do switch (notifytype) { case NOTIFY_NEEDUPDATE: //When we are told we need an update, figure out what to do //Update the caption first if (details->agents[CONTROLTYPE_BUTTON_CAPTION]) { details->caption = (char *) agent_getdata(details->agents[CONTROLTYPE_BUTTON_CAPTION], DATAFETCH_VALUE_TEXT); } else { details->caption = NULL; } //Only two state buttons need updates at this point if (details->is_twostate) { //Get the value newvalueptr = (bool *)(agent_getdata(details->agents[CONTROLTYPE_TWOSTATEBUTTON_AGENT_VALUECHANGE], DATAFETCH_VALUE_BOOL)); if (newvalueptr) { //Set the new value details->is_on = *newvalueptr; } } //Tell the button to draw itself again style_draw_invalidate(c); break; case NOTIFY_SAVE_CONTROL: //Save all local values config_write(config_get_control_setcontrolprop_c(c, "HAlign", button_haligns[details->halign])); config_write(config_get_control_setcontrolprop_c(c, "VAlign", button_valigns[details->valign])); int i; for (i = 0; i < CONTROLTYPE_BUTTON_AGENTCOUNT; i++) agent_notify(details->agents[i], NOTIFY_SAVE_AGENT, NULL); if (details->is_twostate) config_write(config_get_control_setcontrolprop_b(c, "Pressed", &details->is_on)); break; case NOTIFY_DRAGACCEPT: DragAcceptFiles(c->windowptr->hwnd, NULL != details->agents[details->is_twostate ? CONTROLTYPE_TWOSTATEBUTTON_AGENT_ONDROP : CONTROLTYPE_BUTTON_AGENT_ONDROP]); break; } }
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //controltype_label_notify //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ void controltype_label_notify(control *c, int notifytype, void *messagedata) { //Variables controltype_label_details *details; int i; //Get details details = (controltype_label_details *) c->controldetails; //Find out what to do switch (notifytype) { case NOTIFY_NEEDUPDATE: //When we are told we need an update, figure out what to do //Update the caption first if (details->agents[CONTROLTYPE_LABEL_AGENT_CAPTION]) { details->caption = (char *) agent_getdata(details->agents[CONTROLTYPE_LABEL_AGENT_CAPTION], DATAFETCH_VALUE_TEXT); } else { details->caption = NULL; } //Tell the label to draw itself again style_draw_invalidate(c); break; case NOTIFY_SAVE_CONTROL: //Save all local values config_write(config_get_control_setcontrolprop_c(c, "HAlign", label_haligns[details->halign])); config_write(config_get_control_setcontrolprop_c(c, "VAlign", label_valigns[details->valign])); if (details->is_frame) { config_write(config_get_control_setcontrolprop_b(c, "HasTitleBar", &details->has_titlebar)); config_write(config_get_control_setcontrolprop_b(c, "IsLocked", &details->is_locked)); } for (i = 0; i < CONTROLTYPE_LABEL_AGENT_COUNT; i++) agent_notify(details->agents[i], NOTIFY_SAVE_AGENT, NULL); if (details->is_frame) controltype_frame_saveplugins(c); break; case NOTIFY_DRAGACCEPT: DragAcceptFiles(c->windowptr->hwnd, NULL != details->agents[CONTROLTYPE_LABEL_AGENT_ONDROP]); break; } }
void config_initialize() { // Build config directory name gchar * config_dir = g_build_filename(g_get_user_config_dir(), CONFIG_DIRNAME, NULL); m_config_file = g_build_filename(config_dir, CONFIG_FILENAME, NULL); // Make sure config directory exists if(!g_file_test(config_dir, G_FILE_TEST_IS_DIR)) g_mkdir(config_dir, 0777); // If a config file doesn't exist, create one with defaults otherwise // read the existing one. if(!g_file_test(m_config_file, G_FILE_TEST_EXISTS)) { config_load_default(); config_write(); } else { config_read(); } g_free(config_dir); }
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //agenttype_switchedstate_notify //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ void agenttype_switchedstate_notify(agent *a, int notifytype, void *messagedata) { //Get the agent details agenttype_switchedstate_details *details = (agenttype_switchedstate_details *) a->agentdetails; //Declare variables bool *boolptr; switch(notifytype) { case NOTIFY_DRAW: case NOTIFY_CHANGE: //Get the boolean value boolptr = (bool *) agent_getdata(details->agents[AGENTTYPE_SWITCHEDSTATE_AGENT_BOOL], DATAFETCH_VALUE_BOOL); //Do the appropriate action if (boolptr != NULL && *boolptr == true) return agent_notify(details->agents[AGENTTYPE_SWITCHEDSTATE_AGENT_WHENTRUE], notifytype, messagedata); else return agent_notify(details->agents[AGENTTYPE_SWITCHEDSTATE_AGENT_WHENFALSE], notifytype, messagedata); break; case NOTIFY_SAVE_AGENT: //Write existance config_write(config_get_control_setagent_c(a->controlptr, a->agentaction, a->agenttypeptr->agenttypename, agenttype_switchedstate_typenames[details->datatype])); //Save all child agents, if necessary for (int i = 0; i < 3; i++) agent_notify(details->agents[i], NOTIFY_SAVE_AGENT, NULL); break; } }
/** * Start up the configuration system, using the configuration file given * to get the current values. If the configuration file given does not exist, * go ahead and write out the default config to the file. */ gint config_init (const gchar *config_file) { gint ret = 0; tc = cfg_init (config_opts, 0); /* I know that this is racy, but I can't think of a good * way to fix it ... */ if (g_file_test (config_file, G_FILE_TEST_IS_REGULAR)) { /* Read the file, and try to upgrade it */ ret = cfg_parse (tc, config_file); if (ret == CFG_SUCCESS) try_to_update_config_file (config_file); else { DEBUG_ERROR ("Problem parsing config"); g_printerr (_("Problem parsing config file\n")); return 1; } } /* This is commented out because we don't want to do this. Basically, there * is no need to write the config until we have shown the wizard, which is * automatically shown on the first run. */ #if 0 else { /* Write out the defaults */ config_write (config_file); } #endif return 0; }
irom static app_action_t application_function_config_write(application_parameters_t ap) { config_write(); strlcpy(ap.dst, "config write OK\n", ap.size); return(app_action_normal); }
//quit void quit() { free_lists(); config_write(); SetWindowLong( plugin.hwndParent, GWL_WNDPROC, ( LONG )lpWndProcOld ); }
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //plugin_save //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ void plugin_save() { config_printf("!---- %s ----", szVersion); for (struct plugin_properties *p = plugin_properties; p->key; p++) if (p->data) switch (p->type) { case M_BOL: config_write(config_get_plugin_setpluginprop_b(p->key, (bool*)p->data)); break; case M_INT: config_write(config_get_plugin_setpluginprop_i(p->key, (const int*)p->data)); break; case M_STR: config_write(config_get_plugin_setpluginprop_c(p->key, *(const char**)p->data)); break; } //Save OnLoad/OnUnload actions config_write(config_get_plugin_onload()); config_write(config_get_plugin_onunload()); variables_save(); }
static void OnDestroy(HWND hwnd) { write_text(); config_write(); systray_del(hwnd,1024); PostQuitMessage(0); }
/* SYNTAX: UPGRADE [<irssi binary path>] */ static void cmd_upgrade(const char *data) { CONFIG_REC *session; char *session_file, *str; char *binary; if (*data == '\0') data = irssi_binary; if ((binary = g_find_program_in_path(data)) == NULL) cmd_return_error(CMDERR_PROGRAM_NOT_FOUND); /* save the session */ session_file = g_strdup_printf("%s/session", get_irssi_dir()); session = config_open(session_file, 0600); unlink(session_file); signal_emit("session save", 1, session); config_write(session, NULL, -1); config_close(session); /* data may contain some other program as well, like /UPGRADE /usr/bin/screen irssi */ str = g_strdup_printf("%s --noconnect --session=%s --home=%s --config=%s", binary, session_file, get_irssi_dir(), get_irssi_config()); g_free(binary); g_free(session_file); session_args = g_strsplit(str, " ", -1); g_free(str); signal_emit("gui exit", 0); }
static void write_server(GQServerList* list, GqServer* server, gpointer user_data) { gpointer* wc_and_cfg = user_data; struct writeconfig* wc = wc_and_cfg[0]; struct gq_config * cfg = wc_and_cfg[1]; /* GString *pw = g_string_new(); */ config_write(wc, "<ldapserver>\n"); wc->indent++; config_write_string(wc, server->name, "name", NULL); config_write_string(wc, server->ldaphost, "ldaphost", NULL); config_write_int(wc, server->ldapport, "ldapport", NULL); config_write_string_ne(wc, server->basedn, "basedn", NULL); config_write_string_ne(wc, server->binddn, "binddn", NULL); if (cfg->config_version == 0) { config_write_string_ne(wc, server->bindpw, "bindpw", NULL); } else if(server->bindpw && *server->bindpw) { gq_keyring_save_server_password(server); } if(server->bindtype != DEFAULT_BINDTYPE) config_write_string_ne(wc, detokenize(token_bindtype, server->bindtype), "bindtype", NULL); config_write_string_ne(wc, server->searchattr, "search-attribute", NULL); if(server->maxentries != DEFAULT_MAXENTRIES) config_write_int(wc, server->maxentries, "maxentries", NULL); if(server->cacheconn != DEFAULT_CACHECONN) config_write_bool(wc, server->cacheconn, "cache-connection", NULL); if(server->enabletls != DEFAULT_ENABLETLS) config_write_bool(wc, server->enabletls, "enable-tls", NULL); if(server->local_cache_timeout != DEFAULT_LOCAL_CACHE_TIMEOUT) config_write_int(wc, server->local_cache_timeout, "local-cache-timeout", NULL); if(server->ask_pw != DEFAULT_ASK_PW) config_write_bool(wc, server->ask_pw, "ask-pw", NULL); if(server->hide_internal != DEFAULT_HIDE_INTERNAL) config_write_bool(wc, server->hide_internal, "hide-internal", NULL); if(server->show_ref != DEFAULT_SHOW_REF) config_write_bool(wc, server->show_ref, "show-ref", NULL); wc->indent--; config_write(wc, "</ldapserver>\n\n"); }
static int wallet_save_keys(struct wallet *wallet) { struct config *cfg; int res; int n; n = hashtable_getnumentries(wallet->hash_keys); Log(LGPFX" saving %u key%s in %sencrypted wallet %s.\n", n, n > 1 ? "s" : "", wallet->pass ? "encrypted" : "NON-", wallet->filename); cfg = config_create(); config_setint64(cfg, n, "numKeys"); if (wallet->pass) { char saltStr[80]; int64 count = 0; bool s; res = RAND_bytes(wallet->ckey->salt, sizeof wallet->ckey->salt); if (res != 1) { res = ERR_get_error(); Log(LGPFX" RAND_bytes failed: %d\n", res); goto exit; } str_snprintf_bytes(saltStr, sizeof saltStr, NULL, wallet->ckey->salt, sizeof wallet->ckey->salt); config_setstring(cfg, saltStr, "encryption.salt"); s = crypt_set_key_from_passphrase(wallet->pass, wallet->ckey, &count); ASSERT(s); ASSERT(count >= CRYPT_NUM_ITERATIONS_OLD); config_setint64(cfg, count, "encryption.numIterations"); } hashtable_for_each(wallet->hash_keys, wallet_save_key_cb, cfg); file_rotate(wallet->filename, 1); res = file_create(wallet->filename); if (res) { Log(LGPFX" failed to create file '%s': %s\n", wallet->filename, strerror(res)); goto exit; } res = file_chmod(wallet->filename, 0600); if (res) { Log(LGPFX" failed to chmod 0600 wallet.dat: %s\n", strerror(res)); goto exit; } res = config_write(cfg, wallet->filename); exit: config_free(cfg); return res; }
static int sig_write_users(void) { if (last_write + WRITE_USERS_INTERVAL <= time(NULL)) { last_write = time(NULL); config_write(userconfig, NULL, -1); } return 1; }
void config_write_end_tag(struct writeconfig *wc, const char *entity) { GString *outstr = g_string_sized_new(128); end_tag(outstr, entity); config_write(wc, outstr->str); g_string_free(outstr, TRUE); }
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //agenttype_diskspacemonitor_notify //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ void agenttype_diskspacemonitor_notify(agent *a, int notifytype, void *messagedata) { //Get the agent details agenttype_diskspacemonitor_details *details = (agenttype_diskspacemonitor_details *) a->agentdetails; switch(notifytype) { case NOTIFY_CHANGE: control_notify(a->controlptr, NOTIFY_NEEDUPDATE, NULL); break; case NOTIFY_SAVE_AGENT: //Write existance config_write(config_get_control_setagent_c(a->controlptr, a->agentaction, a->agenttypeptr->agenttypename, agenttype_diskspacemonitor_types[details->monitor_type])); config_write(config_get_control_setagentprop_c(a->controlptr, a->agentaction, "MonitoringPath",details->path)); break; } }
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //agenttype_networkmonitor_notify //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ void agenttype_networkmonitor_notify(agent *a, int notifytype, void *messagedata) { //Get the agent details agenttype_networkmonitor_details *details = (agenttype_networkmonitor_details *) a->agentdetails; switch(notifytype) { case NOTIFY_CHANGE: control_notify(a->controlptr, NOTIFY_NEEDUPDATE, NULL); break; case NOTIFY_SAVE_AGENT: //Write existance config_write(config_get_control_setagent_c(a->controlptr, a->agentaction, a->agenttypeptr->agenttypename, agenttype_networkmonitor_interface_numbers[details->monitor_interface_number])); config_write(config_get_control_setagentprop_i(a->controlptr,a->agentaction, "MonitorType",&details->monitor_types)); break; } }
void flg_set_addr(void *data, uint8_t addr) { config.addr = addr; config_write(); cli(); wdt_disable(); wdt_enable(WDTO_15MS); while(1) {} }
int32_t platform_set_cik(const char *cik) { /* * There should be a 4 byte aligned container, because * NVM uses the data from 4byte aligned memory, if it's not aligned * it will write the preceding garbage **/ config_write(NULL, NULL, NULL, cik); return ERR_SUCCESS; }
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //agenttype_mixer_notify //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ void agenttype_mixer_notify_xp (agent *a, int notifytype, void *messagedata) { //Get the agent details AgentType_Mixer_XP * details = static_cast<AgentType_Mixer_XP *>(a->agentdetails); //Variables double *value_double = NULL; bool *value_bool = NULL; MIXERCONTROLDETAILS_UNSIGNED mixer_setcontrol_value_double; MIXERCONTROLDETAILS_BOOLEAN mixer_setcontrol_value_bool; switch (notifytype) { case NOTIFY_CHANGE: { //Set up the values if (a->agenttypeptr->format & CONTROL_FORMAT_SCALE) { value_double = (double *) messagedata; details->m_mixer_controldetails.paDetails = &mixer_setcontrol_value_double; } else if (a->agenttypeptr->format & CONTROL_FORMAT_BOOL) { value_bool = (bool *) messagedata; details->m_mixer_controldetails.paDetails = &mixer_setcontrol_value_bool; } //Retrieve the details if (MMSYSERR_NOERROR != mixerGetControlDetails((HMIXEROBJ) details->m_mixer_handle, &details->m_mixer_controldetails, MIXER_GETCONTROLDETAILSF_VALUE)) return; //Set the value if (a->agenttypeptr->format & CONTROL_FORMAT_SCALE) { mixer_setcontrol_value_double.dwValue = (ULONG) (*value_double * 65535); } else if (a->agenttypeptr->format & CONTROL_FORMAT_BOOL) { mixer_setcontrol_value_bool.fValue = *value_bool; } //Reload the details MMRESULT const res = mixerSetControlDetails((HMIXEROBJ) details->m_mixer_handle, &details->m_mixer_controldetails, MIXER_SETCONTROLDETAILSF_VALUE); if (MMSYSERR_NOERROR != res) return; break; } case NOTIFY_SAVE_AGENT: //Write existance char temp[30]; sprintf(temp, "%d %d %d", (int)details->m_device, (int)details->m_line, (int)details->m_control); config_write(config_get_control_setagent_c(a->controlptr, a->agentaction, a->agenttypeptr->agenttypename, temp)); break; } }
void config_write_start_tag(struct writeconfig *wc, const char *entity, GHashTable *attr) { GString *outstr = g_string_sized_new(128); start_tag(outstr, entity, attr); g_string_append(outstr, "\n"); config_write(wc, outstr->str); g_string_free(outstr, TRUE); }
/*! ******************************************************************************* * Update configuration storage * * \note ******************************************************************************/ void eeprom_config_save(uint8_t idx) { if (idx<CONFIG_RAW_SIZE) { if (config_raw[idx] != config_value(idx)) { if ((config_raw[idx] < config_min(idx)) //min || (config_raw[idx] > config_max(idx))) { //max config_raw[idx] = config_default(idx); // default value } config_write(idx, config_raw[idx]); } } }
/* Note: set config_file to NULL to just free the * data structures, and not write out the state to * a file. */ gint config_free (const gchar *config_file) { gint ret = 0; if (config_file != NULL) ret = config_write (config_file); cfg_free (tc); return ret; }
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //controltype_frame_saveplugins //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ void controltype_frame_saveplugins(control *c) { controltype_label_details *details = (controltype_label_details *) c->controldetails; // Save Plugins ModuleInfo *m = details->module_info; if (NULL == m) return; config_printf("!---- %s::ExternalPlugins ----", c->controlname); for (;m; m=m->next) { config_write(config_get_control_plugin_c(c, "Load", m->file_name)); bool temp = plugin_getset_show_state(details->plugin_info, m->module_name, 3); config_write(config_get_control_plugin_prop_b(c, m->module_name, "IsVisible", temp)); PluginInfo *p = details->plugin_info; for (;p; p=p->next) { if (p->hMO == m->hMO) config_write(config_get_control_plugin_prop_ii(c, p->module_name, "Position", p->xpos, p->ypos)); } } }
int bot_destroy(struct bot* b) { config_write(b->conf, "config.conf"); conn_destroy(b->conn); config_destroy(b->conf); free(b->conn); free(b->conf); b->conn=NULL; b->conf=NULL; if(!b->conn && !b->conf) return 0; else return -1; }
void config_write_int(struct writeconfig *wc, int value, const char *entity, GHashTable *attr) { GString *outstr = g_string_sized_new(128); start_tag(outstr, entity, attr); g_string_sprintfa(outstr, "%d", value); end_tag(outstr, entity); config_write(wc, outstr->str); g_string_free(outstr, TRUE); }
static void on_button_apply() { extern unsigned int timeout; g_cfg.stdby_after = a2i(to_sec); /* apply new timeout */ timeout = g_cfg.stdby_after * 1000; config_write(); frame_config(); }
int config_write_file(config_t *config, const char *filename) { FILE *f = fopen(filename, "wt"); if(! f) { config->error_text = __io_error; return(CONFIG_FALSE); } config_write(config, f); fclose(f); return(CONFIG_TRUE); }
int settings_save(const char *fname) { char *str; if (config_write(mainconfig, fname, 0660) == 0) return TRUE; /* error */ str = g_strdup_printf(_("Couldn't save configuration file: %s"), config_last_error(mainconfig)); signal_emit("gui dialog", 2, "error", str); g_free(str); return FALSE; }
int config_write_file(config_t *config, const char *filename) { FILE *stream = fopen(filename, "wt"); if(stream == NULL) { config->error_text = __io_error; config->error_type = CONFIG_ERR_FILE_IO; return(CONFIG_FALSE); } config_write(config, stream); fclose(stream); config->error_type = CONFIG_ERR_NONE; return(CONFIG_TRUE); }
/* Save a preset to the "blursk-presets" file, or if item==NULL then save all * items into "blursk-presets". (The latter method is used when deleting a * preset -- After deleting it from RAM, it writes all others out to the file. */ static void preset_write(preset_t *item) { gint force; /* were we given a specific item to save? */ if (item) { /* save this item to the "blursk-presets" file */ config_write(FALSE, item->title, &item->conf); } else { /* save all items to the "blursk-presets" file. For the first * item only, call it with the "force" parameter set to TRUE * so that the file's old contents are discarded. */ for (force = TRUE, item = preset_list; item; force = FALSE, item = item->next) { config_write(force, item->title, &item->conf); } } }