static void sql_to_bearerbox(void *arg) { Boxc *boxc; boxc = gw_malloc(sizeof(Boxc)); boxc->bearerbox_connection = connect_to_bearerbox_real(bearerbox_host, bearerbox_port, bearerbox_port_ssl, NULL /* bb_our_host */); boxc->smsbox_connection = NULL; boxc->client_ip = NULL; boxc->alive = 1; boxc->connect_time = time(NULL); boxc->boxc_id = octstr_duplicate(sqlbox_id); if (boxc->bearerbox_connection == NULL) { boxc_destroy(boxc); return; } gwthread_create(bearerbox_to_sql, boxc); identify_to_bearerbox(boxc); if (gw_sql_fetch_msg_list == NULL || gw_sql_save_list == NULL || limit_per_cycle <= 1) { sql_single(boxc); } else { sql_list(boxc); } boxc_destroy(boxc); }
int main(int argc, char **argv) { int opt; unsigned long sended = 0; Octstr *cf, *rf; gwlib_init(); bb_host = octstr_create("localhost"); bb_port = 13001; bb_ssl = 0; while ((opt = getopt(argc, argv, "hv:b:p:si:n:a:f:D:u:d:r:")) != EOF) { switch (opt) { case 'v': log_set_output_level(atoi(optarg)); break; case 'b': octstr_destroy(bb_host); bb_host = octstr_create(optarg); break; case 'p': bb_port = atoi(optarg); break; case 's': bb_ssl = 1; break; case 'i': smsbox_id = octstr_create(optarg); break; case 'n': service = octstr_create(optarg); break; case 'a': account = octstr_create(optarg); break; case 'f': from = octstr_create(optarg); break; case 'D': dlr_mask = atoi(optarg); break; case 'u': dlr_url = octstr_create(optarg); break; case 'd': delay = atof(optarg); break; case 'r': smsc_id = octstr_create(optarg); break; case '?': default: error(0, "Invalid option %c", opt); help(); panic(0, "Stopping."); } } if (optind == argc || argc-optind < 2) { help(); exit(1); } /* check some mandatory elements */ if (from == NULL) panic(0,"Sender address not specified. Use option -f to specify sender address."); if ((DLR_IS_ENABLED(dlr_mask) && dlr_url == NULL) || (!DLR_IS_ENABLED(dlr_mask) && dlr_url != NULL)) panic(0,"dlr-url address OR dlr-mask not specified. Use option -D or -u to specify dlr values"); rf = octstr_create(argv[argc-1]); cf = octstr_create(argv[argc-2]); report_versions("mtbatch"); write_pid_file(); init_batch(cf, rf); connect_to_bearerbox(bb_host, bb_port, bb_ssl, NULL /* bb_our_host */); identify_to_bearerbox(); gwthread_create(read_messages_from_bearerbox, NULL); sended = run_batch(); /* avoid exiting before sending all msgs */ while(sended > counter_value(counter)) { gwthread_sleep(0.1); } program_status = shutting_down; gwthread_join_all(); octstr_destroy(bb_host); octstr_destroy(smsbox_id); octstr_destroy(content); octstr_destroy(service); octstr_destroy(account); octstr_destroy(dlr_url); octstr_destroy(smsc_id); counter_destroy(counter); gwlist_destroy(lines, octstr_destroy_item); gwlib_shutdown(); return 0; }