Ejemplo n.º 1
0
    static void
send_message (GObject *object,
        TpMessage *message,
        TpMessageSendingFlags flags)
{
    FetionImChannel *self = FETION_IM_CHANNEL (object);
    TpBaseChannel *base = TP_BASE_CHANNEL (self);
    if (tp_asv_get_string (tp_message_peek (message, 0), "interface") != NULL)
    {
        /* this message is interface-specific - let's not echo it */
        goto finally;
    }

    FetionConnection *conn =
        FETION_CONNECTION (tp_base_channel_get_connection(base));

    HybridAccount *account = conn->priv->account;

    TpHandle from = tp_base_channel_get_target_handle (base);
    const GHashTable *input = tp_message_peek (message, 1);
    const gchar *send_message = tp_asv_get_string (input, "content");
    HybridBuddy *buddy = hybrid_blist_find_buddy_by_handle(account, from);
    hybrid_conv_send_message(account,buddy,send_message);

finally:
    /* "OK, we've sent the message" (after calling this, message must not be
     * dereferenced) */
    tp_message_mixin_sent (object, message, flags, "", NULL);

}
Ejemplo n.º 2
0
/** start send message **/
static void
send_message (GObject *object,
        TpMessage *message,
        TpMessageSendingFlags flags)
{
    LwqqChannel* self = LWQQ_CHANNEL(object);
    TpBaseChannel *base = TP_BASE_CHANNEL (self);
    if (tp_asv_get_string (tp_message_peek (message, 0), "interface") != NULL)
    {
        /* this message is interface-specific - let's not echo it */
        goto finally;
    }

    LwqqConnection *conn =
        LWQQ_CONNECTION(tp_base_channel_get_connection(base));

    LwqqClient* lc = conn->lc;

    TpHandle to = tp_base_channel_get_target_handle (base);
    const GHashTable *input = tp_message_peek (message, 1);
    const gchar *send_message = tp_asv_get_string (input, "content");
    LwqqBuddy* buddy = lwqq_find_buddy_by_handle(conn, to);
    lwqq_msg_send_text(lc, LWQQ_MS_BUDDY_MSG, buddy->uin, send_message);

finally:
    /* "OK, we've sent the message" (after calling this, message must not be
* dereferenced) */
    tp_message_mixin_sent (object, message, flags, "", NULL);
}
Ejemplo n.º 3
0
void idle_text_send(GObject *obj, TpMessage *message, TpMessageSendingFlags flags, const gchar *recipient, IdleConnection *conn) {
    GError *error = NULL;
    const GHashTable *part;
    TpChannelTextMessageType type = TP_CHANNEL_TEXT_MESSAGE_TYPE_NORMAL;
    gboolean result = TRUE;
    const gchar *content_type, *text;
    guint n_parts;
    GStrv messages;
    GStrv bodies;
    gsize msg_len;
    guint i;

#define INVALID_ARGUMENT(msg, ...) \
	G_STMT_START { \
		IDLE_DEBUG (msg , ## __VA_ARGS__); \
		g_set_error (&error, TP_ERROR, TP_ERROR_INVALID_ARGUMENT, \
				msg , ## __VA_ARGS__); \
		goto failed; \
	} G_STMT_END

    g_return_if_fail (recipient != NULL);

    part = tp_message_peek (message, 0);

    if (tp_asv_lookup (part, "message-type") != NULL)
        type = tp_asv_get_uint32 (part, "message-type", &result);

    if (!result)
        INVALID_ARGUMENT ("message-type must be a 32-bit unsigned integer");

    if (type >= NUM_TP_CHANNEL_TEXT_MESSAGE_TYPES)
        INVALID_ARGUMENT ("invalid message type: %u", type);

    n_parts = tp_message_count_parts (message);

    if (n_parts != 2)
        INVALID_ARGUMENT ("message must contain exactly 1 part, not %u", (n_parts - 1));

    part = tp_message_peek (message, 1);
    content_type = tp_asv_get_string (part, "content-type");
    text = tp_asv_get_string (part, "content");

    if (tp_strdiff (content_type, "text/plain"))
        INVALID_ARGUMENT ("message must be text/plain");

    if (tp_str_empty (text))
        INVALID_ARGUMENT ("content must be a UTF-8 string");

    /* Okay, it's valid. Let's send it. */

    msg_len = idle_connection_get_max_message_length(conn);
    messages = idle_text_encode_and_split(type, recipient, text, msg_len, &bodies, &error);
    if (messages == NULL)
        goto failed;

    for(i = 0; messages[i] != NULL; i++) {
        g_assert(bodies[i] != NULL);
        idle_connection_send(conn, messages[i]);
    }

    g_strfreev(messages);
    g_strfreev(bodies);

    tp_message_mixin_sent (obj, message, flags, "", NULL);
    return;

failed:
    g_assert (error != NULL);
    tp_message_mixin_sent (obj, message, 0, NULL, error);
    g_error_free (error);
}