static int processRequest(char *request) { int count = 0; int responseTotal = 0; config_setting_t *responseConfig = NULL; config_setting_t *responseCurrent = NULL; const char *responseValue = NULL; const char *requestName = NULL; const char *requestValue = NULL; long volume; pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL); pthread_mutex_lock(&lockConfig); responseConfig = config_lookup(&config, "response"); responseTotal = config_setting_length(responseConfig); for(count = 0; count < responseTotal; count++) { responseCurrent = config_setting_get_elem(responseConfig, count); if((responseValue = config_setting_get_string_elem(responseCurrent, 1)) != NULL && strcmp(responseValue, request) == 0) { responseValue = config_setting_get_string_elem(responseCurrent, 2); if(config_setting_get_bool_elem(responseCurrent, 0) == 1) { // formulating default response pthread_mutex_unlock(&lockConfig); pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); common_data.interface->reply(responseValue, strlen(responseValue)); } else { // attempt to formulate custom response requestName = config_setting_name(responseCurrent); pthread_mutex_unlock(&lockConfig); pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); if(strcmp(requestName, "volume") == 0) { if(getMixer(&volume) == EXIT_FAILURE) { return EXIT_FAILURE; } replyVolumeCommand(&volume); } else { statusInfo.retrieve(requestName, &requestValue); if(requestValue != NULL) replyDeviceCommand((char *)requestName, (char *)requestValue); else // custom response not possible, reverting to default value replyDeviceCommand((char *)requestName, (char *)responseValue); } } syslog(LOG_DEBUG, "Successfully processed request: %s", request); return EXIT_SUCCESS; // command is matched, returning } else { pthread_mutex_unlock(&lockConfig); pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); } } syslog(LOG_DEBUG, "Could not identify request: %s", request); return EXIT_SUCCESS; }
void initSerialPort() { struct termios options; const config_setting_t *device; int count; device = config_lookup(cf, "device"); count = config_setting_length(device); DEBUG(LOG_INFO, "There are %d device in your config file",count); int n; for (n = 0; n < count; n++) { fd = open(config_setting_get_string_elem(device, n), O_RDWR | O_NOCTTY); if (fd != -1) break; } if (fd == -1) { DEBUG(LOG_ERR, "Open_port: Unable to open serial ports"); printf("Exiting: no serial port available"); exit(EXIT_FAILURE);/* * Could not open the port.*/ } DEBUG(LOG_INFO,"Opening %s",config_setting_get_string_elem(device, n)); fcntl(fd, F_SETFL, 0); /* * Get the current options for the port... */ tcgetattr(fd, &options); /* * Set the baud rates to 19200... */ cfsetispeed(&options, B9600); cfsetospeed(&options, B9600); /* * Enable the receiver and set local mode... */ options.c_cflag |= (CLOCAL | CREAD | CS8 ); options.c_cflag &= ~(PARENB | CSTOPB | CSIZE); // options.c_cflag &= ~CRTSCTS ; options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG); options.c_iflag &= ~(ICRNL | IXON | IXOFF | IXANY); options.c_oflag &= ~OPOST; /* * Set the new options for the port... */ tcsetattr(fd, TCSAFLUSH, &options); fcntl(fd, F_SETFL, FNDELAY); }
const char *config_get_string_elem(config_t *config, char *setting, int element, const char *initial) { const char *value; config_setting_t *config_setting = config_lookup(config,setting); PRINT_SETTING; if (config_setting == NULL) { PRINT_NOT_FOUND; value = initial; } else { if ((value = config_setting_get_string_elem(config_setting,element)) == NULL) { PRINT_NOT_FOUND; value = initial; } } PRINT_VALUE_STR; return value; }
/** * Load client rules list. * @param[in] option Configuration option. * @param[in,out] rules Resulting rules. * @return <0 - error. 0 - success. >0 - not found. */ static int zcfg_load_client_rules(const config_setting_t *option, zclient_rules_t *rules) { zclient_rules_init(rules); if (!option) { return 1; } if (CONFIG_TYPE_LIST != option->type) { return -1; } int count = config_setting_length(option); zclient_rule_parser_t *rule_parser = zclient_rule_parser_new(); for (int i = 0; i < count; i++) { const char *str = config_setting_get_string_elem(option, i); if (!zclient_rule_parse(rule_parser, rules, str)) { ZLOG(LOG_ERR, "config:%s:%s: invalid client rule: %s", option->parent->name, option->name, str); zclient_rule_parser_free(rule_parser); return -1; } } zclient_rule_parser_free(rule_parser); return 0; }
TCHAR *cfgGetStringElem(const config_setting_t * setting, int index, TCHAR *outStr) { const char *value; value = config_setting_get_string_elem(setting, index); return UTF8_Decode(value, outStr, CONFIG_WCHAR_MAXSTRING); }
/** * Parses the configuration file, specifically the * ldap section. This function will produce a tree, * or really a linked list, tree sounds cooler, of * ldap_query_t structures. This will allow a series * of events to happen sequentially just by adding a * few lines to the configuration file. The returned * node is the head of the tree/list. */ slack_ldap_query_t build_query_tree() { syslog(LOG_INFO, "Building query event tree..."); static slack_ldap_query_t head; slack_ldap_query_t *tail = &head; config_setting_t *setting = config_lookup(&config, "ldap.queries"); int i = 0; do { /* The caveat, and requirement, is that there be at least one ldap query parameter, otherwise you just shouldn't include the ldap module...*/ const char *query = config_setting_get_string_elem(setting, i); if(query != NULL) { char query_param[strlen("ldap.query") //GCC/clang will optimize + strlen(query)+1]; // +1 for dot op sprintf(query_param, "ldap.query.%s", query); syslog(LOG_INFO, "Parsed LDAP query %s", query_param); syslog(LOG_INFO, "Building LDAP query node..."); /* Each of the string must have a +1 for dot operator */ char basednstr[strlen(query_param) + 8]; //length of 'basedn' sprintf(basednstr, "%s.%s", query_param, "basedn"); syslog(LOG_INFO, "Parsing %s", basednstr); char filterstr[strlen(query_param) + 6]; //length of 'filter' sprintf(filterstr, "%s.%s", query_param, "filter"); syslog(LOG_INFO, "Parsing %s", filterstr); char eventstr[strlen(query_param) + 5]; //length of 'event' sprintf(eventstr, "%s.%s", query_param, "event"); syslog(LOG_INFO, "Parsing %s", eventstr); syslog(LOG_INFO, "Building query node..."); config_lookup_string(&config, basednstr, (const char **)&(tail->basednstr)); config_lookup_string(&config, filterstr, (const char **)&(tail->filterstr)); config_lookup_string(&config, eventstr, (const char **)&(tail->eventstr)); tail->next = malloc(sizeof(slack_ldap_query_t)); /* By this point the new node, TODO: write a failure method * if we don't make it to this point. I beleive the only * alternative to correct configuration is segfault :( */ syslog(LOG_INFO, "Success, New Node:"); syslog(LOG_INFO, "--->basedn = %s", tail->basednstr); syslog(LOG_INFO, "--->filter = %s", tail->filterstr); syslog(LOG_INFO, "--->event = %s", tail->eventstr); /* Move onto the next node */ tail = tail->next; i++; } else { syslog(LOG_INFO, "Parsed all ldap queries."); i = -1; tail->next = NULL; } } while(i != -1); return head; }
int init_config() { char filename[] = "iowt.cfg"; PRINTF("Loading config file %s...\n", filename); int rv; config_t config; config_setting_t* config_setting; config_init(&config); if(!config_read_file(&config, filename)) { printf("Error reading line %d: %s\n", config_error_line(&config), config_error_text(&config)); exit(-1); } // Get FILE_DIR int config_lookup_string (const config_t * config, const char * path, const char ** value); rv = config_lookup_string(&config, "file_dir", &FILE_DIR); PRINTF("FILE_DIR is %s\n", FILE_DIR); // Get SERVERS list config_setting = config_lookup (&config, "servers"); // Loop through once to count, malloc, loop again to populate char* temp; int count = -1; do { count++; temp = (char*)config_setting_get_string_elem(config_setting, count); } while(temp != NULL); SERVERS = (const char**)malloc(count*sizeof(char*)); int i; PRINTF("SERVERS list:\n"); for(i=0; i<count; i++) { SERVERS[i] = config_setting_get_string_elem(config_setting, i); PRINTF(" [%02d]: %s\n", i, SERVERS[i]); } NUM_SERVERS = count; PRINTF("Done parsing config!\n"); return 0; }
/** * Load subnet array. * @param[in] cfg Config section. * @param[in] option Option name. * @param[in,out] array Resulting array. * @return <0 - error. 0 - success. >0 - not found. */ static int zcfg_load_subnet_list(const config_setting_t *option, zsubnet_group_t *array) { utarray_init(array, &ut_ip_range_icd); if (!option) { return 1; } if (CONFIG_TYPE_LIST != option->type) { return -1; } int count = config_setting_length(option); for (int i = 0; i < count; i++) { ip_range_t range; char ip_str[INET_ADDRSTRLEN]; const char *item = config_setting_get_string_elem(option, i); const char *cidr_pos = strchr(item, '/'); // search CIDR, and make sure, that ip part is not bigger than buffer size if (cidr_pos && (((size_t) (cidr_pos - item) < sizeof(ip_str)))) { strncpy(ip_str, item, cidr_pos - item); ip_str[cidr_pos - item] = '\0'; struct in_addr ip_addr; if (0 < inet_pton(AF_INET, ip_str, &ip_addr)) { uint8_t cidr = 0; if ((0 == str_to_u8(cidr_pos + 1, &cidr)) && (cidr <= CIDR_MAX)) { range.ip_start = ntohl(ip_addr.s_addr); range.ip_end = IP_RANGE_END(range.ip_start, cidr); utarray_push_back(array, &range); continue; } } } // error handler ZLOG(LOG_ERR, "config:%s:%s: invalid subnet: %s", option->parent->name, option->name, item); utarray_done(array); return -1; } if (count) { utarray_sort(array, ip_range_cmp); } return 0; }
/********************* return RET_NOK on error res must be freed with deep_free *********************/ static ret_code_t __read_list(const char * table, const char * file, char *** res, va_list ap) { const config_t * config = NULL; config_setting_t * setting = NULL; char * path; int i = 0; const char * elem; *res = NULL; SDL_LockMutex(entry_mutex); config = get_config(table,file); if(config==NULL) { SDL_UnlockMutex(entry_mutex); return RET_NOK; } path = get_path(ap); if(path == NULL) { SDL_UnlockMutex(entry_mutex); return RET_NOK; } setting = config_lookup (config, path); if( setting == NULL ) { SDL_UnlockMutex(entry_mutex); free(path); return RET_NOK; } free(path); while( (elem=config_setting_get_string_elem (setting,i )) != NULL ) { i++; *res = (char**)realloc(*res,(i+1)*sizeof(char *)); (*res)[i-1] = strdup(elem); (*res)[i] = NULL; } SDL_UnlockMutex(entry_mutex); if(*res == NULL) { return RET_NOK; } return RET_OK; }
/********************* return RET_NOK on failure *********************/ static ret_code_t __remove_from_list(const char * table, const char * file, const char * to_be_removed, va_list ap) { const config_t * config = NULL; config_setting_t * setting = NULL; char * path; int i = 0; const char * elem; SDL_LockMutex(entry_mutex); config = get_config(table,file); if(config==NULL) { SDL_UnlockMutex(entry_mutex); return RET_NOK; } path = get_path(ap); if(path == NULL) { SDL_UnlockMutex(entry_mutex); return RET_NOK; } setting = config_lookup (config, path); if( setting == NULL ) { SDL_UnlockMutex(entry_mutex); free(path); return RET_NOK; } free(path); while( (elem=config_setting_get_string_elem (setting,i )) != NULL ) { if( strcmp(elem,to_be_removed) == 0 ) { if(config_setting_remove_elem (setting,i)==CONFIG_FALSE) { SDL_UnlockMutex(entry_mutex); return RET_NOK; } write_config(config,table,file); SDL_UnlockMutex(entry_mutex); return RET_OK; } i++; } SDL_UnlockMutex(entry_mutex); return RET_NOK; }
/********************* return RET_NOK on error res MUST BE FREED by caller *********************/ static ret_code_t __read_list_index(const char * table, const char * file, char ** res, int index, va_list ap) { const config_t * config = NULL; config_setting_t * setting = NULL; char * path; const char * result; *res = NULL; SDL_LockMutex(entry_mutex); config = get_config(table,file); if(config==NULL) { SDL_UnlockMutex(entry_mutex); return RET_NOK; } path = get_path(ap); if(path == NULL) { SDL_UnlockMutex(entry_mutex); return RET_NOK; } setting = config_lookup (config, path); if( setting == NULL ) { SDL_UnlockMutex(entry_mutex); free(path); return RET_NOK; } free(path); result = config_setting_get_string_elem (setting,index); if(result == NULL ) { SDL_UnlockMutex(entry_mutex); return RET_NOK; } SDL_UnlockMutex(entry_mutex); *res = strdup(result); return RET_OK; }
void load_message_file_source(void) { #define ARRAYLENGTH(A) ( sizeof(A)/sizeof((A)[0]) ) config_setting_t *main_group = NULL; config_t group_ext; int index=0; if (libconfig->read_file(&group_ext, bra_config.lang_file)) return; memset(lang_s, 0, sizeof(LANG)); if((main_group = config_lookup(&group_ext, "Source"))) { int i, h, k = 0, groups_count = libconfig->setting_length(main_group); config_setting_t *group_ele; config_setting_t *groups; for(i = 0; i < groups_count; ++i) { group_ele = libconfig->setting_get_elem(main_group, i); while(k < ARRAYLENGTH(Source) && (groups = libconfig->setting_get_member(group_ele, Source[k]))) { int group_count = config_setting_length(groups); for(h = 0; h < group_count; h++) { config_setting_t *group_e = libconfig->setting_get_elem(groups, h); copy_to_list((char *)config_setting_name(group_e), (char *)config_setting_get_string_elem(groups, h), index); index++; } k++; } } } ShowConf("Leitura de '"CL_WHITE"%d"CL_RESET"' mensagens em '"CL_WHITE"%s"CL_RESET"'.\n", index, bra_config.lang_file); }
void ya_config_parse() { int ret; const char * const envhome = getenv("HOME"); if ((ya.gen_flag & GEN_EXT_CONF) == 0) snprintf(conf_file, CFILELEN, "%s/.config/yabar/yabar.conf", envhome); config_t ya_conf; config_init(&ya_conf); config_set_auto_convert(&ya_conf, CONFIG_TRUE); ret=config_read_file(&ya_conf, conf_file); if (ret == CONFIG_FALSE) { fprintf(stderr, "Error in the config file at line %d : %s\nExiting...\n", config_error_line(&ya_conf), config_error_text(&ya_conf)); config_destroy(&ya_conf); exit(EXIT_SUCCESS); } char *barstr, *blkstr; config_setting_t *barlist_set, *blklist_set; config_setting_t *curbar_set, *curblk_set; barlist_set = config_lookup(&ya_conf, "bar-list"); if(barlist_set == NULL) { fprintf(stderr, "Please add a `bar-list` entry with at least one bar.\nExiting...\n"); config_destroy(&ya_conf); exit(EXIT_SUCCESS); } ya.barnum = config_setting_length(barlist_set); if(ya.barnum < 1) { fprintf(stderr, "Please add at least one bar in the `bar-list` entry.\nExiting...\n"); config_destroy(&ya_conf); exit(EXIT_SUCCESS); } int blknum; for(int i=0; i < ya.barnum; i++) { barstr = (char *)config_setting_get_string_elem(barlist_set, i); curbar_set = config_lookup(&ya_conf, barstr); if(curbar_set == NULL) { fprintf(stderr, "No valid bar with the name (%s), skipping this invalid bar.\n", barstr); //If there is only one bar, continue won't work and we get a segfault. //We should exit anyway because we have one && invalid bar name. if(ya.barnum == 1) exit(EXIT_SUCCESS); continue; } ya_setup_bar(curbar_set); #ifdef OLD_LIBCONFIG blklist_set = config_lookup_from(curbar_set, "block-list"); #else blklist_set = config_setting_lookup(curbar_set, "block-list"); #endif if(blklist_set == NULL) { fprintf(stderr, "No `block-list` entry found for the bar(%s).\n", barstr); continue; } blknum = config_setting_length(blklist_set); if(blknum < 1) { fprintf(stderr, "No blocks in `block-list` entry for the bar(%s).\n", barstr); continue; } for (int i=0; i < blknum; i++) { blkstr = (char *)config_setting_get_string_elem(blklist_set, i); #ifdef OLD_LIBCONFIG curblk_set = config_lookup_from(curbar_set, blkstr); #else curblk_set = config_setting_lookup(curbar_set, blkstr); #endif if(curblk_set == NULL) { fprintf(stderr, "No valid block with the name (%s) in the bar (%s), skipping this block\n", blkstr, barstr); continue; } ya_setup_block(curblk_set); } } config_destroy(&ya_conf); }
int mme_app_config_init(char* lib_config_file_name_pP, mme_app_config_t* config_pP) { config_t cfg; config_setting_t *setting_sgw = NULL; char *sgw_interface_name_for_S1u_S12_S4_up = NULL; char *sgw_ipv4_address_for_S1u_S12_S4_up = NULL; char *sgw_interface_name_for_S5_S8_up = NULL; char *sgw_ipv4_address_for_S5_S8_up = NULL; char *sgw_interface_name_for_S11 = NULL; char *sgw_ipv4_address_for_S11 = NULL; config_setting_t *setting_pgw = NULL; config_setting_t *subsetting = NULL; config_setting_t *sub2setting = NULL; char *pgw_interface_name_for_S5_S8 = NULL; char *pgw_ipv4_address_for_S5_S8 = NULL; char *pgw_interface_name_for_SGI = NULL; char *pgw_ipv4_address_for_SGI = NULL; char *delimiters=NULL; char *saveptr1= NULL; char *astring = NULL; char *atoken = NULL; char *atoken2 = NULL; char *address = NULL; char *cidr = NULL; char *mask = NULL; int num = 0; int i = 0; int jh, jn; unsigned char buf_in6_addr[sizeof(struct in6_addr)]; struct in6_addr addr6_start; struct in6_addr addr6_mask; int prefix_mask; uint64_t counter64; unsigned char buf_in_addr[sizeof(struct in_addr)]; struct in_addr addr_start; struct in_addr addr_end; memset((char*)config_pP, 0 , sizeof(mme_app_config_t)); config_init(&cfg); if(lib_config_file_name_pP != NULL) { /* Read the file. If there is an error, report it and exit. */ if(! config_read_file(&cfg, lib_config_file_name_pP)) { MME_APP_ERROR("%s:%d - %s\n", lib_config_file_name_pP, config_error_line(&cfg), config_error_text(&cfg)); config_destroy(&cfg); AssertFatal (1 == 0, "Failed to parse eNB configuration file %s!\n", lib_config_file_name_pP); } } else { SPGW_APP_ERROR("No SP-GW configuration file provided!\n"); config_destroy(&cfg); AssertFatal (0, "No SP-GW configuration file provided!\n"); } setting_sgw = config_lookup(&cfg, SGW_CONFIG_STRING_SGW_CONFIG); if(setting_sgw != NULL) { subsetting = config_setting_get_member (setting_sgw, SGW_CONFIG_STRING_NETWORK_INTERFACES_CONFIG); if(subsetting != NULL) { if( ( config_setting_lookup_string( subsetting, SGW_CONFIG_STRING_SGW_INTERFACE_NAME_FOR_S1U_S12_S4_UP, (const char **)&sgw_interface_name_for_S1u_S12_S4_up) && config_setting_lookup_string( subsetting, SGW_CONFIG_STRING_SGW_IPV4_ADDRESS_FOR_S1U_S12_S4_UP, (const char **)&sgw_ipv4_address_for_S1u_S12_S4_up) && config_setting_lookup_string( subsetting, SGW_CONFIG_STRING_SGW_INTERFACE_NAME_FOR_S5_S8_UP, (const char **)&sgw_interface_name_for_S5_S8_up) && config_setting_lookup_string( subsetting, SGW_CONFIG_STRING_SGW_IPV4_ADDRESS_FOR_S5_S8_UP, (const char **)&sgw_ipv4_address_for_S5_S8_up) && config_setting_lookup_string( subsetting, SGW_CONFIG_STRING_SGW_INTERFACE_NAME_FOR_S11, (const char **)&sgw_interface_name_for_S11) && config_setting_lookup_string( subsetting, SGW_CONFIG_STRING_SGW_IPV4_ADDRESS_FOR_S11, (const char **)&sgw_ipv4_address_for_S11) ) ) { config_pP->sgw_config.ipv4.sgw_interface_name_for_S1u_S12_S4_up = strdup(sgw_interface_name_for_S1u_S12_S4_up); cidr = strdup(sgw_ipv4_address_for_S1u_S12_S4_up); address = strtok(cidr, "/"); mask = strtok(NULL, "/"); IPV4_STR_ADDR_TO_INT_NWBO ( address, config_pP->sgw_config.ipv4.sgw_ipv4_address_for_S1u_S12_S4_up, "BAD IP ADDRESS FORMAT FOR S1u_S12_S4 !\n" ) config_pP->sgw_config.ipv4.sgw_ip_netmask_for_S1u_S12_S4_up = atoi(mask); free(cidr); config_pP->sgw_config.ipv4.sgw_interface_name_for_S5_S8_up = strdup(sgw_interface_name_for_S5_S8_up); cidr = strdup(sgw_ipv4_address_for_S5_S8_up); address = strtok(cidr, "/"); mask = strtok(NULL, "/"); IPV4_STR_ADDR_TO_INT_NWBO ( address, config_pP->sgw_config.ipv4.sgw_ipv4_address_for_S5_S8_up, "BAD IP ADDRESS FORMAT FOR S5_S8 !\n" ) config_pP->sgw_config.ipv4.sgw_ip_netmask_for_S5_S8_up = atoi(mask); free(cidr); config_pP->sgw_config.ipv4.sgw_interface_name_for_S11 = strdup(sgw_interface_name_for_S11); cidr = strdup(sgw_ipv4_address_for_S11); address = strtok(cidr, "/"); mask = strtok(NULL, "/"); IPV4_STR_ADDR_TO_INT_NWBO ( address, config_pP->sgw_config.ipv4.sgw_ipv4_address_for_S11, "BAD IP ADDRESS FORMAT FOR S11 !\n" ) config_pP->sgw_config.ipv4.sgw_ip_netmask_for_S11 = atoi(mask); free(cidr); } } } setting_pgw = config_lookup(&cfg, PGW_CONFIG_STRING_PGW_CONFIG); if(setting_pgw != NULL) { subsetting = config_setting_get_member (setting_pgw, SGW_CONFIG_STRING_NETWORK_INTERFACES_CONFIG); if(subsetting != NULL) { if( ( config_setting_lookup_string(subsetting, PGW_CONFIG_STRING_PGW_INTERFACE_NAME_FOR_S5_S8, (const char **)&pgw_interface_name_for_S5_S8) && config_setting_lookup_string(subsetting, PGW_CONFIG_STRING_PGW_IPV4_ADDRESS_FOR_S5_S8, (const char **)&pgw_ipv4_address_for_S5_S8) && config_setting_lookup_string(subsetting, PGW_CONFIG_STRING_PGW_INTERFACE_NAME_FOR_SGI, (const char **)&pgw_interface_name_for_SGI) && config_setting_lookup_string(subsetting, PGW_CONFIG_STRING_PGW_IPV4_ADDR_FOR_SGI, (const char **)&pgw_ipv4_address_for_SGI) ) ) { config_pP->pgw_config.ipv4.pgw_interface_name_for_S5_S8 = strdup(pgw_interface_name_for_S5_S8); cidr = strdup(pgw_ipv4_address_for_S5_S8); address = strtok(cidr, "/"); mask = strtok(NULL, "/"); IPV4_STR_ADDR_TO_INT_NWBO ( address, config_pP->pgw_config.ipv4.pgw_ipv4_address_for_S5_S8, "BAD IP ADDRESS FORMAT FOR S5_S8 !\n" ) config_pP->pgw_config.ipv4.pgw_ip_netmask_for_S5_S8 = atoi(mask); free(cidr); config_pP->pgw_config.ipv4.pgw_interface_name_for_SGI = strdup(pgw_interface_name_for_SGI); cidr = strdup(pgw_ipv4_address_for_SGI); address = strtok(cidr, "/"); mask = strtok(NULL, "/"); IPV4_STR_ADDR_TO_INT_NWBO ( address, config_pP->pgw_config.ipv4.pgw_ipv4_address_for_SGI, "BAD IP ADDRESS FORMAT FOR SGI !\n" ) config_pP->pgw_config.ipv4.pgw_ip_netmask_for_SGI = atoi(mask); free(cidr); } } subsetting = config_setting_get_member (setting_pgw, PGW_CONFIG_STRING_IP_ADDRESS_POOL); if(subsetting != NULL) { sub2setting = config_setting_get_member (subsetting, PGW_CONFIG_STRING_IPV4_ADDRESS_LIST); if(sub2setting != NULL) { num = config_setting_length(sub2setting); for (i = 0; i < num; i++) { astring = config_setting_get_string_elem(sub2setting,i); if (astring != NULL) { trim(astring, strlen(astring)+1); if (inet_pton(AF_INET, astring, buf_in_addr) < 1) { // failure, test if there is a range specified in the string atoken = strtok(astring, PGW_CONFIG_STRING_IP_ADDRESS_RANGE_DELIMITERS); if (inet_pton(AF_INET, astring, buf_in_addr) == 1) { memcpy (&addr_start, buf_in_addr, sizeof(struct in_addr)); // valid address atoken2 = strtok(NULL, PGW_CONFIG_STRING_IP_ADDRESS_RANGE_DELIMITERS); if (inet_pton(AF_INET, atoken2, buf_in_addr) == 1) { memcpy (&addr_end, buf_in_addr, sizeof(struct in_addr)); // valid address for (jh = ntohl(addr_start.s_addr); jh <= ntohl(addr_end.s_addr); jh++) { DevAssert(PGW_MAX_ALLOCATED_PDN_ADDRESSES > config_pP->pgw_config.pool_pdn_addresses.num_ipv4_addresses); jn = htonl(jh); if (IN_CLASSA(addr_start.s_addr)) { if ((jh & 0xFF) && (jh & 0xFF) != 0xFF) { config_pP->pgw_config.pool_pdn_addresses.ipv4_addresses[config_pP->pgw_config.pool_pdn_addresses.num_ipv4_addresses++].s_addr = jn; } } else if (IN_CLASSB(addr_start.s_addr)) { if ((jh & 0xFF) && (jh & 0xFF) != 0xFF) { config_pP->pgw_config.pool_pdn_addresses.ipv4_addresses[config_pP->pgw_config.pool_pdn_addresses.num_ipv4_addresses++].s_addr = jn; } } else if (IN_CLASSC(addr_start.s_addr)) { if ((jh & 0xFF) && (jh & 0xFF) != 0xFF) { config_pP->pgw_config.pool_pdn_addresses.ipv4_addresses[config_pP->pgw_config.pool_pdn_addresses.num_ipv4_addresses++].s_addr = jn; } } else { printf("ERROR ON ADDRESS CLASS %d.%d.%d.%d\n", NIPADDR(jn)); } } } } } else { DevAssert(PGW_MAX_ALLOCATED_PDN_ADDRESSES > config_pP->pgw_config.pool_pdn_addresses.num_ipv4_addresses); memcpy (&addr_start, buf_in_addr, sizeof(struct in_addr)); config_pP->pgw_config.pool_pdn_addresses.ipv4_addresses[config_pP->pgw_config.pool_pdn_addresses.num_ipv4_addresses++].s_addr = addr_start.s_addr; } } } } sub2setting = config_setting_get_member (subsetting, PGW_CONFIG_STRING_IPV6_ADDRESS_LIST); if(sub2setting != NULL) { num = config_setting_length(sub2setting); for (i = 0; i < num; i++) { astring = config_setting_get_string_elem(sub2setting,i); if (astring != NULL) { trim(astring, strlen(astring)+1); if (inet_pton(AF_INET6, astring, buf_in6_addr) < 1) { // failure, test if there is a range specified in the string atoken = strtok(astring, PGW_CONFIG_STRING_IPV6_PREFIX_DELIMITER); if (inet_pton(AF_INET6, astring, buf_in6_addr) == 1) { atoken2 = strtok(NULL, PGW_CONFIG_STRING_IPV6_PREFIX_DELIMITER); prefix_mask = atoi(atoken2); // arbitrary values DevAssert((prefix_mask < 128) && (prefix_mask >= 64)); memcpy (&addr6_start, buf_in6_addr, sizeof(struct in6_addr)); memcpy (&addr6_mask, buf_in6_addr, sizeof(struct in6_addr)); sgw_ipv6_mask_in6_addr(&addr6_mask, prefix_mask); if (memcmp(&addr6_start, &addr6_mask, sizeof(struct in6_addr)) != 0) { AssertFatal(0, "BAD IPV6 ADDR CONFIG/MASK PAIRING %s/%d\n", astring, prefix_mask); } counter64 = 0xFFFFFFFFFFFFFFFF >> prefix_mask; // address Prefix_mask/0..0 not valid do { addr6_start.s6_addr32[3] = addr6_start.s6_addr32[3] + htonl(1); if (addr6_start.s6_addr32[3] == 0) { addr6_start.s6_addr32[2] = addr6_start.s6_addr32[2] + htonl(1); if (addr6_start.s6_addr32[2] == 0) { // should not happen since mask is no less than 64 addr6_start.s6_addr32[1] = addr6_start.s6_addr32[1] + htonl(1); if (addr6_start.s6_addr32[1] == 0) { addr6_start.s6_addr32[0] = addr6_start.s6_addr32[0] + htonl(1); } } } memcpy (&config_pP->pgw_config.pool_pdn_addresses.ipv6_addresses[config_pP->pgw_config.pool_pdn_addresses.num_ipv6_addresses++], &addr6_start, sizeof(struct in6_addr)); counter64 = counter64 - 1; } while (counter64 > 0); } } else {
static void dx_reload_cfg() { int i, j; const char *s; config_setting_t *dxs = dxcfg_lookup("dx", CFG_REQUIRED); assert(config_setting_type(dxs) == CONFIG_TYPE_LIST); const config_setting_t *dxe; for (i=0; (dxe = config_setting_get_elem(dxs, i)) != NULL; i++) { assert(config_setting_type(dxe) == CONFIG_TYPE_GROUP); } int _dx_list_len = i-1; lprintf("%d dx entries\n", _dx_list_len); dx_t *_dx_list = (dx_t *) kiwi_malloc("dx_list", (_dx_list_len+1) * sizeof(dx_t)); float f = 0; dx_t *dxp; for (i=0, dxp = _dx_list; i < _dx_list_len; i++, dxp++) { dxe = config_setting_get_elem(dxs, i); config_setting_t *e; assert((e = config_setting_get_member(dxe, "e")) != NULL); assert(config_setting_type(e) == CONFIG_TYPE_LIST); assert((dxp->freq = (float) config_setting_get_float_elem(e, 0)) != 0); if (dxp->freq < f) lprintf(">>>> DX: entry with freq %.2f < current freq %.2f\n", dxp->freq, f); else f = dxp->freq; assert((s = config_setting_get_string_elem(e, 1)) != NULL); dxcfg_mode(dxp, s); assert((s = config_setting_get_string_elem(e, 2)) != NULL); dxp->ident = str_encode((char *) s); if ((s = config_setting_get_string_elem(e, 3)) == NULL) { dxp->notes = NULL; } else { dxp->notes = str_encode((char *) s); } config_setting_t *flags; const char *flag; if ((flags = config_setting_get_member(dxe, "f")) != NULL) { if (config_setting_type(flags) == CONFIG_TYPE_ARRAY) { for (j=0; j < config_setting_length(flags); j++) { assert((flag = config_setting_get_string_elem(flags, j)) != NULL); dxcfg_flag(dxp, flag); } } else { assert((flag = config_setting_get_string(flags)) != NULL); dxcfg_flag(dxp, flag); } } config_setting_t *offset; if ((offset = config_setting_get_member(dxe, "o")) != NULL) { if (config_setting_type(offset) == CONFIG_TYPE_ARRAY) { assert((dxp->low_cut = (float) config_setting_get_int_elem(offset, 0)) != 0); assert((dxp->high_cut = (float) config_setting_get_int_elem(offset, 1)) != 0); } else { assert((dxp->offset = (float) config_setting_get_int(offset)) != 0); } } //printf("dxe %d f %.2f notes-%c off %.0f,%.0f\n", i, dxp->freq, dxp->notes? 'Y':'N', dxp->offset, dxp->high_cut); } switch_dx_list(_dx_list, _dx_list_len); // convert to json printf("### converting dx list to json\n"); dx_save_as_json(); }
int chkFreq(char *user, long long freq2chk, int mode){ // look through settings in conf file until an OK is found // returns on first matching rule // remove //// for debug fprintf sem_wait(&cfgsem); char grpname[31]; char grpmembers[41]; int n, n1, n2; int memberscount; int groupnamescount; char rulemode[5]; int modeOK = 1; int rulecount; float freq; freq = freq2chk * .000001; ////fprintf(stderr,"checkfreq:%lld freq:%f\n",freq2chk, freq); if (txcfg == TXNONE) { sem_post(&cfgsem); return 1; } if (txcfg == TXALL) { sem_post(&cfgsem); return 0; } config_setting_t *groupnames= NULL; config_setting_t *members= NULL; config_setting_t *rules= NULL; config_setting_t *rule= NULL; groupnames = config_lookup(&cfg, "groupnames"); if (!groupnames){ fprintf(stderr, "Conf File Error - %s%s%s\n", "Your ",share_config_file, " is missing a groupnames= [\"txgroup1\"]setting!!\n TX is disabled" ); sem_post(&cfgsem); return 2; } groupnamescount = config_setting_length(groupnames); for (n = 0; n < groupnamescount; n++) { // Look through these groupnames_members and see if our user is a member strncpy(grpname,config_setting_get_string_elem(groupnames, n),20); ////fprintf(stderr,"Groupname:%d of %d %s\n",n, groupnamescount, grpname); strcpy( grpmembers,grpname); strcat( grpmembers,"_members"); members = config_lookup(&cfg, grpmembers); if (!members){ fprintf(stderr, "Conf File Error - %s%s%s\n", "Your ",share_config_file, " is missing a groupname_members= [\"member1\",\"member2\"]setting!!\n" ); }else{ memberscount = config_setting_length(members); for (n1 = 0; n1 < memberscount; n1++) { ////fprintf(stderr," %s %d of %d %s\n",grpmembers, n1, memberscount, config_setting_get_string_elem(members, n1)); if (strcmp(user,config_setting_get_string_elem(members, n1)) == 0 ){ //our user is a member of this group ////fprintf(stderr, " %s is a member of %s\n",config_setting_get_string_elem(members, n1),grpname); rules = config_lookup(&cfg, grpname); if (!rules){ fprintf(stderr, "Conf File Error - %s%s%s%s%s", "Your ",share_config_file, " is missing a set of rules for ",grpname, "= (\n (\"mode\",statfreq,endfreq )\n);\n"); }else{ // look through each rule and if it matches then we can TX rulecount = config_setting_length(rules); ////fprintf(stderr,"Rule count for %s = %d\n",grpname, rulecount); for (n2 = 0; n2 < rulecount; n2++) { rule = config_setting_get_elem (rules,n2); if (!rule || config_setting_length(rule) != 3){ fprintf(stderr, "Conf File Error - %s%s%s%s%s%d%s", "Your ",share_config_file, " is misconfigured for rulegroup ",grpname, " Rule Number ",n2," has a problem\n"); sem_post(&cfgsem); return 4; }else{ //Check this rule // Do mode first Kind of long but we wat to allow users to write modes by name and not int in conf file modeOK = 1; // set to nomatch first strncpy(rulemode,config_setting_get_string_elem(rule,0),4); //mode is max of 4 chars if(strcmp("*",rulemode) == 0){ // * any mode is OK modeOK = 0; }else if(mode == LSB && strcmp("SSB",rulemode) == 0 ){ modeOK = 0; }else if(mode == USB && strcmp("SSB",rulemode) == 0 ){ modeOK = 0; }else if(mode == DSB && strcmp("SSB",rulemode) == 0 ){ modeOK = 0; }else if(mode == CWL && strcmp("CW",rulemode) == 0 ){ modeOK = 0; }else if(mode == CWU && strcmp("CW",rulemode) == 0 ){ modeOK = 0; }else if(mode == FMN && strcmp("FM",rulemode) == 0 ){ modeOK = 0; }else if(mode == AM && strcmp("AM",rulemode) == 0 ){ modeOK = 0; }else if(mode == DIGU && strcmp("DIG",rulemode) == 0 ){ modeOK = 0; }else if(mode == SPEC && strcmp("SPEC",rulemode) == 0 ){ modeOK = 0; }else if(mode == DIGL && strcmp("DIG",rulemode) == 0 ){ modeOK = 0; }else if(mode == SAM && strcmp("SAM",rulemode) == 0 ){ modeOK = 0; }else if(mode == DRM && strcmp("DRM",rulemode) == 0 ){ modeOK = 0; } ////fprintf(stderr," %s rule %d 0f %d modeOK:%d myfreq:%f rulestart:%f ruleend:%f ", grpname, n2, rulecount, modeOK, freq,config_setting_get_float_elem(rule,1),config_setting_get_float_elem(rule,2) ); if ( modeOK==0 && config_setting_get_float_elem(rule,1) <= freq && config_setting_get_float_elem(rule,2) >= freq ){ ////fprintf(stderr," Pass\n"); sem_post(&cfgsem); return 0; // good to TX }else{ ////fprintf(stderr," Fail\n"); } } } } }else{ ////fprintf(stderr, " %s is NOT a member of %s\n",config_setting_get_string_elem(members, n1),grpname); } } } } sem_post(&cfgsem); return 1; }
int config_get_services(config_t *config,service ***final_services){ config_setting_t *cs_services=NULL; if((cs_services=config_lookup(config,"services"))==NULL){ return 1; } int service_count=config_setting_length(cs_services); service **services=NULL; services=malloc((service_count+1)*sizeof(service *)); int services_len=0; for(int n=0;n<service_count;n++){ //printf("service: %d\n",n); config_setting_t *cs_service=NULL; if((cs_service=config_setting_get_elem(cs_services,n))==NULL){ //printf("failed to retrieve service\n"); continue; } int enabled=0; if(config_setting_lookup_bool(cs_service,"enabled",&enabled)){ //printf(" enabled: %s\n",enabled?"true":"false"); if(enabled==0){ continue; } } config_setting_t *cs_host=NULL; if((cs_host=config_setting_get_member(cs_service,"host"))==NULL){ continue; } char *host=NULL; host=strdup(config_setting_get_string(cs_host)); if(host==NULL){ printf("failed to retrieve host\n"); continue; } config_setting_t *cs_port=NULL; if((cs_port=config_setting_get_member(cs_service,"port"))==NULL){ free(host); continue; } char *port=NULL; switch(config_setting_type(cs_port)){ case CONFIG_TYPE_INT: port=calloc(16,sizeof(*port)); sprintf(port,"%lu",config_setting_get_int(cs_port)); break; case CONFIG_TYPE_STRING: port=strdup(config_setting_get_string(cs_port)); break; } if(port==NULL){ printf("failed to retrieve port\n"); free(host); continue; } config_setting_t *cs_names=NULL; if((cs_names=config_setting_get_member(cs_service,"names"))==NULL){ free(host); free(port); continue; } int name_count=config_setting_length(cs_names); char **names=malloc((name_count+1)*sizeof(*names)); int names_len=0; for(int ni=0;ni<name_count;++ni){ const char *name=config_setting_get_string_elem(cs_names,ni); if(name!=NULL && strlen(name)>0){ names[names_len]=strdup(name); //printf(" \"%s\"\n",names[names_len]); names_len++; } } names[names_len]=NULL; services[services_len]=malloc(sizeof(service)); services[services_len]->host=host; services[services_len]->port=port; services[services_len]->names=names; services_len++; } services[services_len]=NULL; *final_services=services; return 0; }
int centernode_config (centernode_t *cn) { const char *tmp = 0; config_setting_t *item = 0; #define CONFIGITEM(x, config, path) \ do {\ if ((item = config_lookup(config, path)) == 0) {\ fprintf(stderr, "Not found configuration item: [%s].\n", path);\ return -1;\ }\ if ((tmp = config_setting_get_string(item))) {\ memset(x, 0, sizeof(x));\ memcpy(x, tmp, strlen(tmp));\ }\ } while (0) CONFIGITEM(cn->mongoString,cn->config, "system.mongo.string"); CONFIGITEM(cn->nodeid, cn->config, "system.node.id"); CONFIGITEM(cn->homepath, cn->config, "system.node.home"); CONFIGITEM(cn->dbhost, cn->config, "system.db.host"); CONFIGITEM(cn->dbname, cn->config, "system.db.name"); CONFIGITEM(cn->dbuser, cn->config, "system.db.username"); CONFIGITEM(cn->dbpasswd, cn->config, "system.db.passwd"); CONFIGITEM(cn->rdb_host, cn->config, "system.db.redis.host"); CONFIGITEM(cn->rdb_pswd, cn->config, "system.db.redis.password"); #ifdef REDISBAK CONFIGITEM(cn->rdb_bakhost, cn->config, "system.db.redisbak.host"); CONFIGITEM(cn->rdb_bakpswd, cn->config, "system.db.redisbak.password"); #endif #undef CONFIGITEM #define CONFIGITEM(x, config, path) \ do {\ if (!(item = config_lookup(config, path))) {\ fprintf(stderr, "Not found configuration item: [%s].\n", path);\ return -1;\ }\ x = config_setting_get_int(item);\ } while (0) CONFIGITEM(cn->threads, cn->config, "system.node.threads"); CONFIGITEM(cn->syncdelay, cn->config, "system.node.sync-cycle"); CONFIGITEM(cn->dbport, cn->config, "system.db.port"); CONFIGITEM(cn->rdb_port, cn->config, "system.db.redis.port"); #ifdef REDISBAK CONFIGITEM(cn->rdb_bakport, cn->config, "system.db.redisbak.port"); #endif item = config_lookup(cn->config, "system.node.address"); if (!item) { fprintf(stderr, "Not found configuration item: [system.node.address].\n"); return -1; } for (cn->local_num=0; cn->local_num<config_setting_length(item) && cn->local_num<6; ++cn->local_num) { config_setting_t *p = config_setting_get_elem(item, cn->local_num); cn->local[cn->local_num].port = config_setting_get_int_elem(p, 1); cn->local[cn->local_num].isp = config_setting_get_int_elem(p, 2); if ((tmp = config_setting_get_string_elem(p, 0))) strncpy(cn->local[cn->local_num].host, tmp, sizeof(cn->local[cn->local_num].host)); } return 0; }
/** * Load ip-mask array. * @param[in] cfg Config section. * @param[in] option Option name. * @param[in,out] array Resulting array. * @return Zero on success. */ static int load_ip_mask_list(const config_setting_t *cfg, const char *option, UT_array *array) { config_setting_t *cfg_list = config_setting_get_member(cfg, option); if (!cfg_list) { ZERO_LOG(LOG_ERR, "config: missing %s entry", option); return 0; } if (config_setting_type(cfg_list) != CONFIG_TYPE_LIST) { ZERO_LOG(LOG_ERR, "config: invalid %s entry", option); return -1; } int count = config_setting_length(cfg_list); if (0 >= count) { return 0; } utarray_init(array, &ut_ip_range_icd); for (int i = 0; i < count; i++) { struct ip_range range; const char *entry = config_setting_get_string_elem(cfg_list, i); if (!entry) { ZERO_LOG(LOG_ERR, "config: failed to get next %s record", option); continue; } char ip_str[INET_ADDRSTRLEN]; const char *cidr_pos = strchr(entry, '/'); // we search for CIDR, and make sure, that ip part is not bigger than allowed size if (cidr_pos && ((size_t)(cidr_pos - entry) < sizeof(ip_str))) { strncpy(ip_str, entry, cidr_pos - entry); ip_str[cidr_pos - entry] = '\0'; struct in_addr ip_addr; if (0 < inet_pton(AF_INET, ip_str, &ip_addr)) { u_long cidr = strtoul(cidr_pos + 1, NULL, 10); if (cidr != ULONG_MAX && cidr <= 32) { range.ip_start = ntohl(ip_addr.s_addr); range.ip_end = IP_RANGE_END(range.ip_start, cidr); utarray_push_back(array, &range); continue; } } } // if we here, then entry is invalid ZERO_LOG(LOG_ERR, "config: invalid %s item: %s", option, entry); utarray_done(array); return -1; } utarray_sort(array, ip_range_cmp); return 0; }
static int processCommand(void *event_header, void *event) { int count = 0; int entry_count = 0; int total_root_entries = 0; int total_child_entries = 0; config_setting_t *config_root = NULL; config_setting_t *config_child = NULL; config_setting_t *config_entry = NULL; const char *current_header = NULL; const char *current_event = NULL; int int_setting = 0; int status_file; char status_file_path[MSQ_SIZE]; config_root = config_root_setting(&config); total_root_entries = config_setting_length(config_root); pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL); pthread_mutex_lock(&lockConfig); for(count = 0; count < total_root_entries; count++) { config_child = config_setting_get_elem(config_root, count); if(!config_setting_is_group(config_child) || !config_setting_lookup_bool(config_child, "register", &int_setting) || int_setting == 0 || !(config_entry = config_setting_get_member(config_child, "header")) || (current_header = config_setting_get_string_elem(config_entry, common_data.diff_commands)) == NULL || strcmp(current_header, (char *)event_header) != 0) continue; current_header = config_setting_name(config_child); total_child_entries = config_setting_length(config_child); for(entry_count = 0; entry_count < total_child_entries; entry_count++) { config_entry = config_setting_get_elem(config_child, entry_count); if((current_event = config_setting_get_string_elem(config_entry, common_data.diff_commands)) == 0 || strcmp(current_event, (char *)event) != 0) continue; snprintf(status_file_path, MAX_PATH_LENGTH, "%s/%s.%s", TEMPLOCATION, PROGRAM_NAME, current_header); if((status_file = open(status_file_path, O_RDWR|O_CREAT|O_CLOEXEC, LOCKMODE)) < 0) { pthread_mutex_unlock(&lockConfig); pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); return EXIT_FAILURE; } current_event = config_setting_name(config_entry); ftruncate(status_file, 0); write(status_file, current_event, strlen(current_event)); close(status_file); statusInfo.update(current_header, current_event); syslog(LOG_DEBUG, "Status update event (header): %s (%s)", current_event, current_header); pthread_mutex_unlock(&lockConfig); pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); return EXIT_SUCCESS; } } pthread_mutex_unlock(&lockConfig); pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); return EXIT_SUCCESS; } /* serial_process_ascii */
void configure_midi() { int note_channel = 0; config_lookup_int(&app_config, CFG_DEVICES_MIDI_CONTROLLER_CHANNEL, &controller_channel); config_lookup_int(&app_config, CFG_DEVICES_MIDI_NOTE_CHANNEL, ¬e_channel); synth_model_set_midi_channel(&synth_model, note_channel); config_setting_t *setting_devices_midi_input = config_lookup(&app_config, CFG_DEVICES_MIDI_INPUT); if (setting_devices_midi_input == NULL) { LOG_ERROR("Missing midi input devices in config"); exit(EXIT_FAILURE); } const char* midi_device_names[MAX_MIDI_DEVICES]; int midi_device_count = config_setting_length(setting_devices_midi_input); if (midi_device_count < 0 || midi_device_count > MAX_MIDI_DEVICES) { LOG_ERROR("Invalid number of midi devices %d - should be between 1 and %d", midi_device_count, MAX_MIDI_DEVICES); exit(EXIT_FAILURE); } for (int i = 0; i < midi_device_count; i++) { midi_device_names[i] = config_setting_get_string_elem(setting_devices_midi_input, i); } if (midi_initialise(midi_device_count, midi_device_names) < 0) { exit(EXIT_FAILURE); } if (!synth_controllers_initialise(controller_channel, config_lookup(&app_config, CFG_CONTROLLERS))) { exit(EXIT_FAILURE); } if (mod_matrix_controller_initialise(config_lookup(&app_config, CFG_MOD_MATRIX_CONTROLLER), config_lookup(&patch_config, CFG_MOD_MATRIX_CONTROLLER)) != RESULT_OK) { exit(EXIT_FAILURE); } synth_controllers_load(SETTINGS_FILE, &synth_model); config_setting_t *setting_sysex_init_message = config_lookup(&app_config, CFG_SYSEX_INIT); if (setting_sysex_init_message != NULL) { int message_len = config_setting_length(setting_sysex_init_message); char *message_bytes = alloca(message_len); for (int i = 0; i < message_len; i++) { message_bytes[i] = config_setting_get_int_elem(setting_sysex_init_message, i); } midi_send_sysex(message_bytes, message_len); } }
static int yubikey_auth_core(myConf_t *myConf, REQUEST *request) { int passLen = 0, session = 0, counter = 0, i = 0; MD5_CTX ctx; int result = 0; char *filename = "/usr/local/etc/raddb/yubico/users"; //get password by removing the last 32 characters of the password if (strlen(request->password->vp_strvalue) <= 32) { DEBUG("rlm_yubikey: Password too short."); return RLM_MODULE_REJECT; } passLen = strlen(request->password->vp_strvalue) - 32; strncpy(myConf->pass, request->password->vp_strvalue, passLen); myConf->pass[passLen] = '\0'; strncpy(myConf->token, request->password->vp_strvalue + passLen, 32); myConf->token[32] = '\0'; //md5 stuff MD5Init(&ctx); DEBUG("rlm_yubikey: length: %d, string: %s", passLen, myConf->pass); MD5Update(&ctx, (unsigned char *)myConf->pass, passLen); MD5Final(&ctx); MD5toString(&ctx, myConf->md5ComputedString); myConf->md5ComputedString[32] = '\0'; DEBUG("rlm_yubikey: MD5string of your pass: %s", myConf->md5ComputedString); DEBUG("rlm_yubikey: Username: %s", request->username->vp_strvalue); //read file result = config_read_file(&(myConf->config), filename); if (result != CONFIG_TRUE) { DEBUG("rlm_yubikey: Failed to parse configuration file: config_read_file (&config, filename);"); DEBUG("config_error_text()= %s and config_error_line()=%d", config_error_text(&(myConf->config)), config_error_line(&(myConf->config))); return RLM_MODULE_FAIL; } //parse file myConf->config_setting = config_lookup(&(myConf->config), USERS_PATH); if (myConf->config_setting == NULL) { DEBUG("rlm_yubikey: Failed to parse configuration file: config_lookup failed to find the users node"); return RLM_MODULE_FAIL; } //go through the list of users for (i = 0; i < config_setting_length(myConf->config_setting); i++) { DEBUG("Trying i: %d", i); config_setting_t *tmpSetting = NULL; tmpSetting = config_setting_get_elem(myConf->config_setting, i); if (tmpSetting == NULL) { DEBUG("rlm_yubikey: Failed to parse configuration file: config_setting_get_elem(config_setting,i);"); return RLM_MODULE_FAIL; } if ((config_setting_get_string_elem(tmpSetting, 0) == NULL) || (config_setting_get_string_elem(tmpSetting, 1) == NULL) || (config_setting_get_string_elem(tmpSetting, 2) == NULL)) { DEBUG("rlm_yubikey: Failed to parse configuration file while reading the username/password/aeskey triplet "); return RLM_MODULE_FAIL; } //check usernames are equal if (strcmp(request->username->vp_strvalue, config_setting_get_string_elem(tmpSetting, 0)) != 0) { //users do not match. No need to debug this //Go to next iteration continue; } //check passwords are equal if (strcmp(myConf->md5ComputedString, config_setting_get_string_elem(tmpSetting, 1)) != 0) { //passwords do not match. We debug DEBUG("rlm_yubikey: Password does not match for user %s", request->username->vp_strvalue); //Go to next iteration continue; } //check aes stuff - mostly copied from the ykdebug.c that comes with the low-level yubikey library uint8_t buf[128]; const char *aeskey = config_setting_get_string_elem(tmpSetting, 2); char *token = myConf->token; uint8_t key[YUBIKEY_KEY_SIZE]; yubikey_token_st tok; yubikey_modhex_decode((char*) key, token, YUBIKEY_KEY_SIZE); DEBUG("rlm_yubikey: aeskey: %s", aeskey); yubikey_hex_decode((char*) key, aeskey, YUBIKEY_KEY_SIZE); /* Pack up dynamic password, decrypt it and verify checksum */ yubikey_parse((uint8_t*) token, key, &tok); DEBUG("rlm_yubikey: Struct:"); size_t i; char *tmp = (char*) malloc(1024); for (i = 0; i < YUBIKEY_UID_SIZE; i++) { sprintf(tmp + i, "%c ", tok.uid[i] & 0xFF); } tmp[YUBIKEY_UID_SIZE + i] = 0; DEBUG("rlm_yubikey: uid:%s", tmp); free(tmp); DEBUG("rlm_yubikey: counter: %d (0x%04x)", tok.ctr, tok.ctr); DEBUG("rlm_yubikey: timestamp (low): %d (0x%04x)", tok.tstpl, tok.tstpl); DEBUG("rlm_yubikey: timestamp (high): %d (0x%02x)", tok.tstph, tok.tstph); DEBUG("rlm_yubikey: session use: %d (0x%02x)", tok.use, tok.use); DEBUG("rlm_yubikey: random: %d (0x%02x)", tok.rnd, tok.rnd); DEBUG("rlm_yubikey: crc: %d (0x%04x)", tok.crc, tok.crc); DEBUG("rlm_yubikey: Derived:"); DEBUG("rlm_yubikey: cleaned counter: %d (0x%04x)",yubikey_counter(tok.ctr), yubikey_counter(tok.ctr)); yubikey_modhex_encode((char*) buf, (char*) tok.uid, YUBIKEY_UID_SIZE); DEBUG("rlm_yubikey: modhex uid: %s", buf); DEBUG("rlm_yubikey: triggered by caps lock: %s", yubikey_capslock(tok.ctr) ? "yes" : "no"); DEBUG("rlm_yubikey: crc: %04X", yubikey_crc16((void*) & tok, YUBIKEY_KEY_SIZE)); DEBUG("rlm_yubikey: crc check: "); if (yubikey_crc_ok_p((uint8_t*) & tok)) { DEBUG("rlm_yubikey: ok"); char *tmppath = KEYS_PATH; char *path = (char*) malloc(strlen(tmppath) + 32 + 1); strcpy(path, tmppath); strcat(path, aeskey); myConf->config_setting = config_lookup(&(myConf->config), path); if (myConf->config_setting == NULL) { DEBUG("rlm_yubikey: Error parsing file: %s not found", path); return RLM_MODULE_FAIL; } //checking counter and session and update them if necessary counter = config_setting_get_int_elem(myConf->config_setting, 0); session = config_setting_get_int_elem(myConf->config_setting, 1); DEBUG("rlm_yubikey: Read counter: %d, session: %d", counter, session); if ((tok.ctr < counter)||((tok.ctr == counter) && (tok.use <= session))) { DEBUG("rlm_yubikey: someone tried to login with an old generated hash"); return RLM_MODULE_REJECT; } //updating config file with counter and session config_setting_set_int_elem(myConf->config_setting, 0, tok.ctr); config_setting_set_int_elem(myConf->config_setting, 1, tok.use); DEBUG("rlm_yubikey: Written element: %ld", config_setting_get_int_elem(myConf->config_setting, 0)); DEBUG("rlm_yubikey: Written element: %ld", config_setting_get_int_elem(myConf->config_setting, 1)); if (CONFIG_FALSE == config_write_file(&(myConf->config), filename)) { DEBUG("rlm_yubikey: Failed to write the file."); return RLM_MODULE_FAIL; } return RLM_MODULE_OK; } DEBUG("rlm_yubikey: fail"); } DEBUG("rlm_yubikey: Authenticating with password %s", request->password->vp_strvalue); return RLM_MODULE_REJECT; }
/* * Loads a config file into memory */ int load_config(struct wmediumd *ctx, const char *file) { config_t cfg, *cf; const config_setting_t *ids; const config_setting_t *links; int count_ids, i; struct station *station; /*initialize the config file*/ cf = &cfg; config_init(cf); /*read the file*/ if (!config_read_file(cf, file)) { printf("Error loading file %s at line:%d, reason: %s\n", file, config_error_line(cf), config_error_text(cf)); config_destroy(cf); exit(EXIT_FAILURE); } ids = config_lookup(cf, "ifaces.ids"); count_ids = config_setting_length(ids); printf("#_if = %d\n", count_ids); /* Fill the mac_addr */ for (i = 0; i < count_ids; i++) { u8 addr[ETH_ALEN]; const char *str = config_setting_get_string_elem(ids, i); string_to_mac_address(str, addr); station = malloc(sizeof(*station)); if (!station) { fprintf(stderr, "Out of memory!\n"); exit(1); } station->index = i; memcpy(station->addr, addr, ETH_ALEN); memcpy(station->hwaddr, addr, ETH_ALEN); list_add_tail(&station->list, &ctx->stations); printf("Added station %d: " MAC_FMT "\n", i, MAC_ARGS(addr)); } ctx->num_stas = count_ids; /* create link quality matrix */ ctx->snr_matrix = calloc(sizeof(int), count_ids * count_ids); if (!ctx->snr_matrix) { fprintf(stderr, "Out of memory!\n"); exit(1); } /* set default snrs */ for (i = 0; i < count_ids * count_ids; i++) ctx->snr_matrix[i] = SNR_DEFAULT; links = config_lookup(cf, "ifaces.links"); for (i = 0; links && i < config_setting_length(links); i++) { config_setting_t *link; int start, end, snr; link = config_setting_get_elem(links, i); if (config_setting_length(link) != 3) { fprintf(stderr, "Invalid link: expected (int,int,int)\n"); continue; } start = config_setting_get_int_elem(link, 0); end = config_setting_get_int_elem(link, 1); snr = config_setting_get_int_elem(link, 2); if (start < 0 || start >= ctx->num_stas || end < 0 || end >= ctx->num_stas) { fprintf(stderr, "Invalid link [%d,%d,%d]: index out of range\n", start, end, snr); continue; } ctx->snr_matrix[ctx->num_stas * start + end] = snr; ctx->snr_matrix[ctx->num_stas * end + start] = snr; } config_destroy(cf); return EXIT_SUCCESS; }
struct node_parameters read_node_parameters(int node, char *scenario_file) { // string pointing to scenario file char scenario[100]; strcpy(scenario, "scenarios/"); strcat(scenario, scenario_file); config_t cfg; config_init(&cfg); // Read the file. If there is an error, report it and exit. if (!config_read_file(&cfg, scenario)) { printf("Error reading config file on line %i\n", config_error_line(&cfg)); config_destroy(&cfg); exit(1); } int tmpI; double tmpD; const char *tmpS; // scenario info struct for node struct node_parameters np = {}; char nodestr[100]; std::string node_num; std::stringstream out; out << node; node_num = out.str(); // lookup specific node strcpy(nodestr, "node"); strcat(nodestr, node_num.c_str()); config_setting_t *node_config = config_lookup(&cfg, nodestr); // read CORNET IP address for the node if (config_setting_lookup_string(node_config, "TARGET_IP", &tmpS)) strcpy(np.TARGET_IP, tmpS); else strcpy(np.TARGET_IP, "10.0.0.3"); // read CORNET IP address for the node if (config_setting_lookup_string(node_config, "CORNET_IP", &tmpS)) strcpy(np.CORNET_IP, tmpS); else strcpy(np.CORNET_IP, "192.168.1.12"); // read type of node if (config_setting_lookup_string(node_config, "type", &tmpS)) { // printf("\nNode type: %s\n", tmpS); if (strcmp(tmpS, "CR") == 0) { np.type = CR; np.cr_type = ecr; // If node is a CR, lookup whether is uses the ECR or python if (config_setting_lookup_string(node_config, "cr_type", &tmpS)) { if (strcmp(tmpS, "python") == 0) { np.cr_type = python; // python radios are specified by the "python_file" field in the // scenario file if (config_setting_lookup_string(node_config, "python_file", &tmpS)) { strcpy(np.python_file, tmpS); // check for optional command line arguments and add them to // np.arguments if found const config_setting_t *arguments; char path[100]; strcpy(path, nodestr); strcat(path, ".arguments"); arguments = config_lookup(&cfg, path); np.num_arguments = 0; if (arguments != NULL) { np.num_arguments = config_setting_length(arguments); for (int i = 0; i < np.num_arguments; i++) { tmpS = config_setting_get_string_elem(arguments, i); strcpy(np.arguments[i], tmpS); } } else printf("arguments not found\n"); } else { printf("A python radio requires a python file.\n"); } } // Possibly add more types later, but for now if not python, then radio // must be ECR-based // and the engine to use is specified by the "CE" field else { if (config_setting_lookup_string(node_config, "CE", &tmpS)) strcpy(np.CE, tmpS); else { printf( "Configuration of a node did not specify a cognitive engine"); exit(1); } } } } else if (strcmp(tmpS, "interferer") == 0) np.type = interferer; } // read all possible node settings if (config_setting_lookup_string(node_config, "CRTS_IP", &tmpS)) strcpy(np.CRTS_IP, tmpS); else strcpy(np.CRTS_IP, "10.0.0.2"); if (config_setting_lookup_int(node_config, "print_metrics", &tmpI)) np.print_metrics = (int)tmpI; if (config_setting_lookup_int(node_config, "log_phy_rx", &tmpI)) np.log_phy_rx = (int)tmpI; if (config_setting_lookup_int(node_config, "log_phy_tx", &tmpI)) np.log_phy_tx = (int)tmpI; if (config_setting_lookup_int(node_config, "log_net_rx", &tmpI)) np.log_net_rx = (int)tmpI; if (config_setting_lookup_string(node_config, "phy_rx_log_file", &tmpS)) strcpy(np.phy_rx_log_file, tmpS); if (config_setting_lookup_string(node_config, "phy_tx_log_file", &tmpS)) strcpy(np.phy_tx_log_file, tmpS); if (config_setting_lookup_string(node_config, "net_rx_log_file", &tmpS)) strcpy(np.net_rx_log_file, tmpS); if (config_setting_lookup_int(node_config, "generate_octave_logs", &tmpI)) np.generate_octave_logs = (int)tmpI; if (config_setting_lookup_int(node_config, "generate_python_logs", &tmpI)) np.generate_python_logs = (int)tmpI; if (config_setting_lookup_float(node_config, "ce_timeout_ms", &tmpD)) np.ce_timeout_ms = tmpD; if (config_setting_lookup_string(node_config, "duplex", &tmpS)) { if (!strcmp(tmpS, "FDD")) np.duplex = FDD; else if (!strcmp(tmpS, "TDD")) np.duplex = TDD; else if (!strcmp(tmpS, "HD")) np.duplex = HD; else np.duplex = FDD; } if (config_setting_lookup_float(node_config, "rx_freq", &tmpD)) np.rx_freq = tmpD; if (config_setting_lookup_float(node_config, "rx_rate", &tmpD)) np.rx_rate = tmpD; else np.rx_rate = 1e6; if (config_setting_lookup_float(node_config, "rx_gain", &tmpD)) np.rx_gain = tmpD; else np.rx_gain = 20.0; if (config_setting_lookup_int(node_config, "rx_subcarriers", &tmpI)) np.rx_subcarriers = (int)tmpI; else np.rx_subcarriers = 64; if (config_setting_lookup_string(node_config, "rx_subcarrier_alloc_method", &tmpS)) { // subcarrier allocation is being defined in a standard way if (!strcmp(tmpS, "standard")) { np.rx_subcarrier_alloc_method = STANDARD_SUBCARRIER_ALLOC; int rx_guard_subcarriers; int rx_central_nulls; int rx_pilot_freq; if (config_setting_lookup_int(node_config, "rx_guard_subcarriers", &tmpI)) rx_guard_subcarriers = tmpI; if (config_setting_lookup_int(node_config, "rx_central_nulls", &tmpI)) rx_central_nulls = tmpI; if (config_setting_lookup_int(node_config, "rx_pilot_freq", &tmpI)) rx_pilot_freq = tmpI; for (int i = 0; i < np.rx_subcarriers; i++) { // central band nulls if (i < rx_central_nulls / 2 || np.rx_subcarriers - i - 1 < rx_central_nulls / 2) np.rx_subcarrier_alloc[i] = OFDMFRAME_SCTYPE_NULL; // guard band nulls else if (i + 1 > np.rx_subcarriers / 2 - rx_guard_subcarriers && i < np.rx_subcarriers / 2 + rx_guard_subcarriers) np.rx_subcarrier_alloc[i] = OFDMFRAME_SCTYPE_NULL; // pilot subcarriers (based on distance from center) else if (abs((int)((float)np.rx_subcarriers / 2.0 - (float)i - 0.5)) % rx_pilot_freq == 0) np.rx_subcarrier_alloc[i] = OFDMFRAME_SCTYPE_PILOT; // data subcarriers else np.rx_subcarrier_alloc[i] = OFDMFRAME_SCTYPE_DATA; } } // subcarrier allocation is completely custom else if (!strcmp(tmpS, "custom")) { np.rx_subcarrier_alloc_method = CUSTOM_SUBCARRIER_ALLOC; config_setting_t *rx_subcarrier_alloc = config_setting_get_member(node_config, "rx_subcarrier_alloc"); char type_str[9] = "sc_type_"; char num_str[8] = "sc_num_"; char sc_type[16]; char sc_num[16]; int i = 1; int j = 0; int offset = np.rx_subcarriers / 2; sprintf(sc_type, "%s%d", type_str, i); // read in a custom initial subcarrier allocation while ( config_setting_lookup_string(rx_subcarrier_alloc, sc_type, &tmpS)) { // read the number of subcarriers into tmpI sprintf(sc_num, "%s%d", num_str, i); tmpI = 1; config_setting_lookup_int(rx_subcarrier_alloc, sc_num, &tmpI); // set the subcarrier type based on the number specified if (!strcmp(tmpS, "null")) { for (int k = 0; k < tmpI; k++) { if (j >= (np.rx_subcarriers) / 2) offset = -(np.rx_subcarriers / 2); np.rx_subcarrier_alloc[j + offset] = OFDMFRAME_SCTYPE_NULL; j++; } } if (!strcmp(tmpS, "pilot")) { for (int k = 0; k < tmpI; k++) { if (j >= (np.rx_subcarriers) / 2) offset = -(np.rx_subcarriers / 2); np.rx_subcarrier_alloc[j + offset] = OFDMFRAME_SCTYPE_PILOT; j++; } } if (!strcmp(tmpS, "data")) { for (int k = 0; k < tmpI; k++) { if (j >= (np.rx_subcarriers) / 2) offset = -(np.rx_subcarriers / 2); np.rx_subcarrier_alloc[j + offset] = OFDMFRAME_SCTYPE_DATA; j++; } } if (j > 2048) { printf("The number of subcarriers specified was too high!\n"); exit(1); } i++; sprintf(sc_type, "%s%d", type_str, i); } } else np.rx_subcarrier_alloc_method = LIQUID_DEFAULT_SUBCARRIER_ALLOC; } if (config_setting_lookup_int(node_config, "rx_cp_len", &tmpI)) np.rx_cp_len = (int)tmpI; else np.rx_cp_len = 16; if (config_setting_lookup_int(node_config, "rx_taper_len", &tmpI)) np.rx_taper_len = (int)tmpI; else np.rx_taper_len = 4; if (config_setting_lookup_float(node_config, "tx_freq", &tmpD)) np.tx_freq = tmpD; if (config_setting_lookup_float(node_config, "tx_rate", &tmpD)) np.tx_rate = tmpD; else np.rx_rate = 1e6; if (config_setting_lookup_float(node_config, "tx_gain_soft", &tmpD)) np.tx_gain_soft = tmpD; else np.tx_gain_soft = -12.0; if (config_setting_lookup_float(node_config, "tx_gain", &tmpD)) np.tx_gain = tmpD; else np.tx_gain = 20.0; if (config_setting_lookup_int(node_config, "tx_subcarriers", &tmpI)) np.tx_subcarriers = (int)tmpI; else np.tx_subcarriers = 64; if (config_setting_lookup_string(node_config, "tx_subcarrier_alloc_method", &tmpS)) { // subcarrier allocation is being defined in a standard way if (!strcmp(tmpS, "standard")) { np.tx_subcarrier_alloc_method = STANDARD_SUBCARRIER_ALLOC; int tx_guard_subcarriers; int tx_central_nulls; int tx_pilot_freq; if (config_setting_lookup_int(node_config, "tx_guard_subcarriers", &tmpI)) tx_guard_subcarriers = tmpI; if (config_setting_lookup_int(node_config, "tx_central_nulls", &tmpI)) tx_central_nulls = tmpI; if (config_setting_lookup_int(node_config, "tx_pilot_freq", &tmpI)) tx_pilot_freq = tmpI; for (int i = 0; i < np.tx_subcarriers; i++) { // central band nulls if (i < tx_central_nulls / 2 || np.tx_subcarriers - i - 1 < tx_central_nulls / 2) np.tx_subcarrier_alloc[i] = OFDMFRAME_SCTYPE_NULL; // guard band nulls else if (i + 1 > np.tx_subcarriers / 2 - tx_guard_subcarriers && i < np.tx_subcarriers / 2 + tx_guard_subcarriers) np.tx_subcarrier_alloc[i] = OFDMFRAME_SCTYPE_NULL; // pilot subcarriers else if (abs((int)((float)np.tx_subcarriers / 2.0 - (float)i - 0.5)) % tx_pilot_freq == 0) np.tx_subcarrier_alloc[i] = OFDMFRAME_SCTYPE_PILOT; // data subcarriers else np.tx_subcarrier_alloc[i] = OFDMFRAME_SCTYPE_DATA; } } // subcarrier allocation is completely custom else if (!strcmp(tmpS, "custom")) { np.tx_subcarrier_alloc_method = CUSTOM_SUBCARRIER_ALLOC; config_setting_t *tx_subcarrier_alloc = config_setting_get_member(node_config, "tx_subcarrier_alloc"); char type_str[9] = "sc_type_"; char num_str[8] = "sc_num_"; char sc_type[16]; char sc_num[16]; int i = 1; int j = 0; int offset = np.tx_subcarriers / 2; sprintf(sc_type, "%s%d", type_str, i); // read in a custom initial subcarrier allocation while ( config_setting_lookup_string(tx_subcarrier_alloc, sc_type, &tmpS)) { // read the number of subcarriers into tmpI sprintf(sc_num, "%s%d", num_str, i); tmpI = 1; config_setting_lookup_int(tx_subcarrier_alloc, sc_num, &tmpI); // set the subcarrier type based on the number specified if (!strcmp(tmpS, "null")) { for (int k = 0; k < tmpI; k++) { if (j >= (np.tx_subcarriers) / 2) offset = -(np.tx_subcarriers / 2); np.tx_subcarrier_alloc[j + offset] = OFDMFRAME_SCTYPE_NULL; j++; } } if (!strcmp(tmpS, "pilot")) { for (int k = 0; k < tmpI; k++) { if (j >= (np.tx_subcarriers) / 2) offset = -(np.tx_subcarriers / 2); np.tx_subcarrier_alloc[j + offset] = OFDMFRAME_SCTYPE_PILOT; j++; } } if (!strcmp(tmpS, "data")) { for (int k = 0; k < tmpI; k++) { if (j >= (np.tx_subcarriers) / 2) offset = -(np.tx_subcarriers / 2); np.tx_subcarrier_alloc[j + offset] = OFDMFRAME_SCTYPE_DATA; j++; } } if (j > 2048) { printf("The number of subcarriers specified was too high!\n"); exit(1); } i++; sprintf(sc_type, "%s%d", type_str, i); } } else np.tx_subcarrier_alloc_method = LIQUID_DEFAULT_SUBCARRIER_ALLOC; } if (config_setting_lookup_int(node_config, "tx_cp_len", &tmpI)) np.tx_cp_len = (int)tmpI; else np.tx_cp_len = 16; if (config_setting_lookup_int(node_config, "tx_taper_len", &tmpI)) np.tx_taper_len = (int)tmpI; else np.tx_taper_len = 4; // default tx modulation is BPSK np.tx_modulation = LIQUID_MODEM_BPSK; if (config_setting_lookup_string(node_config, "tx_modulation", &tmpS)) { // Iterate through every liquid modulation scheme // and if the string matches, then assign that scheme. // See liquid soruce: src/modem/src/modem_utilities.c // for definition of modulation_types for (int k = 0; k < LIQUID_MODEM_NUM_SCHEMES; k++) { if (!strcmp(tmpS, modulation_types[k].name)) np.tx_modulation = modulation_types[k].scheme; } } // default tx CRC32 np.tx_crc = LIQUID_CRC_32; if (config_setting_lookup_string(node_config, "tx_crc", &tmpS)) { // Iterate through every liquid CRC // and if the string matches, then assign that CRC. // See liquid soruce: src/fec/src/crc.c // for definition of crc_scheme_str for (int k = 0; k < LIQUID_CRC_NUM_SCHEMES; k++) { if (!strcmp(tmpS, crc_scheme_str[k][0])) np.tx_crc = k; } } // default tx FEC0 is Hamming 12/8 np.tx_fec0 = LIQUID_FEC_HAMMING128; if (config_setting_lookup_string(node_config, "tx_fec0", &tmpS)) { // Iterate through every liquid FEC // and if the string matches, then assign that FEC. // See liquid soruce: src/fec/src/fec.c // for definition of fec_scheme_str for (int k = 0; k < LIQUID_FEC_NUM_SCHEMES; k++) { if (!strcmp(tmpS, fec_scheme_str[k][0])) np.tx_fec0 = k; } } // default rx FEC1 is none np.tx_fec1 = LIQUID_FEC_NONE; if (config_setting_lookup_string(node_config, "tx_fec1", &tmpS)) { // Iterate through every liquid FEC // and if the string matches, then assign that FEC. // See liquid soruce: src/fec/src/fec.c // for definition of fec_scheme_str for (int k = 0; k < LIQUID_FEC_NUM_SCHEMES; k++) { if (!strcmp(tmpS, fec_scheme_str[k][0])) np.tx_fec1 = k; } } if (config_setting_lookup_float(node_config, "tx_delay_us", &tmpD)) np.tx_delay_us = tmpD; else np.tx_delay_us = 1e3; if (config_setting_lookup_string(node_config, "interference_type", &tmpS)) { if (!strcmp(tmpS, "CW")) np.interference_type = CW; if (!strcmp(tmpS, "AWGN")) np.interference_type = NOISE; if (!strcmp(tmpS, "GMSK")) np.interference_type = GMSK; if (!strcmp(tmpS, "RRC")) np.interference_type = RRC; if (!strcmp(tmpS, "OFDM")) np.interference_type = OFDM; } if (config_setting_lookup_float(node_config, "period", &tmpD)) np.period = tmpD; if (config_setting_lookup_float(node_config, "duty_cycle", &tmpD)) np.duty_cycle = tmpD; // ====================================================== // process frequency hopping parameters // ====================================================== if (config_setting_lookup_string(node_config, "tx_freq_hop_type", &tmpS)) { if (!strcmp(tmpS, "NONE")) np.tx_freq_hop_type = NONE; if (!strcmp(tmpS, "ALTERNATING")) np.tx_freq_hop_type = ALTERNATING; if (!strcmp(tmpS, "SWEEP")) np.tx_freq_hop_type = SWEEP; if (!strcmp(tmpS, "RANDOM")) np.tx_freq_hop_type = RANDOM; } if (config_setting_lookup_float(node_config, "tx_freq_hop_min", &tmpD)) np.tx_freq_hop_min = tmpD; if (config_setting_lookup_float(node_config, "tx_freq_hop_max", &tmpD)) np.tx_freq_hop_max = tmpD; if (config_setting_lookup_float(node_config, "tx_freq_hop_dwell_time", &tmpD)) np.tx_freq_hop_dwell_time = tmpD; if (config_setting_lookup_float(node_config, "tx_freq_hop_increment", &tmpD)) np.tx_freq_hop_increment = tmpD; return np; }
/** * Loads group configuration from config file into memory. * @private */ static void read_config(void) { config_setting_t *groups = NULL; const char *config_filename = "conf/groups.conf"; // FIXME hardcoded name int group_count = 0; if (conf_read_file(&pc_group_config, config_filename)) return; groups = config_lookup(&pc_group_config, "groups"); if (groups != NULL) { GroupSettings *group_settings = NULL; DBIterator *iter = NULL; int i, loop = 0; group_count = config_setting_length(groups); for (i = 0; i < group_count; ++i) { int id = 0, level = 0; const char *groupname = NULL; int log_commands = 0; config_setting_t *group = config_setting_get_elem(groups, i); if (!config_setting_lookup_int(group, "id", &id)) { ShowConfigWarning(group, "pc_groups:read_config: \"groups\" list member #%d has undefined id, removing...", i); config_setting_remove_elem(groups, i); --i; --group_count; continue; } if (id2group(id) != NULL) { ShowConfigWarning(group, "pc_groups:read_config: duplicate group id %d, removing...", i); config_setting_remove_elem(groups, i); --i; --group_count; continue; } config_setting_lookup_int(group, "level", &level); config_setting_lookup_bool(group, "log_commands", &log_commands); if (!config_setting_lookup_string(group, "name", &groupname)) { char temp[20]; config_setting_t *name = NULL; snprintf(temp, sizeof(temp), "Group %d", id); if ((name = config_setting_add(group, "name", CONFIG_TYPE_STRING)) == NULL || !config_setting_set_string(name, temp)) { ShowError("pc_groups:read_config: failed to set missing group name, id=%d, skipping... (%s:%d)\n", id, config_setting_source_file(group), config_setting_source_line(group)); continue; } config_setting_lookup_string(group, "name", &groupname); // Retrieve the pointer } if (name2group(groupname) != NULL) { ShowConfigWarning(group, "pc_groups:read_config: duplicate group name %s, removing...", groupname); config_setting_remove_elem(groups, i); --i; --group_count; continue; } CREATE(group_settings, GroupSettings, 1); group_settings->id = id; group_settings->level = level; group_settings->name = groupname; group_settings->log_commands = (bool)log_commands; group_settings->inherit = config_setting_get_member(group, "inherit"); group_settings->commands = config_setting_get_member(group, "commands"); group_settings->permissions = config_setting_get_member(group, "permissions"); group_settings->inheritance_done = false; group_settings->root = group; group_settings->group_pos = i; strdb_put(pc_groupname_db, groupname, group_settings); idb_put(pc_group_db, id, group_settings); } group_count = config_setting_length(groups); // Save number of groups // Check if all commands and permissions exist iter = db_iterator(pc_group_db); for (group_settings = dbi_first(iter); dbi_exists(iter); group_settings = dbi_next(iter)) { config_setting_t *commands = group_settings->commands, *permissions = group_settings->permissions; int count = 0, j; // Make sure there is "commands" group if (commands == NULL) commands = group_settings->commands = config_setting_add(group_settings->root, "commands", CONFIG_TYPE_GROUP); count = config_setting_length(commands); for (j = 0; j < count; ++j) { config_setting_t *command = config_setting_get_elem(commands, j); const char *name = config_setting_name(command); if (!atcommand_exists(name)) { ShowConfigWarning(command, "pc_groups:read_config: non-existent command name '%s', removing...", name); config_setting_remove(commands, name); --j; --count; } } // Make sure there is "permissions" group if (permissions == NULL) permissions = group_settings->permissions = config_setting_add(group_settings->root, "permissions", CONFIG_TYPE_GROUP); count = config_setting_length(permissions); for(j = 0; j < count; ++j) { config_setting_t *permission = config_setting_get_elem(permissions, j); const char *name = config_setting_name(permission); int p; ARR_FIND(0, ARRAYLENGTH(pc_g_permission_name), p, strcmp(pc_g_permission_name[p].name, name) == 0); if (p == ARRAYLENGTH(pc_g_permission_name)) { ShowConfigWarning(permission, "pc_groups:read_config: non-existent permission name '%s', removing...", name); config_setting_remove(permissions, name); --p; --count; } } } dbi_destroy(iter); // Apply inheritance i = 0; // counter for processed groups while (i < group_count) { iter = db_iterator(pc_group_db); for (group_settings = dbi_first(iter); dbi_exists(iter); group_settings = dbi_next(iter)) { config_setting_t *inherit = NULL, *commands = group_settings->commands, *permissions = group_settings->permissions; int j, inherit_count = 0, done = 0; if (group_settings->inheritance_done) // group already processed continue; if ((inherit = group_settings->inherit) == NULL || (inherit_count = config_setting_length(inherit)) <= 0) { // this group does not inherit from others ++i; group_settings->inheritance_done = true; continue; } for (j = 0; j < inherit_count; ++j) { GroupSettings *inherited_group = NULL; const char *groupname = config_setting_get_string_elem(inherit, j); if (groupname == NULL) { ShowConfigWarning(inherit, "pc_groups:read_config: \"inherit\" array member #%d is not a name, removing...", j); config_setting_remove_elem(inherit,j); continue; } if ((inherited_group = name2group(groupname)) == NULL) { ShowConfigWarning(inherit, "pc_groups:read_config: non-existent group name \"%s\", removing...", groupname); config_setting_remove_elem(inherit,j); continue; } if (!inherited_group->inheritance_done) continue; // we need to do that group first // Copy settings (commands/permissions) that are not defined yet if (inherited_group->commands != NULL) { int l = 0, commands_count = config_setting_length(inherited_group->commands); for (l = 0; l < commands_count; ++l) config_setting_copy(commands, config_setting_get_elem(inherited_group->commands, l)); } if (inherited_group->permissions != NULL) { int l = 0, permissions_count = config_setting_length(inherited_group->permissions); for (l = 0; l < permissions_count; ++l) config_setting_copy(permissions, config_setting_get_elem(inherited_group->permissions, l)); } ++done; // copied commands and permissions from one of inherited groups } if (done == inherit_count) { // copied commands from all of inherited groups ++i; group_settings->inheritance_done = true; // we're done with this group } } dbi_destroy(iter); if (++loop > group_count) { ShowWarning("pc_groups:read_config: Could not process inheritance rules, check your config '%s' for cycles...\n", config_filename); break; } } // while(i < group_count) // Pack permissions into GroupSettings.e_permissions for faster checking iter = db_iterator(pc_group_db); for (group_settings = dbi_first(iter); dbi_exists(iter); group_settings = dbi_next(iter)) { config_setting_t *permissions = group_settings->permissions; int c, count = config_setting_length(permissions); for (c = 0; c < count; ++c) { config_setting_t *perm = config_setting_get_elem(permissions, c); const char *name = config_setting_name(perm); int val = config_setting_get_bool(perm); int j; if (val == 0) // does not have this permission continue; ARR_FIND(0, ARRAYLENGTH(pc_g_permission_name), j, strcmp(pc_g_permission_name[j].name, name) == 0); group_settings->e_permissions |= pc_g_permission_name[j].permission; } } dbi_destroy(iter); } ShowStatus("Done reading '"CL_WHITE"%d"CL_RESET"' groups in '"CL_WHITE"%s"CL_RESET"'.\n", group_count, config_filename); if( ( pc_group_max = group_count ) ) { DBIterator *iter = db_iterator(pc_group_db); GroupSettings *group_settings = NULL; int* group_ids = aMalloc( pc_group_max * sizeof(int) ); int i = 0; for (group_settings = dbi_first(iter); dbi_exists(iter); group_settings = dbi_next(iter)) { group_ids[i++] = group_settings->id; } atcommand_db_load_groups(group_ids); aFree(group_ids); dbi_destroy(iter); } }
Config* processConfigFile(char* filePath){ config_t cfg; config_setting_t *setting; const char *str; config_init(&cfg); Config *user_config = malloc(sizeof(Config)); /* Read the file. If there is an error, report it and exit. */ if(! config_read_file(&cfg, filePath)) { fprintf(stderr, "%s:%d - %s\n", config_error_file(&cfg), config_error_line(&cfg), config_error_text(&cfg)); config_destroy(&cfg); return(NULL); } /* Get the source root dir. */ if(config_lookup_string(&cfg, "sourceRootDir", &str)){ user_config->sourceRootDir=malloc(strlen(str)+1); user_config->sourceRootDir=strcpy(user_config->sourceRootDir,str); }else{ fprintf(stderr, "No 'sourceRootDir' setting in configuration file.\n"); return(NULL); } /* Get executable_path. */ if(config_lookup_string(&cfg, "executablePath", &str)){ user_config->executablePath=malloc(strlen(str)+1); user_config->executablePath=strcpy(user_config->executablePath,str); }else{ fprintf(stderr, "No 'executablePath' setting in configuration file.\n"); return(NULL); } /* (optional) Get executable_args. */ if(config_lookup_string(&cfg, "executableArgs", &str)){ user_config->executableArgs=malloc(strlen(str)+1); user_config->executableArgs=strcpy(user_config->executableArgs,str); } else{ user_config->executableArgs=NULL; } /* Get source locations*/ setting = config_lookup(&cfg, "source"); if(setting != NULL) { int count = config_setting_length(setting); int i; user_config->source = malloc((count+1)*sizeof(char*)); user_config->numberOfSource = count; for(i = 0; i < count; ++i) { const char *filename= config_setting_get_string_elem(setting, i); user_config->source[i] = malloc(sizeof(char)*(strlen(filename)+1)); strcpy(user_config->source[i],filename); } }else{ fprintf(stderr, "No 'source' setting in configuration file.\n"); return(NULL); } /* Get testing framework */ if(config_lookup_string(&cfg, "testingFramework", &str)){ if(strcmp(str,"cutest")==0){ user_config->testingFramework=1; printf("\n-->Assuming CuTest runner being run from make file<--\n"); if(config_lookup_string(&cfg, "CuTestLibSource", &str)){ user_config->CuTestLibSource=malloc(strlen(str)+1); user_config->CuTestLibSource=strcpy(user_config->CuTestLibSource,str); }else{ fprintf(stderr, "No CuTest lib source found\n"); return(NULL); } if(config_lookup_string(&cfg, "CuTestVersion", &str)){ user_config->CuTestVersion=atoi(str); }else{ user_config->CuTestVersion=1; } }else if(strcmp(str,"libcheck")==0){ user_config->testingFramework=2; if(config_lookup_string(&cfg, "CheckTestLibSource", &str)){ user_config->CheckTestLibSource=malloc(strlen(str)+1); user_config->CheckTestLibSource=strcpy(user_config->CheckTestLibSource,str); }else{ printf("\n-->Assuming the project is using the modified libcheck package provided in Mutate/libcheck<--\n"); } }else{ fprintf(stderr, "testing framework provided in the configuration file is not supported\n"); return(NULL); } /* get make test target */ if(config_lookup_string(&cfg, "makeTestTarget", &str)){ user_config->makeTestTarget=malloc(strlen(str)+1); user_config->makeTestTarget=strcpy(user_config->makeTestTarget,str); } else{ user_config->makeTestTarget=NULL; } }else{ fprintf(stderr, "No 'testingFramework' setting in configuration file.\n"); return(NULL); } config_destroy(&cfg); return user_config; }
static int config_parse_file(mme_config_t *mme_config_p) { config_t cfg; config_setting_t *setting_mme = NULL; config_setting_t *setting = NULL; config_setting_t *subsetting = NULL; config_setting_t *sub2setting = NULL; long int alongint; int i, num; char *astring = NULL; char *address = NULL; char *cidr = NULL; const char* tac = NULL; const char* mcc = NULL; const char* mnc = NULL; char *sgw_ip_address_for_S1u_S12_S4_up = NULL; char *mme_interface_name_for_S1_MME = NULL; char *mme_ip_address_for_S1_MME = NULL; char *mme_interface_name_for_S11 = NULL; char *mme_ip_address_for_S11 = NULL; char *sgw_ip_address_for_S11 = NULL; char system_cmd[256]; config_init(&cfg); if(mme_config_p->config_file != NULL) { /* Read the file. If there is an error, report it and exit. */ if(! config_read_file(&cfg, mme_config_p->config_file)) { fprintf(stdout, "ERROR: %s:%d - %s\n", mme_config_p->config_file, config_error_line(&cfg), config_error_text(&cfg)); config_destroy(&cfg); AssertFatal (1 == 0, "Failed to parse MME configuration file %s!\n", mme_config_p->config_file); } } else { fprintf(stdout, "ERROR No MME configuration file provided!\n"); config_destroy(&cfg); AssertFatal (0, "No MME configuration file provided!\n"); } setting_mme = config_lookup(&cfg, MME_CONFIG_STRING_MME_CONFIG); if(setting_mme != NULL) { // GENERAL MME SETTINGS if( (config_setting_lookup_string( setting_mme, MME_CONFIG_STRING_REALM, (const char **)&astring) )) { mme_config_p->realm = strdup(astring); mme_config_p->realm_length = strlen(mme_config_p->realm); } if( (config_setting_lookup_int( setting_mme, MME_CONFIG_STRING_MAXENB, &alongint) )) { mme_config_p->max_eNBs = (uint32_t)alongint; } if( (config_setting_lookup_int( setting_mme, MME_CONFIG_STRING_MAXUE, &alongint) )) { mme_config_p->max_ues = (uint32_t)alongint; } if( (config_setting_lookup_int( setting_mme, MME_CONFIG_STRING_RELATIVE_CAPACITY, &alongint) )) { mme_config_p->relative_capacity = (uint8_t)alongint; } if( (config_setting_lookup_int( setting_mme, MME_CONFIG_STRING_STATISTIC_TIMER, &alongint) )) { mme_config_p->mme_statistic_timer = (uint32_t)alongint; } if( (config_setting_lookup_string( setting_mme, MME_CONFIG_STRING_EMERGENCY_ATTACH_SUPPORTED, (const char **)&astring) )) { if (strcasecmp(astring , "yes") == 0) mme_config_p->emergency_attach_supported = 1; else mme_config_p->emergency_attach_supported = 0; } if( (config_setting_lookup_string( setting_mme, MME_CONFIG_STRING_UNAUTHENTICATED_IMSI_SUPPORTED, (const char **)&astring) )) { if (strcasecmp(astring , "yes") == 0) mme_config_p->unauthenticated_imsi_supported = 1; else mme_config_p->unauthenticated_imsi_supported = 0; } if( (config_setting_lookup_string( setting_mme, MME_CONFIG_STRING_ASN1_VERBOSITY, (const char **)&astring) )) { if (strcasecmp(astring , MME_CONFIG_STRING_ASN1_VERBOSITY_NONE) == 0) mme_config_p->verbosity_level = 0; else if (strcasecmp(astring , MME_CONFIG_STRING_ASN1_VERBOSITY_ANNOYING) == 0) mme_config_p->verbosity_level = 2; else if (strcasecmp(astring , MME_CONFIG_STRING_ASN1_VERBOSITY_INFO) == 0) mme_config_p->verbosity_level = 1; else mme_config_p->verbosity_level = 0; } // ITTI SETTING setting = config_setting_get_member (setting_mme, MME_CONFIG_STRING_INTERTASK_INTERFACE_CONFIG); if (setting != NULL) { if( (config_setting_lookup_int( setting, MME_CONFIG_STRING_INTERTASK_INTERFACE_QUEUE_SIZE, &alongint) )) { mme_config_p->itti_config.queue_size = (uint32_t)alongint; } } // S6A SETTING setting = config_setting_get_member (setting_mme, MME_CONFIG_STRING_S6A_CONFIG); if (setting != NULL) { if( (config_setting_lookup_string( setting, MME_CONFIG_STRING_S6A_CONF_FILE_PATH, (const char **)&astring) )) { if (astring != NULL) mme_config_p->s6a_config.conf_file = strdup(astring); } if( (config_setting_lookup_string( setting, MME_CONFIG_STRING_S6A_HSS_HOSTNAME, (const char **)&astring) )) { if (astring != NULL) mme_config_p->s6a_config.hss_host_name = strdup(astring); else AssertFatal (1 == 0, "You have to provide a valid HSS hostname %s=...\n", MME_CONFIG_STRING_S6A_HSS_HOSTNAME); } } // SCTP SETTING setting = config_setting_get_member (setting_mme, MME_CONFIG_STRING_SCTP_CONFIG); if (setting != NULL) { if( (config_setting_lookup_int( setting, MME_CONFIG_STRING_SCTP_INSTREAMS, &alongint) )) { mme_config_p->sctp_config.in_streams = (uint16_t)alongint; } if( (config_setting_lookup_int( setting, MME_CONFIG_STRING_SCTP_OUTSTREAMS, &alongint) )) { mme_config_p->sctp_config.out_streams = (uint16_t)alongint; } } // S1AP SETTING setting = config_setting_get_member (setting_mme, MME_CONFIG_STRING_S1AP_CONFIG); if (setting != NULL) { if( (config_setting_lookup_int( setting, MME_CONFIG_STRING_S1AP_OUTCOME_TIMER, &alongint) )) { mme_config_p->s1ap_config.outcome_drop_timer_sec = (uint8_t)alongint; } if( (config_setting_lookup_int( setting, MME_CONFIG_STRING_S1AP_PORT, &alongint) )) { mme_config_p->s1ap_config.port_number = (uint16_t)alongint; } } // GUMMEI SETTING setting = config_setting_get_member (setting_mme, MME_CONFIG_STRING_GUMMEI_CONFIG); if (setting != NULL) { subsetting = config_setting_get_member (setting, MME_CONFIG_STRING_MME_CODE); if (subsetting != NULL) { num = config_setting_length(subsetting); if (mme_config_p->gummei.nb_mmec != num) { if (mme_config_p->gummei.mmec != NULL) { free(mme_config_p->gummei.mmec); } mme_config_p->gummei.mmec = calloc(num, sizeof(*mme_config_p->gummei.mmec)); } mme_config_p->gummei.nb_mmec = num; for (i = 0; i < num; i++) { mme_config_p->gummei.mmec[i] = config_setting_get_int_elem(subsetting, i); } } subsetting = config_setting_get_member (setting, MME_CONFIG_STRING_MME_GID); if (subsetting != NULL) { num = config_setting_length(subsetting); if (mme_config_p->gummei.nb_mme_gid != num) { if (mme_config_p->gummei.mme_gid != NULL) { free(mme_config_p->gummei.mme_gid); } mme_config_p->gummei.mme_gid = calloc(num, sizeof(*mme_config_p->gummei.mme_gid)); } mme_config_p->gummei.nb_mme_gid = num; for (i = 0; i < num; i++) { mme_config_p->gummei.mme_gid[i] = config_setting_get_int_elem(subsetting, i); } } subsetting = config_setting_get_member (setting, MME_CONFIG_STRING_TAI_LIST); if (subsetting != NULL) { num = config_setting_length(subsetting); if (mme_config_p->gummei.nb_plmns != num) { if (mme_config_p->gummei.plmn_mcc != NULL) free(mme_config_p->gummei.plmn_mcc); if (mme_config_p->gummei.plmn_mnc != NULL) free(mme_config_p->gummei.plmn_mnc); if (mme_config_p->gummei.plmn_mnc_len != NULL) free(mme_config_p->gummei.plmn_mnc_len); if (mme_config_p->gummei.plmn_tac != NULL) free(mme_config_p->gummei.plmn_tac); mme_config_p->gummei.plmn_mcc = calloc(num, sizeof(*mme_config_p->gummei.plmn_mcc)); mme_config_p->gummei.plmn_mnc = calloc(num, sizeof(*mme_config_p->gummei.plmn_mnc)); mme_config_p->gummei.plmn_mnc_len = calloc(num, sizeof(*mme_config_p->gummei.plmn_mnc_len)); mme_config_p->gummei.plmn_tac = calloc(num, sizeof(*mme_config_p->gummei.plmn_tac)); } mme_config_p->gummei.nb_plmns = num; for (i = 0; i < num; i++) { sub2setting = config_setting_get_elem(subsetting, i); if (sub2setting != NULL) { if( (config_setting_lookup_string( sub2setting, MME_CONFIG_STRING_MCC, &mcc) )) { mme_config_p->gummei.plmn_mcc[i] = (uint16_t)atoi(mcc); } if( (config_setting_lookup_string( sub2setting, MME_CONFIG_STRING_MNC, &mnc) )) { mme_config_p->gummei.plmn_mnc[i] = (uint16_t)atoi(mnc); mme_config_p->gummei.plmn_mnc_len[i] = strlen(mnc); AssertFatal((mme_config_p->gummei.plmn_mnc_len[i] == 2) || (mme_config_p->gummei.plmn_mnc_len[i] == 3), "Bad MNC length %u, must be 2 or 3", mme_config_p->gummei.plmn_mnc_len[i]); } if( (config_setting_lookup_string( sub2setting, MME_CONFIG_STRING_TAC, &tac) )) { mme_config_p->gummei.plmn_tac[i] = (uint16_t)atoi(tac); AssertFatal(mme_config_p->gummei.plmn_tac[i] != 0, "TAC must not be 0"); } } } } } // NETWORK INTERFACE SETTING setting = config_setting_get_member (setting_mme, MME_CONFIG_STRING_NETWORK_INTERFACES_CONFIG); if(setting != NULL) { if( ( config_setting_lookup_string( setting, MME_CONFIG_STRING_INTERFACE_NAME_FOR_S1_MME, (const char **)&mme_interface_name_for_S1_MME) && config_setting_lookup_string( setting, MME_CONFIG_STRING_IPV4_ADDRESS_FOR_S1_MME, (const char **)&mme_ip_address_for_S1_MME) && config_setting_lookup_string( setting, MME_CONFIG_STRING_INTERFACE_NAME_FOR_S11_MME, (const char **)&mme_interface_name_for_S11) && config_setting_lookup_string( setting, MME_CONFIG_STRING_IPV4_ADDRESS_FOR_S11_MME, (const char **)&mme_ip_address_for_S11) ) ) { mme_config_p->ipv4.mme_interface_name_for_S1_MME = strdup(mme_interface_name_for_S1_MME); cidr = strdup(mme_ip_address_for_S1_MME); address = strtok(cidr, "/"); IPV4_STR_ADDR_TO_INT_NWBO ( address, mme_config_p->ipv4.mme_ip_address_for_S1_MME, "BAD IP ADDRESS FORMAT FOR MME S1_MME !\n" ) free(cidr); mme_config_p->ipv4.mme_interface_name_for_S11 = strdup(mme_interface_name_for_S11); cidr = strdup(mme_ip_address_for_S11); address = strtok(cidr, "/"); IPV4_STR_ADDR_TO_INT_NWBO ( address, mme_config_p->ipv4.mme_ip_address_for_S11, "BAD IP ADDRESS FORMAT FOR MME S11 !\n" ) free(cidr); if (strncasecmp("tun",mme_config_p->ipv4.mme_interface_name_for_S1_MME, strlen("tun")) == 0) { if (snprintf(system_cmd, 256, "ip link set %s down ;openvpn --rmtun --dev %s", mme_config_p->ipv4.mme_interface_name_for_S1_MME, mme_config_p->ipv4.mme_interface_name_for_S1_MME ) > 0) { mme_system(system_cmd, 1); } else { fprintf(stderr, "Del %s\n", mme_config_p->ipv4.mme_interface_name_for_S1_MME); } if (snprintf(system_cmd, 256, "openvpn --mktun --dev %s;sync;ifconfig %s up;sync", mme_config_p->ipv4.mme_interface_name_for_S1_MME, mme_config_p->ipv4.mme_interface_name_for_S1_MME) > 0) { mme_system(system_cmd, 1); } else { fprintf(stderr, "Create %s\n", mme_config_p->ipv4.mme_interface_name_for_S1_MME); } if (snprintf(system_cmd, 256, "ip -4 addr add %s dev %s", mme_ip_address_for_S1_MME, mme_config_p->ipv4.mme_interface_name_for_S1_MME) > 0) { mme_system(system_cmd, 1); } else { fprintf(stderr, "Set IPv4 address on %s\n", mme_config_p->ipv4.mme_interface_name_for_S1_MME); } } } } // NAS SETTING setting = config_setting_get_member (setting_mme, MME_CONFIG_STRING_NAS_CONFIG); if (setting != NULL) { subsetting = config_setting_get_member (setting, MME_CONFIG_STRING_NAS_SUPPORTED_INTEGRITY_ALGORITHM_LIST); if (subsetting != NULL) { num = config_setting_length(subsetting); if (num <= 8) { for (i = 0; i < num; i++) { astring = config_setting_get_string_elem(subsetting, i); if (strcmp("EIA0", astring) == 0) mme_config_p->nas_config.prefered_integrity_algorithm[i] = NAS_CONFIG_SECURITY_ALGORITHMS_EIA0; else if (strcmp("EIA1", astring) == 0) mme_config_p->nas_config.prefered_integrity_algorithm[i] = NAS_CONFIG_SECURITY_ALGORITHMS_EIA1; else if (strcmp("EIA2", astring) == 0) mme_config_p->nas_config.prefered_integrity_algorithm[i] = NAS_CONFIG_SECURITY_ALGORITHMS_EIA2; else if (strcmp("EIA3", astring) == 0) mme_config_p->nas_config.prefered_integrity_algorithm[i] = NAS_CONFIG_SECURITY_ALGORITHMS_EIA0; else if (strcmp("EIA4", astring) == 0) mme_config_p->nas_config.prefered_integrity_algorithm[i] = NAS_CONFIG_SECURITY_ALGORITHMS_EIA0; else if (strcmp("EIA5", astring) == 0) mme_config_p->nas_config.prefered_integrity_algorithm[i] = NAS_CONFIG_SECURITY_ALGORITHMS_EIA0; else if (strcmp("EIA6", astring) == 0) mme_config_p->nas_config.prefered_integrity_algorithm[i] = NAS_CONFIG_SECURITY_ALGORITHMS_EIA0; else if (strcmp("EIA7", astring) == 0) mme_config_p->nas_config.prefered_integrity_algorithm[i] = NAS_CONFIG_SECURITY_ALGORITHMS_EIA0; } for (i = num; i < 8; i++) { mme_config_p->nas_config.prefered_integrity_algorithm[i] = NAS_CONFIG_SECURITY_ALGORITHMS_EIA0; } } } subsetting = config_setting_get_member (setting, MME_CONFIG_STRING_NAS_SUPPORTED_CIPHERING_ALGORITHM_LIST); if (subsetting != NULL) { num = config_setting_length(subsetting); if (num <= 8) { for (i = 0; i < num; i++) { astring = config_setting_get_string_elem(subsetting, i); if (strcmp("EEA0", astring) == 0) mme_config_p->nas_config.prefered_ciphering_algorithm[i] = NAS_CONFIG_SECURITY_ALGORITHMS_EEA0; else if (strcmp("EEA1", astring) == 0) mme_config_p->nas_config.prefered_ciphering_algorithm[i] = NAS_CONFIG_SECURITY_ALGORITHMS_EEA1; else if (strcmp("EEA2", astring) == 0) mme_config_p->nas_config.prefered_ciphering_algorithm[i] = NAS_CONFIG_SECURITY_ALGORITHMS_EEA2; else if (strcmp("EEA3", astring) == 0) mme_config_p->nas_config.prefered_ciphering_algorithm[i] = NAS_CONFIG_SECURITY_ALGORITHMS_EEA0; else if (strcmp("EEA4", astring) == 0) mme_config_p->nas_config.prefered_ciphering_algorithm[i] = NAS_CONFIG_SECURITY_ALGORITHMS_EEA0; else if (strcmp("EEA5", astring) == 0) mme_config_p->nas_config.prefered_ciphering_algorithm[i] = NAS_CONFIG_SECURITY_ALGORITHMS_EEA0; else if (strcmp("EEA6", astring) == 0) mme_config_p->nas_config.prefered_ciphering_algorithm[i] = NAS_CONFIG_SECURITY_ALGORITHMS_EEA0; else if (strcmp("EEA7", astring) == 0) mme_config_p->nas_config.prefered_ciphering_algorithm[i] = NAS_CONFIG_SECURITY_ALGORITHMS_EEA0; } for (i = num; i < 8; i++) { mme_config_p->nas_config.prefered_ciphering_algorithm[i] = NAS_CONFIG_SECURITY_ALGORITHMS_EEA0; } } } } } setting = config_lookup(&cfg, SGW_CONFIG_STRING_SGW_CONFIG); if(setting != NULL) { subsetting = config_setting_get_member (setting, SGW_CONFIG_STRING_NETWORK_INTERFACES_CONFIG); if(subsetting != NULL) { if( ( config_setting_lookup_string( subsetting, SGW_CONFIG_STRING_SGW_IPV4_ADDRESS_FOR_S1U_S12_S4_UP, (const char **)&sgw_ip_address_for_S1u_S12_S4_up) && config_setting_lookup_string( subsetting, SGW_CONFIG_STRING_SGW_IPV4_ADDRESS_FOR_S11, (const char **)&sgw_ip_address_for_S11) && config_setting_lookup_int( subsetting, SGW_CONFIG_STRING_SGW_PORT_FOR_S1U_S12_S4_UP, &alongint) ) ) { cidr = strdup(sgw_ip_address_for_S1u_S12_S4_up); address = strtok(cidr, "/"); IPV4_STR_ADDR_TO_INT_NWBO ( address, mme_config_p->ipv4.sgw_ip_address_for_S1u_S12_S4_up, "BAD IP ADDRESS FORMAT FOR SGW S1u_S12_S4 !\n" ) free(cidr); cidr = strdup(sgw_ip_address_for_S11); address = strtok(cidr, "/"); IPV4_STR_ADDR_TO_INT_NWBO ( address, mme_config_p->ipv4.sgw_ip_address_for_S11, "BAD IP ADDRESS FORMAT FOR SGW S11 !\n" ) free(cidr); mme_config_p->gtpv1u_config.port_number = (uint16_t) alongint; } } } return 0; }
void Level::LoadLevel( char* FileName ) { config_t cfg; config_setting_t *setting; config_setting_t *list; config_init(&cfg); config_read_file( &cfg, FileName ); setting = config_lookup( &cfg, "LevelInfo" ); const char* tmpStr; config_setting_lookup_string( setting, "LevelName", &tmpStr ); LevelName = (char*)malloc( strlen(tmpStr) + 2 ); sprintf( LevelName, "%s", tmpStr ); config_setting_t* trackData = config_setting_get_member( setting, "Music" ); for( int idx = 0; idx < config_setting_length( trackData ); idx++ ) { char* tempElem; tmpStr = config_setting_get_string_elem( trackData, idx ); tempElem = (char*)malloc( strlen(tmpStr) + 2 ); sprintf( tempElem, "%s", tmpStr ); MusicTracks->AddToEnd( (void*)tempElem ); } config_setting_lookup_string( setting, "IntroScreenImage", &tmpStr ); IntroDisplay = (char*)malloc( strlen(tmpStr) + 2 ); sprintf( IntroDisplay, "%s", tmpStr ); config_setting_lookup_int( setting, "IntroMusicTrack", &IntroMusicTrack ); list = config_lookup( &cfg, "Layers" ); for( int eidx = 0; eidx < config_setting_length( list ); eidx++ ) { Layer* newLayer = new Layer( this, config_setting_get_elem( list, eidx ) ); Layers->AddToEnd( newLayer ); } list = config_lookup( &cfg, "Events" ); for( int eidx = 0; eidx < config_setting_length( list ); eidx++ ) { Event* newEvent = new Event( this, config_setting_get_elem( list, eidx ) ); // Are we a pre-game activation? If so, process and delete if( newEvent->ActivatePosition == -1 ) { newEvent->Activate(); delete newEvent; } else { Events->AddToEnd( newEvent ); } } list = config_lookup( &cfg, "Scripts" ); for( int eidx = 0; eidx < config_setting_length( list ); eidx++ ) { Uint16* scriptBuffer; config_setting_t* scriptArray = config_setting_get_elem( list, eidx ); scriptBuffer = (Uint16*)malloc( config_setting_length( scriptArray ) * 2 ); for( int aidx = 0; aidx < config_setting_length( scriptArray ); aidx++ ) { int scriptOpCode; scriptOpCode = config_setting_get_int_elem( scriptArray, aidx ); scriptBuffer[aidx] = (Uint16)(scriptOpCode & 0x0000FFFF); } Scripts->AddToEnd( (void*)scriptBuffer ); } list = config_lookup( &cfg, "Templates" ); for( int eidx = 0; eidx < config_setting_length( list ); eidx++ ) { EnemyCraftTemplate* newTemplate = new EnemyCraftTemplate( Owner, config_setting_get_elem( list, eidx ) ); EnemyTemplates->AddToEnd( newTemplate ); } setting = config_lookup( &cfg, "LayerInfo" ); config_setting_lookup_int( setting, "CollisionIndex", &LayerCollisionIndex ); config_setting_lookup_int( setting, "GameIndex", &LayerGameIndex ); config_destroy(&cfg); }