#include #include #include #include "image.h" #include "xml/xml.h" #include "util/util.h" int kai_read_init_from(struct ka_init_from_t *dest, struct kai_tag_t *src) { KAI_CHECK_TAG_TYPE("init_from"); struct kai_tag_t *ref = kai_tag_get_first_child_with_type(src, "ref"); if (ref != NULL) { dest->ref = strdup(ref->content); } else { dest->ref = strdup(src->content); } return 0; } void kai_release_init_from(struct ka_init_from_t i) { free(i.ref); } int kai_read_image(struct ka_image_t *dest, struct kai_tag_t *src) { KAI_CHECK_TAG_TYPE("image"); dest->id = kai_tag_attr_to_dup(src, "id"); dest->sid = kai_tag_attr_to_dup(src, "sid"); dest->name = kai_tag_attr_to_dup(src, "name"); struct kai_tag_t *init_from = kai_tag_get_first_child_with_type(src, "init_from"); if (init_from == NULL) { free(dest->id); free(dest->sid); free(dest->name); return -1; } int result = kai_read_init_from(&(dest->init_from), init_from); if (result != 0) { free(dest->id); free(dest->sid); free(dest->name); return -1; } return 0; } void kai_release_image(struct ka_image_t i) { free(i.id); free(i.sid); free(i.name); kai_release_init_from(i.init_from); } int kai_read_library_images(struct ka_library_images_t *dest, struct kai_tag_t *src) { KAI_CHECK_TAG_TYPE("library_images"); dest->id = kai_tag_attr_to_dup(src, "id"); dest->name = kai_tag_attr_to_dup(src, "name"); int result; KAI_FILL_ARRAY_FROM_TAGS( result, dest->image, dest->image_count, struct ka_image_t, src, "image", kai_read_image, kai_release_image ); if (result != 0) { kai_release_library_images(*dest); return -1; } return 0; } void kai_release_library_images(struct ka_library_images_t l) { free(l.id); free(l.name); int i; for (i=0; i