Commit 13c1841b authored by DanmeiChen's avatar DanmeiChen
Browse files

indentation of code, use tab

parent b366baa6
......@@ -277,20 +277,19 @@ static
#else // STATIC_IMAXDIV ][
_inline
#endif // STATIC_IMAXDIV ]
imaxdiv_t __cdecl imaxdiv(intmax_t numer, intmax_t denom)
{
imaxdiv_t result;
imaxdiv_t __cdecl imaxdiv(intmax_t numer, intmax_t denom) {
imaxdiv_t result;
result.quot = numer / denom;
result.rem = numer % denom;
result.quot = numer / denom;
result.rem = numer % denom;
if (numer < 0 && result.rem > 0) {
// did division wrong; must fix up
++result.quot;
result.rem -= denom;
}
if (numer < 0 && result.rem > 0) {
// did division wrong; must fix up
++result.quot;
result.rem -= denom;
}
return result;
return result;
}
// 7.8.2.3 The strtoimax and strtoumax functions
......
......@@ -43,17 +43,17 @@ typedef unsigned __int64 uint64_t;
#endif
#ifdef _MSC_VER
#ifdef BELLESIP_STATIC
#define BELLESIP_EXPORT
#else
#ifdef BELLESIP_EXPORTS
#define BELLESIP_EXPORT __declspec(dllexport)
#else
#define BELLESIP_EXPORT __declspec(dllimport)
#endif
#endif
#ifdef BELLESIP_STATIC
#define BELLESIP_EXPORT
#else
#ifdef BELLESIP_EXPORTS
#define BELLESIP_EXPORT __declspec(dllexport)
#else
#define BELLESIP_EXPORT __declspec(dllimport)
#endif
#endif
#else
#define BELLESIP_EXPORT
#define BELLESIP_EXPORT
#endif
#define BELLESIP_UNUSED(a) (void)a;
......
......@@ -31,7 +31,7 @@
if (!belle_sip_header_##header_name##_get_##name(obj)) {\
belle_sip_error("parameter ["#name"]not found for header ["#header_name"]");\
return-1;\
}
}
static void belle_sip_auth_helper_clone_authorization(belle_sip_header_authorization_t* authorization, const belle_sip_header_www_authenticate_t* authentication) {
CLONE_STRING_GENERIC(belle_sip_header_www_authenticate,belle_sip_header_authorization,scheme,authorization,authentication)
......@@ -73,118 +73,115 @@ belle_sip_header_proxy_authorization_t* belle_sip_auth_helper_create_proxy_autho
return authorization;
}
static void belle_sip_auth_choose_method(const char* algo,char *ask,uint8_t *out, size_t size){
if((algo==NULL)||(!strcmp(algo,"MD5"))){
bctbx_md5((const unsigned char*)ask, strlen(ask), out);
}
else if(!strcmp(algo,"SHA-256")){
bctbx_sha256((const unsigned char*)ask, strlen(ask), size, out);
}
static void belle_sip_auth_choose_method(const char *algo, char *ask, uint8_t *out, size_t size) {
if ((algo == NULL) || (!strcmp(algo, "MD5"))) {
bctbx_md5((const unsigned char *)ask, strlen(ask), out);
} else if (!strcmp(algo, "SHA-256")) {
bctbx_sha256((const unsigned char *)ask, strlen(ask), size, out);
}
}
int belle_sip_auth_define_size(const char* algo) {
if((algo==NULL)||(!strcmp(algo,"MD5"))){
return 33;
}
else if(!strcmp(algo,"SHA-256")){
return 65;
}
else{
return 0;
}
int belle_sip_auth_define_size(const char *algo) {
if ((algo == NULL) || (!strcmp(algo, "MD5"))) {
return 33;
} else if (!strcmp(algo, "SHA-256")) {
return 65;
} else {
return 0;
}
}
int belle_sip_auth_helper_compute_ha1_for_algorithm(const char* userid,const char* realm,const char* password, char *ha1, size_t size, const char* algo) {
size_t compared_size;
compared_size = belle_sip_auth_define_size(algo);
if (compared_size!= size) {
belle_sip_error("belle_sip_fill_authorization_header, size of ha1 must be 33 when MD5 or 65 when SHA-256 ");
return -1;
}
size_t length_byte = (size-1)/2;
uint8_t out[length_byte];
size_t di;
char *ask;
if (!userid) {
belle_sip_error("belle_sip_fill_authorization_header, username not found ");
return -1;
}
if (!password) {
belle_sip_error("belle_sip_fill_authorization_header, password not found ");
return -1;
}
if (!realm) {
belle_sip_error("belle_sip_fill_authorization_header, password not found ");
return -1;
}
ask = bctbx_strdup_printf("%s:%s:%s", userid, realm, password);
belle_sip_auth_choose_method(algo, ask, out, length_byte);
for (di = 0; di < length_byte; ++di)
sprintf(ha1 + di * 2, "%02x", out[di]);
ha1[length_byte*2]='\0';
bctbx_free(ask);
return 0;
int belle_sip_auth_helper_compute_ha1_for_algorithm(const char *userid, const char *realm, const char *password, char *ha1, size_t size, const char *algo) {
size_t compared_size;
compared_size = belle_sip_auth_define_size(algo);
if (compared_size != size) {
belle_sip_error("belle_sip_fill_authorization_header, size of ha1 must be 33 when MD5 or 65 when SHA-256 ");
return -1;
}
size_t length_byte = (size - 1) / 2;
uint8_t out[length_byte];
size_t di;
char *ask;
if (!userid) {
belle_sip_error("belle_sip_fill_authorization_header, username not found ");
return -1;
}
if (!password) {
belle_sip_error("belle_sip_fill_authorization_header, password not found ");
return -1;
}
if (!realm) {
belle_sip_error("belle_sip_fill_authorization_header, password not found ");
return -1;
}
ask = bctbx_strdup_printf("%s:%s:%s", userid, realm, password);
belle_sip_auth_choose_method(algo, ask, out, length_byte);
for (di = 0; di < length_byte; ++di)
sprintf(ha1 + di * 2, "%02x", out[di]);
ha1[length_byte * 2] = '\0';
bctbx_free(ask);
return 0;
}
int belle_sip_auth_helper_compute_ha1(const char* userid,const char* realm,const char* password, char ha1[33]) {
belle_sip_auth_helper_compute_ha1_for_algorithm(userid,realm,password,ha1,33,"MD5");
return 0;
int belle_sip_auth_helper_compute_ha1(const char *userid, const char *realm, const char *password, char ha1[33]) {
belle_sip_auth_helper_compute_ha1_for_algorithm(userid, realm, password, ha1, 33, "MD5");
return 0;
}
int belle_sip_auth_helper_compute_ha2_for_algorithm(const char* method,const char* uri, char *ha2, size_t size, const char* algo) {
size_t compared_size;
compared_size = belle_sip_auth_define_size(algo);
if (compared_size!= size) {
belle_sip_error("belle_sip_fill_authorization_header, size of ha1 must be 33 when MD5 or 65 when SHA-256 ");
return -1;
}
size_t length_byte = (size-1)/2;
uint8_t out[length_byte];
size_t di;
char *ask;
ha2[length_byte*2]='\0';
int belle_sip_auth_helper_compute_ha2_for_algorithm(const char *method, const char *uri, char *ha2, size_t size, const char *algo) {
size_t compared_size;
compared_size = belle_sip_auth_define_size(algo);
if (compared_size != size) {
belle_sip_error("belle_sip_fill_authorization_header, size of ha1 must be 33 when MD5 or 65 when SHA-256 ");
return -1;
}
size_t length_byte = (size - 1) / 2;
uint8_t out[length_byte];
size_t di;
char *ask;
ha2[length_byte * 2] = '\0';
/*HA2=MD5(method:uri)*/
ask = bctbx_strdup_printf("%s:%s", method, uri);
belle_sip_auth_choose_method(algo, ask, out, length_byte);
ask = bctbx_strdup_printf("%s:%s", method, uri);
belle_sip_auth_choose_method(algo, ask, out, length_byte);
for (di = 0; di < length_byte; ++di)
sprintf(ha2 + di * 2, "%02x", out[di]);
bctbx_free(ask);
bctbx_free(ask);
return 0;
}
int belle_sip_auth_helper_compute_ha2(const char* method,const char* uri, char ha2[33]) {
belle_sip_auth_helper_compute_ha2_for_algorithm(method, uri, ha2, 33, "MD5");
return 0;
int belle_sip_auth_helper_compute_ha2(const char *method, const char *uri, char ha2[33]) {
belle_sip_auth_helper_compute_ha2_for_algorithm(method, uri, ha2, 33, "MD5");
return 0;
}
int belle_sip_auth_helper_compute_response_for_algorithm(const char* ha1,const char* nonce, const char* ha2, char *response, size_t size, const char* algo) {
size_t compared_size;
compared_size = belle_sip_auth_define_size(algo);
if (compared_size!= size) {
belle_sip_error("belle_sip_fill_authorization_header, size of ha1 must be 33 when MD5 or 65 when SHA-256 ");
return -1;
}
size_t length_byte = (size-1)/2;
uint8_t out[length_byte];
size_t di;
char *ask;
response[length_byte*2]='\0';
ask = bctbx_strdup_printf("%s:%s:%s", ha1, nonce, ha2);
belle_sip_auth_choose_method(algo, ask, out, length_byte);
int belle_sip_auth_helper_compute_response_for_algorithm(const char *ha1, const char *nonce, const char *ha2, char *response, size_t size, const char *algo) {
size_t compared_size;
compared_size = belle_sip_auth_define_size(algo);
if (compared_size != size) {
belle_sip_error("belle_sip_fill_authorization_header, size of ha1 must be 33 when MD5 or 65 when SHA-256 ");
return -1;
}
size_t length_byte = (size - 1) / 2;
uint8_t out[length_byte];
size_t di;
char *ask;
response[length_byte * 2] = '\0';
ask = bctbx_strdup_printf("%s:%s:%s", ha1, nonce, ha2);
belle_sip_auth_choose_method(algo, ask, out, length_byte);
/*copy values*/
for (di = 0; di < length_byte; ++di)
sprintf(response + di * 2, "%02x", out[di]);
bctbx_free(ask);
bctbx_free(ask);
return 0;
}
int belle_sip_auth_helper_compute_response(const char* ha1,const char* nonce, const char* ha2, char response[33]) {
belle_sip_auth_helper_compute_response_for_algorithm(ha1, nonce, ha2, response, 33, "MD5");
return 0;
int belle_sip_auth_helper_compute_response(const char *ha1, const char *nonce, const char *ha2, char response[33]) {
belle_sip_auth_helper_compute_response_for_algorithm(ha1, nonce, ha2, response, 33, "MD5");
return 0;
}
int belle_sip_auth_helper_compute_response_qop_auth_for_algorithm(const char* ha1
......@@ -195,29 +192,29 @@ int belle_sip_auth_helper_compute_response_qop_auth_for_algorithm(const char* ha
, const char* ha2
, char *response
, size_t size, const char* algo) {
size_t compared_size;
compared_size = belle_sip_auth_define_size(algo);
if (compared_size!= size) {
belle_sip_error("belle_sip_fill_authorization_header, size of ha1 must be 33 when MD5 or 65 when SHA-256 ");
return -1;
}
size_t length_byte = (size-1)/2;
uint8_t out[length_byte];
size_t di;
char *ask;
size_t compared_size;
compared_size = belle_sip_auth_define_size(algo);
if (compared_size != size) {
belle_sip_error("belle_sip_fill_authorization_header, size of ha1 must be 33 when MD5 or 65 when SHA-256 ");
return -1;
}
size_t length_byte = (size - 1) / 2;
uint8_t out[length_byte];
size_t di;
char *ask;
char nounce_count_as_string[9];
response[length_byte*2]='\0';
response[length_byte * 2] = '\0';
snprintf(nounce_count_as_string,sizeof(nounce_count_as_string),"%08x",nonce_count);
snprintf(nounce_count_as_string, sizeof(nounce_count_as_string), "%08x", nonce_count);
/*response=MD5(HA1:nonce:nonce_count:cnonce:qop:HA2)*/
ask = bctbx_strdup_printf("%s:%s:%s:%s:%s:%s", ha1, nonce, nounce_count_as_string, cnonce, qop, ha2);
belle_sip_auth_choose_method(algo, ask, out, length_byte);
ask = bctbx_strdup_printf("%s:%s:%s:%s:%s:%s", ha1, nonce, nounce_count_as_string, cnonce, qop, ha2);
belle_sip_auth_choose_method(algo, ask, out, length_byte);
/*copy values*/
for (di = 0; di < length_byte; ++di)
sprintf(response + di * 2, "%02x", out[di]);
bctbx_free(ask);
bctbx_free(ask);
return 0;
}
......@@ -227,20 +224,20 @@ int belle_sip_auth_helper_compute_response_qop_auth(const char* ha1
, const char* cnonce
, const char* qop
, const char* ha2, char response[33]) {
belle_sip_auth_helper_compute_response_qop_auth_for_algorithm(ha1, nonce, nonce_count, cnonce, qop, ha2, response, 33, "MD5");
return 0;
belle_sip_auth_helper_compute_response_qop_auth_for_algorithm(ha1, nonce, nonce_count, cnonce, qop, ha2, response, 33, "MD5");
return 0;
}
int belle_sip_auth_helper_fill_authorization(belle_sip_header_authorization_t* authorization
,const char* method
,const char* ha1) {
size_t size;
const char *algo = belle_sip_header_authorization_get_algorithm(authorization);
size = belle_sip_auth_define_size(algo);
if(!size) {
belle_sip_error("Algorithm [%s] is not correct ", algo);
return -1;
}
size_t size;
const char *algo = belle_sip_header_authorization_get_algorithm(authorization);
size = belle_sip_auth_define_size(algo);
if (!size) {
belle_sip_error("Algorithm [%s] is not correct ", algo);
return -1;
}
int auth_mode=0;
char* uri;
......
......@@ -977,7 +977,7 @@ struct belle_sip_auth_event {
char* distinguished_name;
belle_sip_certificates_chain_t * cert;
belle_sip_signing_key_t* key;
char* algorithm; /* either MD5 ot SHA256*/
char* algorithm; /* either MD5 ot SHA256*/
};
belle_sip_auth_event_t* belle_sip_auth_event_create(belle_sip_object_t *source, const char* realm,const belle_sip_uri_t * from_uri);
......
......@@ -1595,11 +1595,11 @@ void belle_sip_channel_check_dns_reusability(belle_sip_channel_t *obj) {
#ifdef __ANDROID__
unsigned long belle_sip_begin_background_task(const char *name, belle_sip_background_task_end_callback_t cb, void *data){
return wake_lock_acquire(name);
return wake_lock_acquire(name);
}
void belle_sip_end_background_task(unsigned long id){
wake_lock_release(id);
wake_lock_release(id);
}
#elif !TARGET_OS_IPHONE && !defined(__APPLE__)
......
......@@ -4943,22 +4943,22 @@ int dns_resconf_loadwin(struct dns_resolv_conf *resconf) {
FIXED_INFO *pFixedInfo;
ULONG ulOutBufLen;
DWORD dwRetVal;
IP_ADDR_STRING *pIPAddr;
IP_ADDR_STRING *pIPAddr;
unsigned sa_count = 0;
int error;
pFixedInfo = (FIXED_INFO *) malloc(sizeof(FIXED_INFO));
if (pFixedInfo == NULL) {
return -1;
}
ulOutBufLen = sizeof(FIXED_INFO);
if (pFixedInfo == NULL) {
return -1;
}
ulOutBufLen = sizeof(FIXED_INFO);
if (GetNetworkParams(pFixedInfo, &ulOutBufLen) == ERROR_BUFFER_OVERFLOW) {
free(pFixedInfo);
pFixedInfo = (FIXED_INFO *) malloc(ulOutBufLen);
if (pFixedInfo == NULL) {
return -1;
}
}
free(pFixedInfo);
pFixedInfo = (FIXED_INFO *) malloc(ulOutBufLen);
if (pFixedInfo == NULL) {
return -1;
}
}
if ((dwRetVal = GetNetworkParams(pFixedInfo, &ulOutBufLen)) == NO_ERROR) {
memset(resconf->search, '\0', sizeof resconf->search);
......
......@@ -129,253 +129,249 @@
static void
md5_process(md5_state_t *pms, const md5_byte_t *data /*[64]*/)
{
md5_word_t
md5_process(md5_state_t *pms, const md5_byte_t *data /*[64]*/) {
md5_word_t
a = pms->abcd[0], b = pms->abcd[1],
c = pms->abcd[2], d = pms->abcd[3];
md5_word_t t;
md5_word_t t;
#if BYTE_ORDER > 0
/* Define storage only for big-endian CPUs. */
md5_word_t X[16];
/* Define storage only for big-endian CPUs. */
md5_word_t X[16];
#else
/* Define storage for little-endian or both types of CPUs. */
md5_word_t xbuf[16];
const md5_word_t *X;
/* Define storage for little-endian or both types of CPUs. */
md5_word_t xbuf[16];
const md5_word_t *X;
#endif
{
{
#if BYTE_ORDER == 0
/*
* Determine dynamically whether this is a big-endian or
* little-endian machine, since we can use a more efficient
* algorithm on the latter.
*/
static const int w = 1;
if (*((const md5_byte_t *)&w)) /* dynamic little-endian */
/*
* Determine dynamically whether this is a big-endian or
* little-endian machine, since we can use a more efficient
* algorithm on the latter.
*/
static const int w = 1;
if (*((const md5_byte_t *)&w)) /* dynamic little-endian */
#endif
#if BYTE_ORDER <= 0 /* little-endian */
{
/*
* On little-endian machines, we can process properly aligned
* data without copying it.
*/
if (!((data - (const md5_byte_t *)0) & 3)) {
/* data are properly aligned */
X = (const md5_word_t *)data;
} else {
/* not aligned */
memcpy(xbuf, data, 64);
X = xbuf;
}
}
{
/*
* On little-endian machines, we can process properly aligned
* data without copying it.
*/
if (!((data - (const md5_byte_t *)0) & 3)) {
/* data are properly aligned */
X = (const md5_word_t *)data;
} else {
/* not aligned */
memcpy(xbuf, data, 64);
X = xbuf;
}
}
#endif
#if BYTE_ORDER == 0
else /* dynamic big-endian */
else /* dynamic big-endian */
#endif
#if BYTE_ORDER >= 0 /* big-endian */
{
/*
* On big-endian machines, we must arrange the bytes in the
* right order.
*/
const md5_byte_t *xp = data;
int i;
{
/*
* On big-endian machines, we must arrange the bytes in the
* right order.
*/
const md5_byte_t *xp = data;
int i;
# if BYTE_ORDER == 0
X = xbuf; /* (dynamic only) */
X = xbuf; /* (dynamic only) */
# else
# define xbuf X /* (static only) */
# endif
for (i = 0; i < 16; ++i, xp += 4)
xbuf[i] = xp[0] + (xp[1] << 8) + (xp[2] << 16) + (xp[3] << 24);
}
for (i = 0; i < 16; ++i, xp += 4)
xbuf[i] = xp[0] + (xp[1] << 8) + (xp[2] << 16) + (xp[3] << 24);
}
#endif
}
}
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32 - (n))))
/* Round 1. */
/* Let [abcd k s i] denote the operation
a = b + ((a + F(b,c,d) + X[k] + T[i]) <<< s). */
/* Round 1. */
/* Let [abcd k s i] denote the operation
a = b + ((a + F(b,c,d) + X[k] + T[i]) <<< s). */
#define F(x, y, z) (((x) & (y)) | (~(x) & (z)))
#define SET(a, b, c, d, k, s, Ti)\
t = a + F(b,c,d) + X[k] + Ti;\
a = ROTATE_LEFT(t, s) + b
/* Do the following 16 operations. */
SET(a, b, c, d, 0, 7, T1);
SET(d, a, b, c, 1, 12, T2);
SET(c, d, a, b, 2, 17, T3);
SET(b, c, d, a, 3, 22, T4);
SET(a, b, c, d, 4, 7, T5);
SET(d, a, b, c, 5, 12, T6);
SET(c, d, a, b, 6, 17, T7);
SET(b, c, d, a, 7, 22, T8);
SET(a, b, c, d, 8, 7, T9);
SET(d, a, b, c, 9, 12, T10);
SET(c, d, a, b, 10, 17, T11);
SET(b, c, d, a, 11, 22, T12);
SET(a, b, c, d, 12, 7, T13);
SET(d, a, b, c, 13, 12, T14);
SET(c, d, a, b, 14, 17, T15);
SET(b, c, d, a, 15, 22, T16);
t = a + F(b,c,d) + X[k] + Ti;\
a = ROTATE_LEFT(t, s) + b
/* Do the following 16 operations. */
SET(a, b, c, d, 0, 7, T1);
SET(d, a, b, c, 1, 12, T2);
SET(c, d, a, b, 2, 17, T3);
SET(b, c, d, a, 3, 22, T4);
SET(a, b, c, d, 4, 7, T5);
SET(d, a, b, c, 5, 12, T6);
SET(c, d, a, b, 6, 17, T7);
SET(b, c, d, a, 7, 22, T8);
SET(a, b, c, d, 8, 7, T9);
SET(d, a, b, c, 9, 12, T10);
SET(c, d, a, b, 10, 17, T11);
SET(b, c, d, a, 11, 22, T12);
SET(a, b, c, d, 12, 7, T13);
SET(d, a, b, c, 13, 12, T14);
SET(c, d, a, b, 14, 17, T15);
SET(b, c, d, a, 15, 22, T16);
#undef SET
/* Round 2. */
/* Let [abcd k s i] denote the operation
a = b + ((a + G(b,c,d) + X[k] + T[i]) <<< s). */
/* Round 2. */
/* Let [abcd k s i] denote the operation
a = b + ((a + G(b,c,d) + X[k] + T[i]) <<< s). */
#define G(x, y, z) (((x) & (z)) | ((y) & ~(z)))
#define SET(a, b, c, d, k, s, Ti)\
t = a + G(b,c,d) + X[k] + Ti;\
a = ROTATE_LEFT(t, s) + b
/* Do the following 16 operations. */
SET(a, b, c, d, 1, 5, T17);
SET(d, a, b, c, 6, 9, T18);
SET(c, d, a, b, 11, 14, T19);
SET(b, c, d, a, 0, 20, T20);
SET(a, b, c, d, 5, 5, T21);
SET(d, a, b, c, 10, 9, T22);
SET(c, d, a, b, 15, 14, T23);
SET(b, c, d, a, 4, 20, T24);
SET(a, b, c, d, 9, 5, T25);
SET(d, a, b, c, 14, 9, T26);
SET(c, d, a, b, 3, 14, T27);
SET(b, c, d, a, 8, 20, T28);
SET(a, b, c, d, 13, 5, T29);
SET(d, a, b, c, 2, 9, T30);