The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Data Structures | Macros | Functions | Variables
rest.c File Reference

Functions and datatypes for the REST (HTTP) transport. More...

#include <ctype.h>
#include <string.h>
#include <time.h>
#include <freeradius-devel/server/base.h>
#include <freeradius-devel/server/log.h>
#include <freeradius-devel/server/pool.h>
#include <freeradius-devel/server/tmpl.h>
#include <freeradius-devel/unlang/call.h>
#include <freeradius-devel/util/value.h>
#include <talloc.h>
#include "rest.h"
+ Include dependency graph for rest.c:

Go to the source code of this file.

Data Structures

struct  json_flags_t
 Flags to control the conversion of JSON values to fr_pair_ts. More...
 
struct  rest_custom_data_t
 

Macros

#define CURLAUTH_BASIC   0
 
#define CURLAUTH_DIGEST   0
 
#define CURLAUTH_DIGEST_IE   0
 
#define CURLAUTH_GSSNEGOTIATE   0
 
#define CURLAUTH_NTLM   0
 
#define CURLAUTH_NTLM_WB   0
 
#define CURLOPT_TLSAUTH_SRP   0
 
#define LOG_PREFIX   mctx->mi->name
 
#define SET_AUTH_OPTION(_x, _y)
 

Functions

static int _mod_conn_free (fr_curl_io_request_t *randle)
 Frees a libcurl handle, and any additional memory used by context data. More...
 
static int json_pair_alloc (rlm_rest_t const *instance, rlm_rest_section_t const *section, request_t *request, json_object *object, UNUSED int level, int max)
 Processes JSON response and converts it into multiple fr_pair_ts. More...
 
static fr_pair_tjson_pair_alloc_leaf (UNUSED rlm_rest_t const *instance, UNUSED rlm_rest_section_t const *section, TALLOC_CTX *ctx, request_t *request, fr_dict_attr_t const *da, json_flags_t *flags, json_object *leaf)
 Converts JSON "value" key into fr_pair_t. More...
 
static int rest_decode_json (rlm_rest_t const *instance, rlm_rest_section_t const *section, request_t *request, UNUSED fr_curl_io_request_t *randle, char *raw, UNUSED size_t rawlen)
 Converts JSON response into fr_pair_ts and adds them to the request. More...
 
static int rest_decode_plain (UNUSED rlm_rest_t const *inst, UNUSED rlm_rest_section_t const *section, request_t *request, UNUSED fr_curl_io_request_t *randle, char *raw, size_t rawlen)
 Converts plain response into a single fr_pair_t. More...
 
static int rest_decode_post (UNUSED rlm_rest_t const *instance, UNUSED rlm_rest_section_t const *section, request_t *request, fr_curl_io_request_t *randle, char *raw, size_t rawlen)
 Converts POST response into fr_pair_ts and adds them to the request. More...
 
static size_t rest_encode_custom (void *out, size_t size, size_t nmemb, void *userdata)
 Copies a pre-expanded xlat string to the output buffer. More...
 
static size_t rest_encode_json (void *out, size_t size, size_t nmemb, void *userdata)
 Encodes fr_pair_t linked list in JSON format. More...
 
static size_t rest_encode_post (void *out, size_t size, size_t nmemb, void *userdata)
 Encodes fr_pair_t linked list in POST format. More...
 
size_t rest_get_handle_data (char const **out, fr_curl_io_request_t *randle)
 Extracts pointer to buffer containing response data. More...
 
void * rest_mod_conn_create (TALLOC_CTX *ctx, void *instance, UNUSED fr_time_delta_t timeout)
 Creates a new connection handle for use by the FR connection API. More...
 
int rest_request_config (module_ctx_t const *mctx, rlm_rest_section_t const *section, request_t *request, fr_curl_io_request_t *randle, http_method_t method, http_body_type_t type, char const *uri, char const *body_data)
 Configures request curlopts. More...
 
static int rest_request_config_body (module_ctx_t const *mctx, rlm_rest_section_t const *section, request_t *request, fr_curl_io_request_t *randle, rest_read_t func)
 Configures body specific curlopts. More...
 
static ssize_t rest_request_encode_wrapper (char **out, UNUSED rlm_rest_t const *inst, rest_read_t func, size_t limit, void *userdata)
 Emulates successive libcurl calls to an encoding function. More...
 
