Skip to content

Commit

Permalink
modules/afmongodb, configure.ac: ENABLE_LEGACY_MONGODB_OPTIONS
Browse files Browse the repository at this point in the history
This re-adds additional support for previous syntax used by libmongo-client
before we started using mongo-c-driver and its URI syntax exclusively.

I.e., so additionally to uri() and collection(), now the following
keywords should work again:

servers()
safe_mode()
path()
password()
username()
database()

Note that these are plainly translated to a connection URI without
much sanity checking or preserving their former semantic meaning.
So various aspects of the MongoDB connection like health checks, retries,
error reporting and synchronicity will still follow the slightly altered
semantics of mongo-c-driver.

In the future, theoretically it is enough to revert this single commit
to remove support.
(This is one reason I did not opt for OOP & inheritance to implement this)

Fixes syslog-ng#893

Signed-off-by: bkil-syslogng <tamas.nagy@balabit.com>
  • Loading branch information
bkil-syslogng committed Mar 8, 2016
1 parent 20828a9 commit e7962e4
Show file tree
Hide file tree
Showing 12 changed files with 684 additions and 0 deletions.
14 changes: 14 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,11 @@ AC_ARG_WITH(mongoc,
Link against the system supplied or the built-in mongo-c-driver library. (default: auto)]
,,with_mongoc="auto")

AC_ARG_ENABLE(legacy-mongodb-options,
[ --enable-legacy-mongodb-options=[yes/no]
Support libmongo-client non-URI MongoDB options. (default: yes)]
,,enable_legacy_mongodb_options="yes")

