Commit 2c2462c4 authored by rosset claire's avatar rosset claire

Wrapped auth info in C++

parent 9bc9717b
This diff is collapsed.
......@@ -86,11 +86,14 @@ static void call_received(SalCallOp *h) {
if (pAssertedIdAddr) {
ms_message("Using P-Asserted-Identity [%s] instead of from [%s] for op [%p]", pAssertedId, h->getFrom().c_str(), h);
fromAddr = pAssertedIdAddr;
} else
} else{
ms_warning("Unsupported P-Asserted-Identity header for op [%p] ", h);
} else
}
} else{
ms_warning("No P-Asserted-Identity header found so cannot use it for op [%p] instead of from", h);
}
}
if (!fromAddr)
fromAddr = linphone_address_new(h->getFrom().c_str());
......@@ -538,31 +541,31 @@ static bool_t fill_auth_info(LinphoneCore *lc, SalAuthInfo* sai) {
* Compare algorithm of server(sai) with algorithm of client(ai), if they are not correspondant,
* exit. The default algorithm is MD5 if it's NULL.
*/
if (sai->algorithm && ai->algorithm) {
if (strcasecmp(ai->algorithm, sai->algorithm))
if (sai->algorithm && linphone_auth_info_get_algorithm(ai)) {
if (strcasecmp(linphone_auth_info_get_algorithm(ai), sai->algorithm))
return TRUE;
} else if (
(ai->algorithm && strcasecmp(ai->algorithm, "MD5")) ||
(linphone_auth_info_get_algorithm(ai) && strcasecmp(linphone_auth_info_get_algorithm(ai), "MD5")) ||
(sai->algorithm && strcasecmp(sai->algorithm, "MD5"))
)
return TRUE;
sai->userid = ms_strdup(ai->userid ? ai->userid : ai->username);
sai->password = ai->passwd?ms_strdup(ai->passwd) : NULL;
sai->ha1 = ai->ha1 ? ms_strdup(ai->ha1) : NULL;
sai->userid = ms_strdup(linphone_auth_info_get_userid(ai) ? linphone_auth_info_get_userid(ai) : linphone_auth_info_get_username(ai));
sai->password = linphone_auth_info_get_passwd(ai)?ms_strdup(linphone_auth_info_get_passwd(ai)) : NULL;
sai->ha1 = linphone_auth_info_get_ha1(ai) ? ms_strdup(linphone_auth_info_get_ha1(ai)) : NULL;
} else if (sai->mode == SalAuthModeTls) {
if (ai->tls_cert && ai->tls_key) {
sal_certificates_chain_parse(sai, ai->tls_cert, SAL_CERTIFICATE_RAW_FORMAT_PEM);
sal_signing_key_parse(sai, ai->tls_key, "");
} else if (ai->tls_cert_path && ai->tls_key_path) {
sal_certificates_chain_parse_file(sai, ai->tls_cert_path, SAL_CERTIFICATE_RAW_FORMAT_PEM);
sal_signing_key_parse_file(sai, ai->tls_key_path, "");
if (linphone_auth_info_get_tls_cert(ai) && linphone_auth_info_get_tls_key(ai)) {
sal_certificates_chain_parse(sai, linphone_auth_info_get_tls_cert(ai), SAL_CERTIFICATE_RAW_FORMAT_PEM);
sal_signing_key_parse(sai, linphone_auth_info_get_tls_key(ai), "");
} else if (linphone_auth_info_get_tls_cert_path(ai) && linphone_auth_info_get_tls_key_path(ai)) {
sal_certificates_chain_parse_file(sai, linphone_auth_info_get_tls_cert_path(ai), SAL_CERTIFICATE_RAW_FORMAT_PEM);
sal_signing_key_parse_file(sai, linphone_auth_info_get_tls_key_path(ai), "");
} else {
fill_auth_info_with_client_certificate(lc, sai);
}
}
if (sai->realm && !ai->realm){
if (sai->realm && !linphone_auth_info_get_realm(ai)){
/*if realm was not known, then set it so that ha1 may eventually be calculated and clear text password dropped*/
linphone_auth_info_set_realm(ai, sai->realm);
linphone_core_write_auth_info(lc, ai);
......
......@@ -19,6 +19,10 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "linphone/core.h"
#include "private.h"
#include "linphone/api/c-auth-info.h"
LinphoneCardDavContext* linphone_carddav_context_new(LinphoneFriendList *lfl) {
LinphoneCardDavContext *carddav_context = NULL;
......@@ -471,9 +475,9 @@ static void process_auth_requested_from_carddav_request(void *data, belle_sip_au
const char *domain = belle_generic_uri_get_host(uri);
if (cdc->auth_info) {
belle_sip_auth_event_set_username(event, cdc->auth_info->username);
belle_sip_auth_event_set_passwd(event, cdc->auth_info->passwd);
belle_sip_auth_event_set_ha1(event, cdc->auth_info->ha1);
belle_sip_auth_event_set_username(event, linphone_auth_info_get_username(cdc->auth_info));
belle_sip_auth_event_set_passwd(event, linphone_auth_info_get_passwd(cdc->auth_info));
belle_sip_auth_event_set_ha1(event, linphone_auth_info_get_ha1(cdc->auth_info));
} else {
LinphoneCore *lc = cdc->friend_list->lc;
const bctbx_list_t *auth_infos = linphone_core_get_auth_info_list(lc);
......@@ -481,11 +485,11 @@ static void process_auth_requested_from_carddav_request(void *data, belle_sip_au
ms_debug("Looking for auth info for domain %s and realm %s", domain, realm);
while (auth_infos) {
LinphoneAuthInfo *auth_info = (LinphoneAuthInfo *)auth_infos->data;
if (auth_info->domain && strcmp(domain, auth_info->domain) == 0) {
if (!auth_info->realm || strcmp(realm, auth_info->realm) == 0) {
belle_sip_auth_event_set_username(event, auth_info->username);
belle_sip_auth_event_set_passwd(event, auth_info->passwd);
belle_sip_auth_event_set_ha1(event, auth_info->ha1);
if (linphone_auth_info_get_domain(auth_info) && strcmp(domain, linphone_auth_info_get_domain(auth_info)) == 0) {
if (!linphone_auth_info_get_realm(auth_info) || strcmp(realm, linphone_auth_info_get_realm(auth_info)) == 0) {
belle_sip_auth_event_set_username(event, linphone_auth_info_get_username(auth_info));
belle_sip_auth_event_set_passwd(event, linphone_auth_info_get_passwd(auth_info));
belle_sip_auth_event_set_ha1(event, linphone_auth_info_get_ha1(auth_info));
cdc->auth_info = linphone_auth_info_clone(auth_info);
break;
}
......
......@@ -123,8 +123,6 @@ bool_t linphone_call_params_get_no_user_consent(const LinphoneCallParams *params
// FIXME: Remove this declaration, use LINPHONE_PUBLIC as ugly workaround, already defined in tester_utils.h
LINPHONE_PUBLIC void linphone_call_params_set_no_user_consent(LinphoneCallParams *params, bool_t value);
void linphone_auth_info_write_config(LinphoneConfig *config, LinphoneAuthInfo *obj, int pos);
LinphoneAuthInfo * linphone_auth_info_new_from_config_file(LpConfig *config, int pos);
void _linphone_core_uninit(LinphoneCore *lc);
void linphone_core_write_auth_info(LinphoneCore *lc, LinphoneAuthInfo *ai);
const LinphoneAuthInfo *_linphone_core_find_tls_auth_info(LinphoneCore *lc);
......
......@@ -146,22 +146,6 @@ struct _LinphoneProxyConfig
BELLE_SIP_DECLARE_VPTR_NO_EXPORT(LinphoneProxyConfig);
struct _LinphoneAuthInfo
{
belle_sip_object_t base;
char *username;
char *realm;
char *userid;
char *passwd;
char *ha1;
char *domain;
char *tls_cert;
char *tls_key;
char *tls_cert_path;
char *tls_key_path;
char *algorithm;
};
struct _LinphoneFriendPresence {
char *uri_or_tel;
LinphonePresenceModel *presence;
......
......@@ -24,6 +24,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "linphone/core.h"
#include "c-wrapper/c-wrapper.h"
#include "linphone/api/c-auth-info.h"
// TODO: From coreapi. Remove me later.
#include "private.h"
......
......@@ -23,7 +23,6 @@
set(ROOT_HEADER_FILES
account_creator_service.h
account_creator.h
auth_info.h
buffer.h
call_log.h
call_params.h
......@@ -75,6 +74,7 @@ set(ROOT_HEADER_FILES
set(C_API_HEADER_FILES
c-address.h
c-auth-info.h
c-api.h
c-call-cbs.h
c-call-stats.h
......
......@@ -22,6 +22,7 @@
#include "linphone/utils/general.h"
#include "linphone/api/c-auth-info.h"
#include "linphone/api/c-address.h"
#include "linphone/api/c-call-cbs.h"
#include "linphone/api/c-call-stats.h"
......
......@@ -20,8 +20,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#ifndef LINPHONE_AUTH_INFO_H
#define LINPHONE_AUTH_INFO_H
#include <mediastreamer2/mscommon.h>
#include "linphone/types.h"
#include "linphone/api/c-types.h"
/**
* @addtogroup authentication
......@@ -31,34 +30,18 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
/**
* Safely cast a belle_sip_object_t into #LinphoneAuthInfo
*/
#define LINPHONE_AUTH_INFO(obj) BELLE_SIP_CAST(obj, LinphoneAuthInfo)
#ifdef __cplusplus
extern "C" {
#endif
/**
* Creates a #LinphoneAuthInfo object with supplied information.
* The object can be created empty, that is with all arguments set to NULL.
* Username, userid, password, realm and domain can be set later using specific methods.
* At the end, username and passwd (or ha1) are required.
* @param username The username that needs to be authenticated
* @param userid The userid used for authenticating (use NULL if you don't know what it is)
* @param passwd The password in clear text
* @param ha1 The ha1-encrypted password if password is not given in clear text.
* @param realm The authentication domain (which can be larger than the sip domain. Unfortunately many SIP servers don't use this parameter.
* @param domain The SIP domain for which this authentication information is valid, if it has to be restricted for a single SIP domain.
* @return A #LinphoneAuthInfo object. linphone_auth_info_destroy() must be used to destroy it when no longer needed. The #LinphoneCore makes a copy of #LinphoneAuthInfo
* passed through linphone_core_add_auth_info().
**/
LINPHONE_PUBLIC LinphoneAuthInfo *linphone_auth_info_new(
const char *username,
const char *userid,
const char *passwd,
const char *ha1,
const char *rfealm,
const char *domain
);
const char *domain);
LINPHONE_PUBLIC LinphoneAuthInfo *linphone_auth_info_new_for_algorithm(
const char *username,
......@@ -67,15 +50,13 @@ LINPHONE_PUBLIC LinphoneAuthInfo *linphone_auth_info_new_for_algorithm(
const char *ha1,
const char *realm,
const char *domain,
const char *algorithm
);
const char *algorithm);
/**
* Instantiates a new auth info with values from source.
* @param[in] source The #LinphoneAuthInfo object to be cloned
* @return The newly created #LinphoneAuthInfo object.
*/
LINPHONE_PUBLIC LinphoneAuthInfo *linphone_auth_info_clone(const LinphoneAuthInfo* source);
LINPHONE_PUBLIC LinphoneAuthInfo *linphone_auth_info_clone(const LinphoneAuthInfo *source);
/**
* Take a reference on a #LinphoneAuthInfo.
......@@ -263,6 +244,10 @@ LINPHONE_PUBLIC const char *linphone_auth_info_get_tls_key_path(const LinphoneAu
/* you don't need those function*/
LINPHONE_PUBLIC LINPHONE_DEPRECATED void linphone_auth_info_destroy(LinphoneAuthInfo *info);
void linphone_auth_info_write_config(LpConfig *config, LinphoneAuthInfo *obj, int pos);
LinphoneAuthInfo *linphone_auth_info_new_from_config_file(LpConfig *config, int pos);
/**
* @}
*/
......
......@@ -34,7 +34,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "linphone/account_creator.h"
#include "linphone/account_creator_service.h"
#include "linphone/auth_info.h"
#include "linphone/buffer.h"
#include "linphone/call.h"
#include "linphone/call_log.h"
......
......@@ -83,6 +83,7 @@ set(LINPHONE_CXX_OBJECTS_PRIVATE_HEADER_FILES
address/address.h
address/identity-address.h
address/identity-address-parser.h
auth-info/auth-info.h
c-wrapper/c-wrapper.h
c-wrapper/internal/c-sal.h
c-wrapper/internal/c-tools.h
......@@ -243,6 +244,7 @@ set(LINPHONE_CXX_OBJECTS_SOURCE_FILES
address/identity-address.cpp
address/identity-address-parser.cpp
c-wrapper/api/c-address.cpp
c-wrapper/api/c-auth-info.cpp
c-wrapper/api/c-call-cbs.cpp
c-wrapper/api/c-call-params.cpp
c-wrapper/api/c-call-stats.cpp
......@@ -265,6 +267,7 @@ set(LINPHONE_CXX_OBJECTS_SOURCE_FILES
c-wrapper/api/c-search-result.cpp
c-wrapper/internal/c-sal.cpp
c-wrapper/internal/c-tools.cpp
auth-info/auth-info.cpp
call/call.cpp
call/local-conference-call.cpp
call/remote-conference-call.cpp
......
/*
* auth-info.cpp
* Copyright (C) 2010-2019 Belledonne Communications SARL
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "auth-info.h"
#include "logger/logger.h"
#include "linphone/lpconfig.h"
#include "bellesip_sal/sal_impl.h"
using namespace std;
LINPHONE_BEGIN_NAMESPACE
AuthInfo::AuthInfo(const string &username, const string &userid, const string &passwd, const string &ha1, const string &realm, const string &domain){
AuthInfo::init(username, userid, passwd, ha1, realm, domain, "");
}
AuthInfo::AuthInfo(const string &username, const string &userid, const string &passwd, const string &ha1, const string &realm, const string &domain, const string &algorithm){
AuthInfo::init(username, userid, passwd, ha1, realm, domain, algorithm);
if(algorithm.empty()){
mAlgorithm = "MD5";
}
else{
mAlgorithm = algorithm;
}
}
void AuthInfo::init(const string &username, const string &userid, const string &passwd, const string &ha1, const string &realm, const string &domain, const string &algorithm){
mUsername = username;
mUserid = userid;
mPasswd = passwd;
mHa1 = ha1;
mRealm = realm;
mDomain = domain;
mAlgorithm = algorithm;
}
AuthInfo::AuthInfo(LpConfig *config, string key){
const char *username, *userid, *passwd, *ha1, *realm, *domain, *tls_cert_path, *tls_key_path, *algo;
username = lp_config_get_string(config, key.c_str(), "username", "");
userid = lp_config_get_string(config, key.c_str(), "userid", "");
passwd = lp_config_get_string(config, key.c_str(), "passwd", "");
ha1 = lp_config_get_string(config, key.c_str(), "ha1", "");
realm = lp_config_get_string(config, key.c_str(), "realm", "");
domain = lp_config_get_string(config, key.c_str(), "domain", "");
tls_cert_path = lp_config_get_string(config, key.c_str(), "client_cert_chain", "");
tls_key_path = lp_config_get_string(config, key.c_str(), "client_cert_key", "");
algo = lp_config_get_string(config, key.c_str(), "algorithm", "MD5");
setTlsCertPath(tls_cert_path);
setTlsKeyPath(tls_key_path);
init(username, userid, passwd, ha1, realm, domain, algo);
}
AuthInfo* AuthInfo::clone() const {
AuthInfo *ai = new AuthInfo(getUsername(), getUserid(), getPassword(), getHa1(), getRealm(), getDomain(), getAlgorithm());
ai->setTlsCert(getTlsCert());
ai->setTlsCertPath(getTlsCertPath());
ai->setTlsKey(getTlsKey());
ai->setTlsKeyPath(getTlsKeyPath());
return ai;
}
const string& AuthInfo::getUsername() const{
return mUsername;
}
const string& AuthInfo::getAlgorithm() const{
return mAlgorithm;
}
const string& AuthInfo::getPassword() const{
return mPasswd;
}
const string& AuthInfo::getUserid() const{
return mUserid;
}
const string& AuthInfo::getRealm() const{
return mRealm;
}
const string& AuthInfo::getDomain() const{
return mDomain;
}
const string& AuthInfo::getHa1() const{
return mHa1;
}
const string& AuthInfo::getTlsCert() const{
return mTlsCert;
}
const string& AuthInfo::getTlsKey() const{
return mTlsKey;
}
const string& AuthInfo::getTlsCertPath() const{
return mTlsCertPath;
}
const string& AuthInfo::getTlsKeyPath() const{
return mTlsKeyPath;
}
void AuthInfo::setPassword(const string &passwd){
mPasswd = passwd;
}
void AuthInfo::setUsername(const string &username){
mUsername = username;
}
void AuthInfo::setAlgorithm(const string &algorithm){
if(!algorithm.empty()){
mAlgorithm = algorithm;
}
if(algorithm.compare("MD5") == 0 && algorithm.compare("SHA-256") == 0){
lError() << "Given algorithm is not correct. Set algorithm failed";
}
else{
mAlgorithm = "MD5";
}
}
void AuthInfo::setUserid(const string &userid){
mUserid = userid;
}
void AuthInfo::setRealm(const string &realm){
mRealm = realm;
}
void AuthInfo::setDomain(const string &domain){
mDomain = domain;
}
void AuthInfo::setHa1(const string &ha1){
mHa1 = ha1;
}
void AuthInfo::setTlsCert(const string &tlsCert){
mTlsCert = tlsCert;
}
void AuthInfo::setTlsKey(const string &tlsKey){
mTlsKey = tlsKey;
}
void AuthInfo::setTlsCertPath(const string &tlsCertPath){
mTlsCertPath = tlsCertPath;
}
void AuthInfo::setTlsKeyPath(const string &tlsKeyPath){
mTlsKeyPath = tlsKeyPath;
}
void AuthInfo::writeConfig(LpConfig *config, int pos){
char key[50];
char *myHa1;
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);
if (lp_config_get_int(config, "sip", "store_auth_info", 1) == 0) {
return;
}
if (getHa1().empty() && !getRealm().empty() && !getPassword().empty() && (!getUsername().empty() || !getUserid().empty()) && store_ha1_passwd) {
/* Default algorithm is MD5 if it's NULL */
if(getAlgorithm().empty() || getAlgorithm().compare("MD5") == 0){
myHa1 = reinterpret_cast<char *>(ms_malloc(33));
sal_auth_compute_ha1(getUserid().empty() ? getUsername().c_str() : getUserid().c_str(), getRealm().c_str(), getPassword().c_str(), myHa1);
mHa1 = myHa1;
ms_free(myHa1);
}
/* If algorithm is SHA-256, calcul ha1 by sha256*/
else if(getAlgorithm().compare("SHA-256") == 0){
myHa1 = reinterpret_cast<char *>(ms_malloc(65));
sal_auth_compute_ha1_for_algorithm(getUserid().empty() ? getUsername().c_str() : getUserid().c_str(), getRealm().c_str(), getPassword().c_str(), myHa1, 65, getAlgorithm().c_str());
mHa1 = myHa1;
ms_free(myHa1);
}
}
lp_config_set_string(config, key, "username", getUsername().c_str());
lp_config_set_string(config, key, "userid", getUserid().c_str());
lp_config_set_string(config, key, "ha1", getHa1().c_str());
if (store_ha1_passwd && !getHa1().empty()) {
/*if we have our ha1 and store_ha1_passwd set to TRUE, then drop the clear text password for security*/
setPassword("");
}
else {
/*we store clear text password only if store_ha1_passwd is FALSE AND we have an ha1 to store. Otherwise, passwd would simply be removed, which might bring major auth issue*/
lp_config_set_string(config, key, "passwd", getPassword().c_str());
}
lp_config_set_string(config, key, "realm", getRealm().c_str());
lp_config_set_string(config, key, "domain", getDomain().c_str());
lp_config_set_string(config, key, "client_cert_chain", getTlsCertPath().c_str());
lp_config_set_string(config, key, "client_cert_key", getTlsKeyPath().c_str());
lp_config_set_string(config, key, "algorithm",getAlgorithm().c_str());
}
std::string AuthInfo::toString() const{
std::ostringstream ss;
ss << "Username[" << mUsername << "];";
ss << "Userid[" << mUserid << "];";
ss << "Realm[" << mRealm << "];";
ss << "Domain[" << mDomain << "];";
ss << "Algorithm[" << mAlgorithm << "];";
return ss.str();
}
LINPHONE_END_NAMESPACE
\ No newline at end of file
/*
* auth-info.h
* Copyright (C) 2010-2019 Belledonne Communications SARL
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef AUTH_INFO_H
#define AUTH_INFO_H
#include <belle-sip/object++.hh>
#include "linphone/api/c-types.h"
LINPHONE_BEGIN_NAMESPACE
class AuthInfo : public bellesip::HybridObject<LinphoneAuthInfo, AuthInfo> {
public:
AuthInfo(const std::string &username = "", const std::string &userid = "", const std::string &passwd = "", const std::string &ha1 = "", const std::string &realm = "", const std::string &domain = "");
AuthInfo(const std::string &username, const std::string &userid, const std::string &passwd, const std::string &ha1, const std::string &realm, const std::string &domain, const std::string &algorithm);
AuthInfo(LpConfig * config, std::string key);
AuthInfo* clone() const override;
void init(const std::string &username, const std::string &userid, const std::string &passwd, const std::string &ha1, const std::string &realm, const std::string &domain, const std::string &algorithm);
void setPassword(const std::string &passwd);
void setUsername(const std::string &username);
void setAlgorithm(const std::string &algorithm);
void setUserid(const std::string &userid);
void setRealm(const std::string &realm);
void setDomain(const std::string &domain);
void setHa1(const std::string &ha1);
void setTlsCert(const std::string &tlsCert);
void setTlsKey(const std::string &tlsKey);
void setTlsCertPath(const std::string &tlsCertPath);
void setTlsKeyPath(const std::string &tlsKeyPath);
void writeConfig(LpConfig *config, int pos);
const std::string& getUsername() const;
const std::string& getAlgorithm() const;
const std::string& getPassword() const;
const std::string& getUserid() const;
const std::string& getRealm() const;
const std::string& getDomain() const;
const std::string& getHa1() const;
const std::string& getTlsCert() const;
const std::string& getTlsKey() const;
const std::string& getTlsCertPath() const;
const std::string& getTlsKeyPath() const;
private:
std::string mUsername;
std::string mUserid;
std::string mPasswd;
std::string mHa1;
std::string mRealm;
std::string mDomain;
std::string mAlgorithm;
std::string mTlsCert;
std::string mTlsKey;
std::string mTlsCertPath;
std::string mTlsKeyPath;
std::string toString() const override;
};
LINPHONE_END_NAMESPACE
#endif
/*
* c-auth-info.cpp
* Copyright (C) 2010-2019 Belledonne Communications SARL
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "linphone/api/c-auth-info.h"
#include "auth-info/auth-info.h"
#include "linphone/lpconfig.h"
#include "c-wrapper/c-wrapper.h"
using namespace LinphonePrivate;
LinphoneAuthInfo *linphone_auth_info_new(const char *username, const char *userid, const char *passwd, const char *ha1, const char *realm, const char *domain){
return AuthInfo::createCObject(username ? username : "", userid ? userid : "", passwd ? passwd : "", ha1 ? ha1 : "", realm ? realm : "", domain ? domain : "");
}
LinphoneAuthInfo *linphone_auth_info_new_for_algorithm(const char *username, const char *userid, const char *passwd, const char *ha1, const char *realm, const char *domain, const char *algorithm){
return AuthInfo::createCObject(username ? username : "", userid ? userid : "", passwd ? passwd : "", ha1 ? ha1 : "", realm ? realm : "", domain ? domain : "", algorithm ? algorithm : "");
}
LinphoneAuthInfo *linphone_auth_info_new_from_config_file(LpConfig * config, int pos){
char key[50];
sprintf(key, "auth_info_%i", pos);
if (lp_config_has_section(config, key)) {
LinphoneAuthInfo *ai = AuthInfo::createCObject(config, key);
return ai;
}
return NULL;
}
void linphone_auth_info_write_config(LpConfig *config, LinphoneAuthInfo *obj, int pos){
// obj will be null when writing all auth infos to mark the end
if (obj) {
AuthInfo::toCpp(obj)->writeConfig(config, pos);
} else {
char key[50];
sprintf(key, "auth_info_%i", pos);
lp_config_clean_section(config, key);
}
}
LinphoneAuthInfo *linphone_auth_info_clone(const LinphoneAuthInfo* source){
if(source){
LinphoneAuthInfo *ai = AuthInfo::toCpp(source)->clone()->toC();
return ai;
}
return NULL;
}
LinphoneAuthInfo *linphone_auth_info_ref(LinphoneAuthInfo *info){
if(info){
AuthInfo::toCpp(info)->ref();
return info;
}
return NULL;
}
void linphone_auth_info_unref(LinphoneAuthInfo *info){
if(info){
AuthInfo::toCpp(info)->unref();
}
}
void linphone_auth_info_set_password(LinphoneAuthInfo *info, const char *passwd){
AuthInfo::toCpp(info)->setPassword(L_C_TO_STRING(passwd));
}
void linphone_auth_info_set_passwd(LinphoneAuthInfo *info, const char *passwd) {
linphone_auth_info_set_password(info, passwd);
}
void linphone_auth_info_set_username(LinphoneAuthInfo *info, const char *username){
AuthInfo::toCpp(info)->setUsername(L_C_TO_STRING(username));
}
void linphone_auth_info_set_algorithm(LinphoneAuthInfo *info, const char *algorithm){
AuthInfo::toCpp(info)->setAlgorithm(L_C_TO_STRING(algorithm));
}
void linphone_auth_info_set_userid(LinphoneAuthInfo *info, const char *userid){
AuthInfo::toCpp(info)->setUserid(L_C_TO_STRING(userid));
}
void linphone_auth_info_set_realm(LinphoneAuthInfo *info, const char *realm){
AuthInfo::toCpp(info)->setRealm(L_C_TO_STRING(realm));
}
void linphone_auth_info_set_domain(LinphoneAuthInfo *info, const char *domain){
AuthInfo::toCpp(info)->setDomain(L_C_TO_STRING(domain));
}
void linphone_auth_info_set_ha1(LinphoneAuthInfo *info, const char *ha1){
AuthInfo::toCpp(info)->setHa1(L_C_TO_STRING(ha1));
}
void linphone_auth_info_set_tls_cert(LinphoneAuthInfo *info, const char *tls_cert){
AuthInfo::toCpp(info)->setTlsCert(L_C_TO_STRING(tls_cert));
}