/* File : urlparse.h - Dillo
 *
 * Copyleft (C) 2001 Livio Baldini Soares <livio@linux.ime.usp.br>
 *              2001 Jorge Arrelano Cid   <jcid@user.sourceforge.net>
 *
 * Parse and normalize all URL's inside Dillo.
 * 
 */

#ifndef __DILLO_URLPARSE_H__
#define __DILLO_URLPARSE_H__


#define DILLO_URL_HTTP_PROTOCOL    "HTTP"
#define DILLO_URL_ABOUT_PROTOCOL   "ABOUT"
#define DILLO_URL_FILE_PROTOCOL    "FILE"

#define DILLO_URL_HTTP_PORT        80
#define DILLO_URL_FTP_PORT         21

#define URN_OTHER  "()+,-.:=@;$_!*'/%?"

/* Values for DilloUrl->flags.
   Specifies which which action whould be done in the IO system
   when this URL needs to be used.
 */
#define URL_Get                 0x00000001
#define URL_Post                0x00000002
#define URL_ISindex             0x00000004
#define URL_RealmAccess         0x00000008

#define URL_P2PReload           0x00000010
#define URL_ReloadImages        0x00000020
#define URL_ReloadPage          0x00000040
#define URL_ReloadFromCache     0x00000080

#define URL_ReloadIncomplete    0x00000100



/* Access methods to access fields inside DilloURL */

#define URL_ORIG(u)     u->original_url /* should we make this public??? */
#define URL_PROTO(u)    u->protocol
#define URL_HOST(u)     u->hostname
#define URL_PATH(u)     u->path
#define URL_PORT(u)     u->port
#define URL_FLAGS(u)    u->flags
#define URL_DATA(u)     u->data
#define URL_POS(u)      u->scrolling_position


typedef struct _DilloURL DilloURL;

#ifdef __cplusplus
/* extern "C" { */
#endif /* __cplusplus */

struct _DilloURL {
   const gchar *original_url;

   const gchar *protocol;
   const gchar *hostname;
   const gchar *path;
   /* const gchar *anchor; <-- should we leave this out of `path' field to avoid
                               parse on `path' to decide if it has anchors ???*/
   const gint port;
   const gint flags;
   const gchar *data;              /* POST */
   const gint scrolling_position;  /* remeber position for history stack */
};

/* Wouldn't it be better to call this a_Url_new() ??? */
DilloURL* a_Url_make(gchar *url_str, gchar *base_url,
		     gint flags, gint pos);
/*
  [1] Resolves *url_str (which can be relative) to an absolute URL.
  [2] Squeeze `path' field
*/

void a_Url_free(DilloURL *u);

DilloURL* a_Url_dup(const DilloURL *u);


/* 
   Will Dillo change diferent protocols/ports if none is specified??
   Or once the protocol/port is set (to a default?) it doesn't change?
   If so, these next 2 functions should be removed...
*/
void a_Url_set_protocol(DilloUrl *u, gint port);
void a_Url_set_port(DilloUrl *u, gint port);

void a_Url_set_flags(DilloUrl *u, gint flags);
/* You suggested to do a:
   [1[ (gint) u->flags = flags;
   But isn't it better to do a:
   [2] (gint) u->glags |= flags;
   ??
   Or are all the flags mutually excludent??
*/


void a_Url_set_data(DilloUrl *u, gchar *data);
/*
  Should we do:
  [1] (gchar) u->data = data;
  OR
  [2] (gchar) u->data = (data) ? g_strdup(data) : NULL;
??? I would choose the second.
*/

void a_Url_set_pos(DilloUrl *u, gint pos);


/* 
   These are not needed anymore, right?
   (gchar *a_Url_to_string(const DilloURL *url);) == (a_Url_make)
   (DilloURL *a_string_to_Url(const gchar *urlstring);) == (URL_ORIG)
*/

/* Compares two different URL's to see if they are the same.
   Which fields should be compare to decide if the URL's are equal?
   COMPARE:
     protocol, hostname, path, port, data
   NOT COMPARE:
     original_url, flags, scrolling_position

   OR... we *only* compare `original_url' ????
 */
gint a_Url_cmp(const DilloURL* A, const DilloURL *B);

/* Stolen from IO/Url.[ch] */

/* Will these be needed in Dillo???
   It seems that these functions we be used only inside urlparse.c,
   therefore, they can be "static", right?

   Am I forgetting something?

   gint  a_Url_is_absolute (const gchar *url);
   char* a_Url_parse_hash  (const DilloURL *url);
   DilloURL* a_Url_squeeze(gchar *str);
   DilloURL* a_Url_resolve_relative(const DilloURL *baseurl, const gchar *RelativeUrl);
   char* a_Url_parse(const DilloURL *url, char *hostname, gint *port);
*/

#ifdef __cplusplus
     /* } */
#endif /* __cplusplus */

#endif /* __DILLO_URLPARSE_H__ */

