Commit bbb58199 authored by Simon Morlat's avatar Simon Morlat

transactions - work in progress

parent ce989ef4
......@@ -47,6 +47,10 @@ BELLE_SIP_DECLARE_TYPES_BEGIN(belle_sip,1)
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_ict_t),
BELLE_SIP_TYPE_ID(belle_sip_nict_t),
BELLE_SIP_TYPE_ID(belle_sip_ist_t),
BELLE_SIP_TYPE_ID(belle_sip_nist_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),
......@@ -113,32 +117,22 @@ char * belle_sip_strdup(const char *s);
BELLE_SIP_END_DECLS
/*these types are declared here because they are widely used in many headers included after*/
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_dialog belle_sip_dialog_t;
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;
BELLE_SIP_DECLARE_INTERFACE_BEGIN(belle_sip_listener_t)
void (*process_dialog_terminated)(belle_sip_listener_t *user_ctx, const belle_sip_dialog_terminated_event_t *event);
void (*process_io_error)(belle_sip_listener_t *user_ctx, const belle_sip_io_error_event_t *event);
void (*process_request_event)(belle_sip_listener_t *user_ctx, const belle_sip_request_event_t *event);
void (*process_response_event)(belle_sip_listener_t *user_ctx, const belle_sip_response_event_t *event);
void (*process_timeout)(belle_sip_listener_t *user_ctx, const belle_sip_timeout_event_t *event);
void (*process_transaction_terminated)(belle_sip_listener_t *user_ctx, const belle_sip_transaction_terminated_event_t *event);
BELLE_SIP_DECLARE_INTERFACE_END
typedef struct belle_sip_transaction belle_sip_transaction_t;
typedef struct belle_sip_server_transaction belle_sip_server_transaction_t;
typedef struct belle_sip_client_transaction belle_sip_client_transaction_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;
#include "belle-sip/utils.h"
#include "belle-sip/list.h"
#include "belle-sip/listener.h"
#include "belle-sip/mainloop.h"
#include "belle-sip/uri.h"
#include "belle-sip/headers.h"
......@@ -148,7 +142,6 @@ BELLE_SIP_DECLARE_INTERFACE_END
#include "belle-sip/dialog.h"
#include "belle-sip/sipstack.h"
#include "belle-sip/listeningpoint.h"
#include "belle-sip/listener.h"
#include "belle-sip/provider.h"
......
......@@ -20,7 +20,23 @@
#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;
BELLE_SIP_DECLARE_INTERFACE_BEGIN(belle_sip_listener_t)
void (*process_dialog_terminated)(belle_sip_listener_t *user_ctx, const belle_sip_dialog_terminated_event_t *event);
void (*process_io_error)(belle_sip_listener_t *user_ctx, const belle_sip_io_error_event_t *event);
void (*process_request_event)(belle_sip_listener_t *user_ctx, const belle_sip_request_event_t *event);
void (*process_response_event)(belle_sip_listener_t *user_ctx, const belle_sip_response_event_t *event);
void (*process_timeout)(belle_sip_listener_t *user_ctx, const belle_sip_timeout_event_t *event);
void (*process_transaction_terminated)(belle_sip_listener_t *user_ctx, const belle_sip_transaction_terminated_event_t *event);
BELLE_SIP_DECLARE_INTERFACE_END
#define BELLE_SIP_LISTENER(obj) BELLE_SIP_INTERFACE_CAST(obj,belle_sip_listener_t)
struct belle_sip_dialog_terminated_event{
belle_sip_provider_t *source;
......
......@@ -18,9 +18,7 @@
#ifndef BELLE_SIP_MESSAGE_H
#define BELLE_SIP_MESSAGE_H
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)
......
......@@ -28,12 +28,46 @@
typedef unsigned int belle_sip_type_id_t;
#define BELLE_SIP_DECLARE_TYPES_BEGIN(namezpace,unique_namespace_id) \
enum namezspace##type_ids{\
namezspace##type_id_first=unique_namespace_id,
enum namezpace##type_ids{\
namezpace##type_id_first=unique_namespace_id,
#define BELLE_SIP_DECLARE_TYPES_END };
#define BELLE_SIP_OBJECT_VPTR_NAME(object_type) object_type##_vptr
#define BELLE_SIP_OBJECT_VPTR_TYPE(object_type) object_type##_vptr_t
#define BELLE_SIP_DECLARE_VPTR(object_type) \
typedef belle_sip_object_vptr_t BELLE_SIP_OBJECT_VPTR_TYPE(object_type);\
extern BELLE_SIP_OBJECT_VPTR_TYPE(object_type) BELLE_SIP_OBJECT_VPTR_NAME(object_type);
#define BELLE_SIP_DECLARE_CUSTOM_VPTR_BEGIN(object_type, parent_type) \
typedef struct object_type##_vptr_struct BELLE_SIP_OBJECT_VPTR_TYPE(object_type);\
extern BELLE_SIP_OBJECT_VPTR_TYPE(object_type) BELLE_SIP_OBJECT_VPTR_NAME(object_type);\
struct object_type##_vptr_struct{\
BELLE_SIP_OBJECT_VPTR_TYPE(parent_type) base;
#define BELLE_SIP_DECLARE_CUSTOM_VPTR_END };
#define BELLE_SIP_INSTANCIATE_CUSTOM_VPTR(object_type) \
BELLE_SIP_OBJECT_VPTR_TYPE(object_type) BELLE_SIP_OBJECT_VPTR_NAME(object_type)
#define BELLE_SIP_VPTR_INIT(object_type,parent_type,unowned) \
BELLE_SIP_TYPE_ID(object_type), \
#object_type,\
unowned,\
(belle_sip_object_vptr_t*)&BELLE_SIP_OBJECT_VPTR_NAME(parent_type), \
(belle_sip_interface_desc_t**)object_type##interfaces_table
#define BELLE_SIP_INSTANCIATE_VPTR(object_type,parent_type,destroy,clone,marshal,unowned) \
BELLE_SIP_OBJECT_VPTR_TYPE(object_type) BELLE_SIP_OBJECT_VPTR_NAME(object_type)={ \
BELLE_SIP_VPTR_INIT(object_type,parent_type,unowned), \
(belle_sip_object_destroy_t)destroy, \
(belle_sip_object_clone_t)clone, \
(belle_sip_object_marshal_t)marshal\
}
/**
* belle_sip_object_t is the base object.
......@@ -43,9 +77,44 @@ typedef unsigned int belle_sip_type_id_t;
**/
typedef struct _belle_sip_object belle_sip_object_t;
typedef void (*belle_sip_object_destroy_t)(belle_sip_object_t*);
typedef void (*belle_sip_object_clone_t)(belle_sip_object_t* obj, const belle_sip_object_t *orig);
typedef int (*belle_sip_object_marshal_t)(belle_sip_object_t* obj, char* buff,unsigned int offset,size_t buff_size);
struct _belle_sip_object_vptr{
belle_sip_type_id_t id;
const char *type_name;
int initially_unowned;
struct _belle_sip_object_vptr *parent;
struct belle_sip_interface_desc **interfaces; /*NULL terminated table of */
belle_sip_object_destroy_t destroy;
belle_sip_object_clone_t clone;
belle_sip_object_marshal_t marshal;
};
typedef struct _belle_sip_object_vptr belle_sip_object_vptr_t;
extern belle_sip_object_vptr_t belle_sip_object_t_vptr;
struct _belle_sip_object{
belle_sip_object_vptr_t *vptr;
size_t size;
int ref;
char* name;
struct weak_ref *weak_refs;
};
BELLE_SIP_BEGIN_DECLS
belle_sip_object_t * _belle_sip_object_new(size_t objsize, belle_sip_object_vptr_t *vptr);
#define belle_sip_object_new(_type) (_type*)_belle_sip_object_new(sizeof(_type),(belle_sip_object_vptr_t*)&BELLE_SIP_OBJECT_VPTR_NAME(_type))
int belle_sip_object_is_unowed(const belle_sip_object_t *obj);
/**
......@@ -112,7 +181,6 @@ int belle_sip_object_is_instance_of(belle_sip_object_t * obj,belle_sip_type_id_t
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_IMPLEMENTS(obj,_iface) belle_sip_object_implements((belle_sip_object_t*)obj,_iface##_id)
#define BELLE_SIP_OBJECT(obj) BELLE_SIP_CAST(obj,belle_sip_object_t)
#define BELLE_SIP_IS_INSTANCE_OF(obj,_type) belle_sip_object_is_instance_of((belle_sip_object_t*)obj,_type##_id)
......@@ -141,6 +209,8 @@ BELLE_SIP_END_DECLS
#define BELLE_SIP_INTERFACE_CAST(obj,_iface) ((_iface*)belle_sip_object_interface_cast((belle_sip_object_t*)(obj),_iface##_id,#_iface,__FILE__,__LINE__))
#define BELLE_SIP_IMPLEMENTS(obj,_iface) belle_sip_object_implements((belle_sip_object_t*)obj,_iface##_id)
typedef struct belle_sip_interface_desc{
belle_sip_interface_id_t id;
......@@ -156,6 +226,33 @@ typedef struct belle_sip_interface_desc{
#define BELLE_SIP_DECLARE_INTERFACE_END };
#define BELLE_SIP_IMPLEMENT_INTERFACE_BEGIN(object_type,interface_name) \
static BELLE_SIP_INTERFACE_METHODS_TYPE(interface_name) methods_##object_type##_##interface_name={\
{ BELLE_SIP_INTERFACE_ID(interface_name),\
#interface_name },
#define BELLE_SIP_IMPLEMENT_INTERFACE_END };
#define BELLE_SIP_DECLARE_NO_IMPLEMENTED_INTERFACES(object_type)\
static belle_sip_interface_desc_t * object_type##interfaces_table[]={\
NULL \
}
#define BELLE_SIP_DECLARE_IMPLEMENTED_INTERFACES_1(object_type,iface1) \
static belle_sip_interface_desc_t * object_type##interfaces_table[]={\
(belle_sip_interface_desc_t*)&methods_##object_type##_##iface1, \
NULL \
}
#define BELLE_SIP_DECLARE_IMPLEMENTED_INTERFACES_2(object_type,iface1,iface2) \
static belle_sip_interface_desc_t * object_type##interfaces_table[]={\
(belle_sip_interface_desc_t*)&methods_##object_type##_##iface1, \
(belle_sip_interface_desc_t*)&methods_##object_type##_##iface2, \
NULL \
}
#endif
......@@ -18,11 +18,6 @@
#ifndef BELLE_SIP_TRANSACTION_H
#define BELLE_SIP_TRANSACTION_H
typedef struct belle_sip_transaction belle_sip_transaction_t;
typedef struct belle_sip_server_transaction belle_sip_server_transaction_t;
typedef struct belle_sip_client_transaction belle_sip_client_transaction_t;
typedef enum belle_sip_transaction_state{
BELLE_SIP_TRANSACTION_INIT,
......
......@@ -27,11 +27,11 @@
/***************/
typedef enum {
BELLE_SIP_LOG_DEBUG=1,
BELLE_SIP_LOG_MESSAGE=1<<1,
BELLE_SIP_LOG_WARNING=1<<2,
BELLE_SIP_LOG_ERROR=1<<3,
BELLE_SIP_LOG_FATAL=1<<4,
BELLE_SIP_LOG_FATAL=1,
BELLE_SIP_LOG_ERROR=1<<1,
BELLE_SIP_LOG_WARNING=1<<2,
BELLE_SIP_LOG_MESSAGE=1<<3,
BELLE_SIP_LOG_DEBUG=1<<4,
BELLE_SIP_LOG_END=1<<5
} belle_sip_log_level;
......
......@@ -27,7 +27,7 @@ libbellesip_generated_la_CFLAGS=$(LESS_STRICT_OPTIONS) $(ANTLR_CFLAGS)
lib_LTLIBRARIES=libbellesip.la
libbellesip_la_SOURCES=clock_gettime.h \
libbellesip_la_SOURCES= clock_gettime.c clock_gettime.h \
belle_sip_uri_impl.c \
belle_sip_headers_impl.c \
belle_sip_utils.c belle_sip_internal.h \
......@@ -43,7 +43,8 @@ libbellesip_la_SOURCES=clock_gettime.h \
channel.c channel.h \
message.c \
md5.c \
auth_helper.c
auth_helper.c \
ict.c
libbellesip_la_CFLAGS=$(STRICT_OPTIONS) $(ANTLR_CFLAGS)
......
......@@ -35,85 +35,6 @@
/* include all public headers*/
#include "belle-sip/belle-sip.h"
typedef void (*belle_sip_object_destroy_t)(belle_sip_object_t*);
typedef void (*belle_sip_object_clone_t)(belle_sip_object_t* obj, const belle_sip_object_t *orig);
typedef int (*belle_sip_object_marshal_t)(belle_sip_object_t* obj, char* buff,unsigned int offset,size_t buff_size);
struct _belle_sip_object_vptr{
belle_sip_type_id_t id;
const char *type_name;
int initially_unowned;
struct _belle_sip_object_vptr *parent;
belle_sip_interface_desc_t **interfaces; /*NULL terminated table of */
belle_sip_object_destroy_t destroy;
belle_sip_object_clone_t clone;
belle_sip_object_marshal_t marshal;
};
typedef struct _belle_sip_object_vptr belle_sip_object_vptr_t;
extern belle_sip_object_vptr_t belle_sip_object_t_vptr;
#define BELLE_SIP_OBJECT_VPTR_NAME(object_type) object_type##_vptr
#define BELLE_SIP_OBJECT_VPTR_TYPE(object_type) object_type##_vptr_t
#define BELLE_SIP_DECLARE_VPTR(object_type) \
typedef belle_sip_object_vptr_t BELLE_SIP_OBJECT_VPTR_TYPE(object_type);\
extern BELLE_SIP_OBJECT_VPTR_TYPE(object_type) BELLE_SIP_OBJECT_VPTR_NAME(object_type);
#define BELLE_SIP_DECLARE_CUSTOM_VPTR_BEGIN(object_type, parent_type) \
typedef struct object_type##_vptr_struct BELLE_SIP_OBJECT_VPTR_TYPE(object_type);\
extern BELLE_SIP_OBJECT_VPTR_TYPE(object_type) BELLE_SIP_OBJECT_VPTR_NAME(object_type);\
struct object_type##_vptr_struct{\
BELLE_SIP_OBJECT_VPTR_TYPE(parent_type) base;
#define BELLE_SIP_DECLARE_CUSTOM_VPTR_END };
#define BELLE_SIP_INSTANCIATE_CUSTOM_VPTR(object_type) \
BELLE_SIP_OBJECT_VPTR_TYPE(object_type) BELLE_SIP_OBJECT_VPTR_NAME(object_type)
#define BELLE_SIP_VPTR_INIT(object_type,parent_type,unowned) \
BELLE_SIP_TYPE_ID(object_type), \
#object_type,\
unowned,\
(belle_sip_object_vptr_t*)&BELLE_SIP_OBJECT_VPTR_NAME(parent_type), \
(belle_sip_interface_desc_t**)object_type##interfaces_table
#define BELLE_SIP_INSTANCIATE_VPTR(object_type,parent_type,destroy,clone,marshal,unowned) \
BELLE_SIP_OBJECT_VPTR_TYPE(object_type) BELLE_SIP_OBJECT_VPTR_NAME(object_type)={ \
BELLE_SIP_VPTR_INIT(object_type,parent_type,unowned), \
(belle_sip_object_destroy_t)destroy, \
(belle_sip_object_clone_t)clone, \
(belle_sip_object_marshal_t)marshal\
}
#define BELLE_SIP_IMPLEMENT_INTERFACE_BEGIN(object_type,interface_name) \
static BELLE_SIP_INTERFACE_METHODS_TYPE(interface_name) methods_##object_type##_##interface_name={\
{ BELLE_SIP_INTERFACE_ID(interface_name),\
#interface_name },
#define BELLE_SIP_IMPLEMENT_INTERFACE_END };
#define BELLE_SIP_DECLARE_NO_IMPLEMENTED_INTERFACES(object_type)\
static belle_sip_interface_desc_t * object_type##interfaces_table[]={\
NULL \
}
#define BELLE_SIP_DECLARE_IMPLEMENTED_INTERFACES_1(object_type,iface1) \
static belle_sip_interface_desc_t * object_type##interfaces_table[]={\
(belle_sip_interface_desc_t*)&methods_##object_type##_##iface1, \
NULL \
}
#define BELLE_SIP_DECLARE_IMPLEMENTED_INTERFACES_2(object_type,iface1,iface2) \
static belle_sip_interface_desc_t * object_type##interfaces_table[]={\
(belle_sip_interface_desc_t*)&methods_##object_type##_##iface1, \
(belle_sip_interface_desc_t*)&methods_##object_type##_##iface2, \
NULL \
}
/*etc*/
......@@ -159,18 +80,9 @@ typedef struct weak_ref{
void *userpointer;
}weak_ref_t;
struct _belle_sip_object{
belle_sip_object_vptr_t *vptr;
size_t size;
int ref;
char* name;
weak_ref_t *weak_refs;
};
belle_sip_object_t * _belle_sip_object_new(size_t objsize, belle_sip_object_vptr_t *vptr);
void *belle_sip_object_get_interface_methods(belle_sip_object_t *obj, belle_sip_interface_id_t ifid);
#define belle_sip_object_new(_type) (_type*)_belle_sip_object_new(sizeof(_type),(belle_sip_object_vptr_t*)&BELLE_SIP_OBJECT_VPTR_NAME(_type))
#define BELLE_SIP_OBJECT_VPTR(obj,object_type) ((BELLE_SIP_OBJECT_VPTR_TYPE(object_type)*)(((belle_sip_object_t*)obj)->vptr))
#define belle_sip_object_init(obj) /*nothing*/
......@@ -184,9 +96,6 @@ BELLE_SIP_DECLARE_VPTR(belle_sip_provider_t);
BELLE_SIP_DECLARE_VPTR(belle_sip_main_loop_t);
BELLE_SIP_DECLARE_VPTR(belle_sip_source_t);
BELLE_SIP_DECLARE_VPTR(belle_sip_resolver_context_t);
BELLE_SIP_DECLARE_VPTR(belle_sip_transaction_t);
BELLE_SIP_DECLARE_VPTR(belle_sip_server_transaction_t);
BELLE_SIP_DECLARE_VPTR(belle_sip_client_transaction_t);
BELLE_SIP_DECLARE_VPTR(belle_sip_dialog_t);
BELLE_SIP_DECLARE_VPTR(belle_sip_header_address_t);
BELLE_SIP_DECLARE_VPTR(belle_sip_header_contact_t);
......@@ -534,22 +443,95 @@ struct belle_sip_transaction{
belle_sip_request_t *request;
belle_sip_response_t *prov_response;
belle_sip_response_t *final_response;
belle_sip_channel_t *channel;
char *branch_id;
belle_sip_transaction_state_t state;
uint64_t start_time;
belle_sip_source_t *timer;
int interval;
int is_reliable:1;
int is_server:1;
int is_invite:1;
void *appdata;
};
BELLE_SIP_DECLARE_VPTR(belle_sip_transaction_t)
/*
*
*
* Client transaction
*
*
*/
struct belle_sip_client_transaction{
belle_sip_transaction_t base;
};
BELLE_SIP_DECLARE_CUSTOM_VPTR_BEGIN(belle_sip_client_transaction_t,belle_sip_transaction_t)
void (*send_request)(belle_sip_client_transaction_t *);
void (*on_response)(belle_sip_client_transaction_t *obj, belle_sip_response_t *resp);
BELLE_SIP_DECLARE_CUSTOM_VPTR_END
belle_sip_client_transaction_t * belle_sip_client_transaction_new(belle_sip_provider_t *prov,belle_sip_request_t *req);
belle_sip_server_transaction_t * belle_sip_server_transaction_new(belle_sip_provider_t *prov,belle_sip_request_t *req);
void belle_sip_client_transaction_init(belle_sip_client_transaction_t *obj, belle_sip_provider_t *prov, belle_sip_request_t *req);
void belle_sip_client_transaction_add_response(belle_sip_client_transaction_t *t, belle_sip_response_t *resp);
struct belle_sip_ict{
belle_sip_client_transaction_t base;
};
typedef struct belle_sip_ict belle_sip_ict_t;
BELLE_SIP_DECLARE_CUSTOM_VPTR_BEGIN(belle_sip_ict_t,belle_sip_client_transaction_t)
BELLE_SIP_DECLARE_CUSTOM_VPTR_END
belle_sip_ict_t * belle_sip_ict_new(belle_sip_provider_t *prov, belle_sip_request_t *req);
struct belle_sip_nict{
belle_sip_client_transaction_t base;
};
typedef struct belle_sip_nict belle_sip_nict_t;
BELLE_SIP_DECLARE_CUSTOM_VPTR_BEGIN(belle_sip_nict_t,belle_sip_client_transaction_t)
BELLE_SIP_DECLARE_CUSTOM_VPTR_END
belle_sip_nict_t * belle_sip_nict_new(belle_sip_provider_t *prov, belle_sip_request_t *req);
/*
*
*
* Server transaction
*
*
*/
struct belle_sip_server_transaction{
belle_sip_transaction_t base;
};
BELLE_SIP_DECLARE_CUSTOM_VPTR_BEGIN(belle_sip_server_transaction_t,belle_sip_transaction_t)
BELLE_SIP_DECLARE_CUSTOM_VPTR_END
struct belle_sip_ist{
belle_sip_server_transaction_t base;
};
typedef struct belle_sip_ist belle_sip_ist_t;
BELLE_SIP_DECLARE_CUSTOM_VPTR_BEGIN(belle_sip_ist_t,belle_sip_server_transaction_t)
BELLE_SIP_DECLARE_CUSTOM_VPTR_END
belle_sip_ist_t * belle_sip_ist_new(belle_sip_provider_t *prov, belle_sip_request_t *req);
struct belle_sip_nist{
belle_sip_server_transaction_t base;
};
typedef struct belle_sip_nist belle_sip_nist_t;
BELLE_SIP_DECLARE_CUSTOM_VPTR_BEGIN(belle_sip_nist_t,belle_sip_server_transaction_t)
BELLE_SIP_DECLARE_CUSTOM_VPTR_END
belle_sip_nist_t * belle_sip_nist_new(belle_sip_provider_t *prov, belle_sip_request_t *req);
/*
belle_sip_response_t
*/
......
......@@ -98,6 +98,8 @@ const struct addrinfo * belle_sip_channel_get_peer(belle_sip_channel_t *obj);
const char *belle_sip_channel_get_local_address(belle_sip_channel_t *obj, int *port);
#define belle_sip_channel_get_state(chan) ((chan)->state)
/*just invokes the listeners to process data*/
void belle_sip_channel_process_data(belle_sip_channel_t *obj,unsigned int revents);
......
/*
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 "belle_sip_internal.h"
static void ict_destroy(belle_sip_ict_t *obj){
}
static void ict_on_response(belle_sip_ict_t *obj, belle_sip_response_t *resp){
}
static void ict_send_request(belle_sip_ict_t *obj){
belle_sip_transaction_t *base=(belle_sip_transaction_t*)obj;
base->state=BELLE_SIP_TRANSACTION_CALLING;
}
BELLE_SIP_DECLARE_NO_IMPLEMENTED_INTERFACES(belle_sip_ict_t);
BELLE_SIP_INSTANCIATE_CUSTOM_VPTR(belle_sip_ict_t)={
{
{
BELLE_SIP_VPTR_INIT(belle_sip_ict_t,belle_sip_client_transaction_t,FALSE),
(belle_sip_object_destroy_t)ict_destroy,
NULL,
NULL
},
(void (*)(belle_sip_client_transaction_t*))ict_send_request,
(void (*)(belle_sip_client_transaction_t*,belle_sip_response_t*))ict_on_response
}
};
belle_sip_ict_t *belle_sip_ict_new(belle_sip_provider_t *prov, belle_sip_request_t *req){
belle_sip_ict_t *obj=belle_sip_object_new(belle_sip_ict_t);
belle_sip_client_transaction_init((belle_sip_client_transaction_t*)obj,prov,req);
return obj;
}
......@@ -165,12 +165,18 @@ belle_sip_header_call_id_t * belle_sip_provider_create_call_id(belle_sip_provide
return cid;
}
belle_sip_client_transaction_t *belle_sip_provider_create_client_transaction(belle_sip_provider_t *p, belle_sip_request_t *req){
return belle_sip_client_transaction_new(p,req);
belle_sip_client_transaction_t *belle_sip_provider_create_client_transaction(belle_sip_provider_t *prov, belle_sip_request_t *req){
if (strcmp(belle_sip_request_get_method(req),"INVITE")==0)
return (belle_sip_client_transaction_t*)belle_sip_ict_new(prov,req);
else
return (belle_sip_client_transaction_t*)belle_sip_nict_new(prov,req);
}
belle_sip_server_transaction_t *belle_sip_provider_create_server_transaction(belle_sip_provider_t *p, belle_sip_request_t *req){
return belle_sip_server_transaction_new(p,req);
belle_sip_server_transaction_t *belle_sip_provider_create_server_transaction(belle_sip_provider_t *prov, belle_sip_request_t *req){
if (strcmp(belle_sip_request_get_method(req),"INVITE")==0)
return (belle_sip_server_transaction_t*)belle_sip_ist_new(prov,req);
else
return (belle_sip_server_transaction_t*)belle_sip_nist_new(prov,req);
}
belle_sip_stack_t *belle_sip_provider_get_sip_stack(belle_sip_provider_t *p){
......@@ -223,7 +229,7 @@ void belle_sip_provider_set_transaction_terminated(belle_sip_provider_t *p, bell
belle_sip_transaction_terminated_event_t ev;
ev.source=p;
ev.transaction=t;
ev.is_server_transaction=t->is_server;
ev.is_server_transaction=BELLE_SIP_IS_INSTANCE_OF(t,belle_sip_server_transaction_t);
BELLE_SIP_PROVIDER_INVOKE_LISTENERS(p,process_transaction_terminated,&ev);
}
This diff is collapsed.
......@@ -19,16 +19,67 @@
#include <stdio.h>
#include "belle-sip/belle-sip.h"
static void process_dialog_terminated(belle_sip_listener_t *obj, const belle_sip_dialog_terminated_event_t *event){
belle_sip_message("process_dialog_terminated called");
}
static void process_io_error(belle_sip_listener_t *obj, const belle_sip_io_error_event_t *event){
belle_sip_message("process_io_error");
}
static void process_request_event(belle_sip_listener_t *obj, const belle_sip_request_event_t *event){
belle_sip_message("process_request_event");
}
static void process_response_event(belle_sip_listener_t *obj, const belle_sip_response_event_t *event){
belle_sip_message("process_response_event");
}
static void process_timeout(belle_sip_listener_t *obj, const belle_sip_timeout_event_t *event){
belle_sip_message("process_timeout");
}
static void process_transaction_terminated(belle_sip_listener_t *obj, const belle_sip_transaction_terminated_event_t *event){
belle_sip_message("process_transaction_terminated");
}
/*this would normally go to a .h file*/
struct test_listener{
belle_sip_object_t base;
void *some_context;
};
typedef struct test_listener test_listener_t;
BELLE_SIP_DECLARE_TYPES_BEGIN(test,0x1000)
BELLE_SIP_TYPE_ID(test_listener_t)
BELLE_SIP_DECLARE_TYPES_END
BELLE_SIP_DECLARE_VPTR(test_listener_t);
/*the following would go to .c file */
BELLE_SIP_IMPLEMENT_INTERFACE_BEGIN(test_listener_t,belle_sip_listener_t)
process_dialog_terminated,
process_io_error,
process_request_event,
process_response_event,
process_timeout,
process_transaction_terminated
BELLE_SIP_IMPLEMENT_INTERFACE_END
BELLE_SIP_DECLARE_IMPLEMENTED_INTERFACES_1(test_listener_t,belle_sip_listener_t);
BELLE_SIP_INSTANCIATE_VPTR(test_listener_t,belle_sip_object_t,NULL,NULL,NULL,FALSE);
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;
test_listener_t *listener=belle_sip_object_new(test_listener_t);
belle_sip_set_log_level(BELLE_SIP_LOG_DEBUG);
lp=belle_sip_stack_create_listening_point(stack,"0.0.0.0",7060,"UDP");
prov=belle_sip_stack_create_provider(stack,lp);
belle_sip_provider_add_sip_listener(prov,BELLE_SIP_LISTENER(listener));
req=belle_sip_request_create(
belle_sip_uri_parse("sip:test.linphone.org"),
"REGISTER",
......@@ -44,9 +95,9 @@ int main(int argc, char *argv[]){
printf("Message to send:\n%s\n",tmp);
belle_sip_free(tmp);
belle_sip_provider_send_request(prov,req);
belle_sip_stack_sleep(stack,5000);
belle_sip_stack_sleep(stack,25000);
printf("Exiting\n");
belle_sip_object_unref(BELLE_SIP_OBJECT(prov));
belle_sip_object_unref(BELLE_SIP_OBJECT(stack));
belle_sip_object_unref(prov);
belle_sip_object_unref(stack);
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment