summaryrefslogtreecommitdiff
path: root/inc/webserver.h
blob: 0a49cf963d20cc05d41a99fea68790c0382935c0 (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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/* 
 * File:   upnpwebserver.h
 * Author: savop
 *
 * Created on 30. Mai 2009, 18:13
 */

#ifndef _UPNPWEBSERVER_H
#define	_UPNPWEBSERVER_H

#include "../common.h"
#include <upnp/upnp.h>

/**
 * The internal webserver
 *
 * This is the internal webserver. It distributes all the contents of the
 * UPnP-Server.
 *
 */
class cUPnPWebServer {
    friend class cUPnPServer;
private:
    static cUPnPWebServer *mInstance;
    static UpnpVirtualDirCallbacks mVirtualDirCallbacks;
    const char* mRootdir;
    cUPnPWebServer(const char* root = "/");
protected:
public:
    /**
     * Initializes the webserver
     *
     * It enables the webserver which comes with the <em>Intel SDK</em> and creates
     * virtual directories for shares media.
     *
     * @return returns
     * - \bc true, if initializing was successful
     * - \bc false, otherwise
     */
    bool init();
    /**
     * Uninitializes the webserver
     *
     * This stops the webserver.
     *
     * @return returns
     * - \bc true, if initializing was successful
     * - \bc false, otherwise
     */
    bool uninit();
    /**
     * Returns the instance of the webserver
     *
     * Returns the instance of the webserver. This will create a single
     * instance of none is existing on the very first call. A subsequent call
     * will return the same instance.
     *
     * @return the instance of webserver
     */
    static cUPnPWebServer* getInstance(
        const char* rootdir = "/" /**< the root directory of the webserver */
    );
    virtual ~cUPnPWebServer();
//};

    /****************************************************
     *
     *  The callback functions for the webserver
     *
     ****************************************************/
    
    /**
     * Retrieve file information
     *
     * Returns file related information for an virtual directory file
     *
     * @return 0 on success, -1 otherwise
     * @param filename The filename of which the information is gathered
     * @param info     The File_Info structure with the data
     */
    static int getInfo(const char* filename, struct File_Info* info);
    /**
     * Opens a virtual directory file
     *
     * Opens a file in a virtual directory with the specified mode.
     *
     * Possible modes are:
     * - \b UPNP_READ,    Opens the file for reading
     * - \b UPNP_WRITE,    Opens the file for writing
     *
     * It returns a file handle to the opened file, NULL otherwise
     *
     * @return FileHandle to the opened file, NULL otherwise
     * @param filename The file to open
     * @param mode UPNP_WRITE for writing, UPNP_READ for reading.
     */
    static UpnpWebFileHandle open(const char* filename, UpnpOpenFileMode mode);
    /**
     * Reads from the opened file
     *
     * Reads <code>buflen</code> bytes from the file and stores the content
     * to the buffer
     *
     * Returns 0 no more bytes read (EOF)
     *         >0 bytes read from file
     *
     * @return number of bytes read, 0 on EOF
     * @param fh the file handle of the opened file
     * @param buf the buffer to write the bytes to
     * @param buflen the maximum count of bytes to read
     *
     */
    static int read(UpnpWebFileHandle fh, char* buf, size_t buflen);
    /**
     * Writes to the opened file
     *
     * Writes <code>buflen</code> bytes from the buffer and stores the content
     * in the file
     *
     * Returns >0 bytes wrote to file, maybe less the buflen in case of write
     * errors
     *
     * @return number of bytes read, 0 on EOF
     * @param fh the file handle of the opened file
     * @param buf the buffer to read the bytes from
     * @param buflen the maximum count of bytes to write
     *
     */
    static int write(UpnpWebFileHandle fh, char* buf, size_t buflen);
    /**
     * Seek in the file
     *
     * Seeks in the opened file and sets the file pointer to the specified offset
     *
     * Returns 0 on success, non-zero value otherwise
     *
     * @return 0 on success, non-zero value otherwise
     * @param fh the file handle of the opened file
     * @param offset a negative oder positive value which moves the pointer
     *        forward or backward
     * @param origin SEEK_CUR, SEEK_END or SEEK_SET
     *
     */
    static int seek(UpnpWebFileHandle fh, off_t offset, int origin);
    /**
     * Closes the file
     *
     * closes the opened file
     *
     * Returns 0 on success, non-zero value otherwise
     *
     * @return 0 on success, non-zero value otherwise
     * @param fh the file handle of the opened file
     *
     */
    static int close(UpnpWebFileHandle fh);
};

#endif	/* _UPNPWEBSERVER_H */