| |
}
|
| |
|
| |
static int
|
| - |
parse_actions(yaml_document_t *doc, yaml_node_t *node, struct plist *p,
|
| + |
parse_actions(ucl_object_t *o, struct plist *p,
|
| |
char *line, struct file_attr *a)
|
| |
{
|
| - |
yaml_node_item_t *item;
|
| - |
yaml_node_t *val;
|
| - |
int i;
|
| - |
|
| - |
if (node->type != YAML_SEQUENCE_NODE) {
|
| - |
pkg_emit_error("Malformed actions, skipping");
|
| - |
return EPKG_FATAL;
|
| - |
}
|
| + |
ucl_object_t *cur;
|
| |
|
| - |
item = node->data.sequence.items.start;
|
| - |
while (item < node->data.sequence.items.top) {
|
| - |
val = yaml_document_get_node(doc, *item);
|
| - |
if (val->type != YAML_SCALAR_NODE) {
|
| - |
pkg_emit_error("Skipping malformed action");
|
| - |
++item;
|
| - |
continue;
|
| - |
}
|
| + |
cur = o;
|
| + |
int i;
|
| |
|
| + |
while (cur) {
|
| |
for (i = 0; list_actions[i].name != NULL; i++) {
|
| - |
if (!strcasecmp(val->data.scalar.value,
|
| - |
list_actions[i].name)) {
|
| + |
if (!strcasecmp(cur->key, list_actions[i].name)) {
|
| |
list_actions[i].perform(p, line, a);
|
| |
break;
|
| |
}
|
| |
}
|
| - |
++item;
|
| + |
cur = cur->next;
|
| |
}
|
| |
|
| |
return (EPKG_OK);
|
| |
}
|
| |
|
| |
static void
|
| - |
parse_attributes(yaml_document_t *doc, yaml_node_t *node, struct file_attr **a) {
|
| - |
yaml_node_pair_t *pair;
|
| - |
yaml_node_t *key, *val;
|
| + |
parse_attributes(ucl_object_t *o, struct file_attr **a) {
|
| + |
ucl_object_t *sub, *tmp;
|
| |
|
| |
if (*a == NULL)
|
| |
*a = calloc(1, sizeof(struct file_attr));
|
| |
|
| - |
pair = node->data.mapping.pairs.start;
|
| - |
while (pair < node->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) {
|
| - |
++pair;
|
| + |
HASH_ITER(hh, o, sub, tmp) {
|
| + |
if (!strcasecmp(sub->key, "owner") && sub->type == UCL_STRING) {
|
| + |
free((*a)->owner);
|
| + |
(*a)->owner = strdup(sub->value.sv);
|
| |
continue;
|
| |
}
|
| - |
|
| - |
if (!strcasecmp(key->data.scalar.value, "owner")) {
|
| - |
if (val->type == YAML_SCALAR_NODE) {
|
| - |
if ((*a)->owner == NULL)
|
| - |
(*a)->owner = strdup(val->data.scalar.value);
|
| - |
} else {
|
| - |
pkg_emit_error("Expecting a scalar for the owner attribute, ignored");
|
| - |
}
|
| - |
++pair;
|
| + |
if (!strcasecmp(sub->key, "group") && sub->type == UCL_STRING) {
|
| + |
free((*a)->group);
|
| + |
(*a)->group = strdup(sub->value.sv);
|
| |
continue;
|
| |
}
|
| - |
if (!strcasecmp(key->data.scalar.value, "group")) {
|
| - |
if (val->type == YAML_SCALAR_NODE) {
|
| - |
if ((*a)->group == NULL)
|
| - |
(*a)->group = strdup(val->data.scalar.value);
|
| + |
if (!strcasecmp(sub->key, "mode")) {
|
| + |
if (sub->type == UCL_STRING) {
|
| + |
void *set;
|
| + |
if ((set = setmode(sub->value.sv)) == NULL)
|
| + |
pkg_emit_error("Bad format for the mode attribute: %s", sub->value.sv);
|
| + |
else
|
| + |
(*a)->mode = getmode(set, 0);
|
| + |
free(set);
|
| |
} else {
|
| - |
pkg_emit_error("Expecting a scalar for the group attribute, ignored");
|
| + |
pkg_emit_error("Expecting a string for the mode attribute, ignored");
|
| |
}
|
| |
}
|
| - |
if (!strcasecmp(key->data.scalar.value, "mode")) {
|
| - |
if (val->type == YAML_SCALAR_NODE) {
|
| - |
if ((*a)->mode == 0) {
|
| - |
void *set;
|
| - |
if ((set = setmode(val->data.scalar.value)) == NULL)
|
| - |
pkg_emit_error("Bad format for the mode attribute: %s", val->data.scalar.value);
|
| - |
else
|
| - |
(*a)->mode = getmode(set, 0);
|
| - |
free(set);
|
| - |
}
|
| - |
} else {
|
| - |
pkg_emit_error("Expecting a scalar for the mode attribute, ignored");
|
| - |
}
|
| - |
}
|
| - |
++pair;
|
| - |
continue;
|
| |
}
|
| |
}
|
| |
|
| |
|
| |
static int
|
| - |
parse_and_apply_keyword_file(yaml_document_t *doc, yaml_node_t *node,
|
| - |
struct plist *p, char *line, struct file_attr *attr)
|
| + |
parse_and_apply_keyword_file(ucl_object_t *obj, struct plist *p, char *line, struct file_attr *attr)
|
| |
{
|
| - |
yaml_node_pair_t *pair;
|
| - |
yaml_node_t *key, *val;
|
| - |
yaml_node_t *actions = NULL;
|
| + |
ucl_object_t *sub, *tmp, *actions;
|
| |
char *cmd;
|
| |
|
| - |
pair = node->data.mapping.pairs.start;
|
| - |
while (pair < node->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) {
|
| - |
++pair; /* ignore silently */
|
| - |
continue;
|
| - |
}
|
| - |
|
| - |
if (!strcasecmp(key->data.scalar.value, "actions")) {
|
| - |
actions = val;
|
| - |
++pair;
|
| + |
HASH_ITER(hh, obj, sub, tmp) {
|
| + |
if (!strcasecmp(sub->key, "actions") && sub->type == UCL_ARRAY) {
|
| + |
actions = sub->value.ov;
|
| |
continue;
|
| |
}
|
| |
|
| - |
if (!strcasecmp(key->data.scalar.value, "attributes")) {
|
| - |
parse_attributes(doc, val, &attr);
|
| - |
++pair;
|
| + |
if (!strcasecmp(sub->key, "attributes") && sub->type == UCL_OBJECT) {
|
| + |
parse_attributes(sub->value.ov, &attr);
|
| |
continue;
|
| |
}
|
| |
|
| - |
if (!strcasecmp(key->data.scalar.value, "pre-install")) {
|
| - |
if (val->data.scalar.length != 0) {
|
| - |
format_exec_cmd(&cmd, val->data.scalar.value,
|
| - |
p->prefix, p->last_file, line);
|
| - |
sbuf_cat(p->pre_install_buf, cmd);
|
| - |
free(cmd);
|
| - |
}
|
| - |
++pair;
|
| + |
if (!strcasecmp(sub->key, "pre-install") && sub->type == UCL_STRING) {
|
| + |
format_exec_cmd(&cmd, sub->value.sv, p->prefix, p->last_file, line);
|
| + |
sbuf_cat(p->pre_install_buf, cmd);
|
| + |
free(cmd);
|
| |
continue;
|
| |
}
|
| |
|
| - |
if (!strcasecmp(key->data.scalar.value, "post-install")) {
|
| - |
if (val->data.scalar.length != 0) {
|
| - |
format_exec_cmd(&cmd, val->data.scalar.value,
|
| - |
p->prefix, p->last_file, line);
|
| - |
sbuf_cat(p->post_install_buf, cmd);
|
| - |
free(cmd);
|
| - |
}
|
| - |
++pair;
|
| + |
if (!strcasecmp(sub->key, "post-install") && sub->type == UCL_STRING) {
|
| + |
format_exec_cmd(&cmd, sub->value.sv, p->prefix, p->last_file, line);
|
| + |
sbuf_cat(p->post_install_buf, cmd);
|
| + |
free(cmd);
|
| |
continue;
|
| |
}
|
| |
|
| - |
if (!strcasecmp(key->data.scalar.value, "pre-deinstall")) {
|
| - |
if (val->data.scalar.length != 0) {
|
| - |
format_exec_cmd(&cmd, val->data.scalar.value,
|
| - |
p->prefix, p->last_file, line);
|
| - |
sbuf_cat(p->pre_deinstall_buf, cmd);
|
| - |
free(cmd);
|
| - |
}
|
| - |
++pair;
|
| + |
if (!strcasecmp(sub->key, "pre-deinstall") && sub->type == UCL_STRING) {
|
| + |
format_exec_cmd(&cmd, sub->value.sv, p->prefix, p->last_file, line);
|
| + |
sbuf_cat(p->pre_deinstall_buf, cmd);
|
| + |
free(cmd);
|
| |
continue;
|
| |
}
|
| |
|
| - |
if (!strcasecmp(key->data.scalar.value, "post-deinstall")) {
|
| - |
if (val->data.scalar.length != 0) {
|
| - |
format_exec_cmd(&cmd, val->data.scalar.value,
|
| - |
p->prefix, p->last_file, line);
|
| - |
sbuf_cat(p->post_deinstall_buf, cmd);
|
| - |
free(cmd);
|
| - |
}
|
| - |
++pair;
|
| + |
if (!strcasecmp(sub->key, "post-deinstall") && sub->type == UCL_STRING) {
|
| + |
format_exec_cmd(&cmd, sub->value.sv, p->prefix, p->last_file, line);
|
| + |
free(cmd);
|
| |
continue;
|
| |
}
|
| |
|
| - |
if (!strcasecmp(key->data.scalar.value, "pre-upgrade")) {
|
| - |
if (val->data.scalar.length != 0) {
|
| - |
format_exec_cmd(&cmd, val->data.scalar.value,
|
| - |
p->prefix, p->last_file, line);
|
| - |
sbuf_cat(p->pre_upgrade_buf, cmd);
|
| - |
free(cmd);
|
| - |
}
|
| - |
++pair;
|
| + |
if (!strcasecmp(sub->key, "pre-upgrade") && sub->type == UCL_STRING) {
|
| + |
format_exec_cmd(&cmd, sub->value.sv, p->prefix, p->last_file, line);
|
| + |
sbuf_cat(p->pre_upgrade_buf, cmd);
|
| + |
free(cmd);
|
| |
continue;
|
| |
}
|
| |
|
| - |
if (!strcasecmp(key->data.scalar.value, "post-upgrade")) {
|
| - |
if (val->data.scalar.length != 0) {
|
| - |
format_exec_cmd(&cmd, val->data.scalar.value,
|
| - |
p->prefix, p->last_file, line);
|
| - |
sbuf_cat(p->post_upgrade_buf, cmd);
|
| - |
free(cmd);
|
| - |
}
|
| - |
++pair;
|
| + |
if (!strcasecmp(sub->key, "post-upgrade") && sub->type == UCL_STRING) {
|
| + |
format_exec_cmd(&cmd, sub->value.sv, p->prefix, p->last_file, line);
|
| + |
sbuf_cat(p->post_upgrade_buf, cmd);
|
| + |
free(cmd);
|
| |
continue;
|
| |
}
|
| - |
++pair;
|
| |
}
|
| |
|
| |
if (actions != NULL)
|
| - |
parse_actions(doc, actions, p, line, attr);
|
| + |
parse_actions(actions, p, line, attr);
|
| |
|
| |
return (EPKG_OK);
|
| |
}
|