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.

A large part of the code comes from the previous state before being
removed:

6636898
"afmongodb: added mongo uri option, removed all redundant ones"

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 May 24, 2016
1 parent 0b0c369 commit 8611333
Show file tree
Hide file tree
Showing 15 changed files with 896 additions and 0 deletions.
14 changes: 14 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,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 @@ -979,6 +984,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 @@ -1549,6 +1561,7 @@ 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_EXTRA_WARNINGS, [test "$enable_extra_warnings" = "yes"])
AM_CONDITIONAL(ENABLE_LEGACY_MONGODB_OPTIONS, [test x"$enable_legacy_mongodb_options" != x"no"])

AC_SUBST(timezonedir)
AC_SUBST(pidfiledir)
Expand Down Expand Up @@ -1641,6 +1654,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
12 changes: 12 additions & 0 deletions modules/afmongodb/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,18 @@ 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 \
modules/afmongodb/host-list.c \
modules/afmongodb/host-list.h
endif

modules_afmongodb_libafmongodb_la_LIBADD = \
$(MODULE_DEPS_LIBS) $(LIBMONGO_LIBS)
modules_afmongodb_libafmongodb_la_LDFLAGS = \
Expand Down
60 changes: 60 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 @@ -72,6 +78,7 @@ afmongodb_option
{
afmongodb_dd_set_collection(last_driver, $3); free($3);
}
| afmongodb_legacy_option
| value_pair_option
{
afmongodb_dd_set_value_pairs(last_driver, $1);
Expand All @@ -81,6 +88,59 @@ afmongodb_option
| { last_template_options = afmongodb_dd_get_template_options(last_driver); } template_option
;

afmongodb_legacy_option
: KW_IFDEF
{
#if SYSLOG_NG_ENABLE_LEGACY_MONGODB_OPTIONS
}
| KW_SERVERS '(' string_list ')'
{
CHECK_ERROR(afmongodb_dd_validate_network_combination(last_driver), @3,
"Can't mix path() & servers()");
afmongodb_dd_set_servers(last_driver, $3);
}
| KW_HOST '(' string ')'
{
CHECK_ERROR(afmongodb_dd_validate_network_combination(last_driver), @3,
"Can't mix path() & host()");
afmongodb_dd_set_host(last_driver, $3);
free($3);
}
| KW_PORT '(' LL_NUMBER ')'
{
CHECK_ERROR(afmongodb_dd_validate_network_combination(last_driver), @3,
"Can't mix path() & port()");
afmongodb_dd_set_port(last_driver, $3);
}
| KW_PATH '(' string ')'
{
CHECK_ERROR(afmongodb_dd_validate_socket_combination(last_driver), @3,
"Can't mix path() with host() or server()");
afmongodb_dd_set_path(last_driver, $3);
free($3);
}
| KW_DATABASE '(' string ')'
{
afmongodb_dd_set_database(last_driver, $3); free($3);
}
| KW_USERNAME '(' string ')'
{
afmongodb_dd_set_user(last_driver, $3); free($3);
}
| KW_PASSWORD '(' string ')'
{
afmongodb_dd_set_password(last_driver, $3); free($3);
}
| KW_SAFE_MODE '(' yesno ')'
{
afmongodb_dd_set_safe_mode(last_driver, !!$3);
}
| KW_ENDIF
{
#endif /* SYSLOG_NG_ENABLE_LEGACY_MONGODB_OPTIONS */
}
;

/* INCLUDE_RULES */

%%
151 changes: 151 additions & 0 deletions modules/afmongodb/afmongodb-legacy-grammar.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
/*
* 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_validate_socket_combination(LogDriver *d)
{
MongoDBDestDriver *self = (MongoDBDestDriver *)d;

if ((self->port != 0 || self->port != MONGO_CONN_LOCAL) && self->address != NULL)
return FALSE;
if (self->servers)
return FALSE;

return TRUE;
}

gboolean
afmongodb_dd_validate_network_combination(LogDriver *d)
{
MongoDBDestDriver *self = (MongoDBDestDriver *)d;

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");

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");

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");

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");

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");

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");

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");

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");

self->safe_mode = state;
self->is_legacy = TRUE;
}
40 changes: 40 additions & 0 deletions modules/afmongodb/afmongodb-legacy-grammar.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* 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 "syslog-ng.h"
#include "driver.h"

gboolean afmongodb_dd_validate_socket_combination(LogDriver *d);
gboolean afmongodb_dd_validate_network_combination(LogDriver *d);
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
31 changes: 31 additions & 0 deletions modules/afmongodb/afmongodb-legacy-private.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* 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 "syslog-ng.h"
#include "afmongodb-private.h"

#define MONGO_CONN_LOCAL -1

#endif
Loading

0 comments on commit 8611333

Please sign in to comment.