Build fixes.
[platform/core/uifw/at-spi2-atk.git] / atk-adaptor / adaptors / text-adaptor.c
index a15f9c7..7a810b2 100644 (file)
@@ -28,8 +28,8 @@
 #include <droute/droute.h>
 
 #include "common/spi-dbus.h"
-
-#include "accessible-marshaller.h"
+#include "object.h"
+#include "introspection.h"
 
 static dbus_bool_t
 impl_get_CharacterCount (DBusMessageIter * iter, void *user_data)
@@ -47,6 +47,20 @@ impl_get_CaretOffset (DBusMessageIter * iter, void *user_data)
   return droute_return_v_int32 (iter, atk_text_get_caret_offset (text));
 }
 
+static gchar *
+validate_allocated_string (gchar *str)
+{
+  if (!str)
+    return g_strdup ("");
+  if (!g_utf8_validate (str, -1, NULL))
+    {
+      g_warning ("atk-bridge: received bad UTF-8 string from a get_text function");
+      g_free (str);
+      return g_strdup ("");
+    }
+  return str;
+}
+
 static DBusMessage *
 impl_GetText (DBusConnection * bus, DBusMessage * message, void *user_data)
 {
@@ -66,8 +80,7 @@ impl_GetText (DBusConnection * bus, DBusMessage * message, void *user_data)
       return droute_invalid_arguments_error (message);
     }
   txt = atk_text_get_text (text, startOffset, endOffset);
-  if (!txt)
-    txt = g_strdup ("");
+  txt = validate_allocated_string (txt);
   reply = dbus_message_new_method_return (message);
   if (reply)
     {
@@ -133,8 +146,7 @@ impl_GetTextBeforeOffset (DBusConnection * bus, DBusMessage * message,
                                      &intstart_offset, &intend_offset);
   startOffset = intstart_offset;
   endOffset = intend_offset;
-  if (!txt)
-    txt = g_strdup ("");
+  txt = validate_allocated_string (txt);
   reply = dbus_message_new_method_return (message);
   if (reply)
     {
@@ -173,8 +185,7 @@ impl_GetTextAtOffset (DBusConnection * bus, DBusMessage * message,
                                  &intstart_offset, &intend_offset);
   startOffset = intstart_offset;
   endOffset = intend_offset;
-  if (!txt)
-    txt = g_strdup ("");
+  txt = validate_allocated_string (txt);
   reply = dbus_message_new_method_return (message);
   if (reply)
     {
@@ -214,8 +225,7 @@ impl_GetTextAfterOffset (DBusConnection * bus, DBusMessage * message,
                                     &intstart_offset, &intend_offset);
   startOffset = intstart_offset;
   endOffset = intend_offset;
-  if (!txt)
-    txt = g_strdup ("");
+  txt = validate_allocated_string (txt);
   reply = dbus_message_new_method_return (message);
   if (reply)
     {
@@ -370,7 +380,7 @@ impl_GetAttributes (DBusConnection * bus, DBusMessage * message,
   if (reply)
     {
       dbus_message_iter_init_append (reply, &iter);
-      spi_atk_append_attribute_set (&iter, set);
+      spi_object_append_attribute_set (&iter, set);
       dbus_message_append_args (reply, DBUS_TYPE_INT32, &startOffset,
                                 DBUS_TYPE_INT32, &endOffset,
                                 DBUS_TYPE_INVALID);
@@ -398,7 +408,7 @@ impl_GetDefaultAttributes (DBusConnection * bus, DBusMessage * message,
   if (reply)
     {
       dbus_message_iter_init_append (reply, &iter);
-      spi_atk_append_attribute_set (&iter, set);
+      spi_object_append_attribute_set (&iter, set);
     }
   atk_attribute_set_free (set);
   return reply;
@@ -735,7 +745,7 @@ impl_GetAttributeRun (DBusConnection * bus, DBusMessage * message,
   dbus_int32_t startOffset, endOffset;
   gint intstart_offset = 0, intend_offset = 0;
   DBusMessage *reply;
-  AtkAttributeSet *attributes, *default_attributes = NULL;
+  AtkAttributeSet *attributes = NULL;
   AtkAttribute *attr = NULL;
   DBusMessageIter iter, iterArray;
 
@@ -753,20 +763,18 @@ impl_GetAttributeRun (DBusConnection * bus, DBusMessage * message,
     atk_text_get_run_attributes (text, offset, &intstart_offset,
                                  &intend_offset);
 
+  if (includeDefaults)
+    {
+      attributes = g_slist_concat (attributes,
+                                   atk_text_get_default_attributes (text));
+    }
+
   reply = dbus_message_new_method_return (message);
   if (!reply)
     return NULL;
 
   dbus_message_iter_init_append (reply, &iter);
-  dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, "{ss}",
-                                    &iterArray);
-  spi_atk_append_attribute_set_inner (&iterArray, attributes);
-  if (includeDefaults)
-    {
-      default_attributes = atk_text_get_default_attributes (text);
-      spi_atk_append_attribute_set_inner (&iterArray, default_attributes);
-    }
-  dbus_message_iter_close_container (&iter, &iterArray);
+  spi_object_append_attribute_set (&iter, attributes);
 
   startOffset = intstart_offset;
   endOffset = intend_offset;
@@ -774,8 +782,6 @@ impl_GetAttributeRun (DBusConnection * bus, DBusMessage * message,
   dbus_message_iter_append_basic (&iter, DBUS_TYPE_INT32, &endOffset);
 
   atk_attribute_set_free (attributes);
-  if (default_attributes)
-    atk_attribute_set_free (default_attributes);
 
   return reply;
 }
@@ -798,7 +804,7 @@ impl_GetDefaultAttributeSet (DBusConnection * bus, DBusMessage * message,
   if (reply)
     {
       dbus_message_iter_init_append (reply, &iter);
-      spi_atk_append_attribute_set (&iter, attributes);
+      spi_object_append_attribute_set (&iter, attributes);
     }
 
   if (attributes)
@@ -841,5 +847,5 @@ void
 spi_initialize_text (DRoutePath * path)
 {
   droute_path_add_interface (path,
-                             SPI_DBUS_INTERFACE_TEXT, methods, properties);
+                             SPI_DBUS_INTERFACE_TEXT, spi_org_a11y_atspi_Text, methods, properties);
 };