From 907004a179d476481da9f613cccdabb5cca306ac Mon Sep 17 00:00:00 2001 From: Paul Duncan Date: Fri, 26 Aug 2016 21:50:23 -0400 Subject: add fhp_strtoken() --- fhp.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'fhp.c') diff --git a/fhp.c b/fhp.c index da48f0a..237345b 100644 --- a/fhp.c +++ b/fhp.c @@ -131,6 +131,53 @@ fhp_strerror( return FHP_OK; } +static const char * +fhp_tokens[] = { + "METHOD_START", + "METHOD_FRAGMENT", + "METHOD_END", + + "URL_START", + "URL_FRAGMENT", + "URL_END", + + "VERSION_START", + "VERSION_FRAGMENT", + "VERSION_END", + + "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; +} + static fhp_t DEFAULT_CONTEXT = { .state = FHP_STATE_INIT, .user_data = NULL, -- cgit v1.2.3