%global with_tests   0%{?_with_tests:1}
Name:          mongo-c-driver
Summary:       Client library written in C for MongoDB
Version:       1.27.4
Release:       1
License:       ASL 2.0 and ISC and MIT and zlib
URL:           https://github.com/mongodb/mongo-c-driver
Source0:       %{url}/releases/download/%{version}/%{name}-%{version}.tar.gz
BuildRequires: cmake >= 3.1 openssl-devel pkgconfig(libsasl2) pkgconfig(zlib) gcc
BuildRequires: pkgconfig(snappy) pkgconfig(icu-uc) perl-interpreter python3 python3-sphinx
BuildRequires: chrpath
%if %{with_tests}
BuildRequires: mongodb-server openssl
%endif
Obsoletes:     mongo-c-driver-tools < 1.3.0 mongo-c-driver-libs < %{version}-%{release}
Provides:      mongo-c-driver-tools = 1.13.1 mongo-c-driver-tools%{?_isa} = 1.13.1
Provides:      mongo-c-driver-libs = %{version}-%{release} mongo-c-driver-libs%{?_isa} = %{version}-%{release}

%description
mongo-c-driver is a project that includes two libraries: libmongoc, a client library
written in C for MongoDB. libbson, a library providing useful routines related to
building, parsing, and iterating BSON documents.

%package devel
Summary:       Header files and development libraries for %{name}
Requires:      mongo-c-driver = %{version}-%{release} pkgconfig cmake-filesystem

%description devel
The mongo-c-driver-devel package includes header files and libraries necessary
for the mongo-c-driver library.

%package -n libbson
Summary:       Building, parsing, and iterating BSON documents
Provides:      bundled(jsonsl)

%description -n libbson
mongo-c-driver is a project that includes two libraries: libmongoc, a client library
written in C for MongoDB. libbson, a library providing useful routines related to
building, parsing, and iterating BSON documents.

%package -n libbson-devel
Summary:       Development files for mongo-c-driver
Requires:      libbson = %{version}-%{release} pkgconfig cmake-filesystem

%description -n libbson-devel
The libbson-devel package includes header files and libraries necessary
for the libbson library.

%package help
Summary:       This package contains help documents
Requires:      %{name} = %{version}-%{release}

%description help
Files for help with mongo-c-driver.

%prep
%autosetup -n %{name}-%{version} -p1

%build
%cmake -DENABLE_BSON:STRING=ON -DENABLE_MONGOC:BOOL=ON -DENABLE_SHM_COUNTERS:BOOL=ON \
    -DENABLE_SSL:STRING=OPENSSL -DENABLE_SASL:STRING=CYRUS -DENABLE_ICU:STRING=ON \
    -DENABLE_AUTOMATIC_INIT_AND_CLEANUP:BOOL=OFF -DENABLE_CRYPTO_SYSTEM_PROFILE:BOOL=ON \
    -DENABLE_MAN_PAGES:BOOL=ON -DENABLE_TESTS:BOOL=ON -DENABLE_EXAMPLES:BOOL=OFF \
    -DENABLE_UNINSTALL:BOOL=OFF .
%make_build

%install
%make_install
%delete_la_and_a
find %{buildroot}%{_libdir} -type f -name "*static*" -exec rm -f {} ';'

chrpath -d %{buildroot}%{_bindir}/mongoc-stat
mkdir -p %{buildroot}/etc/ld.so.conf.d
echo "/home/abuild/rpmbuild/BUILD/mongo-c-driver-%{version}/src/libmongoc:/home/abuild/rpmbuild/BUILD/mongo-c-driver-%{version}/src/libbson" > %{buildroot}/etc/ld.so.conf.d/%{name}-%{_arch}.conf

rm -rf %{buildroot}%{_datadir}/%{name}

%post
/sbin/ldconfig

%postun
/sbin/ldconfig

