Commit 338cfa1e authored by Slava Monich's avatar Slava Monich

[mms-lib] Improved handling of expired push notifications

parent d08067e2
......@@ -81,6 +81,10 @@ mms_task_notification_ind(
MMS_DEBUG(" Expiry: %s", expiry);
#endif /* MMS_LOG_DEBUG */
if (task->deadline > ni->expiry) {
task->deadline = ni->expiry;
}
id = mms_handler_message_notify(task->handler, task->imsi,
mms_strip_address_type(ni->from), ni->subject, ni->expiry, ind->push);
if (id) {
......
......@@ -27,6 +27,10 @@ typedef struct mms_handler_test {
unsigned int last_id;
GHashTable* recs;
MMSDispatcher* dispatcher;
int flags;
#define MMS_HANDLER_TEST_FLAG_REJECT_NOTIFY (0x01)
} MMSHandlerTest;
typedef enum mms_handler_record_type {
......@@ -54,7 +58,7 @@ typedef struct mms_handler_record_receive {
MMSDispatcher* dispatcher;
MMSMessage* msg;
GBytes* data;
guint receive_message_id;
guint defer_id;
} MMSHandlerRecordReceive;
G_DEFINE_TYPE(MMSHandlerTest, mms_handler_test, MMS_TYPE_HANDLER);
......@@ -219,7 +223,7 @@ mms_handler_test_receive_pending_check(
MMSHandlerRecord* rec = value;
if (rec->type == MMS_HANDLER_RECORD_RECEIVE) {
MMSHandlerRecordReceive* recv = mms_handler_test_record_receive(rec);
if (recv->receive_message_id) {
if (recv->defer_id) {
gboolean* pending = user_data;
*pending = TRUE;
}
......@@ -235,7 +239,7 @@ mms_handler_test_receive_pending(
if (id) {
MMSHandlerRecordReceive* recv;
recv = mms_handler_test_get_receive_record(test, id);
return recv && recv->receive_message_id;
return recv && recv->defer_id;
} else {
gboolean pending = FALSE;
g_hash_table_foreach(test->recs,
......@@ -274,9 +278,9 @@ mms_handler_test_hash_remove_record(
g_free(rec->id);
if (rec->type == MMS_HANDLER_RECORD_RECEIVE) {
MMSHandlerRecordReceive* recv = mms_handler_test_record_receive(rec);
if (recv->receive_message_id) {
g_source_remove(recv->receive_message_id);
recv->receive_message_id = 0;
if (recv->defer_id) {
g_source_remove(recv->defer_id);
recv->defer_id = 0;
}
mms_dispatcher_unref(recv->dispatcher);
mms_message_unref(recv->msg);
......@@ -296,10 +300,10 @@ mms_handler_test_receive(
{
MMSHandlerRecordReceive* recv = data;
MMSDispatcher* disp = recv->dispatcher;
MMS_ASSERT(recv->receive_message_id);
MMS_ASSERT(recv->defer_id);
MMS_ASSERT(recv->dispatcher);
MMS_DEBUG("Initiating receive of message %s", recv->rec.id);
recv->receive_message_id = 0;
recv->defer_id = 0;
recv->dispatcher = NULL;
mms_dispatcher_receive_message(disp, recv->rec.id, recv->rec.imsi,
TRUE, recv->data, NULL);
......@@ -319,21 +323,27 @@ mms_handler_test_message_notify(
GBytes* data)
{
MMSHandlerTest* test = MMS_HANDLER_TEST(handler);
MMSHandlerRecordReceive* recv = g_new0(MMSHandlerRecordReceive, 1);
char* id = g_strdup_printf("%u", (++test->last_id));
recv->rec.id = id;
recv->rec.imsi = g_strdup(imsi);
recv->rec.type = MMS_HANDLER_RECORD_RECEIVE;
recv->state = MMS_RECEIVE_STATE_INVALID;
recv->data = g_bytes_ref(data);
MMS_DEBUG("Push %s imsi=%s from=%s subj=%s", id, imsi, from, subj);
g_hash_table_replace(test->recs, id, &recv->rec);
if (test->dispatcher) {
recv->receive_message_id = g_idle_add(mms_handler_test_receive, recv);
recv->dispatcher = mms_dispatcher_ref(test->dispatcher);
return g_strdup("");
if (test->flags & MMS_HANDLER_TEST_FLAG_REJECT_NOTIFY) {
MMS_DEBUG("Rejecting push imsi=%s from=%s subj=%s", imsi, from, subj);
return NULL;
} else {
return g_strdup(id);
MMSHandlerRecordReceive* recv = g_new0(MMSHandlerRecordReceive, 1);
char* id = g_strdup_printf("%u", (++test->last_id));
recv->rec.id = id;
recv->rec.imsi = g_strdup(imsi);
recv->rec.type = MMS_HANDLER_RECORD_RECEIVE;
recv->state = MMS_RECEIVE_STATE_INVALID;
recv->data = g_bytes_ref(data);
MMS_DEBUG("Push %s imsi=%s from=%s subj=%s", id, imsi, from, subj);
g_hash_table_replace(test->recs, id, &recv->rec);
if (test->dispatcher) {
MMS_DEBUG("Deferring push");
recv->defer_id = g_idle_add(mms_handler_test_receive, recv);
recv->dispatcher = mms_dispatcher_ref(test->dispatcher);
return g_strdup("");
} else {
return g_strdup(id);
}
}
}
......@@ -538,6 +548,14 @@ mms_handler_test_defer_receive(
test->dispatcher = mms_dispatcher_ref(dispatcher);
}
void
mms_handler_test_reject_receive(
MMSHandler* handler)
{
MMSHandlerTest* test = MMS_HANDLER_TEST(handler);
test->flags |= MMS_HANDLER_TEST_FLAG_REJECT_NOTIFY;
}
void
mms_handler_test_reset(
MMSHandler* handler)
......@@ -546,6 +564,7 @@ mms_handler_test_reset(
g_hash_table_remove_all(test->recs);
mms_dispatcher_unref(test->dispatcher);
test->dispatcher = NULL;
test->flags = 0;
}
/*
......
......@@ -65,6 +65,10 @@ mms_handler_test_defer_receive(
MMSHandler* handler,
MMSDispatcher* dispatcher);
void
mms_handler_test_reject_receive(
MMSHandler* handler);
void
mms_handler_test_reset(
MMSHandler* handler);
......
......@@ -54,7 +54,8 @@ typedef struct test_desc {
int flags;
#define TEST_PUSH_HANDLING_FAILURE_OK (0x01)
#define TEST_DEFER_RECEIVE (0x02)
#define TEST_DEFER_RECEIVE (0x02)
#define TEST_REJECT_RECEIVE (0x04)
} TestDesc;
......@@ -163,7 +164,7 @@ static const TestDesc retrieve_tests[] = {
TEST_PARTS(retrieve_success1_parts),
TEST_DEFER_RECEIVE
},{
"Expired",
"Expired1",
NULL,
"m-notification.ind",
NULL,
......@@ -174,6 +175,18 @@ static const TestDesc retrieve_tests[] = {
MMS_MESSAGE_TYPE_NONE,
TEST_PARTS_NONE,
0
},{
"Expired2",
NULL,
"m-notification.ind",
NULL,
SOUP_STATUS_OK,
NULL,
NULL,
MMS_RECEIVE_STATE_INVALID,
MMS_MESSAGE_TYPE_NOTIFYRESP_IND,
TEST_PARTS_NONE,
TEST_REJECT_RECEIVE
},{
"SoonExpired",
NULL,
......@@ -453,6 +466,9 @@ test_init(
test->desc->content_type, test->desc->status);
port = test_http_get_port(test->http);
mms_connman_test_set_port(test->cm, port, TRUE);
if (desc->flags & TEST_REJECT_RECEIVE) {
mms_handler_test_reject_receive(test->handler);
}
if (desc->flags & TEST_DEFER_RECEIVE) {
mms_handler_test_defer_receive(test->handler, test->disp);
}
......@@ -561,45 +577,55 @@ test_retrieve(
int main(int argc, char* argv[])
{
int ret;
MMSConfig config;
const char* test_name = NULL;
int ret = RET_ERR;
gboolean keep_temp = FALSE;
gboolean verbose = FALSE;
GError* error = NULL;
GOptionContext* options;
GOptionEntry entries[] = {
{ "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose,
"Enable verbose output", NULL },
{ "keep", 'k', 0, G_OPTION_ARG_NONE, &keep_temp,
"Keep temporary files", NULL },
{ NULL }
};
mms_lib_init(argv[0]);
mms_lib_default_config(&config);
mms_log_default.name = "test_retrieve";
if (argc > 1 && !strcmp(argv[1], "-v")) {
mms_log_default.level = MMS_LOGLEVEL_VERBOSE;
memmove(argv + 1, argv + 2, (argc-2)*sizeof(argv[0]));
argc--;
} else {
mms_log_default.level = MMS_LOGLEVEL_INFO;
mms_task_http_log.level =
mms_task_decode_log.level =
mms_task_retrieve_log.level =
mms_task_notification_log.level = MMS_LOGLEVEL_NONE;
mms_log_stdout_timestamp = FALSE;
}
if (argc == 2 && argv[1][0] != '-') {
test_name = argv[1];
}
if (argc == 1 || test_name) {
options = g_option_context_new("[TEST] - MMS retrieve test");
g_option_context_add_main_entries(options, entries, NULL);
if (g_option_context_parse(options, &argc, &argv, &error) && argc < 3) {
MMSConfig config;
const char* test_name = (argc == 2) ? argv[1] : NULL;
char* tmpd = g_mkdtemp(g_strdup("/tmp/test_retrieve_XXXXXX"));
MMS_VERBOSE("Temporary directory %s", tmpd);
mms_lib_default_config(&config);
config.root_dir = tmpd;
config.keep_temp_files = keep_temp;
config.idle_secs = 0;
config.attic_enabled = TRUE;
mms_log_set_type(MMS_LOG_TYPE_STDOUT, "test_retrieve");
if (verbose) {
mms_log_default.level = MMS_LOGLEVEL_VERBOSE;
} else {
mms_log_default.level = MMS_LOGLEVEL_INFO;
mms_task_http_log.level =
mms_task_decode_log.level =
mms_task_retrieve_log.level =
mms_task_notification_log.level = MMS_LOGLEVEL_NONE;
mms_log_stdout_timestamp = FALSE;
}
ret = test_retrieve(&config, test_name);
remove(tmpd);
g_free(tmpd);
} else {
printf("Usage: test_retrieve [-v] [TEST]\n");
fprintf(stderr, "%s\n", MMS_ERRMSG(error));
g_error_free(error);
ret = RET_ERR;
}
g_option_context_free(options);
mms_lib_deinit();
return ret;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment