From 624ffcb0067ce0645111e980570e8b5467edbca6 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Sat, 6 Sep 2014 04:08:31 +0000 Subject: [PATCH] included qparam to url for rewriting --- qse/cmd/http/httpd.c | 3 ++- qse/lib/http/httpd-std-urs.h | 33 +++++++++++++++++++++++++++------ qse/lib/http/httpd.h | 2 ++ 3 files changed, 31 insertions(+), 7 deletions(-) diff --git a/qse/cmd/http/httpd.c b/qse/cmd/http/httpd.c index d9dd7706..2f120517 100644 --- a/qse/cmd/http/httpd.c +++ b/qse/cmd/http/httpd.c @@ -2154,17 +2154,18 @@ static int prerewrite_url (qse_httpd_t* httpd, qse_httpd_client_t* client, qse_h httpd_xtn = qse_httpd_getxtnstd (httpd); printf ("PREREWRITING.....................\n"); +/* if (qse_htre_getqmethodtype(req) == QSE_HTTP_CONNECT) { *url = QSE_NULL; return 0; } +*/ /* TODO: override prerewrite url */ return httpd_xtn->org_urs_prerewrite (httpd, client, req, host, url); } - static void logact_httpd (qse_httpd_t* httpd, const qse_httpd_act_t* act) { /*httpd_xtn_t* httpd_xtn;*/ diff --git a/qse/lib/http/httpd-std-urs.h b/qse/lib/http/httpd-std-urs.h index 14e15419..38984e30 100644 --- a/qse/lib/http/httpd-std-urs.h +++ b/qse/lib/http/httpd-std-urs.h @@ -487,17 +487,31 @@ static int urs_prerewrite (qse_httpd_t* httpd, qse_httpd_client_t* client, qse_h const qse_mchar_t* qpath; int mtype; const qse_mchar_t* mname; + const qse_mchar_t* quest; + const qse_mchar_t* qparam; + const qse_mchar_t* proto; const qse_mchar_t* host_ptr = QSE_NULL; - qse_mchar_t cliaddrbuf[128]; + qse_mchar_t cliaddrbuf[MAX_NWAD_TEXT_SIZE]; qse_size_t total_len; qse_mchar_t* url_to_rewrite; qpath = qse_htre_getqpath(req); + qparam = qse_htre_getqparam(req); mtype = qse_htre_getqmethodtype(req); mname = qse_htre_getqmethodname(req); total_len = qse_mbslen(qpath) + qse_mbslen(mname); + if (qparam) + { + quest = QSE_MT("?"); + total_len = total_len + 1 + qse_mbslen(qparam); + } + else + { + qparam = QSE_MT(""); + quest = QSE_MT(""); + } if (host) { @@ -519,17 +533,24 @@ static int urs_prerewrite (qse_httpd_t* httpd, qse_httpd_client_t* client, qse_h } total_len += qse_nwadtombs (&client->remote_addr, cliaddrbuf, QSE_COUNTOF(cliaddrbuf), QSE_NWADTOMBS_ADDR); - total_len += 128; /* extra space */ url_to_rewrite = qse_httpd_allocmem (httpd, total_len); if (url_to_rewrite == QSE_NULL) return -1; - /* URL client-ip/client-fqdn ident method */ - if (mtype != QSE_HTTP_CONNECT && host_ptr) - qse_mbsxfmt (url_to_rewrite, total_len, QSE_MT("http://%s%s %s/- - %s"), host_ptr, qpath, cliaddrbuf, mname); + + if (mtype == QSE_HTTP_CONNECT || !host_ptr) + { + host_ptr = QSE_MT(""); + proto = QSE_MT(""); + } else - qse_mbsxfmt (url_to_rewrite, total_len, QSE_MT("%s %s/- - %s"), qpath, cliaddrbuf, mname); + { + proto = QSE_MT("http://"); + } + + /* URL client-ip/client-fqdn ident method */ + qse_mbsxfmt (url_to_rewrite, total_len, QSE_MT("%s%s%s%s%s %s/- - %s"), proto, host_ptr, qpath, quest, qparam, cliaddrbuf, mname); *url = url_to_rewrite; return 1; diff --git a/qse/lib/http/httpd.h b/qse/lib/http/httpd.h index 75700f9e..9e25f093 100644 --- a/qse/lib/http/httpd.h +++ b/qse/lib/http/httpd.h @@ -110,6 +110,8 @@ struct qse_httpd_status_reloc_t #define MAX_SEND_SIZE 4096 #define MAX_RECV_SIZE 4096 +#define MAX_NWAD_TEXT_SIZE 96 + #ifdef __cplusplus extern "C" { #endif