Commit c7066e31 authored by jehan's avatar jehan
Browse files

Merge branch 'refs/heads/master' of gitosis@git.linphone.org:belle-sip

into HEAD
parents 3200c2e8 cab2edce
......@@ -3,10 +3,17 @@ bellesipdir=$(includedir)/belle-sip
bellesip_HEADERS=\
uri.h \
list.h \
headers.h \
parameters.h \
mainloop.h \
transaction.h \
message.h \
transport.h \
listeningpoint.h \
sipstack.h \
provider.h \
listener.h \
dialog.h \
belle-sip.h
EXTRA_DIST=$(bellesip_HEADERS)
......@@ -20,25 +20,46 @@
#include <stdlib.h>
#ifdef __cplusplus
#define BELLE_SIP_BEGIN_DECLS extern "C"{
#define BELLE_SIP_END_DECLS }
#else
#define BELLE_SIP_BEGIN_DECLS
#define BELLE_SIP_END_DECLS
#endif
#define BELLE_SIP_TYPE_ID(_type) _type##_id
typedef enum belle_sip_type_id{
belle_sip_type_id_first=1,
BELLE_SIP_TYPE_ID(belle_sip_stack_t),
BELLE_SIP_TYPE_ID(belle_sip_listening_point_t),
BELLE_SIP_TYPE_ID(belle_sip_datagram_listening_point_t),
BELLE_SIP_TYPE_ID(belle_sip_udp_listening_point_t),
BELLE_SIP_TYPE_ID(belle_sip_channel_t),
BELLE_SIP_TYPE_ID(belle_sip_udp_channel_t),
BELLE_SIP_TYPE_ID(belle_sip_provider_t),
BELLE_SIP_TYPE_ID(belle_sip_main_loop_t),
BELLE_SIP_TYPE_ID(belle_sip_source_t),
BELLE_SIP_TYPE_ID(belle_sip_transaction_t),
BELLE_SIP_TYPE_ID(belle_sip_server_transaction_t),
BELLE_SIP_TYPE_ID(belle_sip_client_transaction_t),
BELLE_SIP_TYPE_ID(belle_sip_transport_t),
BELLE_SIP_TYPE_ID(belle_sip_dialog_t),
BELLE_SIP_TYPE_ID(belle_sip_header_address_t),
BELLE_SIP_TYPE_ID(belle_sip_header_contact_t),
BELLE_SIP_TYPE_ID(belle_sip_header_from_t),
BELLE_SIP_TYPE_ID(belle_sip_header_to_t),
BELLE_SIP_TYPE_ID(belle_sip_header_via_t),
BELLE_SIP_TYPE_ID(belle_sip_uri_t),
BELLE_SIP_TYPE_ID(belle_sip_message_t),
BELLE_SIP_TYPE_ID(belle_sip_request_t),
BELLE_SIP_TYPE_ID(belle_sip_response_t),
BELLE_SIP_TYPE_ID(belle_sip_object_t),
BELLE_SIP_TYPE_ID(belle_sip_parameters_t),
BELLE_SIP_TYPE_ID(belle_sip_header_callid_t),
BELLE_SIP_TYPE_ID(belle_sip_header_cseq_t),
BELLE_SIP_TYPE_ID(belle_sip_header_content_type_t),
BELLE_SIP_TYPE_ID(belle_sip_sender_task_t),
belle_sip_type_id_end
}belle_sip_type_id_t;
......@@ -52,33 +73,42 @@ typedef enum belle_sip_type_id{
typedef struct _belle_sip_object belle_sip_object_t;
BELLE_SIP_BEGIN_DECLS
int belle_sip_object_is_unowed(const belle_sip_object_t *obj);
/**
* Increments reference counter, which prevents the object from being destroyed.
* If the object is initially unowed, this acquires the first reference.
**/
#define belle_sip_object_ref(obj) _belle_sip_object_ref((belle_sip_object_t*)obj)
belle_sip_object_t * _belle_sip_object_ref(belle_sip_object_t *obj);
belle_sip_object_t * belle_sip_object_ref(void *obj);
/**
* Decrements the reference counter. When it drops to zero, the object is destroyed.
**/
#define belle_sip_object_unref(obj) _belle_sip_object_unref((belle_sip_object_t*)obj)
void _belle_sip_object_unref(belle_sip_object_t *obj);
void belle_sip_object_unref(void *obj);
/**
* Destroy the object: this function is intended for unowed object, that is objects
* that were created with a 0 reference count.
**/
#define belle_sip_object_destroy(obj) _belle_sip_object_destroy((belle_sip_object_t*)obj)
void _belle_sip_object_destroy(belle_sip_object_t *obj);
void belle_sip_object_destroy(void *obj);
void *belle_sip_object_cast(belle_sip_object_t *obj, belle_sip_type_id_t id, const char *castname, const char *file, int fileno);
#define BELLE_SIP_CAST(obj,_type) (_type*)belle_sip_object_cast((belle_sip_object_t *)(obj), _type##_id, #_type, __FILE__, __LINE__)
BELLE_SIP_END_DECLS
#define BELLE_SIP_CAST(obj,_type) ((_type*)belle_sip_object_cast((belle_sip_object_t *)(obj), _type##_id, #_type, __FILE__, __LINE__))
#define BELLE_SIP_OBJECT(obj) BELLE_SIP_CAST(obj,belle_sip_object_t)
typedef struct belle_sip_listening_point belle_sip_listening_point_t;
typedef struct belle_sip_stack belle_sip_stack_t;
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/list.h"
#include "belle-sip/mainloop.h"
#include "belle-sip/uri.h"
......@@ -86,6 +116,12 @@ void *belle_sip_object_cast(belle_sip_object_t *obj, belle_sip_type_id_t id, con
#include "belle-sip/parameters.h"
#include "belle-sip/message.h"
#include "belle-sip/transaction.h"
#include "belle-sip/dialog.h"
#include "belle-sip/sipstack.h"
#include "belle-sip/listeningpoint.h"
#include "belle-sip/provider.h"
#include "belle-sip/listener.h"
#undef TRUE
#define TRUE 1
......
/*
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_dialog_h
#define belle_sip_dialog_h
enum belle_sip_dialog_state{
BELLE_SIP_DIALOG_NULL,
BELLE_SIP_DIALOG_EARLY,
BELLE_SIP_DIALOG_CONFIRMED,
BELLE_SIP_DIALOG_TERMINATED
};
typedef enum belle_sip_dialog_state belle_sip_dialog_state_t;
BELLE_SIP_BEGIN_DECLS
belle_sip_request_t *belle_sip_dialog_create_ack(belle_sip_dialog_t *dialog, unsigned int cseq);
belle_sip_request_t *belle_sip_dialog_create_request(belle_sip_dialog_t *dialog, const char *method);
void belle_sip_dialog_delete(belle_sip_dialog_t *dialog);
void *belle_sip_get_application_data(belle_sip_dialog_t *dialog);
void belle_sip_set_application_data(belle_sip_dialog_t *dialog, void *data);
const char *belle_sip_dialog_get_dialog_id(belle_sip_dialog_t *dialog);
const belle_sip_header_address_t *belle_sip_get_local_party(belle_sip_dialog_t *dialog);
const belle_sip_header_address_t *belle_sip_get_remote_party(belle_sip_dialog_t *dialog);
unsigned int belle_sip_dialog_get_local_seq_number(belle_sip_dialog_t *dialog);
unsigned int belle_sip_dialog_get_remote_seq_number(belle_sip_dialog_t *dialog);
const char *belle_sip_dialog_get_local_tag(belle_sip_dialog_t *dialog);
const char *belle_sip_dialog_get_remote_tag(belle_sip_dialog_t *dialog);
const belle_sip_header_address_t *belle_sip_dialog_get_remote_target(belle_sip_dialog_t *dialog);
const belle_sip_list_t belle_sip_dialog_get_route_set(belle_sip_dialog_t *dialog);
belle_sip_dialog_state_t belle_sip_dialog_get_state(belle_sip_dialog_t *dialog);
int belle_sip_dialog_is_server(belle_sip_dialog_t *dialog);
void belle_sip_dialog_send_ack(belle_sip_dialog_t *dialog, belle_sip_request_t *request);
void belle_sip_dialog_terminate_on_bye(belle_sip_dialog_t *dialog, int val);
BELLE_SIP_END_DECLS
#endif
/*
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_listener_h
#define belle_sip_listener_h
typedef struct belle_sip_dialog_terminated_event belle_sip_dialog_terminated_event_t;
typedef struct belle_sip_io_error_event belle_sip_io_error_event_t;
typedef struct belle_sip_request_event belle_sip_request_event_t;
typedef struct belle_sip_response_event belle_sip_response_event_t;
typedef struct belle_sip_timeout_event belle_sip_timeout_event_t;
typedef struct belle_sip_transaction_terminated_event belle_sip_transaction_terminated_event_t;
struct belle_sip_dialog_terminated_event{
belle_sip_provider_t *source;
belle_sip_dialog_t *dialog;
};
struct belle_sip_io_error_event{
belle_sip_provider_t *source;
char *transport;
char *host;
int port;
};
struct belle_sip_request_event{
belle_sip_provider_t *source;
belle_sip_server_transaction_t *server_transaction;
belle_sip_dialog_t *dialog;
belle_sip_request_t *request;
};
struct belle_sip_response_event{
belle_sip_provider_t *source;
belle_sip_client_transaction_t *client_transaction;
belle_sip_dialog_t *dialog;
belle_sip_request_t *response;
};
struct belle_sip_timeout_event{
belle_sip_provider_t *source;
belle_sip_transaction_t *transaction;
int is_server_transaction;
};
struct belle_sip_transaction_terminated_event{
belle_sip_provider_t *source;
belle_sip_transaction_t *transaction;
int is_server_transaction;
};
struct belle_sip_listener{
void (*process_dialog_terminated)(void *user_ctx, const belle_sip_dialog_terminated_event_t *event);
void (*process_io_error)(void *user_ctx, const belle_sip_io_error_event_t *event);
void (*process_request_event)(void *user_ctx, const belle_sip_request_event_t *event);
void (*process_response_event)(void *user_ctx, const belle_sip_response_event_t *event);
void (*process_timeout)(void *user_ctx, const belle_sip_timeout_event_t *event);
void (*process_transaction_terminated)(void *user_ctx, const belle_sip_transaction_terminated_event_t *event);
};
#endif
/*
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_TRANSPORT_H
#define BELLE_SIP_TRANSPORT_H
#ifndef WIN32
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#else
#endif
typedef struct belle_sip_channel belle_sip_channel_t;
BELLE_SIP_BEGIN_DECLS
/**
* belle_sip_transport_t is an object representing a single communication channel (=unix socket),
* unlike the belle_sip_listening_point_t that can owns several channels for TCP or TLS (incoming server child sockets or
* outgoing client sockets).
**/
int belle_sip_channel_send(belle_sip_channel_t *t, const void *buf, size_t buflen);
int belle_sip_channel_recv(belle_sip_channel_t *t, void *buf, size_t buflen);
const struct addrinfo * belle_sip_channel_get_peer(belle_sip_channel_t *t);
const char *belle_sip_listening_point_get_ip_address(const belle_sip_listening_point_t *lp);
int belle_sip_listening_point_get_port(const belle_sip_listening_point_t *lp);
const char *belle_sip_listening_point_get_transport(const belle_sip_listening_point_t *ip);
const char *belle_sip_listening_point_get_ip_address(const belle_sip_listening_point_t *ip);
BELLE_SIP_END_DECLS
#endif
......@@ -38,11 +38,10 @@ typedef int (*belle_sip_source_func_t)(void *user_data, unsigned int events);
typedef struct belle_sip_main_loop belle_sip_main_loop_t;
BELLE_SIP_BEGIN_DECLS
void belle_sip_main_loop_add_source(belle_sip_main_loop_t *ml, belle_sip_source_t *source);
void belle_sip_main_loop_remove_source(belle_sip_main_loop_t *ml, belle_sip_source_t *source);
/**
* Creates a mainloop.
**/
......@@ -67,6 +66,10 @@ unsigned long belle_sip_main_loop_add_timeout(belle_sip_main_loop_t *ml, belle_s
belle_sip_source_t * belle_sip_timeout_source_new(belle_sip_source_func_t func, void *data, unsigned int timeout_value_ms);
belle_sip_source_t * belle_sip_fd_source_new(belle_sip_source_func_t func, void *data, int fd, unsigned int events, unsigned int timeout_value_ms);
unsigned long belle_sip_source_get_id(belle_sip_source_t *s);
/**
* Executes the main loop forever (or until belle_sip_main_loop_quit() is called)
**/
......@@ -87,4 +90,6 @@ void belle_sip_main_loop_quit(belle_sip_main_loop_t *ml);
**/
void belle_sip_main_loop_cancel_source(belle_sip_main_loop_t *ml, unsigned long id);
BELLE_SIP_END_DECLS
#endif
......@@ -18,9 +18,21 @@
#ifndef BELLE_SIP_MESSAGE_H
#define BELLE_SIP_MESSAGE_H
typedef struct belle_sip_message bellesip_message_t;
typedef struct belle_sip_message belle_sip_message_t;
typedef struct belle_sip_request belle_sip_request_t;
typedef struct belle_sip_response belle_sip_response_t;
#define BELLE_SIP_MESSAGE(obj) BELLE_SIP_CAST(obj,belle_sip_message_t)
#define BELLE_SIP_REQUEST(obj) BELLE_SIP_CAST(obj,belle_sip_request_t)
#define BELLE_SIP_RESPONSE(obj) BELLE_SIP_CAST(obj,belle_sip_response_t)
int belle_sip_message_is_request(belle_sip_message_t *msg);
int belle_sip_message_is_response(belle_sip_message_t *msg);
belle_sip_header_t *belle_sip_message_get_header_last(belle_sip_message_t *msg, const char *header_name);
char *belle_sip_message_to_string(belle_sip_message_t *msg);
#endif
/*
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_provider_h
#define belle_sip_provider_h
BELLE_SIP_BEGIN_DECLS
int belle_sip_provider_add_listening_point(belle_sip_provider_t *p, belle_sip_listening_point_t *lp);
void belle_sip_provider_remove_listening_point(belle_sip_provider_t *p, belle_sip_listening_point_t *lp);
belle_sip_listening_point_t *belle_sip_provider_get_listening_point(belle_sip_provider_t *p, const char *transport);
const belle_sip_list_t *belle_sip_provider_get_listening_points(belle_sip_provider_t *p);
void belle_sip_provider_add_sip_listener(belle_sip_provider_t *p, belle_sip_listener_t *l, void *user_ctx);
void belle_sip_provider_remove_sip_listener(belle_sip_provider_t *p, belle_sip_listener_t *l, void *user_ctx);
belle_sip_client_transaction_t *belle_sip_provider_create_client_transaction(belle_sip_provider_t *p, belle_sip_request_t *req);
belle_sip_server_transaction_t *belle_sip_provider_create_server_transaction(belle_sip_provider_t *p, belle_sip_request_t *req);
belle_sip_stack_t *belle_sip_provider_get_sip_stack(belle_sip_provider_t *p);
void belle_sip_provider_send_request(belle_sip_provider_t *p, belle_sip_request_t *req);
void belle_sip_provider_send_response(belle_sip_provider_t *p, belle_sip_response_t *resp);
BELLE_SIP_END_DECLS
#endif
/*
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_stack_h
#define belle_sip_stack_h
struct belle_sip_hop{
const char *host;
const char *transport;
int port;
};
typedef struct belle_sip_hop belle_sip_hop_t;
BELLE_SIP_BEGIN_DECLS
belle_sip_stack_t * belle_sip_stack_new(const char *properties);
belle_sip_listening_point_t *belle_sip_stack_create_listening_point(belle_sip_stack_t *s, const char *ipaddress, int port, const char *transport);
void belle_sip_stack_delete_listening_point(belle_sip_stack_t *s, belle_sip_listening_point_t *lp);
belle_sip_provider_t *belle_sip_stack_create_provider(belle_sip_stack_t *s, belle_sip_listening_point_t *lp);
void belle_sip_stack_main(belle_sip_stack_t *stack);
void belle_sip_stack_sleep(belle_sip_stack_t *stack, unsigned int milliseconds);
BELLE_SIP_END_DECLS
#endif
......@@ -33,6 +33,7 @@ typedef enum belle_sip_transaction_state{
BELLE_SIP_TRANSACTION_TERMINATED
}belle_sip_transaction_state_t;
BELLE_SIP_BEGIN_DECLS
void *belle_sip_transaction_get_application_data(const belle_sip_transaction_t *t);
void belle_sip_transaction_set_application_data(belle_sip_transaction_t *t, void *data);
......@@ -52,11 +53,7 @@ void belle_sip_client_transaction_send_request(belle_sip_client_transaction_t *t
#define BELLE_SIP_CLIENT_TRANSACTION(t) BELLE_SIP_CAST(t,belle_sip_client_transaction_t)
/*to be moved out when belle_sip_provider_t is implemented:*/
belle_sip_client_transaction_t * belle_sip_client_transaction_new(belle_sip_request_t *req);
belle_sip_server_transaction_t * belle_sip_server_transaction_new(belle_sip_request_t *req);
BELLE_SIP_END_DECLS
#endif
/*
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_TRANSPORT_H
#define BELLE_SIP_TRANSPORT_H
typedef struct belle_sip_transport belle_sip_transport_t;
struct belle_sip_transport_class{
char *name; /*udp,tcp*/
int is_reliable;
int (*connect)(belle_sip_transport_t *t, const struct sockaddr *addr, socklen_t addrlen);
int (*recvfrom)(belle_sip_transport_t *t, void *buf, size_t buflen, struct sockaddr *addr, socklen_t *addrlen);
int (*sendto)(belle_sip_transport_t *t, const void *buf, size_t buflen, const struct sockaddr *addr, socklen_t addrlen);
/**
* Method to know if this transport is suitable for supplied transport name and address.
* Should return 1 if suitable, 0 otherwise.
**/
int (*matches)(belle_sip_transport_t *, const char *name, const struct sockaddr *addr, socklen_t addrlen);
void (*close)(belle_sip_transport_t *);
};
typedef struct belle_sip_transport_class belle_sip_transport_class_t;
struct belle_sip_transport{
int magic;
belle_sip_transport_class_t *klass;
int refcnt;
};
const char *belle_sip_transport_get_name(const belle_sip_transport_t *t);
int belle_sip_transport_is_reliable(const belle_sip_transport_t *t);
int belle_sip_transport_matches(belle_sip_transport_t *t, const char *name, const struct sockaddr *addr, socklen_t addrlen);
int belle_sip_transport_sendto(belle_sip_transport_t *t, const void *buf, size_t buflen, const struct sockaddr *addr, socklen_t addrlen);
int belle_sip_transport_recvfrom(belle_sip_transport_t *t, void *buf, size_t buflen, struct sockaddr *addr, socklen_t *addrlen);
void belle_sip_transport_ref(belle_sip_transport_t *t);
void belle_sip_transport_unref(belle_sip_transport_t *t);
BELLE_SIP_DECLARE_CAST(belle_sip_transport_t);
#define BELLE_SIP_TRANSPORT(obj) BELLE_SIP_CAST(obj,belle_sip_transport_t)
#endif
......@@ -10,8 +10,12 @@ generated_src= \
belle_sip_messageParser.c belle_sip_messageParser.h \
belle_sip_messageLexer.c belle_sip_messageLexer.h
$(generated_src) : $(grammar_files)
$(builddir)/generated_src_stamp : $(grammar_files)
$(ANTLR) -make -fo $(builddir) $(grammar_files)
touch $(builddir)/generated_src_stamp
$(generated_src) : $(builddir)/generated_src_stamp
BUILT_SOURCES=$(generated_src)
......@@ -24,13 +28,20 @@ libbellesip_generated_la_CFLAGS=$(LESS_STRICT_OPTIONS)
lib_LTLIBRARIES=libbellesip.la
libbellesip_la_SOURCES=belle_sip_uri_impl.c \
libbellesip_la_SOURCES=clock_gettime.h \
belle_sip_uri_impl.c \
belle_sip_headers_impl.c \
belle_sip_utils.c belle_sip_internal.h \
belle_sip_object.c \
belle_sip_loop.c \
belle_sip_resolver.c belle_sip_resolver.h \
transaction.c
belle_sip_parameters.c \
transaction.c \
listeningpoint.c \
sipstack.c \
provider.c \
sender_task.c sender_task.h \
message.c