std::string markup_unescape(std::string const &markup) { gchar *unescaped = purple_unescape_html(markup.c_str()); std::string result(unescaped); g_free(unescaped); return result; }
static int tgprpl_send_im (PurpleConnection * gc, const char *who, const char *message, PurpleMessageFlags flags) { debug ("tgprpl_send_im()\n"); telegram_conn *conn = purple_connection_get_protocol_data(gc); PurpleAccount *pa = conn->pa; // this is part of a workaround to support clients without // the request API (request.h), see telegram-base.c:request_code() if (conn->in_fallback_chat) { request_code_entered (conn->TLS, message); conn->in_fallback_chat = 0; return 1; } PurpleBuddy *b = purple_find_buddy (pa, who); if (!b) { warning ("Buddy %s not found, cannot send IM\n", who); return -1; } tgl_peer_t *peer = tgl_peer_get(conn->TLS, TGL_MK_USER(atoi (who))); if (!peer) { warning ("Protocol data tgl_peer_t for %s not found, cannot send IM\n", who); return -1; } gchar *raw = purple_unescape_html(message); tgl_do_send_message (conn->TLS, peer->id, raw, (int)strlen (raw), 0, 0); g_free(raw); return 1; }
static void find_feed_url_cb(FacebookAccount *fba, gchar *data, gsize data_len, gpointer userdata) { const gchar *search_string = "/feeds/notifications.php"; gchar *feed_url; gchar *stripped; purple_debug_info("facebook", "find_feed_url_cb\n"); if (!data) data = "(null)"; feed_url = g_strstr_len(data, data_len, search_string); if (!feed_url) { purple_debug_error("facebook", "received data, but could not find url on page\n"); return; } feed_url = g_strndup(feed_url, strchr(feed_url, '"') - feed_url); /* convert & to & */ stripped = purple_unescape_html(feed_url); g_free(feed_url); feed_url = stripped; purple_debug_info("facebook", "parsed feed url %s\n", feed_url); if (feed_url && *feed_url) { purple_account_set_string(fba->account, "notifications_feed_url", feed_url); fb_get_notifications_feed(fba); } }
void purpleTooltipInfo::Init(PurpleNotifyUserInfoEntry *aEntry) { mType = purple_notify_user_info_entry_get_type(aEntry); mLabel = purple_notify_user_info_entry_get_label(aEntry); char *value = purple_unescape_html(purple_notify_user_info_entry_get_value(aEntry)); mValue = value; g_free(value); }
char * xmlnode_get_data_unescaped(xmlnode *node) { char *escaped = xmlnode_get_data(node); char *unescaped = escaped ? purple_unescape_html(escaped) : NULL; g_free(escaped); return unescaped; }
static void 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; xmlnode *node; int i, j; if(!element_name || xpd->error) { return; } else { if(xpd->current) node = xmlnode_new_child(xpd->current, (const char*) element_name); else node = xmlnode_new((const char *) element_name); xmlnode_set_namespace(node, (const char *) xmlns); 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 *prefix = (const char *)attributes[i + 1]; char *txt; int attrib_len = attributes[i+4] - attributes[i+3]; char *attrib = g_malloc(attrib_len + 1); memcpy(attrib, attributes[i+3], attrib_len); attrib[attrib_len] = '\0'; txt = attrib; attrib = purple_unescape_html(txt); g_free(txt); if (prefix && *prefix) { xmlnode_set_attrib_with_prefix(node, (const char*) attributes[i], prefix, attrib); } else { xmlnode_set_attrib(node, (const char*) attributes[i], attrib); } g_free(attrib); } xpd->current = node; } }
char * purple_xmlnode_get_data_unescaped(const PurpleXmlNode *node) { char *escaped = purple_xmlnode_get_data(node); char *unescaped = escaped ? purple_unescape_html(escaped) : NULL; g_free(escaped); return unescaped; }
static int tgprpl_send_chat (PurpleConnection * gc, int id, const char *message, PurpleMessageFlags flags) { debug ("tgprpl_send_chat()\n"); telegram_conn *conn = purple_connection_get_protocol_data (gc); gchar *raw = purple_unescape_html(message); tgl_do_send_message (conn->TLS, TGL_MK_CHAT(id), raw, (int)strlen (raw), 0, 0); g_free (raw); p2tgl_got_chat_in(conn->TLS, TGL_MK_CHAT(id), TGL_MK_USER(conn->TLS->our_id), message, PURPLE_MESSAGE_RECV, time(NULL)); return 1; }
static int fetion_im_send(PurpleConnection * gc, const char *who, const char *what, PurpleMessageFlags flags) { struct fetion_account_data *sip = gc->proto_data; char *to = g_strdup(who); char *text = purple_unescape_html(what); fetion_send_message(sip, to, text, NULL, FALSE); g_free(to); g_free(text); return 1; }
/* * Initialize from an incoming libPurple callback parameters * * payload form: (Sprint) * { "serviceName": "gmail", "username": "******", "usernameFrom": "*****@*****.**", "messageText": "<body>test reply to phone<\/body>" } * { "serviceName": "aol", "username": "******", "usernameFrom": "palm", "messageText": "test incoming message" } * * */ MojErr IMMessage::initFromCallback(const char* serviceName, const char* username, const char* usernameFrom, const char* message) { MojErr err; // unescape, strip html // #/tmp/testsanitize "<a>foo</a>" // sanitized: <a>foo</a> // unsanitized: <a>foo</a> // removed: foo char* unescapedMessage = purple_unescape_html(message); char* sanitizedMessage = purple_markup_strip_html(unescapedMessage); g_free(unescapedMessage); msgText.assign(""); // Inefficient but working solution. // TODO: Implement proper sanitization (that just keeps br, u, l and i) for (char* ptr = sanitizedMessage; *ptr; ++ptr) if (*ptr == '\n') msgText.append("<br>"); else msgText.append(*ptr); err = msgText.assign(sanitizedMessage); g_free(sanitizedMessage); MojErrCheck(err); // remove blanks and convert to lowercase // for AOL, this is screen name with no "@aol.com"... MojString formattedUserName; err = formattedUserName.assign(usernameFrom); MojErrCheck(err); err = unformatFromAddress(formattedUserName, fromAddress); MojErrCheck(err); err = toAddress.assign(username); MojErrCheck(err); err = msgType.assign(serviceName); MojErrCheck(err); // set time stamp to current time - seconds since 1/1/1970 // for some reason multiplying a time_t by 1000 doesn't work - you have to convert to a long first... //deviceTimestamp = time (NULL) * 1000; MojInt64 sec = time (NULL); deviceTimestamp = sec * 1000; // server timestamp is new Date().getTime() serverTimestamp = sec * 1000; return MojErrNone; }
/* Frees 'urls' */ static void process_urls(PurpleConversation *conv, GList *urls) { GList *iter; int c; FinchConv *fconv = FINCH_CONV(conv); GntTextView *tv = GNT_TEXT_VIEW(fconv->tv); for (iter = urls, c = 1; iter; iter = iter->next, c++) { int i; CbInfo *cbdata; gchar *url, *str; gchar *original_url; const gchar *tiny_url; i = gnt_text_view_get_lines_below(tv); original_url = purple_unescape_html((char *)iter->data); tiny_url = g_hash_table_lookup(tinyurl_cache, original_url); if (tiny_url) { gchar *str = g_strdup_printf("\n[%d] %s", c, tiny_url); g_free(original_url); gnt_text_view_append_text_with_flags(tv, str, GNT_TEXT_FLAG_DIM); if (i == 0) gnt_text_view_scroll(tv, 0); g_free(str); continue; } cbdata = g_new(CbInfo, 1); cbdata->num = c; cbdata->original_url = original_url; cbdata->tag = g_strdup_printf("%s%d", "tiny_", tag_num++); cbdata->conv = conv; if (g_ascii_strncasecmp(original_url, "http://", 7) && g_ascii_strncasecmp(original_url, "https://", 8)) { url = g_strdup_printf("%shttp%%3A%%2F%%2F%s", purple_prefs_get_string(PREF_URL), purple_url_encode(original_url)); } else { url = g_strdup_printf("%s%s", purple_prefs_get_string(PREF_URL), purple_url_encode(original_url)); } purple_http_get(NULL, url_fetched, cbdata, url); str = g_strdup_printf(_("\nFetching TinyURL...")); gnt_text_view_append_text_with_tag((tv), str, GNT_TEXT_FLAG_DIM, cbdata->tag); g_free(str); if (i == 0) gnt_text_view_scroll(tv, 0); g_free(iter->data); g_free(url); } g_list_free(urls); }
/* 205 - MSG_CLIENT_PRIVMSG */ static int nap_send_im(PurpleConnection *gc, const char *who, const char *message, PurpleMessageFlags flags) { char *tmp = purple_unescape_html(message); if ((strlen(tmp) < 2) || (tmp[0] != '/' ) || (tmp[1] == '/')) { /* Actually send a chat message */ nap_write_packet(gc, 205, "%s %s", who, tmp); } else { /* user typed an IRC-style command */ nap_do_irc_style(gc, tmp, who); } g_free(tmp); return 1; }
static void on_write_im(PurpleConversation *conv, const char *name, const char *message, PurpleMessageFlags flags, time_t mtime) { g_assert(conversations_uiops_lua); LuaState *L = ms_lua_var_get(conversations_uiops_lua, "conversation_write_im"); char *message2 = purple_unescape_html(message); lua_pushlightuserdata(L, conv); lua_gettable(L, LUA_REGISTRYINDEX); g_assert(!lua_isnil(L, -1)); lua_pushstring(L, name); lua_pushstring(L, message2); lua_pushinteger(L, flags); lua_pushinteger(L, mtime); ms_lua_call(L, 5, 0, "purple.conversations in uiops.conversation_write_im"); g_free(message2); }
static gchar *format_channel_real(ParserVars *vars, const gchar *name, const gchar *title) { PurpleAccount *pa; gchar *unescaped, *ret; GString *gs; if(!vars->fla) return g_strdup(name); unescaped = purple_unescape_html(name); gs = g_string_new(NULL); pa = vars->fla->pa; g_string_append(gs, "<a href=\"flistc://"); g_string_append(gs, purple_url_encode(flist_serialize_account(pa))); g_string_append_c(gs, '/'); g_string_append(gs, purple_url_encode(unescaped)); g_string_append(gs, "\">(Channel) "); g_string_append(gs, title); g_string_append(gs, "</a>"); ret = g_string_free(gs, FALSE); g_free(unescaped); return ret; }
/* 402 - MSG_CLIENT_PUBLIC */ static int nap_chat_send(PurpleConnection *gc, int id, const char *message, PurpleMessageFlags flags) { PurpleConversation *c = purple_find_chat(gc, id); char *tmp = purple_unescape_html(message); if (!c) return -EINVAL; if ((strlen(tmp) < 2) || (tmp[0] != '/' ) || (tmp[1] == '/')) { /* Actually send a chat message */ nap_write_packet(gc, 402, "%s %s", c->name, tmp); } else { /* user typed an IRC-style command */ nap_do_irc_style(gc, tmp, c->name); } g_free(tmp); return 0; }
SilcDList silcpurple_image_message(const char *msg, SilcMessageFlags *mflags) { SilcMime mime = NULL, p; SilcDList list, parts = NULL; const char *start, *end, *last; GData *attribs; char *type; gboolean images = FALSE; last = msg; while (last && *last && purple_markup_find_tag("img", last, &start, &end, &attribs)) { PurpleStoredImage *image = NULL; const char *id; /* Check if there is text before image */ if (start - last) { char *text, *tmp; p = silc_mime_alloc(); /* Add content type */ silc_mime_add_field(p, "Content-Type", "text/plain; charset=utf-8"); tmp = g_strndup(last, start - last); text = purple_unescape_html(tmp); g_free(tmp); /* Add text */ silc_mime_add_data(p, (const unsigned char *)text, strlen(text)); g_free(text); if (!parts) parts = silc_dlist_init(); silc_dlist_add(parts, p); } id = g_datalist_get_data(&attribs, "id"); if (id && (image = purple_imgstore_find_by_id(atoi(id)))) { unsigned long imglen = purple_imgstore_get_size(image); gconstpointer img = purple_imgstore_get_data(image); p = silc_mime_alloc(); /* Add content type */ type = silcpurple_file2mime(purple_imgstore_get_filename(image)); if (!type) { g_datalist_clear(&attribs); last = end + 1; continue; } silc_mime_add_field(p, "Content-Type", type); g_free(type); /* Add content transfer encoding */ silc_mime_add_field(p, "Content-Transfer-Encoding", "binary"); /* Add image data */ silc_mime_add_data(p, img, imglen); if (!parts) parts = silc_dlist_init(); silc_dlist_add(parts, p); images = TRUE; } g_datalist_clear(&attribs); /* Continue after tag */ last = end + 1; } /* Check for text after the image(s) */ if (images && last && *last) { char *tmp = purple_unescape_html(last); p = silc_mime_alloc(); /* Add content type */ silc_mime_add_field(p, "Content-Type", "text/plain; charset=utf-8"); /* Add text */ silc_mime_add_data(p, (const unsigned char *)tmp, strlen(tmp)); g_free(tmp); if (!parts) parts = silc_dlist_init(); silc_dlist_add(parts, p); } /* If there weren't any images, don't return anything. */ if (!images) { if (parts) silc_dlist_uninit(parts); return NULL; } if (silc_dlist_count(parts) > 1) { /* Multipart MIME message */ char b[32]; mime = silc_mime_alloc(); silc_mime_add_field(mime, "MIME-Version", "1.0"); g_snprintf(b, sizeof(b), "b%4X%4X", (unsigned int)time(NULL), silc_dlist_count(parts)); silc_mime_set_multipart(mime, "mixed", b); silc_dlist_start(parts); while ((p = silc_dlist_get(parts)) != SILC_LIST_END) silc_mime_add_multipart(mime, p); } else { /* Simple MIME message */ silc_dlist_start(parts); mime = silc_dlist_get(parts); silc_mime_add_field(mime, "MIME-Version", "1.0"); } *mflags &= ~SILC_MESSAGE_FLAG_UTF8; *mflags |= SILC_MESSAGE_FLAG_DATA; /* Encode message. Fragment if it is too large */ list = silc_mime_encode_partial(mime, 0xfc00); silc_dlist_uninit(parts); /* Added multiparts gets freed here */ silc_mime_free(mime); return list; }
static void fb_login_cb(FacebookAccount *fba, gchar *response, gsize len, gpointer userdata) { gchar *user_cookie; const gchar *persist_data_start; gchar *persist_data; const gchar *session_start; gchar *session; gchar *captcha_url; const gchar *extra_challenge_params; gchar *extra_challenge; if (len && g_strstr_len(response, len, "captcha")) { purple_debug_info("facebook", "captcha page: %s\n", response); purple_connection_update_progress(fba->pc, _("Handling Captcha"), 2, 4); persist_data_start = "<input type=\"hidden\" id=\"captcha_persist_data\" name=\"captcha_persist_data\" value=\""; persist_data = g_strstr_len(response, len, persist_data_start); if (persist_data) { persist_data += strlen(persist_data_start); fba->persist_data = g_strndup(persist_data, strchr(persist_data, '"') - persist_data); } session_start = "<input type=\"hidden\" id=\"captcha_session\" name=\"captcha_session\" value=\""; session = g_strstr_len(response, len, session_start); if (session) { session += strlen(session_start); fba->captcha_session = g_strndup(session, strchr(session, '"') - session); } extra_challenge_params = "<input type=\"hidden\" id=\"extra_challenge_params\" name=\"extra_challenge_params\" value=\""; extra_challenge = g_strstr_len(response, len, extra_challenge_params); if (extra_challenge) { extra_challenge += strlen(extra_challenge_params); fba->extra_challenge = g_strndup(extra_challenge, strchr(extra_challenge, '"') - extra_challenge); extra_challenge = purple_unescape_html(fba->extra_challenge); g_free(fba->extra_challenge); fba->extra_challenge = extra_challenge; } if (!fba->extra_challenge || !fba->persist_data || !fba->captcha_session) { purple_debug_info("facebook", "captcha response: %s\n", response); g_free(fba->extra_challenge); g_free(fba->persist_data); g_free(fba->captcha_session); fba->extra_challenge = NULL; fba->persist_data = NULL; fba->captcha_session = NULL; purple_connection_error_reason(fba->pc, PURPLE_CONNECTION_ERROR_OTHER_ERROR, "Could not authenticate captcha. Logging into the Facebook website may fix this."); return; } captcha_url = g_strdup_printf("/challenge?k=" FACEBOOK_CAPTCHA_SITE "&%s", fba->extra_challenge?fba->extra_challenge:""); fb_post_or_get(fba, FB_METHOD_GET | FB_METHOD_SSL, "api-secure.recaptcha.net", captcha_url, NULL, fb_login_captcha_cb, NULL, FALSE); g_free(captcha_url); return; } purple_connection_update_progress(fba->pc, _("Authenticating"), 2, 3); /* Look for our uid */ user_cookie = g_hash_table_lookup(fba->cookie_table, "c_user"); if (user_cookie == NULL) { /* * Server didn't set the c_user cookie, so we must have given * them a bad username or password */ purple_connection_error_reason(fba->pc, PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED, _("Incorrect username or password.")); return; } fba->uid = atoll(user_cookie); purple_debug_info("facebook", "uid %" G_GINT64_FORMAT "\n", fba->uid); /* ok, we're logged in now! */ purple_connection_set_state(fba->pc, PURPLE_CONNECTED); /* This will kick off our long-poll message retrieval loop */ fb_get_post_form_id(fba); fb_check_friend_requests(fba); /* periodically check for people adding you to their facebook friend list */ fba->friend_request_timer = purple_timeout_add_seconds(60 * 5, fb_check_friend_requests, fba); /* periodically check for new notifications */ fba->notifications_timer = purple_timeout_add_seconds(60, (GSourceFunc)fb_get_notifications_feed, fba); /* Periodically check for new messages. NOTE: This MUST exist, * regardless of other other mechanisms for checking messages. This * is because the code needs a failsafe checker in case other one of * the other retrieval mechanisms dies due to a bad request, etc. * Without such a failsafe, a user will receive no messages, which is * one of hardest bugs to debug and get reports about. Hence, the * importance of this loop. * That said, there is room for tweaking this loop and possibly even * setting it such that it is the primary or only message checker. * The key is that the method must NEVER die until logout. */ fba->perpetual_messages_timer = purple_timeout_add_seconds(15, (GSourceFunc)fb_get_messages_failsafe, fba); /* init blist subsystem */ fb_blist_init(fba); /* init conversation subsystem */ fb_conversation_init(fba); }