2020-03-03 13:47:51 +00:00
|
|
|
/*
|
|
|
|
Copyright (c) 2016-2020 Chung, Hyung-Hwan. All rights reserved.
|
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
|
|
modification, are permitted provided that the following conditions
|
|
|
|
are met:
|
|
|
|
1. Redistributions of source code must retain the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer.
|
|
|
|
2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer in the
|
|
|
|
documentation and/or other materials provided with the distribution.
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
|
|
|
|
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _MIO_HTRD_H_
|
|
|
|
#define _MIO_HTRD_H_
|
|
|
|
|
|
|
|
#include <mio-http.h>
|
|
|
|
#include <mio-htre.h>
|
|
|
|
|
|
|
|
typedef struct mio_htrd_t mio_htrd_t;
|
|
|
|
|
|
|
|
enum mio_htrd_errnum_t
|
|
|
|
{
|
|
|
|
MIO_HTRD_ENOERR,
|
|
|
|
MIO_HTRD_EOTHER,
|
|
|
|
MIO_HTRD_ENOIMPL,
|
|
|
|
MIO_HTRD_ESYSERR,
|
|
|
|
MIO_HTRD_EINTERN,
|
|
|
|
|
|
|
|
MIO_HTRD_ENOMEM,
|
|
|
|
MIO_HTRD_EBADRE,
|
|
|
|
MIO_HTRD_EBADHDR,
|
|
|
|
MIO_HTRD_ERECBS,
|
|
|
|
MIO_HTRD_ECONCB,
|
|
|
|
MIO_HTRD_ESUSPENDED
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef enum mio_htrd_errnum_t mio_htrd_errnum_t;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The mio_htrd_option_t type defines various options to
|
|
|
|
* change the behavior of the mio_htrd_t reader.
|
|
|
|
*/
|
|
|
|
enum mio_htrd_option_t
|
|
|
|
{
|
|
|
|
MIO_HTRD_SKIPEMPTYLINES = (1 << 0), /**< skip leading empty lines before the initial line */
|
|
|
|
MIO_HTRD_SKIPINITIALLINE = (1 << 1), /**< skip processing an initial line */
|
|
|
|
MIO_HTRD_CANONQPATH = (1 << 2), /**< canonicalize the query path */
|
|
|
|
MIO_HTRD_PEEKONLY = (1 << 3), /**< trigger a peek callback after headers without processing contents */
|
|
|
|
MIO_HTRD_REQUEST = (1 << 4), /**< parse input as a request */
|
|
|
|
MIO_HTRD_RESPONSE = (1 << 5), /**< parse input as a response */
|
|
|
|
MIO_HTRD_TRAILERS = (1 << 6), /**< store trailers in a separate table */
|
|
|
|
MIO_HTRD_STRICT = (1 << 7) /**< be more picky */
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef enum mio_htrd_option_t mio_htrd_option_t;
|
|
|
|
|
|
|
|
typedef struct mio_htrd_recbs_t mio_htrd_recbs_t;
|
|
|
|
|
|
|
|
struct mio_htrd_recbs_t
|
|
|
|
{
|
|
|
|
int (*peek) (mio_htrd_t* htrd, mio_htre_t* re);
|
|
|
|
int (*poke) (mio_htrd_t* htrd, mio_htre_t* re);
|
|
|
|
};
|
|
|
|
|
|
|
|
struct mio_htrd_t
|
|
|
|
{
|
2020-05-01 18:01:29 +00:00
|
|
|
mio_t* mio;
|
2020-03-03 13:47:51 +00:00
|
|
|
mio_htrd_errnum_t errnum;
|
|
|
|
int option;
|
|
|
|
int flags;
|
|
|
|
|
|
|
|
const mio_htrd_recbs_t* recbs;
|
|
|
|
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
int flags;
|
|
|
|
|
|
|
|
int crlf; /* crlf status */
|
2020-05-01 18:01:29 +00:00
|
|
|
mio_oow_t plen; /* raw request length excluding crlf */
|
|
|
|
mio_oow_t need; /* number of octets needed for contents */
|
2020-03-03 13:47:51 +00:00
|
|
|
|
|
|
|
struct
|
|
|
|
{
|
2020-05-01 18:01:29 +00:00
|
|
|
mio_oow_t len;
|
|
|
|
mio_oow_t count;
|
2020-03-03 13:47:51 +00:00
|
|
|
int phase;
|
|
|
|
} chunk;
|
|
|
|
} s; /* state */
|
|
|
|
|
|
|
|
/* buffers needed for processing a request */
|
|
|
|
struct
|
|
|
|
{
|
2020-05-01 18:01:29 +00:00
|
|
|
mio_becs_t raw; /* buffer to hold raw octets */
|
|
|
|
mio_becs_t tra; /* buffer for handling trailers */
|
2020-03-03 13:47:51 +00:00
|
|
|
} b;
|
|
|
|
} fed;
|
|
|
|
|
|
|
|
mio_htre_t re;
|
|
|
|
int clean;
|
|
|
|
};
|
|
|
|
|
|
|
|
#if defined(__cplusplus)
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The mio_htrd_open() function creates a htrd processor.
|
|
|
|
*/
|
|
|
|
MIO_EXPORT mio_htrd_t* mio_htrd_open (
|
2020-05-01 18:01:29 +00:00
|
|
|
mio_t* mio, /**< memory manager */
|
|
|
|
mio_oow_t xtnsize /**< extension size in bytes */
|
2020-03-03 13:47:51 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The mio_htrd_close() function destroys a htrd processor.
|
|
|
|
*/
|
|
|
|
MIO_EXPORT void mio_htrd_close (
|
|
|
|
mio_htrd_t* htrd
|
|
|
|
);
|
|
|
|
|
|
|
|
MIO_EXPORT int mio_htrd_init (
|
|
|
|
mio_htrd_t* htrd,
|
2020-05-01 18:01:29 +00:00
|
|
|
mio_t* mio
|
2020-03-03 13:47:51 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
MIO_EXPORT void mio_htrd_fini (
|
|
|
|
mio_htrd_t* htrd
|
|
|
|
);
|
|
|
|
|
2020-05-01 18:01:29 +00:00
|
|
|
#if defined(MIO_HAVE_INLINE)
|
|
|
|
static MIO_INLINE void* mio_htrd_getxtn (mio_htrd_t* htrd) { return (void*)(htrd + 1); }
|
|
|
|
#else
|
|
|
|
#define mio_htrd_getxtn(htrd) ((void*)((mio_htrd_t*)(htrd) + 1))
|
|
|
|
#endif
|
2020-03-03 13:47:51 +00:00
|
|
|
|
|
|
|
MIO_EXPORT mio_htrd_errnum_t mio_htrd_geterrnum (
|
|
|
|
mio_htrd_t* htrd
|
|
|
|
);
|
|
|
|
|
|
|
|
MIO_EXPORT void mio_htrd_clear (
|
|
|
|
mio_htrd_t* htrd
|
|
|
|
);
|
|
|
|
|
|
|
|
MIO_EXPORT int mio_htrd_getopt (
|
|
|
|
mio_htrd_t* htrd
|
|
|
|
);
|
|
|
|
|
|
|
|
MIO_EXPORT void mio_htrd_setopt (
|
|
|
|
mio_htrd_t* htrd,
|
|
|
|
int opts
|
|
|
|
);
|
|
|
|
|
|
|
|
MIO_EXPORT const mio_htrd_recbs_t* mio_htrd_getrecbs (
|
|
|
|
mio_htrd_t* htrd
|
|
|
|
);
|
|
|
|
|
|
|
|
MIO_EXPORT void mio_htrd_setrecbs (
|
|
|
|
mio_htrd_t* htrd,
|
|
|
|
const mio_htrd_recbs_t* recbs
|
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The mio_htrd_feed() function accepts htrd request octets and invokes a
|
|
|
|
* callback function if it has processed a proper htrd request.
|
|
|
|
*/
|
|
|
|
MIO_EXPORT int mio_htrd_feed (
|
|
|
|
mio_htrd_t* htrd, /**< htrd */
|
2020-05-15 06:18:49 +00:00
|
|
|
const mio_bch_t* req, /**< request octets */
|
|
|
|
mio_oow_t len, /**< number of octets */
|
|
|
|
mio_oow_t* rem
|
2020-03-03 13:47:51 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The mio_htrd_halt() function indicates the end of feeeding
|
|
|
|
* if the current response should be processed until the
|
|
|
|
* connection is closed.
|
|
|
|
*/
|
|
|
|
MIO_EXPORT int mio_htrd_halt (
|
|
|
|
mio_htrd_t* htrd
|
|
|
|
);
|
|
|
|
|
|
|
|
MIO_EXPORT void mio_htrd_suspend (
|
|
|
|
mio_htrd_t* htrd
|
|
|
|
);
|
|
|
|
|
|
|
|
MIO_EXPORT void mio_htrd_resume (
|
|
|
|
mio_htrd_t* htrd
|
|
|
|
);
|
|
|
|
|
|
|
|
MIO_EXPORT void mio_htrd_dummify (
|
|
|
|
mio_htrd_t* htrd
|
|
|
|
);
|
|
|
|
|
|
|
|
MIO_EXPORT void mio_htrd_undummify (
|
|
|
|
mio_htrd_t* htrd
|
|
|
|
);
|
|
|
|
|
2020-05-01 18:01:29 +00:00
|
|
|
/*
|
2020-03-03 13:47:51 +00:00
|
|
|
MIO_EXPORT int mio_htrd_scanqparam (
|
2020-05-01 18:01:29 +00:00
|
|
|
mio_htrd_t* http,
|
|
|
|
const mio_bcs_t* cstr
|
2020-03-03 13:47:51 +00:00
|
|
|
);
|
2020-05-01 18:01:29 +00:00
|
|
|
*/
|
2020-03-03 13:47:51 +00:00
|
|
|
|
|
|
|
#if defined(__cplusplus)
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|