Hi all,
Attached is a patch that does 2 things:
i) enables checking against all words (including spaces) in the
regex-keyword
ii) fixes a bug where the keyword was always taken into account even if
the regex-keyword was there.
It seems a fair number of people would like to see this in the code. I
did the patch on 1.4 and then ported it to cvs head so there a couple of
annoying whitespace differences - sorry about that.
PS - I am nearly there with the multiplex thing I think. Will report soon.
Cheers,
Gareth
--
Gareth Reakes, Managing Director Parthenon Computing
+44-1865-811184 http://www.parthcomp.com
Index: urltrans.c
===================================================================
RCS file: /home/cvs/gateway/gw/urltrans.c,v
retrieving revision 1.99
diff -u -r1.99 urltrans.c
--- urltrans.c 2 Mar 2005 13:55:00 -0000 1.99
+++ urltrans.c 21 Jun 2005 10:48:40 -0000
@@ -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,11 +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);
- gwlist_destroy(words, octstr_destroy_item);
- }
+ if (text != NULL)
+ t = find_translation(trans, text, smsc, sender, receiver, &reject);
if (reject)
t = find_black_list_translation(trans, smsc);
@@ -609,7 +606,7 @@
octstr_append(result, octstr_imm("8-BIT"));
break;
case DC_UCS2:
- octstr_append(result, octstr_imm("UTF-16BE"));
+ octstr_append(result, octstr_imm("UTF16-BE"));
break;
}
}
@@ -632,7 +629,6 @@
octstr_destroy(enc);
}
break;
-
case 'o': /* account information (may be operator id for aggregators */
if (octstr_len(request->sms.account)) {
enc = octstr_duplicate(request->sms.account);
@@ -661,6 +657,7 @@
/* XXX sms.parameters not present in here:
* * pid - will we receive this ?
+ * * mwi,mclass - will we receive these bits from smsc ?
* * alt-dcs - shouldn't be required unless we want to inform
* which alt-dcs external server should use back
* * compress - if we use compression, probably kannel would
@@ -1337,7 +1334,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;*/
@@ -1345,23 +1342,39 @@
size_t n_match = 1;
regmatch_t p_match[10];
URLTranslation *t;
+ Octstr *word, *allwords;
+
+
+ word = gwlist_get(words, 0);
+ word = octstr_duplicate(word);
+ octstr_convert_range(word, 0, octstr_len(word), tolower);
- gw_assert(trans != NULL && word != NULL);
+ 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) {
t = gwlist_get(trans->list, i);
if (t->keyword == NULL)
- continue;
+ continue;
+ //GR
/* 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(t->keyword_regex != NULL) {
+ if (gw_regex_exec(t->keyword_regex, allwords, 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);
- }
+ else if (octstr_compare(t->keyword, word) == 0) {
+ gwlist_append(list, t);
+ }
+ }
+
+ octstr_destroy(word);
+ octstr_destroy(allwords);
return list;
}
@@ -1369,23 +1382,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 = gwlist_len(words);
if (n == 0)
return NULL;
n = 1;
- keyword = gwlist_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
@@ -1405,8 +1415,9 @@
if(t != NULL)
*reject = 0;
- octstr_destroy(keyword);
gwlist_destroy(list, NULL);
+
+ gwlist_destroy(words, octstr_destroy_item);
return t;
}