static void rest_request_init (rlm_rest_section_t const *section, request_t *request, rlm_rest_request_t *ctx)
 (Re-)Initialises the data in a rlm_rest_request_t. More...
 
static size_t rest_response_body (void *in, size_t size, size_t nmemb, void *userdata)
 Processes incoming HTTP body data from libcurl. More...
 
void rest_response_debug (request_t *request, fr_curl_io_request_t *handle)
 Print out the response text. More...
 
int rest_response_decode (rlm_rest_t const *instance, rlm_rest_section_t const *section, request_t *request, fr_curl_io_request_t *randle)
 Sends the response to the correct decode function. More...
 
void rest_response_error (request_t *request, fr_curl_io_request_t *handle)
 Print out the response text as error lines. More...
 
static size_t rest_response_header (void *in, size_t size, size_t nmemb, void *userdata)
 Processes incoming HTTP header data from libcurl. More...
 
static void rest_response_init (rlm_rest_section_t const *section, request_t *request, rlm_rest_response_t *ctx, http_body_type_t type, tmpl_t *header)
 (Re-)Initialises the data in a rlm_rest_response_t. More...
 
size_t rest_uri_escape (UNUSED request_t *request, char *out, size_t outlen, char const *raw, UNUSED void *arg)
 URL encodes a string. More...
 
ssize_t rest_uri_host_unescape (char **out, UNUSED rlm_rest_t const *inst, request_t *request, fr_curl_io_request_t *randle, char const *uri)
 Unescapes the host portion of a URI string. More...
 

Variables

fr_table_num_sorted_t const http_auth_table []
 
size_t http_auth_table_len = NUM_ELEMENTS(http_auth_table)
 
const http_body_type_t http_body_type_supported [REST_HTTP_BODY_NUM_ENTRIES]
 Table of encoder/decoder support. More...
 
fr_table_num_sorted_t const http_body_type_table []
 Conversion table for type config values. More...
 
size_t http_body_type_table_len = NUM_ELEMENTS(http_body_type_table)
 
fr_table_num_sorted_t const http_content_type_table []
 Conversion table for "Content-Type" header values. More...
 
size_t http_content_type_table_len = NUM_ELEMENTS(http_content_type_table)
 
const unsigned long http_curl_auth [REST_HTTP_AUTH_NUM_ENTRIES]
 
fr_table_num_sorted_t const http_method_table []
 Conversion table for method config values. More...
 
size_t http_method_table_len = NUM_ELEMENTS(http_method_table)
 

Detailed Description

Functions and datatypes for the REST (HTTP) transport.

Id
5c9c465279d6eeb72570015af474c95d3f74a915

Definition in file rest.c.


Data Structure Documentation

◆ json_flags_t

struct json_flags_t

Flags to control the conversion of JSON values to fr_pair_ts.

These fields are set when parsing the expanded format for value pairs in JSON, and control how json_pair_alloc_leaf and json_pair_alloc convert the JSON value, and move the new fr_pair_t into an attribute list.

See also
json_pair_alloc
json_pair_alloc_leaf

Definition at line 221 of file rest.c.

Data Fields
int do_xlat If true value will be expanded with xlat.
int is_json If true value will be inserted as raw JSON.
fr_token_t op The operator that determines how the new VP.

◆ rest_custom_data_t

struct rest_custom_data_t

Definition at line 205 of file rest.c.

Data Fields
size_t len Length of data.
char const * p how much text we've sent so far.
char const * start Start of the buffer.

Macro Definition Documentation

◆ CURLAUTH_BASIC

#define CURLAUTH_BASIC   0

Definition at line 77 of file rest.c.

◆ CURLAUTH_DIGEST

#define CURLAUTH_DIGEST   0

Definition at line 80 of file rest.c.

◆ CURLAUTH_DIGEST_IE

#define CURLAUTH_DIGEST_IE   0

Definition at line 83 of file rest.c.

◆ CURLAUTH_GSSNEGOTIATE

#define CURLAUTH_GSSNEGOTIATE   0

Definition at line 86 of file rest.c.

◆ CURLAUTH_NTLM

#define CURLAUTH_NTLM   0

Definition at line 89 of file rest.c.

◆ CURLAUTH_NTLM_WB

#define CURLAUTH_NTLM_WB   0

Definition at line 92 of file rest.c.

◆ CURLOPT_TLSAUTH_SRP

#define CURLOPT_TLSAUTH_SRP   0

Definition at line 74 of file rest.c.

◆ LOG_PREFIX

#define LOG_PREFIX   mctx->mi->name

Definition at line 27 of file rest.c.

◆ SET_AUTH_OPTION

#define SET_AUTH_OPTION (   _x,
  _y 
)
Value:
do {\
if ((ret = curl_easy_setopt(candle, _x, _y)) != CURLE_OK) {\
option = STRINGIFY(_x);\
REDEBUG("Failed setting curl option %s: %s (%i)", option, curl_easy_strerror(ret), ret); \
goto error;\
}\
} while (0)
#define STRINGIFY(x)
Definition: build.h:195

Function Documentation

◆ _mod_conn_free()

static int _mod_conn_free ( fr_curl_io_request_t randle)
static

Frees a libcurl handle, and any additional memory used by context data.

Parameters
[in]randlefr_curl_io_request_t to close and free.
Returns
returns true.

Definition at line 235 of file rest.c.

+ Here is the caller graph for this function:

◆ json_pair_alloc()

static int json_pair_alloc ( rlm_rest_t const *  instance,
rlm_rest_section_t const *  section,
request_t request,
json_object *  object,
UNUSED int  level,
int  max 
)
static

Processes JSON response and converts it into multiple fr_pair_ts.

Processes JSON attribute declarations in the format below. Will recurse when processing nested attributes. When processing nested attributes flags and operators from previous attributes are not inherited.

JSON response format is:

{
        "<attribute0>":{
                "do_xlat":<bool>,
                "is_json":<bool>,
                "op":"<operator>",
                "value":[<value0>,<value1>,<valueN>]
        },
        "<attribute1>":{
                "value":{
                        "<nested-attribute0>":{
                                "op":"<operator>",
                                "value":<value0>
                        }
                }
        },
        "<attribute2>":"<value0>",
        "<attributeN>":[<value0>,<value1>,<valueN>]
}

JSON valuepair flags:

  • do_xlat (optional) Controls xlat expansion of values. Defaults to true.
  • is_json (optional) If true, any nested JSON data will be copied to the fr_pair_t in string form. Defaults to true.
  • op (optional) Controls how the attribute is inserted into the target list. Defaults to ':=' (T_OP_SET).

If "op" is ':=' or '=', it will be automagically changed to '+=' for the second and subsequent values in multivalued attributes. This does not work between multiple attribute declarations.

See also
fr_tokens_table
Parameters
[in]instanceconfiguration data.
[in]sectionconfiguration data.
[in]requestCurrent request.
[in]objectcontaining root node, or parent node.
[in]levelCurrent nesting level.
[in]maxcounter, decremented after each fr_pair_t is created, when 0 no more attributes will be processed.
Returns
  • Number of attributes created.
  • < 0 on error.

Definition at line 982 of file rest.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ json_pair_alloc_leaf()

static fr_pair_t* json_pair_alloc_leaf ( UNUSED rlm_rest_t const *  instance,
UNUSED rlm_rest_section_t const *  section,
TALLOC_CTX *  ctx,
request_t request,
fr_dict_attr_t const *  da,
json_flags_t flags,
json_object *  leaf 
)
static

Converts JSON "value" key into fr_pair_t.

If leaf is not in fact a leaf node, but contains JSON data, the data will written to the attribute in JSON string format.

Parameters
[in]instanceconfiguration data.
[in]sectionconfiguration data.
[in]ctxto allocate new fr_pair_ts in.
[in]requestCurrent request.
[in]daAttribute to create.
[in]flagscontaining the operator other flags controlling value expansion.
[in]leafobject containing the fr_pair_t value.
Returns

Definition at line 846 of file rest.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ rest_decode_json()

static int rest_decode_json ( rlm_rest_t const *  instance,
rlm_rest_section_t const *  section,
request_t request,
UNUSED fr_curl_io_request_t randle,
char *  raw,
UNUSED size_t  rawlen 
)
static

Converts JSON response into fr_pair_ts and adds them to the request.

Converts the raw JSON string into a json-c object tree and passes it to json_pair_alloc. After the tree has been parsed json_object_put is called which decrements the reference count of the root node by one, and frees the entire tree.

