Esempio n. 1
0
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;
}