Commit 93914c45 authored by jehan's avatar jehan
Browse files

add enhancement to autho header

parent 42af7fa7
......@@ -256,7 +256,7 @@ void belle_sip_header_content_length_set_content_length(belle_sip_header_content
******************************/
typedef struct _belle_sip_header_authorization belle_sip_header_authorization_t;
belle_sip_header_authorization_t* belle_sip_header_authorization_authorization();
belle_sip_header_authorization_t* belle_sip_header_authorization_new();
belle_sip_header_authorization_t* belle_sip_header_authorization_parse(const char* authorization);
const char* belle_sip_header_authorization_get_algorithm(const belle_sip_header_authorization_t* authorization );
const char* belle_sip_header_authorization_get_cnonce(const belle_sip_header_authorization_t* authorization );
......
......@@ -394,20 +394,51 @@ GET_SET_STRING(belle_sip_header_extension,value);
struct _belle_sip_header_authorization {
belle_sip_header_t header;
const char* username;
const char* realm;
const char* nonce;
belle_sip_uri_t* uri;
const char* dresponse;
const char* algorithm;
};
static void belle_sip_header_authorization_destroy(belle_sip_header_authorization_t* authorization) {
if (authorization->username) belle_sip_free((void*)authorization->username);
if (authorization->realm) belle_sip_free((void*)authorization->realm);
if (authorization->nonce) belle_sip_free((void*)authorization->nonce);
if (authorization->uri) {
belle_sip_object_unref(BELLE_SIP_OBJECT(authorization->uri));
}
if (authorization->algorithm) belle_sip_free((void*)authorization->algorithm);
}
static void belle_sip_header_authorization_clone(belle_sip_header_authorization_t* authorization,
const belle_sip_header_authorization_t *orig ) {
}
belle_sip_uri_t* belle_sip_header_authorization_get_uri(const belle_sip_header_authorization_t* authorization) {
return authorization->uri;
}
void belle_sip_header_authorization_set_uri(belle_sip_header_authorization_t* authorization, belle_sip_uri_t* uri) {
if (authorization->uri) {
belle_sip_object_unref(BELLE_SIP_OBJECT(authorization->uri));
}
authorization->uri=uri;
if (authorization->uri) belle_sip_object_ref(authorization->uri);
}
BELLE_SIP_NEW_HEADER(header_authorization,header,"Authorization")
BELLE_SIP_PARSE(header_authorization)
GET_SET_STRING(belle_sip_header_authorization,username);
GET_SET_STRING(belle_sip_header_authorization,realm);
GET_SET_STRING(belle_sip_header_authorization,nonce);
GET_SET_STRING(belle_sip_header_authorization,dresponse);
const char* belle_sip_header_authorization_get_response(const belle_sip_header_authorization_t* authorization) {
return belle_sip_header_authorization_get_dresponse(authorization);
}
void belle_sip_header_authorization_set_response(belle_sip_header_authorization_t* authorization, const char* response) {
belle_sip_header_authorization_set_dresponse(authorization,response);
}
GET_SET_STRING(belle_sip_header_authorization,algorithm);
......@@ -226,27 +226,44 @@ credentials
digest_response
: dig_resp (comma dig_resp)*;
dig_resp
: username
/*| realm | nonce | digest_uri
| dresponse | algorithm | cnonce
: username { belle_sip_header_authorization_set_username($header_authorization::current,$username.ret);
belle_sip_free($username.ret);
}
| realm { belle_sip_header_authorization_set_realm($header_authorization::current,$realm.ret);
belle_sip_free($realm.ret);
}
| nonce { belle_sip_header_authorization_set_nonce($header_authorization::current,$nonce.ret);
belle_sip_free($nonce.ret);
}
| digest_uri
| dresponse { belle_sip_header_authorization_set_response($header_authorization::current,$dresponse.ret);
belle_sip_free($dresponse.ret);
}
/*| algorithm {
belle_sip_header_authorization_set_algoritm($header_authorization::current,$algorithm.ret);
}
| cnonce
| opaque | message_qop
| nonce_count | auth_param*/;
| nonce_count | auth_param*/ | (token equal (quoted_string |token)) ;
username_token: {IS_TOKEN(username)}? token;
username
username returns [char* ret]
: username_token /*'username'*/ equal username_value {
char* unquoted_string = _belle_sip_str_dup_and_unquote_string($username_value.text->chars);
belle_sip_header_authorization_set_username($header_authorization::current,(const char*)unquoted_string);
belle_sip_free(unquoted_string);} ;
$ret = _belle_sip_str_dup_and_unquote_string($username_value.text->chars);
};
username_value : quoted_string;
uri_token: {IS_TOKEN(uri)}? token;
digest_uri
: uri_token /*'uri'*/ equal LDQUOT digest_uri_value RDQUOT;
: uri_token /*'uri'*/ equal DQUOTE uri DQUOTE
{belle_sip_header_authorization_set_uri($header_authorization::current,$uri.ret);
belle_sip_object_unref(BELLE_SIP_OBJECT($uri.ret));
};
/*
digest_uri_value : rquest_uri ;
rquest_uri
: uri;
*/
// Equal to request-uri as specified by HTTP/1.1
message_qop
: {IS_TOKEN(qop)}? token/*'qop'*/ equal qop_value;
......@@ -262,11 +279,13 @@ nonce_count
: {IS_TOKEN(nc)}? token /*'nc'*/ equal nc_value;
nc_value
: huit_lhex;
dresponse
: {IS_TOKEN(response)}? token /*'response'*/ equal request_digest;
dresponse returns [char* ret]
: {IS_TOKEN(response)}? token /*'response'*/ equal request_digest{
$ret = _belle_sip_str_dup_and_unquote_string($request_digest.text->chars);
};
request_digest
: sp_laquot_sp huit_lhex huit_lhex huit_lhex huit_lhex sp_raquot_sp;
: quoted_string ;/*sp_laquot_sp huit_lhex huit_lhex huit_lhex huit_lhex sp_raquot_sp;
*/
huit_lhex
: hexdigit+;
......@@ -520,25 +539,35 @@ digest_cln
: realm | domain | nonce
| opaque | stale | algorithm
| qop_options | auth_param;
realm
: 'realm' EQUAL realm_value;
*/
realm returns [char* ret]
: {IS_TOKEN(realm)}? token /*'realm'*/ equal realm_value {
$ret = _belle_sip_str_dup_and_unquote_string($realm_value.text->chars);
};
realm_value
: quoted_string;
: quoted_string ;
/*
domain
: 'domain' EQUAL LDQUOT uri
( SP+ uri )* RDQUOT;
uri
: absoluteURI | '/'.;
nonce
: 'nonce' EQUAL nonce_value;
*/
nonce returns [char* ret]
: {IS_TOKEN(nonce)}? token /*'nonce'*/ equal nonce_value{
$ret = _belle_sip_str_dup_and_unquote_string($nonce_value.text->chars);
};
/*
opaque
: 'opaque' EQUAL quoted_string;
stale
: 'stale' EQUAL ( 'true' | 'false' );
algorithm
: 'algorithm' EQUAL ( 'MD5' | 'MD5-sess'
| token );
algorithm returns [const char* ret]
: {IS_TOKEN(algorithm)}? token 'algorithm' equal ( 'MD5' | 'MD5-sess'
| token {$ret=$token.text->chars;})
;
qop_options
: 'qop' EQUAL LDQUOT qop_value
(',' qop_value)* RDQUOT:
......
......@@ -164,6 +164,10 @@ void test_header_authorization(void) {
belle_sip_header_authorization_t* L_authorization = belle_sip_header_authorization_parse(l_raw_header);
CU_ASSERT_PTR_NOT_NULL(L_authorization);
CU_ASSERT_STRING_EQUAL(belle_sip_header_authorization_get_username(L_authorization), "0033482532176");
CU_ASSERT_STRING_EQUAL(belle_sip_header_authorization_get_realm(L_authorization), "sip.ovh.net");
CU_ASSERT_STRING_EQUAL(belle_sip_header_authorization_get_nonce(L_authorization), "1bcdcb194b30df5f43973d4c69bdf54f");
CU_ASSERT_PTR_NOT_NULL(belle_sip_header_authorization_get_uri(L_authorization));
CU_ASSERT_STRING_EQUAL(belle_sip_header_authorization_get_response(L_authorization), "eb36c8d5c8642c1c5f44ec3404613c81");
belle_sip_object_unref(BELLE_SIP_OBJECT(L_authorization));
}
......
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