Commit d8dbfb6b authored by Slava Monich's avatar Slava Monich

[mms_task_encode] Append file extensions for known media types

Good for interoperability with non-Jolla phones.
parent 07d474df
......@@ -387,15 +387,52 @@ mms_task_encode_finalize(
static
char*
mms_task_encode_generate_unique_path(
mms_task_encode_generate_path(
const char* dir,
const char* file)
const char* file,
const char* content_type)
{
int i;
char* path;
char* tmpfile = NULL;
/* For interoperability reasons, it's better if the file extension
* matches the content type. */
if (content_type) {
char** parsed = mms_parse_http_content_type(content_type);
if (parsed) {
static const struct extension_map {
const char* type;
const char* ext;
} known_extensions [] = {
{ "image/jpeg", ".jpg" },
{ "image/png", ".png" },
{ "image/bmp", ".bmp" },
{ "image/gif", ".gif" },
{ "text/plain", ".txt" },
{ "text/html", ".html" },
};
const char* type = parsed[0];
const char* known_ext = NULL;
for (i=0; i<(int)G_N_ELEMENTS(known_extensions); i++) {
if (!strcmp(type, known_extensions[i].type)) {
known_ext = known_extensions[i].ext;
break;
}
}
if (known_ext) {
const char* ext = strrchr(file, '.');
if (!ext || strcasecmp(ext, known_ext)) {
file = tmpfile = g_strconcat(file, known_ext, NULL);
}
}
g_strfreev(parsed);
}
}
/* Most likely the very first check would succeed */
char* path = g_strconcat(dir, "/", file, NULL);
path = g_strconcat(dir, "/", file, NULL);
if (g_file_test(path, G_FILE_TEST_IS_REGULAR)) {
int i;
char* tmpfile = NULL;
for (i=0; i<100; i++) {
char* newfile = g_strconcat("_", file, NULL);
g_free(tmpfile);
......@@ -404,8 +441,8 @@ mms_task_encode_generate_unique_path(
file = tmpfile = newfile;
if (!g_file_test(path, G_FILE_TEST_IS_REGULAR)) break;
}
g_free(tmpfile);
}
g_free(tmpfile);
return path;
}
......@@ -425,8 +462,8 @@ mms_task_encode_prepare_attachments(
MMSAttachment* attachment = NULL;
MMSAttachmentInfo info = parts[i];
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
char* path = mms_task_encode_generate_unique_path(dir,
g_basename(info.file_name));
char* path = mms_task_encode_generate_path(dir,
g_basename(info.file_name), info.content_type);
G_GNUC_END_IGNORE_DEPRECATIONS
GFile* src = g_file_new_for_path(info.file_name);
GFile* dest = g_file_new_for_path(path);
......@@ -452,7 +489,7 @@ mms_task_encode_prepare_attachments(
if (i == nparts) {
/* Generate SMIL if necessary */
if (smil_index < 0) {
char* path = mms_task_encode_generate_unique_path(dir, "smil");
char* path = mms_task_encode_generate_path(dir, "smil", NULL);
MMSAttachment* smil = mms_attachment_new_smil(config, path,
(MMSAttachment**)array->pdata, array->len, error);
g_free(path);
......
<!DOCTYPE smil PUBLIC "-//W3C//DTD SMIL 1.0//EN" "http://www.w3.org/TR/REC-smil/SMIL10.dtd">
<smil>
<head>
<layout>
<root-layout height="160" width="120"/>
<region fit="scroll" height="100%" left="0" top="0" width="100%" id="Text"/>
<region fit="meet" height="100%" left="0" top="0" width="100%" id="Media"/>
</layout>
</head>
<body>
<par dur="5000ms">
<text src="test.txt" region="Text"/>
<img src="0001.jpg" region="Media"/>
</par>
</body>
</smil>
Тестовое сообщение
......@@ -78,16 +78,24 @@ static const MMSAttachmentInfo test_files_accept [] = {
{ "test.txt", "text/plain;charset=utf-8", "text" }
};
static const MMSAttachmentInfo test_files_accept_no_ext [] = {
{ "smil", NULL, NULL },
{ "0001", "image/jpeg", "image1" },
{ "0001", "image/jpeg", "image2" },
{ "test.text", "text/plain;charset=utf-8", "text" }
};
static const MMSAttachmentInfo test_files_reject [] = {
{ "0001.png", "image/png", "image" },
{ "test.txt", "text/plain", "text" }
};
#define ATTACHMENTS(a) a, G_N_ELEMENTS(a)
static const TestDesc send_tests[] = {
{
"Accept",
test_files_accept,
G_N_ELEMENTS(test_files_accept),
ATTACHMENTS(test_files_accept),
"Test of successful delivery",
"+1234567890",
"+2345678901,+3456789012",
......@@ -99,10 +107,23 @@ static const TestDesc send_tests[] = {
SOUP_STATUS_OK,
MMS_SEND_STATE_SENDING,
"TestMessageId"
},{
"AcceptNoExt",
ATTACHMENTS(test_files_accept_no_ext),
"Test of successful delivery (no extensions)",
"+1234567890",
"+2345678901,+3456789012",
"+4567890123",
"IMSI",
0,
"m-send.conf",
MMS_CONTENT_TYPE,
SOUP_STATUS_OK,
MMS_SEND_STATE_SENDING,
"TestMessageId"
},{
"Reject",
test_files_reject,
G_N_ELEMENTS(test_files_reject),
ATTACHMENTS(test_files_reject),
"Rejection test",
"+1234567890",
NULL,
......
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