VirtualBox

source: vbox/trunk/src/VBox/Runtime/common/rest/RTCRestClientResponseBase.cpp@ 73921

Last change on this file since 73921 was 73921, checked in by vboxsync, 7 years ago

iprt/rest: More work on the API code generation. bugref:9167

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.6 KB
Line 
1/* $Id: RTCRestClientResponseBase.cpp 73921 2018-08-27 19:41:26Z vboxsync $ */
2/** @file
3 * IPRT - C++ REST, RTCRestClientResponseBase implementation.
4 */
5
6/*
7 * Copyright (C) 2018 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
28/*********************************************************************************************************************************
29* Header Files *
30*********************************************************************************************************************************/
31#include <iprt/cpp/restbase.h>
32
33#include <iprt/ctype.h>
34#include <iprt/err.h>
35
36
37/**
38 * Default constructor.
39 */
40RTCRestClientResponseBase::RTCRestClientResponseBase()
41 : m_rcStatus(VERR_WRONG_ORDER)
42{
43}
44
45
46/**
47 * Destructor.
48 */
49RTCRestClientResponseBase::~RTCRestClientResponseBase()
50{
51 /* nothing to do here */
52}
53
54
55/**
56 * Copy constructor.
57 */
58RTCRestClientResponseBase::RTCRestClientResponseBase(RTCRestClientResponseBase const &a_rThat)
59 : m_rcStatus(a_rThat.m_rcStatus)
60{
61}
62
63
64/**
65 * Copy assignment operator.
66 */
67RTCRestClientResponseBase &RTCRestClientResponseBase::operator=(RTCRestClientResponseBase const &a_rThat)
68{
69 m_rcStatus = a_rThat.m_rcStatus;
70 return *this;
71}
72
73
74int RTCRestClientResponseBase::receivePrepare(RTHTTP a_hHttp, void ***a_pppvHdr, void ***a_pppvBody)
75{
76 RT_NOREF(a_hHttp, a_pppvHdr, a_pppvBody);
77 return VINF_SUCCESS;
78}
79
80
81void RTCRestClientResponseBase::receiveComplete(int a_rcStatus, RTHTTP a_hHttp)
82{
83 RT_NOREF_PV(a_hHttp);
84 m_rcStatus = a_rcStatus;
85}
86
87
88void RTCRestClientResponseBase::consumeHeaders(const char *a_pchData, size_t a_cbData)
89{
90 RT_NOREF(a_pchData, a_cbData);
91}
92
93
94void RTCRestClientResponseBase::consumeBody(const char *a_pchData, size_t a_cbData)
95{
96 RT_NOREF(a_pchData, a_cbData);
97}
98
99
100void RTCRestClientResponseBase::receiveFinal()
101{
102}
103
104
105int RTCRestClientResponseBase::extractHeaderFromBlob(const char *a_pszField, size_t a_cchField,
106 const char *a_pchData, size_t a_cbData,
107 RTCString *a_pStrDst)
108{
109 char const chUpper0 = RT_C_TO_UPPER(a_pszField[0]);
110 char const chLower0 = RT_C_TO_LOWER(a_pszField[0]);
111 Assert(!RT_C_IS_SPACE(chUpper0));
112
113 while (a_cbData > a_cchField)
114 {
115 /* Determine length of the header name:value combo.
116 Note! Multi-line field values are not currently supported. */
117 const char *pchEol = (const char *)memchr(a_pchData, '\n', a_cbData);
118 while (pchEol && (pchEol == a_pchData || pchEol[-1] != '\r'))
119 pchEol = (const char *)memchr(pchEol, '\n', a_cbData - (pchEol - a_pchData));
120
121 size_t cchField = pchEol ? pchEol - a_pchData + 1 : a_cbData;
122
123 /* Try match */
124 if ( a_pchData[a_cchField] == ':'
125 && ( a_pchData[0] == chUpper0
126 || a_pchData[0] == chLower0)
127 && RTStrNICmpAscii(a_pchData, a_pszField, a_cchField) == 0)
128 {
129 /* Drop CRLF. */
130 if (pchEol)
131 cchField -= 2;
132
133 /* Drop the field name and optional whitespace. */
134 cchField -= a_cchField + 1;
135 a_pchData += a_cchField + 1;
136 if (cchField > 0 && RT_C_IS_BLANK(*a_pchData))
137 {
138 a_pchData++;
139 cchField--;
140 }
141
142 /* Return the value. */
143 int rc = a_pStrDst->assignNoThrow(a_pchData, cchField);
144 if (RT_SUCCESS(rc))
145 RTStrPurgeEncoding(a_pStrDst->mutableRaw());
146 return rc;
147 }
148
149 /* Advance to the next field. */
150 a_pchData += cchField;
151 a_cbData -= cchField;
152 }
153
154 return VERR_NOT_FOUND;
155}
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