Commit 9bb0174d authored by jehan's avatar jehan

add header Authentication-Info

parent bff19b27
......@@ -771,6 +771,34 @@ BELLESIP_EXPORT const char* belle_sip_header_reason_get_text(const belle_sip_hea
#define BELLE_SIP_REASON "Reason"
/******************************
* AuthenticationInfo header inherit from header
*
******************************/
typedef struct _belle_sip_header_authentication_info belle_sip_header_authentication_info_t;
BELLESIP_EXPORT belle_sip_header_authentication_info_t* belle_sip_header_authentication_info_new(void);
BELLESIP_EXPORT belle_sip_header_authentication_info_t* belle_sip_header_authentication_info_parse(const char* authentication_info );
BELLESIP_EXPORT const char* belle_sip_header_authentication_info_get_next_nonce(const belle_sip_header_authentication_info_t* authentication_info );
BELLESIP_EXPORT void belle_sip_header_authentication_info_set_next_nonce(belle_sip_header_authentication_info_t* authentication_info, const char* next_nonce);
/*limited to a sinle value*/
BELLESIP_EXPORT const char* belle_sip_header_authentication_info_get_qop(const belle_sip_header_authentication_info_t* authentication_info);
BELLESIP_EXPORT void belle_sip_header_authentication_info_set_qop(belle_sip_header_authentication_info_t* authentication_info, const char* qop);
BELLESIP_EXPORT const char* belle_sip_header_authentication_info_get_rsp_auth(const belle_sip_header_authentication_info_t* rsp_auth);
BELLESIP_EXPORT void belle_sip_header_authentication_info_set_rsp_auth(belle_sip_header_authentication_info_t* authentication_info, const char* rsp_auth);
BELLESIP_EXPORT const char* belle_sip_header_authentication_info_get_cnonce(const belle_sip_header_authentication_info_t* authentication_info);
BELLESIP_EXPORT void belle_sip_header_authentication_info_set_cnonce(belle_sip_header_authentication_info_t* authentication_info, const char* cNonce);
BELLESIP_EXPORT void belle_sip_header_authentication_info_set_nonce_count(belle_sip_header_authentication_info_t* authentication_info, int nonceCount);
BELLESIP_EXPORT int belle_sip_header_authentication_info_get_nonce_count(const belle_sip_header_authentication_info_t* authentication_info);
#define BELLE_SIP_HEADER_AUTHENTICATION_INFO(t) BELLE_SIP_CAST(t,belle_sip_header_authentication_info_t)
#define BELLE_SIP_AUTHENTICATION_INFO "Authentication-Info"
BELLE_SIP_END_DECLS
......
......@@ -144,7 +144,8 @@ BELLE_SIP_DECLARE_TYPES_BEGIN(belle_sip,1)
BELLE_SIP_TYPE_ID(belle_sip_header_supported_t),
BELLE_SIP_TYPE_ID(belle_sip_header_content_disposition_t),
BELLE_SIP_TYPE_ID(belle_sip_header_accept_t),
BELLE_SIP_TYPE_ID(belle_sip_header_reason_t)
BELLE_SIP_TYPE_ID(belle_sip_header_reason_t),
BELLE_SIP_TYPE_ID(belle_sip_header_authentication_info_t)
BELLE_SIP_DECLARE_TYPES_END
......
......@@ -84,6 +84,8 @@ static struct header_name_func_pair header_table[] = {
,{PROTO_SIP, BELLE_SIP_CONTENT_DISPOSITION, (header_parse_func)belle_sip_header_content_disposition_parse}
,{PROTO_SIP, BELLE_SIP_ACCEPT, (header_parse_func)belle_sip_header_accept_parse}
,{PROTO_SIP, BELLE_SIP_REASON, (header_parse_func)belle_sip_header_reason_parse}
,{PROTO_SIP, BELLE_SIP_AUTHENTICATION_INFO, (header_parse_func)belle_sip_header_authentication_info_parse}
,{PROTO_HTTP, "AuthenticationInfo", (header_parse_func)belle_sip_header_authentication_info_parse}
};
static belle_sip_header_t* belle_header_create(const char* name,const char* value,int protocol) {
......@@ -2050,7 +2052,6 @@ belle_sip_error_code belle_sip_header_reason_marshal(belle_sip_header_reason_t*
if (error!=BELLE_SIP_OK) return error;
if (reason->unquoted_text)
error=belle_sip_snprintf(buff,buff_size,offset,"; text=\"%s\"",reason->unquoted_text);
if (error!=BELLE_SIP_OK) return error;
return error;
}
......@@ -2080,3 +2081,79 @@ GET_SET_STRING_PARAM(belle_sip_header_reason,protocol);
GET_SET_INT_PARAM(belle_sip_header_reason,cause,int);
BELLE_SIP_PARSE(header_reason)
BELLE_SIP_NEW_HEADER(header_reason,parameters,BELLE_SIP_REASON)
/******************************
* AuthenticationInfo header hinerite from header
*
******************************/
struct _belle_sip_header_authentication_info {
belle_sip_header_t header;
const char* rsp_auth;
const char* cnonce;
int nonce_count;
const char* qop;
const char* next_nonce;
};
static void belle_sip_header_authentication_info_destroy(belle_sip_header_authentication_info_t* authentication_info) {
DESTROY_STRING(authentication_info,rsp_auth);
DESTROY_STRING(authentication_info,cnonce);
DESTROY_STRING(authentication_info,qop);
DESTROY_STRING(authentication_info,next_nonce);
}
static void belle_sip_header_authentication_info_clone( belle_sip_header_authentication_info_t* authentication_info
, const belle_sip_header_authentication_info_t* orig){
CLONE_STRING(belle_sip_header_authentication_info,rsp_auth,authentication_info,orig)
CLONE_STRING(belle_sip_header_authentication_info,cnonce,authentication_info,orig)
CLONE_STRING(belle_sip_header_authentication_info,qop,authentication_info,orig)
CLONE_STRING(belle_sip_header_authentication_info,next_nonce,authentication_info,orig)
}
belle_sip_error_code belle_sip_header_authentication_info_marshal(belle_sip_header_authentication_info_t* authentication_info, char* buff, size_t buff_size, size_t *offset) {
char* border=" ";
belle_sip_error_code error=belle_sip_header_marshal(BELLE_SIP_HEADER(authentication_info), buff, buff_size, offset);
if (error!=BELLE_SIP_OK) return error;
if (authentication_info->rsp_auth) {
error=belle_sip_snprintf(buff,buff_size,offset,"%srspauth=\"%s\"", border,authentication_info->rsp_auth);
border=", ";
}
if (error!=BELLE_SIP_OK) return error;
if (authentication_info->cnonce) {
error=belle_sip_snprintf(buff,buff_size,offset,"%scnonce=\"%s\"", border, authentication_info->cnonce);
border=", ";
}
if (error!=BELLE_SIP_OK) return error;
if (authentication_info->nonce_count >= 0) {
error=belle_sip_snprintf(buff,buff_size,offset,"%snc=%08x", border, authentication_info->nonce_count);
border=", ";
}
if (error!=BELLE_SIP_OK) return error;
if (authentication_info->qop) {
error=belle_sip_snprintf(buff,buff_size,offset,"%sqop=\"%s\"", border, authentication_info->qop);
border=", ";
}
if (error!=BELLE_SIP_OK) return error;
if (authentication_info->next_nonce) {
error=belle_sip_snprintf(buff,buff_size,offset,"%snextnonce=\"%s\"", border, authentication_info->next_nonce);
}
return error;
}
void belle_sip_header_authentication_info_init(belle_sip_header_authentication_info_t* header_authentication) {
header_authentication->nonce_count=-1;
}
BELLE_SIP_NEW_HEADER_INIT(header_authentication_info,header,BELLE_SIP_AUTHENTICATION_INFO,header_authentication_info)
BELLE_SIP_PARSE(header_authentication_info)
GET_SET_STRING(belle_sip_header_authentication_info,rsp_auth);
GET_SET_STRING(belle_sip_header_authentication_info,qop);
GET_SET_STRING(belle_sip_header_authentication_info,next_nonce);
GET_SET_STRING(belle_sip_header_authentication_info,cnonce);
GET_SET_INT(belle_sip_header_authentication_info,nonce_count,int);
......@@ -213,6 +213,8 @@ BELLE_SIP_DECLARE_VPTR(belle_sip_header_supported_t);
BELLE_SIP_DECLARE_VPTR(belle_sip_header_content_disposition_t);
BELLE_SIP_DECLARE_VPTR(belle_sip_header_accept_t);
BELLE_SIP_DECLARE_VPTR(belle_sip_header_reason_t);
BELLE_SIP_DECLARE_VPTR(belle_sip_header_authentication_info_t);
BELLE_SIP_DECLARE_CUSTOM_VPTR_BEGIN(belle_sip_resolver_context_t,belle_sip_source_t)
void (*cancel)(belle_sip_resolver_context_t *);
......
......@@ -1548,6 +1548,64 @@ scope { belle_sip_header_reason_t* prev;}
header_reason_protocol
: token;
//*********************************************//
/*
AuthenticationInfo = "Authentication-Info" ":" auth-info
auth-info = 1#(nextnonce | [ message-qop ]
| [ response-auth ] | [ cnonce ]
| [nonce-count] )
nextnonce = "nextnonce" "=" nonce-value
response-auth = "rspauth" "=" response-digest
response-digest = <"> *LHEX <">
*/
header_authentication_info returns [belle_sip_header_authentication_info_t* ret=NULL]
scope { belle_sip_header_authentication_info_t* current; }
@init {$header_authentication_info::current = belle_sip_header_authentication_info_new(); $ret=$header_authentication_info::current; }
: {IS_TOKEN( Authentication-Info)}? token /*' Authentication-Info'*/ hcolon auth_info ( comma auth_info)*;
catch [ANTLR3_RECOGNITION_EXCEPTION]
{
belle_sip_message("[\%s] reason [\%s]",(const char*)EXCEPTION->name,(const char*)EXCEPTION->message);
belle_sip_object_unref($header_authentication_info::current);
$ret=NULL;
}
auth_info
:
( next_nonce { belle_sip_header_authentication_info_set_next_nonce($header_authentication_info::current,(char*)$next_nonce.ret);
belle_sip_free($next_nonce.ret);
}
|cnonce{
belle_sip_header_authentication_info_set_cnonce($header_authentication_info::current,(char*)$cnonce.ret);
belle_sip_free($cnonce.ret);
}
| authentication_info_message_qop{
belle_sip_header_authentication_info_set_qop($header_authentication_info::current,$authentication_info_message_qop.ret);
}
|nonce_count{
belle_sip_header_authentication_info_set_nonce_count($header_authentication_info::current,atoi((char*)$nonce_count.ret));
}
|rspauth {
belle_sip_header_authentication_info_set_rsp_auth($header_authentication_info::current,$rspauth.ret);
belle_sip_free($rspauth.ret);
}) ;
authentication_info_message_qop returns [const char* ret=NULL]
: {IS_TOKEN(qop)}? token/*'qop'*/ equal quoted_string { $ret = _belle_sip_str_dup_and_unquote_string((char*)$quoted_string.text->chars);};
rspauth returns [char* ret=NULL]
: {IS_TOKEN(rspauth)}? token /*'nonce'*/ equal quoted_string{
$ret = _belle_sip_str_dup_and_unquote_string((char*)$quoted_string.text->chars);
};
next_nonce returns [char* ret=NULL]
: {IS_TOKEN(nextnonce)}? token /*'nonce'*/ equal nonce_value{
$ret = _belle_sip_str_dup_and_unquote_string((char*)$nonce_value.text->chars);
};
quoted_algorithm returns [char* ret=NULL]
: {IS_TOKEN(nextnonce)}? token /*'nonce'*/ equal nonce_value{
$ret = _belle_sip_str_dup_and_unquote_string((char*)$nonce_value.text->chars);
};
//**********************************************//
header returns [belle_sip_header_t* ret=NULL]
: header_extension_base[FALSE] {$ret=$header_extension_base.ret;};
......
......@@ -1160,6 +1160,29 @@ static void test_reason_header(void) {
BC_ASSERT_PTR_NULL(belle_sip_header_reason_parse("nimportequoi"));
}
static void test_authentication_info_header(void) {
belle_sip_header_authentication_info_t *L_tmp;
belle_sip_header_authentication_info_t* L_authentication_info = BELLE_SIP_HEADER_AUTHENTICATION_INFO(belle_sip_header_create("Authentication-Info"
, "nextnonce=\"47364c23432d2e131a5fb210812c\""
", qop=\"auth\""));
BC_ASSERT_STRING_EQUAL(belle_sip_header_authentication_info_get_next_nonce(L_authentication_info),"47364c23432d2e131a5fb210812c");
belle_sip_header_authentication_info_set_next_nonce(L_authentication_info, "31a5fb210812c47364c23432d2e1");
char* l_raw_header = belle_sip_object_to_string(BELLE_SIP_OBJECT(L_authentication_info));
belle_sip_object_unref(BELLE_SIP_OBJECT(L_authentication_info));
L_tmp = belle_sip_header_authentication_info_parse(l_raw_header);
L_authentication_info = BELLE_SIP_HEADER_AUTHENTICATION_INFO(belle_sip_object_clone(BELLE_SIP_OBJECT(L_tmp)));
belle_sip_object_unref(BELLE_SIP_OBJECT(L_tmp));
BC_ASSERT_STRING_EQUAL(belle_sip_header_authentication_info_get_next_nonce(L_authentication_info),"31a5fb210812c47364c23432d2e1");
BC_ASSERT_STRING_EQUAL(belle_sip_header_authentication_info_get_qop(L_authentication_info),"auth");
belle_sip_object_unref(BELLE_SIP_OBJECT(L_authentication_info));
belle_sip_free(l_raw_header);
BC_ASSERT_PTR_NULL(belle_sip_header_authentication_info_parse("nimportequoi"));
}
test_t headers_tests[] = {
TEST_NO_TAG("Address", test_address_header),
TEST_NO_TAG("Address tel uri", test_address_header_with_tel_uri),
......@@ -1202,7 +1225,8 @@ test_t headers_tests[] = {
TEST_NO_TAG("Header Supported", test_supported_header),
TEST_NO_TAG("Header Content-Disposition", test_content_disposition_header),
TEST_NO_TAG("Header Accept", test_accept_header),
TEST_NO_TAG("Header Reason", test_reason_header)
TEST_NO_TAG("Header Reason", test_reason_header),
TEST_NO_TAG("Header Authentication-Info", test_authentication_info_header)
};
test_suite_t headers_test_suite = {"Headers", NULL, NULL, belle_sip_tester_before_each, belle_sip_tester_after_each,
......
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