int UDT_transport_connect(UDT_transport *udt) { char * remote_ip = NULL; char * remote_port = NULL; remote_ip = ortp_strdup_printf("%s",inet_ntoa(((struct sockaddr_in *)&udt->rtp_session->rtp.rem_addr)->sin_addr)); remote_port = ortp_strdup_printf("%d",ntohs(((struct sockaddr_in *)&udt->rtp_session->rtp.rem_addr)->sin_port)); if (0 != getaddrinfo(remote_ip, remote_port, &udt->hints, &udt->peer)){ return -1; } if (UDT::ERROR == UDT::connect(udt->udt_socket,udt-> peer->ai_addr,udt->peer->ai_addrlen)){ ms_error("connect: %s",UDT::getlasterror().getErrorMessage()); return -2; } //using CC method CUDPBlast* cchandle = NULL; int temp; UDT::getsockopt(udt->udt_socket, 0, UDT_CC, &cchandle, &temp); if (NULL != cchandle) cchandle->setRate(1); ms_free(remote_ip); ms_free(remote_port); return 0; }
void UDT_transport_set_rtp_session(UDT_transport *udt,RtpSession *session){ char *local_port = ortp_strdup_printf("%d", session->rtp.loc_port); udt->rtp_session = session; udt->ortp_transport.session = session; if (0 != getaddrinfo(NULL, local_port, &udt->hints, &udt->local)){ ms_message("incorrect network address."); return; } udt->udt_socket = UDT::socket(udt->local->ai_family, udt->local->ai_socktype, udt->local->ai_protocol); /*设置传输参数*/ UDT::setsockopt(udt->udt_socket, 0, UDT_MSS, new int(ms_get_payload_max_size()), sizeof(int)); //MTU size UDT::setsockopt(udt->udt_socket, 0, UDT_RCVSYN, new bool(true), sizeof(bool)); UDT::setsockopt(udt->udt_socket, 0, UDT_SNDSYN, new bool(true), sizeof(bool)); //非阻塞模式 UDT::setsockopt(udt->udt_socket, 0, UDT_SNDBUF, new int(1024000), sizeof(int)); //接受缓冲 UDT::setsockopt(udt->udt_socket, 0, UDT_RCVBUF, new int(1024000), sizeof(int)); //发送缓冲 UDT::setsockopt(udt->udt_socket, 0, UDT_RCVTIMEO, new int(1), sizeof(int)); //阻塞模式超时设置 UDT::setsockopt(udt->udt_socket, 0, UDT_SNDTIMEO, new int(1), sizeof(int)); //阻塞模式超时设置 UDT::setsockopt(udt->udt_socket, 0, UDT_RENDEZVOUS, new bool(true), sizeof(bool)); if (UDT::ERROR == UDT::bind(udt->udt_socket, rtp_session_get_rtp_socket(udt->rtp_session))){ ms_error("bind: %s",UDT::getlasterror().getErrorMessage()); } ms_free(local_port); }
char * linphone_call_log_to_str(LinphoneCallLog *cl){ char *status; char *tmp; char *from=linphone_address_as_string (cl->from); char *to=linphone_address_as_string (cl->to); switch(cl->status){ case LinphoneCallAborted: status=_("aborted"); break; case LinphoneCallSuccess: status=_("completed"); break; case LinphoneCallMissed: status=_("missed"); break; default: status="unknown"; } tmp=ortp_strdup_printf(_("%s at %s\nFrom: %s\nTo: %s\nStatus: %s\nDuration: %i mn %i sec\n"), (cl->dir==LinphoneCallIncoming) ? _("Incoming call") : _("Outgoing call"), cl->start_date, from, to, status, cl->duration/60, cl->duration%60); ms_free(from); ms_free(to); return tmp; }
void linphone_call_log_completed(LinphoneCall *call){ LinphoneCore *lc=call->core; call->log->duration=time(NULL)-call->start_time; if (call->log->status==LinphoneCallMissed){ char *info; lc->missed_calls++; info=ortp_strdup_printf(ngettext("You have missed %i call.", "You have missed %i calls.", lc->missed_calls), lc->missed_calls); if (lc->vtable.display_status!=NULL) lc->vtable.display_status(lc,info); ms_free(info); } lc->call_logs=ms_list_prepend(lc->call_logs,(void *)call->log); if (ms_list_size(lc->call_logs)>lc->max_call_logs){ MSList *elem,*prevelem=NULL; /*find the last element*/ for(elem=lc->call_logs;elem!=NULL;elem=elem->next){ prevelem=elem; } elem=prevelem; linphone_call_log_destroy((LinphoneCallLog*)elem->data); lc->call_logs=ms_list_remove_link(lc->call_logs,elem); } if (lc->vtable.call_log_updated!=NULL){ lc->vtable.call_log_updated(lc,call->log); } call_logs_write_to_config_file(lc); }
LpConfig *lp_config_new_with_factory(const char *config_filename, const char *factory_config_filename) { LpConfig *lpconfig=lp_new0(LpConfig,1); lpconfig->refcnt=1; if (config_filename!=NULL){ if(ortp_file_exist(config_filename) == 0) { lpconfig->filename=lp_realpath(config_filename, NULL); if(lpconfig->filename == NULL) { ms_error("Could not find the real path of %s: %s", config_filename, strerror(errno)); goto fail; } } else { lpconfig->filename = ms_strdup(config_filename); } lpconfig->tmpfilename=ortp_strdup_printf("%s.tmp",lpconfig->filename); ms_message("Using (r/w) config information from %s", lpconfig->filename); #if !defined(_WIN32) { struct stat fileStat; if ((stat(lpconfig->filename,&fileStat) == 0) && (S_ISREG(fileStat.st_mode))) { /* make existing configuration files non-group/world-accessible */ if (chmod(lpconfig->filename, S_IRUSR | S_IWUSR) == -1) { ms_warning("unable to correct permissions on " "configuration file: %s", strerror(errno)); } } } #endif /*_WIN32*/ /*open with r+ to check if we can write on it later*/ lpconfig->file=fopen(lpconfig->filename,"r+"); #ifdef RENAME_REQUIRES_NONEXISTENT_NEW_PATH if (lpconfig->file==NULL){ lpconfig->file=fopen(lpconfig->tmpfilename,"r+"); if (lpconfig->file){ ms_warning("Could not open %s but %s works, app may have crashed during last sync.",lpconfig->filename,lpconfig->tmpfilename); } } #endif if (lpconfig->file!=NULL){ lp_config_parse(lpconfig,lpconfig->file); fclose(lpconfig->file); lpconfig->file=NULL; lpconfig->modified=0; } } if (factory_config_filename != NULL) { lp_config_read_file(lpconfig, factory_config_filename); } return lpconfig; fail: ms_free(lpconfig); return NULL; }
void payload_type_append_recv_fmtp(PayloadType *pt, const char *fmtp){ if (canWrite(pt)){ if (pt->recv_fmtp==NULL) pt->recv_fmtp=ortp_strdup(fmtp); else{ char *tmp=ortp_strdup_printf("%s;%s",pt->recv_fmtp,fmtp); ortp_free(pt->recv_fmtp); pt->recv_fmtp=tmp; } } }
static void linphone_log_handler(OrtpLogLevel lev, const char *fmt, va_list args){ const char *lname="undef"; char *msg; char *msg_str; switch(lev){ case ORTP_DEBUG: lname="DEBUG"; break; case ORTP_MESSAGE: lname="MESSAGE"; break; case ORTP_WARNING: lname="WARING"; break; case ORTP_ERROR: lname="ERROR"; break; case ORTP_FATAL: lname="FATAL"; break; default: lname = ("Bad level !"); } msg=ortp_strdup_vprintf(fmt,args); msg_str = ortp_strdup_printf("%s: %s\r\n",lname,msg); #ifdef _MSC_VER OutputDebugString(msg_str); #endif ms_free(msg); ms_free(msg_str); }
static void register_failure(SalOp *op, SalError error, SalReason reason, const char *details){ LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op)); LinphoneProxyConfig *cfg=(LinphoneProxyConfig*)sal_op_get_user_pointer(op); if (cfg==NULL){ ms_warning("Registration failed for unknown proxy config."); return ; } if (details==NULL) details=_("no response timeout"); if (lc->vtable.display_status) { char *msg=ortp_strdup_printf(_("Registration on %s failed: %s"),sal_op_get_proxy(op),details ); lc->vtable.display_status(lc,msg); ms_free(msg); } if (error== SalErrorFailure && reason == SalReasonForbidden) { linphone_proxy_config_set_error(cfg, LinphoneReasonBadCredentials); } else if (error == SalErrorNoResponse) { linphone_proxy_config_set_error(cfg, LinphoneReasonNoResponse); } linphone_proxy_config_set_state(cfg,LinphoneRegistrationFailed,details); }
static void register_failure(SalOp *op, SalError error, SalReason reason, const char *details){ LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op)); LinphoneProxyConfig *cfg=(LinphoneProxyConfig*)sal_op_get_user_pointer(op); if (cfg==NULL){ ms_warning("Registration failed for unknown proxy config."); return ; } if (cfg->deletion_date!=0){ ms_message("Registration failed for removed proxy config, ignored"); return; } if (details==NULL) details=_("no response timeout"); if (lc->vtable.display_status) { char *msg=ortp_strdup_printf(_("Registration on %s failed: %s"),sal_op_get_proxy(op),details ); lc->vtable.display_status(lc,msg); ms_free(msg); } linphone_proxy_config_set_error(cfg,linphone_reason_from_sal(reason)); if (error== SalErrorFailure && reason == SalReasonServiceUnavailable && linphone_proxy_config_get_state(cfg) == LinphoneRegistrationOk) { linphone_proxy_config_set_state(cfg,LinphoneRegistrationProgress,_("Service unavailable, retrying")); } else { linphone_proxy_config_set_state(cfg,LinphoneRegistrationFailed,details); } if (cfg->publish_op){ /*prevent publish to be sent now until registration gets successful*/ sal_op_release(cfg->publish_op); cfg->publish_op=NULL; cfg->send_publish=cfg->publish; } }
static void spawn_linphonec(int argc, char *argv[]){ PROCESS_INFORMATION pinfo; STARTUPINFO si; BOOL ret; const char *cmd = "linphoned.exe --pipe -c NUL"; char *args_in_line = argv_to_line(argc, argv); char *cmd_with_args; ZeroMemory( &si, sizeof(si) ); si.cb = sizeof(si); ZeroMemory( &pinfo, sizeof(pinfo) ); if(args_in_line) { cmd_with_args = ortp_strdup_printf("%s %s", cmd, args_in_line); } else { cmd_with_args = ortp_strdup(cmd); } ret=CreateProcess(NULL, cmd_with_args, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pinfo); if(args_in_line) ortp_free(args_in_line); ortp_free(cmd_with_args); if (!ret){ fprintf(stderr,"Spawning of linphoned.exe failed.\n"); }else{ WaitForInputIdle(pinfo.hProcess,1000); } }
static void call_received(SalOp *h){ LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(h)); char *barmesg; LinphoneCall *call; const char *from,*to; char *tmp; LinphoneAddress *from_parsed; LinphoneAddress *from_addr, *to_addr; SalMediaDescription *md; bool_t propose_early_media=lp_config_get_int(lc->config,"sip","incoming_calls_early_media",FALSE); const char *ringback_tone=linphone_core_get_remote_ringback_tone (lc); /* first check if we can answer successfully to this invite */ if (lc->presence_mode==LinphoneStatusBusy || lc->presence_mode==LinphoneStatusOffline || lc->presence_mode==LinphoneStatusDoNotDisturb || lc->presence_mode==LinphoneStatusMoved){ if (lc->presence_mode==LinphoneStatusBusy ) sal_call_decline(h,SalReasonBusy,NULL); else if (lc->presence_mode==LinphoneStatusOffline) sal_call_decline(h,SalReasonTemporarilyUnavailable,NULL); else if (lc->presence_mode==LinphoneStatusDoNotDisturb) sal_call_decline(h,SalReasonTemporarilyUnavailable,NULL); else if (lc->alt_contact!=NULL && lc->presence_mode==LinphoneStatusMoved) sal_call_decline(h,SalReasonRedirect,lc->alt_contact); sal_op_release(h); return; } if (!linphone_core_can_we_add_call(lc)){/*busy*/ sal_call_decline(h,SalReasonBusy,NULL); sal_op_release(h); return; } from=sal_op_get_from(h); to=sal_op_get_to(h); from_addr=linphone_address_new(from); to_addr=linphone_address_new(to); if (is_duplicate_call(lc,from_addr,to_addr)){ ms_warning("Receiving duplicated call, refusing this one."); sal_call_decline(h,SalReasonBusy,NULL); linphone_address_destroy(from_addr); linphone_address_destroy(to_addr); return; } call=linphone_call_new_incoming(lc,from_addr,to_addr,h); sal_call_set_local_media_description(h,call->localdesc); md=sal_call_get_final_media_description(h); if (md && sal_media_description_empty(md)){ sal_call_decline(h,SalReasonMedia,NULL); linphone_call_unref(call); return; } /* the call is acceptable so we can now add it to our list */ linphone_core_add_call(lc,call); from_parsed=linphone_address_new(sal_op_get_from(h)); linphone_address_clean(from_parsed); tmp=linphone_address_as_string(from_parsed); linphone_address_destroy(from_parsed); barmesg=ortp_strdup_printf("%s %s%s",tmp,_("is contacting you"), (sal_call_autoanswer_asked(h)) ?_(" and asked autoanswer."):_(".")); if (lc->vtable.show) lc->vtable.show(lc); if (lc->vtable.display_status) lc->vtable.display_status(lc,barmesg); /* play the ring if this is the only call*/ if (lc->sound_conf.ring_sndcard!=NULL && ms_list_size(lc->calls)==1){ lc->current_call=call; if (lc->ringstream && lc->dmfs_playing_start_time!=0){ ring_stop(lc->ringstream); lc->ringstream=NULL; lc->dmfs_playing_start_time=0; } if(lc->ringstream==NULL && lc->sound_conf.local_ring){ MSSndCard *ringcard=lc->sound_conf.lsd_card ?lc->sound_conf.lsd_card : lc->sound_conf.ring_sndcard; ms_message("Starting local ring..."); lc->ringstream=ring_start(lc->sound_conf.local_ring,2000,ringcard); } else { ms_message("the local ring is already started"); } }else{ /*TODO : play a tone within the context of the current call */ } linphone_call_ref(call); /*prevent the call from being destroyed while we are notifying, if the user declines within the state callback */ linphone_call_set_state(call,LinphoneCallIncomingReceived,"Incoming call"); if (call->state==LinphoneCallIncomingReceived){ sal_call_notify_ringing(h,propose_early_media || ringback_tone!=NULL); if (propose_early_media || ringback_tone!=NULL){ linphone_call_set_state(call,LinphoneCallIncomingEarlyMedia,"Incoming call early media"); linphone_core_update_streams(lc,call,md); } if (sal_call_get_replaces(call->op)!=NULL && lp_config_get_int(lc->config,"sip","auto_answer_replacing_calls",1)){ linphone_core_accept_call(lc,call); } } linphone_call_unref(call); ms_free(barmesg); ms_free(tmp); }
static char *make_pipe_name(const char *name){ return ortp_strdup_printf("\\\\.\\pipe\\%s",name); }
static char *make_pipe_name(const char *name){ return ortp_strdup_printf("/tmp/%s",name); }