VirtualBox

source: vbox/trunk/src/VBox/Runtime/common/rest/RTCRestClientRequestBase.cpp@ 73958

Last change on this file since 73958 was 73918, checked in by vboxsync, 6 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: 3.1 KB
Line 
1/* $Id: RTCRestClientRequestBase.cpp 73918 2018-08-27 15:08:55Z vboxsync $ */
2/** @file
3 * IPRT - C++ REST, RTCRestClientRequestBase 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/assert.h>
34#include <iprt/err.h>
35
36
37/**
38 * Default constructor.
39 * */
40RTCRestClientRequestBase::RTCRestClientRequestBase()
41{
42 /* nothing to do */
43}
44
45
46/**
47 * Destructor
48 */
49RTCRestClientRequestBase::~RTCRestClientRequestBase()
50{
51 /* nothing to do */
52}
53
54
55int RTCRestClientRequestBase::doPathParameters(RTCString *a_pStrPath, const char *a_pszPathTemplate, size_t a_cchPathTemplate,
56 PATHREPLACEENTRY *a_paPathParams, size_t a_cPathParams) const
57{
58 int rc = a_pStrPath->assignNoThrow(a_pszPathTemplate, a_cchPathTemplate);
59 AssertRCReturn(rc, rc);
60
61 /* Locate the sub-string to replace with values first: */
62 for (size_t i = 0; i < a_cPathParams; i++)
63 {
64 char const *psz = strstr(a_pszPathTemplate, a_paPathParams[i].pszName);
65 AssertReturn(psz, VERR_INTERNAL_ERROR_5);
66 a_paPathParams[i].offName = psz - a_pszPathTemplate;
67 }
68
69 /* Replace with actual values: */
70 RTCString strTmpVal;
71 for (size_t i = 0; i < a_cPathParams; i++)
72 {
73 rc = a_paPathParams[i].pObj->toString(&strTmpVal, a_paPathParams[i].fFlags);
74 AssertRCReturn(rc, rc);
75
76 /* Replace. */
77 ssize_t cchAdjust = strTmpVal.length() - a_paPathParams[i].cchName;
78 rc = a_pStrPath->replaceNoThrow(a_paPathParams[i].offName, a_paPathParams[i].cchName, strTmpVal);
79 AssertRCReturn(rc, rc);
80
81 /* Adjust subsequent fields. */
82 if (cchAdjust != 0)
83 for (size_t j = i + 1; j < a_cPathParams; j++)
84 if (a_paPathParams[j].offName > a_paPathParams[i].offName)
85 a_paPathParams[j].offName += cchAdjust;
86 }
87
88 return VINF_SUCCESS;
89}
90
Note: See TracBrowser for help on using the repository browser.

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