fixed fio.c for not handling QSE_FIO_MBSPATH perperly on dos.
fixed httpd further for dos
This commit is contained in:
parent
2218670769
commit
d207120933
@ -30,6 +30,7 @@
|
||||
#elif defined(__DOS__)
|
||||
# include <dos.h>
|
||||
# include <tcp.h> /* watt-32 */
|
||||
# include <conio.h>
|
||||
#else
|
||||
# include <unistd.h>
|
||||
# include <errno.h>
|
||||
@ -2427,20 +2428,26 @@ static void impede_httpd (qse_httpd_t* httpd)
|
||||
/* reconfigure the server when the server is impeded in sig_reconf(). */
|
||||
|
||||
httpd_xtn = qse_httpd_getxtnstd (httpd);
|
||||
|
||||
if (open_config_file (httpd) >= 0)
|
||||
if (httpd_xtn->impede_code == 9999)
|
||||
{
|
||||
qse_httpd_server_t* server;
|
||||
|
||||
server = qse_httpd_getfirstserver (httpd);
|
||||
while (server)
|
||||
qse_httpd_stop (httpd);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (open_config_file (httpd) >= 0)
|
||||
{
|
||||
if (server->dope.flags & QSE_HTTPD_SERVER_ACTIVE)
|
||||
reconf_server (httpd, server);
|
||||
qse_httpd_server_t* server;
|
||||
|
||||
server = qse_httpd_getnextserver (httpd, server);
|
||||
server = qse_httpd_getfirstserver (httpd);
|
||||
while (server)
|
||||
{
|
||||
if (server->dope.flags & QSE_HTTPD_SERVER_ACTIVE)
|
||||
reconf_server (httpd, server);
|
||||
|
||||
server = qse_httpd_getnextserver (httpd, server);
|
||||
}
|
||||
close_config_file (httpd);
|
||||
}
|
||||
close_config_file (httpd);
|
||||
}
|
||||
|
||||
/* chain-call the orignal impedence function */
|
||||
@ -2609,7 +2616,7 @@ static int handle_args (int argc, qse_char_t* argv[])
|
||||
{
|
||||
print_version ();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@ -2708,6 +2715,28 @@ oops:
|
||||
return -1;
|
||||
}
|
||||
|
||||
#if defined(__DOS__)
|
||||
static void interrupt (*old_keyboard_handler)() = QSE_NULL;
|
||||
static int impeded_for_keyboard = 0;
|
||||
static void interrupt new_keyboard_handler (void)
|
||||
{
|
||||
if (!impeded_for_keyboard && g_httpd)
|
||||
{
|
||||
httpd_xtn_t* httpd_xtn;
|
||||
int c;
|
||||
|
||||
/* TODO: read a keystroke... etc */
|
||||
httpd_xtn = qse_httpd_getxtnstd (g_httpd);
|
||||
httpd_xtn->impede_code = 9999;
|
||||
qse_httpd_impede (g_httpd);
|
||||
impeded_for_keyboard = 1;
|
||||
}
|
||||
|
||||
if (old_keyboard_handler) old_keyboard_handler ();
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
int qse_main (int argc, qse_achar_t* argv[])
|
||||
{
|
||||
int ret;
|
||||
@ -2746,6 +2775,11 @@ int qse_main (int argc, qse_achar_t* argv[])
|
||||
|
||||
qse_openstdsios ();
|
||||
|
||||
#if defined(__DOS__)
|
||||
old_keyboard_handler = _dos_getvect (0x09);
|
||||
_dos_setvect (0x09, new_keyboard_handler);
|
||||
#endif
|
||||
|
||||
#if defined(_WIN32)
|
||||
if (WSAStartup (MAKEWORD(2,0), &wsadata) != 0)
|
||||
{
|
||||
@ -2754,6 +2788,8 @@ int qse_main (int argc, qse_achar_t* argv[])
|
||||
goto oops;
|
||||
}
|
||||
#elif defined(__DOS__)
|
||||
|
||||
|
||||
_watt_do_exit = 0; /* prevent sock_init from exiting upon failure */
|
||||
if (sock_init () != 0)
|
||||
{
|
||||
@ -2786,6 +2822,10 @@ int qse_main (int argc, qse_achar_t* argv[])
|
||||
#endif
|
||||
|
||||
oops:
|
||||
#if defined(__DOS__)
|
||||
if (old_keyboard_handler)
|
||||
_dos_setvect (0x09, old_keyboard_handler);
|
||||
#endif
|
||||
qse_closestdsios ();
|
||||
return ret;
|
||||
}
|
||||
|
@ -582,23 +582,32 @@ int qse_fio_init (
|
||||
qse_size_t wl, ml;
|
||||
int px;
|
||||
|
||||
path_mb = path_mb_buf;
|
||||
ml = QSE_COUNTOF(path_mb_buf);
|
||||
px = qse_wcstombs (path, &wl, path_mb, &ml);
|
||||
if (px == -2)
|
||||
if (flags & QSE_FIO_MBSPATH)
|
||||
{
|
||||
path_mb = qse_wcstombsdup (path, QSE_NULL, mmgr);
|
||||
if (path_mb == QSE_NULL)
|
||||
path_mb = (qse_mchar_t*)path;
|
||||
}
|
||||
else
|
||||
{
|
||||
path_mb = path_mb_buf;
|
||||
ml = QSE_COUNTOF(path_mb_buf);
|
||||
px = qse_wcstombs (path, &wl, path_mb, &ml);
|
||||
if (px == -2)
|
||||
{
|
||||
fio->errnum = QSE_FIO_ENOMEM;
|
||||
/* static buffer size not enough.
|
||||
* switch to dynamic allocation */
|
||||
path_mb = qse_wcstombsdup (path, QSE_NULL, mmgr);
|
||||
if (path_mb == QSE_NULL)
|
||||
{
|
||||
fio->errnum = QSE_FIO_ENOMEM;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else if (px <= -1)
|
||||
{
|
||||
fio->errnum = QSE_FIO_EINVAL;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else if (px <= -1)
|
||||
{
|
||||
fio->errnum = QSE_FIO_EINVAL;
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (flags & QSE_FIO_APPEND)
|
||||
|
@ -201,6 +201,7 @@ static QSE_INLINE int task_main_getfile (
|
||||
if (httpd->opt.scb.file.ropen (httpd, file->path.ptr, &handle) <= -1)
|
||||
{
|
||||
int http_errnum;
|
||||
printf ("ropen failure...\n");
|
||||
http_errnum = (httpd->errnum == QSE_HTTPD_ENOENT)? 404:
|
||||
(httpd->errnum == QSE_HTTPD_EACCES)? 403: 500;
|
||||
x = qse_httpd_entask_error (
|
||||
@ -210,6 +211,7 @@ static QSE_INLINE int task_main_getfile (
|
||||
}
|
||||
fileopen = 1;
|
||||
|
||||
printf ("ropen ok...\n");
|
||||
if (file->u.get.range.type != QSE_HTTP_RANGE_NONE)
|
||||
{
|
||||
qse_mchar_t tmp[4][64];
|
||||
|
@ -287,10 +287,6 @@ int init_dns_query (qse_uint8_t* buf, qse_size_t len, const qse_mchar_t* name, i
|
||||
|
||||
static int dns_open (qse_httpd_t* httpd, qse_httpd_dns_t* dns)
|
||||
{
|
||||
#if defined(__DOS__)
|
||||
qse_httpd_seterrnum (httpd, QSE_HTTPD_ENOIMPL);
|
||||
return -1;
|
||||
#else
|
||||
qse_nwad_t nwad;
|
||||
dns_ctx_t* dc;
|
||||
httpd_xtn_t* httpd_xtn;
|
||||
@ -368,9 +364,9 @@ static int dns_open (qse_httpd_t* httpd, qse_httpd_dns_t* dns)
|
||||
httpd->opt.rcb.logact (httpd, &msg);
|
||||
}
|
||||
|
||||
dns->handle[0] = open_client_socket (httpd, AF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
||||
dns->handle[0] = open_client_socket (httpd, AF_INET, SOCK_DGRAM, 0);
|
||||
#if defined(AF_INET6)
|
||||
dns->handle[1] = open_client_socket (httpd, AF_INET6, SOCK_DGRAM, IPPROTO_UDP);
|
||||
dns->handle[1] = open_client_socket (httpd, AF_INET6, SOCK_DGRAM, 0);
|
||||
#endif
|
||||
#if defined(AF_UNIX)
|
||||
dns->handle[2] = open_client_socket (httpd, AF_UNIX, SOCK_DGRAM, 0);
|
||||
@ -401,7 +397,6 @@ static int dns_open (qse_httpd_t* httpd, qse_httpd_dns_t* dns)
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
if (!qse_isvalidsckhnd(dns->handle[0]) &&
|
||||
!qse_isvalidsckhnd(dns->handle[1]) &&
|
||||
!qse_isvalidsckhnd(dns->handle[2]))
|
||||
@ -463,8 +458,6 @@ oops:
|
||||
}
|
||||
if (dc) qse_httpd_freemem (httpd, dc);
|
||||
return -1;
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
static void dns_remove_tmr_tmout (qse_httpd_t* httpd, dns_req_t* req)
|
||||
|
@ -92,14 +92,10 @@ struct urs_req_t
|
||||
|
||||
static int urs_open (qse_httpd_t* httpd, qse_httpd_urs_t* urs)
|
||||
{
|
||||
#if defined(__DOS__)
|
||||
qse_httpd_seterrnum (httpd, QSE_HTTPD_ENOIMPL);
|
||||
return -1;
|
||||
#else
|
||||
qse_nwad_t nwad;
|
||||
urs_ctx_t* dc;
|
||||
httpd_xtn_t* httpd_xtn;
|
||||
int type, proto = IPPROTO_UDP; /*IPPROTO_SCTP*/
|
||||
int type, proto = 0; /*IPPROTO_UDP;*/ /*IPPROTO_SCTP*/
|
||||
|
||||
httpd_xtn = qse_httpd_getxtn (httpd);
|
||||
|
||||
@ -233,8 +229,6 @@ oops:
|
||||
}
|
||||
if (dc) qse_httpd_freemem (httpd, dc);
|
||||
return -1;
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
static void urs_remove_tmr_tmout (qse_httpd_t* httpd, urs_req_t* req)
|
||||
|
@ -73,11 +73,15 @@
|
||||
|
||||
#elif defined(__DOS__)
|
||||
|
||||
# include <io.h>
|
||||
# include <direct.h>
|
||||
# include <errno.h>
|
||||
# include <tcp.h> /* watt-32 */
|
||||
# include <sys/ioctl.h> /* watt-32 */
|
||||
# include <sys/stat.h>
|
||||
|
||||
# define select select_s /* TODO: is this correct? */
|
||||
# define memset QSE_MEMSET
|
||||
# define select select_s
|
||||
# undef AF_UNIX
|
||||
|
||||
#else
|
||||
@ -416,12 +420,6 @@ static QSE_INLINE qse_ssize_t __send_file (
|
||||
{
|
||||
/* TODO: os2 warp 4.5 has send_file. support it??? load it dynamically??? */
|
||||
|
||||
/*
|
||||
#if defined(__DOS__)
|
||||
qse_httpd_seterrnum (httpd, QSE_HTTPD_ENOIMPL);
|
||||
return -1;
|
||||
|
||||
#el*/
|
||||
#if defined(HAVE_SENDFILE) && defined(HAVE_SENDFILE64)
|
||||
|
||||
qse_ssize_t ret;
|
||||
@ -903,10 +901,6 @@ oops:
|
||||
|
||||
static int server_open (qse_httpd_t* httpd, qse_httpd_server_t* server)
|
||||
{
|
||||
/*#if defined(__DOS__)
|
||||
qse_httpd_seterrnum (httpd, QSE_HTTPD_ENOIMPL);
|
||||
return -1;
|
||||
#else*/
|
||||
qse_sck_hnd_t fd = QSE_INVALID_SCKHND, flag;
|
||||
qse_skad_t addr;
|
||||
int addrsize;
|
||||
@ -1030,7 +1024,6 @@ bind_ok:
|
||||
oops:
|
||||
if (qse_isvalidsckhnd(fd)) qse_closesckhnd (fd);
|
||||
return -1;
|
||||
/*#endif*/
|
||||
}
|
||||
|
||||
static void server_close (qse_httpd_t* httpd, qse_httpd_server_t* server)
|
||||
@ -1041,11 +1034,6 @@ static void server_close (qse_httpd_t* httpd, qse_httpd_server_t* server)
|
||||
static int server_accept (
|
||||
qse_httpd_t* httpd, qse_httpd_server_t* server, qse_httpd_client_t* client)
|
||||
{
|
||||
/*#if defined(__DOS__)
|
||||
qse_httpd_seterrnum (httpd, QSE_HTTPD_ENOIMPL);
|
||||
return -1;
|
||||
|
||||
#else*/
|
||||
qse_skad_t addr;
|
||||
qse_sck_len_t addrlen;
|
||||
qse_sck_hnd_t fd = QSE_INVALID_SCKHND;
|
||||
@ -1124,19 +1112,12 @@ printf ("ERROR: too many client?\n");
|
||||
oops:
|
||||
if (qse_isvalidsckhnd(fd)) qse_closesckhnd (fd);
|
||||
return -1;
|
||||
/*#endif*/
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------- */
|
||||
|
||||
static int peer_open (qse_httpd_t* httpd, qse_httpd_peer_t* peer)
|
||||
{
|
||||
/*#if defined(__DOS__)
|
||||
qse_httpd_seterrnum (httpd, QSE_HTTPD_ENOIMPL);
|
||||
return -1;
|
||||
|
||||
#else*/
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
httpd_xtn_t* xtn;
|
||||
@ -1304,7 +1285,6 @@ oops:
|
||||
return -1;
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
/*#endif*/
|
||||
}
|
||||
|
||||
static void peer_close (qse_httpd_t* httpd, qse_httpd_peer_t* peer)
|
||||
@ -1464,14 +1444,9 @@ static qse_ssize_t peer_recv (
|
||||
}
|
||||
else
|
||||
{
|
||||
/*#if defined(__DOS__)
|
||||
qse_httpd_seterrnum (httpd, QSE_HTTPD_ENOIMPL);
|
||||
return -1;
|
||||
#else*/
|
||||
qse_ssize_t ret = recv (peer->handle, buf, bufsize, 0);
|
||||
if (ret <= -1) qse_httpd_seterrnum (httpd, SKERR_TO_ERRNUM());
|
||||
return ret;
|
||||
/*#endif*/
|
||||
}
|
||||
}
|
||||
|
||||
@ -1499,14 +1474,9 @@ static qse_ssize_t peer_send (
|
||||
}
|
||||
else
|
||||
{
|
||||
/*#if defined(__DOS__)
|
||||
qse_httpd_seterrnum (httpd, QSE_HTTPD_ENOIMPL);
|
||||
return -1;
|
||||
#else*/
|
||||
qse_ssize_t ret = send (peer->handle, buf, bufsize, 0);
|
||||
if (ret <= -1) qse_httpd_seterrnum (httpd, SKERR_TO_ERRNUM());
|
||||
return ret;
|
||||
/*#endif*/
|
||||
}
|
||||
}
|
||||
|
||||
@ -1608,11 +1578,6 @@ static int mux_readable (qse_httpd_t* httpd, qse_httpd_hnd_t handle, const qse_n
|
||||
tv = tmout? QSE_SECNSEC_TO_MSEC (tmout->sec, tmout->nsec): -1;
|
||||
return os2_select (&handle, 1, 0, 0, tv);
|
||||
|
||||
/*#elif defined(__DOS__)
|
||||
|
||||
qse_httpd_seterrnum (httpd, QSE_HTTPD_ENOIMPL);
|
||||
return -1;*/
|
||||
|
||||
#else
|
||||
fd_set r;
|
||||
struct timeval tv, * tvp;
|
||||
@ -1639,12 +1604,6 @@ static int mux_writable (qse_httpd_t* httpd, qse_httpd_hnd_t handle, const qse_n
|
||||
tv = tmout? QSE_SECNSEC_TO_MSEC (tmout->sec, tmout->nsec): -1;
|
||||
return os2_select (&handle, 0, 1, 0, tv);
|
||||
|
||||
/*#elif defined(__DOS__)
|
||||
|
||||
qse_httpd_seterrnum (httpd, QSE_HTTPD_ENOIMPL);
|
||||
return -1;
|
||||
*/
|
||||
|
||||
#else
|
||||
fd_set w;
|
||||
struct timeval tv, * tvp;
|
||||
@ -1764,9 +1723,32 @@ static int stat_file (
|
||||
return 0;
|
||||
|
||||
#elif defined(__DOS__)
|
||||
/* TODO: */
|
||||
qse_httpd_seterrnum (httpd, QSE_HTTPD_ENOIMPL);
|
||||
return -1;
|
||||
|
||||
struct stat st;
|
||||
|
||||
if (stat (path, &st) <= -1)
|
||||
{
|
||||
qse_httpd_seterrnum (httpd, syserr_to_errnum(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((filter == STAT_REG && !S_ISREG(st.st_mode)) ||
|
||||
(filter == STAT_DIR && !S_ISDIR(st.st_mode)))
|
||||
{
|
||||
qse_httpd_seterrnum (httpd, QSE_HTTPD_EACCES);
|
||||
return -1;
|
||||
}
|
||||
|
||||
QSE_MEMSET (hst, 0, QSE_SIZEOF(*hst));
|
||||
|
||||
hst->isdir = S_ISDIR(st.st_mode);
|
||||
hst->dev = st.st_dev;
|
||||
hst->ino = st.st_ino;
|
||||
hst->size = st.st_size;
|
||||
hst->mtime.sec = st.st_mtime;
|
||||
hst->mtime.nsec = 0;
|
||||
|
||||
return 0;
|
||||
#else
|
||||
qse_stat_t st;
|
||||
|
||||
@ -1841,9 +1823,13 @@ static int file_purge (qse_httpd_t* httpd, const qse_mchar_t* path)
|
||||
return 0;
|
||||
|
||||
#elif defined(__DOS__)
|
||||
/* TODO: */
|
||||
qse_httpd_seterrnum (httpd, QSE_HTTPD_ENOIMPL);
|
||||
return -1;
|
||||
|
||||
if (unlink (path) <= -1)
|
||||
{
|
||||
qse_httpd_seterrnum (httpd, syserr_to_errnum(errno));
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
|
||||
#else
|
||||
|
||||
@ -1980,8 +1966,15 @@ static int dir_make (qse_httpd_t* httpd, const qse_mchar_t* path)
|
||||
return 0;
|
||||
|
||||
#elif defined(__DOS__)
|
||||
qse_httpd_seterrnum (httpd, QSE_HTTPD_ENOIMPL);
|
||||
return -1;
|
||||
|
||||
if (mkdir (path) <= -1)
|
||||
{
|
||||
qse_httpd_seterrnum (httpd, syserr_to_errnum(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
#else
|
||||
|
||||
if (QSE_MKDIR (path, 0755) <= -1)
|
||||
@ -2015,8 +2008,14 @@ static int dir_purge (qse_httpd_t* httpd, const qse_mchar_t* path)
|
||||
return 0;
|
||||
|
||||
#elif defined(__DOS__)
|
||||
qse_httpd_seterrnum (httpd, QSE_HTTPD_ENOIMPL);
|
||||
return -1;
|
||||
|
||||
if (rmdir (path) <= -1)
|
||||
{
|
||||
qse_httpd_seterrnum (httpd, syserr_to_errnum(errno));
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
|
||||
#else
|
||||
|
||||
if (QSE_RMDIR (path) <= -1)
|
||||
@ -2175,15 +2174,10 @@ static qse_ssize_t client_recv (
|
||||
}
|
||||
else
|
||||
{
|
||||
/*#if defined(__DOS__)
|
||||
qse_httpd_seterrnum (httpd, QSE_HTTPD_ENOIMPL);
|
||||
return -1;
|
||||
#else*/
|
||||
qse_ssize_t ret;
|
||||
ret = recv (client->handle, buf, bufsize, 0);
|
||||
if (ret <= -1) qse_httpd_seterrnum (httpd, SKERR_TO_ERRNUM());
|
||||
return ret;
|
||||
/*#endif*/
|
||||
}
|
||||
}
|
||||
|
||||
@ -2211,14 +2205,9 @@ static qse_ssize_t client_send (
|
||||
}
|
||||
else
|
||||
{
|
||||
/*#if defined(__DOS__)
|
||||
qse_httpd_seterrnum (httpd, QSE_HTTPD_ENOIMPL);
|
||||
return -1;
|
||||
#else*/
|
||||
qse_ssize_t ret = send (client->handle, buf, bufsize, 0);
|
||||
if (ret <= -1) qse_httpd_seterrnum (httpd, SKERR_TO_ERRNUM());
|
||||
return ret;
|
||||
/*#endif*/
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user