Update README
[platform/core/uifw/at-spi2-atk.git] / atk-adaptor / adaptors / text-adaptor.c
index 9973fef..5b48a18 100644 (file)
@@ -27,7 +27,7 @@
 #include <atk/atk.h>
 #include <droute/droute.h>
 
-#include "common/spi-dbus.h"
+#include "spi-dbus.h"
 #include "object.h"
 #include "introspection.h"
 
@@ -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)
     {
@@ -314,31 +324,6 @@ impl_GetAttributeValue (DBusConnection * bus, DBusMessage * message,
   return reply;
 }
 
-static char *
-_string_from_attribute_set (AtkAttributeSet * set)
-{
-  gchar *attributes, *tmp, *tmp2;
-  GSList *cur_attr;
-  AtkAttribute *at;
-
-  attributes = g_strdup ("");
-  cur_attr = (GSList *) set;
-  while (cur_attr)
-    {
-      at = (AtkAttribute *) cur_attr->data;
-      tmp = g_strdup_printf ("%s%s:%s%s",
-                             ((GSList *) (set) == cur_attr) ? "" : " ",
-                             at->name, at->value,
-                             (cur_attr->next) ? ";" : "");
-      tmp2 = g_strconcat (attributes, tmp, NULL);
-      g_free (tmp);
-      g_free (attributes);
-      attributes = tmp2;
-      cur_attr = cur_attr->next;
-    }
-  return attributes;
-}
-
 static DBusMessage *
 impl_GetAttributes (DBusConnection * bus, DBusMessage * message,
                     void *user_data)
@@ -736,8 +721,7 @@ impl_GetAttributeRun (DBusConnection * bus, DBusMessage * message,
   gint intstart_offset = 0, intend_offset = 0;
   DBusMessage *reply;
   AtkAttributeSet *attributes = NULL;
-  AtkAttribute *attr = NULL;
-  DBusMessageIter iter, iterArray;
+  DBusMessageIter iter;
 
   g_return_val_if_fail (ATK_IS_TEXT (user_data),
                         droute_not_yet_handled_error (message));
@@ -837,5 +821,5 @@ void
 spi_initialize_text (DRoutePath * path)
 {
   droute_path_add_interface (path,
-                             SPI_DBUS_INTERFACE_TEXT, spi_org_freedesktop_atspi_Text, methods, properties);
+                             ATSPI_DBUS_INTERFACE_TEXT, spi_org_a11y_atspi_Text, methods, properties);
 };