static int pkg_set_files_from_node(struct pkg *pkg, yaml_node_t *item, yaml_document_t *doc, const char *filename) { yaml_node_pair_t *pair = NULL; yaml_node_t *key = NULL; yaml_node_t *val = NULL; const char *sum = NULL; const char *uname = NULL; const char *gname = NULL; void *set = NULL; mode_t perm = 0; pair = item->data.mapping.pairs.start; while (pair < item->data.mapping.pairs.top) { key = yaml_document_get_node(doc, pair->key); val = yaml_document_get_node(doc, pair->value); if (key->data.scalar.length <= 0) { pkg_emit_error("Skipping malformed file entry for %s", filename); ++pair; continue; } if (val->type != YAML_SCALAR_NODE || val->data.scalar.length <= 0) { pkg_emit_error("Skipping malformed file entry for %s", filename); ++pair; continue; } if (!strcasecmp(key->data.scalar.value, "uname")) uname = val->data.scalar.value; else if (!strcasecmp(key->data.scalar.value, "gname")) gname = val->data.scalar.value; else if (!strcasecmp(key->data.scalar.value, "sum") && val->data.scalar.length == 64) sum = val->data.scalar.value; else if (!strcasecmp(key->data.scalar.value, "perm")) { if ((set = setmode(val->data.scalar.value)) == NULL) pkg_emit_error("Not a valid mode: %s", val->data.scalar.value); else perm = getmode(set, 0); } else { pkg_emit_error("Skipping unknown key for file(%s): %s", filename, key->data.scalar.value); } ++pair; } if (key != NULL) pkg_addfile_attr(pkg, key->data.scalar.value, sum, uname, gname, perm, false); return (EPKG_OK); }
static int pkg_set_files_from_object(struct pkg *pkg, ucl_object_t *obj) { ucl_object_t *cur; ucl_object_iter_t it = NULL; const char *sum = NULL; const char *uname = NULL; const char *gname = NULL; void *set = NULL; mode_t perm = 0; struct sbuf *fname = NULL; const char *key, *okey; okey = ucl_object_key(obj); if (okey == NULL) return (EPKG_FATAL); urldecode(okey, &fname); while ((cur = ucl_iterate_object(obj, &it, true))) { key = ucl_object_key(cur); if (key == NULL) continue; if (!strcasecmp(key, "uname") && cur->type == UCL_STRING) uname = ucl_object_tostring(cur); else if (!strcasecmp(key, "gname") && cur->type == UCL_STRING) gname = ucl_object_tostring(cur); else if (!strcasecmp(key, "sum") && cur->type == UCL_STRING && strlen(ucl_object_tostring(cur)) == 64) sum = ucl_object_tostring(cur); else if (!strcasecmp(key, "perm") && (cur->type == UCL_STRING || cur->type == UCL_INT)) { if ((set = setmode(ucl_object_tostring_forced(cur))) == NULL) pkg_emit_error("Not a valid mode: %s", ucl_object_tostring(cur)); else perm = getmode(set, 0); } else { pkg_emit_error("Skipping unknown key for file(%s): %s", sbuf_data(fname), ucl_object_tostring(cur)); } } pkg_addfile_attr(pkg, sbuf_data(fname), sum, uname, gname, perm, false); sbuf_delete(fname); return (EPKG_OK); }