static LinphoneCore* configure_lc_from(LinphoneCoreVTable* v_table, const char* path, const char* file, void* user_data) { LinphoneCore* lc; char filepath[256]={0}; char ringpath[256]={0}; char ringbackpath[256]={0}; char rootcapath[256]={0}; char dnsuserhostspath[256]={0}; char nowebcampath[256]={0}; if (path==NULL) path="."; if (file){ sprintf(filepath, "%s/%s", path, file); CU_ASSERT_TRUE_FATAL(ortp_file_exist(filepath)==0); } lc = linphone_core_new(v_table,NULL,*filepath!='\0' ? filepath : NULL, user_data); sal_enable_test_features(lc->sal,TRUE); snprintf(rootcapath, sizeof(rootcapath), "%s/certificates/cn/cafile.pem", path); linphone_core_set_root_ca(lc,rootcapath); sprintf(dnsuserhostspath, "%s/%s", path, userhostsfile); sal_set_dns_user_hosts_file(lc->sal, dnsuserhostspath); snprintf(ringpath,sizeof(ringpath), "%s/sounds/oldphone.wav",path); snprintf(ringbackpath,sizeof(ringbackpath), "%s/sounds/ringback.wav", path); linphone_core_set_ring(lc, ringpath); linphone_core_set_ringback(lc, ringbackpath); snprintf(nowebcampath, sizeof(nowebcampath), "%s/images/nowebcamCIF.jpg", path); linphone_core_set_static_picture(lc,nowebcampath); return lc; }
LinphoneCore* configure_lc_from(LinphoneCoreVTable* v_table, const char* path, const char* file, void* user_data) { LinphoneCore* lc; LpConfig* config = NULL; char *filepath = NULL; char *ringpath = NULL; char *ringbackpath = NULL; char *rootcapath = NULL; char *dnsuserhostspath = NULL; char *nowebcampath = NULL; if (path==NULL) path="."; if (file){ filepath = ms_strdup_printf("%s/%s", path, file); if (ortp_file_exist(filepath) != 0) { ms_fatal("Could not find file %s in path %s, did you configured resources directory correctly?", file, path); } config = lp_config_new_with_factory(NULL,filepath); } // setup dynamic-path assets ringpath = ms_strdup_printf("%s/sounds/oldphone.wav",path); ringbackpath = ms_strdup_printf("%s/sounds/ringback.wav", path); nowebcampath = ms_strdup_printf("%s/images/nowebcamCIF.jpg", path); rootcapath = ms_strdup_printf("%s/certificates/cn/cafile.pem", path); dnsuserhostspath = ms_strdup_printf( "%s/%s", path, userhostsfile); if( config != NULL ) { lp_config_set_string(config, "sound", "remote_ring", ringbackpath); lp_config_set_string(config, "sound", "local_ring" , ringpath); lp_config_set_string(config, "sip", "root_ca" , rootcapath); lc = linphone_core_new_with_config(v_table, config, user_data); } else { lc = linphone_core_new(v_table,NULL,(filepath!=NULL&&filepath[0]!='\0') ? filepath : NULL, user_data); linphone_core_set_ring(lc, ringpath); linphone_core_set_ringback(lc, ringbackpath); linphone_core_set_root_ca(lc,rootcapath); } sal_enable_test_features(lc->sal,TRUE); sal_set_dns_user_hosts_file(lc->sal, dnsuserhostspath); linphone_core_set_static_picture(lc,nowebcampath); linphone_core_enable_ipv6(lc, liblinphone_tester_ipv6_enabled); ms_free(ringpath); ms_free(ringbackpath); ms_free(nowebcampath); ms_free(rootcapath); ms_free(dnsuserhostspath); if( filepath ) ms_free(filepath); if( config ) lp_config_unref(config); return 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; }
/* Called when we start logging, find a good place for the log files, perform rotation, insert the start marker and return the pointer to the file that should be used for logging, or NULL on errors or if disabled. */ static FILE *linphone_gtk_log_init(void) { static char _logdir[1024]; static char _logfname[1024]; static gboolean _log_init = FALSE; const char *dst_fname=NULL; if (!_log_init) { if (linphone_gtk_get_core()!=NULL){ dst_fname = linphone_gtk_get_ui_config("logfile",NULL); dateformat=linphone_gtk_get_ui_config("logfile_date_format",dateformat); } /* For anything to happen, we need a logfile configuration variable, this is our trigger */ if (dst_fname) { /* arrange for _logdir to contain a directory that has been created and _logfname to contain the path to a file to which we will log */ #ifdef _WIN32 const char *appdata=getenv("LOCALAPPDATA"); if (appdata) { snprintf(_logdir, sizeof(_logdir),"%s\\Linphone", appdata); mkdir(_logdir); } else { _logdir[0] = '\0'; } #define PATH_SEPARATOR '\\' #else const char *home=getenv("HOME"); if (home) { snprintf(_logdir, sizeof(_logdir),"%s/.linphone", home); mkdir(_logdir,S_IRUSR | S_IWUSR | S_IRGRP); } else { _logdir[0] = '\0'; } #define PATH_SEPARATOR '/' #endif if (_logdir[0] != '\0') { /* We have a directory, fix the path to the log file in it and open the file so that we will be appending to it. */ snprintf(_logfname, sizeof(_logfname), "%s%c%s",_logdir, PATH_SEPARATOR, dst_fname); } }else if (linphone_logfile!=NULL){ snprintf(_logfname,sizeof(_logfname),"%s",linphone_logfile); } if (_logfname[0]!='\0'){ /* If the constant LOGFILE_ROTATION is greater than zero, then we kick away a simple rotation that will ensure that there are never more than LOGFILE_ROTATION+1 old copies of the log file on the disk. The oldest file is always rotated "away" as expected. Rotated files have the same name as the main log file, though with a number 0..LOGFILE_ROTATION at the end, where the greater the number is, the older the file is. */ if (ortp_file_exist(_logfname)==0 && LOGFILE_ROTATION > 0) { int i; char old_fname[1024]; char new_fname[1024]; /* Rotate away existing files. We make sure to remove the old files otherwise rename() would not work properly. We have to loop in reverse here. */ for (i=LOGFILE_ROTATION-1;i>=0;i--) { snprintf(old_fname, sizeof(old_fname), "%s%c%s.%d", _logdir, PATH_SEPARATOR, dst_fname, i); snprintf(new_fname, sizeof(new_fname), "%s%c%s.%d", _logdir, PATH_SEPARATOR, dst_fname, i+1); if (ortp_file_exist(old_fname)==0) { if (ortp_file_exist(new_fname)==0) unlink(new_fname); rename(old_fname, new_fname); } } /* Move current log file as the first of the rotation. Make sure to remove the old .0 also, since otherwise rename() would not work as expected. */ snprintf(new_fname, sizeof(new_fname), "%s%c%s.%d", _logdir, PATH_SEPARATOR, dst_fname, 0); if (ortp_file_exist(new_fname)==0) unlink(new_fname); rename(_logfname, new_fname); } /* Start a new log file and mark that we have now initialised */ _logfile = fopen(_logfname, "w"); fprintf(_logfile, "%s\n", LOGFILE_MARKER_START); } _log_init = TRUE; } return _logfile; }