See also
rest_encode_json
json_pair_alloc
Parameters
[in]instanceconfiguration data.
[in]sectionconfiguration data.
[in,out]requestCurrent request.
[in]randleREST handle.
[in]rawbuffer containing JSON data.
[in]rawlenLength of data in raw buffer.
Returns
  • The number of fr_pair_t processed.
  • -1 on unrecoverable error.

Definition at line 1197 of file rest.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ rest_decode_plain()

static int rest_decode_plain ( UNUSED rlm_rest_t const *  inst,
UNUSED rlm_rest_section_t const *  section,
request_t request,
UNUSED fr_curl_io_request_t randle,
char *  raw,
size_t  rawlen 
)
static

Converts plain response into a single fr_pair_t.

Parameters
[in]instconfiguration data.
[in]sectionconfiguration data.
[in]randlefr_curl_io_request_t to use.
[in]requestCurrent request.
[in]rawbuffer containing POST data.
[in]rawlenLength of data in raw buffer.
Returns
  • Number of fr_pair_t processed.
  • -1 on unrecoverable error.

Definition at line 649 of file rest.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ rest_decode_post()

static int rest_decode_post ( UNUSED rlm_rest_t const *  instance,
UNUSED rlm_rest_section_t const *  section,
request_t request,
fr_curl_io_request_t randle,
char *  raw,
size_t  rawlen 
)
static

Converts POST response into fr_pair_ts and adds them to the request.

Accepts fr_pair_tS in the same format as rest_encode_post, but with the addition of optional attribute list qualifiers as part of the attribute name string.

If no qualifiers are specified, will default to the request list.

POST response format is:

[outer.][<list>.]<attribute0>=<value0>&[outer.][<list>.]<attribute1>=<value1>&[outer.][<list>.]<attributeN>=<valueN> 
See also
rest_encode_post
Parameters
[in]instanceconfiguration data.
[in]sectionconfiguration data.
[in]randlefr_curl_io_request_t to use.
[in]requestCurrent request.
[in]rawbuffer containing POST data.
[in]rawlenLength of data in raw buffer.
Returns
  • Number of fr_pair_ts processed.
  • -1 on unrecoverable error.

Definition at line 693 of file rest.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ rest_encode_custom()

static size_t rest_encode_custom ( void *  out,
size_t  size,
size_t  nmemb,
void *  userdata 
)
static

Copies a pre-expanded xlat string to the output buffer.

Parameters
[out]outChar buffer to write encoded data to.
[in]sizeMultiply by nmemb to get the length of ptr.
[in]nmembMultiply by size to get the length of ptr.
[in]userdatarlm_rest_request_t to keep encoding state between calls.
Returns
  • Length of data (including NULL) written to ptr.
  • 0 if no more data to write.

Definition at line 291 of file rest.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ rest_encode_json()

static size_t rest_encode_json ( void *  out,
size_t  size,
size_t  nmemb,
void *  userdata 
)
static

Encodes fr_pair_t linked list in JSON format.

This is a stream function matching the rest_read_t prototype. Multiple successive calls will return additional encoded fr_pair_ts.

Only complete attribute headers

"<name>":{"type":"<type>","value":[' 

and complete attribute values will be written to ptr.

If an attribute occurs multiple times in the request the attribute values will be concatenated into a single value array.

JSON request format is:

{
        "<attribute0>":{
                "type":"<type0>",
                "value":[<value0>,<value1>,<valueN>]
        },
        "<attribute1>":{
                "type":"<type1>",
                "value":[...]
        },
        "<attributeN>":{
                "type":"<typeN>",
                "value":[...]
        },
}
Parameters
[out]outChar buffer to write encoded data to.
[in]sizeMultiply by nmemb to get the length of ptr.
[in]nmembMultiply by size to get the length of ptr.
[in]userdatarlm_rest_request_t to keep encoding state between calls.
Returns
  • Length of data (including NULL) written to ptr.
  • 0 if no more data to write.

Definition at line 527 of file rest.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ rest_encode_post()

static size_t rest_encode_post ( void *  out,
size_t  size,
size_t  nmemb,
void *  userdata 
)
static

Encodes fr_pair_t linked list in POST format.

This is a stream function matching the rest_read_t prototype. Multiple successive calls will return additional encoded fr_pair_ts. Only complete attribute headers

'<name>=' 

and values will be written to the ptr buffer.

POST request format is:

<attribute0>=<value0>&<attribute1>=<value1>&<attributeN>=<valueN>

All attributes and values are url encoded. There is currently no support for nested attributes, or attribute qualifiers.

Nested attributes may be added in the future using

<attribute-outer>:<attribute-inner>

to denotate nesting.

Requires libcurl for url encoding.

See also
rest_decode_post
Parameters
[out]outChar buffer to write encoded data to.
[in]sizeMultiply by nmemb to get the length of ptr.
[in]nmembMultiply by size to get the length of ptr.
[in]userdatarlm_rest_request_t to keep encoding state between calls.
Returns
  • Length of data (including NULL) written to ptr.
  • 0 if no more data to write.

Definition at line 350 of file rest.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ rest_get_handle_data()

size_t rest_get_handle_data ( char const **  out,
fr_curl_io_request_t randle 
)

Extracts pointer to buffer containing response data.

Parameters
[out]outWhere to write the pointer to the buffer.
[in]randleused for the last request.
Returns
  • 0 if no data i available.
  • > 0 if data is available.

Definition at line 1620 of file rest.c.

+ Here is the caller graph for this function:

◆ rest_mod_conn_create()

void* rest_mod_conn_create ( TALLOC_CTX *  ctx,
void *  instance,
UNUSED fr_time_delta_t  timeout 
)

Creates a new connection handle for use by the FR connection API.

Matches the fr_pool_connection_create_t function prototype, is passed to fr_pool_init, and called when a new connection is required by the connection pool API.

Creates an instances of fr_curl_io_request_t, and rlm_rest_curl_context_t which hold the context data required for generating requests and parsing responses.

See also
fr_pool_init
fr_pool_connection_create_t
connection.c

Definition at line 256 of file rest.c.

+ Here is the call graph for this function:

◆ rest_request_config()

int rest_request_config ( module_ctx_t const *  mctx,
rlm_rest_section_t const *  section,
request_t request,
fr_curl_io_request_t randle,
http_method_t  method,
http_body_type_t  type,
char const *  uri,
char const *  body_data 
)

Configures request curlopts.

Configures libcurl handle setting various curlopts for things like local client time, Content-Type, and other FreeRADIUS custom headers.

Current FreeRADIUS custom headers are:

  • X-FreeRADIUS-Section The module section being processed.
  • X-FreeRADIUS-Server The current virtual server the request_t is passing through.

Sets up callbacks for all response processing (buffers and body data).

Parameters
[in]mctxcall data.
[in]sectionconfiguration data.
[in]randleto configure.
[in]requestCurrent request.
[in]methodto use (HTTP verbs PUT, POST, DELETE etc...).
[in]typeContent-Type for request encoding, also sets the default for decoding.
[in]uribuffer containing the expanded URI to send the request to.
[in]body_data(optional) custom body data. Must persist whilst we're writing data out to the socket. Must be a talloced buffer which is \0 terminated.
Returns
  • 0 on success (all opts configured).
  • -1 on failure.

Definition at line 1721 of file rest.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ rest_request_config_body()

static int rest_request_config_body ( module_ctx_t const *  mctx,
rlm_rest_section_t const *  section,
request_t request,
fr_curl_io_request_t randle,
rest_read_t  func 
)
static

Configures body specific curlopts.

Configures libcurl handle to use either chunked mode, where the request data will be sent using multiple HTTP requests, or contiguous mode where the request data will be sent in a single HTTP request.

Parameters
[in]mctxCall data.
[in]sectionconfiguration data.
[in]requestCurrent request.
[in]randlefr_curl_io_request_t to configure.
[in]functo pass to libcurl for chunked. transfers (NULL if not using chunked mode).
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 1646 of file rest.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ rest_request_encode_wrapper()

static ssize_t rest_request_encode_wrapper ( char **  out,
UNUSED rlm_rest_t const *  inst,
rest_read_t  func,
size_t  limit,
void *  userdata 
)
static

Emulates successive libcurl calls to an encoding function.

This function is used when the request will be sent to the HTTP server as one contiguous entity. A buffer of REST_BODY_ALLOC_CHUNK bytes is allocated and passed to the stream encoding function.

If the stream function does not return 0, a new buffer is allocated which is the size of the previous buffer + REST_BODY_ALLOC_CHUNK bytes, the data from the previous buffer is copied, and freed, and another call is made to the stream function, passing a pointer into the new buffer at the end of the previously written data.

This process continues until the stream function signals (by returning 0) that it has no more data to write.

Parameters
[out]outwhere the pointer to the alloced buffer should be written.
[in]instof rlm_rest.
[in]funcStream function.
[in]limitMaximum buffer size to alloc.
[in]userdatarlm_rest_request_t to keep encoding state between calls to stream function.
Returns
  • Length of the data written to the buffer (excluding NULL).
  • -1 if alloc >= limit.

Definition at line 590 of file rest.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ rest_request_init()

static void rest_request_init ( rlm_rest_section_t const *  section,
request_t request,
rlm_rest_request_t ctx 
)
static

(Re-)Initialises the data in a rlm_rest_request_t.

Resets the values of a rlm_rest_request_t to their defaults.

Parameters
[in]sectionconfiguration data.
[in]requestCurrent request.
[in]ctxto initialise.

Definition at line 626 of file rest.c.

+ Here is the caller graph for this function:

◆ rest_response_body()

static size_t rest_response_body ( void *  in,
size_t  size,
size_t  nmemb,
void *  userdata 
)
static

Processes incoming HTTP body data from libcurl.

Writes incoming body data to an intermediary buffer for later parsing by one of the decode functions.

Parameters
[in]inChar buffer where inbound header data is written
[in]sizeMultiply by nmemb to get the length of ptr.
[in]nmembMultiply by size to get the length of ptr.
[in]userdatarlm_rest_response_t to keep parsing state between calls.
Returns
  • Length of data processed.
  • 0 on error.

Definition at line 1458 of file rest.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ rest_response_debug()

void rest_response_debug ( request_t request,
fr_curl_io_request_t handle 
)

Print out the response text.

Parameters
requestThe Current request.
handlefr_curl_io_request_t used to execute the previous request.

Definition at line 1563 of file rest.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ rest_response_decode()

int rest_response_decode ( rlm_rest_t const *  instance,
rlm_rest_section_t const *  section,
request_t request,
fr_curl_io_request_t randle 
)

Sends the response to the correct decode function.

Uses the Content-Type information written in rest_response_header to determine the correct decode function to use. The decode function will then convert the raw received data into fr_pair_ts.

Parameters
[in]instanceconfiguration data.
[in]sectionconfiguration data.
[in]requestCurrent request.
[in]randleto use.
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 2067 of file rest.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ rest_response_error()

void rest_response_error ( request_t request,
fr_curl_io_request_t handle 
)

Print out the response text as error lines.

Parameters
requestThe Current request.
handlefr_curl_io_request_t used to execute the previous request.

Definition at line 1538 of file rest.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ rest_response_header()

static size_t rest_response_header ( void *  in,
size_t  size,
size_t  nmemb,
void *  userdata 
)
static

Processes incoming HTTP header data from libcurl.

Processes the status line, and Content-Type headers from the incoming HTTP response.

Matches prototype for CURLOPT_HEADERFUNCTION, and will be called directly by libcurl.

Parameters
[in]inChar buffer where inbound header data is written.
[in]sizeMultiply by nmemb to get the length of ptr.
[in]nmembMultiply by size to get the length of ptr.
[in]userdatarlm_rest_response_t to keep parsing state between calls.
Returns
  • Length of data processed.
  • 0 on error.

Definition at line 1245 of file rest.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ rest_response_init()

static void rest_response_init ( rlm_rest_section_t const *  section,
request_t request,
rlm_rest_response_t ctx,
http_body_type_t  type,
tmpl_t header 
)
static

(Re-)Initialises the data in a rlm_rest_response_t.

This resets the values of the a rlm_rest_response_t to their defaults. Must be called between encoding sessions.

See also
rest_response_body
rest_response_header
Parameters
[in]sectionthat created the request.
[in]requestCurrent request.
[in]ctxdata to initialise.
[in]typeDefault http_body_type to use when decoding raw data, may be overwritten by rest_response_header.
[in]headerWhere to write out headers, may be NULL.

Definition at line 1598 of file rest.c.

+ Here is the caller graph for this function:

◆ rest_uri_escape()

size_t rest_uri_escape ( UNUSED request_t request,
char *  out,
size_t  outlen,
char const *  raw,
UNUSED void *  arg 
)

URL encodes a string.

Encode special chars as per RFC 3986 section 4.

Parameters
[in]requestCurrent request.
[out]outWhere to write escaped string.
[in]outlenSize of out buffer.
[in]rawstring to be urlencoded.
[in]argpointer, gives context for escaping.
Returns
length of data written to out (excluding NULL).

Definition at line 2120 of file rest.c.

+ Here is the call graph for this function:

◆ rest_uri_host_unescape()

ssize_t rest_uri_host_unescape ( char **  out,
UNUSED rlm_rest_t const *  inst,
request_t request,
fr_curl_io_request_t randle,
char const *  uri 
)

Unescapes the host portion of a URI string.

This is required because the xlat functions which operate on the input string cannot distinguish between host and path components.

Parameters
[out]outWhere to write the pointer to the new buffer containing the escaped URI.
[in]instof rlm_rest.
[in]requestCurrent request
[in]randleto use.
[in]uriconfiguration data.
Returns
  • Length of data written to buffer (excluding NULL).
  • < 0 if an error occurred.

Definition at line 2146 of file rest.c.

+ Here is the call graph for this function:

Variable Documentation

◆ http_auth_table

fr_table_num_sorted_t const http_auth_table[]
Initial value:
= {
{ L("any"), REST_HTTP_AUTH_ANY },
{ L("basic"), REST_HTTP_AUTH_BASIC },
{ L("digest"), REST_HTTP_AUTH_DIGEST },
{ L("digest-ie"), REST_HTTP_AUTH_DIGEST_IE },
{ L("gss-negotiate"), REST_HTTP_AUTH_GSSNEGOTIATE },
{ L("none"), REST_HTTP_AUTH_NONE },
{ L("ntlm"), REST_HTTP_AUTH_NTLM },
{ L("ntlm-winbind"), REST_HTTP_AUTH_NTLM_WB },
{ L("safe"), REST_HTTP_AUTH_ANY_SAFE },
}
#define L(_str)
Helper for initialising arrays of string literals.
Definition: build.h:207
@ REST_HTTP_AUTH_NTLM_WB
Definition: rest.h:78
@ REST_HTTP_AUTH_BASIC
Definition: rest.h:73
@ REST_HTTP_AUTH_NTLM
Definition: rest.h:77
@ REST_HTTP_AUTH_DIGEST
Definition: rest.h:74
@ REST_HTTP_AUTH_TLS_SRP
Definition: rest.h:72
@ REST_HTTP_AUTH_GSSNEGOTIATE
Definition: rest.h:76
@ REST_HTTP_AUTH_ANY
Definition: rest.h:79
@ REST_HTTP_AUTH_NONE
Definition: rest.h:71
@ REST_HTTP_AUTH_DIGEST_IE
Definition: rest.h:75
@ REST_HTTP_AUTH_ANY_SAFE
Definition: rest.h:80

Definition at line 160 of file rest.c.

◆ http_auth_table_len

size_t http_auth_table_len = NUM_ELEMENTS(http_auth_table)

Definition at line 172 of file rest.c.

◆ http_body_type_supported

const http_body_type_t http_body_type_supported[REST_HTTP_BODY_NUM_ENTRIES]
Initial value:

Table of encoder/decoder support.

Indexes in this table match the http_body_type_t enum, and should be updated if additional enum values are added.

See also
http_body_type_t

Definition at line 51 of file rest.c.

◆ http_body_type_table

fr_table_num_sorted_t const http_body_type_table[]
Initial value:
= {
{ L("html"), REST_HTTP_BODY_HTML },
{ L("invalid"), REST_HTTP_BODY_INVALID },
{ L("json"), REST_HTTP_BODY_JSON },
{ L("none"), REST_HTTP_BODY_NONE },
{ L("plain"), REST_HTTP_BODY_PLAIN },
{ L("post"), REST_HTTP_BODY_POST },
{ L("unavailable"), REST_HTTP_BODY_UNAVAILABLE },
{ L("unknown"), REST_HTTP_BODY_UNKNOWN },
{ L("unsupported"), REST_HTTP_BODY_UNSUPPORTED },
{ L("xml"), REST_HTTP_BODY_XML },
{ L("yaml"), REST_HTTP_BODY_YAML }
}
@ REST_HTTP_BODY_HTML
Definition: rest.h:64
@ REST_HTTP_BODY_XML
Definition: rest.h:62
@ REST_HTTP_BODY_YAML
Definition: rest.h:63
@ REST_HTTP_BODY_UNAVAILABLE
Definition: rest.h:56

Conversion table for type config values.

Textual names for http_body_type_t enum values, used by the configuration parser.

See also
http_body_Type_t
fr_table_value_by_str
fr_table_str_by_value

Definition at line 145 of file rest.c.

◆ http_body_type_table_len

size_t http_body_type_table_len = NUM_ELEMENTS(http_body_type_table)

Definition at line 158 of file rest.c.

◆ http_content_type_table

fr_table_num_sorted_t const http_content_type_table[]
Initial value:
= {
{ L("application/json"), REST_HTTP_BODY_JSON },
{ L("application/x-www-form-urlencoded"), REST_HTTP_BODY_POST },
{ L("application/x-yaml"), REST_HTTP_BODY_YAML },
{ L("application/yaml"), REST_HTTP_BODY_YAML },
{ L("text/html"), REST_HTTP_BODY_HTML },
{ L("text/plain"), REST_HTTP_BODY_PLAIN },
{ L("text/x-yaml"), REST_HTTP_BODY_YAML },
{ L("text/xml"), REST_HTTP_BODY_XML },
{ L("text/yaml"), REST_HTTP_BODY_YAML }
}

Conversion table for "Content-Type" header values.

Used by rest_response_header for parsing incoming headers.

Values we expect to see in the 'Content-Type:' header of the incoming response.

Some data types (like YAML) do no have standard MIME types defined, so multiple types, are listed here.

See also
http_body_Type_t
fr_table_value_by_str
fr_table_str_by_value

Definition at line 188 of file rest.c.

◆ http_content_type_table_len

size_t http_content_type_table_len = NUM_ELEMENTS(http_content_type_table)

Definition at line 199 of file rest.c.

◆ http_curl_auth

const unsigned long http_curl_auth[REST_HTTP_AUTH_NUM_ENTRIES]
Initial value:
= {
[REST_HTTP_AUTH_ANY] = CURLAUTH_ANY,
[REST_HTTP_AUTH_ANY_SAFE] = CURLAUTH_ANYSAFE
}
#define CURLAUTH_DIGEST_IE
Definition: rest.c:83
#define CURLOPT_TLSAUTH_SRP
Definition: rest.c:74
#define CURLAUTH_BASIC
Definition: rest.c:77
#define CURLAUTH_NTLM
Definition: rest.c:89
#define CURLAUTH_NTLM_WB
Definition: rest.c:92
#define CURLAUTH_GSSNEGOTIATE
Definition: rest.c:86
#define CURLAUTH_DIGEST
Definition: rest.c:80
@ REST_HTTP_AUTH_UNKNOWN
Definition: rest.h:70

Definition at line 100 of file rest.c.

◆ http_method_table

fr_table_num_sorted_t const http_method_table[]
Initial value:
= {
{ L("DELETE"), REST_HTTP_METHOD_DELETE },
{ L("GET"), REST_HTTP_METHOD_GET },
{ L("PATCH"), REST_HTTP_METHOD_PATCH },
{ L("POST"), REST_HTTP_METHOD_POST },
{ L("PUT"), REST_HTTP_METHOD_PUT },
{ L("UNKNOWN"), REST_HTTP_METHOD_UNKNOWN }
}
@ REST_HTTP_METHOD_PATCH
Definition: rest.h:48
@ REST_HTTP_METHOD_DELETE
Definition: rest.h:49
@ REST_HTTP_METHOD_PUT
Definition: rest.h:47
@ REST_HTTP_METHOD_POST
Definition: rest.h:46
@ REST_HTTP_METHOD_UNKNOWN
Definition: rest.h:44
@ REST_HTTP_METHOD_GET
Definition: rest.h:45

Conversion table for method config values.

HTTP verb strings for http_method_t enum values. Used by libcurl in the status line of the outgoing HTTP header, by rest_response_header for decoding incoming HTTP responses, and by the configuration parser.

Note
must be kept in sync with http_method_t enum.
See also
http_method_t
fr_table_value_by_str
fr_table_str_by_value

Definition at line 126 of file rest.c.

◆ http_method_table_len

size_t http_method_table_len = NUM_ELEMENTS(http_method_table)

Definition at line 134 of file rest.c.