Ejemplo n.º 1
0
int smscconn_info(SMSCConn *conn, StatusInfo *infotable)
{
    if (conn == NULL || infotable == NULL)
	return -1;

    mutex_lock(conn->flow_mutex);

    infotable->status = conn->status;
    infotable->killed = conn->why_killed;
    infotable->is_stopped = conn->is_stopped;
    infotable->online = time(NULL) - conn->connect_time;
    
    infotable->sent = counter_value(conn->sent);
    infotable->received = counter_value(conn->received);
    infotable->sent_dlr = counter_value(conn->sent_dlr);
    infotable->received_dlr = counter_value(conn->received_dlr);
    infotable->failed = counter_value(conn->failed);

    if (conn->queued)
	infotable->queued = conn->queued(conn);
    else
	infotable->queued = -1;

    infotable->load = conn->load;
    
    mutex_unlock(conn->flow_mutex);

    return 0;
}
Ejemplo n.º 2
0
int main(int argc, char **argv)
{
	Octstr *os1;
	Octstr *os2;
	time_t start, diff;

    gwlib_init();

    os1 = octstr_create(argv[1]);
    os2 = octstr_create(argv[2]);

    counter = counter_create();
    start = time(NULL);
    for_each_file(os1, 1, count_file);
    diff = (time(NULL) - start);
    debug("",0,"file count: %ld in %lds", (long) counter_value(counter), (long) diff);

#ifdef HAVE_NFTW
    counter_set(counter, 0);
    start = time(NULL);
    for_each_file2(os2, 1, count_file2);
    diff = (time(NULL) - start);
    debug("",0,"file count: %ld in %lds", (long) counter_value(counter), (long) diff);
#endif

    counter_destroy(counter);
    octstr_destroy(os1);
    octstr_destroy(os2);
    gwlib_shutdown();
	return 0;
}
Ejemplo n.º 3
0
static long httpsmsc_queued(SMSCConn *conn)
{
    ConnData *conndata = conn->data;

    return (conndata ? (conn->status != SMSCCONN_DEAD ? 
            counter_value(conndata->open_sends) : 0) : 0);
}
Ejemplo n.º 4
0
Result parser_value(register Parser *pp, int *value, char const *text)
{
                                                        /* find the counter */
    register HashItem *item = hashmap_find(pp->d_symtab_ptr, text, COUNTER);

    if (item != PFAILED)                                /* got it           */
    {
        *value = counter_value(item);                   /* assign the value */
        if (message_show(MSG_INFO))
            message("%s: counter[%s] == %d", parser_fun(), text, *value);
    }
    else if (sscanf(text, "%d", value) == 1)    /* convert text to number   */
    {
        if (message_show(MSG_INFO))
            message("%s: got value %d\n", parser_fun(),  *value);
    }
    else                                                    /* no number    */
    {
        if (message_show(MSG_ERR))
            message("%s: Number expected at `%s'", parser_fun(), text);
        return FAILED;
    }

    return SUCCESS;
}
Ejemplo n.º 5
0
static void empty_msg_lists(void)
{
    Msg *msg;

#ifndef NO_WAP

    if (list_len(incoming_wdp) > 0 || list_len(outgoing_wdp) > 0)
	warning(0, "Remaining WDP: %ld incoming, %ld outgoing",
	      list_len(incoming_wdp), list_len(outgoing_wdp));

    info(0, "Total WDP messages: received %ld, sent %ld",
	 counter_value(incoming_wdp_counter),
	 counter_value(outgoing_wdp_counter));
#endif
    
    while((msg = list_extract_first(incoming_wdp))!=NULL)
	msg_destroy(msg);
    while((msg = list_extract_first(outgoing_wdp))!=NULL)
	msg_destroy(msg);

    list_destroy(incoming_wdp, NULL);
    list_destroy(outgoing_wdp, NULL);

    counter_destroy(incoming_wdp_counter);
    counter_destroy(outgoing_wdp_counter);
    
    
#ifndef NO_SMS

    /* XXX we should record these so that they are not forever lost...
     */
    if (list_len(incoming_sms) > 0 || list_len(outgoing_sms) > 0)
	debug("bb", 0, "Remaining SMS: %ld incoming, %ld outgoing",
	      list_len(incoming_sms), list_len(outgoing_sms));

    info(0, "Total SMS messages: received %ld, sent %ld",
	 counter_value(incoming_sms_counter),
	 counter_value(outgoing_sms_counter));

#endif

    list_destroy(incoming_sms, msg_destroy_item);
    list_destroy(outgoing_sms, msg_destroy_item);
    
    counter_destroy(incoming_sms_counter);
    counter_destroy(outgoing_sms_counter);
}
Ejemplo n.º 6
0
void BytecodeCounter::print() {
  tty->print_cr(
    "%d bytecodes executed in %.1fs (%.3fMHz)",
    counter_value(),
    elapsed_time(),
    frequency() / 1000000.0
  );
}
Ejemplo n.º 7
0
static void send_smpp_thread(void *arg)
{
    ESME *esme;
    Octstr *os;
    SMPP_PDU *pdu;
    unsigned long id;

    esme = arg;
    
    id = 0;
    while (!quitting && counter_value(num_to_esme) < max_to_esme) {
        id = counter_increase(num_to_esme) + 1;
        while (!quitting && counter_value(num_from_esme) + 500 < id)
            gwthread_sleep(1.0);
        if (quitting)
            break;
        pdu = smpp_pdu_create(deliver_sm, counter_increase(message_id_counter));
        pdu->u.deliver_sm.source_addr = octstr_create("456");
        pdu->u.deliver_sm.destination_addr = octstr_create("123");
        pdu->u.deliver_sm.short_message = octstr_format("%ld", id);
        if (esme->version > 0x33)
            pdu->u.deliver_sm.receipted_message_id = octstr_create("receipted_message_id\0");
        os = smpp_pdu_pack(NULL, pdu);
        conn_write(esme->conn, os);
        octstr_destroy(os);
        smpp_pdu_destroy(pdu);
        if (first_to_esme == (time_t) -1)
            time(&first_to_esme);
        debug("test.smpp", 0, "Delivered SMS %ld of %ld to bearerbox via SMPP.",
              id, max_to_esme);

        if ((id % enquire_interval) == 0) {
            pdu = smpp_pdu_create(enquire_link, counter_increase(message_id_counter));
            os = smpp_pdu_pack(NULL, pdu);
            conn_write(esme->conn, os);
            octstr_destroy(os);
            smpp_pdu_destroy(pdu);
            debug("test.smpp", 0, "Sent enquire_link to bearerbox.");
        }
    }
    time(&last_to_esme);
    if (id == max_to_esme)
	info(0, "All messages sent to ESME.");
    debug("test.smpp", 0, "%s terminates.", __func__);
}
Ejemplo n.º 8
0
void smpp_listener_event(evutil_socket_t fd, short what, void *arg)
{
    SMPPEsme *smpp_esme = arg;
    SMPP_PDU *pdu = NULL;
    int result;
    SMPPQueuedPDU *smpp_queued_pdu;
    
    if(what & EV_READ) {
        debug("smpp.listener.event", 0, "Got a read event for SMPP esme connection %ld %d", smpp_esme->id, smpp_esme->bind_type);
        while((result = smpp_listener_read_pdu(smpp_esme, &smpp_esme->pending_len, &pdu)) > 0) {
            counter_set(smpp_esme->errors, 0L);
            smpp_queued_pdu = smpp_queued_pdu_create();
            smpp_queued_pdu->pdu = pdu;
            smpp_queued_pdu->smpp_esme = smpp_esme;
            smpp_queues_add_inbound(smpp_queued_pdu);
        }
        
        if(result == 0) {
            /* Just no data, who cares*/
        } else {
            if(result == -1) {
                error(0, "Could not read PDU from %s status was %d", octstr_get_cstr(smpp_esme->system_id), result);
                /* This is a connection error we can close this ESME */
                /* Stop listening on this connection, its dead */
                smpp_esme_stop_listening(smpp_esme);
                
                if(!smpp_esme->authenticated) { /* If there is a pending disconnect operation it means an unbind/rejected bind requested to disconnect, let outbound queue handle */
                    /* This bind is not authenticated so will never be cleaned up, lets do it here  */
                    debug("smpp.listener.event", 0, "Cleaning up disconnected ESME %ld", smpp_esme->id);
                    smpp_listener_auth_failed(smpp_esme->smpp_server, smpp_esme->ip);
                    smpp_esme_cleanup(smpp_esme);
                } else {
                    debug("smpp.listener.event", 0, "Allowing background thread to clean up %ld", smpp_esme->id);
                }
            } else if(result == -2) {
                error(0, "Could not read PDU from %s status was %d", octstr_get_cstr(smpp_esme->system_id), result);
                counter_increase(smpp_esme->errors);
                
                if(counter_value(smpp_esme->errors) >= SMPP_ESME_MAX_CONSECUTIVE_ERRORS) {
                    error(0, "SMPP[%s] max consecutive PDU errors, disconnecting", octstr_get_cstr(smpp_esme->system_id));
                    smpp_esme_stop_listening(smpp_esme);
                    
                    if(!smpp_esme->authenticated) {
                        /* This bind is not authenticated so will never be cleaned up, lets do it here  */
                        smpp_listener_auth_failed(smpp_esme->smpp_server, smpp_esme->ip);
                        smpp_esme_cleanup(smpp_esme);
                    } else {
                        debug("smpp.listener.event", 0, "Allowing background thread to clean up mangled %ld", smpp_esme->id);
                    }
                    
                }
            }
        }
    } else {
        debug("smpp.listener.event", 0, "Got a other event for SMPP esme connection %ld", smpp_esme->id);
    }
}
Ejemplo n.º 9
0
static void smpp_listener_connection_callback(struct evconnlistener *listener, evutil_socket_t fd, struct sockaddr *address, int socklen, void *ctx) {
    struct event_base *base = evconnlistener_get_base(listener);
    
    SMPPServer *smpp_server = ctx;
    Octstr *ip = NULL; //host_ip(address);
    
    if (address->sa_family == AF_INET)
    {
        struct sockaddr_in *sin = (struct sockaddr_in *) address;
        ip = host_ip(*sin);
    }

    debug("smpp.listener.connection.callback", 0, "Got connection from %s", octstr_get_cstr(ip));

    if(octstr_len(ip)) {
        if(smpp_listener_ip_is_blocked(smpp_server, ip)) {
            debug("smpp.listener.connection.callback", 0, "%s is temporarily banned from connecting. Rejecting.", octstr_get_cstr(ip));
            evutil_closesocket(fd);
            octstr_destroy(ip);
            return;
        }
    }
    
    struct event *event_container;
    
    SMPPEsme *smpp_esme = smpp_esme_create();
    smpp_esme->conn = conn_wrap_fd(fd, smpp_server->enable_ssl);
    smpp_esme->connected = 1;
    smpp_esme->smpp_server = smpp_server;
    smpp_esme->time_connected = time(NULL);
    smpp_esme->id = counter_value(smpp_server->esme_counter);
    smpp_esme->ip = ip;
    smpp_esme->max_open_acks = smpp_server->default_max_open_acks;
    
    counter_increase(smpp_server->esme_counter);
    
    event_container = event_new(base, fd, EV_TIMEOUT|EV_READ|EV_PERSIST, smpp_listener_event,
           smpp_esme);
    
    event_add(event_container, NULL);
    
    smpp_esme->event_container = event_container;
   
    
}
Ejemplo n.º 10
0
static int store_spool_load(void(*receive_msg)(Msg*))
{
    int rc;

    /* check if we are active */
    if (spool == NULL)
        return 0;
        
    /* sanity check */
    if (receive_msg == NULL)
        return -1;

    rc = for_each_file(spool, 0, dispatch, receive_msg);

    info(0, "Loaded %ld messages from store.", counter_value(counter));

    /* allow using of storage */
    gwlist_remove_producer(loaded);

    return rc;
}
Ejemplo n.º 11
0
/*
 * Thread to listen to HTTP requests from SMSC entity
 */
