From: ofono@market.talbothome.com
To: ofono@ofono.org
Subject: [PATCH 08/09] Fix a few Bugs in service.c
Date: Fri, 19 Feb 2021 01:05:55 +0000 [thread overview]
Message-ID: <20210219010555.2937.52472@ml01.vlan13.01.org> (raw)
[-- Attachment #1: Type: text/plain, Size: 7344 bytes --]
This commit fixes a few bugs:
- Makes sure "sent" has an accurate time (it currently only has a time of the start of epoch time)
- Allows "Draft" to go to "Sent" on the dbus
- Allows the time to be preserved on sent and recieved messages if mmsd is closed and opened
(cherry picked from commit f8597b2f6a57f96fa6f7ac8e8c8a4cf550f9d2e9)
---
src/mmsutil.h | 2 ++
src/service.c | 60 +++++++++++++++++++++++++++++++++++++++------------
2 files changed, 48 insertions(+), 14 deletions(-)
diff --git a/src/mmsutil.h b/src/mmsutil.h
index 00ecc39..ec139f1 100644
--- a/src/mmsutil.h
+++ b/src/mmsutil.h
@@ -120,12 +120,14 @@ struct mms_retrieve_conf {
char *priority;
char *msgid;
time_t date;
+ char *datestamp;
};
struct mms_send_req {
enum mms_message_status status;
char *to;
time_t date;
+ char *datestamp;
char *content_type;
gboolean dr;
};
diff --git a/src/service.c b/src/service.c
index 58cd747..f3e710f 100644
--- a/src/service.c
+++ b/src/service.c
@@ -18,6 +18,7 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
+#define _XOPEN_SOURCE 700
#ifdef HAVE_CONFIG_H
#include <config.h>
@@ -35,6 +36,8 @@
#include <glib.h>
#include <glib/gstdio.h>
#include <gdbus.h>
+#include <time.h>
+#include <stdio.h>
#include <gweb/gweb.h>
@@ -129,6 +132,11 @@ static DBusConnection *connection;
static guint32 transaction_id_start = 0;
+
+static const char *time_to_str(const time_t *t);
+void debug_print(const char* s, void* data);
+
+
static void mms_load_settings(struct mms_service *service)
{
GError *error;
@@ -220,6 +228,7 @@ static void emit_msg_status_changed(const char *path, const char *new_status)
signal = dbus_message_new_signal(path, MMS_MESSAGE_INTERFACE,
"PropertyChanged");
+
if (signal == NULL)
return;
@@ -269,6 +278,7 @@ static DBusMessage *msg_mark_read(DBusConnection *conn,
g_free(state);
g_key_file_set_boolean(meta, "info", "read", TRUE);
+ mms->rc.status = MMS_MESSAGE_STATUS_READ;
mms_store_meta_close(service->identity, mms->uuid, meta, TRUE);
@@ -722,6 +732,7 @@ static gboolean result_request_send_conf(struct mms_request *request)
g_key_file_set_string(meta, "info", "state", "sent");
g_key_file_set_string(meta, "info", "id", msg->sc.msgid);
+ request->msg->sr.status = MMS_MESSAGE_STATUS_SENT;
mms_message_free(msg);
@@ -1048,6 +1059,7 @@ static DBusMessage *send_message(DBusConnection *conn,
struct mms_service *service = data;
struct mms_request *request;
GKeyFile *meta;
+ const char *datestr;
msg = g_new0(struct mms_message, 1);
if (msg == NULL)
@@ -1060,7 +1072,13 @@ static DBusMessage *send_message(DBusConnection *conn,
msg->sr.dr = service->use_delivery_reports;
- if (send_message_get_args(dbus_msg, msg) == FALSE) {
+ time(&msg->sr.date);
+
+ datestr = time_to_str(&msg->sr.date);
+
+ msg->sr.datestamp = g_strdup(datestr);
+
+ if (send_message_get_args(dbus_msg, msg, service) == FALSE) {
mms_debug("Invalid arguments");
release_attachement_data(msg->attachments);
@@ -1100,6 +1118,7 @@ static DBusMessage *send_message(DBusConnection *conn,
if (meta == NULL)
goto release_request;
+ g_key_file_set_string(meta, "info", "date", msg->sr.datestamp);
g_key_file_set_string(meta, "info", "state", "draft");
if (service->use_delivery_reports) {
@@ -1340,10 +1359,12 @@ static gboolean load_message_from_store(const char *service_id,
char *state = NULL;
gboolean read_status;
char *data_path = NULL;
+ char *datestr = NULL;
gboolean success = FALSE;
gboolean tainted = FALSE;
void *pdu;
size_t len;
+ struct tm tm;
meta = mms_store_meta_open(service_id, uuid);
if (meta == NULL)
@@ -1355,6 +1376,13 @@ static gboolean load_message_from_store(const char *service_id,
read_status = g_key_file_get_boolean(meta, "info", "read", NULL);
+ datestr = g_key_file_get_string(meta, "info", "date", NULL);
+ if (datestr != NULL) {
+ strptime(datestr, "%Y-%m-%dT%H:%M:%S%z", &tm);
+ } else {
+ mms_error("src/service.c:load_message_from_store() There is no date stamp!");
+ }
+
data_path = mms_store_get_path(service_id, uuid);
if (data_path == NULL)
goto out;
@@ -1373,25 +1401,28 @@ static gboolean load_message_from_store(const char *service_id,
msg->uuid = g_strdup(uuid);
- if (strcmp(state, "received") == 0
- && msg->type == MMS_MESSAGE_TYPE_RETRIEVE_CONF) {
+ if (strcmp(state, "received") == 0 && msg->type == MMS_MESSAGE_TYPE_RETRIEVE_CONF) {
+ msg->rc.datestamp = g_strdup(datestr);
+ msg->rc.date = mktime(&tm);
if (read_status == TRUE)
msg->rc.status = MMS_MESSAGE_STATUS_READ;
else
msg->rc.status = MMS_MESSAGE_STATUS_RECEIVED;
- } else if (strcmp(state, "downloaded") == 0
- && msg->type == MMS_MESSAGE_TYPE_RETRIEVE_CONF) {
+ } else if (strcmp(state, "downloaded") == 0 && msg->type == MMS_MESSAGE_TYPE_RETRIEVE_CONF) {
msg->rc.status = MMS_MESSAGE_STATUS_DOWNLOADED;
if (msg->transaction_id == NULL)
msg->transaction_id = "";
- } else if (strcmp(state, "sent") == 0
- && msg->type == MMS_MESSAGE_TYPE_SEND_REQ)
+ } else if (strcmp(state, "sent") == 0 && msg->type == MMS_MESSAGE_TYPE_SEND_REQ) {
+ msg->sr.datestamp = g_strdup(datestr);
+ msg->sr.date = mktime(&tm);
msg->sr.status = MMS_MESSAGE_STATUS_SENT;
- else if (strcmp(state, "draft") == 0
- && msg->type == MMS_MESSAGE_TYPE_SEND_REQ)
+ }
+ else if (strcmp(state, "draft") == 0 && msg->type == MMS_MESSAGE_TYPE_SEND_REQ) {
+ msg->sr.datestamp = g_strdup(datestr);
+ msg->sr.date = mktime(&tm);
msg->sr.status = MMS_MESSAGE_STATUS_DRAFT;
- else if (msg->type != MMS_MESSAGE_TYPE_NOTIFICATION_IND &&
- msg->type != MMS_MESSAGE_TYPE_DELIVERY_IND)
+ }
+ else if (msg->type != MMS_MESSAGE_TYPE_NOTIFICATION_IND && msg->type != MMS_MESSAGE_TYPE_DELIVERY_IND)
goto out;
success = TRUE;
@@ -1880,14 +1911,13 @@ static void append_rc_msg_properties(DBusMessageIter *dict,
static void append_sr_msg_properties(DBusMessageIter *dict,
struct mms_message *msg)
{
- const char *date = time_to_str(&msg->rc.date);
const char *status = mms_message_status_get_string(msg->sr.status);
mms_dbus_dict_append_basic(dict, "Status",
DBUS_TYPE_STRING, &status);
mms_dbus_dict_append_basic(dict, "Date",
- DBUS_TYPE_STRING, &date);
+ DBUS_TYPE_STRING, &msg->sr.datestamp);
if (msg->sr.to != NULL)
append_msg_recipients(dict, msg);
@@ -2121,6 +2151,9 @@ static gboolean result_request_notify_resp(struct mms_request *request)
if (meta == NULL)
return FALSE;
+ const char *datestr = time_to_str(&msg->rc.date);
+ msg->rc.datestamp = g_strdup(datestr);
+ g_key_file_set_string(meta, "info", "date", msg->rc.datestamp);
g_key_file_set_string(meta, "info", "state", "received");
mms_store_meta_close(request->service->identity,
@@ -2537,7 +2570,6 @@ void mms_service_bearer_notify(struct mms_service *service, mms_bool_t active,
if (active == FALSE)
goto interface_down;
-
DBG("interface %s proxy %s", interface, proxy);
if (service->web != NULL) {
--
2.30.0
reply other threads:[~2021-02-19 1:05 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210219010555.2937.52472@ml01.vlan13.01.org \
--to=ofono@market.talbothome.com \
--cc=ofono@ofono.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).