diff options
author | Paul Duncan <pabs@pablotron.org> | 2016-08-28 15:39:26 -0400 |
---|---|---|
committer | Paul Duncan <pabs@pablotron.org> | 2016-08-28 15:39:26 -0400 |
commit | 566fd0d75c4a46b8a69f67a75ecfb704e985db01 (patch) | |
tree | 7ed0c437c15275c03419314092104a52409c1e1e | |
parent | b477f7b16f4b7a08d6eaf7f2b6093f14a13123ea (diff) | |
download | libfhp-566fd0d75c4a46b8a69f67a75ecfb704e985db01.tar.bz2 libfhp-566fd0d75c4a46b8a69f67a75ecfb704e985db01.zip |
refactor ctx.c
-rw-r--r-- | ctx.c | 43 |
1 files changed, 25 insertions, 18 deletions
@@ -25,8 +25,8 @@ fhp_ctx_buf_flush( ctx->buf_hash = fhp_lc_hash_push(ctx->buf_hash, ctx->buf, ctx->buf_len); // push to header value parser - fhp_err_t err; - if ((err = fhp_header_value_parser_push(ctx, ctx->buf, ctx->buf_len)) != FHP_OK) + fhp_err_t err = fhp_header_value_parser_push(ctx, ctx->buf, ctx->buf_len); + if (err != FHP_OK) return err; // clear buffer @@ -64,24 +64,31 @@ fhp_ctx_buf_push( static fhp_err_t fhp_ctx_handle_method(fhp_ctx_t * const ctx) { + uint32_t hash = ctx->buf_hash; + fhp_token_t method = FHP_TOKEN_METHOD_OTHER; + // get method token - ctx->http_method = FHP_TOKEN_METHOD_OTHER; - if (ctx->buf_hash == ctx->env->hashes[FHP_STR_GET]) { - ctx->http_method = FHP_TOKEN_METHOD_GET; - } else if (ctx->buf_hash == ctx->env->hashes[FHP_STR_POST]) { - ctx->http_method = FHP_TOKEN_METHOD_POST; - } else if (ctx->buf_hash == ctx->env->hashes[FHP_STR_HEAD]) { - ctx->http_method = FHP_TOKEN_METHOD_HEAD; - } else if (ctx->buf_hash == ctx->env->hashes[FHP_STR_PUT]) { - ctx->http_method = FHP_TOKEN_METHOD_PUT; - } else if (ctx->buf_hash == ctx->env->hashes[FHP_STR_DELETE]) { - ctx->http_method = FHP_TOKEN_METHOD_DELETE; - } else if (ctx->buf_hash == ctx->env->hashes[FHP_STR_OPTIONS]) { - ctx->http_method = FHP_TOKEN_METHOD_OPTIONS; + if (hash == ctx->env->hashes[FHP_STR_GET]) { + method = FHP_TOKEN_METHOD_GET; + } else if (hash == ctx->env->hashes[FHP_STR_POST]) { + method = FHP_TOKEN_METHOD_POST; + } else if (hash == ctx->env->hashes[FHP_STR_HEAD]) { + method = FHP_TOKEN_METHOD_HEAD; + } else if (hash == ctx->env->hashes[FHP_STR_PUT]) { + method = FHP_TOKEN_METHOD_PUT; + } else if (hash == ctx->env->hashes[FHP_STR_DELETE]) { + method = FHP_TOKEN_METHOD_DELETE; + } else if (hash == ctx->env->hashes[FHP_STR_OPTIONS]) { + method = FHP_TOKEN_METHOD_OPTIONS; + } else { + method = FHP_TOKEN_METHOD_OTHER; } + // set method token + ctx->http_method = method; + // send method token - if (!ctx->cb(ctx, ctx->http_method, 0, 0)) + if (!ctx->cb(ctx, method, 0, 0)) return FHP_ERR_CB; // return success @@ -92,7 +99,7 @@ fhp_ctx_handle_method(fhp_ctx_t * const ctx) { // context functions // -static const fhp_ctx_t FHP_DEFAULT_CONTEXT = { +static const fhp_ctx_t FHP_CTX_DEFAULT = { .state = FHP_STATE_INIT, .user_data = NULL, .cb = NULL, @@ -114,7 +121,7 @@ fhp_ctx_init( fhp_cb_t cb, void * const user_data ) { - *ctx = FHP_DEFAULT_CONTEXT; + *ctx = FHP_CTX_DEFAULT; ctx->env = env ? env : fhp_get_default_env(); ctx->user_data = user_data; ctx->cb = cb; |