static void httpsmsc_receiver(void *arg)
{
    SMSCConn *conn = arg;
    ConnData *conndata = conn->data;
    HTTPClient *client;
    Octstr *ip, *url, *body;
    List *headers, *cgivars;

    /* Make sure we log into our own log-file if defined */
    log_thread_to(conn->log_idx);

    while (conndata->shutdown == 0) {
        /* reset */
        ip = url = body = NULL;
        headers = cgivars = NULL;

        /* XXX if conn->is_stopped, do not receive new messages.. */

        client = http_accept_request(conndata->port, &ip, &url,
                                     &headers, &body, &cgivars);
        if (client == NULL)
            break;

        if (cgivars != NULL) {
        	octstr_append_char(url, '?');
        	http_cgivar_dump_into(cgivars, url);
        }

        debug("smsc.http", 0, "HTTP[%s]: Got request `%s'",
              octstr_get_cstr(conn->id), octstr_get_cstr(url));

        if (connect_denied(conndata->allow_ip, ip)) {
            info(0, "HTTP[%s]: Connection `%s' tried from denied "
                    "host %s, ignored", octstr_get_cstr(conn->id),
                    octstr_get_cstr(url), octstr_get_cstr(ip));
            http_close_client(client);
        } else
            conndata->callbacks->receive_sms(conn, client, headers, body, cgivars);

        debug("smsc.http", 0, "HTTP[%s]: Destroying client information",
              octstr_get_cstr(conn->id));
        octstr_destroy(url);
        octstr_destroy(ip);
        octstr_destroy(body);
        http_destroy_headers(headers);
        http_destroy_cgiargs(cgivars);
    }
    debug("smsc.http", 0, "HTTP[%s]: httpsmsc_receiver dying",
          octstr_get_cstr(conn->id));

    conndata->shutdown = 1;
    http_close_port(conndata->port);

    /* unblock http_receive_result() if there are no open sends */
    if (counter_value(conndata->open_sends) == 0)
        http_caller_signal_shutdown(conndata->http_ref);

    if (conndata->sender_thread != -1) {
        gwthread_wakeup(conndata->sender_thread);
        gwthread_join(conndata->sender_thread);
    }
    if (conndata->send_cb_thread != -1) {
        gwthread_wakeup(conndata->send_cb_thread);
        gwthread_join(conndata->send_cb_thread);
    }

    mutex_lock(conn->flow_mutex);
    conn->status = SMSCCONN_DEAD;
    mutex_unlock(conn->flow_mutex);

    if (conndata->callbacks != NULL && conndata->callbacks->destroy != NULL)
        conndata->callbacks->destroy(conn);
    conn->data = NULL;
    conndata_destroy(conndata);
    bb_smscconn_killed();
}
Ejemplo n.º 12
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;
}
Ejemplo n.º 13
0
static long store_spool_messages()
{
    return counter ? counter_value(counter) : -1;
}
Ejemplo n.º 14
0
/*
 * Get count of DLR messages within the spool.
 */
