예제 #1
0
int lp_config_read_file(LpConfig *lpconfig, const char *filename){
	FILE* f=fopen(filename,"r");
	if (f!=NULL){
		lp_config_parse(lpconfig,f);
		fclose(f);
		return 0;
	}
	ms_warning("Fail to open file %s",filename);
	return -1;
}
예제 #2
0
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;
}
예제 #3
0
int lp_config_read_file(LpConfig *lpconfig, const char *filename) {
    FILE* f=fopen(filename,"r");
    if (f!=NULL) {
        ms_message("Reading config information from %s", filename);
        lp_config_parse(lpconfig,f);
        fclose(f);
        return 0;
    }
    ms_warning("Fail to open file %s",filename);
    return -1;
}
예제 #4
0
LpConfig * lp_config_new(const char *filename){
	LpConfig *lpconfig=lp_new0(LpConfig,1);
	if (filename!=NULL){
		lpconfig->filename=strdup(filename);
#ifdef HAVE_SQLITE3
		lpconfig->db = NULL;
		if (sqlite3_open(filename,&lpconfig->db) == SQLITE_OK){
			sqlite3_key(lpconfig->db,SQLITE3_KEY,SQLITE3_KEY_LEN);

			if(!sqlite3_table_new(lpconfig->db));
			lp_config_parse(lpconfig);

			sqlite3_close(lpconfig->db);
		}else{
			//ms_warning("Can't open database: %s\n", sqlite3_errmsg(lpconfig->db));
		}
		lpconfig->db = NULL;
#else
#ifdef _MSC_VER
		lpconfig->file=fopen(lpconfig->filename,"a+b");
#else
		lpconfig->file=fopen(lpconfig->filename,"rw");
#endif // _MSC_VER
		if (lpconfig->file!=NULL){
			lp_config_parse(lpconfig);
			fclose(lpconfig->file);

			/* make existing configuration files non-group/world-accessible */
			//if (chmod(filename, S_IRUSR | S_IWUSR) == -1)
			//	ms_warning("unable to correct permissions on "
			//	  	  "configuration file: %s",
			//		   strerror(errno));
			lpconfig->file=NULL;
			lpconfig->modified=0;
		}
#endif // HAVE_SQLITE3

	}
	return lpconfig;
}
예제 #5
0
int lp_config_read_file(LpConfig *lpconfig, const char *filename){
	char* path = lp_realpath(filename, NULL);
	FILE* f=fopen(path,"r");
	if (f!=NULL){
		ms_message("Reading config information from %s", path);
		lp_config_parse(lpconfig,f);
		fclose(f);
		return 0;
	}
	ms_warning("Fail to open file %s",path);
	ms_free(path);
	return -1;
}
예제 #6
0
파일: lpconfig.c 프로젝트: abdfaye/linphone
int lp_config_read_file(LpConfig *lpconfig, const char *filename){
	char* path = lp_realpath(filename, NULL);
	int fd=-1;
	bctbx_vfs_file_t* pFile = bctbx_file_open(lpconfig->g_bctbx_vfs, path, "r");
	fd = pFile->fd;
	if (fd != -1){
		ms_message("Reading config information from %s", path);
		lp_config_parse(lpconfig, pFile);
		bctbx_file_close(pFile);
		ms_free(path);
		return 0;
	}
	ms_warning("Fail to open file %s",path);
	ms_free(path);
	return -1;
}
예제 #7
0
LpConfig * lp_config_new(const char *filename){
	LpConfig *lpconfig=lp_new0(LpConfig,1);
	if (filename!=NULL){
		lpconfig->filename=ortp_strdup(filename);
		lpconfig->file=fopen(filename,"rw");
		if (lpconfig->file!=NULL){
			lp_config_parse(lpconfig,lpconfig->file);
			fclose(lpconfig->file);			
#if !defined(_WIN32_WCE)
			/* make existing configuration files non-group/world-accessible */
			if (chmod(filename, S_IRUSR | S_IWUSR) == -1)
				ms_warning("unable to correct permissions on "
				  	  "configuration file: %s",
					   strerror(errno));
#endif /*_WIN32_WCE*/
			lpconfig->file=NULL;
			lpconfig->modified=0;
		}
	}
	return lpconfig;
}