Module: sip-router Branch: janakj/ldap Commit: 859a44b1377f9486e155af467507d574361a180c URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=859a44b1...
Author: Gergely Kovacs gergo@iptel.org Committer: Gergely Kovacs gergo@iptel.org Date: Thu Aug 7 09:57:04 2008 +0000
support for automatic reconnects added
---
modules/db_ldap/ld_cfg.c | 6 ++++-- modules/db_ldap/ld_cmd.c | 38 ++++++++++++++++++++++++++++---------- modules/db_ldap/ld_mod.c | 24 +++++++++++++----------- modules/db_ldap/ld_mod.h | 12 +++++++----- 4 files changed, 52 insertions(+), 28 deletions(-)
diff --git a/modules/db_ldap/ld_cfg.c b/modules/db_ldap/ld_cfg.c index 996ce95..7ce1752 100644 --- a/modules/db_ldap/ld_cfg.c +++ b/modules/db_ldap/ld_cfg.c @@ -446,7 +446,7 @@ struct ld_con_info* ld_find_conn_info(str* conn_id) }
-int ld_cfg_validity_check(struct ld_cfg *cfg) +static int ld_cfg_validity_check(struct ld_cfg *cfg) { struct ld_cfg *pcfg;
@@ -488,8 +488,10 @@ int ld_load_cfg(str* filename) } cfg_parser_close(parser);
- if (ld_cfg_validity_check(cfg)) + if (ld_cfg_validity_check(cfg)) { + ld_cfg_free(); return -1; + }
return 0; } diff --git a/modules/db_ldap/ld_cmd.c b/modules/db_ldap/ld_cmd.c index e628796..163dd54 100644 --- a/modules/db_ldap/ld_cmd.c +++ b/modules/db_ldap/ld_cmd.c @@ -162,6 +162,7 @@ int ld_cmd_exec(db_res_t* res, db_cmd_t* cmd) char* filter, *err_desc; int ret, err; LDAPMessage* msg; + int reconn_cnt = glb_reconn_cnt;
filter = NULL; err_desc = NULL; @@ -179,16 +180,33 @@ int ld_cmd_exec(db_res_t* res, db_cmd_t* cmd) goto error; }
- ret = ldap_search_ext_s(lcon->con, lcmd->base, lcmd->scope, filter, - lcmd->result, 0, NULL, NULL, - lcmd->timelimit.tv_sec ? &lcmd->timelimit : NULL, - lcmd->sizelimit, - &msg); - - if (ret != LDAP_SUCCESS) { - ERR("ldap: Error in ldap_search: %s\n", ldap_err2string(ret)); - goto error; - } + do { + if (lcon->flags & LD_CONNECTED) { + ret = ldap_search_ext_s(lcon->con, lcmd->base, lcmd->scope, filter, + lcmd->result, 0, NULL, NULL, + lcmd->timelimit.tv_sec ? &lcmd->timelimit : NULL, + lcmd->sizelimit, + &msg); + } else { + ret = LDAP_SERVER_DOWN; + } + if (ret != LDAP_SUCCESS) { + ERR("ldap: Error in ldap_search: %s\n", ldap_err2string(ret)); + if (ret == LDAP_SERVER_DOWN) { + lcon->flags &= ~LD_CONNECTED; + do { + if (!reconn_cnt) { + ERR("ldap: maximum reconnection attempt reached! giving up\n"); + goto error; + } + reconn_cnt--; + err = ld_con_connect(con); + } while (err != 0); + } else { + goto error; + } + } + } while (ret != LDAP_SUCCESS);
ret = ldap_parse_result(lcon->con, msg, &err, NULL, &err_desc, NULL, NULL, 0); if (ret != LDAP_SUCCESS) { diff --git a/modules/db_ldap/ld_mod.c b/modules/db_ldap/ld_mod.c index a409964..8a21095 100644 --- a/modules/db_ldap/ld_mod.c +++ b/modules/db_ldap/ld_mod.c @@ -1,5 +1,5 @@ -/* - * $Id$ +/* + * $Id$ * * LDAP Database Driver for SER * @@ -18,15 +18,15 @@ * 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., + * with this program; if not, write to the Free Software Foundation, Inc., * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
/** \addtogroup ldap - * @{ + * @{ */
-/** \file +/** \file * LDAP module interface. */
@@ -49,6 +49,7 @@ #include <ldap.h>
str ld_cfg_file = STR_STATIC_INIT("ldap.cfg"); +int glb_reconn_cnt = 3;
static int ld_mod_init(void); static void ld_mod_destroy(void); @@ -82,7 +83,8 @@ static cmd_export_t cmds[] = { * Exported parameters */ static param_export_t params[] = { - {"config", PARAM_STR, &ld_cfg_file}, + {"config", PARAM_STR, &ld_cfg_file}, + {"reconnect_attempt", PARAM_INT, &glb_reconn_cnt}, {0, 0, 0} };
@@ -467,25 +469,25 @@ int ldap_test(void) case DB_BITMAP: ERR("%s: %d\n", rec->fld[i].name, rec->fld[i].v.int4); break; - + case DB_DATETIME: times = ctime(&rec->fld[i].v.time); ERR("%s: %d:%.*s\n", rec->fld[i].name, rec->fld[i].v.time, strlen(times) - 1, times); break; - + case DB_DOUBLE: ERR("%s: %f\n", rec->fld[i].name, rec->fld[i].v.dbl); break; - + case DB_FLOAT: ERR("%s: %f\n", rec->fld[i].name, rec->fld[i].v.flt); break; - + case DB_STR: case DB_BLOB: ERR("%s: %.*s\n", rec->fld[i].name, rec->fld[i].v.lstr.len, rec->fld[i].v.lstr.s); break; - + case DB_CSTR: ERR("%s: %s\n", rec->fld[i].name, rec->fld[i].v.cstr); break; diff --git a/modules/db_ldap/ld_mod.h b/modules/db_ldap/ld_mod.h index 859fabd..c0d656c 100644 --- a/modules/db_ldap/ld_mod.h +++ b/modules/db_ldap/ld_mod.h @@ -1,5 +1,5 @@ -/* - * $Id$ +/* + * $Id$ * * LDAP Database Driver for SER * @@ -18,7 +18,7 @@ * 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., + * with this program; if not, write to the Free Software Foundation, Inc., * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */
@@ -26,11 +26,13 @@ #define _LD_MOD_H
/** @defgroup ldap LDAP Database Driver - * @ingroup DB_API + * @ingroup DB_API */ /** @{ */
-/** \file +extern int glb_reconn_cnt; + +/** \file * LDAP module interface. */