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

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