Hey,

Here is the patch for 1.4. If you want CVS I posted it to the devel list to be put into the code base. For the archives the patch:

i) fixes the bug where keyword gets matched even when keyword-regex is specified

ii) allows multiple words to be specified in keyword-regex.

Cheers,

Gareth

--
Gareth Reakes, Managing Director      Parthenon Computing
+44-1865-811184                  http://www.parthcomp.com
--- gateway-1.4.0/gw/urltrans.c 2004-09-28 15:47:01.000000000 +0100
+++ /home/gareth/mbuni/kannel/gateway-1.4.0/gw/urltrans.c       2005-06-21 
11:59:59.537574964 +0100
@@ -158,7 +158,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);
 static URLTranslation *find_default_translation(URLTranslationList *trans,
                                                Octstr *smsc, Octstr *sender, 
Octstr *receiver,
@@ -280,10 +280,8 @@
     int reject = 0;
     
     /* do not panic if text == NULL */
-    if (text != NULL) {
-        words = octstr_split_words(text);
-        t = find_translation(trans, words, smsc, sender, receiver, &reject);
-        list_destroy(words, octstr_destroy_item);
+    if (text != NULL){
+        t = find_translation(trans, text, smsc, sender, receiver, &reject);
     }
     
     if (reject)
@@ -965,6 +963,7 @@
                             tolower);
 
         keyword_regex = cfg_get(grp, octstr_imm("keyword-regex"));
+
         if (keyword_regex != NULL) {
             if ((ot->keyword_regex = gw_regex_comp(keyword_regex, 
REG_EXTENDED)) == NULL)
                   panic(0, "Could not compile pattern '%s'", 
octstr_get_cstr(keyword_regex));
@@ -1321,7 +1320,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;*/
@@ -1329,23 +1328,37 @@
     size_t n_match = 1;
     regmatch_t p_match[10];
     URLTranslation *t;
+    Octstr *word, *allwords;
+
+
+    word = list_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);
+    gw_assert(trans != NULL && word != NULL && allwords != NULL);
 
     list = list_create();
     for (i = 0; i < list_len(trans->list); ++i) {
         t = list_get(trans->list, i);
         if (t->keyword == NULL) 
            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))
+                               /* if regex feature is used try to match */
+                               if(t->keyword_regex != NULL) {
+                                       if (gw_regex_exec(t->keyword_regex, 
allwords, n_match, p_match, 0) == 0) {
             list_append(list, t);
-
+                                       }
+                               }
         /* otherwise look for exact match */
-        if (octstr_compare(t->keyword, word) == 0) 
-            list_append(list, t);
-       }
+        else if (octstr_compare(t->keyword, word) == 0) {
+                                       list_append(list, t);
+                               }
+               }
+
+    octstr_destroy(word);    
+    octstr_destroy(allwords);
     return list;
 }
 
@@ -1353,23 +1366,20 @@
  * Find the appropriate translation 
  */
 static URLTranslation *find_translation(URLTranslationList *trans, 
-                    List *words, Octstr *smsc, Octstr *sender, Octstr 
*receiver, int *reject)
+                    Octstr *text, Octstr *smsc, Octstr *sender, Octstr 
*receiver, int *reject)
 {
-    Octstr *keyword;
     int i, n;
     URLTranslation *t;
     List *list;
 
+               List *words = octstr_split_words(text);
+
     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 = 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
@@ -1389,8 +1399,9 @@
     if(t != NULL)
        *reject = 0;
 
-    octstr_destroy(keyword);    
     list_destroy(list, NULL);
+
+               list_destroy(words, octstr_destroy_item);
     return t;
 }
 

Reply via email to