MXS-2208 Allow dbfw parser to be compiled as C

maxsbase/log.h will turn into C++, but the flex and bison
generated files are by default C.
This commit is contained in:
Johan Wikman 2018-12-05 14:25:44 +02:00
parent 80805292ef
commit d44cf7b20e
4 changed files with 24 additions and 4 deletions

View File

@ -1779,3 +1779,13 @@ json_t* Dbfw::diagnostics_json() const
{
return rules_to_json(this_thread->rules(this));
}
extern "C"
void dbfilter_log_warning(const char* file, int line, const char* function,
const char* format, const char* what)
{
char buffer[strlen(format) + strlen(what) + 1];
sprintf(buffer, format, what);
mxb_log_message(LOG_WARNING, file, line, function, "%s", buffer);
}

View File

@ -21,6 +21,10 @@
#include <maxscale/cdefs.h>
#ifndef MXS_MODULE_NAME
#define MXS_MODULE_NAME "dbfwfilter"
#endif
MXS_BEGIN_DECLS
/** Matching type */
@ -56,4 +60,11 @@ void add_active_rule(void* scanner, const char* name);
void set_matching_mode(void* scanner, enum match_type mode);
bool create_user_templates(void* scanner);
/** Log warnings from C code */
void log_warning(const char* module, const char* file, int line, const char* function,
const char* format, const char* what);
#define FW_LOG_WARNING(format, what)\
log_warning(MXS_MODULE_NAME, __FILE__, __LINE__, __func__, format, what)
MXS_END_DECLS

View File

@ -20,7 +20,6 @@
%{
#include <lex.yy.h>
#include "dbfwfilter.h"
#include <maxscale/log.h>
%}
/** We need a reentrant scanner so no global variables are used */
@ -53,7 +52,7 @@
input
: line_input
| line_input command { MXS_WARNING("Firewall rules file lacks a trailing newline."); }
| line_input command { FW_LOG_WARNING("Firewall rules file lacks a trailing newline.", ""); }
;
line_input

View File

@ -13,7 +13,7 @@
%{
#include <ruleparser.yy.h>
#include <maxscale/log.h>
#include "dbfwfilter.h"
%}
%option reentrant noyywrap bison-bridge prefix="dbfw_yy"
@ -37,7 +37,7 @@ CMP [=<>!]+
%%
{SPACE}"\n"+ return '\n';
{COMMENT} return FWTOK_COMMENT;
deny|allow MXS_WARNING("Use of '%s' is deprecated, use 'match' instead", yytext);return FWTOK_MATCH;
deny|allow FW_LOG_WARNING("Use of '%s' is deprecated, use 'match' instead", yytext);return FWTOK_MATCH;
rule return FWTOK_RULE;
function return FWTOK_FUNCTION;
not_function return FWTOK_NOT_FUNCTION;