Exemple #1
0
static QString generateMetaData(GUPnPDIDLLiteObject *object)
{
    GList *resources, *it;

    if (GUPNP_IS_DIDL_LITE_CONTAINER(object)) {
        return QString();
    }

    // produce minimal DIDL
    auto writer = wrap(gupnp_didl_lite_writer_new (NULL));
    GUPnPDIDLLiteObject *item = GUPNP_DIDL_LITE_OBJECT(gupnp_didl_lite_writer_add_item(writer));
    const char *title = gupnp_didl_lite_object_get_title(object);

    // maximum title length is 256 bytes
    if (strlen(title) > 256) {
        char *tmp = 0;
        const char *end_ptr = 0;

        g_utf8_validate(title, 256, &end_ptr);
        tmp = g_strndup(title, end_ptr - title);
        gupnp_didl_lite_object_set_title(item, tmp);
        g_free(tmp);
    } else {
        gupnp_didl_lite_object_set_title(item, title);
    }

    gupnp_didl_lite_object_set_upnp_class(item, gupnp_didl_lite_object_get_upnp_class(object));
    gupnp_didl_lite_object_set_parent_id(item, gupnp_didl_lite_object_get_parent_id(object));
    gupnp_didl_lite_object_set_id(item, gupnp_didl_lite_object_get_id(object));
    gupnp_didl_lite_object_set_restricted(item, gupnp_didl_lite_object_get_restricted(object));
    it = resources = gupnp_didl_lite_object_get_resources(object);
    while (it != 0) {
        GUPnPDIDLLiteResource *orig_resource = GUPNP_DIDL_LITE_RESOURCE(it->data);
        GUPnPDIDLLiteResource *resource = gupnp_didl_lite_object_add_resource(item);
        gupnp_didl_lite_resource_set_uri(resource,
                                         gupnp_didl_lite_resource_get_uri (orig_resource));
        gupnp_didl_lite_resource_set_protocol_info(resource,
                                                   gupnp_didl_lite_resource_get_protocol_info(orig_resource));

        it = it->next;
    }
    g_list_free_full(resources, (GDestroyNotify)g_object_unref);

    return QString::fromUtf8(gupnp_didl_lite_writer_get_string(writer));
}
static char *
create_didl_for_file (const char *file_path,
                      const char *title,
                      const char *parent_id)
{
        GUPnPDIDLLiteWriter *writer;
        GUPnPDIDLLiteObject *item;
        char *didl;
        char *new_title;
        const char *upnp_class;

        writer = gupnp_didl_lite_writer_new (NULL);

        item = GUPNP_DIDL_LITE_OBJECT
                        (gupnp_didl_lite_writer_add_item (writer));
        gupnp_didl_lite_object_set_parent_id (item, parent_id);
        gupnp_didl_lite_object_set_id (item, "");
        gupnp_didl_lite_object_set_restricted (item, FALSE);

        if (title == NULL) {
                new_title = g_path_get_basename (file_path);
        } else {
                new_title = g_strdup (title);
        }
        gupnp_didl_lite_object_set_title (item, new_title);
        g_free (new_title);

        upnp_class = create_res_for_file (file_path, item);
        if (upnp_class == NULL) {
                g_critical ("Failed to guess UPnP class for file '%s'",
                            file_path);

                g_object_unref (writer);

                return NULL;
        } else
                gupnp_didl_lite_object_set_upnp_class (item, upnp_class);

        didl = gupnp_didl_lite_writer_get_string (writer);

        g_object_unref (item);
        g_object_unref (writer);

        return didl;
}