VirtualBox

Changeset 74348 in vbox


Ignore:
Timestamp:
Sep 18, 2018 5:06:05 PM (7 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
125161
Message:

IPRT/rest: Trying to make the basepath stuff more flexible. However, it's not peferect yet and requires the host to be set. Sigh. bugref:9167

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/iprt/cpp/restclient.h

    r74250 r74348  
    632632{
    633633public:
    634     RTCRestClientApiBase()
    635         : m_hHttp(NIL_RTHTTP)
    636     {}
     634    RTCRestClientApiBase();
    637635    virtual ~RTCRestClientApiBase();
    638636
    639     /** @name Base path (URL) handling.
     637    /** @name Host and Base path (URL) handling.
    640638     * @{ */
    641639    /**
    642      * Gets the base path we're using.
    643      *
    644      * @returns Base URL string.  If empty, we'll be using the default one.
    645      */
    646     inline RTCString const &getBasePath(void) const
    647     {
    648         return m_strBasePath;
    649     }
     640     * Gets the default host (start of URL) as specified in the specs.
     641     *
     642     * @returns Host string (start of URL).
     643     */
     644    virtual const char *getDefaultHost() const = 0;
     645
     646    /**
     647     * Gets the host we're using.
     648     *
     649     * @returns Host URL string.
     650     */
     651    const char *getHost(void) const;
     652
     653    /**
     654     * Sets the host (URL) to use when talking to the server.
     655     *
     656     * Setting the host is only required if there is a desire to use a
     657     * different server from the one specified in the API specification, like
     658     * for instance regional one.
     659     *
     660     * @returns IPRT status code.
     661     * @param   a_pszHost   The base path to use.
     662     */
     663    virtual int setHost(const char *a_pszHost);
    650664
    651665    /**
     
    656670     * for instance regional one.
    657671     *
     672     * @returns IPRT status code.
     673     * @param   a_strHost   The base path to use.
     674     * @note    Defers to the C-string variant.
     675     */
     676    int setHost(RTCString const &a_strHost);
     677
     678
     679    /**
     680     * Gets the default base path (relative to getHost()) as specified in the specs.
     681     *
     682     * @returns Base path string.
     683     */
     684    virtual const char *getDefaultBasePath() const = 0;
     685
     686    /**
     687     * Gets the base path we're using (relative to getHost).
     688     *
     689     * @returns Base path string.
     690     */
     691    const char *getBasePath(void) const;
     692
     693    /**
     694     * Sets the base path (relative to getHost()) to use when talking to the server.
     695     *
     696     * It is assumed that the base path is at the minimum a lone slash, so an
     697     * empty (or NULL) string is understood to mean reverting to the default
     698     * (see getDefaultBasePath()).
     699     *
    658700     * @param   a_pszPath   The base path to use.
    659701     */
    660     virtual void setBasePath(const char *a_pszPath)
    661     {
    662         m_strBasePath = a_pszPath;
    663     }
    664 
    665     /**
    666      * Sets the base path (URL) to use when talking to the server.
    667      *
    668      * Setting the base path is only required if there is a desire to use a
    669      * different server from the one specified in the API specification, like
    670      * for instance regional one.
     702    virtual int setBasePath(const char *a_pszPath);
     703
     704    /**
     705     * Sets the base path (relative to getHost()) to use when talking to the server.
    671706     *
    672707     * @param   a_strPath   The base path to use.
    673708     * @note    Defers to the C-string variant.
    674709     */
    675     inline void setBasePath(RTCString const &a_strPath) { setBasePath(a_strPath.c_str()); }
    676 
    677     /**
    678      * Gets the default base path (URL) as specified in the specs.
    679      *
    680      * @returns Base path (URL) string.
    681      */
    682     virtual const char *getDefaultBasePath() = 0;
     710    int setBasePath(RTCString const &a_strPath);
     711
    683712    /** @} */
    684713
     
    692721    /** Handle to the HTTP connection object. */
    693722    RTHTTP  m_hHttp;
    694     /** The base path to use. */
     723    /** The host to use.  If empty use the default. */
     724    RTCString m_strHost;
     725    /** The base path to use.  If empty use the default. */
    695726    RTCString m_strBasePath;
    696727
  • trunk/src/VBox/Runtime/common/rest/RTCRestClientApiBase.cpp

    r74250 r74348  
    3838
    3939/**
     40 * Default constructor.
     41 */
     42RTCRestClientApiBase::RTCRestClientApiBase()
     43    : m_hHttp(NIL_RTHTTP)
     44{
     45}
     46
     47
     48/**
    4049 * The destructor.
    4150 */
     
    4857        m_hHttp = NIL_RTHTTP;
    4958    }
     59}
     60
     61
     62const char *RTCRestClientApiBase::getHost() const
     63{
     64    return m_strHost.isEmpty() ? getDefaultHost() : m_strHost.c_str();
     65}
     66
     67int RTCRestClientApiBase::setHost(const char *a_pszHost)
     68{
     69    return m_strHost.assignNoThrow(a_pszHost);
     70}
     71
     72
     73int RTCRestClientApiBase::setHost(RTCString const &a_strPath)
     74{
     75    return setHost(a_strPath.c_str());
     76}
     77
     78
     79const char *RTCRestClientApiBase::getBasePath(void) const
     80{
     81    return m_strBasePath.isEmpty() ? getDefaultBasePath() : m_strBasePath.c_str();
     82}
     83
     84
     85int RTCRestClientApiBase::setBasePath(const char *a_pszPath)
     86{
     87    return m_strBasePath.assignNoThrow(a_pszPath);
     88}
     89
     90
     91int RTCRestClientApiBase::setBasePath(RTCString const &a_strPath)
     92{
     93    return setBasePath(a_strPath.c_str());
    5094}
    5195
     
    126170                     */
    127171                    RTCString strFullUrl;
    128                     rc = strFullUrl.assignNoThrow(m_strBasePath);
     172                    rc = strFullUrl.assignNoThrow(getHost());
     173                    if (RT_SUCCESS(rc))
     174                        rc = strFullUrl.appendNoThrow(getBasePath());
    129175                    if (strExtraPath.isNotEmpty())
    130176                    {
Note: See TracChangeset for help on using the changeset viewer.

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