[-]
[+]
|
Changed |
_service:tar_git:ofono.changes
|
|
[-]
[+]
|
Changed |
_service:tar_git:ofono.spec
^
|
|
[-]
[+]
|
Changed |
_service
^
|
@@ -2,6 +2,6 @@
<service name="tar_git">
<param name="url">https://git.merproject.org/slava/ofono.git</param>
<param name="branch">master</param>
- <param name="revision">mer/1.19+git34</param>
+ <param name="revision">mer/1.19+git37</param>
</service>
</services>
|
[-]
[+]
|
Changed |
_service:tar_git:ofono-1.19+git37.tar.bz2/ofono/.gitignore
^
|
@@ -42,6 +42,7 @@
unit/test-caif
unit/test-stkutil
unit/test-cdmasms
+unit/test-ril_util
unit/test-rilmodem-cb
unit/test-rilmodem-cs
unit/test-rilmodem-gprs
@@ -49,6 +50,7 @@
unit/test-sailfish_cell_info
unit/test-sailfish_manager
unit/test-sailfish_sim_info
+unit/test-sms-filter
unit/test-*.log
unit/test-*.trs
@@ -63,6 +65,9 @@
drivers/*/*.gcda
drivers/*/*.gcno
drivers/*/*.gcov
+plugins/*/*.gcda
+plugins/*/*.gcno
+plugins/*/*.gcov
*/*.gcda
*/*.gcno
*/*.gcov
|
[-]
[+]
|
Changed |
_service:tar_git:ofono-1.19+git37.tar.bz2/ofono/Makefile.am
^
|
@@ -23,6 +23,7 @@
include/cdma-provision.h include/handsfree.h \
include/sim-mnclength.h \
include/handsfree-audio.h include/siri.h \
+ include/sms-filter.h \
include/netmon.h
nodist_pkginclude_HEADERS = include/version.h
@@ -701,6 +702,7 @@
src/cdma-provision.c src/handsfree.c \
src/handsfree-audio.c src/bluetooth.h \
src/sim-mnclength.c src/voicecallagent.c \
+ src/sms-filter.c \
src/hfp.h src/siri.c \
src/netmon.c
@@ -878,7 +880,7 @@
unit_tests = unit/test-common unit/test-util unit/test-idmap \
unit/test-simutil unit/test-stkutil \
unit/test-sms unit/test-cdmasms \
- unit/test-provision
+ unit/test-provision unit/test-sms-filter
if SAILFISH_MANAGER
@@ -917,6 +919,14 @@
if RILMODEM
if SAILFISH_RILMODEM
+unit_test_ril_util_SOURCES = unit/test-ril_util.c drivers/ril/ril_util.c \
+ src/log.c
+unit_test_ril_util_CFLAGS = $(COVERAGE_OPT) $(AM_CFLAGS)
+unit_test_ril_util_LDADD = @GLIB_LIBS@ -ldl
+unit_objects += $(unit_test_ril_util_OBJECTS)
+unit_tests += unit/test-ril_util
+
+else
unit_tests += unit/test-rilmodem-cs \
unit/test-rilmodem-cs \
unit/test-rilmodem-sms \
@@ -993,6 +1003,12 @@
unit_test_provision_LDADD = @GLIB_LIBS@ -ldl
unit_objects += $(unit_test_provision_OBJECTS)
+unit_test_sms_filter_SOURCES = unit/test-sms-filter.c \
+ src/sms-filter.c src/log.c
+unit_test_sms_filter_CFLAGS = $(COVERAGE_OPT) $(AM_CFLAGS)
+unit_test_sms_filter_LDADD = @GLIB_LIBS@ -ldl
+unit_objects += $(unit_test_sms_filter_OBJECTS)
+
test_rilmodem_sources = $(gril_sources) src/log.c src/common.c src/util.c \
gatchat/ringbuffer.h gatchat/ringbuffer.c \
unit/rilmodem-test-server.h \
|
[-]
[+]
|
Changed |
_service:tar_git:ofono-1.19+git37.tar.bz2/ofono/configure.ac
^
|
@@ -188,8 +188,8 @@
AC_MSG_ERROR(libgrilio >= 1.0.18 is required))
PKG_CHECK_MODULES(GLIBUTIL, libglibutil >= 1.0.23, dummy=yes,
AC_MSG_ERROR(libglibutil >= 1.0.23 is required))
- PKG_CHECK_MODULES(LIBMCE, libmce-glib, dummy=yes,
- AC_MSG_ERROR(libmce-glib is required))
+ PKG_CHECK_MODULES(LIBMCE, libmce-glib >= 1.0.5, dummy=yes,
+ AC_MSG_ERROR(libmce-glib >= 1.0.5 is required))
CFLAGS="$CFLAGS $GRILIO_CFLAGS $LIBMCE_CFLAGS"
LIBS="$LIBS $GRILIO_LIBS $LIBMCE_LIBS"
enable_sailfish_manager=yes
|
[-]
[+]
|
Changed |
_service:tar_git:ofono-1.19+git37.tar.bz2/ofono/drivers/atmodem/sim.c
^
|
@@ -1293,14 +1293,15 @@
struct cb_data *cbd = user_data;
struct sim_data *sd = cbd->user;
ofono_sim_lock_unlock_cb_t cb = cbd->cb;
+ void *data = cbd->data;
at_util_sim_state_query_free(sd->sim_state_query);
sd->sim_state_query = NULL;
if (present == 1)
- CALLBACK_WITH_SUCCESS(cb, cbd->data);
+ CALLBACK_WITH_SUCCESS(cb, data);
else
- CALLBACK_WITH_FAILURE(cb, cbd->data);
+ CALLBACK_WITH_FAILURE(cb, data);
}
static void at_pin_send_cb(gboolean ok, GAtResult *result,
|
[-]
[+]
|
Changed |
_service:tar_git:ofono-1.19+git37.tar.bz2/ofono/drivers/ril/ril_config.c
^
|
@@ -14,6 +14,7 @@
*/
#include "ril_config.h"
+#include "ril_util.h"
#include "ril_log.h"
#include <gutil_intarray.h>
@@ -190,12 +191,10 @@
GUtilIntArray *array = gutil_int_array_new();
while (*ptr) {
- const char *str = *ptr++;
- char *end = NULL;
- long ival = strtol(str, &end, 0);
+ int val;
- if (str[0] && !end[0]) {
- gutil_int_array_append(array, ival);
+ if (ril_parse_int(*ptr++, 0, &val)) {
+ gutil_int_array_append(array, val);
}
}
|
[-]
[+]
|
Changed |
_service:tar_git:ofono-1.19+git37.tar.bz2/ofono/drivers/ril/ril_network.c
^
|
@@ -208,8 +208,14 @@
reg->max_calls = 2;
}
- reg->lac = slac ? strtol(slac, NULL, 16) : -1;
- reg->ci = sci ? strtol(sci, NULL, 16) : -1;
+ if (!ril_parse_int(slac, 16, ®->lac)) {
+ reg->lac = -1;
+ }
+
+ if (!ril_parse_int(sci, 16, ®->ci)) {
+ reg->ci = -1;
+ }
+
reg->access_tech = ril_parse_tech(stech, ®->ril_tech);
DBG_(self, "%s,%s,%s,%d,%s,%s,%s",
|
[-]
[+]
|
Changed |
_service:tar_git:ofono-1.19+git37.tar.bz2/ofono/drivers/ril/ril_plugin.c
^
|
@@ -2,6 +2,7 @@
* oFono - Open Source Telephony - RIL-based devices
*
* Copyright (C) 2015-2017 Jolla Ltd.
+ * Contact: Slava Monich <slava.monich@jolla.com>
*
* 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
@@ -38,10 +39,14 @@
#include <sys/types.h>
#include <sys/syscall.h>
#include <sys/prctl.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <pwd.h>
+#include <grp.h>
#define OFONO_API_SUBJECT_TO_CHANGE
#include <ofono/plugin.h>
-#include "ofono.h"
+#include "storage.h"
#define OFONO_RADIO_ACCESS_MODE_ALL (OFONO_RADIO_ACCESS_MODE_GSM |\
OFONO_RADIO_ACCESS_MODE_UMTS |\
@@ -49,11 +54,10 @@
#define RIL_DEVICE_IDENTITY_RETRIES_LAST 2
-#define RADIO_GID 1001
-#define RADIO_UID 1001
#define RIL_SUB_SIZE 4
#define RILMODEM_CONF_FILE CONFIGDIR "/ril_subscription.conf"
+#define RILMODEM_DEFAULT_IDENTITY "radio:radio"
#define RILMODEM_DEFAULT_SOCK "/dev/socket/rild"
#define RILMODEM_DEFAULT_SOCK2 "/dev/socket/rild2"
#define RILMODEM_DEFAULT_SUB "SUB1"
@@ -77,6 +81,7 @@
* with lower case.
*/
#define RILCONF_SETTINGS_EMPTY "EmptyConfig"
+#define RILCONF_SETTINGS_IDENTITY "Identity"
#define RILCONF_SETTINGS_3GHANDOVER "3GLTEHandover"
#define RILCONF_SETTINGS_SET_RADIO_CAP "SetRadioCapability"
@@ -130,9 +135,15 @@
RIL_SET_RADIO_CAP_DISABLED
};
+struct ril_plugin_identity {
+ uid_t uid;
+ gid_t gid;
+};
+
struct ril_plugin_settings {
int dm_flags;
enum ril_set_radio_cap_opt set_radio_cap;
+ struct ril_plugin_identity identity;
};
typedef struct sailfish_slot_manager_impl {
@@ -142,6 +153,7 @@
struct ril_plugin_settings settings;
gulong caps_manager_event_id;
guint start_timeout_id;
+ MceDisplay *display;
GSList *slots;
} ril_plugin;
@@ -196,6 +208,7 @@
static void ril_debug_grilio_notify(struct ofono_debug_desc *desc);
static void ril_debug_mce_notify(struct ofono_debug_desc *desc);
static void ril_plugin_debug_notify(struct ofono_debug_desc *desc);
+static void ril_plugin_drop_orphan_slots(ril_plugin *plugin);
static void ril_plugin_retry_init_io(ril_slot *slot);
static void ril_plugin_check_modem(ril_slot *slot);
@@ -759,6 +772,19 @@
}
}
+static void ril_plugin_manager_started(ril_plugin *plugin)
+{
+ ril_plugin_drop_orphan_slots(plugin);
+ sailfish_slot_manager_started(plugin->handle);
+
+ /*
+ * We no longer need this MceDisplay reference, the slots
+ * (if there are any) are holding references of their own.
+ */
+ mce_display_unref(plugin->display);
+ plugin->display = NULL;
+}
+
static void ril_plugin_all_slots_started_cb(ril_slot *slot, void *param)
{
if (!slot->handle) {
@@ -778,7 +804,7 @@
g_source_remove(plugin->start_timeout_id);
/* id is zeroed by ril_plugin_manager_start_done */
GASSERT(!plugin->start_timeout_id);
- sailfish_slot_manager_started(plugin->handle);
+ ril_plugin_manager_started(plugin);
}
}
}
@@ -995,7 +1021,7 @@
g_free(slot->sockpath);
g_free(slot->sub);
g_free(slot->ecclist_file);
- g_slice_free(ril_slot, slot);
+ g_free(slot);
}
static gboolean ril_plugin_slot_start_timeout(gpointer user_data)
@@ -1323,6 +1349,60 @@
return number;
}
+static void ril_plugin_parse_identity(struct ril_plugin_identity *identity,
+ const char *value)
+{
+ char *sep = strchr(value, ':');
+ const char *user = value;
+ const char *group = NULL;
+ char *tmp_user = NULL;
+ const struct passwd *pw = NULL;
+ const struct group *gr = NULL;
+
+ if (sep) {
+ /* Group */
+ group = sep + 1;
+ gr = getgrnam(group);
+ user = tmp_user = g_strndup(value, sep - value);
+
+ if (!gr) {
+ int n;
+
+ /* Try numeric */
+ if (ril_parse_int(group, 0, &n)) {
+ gr = getgrgid(n);
+ }
+ }
+ }
+
+ /* User */
+ pw = getpwnam(user);
+ if (!pw) {
+ int n;
+
+ /* Try numeric */
+ if (ril_parse_int(user, 0, &n)) {
+ pw = getpwuid(n);
+ }
+ }
+
+ if (pw) {
+ DBG("User %s -> %d", user, pw->pw_uid);
+ identity->uid = pw->pw_uid;
+ } else {
+ ofono_warn("Invalid user '%s'", user);
+ }
+
+ if (gr) {
+ DBG("Group %s -> %d", group, gr->gr_gid);
+ identity->gid = gr->gr_gid;
+ } else if (group) {
+ ofono_warn("Invalid group '%s'", group);
+ }
+
+ g_free(tmp_user);
+}
+
static GSList *ril_plugin_parse_config_file(GKeyFile *file,
struct ril_plugin_settings *ps)
{
@@ -1343,6 +1423,7 @@
} else if (!strcmp(group, RILCONF_SETTINGS_GROUP)) {
/* Plugin configuration */
int ival;
+ char *sval;
/* 3GLTEHandover */
ril_config_get_flag(file, group,
@@ -1358,6 +1439,14 @@
"off", RIL_SET_RADIO_CAP_DISABLED, NULL)) {
ps->set_radio_cap = ival;
}
+
+ /* Identity */
+ sval = g_key_file_get_string(file, group,
+ RILCONF_SETTINGS_IDENTITY, NULL);
+ if (sval) {
+ ril_plugin_parse_identity(&ps->identity, sval);
+ g_free(sval);
+ }
}
}
@@ -1403,7 +1492,7 @@
|
[-]
[+]
|
Changed |
_service:tar_git:ofono-1.19+git37.tar.bz2/ofono/drivers/ril/ril_subscription.conf
^
|
@@ -21,6 +21,13 @@
#
#EmptyConfig=false
+# User and group for the ofono process. RIL clients are typically
+# expected to run under radio:radio.
+#
+# Default is radio:radio
+#
+#Identity=radio:radio
+
# If the phone has more than one SIM slot, the 3G/LTE module may be
# shared by all modems, meaning that only one of the slots can use
# 3G/LTE. In order to "hand 4G over" to the other slot, the modem
|
[-]
[+]
|
Changed |
_service:tar_git:ofono-1.19+git37.tar.bz2/ofono/drivers/ril/ril_util.c
^
|
@@ -20,6 +20,8 @@
#include <sys/socket.h>
#include <ctype.h>
+#include <errno.h>
+#include <limits.h>
#include "common.h"
#include "netreg.h"
@@ -324,8 +326,7 @@
{
int access_tech = -1;
int tech = -1;
- if (stech && stech[0]) {
- tech = atoi(stech);
+ if (ril_parse_int(stech, 0, &tech)) {
switch (tech) {
case RADIO_TECH_GPRS:
case RADIO_TECH_GSM:
@@ -382,8 +383,8 @@
if (i == OFONO_MAX_MCC_LENGTH) {
/* Usually 2 but sometimes 3 digit network code */
- for (i=0;
- i<OFONO_MAX_MNC_LENGTH && *ptr && isdigit(*ptr);
+ for (i = 0;
+ i < OFONO_MAX_MNC_LENGTH && *ptr && isdigit(*ptr);
i++) {
op->mnc[i] = *ptr++;
}
@@ -410,6 +411,26 @@
return FALSE;
}
+gboolean ril_parse_int(const char *str, int base, int *value)
+{
+ gboolean ok = FALSE;
+
+ if (str && str[0]) {
+ char *str2 = g_strstrip(g_strdup(str));
+ char *end = str2;
+ long l;
+
+ errno = 0;
+ l = strtol(str2, &end, base);
+ ok = !*end && errno != ERANGE && l >= INT_MIN && l <= INT_MAX;
+ if (ok && value) {
+ *value = (int)l;
+ }
+ g_free(str2);
+ }
+ return ok;
+}
+
/*
* Local Variables:
* mode: C
|
[-]
[+]
|
Changed |
_service:tar_git:ofono-1.19+git37.tar.bz2/ofono/drivers/ril/ril_util.h
^
|
@@ -1,7 +1,7 @@
/*
* oFono - Open Source Telephony - RIL-based devices
*
- * Copyright (C) 2015-2016 Jolla Ltd.
+ * Copyright (C) 2015-2017 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
@@ -26,6 +26,7 @@
const char *ril_radio_state_to_string(int radio_state);
int ril_parse_tech(const char *stech, int *ril_tech);
gboolean ril_parse_mcc_mnc(const char *str, struct ofono_network_operator *op);
+gboolean ril_parse_int(const char *str, int base, int *value);
#define ril_error_init_ok(err) \
((err)->error = 0, (err)->type = OFONO_ERROR_TYPE_NO_ERROR)
|
[-]
[+]
|
Changed |
_service:tar_git:ofono-1.19+git37.tar.bz2/ofono/include/modem.h
^
|
@@ -29,6 +29,7 @@
#include <ofono/types.h>
struct ofono_modem;
+struct ofono_sim;
enum ofono_modem_type {
OFONO_MODEM_TYPE_HARDWARE = 0,
@@ -80,6 +81,7 @@
const char *interface);
const char *ofono_modem_get_path(struct ofono_modem *modem);
+struct ofono_sim *ofono_modem_get_sim(struct ofono_modem *modem);
void ofono_modem_set_data(struct ofono_modem *modem, void *data);
void *ofono_modem_get_data(struct ofono_modem *modem);
|
[-]
[+]
|
Added |
_service:tar_git:ofono-1.19+git37.tar.bz2/ofono/include/sms-filter.h
^
|
@@ -0,0 +1,184 @@
+/*
+ * oFono - Open Source Telephony
+ *
+ * Copyright (C) 2017 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 __OFONO_SMS_FILTER_H
+#define __OFONO_SMS_FILTER_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <ofono/types.h>
+
+struct ofono_modem;
+
+/* 23.040 Section 9.1.2.5 */
+enum ofono_sms_number_type {
+ OFONO_SMS_NUMBER_TYPE_UNKNOWN = 0,
+ OFONO_SMS_NUMBER_TYPE_INTERNATIONAL = 1,
+ OFONO_SMS_NUMBER_TYPE_NATIONAL = 2,
+ OFONO_SMS_NUMBER_TYPE_NETWORK_SPECIFIC = 3,
+ OFONO_SMS_NUMBER_TYPE_SUBSCRIBER = 4,
+ OFONO_SMS_NUMBER_TYPE_ALPHANUMERIC = 5,
+ OFONO_SMS_NUMBER_TYPE_ABBREVIATED = 6,
+ OFONO_SMS_NUMBER_TYPE_RESERVED = 7
+};
+
+/* 23.040 Section 9.1.2.5 */
+enum ofono_sms_numbering_plan {
+ OFONO_SMS_NUMBERING_PLAN_UNKNOWN = 0,
+ OFONO_SMS_NUMBERING_PLAN_ISDN = 1,
+ OFONO_SMS_NUMBERING_PLAN_DATA = 3,
+ OFONO_SMS_NUMBERING_PLAN_TELEX = 4,
+ OFONO_SMS_NUMBERING_PLAN_SC1 = 5,
+ OFONO_SMS_NUMBERING_PLAN_SC2 = 6,
+ OFONO_SMS_NUMBERING_PLAN_NATIONAL = 8,
+ OFONO_SMS_NUMBERING_PLAN_PRIVATE = 9,
+ OFONO_SMS_NUMBERING_PLAN_ERMES = 10,
+ OFONO_SMS_NUMBERING_PLAN_RESERVED = 15
+};
+
+enum ofono_sms_class {
+ OFONO_SMS_CLASS_0 = 0,
+ OFONO_SMS_CLASS_1 = 1,
+ OFONO_SMS_CLASS_2 = 2,
+ OFONO_SMS_CLASS_3 = 3,
+ OFONO_SMS_CLASS_UNSPECIFIED = 4,
+};
+
+struct ofono_sms_address {
+ enum ofono_sms_number_type number_type;
+ enum ofono_sms_numbering_plan numbering_plan;
+ /*
+ * An alphanum TP-OA is 10 7-bit coded octets, which can carry
+ * 11 8-bit characters. 22 bytes + terminator in UTF-8.
+ */
+ char address[23];
+};
+
+struct ofono_sms_scts {
+ unsigned char year;
+ unsigned char month;
+ unsigned char day;
+ unsigned char hour;
+ unsigned char minute;
+ unsigned char second;
+ ofono_bool_t has_timezone;
+ unsigned char timezone;
+};
+
+enum ofono_sms_filter_result {
+ OFONO_SMS_FILTER_DROP, /* Stop processing and drop the message */
+ OFONO_SMS_FILTER_CONTINUE /* Run the next filter */
+};
+
+typedef void (*ofono_sms_filter_send_text_cb_t)
+ (enum ofono_sms_filter_result result,
+ const struct ofono_sms_address *addr,
+ const char *message,
+ void *data);
+
+typedef void (*ofono_sms_filter_send_datagram_cb_t)
+ (enum ofono_sms_filter_result result,
+ const struct ofono_sms_address *addr,
+ int dst_port, int src_port,
+ const unsigned char *buf, unsigned int len,
+ void *data);
+
+typedef void (*ofono_sms_filter_recv_text_cb_t)
+ (enum ofono_sms_filter_result result,
+ const struct ofono_uuid *uuid,
+ const char *message,
+ enum ofono_sms_class cls,
+ const struct ofono_sms_address *addr,
+ const struct ofono_sms_scts *scts,
+ void *data);
+
+typedef void (*ofono_sms_filter_recv_datagram_cb_t)
+ (enum ofono_sms_filter_result result,
+ const struct ofono_uuid *uuid,
+ int dst_port, int src_port,
+ const unsigned char *buf, unsigned int len,
+ const struct ofono_sms_address *addr,
+ const struct ofono_sms_scts *scts,
+ void *data);
+
+#define OFONO_SMS_FILTER_PRIORITY_LOW (-100)
+#define OFONO_SMS_FILTER_PRIORITY_DEFAULT (0)
+#define OFONO_SMS_FILTER_PRIORITY_HIGH (100)
+
+/*
+ * The filter callbacks either invoke the completion callback directly
+ * or return the id of the cancellable asynchronous operation (but never
+ * both). If non-zero value is returned, the completion callback has to
+ * be invoked later on a fresh stack. Once the asynchronous filtering
+ * operation is cancelled, the associated completion callback must not
+ * be invoked.
+ *
+ * The pointers passed to the filter callbacks are guaranteed to be
+ * valid until the filter calls the completion callback. The completion
+ * callback is never NULL.
+ *
+ * Please avoid making blocking D-Bus calls from the filter callbacks.
+ */
+struct ofono_sms_filter {
+ const char *name;
+ int priority;
+ unsigned int (*filter_send_text)(struct ofono_modem *modem,
+ const struct ofono_sms_address *addr,
+ const char *message,
+ ofono_sms_filter_send_text_cb_t cb,
+ void *data);
+ unsigned int (*filter_send_datagram)(struct ofono_modem *modem,
+ const struct ofono_sms_address *addr,
+ int dst_port, int src_port,
+ const unsigned char *buf, unsigned int len,
+ ofono_sms_filter_send_datagram_cb_t cb,
+ void *data);
+ unsigned int (*filter_recv_text)(struct ofono_modem *modem,
+ const struct ofono_uuid *uuid,
+ const char *message,
+ enum ofono_sms_class cls,
+ const struct ofono_sms_address *addr,
+ const struct ofono_sms_scts *scts,
+ ofono_sms_filter_recv_text_cb_t cb,
+ void *data);
+ unsigned int (*filter_recv_datagram)(struct ofono_modem *modem,
+ const struct ofono_uuid *uuid,
+ int dst_port, int src_port,
+ const unsigned char *buf, unsigned int len,
+ const struct ofono_sms_address *addr,
+ const struct ofono_sms_scts *scts,
+ ofono_sms_filter_recv_datagram_cb_t cb,
+ void *data);
+ void (*cancel)(unsigned int id);
+};
+
+int ofono_sms_filter_register(const struct ofono_sms_filter *filter);
+void ofono_sms_filter_unregister(const struct ofono_sms_filter *filter);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __OFONO_SMS_FILTER_H */
+
+/*
+ * Local Variables:
+ * mode: C
+ * c-basic-offset: 8
+ * indent-tabs-mode: t
+ * End:
+ */
|
[-]
[+]
|
Changed |
_service:tar_git:ofono-1.19+git37.tar.bz2/ofono/plugins/mbpi.c
^
|
@@ -39,8 +39,15 @@
#include <ofono/gprs-provision.h>
#ifndef MBPI_DATABASE
-#define MBPI_DATABASE "/usr/share/mobile-broadband-provider-info/" \
+# ifdef PROVIDER_DATABASE
+ /* This one is pulled from mobile-broadband-provider-info.pc
+ * by the configure script, we should trust it. */
+# define MBPI_DATABASE PROVIDER_DATABASE
+# else
+ /* The default one */
+# define MBPI_DATABASE "/usr/share/mobile-broadband-provider-info/" \
"serviceproviders.xml"
+# endif
#endif
#include "mbpi.h"
|
[-]
[+]
|
Changed |
_service:tar_git:ofono-1.19+git37.tar.bz2/ofono/plugins/sailfish_debuglog.c
^
|
@@ -1,8 +1,7 @@
/*
- *
* oFono - Open Source Telephony
*
- * Copyright (C) 2015-2016 Jolla Ltd.
+ * Copyright (C) 2015-2017 Jolla Ltd.
* Contact: Slava Monich <slava.monich@jolla.com>
*
* This program is free software; you can redistribute it and/or modify
@@ -19,10 +18,7 @@
#include <config.h>
#endif
-#define OFONO_API_SUBJECT_TO_CHANGE
-#include <ofono/plugin.h>
-#include <ofono/dbus.h>
-#include <ofono/log.h>
+#include "src/ofono.h"
#include <dbuslog_server_dbus.h>
#include <gutil_log.h>
@@ -113,13 +109,13 @@
return s1 && s2 && !strcmp(s1, s2);
}
-static void debuglog_update_flags(const char* name, guint set, guint clear)
+static void debuglog_update_flags_range(struct ofono_debug_desc *start,
+ struct ofono_debug_desc *stop, const char* name,
+ guint set, guint clear)
{
const guint flags = set | clear;
- struct ofono_debug_desc *start = __start___debug;
- struct ofono_debug_desc *stop = __stop___debug;
- if (start && stop) {
+ if (start && stop && start < stop) {
struct ofono_debug_desc *desc;
for (desc = start; desc < stop; desc++) {
@@ -142,7 +138,44 @@
}
}
}
+}
+
+struct debuglog_update_flags_data {
+ const char* name;
+ guint set;
+ guint clear;
+};
+
+static void debuglog_update_flags_plugin(struct ofono_plugin_desc *desc,
+ int flags, void *user_data)
+{
+ /*
+ * We are only interested in the external plugins here because
+ * they don't fall into __start___debug .. __stop___debug range.
+ */
+ if (!(flags & OFONO_PLUGIN_FLAG_BUILTIN) &&
+ desc->debug_start && desc->debug_stop) {
+ const struct debuglog_update_flags_data *update = user_data;
+
+ debuglog_update_flags_range(desc->debug_start,
+ desc->debug_stop, update->name,
+ update->set, update->clear);
+ }
+}
+static void debuglog_update_flags(const char* name, guint set, guint clear)
+{
+ struct debuglog_update_flags_data update;
+
+ /* Builtin plugins */
+ debuglog_update_flags_range(__start___debug, __stop___debug, name,
+ set, clear);
+
+ /* External plugins */
+ update.name = name;
+ update.set = set;
+ update.clear = clear;
+ __ofono_plugin_foreach(debuglog_update_flags_plugin, &update);
}
static void debuglog_category_enabled(DBusLogServer* server,
@@ -189,15 +222,10 @@
return flags;
}
-static int debuglog_init(void)
+static void debuglog_add_categories(const struct ofono_debug_desc *start,
+ const struct ofono_debug_desc *stop)
{
- const struct ofono_debug_desc *start = __start___debug;
- const struct ofono_debug_desc *stop = __stop___debug;
-
- debuglog_server = dbus_log_server_new(ofono_dbus_get_connection(),
- DEBUGLOG_PATH);
-
- if (start && stop) {
+ if (start && stop && start < stop) {
const struct ofono_debug_desc *desc;
GHashTable *hash = NULL;
@@ -221,19 +249,50 @@
g_hash_table_destroy(hash);
}
+ }
+}
- debuglog_event_id[DEBUG_EVENT_CATEGORY_ENABLED] =
- dbus_log_server_add_category_enabled_handler(
- debuglog_server, debuglog_category_enabled,
- NULL);
- debuglog_event_id[DEBUG_EVENT_CATEGORY_DISABLED] =
- dbus_log_server_add_category_disabled_handler(
- debuglog_server, debuglog_category_disabled,
- NULL);
+static void debuglog_add_external_plugin(struct ofono_plugin_desc *desc,
+ int flags, void *user_data)
+{
+ /*
+ * We are only interested in the external plugins here because
+ * they don't fall into __start___debug .. __stop___debug range.
+ */
+ if (!(flags & OFONO_PLUGIN_FLAG_BUILTIN)) {
+ if (desc->debug_start && desc->debug_stop) {
+ DBG("Adding \"%s\" plugin", desc->name);
+ debuglog_add_categories(desc->debug_start,
+ desc->debug_stop);
+ } else {
+ DBG("No debug descriptors for \"%s\" plugin",
+ desc->name);
+ }
}
+}
+
+static int debuglog_init(void)
+{
+ debuglog_server = dbus_log_server_new(ofono_dbus_get_connection(),
+ DEBUGLOG_PATH);
+
+ /*
+ * First handle the executable and the builtin plugins (including
+ * this one) then the external plugins.
+ */
+ debuglog_add_categories(__start___debug, __stop___debug);
+ __ofono_plugin_foreach(debuglog_add_external_plugin, NULL);
+
+ debuglog_event_id[DEBUG_EVENT_CATEGORY_ENABLED] =
+ dbus_log_server_add_category_enabled_handler(debuglog_server,
+ debuglog_category_enabled, NULL);
+ debuglog_event_id[DEBUG_EVENT_CATEGORY_DISABLED] =
+ dbus_log_server_add_category_disabled_handler(debuglog_server,
+ debuglog_category_disabled, NULL);
debuglog_default_log_proc = gutil_log_func2;
gutil_log_func2 = debuglog_gutil_log_func;
+ gutil_log_func = gutil_log_syslog;
ofono_log_hook = debuglog_ofono_log_hook;
dbus_log_server_set_default_level(debuglog_server, DBUSLOG_LEVEL_DEBUG);
@@ -251,5 +310,5 @@
}
OFONO_PLUGIN_DEFINE(debuglog, "Debug log interface",
- VERSION, OFONO_PLUGIN_PRIORITY_DEFAULT,
+ VERSION, OFONO_PLUGIN_PRIORITY_HIGH,
debuglog_init, debuglog_exit)
|
[-]
[+]
|
Changed |
_service:tar_git:ofono-1.19+git37.tar.bz2/ofono/src/modem.c
^
|
@@ -185,6 +185,11 @@
return NULL;
}
+struct ofono_sim *ofono_modem_get_sim(struct ofono_modem *modem)
+{
+ return __ofono_atom_find(OFONO_ATOM_TYPE_SIM, modem);
+}
+
struct ofono_atom *__ofono_modem_add_atom(struct ofono_modem *modem,
enum ofono_atom_type type,
void (*destruct)(struct ofono_atom *),
|
[-]
[+]
|
Changed |
_service:tar_git:ofono-1.19+git37.tar.bz2/ofono/src/ofono.h
^
|
@@ -104,6 +104,12 @@
int __ofono_plugin_init(const char *pattern, const char *exclude);
void __ofono_plugin_cleanup(void);
+void __ofono_plugin_foreach(void (*fn) (struct ofono_plugin_desc *desc,
+ int flags, void *user_data), void *user_data);
+
+#define OFONO_PLUGIN_FLAG_BUILTIN (0x01)
+#define OFONO_PLUGIN_FLAG_ACTIVE (0x02)
+
#include <ofono/modem.h>
typedef void (*ofono_modem_foreach_func)(struct ofono_modem *modem,
@@ -535,10 +541,53 @@
ofono_bool_t __ofono_private_network_request(ofono_private_network_cb_t cb,
int *id, void *data);
+#include <ofono/sms-filter.h>
+
+struct sms_filter_chain;
+struct sms_address;
+struct sms_scts;
+enum sms_class;
+
+typedef void (*sms_send_text_cb_t)(struct ofono_sms *sms,
+ const struct sms_address *addr, const char *text, void *data);
+
+typedef void (*sms_dispatch_recv_text_cb_t)
+ (struct ofono_sms *sms, const struct ofono_uuid *uuid,
+ const char *message, enum sms_class cls,
+ const struct sms_address *addr, const struct sms_scts *scts);
+
+typedef void (*sms_dispatch_recv_datagram_cb_t)
+ (struct ofono_sms *sms, const struct ofono_uuid *uuid,
+ int dst, int src, const unsigned char *buf, unsigned int len,
+ const struct sms_address *addr, const struct sms_scts *scts);
+
+struct sms_filter_chain *__ofono_sms_filter_chain_new(struct ofono_sms *sms,
+ struct ofono_modem *modem);
+void __ofono_sms_filter_chain_free(struct sms_filter_chain *chain);
+
+void __ofono_sms_filter_chain_send_text(struct sms_filter_chain *chain,
+ const struct sms_address *addr, const char *text,
+ sms_send_text_cb_t sender, ofono_destroy_func destroy,
+ void *data);
+
+/* Does g_free(buf) when done */
+void __ofono_sms_filter_chain_recv_datagram(struct sms_filter_chain *chain,
+ const struct ofono_uuid *uuid, int dst_port, int src_port,
+ unsigned char *buf, unsigned int len,
+ const struct sms_address *addr, const struct sms_scts *scts,
+ sms_dispatch_recv_datagram_cb_t default_handler);
+
+/* Does g_free(message) when done */
+void __ofono_sms_filter_chain_recv_text(struct sms_filter_chain *chain,
+ const struct ofono_uuid *uuid, char *message,
+ enum sms_class cls, const struct sms_address *addr,
+ const struct sms_scts *scts,
+ sms_dispatch_recv_text_cb_t default_handler);
+
#include <ofono/sim-mnclength.h>
int __ofono_sim_mnclength_get_mnclength(const char *imsi);
+int mnclength(int mcc, int mnc);
#include <ofono/netmon.h>
-int mnclength(int mcc, int mnc);
|
[-]
[+]
|
Changed |
_service:tar_git:ofono-1.19+git37.tar.bz2/ofono/src/plugin.c
^
|
@@ -24,6 +24,7 @@
#endif
#include <dlfcn.h>
+#include <string.h>
#include <glib.h>
@@ -52,7 +53,8 @@
if (desc->init == NULL)
return FALSE;
- if (g_str_equal(desc->version, OFONO_VERSION) == FALSE) {
+ /* Allow older versions (assuming that API is backward compatible) */
+ if (!desc->version || strcmp(desc->version, OFONO_VERSION) > 0) {
ofono_error("Invalid version %s for %s", desc->version,
desc->description);
return FALSE;
@@ -99,6 +101,25 @@
return TRUE;
}
+void __ofono_plugin_foreach(void (*fn) (struct ofono_plugin_desc *desc,
+ int flags, void *user_data), void *user_data)
+{
+ GSList *list;
+
+ for (list = plugins; list; list = list->next) {
+ struct ofono_plugin *plugin = list->data;
+ int flags = 0;
+
+ if (!plugin->handle)
+ flags |= OFONO_PLUGIN_FLAG_BUILTIN;
+
+ if (plugin->active)
+ flags |= OFONO_PLUGIN_FLAG_ACTIVE;
+
+ fn(plugin->desc, flags, user_data);
+ }
+}
+
#include "builtin.h"
int __ofono_plugin_init(const char *pattern, const char *exclude)
|
[-]
[+]
|
Added |
_service:tar_git:ofono-1.19+git37.tar.bz2/ofono/src/sms-filter.c
^
|
@@ -0,0 +1,808 @@
+/*
+ * oFono - Open Source Telephony
+ *
+ * Copyright (C) 2017 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 "ofono.h"
+
+#include <errno.h>
+#include <string.h>
+
+#include "smsutil.h"
+
+#define CAST(address,type,field) \
+ ((type *)((guint8*)(address) - G_STRUCT_OFFSET(type,field)))
+
+/* We don't convert enums, assert that they match each other */
+#define ASSERT_ENUM_(x) G_STATIC_ASSERT((int)x == (int)OFONO_##x)
+
+/* ofono_sms_number_type vs sms_number_type */
+ASSERT_ENUM_(SMS_NUMBER_TYPE_UNKNOWN);
+ASSERT_ENUM_(SMS_NUMBER_TYPE_INTERNATIONAL);
+ASSERT_ENUM_(SMS_NUMBER_TYPE_NATIONAL);
+ASSERT_ENUM_(SMS_NUMBER_TYPE_NETWORK_SPECIFIC);
+ASSERT_ENUM_(SMS_NUMBER_TYPE_SUBSCRIBER);
+ASSERT_ENUM_(SMS_NUMBER_TYPE_ALPHANUMERIC);
+ASSERT_ENUM_(SMS_NUMBER_TYPE_ABBREVIATED);
+ASSERT_ENUM_(SMS_NUMBER_TYPE_RESERVED);
+
+/* ofono_sms_numbering_plan vs sms_numbering_plan */
+ASSERT_ENUM_(SMS_NUMBERING_PLAN_UNKNOWN);
+ASSERT_ENUM_(SMS_NUMBERING_PLAN_ISDN);
+ASSERT_ENUM_(SMS_NUMBERING_PLAN_DATA);
+ASSERT_ENUM_(SMS_NUMBERING_PLAN_TELEX);
+ASSERT_ENUM_(SMS_NUMBERING_PLAN_SC1);
+ASSERT_ENUM_(SMS_NUMBERING_PLAN_SC2);
+ASSERT_ENUM_(SMS_NUMBERING_PLAN_NATIONAL);
+ASSERT_ENUM_(SMS_NUMBERING_PLAN_PRIVATE);
+ASSERT_ENUM_(SMS_NUMBERING_PLAN_ERMES);
+ASSERT_ENUM_(SMS_NUMBERING_PLAN_RESERVED);
+
+/* ofono_sms_class vs sms_class */
+ASSERT_ENUM_(SMS_CLASS_0);
+ASSERT_ENUM_(SMS_CLASS_1);
+ASSERT_ENUM_(SMS_CLASS_2);
+ASSERT_ENUM_(SMS_CLASS_3);
+ASSERT_ENUM_(SMS_CLASS_UNSPECIFIED);
+
+struct sms_filter_message;
+struct sms_filter_message_fn {
+ const char *name;
+ gboolean (*can_process)(const struct ofono_sms_filter *filter);
+ guint (*process)(const struct ofono_sms_filter *filter,
+ struct sms_filter_message *msg);
+ void (*passthrough)(struct sms_filter_message *msg);
+ void (*destroy)(struct sms_filter_message *msg);
+ void (*free)(struct sms_filter_message *msg);
+};
+
+struct sms_filter_message {
+ int refcount;
+ gboolean destroyed;
+ const struct sms_filter_message_fn *fn;
+ struct sms_filter_chain *chain;
+ GSList *filter_link;
+ guint pending_id;
+ guint continue_id;
+};
+
+struct sms_filter_chain_send_text {
+ struct sms_filter_message message;
+ sms_send_text_cb_t send;
+ ofono_destroy_func destroy;
+ void *data;
+ char *text;
+ struct ofono_sms_address addr;
+};
+
+struct sms_filter_chain_recv_text {
+ struct sms_filter_message message;
+ sms_dispatch_recv_text_cb_t default_handler;
+ struct ofono_uuid uuid;
+ char *text;
+ enum ofono_sms_class cls;
+ struct ofono_sms_address addr;
+ struct ofono_sms_scts scts;
+};
+
+struct sms_filter_chain_recv_datagram {
+ struct sms_filter_message message;
+ sms_dispatch_recv_datagram_cb_t default_handler;
+ struct ofono_uuid uuid;
+ int dst_port;
+ int src_port;
+ unsigned char *buf;
+ unsigned int len;
+ struct ofono_sms_address addr;
+ struct ofono_sms_scts scts;
+};
+
+struct sms_filter_chain {
+ struct ofono_sms *sms;
+ struct ofono_modem *modem;
+ GSList *msg_list;
+};
+
+static GSList *sms_filter_list = NULL;
+
+static void sms_filter_convert_sms_address(struct ofono_sms_address *dest,
+ const struct sms_address *src)
+{
+ dest->number_type = (enum ofono_sms_number_type)src->number_type;
+ dest->numbering_plan = (enum ofono_sms_numbering_plan)
+ src->numbering_plan;
+ strncpy(dest->address, src->address, sizeof(dest->address));
+};
+
+static void sms_filter_convert_sms_address_back(struct sms_address *dest,
+ const struct ofono_sms_address *src)
+{
+ dest->number_type = (enum sms_number_type)src->number_type;
+ dest->numbering_plan = (enum sms_numbering_plan)src->numbering_plan;
+ strncpy(dest->address, src->address, sizeof(dest->address));
+};
+
+static void sms_filter_convert_sms_scts(struct ofono_sms_scts *dest,
+ const struct sms_scts *src)
+{
+ dest->year = src->year;
+ dest->month = src->month;
+ dest->day = src->day;
+ dest->hour = src->hour;
+ dest->minute = src->minute;
+ dest->second = src->second;
+ dest->has_timezone = src->has_timezone;
+ dest->timezone = src->timezone;
+}
+
+static void sms_filter_convert_sms_scts_back(struct sms_scts *dest,
+ const struct ofono_sms_scts *src)
+{
+ dest->year = src->year;
+ dest->month = src->month;
+ dest->day = src->day;
+ dest->hour = src->hour;
+ dest->minute = src->minute;
+ dest->second = src->second;
+ dest->has_timezone = src->has_timezone;
+ dest->timezone = src->timezone;
+}
+
+static void sms_filter_message_init(struct sms_filter_message *msg,
+ struct sms_filter_chain *chain, const struct sms_filter_message_fn *fn)
+{
+ /* The caller has zeroed the structure for us */
+ msg->fn = fn;
+ msg->chain = chain;
+ msg->filter_link = sms_filter_list;
+
+ /*
+ * The list holds an implicit reference to the message. The reference
+ * is released by sms_filter_message_free when the message is removed
+ * from the list.
+ */
+ msg->refcount = 1;
+ chain->msg_list = g_slist_append(chain->msg_list, msg);
+}
+
+static void sms_filter_message_process(struct sms_filter_message *msg)
+{
+ GSList *filter_link = msg->filter_link;
+ const struct ofono_sms_filter *filter = filter_link->data;
+ const struct sms_filter_message_fn *fn = msg->fn;
+
+ while (filter && !fn->can_process(filter)) {
+ filter_link = filter_link->next;
+ filter = filter_link ? filter_link->data : NULL;
+ }
+
+ if (filter) {
+ guint id;
+
+ /*
+ * If fn->process returns zero, the message may have
+ * already been deallocated. It's only guaranteed to
+ * be alive if fn->process returns non-zero id.
+ */
+ msg->filter_link = filter_link;
+ id = fn->process(filter, msg);
+ if (id) {
|
[-]
[+]
|
Changed |
_service:tar_git:ofono-1.19+git37.tar.bz2/ofono/src/sms.c
^
|
@@ -66,6 +66,7 @@
GSList *pending_get_prop;
struct ofono_phone_number sca;
struct sms_assembly *assembly;
+ struct sms_filter_chain *filter_chain;
guint ref;
GQueue *txq;
unsigned long tx_counter;
@@ -948,6 +949,68 @@
DBUS_TYPE_INVALID);
}
+struct sms_message_data {
+ DBusMessage *pending;
+};
+
+static void sms_send_message_submit(struct ofono_sms *sms,
+ const struct sms_address *addr, const char *text, void *data)
+{
+ struct sms_message_data *message = data;
+ const char *to = sms_address_to_string(addr);
+ GSList *msg_list;
+ struct ofono_modem *modem;
+ unsigned int flags;
+ gboolean use_16bit_ref = FALSE;
+ int err;
+ struct ofono_uuid uuid;
+
+ msg_list = sms_text_prepare_with_alphabet(to, text, sms->ref,
+ use_16bit_ref,
+ sms->use_delivery_reports,
+ sms->alphabet);
+
+ if (msg_list == NULL) {
+ __ofono_dbus_pending_reply(&message->pending,
+ __ofono_error_invalid_format(message->pending));
+ return;
+ }
+
+ flags = OFONO_SMS_SUBMIT_FLAG_RECORD_HISTORY;
+ flags |= OFONO_SMS_SUBMIT_FLAG_RETRY;
+ flags |= OFONO_SMS_SUBMIT_FLAG_EXPOSE_DBUS;
+ if (sms->use_delivery_reports)
+ flags |= OFONO_SMS_SUBMIT_FLAG_REQUEST_SR;
+
+ err = __ofono_sms_txq_submit(sms, msg_list, flags, &uuid,
+ message_queued, message->pending);
+
+ g_slist_free_full(msg_list, g_free);
+
+ if (err < 0) {
+ __ofono_dbus_pending_reply(&message->pending,
+ __ofono_error_failed(message->pending));
+ return;
+ }
+
+ modem = __ofono_atom_get_modem(sms->atom);
+ __ofono_history_sms_send_pending(modem, &uuid, to, time(NULL), text);
+
+ /* Ownership has been transfered to the message queue */
+ message->pending = NULL;
+}
+
+static void sms_send_message_destroy(void *data)
+{
+ struct sms_message_data *message = data;
+
+ if (message->pending) {
+ __ofono_dbus_pending_reply(&message->pending,
+ __ofono_error_canceled(message->pending));
+ }
+ g_free(message);
+}
+
/*
* Pre-process a SMS text message and deliver it [D-Bus SendMessage()]
*
@@ -967,12 +1030,8 @@
struct ofono_sms *sms = data;
const char *to;
const char *text;
- GSList *msg_list;
- struct ofono_modem *modem;
- unsigned int flags;
- gboolean use_16bit_ref = FALSE;
- int err;
- struct ofono_uuid uuid;
+ struct sms_message_data *message;
+ struct sms_address addr;
if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &to,
DBUS_TYPE_STRING, &text,
@@ -982,30 +1041,12 @@
if (valid_phone_number_format(to) == FALSE)
return __ofono_error_invalid_format(msg);
- msg_list = sms_text_prepare_with_alphabet(to, text, sms->ref,
- use_16bit_ref,
- sms->use_delivery_reports,
- sms->alphabet);
+ message = g_new0(struct sms_message_data, 1);
+ message->pending = dbus_message_ref(msg);
- if (msg_list == NULL)
- return __ofono_error_invalid_format(msg);
-
- flags = OFONO_SMS_SUBMIT_FLAG_RECORD_HISTORY;
- flags |= OFONO_SMS_SUBMIT_FLAG_RETRY;
- flags |= OFONO_SMS_SUBMIT_FLAG_EXPOSE_DBUS;
- if (sms->use_delivery_reports)
- flags |= OFONO_SMS_SUBMIT_FLAG_REQUEST_SR;
-
- err = __ofono_sms_txq_submit(sms, msg_list, flags, &uuid,
- message_queued, msg);
-
- g_slist_free_full(msg_list, g_free);
-
- if (err < 0)
- return __ofono_error_failed(msg);
-
- modem = __ofono_atom_get_modem(sms->atom);
- __ofono_history_sms_send_pending(modem, &uuid, to, time(NULL), text);
+ sms_address_from_string(&addr, to);
+ __ofono_sms_filter_chain_send_text(sms->filter_chain, &addr, text,
+ sms_send_message_submit, sms_send_message_destroy, message);
return NULL;
}
@@ -1394,20 +1435,18 @@
if (buf == NULL)
return;
- dispatch_app_datagram(sms, &uuid, dstport, srcport, buf, len,
- &s->deliver.oaddr, &s->deliver.scts);
-
- g_free(buf);
+ __ofono_sms_filter_chain_recv_datagram(sms->filter_chain,
+ &uuid, dstport, srcport, buf, len, &s->deliver.oaddr,
+ &s->deliver.scts, dispatch_app_datagram);
} else {
char *message = sms_decode_text(sms_list);
if (message == NULL)
return;
- dispatch_text_message(sms, &uuid, message, cls,
- &s->deliver.oaddr, &s->deliver.scts);
-
- g_free(message);
+ __ofono_sms_filter_chain_recv_text(sms->filter_chain, &uuid,
+ message, cls, &s->deliver.oaddr, &s->deliver.scts,
+ dispatch_text_message);
}
}
@@ -1749,6 +1788,8 @@
if (sms == NULL)
return;
+ __ofono_sms_filter_chain_free(sms->filter_chain);
+
if (sms->driver && sms->driver->remove)
sms->driver->remove(sms);
@@ -1842,6 +1883,8 @@
break;
}
+ sms->filter_chain = __ofono_sms_filter_chain_new(sms, modem);
+
return sms;
}
|
[-]
[+]
|
Changed |
_service:tar_git:ofono-1.19+git37.tar.bz2/ofono/unit/coverage
^
|
@@ -17,6 +17,8 @@
test-sms-root \
test-caif \
test-provision \
+ test-ril_util \
+ test-sms-filter \
test-sailfish_cell_info \
test-sailfish_manager \
test-sailfish_sim_info"
@@ -29,13 +31,14 @@
popd > /dev/null
FULL_COV="$TEST_DIR/full.gcov"
+DRIVERS_COV="$TEST_DIR/drivers.gcov"
PLUGINS_COV="$TEST_DIR/plugins.gcov"
SRC_COV="$TEST_DIR/src.gcov"
OUT="$TEST_DIR/html"
# Clean everything up
find "$BASE_DIR" -name "*.gcda" -exec rm {} \;
-rm -f "$FULL_COV" "$PLUGINS_COV" "$SRC_COV"
+rm -f "$FULL_COV" "$DRIVERS_COV" "$PLUGINS_COV" "$SRC_COV"
rm -fr "$OUT"
# Run the tests
@@ -52,8 +55,9 @@
GENHTML_OPT="--branch-coverage"
lcov $LCOV_OPT -c -d "$BASE_DIR" -o "$FULL_COV" || exit 1
+lcov $LCOV_OPT -e "$FULL_COV" "$BASE_DIR/drivers/*" -o "$DRIVERS_COV" || exit 1
lcov $LCOV_OPT -e "$FULL_COV" "$BASE_DIR/plugins/*" -o "$PLUGINS_COV" || exit 1
lcov $LCOV_OPT -e "$FULL_COV" "$BASE_DIR/src/*" -o "$SRC_COV" || exit 1
-genhtml $GENHTML_OPT -t ofono "$PLUGINS_COV" "$SRC_COV" --output-directory "$OUT" || exit 1
+genhtml $GENHTML_OPT -t ofono "$DRIVERS_COV" "$PLUGINS_COV" "$SRC_COV" --output-directory "$OUT" || exit 1
echo Coverage report: $OUT/index.html
|
[-]
[+]
|
Added |
_service:tar_git:ofono-1.19+git37.tar.bz2/ofono/unit/test-ril_util.c
^
|
@@ -0,0 +1,128 @@
+/*
+ * oFono - Open Source Telephony
+ *
+ * Copyright (C) 2017 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 "drivers/ril/ril_util.h"
+
+#include "ofono.h"
+#include "common.h"
+
+void test_parse_tech(void)
+{
+ int tech = 0;
+
+ g_assert(ril_parse_tech(NULL, NULL) == -1);
+ g_assert(ril_parse_tech(NULL, &tech) == -1);
+ g_assert(tech == -1);
+ g_assert(ril_parse_tech("-1", &tech) == -1);
+ g_assert(tech == -1);
+ g_assert(ril_parse_tech("0", &tech) == -1);
+ g_assert(tech == -1);
+ g_assert(ril_parse_tech("1", &tech) == ACCESS_TECHNOLOGY_GSM);
+ g_assert(tech == RADIO_TECH_GPRS);
+ g_assert(ril_parse_tech("16", &tech) == ACCESS_TECHNOLOGY_GSM);
+ g_assert(tech == RADIO_TECH_GSM);
+ g_assert(ril_parse_tech("2", &tech) == ACCESS_TECHNOLOGY_GSM_EGPRS);
+ g_assert(tech == RADIO_TECH_EDGE);
+ g_assert(ril_parse_tech("3", &tech) == ACCESS_TECHNOLOGY_UTRAN);
+ g_assert(tech == RADIO_TECH_UMTS);
+ g_assert(ril_parse_tech("9", &tech) == ACCESS_TECHNOLOGY_UTRAN_HSDPA);
+ g_assert(tech == RADIO_TECH_HSDPA);
+ g_assert(ril_parse_tech("10", &tech) == ACCESS_TECHNOLOGY_UTRAN_HSUPA);
+ g_assert(tech == RADIO_TECH_HSUPA);
+ g_assert(ril_parse_tech("11", &tech) ==
+ ACCESS_TECHNOLOGY_UTRAN_HSDPA_HSUPA);
+ g_assert(tech == RADIO_TECH_HSPA);
+ g_assert(ril_parse_tech("15", &tech) ==
+ ACCESS_TECHNOLOGY_UTRAN_HSDPA_HSUPA);
+ g_assert(tech == RADIO_TECH_HSPAP);
+ g_assert(ril_parse_tech("14", &tech) == ACCESS_TECHNOLOGY_EUTRAN);
+ g_assert(tech == RADIO_TECH_LTE);
+}
+
+void test_parse_mcc_mnc(void)
+{
+ struct ofono_network_operator op;
+
+ memset(&op, 0, sizeof(op));
+ g_assert(!ril_parse_mcc_mnc(NULL, &op));
+ g_assert(!ril_parse_mcc_mnc("", &op));
+ g_assert(!ril_parse_mcc_mnc("24x", &op));
+ g_assert(!ril_parse_mcc_mnc("244", &op));
+ g_assert(!ril_parse_mcc_mnc("244x", &op));
+ g_assert(ril_parse_mcc_mnc("24412", &op));
+ g_assert(!strcmp(op.mcc, "244"));
+ g_assert(!strcmp(op.mnc, "12"));
+ g_assert(!op.tech);
+ g_assert(ril_parse_mcc_mnc("25001+", &op));
+ g_assert(!strcmp(op.mcc, "250"));
+ g_assert(!strcmp(op.mnc, "01"));
+ g_assert(!op.tech);
+ g_assert(ril_parse_mcc_mnc("25503+14", &op));
+ g_assert(!strcmp(op.mcc, "255"));
+ g_assert(!strcmp(op.mnc, "03"));
+ g_assert(op.tech == ACCESS_TECHNOLOGY_EUTRAN);
+ /* Not sure if this is right but that's now it currently works: */
+ op.tech = 0;
+ g_assert(ril_parse_mcc_mnc("3101500", &op));
+ g_assert(!strcmp(op.mcc, "310"));
+ g_assert(!strcmp(op.mnc, "150"));
+ g_assert(!op.tech);
+}
+
+void test_parse_int(void)
+{
+ int value;
+
+ g_assert(!ril_parse_int(NULL, 0, NULL));
+ g_assert(!ril_parse_int("", 0, NULL));
+ g_assert(!ril_parse_int("garbage", 0, NULL));
+ g_assert(!ril_parse_int("0 trailing garbage", 0, NULL));
+ g_assert(ril_parse_int("0", 0, NULL));
+ g_assert(ril_parse_int("0", 0, &value));
+ g_assert(value == 0);
+ g_assert(!ril_parse_int("0x10000000000000000", 0, &value));
+ g_assert(!ril_parse_int("-2147483649", 0, &value));
+ g_assert(!ril_parse_int("4294967295", 0, &value));
+ g_assert(ril_parse_int(" 0x7fffffff ", 0, &value));
+ g_assert(value == 0x7fffffff);
+ g_assert(ril_parse_int(" 7fffffff ", 16, &value));
+ g_assert(value == 0x7fffffff);
+ g_assert(!ril_parse_int("0xffffffff", 0, &value));
+}
+
+#define TEST_(name) "/ril_util/" name
+
+int main(int argc, char *argv[])
+{
+ g_test_init(&argc, &argv, NULL);
+
+ __ofono_log_init("test-ril_util",
+ g_test_verbose() ? "*" : NULL,
+ FALSE, FALSE);
+
+ g_test_add_func(TEST_("parse_tech"), test_parse_tech);
+ g_test_add_func(TEST_("parse_mcc_mnc"), test_parse_mcc_mnc);
+ g_test_add_func(TEST_("parse_int"), test_parse_int);
+
+ return g_test_run();
+}
+
+/*
+ * Local Variables:
+ * mode: C
+ * c-basic-offset: 8
+ * indent-tabs-mode: t
+ * End:
+ */
|
[-]
[+]
|
Added |
_service:tar_git:ofono-1.19+git37.tar.bz2/ofono/unit/test-sms-filter.c
^
|
@@ -0,0 +1,1182 @@
+/*
+ * oFono - Open Source Telephony
+ *
+ * Copyright (C) 2017 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.
+ */
+
+#define OFONO_API_SUBJECT_TO_CHANGE
+#include "ofono.h"
+#include "common.h"
+#include "smsutil.h"
+
+#include <gutil_log.h>
+
+#include <errno.h>
+
+#define TEST_TIMEOUT_SEC (20)
+
+static GMainLoop *test_loop = NULL;
+static guint test_timeout_id = 0;
+
+/* Fake data structures */
+
+struct ofono_sms {
+ int dg_count;
+ int msg_count;
+};
+
+struct ofono_modem {
+ int filter_dg_count;
+ int filter_msg_count;
+};
+
+/* Code shared by all tests */
+
+static gboolean test_no_timeout_cb(gpointer data)
+{
+ g_assert(FALSE);
+ return G_SOURCE_REMOVE;
+}
+
+static gboolean test_timeout_cb(gpointer user_data)
+{
+ ofono_error("Timeout!");
+ g_main_loop_quit(test_loop);
+ test_timeout_id = 0;
+ return G_SOURCE_REMOVE;
+}
+
+static gboolean test_quit_cb(gpointer user_data)
+{
+ g_main_loop_quit(test_loop);
+ return G_SOURCE_REMOVE;
+}
+
+static void test_inc(gpointer data)
+{
+ (*(int*)data)++;
+}
+
+static void test_send_text_inc(struct ofono_sms *sms,
+ const struct sms_address *addr, const char *text, void *data)
+{
+ (*(int*)data)++;
+}
+
+static void test_common_init()
+{
+ test_loop = g_main_loop_new(NULL, FALSE);
+ test_timeout_id = g_timeout_add_seconds(TEST_TIMEOUT_SEC,
+ test_timeout_cb, NULL);
+}
+
+static void test_common_deinit()
+{
+ g_assert(test_timeout_id);
+ g_source_remove(test_timeout_id);
+ g_main_loop_unref(test_loop);
+ test_timeout_id = 0;
+ test_loop = NULL;
+}
+
+static void test_default_send_message(struct ofono_sms *sms,
+ const struct sms_address *addr, const char *text, void *data)
+{
+ sms->msg_count++;
+ g_main_loop_quit(test_loop);
+}
+
+static void test_default_dispatch_datagram(struct ofono_sms *sms,
+ const struct ofono_uuid *uuid, int dst, int src,
+ const unsigned char *buf, unsigned int len,
+ const struct sms_address *addr,
+ const struct sms_scts *scts)
+{
+ sms->dg_count++;
+ g_main_loop_quit(test_loop);
+}
+
+static void test_default_dispatch_recv_message(struct ofono_sms *sms,
+ const struct ofono_uuid *uuid, const char *message,
+ enum sms_class cls, const struct sms_address *addr,
+ const struct sms_scts *scts)
+{
+ sms->msg_count++;
+ g_main_loop_quit(test_loop);
+}
+
+/* Test cases */
+
+/* ==== misc ==== */
+
+static void test_misc(void)
+{
+ static struct ofono_sms_filter noname = { 0 };
+ static struct ofono_sms_filter misc = {
+ .name = "misc"
+ };
+ int count = 0;
+
+ g_assert(ofono_sms_filter_register(NULL) == -EINVAL);
+ g_assert(ofono_sms_filter_register(&noname) == -EINVAL);
+ g_assert(ofono_sms_filter_register(&misc) == 0);
+ g_assert(ofono_sms_filter_register(&misc) == 0);
+ __ofono_sms_filter_chain_send_text(NULL, NULL, NULL, NULL, NULL, NULL);
+ __ofono_sms_filter_chain_send_text(NULL, NULL, NULL, NULL,
+ test_inc, &count);
+ g_assert(count == 1);
+ __ofono_sms_filter_chain_recv_text(NULL, NULL, NULL, 0, NULL, NULL,
+ NULL);
+ __ofono_sms_filter_chain_recv_datagram(NULL, NULL, 0, 0, NULL, 0, NULL,
+ NULL, NULL);
+ __ofono_sms_filter_chain_free(NULL);
+ ofono_sms_filter_unregister(&misc);
+ ofono_sms_filter_unregister(&misc);
+ ofono_sms_filter_unregister(&misc);
+ ofono_sms_filter_unregister(NULL);
+}
+
+/* ==== no_default ==== */
+
+static void test_no_default(void)
+{
+ struct sms_filter_chain *chain;
+ struct ofono_modem modem;
+ struct ofono_sms sms;
+ struct ofono_uuid uuid;
+ struct sms_address addr;
+ struct sms_scts scts;
+ int count = 0;
+
+ memset(&modem, 0, sizeof(modem));
+ memset(&sms, 0, sizeof(sms));
+ memset(&uuid, 0, sizeof(uuid));
+ memset(&addr, 0, sizeof(addr));
+ memset(&scts, 0, sizeof(scts));
+
+ /* These calls just deallocate the buffer we pass in. One can
+ * verify that with valgrind */
+ chain = __ofono_sms_filter_chain_new(&sms, &modem);
+ __ofono_sms_filter_chain_send_text(chain, &addr, "1", NULL, NULL,
+ NULL);
+ __ofono_sms_filter_chain_send_text(chain, &addr, "1", NULL,
+ test_inc, &count);
+ g_assert(count == 1);
+ count = 0;
+ __ofono_sms_filter_chain_send_text(chain, &addr, "1",
+ test_send_text_inc, test_inc, &count);
+ g_assert(count == 2);
+ __ofono_sms_filter_chain_recv_text(chain, &uuid, g_strdup("1"), 0,
+ &addr, &scts, NULL);
+ __ofono_sms_filter_chain_recv_datagram(chain, &uuid, 0, 0,
+ g_malloc0(1), 1, &addr, &scts, NULL);
+ __ofono_sms_filter_chain_free(chain);
+}
+
+/* ==== send_message ==== */
+
+struct test_send_message_data {
+ struct ofono_modem modem;
+ struct ofono_sms sms;
+ struct sms_filter_chain *chain;
+ int destroy_count;
+};
+
+static void test_send_message_destroy(void *data)
+{
+ struct test_send_message_data *test = data;
+
+ test->destroy_count++;
+ DBG("%d", test->destroy_count);
|