summaryrefslogtreecommitdiff
path: root/src/librygel-server/rygel-http-get-handler.vala
blob: 42adbc0f5e512c96da939b96fecedfe2215101c1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/*
 * Copyright (C) 2008-2010 Nokia Corporation.
 * Copyright (C) 2010 Andreas Henriksson <andreas@fatal.se>
 * Copyright (C) 2013 Cable Television Laboratories, Inc.
 *
 * Author: Zeeshan Ali (Khattak) <zeeshanak@gnome.org>
 *                               <zeeshan.ali@nokia.com>
 *         Craig Pratt <craig@ecaspia.com>
 *
 * This file is part of Rygel.
 *
 * Rygel is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * Rygel is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */

using GUPnP;

/**
 * HTTP GET request handler interface.
 */
public abstract class Rygel.HTTPGetHandler: GLib.Object {
    protected const string TRANSFER_MODE_HEADER = "transferMode.dlna.org";

    protected const string TRANSFER_MODE_STREAMING = "Streaming";
    protected const string TRANSFER_MODE_INTERACTIVE = "Interactive";
    protected const string TRANSFER_MODE_BACKGROUND = "Background";

    public Cancellable cancellable { get; set; }

    /**
     * Invokes the handler to add response headers to/for the given HTTP request
     */
    public virtual void add_response_headers (HTTPGet request)
                                              throws HTTPRequestError {
        var mode = request.msg.request_headers.get_one (TRANSFER_MODE_HEADER);

        // Per DLNA 7.5.4.3.2.33.2, if the transferMode header is empty it
        // must be treated as Streaming mode or Interactive, depending upon
        // the content
        if (mode == null) {
            mode = this.get_default_transfer_mode ();
        }
        request.msg.response_headers.append (TRANSFER_MODE_HEADER, mode);

        // Handle device-specific hacks that need to change the response
        // headers such as Samsung's subtitle stuff.
        if (request.hack != null) {
            request.hack.modify_headers (request);
        }
    }

    /**
     * Returns the default transfer mode for the handler.
     * The default is "Interactive"
     */
    public virtual string get_default_transfer_mode () {
        return TRANSFER_MODE_INTERACTIVE; // Considering this the default
    }

    /**
     * Returns true if the handler supports the given transfer mode, false
     * otherwise.
     */
    public abstract bool supports_transfer_mode (string mode);

    /**
     * Returns the resource size or -1 if not known.
     */
    public abstract int64 get_resource_size ();

    /**
     * Returns the resource duration (in microseconds) or -1 if not known.
     */
    public virtual int64 get_resource_duration () {
        return -1;
    }

    /**
     * Returns true if the handler supports full random-access byte seek.
     */
    public virtual bool supports_byte_seek () {
        return false;
    }

    /**
     * Returns true if the handler supports full random-access time seek.
     */
    public virtual bool supports_time_seek () {
        return false;
    }

    /**
     * Returns true if the handler supports any play speed requests.
     */
    public virtual bool supports_playspeed () {
        return false;
    }

    /**
     * Create an HTTPResponse object that will render the body.
     */
    public abstract HTTPResponse render_body (HTTPGet request)
                                              throws HTTPRequestError;

}