aboutsummaryrefslogtreecommitdiff
path: root/cli
diff options
context:
space:
mode:
authorAleksander Morgado <aleksander@lanedo.com>2012-09-12 15:44:01 +0200
committerAleksander Morgado <aleksander@lanedo.com>2012-09-14 07:05:26 +0200
commitf6832d72cf386eb495c5d2b988d24c1a963f71d6 (patch)
treee2d700ebfa5f6ddb0d755b53be2d97561602201e /cli
parent015627974984ef7b5a7595421a9921fbaa759555 (diff)
cli: new `--create-file-with-data' action for SMS objects
This new action allows creating a new file with the binary data stored in the SMS, if any. E.g.: $> sudo mmcli -s 7 \ --create-file-with-data=output.txt This action can only be run on SMS object with binary data.
Diffstat (limited to 'cli')
-rw-r--r--cli/mmcli-sms.c80
1 files changed, 74 insertions, 6 deletions
diff --git a/cli/mmcli-sms.c b/cli/mmcli-sms.c
index f9625b14..f35e84d6 100644
--- a/cli/mmcli-sms.c
+++ b/cli/mmcli-sms.c
@@ -47,6 +47,7 @@ static gboolean info_flag; /* set when no action found */
static gboolean send_flag;
static gboolean store_flag;
static gchar *store_in_storage_str;
+static gchar *create_file_with_data_str;
static GOptionEntry entries[] = {
{ "send", 0, 0, G_OPTION_ARG_NONE, &send_flag,
@@ -61,6 +62,10 @@ static GOptionEntry entries[] = {
"Store the SMS in the device, at the specified storage",
NULL,
},
+ { "create-file-with-data", 0, 0, G_OPTION_ARG_STRING, &create_file_with_data_str,
+ "Create a file with the data contents of the SMS.",
+ "[File path",
+ },
{ NULL }
};
@@ -91,7 +96,8 @@ mmcli_sms_options_enabled (void)
n_actions = (send_flag +
store_flag +
- !!store_in_storage_str);
+ !!store_in_storage_str +
+ !!create_file_with_data_str);
if (n_actions == 0 && mmcli_get_common_sms_string ()) {
/* default to info */
@@ -107,6 +113,9 @@ mmcli_sms_options_enabled (void)
if (info_flag)
mmcli_force_sync_operation ();
+ if (create_file_with_data_str)
+ mmcli_force_sync_operation ();
+
checked = TRUE;
return !!n_actions;
}
@@ -138,6 +147,8 @@ static void
print_sms_info (MMSms *sms)
{
MMSmsPduType pdu_type;
+ const guint8 *data;
+ gsize data_size;
/* Not the best thing to do, as we may be doing _get() calls twice, but
* easiest to maintain */
@@ -149,17 +160,32 @@ print_sms_info (MMSms *sms)
g_print ("SMS '%s'\n",
mm_sms_get_path (sms));
g_print (" -----------------------------------\n"
- " Content | text: '%s'\n"
- " | number: '%s'\n"
- " -----------------------------------\n"
+ " Content | number: '%s'\n",
+ VALIDATE (mm_sms_get_number (sms)));
+
+ if (mm_sms_get_text (sms))
+ g_print (" | text : '%s'\n",
+ VALIDATE (mm_sms_get_text (sms)));
+
+ data = mm_sms_get_data (sms, &data_size);
+ if (data) {
+ gchar *data_hex;
+
+ data_hex = mm_utils_bin2hexstr (data, data_size);
+ g_print (" | data : '%s'\n",
+ VALIDATE (data_hex));
+ g_free (data_hex);
+ }
+
+ g_print (" -----------------------------------\n"
" Properties | PDU type: '%s'\n"
" | state: '%s'\n"
" | smsc: '%s'\n"
" | validity: '%u'\n"
" | class: '%u'\n"
" | storage: '%s'\n",
- VALIDATE (mm_sms_get_text (sms)),
- VALIDATE (mm_sms_get_number (sms)),
+
+
mm_sms_pdu_type_get_string (pdu_type),
mm_sms_state_get_string (mm_sms_get_state (sms)),
VALIDATE (mm_sms_get_smsc (sms)),
@@ -191,6 +217,38 @@ print_sms_info (MMSms *sms)
}
static void
+create_file_with_data (MMSms *sms,
+ const gchar *input_path_str)
+{
+ GError *error = NULL;
+ gchar *path;
+ GFile *file;
+ const guint8 *data;
+ gsize data_size;
+
+ file = g_file_new_for_commandline_arg (input_path_str);
+ path = g_file_get_path (file);
+
+ data = mm_sms_get_data (sms, &data_size);
+ if (!data) {
+ g_printerr ("error: couldn't create file: SMS has no data\n");
+ exit (EXIT_FAILURE);
+ }
+
+ if (!g_file_set_contents (path,
+ (const gchar *)data,
+ data_size,
+ &error)) {
+ g_printerr ("error: cannot write to file '%s': '%s'\n",
+ input_path_str, error->message);
+ exit (EXIT_FAILURE);
+ }
+
+ g_free (path);
+ g_object_unref (file);
+}
+
+static void
send_process_reply (gboolean result,
const GError *error)
{
@@ -258,6 +316,9 @@ get_sms_ready (GObject *source,
if (info_flag)
g_assert_not_reached ();
+ if (create_file_with_data_str)
+ g_assert_not_reached ();
+
/* Requesting to send the SMS? */
if (send_flag) {
mm_sms_send (ctx->sms,
@@ -339,6 +400,13 @@ mmcli_sms_run_synchronous (GDBusConnection *connection)
return;
}
+ /* Request to create a new file with the data from the SMS? */
+ if (create_file_with_data_str) {
+ g_debug ("Creating file with SMS data...");
+ create_file_with_data (ctx->sms, create_file_with_data_str);
+ return;
+ }
+
/* Requesting to send the SMS? */
if (send_flag) {
gboolean operation_result;