1 /** Function prototypes datatypes for the REST (HTTP) transport.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 * Copyright 2012 Arran Cudbard-Bell <a.cudbard-bell@freeradius.org>
23 #include <freeradius-devel/ident.h>
24 #include <freeradius-devel/connection.h>
26 RCSIDH(other_h, "$Id$")
29 #define REST_URI_MAX_LEN 2048
30 #define REST_BODY_MAX_LEN 8192
31 #define REST_BODY_INCR 512
32 #define REST_BODY_MAX_ATTRS 256
43 HTTP_BODY_UNKNOWN = 0,
44 HTTP_BODY_UNSUPPORTED,
56 HTTP_AUTH_UNKNOWN = 0,
62 HTTP_AUTH_GSSNEGOTIATE,
71 * Must be updated (in rest.c) if additional values are added to
74 extern const http_body_type_t http_body_type_supported[HTTP_BODY_NUM_ENTRIES];
76 extern const http_body_type_t http_curl_auth[HTTP_AUTH_NUM_ENTRIES];
78 extern const FR_NAME_NUMBER http_auth_table[];
80 extern const FR_NAME_NUMBER http_method_table[];
82 extern const FR_NAME_NUMBER http_body_table[];
84 extern const FR_NAME_NUMBER http_content_header_table[];
87 * Structure for section configuration
89 typedef struct rlm_rest_section_t {
97 http_body_type_t body;
102 http_auth_type_t auth;
105 char *certificate_file;
107 char *private_key_file;
108 char *private_key_password;
116 } rlm_rest_section_t;
119 * Structure for module configuration
121 typedef struct rlm_rest_t {
122 const char *xlat_name;
126 fr_connection_pool_t *conn_pool;
128 rlm_rest_section_t authorize;
129 rlm_rest_section_t authenticate;
130 rlm_rest_section_t accounting;
131 rlm_rest_section_t checksimul;
132 rlm_rest_section_t postauth;
136 * States for stream based attribute encoders
140 READ_STATE_ATTR_BEGIN,
141 READ_STATE_ATTR_CONT,
146 * States for the response parser
149 WRITE_STATE_INIT = 0,
150 WRITE_STATE_PARSE_HEADERS,
151 WRITE_STATE_PARSE_CONTENT,
156 * Outbound data context (passed to CURLOPT_READFUNCTION as CURLOPT_READDATA)
158 typedef struct rlm_rest_read_t {
159 rlm_rest_t *instance;
170 * Curl inbound data context (passed to CURLOPT_WRITEFUNCTION and
171 * CURLOPT_HEADERFUNCTION as CURLOPT_WRITEDATA and CURLOPT_HEADERDATA)
173 typedef struct rlm_rest_write_t {
174 rlm_rest_t *instance;
178 char *buffer; /* HTTP incoming raw data */
179 size_t alloc; /* Space allocated for buffer */
180 size_t used; /* Space used in buffer */
182 int code; /* HTTP Status Code */
183 http_body_type_t type; /* HTTP Content Type */
189 typedef struct rlm_rest_curl_context_t {
190 struct curl_slist *headers;
192 rlm_rest_read_t read;
193 rlm_rest_write_t write;
194 } rlm_rest_curl_context_t;
197 * Connection API handle
199 typedef struct rlm_rest_handle_t {
200 void *handle; /* Real Handle */
201 void *ctx; /* Context */
205 * Function prototype for rest_read_wrapper. Matches CURL's
206 * CURLOPT_READFUNCTION prototype.
208 typedef size_t (*rest_read_t)(void *ptr, size_t size, size_t nmemb,
212 * Connection API callbacks
214 int rest_init(rlm_rest_t *instance);
216 void rest_cleanup(void);
218 void *rest_socket_create(void *instance);
220 int rest_socket_alive(void *instance, void *handle);
222 int rest_socket_delete(void *instance, void *handle);
225 * Request processing API
227 int rest_request_config(rlm_rest_t *instance,
228 rlm_rest_section_t *section, REQUEST *request,
229 void *handle, http_method_t method,
230 http_body_type_t type, char *uri);
232 int rest_request_perform(rlm_rest_t *instance, rlm_rest_section_t *section,
235 int rest_request_decode(rlm_rest_t *instance,
236 UNUSED rlm_rest_section_t *section, REQUEST *request,
239 void rest_request_cleanup(rlm_rest_t *instance, rlm_rest_section_t *section,
242 #define rest_get_handle_code(handle)(((rlm_rest_curl_context_t*)((rlm_rest_handle_t*)handle)->ctx)->write.code)
244 #define rest_get_handle_type(handle)(((rlm_rest_curl_context_t*)((rlm_rest_handle_t*)handle)->ctx)->write.type)
249 ssize_t rest_uri_build(rlm_rest_t *instance, rlm_rest_section_t *section,
250 REQUEST *request, char *buffer, size_t bufsize);