/*
 * Copyright (c) 2020 One Identity
 * Copyright (c) 2020 Laszlo Budai <laszlo.budai@outlook.com>
 *
 * 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 "driver.h"
#include "cfg-lexer.h"
#include "http-test-slots-parser.h"
}

%code {

#pragma GCC diagnostic ignored "-Wswitch-default"

#include "http-test-slots.h"

HttpTestSlotsPlugin *last_http_test_slots;

}

%define api.prefix {http_test_slots_}

/* 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 {LogDriverPlugin **instance}
%parse-param {gpointer arg}

/* INCLUDE_DECLS */

%token KW_HTTP_TEST_SLOTS
%token KW_HEADER

%%

start
  : LL_CONTEXT_INNER_DEST http_test_slots_start { YYACCEPT; }
  ;

http_test_slots_start
  : KW_HTTP_TEST_SLOTS '('
  {
    last_http_test_slots = http_test_slots_plugin_new();
    *instance = (LogDriverPlugin *) last_http_test_slots;
    }
    http_test_slots_options
  ')'
  ;

http_test_slots_options
	: http_test_slots_option http_test_slots_options
	|
	;


http_test_slots_option
  : KW_HEADER '(' string ')'		{ http_test_slots_plugin_set_header(last_http_test_slots, $3); free($3); }

  ;

/* INCLUDE_RULES */

%%
