Browse code

misc/examples/kemi: use kx functions instead of pv

Daniel-Constantin Mierla authored on 12/01/2021 08:52:31
Showing 1 changed files
... ...
@@ -116,23 +116,23 @@ function ksr_route_relay()
116 116
 function ksr_route_reqinit()
117 117
 {
118 118
 	if (!KSR.is_myself_srcip()) {
119
-		if (!KSR.pv.is_null("$sht(ipban=>$si)")) {
119
+		if (KSR.htable.sht_match_name("ipban", "eq", srcip) > 0) {
120 120
 			// ip is already blocked
121
-			KSR.dbg("request from blocked IP - " + KSR.pv.get("$rm")
122
-					+ " from " + KSR.pv.get("$fu") + " (IP:"
123
-					+ KSR.pv.get("$si") + ":" + KSR.pv.get("$sp") + ")\n");
121
+			KSR.dbg("request from blocked IP - " + KSR.kx.get_method()
122
+					+ " from " + KSR.kx.get_furi() + " (IP:"
123
+					+ KSR.kx.get_srcip() + ":" + KSR.kx.get_srcport() + ")\n");
124 124
 			KSR.x.exit();
125 125
 		}
126 126
 		if (KSR.pike.pike_check_req()<0) {
127
-			KSR.err("ALERT: pike blocking " + KSR.pv.get("$rm")
128
-					+ " from " + KSR.pv.get("$fu") + " (IP:"
129
-					+ KSR.pv.get("$si") + ":" + KSR.pv.get("$sp") + ")\n");
130
-			KSR.pv.seti("$sht(ipban=>$si)", 1);
127
+			KSR.err("ALERT: pike blocking " + KSR.kx.get_method()
128
+					+ " from " + KSR.kx.get_furi() + " (IP:"
129
+					+ KSR.kx.get_srcip() + ":" + KSR.kx.get_srcport() + ")\n");
130
+			KSR.htable.sht_seti("ipban", KSR.kx.get_srcip(), 1);
131 131
 			KSR.x.exit();
132 132
 		}
133 133
 	}
134 134
 	if (KSR.corex.has_user_agent()>0) {
135
-		var UA = KSR.pv.gete("$ua");
135
+		var UA = KSR.kx.gete_ua();
136 136
 		if (UA.indexOf("friendly")>=0 || UA.indexOf("scanner")>=0
137 137
 				|| UA.indexOf("sipcli")>=0 || UA.indexOf("sipvicious")>=0) {
138 138
 			KSR.sl.sl_send_reply(200, "OK");
... ...
@@ -154,7 +154,7 @@ function ksr_route_reqinit()
154 154
 
155 155
 	if (KSR.sanity.sanity_check(1511, 7)<0) {
156 156
 		KSR.err("Malformed SIP message from "
157
-				+ KSR.pv.get("$si") + ":" + KSR.pv.get("$sp") + "\n");
157
+				+ KSR.kx.get_srcip() + ":" + KSR.kx.get_srcport() + "\n");
158 158
 		KSR.x.exit();
159 159
 	}
160 160
 }
... ...
@@ -238,7 +238,7 @@ function ksr_route_location()
238 238
 }
239 239
 
240 240
 
241
-// IP authorization and user uthentication
241
+// IP authorization and user authentication
242 242
 function ksr_route_auth()
243 243
 {
244 244
 	if (!KSR.is_REGISTER()) {
... ...
@@ -250,8 +250,8 @@ function ksr_route_auth()
250 250
 
251 251
 	if (KSR.is_REGISTER() || KSR.is_myself_furi()) {
252 252
 		// authenticate requests
253
-		if (KSR.auth_db.auth_check(KSR.pv.get("$fd"), "subscriber", 1)<0) {
254
-			KSR.auth.auth_challenge(KSR.pv.get("$fd"), 0);
253
+		if (KSR.auth_db.auth_check(KSR.kx.gete_fhost(), "subscriber", 1)<0) {
254
+			KSR.auth.auth_challenge(KSR.kx.gete_fhost(), 0);
255 255
 			KSR.x.exit();
256 256
 		}
257 257
 		// user authenticated - remove auth header
... ...
@@ -340,8 +340,8 @@ function ksr_route_sipout()
340 340
 // equivalent of branch_route[...]{}
341 341
 function ksr_branch_manage()
342 342
 {
343
-	KSR.dbg("new branch [" + KSR.pv.get("$T_branch_idx")
344
-				+ "] to " + KSR.pv.get("$ru") + "\n");
343
+	KSR.dbg("new branch [" + KSR.tm.t_get_branch_index()
344
+				+ "] to " + KSR.kx.get_ruri() + "\n");
345 345
 	ksr_route_natmanage();
346 346
 	return;
347 347
 }
... ...
@@ -351,7 +351,7 @@ function ksr_branch_manage()
351 351
 function ksr_onreply_manage()
352 352
 {
353 353
 	KSR.dbg("incoming reply\n");
354
-	var scode = KSR.pv.get("$rs");
354
+	var scode = KSR.kx.gets_status();
355 355
 	if (scode>100 && scode<=299) {
356 356
 		ksr_route_natmanage();
357 357
 	}