Browse code

usrloc: set tcp connection id to -1 for records added via rpc

- cope properly with the handle_lost_tcp modparam

Daniel-Constantin Mierla authored on 09/09/2021 07:11:06
Showing 1 changed files
... ...
@@ -678,6 +678,7 @@ static void ul_rpc_add(rpc_t* rpc, void* ctx)
678 678
 	}
679 679
 	ci.ruid = _ul_sruid.uid;
680 680
 	ci.server_id = server_id;
681
+	ci.tcpconn_id = -1;
681 682
 
682 683
 	lock_udomain(dom, &aor);
683 684
 
Browse code

usrloc: adjusted rpc reply text when the location domain table is not found

Daniel-Constantin Mierla authored on 09/03/2021 11:27:10
Showing 1 changed files
... ...
@@ -402,7 +402,7 @@ static void ul_rpc_lookup(rpc_t* rpc, void* ctx)
402 402
 	/* look for table */
403 403
 	dom = rpc_find_domain( &table );
404 404
 	if (dom == NULL) {
405
-		rpc->fault(ctx, 500, "Domain not found");
405
+		rpc->fault(ctx, 500, "Domain table not found");
406 406
 		return;
407 407
 	}
408 408
 
... ...
@@ -476,7 +476,7 @@ static void ul_rpc_rm_aor(rpc_t* rpc, void* ctx)
476 476
 	/* look for table */
477 477
 	dom = rpc_find_domain( &table );
478 478
 	if (dom == NULL) {
479
-		rpc->fault(ctx, 500, "Domain not found");
479
+		rpc->fault(ctx, 500, "Domain table not found");
480 480
 		return;
481 481
 	}
482 482
 
... ...
@@ -520,7 +520,7 @@ static void ul_rpc_rm_contact(rpc_t* rpc, void* ctx)
520 520
 	/* look for table */
521 521
 	dom = rpc_find_domain( &table );
522 522
 	if (dom == NULL) {
523
-		rpc->fault(ctx, 500, "Domain not found");
523
+		rpc->fault(ctx, 500, "Domain table not found");
524 524
 		return;
525 525
 	}
526 526
 
... ...
@@ -661,7 +661,7 @@ static void ul_rpc_add(rpc_t* rpc, void* ctx)
661 661
 	/* look for table */
662 662
 	dom = rpc_find_domain( &table );
663 663
 	if (dom == NULL) {
664
-		rpc->fault(ctx, 500, "Domain not found");
664
+		rpc->fault(ctx, 500, "Domain table not found");
665 665
 		return;
666 666
 	}
667 667
 
Browse code

usrloc: use unsigned int for rpc output for the fields having this type

Daniel-Constantin Mierla authored on 21/09/2020 08:59:34
Showing 1 changed files
... ...
@@ -144,12 +144,12 @@ int rpc_dump_contact(rpc_t* rpc, void* ctx, void *ih, ucontact_t* c)
144 144
 		rpc->fault(ctx, 500, "Internal error adding state");
145 145
 		return -1;
146 146
 	}
147
-	if(rpc->struct_add(vh, "d", "Flags", c->flags)<0)
147
+	if(rpc->struct_add(vh, "u", "Flags", c->flags)<0)
148 148
 	{
149 149
 		rpc->fault(ctx, 500, "Internal error adding flags");
150 150
 		return -1;
151 151
 	}
152
-	if(rpc->struct_add(vh, "d", "CFlags", c->cflags)<0)
152
+	if(rpc->struct_add(vh, "u", "CFlags", c->cflags)<0)
153 153
 	{
154 154
 		rpc->fault(ctx, 500, "Internal error adding cflags");
155 155
 		return -1;
... ...
@@ -159,7 +159,7 @@ int rpc_dump_contact(rpc_t* rpc, void* ctx, void *ih, ucontact_t* c)
159 159
 		rpc->fault(ctx, 500, "Internal error adding socket");
160 160
 		return -1;
161 161
 	}
162
-	if(rpc->struct_add(vh, "d", "Methods", c->methods)<0)
162
+	if(rpc->struct_add(vh, "u", "Methods", c->methods)<0)
163 163
 	{
164 164
 		rpc->fault(ctx, 500, "Internal error adding methods");
165 165
 		return -1;
... ...
@@ -175,7 +175,7 @@ int rpc_dump_contact(rpc_t* rpc, void* ctx, void *ih, ucontact_t* c)
175 175
 		rpc->fault(ctx, 500, "Internal error adding instance");
176 176
 		return -1;
177 177
 	}
178
-	if(rpc->struct_add(vh, "d", "Reg-Id", c->reg_id)<0)
178
+	if(rpc->struct_add(vh, "u", "Reg-Id", c->reg_id)<0)
179 179
 	{
180 180
 		rpc->fault(ctx, 500, "Internal error adding reg_id");
181 181
 		return -1;
... ...
@@ -286,7 +286,7 @@ static void ul_rpc_dump(rpc_t* rpc, void* ctx)
286 286
 						rpc->fault(ctx, 500, "Internal error creating aor struct");
287 287
 						return;
288 288
 					}
