static void assign_string(char **str, const char *arg){ if (*str){ ms_free(*str); *str=NULL; } if (arg) *str=ms_strdup(arg); }
void video_stream_set_display_filter_name(VideoStream *s, const char *fname){ if (s->display_name!=NULL){ ms_free(s->display_name); s->display_name=NULL; } if (fname!=NULL) s->display_name=ms_strdup(fname); }
void ms_plugins_init(void) { if (ms_plugins_ref++ >0 ) { ms_message ("Skiping ms_plugins_init, because [%i] ref",ms_plugins_ref); return; } if (plugins_dir == NULL) { #ifdef PACKAGE_PLUGINS_DIR plugins_dir = ms_strdup(PACKAGE_PLUGINS_DIR); #else plugins_dir = ms_strdup(""); #endif } if (strlen(plugins_dir) > 0) { ms_message("Loading ms plugins from [%s]",plugins_dir); ms_load_plugins(plugins_dir); } }
LinphoneCallParams * linphone_call_params_copy(const LinphoneCallParams *cp){ unsigned int i; LinphoneCallParams *ncp=linphone_call_params_new(); memcpy(ncp,cp,sizeof(LinphoneCallParams)); if (cp->record_file) ncp->record_file=ms_strdup(cp->record_file); if (cp->session_name) ncp->session_name=ms_strdup(cp->session_name); /* * The management of the custom headers is not optimal. We copy everything while ref counting would be more efficient. */ if (cp->custom_headers) ncp->custom_headers=sal_custom_header_clone(cp->custom_headers); if (cp->custom_sdp_attributes) ncp->custom_sdp_attributes = sal_custom_sdp_attribute_clone(cp->custom_sdp_attributes); for (i = 0; i < (unsigned int)LinphoneStreamTypeUnknown; i++) { if (cp->custom_sdp_media_attributes[i]) ncp->custom_sdp_media_attributes[i] = sal_custom_sdp_attribute_clone(cp->custom_sdp_media_attributes[i]); } return ncp; }
static MSList * parse_tags(const char *tags) { MSList *tags_list = NULL; char *t; char *p; if ((tags == NULL) || (tags[0] == '\0')) return NULL; p = t = ms_strdup(tags); while (p != NULL) { char *next = strstr(p, ","); if (next != NULL) { *(next++) = '\0'; } tags_list = ms_list_append(tags_list, ms_strdup(p)); p = next; } ms_free(t); return tags_list; }
void sal_set_uuid(Sal *sal, const char *uuid){ if (sal->uuid){ ms_free(sal->uuid); sal->uuid=NULL; } if (uuid) sal->uuid=ms_strdup(uuid); }
void sal_add_supported_tag(Sal *ctx, const char* tag){ bctbx_list_t *elem=bctbx_list_find_custom(ctx->supported_tags,(bctbx_compare_func)strcasecmp,tag); if (!elem){ ctx->supported_tags=bctbx_list_append(ctx->supported_tags,ms_strdup(tag)); make_supported_header(ctx); } }
static void simple_analyzer_suggest_action(MSQosAnalyzer *objbase, MSRateControlAction *action){ MSSimpleQosAnalyzer *obj=(MSSimpleQosAnalyzer*)objbase; rtpstats_t *cur=&obj->stats[obj->curindex % STATS_HISTORY]; /*big losses and big jitter */ if (cur->lost_percentage>=unacceptable_loss_rate && cur->int_jitter>=big_jitter){ action->type=MSRateControlActionDecreaseBitrate; action->value=(int)MIN(cur->lost_percentage,50); ms_message("MSSimpleQosAnalyzer: loss rate unacceptable and big jitter"); }else if (simple_rt_prop_increased(obj)){ action->type=MSRateControlActionDecreaseBitrate; action->value=20; ms_message("MSSimpleQosAnalyzer: rt_prop doubled."); }else if (cur->lost_percentage>=unacceptable_loss_rate){ /*big loss rate but no jitter, and no big rtp_prop: pure lossy network*/ action->type=MSRateControlActionDecreaseBitrate; action->value=(int)MIN(cur->lost_percentage,50); ms_message("MSSimpleQosAnalyzer: loss rate unacceptable."); }else{ action->type=MSRateControlActionDoNothing; ms_message("MSSimpleQosAnalyzer: everything is fine."); } if (objbase->on_action_suggested!=NULL){ int i; char *data[4]; int datac = sizeof(data) / sizeof(data[0]); data[0]=ms_strdup("%loss rt_prop_increased int_jitter_ms rt_prop_ms"); data[1]=ms_strdup_printf("%d %d %d %d" , (int)cur->lost_percentage , (simple_rt_prop_increased(obj)==TRUE) , (int)cur->int_jitter , (int)(1000*cur->rt_prop)); data[2]=ms_strdup("action_type action_value"); data[3]=ms_strdup_printf("%s %d" , ms_rate_control_action_type_name(action->type) , action->value); objbase->on_action_suggested(objbase->on_action_suggested_user_pointer, datac, (const char**)data); for (i=0;i<datac;++i){ ms_free(data[i]); } } }
static void v4l2_init(MSFilter *f){ V4l2State *s=ms_new0(V4l2State,1); s->dev=ms_strdup("/dev/video0"); s->fd=-1; s->vsize=MS_VIDEO_SIZE_CIF; s->fps=15; s->configured=FALSE; f->data=s; }
void linphone_proxy_config_set_sip_setup(LinphoneProxyConfig *cfg, const char *type){ if (cfg->type) ms_free(cfg->type); cfg->type=ms_strdup(type); if (linphone_proxy_config_get_addr(cfg)==NULL){ /*put a placeholder so that the sip setup gets saved into the config */ linphone_proxy_config_set_server_addr(cfg,"sip:undefined"); } }
void linphone_tunnel_config_set_host(LinphoneTunnelConfig *tunnel, const char *host) { if(tunnel->host != NULL) { ms_free(tunnel->host); tunnel->host = NULL; } if(host != NULL && strlen(host)) { tunnel->host = ms_strdup(host); } }
static LinphoneEvent * linphone_event_new_base(LinphoneCore *lc, LinphoneSubscriptionDir dir, const char *name, SalOp *op){ LinphoneEvent *lev=belle_sip_object_new(LinphoneEvent); lev->lc=lc; lev->dir=dir; lev->op=op; lev->name=ms_strdup(name); sal_op_set_user_pointer(lev->op,lev); return lev; }
static MSSndCard *winsndcard_new(const char *name, int in_dev, int out_dev, unsigned cap){ MSSndCard *card=ms_snd_card_new(&winsnd_card_desc); WinSndCard *d=(WinSndCard*)card->data; card->name=ms_strdup(name); d->in_devid=in_dev; d->out_devid=out_dev; card->capabilities=cap; return card; }
static void pulse_card_detect(MSSndCardManager *m){ MSSndCard *card=ms_snd_card_new(&pulse_card_desc); if (card!=NULL){ card->name=ms_strdup("default"); card->capabilities=MS_SND_CARD_CAP_CAPTURE|MS_SND_CARD_CAP_PLAYBACK; ms_snd_card_manager_add_card(m,card); init_pulse_context(); } }
void sal_op_set_entity_tag(SalOp *op, const char* entity_tag) { SalOpBase* op_base = (SalOpBase*)op; if (op_base->entity_tag != NULL){ ms_free(op_base->entity_tag); } if (entity_tag) op_base->entity_tag = ms_strdup(entity_tag); else op_base->entity_tag = NULL; }
void linphone_friend_list_set_display_name(LinphoneFriendList *list, const char *display_name) { if (list->display_name != NULL) { ms_free(list->display_name); list->display_name = NULL; } if (display_name != NULL) { list->display_name = ms_strdup(display_name); linphone_core_store_friends_list_in_db(list->lc, list); } }
static MSSndCard *ca_card_new(const char *name, CFStringRef uidname, AudioDeviceID dev, unsigned cap) { MSSndCard *card = ms_snd_card_new(&ca_card_desc); CaSndDsCard *d = (CaSndDsCard *) card->data; d->uidname = uidname; d->dev = dev; card->name = ms_strdup(name); card->capabilities = cap; return card; }
static void linphone_call_audiostream_auth_token_ready(void *data, const char* auth_token, bool_t verified) { LinphoneCall *call=(LinphoneCall *)data; if (call->auth_token != NULL) ms_free(call->auth_token); call->auth_token=ms_strdup(auth_token); call->auth_token_verified=verified; ms_message("Authentication token is %s (%s)", auth_token, verified?"verified":"unverified"); }
void linphone_friend_set_ref_key(LinphoneFriend *lf, const char *key){ if (lf->refkey!=NULL){ ms_free(lf->refkey); lf->refkey=NULL; } if (key) lf->refkey=ms_strdup(key); if (lf->lc) linphone_core_write_friends_config(lf->lc); }
void linphone_friend_list_set_uri(LinphoneFriendList *list, const char *uri) { if (list->uri != NULL) { ms_free(list->uri); list->uri = NULL; } if (uri != NULL) { list->uri = ms_strdup(uri); linphone_core_store_friends_list_in_db(list->lc, list); } }
// Callback for sql request when getting linphone content static int callback_content(void *data, int argc, char **argv, char **colName) { LinphoneChatMessage *message = (LinphoneChatMessage *)data; if (message->file_transfer_information) { linphone_content_uninit(message->file_transfer_information); ms_free(message->file_transfer_information); message->file_transfer_information = NULL; } message->file_transfer_information = (LinphoneContent *)malloc(sizeof(LinphoneContent)); memset(message->file_transfer_information, 0, sizeof(*(message->file_transfer_information))); message->file_transfer_information->type = argv[1] ? ms_strdup(argv[1]) : NULL; message->file_transfer_information->subtype = argv[2] ? ms_strdup(argv[2]) : NULL; message->file_transfer_information->name = argv[3] ? ms_strdup(argv[3]) : NULL; message->file_transfer_information->encoding = argv[4] ? ms_strdup(argv[4]) : NULL; message->file_transfer_information->size = (size_t) atoi(argv[5]); return 0; }
static bool_t open_file(JpegWriter *obj, const char *filename) { obj->filename=ms_strdup(filename); obj->tmpFilename=ms_strdup_printf("%s.part",filename); obj->file = fopen(obj->tmpFilename, "wb"); if(!obj->file) { ms_error("Could not open %s for write", obj->tmpFilename); close_file(obj,FALSE); } return TRUE; }
void sal_op_set_remote_ua(SalOp*op,belle_sip_message_t* message) { belle_sip_header_user_agent_t* user_agent=belle_sip_message_get_header_by_type(message,belle_sip_header_user_agent_t); char user_agent_string[256]; if (user_agent && belle_sip_header_user_agent_get_products_as_string(user_agent,user_agent_string,sizeof(user_agent_string))>0) { if (op->base.remote_ua!=NULL){ ms_free(op->base.remote_ua); } op->base.remote_ua=ms_strdup(user_agent_string); } }
void sal_set_root_ca(Sal* ctx, const char* rootCa){ if (ctx->root_ca){ ms_free(ctx->root_ca); ctx->root_ca=NULL; } if (rootCa) ctx->root_ca=ms_strdup(rootCa); set_tls_properties(ctx); return ; }
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 call_logs_read_from_config_file(LinphoneCore *lc){ char logsection[32]; int i; const char *tmp; uint64_t sec; LpConfig *cfg=lc->config; for(i=0;;++i){ snprintf(logsection,sizeof(logsection),"call_log_%i",i); if (lp_config_has_section(cfg,logsection)){ LinphoneCallLog *cl; LinphoneAddress *from=NULL,*to=NULL; tmp=lp_config_get_string(cfg,logsection,"from",NULL); if (tmp) from=linphone_address_new(tmp); tmp=lp_config_get_string(cfg,logsection,"to",NULL); if (tmp) to=linphone_address_new(tmp); if (!from || !to) continue; cl=linphone_call_log_new(lp_config_get_int(cfg,logsection,"dir",0),from,to); cl->status=lp_config_get_int(cfg,logsection,"status",0); sec=lp_config_get_int64(cfg,logsection,"start_date_time",0); if (sec) { /*new call log format with date expressed in seconds */ cl->start_date_time=(time_t)sec; set_call_log_date(cl,cl->start_date_time); }else{ tmp=lp_config_get_string(cfg,logsection,"start_date",NULL); if (tmp) { strncpy(cl->start_date,tmp,sizeof(cl->start_date)); cl->start_date_time=string_to_time(cl->start_date); } } cl->duration=lp_config_get_int(cfg,logsection,"duration",0); tmp=lp_config_get_string(cfg,logsection,"refkey",NULL); if (tmp) cl->refkey=ms_strdup(tmp); cl->quality=lp_config_get_float(cfg,logsection,"quality",-1); cl->video_enabled=lp_config_get_int(cfg,logsection,"video_enabled",0); tmp=lp_config_get_string(cfg,logsection,"call_id",NULL); if (tmp) cl->call_id=ms_strdup(tmp); lc->call_logs=ms_list_append(lc->call_logs,cl); }else break; } }
static void bb10camera_detect(MSWebCamManager *obj) { camera_error_t error; camera_handle_t handle; error = camera_open(CAMERA_UNIT_FRONT, CAMERA_MODE_RW, &handle); if (error == CAMERA_EOK) { if (camera_has_feature(handle, CAMERA_FEATURE_VIDEO)) { if (camera_can_feature(handle, CAMERA_FEATURE_VIDEO)) { MSWebCam *cam = ms_web_cam_new(&ms_bb10_camera_desc); cam->name = ms_strdup("BB10 Front Camera"); ms_message("[bb10_capture] camera added: %s", cam->name); ms_web_cam_manager_add_cam(obj, cam); camera_close(handle); } else { ms_warning("[bb10_capture] front camera has video feature but can't do it..."); } } else { ms_warning("[bb10_capture] front camera doesn't have video feature"); } } else { ms_warning("[bb10_capture] Can't open front camera: %s", error_to_string(error)); } error = camera_open(CAMERA_UNIT_REAR, CAMERA_MODE_RW, &handle); if (error == CAMERA_EOK) { if (camera_has_feature(handle, CAMERA_FEATURE_VIDEO)) { if (camera_can_feature(handle, CAMERA_FEATURE_VIDEO)) { MSWebCam *cam = ms_web_cam_new(&ms_bb10_camera_desc); cam->name = ms_strdup("BB10 Rear Camera"); ms_message("[bb10_capture] camera added: %s", cam->name); ms_web_cam_manager_add_cam(obj, cam); camera_close(handle); } else { ms_warning("[bb10_capture] rear camera has video feature but can't do it..."); } } else { ms_warning("[bb10_capture] rear camera doesn't have video feature"); } } else { ms_warning("[bb10_capture] Can't open rear camera: %s", error_to_string(error)); } }
MSSndCard * ms_snd_card_new_with_name(MSSndCardDesc *desc,const char* name) { MSSndCard *obj=(MSSndCard *)ms_new(MSSndCard,1); obj->desc=desc; obj->name=name?ms_strdup(name):NULL; obj->data=NULL; obj->id=NULL; obj->capabilities=MS_SND_CARD_CAP_CAPTURE|MS_SND_CARD_CAP_PLAYBACK; if (desc->init!=NULL) desc->init(obj); return obj; }
static char* get_public_contact_ip(LinphoneCore* lc) { long contact_host_ip_len; char contact_host_ip[255]; char * contact = linphone_proxy_config_get_contact(linphone_core_get_default_proxy_config(lc)); CU_ASSERT_PTR_NOT_NULL(contact); contact_host_ip_len = strchr(contact, ':')-contact; strncpy(contact_host_ip, contact, contact_host_ip_len); contact_host_ip[contact_host_ip_len]='\0'; ms_free(contact); return ms_strdup(contact_host_ip); }
MSMediaPlayer *ms_media_player_new(MSSndCard *snd_card, const char *video_display_name, void *window_id) { MSMediaPlayer *obj = (MSMediaPlayer *)ms_new0(MSMediaPlayer, 1); obj->ticker = ms_ticker_new(); ms_mutex_init(&obj->cb_access, NULL); obj->snd_card = snd_card; if(video_display_name != NULL && strlen(video_display_name) > 0) { obj->video_display = ms_strdup(video_display_name); obj->window_id = window_id; } return obj; }