/*
 * $Log: url,v $
 * Revision 1.14  1998/12/05 15:44:36  joseph
 * url_present was not used externally, so it made static
 *
 * Revision 1.13  1998/09/28 15:56:24  joseph
 * Changed to delay loading of mimemap module to the start of a fetch
 *
 * Revision 1.12  1998/09/02 19:21:24  joseph
 * Replaced internal mimemap stuff with calls to MimeMap module
 *
 * Revision 1.11  1998/08/30 18:31:51  joseph
 * Fetching of inline images may be specified more precisely
 *
 * Revision 1.10  1998/08/30 13:10:00  joseph
 * Fetching ordered is now more defined - pages closer to the root, and
 * actual pages (as opposed to inlines) at the same line level are favoured.
 *
 * Revision 1.9  1998/08/11 20:35:51  joseph
 * Added url_clear() to clear URLs from all the lists at the end of a fetch
 *
 * Revision 1.8  1998/08/09 15:07:02  joseph
 * Added include/exclude lists for URLs
 *
 * Revision 1.7  1998/06/16 18:29:40  joseph
 * Added recalculation of fetch portion for base href & redirections
 * Added processing of base href in fetch and rewrite
 * Moved file_truncate from rewrite to file
 * Logging of urls with unknown schemes
 * Errorlog file kept open across whole fetch
 * Log routines may handle effects of *close better.
 * Invalid chars in urls and hostnames replaced with ~'s on filesystem
 * Rewrite recovers from zero length log file
 * Removed permfail, softfail states as not used
 * Removed some unused bits from url structures
 * Changed proxy code to handle dotless hostnames okay.
 * Version to 0.06a.
 *
 * Revision 1.6  1998/06/06 21:45:02  joseph
 * Added ability to not fetch frames / inline images in fetch / config
 * wimpc_menuread moved to wimpclib
 * Now fades individual fetches when started, unfades all at end of fetch
 *
 * Revision 1.5  1998/06/05 22:55:27  joseph
 * URLs now moved to 'FETCHED' once they are fetched
 * Front end made proper
 * Added multiple fetch files + a menu in frontend
 * Fixed bugs with links containing url with spaces before them
 * Combined both makefilenames into one in misc.c
 * Added readtag and openfetch to http.
 * Keep FetchLog open for duration of fetch
 * Logfile now contains links to the orignal pages too
 * Added url_handled, returns true if the url is one we know how to fetch
 * Added shift to fetch without rewriting, and adjust to dump all flex
 * lists to files. (#define URLDUMP)
 * Frontend animation now updates every 0.5 secs, and has new rewrite icon
 * Added stopping / aborting of fetch / rewrite
 *
 * Revision 1.4  1998/04/05 11:37:22  jogu
 * Changed sense of linkdepth
 *
 * Revision 1.3  1998/03/25 17:59:30  jogu
 * Added fetchportion, made linkdepth a 16 bit quantity
 *
 * Revision 1.2  1998/03/21 20:29:13  jogu
 * Added link depth to url_addto
 *
 * Revision 1.1.1.1  1997/12/29 14:37:55  jogu
 * WebGet Initial CMS Ver
 *
 */

#ifndef URL_H
#define URL_H

#include "eval.h"

typedef enum URL_LISTS_ENUM { FOUND, PENDING, FETCHED, /*MIMETYPES,*/ SIZEOF_LISTS_ENUM } URL_LISTS;

typedef struct url_str
{
/*  unsigned int     next_off;*/     /* offset from here to next url (0=none) */
/*  unsigned int     content; not used ? */	 /* offset into content-type list (0=not known) */
/*  unsigned int 	   size; not used? */	 /* size in bytes of this url. (0=not known) */
  unsigned int	   fetching:1; 	 /* true if fetching */
//  unsigned int	   header:1; 	 /* true if we have the header */
//  unsigned int     selected:1; 	 /* true if user has selected this url */
  unsigned int	   proxy:3;	 /* proxy to use. 0=unknown, 1=none,  2,3...7 = proxy[0-5] */
/*  unsigned int	   mimetype:8;	*/ /* as in mimetype_str. 0 = none/unknown */
  unsigned int     noinlineimages:1; /* fetch inline images? */
  unsigned int     inlineframes:1; /* fetch inline frames? */
  unsigned int	   linkdepthtogo:16; /* most possible remaining links that we've found this url at 0-65,000 */
  unsigned int	   act_linkdepth:16; /* lowest depth of this url, 0-65,000 */
  unsigned int     fetchportion:16; /* how many characters of this url any links found must
                                       match in order to get fetched */
  unsigned int     imagefetchportion:16; /* how many characters of this url any links found must
                                       match in order to get fetched */
  int              filetype;
//  int	   	   state;	 /* eg. resolve, connect, send, header, body. colour in list */
/*  char     	   url[1];*/	 /* the url, as long as is needed */
/* waste any padding. for simplicity. */
  int              ruleset; /* reference number for the ruleset this url uses */
  eval_inline      inline;       /* inline type - not / image / frame / metarefresh */
} url_t;

/*typedef struct fileset_str
{
  int uses;
  char fname[11];
} fileset_t; */

#if 0
typedef struct mimetype_str
{
  unsigned int	    ref:8;	      /* unique identifier for this type */
  unsigned int      filetype:12;      /* RiscOS filetype for this content type */
  unsigned int      fetch:1;          /* whether or not this content type should be fetched */
} mimetype_t;
#endif

#ifdef URL_INTERNALS
static char *lists[SIZEOF_LISTS_ENUM];

static const size_t url_strsize[SIZEOF_LISTS_ENUM] = {
  sizeof(struct url_str),
  sizeof(struct url_str),
  0,
/*  sizeof(struct mimetype_str) */
  };
#endif





int url_init(void);
void url_clear( void );
int url_handled( const char */*url*/ );

int url_addto( URL_LISTS where, char *url, int linkdepth, int fetchportion,
               int noinlineimages, int inlineframes, int ruleset, eval_inline inline, int act_linkdepth,
               int imagefetchportion );

int url_remove(URL_LISTS where, const char *url);
int url_promote(URL_LISTS where, const char *url);
void url_dump(URL_LISTS where, const char *file);
url_t *url_getnext(URL_LISTS where);
url_t *url_getinfo(URL_LISTS where, const char *url);

#if 0
int mimetype_load(const char *file);
mimetype_t *mimetype_lookup(char *type);
mimetype_t *mimetype_lookupbyref(int ref);
#endif

int mimetype_init( void );
int mimetype_getfiletype( const char *mimetype );


#endif