static long dlr_spool_messages(void)
{
    return counter_value(counter);
}
Ejemplo n.º 15
0
 virtual counter_value get_counter_value(bool /*reset*/) override
 {
     HPX_THROW_EXCEPTION(invalid_status, "get_counter_value",
         "get_counter_value is not implemented for this counter");
     return counter_value();
 }
Ejemplo n.º 16
0
/*
 * Thread to send queued messages
 */
static void httpsmsc_sender(void *arg)
{
    SMSCConn *conn = arg;
    ConnData *conndata = conn->data;
    Msg *msg;
    double delay = 0;

    /* Make sure we log into our own log-file if defined */
    log_thread_to(conn->log_idx);

    if (conn->throughput) {
        delay = 1.0 / conn->throughput;
    }

    while (conndata->shutdown == 0) {
        /* check if we can send ; otherwise block on semaphore */
        if (conndata->max_pending_sends)
            semaphore_down(conndata->max_pending_sends);

        if (conndata->shutdown) {
            if (conndata->max_pending_sends)
                semaphore_up(conndata->max_pending_sends);
            break;
        }

        msg = gwlist_consume(conndata->msg_to_send);
        if (msg == NULL)
            break;

        /* obey throughput speed limit, if any */
        if (conn->throughput > 0) {
            gwthread_sleep(delay);
        }
        counter_increase(conndata->open_sends);
        if (conndata->callbacks->send_sms(conn, msg) == -1) {
            counter_decrease(conndata->open_sends);
            if (conndata->max_pending_sends)
                semaphore_up(conndata->max_pending_sends);
        }
    }

    /* put outstanding sends back into global queue */
    while((msg = gwlist_extract_first(conndata->msg_to_send)))
        bb_smscconn_send_failed(conn, msg, SMSCCONN_FAILED_SHUTDOWN, NULL);

    /* if there no receiver shutdown */
    if (conndata->port <= 0) {
        /* unblock http_receive_result() if there are no open sends */
        if (counter_value(conndata->open_sends) == 0)
            http_caller_signal_shutdown(conndata->http_ref);

        if (conndata->send_cb_thread != -1) {
            gwthread_wakeup(conndata->send_cb_thread);
            gwthread_join(conndata->send_cb_thread);
        }
        mutex_lock(conn->flow_mutex);
        conn->status = SMSCCONN_DEAD;
        mutex_unlock(conn->flow_mutex);

        if (conndata->callbacks != NULL && conndata->callbacks->destroy != NULL)
            conndata->callbacks->destroy(conn);
        conn->data = NULL;
        conndata_destroy(conndata);
        bb_smscconn_killed();
    }
}
Ejemplo n.º 17
0
/*
 * Thread to handle finished sendings
 */
