Browse code

auth: exported has_credentials() to kemi framework

Daniel-Constantin Mierla authored on 04/05/2017 05:31:41
Showing 1 changed files
... ...
@@ -444,32 +444,39 @@ int w_consume_credentials(struct sip_msg* msg, char* s1, char* s2)
444 444
 /**
445 445
  *
446 446
  */
447
-int w_has_credentials(sip_msg_t *msg, char* realm, char* s2)
447
+int ki_has_credentials(sip_msg_t *msg, str* srealm)
448 448
 {
449
-	str srealm  = {0, 0};
450 449
 	hdr_field_t *hdr = NULL;
451 450
 	int ret;
452 451
 
453
-	if (fixup_get_svalue(msg, (gparam_t*)realm, &srealm) < 0) {
454
-		LM_ERR("failed to get realm value\n");
455
-		return -1;
456
-	}
457
-
458
-	ret = find_credentials(msg, &srealm, HDR_PROXYAUTH_T, &hdr);
452
+	ret = find_credentials(msg, srealm, HDR_PROXYAUTH_T, &hdr);
459 453
 	if(ret==0) {
460
-		LM_DBG("found www credentials with realm [%.*s]\n", srealm.len, srealm.s);
454
+		LM_DBG("found www credentials with realm [%.*s]\n", srealm->len, srealm->s);
461 455
 		return 1;
462 456
 	}
463
-	ret = find_credentials(msg, &srealm, HDR_AUTHORIZATION_T, &hdr);
457
+	ret = find_credentials(msg, srealm, HDR_AUTHORIZATION_T, &hdr);
464 458
 	if(ret==0) {
465
-		LM_DBG("found proxy credentials with realm [%.*s]\n", srealm.len, srealm.s);
459
+		LM_DBG("found proxy credentials with realm [%.*s]\n", srealm->len, srealm->s);
466 460
 		return 1;
467 461
 	}
468 462
 
469
-	LM_DBG("no credentials with realm [%.*s]\n", srealm.len, srealm.s);
463
+	LM_DBG("no credentials with realm [%.*s]\n", srealm->len, srealm->s);
470 464
 	return -1;
471 465
 }
472 466
 
467
+/**
468
+ *
469
+ */
470
+int w_has_credentials(sip_msg_t *msg, char* realm, char* s2)
471
+{
472
+	str srealm  = {0, 0};
473
+
474
+	if (fixup_get_svalue(msg, (gparam_t*)realm, &srealm) < 0) {
475
+		LM_ERR("failed to get realm value\n");
476
+		return -1;
477
+	}
478
+	return ki_has_credentials(msg, &srealm);
479
+}
473 480
 /**
474 481
  * @brief do WWW-Digest authentication with password taken from cfg var
475 482
  */
... ...
@@ -1220,6 +1227,11 @@ static sr_kemi_t sr_kemi_auth_exports[] = {
1220 1227
 		{ SR_KEMIP_STR, SR_KEMIP_STR, SR_KEMIP_INT,
1221 1228
 			SR_KEMIP_INT, SR_KEMIP_NONE, SR_KEMIP_NONE }
1222 1229
 	},
1230
+	{ str_init("auth"), str_init("has_credentials"),
1231
+		SR_KEMIP_INT, ki_has_credentials,
1232
+		{ SR_KEMIP_STR, SR_KEMIP_NONE, SR_KEMIP_NONE,
1233
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
1234
+	},
1223 1235
 
1224 1236
 	{ {0, 0}, {0, 0}, 0, NULL, { 0, 0, 0, 0, 0, 0 } }
1225 1237
 };