- fixed dbus_bus_request_name
[platform/upstream/dbus.git] / dbus / dbus-object-tree.c
index 2f8dcba..172c9d9 100644 (file)
@@ -508,7 +508,7 @@ unlock:
 #endif
     {
       _dbus_connection_ref_unlocked (connection);
-      _dbus_verbose ("unlock %s\n", _DBUS_FUNCTION_NAME);
+      _dbus_verbose ("unlock\n");
       _dbus_connection_unlock (connection);
     }
 
@@ -642,7 +642,7 @@ handle_default_introspect_and_unlock (DBusObjectTree          *tree,
       if (tree->connection)
 #endif
         {
-          _dbus_verbose ("unlock %s %d\n", _DBUS_FUNCTION_NAME, __LINE__);
+          _dbus_verbose ("unlock\n");
           _dbus_connection_unlock (tree->connection);
         }
       
@@ -657,7 +657,7 @@ handle_default_introspect_and_unlock (DBusObjectTree          *tree,
       if (tree->connection)
 #endif
         {
-          _dbus_verbose ("unlock %s %d\n", _DBUS_FUNCTION_NAME, __LINE__);
+          _dbus_verbose ("unlock\n");
           _dbus_connection_unlock (tree->connection);
         }
 
@@ -717,7 +717,7 @@ handle_default_introspect_and_unlock (DBusObjectTree          *tree,
     {
       if (!already_unlocked)
         {
-          _dbus_verbose ("unlock %s %d\n", _DBUS_FUNCTION_NAME, __LINE__);
+          _dbus_verbose ("unlock\n");
           _dbus_connection_unlock (tree->connection);
         }
     }
@@ -745,7 +745,8 @@ handle_default_introspect_and_unlock (DBusObjectTree          *tree,
  */
 DBusHandlerResult
 _dbus_object_tree_dispatch_and_unlock (DBusObjectTree          *tree,
-                                       DBusMessage             *message)
+                                       DBusMessage             *message,
+                                       dbus_bool_t             *found_object)
 {
   char **path;
   dbus_bool_t exact_match;
@@ -765,7 +766,7 @@ _dbus_object_tree_dispatch_and_unlock (DBusObjectTree          *tree,
       if (tree->connection)
 #endif
         {
-          _dbus_verbose ("unlock %s\n", _DBUS_FUNCTION_NAME);
+          _dbus_verbose ("unlock\n");
           _dbus_connection_unlock (tree->connection);
         }
       
@@ -780,7 +781,7 @@ _dbus_object_tree_dispatch_and_unlock (DBusObjectTree          *tree,
       if (tree->connection)
 #endif
         {
-          _dbus_verbose ("unlock %s\n", _DBUS_FUNCTION_NAME);
+          _dbus_verbose ("unlock\n");
           _dbus_connection_unlock (tree->connection);
         }
       
@@ -791,6 +792,9 @@ _dbus_object_tree_dispatch_and_unlock (DBusObjectTree          *tree,
   /* Find the deepest path that covers the path in the message */
   subtree = find_handler (tree, (const char**) path, &exact_match);
   
+  if (found_object)
+    *found_object = !!subtree;
+
   /* Build a list of all paths that cover the path in the message */
 
   list = NULL;
@@ -846,7 +850,7 @@ _dbus_object_tree_dispatch_and_unlock (DBusObjectTree          *tree,
           if (tree->connection)
 #endif
             {
-              _dbus_verbose ("unlock %s\n", _DBUS_FUNCTION_NAME);
+              _dbus_verbose ("unlock\n");
               _dbus_connection_unlock (tree->connection);
             }
 
@@ -886,7 +890,7 @@ _dbus_object_tree_dispatch_and_unlock (DBusObjectTree          *tree,
       if (tree->connection)
 #endif
         {
-          _dbus_verbose ("unlock %s\n", _DBUS_FUNCTION_NAME);
+          _dbus_verbose ("unlock\n");
           _dbus_connection_unlock (tree->connection);
         }
     }
@@ -926,8 +930,7 @@ _dbus_object_tree_get_user_data_unlocked (DBusObjectTree *tree,
 
   if ((subtree == NULL) || !exact_match)
     {
-      _dbus_verbose ("%s: No object at specified path found\n",
-                     _DBUS_FUNCTION_NAME);
+      _dbus_verbose ("No object at specified path found\n");
       return NULL;
     }
 
@@ -951,7 +954,7 @@ allocate_subtree_object (const char *name)
 
   len = strlen (name);
 
-  subtree = dbus_malloc (MAX (front_padding + (len + 1), sizeof (DBusObjectSubtree)));
+  subtree = dbus_malloc0 (MAX (front_padding + (len + 1), sizeof (DBusObjectSubtree)));
 
   if (subtree == NULL)
     return NULL;
@@ -988,7 +991,7 @@ _dbus_object_subtree_new (const char                  *name,
     }
 
   subtree->user_data = user_data;
-  subtree->refcount.value = 1;
+  _dbus_atomic_inc (&subtree->refcount);
   subtree->subtrees = NULL;
   subtree->n_subtrees = 0;
   subtree->max_subtrees = 0;
@@ -1003,8 +1006,14 @@ _dbus_object_subtree_new (const char                  *name,
 static DBusObjectSubtree *
 _dbus_object_subtree_ref (DBusObjectSubtree *subtree)
 {
-  _dbus_assert (subtree->refcount.value > 0);
+#ifdef DBUS_DISABLE_ASSERT
   _dbus_atomic_inc (&subtree->refcount);
+#else
+  dbus_int32_t old_value;
+
+  old_value = _dbus_atomic_inc (&subtree->refcount);
+  _dbus_assert (old_value > 0);
+#endif
 
   return subtree;
 }
@@ -1012,9 +1021,12 @@ _dbus_object_subtree_ref (DBusObjectSubtree *subtree)
 static void
 _dbus_object_subtree_unref (DBusObjectSubtree *subtree)
 {
-  _dbus_assert (subtree->refcount.value > 0);
+  dbus_int32_t old_value;
+
+  old_value = _dbus_atomic_dec (&subtree->refcount);
+  _dbus_assert (old_value > 0);
 
-  if (_dbus_atomic_dec (&subtree->refcount) == 1)
+  if (old_value == 1)
     {
       _dbus_assert (subtree->unregister_function == NULL);
       _dbus_assert (subtree->message_function == NULL);
@@ -1049,7 +1061,7 @@ _dbus_object_tree_list_registered_and_unlock (DBusObjectTree *tree,
   if (tree->connection)
 #endif
     {
-      _dbus_verbose ("unlock %s\n", _DBUS_FUNCTION_NAME);
+      _dbus_verbose ("unlock\n");
       _dbus_connection_unlock (tree->connection);
     }
 
@@ -1081,6 +1093,7 @@ _dbus_decompose_path (const char*     data,
   int i, j, comp;
 
   _dbus_assert (data != NULL);
+  _dbus_assert (path != NULL);
   
 #if VERBOSE_DECOMPOSE
   _dbus_verbose ("Decomposing path \"%s\"\n",
@@ -1093,6 +1106,7 @@ _dbus_decompose_path (const char*     data,
       i = 0;
       while (i < len)
         {
+          _dbus_assert (data[i] != '\0');
           if (data[i] == '/')
             n_components += 1;
           ++i;
@@ -1381,7 +1395,7 @@ do_test_dispatch (DBusObjectTree *tree,
       ++j;
     }
 
-  result = _dbus_object_tree_dispatch_and_unlock (tree, message);
+  result = _dbus_object_tree_dispatch_and_unlock (tree, message, NULL);
   if (result == DBUS_HANDLER_RESULT_NEED_MEMORY)
     goto oom;