From 8fb85db3105c7153359d588e5cf3cd93d4bd58ec Mon Sep 17 00:00:00 2001 From: jmasterfunk84 <48972964+jmasterfunk84@users.noreply.github.com> Date: Wed, 12 Oct 2022 11:28:15 -0600 Subject: [PATCH] [DBI] Disable Change Streams with mongo Version Support for change stream is only available in mongoc >=1.9.0 - Disabled related functions in dbi. Support for bson to json used in debug statement only in libbson >=1.7.0 - Simple debug message in lower versions --- lib/app/ogs-context.c | 4 ++++ lib/dbi/ogs-mongoc.c | 10 ++++++++++ lib/dbi/ogs-mongoc.h | 2 ++ src/hss/hss-context.c | 9 ++++++--- 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/lib/app/ogs-context.c b/lib/app/ogs-context.c index 24b4d900a..1b22523f2 100644 --- a/lib/app/ogs-context.c +++ b/lib/app/ogs-context.c @@ -352,8 +352,12 @@ int ogs_app_context_parse_config(void) ogs_yaml_iter_bool(¶meter_iter); } else if (!strcmp(parameter_key, "use_mongodb_change_stream")) { +#if MONGOC_MAJOR_VERSION >= 1 && MONGOC_MINOR_VERSION >= 9 self.use_mongodb_change_stream = ogs_yaml_iter_bool(¶meter_iter); +#else + self.use_mongodb_change_stream = false; +#endif } else ogs_warn("unknown key `%s`", parameter_key); } diff --git a/lib/dbi/ogs-mongoc.c b/lib/dbi/ogs-mongoc.c index b533ed182..a9e6c21e8 100644 --- a/lib/dbi/ogs-mongoc.c +++ b/lib/dbi/ogs-mongoc.c @@ -182,15 +182,18 @@ void ogs_dbi_final() mongoc_collection_destroy(self.collection.subscriber); } +#if MONGOC_MAJOR_VERSION >= 1 && MONGOC_MINOR_VERSION >= 9 if (self.stream) { mongoc_change_stream_destroy(self.stream); } +#endif ogs_mongoc_final(); } int ogs_dbi_collection_watch_init(void) { +#if MONGOC_MAJOR_VERSION >= 1 && MONGOC_MINOR_VERSION >= 9 bson_t empty = BSON_INITIALIZER; const bson_t *err_doc; bson_error_t error; @@ -213,10 +216,14 @@ int ogs_dbi_collection_watch_init(void) } return OGS_OK; +# else + return OGS_ERROR; +#endif } int ogs_dbi_poll_change_stream(void) { +#if MONGOC_MAJOR_VERSION >= 1 && MONGOC_MINOR_VERSION >= 9 int rv; const bson_t *document; @@ -240,4 +247,7 @@ int ogs_dbi_poll_change_stream(void) } return OGS_OK; +# else + return OGS_ERROR; +#endif } diff --git a/lib/dbi/ogs-mongoc.h b/lib/dbi/ogs-mongoc.h index a0037dfbe..372289038 100644 --- a/lib/dbi/ogs-mongoc.h +++ b/lib/dbi/ogs-mongoc.h @@ -37,7 +37,9 @@ typedef struct ogs_mongoc_s { void *client; void *database; +#if MONGOC_MAJOR_VERSION >= 1 && MONGOC_MINOR_VERSION >= 9 mongoc_change_stream_t *stream; +#endif char *masked_db_uri; diff --git a/src/hss/hss-context.c b/src/hss/hss-context.c index ff743ea80..b024d357b 100644 --- a/src/hss/hss-context.c +++ b/src/hss/hss-context.c @@ -1201,8 +1201,13 @@ int hss_handle_change_event(const bson_t *document) char *imsi_bcd; +#if BSON_MAJOR_VERSION >= 1 && BSON_MINOR_VERSION >= 7 char *as_json = bson_as_relaxed_extended_json(document, NULL); - ogs_debug("Got document: %s\n", as_json); + ogs_debug("Received change stream document: %s\n", as_json); + bson_free (as_json); +# else + ogs_debug("Received change stream document."); +#endif if (!bson_iter_init_find(&iter, document, "fullDocument")) { ogs_error("No 'imsi' field in this document."); return OGS_ERROR; @@ -1276,8 +1281,6 @@ int hss_handle_change_event(const bson_t *document) ogs_debug("No 'updateDescription' field in this document"); } - bson_free (as_json); - if (send_clr_flag) { ogs_info("[%s] Cancel Location Requested", imsi_bcd); hss_s6a_send_clr(imsi_bcd, NULL, NULL,