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; } }
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; }
static gboolean run_test( const TestDesc* test) { gboolean ok = FALSE; char** parsed = mms_parse_http_content_type(test->input); if (parsed) { if (test->output) { char* unparsed = mms_unparse_http_content_type(parsed); if (!strcmp(unparsed, test->output)) { char** p1 = parsed; char** p2 = test->parsed; ok = TRUE; while (*p1 && ok) { if (*p2) { ok = !strcmp(*p1++, *p2++); } else { ok = FALSE; break; } } if (*p2) ok = FALSE; g_free(unparsed); } } } else if (!test->output) { /* Test is expected to fail */ ok = TRUE; } g_strfreev(parsed); MMS_INFO("%s: %s", ok ? "OK" : "FAILED", test->name); return ok; }
/** * Runs the task */ static void mms_task_notification_run( MMSTask* task) { MMSTaskNotification* ind = MMS_TASK_NOTIFICATION(task); switch (ind->pdu->type) { case MMS_MESSAGE_TYPE_NOTIFICATION_IND: mms_task_notification_ind(ind); break; case MMS_MESSAGE_TYPE_DELIVERY_IND: mms_task_delivery_ind(ind); break; case MMS_MESSAGE_TYPE_READ_ORIG_IND: mms_task_read_orig_ind(ind); break; default: MMS_INFO("Ignoring MMS push PDU of type %u", ind->pdu->type); mms_task_notification_unrecornized(task_config(task), ind->push); break; } if (task->state == MMS_TASK_STATE_READY) { mms_task_set_state(task, MMS_TASK_STATE_DONE); } }
static gboolean mms_engine_start_timeout_callback( gpointer data) { MMSEngine* engine = data; MMS_ASSERT(engine->start_timeout_id); MMS_INFO("Shutting down due to inactivity..."); engine->start_timeout_id = 0; mms_engine_stop_schedule(engine); return FALSE; }
static gboolean test_timeout( gpointer data) { Test* test = data; test->timeout_id = 0; test->ret = RET_TIMEOUT; MMS_INFO("%s TIMEOUT", test->desc->name); mms_connman_test_close_connection(test->cm); mms_dispatcher_cancel(test->disp, NULL); return FALSE; }
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 void test_finish( Test* test) { const TestDesc* desc = test->desc; const char* name = desc->name; if (test->ret == RET_OK) { MMS_READ_STATUS rs; rs = mms_handler_test_read_status(test->handler, test->id); if (rs != desc->status) { test->ret = RET_ERR; MMS_ERR("%s status %d, expected %d", name, rs, desc->status); } } MMS_INFO("%s: %s", (test->ret == RET_OK) ? "OK" : "FAILED", name); mms_handler_test_reset(test->handler); 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 test_finish( Test* test) { const TestDesc* desc = test->desc; const char* name = desc->name; if (test->ret == RET_OK) { MMS_SEND_STATE state; const char* details; state = mms_handler_test_send_state(test->handler, test->id); details = mms_handler_test_send_details(test->handler, test->id); if (state != desc->expected_state) { test->ret = RET_ERR; MMS_ERR("%s state %d, expected %d", name, state, desc->expected_state); } else if (g_strcmp0(details, desc->details)) { test->ret = RET_ERR; MMS_ERR("%s details '%s', expected '%s'", name, details, desc->details); } else if (desc->msgid) { const char* msgid = mms_handler_test_send_msgid(test->handler, test->id); if (!msgid || strcmp(msgid, desc->msgid)) { test->ret = RET_ERR; MMS_ERR("%s msgid %s, expected %s", name, msgid, desc->msgid); } else if (msgid && !desc->msgid) { test->ret = RET_ERR; MMS_ERR("%s msgid is not expected", name); } } } MMS_INFO("%s: %s", (test->ret == RET_OK) ? "OK" : "FAILED", name); mms_handler_test_reset(test->handler); g_main_loop_quit(test->loop); }
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); }