Diff for /Amaya/amaya/query.c between versions 1.115 and 1.116

version 1.115, 1998/07/08 19:08:47 version 1.116, 1998/07/24 17:05:24
Line 16 Line 16
   
 #ifndef AMAYA_JAVA  #ifndef AMAYA_JAVA
   
   /* defines to include elsewhere
   *********************************/
   
   #define AMAYA_WWW_CACHE
   
   /*** for windows? ***/
   
   #ifndef _WINDOWS
   #define DEFAULT_CACHE_DIR "/tmp"
   #define CACHE_DIR_NAME "/amaya-cache"
   #else 
   #define DEFAULT_CACHE_DIR "c:\tmp"
   #define CACHE_DIR_NAME "\amaya-cache"
   #endif /* !_WINDOWS */
   
   
   
   #define DEFAULT_CACHE_SIZE 5
   
   
 /* Amaya includes  */  /* Amaya includes  */
 #define THOT_EXPORT extern  #define THOT_EXPORT extern
 #include "amaya.h"  #include "amaya.h"
Line 54  struct _HTError Line 74  struct _HTError
      char               *where; /* Which function */       char               *where; /* Which function */
   };    };
   
   
 struct _HTHost  
   {  
      char               *hostname;      /* name of host + optional port */  
      time_t              ntime; /* Creation time */  
      char               *type;  /* Peer type */  
      int                 version;       /* Peer version */  
      HTMethod            methods;       /* Public methods (bit-flag) */  
      char               *server;        /* Server name */  
      char               *user_agent;    /* User Agent */  
      char               *range_units;   /* Acceptable range units */  
      HTTransportMode     mode;  /* Supported mode */  
      HTChannel          *channel;       /* Persistent channel */  
      HTList             *pipeline;      /* Pipe line of net objects */  
      HTList             *pending;       /* List of pending Net objects */  
      time_t              expires;       /* Persistent channel expires time */  
   };  
   
 /* Type definitions and global variables etc. local to this module */  /* Type definitions and global variables etc. local to this module */
   
 /*----------------------------------------------------------------------*/  /*----------------------------------------------------------------------*/
Line 82  static HTList      *converters = NULL; / Line 84  static HTList      *converters = NULL; /
 static HTList      *acceptTypes = NULL; /* List of types for the Accept header */  static HTList      *acceptTypes = NULL; /* List of types for the Accept header */
 static HTList      *encodings = NULL;  static HTList      *encodings = NULL;
 static int          object_counter = 0; /* loaded objects counter */  static int          object_counter = 0; /* loaded objects counter */
 static  boolean    AmayaAlive;          /* set to 1 if the application is  static  boolean     AmayaAlive; /* set to 1 if the application is active;
                                            active; 0 if we have killed it */                                     0 if we have killed */
   
 #include "answer_f.h"  #include "answer_f.h"
 #include "query_f.h"  #include "query_f.h"
Line 92  static  boolean    AmayaAlive; Line 94  static  boolean    AmayaAlive;
 #include "AHTMemConv_f.h"  #include "AHTMemConv_f.h"
 #include "AHTFWrite_f.h"  #include "AHTFWrite_f.h"
   
 #ifdef _WINDOWS  /* prototypes */
   
 #ifdef __STDC__  #ifdef __STDC__
   #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 */
 #else  #else
   #ifdef _WINDOWS
 int WIN_Activate_Request ();  int WIN_Activate_Request ();
 #endif /* __STDC__ */  
 #endif /* _WINDOWS */  #endif /* _WINDOWS */
   #endif /* __STDC__ */
   
   
 /*----------------------------------------------------------------------  /*----------------------------------------------------------------------
   GetDocIdStatus    GetDocIdStatus
Line 207  int                 docid; Line 214  int                 docid;
    AHTDocId_Status    *docid_status;     AHTDocId_Status    *docid_status;
   
    if ((me = (AHTReqContext *) TtaGetMemory (sizeof (AHTReqContext))) == NULL)     if ((me = (AHTReqContext *) TtaGetMemory (sizeof (AHTReqContext))) == NULL)
       outofmem (__FILE__, "Context_new");       outofmem (__FILE__, "AHTReqContext_new");
   
      /* clear the structure */
      memset ((void *) me, 0, sizeof (AHTReqContext));
   
    /* Bind the Context object together with the Request Object */     /* Bind the Context object together with the Request Object */
    me->request = HTRequest_new ();     me->request = HTRequest_new ();
       
      /*
      ** Make sure that the first request is flushed immediately and not
      ** buffered in the output buffer
      */
      HTRequest_setFlush(me->request, YES);
   
    /* clean the associated file structure) */     /* clean the associated file structure) */
    HTRequest_setOutputStream (me->request, NULL);     HTRequest_setOutputStream (me->request, NULL);
     
    /* Initialize the other members of the structure */     /* Initialize the other members of the structure */
    me->reqStatus = HT_NEW; /* initial status of a request */     me->reqStatus = HT_NEW; /* initial status of a request */
    me->output = NULL;  
    me->content_type = NULL;  
 #  ifndef _WINDOWS  
    me->read_xtinput_id = (XtInputId) NULL;  
    me->write_xtinput_id = (XtInputId) NULL;  
    me->except_xtinput_id = (XtInputId) NULL;  
 #  endif  
    me->docid = docid;     me->docid = docid;
    HTRequest_setMethod (me->request, METHOD_GET);     HTRequest_setMethod (me->request, METHOD_GET);
    HTRequest_setOutputFormat (me->request, WWW_SOURCE);     HTRequest_setOutputFormat (me->request, WWW_SOURCE);
    HTRequest_setContext (me->request, me);     HTRequest_setContext (me->request, me);
    me->read_ops = 0;  
    me->write_ops = 0;  
    me->except_ops = 0;  
    /* experimental */     /* experimental */
    me->read_sock = INVSOC;     me->read_sock = INVSOC;
    me->write_sock = INVSOC;     me->write_sock = INVSOC;
Line 243  int                 docid; Line 250  int                 docid;
   
    if (docid_status == NULL)     if (docid_status == NULL)
      {       {
         docid_status = (AHTDocId_Status *) TtaGetMemory (sizeof (AHTDocId_Status));          docid_status = (AHTDocId_Status *) 
             TtaGetMemory (sizeof (AHTDocId_Status));
         docid_status->docid = docid;          docid_status->docid = docid;
         docid_status->counter = 1;          docid_status->counter = 1;
         HTList_addObject (Amaya->docid_status, (void *) docid_status);          HTList_addObject (Amaya->docid_status, (void *) docid_status);
Line 251  int                 docid; Line 259  int                 docid;
    else     else
       docid_status->counter++;        docid_status->counter++;
   
   
    Amaya->open_requests++;     Amaya->open_requests++;
   
    /* error stream handling */  
    me->error_stream = (char *) NULL;  
    me->error_stream_size = 0;  
   
 #ifdef DEBUG_LIBWWW  #ifdef DEBUG_LIBWWW
    fprintf (stderr, "AHTReqContext_new: Created object %p\n", me);     fprintf (stderr, "AHTReqContext_new: Created object %p\n", me);
 #endif     #endif   
    return me;  
   
      return me;
 }  }
   
 /*----------------------------------------------------------------------  /*----------------------------------------------------------------------
Line 303  AHTReqContext      *me; Line 306  AHTReqContext      *me;
                   TtaFreeMemory ((void *) docid_status);                    TtaFreeMemory ((void *) docid_status);
                }                 }
           }            }
   
         if (HTRequest_outputStream (me->request))          if (HTRequest_outputStream (me->request))
           AHTFWriter_FREE (me->request->output_stream);            AHTFWriter_FREE (me->request->output_stream);
   
         HTRequest_delete (me->request);          HTRequest_delete (me->request);
   
         if (me->output && me->output != stdout)          if (me->output && me->output != stdout)
Line 350  AHTReqContext      *me; Line 351  AHTReqContext      *me;
   
         if (me->content_type)          if (me->content_type)
           TtaFreeMemory (me->content_type);            TtaFreeMemory (me->content_type);
         if (me->mode & AMAYA_FORM_POST)          /* @@@ need to do this better */
           TtaFreeMemory (me->mem_ptr);          if (me->formdata)
             HTAssocList_delete (me->formdata);
   
           /* to trace bugs */
           memset ((void *) me, 0, sizeof (AHTReqContext));
   
         TtaFreeMemory ((void *) me);          TtaFreeMemory ((void *) me);
   
         Amaya->open_requests--;          Amaya->open_requests--;
         return TRUE;  
   
           return TRUE;
      }       }
    return FALSE;     return FALSE;
 }  }
   
   
 /*----------------------------------------------------------------------  /*----------------------------------------------------------------------
   AHTUpload_callback  
   callback handler for executing the PUT command  
   ----------------------------------------------------------------------*/  
 #ifdef __STDC__  
 static int          AHTUpload_callback (HTRequest * request, HTStream * target)  
 #else  
 static int          AHTUpload_callback (request, target)  
 HTRequest          *request;  
 HTStream           *target;  
   
 #endif  
 {  
    AHTReqContext      *me = HTRequest_context (request);  
    HTParentAnchor     *entity = HTRequest_entityAnchor (request);  
    int                 len = HTAnchor_length (entity);  
    int                 status;  
   
    /* Send the data down the pipe */  
   
    status = (*target->isa->put_block) (target, me->mem_ptr, len);  
   
    if (status == HT_LOADED || status == HT_OK)  
      {  
        if (PROT_TRACE)  
          HTTrace ("Posting Data Target is SAVED\n");  
        (*target->isa->flush) (target);  
        return (HT_LOADED);  
      }  
    if (status == HT_WOULD_BLOCK)  
      {  
         if (PROT_TRACE)  
            HTTrace ("Posting Data Target WOULD BLOCK\n");  
 #ifdef _WINDOWS  
         return HT_CONTINUE;  
 #else  
         return HT_WOULD_BLOCK;  
 #endif /* _WINDOWS */  
   
         return HT_WOULD_BLOCK;  
      }  
    else if (status == HT_PAUSE)  
      {  
         if (PROT_TRACE)  
            HTTrace ("Posting Data Target PAUSED\n");  
         /*  
         return HT_PAUSE;  
         */  
         return HT_CONTINUE;  
           
      }  
    else if (status > 0)  
      {                          /* Stream specific return code */  
         if (PROT_TRACE)  
            HTTrace ("Posting Data. Target returns %d\n", status);  
         return status;  
      }  
    else  
      {                          /* we have a real error */  
         if (PROT_TRACE)  
            HTTrace ("Posting Data Target ERROR %d\n", status);  
         return status;  
      }  
 }  
   
 /*----------------------------------------------------------------------  
   Thread_deleteAll    Thread_deleteAll
   this function deletes the whole list of active threads.               this function deletes the whole list of active threads.           
   ----------------------------------------------------------------------*/    ----------------------------------------------------------------------*/
Line 497  HTRequest           *request; Line 438  HTRequest           *request;
       return HT_ERROR;        return HT_ERROR;
   
 #ifdef DEBUG_LIBWWW  #ifdef DEBUG_LIBWWW
   fprintf(stderr, "AHTOpen_file: start\n");    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) 
