Ejemplo n.º 1
0
/*
 * Find the appropriate translation 
 */
static URLTranslation *find_translation(URLTranslationList *trans, 
                    List *words, Octstr *smsc, Octstr *sender, Octstr *receiver, int *reject)
{
    Octstr *keyword;
    int i, n;
    URLTranslation *t;
    List *list;

    n = list_len(words);
    if (n == 0)
        return NULL;
    n = 1;

    keyword = list_get(words, 0);
    keyword = octstr_duplicate(keyword);
    octstr_convert_range(keyword, 0, octstr_len(keyword), tolower);

    list = get_matching_translations(trans, keyword);
    /*
      list now contains all translations where the keyword of the sms matches the
      pattern defined by the tranlsation's keyword
    */
    t = NULL;
    for (i = 0; i < list_len(list); ++i) {
        t = list_get(list, i);

        if (check_allowed_translation(t, smsc, sender, receiver, reject) == 0
            && check_num_args(t, words) == 0)
	    break;

	t = NULL;
    }

    /* Only return reject if there's only blacklisted smsc's */
    if(t != NULL)
	*reject = 0;

    octstr_destroy(keyword);    
    list_destroy(list, NULL);
    return t;
}
Ejemplo n.º 2
0
/*
 * Find the appropriate translation 
 */
static URLTranslation *find_translation(URLTranslationList *trans, Msg *msg)
{
    Octstr *data;
    int i;
    URLTranslation *t = NULL;
    List *list, *words;

    /* convert tolower and try to match */
    data = octstr_duplicate(msg->sms.msgdata);
    i = 0;
    while((i = octstr_search_char(data, 0, i)) != -1 && i < octstr_len(data) - 1) {
        octstr_delete(data, i, 1);
    }
    
    list = get_matching_translations(trans, data);
    words = octstr_split_words(data);

    /**
     * List now contains all translations where the keyword of the sms 
     * matches the pattern defined by the tranlsation's keyword.
     */
    for (i = 0; i < gwlist_len(list); ++i) {
        t = gwlist_get(list, i);

        /* TODO check_num_args, do we really need this??? */
        if (check_allowed_translation(t, msg->sms.smsc_id, msg->sms.sender, msg->sms.receiver, msg->sms.account) == 0
            && check_num_args(t, words) == 0)
            break;

        t = NULL;
    }

    octstr_destroy(data);
    gwlist_destroy(words, octstr_destroy_item);
    gwlist_destroy(list, NULL);
    
    return t;
}