replaced a few calls to snprintf() with qse_fmtuintmaxtombs().

changed the behavior when handling a query path without a slash
This commit is contained in:
hyung-hwan 2012-09-27 12:54:35 +00:00
parent 5b07370866
commit e0353fca2f
8 changed files with 74 additions and 78 deletions

View File

@ -21,6 +21,10 @@
#ifndef _QSE_LIB_CMN_SYSCALL_H_
#define _QSE_LIB_CMN_SYSCALL_H_
#if defined(_WIN32) || defined(__OS2__) || defined(__DOS__)
# error Do not include this file
#endif
/* This file defines unix/linux system calls */
#if defined(HAVE_SYS_TYPES_H)

View File

@ -1049,20 +1049,21 @@ qse_printf (QSE_T("TASK_MAIN_CGI_4\n"));
if (cgi->resflags & CGI_RES_CLIENT_CHUNK)
{
qse_size_t count, extra;
qse_mchar_t chunklen[7];
/* this function assumes that the chunk length does not
* exceed 4 hexadecimal digits. */
QSE_ASSERT (QSE_SIZEOF(cgi->buf) <= 0xFFFF);
#define CHLEN_RESERVE 6
qse_printf (QSE_T("READING CHUNKED MODE...\n"));
extra = (QSE_SIZEOF(chunklen) - 1) + 2;
extra = CHLEN_RESERVE + 2;
count = QSE_SIZEOF(cgi->buf) - cgi->buflen;
if (count > extra)
{
n = qse_pio_read (
&cgi->pio, QSE_PIO_OUT,
&cgi->buf[cgi->buflen + QSE_SIZEOF(chunklen) - 1],
&cgi->buf[cgi->buflen + CHLEN_RESERVE],
count - extra
);
if (n <= -1)
@ -1085,13 +1086,19 @@ qse_printf (QSE_T("TASK_MAIN_CGI_4\n"));
return 1;
}
/* set the chunk length */
/* TODO: chagne snprintf to qse_fmtuintmaxtombs() */
snprintf (chunklen, QSE_COUNTOF(chunklen),
QSE_MT("%-4lX\r\n"), (unsigned long)n);
QSE_MEMCPY (&cgi->buf[cgi->buflen],
chunklen, QSE_SIZEOF(chunklen) - 1);
cgi->buflen += QSE_SIZEOF(chunklen) - 1 + n;
/* set the chunk length. if the length string is less
* than 4 digits, the right side of the string is filled
* with space letters. for example, the chunk length line
* for the length 10 will be "A \r\n". */
cgi->buflen += qse_fmtuintmaxtombs (
&cgi->buf[cgi->buflen], CHLEN_RESERVE - 2 + 1,
n, 16 | QSE_FMTUINTMAXTOMBS_UPPERCASE | QSE_FMTUINTMAXTOMBS_FILLRIGHT,
-1, QSE_MT(' '), QSE_NULL
);
cgi->buf[cgi->buflen++] = QSE_MT('\r');
cgi->buf[cgi->buflen++] = QSE_MT('\n');
cgi->buflen += n; /* +n for the data read above */
/* set the trailing CR & LF for a chunk */
cgi->buf[cgi->buflen++] = QSE_MT('\r');

View File

@ -20,9 +20,20 @@
#include "httpd.h"
#include "../cmn/mem.h"
#include "../cmn/syscall.h"
#include <qse/cmn/str.h>
#include <qse/cmn/fmt.h>
#include <qse/cmn/path.h>
#if defined(_WIN32)
/* TODO: */
#elif defined(__OS2__)
/* TODO: */
#elif defined(__DOS__)
/* TODO: */
#else
# include "../cmn/syscall.h"
#endif
#include <qse/cmn/stdio.h> /* TODO: remove this */
typedef struct task_dir_t task_dir_t;
@ -106,13 +117,15 @@ static void fill_chunk_length (task_dseg_t* ctx)
int x;
/* right alignment with space padding on the left */
/* TODO: change snprintf to qse_fmtuintmaxtombs() */
x = snprintf (
x = qse_fmtuintmaxtombs (
ctx->buf, (SIZE_CHLEN + SIZE_CHLENCRLF) - 1,
QSE_MT("%*lX"), (int)(SIZE_CHLEN + SIZE_CHLENCRLF - 2),
(unsigned long)(ctx->chunklen - (SIZE_CHLEN + SIZE_CHLENCRLF)));
/* i don't check the error of snprintf because i've secured the
(ctx->chunklen - (SIZE_CHLEN + SIZE_CHLENCRLF)), /* value to convert */
16 | QSE_FMTUINTMAXTOMBS_UPPERCASE, /* uppercase hexadecimal letters */
-1, /* no particular precision - want space filled if less than 4 digits */
QSE_MT(' '), /* fill with space */
QSE_NULL
);
/* i don't check the buffer size error because i've secured the
* suffient space for the chunk length at the beginning of the buffer */
/* CHLENCRLF */
@ -380,7 +393,6 @@ static qse_httpd_task_t* entask_directory_segment (
task.fini = task_fini_dseg;
task.ctx = &data;
qse_printf (QSE_T("Debug: entasking directory segment (%d)\n"), client->handle.i);
return qse_httpd_entask (httpd, client, pred, &task, QSE_SIZEOF(data) + data.path.len + 1 + data.qpath.len + 1);
}

View File

@ -20,11 +20,21 @@
#include "httpd.h"
#include "../cmn/mem.h"
#include "../cmn/syscall.h"
#include <qse/cmn/str.h>
#include <qse/cmn/fmt.h>
#include <qse/cmn/path.h>
#include <qse/cmn/time.h>
#if defined(_WIN32)
/* TODO: */
#elif defined(__OS2__)
/* TODO: */
#elif defined(__DOS__)
/* TODO: */
#else
# include "../cmn/syscall.h"
#endif
#include <qse/cmn/stdio.h> /* TODO: remove this */
#define ETAG_LEN_MAX 127
@ -120,7 +130,6 @@ static qse_httpd_task_t* entask_file_segment (
task.fini = task_fini_fseg;
task.ctx = &data;
qse_printf (QSE_T("Debug: entasking file segment (%d)\n"), client->handle.i);
return qse_httpd_entask (httpd, client, pred, &task, QSE_SIZEOF(data));
}
@ -162,8 +171,6 @@ static QSE_INLINE int task_main_file (
/* TODO: if you should deal with files on a network-mounted drive,
setting a trigger or non-blocking I/O are needed. */
qse_printf (QSE_T("opening file %hs\n"), file->path);
httpd->errnum = QSE_HTTPD_ENOERR;
if (httpd->scb->file.stat (httpd, file->path.ptr, &st) <= -1)
{

View File

@ -18,10 +18,6 @@
License along with QSE. If not, see <htrd://www.gnu.org/licenses/>.
*/
#if defined(_WIN32) || defined(__DOS__) || defined(__OS2__)
/* UNSUPPORTED YET.. */
/* TODO: IMPLEMENT THIS */
#else
#include "httpd.h"
#include "../cmn/mem.h"
@ -447,10 +443,15 @@ qse_printf (QSE_T("NORMAL REPLY 222222222222222222222 NORMAL REPLY\n"));
if (proxy->resflags & PROXY_RES_CLIENT_CHUNK &&
qse_comparehttpversions (&res->version, &qse_http_v11) < 0)
{
qse_mchar_t vbuf[64];
snprintf (vbuf, QSE_COUNTOF(vbuf), QSE_MT("HTTP/%d.%d"),
(int)proxy->version.major, (int)proxy->version.minor);
if (qse_mbs_cat (proxy->res, vbuf) == (qse_size_t)-1)
qse_mchar_t major[32], minor[32];
qse_fmtuintmaxtombs (major, QSE_COUNTOF(major), proxy->version.major, 10, -1, QSE_MT('\0'), QSE_NULL);
qse_fmtuintmaxtombs (minor, QSE_COUNTOF(minor), proxy->version.minor, 10, -1, QSE_MT('\0'), QSE_NULL);
if (qse_mbs_cat (proxy->res, QSE_MT("HTTP/")) == (qse_size_t)-1 ||
qse_mbs_cat (proxy->res, major) == (qse_size_t)-1 ||
qse_mbs_cat (proxy->res, QSE_MT(".")) == (qse_size_t)-1 ||
qse_mbs_cat (proxy->res, minor) == (qse_size_t)-1)
{
proxy->httpd->errnum = QSE_HTTPD_ENOMEM;
return -1;
@ -1468,4 +1469,3 @@ qse_httpd_task_t* qse_httpd_entaskproxy (
);
}
#endif

View File

@ -1675,34 +1675,7 @@ qse_printf (QSE_T("Host not included....\n"));
#endif
#if 0
if (peek)
{
if (req->attr.expect &&
(req->version.major > 1 ||
(req->version.major == 1 && req->version.minor >= 1)) &&
!content_received)
{
/* TODO: check method.... */
/* "expect" in the header, version 1.1 or higher,
* and no content received yet */
if (qse_mbscasecmp(req->attr.expect, QSE_MT("100-continue")) != 0)
{
if (qse_httpd_entaskerror (
httpd, client, QSE_NULL, 417, req) == QSE_NULL) return -1;
if (qse_httpd_entaskdisconnect (
httpd, client, QSE_NULL) == QSE_NULL) return -1;
}
else
{
/* TODO: determine if to return 100-continue or other errors */
if (qse_httpd_entaskcontinue (
httpd, client, QSE_NULL, req) == QSE_NULL) return -1;
}
}
}
#endif
/* TODO: investigate if the proxy need to handle 100-continue */
if (peek)
{
@ -1893,12 +1866,15 @@ target->u.proxy.src.u.in4.port = 0;
return 0;
#endif
if (server_xtn->docroot.ptr)
if (server_xtn->docroot.ptr || qpath[0] != QSE_MT('/'))
{
const qse_mchar_t* ta[3];
ta[0] = server_xtn->docroot.ptr;
ta[1] = qpath;
ta[2] = QSE_NULL;
const qse_mchar_t* ta[4];
qse_size_t idx = 0;
if (server_xtn->docroot.ptr) ta[idx++] = server_xtn->docroot.ptr;
if (qpath[0] != QSE_MT('/')) ta[idx++] = QSE_MT("/");
ta[idx++] = qpath;
ta[idx++] = QSE_NULL;
xpath = qse_mbsadup (ta, httpd->mmgr);
if (xpath == QSE_NULL)
{
@ -1985,6 +1961,7 @@ return 0;
target->u.file.mime =
qse_mbsend (qpath, QSE_MT(".html"))? QSE_MT("text/html"):
qse_mbsend (qpath, QSE_MT(".txt"))? QSE_MT("text/plain"):
qse_mbsend (qpath, QSE_MT(".log"))? QSE_MT("text/plain"):
qse_mbsend (qpath, QSE_MT(".css"))? QSE_MT("text/css"):
qse_mbsend (qpath, QSE_MT(".xml"))? QSE_MT("text/xml"):
qse_mbsend (qpath, QSE_MT(".js"))? QSE_MT("application/javascript"):

View File

@ -19,19 +19,10 @@
*/
#include "httpd.h"
#include "../cmn/mem.h"
#include <qse/cmn/str.h>
#include <qse/cmn/fmt.h>
#include "../cmn/mem.h"
#if defined(_WIN32)
/* TODO */
#elif defined(__DOS__)
/* TODO */
#elif defined(__OS2__)
/* TODO */
#else
# include "../cmn/syscall.h"
#endif
#include <stdarg.h>
#include <qse/cmn/stdio.h> /* TODO: remove this */

View File

@ -20,8 +20,6 @@
#include "httpd.h"
#include "../cmn/mem.h"
#include "../cmn/syscall.h"
#include <qse/cmn/chr.h>
#include <qse/cmn/str.h>
#include <qse/cmn/mbwc.h>
@ -661,7 +659,7 @@ qse_printf (QSE_T("Error: failed to read from a client %d\n"), client->handle.i)
}
else if (m == 0)
{
qse_printf (QSE_T("Debug: connection closed %d - errno %d\n"), client->handle.i, errno);
qse_printf (QSE_T("Debug: connection closed %d\n"), client->handle.i);
/* reading from the client returned 0. this typically
* happens when the client closes the connection or
* shutdown the writing half of the socket. it's