Hi Fajar and Alejandro,
This patch works for me ;p
Use \s for spaces.
I think that it should be commited to the cvs repository.
Hope it helps ;p
--
Humberto Figuera - Using Linux 2.6.17
Usuario GNU/Linux 369709
Caracas - Venezuela
GPG Key Fingerprint = 5AAC DF0C 00F4 2834 28BA 37AD 3364 01D1 74CA 0603
--- gw/urltrans.c 2006-10-01 13:10:23.000000000 -0400
+++ urltrans.c 2006-10-05 20:10:03.000000000 -0400
@@ -161,7 +161,7 @@
static URLTranslation *create_onetrans(CfgGroup *grp);
static void destroy_onetrans(void *ot);
static URLTranslation *find_translation(URLTranslationList *trans,
- List *words, Octstr *smsc,
+ Octstr *text, Octstr *smsc,
Octstr *sender, Octstr *receiver, int *reject, Octstr *account);
static URLTranslation *find_default_translation(URLTranslationList *trans,
Octstr *smsc, Octstr *sender, Octstr *receiver,
@@ -284,9 +284,7 @@
/* do not panic if text == NULL */
if (text != NULL) {
- words = octstr_split_words(text);
- t = find_translation(trans, words, smsc, sender, receiver, &reject, account);
- gwlist_destroy(words, octstr_destroy_item);
+ t = find_translation(trans, text, smsc, sender, receiver, &reject, account);
}
if (reject)
@@ -1364,7 +1362,7 @@
* are returned in a list
*
*/
-static List *get_matching_translations(URLTranslationList *trans, Octstr *word)
+static List* get_matching_translations(URLTranslationList *trans, List *words, Octstr *text)
{
List *list;
/*char *tmp_word;*/
@@ -1373,7 +1371,14 @@
regmatch_t p_match[10];
URLTranslation *t;
- gw_assert(trans != NULL && word != NULL);
+ Octstr *word, *allwords;
+ word = gwlist_get(words, 0);
+ word = octstr_duplicate(word);
+ octstr_convert_range(word, 0, octstr_len(word), tolower);
+ allwords = octstr_duplicate(text);
+ octstr_convert_range(allwords, 0, octstr_len(allwords), tolower);
+
+ gw_assert(trans != NULL && word != NULL && allwords != NULL);
list = gwlist_create();
for (i = 0; i < gwlist_len(trans->list); ++i) {
@@ -1382,21 +1387,24 @@
continue;
/* if regex feature is used try to match */
- if ((t->keyword_regex != NULL) &&
- (gw_regex_exec(t->keyword_regex, word, n_match, p_match, 0) == 0))
- gwlist_append(list, t);
-
- /* otherwise look for exact match */
- if (octstr_compare(t->keyword, word) == 0)
- gwlist_append(list, t);
- }
+ if (t->keyword_regex != NULL) {
+ if (gw_regex_exec(t->keyword_regex, allwords, n_match, p_match, 0) == 0) {
+ gwlist_append(list, t);
+ } else if (octstr_compare(t->keyword, word) == 0) {
+ gwlist_append(list, t);
+ }
+ }
+ }
+
+ octstr_destroy(word);
+ octstr_destroy(allwords);
return list;
}
/*
* Find the appropriate translation
*/
-static URLTranslation *find_translation(URLTranslationList *trans, List *words,
+static URLTranslation *find_translation(URLTranslationList *trans, Octstr *text,
Octstr *smsc, Octstr *sender, Octstr *receiver,
int *reject, Octstr *account)
{
@@ -1404,6 +1412,7 @@
int i, n;
URLTranslation *t = NULL;
List *list;
+ List *words = octstr_split_words(text);
n = gwlist_len(words);
if (n == 0)
@@ -1414,9 +1423,10 @@
keyword = octstr_duplicate(keyword);
octstr_convert_range(keyword, 0, octstr_len(keyword), tolower);
- list = get_matching_translations(trans, keyword);
+ list = get_matching_translations(trans, words, text);
/* 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 < gwlist_len(list); ++i) {
t = gwlist_get(list, i);
@@ -1433,6 +1443,7 @@
octstr_destroy(keyword);
gwlist_destroy(list, NULL);
+ gwlist_destroy(words, octstr_destroy_item);
return t;
}