int main(int argc, char **argv) {
    int i, opt, use_threads;
    struct sigaction act;
    char *filename;
    Octstr *log_filename;
    Octstr *file_contents;
#ifdef HAVE_LIBSSL
    Octstr *ssl_server_cert_file = NULL;
    Octstr *ssl_server_key_file = NULL;
#endif
    char *whitelist_name;
    char *blacklist_name;
    int white_asked,
        black_asked;
    long threads[MAX_THREADS];
    FILE *fp;

    gwlib_init();

    act.sa_handler = sigterm;
    sigemptyset(&act.sa_mask);
    act.sa_flags = 0;
    sigaction(SIGTERM, &act, NULL);
    sigaction(SIGINT, &act, NULL);

    port = 8080;
    use_threads = 1;
    verbose = 1;
    run = 1;
    filename = NULL;
    log_filename = NULL;
    blacklist_name = NULL;
    whitelist_name = NULL;
    white_asked = 0;
    black_asked = 0;

    reply_text = octstr_create("Sent.");

    while ((opt = getopt(argc, argv, "hqv:p:t:f:l:sc:k:b:w:r:H:")) != EOF) {
	switch (opt) {
	case 'v':
	    log_set_output_level(atoi(optarg));
	    break;

        case 'q':
	    verbose = 0;                                           
	    break;

	case 'h':
	    help();
	    exit(0);

	case 'p':
	    port = atoi(optarg);
	    break;

	case 't':
	    use_threads = atoi(optarg);
	    if (use_threads > MAX_THREADS)
            use_threads = MAX_THREADS;
	    break;

        case 'c':
#ifdef HAVE_LIBSSL
	    octstr_destroy(ssl_server_cert_file);
	    ssl_server_cert_file = octstr_create(optarg);
#endif
        break;

        case 'k':
#ifdef HAVE_LIBSSL
	    octstr_destroy(ssl_server_key_file);
	    ssl_server_key_file = octstr_create(optarg);
#endif
        break;

	case 's':
#ifdef HAVE_LIBSSL
        ssl = 1;
#endif   
        break;

	case 'f':
	    filename = optarg;
	    break;

	case 'l':
	    octstr_destroy(log_filename);
	    log_filename = octstr_create(optarg);
	break;

    case 'w':
        whitelist_name = optarg;
        if (whitelist_name == NULL)
            whitelist_name = "";
        white_asked = 1;
	break;

    case 'b':
        blacklist_name = optarg;
        if (blacklist_name == NULL)
            blacklist_name = "";
        black_asked = 1;
	break;

	case 'r':
	    octstr_destroy(reply_text);
        reply_text = octstr_create(optarg);
        break;

	case 'H': {
		Octstr *cont;

        fp = fopen(optarg, "a");
        if (fp == NULL)
            panic(0, "Cannot open header text file %s", optarg);
        cont = octstr_read_file(optarg);
        if (cont == NULL)
            panic(0, "Cannot read header text");
        debug("", 0, "headers are");
        octstr_dump(cont, 0);
        split_headers(cont, &extra_headers);
        fclose(fp);
        octstr_destroy(cont);
        break;
	}

	case '?':
	default:
	    error(0, "Invalid option %c", opt);
	    help();
	    panic(0, "Stopping.");
	}
    }

    if (log_filename != NULL) {
    	log_open(octstr_get_cstr(log_filename), GW_DEBUG, GW_NON_EXCL);
	    octstr_destroy(log_filename);
    }

    if (filename == NULL)
    	file_contents = NULL;
    else
    	file_contents = octstr_read_file(filename);

    if (white_asked) {
        whitelist = octstr_read_file(whitelist_name);
        if (whitelist == NULL)
            panic(0, "Cannot read the whitelist");
    }
    
    if (black_asked) {
        blacklist = octstr_read_file(blacklist_name);
        if (blacklist == NULL)
            panic(0, "Cannot read the blacklist");
    }

#ifdef HAVE_LIBSSL
    /*
     * check if we are doing a SSL-enabled server version here
     * load the required cert and key file
     */
    if (ssl) {
        if (ssl_server_cert_file != NULL && ssl_server_key_file != NULL) {
            use_global_server_certkey_file(ssl_server_cert_file, ssl_server_key_file);
            octstr_destroy(ssl_server_cert_file);
            octstr_destroy(ssl_server_key_file);
        } else {
            panic(0, "certificate and public key need to be given!");
        }
    }
#endif
     
    if (http_open_port(port, ssl) == -1)
        panic(0, "http_open_server failed");

    /*
     * Do the real work in a separate thread so that the main
     * thread can catch signals safely.
     */
    for (i = 0; i < use_threads; ++i) 
        threads[i] = gwthread_create(client_thread, file_contents);

    /* wait for all working threads */
    for (i = 0; i < use_threads; ++i)
        gwthread_join(threads[i]);

    octstr_destroy(reply_text);
    gwlist_destroy(extra_headers, octstr_destroy_item);

    debug("test.http", 0, "Program exiting normally.");
    gwlib_shutdown();
    return 0;
}
Exemple #2
0
int main(int argc, char **argv)
{
    Octstr *filename = NULL;
    unsigned long num = 1, j;
    int opt;
    Octstr *mime, *mime2;
    MIMEEntity *m;

    gwlib_init();
        
    while ((opt = getopt(argc, argv, "hv:n:")) != EOF) {
        switch (opt) {
            case 'v':
                log_set_output_level(atoi(optarg));
                break;
            case 'n':
                num = atoi(optarg);
                break;
            case '?':
            default:
                error(0, "Invalid option %c", opt);
                help();
                panic(0, "Stopping.");
        }
    }
    
    if (optind == argc) {
        help();
        exit(0);
    }

    filename = octstr_create(argv[argc-1]);
    mime = octstr_read_file(octstr_get_cstr(filename));

    for (j = 1; j <= num; j++) {

    info(0,"MIME Octstr from file `%s':", octstr_get_cstr(filename));
    octstr_dump(mime, 0);

    m = mime_octstr_to_entity(mime);

    mime_entity_dump(m);

    mime2 = mime_entity_to_octstr(m);

    info(0, "MIME Octstr after reconstruction:");
    octstr_dump(mime2, 0);

    if (octstr_compare(mime, mime2) != 0) {
        error(0, "MIME content from file `%s' and reconstruction differs!", 
              octstr_get_cstr(filename));
    } else {
        info(0, "MIME Octstr compare result has been successfull.");
    }

    octstr_destroy(mime2);
    mime_entity_destroy(m);

    } /* num times */

    octstr_destroy(filename);
 
    gwlib_shutdown();

    return 0;
}
Exemple #3
0
static void parachute_start(const char *myname, const char *panic_script) {
    time_t last_start = 0, last_panic = 0;
    long respawn_count = 0;
    int status;


    if (panic_script && !is_executable(panic_script))
        panic(0, "Panic script `%s' is not executable for us.", panic_script);

    /* setup sighandler */
    parachute_init_signals(0);

    for (;;) {
        if (respawn_count > 0 && difftime(time(NULL), last_start) < 10) {
            error(0, "Child process died too fast, disabling for 30 sec.");
            gwthread_sleep(30.0);
        }
        if (!(child_pid = fork())) { /* child process */
            parachute_init_signals(1); /* reset sighandlers */
	    return;
        }
	else if (child_pid < 0) {
	    error(errno, "Could not start child process! Will retry in 5 sec.");
	    gwthread_sleep(5.0);
            continue;
	}
	else { /* father process */
	    time(&last_start);
            info(0, "Child process with PID (%ld) started.", (long) child_pid);
            do {
                if (waitpid(child_pid, &status, 0) == child_pid) {
                    /* check here why child terminated */
                   if (WIFEXITED(status) && WEXITSTATUS(status) == 0) {
                       info(0, "Child process exited gracefully, exit...");
                       gwlib_shutdown();
                       exit(0);
                   }
                   else if (WIFEXITED(status)) {
                       error(0, "Caught child PID (%ld) which died with return code %d",
                           (long) child_pid, WEXITSTATUS(status));
                       child_pid = -1;
                   }
                   else if (WIFSIGNALED(status)) {
                       error(0, "Caught child PID (%ld) which died due to signal %d",
                           (long) child_pid, WTERMSIG(status));
                       child_pid = -1;
                   }
                }
                else if (errno != EINTR) {
                    error(errno, "Error while waiting of child process.");
                }
            } while(child_pid > 0);

            if (parachute_shutdown) {
                /* may only happens if child process crashed while shutdown */
                info(0, "Child process crashed while shutdown. Exiting due to signal...");
                info(0, "Going into gwlib_shutdown...");
                gwlib_shutdown();
                info(0, "gwlib_shutdown done... Bye bye...");
                exit(WIFEXITED(status) ? WEXITSTATUS(status) : 0);
            }

            /* check whether it's panic while start */
            if (respawn_count == 0 && difftime(time(NULL), last_start) < 2) {
                info(0, "Child process crashed while starting. Exiting...");
                info(0, "Going into gwlib_shutdown...");
                gwlib_shutdown();
                info(0, "gwlib_shutdown done... Bye bye...");
                exit(WIFEXITED(status) ? WEXITSTATUS(status) : 1);
            }

            respawn_count++;
            if (panic_script && myname && difftime(time(NULL), last_panic) > 300) {
                time(&last_panic);
                debug("kannel", 0, "Executing panic script: %s %s %ld", panic_script, myname, respawn_count);
                execute_panic_script(panic_script, "%s %ld", myname, respawn_count);
            }
            /* sleep a while to get e.g. sockets released */
            gwthread_sleep(5.0);
	}
    }
}
Exemple #4
0
int main(int argc, char **argv)
{
    int opt,
        num_threads;
    time_t start,
           end;
    double run_time;
    long threads[MAX_THREADS];
    long i;
    Octstr *fos;

    gwlib_init();
    num_threads = 1;

    while ((opt = getopt(argc, argv, "HhBbnEpv:qr:t:c:a:i:e:k:d:s:S:I:m:u:")) != EOF) {
        switch(opt) {
	    case 'v':
	        log_set_output_level(atoi(optarg));
	    break;

	    case 'q': 
	        verbose = 0;
	    break;  

	    case 'r':
	        max_pushes = atoi(optarg);      
	    break; 
            
	    case 'i': 
                wait_seconds = atof(optarg);
	    break;

            case 't': 
	        num_threads = atoi(optarg);
                if (num_threads > MAX_THREADS)
		    num_threads = MAX_THREADS;
	    break;

	    case 'H': 
	        use_hardcoded = 1;
	    break;

	    case 'c':
	        content_flag = octstr_create(optarg);
            if (octstr_compare(content_flag, octstr_imm("wml")) != 0 && 
                    octstr_compare(content_flag, octstr_imm("si")) != 0 &&
                    octstr_compare(content_flag, octstr_imm("sl")) != 0 &&
                    octstr_compare(content_flag, octstr_imm("nil")) != 0 &&
                    octstr_compare(content_flag, octstr_imm("mms")) != 0 &&
                    octstr_compare(content_flag, octstr_imm("scrap")) != 0 &&
                    octstr_compare(content_flag, octstr_imm("multipart")) != 0) {
		        octstr_destroy(content_flag);
		        error(0, "TEST_PPG: Content type not known");
		        help();
                         exit(1);
            }
	    break;

	    case 'a':
	        appid_flag = octstr_create(optarg);
                if (octstr_compare(appid_flag, octstr_imm("any")) != 0 && 
                        octstr_compare(appid_flag, octstr_imm("ua")) != 0 &&
                        octstr_compare(appid_flag, octstr_imm("mms")) != 0 &&
                        octstr_compare(appid_flag, octstr_imm("nil")) != 0 &&
                        octstr_compare(appid_flag, octstr_imm("scrap")) != 0) {
		octstr_destroy(appid_flag);
		error(0, "TEST_PPG: Push application id not known");
		help();
                exit(1);
           }
	    break;

            case 'n':
                use_numeric = 1;
            break;

            case 's':
                appid_string = octstr_create(optarg);
                use_string = 1;
            break;

            case 'S':
                content_header = octstr_create(optarg);
                use_content_header = 1;
            break;

	    case 'e':
		content_transfer_encoding = octstr_create(optarg);
                if (octstr_compare(content_transfer_encoding, octstr_imm("base64")) != 0) {
	            octstr_destroy(content_transfer_encoding);
		    error(0, "TEST_PPG: unknown content transfer" 
                      " encoding \"%s\"", octstr_get_cstr(content_transfer_encoding));
		    help();
                    exit(1);
		}
	    break;

	    case 'k':
	        connection = octstr_create(optarg);
                if (octstr_compare(connection, octstr_imm("close")) != 0 && 
                        octstr_compare(connection, octstr_imm("keep-alive")) != 0) {
	            octstr_destroy(connection);
		    error(0, "TEST_PPG: Connection-header unacceptable");
		    help();
                    exit(1);
                }
	    break;

	    case 'h':
	        help();
            exit(1);

	    case 'b':
	        use_headers = 1;
	    break;

            case 'B':
                accept_binary = 1;
            break;

            case 'd':
                delimiter = octstr_create(optarg);
                if (octstr_compare(delimiter, octstr_imm("crlf")) != 0 &&
                        octstr_compare(delimiter, octstr_imm("lf")) != 0) {
                    octstr_destroy(delimiter);
                    error(0, "illegal d value");
                    help();
                    exit(1);
                }
            break;

            case 'E':
                add_epilogue = 1;
            break;

            case 'p':
                add_preamble = 1;
            break;

            case 'I':
                initiator_uri = octstr_create(optarg);
		break;

            case 'm':
                use_dlr_mask = 1;
                dlr_mask = octstr_create(optarg);
            break;

            case 'u':
                use_dlr_url = 1;
                dlr_url = octstr_create(optarg);
            break;

	case '?':
	    default:
	        error(0, "TEST_PPG: Invalid option %c", opt);
            help();
            error(0, "Stopping");
            exit(1);
        }
    }

    if (optind == argc) {
        help();
        exit(1);
    }
    
    push_data = argv + optind;
    num_urls = argc - optind;

    if (content_flag == NULL)
        content_flag = octstr_imm("si");

    if (appid_flag == NULL)
        appid_flag = octstr_imm("ua");

    if (appid_string == NULL)
        appid_string = octstr_imm("x-wap-application-id: wml.ua");

    if (content_header == NULL)
        use_content_header = 0;

    if (dlr_mask == NULL)
        use_dlr_mask = 0;

    if (dlr_url == NULL)
        use_dlr_url = 0;

    if (delimiter == NULL)
        delimiter = octstr_imm("crlf");

    if (use_hardcoded) {
        username = octstr_imm("troo");
        password = octstr_imm("far");
    }

    if (push_data[0] == NULL) {
        error(0, "No ppg address or config file, stopping");
        exit(1);
    }
           
    use_config = 0;
    if (!use_hardcoded) {
        if (push_data[1] == NULL) {
            info(0, "a configuration file input assumed");
            read_test_ppg_config(fos = octstr_format("%s", push_data[0]));
            octstr_destroy(fos);
            use_config = 1;
        }
    }

    if (!use_config)
        push_url = octstr_format("%s", push_data[0]);

    if (!use_hardcoded && !use_config && push_data[1] != NULL) {
        if (push_data[2] == NULL) {
	        error(0, "no pap control document, stopping");
            exit(1);
        } else {
           info(0, "an input without a configuration file assumed");
           content_file = octstr_create(push_data[1]);
           pap_file = octstr_create(push_data[2]);
           debug("test.ppg", 0, "using %s as a content file", push_data[1]);
           debug("test.ppg", 0, "using %s as a control file", push_data[2]);
        }
    }

    boundary = "asdlfkjiurwghasf";
    counter = counter_create();

    time(&start);
    if (num_threads == 0)
        push_thread(http_caller_create());
    else {
        for (i = 0; i < num_threads; ++i)
	        threads[i] = gwthread_create(push_thread, http_caller_create());
	    for (i = 0; i < num_threads; ++i)
	        gwthread_join(threads[i]);
    }
    time(&end);
    run_time = difftime(end, start);
    info(0, "TEST_PPG: %ld requests in %f seconds, %f requests per second",
         max_pushes, run_time, max_pushes / run_time);

    octstr_destroy(content_flag);
    octstr_destroy(appid_flag);
    octstr_destroy(content_header);
    octstr_destroy(content_file);
    octstr_destroy(pap_file);
    octstr_destroy(ssl_client_certkey_file);
    octstr_destroy(username);
    octstr_destroy(password);
    octstr_destroy(push_url);
    octstr_destroy(connection);
    octstr_destroy(delimiter);
    octstr_destroy(dlr_mask);
    octstr_destroy(dlr_url);
    counter_destroy(counter);
    gwlib_shutdown();

    exit(0);
}
Exemple #5
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)
{
    Octstr *message, *whoami;
    struct emimsg *emimsg;

    printf("/* This tool can decode an UCP/EMI packet. <*****@*****.**> */\n\n");

    gwlib_init();

    if (argc < 2)
        panic(0, "Syntax: %s <packet_without_STX/ETX>\n", argv[0]);

    message = octstr_format("\02%s\03", argv[1]); // fit the UCP specs.
    whoami = octstr_create("DECODE");

    emimsg = get_fields(message, whoami);

    if (emimsg != NULL) {
        printf("\n");
        printf("TRN      \t%d\n", emimsg->trn);
        printf("TYPE     \t%c (%s)\n", emimsg->or, emimsg->or == 'R' ? "Result" : "Operation");
        printf("OPERATION\t%d (%s)\n", emimsg->ot, emi_typeop (emimsg->ot));

        if (emimsg->ot == 01) {
            printf("E01_ADC  \t%s\n",
                    octstr_get_cstr(emimsg->fields[E01_ADC]));
            printf("E01_OADC \t%s\n",
                    octstr_get_cstr(emimsg->fields[E01_OADC]));
            printf("E01_AC   \t%s\n",
                    octstr_get_cstr(emimsg->fields[E01_AC]));
            printf("E01_ADC  \t%s\n",
                    octstr_get_cstr(emimsg->fields[E01_ADC]));
            printf("E01_MT   \t%s\n",
                    octstr_get_cstr(emimsg->fields[E01_MT]));
            if (octstr_get_char(emimsg->fields[E01_MT], 0) == '3') {
                charset_gsm_to_latin1(emimsg->fields[E01_AMSG]);
            }
            printf("E01_AMSG \t%s\n",
                    octstr_get_cstr(emimsg->fields[E01_AMSG]));
        }

        if ((emimsg->ot == 31 || (emimsg->ot >= 50 && emimsg->ot <= 60))
                && emimsg->or == 'R' && 
                (octstr_get_char(emimsg->fields[E50_ADC], 0) == 'A' ||
                octstr_get_char(emimsg->fields[E50_ADC], 0) == 'N')) {
            printf("E%d_ACK  \t%s\n", emimsg->ot,
                    octstr_get_cstr(emimsg->fields[E50_ADC]));
            printf("E%d_SM   \t%s\n", emimsg->ot,
                    octstr_get_cstr(emimsg->fields[E50_OADC]));
        }

        if (emimsg->ot == 31 && emimsg->or == 'O') {
            printf("E50_ADC  \t%s\n",
                    octstr_get_cstr(emimsg->fields[E50_ADC]));
            printf("E50_PID  \t%s\n",
                    octstr_get_cstr(emimsg->fields[E50_OADC]));
        }

        if (emimsg->ot >= 50 && emimsg->ot <= 59 && 
                octstr_get_char(emimsg->fields[E50_ADC], 0) != 'A' &&
                octstr_get_char(emimsg->fields[E50_ADC], 0) != 'N') {
            printf("E50_ADC  \t%s\n",
                    octstr_get_cstr(emimsg->fields[E50_ADC]));
            printf("E50_OADC \t%s\n",
                    octstr_get_cstr(emimsg->fields[E50_OADC]));
            printf("E50_AC   \t%s\n",
                    octstr_get_cstr(emimsg->fields[E50_AC]));
            printf("E50_NRQ  \t%s\n",
                    octstr_get_cstr(emimsg->fields[E50_NRQ]));
            printf("E50_NADC \t%s\n",
                    octstr_get_cstr(emimsg->fields[E50_NADC]));
            printf("E50_NT   \t%s\n",
                    octstr_get_cstr(emimsg->fields[E50_NT]));
            printf("E50_NPID \t%s\n",
                    octstr_get_cstr(emimsg->fields[E50_NPID]));
            printf("E50_LRQ  \t%s\n",
                    octstr_get_cstr(emimsg->fields[E50_LRQ]));
            printf("E50_LRAD \t%s\n",
                    octstr_get_cstr(emimsg->fields[E50_LRAD]));
            printf("E50_LPID \t%s\n",
                    octstr_get_cstr(emimsg->fields[E50_LPID]));
            printf("E50_DD   \t%s\n",
                    octstr_get_cstr(emimsg->fields[E50_DD]));
            printf("E50_DDT  \t%s\n",
                    octstr_get_cstr(emimsg->fields[E50_DDT]));
            printf("E50_VP   \t%s\n",
                    octstr_get_cstr(emimsg->fields[E50_VP]));
            printf("E50_RPID \t%s\n",
                    octstr_get_cstr(emimsg->fields[E50_RPID]));
            printf("E50_SCTS \t%s\n",
                    octstr_get_cstr(emimsg->fields[E50_SCTS]));
            printf("E50_DST  \t%s\n",
                    octstr_get_cstr(emimsg->fields[E50_DST]));
            printf("E50_RSN  \t%s\n",
                    octstr_get_cstr(emimsg->fields[E50_RSN]));
            printf("E50_DSCTS\t%s\n",
                    octstr_get_cstr(emimsg->fields[E50_DSCTS]));
            printf("E50_MT   \t%s\n",
                    octstr_get_cstr(emimsg->fields[E50_MT]));
            printf("E50_NB   \t%s\n",
                    octstr_get_cstr(emimsg->fields[E50_NB]));
            printf("E50_NMSG \t%s\n",
                    octstr_get_cstr(emimsg->fields[E50_NMSG]));
            if (emimsg->fields[E50_AMSG])
                octstr_hex_to_binary (emimsg->fields[E50_AMSG]);
            if (octstr_get_char(emimsg->fields[E50_MT], 0) == '3') {
                charset_gsm_to_latin1(emimsg->fields[E50_AMSG]);
            }

            printf("E50_AMSG \t%s\n",
                    octstr_get_cstr(emimsg->fields[E50_AMSG]));
            printf("E50_TMSG \t%s\n",
                    octstr_get_cstr(emimsg->fields[E50_TMSG]));
            printf("E50_MMS  \t%s\n",
                    octstr_get_cstr(emimsg->fields[E50_MMS]));
            printf("E50_PR   \t%s\n",
                    octstr_get_cstr(emimsg->fields[E50_PR]));
            printf("E50_DCS  \t%s\n",
                    octstr_get_cstr(emimsg->fields[E50_DCS]));
            printf("E50_MCLS \t%s\n",
                    octstr_get_cstr(emimsg->fields[E50_MCLS]));
            printf("E50_RPI  \t%s\n",
                    octstr_get_cstr(emimsg->fields[E50_RPI]));
            printf("E50_CPG  \t%s\n",
                    octstr_get_cstr(emimsg->fields[E50_CPG]));
            printf("E50_RPLY \t%s\n",
                    octstr_get_cstr(emimsg->fields[E50_RPLY]));
            printf("E50_OTOA \t%s\n",
                    octstr_get_cstr(emimsg->fields[E50_OTOA]));
            printf("E50_HPLMN\t%s\n",
                    octstr_get_cstr(emimsg->fields[E50_HPLMN]));
            printf("E50_XSER \t%s\n",
                    octstr_get_cstr(emimsg->fields[E50_XSER]));
            printf("E50_RES4 \t%s\n",
                    octstr_get_cstr(emimsg->fields[E50_RES4]));
            printf("E50_RES5 \t%s\n",
                    octstr_get_cstr(emimsg->fields[E50_RES5]));
        }

        if ((emimsg->ot == 60 || emimsg->ot == 61) &&
                (octstr_get_char(emimsg->fields[E50_ADC], 0) != 'A' &&
                octstr_get_char(emimsg->fields[E50_ADC], 0) != 'N')) {
            printf("E60_OADC  \t%s\n",
                    octstr_get_cstr(emimsg->fields[E60_OADC]));
            printf("E60_OTON  \t%s\n",
                    octstr_get_cstr(emimsg->fields[E60_OTON]));
            printf("E60_ONPI  \t%s\n",
                    octstr_get_cstr(emimsg->fields[E60_ONPI]));
            printf("E60_STYP  \t%s\n",
                    octstr_get_cstr(emimsg->fields[E60_STYP]));
            if (emimsg->fields[E60_PWD])
                octstr_hex_to_binary (emimsg->fields[E60_PWD]);
            printf("E60_PWD   \t%s\n",
                    octstr_get_cstr(emimsg->fields[E60_PWD]));
            printf("E60_NPWD  \t%s\n",
                    octstr_get_cstr(emimsg->fields[E60_NPWD]));
            printf("E60_VERS  \t%s\n",
                    octstr_get_cstr(emimsg->fields[E60_VERS]));
            printf("E60_LADC  \t%s\n",
                    octstr_get_cstr(emimsg->fields[E60_LADC]));
            printf("E60_LTON  \t%s\n",
                    octstr_get_cstr(emimsg->fields[E60_LTON]));
            printf("E60_LNPI  \t%s\n",
                    octstr_get_cstr(emimsg->fields[E60_LNPI]));
            printf("E60_OPID  \t%s\n",
                    octstr_get_cstr(emimsg->fields[E60_OPID]));
            printf("E60_RES1  \t%s\n",
                    octstr_get_cstr(emimsg->fields[E60_RES1]));
        }
    }

    octstr_destroy(message);
    octstr_destroy(whoami);
    gwlib_shutdown();
    
    return 0;
}
Exemple #7
0
int main(int argc, char **argv) {
	int i;
	Octstr *packet = NULL;
	Octstr *newpacket = NULL;
	WTP_PDU *pdu = NULL;
	Octstr *wsp_data = NULL;
	WSP_PDU *wsp = NULL;

	gwlib_init();

	for (i = 1; i < argc; i++) {
		octstr_destroy(packet);  packet = NULL;
		octstr_destroy(newpacket);  newpacket = NULL;
		octstr_destroy(wsp_data);  wsp_data = NULL;
		wtp_pdu_destroy(pdu);  pdu = NULL;
		wsp_pdu_destroy(wsp);  wsp = NULL;

		packet = octstr_read_file(argv[i]);
		pdu = wtp_pdu_unpack(packet);
		if (!pdu) {
			warning(0, "Unpacking PDU %s failed", argv[i]);
			continue;
		}
		debug("test", 0, "PDU %s:", argv[i]);  
		wtp_pdu_dump(pdu, 0);
		newpacket = wtp_pdu_pack(pdu);
		if (!newpacket) {
			warning(0, "Repacking PDU %s failed", argv[i]);
			continue;
		}
		if (octstr_compare(packet, newpacket) != 0) {
			error(0, "Repacking PDU %s changed it", argv[i]);
			debug("test", 0, "Original:");
			octstr_dump(packet, 1);
			debug("test", 0, "New:");
			octstr_dump(newpacket, 1);
			continue;
		}
		if (pdu->type == Invoke) {
			wsp_data = pdu->u.Invoke.user_data;
		} else if (pdu->type == Result) {
			wsp_data = pdu->u.Result.user_data;
		} else {
			continue;
		}
		wsp_data = octstr_duplicate(wsp_data);

		wsp = wsp_pdu_unpack(wsp_data);
		if (!wsp) {
			warning(0, "Unpacking WSP data in %s failed", argv[i]);
			continue;
		}
		wsp_pdu_dump(wsp, 0);
		octstr_destroy(newpacket);
		newpacket = wsp_pdu_pack(wsp);
		if (!newpacket) {
			warning(0, "Repacking WSP data in %s failed", argv[i]);
			continue;
		}
		if (octstr_compare(wsp_data, newpacket) != 0) {
			error(0, "Repacking WSP data in %s changed it",
				argv[i]);
			debug("test", 0, "Original:");
			octstr_dump(wsp_data, 1);
			debug("test", 0, "New:");
			octstr_dump(newpacket, 1);
			continue;
		}
	}

	octstr_destroy(packet);
	octstr_destroy(newpacket);
	wtp_pdu_destroy(pdu);

	gwlib_shutdown();
    	return 0;
}
Exemple #8
0
int main(int argc, char **argv)
{
    int opt,
        file,
        have_charset,
        ret;
    FILE *fp;
    Octstr *output,
           *si_doc,
           *si_binary;

    gwlib_init();
    file = 0;
    have_charset = 0;
    fp = NULL;

    while ((opt = getopt(argc, argv, "hf:c:v:")) != EOF) {
        switch (opt) {
        case 'h':
	    help();
            exit(1);
	break;

        case 'f':
	    file = 1;
	    file_name = octstr_create(optarg);
            fp = fopen(optarg, "a");
            if (fp == NULL)
	        panic(0, "Cannot open output file");
	break;

        case 'c':
	    have_charset = 1;
	    charset = octstr_create(optarg);
	break;

        case 'v':
	    log_set_output_level(atoi(optarg));
	break;

        case '?':
        default:
	    error(0, "Invalid option %c", opt);
            help();
            panic(0, "Stopping");
	break;
        }
    }

    if (optind >= argc) {
        error(0, "Missing arguments");
        help();
        panic(0, "Stopping");
    }

    si_doc = octstr_read_file(argv[optind]);
    if (si_doc == NULL)
        panic(0, "Cannot read the si document");

    if (!have_charset)
        charset = NULL;
    ret = si_compile(si_doc, charset, &si_binary);
    output = octstr_format("%s", "si compiler returned %d\n", ret);

    if (ret == 0) {
        if (fp == NULL)
	    fp = stdout;
        octstr_append(output, octstr_imm("content being\n"));
        octstr_append(output, si_binary);
    }

    if (file)
        octstr_pretty_print(fp, output);
    else {
        debug("test.si", 0, "si binary was");
        octstr_dump(si_binary, 0);
    }

    if (have_charset)
        octstr_destroy(charset);
    if (file) {
        fclose(fp);
        octstr_destroy(file_name);
    }
    
    octstr_destroy(si_doc);
    octstr_destroy(si_binary);
    octstr_destroy(output);
    gwlib_shutdown();
    return 0;
}
Exemple #9
0
int main(int argc, char **argv) 
{
    int opt;
    Cfg *cfg = NULL;
	
	gwlib_init();
    
    server_port = CONNECTION_ORIENTED_PORT;
    
    while ((opt = getopt(argc, argv, "v:meti:p:")) != EOF) {

        switch (opt) {
            case 'v':
                log_set_output_level(atoi(optarg));
                break;

            case 'm':
                verbose += 1;                                           
                break;

            case 'e':
                verbose += 2;
                break;

            case 't':
                verbose += 4;
                break;
                
            case 'h':
                help();
                exit(0);

            case 'i':
                interface_name = octstr_create(optarg);
                break;
                
            case 'p':
                server_port = atoi(optarg);
                break;

            case '?':
            default:
                error(0, "Invalid option %c", opt);
                help();
                panic(0, "Stopping.");
        }
    }
    
    if (optind == argc) {
        help();
        exit(0);
    }

    /* get the host or IP of the real wap gw to forward the WDP packets */
    wapgw = octstr_create(argv[optind]);

    /* if no interface was given use 0.0.0.0 */
    if (!interface_name)
        interface_name = octstr_create("*");

    report_versions("wapproxy");

    /* initialize main inbound and outbound queues */
    outgoing_wdp = gwlist_create();
    incoming_wdp = gwlist_create();
    flow_threads = gwlist_create();

    outgoing_wdp_counter = counter_create();
    incoming_wdp_counter = counter_create();

    /* start the main UDP listening threads */
    udp_start(cfg);

    gwlist_add_producer(outgoing_wdp);    
    
    debug("bb", 0, "starting WDP routers");
    if (gwthread_create(service_router, NULL) == -1)
        panic(0, "Failed to start a new thread for inbound WDP routing");
    if (gwthread_create(wdp_router, NULL) == -1)
        panic(0, "Failed to start a new thread for outbound WDP routing");

    gwthread_sleep(5.0); /* give time to threads to register themselves */

    while (gwlist_consume(flow_threads) != NULL)
	;

    udp_shutdown();

    gwlist_remove_producer(outgoing_wdp);

    gwlist_destroy(flow_threads, NULL);
    gwlist_destroy(incoming_wdp, NULL);
    gwlist_destroy(outgoing_wdp, NULL);

    counter_destroy(incoming_wdp_counter);
    counter_destroy(outgoing_wdp_counter);
    octstr_destroy(interface_name);
    octstr_destroy(wapgw);

    gwlib_shutdown();

	return 0;
}
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;
}
Exemple #11
0
int main(int argc, char **argv)
{
    Octstr *mime_content,
           *pap_content,
           *push_data,
           *rdf_content,
           *boundary,
           *push_content_file = NULL,
           *this_header,
           *pap_osname,
           *data_osname;
    List *content_headers,
         *source_parts;
    char *pap_content_file,
         *push_data_file,
         *rdf_content_file;
    int ret,
        std_out,
        opt,
        d_file,
        c_file;
    FILE *fp1,
         *fp2,
         *fp3;

    gwlib_init();
    std_out = 0;
    d_file = 0;
    c_file = 0;
    data_osname = NULL;
    pap_osname = NULL;

    while ((opt = getopt(argc, argv, "hd:sc:")) != EOF) {
        switch(opt) {
            case 'h':
                help();
                exit(1);
            break;

            case 'd':
	        d_file = 1;
                data_osname = octstr_create(optarg);
            break;

            case 'c':
	        c_file = 1;
                pap_osname = octstr_create(optarg);
            break;

            case 's':
                std_out = 1;
            break;

            case '?':
            default:
                error(0, "Invalid option %c", opt);
                help();
                panic(0, "Stopping");
            break;
        }
    }    

    if (optind >= argc) {
        help();
        panic(0, "missing arguments, stopping");
    }

    if (!c_file)
        pap_content_file = "test/pap.txt";
    else
        pap_content_file = octstr_get_cstr(pap_osname);
    if (!d_file)
        push_data_file = "test/data.txt";
    else
        push_data_file = octstr_get_cstr(data_osname);
    rdf_content_file = "test/rdf.txt";

    mime_content = octstr_read_file(argv[optind]);
    if (mime_content == NULL) {
        octstr_destroy(mime_content);
        error(0, "No MIME source");
        panic(0, "Stopping");
    }

    source_parts = octstr_split(mime_content, octstr_imm("content="));
    if (gwlist_len(source_parts) == 1) {     /* a hack to circumvent a bug */
        error(0, "Badly formatted source:");
        octstr_destroy(mime_content);
        gwlist_destroy(source_parts, octstr_destroy_item);
        panic(0, "Stopping");
    }

    boundary = gwlist_extract_first(source_parts);
    octstr_delete(boundary, 0, octstr_len(octstr_imm("boundary=")));
    if (skip_tail(&boundary, ';') == 0) {
        error(0, "Cannot determine boundary, no delimiter; possible");
        octstr_dump(boundary, 0);
        goto no_parse;
    }
    
    octstr_destroy(mime_content);
    mime_content = gwlist_extract_first(source_parts);
    if (skip_tail(&mime_content, ';') == 0){
        error(0, "Cannot determine mime content, no delimiter");
        octstr_dump(mime_content, 0);
        goto no_parse;
    }
    prepend_crlf(&mime_content);
    add_crs(mime_content);
    append_crlf(mime_content);
    
    ret = mime_parse(boundary, mime_content, &pap_content, &push_data, 
                     &content_headers, &rdf_content);
    if (ret == 0) {
        error(0, "Mime_parse returned 0, cannot continue");
        goto error;
    }

    remove_crs(pap_content);
    if (!std_out) {
        fp1 = fopen(pap_content_file, "a");
        if (fp1 == NULL) {
            error(0, "Cannot open the file for pap control message");
            goto error;
        }
        octstr_print(fp1, pap_content);
        debug("test.mime", 0, "pap control message appended to the file");
        fclose(fp1);
    } else {
        debug("test.mime", 0, "pap control message was");
        octstr_dump(pap_content, 0);
    }

    remove_crs(push_data);
    if (!std_out) {
        fp2 = fopen(push_data_file, "a");
        if (fp2 == NULL) {
            error(0, "Cannot open the push data file");
            goto error;
        }
        push_content_file = octstr_create("");
        octstr_append(push_content_file, octstr_imm("headers="));
        while (gwlist_len(content_headers) > 0) {
            octstr_append(push_content_file, 
                          this_header = gwlist_extract_first(content_headers));
            octstr_format_append(push_content_file, "%c", ' ');
            octstr_destroy(this_header);
        }
        octstr_append(push_content_file, octstr_imm(";\n"));
        octstr_append(push_content_file, octstr_imm("content="));
        octstr_append(push_content_file, push_data);
        octstr_append(push_content_file, octstr_imm(";\n"));
        octstr_print(fp2, push_content_file);
        debug("test.mime", 0, "push content appended to the file");
        fclose(fp2);
    } else {
        debug("test.mime", 0, "Content headers were");
        http_header_dump(content_headers);
        debug("test.mime", 0, "And push content itself");
        octstr_dump(push_data, 0);
    }

    if (rdf_content != NULL)
        remove_crs(rdf_content);
    if (!std_out && rdf_content != NULL) {
        fp3 = NULL;
        if (rdf_content != NULL) {
            fp3 = fopen(rdf_content_file, "a");
            if (fp3 == NULL) {
                error(0, "Cannot open the rdf file");
                goto cerror;
             }
            octstr_print(fp3, rdf_content);
            debug("test.mime", 0, "push caps message appended to the file");
            fclose(fp3);
        }
    } else {
        if (rdf_content != NULL) {
            debug("test.mime", 0, "push caps message was");
            octstr_dump(rdf_content, 0);
        }
    }
    
    octstr_destroy(boundary);
    octstr_destroy(mime_content);
    octstr_destroy(pap_content);
    octstr_destroy(push_data);
    octstr_destroy(rdf_content);
    octstr_destroy(pap_osname);
    octstr_destroy(data_osname);
    http_destroy_headers(content_headers);
    gwlist_destroy(source_parts, octstr_destroy_item);
    octstr_destroy(push_content_file);
    gwlib_shutdown();

    info(0, "MIME data parsed successfully");
    return 0;

no_parse:
    octstr_destroy(mime_content);
    octstr_destroy(pap_osname);
    octstr_destroy(data_osname);
    gwlist_destroy(source_parts, octstr_destroy_item);
    octstr_destroy(boundary);
    gwlib_shutdown();
    panic(0, "Stopping");

error:
    octstr_destroy(mime_content);
    gwlist_destroy(source_parts, octstr_destroy_item);
    octstr_destroy(boundary);
    octstr_destroy(pap_content);
    octstr_destroy(push_data);
    octstr_destroy(pap_osname);
    octstr_destroy(data_osname);
    http_destroy_headers(content_headers);
    octstr_destroy(rdf_content);
    gwlib_shutdown();
    panic(0, "Stopping");

cerror:
    octstr_destroy(mime_content);
    gwlist_destroy(source_parts, octstr_destroy_item);
    octstr_destroy(boundary);
    octstr_destroy(pap_content);
    octstr_destroy(push_data);
    octstr_destroy(push_content_file);
    octstr_destroy(pap_osname);
    octstr_destroy(data_osname);
    http_destroy_headers(content_headers);
    octstr_destroy(rdf_content);
    gwlib_shutdown();
    panic(0, "Stopping");
/* return after panic always required by gcc */
    return 1;
}
Exemple #12
0
int main(int argc, char **argv)
{
    DBPool *pool;
    DBConf *conf = NULL; /* for compiler please */
    unsigned int num_threads = 1;
    unsigned long i;
    int opt;
    time_t start = 0, end = 0;
    double run_time;
    Octstr *user, *pass, *db, *host, *db_type;
    int j, bail_out;

    user = pass = db = host = db_type = NULL;

    gwlib_init();

    sql = octstr_imm("SHOW STATUS");

    while ((opt = getopt(argc, argv, "v:h:u:p:d:s:q:t:S:T:")) != EOF) {
        switch (opt) {
            case 'v':
                log_set_output_level(atoi(optarg));
                break;

            case 'h':
                host = octstr_create(optarg);
                break;

            case 'u':
                user = octstr_create(optarg);
                break;

            case 'p':
                pass = octstr_create(optarg);
                break;

            case 'd':
                db = octstr_create(optarg);
                break;

            case 'S':
                octstr_destroy(sql);
                sql = octstr_create(optarg);
                break;

            case 's':
                pool_size = atoi(optarg);
                break;

            case 'q':
                queries = atoi(optarg);
                break;

            case 't':
                num_threads = atoi(optarg);
                break;

            case 'T':
                db_type = octstr_create(optarg);
                break;

            case '?':
            default:
                error(0, "Invalid option %c", opt);
                help();
                panic(0, "Stopping.");
        }
    }

    if (!optind) {
        help();
        exit(0);
    }

    if (!db_type) {
        info(0, "No database type given assuming MySQL.");
    }
    else if (octstr_case_compare(db_type, octstr_imm("mysql")) == 0) {
        info(0, "Do tests for mysql database.");
        database_type = DBPOOL_MYSQL;
    }
    else if (octstr_case_compare(db_type, octstr_imm("oracle")) == 0) {
        info(0, "Do tests for oracle database.");
        database_type = DBPOOL_ORACLE;
    }
    else if (octstr_case_compare(db_type, octstr_imm("sqlite")) == 0) {
        info(0, "Do tests for sqlite database.");
        database_type = DBPOOL_SQLITE;
    }
    else if (octstr_case_compare(db_type, octstr_imm("sqlite3")) == 0) {
        info(0, "Do tests for sqlite3 database.");
        database_type = DBPOOL_SQLITE3;
    }
    else {
        panic(0, "Unknown database type '%s'", octstr_get_cstr(db_type));
    }

    /* check if we have the database connection details */
    switch (database_type) {
        case DBPOOL_ORACLE:
            bail_out = (!user || !pass || !db) ? 1 : 0;
            break;
        case DBPOOL_SQLITE:
        case DBPOOL_SQLITE3:
            bail_out = (!db) ? 1 : 0;
            break;
        default:
            bail_out = (!host || !user || !pass || !db) ? 1 : 0;
            break;
    }
    if (bail_out) {
        help();
        panic(0, "Database connection details are not fully provided!");
    }

    for (j = 0; j < 1; j++) {

    /* create DBConf */
    switch (database_type) {
#ifdef HAVE_MYSQL
        case DBPOOL_MYSQL:
            conf = mysql_create_conf(user,pass,db,host);
            client_thread = mysql_client_thread;
            break;
#endif
#ifdef HAVE_ORACLE
        case DBPOOL_ORACLE:
            conf = oracle_create_conf(user, pass, db);
            client_thread = oracle_client_thread;
            break;
#endif
#ifdef HAVE_SQLITE
        case DBPOOL_SQLITE:
            conf = sqlite_create_conf(db);
            client_thread = sqlite_client_thread;
            break;
#endif
#ifdef HAVE_SQLITE3
        case DBPOOL_SQLITE3:
            conf = sqlite3_create_conf(db);
            client_thread = sqlite3_client_thread;
            break;
#endif
        default:
            panic(0, "ooops ....");
    };

    /* create */
    info(0,"Creating database pool to `%s' with %d connections type '%s'.",
          (host ? octstr_get_cstr(host) : octstr_get_cstr(db)), pool_size, octstr_get_cstr(db_type));
    pool = dbpool_create(database_type, conf, pool_size);
    debug("",0,"Connections within pool: %ld", dbpool_conn_count(pool));

    for (i = 0; i < num_threads; ++i) {
        if (gwthread_create(inc_dec_thread, pool) == -1)
            panic(0, "Could not create thread %ld", i);
    }
    gwthread_join_all();

    info(0, "Connections within pool: %ld", dbpool_conn_count(pool));
    info(0, "Checked pool, %d connections still active and ok", dbpool_check(pool));

    /* queries */
    info(0,"SQL query is `%s'", octstr_get_cstr(sql));
    time(&start);
    for (i = 0; i < num_threads; ++i) {
#if 0
        if (gwthread_create(inc_dec_thread, pool) == -1)
            panic(0, "Couldnot create thread %ld", i);
#endif
        if (gwthread_create(client_thread, pool) == -1)
            panic(0, "Couldnot create thread %ld", i);
    }

    gwthread_join_all();
    time(&end);

    run_time = difftime(end, start);
    info(0, "%ld requests in %.2f seconds, %.2f requests/s.",
         (queries * num_threads), run_time, (float) (queries * num_threads) / (run_time==0?1:run_time));

    /* check all active connections */
    debug("",0,"Connections within pool: %ld", dbpool_conn_count(pool));
    info(0,"Checked pool, %d connections still active and ok", dbpool_check(pool));

    info(0,"Destroying pool");
    dbpool_destroy(pool);

    } /* for loop */

    octstr_destroy(sql);
    octstr_destroy(db_type);
    octstr_destroy(user);
    octstr_destroy(pass);
    octstr_destroy(db);
    octstr_destroy(host);
    gwlib_shutdown();

    return 0;
}
Exemple #13
0
int main(int argc, char **argv) 
{
    int i, opt, num_threads;
    Octstr *proxy;
    List *exceptions;
    long proxy_port;
    int proxy_ssl = 0;
    Octstr *proxy_username;
    Octstr *proxy_password;
    Octstr *exceptions_regex;
    char *p;
    long threads[MAX_THREADS];
    time_t start, end;
    double run_time;
    FILE *fp;
    int ssl = 0;
    
    gwlib_init();
    
    proxy = NULL;
    proxy_port = -1;
    exceptions = gwlist_create();
    proxy_username = NULL;
    proxy_password = NULL;
    exceptions_regex = NULL;
    num_threads = 1;
    file = 0;
    fp = NULL;
    
    while ((opt = getopt(argc, argv, "hv:qr:p:P:Se:t:i:a:u:sc:H:B:m:f")) != EOF) {
	switch (opt) {
	case 'v':
	    log_set_output_level(atoi(optarg));
	    break;
	
	case 'q':
	    verbose = 0;
	    break;
	
	case 'r':
	    max_requests = atoi(optarg);
	    break;
	
	case 't':
	    num_threads = atoi(optarg);
	    if (num_threads > MAX_THREADS)
		num_threads = MAX_THREADS;
	    break;

	case 'i':
	    interval = atof(optarg);
	    break;

    case 'u':
        file = 1;
        fp = fopen(optarg, "a");
        if (fp == NULL)
            panic(0, "Cannot open message text file %s", optarg);
        msg_text = octstr_read_file(optarg);
        if (msg_text == NULL)
            panic(0, "Cannot read message text");
        debug("", 0, "message text is");
        octstr_dump(msg_text, 0);
        octstr_url_encode(msg_text);
        fclose(fp);
        break;
	
	case 'h':
	    help();
	    exit(0);
	
	case 'p':
	    proxy = octstr_create(optarg);
	    break;
	
	case 'P':
	    proxy_port = atoi(optarg);
	    break;

	case 'S':
        proxy_ssl = 1;
        break;
	
	case 'e':
	    p = strtok(optarg, ":");
	    while (p != NULL) {
		gwlist_append(exceptions, octstr_create(p));
		p = strtok(NULL, ":");
	    }
	    break;

   case 'E':
       exceptions_regex = octstr_create(optarg);
       break;

	case 'a':
	    p = strtok(optarg, ":");
	    if (p != NULL) {
		auth_username = octstr_create(p);
		p = strtok(NULL, "");
		if (p != NULL)
		    auth_password = octstr_create(p);
	    }
	    break;

    case 's':
        ssl = 1;
        break;

    case 'c':
	    octstr_destroy(ssl_client_certkey_file);
	    ssl_client_certkey_file = octstr_create(optarg);
        break;

    case 'H':
        fp = fopen(optarg, "a");
        if (fp == NULL)
            panic(0, "Cannot open header text file %s", optarg);
        extra_headers = octstr_read_file(optarg);
        if (extra_headers == NULL)
            panic(0, "Cannot read header text");
        debug("", 0, "headers are");
        octstr_dump(extra_headers, 0);
        split_headers(extra_headers, &split);
        fclose(fp);
        break;

    case 'B':
        content_file = octstr_create(optarg);
        break;

	case 'm':
	    method_name = octstr_create(optarg);
	    break;

    case 'f':
        follow_redirect = 0;
        break;

    case '?':
	default:
	    error(0, "Invalid option %c", opt);
	    help();
	    panic(0, "Stopping.");
	}
    }
    
    if (optind == argc) {
        help();
        exit(0);
    }

#ifdef HAVE_LIBSSL
    /*
     * check if we are doing a SSL-enabled client version here
     * load the required cert and key file
     */
    if (ssl || proxy_ssl) {
        if (ssl_client_certkey_file != NULL) {
            use_global_client_certkey_file(ssl_client_certkey_file);
        } else {
            panic(0, "client certkey file need to be given!");
        }
    }
#endif

    if (method_name != NULL) {
        method = http_name2method(method_name);
    }
    
    if (proxy != NULL && proxy_port > 0) {
        http_use_proxy(proxy, proxy_port, proxy_ssl, exceptions,
        proxy_username, proxy_password, exceptions_regex);
    }
    octstr_destroy(proxy);
    octstr_destroy(proxy_username);
    octstr_destroy(proxy_password);
    octstr_destroy(exceptions_regex);
    gwlist_destroy(exceptions, octstr_destroy_item);
    
    urls = argv + optind;
    num_urls = argc - optind;
    
    time(&start);
    if (num_threads == 1)
        client_thread(http_caller_create());
    else {
        for (i = 0; i < num_threads; ++i)
            threads[i] = gwthread_create(client_thread, http_caller_create());
        for (i = 0; i < num_threads; ++i)
            gwthread_join(threads[i]);
    }
    time(&end);
    
    run_time = difftime(end, start);
    info(0, "%ld requests in %f seconds, %f requests/s.",
         (max_requests * num_threads), run_time, (max_requests * num_threads) / run_time);
    
    octstr_destroy(ssl_client_certkey_file);
    octstr_destroy(auth_username);
    octstr_destroy(auth_password);
    octstr_destroy(extra_headers);
    octstr_destroy(content_file);
    gwlist_destroy(split, octstr_destroy_item);
    
    gwlib_shutdown();
    
    return 0;
}
Exemple #14
0
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:xn: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 'x':
                no_smsbox_id = 1;
                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;
}
Exemple #15
0
int create_web_data(char *p_pszFileName, char *p_pszMMSDir, const char *p_pszWebDir)
{
  int iRetVal = 0;
  MmsEnvelope *psoEnv;
  MmsMsg *psoMsg = NULL;
  List *psoHdrList = NULL;
  Octstr *psoHdrs = NULL, *psoHdrName = NULL, *psoHdrValue = NULL, *psoWebDir = NULL;
  MIMEEntity *psoMIME, *psoMIMETmp;
  int iMIMENum, iMIMEInd;
  int iFile = -1;

  gwlib_init();
  mms_strings_init();

  /* формируем имя директрии для вывода результатов */
  psoWebDir = octstr_create(p_pszWebDir);
  if('/' != octstr_get_char(psoWebDir, octstr_len(psoWebDir) - 1)) {
    octstr_append_char(psoWebDir, '/');
  }
  octstr_append_cstr(psoWebDir, p_pszFileName);

  /* создаем директорию */
  if(mkdir(octstr_get_cstr(psoWebDir), 0777)) {
    if(errno != EEXIST) {
      iRetVal = 2;
    }
    goto done;
  }

  psoEnv = default_qfuncs.mms_queue_readenvelope(p_pszFileName, p_pszMMSDir, 0);
  if(psoEnv) {
    psoMsg = default_qfuncs.mms_queue_getdata(psoEnv);
    default_qfuncs.mms_queue_free_env(psoEnv);
  } else {
    iRetVal = 3;
    goto done;
  }

  if(!psoMsg) {
    iRetVal = 4;
    goto done;
  }

  psoHdrs = octstr_create("");
  /* выбираем необходимые заголовки */
  psoHdrList = mms_message_headers(psoMsg);
  /* From */
  psoHdrName = octstr_create("From");
  psoHdrValue = http_header_value(psoHdrList, psoHdrName);
  octstr_format_append(psoHdrs, "%S/%S\r\n", psoHdrName, psoHdrValue);
  octstr_truncate(psoHdrName, 0);
  /* To */
  octstr_append_cstr(psoHdrName, "To");
  psoHdrValue = http_header_value(psoHdrList, psoHdrName);
  octstr_format_append(psoHdrs, "%S/%S\r\n", psoHdrName, psoHdrValue);
  octstr_truncate(psoHdrName, 0);
  /* Date */
  octstr_append_cstr(psoHdrName, "Date");
  psoHdrValue = http_header_value(psoHdrList, psoHdrName);
  octstr_format_append(psoHdrs, "%S/%S", psoHdrName, psoHdrValue);
  octstr_truncate(psoHdrName, 0);
  /**/

  psoMIME = mms_tomime(psoMsg, 1);
  iMIMENum = mime_entity_num_parts(psoMIME);
  if(psoMIME) {
    for(iMIMEInd = 0; iMIMEInd < iMIMENum; ++iMIMEInd) {
      psoMIMETmp = mime_entity_get_part(psoMIME, iMIMEInd);
      operate_single_mime(psoHdrs, psoMIMETmp, octstr_get_cstr(psoWebDir));
    }
  }

  /* формируем имя файла для вывода результатов, используем ту же переменную, что и для директории */
  if('/' != octstr_get_char(psoWebDir, octstr_len(psoWebDir) - 1)) {
    octstr_append_char(psoWebDir, '/');
  }
  octstr_append_cstr(psoWebDir, "common");
  /* создаем файл */
  iFile = open(octstr_get_cstr(psoWebDir), O_CREAT | O_EXCL | O_WRONLY, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
  if(0 < iFile) {
    if(octstr_len(psoHdrs) != write(iFile, octstr_get_cstr(psoHdrs), octstr_len(psoHdrs))) {
      iRetVal = 5;
    }
    close(iFile);
  } else {
    if(errno != EEXIST) {
      iRetVal = 6;
    }
  }

  done:
  if(psoHdrs) {
    octstr_destroy(psoHdrs);
  }
  if(psoHdrName) {
    octstr_destroy(psoHdrName);
  }
  if(psoWebDir) {
    octstr_destroy(psoWebDir);
  }

  mms_strings_shutdown();
  gwlib_shutdown();

  return iRetVal;
}
Exemple #16
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;
}
Exemple #17
0
int main(int argc, char **argv)
{
    output_t outputti = NORMAL_OUT;
    FILE *fp = NULL;
    Octstr *output = NULL;
    Octstr *filename = NULL;
    Octstr *wml_text = NULL;
    Octstr *charset = NULL;
    Octstr *wml_binary = NULL;
    int i, ret = 0, opt, file = 0, zero = 0, numstatus = 0, wml_strict = 1;
    long num = 0;

    /* You can give an wml text file as an argument './wml_tester main.wml' */

    gwlib_init();

    while ((opt = getopt(argc, argv, "hsbzrn:f:c:")) != EOF) {
	switch (opt) {
	case 'h':
	    help();
	    exit(0);
	case 's':
	    if (outputti == NORMAL_OUT)
		outputti = SOURCE_OUT;
	    else {
		help();
		exit(0);
	    }
	    break;
	case 'b':
	    if (outputti == NORMAL_OUT)
		outputti = BINARY_OUT;
	    else {
		help();
		exit(0);
	    }
	    break;
	case 'z':
	    zero = 1;
	    break;
    case 'r':
        wml_strict = 0;
        break;
	case 'n':
	    numstatus = octstr_parse_long(&num, octstr_imm(optarg), 0, 0);
	    if (numstatus == -1) { 
		/* Error in the octstr_parse_long */
		error(num, "Error in the handling of argument to option n");
		help();
		panic(0, "Stopping.");
	    }
	    break;
	case 'f':
	    file = 1;
	    filename = octstr_create(optarg);
	    fp = fopen(optarg, "a");
	    if (fp == NULL)
		panic(0, "Couldn't open output file.");	
	    break;
	case 'c':
	    charset = octstr_create(optarg);
	    break;
	case '?':
	default:
	    error(0, "Invalid option %c", opt);
	    help();
	    panic(0, "Stopping.");
	}
    }

    if (optind >= argc) {
	error(0, "Missing arguments.");
	help();
	panic(0, "Stopping.");
    }

    if (outputti == BINARY_OUT)
	 log_set_output_level(GW_PANIC);
    wml_init(wml_strict);

    while (optind < argc) {
	wml_text = octstr_read_file(argv[optind]);
	if (wml_text == NULL)
	    panic(0, "Couldn't read WML source file.");

	if (zero)
	    set_zero(wml_text);

	for (i = 0; i <= num; i++) {
	    ret = wml_compile(wml_text, charset, &wml_binary, NULL);
	    if (i < num)
		octstr_destroy(wml_binary);
	}
	optind++;

	output = octstr_format("wml_compile returned: %d\n\n", ret);
    
	if (ret == 0) {
	    if (fp == NULL)
		fp = stdout;

	    if (outputti != BINARY_OUT) {
		if (outputti == SOURCE_OUT) {
		    octstr_insert(output, wml_text, octstr_len(output));
		    octstr_append_char(output, '\n');
		}

		octstr_append(output, octstr_imm(
		    "Here's the binary output: \n\n"));
		octstr_print(fp, output);
	    }

	    if (file && outputti != BINARY_OUT) {
		fclose(fp);
		log_open(octstr_get_cstr(filename), 0, GW_NON_EXCL);
		octstr_dump(wml_binary, 0);
		log_close_all();
		fp = fopen(octstr_get_cstr(filename), "a");
	    } else if (outputti != BINARY_OUT)
		octstr_dump(wml_binary, 0);
	    else 
		octstr_print(fp, wml_binary);

	    if (outputti != BINARY_OUT) {
		octstr_destroy(output);
		output = octstr_format("\n And as a text: \n\n");
		octstr_print(fp, output);
      
		octstr_pretty_print(fp, wml_binary);
		octstr_destroy(output);
		output = octstr_format("\n\n");
		octstr_print(fp, output);
	    }
	}

	octstr_destroy(wml_text);
	octstr_destroy(output);
	octstr_destroy(wml_binary);
    }
	
    if (file) {
	fclose(fp);
	octstr_destroy(filename);
    }
    
    if (charset != NULL)
	octstr_destroy(charset);

    wml_shutdown();
    gwlib_shutdown();
    
    return ret;
}
Exemple #18
0
int main(int argc, char **argv) {
	int opt;
	Octstr *address;
	int udpsock;

	gwlib_init();

	/* Set defaults that can't be set statically */
	hostname = octstr_create("localhost");

	while ((opt = getopt(argc, argv, "hg:p:i:m:")) != EOF) {
		switch(opt) {
		case 'g':
			octstr_destroy(hostname);
			hostname = octstr_create(optarg);
			break;

		case 'p':
			port = atoi(optarg);
			break;

		case 'i':
			interval = atof(optarg);
			break;

		case 'm':
			maxsize = atol(optarg);
			if (maxsize > UDP_MAXIMUM) {
				maxsize = UDP_MAXIMUM;
				warning(0, "-m: truncated to UDP maximum of"
					"%ld bytes.", maxsize);
			}
			break;

		case 'h':
			help();
			exit(0);
			break;

		case '?':
		default:
			error(0, "Unknown option '%c'", opt);
			help();
			exit(1);
			break;
		}
	}

	address = udp_create_address(hostname, port);
	udpsock = udp_client_socket();
	if (udpsock < 0)
		exit(1);

	for ( ; optind < argc; optind++) {
		send_file(udpsock, argv[optind], address);
		if (interval > 0 && optind + 1 < argc)
			gwthread_sleep(interval);
	}

	octstr_destroy(address);
	octstr_destroy(hostname);
	gwlib_shutdown();
    	return 0;
}
Exemple #19
0
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;
}
Exemple #20
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;
}
Exemple #21
0
int main(int argc, char **argv)
{
    int opt,
        ret;
    Octstr *pap_doc,
           *log_file;
    WAPEvent *e;

    log_file = NULL;
    gwlib_init();
    
    while ((opt = getopt(argc, argv, "h:v:l:")) != EOF) {
        switch (opt) {
        case 'h':
	    help();
            exit(1);
	break;

        case 'v':
	    log_set_output_level(atoi(optarg));
	break;

        case 'l':
	    octstr_destroy(log_file);
	    log_file = octstr_create(optarg);
	break;

        case '?':
        default:
	    error(0, "Invalid option %c", opt);
            help();
            panic(0, "Stopping");
	break;
        }
    }

    if (optind >= argc) {
        error(0, "Missing arguments");
        help();
        panic(0, "Stopping");
    }

    if (log_file != NULL) {
    	log_open(octstr_get_cstr(log_file), GW_DEBUG, GW_NON_EXCL);
	octstr_destroy(log_file);
    }

    pap_doc = octstr_read_file(argv[optind]);
    if (pap_doc == NULL)
        panic(0, "Cannot read the pap document");

    e = NULL;
    ret = pap_compile(pap_doc, &e);
    
    if (ret < 0) {
        debug("test.pap", 0, "Unable to compile the pap document, rc %d", ret); 
        return 1;           
    } 

    debug("test.pap", 0, "Compiling successfull, wap event being:\n");
    wap_event_dump(e);

    wap_event_destroy(e);
    octstr_destroy(pap_doc);
    gwlib_shutdown();
    return 0;
}