int main(int argc, char **argv) { Cfg *cfg; int ret = 1; Octstr *name; int i; gwlib_init(); for (i = 1; i < argc; ++i) { name = octstr_create(argv[i]); cfg = cfg_create(name); octstr_destroy(name); ret = cfg_read(cfg); info(0, "cfg_read returned %d", ret); if (ret == 0) cfg_dump(cfg); cfg_destroy(cfg); } info(0, "Shutting down."); gwlib_shutdown(); return ret; }
int main(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; }
int MergeTest::merge(const char * input, cfg_policy_t policy) { cfg_t inputCfg = cfg_create(t_tmp_allocrator()); EXPECT_TRUE(inputCfg); if (inputCfg) { install(inputCfg, input); } return cfg_merge(m_root, inputCfg, policy, t_em()); }
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; }
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; }
wcs_t wcs_create(char *cfg_path) { struct wcamsrv *ws = calloc(1, sizeof(struct wcamsrv)); if (!ws) { perror("wcs_create"); return NULL; } ws->cfg = cfg_create(cfg_path); if (ws->cfg == NULL) goto err_mem; ws->app = app_create(cfg_get_max_app_event(ws->cfg)); if (ws->app == NULL) goto err_cfg; ws->pool = pool_create(cfg_get_thread_in_pool(ws->cfg)); if (ws->pool == NULL) goto err_app; #if defined(VID_FUNC) ws->vid = vid_create(ws); if (ws->vid == NULL) goto err_pool; #endif if (wcs_srv_init(ws) == -1) goto err_cam; return ws; err_cam: #if defined(VID_FUNC) vid_free(ws->vid); #endif err_pool: pool_free(ws->pool); err_app: app_free(ws->app); err_cfg: cfg_free(ws->cfg); err_mem: free(ws); return NULL; }
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); }
/** * Init service. Keeps calling status pending to tell service control * manager that this process is not hanging. * @param r: restart, true on restart * @param d: daemon returned here. * @param c: config file returned here. * @return false if failed. */ static int service_init(struct svr** d, struct cfg** c) { struct cfg* cfg = NULL; struct svr* svr = NULL; if(!service_cfgfile) { char* newf = lookup_reg_str("Software\\DnssecTrigger", "ConfigFile"); if(newf) service_cfgfile = newf; else service_cfgfile = strdup(CONFIGFILE); if(!service_cfgfile) fatal_exit("out of memory"); } /* create config */ cfg = cfg_create(service_cfgfile); if(!cfg) return 0; report_status(SERVICE_START_PENDING, NO_ERROR, 2800); /* create daemon */ svr = svr_create(cfg); if(!svr) return 0; report_status(SERVICE_START_PENDING, NO_ERROR, 2600); verbose(VERB_QUERY, "winservice - apply settings"); /* apply settings and init */ verbosity = cfg->verbosity + service_cmdline_verbose; log_init(cfg->logfile, cfg->use_syslog, cfg->chroot); report_status(SERVICE_START_PENDING, NO_ERROR, 2400); hook_resolv_localhost(cfg); report_status(SERVICE_START_PENDING, NO_ERROR, 2300); *d = svr; *c = cfg; return 1; }
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; }
/* * ---------------------------------------------------------- * createRJ() * ---------------------------------------------------------- */ RJFILE *createRJ( char *RJname ) // create a empty diary-sheet file, system'date was used. { RJFILE *rf; int i, iy; char buf[30]; char buf2[30]; SYSTEMTIME SystemTime; // address of system time structure /* I am sure to create the file if( access( RJname, 0 ) == 0 ) { // warning... if( ( rf = openRJ( RJname ) ) != NULL ) { return rf; } } */ rf = (RJFILE *)malloc( sizeof(RJFILE) ); if( rf == NULL ) return NULL; memset( rf, '\0', sizeof(RJFILE) ); if ( !(rf->handle = cfg_create(RJname, rjHEAD_SIZE) ) ) { free (rf); return NULL; } if ( !(rf->ds = AllocDS()) ) { cfg_close( rf->handle ); free (rf); return NULL; } cfg_writeLine( rf->handle, RJFILEMARK ); cfg_make(rf->handle, szSummary, 0); GetLocalTime( &SystemTime ); for(iy = 0; iy < MAXYEAR_RJIO; iy++) { for( i=1; i<=12; i++ ) { sprintf( buf, "%4d%02d", SystemTime.wYear+iy, i); // make keyword // enough to content 999,999,999,999 sprintf( buf2,"%014ld",rf->segPos[i-1]); cfg_write( rf->handle, buf, buf2, 1 ); } } sprintf(buf, "%4d%02d%02d", SystemTime.wYear,SystemTime.wMonth,SystemTime.wDay); cfg_write( rf->handle,"OPTIME", buf, 1 ); cfg_write( rf->handle,"ETIME", buf, 1 ); cfg_write( rf->handle,"STIME", buf, 1 ); rf->curdate = atol( buf ); rf->startdate = rf->curdate; rf->endate = rf->curdate; for( i=1; i<=12; i++ ) { rf->segPos[i-1] = 0L; } InitializeCriticalSection( &(rf->dCriticalSection) ); return rf; }
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; }
/* * 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) { 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; }