1 | /** @file
|
---|
2 | * IPRT - C++ Representational State Transfer (REST) Base Classes.
|
---|
3 | */
|
---|
4 |
|
---|
5 | /*
|
---|
6 | * Copyright (C) 2008-2018 Oracle Corporation
|
---|
7 | *
|
---|
8 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
9 | * available from http://www.virtualbox.org. This file is free software;
|
---|
10 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
11 | * General Public License (GPL) as published by the Free Software
|
---|
12 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
13 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
14 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
15 | *
|
---|
16 | * The contents of this file may alternatively be used under the terms
|
---|
17 | * of the Common Development and Distribution License Version 1.0
|
---|
18 | * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
19 | * VirtualBox OSE distribution, in which case the provisions of the
|
---|
20 | * CDDL are applicable instead of those of the GPL.
|
---|
21 | *
|
---|
22 | * You may elect to license modified versions of this file under the
|
---|
23 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
24 | */
|
---|
25 |
|
---|
26 | #ifndef ___iprt_cpp_restbase_h
|
---|
27 | #define ___iprt_cpp_restbase_h
|
---|
28 |
|
---|
29 | #include <iprt/types.h>
|
---|
30 | #include <iprt/err.h>
|
---|
31 | #include <iprt/http.h>
|
---|
32 | #include <iprt/cpp/utils.h>
|
---|
33 |
|
---|
34 |
|
---|
35 | /** @defgroup grp_rt_cpp_restbase C++ Representational State Transfer (REST) Base Classes.
|
---|
36 | * @ingroup grp_rt_cpp
|
---|
37 | * @{
|
---|
38 | */
|
---|
39 |
|
---|
40 |
|
---|
41 | /**
|
---|
42 | * Base class for REST data objects.
|
---|
43 | */
|
---|
44 | class RTCSRestObjectBase
|
---|
45 | {
|
---|
46 | public:
|
---|
47 | RTCSRestObjectBase() {}
|
---|
48 | virtual ~RTCSRestObjectBase() {}
|
---|
49 | /** @todo Add some kind of state? */
|
---|
50 | };
|
---|
51 |
|
---|
52 |
|
---|
53 | /**
|
---|
54 | * Base class for REST client requests.
|
---|
55 | */
|
---|
56 | class RTCRestClientRequestBase
|
---|
57 | {
|
---|
58 | public:
|
---|
59 | RTCRestClientRequestBase() {}
|
---|
60 | virtual ~RTCRestClientRequestBase() {};
|
---|
61 |
|
---|
62 | /**
|
---|
63 | * Prepares the HTTP handle for transmitting this request.
|
---|
64 | *
|
---|
65 | * @returns IPRT status code.
|
---|
66 | * @param a_hHttp The HTTP handle to prepare for transmitting.
|
---|
67 | */
|
---|
68 | virtual int xmitPrepare(RTHTTP a_hHttp);
|
---|
69 |
|
---|
70 | /**
|
---|
71 | * Always called after the request has been transmitted.
|
---|
72 | *
|
---|
73 | * @param a_rcStatus Negative numbers are IPRT errors, positive are HTTP status codes.
|
---|
74 | * @param a_hHttp The HTTP handle the request was performed on.
|
---|
75 | */
|
---|
76 | virtual void xmitComplete(int a_rcStatus, RTHTTP a_hHttp);
|
---|
77 | };
|
---|
78 |
|
---|
79 |
|
---|
80 | /**
|
---|
81 | * Base class for REST client responses.
|
---|
82 | */
|
---|
83 | class RTCRestClientResponseBase
|
---|
84 | {
|
---|
85 | public:
|
---|
86 | RTCRestClientResponseBase()
|
---|
87 | : m_rcStatus(VERR_WRONG_ORDER)
|
---|
88 | {}
|
---|
89 | RTCRestClientResponseBase(RTCRestClientResponseBase const &a_rThat)
|
---|
90 | : m_rcStatus(a_rThat.m_rcStatus)
|
---|
91 | {}
|
---|
92 | virtual ~RTCRestClientResponseBase();
|
---|
93 |
|
---|
94 | /**
|
---|
95 | * Prepares the HTTP handle for receiving the response.
|
---|
96 | *
|
---|
97 | * This may install callbacks and such like.
|
---|
98 | *
|
---|
99 | * @returns IPRT status code.
|
---|
100 | * @param a_hHttp The HTTP handle to prepare for receiving.
|
---|
101 | */
|
---|
102 | virtual int receivePrepare(RTHTTP a_hHttp);
|
---|
103 |
|
---|
104 | virtual int consumeHeader(const char *a_pvData, size_t a_cbData); ///< ??
|
---|
105 | virtual int consumeBody(const char *a_pvData, size_t a_cbData); ///< ??
|
---|
106 |
|
---|
107 | /**
|
---|
108 | * Called when the HTTP request has been completely received.
|
---|
109 | *
|
---|
110 | * @returns IPRT status code?
|
---|
111 | * @param a_rcStatus Negative numbers are IPRT errors, positive are HTTP status codes.
|
---|
112 | * @param a_hHttp The HTTP handle the request was performed on.
|
---|
113 | */
|
---|
114 | virtual int receiveComplete(int a_rcStatus, RTHTTP a_hHttp);
|
---|
115 |
|
---|
116 | /**
|
---|
117 | * Getter for m_rcStatus.
|
---|
118 | * @returns Negative numbers are IPRT errors, positive are HTTP status codes.
|
---|
119 | */
|
---|
120 | int getStatus() { return m_rcStatus; }
|
---|
121 |
|
---|
122 | private:
|
---|
123 | /** Negative numbers are IPRT errors, positive are HTTP status codes. */
|
---|
124 | int m_rcStatus;
|
---|
125 |
|
---|
126 | };
|
---|
127 |
|
---|
128 |
|
---|
129 | /**
|
---|
130 | * Base class for REST client responses.
|
---|
131 | */
|
---|
132 | class RTCRestClientApiBase : public RTCNonCopyable
|
---|
133 | {
|
---|
134 | public:
|
---|
135 | RTCRestClientApiBase()
|
---|
136 | : m_hHttp(NIL_RTHTTP)
|
---|
137 | {}
|
---|
138 | virtual ~RTCRestClientApiBase();
|
---|
139 |
|
---|
140 | bool isConnected();
|
---|
141 |
|
---|
142 | protected:
|
---|
143 | /** Handle to the HTTP connection object. */
|
---|
144 | RTHTTP m_hHttp;
|
---|
145 | };
|
---|
146 |
|
---|
147 |
|
---|
148 | #endif
|
---|
149 |
|
---|