Пример #1
0
gw_prioqueue_t *gw_prioqueue_create(int(*cmp)(const void*, const void *))
{
    gw_prioqueue_t *ret;
     
    gw_assert(cmp != NULL);
    
    ret = gw_malloc(sizeof(*ret));
    ret->producers = 0;
    pthread_cond_init(&ret->nonempty, NULL);
    ret->mutex = mutex_create();
    ret->tab = NULL;
    ret->size = 0;
    ret->len = 0;
    ret->seq = 0;
    ret->cmp = cmp;
    
    /* put NULL item at pos 0 that is our stop marker */
    make_bigger(ret, 1);
    ret->tab[0] = gw_malloc(sizeof(**ret->tab));
    ret->tab[0]->item = NULL;
    ret->tab[0]->seq = ret->seq++;
    ret->len++;
    
    return ret;
}
Пример #2
0
static DBConf *sqlite3_create_conf(Octstr *db)
{
    DBConf *conf;
    conf = gw_malloc(sizeof(DBConf));
    conf->sqlite3 = gw_malloc(sizeof(SQLite3Conf));

    conf->sqlite3->file = octstr_duplicate(db);

    return conf;
}
Пример #3
0
/*
 * Create a new timer heap.
 */
static TimerHeap *heap_create(void)
{
    TimerHeap *heap;

    heap = gw_malloc(sizeof(*heap));
    heap->tab = gw_malloc(sizeof(heap->tab[0]));
    heap->size = 1;
    heap->len = 0;

    return heap;
}
Пример #4
0
static DBConf *oracle_create_conf(Octstr *user,Octstr *pass, Octstr *db)
{
    DBConf *conf;
    conf = gw_malloc(sizeof(DBConf));
    conf->oracle = gw_malloc(sizeof(OracleConf));

    conf->oracle->username = octstr_duplicate(user);
    conf->oracle->password = octstr_duplicate(pass);
    conf->oracle->tnsname = octstr_duplicate(db);

    return conf;
}
Пример #5
0
static long spawn_thread(gwthread_func_t *func, const char *name, void *arg)
{
    int ret;
    pthread_t id;
    struct new_thread_args *p = NULL;
    long new_thread_id;

    /* We want to pass both these arguments to our wrapper function
     * new_thread, but the pthread_create interface will only let
     * us pass one pointer.  So we wrap them in a little struct. */
    p = gw_malloc(sizeof(*p));
    p->func = func;
    p->arg = arg;
    p->ti = gw_malloc(sizeof(*(p->ti)));
    p->failed = 0;

    /* Lock the thread table here, so that new_thread can block
     * on that lock.  That way, the new thread won't start until
     * we have entered it in the thread table. */
    lock();

    if (active_threads >= THREADTABLE_SIZE) {
        unlock();
        warning(0, "Too many threads, could not create new thread.");
        gw_free(p);
        return -1;
    }

    ret = pthread_create(&id, NULL, &new_thread, p);
    if (ret != 0) {
        unlock();
        error(ret, "Could not create new thread.");
        gw_free(p);
        return -1;
    }
    ret = pthread_detach(id);
    if (ret != 0) {
        error(ret, "Could not detach new thread.");
    }

    new_thread_id = fill_threadinfo(id, name, func, p->ti);
    if (new_thread_id == -1)
        p->failed = 1;
    unlock();
    
    if (new_thread_id != -1)
        debug("gwlib.gwthread", 0, "Started thread %ld (%s)", new_thread_id, name);
    else
        debug("gwlib.gwthread", 0, "Failed to start thread (%s)", name);

    return new_thread_id;
}
Пример #6
0
static DBConf *mysql_create_conf(Octstr *user, Octstr *pass, Octstr *db, Octstr *host)
{
    DBConf *conf;
    conf = gw_malloc(sizeof(DBConf));
    conf->mysql = gw_malloc(sizeof(MySQLConf));

    conf->mysql->username = octstr_duplicate(user);
    conf->mysql->password = octstr_duplicate(pass);
    conf->mysql->database = octstr_duplicate(db);
    conf->mysql->host = octstr_duplicate(host);

    return conf;
}
Пример #7
0
int udp_recvfrom(int s, Octstr **datagram, Octstr **addr)
{
    struct sockaddr_in sa;
    socklen_t salen;
    char *buf;
    int bytes;

    buf = gw_malloc(UDP_PACKET_MAX_SIZE);

    salen = sizeof(sa);
    bytes = recvfrom(s, buf, UDP_PACKET_MAX_SIZE, 0, (struct sockaddr *) &sa, &salen);
    if (bytes == -1) {
        if (errno != EAGAIN)
            error(errno, "Couldn't receive UDP packet");
	gw_free(buf);
        return -1;
    }

    *datagram = octstr_create_from_data(buf, bytes);
    *addr = octstr_create_from_data((char *) &sa, salen);

    gw_free(buf);

    return 0;
}
Пример #8
0
wtls_PDU *wtls_pdu_create(int type) {
        wtls_PDU *pdu;
        
        pdu = gw_malloc(sizeof(*pdu));
        pdu->type = type;
        pdu->reserved = 0;
        pdu->cipher = 0;
        pdu->seqnum = 0;
        pdu->rlen = 0;
        
        switch (pdu->type) {
        case ChangeCipher_PDU:
                pdu->u.cc.change = 1;
				break;
        case Alert_PDU:
                pdu->u.alert.level = 0;
                pdu->u.alert.desc = 0;
                pdu->u.alert.chksum = 0;
				break;
        case Handshake_PDU:
                pdu->u.handshake.msg_type = 0;
                pdu->u.handshake.length = 0;
				break;
        case Application_PDU:
                pdu->u.application.data = NULL;
				break;
        default:
                warning(0, "Cannot create unknown WTLS PDU type %d", pdu->type);
                break;
        }

        return pdu;
}
Пример #9
0
static void start_push(HTTPCaller *caller, long i)   
{
    List *push_headers;
    Octstr *push_content;
    long *id;
    
    push_content = push_content_create();
    push_headers = push_headers_create(octstr_len(push_content));
    if (verbose) {
       debug("test.ppg", 0, "we have push content");
       octstr_dump(push_content, 0);
       debug("test.ppg", 0, "and headers");
       http_header_dump(push_headers);
    }

    id = gw_malloc(sizeof(long));
    *id = i;
    make_url(&push_url);
    debug("test.ppg", 0, "TEST_PPG: starting to push job %ld", i);
    http_start_request(caller, HTTP_METHOD_POST, push_url, push_headers, 
                       push_content, 0, id, ssl_client_certkey_file);
    debug("test.ppg", 0, "push done");
    octstr_destroy(push_content);
    http_destroy_headers(push_headers);
}
Пример #10
0
static void sql_to_bearerbox(void *arg)
{
    Boxc *boxc;

    boxc = gw_malloc(sizeof(Boxc));
    boxc->bearerbox_connection = connect_to_bearerbox_real(bearerbox_host, bearerbox_port, bearerbox_port_ssl, NULL /* bb_our_host */);
    boxc->smsbox_connection = NULL;
    boxc->client_ip = NULL;
    boxc->alive = 1;
    boxc->connect_time = time(NULL);
    boxc->boxc_id = octstr_duplicate(sqlbox_id);
    if (boxc->bearerbox_connection == NULL) {
        boxc_destroy(boxc);
        return;
    }

    gwthread_create(bearerbox_to_sql, boxc);
    identify_to_bearerbox(boxc);

    if (gw_sql_fetch_msg_list == NULL || gw_sql_save_list == NULL || limit_per_cycle <= 1) {
        sql_single(boxc);
    }
    else {
        sql_list(boxc);
    }

    boxc_destroy(boxc);
}
Пример #11
0
unsigned int dbpool_increase(DBPool *p, unsigned int count)
{
    unsigned int i, opened = 0;

    gw_assert(p != NULL && p->conf != NULL && p->db_ops != NULL && p->db_ops->open != NULL);


    /* lock dbpool for updates */
    gwlist_lock(p->pool);

    /* ensure we don't increase more items than the max_size border */
    for (i=0; i < count && p->curr_size < p->max_size; i++) {
        void *conn = p->db_ops->open(p->conf);
        if (conn != NULL) {
            DBPoolConn *pc = gw_malloc(sizeof(DBPoolConn));
            gw_assert(pc != NULL);

            pc->conn = conn;
            pc->pool = p;

            p->curr_size++;
            opened++;
            gwlist_produce(p->pool, pc);
        }
    }

    /* unlock dbpool for updates */
    gwlist_unlock(p->pool);

    return opened;
}
Пример #12
0
static Udpc *udpc_create(int port, char *interface_name)
{
    Udpc *udpc;
    Octstr *os;
    int fl;
    
    udpc = gw_malloc(sizeof(Udpc));
    udpc->fd = udp_bind(port, interface_name);

    os = octstr_create(interface_name);
    udpc->addr = udp_create_address(os, port);
    octstr_destroy(os);
    if (udpc->addr == NULL) {
	error(0, "updc_create: could not resolve interface <%s>",
	      interface_name);
	close(udpc->fd);
	gw_free(udpc);
	return NULL;
    }

    fl = fcntl(udpc->fd, F_GETFL);
    fcntl(udpc->fd, F_SETFL, fl | O_NONBLOCK);

    os = udp_get_ip(udpc->addr);
    debug("bb.udp", 0, "udpc_create: Bound to UDP <%s:%d>",
	  octstr_get_cstr(os), udp_get_port(udpc->addr));

    octstr_destroy(os);
    
    udpc->outgoing_list = gwlist_create();

    return udpc;
}    
Пример #13
0
/******************************************************************************
* Log out and close the socket
*
*/
int cimd_close(SMSCenter *smsc)
{

    char *cbuff = NULL;
    int sum;
    int ret;

    if (smsc->socket == -1) {
        debug("bb.sms.cimd", 0, "Trying to close cimd while already closed!");
        return 0;
    }
    cbuff = gw_malloc(2 * 1024);

    sprintf(cbuff, "%c%s%c%s%c%c", 0x02, "02", 0x09, "11", 0x03, 0x0A);

    sum = write_to_socket(smsc->socket, cbuff);
    if (sum < 0) goto error;

    /* this time we don't block waiting for acknowledge */
    recv(smsc->socket, cbuff, 2*1024, 0);

    gw_free(cbuff);

    ret = close(smsc->socket);
    smsc->socket = -1;
    return ret;

error:
    gw_free(cbuff);
    return -1;
}
Пример #14
0
SMPPOutboundRoutes *smpp_outbound_routes_create() {
    SMPPOutboundRoutes *smpp_outbound_routes = gw_malloc(sizeof(SMPPOutboundRoutes));
    smpp_outbound_routes->system_id = NULL;
    smpp_outbound_routes->routes = NULL;
    smpp_outbound_routes->lock = gw_rwlock_create();
    return smpp_outbound_routes;
}
Пример #15
0
int load_add_interval(Load *load, int interval)
{
    int i;
    struct load_entry *entry;
    
    if (load == NULL)
        return -1;
    
    gw_rwlock_wrlock(load->lock);
    
    /* first look if we have equal interval added already */
    for (i = 0; i < load->len; i++) {
        if (load->entries[i]->interval == interval) {
            gw_rwlock_unlock(load->lock);
            return -1;
        }
    }
    /* so no equal interval there, add new one */
    entry = gw_malloc(sizeof(struct load_entry));
    entry->prev = entry->curr = 0.0;
    entry->interval = interval;
    entry->dirty = 1;
    time(&entry->last);
    
    load->entries = gw_realloc(load->entries, sizeof(struct load*) * (load->len + 1));
    load->entries[load->len] = entry;
    load->len++;
    
    gw_rwlock_unlock(load->lock);
    
    return 0;
}
Пример #16
0
static void construct_linear_table(struct table *table, const struct linear_element *strings, 
                                   long size)
{
    long i;

    table->size = size;
    table->strings = gw_malloc(size * (sizeof table->strings[0]));
    table->numbers = NULL;
    table->versions = gw_malloc(size * (sizeof table->versions[0]));
    table->linear = 1;

    for (i = 0; i < size; i++) {
        table->strings[i] = octstr_imm(strings[i].str);
        table->versions[i] = strings[i].version;
    }
}
Пример #17
0
/*
 * XXX bad assumption here that conn_wrap_fd for SSL can only happens
 * for the server side!!!! FIXME !!!!
 */
