static void
print_messaging_status (void)
{
    MMSmsStorage *supported = NULL;
    guint supported_len = 0;
    gchar *supported_str = NULL;

    mm_modem_messaging_get_supported_storages (ctx->modem_messaging,
                                               &supported,
                                               &supported_len);
    if (supported)
        supported_str = mm_common_build_sms_storages_string (supported, supported_len);

#undef VALIDATE_UNKNOWN
#define VALIDATE_UNKNOWN(str) (str ? str : "unknown")

    g_print ("\n"
             "%s\n"
             "  ----------------------------\n"
             "  Messaging | supported storages: '%s'\n"
             "            |    default storage: '%s'\n",
             mm_modem_messaging_get_path (ctx->modem_messaging),
             VALIDATE_UNKNOWN (supported_str),
             VALIDATE_UNKNOWN (mm_sms_storage_get_string (
                                   mm_modem_messaging_get_default_storage (
                                       ctx->modem_messaging))));
    g_free (supported_str);
}
static void
load_supported_storages_ready (MMIfaceModemMessaging *self,
                               GAsyncResult *res,
                               InitializationContext *ctx)
{
    StorageContext *storage_ctx;
    GError *error = NULL;

    storage_ctx = get_storage_context (self);
    if (!MM_IFACE_MODEM_MESSAGING_GET_INTERFACE (self)->load_supported_storages_finish (
            self,
            res,
            &storage_ctx->supported_mem1,
            &storage_ctx->supported_mem2,
            &storage_ctx->supported_mem3,
            &error)) {
        mm_dbg ("Couldn't load supported storages: '%s'", error->message);
        g_error_free (error);
    } else {
        gchar *mem1;
        gchar *mem2;
        gchar *mem3;
        GArray *supported_storages;
        guint i;

        mem1 = mm_common_build_sms_storages_string ((MMSmsStorage *)storage_ctx->supported_mem1->data,
                                                    storage_ctx->supported_mem1->len);
        mem2 = mm_common_build_sms_storages_string ((MMSmsStorage *)storage_ctx->supported_mem2->data,
                                                    storage_ctx->supported_mem2->len);
        mem3 = mm_common_build_sms_storages_string ((MMSmsStorage *)storage_ctx->supported_mem3->data,
                                                    storage_ctx->supported_mem3->len);

        mm_dbg ("Supported storages loaded:");
        mm_dbg ("  mem1 (list/read/delete) storages: '%s'", mem1);
        mm_dbg ("  mem2 (write/send) storages:       '%s'", mem2);
        mm_dbg ("  mem3 (reception) storages:        '%s'", mem3);
        g_free (mem1);
        g_free (mem2);
        g_free (mem3);

        /* We set in the interface the list of storages which are allowed for
         * both write/send and receive */
        supported_storages = g_array_sized_new (FALSE, FALSE, sizeof (guint32), storage_ctx->supported_mem2->len);
        for (i = 0; i < storage_ctx->supported_mem2->len; i++) {
            gboolean found = FALSE;
            guint j;

            for (j = 0; j < storage_ctx->supported_mem3->len && !found; j++) {
                if (g_array_index (storage_ctx->supported_mem3, MMSmsStorage, j) ==
                    g_array_index (storage_ctx->supported_mem2, MMSmsStorage, i))
                    found = TRUE;
            }

            if (found) {
                guint32 val;

                val = g_array_index (storage_ctx->supported_mem2, MMSmsStorage, i);
                g_array_append_val (supported_storages, val);
            }
        }

        mm_gdbus_modem_messaging_set_supported_storages (
            ctx->skeleton,
            mm_common_sms_storages_garray_to_variant (supported_storages));
        g_array_unref (supported_storages);
    }

    /* Go on to next step */
    ctx->step++;
    interface_initialization_step (ctx);
}