Module: kamailio
Branch: master
Commit: 8334e61815f15656051c5b14cf9321f4c65bcf8c
URL:
https://github.com/kamailio/kamailio/commit/8334e61815f15656051c5b14cf9321f…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2019-07-21T08:56:39+02:00
kemix: exported functions to get auth username
---
Modified: src/modules/kemix/kemix_mod.c
---
Diff:
https://github.com/kamailio/kamailio/commit/8334e61815f15656051c5b14cf9321f…
Patch:
https://github.com/kamailio/kamailio/commit/8334e61815f15656051c5b14cf9321f…
---
diff --git a/src/modules/kemix/kemix_mod.c b/src/modules/kemix/kemix_mod.c
index fd27d47fca..81a4f2bc1c 100644
--- a/src/modules/kemix/kemix_mod.c
+++ b/src/modules/kemix/kemix_mod.c
@@ -30,6 +30,7 @@
#include "../../core/parser/parse_uri.h"
#include "../../core/parser/parse_from.h"
#include "../../core/parser/parse_to.h"
+#include "../../core/parser/digest/digest.h"
MODULE_VERSION
@@ -482,6 +483,78 @@ static int ki_kx_get_protoid(sip_msg_t *msg)
return (int)msg->rcv.proto;
}
+/**
+ *
+ */
+static sr_kemi_xval_t* ki_kx_get_auth_attr(sip_msg_t *msg, int iattr, int xmode)
+{
+ hdr_field_t *hdr;
+
+ memset(&_sr_kemi_kx_xval, 0, sizeof(sr_kemi_xval_t));
+ if(msg==NULL) {
+ sr_kemi_xval_null(&_sr_kemi_kx_xval, xmode);
+ return &_sr_kemi_kx_xval;
+ }
+
+ if ((msg->REQ_METHOD == METHOD_ACK) ||
+ (msg->REQ_METHOD == METHOD_CANCEL)) {
+ LM_DBG("no [Proxy-]Authorization header\n");
+ sr_kemi_xval_null(&_sr_kemi_kx_xval, xmode);
+ return &_sr_kemi_kx_xval;
+ }
+
+ if ((parse_headers(msg, HDR_PROXYAUTH_F|HDR_AUTHORIZATION_F, 0)==-1)
+ || (msg->proxy_auth==0 && msg->authorization==0)) {
+ LM_DBG("no [Proxy-]Authorization header\n");
+ sr_kemi_xval_null(&_sr_kemi_kx_xval, xmode);
+ return &_sr_kemi_kx_xval;
+ }
+
+ hdr = (msg->proxy_auth==0)?msg->authorization:msg->proxy_auth;
+
+ if(parse_credentials(hdr)!=0) {
+ LM_ERR("failed to parse credentials\n");
+ sr_kemi_xval_null(&_sr_kemi_kx_xval, xmode);
+ return &_sr_kemi_kx_xval;
+ }
+ switch(iattr) {
+ case 1:
+ _sr_kemi_kx_xval.vtype = SR_KEMIP_STR;
+ _sr_kemi_kx_xval.v.s = ((auth_body_t*)(hdr->parsed))->digest.username.user;
+ return &_sr_kemi_kx_xval;
+
+ break;
+ default:
+ _sr_kemi_kx_xval.vtype = SR_KEMIP_STR;
+ _sr_kemi_kx_xval.v.s = ((auth_body_t*)(hdr->parsed))->digest.username.whole;
+ return &_sr_kemi_kx_xval;
+ }
+}
+
+/**
+ *
+ */
+static sr_kemi_xval_t* ki_kx_get_au(sip_msg_t *msg)
+{
+ return ki_kx_get_auth_attr(msg, 1, SR_KEMI_XVAL_NULL_NONE);
+}
+
+/**
+ *
+ */
+static sr_kemi_xval_t* ki_kx_getw_au(sip_msg_t *msg)
+{
+ return ki_kx_get_auth_attr(msg, 1, SR_KEMI_XVAL_NULL_PRINT);
+}
+
+/**
+ *
+ */
+static sr_kemi_xval_t* ki_kx_gete_au(sip_msg_t *msg)
+{
+ return ki_kx_get_auth_attr(msg, 1, SR_KEMI_XVAL_NULL_EMPTY);
+}
+
/**
*
*/
@@ -612,6 +685,21 @@ static sr_kemi_t sr_kemi_kx_exports[] = {
{ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,
SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
},
+ { str_init("kx"), str_init("get_au"),
+ SR_KEMIP_XVAL, ki_kx_get_au,
+ { SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,
+ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
+ },
+ { str_init("kx"), str_init("getw_au"),
+ SR_KEMIP_XVAL, ki_kx_getw_au,
+ { SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,
+ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
+ },
+ { str_init("kx"), str_init("gete_au"),
+ SR_KEMIP_XVAL, ki_kx_gete_au,
+ { SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,
+ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
+ },
{ {0, 0}, {0, 0}, 0, NULL, { 0, 0, 0, 0, 0, 0 } }
};