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; }
/** * gupnp_protocol_info_new_from_string: * @protocol_info: The protocol info string * @error: The location where to store any error, or NULL * * Parses the @protocol_info string and creates a new #GUPnPProtocolInfo object * as a result. * * Return value: A new #GUPnPProtocolInfo object. Unref after usage. **/ GUPnPProtocolInfo * gupnp_protocol_info_new_from_string (const char *protocol_info, GError **error) { GUPnPProtocolInfo *info; char **tokens; g_return_val_if_fail (protocol_info != NULL, NULL); tokens = g_strsplit (protocol_info, ":", 4); if (tokens[0] == NULL || tokens[1] == NULL || tokens[2] == NULL || tokens[3] == NULL) { g_set_error (error, GUPNP_PROTOCOL_ERROR, GUPNP_PROTOCOL_ERROR_INVALID_SYNTAX, "Failed to parse protocolInfo string: \n%s", protocol_info); g_strfreev (tokens); return NULL; } info = gupnp_protocol_info_new (); gupnp_protocol_info_set_protocol (info, tokens[0]); gupnp_protocol_info_set_network (info, tokens[1]); gupnp_protocol_info_set_mime_type (info, tokens[2]); parse_additional_info (tokens[3], info); g_strfreev (tokens); return info; }