/**********************************************************************
 
	Copyright (C) 2003 Hirohisa MORI <joshua@nichibun.ac.jp>
 
	This program is free software; you can redistribute it 
	and/or modify it under the terms of the GLOBALBASE 
	Library General Public License (G-LGPL) as published by 

	http://www.globalbase.org/
 
	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.

**********************************************************************/



#include	<stdlib.h>
#include	"memory_debug.h"
#include	"utils.h"

L_CHAR * seek_ptr();

L_CHAR *
get_url_filepath(URL * u)
{
L_CHAR * buf;
L_CHAR * ptr;
char port_buf[20];
	buf = d_alloc(
		((u->db ? l_strlen(u->db) : 0) +
		 (u->resource ? l_strlen(u->resource) : 0) + 100) *
			sizeof(L_CHAR));
	buf[0] = 0;
	ptr = buf;
db:
	if ( u->db == 0 ) {
		*ptr ++ = '/';
	}
	else {
		if ( u->db[0] != '/' )
			*ptr ++ = '/';
		l_strcpy(ptr,u->db);
		ptr = seek_ptr(ptr);
	}
	if ( *(ptr-1) != '/' )
		*ptr ++ = '/';
resource:
	if ( u->resource )
		l_strcpy(ptr,u->resource);
	buf = d_re_alloc(buf,(l_strlen(buf)+1)*sizeof(L_CHAR));
	return buf;
err:
	d_f_ree(buf);
	return 0;
}
