Coverage report for dbus/dbus-bus.c.gcov

        -:    0:Source:dbus-bus.c
        -:    0:Graph:.libs/dbus-bus.gcno
        -:    0:Data:.libs/dbus-bus.gcda
        -:    0:Runs:11813
        -:    0:Programs:5
        -:    1:/* -*- mode: C; c-file-style: "gnu" -*- */
        -:    2:/* dbus-bus.c  Convenience functions for communicating with the bus.
        -:    3: *
        -:    4: * Copyright (C) 2003  CodeFactory AB
        -:    5: * Copyright (C) 2003  Red Hat, Inc.
        -:    6: *
        -:    7: * Licensed under the Academic Free License version 2.1
        -:    8: * 
        -:    9: * This program is free software; you can redistribute it and/or modify
        -:   10: * it under the terms of the GNU General Public License as published by
        -:   11: * the Free Software Foundation; either version 2 of the License, or
        -:   12: * (at your option) any later version.
        -:   13: *
        -:   14: * This program is distributed in the hope that it will be useful,
        -:   15: * but WITHOUT ANY WARRANTY; without even the implied warranty of
        -:   16: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
        -:   17: * GNU General Public License for more details.
        -:   18: * 
        -:   19: * You should have received a copy of the GNU General Public License
        -:   20: * along with this program; if not, write to the Free Software
        -:   21: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
        -:   22: *
        -:   23: */
        -:   24:
        -:   25:#include "dbus-bus.h"
        -:   26:#include "dbus-protocol.h"
        -:   27:#include "dbus-internals.h"
        -:   28:#include "dbus-message.h"
        -:   29:#include "dbus-marshal-validate.h"
        -:   30:#include "dbus-threads-internal.h"
        -:   31:#include <string.h>
        -:   32:
        -:   33:/**
        -:   34: * @defgroup DBusBus Message bus APIs
        -:   35: * @ingroup DBus
        -:   36: * @brief Functions for communicating with the message bus
        -:   37: *
        -:   38: * @todo right now the default address of the system bus is hardcoded,
        -:   39: * so if you change it in the global config file suddenly you have to
        -:   40: * set DBUS_SYSTEM_BUS_ADDRESS env variable.  Might be nice if the
        -:   41: * client lib somehow read the config file, or if the bus on startup
        -:   42: * somehow wrote out its address to a well-known spot, but might also
        -:   43: * not be worth it.
        -:   44: */
        -:   45:
        -:   46:/**
        -:   47: * @defgroup DBusBusInternals Message bus APIs internals
        -:   48: * @ingroup DBusInternals
        -:   49: * @brief Internals of functions for communicating with the message bus
        -:   50: *
        -:   51: * @{
        -:   52: */
        -:   53:
        -:   54:/**
        -:   55: * Block of message-bus-related data we attach to each
        -:   56: * #DBusConnection used with these convenience functions.
        -:   57: *
        -:   58: */
        -:   59:typedef struct
        -:   60:{
        -:   61:  DBusConnection *connection; /**< Connection we're associated with */
        -:   62:  char *unique_name; /**< Unique name of this connection */
        -:   63:
        -:   64:  unsigned int is_well_known : 1; /**< Is one of the well-known connections in our global array */
        -:   65:} BusData;
        -:   66:
        -:   67:/** The slot we have reserved to store BusData.
        -:   68: */
        -:   69:static dbus_int32_t bus_data_slot = -1;
        -:   70:
        -:   71:/** Number of bus types */
        -:   72:#define N_BUS_TYPES 3
        -:   73:
        -:   74:static DBusConnection *bus_connections[N_BUS_TYPES];
        -:   75:static char *bus_connection_addresses[N_BUS_TYPES] = { NULL, NULL, NULL };
        -:   76:
        -:   77:static DBusBusType activation_bus_type = DBUS_BUS_STARTER;
        -:   78:
        -:   79:static dbus_bool_t initialized = FALSE;
        -:   80:
        -:   81:/**
        -:   82: * Lock for globals in this file
        -:   83: */
        -:   84:_DBUS_DEFINE_GLOBAL_LOCK (bus);
        -:   85:
        -:   86:static void
        -:   87:addresses_shutdown_func (void *data)
function addresses_shutdown_func called 0 returned 0% blocks executed 0%
    #####:   88:{
        -:   89:  int i;
        -:   90:
    #####:   91:  i = 0;
    #####:   92:  while (i < N_BUS_TYPES)
branch  0 never executed
branch  1 never executed
        -:   93:    {
    #####:   94:      if (bus_connections[i] != NULL)
branch  0 never executed
branch  1 never executed
    #####:   95:        _dbus_warn ("dbus_shutdown() called but connections were still live!");
call    0 never executed
        -:   96:      
    #####:   97:      dbus_free (bus_connection_addresses[i]);
call    0 never executed
    #####:   98:      bus_connection_addresses[i] = NULL;
    #####:   99:      ++i;
        -:  100:    }
        -:  101:
    #####:  102:  activation_bus_type = DBUS_BUS_STARTER;
    #####:  103:}
        -:  104:
        -:  105:static dbus_bool_t
        -:  106:get_from_env (char           **connection_p,
        -:  107:              const char      *env_var)
function get_from_env called 2787 returned 100% blocks executed 100%
     2787:  108:{
        -:  109:  const char *s;
        -:  110:  
     2787:  111:  _dbus_assert (*connection_p == NULL);
call    0 returned 100%
        -:  112:  
     2787:  113:  s = _dbus_getenv (env_var);
call    0 returned 100%
     2787:  114:  if (s == NULL || *s == '\0')
branch  0 taken 67% (fallthrough)
branch  1 taken 33%
branch  2 taken 0% (fallthrough)
branch  3 taken 100%
      930:  115:    return TRUE; /* successfully didn't use the env var */
        -:  116:  else
        -:  117:    {
     1857:  118:      *connection_p = _dbus_strdup (s);
call    0 returned 100%
     1857:  119:      return *connection_p != NULL;
        -:  120:    }
        -:  121:}
        -:  122:
        -:  123:static dbus_bool_t
        -:  124:init_connections_unlocked (void)
