Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #38 from monich/mms_settings
Support for persistent per-SIM settings
  • Loading branch information
monich committed May 12, 2014
2 parents c8b209d + 5ac2cb8 commit d08067e
Show file tree
Hide file tree
Showing 38 changed files with 592 additions and 223 deletions.
58 changes: 27 additions & 31 deletions mms-engine/main.c
Expand Up @@ -19,18 +19,19 @@
#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)

/* 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 */
Expand Down Expand Up @@ -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));

Expand All @@ -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,
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
25 changes: 21 additions & 4 deletions mms-engine/mms_engine.c
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down
7 changes: 5 additions & 2 deletions mms-engine/mms_engine.h
Expand Up @@ -15,22 +15,25 @@
#ifndef JOLLA_MMS_ENGINE_H
#define JOLLA_MMS_ENGINE_H

#include <glib.h>
#include <gio/gio.h>
#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_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);
Expand Down
31 changes: 25 additions & 6 deletions mms-lib/Makefile
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion mms-lib/include/mms_dispatcher.h
Expand Up @@ -28,7 +28,7 @@ struct mms_dispatcher_delegate {

MMSDispatcher*
mms_dispatcher_new(
const MMSConfig* config,
MMSSettings* settings,
MMSConnMan* cm,
MMSHandler* handler);

Expand Down
16 changes: 3 additions & 13 deletions mms-lib/include/mms_lib_types.h
Expand Up @@ -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 */
Expand All @@ -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;
Expand Down

0 comments on commit d08067e

Please sign in to comment.