VirtualBox

source: vbox/trunk/include/iprt/http-common.h@ 87037

最後變更 在這個檔案從87037是 87037,由 vboxsync 提交於 4 年 前

Shared Clipboard/Transfers: Renaming (RTHTTP_WITH_WEBDAV -> IPRT_HTTP_WITH_WEBDAV). bugref:9874

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 9.9 KB
 
1/* $Id: http-common.h 87037 2020-12-03 16:14:04Z vboxsync $ */
2/** @file
3 * IPRT - Common (client / server) HTTP API.
4 */
5
6/*
7 * Copyright (C) 2012-2020 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.alldomusa.eu.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_common_h
28#define IPRT_INCLUDED_http_common_h
29#ifndef RT_WITHOUT_PRAGMA_ONCE
30# pragma once
31#endif
32
33#include <iprt/list.h>
34#include <iprt/types.h>
35
36RT_C_DECLS_BEGIN
37
38/** HTTP methods. */
39typedef enum RTHTTPMETHOD
40{
41 RTHTTPMETHOD_INVALID = 0,
42 RTHTTPMETHOD_GET,
43 RTHTTPMETHOD_PUT,
44 RTHTTPMETHOD_POST,
45 RTHTTPMETHOD_PATCH,
46 RTHTTPMETHOD_DELETE,
47 RTHTTPMETHOD_HEAD,
48 RTHTTPMETHOD_OPTIONS,
49 RTHTTPMETHOD_TRACE,
50#ifdef IPRT_HTTP_WITH_WEBDAV
51 RTHTTPMETHOD_PROPFIND,
52#endif
53 RTHTTPMETHOD_END,
54 RTHTTPMETHOD_32BIT_HACK = 0x7fffffff
55} RTHTTPMETHOD;
56
57/** HTTP status codes. */
58typedef enum RTHTTPSTATUS
59{
60 RTHTTPSTATUS_INTERNAL_NOT_SET = 0,
61 /**
62 * 2xx - Success / information codes.
63 */
64 RTHTTPSTATUS_OK = 200,
65 RTHTTPSTATUS_CREATED = 201,
66 RTHTTPSTATUS_ACCEPTED = 202,
67 RTHTTPSTATUS_NONAUTHORITATIVEINFORMATION = 203,
68 RTHTTPSTATUS_NOCONTENT = 204,
69 RTHTTPSTATUS_RESETCONTENT = 205,
70 RTHTTPSTATUS_PARTIALCONTENT = 206,
71 RTHTTPSTATUS_MULTISTATUS = 207,
72 RTHTTPSTATUS_ALREADYREPORTED = 208,
73 RTHTTPSTATUS_IMUSED = 226,
74 /**
75 * 4xx - Client error codes.
76 */
77 RTHTTPSTATUS_BADREQUEST = 400,
78 RTHTTPSTATUS_UNAUTHORIZED = 401,
79 RTHTTPSTATUS_PAYMENTREQUIRED = 402,
80 RTHTTPSTATUS_FORBIDDEN = 403,
81 RTHTTPSTATUS_NOTFOUND = 404,
82 RTHTTPSTATUS_METHODNOTALLOWED = 405,
83 RTHTTPSTATUS_NOTACCEPTABLE = 406,
84 RTHTTPSTATUS_PROXYAUTHENTICATIONREQUIRED = 407,
85 RTHTTPSTATUS_REQUESTTIMEOUT = 408,
86 RTHTTPSTATUS_CONFLICT = 409,
87 RTHTTPSTATUS_GONE = 410,
88 RTHTTPSTATUS_LENGTHREQUIRED = 411,
89 RTHTTPSTATUS_PRECONDITIONFAILED = 412,
90 RTHTTPSTATUS_PAYLOADTOOLARGE = 413,
91 RTHTTPSTATUS_URITOOLONG = 414,
92 RTHTTPSTATUS_UNSUPPORTEDMEDIATYPE = 415,
93 RTHTTPSTATUS_RANGENOTSATISFIABLE = 416,
94 RTHTTPSTATUS_EXPECTATIONFAILED = 417,
95 RTHTTPSTATUS_IMATEAPOT = 418,
96 RTHTTPSTATUS_UNPROCESSABLEENTITY = 422,
97 RTHTTPSTATUS_LOCKED = 423,
98 RTHTTPSTATUS_FAILEDDEPENDENCY = 424,
99 RTHTTPSTATUS_UPGRADEREQUIRED = 426,
100 RTHTTPSTATUS_PRECONDITIONREQUIRED = 428,
101 RTHTTPSTATUS_TOOMANYREQUESTS = 429,
102 RTHTTPSTATUS_REQUESTHEADERFIELDSTOOLARGE = 431,
103 RTHTTPSTATUS_UNAVAILABLEFORLEGALREASONS = 451,
104 /**
105 * 5xx - Server error codes.
106 */
107 RTHTTPSTATUS_INTERNALSERVERERROR = 500,
108 RTHTTPSTATUS_NOTIMPLEMENTED = 501,
109 RTHTTPSTATUS_BADGATEWAY = 502,
110 RTHTTPSTATUS_SERVICEUNAVAILABLE = 503,
111 RTHTTPSTATUS_GATEWAYTIMEOUT = 504,
112 RTHTTPSTATUS_HTTPVERSIONNOTSUPPORTED = 505,
113 RTHTTPSTATUS_VARIANTALSONEGOTIATES = 506,
114 RTHTTPSTATUS_INSUFFICIENTSTORAGE = 507,
115 RTHTTPSTATUS_LOOPDETECTED = 508,
116 RTHTTPSTATUS_NOTEXTENDED = 510,
117 RTHTTPSTATUS_NETWORKAUTHENTICATIONREQUIRED = 511,
118
119 RTHTTPSTATUS_32BIT_HACK = 0x7fffffff
120} RTHTTPSTATUS;
121
122/** Checks whether a HTTP status is of type "informational" or not. */
123#define RTHTTPSTATUS_IS_INFO(a_Code) (a_Code >= 100 && a_Code < 200)
124/** Checks whether a HTTP status indicates success or not. */
125#define RTHTTPSTATUS_IS_OK(a_Code) (a_Code >= 200 && a_Code < 300)
126/** Checks whether a HTTP status indicates a redirection or not. */
127#define RTHTTPSTATUS_IS_REDIRECT(a_Code) (a_Code >= 300 && a_Code < 400)
128/** Checks whether a HTTP status indicates a client error or not. */
129#define RTHTTPSTATUS_IS_CLIENTERROR(a_Code) (a_Code >= 400 && a_Code < 500)
130/** Checks whether a HTTP status indicates a server error or not. */
131#define RTHTTPSTATUS_IS_SERVERERROR(a_Code) (a_Code >= 500 && a_Code < 600)
132/** Checks whether a HTTP status indicates an error or not. */
133#define RTHTTPSTATUS_IS_ERROR(a_Code) (a_Code >= 400)
134
135/** Specifies a HTTP MIME type. */
136typedef uint32_t RTHTTPMIMETYPE;
137
138#define RTHTTPMIMETYPE_TEXT_PLAIN "text/plain"
139#define RTHTTPMIMETYPE_APPLICATION_OCTET_STREAM "application/octet-stream"
140
141/** Specifies HTTP version 1.1 as a string. */
142#define RTHTTPVER_1_1_STR "HTTP/1.1"
143
144/** @todo the following three definitions may move the iprt/types.h later. */
145/** HTTP header list handle. */
146typedef R3PTRTYPE(struct RTHTTPHEADERLISTINTERNAL *) RTHTTPHEADERLIST;
147/** Pointer to a HTTP header list handle. */
148typedef RTHTTPHEADERLIST *PRTHTTPHEADERLIST;
149/** Nil HTTP HTTP header list handle. */
150#define NIL_RTHTTPHEADERLIST ((RTHTTPHEADERLIST)0)
151
152/**
153 * HTTP header list entry.
154 */
155typedef struct RTHTTPHEADERENTRY
156{
157 /** The list node. */
158 RTLISTNODE Node;
159 /** The field name length. */
160 uint32_t cchName;
161 /** The value offset. */
162 uint32_t offValue;
163 /** The full header field. */
164 RT_FLEXIBLE_ARRAY_EXTENSION
165 RT_GCC_EXTENSION char szData[RT_FLEXIBLE_ARRAY];
166} RTHTTPHEADERENTRY;
167/** Pointer to a HTTP header. */
168typedef RTHTTPHEADERENTRY *PRTHTTPHEADERENTRY;
169
170/**
171 * Returns the name of the HTTP method.
172 * @returns Read only string.
173 * @param enmMethod The HTTP method to name.
174 */
175RTR3DECL(const char *) RTHttpMethodToStr(RTHTTPMETHOD enmMethod);
176
177RTR3DECL(const char *) RTHttpStatusToStr(RTHTTPSTATUS enmSts);
178
179RTR3DECL(int) RTHttpHeaderListInit(PRTHTTPHEADERLIST hHdrList);
180
181RTR3DECL(void) RTHttpHeaderListDestroy(RTHTTPHEADERLIST hHdrList);
182
183/**
184 * Set custom raw headers.
185 *
186 * @returns IPRT status code.
187 * @param hHdrLst The HTTP header list handle.
188 * @param cHeaders Number of custom headers.
189 * @param papszHeaders Array of headers in form "foo: bar".
190 */
191RTR3DECL(int) RTHttpHeaderListSet(RTHTTPHEADERLIST hHdrLst, size_t cHeaders, const char * const *papszHeaders);
192
193/** @name RTHTTPHEADERLISTADD_F_XXX - Flags for RTHttpHeaderListAddRaw and RTHttpHeaderListAdd
194 * @{ */
195#define RTHTTPHEADERLISTADD_F_BACK UINT32_C(0) /**< Append the header. */
196#define RTHTTPHEADERLISTADD_F_FRONT UINT32_C(1) /**< Prepend the header. */
197/** @} */
198
199/**
200 * Adds a raw header.
201 *
202 * @returns IPRT status code.
203 * @param hHdrLst The HTTP header list handle.
204 * @param pszHeader Header string on the form "foo: bar".
205 * @param fFlags RTHTTPADDHDR_F_FRONT or RTHTTPADDHDR_F_BACK.
206 */
207RTR3DECL(int) RTHttpHeaderListAddRaw(RTHTTPHEADERLIST hHdrLst, const char *pszHeader, uint32_t fFlags);
208
209/**
210 * Adds a header field and value.
211 *
212 * @returns IPRT status code.
213 * @param hHdrLst The HTTP header list handle.
214 * @param pszField The header field name.
215 * @param pszValue The header field value.
216 * @param cchValue The value length or RTSTR_MAX.
217 * @param fFlags Only RTHTTPADDHDR_F_FRONT or RTHTTPADDHDR_F_BACK,
218 * may be extended with encoding controlling flags if
219 * needed later.
220 */
221RTR3DECL(int) RTHttpHeaderListAdd(RTHTTPHEADERLIST hHdrLst, const char *pszField, const char *pszValue, size_t cchValue, uint32_t fFlags);
222
223/**
224 * Gets a header previously added using RTHttpSetHeaders, RTHttpAppendRawHeader
225 * or RTHttpAppendHeader.
226 *
227 * @returns Pointer to the header value on if found, otherwise NULL.
228 * @param hHdrLst The HTTP header list handle.
229 * @param pszField The field name (no colon).
230 * @param cchField The length of the field name or RTSTR_MAX.
231 */
232RTR3DECL(const char *) RTHttpHeaderListGet(RTHTTPHEADERLIST hHdrLst, const char *pszField, size_t cchField);
233
234/**
235 * Gets the number of headers specified by RTHttpAddHeader, RTHttpAddRawHeader or RTHttpSetHeaders.
236 *
237 * @returns Number of headers.
238 * @param hHdrLst The HTTP header list handle.
239 * @note This can be slow and is only really intended for test cases and debugging!
240 */
241RTR3DECL(size_t) RTHttpHeaderListGetCount(RTHTTPHEADERLIST hHdrLst);
242
243/**
244 * Gets a header by ordinal.
245 *
246 * Can be used together with RTHttpGetHeaderCount by test case and debug code to
247 * iterate headers specified by RTHttpAddHeader, RTHttpAddRawHeader or RTHttpSetHeaders.
248 *
249 * @returns The header string ("field: value").
250 * @param hHdrLst The HTTP header list handle.
251 * @param iOrdinal The number of the header to get.
252 * @note This can be slow and is only really intended for test cases and debugging!
253 */
254RTR3DECL(const char *) RTHttpHeaderListGetByOrdinal(RTHTTPHEADERLIST hHdrLst, size_t iOrdinal);
255
256RT_C_DECLS_END
257
258#endif /* !IPRT_INCLUDED_http_common_h */
259
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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