Diff for /Amaya/amaya/query.c between versions 1.264 and 1.265

version 1.264, 2000/12/20 15:14:15 version 1.265, 2001/02/12 10:10:03
Line 1 Line 1
 /*  /*
  *   *
  *  (c) COPYRIGHT MIT and INRIA, 1996.   *  (c) COPYRIGHT MIT and INRIA, 1996-2001.
  *  Please first read the full copyright statement in file COPYRIGHT.   *  Please first read the full copyright statement in file COPYRIGHT.
  *    * 
  */   */
Line 24 Line 24
 #define AMAYA_LOST_UPDATE  #define AMAYA_LOST_UPDATE
   
 #ifdef _WINDOWS  #ifdef _WINDOWS
 #define CACHE_DIR_NAME TEXT("\\libwww-cache\\")  #define CACHE_DIR_NAME "\\libwww-cache\\"
 #else  #else
 #define CACHE_DIR_NAME TEXT("/libwww-cache/")  #define CACHE_DIR_NAME "/libwww-cache/"
 #endif  #endif
   
 /* libwww default parameters */  /* libwww default parameters */
Line 83  struct _HTError Line 83  struct _HTError
 /* Type definitions and global variables etc. local to this module */  /* Type definitions and global variables etc. local to this module */
   
 /*----------------------------------------------------------------------*/  /*----------------------------------------------------------------------*/
   
 /*** private variables ***/  /*** private variables ***/
   
 static HTList      *converters = NULL;  /* List of global converters */  static HTList      *converters = NULL;  /* List of global converters */
Line 118  static  FILE        *trace_fp = NULL; Line 117  static  FILE        *trace_fp = NULL;
   
 /* prototypes */  /* prototypes */
   
 #ifdef __STDC__  
 static void RecCleanCache (CHAR_T* dirname);  
 #ifdef _WINDOWS  #ifdef _WINDOWS
 int WIN_Activate_Request (HTRequest* , HTAlertOpcode, int, const char*, void*, HTAlertPar*);  int WIN_Activate_Request (HTRequest* , HTAlertOpcode, int, const char*, void*, HTAlertPar*);
 #endif /* _WINDOWS */  #endif /* _WINDOWS */
 static void SafePut_init (void);  
 static void SafePut_delete (void);  
 static ThotBool SafePut_query (CHAR_T* url);  
   
 #else  
 static void RecCleanCache (/* char *dirname */);  
 #ifdef _WINDOWS  
 int WIN_Activate_Request (/* HTRequest* , HTAlertOpcode, int, const char*, void*, HTAlertPar* */);  
 #endif /* _WINDOWS */  
 static void SafePut_init (/* void */);  
 static void SafePut_delete (/* void */);  
 static ThotBool SafePut_query (/* CHAR_T* url */);  
 #endif /* __STDC__ */  
   
   
 #ifdef AMAYA_WWW_CACHE  #ifdef AMAYA_WWW_CACHE
Line 149  static ThotBool SafePut_query (/* CHAR_T Line 133  static ThotBool SafePut_query (/* CHAR_T
   Returns -1 in case of failure, otherwise, it'll open a handle on    Returns -1 in case of failure, otherwise, it'll open a handle on
   filename and fd_cachelock will take its value.    filename and fd_cachelock will take its value.
   ----------------------------------------------------------------------*/    ----------------------------------------------------------------------*/
 #ifdef __STDC__  static int set_cachelock (char *filename)
 static int set_cachelock (CHAR_T* filename)  
 #else          
 static int set_cachelock (filename)  
 CharUniut* filename;  
 #endif /* __STDC__ */  
 {  {
   int status;    int status;
 #ifdef _WINDOWS  #ifdef _WINDOWS
Line 191  CharUniut* filename; Line 170  CharUniut* filename;
   remove the write lock set on a filename.    remove the write lock set on a filename.
   It'll close the fd handle on filename and reset *fd to 0.    It'll close the fd handle on filename and reset *fd to 0.
   ----------------------------------------------------------------------*/    ----------------------------------------------------------------------*/
 #ifdef __STDC__  
 static int clear_cachelock (void)  static int clear_cachelock (void)
 #else          
 static int clear_cachelock ()  
 int *fd;  
 #endif /* __STDC__ */  
 {  {
 #ifdef _WINDOWS  #ifdef _WINDOWS
   return 0;    return 0;
Line 218  int *fd; Line 192  int *fd;
   returns 0 if a fd is not locked by other process, otherwise     returns 0 if a fd is not locked by other process, otherwise 
   returns the pid of the process who has the lock    returns the pid of the process who has the lock
   ----------------------------------------------------------------------*/    ----------------------------------------------------------------------*/
 #ifdef __STDC__  static int test_cachelock (char *filename)
 static int test_cachelock (CHAR_T* filename)  
 #else  
 static int test_cachelock (filename)  
 CHAR_T*  filename;  
 #endif /* __STDC__ */  
 {  {
 #ifdef _WINDOWS  #ifdef _WINDOWS
   /* if the lock is set, we can't unlink the file under Windows */    /* if the lock is set, we can't unlink the file under Windows */
Line 263  CHAR_T*  filename; Line 232  CHAR_T*  filename;
   GetDocIdStatus    GetDocIdStatus
   gets the status associated to a docid                             gets the status associated to a docid                         
   ----------------------------------------------------------------------*/    ----------------------------------------------------------------------*/
 #ifdef __STDC__  
 AHTDocId_Status    *GetDocIdStatus (int docid, HTList * documents)  AHTDocId_Status    *GetDocIdStatus (int docid, HTList * documents)
 #else  
 AHTDocID_Status    *GetDocIdStatus (docid, documents)  
 int                 docid;  
 HTList             *documents;  
   
 #endif  
 {  {
    AHTDocId_Status    *me;     AHTDocId_Status    *me;
    HTList             *cur;     HTList             *cur;
Line 293  HTList             *documents; Line 255  HTList             *documents;
   AHTGuessAtom_for    AHTGuessAtom_for
   Converts an Amaya type descriptor into the equivalent MIME type.    Converts an Amaya type descriptor into the equivalent MIME type.
   ----------------------------------------------------------------------*/    ----------------------------------------------------------------------*/
 #ifdef __STDC__  static  HTAtom *AHTGuessAtom_for (char *urlName, PicType contentType)
 static  HTAtom *AHTGuessAtom_for (STRING urlName, PicType contentType)  
 #else  
 static  HTAtom *AHTGuessAtom_for (urlName, contentType)  
 STRING  urlName;  
 PicType contentType;  
 #endif  
 {  {
  HTAtom           *atom;   HTAtom           *atom;
  CHAR_T*           filename;   char *          filename;
  HTEncoding        enc = NULL;   HTEncoding        enc = NULL;
  HTEncoding        cte = NULL;   HTEncoding        cte = NULL;
  HTLanguage        lang = NULL;   HTLanguage        lang = NULL;
  double            quality = 1.0;   double            quality = 1.0;
  char              FName[MAX_LENGTH];  
   
  switch (contentType)   switch (contentType)
    {     {
Line 335  PicType contentType; Line 290  PicType contentType;
      ** Amaya could not detect the type, so        ** Amaya could not detect the type, so 
      ** we try to use the filename's suffix to do so.       ** we try to use the filename's suffix to do so.
      */       */
      filename = AmayaParseUrl (urlName, TEXT(""), AMAYA_PARSE_PATH | AMAYA_PARSE_PUNCTUATION);       filename = AmayaParseUrl (urlName, "", 
      wc2iso_strcpy (FName, filename);                                 AMAYA_PARSE_PATH | AMAYA_PARSE_PUNCTUATION);
      HTBind_getFormat (FName, &atom, &enc, &cte, &lang, &quality);       HTBind_getFormat (filename, &atom, &enc, &cte, &lang, &quality);
      TtaFreeMemory (filename);       TtaFreeMemory (filename);
      if (atom ==  WWW_UNKNOWN)       if (atom ==  WWW_UNKNOWN)
          /*           /*
Line 356  PicType contentType; Line 311  PicType contentType;
   Copies the headers in which the application is interested, doing    Copies the headers in which the application is interested, doing
   any in-between conversions as needed.    any in-between conversions as needed.
   ----------------------------------------------------------------------*/    ----------------------------------------------------------------------*/
 #ifdef __STDC__  
 void HTTP_headers_set (HTRequest * request, HTResponse * response, void *context, int status)  void HTTP_headers_set (HTRequest * request, HTResponse * response, void *context, int status)
 #else  
 void HTTP_headers_set (request, response, context, status)  
 HTRequest          *request;  
 HTResponse         *response;  
 void               *context;  
 int                 status;  
 #endif  
 {  {
   AHTReqContext      *me = (AHTReqContext *) HTRequest_context (request);    AHTReqContext      *me = (AHTReqContext *) HTRequest_context (request);
   HTAtom *tmp_atom;    HTAtom *tmp_atom;
Line 372  int                 status; Line 319  int                 status;
   HTAtom *unk_atom;    HTAtom *unk_atom;
 #endif  #endif
   char *tmp_char;    char *tmp_char;
   CHAR_T tmp_wchar[MAX_LENGTH];    char   tmp_wchar[MAX_LENGTH];
   HTParentAnchor *anchor = NULL;    HTParentAnchor *anchor = NULL;
   ThotBool  use_anchor = FALSE;    ThotBool  use_anchor = FALSE;
   
Line 450  int                 status; Line 397  int                 status;
   HTTP_headers_delete    HTTP_headers_delete
   Deletes all the paramaters that were assigned to the response type    Deletes all the paramaters that were assigned to the response type
   ----------------------------------------------------------------------*/    ----------------------------------------------------------------------*/
 #ifdef __STDC__  
 static void HTTP_headers_delete (AHTHeaders me)  static void HTTP_headers_delete (AHTHeaders me)
 #else  
 static void HTTP_headers_delete (me)  
 AHTHeaders me;  
 #endif  
 {  {
   if (me.content_type)    if (me.content_type)
     TtaFreeMemory (me.content_type);      TtaFreeMemory (me.content_type);
Line 472  AHTHeaders me; Line 414  AHTHeaders me;
   Returns the value of a parameter in the HTTP response structure.    Returns the value of a parameter in the HTTP response structure.
   Returns null if this structure is empty.    Returns null if this structure is empty.
   ----------------------------------------------------------------------*/    ----------------------------------------------------------------------*/
 #ifdef __STDC__  char   *HTTP_headers (AHTHeaders *me, AHTHeaderName param)
 CHAR_T *HTTP_headers (AHTHeaders *me, AHTHeaderName param)  
 #else  
 CHAR_T *HTTP_headers (me, param)  
 AHTHeaders *me;  
 AHTHeaderName param;  
 #endif  
 {  {
   CHAR_T *result;    char   *result;
   
   if (!me)    if (!me)
     return NULL;      return NULL;
Line 508  AHTHeaderName param; Line 444  AHTHeaderName param;
   create a new Amaya Context Object and update the global Amaya    create a new Amaya Context Object and update the global Amaya
   request status.    request status.
   ----------------------------------------------------------------------*/    ----------------------------------------------------------------------*/
 #ifdef __STDC__  
 static AHTReqContext *AHTReqContext_new (int docid)  static AHTReqContext *AHTReqContext_new (int docid)
 #else  
 static AHTReqContext *AHTReqContext_new (docid)  
 int                 docid;  
   
 #endif  
 {  {
    AHTReqContext      *me;     AHTReqContext      *me;
    AHTDocId_Status    *docid_status;     AHTDocId_Status    *docid_status;
Line 573  int                 docid; Line 503  int                 docid;
   Delete an Amaya Context Object and update the global Amaya request    Delete an Amaya Context Object and update the global Amaya request
   status.    status.
   ----------------------------------------------------------------------*/    ----------------------------------------------------------------------*/
   
 #ifdef __STDC__  
 ThotBool  AHTReqContext_delete (AHTReqContext * me)  ThotBool  AHTReqContext_delete (AHTReqContext * me)
 #else  
 ThotBool  AHTReqContext_delete (me)  
 AHTReqContext      *me;  
   
 #endif  
 {  {
    AHTDocId_Status    *docid_status;     AHTDocId_Status    *docid_status;
   
Line 687  AHTReqContext      *me; Line 610  AHTReqContext      *me;
   Thread_deleteAll    Thread_deleteAll
   this function deletes the whole list of active threads.               this function deletes the whole list of active threads.           
   ----------------------------------------------------------------------*/    ----------------------------------------------------------------------*/
 #ifdef __STDC__  
 static void         Thread_deleteAll (void)  static void         Thread_deleteAll (void)
 #else  
 static void         Thread_deleteAll ()  
 #endif  
 {  {
   HTList             *cur;    HTList             *cur;
   AHTReqContext      *me;    AHTReqContext      *me;
Line 734  static void         Thread_deleteAll () Line 653  static void         Thread_deleteAll ()
 /*----------------------------------------------------------------------  /*----------------------------------------------------------------------
   AHTOpen_file    AHTOpen_file
   ----------------------------------------------------------------------*/    ----------------------------------------------------------------------*/
 #ifdef __STDC__  
 int                 AHTOpen_file (HTRequest * request)  int                 AHTOpen_file (HTRequest * request)
 #else  
 int                 AHTOpen_file (request)  
 HTRequest           *request;  
   
 #endif /* __STDC__ */  
 {  {
   AHTReqContext      *me;      /* current request */    AHTReqContext      *me;      /* current request */
   
   me = HTRequest_context (request);    me = HTRequest_context (request);
   
   if (!me)    if (!me)
       return HT_ERROR;        return HT_ERROR;
   
 #ifdef DEBUG_LIBWWW  #ifdef DEBUG_LIBWWW
   fprintf(stderr, "AHTOpen_file: start for object : %p\n", me);    fprintf(stderr, "AHTOpen_file: start for object : %p\n", me);
 #endif /* DEBUG_LIBWWW */  #endif /* DEBUG_LIBWWW */
   
   if (me->reqStatus == HT_ABORT)     if (me->reqStatus == HT_ABORT) 
     {      {
 #ifdef DEBUG_LIBWWW  #ifdef DEBUG_LIBWWW
       fprintf(stderr, "AHTOpen_file: caught an abort request, skipping it\n");        fprintf(stderr, "AHTOpen_file: caught an abort request, skipping it\n");
 #endif /* DEBUG_LIBWWW */  #endif /* DEBUG_LIBWWW */
   
       return HT_OK;        return HT_OK;
     }      }
   
Line 770  HTRequest           *request; Line 679  HTRequest           *request;
   
   if (HTRequest_outputStream (me->request))     if (HTRequest_outputStream (me->request)) 
     {      {
   
 #ifdef DEBUG_LIBWWW  #ifdef DEBUG_LIBWWW
       fprintf(stderr, "AHTOpen_file: output stream already existed for url %s\n", me->urlName);        fprintf(stderr, "AHTOpen_file: output stream already existed for url %s\n", me->urlName);
 #endif /* DEBUG_LIBWWW */        #endif /* DEBUG_LIBWWW */      
Line 778  HTRequest           *request; Line 686  HTRequest           *request;
     }      }
   
 #ifdef DEBUG_LIBWWW  #ifdef DEBUG_LIBWWW
       fprintf(stderr, "AHTOpen_file: opening output stream for url %s\n", me->urlName);    fprintf(stderr, "AHTOpen_file: opening output stream for url %s\n", me->urlName);
 #endif /* DEBUG_LIBWWW */        #endif /* DEBUG_LIBWWW */      
   
   if (!(me->output) &&     if (!(me->output) && 
       (me->output != stdout) &&         (me->output != stdout) && 
 #ifndef _WINDOWS  #ifndef _WINDOWS
       (me->output = ufopen (me->outputfile, TEXT("w"))) == NULL)        (me->output = fopen (me->outputfile, "w")) == NULL)
     {  
 #else /* !_WINDOWS */  #else /* !_WINDOWS */
     (me->output = ufopen (me->outputfile, TEXT("wb"))) == NULL)          (me->output = fopen (me->outputfile, "wb")) == NULL)  
     {  
 #endif /* !_WINDOWS */  #endif /* !_WINDOWS */
       {
       me->outputfile[0] = EOS;  /* file could not be opened */        me->outputfile[0] = EOS;  /* file could not be opened */
 #ifdef DEBUG_LIBWWW  #ifdef DEBUG_LIBWWW
       fprintf(stderr, "AHTOpen_file: couldn't open output stream for url %s\n", me->urlName);        fprintf(stderr, "AHTOpen_file: couldn't open output stream for url %s\n", me->urlName);
 #endif  #endif
       TtaSetStatus (me->docid, 1, TtaGetMessage (AMAYA, AM_CANNOT_CREATE_FILE), me->outputfile);        TtaSetStatus (me->docid, 1,
                       TtaGetMessage (AMAYA, AM_CANNOT_CREATE_FILE),
                       me->outputfile);
       me->reqStatus = HT_ERR;        me->reqStatus = HT_ERR;
       return (HT_ERROR);        return (HT_ERROR);
     }      }
                       
   HTRequest_setOutputStream (me->request,    HTRequest_setOutputStream (me->request,
                              AHTFWriter_new (me->request,                                AHTFWriter_new (me->request, me->output, YES));
                                              me->output, YES));  
   me->reqStatus = HT_WAITING;    me->reqStatus = HT_WAITING;
     
   return HT_OK;    return HT_OK;
 }  }
   
 /*----------------------------------------------------------------------  /*----------------------------------------------------------------------
   redirection_handler    SafePut_init
   this function is registered to handle permanent and temporary    Sets up the domains which are authorized to make a redirect on 
   redirections.    a PUT.
   ----------------------------------------------------------------------*/    ----------------------------------------------------------------------*/
 #ifdef __STDC__  static void SafePut_init (void)
 static int          redirection_handler (HTRequest * request, HTResponse * response, void *param, int status)  {
 #else    char     *strptr;
 static int          redirection_handler (request, context, status)    char     *str = NULL;
 HTRequest          *request;    char*     ptr, *strptrA, *ptr2;
 HTResponse         *response;    char*     domain;
 void               *param;  
 int                 status;  
   
 #endif    /* get the proxy settings from the thot.ini file */
     strptr = TtaGetEnvString ("SAFE_PUT_REDIRECT");
     if (strptr && *strptr)
       {
         /* Get copy we can mutilate */
         ptr2 = strptr;
         /* convert to lowercase */
         ptr = strptr;
         while (*ptr) 
           {
             *ptr = tolower (*ptr);
             ptr++;
           }
         
         /* create the list container */
         safeput_list = HTList_new ();   
         /* store the domain list */
   
         ptr = strptr;
         while ((domain = HTNextField (&strptr)) != NULL)
             HTList_addObject (safeput_list, TtaStrdup (domain)); 
   
         TtaFreeMemory (str);
         TtaFreeMemory (ptr2);
       }
   }
   
   /*----------------------------------------------------------------------
     SafePut_delete
     Deletes the safeput_list variable
     ----------------------------------------------------------------------*/
   static void SafePut_delete (void)
 {  {
      HTList *cur = safeput_list;
    HTAnchor           *new_anchor = HTResponse_redirection (response);    char *domain;
    AHTReqContext      *me = HTRequest_context (request);  
    HTMethod            method = HTRequest_method (request);    if (!safeput_list) 
    CHAR_T*             ref;      return;
    CHAR_T*             escape_src, *dst;  
    CHAR_T              urlAdr[MAX_LENGTH];    while ((domain = (char *) HTList_nextObject (cur))) 
    char                urlRef[MAX_LENGTH];        TtaFreeMemory (domain);
      HTList_delete (safeput_list);
      safeput_list = NULL;
   }
   
   /*----------------------------------------------------------------------
     SafePut_query
     returns true if the domain to which belongs the URL accepts an automatic
     PUT redirect.
     ----------------------------------------------------------------------*/
   static ThotBool SafePut_query (char *url)
   {
     HTList*  cur;
     char*    me;
     ThotBool found;
     char     tmp[MAX_LENGTH];
   
    if (!me) /* if the redirect doesn't come from Amaya, we call libwww's standard redirect filter */    /* extract the domain path of the url and normalize it */
       return (HTRedirectFilter (request, response, param, status));    /* domain = url; */
     cur = safeput_list;
     found = FALSE;
   
    if (!new_anchor) {    while ((me = (char*) HTList_nextObject (cur))) {
       if (PROT_TRACE)          iso2wc_strcpy (tmp, me);
           if (strstr (url, tmp))
             {
              found = TRUE;
              break;
             } 
     } 
   
     return (found);
   }
   
   /*----------------------------------------------------------------------
     redirection_handler
     this function is registered to handle permanent and temporary
     redirections.
     ----------------------------------------------------------------------*/
   static int redirection_handler (HTRequest *request, HTResponse *response,
                                   void *param, int status)
   {
     HTAnchor           *new_anchor = HTResponse_redirection (response);
     AHTReqContext      *me = HTRequest_context (request);
     HTMethod            method = HTRequest_method (request);
     char               *ref;
     char               *escape_src, *dst;
     char                urlAdr[MAX_LENGTH];
   
      if (!me)
        /* if the redirect doesn't come from Amaya, we call libwww's standard redirect filter */
        return (HTRedirectFilter (request, response, param, status));
      
      if (!new_anchor)
        {
          if (PROT_TRACE)
          HTTrace ("Redirection. No destination\n");           HTTrace ("Redirection. No destination\n");
       return HT_OK;         return HT_OK;
    }       }
   
    /*     /*
    ** Only do redirect on GET, HEAD, and authorized domains for PUT     ** Only do redirect on GET, HEAD, and authorized domains for PUT
     */     */
    if ((me->method == METHOD_PUT && !SafePut_query (me->urlName)) || (me->method != METHOD_PUT && !HTMethod_isSafe (method))) {     if ((me->method == METHOD_PUT && !SafePut_query (me->urlName)) ||
       /*         (me->method != METHOD_PUT && !HTMethod_isSafe (method)))
       ** If we got a 303 See Other then change the method to GET.       {
       ** Otherwise ask the user whether we should continue.       /*
       */       ** If we got a 303 See Other then change the method to GET.
       if (status == HT_SEE_OTHER) {       ** Otherwise ask the user whether we should continue.
        */
        if (status == HT_SEE_OTHER)
          {
          if (PROT_TRACE)           if (PROT_TRACE)
             HTTrace("Redirection. Changing method from %s to GET\n", HTMethod_name(method));             HTTrace("Redirection. Changing method from %s to GET\n", HTMethod_name(method));
             HTRequest_setMethod(request, METHOD_GET);           HTRequest_setMethod(request, METHOD_GET);
           } else {         }
              HTAlertCallback    *prompt = HTAlert_find (HT_A_CONFIRM);       else
              if (prompt) {         {
                 if ((*prompt) (request, HT_A_CONFIRM, HT_MSG_REDIRECTION, NULL, NULL, NULL) != YES)           HTAlertCallback    *prompt = HTAlert_find (HT_A_CONFIRM);
                   {           if (prompt)
                     /* the user didn't agree on the redirection, so             {
                        we consider it's an abort */               if ((*prompt) (request, HT_A_CONFIRM, HT_MSG_REDIRECTION, NULL, NULL, NULL) != YES)
                     me->reqStatus = HT_ABORT;                 {
                     /* and we return HT_OK so that the terminate_handler                   /* the user didn't agree on the redirection, so
                        will be called */                      we consider it's an abort */
                     return HT_OK;                   me->reqStatus = HT_ABORT;
                   }                   /* and we return HT_OK so that the terminate_handler
              }                       will be called */
           }                    return HT_OK;
    }                  }
    /*             }
     **  Start new request with the redirect anchor found in the headers.         }
     **  Note that we reuse the same request object which means that we must     }
     **  keep this around until the redirected request has terminated. It also             
     **  allows us in an easy way to keep track of the number of redirections  
     **  so that we can detect endless loops.  
     */  
   
    if (HTRequest_doRetry (request)) {     /*
       /*     **  Start new request with the redirect anchor found in the headers.
       ** Start request with new credentials      **  Note that we reuse the same request object which means that we must
       */     **  keep this around until the redirected request has terminated. It also
       /* only do a redirect using a network protocol understood by Amaya */     **  allows us in an easy way to keep track of the number of redirections
       iso2wc_strcpy (urlAdr, new_anchor->parent->address);     **  so that we can detect endless loops.
       if (IsValidProtocol (urlAdr)) {     */
          /* if it's a valid URL, we try to normalize it */     if (HTRequest_doRetry (request))
          /* We use the pre-redirection anchor as a base name */       {
          /* @@ how to obtain this address here? */         /*
          dst = urlAdr;         ** Start request with new credentials 
          escape_src = EscapeURL (me->urlName);         */
          if (escape_src) {         /* only do a redirect using a network protocol understood by Amaya */
             ref = AmayaParseUrl (dst, escape_src, AMAYA_PARSE_ALL);         iso2wc_strcpy (urlAdr, new_anchor->parent->address);
             wc2iso_strcpy (urlRef, ref);         if (IsValidProtocol (urlAdr))
             TtaFreeMemory (escape_src);           {
                  } else             /* if it's a valid URL, we try to normalize it */
                ref = NULL;             /* We use the pre-redirection anchor as a base name */
              /* @@ how to obtain this address here? */
          if (ref) {             dst = urlAdr;
             HTAnchor_setPhysical (HTAnchor_parent (new_anchor), urlRef);             escape_src = EscapeURL (me->urlName);
             TtaFreeMemory (ref);             if (escape_src)
                  } else               {
                return HT_OK; /* We can't redirect anymore */                 ref = AmayaParseUrl (dst, escape_src, AMAYA_PARSE_ALL);
           } else                 TtaFreeMemory (escape_src);
             return HT_OK; /* We can't redirect anymore */               }
              else
       /* update the current file name */               ref = NULL;
       if ((me->mode & AMAYA_ASYNC) || (me->mode & AMAYA_IASYNC) || (me->method == METHOD_PUT)) {             
          TtaFreeMemory (me->urlName);             if (ref)
          me->urlName = TtaWCSdup (urlAdr);               {
           } else {                 HTAnchor_setPhysical (HTAnchor_parent (new_anchor), ref);
             /* it's a SYNC mode, so we should keep the urlName */                 TtaFreeMemory (ref);
             ustrncpy (me->urlName, urlAdr, MAX_LENGTH - 1);               }
             me->urlName[MAX_LENGTH - 1] = EOS;             else
           }               return HT_OK; /* We can't redirect anymore */
       ChopURL (me->status_urlName, me->urlName);           }
          else
            return HT_OK; /* We can't redirect anymore */
          
          /* update the current file name */
          if ((me->mode & AMAYA_ASYNC) || (me->mode & AMAYA_IASYNC) ||
              (me->method == METHOD_PUT))
            {
              TtaFreeMemory (me->urlName);
              me->urlName = TtaWCSdup (urlAdr);
            }
          else
            {
              /* it's a SYNC mode, so we should keep the urlName */
              strncpy (me->urlName, urlAdr, MAX_LENGTH - 1);
              me->urlName[MAX_LENGTH - 1] = EOS;
            }
          ChopURL (me->status_urlName, me->urlName);
   
       /* @@ verify if this is important */         /* @@ verify if this is important */
       /* @@@ new libwww doesn't need this free stream while making         /* @@@ new libwww doesn't need this free stream while making
          a PUT. Is it the case everywhere or just for PUT? */            a PUT. Is it the case everywhere or just for PUT? */
       if (me->method != METHOD_PUT && me->request->orig_output_stream != NULL)         if (me->method != METHOD_PUT &&
         {             me->request->orig_output_stream != NULL)
           AHTFWriter_FREE (me->request->orig_output_stream);           {
           me->request->orig_output_stream = NULL;             AHTFWriter_FREE (me->request->orig_output_stream);
           if (me->output != stdout) { /* Are we writing to a file? */             me->request->orig_output_stream = NULL;
              if (me->output != stdout)
                {
                  /* Are we writing to a file? */
 #ifdef DEBUG_LIBWWW  #ifdef DEBUG_LIBWWW
             fprintf (stderr, "redirection_handler: New URL is  %s, closing FILE %p\n", me->urlName, me->output);                  fprintf (stderr, "redirection_handler: New URL is  %s, closing FILE %p\n", me->urlName, me->output); 
 #endif   #endif 
             fclose (me->output);                 fclose (me->output);
             me->output = NULL;                 me->output = NULL;
           }               }
         }           }
          
       /* tell the user what we're doing */         /* tell the user what we're doing */
       TtaSetStatus (me->docid, 1, TtaGetMessage (AMAYA, AM_RED_FETCHING), me->status_urlName);          TtaSetStatus (me->docid, 1,
       /*                       TtaGetMessage (AMAYA, AM_RED_FETCHING), me->status_urlName); 
       ** launch the request         /*
       */         ** launch the request
       /* add a link relationship? */         */
       /* reset the request status */         /* add a link relationship? */
       me->reqStatus = HT_NEW;          /* reset the request status */
       /* clear the errors */         me->reqStatus = HT_NEW; 
       HTError_deleteAll (HTRequest_error (request));         /* clear the errors */
       HTRequest_setError (request, NULL);         HTError_deleteAll (HTRequest_error (request));
       /* clear the authentication credentials, as they get regenerated  */         HTRequest_setError (request, NULL);
       HTRequest_deleteCredentialsAll (request);         /* clear the authentication credentials, as they get regenerated  */
                  HTRequest_deleteCredentialsAll (request);
       if (me->method == METHOD_POST || me->method == METHOD_PUT) { /* PUT, POST etc. */         
          char url_Name[MAX_LENGTH];         if (me->method == METHOD_POST || me->method == METHOD_PUT)
          wc2iso_strcpy (url_Name, me->urlName);           /* PUT, POST etc. */
          status = HTLoadAbsolute (url_Name, request);           status = HTLoadAbsolute (me->urlName, request);
       } else         else
            HTLoadAnchor (new_anchor, request);           HTLoadAnchor (new_anchor, request);
    } else {       }
           HTRequest_addError (request, ERR_FATAL, NO, HTERR_MAX_REDIRECT, NULL, 0, "HTRedirectFilter");     else
           /* so that we can show the error message */       {
           if (me->error_html)         HTRequest_addError (request, ERR_FATAL, NO, HTERR_MAX_REDIRECT, NULL, 0, "HTRedirectFilter");
              DocNetworkStatus[me->docid] |= AMAYA_NET_ERROR;         /* so that we can show the error message */
           me->reqStatus = HT_ERR;         if (me->error_html)
           TtaSetStatus (me->docid, 1, TtaGetMessage (AMAYA, AM_REDIRECTIONS_LIMIT), NULL);           DocNetworkStatus[me->docid] |= AMAYA_NET_ERROR;
    }         me->reqStatus = HT_ERR;
          TtaSetStatus (me->docid, 1, TtaGetMessage (AMAYA, AM_REDIRECTIONS_LIMIT), NULL);
        }
      
    /*     /*
    **  By returning HT_ERROR we make sure that this is the last handler to be     **  By returning HT_ERROR we make sure that this is the last handler to be
    **  called. We do this as we don't want any other filter to delete the      **  called. We do this as we don't want any other filter to delete the 
Line 973  int                 status; Line 978  int                 status;
   precondition_handler    precondition_handler
   412 "Precondition failed" handler    412 "Precondition failed" handler
   ----------------------------------------------------------------------*/    ----------------------------------------------------------------------*/
 #if __STDC__  static int precondition_handler (HTRequest *request, HTResponse *response,
 static int          precondition_handler (HTRequest * request, HTResponse * response, void *context, int status)                                   void *context, int status)
 #else  
 static int          precondition_handler (request, response, context, status)  
 HTRequest          *request;  
 HTResponse         *response;  
 void               *context;  
 int                 status;  
 #endif /* __STDC__ */  
 {  {
   AHTReqContext  *me = (AHTReqContext *) HTRequest_context (request);    AHTReqContext  *me = (AHTReqContext *) HTRequest_context (request);
   HTAlertCallback    *prompt = HTAlert_find (HT_A_CONFIRM);    HTAlertCallback    *prompt = HTAlert_find (HT_A_CONFIRM);
Line 1165  static int check_handler (HTRequest * re Line 1163  static int check_handler (HTRequest * re
   terminate_handler    terminate_handler
   this function is registered to handle the result of the request    this function is registered to handle the result of the request
   ----------------------------------------------------------------------*/    ----------------------------------------------------------------------*/
 #if __STDC__  static int terminate_handler (HTRequest *request, HTResponse *response,
 static int          terminate_handler (HTRequest * request, HTResponse * response, void *context, int status)                                void *context, int status)
 #else  
 static int          terminate_handler (request, response, context, status)  
 HTRequest          *request;  
 HTResponse         *response;  
 void               *context;  
 int                 status;  
 #endif /* __STDC__ */  
 {  {
   AHTReqContext      *me = (AHTReqContext *) HTRequest_context (request);    AHTReqContext      *me = (AHTReqContext *) HTRequest_context (request);
   ThotBool            error_flag;    ThotBool            error_flag;
Line 1294  int                 status; Line 1285  int                 status;
   
    /* to avoid a hangup while downloading css files */     /* to avoid a hangup while downloading css files */
    if (AmayaAlive_flag && (me->mode & AMAYA_LOAD_CSS))     if (AmayaAlive_flag && (me->mode & AMAYA_LOAD_CSS))
      TtaSetStatus (me->docid, 1, TtaGetMessage (AMAYA, AM_ELEMENT_LOADED), me->status_urlName);       TtaSetStatus (me->docid, 1,
                      TtaGetMessage (AMAYA, AM_ELEMENT_LOADED),
                      me->status_urlName);
         
   /* don't remove or Xt will hang up during the PUT */    /* don't remove or Xt will hang up during the PUT */
    if (AmayaIsAlive ()  && ((me->method == METHOD_POST) ||     if (AmayaIsAlive ()  && ((me->method == METHOD_POST) ||
Line 1314  int                 status; Line 1307  int                 status;
   this is an application "AFTER" Callback. It's called by the library    this is an application "AFTER" Callback. It's called by the library
   when a request has ended, so that we can setup the correct status.    when a request has ended, so that we can setup the correct status.
   ----------------------------------------------------------------------*/    ----------------------------------------------------------------------*/
   int AHTLoadTerminate_handler (HTRequest *request, HTResponse *response,
 #ifdef __STDC__                                void *param, int status)
 int          AHTLoadTerminate_handler (HTRequest * request, HTResponse * response, void *param, int status)  
 #else  
 int          AHTLoadTerminate_handler (request, response, param, status)  
 HTRequest          *request;  
 HTResponse         *response;  
 void               *param;  
 int                 status;  
   
 #endif  
 {  {
   
   /** @@@@ use this with printstatus ?? */    /** @@@@ use this with printstatus ?? */
   
    AHTReqContext      *me = HTRequest_context (request);     AHTReqContext      *me = HTRequest_context (request);
    HTAlertCallback    *cbf;     HTAlertCallback    *cbf;
    AHTDocId_Status    *docid_status;     AHTDocId_Status    *docid_status;
Line 1378  int                 status; Line 1360  int                 status;
   
      case HT_NOT_MODIFIED:       case HT_NOT_MODIFIED:
        if (PROT_TRACE)         if (PROT_TRACE)
          HTTrace ("Load End.... NOT MODIFIED (%s)", me->status_urlName ? me->status_urlName :" <UNKNOWN>");           HTTrace ("Load End.... NOT MODIFIED (%s)",
                     me->status_urlName ? me->status_urlName :" <UNKNOWN>");
        break;         break;
                 
      case HT_ERROR:       case HT_ERROR:
Line 1387  int                 status; Line 1370  int                 status;
          (*cbf) (request, HT_A_MESSAGE, HT_MSG_NULL, NULL,           (*cbf) (request, HT_A_MESSAGE, HT_MSG_NULL, NULL,
                  HTRequest_error (request), NULL);                   HTRequest_error (request), NULL);
        if (PROT_TRACE)         if (PROT_TRACE)
            HTTrace ("Load End.... ERROR: Can't access `%s\'\n", me->status_urlName ? me->status_urlName :"<UNKNOWN>");              HTTrace ("Load End.... ERROR: Can't access `%s\'\n",
        TtaSetStatus (me->docid, 1, TtaGetMessage (AMAYA, AM_CANNOT_LOAD), me->status_urlName ? me->status_urlName : TEXT("<UNKNOWN>"));                      me->status_urlName ? me->status_urlName :"<UNKNOWN>"); 
          TtaSetStatus (me->docid, 1,
                        TtaGetMessage (AMAYA, AM_CANNOT_LOAD),
                        me->status_urlName ? me->status_urlName : "<UNKNOWN>");
        break;         break;
   
      case HTERR_TIMEOUT:       case HTERR_TIMEOUT:
Line 1397  int                 status; Line 1383  int                 status;
          (*cbf) (request, HT_A_MESSAGE, HT_MSG_NULL, NULL,           (*cbf) (request, HT_A_MESSAGE, HT_MSG_NULL, NULL,
                  HTRequest_error (request), NULL);                   HTRequest_error (request), NULL);
        if (PROT_TRACE)         if (PROT_TRACE)
            HTTrace ("Load End.... REQUEST TIMEOUT: Can't access `%s\'\n", me->status_urlName ? me->status_urlName :"<UNKNOWN>");              HTTrace ("Load End.... REQUEST TIMEOUT: Can't access `%s\'\n",
        TtaSetStatus (me->docid, 1, TtaGetMessage (AMAYA, AM_CANNOT_LOAD), me->status_urlName ? me->status_urlName : TEXT("<UNKNOWN>"));                      me->status_urlName ? me->status_urlName :"<UNKNOWN>"); 
          TtaSetStatus (me->docid, 1, TtaGetMessage (AMAYA, AM_CANNOT_LOAD),
                        me->status_urlName ? me->status_urlName : "<UNKNOWN>");
        break;         break;
   
      default:       default:
Line 1425  static  int LineTrace (const char * fmt, Line 1413  static  int LineTrace (const char * fmt,
   This function prepares the Accept header used by Amaya during    This function prepares the Accept header used by Amaya during
   the HTTP content negotiation phase    the HTTP content negotiation phase
   ----------------------------------------------------------------------*/    ----------------------------------------------------------------------*/
 #ifdef __STDC__  
 static void           AHTAcceptTypesInit (HTList *c)  static void           AHTAcceptTypesInit (HTList *c)
 #else  /* __STDC__ */  
 static void           AHTAcceptTypesInit (c)  
 HTList             *c;  
 #endif /* __STDC__ */  
 {  {
    if (c == (HTList *) NULL)      if (c == (HTList *) NULL) 
       return;        return;
Line 1466  HTList             *c; Line 1449  HTList             *c;
   This function prepares the Accept header used by Amaya during    This function prepares the Accept header used by Amaya during
   the HTTP content negotiation phase    the HTTP content negotiation phase
   ----------------------------------------------------------------------*/    ----------------------------------------------------------------------*/
 #ifdef __STDC__  
 static void         AHTAcceptLanguagesInit (HTList *c)  static void         AHTAcceptLanguagesInit (HTList *c)
 #else  /* __STDC__ */  
 static void         AHTAcceptLanguagesInit (c)  
 HTList             *c;  
 #endif /* __STDC__ */  
 {  {
   CHAR_T*         ptr;    char             *ptr;
   CHAR_T*         lang_list;    char             *lang_list;
   char              s[3];    char              s[3];
   int               count, lg;    int               count, lg;
   double            quality;    double            quality;
   ThotBool          still;    ThotBool          still;
   
   if (c == (HTList *) NULL)     if (c == (HTList *) NULL) 
       return;      return;
       
   lang_list = TtaGetEnvString ("ACCEPT_LANGUAGES");    lang_list = TtaGetEnvString ("ACCEPT_LANGUAGES");
   s[2] = EOS;    s[2] = EOS;
Line 1492  HTList             *c; Line 1470  HTList             *c;
       /* how many languages do we have? */        /* how many languages do we have? */
       ptr = lang_list;        ptr = lang_list;
       count = 0;        count = 0;
       while (*ptr != WC_EOS) {        while (*ptr != WC_EOS)
             while (*ptr != WC_EOS && (*ptr < TEXT('A') || (*ptr > TEXT('Z') && *ptr < TEXT('a')) || *ptr > TEXT('z')))          {
                   /* skip the whole separator */            while (*ptr != WC_EOS &&
                   ptr++;                   (*ptr < 'A' || (*ptr > 'Z' && *ptr < 'a') || *ptr > 'z'))
             lg = 0;              /* skip the whole separator */
             while ((*ptr >= TEXT('A') && *ptr <= TEXT('Z')) || (*ptr >= TEXT('a') && *ptr <= TEXT('z')) || *ptr == TEXT('-')) {              ptr++;
                   /* it's a new language */            lg = 0;
                   ptr++;            while ((*ptr >= 'A' &&
                   lg++;                    *ptr <= 'Z') || (*ptr >= 'a' && *ptr <= 'z') || *ptr == '-')
                         }              {
             if (lg >= 2)                /* it's a new language */
                count++;                ptr++;
             if (*ptr != WC_EOS)                lg++;
                ptr++;              }
           }            if (lg >= 2)
               count++;
             if (*ptr != WC_EOS)
               ptr++;
           }
   
       if (count > 0)        if (count > 0)
          quality = 1.1 - (double) count/10.0;          quality = 1.1 - (double) count/10.0;
       else        else
           quality = 1.0;          quality = 1.0;
   
      /* Read the languages from the registry, then inject them one, by one.        /* Read the languages from the registry, then inject them one, by one.
         The first one is the one with the highest priority.           The first one is the one with the highest priority.
         The libwww ask for the lowest priority first.           The libwww ask for the lowest priority first.
       */        */
       ptr--;        ptr--;
       still = TRUE;        still = TRUE;
       while (count) {        while (count)
             while (still && (*ptr < TEXT('A') || (*ptr > TEXT('Z') && *ptr < TEXT('a')) || *ptr > TEXT('z')))          {
                   /* skip the whole separator */            while (still && (*ptr < 'A' || (*ptr > 'Z' && *ptr < 'a') || *ptr > 'z'))
                   if (ptr > lang_list)              /* skip the whole separator */
                      ptr--;              if (ptr > lang_list)
                   else                ptr--;
                       still = FALSE;              else
             lg = 0;                still = FALSE;
             while (still && ((*ptr >= TEXT('A') && *ptr <= TEXT('Z')) || (*ptr >= TEXT('a') && *ptr <= TEXT('z')) || *ptr == TEXT('-'))) {            lg = 0;
                   /* it's a new language */            while (still &&
                   if (ptr > lang_list)                   ((*ptr >= 'A' &&
                      ptr--;                     *ptr <= 'Z') || (*ptr >= 'a' && *ptr <= 'z') || *ptr == '-'))
                   else              {
                       still = FALSE;                /* it's a new language */
                   lg++;                if (ptr > lang_list)
                         }                  ptr--;
             if (lg >= 2) {                else
                if (still)                  still = FALSE;
                   wc2iso_strncpy  (s, &ptr[1], 2);                lg++;
                else              }
                    wc2iso_strncpy (s, lang_list, 2);            if (lg >= 2)
                count--;              {
                HTLanguage_add (c, s, quality);                if (still)
                quality += 0.1;                  strncpy  (s, &ptr[1], 2);
                         }                else
             ptr--;                  strncpy (s, lang_list, 2);
           }                count--;
   }                HTLanguage_add (c, s, quality);
                 quality += 0.1;
               }
             ptr--;
           }
       }
 }  }
   
 /*----------------------------------------------------------------------  /*----------------------------------------------------------------------
Line 1554  HTList             *c; Line 1541  HTList             *c;
   Bindings between a source media type and a destination media type    Bindings between a source media type and a destination media type
   (conversion).    (conversion).
   ----------------------------------------------------------------------*/    ----------------------------------------------------------------------*/
 #ifdef __STDC__  
 static void         AHTConverterInit (HTList *c)  static void         AHTConverterInit (HTList *c)
 #else  /* __STDC__ */  
 static void         AHTConverterInit (c)  
 HTList             *c;  
 #endif /* __STDC__ */  
 {  {
   
    /* Handler for custom http error messages */     /* Handler for custom http error messages */
    HTConversion_add (c, "*/*", "www/debug", AHTMemConverter, 1.0, 0.0, 0.0);     HTConversion_add (c, "*/*", "www/debug", AHTMemConverter, 1.0, 0.0, 0.0);
   
Line 1613  HTList             *c; Line 1594  HTList             *c;
   ----------------------------------------------------------------------*/    ----------------------------------------------------------------------*/
 static void         AHTProtocolInit (void)  static void         AHTProtocolInit (void)
 {  {
   CHAR_T* strptr;    char *strptr;
   
   /*     /* 
      NB. Preemptive == YES means Blocking requests       NB. Preemptive == YES means Blocking requests
Line 1638  static void         AHTProtocolInit (voi Line 1619  static void         AHTProtocolInit (voi
   
    /* initialize pipelining */     /* initialize pipelining */
   strptr = TtaGetEnvString ("ENABLE_PIPELINING");    strptr = TtaGetEnvString ("ENABLE_PIPELINING");
   if (strptr && *strptr && ustrcasecmp (strptr, TEXT("yes")))    if (strptr && *strptr && strcasecmp (strptr, "yes"))
     HTTP_setConnectionMode (HTTP_11_NO_PIPELINING);      HTTP_setConnectionMode (HTTP_11_NO_PIPELINING);
 }  }
   
Line 1693  static void         AHTNetInit (void) Line 1674  static void         AHTNetInit (void)
   AHTAlertInit    AHTAlertInit
   Register alert messages and their callbacks.    Register alert messages and their callbacks.
   ----------------------------------------------------------------------*/    ----------------------------------------------------------------------*/
 #ifdef __STDC__  
 static void         AHTAlertInit (void)  static void         AHTAlertInit (void)
 #else  
 static void         AHTAlertInit ()  
 #endif  
 {  {
    HTAlert_add (AHTProgress, HT_A_PROGRESS);     HTAlert_add (AHTProgress, HT_A_PROGRESS);
 #ifdef __WINDOWS  #ifdef __WINDOWS
Line 1710  static void         AHTAlertInit () Line 1687  static void         AHTAlertInit ()
    HTAlert_add (AHTPromptUsernameAndPassword, HT_A_USER_PW);     HTAlert_add (AHTPromptUsernameAndPassword, HT_A_USER_PW);
 }  }
   
 /*----------------------------------------------------------------------  
   libwww_CleanCache  
   frontend to the recursive cache cleaning function  
   ----------------------------------------------------------------------*/  
 #ifdef __STDC__  
 void libwww_CleanCache (void)  
 #else  
 void libwww_CleanCache ()  
 Document doc;  
 View view;  
 #endif /* __STDC__ */  
 {  
 #ifdef AMAYA_WWW_CACHE  
   CHAR_T*  real_dir;  
   char*    cache_dir;  
   char*    tmp;  
   int      cache_size;  
   int      cache_expire;  
   int      cache_disconnect;  
   ThotBool error;  
   CHAR_T*  ptr;  
   
   if (!HTCacheMode_enabled ())  
     /* don't do anything if we're not using a cache */  
     return;  
   /* temporarily close down the cache, purge it, then restart */  
   tmp = HTCacheMode_getRoot ();  
   /* don't do anything if we don't have a valid cache dir */  
   if (!tmp || *tmp == EOS)  
           return;  
   cache_dir = TtaStrdup (tmp);  
   HT_FREE (tmp);  
   cache_size = HTCacheMode_maxSize ();  
   cache_expire = HTCacheMode_expires ();  
   cache_disconnect = HTCacheMode_disconnected ();  
   
   /* get something we can work on :) */  
   tmp = HTWWWToLocal (cache_dir, "file:", NULL);  
   real_dir = TtaAllocString (strlen (tmp) + 20);  
   iso2wc_strcpy (real_dir, tmp);  
   HT_FREE (tmp);  
   
   /* safeguard... abort the operation if cache_dir doesn't end with  
      CACHE_DIR_NAME */  
   error = TRUE;  
   ptr = ustrstr (real_dir, CACHE_DIR_NAME);    
     if (ptr && *ptr && !ustrcasecmp (ptr, CACHE_DIR_NAME))  
       error = FALSE;  
   if (error)  
     return;    
     
   /* remove the concurrent cache lock */  
 #ifdef DEBUG_LIBWWW  
   fprintf (stderr, "Clearing the cache lock\n");  
 #endif /* DEBUG_LIBWWW */  
   clear_cachelock ();  
   HTCacheTerminate ();  
   HTCacheMode_setEnabled (FALSE);  
     
   RecCleanCache (real_dir);  
   
   HTCacheMode_setExpires (cache_expire);  
   HTCacheMode_setDisconnected (cache_disconnect);  
   HTCacheInit (cache_dir, cache_size);  
   /* set a new concurrent cache lock */  
   ustrcat (real_dir, TEXT(".lock"));  
   if (set_cachelock (real_dir) == -1)  
     /* couldn't open the .lock file, so, we close the cache to  
        be in the safe side */  
     {  
 #ifdef DEBUG_LIBWWW  
       fprintf (stderr, "couldnt set the cache lock\n");  
 #endif /* DEBUG_LIBWWW */  
       HTCacheTerminate ();  
       HTCacheMode_setEnabled (FALSE);  
     }  
 #ifdef DEBUG_LIBWWW  
   fprintf (stderr, "set a cache lock\n");  
 #endif /* DEBUG_LIBWWW */  
   TtaFreeMemory (real_dir);  
   TtaFreeMemory (cache_dir);  
 #endif /* AMAYA_WWW_CACHE */  
 }  
   
 #ifdef AMAYA_WWW_CACHE  #ifdef AMAYA_WWW_CACHE
 /*----------------------------------------------------------------------  /*----------------------------------------------------------------------
   RecCleanCache    RecCleanCache
   Clears an existing cache directory    Clears an existing cache directory
   ----------------------------------------------------------------------*/    ----------------------------------------------------------------------*/
 #ifdef __STDC__  static void RecCleanCache (char *dirname)
 static void RecCleanCache (CHAR_T* dirname)  
 #else  
 static void RecCleanCache (dirname)  
 CHAR_T*   dirname;  
 #endif /* __STDC__ */  
   
 #ifdef _WINDOWS  
 {  {
   #ifdef _WINDOWS
   HANDLE          hFindFile;    HANDLE          hFindFile;
   ThotBool        status;    ThotBool        status;
   WIN32_FIND_DATA ffd;    WIN32_FIND_DATA ffd;
   CHAR_T        t_dir [MAX_LENGTH];    char          t_dir [MAX_LENGTH];
   CHAR_T*       ptr;    char *      ptr;
   
   /* create a t_dir name to start searching for files */    /* create a t_dir name to start searching for files */
   if ((ustrlen (dirname) + 10) > MAX_LENGTH)    if ((strlen (dirname) + 10) > MAX_LENGTH)
     /* ERROR: directory name is too big */      /* ERROR: directory name is too big */
     return;      return;
   
   ustrcpy (t_dir, dirname);    strcpy (t_dir, dirname);
   /* save the end of the dirname. We'll use it to make    /* save the end of the dirname. We'll use it to make
      a complete pathname when erasing files */       a complete pathname when erasing files */
   ptr = &t_dir[ustrlen (t_dir)];    ptr = &t_dir[strlen (t_dir)];
   ustrcat (t_dir, TEXT("*"));    strcat (t_dir, "*");
   
   hFindFile = FindFirstFile (t_dir, &ffd);    hFindFile = FindFirstFile (t_dir, &ffd);
           
Line 1837  CHAR_T*   dirname; Line 1724  CHAR_T*   dirname;
       if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)        if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
         {          {
           /* it's a directory, erase it recursively */            /* it's a directory, erase it recursively */
           if (ustrcmp (ffd.cFileName, TEXT("..")) && ustrcmp (ffd.cFileName, TEXT(".")))            if (strcmp (ffd.cFileName, "..") && strcmp (ffd.cFileName, "."))
             {              {
               ustrcpy (ptr, ffd.cFileName);                strcpy (ptr, ffd.cFileName);
               ustrcat (ptr, WC_DIR_STR);                strcat (ptr, WC_DIR_STR);
               RecCleanCache (t_dir);                RecCleanCache (t_dir);
               urmdir (t_dir);                urmdir (t_dir);
             }              }
Line 1848  CHAR_T*   dirname; Line 1735  CHAR_T*   dirname;
         else          else
           {            {
             /* it's a file, erase it */              /* it's a file, erase it */
             ustrcpy (ptr, ffd.cFileName);              strcpy (ptr, ffd.cFileName);
             TtaFileUnlink (t_dir);              TtaFileUnlink (t_dir);
           }            }
       status = FindNextFile (hFindFile, &ffd);        status = FindNextFile (hFindFile, &ffd);
     }      }
   FindClose (hFindFile);    FindClose (hFindFile);
 }  
   
 #else /* _WINDOWS */  #else /* _WINDOWS */
 {  
   DIR *dp;    DIR *dp;
   struct stat st;    struct stat st;
 #ifdef HAVE_DIRENT_H  #ifdef HAVE_DIRENT_H
Line 1908  CHAR_T*   dirname; Line 1793  CHAR_T*   dirname;
         }          }
     }      }
   closedir (dp);    closedir (dp);
 }  
 #endif /* _WINDOWS */  #endif /* _WINDOWS */
   }
   #endif /* AMAYA_WWW_CACHE */
   
   /*----------------------------------------------------------------------
     libwww_CleanCache
     frontend to the recursive cache cleaning function
     ----------------------------------------------------------------------*/
   void libwww_CleanCache (void)
   {
   #ifdef AMAYA_WWW_CACHE
     char * real_dir;
     char*    cache_dir;
     char*    tmp;
     int      cache_size;
     int      cache_expire;
     int      cache_disconnect;
     ThotBool error;
     char * ptr;
   
     if (!HTCacheMode_enabled ())
       /* don't do anything if we're not using a cache */
       return;
     /* temporarily close down the cache, purge it, then restart */
     tmp = HTCacheMode_getRoot ();
     /* don't do anything if we don't have a valid cache dir */
     if (!tmp || *tmp == EOS)
             return;
     cache_dir = TtaStrdup (tmp);
     HT_FREE (tmp);
     cache_size = HTCacheMode_maxSize ();
     cache_expire = HTCacheMode_expires ();
     cache_disconnect = HTCacheMode_disconnected ();
   
     /* get something we can work on :) */
     tmp = HTWWWToLocal (cache_dir, "file:", NULL);
     real_dir = TtaGetMemory (strlen (tmp) + 20);
     iso2wc_strcpy (real_dir, tmp);
     HT_FREE (tmp);
   
     /* safeguard... abort the operation if cache_dir doesn't end with
        CACHE_DIR_NAME */
     error = TRUE;
     ptr = strstr (real_dir, CACHE_DIR_NAME);  
       if (ptr && *ptr && !strcasecmp (ptr, CACHE_DIR_NAME))
         error = FALSE;
     if (error)
       return;  
     
     /* remove the concurrent cache lock */
   #ifdef DEBUG_LIBWWW
     fprintf (stderr, "Clearing the cache lock\n");
   #endif /* DEBUG_LIBWWW */
     clear_cachelock ();
     HTCacheTerminate ();
     HTCacheMode_setEnabled (FALSE);
     
     RecCleanCache (real_dir);
   
     HTCacheMode_setExpires (cache_expire);
     HTCacheMode_setDisconnected (cache_disconnect);
     HTCacheInit (cache_dir, cache_size);
     /* set a new concurrent cache lock */
     strcat (real_dir, ".lock");
     if (set_cachelock (real_dir) == -1)
       /* couldn't open the .lock file, so, we close the cache to
          be in the safe side */
       {
   #ifdef DEBUG_LIBWWW
         fprintf (stderr, "couldnt set the cache lock\n");
   #endif /* DEBUG_LIBWWW */
         HTCacheTerminate ();
         HTCacheMode_setEnabled (FALSE);
       }
   #ifdef DEBUG_LIBWWW
     fprintf (stderr, "set a cache lock\n");
   #endif /* DEBUG_LIBWWW */
     TtaFreeMemory (real_dir);
     TtaFreeMemory (cache_dir);
 #endif /* AMAYA_WWW_CACHE */  #endif /* AMAYA_WWW_CACHE */
   }
   
 /*----------------------------------------------------------------------  /*----------------------------------------------------------------------
   CacheInit    CacheInit
   Reads the cache settings from the thot.ini file.    Reads the cache settings from the thot.ini file.
   ----------------------------------------------------------------------*/    ----------------------------------------------------------------------*/
 #ifdef __STDC__  
 static void CacheInit (void)  static void CacheInit (void)
 #else  
 static void Cacheinit ()  
 #endif  
   
 {  {
 #ifndef AMAYA_WWW_CACHE  #ifndef AMAYA_WWW_CACHE
    HTCacheMode_setEnabled (NO);     HTCacheMode_setEnabled (NO);
   
 #else /* AMAYA_WWW_CACHE */  #else /* AMAYA_WWW_CACHE */
   CHAR_T* strptr;    char     *strptr;
   CHAR_T* real_dir = NULL;    char     *real_dir = NULL;
   CHAR_T* cache_lockfile;    char     *cache_lockfile;
   char      www_realDir[MAX_LENGTH];    char     *cache_dir = NULL;
   char*     cache_dir = NULL;  
   int       cache_size;    int       cache_size;
   int       cache_entry_size;    int       cache_entry_size;
   ThotBool  cache_enabled;    ThotBool  cache_enabled;
Line 1942  int i; Line 1899  int i;
   
   /* activate cache? */    /* activate cache? */
   strptr = TtaGetEnvString ("ENABLE_CACHE");    strptr = TtaGetEnvString ("ENABLE_CACHE");
   if (strptr && *strptr && ustrcasecmp (strptr, TEXT("yes")))    if (strptr && *strptr && strcasecmp (strptr, "yes"))
     cache_enabled = NO;      cache_enabled = NO;
   else    else
     cache_enabled = YES;      cache_enabled = YES;
   
   /* cache protected documents? */    /* cache protected documents? */
   strptr = TtaGetEnvString ("CACHE_PROTECTED_DOCS");    strptr = TtaGetEnvString ("CACHE_PROTECTED_DOCS");
   if (strptr && *strptr && !ustrcasecmp (strptr, TEXT("yes")))    if (strptr && *strptr && !strcasecmp (strptr, "yes"))
     HTCacheMode_setProtected (YES);      HTCacheMode_setProtected (YES);
   else    else
     HTCacheMode_setProtected (NO);      HTCacheMode_setProtected (NO);
Line 1958  int i; Line 1915  int i;
   strptr = TtaGetEnvString ("CACHE_DIR");    strptr = TtaGetEnvString ("CACHE_DIR");
   if (strptr && *strptr)     if (strptr && *strptr) 
     {      {
       real_dir = TtaAllocString (ustrlen (strptr) + ustrlen (CACHE_DIR_NAME) + 20);        real_dir = TtaGetMemory (strlen (strptr) + strlen (CACHE_DIR_NAME) + 20);
       ustrcpy (real_dir, strptr);        strcpy (real_dir, strptr);
           if (*(real_dir + ustrlen (real_dir) - 1) != WC_DIR_SEP)        if (*(real_dir + strlen (real_dir) - 1) != WC_DIR_SEP)
             ustrcat (real_dir, WC_DIR_STR);          strcat (real_dir, WC_DIR_STR);
     }      }
   else    else
     {      {
       real_dir = TtaAllocString (ustrlen (TempFileDirectory) + ustrlen (CACHE_DIR_NAME) + 20);        real_dir = TtaGetMemory (strlen (TempFileDirectory) + strlen (CACHE_DIR_NAME) + 20);
       usprintf (real_dir, TEXT("%s%s"), TempFileDirectory, CACHE_DIR_NAME);        usprintf (real_dir, "%s%s", TempFileDirectory, CACHE_DIR_NAME);
     }      }
   
   /* compatiblity with previous versions of Amaya: does real_dir    /* compatiblity with previous versions of Amaya: does real_dir
      include CACHE_DIR_NAME? If not, add it */       include CACHE_DIR_NAME? If not, add it */
   strptr = ustrstr (real_dir, CACHE_DIR_NAME);    strptr = strstr (real_dir, CACHE_DIR_NAME);
   if (!strptr)    if (!strptr)
     ustrcat (real_dir, CACHE_DIR_NAME);      strcat (real_dir, CACHE_DIR_NAME);
   else    else
     {      {
       i = ustrlen (CACHE_DIR_NAME);        i = strlen (CACHE_DIR_NAME);
           if (strptr[i] != WC_EOS)            if (strptr[i] != WC_EOS)
           ustrcat (real_dir, CACHE_DIR_NAME);            strcat (real_dir, CACHE_DIR_NAME);
     }      }
   
   /* convert the local cache dir into a file URL, as expected by    /* convert the local cache dir into a file URL, as expected by
      libwww */       libwww */
      cache_dir = HTLocalToWWW (real_dir, "file:");
   wc2iso_strcpy (www_realDir, real_dir);  
   
   cache_dir = HTLocalToWWW (www_realDir, "file:");  
   
   /* get the cache size (or use a default one) */    /* get the cache size (or use a default one) */
   strptr = TtaGetEnvString ("CACHE_SIZE");    strptr = TtaGetEnvString ("CACHE_SIZE");
   if (strptr && *strptr)     if (strptr && *strptr) 
     cache_size = uatoi (strptr);      cache_size = uatoi (strptr);
   else    else
     cache_size = DEFAULT_CACHE_SIZE;      cache_size = DEFAULT_CACHE_SIZE;
   
   /* get the max cached file size (or use a default one) */    /* get the max cached file size (or use a default one) */
   if (!TtaGetEnvInt ("MAX_CACHE_ENTRY_SIZE", &cache_entry_size))    if (!TtaGetEnvInt ("MAX_CACHE_ENTRY_SIZE", &cache_entry_size))
     cache_entry_size = DEFAULT_MAX_CACHE_ENTRY_SIZE;      cache_entry_size = DEFAULT_MAX_CACHE_ENTRY_SIZE;
   
   if (cache_enabled)     if (cache_enabled) 
     {      {
       /* how to remove the lock? force remove it? */        /* how to remove the lock? force remove it? */
       cache_lockfile = TtaAllocString (ustrlen (real_dir) + 20);        cache_lockfile = TtaGetMemory (strlen (real_dir) + 20);
       ustrcpy (cache_lockfile, real_dir);        strcpy (cache_lockfile, real_dir);
       ustrcat (cache_lockfile, TEXT(".lock"));        strcat (cache_lockfile, ".lock");
       cache_locked = FALSE;        cache_locked = FALSE;
       if (TtaFileExist (cache_lockfile) && !(cache_locked = test_cachelock (cache_lockfile)))        if (TtaFileExist (cache_lockfile) && !(cache_locked = test_cachelock (cache_lockfile)))
         {          {
Line 2014  int i; Line 1965  int i;
           /* remove the lock and clean the cache (the clean cache             /* remove the lock and clean the cache (the clean cache 
              will remove all, making the following call unnecessary */               will remove all, making the following call unnecessary */
           /* little trick to win some memory */            /* little trick to win some memory */
           strptr = ustrrchr (cache_lockfile, TEXT('.'));            strptr = strrchr (cache_lockfile, '.');
           *strptr = WC_EOS;            *strptr = WC_EOS;
           RecCleanCache (cache_lockfile);            RecCleanCache (cache_lockfile);
           *strptr = TEXT('.');            *strptr = '.';
         }          }
   
       if (!cache_locked)         if (!cache_locked) 
Line 2078  int i; Line 2029  int i;
     TtaFreeMemory (real_dir);      TtaFreeMemory (real_dir);
   /* warn the user if the cache isn't active */    /* warn the user if the cache isn't active */
   if (cache_enabled && !HTCacheMode_enabled ())    if (cache_enabled && !HTCacheMode_enabled ())
       InitInfo (TEXT("Cache"), TtaGetMessage (AMAYA, AM_CANT_CREATE_CACHE));        InitInfo ("Cache", TtaGetMessage (AMAYA, AM_CANT_CREATE_CACHE));
 #endif /* AMAYA_WWW_CACHE */  #endif /* AMAYA_WWW_CACHE */
 }  }
   
Line 2087  int i; Line 2038  int i;
   Reads any proxies settings which may be declared as environmental    Reads any proxies settings which may be declared as environmental
   variables or in the thot.ini file. The former overrides the latter.    variables or in the thot.ini file. The former overrides the latter.
   ----------------------------------------------------------------------*/    ----------------------------------------------------------------------*/
 #ifdef __STDC__  
 static void ProxyInit (void)  static void ProxyInit (void)
 #else  
 static void ProxyInit ()  
 #endif /* __STDC__ */  
 {  {
   CHAR_T*   strptr;    char     *strptr;
   char*     name;    char     *name;
     char     *tmp = NULL;
     char     *strptrA;
   ThotBool  proxy_is_onlyproxy;    ThotBool  proxy_is_onlyproxy;
   char*     tmp = NULL;  
   char*     strptrA;  
   
   /* get the proxy settings from the thot.ini file */    /* get the proxy settings from the thot.ini file */
   strptr = TtaGetEnvString ("HTTP_PROXY");    strptr = TtaGetEnvString ("HTTP_PROXY");
   if (strptr && *strptr)    if (strptr && *strptr)
     {      {
       tmp = (char*) TtaGetMemory (ustrlen (strptr) + 1);        tmp = (char *) TtaGetMemory (strlen (strptr) + 1);
       wc2iso_strcpy (tmp, strptr);        strcpy (tmp, strptr);
   
       /* does the proxy env string has an "http://" prefix? */        /* does the proxy env string has an "http://" prefix? */
       if (!ustrncasecmp (strptr, TEXT("http://"), 7))         if (!strncasecmp (strptr, "http://", 7)) 
         HTProxy_add ("http", tmp);          HTProxy_add ("http", tmp);
       else         else 
         {          {
           strptrA = (char*) TtaGetMemory (ustrlen (strptr) + 9);            strptrA = (char *) TtaGetMemory (strlen (strptr) + 9);
           strcpy (strptrA, "http://");            strcpy (strptrA, "http://");
           strcat (strptrA, tmp);            strcat (strptrA, tmp);
           HTProxy_add ("http", strptrA);            HTProxy_add ("http", strptrA);
Line 2124  static void ProxyInit () Line 2071  static void ProxyInit ()
   strptr = TtaGetEnvString ("PROXYDOMAIN");    strptr = TtaGetEnvString ("PROXYDOMAIN");
   if (strptr && *strptr)     if (strptr && *strptr) 
     {      {
       strptrA = (char*) TtaGetMemory (ustrlen (strptr) + 1);        strptrA = (char *) TtaGetMemory (strlen (strptr) + 1);
       wc2iso_strcpy (strptrA, strptr);        tmp = strptrA;
         strcpy (tmp, strptr);
       /* as HTNextField changes the ptr we pass as an argument, we'll        /* as HTNextField changes the ptr we pass as an argument, we'll
          work with another variable, so that we can free the strptrA           work with another variable, so that we can free the tmp
          block later on */           block later on */
       tmp = strptrA;  
       while ((name = HTNextField (&tmp)) != NULL)         while ((name = HTNextField (&tmp)) != NULL) 
         {          {
           char* portstr = strchr (name, ':');            char* portstr = strchr (name, ':');
           unsigned port=0;            unsigned port=0;
           if (portstr) {             if (portstr)
             *portstr++ = EOS;              { 
             if (*portstr)                 *portstr++ = EOS;
               port = (unsigned) atoi (portstr);                if (*portstr) 
           }                  port = (unsigned) atoi (portstr);
               }
           /* Register it for all access methods */            /* Register it for all access methods */
           HTNoProxy_add (name, NULL, port);            HTNoProxy_add (name, NULL, port);
         }          }
Line 2154  static void ProxyInit () Line 2102  static void ProxyInit ()
 }  }
   
 /*----------------------------------------------------------------------  /*----------------------------------------------------------------------
   SafePut_init  
   Sets up the domains which are authorized to make a redirect on   
   a PUT.  
   ----------------------------------------------------------------------*/  
 #ifdef __STDC__  
 static void SafePut_init (void)  
 #else  
 static void SafePut_init ()  
 #endif /* __STDC__ */  
 {  
   CHAR_T* strptr;  
   CHAR_T* str = NULL;  
   char*     ptr, *strptrA, *ptr2;  
   char*     domain;  
   
   /* get the proxy settings from the thot.ini file */  
   strptr = TtaGetEnvString ("SAFE_PUT_REDIRECT");  
   if (strptr && *strptr)  
     {  
       /* Get copy we can mutilate */  
       strptrA = (char*) TtaGetMemory (ustrlen (strptr) + 1);  
       wc2iso_strcpy (strptrA, strptr);  
       ptr2 = strptrA;  
       /* convert to lowercase */  
       ptr = strptrA;  
       while (*ptr)   
         {  
           *ptr = tolower (*ptr);  
           ptr++;  
         }  
         
       /* create the list container */  
       safeput_list = HTList_new ();     
       /* store the domain list */  
   
       ptr = strptrA;  
       while ((domain = HTNextField (&strptrA)) != NULL)  
           HTList_addObject (safeput_list, TtaStrdup (domain));   
   
       TtaFreeMemory (str);  
       TtaFreeMemory (ptr2);  
     }  
 }  
   
 /*----------------------------------------------------------------------  
   SafePut_delete  
   Deletes the safeput_list variable  
   ----------------------------------------------------------------------*/  
 static void SafePut_delete (void)  
 {  
   HTList *cur = safeput_list;  
   char *domain;  
   
   if (!safeput_list)   
     return;  
   
   while ((domain = (char *) HTList_nextObject (cur)))   
       TtaFreeMemory (domain);  
    HTList_delete (safeput_list);  
    safeput_list = NULL;  
 }  
   
 /*----------------------------------------------------------------------  
   SafePut_query  
   returns true if the domain to which belongs the URL accepts an automatic  
   PUT redirect.  
   ----------------------------------------------------------------------*/  
 static ThotBool SafePut_query (CHAR_T* url)  
 {  
   HTList*  cur;  
   char*    me;  
   ThotBool found;  
   CHAR_T   tmp[MAX_LENGTH];  
   
   /* extract the domain path of the url and normalize it */  
   /* domain = url; */  
   cur = safeput_list;  
   found = FALSE;  
   
   while ((me = (char*) HTList_nextObject (cur))) {  
         iso2wc_strcpy (tmp, me);  
         if (ustrstr (url, tmp)) {  
            found = TRUE;  
            break;  
                 }   
   }   
   
   return (found);  
 }  
   
 /*----------------------------------------------------------------------  
   AHTProfile_newAmaya    AHTProfile_newAmaya
   creates the Amaya client profile for libwww.    creates the Amaya client profile for libwww.
   ----------------------------------------------------------------------*/    ----------------------------------------------------------------------*/
 #ifdef __STDC__  static void AHTProfile_newAmaya (char *AppName, char *AppVersion)
 static void         AHTProfile_newAmaya (CHAR_T* AppName, CHAR_T* AppVersion)  
 #else  /* __STDC__ */  
 static void         AHTProfile_newAmaya (AppName, AppVersion)  
 char* AppName;  
 char* AppVersion;  
 #endif /* __STDC__ */  
 {  {
    CHAR_T* strptr;     char *strptr;
 #ifdef _I18N_  #ifdef _I18N_
    unsigned char mbAppName[MAX_LENGTH], mbAppVersion[MAX_LENGTH];     unsigned char mbAppName[MAX_LENGTH], mbAppVersion[MAX_LENGTH];
 #else  /* !_I18N_ */  #else  /* !_I18N_ */
Line 2320  char* AppVersion; Line 2171  char* AppVersion;
    HTAA_newModule ("basic", HTBasic_generate, HTBasic_parse, NULL, HTBasic_delete);     HTAA_newModule ("basic", HTBasic_generate, HTBasic_parse, NULL, HTBasic_delete);
    /* activate MDA by defaul */     /* activate MDA by defaul */
    strptr = TtaGetEnvString ("ENABLE_MDA");     strptr = TtaGetEnvString ("ENABLE_MDA");
    if (!strptr || (strptr && *strptr && ustrcasecmp (strptr, TEXT("no"))))     if (!strptr || (strptr && *strptr && strcasecmp (strptr, "no")))
      HTAA_newModule ("digest", HTDigest_generate, HTDigest_parse, HTDigest_updateInfo, HTDigest_delete);       HTAA_newModule ("digest", HTDigest_generate, HTDigest_parse, HTDigest_updateInfo, HTDigest_delete);
         
    /* Get any proxy settings */     /* Get any proxy settings */
Line 2362  char* AppVersion; Line 2213  char* AppVersion;
   AHTProfile_delete    AHTProfile_delete
   deletes the Amaya client profile.    deletes the Amaya client profile.
   ----------------------------------------------------------------------*/    ----------------------------------------------------------------------*/
 #ifdef __STDC__  
 static void         AHTProfile_delete (void)  static void         AHTProfile_delete (void)
 #else  
 static void         AHTProfile_delete ()  
 #endif                          /* __STDC__ */  
 {  {
    
   /* free the Amaya global context */    /* free the Amaya global context */
   
   /* Clean up all the registred converters */    /* Clean up all the registred converters */
   HTFormat_deleteAll ();    HTFormat_deleteAll ();
   if (acceptTypes)    if (acceptTypes)
Line 2417  static void         AHTProfile_delete () Line 2262  static void         AHTProfile_delete ()
   AmayacontextInit    AmayacontextInit
   initializes an internal Amaya context for our libwww interface     initializes an internal Amaya context for our libwww interface 
   ----------------------------------------------------------------------*/    ----------------------------------------------------------------------*/
 #ifdef __STDC__  static void    AmayaContextInit ()
 static void                AmayaContextInit ()  
 #else  
 static void                AmayaContextInit ()  
 #endif  
   
 {  {
   AmayaAlive_flag = TRUE;    AmayaAlive_flag = TRUE;
   /* Initialization of the global context */    /* Initialization of the global context */
Line 2436  static void                AmayaContextI Line 2276  static void                AmayaContextI
   QueryInit    QueryInit
   initializes the libwww interface     initializes the libwww interface 
   ----------------------------------------------------------------------*/    ----------------------------------------------------------------------*/
 #ifdef __STDC__  void         QueryInit ()
 void                QueryInit ()  
 #else  
 void                QueryInit ()  
 #endif  
 {  {
   CHAR_T* strptr;    char   *strptr;
   int tmp_i;    int     tmp_i;
   long tmp_l;    long    tmp_l;
   
    AmayaContextInit ();     AmayaContextInit ();
    AHTProfile_newAmaya (HTAppName, HTAppVersion);     AHTProfile_newAmaya (HTAppName, HTAppVersion);
Line 2516  void                QueryInit () Line 2352  void                QueryInit ()
        if (WWW_TraceFlag)         if (WWW_TraceFlag)
          {           {
            /* Trace activation (for debugging) */             /* Trace activation (for debugging) */
            CHAR_T *s, *tmp;             char   *s, *tmp;
            s = TtaGetEnvString ("APP_TMPDIR");             s = TtaGetEnvString ("APP_TMPDIR");
            tmp = TtaGetMemory (ustrlen (s) + sizeof (TEXT("/libwww.log")) + 1);             tmp = TtaGetMemory (strlen (s) + sizeof ("/libwww.log") + 1);
            ustrcpy (tmp, s);             strcpy (tmp, s);
            ustrcat (tmp, TEXT("/libwww.log"));             strcat (tmp, "/libwww.log");
            trace_fp = ufopen (tmp, TEXT("ab"));             trace_fp = fopen (tmp, "ab");
            TtaFreeMemory (tmp);             TtaFreeMemory (tmp);
            if (trace_fp)             if (trace_fp)
              HTTrace_setCallback(LineTrace);               HTTrace_setCallback(LineTrace);
Line 2589  void                QueryInit () Line 2425  void                QueryInit ()
   a copy of the Thop event loop so we can handle the stop button in Unix    a copy of the Thop event loop so we can handle the stop button in Unix
   and preemptive requests under Windows    and preemptive requests under Windows
   ----------------------------------------------------------------------*/    ----------------------------------------------------------------------*/
 #ifdef __STDC__  
 static int          LoopForStop (AHTReqContext * me)  
 #else  
 static int          LoopForStop (AHTReqContext * me)  static int          LoopForStop (AHTReqContext * me)
 #endif  
 {  {
 #ifdef _WINDOWS  #ifdef _WINDOWS
   MSG msg;    MSG msg;
Line 2694  void QueryClose () Line 2526  void QueryClose ()
 /*----------------------------------------------------------------------  /*----------------------------------------------------------------------
   NextNameValue    NextNameValue
   ---------------------------------------------------------------------*/    ---------------------------------------------------------------------*/
 #ifdef __STDC__  static char * NextNameValue (char **pstr, char **name, char **value)
 static char * NextNameValue (char ** pstr, char **name, char **value)  
 #else  
 static char * NextNameValue (pstr, name, value);  
 char ** pstr;  
 char **name;  
 char **value;  
 #endif /* __STDC__ */  
 {  {
   char * p = *pstr;    char * p = *pstr;
   char * start = NULL;    char * start = NULL;
Line 2737  char **value; Line 2562  char **value;
 /*----------------------------------------------------------------------  /*----------------------------------------------------------------------
   PrepareFormdata    PrepareFormdata
   ---------------------------------------------------------------------*/    ---------------------------------------------------------------------*/
 #ifdef __STDC__  static   HTAssocList * PrepareFormdata (char *string)
 static   HTAssocList * PrepareFormdata (CHAR_T* string)  
 #else  
 static   HTAssocList * PrepareFormdata (string)  
 CHAR_T*  string;  
 #endif /* __STDC__ */  
 {  {
   char*        tmp_string, *tmp_string_ptr;    char*        tmp_string, *tmp_string_ptr;
   char*        name;    char*        name;
Line 2756  CHAR_T*  string; Line 2576  CHAR_T*  string;
      change       change
      */       */
       
   tmp_string_ptr = TtaGetMemory (ustrlen (string) + 1);    tmp_string_ptr = TtaGetMemory (strlen (string) + 1);
   tmp_string = tmp_string_ptr;    tmp_string = tmp_string_ptr;
   wc2iso_strcpy (tmp_string_ptr, string);    wc2iso_strcpy (tmp_string_ptr, string);
   formdata = HTAssocList_new();    formdata = HTAssocList_new();
Line 2774  CHAR_T*  string; Line 2594  CHAR_T*  string;
   
 /*----------------------------------------------------------------------  /*----------------------------------------------------------------------
   ---------------------------------------------------------------------*/    ---------------------------------------------------------------------*/
 #ifdef __STDC__  
 void AHTRequest_setCustomAcceptHeader (HTRequest *request, char *value)  void AHTRequest_setCustomAcceptHeader (HTRequest *request, char *value)
 #else  
 void AHTRequest_setCustomAcceptHeader (request, value)  
 HTRequest *request;  
 char *value;  
 #endif /* __STDC__ */  
 {                                 {                               
   HTRqHd rqhd = HTRequest_rqHd (request);    HTRqHd rqhd = HTRequest_rqHd (request);
   rqhd = rqhd & (~HT_C_ACCEPT_TYPE);    rqhd = rqhd & (~HT_C_ACCEPT_TYPE);
Line 2793  char *value; Line 2607  char *value;
   A simple function to invoke a callback function whenever there's an error    A simple function to invoke a callback function whenever there's an error
   in GetObjectWWW    in GetObjectWWW
   ---------------------------------------------------------------------*/    ---------------------------------------------------------------------*/
   void InvokeGetObjectWWW_callback (int docid, char *urlName,
 #ifdef __STDC__                                    char *outputfile, TTcbf *terminate_cbf,
 void      InvokeGetObjectWWW_callback (int docid, STRING urlName, STRING outputfile, TTcbf *terminate_cbf, void *context_tcbf, int status)                                    void *context_tcbf, int status)
 #else  
 void      InvokeGetObjectWWW_callback (docid, urlName, outputfile, terminate_cbf, context_tcbf, status)  
 int docid;  
 STRING urlName;  
 STRING outputfile;  
 TTcbf *terminate_cbf;  
 void *context_tcbf;  
 #endif /* __STDC__ */  
 {  {
   if (!terminate_cbf)    if (!terminate_cbf)
     return;      return;
Line 2875  void *context_tcbf; Line 2681  void *context_tcbf;
    HT_OK     HT_OK
     
   ----------------------------------------------------------------------*/    ----------------------------------------------------------------------*/
 #ifdef __STDC__  int GetObjectWWW (int docid, char *urlName, char *formdata,
 int GetObjectWWW (int docid, STRING urlName, STRING formdata,                    char *outputfile, int mode, TIcbf *incremental_cbf, 
                   STRING outputfile, int mode, TIcbf* incremental_cbf,                     void *context_icbf, TTcbf *terminate_cbf, 
                   void* context_icbf, TTcbf* terminate_cbf,                     void *context_tcbf, ThotBool error_html, char *content_type)
                   void* context_tcbf, ThotBool error_html, STRING content_type)  
 #else  
 int GetObjectWWW (docid, urlName, formdata, outputfile, mode,   
                   incremental_cbf, context_icbf,   
                   terminate_cbf, context_tcbf, error_html, content_type)  
 int           docid;  
 CHAR_T*       urlName;  
 CHAR_T*       formdata;  
 CHAR_T*       outputfile;  
 int           mode;  
 TIcbf        *incremental_cbf;  
 void         *context_icbf;  
 TTcbf        *terminate_cbf;  
 void         *context_tcbf;  
 ThotBool      error_html;  
 CHAR_T*       content_type;  
 #endif  
 {  {
    AHTReqContext      *me;     AHTReqContext      *me;
    CHAR_T*             ref;     char *            ref;
    CHAR_T*             esc_url;     char *            esc_url;
    char                urlRef[MAX_LENGTH];  
    int                 status, l;     int                 status, l;
    int                 tempsubdir;     int                 tempsubdir;
    ThotBool            bool_tmp;     ThotBool            bool_tmp;
Line 2919  CHAR_T*       content_type; Line 2707  CHAR_T*       content_type;
      }       }
   
    /* if it's a 'docImage', we have already downloaded it */     /* if it's a 'docImage', we have already downloaded it */
    if (!ustrncmp (TEXT("internal:"), urlName, 9))      if (!strncmp ("internal:", urlName, 9)) 
      {       {
        ustrcpy (outputfile, urlName);         strcpy (outputfile, urlName);
        InvokeGetObjectWWW_callback (docid, urlName, outputfile,         InvokeGetObjectWWW_callback (docid, urlName, outputfile,
                                     terminate_cbf, context_tcbf, HT_OK);                                      terminate_cbf, context_tcbf, HT_OK);
        return HT_OK;         return HT_OK;
Line 2950  CHAR_T*       content_type; Line 2738  CHAR_T*       content_type;
    tempsubdir = (mode & AMAYA_LOAD_CSS) ? 0 : docid;     tempsubdir = (mode & AMAYA_LOAD_CSS) ? 0 : docid;
   
    /* create a tempfilename */     /* create a tempfilename */
    usprintf (outputfile, TEXT("%s%c%d%c%04dAM"), TempFileDirectory, WC_DIR_SEP, tempsubdir, WC_DIR_SEP, object_counter);     usprintf (outputfile, "%s%c%d%c%04dAM", TempFileDirectory, WC_DIR_SEP, tempsubdir, WC_DIR_SEP, object_counter);
    /* update the object_counter (used for the tempfilename) */     /* update the object_counter (used for the tempfilename) */
    object_counter++;     object_counter++;
         
Line 2958  CHAR_T*       content_type; Line 2746  CHAR_T*       content_type;
    esc_url = EscapeURL (urlName);     esc_url = EscapeURL (urlName);
    if (esc_url)      if (esc_url) 
      {       {
        ref = AmayaParseUrl (esc_url, TEXT(""), AMAYA_PARSE_ALL);         ref = AmayaParseUrl (esc_url, "", AMAYA_PARSE_ALL);
        TtaFreeMemory (esc_url);         TtaFreeMemory (esc_url);
      }       }
    else     else
Line 3048  CHAR_T*       content_type; Line 2836  CHAR_T*       content_type;
   
    if ((mode & AMAYA_ASYNC) || (mode & AMAYA_IASYNC))      if ((mode & AMAYA_ASYNC) || (mode & AMAYA_IASYNC)) 
      {       {
        l = ustrlen (outputfile);         l = strlen (outputfile);
        if (l > MAX_LENGTH)         if (l > MAX_LENGTH)
          me->outputfile = TtaAllocString (l + 2);           me->outputfile = TtaGetMemory (l + 2);
        else         else
          me->outputfile = TtaAllocString (MAX_LENGTH + 2);           me->outputfile = TtaGetMemory (MAX_LENGTH + 2);
        ustrcpy (me->outputfile, outputfile);         strcpy (me->outputfile, outputfile);
        l = ustrlen (urlName);         l = strlen (urlName);
        if (l > MAX_LENGTH)         if (l > MAX_LENGTH)
          me->urlName = TtaAllocString (l + 2);           me->urlName = TtaGetMemory (l + 2);
        else         else
          me->urlName = TtaAllocString (MAX_LENGTH + 2);           me->urlName = TtaGetMemory (MAX_LENGTH + 2);
        ustrcpy (me->urlName, urlName);         strcpy (me->urlName, urlName);
 #ifdef _WINDOWS  #ifdef _WINDOWS
      /* force windows ASYNC requests to always be non preemptive */       /* force windows ASYNC requests to always be non preemptive */
      HTRequest_setPreemptive (me->request, NO);       HTRequest_setPreemptive (me->request, NO);
Line 3101  CHAR_T*       content_type; Line 2889  CHAR_T*       content_type;
                  TtaGetMessage (AMAYA, AM_FETCHING),                   TtaGetMessage (AMAYA, AM_FETCHING),
                  me->status_urlName);                   me->status_urlName);
   
    wc2iso_strcpy (urlRef, ref);     me->anchor = (HTParentAnchor *) HTAnchor_findAddress (ref);
    me->anchor = (HTParentAnchor *) HTAnchor_findAddress (urlRef);  
    TtaFreeMemory (ref);     TtaFreeMemory (ref);
         
    TtaGetEnvBoolean ("CACHE_DISCONNECTED_MODE", &bool_tmp);     TtaGetEnvBoolean ("CACHE_DISCONNECTED_MODE", &bool_tmp);
Line 3264  CHAR_T*       content_type; Line 3051  CHAR_T*       content_type;
    HT_ERROR     HT_ERROR
    HT_OK     HT_OK
   ----------------------------------------------------------------------*/    ----------------------------------------------------------------------*/
 #ifdef __STDC__  int PutObjectWWW (int docid, char *fileName, char *urlName, int mode,
 int                 PutObjectWWW (int docid, STRING fileName, STRING urlName, int mode, PicType contentType,                    PicType contentType,
                                   TTcbf * terminate_cbf, void *context_tcbf)                    TTcbf *terminate_cbf, void *context_tcbf)
 #else  
 int                 PutObjectWWW (docid, urlName, fileName, mode, contentType,  
                                   ,terminate_cbf, context_tcbf)  
 int                 docid;  
 STRING              urlName;  
 STRING              fileName;  
 int                 mode;  
 PicType             contentType;  
 TTcbf              *terminate_cbf;  
 void               *context_tcbf;  
   
 #endif /* __STDC__ */  
 {  {
    AHTReqContext      *me;     AHTReqContext      *me;
    CHARSET             charset;     CHARSET             charset;
Line 3287  void               *context_tcbf; Line 3062  void               *context_tcbf;
    char               *fileURL;     char               *fileURL;
    char               *etag = NULL;     char               *etag = NULL;
    HTParentAnchor     *dest_anc_parent;     HTParentAnchor     *dest_anc_parent;
    CHAR_T*             tmp;     char               *tmp;
    CHAR_T*             esc_url;     char               *esc_url;
    int                 UsePreconditions;     int                 UsePreconditions;
    ThotBool            lost_update_check = TRUE;     ThotBool            lost_update_check = TRUE;
    char                url_name[MAX_LENGTH];     char                url_name[MAX_LENGTH];
    char*               tmp2;     char               *tmp2;
 #ifdef _WINDOWS  #ifdef _WINDOWS
    char                file_name[MAX_LENGTH];     char                file_name[MAX_LENGTH];
 #endif /* _WINDOWS */  #endif /* _WINDOWS */
   
    /* should we protect the PUT against lost updates? */     /* should we protect the PUT against lost updates? */
    tmp = TtaGetEnvString ("ENABLE_LOST_UPDATE_CHECK");     tmp = TtaGetEnvString ("ENABLE_LOST_UPDATE_CHECK");
    if (tmp && *tmp && ustrcasecmp (tmp, TEXT("yes")))     if (tmp && *tmp && strcasecmp (tmp, "yes"))
      lost_update_check = FALSE;       lost_update_check = FALSE;
   
    UsePreconditions = mode & AMAYA_USE_PRECONDITIONS;     UsePreconditions = mode & AMAYA_USE_PRECONDITIONS;
Line 3346  void               *context_tcbf; Line 3121  void               *context_tcbf;
    */     */
    if (DocumentMeta[docid]->put_default_name)     if (DocumentMeta[docid]->put_default_name)
      {       {
        CHAR_T *ptr1, *ptr2;         char   *ptr1, *ptr2;
        ptr1 = TtaGetEnvString ("DEFAULTNAME");         ptr1 = TtaGetEnvString ("DEFAULTNAME");
        if (ptr1 && *ptr1)          if (ptr1 && *ptr1) 
          {           {
            ptr2 = ustrstr (urlName, ptr1);             ptr2 = strstr (urlName, ptr1);
            if (ptr2)              if (ptr2) 
              {               {
            wc2iso_strcpy (url_name, urlName);             wc2iso_strcpy (url_name, urlName);
                me->default_put_name = TtaStrdup (url_name);                 me->default_put_name = TtaStrdup (url_name);
                me->default_put_name[strlen (me->default_put_name) - ustrlen (ptr1)] = EOS;                 me->default_put_name[strlen (me->default_put_name) - strlen (ptr1)] = EOS;
                HTRequest_setDefaultPutName (me->request, me->default_put_name);                 HTRequest_setDefaultPutName (me->request, me->default_put_name);
              }               }
          }           }
Line 3374  void               *context_tcbf; Line 3149  void               *context_tcbf;
    me->method = METHOD_PUT;     me->method = METHOD_PUT;
    me->output = stdout;     me->output = stdout;
    /* we are not expecting to receive any input from the server */     /* we are not expecting to receive any input from the server */
    me->outputfile = (CHAR_T*) NULL;      me->outputfile = (char  *) NULL; 
   
 #ifdef _WINDOWS  #ifdef _WINDOWS
    /* libwww's HTParse function doesn't take into account the drive name;     /* libwww's HTParse function doesn't take into account the drive name;
Line 3527  void               *context_tcbf; Line 3302  void               *context_tcbf;
   StopRequest    StopRequest
   stops (kills) all active requests associated with a docid     stops (kills) all active requests associated with a docid 
   ----------------------------------------------------------------------*/    ----------------------------------------------------------------------*/
 #ifdef __STDC__  
 void                StopRequest (int docid)  void                StopRequest (int docid)
 #else  
 void                StopRequest (docid)  
 int                 docid;  
 #endif  
 {  {
    if (Amaya && CanDoStop ())     if (Amaya && CanDoStop ())
      {        { 
Line 3554  int                 docid; Line 3324  int                 docid;
   StopAllRequests    StopAllRequests
   stops (kills) all active requests. We use the docid     stops (kills) all active requests. We use the docid 
   ----------------------------------------------------------------------*/    ----------------------------------------------------------------------*/
 #ifdef __STDC__  
 void                StopAllRequests (int docid)  void                StopAllRequests (int docid)
 #else  
 void                StopAllRequests (docid)  
 int                 docid;  
 #endif  
 {  {
    HTList             *cur;     HTList             *cur;
    AHTReqContext      *me;     AHTReqContext      *me;
Line 3581  int                 docid; Line 3346  int                 docid;
           processing easier */            processing easier */
        UserAborted_flag = TRUE;         UserAborted_flag = TRUE;
        /* abort all outstanding libwww UI dialogues */         /* abort all outstanding libwww UI dialogues */
        CallbackDialogue (BaseDialog + FormAnswer,  STRING_DATA, (CHAR_T*) 0);         CallbackDialogue (BaseDialog + FormAnswer,  STRING_DATA, NULL);
        CallbackDialogue (BaseDialog + ConfirmForm, INTEGER_DATA, (CHAR_T*) 0);         CallbackDialogue (BaseDialog + ConfirmForm, INTEGER_DATA, NULL);
        /* expire all outstanding timers */         /* expire all outstanding timers */
        HTTimer_expireAll ();         HTTimer_expireAll ();
        /* HTNet_killAll (); */         /* HTNet_killAll (); */
Line 3661  int                 docid; Line 3426  int                 docid;
   AmayaIsAlive    AmayaIsAlive
   returns the value of the AmayaAlive_flag    returns the value of the AmayaAlive_flag
   ----------------------------------------------------------------------*/    ----------------------------------------------------------------------*/
 #ifdef __STDC__  
 ThotBool AmayaIsAlive (void)  ThotBool AmayaIsAlive (void)
 #else  
 ThotBool AmayaIsAlive ()  
 #endif /* _STDC_ */  
 {  {
   return AmayaAlive_flag;    return AmayaAlive_flag;
 }  }
Line 3674  ThotBool AmayaIsAlive () Line 3435  ThotBool AmayaIsAlive ()
   CanDoStop    CanDoStop
   returns the value of the CanDoStop flag    returns the value of the CanDoStop flag
   ----------------------------------------------------------------------*/    ----------------------------------------------------------------------*/
 #ifdef __STDC__  
 ThotBool CanDoStop (void)  ThotBool CanDoStop (void)
 #else  
 ThotBool CanDoStop ()  
 #endif /* _STDC_ */  
 {  {
   return CanDoStop_flag;    return CanDoStop_flag;
 }  }
Line 3687  ThotBool CanDoStop () Line 3444  ThotBool CanDoStop ()
   CanDoStop_set    CanDoStop_set
   sets the value of the CanDoStop flag    sets the value of the CanDoStop flag
   ----------------------------------------------------------------------*/    ----------------------------------------------------------------------*/
 #ifdef __STDC__  
 void CanDoStop_set (ThotBool value)  void CanDoStop_set (ThotBool value)
 #else  
 void CanDoStop (value)  
 ThotBool value;  
 #endif /* _STDC_ */  
 {  {
   CanDoStop_flag = value;    CanDoStop_flag = value;
 }  }
   
 #ifdef __STDC__  /*----------------------------------------------------------------------
     ----------------------------------------------------------------------*/
 void libwww_updateNetworkConf (int status)  void libwww_updateNetworkConf (int status)
 #else  
 void libwww_updateNetworkConf (status)  
 int status;  
 #endif /*__STDC__*/  
 {  {
   /* @@@ the docid parameter isn't used... clean it up */    /* @@@ the docid parameter isn't used... clean it up */
   int docid = 1;    int docid = 1;
Line 3750  int status; Line 3499  int status;
 /*----------------------------------------------------------------------  /*----------------------------------------------------------------------
   AHT_FTPURL_flag_set    AHT_FTPURL_flag_set
   ----------------------------------------------------------------------*/    ----------------------------------------------------------------------*/
 #ifdef __STDC__  
 void AHTFTPURL_flag_set (ThotBool value)  void AHTFTPURL_flag_set (ThotBool value)
 #else  
 void AHTFTPURL_flag_set (value)  
 ThotBool value;  
 #endif /* __STDC__ */  
 {  {
   FTPURL_flag = value;    FTPURL_flag = value;
 }  }
Line 3763  ThotBool value; Line 3507  ThotBool value;
 /*----------------------------------------------------------------------  /*----------------------------------------------------------------------
   AHT_FTPURL_flag    AHT_FTPURL_flag
   ----------------------------------------------------------------------*/    ----------------------------------------------------------------------*/
 #ifdef __STDC__  
 ThotBool AHTFTPURL_flag (void)  
 #else  
 ThotBool AHTFTPURL_flag (void)  ThotBool AHTFTPURL_flag (void)
 #endif /* __STDC__ */  
 {  {
   return (FTPURL_flag);    return (FTPURL_flag);
 }  }

Removed from v.1.264  
changed lines
  Added in v.1.265


Webmaster