Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
BC
public
belle-sip
Commits
3d0603af
Commit
3d0603af
authored
Apr 27, 2011
by
jehan
Browse files
add header www-authenticate
parent
2d3494d3
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
160 additions
and
58 deletions
+160
-58
include/belle-sip/belle-sip.h
include/belle-sip/belle-sip.h
+1
-0
include/belle-sip/headers.h
include/belle-sip/headers.h
+26
-0
src/belle_sip_headers_impl.c
src/belle_sip_headers_impl.c
+52
-26
src/belle_sip_message.g
src/belle_sip_message.g
+59
-31
tester/belle_sip_headers_tester.c
tester/belle_sip_headers_tester.c
+22
-1
No files found.
include/belle-sip/belle-sip.h
View file @
3d0603af
...
...
@@ -66,6 +66,7 @@ typedef enum belle_sip_type_id{
BELLE_SIP_TYPE_ID
(
belle_sip_header_t
),
BELLE_SIP_TYPE_ID
(
belle_sip_header_extension_t
),
BELLE_SIP_TYPE_ID
(
belle_sip_header_authorization_t
),
BELLE_SIP_TYPE_ID
(
belle_sip_header_www_authenticate_t
),
BELLE_SIP_TYPE_ID
(
belle_sip_header_proxy_authorization_t
),
belle_sip_type_id_end
}
belle_sip_type_id_t
;
...
...
include/belle-sip/headers.h
View file @
3d0603af
...
...
@@ -291,6 +291,32 @@ belle_sip_header_proxy_authorization_t* belle_sip_header_proxy_authorization_new
belle_sip_header_proxy_authorization_t
*
belle_sip_header_proxy_authorization_parse
(
const
char
*
proxy_authorization
);
#define BELLE_SIP_HEADER_PROXY_AUTHORIZATION(t) BELLE_SIP_CAST(t,belle_sip_header_proxy_authorization_t)
/*******************************
* www_authenticate inherit from parameters
*/
typedef
struct
_belle_sip_header_www_authenticate
belle_sip_header_www_authenticate_t
;
belle_sip_header_www_authenticate_t
*
belle_sip_header_www_authenticate_new
();
belle_sip_header_www_authenticate_t
*
belle_sip_header_www_authenticate_parse
(
const
char
*
www_authenticate
);
const
char
*
belle_sip_header_www_authenticate_get_algorithm
(
const
belle_sip_header_www_authenticate_t
*
www_authenticate
);
const
char
*
belle_sip_header_www_authenticate_get_nonce
(
const
belle_sip_header_www_authenticate_t
*
www_authenticate
);
const
char
*
belle_sip_header_www_authenticate_get_opaque
(
const
belle_sip_header_www_authenticate_t
*
www_authenticate
);
const
char
*
belle_sip_header_www_authenticate_get_qop
(
const
belle_sip_header_www_authenticate_t
*
www_authetication
);
const
char
*
belle_sip_header_www_authenticate_get_realm
(
const
belle_sip_header_www_authenticate_t
*
www_authenticate
);
const
char
*
belle_sip_header_www_authenticate_get_scheme
(
const
belle_sip_header_www_authenticate_t
*
www_authenticate
);
const
char
*
belle_sip_header_www_authenticate_get_domain
(
const
belle_sip_header_www_authenticate_t
*
www_authenticate
);
unsigned
int
belle_sip_header_www_authenticate_is_stale
(
const
belle_sip_header_www_authenticate_t
*
www_authenticate
);
void
belle_sip_header_www_authenticate_set_algorithm
(
belle_sip_header_www_authenticate_t
*
www_authenticate
,
const
char
*
algorithm
);
void
belle_sip_header_www_authenticate_set_nonce
(
belle_sip_header_www_authenticate_t
*
www_authenticate
,
const
char
*
nonce
);
void
belle_sip_header_www_authenticate_set_opaque
(
belle_sip_header_www_authenticate_t
*
www_authenticate
,
const
char
*
opaque
);
void
belle_sip_header_www_authenticate_set_qop
(
belle_sip_header_www_authenticate_t
*
www_authentication
,
const
char
*
qop
);
void
belle_sip_header_www_authenticate_set_realm
(
belle_sip_header_www_authenticate_t
*
www_authenticate
,
const
char
*
realm
);
void
belle_sip_header_www_authenticate_set_scheme
(
belle_sip_header_www_authenticate_t
*
www_authenticate
,
const
char
*
scheme
);
void
belle_sip_header_www_authenticate_set_domain
(
belle_sip_header_www_authenticate_t
*
www_authenticate
,
const
char
*
domain
);
void
belle_sip_header_www_authenticate_set_stale
(
belle_sip_header_www_authenticate_t
*
www_authenticate
,
unsigned
int
enable
);
#define BELLE_SIP_HEADER_WWW_AUTHENTICATE(t) BELLE_SIP_CAST(t,belle_sip_header_www_authenticate_t)
/******************************
*
* Extension header inherit from header
...
...
src/belle_sip_headers_impl.c
View file @
3d0603af
...
...
@@ -391,17 +391,31 @@ GET_SET_STRING(belle_sip_header_extension,value);
*Authorization header object inherent from parameters
****************************
*/
#define AUTH_BASE \
belle_sip_parameters_t params_list; \
const char* scheme; \
const char* realm; \
const char* nonce; \
const char* algorithm; \
const char* opaque; \
const char* qop; \
#define AUTH_BASE_DESTROY(obj) \
if (obj->scheme) belle_sip_free((void*)obj->scheme);\
if (obj->realm) belle_sip_free((void*)obj->realm);\
if (obj->nonce) belle_sip_free((void*)obj->nonce);\
if (obj->algorithm) belle_sip_free((void*)obj->algorithm);\
if (obj->opaque) belle_sip_free((void*)obj->opaque);\
if (obj->qop) belle_sip_free((void*)obj->qop);\
struct
_belle_sip_header_authorization
{
belle_sip_parameters_t
params_list
;
AUTH_BASE
const
char
*
username
;
const
char
*
realm
;
const
char
*
nonce
;
belle_sip_uri_t
*
uri
;
const
char
*
dresponse
;
const
char
*
algorithm
;
const
char
*
response
;
const
char
*
cnonce
;
const
char
*
opaque
;
const
char
*
message_qop
;
int
nonce_count
;
};
...
...
@@ -409,15 +423,11 @@ struct _belle_sip_header_authorization {
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
);
if
(
authorization
->
cnonce
)
belle_sip_free
((
void
*
)
authorization
->
cnonce
);
if
(
authorization
->
opaque
)
belle_sip_free
((
void
*
)
authorization
->
opaque
);
if
(
authorization
->
message_qop
)
belle_sip_free
((
void
*
)
authorization
->
message_qop
);
AUTH_BASE_DESTROY
(
authorization
)
}
static
void
belle_sip_header_authorization_clone
(
belle_sip_header_authorization_t
*
authorization
,
...
...
@@ -439,26 +449,15 @@ void belle_sip_header_authorization_set_uri(belle_sip_header_authorization_t* au
}
BELLE_SIP_NEW_HEADER
(
header_authorization
,
parameters
,
"Authorization"
)
BELLE_SIP_PARSE
(
header_authorization
)
GET_SET_STRING
(
belle_sip_header_authorization
,
scheme
);
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
,
response
);
GET_SET_STRING
(
belle_sip_header_authorization
,
algorithm
);
GET_SET_STRING
(
belle_sip_header_authorization
,
cnonce
);
GET_SET_STRING
(
belle_sip_header_authorization
,
opaque
);
GET_SET_STRING
(
belle_sip_header_authorization
,
message_qop
);
const
char
*
belle_sip_header_authorization_get_qop
(
const
belle_sip_header_authorization_t
*
authorization
)
{
return
belle_sip_header_authorization_get_message_qop
(
authorization
);
}
void
belle_sip_header_authorization_set_qop
(
belle_sip_header_authorization_t
*
authorization
,
const
char
*
qop
)
{
belle_sip_header_authorization_set_message_qop
(
authorization
,
qop
);
}
GET_SET_STRING
(
belle_sip_header_authorization
,
qop
);
GET_SET_INT
(
belle_sip_header_authorization
,
nonce_count
,
int
)
/**************************
...
...
@@ -478,3 +477,30 @@ static void belle_sip_header_proxy_authorization_clone(belle_sip_header_proxy_au
}
BELLE_SIP_NEW_HEADER
(
header_proxy_authorization
,
header_authorization
,
"Proxy-Authorization"
)
BELLE_SIP_PARSE
(
header_proxy_authorization
)
/**************************
*WWW-Authorization header object inherent from parameters
****************************
*/
struct
_belle_sip_header_www_authenticate
{
AUTH_BASE
const
char
*
domain
;
unsigned
int
stale
;
};
static
void
belle_sip_header_www_authenticate_destroy
(
belle_sip_header_www_authenticate_t
*
www_authenticate
)
{
}
static
void
belle_sip_header_www_authenticate_clone
(
belle_sip_header_www_authenticate_t
*
www_authenticate
,
const
belle_sip_header_www_authenticate_t
*
orig
)
{
}
BELLE_SIP_NEW_HEADER
(
header_www_authenticate
,
parameters
,
"WWW-Authenticdate"
)
BELLE_SIP_PARSE
(
header_www_authenticate
)
GET_SET_STRING
(
belle_sip_header_www_authenticate
,
scheme
);
GET_SET_STRING
(
belle_sip_header_www_authenticate
,
realm
);
GET_SET_STRING
(
belle_sip_header_www_authenticate
,
nonce
);
GET_SET_STRING
(
belle_sip_header_www_authenticate
,
algorithm
);
GET_SET_STRING
(
belle_sip_header_www_authenticate
,
opaque
);
GET_SET_STRING
(
belle_sip_header_www_authenticate
,
qop
);
GET_SET_STRING
(
belle_sip_header_www_authenticate
,
domain
)
GET_SET_BOOL
(
belle_sip_header_www_authenticate
,
stale
,
is
)
src/belle_sip_message.g
View file @
3d0603af
...
...
@@ -221,8 +221,9 @@ scope { belle_sip_header_authorization_t* current; }
@init {$header_authorization::current = belle_sip_header_authorization_new(); $ret=$header_authorization::current; }
: authorization_token /*'Authorization'*/ hcolon credentials[$header_authorization::current];
credentials [belle_sip_header_authorization_t* header_authorization_base]
: (digest_token /*'Digest'*/ LWS digest_response[header_authorization_base])
/*| other_response*/;
: (digest_token /*'Digest'*/ {belle_sip_header_authorization_set_scheme(header_authorization_base,"Digest");}
LWS digest_response[header_authorization_base])
| other_response[header_authorization_base];
digest_response [belle_sip_header_authorization_t* header_authorization_base]
: dig_resp[header_authorization_base] (comma dig_resp[header_authorization_base])*;
dig_resp [belle_sip_header_authorization_t* header_authorization_base]
...
...
@@ -314,12 +315,14 @@ auth_param [belle_sip_header_authorization_t* header_authorization_base]
auth_param_value : token | quoted_string ;
auth_param_name
: token;
/*other_response
: auth_scheme LWS auth_param
(COMMA auth_param)*;
other_response [belle_sip_header_authorization_t* header_authorization_base]
: auth_scheme {belle_sip_header_authorization_set_scheme(header_authorization_base,(const char*)$auth_scheme.text->chars);}
LWS auth_param[header_authorization_base]
(comma auth_param[header_authorization_base])*;
auth_scheme
: token;
/*
authentication_info : 'Authentication-Info' HCOLON ainfo
(COMMA ainfo)*;
ainfo
...
...
@@ -549,26 +552,45 @@ other_priority
proxy_authenticate
: 'Proxy-Authenticate' HCOLON challenge;
challenge
: ('Digest' LWS digest_cln (COMMA digest_cln)*)
| other_challenge;
other_challenge
: auth_scheme LWS auth_param
(COMMA auth_param)*;
digest_cln
: realm | domain | nonce
| opaque | stale | algorithm
| qop_options | auth_param;
*/
challenge [belle_sip_header_www_authenticate_t* www_authenticate]
: ({IS_TOKEN(Digest)}? token /*'Digest'*/ {belle_sip_header_www_authenticate_set_scheme(www_authenticate,"Digest");}
LWS digest_cln[www_authenticate] (comma digest_cln[www_authenticate])*)
| other_challenge [www_authenticate];
other_challenge [belle_sip_header_www_authenticate_t* www_authenticate]
: auth_scheme {belle_sip_header_www_authenticate_set_scheme(www_authenticate,$auth_scheme.text->chars);}
LWS auth_param[NULL]
(comma auth_param[NULL])*;
digest_cln [belle_sip_header_www_authenticate_t* www_authenticate]
:
| realm {belle_sip_header_www_authenticate_set_realm(www_authenticate,$realm.ret);
belle_sip_free($realm.ret);}
| nonce {belle_sip_header_www_authenticate_set_nonce(www_authenticate,$nonce.ret);
belle_sip_free($nonce.ret);}
| algorithm {belle_sip_header_www_authenticate_set_algorithm(www_authenticate,$algorithm.ret);}
| opaque {belle_sip_header_www_authenticate_set_opaque(www_authenticate,$opaque.ret);
belle_sip_free($opaque.ret);}
| qop_opts {belle_sip_header_www_authenticate_set_qop(www_authenticate,$qop_opts.ret);
belle_sip_free($qop_opts.ret);}
| domain {belle_sip_header_www_authenticate_set_domain(www_authenticate,$domain.ret);
belle_sip_free($domain.ret);}
| stale { if (strcmp("true",$stale.ret)==0) {
belle_sip_header_www_authenticate_set_stale(www_authenticate,1);
}
}
| auth_param[www_authenticate];
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 ;
/*
domain
: 'domain' EQUAL LDQUOT uri
domain returns [char* ret]
: {IS_TOKEN(domain)}? token /*'domain'*/ equal quoted_string {
$ret = _belle_sip_str_dup_and_unquote_string($quoted_string.text->chars);};
/* LDQUOT uri
( SP+ uri )* RDQUOT;
uri
: absoluteURI | '/'.;
...
...
@@ -581,19 +603,23 @@ opaque returns [char* ret]
: {IS_TOKEN(opaque)}? token /*'opaque'*/ equal quoted_string{
$ret = _belle_sip_str_dup_and_unquote_string($quoted_string.text->chars);
};
/*
stale
: 'stale' EQUAL ( 'true' | 'false' );
*/
stale returns [const char* ret]
: {IS_TOKEN(stale)}? token /*'stale'*/ equal stale_value {$ret=$stale_value.text->chars;} /* ( 'true' | 'false' )*/;
stale_value:token;
algorithm returns [const char* ret]
: {IS_TOKEN(algorithm)}? token /*'algorithm'*/ equal /* ( 'MD5' | 'MD5-sess'
|*/ alg_value=token {$ret=$alg_value.text->chars;}/*)*/
;
/*
qop_options
: 'qop' EQUAL LDQUOT qop_value
(',' qop_value)* RDQUOT:
qop_value
qop_opts returns [char* ret]
: {IS_TOKEN(qop)}? token /*'qop'*/ equal quoted_string {
$ret = _belle_sip_str_dup_and_unquote_string($quoted_string.text->chars);
};/*LDQUOT qop_value
(COMMA qop_value)* RDQUOT:*/
/*qop_value
: 'auth' | 'auth-int' | token;
*/
header_proxy_authorization returns [belle_sip_header_proxy_authorization_t* ret]
...
...
@@ -747,10 +773,12 @@ warn_text
: quoted_string;
pseudonym
: token;
www_authenticate
: 'WWW-Authenticate' HCOLON challenge;
*/
header_www_authenticate returns [belle_sip_header_www_authenticate_t* ret]
scope { belle_sip_header_www_authenticate_t* current; }
@init { $header_www_authenticate::current = belle_sip_header_www_authenticate_new();$ret = $header_www_authenticate::current; }
: {IS_TOKEN(WWW-Authenticate)}? token /*'WWW-Authenticate'*/ hcolon challenge[$header_www_authenticate::current];
header_extension[ANTLR3_BOOLEAN check_for_known_header] returns [belle_sip_header_t* ret]
: header_name
hcolon
...
...
tester/belle_sip_headers_tester.c
View file @
3d0603af
...
...
@@ -164,6 +164,7 @@ void test_header_authorization(void) {
"
\r\n
qop=auth, nc=00000001,cnonce=
\"
0a4f113b
\"
, blabla=
\"
toto
\"
"
;
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_scheme
(
L_authorization
),
"Digest"
);
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"
);
...
...
@@ -186,7 +187,23 @@ void test_header_proxy_authorization(void) {
CU_ASSERT_STRING_EQUAL
(
belle_sip_header_authorization_get_username
(
BELLE_SIP_HEADER_AUTHORIZATION
(
L_authorization
)),
"Alice"
);
CU_ASSERT_STRING_EQUAL
(
belle_sip_header_authorization_get_realm
(
BELLE_SIP_HEADER_AUTHORIZATION
(
L_authorization
)),
"atlanta.com"
);
CU_ASSERT_STRING_EQUAL
(
belle_sip_header_authorization_get_nonce
(
BELLE_SIP_HEADER_AUTHORIZATION
(
L_authorization
)),
"c60f3082ee1212b402a21831ae"
);
CU_ASSERT_STRING_EQUAL
(
belle_sip_header_authorization_get_response
(
BELLE_SIP_HEADER_AUTHORIZATION
(
L_authorization
)),
"245f23415f11432b3434341c022"
);
belle_sip_object_unref
(
BELLE_SIP_OBJECT
(
L_authorization
));
}
void
test_header_www_authenticate
(
void
)
{
const
char
*
l_raw_header
=
"WWW-Authenticate: Digest "
"algorithm=MD5, realm=
\"
atlanta.com
\"
, opaque=
\"
1bc7f9097684320
\"
,"
" qop=
\"
auth
\"
, nonce=
\"
c60f3082ee1212b402a21831ae
\"
, stale=true, domain=
\"
sip:boxesbybob.com
\"
"
;
belle_sip_header_www_authenticate_t
*
L_authorization
=
belle_sip_header_www_authenticate_parse
(
l_raw_header
);
CU_ASSERT_PTR_NOT_NULL
(
L_authorization
);
CU_ASSERT_STRING_EQUAL
(
belle_sip_header_www_authenticate_get_realm
(
L_authorization
),
"atlanta.com"
);
CU_ASSERT_STRING_EQUAL
(
belle_sip_header_www_authenticate_get_domain
(
L_authorization
),
"sip:boxesbybob.com"
);
CU_ASSERT_STRING_EQUAL
(
belle_sip_header_www_authenticate_get_nonce
(
L_authorization
),
"c60f3082ee1212b402a21831ae"
);
CU_ASSERT_STRING_EQUAL
(
belle_sip_header_www_authenticate_get_algorithm
(
L_authorization
),
"MD5"
);
CU_ASSERT_STRING_EQUAL
(
belle_sip_header_www_authenticate_get_opaque
(
L_authorization
),
"1bc7f9097684320"
);
CU_ASSERT_STRING_EQUAL
(
belle_sip_header_www_authenticate_get_qop
(
L_authorization
),
"auth"
);
CU_ASSERT_STRING_EQUAL
(
belle_sip_header_www_authenticate_get_scheme
(
L_authorization
),
"Digest"
);
CU_ASSERT_EQUAL
(
belle_sip_header_www_authenticate_is_stale
(
L_authorization
),
1
);
belle_sip_object_unref
(
BELLE_SIP_OBJECT
(
L_authorization
));
}
...
...
@@ -240,5 +257,9 @@ int belle_sip_headers_test_suite() {
if
(
NULL
==
CU_add_test
(
pSuite
,
"test of proxy authorization"
,
test_header_proxy_authorization
))
{
return
CU_get_error
();
}
if
(
NULL
==
CU_add_test
(
pSuite
,
"test of www authenticate"
,
test_header_www_authenticate
))
{
return
CU_get_error
();
}
return
0
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment