1 | /* $Id: http-server.h 87004 2020-11-27 16:18:47Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * Header file for HTTP server implementation.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2020 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | *
|
---|
17 | * The contents of this file may alternatively be used under the terms
|
---|
18 | * of the Common Development and Distribution License Version 1.0
|
---|
19 | * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
20 | * VirtualBox OSE distribution, in which case the provisions of the
|
---|
21 | * CDDL are applicable instead of those of the GPL.
|
---|
22 | *
|
---|
23 | * You may elect to license modified versions of this file under the
|
---|
24 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
25 | */
|
---|
26 |
|
---|
27 | #ifndef IPRT_INCLUDED_http_server_h
|
---|
28 | #define IPRT_INCLUDED_http_server_h
|
---|
29 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
30 | # pragma once
|
---|
31 | #endif
|
---|
32 |
|
---|
33 | #include <iprt/http-common.h>
|
---|
34 | #include <iprt/types.h>
|
---|
35 | #include <iprt/fs.h>
|
---|
36 |
|
---|
37 | RT_C_DECLS_BEGIN
|
---|
38 |
|
---|
39 | /** @defgroup grp_rt_http RTHttp - HTTP server.
|
---|
40 | * @ingroup grp_rt
|
---|
41 | * @{
|
---|
42 | */
|
---|
43 |
|
---|
44 | /** @defgroup grp_rt_httpserver RTHttpServer - HTTP server implementation.
|
---|
45 | * @{
|
---|
46 | */
|
---|
47 |
|
---|
48 | /** @todo the following three definitions may move the iprt/types.h later. */
|
---|
49 | /** HTTP server handle. */
|
---|
50 | typedef R3PTRTYPE(struct RTHTTPSERVERINTERNAL *) RTHTTPSERVER;
|
---|
51 | /** Pointer to a HTTP server handle. */
|
---|
52 | typedef RTHTTPSERVER *PRTHTTPSERVER;
|
---|
53 | /** Nil HTTP client handle. */
|
---|
54 | #define NIL_RTHTTPSERVER ((RTHTTPSERVER)0)
|
---|
55 |
|
---|
56 | /**
|
---|
57 | * Structure for maintaining a HTTP client request.
|
---|
58 | */
|
---|
59 | typedef struct RTHTTPSERVERREQ
|
---|
60 | {
|
---|
61 | char *pszUrl;
|
---|
62 | RTHTTPMETHOD enmMethod;
|
---|
63 | RTHTTPHEADERLIST hHdrLst;
|
---|
64 | void *pvBody;
|
---|
65 | size_t cbBodyAlloc;
|
---|
66 | size_t cbBodyUsed;
|
---|
67 | } RTHTTPSERVERREQ;
|
---|
68 | /** Pointer to a HTTP client request. */
|
---|
69 | typedef RTHTTPSERVERREQ *PRTHTTPSERVERREQ;
|
---|
70 |
|
---|
71 | /**
|
---|
72 | * Structure for maintaining a HTTP server response.
|
---|
73 | */
|
---|
74 | typedef struct RTHTTPSERVERRESP
|
---|
75 | {
|
---|
76 | RTHTTPSTATUS enmSts;
|
---|
77 | RTHTTPHEADERLIST hHdrLst;
|
---|
78 | void *pvBody;
|
---|
79 | size_t cbBodyAlloc;
|
---|
80 | size_t cbBodyUsed;
|
---|
81 | } RTHTTPSERVERRESP;
|
---|
82 | /** Pointer to a HTTP server response. */
|
---|
83 | typedef RTHTTPSERVERRESP *PRTHTTPSERVERRESP;
|
---|
84 |
|
---|
85 | /**
|
---|
86 | * Structure for maintaining a HTTP server client state.
|
---|
87 | *
|
---|
88 | * Note: The HTTP protocol itself is stateless, but we want to have to possibility to store
|
---|
89 | * some state stuff here nevertheless.
|
---|
90 | */
|
---|
91 | typedef struct RTHTTPSERVERCLIENTSTATE
|
---|
92 | {
|
---|
93 |
|
---|
94 | } RTHTTPSERVERCLIENTSTATE;
|
---|
95 | /** Pointer to a FTP server client state. */
|
---|
96 | typedef RTHTTPSERVERCLIENTSTATE *PRTHTTPSERVERCLIENTSTATE;
|
---|
97 |
|
---|
98 | /**
|
---|
99 | * Structure for storing HTTP server callback data.
|
---|
100 | */
|
---|
101 | typedef struct RTHTTPCALLBACKDATA
|
---|
102 | {
|
---|
103 | /** Pointer to the client state. */
|
---|
104 | PRTHTTPSERVERCLIENTSTATE pClient;
|
---|
105 | /** Saved user pointer. */
|
---|
106 | void *pvUser;
|
---|
107 | /** Size (in bytes) of data at user pointer. */
|
---|
108 | size_t cbUser;
|
---|
109 | } RTHTTPCALLBACKDATA;
|
---|
110 | /** Pointer to HTTP server callback data. */
|
---|
111 | typedef RTHTTPCALLBACKDATA *PRTHTTPCALLBACKDATA;
|
---|
112 |
|
---|
113 | /**
|
---|
114 | * Function callback table for the HTTP server implementation.
|
---|
115 | *
|
---|
116 | * All callbacks are optional and therefore can be NULL.
|
---|
117 | */
|
---|
118 | typedef struct RTHTTPSERVERCALLBACKS
|
---|
119 | {
|
---|
120 | DECLCALLBACKMEMBER(int, pfnOpen,(PRTHTTPCALLBACKDATA pData, const char *pszUrl, uint64_t *pidObj));
|
---|
121 | DECLCALLBACKMEMBER(int, pfnRead,(PRTHTTPCALLBACKDATA pData, uint64_t idObj, void *pvBuf, size_t cbBuf, size_t *pcbRead));
|
---|
122 | DECLCALLBACKMEMBER(int, pfnClose,(PRTHTTPCALLBACKDATA pData, uint64_t idObj));
|
---|
123 | DECLCALLBACKMEMBER(int, pfnQueryInfo,(PRTHTTPCALLBACKDATA pData, const char *pszUrl, PRTFSOBJINFO pObjInfo));
|
---|
124 | DECLCALLBACKMEMBER(int, pfnOnGetRequest,(PRTHTTPCALLBACKDATA pData, PRTHTTPSERVERREQ pReq));
|
---|
125 | DECLCALLBACKMEMBER(int, pfnOnHeadRequest,(PRTHTTPCALLBACKDATA pData, PRTHTTPSERVERREQ pReq));
|
---|
126 | } RTHTTPSERVERCALLBACKS;
|
---|
127 | /** Pointer to a HTTP server callback data table. */
|
---|
128 | typedef RTHTTPSERVERCALLBACKS *PRTHTTPSERVERCALLBACKS;
|
---|
129 |
|
---|
130 | /** Maximum length (in bytes) a client request can have. */
|
---|
131 | #define RTHTTPSERVER_MAX_REQ_LEN _8K
|
---|
132 |
|
---|
133 | /**
|
---|
134 | * Creates a HTTP server instance.
|
---|
135 | *
|
---|
136 | * @returns IPRT status code.
|
---|
137 | * @param phHTTPServer Where to store the HTTP server handle.
|
---|
138 | * @param pcszAddress The address for creating a listening socket.
|
---|
139 | * If NULL or empty string the server is bound to all interfaces.
|
---|
140 | * @param uPort The port for creating a listening socket.
|
---|
141 | * @param pCallbacks Callback table to use.
|
---|
142 | * @param pvUser Pointer to user-specific data. Optional.
|
---|
143 | * @param cbUser Size of user-specific data. Optional.
|
---|
144 | */
|
---|
145 | RTR3DECL(int) RTHttpServerCreate(PRTHTTPSERVER phHttpServer, const char *pcszAddress, uint16_t uPort,
|
---|
146 | PRTHTTPSERVERCALLBACKS pCallbacks, void *pvUser, size_t cbUser);
|
---|
147 |
|
---|
148 | /**
|
---|
149 | * Destroys a HTTP server instance.
|
---|
150 | *
|
---|
151 | * @returns IPRT status code.
|
---|
152 | * @param hHttpServer Handle to the HTTP server handle.
|
---|
153 | */
|
---|
154 | RTR3DECL(int) RTHttpServerDestroy(RTHTTPSERVER hHttpServer);
|
---|
155 |
|
---|
156 | /** @} */
|
---|
157 |
|
---|
158 | /** @} */
|
---|
159 | RT_C_DECLS_END
|
---|
160 |
|
---|
161 | #endif /* !IPRT_INCLUDED_http_server_h */
|
---|
162 |
|
---|