LCOV - code coverage report
Current view: top level - lib/sifp - sss_sifp_dbus.c (source / functions) Hit Total Coverage
Test: .coverage.total Lines: 55 70 78.6 %
Date: 2015-10-19 Functions: 6 6 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 <stdlib.h>
      23             : #include <string.h>
      24             : 
      25             : #include "lib/sifp/sss_sifp.h"
      26             : #include "lib/sifp/sss_sifp_dbus.h"
      27             : #include "lib/sifp/sss_sifp_private.h"
      28             : 
      29           6 : static sss_sifp_error sss_sifp_ifp_call(sss_sifp_ctx *ctx,
      30             :                                         const char *method,
      31             :                                         int first_arg_type,
      32             :                                         va_list ap,
      33             :                                         DBusMessage **_reply)
      34             : {
      35           6 :    DBusMessage *msg = NULL;
      36             :    sss_sifp_error ret;
      37             : 
      38           6 :    msg = sss_sifp_create_message(SSS_SIFP_PATH_IFP, SSS_SIFP_IFACE_IFP, method);
      39           6 :    if (msg == NULL) {
      40           0 :        ret = SSS_SIFP_OUT_OF_MEMORY;
      41           0 :        goto done;
      42             :    }
      43             : 
      44           6 :    if (first_arg_type != DBUS_TYPE_INVALID) {
      45           3 :        dbus_message_append_args_valist(msg, first_arg_type, ap);
      46             :    }
      47             : 
      48           6 :    ret = sss_sifp_send_message(ctx, msg, _reply);
      49             : 
      50             : done:
      51           6 :    if (msg != NULL) {
      52           6 :        dbus_message_unref(msg);
      53             :    }
      54             : 
      55           6 :    return ret;
      56             : }
      57             : 
      58             : DBusMessage *
      59          12 : sss_sifp_create_message(const char *object_path,
      60             :                         const char *interface,
      61             :                         const char *method)
      62             : {
      63          12 :     return dbus_message_new_method_call(SSS_SIFP_IFP, object_path,
      64             :                                         interface, method);
      65             : }
      66             : 
      67             : sss_sifp_error
      68          12 : sss_sifp_send_message(sss_sifp_ctx *ctx,
      69             :                       DBusMessage *msg,
      70             :                       DBusMessage **_reply)
      71             : {
      72          12 :     return sss_sifp_send_message_ex(ctx, msg, 5000, _reply);
      73             : }
      74             : 
      75             : sss_sifp_error
      76          12 : sss_sifp_send_message_ex(sss_sifp_ctx *ctx,
      77             :                          DBusMessage *msg,
      78             :                          int timeout,
      79             :                          DBusMessage **_reply)
      80             : {
      81          12 :     DBusMessage *reply = NULL;
      82             :     DBusError dbus_error;
      83             :     sss_sifp_error ret;
      84             : 
      85          12 :     if (ctx == NULL || msg == NULL) {
      86           0 :         return SSS_SIFP_INVALID_ARGUMENT;
      87             :     }
      88             : 
      89          12 :     dbus_error_init(&dbus_error);
      90             : 
      91          12 :     reply = dbus_connection_send_with_reply_and_block(ctx->conn, msg,
      92             :                                                       timeout, &dbus_error);
      93          12 :     if (dbus_error_is_set(&dbus_error)) {
      94           0 :         sss_sifp_set_io_error(ctx, &dbus_error);
      95           0 :         ret = SSS_SIFP_IO_ERROR;
      96           0 :         goto done;
      97             :     }
      98             : 
      99          12 :     if (_reply == NULL) {
     100           0 :         dbus_message_unref(reply);
     101             :     } else {
     102          12 :         *_reply = reply;
     103             :     }
     104             : 
     105          12 :     ret = SSS_SIFP_OK;
     106             : 
     107             : done:
     108          12 :     dbus_error_free(&dbus_error);
     109          12 :     return ret;
     110             : }
     111             : 
     112             : sss_sifp_error
     113           3 : sss_sifp_invoke_list(sss_sifp_ctx *ctx,
     114             :                      const char *method,
     115             :                      char ***_object_paths,
     116             :                      int first_arg_type,
     117             :                      ...)
     118             : {
     119           3 :     DBusMessage *reply = NULL;
     120           3 :     char *dbus_method = NULL;
     121             :     sss_sifp_error ret;
     122             :     va_list ap;
     123             : 
     124           3 :     if (ctx == NULL || method == NULL || _object_paths == NULL) {
     125           0 :         return SSS_SIFP_INVALID_ARGUMENT;
     126             :     }
     127             : 
     128           3 :     dbus_method = sss_sifp_strcat(ctx, "List", method);
     129           3 :     if (dbus_method == NULL) {
     130           0 :         ret = SSS_SIFP_OUT_OF_MEMORY;
     131           0 :         goto done;
     132             :     }
     133             : 
     134           3 :     va_start(ap, first_arg_type);
     135           3 :     ret = sss_sifp_ifp_call(ctx, dbus_method, first_arg_type, ap, &reply);
     136           3 :     va_end(ap);
     137           3 :     if (ret != SSS_SIFP_OK) {
     138           0 :         goto done;
     139             :     }
     140             : 
     141           3 :     ret = sss_sifp_parse_object_path_list(ctx, reply, _object_paths);
     142             : 
     143             : done:
     144           3 :     sss_sifp_free_string(ctx, &dbus_method);
     145             : 
     146           3 :     if (reply != NULL) {
     147           3 :         dbus_message_unref(reply);
     148             :     }
     149             : 
     150           3 :     return ret;
     151             : }
     152             : 
     153             : sss_sifp_error
     154           3 : sss_sifp_invoke_find(sss_sifp_ctx *ctx,
     155             :                      const char *method,
     156             :                      char **_object_path,
     157             :                      int first_arg_type,
     158             :                      ...)
     159             : {
     160           3 :    DBusMessage *reply = NULL;
     161           3 :    char *dbus_method = NULL;
     162             :    sss_sifp_error ret;
     163             :    va_list ap;
     164             : 
     165           3 :    if (ctx == NULL || method == NULL || _object_path == NULL) {
     166           0 :        return SSS_SIFP_INVALID_ARGUMENT;
     167             :    }
     168             : 
     169           3 :    dbus_method = sss_sifp_strcat(ctx, "Find", method);
     170           3 :    if (dbus_method == NULL) {
     171           0 :        ret = SSS_SIFP_OUT_OF_MEMORY;
     172           0 :        goto done;
     173             :    }
     174             : 
     175           3 :    va_start(ap, first_arg_type);
     176           3 :    ret = sss_sifp_ifp_call(ctx, dbus_method, first_arg_type, ap, &reply);
     177           3 :    va_end(ap);
     178           3 :    if (ret != SSS_SIFP_OK) {
     179           0 :        goto done;
     180             :    }
     181             : 
     182           3 :    ret = sss_sifp_parse_object_path(ctx, reply, _object_path);
     183             : 
     184             : done:
     185           3 :     sss_sifp_free_string(ctx, &dbus_method);
     186             : 
     187           3 :    if (reply != NULL) {
     188           3 :        dbus_message_unref(reply);
     189             :    }
     190             : 
     191           3 :    return ret;
     192             : }

Generated by: LCOV version 1.10