Line 527  HTRequest           *request; Line 468  HTRequest           *request;
 #ifndef _WINDOWS  #ifndef _WINDOWS
       (me->output = fopen (me->outputfile, "w")) == NULL)        (me->output = fopen (me->outputfile, "w")) == NULL)
     {      {
 #else  #else /* !_WINDOWS */
     (me->output = fopen (me->outputfile, "wb")) == NULL)       (me->output = fopen (me->outputfile, "wb")) == NULL) 
     {      {
 #endif /* !_WINDOWS */  #endif /* !_WINDOWS */
Line 624  int                 status; Line 565  int                 status;
           }            }
   
         /* update the current file name */          /* update the current file name */
           TtaFreeMemory (me->urlName);
           me->urlName = TtaStrdup (new_anchor->parent->address);
   
         if (strlen (new_anchor->parent->address) > (MAX_LENGTH - 2))          if (strlen (new_anchor->parent->address) > (MAX_LENGTH - 2))
           {            {
              strncpy (me->urlName, new_anchor->parent->address, MAX_LENGTH - 1);               strncpy (me->urlName, new_anchor->parent->address, 
                         MAX_LENGTH - 1);
              me->urlName[MAX_LENGTH - 1] = EOS;               me->urlName[MAX_LENGTH - 1] = EOS;
           }            }
         else          else
           strcpy (me->urlName, new_anchor->parent->address);            strcpy (me->urlName, new_anchor->parent->address);
   
         ChopURL (me->status_urlName, me->urlName);          ChopURL (me->status_urlName, me->urlName);
   
         TtaSetStatus (me->docid, 1, TtaGetMessage (AMAYA, AM_RED_FETCHING),          TtaSetStatus (me->docid, 1, TtaGetMessage (AMAYA, AM_RED_FETCHING),
                       me->status_urlName);                        me->status_urlName);
   
Line 651  int                 status; Line 597  int                 status;
         }          }
   
         /* reset the status */          /* reset the status */
         me->reqStatus = HT_NEW;          me->reqStatus = HT_NEW; 
         /* clear the errors */          /* clear the errors */
         HTError_deleteAll( HTRequest_error (request));          HTError_deleteAll (HTRequest_error (request));
         HTRequest_setError (request, NULL);          HTRequest_setError (request, NULL);
   
         if (me->method == METHOD_PUT || me->method == METHOD_POST)      /* PUT, POST etc. */          if (me->method == METHOD_PUT || me->method == METHOD_POST)      /* PUT, POST etc. */
           status = HTLoadAbsolute (me->urlName, request);            status = HTLoadAbsolute (me->urlName, request);
         else          else
Line 693  void               *context; Line 640  void               *context;
 int                 status;  int                 status;
 #endif  #endif
 {  {
    AHTReqContext      *me = (AHTReqContext *) HTRequest_context (request);    AHTReqContext      *me = (AHTReqContext *) HTRequest_context (request);
    char               *content_type;    boolean             error_flag;
    boolean             error_flag;    char               *content_type;
   
    if (!me)    if (!me)
      return HT_OK;              /* not an Amaya request */      return HT_OK;               /* not an Amaya request */
      
    /* if Amaya was killed, treat with this request as if it were    if (me->reqStatus == HT_END)
       issued by a Stop button event */      /* we have already processed this request! */
    if (!AmayaAlive)                 return HT_OK;
   
     /* if Amaya was killed, treat with this request as if it were
        issued by a Stop button event */
   
      if (!AmayaIsAlive ())           
       me->reqStatus = HT_ABORT;         me->reqStatus = HT_ABORT; 
         
    if (status == HT_LOADED ||      if (status == HT_LOADED || 
        status == HT_CREATED ||          status == HT_CREATED || 
        status == HT_NO_DATA ||         status == HT_NO_DATA ||
   #ifdef AMAYA_WWW_CACHE
          /* what status to use to know we're downloading from a cache? */
          status ==  HT_NOT_MODIFIED ||
   #endif /* AMAYA_WWW_CACHE */
        me->reqStatus == HT_ABORT)         me->reqStatus == HT_ABORT)
      error_flag = FALSE;       error_flag = FALSE;
    else     else
Line 769  int                 status; Line 725  int                 status;
        me->output = NULL;         me->output = NULL;
      }       }
   
      
    if (error_flag)     if (error_flag)
      me->reqStatus = HT_ERR;       me->reqStatus = HT_ERR;
    else if (me->reqStatus != HT_ABORT)     else if (me->reqStatus != HT_ABORT)
      me->reqStatus = HT_END;       me->reqStatus = HT_END;
      
    /* copy the content_type */       /* copy the content_type */
    content_type = request->anchor->content_type->name;      content_type = request->anchor->content_type->name;
    if (content_type && content_type [0] != EOS)     if (content_type && content_type [0] != EOS)
      {       {
        /* libwww gives www/unknown when it gets an error. As this is          /* libwww gives www/unknown when it gets an error. As this is 
Line 797  int                 status; Line 752  int                 status;
   
    /* to avoid a hangup while downloading css files */     /* to avoid a hangup while downloading css files */
    if (AmayaAlive && (me->mode & AMAYA_LOAD_CSS))     if (AmayaAlive && (me->mode & AMAYA_LOAD_CSS))
        TtaSetStatus (me->docid, 1,        TtaSetStatus (me->docid, 1, 
                      TtaGetMessage (AMAYA, AM_ELEMENT_LOADED),                     TtaGetMessage (AMAYA, AM_ELEMENT_LOADED),
                      me->status_urlName);                     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 (AmayaAlive  && ((me->method == METHOD_POST) ||     if (AmayaIsAlive ()  && ((me->method == METHOD_POST) ||
                        (me->method == METHOD_PUT)))                              (me->method == METHOD_PUT)))
      {       {
        PrintTerminateStatus (me, status);         PrintTerminateStatus (me, status);
          
      }        } 
   
          
    ProcessTerminateRequest (request, response, context, status);     ProcessTerminateRequest (request, response, context, status);
      
    return HT_OK;     return HT_OK;
 }  }
   
Line 830  int                 status; Line 786  int                 status;
   
 #endif  #endif
 {  {
   
     /** @@@@ 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;
   
    switch (status)     switch (status)
          {       {
             case HT_LOADED:           case HT_LOADED:
                if (PROT_TRACE)             if (PROT_TRACE)
                   HTTrace ("Load End.... OK: `%s\' has been accessed\n",               HTTrace ("Load End.... OK: `%s\' has been accessed\n",
                            me->status_urlName);                        me->status_urlName);
   
                docid_status = GetDocIdStatus (me->docid,  
                                               Amaya->docid_status);  
   
                if (docid_status != NULL && docid_status->counter > 1)  
                   TtaSetStatus (me->docid, 1,   
                                 TtaGetMessage (AMAYA, AM_ELEMENT_LOADED),  
                                 me->status_urlName);  
                break;  
   
             case HT_NO_DATA:             docid_status = GetDocIdStatus (me->docid,
                if (PROT_TRACE)                                            Amaya->docid_status);
                   HTTrace ("Load End.... OK BUT NO DATA: `%s\'\n",   
                            me->status_urlName);  
                TtaSetStatus (me->docid, 1,   
                              TtaGetMessage (AMAYA, AM_LOADED_NO_DATA),  
                              me->status_urlName);  
                break;  
   
             case HT_INTERRUPTED:             if (docid_status != NULL && docid_status->counter > 1)
                if (PROT_TRACE)               TtaSetStatus (me->docid, 1, 
                   HTTrace ("Load End.... INTERRUPTED: `%s\'\n",                              TtaGetMessage (AMAYA, AM_ELEMENT_LOADED),
                            me->status_urlName);                             me->status_urlName);
                TtaSetStatus (me->docid, 1,   
                              TtaGetMessage (AMAYA, AM_LOAD_ABORT),   
                              NULL);  
                break;  
   
             case HT_RETRY:  
                if (PROT_TRACE)  
                   HTTrace ("Load End.... NOT AVAILABLE, RETRY AT %ld\n",  
                            HTResponse_retryTime (response));  
                TtaSetStatus (me->docid, 1,   
                              TtaGetMessage (AMAYA, AM_NOT_AVAILABLE_RETRY),  
                              me->status_urlName);  
                break;  
   
             case HT_ERROR:  
   
                cbf = HTAlert_find (HT_A_MESSAGE);  
                if (cbf)  
                   (*cbf) (request, HT_A_MESSAGE, HT_MSG_NULL, NULL,  
                           HTRequest_error (request), NULL);  
                break;                 break;
                  
        case HT_NO_DATA:
          if (PROT_TRACE)
            HTTrace ("Load End.... OK BUT NO DATA: `%s\'\n", 
                     me->status_urlName);
          TtaSetStatus (me->docid, 1, 
                        TtaGetMessage (AMAYA, AM_LOADED_NO_DATA),
                        me->status_urlName);
          break;
          
        case HT_INTERRUPTED:
          if (PROT_TRACE)
            HTTrace ("Load End.... INTERRUPTED: `%s\'\n", 
                     me->status_urlName);
          TtaSetStatus (me->docid, 1, 
                        TtaGetMessage (AMAYA, AM_LOAD_ABORT), 
                        NULL);
          break;
   
                if (PROT_TRACE)       case HT_RETRY:
                   HTTrace ("Load End.... ERROR: Can't access `%s\'\n",         if (PROT_TRACE)
                            me->status_urlName ? me->status_urlName :"<UNKNOWN>");           HTTrace ("Load End.... NOT AVAILABLE, RETRY AT %ld\n",
                TtaSetStatus (me->docid, 1,                    HTResponse_retryTime (response));
                              TtaGetMessage (AMAYA, AM_CANNOT_LOAD),         TtaSetStatus (me->docid, 1, 
                              me->status_urlName ? me->status_urlName : "<UNKNOWN>");                       TtaGetMessage (AMAYA, AM_NOT_AVAILABLE_RETRY),
                break;                       me->status_urlName);
             default:         break;
                if (PROT_TRACE)  
                   HTTrace ("Load End.... UNKNOWN RETURN CODE %d\n", status);  
                break;  
          }  
   
        case HT_ERROR:
          cbf = HTAlert_find (HT_A_MESSAGE);
          if (cbf)
            (*cbf) (request, HT_A_MESSAGE, HT_MSG_NULL, NULL,
                    HTRequest_error (request), NULL);
          break;
          
          if (PROT_TRACE)
            HTTrace ("Load End.... ERROR: Can't access `%s\'\n",
                     me->status_urlName ? me->status_urlName :"<UNKNOWN>");
          TtaSetStatus (me->docid, 1,
                        TtaGetMessage (AMAYA, AM_CANNOT_LOAD),
                        me->status_urlName ? me->status_urlName : "<UNKNOWN>");
          break;
        default:
          if (PROT_TRACE)
            HTTrace ("Load End.... UNKNOWN RETURN CODE %d\n", status);
          break;
        }
      
    return HT_OK;     return HT_OK;
 }  }
   
   #ifdef DEBUG_LIBWWW
   static  int LineTrace (const char * fmt, va_list pArgs)
   {
       return (vfprintf(stderr, fmt, pArgs));
   }
   #endif DEBUG_LIBWWW
   
 /*----------------------------------------------------------------------  /*----------------------------------------------------------------------
   AHTAcceptTypesInit    AHTAcceptTypesInit
   This function prepares the Accept header used by Amaya during    This function prepares the Accept header used by Amaya during
Line 962  HTList             *c; Line 927  HTList             *c;
     ** that is not directly outputting someting to the user on the screen      ** that is not directly outputting someting to the user on the screen
     */      */
   
    HTConversion_add (c, "message/rfc822", "*/*", HTMIMEConvert, 1.0, 0.0, 0.0);     HTConversion_add (c, "message/rfc822", "*/*", HTMIMEConvert, 
                        1.0, 0.0, 0.0);
    HTConversion_add (c, "message/x-rfc822-foot", "*/*", HTMIMEFooter,     HTConversion_add (c, "message/x-rfc822-foot", "*/*", HTMIMEFooter,
                      1.0, 0.0, 0.0);                       1.0, 0.0, 0.0);
    HTConversion_add (c, "message/x-rfc822-head", "*/*", HTMIMEHeader,     HTConversion_add (c, "message/x-rfc822-head", "*/*", HTMIMEHeader,
                      1.0, 0.0, 0.0);                       1.0, 0.0, 0.0);
      HTConversion_add(c,"message/x-rfc822-cont",  "*/*", HTMIMEContinue,  
                       1.0, 0.0, 0.0);
      HTConversion_add(c,"message/x-rfc822-partial","*/*", HTMIMEPartial,
                       1.0, 0.0, 0.0);
    HTConversion_add (c, "multipart/*", "*/*", HTBoundary,     HTConversion_add (c, "multipart/*", "*/*", HTBoundary,
                      1.0, 0.0, 0.0);                       1.0, 0.0, 0.0);
    HTConversion_add (c, "text/plain", "text/html", HTPlainToHTML,     HTConversion_add (c, "text/plain", "text/html", HTPlainToHTML,
                      1.0, 0.0, 0.0);                       1.0, 0.0, 0.0);
   
   
    /*     /*
       ** The following conversions are converting ASCII output from various     ** The following conversions are converting ASCII output from various
       ** protocols to HTML objects.     ** protocols to HTML objects.
     */     */
    HTConversion_add (c, "text/x-http", "*/*", HTTPStatus_new,     HTConversion_add (c, "text/x-http", "*/*", HTTPStatus_new,
                      1.0, 0.0, 0.0);                       1.0, 0.0, 0.0);
   
    /*     /*
     ** We also register a special content type guess stream that can figure out     ** We also register a special content type guess stream that can figure out
     ** the content type by reading the first bytes of the stream     ** the content type by reading the first bytes of the stream
     */     */
    HTConversion_add (c, "www/unknown", "*/*", HTGuess_new,     HTConversion_add (c, "www/unknown", "*/*", HTGuess_new,
                      1.0, 0.0, 0.0);                       1.0, 0.0, 0.0);
   
   #ifdef AMAYA_WWW_CACHE
    /*     /*
       ** Register a persistent cache stream which can save an object to local     ** Register a persistent cache stream which can save an object to local
       ** file     ** file
     */     */
 #if 0  
    HTConversion_add (c, "www/cache", "*/*", HTCacheWriter,     HTConversion_add (c, "www/cache", "*/*", HTCacheWriter,
                      1.0, 0.0, 0.0);                       1.0, 0.0, 0.0);
 #endif     HTConversion_add(c,"www/cache-append", "*/*", HTCacheAppend,
                       1.0, 0.0, 0.0);
   #endif AMAYA_WWW_CACHE
   
    /*     /*
       ** This dumps all other formats to local disk without any further     ** This dumps all other formats to local disk without any further
       ** action taken     ** action taken
     */     */
    HTConversion_add (c, "*/*", "www/present", HTSaveLocally,     HTConversion_add (c, "*/*", "www/present", HTSaveLocally,
                      0.3, 0.0, 0.0);                       0.3, 0.0, 0.0);
      
 }  }
   
   
