summaryrefslogtreecommitdiffstats
path: root/ext/dl/lib
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-03-11 16:20:44 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-03-11 16:20:44 +0000
commitc4e5e000195b7b4a05c463dafb75a254b6f4b965 (patch)
tree1643538a6599df3bca30119ca818bf643c13a79e /ext/dl/lib
parentafce7aab00d697864b4c7ed9d1ced37aafa29556 (diff)
* enum.c (enum_zip): optimize if all arguments are arrays.
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@15751 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/dl/lib')
0 files changed, 0 insertions, 0 deletions
n54' href='#n54'>54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
/*
    Authors:
        Pavel Březina <pbrezina@redhat.com>

    Copyright (C) 2014 Red Hat

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#include <dbus/dbus.h>

#include "lib/sifp/sss_sifp.h"
#include "lib/sifp/sss_sifp_dbus.h"
#include "lib/sifp/sss_sifp_private.h"

#define SSS_SIFP_ATTR_NAME "name"

static sss_sifp_error
sss_sifp_fetch_object_by_attr(sss_sifp_ctx *ctx,
                              const char *method,
                              int attr_type,
                              const void *attr,
                              sss_sifp_object **_object)
{
    sss_sifp_object *object = NULL;
    char *object_path = NULL;
    const char *interface = NULL;
    sss_sifp_error ret;

    if (method == NULL || attr == NULL || attr_type == DBUS_TYPE_INVALID) {
        return SSS_SIFP_INVALID_ARGUMENT;
    }

    ret = sss_sifp_invoke_find(ctx, method, &object_path,
                               attr_type, attr,
                               DBUS_TYPE_INVALID);
    if (ret != SSS_SIFP_OK) {
        goto done;
    }

    interface = sss_sifp_get_iface_for_object(object_path);
    if (interface == NULL) {
        return SSS_SIFP_INTERNAL_ERROR;
    }

    ret = sss_sifp_fetch_object(ctx, object_path, interface, &object);
    if (ret != SSS_SIFP_OK) {
        goto done;
    }

    *_object = object;

    ret = SSS_SIFP_OK;

done:
    sss_sifp_free_string(ctx, &object_path);

    return ret;
}

static sss_sifp_error
sss_sifp_fetch_object_by_name(sss_sifp_ctx *ctx,
                              const char *method,
                              const char *name,
                              sss_sifp_object **_object)
{
    return sss_sifp_fetch_object_by_attr(ctx, method, DBUS_TYPE_STRING, &name,
                                         _object);
}

sss_sifp_error
sss_sifp_list_domains(sss_sifp_ctx *ctx,
                      char ***_domains)
{
    sss_sifp_attr **attrs = NULL;
    char **object_paths = NULL;
    char **domains = NULL;
    const char *name = NULL;
    unsigned int size;
    unsigned int i;
    sss_sifp_error ret;

    if (_domains == NULL) {
        return SSS_SIFP_INVALID_ARGUMENT;
    }

    ret = sss_sifp_invoke_list(ctx, "Domains", &object_paths,
                               DBUS_TYPE_INVALID);
    if (ret != SSS_SIFP_OK) {
        goto done;
    }

    /* calculate number of paths acquired and allocate memory for domains */
    for (size = 0; object_paths[size] != NULL; size++);

    domains = _alloc_zero(ctx, char *, size + 1);
    if (domains == NULL) {
        ret = SSS_SIFP_OUT_OF_MEMORY;
        goto done;
    }

    /* fetch domain name */
    for (i = 0; i < size; i++) {
        ret = sss_sifp_fetch_attr(ctx, object_paths[i],
                                  SSS_SIFP_IFACE_DOMAINS,
                                  SSS_SIFP_ATTR_NAME, &attrs);
        if (ret != SSS_SIFP_OK) {
            goto done;
        }

        ret = sss_sifp_find_attr_as_string(attrs, SSS_SIFP_ATTR_NAME, &name);
        if (ret != SSS_SIFP_OK) {
            goto done;
        }

        domains[i] = sss_sifp_strdup(ctx, name);
        if (domains[i] == NULL) {
            ret = SSS_SIFP_OUT_OF_MEMORY;
            goto done;
        }

        sss_sifp_free_attrs(ctx, &attrs);
    }

    domains[i] = NULL;

    *_domains = domains;