Example #1
0
static
gboolean
test_init(
    Test* test,
    const MMSConfig* config,
    const TestDesc* desc)
{
    gboolean ok = FALSE;
    GError* error = NULL;
    const char* dir = desc->name;
    char* ni = g_strconcat(DATA_DIR, dir, "/", desc->ind_file, NULL);
    memset(test, 0, sizeof(*test));
    test->config = config;
    test->notification_ind = g_mapped_file_new(ni, FALSE, &error);
    if (test->notification_ind) {
        test->desc = desc;
        test->cm = mms_connman_test_new();
        test->handler = mms_handler_test_new();
        test->disp = mms_dispatcher_new(config, test->cm, test->handler);
        test->loop = g_main_loop_new(NULL, FALSE);
        test->timeout_id = g_timeout_add_seconds(10, test_timeout, test);
        test->delegate.fn_done = test_done;
        mms_dispatcher_set_delegate(test->disp, &test->delegate);
        test->id = g_strdup(mms_handler_test_send_new(test->handler, "IMSI"));
        mms_handler_message_sent(test->handler, test->id, desc->mmsid);
        test->ret = RET_ERR;
        ok = TRUE;
    } else {
        MMS_ERR("%s", MMS_ERRMSG(error));
        g_error_free(error);
    }
    g_free(ni);
    return ok;
}
Example #2
0
static
void
mms_task_send_done(
    MMSTaskHttp* http,
    const char* path,
    SoupStatus status)
{
    MMSPdu* pdu = NULL;
    MMS_SEND_STATE state = MMS_SEND_STATE_SEND_ERROR;
    const char* msgid = NULL;
    const char* details = NULL;
    if (SOUP_STATUS_IS_SUCCESSFUL(status)) {
        /* Decode the result */
        GError* error = NULL;
        GMappedFile* map = g_mapped_file_new(path, FALSE, &error);
        if (map) {
            const void* data = g_mapped_file_get_contents(map);
            const gsize len = g_mapped_file_get_length(map);
            pdu = g_new0(MMSPdu, 1);
            if (mms_message_decode(data, len, pdu)) {
                if (pdu &&
                    pdu->type == MMS_MESSAGE_TYPE_SEND_CONF) {
                    if (pdu->sc.rsp_status == MMS_MESSAGE_RSP_STATUS_OK) {
                        if (pdu->sc.msgid && pdu->sc.msgid[0]) {
                            msgid = pdu->sc.msgid;
                            MMS_INFO("Message ID %s", pdu->sc.msgid);
                        } else {
                            MMS_ERR("Missing Message-ID");
                        }
                    } else {
                        MMS_ERR("MMSC responded with %u", pdu->sc.rsp_status);
                        details = pdu->sc.rsp_text;
                        switch (pdu->sc.rsp_status) {
                        case MMS_MESSAGE_RSP_STATUS_ERR_SERVICE_DENIED:
                        case MMS_MESSAGE_RSP_STATUS_ERR_CONTENT_NOT_ACCEPTED:
                        case MMS_MESSAGE_RSP_STATUS_ERR_UNSUPPORTED_MESSAGE:
                        case MMS_MESSAGE_RSP_STATUS_ERR_PERM_SERVICE_DENIED:
                        case MMS_MESSAGE_RSP_STATUS_ERR_PERM_LACK_OF_PREPAID:
                        case MMS_MESSAGE_RSP_STATUS_ERR_PERM_CONTENT_NOT_ACCEPTED:
                            state = MMS_SEND_STATE_REFUSED;
                            break;
                        default:
                            break;
                        }
                    }
                } else {
                    MMS_ERR("Unexpected response from MMSC");
                }
            } else {
                MMS_ERR("Failed to parse MMSC response");
            }
            g_mapped_file_unref(map);
        } else {
            MMS_ERR("%s", MMS_ERRMSG(error));
            g_error_free(error);
        }
    }
    if (msgid) {
        mms_handler_message_sent(http->task.handler, http->task.id, msgid);
    } else {
        mms_handler_message_send_state_changed(http->task.handler,
            http->task.id, state, details);
    }
    if (pdu) mms_message_free(pdu);
}