Line 1012  HTList             *c; Line 983  HTList             *c;
   ----------------------------------------------------------------------*/    ----------------------------------------------------------------------*/
 static void         AHTProtocolInit (void)  static void         AHTProtocolInit (void)
 {  {
     char *strptr;
   
    /*     /* 
       NB. Preemptive == YES means Blocking requests       NB. Preemptive == YES means Blocking requests
       Non-preemptive == NO means Non-blocking requests       Non-preemptive == NO means Non-blocking requests
    */       */
     HTTransport_add("tcp", HT_TP_SINGLE, HTReader_new, HTWriter_new);
    HTProtocol_add ("http", "buffered_tcp", NO, HTLoadHTTP, NULL);    HTTransport_add("buffered_tcp", HT_TP_SINGLE, HTReader_new, 
    /*   HTProtocol_add ("http", "tcp", NO, HTLoadHTTP, NULL); */                    HTBufferWriter_new);
    HTProtocol_add ("file", "local", NO, HTLoadFile, NULL);    HTProtocol_add ("http", "buffered_tcp", HTTP_PORT, NO, HTLoadHTTP, NULL);
     HTProtocol_add ("file", "local", 0, NO, HTLoadFile, NULL);
   #ifdef AMAYA_WWW_CACHE
      HTProtocol_add("cache",  "local", 0, YES, HTLoadCache, NULL);
   #endif /* AMAYA_WWW_CACHE */
 #if 0 /* experimental code */  #if 0 /* experimental code */
    HTProtocol_add ("cache", "local", NO, HTLoadCache, NULL);     HTProtocol_add ("ftp", "tcp", FTP_PORT, NO, HTLoadFTP, NULL);
    HTProtocol_add ("ftp", "tcp", NO, HTLoadFTP, NULL);  
    HTProtocol_add ("telnet", "", YES, HTLoadTelnet, NULL);  
    HTProtocol_add ("tn3270", "", YES, HTLoadTelnet, NULL);  
    HTProtocol_add ("rlogin", "", YES, HTLoadTelnet, NULL);  
    HTProtocol_add ("nntp", "tcp", NO, HTLoadNews, NULL);  
    HTProtocol_add ("news", "tcp", NO, HTLoadNews, NULL);  
 #endif  #endif
   
      /* initialize pipelining */
     strptr = (char *) TtaGetEnvString ("PIPELINING");
     if (strptr && *strptr && strcasecmp (strptr,"yes" ))
       HTTP_setConnectionMode (HTTP_11_NO_PIPELINING);
 }  }
   
 /*----------------------------------------------------------------------  /*----------------------------------------------------------------------
Line 1044  static void         AHTNetInit (void) Line 1019  static void         AHTNetInit (void)
 **      The filters are called in the order by which the are registered  **      The filters are called in the order by which the are registered
 **      Not done automaticly - may be done by application!  **      Not done automaticly - may be done by application!
 */  */
     
   
   HTNet_addBefore (HTCredentialsFilter, "http://*", NULL, 6);  #ifdef AMAYA_WWW_CACHE  
   HTNet_addBefore (HTProxyFilter, NULL, NULL, 10);    HTNet_addBefore (HTCacheFilter, "http://*", NULL, HT_FILTER_MIDDLE);
   /*  HTNet_addBefore (AHTOpen_file, NULL, NULL, 11); */  #endif /* AMAYA_WWW_CACHE */
     HTNet_addBefore (HTCredentialsFilter, "http://*", NULL, HT_FILTER_LATE);
     HTNet_addBefore (HTProxyFilter, NULL, NULL, HT_FILTER_LATE);
   HTHost_setActivateRequestCallback (AHTOpen_file);    HTHost_setActivateRequestCallback (AHTOpen_file);
   
 /*      register AFTER filters  /*      register AFTER filters
Line 1058  static void         AHTNetInit (void) Line 1034  static void         AHTNetInit (void)
 **      Not done automaticly - may be done by application!  **      Not done automaticly - may be done by application!
 */  */
   
    HTNet_addAfter (HTAuthFilter, "http://*", NULL, HT_NO_ACCESS, HT_FILTER_MIDDLE);    HTNet_addAfter (HTAuthFilter, "http://*", NULL, HT_NO_ACCESS,
    HTNet_addAfter (redirection_handler, "http://*", NULL, HT_TEMP_REDIRECT, HT_FILTER_MIDDLE);                    HT_FILTER_MIDDLE);
    HTNet_addAfter (redirection_handler, "http://*", NULL, HT_PERM_REDIRECT, HT_FILTER_MIDDLE);    HTNet_addAfter(HTAuthFilter, "http://*", NULL, HT_REAUTH,
    HTNet_addAfter (HTUseProxyFilter, "http://*", NULL, HT_USE_PROXY, HT_FILTER_MIDDLE);                   HT_FILTER_MIDDLE);
     HTNet_addAfter (redirection_handler, "http://*", NULL, HT_PERM_REDIRECT,
                     HT_FILTER_MIDDLE);
     HTNet_addAfter (redirection_handler, "http://*", NULL, HT_FOUND, 
                     HT_FILTER_MIDDLE);
     HTNet_addAfter (redirection_handler, "http://*", NULL, HT_SEE_OTHER,
                     HT_FILTER_MIDDLE);
     HTNet_addAfter (redirection_handler, "http://*", NULL, HT_TEMP_REDIRECT,
                     HT_FILTER_MIDDLE);
     HTNet_addAfter (HTUseProxyFilter, "http://*", NULL, HT_USE_PROXY,
                     HT_FILTER_MIDDLE);
   #ifdef AMAYA_WWW_CACHE
     HTNet_addAfter (HTCacheUpdateFilter, "http://*", NULL, HT_NOT_MODIFIED, 
                     HT_FILTER_MIDDLE);
   #endif /* AMAYA_WWW_CACHE */
 #ifndef _WINDOWS  #ifndef _WINDOWS
    HTNet_addAfter (AHTLoadTerminate_handler, NULL, NULL, HT_ALL, HT_FILTER_LAST);           HTNet_addAfter (AHTLoadTerminate_handler, NULL, NULL, HT_ALL, 
                      HT_FILTER_LAST);     
 #endif /* !_WINDOWS */  #endif /* !_WINDOWS */
      /**** for later ?? ****/
      /*  HTNet_addAfter(HTInfoFilter,     NULL,           NULL, HT_ALL,           HT_FILTER_LATE); */
    /* handles all errors */     /* handles all errors */
    HTNet_addAfter (terminate_handler, NULL, NULL, HT_ALL, HT_FILTER_LAST);    HTNet_addAfter (terminate_handler, NULL, NULL, HT_ALL, HT_FILTER_LAST);
 }  }
   
 /*----------------------------------------------------------------------  /*----------------------------------------------------------------------
Line 1080  static void         AHTAlertInit () Line 1073  static void         AHTAlertInit ()
 #endif  #endif
 {  {
    HTAlert_add (AHTProgress, HT_A_PROGRESS);     HTAlert_add (AHTProgress, HT_A_PROGRESS);
 #  ifndef _WINDOWS  #ifdef _WINDOWS
    /*   HTAlert_add ((HTAlertCallback *) Add_NewSocket_to_Loop, HT_PROG_CONNECT); */  
 #  else  /* _WINDOWS */  
    HTAlert_add ((HTAlertCallback *) WIN_Activate_Request, HT_PROG_CONNECT);     HTAlert_add ((HTAlertCallback *) WIN_Activate_Request, HT_PROG_CONNECT);
 #  endif /* _WINDOWS */  #endif /* _WINDOWS */
    HTAlert_add (AHTError_print, HT_A_MESSAGE);     HTAlert_add (AHTError_print, HT_A_MESSAGE);
    HTError_setShow (~((unsigned int) 0 ) & ~((unsigned int) HT_ERR_SHOW_DEBUG));        /* process all messages except debug ones*/     HTError_setShow (~((unsigned int) 0 ) & ~((unsigned int) HT_ERR_SHOW_DEBUG));        /* process all messages except debug ones*/
    HTAlert_add (AHTConfirm, HT_A_CONFIRM);     HTAlert_add (AHTConfirm, HT_A_CONFIRM);
    HTAlert_add (AHTPrompt, HT_A_PROMPT);     HTAlert_add (AHTPrompt, HT_A_PROMPT);
    HTAlert_add (AHTPromptPassword, HT_A_SECRET);     HTAlert_add (AHTPromptPassword, HT_A_SECRET);
    HTAlert_add (AHTPromptUsernameAndPassword, HT_A_USER_PW);     HTAlert_add (AHTPromptUsernameAndPassword, HT_A_USER_PW);
   #ifdef AMAYA_WWW_CACHE
      HTAlert_add (AHTConfirm, HT_MSG_CACHE_LOCK);
   #endif /* AMAYA_WWW_CACHE */
   }
   
   /*----------------------------------------------------------------------
     CacheInit
     Reads the cache settings from the thot.ini file.
     ----------------------------------------------------------------------*/
   static void CacheInit (void)
   {
   #ifndef AMAYA_WWW_CACHE
      HTCacheMode_setEnabled (NO);
   
   #else /* AMAYA_WWW_CACHE */
     char *strptr;
     int cache_size;
     char *cache_dir = NULL;
     boolean cache;
   
     /* activate cache? */
     strptr = (char *) TtaGetEnvString ("ENABLE_CACHE");
     if (strptr && *strptr && strcasecmp (strptr,"yes" ))
       cache = NO;
     else
       cache = YES;
   
     /* get the cache dir (or use a default one) */
     strptr = (char *) TtaGetEnvString ("CACHE_DIR");
     if (strptr && *strptr) 
       {
         cache_dir = TtaGetMemory (strlen (strptr) + strlen (CACHE_DIR_NAME) + 1);
         strcpy (cache_dir, strptr);
       }
     else
       {
         cache_dir = TtaGetMemory (strlen (DEFAULT_CACHE_DIR) 
                                   + strlen (CACHE_DIR_NAME) + 1);
         strcpy (cache_dir, DEFAULT_CACHE_DIR);
       }
     strcat (cache_dir, CACHE_DIR_NAME);
   
     /* get the cache size (or use a default one) */
       strptr = (char *) TtaGetEnvString ("CACHE_SIZE");
     if (strptr && *strptr) 
         cache_size = atoi (strptr);
     else
       cache_size = DEFAULT_CACHE_SIZE;
   
     if (cache) 
       {
         /* how to remove the lock? force remove it? */
         /* @@@ugly hack to remove the .lock file ... */
         /* we would need something to remove the index, clear
            the directory, etc. attention to dir-sep  */
         strptr = TtaGetMemory (strlen (cache_dir) + 20);
         strcpy (strptr, cache_dir);
   #ifndef _WINDOWS
         strcat (strptr, "/.lock");
   #else
         strcat (strptr, "\.lock");
   #endif /* !_WINDOWS */
         if (TtaFileExist (strptr))
           {
             /* remove the lock and clean the cache (the clean cache will remove
              all, making the following call unnecessary */
             TtaFileUnlink (strptr);
             /* CleanCache (cache_dir); */
           }
         TtaFreeMemory (strptr);
   
         /* store this in our libwww context */
         HTCacheInit (cache_dir, cache_size);
         HTCacheMode_setExpires(HT_EXPIRES_AUTO);
       }
     else
         HTCacheMode_setEnabled (NO);
   
     if (cache_dir)
       TtaFreeMemory (cache_dir);
   #endif /* AMAYA_WWW_CACHE */
 }  }
   
 /*----------------------------------------------------------------------  /*----------------------------------------------------------------------
Line 1119  static void ProxyInit (void) Line 1191  static void ProxyInit (void)
         unsigned port=0;          unsigned port=0;
         if (portstr) {          if (portstr) {
           *portstr++ = '\0';            *portstr++ = '\0';
           if (*portstr) 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 1162  char               *AppVersion; Line 1234  char               *AppVersion;
    /* Register the default set of application protocol modules */     /* Register the default set of application protocol modules */
    AHTProtocolInit ();     AHTProtocolInit ();
   
    /* Enable the persistent cache */     /* Register the default set of messages and dialog functions */
    /*   HTCacheInit (NULL, 20); */     AHTAlertInit ();
      HTAlert_setInteractive (YES);
   
   #ifdef AMAYA_WWW_CACHE
      /* Enable the persistent cache  */
      CacheInit ();
   #else
      HTCacheMode_setEnabled (NO);
   #endif /* AMAYA_WWW_CACHE */
   
    /* Register the default set of BEFORE and AFTER filters */     /* Register the default set of BEFORE and AFTER filters */
    AHTNetInit ();     AHTNetInit ();
