Commit 7365fb79 authored by jehan's avatar jehan

start refresher implementation

parent db6dd274
......@@ -60,7 +60,7 @@
<folderInfo id="cdt.managedbuild.toolchain.gnu.macosx.base.557244179.959032290." name="/" resourcePath="">
<toolChain id="cdt.managedbuild.toolchain.gnu.macosx.base.1209613831" name="cdt.managedbuild.toolchain.gnu.macosx.base" superClass="cdt.managedbuild.toolchain.gnu.macosx.base">
<targetPlatform archList="all" binaryParser="org.eclipse.cdt.core.MachO64" id="cdt.managedbuild.target.gnu.platform.macosx.base.973927327" name="Debug Platform" osList="macosx" superClass="cdt.managedbuild.target.gnu.platform.macosx.base"/>
<builder arguments="CFLAGS=&quot;-g -Wall &quot; V=1" command="make" id="cdt.managedbuild.target.gnu.builder.macosx.base.190701400" keepEnvironmentInBuildfile="false" managedBuildOn="false" name="Gnu Make Builder" superClass="cdt.managedbuild.target.gnu.builder.macosx.base"/>
<builder arguments="-j2 CFLAGS=&quot;-g -Wall &quot; V=1" command="make" id="cdt.managedbuild.target.gnu.builder.macosx.base.190701400" keepEnvironmentInBuildfile="false" managedBuildOn="false" name="Gnu Make Builder" superClass="cdt.managedbuild.target.gnu.builder.macosx.base"/>
<tool id="cdt.managedbuild.tool.macosx.c.linker.macosx.base.419159753" name="MacOS X C Linker" superClass="cdt.managedbuild.tool.macosx.c.linker.macosx.base">
<inputType id="cdt.managedbuild.tool.macosx.c.linker.input.1079464415" superClass="cdt.managedbuild.tool.macosx.c.linker.input">
<additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/>
......@@ -87,8 +87,13 @@
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
<project id="belle-sip.null.1195886304" name="belle-sip"/>
</storageModule>
<storageModule moduleId="refreshScope" versionNumber="1">
<resource resourceType="PROJECT" workspacePath="/belle-sip"/>
<storageModule moduleId="refreshScope" versionNumber="2">
<configuration configurationName="Default">
<resource resourceType="PROJECT" workspacePath="/belle-sip"/>
</configuration>
<configuration configurationName="debug">
<resource resourceType="PROJECT" workspacePath="/belle-sip"/>
</configuration>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.make.core.buildtargets">
<buildTargets>
......@@ -281,4 +286,5 @@
</profile>
</scannerConfigBuildInfo>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/>
</cproject>
Installation Instructions
*************************
Copyright (C) 1994-1996, 1999-2002, 2004-2011 Free Software Foundation,
Copyright (C) 1994-1996, 1999-2002, 2004-2012 Free Software Foundation,
Inc.
Copying and distribution of this file, with or without modification,
......@@ -309,9 +309,10 @@ causes the specified `gcc' to be used as the C compiler (unless it is
overridden in the site shell script).
Unfortunately, this technique does not work for `CONFIG_SHELL' due to
an Autoconf bug. Until the bug is fixed you can use this workaround:
an Autoconf limitation. Until the limitation is lifted, you can use
this workaround:
CONFIG_SHELL=/bin/bash /bin/bash ./configure CONFIG_SHELL=/bin/bash
CONFIG_SHELL=/bin/bash ./configure CONFIG_SHELL=/bin/bash
`configure' Invocation
======================
......@@ -367,4 +368,3 @@ operates.
`configure' also accepts some other, not widely useful, options. Run
`configure --help' for more details.
......@@ -103,6 +103,7 @@ BELLE_SIP_DECLARE_TYPES_BEGIN(belle_sip,1)
BELLE_SIP_TYPE_ID(belle_sdp_base_description_t),
BELLE_SIP_TYPE_ID(belle_sdp_mime_parameter_t),
BELLE_SIP_TYPE_ID(belle_sip_callbacks_t),
BELLE_SIP_TYPE_ID(belle_sip_refresher_t),
BELLE_SIP_DECLARE_TYPES_END
......@@ -143,6 +144,7 @@ typedef struct _belle_sip_response belle_sip_response_t;
#include "belle-sip/headers.h"
#include "belle-sip/parameters.h"
#include "belle-sip/message.h"
#include "belle-sip/refresher-helper.h"
#include "belle-sip/transaction.h"
#include "belle-sip/dialog.h"
#include "belle-sip/sipstack.h"
......@@ -151,6 +153,7 @@ typedef struct _belle_sip_response belle_sip_response_t;
#include "belle-sip/auth-helper.h"
#undef TRUE
#define TRUE 1
......
......@@ -135,6 +135,12 @@ belle_sip_header_contact_t* belle_sip_header_contact_create (const belle_sip_hea
*
*/
void belle_sip_header_contact_set_wildcard(belle_sip_header_contact_t* contact,unsigned int is_wildcard);
/** Contact heaader equality function
* @return 0 if not equals
*
* */
unsigned int belle_sip_header_contact_equals(const belle_sip_header_contact_t* a,const belle_sip_header_contact_t* b);
#define BELLE_SIP_RANDOM_TAG ((const char*)-1)
#define BELLE_SIP_HEADER_CONTACT(t) BELLE_SIP_CAST(t,belle_sip_header_contact_t)
#define BELLE_SIP_CONTACT "Contact"
......
......@@ -26,6 +26,11 @@ const char *belle_sip_listening_point_get_ip_address(const belle_sip_listening_p
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);
/**
* get the listening information as an URI
* @return IP/port/transport as an URI
*/
const belle_sip_uri_t* belle_sip_listening_point_get_uri(const belle_sip_listening_point_t *ip);
int belle_sip_listening_point_is_reliable(const belle_sip_listening_point_t *lp);
int belle_sip_listening_point_get_well_known_port(const char *transport);
......
......@@ -57,7 +57,7 @@ const char* belle_sip_request_get_method(const belle_sip_request_t* request);
void belle_sip_request_set_method(belle_sip_request_t* request,const char* method);
/**
* Guess the origin of the received sip message from VIA header (thanks to received/rport)
* @param req request to be annylized
* @param req request to be analyzed
* @ return a newly allocated uri
* */
belle_sip_uri_t* belle_sip_request_extract_origin(const belle_sip_request_t* req);
......@@ -106,7 +106,13 @@ void belle_sip_response_set_reason_phrase(belle_sip_response_t *response,const c
belle_sip_response_t *belle_sip_response_new(void);
belle_sip_response_t *belle_sip_response_create_from_request(belle_sip_request_t *req, int status_code);
/**
* This method takes the received rport value of the reponse and update the contact IP/port accordingly
* @param response use to extract received/rport from top most via.
* @param contact contact to be updated
* @returns 0 if no error
* */
int belle_sip_response_fix_contact(const belle_sip_response_t* response,belle_sip_header_contact_t* contact);
BELLE_SIP_END_DECLS
......
......@@ -123,6 +123,7 @@ int belle_sip_object_is_unowed(const belle_sip_object_t *obj);
**/
belle_sip_object_t * belle_sip_object_ref(void *obj);
/*#define BELLE_SIP_REF(object,type) (type*)belle_sip_object_ref(object);*/
/**
* Decrements the reference counter. When it drops to zero, the object is destroyed.
**/
......
/*
belle-sip - SIP (RFC3261) library.
Copyright (C) 2012 Belledonne Communications SARL, Grenoble, France
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 REFRESHER_HELPER_H_
#define REFRESHER_HELPER_H_
typedef struct belle_sip_refresher belle_sip_refresher_t;
/**
* Refresher listener invoked every time a refresh action is performed
* @param refresher corresponding refresher object.
* @param user_pointer user pointer
* @param status_code status code for the last refresh action
* @param reason_phrase
* */
typedef void (*belle_sip_refresher_listener_t) ( const belle_sip_refresher_t* refresher
,void* user_pointer
,unsigned int status_code
,const char* reason_phrase);
/**
* add a refresher listener
*/
void belle_sip_refresher_set_listener(belle_sip_refresher_t* refresher, belle_sip_refresher_listener_t listener,void* user_pointer);
/**
* start the refresher
*/
int belle_sip_refresher_start(belle_sip_refresher_t* refresher);
/**
* stop refresher
*/
void belle_sip_refresher_stop(belle_sip_refresher_t* refresher);
#endif /* REFRESHER_HELPER_H_ */
......@@ -32,6 +32,8 @@ typedef enum belle_sip_transaction_state{
BELLE_SIP_BEGIN_DECLS
const char *belle_sip_transaction_state_to_string(belle_sip_transaction_state_t state);
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);
const char *belle_sip_transaction_get_branch_id(const belle_sip_transaction_t *t);
......@@ -44,6 +46,11 @@ void belle_sip_server_transaction_send_response(belle_sip_server_transaction_t *
belle_sip_request_t * belle_sip_client_transaction_create_cancel(belle_sip_client_transaction_t *t);
int belle_sip_client_transaction_send_request(belle_sip_client_transaction_t *t);
/**
* Creates an a sip refresher for transaction like REGISTER/SUBSCRIBE or INVITE which could be refreshed.
* Transaction must in be in stated BELLE_SIP_TRANSACTION_COMPLETED. Refresher is created and started
* */
belle_sip_refresher_t* belle_sip_client_transaction_create_refresher(belle_sip_client_transaction_t *t);
/**
* Create an authenticated request based on an existing terminated transaction
* */
......
......@@ -57,7 +57,8 @@ libbellesip_la_SOURCES= \
transports/stream_channel.c \
transports/stream_channel.h \
transports/stream_listeningpoint.c \
transports/tls_listeningpoint.c
transports/tls_listeningpoint.c \
refresher.c
if BUILD_TLS
libbellesip_la_SOURCES+=transports/tls_channel.c
endif
......
......@@ -235,6 +235,11 @@ int belle_sip_header_contact_set_qvalue(belle_sip_header_contact_t* contact, flo
float belle_sip_header_contact_get_qvalue(const belle_sip_header_contact_t* contact) {
return belle_sip_header_contact_get_q(contact);
}
unsigned int belle_sip_header_contact_equals(const belle_sip_header_contact_t* a,const belle_sip_header_contact_t* b) {
if (!a | !b) return 0;
return !belle_sip_uri_equals(belle_sip_header_address_get_uri(BELLE_SIP_HEADER_ADDRESS(a))
,belle_sip_header_address_get_uri(BELLE_SIP_HEADER_ADDRESS(b)));
}
/**************************
* From header object inherent from header_address
****************************
......
......@@ -204,7 +204,7 @@ BELLE_SIP_DECLARE_VPTR(belle_sdp_uri_t);
BELLE_SIP_DECLARE_VPTR(belle_sdp_version_t);
BELLE_SIP_DECLARE_VPTR(belle_sdp_base_description_t);
BELLE_SIP_DECLARE_VPTR(belle_sdp_mime_parameter_t);
BELLE_SIP_DECLARE_VPTR(belle_sip_refresher_t);
typedef void (*belle_sip_source_remove_callback_t)(belle_sip_source_t *);
......@@ -505,6 +505,7 @@ struct belle_sip_provider{
belle_sip_stack_t *stack;
belle_sip_list_t *lps; /*listening points*/
belle_sip_list_t *listeners;
belle_sip_list_t *internal_listeners; /*for transaction internaly managed by belle-sip. I.E by refreshers*/
belle_sip_list_t *client_transactions;
belle_sip_list_t *server_transactions;
belle_sip_list_t *dialogs;
......@@ -524,14 +525,18 @@ belle_sip_channel_t * belle_sip_provider_get_channel(belle_sip_provider_t *p, co
void belle_sip_provider_add_dialog(belle_sip_provider_t *prov, belle_sip_dialog_t *dialog);
void belle_sip_provider_remove_dialog(belle_sip_provider_t *prov, belle_sip_dialog_t *dialog);
void belle_sip_provider_release_channel(belle_sip_provider_t *p, belle_sip_channel_t *chan);
void belle_sip_provider_add_internal_sip_listener(belle_sip_provider_t *p, belle_sip_listener_t *l);
typedef struct listener_ctx{
belle_sip_listener_t *listener;
void *data;
}listener_ctx_t;
#define BELLE_SIP_PROVIDER_INVOKE_LISTENERS(provider,callback,event) \
BELLE_SIP_INVOKE_LISTENERS_ARG(((provider)->listeners),belle_sip_listener_t,callback,(event))
#define BELLE_SIP_PROVIDER_INVOKE_LISTENERS_FOR_TRANSACTION(t,callback,event) \
BELLE_SIP_PROVIDER_INVOKE_LISTENERS((t)->is_internal?t->provider->internal_listeners:t->provider->listeners,callback,event)
#define BELLE_SIP_PROVIDER_INVOKE_LISTENERS(listeners,callback,event) \
BELLE_SIP_INVOKE_LISTENERS_ARG((listeners),belle_sip_listener_t,callback,(event))
/*
......@@ -549,6 +554,7 @@ struct belle_sip_transaction{
belle_sip_transaction_state_t state;
uint64_t start_time;
void *appdata;
unsigned int is_internal;
};
......@@ -580,6 +586,7 @@ void belle_sip_transaction_notify_timeout(belle_sip_transaction_t *t);
struct belle_sip_client_transaction{
belle_sip_transaction_t base;
belle_sip_header_route_t* preset_route; /*use to store first remove route header, will be helpful for refresher*/
};
BELLE_SIP_DECLARE_CUSTOM_VPTR_BEGIN(belle_sip_client_transaction_t,belle_sip_transaction_t)
......@@ -814,6 +821,10 @@ struct belle_sip_auth_event {
belle_sip_auth_event_t* belle_sip_auth_event_create(const char* realm,const char* username);
void belle_sip_auth_event_destroy(belle_sip_auth_event_t* event);
/*
* refresher
* */
belle_sip_refresher_t* belle_sip_refresher_new(belle_sip_client_transaction_t* transaction);
#ifdef __cplusplus
}
#endif
......
......@@ -331,7 +331,12 @@ static void _send_message(belle_sip_channel_t *obj, belle_sip_message_t *msg){
channel_set_state(obj,BELLE_SIP_CHANNEL_ERROR);
belle_sip_channel_close(obj);
}else{
belle_sip_message("channel %p: message sent: \n%s",obj,buffer);
belle_sip_message("channel %p: message sent to [%s://%s:%i] \n%s"
,obj
,belle_sip_channel_get_transport_name(obj)
,obj->peer_name
,obj->peer_port
,buffer);
}
}
}
......
......@@ -21,9 +21,10 @@
void belle_sip_listening_point_init(belle_sip_listening_point_t *lp, belle_sip_stack_t *s, const char *address, int port){
lp->port=port;
lp->addr=belle_sip_strdup(address);
lp->stack=s;
lp->listening_uri=belle_sip_uri_create(NULL,address);
belle_sip_uri_set_port(lp->listening_uri,port);
belle_sip_uri_set_transport_param(lp->listening_uri,BELLE_SIP_OBJECT_VPTR(lp,belle_sip_listening_point_t)->transport);
}
static void belle_sip_listening_point_uninit(belle_sip_listening_point_t *lp){
......@@ -32,7 +33,8 @@ static void belle_sip_listening_point_uninit(belle_sip_listening_point_t *lp){
belle_sip_warning("Listening point destroying [%i] channels",existing_channels);
}
belle_sip_list_free_with_data(lp->channels,(void (*)(void*))belle_sip_object_unref);
belle_sip_free(lp->addr);
belle_sip_object_unref(lp->listening_uri);
if (lp->channel_listener)belle_sip_object_unref(lp->channel_listener);
}
......@@ -44,6 +46,7 @@ belle_sip_channel_t *belle_sip_listening_point_create_channel(belle_sip_listenin
belle_sip_channel_t *chan=BELLE_SIP_OBJECT_VPTR(obj,belle_sip_listening_point_t)->create_channel(obj,dest,port);
if (chan){
chan->lp=obj;
belle_sip_channel_add_listener(chan,obj->channel_listener);
belle_sip_listening_point_add_channel(obj,chan);
}
return chan;
......@@ -69,18 +72,20 @@ BELLE_SIP_INSTANCIATE_CUSTOM_VPTR(belle_sip_listening_point_t)={
};
const char *belle_sip_listening_point_get_ip_address(const belle_sip_listening_point_t *lp){
return lp->addr;
return belle_sip_uri_get_host(lp->listening_uri);
}
int belle_sip_listening_point_get_port(const belle_sip_listening_point_t *lp){
return lp->port;
return belle_sip_uri_get_listening_port(lp->listening_uri);
}
const char *belle_sip_listening_point_get_transport(const belle_sip_listening_point_t *lp){
return BELLE_SIP_OBJECT_VPTR(lp,belle_sip_listening_point_t)->transport;
return belle_sip_uri_get_transport_param(lp->listening_uri);
}
const belle_sip_uri_t* belle_sip_listening_point_get_uri(const belle_sip_listening_point_t *lp) {
return lp->listening_uri;
}
int belle_sip_listening_point_get_well_known_port(const char *transport){
if (strcasecmp(transport,"UDP")==0 || strcasecmp(transport,"TCP")==0 ) return 5060;
if (strcasecmp(transport,"DTLS")==0 || strcasecmp(transport,"TLS")==0 ) return 5061;
......@@ -115,6 +120,9 @@ belle_sip_channel_t *belle_sip_listening_point_get_channel(belle_sip_listening_p
return chan;
}
void belle_sip_listener_set_channel_listener(belle_sip_listening_point_t *lp,belle_sip_channel_listener_t* channel_listener) {
lp->channel_listener=channel_listener;
belle_sip_object_ref(lp->channel_listener);
}
......@@ -31,17 +31,17 @@ struct belle_sip_listening_point{
belle_sip_object_t base;
belle_sip_stack_t *stack;
belle_sip_list_t *channels;
char *addr;
int port;
belle_sip_channel_listener_t* channel_listener; /*inital chennel listener used for channel creation*/
belle_sip_uri_t* listening_uri;
};
void belle_sip_listening_point_init(belle_sip_listening_point_t *lp, belle_sip_stack_t *s, const char *address, int port);
void belle_sip_listening_point_init(belle_sip_listening_point_t *lp, belle_sip_stack_t *s, const char *address, int port);
belle_sip_channel_t *_belle_sip_listening_point_get_channel(belle_sip_listening_point_t *lp,const char *peer_name, int peer_port, const struct addrinfo *addr);
belle_sip_channel_t *belle_sip_listening_point_create_channel(belle_sip_listening_point_t *ip, const char *dest, int port);
belle_sip_channel_t *belle_sip_listening_point_create_channel(belle_sip_listening_point_t *ip,const char *dest, int port);
int belle_sip_listening_point_get_well_known_port(const char *transport);
belle_sip_channel_t *belle_sip_listening_point_get_channel(belle_sip_listening_point_t *lp,const char *peer_name, int peer_port);
void belle_sip_listening_point_add_channel(belle_sip_listening_point_t *lp, belle_sip_channel_t *chan);
void belle_sip_listener_set_channel_listener(belle_sip_listening_point_t *lp,belle_sip_channel_listener_t* channel_listener);
/**udp*/
......
......@@ -524,3 +524,38 @@ void belle_sip_response_get_return_hop(belle_sip_response_t *msg, belle_sip_hop_
if (hop->port==-1)
hop->port=belle_sip_header_via_get_listening_port(via);
}
int belle_sip_response_fix_contact(const belle_sip_response_t* response,belle_sip_header_contact_t* contact) {
belle_sip_header_via_t* via_header;
belle_sip_uri_t* contact_uri;
const char* received;
int rport;
int contact_port;
/*first check received/rport*/
via_header= (belle_sip_header_via_t*)belle_sip_message_get_header(BELLE_SIP_MESSAGE(response),BELLE_SIP_VIA);
received = belle_sip_header_via_get_received(via_header);
rport = belle_sip_header_via_get_rport(via_header);
if (received!=NULL || rport>0) {
contact_uri=belle_sip_header_address_get_uri(BELLE_SIP_HEADER_ADDRESS(contact));
if (received && strcmp(received,belle_sip_uri_get_host(contact_uri))!=0) {
/*need to update host*/
belle_sip_uri_set_host(contact_uri,received);
}
contact_port = belle_sip_uri_get_port(contact_uri);
if (rport>0 && rport!=contact_port && (contact_port+rport)!=5060) {
/*need to update port*/
belle_sip_uri_set_port(contact_uri,rport);
}
/*try to fix transport if needed (very unlikely)*/
if (strcasecmp(belle_sip_header_via_get_transport(via_header),"UDP")!=0) {
if (!belle_sip_uri_get_transport_param(contact_uri)
||strcasecmp(belle_sip_uri_get_transport_param(contact_uri),belle_sip_header_via_get_transport(via_header))!=0) {
belle_sip_uri_set_transport_param(contact_uri,belle_sip_header_via_get_transport_lowercase(via_header));
}
} else {
if (belle_sip_uri_get_transport_param(contact_uri)) {
belle_sip_uri_set_transport_param(contact_uri,NULL);
}
}
}
return 0;
}
......@@ -56,6 +56,7 @@ static void belle_sip_authorization_destroy(authorization_context_t* object) {
static void belle_sip_provider_uninit(belle_sip_provider_t *p){
belle_sip_list_free(p->listeners);
belle_sip_list_free(p->internal_listeners);
belle_sip_list_free_with_data(p->lps,belle_sip_object_unref);
belle_sip_list_free_with_data(p->client_transactions,belle_sip_object_unref);
belle_sip_list_free_with_data(p->server_transactions,belle_sip_object_unref);
......@@ -70,7 +71,7 @@ static void channel_state_changed(belle_sip_channel_listener_t *obj, belle_sip_c
ev.source=(belle_sip_provider_t*)obj;
ev.port=chan->peer_port;
ev.host=chan->peer_name;
BELLE_SIP_PROVIDER_INVOKE_LISTENERS(ev.source,process_io_error,&ev);
BELLE_SIP_PROVIDER_INVOKE_LISTENERS(ev.source->listeners,process_io_error,&ev);
}
}
......@@ -92,7 +93,7 @@ static void belle_sip_provider_dispatch_request(belle_sip_provider_t* prov, bell
ev.source=prov;
ev.server_transaction=NULL;
ev.request=req;
BELLE_SIP_PROVIDER_INVOKE_LISTENERS(prov,process_request_event,&ev);
BELLE_SIP_PROVIDER_INVOKE_LISTENERS(prov->listeners,process_request_event,&ev);
}
}
......@@ -115,7 +116,7 @@ static void belle_sip_provider_dispatch_response(belle_sip_provider_t* prov, bel
event.client_transaction=NULL;
event.dialog=NULL;
event.response=msg;
BELLE_SIP_PROVIDER_INVOKE_LISTENERS(prov,process_response_event,&event);
BELLE_SIP_PROVIDER_INVOKE_LISTENERS(prov->listeners,process_response_event,&event);
}
}
......@@ -229,6 +230,7 @@ int belle_sip_provider_add_listening_point(belle_sip_provider_t *p, belle_sip_li
belle_sip_error("Cannot add NULL lp to provider [%p]",p);
return -1;
}
belle_sip_listener_set_channel_listener(lp,BELLE_SIP_CHANNEL_LISTENER(p));
p->lps=belle_sip_list_append(p->lps,belle_sip_object_ref(lp));
return 0;
}
......@@ -253,6 +255,14 @@ const belle_sip_list_t *belle_sip_provider_get_listening_points(belle_sip_provid
return p->lps;
}
void belle_sip_provider_add_internal_sip_listener(belle_sip_provider_t *p, belle_sip_listener_t *l){
p->internal_listeners=belle_sip_list_append(p->internal_listeners,l);
}
void belle_sip_provider_remove_internal_sip_listener(belle_sip_provider_t *p, belle_sip_listener_t *l){
p->internal_listeners=belle_sip_list_remove(p->internal_listeners,l);
}
void belle_sip_provider_add_sip_listener(belle_sip_provider_t *p, belle_sip_listener_t *l){
p->listeners=belle_sip_list_append(p->listeners,l);
}
......@@ -337,7 +347,7 @@ void belle_sip_provider_remove_dialog(belle_sip_provider_t *prov, belle_sip_dial
ev.source=prov;
ev.dialog=dialog;
prov->dialogs=belle_sip_list_remove(prov->dialogs,dialog);
BELLE_SIP_PROVIDER_INVOKE_LISTENERS(prov,process_dialog_terminated,&ev);
BELLE_SIP_PROVIDER_INVOKE_LISTENERS(prov->listeners,process_dialog_terminated,&ev);
belle_sip_object_unref(dialog);
}
......@@ -388,7 +398,6 @@ belle_sip_channel_t * belle_sip_provider_get_channel(belle_sip_provider_t *p, co
if (candidate){
chan=belle_sip_listening_point_create_channel(candidate,name,port);
if (chan==NULL) belle_sip_error("Could not create channel to %s:%s:%i",transport,name,port);
else belle_sip_channel_add_listener(chan,BELLE_SIP_CHANNEL_LISTENER(p));
return chan;
}
belle_sip_error("No listening point matching for transport %s",transport);
......@@ -434,7 +443,7 @@ void belle_sip_provider_set_transaction_terminated(belle_sip_provider_t *p, bell
ev.source=t->provider;
ev.transaction=t;
ev.is_server_transaction=BELLE_SIP_IS_INSTANCE_OF(t,belle_sip_server_transaction_t);
BELLE_SIP_PROVIDER_INVOKE_LISTENERS(t->provider,process_transaction_terminated,&ev);
BELLE_SIP_PROVIDER_INVOKE_LISTENERS_FOR_TRANSACTION(t,process_transaction_terminated,&ev);
if (!ev.is_server_transaction){
belle_sip_provider_remove_client_transaction(p,(belle_sip_client_transaction_t*)t);
}else{
......@@ -642,7 +651,7 @@ int belle_sip_provider_add_authorization(belle_sip_provider_t *p, belle_sip_requ
auth_event = belle_sip_auth_event_create(auth_context->realm,belle_sip_uri_get_user(from_uri));
/*put data*/
/*call listener*/
BELLE_SIP_PROVIDER_INVOKE_LISTENERS(p,process_auth_requested,auth_event);
BELLE_SIP_PROVIDER_INVOKE_LISTENERS(p->listeners,process_auth_requested,auth_event);
if (auth_event->passwd || auth_event->ha1) {
if (!auth_event->userid) {
/*if no userid, username = userid*/
......
This diff is collapsed.
......@@ -51,6 +51,7 @@ static void transaction_destroy(belle_sip_transaction_t *t){
if (t->last_response) belle_sip_object_unref(t->last_response);
if (t->channel) belle_sip_object_unref(t->channel);
if (t->branch_id) belle_sip_free(t->branch_id);
}
BELLE_SIP_DECLARE_NO_IMPLEMENTED_INTERFACES(belle_sip_transaction_t);
......@@ -96,7 +97,11 @@ void belle_sip_transaction_notify_timeout(belle_sip_transaction_t *t){
ev.source=t->provider;
ev.transaction=t;
ev.is_server_transaction=BELLE_SIP_OBJECT_IS_INSTANCE_OF(t,belle_sip_server_transaction_t);
BELLE_SIP_PROVIDER_INVOKE_LISTENERS(t->provider,process_timeout,&ev);
BELLE_SIP_PROVIDER_INVOKE_LISTENERS_FOR_TRANSACTION(t,process_timeout,&ev);
}
belle_sip_dialog_t* belle_sip_transaction_get_dialog(const belle_sip_transaction_t *t) {
return t->dialog;
}
/*
......@@ -169,7 +174,7 @@ static void server_transaction_notify(belle_sip_server_transaction_t *t, belle_s
event.server_transaction=t;
event.dialog=dialog;
event.request=req;
BELLE_SIP_PROVIDER_INVOKE_LISTENERS(t->base.provider,process_request_event,&event);
BELLE_SIP_PROVIDER_INVOKE_LISTENERS_FOR_TRANSACTION(((belle_sip_transaction_t*) t),process_request_event,&event);
}
void belle_sip_server_transaction_on_request(belle_sip_server_transaction_t *t, belle_sip_request_t *req){
......@@ -237,6 +242,10 @@ int belle_sip_client_transaction_send_request(belle_sip_client_transaction_t *t)
belle_sip_error("belle_sip_client_transaction_send_request: bad state.");
return -1;
}
/*store preset route for futur use by refresher*/
t->preset_route=BELLE_SIP_HEADER_ROUTE(belle_sip_message_get_header(BELLE_SIP_MESSAGE(t->base.request),"route"));
if (t->preset_route) belle_sip_object_ref(t->preset_route);
belle_sip_stack_get_next_hop(prov->stack,t->base.request,&hop);
chan=belle_sip_provider_get_channel(prov,hop.host, hop.port, hop.transport);
if (chan){
......@@ -282,7 +291,7 @@ void belle_sip_client_transaction_notify_response(belle_sip_client_transaction_t
event.client_transaction=t;
event.dialog=dialog;
event.response=(belle_sip_response_t*)resp;
BELLE_SIP_PROVIDER_INVOKE_LISTENERS(base->provider,process_response_event,&event);
BELLE_SIP_PROVIDER_INVOKE_LISTENERS_FOR_TRANSACTION(((belle_sip_transaction_t*)t),process_response_event,&event);
/*check that 200Ok for INVITEs have been acknoledged by listener*/
if (dialog) belle_sip_dialog_check_ack_sent(dialog);
}
......@@ -293,6 +302,7 @@ void belle_sip_client_transaction_add_response(belle_sip_client_transaction_t *t
}
static void client_transaction_destroy(belle_sip_client_transaction_t *t ){
if (t->preset_route) belle_sip_object_unref(t->preset_route);
}
static void on_channel_state_changed(belle_sip_channel_listener_t *l, belle_sip_channel_t *chan, belle_sip_channel_state_t state){
......@@ -346,8 +356,12 @@ void belle_sip_client_transaction_init(belle_sip_client_transaction_t *obj, bell
belle_sip_transaction_init((belle_sip_transaction_t*)obj, prov,req);
}
belle_sip_dialog_t* belle_sip_transaction_get_dialog(const belle_sip_transaction_t *t) {
return t->dialog;
belle_sip_refresher_t* belle_sip_client_transaction_create_refresher(belle_sip_client_transaction_t *t) {
belle_sip_refresher_t* refresher = belle_sip_refresher_new(t);
if (refresher) {
belle_sip_refresher_start(refresher);
}
return refresher;
}
......@@ -28,7 +28,10 @@ static void belle_sip_stream_listening_point_uninit(belle_sip_stream_listening_p
}
static belle_sip_channel_t *stream_create_channel(belle_sip_listening_point_t *lp, const char *dest_ip, int port){
belle_sip_channel_t *chan=belle_sip_channel_new_tcp(lp->stack,lp->addr,lp->port,dest_ip,port);
belle_sip_channel_t *chan=belle_sip_channel_new_tcp(lp->stack
,belle_sip_uri_get_host(lp->listening_uri)
,belle_sip_uri_get_port(lp->listening_uri)
,dest_ip,port);
return chan;
}
......
......@@ -26,7 +26,11 @@ static void belle_sip_tls_listening_point_uninit(belle_sip_tls_listening_point_t
static belle_sip_channel_t *tls_create_channel(belle_sip_listening_point_t *lp, const char *dest_ip, int port){
#ifdef HAVE_GNUTLS
belle_sip_channel_t *chan=belle_sip_channel_new_tls(BELLE_SIP_TLS_LISTENING_POINT(lp),lp->addr,lp->port,dest_ip,port);
belle_sip_channel_t *chan=belle_sip_channel_new_tls(BELLE_SIP_TLS_LISTENING_POINT(lp)
,belle_sip_uri_get_host(lp->listening_uri)
,belle_sip_uri_get_port(lp->listening_uri)
,dest_ip
,port);
return chan;
#else
return NULL;
......
......@@ -52,6 +52,7 @@ static int udp_channel_recv(belle_sip_channel_t *obj, void *buf, size_t buflen){
struct sockaddr_storage addr;
socklen_t addrlen=sizeof(addr);
err=recvfrom(chan->sock,buf,buflen,MSG_DONTWAIT,(struct sockaddr*)&addr,&addrlen);
if (err==-1 && errno!=EWOULDBLOCK){
belle_sip_error("Could not receive UDP packet: %s",strerror(errno));
return -errno;
......@@ -118,6 +119,10 @@ belle_sip_channel_t * belle_sip_channel_new_udp_with_addr(belle_sip_stack_t *sta
return NULL;
}
belle_sip_channel_init((belle_sip_channel_t*)obj,stack,sock,NULL,bindip,localport,name,atoi(serv));
err=getaddrinfo(name,serv,ai,&obj->base.peer); /*might be optimized someway ?*/
if (err!=0){
belle_sip_error("getaddrinfo() failed for channel [%p] error [%s]",obj,gai_strerror(err));
}
return (belle_sip_channel_t*)obj;
}
......@@ -34,8 +34,12 @@ static void belle_sip_udp_listening_point_uninit(belle_sip_udp_listening_point_t
}
static belle_sip_channel_t *udp_create_channel(belle_sip_listening_point_t *lp, const char *dest_ip, int port){
belle_sip_channel_t *chan=belle_sip_channel_new_udp(lp->stack,((belle_sip_udp_listening_point_t*)lp)->sock,
lp->addr,lp->port,dest_ip,port);
belle_sip_channel_t *chan=belle_sip_channel_new_udp(lp->stack
,((belle_sip_udp_listening_point_t*)lp)->sock
,belle_sip_uri_get_host(lp->listening_uri)
,belle_sip_uri_get_port(lp->listening_uri)
,dest_ip
,port);
return chan;
}
......@@ -108,10 +112,15 @@ static int on_udp_data(belle_sip_udp_listening_point_t *lp, unsigned int events)
ai.ai_addrlen=addrlen;
chan=_belle_sip_listening_point_get_channel((belle_sip_listening_point_t*)lp,NULL,0,&ai);
if (chan==NULL){
chan=belle_sip_channel_new_udp_with_addr(lp->base.stack,lp->sock,lp->base.addr,lp->base.port,&ai);
chan=belle_sip_channel_new_udp_with_addr(lp->base.stack
,lp->sock
,belle_sip_uri_get_host(lp->base.listening_uri)
,belle_sip_uri_get_port(lp->base.listening_uri)
,&ai);
if (chan!=NULL){
belle_sip_message("udp_listening_point: new channel created to %s:%i",chan->peer_name,chan->peer_port);
belle_sip_listening_point_add_channel((belle_sip_listening_point_t*)lp,chan);
belle_sip_channel_add_listener(chan,lp->base.channel_listener);
}
}
if (chan){
......
......@@ -12,7 +12,8 @@ belle_sip_tester_SOURCES= belle_sip_tester.c \
auth_helper_tester.c \
cast_test.c \
belle_sip_register_tester.c \
belle_sip_dialog_tester.c
belle_sip_dialog_tester.c \
belle_sip_refresher_tester.c
belle_sip_tester_CFLAGS=$(CUNIT_CFLAGS) $(STRICT_OPTIONS)
......
......@@ -238,6 +238,9 @@ static void test_extract_source() {
belle_sip_object_unref(message);
}
/*static void test_fix_contact_with_received_rport() {
}*/
int belle_sip_message_test_suite () {
CU_pSuite pSuite = NULL;
......
/*
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 "CUnit/Basic.h"
#include "belle-sip/belle-sip.h"
#include "belle_sip_internal.h"
typedef enum auth_mode {
none
,digest