diff --git a/source/libublsettings.c b/source/libublsettings.c index 8e0c533..fe57668 100644 --- a/source/libublsettings.c +++ b/source/libublsettings.c @@ -419,6 +419,20 @@ char *yon_char_append(const char *source, const char *append) return NULL; } +char *yon_char_append_c(const char *source, char append) +{ + if (source) + { + size_t size = strlen(source) + 2; + char *final = malloc(size); + memset(final, 0, size); + memcpy(final,source,size-2); + final[size-2]=append; + return final; + } + return NULL; +} + char *yon_char_new(const char *chr) { if (chr){ @@ -471,11 +485,11 @@ int yon_char_check_begins_with(char *haystack, char *needle){ int size = strlen(needle); for (int i=0;istrlen(find)){ + memcpy(final+strlen(final),source+strlen(find),strlen(source+strlen(find))); + } + + return final; + } + } + return NULL; +} + char **yon_char_parse(char *parameters, int *size, char *divider){ *size=0; if (parameters){ @@ -702,7 +736,7 @@ char **yon_char_parsed_rip(char **char_string, int *size, int item_to_delete) { int yon_char_parsed_check_exist(char **parameters, int size, char *param){ - if (parameters){ + if (parameters&&size&&!yon_char_is_empty(param)){ for (int i=0;iignore=0; param->save_command=NULL; param->load_command=NULL; + param->compare_ignore=0; return param; } @@ -1534,6 +1570,22 @@ int yon_config_load_register(YON_CONFIG_TYPE config_type,char *section,char *par } else return -1; } +void yon_config_compare_ignore_set(char *key, int status){ + dictionary *cur = yon_dictionary_get((dictionary**)&__yon__config__strings,key); + if (cur){ + ((yon_config_parameter*)cur)->compare_ignore=!!status; + } +} + +int yon_config_compare_ignore_get(char *key){ + + dictionary *cur = yon_dictionary_get((dictionary**)&__yon__config__strings,key); + if (cur){ + return ((yon_config_parameter*)cur)->compare_ignore; + } + return 0; +} + int yon_config_remove_by_key(char *key){ check_config{ dictionary *dict = yon_dictionary_get((dictionary**)&__yon__config__strings,key); @@ -1543,7 +1595,7 @@ int yon_config_remove_by_key(char *key){ dict->data=""; return 1; } else return 0; - }else return 0; + } } return 0; } @@ -2505,7 +2557,7 @@ int yon_file_save(char *file_path, char *text){ FILE *file = fopen(file_path,"w"); struct passwd *user = getpwnam(yon_ubl_root_user_get()); if (chown(file_path,user->pw_uid,user->pw_gid)){}; - chmod(file_path,0644); + if (chmod(file_path,0755)){}; if (file){ fputs(text,file); fclose(file); @@ -2522,7 +2574,7 @@ int yon_file_create(char *path, char *name, int rules){ if (fl){ struct passwd *user = getpwnam(yon_ubl_root_user_get()); if (chown(path,user->pw_uid,user->pw_gid)){}; - chmod(full_path,rules); + if (chmod(path,0755)){}; fclose(fl); return 1; } else { @@ -2536,7 +2588,7 @@ int yon_file_create(char *path, char *name, int rules){ } } -int yon_file_create_full_path(char *path, int rules){ +int yon_file_create_full_path(char *path, mode_t rules){ if (path){ if (access(path,F_OK)){ int size; @@ -2548,12 +2600,17 @@ int yon_file_create_full_path(char *path, int rules){ if (access(temp,F_OK)){ if (i!=size-1){ mkdir(temp,0755); + struct passwd *user = getpwnam(yon_ubl_root_user_get()); } else { FILE *fl = fopen(temp,"w"); - int chmod_success = chmod(temp,rules); + fclose(fl); } - struct passwd *user = getpwnam(yon_ubl_root_user_get()); - int chown_success = chown(temp,user->pw_uid,user->pw_gid); + + } + if (i>2){ + struct passwd *user = getpwnam(yon_ubl_root_user_get()); + int chown_success = chown(temp,user->pw_uid,user->pw_gid); + int chmod_success = chmod(temp,0755); } } if (!yon_char_is_empty(current)) free(current); diff --git a/source/libublsettings.h b/source/libublsettings.h index dfaa421..0b1f315 100644 --- a/source/libublsettings.h +++ b/source/libublsettings.h @@ -315,6 +315,8 @@ int yon_char_find_last(char *source, char find); */ char *yon_char_append(const char *source, const char *append); +char *yon_char_append_c(const char *source, char append); + /**[EN] * * creates new char string by copying another char. @@ -415,6 +417,7 @@ char *yon_char_from_long(long int_to_convert); * Заменяет в строке [source] все вхождения строки [find] на [replace] */ char *yon_char_replace(char *source, char *find, char*replace); +char *yon_char_replace_single(char *source, char *find, char *replace); /**yon_char_parse(char *parameters, int *size, char *divider) * [EN] @@ -695,7 +698,7 @@ int yon_file_create(char *path, char *name, int rules); * Создать файл по пути [path] * С правами доступа [rules] (от 0000 до 0777) */ -int yon_file_create_full_path(char *path, int rules); +int yon_file_create_full_path(char *path, mode_t rules); /**yon_file_ls (char *path, int *size) * [EN] @@ -739,6 +742,8 @@ void yon_dir_remove(const char *path); */ config_str yon_dir_get_contents(char *dir_path, int *size); +config_str yon_dir_get_by_mask(char *path, char *mask, int *size); + //config functions #define ubconfig_save_command "ubconfig " @@ -750,6 +755,7 @@ config_str yon_dir_get_contents(char *dir_path, int *size); #define ubconfig_set_command_full(target, section, data) yon_char_unite("ubconfig ",!yon_char_is_empty(target)?"--target ":"",!yon_char_is_empty(target)?target:""," set ",section," ",data,NULL) #define ubconfig_load_command(target) yon_char_unite("ubconfig --source ",target," get ",NULL) #define ubconfig_load_command_full(target, data) yon_char_unite("ubconfig --source ",target," get ",data,NULL) +#define ubconfig_remove_command_full(target, section, data) yon_char_unite("ubconfig ",!yon_char_is_empty(target)?"--target ":"",!yon_char_is_empty(target)?target:""," remove ",section," ",data,NULL) /** * Типы конфигураций ubconfig-а @@ -861,6 +867,10 @@ int yon_config_load_register_no_cleaning(YON_CONFIG_TYPE config_type,char *secti [[ deprecated ( "Use yon_config_load_config instead" ) ]] int yon_config_load_register(YON_CONFIG_TYPE config_type,char *section,char *parameter, ...); +void yon_config_compare_ignore_set(char *key, int status); + +int yon_config_compare_ignore_get(char *key); + /**yon_config_remove_by_key(char *key) * [EN] *