summaryrefslogtreecommitdiff
path: root/token.c
diff options
context:
space:
mode:
authorPaul Duncan <pabs@pablotron.org>2016-08-28 00:30:02 -0400
committerPaul Duncan <pabs@pablotron.org>2016-08-28 00:30:02 -0400
commit9315bbfd0f9e51da5438d29681cab6f9a6533d89 (patch)
treef02b70f56196e57be7086333b321e9cf012ac9ef /token.c
parent1bc717dc54b9964e7c62082b34d2d74e3daaa6a6 (diff)
downloadlibfhp-9315bbfd0f9e51da5438d29681cab6f9a6533d89.tar.bz2
libfhp-9315bbfd0f9e51da5438d29681cab6f9a6533d89.zip
split up fhp.c
Diffstat (limited to 'token.c')
-rw-r--r--token.c65
1 files changed, 65 insertions, 0 deletions
diff --git a/token.c b/token.c
new file mode 100644
index 0000000..d32c952
--- /dev/null
+++ b/token.c
@@ -0,0 +1,65 @@
+#include <string.h>
+#include "fhp/fhp.h"
+
+//
+// token functions
+//
+
+static const char *
+fhp_tokens[] = {
+ "METHOD_START",
+ "METHOD_FRAGMENT",
+ "METHOD_END",
+
+ "METHOD_GET",
+ "METHOD_POST",
+ "METHOD_HEAD",
+ "METHOD_PUT",
+ "METHOD_DELETE",
+ "METHOD_OPTIONS",
+ "METHOD_OTHER",
+
+ "URL_START",
+ "URL_FRAGMENT",
+ "URL_END",
+
+ "VERSION_START",
+ "VERSION_FRAGMENT",
+ "VERSION_END",
+
+ "VERSION_HTTP_10",
+ "VERSION_HTTP_11",
+ "VERSION_OTHER",
+
+ "HEADER_NAME_START",
+ "HEADER_NAME_FRAGMENT",
+ "HEADER_NAME_END",
+
+ "HEADER_VALUE_START",
+ "HEADER_VALUE_FRAGMENT",
+ "HEADER_VALUE_END",
+
+ "LAST"
+};
+
+fhp_err_t
+fhp_strtoken(
+ fhp_token_t token,
+ char * const buf,
+ size_t len
+) {
+ // check token code
+ if (token >= FHP_TOKEN_LAST)
+ return FHP_ERR_INVALID_ERROR;
+
+ // check buffer size
+ size_t str_len = strlen(fhp_tokens[token]) + 1;
+ if (len < str_len)
+ return FHP_ERR_BUFFER_TOO_SMALL;
+
+ // copy string
+ memcpy(buf, fhp_tokens[token], str_len);
+
+ // return success
+ return FHP_OK;
+}