static const char * create_res_for_file (const char *file_path, GUPnPDIDLLiteObject *object) { GUPnPDIDLLiteResource *res; GUPnPProtocolInfo *info; char *content_type; char *mime_type; const char *upnp_class; res = gupnp_didl_lite_object_add_resource (object); gupnp_didl_lite_resource_set_uri (res, ""); content_type = g_content_type_guess (file_path, NULL, 0, NULL); mime_type = g_content_type_get_mime_type (content_type); upnp_class = guess_upnp_class_for_mime_type (mime_type); info = gupnp_protocol_info_new (); gupnp_protocol_info_set_mime_type (info, mime_type); gupnp_protocol_info_set_protocol (info, "*"); gupnp_didl_lite_resource_set_protocol_info (res, info); g_object_unref (info); g_object_unref (res); g_free (mime_type); g_free (content_type); return upnp_class; }
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)); }