Module: kamailio Branch: master Commit: 019637af117eeab4b0b06e73ac6808b0e42fe760 URL: https://github.com/kamailio/kamailio/commit/019637af117eeab4b0b06e73ac6808b0...
Author: Daniel-Constantin Mierla miconda@gmail.com Committer: Daniel-Constantin Mierla miconda@gmail.com Date: 2016-04-21T14:56:56+02:00
auth: restructuring of code for auth_challenge()
- split code specific for config and internal API
---
Modified: modules/auth/api.c Modified: modules/auth/api.h Modified: modules/auth/auth_mod.c
---
Diff: https://github.com/kamailio/kamailio/commit/019637af117eeab4b0b06e73ac6808b0... Patch: https://github.com/kamailio/kamailio/commit/019637af117eeab4b0b06e73ac6808b0...
---
diff --git a/modules/auth/api.c b/modules/auth/api.c index 0eb438f..d31b099 100644 --- a/modules/auth/api.c +++ b/modules/auth/api.c @@ -226,7 +226,7 @@ int bind_auth_s(auth_api_s_t* api) api->calc_HA1 = calc_HA1; api->calc_response = calc_response; api->check_response = auth_check_response; - api->auth_challenge = auth_challenge; + api->auth_challenge_hftype = auth_challenge_hftype; api->pv_authenticate = pv_authenticate; api->consume_credentials = consume_credentials; return 0; diff --git a/modules/auth/api.h b/modules/auth/api.h index ff8a124..f612923 100644 --- a/modules/auth/api.h +++ b/modules/auth/api.h @@ -105,9 +105,9 @@ auth_result_t post_auth(struct sip_msg* msg, struct hdr_field* hdr); typedef int (*check_response_t)(dig_cred_t* cred, str* method, char* ha1); int auth_check_response(dig_cred_t* cred, str* method, char* ha1);
-typedef int (*auth_challenge_f)(struct sip_msg *msg, str *realm, int flags, +typedef int (*auth_challenge_hftype_f)(struct sip_msg *msg, str *realm, int flags, int hftype); -int auth_challenge(struct sip_msg *msg, str *realm, int flags, +int auth_challenge_hftype(struct sip_msg *msg, str *realm, int flags, int hftype);
typedef int (*pv_authenticate_f)(struct sip_msg *msg, str *realm, str *passwd, @@ -129,7 +129,7 @@ typedef struct auth_api_s { calc_HA1_t calc_HA1; calc_response_t calc_response; check_response_t check_response; - auth_challenge_f auth_challenge; + auth_challenge_hftype_f auth_challenge_hftype; pv_authenticate_f pv_authenticate; consume_credentials_f consume_credentials; } auth_api_s_t; diff --git a/modules/auth/auth_mod.c b/modules/auth/auth_mod.c index 9349b50..bb029fc 100644 --- a/modules/auth/auth_mod.c +++ b/modules/auth/auth_mod.c @@ -942,7 +942,7 @@ int auth_challenge_helper(struct sip_msg *msg, str *realm, int flags, int hftype /** * */ -int auth_challenge(struct sip_msg *msg, str *realm, int flags, int hftype) +int auth_challenge_hftype(struct sip_msg *msg, str *realm, int flags, int hftype) { return auth_challenge_helper(msg, realm, flags, hftype, NULL); } @@ -950,6 +950,23 @@ int auth_challenge(struct sip_msg *msg, str *realm, int flags, int hftype) /** * */ +int auth_challenge(sip_msg_t *msg, str *realm, int flags) +{ + int htype; + + if(msg==NULL) return -1; + + if(msg->REQ_METHOD==METHOD_REGISTER) + htype = HDR_AUTHORIZATION_T; + else + htype = HDR_PROXYAUTH_T; + + return auth_challenge_helper(msg, realm, flags, htype, NULL); +} + +/** + * + */ static int proxy_challenge(struct sip_msg *msg, char* realm, char *flags) { int vflags = 0; @@ -970,7 +987,7 @@ static int proxy_challenge(struct sip_msg *msg, char* realm, char *flags) goto error; }
- return auth_challenge(msg, &srealm, vflags, HDR_PROXYAUTH_T); + return auth_challenge_hftype(msg, &srealm, vflags, HDR_PROXYAUTH_T);
error: if(!(vflags&4)) { @@ -1003,7 +1020,7 @@ static int www_challenge(struct sip_msg *msg, char* realm, char *flags) goto error; }
- return auth_challenge(msg, &srealm, vflags, HDR_AUTHORIZATION_T); + return auth_challenge_hftype(msg, &srealm, vflags, HDR_AUTHORIZATION_T);
error: if(!(vflags&4)) { @@ -1041,9 +1058,9 @@ static int w_auth_challenge(struct sip_msg *msg, char* realm, char *flags) }
if(msg->REQ_METHOD==METHOD_REGISTER) - return auth_challenge(msg, &srealm, vflags, HDR_AUTHORIZATION_T); + return auth_challenge_hftype(msg, &srealm, vflags, HDR_AUTHORIZATION_T); else - return auth_challenge(msg, &srealm, vflags, HDR_PROXYAUTH_T); + return auth_challenge_hftype(msg, &srealm, vflags, HDR_PROXYAUTH_T);
error: if(!(vflags&4)) {