function init_connections_unlocked called 929 returned 100% blocks executed 72%
      929:  125:{
      929:  126:  if (!initialized)
branch  0 taken 100% (fallthrough)
branch  1 taken 0%
        -:  127:    {
        -:  128:      const char *s;
        -:  129:      int i;
        -:  130:
      929:  131:      i = 0;
     4645:  132:      while (i < N_BUS_TYPES)
branch  0 taken 75%
branch  1 taken 25% (fallthrough)
        -:  133:        {
     2787:  134:          bus_connections[i] = NULL;
     2787:  135:          ++i;
        -:  136:        }
        -:  137:
        -:  138:      /* Don't init these twice, we may run this code twice if
        -:  139:       * init_connections_unlocked() fails midway through.
        -:  140:       * In practice, each block below should contain only one
        -:  141:       * "return FALSE" or running through twice may not
        -:  142:       * work right.
        -:  143:       */
        -:  144:      
      929:  145:       if (bus_connection_addresses[DBUS_BUS_SYSTEM] == NULL)
branch  0 taken 100% (fallthrough)
branch  1 taken 0%
        -:  146:         {
      929:  147:           _dbus_verbose ("Filling in system bus address...\n");
call    0 returned 100%
        -:  148:           
      929:  149:           if (!get_from_env (&bus_connection_addresses[DBUS_BUS_SYSTEM],
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
        -:  150:                              "DBUS_SYSTEM_BUS_ADDRESS"))
    #####:  151:             return FALSE;
        -:  152:         }
        -:  153:
        -:  154:                  
      929:  155:       if (bus_connection_addresses[DBUS_BUS_SYSTEM] == NULL)
branch  0 taken 100% (fallthrough)
branch  1 taken 0%
        -:  156:         {
        -:  157:           /* Use default system bus address if none set in environment */
      929:  158:           bus_connection_addresses[DBUS_BUS_SYSTEM] =
call    0 returned 100%
        -:  159:             _dbus_strdup (DBUS_SYSTEM_BUS_DEFAULT_ADDRESS);
      929:  160:           if (bus_connection_addresses[DBUS_BUS_SYSTEM] == NULL)
branch  0 taken 0% (fallthrough)
branch  1 taken 100%
    #####:  161:             return FALSE;
        -:  162:           
      929:  163:           _dbus_verbose ("  used default system bus \"%s\"\n",
call    0 returned 100%
        -:  164:                          bus_connection_addresses[DBUS_BUS_SYSTEM]);
        -:  165:         }
        -:  166:       else
    #####:  167:         _dbus_verbose ("  used env var system bus \"%s\"\n",
call    0 never executed
        -:  168:                        bus_connection_addresses[DBUS_BUS_SYSTEM]);
        -:  169:          
      929:  170:      if (bus_connection_addresses[DBUS_BUS_SESSION] == NULL)
branch  0 taken 100% (fallthrough)
branch  1 taken 0%
        -:  171:        {
      929:  172:          _dbus_verbose ("Filling in session bus address...\n");
call    0 returned 100%
        -:  173:          
      929:  174:          if (!get_from_env (&bus_connection_addresses[DBUS_BUS_SESSION],
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
        -:  175:                             "DBUS_SESSION_BUS_ADDRESS"))
    #####:  176:            return FALSE;
      929:  177:          _dbus_verbose ("  \"%s\"\n", bus_connection_addresses[DBUS_BUS_SESSION] ?
branch  0 taken 100% (fallthrough)
branch  1 taken 0%
call    2 returned 100%
        -:  178:                         bus_connection_addresses[DBUS_BUS_SESSION] : "none set");
        -:  179:        }
        -:  180:
      929:  181:      if (bus_connection_addresses[DBUS_BUS_STARTER] == NULL)
branch  0 taken 100% (fallthrough)
branch  1 taken 0%
        -:  182:        {
      929:  183:          _dbus_verbose ("Filling in activation bus address...\n");
call    0 returned 100%
        -:  184:          
      929:  185:          if (!get_from_env (&bus_connection_addresses[DBUS_BUS_STARTER],
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
        -:  186:                             "DBUS_STARTER_ADDRESS"))
    #####:  187:            return FALSE;
        -:  188:          
      929:  189:          _dbus_verbose ("  \"%s\"\n", bus_connection_addresses[DBUS_BUS_STARTER] ?
branch  0 taken 99% (fallthrough)
branch  1 taken 1%
call    2 returned 100%
        -:  190:                         bus_connection_addresses[DBUS_BUS_STARTER] : "none set");
        -:  191:        }
        -:  192:
        -:  193:
      929:  194:      if (bus_connection_addresses[DBUS_BUS_STARTER] != NULL)
branch  0 taken 99% (fallthrough)
branch  1 taken 1%
        -:  195:        {
      928:  196:          s = _dbus_getenv ("DBUS_STARTER_BUS_TYPE");
call    0 returned 100%
        -:  197:              
      928:  198:          if (s != NULL)
branch  0 taken 0% (fallthrough)
branch  1 taken 100%
        -:  199:            {
    #####:  200:              _dbus_verbose ("Bus activation type was set to \"%s\"\n", s);
call    0 never executed
        -:  201:                  
    #####:  202:              if (strcmp (s, "system") == 0)
call    0 never executed
branch  1 never executed
branch  2 never executed
    #####:  203:                activation_bus_type = DBUS_BUS_SYSTEM;
    #####:  204:              else if (strcmp (s, "session") == 0)
call    0 never executed
branch  1 never executed
branch  2 never executed
    #####:  205:                activation_bus_type = DBUS_BUS_SESSION;
        -:  206:            }
        -:  207:        }
        -:  208:      else
        -:  209:        {
        -:  210:          /* Default to the session bus instead if available */
        1:  211:          if (bus_connection_addresses[DBUS_BUS_SESSION] != NULL)
branch  0 taken 100% (fallthrough)
branch  1 taken 0%
        -:  212:            {
        1:  213:              bus_connection_addresses[DBUS_BUS_STARTER] =
call    0 returned 100%
        -:  214:                _dbus_strdup (bus_connection_addresses[DBUS_BUS_SESSION]);
        1:  215:              if (bus_connection_addresses[DBUS_BUS_STARTER] == NULL)
branch  0 taken 0% (fallthrough)
branch  1 taken 100%
    #####:  216:                return FALSE;
        -:  217:            }
        -:  218:        }
        -:  219:      
        -:  220:      /* If we return FALSE we have to be sure that restarting
        -:  221:       * the above code will work right
        -:  222:       */
        -:  223:      
      929:  224:      if (!_dbus_setenv ("DBUS_ACTIVATION_ADDRESS", NULL))
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
    #####:  225:        return FALSE;
        -:  226:
      929:  227:      if (!_dbus_setenv ("DBUS_ACTIVATION_BUS_TYPE", NULL))
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
    #####:  228:        return FALSE;
        -:  229:      
      929:  230:      if (!_dbus_register_shutdown_func (addresses_shutdown_func,
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
        -:  231:                                         NULL))
    #####:  232:        return FALSE;
        -:  233:      
      929:  234:      initialized = TRUE;
        -:  235:    }
        -:  236:
      929:  237:  return initialized;
        -:  238:}
        -:  239:
        -:  240:static void
        -:  241:bus_data_free (void *data)
function bus_data_free called 5907 returned 100% blocks executed 42%
     5907:  242:{
     5907:  243:  BusData *bd = data;
        -:  244:  
     5907:  245:  if (bd->is_well_known)
branch  0 taken 0% (fallthrough)
branch  1 taken 100%
        -:  246:    {
        -:  247:      int i;
    #####:  248:      _DBUS_LOCK (bus);
call    0 never executed
        -:  249:      /* We may be stored in more than one slot */
    #####:  250:      i = 0;
    #####:  251:      while (i < N_BUS_TYPES)
branch  0 never executed
branch  1 never executed
        -:  252:        {
    #####:  253:          if (bus_connections[i] == bd->connection)
branch  0 never executed
branch  1 never executed
    #####:  254:            bus_connections[i] = NULL;
        -:  255:          
    #####:  256:          ++i;
        -:  257:        }
    #####:  258:      _DBUS_UNLOCK (bus);
call    0 never executed
        -:  259:    }
        -:  260:  
     5907:  261:  dbus_free (bd->unique_name);
call    0 returned 100%
     5907:  262:  dbus_free (bd);
call    0 returned 100%
        -:  263:
     5907:  264:  dbus_connection_free_data_slot (&bus_data_slot);
call    0 returned 100%
     5907:  265:}
        -:  266:
        -:  267:static BusData*
        -:  268:ensure_bus_data (DBusConnection *connection)
function ensure_bus_data called 13459 returned 100% blocks executed 94%
    13459:  269:{
        -:  270:  BusData *bd;
        -:  271:
    13459:  272:  if (!dbus_connection_allocate_data_slot (&bus_data_slot))
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
    #####:  273:    return NULL;
        -:  274:
    13459:  275:  bd = dbus_connection_get_data (connection, bus_data_slot);
call    0 returned 100%
    13459:  276:  if (bd == NULL)
branch  0 taken 47% (fallthrough)
branch  1 taken 53%
        -:  277:    {      
     6345:  278:      bd = dbus_new0 (BusData, 1);
call    0 returned 100%
     6345:  279:      if (bd == NULL)
branch  0 taken 1% (fallthrough)
branch  1 taken 99%
        -:  280:        {
       17:  281:          dbus_connection_free_data_slot (&bus_data_slot);
call    0 returned 100%
       17:  282:          return NULL;
        -:  283:        }
        -:  284:
     6328:  285:      bd->connection = connection;
        -:  286:      
     6328:  287:      if (!dbus_connection_set_data (connection, bus_data_slot, bd,
call    0 returned 100%
branch  1 taken 1% (fallthrough)
branch  2 taken 99%
        -:  288:                                     bus_data_free))
        -:  289:        {
        4:  290:          dbus_free (bd);
call    0 returned 100%
        4:  291:          dbus_connection_free_data_slot (&bus_data_slot);
call    0 returned 100%
        4:  292:          return NULL;
        -:  293:        }
        -:  294:
        -:  295:      /* Data slot refcount now held by the BusData */
        -:  296:    }
        -:  297:  else
        -:  298:    {
     7114:  299:      dbus_connection_free_data_slot (&bus_data_slot);
call    0 returned 100%
        -:  300:    }
        -:  301:
    13438:  302:  return bd;
        -:  303:}
        -:  304:
        -:  305:static DBusConnection *
        -:  306:internal_bus_get (DBusBusType  type,
        -:  307:	      DBusError   *error, dbus_bool_t private)
