From 9315bbfd0f9e51da5438d29681cab6f9a6533d89 Mon Sep 17 00:00:00 2001 From: Paul Duncan Date: Sun, 28 Aug 2016 00:30:02 -0400 Subject: split up fhp.c --- token.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 token.c (limited to 'token.c') 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 +#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; +} -- cgit v1.2.3