Skip to content

Commit

Permalink
Move body type function back to header parser (Gets called fewer times)
Browse files Browse the repository at this point in the history
  • Loading branch information
arr2036 committed Mar 24, 2014
1 parent 10f6f54 commit 1cc80cd
Showing 1 changed file with 38 additions and 37 deletions.
75 changes: 38 additions & 37 deletions src/modules/rlm_rest/rest.c
Expand Up @@ -45,7 +45,7 @@ RCSID("$Id$")
* @see http_body_type_t
*/
const http_body_type_t http_body_type_supported[HTTP_BODY_NUM_ENTRIES] = {
HTTP_BODY_UNSUPPORTED, // HTTP_BODY_UNKOWN
HTTP_BODY_UNKNOWN, // HTTP_BODY_UNKOWN
HTTP_BODY_UNSUPPORTED, // HTTP_BODY_UNSUPPORTED
HTTP_BODY_UNSUPPORTED, // HTTP_BODY_UNAVAILABLE
HTTP_BODY_UNSUPPORTED, // HTTP_BODY_INVALID
Expand Down Expand Up @@ -1490,11 +1490,46 @@ static size_t rest_response_header(void *in, size_t size, size_t nmemb, void *us
RDEBUG2("\tType : %s (%.*s)", fr_int2str(http_body_type_table, type, "<INVALID>"),
(int) len, p);

if (type == HTTP_BODY_UNKNOWN) {
/*
* Figure out if the type is supported by one of the decoders.
*/
if (ctx->force_to != HTTP_BODY_UNKNOWN) {
if (ctx->force_to != ctx->type) {
RDEBUG3("Forcing body type to \"%s\"",
fr_int2str(http_body_type_table, ctx->force_to, "<INVALID>"));
ctx->type = ctx->force_to;
}
/*
* Assume the force_to value has already been validation.
*/
} else switch (http_body_type_supported[ctx->type]) {
case HTTP_BODY_UNKNOWN:
RWDEBUG("Couldn't determine type, using the request's type \"%s\".",
fr_int2str(http_body_type_table, ctx->type, "<INVALID>"));
} else {
break;

case HTTP_BODY_UNSUPPORTED:
REDEBUG("Type \"%s\" is currently unsupported",
fr_int2str(http_body_type_table, ctx->type, "<INVALID>"));
ctx->type = HTTP_BODY_UNSUPPORTED;
break;

case HTTP_BODY_UNAVAILABLE:
REDEBUG("Type \"%s\" is unavailable, please rebuild this module with the required "
"library", fr_int2str(http_body_type_table, ctx->type, "<INVALID>"));
ctx->type = HTTP_BODY_UNAVAILABLE;
break;

case HTTP_BODY_INVALID:
REDEBUG("Type \"%s\" is not a valid web API data markup format",
fr_int2str(http_body_type_table, ctx->type, "<INVALID>"));
ctx->type = HTTP_BODY_INVALID;
break;

/* supported type */
default:
ctx->type = type;
break;
}
}
break;
Expand Down Expand Up @@ -1558,40 +1593,6 @@ static size_t rest_response_body(void *ptr, size_t size, size_t nmemb, void *use
ctx->state = WRITE_STATE_PARSE_CONTENT;
}

/*
* Figure out if the type is supported by one of the decoders.
*/
if (ctx->force_to != HTTP_BODY_UNKNOWN) {
RDEBUG3("Forcing body type to \"%s\"",
fr_int2str(http_body_type_table, ctx->force_to, "<INVALID>"));
ctx->type = ctx->force_to;
/*
* Assume the force_to value has already been validation.
*/
} else switch (http_body_type_supported[ctx->type]) {
case HTTP_BODY_UNSUPPORTED:
REDEBUG("Type \"%s\" is currently unsupported",
fr_int2str(http_body_type_table, ctx->type, "<INVALID>"));
ctx->type = HTTP_BODY_UNSUPPORTED;
break;

case HTTP_BODY_UNAVAILABLE:
REDEBUG("Type \"%s\" is unavailable, please rebuild this module with the required "
"library", fr_int2str(http_body_type_table, ctx->type, "<INVALID>"));
ctx->type = HTTP_BODY_UNAVAILABLE;
break;

case HTTP_BODY_INVALID:
REDEBUG("Type \"%s\" is not a valid web API data markup format",
fr_int2str(http_body_type_table, ctx->type, "<INVALID>"));
ctx->type = HTTP_BODY_INVALID;
break;

/* supported type */
default:
break;
}

switch (ctx->type) {
case HTTP_BODY_UNSUPPORTED:
case HTTP_BODY_UNAVAILABLE:
Expand Down

0 comments on commit 1cc80cd

Please sign in to comment.