function internal_bus_get called 929 returned 100% blocks executed 59%
      929:  308:{
        -:  309:  const char *address;
        -:  310:  DBusConnection *connection;
        -:  311:  BusData *bd;
        -:  312:  DBusBusType address_type;
        -:  313:
      929:  314:  _dbus_return_val_if_fail (type >= 0 && type < N_BUS_TYPES, NULL);
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
call    3 never executed
call    4 never executed
      929:  315:  _dbus_return_val_if_error_is_set (error, NULL);
call    0 returned 100%
branch  1 taken 100% (fallthrough)
branch  2 taken 0%
call    3 returned 100%
branch  4 taken 0% (fallthrough)
branch  5 taken 100%
call    6 never executed
call    7 never executed
        -:  316:
      929:  317:  _DBUS_LOCK (bus);
call    0 returned 100%
        -:  318:
      929:  319:  if (!init_connections_unlocked ())
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
        -:  320:    {
    #####:  321:      _DBUS_UNLOCK (bus);
call    0 never executed
    #####:  322:      _DBUS_SET_OOM (error);
call    0 never executed
    #####:  323:      return NULL;
        -:  324:    }
        -:  325:
        -:  326:  /* We want to use the activation address even if the
        -:  327:   * activating bus is the session or system bus,
        -:  328:   * per the spec.
        -:  329:   */
      929:  330:  address_type = type;
        -:  331:  
        -:  332:  /* Use the real type of the activation bus for getting its
        -:  333:   * connection, but only if the real type's address is available. (If
        -:  334:   * the activating bus isn't a well-known bus then
        -:  335:   * activation_bus_type == DBUS_BUS_STARTER)
        -:  336:   */
      929:  337:  if (type == DBUS_BUS_STARTER &&
branch  0 taken 99% (fallthrough)
branch  1 taken 1%
branch  2 taken 100% (fallthrough)
branch  3 taken 0%
        -:  338:      bus_connection_addresses[activation_bus_type] != NULL)
      928:  339:    type = activation_bus_type;
        -:  340:  
      929:  341:  if (!private && bus_connections[type] != NULL)
branch  0 taken 100% (fallthrough)
branch  1 taken 0%
branch  2 taken 0% (fallthrough)
branch  3 taken 100%
        -:  342:    {
    #####:  343:      connection = bus_connections[type];
    #####:  344:      dbus_connection_ref (connection);
call    0 never executed
        -:  345:      
    #####:  346:      _DBUS_UNLOCK (bus);
call    0 never executed
    #####:  347:      return connection;
        -:  348:    }
        -:  349:
      929:  350:  address = bus_connection_addresses[address_type];
      929:  351:  if (address == NULL)
branch  0 taken 0% (fallthrough)
branch  1 taken 100%
        -:  352:    {
    #####:  353:      dbus_set_error (error, DBUS_ERROR_FAILED,
call    0 never executed
        -:  354:                      "Unable to determine the address of the message bus (try 'man dbus-launch' and 'man dbus-daemon' for help)");
    #####:  355:      _DBUS_UNLOCK (bus);
call    0 never executed
    #####:  356:      return NULL;
        -:  357:    }
        -:  358:
      929:  359:  if (private)
branch  0 taken 0% (fallthrough)
branch  1 taken 100%
    #####:  360:    connection = dbus_connection_open_private(address, error);
call    0 never executed
        -:  361:  else
      929:  362:    connection = dbus_connection_open (address, error);
call    0 returned 100%
        -:  363:  
      929:  364:  if (!connection)
branch  0 taken 0% (fallthrough)
branch  1 taken 100%
        -:  365:    {
    #####:  366:      _DBUS_ASSERT_ERROR_IS_SET (error);
branch  0 never executed
branch  1 never executed
call    2 never executed
branch  3 never executed
branch  4 never executed
call    5 never executed
    #####:  367:      _DBUS_UNLOCK (bus);
call    0 never executed
    #####:  368:      return NULL;
        -:  369:    }
        -:  370:
        -:  371:  /* By default we're bound to the lifecycle of
        -:  372:   * the message bus.
        -:  373:   */
      929:  374:  dbus_connection_set_exit_on_disconnect (connection,
call    0 returned 100%
        -:  375:                                          TRUE);
        -:  376:  
      929:  377:  if (!dbus_bus_register (connection, error))
call    0 returned 100%
branch  1 taken 55% (fallthrough)
branch  2 taken 45%
        -:  378:    {
      512:  379:      _DBUS_ASSERT_ERROR_IS_SET (error);
branch  0 taken 100% (fallthrough)
branch  1 taken 0%
call    2 returned 100%
branch  3 taken 100% (fallthrough)
branch  4 taken 0%
call    5 returned 100%
      512:  380:      dbus_connection_close (connection);
call    0 returned 100%
      512:  381:      dbus_connection_unref (connection);
call    0 returned 100%
        -:  382:
      512:  383:      _DBUS_UNLOCK (bus);
call    0 returned 100%
      512:  384:      return NULL;
        -:  385:    }
        -:  386:
      417:  387:  if (!private)
branch  0 taken 100% (fallthrough)
branch  1 taken 0%
      417:  388:    bus_connections[type] = connection;
        -:  389:  
      417:  390:  bd = ensure_bus_data (connection);
call    0 returned 100%
      417:  391:  _dbus_assert (bd != NULL);
call    0 returned 100%
        -:  392:
      417:  393:  bd->is_well_known = TRUE;
        -:  394:
      417:  395:  _DBUS_UNLOCK (bus);
call    0 returned 100%
      417:  396:  return connection;
        -:  397:}
        -:  398:
        -:  399:
        -:  400:/** @} */ /* end of implementation details docs */
        -:  401:
        -:  402:/**
        -:  403: * @addtogroup DBusBus
        -:  404: * @{
        -:  405: */
        -:  406:
        -:  407:/**
        -:  408: * Connects to a bus daemon and registers the client with it.  If a
        -:  409: * connection to the bus already exists, then that connection is
        -:  410: * returned.  Caller owns a reference to the bus.
        -:  411: *
        -:  412: * @todo alex thinks we should nullify the connection when we get a disconnect-message.
        -:  413: *
        -:  414: * @param type bus type
        -:  415: * @param error address where an error can be returned.
        -:  416: * @returns a DBusConnection with new ref
        -:  417: */
        -:  418:DBusConnection *
        -:  419:dbus_bus_get (DBusBusType  type,
function dbus_bus_get called 929 returned 100% blocks executed 100%
      929:  420:	      DBusError   *error) {
      929:  421:  return internal_bus_get(type, error, FALSE);
call    0 returned 100%
        -:  422:}
        -:  423:
        -:  424:/**
        -:  425: * Connects to a bus daemon and registers the client with it.  Unlike
        -:  426: * dbus_bus_get(), always creates a new connection. This connection
        -:  427: * will not be saved or recycled by libdbus. Caller owns a reference
        -:  428: * to the bus.
        -:  429: *
        -:  430: * @param type bus type
        -:  431: * @param error address where an error can be returned.
        -:  432: * @returns a DBusConnection with new ref
        -:  433: */
        -:  434:DBusConnection *
        -:  435:dbus_bus_get_private (DBusBusType  type,
function dbus_bus_get_private called 0 returned 0% blocks executed 0%
    #####:  436:	      DBusError   *error) {
    #####:  437:  return internal_bus_get(type, error, TRUE);
call    0 never executed
        -:  438:}
        -:  439:
        -:  440:/**
        -:  441: * Registers a connection with the bus. This must be the first
        -:  442: * thing an application does when connecting to the message bus.
        -:  443: * If registration succeeds, the unique name will be set,
        -:  444: * and can be obtained using dbus_bus_get_unique_name().
        -:  445: * 
        -:  446: * @param connection the connection
        -:  447: * @param error place to store errors
        -:  448: * @returns #TRUE on success
        -:  449: */
        -:  450:dbus_bool_t
        -:  451:dbus_bus_register (DBusConnection *connection,
        -:  452:                   DBusError      *error)
