@ -213,16 +213,27 @@ dictionary *yon_dictionary_new_with_data(char *key, void *data)
return dct ;
return dct ;
}
}
void * yon_dictionary_free ( dictionary * dictionary_to_free ) {
if ( dictionary_to_free ) {
free ( dictionary_to_free - > data ) ;
free ( dictionary_to_free - > key ) ;
free ( dictionary_to_free ) ;
return NULL ;
}
}
void * yon_dictionary_free_all ( dictionary * dictionary_to_free , void ( * data_manipulation ) ( void * ) ) {
void * yon_dictionary_free_all ( dictionary * dictionary_to_free , void ( * data_manipulation ) ( void * ) ) {
dictionary * dict = NULL ;
if ( dictionary_to_free ) {
for_dictionaries ( dict , dictionary_to_free ) {
dictionary * dict = NULL ;
if ( data_manipulation )
for_dictionaries ( dict , dictionary_to_free ) {
data_manipulation ( dict - > data ) ;
if ( data_manipulation )
if ( dict - > prev )
data_manipulation ( dict - > data ) ;
free ( dict - > prev ) ;
if ( dict - > prev )
free ( dict - > prev ) ;
}
free ( dict ) ;
return NULL ;
}
}
free ( dict ) ;
return NULL ;
}
}
dictionary * yon_dictionary_append_with_data ( dictionary * dict , char * key , void * data )
dictionary * yon_dictionary_append_with_data ( dictionary * dict , char * key , void * data )
@ -711,6 +722,18 @@ dictionary *yon_char_parsed_convert_copy_to_dictionary(config_str parsed, int si
return NULL ;
return NULL ;
}
}
char * yon_char_parsed_to_string ( config_str parsed , int size , char * divider_replace ) {
if ( parsed & & size > 0 ) {
char * final_string = " " ;
for ( int i = 0 ; i < size ; i + + ) {
yon_char_unite ( final_string , yon_char_is_empty ( final_string ) ? " " : divider_replace , parsed [ i ] , NULL ) ;
}
if ( ! yon_char_is_empty ( final_string ) ) {
return final_string ;
} else return NULL ;
}
}
int yon_ubl_check_root ( ) {
int yon_ubl_check_root ( ) {
if ( getuid ( ) = = 0 ) return 1 ;
if ( getuid ( ) = = 0 ) return 1 ;
else return 0 ;
else return 0 ;
@ -877,7 +900,24 @@ dictionary *__yon_config_ignored = NULL;
int yon_config_set_ignore ( char * key ) {
int yon_config_set_ignore ( char * key ) {
yon_dictionary_add_or_create_if_exists_with_data ( __yon_config_ignored , key , NULL ) ;
if ( ! yon_dictionary_get ( & __yon_config_ignored , key ) ) {
yon_dictionary_add_or_create_if_exists_with_data ( __yon_config_ignored , key , NULL ) ;
}
}
int yon_config_remove_ignore ( char * key ) {
dictionary * dict = yon_dictionary_get ( & __yon_config_ignored , key ) ;
if ( dict ) {
__yon_config_ignored = yon_dictionary_rip ( dict ) ;
}
}
int yon_config_get_status ( char * key ) {
dictionary * dict ;
if ( yon_dictionary_get ( ( dictionary * * ) & __yon__config__strings , key ) ) {
return ( ( yon_config_parameter * ) dict ) - > flag1 ;
}
else return 0 ;
}
}
int yon_config_check_ignore ( char * key ) {
int yon_config_check_ignore ( char * key ) {
@ -886,106 +926,159 @@ int yon_config_check_ignore(char *key){
else return 0 ;
else return 0 ;
}
}
int yon_config_load_register ( YON_CONFIG_TYPE config_type , char * section , char * parameter , . . . ) {
int yon_config_load_register_no_cleaning ( YON_CONFIG_TYPE config_type , char * section , char * parameter , . . . ) {
if ( __yon__config__strings ) {
if ( config_type ! = YON_CONFIG_BOTH ) {
__yon__config__strings = yon_dictionary_free_all ( ( dictionary * ) __yon__config__strings , NULL ) ;
va_list args ;
}
va_start ( args , parameter ) ;
va_list args ;
dictionary * sections = NULL ;
va_start ( args , parameter ) ;
yon_dictionary_add_or_create_if_exists_with_data ( sections , section , parameter ) ;
dictionary * sections = NULL ;
char * arg ;
yon_dictionary_add_or_create_if_exists_with_data ( sections , section , parameter ) ;
char * arg ;
while ( arg = va_arg ( args , char * ) ) {
char * key = va_arg ( args , char * ) ;
while ( arg = va_arg ( args , char * ) ) {
if ( sections & & yon_dictionary_get ( & sections , arg ) ) sections - > data = ( void * ) yon_char_unite ( yon_dictionary_get_data ( sections , char * ) , " " , key , NULL ) ;
char * key = va_arg ( args , char * ) ;
else yon_dictionary_add_or_create_if_exists_with_data ( sections , arg , key ) ;
if ( sections & & yon_dictionary_get ( & sections , arg ) ) sections - > data = ( void * ) yon_char_unite ( yon_dictionary_get_data ( sections , char * ) , " " , key , NULL ) ;
}
else yon_dictionary_add_or_create_if_exists_with_data ( sections , arg , key ) ;
char * command = NULL ;
}
dictionary * dict ;
char * command = NULL ;
for_dictionaries ( dict , sections ) {
dictionary * dict ;
command = yon_char_unite ( ubconfig_load_command , config_type = = YON_CONFIG_GLOBAL ? " global get " : config_type = = YON_CONFIG_LOCAL ? " system get " : " default get " , dict - > key , " " , yon_dictionary_get_data ( dict , char * ) , NULL ) ;
for_dictionaries ( dict , sections ) {
FILE * output = popen ( command , " r " ) ;
command = yon_char_unite ( ubconfig_load_command , " default get " , dict - > key , " " , yon_dictionary_get_data ( dict , char * ) , NULL ) ;
int i = 0 ;
FILE * output = popen ( command , " r " ) ;
char str [ 4096 ] ;
int i = 0 ;
memset ( str , 0 , 4096 ) ;
char str [ 4096 ] ;
while ( fgets ( str , 4096 , output ) )
memset ( str , 0 , 4096 ) ;
while ( fgets ( str , 4096 , output ) )
{
if ( strcmp ( str , " " ) ! = 0 & & strcmp ( str , " (null) \n " ) ! = 0 )
{
{
char * key = yon_char_divide_search ( str , " = " , - 1 ) ;
if ( strcmp ( str , " " ) ! = 0 & & strcmp ( str , " (null) \n " ) ! = 0 )
char * final_str = yon_char_divide_search ( str , " \n " , - 1 ) ;
{
char * key = yon_char_divide_search ( str , " = " , - 1 ) ;
char * final_str = yon_char_divide_search ( str , " \n " , - 1 ) ;
if ( ! yon_dictionary_get ( ( dictionary * * ) & __yon__config__strings , key ) ) {
if ( ! yon_dictionary_get ( ( dictionary * * ) & __yon__config__strings , key ) ) {
yon_config_parameter_add_or_create_if_exists_with_data ( __yon__config__strings , key , yon_char_new ( final_str ) ) ;
yon_config_parameter_add_or_create_if_exists_with_data ( __yon__config__strings , key , yon_char_new ( final_str ) ) ;
} else {
__yon__config__strings - > data = final_str ;
}
yon_config_remove_ignore ( key ) ;
if ( config_type = = YON_CONFIG_DEFAULT ) {
__yon__config__strings - > flag1 = - 2 ;
yon_config_set_ignore ( key ) ;
}
__yon__config__strings - > data_type = DICTIONARY_CHAR_TYPE ;
__yon__config__strings - > section = dict - > key ;
}
}
__yon__config__strings - > data_type = DICTIONARY_CHAR_TYPE ;
__yon__config__strings - > section = dict - > key ;
}
}
free ( command ) ;
fclose ( output ) ;
}
}
free ( command ) ;
check_config
fclose ( output ) ;
return 1 ;
}
else return 0 ;
for_dictionaries ( dict , sections ) {
} else return - 1 ;
command = yon_char_unite ( ubconfig_load_command , config_type = = YON_CONFIG_GLOBAL ? " global get " : " system get " , dict - > key , " " , yon_dictionary_get_data ( dict , char * ) , NULL ) ;
}
FILE * output = popen ( command , " r " ) ;
int i = 0 ;
int yon_config_load_register ( YON_CONFIG_TYPE config_type , char * section , char * parameter , . . . ) {
char str [ 4096 ] ;
if ( config_type ! = YON_CONFIG_BOTH ) {
memset ( str , 0 , 4096 ) ;
if ( __yon__config__strings ) {
while ( fgets ( str , 4096 , output ) )
__yon__config__strings = yon_dictionary_free_all ( ( dictionary * ) __yon__config__strings , NULL ) ;
{
}
if ( strcmp ( str , " " ) ! = 0 & & strcmp ( str , " (null) \n " ) ! = 0 )
va_list args ;
va_start ( args , parameter ) ;
dictionary * sections = NULL ;
yon_dictionary_add_or_create_if_exists_with_data ( sections , section , parameter ) ;
char * arg ;
while ( arg = va_arg ( args , char * ) ) {
char * key = va_arg ( args , char * ) ;
if ( sections & & yon_dictionary_get ( & sections , arg ) ) sections - > data = ( void * ) yon_char_unite ( yon_dictionary_get_data ( sections , char * ) , " " , key , NULL ) ;
else yon_dictionary_add_or_create_if_exists_with_data ( sections , arg , key ) ;
}
char * command = NULL ;
dictionary * dict ;
for_dictionaries ( dict , sections ) {
command = yon_char_unite ( ubconfig_load_command , config_type = = YON_CONFIG_GLOBAL ? " global get " : config_type = = YON_CONFIG_LOCAL ? " system get " : " default get " , dict - > key , " " , yon_dictionary_get_data ( dict , char * ) , NULL ) ;
FILE * output = popen ( command , " r " ) ;
int i = 0 ;
char str [ 4096 ] ;
memset ( str , 0 , 4096 ) ;
while ( fgets ( str , 4096 , output ) )
{
{
char * key = yon_char_divide_search ( str , " = " , - 1 ) ;
if ( strcmp ( str , " " ) ! = 0 & & strcmp ( str , " (null) \n " ) ! = 0 )
char * final_str = yon_char_divide_search ( str , " \n " , - 1 ) ;
{
char * key = yon_char_divide_search ( str , " = " , - 1 ) ;
char * final_str = yon_char_divide_search ( str , " \n " , - 1 ) ;
if ( ! yon_dictionary_get ( ( dictionary * * ) & __yon__config__strings , key ) ) {
if ( ! yon_dictionary_get ( ( dictionary * * ) & __yon__config__strings , key ) ) {
yon_config_parameter_add_or_create_if_exists_with_data ( __yon__config__strings , key , yon_char_new ( final_str ) ) ;
yon_config_parameter_add_or_create_if_exists_with_data ( __yon__config__strings , key , yon_char_new ( final_str ) ) ;
} else {
} else {
__yon__config__strings - > data = final_str ;
__yon__config__strings - > data = final_str ;
}
yon_config_remove_ignore ( key ) ;
if ( config_type = = YON_CONFIG_DEFAULT ) {
__yon__config__strings - > flag1 = - 2 ;
yon_config_set_ignore ( key ) ;
}
__yon__config__strings - > data_type = DICTIONARY_CHAR_TYPE ;
__yon__config__strings - > section = dict - > key ;
}
}
__yon__config__strings - > data_type = DICTIONARY_CHAR_TYPE ;
__yon__config__strings - > section = dict - > key ;
}
}
free ( command ) ;
fclose ( output ) ;
}
}
free ( command ) ;
check_config
fclose ( output ) ;
return 1 ;
}
else return 0 ;
check_config
} else return - 1 ;
return 1 ;
else return 0 ;
}
}
int yon_config_remove_by_key ( char * key ) {
int yon_config_remove_by_key ( char * key ) {
check_config {
check_config {
dictionary * dict = yon_dictionary_get ( ( dictionary * * ) & __yon__config__strings , key ) ;
dictionary * dict = yon_dictionary_get ( ( dictionary * * ) & __yon__config__strings , key ) ;
if ( dict ) {
if ( dict ) {
( ( yon_config_parameter * ) dict ) - > flag1 = - 1 ;
if ( ! yon_dictionary_get ( & __yon_config_ignored , dict - > key ) ) {
dict - > data = " " ;
( ( yon_config_parameter * ) dict ) - > flag1 = - 1 ;
return 1 ;
dict - > data = " " ;
return 1 ;
} else return 0 ;
} else return 0 ;
} else return 0 ;
}
}
return 0 ;
return 0 ;
}
}
int yon_config_remove_element ( char * key , char * delete d) {
int yon_config_remove_element ( char * key , char * delete , char * divider ) {
check_config {
check_config {
int found = 0 ;
yon_config_parameter * dict = ( yon_config_parameter * ) yon_dictionary_get ( ( dictionary * * ) & __yon__config__strings , key ) ;
yon_config_parameter * dict = ( yon_config_parameter * ) yon_dictionary_get ( ( dictionary * * ) & __yon__config__strings , key ) ;
char * data = ( char * ) dict - > data ;
if ( dict ) {
char * found = strstr ( data , deleted ) ;
int size ;
int size = strlen ( data ) - strlen ( found ) + 1 ;
config_str parsed = yon_char_parse ( ( char * ) dict - > data , & size , divider ) ;
char * new_data = malloc ( size ) ;
config_str final = NULL ;
memset ( new_data , 0 , size ) ;
for ( int i = 0 ; i < size ; i + + ) {
if ( strlen ( found ) ! = strlen ( deleted ) ) {
if ( ! strcmp ( parsed [ i ] , delete ) ) {
memcpy ( new_data , data , size - 1 ) ;
parsed = yon_char_parsed_rip ( parsed , & size , i - - ) ;
new_data = yon_char_append ( new_data , found + strlen ( deleted ) + 1 ) ;
found = 1 ;
} else {
}
memcpy ( new_data , data , size - 2 ) ;
}
new_data = yon_char_append ( new_data , found + strlen ( deleted ) ) ;
char * final_string = yon_char_parsed_to_string ( parsed , size , divider ) ;
if ( final_string ) {
free ( dict - > data ) ;
dict - > data = final_string ;
return 1 ;
} else return 0 ;
}
}
dict - > data = ( void * ) ( new_data ) ;
dict - > flag1 = 1 ;
} else return 0 ;
return 1 ;
}
int yon_config_append_element ( char * key , char * append , char * divider ) {
check_config {
int found = 0 ;
yon_config_parameter * dict = ( yon_config_parameter * ) yon_dictionary_get ( ( dictionary * * ) & __yon__config__strings , key ) ;
if ( dict ) {
yon_char_unite ( ( char * ) dict - > data , divider , append , NULL ) ;
return 1 ;
}
} else return 0 ;
} else return 0 ;
}
}
@ -1087,6 +1180,9 @@ int yon_config_set(char *key, void *data){
yon_config_parameter * dict = ( yon_config_parameter * ) yon_dictionary_get ( ( dictionary * * ) & __yon__config__strings , key ) ;
yon_config_parameter * dict = ( yon_config_parameter * ) yon_dictionary_get ( ( dictionary * * ) & __yon__config__strings , key ) ;
dict - > data = data ;
dict - > data = data ;
dict - > flag1 = 1 ;
dict - > flag1 = 1 ;
if ( yon_dictionary_get ( & __yon_config_ignored , dict - > key ) ) {
__yon_config_ignored = yon_dictionary_rip ( __yon_config_ignored ) ;
}
return 1 ;
return 1 ;
} else return 0 ;
} else return 0 ;
}
}
@ -1112,13 +1208,16 @@ int yon_config_clean(){
void yon_config_register ( char * key , char * config_section , void * data ) {
void yon_config_register ( char * key , char * config_section , void * data ) {
if ( ! __yon__config__strings | | ! yon_dictionary_get ( ( dictionary * * ) & __yon__config__strings , key ) ) {
if ( ! __yon__config__strings | | ! yon_dictionary_get ( ( dictionary * * ) & __yon__config__strings , key ) ) {
yon_config_parameter_add_or_create_if_exists_with_data ( __yon__config__strings , key , data ) ;
yon_config_parameter_add_or_create_if_exists_with_data ( __yon__config__strings , key , yon_char_new ( data ) ) ;
__yon__config__strings - > flag1 = 1 ;
__yon__config__strings - > flag1 = 1 ;
}
}
else if ( yon_dictionary_get ( ( dictionary * * ) & __yon__config__strings , key ) ) {
else if ( yon_dictionary_get ( ( dictionary * * ) & __yon__config__strings , key ) ) {
if ( data ! = __yon__config__strings - > data & & strcmp ( __yon__config__strings - > data , data ) ) {
if ( data ! = __yon__config__strings - > data & & strcmp ( __yon__config__strings - > data , data ) ) {
__yon__config__strings - > data = data ;
__yon__config__strings - > data = yon_char_new ( data ) ;
__yon__config__strings - > flag1 = 1 ;
__yon__config__strings - > flag1 = 1 ;
if ( yon_dictionary_get ( & __yon_config_ignored , __yon__config__strings - > key ) ) {
yon_dictionary_rip ( __yon_config_ignored ) ;
}
}
}
}
}
__yon__config__strings - > data_type = DICTIONARY_CHAR_TYPE ;
__yon__config__strings - > data_type = DICTIONARY_CHAR_TYPE ;
@ -1175,14 +1274,18 @@ int yon_config_save_registered(char *path){
for_dictionaries ( dct , sections_add ) {
for_dictionaries ( dct , sections_add ) {
char * command = yon_dictionary_get_data ( dct , char * ) ;
char * command = yon_dictionary_get_data ( dct , char * ) ;
yon_launch ( command ) ;
yon_launch ( command ) ;
yon_dictionary_free_all ( sections_add , free ) ;
}
}
if ( sections_remove )
if ( sections_remove )
for_dictionaries ( dct , sections_remove ) {
for_dictionaries ( dct , sections_remove ) {
char * command = yon_dictionary_get_data ( dct , char * ) ;
char * command = yon_dictionary_get_data ( dct , char * ) ;
yon_launch ( command ) ;
yon_launch ( command ) ;
yon_dictionary_free_all ( sections_remove , free ) ;
}
}
return 1 ;
if ( sections_add | | sections_remove )
} else return 1 ;
return 1 ;
else return 0 ;
} else return 0 ;
}
}
int yon_config_force_save_registered ( char * path ) {
int yon_config_force_save_registered ( char * path ) {