Commit d41e2d5d authored by Ronan's avatar Ronan

fix(core): coding style, avoid spaces => use tabs instead, alignment...

parent b7d0db12
......@@ -43,30 +43,29 @@ BELLE_SIP_INSTANCIATE_VPTR(
);
LinphoneAuthInfo *linphone_auth_info_new(const char *username, const char *userid, const char *passwd, const char *ha1, const char *realm, const char *domain){
return linphone_auth_info_new_for_algorithm(username, userid, passwd, ha1, realm, domain, NULL);
return linphone_auth_info_new_for_algorithm(username, userid, passwd, ha1, realm, domain, NULL);
}
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){
LinphoneAuthInfo *obj=belle_sip_object_new(LinphoneAuthInfo);
if (username!=NULL && (strlen(username)>0) ) obj->username=ms_strdup(username);
if (userid!=NULL && (strlen(userid)>0)) obj->userid=ms_strdup(userid);
if (passwd!=NULL && (strlen(passwd)>0)) obj->passwd=ms_strdup(passwd);
if (ha1!=NULL && (strlen(ha1)>0)) obj->ha1=ms_strdup(ha1);
if (realm!=NULL && (strlen(realm)>0)) obj->realm=ms_strdup(realm);
if (domain!=NULL && (strlen(domain)>0)) obj->domain=ms_strdup(domain);
/* Default algorithm is MD5 if it's NULL*/
if(algorithm==NULL)
obj->algorithm = ms_strdup("MD5");
/* If algorithm is neither MD5 or SHA-256, exit wit error*/
if(algorithm && strcmp(algorithm, "MD5") && strcmp(algorithm, "SHA-256")){
ms_error("Given algorithm %s is not correct.", algorithm);
return NULL;
}
/*Else, set algorithm for obj */
if(algorithm){
obj->algorithm=ms_strdup(algorithm);
}
return obj;
LinphoneAuthInfo *obj=belle_sip_object_new(LinphoneAuthInfo);
if (username!=NULL && (strlen(username)>0) ) obj->username=ms_strdup(username);
if (userid!=NULL && (strlen(userid)>0)) obj->userid=ms_strdup(userid);
if (passwd!=NULL && (strlen(passwd)>0)) obj->passwd=ms_strdup(passwd);
if (ha1!=NULL && (strlen(ha1)>0)) obj->ha1=ms_strdup(ha1);
if (realm!=NULL && (strlen(realm)>0)) obj->realm=ms_strdup(realm);
if (domain!=NULL && (strlen(domain)>0)) obj->domain=ms_strdup(domain);
if (!algorithm)
obj->algorithm = ms_strdup("MD5");
if(algorithm && strcmp(algorithm, "MD5") && strcmp(algorithm, "SHA-256")){
ms_error("Given algorithm %s is not correct.", algorithm);
return NULL;
}
if(algorithm)
obj->algorithm=ms_strdup(algorithm);
return obj;
}
static void _linphone_auth_info_copy(LinphoneAuthInfo *dst, const LinphoneAuthInfo *src) {
......@@ -80,7 +79,7 @@ static void _linphone_auth_info_copy(LinphoneAuthInfo *dst, const LinphoneAuthIn
if (src->tls_key) dst->tls_key = ms_strdup(src->tls_key);
if (src->tls_cert_path) dst->tls_cert_path = ms_strdup(src->tls_cert_path);
if (src->tls_key_path) dst->tls_key_path = ms_strdup(src->tls_key_path);
if (src->algorithm) dst->algorithm = ms_strdup(src->algorithm);
if (src->algorithm) dst->algorithm = ms_strdup(src->algorithm);
}
LinphoneAuthInfo *linphone_auth_info_clone(const LinphoneAuthInfo *ai){
......@@ -234,7 +233,7 @@ static void _linphone_auth_info_uninit(LinphoneAuthInfo *obj) {
if (obj->tls_key != NULL) ms_free(obj->tls_key);
if (obj->tls_cert_path != NULL) ms_free(obj->tls_cert_path);
if (obj->tls_key_path != NULL) ms_free(obj->tls_key_path);
if (obj->algorithm != NULL) ms_free(obj->algorithm);
if (obj->algorithm != NULL) ms_free(obj->algorithm);
}
/**
......@@ -255,17 +254,16 @@ void linphone_auth_info_write_config(LpConfig *config, LinphoneAuthInfo *obj, in
return;
}
if (!obj->ha1 && obj->realm && obj->passwd && (obj->username || obj->userid) && store_ha1_passwd) {
/*compute ha1 to avoid storing clear text password*/
/* Default algorithm is MD5 if it's NULL */
if((obj->algorithm==NULL)||(!(strcmp(obj->algorithm, "MD5")))){
obj->ha1 = reinterpret_cast<char *>(ms_malloc(33));
sal_auth_compute_ha1(obj->userid ? obj->userid : obj->username, obj->realm, obj->passwd, obj->ha1);
}
/* If algorithm is SHA-256, calcul ha1 by sha256*/
if((obj->algorithm)&&(!(strcmp(obj->algorithm, "SHA-256")))){
obj->ha1 = reinterpret_cast<char *>(ms_malloc(65));
sal_auth_compute_ha1_for_algorithm(obj->userid ? obj->userid : obj->username, obj->realm, obj->passwd, obj->ha1,65, obj->algorithm);
}
/* Default algorithm is MD5 if it's NULL */
if((obj->algorithm==NULL)||(!(strcmp(obj->algorithm, "MD5")))){
obj->ha1 = reinterpret_cast<char *>(ms_malloc(33));
sal_auth_compute_ha1(obj->userid ? obj->userid : obj->username, obj->realm, obj->passwd, obj->ha1);
}
/* If algorithm is SHA-256, calcul ha1 by sha256*/
if((obj->algorithm)&&(!(strcmp(obj->algorithm, "SHA-256")))){
obj->ha1 = reinterpret_cast<char *>(ms_malloc(65));
sal_auth_compute_ha1_for_algorithm(obj->userid ? obj->userid : obj->username, obj->realm, obj->passwd, obj->ha1,65, obj->algorithm);
}
}
if (obj->username != NULL) {
lp_config_set_string(config, key, "username", obj->username);
......@@ -297,9 +295,9 @@ void linphone_auth_info_write_config(LpConfig *config, LinphoneAuthInfo *obj, in
if (obj->tls_key_path != NULL) {
lp_config_set_string(config, key, "client_cert_key", obj->tls_key_path);
}
if (obj->algorithm != NULL) {
lp_config_set_string(config, key, "algorithm", obj->algorithm);
}
if (obj->algorithm != NULL) {
lp_config_set_string(config, key, "algorithm", obj->algorithm);
}
}
LinphoneAuthInfo *linphone_auth_info_new_from_config_file(LpConfig * config, int pos)
......@@ -484,7 +482,7 @@ void linphone_core_add_auth_info(LinphoneCore *lc, const LinphoneAuthInfo *info)
sai.realm=ai->realm;
sai.password=ai->passwd;
sai.ha1=ai->ha1;
sai.algorithm=ai->algorithm;
sai.algorithm=ai->algorithm;
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, "");
......
......@@ -65,7 +65,7 @@ SalAuthInfo* sal_auth_info_create(belle_sip_auth_event_t* event) {
auth_info->username = ms_strdup(belle_sip_auth_event_get_username(event));
auth_info->domain = ms_strdup(belle_sip_auth_event_get_domain(event));
auth_info->mode = (SalAuthMode)belle_sip_auth_event_get_mode(event);
auth_info->algorithm = ms_strdup(belle_sip_auth_event_get_algorithm(event));
auth_info->algorithm = ms_strdup(belle_sip_auth_event_get_algorithm(event));
return auth_info;
}
......@@ -84,9 +84,15 @@ int sal_auth_compute_ha1(const char* userid,const char* realm,const char* passwo
return belle_sip_auth_helper_compute_ha1(userid, realm, password, ha1);
}
int sal_auth_compute_ha1_for_algorithm(const char* userid,const char* realm,const char* password, char* ha1,
size_t size, const char* algo) {
return belle_sip_auth_helper_compute_ha1_for_algorithm(userid, realm, password, ha1, size, algo);
int sal_auth_compute_ha1_for_algorithm(
const char *userid,
const char *realm,
const char *password,
char *ha1,
size_t size,
const char *algo
) {
return belle_sip_auth_helper_compute_ha1_for_algorithm(userid, realm, password, ha1, size, algo);
}
SalCustomHeader *sal_custom_header_ref(SalCustomHeader *ch){
......
......@@ -526,15 +526,18 @@ static bool_t fill_auth_info(LinphoneCore *lc, SalAuthInfo* sai) {
}
if (ai) {
if (sai->mode == SalAuthModeHttpDigest) {
/* 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(strcmp(ai->algorithm, sai->algorithm))
return TRUE;
}
else if((ai->algorithm && strcmp(ai->algorithm, "MD5")) ||
(sai->algorithm && strcmp(sai->algorithm, "MD5")))
return TRUE;
/*
* 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 (strcmp(ai->algorithm, sai->algorithm))
return TRUE;
} else if (
(ai->algorithm && strcmp(ai->algorithm, "MD5")) ||
(sai->algorithm && strcmp(sai->algorithm, "MD5"))
)
return TRUE;
sai->userid = ms_strdup(ai->userid ? ai->userid : ai->username);
sai->password = ai->passwd?ms_strdup(ai->passwd) : NULL;
......
......@@ -562,7 +562,7 @@ struct _LinphoneAuthInfo
char *tls_key;
char *tls_cert_path;
char *tls_key_path;
char *algorithm;
char *algorithm;
};
typedef enum _LinphoneIsComposingState {
......
......@@ -51,11 +51,25 @@ extern "C" {
* @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 *realm, const char *domain);
LINPHONE_PUBLIC 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);
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
);
LINPHONE_PUBLIC 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
);
/**
* Instantiates a new auth info with values from source.
* @param[in] source The #LinphoneAuthInfo object to be cloned
......
......@@ -762,7 +762,7 @@ SalAuthInfo* sal_auth_info_clone(const SalAuthInfo* auth_info) {
new_auth_info->realm=auth_info->realm?ms_strdup(auth_info->realm):NULL;
new_auth_info->domain=auth_info->realm?ms_strdup(auth_info->domain):NULL;
new_auth_info->password=auth_info->password?ms_strdup(auth_info->password):NULL;
new_auth_info->algorithm=auth_info->algorithm?ms_strdup(auth_info->algorithm):NULL;
new_auth_info->algorithm=auth_info->algorithm?ms_strdup(auth_info->algorithm):NULL;
return new_auth_info;
}
......@@ -775,7 +775,7 @@ void sal_auth_info_delete(SalAuthInfo* auth_info) {
if (auth_info->ha1) ms_free(auth_info->ha1);
if (auth_info->certificates) sal_certificates_chain_delete(auth_info->certificates);
if (auth_info->key) sal_signing_key_delete(auth_info->key);
if (auth_info->algorithm) ms_free(auth_info->algorithm);
if (auth_info->algorithm) ms_free(auth_info->algorithm);
ms_free(auth_info);
}
......
......@@ -23,11 +23,11 @@
protocols and implementations under linphone, for example SIP, JINGLE...
**/
#ifndef sal_h
#define sal_h
#ifndef _C_SAL_H_
#define _C_SAL_H_
#ifdef HAVE_CONFIG_H
#include "config.h"
#include "config.h"
#endif
#include "mediastreamer2/mediastream.h"
......@@ -263,7 +263,7 @@ typedef struct SalStreamDescription{
SalSrtpCryptoAlgo crypto[SAL_CRYPTO_ALGO_MAX];
unsigned int crypto_local_tag;
int max_rate;
bool_t implicit_rtcp_fb;
bool_t implicit_rtcp_fb;
OrtpRtcpFbConfiguration rtcp_fb;
OrtpRtcpXrConfiguration rtcp_xr;
SalCustomSdpAttribute *custom_sdp_attributes;
......@@ -474,7 +474,7 @@ typedef struct SalAuthInfo{
char *realm;
char *domain;
char *ha1;
char *algorithm;
char *algorithm;
SalAuthMode mode;
belle_sip_signing_key_t *key;
belle_sip_certificates_chain_t *certificates;
......@@ -488,10 +488,8 @@ extern "C" {
SalAuthInfo* sal_auth_info_new(void);
SalAuthInfo* sal_auth_info_clone(const SalAuthInfo* auth_info);
void sal_auth_info_delete(SalAuthInfo* auth_info);
LINPHONE_PUBLIC int sal_auth_compute_ha1(const char* userid,const char* realm,const char* password, char ha1[33]);
LINPHONE_PUBLIC int sal_auth_compute_ha1_for_algorithm(const char* userid,const char* realm,const char* password, char *ha1,size_t size,const char* algo);
/*LINPHONE_PUBLIC int sal_auth_compute_ha1_for_algorithm(const char* userid,const char* realm,const char* password, char *ha1,
size_t size, const char* algo);*/
LINPHONE_PUBLIC int sal_auth_compute_ha1(const char *userid, const char *realm, const char *password, char ha1[33]);
LINPHONE_PUBLIC int sal_auth_compute_ha1_for_algorithm(const char *userid, const char *realm, const char *password, char *ha1, size_t size, const char *algo);
SalAuthMode sal_auth_info_get_mode(const SalAuthInfo* auth_info);
belle_sip_signing_key_t *sal_auth_info_get_signing_key(const SalAuthInfo* auth_info);
belle_sip_certificates_chain_t *sal_auth_info_get_certificates_chain(const SalAuthInfo* auth_info);
......@@ -579,13 +577,13 @@ typedef enum _SalPrivacy {
SalPrivacyCritical=0x10,
SalPrivacyDefault=0x8000
} SalPrivacy;
typedef unsigned int SalPrivacyMask;
typedef unsigned int SalPrivacyMask;
#ifdef __cplusplus
extern "C" {
#endif
const char* sal_privacy_to_string(SalPrivacy privacy);
const char* sal_privacy_to_string(SalPrivacy privacy);
#ifdef __cplusplus
}
......@@ -593,8 +591,8 @@ const char* sal_privacy_to_string(SalPrivacy privacy);
#define payload_type_set_number(pt,n) (pt)->user_data=(void*)((intptr_t)n);
#define payload_type_get_number(pt) ((int)(intptr_t)(pt)->user_data)
#define payload_type_set_number(pt,n) (pt)->user_data=(void*)((intptr_t)n);
#define payload_type_get_number(pt) ((int)(intptr_t)(pt)->user_data)
#ifdef __cplusplus
extern "C" {
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment