VirtualBox

source: vbox/trunk/include/iprt/http-server.h@ 87012

Last change on this file since 87012 was 87012, checked in by vboxsync, 4 years ago

Shared Clipboard/Transfers: Docs fix. bugref:9874

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.3 KB
Line 
1/* $Id: http-server.h 87012 2020-11-27 17:55:37Z 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
37RT_C_DECLS_BEGIN
38
39/** @defgroup grp_rt_httpserver RTHttpServer - HTTP server implementation.
40 * @ingroup grp_rt
41 * @{
42 */
43
44/** @todo the following three definitions may move the iprt/types.h later. */
45/** HTTP server handle. */
46typedef R3PTRTYPE(struct RTHTTPSERVERINTERNAL *) RTHTTPSERVER;
47/** Pointer to a HTTP server handle. */
48typedef RTHTTPSERVER *PRTHTTPSERVER;
49/** Nil HTTP client handle. */
50#define NIL_RTHTTPSERVER ((RTHTTPSERVER)0)
51
52/**
53 * Structure for maintaining a HTTP client request.
54 */
55typedef struct RTHTTPSERVERREQ
56{
57 char *pszUrl;
58 RTHTTPMETHOD enmMethod;
59 RTHTTPHEADERLIST hHdrLst;
60 void *pvBody;
61 size_t cbBodyAlloc;
62 size_t cbBodyUsed;
63} RTHTTPSERVERREQ;
64/** Pointer to a HTTP client request. */
65typedef RTHTTPSERVERREQ *PRTHTTPSERVERREQ;
66
67/**
68 * Structure for maintaining a HTTP server response.
69 */
70typedef struct RTHTTPSERVERRESP
71{
72 RTHTTPSTATUS enmSts;
73 RTHTTPHEADERLIST hHdrLst;
74 void *pvBody;
75 size_t cbBodyAlloc;
76 size_t cbBodyUsed;
77} RTHTTPSERVERRESP;
78/** Pointer to a HTTP server response. */
79typedef RTHTTPSERVERRESP *PRTHTTPSERVERRESP;
80
81/**
82 * Structure for maintaining a HTTP server client state.
83 *
84 * Note: The HTTP protocol itself is stateless, but we want to have to possibility to store
85 * some state stuff here nevertheless.
86 */
87typedef struct RTHTTPSERVERCLIENTSTATE
88{
89 uint32_t fUnused;
90} RTHTTPSERVERCLIENTSTATE;
91/** Pointer to a FTP server client state. */
92typedef RTHTTPSERVERCLIENTSTATE *PRTHTTPSERVERCLIENTSTATE;
93
94/**
95 * Structure for storing HTTP server callback data.
96 */
97typedef struct RTHTTPCALLBACKDATA
98{
99 /** Pointer to the client state. */
100 PRTHTTPSERVERCLIENTSTATE pClient;
101 /** Saved user pointer. */
102 void *pvUser;
103 /** Size (in bytes) of data at user pointer. */
104 size_t cbUser;
105} RTHTTPCALLBACKDATA;
106/** Pointer to HTTP server callback data. */
107typedef RTHTTPCALLBACKDATA *PRTHTTPCALLBACKDATA;
108
109/**
110 * Function callback table for the HTTP server implementation.
111 *
112 * All callbacks are optional and therefore can be NULL.
113 */
114typedef struct RTHTTPSERVERCALLBACKS
115{
116 DECLCALLBACKMEMBER(int, pfnOpen,(PRTHTTPCALLBACKDATA pData, const char *pszUrl, uint64_t *pidObj));
117 DECLCALLBACKMEMBER(int, pfnRead,(PRTHTTPCALLBACKDATA pData, uint64_t idObj, void *pvBuf, size_t cbBuf, size_t *pcbRead));
118 DECLCALLBACKMEMBER(int, pfnClose,(PRTHTTPCALLBACKDATA pData, uint64_t idObj));
119 DECLCALLBACKMEMBER(int, pfnQueryInfo,(PRTHTTPCALLBACKDATA pData, const char *pszUrl, PRTFSOBJINFO pObjInfo));
120 DECLCALLBACKMEMBER(int, pfnOnGetRequest,(PRTHTTPCALLBACKDATA pData, PRTHTTPSERVERREQ pReq));
121 DECLCALLBACKMEMBER(int, pfnOnHeadRequest,(PRTHTTPCALLBACKDATA pData, PRTHTTPSERVERREQ pReq));
122} RTHTTPSERVERCALLBACKS;
123/** Pointer to a HTTP server callback data table. */
124typedef RTHTTPSERVERCALLBACKS *PRTHTTPSERVERCALLBACKS;
125
126/** Maximum length (in bytes) a client request can have. */
127#define RTHTTPSERVER_MAX_REQ_LEN _8K
128
129/**
130 * Creates a HTTP server instance.
131 *
132 * @returns IPRT status code.
133 * @param phHttpServer Where to store the HTTP server handle.
134 * @param pcszAddress The address for creating a listening socket.
135 * If NULL or empty string the server is bound to all interfaces.
136 * @param uPort The port for creating a listening socket.
137 * @param pCallbacks Callback table to use.
138 * @param pvUser Pointer to user-specific data. Optional.
139 * @param cbUser Size of user-specific data. Optional.
140 */
141RTR3DECL(int) RTHttpServerCreate(PRTHTTPSERVER phHttpServer, const char *pcszAddress, uint16_t uPort,
142 PRTHTTPSERVERCALLBACKS pCallbacks, void *pvUser, size_t cbUser);
143
144/**
145 * Destroys a HTTP server instance.
146 *
147 * @returns IPRT status code.
148 * @param hHttpServer Handle to the HTTP server handle.
149 */
150RTR3DECL(int) RTHttpServerDestroy(RTHTTPSERVER hHttpServer);
151
152/** @} */
153RT_C_DECLS_END
154
155#endif /* !IPRT_INCLUDED_http_server_h */
156
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette