summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/message.c28
-rw-r--r--src/ofono.h3
-rw-r--r--src/sms.c49
3 files changed, 37 insertions, 43 deletions
diff --git a/src/message.c b/src/message.c
index 668a693b..7cc6538d 100644
--- a/src/message.c
+++ b/src/message.c
@@ -26,6 +26,7 @@
#include <string.h>
#include <gdbus.h>
#include <stdio.h>
+#include <errno.h>
#include "ofono.h"
#include "message.h"
@@ -76,8 +77,35 @@ static DBusMessage *message_get_properties(DBusConnection *conn,
return reply;
}
+static DBusMessage *message_cancel(DBusConnection *conn,
+ DBusMessage *msg, void *data)
+{
+ struct message *m = data;
+ int res;
+
+ if (dbus_message_get_args(msg, NULL, DBUS_TYPE_INVALID) == FALSE)
+ return __ofono_error_invalid_args(msg);
+
+ if (m->state != MESSAGE_STATE_PENDING)
+ return __ofono_error_not_available(msg);
+
+ res = __ofono_sms_txq_cancel(__ofono_atom_get_data(m->atom), &m->uuid);
+
+ switch (res) {
+ case -ENOENT:
+ return __ofono_error_not_found(msg);
+ case -EPERM:
+ return __ofono_error_access_denied(msg);
+ case 0:
+ return dbus_message_new_method_return(msg);
+ default:
+ return __ofono_error_failed(msg);
+ }
+}
+
static GDBusMethodTable message_methods[] = {
{ "GetProperties", "", "a{sv}", message_get_properties },
+ { "Cancel", "", "", message_cancel },
{ }
};
diff --git a/src/ofono.h b/src/ofono.h
index e7053cd0..b9ca314c 100644
--- a/src/ofono.h
+++ b/src/ofono.h
@@ -299,6 +299,9 @@ int __ofono_sms_txq_set_submit_notify(struct ofono_sms *sms,
void *data,
ofono_destroy_func destroy);
+int __ofono_sms_txq_cancel(struct ofono_sms *sms,
+ const struct ofono_uuid *uuid);
+
const char *__ofono_sms_message_path_from_uuid(struct ofono_sms *sms,
const struct ofono_uuid *uuid);
diff --git a/src/sms.c b/src/sms.c
index 5e6be580..02eba66e 100644
--- a/src/sms.c
+++ b/src/sms.c
@@ -1053,59 +1053,23 @@ static DBusMessage *sms_get_messages(DBusConnection *conn, DBusMessage *msg,
return reply;
}
-static gboolean uuid_from_message_path(const char *path,
- struct ofono_uuid *uuid)
-{
- const char *uuidstr;
- size_t len;
-
- len = strlen(path);
-
- if (len < OFONO_SHA1_UUID_LEN * 2)
- return FALSE;
-
- uuidstr = path + len - OFONO_SHA1_UUID_LEN * 2;
-
- if (decode_hex_own_buf(uuidstr, -1, NULL, 0, uuid->uuid) == NULL)
- return FALSE;
-
- return TRUE;
-}
-
static gint entry_compare_by_uuid(gconstpointer a, gconstpointer b)
{
const struct tx_queue_entry *entry = a;
- const char *uuid = b;
+ const struct ofono_uuid *uuid = b;
return memcmp(&entry->uuid, uuid, sizeof(entry->uuid));
}
-static DBusMessage *sms_cancel_message(DBusConnection *conn, DBusMessage *msg,
- void *data)
+int __ofono_sms_txq_cancel(struct ofono_sms *sms, const struct ofono_uuid *uuid)
{
- struct ofono_sms *sms = data;
- char *path;
- struct ofono_uuid uuid;
GList *l;
struct tx_queue_entry *entry;
- if (sms->pending)
- return __ofono_error_busy(msg);
-
- if (dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &path,
- DBUS_TYPE_INVALID) == FALSE)
- return __ofono_error_invalid_args(msg);
-
- if (path[0] == '\0')
- return __ofono_error_invalid_args(msg);
-
- if (uuid_from_message_path(path, &uuid) == FALSE)
- return __ofono_error_invalid_args(msg);
-
- l = g_queue_find_custom(sms->txq, uuid.uuid, entry_compare_by_uuid);
+ l = g_queue_find_custom(sms->txq, uuid, entry_compare_by_uuid);
if (l == NULL)
- return __ofono_error_not_found(msg);
+ return -ENOENT;
entry = l->data;
@@ -1116,7 +1080,7 @@ static DBusMessage *sms_cancel_message(DBusConnection *conn, DBusMessage *msg,
*/
if (entry->cur_pdu > 0 ||
sms->tx_state == MESSAGE_STATE_PENDING)
- return __ofono_error_failed(msg);
+ return -EPERM;
/*
* Make sure we don't call tx_next() if there are no entries
@@ -1135,7 +1099,7 @@ static DBusMessage *sms_cancel_message(DBusConnection *conn, DBusMessage *msg,
sms->tx_state = MESSAGE_STATE_CANCELLED;
sms_tx_queue_remove_entry(sms, l);
- return dbus_message_new_method_return(msg);
+ return 0;
}
static GDBusMethodTable sms_manager_methods[] = {
@@ -1145,7 +1109,6 @@ static GDBusMethodTable sms_manager_methods[] = {
G_DBUS_METHOD_FLAG_ASYNC },
{ "SendMessage", "ss", "o", sms_send_message,
G_DBUS_METHOD_FLAG_ASYNC },
- { "CancelMessage", "o", "", sms_cancel_message },
{ "GetMessages", "", "a(oa{sv})", sms_get_messages },
{ }
};