LCOV - code coverage report
Current view: top level - libpkg - pkg_object.c (source / functions) Hit Total Coverage
Test: cov.info Lines: 26 46 56.5 %
Date: 2015-08-15 Functions: 7 10 70.0 %

          Line data    Source code
       1             : /*-
       2             :  * Copyright (c) 2014 Baptiste Daroussin <bapt@FreeBSD.org>
       3             :  * All rights reserved.
       4             :  * 
       5             :  * Redistribution and use in source and binary forms, with or without
       6             :  * modification, are permitted provided that the following conditions
       7             :  * are met:
       8             :  * 1. Redistributions of source code must retain the above copyright
       9             :  *    notice, this list of conditions and the following disclaimer
      10             :  *    in this position and unchanged.
      11             :  * 2. Redistributions in binary form must reproduce the above copyright
      12             :  *    notice, this list of conditions and the following disclaimer in the
      13             :  *    documentation and/or other materials provided with the distribution.
      14             :  * 
      15             :  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
      16             :  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
      17             :  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
      18             :  * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
      19             :  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
      20             :  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
      21             :  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
      22             :  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
      23             :  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
      24             :  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
      25             :  */
      26             : 
      27             : #include <assert.h>
      28             : #include <ucl.h>
      29             : #include "pkg.h"
      30             : #include "private/pkg.h"
      31             : 
      32             : const char *
      33           2 : pkg_object_dump(const pkg_object *o)
      34             : {
      35           2 :         if (o == NULL)
      36           0 :                 return ("");
      37             : 
      38           2 :         return (ucl_object_emit(o, UCL_EMIT_CONFIG));
      39             : }
      40             : 
      41             : void
      42           0 : pkg_object_free(pkg_object *o)
      43             : {
      44           0 :         ucl_object_unref(o);
      45           0 : }
      46             : 
      47             : const char *
      48        4262 : pkg_object_key(const pkg_object *o)
      49             : {
      50        4262 :         if (o == NULL)
      51           0 :                 return (NULL);
      52             : 
      53        4262 :         return (ucl_object_key(o));
      54             : }
      55             : 
      56             : const pkg_object *
      57        5053 : pkg_object_iterate(const pkg_object *o, pkg_iter *it)
      58             : {
      59        5053 :         if (o == NULL)
      60           0 :                 return (NULL);
      61             : 
      62        5053 :         return (ucl_iterate_object(o, it, true));
      63             : }
      64             : 
      65             : pkg_object_t
      66           1 : pkg_object_type(const pkg_object *o)
      67             : {
      68             : 
      69           1 :         if (o == NULL)
      70           0 :                 return (PKG_NULL);
      71             : 
      72           1 :         switch (o->type) {
      73             :         case UCL_OBJECT:
      74           0 :                 return (PKG_OBJECT);
      75             :         case UCL_BOOLEAN:
      76           0 :                 return (PKG_BOOL);
      77             :         case UCL_STRING:
      78           1 :                 return (PKG_STRING);
      79             :         case UCL_INT:
      80           0 :                 return (PKG_INT);
      81             :         case UCL_ARRAY:
      82           0 :                 return (PKG_ARRAY);
      83             :         default:
      84           0 :                 return (PKG_NULL);
      85             :         };
      86             : 
      87             : }
      88             : 
      89             : bool
      90        1914 : pkg_object_bool(const pkg_object *o)
      91             : {
      92        1914 :         if (o == NULL || o->type != UCL_BOOLEAN)
      93           0 :                 return (false);
      94             : 
      95        1914 :         return (ucl_object_toboolean(o));
      96             : }
      97             : 
      98             : const char *
      99        2481 : pkg_object_string(const pkg_object *o)
     100             : {
     101             :         const char *ret;
     102             : 
     103        2481 :         if (o == NULL)
     104           2 :                 return (NULL);
     105             : 
     106        2479 :         ret = ucl_object_tostring_forced(o);
     107             : 
     108        2479 :         if (ret && *ret == '\0')
     109         430 :                 return (NULL);
     110        2049 :         return (ret);
     111             : }
     112             : 
     113             : int64_t
     114         595 : pkg_object_int(const pkg_object *o)
     115             : {
     116         595 :         if (o == NULL || o->type != UCL_INT)
     117           0 :                 return (0);
     118             : 
     119         595 :         return (ucl_object_toint(o));
     120             : }
     121             : 
     122             : unsigned
     123           0 : pkg_object_count(const pkg_object *o)
     124             : {
     125           0 :         return (UCL_COUNT(o));
     126             : }
     127             : 
     128             : const pkg_object *
     129           0 : pkg_object_find(const pkg_object *o, const char *key)
     130             : {
     131           0 :         if (o == NULL)
     132           0 :                 return (NULL);
     133             : 
     134           0 :         return (ucl_object_find_key(o, key));
     135             : }

Generated by: LCOV version 1.10