diff options
author | Paul Duncan <pabs@pablotron.org> | 2016-08-26 21:50:23 -0400 |
---|---|---|
committer | Paul Duncan <pabs@pablotron.org> | 2016-08-26 21:50:23 -0400 |
commit | 907004a179d476481da9f613cccdabb5cca306ac (patch) | |
tree | e336839af11a405be739f1a21a260a4d09b81a80 /fhp.c | |
parent | 0f8623056efdc7a5fe4b02a0b819b920703c5460 (diff) | |
download | libfhp-907004a179d476481da9f613cccdabb5cca306ac.tar.bz2 libfhp-907004a179d476481da9f613cccdabb5cca306ac.zip |
add fhp_strtoken()
Diffstat (limited to 'fhp.c')
-rw-r--r-- | fhp.c | 47 |
1 files changed, 47 insertions, 0 deletions
@@ -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, |