Line 1180  char               *AppVersion; Line 1260  char               *AppVersion;
    HTFormat_setConversion (converters);     HTFormat_setConversion (converters);
   
    /* Register the default set of transfer encoders and decoders */     /* Register the default set of transfer encoders and decoders */
    HTEncoderInit (encodings);   /* chunks ??? */     HTTransferEncoderInit (encodings);   /* chunks ??? */
    HTFormat_setTransferCoding (encodings);     HTFormat_setTransferCoding (encodings);
   
    /* Register the default set of MIME header parsers */     /* Register the default set of MIME header parsers */
Line 1189  char               *AppVersion; Line 1269  char               *AppVersion;
    /* Register the default set of Icons for directory listings */     /* Register the default set of Icons for directory listings */
    /*HTIconInit(NULL); *//* experimental */     /*HTIconInit(NULL); *//* experimental */
   
    /* Register the default set of messages and dialog functions */  
    AHTAlertInit ();  
    HTAlert_setInteractive (YES);  
 }  }
   
 /*----------------------------------------------------------------------  /*----------------------------------------------------------------------
Line 1225  static void         AHTProfile_delete () Line 1302  static void         AHTProfile_delete ()
 #  endif _WINDOWS;                #  endif _WINDOWS;              
           
     /* Clean up the persistent cache (if any) */      /* Clean up the persistent cache (if any) */
   /*  HTCacheTerminate (); */  #ifdef AMAYA_WWW_CACHE
       HTCacheTerminate ();
   #endif /* AMAYA_WWW_CACHE */
           
     /* Clean up all the global preferences */      /* Clean up all the global preferences */
     HTFormat_deleteAll ();      HTFormat_deleteAll ();
Line 1236  static void         AHTProfile_delete () Line 1315  static void         AHTProfile_delete ()
 }  }
   
 /*----------------------------------------------------------------------  /*----------------------------------------------------------------------
     AmayacontextInit
     initializes an internal Amaya context for our libwww interface 
     ----------------------------------------------------------------------*/
   #ifdef __STDC__
   static void                AmayaContextInit ()
   #else
   static void                AmayaContextInit ()
   #endif
   
   {
     AmayaAlive = TRUE;
     /* Initialization of the global context */
     Amaya = (AmayaContext *) TtaGetMemory (sizeof (AmayaContext));
     Amaya->reqlist = HTList_new ();
     Amaya->docid_status = HTList_new ();
     Amaya->open_requests = 0;
   }
   
   /*----------------------------------------------------------------------
   QueryInit    QueryInit
   initializes the libwww interface     initializes the libwww interface 
   ----------------------------------------------------------------------*/    ----------------------------------------------------------------------*/
Line 1246  void                QueryInit () Line 1344  void                QueryInit ()
 #endif  #endif
 {  {
   
    AmayaAlive = TRUE;     AmayaContextInit ();
      
    AHTProfile_newAmaya (HTAppName, HTAppVersion);     AHTProfile_newAmaya (HTAppName, HTAppVersion);
      
    /* New AHTBridge stuff */     /* New AHTBridge stuff */
   
 #  ifdef _WINDOWS  #ifdef _WINDOWS
    AHTEventInit ();     AHTEventInit ();
 #  endif _WINDOWS;  #endif /* _WINDOWS */
   
    HTEvent_setRegisterCallback (AHTEvent_register);     HTEvent_setRegisterCallback ((void *) AHTEvent_register);
    /*** a effacer ***/     HTEvent_setUnregisterCallback ((void *) AHTEvent_unregister);
    HTEvent_setUnregisterCallback (AHTEvent_unregister);  
         /***  ***/  
   
 #  ifndef _WINDOWS  #ifndef _WINDOWS
    HTEvent_setUnregisterCallback (AHTEvent_unregister);     HTTimer_registerSetTimerCallback ((void *) SetTimer);
 #  endif /* _WINDOWS */     HTTimer_registerDeleteTimerCallback ((void *) DeleteTimer);
   #endif /* !_WINDOWS */
   
   #ifdef AMAYA_WWW_CACHE
      /*** 
           WWW_TraceFlag = CACHE_TRACE;
      ***/
   #endif
   
 #ifdef DEBUG_LIBWWW  #ifdef DEBUG_LIBWWW
   WWW_TraceFlag = SHOW_CORE_TRACE | SHOW_THREAD_TRACE | PROT_TRACE;    /* forwards error messages to our own function */
      WWW_TraceFlag = THD_TRACE;
     HTTrace_setCallback(LineTrace);
 #endif  #endif
   
    /* Trace activation (for debugging) */     /* Trace activation (for debugging) */
    /*     /*
        WWW_TraceFlag = SHOW_CORE_TRACE | SHOW_THREAD_TRACE | PROT_TRACE;
   
       WWW_TraceFlag = SHOW_APP_TRACE | SHOW_UTIL_TRACE |        WWW_TraceFlag = SHOW_APP_TRACE | SHOW_UTIL_TRACE |
       SHOW_BIND_TRACE | SHOW_THREAD_TRACE |        SHOW_BIND_TRACE | SHOW_THREAD_TRACE |
       SHOW_STREAM_TRACE | SHOW_PROTOCOL_TRACE |        SHOW_STREAM_TRACE | SHOW_PROTOCOL_TRACE |
Line 1300  void                QueryInit () Line 1408  void                QueryInit ()
 #else  #else
    HTHost_setPersistTimeout (60L);     HTHost_setPersistTimeout (60L);
 #endif /* _WINDOWS */  #endif /* _WINDOWS */
      HTHost_setEventTimeout (1000);
   
    /* Cache is disabled in this version */  
    HTCacheMode_setEnabled (0);  
   
    /* Initialization of the global context */  
    Amaya = (AmayaContext *) TtaGetMemory (sizeof (AmayaContext));  
    Amaya->reqlist = HTList_new ();  
    Amaya->docid_status = HTList_new ();  
    Amaya->open_requests = 0;  
      
 #ifdef CATCH_SIG  #ifdef CATCH_SIG
    signal (SIGPIPE, SIG_IGN);     signal (SIGPIPE, SIG_IGN);
 #endif  #endif
   
 }  }
   
 #ifndef _WINDOWS  #ifndef _WINDOWS
