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 void gupnp_protocol_info_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec) { GUPnPProtocolInfo *info; info = GUPNP_PROTOCOL_INFO (object); switch (property_id) { case PROP_PROTOCOL: gupnp_protocol_info_set_protocol (info, g_value_get_string (value)); break; case PROP_NETWORK: gupnp_protocol_info_set_network (info, g_value_get_string (value)); break; case PROP_MIME_TYPE: gupnp_protocol_info_set_mime_type (info, g_value_get_string (value)); break; case PROP_DLNA_PROFILE: gupnp_protocol_info_set_dlna_profile (info, g_value_get_string (value)); break; case PROP_PLAY_SPEEDS: gupnp_protocol_info_set_play_speeds (info, g_value_get_boxed (value)); break; case PROP_DLNA_CONVERSION: gupnp_protocol_info_set_dlna_conversion (info, g_value_get_flags (value)); break; case PROP_DLNA_OPERATION: gupnp_protocol_info_set_dlna_operation (info, g_value_get_flags (value)); break; case PROP_DLNA_FLAGS: gupnp_protocol_info_set_dlna_flags (info, g_value_get_flags (value)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; } }
/** * 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; }
/** * korva_upnp_host_data_get_protocol_info: * * Get the UPnP-AV/DLNA protocol info string for the :file. The transport is * always "http-get". The ci-param is "0" (original source) and op-param is "01" * (byte seek only). If :meta-data contains a DLNA profile it will be added as * well as the the file's content type. * * The function lazy-creates the string when used for the first time. * * @self: An instance of #KorvaUPnPHostData * * Returns: (transfer none): A protocol info string. */ const char * korva_upnp_host_data_get_protocol_info (KorvaUPnPHostData *self) { if (self->priv->protocol_info == NULL) { GVariant *value; const char *dlna_profile; GUPnPProtocolInfo *info; info = gupnp_protocol_info_new_from_string ("http-get:*:*:DLNA.ORG_CI=0;DLNA.ORG_OP=01", NULL); gupnp_protocol_info_set_mime_type (info, korva_upnp_host_data_get_content_type (self)); value = g_hash_table_lookup (self->priv->meta_data, "DLNAProfile"); if (value != NULL) { dlna_profile = g_variant_get_string (value, NULL); gupnp_protocol_info_set_dlna_profile (info, dlna_profile); } self->priv->protocol_info = gupnp_protocol_info_to_string (info); g_object_unref (info); } return self->priv->protocol_info; }