HTTP data server updates

Check of enable-http-data config option
HTTP/2 Return 400 bad request if no path match
Test: updated yang file revisions, extended restconf config with http-data
This commit is contained in:
Olof hagsand 2022-04-21 16:45:18 +02:00
parent 2a8cedf0c3
commit 404d05950a
10 changed files with 243 additions and 136 deletions

View file

@ -87,7 +87,7 @@ static const map_str2str mime_map[] = {
/*! Check if uri path denotes a data path
*
* @param[out] data Pointer to string where data starts if retval = 1
* @retval 0 No, not a data path
* @retval 0 No, not a data path, or not enabled
* @retval 1 Yes, a data path and "data" points to www-data if given
*/
int
@ -97,19 +97,21 @@ api_path_is_data(clicon_handle h,
char *path;
char *http_data_path;
if ((path = restconf_uripath(h)) == NULL)
return 0;
if ((http_data_path = clicon_option_str(h, "CLICON_HTTP_DATA_PATH")) == NULL)
return 0;
if (strlen(path) < strlen(http_data_path))
return 0;
if (path[0] != '/')
return 0;
if (strncmp(path, http_data_path, strlen(http_data_path)) != 0)
return 0;
if (data)
*data = path + strlen(http_data_path);
return 1;
if (restconf_http_data_get(h) == 0)
return 0;
if ((path = restconf_uripath(h)) == NULL)
return 0;
if ((http_data_path = clicon_option_str(h, "CLICON_HTTP_DATA_PATH")) == NULL)
return 0;
if (strlen(path) < strlen(http_data_path))
return 0;
if (path[0] != '/')
return 0;
if (strncmp(path, http_data_path, strlen(http_data_path)) != 0)
return 0;
if (data)
*data = path + strlen(http_data_path);
return 1;
}
/*! Generic restconf error function on get/head request

View file

@ -90,9 +90,10 @@ struct restconf_handle {
event_stream_t *rh_stream; /* notification streams, see clixon_stream.[ch] */
/* ------ end of common handle ------ */
clicon_hash_t *rh_params; /* restconf parameters, including http headers */
clixon_auth_type_t rh_auth_type; /* authentication type */
int rh_pretty; /* pretty-print for http replies */
clicon_hash_t *rh_params; /* restconf parameters, including http headers */
clixon_auth_type_t rh_auth_type; /* authentication type */
int rh_pretty; /* pretty-print for http replies */
int rh_http_data; /* enable-http-data (and if-feature http-data) */
char *rh_fcgi_socket; /* if-feature fcgi, XXX: use WITH_RESTCONF_FCGI ? */
};
@ -228,12 +229,10 @@ restconf_pretty_get(clicon_handle h)
}
/*! Set restconf pretty-print
* @param[in] h Clicon handle
* @param[in] name Data name
* @param[in] val Data value as null-terminated string
* @retval 0 OK
* @retval -1 Error
* Currently using clixon runtime data but there is risk for colliding names
* @param[in] h Clicon handle
* @param[in] pretty 0 or 1
* @retval 0 OK
* @retval -1 Error
*/
int
restconf_pretty_set(clicon_handle h,
@ -245,6 +244,34 @@ restconf_pretty_set(clicon_handle h,
return 0;
}
/*! Get restconf http-data
* @param[in] h Clixon handle
* @retval 0 Yes, http-data enabled
* @retval 1 No, http-data disabled
*/
int
restconf_http_data_get(clicon_handle h)
{
struct restconf_handle *rh = handle(h);
return rh->rh_http_data;
}
/*! Set restconf http-data
* @param[in] h Clixon handle
* @retval 0 OK
* @retval -1 Error
*/
int
restconf_http_data_set(clicon_handle h,
int http_data)
{
struct restconf_handle *rh = handle(h);
rh->rh_http_data = http_data;
return 0;
}
/*! Get restconf fcgi socket path
* @param[in] h Clicon handle
* @retval socketpath

View file

@ -51,6 +51,8 @@ clixon_auth_type_t restconf_auth_type_get(clicon_handle h);
int restconf_auth_type_set(clicon_handle h, clixon_auth_type_t type);
int restconf_pretty_get(clicon_handle h);
int restconf_pretty_set(clicon_handle h, int pretty);
int restconf_http_data_get(clicon_handle h);
int restconf_http_data_set(clicon_handle h, int http_data);
char *restconf_fcgi_socket_get(clicon_handle h);
int restconf_fcgi_socket_set(clicon_handle h, char *socketpath);

View file

@ -786,6 +786,13 @@ restconf_config_init(clicon_handle h,
else if (strcmp(bstr, "false") == 0)
restconf_pretty_set(h, 0);
}
if ((x = xpath_first(xrestconf, nsc, "enable-http-data")) != NULL &&
(bstr = xml_body(x)) != NULL){
if (strcmp(bstr, "true") == 0)
restconf_http_data_set(h, 1);
else if (strcmp(bstr, "false") == 0)
restconf_http_data_set(h, 0);
}
if ((x = xpath_first(xrestconf, nsc, "fcgi-socket")) != NULL &&
(bstr = xml_body(x)) != NULL){
if (restconf_fcgi_socket_set(h, bstr) < 0)

View file

@ -479,8 +479,10 @@ http2_exec(restconf_conn *rc,
if (restconf_nghttp2_path(sd) < 0)
goto done;
}
else
else{
sd->sd_code = 400;
; /* ignore */
}
/* If body, add a content-length header
* A server MUST NOT send a Content-Length header field in any response
* with a status code of 1xx (Informational) or 204 (No Content). A