diff --git a/coreapi/bellesip_sal/sal_impl.c b/coreapi/bellesip_sal/sal_impl.c index b3877004d..55786af3b 100644 --- a/coreapi/bellesip_sal/sal_impl.c +++ b/coreapi/bellesip_sal/sal_impl.c @@ -693,3 +693,69 @@ void sal_use_dates(Sal *ctx, bool_t enabled){ int sal_auth_compute_ha1(const char* userid,const char* realm,const char* password, char ha1[33]) { return belle_sip_auth_helper_compute_ha1(userid, realm, password, ha1); } + + +SalCustomHeader *sal_custom_header_append(SalCustomHeader *ch, const char *name, const char *value){ + belle_sip_message_t *msg=(belle_sip_message_t*)ch; + belle_sip_header_t *h; + char *tmp=ms_strdup_printf("%s: %s\r\n",name,value); + + if (msg==NULL){ + msg=(belle_sip_message_t*)belle_sip_request_new(); + } + h=BELLE_SIP_HEADER(belle_sip_header_extension_parse(tmp)); + ms_free(tmp); + if (h==NULL){ + belle_sip_error("Fail to parse extension header."); + return (SalCustomHeader*)msg; + } + belle_sip_message_add_header(msg,h); + return (SalCustomHeader*)msg; +} + +const char *sal_custom_header_find(const SalCustomHeader *ch, const char *name){ + belle_sip_header_t *h=belle_sip_message_get_header((belle_sip_message_t*)ch,name); + + if (h){ + if (BELLE_SIP_OBJECT_IS_INSTANCE_OF(h,belle_sip_header_extension_t)){ + return belle_sip_header_extension_get_value(BELLE_SIP_HEADER_EXTENSION(h)); + }else{ + char *tmp=belle_sip_object_to_string((belle_sip_object_t*)h); + char *p=tmp+strlen(belle_sip_header_get_name(h))+1+1; /*header name + : + ' '*/ + char *ret=belle_sip_strdup(p); + belle_sip_free(tmp); + /*TODO: fix memory leak here*/ + + return ret; + } + } + return NULL; +} + +void sal_custom_header_free(SalCustomHeader *ch){ + belle_sip_object_unref((belle_sip_message_t*)ch); +} + +SalCustomHeader *sal_custom_header_clone(const SalCustomHeader *ch){ + return (SalCustomHeader*)belle_sip_object_ref((belle_sip_message_t*)ch); +} + +const SalCustomHeader *sal_op_get_custom_header(SalOp *op){ + SalOpBase *b=(SalOpBase *)op; + return b->custom_headers; +} + +/* + * Warning: this function takes owneship of the custom headers + */ +void sal_op_set_custom_header(SalOp *op, SalCustomHeader* ch){ + SalOpBase *b=(SalOpBase *)op; + if (b->custom_headers){ + sal_custom_header_free(b->custom_headers); + b->custom_headers=NULL; + } + if (ch) belle_sip_object_ref((belle_sip_message_t*)ch); + b->custom_headers=ch; +} + + diff --git a/coreapi/bellesip_sal/sal_impl.h b/coreapi/bellesip_sal/sal_impl.h index a53afd4c8..70f3a45d4 100644 --- a/coreapi/bellesip_sal/sal_impl.h +++ b/coreapi/bellesip_sal/sal_impl.h @@ -89,6 +89,7 @@ struct SalOp{ SalOpType_t type; }; + belle_sdp_session_description_t * media_description_to_sdp(const SalMediaDescription *sal); int sdp_to_media_description(belle_sdp_session_description_t *sdp, SalMediaDescription *desc); belle_sip_request_t* sal_op_build_request(SalOp *op,const char* method); @@ -126,4 +127,6 @@ SalAuthInfo* sal_auth_info_create(belle_sip_auth_event_t* event) ; void sal_add_pending_auth(Sal *sal, SalOp *op); void sal_add_presence_info(belle_sip_message_t *notify, SalPresenceStatus online_status); + + #endif /* SAL_IMPL_H_ */ diff --git a/coreapi/bellesip_sal/sal_op_call.c b/coreapi/bellesip_sal/sal_op_call.c index d399b11d1..5b2c3c8e1 100644 --- a/coreapi/bellesip_sal/sal_op_call.c +++ b/coreapi/bellesip_sal/sal_op_call.c @@ -82,13 +82,14 @@ static int set_sdp(belle_sip_message_t *msg,belle_sdp_session_description_t* ses belle_sip_header_content_type_t* content_type ; belle_sip_header_content_length_t* content_length; int length; - char buff[1024]; + char buff[2048]; if (session_desc) { content_type = belle_sip_header_content_type_create("application","sdp"); length = belle_sip_object_marshal(BELLE_SIP_OBJECT(session_desc),buff,0,sizeof(buff)); - if (length==sizeof(buff)) { + if (length>=sizeof(buff)) { ms_error("Buffer too small or sdp too big"); + return -1; } content_length= belle_sip_header_content_length_create(length); @@ -205,7 +206,7 @@ static void call_response_event(void *op_base, const belle_sip_response_event_t set_or_update_dialog(op,belle_sip_response_event_get_dialog(event)); dialog_state=op->dialog?belle_sip_dialog_get_state(op->dialog):BELLE_SIP_DIALOG_NULL; - switch(dialog_state) { + switch(dialog_state) { case BELLE_SIP_DIALOG_NULL: case BELLE_SIP_DIALOG_EARLY: { diff --git a/coreapi/bellesip_sal/sal_op_call_transfer.c b/coreapi/bellesip_sal/sal_op_call_transfer.c index 5afa9d8dc..4062bb30a 100644 --- a/coreapi/bellesip_sal/sal_op_call_transfer.c +++ b/coreapi/bellesip_sal/sal_op_call_transfer.c @@ -192,7 +192,6 @@ void sal_op_process_refer(SalOp *op, const belle_sip_request_event_t *event){ } void sal_op_call_process_notify(SalOp *op, const belle_sip_request_event_t *event){ - belle_sip_server_transaction_t* server_transaction = belle_sip_provider_create_server_transaction(op->base.root->prov,belle_sip_request_event_get_request(event)); belle_sip_request_t* req = belle_sip_request_event_get_request(event); const char* body = belle_sip_message_get_body(BELLE_SIP_MESSAGE(req)); @@ -202,34 +201,32 @@ void sal_op_call_process_notify(SalOp *op, const belle_sip_request_event_t *even ms_message("Receiving NOTIFY request on op [%p]",op); if (header_event - && strcasecmp(belle_sip_header_extension_get_value(BELLE_SIP_HEADER_EXTENSION(header_event)),"refer")==0 - && content_type - && strcmp(belle_sip_header_content_type_get_type(content_type),"message")==0 - && strcmp(belle_sip_header_content_type_get_subtype(content_type),"sipfrag")==0 - && body){ - belle_sip_response_t* sipfrag=BELLE_SIP_RESPONSE(belle_sip_message_parse(body)); + && strncasecmp(belle_sip_header_extension_get_value(BELLE_SIP_HEADER_EXTENSION(header_event)),"refer",strlen("refer"))==0 + && content_type + && strcmp(belle_sip_header_content_type_get_type(content_type),"message")==0 + && strcmp(belle_sip_header_content_type_get_subtype(content_type),"sipfrag")==0 + && body){ + belle_sip_response_t* sipfrag=BELLE_SIP_RESPONSE(belle_sip_message_parse(body)); - if (sipfrag){ - - int code=belle_sip_response_get_status_code(sipfrag); - SalReferStatus status=SalReferFailed; - if (code==100){ - status=SalReferTrying; - }else if (code==200){ - status=SalReferSuccess; - }else if (code>=400){ - status=SalReferFailed; - } - belle_sip_object_unref(sipfrag); - resp = belle_sip_response_create_from_request(req,200); - belle_sip_server_transaction_send_response(server_transaction,resp); - op->base.root->callbacks.notify_refer(op,status); - } - }else{ - ms_error("Notify without sipfrag, trashing"); - resp = belle_sip_response_create_from_request(req,501); + if (sipfrag){ + int code=belle_sip_response_get_status_code(sipfrag); + SalReferStatus status=SalReferFailed; + if (code==100){ + status=SalReferTrying; + }else if (code==200){ + status=SalReferSuccess; + }else if (code>=400){ + status=SalReferFailed; + } + belle_sip_object_unref(sipfrag); + resp = belle_sip_response_create_from_request(req,200); belle_sip_server_transaction_send_response(server_transaction,resp); + op->base.root->callbacks.notify_refer(op,status); } - + }else{ + ms_error("Notify without sipfrag, trashing"); + resp = belle_sip_response_create_from_request(req,501); + belle_sip_server_transaction_send_response(server_transaction,resp); + } } diff --git a/coreapi/bellesip_sal/sal_sdp.c b/coreapi/bellesip_sal/sal_sdp.c index 1aa7f004c..1b75f4293 100644 --- a/coreapi/bellesip_sal/sal_sdp.c +++ b/coreapi/bellesip_sal/sal_sdp.c @@ -204,7 +204,8 @@ belle_sdp_session_description_t * media_description_to_sdp ( const SalMediaDescr belle_sdp_session_description_set_session_name ( session_desc,belle_sdp_session_name_create ( "Talk" ) ); - if ( !sal_media_description_has_dir ( desc,SalStreamSendOnly ) && !sal_media_description_has_dir ( desc,SalStreamInactive ) ) { + if ( (!sal_media_description_has_dir ( desc,SalStreamSendOnly ) && !sal_media_description_has_dir ( desc,SalStreamInactive )) + || desc->ice_ufrag[0] != '\0' ) { belle_sdp_session_description_set_connection ( session_desc ,belle_sdp_connection_create ( "IN",inet6 ? "IP6" :"IP4",desc->addr ) ); diff --git a/coreapi/sal.c b/coreapi/sal.c index fa7277261..407d0fc2e 100644 --- a/coreapi/sal.c +++ b/coreapi/sal.c @@ -487,61 +487,6 @@ void sal_auth_info_delete(const SalAuthInfo* auth_info) { ms_free((void*)auth_info); } -SalCustomHeader *sal_custom_header_append(SalCustomHeader *ch, const char *name, const char *value){ - SalCustomHeader *h=ms_new0(SalCustomHeader,1); - h->header_name=ms_strdup(name); - h->header_value=ms_strdup(value); - h->node.data=h; - return (SalCustomHeader*)ms_list_append_link((MSList*)ch,(MSList*)h); -} - -const char *sal_custom_header_find(const SalCustomHeader *ch, const char *name){ - const MSList *it; - for (it=(const MSList*)ch;it!=NULL;it=it->next){ - const SalCustomHeader *itch=(const SalCustomHeader *)it; - if (strcasecmp(itch->header_name,name)==0) - return itch->header_value; - } - return NULL; -} - -static void sal_custom_header_uninit(SalCustomHeader *ch){ - ms_free(ch->header_name); - ms_free(ch->header_value); -} - -void sal_custom_header_free(SalCustomHeader *ch){ - ms_list_for_each((MSList*)ch,(void (*)(void*))sal_custom_header_uninit); - ms_list_free((MSList *)ch); -} - -SalCustomHeader *sal_custom_header_clone(const SalCustomHeader *ch){ - const MSList *it; - SalCustomHeader *ret=NULL; - for (it=(const MSList*)ch;it!=NULL;it=it->next){ - const SalCustomHeader *itch=(const SalCustomHeader *)it; - ret=sal_custom_header_append(ret,itch->header_name,itch->header_value); - } - return ret; -} - -const SalCustomHeader *sal_op_get_custom_header(SalOp *op){ - SalOpBase *b=(SalOpBase *)op; - return b->custom_headers; -} - -/* - * Warning: this function takes owneship of the custom headers - */ -void sal_op_set_custom_header(SalOp *op, SalCustomHeader* ch){ - SalOpBase *b=(SalOpBase *)op; - if (b->custom_headers){ - sal_custom_header_free(b->custom_headers); - b->custom_headers=NULL; - } - b->custom_headers=ch; -} - const char* sal_stream_type_to_string(SalStreamType type) { diff --git a/include/sal/sal.h b/include/sal/sal.h index 9b715eb63..ecb6bb314 100644 --- a/include/sal/sal.h +++ b/include/sal/sal.h @@ -515,11 +515,6 @@ int sal_ping(SalOp *op, const char *from, const char *to); /*misc*/ void sal_get_default_local_ip(Sal *sal, int address_family, char *ip, size_t iplen); -struct SalCustomHeader{ - MSList node; - char *header_name; - char *header_value; -}; SalCustomHeader *sal_custom_header_append(SalCustomHeader *ch, const char *name, const char *value); const char *sal_custom_header_find(const SalCustomHeader *ch, const char *name);