Revert "Change log level to prevent abort."
[platform/upstream/at-spi2-core.git] / atspi / atspi-misc.c
index fb17f53..e719040 100644 (file)
 #include "atspi-gmain.h"
 #include <stdio.h>
 #include <string.h>
+#include <ctype.h>
 
 /* This value is not fixed, could be changed. */
-#define HASH_TABLE_SIZE_MAX 1000
+#define HASH_TABLE_SIZE_MAX 3000
 
 static void handle_get_items (DBusPendingCall *pending, void *user_data);
 
@@ -485,12 +486,16 @@ add_accessible_from_iter (DBusMessageIter *iter)
     dbus_message_iter_get_basic (&iter_struct, &index);
     if (index >= 0 && accessible->accessible_parent)
     {
-      if (index >= accessible->accessible_parent->children->len) {
+      if (index >= accessible->accessible_parent->children->len)
+      {
         /* There is no room for this object */
         g_ptr_array_set_size (accessible->accessible_parent->children, index + 1);
-      } else {
+      }
+      else
+      {
         /* This place is already taken - let's free this place with dignity */
-        g_object_unref (g_ptr_array_index (accessible->accessible_parent->children, index));
+        if (g_ptr_array_index (accessible->accessible_parent->children, index))
+          g_object_unref (g_ptr_array_index (accessible->accessible_parent->children, index));
       }
       g_ptr_array_index (accessible->accessible_parent->children, index) = g_object_ref (accessible);
     }
@@ -807,13 +812,13 @@ destroy_deferred_message_item(gpointer ptr)
   BusDataClosure *c = ptr;
   dbus_message_unref (c->message);
   dbus_connection_unref (c->bus);
-  g_free(c);
+  g_free (c);
 }
 
 static void
 cleanup_deferred_message(void)
 {
-  g_queue_free_full(deferred_messages, destroy_deferred_message_item);
+  g_queue_free_full (deferred_messages, destroy_deferred_message_item);
   deferred_messages = NULL;
 }
 
@@ -901,43 +906,6 @@ atspi_dbus_filter (DBusConnection *bus, DBusMessage *message, void *data)
   return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
 }
 
-/*
- * Returns a 'canonicalized' value for DISPLAY,
- * with the screen number stripped off if present.
- *
- * TODO: Avoid having duplicate functions for this here and in at-spi2-atk
- */
-static gchar *
-spi_display_name (void)
-{
-  char *canonical_display_name = NULL;
-  const gchar *display_env = g_getenv ("AT_SPI_DISPLAY");
-
-  if (!display_env)
-    {
-      display_env = g_getenv ("DISPLAY");
-      if (!display_env || !display_env[0])
-        return NULL;
-      else
-        {
-          gchar *display_p, *screen_p;
-          canonical_display_name = g_strdup (display_env);
-          display_p = g_utf8_strrchr (canonical_display_name, -1, ':');
-          screen_p = g_utf8_strrchr (canonical_display_name, -1, '.');
-          if (screen_p && display_p && (screen_p > display_p))
-            {
-              *screen_p = '\0';
-            }
-        }
-    }
-  else
-    {
-      canonical_display_name = g_strdup (display_env);
-    }
-
-  return canonical_display_name;
-}
-
 /**
  * atspi_init:
  *
@@ -1304,7 +1272,7 @@ _atspi_dbus_get_property (gpointer obj, const char *interface, const char *name,
   process_deferred_messages ();
   if (!reply)
   {
-    // TODO: throw exception
+    /* TODO: throw exception */
     goto done;
   }
 
@@ -1331,14 +1299,12 @@ _atspi_dbus_get_property (gpointer obj, const char *interface, const char *name,
   }
   if (!strcmp (type, "(so)"))
   {
-    g_object_unref(*(AtspiAccessible**)data);
     *((AtspiAccessible **)data) = _atspi_dbus_return_accessible_from_iter (&iter_variant);
   }
   else
   {
     if (type [0] == 's')
     {
-      g_free(*(char**)data);
       *(char**) data = NULL;
     }
 
@@ -1532,6 +1498,43 @@ _atspi_error_quark (void)
  * Gets the IOR from the XDisplay.
  */
 #ifdef HAVE_X11
+/*
+ * Returns a 'canonicalized' value for DISPLAY,
+ * with the screen number stripped off if present.
+ *
+ * TODO: Avoid having duplicate functions for this here and in at-spi2-atk
+ */
+static gchar *
+spi_display_name (void)
+{
+  char *canonical_display_name = NULL;
+  const gchar *display_env = g_getenv ("AT_SPI_DISPLAY");
+
+  if (!display_env)
+    {
+      display_env = g_getenv ("DISPLAY");
+      if (!display_env || !display_env[0])
+        return NULL;
+      else
+        {
+          gchar *display_p, *screen_p;
+          canonical_display_name = g_strdup (display_env);
+          display_p = g_utf8_strrchr (canonical_display_name, -1, ':');
+          screen_p = g_utf8_strrchr (canonical_display_name, -1, '.');
+          if (screen_p && display_p && (screen_p > display_p))
+            {
+              *screen_p = '\0';
+            }
+        }
+    }
+  else
+    {
+      canonical_display_name = g_strdup (display_env);
+    }
+
+  return canonical_display_name;
+}
+
 static char *
 get_accessibility_bus_address_x11 (void)
 {
@@ -1594,7 +1597,7 @@ get_accessibility_bus_address_dbus (void)
   dbus_error_init (&error);
   reply = dbus_connection_send_with_reply_and_block (session_bus,
                                                     message,
-                                                    -1,
+                                                    15000,
                                                     &error);
   dbus_message_unref (message);
 
@@ -1967,3 +1970,33 @@ _atspi_prepare_screen_reader_interface ()
   dbus_connection_add_filter (a11y_bus, screen_reader_filter, NULL, NULL);
   return TRUE;
 }
+
+gchar *
+_atspi_strdup_and_adjust_for_dbus (const char *s)
+{
+  gchar *d = g_strdup (s);
+  gchar *p;
+  int parts = 0;
+
+  if (!d)
+    return NULL;
+
+  for (p = d; *p; p++)
+  {
+    if (*p == '-')
+    {
+      memmove (p, p + 1, g_utf8_strlen (p, -1));
+      *p = toupper (*p);
+    }
+    else if (*p == ':')
+    {
+      parts++;
+      if (parts == 2)
+        break;
+      p [1] = toupper (p [1]);
+    }
+  }
+
+  d [0] = toupper (d [0]);
+  return d;
+}