static int irc_chat_send(PurpleConnection *gc, int id, const char *what, PurpleMessageFlags flags) { struct irc_conn *irc = gc->proto_data; PurpleConversation *convo = purple_find_chat(gc, id); const char *args[2]; char *tmp; if (!convo) { purple_debug(PURPLE_DEBUG_ERROR, "irc", "chat send on nonexistent chat\n"); return -EINVAL; } #if 0 if (*what == '/') { return irc_parse_cmd(irc, convo->name, what + 1); } #endif purple_markup_html_to_xhtml(what, NULL, &tmp); args[0] = convo->name; args[1] = tmp; irc_cmd_privmsg(irc, "msg", NULL, args); serv_got_chat_in(gc, id, purple_connection_get_display_name(gc), 0, what, time(NULL)); g_free(tmp); return 0; }
static int waprpl_send_chat(PurpleConnection * gc, int id, const char *message, PurpleMessageFlags flags) { whatsapp_connection *wconn = purple_connection_get_protocol_data(gc); PurpleAccount *account = purple_connection_get_account(gc); PurpleConversation *convo = purple_find_chat(gc, id); PurpleChat *ch = blist_find_chat_by_convo(gc, id); GHashTable *hasht = purple_chat_get_components(ch); char *chat_id = g_hash_table_lookup(hasht, "id"); char *plain; purple_markup_html_to_xhtml(message, NULL, &plain); char msgid[128]; waAPI_getmsgid(wconn->waAPI, msgid); purple_signal_emit(purple_connection_get_prpl(gc), "whatsapp-sending-message", gc, msgid, chat_id, message); waAPI_sendchat(wconn->waAPI, msgid, chat_id, plain); g_free(plain); waprpl_check_output(gc); const char *me = purple_account_get_string(account, "nick", ""); purple_conv_chat_write(PURPLE_CONV_CHAT(convo), me, message, PURPLE_MESSAGE_SEND, time(NULL)); return 1; }
END_TEST START_TEST(test_markup_html_to_xhtml) { gchar *xhtml = NULL; gchar *plaintext = NULL; purple_markup_html_to_xhtml("<a>", &xhtml, &plaintext); fail_unless(strcmp("<a href=''></a>", xhtml) == 0, NULL); g_free(xhtml); fail_unless(strcmp("", plaintext) == 0, NULL); g_free(plaintext); }
static int waprpl_send_im(PurpleConnection * gc, const char *who, const char *message, PurpleMessageFlags flags) { whatsapp_connection *wconn = purple_connection_get_protocol_data(gc); char *plain; purple_markup_html_to_xhtml(message, NULL, &plain); waAPI_sendim(wconn->waAPI, who, plain); g_free(plain); waprpl_check_output(gc); return 1; }
static int irc_im_send(PurpleConnection *gc, const char *who, const char *what, PurpleMessageFlags flags) { struct irc_conn *irc = gc->proto_data; char *plain; const char *args[2]; args[0] = irc_nick_skip_mode(irc, who); purple_markup_html_to_xhtml(what, NULL, &plain); args[1] = plain; irc_cmd_privmsg(irc, "msg", NULL, args); g_free(plain); return 1; }
void SpectrumMUCConversation::handleMessage(AbstractUser *user, const char *who, const char *msg, PurpleMessageFlags flags, time_t mtime, const std::string ¤tBody) { std::string name(who); // // // send message to user // std::string message(purple_unescape_html(msg)); // Message s(Message::Groupchat, user->jid() + m_res, message); // s.setFrom(m_jid + "/" + name); // // Transport::instance()->send( s.tag() ); // Escape HTML characters. char *newline = purple_strdup_withhtml(msg); char *strip, *xhtml; purple_markup_html_to_xhtml(newline, &xhtml, &strip); std::string message(strip); std::string to = user->jid() + m_res; std::cout << user->jid() << " " << m_res << "\n"; Message s(Message::Groupchat, to, message); s.setFrom(m_jid + "/" + name); // <delay xmlns="urn:xmpp:delay" stamp="2010-02-16T15:49:19Z"/> // <x xmlns="jabber:x:delay" stamp="20100216T15:49:19"/> // Delayed messages, we have to count with some delay if ((unsigned long) time(NULL)-10 > (unsigned long) mtime) { char buf[80]; strftime(buf, sizeof(buf), "%Y-%m-%dT%H:%M:%SZ", gmtime(&mtime)); std::string timestamp(buf); DelayedDelivery *d = new DelayedDelivery(m_jid, timestamp); s.addExtension(d); } Tag *stanzaTag = s.tag(); g_free(newline); g_free(xhtml); g_free(strip); // std::string res = getResource(); // if (user->hasFeature(GLOOX_FEATURE_XHTML_IM, res) && m != message) { // Transport::instance()->parser()->getTag("<body>" + m + "</body>", sendXhtmlTag, stanzaTag); // return; // } Transport::instance()->send(stanzaTag); }
static void append_to_tooltip(PurpleBlistNode *node, GString *text, gboolean full) { if (full) { const gchar *note = purple_blist_node_get_string(node, "notes"); if ((note != NULL) && (*note != '\0')) { char *tmp, *esc; purple_markup_html_to_xhtml(note, NULL, &tmp); esc = g_markup_escape_text(tmp, -1); g_free(tmp); g_string_append_printf(text, _("\n<b>Buddy Note</b>: %s"), esc); g_free(esc); } } }
static int irc_im_send(PurpleConnection *gc, const char *who, const char *what, PurpleMessageFlags flags) { struct irc_conn *irc = gc->proto_data; char *plain; const char *args[2]; if (strchr(status_chars, *who) != NULL) args[0] = who + 1; else args[0] = who; purple_markup_html_to_xhtml(what, NULL, &plain); args[1] = plain; irc_cmd_privmsg(irc, "msg", NULL, args); g_free(plain); return 1; }
static void *finch_notify_formatted(const char *title, const char *primary, const char *secondary, const char *text) { char *xhtml = NULL; char *t = g_strdup_printf("<span>%s%s%s</span>", secondary ? secondary : "", secondary ? "\n" : "", text ? text : ""); void *ret; purple_markup_html_to_xhtml(t, &xhtml, NULL); ret = finch_notify_common(PURPLE_NOTIFY_FORMATTED, PURPLE_NOTIFY_MSG_INFO, title, primary, xhtml); g_free(t); g_free(xhtml); return ret; }
static int waprpl_send_im(PurpleConnection * gc, const char *who, const char *message, PurpleMessageFlags flags) { whatsapp_connection *wconn = purple_connection_get_protocol_data(gc); char *plain; purple_markup_html_to_xhtml(message, NULL, &plain); char msgid[128]; waAPI_getmsgid(wconn->waAPI, msgid); purple_signal_emit(purple_connection_get_prpl(gc), "whatsapp-sending-message", gc, msgid, who, message); waAPI_sendim(wconn->waAPI, msgid, who, plain); g_free(plain); waprpl_check_output(gc); return 1; }
void SpectrumConversation::handleMessage(AbstractUser *user, const char *who, const char *msg, PurpleMessageFlags flags, time_t mtime, const std::string ¤tBody) { std::string name(who); // Remove resource if it's XMPP JID size_t pos = name.find("/"); if (pos != std::string::npos) name.erase((int) pos, name.length() - (int) pos); AbstractSpectrumBuddy *s_buddy = NULL; #ifndef TESTS User *u = (User *) user; s_buddy = u->getRosterItem(name); #endif if (s_buddy && s_buddy->getFlags() & SPECTRUM_BUDDY_JID_ESCAPING) name = JID::escapeNode(name); else if (s_buddy) std::for_each( name.begin(), name.end(), replaceBadJidCharacters() ); // OK else if (m_room.empty()) name = JID::escapeNode(name); // Escape HTML characters. char *newline = purple_strdup_withhtml(msg); char *strip, *xhtml, *xhtml_linkified; purple_markup_html_to_xhtml(newline, &xhtml, &strip); xhtml_linkified = purple_markup_linkify(xhtml); std::string message(strip); std::string m(xhtml_linkified); g_free(newline); g_free(xhtml); g_free(xhtml_linkified); g_free(strip); std::string to; if (getResource().empty()) to = user->jid(); else to = user->jid() + "/" + getResource(); if (flags & PURPLE_MESSAGE_ERROR) { Message s(Message::Error, to, currentBody); if (!m_room.empty()) s.setFrom(m_room + "/" + name); else { std::transform(name.begin(), name.end(), name.begin(),(int(*)(int)) std::tolower); s.setFrom(name + std::string(getType() == SPECTRUM_CONV_CHAT ? "" : ("%" + JID(user->username()).server())) + "@" + Transport::instance()->jid() + "/bot"); } Error *c = new Error(StanzaErrorTypeModify, StanzaErrorNotAcceptable); c->setText(tr(user->getLang(), message)); s.addExtension(c); Transport::instance()->send(s.tag()); return; } Message s(Message::Chat, to, message); if (!m_room.empty()) s.setFrom(m_room + "/" + name); else { std::transform(name.begin(), name.end(), name.begin(),(int(*)(int)) std::tolower); s.setFrom(name + std::string(getType() == SPECTRUM_CONV_CHAT ? "" : ("%" + JID(user->username()).server())) + "@" + Transport::instance()->jid() + "/bot"); } // chatstates if (purple_value_get_boolean(user->getSetting("enable_chatstate"))) { if (user->hasFeature(GLOOX_FEATURE_CHATSTATES, getResource())) { ChatState *c = new ChatState(ChatStateActive); s.addExtension(c); } } // Delayed messages, we have to count with some delay if (mtime && (unsigned long) time(NULL)-10 > (unsigned long) mtime/* && (unsigned long) time(NULL) - 31536000 < (unsigned long) mtime*/) { char buf[80]; strftime(buf, sizeof(buf), "%Y-%m-%dT%H:%M:%SZ", gmtime(&mtime)); std::string timestamp(buf); DelayedDelivery *d = new DelayedDelivery(name + "@" + Transport::instance()->jid() + "/bot", timestamp); s.addExtension(d); } Tag *stanzaTag = s.tag(); std::string res = getResource(); if (user->hasFeature(GLOOX_FEATURE_XHTML_IM, res) && m != message) { if (m.find("<body") != 0) { m = "<body>" + m + "</body>"; } Transport::instance()->parser()->getTag(m, sendXhtmlTag, stanzaTag); return; } Transport::instance()->send(stanzaTag); }