Commit 9bf1620a authored by Simon Morlat's avatar Simon Morlat

work in progress, generates to tag for server transaction's responses.

parent 3babc98d
......@@ -135,13 +135,14 @@ belle_sip_header_contact_t* belle_sip_header_contact_parse (const char* contact)
belle_sip_header_from_t* belle_sip_header_from_create(const char *address, const char *tag);
belle_sip_header_from_t* belle_sip_header_from_parse (const char* from) ;
belle_sip_header_from_t* belle_sip_header_from_parse(const char* 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(const belle_sip_header_from_t* from);
void belle_sip_header_from_set_random_tag(belle_sip_header_from_t *obj);
#define BELLE_SIP_HEADER_FROM(t) BELLE_SIP_CAST(t,belle_sip_header_from_t)
/******************************
* To header object inherent from header_address
......@@ -159,6 +160,8 @@ belle_sip_header_contact_t* belle_sip_header_contact_parse (const char* contact)
const char* belle_sip_header_to_get_tag(const belle_sip_header_to_t* from);
void belle_sip_header_to_set_random_tag(belle_sip_header_to_t *obj);
#define BELLE_SIP_HEADER_TO(t) BELLE_SIP_CAST(t,belle_sip_header_to_t)
/******************************
......
......@@ -92,7 +92,7 @@ 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_new_from_request(belle_sip_request_t *req, int status_code);
belle_sip_response_t *belle_sip_response_create_from_request(belle_sip_request_t *req, int status_code);
BELLE_SIP_END_DECLS
......
......@@ -133,6 +133,8 @@ void belle_sip_set_log_level(int level);
char * belle_sip_random_token(char *ret, size_t size);
char * belle_sip_create_tag(char *ret, size_t size);
#if defined(WIN32) || defined(WIN32_WCE)
typedef SOCKET belle_sip_fd_t;
#else
......
......@@ -251,6 +251,12 @@ BELLE_SIP_NEW_HEADER(header_from,header_address,"From")
BELLE_SIP_PARSE(header_from)
GET_SET_STRING_PARAM(belle_sip_header_from,tag);
void belle_sip_header_from_set_random_tag(belle_sip_header_from_t *obj){
char tmp[8];
/*not less than 32bit */
belle_sip_header_from_set_tag(obj,belle_sip_random_token(tmp,sizeof(tmp)));
}
/**************************
* To header object inherits from header_address
****************************
......@@ -280,6 +286,12 @@ belle_sip_header_to_t* belle_sip_header_to_create(const char *address, const cha
return to;
}
void belle_sip_header_to_set_random_tag(belle_sip_header_to_t *obj){
char tmp[8];
/*not less than 32bit */
belle_sip_header_to_set_tag(obj,belle_sip_random_token(tmp,sizeof(tmp)));
}
/******************************
* User-Agent header hinerite from header
*
......
......@@ -609,6 +609,7 @@ belle_sip_nict_t * belle_sip_nict_new(belle_sip_provider_t *prov, belle_sip_requ
struct belle_sip_server_transaction{
belle_sip_transaction_t base;
char to_tag[8];
};
BELLE_SIP_DECLARE_CUSTOM_VPTR_BEGIN(belle_sip_server_transaction_t,belle_sip_transaction_t)
......
......@@ -544,7 +544,6 @@ char * belle_sip_random_token(char *ret, size_t size){
return ret;
}
void belle_sip_util_copy_headers(belle_sip_message_t *orig, belle_sip_message_t *dest, const char*header, int multiple){
const belle_sip_list_t *elem;
elem=belle_sip_message_get_headers(orig,header);
......
......@@ -30,6 +30,24 @@ static void ist_on_terminate(belle_sip_ist_t *obj){
// belle_sip_transaction_t *base=(belle_sip_transaction_t*)obj;
}
static int ist_send_new_response(belle_sip_ist_t *obj, belle_sip_response_t *resp){
belle_sip_transaction_t *base=(belle_sip_transaction_t*)obj;
int code=belle_sip_response_get_status_code(resp);
int ret=0;
switch(base->state){
case BELLE_SIP_TRANSACTION_PROCEEDING:
if (code==100)
belle_sip_channel_queue_message(base->channel,(belle_sip_message_t*)resp);
break;
default:
break;
}
return ret;
}
static void ist_on_request_retransmission(belle_sip_nist_t *obj){
}
BELLE_SIP_DECLARE_NO_IMPLEMENTED_INTERFACES(belle_sip_ist_t);
......@@ -44,6 +62,8 @@ BELLE_SIP_INSTANCIATE_CUSTOM_VPTR(belle_sip_ist_t)={
},
(void (*)(belle_sip_transaction_t *))ist_on_terminate
},
(int (*)(belle_sip_server_transaction_t*, belle_sip_response_t *))ist_send_new_response,
(void (*)(belle_sip_server_transaction_t*))ist_on_request_retransmission,
}
};
......@@ -51,5 +71,12 @@ BELLE_SIP_INSTANCIATE_CUSTOM_VPTR(belle_sip_ist_t)={
belle_sip_ist_t *belle_sip_ist_new(belle_sip_provider_t *prov, belle_sip_request_t *req){
belle_sip_ist_t *obj=belle_sip_object_new(belle_sip_ist_t);
belle_sip_server_transaction_init((belle_sip_server_transaction_t*)obj,prov,req);
belle_sip_transaction_t *base=(belle_sip_transaction_t*)obj;
belle_sip_response_t *resp;
base->state=BELLE_SIP_TRANSACTION_PROCEEDING;
resp=belle_sip_response_create_from_request(req,100);
belle_sip_server_transaction_send_response((belle_sip_server_transaction_t*)obj,resp);
belle_sip_object_unref(resp);
return obj;
}
......@@ -267,7 +267,6 @@ belle_sip_header_t *belle_sip_message_get_header(belle_sip_message_t *msg, const
return NULL;
}
char *belle_sip_message_to_string(belle_sip_message_t *msg){
return belle_sip_object_to_string(BELLE_SIP_OBJECT(msg));
}
......@@ -422,17 +421,28 @@ static void belle_sip_response_init_default(belle_sip_response_t *resp, int stat
resp->reason_phrase=belle_sip_strdup(phrase);
}
belle_sip_response_t *belle_sip_response_new_from_request(belle_sip_request_t *req, int status_code){
belle_sip_response_t *belle_sip_response_create_from_request(belle_sip_request_t *req, int status_code){
belle_sip_response_t *resp=belle_sip_response_new();
belle_sip_header_t *h;
belle_sip_header_to_t *to;
belle_sip_response_init_default(resp,status_code,NULL);
if (status_code==100){
h=belle_sip_message_get_header((belle_sip_message_t*)req,"timestamp");
belle_sip_message_add_header((belle_sip_message_t*)resp,h);
}
belle_sip_message_add_headers((belle_sip_message_t*)resp,belle_sip_message_get_headers ((belle_sip_message_t*)req,"via"));
belle_sip_message_add_header((belle_sip_message_t*)resp,belle_sip_message_get_header((belle_sip_message_t*)req,"from"));
belle_sip_message_add_header((belle_sip_message_t*)resp,belle_sip_message_get_header((belle_sip_message_t*)req,"to"));
belle_sip_message_add_header((belle_sip_message_t*)resp,belle_sip_message_get_header((belle_sip_message_t*)req,"cseq"));
h=belle_sip_message_get_header((belle_sip_message_t*)req,"to");
if (status_code!=100){
//so that to tag can be added
to=(belle_sip_header_to_t*)belle_sip_object_clone((belle_sip_object_t*)h);
}else{
to=(belle_sip_header_to_t*)h;
}
belle_sip_message_add_header((belle_sip_message_t*)req,(belle_sip_header_t*)to);
h=belle_sip_message_get_header((belle_sip_message_t*)req,"call-id");
if (h) belle_sip_message_add_header((belle_sip_message_t*)resp,h);
belle_sip_message_add_header((belle_sip_message_t*)resp,h);
belle_sip_message_add_header((belle_sip_message_t*)resp,belle_sip_message_get_header((belle_sip_message_t*)req,"cseq"));
return resp;
}
......
......@@ -288,6 +288,11 @@ void belle_sip_provider_send_request(belle_sip_provider_t *p, belle_sip_request_
void belle_sip_provider_send_response(belle_sip_provider_t *p, belle_sip_response_t *resp){
belle_sip_hop_t hop;
belle_sip_channel_t *chan;
belle_sip_header_to_t *to=(belle_sip_header_to_t*)belle_sip_message_get_header((belle_sip_message_t*)resp,"to");
if (belle_sip_response_get_status_code(resp)!=100 && belle_sip_header_to_get_tag(to)==NULL){
belle_sip_fatal("Generation of unique to tags for stateless responses is not implemented.");
}
belle_sip_response_get_return_hop(resp,&hop);
chan=belle_sip_provider_get_channel(p,hop.host, hop.port, hop.transport);
if (chan) belle_sip_channel_queue_message(chan,BELLE_SIP_MESSAGE(resp));
......
......@@ -119,10 +119,12 @@ BELLE_SIP_INSTANCIATE_CUSTOM_VPTR(belle_sip_server_transaction_t)={
void belle_sip_server_transaction_init(belle_sip_server_transaction_t *t, belle_sip_provider_t *prov,belle_sip_request_t *req){
belle_sip_transaction_init((belle_sip_transaction_t*)t,prov,req);
belle_sip_random_token(t->to_tag,sizeof(t->to_tag));
}
void belle_sip_server_transaction_send_response(belle_sip_server_transaction_t *t, belle_sip_response_t *resp){
belle_sip_transaction_t *base=(belle_sip_transaction_t*)t;
belle_sip_header_to_t *to=(belle_sip_header_to_t*)belle_sip_message_get_header((belle_sip_message_t*)resp,"to");
belle_sip_object_ref(resp);
if (!base->last_response){
belle_sip_hop_t hop;
......@@ -131,6 +133,10 @@ void belle_sip_server_transaction_send_response(belle_sip_server_transaction_t *
belle_sip_object_ref(base->channel);
belle_sip_hop_free(&hop);
}
if (belle_sip_header_to_get_tag(to)==NULL && belle_sip_response_get_status_code(resp)!=100){
//add a random to tag
belle_sip_header_to_set_tag(to,t->to_tag);
}
if (BELLE_SIP_OBJECT_VPTR(t,belle_sip_server_transaction_t)->send_new_response(t,resp)==0){
if (base->last_response)
belle_sip_object_unref(base->last_response);
......
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