From owner-svn-src-all@FreeBSD.ORG Sun Feb 23 21:55:08 2014 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id BA2907D6; Sun, 23 Feb 2014 21:55:08 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 99DB61999; Sun, 23 Feb 2014 21:55:08 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.8/8.14.8) with ESMTP id s1NLt8nt050531; Sun, 23 Feb 2014 21:55:08 GMT (envelope-from bapt@svn.freebsd.org) Received: (from bapt@localhost) by svn.freebsd.org (8.14.8/8.14.8/Submit) id s1NLt8ED050528; Sun, 23 Feb 2014 21:55:08 GMT (envelope-from bapt@svn.freebsd.org) Message-Id: <201402232155.s1NLt8ED050528@svn.freebsd.org> From: Baptiste Daroussin Date: Sun, 23 Feb 2014 21:55:08 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r262400 - head/usr.sbin/pkg X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 23 Feb 2014 21:55:08 -0000 Author: bapt Date: Sun Feb 23 21:55:07 2014 New Revision: 262400 URL: http://svnweb.freebsd.org/changeset/base/262400 Log: Switch pkg(7) from libyaml to libucl Modified: head/usr.sbin/pkg/Makefile head/usr.sbin/pkg/config.c head/usr.sbin/pkg/pkg.c Modified: head/usr.sbin/pkg/Makefile ============================================================================== --- head/usr.sbin/pkg/Makefile Sun Feb 23 21:50:11 2014 (r262399) +++ head/usr.sbin/pkg/Makefile Sun Feb 23 21:55:07 2014 (r262400) @@ -4,11 +4,11 @@ PROG= pkg SRCS= pkg.c dns_utils.c config.c MAN= pkg.7 -CFLAGS+=-I${.CURDIR}/../../contrib/libyaml/include -.PATH: ${.CURDIR}/../../contrib/libyaml/include -DPADD= ${LIBARCHIVE} ${LIBELF} ${LIBFETCH} ${LIBYAML} ${LIBSBUF} ${LIBSSL} \ +CFLAGS+=-I${.CURDIR}/../../contrib/libucl/include +.PATH: ${.CURDIR}/../../contrib/libucl/include +DPADD= ${LIBARCHIVE} ${LIBELF} ${LIBFETCH} ${LIBUCL} ${LIBSBUF} ${LIBSSL} \ ${LIBCRYPTO} -LDADD= -larchive -lelf -lfetch -lyaml -lsbuf -lssl -lcrypto -USEPRIVATELIB= yaml +LDADD= -larchive -lelf -lfetch -lucl -lsbuf -lssl -lcrypto +USEPRIVATELIB= ucl .include Modified: head/usr.sbin/pkg/config.c ============================================================================== --- head/usr.sbin/pkg/config.c Sun Feb 23 21:50:11 2014 (r262399) +++ head/usr.sbin/pkg/config.c Sun Feb 23 21:55:07 2014 (r262400) @@ -37,7 +37,7 @@ __FBSDID("$FreeBSD$"); #include #include -#include +#include #include #include #include @@ -509,76 +509,45 @@ boolstr_to_bool(const char *str) } static void -config_parse(yaml_document_t *doc, yaml_node_t *node, pkg_conf_file_t conftype) +config_parse(ucl_object_t *obj, pkg_conf_file_t conftype) { - yaml_node_item_t *item; - yaml_node_pair_t *pair; - yaml_node_t *key, *val, *item_val; struct sbuf *buf = sbuf_new_auto(); + ucl_object_t *cur, *seq; + ucl_object_iter_t it = NULL, itseq = NULL; struct config_entry *temp_config; struct config_value *cv; + const char *key; int i; size_t j; - pair = node->data.mapping.pairs.start; - /* Temporary config for configs that may be disabled. */ temp_config = calloc(CONFIG_SIZE, sizeof(struct config_entry)); - while (pair < node->data.mapping.pairs.top) { - key = yaml_document_get_node(doc, pair->key); - val = yaml_document_get_node(doc, pair->value); - - /* - * ignoring silently empty keys can be empty lines - * or user mistakes - */ - if (key->data.scalar.length <= 0) { - ++pair; - continue; - } - - /* - * silently skip on purpose to allow user to leave - * empty lines without complaining - */ - if (val->type == YAML_NO_NODE || - (val->type == YAML_SCALAR_NODE && - val->data.scalar.length <= 0)) { - ++pair; + while ((cur = ucl_iterate_object(obj, &it, true))) { + key = ucl_object_key(cur); + if (key == NULL) continue; - } - sbuf_clear(buf); if (conftype == CONFFILE_PKG) { - for (j = 0; j < strlen(key->data.scalar.value); ++j) - sbuf_putc(buf, - toupper(key->data.scalar.value[j])); + for (j = 0; j < strlen(key); ++j) + sbuf_putc(buf, key[j]); sbuf_finish(buf); } else if (conftype == CONFFILE_REPO) { - /* The CONFFILE_REPO type is more restrictive. Only - parse known elements. */ - if (strcasecmp(key->data.scalar.value, "url") == 0) + if (strcasecmp(key, "url") == 0) sbuf_cpy(buf, "PACKAGESITE"); - else if (strcasecmp(key->data.scalar.value, - "mirror_type") == 0) + else if (strcasecmp(key, "mirror_type") == 0) sbuf_cpy(buf, "MIRROR_TYPE"); - else if (strcasecmp(key->data.scalar.value, - "signature_type") == 0) + else if (strcasecmp(key, "signature_type") == 0) sbuf_cpy(buf, "SIGNATURE_TYPE"); - else if (strcasecmp(key->data.scalar.value, - "fingerprints") == 0) + else if (strcasecmp(key, "fingerprints") == 0) sbuf_cpy(buf, "FINGERPRINTS"); - else if (strcasecmp(key->data.scalar.value, - "enabled") == 0) { - /* Skip disabled repos. */ - if (!boolstr_to_bool(val->data.scalar.value)) + else if (strcasecmp(key, "enabled") == 0) { + if ((cur->type != UCL_BOOLEAN) || + !ucl_object_toboolean(cur)) goto cleanup; - } else { /* Skip unknown entries for future use. */ - ++pair; + } else continue; - } sbuf_finish(buf); } @@ -588,51 +557,40 @@ config_parse(yaml_document_t *doc, yaml_ } /* Silently skip unknown keys to be future compatible. */ - if (i == CONFIG_SIZE) { - ++pair; + if (i == CONFIG_SIZE) continue; - } /* env has priority over config file */ - if (c[i].envset) { - ++pair; + if (c[i].envset) continue; - } /* Parse sequence value ["item1", "item2"] */ switch (c[i].type) { case PKG_CONFIG_LIST: - if (val->type != YAML_SEQUENCE_NODE) { - fprintf(stderr, "Skipping invalid array " + if (cur->type != UCL_ARRAY) { + warnx("Skipping invalid array " "value for %s.\n", c[i].key); - ++pair; continue; } - item = val->data.sequence.items.start; temp_config[i].list = malloc(sizeof(*temp_config[i].list)); STAILQ_INIT(temp_config[i].list); - while (item < val->data.sequence.items.top) { - item_val = yaml_document_get_node(doc, *item); - if (item_val->type != YAML_SCALAR_NODE) { - ++item; + while ((seq = ucl_iterate_object(cur, &itseq, true))) { + if (seq->type != UCL_STRING) continue; - } cv = malloc(sizeof(struct config_value)); cv->value = - strdup(item_val->data.scalar.value); + strdup(ucl_object_tostring(seq)); STAILQ_INSERT_TAIL(temp_config[i].list, cv, next); - ++item; } break; default: /* Normal string value. */ - temp_config[i].value = strdup(val->data.scalar.value); + temp_config[i].value = strdup(ucl_object_tostring(cur)); break; } - ++pair; } /* Repo is enabled, copy over all settings from temp_config. */ @@ -662,27 +620,22 @@ cleanup: * etc... */ static void -parse_repo_file(yaml_document_t *doc, yaml_node_t *node) +parse_repo_file(ucl_object_t *obj) { - yaml_node_pair_t *pair; + ucl_object_iter_t it = NULL; + ucl_object_t *cur; + const char *key; - pair = node->data.mapping.pairs.start; - while (pair < node->data.mapping.pairs.top) { - yaml_node_t *key = yaml_document_get_node(doc, pair->key); - yaml_node_t *val = yaml_document_get_node(doc, pair->value); + while ((cur = ucl_iterate_object(obj, &it, true))) { + key = ucl_object_key(cur); - if (key->data.scalar.length <= 0) { - ++pair; + if (key == NULL) continue; - } - if (val->type != YAML_MAPPING_NODE) { - ++pair; + if (cur->type != UCL_OBJECT) continue; - } - config_parse(doc, val, CONFFILE_REPO); - ++pair; + config_parse(cur, CONFFILE_REPO); } } @@ -690,37 +643,33 @@ parse_repo_file(yaml_document_t *doc, ya static int read_conf_file(const char *confpath, pkg_conf_file_t conftype) { - FILE *fp; - yaml_parser_t parser; - yaml_document_t doc; - yaml_node_t *node; + struct ucl_parser *p; + ucl_object_t *obj = NULL; - if ((fp = fopen(confpath, "r")) == NULL) { + p = ucl_parser_new(0); + + if (!ucl_parser_add_file(p, confpath)) { if (errno != ENOENT) - err(EXIT_FAILURE, "Unable to open configuration " - "file %s", confpath); + errx(EXIT_FAILURE, "Unable to parse configuration " + "file %s: %s", confpath, ucl_parser_get_error(p)); + ucl_parser_free(p); /* no configuration present */ return (1); } - yaml_parser_initialize(&parser); - yaml_parser_set_input_file(&parser, fp); - yaml_parser_load(&parser, &doc); - - node = yaml_document_get_root_node(&doc); - - if (node == NULL || node->type != YAML_MAPPING_NODE) + obj = ucl_parser_get_object(p); + if (obj->type != UCL_OBJECT) warnx("Invalid configuration format, ignoring the " "configuration file %s", confpath); else { if (conftype == CONFFILE_PKG) - config_parse(&doc, node, conftype); + config_parse(obj, conftype); else if (conftype == CONFFILE_REPO) - parse_repo_file(&doc, node); + parse_repo_file(obj); } - yaml_document_delete(&doc); - yaml_parser_delete(&parser); + ucl_object_free(obj); + ucl_parser_free(p); return (0); } Modified: head/usr.sbin/pkg/pkg.c ============================================================================== --- head/usr.sbin/pkg/pkg.c Sun Feb 23 21:50:11 2014 (r262399) +++ head/usr.sbin/pkg/pkg.c Sun Feb 23 21:55:07 2014 (r262400) @@ -49,7 +49,7 @@ __FBSDID("$FreeBSD$"); #include #include #include -#include +#include #include #include @@ -268,38 +268,28 @@ cleanup: } static struct fingerprint * -parse_fingerprint(yaml_document_t *doc, yaml_node_t *node) +parse_fingerprint(ucl_object_t *obj) { - yaml_node_pair_t *pair; - yaml_char_t *function, *fp; + ucl_object_t *cur; + ucl_object_iter_t it = NULL; + const char *function, *fp, *key; struct fingerprint *f; hash_t fct = HASH_UNKNOWN; function = fp = NULL; - pair = node->data.mapping.pairs.start; - while (pair < node->data.mapping.pairs.top) { - yaml_node_t *key = yaml_document_get_node(doc, pair->key); - yaml_node_t *val = yaml_document_get_node(doc, pair->value); - - if (key->data.scalar.length <= 0) { - ++pair; + while ((cur = ucl_iterate_object(obj, &it, true))) { + key = ucl_object_key(cur); + if (cur->type != UCL_STRING) + continue; + if (strcasecmp(key, "function") == 0) { + function = ucl_object_tostring(cur); continue; } - - if (val->type != YAML_SCALAR_NODE) { - ++pair; + if (strcasecmp(key, "fingerprint") == 0) { + fp = ucl_object_tostring(cur); continue; } - - if (strcasecmp(key->data.scalar.value, "function") == 0) - function = val->data.scalar.value; - else if (strcasecmp(key->data.scalar.value, "fingerprint") - == 0) - fp = val->data.scalar.value; - - ++pair; - continue; } if (fp == NULL || function == NULL) @@ -309,7 +299,7 @@ parse_fingerprint(yaml_document_t *doc, fct = HASH_SHA256; if (fct == HASH_UNKNOWN) { - fprintf(stderr, "Unsupported hashing function: %s\n", function); + warnx("Unsupported hashing function: %s\n", function); return (NULL); } @@ -335,10 +325,8 @@ free_fingerprint_list(struct fingerprint static struct fingerprint * load_fingerprint(const char *dir, const char *filename) { - yaml_parser_t parser; - yaml_document_t doc; - yaml_node_t *node; - FILE *fp; + ucl_object_t *obj = NULL; + struct ucl_parser *p = NULL; struct fingerprint *f; char path[MAXPATHLEN]; @@ -346,24 +334,23 @@ load_fingerprint(const char *dir, const snprintf(path, MAXPATHLEN, "%s/%s", dir, filename); - if ((fp = fopen(path, "r")) == NULL) + p = ucl_parser_new(0); + if (!ucl_parser_add_file(p, path)) { + warnx("%s: %s", path, ucl_parser_get_error(p)); + ucl_parser_free(p); return (NULL); + } - yaml_parser_initialize(&parser); - yaml_parser_set_input_file(&parser, fp); - yaml_parser_load(&parser, &doc); - - node = yaml_document_get_root_node(&doc); - if (node == NULL || node->type != YAML_MAPPING_NODE) - goto out; - - f = parse_fingerprint(&doc, node); - f->name = strdup(filename); - -out: - yaml_document_delete(&doc); - yaml_parser_delete(&parser); - fclose(fp); + obj = ucl_parser_get_object(p); + + if (obj->type == UCL_OBJECT) + f = parse_fingerprint(obj); + + if (f != NULL) + f->name = strdup(filename); + + ucl_object_free(obj); + ucl_parser_free(p); return (f); }