function dbus_bus_register called 929 returned 100% blocks executed 65%
      929:  453:{
        -:  454:  DBusMessage *message, *reply;
        -:  455:  char *name;
        -:  456:  BusData *bd;
        -:  457:  dbus_bool_t retval;
        -:  458:
      929:  459:  _dbus_return_val_if_fail (connection != NULL, FALSE);
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
call    3 never executed
call    4 never executed
      929:  460:  _dbus_return_val_if_error_is_set (error, FALSE);
call    0 returned 100%
branch  1 taken 100% (fallthrough)
branch  2 taken 0%
call    3 returned 100%
branch  4 taken 0% (fallthrough)
branch  5 taken 100%
call    6 never executed
call    7 never executed
        -:  461:
      929:  462:  retval = FALSE;
        -:  463:  
      929:  464:  bd = ensure_bus_data (connection);
call    0 returned 100%
      929:  465:  if (bd == NULL)
branch  0 taken 0% (fallthrough)
branch  1 taken 100%
        -:  466:    {
    #####:  467:      _DBUS_SET_OOM (error);
call    0 never executed
    #####:  468:      return FALSE;
        -:  469:    }
        -:  470:
      929:  471:  if (bd->unique_name != NULL)
branch  0 taken 0% (fallthrough)
branch  1 taken 100%
        -:  472:    {
    #####:  473:      _dbus_warn ("Attempt to register the same DBusConnection with the message bus, but it is already registered\n");
call    0 never executed
        -:  474:      /* This isn't an error, it's a programming bug. We'll be nice
        -:  475:       * and not _dbus_assert_not_reached()
        -:  476:       */
    #####:  477:      return TRUE;
        -:  478:    }
        -:  479:  
      929:  480:  message = dbus_message_new_method_call (DBUS_SERVICE_DBUS,
call    0 returned 100%
        -:  481:                                          DBUS_PATH_DBUS,
        -:  482:                                          DBUS_INTERFACE_DBUS,
        -:  483:                                          "Hello"); 
        -:  484:
      929:  485:  if (!message)
branch  0 taken 0% (fallthrough)
branch  1 taken 100%
        -:  486:    {
    #####:  487:      _DBUS_SET_OOM (error);
call    0 never executed
    #####:  488:      return FALSE;
        -:  489:    }
        -:  490:  
      929:  491:  reply = dbus_connection_send_with_reply_and_block (connection, message, -1, error);
call    0 returned 100%
        -:  492:
      929:  493:  dbus_message_unref (message);
call    0 returned 100%
        -:  494:  
      929:  495:  if (reply == NULL)
branch  0 taken 55% (fallthrough)
branch  1 taken 45%
      512:  496:    goto out;
      417:  497:  else if (dbus_set_error_from_message (error, reply))
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
    #####:  498:    goto out;
      417:  499:  else if (!dbus_message_get_args (reply, error,
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
        -:  500:                                   DBUS_TYPE_STRING, &name,
        -:  501:                                   DBUS_TYPE_INVALID))
    #####:  502:    goto out;
        -:  503:  
      417:  504:  bd->unique_name = _dbus_strdup (name);
call    0 returned 100%
      417:  505:  if (bd->unique_name == NULL)
branch  0 taken 0% (fallthrough)
branch  1 taken 100%
        -:  506:    {
    #####:  507:      _DBUS_SET_OOM (error);
call    0 never executed
    #####:  508:      goto out;
        -:  509:    }
        -:  510:  
      417:  511:  retval = TRUE;
        -:  512:  
      929:  513: out:
      929:  514:  if (reply)
branch  0 taken 45% (fallthrough)
branch  1 taken 55%
      417:  515:    dbus_message_unref (reply);
call    0 returned 100%
        -:  516:
      929:  517:  if (!retval)
branch  0 taken 55% (fallthrough)
branch  1 taken 45%
      512:  518:    _DBUS_ASSERT_ERROR_IS_SET (error);
branch  0 taken 100% (fallthrough)
branch  1 taken 0%
call    2 returned 100%
branch  3 taken 100% (fallthrough)
branch  4 taken 0%
call    5 returned 100%
        -:  519:  
      929:  520:  return retval;
        -:  521:}
        -:  522:
        -:  523:
        -:  524:/**
        -:  525: * Sets the unique name of the connection.  Can only be used if you
        -:  526: * registered with the bus manually (i.e. if you did not call
        -:  527: * dbus_bus_register()). Can only be called once per connection.
        -:  528: *
        -:  529: * @param connection the connection
        -:  530: * @param unique_name the unique name
        -:  531: * @returns #FALSE if not enough memory
        -:  532: */
        -:  533:dbus_bool_t
        -:  534:dbus_bus_set_unique_name (DBusConnection *connection,
        -:  535:                          const char     *unique_name)
function dbus_bus_set_unique_name called 3372 returned 100% blocks executed 65%
     3372:  536:{
        -:  537:  BusData *bd;
        -:  538:
     3372:  539:  _dbus_return_val_if_fail (connection != NULL, FALSE);
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
call    3 never executed
call    4 never executed
     3372:  540:  _dbus_return_val_if_fail (unique_name != NULL, FALSE);
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
call    3 never executed
call    4 never executed
        -:  541:  
     3372:  542:  bd = ensure_bus_data (connection);
call    0 returned 100%
     3372:  543:  if (bd == NULL)
branch  0 taken 1% (fallthrough)
branch  1 taken 99%
       17:  544:    return FALSE;
        -:  545:
     3355:  546:  _dbus_assert (bd->unique_name == NULL);
call    0 returned 100%
        -:  547:  
     3355:  548:  bd->unique_name = _dbus_strdup (unique_name);
call    0 returned 100%
     3355:  549:  return bd->unique_name != NULL;
        -:  550:}
        -:  551:
        -:  552:/**
        -:  553: * Gets the unique name of the connection.  Only possible after the
        -:  554: * connection has been registered with the message bus.
        -:  555: *
        -:  556: * The name remains valid for the duration of the connection and
        -:  557: * should not be freed by the caller.
        -:  558: * 
        -:  559: * @param connection the connection
        -:  560: * @returns the unique name or NULL on error
        -:  561: */
        -:  562:const char*
        -:  563:dbus_bus_get_unique_name (DBusConnection *connection)
function dbus_bus_get_unique_name called 8741 returned 100% blocks executed 70%
     8741:  564:{
        -:  565:  BusData *bd;
        -:  566:
     8741:  567:  _dbus_return_val_if_fail (connection != NULL, NULL);
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
call    3 never executed
call    4 never executed
        -:  568:  
     8741:  569:  bd = ensure_bus_data (connection);
call    0 returned 100%
     8741:  570:  if (bd == NULL)
branch  0 taken 1% (fallthrough)
branch  1 taken 99%
        4:  571:    return NULL;
        -:  572:  
     8737:  573:  return bd->unique_name;
        -:  574:}
        -:  575:
        -:  576:/**
        -:  577: * Asks the bus to return the uid of the named
        -:  578: * connection.
        -:  579: *
        -:  580: * @param connection the connection
        -:  581: * @param name a name owned by the connection
        -:  582: * @param error location to store the error
        -:  583: * @returns a result code, -1 if error is set
        -:  584: */ 
        -:  585:unsigned long
        -:  586:dbus_bus_get_unix_user (DBusConnection *connection,
        -:  587:                        const char     *name,
        -:  588:                        DBusError      *error)
function dbus_bus_get_unix_user called 0 returned 0% blocks executed 0%
    #####:  589:{
        -:  590:  DBusMessage *message, *reply;
        -:  591:  dbus_uint32_t uid;
        -:  592:
    #####:  593:  _dbus_return_val_if_fail (connection != NULL, DBUS_UID_UNSET);
call    0 never executed
branch  1 never executed
branch  2 never executed
call    3 never executed
call    4 never executed
    #####:  594:  _dbus_return_val_if_fail (name != NULL, DBUS_UID_UNSET);
call    0 never executed
branch  1 never executed
branch  2 never executed
call    3 never executed
call    4 never executed
    #####:  595:  _dbus_return_val_if_fail (_dbus_check_is_valid_bus_name (name), DBUS_UID_UNSET);
call    0 never executed
call    1 never executed
branch  2 never executed
branch  3 never executed
call    4 never executed
call    5 never executed
    #####:  596:  _dbus_return_val_if_error_is_set (error, DBUS_UID_UNSET);
call    0 never executed
branch  1 never executed
branch  2 never executed
call    3 never executed
branch  4 never executed
branch  5 never executed
call    6 never executed
call    7 never executed
        -:  597:  
    #####:  598:  message = dbus_message_new_method_call (DBUS_SERVICE_DBUS,
call    0 never executed
        -:  599:                                          DBUS_PATH_DBUS,
        -:  600:                                          DBUS_INTERFACE_DBUS,
        -:  601:                                          "GetConnectionUnixUser");
        -:  602:
    #####:  603:  if (message == NULL)
