char * _belle_sip_object_describe_type(belle_sip_object_vptr_t *vptr){ const int maxbufsize=2048; char *ret=belle_sip_malloc(maxbufsize); belle_sip_object_vptr_t *it; size_t pos=0; belle_sip_list_t *l=NULL,*elem; belle_sip_snprintf(ret,maxbufsize,&pos,"Ownership:\n"); belle_sip_snprintf(ret,maxbufsize,&pos,"\t%s is created initially %s\n",vptr->type_name, vptr->initially_unowned ? "unowned" : "owned"); belle_sip_snprintf(ret,maxbufsize,&pos,"\nInheritance diagram:\n"); for(it=vptr;it!=NULL;it=it->get_parent()){ l=belle_sip_list_prepend(l,it); } for(elem=l;elem!=NULL;elem=elem->next){ it=(belle_sip_object_vptr_t*)elem->data; belle_sip_snprintf(ret,maxbufsize,&pos,"\t%s\n",it->type_name); if (elem->next) belle_sip_snprintf(ret,maxbufsize,&pos,"\t |\n"); } belle_sip_list_free(l); belle_sip_snprintf(ret,maxbufsize,&pos,"\nImplemented interfaces:\n"); for(it=vptr;it!=NULL;it=it->get_parent()){ belle_sip_interface_desc_t **desc=it->interfaces; if (desc!=NULL){ for(;*desc!=NULL;desc++){ belle_sip_snprintf(ret,maxbufsize,&pos,"\t* %s\n",(*desc)->ifname); } } } return ret; }
void belle_sip_object_pool_add(belle_sip_object_pool_t *pool, belle_sip_object_t *obj){ if (obj->pool!=NULL){ belle_sip_fatal("It is not possible to add an object to multiple pools."); } pool->objects=belle_sip_list_prepend(pool->objects,obj); obj->pool_iterator=pool->objects; obj->pool=pool; }
static int belle_sip_dialog_init_as_uac(belle_sip_dialog_t *obj, belle_sip_request_t *req, belle_sip_response_t *resp){ const belle_sip_list_t *elem; belle_sip_header_contact_t *ct=belle_sip_message_get_header_by_type(resp,belle_sip_header_contact_t); belle_sip_header_cseq_t *cseq=belle_sip_message_get_header_by_type(req,belle_sip_header_cseq_t); belle_sip_header_to_t *to=belle_sip_message_get_header_by_type(resp,belle_sip_header_to_t); belle_sip_header_via_t *via=belle_sip_message_get_header_by_type(req,belle_sip_header_via_t); belle_sip_uri_t *requri=belle_sip_request_get_uri(req); if (!to){ belle_sip_error("No to in response."); return -1; } if (!cseq){ belle_sip_error("No cseq in request."); return -1; } if (!via){ belle_sip_error("No via in request."); return -1; } if (strcasecmp(belle_sip_header_via_get_protocol(via),"TLS")==0 && belle_sip_uri_is_secure(requri)){ obj->is_secure=TRUE; } /**12.1.2 * The route set MUST be set to the list of URIs in the Record-Route *header field from the response, taken in reverse order and preserving *all URI parameters. If no Record-Route header field is present in *the response, the route set MUST be set to the empty set. **/ obj->route_set=belle_sip_list_free_with_data(obj->route_set,belle_sip_object_unref); for(elem=belle_sip_message_get_headers((belle_sip_message_t*)resp,BELLE_SIP_RECORD_ROUTE);elem!=NULL;elem=elem->next){ obj->route_set=belle_sip_list_prepend(obj->route_set,belle_sip_object_ref(belle_sip_header_route_create( (belle_sip_header_address_t*)elem->data))); } check_route_set(obj->route_set); /*contact might be provided later*/ if (ct) obj->remote_target=(belle_sip_header_address_t*)belle_sip_object_ref(ct); obj->local_cseq=belle_sip_header_cseq_get_seq_number(cseq); /*call id is already set */ /*local_tag is already set*/ obj->remote_party=(belle_sip_header_address_t*)belle_sip_object_ref(to); /*local party is already set*/ if (strcmp(belle_sip_request_get_method(req),"INVITE")==0){ set_last_out_invite(obj,req); } return 0; }
void belle_sip_listening_point_add_channel(belle_sip_listening_point_t *lp, belle_sip_channel_t *chan){ chan->lp=lp; belle_sip_channel_add_listener(chan,lp->channel_listener); /*add channel listener*/ /*channel is already owned, no ref needed - REVISIT: channel should be initally unowned probably.*/ /* The channel with names must be treated with higher priority by the get_channel() method so queued on front. * This is to prevent the UDP listening point to dispatch incoming messages to channels that were created by inbound connection * where name cannot be determined. When this arrives, there can be 2 channels for the same destination IP and strange problems can occur * where requests are sent through name qualified channel and response received through name unqualified channel. */ if (chan->has_name) lp->channels=belle_sip_list_prepend(lp->channels,chan); else lp->channels=belle_sip_list_append(lp->channels,chan); }
belle_sip_list_t* belle_sip_list_insert(belle_sip_list_t* list, belle_sip_list_t* before, void *data){ belle_sip_list_t* elem; if (list==NULL || before==NULL) return belle_sip_list_append(list,data); for(elem=list;elem!=NULL;elem=belle_sip_list_next(elem)){ if (elem==before){ if (elem->prev==NULL) return belle_sip_list_prepend(list,data); else{ belle_sip_list_t* nelem=belle_sip_list_new(data); nelem->prev=elem->prev; nelem->next=elem; elem->prev->next=nelem; elem->prev=nelem; } } } return list; }
int belle_http_provider_send_request(belle_http_provider_t *obj, belle_http_request_t *req, belle_http_request_listener_t *listener){ belle_sip_channel_t *chan; belle_sip_hop_t *hop=belle_sip_hop_new_from_generic_uri(req->orig_uri ? req->orig_uri : req->req_uri); belle_sip_list_t **channels=provider_get_channels(obj,hop->transport); if (listener) belle_http_request_set_listener(req,listener); chan=belle_sip_channel_find_from_list(*channels,obj->ai_family, hop); if (!chan){ if (strcasecmp(hop->transport,"tcp")==0){ chan=belle_sip_stream_channel_new_client(obj->stack,obj->bind_ip,0,hop->cname,hop->host,hop->port); } #ifdef HAVE_POLARSSL else if (strcasecmp(hop->transport,"tls")==0){ chan=belle_sip_channel_new_tls(obj->stack,obj->verify_ctx,obj->bind_ip,0,hop->cname,hop->host,hop->port); } #endif if (!chan){ belle_sip_error("belle_http_provider_send_request(): cannot create channel for [%s:%s:%i]",hop->transport,hop->cname,hop->port); belle_sip_object_unref(hop); return -1; } belle_http_channel_context_new(chan,obj); *channels=belle_sip_list_prepend(*channels,chan); } belle_sip_object_unref(hop); split_request_url(req); fix_request(req); belle_http_request_set_channel(req,chan); if( req->background_task_id != 0){ req->background_task_id = belle_sip_begin_background_task("belle-sip http", belle_http_end_background_task, req); } belle_sip_channel_queue_message(chan,BELLE_SIP_MESSAGE(req)); return 0; }
static void add_new_object(belle_sip_object_t *obj){ if (belle_sip_leak_detector_enabled && !belle_sip_leak_detector_inhibited){ all_objects=belle_sip_list_prepend(all_objects,obj); } }