Ejemplo n.º 1
0
static void
purple_xmlnode_parser_element_start_libxml(void *user_data,
        const xmlChar *element_name, const xmlChar *prefix, const xmlChar *xmlns,
        int nb_namespaces, const xmlChar **namespaces,
        int nb_attributes, int nb_defaulted, const xmlChar **attributes)
{
    struct _xmlnode_parser_data *xpd = user_data;
    PurpleXmlNode *node;
    int i, j;

    if(!element_name || xpd->error) {
        return;
    } else {
        if(xpd->current)
            node = purple_xmlnode_new_child(xpd->current, (const char*) element_name);
        else
            node = purple_xmlnode_new((const char *) element_name);

        purple_xmlnode_set_namespace(node, (const char *) xmlns);
        purple_xmlnode_set_prefix(node, (const char *)prefix);

        if (nb_namespaces != 0) {
            node->namespace_map = g_hash_table_new_full(
                                      g_str_hash, g_str_equal, g_free, g_free);

            for (i = 0, j = 0; i < nb_namespaces; i++, j += 2) {
                const char *key = (const char *)namespaces[j];
                const char *val = (const char *)namespaces[j + 1];
                g_hash_table_insert(node->namespace_map,
                                    g_strdup(key ? key : ""), g_strdup(val ? val : ""));
            }
        }

        for(i=0; i < nb_attributes * 5; i+=5) {
            const char *name = (const char *)attributes[i];
            const char *prefix = (const char *)attributes[i+1];
            char *txt;
            int attrib_len = attributes[i+4] - attributes[i+3];
            char *attrib = g_strndup((const char *)attributes[i+3], attrib_len);
            txt = attrib;
            attrib = purple_unescape_text(txt);
            g_free(txt);
            purple_xmlnode_set_attrib_full(node, name, NULL, prefix, attrib);
            g_free(attrib);
        }

        xpd->current = node;
    }
}
Ejemplo n.º 2
0
int tgp_msg_send (struct tgl_state *TLS, const char *message, tgl_peer_id_t to) {
  // search for outgoing embedded image tags and send them
  gchar *img = NULL;
  gchar *stripped = NULL;
  if ((img = g_strrstr (message, "<IMG")) || (img = g_strrstr (message, "<img"))) {
    if (tgl_get_peer_type(to) == TGL_PEER_ENCR_CHAT) {
      tgp_msg_err_out (TLS, "Sorry, sending documents to encrypted chats not yet supported.", to);
      return 0;
    }
    
    debug ("img found: %s", img);
    gchar *id;
    if ((id = g_strrstr (img, "ID=\"")) || (id = g_strrstr (img, "id=\""))) {
      id += 4;
      debug ("id found: %s", id);
      int imgid = atoi (id);
      if (imgid > 0) {
        PurpleStoredImage *psi = purple_imgstore_find_by_id (imgid);
        gchar *tmp = g_build_filename(g_get_tmp_dir(), purple_imgstore_get_filename (psi), NULL) ;
        GError *err = NULL;
        gconstpointer data = purple_imgstore_get_data (psi);
        g_file_set_contents (tmp, data, purple_imgstore_get_size (psi), &err);
        if (! err) {
          stripped = purple_markup_strip_html (message);
          tgl_do_send_document (TLS, to, tmp, stripped, (int)strlen (stripped), TGL_SEND_MSG_FLAG_DOCUMENT_AUTO, tgp_msg_send_done, NULL);
          g_free (stripped);
          return 1;
        } else {
          failure ("Cannot store image, temp directory not available: %s\n", err->message);
          g_error_free (err);
          return 0;
        }
      }
    }
    // no image id found in image
    return 0;
  }
  
#ifndef __ADIUM_
  /*
    Adium won't escape any HTML markup and just pass any user-input through,
    while Pidgin will replace special chars with the escape chars and also add 
    additional markup for RTL languages and such.

    First, we remove any HTML markup added by Pidgin, since Telegram won't handle it properly.
    User-entered HTML is still escaped and therefore won't be harmed.
   */
  stripped = purple_markup_strip_html (message);
  
  /* 
    now unescape the markup, so that html special chars will still show
    up properly in Telegram
   */
  gchar *unescaped = purple_unescape_text (stripped);
  int ret = tgp_msg_send_split (TLS, stripped, to);
  
  g_free (unescaped);
  g_free (stripped);
  return ret;
#endif
  
  return tgp_msg_send_split (TLS, message, to);
}