AC_ARG_WITH(jsonc,
[ --with-jsonc=[system/internal/auto/no]
Link against the system supplied or the built-in jsonc library or explicitly disable it. (default:auto)]
Expand Down Expand Up @@ -933,6 +938,13 @@ dnl ***************************************************************************
dnl mongo-c-driver headers/libraries
dnl ***************************************************************************

if test x"$enable_legacy_mongodb_options" = x"no"; then
enable_legacy_mongodb_options_bit=0
else
enable_legacy_mongodb_options_bit=1
fi
AC_DEFINE_UNQUOTED(ENABLE_LEGACY_MONGODB_OPTIONS, [$enable_legacy_mongodb_options_bit], [Support libmongo-client non-URI MongoDB options])

if test "x$with_mongoc" = "xauto"; then
with_mongoc="system"
PKG_CHECK_MODULES(LIBMONGO, libmongoc >= $LMC_MIN_VERSION,,with_mongoc="auto-internal")
Expand Down Expand Up @@ -1470,6 +1482,7 @@ AM_CONDITIONAL(ENABLE_JAVA, [test "$enable_java" = "yes"])
AM_CONDITIONAL(ENABLE_JAVA_MODULES, [test "$enable_java_modules" = "yes"])
AM_CONDITIONAL(ENABLE_MANPAGES, [test "$enable_manpages" != "no"])
AM_CONDITIONAL(ENABLE_NATIVE, [test "$enable_native" != "no"])
AM_CONDITIONAL(ENABLE_LEGACY_MONGODB_OPTIONS, [test x"$enable_legacy_mongodb_options" != x"no"])

AC_SUBST(timezonedir)
AC_SUBST(pidfiledir)
Expand Down Expand Up @@ -1560,6 +1573,7 @@ echo " Linux capability support : ${has_linux_caps:=no}"
echo " Env wrapper support : ${enable_env_wrapper:=no}"
echo " systemd support : ${enable_systemd:=no} (unit dir: ${systemdsystemunitdir:=none})"
echo " systemd-journal support : ${with_systemd_journal:=no}"
echo " libmongo-client options : ${enable_legacy_mongodb_options}"
echo " Modules:"
echo " Module search path : ${module_path}"
echo " Sun STREAMS support (module): ${enable_sun_streams:=no}"
Expand Down
10 changes: 10 additions & 0 deletions modules/afmongodb/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ modules_afmongodb_libafmongodb_la_SOURCES = \
modules/afmongodb/afmongodb-parser.c \
modules/afmongodb/afmongodb-parser.h \
${DUMMY_C}

if ENABLE_LEGACY_MONGODB_OPTIONS
modules_afmongodb_libafmongodb_la_SOURCES += \
modules/afmongodb/afmongodb-legacy-uri.c \
modules/afmongodb/afmongodb-legacy-uri.h \
modules/afmongodb/afmongodb-legacy-grammar.c \
modules/afmongodb/afmongodb-legacy-grammar.h \
modules/afmongodb/afmongodb-legacy-private.h
endif

modules_afmongodb_libafmongodb_la_LIBADD = \
$(MODULE_DEPS_LIBS) $(LIBMONGO_LIBS)
modules_afmongodb_libafmongodb_la_LDFLAGS = \
Expand Down
76 changes: 76 additions & 0 deletions modules/afmongodb/afmongodb-grammar.ym
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@
%token KW_MONGODB
%token KW_URI
%token KW_COLLECTION
%token KW_SERVERS
%token KW_SAFE_MODE
%token KW_PATH
%token KW_PASSWORD
%token KW_USERNAME
%token KW_DATABASE

%%

Expand All @@ -66,6 +72,76 @@ afmongodb_options
afmongodb_option
: KW_URI '(' string ')' { afmongodb_dd_set_uri(last_driver, $3); free($3); }
| KW_COLLECTION '(' string ')' { afmongodb_dd_set_collection(last_driver, $3); free($3); }
| KW_SERVERS '(' string_list ')'
{
#if SYSLOG_NG_ENABLE_LEGACY_MONGODB_OPTIONS
CHECK_ERROR(afmongodb_dd_check_address(last_driver, FALSE), @3, "Can't mix path() & servers()");
afmongodb_dd_set_servers(last_driver, $3);
#else
YYERROR;
#endif
}
| KW_HOST '(' string ')'
{
#if SYSLOG_NG_ENABLE_LEGACY_MONGODB_OPTIONS
CHECK_ERROR(afmongodb_dd_check_address(last_driver, FALSE), @3, "Can't mix path() & host()");
afmongodb_dd_set_host(last_driver, $3);
free($3);
#else
YYERROR;
#endif
}
| KW_PORT '(' LL_NUMBER ')'
{
#if SYSLOG_NG_ENABLE_LEGACY_MONGODB_OPTIONS
CHECK_ERROR(afmongodb_dd_check_address(last_driver, FALSE), @3, "Can't mix path() & port()");
afmongodb_dd_set_port(last_driver, $3);
#else
YYERROR;
#endif
}
| KW_PATH '(' string ')'
{
#if SYSLOG_NG_ENABLE_LEGACY_MONGODB_OPTIONS
CHECK_ERROR(afmongodb_dd_check_address(last_driver, TRUE), @3, "Can't mix path() with host() or server()");
afmongodb_dd_set_path(last_driver, $3);
free($3);
#else
YYERROR;
#endif
}
| KW_DATABASE '(' string ')'
{
#if SYSLOG_NG_ENABLE_LEGACY_MONGODB_OPTIONS
afmongodb_dd_set_database(last_driver, $3); free($3);
#else
YYERROR;
#endif
}
| KW_USERNAME '(' string ')'
{
#if SYSLOG_NG_ENABLE_LEGACY_MONGODB_OPTIONS
afmongodb_dd_set_user(last_driver, $3); free($3);
#else
YYERROR;
#endif
}
| KW_PASSWORD '(' string ')'
{
#if SYSLOG_NG_ENABLE_LEGACY_MONGODB_OPTIONS
afmongodb_dd_set_password(last_driver, $3); free($3);
#else
YYERROR;
#endif
}
| KW_SAFE_MODE '(' yesno ')'
{
#if SYSLOG_NG_ENABLE_LEGACY_MONGODB_OPTIONS
afmongodb_dd_set_safe_mode(last_driver, !!$3);
#else
YYERROR;
#endif
}
| value_pair_option { afmongodb_dd_set_value_pairs(last_driver, $1); }
| dest_driver_option
| threaded_dest_driver_option
Expand Down
147 changes: 147 additions & 0 deletions modules/afmongodb/afmongodb-legacy-grammar.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
/*
* Copyright (c) 2010-2016 Balabit
*
* 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.
*
*/

#include "afmongodb-legacy-grammar.h"
#include "afmongodb-legacy-private.h"

gboolean
afmongodb_dd_check_address(LogDriver *d, gboolean local)
{
MongoDBDestDriver *self = (MongoDBDestDriver *)d;

if (local)
{
if ((self->port != 0 || self->port != MONGO_CONN_LOCAL) && self->address != NULL)
return FALSE;
if (self->servers)
return FALSE;
}
else
{
if (self->port == MONGO_CONN_LOCAL && self->address != NULL)
return FALSE;
}
return TRUE;
}

void
afmongodb_dd_set_user(LogDriver *d, const gchar *user)
{
MongoDBDestDriver *self = (MongoDBDestDriver *)d;

msg_warning_once(
"WARNING: Using username() option is deprecated in mongodb driver, please use uri() instead", NULL);

g_free(self->user);
self->user = g_strdup(user);
self->is_legacy = TRUE;
}

void
afmongodb_dd_set_password(LogDriver *d, const gchar *password)
{
MongoDBDestDriver *self = (MongoDBDestDriver *)d;

msg_warning_once(
"WARNING: Using password() option is deprecated in mongodb driver, please use uri() instead", NULL);

g_free(self->password);
self->password = g_strdup(password);
self->is_legacy = TRUE;
}

void
afmongodb_dd_set_host(LogDriver *d, const gchar *host)
{
MongoDBDestDriver *self = (MongoDBDestDriver *)d;

msg_warning_once(
"WARNING: Using host() option is deprecated in mongodb driver, please use uri() instead", NULL);

g_free(self->address);
self->address = g_strdup(host);
self->is_legacy = TRUE;
}

void
afmongodb_dd_set_port(LogDriver *d, gint port)
{
MongoDBDestDriver *self = (MongoDBDestDriver *)d;

msg_warning_once(
"WARNING: Using port() option is deprecated in mongodb driver, please use uri() instead", NULL);

self->port = port;
self->is_legacy = TRUE;
}

void
afmongodb_dd_set_servers(LogDriver *d, GList *servers)
{
MongoDBDestDriver *self = (MongoDBDestDriver *)d;

msg_warning_once(
"WARNING: Using servers() option is deprecated in mongodb driver, please use uri() instead", NULL);

string_list_free(self->servers);
self->servers = servers;
self->is_legacy = TRUE;
}

void
afmongodb_dd_set_path(LogDriver *d, const gchar *path)
{
MongoDBDestDriver *self = (MongoDBDestDriver *)d;

msg_warning_once(
"WARNING: Using path() option is deprecated in mongodb driver, please use uri() instead", NULL);

g_free(self->address);
self->address = g_strdup(path);
self->port = MONGO_CONN_LOCAL;
self->is_legacy = TRUE;
}

void
afmongodb_dd_set_database(LogDriver *d, const gchar *database)
{
MongoDBDestDriver *self = (MongoDBDestDriver *)d;

msg_warning_once(
"WARNING: Using database() option is deprecated in mongodb driver, please use uri() instead", NULL);

g_free(self->db);
self->db = g_strdup(database);
self->is_legacy = TRUE;
}

void
afmongodb_dd_set_safe_mode(LogDriver *d, gboolean state)
{
MongoDBDestDriver *self = (MongoDBDestDriver *)d;

msg_warning_once(
"WARNING: Using safe_mode() option is deprecated in mongodb driver, please use uri() instead", NULL);

self->safe_mode = state;
self->is_legacy = TRUE;
}
38 changes: 38 additions & 0 deletions modules/afmongodb/afmongodb-legacy-grammar.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright (c) 2010-2016 Balabit
*
* 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.
*
*/

#ifndef AFMONGODB_LEGACY_GRAMMAR_H_
#define AFMONGODB_LEGACY_GRAMMAR_H_

#include "driver.h"

gboolean afmongodb_dd_check_address(LogDriver *d, gboolean local);
void afmongodb_dd_set_servers(LogDriver *d, GList *servers);
void afmongodb_dd_set_host(LogDriver *d, const gchar *host);
void afmongodb_dd_set_port(LogDriver *d, gint port);
void afmongodb_dd_set_database(LogDriver *d, const gchar *database);
void afmongodb_dd_set_user(LogDriver *d, const gchar *user);
void afmongodb_dd_set_password(LogDriver *d, const gchar *password);
void afmongodb_dd_set_safe_mode(LogDriver *d, gboolean state);
void afmongodb_dd_set_path(LogDriver *d, const gchar *path);

#endif
36 changes: 36 additions & 0 deletions modules/afmongodb/afmongodb-legacy-private.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright (c) 2010-2016 Balabit
*
* 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.
*
*/

#ifndef AFMONGODB_LEGACY_PRIVATE_H_
#define AFMONGODB_LEGACY_PRIVATE_H_

#include "afmongodb-private.h"

#define MONGO_CONN_LOCAL -1

typedef struct _MongoDBHostPort
{
char *host;
gint port;
} MongoDBHostPort;

#endif
Loading

0 comments on commit e7962e4

Please sign in to comment.