%check
%if %{with_tests}
install -d dbtest
mongod --journal --ipv6 --unixSocketPrefix /tmp --logpath $PWD/server.log \
  --pidfilepath $PWD/server.pid --dbpath $PWD/dbtest --fork
ret=0
export MONGOC_TEST_OFFLINE=on
make check || ret=1
[ -s server.pid ] && kill $(cat server.pid)
exit $ret
%endif

%files
%{_bindir}/mongoc-stat
%doc COPYING
%doc THIRD_PARTY_NOTICES
%{_libdir}/libmongoc-1.0.so.*
%config(noreplace) /etc/ld.so.conf.d/*

%files devel
%doc src/libmongoc/examples
%doc NEWS
%{_includedir}/libmongoc-1.0
%{_libdir}/libmongoc-1.0.so
%{_libdir}/pkgconfig/libmongoc-*.pc
%{_libdir}/cmake/mongoc-1.0
%{_libdir}/cmake/libmongoc-1.0

%files -n libbson
%{_libdir}/libbson*.so.*

%files -n libbson-devel
%doc src/libbson/examples
%doc src/libbson/NEWS
%{_includedir}/libbson-1.0
%{_libdir}/libbson*.so
%{_libdir}/cmake/libbson-1.0
%{_libdir}/cmake/bson-1.0
%{_libdir}/pkgconfig/libbson-*.pc

%files help
%{_mandir}/man3/*

%changelog
* Thu Jul 11 2024 yaoxin <yao_xin001@hoperun.com> - 1.27.4-1
- Update to 1.27.4 for fix CVE-2024-6381 and CVE-2024-6383
- libbson Fixes:
  * Fix build with Visual Studio 2013.
  * Fix parsing of colon in timezone.
  * Error on failure to init subdocument in bson_iter_visit_all.
  * Fix string handling in bson_string_new and bson_string_append.
  * Fix iteration in bson_strfreev.
  * Use aligned alloc for bson_array_builder_t
  * Restore support for Sphinx 1.7.6 for man page build.
  * Fix conversion warning with GCC 12.
  * Fixes to some format strings in trace logs.
  * Allow mongoc_buffer_t to be larger than INT_MAX.
  * Add bson_array_builder_t.
- libmongoc Fixes:
  * Fix possible crash reading malformed wire protocol message.
  * Upgraded bundled Zlib from 1.2.3 to 1.3.1
  * Close leftover connections to removed servers.
  * Fix possible crash when client is configured with empty password.
  * Fix possible hang if mongoc_gridfs_file_readv is called with a corrupt chunk with incomplete data.
  * Fix 32-bit compile with 64-bit time_t
  * Restore support for Sphinx 1.7.6 for man page build.
  * Disable shared libmongoc targets if ENABLE_SHARED=OFF
  * Fix documentation build with Python 3.9.
  * Fix data race in mongoc_cursor_get_host.
  * Add back support for BUILD_VERSION CMake option. BUILD_VERSION was unintentionally removed in 1.25.0.
  * Send recoveryToken in transactions when connected to a load balancer.

* Tue Jan 16 2024 wangkai <13474090681@163.com> - 1.24.4-2
- Fix CVE-2023-0437

* Tue Oct 17 2023 xu_ping <707078654@qq.com> - 1.24.4-1
- Upgrade version to 1.24.4

* Thu Aug 25 2022 wangkai <wangkai385@h-partners.com> - 1.13.1-6
- Remove rpath

* Web 02 Jun 2021 zhaoyao<zhaoyao32@huawei.com> - 1.13.1-5
- Add gcc build require.

* Fri Jun 19 2020 sunguoshuai<sunguoshuai@huawei.com> - 1.13.1-4
- Use python3 instead of python2.

* Fri Feb 21 2020 gulining<gulining1@huawei.com> - 1.13.1-3
- fix build error

* Wed Jan 8 2020 gulining<gulining1@huawei.com> - 1.13.1-2
- Pakcage init
