Fix libbson deprecated API warning with version compatibility#3792
Merged
liviuchircu merged 1 commit intoOpenSIPS:masterfrom Jan 27, 2026
Merged
Fix libbson deprecated API warning with version compatibility#3792liviuchircu merged 1 commit intoOpenSIPS:masterfrom
liviuchircu merged 1 commit intoOpenSIPS:masterfrom
Conversation
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 <lemenkov@gmail.com>
Assisted-by: Claude (Anthropic) <https://claude.ai>
8c08ad9 to
6be8391
Compare
Member
|
The fix is solid, @lemenkov, as it maintains backwards-compatibility and avoids the warnings on newer systems while still driving the code forward to use the new driver API. I will backport it down to |
liviuchircu
pushed a commit
that referenced
this pull request
Jan 27, 2026
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.
Assisted-by: Claude (Anthropic) <https://claude.ai>
Signed-off-by: Peter Lemenkov <lemenkov@gmail.com>
(cherry picked from commit dead516)
liviuchircu
pushed a commit
that referenced
this pull request
Jan 27, 2026
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.
Assisted-by: Claude (Anthropic) <https://claude.ai>
Signed-off-by: Peter Lemenkov <lemenkov@gmail.com>
(cherry picked from commit dead516)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fix libbson deprecated API warning with version compatibility
Details
This PR fixes deprecation warnings that appear when compiling the cachedb_mongodb module with mongo-c-driver >= 1.29.0. The
bson_as_json()function was deprecated in favor ofbson_as_legacy_extended_json()in mongo-c-driver version 1.29.0 (released October 2024).The warning appears during compilation:
The deprecation was introduced to clarify which JSON format is being produced - legacy extended JSON vs. canonical extended JSON. The function signatures are identical, making this a straightforward API update.
However, many LTS distributions still ship older versions of mongo-c-driver (< 1.29.0), so the code needs to maintain backward compatibility with both the old and new API.
Solution
Add a compatibility macro at the top of
modules/cachedb_mongodb/cachedb_mongodb_dbase.cthat maps the new function name to the old one on older versions:Then update all
bson_as_json()calls tobson_as_legacy_extended_json()throughout the file.This approach:
Compatibility
Fully backward compatible. The macro ensures the code works with:
bson_as_legacy_extended_json()APIbson_as_json()via macroNo runtime behavior changes - the same JSON is produced on all versions.
Closing issues
N/A