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
42af7fa7
Commit
42af7fa7
authored
Apr 21, 2011
by
jehan
Browse files
add username getter to authorization header
parent
eca24ea7
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
141 additions
and
43 deletions
+141
-43
include/belle-sip/belle-sip.h
include/belle-sip/belle-sip.h
+1
-0
include/belle-sip/headers.h
include/belle-sip/headers.h
+36
-3
src/belle_sip_headers_impl.c
src/belle_sip_headers_impl.c
+24
-3
src/belle_sip_internal.h
src/belle_sip_internal.h
+3
-0
src/belle_sip_message.g
src/belle_sip_message.g
+49
-35
src/belle_sip_utils.c
src/belle_sip_utils.c
+6
-0
tester/belle_sip_headers_tester.c
tester/belle_sip_headers_tester.c
+20
-0
tester/belle_sip_message_tester.c
tester/belle_sip_message_tester.c
+2
-2
No files found.
include/belle-sip/belle-sip.h
View file @
42af7fa7
...
...
@@ -65,6 +65,7 @@ typedef enum belle_sip_type_id{
BELLE_SIP_TYPE_ID
(
belle_sip_header_content_length_t
),
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_end
}
belle_sip_type_id_t
;
...
...
include/belle-sip/headers.h
View file @
42af7fa7
...
...
@@ -251,7 +251,40 @@ void belle_sip_header_content_length_set_content_length(belle_sip_header_content
#define BELLE_SIP_HEADER_CONTENT_LENGTH(t) BELLE_SIP_CAST(t,belle_sip_header_content_length_t)
/******************************
* Extension header hinerite from header
* authorization header inherit from header
*
******************************/
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_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
);
const
char
*
belle_sip_header_authorization_get_nonce
(
const
belle_sip_header_authorization_t
*
authorization
);
int
belle_sip_header_authorization_get_nonce_count
(
const
belle_sip_header_authorization_t
*
authorization
);
const
char
*
belle_sip_header_authorization_get_opaque
(
const
belle_sip_header_authorization_t
*
authorization
);
const
char
*
belle_sip_header_authorization_get_qop
(
const
belle_sip_header_authorization_t
*
authorization
);
const
char
*
belle_sip_header_authorization_get_realm
(
const
belle_sip_header_authorization_t
*
authorization
);
const
char
*
belle_sip_header_authorization_get_response
(
const
belle_sip_header_authorization_t
*
authorization
);
const
char
*
belle_sip_header_authorization_get_scheme
(
const
belle_sip_header_authorization_t
*
authorization
);
belle_sip_uri_t
*
belle_sip_header_authorization_get_uri
(
const
belle_sip_header_authorization_t
*
authorization
);
const
char
*
belle_sip_header_authorization_get_username
(
const
belle_sip_header_authorization_t
*
authorization
);
void
belle_sip_header_authorization_set_algorithm
(
belle_sip_header_authorization_t
*
authorization
,
const
char
*
algorithm
);
void
belle_sip_header_authorization_set_cnonce
(
belle_sip_header_authorization_t
*
authorization
,
const
char
*
cNonce
);
void
belle_sip_header_authorization_set_nonce
(
belle_sip_header_authorization_t
*
authorization
,
const
char
*
nonce
);
void
belle_sip_header_authorization_set_nonce_count
(
belle_sip_header_authorization_t
*
authorization
,
int
nonceCount
);
void
belle_sip_header_authorization_set_opaque
(
belle_sip_header_authorization_t
*
authorization
,
const
char
*
opaque
);
void
belle_sip_header_authorization_set_qop
(
belle_sip_header_authorization_t
*
authorization
,
const
char
*
qop
);
void
belle_sip_header_authorization_set_realm
(
belle_sip_header_authorization_t
*
authorization
,
const
char
*
realm
);
void
belle_sip_header_authorization_set_response
(
belle_sip_header_authorization_t
*
authorization
,
const
char
*
response
);
void
belle_sip_header_authorization_set_scheme
(
belle_sip_header_authorization_t
*
authorization
,
const
char
*
scheme
);
void
belle_sip_header_authorization_set_uri
(
belle_sip_header_authorization_t
*
authorization
,
belle_sip_uri_t
*
uri
);
void
belle_sip_header_authorization_set_username
(
belle_sip_header_authorization_t
*
authorization
,
const
char
*
username
);
#define BELLE_SIP_HEADER_AUTHORIZATION(t) BELLE_SIP_CAST(t,belle_sip_header_authorization_t)
/******************************
* Extension header inherit from header
*
******************************/
typedef
struct
_belle_sip_header_extension
belle_sip_header_extension_t
;
...
...
@@ -259,8 +292,8 @@ typedef struct _belle_sip_header_extension belle_sip_header_extension_t;
belle_sip_header_extension_t
*
belle_sip_header_extension_new
();
belle_sip_header_extension_t
*
belle_sip_header_extension_parse
(
const
char
*
extension
)
;
const
char
*
belle_sip_header_extension_
length_
get_value
(
const
belle_sip_header_extension_t
*
extension
);
void
belle_sip_header_extension_
length_
set_value
(
belle_sip_header_extension_t
*
extension
,
const
char
*
value
);
const
char
*
belle_sip_header_extension_get_value
(
const
belle_sip_header_extension_t
*
extension
);
void
belle_sip_header_extension_set_value
(
belle_sip_header_extension_t
*
extension
,
const
char
*
value
);
#define BELLE_SIP_HEADER_EXTENSION(t) BELLE_SIP_CAST(t,belle_sip_header_extension_t)
#endif
/* HEADERS_H_ */
src/belle_sip_headers_impl.c
View file @
42af7fa7
...
...
@@ -70,9 +70,7 @@ GET_SET_STRING(belle_sip_header_address,displayname);
void
belle_sip_header_address_set_quoted_displayname
(
belle_sip_header_address_t
*
address
,
const
char
*
value
)
{
if
(
address
->
displayname
!=
NULL
)
belle_sip_free
((
void
*
)(
address
->
displayname
));
size_t
value_size
=
strlen
(
value
);
address
->
displayname
=
belle_sip_malloc0
(
value_size
-
2
+
1
);
strncpy
((
char
*
)(
address
->
displayname
),
value
+
1
,
value_size
-
2
);
address
->
displayname
=
_belle_sip_str_dup_and_unquote_string
(
value
);
}
belle_sip_uri_t
*
belle_sip_header_address_get_uri
(
belle_sip_header_address_t
*
address
)
{
return
address
->
uri
;
...
...
@@ -389,4 +387,27 @@ belle_sip_header_extension_t* belle_sip_header_extension_parse (const char* valu
return
BELLE_SIP_HEADER_EXTENSION
(
l_parsed_object
.
ret
);
}
GET_SET_STRING
(
belle_sip_header_extension
,
value
);
/**************************
* content length header object inherent from object
****************************
*/
struct
_belle_sip_header_authorization
{
belle_sip_header_t
header
;
const
char
*
username
;
};
static
void
belle_sip_header_authorization_destroy
(
belle_sip_header_authorization_t
*
authorization
)
{
if
(
authorization
->
username
)
belle_sip_free
((
void
*
)
authorization
->
username
);
}
static
void
belle_sip_header_authorization_clone
(
belle_sip_header_authorization_t
*
authorization
,
const
belle_sip_header_authorization_t
*
orig
)
{
}
BELLE_SIP_NEW_HEADER
(
header_authorization
,
header
,
"Authorization"
)
BELLE_SIP_PARSE
(
header_authorization
)
GET_SET_STRING
(
belle_sip_header_authorization
,
username
);
src/belle_sip_internal.h
View file @
42af7fa7
...
...
@@ -504,6 +504,9 @@ void belle_sip_client_transaction_add_response(belle_sip_client_transaction_t *t
*/
void
belle_sip_response_get_return_hop
(
belle_sip_response_t
*
msg
,
belle_sip_hop_t
*
hop
);
#define IS_TOKEN(token) (strcmp(#token,(const char*)(INPUT->toStringTT(INPUT,LT(1),LT(strlen(#token))))->chars) == 0)
char
*
_belle_sip_str_dup_and_unquote_string
(
char
*
quoted_string
);
#ifdef __cplusplus
}
#endif
...
...
src/belle_sip_message.g
View file @
42af7fa7
...
...
@@ -212,56 +212,66 @@ absoluteURI
: token ':' token;
allow : 'Allow' HCOLON (method (COMMA method))? ;
*/
authorization_token: {IS_TOKEN(Authorization)}? token;
digest_token: {IS_TOKEN(Digest)}? token;
authorization
: 'Authorization' HCOLON credentials;
header_authorization returns [belle_sip_header_authorization_t* ret]
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;
credentials
: ('Digest' LWS digest_response)
| other_response;
: (
digest_token /*
'Digest'
*/
LWS digest_response)
/*
| other_response
*/
;
digest_response
: dig_resp (
COMMA
dig_resp)*;
: dig_resp (
comma
dig_resp)*;
dig_resp
: username | realm | nonce | digest_uri
: username
/*| realm | nonce | digest_uri
| dresponse | algorithm | cnonce
| opaque | message_qop
| nonce_count | auth_param;
| nonce_count | auth_param*/;
username_token: {IS_TOKEN(username)}? token;
username
: 'username' EQUAL username_value;
: 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);} ;
username_value : quoted_string;
uri_token: {IS_TOKEN(uri)}? token;
digest_uri
:
'uri' EQUAL
LDQUOT digest_uri_value RDQUOT;
:
uri_token /*'uri'*/ equal
LDQUOT digest_uri_value RDQUOT;
digest_uri_value : rquest_uri ;
rquest_uri
:
absoluteURI
;
;
:
uri
;
// Equal to request-uri as specified by HTTP/1.1
message_qop
:
'qop' EQUAL
qop_value;
:
{IS_TOKEN(qop)}? token/*'qop'*/ equal
qop_value;
qop_value
: 'auth'|'auth-int' | token;
;
: {IS_TOKEN(auth)}? token /*'auth'*/ | {IS_TOKEN(auth-int)}? token /*'auth-int'*/ | token;
cnonce
:
'cnonce' EQUAL
cnonce_value;
:
{IS_TOKEN(cnonce)}? token /*'cnonce'*/ equal
cnonce_value;
cnonce_value
: nonce_value;
nonce_count
:
'nc' EQUAL
nc_value;
:
{IS_TOKEN(nc)}? token /*'nc'*/ equal
nc_value;
nc_value
: huit_lhex;
;
: huit_lhex;
dresponse
: 'response'
EQUAL
request_digest;
:
{IS_TOKEN(response)}? token /*
'response'
*/ equal
request_digest;
request_digest
:
LDQUOT
huit_lhex huit_lhex huit_lhex huit_lhex
RDQUOT
;
:
sp_laquot_sp
huit_lhex huit_lhex huit_lhex huit_lhex
sp_raquot_sp
;
huit_lhex
: hexdigit+;
;
auth_param
: auth_param_name
EQUAL
: auth_param_name
equal
( token | quoted_string );
auth_param_name
: token;
...
...
@@ -270,7 +280,7 @@ other_response
(COMMA auth_param)*;
auth_scheme
: token;
/*
authentication_info : 'Authentication-Info' HCOLON ainfo
(COMMA ainfo)*;
ainfo
...
...
@@ -279,14 +289,16 @@ ainfo
| nonce_count;
nextnonce
: 'nextnonce' EQUAL nonce_value;
*/
nonce_value : quoted_string;
/*
response_auth
: 'rspauth' EQUAL response_digest;
response_digest
: LDQUOT hexdigit* RDQUOT;
*/
/*callid header*/
call_id_token: {
strcmp("Call-ID",(const char*)(INPUT->toStringTT(INPUT,LT(1),LT(7)))->chars) == 0
}? token;
call_id_token: {
IS_TOKEN(Call-ID)
}? token;
header_call_id returns [belle_sip_header_call_id_t* ret]
scope { belle_sip_header_call_id_t* current; }
...
...
@@ -304,7 +316,7 @@ info_param
| 'card' | token ) ) | generic_param;
*/
/* contact header */
contact_token: {
strcmp("Contact",(const char*)(INPUT->toStringTT(INPUT,LT(1),LT(7)))->chars) == 0
}? token;
contact_token: {
IS_TOKEN(Contact)
}? token;
header_contact returns [belle_sip_header_contact_t* ret]
scope { belle_sip_header_contact_t* current; }
...
...
@@ -374,7 +386,8 @@ huit_alpha
: alpha+;
;
*/
content_length_token : {strcmp("Content-Length",(const char*)(INPUT->toStringTT(INPUT,LT(1),LT(14)))->chars) == 0}? token;
/*content_length_token : {strcmp("Content-Length",(const char*)(INPUT->toStringTT(INPUT,LT(1),LT(14)))->chars) == 0}? token;*/
content_length_token : {IS_TOKEN(Content-Length)}? token;
header_content_length returns [belle_sip_header_content_length_t* ret]
scope { belle_sip_header_content_length_t* current; }
@init {$header_content_length::current = belle_sip_header_content_length_new(); $ret=$header_content_length::current; }
...
...
@@ -383,7 +396,7 @@ scope { belle_sip_header_content_length_t* current; }
content_length {belle_sip_header_content_length_set_content_length($header_content_length::current,atoi((const char*)$content_length.text->chars));};
content_length:DIGIT+;
content_type_token : {
strcmp("
Content-Type
",(const char*)(INPUT->toStringTT(INPUT,LT(1),LT(12)))->chars) == 0
}? token;
content_type_token : {
IS_TOKEN(
Content-Type
)
}? token;
header_content_type returns [belle_sip_header_content_type_t* ret]
scope { belle_sip_header_content_type_t* current;}
@init { $header_content_type::current = belle_sip_header_content_type_new();$ret=$header_content_type::current; }
...
...
@@ -417,7 +430,7 @@ m_value
: token | quoted_string;
*/
cseq_token : {
strcmp("CSeq",(const char*)(INPUT->toStringTT(INPUT,LT(1),LT(4)))->chars) == 0
}? token;
cseq_token : {
IS_TOKEN(CSeq)
}? token;
header_cseq returns [belle_sip_header_cseq_t* ret]
scope { belle_sip_header_cseq_t* current; }
@init { $header_cseq::current = belle_sip_header_cseq_new();$ret = $header_cseq::current; }
...
...
@@ -452,7 +465,7 @@ error_uri
expires
: 'Expires' HCOLON delta_seconds;
*/
from_token: {
strcmp("From",(const char*)(INPUT->toStringTT(INPUT,LT(1),LT(4)))->chars) == 0
}? token;
from_token: {
IS_TOKEN(From)
}? token;
header_from returns [belle_sip_header_from_t* ret]
scope { belle_sip_header_from_t* current; }
@init { $header_from::current = belle_sip_header_from_new();$ret = $header_from::current; }
...
...
@@ -541,7 +554,7 @@ proxy_require
option_tag
: token;
*/
record_route_token: {
strcmp("
Record-Route
",(const char*)(INPUT->toStringTT(INPUT,LT(1),LT(12)))->chars) == 0
}? token;
record_route_token: {
IS_TOKEN(
Record-Route
)
}? token;
header_record_route returns [belle_sip_header_record_route_t* ret]
scope { belle_sip_header_record_route_t* current; }
@init { $header_record_route::current = belle_sip_header_record_route_new();$ret = $header_record_route::current; }
...
...
@@ -574,7 +587,7 @@ retry_param
: ('duration' EQUAL delta_seconds)
| generic_param;
*/
route_token: {
strcmp("Route",(const char*)(INPUT->toStringTT(INPUT,LT(1),LT(5)))->chars) == 0
}? token;
route_token: {
IS_TOKEN(Route)
}? token;
header_route returns [belle_sip_header_route_t* ret]
scope { belle_sip_header_route_t* current; }
@init { $header_route::current = belle_sip_header_route_new();$ret = $header_route::current; }
...
...
@@ -610,7 +623,7 @@ timestamp
delay
: (DIGIT)* ( '.' (DIGIT)* )?;
*/
to_token: {
strcmp("To",(const char*)(INPUT->toStringTT(INPUT,LT(1),LT(2)))->chars) == 0
}? token;
to_token: {
IS_TOKEN(To)
}? token;
header_to returns [belle_sip_header_to_t* ret]
scope { belle_sip_header_to_t* current; }
@init { $header_to::current = belle_sip_header_to_new(); }
...
...
@@ -627,7 +640,7 @@ unsupported
user_agent
: 'User-Agent' HCOLON server_val (LWS server_val)*;
*/
via_token: {
strcmp("Via",(const char*)(INPUT->toStringTT(INPUT,LT(1),LT(3)))->chars) == 0
}? token;
via_token: {
IS_TOKEN(Via)
}? token;
header_via returns [belle_sip_header_via_t* ret]
scope { belle_sip_header_via_t* current; }
@init { $header_via::current = belle_sip_header_via_new(); }
...
...
@@ -728,8 +741,8 @@ uri returns [belle_sip_uri_t* ret]
scope { belle_sip_uri_t* current; }
@init { $uri::current = belle_sip_uri_new(); }
: sip_schema ((userinfo hostport) | hostport ) uri_parameters? headers? {$ret = $uri::current;};
sip_token: {
strcmp("sip",(const char*)(INPUT->toStringTT(INPUT,LT(1),LT(3)))->chars) == 0
}? token;
sips_token: {
strcmp("sips",(const char*)(INPUT->toStringTT(INPUT,LT(1),LT(4)))->chars) == 0
}? token;
sip_token: {
IS_TOKEN(sip)
}? token;
sips_token: {
IS_TOKEN(sips)
}? token;
sip_schema : (sips_token {belle_sip_uri_set_secure($uri::current,1);}
| sip_token) COLON ;
...
...
@@ -816,7 +829,7 @@ mark : '-' | '_' | '.' | '!' | '~' | STAR | '\'' ;
HEX_CHAR: 'a'..'f' |'A'..'F';
DIGIT : '0'..'9' ;
CRLF : '\r\n' { USER1 = GETCHARINDEX();};
CRLF : '\r\n' { USER1 =
(int)(ctx->pLexer->input->currentLine - ctx->pLexer->input->data); /*
GETCHARINDEX()
*/
;};
...
...
@@ -857,6 +870,7 @@ SEMI
: ';'
;
comma : LWS? COMMA LWS?;
COMMA
: ','
;
...
...
src/belle_sip_utils.c
View file @
42af7fa7
...
...
@@ -470,5 +470,11 @@ int belle_sip_param_pair_comp_func(const belle_sip_param_pair_t *a, const char*b
return
strcmp
(
a
->
name
,
b
);
}
char
*
_belle_sip_str_dup_and_unquote_string
(
char
*
quoted_string
)
{
size_t
value_size
=
strlen
(
quoted_string
);
char
*
unquoted_string
=
belle_sip_malloc0
(
value_size
-
2
+
1
);
strncpy
(
unquoted_string
,
quoted_string
+
1
,
value_size
-
2
);
return
unquoted_string
;
}
tester/belle_sip_headers_tester.c
View file @
42af7fa7
...
...
@@ -152,6 +152,20 @@ void test_header_content_length(void) {
CU_ASSERT_EQUAL
(
belle_sip_header_content_length_get_content_length
(
L_content_length
),
3495
);
belle_sip_object_unref
(
BELLE_SIP_OBJECT
(
L_content_length
));
}
void
test_header_extention
(
void
)
{
belle_sip_header_extension_t
*
L_extension
=
belle_sip_header_extension_parse
(
"toto: titi"
);
CU_ASSERT_STRING_EQUAL
(
belle_sip_header_extension_get_value
(
L_extension
),
"titi"
);
belle_sip_object_unref
(
BELLE_SIP_OBJECT
(
L_extension
));
}
void
test_header_authorization
(
void
)
{
const
char
*
l_raw_header
=
"Authorization: Digest username=
\"
0033482532176
\"
, "
\
"realm=
\"
sip.ovh.net
\"
, nonce=
\"
1bcdcb194b30df5f43973d4c69bdf54f
\"
, uri=
\"
sip:sip.ovh.net
\"
, response=
\"
eb36c8d5c8642c1c5f44ec3404613c81
\"
,"
\
"algorithm=MD5, opaque=
\"
1bc7f9097684320
\"
"
;
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"
);
belle_sip_object_unref
(
BELLE_SIP_OBJECT
(
L_authorization
));
}
int
belle_sip_headers_test_suite
()
{
...
...
@@ -194,5 +208,11 @@ int belle_sip_headers_test_suite() {
if
(
NULL
==
CU_add_test
(
pSuite
,
"test of content lenth"
,
test_header_content_length
))
{
return
CU_get_error
();
}
if
(
NULL
==
CU_add_test
(
pSuite
,
"test of extension"
,
test_header_extention
))
{
return
CU_get_error
();
}
if
(
NULL
==
CU_add_test
(
pSuite
,
"test of authorization"
,
test_header_authorization
))
{
return
CU_get_error
();
}
return
0
;
}
tester/belle_sip_message_tester.c
View file @
42af7fa7
...
...
@@ -104,11 +104,11 @@ static void testRegisterRaw(void) {
"Max-Forwards: 70
\r\n
"
\
"User-Agent: Linphone/3.3.99.10 (eXosip2/3.3.0)
\r\n
"
\
"Expires: 3600
\r\n
"
\
"Content-Length: 0
\r\n\r\n
"
;
"Content-Length: 0
\r\n\r\n
123456789
"
;
size_t
size
=
0
;
size_t
raw_message_size
=
strlen
(
raw_message
);
belle_sip_message_t
*
message
=
belle_sip_message_parse_raw
(
raw_message
,
raw_message_size
,
&
size
);
CU_ASSERT_EQUAL
(
raw_message_size
,
size
);
CU_ASSERT_EQUAL
(
raw_message_size
,
size
+
9
);
belle_sip_request_t
*
request
=
BELLE_SIP_REQUEST
(
message
);
CU_ASSERT_STRING_EQUAL
(
belle_sip_request_get_method
(
request
),
"REGISTER"
);
CU_ASSERT_PTR_NOT_NULL
(
belle_sip_request_get_uri
(
request
));
...
...
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