static void test_done( MMSDispatcherDelegate* delegate, MMSDispatcher* dispatcher) { Test* test = MMS_CAST(delegate,Test,delegate); const TestDesc* desc = test->desc; const char* name = desc->name; if (test->ret == RET_OK) { const void* resp_data = NULL; gsize resp_len = 0; GBytes* reply = test_http_get_post_data(test->http); if (reply) resp_data = g_bytes_get_data(reply, &resp_len); if (resp_len > 0) { MMSPdu* pdu = g_new0(MMSPdu, 1); test->ret = RET_ERR; if (mms_message_decode(resp_data, resp_len, pdu)) { if (pdu->type != MMS_MESSAGE_TYPE_READ_REC_IND) { MMS_ERR("Unexpected PDU type %u", pdu->type); } else if (pdu->ri.rr_status != desc->rr_status) { MMS_ERR("Read status %d, expected %d", pdu->ri.rr_status, desc->rr_status); } else if (g_strcmp0(pdu->ri.to, desc->to)) { MMS_ERR("Phone number %s, expected %s", pdu->ri.to, desc->to); } else { MMS_READ_REPORT_STATUS status = mms_handler_test_read_report_status(test->handler, test->id); if (status != MMS_READ_REPORT_STATUS_OK) { MMS_ERR("Unexpected status %d", status); } else { test->ret = RET_OK; } } } else { MMS_ERR("Can't decode PDU"); } mms_message_free(pdu); } } MMS_INFO("%s: %s", (test->ret == RET_OK) ? "OK" : "FAILED", name); g_main_loop_quit(test->loop); }
static gboolean test_file( const char* file) { GError* error = NULL; char* path = g_strconcat(DATA_DIR, file, NULL); GMappedFile* map = g_mapped_file_new(path, FALSE, &error); g_free(path); if (map) { struct mms_message* msg = g_new0(struct mms_message, 1); const void* data = g_mapped_file_get_contents(map); const gsize length = g_mapped_file_get_length(map); gboolean ok = mms_message_decode(data, length, msg); g_mapped_file_unref(map); mms_message_free(msg); if (ok) { MMS_INFO("OK: %s", file); return TRUE; } MMS_ERR("Failed to decode %s", file); } else {
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); }