Ejemplo n.º 1
0
/* org.nemomobile.MmsEngine.sendReadReport */
static
gboolean
mms_engine_handle_send_read_report(
    OrgNemomobileMmsEngine* proxy,
    GDBusMethodInvocation* call,
    int database_id,
    const char* imsi,
    const char* message_id,
    const char* to,
    int read_status, /*  0: Read  1: Deleted without reading */
    MMSEngine* engine)
{
    GError* error = NULL;
    char* id = g_strdup_printf("%d", database_id);
    MMS_DEBUG_("%s %s %s %s %d", id, imsi, message_id, to, read_status);
    if (mms_dispatcher_send_read_report(engine->dispatcher, id, imsi,
        message_id, to, (read_status == 1) ? MMS_READ_STATUS_DELETED :
        MMS_READ_STATUS_READ, &error)) {
        if (mms_dispatcher_start(engine->dispatcher)) {
            mms_engine_start_timeout_cancel(engine);
        }
        org_nemomobile_mms_engine_complete_send_read_report(proxy, call);
    } else {
        g_dbus_method_invocation_return_error(call, G_DBUS_ERROR,
            G_DBUS_ERROR_FAILED, "%s", MMS_ERRMSG(error));
        g_error_free(error);
    }
    g_free(id);
    return TRUE;
}
Ejemplo n.º 2
0
static
int
test_read_report_once(
    const MMSConfig* config,
    const TestDesc* desc,
    gboolean debug)
{
    Test test;
    GError* error = NULL;
    test_init(&test, config, desc, debug);
    if (mms_dispatcher_send_read_report(test.disp, test.id, TEST_IMSI,
        "MessageID", desc->phone, desc->status, &error)) {
        if (mms_dispatcher_start(test.disp)) {
            test.ret = RET_OK;
            g_main_loop_run(test.loop);
        } else {
            MMS_INFO("FAILED");
        }
    } else {
        g_error_free(error);
        MMS_INFO("FAILED");
    }
    test_finalize(&test);
    return test.ret;
}
Ejemplo n.º 3
0
static
int
test_run_one(
    const MMSConfig* config,
    const TestDesc* desc)
{
    Test test;
    if (test_init(&test, config, desc)) {
        GError* error = NULL;
        GBytes* push = g_bytes_new_static(
            g_mapped_file_get_contents(test.notification_ind),
            g_mapped_file_get_length(test.notification_ind));
        if (mms_dispatcher_handle_push(test.disp, "TestConnection",
            push, &error)) {
            if (mms_dispatcher_start(test.disp)) {
                test.ret = RET_OK;
                g_main_loop_run(test.loop);
            } else {
                MMS_INFO("%s FAILED", desc->name);
            }
        } else {
            MMS_ERR("%s", MMS_ERRMSG(error));
            MMS_INFO("%s FAILED", desc->name);
            g_error_free(error);
        }
        g_bytes_unref(push);
        test_finalize(&test);
        return test.ret;
    } else {
        return RET_ERR;
    }
}
Ejemplo n.º 4
0
/* org.nemomobile.MmsEngine.pushNotify */
static
gboolean
mms_engine_handle_push_notify(
    OrgNemomobileMmsEngine* proxy,
    GDBusMethodInvocation* call,
    const char* imsi,
    const char* type,
    GVariant* data,
    MMSEngine* engine)
{
    gsize len = 0;
    const guint8* bytes = g_variant_get_fixed_array(data, &len, 1);
    MMS_DEBUG("Received %u bytes from %s", (guint)len, imsi);
    if (!type || g_ascii_strcasecmp(type, MMS_CONTENT_TYPE)) {
        MMS_ERR("Unsupported content type %s", type);
        g_dbus_method_invocation_return_error(call, G_DBUS_ERROR,
            G_DBUS_ERROR_FAILED, "Unsupported content type");
    } else if (!imsi || !imsi[0]) {
        MMS_ERR_("IMSI is missing");
        g_dbus_method_invocation_return_error(call, G_DBUS_ERROR,
            G_DBUS_ERROR_FAILED, "IMSI is missing");
    } else if (!bytes || !len) {
        MMS_ERR_("No data provided");
        g_dbus_method_invocation_return_error(call, G_DBUS_ERROR,
            G_DBUS_ERROR_FAILED, "No data provided");
    } else {
        GError* err = NULL;
        GBytes* msg = g_bytes_new(bytes, len);
        if (mms_dispatcher_handle_push(engine->dispatcher, imsi, msg, &err)) {
            if (mms_dispatcher_start(engine->dispatcher)) {
                mms_engine_start_timeout_cancel(engine);
            }
            org_nemomobile_mms_engine_complete_push(proxy, call);
        } else {
            g_dbus_method_invocation_return_error(call, G_DBUS_ERROR,
                G_DBUS_ERROR_FAILED, "%s", MMS_ERRMSG(err));
            g_error_free(err);
        }
        g_bytes_unref(msg);
    }
    return TRUE;
}
Ejemplo n.º 5
0
/* org.nemomobile.MmsEngine.receiveMessage */
static
gboolean
mms_engine_handle_receive_message(
    OrgNemomobileMmsEngine* proxy,
    GDBusMethodInvocation* call,
    int database_id,
    const char* imsi,
    gboolean automatic,
    GVariant* data,
    MMSEngine* engine)
{
    gsize len = 0;
    const guint8* bytes = g_variant_get_fixed_array(data, &len, 1);
    MMS_DEBUG("Processing push %u bytes from %s", (guint)len, imsi);
    if (imsi && bytes && len) {
        char* id = g_strdup_printf("%d", database_id);
        GBytes* push = g_bytes_new(bytes, len);
        GError* error = NULL;
        if (mms_dispatcher_receive_message(engine->dispatcher, id, imsi,
            automatic, push, &error)) {
            if (mms_dispatcher_start(engine->dispatcher)) {
                mms_engine_start_timeout_cancel(engine);
            }
            org_nemomobile_mms_engine_complete_receive_message(proxy, call);
        } else {
            g_dbus_method_invocation_return_error(call, G_DBUS_ERROR,
                G_DBUS_ERROR_FAILED, "%s", MMS_ERRMSG(error));
            g_error_free(error);
        }
        g_bytes_unref(push);
        g_free(id);
    } else {
        g_dbus_method_invocation_return_error(call, G_DBUS_ERROR,
            G_DBUS_ERROR_FAILED, "Invalid parameters");
    }
    return TRUE;
}
Ejemplo n.º 6
0
/* org.nemomobile.MmsEngine.sendMessage */
static
gboolean
mms_engine_handle_send_message(
    OrgNemomobileMmsEngine* proxy,
    GDBusMethodInvocation* call,
    int database_id,
    const char* imsi_to,
    const char* const* to,
    const char* const* cc,
    const char* const* bcc,
    const char* subject,
    guint flags,
    GVariant* attachments,
    MMSEngine* engine)
{
    if (to && *to) {
        unsigned int i;
        char* to_list = g_strjoinv(",", (char**)to);
        char* cc_list = NULL;
        char* bcc_list = NULL;
        char* id = NULL;
        char* imsi;
        MMSAttachmentInfo* parts;
        GArray* info = g_array_sized_new(FALSE, FALSE, sizeof(*parts), 0);
        GError* error = NULL;

        /* Extract attachment info */
        char* fn = NULL;
        char* ct = NULL;
        char* cid = NULL;
        GVariantIter* iter = NULL;
        g_variant_get(attachments, "a(sss)", &iter);
        while (g_variant_iter_loop(iter, "(sss)", &fn, &ct, &cid)) {
            MMSAttachmentInfo part;
            part.file_name = g_strdup(fn);
            part.content_type = g_strdup(ct);
            part.content_id = g_strdup(cid);
            g_array_append_vals(info, &part, 1);
        }

        /* Convert address lists into comma-separated strings
         * expected by mms_dispatcher_send_message and mms_codec */
        if (cc && *cc) cc_list = g_strjoinv(",", (char**)cc);
        if (bcc && *bcc) bcc_list = g_strjoinv(",", (char**)bcc);
        if (database_id > 0) id = g_strdup_printf("%u", database_id);

        /* Queue the message */
        parts = (void*)info->data;
        imsi = mms_dispatcher_send_message(engine->dispatcher, id,
            imsi_to, to_list, cc_list, bcc_list, subject, flags, parts,
            info->len, &error);
        if (imsi) {
            if (mms_dispatcher_start(engine->dispatcher)) {
                mms_engine_start_timeout_cancel(engine);
            }
            org_nemomobile_mms_engine_complete_send_message(proxy, call, imsi);
            g_free(imsi);
        } else {
            g_dbus_method_invocation_return_error(call, G_DBUS_ERROR,
                G_DBUS_ERROR_FAILED, "%s", MMS_ERRMSG(error));
            g_error_free(error);
        }

        for (i=0; i<info->len; i++) {
            g_free((void*)parts[i].file_name);
            g_free((void*)parts[i].content_type);
            g_free((void*)parts[i].content_id);
        }

        g_free(to_list);
        g_free(cc_list);
        g_free(bcc_list);
        g_free(id);
        g_array_unref(info);
        g_variant_iter_free(iter);
    } else {
        g_dbus_method_invocation_return_error(call, G_DBUS_ERROR,
            G_DBUS_ERROR_FAILED, "Missing recipient");
    }
    return TRUE;
}