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
f74ba236
Commit
f74ba236
authored
Sep 09, 2011
by
Simon Morlat
Browse files
first message sent !
parent
51810110
Changes
11
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
169 additions
and
47 deletions
+169
-47
configure.ac
configure.ac
+13
-1
include/belle-sip/belle-sip.h
include/belle-sip/belle-sip.h
+6
-0
include/belle-sip/utils.h
include/belle-sip/utils.h
+53
-0
src/Makefile.am
src/Makefile.am
+0
-2
src/belle_sdp.g
src/belle_sdp.g
+2
-2
src/belle_sip_internal.h
src/belle_sip_internal.h
+2
-21
src/belle_sip_resolver.c
src/belle_sip_resolver.c
+33
-17
src/belle_sip_uri_impl.c
src/belle_sip_uri_impl.c
+1
-1
src/listeningpoint.c
src/listeningpoint.c
+1
-1
tester/basic_test.c
tester/basic_test.c
+56
-0
tester/belle_sdp_tester.c
tester/belle_sdp_tester.c
+2
-2
No files found.
configure.ac
View file @
f74ba236
...
...
@@ -19,7 +19,19 @@ else
use_rpm=true;
fi
CFLAGS="-g -O2"
AC_ARG_ENABLE(debug,
[ --enable-debug Turn on debug mode (default=yes)],
[case "${enableval}" in
yes) debug=true ;;
no) debug=false ;;
*) AC_MSG_ERROR(bad value ${enableval} for --enable-debug) ;;
esac],[debug=true])
if test "$debug" = "no" ; then
CFLAGS="-g -O2"
else
CFLAGS="-g"
fi
if test x$GCC = xyes ; then
STRICT_OPTIONS=" -Wall -Werror"
...
...
include/belle-sip/belle-sip.h
View file @
f74ba236
...
...
@@ -160,6 +160,7 @@ typedef struct belle_sip_provider belle_sip_provider_t;
typedef
struct
belle_sip_listener
belle_sip_listener_t
;
typedef
struct
belle_sip_dialog
belle_sip_dialog_t
;
#include "belle-sip/utils.h"
#include "belle-sip/list.h"
#include "belle-sip/mainloop.h"
#include "belle-sip/uri.h"
...
...
@@ -180,4 +181,9 @@ typedef struct belle_sip_dialog belle_sip_dialog_t;
#undef FALSE
#define FALSE 0
#define BELLE_SIP_POINTER_TO_INT(p) ((int)(long)(p))
#define BELLE_SIP_INT_TO_POINTER(i) ((void*)(long)(i))
#endif
include/belle-sip/utils.h
0 → 100644
View file @
f74ba236
/*
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 BELLE_SIP_UTILS_H
#define BELLE_SIP_UTILS_H
#include <stdarg.h>
#include <stdio.h>
/***************/
/* logging api */
/***************/
typedef
enum
{
BELLE_SIP_DEBUG
=
1
,
BELLE_SIP_MESSAGE
=
1
<<
1
,
BELLE_SIP_WARNING
=
1
<<
2
,
BELLE_SIP_ERROR
=
1
<<
3
,
BELLE_SIP_FATAL
=
1
<<
4
,
BELLE_SIP_LOGLEV_END
=
1
<<
5
}
belle_sip_log_level
;
#define BELLE_SIP_LOG_ALL (0xffff)
typedef
void
(
*
belle_sip_log_function_t
)(
belle_sip_log_level
lev
,
const
char
*
fmt
,
va_list
args
);
BELLE_SIP_BEGIN_DECLS
void
belle_sip_set_log_file
(
FILE
*
file
);
void
belle_sip_set_log_handler
(
belle_sip_log_function_t
func
);
void
belle_sip_set_log_level_mask
(
int
levelmask
);
BELLE_SIP_END_DECLS
#endif
src/Makefile.am
View file @
f74ba236
...
...
@@ -5,8 +5,6 @@ grammar_files= \
$(srcdir)
/belle_sdp.g
generated_src
=
\
belle_sip_uriParser.c belle_sip_uriParser.h
\
belle_sip_uriLexer.c belle_sip_uriLexer.h
\
belle_sip_messageParser.c belle_sip_messageParser.h
\
belle_sip_messageLexer.c belle_sip_messageLexer.h
\
belle_sdpParser.c belle_sdpParser.h
\
...
...
src/belle_sdp.g
View file @
f74ba236
...
...
@@ -144,7 +144,7 @@ media_value: alpha_num+;
fmt: DIGIT+ {belle_sdp_media_set_media_formats($media::current
,belle_sip_list_append(belle_sdp_media_get_media_formats($media::current)
,(void*)atoi((const char*)$fmt.text->chars)));};
,(void*)
(long)
atoi((const char*)$fmt.text->chars)));};
//;typically an RTP payload type for audio
//;and video media
proto options { greedy = false; }: ~(SPACE|CR|LF)*;
...
...
src/belle_sip_internal.h
View file @
f74ba236
...
...
@@ -20,7 +20,7 @@
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdint.h>
#include <errno.h>
...
...
@@ -149,24 +149,6 @@ belle_sip_list_t *belle_sip_list_remove_custom(belle_sip_list_t *list, belle_sip
belle_sip_list_t
*
belle_sip_list_delete_custom
(
belle_sip_list_t
*
list
,
belle_sip_compare_func
compare_func
,
const
void
*
user_data
);
belle_sip_list_t
*
belle_sip_list_free
(
belle_sip_list_t
*
list
);
#define belle_sip_list_next(elem) ((elem)->next)
/***************/
/* logging api */
/***************/
typedef
enum
{
BELLE_SIP_DEBUG
=
1
,
BELLE_SIP_MESSAGE
=
1
<<
1
,
BELLE_SIP_WARNING
=
1
<<
2
,
BELLE_SIP_ERROR
=
1
<<
3
,
BELLE_SIP_FATAL
=
1
<<
4
,
BELLE_SIP_LOGLEV_END
=
1
<<
5
}
belle_sip_log_level
;
typedef
void
(
*
belle_sip_log_function_t
)(
belle_sip_log_level
lev
,
const
char
*
fmt
,
va_list
args
);
void
belle_sip_set_log_file
(
FILE
*
file
);
void
belle_sip_set_log_handler
(
belle_sip_log_function_t
func
);
extern
belle_sip_log_function_t
belle_sip_logv_out
;
...
...
@@ -185,7 +167,6 @@ extern unsigned int __belle_sip_log_mask;
void
belle_sip_logv
(
int
level
,
const
char
*
fmt
,
va_list
args
);
#endif
void
belle_sip_set_log_level_mask
(
int
levelmask
);
#ifdef BELLE_SIP_DEBUG_MODE
static
inline
void
belle_sip_debug
(
const
char
*
fmt
,...)
...
...
@@ -284,7 +265,7 @@ char *belle_sip_strdup_printf(const char *fmt,...);
const char* object_type##_get_##func_name (const object_type##_t* obj) {\
const char* l_value = belle_sip_parameters_get_parameter(BELLE_SIP_PARAMETERS(obj),#attribute);\
if (l_value == NULL) { \
belle_sip_warning("cannot find parameters [%s]",#attribute);\
/*
belle_sip_warning("cannot find parameters [%s]",#attribute);
*/
\
return NULL;\
}\
return l_value;\
...
...
src/belle_sip_resolver.c
View file @
f74ba236
...
...
@@ -18,6 +18,35 @@
#include "belle_sip_resolver.h"
int
belle_sip_addrinfo_to_ip
(
const
struct
addrinfo
*
ai
,
char
*
ip
,
size_t
ip_size
,
int
*
port
){
char
serv
[
16
];
int
err
=
getnameinfo
(
ai
->
ai_addr
,
ai
->
ai_addrlen
,
ip
,
ip_size
,
serv
,
sizeof
(
serv
),
NI_NUMERICHOST
|
NI_NUMERICSERV
);
if
(
err
!=
0
){
belle_sip_error
(
"getnameinfo() error: %s"
,
gai_strerror
(
err
));
strncpy
(
ip
,
"<bug!!>"
,
ip_size
);
}
if
(
port
)
*
port
=
atoi
(
serv
);
return
0
;
}
struct
addrinfo
*
belle_sip_ip_address_to_addrinfo
(
const
char
*
ipaddress
,
int
port
){
struct
addrinfo
*
res
=
NULL
;
struct
addrinfo
hints
=
{
0
};
char
serv
[
10
];
int
err
;
snprintf
(
serv
,
sizeof
(
serv
),
"%i"
,
port
);
hints
.
ai_family
=
AF_UNSPEC
;
hints
.
ai_flags
=
AI_NUMERICSERV
|
AI_NUMERICHOST
;
err
=
getaddrinfo
(
ipaddress
,
serv
,
&
hints
,
&
res
);
if
(
err
!=
0
){
return
NULL
;
}
return
res
;
}
void
belle_sip_resolver_context_destroy
(
belle_sip_resolver_context_t
*
ctx
){
if
(
ctx
->
thread
!=
0
){
if
(
!
ctx
->
exited
){
...
...
@@ -58,6 +87,7 @@ static void *belle_sip_resolver_thread(void *ptr){
char
serv
[
10
];
int
err
;
belle_sip_message
(
"Resolver thread started."
);
snprintf
(
serv
,
sizeof
(
serv
),
"%i"
,
ctx
->
port
);
hints
.
ai_family
=
(
ctx
->
hints
&
BELLE_SIP_RESOLVER_HINT_IPV6
)
?
AF_INET6
:
AF_INET
;
hints
.
ai_flags
=
AI_NUMERICSERV
;
...
...
@@ -65,8 +95,9 @@ static void *belle_sip_resolver_thread(void *ptr){
if
(
err
!=
0
){
belle_sip_error
(
"DNS resolution of %s failed: %s"
,
ctx
->
name
,
gai_strerror
(
err
));
}
else
{
char
tmp
[
64
];
belle_sip_message
(
"%s has address %s."
,
ctx
->
name
,
inet_ntop
(
res
->
ai_family
,
res
->
ai_addr
,
tmp
,
sizeof
(
tmp
)));
char
host
[
64
];
belle_sip_addrinfo_to_ip
(
res
,
host
,
sizeof
(
host
),
NULL
);
belle_sip_message
(
"%s has address %s."
,
ctx
->
name
,
host
);
ctx
->
ai
=
res
;
}
...
...
@@ -95,18 +126,3 @@ unsigned long belle_sip_resolve(const char *name, int port, unsigned int hints,
}
}
struct
addrinfo
*
belle_sip_ip_address_to_addrinfo
(
const
char
*
ipaddress
,
int
port
){
struct
addrinfo
*
res
=
NULL
;
struct
addrinfo
hints
=
{
0
};
char
serv
[
10
];
int
err
;
snprintf
(
serv
,
sizeof
(
serv
),
"%i"
,
port
);
hints
.
ai_family
=
AF_UNSPEC
;
hints
.
ai_flags
=
AI_NUMERICSERV
|
AI_NUMERICHOST
;
err
=
getaddrinfo
(
ipaddress
,
serv
,
&
hints
,
&
res
);
if
(
err
!=
0
){
return
NULL
;
}
return
res
;
}
src/belle_sip_uri_impl.c
View file @
f74ba236
...
...
@@ -131,7 +131,7 @@ const belle_sip_list_t* belle_sip_uri_get_header_names(const belle_sip_uri_t* ur
int
belle_sip_uri_get_listening_port
(
const
belle_sip_uri_t
*
uri
){
int
port
=
belle_sip_uri_get_port
(
uri
);
const
char
*
transport
=
belle_sip_uri_get_transport_param
(
uri
);
if
(
port
==
-
1
)
if
(
port
==
0
)
port
=
belle_sip_listening_point_get_well_known_port
(
transport
?
transport
:
"UDP"
);
return
port
;
}
...
...
src/listeningpoint.c
View file @
f74ba236
...
...
@@ -80,7 +80,7 @@ static int udp_channel_send(belle_sip_channel_t *obj, const void *buf, size_t bu
int
err
;
err
=
sendto
(
chan
->
sock
,
buf
,
buflen
,
0
,
obj
->
peer
.
ai_addr
,
obj
->
peer
.
ai_addrlen
);
if
(
err
==-
1
){
belle_sip_
error
(
"Could not send UDP packet: %s"
,
strerror
(
errno
));
belle_sip_
fatal
(
"Could not send UDP packet: %s"
,
strerror
(
errno
));
return
-
errno
;
}
return
err
;
...
...
tester/basic_test.c
0 → 100644
View file @
f74ba236
/*
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/>.
*/
#include <stdio.h>
#include "belle-sip/belle-sip.h"
int
main
(
int
argc
,
char
*
argv
[]){
belle_sip_stack_t
*
stack
=
belle_sip_stack_new
(
NULL
);
belle_sip_listening_point_t
*
lp
;
belle_sip_provider_t
*
prov
;
belle_sip_request_t
*
req
;
belle_sip_set_log_level_mask
(
BELLE_SIP_LOG_ALL
);
lp
=
belle_sip_stack_create_listening_point
(
stack
,
"0.0.0.0"
,
7060
,
"UDP"
);
prov
=
belle_sip_stack_create_provider
(
stack
,
lp
);
req
=
belle_sip_request_create
(
belle_sip_uri_parse
(
"sip:test.linphone.org"
),
"REGISTER"
,
belle_sip_provider_create_call_id
(
prov
),
belle_sip_header_cseq_create
(
20
,
"REGISTER"
),
belle_sip_header_from_create
(
"Tester <sip:tester@test.linphone.org>"
,
"a0dke45"
),
belle_sip_header_to_create
(
"Tester <sip:tester@test.linphone.org>"
,
NULL
),
belle_sip_header_via_create
(
belle_sip_listening_point_get_ip_address
(
lp
),
belle_sip_listening_point_get_port
(
lp
),
belle_sip_listening_point_get_transport
(
lp
),
"67687djeij"
),
70
);
char
*
tmp
=
belle_sip_object_to_string
(
BELLE_SIP_OBJECT
(
req
));
printf
(
"Message to send:
\n
%s
\n
"
,
tmp
);
belle_sip_free
(
tmp
);
belle_sip_provider_send_request
(
prov
,
req
);
belle_sip_main_loop_add_timeout
(
belle_sip_stack_get_main_loop
(
stack
),(
belle_sip_source_func_t
)
belle_sip_main_loop_quit
,
belle_sip_stack_get_main_loop
(
stack
),
5000
);
belle_sip_stack_main
(
stack
);
printf
(
"Exiting
\n
"
);
belle_sip_object_unref
(
BELLE_SIP_OBJECT
(
prov
));
belle_sip_object_unref
(
BELLE_SIP_OBJECT
(
stack
));
return
0
;
}
tester/belle_sdp_tester.c
View file @
f74ba236
...
...
@@ -106,7 +106,7 @@ static void test_media(void) {
int
fmt
[]
=
{
111
,
110
,
3
,
0
,
8
,
101
};
int
i
=
0
;
for
(;
list
!=
NULL
;
list
=
list
->
next
){
CU_ASSERT_EQUAL
(
(
int
)
(
list
->
data
),
fmt
[
i
++
]);
CU_ASSERT_EQUAL
(
BELLE_SIP_POINTER_TO_INT
(
list
->
data
),
fmt
[
i
++
]);
}
belle_sip_object_unref
(
BELLE_SIP_OBJECT
(
l_media
));
...
...
@@ -136,7 +136,7 @@ static void test_media_description(void) {
int
fmt
[]
=
{
99
,
97
,
98
};
int
i
=
0
;
for
(;
list
!=
NULL
;
list
=
list
->
next
){
CU_ASSERT_EQUAL
(
(
int
)
(
list
->
data
),
fmt
[
i
++
]);
CU_ASSERT_EQUAL
(
BELLE_SIP_POINTER_TO_INT
(
list
->
data
),
fmt
[
i
++
]);
}
/*connection*/
belle_sdp_connection_t
*
lConnection
=
belle_sdp_media_description_get_connection
(
l_media_description
);
...
...
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