Exemplo n.º 1
0
gboolean
otr_on_message_send(ProfChatWin *chatwin, const char *const message)
{
    char *id = NULL;
    prof_otrpolicy_t policy = otr_get_policy(chatwin->barejid);

    // Send encrypted message
    if (otr_is_secure(chatwin->barejid)) {
        char *encrypted = otr_encrypt_message(chatwin->barejid, message);
        if (encrypted) {
            id = message_send_chat_otr(chatwin->barejid, encrypted);
            chat_log_otr_msg_out(chatwin->barejid, message);
            chatwin_outgoing_msg(chatwin, message, id, PROF_MSG_OTR);
            otr_free_message(encrypted);
            free(id);
            return TRUE;
        } else {
            ui_win_error_line((ProfWin*)chatwin, "Failed to encrypt and send message.");
            return TRUE;
        }
    }

    // show error if not secure and policy always
    if (policy == PROF_OTRPOLICY_ALWAYS) {
        ui_win_error_line((ProfWin*)chatwin, "Failed to send message. OTR policy set to: always");
        return TRUE;
    }

    // tag and send for policy opportunistic
    if (policy == PROF_OTRPOLICY_OPPORTUNISTIC) {
        char *otr_tagged_msg = otr_tag_message(message);
        id = message_send_chat_otr(chatwin->barejid, otr_tagged_msg);
        chatwin_outgoing_msg(chatwin, message, id, PROF_MSG_PLAIN);
        chat_log_msg_out(chatwin->barejid, message);
        free(otr_tagged_msg);
        free(id);
        return TRUE;
    }

    return FALSE;
}
Exemplo n.º 2
0
void
cl_ev_send_msg(ProfChatWin *chatwin, const char *const msg)
{
    chat_state_active(chatwin->state);

// OTR suported, PGP supported
#ifdef HAVE_LIBOTR
#ifdef HAVE_LIBGPGME
    if (chatwin->pgp_send) {
        char *id = message_send_chat_pgp(chatwin->barejid, msg);
        chat_log_pgp_msg_out(chatwin->barejid, msg);
        chatwin_outgoing_msg(chatwin, msg, id, PROF_MSG_PGP);
        free(id);
    } else {
        gboolean handled = otr_on_message_send(chatwin, msg);
        if (!handled) {
            char *id = message_send_chat(chatwin->barejid, msg);
            chat_log_msg_out(chatwin->barejid, msg);
            chatwin_outgoing_msg(chatwin, msg, id, PROF_MSG_PLAIN);
            free(id);
        }
    }
    return;
#endif
#endif

// OTR supported, PGP unsupported
#ifdef HAVE_LIBOTR
#ifndef HAVE_LIBGPGME
    gboolean handled = otr_on_message_send(chatwin, msg);
    if (!handled) {
        char *id = message_send_chat(chatwin->barejid, msg);
        chat_log_msg_out(chatwin->barejid, msg);
        chatwin_outgoing_msg(chatwin, msg, id, PROF_MSG_PLAIN);
        free(id);
    }
    return;
#endif
#endif

// OTR unsupported, PGP supported
#ifndef HAVE_LIBOTR
#ifdef HAVE_LIBGPGME
    if (chatwin->pgp_send) {
        char *id = message_send_chat_pgp(chatwin->barejid, msg);
        chat_log_pgp_msg_out(chatwin->barejid, msg);
        chatwin_outgoing_msg(chatwin, msg, id, PROF_MSG_PGP);
        free(id);
    } else {
        char *id = message_send_chat(chatwin->barejid, msg);
        chat_log_msg_out(chatwin->barejid, msg);
        chatwin_outgoing_msg(chatwin, msg, id, PROF_MSG_PLAIN);
        free(id);
    }
    return;
#endif
#endif

// OTR unsupported, PGP unsupported
#ifndef HAVE_LIBOTR
#ifndef HAVE_LIBGPGME
    char *id = message_send_chat(chatwin->barejid, msg);
    chat_log_msg_out(chatwin->barejid, msg);
    chatwin_outgoing_msg(chatwin, msg, id, PROF_MSG_PLAIN);
    free(id);
    return;
#endif
#endif
}
Exemplo n.º 3
0
void
cl_ev_send_msg(ProfChatWin *chatwin, const char *const msg, const char *const oob_url)
{
    chat_state_active(chatwin->state);

    gboolean request_receipt = FALSE;
    if (prefs_get_boolean(PREF_RECEIPTS_REQUEST)) {
        char *session_jid = chat_session_get_jid(chatwin->barejid);
        if (session_jid) {
            Jid *session_jidp = jid_create(session_jid);
            if (session_jidp && session_jidp->resourcepart) {
                if (caps_jid_has_feature(session_jid, XMPP_FEATURE_RECEIPTS)) {
                    request_receipt = TRUE;
                }
            }
            jid_destroy(session_jidp);
            free(session_jid);
        }
    }

    char *plugin_msg = plugins_pre_chat_message_send(chatwin->barejid, msg);
    if (plugin_msg == NULL) {
        return;
    }

// OTR suported, PGP supported
#ifdef HAVE_LIBOTR
#ifdef HAVE_LIBGPGME
    if (chatwin->pgp_send) {
        char *id = message_send_chat_pgp(chatwin->barejid, plugin_msg, request_receipt);
        chat_log_pgp_msg_out(chatwin->barejid, plugin_msg);
        chatwin_outgoing_msg(chatwin, plugin_msg, id, PROF_MSG_PGP, request_receipt);
        free(id);
    } else {
        gboolean handled = otr_on_message_send(chatwin, plugin_msg, request_receipt);
        if (!handled) {
            char *id = message_send_chat(chatwin->barejid, plugin_msg, oob_url, request_receipt);
            chat_log_msg_out(chatwin->barejid, plugin_msg);
            chatwin_outgoing_msg(chatwin, plugin_msg, id, PROF_MSG_PLAIN, request_receipt);
            free(id);
        }
    }

    plugins_post_chat_message_send(chatwin->barejid, plugin_msg);
    free(plugin_msg);
    return;
#endif
#endif

// OTR supported, PGP unsupported
#ifdef HAVE_LIBOTR
#ifndef HAVE_LIBGPGME
    gboolean handled = otr_on_message_send(chatwin, plugin_msg, request_receipt);
    if (!handled) {
        char *id = message_send_chat(chatwin->barejid, plugin_msg, oob_url, request_receipt);
        chat_log_msg_out(chatwin->barejid, plugin_msg);
        chatwin_outgoing_msg(chatwin, plugin_msg, id, PROF_MSG_PLAIN, request_receipt);
        free(id);
    }

    plugins_post_chat_message_send(chatwin->barejid, plugin_msg);
    free(plugin_msg);
    return;
#endif
#endif

// OTR unsupported, PGP supported
#ifndef HAVE_LIBOTR
#ifdef HAVE_LIBGPGME
    if (chatwin->pgp_send) {
        char *id = message_send_chat_pgp(chatwin->barejid, plugin_msg, request_receipt);
        chat_log_pgp_msg_out(chatwin->barejid, plugin_msg);
        chatwin_outgoing_msg(chatwin, plugin_msg, id, PROF_MSG_PGP, request_receipt);
        free(id);
    } else {
        char *id = message_send_chat(chatwin->barejid, plugin_msg, oob_url, request_receipt);
        chat_log_msg_out(chatwin->barejid, plugin_msg);
        chatwin_outgoing_msg(chatwin, plugin_msg, id, PROF_MSG_PLAIN, request_receipt);
        free(id);
    }

    plugins_post_chat_message_send(chatwin->barejid, plugin_msg);
    free(plugin_msg);
    return;
#endif
#endif

// OTR unsupported, PGP unsupported
#ifndef HAVE_LIBOTR
#ifndef HAVE_LIBGPGME
    char *id = message_send_chat(chatwin->barejid, plugin_msg, oob_url, request_receipt);
    chat_log_msg_out(chatwin->barejid, plugin_msg);
    chatwin_outgoing_msg(chatwin, plugin_msg, id, PROF_MSG_PLAIN, request_receipt);
    free(id);

    plugins_post_chat_message_send(chatwin->barejid, plugin_msg);
    free(plugin_msg);
    return;
#endif
#endif
}