static void
print_sms_short_info (MMSms *sms)
{
    g_print ("\t%s (%s)\n",
             mm_sms_get_path (sms),
             mm_sms_state_get_string (mm_sms_get_state (sms)));
}
Exemple #2
0
static void
print_sms_info (MMSms *sms)
{
    /* Not the best thing to do, as we may be doing _get() calls twice, but
     * easiest to maintain */
#undef VALIDATE
#define VALIDATE(str) (str ? str : "unknown")

    g_print ("SMS '%s'\n",
             mm_sms_get_path (sms));
    g_print ("  -------------------------\n"
             "  Content    |      text: '%s'\n"
             "             |    number: '%s'\n"
             "  -------------------------\n"
             "  Properties |     state: '%s'\n"
             "             |      smsc: '%s'\n"
             "             | timestamp: '%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_state_get_string (mm_sms_get_state (sms)),
             VALIDATE (mm_sms_get_smsc (sms)),
             VALIDATE (mm_sms_get_timestamp (sms)),
             mm_sms_get_validity (sms),
             mm_sms_get_class (sms),
             mm_sms_storage_get_string (mm_sms_get_storage (sms)));
}
static void
get_sms_to_delete_ready (GDBusConnection *connection,
                         GAsyncResult *res)
{
    MMSms *sms;
    MMObject *obj = NULL;

    sms = mmcli_get_sms_finish (res, NULL, &obj);
    if (!g_str_equal (mm_object_get_path (obj), mm_modem_messaging_get_path (ctx->modem_messaging))) {
        g_printerr ("error: SMS '%s' not owned by modem '%s'",
                    mm_sms_get_path (sms),
                    mm_modem_messaging_get_path (ctx->modem_messaging));
        exit (EXIT_FAILURE);
    }

    mm_modem_messaging_delete (ctx->modem_messaging,
                               mm_sms_get_path (sms),
                               ctx->cancellable,
                               (GAsyncReadyCallback)delete_ready,
                               NULL);
    g_object_unref (sms);
    g_object_unref (obj);
}
static MMSms *
find_sms_in_list (GList *list,
                  const gchar *sms_path)
{
    GList *l;

    for (l = list; l; l = g_list_next (l)) {
        MMSms *sms = MM_SMS (l->data);

        if (g_str_equal (mm_sms_get_path (sms), sms_path)) {
            g_debug ("Sms found at '%s'\n", sms_path);
            return g_object_ref (sms);
        }
    }

    return NULL;
}
void
mmcli_modem_messaging_run_synchronous (GDBusConnection *connection)
{
    GError *error = NULL;

    /* Initialize context */
    ctx = g_new0 (Context, 1);
    ctx->object = mmcli_get_modem_sync (connection,
                                        mmcli_get_common_modem_string (),
                                        &ctx->manager);
    ctx->modem_messaging = mm_object_get_modem_messaging (ctx->object);

    /* Setup operation timeout */
    if (ctx->modem_messaging)
        mmcli_force_operation_timeout (G_DBUS_PROXY (ctx->modem_messaging));

    ensure_modem_messaging ();

    /* Request to get location status? */
    if (status_flag) {
        g_debug ("Printing messaging status...");
        print_messaging_status ();
        return;
    }

    /* Request to list the SMS? */
    if (list_flag) {
        GList *result;

        g_debug ("Synchronously listing SMS messages...");
        result = mm_modem_messaging_list_sync (ctx->modem_messaging, NULL, &error);
        list_process_reply (result, error);
        return;
    }

    /* Request to create a new SMS? */
    if (create_str) {
        MMSms *sms;
        GError *error = NULL;
        MMSmsProperties *properties;

        properties = build_sms_properties_from_input (create_str,
                                                      create_with_data_str);
        g_debug ("Synchronously creating new SMS in modem...");
        sms = mm_modem_messaging_create_sync (ctx->modem_messaging,
                                              properties,
                                              NULL,
                                              &error);
        g_object_unref (properties);

        create_process_reply (sms, error);
        return;
    }

    /* Request to delete a given SMS? */
    if (delete_str) {
        gboolean result;
        MMSms *sms;
        MMObject *obj = NULL;

        sms = mmcli_get_sms_sync (connection,
                                  delete_str,
                                  NULL,
                                  &obj);
        if (!g_str_equal (mm_object_get_path (obj), mm_modem_messaging_get_path (ctx->modem_messaging))) {
            g_printerr ("error: SMS '%s' not owned by modem '%s'",
                        mm_sms_get_path (sms),
                        mm_modem_messaging_get_path (ctx->modem_messaging));
            exit (EXIT_FAILURE);
        }

        result = mm_modem_messaging_delete_sync (ctx->modem_messaging,
                                                 mm_sms_get_path (sms),
                                                 NULL,
                                                 &error);
        g_object_unref (sms);
        g_object_unref (obj);

        delete_process_reply (result, error);
        return;
    }

    g_warn_if_reached ();
}
Exemple #6
0
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 */
#undef VALIDATE
#define VALIDATE(str) (str ? str : "unknown")

    pdu_type = mm_sms_get_pdu_type (sms);

    g_print ("SMS '%s'\n",
             mm_sms_get_path (sms));
    g_print ("  -----------------------------------\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",
             mm_sms_pdu_type_get_string (pdu_type),
             mm_sms_state_get_string (mm_sms_get_state (sms)));

    if (mm_sms_get_validity_type (sms) == MM_SMS_VALIDITY_TYPE_RELATIVE)
        g_print ("             | validity (relative): '%u'\n",
                 mm_sms_get_validity_relative (sms));

    g_print ("             |             storage: '%s'\n",
             mm_sms_storage_get_string (mm_sms_get_storage (sms)));

    /* Print properties which are set, regardless of the pdu type */

    if (mm_sms_get_smsc (sms))
        g_print ("             |                smsc: '%s'\n",
                 mm_sms_get_smsc (sms));

    if (mm_sms_get_class (sms) >= 0)
        g_print ("             |               class: '%d'\n",
                 mm_sms_get_class (sms));

    if (mm_sms_get_teleservice_id (sms) != MM_SMS_CDMA_TELESERVICE_ID_UNKNOWN)
        g_print ("             |      teleservice id: '%s'\n",
                 mm_sms_cdma_teleservice_id_get_string (mm_sms_get_teleservice_id (sms)));

    if (mm_sms_get_service_category (sms) != MM_SMS_CDMA_SERVICE_CATEGORY_UNKNOWN)
        g_print ("             |    service category: '%s'\n",
                 mm_sms_cdma_service_category_get_string (mm_sms_get_service_category (sms)));

    /* Delivery report request just in 3GPP submit PDUs */
    if (pdu_type == MM_SMS_PDU_TYPE_SUBMIT)
        g_print ("             |     delivery report: '%s'\n",
                 mm_sms_get_delivery_report_request (sms) ? "requested" : "not requested");

    if (mm_sms_get_message_reference (sms) != 0)
        g_print ("             |   message reference: '%u'\n",
                 mm_sms_get_message_reference (sms));

    if (mm_sms_get_timestamp (sms))
        g_print ("             |           timestamp: '%s'\n",
                 mm_sms_get_timestamp (sms));

    if (mm_sms_get_delivery_state (sms) != MM_SMS_DELIVERY_STATE_UNKNOWN)
        g_print ("             |      delivery state: '%s' (0x%X)\n",
                 VALIDATE (mm_sms_delivery_state_get_string_extended (mm_sms_get_delivery_state (sms))),
                 mm_sms_get_delivery_state (sms));

    if (mm_sms_get_discharge_timestamp (sms))
        g_print ("             | discharge timestamp: '%s'\n",
                 mm_sms_get_discharge_timestamp (sms));
}
static void
handle_create_auth_ready (MMBaseModem *self,
                          GAsyncResult *res,
                          HandleCreateContext *ctx)
{
    MMModemState modem_state = MM_MODEM_STATE_UNKNOWN;
    MMSmsList *list = NULL;
    GError *error = NULL;
    MMSmsProperties *properties;
    MMSms *sms;

    if (!mm_base_modem_authorize_finish (self, res, &error)) {
        g_dbus_method_invocation_take_error (ctx->invocation, error);
        handle_create_context_free (ctx);
        return;
    }

    g_object_get (self,
                  MM_IFACE_MODEM_STATE, &modem_state,
                  NULL);

    if (modem_state < MM_MODEM_STATE_ENABLED) {
        g_dbus_method_invocation_return_error (ctx->invocation,
                                               MM_CORE_ERROR,
                                               MM_CORE_ERROR_WRONG_STATE,
                                               "Cannot create SMS: device not yet enabled");
        handle_create_context_free (ctx);
        return;
    }

    /* Parse input properties */
    properties = mm_sms_properties_new_from_dictionary (ctx->dictionary, &error);
    if (!properties) {
        g_dbus_method_invocation_take_error (ctx->invocation, error);
        handle_create_context_free (ctx);
        return;
    }

    sms = mm_sms_new_from_properties (MM_BASE_MODEM (self),
                                      properties,
                                      &error);
    if (!sms) {
        g_object_unref (properties);
        g_dbus_method_invocation_take_error (ctx->invocation, error);
        handle_create_context_free (ctx);
        return;
    }

    g_object_get (self,
                  MM_IFACE_MODEM_MESSAGING_SMS_LIST, &list,
                  NULL);
    if (!list) {
        g_object_unref (properties);
        g_object_unref (sms);
        g_dbus_method_invocation_return_error (ctx->invocation,
                                               MM_CORE_ERROR,
                                               MM_CORE_ERROR_WRONG_STATE,
                                               "Cannot create SMS: missing SMS list");
        handle_create_context_free (ctx);
        return;
    }

    /* Add it to the list */
    mm_sms_list_add_sms (list, sms);

    /* Complete the DBus call */
    mm_gdbus_modem_messaging_complete_create (ctx->skeleton,
                                              ctx->invocation,
                                              mm_sms_get_path (sms));
    g_object_unref (sms);

    g_object_unref (properties);
    g_object_unref (list);

    handle_create_context_free (ctx);
}