static void httpsmsc_send_cb(void *arg)
{
    SMSCConn *conn = arg;
    ConnData *conndata = conn->data;
    Msg *msg;
    int status;
    List *headers;
    Octstr *final_url, *body;

    /* Make sure we log into our own log-file if defined */
    log_thread_to(conn->log_idx);

    while(conndata->shutdown == 0 || counter_value(conndata->open_sends)) {

        msg = http_receive_result(conndata->http_ref, &status,
                                  &final_url, &headers, &body);

        if (msg == NULL)
            break;  /* they told us to die, by unlocking */

        counter_decrease(conndata->open_sends);
        if (conndata->max_pending_sends)
            semaphore_up(conndata->max_pending_sends);

        /* Handle various states here. */

        /* request failed and we are not in shutdown mode */
        if (status == -1 && conndata->shutdown == 0) {
            error(0, "HTTP[%s]: Couldn't connect to SMS center."
                     "(retrying in %ld seconds) %ld.",
                     octstr_get_cstr(conn->id), conn->reconnect_delay, counter_value(conndata->open_sends));
            mutex_lock(conn->flow_mutex);
            conn->status = SMSCCONN_RECONNECTING;
            mutex_unlock(conn->flow_mutex);
            /* XXX how should we know whether it's temp. error ?? */
            bb_smscconn_send_failed(conn, msg, SMSCCONN_FAILED_TEMPORARILY, NULL);
            /*
             * Just sleep reconnect delay and set conn to ACTIVE again;
             * otherwise if no pending request are here, we leave conn in
             * RECONNECTING state for ever and no routing (trials) take place.
             */
            if (counter_value(conndata->open_sends) == 0) {
                gwthread_sleep(conn->reconnect_delay);
                /* and now enable routing again */
                mutex_lock(conn->flow_mutex);
                conn->status = SMSCCONN_ACTIVE;
                time(&conn->connect_time);
                mutex_unlock(conn->flow_mutex);
                /* tell bearerbox core that we are connected again */
                bb_smscconn_connected(conn);
            }
            continue;
        }
        /* request failed and we *are* in shutdown mode, drop the message */
        else if (status == -1 && conndata->shutdown == 1) {
            bb_smscconn_send_failed(conn, msg, SMSCCONN_FAILED_SHUTDOWN, NULL);
        }
        /* request succeeded */
        else {
            /* we received a response, so this link is considered online again */
            if (conn->status != SMSCCONN_ACTIVE) {
                mutex_lock(conn->flow_mutex);
                conn->status = SMSCCONN_ACTIVE;
                time(&conn->connect_time);
                mutex_unlock(conn->flow_mutex);
                /* tell bearerbox core that we are connected again */
                bb_smscconn_connected(conn);
            }
            conndata->callbacks->parse_reply(conn, msg, status, headers, body);
        }

        http_destroy_headers(headers);
        octstr_destroy(final_url);
        octstr_destroy(body);
    }
    debug("smsc.http", 0, "HTTP[%s]: httpsmsc_send_cb dying",
          octstr_get_cstr(conn->id));
    conndata->shutdown = 1;

    if (counter_value(conndata->open_sends)) {
        warning(0, "HTTP[%s]: Shutdown while <%ld> requests are pending.",
                octstr_get_cstr(conn->id), counter_value(conndata->open_sends));
    }
}
Ejemplo n.º 18
0
Octstr *bb_print_status(int status_type)
{
    char *s, *lb;
    char *frmt, *footer;
    Octstr *ret, *str, *version;
    time_t t;

    if ((lb = bb_status_linebreak(status_type)) == NULL)
        return octstr_create("Un-supported format");

    t = time(NULL) - start_time;
    
    if (bb_status == BB_RUNNING)
        s = "running";
    else if (bb_status == BB_ISOLATED)
        s = "isolated";
    else if (bb_status == BB_SUSPENDED)
        s = "suspended";
    else if (bb_status == BB_FULL)
        s = "filled";
    else
        s = "going down";

    version = version_report_string("bearerbox");

    if (status_type == BBSTATUS_HTML) {
        frmt = "%s</p>\n\n"
               " <p>Status: %s, uptime %ldd %ldh %ldm %lds</p>\n\n"
               " <p>WDP: received %ld (%ld queued), sent %ld "
               "(%ld queued)</p>\n\n"
               " <p>SMS: received %ld (%ld queued), sent %ld "
               "(%ld queued), store size %ld<br>\n"
               " SMS: inbound (%.2f,%.2f,%.2f) msg/sec, "
               "outbound (%.2f,%.2f,%.2f) msg/sec</p>\n\n"
               " <p>DLR: received %ld, sent %ld<br>\n"
               " DLR: inbound (%.2f,%.2f,%.2f) msg/sec, outbound (%.2f,%.2f,%.2f) msg/sec<br>\n"
               " DLR: %ld queued, using %s storage</p>\n\n";
        footer = "<p>";
    } else if (status_type == BBSTATUS_WML) {
        frmt = "%s</p>\n\n"
               "   <p>Status: %s, uptime %ldd %ldh %ldm %lds</p>\n\n"
               "   <p>WDP: received %ld (%ld queued)<br/>\n"
               "      WDP: sent %ld (%ld queued)</p>\n\n"
               "   <p>SMS: received %ld (%ld queued)<br/>\n"
               "      SMS: sent %ld (%ld queued)<br/>\n"
               "      SMS: store size %ld<br/>\n"
               "      SMS: inbound (%.2f,%.2f,%.2f) msg/sec<br/>\n"
               "      SMS: outbound (%.2f,%.2f,%.2f) msg/sec</p>\n"
               "   <p>DLR: received %ld<br/>\n"
               "      DLR: sent %ld<br/>\n"
               "      DLR: inbound (%.2f,%.2f,%.2f) msg/sec<br/>\n"
               "      DLR: outbound (%.2f,%.2f,%.2f) msg/sec<br/>\n"
               "      DLR: %ld queued<br/>\n"
               "      DLR: using %s storage</p>\n\n";
        footer = "<p>";
    } else if (status_type == BBSTATUS_XML) {
        frmt = "<version>%s</version>\n"
               "<status>%s, uptime %ldd %ldh %ldm %lds</status>\n"
               "\t<wdp>\n\t\t<received><total>%ld</total><queued>%ld</queued>"
               "</received>\n\t\t<sent><total>%ld</total><queued>%ld</queued>"
               "</sent>\n\t</wdp>\n"
               "\t<sms>\n\t\t<received><total>%ld</total><queued>%ld</queued>"
               "</received>\n\t\t<sent><total>%ld</total><queued>%ld</queued>"
               "</sent>\n\t\t<storesize>%ld</storesize>\n\t\t"
               "<inbound>%.2f,%.2f,%.2f</inbound>\n\t\t"
               "<outbound>%.2f,%.2f,%.2f</outbound>\n\t\t"
               "</sms>\n"
               "\t<dlr>\n\t\t<received><total>%ld</total></received>\n\t\t"
               "<sent><total>%ld</total></sent>\n\t\t"
               "<inbound>%.2f,%.2f,%.2f</inbound>\n\t\t"
               "<outbound>%.2f,%.2f,%.2f</outbound>\n\t\t"
               "<queued>%ld</queued>\n\t\t<storage>%s</storage>\n\t</dlr>\n";
        footer = "";
    } else {
        frmt = "%s\n\nStatus: %s, uptime %ldd %ldh %ldm %lds\n\n"
               "WDP: received %ld (%ld queued), sent %ld (%ld queued)\n\n"
               "SMS: received %ld (%ld queued), sent %ld (%ld queued), store size %ld\n"
               "SMS: inbound (%.2f,%.2f,%.2f) msg/sec, "
               "outbound (%.2f,%.2f,%.2f) msg/sec\n\n"
               "DLR: received %ld, sent %ld\n"
               "DLR: inbound (%.2f,%.2f,%.2f) msg/sec, outbound (%.2f,%.2f,%.2f) msg/sec\n"
               "DLR: %ld queued, using %s storage\n\n";
        footer = "";
    }
    
    ret = octstr_format(frmt,
        octstr_get_cstr(version),
        s, t/3600/24, t/3600%24, t/60%60, t%60,
        counter_value(incoming_wdp_counter),
        gwlist_len(incoming_wdp) + boxc_incoming_wdp_queue(),
        counter_value(outgoing_wdp_counter), gwlist_len(outgoing_wdp) + udp_outgoing_queue(),
        counter_value(incoming_sms_counter), gwlist_len(incoming_sms),
        counter_value(outgoing_sms_counter), gwlist_len(outgoing_sms),
        store_messages(),
        load_get(incoming_sms_load,0), load_get(incoming_sms_load,1), load_get(incoming_sms_load,2),
        load_get(outgoing_sms_load,0), load_get(outgoing_sms_load,1), load_get(outgoing_sms_load,2),
        counter_value(incoming_dlr_counter), counter_value(outgoing_dlr_counter),
        load_get(incoming_dlr_load,0), load_get(incoming_dlr_load,1), load_get(incoming_dlr_load,2),
        load_get(outgoing_dlr_load,0), load_get(outgoing_dlr_load,1), load_get(outgoing_dlr_load,2),
        dlr_messages(), dlr_type());

    octstr_destroy(version);
    
    append_status(ret, str, boxc_status, status_type);
    append_status(ret, str, smsc2_status, status_type);
    octstr_append_cstr(ret, footer);
    
    return ret;
}
Ejemplo n.º 19
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: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;
}
Ejemplo n.º 20
0
double BytecodeCounter::frequency() {
  return (double)counter_value() / elapsed_time();
}