/* * Function to create basic config for bluetooth setup. Config is assigned to gn_cfg_info structure. * @model: model to be set * @connection: connection to be set * @port: port to be set */ GNOKII_API struct gn_cfg_header *gn_cfg_bluetooth_create(char *model, char *btmac, char *rfchannel) { struct gn_cfg_header *hdr, *config; if (!model | !btmac | !rfchannel) { dprintf("Neither model nor Bluetooth mac address nor rfcomm channel can be NULL.\n"); return NULL; } config = gn_cfg_section_create(NULL, model, "bluetooth", btmac); if (!config) return NULL; hdr = gn_cfg_variable_set(config, "global", "rfcomm_channel", rfchannel, 1); if (!hdr) { dprintf("Failed to create config.\n"); free(config); return NULL; } /* Dump config */ cfg_dump(config); /* Assign to gn_cfg_info. libgnokii needs it so far. */ gn_cfg_info = config; return config; }
int main(int argc, char **argv) { Cfg *cfg; int ret = 1; Octstr *name; int i; gwlib_init(); for (i = 1; i < argc; ++i) { name = octstr_create(argv[i]); cfg = cfg_create(name); octstr_destroy(name); ret = cfg_read(cfg); info(0, "cfg_read returned %d", ret); if (ret == 0) cfg_dump(cfg); cfg_destroy(cfg); } info(0, "Shutting down."); gwlib_shutdown(); return ret; }
int main(void) { int nr = 1, cnt = 0; float tmin = 0.5f, tmax = 1.0f; char *p = NULL; cfg_t *cfg; if ((cfg = cfg_open("foo.cfg")) == NULL) { printf("error reading\n"); return 1; } cfg_add(cfg, "nrtemp", "%d", &nr, "# of T."); cfg_add(cfg, "tmin", "%f", &tmin, "T min"); cfg_add(cfg, "tmax", "%f", &tmax, "T max"); cfg_add(cfg, "mystr", "%s", &p, "some string"); cfg_add(cfg, "arrcnt", "%d", &cnt, "array count"); cfg_match(cfg, CFG_CHECKUSE); cfg_dump(cfg); printf("nr=%d, (%g,%g), cnt=%d\n", nr, tmin, tmax, cnt); printf("mystr=\"%s\"\n", p); cfg_close(cfg); ssdelall(); return 0; }
int main(int argc, char *argv[]) { int opt; int daemonize = FALSE; int verbose_level = 2; char *configfile = DEFAULT_CONFIG_FILE; while((opt = getopt(argc, argv, "c:bd:")) != -1) { switch(opt) { case 'c': configfile = optarg; break; case 'b': daemonize = TRUE; break; case 'd': verbose_level = atoi(optarg); break; default: usage(argv[0]); exit(EXIT_FAILURE); break; } } debug_level(verbose_level); DEBUG("Loading config from %s", configfile); if(cfg_load(configfile) == -1) { ERROR("Error loading config. Aborting"); return EXIT_FAILURE; } cfg_dump(); DEBUG("Starting mqtt workers"); mqtt_init(); DEBUG("Starting receive thread"); if(!nrf24_recv_init()) { ERROR("Error starting radio receiver. Abort"); exit(EXIT_FAILURE); } while(1) { sleep(1); } nrf24_recv_deinit(); mqtt_deinit(); return(EXIT_SUCCESS); }
/* * Function to create generic config. Config is assigned to gn_cfg_info structure. * @model: model to be set * @connection: connection to be set * @port: port to be set */ GNOKII_API struct gn_cfg_header *gn_cfg_generic_create(char *model, char *connection, char *port) { struct gn_cfg_header *config; config = gn_cfg_section_create(NULL, model, connection, port); if (!config) return NULL; /* Dump config */ cfg_dump(config); /* Assign to gn_cfg_info. libgnokii needs it so far. */ gn_cfg_info = config; return config; }
static void read_test_ppg_config(Octstr *name) { Cfg *cfg; CfgGroup *grp; cfg = cfg_create(name); if (cfg_read(cfg) == -1) panic(0, "Cannot read a configuration file %s, exiting", octstr_get_cstr(name)); cfg_dump(cfg); grp = cfg_get_single_group(cfg, octstr_imm("test-ppg")); cfg_get_integer(&retries, grp, octstr_imm("retries")); cfg_get_bool(&pi_ssl, grp, octstr_imm("pi-ssl")); #ifdef HAVE_LIBSSL if (pi_ssl) { ssl_client_certkey_file = cfg_get(grp, octstr_imm("ssl-client-certkey-file")); if (ssl_client_certkey_file != NULL) { use_global_client_certkey_file(ssl_client_certkey_file); } else { error(0, "cannot set up SSL without client certkey file"); exit(1); } } #endif grp = cfg_get_single_group(cfg, octstr_imm("configuration")); push_url = cfg_get(grp, octstr_imm("push-url")); pap_file = cfg_get(grp, octstr_imm("pap-file")); content_file = cfg_get(grp, octstr_imm("content-file")); if (!use_hardcoded) { username = cfg_get(grp, octstr_imm("username")); password = cfg_get(grp, octstr_imm("password")); } cfg_destroy(cfg); }
int main(int argc, char **argv) { group_t *head; FILE *fp; int i; if (argc < 2) { fprintf(stderr, "Usage: %s <cfgfile>...\n", argv[0]); exit(EXIT_FAILURE); } for (i=1; i < argc; i++) { fp = fopen(argv[i], "r"); if (!fp) { fprintf(stderr, "error: unable to open file %s!\n", argv[1]); continue; } fprintf(stderr, "Parsing file %s...\n", argv[i]); head = cfg_load(fp); cfg_dump(head); cfg_free(head); } exit(EXIT_SUCCESS); }
int apt_dump_cfg() { cfg_dump(); }
static Cfg *init_wapbox(Cfg *cfg) { CfgGroup *grp; Octstr *s; Octstr *logfile; int lf, m; long value; lf = m = 1; cfg_dump(cfg); /* * Extract info from the core group. */ grp = cfg_get_single_group(cfg, octstr_imm("core")); if (grp == NULL) panic(0, "No 'core' group in configuration."); if (cfg_get_integer(&bearerbox_port,grp,octstr_imm("wapbox-port")) == -1) panic(0, "No 'wapbox-port' in core group"); #ifdef HAVE_LIBSSL cfg_get_bool(&bearerbox_ssl, grp, octstr_imm("wapbox-port-ssl")); #endif /* HAVE_LIBSSL */ /* load parameters that could be later reloaded */ config_reload(0); conn_config_ssl(grp); /* * And the rest of the pull info comes from the wapbox group. */ grp = cfg_get_single_group(cfg, octstr_imm("wapbox")); if (grp == NULL) panic(0, "No 'wapbox' group in configuration."); bearerbox_host = cfg_get(grp, octstr_imm("bearerbox-host")); if (cfg_get_integer(&timer_freq, grp, octstr_imm("timer-freq")) == -1) timer_freq = DEFAULT_TIMER_FREQ; logfile = cfg_get(grp, octstr_imm("log-file")); if (logfile != NULL) { log_open(octstr_get_cstr(logfile), logfilelevel, GW_NON_EXCL); info(0, "Starting to log to file %s level %ld", octstr_get_cstr(logfile), logfilelevel); } octstr_destroy(logfile); if ((s = cfg_get(grp, octstr_imm("syslog-level"))) != NULL) { long level; Octstr *facility; if ((facility = cfg_get(grp, octstr_imm("syslog-facility"))) != NULL) { log_set_syslog_facility(octstr_get_cstr(facility)); octstr_destroy(facility); } if (octstr_compare(s, octstr_imm("none")) == 0) { log_set_syslog(NULL, 0); debug("wap", 0, "syslog parameter is none"); } else if (octstr_parse_long(&level, s, 0, 10) > 0) { log_set_syslog("wapbox", level); debug("wap", 0, "syslog parameter is %ld", level); } octstr_destroy(s); } else { log_set_syslog(NULL, 0); debug("wap", 0, "no syslog parameter"); } /* determine which timezone we use for access logging */ if ((s = cfg_get(grp, octstr_imm("access-log-time"))) != NULL) { lf = (octstr_case_compare(s, octstr_imm("gmt")) == 0) ? 0 : 1; octstr_destroy(s); } /* should predefined markers be used, ie. prefixing timestamp */ cfg_get_bool(&m, grp, octstr_imm("access-log-clean")); /* open access-log file */ if ((s = cfg_get(grp, octstr_imm("access-log"))) != NULL) { info(0, "Logging accesses to '%s'.", octstr_get_cstr(s)); alog_open(octstr_get_cstr(s), lf, m ? 0 : 1); octstr_destroy(s); } if (cfg_get_integer(&value, grp, octstr_imm("http-timeout")) == 0) http_set_client_timeout(value); /* configure the 'wtls' group */ #if (HAVE_WTLS_OPENSSL) /* Load up the necessary keys */ grp = cfg_get_single_group(cfg, octstr_imm("wtls")); if (grp != NULL) { if ((s = cfg_get(grp, octstr_imm("certificate-file"))) != NULL) { if (octstr_compare(s, octstr_imm("none")) == 0) { debug("bbox", 0, "certificate file not set"); } else { /* Load the certificate into the necessary parameter */ get_cert_from_file(s, &x509_cert); gw_assert(x509_cert != NULL); debug("bbox", 0, "certificate parameter is %s", octstr_get_cstr(s)); } octstr_destroy(s); } else panic(0, "No 'certificate-file' in wtls group"); if ((s = cfg_get(grp, octstr_imm("privatekey-file"))) != NULL) { Octstr *password; password = cfg_get(grp, octstr_imm("privatekey-password")); if (octstr_compare(s, octstr_imm("none")) == 0) { debug("bbox", 0, "privatekey-file not set"); } else { /* Load the private key into the necessary parameter */ get_privkey_from_file(s, &private_key, password); gw_assert(private_key != NULL); debug("bbox", 0, "certificate parameter is %s", octstr_get_cstr(s)); } if (password != NULL) octstr_destroy(password); octstr_destroy(s); } else panic(0, "No 'privatekey-file' in wtls group"); } #endif /* * Check if we have a 'radius-acct' proxy group and start the * corresponding thread for the proxy. */ grp = cfg_get_single_group(cfg, octstr_imm("radius-acct")); if (grp) { radius_acct_init(grp); } /* * We pass ppg configuration groups to the ppg module. */ grp = cfg_get_single_group(cfg, octstr_imm("ppg")); if (grp == NULL) { cfg_destroy(cfg); return NULL; } return cfg; }
void cfg_dump(cfg_t cfg, write_stream_t stream, int ident, int level_ident) { struct cfg_it it; cfg_t child; int c; if(cfg == 0) return; switch(cfg->m_type) { case CPE_CFG_TYPE_SEQUENCE: { stream_putc(stream, '['); c = 0; cfg_it_init(&it, cfg); if ((child = cfg_it_next(&it))) { stream_putc(stream, ' '); cfg_dump(child, stream, ident + level_ident, level_ident); ++c; } while((child = cfg_it_next(&it))) { stream_putc(stream, '\n'); stream_putc_count(stream, ' ', ident); stream_putc(stream, ','); stream_putc(stream, ' '); cfg_dump(child, stream, ident + level_ident, level_ident); ++c; } if (c == 1) { stream_putc(stream, ' '); } else if (c > 1) { stream_putc(stream, '\n'); stream_putc_count(stream, ' ', ident); } stream_putc(stream, ']'); break; } case CPE_CFG_TYPE_STRUCT: { stream_putc(stream, '{'); c = 0; cfg_it_init(&it, cfg); if ((child = cfg_it_next(&it))) { stream_printf(stream, " %s=", cfg_name(child)); cfg_dump(child, stream, ident + level_ident, level_ident); ++c; } while((child = cfg_it_next(&it))) { stream_putc(stream, '\n'); stream_putc_count(stream, ' ', ident); stream_printf(stream, ", %s=", cfg_name(child)); cfg_dump(child, stream, ident + level_ident, level_ident); ++c; } if (c == 1) { stream_putc(stream, ' '); } else if (c > 1) { stream_putc(stream, '\n'); stream_putc_count(stream, ' ', ident); } stream_putc(stream, '}'); break; } default: dr_ctype_print_to_stream(stream, cfg_data(cfg), cfg->m_type, 0); break; } }