Commit a09d8218 authored by Slava Monich's avatar Slava Monich

Initial commit

parent ed0b26f0
*~
mms-engine/mms-engine.pro.user
mms-engine/build
mms-lib/mms-lib.pro.user
mms-lib/build
mms-lib/test/coverage/full.gcov
mms-lib/test/coverage/mms-lib.gcov
mms-lib/test/coverage/results
mms-lib/test/mms_codec/build
mms-lib/test/mms_lib_test.ncb
mms-lib/test/mms_lib_test.opt
mms-lib/test/read_report/build
mms-lib/test/retrieve/build
mms-lib/test/retrieve_cancel/build
mms-ofono/mms-ofono.pro.user
mms-ofono/build
mms-handler-dbus/mms-handler-dbus.pro.user
mms-handler-dbus/build
mms-handler-dbus/test/mms_handler_dbus_server/build
mms-handler-dbus/test/mms_handler_dbus_server/test_mms_handler_dbus_server.pro.user
mms-handler-dbus/test/mms_handler_dbus_client/build
mms-dump/build
mms-dump/mms_dump.ncb
mms-dump/mms_dump.opt
MMS engine.
Copyright (C) 2013-2014 Jolla Ltd.
Copyright (C) 2010-2011 Intel Corporation.
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.
# -*- Mode: makefile -*-
.PHONY: all debug release clean
# Required packages
PKGS = glib-2.0 libwspcodec
LIB_PKGS = $(PKGS)
#
# Default target
#
all: debug release
#
# Sources
#
SRC = mms-dump.c
#
# Directories
#
SRC_DIR = .
BUILD_DIR = build
DEBUG_BUILD_DIR = $(BUILD_DIR)/debug
RELEASE_BUILD_DIR = $(BUILD_DIR)/release
#
# Tools and flags
#
CC = $(CROSS_COMPILE)gcc
LD = $(CC)
DEBUG_FLAGS = -g
RELEASE_FLAGS = -O2
DEBUG_DEFS = -DDEBUG
RELEASE_DEFS =
WARNINGS = -Wall
CFLAGS = $(shell pkg-config --cflags $(PKGS)) -MMD
LIBS = $(shell pkg-config --libs $(LIB_PKGS))
DEBUG_CFLAGS = $(WARNINGS) $(DEBUG_FLAGS) $(DEBUG_DEFS) $(CFLAGS)
RELEASE_CFLAGS = $(WARNINGS) $(RELEASE_FLAGS) $(RELEASE_DEFS) $(CFLAGS)
DEBUG_LIBS = $(LIBS)
RELEASE_LIBS = $(LIBS)
#
# Files
#
DEBUG_OBJS = $(SRC:%.c=$(DEBUG_BUILD_DIR)/%.o)
RELEASE_OBJS = $(SRC:%.c=$(RELEASE_BUILD_DIR)/%.o)
#
# Dependencies
#
DEBUG_EXE_DEPS = $(DEBUG_BUILD_DIR)
RELEASE_EXE_DEPS = $(RELEASE_BUILD_DIR)
DEPS = $(DEBUG_OBJS:%.o=%.d) $(RELEASE_OBJS:%.o=%.d)
ifneq ($(MAKECMDGOALS),clean)
ifneq ($(strip $(DEPS)),)
-include $(DEPS)
endif
endif
#
# Rules
#
EXE = mms-dump
DEBUG_EXE = $(DEBUG_BUILD_DIR)/$(EXE)
RELEASE_EXE = $(RELEASE_BUILD_DIR)/$(EXE)
debug: $(DEBUG_EXE)
release: $(RELEASE_EXE)
clean:
rm -fr $(BUILD_DIR) $(SRC_DIR)/*~
$(DEBUG_BUILD_DIR):
mkdir -p $@
$(RELEASE_BUILD_DIR):
mkdir -p $@
$(DEBUG_BUILD_DIR)/%.o : $(SRC_DIR)/%.c
$(CC) -c $(DEBUG_CFLAGS) -MT"$@" -MF"$(@:%.o=%.d)" $< -o $@
$(RELEASE_BUILD_DIR)/%.o : $(SRC_DIR)/%.c
$(CC) -c $(RELEASE_CFLAGS) -MT"$@" -MF"$(@:%.o=%.d)" $< -o $@
$(DEBUG_EXE): $(DEBUG_EXE_DEPS) $(DEBUG_OBJS)
$(LD) $(DEBUG_FLAGS) $(DEBUG_OBJS) $(DEBUG_LIBS) -o $@
$(RELEASE_EXE): $(RELEASE_EXE_DEPS) $(RELEASE_OBJS)
$(LD) $(RELEASE_FLAGS) $(RELEASE_OBJS) $(RELEASE_LIBS) -o $@
strip $@
This diff is collapsed.
# -*- Mode: makefile -*-
.PHONY: all debug release clean cleaner
.PHONY: mms_lib_debug_lib mms_lib_release_lib
.PHONY: mms_ofono_debug_lib mms_ofono_release_lib
.PHONY: mms_handler_debug_lib mms_handler_release_lib
# Required packages
PKGS = gio-unix-2.0 gio-2.0 glib-2.0
LIB_PKGS = libwspcodec libsoup-2.4 $(PKGS)
#
# Default target
#
all: debug release
#
# Sources
#
SRC = main.c mms_engine.c
GEN_SRC = org.nemomobile.MmsEngine.c
#
# Directories
#
SRC_DIR = .
BUILD_DIR = build
SPEC_DIR = .
GEN_DIR = $(BUILD_DIR)
DEBUG_BUILD_DIR = $(BUILD_DIR)/debug
RELEASE_BUILD_DIR = $(BUILD_DIR)/release
#
# mms-lib
#
MMS_LIB_LIB = libmms.a
MMS_LIB_DIR = ../mms-lib
MMS_LIB_BUILD_DIR = $(MMS_LIB_DIR)/build
MMS_LIB_DEBUG_LIB = $(MMS_LIB_BUILD_DIR)/debug/$(MMS_LIB_LIB)
MMS_LIB_RELEASE_LIB = $(MMS_LIB_BUILD_DIR)/release/$(MMS_LIB_LIB)
#
# mms-ofono
#
MMS_OFONO_LIB = libmms-ofono.a
MMS_OFONO_DIR = ../mms-ofono
MMS_OFONO_BUILD_DIR = $(MMS_OFONO_DIR)/build
MMS_OFONO_DEBUG_LIB = $(MMS_OFONO_BUILD_DIR)/debug/$(MMS_OFONO_LIB)
MMS_OFONO_RELEASE_LIB = $(MMS_OFONO_BUILD_DIR)/release/$(MMS_OFONO_LIB)
#
# mms-handler-dbus
#
MMS_HANDLER_LIB = libmms-handler-dbus.a
MMS_HANDLER_DIR = ../mms-handler-dbus
MMS_HANDLER_BUILD_DIR = $(MMS_HANDLER_DIR)/build
MMS_HANDLER_DEBUG_LIB = $(MMS_HANDLER_BUILD_DIR)/debug/$(MMS_HANDLER_LIB)
MMS_HANDLER_RELEASE_LIB = $(MMS_HANDLER_BUILD_DIR)/release/$(MMS_HANDLER_LIB)
#
# Tools and flags
#
CC = $(CROSS_COMPILE)gcc
LD = $(CC)
DEBUG_FLAGS = -g
RELEASE_FLAGS = -O2
DEBUG_DEFS = -DDEBUG
RELEASE_DEFS =
WARN = -Wall
CFLAGS = $(shell pkg-config --cflags $(PKGS)) -I. -I$(GEN_DIR) \
-I$(MMS_LIB_DIR)/include -I$(MMS_OFONO_DIR)/include \
-I$(MMS_HANDLER_DIR)/include -MMD
DEBUG_CFLAGS = $(DEBUG_FLAGS) $(DEBUG_DEFS) $(CFLAGS)
RELEASE_CFLAGS = $(RELEASE_FLAGS) $(RELEASE_DEFS) $(CFLAGS)
LIBS = $(shell pkg-config --libs $(LIB_PKGS))
DEBUG_LIBS = \
$(MMS_OFONO_DEBUG_LIB) \
$(MMS_HANDLER_DEBUG_LIB) \
$(MMS_LIB_DEBUG_LIB) \
$(LIBS)
RELEASE_LIBS = \
$(MMS_OFONO_RELEASE_LIB) \
$(MMS_HANDLER_RELEASE_LIB) \
$(MMS_LIB_RELEASE_LIB) \
$(LIBS)
#
# Files
#
.PRECIOUS: $(GEN_SRC:%=$(GEN_DIR)/%)
DEBUG_OBJS = \
$(GEN_SRC:%.c=$(DEBUG_BUILD_DIR)/%.o) \
$(SRC:%.c=$(DEBUG_BUILD_DIR)/%.o)
RELEASE_OBJS = \
$(GEN_SRC:%.c=$(RELEASE_BUILD_DIR)/%.o) \
$(SRC:%.c=$(RELEASE_BUILD_DIR)/%.o)
#
# Dependencies
#
DEBUG_DEPS = \
mms_lib_debug_lib \
mms_ofono_debug_lib \
mms_handler_debug_lib
RELEASE_DEPS = \
mms_lib_release_lib \
mms_ofono_release_lib \
mms_handler_release_lib
DEBUG_EXE_DEPS = \
$(MMS_LIB_DEBUG_LIB) \
$(MMS_OFONO_DEBUG_LIB) \
$(MMS_HANDLER_DEBUG_LIB) \
$(DEBUG_BUILD_DIR)
RELEASE_EXE_DEPS = \
$(MMS_LIB_RELEASE_LIB) \
$(MMS_OFONO_RELEASE_LIB) \
$(MMS_HANDLER_RELEASE_LIB) \
$(RELEASE_BUILD_DIR)
DEPS = $(DEBUG_OBJS:%.o=%.d) $(RELEASE_OBJS:%.o=%.d)
ifneq ($(MAKECMDGOALS),clean)
ifneq ($(strip $(DEPS)),)
-include $(DEPS)
endif
endif
#
# Rules
#
EXE = mms-engine
DEBUG_EXE = $(DEBUG_BUILD_DIR)/$(EXE)
RELEASE_EXE = $(RELEASE_BUILD_DIR)/$(EXE)
debug: $(DEBUG_DEPS) $(DEBUG_EXE)
release: $(RELEASE_DEPS) $(RELEASE_EXE)
clean:
rm -fr $(BUILD_DIR) $(SRC_DIR)/*~
cleaner: clean
make -C $(MMS_LIB_DIR) clean
make -C $(MMS_OFONO_DIR) clean
make -C $(MMS_HANDLER_DIR) clean
$(GEN_DIR):
mkdir -p $@
$(DEBUG_BUILD_DIR):
mkdir -p $@
$(RELEASE_BUILD_DIR):
mkdir -p $@
mms_lib_debug_lib:
make -C $(MMS_LIB_DIR) debug
mms_lib_release_lib:
make -C $(MMS_LIB_DIR) release
mms_ofono_debug_lib:
make -C $(MMS_OFONO_DIR) debug
mms_ofono_release_lib:
make -C $(MMS_OFONO_DIR) release
mms_handler_debug_lib:
make -C $(MMS_HANDLER_DIR) debug
mms_handler_release_lib:
make -C $(MMS_HANDLER_DIR) release
$(MMS_LIB_DEBUG_LIB): mms_lib_debug_lib
$(MMS_LIB_RELEASE_LIB): mms_lib_release_lib
$(MMS_OFONO_DEBUG_LIB): mms_ofono_debug_lib
$(MMS_OFONO_RELEASE_LIB): mms_ofono_release_lib
$(MMS_HANDLER_DEBUG_LIB): mms_handler_debug_lib
$(MMS_HANDLER_RELEASE_LIB): mms_handler_release_lib
$(GEN_DIR)/%.c: $(SPEC_DIR)/%.xml
gdbus-codegen --generate-c-code $(@:%.c=%) $<
$(DEBUG_BUILD_DIR)/%.o : $(SRC_DIR)/%.c
$(CC) -c $(WARN) $(DEBUG_CFLAGS) -MT"$@" -MF"$(@:%.o=%.d)" $< -o $@
$(RELEASE_BUILD_DIR)/%.o : $(SRC_DIR)/%.c
$(CC) -c $(WARN) $(RELEASE_CFLAGS) -MT"$@" -MF"$(@:%.o=%.d)" $< -o $@
$(DEBUG_BUILD_DIR)/%.o : $(GEN_DIR)/%.c
$(CC) -c $(DEBUG_CFLAGS) -MT"$@" -MF"$(@:%.o=%.d)" $< -o $@
$(RELEASE_BUILD_DIR)/%.o : $(GEN_DIR)/%.c
$(CC) -c $(RELEASE_CFLAGS) -MT"$@" -MF"$(@:%.o=%.d)" $< -o $@
$(DEBUG_EXE): $(DEBUG_EXE_DEPS) $(DEBUG_OBJS)
$(LD) $(DEBUG_FLAGS) $(DEBUG_OBJS) $(DEBUG_LIBS) -o $@
$(RELEASE_EXE): $(RELEASE_EXE_DEPS) $(RELEASE_OBJS)
$(LD) $(RELEASE_FLAGS) $(RELEASE_OBJS) $(RELEASE_LIBS) -o $@
strip $@
/*
* Copyright (C) 2013-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 <syslog.h>
#include <glib-unix.h>
#include "mms_engine.h"
#include "mms_ofono_log.h"
#include "mms_lib_log.h"
#include "mms_lib_util.h"
#include "mms_dispatcher.h"
/* Options configurable from the command line */
typedef struct mms_app_options {
GBusType bus_type;
gboolean keep_running;
MMSConfig config;
} MMSAppOptions;
/* All known log modules */
static MMSLogModule* mms_app_log_modules[] = {
&mms_log_default,
#define MMS_LIB_LOG_MODULE(m) &(m),
MMS_LIB_LOG_MODULES(MMS_LIB_LOG_MODULE)
MMS_OFONO_LOG_MODULES(MMS_LIB_LOG_MODULE)
#undef MMS_LIB_LOG_MODULE
};
/* Signal handler */
static
gboolean
mms_app_signal(
gpointer arg)
{
GMainLoop* loop = arg;
MMS_INFO("Caught signal, shutting down...");
if (loop) {
g_idle_add((GSourceFunc)g_main_loop_quit, loop);
} else {
exit(0);
}
return FALSE;
}
/* D-Bus event handlers */
static
void
mms_app_bus_acquired(
GDBusConnection* bus,
const gchar* name,
gpointer arg)
{
MMSEngine* engine = arg;
GError* error = NULL;
MMS_DEBUG("Bus acquired, starting...");
if (!mms_engine_register(engine, bus, &error)) {
MMS_ERR("Could not start: %s", MMS_ERRMSG(error));
g_error_free(error);
mms_engine_stop(engine);
}
}
static
void
mms_app_name_acquired(
GDBusConnection* bus,
const gchar* name,
gpointer arg)
{
MMS_DEBUG("Acquired service name '%s'", name);
}
static
void
mms_app_name_lost(
GDBusConnection* bus,
const gchar* name,
gpointer arg)
{
MMSEngine* engine = arg;
MMS_ERR("'%s' service already running or access denied", name);
mms_engine_stop(engine);
}
/* Option parsing callbacks */
static
gboolean
mms_app_option_loglevel(
const gchar* name,
const gchar* value,
gpointer data,
GError** error)
{
return mms_log_parse_option(value, mms_app_log_modules,
G_N_ELEMENTS(mms_app_log_modules), error);
}
static
gboolean
mms_app_option_logtype(
const gchar* name,
const gchar* value,
gpointer data,
GError** error)
{
if (mms_log_set_type(value, MMS_APP_LOG_PREFIX)) {
return TRUE;
} else {
if (error) {
*error = g_error_new(G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE,
"Invalid log type \'%s\'", value);
}
return FALSE;
}
}
static
gboolean
mms_app_option_verbose(
const gchar* name,
const gchar* value,
gpointer data,
GError** error)
{
mms_log_default.level = MMS_LOGLEVEL_VERBOSE;
return TRUE;
}
/* Parses command line and sets up application options */
static
gboolean
mms_app_parse_options(
MMSAppOptions* opt,
int argc,
char* argv[])
{
gboolean ok;
GError* error = NULL;
gboolean session_bus = FALSE;
char* root_dir_help = g_strdup_printf(
"Root directory for MMS files [%s]",
opt->config.root_dir);
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* description = mms_log_description(mms_app_log_modules,
G_N_ELEMENTS(mms_app_log_modules));
GOptionContext* options;
GOptionEntry entries[] = {
{ "session", 0, 0, G_OPTION_ARG_NONE, &session_bus,
"Use session bus (default is system)", NULL },
{ "root-dir", 'd', 0, G_OPTION_ARG_FILENAME,
(void*)&opt->config.root_dir, root_dir_help, "DIR" },
{ "retry-secs", 'r', 0, G_OPTION_ARG_INT,
&opt->config.retry_secs, retry_secs_help, "SEC" },
{ "idle-secs", 'i', 0, G_OPTION_ARG_INT,
&opt->config.idle_secs, idle_secs_help, "SEC" },
{ "keep-running", 'k', 0, G_OPTION_ARG_NONE, &opt->keep_running,
"Keep running after everything is done", NULL },
{ "keep-temp-files", 't', 0, G_OPTION_ARG_NONE,
&opt->config.keep_temp_files,
"Don't delete temporary files", NULL },
{ "attic", 'a', 0, G_OPTION_ARG_NONE,
&opt->config.attic_enabled,
"Store unrecognized push messages in the attic", NULL },
{ "verbose", 'v', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK,
mms_app_option_verbose, "Be verbose (equivalent to -l=verbose)",
NULL },
{ "log-output", 'o', 0, G_OPTION_ARG_CALLBACK, mms_app_option_logtype,
"Log output [stdout]", "<stdout|syslog|glib>" },
{ "log-level", 'l', 0, G_OPTION_ARG_CALLBACK, mms_app_option_loglevel,
"Set log level (repeatable)", "[MODULE:]LEVEL" },
{ NULL }
};
options = g_option_context_new("- part of Jolla MMS system");
g_option_context_add_main_entries(options, entries, NULL);
g_option_context_set_description(options, description);
ok = g_option_context_parse(options, &argc, &argv, &error);
g_option_context_free(options);
g_free(root_dir_help);
g_free(retry_secs_help);
g_free(idle_secs_help);
g_free(description);
if (ok) {
MMS_INFO("Starting");
if (session_bus) {
MMS_DEBUG("Attaching to session bus");
opt->bus_type = G_BUS_TYPE_SESSION;
} else {
MMS_DEBUG("Attaching to system bus");
opt->bus_type = G_BUS_TYPE_SYSTEM;
}
return TRUE;
} else {
fprintf(stderr, "%s\n", MMS_ERRMSG(error));
g_error_free(error);
return FALSE;
}
}
int main(int argc, char* argv[])
{
int result = 1;
MMSAppOptions opt = {0};
mms_lib_init();
mms_log_default.name = MMS_APP_LOG_PREFIX;
mms_lib_default_config(&opt.config);
if (mms_app_parse_options(&opt, argc, argv)) {
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,
mms_app_log_modules, G_N_ELEMENTS(mms_app_log_modules));
if (engine) {
guint name_id;
/* Setup main loop */
GMainLoop* loop = g_main_loop_new(NULL, FALSE);
g_unix_signal_add(SIGTERM, mms_app_signal, loop);
g_unix_signal_add(SIGINT, mms_app_signal, loop);
/* Acquire name, don't allow replacement */
name_id = g_bus_own_name(opt.bus_type, MMS_ENGINE_SERVICE,
G_BUS_NAME_OWNER_FLAGS_REPLACE, mms_app_bus_acquired,
mms_app_name_acquired, mms_app_name_lost, engine, NULL);
/* Run the main loop */
mms_engine_run(engine, loop);
/* Cleanup and exit */
g_bus_unown_name(name_id);
g_main_loop_unref(loop);
mms_engine_unref(engine);
}
MMS_INFO("Exiting");
result = 0;
}
if (mms_log_func == mms_log_syslog) {
closelog();
}
return result;
}
<!DOCTYPE busconfig PUBLIC
"-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
<!-- This file goes to /etc/dbus-1/system.d */
<busconfig>
<policy user="nemo">
<allow own="com.jolla.mms.handler"/>
</policy>
<policy user="root">
<allow own="com.jolla.mms.handler"/>
<allow send_destination="com.jolla.mms.handler"
send_interface="com.jolla.mms.handler"/>
</policy>
<!-- allow radio user (ofono) signaling -->
<policy user="radio">
<allow send_destination="com.jolla.mms.handler"/>
</policy>
</busconfig>
TEMPLATE = app
CONFIG -= qt
CONFIG += link_pkgconfig
PKGCONFIG += libsoup-2.4 gio-unix-2.0 gio-2.0 glib-2.0 dbus-1 libwspcodec
DBUS_INTERFACE_DIR = $$_PRO_FILE_PWD_
MMS_LIB_DIR = $$_PRO_FILE_PWD_/../mms-lib
MMS_OFONO_DIR = $$_PRO_FILE_PWD_/../mms-ofono
MMS_HANDLER_DIR = $$_PRO_FILE_PWD_/../mms-handler-dbus
INCLUDEPATH += $$MMS_OFONO_DIR/include
INCLUDEPATH += $$MMS_LIB_DIR/include
INCLUDEPATH += $$MMS_HANDLER_DIR/include
QMAKE_CFLAGS += -Wno-unused
SOURCES += \
main.c \
mms_engine.c
HEADERS += \
mms_engine.h
OTHER_FILES += \
org.nemomobile.MmsEngine.push.conf \
org.nemomobile.MmsEngine.dbus.conf \
org.nemomobile.MmsEngine.service \
org.nemomobile.MmsEngine.xml
CONFIG(debug, debug|release) {
DEFINES += DEBUG
DESTDIR = $$_PRO_FILE_PWD_/build/debug
LIBS += $$MMS_OFONO_DIR/build/debug/libmms-ofono.a
LIBS += $$MMS_HANDLER_DIR/build/debug/libmms-handler-dbus.a
LIBS += $$MMS_LIB_DIR/build/debug/libmms-lib.a
} else {
DESTDIR = $$_PRO_FILE_PWD_/build/release