int sal_message_send(SalOp *op, const char *from, const char *to, const char* content_type, const char *msg){ osip_message_t *sip=NULL; if(op->cid == -1) { /* we are not currently in communication with the destination */ if (from) sal_op_set_from(op,from); if (to) sal_op_set_to(op,to); sal_exosip_fix_route(op); eXosip_lock(); eXosip_message_build_request(&sip,"MESSAGE",sal_op_get_to(op), sal_op_get_from(op),sal_op_get_route(op)); if (sip!=NULL){ sal_exosip_add_custom_headers(sip,op->base.custom_headers); msg_add_current_date(sip); osip_message_set_content_type(sip,content_type); if (msg) osip_message_set_body(sip,msg,strlen(msg)); sal_add_other(op->base.root,op,sip); eXosip_message_send_request(sip); }else{ ms_error("Could not build MESSAGE request !"); } eXosip_unlock(); } else { /* we are currently in communication with the destination */ eXosip_lock(); //First we generate an INFO message to get the current call_id and a good cseq eXosip_call_build_request(op->did,"MESSAGE",&sip); if(sip == NULL) { ms_warning("could not get a build info to send MESSAGE, maybe no previous call established ?"); eXosip_unlock(); return -1; } sal_exosip_add_custom_headers(sip,op->base.custom_headers); msg_add_current_date(sip); osip_message_set_content_type(sip,content_type); if (msg) osip_message_set_body(sip,msg,strlen(msg)); eXosip_call_send_request(op->did,sip); eXosip_unlock(); } return 0; }
int uac_sendInvite(sessionId * id, const sip_entity* to, const alter_message * alter_m) {// char * to, char * message, char *meessageType,char *subject osip_message_t *invite; int i;// optionnal route header char to_[100]; snprintf (to_, 100,"sip:%s@%s", to->username,to->ip); char from_[100]; snprintf (from_, 100,"sip:%s@%s:%s",device_info.ipc_id, device_info.ipc_ip ,device_info.ipc_port ); i = eXosip_call_build_initial_invite (&invite,to_,from_,NULL,alter_m->subject ); if (i != 0) { return -1; } //osip_message_set_supported (invite, "100rel"); { char localip[128]; eXosip_guess_localip (AF_INET, localip, 128); i=osip_message_set_body (invite, alter_m->body, strlen (alter_m->body)); i=osip_message_set_content_type (invite, alter_m->content_type); } eXosip_lock (); i = eXosip_call_send_initial_invite (invite); eXosip_unlock (); //printf("invite->call_id->number:%s size:%d\n",invite->call_id->number,strlen(invite->call_id->number)); //id->call_id=(char *)malloc(sizeof(char)*(strlen(invite->call_id->number)+1)); int copynum=0; if(sizeof(id->call_id)>(strlen(invite->call_id->number)+1)) { copynum=(strlen(invite->call_id->number)+1); } else { copynum=sizeof(id->call_id); } memcpy(id->call_id,invite->call_id->number,copynum);//strlen(invite->call_id->number)+1); //if (i > 0) //{ //eXosip_call_set_reference (i, "ssss"); //} return 0; }
static void add_presence_body(osip_message_t *notify, SalPresenceStatus online_status) { char buf[1000]; char *contact_info; osip_from_t *from=NULL; from=osip_message_get_from(notify); osip_uri_to_str(from->url,&contact_info); mk_presence_body (online_status, contact_info, buf, sizeof (buf), presence_style); osip_message_set_body(notify, buf, strlen(buf)); osip_message_set_content_type(notify, presence_style ? "application/xpidf+xml" : "application/pidf+xml"); osip_free(contact_info); }
int eXosip_build_publish (struct eXosip_t *excontext, osip_message_t ** message, const char *to, const char *from, const char *route, const char *event, const char *expires, const char *ctype, const char *body) { int i; *message = NULL; if (to == NULL || to[0] == '\0') return OSIP_BADPARAMETER; if (from == NULL || from[0] == '\0') return OSIP_BADPARAMETER; if (event == NULL || event[0] == '\0') return OSIP_BADPARAMETER; if (ctype == NULL || ctype[0] == '\0') { if (body != NULL && body[0] != '\0') return OSIP_BADPARAMETER; } else { if (body == NULL || body[0] == '\0') return OSIP_BADPARAMETER; } i = _eXosip_generating_publish (excontext, message, to, from, route); if (i != 0) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "eXosip: cannot send message (cannot build PUBLISH)! ")); return i; } if (body != NULL && body[0] != '\0' && ctype != NULL && ctype[0] != '\0') { osip_message_set_content_type (*message, ctype); osip_message_set_body (*message, body, strlen (body)); /* osip_message_set_header (*message, "Content-Disposition", "render;handling=required"); */ } if (expires != NULL && expires[0] != '\0') osip_message_set_expires (*message, expires); else osip_message_set_expires (*message, "3600"); osip_message_set_header (*message, "Event", event); return OSIP_SUCCESS; }
int uac_send_noSessionMessage(const sip_entity* to_, const alter_message * alter_m) {//,char * to, char * from, char * route,char * content,char * subject osip_message_t *message; char from[4+CHARLEN+1+15+1+4+1]; char to[4+CHARLEN+1+15+1+4+1]; snprintf(from,sizeof(from),"sip:%s@%s:%s",device_info.ipc_id,device_info.ipc_ip,device_info.ipc_port); snprintf(to,sizeof(to),"sip:%s@%s:%d",to_->username,to_->ip,to_->port); eXosip_lock (); eXosip_message_build_request (&message, alter_m->method_type, to,from, alter_m->route); if(alter_m->subject!=NULL) osip_message_set_subject(message,alter_m->subject); osip_message_set_body(message,alter_m->body,strlen(alter_m->body)); osip_message_set_content_type(message,alter_m->content_type); eXosip_message_send_request(message); eXosip_unlock (); return 1; }
int uac_send_message(const sessionId Id, const alter_message * alter_m) { osip_message_t *message; int i; eXosip_lock (); i = eXosip_call_build_request (Id.did,alter_m->method_type/*"MESSAGE" or "INFO"*/, &message); if (i == 0) { if(alter_m->content_type!=NULL) osip_message_set_content_type (message, alter_m->content_type/*"Application/MANSRTSP"*/); if(alter_m->subject!=NULL) osip_message_set_subject(message,alter_m->subject); osip_message_set_body (message, alter_m->body, strlen (alter_m->body)); i = eXosip_call_send_request (Id.did, message); } eXosip_unlock (); return i; }
void call_accept(Call *call) { sdp_context_t *ctx; PayloadType *payload; char *hellofile; static int call_count=0; char record_file[250]; osip_message_t *msg=NULL; sprintf(record_file,"/tmp/sipomatic%i.wav",call_count); ctx=call->sdpc; payload=rtp_profile_get_payload(call->profile,call->audio.pt); if (strcmp(payload->mime_type,"telephone-event")==0){ /* telephone-event is not enough to accept a call */ ms_message("Cannot accept call with only telephone-event.\n"); eXosip_call_send_answer(call->did,415,NULL); call->state=CALL_STATE_FINISHED; return; } if (payload->clock_rate==16000){ hellofile=call->root->file_path16000hz; }else hellofile=call->root->file_path8000hz; eXosip_call_build_answer(call->tid,200,&msg); osip_message_set_content_type(msg,"application/sdp"); osip_message_set_body(msg,call->sdpc->answerstr,strlen(call->sdpc->answerstr)); eXosip_call_send_answer(call->tid,200,msg); call->audio_stream=audio_stream_new(call->audio.localport,call->audio.localport+1,call->root->ipv6); audio_stream_start_with_files(call->audio_stream, call->profile, call->audio.remaddr,call->audio.remoteport,call->audio.remoteport+1, call->audio.pt,20,hellofile,record_file); call_count++; #ifdef VIDEO_ENABLED if (call->video.remoteport!=0){ video_stream_send_only_start(call->video_stream,call->profile, call->video.remaddr,call->video.remoteport,call->video.remoteport+1,call->video.pt, 60, ms_web_cam_manager_get_default_cam(ms_web_cam_manager_get())); } #endif call->time=time(NULL); call->state=CALL_STATE_RUNNING; ms_filter_set_notify_callback(call->audio_stream->soundread,endoffile_cb,(void*)call); }
int uac_send_info(const sessionId Id) { osip_message_t *info; char info_body[1000]; int i; eXosip_lock (); i = eXosip_call_build_info (Id.did, &info); if (i == 0) { snprintf (info_body, 999, "Signal=sss\r\nDuration=250\r\n"); osip_message_set_content_type (info, "Application/MANSRTSP"); osip_message_set_body (info, info_body, strlen (info_body)); i = eXosip_call_send_request (Id.did, info); } else { printf("eXosip_call_build_info error\n"); return 0; } eXosip_unlock (); //成功时返回的i可能是0,如果是0则需要修改,后续在测试修改 return i; }
int csenn_eXosip_invit(sessionId * id, char * to, char * sdpMessage, char * responseSdp) { osip_message_t *invite; int i;// optionnal route header char to_[100]; snprintf (to_, 100,"sip:%s", to); char from_[100]; snprintf (from_, 100, "sip:%s:%s", device_info.ipc_ip ,device_info.ipc_port ); //snprintf (tmp, 4096, ""); /*i = eXosip_call_build_initial_invite (&invite, "sip:[email protected]:5060", "sip:[email protected]:5060", NULL, "34020000001320000001:1,34020000001180000002:1" );*/ i = eXosip_call_build_initial_invite (&invite, to_, from_, NULL, "This is a call for a conversation" ); //i = eXosip_call_build_initial_invite (&invite,"<sip:[email protected]>", "<sip:[email protected]>",NULL, "This is a call for a conversation" ); if (i != 0) { return -1; } //osip_message_set_supported (invite, "100rel"); { char tmp[4096]; char localip[128]; eXosip_guess_localip (AF_INET, localip, 128); localip[128]=device_info.ipc_ip; i=osip_message_set_body (invite, sdpMessage, strlen (sdpMessage)); i=osip_message_set_content_type (invite, "APPLICATION/SDP"); } eXosip_lock (); i = eXosip_call_send_initial_invite (invite); if (i > 0) { //eXosip_call_set_reference (i, "ssss"); } eXosip_unlock (); int flag1 = 1; while (flag1) { eXosip_event_t *je; je = eXosip_event_wait (0, 1000); if (je == NULL) { printf ("No response or the time is over!\n"); break; } switch (je->type) { case EXOSIP_CALL_INVITE: printf ("a new invite reveived!\n"); break; case EXOSIP_CALL_PROCEEDING: printf ("proceeding!\n"); break; case EXOSIP_CALL_RINGING: printf ("ringing!\n"); //printf ("call_id is %d, dialog_id is %d \n", je->cid, je->did); break; case EXOSIP_CALL_ANSWERED: printf ("ok! connected!\n"); printf ("call_id is %d, dialog_id is %d \n", je->cid, je->did); id->cid=je->cid; id->did=je->did; osip_body_t *body; osip_message_get_body (je->response, 0, &body); //printf ("I get the msg is: %s\n", body->body); //(*responseSdp)=(char *)malloc (body->length*sizeof(char)); if(body!=NULL) snprintf (responseSdp, body->length,"%s", body->body); //response a ack osip_message_t *ack = NULL; eXosip_call_build_ack (je->did, &ack); eXosip_call_send_ack (je->did, ack); flag1 = 0; break; case EXOSIP_CALL_CLOSED: printf ("the other sid closed!\n"); break; case EXOSIP_CALL_ACK: printf ("ACK received!\n"); break; default: printf ("other response!\n"); break; } eXosip_event_free (je); } return 0; }
int main (int argc, char *argv[]) { eXosip_event_t *je; osip_message_t *reg = NULL; osip_message_t *invite = NULL; osip_message_t *ack = NULL; osip_message_t *info = NULL; osip_message_t *message = NULL; int call_id, dialog_id; int i,flag; int flag1 = 1; int id; char *identity = "sip:[email protected]"; char *registerer = "sip:192.168.44.100:5060"; char *source_call = "sip:[email protected]"; char *dest_call = "sip:[email protected]:5060"; char command; char tmp[4096]; char localip[128]; printf("r 向服务器注册\n\n"); printf("c 取消注册\n\n"); printf("i 发起呼叫请求\n\n"); printf("h 挂断\n\n"); printf("q 退出程序\n\n"); printf("s 执行方法INFO\n\n"); printf("m 执行方法MESSAGE\n\n"); //初始化 i = eXosip_init (); if (i != 0) { printf ("Couldn't initialize eXosip!\n"); return -1; } else { printf ("eXosip_init successfully!\n"); } i = eXosip_listen_addr (IPPROTO_UDP, NULL, 5060, AF_INET, 0); if (i != 0) { eXosip_quit (); fprintf (stderr, "Couldn't initialize transport layer!\n"); return -1; } flag = 1; while (flag) { printf ("please input the comand:\n"); scanf ("%c", &command); getchar (); switch (command) { case 'r': printf ("This modal isn't commpleted!\n"); break; case 'i':/* INVITE */ i = eXosip_call_build_initial_invite (&invite, dest_call, source_call, NULL, "This si a call for a conversation"); if (i != 0) { printf ("Intial INVITE failed!\n"); break; } //符合SDP格式,其中属性a是自定义格式,也就是说可以存放自己的信息,但是只能是两列,比如帐户信息 //但是经测试,格式:v o t必不可少,原因未知,估计是协议栈在传输时需要检查的 snprintf (tmp, 4096, "v=0\r\n" "o=anonymous 0 0 IN IP4 0.0.0.0\r\n" "t=1 10\r\n" "a=username:rainfish\r\n" "a=password:123\r\n"); osip_message_set_body (invite, tmp, strlen(tmp)); osip_message_set_content_type (invite, "application/sdp"); eXosip_lock (); i = eXosip_call_send_initial_invite (invite); eXosip_unlock (); flag1 = 1; while (flag1) { je = eXosip_event_wait (0, 200); if (je == NULL) { printf ("No response or the time is over!\n"); break; } switch (je->type) { case EXOSIP_CALL_INVITE: printf ("a new invite reveived!\n"); break; case EXOSIP_CALL_PROCEEDING: printf ("proceeding!\n"); break; case EXOSIP_CALL_RINGING: printf ("ringing!\n"); // call_id = je->cid; // dialog_id = je->did; printf ("call_id is %d, dialog_id is %d \n", je->cid, je->did); break; case EXOSIP_CALL_ANSWERED: printf ("ok! connected!\n"); call_id = je->cid; dialog_id = je->did; printf ("call_id is %d, dialog_id is %d \n", je->cid, je->did); eXosip_call_build_ack (je->did, &ack); eXosip_call_send_ack (je->did, ack); flag1 = 0; break; case EXOSIP_CALL_CLOSED: printf ("the other sid closed!\n"); break; case EXOSIP_CALL_ACK: printf ("ACK received!\n"); break; default: printf ("other response!\n"); break; } eXosip_event_free (je); } break; case 'h': printf ("Holded !\n"); eXosip_lock (); eXosip_call_terminate (call_id, dialog_id); eXosip_unlock (); break; case 'c': printf ("This modal isn't commpleted!\n"); break; case 's': //传输INFO方法 eXosip_call_build_info (dialog_id, &info); snprintf (tmp , 4096, "hello,rainfish"); osip_message_set_body (info, tmp, strlen(tmp)); //格式可以任意设定,text/plain代表文本信息 osip_message_set_content_type (info, "text/plain"); eXosip_call_send_request (dialog_id, info); break; case 'm': //传输MESSAGE方法,也就是即时消息,和INFO方法相比,我认为主要区别,是MESSAGE不用建立连接,直接传输信息,而INFO必须 //在建立INVITE的基础上传输。 printf ("the mothed :MESSAGE\n"); eXosip_message_build_request (&message, "MESSAGE", dest_call, source_call, NULL); snprintf (tmp, 4096, "hellor rainfish"); osip_message_set_body (message, tmp, strlen(tmp)); //假设格式是xml osip_message_set_content_type (message, "text/xml"); eXosip_message_send_request (message); break; case 'q': eXosip_quit (); printf ("Exit the setup!\n"); flag = 0; break; } } return (0); }
int uas_invite(sipua_uas_t *sipuas, const char *to, sipua_call_t* call_info, char* sdp_body, int sdp_bytes) { eXosipua_t *jua = (eXosipua_t*)sipuas; osip_message_t *invite; char sdp_size[8]; char* proxy = NULL; int ret; char *from = call_info->user_prof->regname; /* OSIP_TRACE (osip_trace(__FILE__, __LINE__, OSIP_INFO2, NULL, "To: |%s|\n", to)); */ if (0!=jua_check_url(from)) { jua_log(("uas_call: illigal sip id!\n")); return UA_FAIL; } if (0!=jua_check_url(to)) { jua_log(("uas_invite: illigal sip destination\n")); return UA_FAIL; } if(jua->sipuas.proxy[0]!='\0') { proxy = uas_check_route(jua->sipuas.proxy); } #if 0 else { proxy = uas_check_route(call_info->user_prof->registrar); } #endif sprintf(sdp_size,"%i", sdp_bytes); printf("uas_invite: [%s] from %s to %s, proxy[%s]\n", call_info->subject, from, to, proxy); printf("\n-------Initiate SDP [%d bytes]--------\n", sdp_bytes); printf("Callid[%s]\n", call_info->setid.id); printf("----------------------------------------\n"); printf("%s", sdp_body); printf("----------------------------------------\n"); if (eXosip_build_initial_invite(&invite, to, from, proxy, call_info->subject) != 0) return UA_FAIL; /* sdp content of the call */ osip_message_set_content_type(invite, "application/sdp"); osip_message_set_content_length(invite, sdp_size); osip_message_set_body(invite, sdp_body, sdp_bytes); eXosip_lock(); ret = eXosip_initiate_call(invite, call_info, NULL/*negotiation_reference*/, NULL/*local_audio_port*/); eXosip_unlock(); if(proxy) osip_free(proxy); /*When to free it ??? osip_message_free(invite); */ return ret; }
int eXosip_answer_invite_2xx(eXosip_call_t *jc, eXosip_dialog_t *jd, int code, char *local_sdp_port, char *ctct, char *local_video_port, char *public_sdp_port, char *public_video_port) { osip_event_t *evt_answer; osip_message_t *response; int i; char *size; char *body = NULL; osip_transaction_t *tr; tr = eXosip_find_last_inc_invite(jc, jd); if (tr==NULL || tr->orig_request==NULL) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "eXosip: cannot find transaction to answer\n")); return -1; } if (jd!=NULL && jd->d_dialog==NULL) { /* element previously removed */ OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "eXosip: cannot answer this closed transaction\n")); return -1; } /* is the transaction already answered? */ if (tr->state==IST_COMPLETED || tr->state==IST_CONFIRMED || tr->state==IST_TERMINATED) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "eXosip: transaction already answered\n")); return -1; } /* WE SHOULD LOOK FOR A SDP PACKET!! */ if(NULL != osip_list_get(&tr->orig_request->bodies,0)) { body = generating_sdp_answer(tr->orig_request, jc->c_ctx); if (body==NULL) code = 488; /* bad sdp */ } else { if(local_sdp_port==NULL && local_video_port == NULL) code = 488; /* session description in the request is not acceptable. */ else /* body is NULL (contains no SDP), generate a response to INVITE w/ no SDP */ body = generating_no_sdp_answer(jc, jd, tr->orig_request, public_sdp_port ? public_sdp_port : local_sdp_port , public_video_port ? public_video_port : local_video_port); } if (jd==NULL) i = _eXosip_build_response_default(&response, NULL, code, tr->orig_request); else i = _eXosip_build_response_default(&response, jd->d_dialog, code, tr->orig_request); if (i!=0) { OSIP_TRACE(osip_trace(__FILE__,__LINE__,OSIP_INFO1,NULL,"ERROR: Could not create response for invite\n")); code = 500; /* ? which code to use? */ osip_free(body); /* not used */ return -1; } if (code==488) { osip_message_set_content_length(response, "0"); /* TODO: send message to transaction layer */ osip_free(body); evt_answer = osip_new_outgoing_sipmessage(response); evt_answer->transactionid = tr->transactionid; osip_transaction_add_event(tr, evt_answer); __eXosip_wakeup(); return 0; } if ( ! body ) { fprintf(stderr, "%s,%d: body is NULL\n", __FILE__, __LINE__); return -1; } i = osip_message_set_body(response, body, strlen(body)); if (i!=0) { goto g2atii_error_1; } size = (char *) osip_malloc(6*sizeof(char)); #ifdef __APPLE_CC__ sprintf(size,"%li",strlen(body)); #else sprintf(size,"%i",strlen(body)); #endif i = osip_message_set_content_length(response, size); osip_free(size); if (i!=0) goto g2atii_error_1; i = osip_message_set_content_type(response, "application/sdp"); if (i!=0) goto g2atii_error_1; /* request that estabish a dialog: */ /* 12.1.1 UAS Behavior */ { i = complete_answer_that_establish_a_dialog2(response, tr->orig_request, ctct); if (i!=0) goto g2atii_error_1;; /* ?? */ } osip_free(body); /* THIS RESPONSE MUST BE SENT RELIABILY until the final ACK is received !! */ /* this response must be stored at the upper layer!!! (it will be destroyed*/ /* right after being sent! */ if (jd==NULL) { i = eXosip_dialog_init_as_uas(&jd, owsip_transaction_account_get (tr), tr->orig_request, response); if (i!=0) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "eXosip: cannot create dialog!\n")); return -1; } ADD_ELEMENT(jc->c_dialogs, jd); } eXosip_dialog_set_200ok(jd, response); evt_answer = osip_new_outgoing_sipmessage(response); evt_answer->transactionid = tr->transactionid; osip_transaction_add_event(tr, evt_answer); osip_dialog_set_state(jd->d_dialog, DIALOG_CONFIRMED); __eXosip_wakeup(); return 0; g2atii_error_1: osip_free(body); osip_message_free(response); return -1; }
int eXosip_answer_options_2xx(eXosip_call_t *jc, eXosip_dialog_t *jd, int code) { osip_event_t *evt_answer; osip_transaction_t *tr; osip_message_t *response; sdp_message_t *sdp; char *body; char size[10]; int i; tr = eXosip_find_last_inc_options(jc, jd); if (tr==NULL) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "eXosip: cannot find transaction to answer")); return -1; } osip_negotiation_sdp_build_offer(eXosip.osip_negotiation, NULL, &sdp, "10400", NULL); if (sdp==NULL) { return -1; } if (jd!=NULL) { i = _eXosip_build_response_default(&response, jd->d_dialog, code, tr->orig_request); } else { i = _eXosip_build_response_default(&response, NULL, code, tr->orig_request); } if (i!=0) { OSIP_TRACE(osip_trace(__FILE__,__LINE__,OSIP_INFO1,NULL,"ERROR: Could not create response for options\n")); sdp_message_free(sdp); /* not used */ return -1; } i = sdp_message_to_str(sdp, &body); sdp_message_free(sdp); if ( ( i!=0 ) || ( ! body ) ) { osip_message_free(response); return -1; } i = osip_message_set_body(response, body, strlen(body)); if (i!=0) { osip_message_free(response); return -1; } #ifdef __APPLE_CC__ snprintf(size, 9,"%li",strlen(body)); #else snprintf(size, 9,"%i",strlen(body)); #endif i = osip_message_set_content_length(response, size); if (i!=0) { osip_free(body); osip_message_free(response); return -1; } osip_free(body); i = osip_message_set_content_type(response, "application/sdp"); if (i!=0) { osip_message_free(response); return -1; } evt_answer = osip_new_outgoing_sipmessage(response); evt_answer->transactionid = tr->transactionid; osip_transaction_add_event(tr, evt_answer); __eXosip_wakeup(); return 0; }
static char * generating_no_sdp_answer(eXosip_call_t *jc, eXosip_dialog_t *jd, osip_message_t *orig_request, char *local_sdp_port, char *local_video_port) { sdp_message_t *local_sdp = NULL; char *local_body = NULL; char *size; int i; jc->c_ack_sdp = 1; if(osip_negotiation_sdp_build_offer(eXosip.osip_negotiation, NULL, &local_sdp, local_sdp_port, local_video_port) != 0) return NULL; if (local_sdp!=NULL) { int pos=0; while (!sdp_message_endof_media (local_sdp, pos)) { int k = 0; char *tmp = sdp_message_m_media_get (local_sdp, pos); if (0 == strncmp (tmp, "audio", 5)) { char *payload = NULL; do { payload = sdp_message_m_payload_get (local_sdp, pos, k); if (payload == NULL) { } else if (0==strncmp("110",payload,3)) { sdp_message_a_attribute_add (local_sdp, pos, osip_strdup ("AS"), osip_strdup ("110 20")); } else if (0==strncmp("111",payload,3)) { sdp_message_a_attribute_add (local_sdp, pos, osip_strdup ("AS"), osip_strdup ("111 20")); } k++; } while (payload != NULL); } pos++; } } i = sdp_message_to_str(local_sdp, &local_body); if (local_body!=NULL) { size= (char *)osip_malloc(7*sizeof(char)); #ifdef __APPLE_CC__ sprintf(size,"%li",strlen(local_body)); #else sprintf(size,"%i",strlen(local_body)); #endif osip_message_set_content_length(orig_request, size); osip_free(size); osip_message_set_body(orig_request, local_body, strlen(local_body)); osip_message_set_content_type(orig_request, "application/sdp"); } else osip_message_set_content_length(orig_request, "0"); osip_negotiation_ctx_set_local_sdp(jc->c_ctx, local_sdp); OSIP_TRACE(osip_trace(__FILE__,__LINE__,OSIP_INFO3,NULL,"200 OK w/ SDP (RESPONSE TO INVITE w/ NO SDP)=\n%s\n", local_body)); return local_body; }
int sdp_complete_message (int did, sdp_message_t * remote_sdp, osip_message_t * msg) { sdp_media_t *remote_med; char *tmp = NULL; char buf[4096]; int pos; char localip[128]; if (remote_sdp == NULL) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_WARNING, NULL, "No remote SDP body found for call\n")); return -1; } if (msg == NULL) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_WARNING, NULL, "No message to complete\n")); return -1; } eXosip_guess_localip (AF_INET, localip, 128); snprintf (buf, 4096, "v=0\r\n" "o=josua 0 0 IN IP4 %s\r\n" "s=conversation\r\n" "c=IN IP4 %s\r\n" "t=0 0\r\n", localip, localip); pos = 0; while (!osip_list_eol (remote_sdp->m_medias, pos)) { char payloads[128]; int pos2; memset (payloads, '\0', sizeof (payloads)); remote_med = (sdp_media_t *) osip_list_get (remote_sdp->m_medias, pos); if (0 == osip_strcasecmp (remote_med->m_media, "audio")) { pos2 = 0; while (!osip_list_eol (remote_med->m_payloads, pos2)) { tmp = (char *) osip_list_get (remote_med->m_payloads, pos2); if (tmp != NULL && (0 == osip_strcasecmp (tmp, "0") || 0 == osip_strcasecmp (tmp, "8"))) { strcat (payloads, tmp); strcat (payloads, " "); } pos2++; } strcat (buf, "m="); strcat (buf, remote_med->m_media); if (pos2 == 0 || payloads[0] == '\0') { strcat (buf, " 0 RTP/AVP \r\n"); return -1; /* refuse anyway */ } else { strcat (buf, " 10500 RTP/AVP "); strcat (buf, payloads); strcat (buf, "\r\n"); #if 0 if (NULL != strstr (payloads, " 0 ") || (payloads[0] == '0' && payloads[1] == ' ')) strcat (buf, "a=rtpmap:0 PCMU/8000/1\r\n"); if (NULL != strstr (payloads, " 8 ") || (payloads[0] == '8' && payloads[1] == ' ')) strcat (buf, "a=rtpmap:8 PCMA/8000/1\r\n"); #else if (NULL != strstr (payloads, " 0 ") || (payloads[0] == '0' && payloads[1] == ' ')) strcat (buf, "a=rtpmap:0 PCMU/8000\r\n"); if (NULL != strstr (payloads, " 8 ") || (payloads[0] == '8' && payloads[1] == ' ')) strcat (buf, "a=rtpmap:8 PCMA/8000\r\n"); #endif } } else { strcat (buf, "m="); strcat (buf, remote_med->m_media); strcat (buf, " 0 "); strcat (buf, remote_med->m_proto); strcat (buf, " \r\n"); } pos++; } osip_message_set_body (msg, buf, strlen (buf)); osip_message_set_content_type (msg, "application/sdp"); return 0; }
int _eXosip_insubscription_auto_send_notify (int did, int subscription_status, int subscription_reason) { osip_message_t *notify; int i; char xml[4096]; char *entity; eXosip_call_t *jc; eXosip_dialog_t *jd; if (did <= 0) return OSIP_BADPARAMETER; i = eXosip_insubscription_build_notify (did, subscription_status, subscription_reason, ¬ify); if (i != 0) { return i; } /* build dialog xml state */ memset (xml, 0, sizeof (xml)); i = osip_uri_to_str (notify->from->url, &entity); if (i != 0 || entity == NULL) { osip_message_free (notify); return i; } snprintf (xml, sizeof (xml), "<?xml version=\"1.0\"?>" "\r\n" "<dialog-info xmlns=\"urn:ietf:params:xml:ns:dialog-info\"" "\r\n" " version=\"2\" state=\"full\"" "\r\n" " entity=\"%s\">" "\r\n", entity); osip_free (entity); /* loop over all jc/jd */ for (jc = eXosip.j_calls; jc != NULL; jc = jc->next) { for (jd = jc->c_dialogs; jd != NULL; jd = jd->next) { if (jd->d_dialog == NULL) /* finished call */ { } else { char tmp_dialog[2048]; char direction[20]; char dlg_state[20]; char *remote_uri = NULL; if (jd->d_dialog->type == CALLER) strcpy (direction, "initiator"); else strcpy (direction, "recipient"); if (jd->d_dialog->state == DIALOG_CONFIRMED) strcpy (dlg_state, "confirmed"); else strcpy (dlg_state, "early"); if (jd->d_dialog->remote_uri != NULL && jd->d_dialog->remote_uri->url != NULL) { osip_uri_to_str (jd->d_dialog->remote_uri->url, &remote_uri); } if (remote_uri != NULL) { /* add dialog info */ snprintf (tmp_dialog, sizeof (tmp_dialog), " <dialog id=\"%s\" call-id=\"%s\"" "\r\n" " local-tag=\"%s\" remote-tag=\"%s\"" "\r\n" " direction=\"%s\">" "\r\n" " <state>%s</state>" "\r\n" " <remote>" "\r\n" " <identity>%s</identity>" "\r\n" " </remote>" "\r\n" " </dialog>" "\r\n", jd-> d_dialog-> call_id, jd-> d_dialog-> call_id, jd-> d_dialog-> local_tag, jd-> d_dialog-> remote_tag, direction, dlg_state, remote_uri); strcat (xml, tmp_dialog); } } } } strcat (xml, "</dialog-info>" "\r\n"); osip_message_set_content_type (notify, "application/dialog-info+xml"); osip_message_set_body (notify, xml, strlen (xml)); return eXosip_insubscription_send_request (did, notify); }