diff --git a/mms-engine/main.c b/mms-engine/main.c index 947029f..d086370 100644 --- a/mms-engine/main.c +++ b/mms-engine/main.c @@ -19,7 +19,7 @@ #include "mms_ofono_log.h" #include "mms_lib_log.h" #include "mms_lib_util.h" -#include "mms_dispatcher.h" +#include "mms_settings.h" #define RET_OK (0) #define RET_ERR (1) @@ -27,10 +27,11 @@ /* Options configurable from the command line */ typedef struct mms_app_options { GBusType bus_type; - gboolean keep_running; + int flags; char* dir; char* user_agent; MMSConfig config; + MMSSettingsSimData settings; } MMSAppOptions; /* All known log modules */ @@ -161,26 +162,18 @@ mms_app_parse_options( #ifdef MMS_ENGINE_VERSION gboolean print_version = FALSE; #endif - gint size_limit_kb = opt->config.size_limit/1024; - gdouble megapixels = opt->config.max_pixels / 1000000.0; + gboolean keep_running = FALSE; + gint size_limit_kb = -1; + gdouble megapixels = -1; char* root_dir_help = g_strdup_printf( "Root directory for MMS files [%s]", opt->config.root_dir); - char* user_agent_help = g_strdup_printf( - "User-Agent [%s]", - opt->config.user_agent); char* retry_secs_help = g_strdup_printf( "Retry period in seconds [%d]", opt->config.retry_secs); char* idle_secs_help = g_strdup_printf( "Inactivity timeout in seconds [%d]", opt->config.idle_secs); - char* size_limit_help = g_strdup_printf( - "Maximum size for outgoing messages [%d]", - size_limit_kb); - char* megapixels_help = g_strdup_printf( - "Maximum pixel count for outgoing images [%.1f]", - megapixels); char* description = mms_log_description(mms_app_log_modules, G_N_ELEMENTS(mms_app_log_modules)); @@ -195,12 +188,12 @@ mms_app_parse_options( { "idle-secs", 'i', 0, G_OPTION_ARG_INT, &opt->config.idle_secs, idle_secs_help, "SEC" }, { "size-limit", 's', 0, G_OPTION_ARG_INT, - &size_limit_kb, size_limit_help, "KB" }, + &size_limit_kb, "Maximum size for outgoing messages", "KB" }, { "pix-limit", 'p', 0, G_OPTION_ARG_DOUBLE, - &megapixels, megapixels_help, "MPIX" }, + &megapixels, "Maximum pixel count for outgoing images", "MPIX" }, { "user-agent", 'u', 0, G_OPTION_ARG_STRING, - &opt->user_agent, user_agent_help, "STRING" }, - { "keep-running", 'k', 0, G_OPTION_ARG_NONE, &opt->keep_running, + &opt->user_agent, "User-Agent header", "STRING" }, + { "keep-running", 'k', 0, G_OPTION_ARG_NONE, &keep_running, "Keep running after everything is done", NULL }, { "keep-temp-files", 't', 0, G_OPTION_ARG_NONE, &opt->config.keep_temp_files, @@ -228,37 +221,41 @@ mms_app_parse_options( ok = g_option_context_parse(options, &argc, &argv, &error); g_option_context_free(options); g_free(root_dir_help); - g_free(user_agent_help); g_free(retry_secs_help); g_free(idle_secs_help); - g_free(size_limit_help); - g_free(megapixels_help); g_free(description); #ifdef MMS_ENGINE_VERSION # define MMS_STRING__(x) #x # define MMS_STRING_(x) MMS_STRING__(x) +# define MMS_VERVION_STRING MMS_STRING_(MMS_ENGINE_VERSION) if (print_version) { - printf("MMS engine %s\n", MMS_STRING_(MMS_ENGINE_VERSION)); + printf("MMS engine %s\n", MMS_VERVION_STRING); *result = RET_OK; return FALSE; } else #endif if (ok) { +#ifdef MMS_ENGINE_VERSION + MMS_INFO("Version %s starting", MMS_VERVION_STRING); +#else MMS_INFO("Starting"); +#endif if (size_limit_kb >= 0) { - opt->config.size_limit = size_limit_kb * 1024; - } else { - opt->config.size_limit = 0; + opt->settings.size_limit = size_limit_kb * 1024; + opt->flags |= MMS_ENGINE_FLAG_OVERRIDE_SIZE_LIMIT; } if (megapixels >= 0) { - opt->config.max_pixels = (int)(megapixels*1000)*1000; - } else { - opt->config.max_pixels = 0; + opt->settings.max_pixels = (int)(megapixels*1000)*1000; + opt->flags |= MMS_ENGINE_FLAG_OVERRIDE_MAX_PIXELS; + } + if (opt->user_agent) { + opt->settings.user_agent = opt->user_agent; + opt->flags |= MMS_ENGINE_FLAG_OVERRIDE_USER_AGENT; } if (opt->dir) opt->config.root_dir = opt->dir; - if (opt->user_agent) opt->config.user_agent = opt->user_agent; + if (keep_running) opt->flags |= MMS_ENGINE_FLAG_KEEP_RUNNING; if (session_bus) { MMS_DEBUG("Attaching to session bus"); opt->bus_type = G_BUS_TYPE_SESSION; @@ -283,13 +280,12 @@ int main(int argc, char* argv[]) mms_lib_init(argv[0]); mms_log_default.name = MMS_APP_LOG_PREFIX; mms_lib_default_config(&opt.config); + mms_settings_sim_data_default(&opt.settings); if (mms_app_parse_options(&opt, argc, argv, &result)) { MMSEngine* engine; - unsigned int engine_flags = 0; - if (opt.keep_running) engine_flags |= MMS_ENGINE_FLAG_KEEP_RUNNING; /* Create engine instance. This may fail */ - engine = mms_engine_new(&opt.config, engine_flags, + engine = mms_engine_new(&opt.config, &opt.settings, opt.flags, mms_app_log_modules, G_N_ELEMENTS(mms_app_log_modules)); if (engine) { guint name_id; diff --git a/mms-engine/mms_engine.c b/mms-engine/mms_engine.c index 3198be8..88938a9 100644 --- a/mms-engine/mms_engine.c +++ b/mms-engine/mms_engine.c @@ -14,6 +14,7 @@ #include "mms_engine.h" #include "mms_dispatcher.h" +#include "mms_settings.h" #include "mms_lib_util.h" #include "mms_ofono_connman.h" #include "mms_handler_dbus.h" @@ -54,9 +55,9 @@ struct mms_engine { typedef GObjectClass MMSEngineClass; G_DEFINE_TYPE(MMSEngine, mms_engine, G_TYPE_OBJECT); -#define MMS_ENGINE_TYPE (mms_engine_get_type()) +#define MMS_TYPE_ENGINE (mms_engine_get_type()) #define MMS_ENGINE(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),\ - MMS_ENGINE_TYPE, MMSEngine)) + MMS_TYPE_ENGINE, MMSEngine)) inline static MMSEngine* mms_engine_from_dispatcher_delegate(MMSDispatcherDelegate* delegate) @@ -408,15 +409,31 @@ mms_engine_handle_set_log_type( MMSEngine* mms_engine_new( const MMSConfig* config, + const MMSSettingsSimData* override, unsigned int flags, MMSLogModule* log_modules[], int log_count) { MMSConnMan* cm = mms_connman_ofono_new(); if (cm) { - MMSEngine* mms = g_object_new(MMS_ENGINE_TYPE, NULL); + MMSEngine* mms = g_object_new(MMS_TYPE_ENGINE, NULL); MMSHandler* handler = mms_handler_dbus_new(); - mms->dispatcher = mms_dispatcher_new(config, cm, handler); + MMSSettings* settings = mms_settings_default_new(config); + + if (flags & MMS_ENGINE_FLAG_OVERRIDE_USER_AGENT) { + g_free(settings->sim_defaults.user_agent); + settings->sim_defaults.data.user_agent = + settings->sim_defaults.user_agent = g_strdup(override->user_agent); + } + if (flags & MMS_ENGINE_FLAG_OVERRIDE_SIZE_LIMIT) { + settings->sim_defaults.data.size_limit = override->size_limit; + } + if (flags & MMS_ENGINE_FLAG_OVERRIDE_MAX_PIXELS) { + settings->sim_defaults.data.max_pixels = override->max_pixels; + } + + mms->dispatcher = mms_dispatcher_new(settings, cm, handler); + mms_settings_unref(settings); mms_connman_unref(cm); mms_handler_unref(handler); mms_dispatcher_set_delegate(mms->dispatcher, diff --git a/mms-engine/mms_engine.h b/mms-engine/mms_engine.h index 1c62e0b..27dd2bf 100644 --- a/mms-engine/mms_engine.h +++ b/mms-engine/mms_engine.h @@ -15,22 +15,25 @@ #ifndef JOLLA_MMS_ENGINE_H #define JOLLA_MMS_ENGINE_H -#include #include -#include "mms_lib_types.h" +#include "mms_settings.h" #define MMS_APP_LOG_PREFIX "mms-engine" #define MMS_ENGINE_SERVICE "org.nemomobile.MmsEngine" #define MMS_ENGINE_PATH "/" -#define MMS_ENGINE_FLAG_KEEP_RUNNING (0x01) +#define MMS_ENGINE_FLAG_KEEP_RUNNING (0x01) +#define MMS_ENGINE_FLAG_OVERRIDE_USER_AGENT (0x02) +#define MMS_ENGINE_FLAG_OVERRIDE_SIZE_LIMIT (0x04) +#define MMS_ENGINE_FLAG_OVERRIDE_MAX_PIXELS (0x08) typedef struct mms_engine MMSEngine; MMSEngine* mms_engine_new( const MMSConfig* config, + const MMSSettingsSimData* settings, unsigned int flags, MMSLogModule* log_modules[], int log_count); diff --git a/mms-lib/Makefile b/mms-lib/Makefile index c83fc9d..8a88250 100644 --- a/mms-lib/Makefile +++ b/mms-lib/Makefile @@ -24,12 +24,31 @@ all: debug release # Sources # -SRC = mms_attachment.c mms_attachment_image.c mms_attachment_jpeg.c \ - mms_codec.c mms_connection.c mms_connman.c mms_dispatcher.c mms_error.c \ - mms_handler.c mms_lib_util.c mms_file_util.c mms_log.c mms_message.c \ - mms_task.c mms_task_ack.c mms_task_decode.c mms_task_encode.c \ - mms_task_http.c mms_task_notification.c mms_task_notifyresp.c \ - mms_task_publish.c mms_task_read.c mms_task_retrieve.c mms_task_send.c \ +SRC = \ + mms_attachment.c \ + mms_attachment_image.c \ + mms_attachment_jpeg.c \ + mms_codec.c \ + mms_connection.c \ + mms_connman.c \ + mms_dispatcher.c \ + mms_error.c \ + mms_handler.c \ + mms_lib_util.c \ + mms_file_util.c \ + mms_log.c mms_message.c \ + mms_settings.c \ + mms_task.c \ + mms_task_ack.c \ + mms_task_decode.c \ + mms_task_encode.c \ + mms_task_http.c \ + mms_task_notification.c \ + mms_task_notifyresp.c \ + mms_task_publish.c \ + mms_task_read.c \ + mms_task_retrieve.c \ + mms_task_send.c \ mms_util.c ifeq ($(MMS_RESIZE),Qt) diff --git a/mms-lib/include/mms_dispatcher.h b/mms-lib/include/mms_dispatcher.h index e36e837..496ef0d 100644 --- a/mms-lib/include/mms_dispatcher.h +++ b/mms-lib/include/mms_dispatcher.h @@ -28,7 +28,7 @@ struct mms_dispatcher_delegate { MMSDispatcher* mms_dispatcher_new( - const MMSConfig* config, + MMSSettings* settings, MMSConnMan* cm, MMSHandler* handler); diff --git a/mms-lib/include/mms_lib_types.h b/mms-lib/include/mms_lib_types.h index d230827..34e4fc0 100644 --- a/mms-lib/include/mms_lib_types.h +++ b/mms-lib/include/mms_lib_types.h @@ -43,19 +43,6 @@ # define HAVE_REALPATH #endif -/* Static configuration, chosen at startup and never changing since then */ -typedef struct mms_config { - const char* root_dir; /* Root directory for storing MMS files */ - const char* user_agent; /* User agent string */ - int retry_secs; /* Retry timeout in seconds */ - int idle_secs; /* Idle timeout */ - gsize size_limit; /* Maximum size of m-Send.req PDU */ - guint max_pixels; /* Pixel limit for outbound images */ - gboolean keep_temp_files; /* Keep temporary files around */ - gboolean attic_enabled; /* Keep unrecognized push message in attic */ - gboolean send_dr; /* Allow sending delivery reports */ -} MMSConfig; - /* Attachment information */ typedef struct mms_attachment_info { const char* file_name; /* Full path name */ @@ -64,6 +51,9 @@ typedef struct mms_attachment_info { } MMSAttachmentInfo; /* Types */ +typedef struct mms_config MMSConfig; +typedef struct mms_settings MMSSettings; +typedef struct mms_settings_sim_data MMSSettingsSimData; typedef struct mms_handler MMSHandler; typedef struct mms_connman MMSConnMan; typedef struct mms_log_module MMSLogModule; diff --git a/mms-lib/include/mms_settings.h b/mms-lib/include/mms_settings.h new file mode 100644 index 0000000..1caadc9 --- /dev/null +++ b/mms-lib/include/mms_settings.h @@ -0,0 +1,111 @@ +/* + * Copyright (C) 2014 Jolla Ltd. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + */ + +#ifndef JOLLA_MMS_SETTINGS_H +#define JOLLA_MMS_SETTINGS_H + +#include "mms_lib_types.h" + +/* Static configuration, chosen at startup and never changing since then */ +struct mms_config { + const char* root_dir; /* Root directory for storing MMS files */ + int retry_secs; /* Retry timeout in seconds */ + int idle_secs; /* Idle timeout */ + gboolean keep_temp_files; /* Keep temporary files around */ + gboolean attic_enabled; /* Keep unrecognized push message in attic */ +}; + +/* Persistent mutable per-SIM settings */ +struct mms_settings_sim_data { + const char* user_agent; /* User agent string */ + unsigned int size_limit; /* Maximum size of m-Send.req PDU */ + unsigned int max_pixels; /* Pixel limit for outbound images */ + gboolean allow_dr; /* Allow sending delivery reports */ +}; + +/* Copy of per-SIM settings */ +typedef struct mms_settings_sim_data_copy { + MMSSettingsSimData data; /* Settings data */ + char* user_agent; /* Allocated copy of user_agent */ +} MMSSettingsSimDataCopy; + +/* Instance */ +struct mms_settings { + GObject object; + const MMSConfig* config; + MMSSettingsSimDataCopy sim_defaults; +}; + +/* Class */ +typedef struct mms_settings_class { + GObjectClass parent; + const MMSSettingsSimData* (*fn_get_sim_data)( + MMSSettings* settings, + const char* imsi); +} MMSSettingsClass; + +/* Default values */ +#define MMS_SETTINGS_DEFAULT_USER_AGENT "Mozilla/5.0 (Sailfish; Jolla)" +#define MMS_SETTINGS_DEFAULT_SIZE_LIMIT (300*1024) +#define MMS_SETTINGS_DEFAULT_MAX_PIXELS (3000000) +#define MMS_SETTINGS_DEFAULT_ALLOW_DR TRUE + +GType mms_settings_get_type(void); +#define MMS_TYPE_SETTINGS (mms_settings_get_type()) +#define MMS_SETTINGS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), \ + MMS_TYPE_SETTINGS, MMSSettingsClass)) + +MMSSettings* +mms_settings_ref( + MMSSettings* settings); + +void +mms_settings_unref( + MMSSettings* settings); + +MMSSettings* +mms_settings_default_new( + const MMSConfig* config); + +const MMSSettingsSimData* +mms_settings_get_sim_data( + MMSSettings* settings, + const char* imsi); + +void +mms_settings_sim_data_default( + MMSSettingsSimData* data); + +void +mms_settings_set_sim_defaults( + MMSSettings* settings, + const MMSSettingsSimData* data); + +MMSSettingsSimDataCopy* +mms_settings_sim_data_copy_new( + const MMSSettingsSimData* data); + +void +mms_settings_sim_data_copy_free( + MMSSettingsSimDataCopy* data); + +#endif /* JOLLA_MMS_SETTINGS_H */ + +/* + * Local Variables: + * mode: C + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/mms-lib/mms-lib.pro b/mms-lib/mms-lib.pro index 826a0b0..d611627 100644 --- a/mms-lib/mms-lib.pro +++ b/mms-lib/mms-lib.pro @@ -39,6 +39,7 @@ SOURCES += \ src/mms_message.c \ src/mms_lib_util.c \ src/mms_log.c \ + src/mms_settings.c \ src/mms_task.c \ src/mms_task_ack.c \ src/mms_task_decode.c \ @@ -71,4 +72,5 @@ HEADERS += \ include/mms_lib_types.h \ include/mms_lib_util.h \ include/mms_log.h \ - include/mms_message.h + include/mms_message.h \ + include/mms_settings.h diff --git a/mms-lib/src/mms_attachment.c b/mms-lib/src/mms_attachment.c index 0fc8233..f9e07ea 100644 --- a/mms-lib/src/mms_attachment.c +++ b/mms-lib/src/mms_attachment.c @@ -14,6 +14,7 @@ #include "mms_attachment.h" #include "mms_file_util.h" +#include "mms_settings.h" #include "mms_codec.h" #ifdef HAVE_MAGIC @@ -344,12 +345,13 @@ mms_attachment_reset( gboolean mms_attachment_resize( - MMSAttachment* at) + MMSAttachment* at, + const MMSSettingsSimData* settings) { if (at) { MMSAttachmentClass* klass = MMS_ATTACHMENT_GET_CLASS(at); if (klass->fn_resize) { - return klass->fn_resize(at); + return klass->fn_resize(at, settings); } } return FALSE; diff --git a/mms-lib/src/mms_attachment.h b/mms-lib/src/mms_attachment.h index 6451533..7d0a427 100644 --- a/mms-lib/src/mms_attachment.h +++ b/mms-lib/src/mms_attachment.h @@ -37,8 +37,11 @@ struct _mms_attachment { typedef struct mms_attachment_class { GObjectClass parent; - void (*fn_reset)(MMSAttachment* attachment); - gboolean (*fn_resize)(MMSAttachment* attachment); + void (*fn_reset)( + MMSAttachment* attachment); + gboolean (*fn_resize)( + MMSAttachment* attachment, + const MMSSettingsSimData* settings); } MMSAttachmentClass; GType mms_attachment_get_type(void); @@ -80,7 +83,8 @@ mms_attachment_guess_content_type( gboolean mms_attachment_resize( - MMSAttachment* attachment); + MMSAttachment* attachment, + const MMSSettingsSimData* settings); #endif /* JOLLA_MMS_ATTACHMENT_H */ diff --git a/mms-lib/src/mms_attachment_image.c b/mms-lib/src/mms_attachment_image.c index 306a91d..d44bfd4 100644 --- a/mms-lib/src/mms_attachment_image.c +++ b/mms-lib/src/mms_attachment_image.c @@ -13,6 +13,7 @@ */ #include "mms_attachment_image.h" +#include "mms_settings.h" #include "mms_file_util.h" #ifdef MMS_RESIZE_IMAGEMAGICK @@ -32,13 +33,16 @@ G_DEFINE_TYPE(MMSAttachmentImage, mms_attachment_image, MMS_TYPE_ATTACHMENT); int mms_attachment_image_next_resize_step( MMSAttachmentImage* image, + const MMSSettingsSimData* settings, unsigned int columns, unsigned int rows) { int next_step = image->resize_step + 1; - if (image->attachment.config->max_pixels > 0) { + const unsigned int max_pixels = settings ? settings->max_pixels : + MMS_SETTINGS_DEFAULT_MAX_PIXELS; + if (max_pixels > 0) { unsigned int size = (columns/(next_step+1))*(rows/(next_step+1)); - while (size > 0 && size > image->attachment.config->max_pixels) { + while (size > 0 && size > max_pixels) { next_step++; size = (columns/(next_step+1))*(rows/(next_step+1)); } @@ -70,7 +74,8 @@ mms_attachment_image_prepare_filename( static gboolean mms_attachment_image_resize_default( - MMSAttachmentImage* image) + MMSAttachmentImage* image, + const MMSSettingsSimData* settings) { gboolean ok = FALSE; #ifdef MMS_RESIZE_IMAGEMAGICK @@ -88,7 +93,7 @@ mms_attachment_image_resize_default( const unsigned int src_cols = src->magick_columns; const unsigned int src_rows = src->magick_rows; const int next_step = mms_attachment_image_next_resize_step(image, - src_cols, src_rows); + settings, src_cols, src_rows); const unsigned int cols = src_cols/(next_step+1); const unsigned int rows = src_rows/(next_step+1); Image* dest; @@ -119,7 +124,7 @@ mms_attachment_image_resize_default( DestroyImageInfo(info); #else # ifdef MMS_RESIZE_QT - ok = mms_attachment_image_resize_qt(image); + ok = mms_attachment_image_resize_qt(image, settings); # endif /* MMS_RESIZE_QT */ #endif /* MMS_RESIZE_IMAGEMAGICK */ return ok; @@ -128,7 +133,8 @@ mms_attachment_image_resize_default( static gboolean mms_attachment_image_resize_type_specific( - MMSAttachmentImage* image) + MMSAttachmentImage* image, + const MMSSettingsSimData* settings) { /* If klass->fn_resize_new is not NULL, then we assume that all * other callbacks are present as well */ @@ -141,7 +147,7 @@ mms_attachment_image_resize_type_specific( gboolean can_resize; const char* fname = mms_attachment_image_prepare_filename(image); const int next_step = mms_attachment_image_next_resize_step(image, - resize->image.width, resize->image.height); + settings, resize->image.width, resize->image.height); MMSAttachmentImageSize image_size; MMSAttachmentImageSize out_size; image_size = resize->image; @@ -248,7 +254,8 @@ mms_attachment_image_resize_type_specific( static gboolean mms_attachment_image_resize( - MMSAttachment* at) + MMSAttachment* at, + const MMSSettingsSimData* settings) { MMSAttachmentImage* image = MMS_ATTACHMENT_IMAGE(at); gboolean ok; @@ -256,8 +263,8 @@ mms_attachment_image_resize( g_mapped_file_unref(at->map); at->map = NULL; } - ok = mms_attachment_image_resize_type_specific(image); - if (!ok) ok = mms_attachment_image_resize_default(image); + ok = mms_attachment_image_resize_type_specific(image, settings); + if (!ok) ok = mms_attachment_image_resize_default(image, settings); if (ok) { GError* error = NULL; GMappedFile* map = g_mapped_file_new(image->resized, FALSE, &error); diff --git a/mms-lib/src/mms_attachment_image.h b/mms-lib/src/mms_attachment_image.h index 52da048..14e725c 100644 --- a/mms-lib/src/mms_attachment_image.h +++ b/mms-lib/src/mms_attachment_image.h @@ -74,6 +74,7 @@ typedef struct mms_attachment_image_class { int mms_attachment_image_next_resize_step( MMSAttachmentImage* image, + const MMSSettingsSimData* settings, unsigned int columns, unsigned int rows); @@ -84,7 +85,8 @@ mms_attachment_image_prepare_filename( #ifdef MMS_RESIZE_QT gboolean mms_attachment_image_resize_qt( - MMSAttachmentImage* image); + MMSAttachmentImage* image, + const MMSSettingsSimData* settings); #endif #endif /* JOLLA_MMS_ATTACHMENT_IMAGE_H */ diff --git a/mms-lib/src/mms_attachment_qt.cpp b/mms-lib/src/mms_attachment_qt.cpp index c5976bf..3c2d54c 100644 --- a/mms-lib/src/mms_attachment_qt.cpp +++ b/mms-lib/src/mms_attachment_qt.cpp @@ -24,14 +24,15 @@ extern "C" { gboolean mms_attachment_image_resize_qt( - MMSAttachmentImage* image) + MMSAttachmentImage* image, + const MMSSettingsSimData* s) { gboolean ok = FALSE; QImage qimage; if (qimage.load(image->attachment.original_file)) { const int w = qimage.width(); const int h = qimage.height(); - const int step = mms_attachment_image_next_resize_step(image, w, h); + const int step = mms_attachment_image_next_resize_step(image, s, w, h); const char* fname = mms_attachment_image_prepare_filename(image); const int w1 = w/(step+1); QImage scaled = qimage.scaledToWidth(w1, Qt::SmoothTransformation); diff --git a/mms-lib/src/mms_dispatcher.c b/mms-lib/src/mms_dispatcher.c index 5c1e7c1..5b7f5b4 100644 --- a/mms-lib/src/mms_dispatcher.c +++ b/mms-lib/src/mms_dispatcher.c @@ -14,6 +14,7 @@ #include "mms_dispatcher.h" #include "mms_handler.h" +#include "mms_settings.h" #include "mms_connection.h" #include "mms_connman.h" #include "mms_file_util.h" @@ -31,7 +32,7 @@ MMS_LOG_MODULE_DEFINE("mms-dispatcher"); struct mms_dispatcher { gint ref_count; - const MMSConfig* config; + MMSSettings* settings; MMSTask* active_task; MMSTaskDelegate task_delegate; MMSHandler* handler; @@ -162,7 +163,7 @@ mms_dispatcher_network_idle_check( /* Schedule idle inactivity timeout callback */ MMS_VERBOSE("Network connection is inactive"); disp->network_idle_id = mms_dispatcher_timeout_callback_schedule(disp, - disp->config->idle_secs, mms_dispatcher_network_idle_run); + disp->settings->config->idle_secs, mms_dispatcher_network_idle_run); } } @@ -387,15 +388,15 @@ gboolean mms_dispatcher_start( MMSDispatcher* disp) { - int err = g_mkdir_with_parents(disp->config->root_dir, MMS_DIR_PERM); + const char* root_dir = disp->settings->config->root_dir; + int err = g_mkdir_with_parents(root_dir, MMS_DIR_PERM); if (!err || errno == EEXIST) { if (!g_queue_is_empty(disp->tasks)) { mms_dispatcher_next_run_schedule(disp); return TRUE; } } else { - MMS_ERR("Failed to create %s: %s", disp->config->root_dir, - strerror(errno)); + MMS_ERR("Failed to create %s: %s", root_dir, strerror(errno)); } return FALSE; } @@ -436,7 +437,7 @@ mms_dispatcher_handle_push( GError** error) { return mms_dispatcher_queue_and_unref_task(disp, - mms_task_notification_new(disp->config, disp->handler, + mms_task_notification_new(disp->settings, disp->handler, imsi, push, error)); } @@ -458,7 +459,7 @@ mms_dispatcher_receive_message( MMS_ASSERT(pdu->type == MMS_MESSAGE_TYPE_NOTIFICATION_IND); if (pdu->type == MMS_MESSAGE_TYPE_NOTIFICATION_IND) { ok = mms_dispatcher_queue_and_unref_task(disp, - mms_task_retrieve_new(disp->config, disp->handler, + mms_task_retrieve_new(disp->settings, disp->handler, id, imsi, pdu, error)); } mms_message_free(pdu); @@ -482,7 +483,7 @@ mms_dispatcher_send_read_report( GError** error) { return mms_dispatcher_queue_and_unref_task(disp, - mms_task_read_new(disp->config, disp->handler, + mms_task_read_new(disp->settings, disp->handler, id, imsi, message_id, to, status, error)); } @@ -510,7 +511,7 @@ mms_dispatcher_send_message( } if (imsi) { if (mms_dispatcher_queue_and_unref_task(disp, - mms_task_encode_new(disp->config, disp->handler, id, imsi, + mms_task_encode_new(disp->settings, disp->handler, id, imsi, to, cc, bcc, subject, flags, parts, nparts, error))) { return default_imsi ? default_imsi : g_strdup(imsi); } @@ -611,13 +612,13 @@ mms_dispatcher_delegate_task_state_changed( */ MMSDispatcher* mms_dispatcher_new( - const MMSConfig* config, + MMSSettings* settings, MMSConnMan* cm, MMSHandler* handler) { MMSDispatcher* disp = g_new0(MMSDispatcher, 1); disp->ref_count = 1; - disp->config = config; + disp->settings = mms_settings_ref(settings); disp->tasks = g_queue_new(); disp->handler = mms_handler_ref(handler); disp->cm = mms_connman_ref(cm); @@ -639,9 +640,8 @@ mms_dispatcher_finalize( MMSDispatcher* disp) { MMSTask* task; - char* msg_dir = g_strconcat(disp->config->root_dir, - "/" MMS_MESSAGE_DIR "/", NULL); - + const char* root_dir = disp->settings->config->root_dir; + char* msg_dir = g_strconcat(root_dir, "/" MMS_MESSAGE_DIR "/", NULL); MMS_VERBOSE_(""); mms_dispatcher_close_connection(disp); while ((task = g_queue_pop_head(disp->tasks)) != NULL) { @@ -650,6 +650,7 @@ mms_dispatcher_finalize( mms_task_unref(task); } g_queue_free(disp->tasks); + mms_settings_unref(disp->settings); mms_handler_unref(disp->handler); mms_connman_unref(disp->cm); diff --git a/mms-lib/src/mms_file_util.h b/mms-lib/src/mms_file_util.h index f308067..45dccd9 100644 --- a/mms-lib/src/mms_file_util.h +++ b/mms-lib/src/mms_file_util.h @@ -78,9 +78,9 @@ mms_file_copy( #define mms_message_dir(config,id) \ (g_strconcat((config)->root_dir, "/" MMS_MESSAGE_DIR "/" , id, NULL)) #define mms_task_dir(task) \ - mms_message_dir((task)->config,(task)->id) + mms_message_dir(task_config(task),(task)->id) #define mms_task_file(task,file) \ - (g_strconcat((task)->config->root_dir, "/" MMS_MESSAGE_DIR "/" , \ + (g_strconcat(task_config(task)->root_dir, "/" MMS_MESSAGE_DIR "/" , \ (task)->id, "/", file, NULL)) #endif /* JOLLA_MMS_FILE_UTIL_H */ diff --git a/mms-lib/src/mms_lib_util.c b/mms-lib/src/mms_lib_util.c index 5da5237..5f83162 100644 --- a/mms-lib/src/mms_lib_util.c +++ b/mms-lib/src/mms_lib_util.c @@ -23,11 +23,8 @@ #endif #define MMS_DEFAULT_ROOT_DIR "/tmp/mms" -#define MMS_DEFAULT_USER_AGENT "Mozilla/5.0 (Sailfish; Jolla)" #define MMS_DEFAULT_RETRY_SECS (15) #define MMS_DEFAULT_IDLE_SECS (20) -#define MMS_DEFAULT_SIZE_LIMIT (300*1024) -#define MMS_DEFAULT_MAX_PIXELS (3000000) /** * MMS error domain @@ -75,14 +72,10 @@ mms_lib_default_config( MMSConfig* config) { config->root_dir = MMS_DEFAULT_ROOT_DIR; - config->user_agent = MMS_DEFAULT_USER_AGENT; config->retry_secs = MMS_DEFAULT_RETRY_SECS; config->idle_secs = MMS_DEFAULT_IDLE_SECS; - config->size_limit = MMS_DEFAULT_SIZE_LIMIT; - config->max_pixels = MMS_DEFAULT_MAX_PIXELS; config->keep_temp_files = FALSE; config->attic_enabled = FALSE; - config->send_dr = TRUE; } /* diff --git a/mms-lib/src/mms_settings.c b/mms-lib/src/mms_settings.c new file mode 100644 index 0000000..69f895b --- /dev/null +++ b/mms-lib/src/mms_settings.c @@ -0,0 +1,166 @@ +/* + * Copyright (C) 2014 Jolla Ltd. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + */ + +#include "mms_settings.h" + +G_DEFINE_TYPE(MMSSettings, mms_settings, G_TYPE_OBJECT); +#define MMS_SETTINGS_GET_CLASS(obj) \ + (G_TYPE_INSTANCE_GET_CLASS((obj), MMS_TYPE_SETTINGS, MMSSettingsClass)) +#define MMS_SETTINGS(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST((obj), MMS_TYPE_SETTINGS, MMSSettings)) + +MMSSettings* +mms_settings_ref( + MMSSettings* s) +{ + if (s) g_object_ref(MMS_SETTINGS(s)); + return s; +} + +void +mms_settings_unref( + MMSSettings* s) +{ + if (s) g_object_unref(MMS_SETTINGS(s)); +} + +void +mms_settings_sim_data_default( + MMSSettingsSimData* data) +{ + memset(data, 0, sizeof(*data)); + data->user_agent = MMS_SETTINGS_DEFAULT_USER_AGENT; + data->size_limit = MMS_SETTINGS_DEFAULT_SIZE_LIMIT; + data->max_pixels = MMS_SETTINGS_DEFAULT_MAX_PIXELS; + data->allow_dr = MMS_SETTINGS_DEFAULT_ALLOW_DR; +} + +static +void +mms_settings_sim_data_copy( + MMSSettingsSimDataCopy* dest, + const MMSSettingsSimData* src) +{ + g_free(dest->user_agent); + if (src) { + dest->data = *src; + dest->data.user_agent = dest->user_agent = g_strdup(src->user_agent); + } else { + dest->user_agent = NULL; + mms_settings_sim_data_default(&dest->data); + } +} + +MMSSettingsSimDataCopy* +mms_settings_sim_data_copy_new( + const MMSSettingsSimData* data) +{ + MMSSettingsSimDataCopy* copy = NULL; + if (data) { + copy = g_new0(MMSSettingsSimDataCopy, 1); + mms_settings_sim_data_copy(copy, data); + } + return copy; +} + +void +mms_settings_sim_data_copy_free( + MMSSettingsSimDataCopy* copy) +{ + if (copy) { + g_free(copy->user_agent); + g_free(copy); + } +} + +void +mms_settings_set_sim_defaults( + MMSSettings* settings, + const MMSSettingsSimData* data) +{ + if (settings) { + mms_settings_sim_data_copy(&settings->sim_defaults, data); + } +} + +const MMSSettingsSimData* +mms_settings_get_sim_data( + MMSSettings* settings, + const char* imsi) +{ + if (settings) { + MMSSettingsClass* klass = MMS_SETTINGS_GET_CLASS(settings); + return klass->fn_get_sim_data(settings, imsi); + } + return NULL; +} + +MMSSettings* +mms_settings_default_new( + const MMSConfig* config) +{ + MMSSettings* settings = g_object_new(MMS_TYPE_SETTINGS, NULL); + settings->config = config; + return settings; +} + +static +const MMSSettingsSimData* +mms_settings_get_default_sim_data( + MMSSettings* settings, + const char* imsi) +{ + return &settings->sim_defaults.data; +} + +static +void +mms_settings_finalize( + GObject* object) +{ + MMSSettings* settings = MMS_SETTINGS(object); + g_free(settings->sim_defaults.user_agent); + G_OBJECT_CLASS(mms_settings_parent_class)->finalize(object); +} + +/** + * Per class initializer + */ +static +void +mms_settings_class_init( + MMSSettingsClass* klass) +{ + klass->fn_get_sim_data = mms_settings_get_default_sim_data; + G_OBJECT_CLASS(klass)->finalize = mms_settings_finalize; +} + +/** + * Per instance initializer + */ +static +void +mms_settings_init( + MMSSettings* settings) +{ + mms_settings_sim_data_default(&settings->sim_defaults.data); +} + +/* + * Local Variables: + * mode: C + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/mms-lib/src/mms_task.c b/mms-lib/src/mms_task.c index ad251db..28351a8 100644 --- a/mms-lib/src/mms_task.c +++ b/mms-lib/src/mms_task.c @@ -60,7 +60,7 @@ mms_task_schedule_wakeup( unsigned int secs) { const time_t now = time(NULL); - if (!secs) secs = task->config->retry_secs; + if (!secs) secs = task->settings->config->retry_secs; /* Cancel the previous sleep */ if (task->wakeup_id) { @@ -119,7 +119,7 @@ mms_task_finalize( MMS_ASSERT(!task->delegate); MMS_ASSERT(!task->wakeup_id); if (task->id) { - if (!task->config->keep_temp_files) { + if (!task_config(task)->keep_temp_files) { char* dir = mms_task_dir(task); if (rmdir(dir) == 0) { MMS_VERBOSE("Deleted %s", dir); @@ -130,6 +130,7 @@ mms_task_finalize( } g_free(task->name); g_free(task->imsi); + mms_settings_unref(task->settings); mms_handler_unref(task->handler); G_OBJECT_CLASS(mms_task_parent_class)->finalize(object); } @@ -154,7 +155,7 @@ mms_task_init( void* mms_task_alloc( GType type, - const MMSConfig* config, + MMSSettings* settings, MMSHandler* handler, const char* name, const char* id, @@ -164,7 +165,7 @@ mms_task_alloc( const time_t now = time(NULL); time_t max_lifetime = MMS_TASK_GET_CLASS(task)->max_lifetime; if (!max_lifetime) max_lifetime = MMS_TASK_DEFAULT_LIFETIME; - task->config = config; + task->settings = mms_settings_ref(settings); task->handler = mms_handler_ref(handler); if (name) { task->name = id ? @@ -249,7 +250,8 @@ mms_task_set_state( mms_task_state_name(task->state), mms_task_state_name(state)); if (state == MMS_TASK_STATE_SLEEP && !task->wakeup_id) { - if (!mms_task_schedule_wakeup(task, task->config->retry_secs)) { + const unsigned int secs = task_config(task)->retry_secs; + if (!mms_task_schedule_wakeup(task, secs)) { MMS_DEBUG("%s SLEEP -> DONE (no time left)", task->name); state = MMS_TASK_STATE_DONE; } @@ -325,8 +327,8 @@ mms_task_make_id( MMSTask* task) { if (!task->id || !task->id[0]) { - char* msgdir = g_strconcat(task->config->root_dir, "/", - MMS_MESSAGE_DIR, NULL); + const char* root_dir = task_config(task)->root_dir; + char* msgdir = g_strconcat(root_dir, "/", MMS_MESSAGE_DIR, NULL); int err = g_mkdir_with_parents(msgdir, MMS_DIR_PERM); if (!err || errno == EEXIST) { char* tmpl = g_strconcat(msgdir, "/XXXXXX" , NULL); @@ -337,14 +339,24 @@ mms_task_make_id( } g_free(tmpl); } else { - MMS_ERR("Failed to create %s: %s", task->config->root_dir, - strerror(errno)); + MMS_ERR("Failed to create %s: %s", root_dir, strerror(errno)); } g_free(msgdir); } return task->id; } +const MMSSettingsSimData* +mms_task_sim_settings( + MMSTask* task) +{ + if (task && task->settings) { + return mms_settings_get_sim_data(task->settings, task->imsi); + } else { + return NULL; + } +} + /* * Local Variables: * mode: C diff --git a/mms-lib/src/mms_task.h b/mms-lib/src/mms_task.h index a53aa7e..b2f4f5a 100644 --- a/mms-lib/src/mms_task.h +++ b/mms-lib/src/mms_task.h @@ -15,7 +15,7 @@ #ifndef JOLLA_MMS_TASK_H #define JOLLA_MMS_TASK_H -#include "mms_lib_types.h" +#include "mms_settings.h" /* Claim MMS 1.1 support */ #define MMS_VERSION MMS_MESSAGE_VERSION_1_1 @@ -55,7 +55,7 @@ struct mms_task { char* name; /* Task name for debug purposes */ char* id; /* Database record ID */ char* imsi; /* Associated subscriber identity */ - const MMSConfig* config; /* Immutable configuration */ + MMSSettings* settings; /* Settings */ MMSHandler* handler; /* Message database interface */ MMSTaskDelegate* delegate; /* Observer */ MMS_TASK_STATE state; /* Task state */ @@ -90,7 +90,7 @@ GType mms_task_get_type(void); void* mms_task_alloc( GType type, - const MMSConfig* config, + MMSSettings* settings, MMSHandler* handler, const char* name, const char* id, @@ -153,10 +153,17 @@ const char* mms_task_make_id( MMSTask* task); +const MMSSettingsSimData* +mms_task_sim_settings( + MMSTask* task); + +#define task_config(task) \ + ((task)->settings->config) + /* Create particular types of tasks */ MMSTask* mms_task_notification_new( - const MMSConfig* config, + MMSSettings* settings, MMSHandler* handler, const char* imsi, GBytes* bytes, @@ -164,7 +171,7 @@ mms_task_notification_new( MMSTask* mms_task_retrieve_new( - const MMSConfig* config, + MMSSettings* settings, MMSHandler* handler, const char* id, const char* imsi, @@ -173,33 +180,24 @@ mms_task_retrieve_new( MMSTask* mms_task_decode_new( - const MMSConfig* config, - MMSHandler* handler, - const char* id, - const char* imsi, + MMSTask* parent, const char* transaction_id, const char* file); MMSTask* mms_task_notifyresp_new( - const MMSConfig* config, - MMSHandler* handler, - const char* id, - const char* imsi, + MMSTask* parent, const char* transaction_id, MMSNotifyStatus status); MMSTask* mms_task_ack_new( - const MMSConfig* config, - MMSHandler* handler, - const char* id, - const char* imsi, + MMSTask* parent, const char* transaction_id); MMSTask* mms_task_read_new( - const MMSConfig* config, + MMSSettings* settings, MMSHandler* handler, const char* id, const char* imsi, @@ -210,13 +208,13 @@ mms_task_read_new( MMSTask* mms_task_publish_new( - const MMSConfig* config, + MMSSettings* settings, MMSHandler* handler, MMSMessage* msg); MMSTask* mms_task_encode_new( - const MMSConfig* config, + MMSSettings* settings, MMSHandler* handler, const char* id, const char* imsi, @@ -231,10 +229,7 @@ mms_task_encode_new( MMSTask* mms_task_send_new( - const MMSConfig* config, - MMSHandler* handler, - const char* id, - const char* imsi); + MMSTask* parent); #endif /* JOLLA_MMS_TASK_H */ diff --git a/mms-lib/src/mms_task_ack.c b/mms-lib/src/mms_task_ack.c index 535c6ae..aaf43a9 100644 --- a/mms-lib/src/mms_task_ack.c +++ b/mms-lib/src/mms_task_ack.c @@ -15,12 +15,14 @@ #include "mms_task.h" #include "mms_task_http.h" #include "mms_file_util.h" +#include "mms_settings.h" #include "mms_codec.h" static const char* mms_task_ack_encode( const MMSConfig* config, + const MMSSettingsSimData* settings, const char* id, const char* transaction_id) { @@ -33,7 +35,8 @@ mms_task_ack_encode( pdu->type = MMS_MESSAGE_TYPE_ACKNOWLEDGE_IND; pdu->version = MMS_VERSION; pdu->transaction_id = g_strdup(transaction_id); - pdu->ai.report = config->send_dr; + pdu->ai.report = settings ? settings->allow_dr : + MMS_SETTINGS_DEFAULT_ALLOW_DR; if (mms_message_encode(pdu, fd)) result = file; mms_message_free(pdu); close(fd); @@ -45,16 +48,14 @@ mms_task_ack_encode( /* Create MMS delivery acknowledgement task */ MMSTask* mms_task_ack_new( - const MMSConfig* config, - MMSHandler* handler, - const char* id, - const char* imsi, + MMSTask* parent, const char* tx_id) { - const char* file = mms_task_ack_encode(config, id, tx_id); + const char* file = mms_task_ack_encode(task_config(parent), + mms_task_sim_settings(parent), parent->id, tx_id); if (file) { - return mms_task_http_alloc(0, config, handler, "Ack", - id, imsi, NULL, NULL, file); + return mms_task_http_alloc_with_parent(0, parent, "Ack", + NULL, NULL, file); } return NULL; } diff --git a/mms-lib/src/mms_task_decode.c b/mms-lib/src/mms_task_decode.c index 0cc90b6..f803e5e 100644 --- a/mms-lib/src/mms_task_decode.c +++ b/mms-lib/src/mms_task_decode.c @@ -136,7 +136,7 @@ mms_task_decode_retrieve_conf( MMS_DEBUG(" %u parts", nparts); #endif /* MMS_LOG_DEBUG */ - if (task->config->keep_temp_files) { + if (task_config(task)->keep_temp_files) { msg->flags |= MMS_MESSAGE_FLAG_KEEP_FILES; } @@ -218,10 +218,10 @@ mms_task_decode_process_pdu( if (msg) { /* Successfully received and decoded MMS message */ mms_task_queue_and_unref(task->delegate, - mms_task_ack_new(task->config, task->handler, - task->id, task->imsi, dec->transaction_id)); + mms_task_ack_new(task, dec->transaction_id)); mms_task_queue_and_unref(task->delegate, - mms_task_publish_new(task->config, task->handler, msg)); + mms_task_publish_new(task->settings, + task->handler, msg)); mms_message_unref(msg); return; } @@ -243,8 +243,7 @@ mms_task_decode_process_pdu( /* Tell MMS server that we didn't understand this PDU */ mms_task_queue_and_unref(task->delegate, - mms_task_notifyresp_new(task->config, task->handler, task->id, - task->imsi, dec->transaction_id, + mms_task_notifyresp_new(task, dec->transaction_id, MMS_MESSAGE_NOTIFY_STATUS_UNRECOGNISED)); mms_handler_message_receive_state_changed(task->handler, task->id, MMS_RECEIVE_STATE_DECODING_ERROR); @@ -267,7 +266,7 @@ mms_task_decode_finalize( GObject* object) { MMSTaskDecode* dec = MMS_TASK_DECODE(object); - if (!dec->task.config->keep_temp_files) { + if (!task_config(&dec->task)->keep_temp_files) { mms_remove_file_and_dir(dec->file); } g_mapped_file_unref(dec->map); @@ -295,15 +294,13 @@ mms_task_decode_init( /* Create MMS decode task */ MMSTask* mms_task_decode_new( - const MMSConfig* config, - MMSHandler* handler, - const char* id, - const char* imsi, + MMSTask* parent, const char* transaction_id, const char* file) { MMSTaskDecode* dec = mms_task_alloc(MMS_TYPE_TASK_DECODE, - config, handler, "Decode", id, imsi); + parent->settings, parent->handler, "Decode", parent->id, + parent->imsi); GError* error = NULL; dec->map = g_mapped_file_new(file, FALSE, &error); if (dec->map) { diff --git a/mms-lib/src/mms_task_encode.c b/mms-lib/src/mms_task_encode.c index 856ff92..6e730da 100644 --- a/mms-lib/src/mms_task_encode.c +++ b/mms-lib/src/mms_task_encode.c @@ -15,6 +15,7 @@ #include "mms_task.h" #include "mms_attachment.h" #include "mms_dispatcher.h" +#include "mms_settings.h" #include "mms_handler.h" #include "mms_file_util.h" #include "mms_util.h" @@ -64,6 +65,7 @@ typedef struct mms_encode_job { GCancellable* cancellable; /* Can be used to cancel the job */ GMainContext* context; /* Pointer to the main contex */ char* path; /* Path to the encoded file */ + MMSSettingsSimDataCopy* settings; /* Copy of settings to use */ MMS_ENCODE_STATE state; /* Job state */ } MMSEncodeJob; @@ -108,7 +110,7 @@ mms_encode_job_resize( } if (resize_me) { MMS_DEBUG("Resizing %s", resize_me->original_file); - return mms_attachment_resize(resize_me); + return mms_attachment_resize(resize_me, &job->settings->data); } else { MMS_DEBUG("There is nothing to resize"); return FALSE; @@ -205,8 +207,9 @@ mms_encode_job_run( { int i; gsize size; - const MMSConfig* config = job->enc->task.config; MMSTaskEncode* enc = job->enc; + const unsigned int size_limit = job->settings ? + job->settings->data.size_limit : MMS_SETTINGS_DEFAULT_SIZE_LIMIT; job->state = MMS_ENCODE_STATE_RUNNING; @@ -217,7 +220,7 @@ mms_encode_job_run( /* Keep resizing attachments until we squeeze them into the limit */ size = mms_encode_job_encode(job); - while (config->size_limit && size > config->size_limit && + while (size_limit && size > size_limit && !g_cancellable_is_cancelled(job->cancellable) && mms_encode_job_resize(job)) { gsize last_size = size; @@ -225,7 +228,7 @@ mms_encode_job_run( if (!size || size >= last_size) break; } - if (size > 0 && (!config->size_limit || size <= config->size_limit)) { + if (size > 0 && (!size_limit || size <= size_limit)) { job->state = MMS_ENCODE_STATE_DONE; } else { unlink(job->path); @@ -259,6 +262,7 @@ mms_encode_job_unref( mms_task_unref(&job->enc->task); g_object_unref(job->cancellable); g_main_context_unref(job->context); + mms_settings_sim_data_copy_free(job->settings); g_free(job->path); g_free(job); } @@ -271,11 +275,13 @@ mms_encode_job_new( MMSTaskEncode* enc) { MMSEncodeJob* job = g_new0(MMSEncodeJob, 1); + const MMSSettingsSimData* sim_data = mms_task_sim_settings(&enc->task); mms_task_ref(&enc->task); job->ref_count = 1; job->enc = enc; job->cancellable = g_cancellable_new(); job->context = g_main_context_ref(g_main_context_default()); + job->settings = mms_settings_sim_data_copy_new(sim_data); return job; } @@ -315,8 +321,7 @@ mms_task_encode_job_done( MMS_VERBOSE_("Encoding completion state %d", job->state); enc->active_job = NULL; if (job->state == MMS_ENCODE_STATE_DONE) { - mms_task_queue_and_unref(task->delegate, mms_task_send_new( - task->config, task->handler, task->id, task->imsi)); + mms_task_queue_and_unref(task->delegate, mms_task_send_new(task)); } else { mms_handler_message_send_state_changed(task->handler, task->id, (job->state == MMS_ENCODE_STATE_TOO_BIG) ? @@ -594,7 +599,7 @@ mms_task_encode_init( /* Create MMS encode task */ MMSTask* mms_task_encode_new( - const MMSConfig* config, + MMSSettings* settings, MMSHandler* handler, const char* id, const char* imsi, @@ -612,15 +617,15 @@ mms_task_encode_new( int err; char* dir; MMSTaskEncode* enc = mms_task_alloc(MMS_TYPE_TASK_ENCODE, - config, handler, "Encode", id, imsi); + settings, handler, "Encode", id, imsi); MMSTask* task = &enc->task; mms_task_make_id(task); dir = mms_task_file(task, MMS_ENCODE_DIR); err = g_mkdir_with_parents(dir, MMS_DIR_PERM); if (!err || errno == EEXIST) { - GPtrArray* array = mms_task_encode_prepare_attachments(config, - dir, parts, nparts, error); + GPtrArray* array = mms_task_encode_prepare_attachments( + settings->config, dir, parts, nparts, error); if (array) { enc->nparts = array->len; enc->parts = (MMSAttachment**)g_ptr_array_free(array, FALSE); diff --git a/mms-lib/src/mms_task_http.c b/mms-lib/src/mms_task_http.c index ad68839..60de42a 100644 --- a/mms-lib/src/mms_task_http.c +++ b/mms-lib/src/mms_task_http.c @@ -14,6 +14,7 @@ #include "mms_task_http.h" #include "mms_connection.h" +#include "mms_settings.h" #include "mms_file_util.h" #ifndef _WIN32 @@ -100,7 +101,7 @@ mms_http_uri_parse( static SoupSession* mms_http_create_session( - const MMSConfig* cfg, + const MMSSettingsSimData* cfg, MMSConnection* conn) { SoupSession* session = NULL; @@ -162,7 +163,7 @@ mms_http_create_session( } } - if (cfg->user_agent) { + if (cfg && cfg->user_agent) { g_object_set(session, SOUP_SESSION_USER_AGENT, cfg->user_agent, NULL); } @@ -172,7 +173,7 @@ mms_http_create_session( static MMSHttpTransfer* mms_http_transfer_new( - const MMSConfig* config, + const MMSSettingsSimData* cfg, MMSConnection* connection, const char* method, const char* uri, @@ -182,7 +183,7 @@ mms_http_transfer_new( SoupURI* soup_uri = mms_http_uri_parse(uri); if (soup_uri) { MMSHttpTransfer* tx = g_new(MMSHttpTransfer, 1); - tx->session = mms_http_create_session(config, connection); + tx->session = mms_http_create_session(cfg, connection); tx->message = soup_message_new_from_uri(method, soup_uri); tx->connection = mms_connection_ref(connection); tx->receive_fd = receive_fd; @@ -413,9 +414,9 @@ mms_task_http_start( /* Set up the transfer */ const char* uri = priv->uri ? priv->uri : connection->mmsc; - priv->tx = mms_http_transfer_new(http->task.config, connection, - priv->send_path ? SOUP_METHOD_POST : SOUP_METHOD_GET, uri, - receive_fd, send_fd); + priv->tx = mms_http_transfer_new(mms_task_sim_settings(&http->task), + connection, priv->send_path ? SOUP_METHOD_POST : SOUP_METHOD_GET, + uri, receive_fd, send_fd); if (priv->tx) { SoupMessage* msg = priv->tx->message; soup_message_body_set_accumulate(msg->response_body, FALSE); @@ -541,7 +542,7 @@ mms_task_http_finalize( MMS_ASSERT(!http->priv->got_chunk_signal_id); MMS_ASSERT(!http->priv->wrote_headers_signal_id); MMS_ASSERT(!http->priv->wrote_chunk_signal_id); - if (!http->task.config->keep_temp_files) { + if (!task_config(&http->task)->keep_temp_files) { mms_remove_file_and_dir(http->priv->send_path); mms_remove_file_and_dir(http->priv->receive_path); } @@ -586,7 +587,7 @@ mms_task_http_init( void* mms_task_http_alloc( GType type, /* Zero for MMS_TYPE_TASK_HTTP */ - const MMSConfig* config, /* Global configuration */ + MMSSettings* settings, /* Settings */ MMSHandler* handler, /* MMS handler */ const char* name, /* Task name */ const char* id, /* Database message id */ @@ -596,7 +597,7 @@ mms_task_http_alloc( const char* send_file) /* File to read data from (optional) */ { MMSTaskHttp* http = mms_task_alloc(type ? type : MMS_TYPE_TASK_HTTP, - config, handler, name, id, imsi); + settings, handler, name, id, imsi); MMSTaskHttpPrivate* priv = g_new0(MMSTaskHttpPrivate, 1); http->priv = priv; priv->uri = g_strdup(uri); @@ -608,6 +609,19 @@ mms_task_http_alloc( return http; } +void* +mms_task_http_alloc_with_parent( + GType type, /* Zero for MMS_TYPE_TASK_HTTP */ + MMSTask* parent, /* Parent task */ + const char* name, /* Task name */ + const char* uri, /* NULL to use MMSC URL */ + const char* receive_file, /* File to write data to (optional) */ + const char* send_file) /* File to read data from (optional) */ +{ + return mms_task_http_alloc(type, parent->settings, parent->handler, + name, parent->id, parent->imsi, uri, receive_file, send_file); +} + /* * Local Variables: * mode: C diff --git a/mms-lib/src/mms_task_http.h b/mms-lib/src/mms_task_http.h index 9aff4b8..507dc7e 100644 --- a/mms-lib/src/mms_task_http.h +++ b/mms-lib/src/mms_task_http.h @@ -53,7 +53,7 @@ GType mms_task_http_get_type(void); void* mms_task_http_alloc( GType type, /* Zero for MMS_TYPE_TASK_HTTP */ - const MMSConfig* config, /* Global configuration */ + MMSSettings* settings, /* Settings */ MMSHandler* handler, /* MMS handler */ const char* name, /* Task name */ const char* id, /* Database message id */ @@ -62,6 +62,15 @@ mms_task_http_alloc( const char* receive_file, /* File to write data to (optional) */ const char* send_file); /* File to read data from (optional) */ +void* +mms_task_http_alloc_with_parent( + GType type, /* Zero for MMS_TYPE_TASK_HTTP */ + MMSTask* parent, /* Parent task */ + const char* name, /* Task name */ + const char* uri, /* NULL to use MMSC URL */ + const char* receive_file, /* File to write data to (optional) */ + const char* send_file); /* File to read data from (optional) */ + #endif /* JOLLA_MMS_TASK_HTTP_H */ /* diff --git a/mms-lib/src/mms_task_notification.c b/mms-lib/src/mms_task_notification.c index 7f24901..16c1acf 100644 --- a/mms-lib/src/mms_task_notification.c +++ b/mms-lib/src/mms_task_notification.c @@ -100,8 +100,8 @@ mms_task_notification_ind( /* Schedule the download task */ if (!mms_task_queue_and_unref(task->delegate, - mms_task_retrieve_new(task->config, task->handler, - task->id, task->imsi, ind->pdu, NULL))) { + 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); } @@ -111,12 +111,11 @@ mms_task_notification_ind( } else if (!mms_task_retry(task)) { mms_task_make_id(task); mms_task_queue_and_unref(task->delegate, - mms_task_notifyresp_new(task->config, task->handler, task->id, - task->imsi, ind->pdu->transaction_id, + mms_task_notifyresp_new(task, ind->pdu->transaction_id, MMS_MESSAGE_NOTIFY_STATUS_REJECTED)); } - if (task->config->keep_temp_files) { + if (task_config(task)->keep_temp_files) { mms_task_notification_write_file(ind, MMS_NOTIFICATION_IND_FILE); } } @@ -130,7 +129,7 @@ mms_task_delivery_ind( MMSTaskNotification* ind) { MMS_DELIVERY_STATUS ds; - MMSTask* t = &ind->task; + MMSTask* task = &ind->task; const struct mms_delivery_ind* di = &ind->pdu->di; const char* to = mms_strip_address_type(di->to); MMS_DEBUG("Processing M-Delivery.ind PDU"); @@ -163,8 +162,8 @@ mms_task_delivery_ind( ds = MMS_DELIVERY_STATUS_UNKNOWN; break; } - mms_handler_delivery_report(t->handler, t->imsi, di->msgid, to, ds); - if (t->config->keep_temp_files) { + mms_handler_delivery_report(task->handler, task->imsi, di->msgid, to, ds); + if (task_config(task)->keep_temp_files) { mms_task_notification_write_file(ind, MMS_DELIVERY_IND_FILE); } } @@ -178,7 +177,7 @@ mms_task_read_orig_ind( MMSTaskNotification* ind) { MMS_READ_STATUS rs; - MMSTask* t = &ind->task; + MMSTask* task = &ind->task; const struct mms_read_ind* ri = &ind->pdu->ri; const char* to = mms_strip_address_type(ri->to); MMS_DEBUG("Processing M-Read-Orig.ind"); @@ -195,8 +194,8 @@ mms_task_read_orig_ind( rs = MMS_READ_STATUS_INVALID; break; } - mms_handler_read_report(t->handler, t->imsi, ri->msgid, to, rs); - if (ind->task.config->keep_temp_files) { + mms_handler_read_report(task->handler, task->imsi, ri->msgid, to, rs); + if (task_config(task)->keep_temp_files) { mms_task_notification_write_file(ind, MMS_READ_ORIG_IND_FILE); } } @@ -245,7 +244,7 @@ mms_task_notification_run( break; default: MMS_INFO("Ignoring MMS push PDU of type %u", ind->pdu->type); - mms_task_notification_unrecornized(task->config, ind->push); + mms_task_notification_unrecornized(task_config(task), ind->push); break; } if (task->state == MMS_TASK_STATE_READY) { @@ -283,7 +282,7 @@ mms_task_notification_init( /* Create MMS notification task */ MMSTask* mms_task_notification_new( - const MMSConfig* config, + MMSSettings* settings, MMSHandler* handler, const char* imsi, GBytes* bytes, @@ -304,13 +303,13 @@ mms_task_notification_new( #endif /* MMS_LOG_DEBUG */ ind = mms_task_alloc(MMS_TYPE_TASK_NOTIFICATION, - config, handler, "Notification", NULL, imsi); + settings, handler, "Notification", NULL, imsi); ind->push = g_bytes_ref(bytes); ind->pdu = pdu; return &ind->task; } else { MMS_ERROR(error, MMS_LIB_ERROR_DECODE, "Failed to decode MMS PDU"); - mms_task_notification_unrecornized(config, bytes); + mms_task_notification_unrecornized(settings->config, bytes); return NULL; } } diff --git a/mms-lib/src/mms_task_notifyresp.c b/mms-lib/src/mms_task_notifyresp.c index 1914d0c..e5fe48a 100644 --- a/mms-lib/src/mms_task_notifyresp.c +++ b/mms-lib/src/mms_task_notifyresp.c @@ -48,17 +48,15 @@ mms_task_notifyresp_encode( */ MMSTask* mms_task_notifyresp_new( - const MMSConfig* config, - MMSHandler* handler, - const char* id, - const char* imsi, + MMSTask* parent, const char* tx_id, MMSNotifyStatus ns) { - const char* file = mms_task_notifyresp_encode(config, id, tx_id, ns); + const char* file = mms_task_notifyresp_encode(task_config(parent), + parent->id, tx_id, ns); if (file) { - return mms_task_http_alloc(0, config, handler, "NotifyResp", - id, imsi, NULL, NULL, file); + return mms_task_http_alloc_with_parent(0, parent, "NotifyResp", + NULL, NULL, file); } return NULL; } diff --git a/mms-lib/src/mms_task_publish.c b/mms-lib/src/mms_task_publish.c index a4b4ffc..553ee81 100644 --- a/mms-lib/src/mms_task_publish.c +++ b/mms-lib/src/mms_task_publish.c @@ -74,14 +74,14 @@ mms_task_publish_init( /* Create MMS publish task */ MMSTask* mms_task_publish_new( - const MMSConfig* config, + MMSSettings* settings, MMSHandler* handler, MMSMessage* msg) { MMS_ASSERT(msg && msg->id); if (msg && msg->id) { MMSTaskPublish* pub = mms_task_alloc(MMS_TYPE_TASK_PUBLISH, - config, handler, "Publish", msg->id, NULL); + settings, handler, "Publish", msg->id, NULL); pub->msg = mms_message_ref(msg); return &pub->task; } else { diff --git a/mms-lib/src/mms_task_read.c b/mms-lib/src/mms_task_read.c index 2431ca9..838ef1a 100644 --- a/mms-lib/src/mms_task_read.c +++ b/mms-lib/src/mms_task_read.c @@ -61,7 +61,7 @@ mms_task_read_encode( */ MMSTask* mms_task_read_new( - const MMSConfig* config, + MMSSettings* settings, MMSHandler* handler, const char* id, const char* imsi, @@ -70,9 +70,10 @@ mms_task_read_new( MMSReadStatus rs, GError** err) { - const char* file = mms_task_read_encode(config, id, msg_id, to, rs, err); + const char* file = mms_task_read_encode(settings->config, + id, msg_id, to, rs, err); if (file) { - return mms_task_http_alloc(0, config, handler, "Read", + return mms_task_http_alloc(0, settings, handler, "Read", id, imsi, NULL, NULL, file); } return NULL; diff --git a/mms-lib/src/mms_task_retrieve.c b/mms-lib/src/mms_task_retrieve.c index 4ef4665..6b3fefc 100644 --- a/mms-lib/src/mms_task_retrieve.c +++ b/mms-lib/src/mms_task_retrieve.c @@ -66,8 +66,7 @@ mms_task_retrieve_done( MMS_RECEIVE_STATE state = (SOUP_STATUS_IS_SUCCESSFUL(status) && mms_task_queue_and_unref(task->delegate, - mms_task_decode_new(task->config, task->handler, task->id, - task->imsi, retrieve->transaction_id, path))) ? + mms_task_decode_new(task, retrieve->transaction_id, path))) ? MMS_RECEIVE_STATE_DECODING : MMS_RECEIVE_STATE_DOWNLOAD_ERROR; mms_handler_message_receive_state_changed(http->task.handler, @@ -114,7 +113,7 @@ mms_task_retrieve_init( /* Create MMS retrieve task */ MMSTask* mms_task_retrieve_new( - const MMSConfig* config, + MMSSettings* settings, MMSHandler* handler, const char* id, const char* imsi, @@ -127,8 +126,8 @@ mms_task_retrieve_new( MMS_ASSERT(pdu->transaction_id); if (pdu->ni.expiry > now) { MMSTaskRetrieve* retrieve = mms_task_http_alloc( - MMS_TYPE_TASK_RETRIEVE, config, handler, "Retrieve", id, imsi, - pdu->ni.location, MMS_RETRIEVE_CONF_FILE, NULL); + MMS_TYPE_TASK_RETRIEVE, settings, handler, "Retrieve", + id, imsi, pdu->ni.location, MMS_RETRIEVE_CONF_FILE, NULL); if (retrieve->http.task.deadline > pdu->ni.expiry) { retrieve->http.task.deadline = pdu->ni.expiry; } diff --git a/mms-lib/src/mms_task_send.c b/mms-lib/src/mms_task_send.c index d30a4ba..2a59c56 100644 --- a/mms-lib/src/mms_task_send.c +++ b/mms-lib/src/mms_task_send.c @@ -138,13 +138,9 @@ mms_task_send_init( /* Create MMS send task */ MMSTask* mms_task_send_new( - const MMSConfig* config, - MMSHandler* handler, - const char* id, - const char* imsi) + MMSTask* parent) { - return mms_task_http_alloc( - MMS_TYPE_TASK_SEND, config, handler, "Send", id, imsi, + return mms_task_http_alloc_with_parent(MMS_TYPE_TASK_SEND, parent, "Send", NULL, MMS_SEND_CONF_FILE, MMS_SEND_REQ_FILE); } diff --git a/mms-lib/test/delivery_ind/test_delivery_ind.c b/mms-lib/test/delivery_ind/test_delivery_ind.c index 6606128..e16d132 100644 --- a/mms-lib/test/delivery_ind/test_delivery_ind.c +++ b/mms-lib/test/delivery_ind/test_delivery_ind.c @@ -18,6 +18,7 @@ #include "mms_file_util.h" #include "mms_lib_log.h" #include "mms_lib_util.h" +#include "mms_settings.h" #include "mms_dispatcher.h" #define RET_OK (0) @@ -127,16 +128,18 @@ test_init( test->config = config; test->notification_ind = g_mapped_file_new(ni, FALSE, &error); if (test->notification_ind) { + MMSSettings* settings = mms_settings_default_new(config); 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->disp = mms_dispatcher_new(settings, 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); + mms_settings_unref(settings); test->ret = RET_ERR; ok = TRUE; } else { diff --git a/mms-lib/test/read_ind/test_read_ind.c b/mms-lib/test/read_ind/test_read_ind.c index 15c9e22..798dead 100644 --- a/mms-lib/test/read_ind/test_read_ind.c +++ b/mms-lib/test/read_ind/test_read_ind.c @@ -18,6 +18,7 @@ #include "mms_file_util.h" #include "mms_lib_log.h" #include "mms_lib_util.h" +#include "mms_settings.h" #include "mms_dispatcher.h" #define RET_OK (0) @@ -127,16 +128,18 @@ test_init( test->config = config; test->notification_ind = g_mapped_file_new(ni, FALSE, &error); if (test->notification_ind) { + MMSSettings* settings = mms_settings_default_new(config); 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->disp = mms_dispatcher_new(settings, 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); + mms_settings_unref(settings); test->ret = RET_ERR; ok = TRUE; } else { diff --git a/mms-lib/test/read_report/test_read_report.c b/mms-lib/test/read_report/test_read_report.c index 3a8c036..21d422b 100644 --- a/mms-lib/test/read_report/test_read_report.c +++ b/mms-lib/test/read_report/test_read_report.c @@ -20,6 +20,7 @@ #include "mms_codec.h" #include "mms_lib_log.h" #include "mms_lib_util.h" +#include "mms_settings.h" #include "mms_dispatcher.h" #include @@ -91,15 +92,17 @@ test_init( Test* test, const MMSConfig* config) { + MMSSettings* settings = mms_settings_default_new(config); test->cm = mms_connman_test_new(); test->handler = mms_handler_test_new(); - test->disp = mms_dispatcher_new(config, test->cm, test->handler); + test->disp = mms_dispatcher_new(settings, 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->http = test_http_new(NULL, NULL, SOUP_STATUS_OK); mms_connman_test_set_port(test->cm, test_http_get_port(test->http), TRUE); + mms_settings_unref(settings); test->ret = RET_ERR; } diff --git a/mms-lib/test/resize/test_resize.c b/mms-lib/test/resize/test_resize.c index f1593c7..dc8e961 100644 --- a/mms-lib/test/resize/test_resize.c +++ b/mms-lib/test/resize/test_resize.c @@ -13,10 +13,10 @@ */ #include "mms_attachment.h" +#include "mms_settings.h" #include "mms_lib_util.h" #include "mms_lib_log.h" #include "mms_file_util.h" -#include "mms_log.h" #include #include @@ -361,17 +361,18 @@ test_run_one( if (mms_file_copy(test->file, testfile, NULL)) { MMSAttachment* at; MMSAttachmentInfo info; - MMSConfig test_config = *config; - test_config.max_pixels = test->max_pixels; + MMSSettingsSimData sim_settings; + mms_settings_sim_data_default(&sim_settings); + sim_settings.max_pixels = test->max_pixels; info.file_name = testfile; info.content_type = test->type->content_type; info.content_id = name; - at = mms_attachment_new(&test_config, &info, &error); + at = mms_attachment_new(config, &info, &error); if (at) { int i; gboolean ok = TRUE; for (i=0; isteps && ok; i++) { - if (!mms_attachment_resize(at)) { + if (!mms_attachment_resize(at, &sim_settings)) { ok = FALSE; } } diff --git a/mms-lib/test/retrieve/test_retrieve.c b/mms-lib/test/retrieve/test_retrieve.c index e563c51..2472608 100644 --- a/mms-lib/test/retrieve/test_retrieve.c +++ b/mms-lib/test/retrieve/test_retrieve.c @@ -20,6 +20,7 @@ #include "mms_file_util.h" #include "mms_lib_log.h" #include "mms_lib_util.h" +#include "mms_settings.h" #include "mms_dispatcher.h" #include @@ -438,11 +439,12 @@ test_init( if (rc) test->retrieve_conf = g_mapped_file_new(rc, FALSE, &error); if (test->retrieve_conf || !rc) { guint port; + MMSSettings* settings = mms_settings_default_new(config); g_mapped_file_ref(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->disp = mms_dispatcher_new(settings, 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; @@ -454,6 +456,7 @@ test_init( if (desc->flags & TEST_DEFER_RECEIVE) { mms_handler_test_defer_receive(test->handler, test->disp); } + mms_settings_unref(settings); test->ret = RET_ERR; ok = TRUE; } else { diff --git a/mms-lib/test/retrieve_cancel/test_retrieve_cancel.c b/mms-lib/test/retrieve_cancel/test_retrieve_cancel.c index 4580a2e..5d3b363 100644 --- a/mms-lib/test/retrieve_cancel/test_retrieve_cancel.c +++ b/mms-lib/test/retrieve_cancel/test_retrieve_cancel.c @@ -17,6 +17,7 @@ #include "mms_log.h" #include "mms_lib_util.h" +#include "mms_settings.h" #include "mms_dispatcher.h" #define RET_OK (0) @@ -80,16 +81,18 @@ test_init( const MMSConfig* config, const TestDesc* desc) { + MMSSettings* settings = mms_settings_default_new(config); memset(test, 0, sizeof(*test)); 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->disp = mms_dispatcher_new(settings, test->cm, test->handler); test->pdu = g_bytes_new_static(desc->pdu, desc->pdusize); test->loop = g_main_loop_new(NULL, FALSE); test->delegate.fn_done = test_done; mms_dispatcher_set_delegate(test->disp, &test->delegate); test->timeout_id = g_timeout_add_seconds(10, test_timeout, test); + mms_settings_unref(settings); test->ret = RET_ERR; } diff --git a/mms-lib/test/retrieve_no_proxy/test_retrieve_no_proxy.c b/mms-lib/test/retrieve_no_proxy/test_retrieve_no_proxy.c index ecf4aed..0f4e081 100644 --- a/mms-lib/test/retrieve_no_proxy/test_retrieve_no_proxy.c +++ b/mms-lib/test/retrieve_no_proxy/test_retrieve_no_proxy.c @@ -21,6 +21,7 @@ #include "mms_file_util.h" #include "mms_lib_log.h" #include "mms_lib_util.h" +#include "mms_settings.h" #include "mms_dispatcher.h" #include @@ -140,15 +141,17 @@ test_init( char* port_string; char* push_data; gsize push_len; + MMSSettings* settings = mms_settings_default_new(config); test->cm = mms_connman_test_new(); test->handler = mms_handler_test_new(); - test->disp = mms_dispatcher_new(config, test->cm, test->handler); + test->disp = mms_dispatcher_new(settings, 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->http = test_http_new(test->retrieve_conf, MMS_CONTENT_TYPE, SOUP_STATUS_OK); + port = test_http_get_port(test->http); mms_connman_test_set_port(test->cm, port, FALSE); port_string = g_strdup_printf("%u", port); @@ -161,6 +164,7 @@ test_init( g_free(push_data); g_free(port_string); + mms_settings_unref(settings); test->ret = RET_ERR; ok = TRUE; } else { diff --git a/mms-lib/test/send/test_send.c b/mms-lib/test/send/test_send.c index 2cc1312..07bf486 100644 --- a/mms-lib/test/send/test_send.c +++ b/mms-lib/test/send/test_send.c @@ -21,6 +21,7 @@ #include "mms_file_util.h" #include "mms_lib_log.h" #include "mms_lib_util.h" +#include "mms_settings.h" #include "mms_dispatcher.h" #include @@ -331,6 +332,7 @@ test_init( 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; inparts; i++) { @@ -343,7 +345,7 @@ test_init( 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->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); @@ -354,7 +356,14 @@ test_init( if (desc->flags & TEST_FLAG_CANCEL) { mms_connman_test_set_connect_callback(test->cm, test_cancel, test); } - if (desc->size_limit) config->size_limit = desc->size_limit; + 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; }