aboutsummaryrefslogtreecommitdiffstats
path: root/src/libtipidee/tipidee_method.c
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2023-10-10 08:06:46 +0000
committerLaurent Bercot <ska@appnovation.com>2023-10-10 08:06:46 +0000
commit541325d00c7078d063ea97333d3c9c64d6b6c7b6 (patch)
tree86453b9f547359546d74988b04ab33ec10b4000c /src/libtipidee/tipidee_method.c
parentd9f5cb7a28ee79e299e41d3ce325171f01e1a3d7 (diff)
downloadtipidee-541325d00c7078d063ea97333d3c9c64d6b6c7b6.tar.gz
Add new logging functions, change method_conv for bsearch
Signed-off-by: Laurent Bercot <ska@appnovation.com>
Diffstat (limited to 'src/libtipidee/tipidee_method.c')
-rw-r--r--src/libtipidee/tipidee_method.c46
1 files changed, 46 insertions, 0 deletions
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 ;
+}