Connection *conn_wrap_fd(int fd, int ssl)
{
    Connection *conn;

    if (socket_set_blocking(fd, 0) < 0)
        return NULL;

    conn = gw_malloc(sizeof(*conn));
    conn->inlock = mutex_create();
    conn->outlock = mutex_create();
    conn->claimed = 0;

    conn->outbuf = octstr_create("");
    conn->outbufpos = 0;
    conn->inbuf = octstr_create("");
    conn->inbufpos = 0;

    conn->fd = fd;
    conn->connected = yes;
    conn->read_eof = 0;
    conn->io_error = 0;
    conn->output_buffering = DEFAULT_OUTPUT_BUFFERING;

    conn->registered = NULL;
    conn->callback = NULL;
    conn->callback_data = NULL;
    conn->callback_data_destroyer = NULL;
    conn->listening_pollin = 0;
    conn->listening_pollout = 0;
#ifdef HAVE_LIBSSL
    /*
     * do all the SSL magic for this connection
     */
    if (ssl) {
        conn->ssl = SSL_new(global_server_ssl_context);
        conn->peer_certificate = NULL;

        /* SSL_set_fd can fail, so check it */
        if (SSL_set_fd(conn->ssl, conn->fd) == 0) {
            /* SSL_set_fd failed, log error and return NULL */
            error(errno, "SSL: OpenSSL: %.256s", ERR_error_string(ERR_get_error(), NULL));
            conn_destroy(conn);
            return NULL;
        }
        /* SSL_set_verify(conn->ssl, 0, NULL); */

        /* set read/write BIO layer to non-blocking mode */
        BIO_set_nbio(SSL_get_rbio(conn->ssl), 1);
        BIO_set_nbio(SSL_get_wbio(conn->ssl), 1);

        /* set accept state , SSL-Handshake will be handled transparent while SSL_[read|write] */
         SSL_set_accept_state(conn->ssl);
    } else {
        conn->ssl = NULL;
        conn->peer_certificate = NULL;
    }
#endif /* HAVE_LIBSSL */

    return conn;
}
Пример #18
0
RADIUS_PDU *radius_pdu_create(int type, RADIUS_PDU *req)
{
    RADIUS_PDU *pdu;

    pdu = gw_malloc(sizeof(*pdu));
    pdu->type = type;

    switch (type) {
    #define INTEGER(name, octets) \
   	if (strcmp(#name, "code") == 0) p->name = type; \
    else p->name = 0;
    #define OCTETS(name, field_giving_octets) p->name = NULL;
    #define PDU(name, id, fields) \
    	case id: { \
	    struct name *p = &pdu->u.name; \
	    pdu->type_name = #name; \
	    fields \
	} break;
    #include "radius_pdu.def"
    default:
    	error(0, "Unknown RADIUS_PDU type, internal error.");
    	gw_free(pdu);
	return NULL;
    }
    #define ATTR(attr, type, string, min, max)
    #define UNASSIGNED(attr)
    #define ATTRIBUTES(fields) \
        pdu->attr = dict_create(20, (void (*)(void *))octstr_destroy);
    #include "radius_attributes.def"

    return pdu;
}
Пример #19
0
static WTLSMachine *wtls_machine_create(WAPAddrTuple * tuple)
{

        WTLSMachine *wtls_machine;
        wtls_machine = gw_malloc(sizeof(WTLSMachine)); 
        
#define MACHINE(field) field
#define ENUM(name) wtls_machine->name = NULL_STATE;
#define ADDRTUPLE(name) wtls_machine->name = NULL;
#define INTEGER(name) wtls_machine->name = 0;
#define OCTSTR(name) wtls_machine->name = NULL;
#define PDULIST(name) wtls_machine->name = NULL;
#include "wtls_machine-decl.h"
        
        gwlist_append(wtls_machines, wtls_machine);
        wtls_machine->mid = counter_increase(wtls_machine_id_counter);
        wtls_machine->addr_tuple = wap_addr_tuple_duplicate(tuple);
   wtls_machine->server_seq_num = wtls_machine->client_seq_num = -1;
   wtls_machine->last_refresh = -1;

		wtls_machine->handshake_data = octstr_create("");
		
   debug("wap.wtls", 0, "WTLS: Created WTLSMachine %ld (0x%p)",
         wtls_machine->mid, (void *)wtls_machine);
        return wtls_machine;
}
Пример #20
0
/* linux version */
int gw_gethostbyname(struct hostent *ent, const char *name, char **buff)
{
    struct hostent *tmphp, hp;
    int herr, res;
    size_t bufflen;

    tmphp = NULL; /* for compiler please */

    bufflen = 1024;
    *buff = (char*) gw_malloc(bufflen);
    while ((res=gethostbyname_r(name, &hp,*buff, bufflen, &tmphp, &herr)) == ERANGE) {
        /* enlarge the buffer */
	bufflen *= 2;
	*buff = (char*) gw_realloc(*buff, bufflen);
    }

    if (res != 0 || tmphp == NULL) {
        error(herr, "Error while gw_gethostbyname occurs.");
        gw_free(*buff);
        *buff = NULL;
        res = -1;
    }
    else {
        *ent = hp;
    }

    return res;
}
Пример #21
0
static WTPInitMachine *init_machine_create(WAPAddrTuple *tuple, unsigned short
                                           tid, int tidnew)
{
     WTPInitMachine *init_machine;
	
     init_machine = gw_malloc(sizeof(WTPInitMachine)); 
        
     #define ENUM(name) init_machine->name = INITIATOR_NULL_STATE;
     #define INTEGER(name) init_machine->name = 0; 
     #define EVENT(name) init_machine->name = NULL;
     #define TIMER(name) init_machine->name = gwtimer_create(queue); 
     #define ADDRTUPLE(name) init_machine->name = NULL; 
     #define MACHINE(field) field
     #include "wtp_init_machine.def"

     gwlist_append(init_machines, init_machine);

     init_machine->mid = counter_increase(init_machine_id_counter);
     init_machine->addr_tuple = wap_addr_tuple_duplicate(tuple);
     init_machine->tid = tid;
     init_machine->tidnew = tidnew;
	
     debug("wap.wtp", 0, "WTP: Created WTPInitMachine %p (%ld)", 
	   (void *) init_machine, init_machine->mid);

     return init_machine;
}
Пример #22
0
SMPP_PDU *smpp_pdu_create(unsigned long type, unsigned long seq_no)
{
    SMPP_PDU *pdu;

    pdu = gw_malloc(sizeof(*pdu));
    pdu->type = type;

    switch (type) {
    #define OPTIONAL_BEGIN
    #define TLV_INTEGER(name, octets) p->name = -1;
    #define TLV_NULTERMINATED(name, max_len) p->name = NULL;
    #define TLV_OCTETS(name, min_len, max_len) p->name = NULL;
    #define OPTIONAL_END
    #define INTEGER(name, octets) \
   	if (strcmp(#name, "command_id") == 0) p->name = type; \
    	else if (strcmp(#name, "sequence_number") == 0) p->name = seq_no; \
    	else p->name = 0;
    #define NULTERMINATED(name, max_octets) p->name = NULL;
    #define OCTETS(name, field_giving_octetst) p->name = NULL;
    #define PDU(name, id, fields) \
    	case id: { \
	    struct name *p = &pdu->u.name; \
	    pdu->type_name = #name; \
	    fields \
	} break;
    #include "smpp_pdu.def"
    default:
    	error(0, "Unknown SMPP_PDU type, internal error.");
    	gw_free(pdu);
	return NULL;
    }

    return pdu;
}
Пример #23
0
static SMASI *smasi_create(SMSCConn *conn) 
{

    SMASI *smasi = gw_malloc(sizeof(SMASI));

    smasi->conn = conn;

    smasi->thread_handle = -1;
    smasi->msgs_to_send = gwlist_create();
    smasi->sent_msgs = dict_create(16, NULL);
    smasi->received_msgs = gwlist_create();
    smasi->message_id_counter = counter_create();
    smasi->host = NULL;
    smasi->username = NULL;
    smasi->password = NULL;
    smasi->source_addr_ton = -1;
    smasi->source_addr_npi = -1;
    smasi->dest_addr_ton = -1;
    smasi->dest_addr_npi = -1;
    smasi->my_number = NULL;
    smasi->port = 21500;
    smasi->quitting = 0;
    smasi->logged_off = 0;
    smasi->priority = 0;
    smasi->throttling_err_time = 0;
    smasi->enquire_link_interval = 30;

    gwlist_add_producer(smasi->msgs_to_send);

    return smasi;
} 
Пример #24
0
static WSPMachine *machine_create(void) {
	WSPMachine *p;
	
	p = gw_malloc(sizeof(WSPMachine));
	debug("wap.wsp", 0, "WSP: Created WSPMachine %p", (void *) p);
	
	#define INTEGER(name) p->name = 0;
	#define OCTSTR(name) p->name = NULL;
	#define HTTPHEADERS(name) p->name = NULL;
	#define ADDRTUPLE(name) p->name = NULL;
	#define MACHINESLIST(name) p->name = gwlist_create();
	#define CAPABILITIES(name) p->name = NULL;
	#define COOKIES(name) p->name = gwlist_create();
	#define REFERER(name) p->name = NULL;
	#define MACHINE(fields) fields
	#include "wsp_server_session_machine.def"
	
	p->state = NULL_SESSION;

	/* set capabilities to default values (defined in 1.1) */

	p->client_SDU_size = 1400;
	p->MOR_push = 1;
	
	/* Insert new machine at the _front_, because 1) it's more likely
	 * to get events than old machines are, so this speeds up the linear
	 * search, and 2) we want the newest machine to get any method
	 * invokes that come through before the Connect is established. */
	gwlist_insert(session_machines, 0, p);

	return p;
}
Пример #25
0
/*
 * Load all configuration directives that are common for all database
 * types that use the 'dlr-db' group to define which attributes are 
 * used in the table
 */
struct dlr_db_fields *dlr_db_fields_create(CfgGroup *grp)
{
    struct dlr_db_fields *ret = NULL;

    ret = gw_malloc(sizeof(*ret));
    gw_assert(ret != NULL);
    memset(ret, 0, sizeof(*ret));

    if (!(ret->table = cfg_get(grp, octstr_imm("table"))))
   	    panic(0, "DLR: DB: directive 'table' is not specified!");
    if (!(ret->field_smsc = cfg_get(grp, octstr_imm("field-smsc"))))
   	    panic(0, "DLR: DB: directive 'field-smsc' is not specified!");
    if (!(ret->field_ts = cfg_get(grp, octstr_imm("field-timestamp"))))
        panic(0, "DLR: DB: directive 'field-timestamp' is not specified!");
    if (!(ret->field_src = cfg_get(grp, octstr_imm("field-source"))))
   	    panic(0, "DLR: DB: directive 'field-source' is not specified!");
    if (!(ret->field_dst = cfg_get(grp, octstr_imm("field-destination"))))
   	    panic(0, "DLR: DB: directive 'field-destination' is not specified!");
    if (!(ret->field_serv = cfg_get(grp, octstr_imm("field-service"))))
   	    panic(0, "DLR: DB: directive 'field-service' is not specified!");
    if (!(ret->field_url = cfg_get(grp, octstr_imm("field-url"))))
   	    panic(0, "DLR: DB: directive 'field-url' is not specified!");
    if (!(ret->field_mask = cfg_get(grp, octstr_imm("field-mask"))))
        panic(0, "DLR: DB: directive 'field-mask' is not specified!");
    if (!(ret->field_status = cfg_get(grp, octstr_imm("field-status"))))
   	    panic(0, "DLR: DB: directive 'field-status' is not specified!");
    if (!(ret->field_boxc = cfg_get(grp, octstr_imm("field-boxc-id"))))
   	    panic(0, "DLR: DB: directive 'field-boxc-id' is not specified!");

    return ret;
}
Пример #26
0
/*
 * Malloc callback function to get tracking of OCI allocs.
 */
static void *oracle_malloc(void *ctx, size_t size)
{
    void *ret = gw_malloc(size);
    debug("dbpool.oracle",0,"oracle_malloc called size=%ld @%08lx", (long) size, 
          (long) ret);
    return ret;
}
Пример #27
0
SMASI_PDU *smasi_pdu_create(unsigned long type) 
{
    SMASI_PDU *pdu;

    pdu = gw_malloc(sizeof(*pdu));
    pdu->type = type;

    switch (type) {
    #define NONTERMINATED(name) p->name = NULL;
    #define COMATERMINATED(name) p->name = NULL;
    #define PDU(name, id, fields) \
        case id: { \
        struct name *p = &pdu->u.name; \
        pdu->type_name = #name; \
        pdu->needs_hyphen = (id < SMASI_HYPHEN_ID ? 1 : 0); \
        fields \
    } break;
    #include "smasi_pdu.def"
    default:
        warning(0, "Unknown SMASI_PDU type, internal error.");
        gw_free(pdu);
    return NULL;
    }

    return pdu;
}
Пример #28
0
static void *mongodb_open_conn(const DBConf *db_conf)
{
    MongoDBConf *conf = db_conf->mongodb;
    mongo_connection *conn; /* ptr */
    mongo_conn_return status;
    mongo_conf = conf;
/*
    octstr_get_cstr(conf->username),
    octstr_get_cstr(conf->password),
    octstr_get_cstr(conf->database),
*/
    conn = gw_malloc(sizeof(mongo_connection));
    gw_assert(conn != NULL);

    info(0, "MongoDB: connecting to %s:%lu", octstr_get_cstr(conf->host), conf->port);

    status = mongo_connect(conn, octstr_get_cstr(conf->host), conf->port);

    switch (status) {
    case mongo_conn_success:
        info(0, "MongoDB: connected");
        break;
    case mongo_conn_bad_arg:
        error(0, "MongoDB: bad arguments");
        goto failed;
    case mongo_conn_no_socket:
        error(0, "MongoDB: no socket");
        goto failed;
    case mongo_conn_fail:
        error(0, "MongoDB: connection failed");
        goto failed;
    case mongo_conn_not_master:
        error(0, "MongoDB: not master");
        goto failed;
    case mongo_conn_bad_set_name:
	error(0, "MongoDB: bad set name");
	goto failed;
    case mongo_conn_cannot_find_primary:
	error(0, "MongoDB: cannot find primary");
	goto failed;
    }

/*
    if (conf->username && conf->password &&
        !mongo_cmd_authenticate(conn, octstr_get_cstr(conf->database), octstr_get_cstr(conf->username), octstr_get_cstr(conf->password))) {
        error(0, "MongoDB: authentication failed");
        goto failed;
    }
*/

    return conn;

failed:
    if (conn != NULL) {
        mongo_destroy(conn);
        gw_free(conn);
    }
    return NULL;
}
Пример #29
0
DBPool *dbpool_create(enum db_type db_type, DBConf *conf, unsigned int connections)
{
    DBPool *p;

    if (conf == NULL)
        return NULL;

    p = gw_malloc(sizeof(DBPool));
    gw_assert(p != NULL);
    p->pool = gwlist_create();
    gwlist_add_producer(p->pool);
    p->max_size = connections;
    p->curr_size = 0;
    p->conf = conf;
    p->db_type = db_type;

    switch(db_type) {
#ifdef HAVE_MYSQL
        case DBPOOL_MYSQL:
            p->db_ops = &mysql_ops;
            break;
#endif
#ifdef HAVE_ORACLE
        case DBPOOL_ORACLE:
            p->db_ops = &oracle_ops;
            break;
#endif
#ifdef HAVE_SQLITE
        case DBPOOL_SQLITE:
            p->db_ops = &sqlite_ops;
            break;
#endif
#ifdef HAVE_SQLITE3
        case DBPOOL_SQLITE3:
            p->db_ops = &sqlite3_ops;
            break;
#endif
#ifdef HAVE_SDB
        case DBPOOL_SDB:
            p->db_ops = &sdb_ops;
            break;
#endif
#ifdef HAVE_PGSQL
       case DBPOOL_PGSQL:
           p->db_ops = &pgsql_ops;
           break;
#endif
        default:
            panic(0, "Unknown dbpool type defined.");
    }

    /*
     * XXX what is todo here if not all connections
     * where established ???
     */
    dbpool_increase(p, connections);

    return p;
}
Пример #30
0
 SMPPBlockedIp *smpp_blocked_ip_create() {
    SMPPBlockedIp *smpp_blocked_ip = gw_malloc(sizeof(SMPPBlockedIp));
    smpp_blocked_ip->ip = NULL;
    smpp_blocked_ip->time_blocked = 0;
    smpp_blocked_ip->attempts = 0;

    return smpp_blocked_ip;
 }