Line 1339  static int          LoopForStop (AHTReqC Line 1438  static int          LoopForStop (AHTReqC
    while (me->reqStatus != HT_ABORT &&     while (me->reqStatus != HT_ABORT &&
           me->reqStatus != HT_END &&            me->reqStatus != HT_END &&
           me->reqStatus != HT_ERR) {            me->reqStatus != HT_ERR) {
          if (!AmayaAlive)           if (!AmayaIsAlive ())
             /* Amaya was killed by one of the callback handlers */              /* Amaya was killed by one of the callback handlers */
             exit (0);              exit (0);
   
Line 1377  static int          LoopForStop (AHTReqC Line 1476  static int          LoopForStop (AHTReqC
   closes all existing threads, frees all non-automatically deallocated    closes all existing threads, frees all non-automatically deallocated
   memory and then ends libwww.    memory and then ends libwww.
   ----------------------------------------------------------------------*/    ----------------------------------------------------------------------*/
 void                QueryClose ()  void QueryClose ()
 {  {
   
    AmayaAlive = FALSE;    AmayaAlive = FALSE;
   
    /* remove all the handlers and callbacks that may output a message to    /* remove all the handlers and callbacks that may output a message to
       a non-existent Amaya window */       a non-existent Amaya window */
   
    HTNet_deleteAfter (AHTLoadTerminate_handler);    HTNet_deleteAfter (AHTLoadTerminate_handler);
    HTNet_deleteAfter (redirection_handler);    HTNet_deleteAfter (redirection_handler);
    HTAlertCall_deleteAll (HTAlert_global () );    HTAlertCall_deleteAll (HTAlert_global () );
    HTAlert_setGlobal ((HTList *) NULL);    HTAlert_setGlobal ((HTList *) NULL);
    HTEvent_setRegisterCallback ((HTEvent_registerCallback *) NULL);    HTEvent_setRegisterCallback ((HTEvent_registerCallback *) NULL);
    HTEvent_setUnregisterCallback ((HTEvent_unregisterCallback *) NULL);    HTEvent_setUnregisterCallback ((HTEvent_unregisterCallback *) NULL);
     HTHost_setActivateRequestCallback (NULL);  #ifndef _WINDOWS
    Thread_deleteAll ();    /** need to erase all existing timers too **/
      HTTimer_registerSetTimerCallback (NULL);
      HTTimer_registerDeleteTimerCallback (NULL);
   #endif /* !_WINDOWS */
     HTHost_setActivateRequestCallback (NULL);
     Thread_deleteAll ();
     
    HTProxy_deleteAll ();    HTProxy_deleteAll ();
    HTNoProxy_deleteAll ();    HTNoProxy_deleteAll ();
    HTGateway_deleteAll ();    HTGateway_deleteAll ();
    AHTProfile_delete ();    AHTProfile_delete ();
   }
   
   /*----------------------------------------------------------------------
     NextNameValue
     ---------------------------------------------------------------------*/
   #ifdef __STDC__
   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 * start = NULL;
     if (!pstr || !*pstr) return NULL;
     
       if (!*p) {
         *pstr = p;
         *name = NULL;
         *value = NULL;
         return NULL;                                       /* No field */
       }
       
       /* Now search for the next '&' and ';' delimitators */
       start = p;
       while (*p && *p != '&' && *p != ';') p++;
       if (*p) 
         *p++ = '\0';
       *pstr = p;
   
       /* Search for the name and value */
       *name = start;
       p = start;
       
       while(*p && *p != '=') 
         p++;
       if (*p) 
         *p++ = '\0';
       *value = p;
   
       return start;
   }
   
   /*----------------------------------------------------------------------
     PrepareFormdata
     ---------------------------------------------------------------------*/
   #ifdef __STDC__
   static HTAssocList * PrepareFormdata (char *string)
   #else
   static HTAssocList * PrepareFormdata (string)
   char *string;
   #endif /* __STDC__ */
   {
     char * tmp_string, * tmp_string_ptr;
     char * name;
     char * value;
     HTAssocList * formdata;
   
     if (!string)
       return NULL;
   
     /* store the ptr in another variable, as the original address will
        change
        */
   
     tmp_string_ptr = tmp_string = TtaStrdup (string);
     formdata = HTAssocList_new();
     
     while (*tmp_string)
       {
         NextNameValue (&tmp_string, &name, &value);
         HTAssocList_addObject(formdata,
                               name, value);
       }
   
     TtaFreeMemory (tmp_string_ptr);
     return formdata;
 }  }
   
   
Line 1407  void                QueryClose () Line 1590  void                QueryClose ()
   in GetObjectWWW    in GetObjectWWW
   ---------------------------------------------------------------------*/    ---------------------------------------------------------------------*/
   
 #ifdef _STDC  #ifdef __STDC__
 void      InvokeGetObjectWWW_callback (int docid, char *urlName, char *outputfile, TTcbf *terminate_cbf, void *context_cbf, int status)  void      InvokeGetObjectWWW_callback (int docid, char *urlName, char *outputfile, TTcbf *terminate_cbf, void *context_tcbf, int status)
 #else  #else
 void      InvokeGetObjectWWW_callback (docid, urlName, outputfile, terminate_cbf, context_tcbf, status)  void      InvokeGetObjectWWW_callback (docid, urlName, outputfile, terminate_cbf, context_tcbf, status)
 int docid;  int docid;
Line 1416  char *urlName; Line 1599  char *urlName;
 char *outputfile;  char *outputfile;
 TTcbf *terminate_cbf;  TTcbf *terminate_cbf;
 void *context_tcbf;  void *context_tcbf;
 int status;  #endif /* __STDC__ */
 #endif /* _STDC */  
 {  {
   if (!terminate_cbf)    if (!terminate_cbf)
     return;      return;
       
   (*terminate_cbf) (docid, -1, urlName, outputfile,    (*terminate_cbf) (docid, status, urlName, outputfile,
                     NULL, context_tcbf);                        NULL, context_tcbf);  
 }  }
   
Line 1490  int status; Line 1672  int status;
     
   ----------------------------------------------------------------------*/    ----------------------------------------------------------------------*/
 #ifdef __STDC__  #ifdef __STDC__
 int GetObjectWWW (int docid, char* urlName, char* postString, char* outputfile, int mode,  int GetObjectWWW (int docid, char* urlName, char* postString,
                   TIcbf* incremental_cbf, void* context_icbf, TTcbf* terminate_cbf,                     char* outputfile, int mode, TIcbf* incremental_cbf, 
                     void* context_icbf, TTcbf* terminate_cbf, 
                   void* context_tcbf, boolean error_html, char *content_type)                    void* context_tcbf, boolean error_html, char *content_type)
 #else  #else
 int GetObjectWWW (docid, urlName, postString, outputfile, mode, incremental_cbf, context_icbf,   int GetObjectWWW (docid, urlName, postString, outputfile, mode, 
                     incremental_cbf, context_icbf, 
                   terminate_cbf, context_tcbf, error_html, content_type)                    terminate_cbf, context_tcbf, error_html, content_type)
 int           docid;  int           docid;
 char         *urlName;  char         *urlName;
Line 1514  char       *content_type; Line 1698  char       *content_type;
    int                 status, l;     int                 status, l;
    int                 tempsubdir;     int                 tempsubdir;
   
    if (urlName == NULL || outputfile == NULL) {     if (urlName == NULL || docid == 0 || outputfile == NULL) 
       /* no file to be loaded */       {
       TtaSetStatus (docid, 1, TtaGetMessage (AMAYA, AM_BAD_URL), urlName);         /* no file to be loaded */
          TtaSetStatus (docid, 1, TtaGetMessage (AMAYA, AM_BAD_URL), urlName);
                 
       if (error_html)         if (error_html)
          /* so we can show the error message */           /* so we can show the error message */
          DocNetworkStatus[docid] |= AMAYA_NET_ERROR;           DocNetworkStatus[docid] |= AMAYA_NET_ERROR;
       InvokeGetObjectWWW_callback (docid, urlName, outputfile, terminate_cbf,         InvokeGetObjectWWW_callback (docid, urlName, outputfile, terminate_cbf,
                                    context_tcbf, -1);                                      context_tcbf, HT_ERROR);
       return HT_ERROR;         return HT_ERROR;
    }       }
   
    /* do we support this protocol? */     /* do we support this protocol? */
    if (IsValidProtocol (urlName) == NO) {     if (IsValidProtocol (urlName) == NO) 
       /* return error */       {
       outputfile[0] = EOS;      /* file could not be opened */         /* return error */
       TtaSetStatus (docid, 1, TtaGetMessage (AMAYA, AM_GET_UNSUPPORTED_PROTOCOL), urlName);         outputfile[0] = EOS;     /* file could not be opened */
                TtaSetStatus (docid, 1, 
       if (error_html)                       TtaGetMessage (AMAYA, AM_GET_UNSUPPORTED_PROTOCOL),
                        urlName);
   
          if (error_html)
          /* so we can show the error message */           /* so we can show the error message */
          DocNetworkStatus[docid] |= AMAYA_NET_ERROR;           DocNetworkStatus[docid] |= AMAYA_NET_ERROR;
       InvokeGetObjectWWW_callback (docid, urlName, outputfile, terminate_cbf,         InvokeGetObjectWWW_callback (docid, urlName, outputfile, terminate_cbf,
                                    context_tcbf, -1);                                      context_tcbf, HT_ERROR);
       return HT_ERROR;         return HT_ERROR;
    }       }
   
    /* we store CSS in subdir named 0; all the other files go to a subidr     /* we store CSS in subdir named 0; all the other files go to a subidr
       named after their own docid */        named after their own docid */
         
    tempsubdir = (mode & AMAYA_LOAD_CSS) ? 0 : docid;     tempsubdir = (mode & AMAYA_LOAD_CSS) ? 0 : docid;
   
    /*create a tempfilename */     /* create a tempfilename */
    sprintf (outputfile, "%s%c%d%c%04dAM", TempFileDirectory, DIR_SEP, tempsubdir, DIR_SEP, object_counter);     sprintf (outputfile, "%s%c%d%c%04dAM", 
               TempFileDirectory, DIR_SEP, tempsubdir, DIR_SEP, object_counter);
    /* update the object_counter */     /* update the object_counter (used for the tempfilename) */
    object_counter++;     object_counter++;
      
    /* normalize the URL */     /* normalize the URL */
    ref = AmayaParseUrl (urlName, "", AMAYA_PARSE_ALL);     ref = AmayaParseUrl (urlName, "", AMAYA_PARSE_ALL);
    /* should we abort the request if we could not normalize the url? */     /* should we abort the request if we could not normalize the url? */
Line 1559  char       *content_type; Line 1748  char       *content_type;
       TtaSetStatus (docid, 1, TtaGetMessage (AMAYA, AM_BAD_URL), urlName);        TtaSetStatus (docid, 1, TtaGetMessage (AMAYA, AM_BAD_URL), urlName);
               
       if (error_html)        if (error_html)
          /* so we can show the error message */          /* so we can show the error message */
          DocNetworkStatus[docid] |= AMAYA_NET_ERROR;          DocNetworkStatus[docid] |= AMAYA_NET_ERROR;
       InvokeGetObjectWWW_callback (docid, urlName, outputfile, terminate_cbf,        InvokeGetObjectWWW_callback (docid, urlName, outputfile, terminate_cbf,
                                    context_tcbf, -1);                                     context_tcbf, HT_ERROR);
       return HT_ERROR;        return HT_ERROR;
    }     }
   
    /* verify if that file name existed */     /* verify if that file name existed */
    if (TtaFileExist (outputfile))     if (TtaFileExist (outputfile))
      TtaFileUnlink (outputfile);       TtaFileUnlink (outputfile);
      
    /* Initialize the request structure */     /* Initialize the request structure */
    me = AHTReqContext_new (docid);     me = AHTReqContext_new (docid);
    if (me == NULL) {     if (me == NULL) 
      outputfile[0] = EOS;       {
      /* need an error message here */         outputfile[0] = EOS;
      TtaFreeMemory (ref);         /* need an error message here */
      InvokeGetObjectWWW_callback (docid, urlName, outputfile, terminate_cbf,         TtaFreeMemory (ref);
                                    context_tcbf, -1);         InvokeGetObjectWWW_callback (docid, urlName, outputfile, terminate_cbf,
      return HT_ERROR;                                     context_tcbf, HT_ERROR);
    }         return HT_ERROR;
           }
   
    /* Specific initializations for POST and GET */     /* Specific initializations for POST and GET */
    if (mode & AMAYA_FORM_POST) {     if (mode & AMAYA_FORM_POST)
      me->method = METHOD_POST;       {
      if (postString) {         me->method = METHOD_POST;
        me->block_size = strlen (postString);         if (postString)
        me->mem_ptr = TtaStrdup (postString);           {
      } else {             me->mem_ptr = TtaStrdup (postString);
        me->mem_ptr = "";             me->block_size = strlen (postString);
        me->block_size = 0;           }
      }         HTRequest_setMethod (me->request, METHOD_POST);
      HTRequest_setMethod (me->request, METHOD_POST);       }
       HTRequest_setPostCallback (me->request, AHTUpload_callback);     else 
    } else {       {
      me->method = METHOD_GET;         me->method = METHOD_GET;
      me->dest = (HTParentAnchor *) NULL;        /*useful only for PUT and POST methods */         if (!HasKnownFileSuffix (ref))
      if (!HasKnownFileSuffix (ref))           HTRequest_setConversion(me->request, acceptTypes, TRUE);
        HTRequest_setConversion(me->request, acceptTypes, TRUE);       }
    }  
   
    /* Common initialization */     /* Common initialization for all HTML methods */
    me->mode = mode;     me->mode = mode;
    me->error_html = error_html;     me->error_html = error_html;
    me->incremental_cbf = incremental_cbf;     me->incremental_cbf = incremental_cbf;
Line 1609  char       *content_type; Line 1799  char       *content_type;
   
    /* for the async. request modes, we need to have our     /* for the async. request modes, we need to have our
       own copy of outputfile and urlname        own copy of outputfile and urlname
     */        */
   
    if ((mode & AMAYA_ASYNC) || (mode & AMAYA_IASYNC)) {     if ((mode & AMAYA_ASYNC) || (mode & AMAYA_IASYNC)) 
       l = strlen (outputfile);       {
       if (l > MAX_LENGTH)         l = strlen (outputfile);
         me->outputfile = TtaGetMemory (l + 2);         if (l > MAX_LENGTH)
       else           me->outputfile = TtaGetMemory (l + 2);
         me->outputfile = TtaGetMemory (MAX_LENGTH + 2);         else
       strcpy (me->outputfile, outputfile);           me->outputfile = TtaGetMemory (MAX_LENGTH + 2);
       l = strlen (urlName);         strcpy (me->outputfile, outputfile);
       if (l > MAX_LENGTH)         l = strlen (urlName);
         me->urlName = TtaGetMemory (l + 2);         if (l > MAX_LENGTH)
       else           me->urlName = TtaGetMemory (l + 2);
         me->urlName = TtaGetMemory (MAX_LENGTH + 2);         else
       strcpy (me->urlName, urlName);           me->urlName = TtaGetMemory (MAX_LENGTH + 2);
 #  ifdef _WINDOWS         strcpy (me->urlName, urlName);
       HTRequest_setPreemptive (me->request, NO);  #ifdef _WINDOWS
    } else {       /* force windows ASYNC requests to always be non preemptive */
      me->outputfile = outputfile;       HTRequest_setPreemptive (me->request, NO);
      me->urlName = urlName;  #endif /*_WINDOWS */
      me->content_type = content_type;       } /* AMAYA_ASYNC mode */ 
      HTRequest_setPreemptive (me->request, YES);     else 
    }  #ifdef _WINDOWS
 #  else /* !_WINDOWS */       {
    } else {         me->outputfile = outputfile;
      me->outputfile = outputfile;         me->urlName = urlName;
      me->urlName = urlName;         /* force windows SYNC requests to always be non preemptive */
      me->content_type = content_type;         HTRequest_setPreemptive (me->request, YES);
    }       }
      /***  #else /* !_WINDOWS */
        {
          me->outputfile = outputfile;
          me->urlName = urlName;
        }
      /***
      Change for taking into account the stop button:       Change for taking into account the stop button:
      The requests will be always asynchronous, however, if mode=AMAYA_SYNC,       The requests will be always asynchronous, however, if mode=AMAYA_SYNC,
      we will loop until the document has been received or a stop signal       we will loop until the document has been received or a stop signal
      generated       generated
      ****/       ****/
      HTRequest_setPreemptive (me->request, NO);     HTRequest_setPreemptive (me->request, NO);
 #  endif /* _WINDOWS */  #endif /* _WINDOWS */
   
    /* prepare the URLname that will be displayed in teh status bar */     /* prepare the URLname that will be displayed in teh status bar */
    ChopURL (me->status_urlName, me->urlName);     ChopURL (me->status_urlName, me->urlName);
   
    TtaSetStatus (me->docid, 1,      TtaSetStatus (me->docid, 1, 
                  TtaGetMessage (AMAYA, AM_FETCHING),                   TtaGetMessage (AMAYA, AM_FETCHING),
                  me->status_urlName);                   me->status_urlName);
Line 1658  char       *content_type; Line 1852  char       *content_type;
    TtaFreeMemory (ref);     TtaFreeMemory (ref);
   
    if (mode & AMAYA_NOCACHE)      if (mode & AMAYA_NOCACHE) 
         HTRequest_setReloadMode (me->request, HT_CACHE_FLUSH);
   
      /* prepare the query string and format for POST */
      if (mode & AMAYA_FORM_POST)
      {       {
       HTRequest_addGnHd (me->request, HT_G_PRAGMA_NO_CACHE);         HTAnchor_setFormat ((HTParentAnchor *) me->anchor, 
       HTRequest_addCacheControl (me->request, "no-cache", "");                             HTAtom_for ("application/x-www-form-urlencoded"));
       HTAnchor_clearHeader(me->anchor);         HTAnchor_setLength ((HTParentAnchor *) me->anchor, me->block_size);
      }         HTRequest_setEntityAnchor (me->request, me->anchor);
          HTRequest_setEntityAnchor (me->request, me->anchor);
          me->formdata = PrepareFormdata (postString);
        } 
   
    if (mode & AMAYA_FORM_POST) {     /* do the request */
       HTAnchor_setFormat ((HTParentAnchor *) me->anchor, HTAtom_for ("application/x-www-form-urlencoded"));     if (mode & AMAYA_FORM_POST)
       HTAnchor_setLength ((HTParentAnchor *) me->anchor, me->block_size);       status = HTPostFormAnchor (me->formdata, (HTAnchor *) me->anchor, 
       HTRequest_setEntityAnchor (me->request, me->anchor);                                  me->request);
            else
       status = HTLoadAbsolute (urlName, me->request);  
    } else  
      status = HTLoadAnchor ((HTAnchor *) me->anchor, me->request);       status = HTLoadAnchor ((HTAnchor *) me->anchor, me->request);
      
    if (status == HT_ERROR && me->reqStatus == HT_NEW)  
      {  
        InvokeGetObjectWWW_callback (docid, urlName, outputfile, terminate_cbf,  
                                     context_tcbf, -1);  
      }  
   
 #ifndef _WINDOWS     /* control the errors */
    if (status == HT_ERROR ||     if (status != HT_OK
     me->reqStatus == HT_END ||         && HTError_hasSeverity (HTRequest_error (me->request), ERR_NON_FATAL))
     me->reqStatus == HT_ERR)       status = HT_ERROR;
    {  
      /* in case of error, free all allocated memory and exit */  
      if (me->output && me->output != stdout) {  
 #ifdef DEBUG_LIBWWW        
        fprintf (stderr, "GetObjectWWW:: URL is  %s, closing "  
                 "FILE %p\n", me->urlName, me->output);   
 #endif  
        fclose (me->output);  
        me->output = NULL;  
      }  
             
      if (me->reqStatus == HT_ERR) {       /* test the effect of HTRequest_kill () */
         status = HT_ERROR;  
         /* show an error message on the status bar */  
         DocNetworkStatus[me->docid] |= AMAYA_NET_ERROR;  
         TtaSetStatus (me->docid, 1, TtaGetMessage (AMAYA, AM_CANNOT_LOAD), me->  
                       status_urlName);  
       } else  
         status = HT_OK;  
   
       AHTReqContext_delete (me);  
  } else {  
          /* part of the stop button handler */  
          if ((mode & AMAYA_SYNC) || (mode & AMAYA_ISYNC)) {  
             status = LoopForStop (me);  
             AHTReqContext_delete (me);  
          }  
    }  
 #else  /* !_WINDOWS */  
   
    if (status == HT_ERROR ||  
            me->reqStatus == HT_ERROR)  
      {  
            status = HT_ERROR;  
   
        /* in case of error, close any open files, free all allocated  
               memory and exit */  
        if (me->output && me->output != stdout)  
              {  
 #ifdef DEBUG_LIBWWW        
            fprintf (stderr, "GetObjectWWW: URL is  %s, closing "  
                     "FILE %p\n", me->urlName, me->output);   
 #endif  
            fclose (me->output);  
            me->output = NULL;  
          }  
             
        if (me->reqStatus == HT_ERR)   #if 0
              {       /** *this should go to term_d @@@@ */
               /* show an error message on the status bar */       if (me->reqStatus == HT_CACHE)
               DocNetworkStatus[me->docid] |= AMAYA_NET_ERROR;  
               TtaSetStatus (me->docid, 1,   
                   TtaGetMessage (AMAYA, AM_CANNOT_LOAD),  
                   me->status_urlName);  
          }  
      }   
        else   
           {  
             status = HT_OK;  
       }  
    
    /* part of the stop button handler */  
      if ((mode & AMAYA_SYNC) || (mode & AMAYA_ISYNC))  
        {         {
         if (HTRequest_net (me->request))           AHTPrintPendingRequestStatus (me->docid, YES);
            HTRequest_kill (me->request);           /* free the memory allocated for async requests */
         else           InvokeGetObjectWWW_callback (docid, urlName, outputfile, 
            AHTReqContext_delete (me);                                        terminate_cbf, context_tcbf, HT_OK);
            AHTReqContext_delete (me);
            return HT_OK;
        }         }
   #endif 
   
 #endif /* !_WINDOWS */     if (status == HT_ERROR)
        /* the request invocation failed */
        {
          /* show an error message on the status bar */
          DocNetworkStatus[docid] |= AMAYA_NET_ERROR;
          TtaSetStatus (docid, 1, 
                        TtaGetMessage (AMAYA, AM_CANNOT_LOAD),
                        urlName);
          if (me->reqStatus == HT_NEW)
            /* manually invoke the last processing that usually gets done
               in a succesful request */
            InvokeGetObjectWWW_callback (docid, urlName, outputfile, 
                                         terminate_cbf, context_tcbf, HT_ERROR);
          /* terminate_handler wasn't called */
          if (mode & AMAYA_SYNC || mode & AMAYA_ISYNC)
            AHTReqContext_delete (me);
        }
      else
      /* end treatment for SYNC requests */
   
    return (status);     if ((mode & AMAYA_SYNC) || (mode & AMAYA_ISYNC))
        {
   #ifndef _WINDOWS
          /* part of the UNIX stop button handler */
          if (status != HT_ERROR)
            status = LoopForStop (me);
   #endif /* _!WINDOWS */
          
          if (!HTRequest_kill (me->request))
            AHTReqContext_delete (me);
        }
       return (status);
 }  }
   
 /*----------------------------------------------------------------------  /*----------------------------------------------------------------------
Line 1813  PicType             contentType; Line 1981  PicType             contentType;
 TTcbf              *terminate_cbf;  TTcbf              *terminate_cbf;
 void               *context_tcbf;  void               *context_tcbf;
   
 #endif  #endif /* __STDC__ */
 {  {
    /*AHTReqContext      *me; */     AHTReqContext      *me;
    int                 status;     int                 status;
   
    int                 fd;     int                 fd;
    struct stat         file_stat;     struct stat         file_stat;
    char               *mem_ptr;     char               *fileURL;
    unsigned long       block_size;  
   
    AmayaLastHTTPErrorMsg [0] = EOS;     AmayaLastHTTPErrorMsg [0] = EOS;
         
    if (urlName == NULL || docid == 0 || fileName == NULL ||     if (urlName == NULL || docid == 0 || fileName == NULL 
        !TtaFileExist (fileName))         || !TtaFileExist (fileName))
       /* no file to be uploaded */        /* no file to be uploaded */
       return HT_ERROR;        return HT_ERROR;
   
Line 1839  void               *context_tcbf; Line 2005  void               *context_tcbf;
                       urlName);                        urlName);
         return HT_ERROR;          return HT_ERROR;
      }       }
    /* read the file into memory */  
 #  ifndef _WINDOWS     /* verify the file's size */
   #ifndef _WINDOWS
    if ((fd = open (fileName, O_RDONLY)) == -1)     if ((fd = open (fileName, O_RDONLY)) == -1)
 #  else /* _WINDOWS */  #else 
    if ((fd = open (fileName, _O_RDONLY | _O_BINARY)) == -1)     if ((fd = open (fileName, _O_RDONLY | _O_BINARY)) == -1)
 #  endif /* _WINDOWS */  #endif /* _WINDOWS */
      {       {
         /* if we could not open the file, exit */          /* if we could not open the file, exit */
         /*error msg here */          /*error msg here */
Line 1852  void               *context_tcbf; Line 2019  void               *context_tcbf;
      }       }
   
    fstat (fd, &file_stat);     fstat (fd, &file_stat);
      close (fd);
   
    if (file_stat.st_size == 0)     if (file_stat.st_size == 0)
      {       {
         /* file was empty */          /* file was empty */
         /*errmsg here */          /*errmsg here */
         close (fd);  
         return (HT_ERROR);          return (HT_ERROR);
      }       }
    block_size = file_stat.st_size;  
   
    if (THD_TRACE)  
       fprintf (stderr, "file size == %u\n", (unsigned) block_size);  
   
    mem_ptr = (char *) TtaGetMemory (block_size);  
   
    if (mem_ptr == (char *) NULL)     /* prepare the request context */
      {  
         /* could not allocate enough memory */  
         /*errmsg here */  
         close (fd);  
         return (HT_ERROR);  
      }  
    read (fd, mem_ptr, block_size);  
   
    close (fd);     if (THD_TRACE)
         fprintf (stderr, "file size == %u\n", (unsigned) file_stat.st_size);
    status = UploadMemWWW (docid, METHOD_PUT, urlName, contentType, mem_ptr,  
                           block_size, mode, terminate_cbf,  
                           context_tcbf, (char *) NULL);  
   
    TtaFreeMemory (mem_ptr);  
    TtaHandlePendingEvents ();  
    return (status);  
 }  
   
 /*----------------------------------------------------------------------  
   UploadMemWWW  
   low level interface function to libwww for uploading a block of  
   memory to a URL.  
   ----------------------------------------------------------------------*/  
 #ifdef __STDC__  
 int                 UploadMemWWW (int docid, HTMethod method,  
                      char *urlName, PicType contentType, char *mem_ptr, unsigned long block_size,  
                         int mode, TTcbf * terminate_cbf, void *context_tcbf,  
                                   char *outputfile)  
 #else  
 int                 UploadMemWWW (docid, method, urlName, contentType, mem_ptr, block_size, mode,  
                                   terminate_cbf, context_tcbf, outputfile)  
 int                 docid;  
 HTMethod            method;  
 char               *urlName;  
 PicType             contentType;  
 char               *mem_ptr;  
 usigned long        block_size;  
 int                 mode;  
 TTcbf              *terminate_cbf;  
 void               *context_tcbf;  
 char               *outputfile;  
   
 #endif  
 {  
    AHTReqContext      *me;  
    int                 status;  
   
    if (mem_ptr == (char *) NULL ||  
        block_size == 0 ||  
        docid == 0 ||  
        urlName == (char *) NULL)  
      {  
         /* nothing to be uploaded */  
         return HT_ERROR;  
      }  
   
    /* Initialize the request structure */  
    me = AHTReqContext_new (docid);     me = AHTReqContext_new (docid);
   
    if (me == NULL)     if (me == NULL)
Line 1934  char               *outputfile; Line 2041  char               *outputfile;
         TtaHandlePendingEvents ();          TtaHandlePendingEvents ();
         return (HT_ERROR);          return (HT_ERROR);
      }       }
    me->mode = mode;  
   
      me->mode = mode;
    me->incremental_cbf = (TIcbf *) NULL;     me->incremental_cbf = (TIcbf *) NULL;
    me->context_icbf = (void *) NULL;     me->context_icbf = (void *) NULL;
    me->terminate_cbf = terminate_cbf;     me->terminate_cbf = terminate_cbf;
    me->context_tcbf = context_tcbf;     me->context_tcbf = context_tcbf;
   
    me->output = stdout;  
    me->outputfile = (char *) NULL;  
    me->urlName = urlName;     me->urlName = urlName;
      me->block_size =  file_stat.st_size;
 #ifdef _WINDOWS  
    HTRequest_setPreemptive (me->request, YES);  
 #else  
    HTRequest_setPreemptive (me->request, NO);  
 #endif /* _WINDOWS */  
   
    /* select the parameters that distinguish a PUT from a GET/POST */     /* select the parameters that distinguish a PUT from a GET/POST */
    me->method = METHOD_PUT;     me->method = METHOD_PUT;
    HTRequest_setMethod (me->request, METHOD_PUT);     HTRequest_setMethod (me->request, METHOD_PUT);
