From e8cef98c87616c26db83fbd5784e84b33ff0bdfb Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Tue, 2 Sep 2014 15:24:30 +0000 Subject: [PATCH] touched up some code --- qse/cmd/http/httpd.c | 1 + qse/lib/http/httpd-file.c | 2 +- qse/lib/http/httpd-proxy.c | 11 +++++ qse/lib/http/httpd-std.c | 99 ++++++++++++++++++-------------------- 4 files changed, 60 insertions(+), 53 deletions(-) diff --git a/qse/cmd/http/httpd.c b/qse/cmd/http/httpd.c index 173816e4..9efcb8bc 100644 --- a/qse/cmd/http/httpd.c +++ b/qse/cmd/http/httpd.c @@ -2139,6 +2139,7 @@ static int prerewrite_url (qse_httpd_t* httpd, qse_httpd_client_t* client, qse_h httpd_xtn = qse_httpd_getxtnstd (httpd); +printf ("PREREWRITING.....................\n"); /* TODO: override prerewrite url */ return httpd_xtn->org_urs_prerewrite (httpd, client, req, host, url); } diff --git a/qse/lib/http/httpd-file.c b/qse/lib/http/httpd-file.c index d8ff6af3..33c644fd 100644 --- a/qse/lib/http/httpd-file.c +++ b/qse/lib/http/httpd-file.c @@ -207,7 +207,7 @@ static QSE_INLINE int task_main_getfile ( httpd, client, x, http_errnum, file->method, &file->version, file->keepalive); goto no_file_send; - } + } fileopen = 1; if (file->u.get.range.type != QSE_HTTP_RANGE_NONE) diff --git a/qse/lib/http/httpd-proxy.c b/qse/lib/http/httpd-proxy.c index c4973b04..66faf71f 100644 --- a/qse/lib/http/httpd-proxy.c +++ b/qse/lib/http/httpd-proxy.c @@ -1041,6 +1041,17 @@ printf (">>>>>>>>>>>>>>>>>>>>>>>> [%s] <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n", proxy qse_mbs_cat (proxy->reqfwdbuf, qse_htre_getqparam(arg->req)) == (qse_size_t)-1) goto nomem_oops; } +#if 0 +{ +/* KT FILTERING WORKAROUND POC. KT seems to check the Host: the first packet + * only.I add 1500 byte space octets between the URL and the HTTP version string. + * the header is likely to be placed in the second packet. it seems to work. */ +qse_mchar_t spc[1500]; +QSE_MEMSET (spc, QSE_MT(' '), QSE_COUNTOF(spc)); +qse_mbs_ncat (proxy->reqfwdbuf, spc, QSE_COUNTOF(spc)); +} +#endif + if (qse_mbs_cat (proxy->reqfwdbuf, QSE_MT(" ")) == (qse_size_t)-1 || qse_mbs_cat (proxy->reqfwdbuf, qse_htre_getverstr(arg->req)) == (qse_size_t)-1 || qse_mbs_cat (proxy->reqfwdbuf, QSE_MT("\r\n")) == (qse_size_t)-1 || diff --git a/qse/lib/http/httpd-std.c b/qse/lib/http/httpd-std.c index d7aa964d..0f603747 100644 --- a/qse/lib/http/httpd-std.c +++ b/qse/lib/http/httpd-std.c @@ -375,7 +375,7 @@ static qse_httpd_errnum_t direrr_to_errnum (qse_dir_errnum_t e) /* ------------------------------------------------------------------- */ static QSE_INLINE qse_ssize_t __send_file ( - qse_httpd_t* httpd, int out_fd, qse_ubi_t in_fd, + qse_httpd_t* httpd, qse_sck_hnd_t out_fd, qse_ubi_t in_fd, qse_foff_t* offset, qse_size_t count) { /* TODO: os2 warp 4.5 has send_file. support it??? load it dynamically??? */ @@ -387,12 +387,14 @@ static QSE_INLINE qse_ssize_t __send_file ( #elif defined(HAVE_SENDFILE) && defined(HAVE_SENDFILE64) qse_ssize_t ret; - qse_ubi_t infd = qse_fio_gethandleasubi (in_fd.ptr); + qse_fio_hnd_t fh; + + fh = qse_fio_gethandle (in_fd.ptr); #if !defined(_LP64) && (QSE_SIZEOF_VOID_P<8) && defined(HAVE_SENDFILE64) - ret = sendfile64 (out_fd, infd.i, offset, count); + ret = sendfile64 (out_fd, fh, offset, count); #else - ret = sendfile (out_fd, infd.i, offset, count); + ret = sendfile (out_fd, fh, offset, count); #endif if (ret <= -1) qse_httpd_seterrnum (httpd, SKERR_TO_ERRNUM()); return ret; @@ -400,20 +402,27 @@ static QSE_INLINE qse_ssize_t __send_file ( #elif defined(HAVE_SENDFILE) qse_ssize_t ret; - qse_ubi_t infd = qse_fio_gethandleasubi (in_fd.ptr); - ret = sendfile (out_fd, infd.i, offset, count); + qse_fio_hnd_t fh; + + fh = qse_fio_gethandle (in_fd.ptr); + ret = sendfile (out_fd, fh, offset, count); if (ret <= -1) qse_httpd_seterrnum (httpd, SKERR_TO_ERRNUM()); return ret; #elif defined(HAVE_SENDFILE64) + qse_ssize_t ret; - qse_ubi_t infd = qse_fio_gethandleasubi (in_fd.ptr); - ret = sendfile64 (out_fd, in_fd.i, offset, count); + qse_fio_hnd_t fh; + + fh = qse_fio_gethandle (in_fd.ptr); + ret = sendfile64 (out_fd, fh, offset, count); if (ret <= -1) qse_httpd_seterrnum (httpd, SKERR_TO_ERRNUM()); return ret; #elif defined(HAVE_SENDFILEV) || defined(HAVE_SENDFILEV64) + /* solaris */ + #if !defined(_LP64) && (QSE_SIZEOF_VOID_P<8) && defined(HAVE_SENDFILE64) struct sendfilevec64 vec; #else @@ -458,7 +467,7 @@ on failure xfer != ret. if (offset && (foff = qse_fio_seek (in_fd.ptr, *offset, QSE_FIO_BEGIN)) != *offset) { - if (foff == (qse_foff_t)-1) + if (foff == (qse_foff_t)-1) qse_httpd_seterrnum (httpd, fioerr_to_errnum(qse_fio_geterrnum(in_fd.ptr))); else qse_httpd_seterrnum (httpd, QSE_HTTPD_ESYSERR); @@ -478,7 +487,7 @@ on failure xfer != ret. } else if (ret <= -1) { - qse_httpd_seterrnum (httpd, fioerr_to_errnum(qse_fio_geterrnum(in_fd.ptr))); + qse_httpd_seterrnum (httpd, fioerr_to_errnum(qse_fio_geterrnum(in_fd.ptr))); } return ret; @@ -500,7 +509,7 @@ static QSE_INLINE qse_ssize_t __send_file_ssl ( if (offset && (foff = qse_fio_seek (in_fd.ptr, *offset, QSE_FIO_BEGIN)) != *offset) { - if (foff == (qse_foff_t)-1) + if (foff == (qse_foff_t)-1) qse_httpd_seterrnum (httpd, fioerr_to_errnum(qse_fio_geterrnum(in_fd.ptr))); else qse_httpd_seterrnum (httpd, QSE_HTTPD_ESYSERR); @@ -1547,29 +1556,32 @@ static int file_purge (qse_httpd_t* httpd, const qse_mchar_t* path) #endif } +static qse_fio_t* __open_file (qse_httpd_t* httpd, const qse_mchar_t* path, int fio_flags, int fio_mode) +{ + qse_fio_t* fio; + + fio = qse_httpd_allocmem (httpd, QSE_SIZEOF(*fio)); + if (fio == QSE_NULL) return QSE_NULL; + + if (qse_fio_init (fio, httpd->mmgr, (const qse_char_t*)path, fio_flags, fio_mode) <= -1) + { + qse_httpd_seterrnum (httpd, fioerr_to_errnum(qse_fio_geterrnum(fio))); + qse_httpd_freemem (httpd, fio); + return QSE_NULL; + } + + return fio; +} + static int file_ropen ( qse_httpd_t* httpd, const qse_mchar_t* path, qse_ubi_t* handle) { qse_fio_t* fio; - fio = QSE_MMGR_ALLOC (httpd->mmgr, QSE_SIZEOF(*fio)); - if (fio == QSE_NULL) - { - qse_httpd_seterrnum (httpd, QSE_HTTPD_ENOMEM); - return -1; - } - - if (qse_fio_init ( - fio, httpd->mmgr, (const qse_char_t*)path, - QSE_FIO_READ | QSE_FIO_MBSPATH, 0) <= -1) - { - qse_httpd_seterrnum (httpd, fioerr_to_errnum(qse_fio_geterrnum(fio))); - QSE_MMGR_FREE (httpd->mmgr, fio); - return -1; - } + fio = __open_file (httpd, path, QSE_FIO_READ | QSE_FIO_MBSPATH, 0); + if (fio == QSE_NULL) return -1; handle->ptr = fio; - if (httpd->opt.trait & QSE_HTTPD_LOGACT) { qse_httpd_act_t msg; @@ -1579,8 +1591,8 @@ static int file_ropen ( qse_mbsxcpy (&msg.u.mdbgmsg[pos], QSE_COUNTOF(msg.u.mdbgmsg) - pos, path); httpd->opt.rcb.logact (httpd, &msg); } - return 0; + return 0; } static int file_wopen ( @@ -1589,25 +1601,10 @@ static int file_wopen ( { qse_fio_t* fio; - fio = QSE_MMGR_ALLOC (httpd->mmgr, QSE_SIZEOF(*fio)); - if (fio == QSE_NULL) - { - qse_httpd_seterrnum (httpd, QSE_HTTPD_ENOMEM); - return -1; - } - - if (qse_fio_init ( - fio, httpd->mmgr, (const qse_char_t*)path, - QSE_FIO_WRITE | QSE_FIO_CREATE | - QSE_FIO_TRUNCATE | QSE_FIO_MBSPATH, 0644) <= -1) - { - qse_httpd_seterrnum (httpd, fioerr_to_errnum(qse_fio_geterrnum(fio))); - QSE_MMGR_FREE (httpd->mmgr, fio); - return -1; - } + fio = __open_file (httpd, path, QSE_FIO_WRITE | QSE_FIO_CREATE | QSE_FIO_TRUNCATE | QSE_FIO_MBSPATH, 0644); + if (fio == QSE_NULL) return -1; handle->ptr = fio; - if (httpd->opt.trait & QSE_HTTPD_LOGACT) { qse_httpd_act_t msg; @@ -1624,26 +1621,24 @@ static int file_wopen ( static void file_close (qse_httpd_t* httpd, qse_ubi_t handle) { qse_fio_fini (handle.ptr); - QSE_MMGR_FREE (httpd->mmgr, handle.ptr); + qse_httpd_freemem (httpd, handle.ptr); } static qse_ssize_t file_read ( - qse_httpd_t* httpd, qse_ubi_t handle, - qse_mchar_t* buf, qse_size_t len) + qse_httpd_t* httpd, qse_ubi_t handle, qse_mchar_t* buf, qse_size_t len) { qse_ssize_t n; n = qse_fio_read (handle.ptr, buf, len); - if (n <= -1) qse_httpd_seterrnum (httpd, fioerr_to_errnum(qse_fio_geterrnum(handle.ptr))); + if (n <= -1) qse_httpd_seterrnum (httpd, fioerr_to_errnum(qse_fio_geterrnum(handle.ptr))); return n; } static qse_ssize_t file_write ( - qse_httpd_t* httpd, qse_ubi_t handle, - const qse_mchar_t* buf, qse_size_t len) + qse_httpd_t* httpd, qse_ubi_t handle, const qse_mchar_t* buf, qse_size_t len) { qse_ssize_t n; n = qse_fio_write (handle.ptr, buf, len); - if (n <= -1) qse_httpd_seterrnum (httpd, fioerr_to_errnum(qse_fio_geterrnum(handle.ptr))); + if (n <= -1) qse_httpd_seterrnum (httpd, fioerr_to_errnum(qse_fio_geterrnum(handle.ptr))); return n; }