[PATCH] WAP access-log logging 502 (Bad Gateway) for HTTP requests failing

Stipe Tolj <[email protected]>
Newsgroups gmane.comp.mobile.kannel.devel
Organization Wapme Systems AG
Message-ID <[email protected]>
Hi list,

here is a patch that will allow to log 502 HTTP response code for
proxied WAP GW requests that did not have any internal HTTP response
code, ie. wapbox could not connect to the port or host was not
reachable.

Please try and vote on commitment.

Stipe

mailto:[email protected]
-------------------------------------------------------------------
Wapme Systems AG

Münsterstr. 248
40470 Düsseldorf, NRW, Germany

phone: +49.211.74845.0
fax: +49.211.74845.299

mailto:[email protected]
http://www.wapme-systems.de/
-------------------------------------------------------------------

-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: GnuPG v1.2.2 (Cygwin)

mIsEP6mcYwEEAMDnUiUwrbb+xwTFWN6TxF2+XZu7/alwJMeCwMBRvXtPZqfjpPhS
OkBpU0F4TrVuugz1HINTSaJTYq10AzDQXp5NkyWgckqW79nPAWuOX0dicbJk+cN2
nM2TI4KaxUDe6u8hghNEnH/i2lXsUu9apnP/iixzV81VC2je3uc9hZpnAAYptEVT
dGlwZSBUb2xqIChUZWNobm9sb2d5IENlbnRlciAmIFJlc2VhcmNoIExhYikgPHRv
bGpAd2FwbWUtc3lzdGVtcy5kZT6ItAQTAQIAHgUCP6mcYwIbAwYLCQgHAwIDFQID
AxYCAQIeAQIXgAAKCRABV0w1BqPYRuSqA/wPzsQxao2YePENCtgRTrO86U6zg3sl
OcS6CJFI4FZP5h/xD3GRsNH1+MPSvZlomDdpFnr547DGz/Kq9MXuQwVvlVig5yWZ
K5dtKp1r5YLhxJQBhfirZbRFFnYmf19f18J8OoS28tuFVftDl1AIwJS3HLyBTv6H
g2HyLAEKQIp30Q==
=aYCI
-----END PGP PUBLIC KEY BLOCK-----
wap-access.patch (application/x-unknown-content-type-patch_auto_file, 3.9 KB)
Index: gw/wap-appl.c 
=================================================================== 
RCS file: /home/cvs/gateway/gw/wap-appl.c,v 
retrieving revision 1.101 
diff -u -r1.101 wap-appl.c 
--- gw/wap-appl.c	2 Dec 2003 09:19:20 -0000	1.101 
+++ gw/wap-appl.c	15 Dec 2003 13:19:13 -0000 
@@ -718,10 +718,13 @@ 
     int converted; 
     WSPMachine *sm; 
     List *device_headers; 
+    WAPAddrTuple *addr_tuple; 
+    Octstr *ua, *server; 
  
     content.url = url; 
     content.body = content_body; 
-    content.version = NULL; 
+    content.version = content.type = content.charset = NULL; 
+    server = ua = NULL; 
  
     /* Get session machine for this session. If this was a connection-less 
      * request be obviously will not find any session machine entry. */ 
@@ -734,8 +737,40 @@ 
     if (device_headers == NULL) 
         device_headers = list_create(); 
  
+    /*  
+     * We are acting as a proxy. Hence ensure we log a correct HTTP response 
+     * code to our access-log file to allow identification of failed proxying 
+     * requests in the main accesss-log. 
+     */ 
+    /* get client IP and User-Agent identifier */ 
+    addr_tuple = (orig_event->type == S_MethodInvoke_Ind) ? 
+        orig_event->u.S_MethodInvoke_Ind.addr_tuple :  
+        orig_event->u.S_Unit_MethodInvoke_Ind.addr_tuple; 
+    ua = http_header_value(request_headers, octstr_imm("User-Agent")); 
+ 
+    if (headers != NULL) { 
+        /* get response content type and Server identifier */ 
+        http_header_get_content_type(headers, &content.type, &content.charset); 
+        server = http_header_value(headers, octstr_imm("Server")); 
+    } 
+ 
+    /* log the access */ 
+    /* XXX make this configurable in the future */ 
+    alog("%s %s <%s> (%s, charset='%s') %ld %d <%s> <%s>",  
+         octstr_get_cstr(addr_tuple->remote->address),  
+         octstr_get_cstr(method), octstr_get_cstr(url),  
+         content.type ? octstr_get_cstr(content.type) : "",  
+         content.charset ? octstr_get_cstr(content.charset) : "", 
+         octstr_len(content.body), status < 0 ? HTTP_BAD_GATEWAY : status, 
+         ua ? octstr_get_cstr(ua) : "", 
+         server ? octstr_get_cstr(server) : ""); 
+ 
+    octstr_destroy(ua); 
+    octstr_destroy(server); 
+     
+ 
     if (status < 0) { 
-        error(0, "WSP: http lookup failed, oops."); /* XXX DAVI: also check for empty reply */ 
+        error(0, "WSP: HTTP lookup failed, oops."); 
         /* smart WSP error messaging?! */ 
         if (wsp_smart_errors) { 
             Octstr *referer_url; 
@@ -784,32 +819,7 @@ 
  
     } else { 
         /* received response by HTTP server */ 
-        WAPAddrTuple *addr_tuple; 
-        Octstr *ua, *server; 
- 
-        /* get client IP and User-Agent identifier */ 
-        addr_tuple = (orig_event->type == S_MethodInvoke_Ind) ? 
-            orig_event->u.S_MethodInvoke_Ind.addr_tuple :  
-            orig_event->u.S_Unit_MethodInvoke_Ind.addr_tuple; 
-        ua = http_header_value(request_headers, octstr_imm("User-Agent")); 
- 
-        /* get response content type and Server identifier */ 
-        http_header_get_content_type(headers, &content.type, &content.charset); 
-        server = http_header_value(headers, octstr_imm("Server")); 
- 
-        /* log the access */ 
-        /* XXX make this configurable in the future */ 
-        alog("%s %s <%s> (%s, charset='%s') %ld %d <%s> <%s>",  
-             octstr_get_cstr(addr_tuple->remote->address),  
-             octstr_get_cstr(method), octstr_get_cstr(url),  
-             octstr_get_cstr(content.type), octstr_get_cstr(content.charset), 
-             octstr_len(content.body), status, 
-             ua ? octstr_get_cstr(ua) : "", 
-             server ? octstr_get_cstr(server) : ""); 
- 
-        octstr_destroy(ua); 
-        octstr_destroy(server); 
- 
+  
 #ifdef ENABLE_COOKIES 
         if (session_id != -1) 
             /* DAVI if (get_cookies(url, headers, find_session_machine_by_id(session_id)) == -1) */
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.