branch  0 never executed
branch  1 never executed
        -:  604:    {
    #####:  605:      _DBUS_SET_OOM (error);
call    0 never executed
    #####:  606:      return DBUS_UID_UNSET;
        -:  607:    }
        -:  608: 
    #####:  609:  if (!dbus_message_append_args (message,
call    0 never executed
branch  1 never executed
branch  2 never executed
        -:  610:				 DBUS_TYPE_STRING, &name,
        -:  611:				 DBUS_TYPE_INVALID))
        -:  612:    {
    #####:  613:      dbus_message_unref (message);
call    0 never executed
    #####:  614:      _DBUS_SET_OOM (error);
call    0 never executed
    #####:  615:      return DBUS_UID_UNSET;
        -:  616:    }
        -:  617:  
    #####:  618:  reply = dbus_connection_send_with_reply_and_block (connection, message, -1,
call    0 never executed
        -:  619:                                                     error);
        -:  620:  
    #####:  621:  dbus_message_unref (message);
call    0 never executed
        -:  622:  
    #####:  623:  if (reply == NULL)
branch  0 never executed
branch  1 never executed
        -:  624:    {
    #####:  625:      _DBUS_ASSERT_ERROR_IS_SET (error);
branch  0 never executed
branch  1 never executed
call    2 never executed
branch  3 never executed
branch  4 never executed
call    5 never executed
    #####:  626:      return DBUS_UID_UNSET;
        -:  627:    }  
        -:  628:
    #####:  629:  if (dbus_set_error_from_message (error, reply))
call    0 never executed
branch  1 never executed
branch  2 never executed
        -:  630:    {
    #####:  631:      _DBUS_ASSERT_ERROR_IS_SET (error);
branch  0 never executed
branch  1 never executed
call    2 never executed
branch  3 never executed
branch  4 never executed
call    5 never executed
    #####:  632:      dbus_message_unref (reply);
call    0 never executed
    #####:  633:      return DBUS_UID_UNSET;
        -:  634:    }
        -:  635:  
    #####:  636:  if (!dbus_message_get_args (reply, error,
call    0 never executed
branch  1 never executed
branch  2 never executed
        -:  637:                              DBUS_TYPE_UINT32, &uid,
        -:  638:                              DBUS_TYPE_INVALID))
        -:  639:    {
    #####:  640:      _DBUS_ASSERT_ERROR_IS_SET (error);
branch  0 never executed
branch  1 never executed
call    2 never executed
branch  3 never executed
branch  4 never executed
call    5 never executed
    #####:  641:      dbus_message_unref (reply);
call    0 never executed
    #####:  642:      return DBUS_UID_UNSET;
        -:  643:    }
        -:  644:
    #####:  645:  dbus_message_unref (reply);
call    0 never executed
        -:  646:  
    #####:  647:  return (unsigned long) uid;
        -:  648:}
        -:  649:
        -:  650:
        -:  651:/**
        -:  652: * Asks the bus to assign the given name to this connection by invoking
        -:  653: * the RequestName method on the bus. This method is fully documented
        -:  654: * in the D-BUS specification. For quick reference, the flags and
        -:  655: * result codes are discussed here, but the specification is the
        -:  656: * canonical version of this information.
        -:  657: *
        -:  658: * The #DBUS_NAME_FLAG_ALLOW_REPLACEMENT flag indicates that the caller
        -:  659: * will allow other services to take over the name from the current owner.
        -:  660: *
        -:  661: * The #DBUS_NAME_FLAG_REPLACE_EXISTING flag indicates that the caller
        -:  662: * would like to take over the name from the current owner.
        -:  663: * If the current name owner did not use #DBUS_NAME_FLAG_ALLOW_REPLACEMENT
        -:  664: * then this flag indicates that the caller would like to be placed
        -:  665: * in the queue to own the name when the current owner lets go.
        -:  666: *
        -:  667: * If no flags are given, an application will receive the requested
        -:  668: * name only if the name is currently unowned; it will NOT give
        -:  669: * up the name if another application asks to take it over using
        -:  670: * #DBUS_NAME_FLAG_REPLACE_EXISTING.
        -:  671: *
        -:  672: * This function returns a result code. The possible result codes
        -:  673: * are as follows.
        -:  674: * 
        -:  675: * #DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER means that the name had no
        -:  676: * existing owner, and the caller is now the primary owner; or that
        -:  677: * the name had an owner, and the caller specified
        -:  678: * #DBUS_NAME_FLAG_REPLACE_EXISTING, and the current owner
        -:  679: * specified #DBUS_NAME_FLAG_ALLOW_REPLACEMENT.
        -:  680: *
        -:  681: * #DBUS_REQUEST_NAME_REPLY_IN_QUEUE happens only if the caller does NOT
        -:  682: * specify #DBUS_NAME_FLAG_DO_NOT_QUEUE and either the current owner
        -:  683: * did NOT specify #DBUS_NAME_FLAG_ALLOW_REPLACEMENT or the caller did NOT
        -:  684: * specify #DBUS_NAME_FLAG_REPLACE_EXISTING. In this case the caller ends up 
        -:  685: * in a queue to own the name after the current owner gives it up.
        -:  686: *
        -:  687: * #DBUS_REQUEST_NAME_REPLY_EXISTS happens if the name has an owner
        -:  688: * already and the caller specifies #DBUS_NAME_FLAG_DO_NOT_QUEUE
        -:  689: * and either the current owner has NOT specified 
        -:  690: * #DBUS_NAME_FLAG_ALLOW_REPLACEMENT or the caller did NOT specify 
        -:  691: * #DBUS_NAME_FLAG_REPLACE_EXISTING.
        -:  692: *
        -:  693: * #DBUS_REQUEST_NAME_REPLY_ALREADY_OWNER happens if an application
        -:  694: * requests a name it already owns.
        -:  695: *
        -:  696: * When a service represents an application, say "text editor," then
        -:  697: * it should specify #DBUS_NAME_FLAG_ALLOW_REPLACEMENT if it wants
        -:  698: * the last editor started to be the user's editor vs. the first one
        -:  699: * started.  Then any editor that can be the user's editor should
        -:  700: * specify #DBUS_NAME_FLAG_REPLACE_EXISTING to either take over
        -:  701: * (last-started-wins) or be queued up (first-started-wins) according
        -:  702: * to whether #DBUS_NAME_FLAG_ALLOW_REPLACEMENT was given.
        -:  703: * 
        -:  704: * @todo this all seems sort of broken. Shouldn't the flags be a property
        -:  705: * of the name, not the app requesting the name? What are the use-cases
        -:  706: * other than the "text editor" thing and how are we supporting them?
        -:  707: * 
        -:  708: * @param connection the connection
        -:  709: * @param name the name to request
        -:  710: * @param flags flags
        -:  711: * @param error location to store the error
        -:  712: * @returns a result code, -1 if error is set
        -:  713: */ 
        -:  714:int
        -:  715:dbus_bus_request_name (DBusConnection *connection,
        -:  716:                       const char     *name,
        -:  717:                       unsigned int    flags,
        -:  718:                       DBusError      *error)