289
-					if(rpc->struct_add(bh, "Sd[",
289
+					if(rpc->struct_add(bh, "Su[",
290 290
 								"AoR", &r->aor,
291 291
 								"HashID", r->aorhash,
292 292
 								"Contacts", &ih)<0)
Browse code

usrloc: rpc scan flags, cflags and methods fields as unsigned int

Daniel-Constantin Mierla authored on 02/07/2020 07:10:48
Showing 1 changed files
... ...
@@ -623,7 +623,7 @@ static void ul_rpc_add(rpc_t* rpc, void* ctx)
623 623
 
624 624
 	memset(&ci, 0, sizeof(ucontact_info_t));
625 625
 
626
-	ret = rpc->scan(ctx, "SSSdfSddd*SS", &table, &aor, &contact, &ci.expires,
626
+	ret = rpc->scan(ctx, "SSSdfSuuu*SS", &table, &aor, &contact, &ci.expires,
627 627
 			&dtemp, &path, &ci.flags, &ci.cflags, &ci.methods, &received,
628 628
 			&socket);
629 629
 	if (ret < 9) {
Browse code

usrloc: use ul prefix for global param variables

Daniel-Constantin Mierla authored on 01/05/2020 12:47:55
Showing 1 changed files
... ...
@@ -359,7 +359,7 @@ static inline int rpc_fix_aor(str *aor)
359 359
 	char *p;
360 360
 
361 361
 	p = memchr( aor->s, '@', aor->len);
362
-	if (use_domain) {
362
+	if (ul_use_domain) {
363 363
 		if (p==NULL)
364 364
 			return -1;
365 365
 	} else {
... ...
@@ -421,7 +421,7 @@ static void ul_rpc_lookup(rpc_t* rpc, void* ctx)
421 421
 		return;
422 422
 	}
423 423
 
424
-	get_act_time();
424
+	ul_get_act_time();
425 425
 	rpl_tree = 0;
426 426
 
427 427
 	if (rpc->add(ctx, "{", &th) < 0)
... ...
@@ -443,7 +443,7 @@ static void ul_rpc_lookup(rpc_t* rpc, void* ctx)
443 443
 
444 444
 	/* We have contacts, list them */
445 445
 	for( con=rec->contacts ; con ; con=con->next) {
446
-		if (VALID_CONTACT( con, act_time)) {
446
+		if (VALID_CONTACT(con, ul_act_time)) {
447 447
 			rpl_tree++;
448 448
 			if (rpc_dump_contact(rpc, ctx, ih, con) == -1) {
449 449
 				release_urecord(rec);
... ...
@@ -700,14 +700,14 @@ static void ul_rpc_add(rpc_t* rpc, void* ctx)
700 700
 		}
701 701
 	}
702 702
 
703
-	get_act_time();
703
+	ul_get_act_time();
704 704
 
705 705
 	ci.callid = &rpc_ul_cid;
706 706
 	ci.user_agent = &rpc_ul_ua;
707 707
 	ci.cseq = RPC_UL_CSEQ;
708 708
 	/* 0 expires means permanent contact */
709 709
 	if (ci.expires!=0)
710
-		ci.expires += act_time;
710
+		ci.expires += ul_act_time;
711 711
 
712 712
 	if (c) {
713 713
 		if (update_ucontact( r, c, &ci) < 0)
... ...
@@ -747,7 +747,7 @@ static void ul_rpc_db_users(rpc_t* rpc, void* ctx)
747 747
 	db1_res_t* res = NULL;
748 748
 	int count = 0;
749 749
 
750
-	if (db_mode == NO_DB) {
750
+	if (ul_db_mode == NO_DB) {
751 751
 		rpc->fault(ctx, 500, "Command is not supported in db_mode=0");
752 752
 		return;
753 753
 	}
... ...
@@ -757,7 +757,7 @@ static void ul_rpc_db_users(rpc_t* rpc, void* ctx)
757 757
 		return;
758 758
 	}
759 759
 
760
-	if (user_col.len + domain_col.len + table.len + 32 > QUERY_LEN) {
760
+	if (ul_user_col.len + ul_domain_col.len + table.len + 32 > QUERY_LEN) {
761 761
 		rpc->fault(ctx, 500, "Too long database query");
762 762
 		return;
763 763
 	}
... ...
@@ -774,8 +774,8 @@ static void ul_rpc_db_users(rpc_t* rpc, void* ctx)
774 774
 	memset(query, 0, QUERY_LEN);
775 775
 	query_str.len = snprintf(query, QUERY_LEN,
776 776
 			"SELECT COUNT(DISTINCT %.*s, %.*s) FROM %.*s WHERE (UNIX_TIMESTAMP(expires) = 0) OR (expires > NOW())",
777
-			user_col.len, user_col.s,
778
-			domain_col.len, domain_col.s,
777
+			ul_user_col.len, ul_user_col.s,
778
+			ul_domain_col.len, ul_domain_col.s,
779 779
 			table.len, table.s);
780 780
 	query_str.s = query;
781 781
 	if (ul_dbf.raw_query(ul_dbh, &query_str, &res) < 0 || res==NULL) {
... ...
@@ -803,7 +803,7 @@ static void ul_rpc_db_contacts(rpc_t* rpc, void* ctx)
803 803
 	db1_res_t* res = NULL;
804 804
 	int count = 0;
805 805
 
806
-	if (db_mode == NO_DB) {
806
+	if (ul_db_mode == NO_DB) {
807 807
 		rpc->fault(ctx, 500, "Command is not supported in db_mode=0");
808 808
 		return;
809 809
 	}
... ...
@@ -857,7 +857,7 @@ static void ul_rpc_db_expired_contacts(rpc_t* rpc, void* ctx)
857 857
 	db1_res_t* res = NULL;
858 858
 	int count = 0;
859 859
 
860
-	if (db_mode == NO_DB) {
860
+	if (ul_db_mode == NO_DB) {
861 861
 		rpc->fault(ctx, 500, "Command is not supported in db_mode=0");
862 862
 		return;
863 863
 	}
Browse code

usrloc: global root var for domains list renamed to _ksr_ul_root

Daniel-Constantin Mierla authored on 27/03/2020 12:58:56
Showing 1 changed files
... ...
@@ -246,7 +246,7 @@ static void ul_rpc_dump(rpc_t* rpc, void* ctx)
246 246
 		return;
247 247
 	}
248 248
 	
249
-	for( dl=root ; dl ; dl=dl->next ) {
249
+	for( dl=_ksr_ul_root ; dl ; dl=dl->next ) {
250 250
 		dom = dl->d;
251 251
 
252 252
 		if (rpc->struct_add(dah, "{", "Domain", &dh) < 0)
... ...
@@ -338,7 +338,7 @@ static inline udomain_t* rpc_find_domain(str* table)
338 338
 {
339 339
 	dlist_t* dom;
340 340
 
341
-	for( dom=root ; dom ; dom=dom->next ) {
341
+	for( dom=_ksr_ul_root ; dom ; dom=dom->next ) {
342 342
 		if ((dom->name.len == table->len) &&
343 343
 				!memcmp(dom->name.s, table->s, table->len))
344 344
 			return dom->d;
Browse code

usrloc: print ka roundtrip via rpc dump command

Daniel-Constantin Mierla authored on 27/03/2020 08:12:34
Showing 1 changed files
... ...
@@ -200,6 +200,11 @@ int rpc_dump_contact(rpc_t* rpc, void* ctx, void *ih, ucontact_t* c)
200 200
 		rpc->fault(ctx, 500, "Internal error adding last_keepalive");
201 201
 		return -1;
202 202
 	}
203
+	if(rpc->struct_add(vh, "d", "KA-Roundtrip", (int)c->ka_roundtrip)<0)
204
+	{
205
+		rpc->fault(ctx, 500, "Internal error adding keepalive roundtrip");
206
+		return -1;
207
+	}
203 208
 	if(rpc->struct_add(vh, "d", "Last-Modified", (int)c->last_modified)<0)
204 209
 	{
205 210
 		rpc->fault(ctx, 500, "Internal error adding last_modified");
Browse code

usrloc: updated with relocation of lib/srutils to core/utils

Daniel-Constantin Mierla authored on 21/01/2020 13:41:52
Showing 1 changed files
... ...
@@ -19,7 +19,7 @@
19 19
 #include "../../core/ip_addr.h"
20 20
 #include "../../core/dprint.h"
21 21
 #include "../../core/dset.h"
22
-#include "../../lib/srutils/sruid.h"
22
+#include "../../core/utils/sruid.h"
23 23
 
24 24
 #include "ul_rpc.h"
25 25
 #include "dlist.h"
Browse code

usrloc: fix memory leak on DB_ONLY mode on RPC commands

Victor Seva authored on 28/06/2019 15:06:54 • Henning Westerholt committed on 02/07/2019 19:41:59
Showing 1 changed files
... ...
@@ -421,6 +421,7 @@ static void ul_rpc_lookup(rpc_t* rpc, void* ctx)
421 421
 
422 422
 	if (rpc->add(ctx, "{", &th) < 0)
423 423
 	{
424
+		release_urecord(rec);
424 425
 		unlock_udomain(dom, &aor);
425 426
 		rpc->fault(ctx, 500, "Internal error creating outer rpc");
426 427
 		return;
... ...
@@ -429,6 +430,7 @@ static void ul_rpc_lookup(rpc_t* rpc, void* ctx)
429 430
 				"AoR", &aor,
430 431
 				"Contacts", &ih)<0)
431 432
 	{
433
+		release_urecord(rec);
432 434
 		unlock_udomain(dom, &aor);
433 435
 		rpc->fault(ctx, 500, "Internal error creating aor struct");
434 436
 		return;
... ...
@@ -439,12 +441,13 @@ static void ul_rpc_lookup(rpc_t* rpc, void* ctx)
439 441
 		if (VALID_CONTACT( con, act_time)) {
440 442
 			rpl_tree++;
441 443
 			if (rpc_dump_contact(rpc, ctx, ih, con) == -1) {
444
+				release_urecord(rec);
442 445
 				unlock_udomain(dom, &aor);
443 446
 				return;
444 447
 			}
445 448
 		}
446 449
 	}
447
-
450
+	release_urecord(rec);
448 451
 	unlock_udomain( dom, &aor);
449 452
 
450 453
 	if (rpl_tree==0) {
... ...
@@ -533,17 +536,20 @@ static void ul_rpc_rm_contact(rpc_t* rpc, void* ctx)
533 536
 
534 537
 	ret = get_ucontact( rec, &contact, &rpc_ul_cid, &rpc_ul_path, RPC_UL_CSEQ+1, &con);
535 538
 	if (ret < 0) {
539
+		release_urecord(rec);
536 540
 		unlock_udomain( dom, &aor);
537 541
 		rpc->fault(ctx, 500, "Internal error (can't get contact)");
538 542
 		return;
539 543
 	}
540 544
 	if (ret > 0) {
545
+		release_urecord(rec);
541 546
 		unlock_udomain( dom, &aor);
542 547
 		rpc->fault(ctx, 404, "Contact not found");
543 548
 		return;
544 549
 	}
545 550
 
546 551
 	if (delete_ucontact(rec, con) < 0) {
552
+		release_urecord(rec);
547 553
 		unlock_udomain( dom, &aor);
548 554
 		rpc->fault(ctx, 500, "Internal error (can't delete contact)");
549 555
 		return;
Browse code

usrloc: safety checks for query result in db rpc functions

- GH #1900

Daniel-Constantin Mierla authored on 21/03/2019 12:48:25
Showing 1 changed files
... ...
@@ -733,8 +733,8 @@ static void ul_rpc_db_users(rpc_t* rpc, void* ctx)
733 733
 	str table = {0, 0};
734 734
 	char query[QUERY_LEN];
735 735
 	str query_str;
736
-	db1_res_t* res;
737
-	int count;
736
+	db1_res_t* res = NULL;
737
+	int count = 0;
738 738
 
739 739
 	if (db_mode == NO_DB) {
740 740
 		rpc->fault(ctx, 500, "Command is not supported in db_mode=0");
... ...
@@ -767,12 +767,13 @@ static void ul_rpc_db_users(rpc_t* rpc, void* ctx)
767 767
 			domain_col.len, domain_col.s,
768 768
 			table.len, table.s);
769 769
 	query_str.s = query;
770
-	if (ul_dbf.raw_query(ul_dbh, &query_str, &res) < 0) {
770
+	if (ul_dbf.raw_query(ul_dbh, &query_str, &res) < 0 || res==NULL) {
771 771
 		rpc->fault(ctx, 500, "Failed to query AoR count");
772 772
 		return;
773 773
 	}
774
-
775
-	count = (int)VAL_INT(ROW_VALUES(RES_ROWS(res)));
774
+	if (RES_ROW_N(res) > 0) {
775
+		count = (int)VAL_INT(ROW_VALUES(RES_ROWS(res)));
776
+	}
776 777
 	ul_dbf.free_result(ul_dbh, res);
777 778
 
778 779
 	rpc->add(ctx, "d", count);
... ...
@@ -788,8 +789,8 @@ static void ul_rpc_db_contacts(rpc_t* rpc, void* ctx)
788 789
 	str table = {0, 0};
789 790
 	char query[QUERY_LEN];
790 791
 	str query_str;
791
-	db1_res_t* res;
792
-	int count;
792
+	db1_res_t* res = NULL;
793
+	int count = 0;
793 794
 
794 795
 	if (db_mode == NO_DB) {
795 796
 		rpc->fault(ctx, 500, "Command is not supported in db_mode=0");
... ...
@@ -819,12 +820,14 @@ static void ul_rpc_db_contacts(rpc_t* rpc, void* ctx)
819 820
 	query_str.len = snprintf(query, QUERY_LEN, "SELECT COUNT(*) FROM %.*s WHERE (UNIX_TIMESTAMP(expires) = 0) OR (expires > NOW())",
820 821
 			table.len, table.s);
821 822
 	query_str.s = query;
822
-	if (ul_dbf.raw_query(ul_dbh, &query_str, &res) < 0) {
823
+	if (ul_dbf.raw_query(ul_dbh, &query_str, &res) < 0 || res==NULL) {
823 824
 		rpc->fault(ctx, 500, "Failed to query contact count");
824 825
 		return;
825 826
 	}
826 827
 
827
-	count = (int)VAL_INT(ROW_VALUES(RES_ROWS(res)));
828
+	if (RES_ROW_N(res) > 0) {
829
+		count = (int)VAL_INT(ROW_VALUES(RES_ROWS(res)));
830
+	}
828 831
 	ul_dbf.free_result(ul_dbh, res);
829 832
 
830 833
 	rpc->add(ctx, "d", count);
... ...
@@ -840,8 +843,8 @@ static void ul_rpc_db_expired_contacts(rpc_t* rpc, void* ctx)
840 843
 	str table = {0, 0};
841 844
 	char query[QUERY_LEN];
842 845
 	str query_str;
843
-	db1_res_t* res;
844
-	int count;
846
+	db1_res_t* res = NULL;
847
+	int count = 0;
845 848
 
846 849
 	if (db_mode == NO_DB) {
847 850
 		rpc->fault(ctx, 500, "Command is not supported in db_mode=0");
... ...
@@ -871,12 +874,14 @@ static void ul_rpc_db_expired_contacts(rpc_t* rpc, void* ctx)
871 874
 	query_str.len = snprintf(query, QUERY_LEN, "SELECT COUNT(*) FROM %.*s WHERE (UNIX_TIMESTAMP(expires) > 0) AND (expires <= NOW())",
872 875
 			table.len, table.s);
873 876
 	query_str.s = query;
874
-	if (ul_dbf.raw_query(ul_dbh, &query_str, &res) < 0) {
877
+	if (ul_dbf.raw_query(ul_dbh, &query_str, &res) < 0 || res==NULL) {
875 878
 		rpc->fault(ctx, 500, "Failed to query contact count");
876 879
 		return;
877 880
 	}
878 881
 
879
-	count = (int)VAL_INT(ROW_VALUES(RES_ROWS(res)));
882
+	if (RES_ROW_N(res) > 0) {
883
+		count = (int)VAL_INT(ROW_VALUES(RES_ROWS(res)));
884
+	}
880 885
 	ul_dbf.free_result(ul_dbh, res);
881 886
 
882 887
 	rpc->add(ctx, "d", count);
Browse code

usrloc: use sruid_next_safe()

Daniel-Constantin Mierla authored on 19/09/2018 06:11:36
Showing 1 changed files
... ...
@@ -660,7 +660,7 @@ static void ul_rpc_add(rpc_t* rpc, void* ctx)
660 660
 		return;
661 661
 	}
662 662
 
663
-	if(sruid_next(&_ul_sruid)<0)
663
+	if(sruid_next_safe(&_ul_sruid)<0)
664 664
 	{
665 665
 		rpc->fault(ctx, 500, "Can't obtain next uid");
666 666
 		return;
Browse code

usrloc: set server_id for rpc ul add command

Daniel-Constantin Mierla authored on 13/08/2018 09:31:25
Showing 1 changed files
... ...
@@ -666,6 +666,7 @@ static void ul_rpc_add(rpc_t* rpc, void* ctx)
666 666
 		return;
667 667
 	}
668 668
 	ci.ruid = _ul_sruid.uid;
669
+	ci.server_id = server_id;
669 670
 
670 671
 	lock_udomain(dom, &aor);
671 672
 
Browse code

usrloc: fix RPC ul.add optional received param value when unset

fix #1586

Victor Seva authored on 11/07/2018 09:39:20
Showing 1 changed files
... ...
@@ -600,6 +600,7 @@ static void ul_rpc_add(rpc_t* rpc, void* ctx)
600 600
 	str aor = {0, 0};
601 601
 	str contact = {0, 0};
602 602
 	str path = {0, 0};
603
+	str received = {0, 0};
603 604
 	str socket = {0, 0};
604 605
 	str temp = {0, 0};
605 606
 	double dtemp;
... ...
@@ -612,7 +613,7 @@ static void ul_rpc_add(rpc_t* rpc, void* ctx)
612 613
 	memset(&ci, 0, sizeof(ucontact_info_t));
613 614
 
614 615
 	ret = rpc->scan(ctx, "SSSdfSddd*SS", &table, &aor, &contact, &ci.expires,
615
-			&dtemp, &path, &ci.flags, &ci.cflags, &ci.methods, &ci.received,
616
+			&dtemp, &path, &ci.flags, &ci.cflags, &ci.methods, &received,
616 617
 			&socket);
617 618
 	if (ret < 9) {
618 619
 		LM_ERR("not enough parameters - read so far: %d\n", ret);
... ...
@@ -626,9 +627,9 @@ static void ul_rpc_add(rpc_t* rpc, void* ctx)
626 627
 	}
627 628
 	if(ret>9) {
628 629
 		/* received parameter */
629
-		if(!ul_rpc_is_param_set(&ci.received)) {
630
-			ci.received.s = 0;
631
-			ci.received.len = 0;
630
+		if(ul_rpc_is_param_set(&received)) {
631
+			ci.received.s = received.s;
632
+			ci.received.len = received.len;
632 633
 		}
633 634
 	}
634 635
 	if(ret>10) {
Browse code

usrloc: fix format of the ul.dump json reply

- create "Domains" array instead of a single "Domain" object.

Vitaliy Aleksandrov authored on 19/10/2017 13:00:32
Showing 1 changed files
... ...
@@ -217,6 +217,8 @@ static void ul_rpc_dump(rpc_t* rpc, void* ctx)
217 217
 	int summary = 0;
218 218
 	ucontact_t* c;
219 219
 	void* th;
220
+	void* dah;
221
+	void* dh;
220 222
 	void* ah;
221 223
 	void* bh;
222 224
 	void* ih;
... ...
@@ -228,14 +230,27 @@ static void ul_rpc_dump(rpc_t* rpc, void* ctx)
228 230
 	if(brief.len==5 && (strncmp(brief.s, "brief", 5)==0))
229 231
 		summary = 1;
230 232
 
233
+	if (rpc->add(ctx, "{", &th) < 0)
234
+	{
235
+		rpc->fault(ctx, 500, "Internal error creating top rpc");
236
+		return;
237
+	}
238
+	if (rpc->struct_add(th, "[", "Domains", &dah) < 0)
239
+	{
240
+		rpc->fault(ctx, 500, "Internal error creating inner struct");
241
+		return;
242
+	}
243
+	
231 244
 	for( dl=root ; dl ; dl=dl->next ) {
232 245
 		dom = dl->d;
233
-		if (rpc->add(ctx, "{", &th) < 0)
246
+
247
+		if (rpc->struct_add(dah, "{", "Domain", &dh) < 0)
234 248
 		{
235
-			rpc->fault(ctx, 500, "Internal error creating top rpc");
249
+			rpc->fault(ctx, 500, "Internal error creating inner struct");
236 250
 			return;
237 251
 		}
238
-		if(rpc->struct_add(th, "Sd[",
252
+
253
+		if(rpc->struct_add(dh, "Sd[",
239 254
 					"Domain",  &dl->name,
240 255
 					"Size",    (int)dom->size,
241 256
 					"AoRs",    &ah)<0)
... ...
@@ -289,7 +304,7 @@ static void ul_rpc_dump(rpc_t* rpc, void* ctx)
289 304
 		}
290 305
 
291 306
 		/* extra attributes node */
292
-		if(rpc->struct_add(th, "{", "Stats",    &sh)<0)
307
+		if(rpc->struct_add(dh, "{", "Stats",    &sh)<0)
293 308
 		{
294 309
 			rpc->fault(ctx, 500, "Internal error creating stats struct");
295 310
 			return;
Browse code

usrloc: fix usrloc slot lock in ul.dump rpc procedure

- unlock usrloc slot when "ul.dump brief" fails during aor struct creation

Vitaliy Aleksandrov authored on 20/10/2017 12:39:30
Showing 1 changed files
... ...
@@ -254,6 +254,7 @@ static void ul_rpc_dump(rpc_t* rpc, void* ctx)
254 254
 					if(rpc->struct_add(ah, "S",
255 255
 								"AoR", &r->aor)<0)
256 256
 					{
257
+						unlock_ulslot( dom, i);
257 258
 						rpc->fault(ctx, 500, "Internal error creating aor struct");
258 259
 						return;
259 260
 					}
Browse code

usrloc: log message when rpc ul.add does not get proper params

Daniel-Constantin Mierla authored on 18/10/2017 16:35:31
Showing 1 changed files
... ...
@@ -599,6 +599,7 @@ static void ul_rpc_add(rpc_t* rpc, void* ctx)
599 599
 			&dtemp, &path, &ci.flags, &ci.cflags, &ci.methods, &ci.received,
600 600
 			&socket);
601 601
 	if (ret < 9) {
602
+		LM_ERR("not enough parameters - read so far: %d\n", ret);
602 603
 		rpc->fault(ctx, 500, "Not enough parameters or wrong format");
603 604
 		return;
604 605
 	}
Browse code

usrloc: rpc ul.add can set also received and socket fields

Daniel-Constantin Mierla authored on 17/09/2017 08:49:18
Showing 1 changed files
... ...
@@ -584,7 +584,6 @@ static void ul_rpc_add(rpc_t* rpc, void* ctx)
584 584
 	str aor = {0, 0};
585 585
 	str contact = {0, 0};
586 586
 	str path = {0, 0};
587
-	str received = {0, 0};
588 587
 	str socket = {0, 0};
589 588
 	str temp = {0, 0};
590 589
 	double dtemp;
... ...
@@ -594,11 +593,12 @@ static void ul_rpc_add(rpc_t* rpc, void* ctx)
594 593
 	udomain_t *dom;
595 594
 	int ret;
596 595
 
597
-	memset( &ci, 0, sizeof(ucontact_info_t));
596
+	memset(&ci, 0, sizeof(ucontact_info_t));
598 597
 
599
-	ret = rpc->scan(ctx, "SSSdfSddd", &table, &aor, &contact, &ci.expires,
600
-			&dtemp, &path, &ci.flags, &ci.cflags, &ci.methods);
601
-	if ( ret != 9) {
598
+	ret = rpc->scan(ctx, "SSSdfSddd*SS", &table, &aor, &contact, &ci.expires,
599
+			&dtemp, &path, &ci.flags, &ci.cflags, &ci.methods, &ci.received,
600
+			&socket);
601
+	if (ret < 9) {
602 602
 		rpc->fault(ctx, 500, "Not enough parameters or wrong format");
603 603
 		return;
604 604
 	}
... ...
@@ -607,6 +607,19 @@ static void ul_rpc_add(rpc_t* rpc, void* ctx)
607 607
 	} else {
608 608
 		LM_DBG("path == 0 -> unset\n");
609 609
 	}
610
+	if(ret>9) {
611
+		/* received parameter */
612
+		if(!ul_rpc_is_param_set(&ci.received)) {
613
+			ci.received.s = 0;
614
+			ci.received.len = 0;
615
+		}
616
+	}
617
+	if(ret>10) {
618
+		/* socket parameter */
619
+		if(ul_rpc_is_param_set(&socket)) {
620
+			ci.sock = lookup_local_socket(&socket);
621
+		}
622
+	}
610 623
 	LM_DBG("ret: %d table:%.*s aor:%.*s contact:%.*s expires:%d"
611 624
 			" dtemp:%f path:%.*s flags:%d bflags:%d methods:%d\n",
612 625
 			ret, table.len, table.s, aor.len, aor.s, contact.len, contact.s,
... ...
@@ -624,7 +637,7 @@ static void ul_rpc_add(rpc_t* rpc, void* ctx)
624 637
 	}
625 638
 
626 639
 	/* process the aor */
627
-	if ( rpc_fix_aor(&aor) != 0 ) {
640
+	if (rpc_fix_aor(&aor) != 0 ) {
628 641
 		rpc->fault(ctx, 500, "Domain missing in AOR");
629 642
 		return;
630 643
 	}
... ...
@@ -636,13 +649,13 @@ static void ul_rpc_add(rpc_t* rpc, void* ctx)
636 649
 	}
637 650
 	ci.ruid = _ul_sruid.uid;
638 651
 
639
-	lock_udomain( dom, &aor);
652
+	lock_udomain(dom, &aor);
640 653
 
641
-	ret = get_urecord( dom, &aor, &r);
654
+	ret = get_urecord(dom, &aor, &r);
642 655
 	if(ret==1) {
643
-		if (insert_urecord( dom, &aor, &r) < 0)
656
+		if (insert_urecord(dom, &aor, &r) < 0)
644 657
 		{
645
-			unlock_udomain( dom, &aor);
658
+			unlock_udomain(dom, &aor);
646 659
 			rpc->fault(ctx, 500, "Can't insert record");
647 660
 			return;
648 661
 		}
... ...
@@ -651,7 +664,7 @@ static void ul_rpc_add(rpc_t* rpc, void* ctx)
651 664
 		if (get_ucontact( r, &contact, &rpc_ul_cid, &rpc_ul_path,
652 665
 					RPC_UL_CSEQ+1, &c) < 0)
653 666
 		{
654
-			unlock_udomain( dom, &aor);
667
+			unlock_udomain(dom, &aor);
655 668
 			rpc->fault(ctx, 500, "Can't get record");
656 669
 			return;
657 670
 		}
... ...
@@ -670,22 +683,22 @@ static void ul_rpc_add(rpc_t* rpc, void* ctx)
670 683
 		if (update_ucontact( r, c, &ci) < 0)
671 684
 		{
672 685
 			release_urecord(r);
673
-			unlock_udomain( dom, &aor);
686
+			unlock_udomain(dom, &aor);
674 687
 			rpc->fault(ctx, 500, "Can't update contact");
675 688
 			return;
676 689
 		}
677 690
 	} else {
678
-		if ( insert_ucontact( r, &contact, &ci, &c) < 0 )
691
+		if ( insert_ucontact(r, &contact, &ci, &c) < 0 )
679 692
 		{
680 693
 			release_urecord(r);
681
-			unlock_udomain( dom, &aor);
694
+			unlock_udomain(dom, &aor);
682 695
 			rpc->fault(ctx, 500, "Can't insert contact");
683 696
 			return;
684 697
 		}
685 698
 	}
686 699
 
687 700
 	release_urecord(r);
688
-	unlock_udomain( dom, &aor);
701
+	unlock_udomain(dom, &aor);
689 702
 	return;
690 703
 }
691 704
 
Browse code

usrloc: helper function to test if a rpc parameter is set or not

- useful for optional parameters which can be given '0' or '.' value to
indicate that it is not intended to be set

Daniel-Constantin Mierla authored on 17/09/2017 08:26:18
Showing 1 changed files
... ...
@@ -556,6 +556,23 @@ static const char* ul_rpc_flush_doc[2] = {
556 556
 	0
557 557
 };
558 558
 
559
+/**
560
+ * test if a rpc parameter is set
561
+ * - used for optional parameters which can be given '.' or '0' value
562
+ *   in order to indicate is not intended to be set
563
+ * - return: 1 if parameter is set; 0 if parameter is not set
564
+ */
565
+int ul_rpc_is_param_set(str *p)
566
+{
567
+	if(p==NULL || p->len==0 || p->s==NULL)
568
+		return 0;
569
+	if(p->len>1)
570
+		return 1;
571
+	if((strncmp(p->s, ".", 1)==0) || (strncmp(p->s, "0", 1)==0))
572
+		return 0;
573
+	return 1;
574
+}
575
+
559 576
 /*!
560 577
  * \brief Add a new contact for an address of record
561 578
  * \note Expects 9 parameters: table name, AOR, contact, expires, Q,
... ...
@@ -567,6 +584,8 @@ static void ul_rpc_add(rpc_t* rpc, void* ctx)
567 584
 	str aor = {0, 0};
568 585
 	str contact = {0, 0};
569 586
 	str path = {0, 0};
587
+	str received = {0, 0};
588
+	str socket = {0, 0};
570 589
 	str temp = {0, 0};
571 590
 	double dtemp;
572 591
 	ucontact_info_t ci;
... ...
@@ -583,10 +602,10 @@ static void ul_rpc_add(rpc_t* rpc, void* ctx)
583 602
 		rpc->fault(ctx, 500, "Not enough parameters or wrong format");
584 603
 		return;
585 604
 	}
586
-	if(path.len==1 && (strncmp(path.s, "0", 1)==0))	{
587
-		LM_DBG("path == 0 -> unset\n");
588
-	} else {
605
+	if(ul_rpc_is_param_set(&path)) {
589 606
 		ci.path = &path;
607
+	} else {
608
+		LM_DBG("path == 0 -> unset\n");
590 609
 	}
591 610
 	LM_DBG("ret: %d table:%.*s aor:%.*s contact:%.*s expires:%d"
592 611
 			" dtemp:%f path:%.*s flags:%d bflags:%d methods:%d\n",
Browse code

usrloc: test first if all params are retrieved for rpc ul.add

- avoid logging unset values

Daniel-Constantin Mierla authored on 17/09/2017 08:08:37
Showing 1 changed files
... ...
@@ -579,19 +579,21 @@ static void ul_rpc_add(rpc_t* rpc, void* ctx)
579 579
 
580 580
 	ret = rpc->scan(ctx, "SSSdfSddd", &table, &aor, &contact, &ci.expires,
581 581
 			&dtemp, &path, &ci.flags, &ci.cflags, &ci.methods);
582
+	if ( ret != 9) {
583
+		rpc->fault(ctx, 500, "Not enough parameters or wrong format");
584
+		return;
585
+	}
582 586
 	if(path.len==1 && (strncmp(path.s, "0", 1)==0))	{
583 587
 		LM_DBG("path == 0 -> unset\n");
584
-	}
585
-	else {
588
+	} else {
586 589
 		ci.path = &path;
587 590
 	}
588
-	LM_DBG("ret: %d table:%.*s aor:%.*s contact:%.*s expires:%d dtemp:%f path:%.*s flags:%d bflags:%d methods:%d\n",
591
+	LM_DBG("ret: %d table:%.*s aor:%.*s contact:%.*s expires:%d"
592
+			" dtemp:%f path:%.*s flags:%d bflags:%d methods:%d\n",
589 593
 			ret, table.len, table.s, aor.len, aor.s, contact.len, contact.s,
590
-			(int) ci.expires, dtemp, (ci.path)?ci.path->len:0, (ci.path && ci.path->s)?ci.path->s:"", ci.flags, ci.cflags, (int) ci.methods);
591
-	if ( ret != 9) {
592
-		rpc->fault(ctx, 500, "Not enough parameters or wrong format");
593
-		return;
594
-	}
594
+			(int) ci.expires, dtemp, (ci.path)?ci.path->len:0,
595
+			(ci.path && ci.path->s)?ci.path->s:"", ci.flags, ci.cflags,
596
+			(int) ci.methods);
595 597
 	ci.q = double2q(dtemp);
596 598
 	temp.s = q2str(ci.q, (unsigned int*)&temp.len);
597 599
 	LM_DBG("q:%.*s\n", temp.len, temp.s);
... ...
@@ -627,7 +629,8 @@ static void ul_rpc_add(rpc_t* rpc, void* ctx)
627 629
 		}
628 630
 		c = 0;
629 631
 	} else {
630
-		if (get_ucontact( r, &contact, &rpc_ul_cid, &rpc_ul_path, RPC_UL_CSEQ+1, &c) < 0)
632
+		if (get_ucontact( r, &contact, &rpc_ul_cid, &rpc_ul_path,
633
+					RPC_UL_CSEQ+1, &c) < 0)
631 634
 		{
632 635
 			unlock_udomain( dom, &aor);
633 636
 			rpc->fault(ctx, 500, "Can't get record");
Browse code

usrloc: use app name in UL rpc UA, shift from mi to rpc in strings

- coherent indentation

Daniel-Constantin Mierla authored on 13/09/2017 16:07:34
Showing 1 changed files
... ...
@@ -31,11 +31,11 @@
31 31
 /*! CSEQ nr used */
32 32
 #define RPC_UL_CSEQ 1
33 33
 /*! call-id used for ul_add and ul_rm_contact */
34
-static str rpc_ul_cid = str_init("dfjrewr12386fd6-343@kamailio.mi");
34
+static str rpc_ul_cid = str_init("dfjrewr12386fd6-343@kamailio.rpc");
35 35
 /*! path used for ul_add and ul_rm_contact */
36 36
 static str rpc_ul_path = str_init("dummypath");
37 37
 /*! user agent used for ul_add */
38
-static str rpc_ul_ua  = str_init("SIP Router MI Server");
38
+static str rpc_ul_ua  = str_init(NAME " SIP Router - RPC Server");
39 39
 
40 40
 extern sruid_t _ul_sruid;
41 41
 
... ...
@@ -65,10 +65,10 @@ int rpc_dump_contact(rpc_t* rpc, void* ctx, void *ih, ucontact_t* c)
65 65
 		return -1;
66 66
 	}
67 67
 	if (c->expires == 0) { if(rpc->struct_add(vh, "s", "Expires", "permanent")<0)
68
-	{
68
+		{
69 69
 			rpc->fault(ctx, 500, "Internal error adding expire");
70 70
 			return -1;
71
-	}
71
+		}
72 72
 	} else if (c->expires == UL_EXPIRED_TIME) {
73 73
 		if(rpc->struct_add(vh, "s", "Expires", "deleted")<0)
74 74
 		{
... ...
@@ -122,19 +122,19 @@ int rpc_dump_contact(rpc_t* rpc, void* ctx, void *ih, ucontact_t* c)
122 122
 		return -1;
123 123
 	}
124 124
 	if(rpc->struct_add(vh, "S", "User-Agent",
125
-			(c->user_agent.len)?&c->user_agent: &empty_str)<0)
125
+				(c->user_agent.len)?&c->user_agent: &empty_str)<0)
126 126
 	{
127 127
 		rpc->fault(ctx, 500, "Internal error adding user-agent");
128 128
 		return -1;
129 129
 	}
130 130
 	if(rpc->struct_add(vh, "S", "Received",
131
-			(c->received.len)?&c->received: &empty_str)<0)
131
+				(c->received.len)?&c->received: &empty_str)<0)
132 132
 	{
133 133
 		rpc->fault(ctx, 500, "Internal error adding received");
134 134
 		return -1;
135 135
 	}
136 136
 	if(rpc->struct_add(vh, "S", "Path",
137
-			(c->path.len)?&c->path: &empty_str)<0)
137
+				(c->path.len)?&c->path: &empty_str)<0)
138 138
 	{
139 139
 		rpc->fault(ctx, 500, "Internal error adding path");
140 140
 		return -1;
... ...
@@ -170,7 +170,7 @@ int rpc_dump_contact(rpc_t* rpc, void* ctx, void *ih, ucontact_t* c)
170 170
 		return -1;
171 171
 	}
172 172
 	if(rpc->struct_add(vh, "S", "Instance",
173
-			(c->instance.len)?&c->instance: &empty_str)<0)
173
+				(c->instance.len)?&c->instance: &empty_str)<0)
174 174
 	{
175 175
 		rpc->fault(ctx, 500, "Internal error adding instance");
176 176
 		return -1;
... ...
@@ -180,17 +180,17 @@ int rpc_dump_contact(rpc_t* rpc, void* ctx, void *ih, ucontact_t* c)
180 180
 		rpc->fault(ctx, 500, "Internal error adding reg_id");
181 181
 		return -1;
182 182
 	}
183
-    if(rpc->struct_add(vh, "d", "Server-Id", c->server_id)<0)
183
+	if(rpc->struct_add(vh, "d", "Server-Id", c->server_id)<0)
184 184
 	{
185 185
 		rpc->fault(ctx, 500, "Internal error adding server_id");
186 186
 		return -1;
187 187
 	}
188
-    if(rpc->struct_add(vh, "d", "Tcpconn-Id", c->tcpconn_id)<0)
188
+	if(rpc->struct_add(vh, "d", "Tcpconn-Id", c->tcpconn_id)<0)
189 189
 	{
190 190
 		rpc->fault(ctx, 500, "Internal error adding tcpconn_id");
191 191
 		return -1;
192 192
 	}
193
-    if(rpc->struct_add(vh, "d", "Keepalive", c->keepalive)<0)
193
+	if(rpc->struct_add(vh, "d", "Keepalive", c->keepalive)<0)
194 194
 	{
195 195
 		rpc->fault(ctx, 500, "Internal error adding keepalive");
196 196
 		return -1;
... ...
@@ -227,7 +227,7 @@ static void ul_rpc_dump(rpc_t* rpc, void* ctx)
227 227
 
228 228
 	if(brief.len==5 && (strncmp(brief.s, "brief", 5)==0))
229 229
 		summary = 1;
230
-	
230
+
231 231
 	for( dl=root ; dl ; dl=dl->next ) {
232 232
 		dom = dl->d;
233 233
 		if (rpc->add(ctx, "{", &th) < 0)
... ...
@@ -252,23 +252,23 @@ static void ul_rpc_dump(rpc_t* rpc, void* ctx)
252 252
 				if(summary==1)
253 253
 				{
254 254
 					if(rpc->struct_add(ah, "S",
255
-							"AoR", &r->aor)<0)
255
+								"AoR", &r->aor)<0)
256 256
 					{
257 257
 						rpc->fault(ctx, 500, "Internal error creating aor struct");
258 258
 						return;
259 259
 					}
260 260
 				} else {
261 261
 					if(rpc->struct_add(ah, "{",
262
-							"Info", &bh)<0)
262
+								"Info", &bh)<0)
263 263
 					{
264 264
 						unlock_ulslot( dom, i);
265 265
 						rpc->fault(ctx, 500, "Internal error creating aor struct");
266 266
 						return;
267 267
 					}
268 268
 					if(rpc->struct_add(bh, "Sd[",
269
-							"AoR", &r->aor,
270
-							"HashID", r->aorhash,
271
-							"Contacts", &ih)<0)
269
+								"AoR", &r->aor,
270
+								"HashID", r->aorhash,
271
+								"Contacts", &ih)<0)
272 272
 					{
273 273
 						unlock_ulslot( dom, i);
274 274
 						rpc->fault(ctx, 500, "Internal error creating aor struct");
... ...
@@ -294,8 +294,8 @@ static void ul_rpc_dump(rpc_t* rpc, void* ctx)
294 294
 			return;
295 295
 		}
296 296
 		if(rpc->struct_add(sh, "dd",
297
-				"Records", n,
298
-				"Max-Slots", max)<0)
297
+					"Records", n,
298
+					"Max-Slots", max)<0)
299 299
 		{
300 300
 			rpc->fault(ctx, 500, "Internal error adding stats");
301 301
 			return;
... ...
@@ -319,7 +319,7 @@ static inline udomain_t* rpc_find_domain(str* table)
319 319
 
320 320
 	for( dom=root ; dom ; dom=dom->next ) {
321 321
 		if ((dom->name.len == table->len) &&
322
-		!memcmp(dom->name.s, table->s, table->len))
322
+				!memcmp(dom->name.s, table->s, table->len))
323 323
 			return dom->d;
324 324
 	}
325 325
 	return 0;
... ...
@@ -410,8 +410,8 @@ static void ul_rpc_lookup(rpc_t* rpc, void* ctx)
410 410
 		return;
411 411
 	}
412 412
 	if(rpc->struct_add(th, "S[",
413
-			"AoR", &aor,
414
-			"Contacts", &ih)<0)
413
+				"AoR", &aor,
414
+				"Contacts", &ih)<0)
415 415
 	{
416 416
 		unlock_udomain(dom, &aor);
417 417
 		rpc->fault(ctx, 500, "Internal error creating aor struct");
... ...
@@ -578,7 +578,7 @@ static void ul_rpc_add(rpc_t* rpc, void* ctx)
578 578
 	memset( &ci, 0, sizeof(ucontact_info_t));
579 579
 
580 580
 	ret = rpc->scan(ctx, "SSSdfSddd", &table, &aor, &contact, &ci.expires,
581
-		&dtemp, &path, &ci.flags, &ci.cflags, &ci.methods);
581
+			&dtemp, &path, &ci.flags, &ci.cflags, &ci.methods);
582 582
 	if(path.len==1 && (strncmp(path.s, "0", 1)==0))	{
583 583
 		LM_DBG("path == 0 -> unset\n");
584 584
 	}
... ...
@@ -586,8 +586,8 @@ static void ul_rpc_add(rpc_t* rpc, void* ctx)
586 586
 		ci.path = &path;
587 587
 	}
588 588
 	LM_DBG("ret: %d table:%.*s aor:%.*s contact:%.*s expires:%d dtemp:%f path:%.*s flags:%d bflags:%d methods:%d\n",
589
-		ret, table.len, table.s, aor.len, aor.s, contact.len, contact.s,
590
-		(int) ci.expires, dtemp, (ci.path)?ci.path->len:0, (ci.path && ci.path->s)?ci.path->s:"", ci.flags, ci.cflags, (int) ci.methods);
589
+			ret, table.len, table.s, aor.len, aor.s, contact.len, contact.s,
590
+			(int) ci.expires, dtemp, (ci.path)?ci.path->len:0, (ci.path && ci.path->s)?ci.path->s:"", ci.flags, ci.cflags, (int) ci.methods);
591 591
 	if ( ret != 9) {
592 592
 		rpc->fault(ctx, 500, "Not enough parameters or wrong format");
593 593
 		return;
... ...
@@ -676,52 +676,52 @@ static const char* ul_rpc_add_doc[2] = {
676 676
 
677 677
 static void ul_rpc_db_users(rpc_t* rpc, void* ctx)
678 678
 {
679
-    str table = {0, 0};
680
-    char query[QUERY_LEN];
681
-    str query_str;
682
-    db1_res_t* res;
683
-    int count;
684
-
685
-    if (db_mode == NO_DB) {
686
-	rpc->fault(ctx, 500, "Command is not supported in db_mode=0");
687
-	return;
688
-    }
679
+	str table = {0, 0};
680
+	char query[QUERY_LEN];
681
+	str query_str;
682
+	db1_res_t* res;
683
+	int count;
689 684
 
690
-    if (rpc->scan(ctx, "S", &table) != 1) {
691
-	rpc->fault(ctx, 500, "Not enough parameters (table to lookup)");
692
-	return;
693
-    }
685
+	if (db_mode == NO_DB) {
686
+		rpc->fault(ctx, 500, "Command is not supported in db_mode=0");
687
+		return;
688
+	}
694 689
 
695
-    if (user_col.len + domain_col.len + table.len + 32 > QUERY_LEN) {
696
-	rpc->fault(ctx, 500, "Too long database query");
697
-	return;
698
-    }
690
+	if (rpc->scan(ctx, "S", &table) != 1) {
691
+		rpc->fault(ctx, 500, "Not enough parameters (table to lookup)");
692
+		return;
693
+	}
699 694
 
700
-    if (!DB_CAPABILITY(ul_dbf, DB_CAP_RAW_QUERY)) {
701
-	rpc->fault(ctx, 500, "Database does not support raw queries");
702
-	return;
703
-    }
704
-    if (ul_dbf.use_table(ul_dbh, &table) < 0) {
705
-	rpc->fault(ctx, 500, "Failed to use table");
706
-	return;
707
-    }
708
-	
709
-    memset(query, 0, QUERY_LEN);
710
-    query_str.len = snprintf(query, QUERY_LEN,
711
-			     "SELECT COUNT(DISTINCT %.*s, %.*s) FROM %.*s WHERE (UNIX_TIMESTAMP(expires) = 0) OR (expires > NOW())",
712
-			     user_col.len, user_col.s,
713
-			     domain_col.len, domain_col.s,
714
-			     table.len, table.s);
715
-    query_str.s = query;
716
-    if (ul_dbf.raw_query(ul_dbh, &query_str, &res) < 0) {
717
-	rpc->fault(ctx, 500, "Failed to query AoR count");
718
-	return;
719
-    }
695
+	if (user_col.len + domain_col.len + table.len + 32 > QUERY_LEN) {
696
+		rpc->fault(ctx, 500, "Too long database query");
697
+		return;
698
+	}
699
+
700
+	if (!DB_CAPABILITY(ul_dbf, DB_CAP_RAW_QUERY)) {