Module: sip-router Branch: master Commit: 9d8d30c691fbd779ccf68c5f0f12cef17792934d URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=9d8d30c6...
Author: Marius Zbihlei marius.zbihlei@1and1.ro Committer: Marius Zbihlei marius.zbihlei@1and1.ro Date: Mon Aug 30 17:19:17 2010 +0300
modules/db_berkeley Added a compatibility layer between libdb versions smaller than 4.6 and libdb4.6
Cursor method close() is not present in versions smaller than 4.6 thus the module would not compile. Also c_* methods are marked as deprecated so the compatibility layer should be extended as well.
---
modules/db_berkeley/bdb_cmd.c | 3 +- modules/db_berkeley/bdb_crs_compat.h | 43 ++++++++++++++++++++++++++++++++++ modules/db_berkeley/bdb_res.c | 3 +- modules/db_berkeley/km_db_berkeley.c | 9 ++++--- 4 files changed, 52 insertions(+), 6 deletions(-)
diff --git a/modules/db_berkeley/bdb_cmd.c b/modules/db_berkeley/bdb_cmd.c index 64b46c3..8396690 100644 --- a/modules/db_berkeley/bdb_cmd.c +++ b/modules/db_berkeley/bdb_cmd.c @@ -44,6 +44,7 @@ #include "bdb_uri.h" #include "bdb_res.h" #include "bdb_lib.h" +#include "bdb_crs_compat.h"
#define BDB_BUF_SIZE 1024
@@ -56,7 +57,7 @@ static void bdb_cmd_free(db_cmd_t* cmd, bdb_cmd_t* payload) { db_drv_free(&payload->gen); if (payload->dbcp) - payload->dbcp->c_close(payload->dbcp); + payload->dbcp->CLOSE_CURSOR(payload->dbcp); if(payload->skey.s) pkg_free(payload->skey.s); pkg_free(payload); diff --git a/modules/db_berkeley/bdb_crs_compat.h b/modules/db_berkeley/bdb_crs_compat.h new file mode 100644 index 0000000..5d2d558 --- /dev/null +++ b/modules/db_berkeley/bdb_crs_compat.h @@ -0,0 +1,43 @@ +/* + * $Id$ + * + * BDB Compatibility layer for SIP-router + * + * Copyright (C) 2010 Marius Zbihlei marius.zbihlei at 1and1 dot ro + * + * This file is part of SIP-router, a free SIP server. + * + * SIP-router is free software; you can redistribute it and/or modify it under the + * terms of the GNU General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) any later + * version. + * + * SIP-router 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., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ +#ifndef BDB_CRS_COMPAT_H +#define BDB_CRS_COMPAT_H + +#include <db.h> + +/* this is a compatibility layer for cursor close function + * Historically, the function was called c_close() but it became deprecated + * starting with version 4.6 + */ +#if DB_VERSION_MAJOR < 4 +# define CLOSE_CURSOR c_close +#else +#if (DB_VERSION_MAJOR == 4) && (DB_VERSION_MINOR < 6) +# define CLOSE_CURSOR c_close +#else +# define CLOSE_CURSOR close +#endif +#endif + +#endif //BDB_CRS_COMPAT_H \ No newline at end of file diff --git a/modules/db_berkeley/bdb_res.c b/modules/db_berkeley/bdb_res.c index 75bd856..1b73335 100644 --- a/modules/db_berkeley/bdb_res.c +++ b/modules/db_berkeley/bdb_res.c @@ -32,6 +32,7 @@
#include "bdb_res.h" #include "bdb_cmd.h" +#include "bdb_crs_compat.h"
#include "../../mem/mem.h" #include "../../dprint.h" @@ -48,7 +49,7 @@ void bdb_res_free(db_res_t* res, bdb_res_t *payload)
if(bcmd->dbcp!=NULL) { - bcmd->dbcp->close(bcmd->dbcp); + bcmd->dbcp->CLOSE_CURSOR(bcmd->dbcp); bcmd->dbcp = NULL; } db_drv_free(&payload->gen); diff --git a/modules/db_berkeley/km_db_berkeley.c b/modules/db_berkeley/km_db_berkeley.c index 9bab9d2..daeaca6 100644 --- a/modules/db_berkeley/km_db_berkeley.c +++ b/modules/db_berkeley/km_db_berkeley.c @@ -51,6 +51,7 @@ #include "km_bdb_res.h" #include "km_bdb_mi.h" #include "bdb_mod.h" +#include "bdb_crs_compat.h"
#ifndef CFG_DIR #define CFG_DIR "/tmp" @@ -457,7 +458,7 @@ int km_bdb_query(db1_con_t* _con, db_key_t* _k, db_op_t* _op, db_val_t* _v, i++; } - dbcp->c_close(dbcp); + dbcp->CLOSE_CURSOR(dbcp); ret=0; #ifdef BDB_EXTRA_DEBUG @@ -520,7 +521,7 @@ int km_bdb_query(db1_con_t* _con, db_key_t* _k, db_op_t* _op, db_val_t* _v, i++; } - dbcp->c_close(dbcp); + dbcp->CLOSE_CURSOR(dbcp); BDB_CON_RESULT(_con) = *_r; return 0; } @@ -834,7 +835,7 @@ int bdb_delete(db1_con_t* _h, db_key_t* _k, db_op_t* _op, db_val_t* _v, int _n) ret = dbcp->c_del(dbcp, 0); } - dbcp->c_close(dbcp); + dbcp->CLOSE_CURSOR(dbcp); return 0; }
@@ -1006,7 +1007,7 @@ int _bdb_delete_cursor(db1_con_t* _h, db_key_t* _k, db_op_t* _op, db_val_t* _v, error: if(dbcp) - dbcp->c_close(dbcp); + dbcp->CLOSE_CURSOR(dbcp); if(_r) db_free_result(_r); if(lkey)