HTTPConnection.hpp 3.28 KB
Newer Older
Christopher Mueller's avatar
Christopher Mueller committed
1
/*
2
 * HTTPConnection.hpp
Christopher Mueller's avatar
Christopher Mueller committed
3 4
 *****************************************************************************
 * Copyright (C) 2010 - 2011 Klagenfurt University
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
5
 *               2014 - 2015 VideoLAN and VLC Authors
Christopher Mueller's avatar
Christopher Mueller committed
6 7 8 9 10
 *
 * Created on: Aug 10, 2010
 * Authors: Christopher Mueller <christopher.mueller@itec.uni-klu.ac.at>
 *          Christian Timmerer  <christian.timmerer@itec.uni-klu.ac.at>
 *
11 12
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published
Christopher Mueller's avatar
Christopher Mueller committed
13 14 15 16 17
 * by the Free Software Foundation; either version 2.1 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Lesser General Public License for more details.
Christopher Mueller's avatar
Christopher Mueller committed
20 21
 *
 * You should have received a copy of the GNU Lesser General Public License
22 23
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
Christopher Mueller's avatar
Christopher Mueller committed
24
 *****************************************************************************/
25 26
#ifndef HTTPCONNECTION_H_
#define HTTPCONNECTION_H_
Christopher Mueller's avatar
Christopher Mueller committed
27

28 29 30 31
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

32
#include "BytesRange.hpp"
33
#include <vlc_common.h>
34
#include <string>
Christopher Mueller's avatar
Christopher Mueller committed
35

36
namespace adaptive
Christopher Mueller's avatar
Christopher Mueller committed
37 38 39
{
    namespace http
    {
40 41 42
        class Socket;

        class HTTPConnection
Christopher Mueller's avatar
Christopher Mueller committed
43 44
        {
            public:
45
                HTTPConnection(vlc_object_t *stream, Socket *, bool = false);
46
                virtual ~HTTPConnection();
47

48 49
                virtual bool    compare     (const std::string &, uint16_t, int) const;
                virtual bool    connect     (const std::string& hostname, uint16_t port = 80);
50
                virtual bool    connected   () const;
51
                virtual int     query       (const std::string& path, const BytesRange & = BytesRange());
52 53 54 55 56
                virtual bool    send        (const void *buf, size_t size);
                virtual ssize_t read        (void *p_buffer, size_t len);
                virtual void    disconnect  ();
                virtual bool    send        (const std::string &data);

57 58 59
                size_t getContentLength() const;
                bool isAvailable () const;
                void setUsed( bool );
60

61
            protected:
62

63 64 65
                virtual void    onHeader    (const std::string &line,
                                             const std::string &value);
                virtual std::string extraRequestHeaders() const;
66 67
                virtual std::string buildRequestHeader(const std::string &path) const;

68
                int parseReply();
69 70
                std::string readLine();
                std::string hostname;
71
                uint16_t port;
72
                char * psz_useragent;
73
                vlc_object_t *stream;
74 75 76 77
                size_t bytesRead;
                size_t contentLength;
                BytesRange bytesRange;
                bool available;
78 79 80 81 82

                bool                connectionClose;
                bool                queryOk;
                int                 retries;
                static const int    retryCount = 5;
83 84

            private:
85 86
                Socket *socket;
       };
Christopher Mueller's avatar
Christopher Mueller committed
87 88 89
    }
}

90
#endif /* HTTPCONNECTION_H_ */