1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237
|
/*
* Copyright (c) 2022 One Identity LLC.
* Copyright (c) 2016 Marc Falzon
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 as published
* by the Free Software Foundation, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As an additional exemption you are allowed to compile & link against the
* OpenSSL libraries as published by the OpenSSL project. See the file
* COPYING for details.
*
*/
%code top {
#include "http-parser.h"
}
%code {
#include "cfg-grammar-internal.h"
#include "cfg-parser.h"
#include "http.h"
#include "response-handler.h"
#include "autodetect-ca-location.h"
#include "plugin.h"
#include <string.h>
HttpResponseHandler last_response_handler;
}
%define api.prefix {http_}
/* this parameter is needed in order to instruct bison to use a complete
* argument list for yylex/yyerror */
%lex-param {CfgLexer *lexer}
%parse-param {CfgLexer *lexer}
%parse-param {LogDriver **instance}
%parse-param {gpointer arg}
%token KW_HTTP
%token KW_URL
%token KW_USER
%token KW_PASSWORD
%token KW_USER_AGENT
%token KW_METHOD
%token KW_HEADERS
%token KW_BODY
%token KW_CA_DIR
%token KW_CA_FILE
%token KW_CERT_FILE
%token KW_KEY_FILE
%token KW_CIPHER_SUITE
%token KW_TLS12_AND_OLDER
%token KW_TLS13
%token KW_PROXY
%token KW_USE_SYSTEM_CERT_STORE
%token KW_SSL_VERSION
%token KW_PEER_VERIFY
%token KW_TIMEOUT
%token KW_OCSP_STAPLING_VERIFY
%token KW_TLS
%token KW_ACCEPT_ENCODING
%token KW_CONTENT_COMPRESSION
%token KW_BATCH_BYTES
%token KW_BODY_PREFIX
%token KW_BODY_SUFFIX
%token KW_DELIMITER
%token KW_ACCEPT_REDIRECTS
%token KW_RESPONSE_ACTION
%token KW_SUCCESS
%token KW_RETRY
%token KW_DROP
%token KW_DISCONNECT
%token KW_FLUSH_ON_WORKER_KEY_CHANGE
%type <ptr> driver
%type <ptr> http_destination
%type <ptr> http_response_action
/* INCLUDE_DECLS */
%%
start
: driver
{
*instance = $1;
if (yychar != HTTP_EMPTY)
cfg_lexer_unput_token(lexer, &yylval);
YYACCEPT;
}
;
driver
: LL_CONTEXT_DESTINATION http_destination { $$ = $2; }
;
http_destination
: KW_HTTP
{
last_driver = http_dd_new(configuration);
}
'(' _inner_dest_context_push http_options _inner_dest_context_pop ')' { $$ = last_driver; }
;
http_options
: http_option http_options
|
;
http_response_action
: KW_SUCCESS { $$ = http_result_success; }
| KW_RETRY { $$ = http_result_retry; }
| KW_DROP { $$ = http_result_drop; }
| KW_DISCONNECT { $$ = http_result_disconnect; }
;
response_action_items
: response_action_item response_action_items
|
;
response_action_item
: positive_integer { last_response_handler.status_code = $1; }
LL_ARROW
http_response_action { last_response_handler.action = $4;
http_dd_insert_response_handler(last_driver, &last_response_handler);}
;
http_option
: KW_URL '(' string_list ')'
{
GError *error = NULL;
CHECK_ERROR_GERROR(http_dd_set_urls(last_driver, $3, &error), @3, error, "Error setting url");
g_list_free_full($3, free);
}
| KW_USER '(' string ')' { http_dd_set_user(last_driver, $3); free($3); }
| KW_PASSWORD '(' string ')' { http_dd_set_password(last_driver, $3); free($3); }
| KW_USER_AGENT '(' string ')' { http_dd_set_user_agent(last_driver, $3); free($3); }
| KW_HEADERS '(' string_list ')' { http_dd_set_headers(last_driver, $3); g_list_free_full($3, free); }
| KW_METHOD '(' string ')' { http_dd_set_method(last_driver, $3); free($3); }
| KW_BODY_PREFIX '(' string ')' { http_dd_set_body_prefix(last_driver, $3); free($3); }
| KW_BODY_SUFFIX '(' string ')' { http_dd_set_body_suffix(last_driver, $3); free($3); }
| KW_DELIMITER '(' string ')' { http_dd_set_delimiter(last_driver, $3); free($3); }
| KW_PROXY '(' string ')' { http_dd_set_proxy(last_driver, $3); free($3); }
| KW_BODY '(' template_name_or_content ')' { http_dd_set_body(last_driver, $3); log_template_unref($3); }
| KW_ACCEPT_REDIRECTS '(' yesno ')' { http_dd_set_accept_redirects(last_driver, $3); }
| KW_TIMEOUT '(' nonnegative_integer ')' { http_dd_set_timeout(last_driver, $3); }
| KW_BATCH_BYTES '(' nonnegative_integer ')' { http_dd_set_batch_bytes(last_driver, $3); }
| threaded_dest_driver_general_option
| threaded_dest_driver_batch_option
| threaded_dest_driver_workers_option
| http_tls_option
| KW_FLUSH_ON_WORKER_KEY_CHANGE '(' yesno ')' { log_threaded_dest_driver_set_flush_on_worker_key_change(last_driver, $3); }
| KW_TLS '(' http_tls_options ')'
| KW_ACCEPT_ENCODING '(' string ')' { http_dd_set_accept_encoding(last_driver, $3); free($3); }
| KW_CONTENT_COMPRESSION '(' string ')'
{
CHECK_ERROR(http_dd_set_content_compression(last_driver, $3), @3, "Unrecognized compression type");
free($3);
}
| { last_template_options = http_dd_get_template_options(last_driver); } template_option
| KW_RESPONSE_ACTION '(' response_action_items ')'
;
http_tls_options
: http_tls_option http_tls_options
|
;
http_tls_option
: KW_CA_DIR '(' string ')' { http_dd_set_ca_dir(last_driver, $3); free($3); }
| KW_CA_FILE '(' path_check ')' { http_dd_set_ca_file(last_driver, $3); free($3); }
| KW_CERT_FILE '(' path_check ')' { http_dd_set_cert_file(last_driver, $3); free($3); }
| KW_KEY_FILE '(' path_secret ')' { http_dd_set_key_file(last_driver, $3); free($3); }
| KW_CIPHER_SUITE '(' tls_cipher_suites ')'
| KW_CIPHER_SUITE '(' string ')' { http_dd_set_cipher_suite(last_driver, $3); free($3); }
| KW_SSL_VERSION '(' string ')' { CHECK_ERROR(http_dd_set_ssl_version(last_driver, $3), @3,
"curl: unsupported SSL version: %s", $3);
free($3); }
| KW_USE_SYSTEM_CERT_STORE '(' yesno ')' {
if ($3)
{
const gchar *ca_dir = auto_detect_ca_dir();
const gchar *ca_file = auto_detect_ca_file();
CHECK_ERROR(ca_dir || ca_file, @3,
"Failed to autodect system cert store");
http_dd_set_ca_file(last_driver, ca_file);
http_dd_set_ca_dir(last_driver, ca_dir);
}
}
| KW_PEER_VERIFY '(' yesno ')' { http_dd_set_peer_verify(last_driver, $3); }
| KW_OCSP_STAPLING_VERIFY '(' yesno ')'
{
CHECK_ERROR(http_dd_set_ocsp_stapling_verify(last_driver, $3), @3,
"Error setting ocsp-stapling-verify(), OCSP stapling is not supported with this libcurl version");
}
;
tls_cipher_suites
: tls_cipher_suite tls_cipher_suites
|
;
tls_cipher_suite
: KW_TLS12_AND_OLDER '(' string ')'
{
http_dd_set_cipher_suite(last_driver, $3);
free($3);
}
| KW_TLS13 '(' string ')'
{
CHECK_ERROR(http_dd_set_tls13_cipher_suite(last_driver, $3), @3,
"Error setting cipher-suite(tls13()), specifying TLS 1.3 ciphers is not supported with this libcurl version");
free($3);
}
;
/* INCLUDE_RULES */
%%
|