config_setting_t *config_setting_add(config_setting_t *parent, const char *name, int type) { if((type < CONFIG_TYPE_NONE) || (type > CONFIG_TYPE_LIST)) return(NULL); if(! parent) return(NULL); if((parent->type == CONFIG_TYPE_ARRAY) || (parent->type == CONFIG_TYPE_LIST)) name = NULL; if(name) { if(! __config_validate_name(name)) return(NULL); } #if 0 /* https://github.com/HerculesWS/Hercules/pull/136#discussion_r6363319 * With this code, accidental duplicate keys would cause the file parsing to fail * (would cause several issues during runtime on file reloads), while libconfig's code * has no problems with duplicate members so it was ducked out -- TODO: looking now though * I'd think it could be useful to have it display a warning or error message when finding * duplicate keys instead of silently moving on. [Ind] */ if(config_setting_get_member(parent, name) != NULL) return(NULL); /* already exists */ #endif return(config_setting_create(parent, name, type)); }
config_setting_t *config_setting_add(config_setting_t *parent, const char *name, int type) { if((type < CONFIG_TYPE_NONE) || (type > CONFIG_TYPE_LIST)) return(NULL); if(! parent) return(NULL); if((parent->type == CONFIG_TYPE_ARRAY) || (parent->type == CONFIG_TYPE_LIST)) name = NULL; if(name) { if(! __config_validate_name(name)) return(NULL); } config_setting_t *setting = config_setting_get_member(parent, name); if (setting != NULL) { if ((setting->type != type && type != CONFIG_TYPE_NONE) || (setting->type != CONFIG_TYPE_GROUP && setting->type != CONFIG_TYPE_ARRAY && setting->type != CONFIG_TYPE_LIST)) return(NULL); /* already exists */ else return setting; /* merge with existing config */ } return(config_setting_create(parent, name, type)); }
config_setting_t *config_setting_add (config_setting_t * parent, const char *name, int type) { if ((type < CONFIG_TYPE_NONE) || (type > CONFIG_TYPE_LIST)) return (NULL); if (!parent) return (NULL); if ((parent->type == CONFIG_TYPE_ARRAY) || (parent->type == CONFIG_TYPE_LIST)) name = NULL; if (name) { if (!__config_validate_name (name)) return (NULL); } if (config_setting_get_member (parent, name) != NULL) return (NULL); /* already exists */ return (config_setting_create (parent, name, type)); }