LCOV - code coverage report
Current view: top level - lib/sifp - sss_sifp_utils.c (source / functions) Hit Total Coverage
Test: .coverage.total Lines: 36 40 90.0 %
Date: 2015-10-19 Functions: 5 5 100.0 %

          Line data    Source code
       1             : /*
       2             :     Authors:
       3             :         Pavel Březina <pbrezina@redhat.com>
       4             : 
       5             :     Copyright (C) 2014 Red Hat
       6             : 
       7             :     This program is free software; you can redistribute it and/or modify
       8             :     it under the terms of the GNU General Public License as published by
       9             :     the Free Software Foundation; either version 3 of the License, or
      10             :     (at your option) any later version.
      11             : 
      12             :     This program is distributed in the hope that it will be useful,
      13             :     but WITHOUT ANY WARRANTY; without even the implied warranty of
      14             :     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      15             :     GNU General Public License for more details.
      16             : 
      17             :     You should have received a copy of the GNU General Public License
      18             :     along with this program.  If not, see <http://www.gnu.org/licenses/>.
      19             : */
      20             : 
      21             : #include <dbus/dbus.h>
      22             : #include <string.h>
      23             : 
      24             : #include "lib/sifp/sss_sifp.h"
      25             : #include "lib/sifp/sss_sifp_private.h"
      26             : 
      27         199 : void *sss_sifp_alloc_zero(sss_sifp_ctx *ctx, size_t size, size_t num)
      28             : {
      29         199 :     void *addr = ctx->alloc_fn(size * num, ctx->alloc_pvt);
      30             : 
      31         199 :     if (addr == NULL) {
      32           0 :         return NULL;
      33             :     }
      34             : 
      35         199 :     memset(addr, '\0', size * num);
      36             : 
      37         199 :     return addr;
      38             : }
      39             : 
      40           2 : void sss_sifp_set_io_error(sss_sifp_ctx *ctx, DBusError *error)
      41             : {
      42           2 :     dbus_error_free(ctx->io_error);
      43           2 :     dbus_error_init(ctx->io_error);
      44           2 :     dbus_set_error(ctx->io_error, error->name, error->message);
      45           2 : }
      46             : 
      47             : const char *
      48           6 : sss_sifp_get_iface_for_object(const char *object_path)
      49             : {
      50             :     int i;
      51             :     const char *path;
      52             :     static struct {
      53             :         const char *path;
      54             :         const char *iface;
      55             :     } known_types[] = {
      56             :         {SSS_SIFP_PATH_IFP "/Components/", SSS_SIFP_IFACE_COMPONENTS},
      57             :         {SSS_SIFP_PATH_IFP "/Domains/", SSS_SIFP_IFACE_DOMAINS},
      58             :         {SSS_SIFP_PATH_IFP "/Services/", SSS_SIFP_IFACE_SERVICES},
      59             :         {SSS_SIFP_PATH_IFP "/Users/", SSS_SIFP_IFACE_USERS},
      60             :         {SSS_SIFP_PATH_IFP "/Groups/", SSS_SIFP_IFACE_GROUPS},
      61             :         {NULL, NULL}
      62             :     };
      63             : 
      64          17 :     for (i = 0; known_types[i].path != NULL; i++) {
      65          17 :         path = known_types[i].path;
      66          17 :         if (strncmp(path, object_path, strlen(path)) == 0) {
      67           6 :             return known_types[i].iface;
      68             :         }
      69             :     }
      70             : 
      71           0 :     return NULL;
      72             : }
      73             : 
      74          84 : char * sss_sifp_strdup(sss_sifp_ctx *ctx, const char *str)
      75             : {
      76          84 :     char *result = NULL;
      77             :     size_t str_len;
      78             : 
      79          84 :     if (str == NULL) {
      80           2 :         return NULL;
      81             :     }
      82             : 
      83          82 :     str_len = strlen(str);
      84          82 :     result = _alloc_zero(ctx, char, str_len + 1);
      85          82 :     if (result == NULL) {
      86           0 :         return NULL;
      87             :     }
      88             : 
      89          82 :     strncpy(result, str, str_len);
      90             : 
      91          82 :     return result;
      92             : }
      93             : 
      94          10 : char * sss_sifp_strcat(sss_sifp_ctx *ctx, const char *str1, const char *str2)
      95             : {
      96          10 :     char *result = NULL;
      97             : 
      98          10 :     if (str1 == NULL) {
      99           2 :         return sss_sifp_strdup(ctx, str2);
     100             :     }
     101             : 
     102           8 :     if (str2 == NULL) {
     103           1 :         return sss_sifp_strdup(ctx, str1);
     104             :     }
     105             : 
     106           7 :     size_t len = strlen(str1) + strlen(str2) + 1;
     107             : 
     108           7 :     result = _alloc_zero(ctx, char, len);
     109           7 :     if (result == NULL) {
     110           0 :         return NULL;
     111             :     }
     112             : 
     113           7 :     strcat(result, str1);
     114           7 :     strcat(result, str2);
     115             : 
     116           7 :     return result;
     117             : }

Generated by: LCOV version 1.10