revert to the migration tempoary
[framework/uifw/elementary.git] / src / lib / elm_cnp_helper.c
index dd99db6..59554ca 100644 (file)
@@ -168,14 +168,14 @@ static void entry_insert_filter(Evas_Object* entry, char* str);
 /* Optimisation: Turn this into a 256 byte table:
  *     then can lookup in one index, not N checks */
 static const Escape escapes[] = {
-       { "<br>",   '\n' },
-       { "<ps>",   '\n' },
-       { "<\t>",   '\t' },
-       { "gt;",    '>'  },
-       { "lt;",    '<'  },
-       { "amp;",   '&'  },
-       { "quot;",  '\'' },
-       { "dquot;", '"'  }
+  { "<br>",   '\n' },
+  { "<ps>",   '\n' },
+  { "<\t>",   '\t' },
+  { "gt;",    '>'  },
+  { "lt;",    '<'  },
+  { "amp;",   '&'  },
+  { "quot;",  '\'' },
+  { "dquot;", '"'  }
 };
 #define N_ESCAPES ((int)(sizeof(escapes) / sizeof(escapes[0])))
 
@@ -772,7 +772,12 @@ _get_tag_value(const char *tag_str, const char *tag_name)
              char *valueEnd = strchr(value, '\0');
 
              int i;
-             for (i = 0; i < spCnt; i++)
+             int start = 0;
+             if ((!strncmp(tag_str, "<item", 5) && !strcmp(tag_name, "href")) // EFL img tag
+               || (!strncmp(tag_str, "<img", 4) && !strcmp(tag_name, "src"))) // HTML img tag
+               start = 1;
+
+             for (i = start; i < spCnt; i++)
                {
                   if (spArray[i] && spArray[i] < valueEnd)
                     valueEnd = spArray[i];
@@ -818,8 +823,7 @@ _set_EFL_item_data(PItemTagData data, const char *tag_str)
         if (path)
           {
              char *modify = malloc(sizeof(char) * (strlen(value) + 1));
-             strncpy(modify, "file://", 7);
-             modify[7] = '\0';
+             strncpy(modify, "file://", 8);
              path += 7;
              while (path[1] && path[0] && path[1] == '/' && path[0] == '/')
                {
@@ -900,8 +904,7 @@ _set_HTML_img_data(PItemTagData data, const char *tag_str)
         if (path)
           {
              char *modify = malloc(sizeof(char) * (strlen(value) + 1));
-             strncpy(modify, "file://", 7);
-             modify[7] = '\0';
+             strncpy(modify, "file://", 8);
              path += 7;
              while (path[1] && path[0] && path[1] == '/' && path[0] == '/')
                {
@@ -1458,11 +1461,13 @@ notify_handler_targets(Cnp_Selection *sel, Ecore_X_Event_Selection_Notify *notif
           {
              if ((atoms[j].atom == atomlist[i]) && (atoms[j].notify))
                {
-/*                  if ((j == CNP_ATOM_text_uri) ||
+#if 0
+                  if ((j == CNP_ATOM_text_uri) ||
                       (j == CNP_ATOM_text_urilist))
                     {
                       if(!is_uri_type_data(sel, notify)) continue;
-                    }*/
+                    }
+#endif
                   cnp_debug("Atom %s matches\n",atoms[j].name);
                   goto done;
                }
@@ -1538,7 +1543,7 @@ entry_insert_filter(Evas_Object* entry, char* str)
              if (!startTag)
                startTag = strstr(insertStr, "</item");
              if (startTag)
-               endTag = strstr(insertStr, ">");
+               endTag = strstr(startTag, ">");
              else
                break;
              if (!endTag || startTag > endTag)
@@ -1624,7 +1629,7 @@ notify_handler_uri(Cnp_Selection *sel, Ecore_X_Event_Selection_Notify *notify)
    Ecore_X_Selection_Data *data;
    Ecore_X_Selection_Data_Files *files;
    Paste_Image *pi;
-   char *p;
+   char *p, *stripstr;
 
    data = notify->data;
    cnp_debug("data->format is %d %p %p\n", data->format, notify, data);
@@ -1638,11 +1643,11 @@ notify_handler_uri(Cnp_Selection *sel, Ecore_X_Event_Selection_Notify *notify)
              cnp_debug("more then one file: Bailing\n");
              return 0;
           }
-        p = files->files[0];
+        stripstr = p = strdup(files->files[0]);
      }
    else
      {
-        p = (char *)data->data;
+        stripstr = p = strndup((char *)data->data, data->length);
      }
 
    if (!p)
@@ -1660,12 +1665,17 @@ notify_handler_uri(Cnp_Selection *sel, Ecore_X_Event_Selection_Notify *notify)
         ddata.data = p;
         ddata.len = data->length;
         sel->datacb(sel->udata, sel->widget, &ddata);
+        free(p);
         return 0;
      }
    if (strncmp(p, "file://", 7))
      {
         /* Try and continue if it looks sane */
-        if (*p != '/') return 0;
+        if (*p != '/')
+          {
+             free(p);
+             return 0;
+          }
      }
    else
      {
@@ -1684,6 +1694,7 @@ notify_handler_uri(Cnp_Selection *sel, Ecore_X_Event_Selection_Notify *notify)
         pasteimage_append(pi, sel->requestwidget);
         savedtypes.pi = NULL;
      }
+   free(stripstr);
    return 0;
 }
 
@@ -1928,14 +1939,20 @@ edje_converter(char *target __UNUSED__, void *data, int size __UNUSED__, void **
         if (edje)
           *data_ret = edje;
         else
-          *data_ret = strdup(sel->selbuf);
+           if (sel->selbuf)
+             *data_ret = strdup(sel->selbuf);
+           else
+             *data_ret = strdup("");
      }
    if (size_ret)
      {
         if (edje)
           *size_ret = strlen(edje);
         else
-          *size_ret = strlen(sel->selbuf);
+          if (sel->selbuf)
+            *size_ret = strlen(sel->selbuf);
+          else
+            *size_ret = 0;
      }
 
    return EINA_TRUE;
@@ -1995,7 +2012,10 @@ html_converter(char *target __UNUSED__, void *data, int size __UNUSED__, void **
         if (html)
           *data_ret = html;
         else
-          *data_ret = strdup(sel->selbuf);
+          if (sel->selbuf)
+            *data_ret = strdup(sel->selbuf);
+          else
+            *data_ret = strdup("");
      }
 
    if (size_ret)
@@ -2003,7 +2023,10 @@ html_converter(char *target __UNUSED__, void *data, int size __UNUSED__, void **
         if (html)
           *size_ret = strlen(html);
         else
-          *size_ret = strlen(sel->selbuf);
+          if (sel->selbuf)
+            *size_ret = strlen(sel->selbuf);
+          else
+            *size_ret = 0;
      }
    if (convert_target != sel->selbuf)
      free(convert_target);
@@ -2689,7 +2712,6 @@ elm_cnp_tempfile_create(int size)
 
    tmppath = getenv("TMP");
    if (!tmppath) tmppath = P_tmpdir;
-   if (!tmppath) tmppath = "/tmp";
    len = snprintf(NULL, 0, "%s/%sXXXXXX", tmppath, "elmcnpitem-");
    if (len < 0)
      {