From 8c08ad9e910e7cfb97a646094b3d89b796efa18f Mon Sep 17 00:00:00 2001 From: Peter Lemenkov Date: Sun, 26 Oct 2025 15:54:50 +0100 Subject: [PATCH] Fix libbson deprecated API warning with version compatibility MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit During compilation of cachedb_mongodb module, numerous deprecation warnings appear on systems with mongo-c-driver >= 1.29.0: ``` Compiling cachedb_mongodb_dbase.c gcc -fPIC -DPIC -O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Wno-complain-wrong-lang -Werror=format-security -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -march=x86-64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -mtls-dialect=gnu2 -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -DMOD_NAME='cachedb_mongodb' -DPKG_MALLOC -DSHM_MMAP -DUSE_MCAST -DDISABLE_NAGLE -DSTATISTICS -DHAVE_RESOLV_RES -DF_MALLOC -DQ_MALLOC -DHP_MALLOC -DDBG_MALLOC -DF_PARALLEL_MALLOC -DHAVE_STDATOMIC -DHAVE_GENERICS -DNAME='"opensips"' -DVERSION='"3.6.2"' -DARCH='"x86_64"' -DOS='"linux"' -DCOMPILER='"gcc 15"' -D__CPU_x86_64 -D__OS_linux -D__SMP_yes -DCFG_DIR='"/etc/opensips/"' -DVERSIONTYPE='"git"' -DTHISREVISION='"994bcd690"' -DFAST_LOCK -DADAPTIVE_WAIT -DADAPTIVE_WAIT_LOOPS=1024 -DHAVE_GETHOSTBYNAME2 -DHAVE_UNION_SEMUN -DHAVE_MSG_NOSIGNAL -DHAVE_MSGHDR_MSG_CONTROL -DHAVE_ALLOCA_H -DHAVE_TIMEGM -DHAVE_EPOLL -DHAVE_SIGIO_RT -DHAVE_SELECT -I/usr/include/json-c -I/usr/include/json-c -DJSON_PKG_MAJOR=0 -DJSON_PKG_MINOR=18 -DJSON_PKG_MICRO=0 -DUTF8PROC_EXPORTS -I/usr/include/libmongoc-1.0 -I/usr/include/libbson-1.0 -c cachedb_mongodb_dbase.c -o cachedb_mongodb_dbase.o cachedb_mongodb_dbase.c: In function ‘mongo_con_set’: cachedb_mongodb_dbase.c:315:9: warning: ‘bson_as_json’ is deprecated: Use bson_as_legacy_extended_json instead [-Wdeprecated-declarations] 315 | dbg_bson("query: ", query); | ^~~~~~~~ In file included from /usr/include/libmongoc-1.0/mongoc/mongoc.h:22, from /usr/include/libmongoc-1.0/mongoc.h:18, from cachedb_mongodb_dbase.h:30, from cachedb_mongodb_dbase.c:22: /usr/include/libbson-1.0/bson/bson.h:535:1: note: declared here 535 | bson_as_json (const bson_t *bson, size_t *length) BSON_GNUC_DEPRECATED_FOR (bson_as_legacy_extended_json); | ^~~~~~~~~~~~ ``` The MongoDB C driver (libbson) deprecated bson_as_json() in version 1.29.0 (October 2024) in favor of bson_as_legacy_extended_json() to clarify which JSON format is being produced (legacy vs. canonical extended JSON). We added compatibility macro at the top of cachedb_mongodb_dbase.c - for mongo-c-driver < 1.29.0, define bson_as_legacy_extended_json as an alias to bson_as_json, allowing the code to use the new API name while maintaining backward compatibility. This change maintains compatibility with all mongo-c-driver versions. The new function name is used on >= 1.29.0, while older versions transparently use the original bson_as_json() through the macro alias. No behavioral changes - the replacement is functionally identical and produces the same JSON output format. The new name simply makes it explicit that the legacy extended JSON format is being used. Note: mongo-c-driver 1.29.0 was released in October 2024. Many LTS distributions still ship earlier versions (e.g., RHEL 8/9, Ubuntu 20.04/22.04, Debian 11/12), making the compatibility macro necessary. Signed-off-by: Peter Lemenkov Assisted-by: Claude (Anthropic) --- modules/cachedb_mongodb/cachedb_mongodb_dbase.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/modules/cachedb_mongodb/cachedb_mongodb_dbase.c b/modules/cachedb_mongodb/cachedb_mongodb_dbase.c index 73e4db3b68a..5b5ab550a84 100644 --- a/modules/cachedb_mongodb/cachedb_mongodb_dbase.c +++ b/modules/cachedb_mongodb/cachedb_mongodb_dbase.c @@ -40,11 +40,15 @@ extern int compat_mode_24; #define HEX_OID_SIZE 25 char *hex_oid_id; +#if !MONGOC_CHECK_VERSION(1, 29, 0) +#define bson_as_legacy_extended_json bson_as_json +#endif + #define dbg_bson(_prepend_txt, __bson_ptr__) \ do { \ char *__bson_str__; \ if (is_printable(L_DBG)) { \ - __bson_str__ = bson_as_json(__bson_ptr__, NULL); \ + __bson_str__ = bson_as_legacy_extended_json(__bson_ptr__, NULL); \ LM_DBG("%s%s\n", _prepend_txt, __bson_str__); \ bson_free(__bson_str__); \ } \ @@ -1309,11 +1313,11 @@ int mongo_db_query_trans(cachedb_con *con, const str *table, const db_key_t *_k, namespace); if (is_printable(L_DBG)) { - strf = bson_as_json(filter, NULL); + strf = bson_as_legacy_extended_json(filter, NULL); #if MONGOC_CHECK_VERSION(1, 5, 0) - stro = bson_as_json(opts, NULL); + stro = bson_as_legacy_extended_json(opts, NULL); #else - stro = bson_as_json(fields, NULL); + stro = bson_as_legacy_extended_json(fields, NULL); #endif LM_DBG("query doc:\n%s\n%s\n", strf, stro); bson_free(strf);