From 725b8665663f753b28d3c6892949a8c4157abf66 Mon Sep 17 00:00:00 2001 From: Gautier Pelloux-Prayer Date: Fri, 16 Oct 2015 11:19:06 +0200 Subject: [PATCH] proxy.c: add new linphone_proxy_config_find_auth_info API --- coreapi/authentication.c | 20 ++++++-------------- coreapi/linphone_proxy_config.h | 7 +++++++ coreapi/linphonecore.h | 18 ++++++++++++------ coreapi/proxy.c | 6 ++++++ 4 files changed, 31 insertions(+), 20 deletions(-) diff --git a/coreapi/authentication.c b/coreapi/authentication.c index cd0d20638..b0318bc99 100644 --- a/coreapi/authentication.c +++ b/coreapi/authentication.c @@ -142,8 +142,8 @@ void linphone_auth_info_write_config(LpConfig *config, LinphoneAuthInfo *obj, in { char key[50]; bool_t store_ha1_passwd = lp_config_get_int(config, "sip", "store_ha1_passwd", 1); - - + + sprintf(key,"auth_info_%i",pos); lp_config_clean_section(config,key); @@ -275,18 +275,10 @@ const LinphoneAuthInfo *_linphone_core_find_auth_info(LinphoneCore *lc, const ch if (ai==NULL){ ai=find_auth_info(lc,username,NULL,NULL, ignore_realm); } - /*if (ai) ms_message("linphone_core_find_auth_info(): returning auth info username=%s, realm=%s", ai->username, ai->realm);*/ + if (ai) ms_message("linphone_core_find_auth_info(): returning auth info username=%s, realm=%s", ai->username, ai->realm); return ai; } -/** - * Find authentication info matching realm, username, domain criteria. - * First of all, (realm,username) pair are searched. If multiple results (which should not happen because realm are supposed to be unique), then domain is added to the search. - * @param lc the LinphoneCore - * @param realm the authentication 'realm' (optional) - * @param username the SIP username to be authenticated (mandatory) - * @param domain the SIP domain name (optional) - * @return a #LinphoneAuthInfo -**/ + const LinphoneAuthInfo *linphone_core_find_auth_info(LinphoneCore *lc, const char *realm, const char *username, const char *domain){ return _linphone_core_find_auth_info(lc, realm, username, domain, TRUE); } @@ -295,9 +287,9 @@ const LinphoneAuthInfo *linphone_core_find_auth_info(LinphoneCore *lc, const cha void linphone_core_write_auth_info(LinphoneCore *lc, LinphoneAuthInfo *ai){ int i; MSList *elem = lc->auth_info; - + if (!lc->sip_conf.save_auth_info) return; - + for (i=0; elem != NULL; elem = elem->next, i++){ if (ai == elem->data){ linphone_auth_info_write_config(lc->config, ai, i); diff --git a/coreapi/linphone_proxy_config.h b/coreapi/linphone_proxy_config.h index a84a8c8f3..f28de3df7 100644 --- a/coreapi/linphone_proxy_config.h +++ b/coreapi/linphone_proxy_config.h @@ -521,6 +521,13 @@ LINPHONE_PUBLIC const char *linphone_proxy_config_get_custom_header(LinphoneProx **/ LINPHONE_PUBLIC void linphone_proxy_config_set_custom_header(LinphoneProxyConfig *cfg, const char *header_name, const char *header_value); +/** + * Find authentication info matching proxy config, if any, similarly to linphone_core_find_auth_info. + * @param[in] cfg #LinphoneProxyConfig object. + * @return a #LinphoneAuthInfo matching proxy config criteria if possible, NULL if nothing can be found. +**/ +LINPHONE_PUBLIC const struct _LinphoneAuthInfo* linphone_proxy_config_find_auth_info(const LinphoneProxyConfig *cfg); + /** * @} */ diff --git a/coreapi/linphonecore.h b/coreapi/linphonecore.h index aa6856d21..ccaa05913 100644 --- a/coreapi/linphonecore.h +++ b/coreapi/linphonecore.h @@ -47,6 +47,9 @@ extern "C" { struct _LinphoneCore; struct _LinphoneChatRoom; +struct _LinphoneAuthInfo; +struct _SipSetupContext; +struct _LinphoneInfoMessage; /** * Linphone core main object created by function linphone_core_new() . @@ -442,10 +445,6 @@ LINPHONE_PUBLIC void linphone_address_destroy(LinphoneAddress *u); */ LINPHONE_PUBLIC LinphoneAddress * linphone_core_create_address(LinphoneCore *lc, const char *address); -struct _SipSetupContext; - - -struct _LinphoneInfoMessage; /** * The LinphoneInfoMessage is an object representing an informational message sent or received by the core. **/ @@ -1022,8 +1021,6 @@ LINPHONE_PUBLIC const char *linphone_registration_state_to_string(LinphoneRegist #include "linphone_proxy_config.h" -struct _LinphoneAuthInfo; - /** * @addtogroup authentication * @{ @@ -2900,6 +2897,15 @@ LINPHONE_PUBLIC void linphone_core_remove_auth_info(LinphoneCore *lc, const Linp LINPHONE_PUBLIC const MSList *linphone_core_get_auth_info_list(const LinphoneCore *lc); +/** + * Find authentication info matching realm, username, domain criteria. + * First of all, (realm,username) pair are searched. If multiple results (which should not happen because realm are supposed to be unique), then domain is added to the search. + * @param lc the LinphoneCore + * @param realm the authentication 'realm' (optional) + * @param username the SIP username to be authenticated (mandatory) + * @param domain the SIP domain name (optional) + * @return a #LinphoneAuthInfo +**/ LINPHONE_PUBLIC const LinphoneAuthInfo *linphone_core_find_auth_info(LinphoneCore *lc, const char *realm, const char *username, const char *sip_domain); LINPHONE_PUBLIC void linphone_core_abort_authentication(LinphoneCore *lc, LinphoneAuthInfo *info); diff --git a/coreapi/proxy.c b/coreapi/proxy.c index 6d9ba8181..c0b96c6fc 100644 --- a/coreapi/proxy.c +++ b/coreapi/proxy.c @@ -1548,3 +1548,9 @@ uint8_t linphone_proxy_config_get_avpf_rr_interval(const LinphoneProxyConfig *cf const LinphoneAddress* linphone_proxy_config_get_contact(const LinphoneProxyConfig *cfg) { return sal_op_get_contact_address(cfg->op); } + +const struct _LinphoneAuthInfo* linphone_proxy_config_find_auth_info(const LinphoneProxyConfig *cfg) { + const char* username = cfg->identity_address ? linphone_address_get_username(cfg->identity_address) : NULL; + const char* domain = cfg->identity_address ? linphone_address_get_domain(cfg->identity_address) : NULL; + return _linphone_core_find_auth_info(cfg->lc, cfg->realm, username, domain, TRUE); +}