diff options
Diffstat (limited to 'token.c')
-rw-r--r-- | token.c | 65 |
1 files changed, 65 insertions, 0 deletions
@@ -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; +} |