Commit c239d7e4 authored by Slava Monich's avatar Slava Monich

[mms-send] Added -t, --content-type=TYPE option. JB#42104

Allows to specify content type for the attachment. Can be repeated
if there are several attachments. The first content type is applied
to the first attachment, the second content type to the second
attachment and so on.
parent 7ef151b4
......@@ -3,7 +3,7 @@
.PHONY: all debug release clean
# Required packages
PKGS = gio-unix-2.0 gio-2.0 glib-2.0
PKGS = libglibutil gio-unix-2.0 gio-2.0 glib-2.0
LIB_PKGS = $(PKGS)
#
......
/*
* Copyright (C) 2013-2016 Jolla Ltd.
* Copyright (C) 2013-2019 Jolla Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
......@@ -18,6 +18,8 @@
#include <stdlib.h>
#include <string.h>
#include <gutil_strv.h>
/* Generated headers */
#include "org.nemomobile.MmsEngine.h"
......@@ -29,24 +31,23 @@ enum app_ret_value {
RET_ERR_SEND
};
typedef struct mms_send_opt {
char** ctype;
char* imsi;
char* subject;
const char* to;
guint flags;
} MmsSendOpt;
#define MMS_SEND_REQUEST_DELIVERY_REPORT (0x01)
#define MMS_SEND_REQUEST_READ_REPORT (0x02)
#define MMS_SEND_FLAG_VERBOSE (0x04)
/* Protocol flags */
#define MMS_SEND_REQUEST_PROTOCOL_FLAGS (\
MMS_SEND_REQUEST_DELIVERY_REPORT |\
MMS_SEND_REQUEST_READ_REPORT )
static
char*
mms_send(
char* files[],
int count,
const char* imsi,
const char* to,
const char* subject,
int flags)
const MmsSendOpt* opt)
{
char* imsi_out = NULL;
GError* error = NULL;
......@@ -54,6 +55,7 @@ mms_send(
org_nemomobile_mms_engine_proxy_new_for_bus_sync(
G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_NONE,
"org.nemomobile.MmsEngine", "/", NULL, &error);
if (proxy) {
int i;
gboolean ok = TRUE;
......@@ -62,10 +64,13 @@ mms_send(
GVariantBuilder b;
g_variant_builder_init(&b, G_VARIANT_TYPE("a(sss)"));
for (i=0; ok && i<count; i++) {
for (i = 0; ok && i < count; i++) {
if (realpath(files[i], fname)) {
if (g_file_test(fname, G_FILE_TEST_IS_REGULAR)) {
g_variant_builder_add(&b, "(sss)", fname, "", "");
const char* ctype = gutil_strv_at(opt->ctype, i);
g_variant_builder_add(&b, "(sss)", fname,
ctype ? ctype : "", "");
} else {
fprintf(stderr, "%s: no such file: %s\n", pname, fname);
ok = FALSE;
......@@ -78,17 +83,19 @@ mms_send(
parts = g_variant_ref_sink(g_variant_builder_end(&b));
if (ok) {
char** to_list = g_strsplit(to, ",", 0);
char** to_list = g_strsplit(opt->to, ",", 0);
const char* imsi = opt->imsi ? opt->imsi : "";
const char* subject = opt->subject ? opt->subject : "";
const char* none = NULL;
if (!org_nemomobile_mms_engine_call_send_message_sync(proxy,
0, imsi, (const gchar* const*)to_list, &none, &none, subject,
flags & MMS_SEND_REQUEST_PROTOCOL_FLAGS,
parts, &imsi_out, NULL, &error)) {
0, imsi, (const gchar* const*)to_list, &none, &none,
subject, opt->flags, parts, &imsi_out, NULL, &error)) {
/* D-Bus error */
fprintf(stderr, "%s\n", error->message);
g_error_free(error);
}
g_free(to_list);
g_strfreev(to_list);
}
g_free(fname);
......@@ -101,37 +108,73 @@ mms_send(
return imsi_out;
}
/* Limit the scape of global variable */
static MmsSendOpt app_opt;
static
void
mms_send_opt_init(
MmsSendOpt* opt)
{
memset(opt, 0, sizeof(*opt));
}
static
void
mms_send_opt_deinit(
MmsSendOpt* opt)
{
g_strfreev(opt->ctype);
g_free(opt->imsi);
g_free(opt->subject);
}
static
gboolean
mms_send_opt_content_type(
const gchar* name,
const gchar* value,
gpointer data,
GError** error)
{
app_opt.ctype = gutil_strv_add(app_opt.ctype, value);
return TRUE;
}
int main(int argc, char* argv[])
{
int ret = RET_ERR_CMDLINE;
gboolean ok, verbose = FALSE, dr = FALSE, rr = FALSE;
GError* error = NULL;
char* imsi = "";
char* subject = "";
GOptionEntry entries[] = {
{ "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose,
"Enable verbose output", NULL },
{ "imsi", 'i', 0, G_OPTION_ARG_STRING, &imsi,
{ "imsi", 'i', 0, G_OPTION_ARG_STRING, &app_opt.imsi,
"Select the SIM card", "IMSI" },
{ "subject", 's', 0, G_OPTION_ARG_STRING, &subject,
{ "subject", 's', 0, G_OPTION_ARG_STRING, &app_opt.subject,
"Set message subject", "TEXT" },
{ "delivery-report", 'd', 0, G_OPTION_ARG_NONE, &dr,
"Request delivery report", NULL },
{ "read-report", 'r', 0, G_OPTION_ARG_NONE, &rr,
"Request read report", NULL },
{ "content-type", 't', 0, G_OPTION_ARG_CALLBACK,
mms_send_opt_content_type,
"Content type (repeatable)", "TYPE" },
{ NULL }
};
GOptionContext* options = g_option_context_new("TO FILES...");
mms_send_opt_init(&app_opt);
g_option_context_add_main_entries(options, entries, NULL);
ok = g_option_context_parse(options, &argc, &argv, &error);
if (ok) {
if (argc > 2) {
int flags = 0;
char* res;
if (verbose) flags |= MMS_SEND_FLAG_VERBOSE;
if (dr) flags |= MMS_SEND_REQUEST_DELIVERY_REPORT;
if (rr) flags |= MMS_SEND_REQUEST_READ_REPORT;
res = mms_send(argv+2, argc-2, imsi, argv[1], subject, flags);
if (dr) app_opt.flags |= MMS_SEND_REQUEST_DELIVERY_REPORT;
if (rr) app_opt.flags |= MMS_SEND_REQUEST_READ_REPORT;
app_opt.to = argv[1];
res = mms_send(argv + 2, argc - 2, &app_opt);
if (res) {
if (verbose) printf("%s\n", res);
g_free(res);
......@@ -147,6 +190,7 @@ int main(int argc, char* argv[])
g_error_free(error);
}
g_option_context_free(options);
mms_send_opt_deinit(&app_opt);
return ret;
}
......
......@@ -3,11 +3,13 @@ TARGET = mms-send
CONFIG -= qt
CONFIG += link_pkgconfig
PKGCONFIG += gio-unix-2.0 gio-2.0 glib-2.0
PKGCONFIG += libglibutil gio-unix-2.0 gio-2.0 glib-2.0
QMAKE_CFLAGS += -Wno-unused-parameter
SOURCES += mms-send.c
OTHER_FILES += Makefile
DBUS_SPEC_DIR = $$_PRO_FILE_PWD_/../mms-engine
# org.nemomobile.MmsEngine
......
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