Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
BC
public
belle-sip
Commits
32f03c56
Commit
32f03c56
authored
Dec 02, 2010
by
jehan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
start from header implementation
parent
f2bc48be
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
291 additions
and
30 deletions
+291
-30
include/belle-sip/headers.h
include/belle-sip/headers.h
+24
-2
src/belle_sip_headers_impl.c
src/belle_sip_headers_impl.c
+26
-3
src/belle_sip_internal.h
src/belle_sip_internal.h
+6
-0
src/belle_sip_message.g
src/belle_sip_message.g
+50
-20
src/belle_sip_utils.c
src/belle_sip_utils.c
+4
-3
src/clock_gettime.c
src/clock_gettime.c
+136
-0
src/clock_gettime.h
src/clock_gettime.h
+34
-0
tester/belle_sip_headers_tester.c
tester/belle_sip_headers_tester.c
+11
-2
No files found.
include/belle-sip/headers.h
View file @
32f03c56
...
...
@@ -97,12 +97,34 @@ belle_sip_header_contact_t* belle_sip_header_contact_parse (const char* contact)
/**
* Sets the qValue value of the Name Address.
*/
int
belle_sip_header_contact_set_qvalue
(
belle_sip_header_contact_t
*
contact
,
float
q
V
alue
);
int
belle_sip_header_contact_set_qvalue
(
belle_sip_header_contact_t
*
contact
,
float
q
v
alue
);
/**
* Sets a wildcard on this contact address that is "*" is assigned to the contact header so that the header will have the format of Contact: *.
*
*/
void
belle_sip_header_contact_set_wilcard
(
belle_sip_header_contact_t
*
contact
);
void
belle_sip_header_contact_set_wildcard
(
belle_sip_header_contact_t
*
contact
,
unsigned
int
is_wildcard
);
/**
* From header object inherent from header_address
*
*/
typedef
struct
_belle_sip_header_from
belle_sip_header_from_t
;
belle_sip_header_from_t
*
belle_sip_header_from_new
();
void
belle_sip_header_from_delete
(
belle_sip_header_from_t
*
from
);
belle_sip_header_from_t
*
belle_sip_header_from_parse
(
const
char
*
from
)
;
belle_sip_header_from_t
*
belle_sip_header_from_ref
(
belle_sip_header_from_t
*
from
)
;
void
belle_sip_header_from_unref
(
belle_sip_header_from_t
*
from
)
;
void
belle_sip_header_from_set_tag
(
belle_sip_header_from_t
*
from
,
const
char
*
tag
);
const
char
*
belle_sip_header_from_get_tag
(
belle_sip_header_from_t
*
from
);
#endif
/* HEADERS_H_ */
src/belle_sip_headers_impl.c
View file @
32f03c56
...
...
@@ -46,6 +46,12 @@ void belle_sip_header_address_delete(belle_sip_header_address_t* contact) {
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
);
}
belle_sip_uri_t
*
belle_sip_header_address_get_uri
(
belle_sip_header_address_t
*
address
)
{
return
address
->
uri
;
}
...
...
@@ -63,7 +69,6 @@ BELLE_SIP_REF(header_address)
struct
_belle_sip_header_contact
{
belle_sip_header_address_t
address
;
int
ref
;
belle_sip_header_address_t
*
header_address
;
int
expires
;
float
qvalue
;
unsigned
int
wildcard
;
...
...
@@ -74,7 +79,7 @@ belle_sip_header_contact_t* belle_sip_header_contact_new() {
}
void
belle_sip_header_contact_delete
(
belle_sip_header_contact_t
*
contact
)
{
if
(
contact
->
header_address
)
belle_sip_header_address_
delete
(
contact
->
header_address
);
belle_sip_
header_address
_delete
((
belle_sip_header_address_
t
*
)
contact
);
}
BELLE_SIP_PARSE
(
header_contact
);
...
...
@@ -91,13 +96,31 @@ int belle_sip_header_contact_set_expires(belle_sip_header_contact_t* contact, in
return
0
;
}
int
belle_sip_header_contact_set_qvalue
(
belle_sip_header_contact_t
*
contact
,
float
qValue
)
{
if
(
qValue
!=
-
1
||
qValue
<
0
||
qValue
>
1
)
{
if
(
qValue
!=
-
1
&&
qValue
<
0
&&
qValue
>
1
)
{
return
-
1
;
}
_belle_sip_header_contact_set_qvalue
(
contact
,
qValue
);
return
0
;
}
/**
* From header object inherent from header_address
*
*/
struct
_belle_sip_header_from
{
belle_sip_header_address_t
address
;
int
ref
;
const
char
*
tag
;
};
BELLE_SIP_NEW
(
header_from
)
BELLE_SIP_REF
(
header_from
)
BELLE_SIP_PARSE
(
header_from
)
GET_SET_STRING
(
belle_sip_header_from
,
tag
);
void
belle_sip_header_from_delete
(
belle_sip_header_from_t
*
from
)
{
belle_sip_header_address_delete
((
belle_sip_header_address_t
*
)
from
);
}
...
...
src/belle_sip_internal.h
View file @
32f03c56
...
...
@@ -235,6 +235,11 @@ belle_sip_##object_type##_t* belle_sip_##object_type##_parse (const char* value)
return l_parsed_object;\
}
#define BELLE_SIP_NEW(object_type) \
belle_sip_##object_type##_t* belle_sip_##object_type##_ref (belle_sip_##object_type##_t* obj) { \
return (belle_sip_##object_type##_t*)belle_sip_new0(belle_sip_##object_type##_t);\
}
#define BELLE_SIP_REF(object_type) \
belle_sip_##object_type##_t* belle_sip_##object_type##_ref (belle_sip_##object_type##_t* obj) { \
obj->ref++;\
...
...
@@ -266,6 +271,7 @@ belle_sip_param_pair_t* belle_sip_param_pair_ref(belle_sip_param_pair_t* obj);
void
belle_sip_param_pair_unref
(
belle_sip_param_pair_t
*
obj
);
void
belle_sip_header_address_set_quoted_displayname
(
belle_sip_header_address_t
*
address
,
const
char
*
value
);
#ifdef __cplusplus
}
...
...
src/belle_sip_message.g
View file @
32f03c56
...
...
@@ -148,13 +148,13 @@ qvalue
| ( '1'( '.'DIGIT+)? );
*/
generic_param returns [belle_sip_param_pair_t* ret]
: token ( EQUAL is_gen=gen_value )? {$ret=belle_sip_param_pair_new($token.text->chars,$is_gen.text?$gen_value.text->chars:NULL);};
:
SP*
token (
SP*
EQUAL
SP*
is_gen=gen_value )? {$ret=belle_sip_param_pair_new($token.text->chars,$is_gen.text?$gen_value.text->chars:NULL);};
gen_value
: token | quoted_string;
quoted_string
options { greedy = false; }
: DQUOTE .* DQUOTE ;
: DQUOTE
unquoted_value=(
.*
)
DQUOTE ;
/*
accept_encoding
...
...
@@ -268,21 +268,28 @@ info_param
: ( 'purpose' EQUAL ( 'icon' | 'info'
| 'card' | token ) ) | generic_param;
*/
/* contact header */
contact_token: {strcmp("Contact",(const char*)(INPUT->toStringTT(INPUT,LT(1),LT(7)))->chars) == 0}? token;
header_contact returns [belle_sip_header_contact_t* ret]
scope { belle_sip_header_contact_t* current; }
@init { $header_contact::current = belle_sip_header_contact_new(); }
: ('Contact' /*| 'm'*/ ) hcolom
( STAR | (contact_param (COMMA contact_param)*)) {$ret = $header_contact::current;};
: (contact_token /*'Contact'*/ /*| 'm'*/ ) hcolom
( STAR { belle_sip_header_contact_set_wildcard($header_contact::current,1);}
| (contact_param (COMMA contact_param)*)) {$ret = $header_contact::current;};
contact_param
: (name_addr | addr_spec) (SEMI contact_params)*;
name_addr
: ( display_name )? sp_laquot_sp addr_spec sp_raquot_sp;
addr_spec : uri {belle_sip_header_address_set_uri((belle_sip_header_address_t*) $header_contact::current
,belle_sip_uri_ref($uri.ret));
};//| absoluteURI;
display_name : token | quoted_string {belle_sip_header_address_set_displayname((belle_sip_header_address_t*) $header_contact::current
,$display_name.text->chars);};
: (name_addr[(belle_sip_header_address_t*) $header_contact::current]
| addr_spec[(belle_sip_header_address_t*) $header_contact::current]) (SEMI contact_params)*;
name_addr[belle_sip_header_address_t* object]
: ( display_name[object] )? sp_laquot_sp addr_spec[object] sp_raquot_sp;
addr_spec[belle_sip_header_address_t* object]
: uri {belle_sip_header_address_set_uri(object,belle_sip_uri_ref($uri.ret));};//| absoluteURI;
display_name[belle_sip_header_address_t* object]
: token {belle_sip_header_address_set_displayname(object,$token.text->chars);}
| quoted_string {belle_sip_header_address_set_quoted_displayname(object,$quoted_string.text->chars);}
;
contact_params
: /*c_p_q | c_p_expires
...
...
@@ -292,7 +299,16 @@ contact_params
c_p_expires
: 'expires' EQUAL delta_seconds;*/
contact_extension
: generic_param;
: generic_param {belle_sip_param_pair_t* pair = $generic_param.ret ;
if (strcmp("expires",pair->name) == 0) {
belle_sip_header_contact_set_expires($header_contact::current,atoi(pair->value));
} else if (strcmp("q",pair->name) == 0) {
belle_sip_header_contact_set_qvalue($header_contact::current,atof(pair->value));
} else {
belle_sip_warning("unknown contact param \%s",(const char *)$contact_extension.text->chars);
}
belle_sip_param_pair_unref(pair);
};
/*
delta_seconds
: DIGIT+;*/
...
...
@@ -386,18 +402,32 @@ error_uri
expires
: 'Expires' HCOLON delta_seconds;
from
: ( 'From' | 'f' ) HCOLON from_spec;
*/
from_token: {strcmp("From",(const char*)(INPUT->toStringTT(INPUT,LT(1),LT(4)))->chars) == 0}? token;
header_from
scope { belle_sip_header_from_t* current; }
@init { $header_from::current = belle_sip_header_from_new(); }
: from_token/* ( 'From' | 'f' )*/ HCOLON from_spec;
from_spec
: ( name_addr
| addr_spec
)
: ( name_addr
[$header_from::current] | addr_spec[$header_from::current]
)
( SEMI from_param )*;
from_param
: tag_param | generic_param;
: /*tag_param |*/ generic_param {belle_sip_param_pair_t* pair = $generic_param.ret ;
if (strcmp("tag",pair->name) == 0) {
belle_sip_header_from_set_tag($header_contact::current,pair->value);
} else {
belle_sip_warning("unknown from param \%s",(const char *)$from_param.text->chars);
}
belle_sip_param_pair_unref(pair);
}
;
/*
tag_param
: 'tag' EQUAL token;
*/
/*
in_reply_to
: 'In-Reply-To' HCOLON callid (COMMA callid);
...
...
src/belle_sip_utils.c
View file @
32f03c56
...
...
@@ -19,7 +19,7 @@
#include "belle_sip_internal.h"
#include <time.h>
#include "clock_gettime.h"
/*for apple*/
static
FILE
*
__log_file
=
0
;
...
...
@@ -435,6 +435,7 @@ uint64_t belle_sip_time_ms(void){
return
0
;
}
return
(
ts
.
tv_sec
*
1000LL
)
+
(
ts
.
tv_nsec
/
1000000LL
);
}
...
...
@@ -446,8 +447,8 @@ uint64_t belle_sip_time_ms(void){
belle_sip_param_pair_t
*
belle_sip_param_pair_new
(
const
char
*
name
,
const
char
*
value
)
{
belle_sip_param_pair_t
*
lPair
=
(
belle_sip_param_pair_t
*
)
belle_sip_new0
(
belle_sip_param_pair_t
);
lPair
->
name
=
strdup
(
name
);
lPair
->
value
=
strdup
(
value
);
lPair
->
name
=
name
?
belle_sip_
strdup
(
name
)
:
NULL
;
lPair
->
value
=
value
?
belle_sip_
strdup
(
value
)
:
NULL
;
return
lPair
;
}
...
...
src/clock_gettime.c
0 → 100644
View file @
32f03c56
/*
* Copyright (c), MM Weiss
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. Neither the name of the MM Weiss nor the names of its contributors
* may be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* clock_gettime_stub.c
* gcc -Wall -c clock_gettime_stub.c
* posix realtime functions; MacOS user space glue
*/
/* @comment
* other possible implementation using intel builtin rdtsc
* rdtsc-workaround: http://www.mcs.anl.gov/~kazutomo/rdtsc.html
*
* we could get the ticks by doing this
*
* __asm __volatile("mov %%ebx, %%esi\n\t"
* "cpuid\n\t"
* "xchg %%esi, %%ebx\n\t"
* "rdtsc"
* : "=a" (a),
* "=d" (d)
* );
* we could even replace our tricky sched_yield call by assembly code to get a better accurency,
* anyway the following C stub will satisfy 99% of apps using posix clock_gettime call,
* moreover, the setter version (clock_settime) could be easly written using mach primitives:
* http://www.opensource.apple.com/source/xnu/xnu-${VERSION}/osfmk/man/ (clock_[set|get]_time)
*
* hackers don't be crackers, don't you use a flush toilet?
*
*
* @see draft: ./posix-realtime-stub/posix-realtime-stub.c
*
*/
#ifdef __APPLE__
#pragma weak clock_gettime
#include <sys/time.h>
#include <sys/resource.h>
#include <mach/mach.h>
#include <mach/clock.h>
#include <mach/mach_time.h>
#include <errno.h>
#include <unistd.h>
#include <sched.h>
#include "clock_gettime.h"
static
mach_timebase_info_data_t
__clock_gettime_inf
;
int
clock_gettime
(
clockid_t
clk_id
,
struct
timespec
*
tp
)
{
kern_return_t
ret
;
clock_serv_t
clk
;
clock_id_t
clk_serv_id
;
mach_timespec_t
tm
;
uint64_t
start
,
end
,
delta
,
nano
;
task_basic_info_data_t
tinfo
;
task_thread_times_info_data_t
ttinfo
;
mach_msg_type_number_t
tflag
;
int
retval
=
-
1
;
switch
(
clk_id
)
{
case
CLOCK_REALTIME
:
case
CLOCK_MONOTONIC
:
clk_serv_id
=
clk_id
==
CLOCK_REALTIME
?
CALENDAR_CLOCK
:
SYSTEM_CLOCK
;
if
(
KERN_SUCCESS
==
(
ret
=
host_get_clock_service
(
mach_host_self
(),
clk_serv_id
,
&
clk
)))
{
if
(
KERN_SUCCESS
==
(
ret
=
clock_get_time
(
clk
,
&
tm
)))
{
tp
->
tv_sec
=
tm
.
tv_sec
;
tp
->
tv_nsec
=
tm
.
tv_nsec
;
retval
=
0
;
}
}
if
(
KERN_SUCCESS
!=
ret
)
{
errno
=
EINVAL
;
retval
=
-
1
;
}
break
;
case
CLOCK_PROCESS_CPUTIME_ID
:
case
CLOCK_THREAD_CPUTIME_ID
:
start
=
mach_absolute_time
();
if
(
clk_id
==
CLOCK_PROCESS_CPUTIME_ID
)
{
getpid
();
}
else
{
sched_yield
();
}
end
=
mach_absolute_time
();
delta
=
end
-
start
;
if
(
0
==
__clock_gettime_inf
.
denom
)
{
mach_timebase_info
(
&
__clock_gettime_inf
);
}
nano
=
delta
*
__clock_gettime_inf
.
numer
/
__clock_gettime_inf
.
denom
;
tp
->
tv_sec
=
nano
*
1e-9
;
tp
->
tv_nsec
=
nano
-
(
tp
->
tv_sec
*
1e9
);
retval
=
0
;
break
;
default:
errno
=
EINVAL
;
retval
=
-
1
;
}
return
retval
;
}
#endif // __APPLE__
/* EOF */
src/clock_gettime.h
0 → 100644
View file @
32f03c56
/*
belle-sip - SIP (RFC3261) library.
Copyright (C) 2010 Belledonne Communications SARL
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef CLOCK_GETTIME_H_
#define CLOCK_GETTIME_H_
#ifdef __APPLE__
typedef
enum
{
CLOCK_REALTIME
,
CLOCK_MONOTONIC
,
CLOCK_PROCESS_CPUTIME_ID
,
CLOCK_THREAD_CPUTIME_ID
}
clockid_t
;
int
clock_gettime
(
clockid_t
clk_id
,
struct
timespec
*
tp
)
;
#endif
#endif
/* CLOCK_GETTIME_H_ */
tester/belle_sip_headers_tester.c
View file @
32f03c56
...
...
@@ -41,9 +41,9 @@ void test_simple_header_contact(void) {
belle_sip_header_contact_delete
(
L_contact
);
}
void
test_complex_header_contact
_with
(
void
)
{
void
test_complex_header_contact
(
void
)
{
belle_sip_header_contact_t
*
L_contact
=
belle_sip_header_contact_parse
(
"Contact:
\"
jremis
\"
<sip:titi.com>;expires=3600;
q=0.7"
);
belle_sip_header_contact_t
*
L_contact
=
belle_sip_header_contact_parse
(
"Contact:
\"
jremis
\"
<sip:titi.com>;expires=3600;q=0.7"
);
belle_sip_uri_t
*
L_uri
=
belle_sip_header_address_get_uri
((
belle_sip_header_address_t
*
)
L_contact
);
CU_ASSERT_PTR_NOT_NULL
(
L_uri
);
...
...
@@ -55,6 +55,12 @@ void test_complex_header_contact_with(void) {
CU_ASSERT_EQUAL
(
belle_sip_header_contact_get_qvalue
(
L_contact
),
0
.
7
);
belle_sip_header_contact_delete
(
L_contact
);
L_contact
=
belle_sip_header_contact_parse
(
"Contact: toto <sip:titi.com>;expires=3600; q=0.7"
);
CU_ASSERT_STRING_EQUAL
(
belle_sip_header_address_get_displayname
((
belle_sip_header_address_t
*
)
L_contact
),
"toto"
);
belle_sip_header_contact_delete
(
L_contact
);
}
...
...
@@ -70,5 +76,8 @@ int belle_sip_headers_test_suite() {
if
(
NULL
==
CU_add_test
(
pSuite
,
"test of simple contact header"
,
test_simple_header_contact
))
{
return
CU_get_error
();
}
if
(
NULL
==
CU_add_test
(
pSuite
,
"test of complex contact header"
,
test_complex_header_contact
))
{
return
CU_get_error
();
}
}
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