int config_load (rockon_config *config) { char *username; int ipc_path_lenght; assert(config); /* default values */ config->launch_server = 0; config->auto_reconnect = 0; config->reconnect_interval = 3; username = getenv("USER"); ipc_path_lenght = strlen(username) + 22; config->ipc_path = (char*) malloc(sizeof(char) * ipc_path_lenght); if (config->ipc_path == NULL) { EINA_LOG_CRIT("malloc ipc_path failed"); return 0; } snprintf(config->ipc_path, ipc_path_lenght, "unix:///tmp/xmms-ipc-%s", username); if ((config->config_filename = get_config_filename ("rockon.conf"))) { config->lcfg_obj = lcfg_new(config->config_filename); if (lcfg_parse(config->lcfg_obj) != lcfg_status_ok) { return 0; } lcfg_accept(config->lcfg_obj, config_visitor_load, config); return 1; } return 0; }
static gboolean read_config (GtkFileChooserSettings *settings, GError **error) { char *filename; char *contents; gsize contents_len; gboolean success; filename = get_config_filename (); success = g_file_get_contents (filename, &contents, &contents_len, error); g_free (filename); if (!success) { set_defaults (settings); return FALSE; } success = parse_config (settings, contents, error); g_free (contents); return success; }
bool flush_config_file(FILE *f, const char *conf_filename) { char dst_file[256], tmp_file[256], bak_file[256]; get_config_filename(dst_file, sizeof(dst_file), conf_filename); memcpy(tmp_file, dst_file, sizeof(tmp_file)); memcpy(bak_file, dst_file, sizeof(bak_file)); strncat(tmp_file, ".tmp", sizeof(tmp_file) - strlen(tmp_file) - 1); strncat(bak_file, ".bak", sizeof(bak_file) - strlen(bak_file) - 1); fclose(f); return safe_overwrite_with_bak(dst_file, tmp_file, bak_file, 0); }
/** * Opens the key store file: ~/.config/hexchat/addon_fishlim.conf */ static GKeyFile *getConfigFile() { gchar *filename = get_config_filename(); GKeyFile *keyfile = g_key_file_new(); g_key_file_load_from_file(keyfile, filename, G_KEY_FILE_KEEP_COMMENTS | G_KEY_FILE_KEEP_TRANSLATIONS, NULL); g_free(filename); return keyfile; }
static char *get_emmlog_filename(char *dest, size_t destlen, const char *basefilename, const char *ext) { char filename[64 + 16]; snprintf(filename, sizeof(filename), "%s_emm.%s", basefilename, ext); if (!cfg.emmlogdir) { get_config_filename(dest, destlen, filename); } else { const char *slash = "/"; if (cfg.emmlogdir[strlen(cfg.emmlogdir) - 1] == '/') slash = ""; snprintf(dest, destlen, "%s%s%s", cfg.emmlogdir, slash, filename); } return dest; }
gboolean _gtk_file_chooser_settings_save (GtkFileChooserSettings *settings, GError **error) { char *contents; char *filename; char *dirname; gboolean retval; g_return_val_if_fail (error == NULL || *error == NULL, FALSE); contents = settings_to_markup (settings); filename = get_config_filename (); dirname = NULL; retval = FALSE; if (!g_file_set_contents (filename, contents, -1, NULL)) { char *dirname; int saved_errno; /* Directory is not there? */ dirname = get_config_dirname (); if (g_mkdir_with_parents (dirname, 0700) != 0) /* 0700 per the XDG basedir spec */ { saved_errno = errno; g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (saved_errno), _("Could not create directory: %s"), dirname); goto out; } if (!g_file_set_contents (filename, contents, -1, error)) goto out; } retval = TRUE; out: g_free (contents); g_free (dirname); g_free (filename); return retval; }
static FILE *__open_config_file(const char *conf_filename, bool die_on_err) { char filename[256]; FILE *f = fopen(get_config_filename(filename, sizeof(filename), conf_filename), "r"); if (!f) { if (die_on_err) { fprintf(stderr, "ERROR: Cannot open file \"%s\" (errno=%d %s)", filename, errno, strerror(errno)); fprintf(stderr, "\n"); exit(1); } else { cs_log("ERROR: Cannot open file \"%s\" (errno=%d %s)", filename, errno, strerror(errno)); } return NULL; } return f; }
/** * Writes the key store file to disk. */ static bool save_keystore(GKeyFile *keyfile) { char *filename; bool ok; // Serialize gsize file_length; gchar *file_data = g_key_file_to_data(keyfile, &file_length, NULL); if (!file_data) return false; // Write to file filename = get_config_filename(); ok = g_file_set_contents(filename, file_data, file_length, NULL); g_free(filename); g_free(file_data); return ok; }
FILE *create_config_file(const char *conf_filename) { char temp_file[256]; get_config_filename(temp_file, sizeof(temp_file), conf_filename); strncat(temp_file, ".tmp", sizeof(temp_file) - strlen(temp_file) - 1); FILE *f = fopen(temp_file, "w"); if (!f) { cs_log("ERROR: Cannot create file \"%s\" (errno=%d %s)", temp_file, errno, strerror(errno)); return NULL; } setvbuf(f, NULL, _IOFBF, 16 * 1024); fprintf(f, "# %s generated automatically by Streamboard OSCAM %s SVN r%s\n", conf_filename, CS_VERSION, CS_SVN_VERSION); fprintf(f, "# Read more: http://www.streamboard.tv/svn/oscam/trunk/Distribution/doc/txt/%s.txt\n\n", conf_filename); return f; }
static void load_config(void) { gchar *filename = get_config_filename(); GKeyFile *kf = g_key_file_new(); if (g_key_file_load_from_file(kf, filename, G_KEY_FILE_NONE, NULL)) { vi_set_enabled(utils_get_setting_boolean(kf, CONF_GROUP, CONF_ENABLE_VIM, TRUE)); vi_set_insert_for_dummies(utils_get_setting_boolean(kf, CONF_GROUP, CONF_INSERT_FOR_DUMMIES, FALSE)); start_in_insert = utils_get_setting_boolean(kf, CONF_GROUP, CONF_START_IN_INSERT, FALSE); } g_key_file_free(kf); g_free(filename); }
static void save_config (void) { gchar *path; gchar *dirname; GError *err = NULL; path = get_config_filename (); dirname = g_path_get_dirname (path); utils_mkdir (dirname, TRUE); g_free (dirname); if (! gwh_settings_save_to_file (G_settings, path, &err)) { g_warning ("Failed to save configuration: %s", err->message); g_error_free (err); } g_free (path); g_object_unref (G_settings); G_settings = NULL; }
static void save_config(void) { GKeyFile *kf = g_key_file_new(); gchar *filename = get_config_filename(); gchar *dirname = g_path_get_dirname(filename); gchar *data; gsize length; g_key_file_set_boolean(kf, CONF_GROUP, CONF_ENABLE_VIM, vi_get_enabled()); g_key_file_set_boolean(kf, CONF_GROUP, CONF_INSERT_FOR_DUMMIES, vi_get_insert_for_dummies()); g_key_file_set_boolean(kf, CONF_GROUP, CONF_START_IN_INSERT, start_in_insert); utils_mkdir(dirname, TRUE); data = g_key_file_to_data(kf, &length, NULL); g_file_set_contents(filename, data, length, NULL); g_free(data); g_key_file_free(kf); g_free(filename); g_free(dirname); }
void dvbapi_save_channel_cache(void) { char fname[256]; get_config_filename(fname, sizeof(fname), "oscam.ccache"); FILE *file = fopen(fname, "w"); if(!file) { cs_log("dvbapi channelcache can't write to file %s", fname); return; } LL_ITER it = ll_iter_create(channel_cache); struct s_channel_cache *c; while((c = ll_iter_next(&it))) { fprintf(file, "%04X,%06X,%04X,%04X,%06X\n", c->caid, c->prid, c->srvid, c->pid, c->chid); } fclose(file); cs_log("dvbapi channelcache saved to %s", fname); }
static void load_config (void) { gchar *path; GError *err = NULL; G_settings = gwh_settings_get_default (); gwh_settings_install_property (G_settings, g_param_spec_boolean ( "browser-auto-reload", _("Browser auto reload"), _("Whether the browser reloads itself upon document saving"), TRUE, G_PARAM_READWRITE)); gwh_settings_install_property (G_settings, g_param_spec_string ( "browser-last-uri", _("Browser last URI"), _("Last URI visited by the browser"), "about:blank", G_PARAM_READWRITE)); gwh_settings_install_property (G_settings, g_param_spec_enum ( "browser-orientation", _("Browser orientation"), _("Orientation of the browser widget"), GTK_TYPE_ORIENTATION, GTK_ORIENTATION_VERTICAL, G_PARAM_READWRITE)); gwh_settings_install_property (G_settings, g_param_spec_enum ( "browser-position", _("Browser position"), _("Position of the browser widget in Geany's UI"), GWH_TYPE_BROWSER_POSITION, GWH_BROWSER_POSITION_MESSAGE_WINDOW, G_PARAM_READWRITE)); gwh_settings_install_property (G_settings, g_param_spec_string ( "browser-separate-window-geometry", _("Browser separate window geometry"), _("Last geometry of the separated browser's window"), "400x300", G_PARAM_READWRITE)); gwh_settings_install_property (G_settings, g_param_spec_string ( "inspector-window-geometry", _("Inspector window geometry"), _("Last geometry of the inspector window"), "400x300", G_PARAM_READWRITE)); gwh_settings_install_property (G_settings, g_param_spec_boolean ( "inspector-detached", _("Inspector detached"), _("Whether the inspector is in a separate window or docked in the browser"), FALSE, G_PARAM_READWRITE)); gwh_settings_install_property (G_settings, g_param_spec_boolean ( "wm-secondary-windows-skip-taskbar", _("Secondary windows skip task bar"), _("Whether to tell the window manager not to show the secondary windows in the task bar"), TRUE, G_PARAM_READWRITE)); gwh_settings_install_property (G_settings, g_param_spec_boolean ( "wm-secondary-windows-are-transient", _("Secondary windows are transient"), _("Whether secondary windows are transient children of their parent"), TRUE, G_PARAM_READWRITE)); gwh_settings_install_property (G_settings, g_param_spec_enum ( "wm-secondary-windows-type", _("Secondary windows type"), _("The type of the secondary windows"), GWH_TYPE_WINDOW_TYPE, GWH_WINDOW_TYPE_NORMAL, G_PARAM_READWRITE)); path = get_config_filename (); if (! gwh_settings_load_from_file (G_settings, path, &err)) { g_warning ("Failed to load configuration: %s", err->message); g_error_free (err); } g_free (path); }
void dvbapi_load_channel_cache(void) { if (USE_OPENXCAS) // Why? return; char fname[256]; char line[1024]; FILE *file; struct s_channel_cache *c; get_config_filename(fname, sizeof(fname), "oscam.ccache"); file = fopen(fname, "r"); if(!file) { cs_log("dvbapi channelcache can't read from file %s", fname); return; } int32_t i = 1; int32_t valid = 0; char *ptr, *saveptr1 = NULL; char *split[6]; memset(line, 0, sizeof(line)); while(fgets(line, sizeof(line), file)) { if(!line[0] || line[0] == '#' || line[0] == ';') { continue; } for(i = 0, ptr = strtok_r(line, ",", &saveptr1); ptr && i < 6 ; ptr = strtok_r(NULL, ",", &saveptr1), i++) { split[i] = ptr; } valid = (i == 5); if(valid) { if(!cs_malloc(&c, sizeof(struct s_channel_cache))) { continue; } c->caid = a2i(split[0], 4); c->prid = a2i(split[1], 6); c->srvid = a2i(split[2], 4); c->pid = a2i(split[3], 4); c->chid = a2i(split[4], 6); if(valid && c->caid != 0) { if(!channel_cache) { channel_cache = ll_create("channel cache"); } ll_append(channel_cache, c); } else { NULLFREE(c); } } } fclose(file); cs_log("dvbapi channelcache loaded from %s", fname); }
/* Actually load the configuration file. * You will almost certainly want to replace this with something better. */ static int load_config(void) { FILE *fd = NULL; char buffer[256]; char *extname = NULL; char *threadname = NULL; char *directive = NULL; char *check = NULL; int matches = 0; /* Belt and braces - if already loaded, don't re-load */ if( cfg_loaded ) return cfg_loaded; /* Find out where we load from */ char const *filename = get_config_filename(); if ( !filename ) return 0; LOG("Load Config from %s", filename); /* Try and open that file */ fd = fopen(filename, "r"); if( !fd ) { LOG_E("Opening file \"%s\" failed (error %d: %s)", filename, errno, strerror(errno)); return -errno; } /* Loop over the file */ while( !feof(fd) ) { check = fgets(buffer, 255, fd); /* Check nothing went wrong */ if( ferror(fd) || (!check && !feof(fd)) ) LOG_E("Reading file \"%s\" failed: %d %s", filename, errno, strerror(errno)); buffer[255] = '\0'; /* sscanf isn't particularly safe - a real application should use a better parser */ matches = sscanf(buffer, "%ms%ms%ms", &directive, &threadname, &extname); if( matches < 3 ) break; LOG("Read: %s %s %s", directive, threadname, extname); if( !strncasecmp("set", directive, 4) ) directive_set(threadname, atoi(extname)); else if( !strncasecmp("name", directive, 5) ) add_mapping(threadname, extname); else if( !strncasecmp("num", directive, 4) ) add_numeric(atoi(threadname), extname); else LOG_E("Invalid directive: %s", directive); free(directive); free(threadname); free(extname); } LOG("Load Complete"); fclose(fd); /* Debug print the loaded table */ dump_table(); return 1; }
// Alsa can convert about any format/channels/rate to any other rate // However, since we added some code in the daemon to convert, why not do it ourselves!!! // Moreover some player like aplay won't play a wav file if the device that do not natively support the requested format // If you want alsa to do the conversion, just remove the value you want to see converted static int a2dp_constraint(snd_pcm_a2dp_t * a2dp) { snd_pcm_ioplug_t *io = &a2dp->io; #define ARRAY_SIZE(x) (sizeof(x)/sizeof((x)[0])) snd_pcm_access_t access_list[] = { SND_PCM_ACCESS_RW_INTERLEAVED }; unsigned int formats[] = { SND_PCM_FORMAT_U8, SND_PCM_FORMAT_S8, SND_PCM_FORMAT_S16_LE }; unsigned int channels[] = { 1, 2 }; unsigned int rates[] = { 8000, 11025, 22050, 32000, 44100, 48000 }; int formats_nb = ARRAY_SIZE(formats); int channels_nb = ARRAY_SIZE(channels); int rates_nb = ARRAY_SIZE(rates); int rate_daemon = 0; int rate_prefered = 0; char srcfilename[512]; int err; get_config_filename(srcfilename, sizeof(srcfilename)); // Default is same as the daemon rate_daemon = read_config_int(srcfilename, "a2dpd", "rate", A2DPD_FRAME_RATE); // If a value is specified, use it rate_prefered = read_config_int(srcfilename, "a2dpd", "plugin-rate", rate_daemon); // If this value is not 0, alsa will convert to plugin-rate if(rate_prefered != 0) { // use defaults settings the rate specified + 16 bits stereo rates[0] = rate_prefered; rates_nb = 1; formats[0] = SND_PCM_FORMAT_S16_LE; formats_nb = 1; channels[0] = 2; channels_nb = 1; } else { // If this value is 0, the daemon will do most conversions } syslog(LOG_INFO, "[build %s %s] a2dp %p", __DATE__, __TIME__, a2dp); err = snd_pcm_ioplug_set_param_list(io, SND_PCM_IOPLUG_HW_ACCESS, ARRAY_SIZE(access_list), access_list); if (err < 0) return err; err = snd_pcm_ioplug_set_param_list(io, SND_PCM_IOPLUG_HW_FORMAT, formats_nb, formats); if (err < 0) return err; err = snd_pcm_ioplug_set_param_list(io, SND_PCM_IOPLUG_HW_CHANNELS, channels_nb, channels); if (err < 0) return err; err = snd_pcm_ioplug_set_param_list(io, SND_PCM_IOPLUG_HW_RATE, rates_nb, rates); if (err < 0) return err; err = snd_pcm_ioplug_set_param_minmax(io, SND_PCM_IOPLUG_HW_PERIOD_BYTES, 8192, 8192); if (err < 0) return err; err = snd_pcm_ioplug_set_param_minmax(io, SND_PCM_IOPLUG_HW_PERIODS, 2, 2); if (err < 0) return err; return 0; }
static void read_config_file(const char *name, const char **configs, int missingok) { FILE *f; char *line = NULL; size_t line_length = 0; int linenum = 0; char *realname; if (!strcmp(name, "-")) { f = stdin; realname = strdup("stdin"); } else { realname = get_config_filename(name, 0); f = fopen(realname, "r"); if (f == NULL && errno == ENOENT) { free(realname); realname = get_config_filename(name, 1); f = fopen(realname, "r"); } if (missingok && f == NULL && errno == ENOENT) { free(realname); return; } if (f == NULL) error(1, errno, "couldn't open `%s'", realname); } for (;;) { ssize_t llen; int i; llen = getline(&line, &line_length, f); if (llen == -1 && feof(f)) break; if (llen == -1) error(1, errno, "reading `%s'", realname); if (llen > 0 && line[llen - 1] == '\n') line[--llen] = 0; if (llen > 0 && line[llen - 1] == '\r') line[--llen] = 0; linenum++; for (i = 0; config_names[i].name != NULL; i++) { if (strncasecmp(config_names[i].name, line, strlen(config_names[i].name)) == 0) { /* boolean implementation, using harmless pointer targets as true */ if (!config_names[i].needsArgument) { configs[config_names[i].nm] = config_names[i].name; break; } if (configs[config_names[i].nm] == NULL) configs[config_names[i].nm] = strdup(line + strlen(config_names[i].name)); if (configs[config_names[i].nm] == NULL) error(1, errno, "can't allocate memory"); break; } } if (config_names[i].name == NULL && line[0] != '#' && line[0] != 0) error(0, 0, "warning: unknown configuration directive in %s at line %d", realname, linenum); } free(line); free(realname); if (strcmp(name, "-")) fclose(f); }
void do_emm_from_file(struct s_reader * reader) { if (!reader->emmfile) return; char token[256]; FILE *fp; if (reader->emmfile[0] == '/') snprintf(token, sizeof(token), "%s", reader->emmfile); //pathname included else get_config_filename(token, sizeof(token), reader->emmfile); //only file specified, look in confdir for this file if (!(fp = fopen (token, "rb"))) { rdr_log(reader, "ERROR: Cannot open EMM file '%s' (errno=%d %s)\n", token, errno, strerror(errno)); return; } EMM_PACKET *eptmp; if (!cs_malloc(&eptmp, sizeof(EMM_PACKET))) { fclose (fp); return; } size_t ret = fread(eptmp, sizeof(EMM_PACKET), 1, fp); if (ret < 1 && ferror(fp)) { rdr_log(reader, "ERROR: Can't read EMM from file '%s' (errno=%d %s)", token, errno, strerror(errno)); free(eptmp); fclose(fp); return; } fclose (fp); eptmp->caid[0] = (reader->caid >> 8) & 0xFF; eptmp->caid[1] = reader->caid & 0xFF; if (reader->nprov > 0) memcpy(eptmp->provid, reader->prid[0], sizeof(eptmp->provid)); eptmp->emmlen = eptmp->emm[2] + 3; struct s_cardsystem *cs = get_cardsystem_by_caid(reader->caid); if (cs && cs->get_emm_type && !cs->get_emm_type(eptmp, reader)) { rdr_debug_mask(reader, D_EMM, "emm skipped, get_emm_type() returns error"); free(eptmp); return; } //save old b_nano value //clear lsb and lsb+1, so no blocking, and no saving for this nano uint16_t save_s_nano = reader->s_nano; uint16_t save_b_nano = reader->b_nano; uint32_t save_saveemm = reader->saveemm; reader->s_nano = reader->b_nano = 0; reader->saveemm = 0; int32_t rc = cardreader_do_emm(reader, eptmp); if (rc == OK) rdr_log(reader, "EMM from file %s was successful written.", token); else rdr_log(reader, "ERROR: EMM read from file %s NOT processed correctly! (rc=%d)", token, rc); //restore old block/save settings reader->s_nano = save_s_nano; reader->b_nano = save_b_nano; reader->saveemm = save_saveemm; free(eptmp); }
/* Init necessary structures for SSL in WebIf*/ SSL_CTX *SSL_Webif_Init(void) { SSL_library_init(); SSL_load_error_strings(); ERR_load_BIO_strings(); ERR_load_SSL_strings(); SSL_CTX *ctx; static const char *cs_cert = "oscam.pem"; if(pthread_key_create(&getssl, NULL)) { cs_log("Could not create getssl"); } // set locking callbacks for SSL int32_t i, num = CRYPTO_num_locks(); lock_cs = (CS_MUTEX_LOCK *) OPENSSL_malloc(num * sizeof(CS_MUTEX_LOCK)); for(i = 0; i < num; ++i) { cs_lock_create(&lock_cs[i], "ssl_lock_cs", 10000); } /* static lock callbacks */ CRYPTO_set_id_callback(SSL_id_function); CRYPTO_set_locking_callback(SSL_locking_function); /* dynamic lock callbacks */ CRYPTO_set_dynlock_create_callback(SSL_dyn_create_function); CRYPTO_set_dynlock_lock_callback(SSL_dyn_lock_function); CRYPTO_set_dynlock_destroy_callback(SSL_dyn_destroy_function); if(cfg.http_force_sslv3) { ctx = SSL_CTX_new(SSLv3_server_method()); #ifdef SSL_CTX_clear_options SSL_CTX_clear_options(ctx, SSL_OP_ALL); //we CLEAR all bug workarounds! This is for security reason #else cs_log("WARNING: You enabled to force sslv3 but your system does not support to clear the ssl workarounds! SSL security will be reduced!"); #endif SSL_CTX_set_options(ctx, SSL_OP_NO_SSLv2); // we force SSL v3 ! SSL_CTX_set_cipher_list(ctx, SSL_TXT_RC4); } else { ctx = SSL_CTX_new(SSLv23_server_method()); } char path[128]; if(!cfg.http_cert) { get_config_filename(path, sizeof(path), cs_cert); } else { cs_strncpy(path, cfg.http_cert, sizeof(path)); } if(!ctx) { ERR_print_errors_fp(stderr); return NULL; } if(SSL_CTX_use_certificate_file(ctx, path, SSL_FILETYPE_PEM) <= 0) { ERR_print_errors_fp(stderr); return NULL; } if(SSL_CTX_use_PrivateKey_file(ctx, path, SSL_FILETYPE_PEM) <= 0) { ERR_print_errors_fp(stderr); return NULL; } if(!SSL_CTX_check_private_key(ctx)) { cs_log("SSL: Private key does not match the certificate public key"); return NULL; } cs_log("load ssl certificate file %s", path); return ctx; }