static void add_filter_restrictions(filter *f, cfg_t *sec) { for (int i = 0; i < NUM_FILTER_OPTIONS; ++i) { filter_option *opt = &filter_options[i]; if (cfg_size(sec, opt->config_name)) { switch (opt->type) { case FILTER_OPTION_TYPE_BOOL: { int value = cfg_getbool(sec, opt->config_name) == cfg_true ? 1 : 0; filter_add_restriction_bool(f, opt->data.property_name, value); break; } case FILTER_OPTION_TYPE_STRING: { const char *value = cfg_getstr(sec, opt->config_name); filter_add_restriction_string(f, opt->data.property_name, value); break; } case FILTER_OPTION_TYPE_CUSTOM: { intptr_t value = cfg_getbool(sec, opt->config_name) == cfg_true ? 1 : 0; filter_add_restriction_custom(f, opt->data.custom.match_func, opt->data.custom.free_func, opt->data.custom.cookie, value); break; } default: assert(0); break; } } } }
int main(int argc, char **argv) { int i; cfg_t *cfg = parse_conf(argc > 1 ? argv[1] : "ftp.conf"); /* print the parsed configuration options */ if(cfg) { printf("reverse-dns = %s\n", cfg_getbool(cfg, "reverse-dns") ? "true" : "false"); printf("passive-mode = %s\n", cfg_getbool(cfg, "passive-mode") ? "true" : "false"); printf("remote-completion = %s\n", cfg_getbool(cfg, "remote-completion") ? "true" : "false"); printf("number of bookmarks: %d\n", cfg_size(cfg, "bookmark")); for(i = 0; i < cfg_size(cfg, "bookmark"); i++) { cfg_t *bookmark = cfg_getnsec(cfg, "bookmark", i); printf(" bookmark #%d: %s:%s@%s:%ld%s\n", i+1, cfg_getstr(bookmark, "login"), cfg_getstr(bookmark, "password"), cfg_getstr(bookmark, "host"), cfg_getint(bookmark, "port"), cfg_getstr(bookmark, "directory")); } for(i = 0; i < cfg_size(cfg, "xterm-terminals"); i++) printf("xterm-terminal #%d: %s\n", i+1, cfg_getnstr(cfg, "xterm-terminals", i)); printf("auto-create-bookmark = %ld\n", cfg_getint(cfg, "auto-create-bookmark")); cfg_free(cfg); } return 0; }
static cfg_t* find_module_config(char *modname) { cfg_t *modules_cfg; int j; modules_cfg = cfg_getsec(python_module.config_file, "modules"); for (j = 0; j < cfg_size(modules_cfg, "module"); j++) { char *modName, *modLanguage; int modEnabled; cfg_t *pymodule = cfg_getnsec(modules_cfg, "module", j); /* Check the module language to make sure that the language designation is python. */ modLanguage = cfg_getstr(pymodule, "language"); if (!modLanguage || strcasecmp(modLanguage, "python")) continue; modName = cfg_getstr(pymodule, "name"); if (strcasecmp(modname, modName)) { continue; } /* Check to make sure that the module is enabled. */ modEnabled = cfg_getbool(pymodule, "enabled"); if (!modEnabled) continue; return pymodule; } return NULL; }
static int ignore_pl(plist_t pl, const char *name) { uint64_t kind; int smart; uint8_t master; uint8_t party; kind = 0; smart = 0; master = 0; party = 0; /* Special (builtin) playlists */ get_dictval_int_from_key(pl, "Distinguished Kind", &kind); /* Import smart playlists (optional) */ if (!cfg_getbool(cfg_getsec(cfg, "library"), "itunes_smartpl") && (plist_dict_get_item(pl, "Smart Info") || plist_dict_get_item(pl, "Smart Criteria"))) smart = 1; /* Not interested in the Master playlist */ get_dictval_bool_from_key(pl, "Master", &master); /* Not interested in Party Shuffle playlists */ get_dictval_bool_from_key(pl, "Party Shuffle", &party); if ((kind > 0) || smart || party || master) { DPRINTF(E_INFO, L_SCAN, "Ignoring playlist '%s' (k %" PRIu64 " s%d p%d m%d)\n", name, kind, smart, party, master); return 1; } return 0; }
/** * @brief parses a downstream {} config entry from a server { } config. * * @param cfg * * @return */ downstream_cfg_t * downstream_cfg_parse(cfg_t * cfg) { downstream_cfg_t * dscfg; assert(cfg != NULL); dscfg = downstream_cfg_new(); assert(dscfg != NULL); dscfg->name = strdup(cfg_title(cfg)); dscfg->enabled = cfg_getbool(cfg, "enabled"); dscfg->host = strdup(cfg_getstr(cfg, "addr")); dscfg->port = cfg_getint(cfg, "port"); dscfg->n_connections = cfg_getint(cfg, "connections"); dscfg->high_watermark = cfg_getint(cfg, "high-watermark"); dscfg->read_timeout.tv_sec = cfg_getnint(cfg, "read-timeout", 0); dscfg->read_timeout.tv_usec = cfg_getnint(cfg, "read-timeout", 1); dscfg->write_timeout.tv_sec = cfg_getnint(cfg, "write-timeout", 0); dscfg->write_timeout.tv_usec = cfg_getnint(cfg, "write-timeout", 1); dscfg->retry_ival.tv_sec = cfg_getnint(cfg, "retry", 0); dscfg->retry_ival.tv_usec = cfg_getnint(cfg, "retry", 1); if (dscfg->enabled == true) { _rusage.total_num_connections += dscfg->n_connections; } return dscfg; }
/* * Returns the correct color format for dzen (^fg(color)), xmobar (<fc=color>) * or lemonbar (%{Fcolor}) * */ char *color(const char *colorstr) { static char colorbuf[32]; if (!cfg_getbool(cfg_general, "colors")) { colorbuf[0] = '\0'; return colorbuf; } if (output_format == O_DZEN2) (void)snprintf(colorbuf, sizeof(colorbuf), "^fg(%s)", cfg_getstr(cfg_general, colorstr)); else if (output_format == O_XMOBAR) (void)snprintf(colorbuf, sizeof(colorbuf), "<fc=%s>", cfg_getstr(cfg_general, colorstr)); else if (output_format == O_LEMONBAR) (void)snprintf(colorbuf, sizeof(colorbuf), "%%{F%s}", cfg_getstr(cfg_general, colorstr)); else if (output_format == O_TERM) { /* The escape-sequence for color is <CSI><col>;1m (bright/bold * output), where col is a 3-bit rgb-value with b in the * least-significant bit. We round the given color to the * nearist 3-bit-depth color and output the escape-sequence */ char *str = cfg_getstr(cfg_general, colorstr); int col = strtol(str + 1, NULL, 16); int r = (col & (0xFF << 0)) / 0x80; int g = (col & (0xFF << 8)) / 0x8000; int b = (col & (0xFF << 16)) / 0x800000; col = (r << 2) | (g << 1) | b; (void)snprintf(colorbuf, sizeof(colorbuf), "\033[3%d;1m", col); } return colorbuf; }
gboolean config_getbool(const gchar *key) { gboolean temp; config_mutex_lock (); temp = cfg_getbool (tc, key); config_mutex_unlock (); return temp; }
static void initscan() { time_t starttime; time_t endtime; bool clear_queue_disabled; int i; scanning = true; starttime = time(NULL); listener_notify(LISTENER_UPDATE); // Only clear the queue if enabled (default) in config clear_queue_disabled = cfg_getbool(cfg_getsec(cfg, "mpd"), "clear_queue_on_stop_disable"); if (!clear_queue_disabled) { db_queue_clear(0); } for (i = 0; sources[i]; i++) { if (!sources[i]->disabled && sources[i]->initscan) sources[i]->initscan(); } if (! (cfg_getbool(cfg_getsec(cfg, "library"), "filescan_disable"))) { purge_cruft(starttime); DPRINTF(E_DBG, L_LIB, "Running post library scan jobs\n"); db_hook_post_scan(); } endtime = time(NULL); DPRINTF(E_LOG, L_LIB, "Library init scan completed in %.f sec (%d changes)\n", difftime(endtime, starttime), deferred_update_notifications); scanning = false; if (handle_deferred_update_notifications()) listener_notify(LISTENER_UPDATE | LISTENER_DATABASE); else listener_notify(LISTENER_UPDATE); }
static void netlink_use_bit(struct attr_map *map, const int size) { if(cfg_getbool(cfg, "use_bit")) { for(int i = 0; i < size; ++i) { if(!strcmp(map[i].description, "Bytes")) { map[i].description = "Bits"; } } } }
static void parse_elp_list(cfg_t *cfg, shash_t *ht) { elp_node_t *enode; elp_t *elp; lisp_addr_t *laddr; char *name; int i, j; for(i = 0; i < cfg_size(cfg, "explicit-locator-path"); i++) { cfg_t *selp = cfg_getnsec(cfg, "explicit-locator-path", i); name = cfg_getstr(selp, "elp-name"); elp = elp_type_new(); for (j = 0; j < cfg_size(selp, "elp-node");j++) { cfg_t *senode = cfg_getnsec(selp, "elp-node", j); enode = xzalloc(sizeof(elp_node_t)); enode->addr = lisp_addr_new(); if (lisp_addr_ip_from_char(cfg_getstr(senode, "address"), enode->addr) != GOOD) { elp_node_del(enode); OOR_LOG(LDBG_1, "parse_elp_list: Couldn't parse ELP node %s", cfg_getstr(senode, "address")); continue; } enode->L = cfg_getbool(senode, "lookup") ? 1 : 0; enode->P = cfg_getbool(senode, "probe") ? 1 : 0; enode->S = cfg_getbool(senode, "strict") ? 1: 0; glist_add_tail(enode, elp->nodes); } laddr = lisp_addr_new_lafi(LM_AFI_LCAF); lisp_addr_lcaf_set_type(laddr, LCAF_EXPL_LOC_PATH); lisp_addr_lcaf_set_addr(laddr, elp); OOR_LOG(LDBG_1, "Configuration file: parsed explicit-locator-path: %s", lisp_addr_to_char(laddr)); shash_insert(ht, strdup(name), laddr); } }
void conf_init(void) { cfg_read_interval = cfg_getfloat(cfg, "read_interval"); cfg_rate_interval = cfg_getfloat(cfg, "rate_interval"); cfg_rate_variance = cfg_getfloat(cfg, "variance") * cfg_rate_interval; cfg_history_variance = cfg_getfloat(cfg, "history_variance"); cfg_show_all = cfg_getbool(cfg, "show_all"); cfg_unit_exp = cfg_getint(cfg, "unit_exp"); element_parse_policy(cfg_getstr(cfg, "policy")); }
/* * Returns the correct color format for dzen (^fg(color)) or xmobar (<fc=color>) * */ char *color(const char *colorstr) { static char colorbuf[32]; if (!cfg_getbool(cfg_general, "colors")) { colorbuf[0] = '\0'; return colorbuf; } if (output_format == O_DZEN2) (void)snprintf(colorbuf, sizeof(colorbuf), "^fg(%s)", cfg_getstr(cfg_general, colorstr)); else if (output_format == O_XMOBAR) (void)snprintf(colorbuf, sizeof(colorbuf), "<fc=%s>", cfg_getstr(cfg_general, colorstr)); return colorbuf; }
static void configfile_read_attrs(void) { int i, nattrs, t; nattrs = cfg_size(cfg, "attr"); for (i = 0; i < nattrs; i++) { struct unit *u; cfg_t *attr; const char *name, *description, *unit, *type; int flags = 0; if (!(attr = cfg_getnsec(cfg, "attr", i))) BUG(); if (!(name = cfg_title(attr))) BUG(); description = cfg_getstr(attr, "description"); unit = cfg_getstr(attr, "unit"); type = cfg_getstr(attr, "type"); if (!unit) quit("Attribute '%s' is missing unit specification\n", name); if (!type) quit("Attribute '%s' is missing type specification\n", name); if (!(u = unit_lookup(unit))) quit("Unknown unit \'%s\' attribute '%s'\n", unit, name); if (!strcasecmp(type, "counter")) t = ATTR_TYPE_COUNTER; else if (!strcasecmp(type, "rate")) t = ATTR_TYPE_RATE; else if (!strcasecmp(type, "percent")) t = ATTR_TYPE_PERCENT; else quit("Unknown type \'%s\' in attribute '%s'\n", type, name); if (cfg_getbool(attr, "history")) flags |= ATTR_DEF_FLAG_HISTORY; attr_def_add(name, description, u, t, flags); } }
/** * @brief parses header addition config from server vhost { { rules { rule { headers { } } } } } * * @param cfg * * @return */ headers_cfg_t * headers_cfg_parse(cfg_t * cfg) { headers_cfg_t * hcfg; int n_x509_exts; int i; if (cfg == NULL) { return NULL; } hcfg = headers_cfg_new(); assert(hcfg != NULL); hcfg->x_forwarded_for = cfg_getbool(cfg, "x-forwarded-for"); hcfg->x_ssl_subject = cfg_getbool(cfg, "x-ssl-subject"); hcfg->x_ssl_issuer = cfg_getbool(cfg, "x-ssl-issuer"); hcfg->x_ssl_notbefore = cfg_getbool(cfg, "x-ssl-notbefore"); hcfg->x_ssl_notafter = cfg_getbool(cfg, "x-ssl-notafter"); hcfg->x_ssl_sha1 = cfg_getbool(cfg, "x-ssl-sha1"); hcfg->x_ssl_serial = cfg_getbool(cfg, "x-ssl-serial"); hcfg->x_ssl_cipher = cfg_getbool(cfg, "x-ssl-cipher"); hcfg->x_ssl_certificate = cfg_getbool(cfg, "x-ssl-certificate"); n_x509_exts = cfg_size(cfg, "x509-extension"); for (i = 0; i < n_x509_exts; i++) { x509_ext_cfg_t * x509cfg; lztq_elem * elem; x509cfg = x509_ext_cfg_parse(cfg_getnsec(cfg, "x509-extension", i)); assert(x509cfg != NULL); elem = lztq_append(hcfg->x509_exts, x509cfg, sizeof(x509cfg), x509_ext_cfg_free); assert(elem != NULL); } return hcfg; }
int parse_map_servers(cfg_t *cfg, lisp_xtr_t *xtr) { int n,i; /* MAP-SERVER CONFIG */ n = cfg_size(cfg, "map-server"); for (i = 0; i < n; i++) { cfg_t *ms = cfg_getnsec(cfg, "map-server", i); if (add_map_server(xtr->map_servers, cfg_getstr(ms, "address"), cfg_getint(ms, "key-type"), cfg_getstr(ms, "key"), (cfg_getbool(ms, "proxy-reply") ? 1 : 0)) == GOOD) { OOR_LOG(LDBG_1, "Added %s to map-server list", cfg_getstr(ms, "address")); } else { OOR_LOG(LWRN, "Can't add %s Map Server.", cfg_getstr(ms, "address")); } } return (GOOD); }
static rproxy_cfg_t * rproxy_cfg_parse_(cfg_t * cfg) { rproxy_cfg_t * rpcfg; int i; assert(cfg != NULL); rpcfg = rproxy_cfg_new(); assert(rpcfg != NULL); if (cfg_getstr(cfg, "user")) { rpcfg->user = strdup(cfg_getstr(cfg, "user")); } if (cfg_getstr(cfg, "group")) { rpcfg->group = strdup(cfg_getstr(cfg, "group")); } if (cfg_getstr(cfg, "rootdir")) { rpcfg->rootdir = strdup(cfg_getstr(cfg, "rootdir")); } rpcfg->max_nofile = cfg_getint(cfg, "max-nofile"); rpcfg->daemonize = cfg_getbool(cfg, "daemonize"); for (i = 0; i < cfg_size(cfg, "server"); i++) { lztq_elem * elem; server_cfg_t * scfg; scfg = server_cfg_parse(cfg_getnsec(cfg, "server", i)); assert(scfg != NULL); scfg->rproxy_cfg = rpcfg; elem = lztq_append(rpcfg->servers, scfg, sizeof(scfg), server_cfg_free); assert(elem != NULL); } /* set our rusage settings from the global one */ memcpy(&rpcfg->rusage, &_rusage, sizeof(rproxy_rusage_t)); return rpcfg; } /* rproxy_cfg_parse_ */
int ListenTCP(uint16_t port) { /* Socket erstellen - TCP, IPv4, keine Optionen */ int lsd = socket(AF_INET, SOCK_STREAM, 0); /* IPv4, Port: 1111, jede IP-Adresse akzeptieren */ struct sockaddr_in saddr; saddr.sin_family = AF_INET; saddr.sin_port = htons(port); if (cfg_getbool(cfg, "tcpbindlocal")) { syslog(LOG_NOTICE, "Binding to localhost.\n"); saddr.sin_addr.s_addr = htonl(INADDR_LOOPBACK); } else { syslog(LOG_NOTICE, "Binding to any interface.\n"); saddr.sin_addr.s_addr = htonl(INADDR_ANY); } //Important! Makes sure you can restart the daemon without any problems! const int optVal = 1; const socklen_t optLen = sizeof(optVal); int rtn = setsockopt(lsd, SOL_SOCKET, SO_REUSEADDR, (void*) &optVal, optLen); //assert(rtn == 0); /* this is optional */ /* Socket an Port binden */ if (bind(lsd, (struct sockaddr*) &saddr, sizeof(saddr)) < 0) { //whoops. Could not listen syslog(LOG_ERR, "Could not bind to TCP port! Terminated.\n"); exit(EXIT_FAILURE); } syslog(LOG_NOTICE, "Successfully started daemon\n"); /* Auf Socket horchen (Listen) */ listen(lsd, 10); return lsd; }
static void configfile_read_element_cfg(void) { int i, nelement; nelement = cfg_size(cfg, "element"); for (i = 0; i < nelement; i++) { struct element_cfg *ec; cfg_t *element; const char *name, *description; long max; if (!(element = cfg_getnsec(cfg, "element", i))) BUG(); if (!(name = cfg_title(element))) BUG(); ec = element_cfg_alloc(name); if ((description = cfg_getstr(element, "description"))) ec->ec_description = strdup(description); if ((max = cfg_getint(element, "max"))) ec->ec_rxmax = ec->ec_txmax = max; if ((max = cfg_getint(element, "rxmax"))) ec->ec_rxmax = max; if ((max = cfg_getint(element, "txmax"))) ec->ec_txmax = max; if (cfg_getbool(element, "show")) ec->ec_flags |= ELEMENT_CFG_SHOW; else ec->ec_flags |= ELEMENT_CFG_HIDE; } }
/* Thread: main */ int httpd_init(void) { int v6enabled; unsigned short port; int ret; httpd_exit = 0; evbase_httpd = event_base_new(); if (!evbase_httpd) { DPRINTF(E_FATAL, L_HTTPD, "Could not create an event base\n"); return -1; } ret = rsp_init(); if (ret < 0) { DPRINTF(E_FATAL, L_HTTPD, "RSP protocol init failed\n"); goto rsp_fail; } ret = daap_init(); if (ret < 0) { DPRINTF(E_FATAL, L_HTTPD, "DAAP protocol init failed\n"); goto daap_fail; } ret = dacp_init(); if (ret < 0) { DPRINTF(E_FATAL, L_HTTPD, "DACP protocol init failed\n"); goto dacp_fail; } streaming_init(); #ifdef USE_EVENTFD exit_efd = eventfd(0, EFD_CLOEXEC); if (exit_efd < 0) { DPRINTF(E_FATAL, L_HTTPD, "Could not create eventfd: %s\n", strerror(errno)); goto pipe_fail; } exitev = event_new(evbase_httpd, exit_efd, EV_READ, exit_cb, NULL); #else ret = pipe2(exit_pipe, O_CLOEXEC); if (ret < 0) { DPRINTF(E_FATAL, L_HTTPD, "Could not create pipe: %s\n", strerror(errno)); goto pipe_fail; } exitev = event_new(evbase_httpd, exit_pipe[0], EV_READ, exit_cb, NULL); #endif /* USE_EVENTFD */ if (!exitev) { DPRINTF(E_FATAL, L_HTTPD, "Could not create exit event\n"); goto event_fail; } event_add(exitev, NULL); evhttpd = evhttp_new(evbase_httpd); if (!evhttpd) { DPRINTF(E_FATAL, L_HTTPD, "Could not create HTTP server\n"); goto event_fail; } v6enabled = cfg_getbool(cfg_getsec(cfg, "general"), "ipv6"); port = cfg_getint(cfg_getsec(cfg, "library"), "port"); if (v6enabled) { ret = evhttp_bind_socket(evhttpd, "::", port); if (ret < 0) { DPRINTF(E_LOG, L_HTTPD, "Could not bind to port %d, falling back to IPv4\n", port); v6enabled = 0; } } if (!v6enabled) { ret = evhttp_bind_socket(evhttpd, "0.0.0.0", port); if (ret < 0) { DPRINTF(E_FATAL, L_HTTPD, "Could not bind to port %d (forked-daapd already running?)\n", port); goto bind_fail; } } evhttp_set_gencb(evhttpd, httpd_gen_cb, NULL); ret = pthread_create(&tid_httpd, NULL, httpd, NULL); if (ret != 0) { DPRINTF(E_FATAL, L_HTTPD, "Could not spawn HTTPd thread: %s\n", strerror(errno)); goto thread_fail; } return 0; thread_fail: bind_fail: evhttp_free(evhttpd); event_fail: #ifdef USE_EVENTFD close(exit_efd); #else close(exit_pipe[0]); close(exit_pipe[1]); #endif pipe_fail: streaming_deinit(); dacp_deinit(); dacp_fail: daap_deinit(); daap_fail: rsp_deinit(); rsp_fail: event_base_free(evbase_httpd); return -1; }
int handle_lispd_config_file() { cfg_t *cfg = 0; unsigned int i = 0; unsigned n = 0; int ret = 0; static cfg_opt_t map_server_opts[] = { CFG_STR("address", 0, CFGF_NONE), CFG_INT("key-type", 0, CFGF_NONE), CFG_STR("key", 0, CFGF_NONE), CFG_BOOL("proxy-reply", cfg_false, CFGF_NONE), CFG_BOOL("verify", cfg_false, CFGF_NONE), CFG_END() }; static cfg_opt_t db_mapping_opts[] = { CFG_STR("eid-prefix", 0, CFGF_NONE), CFG_INT("iid", -1, CFGF_NONE), CFG_STR("interface", 0, CFGF_NONE), CFG_INT("priority_v4", 0, CFGF_NONE), CFG_INT("weight_v4", 0, CFGF_NONE), CFG_INT("priority_v6", 0, CFGF_NONE), CFG_INT("weight_v6", 0, CFGF_NONE), CFG_END() }; static cfg_opt_t mc_mapping_opts[] = { CFG_STR("eid-prefix", 0, CFGF_NONE), CFG_INT("iid", 0, CFGF_NONE), CFG_STR("rloc", 0, CFGF_NONE), CFG_INT("priority", 0, CFGF_NONE), CFG_INT("weight", 0, CFGF_NONE), CFG_END() }; static cfg_opt_t petr_mapping_opts[] = { CFG_STR("address", 0, CFGF_NONE), CFG_INT("priority", 255, CFGF_NONE), CFG_INT("weight", 0, CFGF_NONE), CFG_END() }; cfg_opt_t opts[] = { CFG_SEC("database-mapping", db_mapping_opts, CFGF_MULTI), CFG_SEC("static-map-cache", mc_mapping_opts, CFGF_MULTI), CFG_SEC("map-server", map_server_opts, CFGF_MULTI), CFG_SEC("proxy-etr", petr_mapping_opts, CFGF_MULTI), CFG_INT("map-request-retries", 0, CFGF_NONE), CFG_INT("control-port", 0, CFGF_NONE), CFG_BOOL("debug", cfg_false, CFGF_NONE), CFG_STR("map-resolver", 0, CFGF_NONE), CFG_STR_LIST("proxy-itrs", 0, CFGF_NONE), CFG_END() }; /* * parse config_file */ cfg = cfg_init(opts, CFGF_NOCASE); ret = cfg_parse(cfg, config_file); if (ret == CFG_FILE_ERROR) { syslog(LOG_DAEMON, "Couldn't find config file %s, exiting...", config_file); exit(EXIT_FAILURE); } else if(ret == CFG_PARSE_ERROR) { syslog(LOG_DAEMON, "NOTE: Version 0.2.4 changed the format of the 'proxy-etr' element."); syslog(LOG_DAEMON, " Check the 'lispd.conf.example' file for an example entry in"); syslog(LOG_DAEMON, " the new format."); syslog(LOG_DAEMON, "Parse error in file %s, exiting...", config_file); exit(EXIT_FAILURE); } /* * lispd config options */ ret = cfg_getint(cfg, "map-request-retries"); if (ret != 0) map_request_retries = ret; cfg_getbool(cfg, "debug") ? (debug = 1) : (debug = 0); /* * LISP config options */ /* * handle map-resolver config */ map_resolver = cfg_getstr(cfg, "map-resolver"); if (!add_server(map_resolver, &map_resolvers)) return(0); #ifdef DEBUG syslog(LOG_DAEMON, "Added %s to map-resolver list", map_resolver); #endif /* * handle proxy-etr config */ n = cfg_size(cfg, "proxy-etr"); for(i = 0; i < n; i++) { cfg_t *petr = cfg_getnsec(cfg, "proxy-etr", i); if (!add_proxy_etr_entry(petr, &proxy_etrs)) { syslog(LOG_DAEMON, "Can't add proxy-etr %d (%s)", i, cfg_getstr(petr, "address")); } } if (!proxy_etrs){ syslog(LOG_DAEMON, "WARNING: No Proxy-ETR defined. Packets to non-LISP destinations will be forwarded natively (no LISP encapsulation). This may prevent mobility in some scenarios."); sleep(3); } /* * handle proxy-itr config */ n = cfg_size(cfg, "proxy-itrs"); for(i = 0; i < n; i++) { if ((proxy_itr = cfg_getnstr(cfg, "proxy-itrs", i)) != NULL) { if (!add_server(proxy_itr, &proxy_itrs)) continue; #ifdef DEBUG syslog(LOG_DAEMON, "Added %s to proxy-itr list", proxy_itr); #endif } } /* * handle database-mapping config */ n = cfg_size(cfg, "database-mapping"); for(i = 0; i < n; i++) { cfg_t *dm = cfg_getnsec(cfg, "database-mapping", i); if (!add_database_mapping(dm)) { syslog(LOG_DAEMON, "Can't add database-mapping %d (%s->%s)", i, cfg_getstr(dm, "eid-prefix"), cfg_getstr(dm, "interface")); } } /* * handle map-server config */ n = cfg_size(cfg, "map-server"); for(i = 0; i < n; i++) { cfg_t *ms = cfg_getnsec(cfg, "map-server", i); if (!add_map_server(cfg_getstr(ms, "address"), cfg_getint(ms, "key-type"), cfg_getstr(ms, "key"), (cfg_getbool(ms, "proxy-reply") ? 1:0), (cfg_getbool(ms, "verify") ? 1:0))) return(0); #ifdef DEBUG syslog(LOG_DAEMON, "Added %s to map-server list", cfg_getstr(ms, "address")); #endif } /* * handle static-map-cache config */ n = cfg_size(cfg, "static-map-cache"); for(i = 0; i < n; i++) { cfg_t *smc = cfg_getnsec(cfg, "static-map-cache", i); if (!add_static_map_cache_entry(smc)) { syslog(LOG_DAEMON,"Can't add static-map-cache %d (EID:%s -> RLOC:%s)", i, cfg_getstr(smc, "eid-prefix"), cfg_getstr(smc, "rloc")); } } #if (DEBUG > 3) dump_tree(AF_INET,AF4_database); dump_tree(AF_INET6,AF6_database); dump_database(); dump_map_servers(); dump_servers(map_resolvers, "map-resolvers"); dump_servers(proxy_etrs, "proxy-etrs"); dump_servers(proxy_itrs, "proxy-itrs"); dump_map_cache(); #endif cfg_free(cfg); return(0); }
int turnserver_cfg_mod_tmpuser(void) { return cfg_getbool(g_cfg, "mod_tmpuser"); }
int turnserver_cfg_daemon(void) { return cfg_getbool(g_cfg, "daemon"); }
int turnserver_cfg_tcp_buffer_userspace(void) { return cfg_getbool(g_cfg, "tcp_buffer_userspace"); }
int turnserver_cfg_turn_tcp(void) { return cfg_getbool(g_cfg, "turn_tcp"); }
int turnserver_cfg_dtls(void) { return cfg_getbool(g_cfg, "dtls"); }
int init_ac_cfgd_config(char *conf_path, struct ac_cfgd_config_t *config) { int ret; cfg_opt_t opts[] = { CFG_BOOL("background", cfg_false, CFGF_NONE), CFG_BOOL("debug_mode", cfg_false, CFGF_NONE), CFG_STR("svc_name", SVC_TEST_NAME, CFGF_NONE), CFG_INT("svc_gameid", SVC_TEST_GAMEID, CFGF_NONE), CFG_STR("cc_ip", "localhost", CFGF_NONE), CFG_INT("cc_port", 3306, CFGF_NONE), CFG_STR("cc_my_user", "root", CFGF_NONE), CFG_STR("cc_my_passwd", "ta0mee", CFGF_NONE), CFG_STR("cc_my_dbname", "anticheat", CFGF_NONE), CFG_STR("cc_my_tw_tab_basename", "tw_config", CFGF_NONE), CFG_STR("cc_my_sw_tab_basename", "sw_config", CFGF_NONE), CFG_END() }; cfg_t *cfg = cfg_init(opts, CFGF_NONE); ret = cfg_parse(cfg, conf_path ? conf_path : DEF_CFG_PATH); if(ret == CFG_FILE_ERROR) { DP("Access error, conf: %s, err: %s", conf_path ? conf_path : DEF_CFG_PATH, strerror(errno)); return -1; } else if(ret == CFG_PARSE_ERROR) { DP("Parse error, conf: %s", conf_path ? conf_path : DEF_CFG_PATH); return -1; } memset(config, 0, sizeof(*config)); config->background = cfg_getbool(cfg, "background"); config->debug_mode = cfg_getbool(cfg, "debug_mode"); snprintf(config->svc_name, sizeof(config->svc_name), "%s", cfg_getstr(cfg, "svc_name")); config->svc_gameid = cfg_getint(cfg, "svc_gameid"); snprintf(config->cc_ip, sizeof(config->cc_ip), "%s", cfg_getstr(cfg, "cc_ip")); config->cc_port = cfg_getint(cfg, "cc_port"); snprintf(config->cc_my_user, sizeof(config->cc_my_user), "%s", cfg_getstr(cfg, "cc_my_user")); snprintf(config->cc_my_passwd, sizeof(config->cc_my_passwd), "%s", cfg_getstr(cfg, "cc_my_passwd")); snprintf(config->cc_my_dbname, sizeof(config->cc_my_dbname), "%s", cfg_getstr(cfg, "cc_my_dbname")); snprintf(config->cc_my_tw_tab_basename, sizeof(config->cc_my_tw_tab_basename), "%s", cfg_getstr(cfg, "cc_my_tw_tab_basename")); snprintf(config->cc_my_sw_tab_basename, sizeof(config->cc_my_sw_tab_basename), "%s", cfg_getstr(cfg, "cc_my_sw_tab_basename")); if (config->svc_gameid > MAX_SVC_GAMEID) { DP("Invalid svc_gameid: %u for svc: %s", config->svc_gameid, config->svc_name); return -1; } cfg_free(cfg); return 0; }
Ganglia_udp_send_channels Ganglia_udp_send_channels_create( Ganglia_pool p, Ganglia_gmond_config config ) { apr_array_header_t *send_channels = NULL; cfg_t *cfg=(cfg_t *)config; int i, num_udp_send_channels = cfg_size( cfg, "udp_send_channel"); apr_pool_t *context = (apr_pool_t*)p; /* Return null if there are no send channels specified */ if(num_udp_send_channels <= 0) return (Ganglia_udp_send_channels)send_channels; /* Create my UDP send array */ send_channels = apr_array_make( context, num_udp_send_channels, sizeof(apr_socket_t *)); for(i = 0; i< num_udp_send_channels; i++) { cfg_t *udp_send_channel; char *mcast_join, *mcast_if, *host; int port, ttl, bind_hostname; apr_socket_t *socket = NULL; apr_pool_t *pool = NULL; char *bind_address; udp_send_channel = cfg_getnsec( cfg, "udp_send_channel", i); host = cfg_getstr( udp_send_channel, "host" ); mcast_join = cfg_getstr( udp_send_channel, "mcast_join" ); mcast_if = cfg_getstr( udp_send_channel, "mcast_if" ); port = cfg_getint( udp_send_channel, "port"); ttl = cfg_getint( udp_send_channel, "ttl"); bind_address = cfg_getstr( udp_send_channel, "bind" ); bind_hostname = cfg_getbool( udp_send_channel, "bind_hostname"); debug_msg("udp_send_channel mcast_join=%s mcast_if=%s host=%s port=%d\n", mcast_join? mcast_join:"NULL", mcast_if? mcast_if:"NULL", host? host:"NULL", port); if(bind_address != NULL && bind_hostname == cfg_true) { err_msg("udp_send_channel: bind and bind_hostname are mutually exclusive, both parameters can't be specified for the same udp_send_channel\n"); exit(1); } /* Create a subpool */ apr_pool_create(&pool, context); /* Join the specified multicast channel */ if( mcast_join ) { /* We'll be listening on a multicast channel */ socket = create_mcast_client(pool, mcast_join, port, ttl, mcast_if, bind_address, bind_hostname); if(!socket) { err_msg("Unable to join multicast channel %s:%d. Exiting\n", mcast_join, port); exit(1); } } else { /* Create a UDP socket */ socket = create_udp_client( pool, host, port, mcast_if, bind_address, bind_hostname ); if(!socket) { err_msg("Unable to create UDP client for %s:%d. Exiting.\n", host? host: "NULL", port); exit(1); } } /* Add the socket to the array */ *(apr_socket_t **)apr_array_push(send_channels) = socket; } return (Ganglia_udp_send_channels)send_channels; }
int main(int argc, char *argv[]) { /* configuration options */ cfg_opt_t opts[] = { CFG_INT("vendor_id", 0, 0), CFG_INT("product_id", 0, 0), CFG_BOOL("self_powered", cfg_true, 0), CFG_BOOL("remote_wakeup", cfg_true, 0), CFG_BOOL("in_is_isochronous", cfg_false, 0), CFG_BOOL("out_is_isochronous", cfg_false, 0), CFG_BOOL("suspend_pull_downs", cfg_false, 0), CFG_BOOL("use_serial", cfg_false, 0), CFG_BOOL("change_usb_version", cfg_false, 0), CFG_INT("usb_version", 0, 0), CFG_INT("default_pid", 0x6001, 0), CFG_INT("max_power", 0, 0), CFG_STR("manufacturer", "Acme Inc.", 0), CFG_STR("product", "USB Serial Converter", 0), CFG_STR("serial", "08-15", 0), CFG_INT("eeprom_type", 0x00, 0), CFG_STR("filename", "", 0), CFG_BOOL("flash_raw", cfg_false, 0), CFG_BOOL("high_current", cfg_false, 0), CFG_STR_LIST("cbus0", "{TXDEN,PWREN,RXLED,TXLED,TXRXLED,SLEEP,CLK48,CLK24,CLK12,CLK6,IO_MODE,BITBANG_WR,BITBANG_RD,SPECIAL}", 0), CFG_STR_LIST("cbus1", "{TXDEN,PWREN,RXLED,TXLED,TXRXLED,SLEEP,CLK48,CLK24,CLK12,CLK6,IO_MODE,BITBANG_WR,BITBANG_RD,SPECIAL}", 0), CFG_STR_LIST("cbus2", "{TXDEN,PWREN,RXLED,TXLED,TXRXLED,SLEEP,CLK48,CLK24,CLK12,CLK6,IO_MODE,BITBANG_WR,BITBANG_RD,SPECIAL}", 0), CFG_STR_LIST("cbus3", "{TXDEN,PWREN,RXLED,TXLED,TXRXLED,SLEEP,CLK48,CLK24,CLK12,CLK6,IO_MODE,BITBANG_WR,BITBANG_RD,SPECIAL}", 0), CFG_STR_LIST("cbus4", "{TXDEN,PWRON,RXLED,TXLED,TX_RX_LED,SLEEP,CLK48,CLK24,CLK12,CLK6}", 0), CFG_BOOL("invert_txd", cfg_false, 0), CFG_BOOL("invert_rxd", cfg_false, 0), CFG_BOOL("invert_rts", cfg_false, 0), CFG_BOOL("invert_cts", cfg_false, 0), CFG_BOOL("invert_dtr", cfg_false, 0), CFG_BOOL("invert_dsr", cfg_false, 0), CFG_BOOL("invert_dcd", cfg_false, 0), CFG_BOOL("invert_ri", cfg_false, 0), CFG_END() }; cfg_t *cfg; /* normal variables */ int _read = 0, _erase = 0, _flash = 0; const int max_eeprom_size = 256; int my_eeprom_size = 0; unsigned char *eeprom_buf = NULL; char *filename; int size_check; int i, argc_filename; FILE *fp; struct ftdi_context *ftdi = NULL; printf("\nFTDI eeprom generator v%s\n", EEPROM_VERSION_STRING); printf ("(c) Intra2net AG and the libftdi developers <*****@*****.**>\n"); if (argc != 2 && argc != 3) { printf("Syntax: %s [commands] config-file\n", argv[0]); printf("Valid commands:\n"); printf("--read-eeprom Read eeprom and write to -filename- from config-file\n"); printf("--erase-eeprom Erase eeprom\n"); printf("--flash-eeprom Flash eeprom\n"); exit (-1); } if (argc == 3) { if (strcmp(argv[1], "--read-eeprom") == 0) _read = 1; else if (strcmp(argv[1], "--erase-eeprom") == 0) _erase = 1; else if (strcmp(argv[1], "--flash-eeprom") == 0) _flash = 1; else { printf ("Can't open configuration file\n"); exit (-1); } argc_filename = 2; } else { argc_filename = 1; } if ((fp = fopen(argv[argc_filename], "r")) == NULL) { printf ("Can't open configuration file\n"); exit (-1); } fclose (fp); cfg = cfg_init(opts, 0); cfg_parse(cfg, argv[argc_filename]); filename = cfg_getstr(cfg, "filename"); if (cfg_getbool(cfg, "self_powered") && cfg_getint(cfg, "max_power") > 0) printf("Hint: Self powered devices should have a max_power setting of 0.\n"); if ((ftdi = ftdi_new()) == 0) { fprintf(stderr, "Failed to allocate ftdi structure :%s \n", ftdi_get_error_string(ftdi)); return EXIT_FAILURE; } if (_read > 0 || _erase > 0 || _flash > 0) { int vendor_id = cfg_getint(cfg, "vendor_id"); int product_id = cfg_getint(cfg, "product_id"); i = ftdi_usb_open(ftdi, vendor_id, product_id); if (i != 0) { int default_pid = cfg_getint(cfg, "default_pid"); printf("Unable to find FTDI devices under given vendor/product id: 0x%X/0x%X\n", vendor_id, product_id); printf("Error code: %d (%s)\n", i, ftdi_get_error_string(ftdi)); printf("Retrying with default FTDI pid=%#04x.\n", default_pid); i = ftdi_usb_open(ftdi, 0x0403, default_pid); if (i != 0) { printf("Error: %s\n", ftdi->error_str); exit (-1); } } } ftdi_eeprom_initdefaults (ftdi, cfg_getstr(cfg, "manufacturer"), cfg_getstr(cfg, "product"), cfg_getstr(cfg, "serial")); printf("FTDI read eeprom: %d\n", ftdi_read_eeprom(ftdi)); eeprom_get_value(ftdi, CHIP_SIZE, &my_eeprom_size); printf("EEPROM size: %d\n", my_eeprom_size); if (_read > 0) { ftdi_eeprom_decode(ftdi, 1); eeprom_buf = malloc(my_eeprom_size); ftdi_get_eeprom_buf(ftdi, eeprom_buf, my_eeprom_size); if (eeprom_buf == NULL) { fprintf(stderr, "Malloc failed, aborting\n"); goto cleanup; } if (filename != NULL && strlen(filename) > 0) { FILE *fp = fopen (filename, "wb"); fwrite (eeprom_buf, 1, my_eeprom_size, fp); fclose (fp); } else { printf("Warning: Not writing eeprom, you must supply a valid filename\n"); } goto cleanup; } eeprom_set_value(ftdi, VENDOR_ID, cfg_getint(cfg, "vendor_id")); eeprom_set_value(ftdi, PRODUCT_ID, cfg_getint(cfg, "product_id")); eeprom_set_value(ftdi, SELF_POWERED, cfg_getbool(cfg, "self_powered")); eeprom_set_value(ftdi, REMOTE_WAKEUP, cfg_getbool(cfg, "remote_wakeup")); eeprom_set_value(ftdi, MAX_POWER, cfg_getint(cfg, "max_power")); eeprom_set_value(ftdi, IN_IS_ISOCHRONOUS, cfg_getbool(cfg, "in_is_isochronous")); eeprom_set_value(ftdi, OUT_IS_ISOCHRONOUS, cfg_getbool(cfg, "out_is_isochronous")); eeprom_set_value(ftdi, SUSPEND_PULL_DOWNS, cfg_getbool(cfg, "suspend_pull_downs")); eeprom_set_value(ftdi, USE_SERIAL, cfg_getbool(cfg, "use_serial")); eeprom_set_value(ftdi, USE_USB_VERSION, cfg_getbool(cfg, "change_usb_version")); eeprom_set_value(ftdi, USB_VERSION, cfg_getint(cfg, "usb_version")); eeprom_set_value(ftdi, CHIP_TYPE, cfg_getint(cfg, "eeprom_type")); eeprom_set_value(ftdi, HIGH_CURRENT, cfg_getbool(cfg, "high_current")); eeprom_set_value(ftdi, CBUS_FUNCTION_0, str_to_cbus(cfg_getstr(cfg, "cbus0"), 13)); eeprom_set_value(ftdi, CBUS_FUNCTION_1, str_to_cbus(cfg_getstr(cfg, "cbus1"), 13)); eeprom_set_value(ftdi, CBUS_FUNCTION_2, str_to_cbus(cfg_getstr(cfg, "cbus2"), 13)); eeprom_set_value(ftdi, CBUS_FUNCTION_3, str_to_cbus(cfg_getstr(cfg, "cbus3"), 13)); eeprom_set_value(ftdi, CBUS_FUNCTION_4, str_to_cbus(cfg_getstr(cfg, "cbus4"), 9)); int invert = 0; if (cfg_getbool(cfg, "invert_rxd")) invert |= INVERT_RXD; if (cfg_getbool(cfg, "invert_txd")) invert |= INVERT_TXD; if (cfg_getbool(cfg, "invert_rts")) invert |= INVERT_RTS; if (cfg_getbool(cfg, "invert_cts")) invert |= INVERT_CTS; if (cfg_getbool(cfg, "invert_dtr")) invert |= INVERT_DTR; if (cfg_getbool(cfg, "invert_dsr")) invert |= INVERT_DSR; if (cfg_getbool(cfg, "invert_dcd")) invert |= INVERT_DCD; if (cfg_getbool(cfg, "invert_ri")) invert |= INVERT_RI; eeprom_set_value(ftdi, INVERT, invert); eeprom_set_value(ftdi, CHANNEL_A_DRIVER, DRIVER_VCP); eeprom_set_value(ftdi, CHANNEL_B_DRIVER, DRIVER_VCP); eeprom_set_value(ftdi, CHANNEL_C_DRIVER, DRIVER_VCP); eeprom_set_value(ftdi, CHANNEL_D_DRIVER, DRIVER_VCP); eeprom_set_value(ftdi, CHANNEL_A_RS485, 0); eeprom_set_value(ftdi, CHANNEL_B_RS485, 0); eeprom_set_value(ftdi, CHANNEL_C_RS485, 0); eeprom_set_value(ftdi, CHANNEL_D_RS485, 0); if (_erase > 0) { printf("FTDI erase eeprom: %d\n", ftdi_erase_eeprom(ftdi)); } size_check = ftdi_eeprom_build(ftdi); eeprom_get_value(ftdi, CHIP_SIZE, &my_eeprom_size); if (size_check == -1) { printf ("Sorry, the eeprom can only contain 128 bytes (100 bytes for your strings).\n"); printf ("You need to short your string by: %d bytes\n", size_check); goto cleanup; } else if (size_check < 0) { printf ("ftdi_eeprom_build(): error: %d\n", size_check); } else { printf ("Used eeprom space: %d bytes\n", my_eeprom_size-size_check); } if (_flash > 0) { if (cfg_getbool(cfg, "flash_raw")) { if (filename != NULL && strlen(filename) > 0) { eeprom_buf = malloc(max_eeprom_size); FILE *fp = fopen(filename, "rb"); if (fp == NULL) { printf ("Can't open eeprom file %s.\n", filename); exit (-1); } my_eeprom_size = fread(eeprom_buf, 1, max_eeprom_size, fp); fclose(fp); if (my_eeprom_size < 128) { printf ("Can't read eeprom file %s.\n", filename); exit (-1); } ftdi_set_eeprom_buf(ftdi, eeprom_buf, my_eeprom_size); } } printf ("FTDI write eeprom: %d\n", ftdi_write_eeprom(ftdi)); libusb_reset_device(ftdi->usb_dev); } // Write to file? if (filename != NULL && strlen(filename) > 0 && !cfg_getbool(cfg, "flash_raw")) { fp = fopen(filename, "w"); if (fp == NULL) { printf ("Can't write eeprom file.\n"); exit (-1); } else printf ("Writing to file: %s\n", filename); if (eeprom_buf == NULL) eeprom_buf = malloc(my_eeprom_size); ftdi_get_eeprom_buf(ftdi, eeprom_buf, my_eeprom_size); fwrite(eeprom_buf, my_eeprom_size, 1, fp); fclose(fp); } cleanup: if (eeprom_buf) free(eeprom_buf); if (_read > 0 || _erase > 0 || _flash > 0) { printf("FTDI close: %d\n", ftdi_usb_close(ftdi)); } ftdi_deinit (ftdi); ftdi_free (ftdi); cfg_free(cfg); printf("\n"); return 0; }
// // E_MetaIntFromCfgBool // // Utility function. // Adds a MetaInteger property to the passed-in table with the same name // and value as the cfg_t bool property. // void E_MetaIntFromCfgBool(MetaTable *meta, cfg_t *cfg, const char *prop) { meta->setInt(prop, cfg_getbool(cfg, prop)); }
int main(int argc, char **argv) { //Check if user == root if(geteuid() != 0) { puts("Please run this software as root!"); exit(EXIT_FAILURE); } // check for non-daemon mode for debugging for(int i = 1; i < argc; i++) { if (str_is(argv[i], "nodaemon")) { start_daemon = 0; break; } } if (start_daemon) { //Init daemon, can be replaced with daemon() call pid_t pid; pid = fork(); if (pid < 0) { exit(EXIT_FAILURE); } if (pid > 0) { exit(EXIT_SUCCESS); } umask(0); //We are now running as the forked child process. openlog(argv[0],LOG_NOWAIT|LOG_PID,LOG_USER); pid_t sid; sid = setsid(); if (sid < 0) { syslog(LOG_ERR, "Could not create process group\n"); exit(EXIT_FAILURE); } if ((chdir("/")) < 0) { syslog(LOG_ERR, "Could not change working directory to /\n"); exit(EXIT_FAILURE); } } else { // open syslog for non-daemon mode openlog(argv[0],LOG_NOWAIT|LOG_PID,LOG_USER); } //Read configuration file cfg_opt_t opts[] = { CFG_INT("i2cbus", 1, CFGF_NONE), CFG_INT("frequency", 99800, CFGF_NONE), CFG_BOOL("stereo", 1, CFGF_NONE), CFG_BOOL("rdsenable", 1, CFGF_NONE), CFG_BOOL("poweron", 1, CFGF_NONE), CFG_BOOL("tcpbindlocal", 1, CFGF_NONE), CFG_INT("tcpport", 42516, CFGF_NONE), CFG_INT("txpower", 3, CFGF_NONE), CFG_BOOL("gain", 0, CFGF_NONE), CFG_INT("volume", 3, CFGF_NONE), CFG_INT("rdspin", 17, CFGF_NONE), CFG_STR("rdsid", "", CFGF_NONE), CFG_STR("rdstext", "", CFGF_NONE), CFG_INT("ledpin", 27, CFGF_NONE), CFG_END() }; cfg = cfg_init(opts, CFGF_NONE); if (cfg_parse(cfg, "/etc/fmberry.conf") == CFG_PARSE_ERROR) return 1; // get LED pin number int led = 1; // led state ledpin = cfg_getint(cfg, "ledpin"); rdsint = cfg_getint(cfg, "rdspin"); // Init I2C bus and transmitter with initial frequency and state if (ns741_init(cfg_getint(cfg, "i2cbus"), cfg_getint(cfg, "frequency")) == -1) { syslog(LOG_ERR, "Init failed! Double-check hardware and try again!\n"); exit(EXIT_FAILURE); } syslog(LOG_NOTICE, "Successfully initialized ns741 transmitter.\n"); int nfds; struct pollfd polls[2]; // open TCP listener socket, will exit() in case of error int lst = ListenTCP(cfg_getint(cfg, "tcpport")); polls[0].fd = lst; polls[0].events = POLLIN; nfds = 1; // initialize data structure for 'status' command bzero(&mmr70, sizeof(mmr70)); mmr70.frequency = cfg_getint(cfg, "frequency"); mmr70.power = cfg_getbool(cfg, "poweron"); mmr70.txpower = cfg_getint(cfg, "txpower"); mmr70.mute = 0; mmr70.gain = cfg_getbool(cfg, "gain"); mmr70.volume = cfg_getint(cfg, "volume"); mmr70.stereo = cfg_getbool(cfg, "stereo"); mmr70.rds = cfg_getbool(cfg, "rdsenable"); strncpy(mmr70.rdsid, cfg_getstr(cfg, "rdsid"), 8); strncpy(mmr70.rdstext, cfg_getstr(cfg, "rdstext"), 64); // apply configuration parameters ns741_txpwr(mmr70.txpower); ns741_mute(mmr70.mute); ns741_stereo(mmr70.stereo); ns741_rds_set_progname(mmr70.rdsid); ns741_rds_set_radiotext(mmr70.rdstext); ns741_power(mmr70.power); ns741_input_gain(mmr70.gain); ns741_volume(mmr70.volume); // Use RPI_REV1 for earlier versions of Raspberry Pi rpi_pin_init(RPI_REVISION); // Get file descriptor for RDS handler polls[1].revents = 0; if (mmr70.rds) { int rds = rpi_pin_poll_enable(rdsint, EDGE_FALLING); if (rds < 0) { printf("Couldn't enable RDS support\n"); run = 0; } polls[1].fd = rds; polls[1].events = POLLPRI; nfds = 2; if (ledpin > 0) { rpi_pin_export(ledpin, RPI_OUTPUT); rpi_pin_set(ledpin, led); } ns741_rds(1); ns741_rds_isr(); // send first two bytes } // main polling loop int ledcounter = 0; while(run) { if (poll(polls, nfds, -1) < 0) break; if (polls[1].revents) { rpi_pin_poll_clear(polls[1].fd); ns741_rds_isr(); // flash LED if enabled on every other RDS refresh cycle if (ledpin > 0) { ledcounter++; if (!(ledcounter % 80)) { led ^= 1; rpi_pin_set(ledpin, led); } } } if (polls[0].revents) ProcessTCP(lst, &mmr70); } // clean up at exit ns741_power(0); if (mmr70.rds) rpi_pin_unexport(rdsint); if (ledpin > 0) { rpi_pin_set(ledpin, 0); rpi_pin_unexport(ledpin); } close(lst); closelog(); return 0; }