function dbus_bus_request_name called 416 returned 100% blocks executed 38%
      416:  719:{
        -:  720:  DBusMessage *message, *reply;
        -:  721:  dbus_uint32_t result;
        -:  722:
      416:  723:  _dbus_return_val_if_fail (connection != NULL, 0);
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
call    3 never executed
call    4 never executed
      416:  724:  _dbus_return_val_if_fail (name != NULL, 0);
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
call    3 never executed
call    4 never executed
      416:  725:  _dbus_return_val_if_fail (_dbus_check_is_valid_bus_name (name), 0);
call    0 returned 100%
call    1 returned 100%
branch  2 taken 0% (fallthrough)
branch  3 taken 100%
call    4 never executed
call    5 never executed
      416:  726:  _dbus_return_val_if_error_is_set (error, 0);
call    0 returned 100%
branch  1 taken 100% (fallthrough)
branch  2 taken 0%
call    3 returned 100%
branch  4 taken 0% (fallthrough)
branch  5 taken 100%
call    6 never executed
call    7 never executed
        -:  727:  
      416:  728:  message = dbus_message_new_method_call (DBUS_SERVICE_DBUS,
call    0 returned 100%
        -:  729:                                          DBUS_PATH_DBUS,
        -:  730:                                          DBUS_INTERFACE_DBUS,
        -:  731:                                          "RequestName");
        -:  732:
      416:  733:  if (message == NULL)
branch  0 taken 0% (fallthrough)
branch  1 taken 100%
        -:  734:    {
    #####:  735:      _DBUS_SET_OOM (error);
call    0 never executed
    #####:  736:      return -1;
        -:  737:    }
        -:  738: 
      416:  739:  if (!dbus_message_append_args (message,
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
        -:  740:				 DBUS_TYPE_STRING, &name,
        -:  741:				 DBUS_TYPE_UINT32, &flags,
        -:  742:				 DBUS_TYPE_INVALID))
        -:  743:    {
    #####:  744:      dbus_message_unref (message);
call    0 never executed
    #####:  745:      _DBUS_SET_OOM (error);
call    0 never executed
    #####:  746:      return -1;
        -:  747:    }
        -:  748:  
      416:  749:  reply = dbus_connection_send_with_reply_and_block (connection, message, -1,
call    0 returned 100%
        -:  750:                                                     error);
        -:  751:  
      416:  752:  dbus_message_unref (message);
call    0 returned 100%
        -:  753:  
      416:  754:  if (reply == NULL)
branch  0 taken 100% (fallthrough)
branch  1 taken 0%
        -:  755:    {
      416:  756:      _DBUS_ASSERT_ERROR_IS_SET (error);
branch  0 taken 100% (fallthrough)
branch  1 taken 0%
call    2 returned 100%
branch  3 taken 100% (fallthrough)
branch  4 taken 0%
call    5 returned 100%
      416:  757:      return -1;
        -:  758:    }  
        -:  759:
    #####:  760:  if (dbus_set_error_from_message (error, reply))
call    0 never executed
branch  1 never executed
branch  2 never executed
        -:  761:    {
    #####:  762:      _DBUS_ASSERT_ERROR_IS_SET (error);
branch  0 never executed
branch  1 never executed
call    2 never executed
branch  3 never executed
branch  4 never executed
call    5 never executed
    #####:  763:      dbus_message_unref (reply);
call    0 never executed
    #####:  764:      return -1;
        -:  765:    }
        -:  766:  
    #####:  767:  if (!dbus_message_get_args (reply, error,
call    0 never executed
branch  1 never executed
branch  2 never executed
        -:  768:                              DBUS_TYPE_UINT32, &result,
        -:  769:                              DBUS_TYPE_INVALID))
        -:  770:    {
    #####:  771:      _DBUS_ASSERT_ERROR_IS_SET (error);
branch  0 never executed
branch  1 never executed
call    2 never executed
branch  3 never executed
branch  4 never executed
call    5 never executed
    #####:  772:      dbus_message_unref (reply);
call    0 never executed
    #####:  773:      return -1;
        -:  774:    }
        -:  775:
    #####:  776:  dbus_message_unref (reply);
call    0 never executed
        -:  777:  
    #####:  778:  return result;
        -:  779:}
        -:  780:
        -:  781:
        -:  782:/**
        -:  783: * Asks the bus to unassign the given name to this connection by invoking
        -:  784: * the ReleaseName method on the bus. This method is fully documented
        -:  785: * in the D-BUS specification.
        -:  786: *
        -:  787: * @param connection the connection
        -:  788: * @param name the name to remove 
        -:  789: * @param error location to store the error
        -:  790: * @returns a result code, -1 if error is set
        -:  791: */ 
        -:  792:int
        -:  793:dbus_bus_release_name (DBusConnection *connection,
        -:  794:                       const char     *name,
        -:  795:                       DBusError      *error)
function dbus_bus_release_name called 0 returned 0% blocks executed 0%
    #####:  796:{
        -:  797:  DBusMessage *message, *reply;
        -:  798:  dbus_uint32_t result;
        -:  799:
    #####:  800:  _dbus_return_val_if_fail (connection != NULL, 0);
call    0 never executed
branch  1 never executed
branch  2 never executed
call    3 never executed
call    4 never executed
    #####:  801:  _dbus_return_val_if_fail (name != NULL, 0);
call    0 never executed
branch  1 never executed
branch  2 never executed
call    3 never executed
call    4 never executed
    #####:  802:  _dbus_return_val_if_fail (_dbus_check_is_valid_bus_name (name), 0);
call    0 never executed
call    1 never executed
branch  2 never executed
branch  3 never executed
call    4 never executed
call    5 never executed
    #####:  803:  _dbus_return_val_if_error_is_set (error, 0);
call    0 never executed
branch  1 never executed
branch  2 never executed
call    3 never executed
branch  4 never executed
branch  5 never executed
call    6 never executed
call    7 never executed
        -:  804:
    #####:  805:  message = dbus_message_new_method_call (DBUS_SERVICE_DBUS,
call    0 never executed
        -:  806:                                          DBUS_PATH_DBUS,
        -:  807:                                          DBUS_INTERFACE_DBUS,
        -:  808:                                          "ReleaseName");
        -:  809:
    #####:  810:  if (message == NULL)
branch  0 never executed
branch  1 never executed
        -:  811:    {
    #####:  812:      _DBUS_SET_OOM (error);
call    0 never executed
    #####:  813:      return -1;
        -:  814:    }
        -:  815:
    #####:  816:  if (!dbus_message_append_args (message,
call    0 never executed
branch  1 never executed
branch  2 never executed
        -:  817:                                 DBUS_TYPE_STRING, &name,
        -:  818:                                 DBUS_TYPE_INVALID))
        -:  819:    {
    #####:  820:      dbus_message_unref (message);
call    0 never executed
    #####:  821:      _DBUS_SET_OOM (error);
call    0 never executed
    #####:  822:      return -1;
        -:  823:    }
        -:  824:
    #####:  825:  reply = dbus_connection_send_with_reply_and_block (connection, message, -1,
call    0 never executed
        -:  826:                                                     error);
        -:  827:
    #####:  828:  dbus_message_unref (message);
call    0 never executed
        -:  829:
    #####:  830:  if (reply == NULL)
branch  0 never executed
branch  1 never executed
        -:  831:    {
    #####:  832:      _DBUS_ASSERT_ERROR_IS_SET (error);
branch  0 never executed
branch  1 never executed
call    2 never executed
branch  3 never executed
branch  4 never executed
call    5 never executed
    #####:  833:      return -1;
        -:  834:    }
        -:  835:
    #####:  836:  if (dbus_set_error_from_message (error, reply))
call    0 never executed
branch  1 never executed
branch  2 never executed
        -:  837:    {
    #####:  838:      _DBUS_ASSERT_ERROR_IS_SET (error);
branch  0 never executed
branch  1 never executed
call    2 never executed
branch  3 never executed
branch  4 never executed
call    5 never executed
    #####:  839:      dbus_message_unref (reply);
call    0 never executed
    #####:  840:      return -1;
        -:  841:    }
        -:  842:
    #####:  843:  if (!dbus_message_get_args (reply, error,
call    0 never executed
branch  1 never executed
branch  2 never executed
        -:  844:                              DBUS_TYPE_UINT32, &result,
        -:  845:                              DBUS_TYPE_INVALID))
        -:  846:    {
    #####:  847:      _DBUS_ASSERT_ERROR_IS_SET (error);
branch  0 never executed
branch  1 never executed
call    2 never executed
branch  3 never executed
branch  4 never executed
call    5 never executed
    #####:  848:      dbus_message_unref (reply);
call    0 never executed
    #####:  849:      return -1;
        -:  850:    }
        -:  851:
    #####:  852:  dbus_message_unref (reply);
call    0 never executed
        -:  853:
    #####:  854:  return result;
        -:  855:}
        -:  856:
        -:  857:/**
        -:  858: * Checks whether a certain name has an owner.
        -:  859: *
        -:  860: * @param connection the connection
        -:  861: * @param name the name
        -:  862: * @param error location to store any errors
        -:  863: * @returns #TRUE if the name exists, #FALSE if not or on error
        -:  864: */
        -:  865:dbus_bool_t
        -:  866:dbus_bus_name_has_owner (DBusConnection *connection,
        -:  867:			 const char     *name,
        -:  868:                         DBusError      *error)
function dbus_bus_name_has_owner called 0 returned 0% blocks executed 0%
    #####:  869:{
        -:  870:  DBusMessage *message, *reply;
        -:  871:  dbus_bool_t exists;
        -:  872:
    #####:  873:  _dbus_return_val_if_fail (connection != NULL, FALSE);
