diff --git a/mms-send/Makefile b/mms-send/Makefile index b985a1c..c8c33b5 100644 --- a/mms-send/Makefile +++ b/mms-send/Makefile @@ -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) # diff --git a/mms-send/mms-send.c b/mms-send/mms-send.c index c57c0e9..adc405d 100644 --- a/mms-send/mms-send.c +++ b/mms-send/mms-send.c @@ -1,5 +1,5 @@ /* - * 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 #include +#include + /* 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 && ictype, 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; } diff --git a/mms-send/mms-send.pro b/mms-send/mms-send.pro index 7232325..71e4c9a 100644 --- a/mms-send/mms-send.pro +++ b/mms-send/mms-send.pro @@ -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