Blame src/libostree/ostree-fetcher-uri.c

rpm-build 0fba15
/*
rpm-build 0fba15
 * Copyright (C) 2011,2017 Colin Walters <walters@verbum.org>
rpm-build 0fba15
 *
rpm-build 0fba15
 * SPDX-License-Identifier: LGPL-2.0+
rpm-build 0fba15
 *
rpm-build 0fba15
 * This library is free software; you can redistribute it and/or
rpm-build 0fba15
 * modify it under the terms of the GNU Lesser General Public
rpm-build 0fba15
 * License as published by the Free Software Foundation; either
rpm-build 0fba15
 * version 2 of the License, or (at your option) any later version.
rpm-build 0fba15
 *
rpm-build 0fba15
 * This library is distributed in the hope that it will be useful,
rpm-build 0fba15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
rpm-build 0fba15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
rpm-build 0fba15
 * Lesser General Public License for more details.
rpm-build 0fba15
 *
rpm-build 0fba15
 * You should have received a copy of the GNU Lesser General Public
rpm-build 0fba15
 * License along with this library; if not, write to the
rpm-build 0fba15
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
rpm-build 0fba15
 * Boston, MA 02111-1307, USA.
rpm-build 0fba15
 *
rpm-build 0fba15
 * Author: Colin Walters <walters@verbum.org>
rpm-build 0fba15
 */
rpm-build 0fba15
rpm-build 0fba15
#include "config.h"
rpm-build 0fba15
rpm-build 0fba15
rpm-build 0fba15
#ifdef HAVE_LIBCURL
rpm-build 0fba15
#include "ostree-soup-uri.h"
rpm-build 0fba15
#else
rpm-build 0fba15
#define LIBSOUP_USE_UNSTABLE_REQUEST_API
rpm-build 0fba15
#include <libsoup/soup.h>
rpm-build 0fba15
#include <libsoup/soup-requester.h>
rpm-build 0fba15
#include <libsoup/soup-request-http.h>
rpm-build 0fba15
#endif
rpm-build 0fba15
rpm-build 0fba15
#include "ostree-fetcher.h"
rpm-build 0fba15
rpm-build 0fba15
#include "libglnx.h"
rpm-build 0fba15
rpm-build 0fba15
void
rpm-build 0fba15
_ostree_fetcher_uri_free (OstreeFetcherURI *uri)
rpm-build 0fba15
{
rpm-build 0fba15
  if (uri)
rpm-build 0fba15
    soup_uri_free ((SoupURI*)uri);
rpm-build 0fba15
}
rpm-build 0fba15
rpm-build 0fba15
OstreeFetcherURI *
rpm-build 0fba15
_ostree_fetcher_uri_parse (const char       *str,
rpm-build 0fba15
                           GError          **error)
rpm-build 0fba15
{
rpm-build 0fba15
  SoupURI *soupuri = soup_uri_new (str);
rpm-build 0fba15
  if (soupuri == NULL)
rpm-build 0fba15
    {
rpm-build 0fba15
      g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
rpm-build 0fba15
                   "Failed to parse uri: %s", str);
rpm-build 0fba15
      return NULL;
rpm-build 0fba15
    }
rpm-build 0fba15
  return (OstreeFetcherURI*)soupuri;
rpm-build 0fba15
}
rpm-build 0fba15
rpm-build 0fba15
static OstreeFetcherURI *
rpm-build 0fba15
_ostree_fetcher_uri_new_path_internal (OstreeFetcherURI *uri,
rpm-build 0fba15
                                       gboolean          extend,
rpm-build 0fba15
                                       const char       *path)
rpm-build 0fba15
{
rpm-build 0fba15
  SoupURI *newuri = soup_uri_copy ((SoupURI*)uri);
rpm-build 0fba15
  if (path)
rpm-build 0fba15
    {
rpm-build 0fba15
      if (extend)
rpm-build 0fba15
        {
rpm-build 0fba15
          const char *origpath = soup_uri_get_path ((SoupURI*)uri);
rpm-build 0fba15
          g_autofree char *newpath = g_build_filename (origpath, path, NULL);
rpm-build 0fba15
          soup_uri_set_path (newuri, newpath);
rpm-build 0fba15
        }
rpm-build 0fba15
      else
rpm-build 0fba15
        {
rpm-build 0fba15
          soup_uri_set_path (newuri, path);
rpm-build 0fba15
        }
rpm-build 0fba15
    }
rpm-build 0fba15
  return (OstreeFetcherURI*)newuri;
rpm-build 0fba15
}
rpm-build 0fba15
rpm-build 0fba15
OstreeFetcherURI *
rpm-build 0fba15
_ostree_fetcher_uri_new_path (OstreeFetcherURI *uri,
rpm-build 0fba15
                              const char       *path)
rpm-build 0fba15
{
rpm-build 0fba15
  return _ostree_fetcher_uri_new_path_internal (uri, FALSE, path);
rpm-build 0fba15
}
rpm-build 0fba15
rpm-build 0fba15
OstreeFetcherURI *
rpm-build 0fba15
_ostree_fetcher_uri_new_subpath (OstreeFetcherURI *uri,
rpm-build 0fba15
                                 const char       *subpath)
rpm-build 0fba15
{
rpm-build 0fba15
  return _ostree_fetcher_uri_new_path_internal (uri, TRUE, subpath);
rpm-build 0fba15
}
rpm-build 0fba15
rpm-build 0fba15
OstreeFetcherURI *
rpm-build 0fba15
_ostree_fetcher_uri_clone (OstreeFetcherURI *uri)
rpm-build 0fba15
{
rpm-build 0fba15
  return _ostree_fetcher_uri_new_subpath (uri, NULL);
rpm-build 0fba15
}
rpm-build 0fba15
rpm-build 0fba15
char *
rpm-build 0fba15
_ostree_fetcher_uri_get_scheme (OstreeFetcherURI *uri)
rpm-build 0fba15
{
rpm-build 0fba15
  return g_strdup (soup_uri_get_scheme ((SoupURI*)uri));
rpm-build 0fba15
}
rpm-build 0fba15
rpm-build 0fba15
char *
rpm-build 0fba15
_ostree_fetcher_uri_get_path (OstreeFetcherURI *uri)
rpm-build 0fba15
{
rpm-build 0fba15
  return g_strdup (soup_uri_get_path ((SoupURI*)uri));
rpm-build 0fba15
}
rpm-build 0fba15
rpm-build 0fba15
char *
rpm-build 0fba15
_ostree_fetcher_uri_to_string (OstreeFetcherURI *uri)
rpm-build 0fba15
{
rpm-build 0fba15
  return soup_uri_to_string ((SoupURI*)uri, FALSE);
rpm-build 0fba15
}