[sr-dev] git:master:d419f427: lib/srdb1: support for username at domain in user id part of db url

Daniel-Constantin Mierla miconda at gmail.com
Thu Jun 27 09:39:10 CEST 2019


Module: kamailio
Branch: master
Commit: d419f427d2acf890e5e45c4f3e8e7a2b2fe4cead
URL: https://github.com/kamailio/kamailio/commit/d419f427d2acf890e5e45c4f3e8e7a2b2fe4cead

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: 2019-06-27T09:36:21+02:00

lib/srdb1: support for username at domain in user id part of db url

- used by some cloud database services
- reworked patch from GH #1992

---

Modified: src/lib/srdb1/db_id.c

---

Diff:  https://github.com/kamailio/kamailio/commit/d419f427d2acf890e5e45c4f3e8e7a2b2fe4cead.diff
Patch: https://github.com/kamailio/kamailio/commit/d419f427d2acf890e5e45c4f3e8e7a2b2fe4cead.patch

---

diff --git a/src/lib/srdb1/db_id.c b/src/lib/srdb1/db_id.c
index 9857f5a29c..35bf228a8f 100644
--- a/src/lib/srdb1/db_id.c
+++ b/src/lib/srdb1/db_id.c
@@ -107,21 +107,22 @@ static int parse_db_url(struct db_id* id, const str* url)
 	};
 
 	enum state st;
-	unsigned int len, i, j, a;
+	unsigned int len, i, j, a, foundanother;
 	const char* begin;
 	char* prev_token;
 
+	foundanother = 0;
 	prev_token = 0;
 
 	if (!id || !url || !url->s) {
 		goto err;
 	}
-	
+
 	len = url->len;
 	if (len < SHORTEST_DB_URL_LEN) {
 		goto err;
 	}
-	
+
 	/* Initialize all attributes to 0 */
 	memset(id, 0, sizeof(struct db_id));
 	st = ST_SCHEME;
@@ -155,7 +156,7 @@ static int parse_db_url(struct db_id* id, const str* url)
 				st = ST_USER_HOST;
 				begin = url->s + i + 1;
 				break;
-				
+
 			default:
 				goto err;
 			}
@@ -164,6 +165,20 @@ static int parse_db_url(struct db_id* id, const str* url)
 		case ST_USER_HOST:
 			switch(url->s[i]) {
 			case '@':
+				/* look for another @ to cope with username at domain user id */
+				if (foundanother == 0) {
+					for (j = i + 1; j < url->len; j++) {
+						if (url->s[j] == '@') {
+							foundanother = 1;
+							break;
+						}
+					}
+					if (foundanother == 1) {
+						/* keep the current @ in the username */
+						st = ST_USER_HOST;
+						break;
+					}
+				}
 				st = ST_HOST;
 				if (dupl_string(&id->username, begin, url->s + i) < 0) goto err;
 				begin = url->s + i + 1;
@@ -232,7 +247,7 @@ static int parse_db_url(struct db_id* id, const str* url)
 				return 0;
 			}
 			break;
-			
+
 		case ST_DB:
 			break;
 		}




More information about the sr-dev mailing list