rest: should force the body type to plain, so it passes other validation checks
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Mon, 24 Mar 2014 14:42:09 +0000 (14:42 +0000)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Mon, 24 Mar 2014 14:42:46 +0000 (14:42 +0000)
src/modules/rlm_rest/rest.c
src/modules/rlm_rest/rest.h
src/modules/rlm_rest/rlm_rest.c

index 3a8faec..581e9b0 100644 (file)
@@ -1561,7 +1561,14 @@ static size_t rest_response_body(void *ptr, size_t size, size_t nmemb, void *use
        /*
         *  Figure out if the type is supported by one of the decoders.
         */
-       switch (http_body_type_supported[ctx->type]) {
+       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>"));
@@ -1731,6 +1738,11 @@ static int rest_request_config_body(UNUSED rlm_rest_t *instance, rlm_rest_sectio
        }
 
        /*
+        *  Force parsing the body text as a particular encoding.
+        */
+       ctx->response.force_to = section->force_to;
+
+       /*
         *  If were not doing chunked encoding then we read the entire
         *  body into a buffer, and send it in one go.
         */
index 200286e..6009bc3 100644 (file)
@@ -110,6 +110,7 @@ typedef struct rlm_rest_section_t {
 
        char *body_str;
        http_body_type_t body;
+       http_body_type_t force_to;
 
        char *username;
        char *password;
@@ -195,6 +196,7 @@ typedef struct rlm_rest_response_t {
 
        int                     code;           //!< HTTP Status Code.
        http_body_type_t        type;           //!< HTTP Content Type.
+       http_body_type_t        force_to;       //!< Force decoding the body type as a particular encoding.
 } rlm_rest_response_t;
 
 /*
index cf632c1..8e0884e 100644 (file)
@@ -152,7 +152,8 @@ static ssize_t rest_xlat(void *instance, REQUEST *request,
                .method = HTTP_METHOD_GET,
                .body = HTTP_BODY_PLAIN,
                .require_auth = false,
-               .timeout = 4
+               .timeout = 4,
+               .force_to = HTTP_BODY_PLAIN
        };
 
        *out = '\0';