Line 1958  char               *outputfile; Line 2056  char               *outputfile;
    /* 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 *) NULL;      me->outputfile = (char *) NULL; 
   
    me->mem_ptr = mem_ptr;     fileURL = HTParse (fileName, "file:/", PARSE_ALL);
    me->block_size = block_size;     me->anchor = (HTParentAnchor *) HTAnchor_findAddress (fileURL);
      HT_FREE (fileURL);
    /* set the callback which will actually copy data into the  
       output stream */  
   
    HTRequest_setPostCallback (me->request, AHTUpload_callback);  
   
    me->anchor = (HTParentAnchor *) HTAnchor_findAddress (urlName);  
   
    if (mode & AMAYA_NOCACHE)  
      {  
       HTRequest_addGnHd (me->request, HT_G_PRAGMA_NO_CACHE);  
       HTRequest_addCacheControl (me->request, "no-cache", "");  
       HTAnchor_clearHeader(me->anchor);  
      }  
   
    /* Set the Content-Type of the file we are uploading */     /* Set the Content-Type of the file we are uploading */
    HTAnchor_setFormat ((HTParentAnchor *) me->anchor,     HTAnchor_setFormat ((HTParentAnchor *) me->anchor,
                        AHTGuessAtom_for (me->urlName, contentType));                         AHTGuessAtom_for (me->urlName, contentType));
   
    HTAnchor_setLength ((HTParentAnchor *) me->anchor, me->block_size);     HTAnchor_setLength ((HTParentAnchor *) me->anchor, me->block_size);
   
    HTRequest_setEntityAnchor (me->request, me->anchor);     HTRequest_setEntityAnchor (me->request, me->anchor);
   #ifdef _WINDOWS
      HTRequest_setPreemptive (me->request, YES);
   #else
      HTRequest_setPreemptive (me->request, NO);
   #endif /* _WINDOWS */
   
      if (mode & AMAYA_NOCACHE)
        HTRequest_setReloadMode (me->request, HT_CACHE_FLUSH);
   
    /* prepare the URLname that will be displayed in teh status bar */     /* prepare the URLname that will be displayed in teh status bar */
    ChopURL (me->status_urlName, me->urlName);     ChopURL (me->status_urlName, me->urlName);
    TtaSetStatus (me->docid, 1, TtaGetMessage (AMAYA, AM_REMOTE_SAVING),     TtaSetStatus (me->docid, 1, TtaGetMessage (AMAYA, AM_REMOTE_SAVING),
                      me->status_urlName);                       me->status_urlName);
   
    status = HTLoadAbsolute (urlName, me->request);     status = HTPutDocumentAbsolute (me->anchor, urlName, me->request);
   
 #ifndef _WINDOWS     if (status != HT_ERROR && me->reqStatus != HT_ERR)
    if (status == HT_ERROR ||   
        me->reqStatus == HT_END ||   
        me->reqStatus == HT_ERR ||   
        HTError_hasSeverity (HTRequest_error (me->request), ERR_INFO))  
      {  
        status = HT_ERROR;  
      }       
    else  
      {       {
         /* part of the stop button handler */          /* part of the stop button handler */
   
         if ((mode & AMAYA_SYNC) || (mode & AMAYA_ISYNC))          if ((mode & AMAYA_SYNC) || (mode & AMAYA_ISYNC))
           {            {
              status = LoopForStop (me);               status = LoopForStop (me);
           }            }
      }       }
 #else /* _WINDOWS */     else
   if (status == HT_ERROR ||        {
           me->reqStatus == HT_ERR) /* || Error_hasSeverity (HTRequest_error (me->request), ERR_INFO)) */        if (! HTRequest_kill (me->request))
           status = HT_ERROR;  
   else  
           status = HT_OK;  
 #endif /* _WINDOWS */  
   
     if (HTRequest_net (me->request))  
         {  
          HTRequest_kill (me->request);  
         }  
     else   
         AHTReqContext_delete (me);          AHTReqContext_delete (me);
    return (status);       }
 }   
      TtaHandlePendingEvents ();
   
      return status;
   }
   
 /*----------------------------------------------------------------------  /*----------------------------------------------------------------------
   Stop Request    Stop Request
Line 2038  int                 docid; Line 2115  int                 docid;
    HTList             *cur;     HTList             *cur;
    AHTDocId_Status    *docid_status;     AHTDocId_Status    *docid_status;
    AHTReqContext      *me;     AHTReqContext      *me;
    HTNet              *reqNet;  
    HTHost             *reqHost;  
    HTChannel          *reqChannel;  
    int                 reqSock;  
 #ifdef DEBUG_LIBWWW  #ifdef DEBUG_LIBWWW
    int                 open_requests;     int                 open_requests;
 #endif /* DEBUG_LIBWWW */  #endif /* DEBUG_LIBWWW */
     
    if (Amaya)   
      if (Amaya && libDoStop)
      {       {
 #ifdef DEBUG_LIBWWW  #ifdef DEBUG_LIBWWW
        fprintf (stderr, "StopRequest: number of Amaya requests : %d\n", Amaya->open_requests);         fprintf (stderr, "StopRequest: number of Amaya requests : %d\n", 
                   Amaya->open_requests);
 #endif /* DEBUG_LIBWWW */  #endif /* DEBUG_LIBWWW */
   
         docid_status = (AHTDocId_Status *) GetDocIdStatus (docid,         docid_status = (AHTDocId_Status *) GetDocIdStatus (docid,
                                                        Amaya->docid_status);                                                            Amaya->docid_status);
         /* verify if there are any requests at all associated with docid */         /* verify if there are any requests at all associated with docid */
          
         if (docid_status == (AHTDocId_Status *) NULL)         if (docid_status == (AHTDocId_Status *) NULL)
            return;           return;
   
 #ifdef DEBUG_LIBWWW  #ifdef DEBUG_LIBWWW
         open_requests = docid_status->counter;         open_requests = docid_status->counter;
 #endif /* DEBUG_LIBWWW */  #endif /* DEBUG_LIBWWW */
   
         /* First, kill all pending requests */         /* First, kill all pending requests */
         /* We first inhibit the activation of pending requests */         /* We first inhibit the activation of pending requests */
         HTHost_disable_PendingReqLaunch ();         HTHost_disable_PendingReqLaunch ();
         cur = Amaya->reqlist;         cur = Amaya->reqlist;
         while ((me = (AHTReqContext *) HTList_nextObject (cur)))          while ((me = (AHTReqContext *) HTList_nextObject (cur))) 
           {           {
              if (me->docid == docid && me->reqStatus == HT_NEW)             if (me->docid == docid && me->reqStatus == HT_NEW)
                {               {
                  reqNet = HTRequest_net (me->request);                 /* If we have an ASYNC request, we kill it.
                  reqSock = HTNet_socket (reqNet);                 ** If it's a SYNC request, we just mark it as aborted
                  reqChannel = HTChannel_find(reqSock);                 */
                  reqHost = HTChannel_host (reqChannel);                 me->reqStatus = HT_ABORT;
                  if (((me->mode & AMAYA_IASYNC)
                  /* If we have an ASYNC request, we kill it.                      || (me->mode & AMAYA_ASYNC))
                  ** If it's a SYNC request, we just mark it as aborted                     && !(me->mode & AMAYA_ASYNC_SAFE_STOP))
                  */                   {
                  me->reqStatus = HT_ABORT;                     /* delete the amaya/libwww request context */
                  if (((me->mode & AMAYA_IASYNC)                     if (!HTRequest_kill (me->request))
                      ||  (me->mode & AMAYA_ASYNC))                       /* if the above function returns NO (0), it means
                      && !(me->mode & AMAYA_ASYNC_SAFE_STOP))                       ** that there was no network context and that 
                    {                       ** terminate_handler wasn't called. So, we erase
                      if (HTRequest_net (me->request))                       ** this context ourselves
                        /* delete the libwww request context */                       */
                        HTRequest_kill (me->request);  
 #ifndef _WINDOWS  
                      /* delete the Amaya request context */  
                      AHTReqContext_delete (me);                       AHTReqContext_delete (me);
 #endif /* !_WINDOWS */                     
                      cur = Amaya->reqlist;                     cur = Amaya->reqlist;
 #ifdef DEBUG_LIBWWW  
                      /* update the number of open requests */  
                      open_requests--;                
 #endif /* DEBUG_LIBWWW */  
                    }  
   
                  if (HTHost_isIdle (reqHost) ) {  
 #ifdef DEBUG_LIBWWW  #ifdef DEBUG_LIBWWW
                    fprintf (stderr, "Host is idle, killing socket %d\n",                     /* update the number of open requests */
                             reqSock);                     open_requests--;                
 #endif /* DEBUG_LIBWWW */  #endif /* DEBUG_LIBWWW */
   
                    HTEvent_unregister (reqSock, FD_ALL);  
                    HTEvent_register(reqSock, NULL, (SockOps) FD_READ,  
                                     HTHost_catchClose,  HT_PRIORITY_MAX);  
                    NETCLOSE (reqSock);  
                    /*     
                    if (reqChannel && reqHost)  
                    HTHost_clearChannel(reqHost, HT_OK);  
                    HTHost_catchClose (reqSock, NULL, FD_CLOSE);  
                    */  
                  }                   }
                }               }
           }           }
         /* enable the activation of pending requests */  
         HTHost_enable_PendingReqLaunch ();  
   
         cur = Amaya->reqlist;          /* enable the activation of pending requests */
         while ((me = (AHTReqContext *) HTList_nextObject (cur)))         HTHost_enable_PendingReqLaunch ();
           {  
              if (me->docid == docid)  
                {  
                  /* kill this request */  
   
                  switch (me->reqStatus)         cur = Amaya->reqlist;
                    {         while ((me = (AHTReqContext *) HTList_nextObject (cur)))
                    case HT_ABORT:           {
              if (me->docid == docid)
                {
                  /* kill this request */
                  
                  switch (me->reqStatus)
                    {
                    case HT_ABORT:
 #ifdef DEBUG_LIBWWW  #ifdef DEBUG_LIBWWW
 fprintf (stderr, "Stop: url %s says abort", me->urlName);                     fprintf (stderr, "Stop: url %s says abort", me->urlName);
 #endif /* DEBUG_LIBWWW */  #endif /* DEBUG_LIBWWW */
                      break;                     break;
                                       
                    case HT_END:                   case HT_END:
 #ifdef DEBUG_LIBWWW  #ifdef DEBUG_LIBWWW
 fprintf (stderr, "Stop: url %s says end", me->urlName);                     fprintf (stderr, "Stop: url %s says end", me->urlName);
 #endif /* DEBUG_LIBWWW */  #endif /* DEBUG_LIBWWW */
                      break;                     break;
   
                    case HT_BUSY:                   case HT_BUSY:
                      me->reqStatus = HT_ABORT;                     me->reqStatus = HT_ABORT;
 #ifdef DEBUG_LIBWWW  #ifdef DEBUG_LIBWWW
 fprintf (stderr, "Stop: url %s going from busy to abort\n", me->urlName);                     fprintf (stderr, "Stop: url %s going from busy to abort\n",
                               me->urlName);
 #endif /* DEBUG_LIBWWW */  #endif /* DEBUG_LIBWWW */
                      break;                     break;
   
                    case HT_NEW_PENDING:                   case HT_NEW_PENDING:
                    case HT_WAITING:                   case HT_WAITING:
                    default:                   default:
 #ifdef DEBUG_LIBWWW  #ifdef DEBUG_LIBWWW
 fprintf (stderr, "Stop: url %s says NEW_PENDING, WAITING", me->urlName);                     fprintf (stderr, "Stop: url %s says NEW_PENDING, WAITING",
                               me->urlName);
 #endif /* DEBUG_LIBWWW */  #endif /* DEBUG_LIBWWW */
                      me->reqStatus = HT_ABORT;                     me->reqStatus = HT_ABORT;
                        
 #                 ifndef _WINDOWS  
                      RequestKillAllXtevents (me);  
 #                 endif _WINDOWS  
   
                      reqNet = HTRequest_net (me->request);  
                      reqSock = HTNet_socket (reqNet);  
                      reqChannel = HTChannel_find(reqSock);  
                      reqHost = HTChannel_host (reqChannel);  
   
                  if (((me->mode & AMAYA_IASYNC)  
                      ||  (me->mode & AMAYA_ASYNC))  
                      && !(me->mode & AMAYA_ASYNC_SAFE_STOP))  
                    {  
                      if (HTRequest_net (me->request))  
                        /* delete the libwww request context */  
                        HTRequest_kill (me->request);  
 #ifndef _WINDOWS  
                      /* delete the Amaya request context */  
                      AHTReqContext_delete (me);  
 #endif /* !_WINDOWS */  
                      cur = Amaya->reqlist;  
 #ifdef DEBUG_LIBWWW  
                      /* update the number of open requests */  
                      open_requests--;                
 #endif /* DEBUG_LIBWWW */  
                    }  
   
                      /* if there are no more requests, then close                     if (((me->mode & AMAYA_IASYNC)
                         the connection */                          || (me->mode & AMAYA_ASYNC))
                                               && !(me->mode & AMAYA_ASYNC_SAFE_STOP))
                      if (HTHost_isIdle (reqHost) ) {                       {
 #ifdef                        DEBUG_LIBWWW                         /* delete the amaya/libwww request context */
                        fprintf (stderr, "Host is idle, "                         if (!HTRequest_kill (me->request))
                                 "killing socket %d\n",                           /* if the above function returns NO (0), it means
                                 reqSock);                           ** that there was no network context and that 
 #endif                        /* DEBUG_LIBWWW */                           ** terminate_handler wasn't called. So, we erase
                        HTEvent_unregister (reqSock, FD_ALL);                           ** this context ourselves
                        HTEvent_register(reqSock,  
                                         NULL,  
                                         (SockOps) FD_READ,  
                                         HTHost_catchClose,  
                                         HT_PRIORITY_MAX);  
                        NETCLOSE (reqSock);                                
                        HTHost_clearChannel (reqHost, HT_ERROR);  
                        /*  
                          if (reqChannel && reqHost)  
                          HTHost_clearChannel(reqHost, HT_OK);  
                          HTHost_catchClose (reqSock, NULL, FD_CLOSE);  
                          */                           */
 #ifdef                          DEBUG_LIBWWW                                                       AHTReqContext_delete (me);
                        fprintf (stderr, "After killing, "  
                                 "HTHost_isIdle gives %d\n",                         cur = Amaya->reqlist;
                                 HTHost_isIdle (reqHost));  #ifdef DEBUG_LIBWWW
 #endif                          /* DEBUG_LIBWWW */                         /* update the number of open requests */
                          open_requests--;            
   #endif /* DEBUG_LIBWWW */
                      }                       }
   
   #ifdef DEBUG_LIBWWW
                      if (HTHost_isIdle (reqHost))
                        fprintf (stderr, "StopRequst: After killing, Host is "
                                 "idle\n");
                      else
                        fprintf (stderr, "StopRequest: After killing, Host isn't "
                                 "idle\n");
   #endif /* DEBUG_LIBWWW */
   
 #ifdef DEBUG_LIBWWW                    #ifdef DEBUG_LIBWWW                  
                      open_requests--;                 open_requests--;
 #endif /* DEBUG_LIBWWW */                      #endif /* DEBUG_LIBWWW */                    
                      break;                       break;
                                             
                    }    /* switch */                   }      /* switch */
                }                /* if me docid */               }          /* if me docid */
           }                     /* while */           }                      /* while */
          
 #ifdef DEBUG_LIBWWW  #ifdef DEBUG_LIBWWW
         fprintf (stderr, "StopRequest: number of Amaya requests : %d\n", Amaya->open_requests);         fprintf (stderr, "StopRequest: number of Amaya requests : "
                   "%d\n", Amaya->open_requests);
 #endif /* DEBUG_LIBWWW */  #endif /* DEBUG_LIBWWW */
   
      }                          /* if amaya open requests */       }                          /* if amaya open requests */
         
 } /* StopRequest */  } /* StopRequest */
   
 /*  
   end of Module query.c  
 */  
   
 /*----------------------------------------------------------------------  /*----------------------------------------------------------------------
   AmayaIsAlive    AmayaIsAlive
Line 2243  boolean AmayaIsAlive () Line 2271  boolean AmayaIsAlive ()
 {  {
   return AmayaAlive;    return AmayaAlive;
 }  }
 #endif /* AMAYA_JAVA */  
   
   #endif /* AMAYA_JAVA */
   
   /*
     end of Module query.c
   */
   
   

Removed from v.1.115  
changed lines
  Added in v.1.116


Webmaster