call    0 never executed
branch  1 never executed
branch  2 never executed
call    3 never executed
call    4 never executed
    #####:  874:  _dbus_return_val_if_fail (name != NULL, FALSE);
call    0 never executed
branch  1 never executed
branch  2 never executed
call    3 never executed
call    4 never executed
    #####:  875:  _dbus_return_val_if_fail (_dbus_check_is_valid_bus_name (name), FALSE);
call    0 never executed
call    1 never executed
branch  2 never executed
branch  3 never executed
call    4 never executed
call    5 never executed
    #####:  876:  _dbus_return_val_if_error_is_set (error, FALSE);
call    0 never executed
branch  1 never executed
branch  2 never executed
call    3 never executed
branch  4 never executed
branch  5 never executed
call    6 never executed
call    7 never executed
        -:  877:  
    #####:  878:  message = dbus_message_new_method_call (DBUS_SERVICE_DBUS,
call    0 never executed
        -:  879:                                          DBUS_PATH_DBUS,
        -:  880:                                          DBUS_INTERFACE_DBUS,
        -:  881:                                          "NameHasOwner");
    #####:  882:  if (message == NULL)
branch  0 never executed
branch  1 never executed
        -:  883:    {
    #####:  884:      _DBUS_SET_OOM (error);
call    0 never executed
    #####:  885:      return FALSE;
        -:  886:    }
        -:  887:  
    #####:  888:  if (!dbus_message_append_args (message,
call    0 never executed
branch  1 never executed
branch  2 never executed
        -:  889:				 DBUS_TYPE_STRING, &name,
        -:  890:				 DBUS_TYPE_INVALID))
        -:  891:    {
    #####:  892:      dbus_message_unref (message);
call    0 never executed
    #####:  893:      _DBUS_SET_OOM (error);
call    0 never executed
    #####:  894:      return FALSE;
        -:  895:    }
        -:  896:  
    #####:  897:  reply = dbus_connection_send_with_reply_and_block (connection, message, -1, error);
call    0 never executed
    #####:  898:  dbus_message_unref (message);
call    0 never executed
        -:  899:
    #####:  900:  if (reply == NULL)
branch  0 never executed
branch  1 never executed
        -:  901:    {
    #####:  902:      _DBUS_ASSERT_ERROR_IS_SET (error);
branch  0 never executed
branch  1 never executed
call    2 never executed
branch  3 never executed
branch  4 never executed
call    5 never executed
    #####:  903:      return FALSE;
        -:  904:    }
        -:  905:
    #####:  906:  if (!dbus_message_get_args (reply, error,
call    0 never executed
branch  1 never executed
branch  2 never executed
        -:  907:                              DBUS_TYPE_BOOLEAN, &exists,
        -:  908:                              DBUS_TYPE_INVALID))
        -:  909:    {
    #####:  910:      _DBUS_ASSERT_ERROR_IS_SET (error);
branch  0 never executed
branch  1 never executed
call    2 never executed
branch  3 never executed
branch  4 never executed
call    5 never executed
    #####:  911:      dbus_message_unref (reply);
call    0 never executed
    #####:  912:      return FALSE;
        -:  913:    }
        -:  914:  
    #####:  915:  dbus_message_unref (reply);
call    0 never executed
    #####:  916:  return exists;
        -:  917:}
        -:  918:
        -:  919:/**
        -:  920: * Starts a service that will request ownership of the given name.
        -:  921: * The returned result will be one of be one of
        -:  922: * #DBUS_START_REPLY_SUCCESS or #DBUS_START_REPLY_ALREADY_RUNNING if
        -:  923: * successful.  Pass #NULL if you don't care about the result.
        -:  924: * 
        -:  925: * The flags parameter is for future expansion, currently you should
        -:  926: * specify 0.
        -:  927: *
        -:  928: * @param connection the connection
        -:  929: * @param name the name we want the new service to request
        -:  930: * @param flags the flags (should always be 0 for now)
        -:  931: * @param result a place to store the result or #NULL
        -:  932: * @param error location to store any errors
        -:  933: * @returns #TRUE if the activation succeeded, #FALSE if not
        -:  934: */
        -:  935:dbus_bool_t
        -:  936:dbus_bus_start_service_by_name (DBusConnection *connection,
        -:  937:                                const char     *name,
        -:  938:                                dbus_uint32_t   flags,
        -:  939:                                dbus_uint32_t  *result,
        -:  940:                                DBusError      *error)
function dbus_bus_start_service_by_name called 0 returned 0% blocks executed 0%
    #####:  941:{
        -:  942:  DBusMessage *msg;
        -:  943:  DBusMessage *reply;
        -:  944:
    #####:  945:  _dbus_return_val_if_fail (connection != NULL, FALSE);
call    0 never executed
branch  1 never executed
branch  2 never executed
call    3 never executed
call    4 never executed
    #####:  946:  _dbus_return_val_if_fail (_dbus_check_is_valid_bus_name (name), FALSE);
call    0 never executed
call    1 never executed
branch  2 never executed
branch  3 never executed
call    4 never executed
call    5 never executed
        -:  947:  
    #####:  948:  msg = dbus_message_new_method_call (DBUS_SERVICE_DBUS,
call    0 never executed
        -:  949:                                      DBUS_PATH_DBUS,
        -:  950:                                      DBUS_INTERFACE_DBUS,
        -:  951:                                      "StartServiceByName");
        -:  952:
    #####:  953:  if (!dbus_message_append_args (msg, DBUS_TYPE_STRING, &name,
call    0 never executed
branch  1 never executed
branch  2 never executed
        -:  954:			  	 DBUS_TYPE_UINT32, &flags, DBUS_TYPE_INVALID))
        -:  955:    {
    #####:  956:      dbus_message_unref (msg);
call    0 never executed
    #####:  957:      _DBUS_SET_OOM (error);
call    0 never executed
    #####:  958:      return FALSE;
        -:  959:    }
        -:  960:
    #####:  961:  reply = dbus_connection_send_with_reply_and_block (connection, msg,
call    0 never executed
        -:  962:                                                     -1, error);
    #####:  963:  dbus_message_unref (msg);
call    0 never executed
        -:  964:
    #####:  965:  if (reply == NULL)
branch  0 never executed
branch  1 never executed
        -:  966:    {
    #####:  967:      _DBUS_ASSERT_ERROR_IS_SET (error);
branch  0 never executed
branch  1 never executed
call    2 never executed
branch  3 never executed
branch  4 never executed
call    5 never executed
    #####:  968:      return FALSE;
        -:  969:    }
        -:  970:
    #####:  971:  if (dbus_set_error_from_message (error, reply))
call    0 never executed
branch  1 never executed
branch  2 never executed
        -:  972:    {
    #####:  973:      _DBUS_ASSERT_ERROR_IS_SET (error);
branch  0 never executed
branch  1 never executed
call    2 never executed
branch  3 never executed
branch  4 never executed
call    5 never executed
    #####:  974:      dbus_message_unref (reply);
call    0 never executed
    #####:  975:      return FALSE;
        -:  976:    }
        -:  977:
    #####:  978:  if (result != NULL &&
branch  0 never executed
branch  1 never executed
call    2 never executed
branch  3 never executed
branch  4 never executed
        -:  979:      !dbus_message_get_args (reply, error, DBUS_TYPE_UINT32,
        -:  980:	      		      result, DBUS_TYPE_INVALID))
        -:  981:    {
    #####:  982:      _DBUS_ASSERT_ERROR_IS_SET (error);
branch  0 never executed
branch  1 never executed
call    2 never executed
branch  3 never executed
branch  4 never executed
call    5 never executed
    #####:  983:      dbus_message_unref (reply);
call    0 never executed
    #####:  984:      return FALSE;
        -:  985:    }
        -:  986:  
    #####:  987:  dbus_message_unref (reply);
call    0 never executed
    #####:  988:  return TRUE;
        -:  989:}
        -:  990:
        -:  991:static void
        -:  992:send_no_return_values (DBusConnection *connection,
        -:  993:                       DBusMessage    *msg,
        -:  994:                       DBusError      *error)
function send_no_return_values called 0 returned 0% blocks executed 0%
    #####:  995:{
    #####:  996:  if (error)
