adding directory name formatter callback to hio_svc_htts_dofile() - not finished yet
This commit is contained in:
parent
85616b1658
commit
9e285bcc1e
@ -976,7 +976,7 @@ if (hio_htre_getcontentlen(req) > 0)
|
|||||||
else if (hio_comp_bcstr_limited(qpath, "/cgi/", 5, 1) == 0)
|
else if (hio_comp_bcstr_limited(qpath, "/cgi/", 5, 1) == 0)
|
||||||
x = hio_svc_htts_docgi(htts, csck, req, "", qpath + 4, 0);
|
x = hio_svc_htts_docgi(htts, csck, req, "", qpath + 4, 0);
|
||||||
else
|
else
|
||||||
x = hio_svc_htts_dofile(htts, csck, req, "", qpath, "text/plain", 0);
|
x = hio_svc_htts_dofile(htts, csck, req, "", qpath, "text/plain", 0, HIO_NULL);
|
||||||
if (x <= -1) goto oops;
|
if (x <= -1) goto oops;
|
||||||
}
|
}
|
||||||
#if 0
|
#if 0
|
||||||
|
@ -211,7 +211,7 @@ if (hio_htre_getcontentlen(req) > 0)
|
|||||||
x = hio_svc_htts_dofcgi(htts, csck, req, &fcgis_addr, 0);
|
x = hio_svc_htts_dofcgi(htts, csck, req, &fcgis_addr, 0);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
x = hio_svc_htts_dofile(htts, csck, req, "", qpath, "text/plain", 0);
|
x = hio_svc_htts_dofile(htts, csck, req, "", qpath, "text/plain", 0, HIO_NULL);
|
||||||
if (x <= -1) goto oops;
|
if (x <= -1) goto oops;
|
||||||
}
|
}
|
||||||
#if 0
|
#if 0
|
||||||
|
@ -84,7 +84,7 @@ static int process_http_request (hio_svc_htts_t* htts, hio_dev_sck_t* csck, hio_
|
|||||||
else // if (mth == HIO_HTTP_GET || mth == HIO_HTTP_POST)
|
else // if (mth == HIO_HTTP_GET || mth == HIO_HTTP_POST)
|
||||||
{
|
{
|
||||||
/* TODO: proper mime-type */
|
/* TODO: proper mime-type */
|
||||||
if (hio_svc_htts_dofile(htts, csck, req, ext->docroot, qpath, HIO_NULL, 0) <= -1) goto oops;
|
if (hio_svc_htts_dofile(htts, csck, req, ext->docroot, qpath, HIO_NULL, 0, HIO_NULL) <= -1) goto oops;
|
||||||
}
|
}
|
||||||
#if 0
|
#if 0
|
||||||
else
|
else
|
||||||
|
@ -137,7 +137,6 @@ typedef void (*hio_svc_htts_thr_func_t) (
|
|||||||
|
|
||||||
/* -------------------------------------------------------------- */
|
/* -------------------------------------------------------------- */
|
||||||
|
|
||||||
|
|
||||||
enum hio_svc_htts_cgi_option_t
|
enum hio_svc_htts_cgi_option_t
|
||||||
{
|
{
|
||||||
HIO_SVC_HTTS_CGI_NO_100_CONTINUE = (1 << 0)
|
HIO_SVC_HTTS_CGI_NO_100_CONTINUE = (1 << 0)
|
||||||
@ -162,6 +161,12 @@ enum hio_svc_htts_txt_option_t
|
|||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
struct hio_svc_htts_file_cbs_t
|
||||||
|
{
|
||||||
|
int (*bfmt_dir) (hio_svc_htts_t* htts, const hio_bch_t* name);
|
||||||
|
};
|
||||||
|
typedef struct hio_svc_htts_file_cbs_t hio_svc_htts_file_cbs_t;
|
||||||
|
|
||||||
#if defined(__cplusplus)
|
#if defined(__cplusplus)
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
@ -341,7 +346,7 @@ HIO_EXPORT int hio_svc_htts_dofcgi (
|
|||||||
hio_dev_sck_t* csck,
|
hio_dev_sck_t* csck,
|
||||||
hio_htre_t* req,
|
hio_htre_t* req,
|
||||||
const hio_skad_t* fcgis_addr,
|
const hio_skad_t* fcgis_addr,
|
||||||
int options
|
int options /**< 0 or bitwise-Ored of #hio_svc_htts_file_option_t enumerators */
|
||||||
);
|
);
|
||||||
|
|
||||||
HIO_EXPORT int hio_svc_htts_dofile (
|
HIO_EXPORT int hio_svc_htts_dofile (
|
||||||
@ -351,7 +356,8 @@ HIO_EXPORT int hio_svc_htts_dofile (
|
|||||||
const hio_bch_t* docroot,
|
const hio_bch_t* docroot,
|
||||||
const hio_bch_t* filepath,
|
const hio_bch_t* filepath,
|
||||||
const hio_bch_t* mime_type,
|
const hio_bch_t* mime_type,
|
||||||
int options
|
int options,
|
||||||
|
hio_svc_htts_file_cbs_t* cbs
|
||||||
);
|
);
|
||||||
|
|
||||||
HIO_EXPORT int hio_svc_htts_dothr (
|
HIO_EXPORT int hio_svc_htts_dothr (
|
||||||
|
@ -73,18 +73,18 @@ struct hio_bopt_lng_t
|
|||||||
struct hio_bopt_t
|
struct hio_bopt_t
|
||||||
{
|
{
|
||||||
/* input */
|
/* input */
|
||||||
const hio_bch_t* str; /* option string */
|
const hio_bch_t* str; /**< option string */
|
||||||
hio_bopt_lng_t* lng; /* long options */
|
hio_bopt_lng_t* lng; /**< long options */
|
||||||
|
|
||||||
/* output */
|
/* output */
|
||||||
hio_bci_t opt; /* character checked for validity */
|
hio_bci_t opt; /**< character checked for validity */
|
||||||
hio_bch_t* arg; /* argument associated with an option */
|
hio_bch_t* arg; /**< argument associated with an option */
|
||||||
|
|
||||||
/* output */
|
/* output */
|
||||||
const hio_bch_t* lngopt;
|
const hio_bch_t* lngopt;
|
||||||
|
|
||||||
/* input + output */
|
/* input + output */
|
||||||
int ind; /* index into parent argv vector */
|
int ind; /**< index into parent argv vector */
|
||||||
|
|
||||||
/* input + output - internal*/
|
/* input + output - internal*/
|
||||||
hio_bch_t* cur;
|
hio_bch_t* cur;
|
||||||
@ -95,7 +95,7 @@ extern "C" {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The hio_getopt() function processes the \a argc command-line arguments
|
* The hio_getuopt() function processes the \a argc command-line arguments
|
||||||
* pointed to by \a argv as configured in \a opt. It can process two
|
* pointed to by \a argv as configured in \a opt. It can process two
|
||||||
* different option styles: a single character starting with '-', and a
|
* different option styles: a single character starting with '-', and a
|
||||||
* long name starting with '--'.
|
* long name starting with '--'.
|
||||||
@ -107,7 +107,7 @@ extern "C" {
|
|||||||
* - \b ? indicates a bad option stored in the \a opt->opt field.
|
* - \b ? indicates a bad option stored in the \a opt->opt field.
|
||||||
* - \b : indicates a bad parameter for an option stored in the \a opt->opt field.
|
* - \b : indicates a bad parameter for an option stored in the \a opt->opt field.
|
||||||
*
|
*
|
||||||
* @return an option character on success, HIO_CHAR_EOF on no more options.
|
* @return an option character on success, #HIO_UCI_EOF on no more options.
|
||||||
*/
|
*/
|
||||||
HIO_EXPORT hio_uci_t hio_getuopt (
|
HIO_EXPORT hio_uci_t hio_getuopt (
|
||||||
int argc, /* argument count */
|
int argc, /* argument count */
|
||||||
@ -115,6 +115,10 @@ HIO_EXPORT hio_uci_t hio_getuopt (
|
|||||||
hio_uopt_t* opt /* option configuration */
|
hio_uopt_t* opt /* option configuration */
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The hio_getbopt() function is analogous to hio_getuopt() except that
|
||||||
|
* it accepts character strings of the #hio_bch_t type.
|
||||||
|
*/
|
||||||
HIO_EXPORT hio_bci_t hio_getbopt (
|
HIO_EXPORT hio_bci_t hio_getbopt (
|
||||||
int argc, /* argument count */
|
int argc, /* argument count */
|
||||||
hio_bch_t* const* argv, /* argument array */
|
hio_bch_t* const* argv, /* argument array */
|
||||||
|
16
lib/hio.h
16
lib/hio.h
@ -25,6 +25,10 @@
|
|||||||
#ifndef _HIO_H_
|
#ifndef _HIO_H_
|
||||||
#define _HIO_H_
|
#define _HIO_H_
|
||||||
|
|
||||||
|
/** \file
|
||||||
|
* The file defines basic data types and functions common through the entire
|
||||||
|
* library.
|
||||||
|
*/
|
||||||
#include <hio-cmn.h>
|
#include <hio-cmn.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
|
||||||
@ -259,6 +263,10 @@ struct hio_dev_evcb_t
|
|||||||
int (*on_write) (hio_dev_t* dev, hio_iolen_t wrlen, void* wrctx, const hio_devaddr_t* dstaddr);
|
int (*on_write) (hio_dev_t* dev, hio_iolen_t wrlen, void* wrctx, const hio_devaddr_t* dstaddr);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The #hio_q_t type is a basic structure that holds two pointers to the previous
|
||||||
|
* item and the next to form a circular doubly linked list to used as a queue.
|
||||||
|
*/
|
||||||
struct hio_q_t
|
struct hio_q_t
|
||||||
{
|
{
|
||||||
hio_q_t* q_next;
|
hio_q_t* q_next;
|
||||||
@ -297,14 +305,14 @@ struct hio_q_t
|
|||||||
__nn->q_prev->q_next = __nn; \
|
__nn->q_prev->q_next = __nn; \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
/* insert an item at the back of the queue */
|
/** The #HIO_Q_ENQ macro inserts an item at the back of the queue. */
|
||||||
/*#define HIO_Q_ENQ(wq,x) HIO_Q_LINK(HIO_Q_TAIL(wq), x, HIO_Q_TAIL(wq)->next)*/
|
/*#define HIO_Q_ENQ(wq,x) HIO_Q_LINK(HIO_Q_TAIL(wq), x, HIO_Q_TAIL(wq)->next)*/
|
||||||
#define HIO_Q_ENQ(wq,x) HIO_Q_LINK(HIO_Q_TAIL(wq), x, wq)
|
#define HIO_Q_ENQ(wq,x) HIO_Q_LINK(HIO_Q_TAIL(wq), x, wq)
|
||||||
|
|
||||||
/* remove an item in the front from the queue */
|
/** The #HIO_Q_DEQ macro removes an item in the front from the queue. */
|
||||||
#define HIO_Q_DEQ(wq) HIO_Q_UNLINK(HIO_Q_HEAD(wq))
|
#define HIO_Q_DEQ(wq) HIO_Q_UNLINK(HIO_Q_HEAD(wq))
|
||||||
|
|
||||||
/* completed write queue */
|
/** The #hio_cwq_t type defines a queue of completed writes. */
|
||||||
struct hio_cwq_t
|
struct hio_cwq_t
|
||||||
{
|
{
|
||||||
hio_cwq_t* q_next;
|
hio_cwq_t* q_next;
|
||||||
@ -331,7 +339,7 @@ struct hio_cwq_t
|
|||||||
#define HIO_CWQ_ENQ(cwq,x) HIO_CWQ_LINK(HIO_CWQ_TAIL(cwq), (hio_q_t*)x, cwq)
|
#define HIO_CWQ_ENQ(cwq,x) HIO_CWQ_LINK(HIO_CWQ_TAIL(cwq), (hio_q_t*)x, cwq)
|
||||||
#define HIO_CWQ_DEQ(cwq) HIO_CWQ_UNLINK(HIO_CWQ_HEAD(cwq))
|
#define HIO_CWQ_DEQ(cwq) HIO_CWQ_UNLINK(HIO_CWQ_HEAD(cwq))
|
||||||
|
|
||||||
/* write queue */
|
/** The #hio_wq_t type defines a queue of pending writes */
|
||||||
struct hio_wq_t
|
struct hio_wq_t
|
||||||
{
|
{
|
||||||
hio_wq_t* q_next;
|
hio_wq_t* q_next;
|
||||||
|
@ -35,6 +35,7 @@
|
|||||||
#include <netinet/tcp.h>
|
#include <netinet/tcp.h>
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#define FILE_ALLOW_UNLIMITED_REQ_CONTENT_LENGTH
|
#define FILE_ALLOW_UNLIMITED_REQ_CONTENT_LENGTH
|
||||||
|
|
||||||
@ -56,6 +57,7 @@ struct file_t
|
|||||||
HIO_SVC_HTTS_RSRC_HEADER;
|
HIO_SVC_HTTS_RSRC_HEADER;
|
||||||
|
|
||||||
int options;
|
int options;
|
||||||
|
hio_svc_htts_file_cbs_t* cbs;
|
||||||
hio_oow_t num_pending_writes_to_client;
|
hio_oow_t num_pending_writes_to_client;
|
||||||
hio_oow_t num_pending_writes_to_peer;
|
hio_oow_t num_pending_writes_to_peer;
|
||||||
int sendfile_ok;
|
int sendfile_ok;
|
||||||
@ -736,12 +738,18 @@ static int open_peer_with_mode (file_t* file, const hio_bch_t* actual_file, int
|
|||||||
while ((de = readdir(dp)))
|
while ((de = readdir(dp)))
|
||||||
{
|
{
|
||||||
/* TODO: do buffering ... */
|
/* TODO: do buffering ... */
|
||||||
|
#if 0
|
||||||
|
/* TODO: call a directory entry formatter callback?? */
|
||||||
|
if (file->cbs && file->cbs->bfmt_dir)
|
||||||
|
{
|
||||||
|
file->cbs->bfmt_dir(file->htts, de->d_name);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
if (strcmp(de->d_name, ".") != 0)
|
if (strcmp(de->d_name, ".") != 0)
|
||||||
{
|
{
|
||||||
write (alt_fd, de->d_name, strlen(de->d_name));
|
write (alt_fd, de->d_name, strlen(de->d_name));
|
||||||
write (alt_fd, "\n", 1);
|
write (alt_fd, "\n", 1);
|
||||||
}
|
}
|
||||||
/* TODO: call a directory entry formatter callback?? */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
lseek (alt_fd, SEEK_SET, 0);
|
lseek (alt_fd, SEEK_SET, 0);
|
||||||
@ -792,10 +800,8 @@ static HIO_INLINE void set_tcp_cork (hio_dev_sck_t* sck)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
int hio_svc_htts_dofile (hio_svc_htts_t* htts, hio_dev_sck_t* csck, hio_htre_t* req, const hio_bch_t* docroot, const hio_bch_t* filepath, const hio_bch_t* mime_type, int options)
|
int hio_svc_htts_dofile (hio_svc_htts_t* htts, hio_dev_sck_t* csck, hio_htre_t* req, const hio_bch_t* docroot, const hio_bch_t* filepath, const hio_bch_t* mime_type, int options, hio_svc_htts_file_cbs_t* cbs)
|
||||||
{
|
{
|
||||||
/* TODO: ETag, Last-Modified... */
|
|
||||||
|
|
||||||
hio_t* hio = htts->hio;
|
hio_t* hio = htts->hio;
|
||||||
hio_svc_htts_cli_t* cli = hio_dev_sck_getxtn(csck);
|
hio_svc_htts_cli_t* cli = hio_dev_sck_getxtn(csck);
|
||||||
file_t* file = HIO_NULL;
|
file_t* file = HIO_NULL;
|
||||||
@ -815,6 +821,7 @@ int hio_svc_htts_dofile (hio_svc_htts_t* htts, hio_dev_sck_t* csck, hio_htre_t*
|
|||||||
if (HIO_UNLIKELY(!file)) goto oops;
|
if (HIO_UNLIKELY(!file)) goto oops;
|
||||||
|
|
||||||
file->options = options;
|
file->options = options;
|
||||||
|
file->cbs = cbs; /* the given pointer must outlive the lifespan of the while file handling cycle. */
|
||||||
file->client = cli;
|
file->client = cli;
|
||||||
file->sendfile_ok = hio_dev_sck_sendfileok(cli->sck);
|
file->sendfile_ok = hio_dev_sck_sendfileok(cli->sck);
|
||||||
/*file->num_pending_writes_to_client = 0;
|
/*file->num_pending_writes_to_client = 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user