static void load_config(void) { cfg_t *cfg; char listen_port_str[128]; char ip[128]; char servername[128]; char num[128]; char thresold[128]; cfg_open(&cfg, CONFIG_FILENAME); cfg_read(cfg, "server", "ip", listen_ip); cfg_read(cfg, "server", "listen", listen_port_str); cfg_read(cfg, "server", "netcard", netcard); cfg_read(cfg, "server", "thread num", num); cfg_read(cfg, "oracle", "ip", ip); cfg_read(cfg, "oracle", "servername", servername); cfg_read(cfg, "oracle", "username", oracle_username); cfg_read(cfg, "oracle", "password", oracle_password); cfg_read(cfg, "spam", "thresold", thresold); cfg_read(cfg, "spam", "data file", spam_data); cfg_close(cfg); /* 处理,应该在此进行正确性判断 */ sprintf(oracle_servername, "%s/%s", ip, servername); listen_port = atoi(listen_port_str); nthread = atoi(num); spam_thresold = atof(thresold); DEBUG("listen ip: %s:%s\n" "oracle user: %s, password: %s\n" "thread count: %d\nspam_data: %s\n" "thresold: %lf\n", listen_ip, listen_port_str, oracle_username, oracle_password, nthread, spam_data, spam_thresold); }
int fwtk_init(struct passwd *pw, sudo_auth *auth) { static Cfg *confp; /* Configuration entry struct */ char resp[128]; /* Response from the server */ if ((confp = cfg_read("sudo")) == (Cfg *)-1) { warningx(_("unable to read fwtk config")); return AUTH_FATAL; } if (auth_open(confp)) { warningx(_("unable to connect to authentication server")); return AUTH_FATAL; } /* Get welcome message from auth server */ if (auth_recv(resp, sizeof(resp))) { warningx(_("lost connection to authentication server")); return AUTH_FATAL; } if (strncmp(resp, "Authsrv ready", 13) != 0) { warningx(_("authentication server error:\n%s"), resp); return AUTH_FATAL; } return AUTH_SUCCESS; }
bool Profile::read_str(const char *section, const char *option, char *store) { if(!cfg_read(profile_path,section,option,store)) { warning("Profile::read_str(%s,%s) : %s", option,section,profile_path); return(false); } return(true); }
int cfg_read_file(cfg_t *cfg, const char *filepath) { FILE *fd = fopen(filepath, "r"); return cfg_read(cfg, fd); }
int main(int argc, char **argv) { Cfg *cfg; int ret = 1; Octstr *name; int i; gwlib_init(); for (i = 1; i < argc; ++i) { name = octstr_create(argv[i]); cfg = cfg_create(name); octstr_destroy(name); ret = cfg_read(cfg); info(0, "cfg_read returned %d", ret); if (ret == 0) cfg_dump(cfg); cfg_destroy(cfg); } info(0, "Shutting down."); gwlib_shutdown(); return ret; }
Config cfg_new_from_stream(FILE* f) { Config cfg = cfg_new(); if(cfg_read(cfg, f) != CFG_OKAY) { cfg_destroy(cfg); cfg = NULL; } return cfg; }
int main(int argc, char *argv[]) { int gui_done = 0; scroll_count = 800; selected_menu = ROMS; alpha_up = 1; alpha = 0; mouse_y_pos = 120; selected_option_item = 0; if(!cfg_read("config.txt")) { printf("Fail => cfg_read()\n"); exit(0); } if(!gui_init_sdl()) { printf("Fail => gui_init_sdl()\n"); exit(0); } emu_config_init(); gui_load(); strncpy(now_path, config->roms_path, MAXPATH); filer_read_dir(now_path); SDL_initFramerate( &sixteen ); SDL_setFramerate( &sixteen, 65 ); while(!gui_done) { handle_mouse(); while( SDL_PollEvent( &event ) ) { switch(event.type) { case SDL_QUIT: { gui_clean(); free(emu); exit(0); } break; } } gui_draw(); SDL_Flip(myscreen); SDL_framerateDelay( &sixteen ); } return 0; }
int main(int argc, char **argv) { int cf_index; Octstr *filename, *version; gwlib_init(); list_dict = dict_create(32, msg_list_destroy_item); cf_index = get_and_set_debugs(argc, argv, check_args); setup_signal_handlers(); if (argv[cf_index] == NULL) filename = octstr_create("httpClient.conf"); else filename = octstr_create(argv[cf_index]); cfg = cfg_create(filename); /* Adding cfg-checks to core */ cfg_add_hooks(smppbox_is_allowed_in_group, smppbox_is_single_group); if (cfg_read(cfg) == -1) panic(0, "Couldn't read configuration from `%s'.", octstr_get_cstr(filename)); octstr_destroy(filename); version = octstr_format("httpClient version %s gwlib", GW_VERSION); report_versions(octstr_get_cstr(version)); octstr_destroy(version); struct server_type *res = NULL; res = sqlbox_init_mysql(cfg); sqlbox_configure_mysql(cfg); init_smpp_server_box(cfg); http_client_box_run(); //gwthread_join_every(sql_to_smpp); //gwthread_join_every(smpp_to_sql); smpp_server_box_shutdown(); dict_destroy(list_dict); list_dict = NULL; cfg_destroy(cfg); if (restart_httpbox) { gwthread_sleep(1.0); } gw_smpp_leave(); gwlib_shutdown(); if (restart_httpbox) execvp(argv[0], argv); return 0; }
static int exynos_pcie_rd_own_conf(struct pcie_port *pp, int where, int size, u32 *val) { int ret; exynos_pcie_sideband_dbi_r_mode(pp, true); ret = cfg_read(pp->dbi_base + (where & ~0x3), where, size, val); exynos_pcie_sideband_dbi_r_mode(pp, false); return ret; }
int cfg_read_file(Config cfg, const char* filename) { int err; FILE* f = fopen(filename, "r"); if(f == NULL) { fprintf(stderr, "cfg_read_file: could not read file '%s'\n", filename); return CFG_FILE_ERROR; } err = cfg_read(cfg, f); fclose(f); return err; }
float Profile::read_float(const char *section, const char *option) { char temp[MAX_VALUE_SIZE]; float val; if(!cfg_read(profile_path, section, option, temp)) { warning("Profile::read_float(%s,%s) : %s", option,section,profile_path); return(-1.0f); } sscanf(temp,"%f",&val); return val; }
void PrintPathTest::installCfg(const char * def) { if (m_root) { cfg_free(m_root); m_root = 0; } m_root = cfg_create(t_tmp_allocrator()); read_stream_mem inputStream = CPE_READ_STREAM_MEM_INITIALIZER(def, strlen(def)); EXPECT_EQ( 0, cfg_read(m_root, (read_stream_t)&inputStream, cfg_merge_use_new, 0)) << "parse cfg fail!\ninput:\n" << def; }
void cfg_reinitialize(void) { int i; #ifdef USE_XFT int xft = xftfont ? 1 : 0; #endif /* free things from old configuration */ XFreeGC(dpy, gc); XFreeGC(dpy, igc); XFreeGC(dpy, bgc); XFreeGC(dpy, ibgc); keys_free(); /* read config again */ cfg_read(0); /* update some things */ p_attr.background_pixel = fg.pixel; p_attr.border_pixel = ibfg.pixel; select_root_events(); /* update clients */ for(i = 0; i < cn; i++) { #ifdef USE_XFT if(xftfont && !xft) clients[i]->wlist_draw = XftDrawCreate(dpy, clients[i]->wlist_item, visual, colormap); if(!xftfont && xft) { XftDrawDestroy(clients[i]->title_draw); XftDrawDestroy(clients[i]->wlist_draw); } #endif XDestroyWindow(dpy, clients[i]->button_parent_left); XDestroyWindow(dpy, clients[i]->button_parent_right); free((void *) clients[i]->buttons); clients[i]->flags ^= clients[i]->flags & HAS_BUTTONS; buttons_create(clients[i]); /* buttons are now on top of the client window */ XRaiseWindow(dpy, clients[i]->window); /* hence this line */ client_update(clients[i]); client_update_name(clients[i]); (clients[i] == current) ? client_set_bg(clients[i], bg, fg) : client_set_bg(clients[i], ibg, ifg); if(clients[i]->flags & IS_TASKBAR) client_set_layer(clients[i], taskbar_ontop ? TOP : NORMAL); XUngrabButton(dpy, AnyButton, AnyModifier, clients[i]->parent); client_grab_buttons(clients[i]); if(clients[i]->flags & FULLSCREEN && clients[i]->layer <= NORMAL && fullscreen_stacking != FS_NORMAL) client_update_layer(clients[i], (fullscreen_stacking == FS_ALWAYS_ONTOP) ? NORMAL : TOP); if(clients[i]->flags & HAS_BORDER) XSetWindowBorderWidth(dpy, clients[i]->parent, border_width); ewmh_update_extents(clients[i]); } ewmh_update_number_of_desktops(); ewmh_update_geometry(); ewmh_update_strut(); }
int main( int argc, char *argv[] ) { selected_item = 0; scroll_count = 800; alpha_up = 1; alpha = 0; if ( argc > 1 ) { strcpy( pdm_dir, argv[1] ); if ( pdm_dir[strlen(pdm_dir)-1] != '/' ) strcat( pdm_dir, "/" ); } else { fprintf(stderr, "Usage: %s pdm_exec_dir\n", argv[0] ); exit(0); } write_pid(); printf("reading configuration file: %s\n", pdm_dir_and("data/pdm.conf") ); cfg_read( pdm_dir_and("data/pdm.conf") ); if( general->autoboot_item >= 0 ) { execl( item->exec_path[general->autoboot_item], item->exec_path[general->autoboot_item], NULL); free( item ); free( general ); exit(0); } gui_init(); gui_load(); while( !gui_done ) { gui_draw(); gui_events(); } gui_clean(); free(item); free(general); return 0; }
int Profile::read_int(const char *section, const char *option) { char temp[MAX_VALUE_SIZE]; int res = -1; if(!cfg_read(profile_path,section,option,temp)) { warning("Profile::read_int(%s,%s) : %s", option,section,profile_path); return(-1); } res = strtol(temp,NULL,10); if(errno==ERANGE) { error("Profile::read_int(%s,%s) value %s : ", section, option, temp, strerror(errno)); return(-1); } else return(res); }
/* * checksum is for erased (eeprom, flash ...) ( all ff) not correct! */ extern void CLI_config_read (void) { if (cfg_read != NULL){ if (cfg_read() == ACE_OK){ if ((NET_inet_chksum (&CLI_config, (ACE_u16_t) (sizeof (CLI_config))) != 0) || (CLI_config.state != CLI_CFG_STATE_SAVED)) { CLI_config_init (); } } else { CLI_config_init (); } } }
int main(int argc, char **argv) { int cf_index; Octstr *filename; gwlib_init(); cf_index = get_and_set_debugs(argc, argv, check_args); setup_signal_handlers(); if (argv[cf_index] == NULL) { filename = octstr_create("sqlbox.conf"); } else { filename = octstr_create(argv[cf_index]); } cfg = cfg_create(filename); /* Adding cfg-checks to core */ cfg_add_hooks(sqlbox_is_allowed_in_group, sqlbox_is_single_group); if (cfg_read(cfg) == -1) panic(0, "Couldn't read configuration from `%s'.", octstr_get_cstr(filename)); octstr_destroy(filename); report_versions("sqlbox"); init_sqlbox(cfg); sqlboxc_run((void *)sqlbox_port); cfg_destroy(cfg); if (restart_sqlbox) { gwthread_sleep(1.0); } gw_sql_leave(); gwlib_shutdown(); if (restart_sqlbox) execvp(argv[0], argv); return 0; }
static void read_test_ppg_config(Octstr *name) { Cfg *cfg; CfgGroup *grp; cfg = cfg_create(name); if (cfg_read(cfg) == -1) panic(0, "Cannot read a configuration file %s, exiting", octstr_get_cstr(name)); cfg_dump(cfg); grp = cfg_get_single_group(cfg, octstr_imm("test-ppg")); cfg_get_integer(&retries, grp, octstr_imm("retries")); cfg_get_bool(&pi_ssl, grp, octstr_imm("pi-ssl")); #ifdef HAVE_LIBSSL if (pi_ssl) { ssl_client_certkey_file = cfg_get(grp, octstr_imm("ssl-client-certkey-file")); if (ssl_client_certkey_file != NULL) { use_global_client_certkey_file(ssl_client_certkey_file); } else { error(0, "cannot set up SSL without client certkey file"); exit(1); } } #endif grp = cfg_get_single_group(cfg, octstr_imm("configuration")); push_url = cfg_get(grp, octstr_imm("push-url")); pap_file = cfg_get(grp, octstr_imm("pap-file")); content_file = cfg_get(grp, octstr_imm("content-file")); if (!use_hardcoded) { username = cfg_get(grp, octstr_imm("username")); password = cfg_get(grp, octstr_imm("password")); } cfg_destroy(cfg); }
int main() { FILE* f = fopen("test","w+"); cfg_write("daniele","1",f); cfg_write("pippo","4",f); cfg_write("urca","7",f); cfg_write("pippo","2",f); cfg_write("urca","3",f); fclose(f); f = fopen("test","r"); char a[100],b[100]; while ( cfg_read(a,b,f) ) { printf("\'%s\' == \'%s\'\n",a,b); } fclose(f); return 0; }
main(int argc, char **argv) { pthread_attr_t sched_attr; int maxprio, minprio; int go = 1; struct sched_param fifo_param; struct sigaction ignoreChildDeath = {NULL, 0, (SA_NOCLDSTOP | SA_RESTART), NULL}; struct sigaction hupAction = {hupcatch, 0, SA_RESTART, NULL}; struct sigaction termAction = {termcatch, 0, SA_RESTART, NULL}; myName=argv[0]; ch_flag = 0; terminate = 0; fprintf(stderr,"%s daemon start.\n", myName); pthread_attr_init(&sched_attr); pthread_attr_setinheritsched(&sched_attr, PTHREAD_EXPLICIT_SCHED); pthread_attr_setschedpolicy(&sched_attr, /*SCHED_RR */ SCHED_FIFO); maxprio = sched_get_priority_max(SCHED_FIFO); minprio = sched_get_priority_min(SCHED_FIFO); sigaction(SIGCHLD, &ignoreChildDeath, NULL); /*zombie protection */ sigaction(SIGHUP, &hupAction, NULL); sigaction(SIGTERM, &termAction, NULL); if (terminate == TERM_TERM) { go = 0; } else { go = 1; } while (go) { /*The main restart loop */ terminate = 0; /*read config file here */ cfg_read(CONFIG_FILE, "", ""); /* do command line option processing, they override config file opts */ do_opts(argc, argv); if (!foreground) { daemon(); } wxin = serial_open(opts.ttydev); last_write_time = time(NULL); if (wxin > 0) { sane_defaults(); init_db(); if (setupio(wxin) < 0) { errlog(9, "setupio bailed."); } iobuf = make_cbuf(BSIZE); pthread_mutex_init(¤t_obs_lock, pthread_mutexattr_default); pthread_mutex_init(¤t_cal_lock, pthread_mutexattr_default); pthread_mutex_init(&terminate_lock, pthread_mutexattr_default); pthread_mutex_init(&cond_update_lock, pthread_mutexattr_default); pthread_cond_init(&cond_update, pthread_condattr_default); #if USE_CBUF /* fifo_param.sched_priority = (minprio + maxprio) / 2; pthread_attr_setschedparam(&sched_attr, &fifo_param);*/ pthread_create(&reader, /*pthread_attr_default */ NULL, (pthread_startroutine_t) serial_reader, (pthread_addr_t) iobuf); pthread_create(&parser, NULL /*&sched_attr*/, (pthread_startroutine_t) parse_input, (pthread_addr_t) iobuf); #if SCREENOUT pthread_create(&writer, NULL /*&sched_attr*/, (pthread_startroutine_t) screen_writer, (pthread_addr_t) NULL); #else /* Make a db writer thread */ pthread_create(&writer, NULL /*&sched_attr*/, (pthread_startroutine_t) db_writer, (pthread_addr_t) NULL); #endif pthread_join(reader, NULL); pthread_join(parser, NULL); pthread_join(writer, NULL); #else parse_input(iobuf); #endif release_cbuf(iobuf); serial_close(opts.ttydev); if (terminate == TERM_TERM) { errlog1(1, "%s: TERMINATE.", argv[0]); go = 0; } if (terminate == TERM_RESTART) { errlog1(1, "%s: RESTART.", argv[0]); go = 1; } #if SCREENOUT #else db_getout(dbconn); #endif } else { go = 0; errlog2(1, "%s: cannot open serial port: %s", argv[0], opts.ttydev); } } errlog1(1,"%s daemon shutdown.", myName); exit(0); }
int main(int argc, char** argv){ CONFIG cfg; cfg_init(&cfg); //read commandline args if(!arg_parse(&cfg, argc-1, argv+1)){ return -1; } //read config file if(!cfg.cfg_file){ fprintf(stderr, "No config file supplied\n"); return -1; } if(!cfg_read(&cfg, cfg.cfg_file)){ cfg_free(&cfg); return -1; } //if not using pgpass, ask for database password if(!cfg.db.use_pgpass){ cfg.db.pass=calloc(sizeof(char),MAX_PASSWORD_LENGTH+1); if(!cfg.db.pass){ fprintf(stderr, "Failed to allocate memory\n"); cfg_free(&cfg); return -1; } fprintf(stderr, "DB Password: "******"\fWaiting..."); ask_password(cfg.db.pass, MAX_PASSWORD_LENGTH); } //check for sane config if(!cfg_sane(&cfg)){ cfg_free(&cfg); return -1; } //connect to database if persistent if(cfg.db.persist_connection){ if(!pq_connect(&(cfg.db))){ cfg_free(&cfg); return -1; } if(cfg.verbosity>2){ fprintf(stderr, "Database connection established\n"); } } //connect to remote devices if(!comms_open(&cfg)){ comms_close(&cfg); pq_close(&(cfg.db)); cfg_free(&cfg); return -1; } //set up signal handlers signal(SIGINT, sig_interrupt); signal(SIGTERM, sig_terminate); //run the state machine garfield_pos(&cfg); comms_close(&cfg); pq_close(&(cfg.db)); cfg_free(&cfg); return 0; }
/* * Read all reloadable configuration directives */ static void config_reload(int reload) { Cfg *cfg; CfgGroup *grp; List *groups; long map_url_max; Octstr *s; long i; long new_value; int new_bool; Octstr *http_proxy_host; Octstr *http_interface_name; long http_proxy_port; int http_proxy_ssl = 0; List *http_proxy_exceptions; Octstr *http_proxy_username; Octstr *http_proxy_password; Octstr *http_proxy_exceptions_regex; int warn_map_url = 0; /* XXX TO-DO: if(reload) implement wapbox.suspend/mutex.lock */ if (reload) debug("config_reload", 0, "Reloading configuration"); /* * NOTE: we could lstat config file and only reload if it was modified, * but as we have a include directive, we don't know every file's * timestamp at this point */ cfg = cfg_create(config_filename); if (cfg_read(cfg) == -1) { warning(0, "Couldn't %sload configuration from `%s'.", (reload ? "re" : ""), octstr_get_cstr(config_filename)); return; } grp = cfg_get_single_group(cfg, octstr_imm("core")); http_proxy_host = cfg_get(grp, octstr_imm("http-proxy-host")); http_proxy_port = -1; cfg_get_integer(&http_proxy_port, grp, octstr_imm("http-proxy-port")); #ifdef HAVE_LIBSSL cfg_get_bool(&http_proxy_ssl, grp, octstr_imm("http-proxy-ssl")); #endif /* HAVE_LIBSSL */ http_proxy_username = cfg_get(grp, octstr_imm("http-proxy-username")); http_proxy_password = cfg_get(grp, octstr_imm("http-proxy-password")); http_proxy_exceptions = cfg_get_list(grp, octstr_imm("http-proxy-exceptions")); http_proxy_exceptions_regex = cfg_get(grp, octstr_imm("http-proxy-exceptions-regex")); if (http_proxy_host != NULL && http_proxy_port > 0) { http_use_proxy(http_proxy_host, http_proxy_port, http_proxy_ssl, http_proxy_exceptions, http_proxy_username, http_proxy_password, http_proxy_exceptions_regex); } octstr_destroy(http_proxy_host); octstr_destroy(http_proxy_username); octstr_destroy(http_proxy_password); octstr_destroy(http_proxy_exceptions_regex); gwlist_destroy(http_proxy_exceptions, octstr_destroy_item); grp = cfg_get_single_group(cfg, octstr_imm("wapbox")); if (grp == NULL) { warning(0, "No 'wapbox' group in configuration."); return; } if (cfg_get_integer(&new_value, grp, octstr_imm("log-level")) != -1) { reload_int(reload, octstr_imm("log level"), &logfilelevel, &new_value); logfilelevel = new_value; log_set_log_level(new_value); } /* Configure interface name for http requests */ http_interface_name = cfg_get(grp, octstr_imm("http-interface-name")); if (http_interface_name != NULL) { http_set_interface(http_interface_name); octstr_destroy(http_interface_name); } /* * users may define 'smart-errors' to have WML decks returned with * error information instead of signaling using the HTTP reply codes */ cfg_get_bool(&new_bool, grp, octstr_imm("smart-errors")); reload_bool(reload, octstr_imm("smart error messaging"), &wsp_smart_errors, &new_bool); /* decide if our XML parser within WML compiler is strict or relaxed */ cfg_get_bool(&new_bool, grp, octstr_imm("wml-strict")); reload_bool(reload, octstr_imm("XML within WML has to be strict"), &wml_xml_strict, &new_bool); if (!wml_xml_strict) warning(0, "'wml-strict' config directive has been set to no, " "this may make you vulnerable against XML bogus input."); if (cfg_get_bool(&new_bool, grp, octstr_imm("concatenation")) == 1) reload_bool(reload, octstr_imm("concatenation"), &concatenation, &new_bool); else concatenation = 1; if (cfg_get_integer(&new_value, grp, octstr_imm("max-messages")) != -1) { max_messages = new_value; reload_int(reload, octstr_imm("max messages"), &max_messages, &new_value); } /* configure URL mappings */ map_url_max = -1; cfg_get_integer(&map_url_max, grp, octstr_imm("map-url-max")); if (map_url_max > 0) warn_map_url = 1; if (reload) { /* clear old map */ wap_map_destroy(); wap_map_user_destroy(); } if ((device_home = cfg_get(grp, octstr_imm("device-home"))) != NULL) { wap_map_url_config_device_home(octstr_get_cstr(device_home)); } if ((s = cfg_get(grp, octstr_imm("map-url"))) != NULL) { warn_map_url = 1; wap_map_url_config(octstr_get_cstr(s)); octstr_destroy(s); } debug("wap", 0, "map_url_max = %ld", map_url_max); for (i = 0; i <= map_url_max; i++) { Octstr *name; name = octstr_format("map-url-%d", i); if ((s = cfg_get(grp, name)) != NULL) wap_map_url_config(octstr_get_cstr(s)); octstr_destroy(name); } /* warn the user that he/she should use the new wap-url-map groups */ if (warn_map_url) warning(0, "'map-url' config directive and related are deprecated, " "please use wap-url-map group"); /* configure wap-url-map */ groups = cfg_get_multi_group(cfg, octstr_imm("wap-url-map")); while (groups && (grp = gwlist_extract_first(groups)) != NULL) { Octstr *name, *url, *map_url, *send_msisdn_query; Octstr *send_msisdn_header, *send_msisdn_format; int accept_cookies; name = cfg_get(grp, octstr_imm("name")); url = cfg_get(grp, octstr_imm("url")); map_url = cfg_get(grp, octstr_imm("map-url")); send_msisdn_query = cfg_get(grp, octstr_imm("send-msisdn-query")); send_msisdn_header = cfg_get(grp, octstr_imm("send-msisdn-header")); send_msisdn_format = cfg_get(grp, octstr_imm("send-msisdn-format")); accept_cookies = -1; cfg_get_bool(&accept_cookies, grp, octstr_imm("accept-cookies")); wap_map_add_url(name, url, map_url, send_msisdn_query, send_msisdn_header, send_msisdn_format, accept_cookies); info(0, "Added wap-url-map <%s> with url <%s>, map-url <%s>, " "send-msisdn-query <%s>, send-msisdn-header <%s>, " "send-msisdn-format <%s>, accept-cookies <%s>", octstr_get_cstr(name), octstr_get_cstr(url), octstr_get_cstr(map_url), octstr_get_cstr(send_msisdn_query), octstr_get_cstr(send_msisdn_header), octstr_get_cstr(send_msisdn_format), (accept_cookies ? "yes" : "no")); } gwlist_destroy(groups, NULL); /* configure wap-user-map */ groups = cfg_get_multi_group(cfg, octstr_imm("wap-user-map")); while (groups && (grp = gwlist_extract_first(groups)) != NULL) { Octstr *name, *user, *pass, *msisdn; name = cfg_get(grp, octstr_imm("name")); user = cfg_get(grp, octstr_imm("user")); pass = cfg_get(grp, octstr_imm("pass")); msisdn = cfg_get(grp, octstr_imm("msisdn")); wap_map_add_user(name, user, pass, msisdn); info(0,"Added wap-user-map <%s> with credentials <%s:%s> " "and MSISDN <%s>", octstr_get_cstr(name), octstr_get_cstr(user), octstr_get_cstr(pass), octstr_get_cstr(msisdn)); } gwlist_destroy(groups, NULL); cfg_destroy(cfg); /* XXX TO-DO: if(reload) implement wapbox.resume/mutex.unlock */ }
int main(int argc, char **argv) { int cf_index; int restart = 0; Msg *msg; Cfg *cfg; double heartbeat_freq = DEFAULT_HEARTBEAT; gwlib_init(); cf_index = get_and_set_debugs(argc, argv, NULL); setup_signal_handlers(); if (argv[cf_index] == NULL) config_filename = octstr_create("kannel.conf"); else config_filename = octstr_create(argv[cf_index]); cfg = cfg_create(config_filename); if (cfg_read(cfg) == -1) panic(0, "Couldn't read configuration from `%s'.", octstr_get_cstr(config_filename)); report_versions("wapbox"); cfg = init_wapbox(cfg); info(0, "------------------------------------------------------------"); info(0, GW_NAME " wapbox version %s starting up.", GW_VERSION); sequence_counter = counter_create(); wsp_session_init(&wtp_resp_dispatch_event, &wtp_initiator_dispatch_event, &wap_appl_dispatch, &wap_push_ppg_dispatch_event); wsp_unit_init(&dispatch_datagram, &wap_appl_dispatch); wsp_push_client_init(&wsp_push_client_dispatch_event, &wtp_resp_dispatch_event); if (cfg) wtp_initiator_init(&dispatch_datagram, &wsp_session_dispatch_event, timer_freq); wtp_resp_init(&dispatch_datagram, &wsp_session_dispatch_event, &wsp_push_client_dispatch_event, timer_freq); wap_appl_init(cfg); #if (HAVE_WTLS_OPENSSL) wtls_secmgr_init(); wtls_init(&write_to_bearerbox); #endif if (cfg) { wap_push_ota_init(&wsp_session_dispatch_event, &wsp_unit_dispatch_event); wap_push_ppg_init(&wap_push_ota_dispatch_event, &wap_appl_dispatch, cfg); } wml_init(wml_xml_strict); if (bearerbox_host == NULL) bearerbox_host = octstr_create(BB_DEFAULT_HOST); connect_to_bearerbox(bearerbox_host, bearerbox_port, bearerbox_ssl, NULL /* bearerbox_our_port */); if (cfg) wap_push_ota_bb_address_set(bearerbox_host); program_status = running; if (0 > heartbeat_start(write_to_bearerbox, heartbeat_freq, wap_appl_get_load)) { info(0, GW_NAME "Could not start heartbeat."); } while (program_status != shutting_down) { WAPEvent *dgram; int ret; /* block infinite for reading messages */ ret = read_from_bearerbox(&msg, INFINITE_TIME); if (ret == -1) { error(0, "Bearerbox is gone, restarting"); program_status = shutting_down; restart = 1; break; } else if (ret == 1) /* timeout */ continue; else if (msg == NULL) /* just to be sure, may not happens */ break; if (msg_type(msg) == admin) { if (msg->admin.command == cmd_shutdown) { info(0, "Bearerbox told us to die"); program_status = shutting_down; } else if (msg->admin.command == cmd_restart) { info(0, "Bearerbox told us to restart"); restart = 1; program_status = shutting_down; } /* * XXXX here should be suspend/resume, add RSN */ } else if (msg_type(msg) == wdp_datagram) { switch (msg->wdp_datagram.destination_port) { case CONNECTIONLESS_PORT: case CONNECTION_ORIENTED_PORT: dgram = wap_event_create(T_DUnitdata_Ind); dgram->u.T_DUnitdata_Ind.addr_tuple = wap_addr_tuple_create( msg->wdp_datagram.source_address, msg->wdp_datagram.source_port, msg->wdp_datagram.destination_address, msg->wdp_datagram.destination_port); dgram->u.T_DUnitdata_Ind.user_data = msg->wdp_datagram.user_data; msg->wdp_datagram.user_data = NULL; wap_dispatch_datagram(dgram); break; case WTLS_CONNECTIONLESS_PORT: case WTLS_CONNECTION_ORIENTED_PORT: #if (HAVE_WTLS_OPENSSL) dgram = wtls_unpack_wdp_datagram(msg); if (dgram != NULL) wtls_dispatch_event(dgram); #endif break; default: panic(0,"Bad packet received! This shouldn't happen!"); break; } } else { warning(0, "Received other message than wdp/admin, ignoring!"); } msg_destroy(msg); } info(0, GW_NAME " wapbox terminating."); program_status = shutting_down; heartbeat_stop(ALL_HEARTBEATS); counter_destroy(sequence_counter); if (cfg) wtp_initiator_shutdown(); wtp_resp_shutdown(); wsp_push_client_shutdown(); wsp_unit_shutdown(); wsp_session_shutdown(); wap_appl_shutdown(); radius_acct_shutdown(); if (cfg) { wap_push_ota_shutdown(); wap_push_ppg_shutdown(); } wml_shutdown(); close_connection_to_bearerbox(); alog_close(); wap_map_destroy(); wap_map_user_destroy(); octstr_destroy(device_home); octstr_destroy(bearerbox_host); octstr_destroy(config_filename); /* * Just sleep for a while to get bearerbox chance to restart. * Otherwise we will fail while trying to connect to bearerbox! */ if (restart) { gwthread_sleep(10.0); /* now really restart */ restart_box(argv); } log_close_all(); gwlib_shutdown(); return 0; }
int main(int argc, char **argv) { struct sigaction act; int port; int opt; double run_time; char *log_file; char *config_file; gwlib_init(); act.sa_handler = handler; sigemptyset(&act.sa_mask); act.sa_flags = 0; sigaction(SIGTERM, &act, NULL); sigaction(SIGINT, &act, NULL); port = 2345; smsc_system_id = octstr_create("kannel_smpp"); smsc_source_addr = octstr_create("123456"); message_id_counter = counter_create(); bearerbox_host = octstr_create("127.0.0.1"); port_for_smsbox = 13001; max_to_esme = 1; num_to_esme = counter_create(); num_from_esme = counter_create(); num_to_bearerbox = counter_create(); num_from_bearerbox = counter_create(); log_file = config_file = NULL; while ((opt = getopt(argc, argv, "hv:p:m:l:c:")) != EOF) { switch (opt) { case 'v': log_set_output_level(atoi(optarg)); break; case 'h': help(); exit(0); case 'm': max_to_esme = atoi(optarg); break; case 'p': port = atoi(optarg); break; case 'l': log_file = optarg; break; case 'c': config_file = optarg; break; case '?': default: error(0, "Invalid option %c", opt); help(); panic(0, "Stopping."); } } if (log_file != NULL) log_open(log_file, GW_DEBUG, GW_NON_EXCL); if (config_file != NULL) { Cfg *cfg; Octstr *tmp = octstr_create(config_file); cfg = cfg_create(tmp); octstr_destroy(tmp); if (cfg_read(cfg) == -1) panic(0, "Errors in config file."); smpp_pdu_init(cfg); cfg_destroy(cfg); } info(0, "Starting drive_smpp test."); gwthread_create(accept_thread, &port); gwthread_join_all(); debug("test.smpp", 0, "Program exiting normally."); run_time = difftime(last_from_esme, first_to_esme); info(0, "Number of messages sent to ESME: %ld", counter_value(num_to_esme)); info(0, "Number of messages sent to smsbox: %ld", counter_value(num_from_bearerbox)); info(0, "Number of messages sent to bearerbox: %ld", counter_value(num_to_bearerbox)); info(0, "Number of messages sent to SMSC: %ld", counter_value(num_from_esme)); info(0, "Time: %.0f secs", run_time); info(0, "Time until all sent to ESME: %.0f secs", difftime(last_to_esme, start_time)); info(0, "Time from first from bb to last to bb: %.0f secs", difftime(last_to_bb, first_from_bb)); info(0, "Time until all sent to SMSC: %.0f secs", difftime(last_from_esme, start_time)); info(0, "SMPP messages SMSC to ESME: %.1f msgs/sec", counter_value(num_to_esme) / run_time); info(0, "SMPP messages ESME to SMSC: %.1f msgs/sec", counter_value(num_from_esme) / run_time); octstr_destroy(smsc_system_id); octstr_destroy(smsc_source_addr); octstr_destroy(bearerbox_host); counter_destroy(num_to_esme); counter_destroy(num_from_esme); counter_destroy(num_to_bearerbox); counter_destroy(num_from_bearerbox); counter_destroy(message_id_counter); gwlib_shutdown(); return 0; }
int main(int argc, char **argv) { int cf_index; Cfg *cfg; bb_status = BB_RUNNING; gwlib_init(); start_time = time(NULL); suspended = gwlist_create(); isolated = gwlist_create(); gwlist_add_producer(suspended); gwlist_add_producer(isolated); cf_index = get_and_set_debugs(argc, argv, check_args); if (argv[cf_index] == NULL) cfg_filename = octstr_create("kannel.conf"); else cfg_filename = octstr_create(argv[cf_index]); cfg = cfg_create(cfg_filename); if (cfg_read(cfg) == -1) panic(0, "Couldn't read configuration from `%s'.", octstr_get_cstr(cfg_filename)); dlr_init(cfg); report_versions("bearerbox"); flow_threads = gwlist_create(); if (init_bearerbox(cfg) == NULL) panic(0, "Initialization failed."); info(0, "----------------------------------------"); info(0, GW_NAME " bearerbox II version %s starting", GW_VERSION); gwthread_sleep(5.0); /* give time to threads to register themselves */ if (store_load(dispatch_into_queue) == -1) panic(0, "Cannot start with store-file failing"); info(0, "MAIN: Start-up done, entering mainloop"); if (bb_status == BB_SUSPENDED) { info(0, "Gateway is now SUSPENDED by startup arguments"); } else if (bb_status == BB_ISOLATED) { info(0, "Gateway is now ISOLATED by startup arguments"); gwlist_remove_producer(suspended); } else { smsc2_resume(1); gwlist_remove_producer(suspended); gwlist_remove_producer(isolated); } while (bb_status != BB_SHUTDOWN && bb_status != BB_DEAD && gwlist_producer_count(flow_threads) > 0) { /* debug("bb", 0, "Main Thread: going to sleep."); */ /* * Not infinite sleep here, because we should notice * when all "flow threads" are dead and shutting bearerbox * down. * XXX if all "flow threads" call gwthread_wakeup(MAIN_THREAD_ID), * we can enter infinite sleep then. */ gwthread_sleep(10.0); /* debug("bb", 0, "Main Thread: woken up."); */ if (bb_todo == 0) { continue; } if (bb_todo & BB_LOGREOPEN) { warning(0, "SIGHUP received, catching and re-opening logs"); log_reopen(); alog_reopen(); bb_todo = bb_todo & ~BB_LOGREOPEN; } if (bb_todo & BB_CHECKLEAKS) { warning(0, "SIGQUIT received, reporting memory usage."); gw_check_leaks(); bb_todo = bb_todo & ~BB_CHECKLEAKS; } } if (bb_status == BB_SHUTDOWN || bb_status == BB_DEAD) warning(0, "Killing signal or HTTP admin command received, shutting down..."); /* call shutdown */ bb_shutdown(); /* wait until flow threads exit */ while (gwlist_consume(flow_threads) != NULL) ; info(0, "All flow threads have died, killing core"); bb_status = BB_DEAD; httpadmin_stop(); boxc_cleanup(); smsc2_cleanup(); store_shutdown(); empty_msg_lists(); gwlist_destroy(flow_threads, NULL); gwlist_destroy(suspended, NULL); gwlist_destroy(isolated, NULL); mutex_destroy(status_mutex); alog_close(); /* if we have any */ bb_alog_shutdown(); cfg_destroy(cfg); octstr_destroy(cfg_filename); dlr_shutdown(); /* now really restart */ if (restart) restart_box(argv); gwlib_shutdown(); return 0; }
int main(int argc, char **argv) { int i, opt; long repeats; URLTranslationList *list; URLTranslation *t; Cfg *cfg; Octstr *name; gwlib_init(); repeats = 1; while ((opt = getopt(argc, argv, "hr:")) != EOF) { switch (opt) { case 'r': repeats = atoi(optarg); break; case 'h': help(); exit(0); case '?': default: error(0, "Invalid option %c", opt); help(); panic(0, "Stopping."); } } if (optind + 1 >= argc) { error(0, "Missing arguments."); help(); panic(0, "Stopping."); } name = octstr_create(argv[optind]); cfg = cfg_create(name); octstr_destroy(name); if (cfg_read(cfg) == -1) panic(0, "Couldn't read configuration file."); list = urltrans_create(); if (urltrans_add_cfg(list, cfg) == -1) panic(0, "Error parsing configuration."); while (repeats-- > 0) { for (i = optind + 1; i < argc; ++i) { Msg *msg = msg_create(sms); msg->sms.msgdata = octstr_create(argv[i]); t = urltrans_find(list, msg); info(0, "type = %d", urltrans_type(t)); msg_destroy(msg); } } urltrans_destroy(list); cfg_destroy(cfg); gwlib_shutdown(); return 0; }
/* * ---------------------------------------------------------- * openRJ() * ---------------------------------------------------------- */ RJFILE *openRJ( char *RJname ) // open diary-sheet file, system'date was used. { RJFILE *rf; int i; // struct dosdate_t d; char buf[30]; char buf2[30]; int year; if ( access( RJname, 0 ) != 0 ) return NULL; rf = (RJFILE *)malloc( sizeof(RJFILE) ); if ( rf == NULL ) return NULL; memset( rf, '\0', sizeof(RJFILE) ); if ( !(rf->handle = cfg_open(RJname, rjHEAD_SIZE) ) ) { free(rf); return NULL; } if ( !(rf->ds = AllocDS()) ) { cfg_close( rf->handle ); free (rf); return NULL; } cfg_readLine( rf->handle, (char *)&buf, 30 ); if ( strncmp( buf, RJFILEMARK, marlLen ) != 0 ) { // inVaild journal file. cfg_close(rf->handle); free(rf); return NULL; } // locate the segment if( cfg_segment( rf->handle, szSummary, NULL) < 0 ) { // inVaild journal file. cfg_close(rf->handle); free(rf); return NULL; } cfg_read( rf->handle, "OPTIME", buf ); rf->curdate = atol( buf ); cfg_read( rf->handle, "ETIME", buf ); rf->endate = atol( buf ); cfg_read( rf->handle, "STIME", buf ); rf->startdate = atol( buf ); buf[4]='\0'; year = atoi( buf ); for( i = 1; i <= 12; i++ ) { sprintf( buf, "%4d%02d", year, i); // make keyword cfg_read( rf->handle, buf, (char *)&buf2 ); rf->segPos[i-1] = atol( buf2 ); rf->exist[i-1] = ( rf->segPos[i-1] ) ? 1 : 0; } InitializeCriticalSection( &(rf->dCriticalSection) ); return rf; }
int main(int argc, char **argv) { char id[UUID_STR_LEN + 1]; int cf_index, ret, type; Octstr *os, *store_type, *store_location, *status; Msg *msg; CfgGroup *grp; conf_file = NULL; gwlib_init(); //This can be overwritten with the -v flag at runtime log_set_output_level(DEFAULT_LOG_LEVEL); cf_index = get_and_set_debugs(argc, argv, check_args); if (argv[cf_index] == NULL) { print_usage(argv[0]); goto error; } if (conf_file == NULL) conf_file = octstr_create("kannel.conf"); cfg = cfg_create(conf_file); if (cfg_read(cfg) == -1) panic(0, "Couldn't read configuration from `%s'.", octstr_get_cstr(conf_file)); info(0, "1"); grp = cfg_get_single_group(cfg, octstr_imm("core")); if (grp == NULL) { printf("FATAL: Could not load Kannel's core group. Exiting.\n"); return 2; } store_location = cfg_get(grp, octstr_imm("store-location")); store_type = cfg_get(grp, octstr_imm("store-type")); store_init(store_type, store_location, -1, msg_pack, msg_unpack_wrapper); switch (command) { case COMMAND_LIST: printf("Listing records %d -> %d\n", list_from+1, list_limit); print_header(); store_load(print_msg); if (counter == 0) { printf("|%60s%14s%60s|\n", "", "Store is Empty", ""); } print_sep(); break; case COMMAND_DELETE: store_load(msg_count); msg = msg_create(ack); msg->ack.nack = ack_failed; msg->ack.time = time(NULL); uuid_parse(octstr_get_cstr(param_1), msg->ack.id); ret = store_save(msg); if (ret == 0) { printf("Deleted message %s\n", octstr_get_cstr(param_1)); counter--; } else { printf("Could not delete message %s\n", octstr_get_cstr(param_1)); } msg_destroy(msg); break; case COMMAND_EXPORT: counter = 0; type = 0; list = gwlist_create(); store_load(msg_push); printf("Exporting %ld messages...\n", gwlist_len(list)); if ((octstr_compare(param_1, octstr_imm("file")) == 0) || (octstr_compare(param_1, octstr_imm("spool")) == 0)) { store_shutdown(); store_init(param_1, param_2, -1, msg_pack, msg_unpack_wrapper); store_load(msg_count); while ((os = gwlist_extract_first(list)) != NULL) { msg = msg_unpack_wrapper(os); if (msg != NULL) { ret = store_save(msg); if (ret == 0) { counter++; } else { printf("Error saving message\n"); } } else { printf("Error extracting message\n"); } msg_destroy(msg); } status = NULL; } else if (octstr_compare(param_1, octstr_imm("text")) == 0) { status = store_status(BBSTATUS_TEXT); } else if (octstr_compare(param_1, octstr_imm("html")) == 0) { status = store_status(BBSTATUS_HTML); } else if (octstr_compare(param_1, octstr_imm("xml")) == 0) { status = store_status(BBSTATUS_XML); } else { status = NULL; } if (status != NULL) { file = fopen(octstr_get_cstr(param_2), "w"); if (file == NULL) { error(errno, "Failed to open '%s' for writing, cannot create output file", octstr_get_cstr(param_2)); return -1; } octstr_print(file, status); fflush(file); if (file != NULL) fclose(file); //printf("%s", octstr_get_cstr(status)); } gwlist_destroy(list, octstr_destroy_item); break; default: break; } octstr_destroy(store_type); octstr_destroy(store_location); cfg_destroy(cfg); store_shutdown(); error: gwlib_shutdown(); return 1; }
/* parse the content of a config file. We expect the buffer to be * persistent and writable. */ static int cfg_parse(struct config *db, char *p, const char *basedir) { struct section *cur; struct entry *kcur; DBG(3, "start, db %p content\n%.50s\n...\n", db, p); cur = NULL; kcur = NULL; while (p && *p) { char c; char *start; char *key, *val; start = strsep(&p, "\n"); /* to end of line */ start = skipws(start); /* skip whitespace */ trimws(start, p - 1); switch (*start) { case '\0': /* comment line */ case ';': /* comment line */ case '#': /* comment line */ break ; case '[': /* section delimiter */ key = ++start; /* skip it */ while (isalnum(*key) || index("-_", *key)) key++; c = *key; *key = '\0'; if (c) key++; if (c != ']') { DBG(0, "invalid section name %s %c\n", start, c); break; } DBG(1, "start section %s\n", start); cur = cfg_find_section(db, start); if (!cur) { /* allocate new */ cur = calloc(1, sizeof(struct section)); if (cur == NULL) { DBG(0, "cannot allocate section %s\n", start); return -1; } cur->next = db->sections; db->sections = cur; cur->name = start; } break; default: /* it a a key/value string then */ DBG(3, "key name pair\n"); key = parse_name(&start, "=\r\n"); val = key ? parse_name(&start, "\r\n") : NULL; DBG(2, "after parse name next p %p %d\n", p, *p); if (!val) { if (key) { DBG(0, "cannot parse name %s\n", start); return -1; } break; } DBG(1, "key [%s] val [%s]\n", key, val); if (!strcmp(key, "include")) { DBG(1, "processing include %s\n", val); cfg_read(val, basedir, db); break; } if (!cur) { DBG(0, "key val outside section, ignore\n"); break; } kcur = (struct entry *)cfg_find_entry(cur, start); if (kcur) { DBG(0, "replace val %s\n", kcur->value); // XXX should we add ? } else { kcur = calloc(1, sizeof(struct entry)); if (kcur == NULL) { DBG(0, "cannot allocate key %s\n", start); return -1; } kcur->next = cur->keys; cur->keys = kcur; kcur->key = key; } kcur->value = val; break ; } } DBG(1, "END db %p\n", db); return 0; }
void init_config (void) { char inifile[MAX_PATH], ifile[MAX_PATH]; char cfgfile[MAX_PATH]; int i; // set defaults cfg_set_string (CONFIG_NFTP, fl_opt.platform_nick, "language", "english"); // read stored customizations strcpy (cfgfile, paths.user_libpath); str_cats (cfgfile, "nftp.cfg"); if (fl_opt.has_console && !fl_opt.initialized) fly_ask_ok (0, "loading %s......\n", cfgfile); cfg_read (CONFIG_NFTP, cfgfile); if (cmdline.language != NULL) { cfg_set_string (CONFIG_NFTP, fl_opt.platform_nick, "language", cmdline.language); } // load nftp.ini strcpy (inifile, paths.user_libpath); str_cats (inifile, "nftp.ini"); if (fl_opt.has_console && !fl_opt.initialized) fly_ask_ok (0, "loading %s......\n", inifile); if (access (inifile, F_OK) != 0) { // looking for nftp.i file in user dir, then in system dir strcpy (ifile, paths.user_libpath); str_cats (ifile, "nftp.i"); if (access (ifile, R_OK) != 0) { strcpy (ifile, paths.system_libpath); str_cats (ifile, "nftp.i"); if (access (ifile, R_OK) != 0) fly_error ("Cannot find nftp.i neither in %s nor in %s", paths.user_libpath, paths.system_libpath); } if (copy_file (ifile, inifile)) fly_error ("Error copying %s to %s", ifile, inifile); } if (access (inifile, R_OK) != 0) { fly_error ("Cannot read %s", inifile); } GetProfileOptions (inifile); if (cmdline.slowlink) options.slowlink = TRUE; if (options.slowlink) fl_opt.use_ceol = TRUE; for (i=0; i<sizeof(runtime_flags)/sizeof(runtime_flags[0]); i++) { *(runtime_flags[i].value) = runtime_flags[i].def; if (runtime_flags[i].name != NULL && cfg_check_boolean (CONFIG_NFTP, NULL, runtime_flags[i].name)) *(runtime_flags[i].value) = cfg_get_boolean (CONFIG_NFTP, NULL, runtime_flags[i].name); } for (i=0; i<MAX_SITE; i++) { status.resolve_symlinks[i] = TRUE; status.use_flags[i] = TRUE; status.use_proxy[i] = FALSE; status.passive_mode[i] = FALSE; } }