/* Jungle Monkey
 * Copyright (C) 1999-2001  The Regents of the University of Michigan
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#include "jmgnet.h"
#include "config.h"

#include <string.h>


#ifndef HAVE_GNET_SHA_CLONE

GSHA* 
gnet_sha_clone (const GSHA* gsha)
{
  GSHA* gshab;
  gchar shastr[2 * GNET_SHA_HASH_LENGTH + 1];

  g_return_val_if_fail (gsha, NULL);

  gnet_sha_copy_string (gsha, shastr);
  shastr[2 * GNET_SHA_HASH_LENGTH] = '\0';
  gshab = gnet_sha_new_string (shastr);

  return gshab;
}

#endif


gchar* 
gnet_url_basename (const GURL* url)
{
  gchar* base;

  g_return_val_if_fail (url, NULL);
  g_return_val_if_fail (url->resource, NULL);

  base = strrchr (url->resource, '/');
  if (base)
    return base + 1;

  return url->resource;
}


gboolean
gnet_url_is_scheme (const GURL* url, const gchar* scheme)
{
  g_return_val_if_fail (url, FALSE);

  if (!url->protocol && !scheme)
    return TRUE;
  else if (url->protocol && scheme)
    return strcmp(url->protocol, scheme) == 0;

  return FALSE;
}


syntax highlighted by Code2HTML, v. 0.9.1