Пример #1
0
static
void
mms_message_finalize(
    MMSMessage* msg)
{
    MMS_VERBOSE_("%p", msg);
    g_free(msg->id);
    g_free(msg->message_id);
    g_free(msg->from);
    g_strfreev(msg->to);
    g_strfreev(msg->cc);
    g_free(msg->subject);
    g_free(msg->cls);
    g_slist_foreach(msg->parts, mms_message_part_free, msg);
    g_slist_free(msg->parts);
    if (msg->parts_dir) {
        if (!(msg->flags & MMS_MESSAGE_FLAG_KEEP_FILES)) {
            if (rmdir(msg->parts_dir) == 0) {
                MMS_VERBOSE("Deleted %s", msg->parts_dir);
            }
        }
        g_free(msg->parts_dir);
    }
    if (msg->msg_dir) {
        if (!(msg->flags & MMS_MESSAGE_FLAG_KEEP_FILES)) {
            if (rmdir(msg->msg_dir) == 0) {
                MMS_VERBOSE("Deleted %s", msg->msg_dir);
            }
        }
        g_free(msg->msg_dir);
    }
}
/**
 * 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);
}
Пример #3
0
static
void
test_http_callback(
    SoupServer* server,
    SoupMessage* msg,
    const char* path,
    GHashTable* query,
    SoupClientContext* context,
    gpointer data)
{
    char* uri = soup_uri_to_string(soup_message_get_uri (msg), FALSE);
    MMS_VERBOSE("%s %s HTTP/1.%d", msg->method, uri,
        soup_message_get_http_version(msg));
    g_free(uri);
    if (msg->method == SOUP_METHOD_CONNECT) {
        soup_message_set_status(msg, SOUP_STATUS_NOT_IMPLEMENTED);
    } else {
        TestHttp* http = data;
        if (msg->request_body->length) {
            SoupBuffer* request = soup_message_body_flatten(msg->request_body);
            if (http->req_bytes) g_bytes_unref(http->req_bytes);
            http->req_bytes = g_bytes_new_with_free_func(request->data,
                request->length, (GDestroyNotify)soup_buffer_free, request);
        }
        soup_message_set_status(msg, http->resp_status);
        soup_message_headers_set_content_type(msg->response_headers,
            http->resp_content_type ? http->resp_content_type : "text/plain",
            NULL);
        soup_message_headers_append(msg->response_headers,
            "Accept-Ranges", "bytes");
        soup_message_headers_append(msg->response_headers,
            "Connection", "close");
        if (http->resp_file) {
            soup_message_headers_set_content_length(msg->response_headers,
                g_mapped_file_get_length(http->resp_file));
            soup_message_body_append(msg->response_body, SOUP_MEMORY_TEMPORARY,
                g_mapped_file_get_contents(http->resp_file),
                g_mapped_file_get_length(http->resp_file));
        } else {
            soup_message_headers_set_content_length(msg->response_headers, 0);
        }
    }
    soup_message_body_complete(msg->request_body);
}
Пример #4
0
int main(int argc, char* argv[])
{
    int ret;
    MMSConfig config;
    const char* test_name = NULL;

    mms_lib_init(argv[0]);
    mms_lib_default_config(&config);
    mms_log_default.name = "test_read_ind";

    if (argc > 1 && !strcmp(argv[1], "-v")) {
        mms_log_default.level = MMS_LOGLEVEL_VERBOSE;
        memmove(argv + 1, argv + 2, (argc-2)*sizeof(argv[0]));
        argc--;
    } else {
        mms_log_default.level = MMS_LOGLEVEL_INFO;
        mms_task_notification_log.level = MMS_LOGLEVEL_NONE;
        mms_log_stdout_timestamp = FALSE;
    }

    if (argc == 2 && argv[1][0] != '-') {
        test_name = argv[1];
    }

    if (argc == 1 || test_name) {
        char* tmpd = g_mkdtemp(g_strdup("/tmp/test_read_ind_XXXXXX"));
        MMS_VERBOSE("Temporary directory %s", tmpd);
        config.root_dir = tmpd;
        config.idle_secs = 0;
        config.attic_enabled = TRUE;
        ret = test_run(&config, test_name);
        remove(tmpd);
        g_free(tmpd);
    } else {
        printf("Usage: test_read_ind [-v] [TEST]\n");
        ret = RET_ERR;
    }

    mms_lib_deinit();
    return ret;
}
Пример #5
0
int main(int argc, char* argv[])
{
    int ret = RET_ERR;
    gboolean debug = FALSE;
    gboolean verbose = FALSE;
    GError* error = NULL;
    GOptionContext* options;
    GOptionEntry entries[] = {
        { "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose,
          "Enable verbose output", NULL },
        { "debug", 'd', 0, G_OPTION_ARG_NONE, &debug,
          "Disable timeout for debugging", NULL },
        { NULL }
    };

    options = g_option_context_new("[TEST] - MMS read report test");
    g_option_context_add_main_entries(options, entries, NULL);
    if (g_option_context_parse(options, &argc, &argv, &error)) {
        MMSConfig config;
        char* tmpd = g_mkdtemp(g_strdup("/tmp/test_read_report_XXXXXX"));
        char* msgdir = g_strconcat(tmpd, "/msg", NULL);

        mms_lib_init(argv[0]);
        mms_lib_default_config(&config);
        config.idle_secs = 0;
        config.root_dir = tmpd;
        mms_log_default.name = "test_read_report";
        if (verbose) {
            mms_log_default.level = MMS_LOGLEVEL_VERBOSE;
        } else {
            mms_log_default.level = MMS_LOGLEVEL_INFO;
            mms_task_decode_log.level =
            mms_task_retrieve_log.level =
            mms_task_notification_log.level = MMS_LOGLEVEL_NONE;
            mms_log_stdout_timestamp = FALSE;
        }

        MMS_VERBOSE("Temporary directory %s", tmpd);
        if (argc < 2) {
            ret = test_read_report(&config, NULL, debug);
        } else {
            int i;
            for (i=1, ret = RET_OK; i<argc; i++) {
                int test_status =  test_read_report(&config, argv[i], debug);
                if (ret == RET_OK && test_status != RET_OK) ret = test_status;
            }
        }
        rmdir(msgdir);
        rmdir(tmpd);
        remove(tmpd);
        g_free(tmpd);
        g_free(msgdir);
        mms_lib_deinit();
    } else {
        fprintf(stderr, "%s\n", MMS_ERRMSG(error));
        g_error_free(error);
        ret = RET_ERR;
    }
    g_option_context_free(options);
    return ret;
}