From: Chris Talbot <chris@talbothome.com>
To: ofono@ofono.org, netdev@vger.kernel.org,
debian-on-mobile-maintainers@alioth-lists.debian.net,
librem-5-dev@lists.community.puri.sm
Subject: [PATCH 5/9] Allow for a user configurable maximum attachment size
Date: Sat, 10 Apr 2021 10:22:05 -0400 [thread overview]
Message-ID: <9c67f5690bd4d5625b799f40e68fa54373617341.camel@talbothome.com> (raw)
In-Reply-To: <eee886683aa0cbf57ec3f0c8637ba02bc01600d6.camel@talbothome.com>
Android and iOS enforce a maximum attachment size for MMS messages.
This patch enforces a maximum attachment size for MMS messages and
makes it user configurable.
The Default maximum size is based off of Android, which has a maximum
MMS size of 1.1 Megabytes
---
src/service.c | 38 ++++++++++++++++++++++++++++++++++----
1 file changed, 34 insertions(+), 4 deletions(-)
diff --git a/src/service.c b/src/service.c
index a3b90c5..dede36d 100644
--- a/src/service.c
+++ b/src/service.c
@@ -56,6 +56,7 @@
#define MAX_ATTACHMENTS_NUMBER 25
#define MAX_ATTEMPTS 3
+#define DEFAULT_MAX_ATTACHMENT_TOTAL_SIZE 1100000
#define SETTINGS_STORE "mms"
#define SETTINGS_GROUP "Settings"
@@ -100,6 +101,7 @@ struct mms_service {
GHashTable *messages;
GKeyFile *settings;
gboolean use_delivery_reports;
+ int max_attach_total_size;
};
enum mms_request_type {
@@ -146,7 +148,22 @@ static void mms_load_settings(struct mms_service
*service)
g_key_file_set_boolean(service->settings,
SETTINGS_GROUP,
"UseDeliveryReports",
service-
>use_delivery_reports);
+ error = NULL;
}
+
+ service->max_attach_total_size =
+ g_key_file_get_integer(service->settings,
SETTINGS_GROUP,
+ "TotalMaxAttachmentSiz
e", &error);
+
+ if (error) {
+ g_error_free(error);
+ service->max_attach_total_size =
DEFAULT_MAX_ATTACHMENT_TOTAL_SIZE;
+ g_key_file_set_integer(service->settings,
SETTINGS_GROUP,
+ "TotalMaxAttachmentSiz
e",
+ service-
>max_attach_total_size);
+ }
+ mms_debug("Maximum Attachment Total Size (in bytes): %d",
service->max_attach_total_size);
+
}
static void mms_request_destroy(struct mms_request *request)
@@ -414,10 +431,11 @@ static gboolean
send_message_get_recipients(DBusMessageIter *top_iter,
}
static gboolean send_message_get_attachments(DBusMessageIter
*top_iter,
- struct mms_message
*msg)
+ struct mms_message
*msg, struct mms_service *service)
{
DBusMessageIter attachments;
unsigned int attach_num = 0;
+ int attach_total_size = 0;
dbus_message_iter_recurse(top_iter, &attachments);
@@ -430,8 +448,10 @@ static gboolean
send_message_get_attachments(DBusMessageIter *top_iter,
struct mms_attachment *attach;
void *ptr;
- if (++attach_num > MAX_ATTACHMENTS_NUMBER)
+ if (++attach_num > MAX_ATTACHMENTS_NUMBER) {
+ mms_error("Error: Too many attachments!");
return FALSE;
+ }
dbus_message_iter_recurse(&attachments, &entry);
@@ -466,6 +486,16 @@ static gboolean
send_message_get_attachments(DBusMessageIter *top_iter,
return FALSE;
}
+ attach_total_size = attach_total_size + attach-
>length;
+
+ mms_debug("Total attachment size: %d",
attach_total_size);
+ mms_debug("Maximum Attachment Total Size (in bytes):
%d", service->max_attach_total_size);
+
+ if (attach_total_size > service-
>max_attach_total_size) {
+ mms_error("Error: Total Attachment size too
large!");
+ return FALSE;
+ }
+
attach->data = ptr;
attach->content_id = g_strdup(id);
@@ -490,7 +520,7 @@ static gboolean
send_message_get_attachments(DBusMessageIter *top_iter,
}
static gboolean send_message_get_args(DBusMessage *dbus_msg,
- struct mms_message
*msg)
+ struct mms_message
*msg, struct mms_service *service)
{
DBusMessageIter top_iter;
const char *smil;
@@ -536,7 +566,7 @@ static gboolean send_message_get_args(DBusMessage
*dbus_msg,
if (dbus_message_iter_get_arg_type(&top_iter) !=
DBUS_TYPE_ARRAY)
return FALSE;
- return send_message_get_attachments(&top_iter, msg);
+ return send_message_get_attachments(&top_iter, msg, service);
}
static struct mms_request *create_request(enum mms_request_type type,
--
2.30.2
next prev parent reply other threads:[~2021-04-10 14:24 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-10 14:13 [PATCH 0/9] Updates for mmsd Chris Talbot
2021-04-10 14:17 ` [PATCH 1/9] Fix mmsd to work with T-mobile Chris Talbot
2021-04-10 14:20 ` [PATCH 2/9] Ensure Compatibility with Telus Canada Chris Talbot
2021-04-10 14:20 ` [PATCH 3/9] Ensure Compatibility with AT&T Chris Talbot
2021-04-10 14:21 ` [PATCH 4/9] Fix issue if there is an empty string in encoded text Chris Talbot
2021-04-10 14:22 ` Chris Talbot [this message]
2021-04-10 14:22 ` [PATCH 6/9] Update README Chris Talbot
2021-04-10 14:23 ` [PATCH 7/9] Fix Draft and Sent Bugs Chris Talbot
2021-04-10 14:23 ` [PATCH 8/9] Allow Maintainer mode to compile without -WError Chris Talbot
2021-04-10 14:24 ` [PATCH 9/9] Enable support for Modem Manager Chris Talbot
2021-04-14 18:21 ` Forking on MMSD Chris Talbot
2021-04-14 18:30 ` [Debian-on-mobile-maintainers] " Guido Günther
2021-04-14 18:46 ` Chris Talbot
2021-04-15 9:10 ` Guido Günther
2021-04-14 18:39 ` Marius Gripsgard
2021-04-14 22:09 ` Bug#985893: " Wookey
2021-04-15 0:12 ` Chris Talbot
2021-04-14 19:29 ` Pavel Machek
2021-04-14 21:11 ` Bug#985893: " Paul Wise
-- strict thread matches above, loose matches on Subject: below --
2021-03-26 10:51 [PATCH 5/9] Allow for a user configurable maximum attachment size Christopher Talbot
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=9c67f5690bd4d5625b799f40e68fa54373617341.camel@talbothome.com \
--to=chris@talbothome.com \
--cc=debian-on-mobile-maintainers@alioth-lists.debian.net \
--cc=librem-5-dev@lists.community.puri.sm \
--cc=netdev@vger.kernel.org \
--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 NNTP newsgroup(s).