예제 #1
0
/* get_matching_translations - iterate over all translations in trans. 
 * for each translation check whether 
 * the translation's keyword has already been interpreted as a regexp. 
 * if not, compile it now,
 * otherwise retrieve compilation result from dictionary.
 *
 * the translations where the word matches the translation's pattern 
 * are returned in a list
 * 
 */
static List *get_matching_translations(URLTranslationList *trans, Octstr *msg) 
{
    List *list;
    long i;
    URLTranslation *t;

    gw_assert(trans != NULL && msg != NULL);

    list = gwlist_create();
    for (i = 0; i < gwlist_len(trans->list); ++i) {
        t = gwlist_get(trans->list, i);
        
        if (t->keyword_regex == NULL)
            continue;

        if (gw_regex_match_pre(t->keyword_regex, msg) == 1) {
            debug("", 0, "match found: %s", octstr_get_cstr(t->name));
            gwlist_append(list, t);
        } else {
            debug("", 0, "no match found: %s", octstr_get_cstr(t->name));
        }
    }

    return list;
}
예제 #2
0
int smscconn_usable(SMSCConn *conn, Msg *msg)
{
    gw_assert(conn != NULL);
    gw_assert(msg != NULL && msg_type(msg) == sms);

    if (conn->status == SMSCCONN_DEAD || conn->why_killed != SMSCCONN_ALIVE)
	return -1;

    /* if allowed-smsc-id set, then only allow this SMSC if message
     * smsc-id matches any of its allowed SMSCes
     */
    if (conn->allowed_smsc_id && (msg->sms.smsc_id == NULL ||
         gwlist_search(conn->allowed_smsc_id, msg->sms.smsc_id, octstr_item_match) == NULL)) {
        return -1;
    }
    /* ..if no allowed-smsc-id set but denied-smsc-id and message smsc-id
     * is set, deny message if smsc-ids match */
    else if (conn->denied_smsc_id && msg->sms.smsc_id != NULL &&
                 gwlist_search(conn->denied_smsc_id, msg->sms.smsc_id, octstr_item_match) != NULL) {
        return -1;
    }

    if (conn->allowed_smsc_id_regex) {
        if (msg->sms.smsc_id == NULL)
            return -1;
        
        if (gw_regex_match_pre(conn->allowed_smsc_id_regex, msg->sms.smsc_id) == 0) 
            return -1;
    }
    else if (conn->denied_smsc_id_regex && msg->sms.smsc_id != NULL) {
        if (gw_regex_match_pre(conn->denied_smsc_id_regex, msg->sms.smsc_id) == 1) 
            return -1;
    }

    /* Have allowed */
    if (conn->allowed_prefix && ! conn->denied_prefix && 
       (does_prefix_match(conn->allowed_prefix, msg->sms.receiver) != 1))
	return -1;
    
    if (conn->allowed_prefix_regex && ! conn->denied_prefix_regex) {
        if (gw_regex_match_pre(conn->allowed_prefix_regex, msg->sms.receiver) == 0)
            return -1;
    }

    /* Have denied */
    if (conn->denied_prefix && ! conn->allowed_prefix &&
       (does_prefix_match(conn->denied_prefix, msg->sms.receiver) == 1))
	return -1;

    if (conn->denied_prefix_regex && ! conn->allowed_prefix_regex) {
        if (gw_regex_match_pre(conn->denied_prefix_regex, msg->sms.receiver) == 1)
            return -1;
    }

    /* Have allowed and denied */
    if (conn->denied_prefix && conn->allowed_prefix &&
       (does_prefix_match(conn->allowed_prefix, msg->sms.receiver) != 1) &&
       (does_prefix_match(conn->denied_prefix, msg->sms.receiver) == 1) )
	return -1;

    if (conn->allowed_prefix_regex && conn->denied_prefix_regex) {
        if (gw_regex_match_pre(conn->allowed_prefix_regex, msg->sms.receiver) == 0 &&
            gw_regex_match_pre(conn->denied_prefix_regex, msg->sms.receiver) == 1)
            return -1;
    }
    
    /* then see if it is preferred one */
    if (conn->preferred_smsc_id && msg->sms.smsc_id != NULL &&
         gwlist_search(conn->preferred_smsc_id, msg->sms.smsc_id, octstr_item_match) != NULL) {
        return 1;
    }

    if (conn->preferred_prefix)
	if (does_prefix_match(conn->preferred_prefix, msg->sms.receiver) == 1)
	    return 1;

    if (conn->preferred_prefix_regex &&
        gw_regex_match_pre(conn->preferred_prefix_regex, msg->sms.receiver) == 1) {
        return 1;
    }
        
    return 0;
}
예제 #3
0
/*
 * checks if a request matches the parameters of a URL-Translation, e.g. whether or not 
 * a user is allowed to use certain services. returns 0 if allowed, -1 if not.
 */
static int check_allowed_translation(URLTranslation *t,
                  Octstr *smsc, Octstr *sender, Octstr *receiver, Octstr *account)
{
    const int IS_ALLOWED = 0;
    const int NOT_ALLOWED = -1;

    /* if smsc_id set and accepted_smsc exist, accept
     * translation only if smsc id is in accept string
     */
    if (smsc && t->accepted_smsc && !gwlist_search(t->accepted_smsc, smsc, octstr_item_match))
        return NOT_ALLOWED;

    if (smsc && t->accepted_smsc_regex && gw_regex_match_pre( t->accepted_smsc_regex, smsc) == 0)
        return NOT_ALLOWED;

    /* if account_id set and accepted_account exist, accept
     * translation only if smsc id is in accept string
     */
    if (account && t->accepted_account && !gwlist_search(t->accepted_account, account, octstr_item_match))
        return NOT_ALLOWED;

    if (account && t->accepted_account_regex && gw_regex_match_pre( t->accepted_account_regex, account) == 0)
        return NOT_ALLOWED;

    /* Have allowed for sender */
    if (t->allowed_prefix && !t->denied_prefix && does_prefix_match(t->allowed_prefix, sender) != 1)
        return NOT_ALLOWED;

    if (t->allowed_prefix_regex && !t->denied_prefix_regex && gw_regex_match_pre(t->allowed_prefix_regex, sender) == 0)
        return NOT_ALLOWED;

    /* Have denied for sender */
    if (t->denied_prefix && !t->allowed_prefix && does_prefix_match(t->denied_prefix, sender) == 1)
        return NOT_ALLOWED;

    if (t->denied_prefix_regex && !t->allowed_prefix_regex && gw_regex_match_pre(t->denied_prefix_regex, sender) == 1)
        return NOT_ALLOWED;

    /* Have allowed for receiver */
    if (t->allowed_recv_prefix && !t->denied_recv_prefix && does_prefix_match(t->allowed_recv_prefix, receiver) != 1)
        return NOT_ALLOWED;

    if (t->allowed_receiver_prefix_regex && !t->denied_receiver_prefix_regex &&
        gw_regex_match_pre(t->allowed_receiver_prefix_regex, receiver) == 0)
        return NOT_ALLOWED;

    /* Have denied for receiver */
    if (t->denied_recv_prefix && !t->allowed_recv_prefix && does_prefix_match(t->denied_recv_prefix, receiver) == 1)
        return NOT_ALLOWED;

    if (t->denied_receiver_prefix_regex && !t->allowed_receiver_prefix_regex &&
        gw_regex_match_pre(t->denied_receiver_prefix_regex, receiver) == 0)
        return NOT_ALLOWED;

    if (t->white_list && numhash_find_number(t->white_list, sender) < 1) {
        return NOT_ALLOWED;
    }

    if (t->white_list_regex && gw_regex_match_pre(t->white_list_regex, sender) == 0) {
        return NOT_ALLOWED;
    }   

    if (t->black_list && numhash_find_number(t->black_list, sender) == 1) {
        return NOT_ALLOWED;
    }

    if (t->black_list_regex && gw_regex_match_pre(t->black_list_regex, sender) == 1) {
        return NOT_ALLOWED;
    }   

    /* Have allowed and denied */
    if (t->denied_prefix && t->allowed_prefix && does_prefix_match(t->allowed_prefix, sender) != 1 &&
        does_prefix_match(t->denied_prefix, sender) == 1)
        return NOT_ALLOWED;

    if (t->denied_prefix_regex && t->allowed_prefix_regex &&
        gw_regex_match_pre(t->allowed_prefix_regex, sender) == 0 &&
        gw_regex_match_pre(t->denied_prefix_regex, sender) == 1)
        return NOT_ALLOWED;

    return IS_ALLOWED;
};
예제 #4
0
파일: smpp_route.c 프로젝트: ktosiu/ksmppd
void smpp_route_message_database(SMPPServer *smpp_server, int direction, Octstr *smsc_id, Octstr *system_id, Msg *msg, void(*callback)(void *context, int result, double cost), void *context) {
    SMPPRouting *smpp_routing = smpp_server->routing;
    List *routes;
    
    long i, num_routes;
    
    int found = 0;
    SMPPRoute *route;
    
    gw_rwlock_rdlock(smpp_routing->lock);
    if(msg_type(msg) == sms) { /* we can only route sms's */
        if((direction == SMPP_ROUTE_DIRECTION_OUTBOUND) && octstr_len(system_id)) {
            /* Look for our ESME routes */
            gw_rwlock_wrlock(smpp_routing->outbound_lock);
            routes = dict_get(smpp_routing->outbound_routes, system_id);
            if(!routes) {
                routes = smpp_database_get_routes(smpp_server, direction, system_id);
                dict_put(smpp_routing->outbound_routes, system_id, routes);
            }
            gw_rwlock_unlock(smpp_routing->outbound_lock);

            num_routes = gwlist_len(routes);
            for(i=0;i<num_routes;i++) {
                route = gwlist_get(routes, i);
                found = gw_regex_match_pre(route->regex, msg->sms.receiver);
                
                if(found) {
                    break;
                }
            }
            
            if(found) {
                octstr_destroy(msg->sms.smsc_id);
                msg->sms.smsc_id = octstr_duplicate(route->smsc_id);
                debug("smpp.route.message.database", 0, "SMPP[%s] Found outbound route for %s towards %s", octstr_get_cstr(system_id), octstr_get_cstr(msg->sms.receiver), octstr_get_cstr(msg->sms.smsc_id));
                callback(context, 1, route->cost);
            } else {
                callback(context, 0, 0);
            }
        } else if((direction == SMPP_ROUTE_DIRECTION_INBOUND) && octstr_len(smsc_id)) {
            routes = smpp_routing->inbound_routes;
            num_routes = gwlist_len(routes);
            for(i=0;i<num_routes;i++) {
                route = gwlist_get(routes, i);
                found = gw_regex_match_pre(route->regex, msg->sms.receiver);
                
                if(found) {
                    break;
                }
            }
            
            if(found) {
                octstr_destroy(msg->sms.service);
                msg->sms.service = octstr_duplicate(route->system_id);
                debug("smpp.route.message.database", 0, "SMPP[%s] Found inbound route for %s from %s", octstr_get_cstr(route->system_id), octstr_get_cstr(msg->sms.receiver), octstr_get_cstr(smsc_id));
                callback(context, 1, route->cost);
            } else {
                callback(context, 0, 0);
            }
        } else {
            callback(context, 0, 0);
        }
    } else {
        callback(context, 0, 0);
    }
    
    gw_rwlock_unlock(smpp_routing->lock);
}