#ifndef SAVE_H #define SAVE_H #include "save.h" char* template_format_save(config_all* _all_config, char* source_set_cmd) { char* cmd = yon_char_new(""); for (int i = 0; i < _all_config->v_u_g_p.pfVectorTotal(&_all_config->v_u_g_p); i++) { config_u_g_p* _config = (config_u_g_p*)_all_config->v_u_g_p.pfVectorGet(&_all_config->v_u_g_p, i); char* key = save_format_key(_config, i); char* value = save_format_str_value(_config, i); //char* value_status = save_format_status_cmd(_config, i); if (key!= NULL) { // key = yon_char_unite(cmd, " " , key, "=\"" , value, "\" ", NULL); cmd = yon_char_unite(cmd, key, "=" , value, " ", NULL); //cmd = yon_char_unite(cmd, key, "=" , value_status, " ", NULL); free(key); free(value); //free(value_status); } } if (strlen(cmd) > 8 && save_check_save(_all_config)== 0) { cmd = yon_char_unite(source_set_cmd, " " ,cmd, NULL); return cmd; } free(cmd); return NULL; } char* template_format_remove_save(config_all* _all_config, char* source_remove_cmd) { char* cmd = yon_char_new(source_remove_cmd); if (_all_config->count_remove == 0) { return NULL; } for (int i = 0; i < _all_config->v_u_g_p.pfVectorTotal(&_all_config->v_u_g_p); i++) { config_u_g_p* _config = (config_u_g_p*)_all_config->v_u_g_p.pfVectorGet(&_all_config->v_u_g_p, i); if (_config->status_set >= 0) { cmd = yon_char_unite(cmd, " " , _config->loaded_keys, " ", NULL); } } if (strlen(cmd) > strlen(source_remove_cmd) && save_check_save(_all_config)== 0) { return cmd; } return cmd; } int wrapper_template_save(config_all* _all_config, char* source_set_cmd, char* source_remove_cmd) { char* str_cmd_remove = template_format_remove_save(_all_config,source_remove_cmd); char* str_cmd_set = template_format_save(_all_config,source_set_cmd); if (str_cmd_set != NULL && str_cmd_remove != NULL) { philos_config_save(yon_char_unite(str_cmd_remove, "; " , str_cmd_set, NULL)); } else if (str_cmd_remove != NULL) { philos_config_save(str_cmd_remove); } else if (str_cmd_set != NULL) { philos_config_save(str_cmd_set); } else { return 0; } if (str_cmd_remove != NULL) { free(str_cmd_remove); } if (str_cmd_set != NULL) { free(str_cmd_set); } _all_config->flag_set_data = 0; return 1; } char* save_format_key(config_u_g_p* config, int index) { if (config->status_set == 1) { return NULL; } char* cmd = yon_char_new(""); char* value = yon_char_new(""); char* key = yon_char_new(""); int number = config->id; key = yon_char_unite("CGROUP_QUOTA[", config->type_arr, ":", NULL); if (strstr(config->type_arr, "prjquota")) { if (number!=-1) { key = yon_char_unite(config->UNIX_file,":",yon_char_from_int(number), NULL); } else { key = yon_char_unite(config->UNIX_file,":AUTO", NULL); } } else { key = yon_char_unite(config->UNIX_file, NULL); } key = yon_char_unite(key, save_str_users(config, index) , "]", NULL); return cmd; } char* save_format_str_value(config_u_g_p* config, int index) { if (config->status_set == 1) { return NULL; } char* value = yon_char_new(""); value = philos_format_cfg_str_size_memory(value, config->soft_restriction_size,config->soft_restriction_size_pow); value = yon_char_unite(value, ","); philos_format_cfg_str_size_memory(value, config->soft_restriction_file,config->soft_restriction_file_pow); value = yon_char_unite(value, ","); philos_format_cfg_str_size_memory(value, config->severe_limitation_size,config->severe_limitation_size_pow); value = yon_char_unite(value, ","); philos_format_cfg_str_size_memory(value, config->severe_limitation_file, config->severe_limitation_file_pow); value = yon_char_unite(value, ","); //philos_format_cfg_str_size_memory(value, config->deferring_size, config->deferring_size_pow); value = yon_char_unite(value, ","); //value = philos_format_cfg_str_size_memory(value, config->deferring_file, config->deferring_file_pow); return value; } char* save_str_users(config_u_g_p* config, int index) { char* cmd = yon_char_new(""); char split_simvol[2] = {0}; split_simvol[0] = 0; split_simvol[1] = 0; if (strstr(config->type_arr, "prjquota")) { for (int i=0; config->actors[i]; i++) { cmd = yon_char_unite(":", split_simvol, config->actors[i], NULL); split_simvol[0] = ','; split_simvol[1] = '\0'; } } else { } } /* char* save_format_status_cmd(config_u_g_p* config, int index) { if (config->status_set == 1) { return NULL; } if (config->status) { return yon_char_new("enable"); } else { return yon_char_new("disable"); } return yon_char_new("disable"); } */ int save_check_save(config_all* _all_config) { if (_all_config->flag_set_data == 1 || _all_config->flag_save>0) { return 0; } else if (_all_config->flag_set_data == 0 || _all_config->flag_save<=0) { return 1; } return 0; } void save_remove_array(config_all* _all_config) { for (int i = 0; i < _all_config->v_u_g_p.pfVectorTotal(&_all_config->v_u_g_p); i++) { config_u_g_p* _config = (config_u_g_p*)_all_config->v_u_g_p.pfVectorGet(&_all_config->v_u_g_p, i); if (_config->status_set == 1) { _all_config->v_u_g_p.pfVectorDelete(&_all_config->v_u_g_p, i); } if (_config->status_set == 2) { _config->status_set = 0; } } } #endif