/*-1* Copyright (c) 2014 Baptiste Daroussin <[email protected]>2* All rights reserved.3*4* Redistribution and use in source and binary forms, with or without5* modification, are permitted provided that the following conditions6* are met:7* 1. Redistributions of source code must retain the above copyright8* notice, this list of conditions and the following disclaimer9* in this position and unchanged.10* 2. Redistributions in binary form must reproduce the above copyright11* notice, this list of conditions and the following disclaimer in the12* documentation and/or other materials provided with the distribution.13*14* THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR15* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES16* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.17* IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,18* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT19* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,20* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY21* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT22* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF23* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.24*/2526#include <assert.h>27#include <ucl.h>28#include "pkg.h"29#include "private/pkg.h"3031char *32pkg_object_dump(const pkg_object *o)33{34if (o == NULL)35return xstrdup("");3637return (ucl_object_emit(o, UCL_EMIT_CONFIG));38}3940void41pkg_object_free(pkg_object *o)42{43ucl_object_unref(o);44}4546const char *47pkg_object_key(const pkg_object *o)48{49if (o == NULL)50return (NULL);5152return (ucl_object_key(o));53}5455const pkg_object *56pkg_object_iterate(const pkg_object *o, pkg_iter *it)57{58if (o == NULL)59return (NULL);6061return (ucl_iterate_object(o, it, true));62}6364pkg_object_t65pkg_object_type(const pkg_object *o)66{6768if (o == NULL)69return (PKG_NULL);7071switch (o->type) {72case UCL_OBJECT:73return (PKG_OBJECT);74case UCL_BOOLEAN:75return (PKG_BOOL);76case UCL_STRING:77return (PKG_STRING);78case UCL_INT:79return (PKG_INT);80case UCL_ARRAY:81return (PKG_ARRAY);82default:83return (PKG_NULL);84};8586}8788bool89pkg_object_bool(const pkg_object *o)90{91if (o == NULL || o->type != UCL_BOOLEAN)92return (false);9394return (ucl_object_toboolean(o));95}9697const char *98pkg_object_string(const pkg_object *o)99{100const char *ret;101102if (o == NULL)103return (NULL);104105ret = ucl_object_tostring_forced(o);106107if (ret && *ret == '\0')108return (NULL);109return (ret);110}111112int64_t113pkg_object_int(const pkg_object *o)114{115if (o == NULL || o->type != UCL_INT)116return (0);117118return (ucl_object_toint(o));119}120121122