static int test_read_report( const MMSConfig* config, const char* name, gboolean debug) { int i, ret; if (name) { const TestDesc* found = NULL; for (i=0, ret = RET_ERR; i<G_N_ELEMENTS(tests); i++) { const TestDesc* test = tests + i; if (!strcmp(test->name, name)) { ret = test_read_report_once(config, test, debug); found = test; break; } } if (!found) MMS_ERR("No such test: %s", name); } else { for (i=0, ret = RET_OK; i<G_N_ELEMENTS(tests); i++) { int status = test_read_report_once(config, tests + i, debug); if (ret == RET_OK && status != RET_OK) ret = status; } } return ret; }
static int test_run( const MMSConfig* config, const char* name) { int i, ret; if (name) { const TestDesc* found = NULL; for (i=0, ret = RET_ERR; i<G_N_ELEMENTS(read_tests); i++) { const TestDesc* test = read_tests + i; if (!strcmp(test->name, name)) { ret = test_run_one(config, test); found = test; break; } } if (!found) MMS_ERR("No such test: %s", name); } else { for (i=0, ret = RET_OK; i<G_N_ELEMENTS(read_tests); i++) { int test_status = test_run_one(config, read_tests + i); if (ret == RET_OK && test_status != RET_OK) ret = test_status; } } return ret; }
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 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; }
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_init( Test* test, MMSConfig* config, const TestDesc* desc) { gboolean ok = FALSE; memset(test, 0, sizeof(*test)); if (desc->resp_file) { GError* error = NULL; char* f = g_strconcat(DATA_DIR, desc->name, "/", desc->resp_file, NULL); test->resp_file = g_mapped_file_new(f, FALSE, &error); if (!test->resp_file) { MMS_ERR("%s", MMS_ERRMSG(error)); g_error_free(error); } g_free(f); } if (!desc->resp_file || test->resp_file) { int i; guint port; MMSSettings* settings = mms_settings_default_new(config); test->parts = g_new0(MMSAttachmentInfo, desc->nparts); test->files = g_new0(char*, desc->nparts); for (i=0; i<desc->nparts; i++) { test->files[i] = g_strconcat(DATA_DIR, desc->name, "/", desc->parts[i].file_name, NULL); test->parts[i] = desc->parts[i]; test->parts[i].file_name = test->files[i]; } test->config = config; test->desc = desc; test->cm = mms_connman_test_new(); test->handler = mms_handler_test_new(); test->disp = mms_dispatcher_new(settings, test->cm, test->handler); test->loop = g_main_loop_new(NULL, FALSE); test->delegate.fn_done = test_done; mms_dispatcher_set_delegate(test->disp, &test->delegate); test->http = test_http_new(test->resp_file, desc->resp_type, desc->resp_status); port = test_http_get_port(test->http); mms_connman_test_set_port(test->cm, port, TRUE); if (desc->flags & TEST_FLAG_CANCEL) { mms_connman_test_set_connect_callback(test->cm, test_cancel, test); } if (desc->size_limit) { MMSSettingsSimData sim_settings; mms_settings_sim_data_default(&sim_settings); sim_settings.size_limit = desc->size_limit; mms_settings_set_sim_defaults(settings, NULL); mms_settings_set_sim_defaults(settings, &sim_settings); } mms_settings_unref(settings); test->ret = RET_ERR; ok = TRUE; }
/** * Handles response from the MMS handler. Non-empty message id means * that we start download the message immediately, empty string means that * download is postponed, NULL id means that an error has occured. */ static void mms_task_notification_done( MMSHandlerMessageNotifyCall* notify, const char* id, void* param) { MMSTaskNotification* ind = MMS_TASK_NOTIFICATION(param); MMSTask* task = &ind->task; MMS_ASSERT(ind->notify == notify); ind->notify = NULL; if (id) { if (id[0]) { MMS_DEBUG(" Database id: %s", id); if (task->id) { char* olddir = mms_task_dir(task); char* file = g_strconcat(olddir, "/" MMS_NOTIFICATION_IND_FILE, NULL); /* Replace fake id with the real one */ g_free(task->id); task->id = g_strdup(id); if (task_config(task)->keep_temp_files) { /* Move file to the new place */ char* newdir = mms_task_dir(task); if (rename(olddir, newdir) == 0) { MMS_VERBOSE("Moved %s to %s", file, newdir); } else { MMS_ERR("Failed to rename %s to %s: %s", olddir, newdir, strerror(errno)); } g_free(newdir); } else { /* Remove temporary directory and file */ remove(file); remove(olddir); } g_free(file); g_free(olddir); } else { task->id = g_strdup(id); } /* Schedule the download task */ if (!mms_task_queue_and_unref(task->delegate, mms_task_retrieve_new(task->settings, task->handler, task->id, task->imsi, ind->pdu, NULL))) { mms_handler_message_receive_state_changed(task->handler, id, MMS_RECEIVE_STATE_DOWNLOAD_ERROR); } } mms_task_set_state(task, MMS_TASK_STATE_DONE); } else if (!mms_task_retry(task)) { mms_task_notification_reject(ind); } mms_task_unref(task); }
MMSOfonoManager* mms_ofono_manager_new( GDBusConnection* bus) { GError* error = NULL; OrgOfonoManager* proxy = org_ofono_manager_proxy_new_sync(bus, G_DBUS_PROXY_FLAGS_NONE, OFONO_SERVICE, "/", NULL, &error); if (proxy) { GVariant* modems = NULL; if (org_ofono_manager_call_get_modems_sync(proxy, &modems, NULL, &error)) { MMSOfonoManager* ofono = g_new0(MMSOfonoManager, 1); ofono->proxy = proxy; g_object_ref(ofono->bus = bus); ofono->modems = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, mms_ofono_manager_hash_remove_modem); /* Subscribe for ModemAdded/Removed notifications */ ofono->modem_added_signal_id = g_signal_connect( proxy, "modem-added", G_CALLBACK(mms_ofono_manager_modem_added), ofono); ofono->modem_removed_signal_id = g_signal_connect( proxy, "modem-removed", G_CALLBACK(mms_ofono_manager_modem_removed), ofono); mms_ofono_manager_set_modems(ofono, modems); g_variant_unref(modems); return ofono; } else { MMS_ERR("Can't get list of modems: %s", MMS_ERRMSG(error)); g_error_free(error); } g_object_unref(proxy); } else { MMS_ERR("%s", MMS_ERRMSG(error)); g_error_free(error); } return NULL; }
static void mms_task_publish_done( MMSHandlerMessageReceivedCall* call, MMSMessage* msg, gboolean ok, void* param) { MMSTaskPublish* pub = MMS_TASK_PUBLISH(param); if (ok) { MMS_DEBUG("Done"); mms_task_set_state(&pub->task, MMS_TASK_STATE_DONE); } else if (mms_task_retry(&pub->task)) { MMS_ERR("Failed to publish the message, will retry later..."); } else { MMS_ERR("Failed to publish the message"); } mms_task_unref(&pub->task); }
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 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); }
/* 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; }
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); }