LpItem * lp_item_new(const char *key, const char *value,bool_t changed){ LpItem *item=lp_new0(LpItem,1); item->key=strdup(key); item->value=strdup(value); item->old_value = strdup(value); item->modified = changed; return item; }
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; }
LpItem * lp_comment_new(const char *comment){ LpItem *item=lp_new0(LpItem,1); char* pos = NULL; item->value=ortp_strdup(comment); pos=strchr(item->value,'\r'); if (pos==NULL) pos=strchr(item->value,'\n'); if(pos) { *pos='\0'; /*replace the '\n' */ } item->is_comment=TRUE; return item; }
LpConfig * lp_config_new_from_buffer(const char *buffer){ LpConfig* conf = lp_new0(LpConfig,1); LpSection* current_section = NULL; char* ptr = ms_strdup(buffer); char* strtok_storage = NULL; char* line = strtok_r(ptr, "\n", &strtok_storage); conf->refcnt=1; while( line != NULL ){ current_section = lp_config_parse_line(conf,line,current_section); line = strtok_r(NULL, "\n", &strtok_storage); } ms_free(ptr); return conf; }
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; }
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; }
LpSection *lp_section_new(const char *name){ LpSection *sec=lp_new0(LpSection,1); sec->name=ortp_strdup(name); return sec; }
LpItem * lp_item_new(const char *key, const char *value){ LpItem *item=lp_new0(LpItem,1); item->key=ortp_strdup(key); item->value=ortp_strdup(value); return item; }
LpSectionParam *lp_section_param_new(const char *key, const char *value){ LpSectionParam *param = lp_new0(LpSectionParam, 1); param->key = ortp_strdup(key); param->value = ortp_strdup(value); return param; }