branch  0 never executed
branch  1 never executed
        -:  997:    {
        -:  998:      /* Block to check success codepath */
        -:  999:      DBusMessage *reply;
        -: 1000:      
    #####: 1001:      reply = dbus_connection_send_with_reply_and_block (connection, msg,
call    0 never executed
        -: 1002:                                                         -1, error);
        -: 1003:      
    #####: 1004:      if (reply == NULL)
branch  0 never executed
branch  1 never executed
    #####: 1005:        _DBUS_ASSERT_ERROR_IS_SET (error);
branch  0 never executed
branch  1 never executed
call    2 never executed
branch  3 never executed
branch  4 never executed
call    5 never executed
        -: 1006:      else
    #####: 1007:        dbus_message_unref (reply);
call    0 never executed
        -: 1008:    }
        -: 1009:  else
        -: 1010:    {
        -: 1011:      /* Silently-fail nonblocking codepath */
    #####: 1012:      dbus_message_set_no_reply (msg, TRUE);
call    0 never executed
    #####: 1013:      dbus_connection_send (connection, msg, NULL);
call    0 never executed
        -: 1014:    }
    #####: 1015:}
        -: 1016:
        -: 1017:/**
        -: 1018: * Adds a match rule to match messages going through the message bus.
        -: 1019: * The "rule" argument is the string form of a match rule.
        -: 1020: *
        -: 1021: * If you pass #NULL for the error, this function will not
        -: 1022: * block; the match thus won't be added until you flush the
        -: 1023: * connection, and if there's an error adding the match
        -: 1024: * (only possible error is lack of resources in the bus),
        -: 1025: * you won't find out about it.
        -: 1026: *
        -: 1027: * If you pass non-#NULL for the error this function will
        -: 1028: * block until it gets a reply.
        -: 1029: *
        -: 1030: * Normal API conventions would have the function return
        -: 1031: * a boolean value indicating whether the error was set,
        -: 1032: * but that would require blocking always to determine
        -: 1033: * the return value.
        -: 1034: *
        -: 1035: * The AddMatch method is fully documented in the D-BUS 
        -: 1036: * specification. For quick reference, the format of the 
        -: 1037: * match rules is discussed here, but the specification 
        -: 1038: * is the canonical version of this information.
        -: 1039: *
        -: 1040: * Rules are specified as a string of comma separated 
        -: 1041: * key/value pairs. An example is 
        -: 1042: * "type='signal',sender='org.freedesktop.DBus',
        -: 1043: * interface='org.freedesktop.DBus',member='Foo',
        -: 1044: * path='/bar/foo',destination=':452345.34'"
        -: 1045: *
        -: 1046: * Possible keys you can match on are type, sender, 
        -: 1047: * interface, member, path, destination and the special
        -: 1048: * arg keys.  Excluding a key from the rule indicates 
        -: 1049: * a wildcard match.  For instance excluding the
        -: 1050: * the member from a match rule but adding a sender would
        -: 1051: * let all messages from that sender through.  
        -: 1052: *
        -: 1053: * Matches are inclusive not exclusive so as long as one 
        -: 1054: * rule matches the message will get through.  It is important
        -: 1055: * to note this because every time a message is received the 
        -: 1056: * application will be paged into memory to process it.  This
        -: 1057: * can cause performance problems such as draining batteries
        -: 1058: * on embedded platforms.
        -: 1059: *
        -: 1060: * The special arg keys are used for further restricting the 
        -: 1061: * match based on the parameters sent by the signal or method.
        -: 1062: * For instance arg1='foo' will check the first argument, 
        -: 1063: * arg2='bar' the second and so on.  For performance reasons
        -: 1064: * there is a set limit on the highest number parameter that
        -: 1065: * can be checked which is set in dbus-protocol.h
        -: 1066: *
        -: 1067: * @param connection connection to the message bus
        -: 1068: * @param rule textual form of match rule
        -: 1069: * @param error location to store any errors
        -: 1070: */
        -: 1071:void
        -: 1072:dbus_bus_add_match (DBusConnection *connection,
        -: 1073:                    const char     *rule,
        -: 1074:                    DBusError      *error)
function dbus_bus_add_match called 0 returned 0% blocks executed 0%
    #####: 1075:{
        -: 1076:  DBusMessage *msg;
        -: 1077:
    #####: 1078:  _dbus_return_if_fail (rule != NULL);
call    0 never executed
branch  1 never executed
branch  2 never executed
call    3 never executed
call    4 never executed
        -: 1079:
    #####: 1080:  msg = dbus_message_new_method_call (DBUS_SERVICE_DBUS,
call    0 never executed
        -: 1081:                                      DBUS_PATH_DBUS,
        -: 1082:                                      DBUS_INTERFACE_DBUS,
        -: 1083:                                      "AddMatch");
        -: 1084:
    #####: 1085:  if (msg == NULL)
branch  0 never executed
branch  1 never executed
        -: 1086:    {
    #####: 1087:      _DBUS_SET_OOM (error);
call    0 never executed
    #####: 1088:      return;
        -: 1089:    }
        -: 1090:
    #####: 1091:  if (!dbus_message_append_args (msg, DBUS_TYPE_STRING, &rule,
call    0 never executed
branch  1 never executed
branch  2 never executed
        -: 1092:                                 DBUS_TYPE_INVALID))
        -: 1093:    {
    #####: 1094:      dbus_message_unref (msg);
call    0 never executed
    #####: 1095:      _DBUS_SET_OOM (error);
call    0 never executed
    #####: 1096:      return;
        -: 1097:    }
        -: 1098:
    #####: 1099:  send_no_return_values (connection, msg, error);
call    0 never executed
        -: 1100:
    #####: 1101:  dbus_message_unref (msg);
call    0 never executed
        -: 1102:}
        -: 1103:
        -: 1104:/**
        -: 1105: * Removes a previously-added match rule "by value" (the most
        -: 1106: * recently-added identical rule gets removed).  The "rule" argument
        -: 1107: * is the string form of a match rule.
        -: 1108: *
        -: 1109: * If you pass #NULL for the error, this function will not
        -: 1110: * block; otherwise it will. See detailed explanation in
        -: 1111: * docs for dbus_bus_add_match().
        -: 1112: * 
        -: 1113: * @param connection connection to the message bus
        -: 1114: * @param rule textual form of match rule
        -: 1115: * @param error location to store any errors
        -: 1116: */
        -: 1117:void
        -: 1118:dbus_bus_remove_match (DBusConnection *connection,
        -: 1119:                       const char     *rule,
        -: 1120:                       DBusError      *error)
function dbus_bus_remove_match called 0 returned 0% blocks executed 0%
    #####: 1121:{
        -: 1122:  DBusMessage *msg;
        -: 1123:
    #####: 1124:  _dbus_return_if_fail (rule != NULL);
call    0 never executed
branch  1 never executed
branch  2 never executed
call    3 never executed
call    4 never executed
        -: 1125:  
    #####: 1126:  msg = dbus_message_new_method_call (DBUS_SERVICE_DBUS,
call    0 never executed
        -: 1127:                                      DBUS_PATH_DBUS,
        -: 1128:                                      DBUS_INTERFACE_DBUS,
        -: 1129:                                      "RemoveMatch");
        -: 1130:
    #####: 1131:  if (!dbus_message_append_args (msg, DBUS_TYPE_STRING, &rule,
call    0 never executed
branch  1 never executed
branch  2 never executed
        -: 1132:                                 DBUS_TYPE_INVALID))
        -: 1133:    {
    #####: 1134:      dbus_message_unref (msg);
call    0 never executed
    #####: 1135:      _DBUS_SET_OOM (error);
call    0 never executed
    #####: 1136:      return;
        -: 1137:    }
        -: 1138:
    #####: 1139:  send_no_return_values (connection, msg, error);
call    0 never executed
        -: 1140:
    #####: 1141:  dbus_message_unref (msg);
call    0 never executed
        -: 1142:}
        -: 1143:
        -: 1144:#ifdef DBUS_BUILD_TESTS
        -: 1145:const char *
        -: 1146:dbus_bus_connection_get_unique_name (DBusConnection *connection)
function dbus_bus_connection_get_unique_name called 0 returned 0% blocks executed 0%
    #####: 1147:{
        -: 1148:  BusData *bd;
    #####: 1149:  bd = dbus_connection_get_data (connection, bus_data_slot);
call    0 never executed
        -: 1150:  
    #####: 1151:  return bd->unique_name;
        -: 1152:}
        -: 1153:#endif /* DBUS_BUILD_TESTS */
        -: 1154:
        -: 1155:
        -: 1156:/** @} */