Module: sip-router
Branch: master
Commit: 2dad021502d0f931fabde0e4c220baf70898a877
URL:    
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=2dad021502d0f931fabde0e4c220baf70898a877

Author: pd <[email protected]>
Committer: pd <[email protected]>
Date:   Sun Dec 18 21:13:19 2011 +0000

lib/srdb1: Enable non-pooled database connections to be defined.

- Kamailio pools database connections, but sometimes this causes
  problems.  For example, we (Crocodile) observed an issue with
  many different queries happening on the same connection while
  using db_fetch_next().
- This change enables you to specify a DB connection as non-pooled
  by putting a '*' at the start of the DB URL in kamailio.cfg.
- Feature added by Paul Pankhurst @ Crocodile RCS

---

 lib/srdb1/db.c    |   13 +++++++++++--
 lib/srdb1/db_id.c |   27 ++++++++++++++++++++++++---
 lib/srdb1/db_id.h |    1 +
 3 files changed, 36 insertions(+), 5 deletions(-)

diff --git a/lib/srdb1/db.c b/lib/srdb1/db.c
index 892a849..5905bb0 100644
--- a/lib/srdb1/db.c
+++ b/lib/srdb1/db.c
@@ -182,8 +182,17 @@ int db_bind_mod(const str* mod, db_func_t* mydbf)
                return -1;
        }
        memcpy(name, "db_", 3);
-       memcpy(name+3, mod->s, mod->len);
-       name[mod->len+3] = 0;
+
+       if (mod->s[0]=='*' )
+       {
+               memcpy(name+3, (mod->s)+1, (mod->len)-1);
+               name[mod->len-1+3] = 0;
+       }
+       else
+       {
+               memcpy(name+3, mod->s, mod->len);
+               name[mod->len+3] = 0;
+       }
 
        /* for safety we initialize mydbf with 0 (this will cause
         *  a segfault immediately if someone tries to call a function
diff --git a/lib/srdb1/db_id.c b/lib/srdb1/db_id.c
index 8c8b2a3..4aa564b 100644
--- a/lib/srdb1/db_id.c
+++ b/lib/srdb1/db_id.c
@@ -65,12 +65,13 @@ static int dupl_string(char** dst, const char* begin, const 
char* end)
  * \param url parsed URL
  * \return 0 if parsing was successful and -1 otherwise
  */
-static int parse_db_url(struct db_id* id, const str* url)
+static int parse_db_url(struct db_id* id, const str* url, int *poolid )
 {
 #define SHORTEST_DB_URL "s://a/b"
 #define SHORTEST_DB_URL_LEN (sizeof(SHORTEST_DB_URL) - 1)
 
        enum state {
+               ST_NONPOOL,    /* Non pooling flag */
                ST_SCHEME,     /* Scheme part */
                ST_SLASH1,     /* First slash */
                ST_SLASH2,     /* Second slash */
@@ -99,11 +100,25 @@ static int parse_db_url(struct db_id* id, const str* url)
        
        /* Initialize all attributes to 0 */
        memset(id, 0, sizeof(struct db_id));
-       st = ST_SCHEME;
+       st = ST_NONPOOL;
        begin = url->s;
 
        for(i = 0; i < len; i++) {
                switch(st) {
+               case ST_NONPOOL:
+                       st = ST_SCHEME;
+                       switch(url->s[i]) {
+                       case '*':
+                               id->poolid = ++(*poolid);
+                               begin++;
+                               break;
+
+                       default:
+                               id->poolid = 0;
+                               break;
+                       }
+                       break;
+
                case ST_SCHEME:
                        switch(url->s[i]) {
                        case ':':
@@ -229,6 +244,7 @@ static int parse_db_url(struct db_id* id, const str* url)
  */
 struct db_id* new_db_id(const str* url)
 {
+       static int poolid=0;
        struct db_id* ptr;
 
        if (!url || !url->s) {
@@ -243,7 +259,7 @@ struct db_id* new_db_id(const str* url)
        }
        memset(ptr, 0, sizeof(struct db_id));
 
-       if (parse_db_url(ptr, url) < 0) {
+       if (parse_db_url(ptr, url, &poolid) < 0) {
                LM_ERR("error while parsing database URL: '%.*s' \n", url->len, 
url->s);
                goto err;
        }
@@ -286,6 +302,11 @@ unsigned char cmp_db_id(const struct db_id* id1, const 
struct db_id* id2)
                                id1->pid, id2->pid);
                return 0;
        }
+       if(id1->poolid!=id2->poolid) {
+               LM_DBG("identical DB URLs, but different poolids [%d/%d]\n",
+                               id1->poolid, id2->poolid);
+               return 0;
+       }
        return 1;
 }
 
diff --git a/lib/srdb1/db_id.h b/lib/srdb1/db_id.h
index 20ab846..b7427a7 100644
--- a/lib/srdb1/db_id.h
+++ b/lib/srdb1/db_id.h
@@ -41,6 +41,7 @@ struct db_id {
        unsigned short port; /**< Port number */
        char* database;      /**< Database, case sensitive */
        int   pid;           /**< Process ID (detect cross connections) */
+       int   poolid;        /**< poolid within a pid */
 };
 
 


_______________________________________________
sr-dev mailing list
[email protected]
http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev

Reply via email to