Hi,
attached is the patch for the feature I suggested some days ago.
It adds support for the "TYPE=USER" address format to the PPG.
I'd be glad if somebody could check and commit, as I would like to
submit some
other patches, too.
Best regards,
Georg
Index: doc/userguide/userguide.xml
===================================================================
RCS file: /home/cvs/gateway/doc/userguide/userguide.xml,v
retrieving revision 1.329
diff -u -r1.329 userguide.xml
--- doc/userguide/userguide.xml 18 Apr 2007 08:17:37 -0000 1.329
+++ doc/userguide/userguide.xml 19 Apr 2007 08:59:05 -0000
@@ -7704,6 +7704,15 @@
your push documents are <emphasis>very</emphasis>
long.
</entry></row>
+ <row><entry><literal>ppg-address-rewrite</literal></entry>
+ <entry><emphasis>string</emphasis></entry>
+ <entry valign="bottom">
+ List of white space separated pairs with a regular expression
+ and a substitution pattern to process the recipient address
+ of PAP push requests. This allows one to rewrite e.g.
+ <literal>TYPE=USER</literal> addresses to a type that
+ Kannel can process, e.g. <literal>TYPE=PLMN</literal>
+ </entry></row>
</tbody>
</tgroup>
</table>
@@ -8008,6 +8017,28 @@
</sect1>
<sect1>
+<title>Support for TYPE=USER push addresses</title>
+<para>
+While the format for IP-addresses and phone numbers is well specified in
+WAP-249-PPGService as <literal>TYPE=IPv4</literal> and
+<literal>TYPE=PLMN</literal>, the specification also contains user
+defined address types, e.g. <literal>TYPE=USER</literal>. If you
+need support for them and are able to transform them by a
+list of POSIX regular expressions and substitutions to a format understood
+by Kannel, you can support these types for your PPG client application.
+E.g., the samples given in WAP-249-PPGService like
+<programlisting>
+ WAPPUSH=47397547589/[EMAIL PROTECTED]
+</programlisting>
+can be transformed to the format Kannel can process by this directive:
+<programlisting>
+ ppg-address-rewrite "(.*=)\+?([0-9]+)/TYPE=USER(.*)$ $1+$2/TYPE=PLMN"
+</programlisting>
+The regular expression is applied case-insensitive.
+</para>
+</sect1>
+
+<sect1>
<title>Push related Kannel headers</title>
<para>This chapter recapitulates Kannel headers used by ppg.</para>
Index: gw/wap_push_pap_compiler.c
===================================================================
RCS file: /home/cvs/gateway/gw/wap_push_pap_compiler.c,v
retrieving revision 1.35
diff -u -r1.35 wap_push_pap_compiler.c
--- gw/wap_push_pap_compiler.c 7 Jan 2007 23:52:58 -0000 1.35
+++ gw/wap_push_pap_compiler.c 19 Apr 2007 08:59:08 -0000
@@ -1488,11 +1488,15 @@
* -2, address parsing error
*/
+extern List *ppg_user_rewrite;
+
int parse_address(Octstr **address, long *type_of_address)
{
long pos;
Octstr *copy;
+ wap_push_address_rewrite(address);
+
pos = octstr_len(*address) - 1;
/*
* Delete first separator, if there is one. This will help our parsing later.
Index: gw/wap_push_ppg.c
===================================================================
RCS file: /home/cvs/gateway/gw/wap_push_ppg.c,v
retrieving revision 1.71
diff -u -r1.71 wap_push_ppg.c
--- gw/wap_push_ppg.c 7 Jan 2007 23:53:00 -0000 1.71
+++ gw/wap_push_ppg.c 19 Apr 2007 08:59:13 -0000
@@ -77,6 +77,7 @@
#include <ctype.h>
#include "wap_push_ppg.h"
+#include "gwlib/regex.h"
#include "wap/wap_events.h"
#include "wap/wsp_caps.h"
#include "wml_compiler.h"
@@ -203,6 +204,7 @@
static Octstr *ppg_dlr_url = NULL;
static Octstr *ppg_smsbox_id = NULL;
static Octstr *service_name = NULL;
+static List *ppg_address_rewrite = NULL;
struct PAPEvent {
HTTPClient *client;
@@ -383,6 +385,7 @@
static int coriented_deliverable(long code);
static int is_phone_number(long type_of_address);
static void replace_octstr_char(Octstr *os1, Octstr *os2, long *pos);
+static void parse_ppg_address_rewrite(Octstr *rewrite);
/*****************************************************************************
*
@@ -507,6 +510,53 @@
return sm;
}
+/**
+ * Rewrites an address according to the setting of ppg_address_rewrite
+ * by applying a list of regular expressions and substitute patterns.
+ */
+
+void wap_push_address_rewrite(Octstr **address) {
+ int nmatch = 10;
+ int rc, i;
+ const char *src;
+ const char *input;
+ char *sub;
+ regmatch_t *pmatch;
+ Octstr *result;
+ long pos;
+
+ if (ppg_address_rewrite==NULL)
+ return;
+ pmatch = gw_malloc(sizeof (regmatch_t)*nmatch);
+
+ gwlist_lock(ppg_address_rewrite);
+ for (pos = 0; pos < gwlist_len(ppg_address_rewrite); pos += 2) {
+ rc = gw_regex_exec (
+ (regex_t*) gwlist_get(ppg_address_rewrite, pos),
+ *address, nmatch, pmatch, 0);
+ if (rc!=0)
+ continue;
+
+ input = (const char*) octstr_get_cstr(
+ (Octstr*) gwlist_get(ppg_address_rewrite, pos+1));
+ sub = gw_regex_sub(input,
+ octstr_get_cstr(*address), nmatch, pmatch);
+ if (sub==NULL)
+ continue;
+ result = octstr_create(sub);
+ info(0, "client address rewritten from <%s> to <%s>",
+ octstr_get_cstr(*address), octstr_get_cstr(result));
+ /* Somebody seems to keep the old address, so we should rather
substitute
+ * the content of *address rather than replace the octet-string
+ */
+ octstr_truncate (*address, 0);
+ octstr_append (*address, result);
+ }
+ gwlist_unlock(ppg_address_rewrite);
+ gw_free (pmatch);
+}
+
+
/*****************************************************************************
*
* INTERNAL FUNCTIONS
@@ -541,6 +591,8 @@
ppg_smsbox_id = cfg_get(grp, octstr_imm("ppg-smsbox-id"));
if ((service_name = cfg_get(grp, octstr_imm("service-name"))) == NULL)
service_name = octstr_format("%s", "ppg");
+ parse_ppg_address_rewrite (cfg_get(grp,
+ octstr_imm("ppg-address-rewrite")));
#ifdef HAVE_LIBSSL
cfg_get_integer(&ppg_ssl_port, grp, octstr_imm("ppg-ssl-port"));
@@ -580,6 +632,39 @@
return USER_CONFIGURATION_ADDED;
}
+static void parse_ppg_address_rewrite(Octstr *rewrite)
+{
+ List *l = NULL;
+ Octstr *rule;
+ Octstr *subst;
+ regex_t *rx;
+
+ if (rewrite==NULL)
+ return;
+ l = octstr_split_words(rewrite);
+ if ((gwlist_len(l) % 2) == 1) {
+ panic(0, "ppg-user-rewrite must contain an even number of elements"
+ ", e.g. \"rule1 substitution1 rule2 substitution2\"");
+ }
+ for (;;) {
+ rule = (Octstr*) gwlist_extract_first(l);
+ subst = (Octstr*) gwlist_extract_first(l);
+ if (rule==NULL || subst==NULL)
+ break;
+ rx = gw_regex_comp (rule, REG_EXTENDED | REG_ICASE);
+ if (rx==NULL) {
+ panic(0, "rule '%s' in ppg-user-rewrite is no valid regular "
+ "expression.", octstr_get_cstr(rule));
+ }
+ if (ppg_address_rewrite==NULL)
+ ppg_address_rewrite = gwlist_create();
+ gwlist_append (ppg_address_rewrite, rx);
+ gwlist_append (ppg_address_rewrite, subst);
+ octstr_destroy(rule);
+ }
+ gwlist_destroy (l, NULL);
+}
+
static int ip_allowed_by_ppg(Octstr *ip)
{
if (ip == NULL)
@@ -3364,7 +3449,3 @@
{
return octstr_duplicate(service_name);
}
-
-
-
-
Index: gw/wap_push_ppg.h
===================================================================
RCS file: /home/cvs/gateway/gw/wap_push_ppg.h,v
retrieving revision 1.15
diff -u -r1.15 wap_push_ppg.h
--- gw/wap_push_ppg.h 7 Jan 2007 23:53:03 -0000 1.15
+++ gw/wap_push_ppg.h 19 Apr 2007 08:59:13 -0000
@@ -211,4 +211,10 @@
*/
PPGSessionMachine *wap_push_ppg_have_push_session_for_sid(long sid);
+/**
+ * Rewrites an address according to the setting of ppg_address_rewrite
+ * by applying a list of regular expressions and substitute patterns.
+ */
+void wap_push_address_rewrite(Octstr **address);
+
#endif
Index: gwlib/cfg.def
===================================================================
RCS file: /home/cvs/gateway/gwlib/cfg.def,v
retrieving revision 1.128
diff -u -r1.128 cfg.def
--- gwlib/cfg.def 18 Apr 2007 08:17:37 -0000 1.128
+++ gwlib/cfg.def 19 Apr 2007 08:59:14 -0000
@@ -201,6 +201,7 @@
OCTSTR(default-dlr-url)
OCTSTR(ppg-smsbox-id)
OCTSTR(service-name)
+ OCTSTR(ppg-address-rewrite)
)