Browse code

htable: adding flags and expires fields to htable.get RPC command

Ovidiu Sas authored on 12/02/2014 21:14:35
Showing 1 changed files
... ...
@@ -649,6 +649,8 @@ error:
649 649
 	return 0;
650 650
 }
651 651
 
652
+#define RPC_DATE_BUF_LEN 21
653
+
652 654
 static const char* htable_dump_doc[2] = {
653 655
 	"Dump the contents of hash table.",
654 656
 	0
... ...
@@ -710,6 +712,8 @@ static void htable_rpc_get(rpc_t* rpc, void* c) {
710 712
 	ht_cell_t *htc;	/*!< One HT cell */
711 713
 	void* th;
712 714
 	void* vh;
715
+	struct tm *_expire_t;
716
+	char expire_buf[RPC_DATE_BUF_LEN]="NEVER";
713 717
 
714 718
 	if (rpc->scan(c, "SS", &htname, &keyname) < 2) {
715 719
 		rpc->fault(c, 500, "Not enough parameters (htable name and key name)");
... ...
@@ -742,14 +746,27 @@ static void htable_rpc_get(rpc_t* rpc, void* c) {
742 746
 		goto error;
743 747
 	}
744 748
 
749
+	if (htc->expire) {
750
+		_expire_t = localtime(&htc->expire);
751
+		strftime(expire_buf, RPC_DATE_BUF_LEN - 1,
752
+			"%Y-%m-%d %H:%M:%S", _expire_t);
753
+	}
754
+	LM_NOTICE("got expire [%s]\n", expire_buf);
755
+
745 756
 	if(htc->flags&AVP_VAL_STR) {
746
-		if(rpc->struct_add(vh, "SS", "name",  &htc->name.s, "value", &htc->value.s)<0)
757
+		if(rpc->struct_add(vh, "SSds", "name",  &htc->name.s,
758
+							"value", &htc->value.s,
759
+							"flags", htc->flags,
760
+							"expire", expire_buf)<0)
747 761
 		{
748 762
 			rpc->fault(c, 500, "Internal error adding item");
749 763
 			goto error;
750 764
 		}
751 765
 	} else {
752
-		if(rpc->struct_add(vh, "Sd", "name",  &htc->name.s, "value", (int)htc->value.n))
766
+		if(rpc->struct_add(vh, "Sdds", "name",  &htc->name.s,
767
+							"value", (int)htc->value.n,
768
+							"flags", htc->flags,
769
+							"expire", expire_buf)<0)
753 770
 		{
754 771
 			rpc->fault(c, 500, "Internal error adding item");
755 772
 			goto error;
... ...
@@ -892,7 +909,7 @@ static void  htable_rpc_dump(rpc_t* rpc, void* c)
892 909
 				} else {
893 910
 					if(rpc->struct_add(vh, "Sd",
894 911
 							"name",  &it->name.s,
895
-							"value", (int)it->value.n))
912
+							"value", (int)it->value.n)<0)
896 913
 					{
897 914
 						rpc->fault(c, 500, "Internal error adding item");
898 915
 						goto error;