diff options
-rw-r--r-- | package/deps.mak | 16 | ||||
-rw-r--r-- | src/include/tipidee/log.h | 41 | ||||
-rw-r--r-- | src/include/tipidee/method.h | 16 | ||||
-rw-r--r-- | src/libtipidee/deps-lib/tipidee | 9 | ||||
-rw-r--r-- | src/libtipidee/tipidee_log_answer.c | 24 | ||||
-rw-r--r-- | src/libtipidee/tipidee_log_exit.c | 14 | ||||
-rw-r--r-- | src/libtipidee/tipidee_log_request.c | 60 | ||||
-rw-r--r-- | src/libtipidee/tipidee_log_resource.c | 11 | ||||
-rw-r--r-- | src/libtipidee/tipidee_log_start.c | 25 | ||||
-rw-r--r-- | src/libtipidee/tipidee_method.c | 46 | ||||
-rw-r--r-- | src/libtipidee/tipidee_method_conv_table.c | 19 | ||||
-rw-r--r-- | src/libtipidee/tipidee_method_tonum.c | 12 | ||||
-rw-r--r-- | src/libtipidee/tipidee_method_tostr.c | 8 |
13 files changed, 241 insertions, 60 deletions
diff --git a/package/deps.mak b/package/deps.mak index 88dbd44..016ff9e 100644 --- a/package/deps.mak +++ b/package/deps.mak @@ -3,6 +3,7 @@ # src/include/tipidee/conf.h: src/include/tipidee/uri.h +src/include/tipidee/log.h: src/include/tipidee/rql.h src/include/tipidee/response.h: src/include/tipidee/rql.h src/include/tipidee/rql.h: src/include/tipidee/method.h src/include/tipidee/uri.h src/include/tipidee/tipidee.h: src/include/tipidee/conf.h src/include/tipidee/config.h src/include/tipidee/headers.h src/include/tipidee/method.h src/include/tipidee/response.h src/include/tipidee/rql.h src/include/tipidee/uri.h src/include/tipidee/util.h @@ -25,9 +26,12 @@ src/libtipidee/tipidee_headers_get_content_length.o src/libtipidee/tipidee_heade src/libtipidee/tipidee_headers_init.o src/libtipidee/tipidee_headers_init.lo: src/libtipidee/tipidee_headers_init.c src/include/tipidee/headers.h src/libtipidee/tipidee_headers_parse.o src/libtipidee/tipidee_headers_parse.lo: src/libtipidee/tipidee_headers_parse.c src/include/tipidee/headers.h src/libtipidee/tipidee_headers_search.o src/libtipidee/tipidee_headers_search.lo: src/libtipidee/tipidee_headers_search.c src/include/tipidee/headers.h -src/libtipidee/tipidee_method_conv_table.o src/libtipidee/tipidee_method_conv_table.lo: src/libtipidee/tipidee_method_conv_table.c src/include/tipidee/method.h -src/libtipidee/tipidee_method_tonum.o src/libtipidee/tipidee_method_tonum.lo: src/libtipidee/tipidee_method_tonum.c src/include/tipidee/method.h -src/libtipidee/tipidee_method_tostr.o src/libtipidee/tipidee_method_tostr.lo: src/libtipidee/tipidee_method_tostr.c src/include/tipidee/method.h +src/libtipidee/tipidee_log_answer.o src/libtipidee/tipidee_log_answer.lo: src/libtipidee/tipidee_log_answer.c src/include/tipidee/log.h +src/libtipidee/tipidee_log_exit.o src/libtipidee/tipidee_log_exit.lo: src/libtipidee/tipidee_log_exit.c src/include/tipidee/log.h +src/libtipidee/tipidee_log_request.o src/libtipidee/tipidee_log_request.lo: src/libtipidee/tipidee_log_request.c src/include/tipidee/log.h src/include/tipidee/method.h +src/libtipidee/tipidee_log_resource.o src/libtipidee/tipidee_log_resource.lo: src/libtipidee/tipidee_log_resource.c src/include/tipidee/log.h +src/libtipidee/tipidee_log_start.o src/libtipidee/tipidee_log_start.lo: src/libtipidee/tipidee_log_start.c src/include/tipidee/log.h +src/libtipidee/tipidee_method.o src/libtipidee/tipidee_method.lo: src/libtipidee/tipidee_method.c src/include/tipidee/method.h src/libtipidee/tipidee_response_error.o src/libtipidee/tipidee_response_error.lo: src/libtipidee/tipidee_response_error.c src/include/tipidee/method.h src/include/tipidee/response.h src/include/tipidee/rql.h src/libtipidee/tipidee_response_header_builtin.o src/libtipidee/tipidee_response_header_builtin.lo: src/libtipidee/tipidee_response_header_builtin.c src/include/tipidee/config.h src/include/tipidee/response.h src/libtipidee/tipidee_response_header_common_put.o src/libtipidee/tipidee_response_header_common_put.lo: src/libtipidee/tipidee_response_header_common_put.c src/include/tipidee/config.h src/include/tipidee/response.h @@ -55,12 +59,12 @@ tipidee-config: src/config/tipidee-config.o src/config/confnode.o src/config/con tipidee-config-preprocess: EXTRA_LIBS := -lskarnet tipidee-config-preprocess: src/config/tipidee-config-preprocess.o ifeq ($(strip $(STATIC_LIBS_ARE_PIC)),) -libtipidee.a.xyzzy: src/libtipidee/tipidee_conf_free.o src/libtipidee/tipidee_conf_get.o src/libtipidee/tipidee_conf_get_argv.o src/libtipidee/tipidee_conf_get_content_type.o src/libtipidee/tipidee_conf_get_redirection.o src/libtipidee/tipidee_conf_get_string.o src/libtipidee/tipidee_conf_get_uint32.o src/libtipidee/tipidee_conf_init.o src/libtipidee/tipidee_headers_get_content_length.o src/libtipidee/tipidee_headers_init.o src/libtipidee/tipidee_headers_parse.o src/libtipidee/tipidee_headers_search.o src/libtipidee/tipidee_method_conv_table.o src/libtipidee/tipidee_method_tonum.o src/libtipidee/tipidee_method_tostr.o src/libtipidee/tipidee_response_error.o src/libtipidee/tipidee_response_header_builtin.o src/libtipidee/tipidee_response_header_common_put.o src/libtipidee/tipidee_response_header_date.o src/libtipidee/tipidee_response_header_date_fmt.o src/libtipidee/tipidee_response_header_lastmodified.o src/libtipidee/tipidee_response_status.o src/libtipidee/tipidee_rql_read.o src/libtipidee/tipidee_uri_parse.o src/libtipidee/tipidee_util_chunked_read.o src/libtipidee/tipidee_util_defaulttext.o src/libtipidee/tipidee_util_httpdate.o +libtipidee.a.xyzzy: src/libtipidee/tipidee_conf_free.o src/libtipidee/tipidee_conf_get.o src/libtipidee/tipidee_conf_get_argv.o src/libtipidee/tipidee_conf_get_content_type.o src/libtipidee/tipidee_conf_get_redirection.o src/libtipidee/tipidee_conf_get_string.o src/libtipidee/tipidee_conf_get_uint32.o src/libtipidee/tipidee_conf_init.o src/libtipidee/tipidee_headers_get_content_length.o src/libtipidee/tipidee_headers_init.o src/libtipidee/tipidee_headers_parse.o src/libtipidee/tipidee_headers_search.o src/libtipidee/tipidee_log_answer.o src/libtipidee/tipidee_log_exit.o src/libtipidee/tipidee_log_resource.o src/libtipidee/tipidee_log_request.o src/libtipidee/tipidee_log_start.o src/libtipidee/tipidee_method.o src/libtipidee/tipidee_response_error.o src/libtipidee/tipidee_response_header_builtin.o src/libtipidee/tipidee_response_header_common_put.o src/libtipidee/tipidee_response_header_date.o src/libtipidee/tipidee_response_header_date_fmt.o src/libtipidee/tipidee_response_header_lastmodified.o src/libtipidee/tipidee_response_status.o src/libtipidee/tipidee_rql_read.o src/libtipidee/tipidee_uri_parse.o src/libtipidee/tipidee_util_chunked_read.o src/libtipidee/tipidee_util_defaulttext.o src/libtipidee/tipidee_util_httpdate.o else -libtipidee.a.xyzzy: src/libtipidee/tipidee_conf_free.lo src/libtipidee/tipidee_conf_get.lo src/libtipidee/tipidee_conf_get_argv.lo src/libtipidee/tipidee_conf_get_content_type.lo src/libtipidee/tipidee_conf_get_redirection.lo src/libtipidee/tipidee_conf_get_string.lo src/libtipidee/tipidee_conf_get_uint32.lo src/libtipidee/tipidee_conf_init.lo src/libtipidee/tipidee_headers_get_content_length.lo src/libtipidee/tipidee_headers_init.lo src/libtipidee/tipidee_headers_parse.lo src/libtipidee/tipidee_headers_search.lo src/libtipidee/tipidee_method_conv_table.lo src/libtipidee/tipidee_method_tonum.lo src/libtipidee/tipidee_method_tostr.lo src/libtipidee/tipidee_response_error.lo src/libtipidee/tipidee_response_header_builtin.lo src/libtipidee/tipidee_response_header_common_put.lo src/libtipidee/tipidee_response_header_date.lo src/libtipidee/tipidee_response_header_date_fmt.lo src/libtipidee/tipidee_response_header_lastmodified.lo src/libtipidee/tipidee_response_status.lo src/libtipidee/tipidee_rql_read.lo src/libtipidee/tipidee_uri_parse.lo src/libtipidee/tipidee_util_chunked_read.lo src/libtipidee/tipidee_util_defaulttext.lo src/libtipidee/tipidee_util_httpdate.lo +libtipidee.a.xyzzy: src/libtipidee/tipidee_conf_free.lo src/libtipidee/tipidee_conf_get.lo src/libtipidee/tipidee_conf_get_argv.lo src/libtipidee/tipidee_conf_get_content_type.lo src/libtipidee/tipidee_conf_get_redirection.lo src/libtipidee/tipidee_conf_get_string.lo src/libtipidee/tipidee_conf_get_uint32.lo src/libtipidee/tipidee_conf_init.lo src/libtipidee/tipidee_headers_get_content_length.lo src/libtipidee/tipidee_headers_init.lo src/libtipidee/tipidee_headers_parse.lo src/libtipidee/tipidee_headers_search.lo src/libtipidee/tipidee_log_answer.lo src/libtipidee/tipidee_log_exit.lo src/libtipidee/tipidee_log_resource.lo src/libtipidee/tipidee_log_request.lo src/libtipidee/tipidee_log_start.lo src/libtipidee/tipidee_method.lo src/libtipidee/tipidee_response_error.lo src/libtipidee/tipidee_response_header_builtin.lo src/libtipidee/tipidee_response_header_common_put.lo src/libtipidee/tipidee_response_header_date.lo src/libtipidee/tipidee_response_header_date_fmt.lo src/libtipidee/tipidee_response_header_lastmodified.lo src/libtipidee/tipidee_response_status.lo src/libtipidee/tipidee_rql_read.lo src/libtipidee/tipidee_uri_parse.lo src/libtipidee/tipidee_util_chunked_read.lo src/libtipidee/tipidee_util_defaulttext.lo src/libtipidee/tipidee_util_httpdate.lo endif libtipidee.so.xyzzy: EXTRA_LIBS := -lskarnet -libtipidee.so.xyzzy: src/libtipidee/tipidee_conf_free.lo src/libtipidee/tipidee_conf_get.lo src/libtipidee/tipidee_conf_get_argv.lo src/libtipidee/tipidee_conf_get_content_type.lo src/libtipidee/tipidee_conf_get_redirection.lo src/libtipidee/tipidee_conf_get_string.lo src/libtipidee/tipidee_conf_get_uint32.lo src/libtipidee/tipidee_conf_init.lo src/libtipidee/tipidee_headers_get_content_length.lo src/libtipidee/tipidee_headers_init.lo src/libtipidee/tipidee_headers_parse.lo src/libtipidee/tipidee_headers_search.lo src/libtipidee/tipidee_method_conv_table.lo src/libtipidee/tipidee_method_tonum.lo src/libtipidee/tipidee_method_tostr.lo src/libtipidee/tipidee_response_error.lo src/libtipidee/tipidee_response_header_builtin.lo src/libtipidee/tipidee_response_header_common_put.lo src/libtipidee/tipidee_response_header_date.lo src/libtipidee/tipidee_response_header_date_fmt.lo src/libtipidee/tipidee_response_header_lastmodified.lo src/libtipidee/tipidee_response_status.lo src/libtipidee/tipidee_rql_read.lo src/libtipidee/tipidee_uri_parse.lo src/libtipidee/tipidee_util_chunked_read.lo src/libtipidee/tipidee_util_defaulttext.lo src/libtipidee/tipidee_util_httpdate.lo +libtipidee.so.xyzzy: src/libtipidee/tipidee_conf_free.lo src/libtipidee/tipidee_conf_get.lo src/libtipidee/tipidee_conf_get_argv.lo src/libtipidee/tipidee_conf_get_content_type.lo src/libtipidee/tipidee_conf_get_redirection.lo src/libtipidee/tipidee_conf_get_string.lo src/libtipidee/tipidee_conf_get_uint32.lo src/libtipidee/tipidee_conf_init.lo src/libtipidee/tipidee_headers_get_content_length.lo src/libtipidee/tipidee_headers_init.lo src/libtipidee/tipidee_headers_parse.lo src/libtipidee/tipidee_headers_search.lo src/libtipidee/tipidee_log_answer.lo src/libtipidee/tipidee_log_exit.lo src/libtipidee/tipidee_log_resource.lo src/libtipidee/tipidee_log_request.lo src/libtipidee/tipidee_log_start.lo src/libtipidee/tipidee_method.lo src/libtipidee/tipidee_response_error.lo src/libtipidee/tipidee_response_header_builtin.lo src/libtipidee/tipidee_response_header_common_put.lo src/libtipidee/tipidee_response_header_date.lo src/libtipidee/tipidee_response_header_date_fmt.lo src/libtipidee/tipidee_response_header_lastmodified.lo src/libtipidee/tipidee_response_status.lo src/libtipidee/tipidee_rql_read.lo src/libtipidee/tipidee_uri_parse.lo src/libtipidee/tipidee_util_chunked_read.lo src/libtipidee/tipidee_util_defaulttext.lo src/libtipidee/tipidee_util_httpdate.lo tipideed: EXTRA_LIBS := -lskarnet tipideed: src/tipideed/tipideed.o src/tipideed/cgi.o src/tipideed/harden.o src/tipideed/log.o src/tipideed/options.o src/tipideed/regular.o src/tipideed/responses.o src/tipideed/send_file.o src/tipideed/tipideed.o src/tipideed/trace.o libtipidee.a.xyzzy INTERNAL_LIBS := diff --git a/src/include/tipidee/log.h b/src/include/tipidee/log.h new file mode 100644 index 0000000..0fe44ce --- /dev/null +++ b/src/include/tipidee/log.h @@ -0,0 +1,41 @@ +/* ISC license. */ + +#ifndef TIPIDEE_LOG_H +#define TIPIDEE_LOG_H + +#include <sys/types.h> +#include <stdint.h> + +#include <skalibs/stralloc.h> + +#include <tipidee/rql.h> + +#define TIPIDEE_LOG_REQUEST 0x0001 +#define TIPIDEE_LOG_REFERRER 0x0002 +#define TIPIDEE_LOG_UA 0x0004 +#define TIPIDEE_LOG_RESOURCE 0x0008 +#define TIPIDEE_LOG_ANSWER 0x0010 +#define TIPIDEE_LOG_SIZE 0x0020 +#define TIPIDEE_LOG_START 0x100 +#define TIPIDEE_LOG_CLIENTIP 0x0200 +#define TIPIDEE_LOG_CLIENTHOST 0x0400 + +#define TIPIDEE_LOG_DEFAULT (TIPIDEE_LOG_REQUEST | TIPIDEE_LOG_ANSWER | TIPIDEE_LOG_SIZE) + +typedef struct tipidee_resattr_s tipidee_resattr, *tipidee_resattr_ref ; +struct tipidee_resattr_s +{ + char const *content_type ; + uint32_t iscgi : 1 ; + uint32_t isnph : 1 ; +} ; +#define TIPIDEE_RESATTR_ZERO { .content_type = 0, .iscgi = 0, .isnph = 0 } + +extern void tipidee_log_start (uint32_t, char const *, char const *) ; +extern void tipidee_log_exit (uint32_t, unsigned int) ; + +extern void tipidee_log_request (uint32_t, tipidee_rql const *, char const *, char const *, stralloc *) ; +extern void tipidee_log_resource (uint32_t, char const *, char const *, tipidee_resattr const *) ; +extern void tipidee_log_answer (uint32_t, unsigned int, off_t) ; + +#endif diff --git a/src/include/tipidee/method.h b/src/include/tipidee/method.h index 05123e8..b6efaa6 100644 --- a/src/include/tipidee/method.h +++ b/src/include/tipidee/method.h @@ -6,26 +6,18 @@ typedef enum tipidee_method_e tipidee_method, *tipidee_method_ref ; enum tipidee_method_e { - TIPIDEE_METHOD_GET = 0, + TIPIDEE_METHOD_CONNECT = 0, + TIPIDEE_METHOD_DELETE, + TIPIDEE_METHOD_GET, TIPIDEE_METHOD_HEAD, TIPIDEE_METHOD_OPTIONS, TIPIDEE_METHOD_POST, + TIPIDEE_METHOD_PRI, TIPIDEE_METHOD_PUT, - TIPIDEE_METHOD_DELETE, TIPIDEE_METHOD_TRACE, - TIPIDEE_METHOD_CONNECT, - TIPIDEE_METHOD_PRI, TIPIDEE_METHOD_UNKNOWN } ; -typedef struct tipidee_method_conv_s tipidee_method_conv, *tipidee_method_conv_ref ; -struct tipidee_method_conv_s -{ - tipidee_method num ; - char const *str ; -} ; - -extern tipidee_method_conv const *tipidee_method_conv_table ; extern char const *tipidee_method_tostr (tipidee_method) ; extern tipidee_method tipidee_method_tonum (char const *) ; diff --git a/src/libtipidee/deps-lib/tipidee b/src/libtipidee/deps-lib/tipidee index b7f88cc..cba7e43 100644 --- a/src/libtipidee/deps-lib/tipidee +++ b/src/libtipidee/deps-lib/tipidee @@ -10,9 +10,12 @@ tipidee_headers_get_content_length.o tipidee_headers_init.o tipidee_headers_parse.o tipidee_headers_search.o -tipidee_method_conv_table.o -tipidee_method_tonum.o -tipidee_method_tostr.o +tipidee_log_answer.o +tipidee_log_exit.o +tipidee_log_resource.o +tipidee_log_request.o +tipidee_log_start.o +tipidee_method.o tipidee_response_error.o tipidee_response_header_builtin.o tipidee_response_header_common_put.o diff --git a/src/libtipidee/tipidee_log_answer.c b/src/libtipidee/tipidee_log_answer.c new file mode 100644 index 0000000..beedb61 --- /dev/null +++ b/src/libtipidee/tipidee_log_answer.c @@ -0,0 +1,24 @@ +/* ISC license. */ + +#include <sys/types.h> + +#include <skalibs/uint64.h> +#include <skalibs/types.h> +#include <skalibs/strerr.h> + +#include <tipidee/log.h> + +void tipidee_log_answer (uint32_t v, unsigned int status, off_t size) +{ + char fmtstatus[UINT_FMT] ; + if (!(v & TIPIDEE_LOG_ANSWER)) return ; + fmtstatus[uint_fmt(fmtstatus, status)] = 0 ; + if (size) + { + char fmtsize[UINT64_FMT] ; + fmtsize[uint64_fmt(fmtsize, size)] = 0 ; + strerr_warni4x("answer ", fmtstatus, " size ", fmtsize) ; + } + else + strerr_warni2x("answer ", fmtstatus) ; +} diff --git a/src/libtipidee/tipidee_log_exit.c b/src/libtipidee/tipidee_log_exit.c new file mode 100644 index 0000000..7d7b3e0 --- /dev/null +++ b/src/libtipidee/tipidee_log_exit.c @@ -0,0 +1,14 @@ +/* ISC license. */ + +#include <skalibs/types.h> +#include <skalibs/strerr.h> + +#include <tipidee/log.h> + +void tipidee_log_exit (uint32_t v, unsigned int e) +{ + char fmt[UINT_FMT] ; + if (!(v & TIPIDEE_LOG_START)) return ; + fmt[uint_fmt(fmt, e)] = 0 ; + strerr_warni2x("exit ", fmt) ; +} diff --git a/src/libtipidee/tipidee_log_request.c b/src/libtipidee/tipidee_log_request.c new file mode 100644 index 0000000..666297d --- /dev/null +++ b/src/libtipidee/tipidee_log_request.c @@ -0,0 +1,60 @@ +/* ISC license. */ + +#include <stddef.h> + +#include <skalibs/strerr.h> +#include <skalibs/stralloc.h> +#include <skalibs/skamisc.h> + +#include <tipidee/method.h> +#include <tipidee/log.h> + +void tipidee_log_request (uint32_t v, tipidee_rql const *rql, char const *referrer, char const *ua, stralloc *sa) +{ + char const *a[14] = { "info: request " } ; + size_t m = 1 ; + size_t start = sa->len ; + size_t refpos = start, uapos = start ; + if (!(v & TIPIDEE_LOG_REQUEST)) return ; + if (!string_quotes(sa, rql->uri.path)) goto eerr ; + if (v & TIPIDEE_LOG_REFERRER) + { + refpos = sa->len ; + if (!string_quotes(sa, referrer) || !stralloc_0(sa)) goto err ; + } + if (v & TIPIDEE_LOG_UA) + { + uapos = sa->len ; + if (!string_quotes(sa, ua) || !stralloc_0(sa)) goto err ; + } + a[m++] = tipidee_method_tostr(rql->m) ; + a[m++] = " host " ; + a[m++] = rql->uri.host ; + a[m++] = " path " ; + a[m++] = sa->s + start ; + if (rql->uri.query) + { + a[m++] = " query " ; + a[m++] = rql->uri.query ; + } + a[m++] = " http 1." ; + a[m++] = rql->http_minor ? "1" : "0" ; + if (v & TIPIDEE_LOG_REFERRER) + { + a[m++] = " referrer " ; + a[m++] = sa->s + refpos ; + } + if (v & TIPIDEE_LOG_UA) + { + a[m++] = " user-agent " ; + a[m++] = sa->s + uapos ; + } + strerr_warnv(a, m) ; + sa->len = start ; + return ; + + err: + sa->len = start ; + eerr: + strerr_warnwu1sys("log request") ; +} diff --git a/src/libtipidee/tipidee_log_resource.c b/src/libtipidee/tipidee_log_resource.c new file mode 100644 index 0000000..dc525a5 --- /dev/null +++ b/src/libtipidee/tipidee_log_resource.c @@ -0,0 +1,11 @@ +/* ISC license. */ + +#include <skalibs/strerr.h> + +#include <tipidee/log.h> + +void tipidee_log_resource (uint32_t v, char const *docroot, char const *file, tipidee_resattr const *ra) +{ + if (!(v & TIPIDEE_LOG_RESOURCE)) return ; + strerr_warni6x("docroot ", docroot, " file ", file, " type ", ra->iscgi ? ra->isnph ? "nph" : "cgi" : ra->content_type) ; +} diff --git a/src/libtipidee/tipidee_log_start.c b/src/libtipidee/tipidee_log_start.c new file mode 100644 index 0000000..34284af --- /dev/null +++ b/src/libtipidee/tipidee_log_start.c @@ -0,0 +1,25 @@ +/* ISC license. */ + +#include <stddef.h> + +#include <skalibs/strerr.h> + +#include <tipidee/log.h> + +void tipidee_log_start (uint32_t v, char const *ip, char const *host) +{ + char const *a[5] = { "info: start" } ; + size_t m = 1 ; + if (!(v & TIPIDEE_LOG_START)) return ; + if (v & TIPIDEE_LOG_CLIENTIP) + { + a[m++] = " ip " ; + a[m++] = ip ; + } + if (v & TIPIDEE_LOG_CLIENTHOST) + { + a[m++] = " host " ; + a[m++] = host ; + } + strerr_warnv(a, m) ; +} diff --git a/src/libtipidee/tipidee_method.c b/src/libtipidee/tipidee_method.c new file mode 100644 index 0000000..c5e7195 --- /dev/null +++ b/src/libtipidee/tipidee_method.c @@ -0,0 +1,46 @@ +/* ISC license. */ + +#include <string.h> +#include <stdlib.h> + +#include <tipidee/method.h> + +struct blah_s +{ + tipidee_method num ; + char const *str ; +} ; + +static struct blah_s const table[] = +{ + { .num = TIPIDEE_METHOD_CONNECT, .str = "CONNECT" }, + { .num = TIPIDEE_METHOD_DELETE, .str = "DELETE" }, + { .num = TIPIDEE_METHOD_GET, .str = "GET" }, + { .num = TIPIDEE_METHOD_HEAD, .str = "HEAD" }, + { .num = TIPIDEE_METHOD_OPTIONS, .str = "OPTIONS" }, + { .num = TIPIDEE_METHOD_POST, .str = "POST" }, + { .num = TIPIDEE_METHOD_PRI, .str = "PRI" }, + { .num = TIPIDEE_METHOD_PUT, .str = "PUT" }, + { .num = TIPIDEE_METHOD_TRACE, .str = "TRACE" }, +} ; + +static int blah_cmp (void const *key, void const *el) +{ + return strcmp((char const *)key, ((struct blah_s const *)el)->str) ; +} + +tipidee_method tipidee_method_tonum (char const *s) +{ + struct blah_s const *p = bsearch( + s, + table, + sizeof(table) / sizeof(struct blah_s), + sizeof(struct blah_s), + &blah_cmp) ; + return p ? p->num : TIPIDEE_METHOD_UNKNOWN ; +} + +char const *tipidee_method_tostr (tipidee_method m) +{ + return m < TIPIDEE_METHOD_UNKNOWN ? table[m].str : 0 ; +} diff --git a/src/libtipidee/tipidee_method_conv_table.c b/src/libtipidee/tipidee_method_conv_table.c deleted file mode 100644 index 892e5b5..0000000 --- a/src/libtipidee/tipidee_method_conv_table.c +++ /dev/null @@ -1,19 +0,0 @@ -/* ISC license. */ - -#include <tipidee/method.h> - -static tipidee_method_conv const table[] = -{ - { .num = TIPIDEE_METHOD_GET, .str = "GET" }, - { .num = TIPIDEE_METHOD_HEAD, .str = "HEAD" }, - { .num = TIPIDEE_METHOD_OPTIONS, .str = "OPTIONS" }, - { .num = TIPIDEE_METHOD_POST, .str = "POST" }, - { .num = TIPIDEE_METHOD_PUT, .str = "PUT" }, - { .num = TIPIDEE_METHOD_DELETE, .str = "DELETE" }, - { .num = TIPIDEE_METHOD_TRACE, .str = "TRACE" }, - { .num = TIPIDEE_METHOD_CONNECT, .str = "CONNECT" }, - { .num = TIPIDEE_METHOD_PRI, .str = "PRI" }, - { .num = TIPIDEE_METHOD_UNKNOWN, .str = 0 } -} ; - -tipidee_method_conv const *tipidee_method_conv_table = table ; diff --git a/src/libtipidee/tipidee_method_tonum.c b/src/libtipidee/tipidee_method_tonum.c deleted file mode 100644 index 7c88e45..0000000 --- a/src/libtipidee/tipidee_method_tonum.c +++ /dev/null @@ -1,12 +0,0 @@ -/* ISC license. */ - -#include <string.h> - -#include <tipidee/method.h> - -tipidee_method tipidee_method_tonum (char const *s) -{ - tipidee_method_conv const *p = tipidee_method_conv_table ; - for (; p->str ; p++) if (!strcmp(s, p->str)) break ; - return p->num ; -} diff --git a/src/libtipidee/tipidee_method_tostr.c b/src/libtipidee/tipidee_method_tostr.c deleted file mode 100644 index 8a3831d..0000000 --- a/src/libtipidee/tipidee_method_tostr.c +++ /dev/null @@ -1,8 +0,0 @@ -/* ISC license. */ - -#include <tipidee/method.h> - -char const *tipidee_method_tostr (tipidee_method m) -{ - return m < TIPIDEE_METHOD_UNKNOWN ? tipidee_method_conv_table[m].str : 0 ; -} |