Diff for /Amaya/amaya/query.c between versions 1.73 and 1.74

version 1.73, 1997/07/03 12:43:29 version 1.74, 1997/07/08 08:20:11
Line 253  int                 docid; Line 253  int                 docid;
    /* error stream handling */     /* error stream handling */
    me->error_stream = (char *) NULL;     me->error_stream = (char *) NULL;
    me->error_stream_size = 0;     me->error_stream_size = 0;
      
   #ifdef DEBUG_LIBWWW
      fprintf (stderr, "AHTReqContext_new: Created object %p\n", me);
   #endif   
    return me;     return me;
   
 }  }
   
 /*----------------------------------------------------------------------  /*----------------------------------------------------------------------
Line 276  AHTReqContext      *me; Line 280  AHTReqContext      *me;
    if (me)     if (me)
      {       {
   
   #ifdef DEBUG_LIBWWW
           fprintf (stderr, "AHTReqContext_delete: Deleting object %p\n", me);
   #endif   
   
         if (Amaya->reqlist)          if (Amaya->reqlist)
            HTList_removeObject (Amaya->reqlist, (void *) me);             HTList_removeObject (Amaya->reqlist, (void *) me);
   
Line 302  AHTReqContext      *me; Line 310  AHTReqContext      *me;
           RequestKillAllXtevents(me);            RequestKillAllXtevents(me);
 #     endif /* WWW_XWINDOWS */  #     endif /* WWW_XWINDOWS */
 #     endif /* !_WINDOWS */  #     endif /* !_WINDOWS */
   
           if ((me->mode & AMAYA_ASYNC) || (me->mode & AMAYA_IASYNC))
             /* for the ASYNC mode, free the memory we allocated in GetObjectWWW
                or in PutObjectWWW */
             {
               TtaFreeMemory (me->urlName);
               me->urlName = NULL;
               TtaFreeMemory (me->outputfile);
               me->outputfile = NULL;
             }
      
         TtaFreeMemory ((void *) me);          TtaFreeMemory ((void *) me);
   
         Amaya->open_requests--;          Amaya->open_requests--;
Line 346  HTStream           *target; Line 365  HTStream           *target;
      {       {
         if (PROT_TRACE)          if (PROT_TRACE)
            HTTrace ("Posting Data Target WOULD BLOCK\n");             HTTrace ("Posting Data Target WOULD BLOCK\n");
   #ifdef _WINDOWS
           return HT_CONTINUE;
   #else
           return HT_WOULD_BLOCK;
   #endif /* _WINDOWS */
   
         return HT_WOULD_BLOCK;          return HT_WOULD_BLOCK;
      }       }
    else if (status == HT_PAUSE)     else if (status == HT_PAUSE)
Line 382  static void         Thread_deleteAll () Line 407  static void         Thread_deleteAll ()
   AHTReqContext      *me;    AHTReqContext      *me;
   AHTDocId_Status    *docid_status;    AHTDocId_Status    *docid_status;
   
    if (Amaya && Amaya->reqlist)    if (Amaya && Amaya->reqlist)
      {      {
         if (Amaya->open_requests > 0)        if (Amaya->open_requests > 0)
           {  #ifdef DEBUG_LIBWWW
             cur = Amaya->reqlist;        fprintf (stderr, "Thread_deleteAll: Killing %d outstanding "
                          "requests\n", Amaya->open_requests);
              HTNet_killAll ();  #endif   
              /* erase the requests */          {
              while ((me = (AHTReqContext *) HTList_removeLastObject (cur)))            cur = Amaya->reqlist;
                {            
                   if (me->request)            HTNet_killAll ();
                     {            /* erase the requests */
             while ((me = (AHTReqContext *) HTList_removeLastObject (cur)))
               {
                 if (me->request)
                   {
 #              ifndef _WINDOWS   #              ifndef _WINDOWS 
                        RequestKillAllXtevents (me);                    RequestKillAllXtevents (me);
 #              endif /* !_WINDOWS */  #              endif /* !_WINDOWS */
                        AHTReqContext_delete (me);                    AHTReqContext_delete (me);
                     }                  }
                }                /* while */              }           /* while */
             
              /* erase the docid_status entities */            /* erase the docid_status entities */
              while ((docid_status = (AHTDocId_Status *) HTList_removeLastObject ((void *) Amaya->docid_status)))            while ((docid_status = (AHTDocId_Status *) HTList_removeLastObject ((void *) Amaya->docid_status)))
                 TtaFreeMemory ((void *) docid_status);              TtaFreeMemory ((void *) docid_status);
             
           }                     /* if */          }                       /* if */
      }      }
 }  }
   
 /*----------------------------------------------------------------------  /*----------------------------------------------------------------------
Line 464  int                 status; Line 493  int                 status;
         
    if (HTRequest_doRetry (request))     if (HTRequest_doRetry (request))
      {       {
   
         /* Verify if this is not redundant */          /* Verify if this is not redundant */
   
         /* do we need to normalize the URL? */          /* do we need to normalize the URL? */
         if (strncmp (new_anchor->parent->address, "http:", 5))          if (strncmp (new_anchor->parent->address, "http:", 5))
           {            {
              /* Yes, so we use the pre-redirection anchor as a base name */               /* Yes, so we use the pre-redirection anchor as a base name */
              ref = AmayaParseUrl (new_anchor->parent->address, me->urlName, AMAYA_PARSE_ALL);               ref = AmayaParseUrl (new_anchor->parent->address, 
                                     me->urlName, AMAYA_PARSE_ALL);
              if (ref)               if (ref)
                {                 {
                   TtaFreeMemory (new_anchor->parent->address);                   TtaFreeMemory (new_anchor->parent->address);
                   new_anchor->parent->address = ref;                   new_anchor->parent->address = ref;
                }                 }
           }            }
   
         /* update the current file name */          /* update the current file name */
         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, 
                 ** copy MAX_LENGTH cars. The error will be detected later on and shown on the                        MAX_LENGTH - 1);
                 ** screen. This code will be fixed up later on  
               */  
              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);
   
Line 500  int                 status; Line 526  int                 status;
         /* Start request with new credentials */          /* Start request with new credentials */
   
         if (me->output) {          if (me->output) {
 #ifdef JOSE  #ifdef DEBUG_LIBWWW
             fprintf (stderr, "redirection_handler: url  %s, closing fd %d\n", me->urlName, me->output);               fprintf (stderr, "redirection_handler: New URL is  %s, closing "
 #endif                               "FILE %p\n", me->urlName, me->output); 
   #endif 
             AHTFWriter_FREE (request->output_stream);              AHTFWriter_FREE (request->output_stream);
             fclose (me->output);              if (me->output != stdout) { /* Are we writing to a file? */
             me->output = NULL;                fclose (me->output);
                 me->output = NULL;
               }
         }          }
   
   # ifdef _WINDOWS
           /* if ((me->mode & AMAYA_ASYNC) ||      (me->mode & AMAYA_IASYNC)) {
              me->reqStatus = HT_END; */
           /* HTEventrg_unregister (me->read_sock, 0); */
           /* }  */
   # endif /* _WINDOWS */
   
         me->reqStatus = HT_NEW; /* reset the status */          me->reqStatus = HT_NEW; /* reset the status */
         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
            HTLoadAnchor (new_anchor, request);            HTLoadAnchor (new_anchor, request);
      }       }
    else     else
      {       {
         HTRequest_addError (request, ERR_FATAL, NO, HTERR_MAX_REDIRECT,         HTRequest_addError (request, ERR_FATAL, NO, HTERR_MAX_REDIRECT,
                             NULL, 0, "HTRedirectFilter");                             NULL, 0, "HTRedirectFilter");
         TtaSetStatus (me->docid, 1, TtaGetMessage (AMAYA, AM_REDIRECTIONS_LIMIT),         TtaSetStatus (me->docid, 1, TtaGetMessage (AMAYA, AM_REDIRECTIONS_LIMIT),
                       NULL);                       NULL);
         if (me->error_html)         if (me->error_html)
            DocNetworkStatus[me->docid] |= AMAYA_NET_ERROR; /* so we can show the error message */           DocNetworkStatus[me->docid] |= AMAYA_NET_ERROR; 
          /* so that we can show the error message */
      }       }
   
    /*     /*
       **  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 
       **  request object now when we have just started a new one ourselves     **  request object now when we have just started a new one ourselves
     */     */
    return HT_ERROR;     return HT_ERROR;
 }  }
   
Line 554  int                 status; Line 591  int                 status;
    HTList              *cur;     HTList              *cur;
   
    if (!me)     if (!me)
       return HT_OK;             /* not an Amaya request */       return HT_OK;              /* not an Amaya request */
      
    if (!AmayaIsAlive)     if (!AmayaIsAlive)
       me->reqStatus = HT_ABORT;       me->reqStatus = HT_ABORT;
      
    if (status == HT_LOADED || status == HT_CREATED || status == HT_NO_DATA)     if (status == HT_LOADED || status == HT_CREATED || status == HT_NO_DATA)
        error_flag = FALSE;       error_flag = FALSE;
    else     else
        error_flag = TRUE;       error_flag = TRUE;
      
    /* output any errors from the server */     /* output any errors from the server */
      
     /***     /***
     ** me->output = output file which will receive an html file     ** me->output = output file which will receive an html file
     ** me->error_html = yes, output HTML errors in the screen     ** me->error_html = yes, output HTML errors in the screen
     ** request->error_stack == if there are any errors, they will be here     ** request->error_stack == if there are any errors, they will be here
     ** me->error_stream_size If it's != 0 means an error message has already     ** me->error_stream_size If it's != 0 means an error message has already
     **                       been written to the stack     **                       been written to the stack
     */     */
      
    /* First, we verify if there are any errors and if they are not     /* First, we verify if there are any errors and if they are not
    ** yet written to the error stack. If no, then let's try to write them     ** yet written to the error stack. If no, then let's try to write them
    ** ourselves     ** ourselves
    */     */
      
 #ifdef JOSE  #ifdef DEBUG_LIBWWW
            fprintf (stderr, "terminate_handler: url  %s, closing fd %d\n", me->urlName, me->output);      fprintf (stderr, "terminate_handler: URL is "
               "%s, closing FILE %p status is %d\n", me->urlName, me->output, 
               status); 
 #endif  #endif
      
    if (me->output && me->output != stdout)     if (me->output && me->output != stdout)
      {       {
         /* we are writing to a file */         /* we are writing to a file */
         if (me->reqStatus != HT_ABORT)         if (me->reqStatus != HT_ABORT)
           {                     /* if the request was not aborted and */           {                      /* if the request was not aborted and */
             if (error_flag)             if (error_flag)
               {         /* there were some errors */               {                  /* there were some errors */
                 if (me->error_html == TRUE)                 if (me->error_html == TRUE)
                   {             /* and we want to print errors */                   {              /* and we want to print errors */
                     if (me->error_stream_size == 0)     /* and the stream is empty */                     if (me->error_stream_size == 0)/* and the stream is empty */
                           AHTError_MemPrint (request);  /* copy errors from the error stack                        AHTError_MemPrint (request); /* copy errors from 
                                                            ** into a data structure */                                                    **the error stack 
                        if (me->error_stream)                                                    ** into a data structure */
                          {      /* if the stream is non-empty */                     if (me->error_stream)
                             fprintf (me->output, me->error_stream);     /* output the errors */                       {  /* if the stream is non-empty */
                             error_flag = FALSE;         /* show it in the HTML window */                         fprintf (me->output, me->error_stream);/* output the errors */
                          }                         error_flag = FALSE;              /* show it in the HTML window */
                        else                       }
                           me->reqStatus = HT_ERR;       /* we did not get an error msg,                      else
                                                            ** so just                       me->reqStatus = HT_ERR;    /* we did not get an error msg, 
                                                            **  mark error                                                   ** so just markerror */
                                                          */                   }
                     }                 else
                   else                   me->reqStatus = HT_ERR;        /* we don't want to print the error */
                      me->reqStatus = HT_ERR;    /* we don't want to print the error */               }                  /* if error_stack */
                }                /* if error_stack */           }                      /* if != HT_ABORT */
           }                     /* if != HT_ABORT */         fclose (me->output);
         fclose (me->output);         me->output = NULL;
         me->output = NULL;  
      }       }
    else     else
      {       {
         /* We must be doing a PUT. Verify if there was an error */         /* We must be doing a PUT. Verify if there was an error */
         if (error_flag)         if (error_flag)
           me->reqStatus = HT_ERR;           me->reqStatus = HT_ERR;
      }                          /* if me-output */       }                          /* if me-output */
      
    /* Second Step: choose a correct treatment in function of the request's     /* Second Step: choose a correct treatment in function of the request's
       being associated with an error, with an interruption, or with a        being associated with an error, with an interruption, or with a
       succesful completion */        succesful completion */
      
    if (!error_flag  && me->reqStatus != HT_ERR     if (!error_flag  && me->reqStatus != HT_ERR
        && me->reqStatus != HT_ABORT)         && me->reqStatus != HT_ABORT)
      {       {
         me->reqStatus = HT_END; /* no errors */         me->reqStatus = HT_END;  /* no errors */
         if (me->terminate_cbf)         if (me->terminate_cbf)
            (*me->terminate_cbf) ((AHTReqContext *) me,           (*me->terminate_cbf) ((AHTReqContext *) me,
                                  HT_LOADED);                                 HT_LOADED);
      }       }
    else if (me->reqStatus == HT_ABORT)     else if (me->reqStatus == HT_ABORT)
      /* either the application ended or the user pressed the stop        /* either the application ended or the user pressed the stop 
         button. We erase the incoming file, if it exists */          button. We erase the incoming file, if it exists */
      {       {
         if (me->outputfile && me->outputfile[0] != EOS)         if (me->outputfile && me->outputfile[0] != EOS)
           {           {
              TtaFileUnlink (me->outputfile);             TtaFileUnlink (me->outputfile);
              me->outputfile[0] = EOS;             me->outputfile[0] = EOS;
           }           }
      }       }
    else if (me->reqStatus == HT_ERR)     else if (me->reqStatus == HT_ERR)
      {       {
         /* there was an error */         /* there was an error */
         if (me->terminate_cbf)         if (me->terminate_cbf)
            (*me->terminate_cbf) ((AHTReqContext *) me,           (*me->terminate_cbf) ((AHTReqContext *) me,
                                  HT_ERROR);                                 HT_ERROR);
          
         if (me->outputfile && me->outputfile[0] != EOS)         if (me->outputfile && me->outputfile[0] != EOS)
           {           {
              TtaFileUnlink (me->outputfile);             TtaFileUnlink (me->outputfile);
              me->outputfile[0] = EOS;             me->outputfile[0] = EOS;
           }           }
      }       }
    else if (error_flag &&      else if (error_flag && 
             (me->reqStatus == HT_BUSY || me->reqStatus == HT_WAITING))              (me->reqStatus == HT_BUSY || me->reqStatus == HT_WAITING))
      {       {
         /* there was an error */         /* there was an error */
         if (me->terminate_cbf)         if (me->terminate_cbf)
            (*me->terminate_cbf) ((AHTReqContext *) me,           (*me->terminate_cbf) ((AHTReqContext *) me,
                                  HT_ERROR);                                 HT_ERROR);
          
         if (me->outputfile && me->outputfile[0] != EOS)         if (me->outputfile && me->outputfile[0] != EOS)
           {           {
              TtaFileUnlink (me->outputfile);             TtaFileUnlink (me->outputfile);
              me->outputfile[0] = EOS;             me->outputfile[0] = EOS;
              me->reqStatus = HT_ERR;             me->reqStatus = HT_ERR;
           }           }
      }                          /* if-else HT_END, HT_ABORT, HT_ERROR */       }                          /* if-else HT_END, HT_ABORT, HT_ERROR */
      
    if ((me->mode & AMAYA_ASYNC) || (me->mode & AMAYA_IASYNC))  
      /* for the ASYNC mode, free the memory we allocated in GetObjectWWW  
         or in PutObjectWWW */  
      {  
         TtaFreeMemory (me->urlName);  
         me->urlName = NULL;  
         TtaFreeMemory (me->outputfile);  
         me->outputfile = NULL;  
      }  
   
    /* 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) ||
                          (me->method == METHOD_PUT)))                           (me->method == METHOD_PUT)))
      {       {
        /* output the status of the request */         /* output the status of the request */
        if (status == 200)         if (status == 200)
          TtaSetStatus (me->docid, 1, TtaGetMessage (AMAYA, AM_REQUEST_SUCCEEDED), me->status_urlName);           TtaSetStatus (me->docid, 1,  
                          TtaGetMessage (AMAYA, AM_REQUEST_SUCCEEDED),
                          me->status_urlName);
        else if (status == 201)         else if (status == 201)
          TtaSetStatus (me->docid, 1, TtaGetMessage (AMAYA, AM_CREATED_NEW_REMOTE_RESSOURCE), me->status_urlName);           TtaSetStatus (me->docid, 1, 
                          TtaGetMessage (AMAYA, AM_CREATED_NEW_REMOTE_RESSOURCE),
                          me->status_urlName);
        else if (status == 204 && me->method == METHOD_PUT)         else if (status == 204 && me->method == METHOD_PUT)
          TtaSetStatus (me->docid, 1, TtaGetMessage (AMAYA, AM_UPDATED_REMOTE_RESSOURCE), me->status_urlName);           TtaSetStatus (me->docid, 1,
                          TtaGetMessage (AMAYA, AM_UPDATED_REMOTE_RESSOURCE),
                          me->status_urlName);
        else if (status == 204 && me->method == METHOD_PUT)         else if (status == 204 && me->method == METHOD_PUT)
          TtaSetStatus (me->docid, 1, TtaGetMessage (AMAYA, AM_NO_DATA), (char *) NULL);           TtaSetStatus (me->docid, 1, 
                          TtaGetMessage (AMAYA, AM_NO_DATA), 
                          (char *) NULL);
        else if (status == -400 || status == 505)         else if (status == -400 || status == 505)
          {           {
          TtaSetStatus (me->docid, 1, TtaGetMessage (AMAYA, AM_SERVER_DID_NOT_UNDERSTAND_REQ_SYNTAX), (char *) NULL);           TtaSetStatus (me->docid, 1, 
            sprintf (AmayaLastHTTPErrorMsg, TtaGetMessage (AMAYA, AM_SERVER_DID_NOT_UNDERSTAND_REQ_SYNTAX));                         TtaGetMessage (AMAYA, 
                                         AM_SERVER_DID_NOT_UNDERSTAND_REQ_SYNTAX),
                          (char *) NULL);
            sprintf (AmayaLastHTTPErrorMsg, 
                     TtaGetMessage (AMAYA,
                                    AM_SERVER_DID_NOT_UNDERSTAND_REQ_SYNTAX));
          }           }
        else if (status == -401)          else if (status == -401) 
          {           {
            TtaSetStatus (me->docid, 1,             TtaSetStatus (me->docid, 1,
                          TtaGetMessage (AMAYA, AM_AUTHENTICATION_FAILURE), me->status_urlName);                           TtaGetMessage (AMAYA, 
            sprintf (AmayaLastHTTPErrorMsg, TtaGetMessage (AMAYA, AM_AUTHENTICATION_FAILURE), me->status_urlName);                                          AM_AUTHENTICATION_FAILURE), 
                            me->status_urlName);
              sprintf (AmayaLastHTTPErrorMsg, 
                       TtaGetMessage (AMAYA, AM_AUTHENTICATION_FAILURE),
                       me->status_urlName);
          }           }
        else if (status == -403)         else if (status == -403)
          {           {
            TtaSetStatus (me->docid, 1,             TtaSetStatus (me->docid, 1,
                          TtaGetMessage (AMAYA, AM_FORBIDDEN_ACCESS), me->status_urlName);                           TtaGetMessage (AMAYA, AM_FORBIDDEN_ACCESS),
            sprintf (AmayaLastHTTPErrorMsg, TtaGetMessage (AMAYA, AM_FORBIDDEN_ACCESS), me->urlName);                           me->status_urlName);
              sprintf (AmayaLastHTTPErrorMsg, 
                       TtaGetMessage (AMAYA, AM_FORBIDDEN_ACCESS), 
                       me->urlName);
          }           }
        else if (status == -405)         else if (status == -405)
          {           {
          TtaSetStatus (me->docid, 1, TtaGetMessage (AMAYA, AM_METHOD_NOT_ALLOWED), (char *) NULL);           TtaSetStatus (me->docid, 1, 
          sprintf(AmayaLastHTTPErrorMsg, TtaGetMessage (AMAYA, AM_METHOD_NOT_ALLOWED));                         TtaGetMessage (AMAYA, AM_METHOD_NOT_ALLOWED),
                          (char *) NULL);
            sprintf(AmayaLastHTTPErrorMsg, 
                    TtaGetMessage (AMAYA, AM_METHOD_NOT_ALLOWED));
          }           }
        else if (status == -1)         else if (status == -1)
          {           {
Line 729  int                 status; Line 780  int                 status;
              /* there's no error context */               /* there's no error context */
              {               {
                sprintf (msg_status, "%d", status);                  sprintf (msg_status, "%d", status); 
                TtaSetStatus (me->docid, 1, TtaGetMessage (AMAYA, AM_UNKNOWN_XXX_STATUS), msg_status);                 TtaSetStatus (me->docid, 1, 
                sprintf (AmayaLastHTTPErrorMsg, TtaGetMessage (AMAYA, AM_UNKNOWN_XXX_STATUS), msg_status);                               TtaGetMessage (AMAYA, AM_UNKNOWN_XXX_STATUS), 
                                msg_status);
                  sprintf (AmayaLastHTTPErrorMsg, 
                           TtaGetMessage (AMAYA, AM_UNKNOWN_XXX_STATUS),
                           msg_status);
                return (HT_OK);                 return (HT_OK);
              }               }
              errorElement = error->element;             
              /* there's an error context */
              errorElement = error->element;
              
            if (errorElement == HTERR_NOT_IMPLEMENTED)             if (errorElement == HTERR_NOT_IMPLEMENTED)
              {               {
                TtaSetStatus (me->docid, 1, TtaGetMessage (AMAYA, AM_SERVER_NOT_IMPLEMENTED_501_ERROR), (char *) NULL);                 TtaSetStatus (me->docid, 1,
                sprintf (AmayaLastHTTPErrorMsg, TtaGetMessage (AMAYA, AM_SERVER_NOT_IMPLEMENTED_501_ERROR));                               TtaGetMessage (AMAYA, AM_SERVER_NOT_IMPLEMENTED_501_ERROR), 
                                (char *) NULL);
                  sprintf (AmayaLastHTTPErrorMsg, 
                           TtaGetMessage (AMAYA, AM_SERVER_NOT_IMPLEMENTED_501_ERROR));
                status = -501;                 status = -501;
              }               }
            else if (errorElement == HTERR_INTERNAL)             else if (errorElement == HTERR_INTERNAL)
Line 746  int                 status; Line 806  int                 status;
                if ((error->length > 0) && (error->length <= 25) &&                 if ((error->length > 0) && (error->length <= 25) &&
                    (error->par) && (((char *) error->par)[0] != EOS))                      (error->par) && (((char *) error->par)[0] != EOS)) 
                  {                   {
                  TtaSetStatus (me->docid, 1, TtaGetMessage (AMAYA, AM_SERVER_INTERNAL_ERROR_500_CAUSE), (char *) (error->par));                     TtaSetStatus (me->docid, 1, 
                  sprintf (AmayaLastHTTPErrorMsg, TtaGetMessage (AMAYA, AM_SERVER_INTERNAL_ERROR_500_CAUSE), (char *) (error->par));                                   TtaGetMessage (AMAYA, AM_SERVER_INTERNAL_ERROR_500_CAUSE), 
                                    (char *) (error->par));
                    sprintf (AmayaLastHTTPErrorMsg, 
                             TtaGetMessage (AMAYA, AM_SERVER_INTERNAL_ERROR_500_CAUSE), 
                             (char *) (error->par));
                  }                   }
                else                 else
                  {                   {
                  TtaSetStatus (me->docid, 1, TtaGetMessage (AMAYA, AM_SERVER_INTERNAL_ERROR_500_NO_CAUSE), (char *) NULL);                     TtaSetStatus (me->docid, 1, 
                  sprintf (AmayaLastHTTPErrorMsg, TtaGetMessage (AMAYA, AM_SERVER_INTERNAL_ERROR_500_NO_CAUSE));                                   TtaGetMessage (AMAYA, AM_SERVER_INTERNAL_ERROR_500_NO_CAUSE), 
                                    (char *) NULL);
                    sprintf (AmayaLastHTTPErrorMsg, 
                             TtaGetMessage (AMAYA, AM_SERVER_INTERNAL_ERROR_500_NO_CAUSE));
                  }                   }
                status = -500;                  status = -500; 
              }               }
Line 760  int                 status; Line 827  int                 status;
              {               {
                sprintf (msg_status, "%d", status);                  sprintf (msg_status, "%d", status); 
                TtaSetStatus (me->docid, 1, TtaGetMessage (AMAYA, AM_UNKNOWN_XXX_STATUS), msg_status);                 TtaSetStatus (me->docid, 1, TtaGetMessage (AMAYA, AM_UNKNOWN_XXX_STATUS), msg_status);
                  sprintf (AmayaLastHTTPErrorMsg, TtaGetMessage (AMAYA, AM_UNKNOWN_XXX_STATUS), msg_status);                 sprintf (AmayaLastHTTPErrorMsg, TtaGetMessage (AMAYA, AM_UNKNOWN_XXX_STATUS), msg_status);
              }               }
          }           }
      }       }
      
 #ifdef _WINDOWS  #ifdef _WINDOWS
    /* erase the context if we're dealing with an asynchronous request */     /* erase the context if we're dealing with an asynchronous request */
    if ((me->mode & AMAYA_ASYNC) ||      (me->mode & AMAYA_IASYNC)) {     if ((me->mode & AMAYA_ASYNC) ||
          (me->mode & AMAYA_IASYNC)) {
            me->reqStatus = HT_END;             me->reqStatus = HT_END;
        /** AHTReqContext_delete (me); **/         /** AHTReqContext_delete (me); **/
    }     }
Line 778  int                 status; Line 846  int                 status;
   
 /*----------------------------------------------------------------------  /*----------------------------------------------------------------------
   AHTLoadTerminate_handler    AHTLoadTerminate_handler
   this is an application "AFTER" Callback. It uses all the functionaly    this is an application "AFTER" Callback. It's called by the library
   that the app part of the Library gives for handling AFTER a request.     when a request has ended, so that we can setup the correct status.
   ----------------------------------------------------------------------*/    ----------------------------------------------------------------------*/
   
 #ifdef __STDC__  #ifdef __STDC__
Line 808  int                 status; Line 876  int                 status;
                                               Amaya->docid_status);                                                Amaya->docid_status);
   
                if (docid_status != NULL && docid_status->counter > 1)                 if (docid_status != NULL && docid_status->counter > 1)
                   TtaSetStatus (me->docid, 1, TtaGetMessage (AMAYA,                    TtaSetStatus (me->docid, 1, 
                                                    AM_ELEMENT_LOADED), me->status_urlName);                                  TtaGetMessage (AMAYA, AM_ELEMENT_LOADED),
                                   me->status_urlName);
                break;                 break;
   
             case HT_NO_DATA:              case HT_NO_DATA:
                if (PROT_TRACE)                 if (PROT_TRACE)
                   HTTrace ("Load End.... OK BUT NO DATA: `%s\'\n", me->status_urlName);                    HTTrace ("Load End.... OK BUT NO DATA: `%s\'\n", 
                TtaSetStatus (me->docid, 1, TtaGetMessage (AMAYA, AM_LOADED_NO_DATA),                             me->status_urlName);
                  TtaSetStatus (me->docid, 1, 
                                TtaGetMessage (AMAYA, AM_LOADED_NO_DATA),
                              me->status_urlName);                               me->status_urlName);
                break;                 break;
   
             case HT_INTERRUPTED:              case HT_INTERRUPTED:
                if (PROT_TRACE)                 if (PROT_TRACE)
                   HTTrace ("Load End.... INTERRUPTED: `%s\'\n", me->status_urlName);                    HTTrace ("Load End.... INTERRUPTED: `%s\'\n", 
                TtaSetStatus (me->docid, 1, TtaGetMessage (AMAYA, AM_LOAD_ABORT), NULL);                             me->status_urlName);
                  TtaSetStatus (me->docid, 1, 
                                TtaGetMessage (AMAYA, AM_LOAD_ABORT), 
                                NULL);
                break;                 break;
   
             case HT_RETRY:              case HT_RETRY:
                if (PROT_TRACE)                 if (PROT_TRACE)
                   HTTrace ("Load End.... NOT AVAILABLE, RETRY AT %ld\n",                    HTTrace ("Load End.... NOT AVAILABLE, RETRY AT %ld\n",
                            HTResponse_retryTime (response));                             HTResponse_retryTime (response));
                TtaSetStatus (me->docid, 1, TtaGetMessage (AMAYA, AM_NOT_AVAILABLE_RETRY),                 TtaSetStatus (me->docid, 1, 
                                TtaGetMessage (AMAYA, AM_NOT_AVAILABLE_RETRY),
                              me->status_urlName);                               me->status_urlName);
                break;                 break;
   
Line 845  int                 status; Line 918  int                 status;
   
                if (PROT_TRACE)                 if (PROT_TRACE)
                   HTTrace ("Load End.... ERROR: Can't access `%s\'\n",                    HTTrace ("Load End.... ERROR: Can't access `%s\'\n",
                            me->status_urlName ? me->status_urlName : "<UNKNOWN>");                             me->status_urlName ? me->status_urlName :"<UNKNOWN>");
                TtaSetStatus (me->docid, 1, TtaGetMessage (AMAYA, AM_CANNOT_LOAD),                 TtaSetStatus (me->docid, 1,
                                TtaGetMessage (AMAYA, AM_CANNOT_LOAD),
                              me->status_urlName ? me->status_urlName : "<UNKNOWN>");                               me->status_urlName ? me->status_urlName : "<UNKNOWN>");
                break;                 break;
             default:              default:
Line 860  int                 status; Line 934  int                 status;
   
 /*----------------------------------------------------------------------  /*----------------------------------------------------------------------
   AHTAcceptTypesInit    AHTAcceptTypesInit
     This function prepares the Accept header used by Amaya during
     the HTTP content negotiation phase
   ----------------------------------------------------------------------*/    ----------------------------------------------------------------------*/
 #ifdef __STDC__  #ifdef __STDC__
 static void           AHTAcceptTypesInit (HTList *c)  static void           AHTAcceptTypesInit (HTList *c)
Line 873  HTList             *c; Line 949  HTList             *c;
   
       /* define here all the mime types that Amaya can accept */        /* define here all the mime types that Amaya can accept */
   
       HTConversion_add (c, "image/png",  "www/present", HTThroughLine, 1.0, 0.0, 0.0);        HTConversion_add (c, "image/png",  "www/present", 
       HTConversion_add (c, "image/jpeg", "www/present", HTThroughLine, 1.0, 0.0, 0.0);                          HTThroughLine, 1.0, 0.0, 0.0);
       HTConversion_add (c, "image/gif",  "www/present", HTThroughLine, 1.0, 0.0, 0.0);        HTConversion_add (c, "image/jpeg", "www/present", 
       HTConversion_add (c, "image/xbm",  "www/present", HTThroughLine, 1.0, 0.0, 0.0);                          HTThroughLine, 1.0, 0.0, 0.0);
       HTConversion_add (c, "image/xpm",  "www/present", HTThroughLine, 1.0, 0.0, 0.0);        HTConversion_add (c, "image/gif",  "www/present", 
       HTConversion_add (c, "application/postscript",  "www/present", HTThroughLine, 1.0, 0.0, 0.0);                          HTThroughLine, 1.0, 0.0, 0.0);
         HTConversion_add (c, "image/xbm",  "www/present", 
                           HTThroughLine, 1.0, 0.0, 0.0);
         HTConversion_add (c, "image/xpm",  "www/present", 
                           HTThroughLine, 1.0, 0.0, 0.0);
         HTConversion_add (c, "application/postscript",  
                           "www/present", HTThroughLine, 1.0, 0.0, 0.0);
   
    /* Define here the equivalences between MIME types and file extensions for     /* Define here the equivalences between MIME types and file extensions for
     the types that Amaya can display */      the types that Amaya can display */
Line 966  static void         AHTProtocolInit (voi Line 1048  static void         AHTProtocolInit (voi
 {  {
   
    /*      /* 
       NB. Preemptive == YES = Blocking request        NB. Preemptive == YES means Blocking requests
       Non-preemptive == NO = Non-blocking request        Non-preemptive == NO means Non-blocking requests
    */     */
   
    HTProtocol_add ("http", "buffered_tcp", NO, HTLoadHTTP, NULL);     HTProtocol_add ("http", "buffered_tcp", NO, HTLoadHTTP, NULL);
Line 992  static void         AHTNetInit (void) Line 1074  static void         AHTNetInit (void)
 {  {
   
 /*      Register BEFORE filters  /*      Register BEFORE filters
    **      The BEFORE filters handle proxies, caches, rule files etc.  **      The BEFORE filters handle proxies, caches, rule files etc.
    **      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!
  */  */
     
   
    /*#ifndef HACK_WWW */  
    HTNet_addBefore (HTCredentialsFilter, "http://*", NULL, 6);  
    HTNet_addBefore (HTProxyFilter, NULL, NULL, 10);  
   
    /*#endif */    HTNet_addBefore (HTCredentialsFilter, "http://*", NULL, 6);
     HTNet_addBefore (HTProxyFilter, NULL, NULL, 10);
   
 /*      register AFTER filters  /*      register AFTER filters
    **      The AFTER filters handle error messages, logging, redirection,  **      The AFTER filters handle error messages, logging, redirection,
    **      authentication etc.  **      authentication etc.
    **      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!
  */  */
   
 #ifndef HACK_WWW  
    HTNet_addAfter (HTAuthFilter, "http://*", NULL, HT_NO_ACCESS, 5);     HTNet_addAfter (HTAuthFilter, "http://*", NULL, HT_NO_ACCESS, 5);
    HTNet_addAfter (redirection_handler, "http://*", NULL, HT_TEMP_REDIRECT, 5);     HTNet_addAfter (redirection_handler, "http://*", NULL, HT_TEMP_REDIRECT, 5);
    HTNet_addAfter (redirection_handler, "http://*", NULL, HT_PERM_REDIRECT, 5);     HTNet_addAfter (redirection_handler, "http://*", NULL, HT_PERM_REDIRECT, 5);
Line 1019  static void         AHTNetInit (void) Line 1097  static void         AHTNetInit (void)
    HTNet_addAfter (AHTLoadTerminate_handler, NULL, NULL, HT_ALL, HT_FILTER_LAST);            HTNet_addAfter (AHTLoadTerminate_handler, NULL, NULL, HT_ALL, HT_FILTER_LAST);       
    /* 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);
 #endif  
 }  }
   
 /*----------------------------------------------------------------------  /*----------------------------------------------------------------------
Line 1073  char               *AppVersion; Line 1150  char               *AppVersion;
    HTTransportInit ();     HTTransportInit ();
   
    /* Register the default set of application protocol modules */     /* Register the default set of application protocol modules */
 #ifndef HACK_WWW  
    AHTProtocolInit ();     AHTProtocolInit ();
 #endif  
   
    /* Enable the persistent cache */     /* Enable the persistent cache */
    /*   HTCacheInit (NULL, 20); */     /*   HTCacheInit (NULL, 20); */
Line 1099  char               *AppVersion; Line 1174  char               *AppVersion;
    HTFormat_setTransferCoding (encodings);     HTFormat_setTransferCoding (encodings);
   
    /* Register the default set of MIME header parsers */     /* Register the default set of MIME header parsers */
    HTMIMEInit ();               /* must be called again for language selector */     HTMIMEInit ();   /* must be called again for language selector */
   
    /* Register the default set of Icons for directory listings */     /* Register the default set of Icons for directory listings */
    /*HTIconInit(NULL); *//* experimental */     /*HTIconInit(NULL); *//* experimental */
Line 1121  static void         AHTProfile_delete () Line 1196  static void         AHTProfile_delete ()
 {  {
     
   /* free the Amaya global context */    /* free the Amaya global context */
    if (!converters)    if (!converters)
       HTConversion_deleteAll (converters);      HTConversion_deleteAll (converters);
    if (!acceptTypes)    if (!acceptTypes)
       HTConversion_deleteAll (acceptTypes);      HTConversion_deleteAll (acceptTypes);
    if (!encodings)    if (!encodings)
       HTCoding_deleteAll (encodings);      HTCoding_deleteAll (encodings);
     
    HTList_delete (Amaya->docid_status);    HTList_delete (Amaya->docid_status);
    HTList_delete (Amaya->reqlist);    HTList_delete (Amaya->reqlist);
    TtaFreeMemory (Amaya);    TtaFreeMemory (Amaya);
                       {    {
   
   if (HTLib_isInitialized ())  
   
       if (HTLib_isInitialized ())
         
 #  ifdef _WINDOWS  #  ifdef _WINDOWS
       HTEventTerminate ();        HTEventTerminate ();
 #  endif _WINDOWS;                #  endif _WINDOWS;              
       
       /* Clean up the persistent cache (if any) */      /* Clean up the persistent cache (if any) */
       HTCacheTerminate ();      HTCacheTerminate ();
       
       /* Clean up all the global preferences */      /* Clean up all the global preferences */
       HTFormat_deleteAll ();      HTFormat_deleteAll ();
       
       /* Terminate libwww */      /* Terminate libwww */
       HTLibTerminate ();      HTLibTerminate ();
     }    }
 }  }
   
 /*----------------------------------------------------------------------  /*----------------------------------------------------------------------
Line 1176  void                QueryInit () Line 1251  void                QueryInit ()
    HTEvent_setUnregisterCallback (AHTEvent_unregister);     HTEvent_setUnregisterCallback (AHTEvent_unregister);
 #  endif /* _WINDOWS */  #  endif /* _WINDOWS */
   
    /* Setup authentication manager */  #ifdef DEBUG_LIBWWW
     /***    WWW_TraceFlag = SHOW_CORE_TRACE | SHOW_THREAD_TRACE | PROT_TRACE;
       HTAuthCall_add("basic", HTBasic_parse, HTBasic_generate, HTBasic_delete);  #endif
       ****/  
   
    /* Trace activation (for debugging) */     /* Trace activation (for debugging) */
    /*     /*
Line 1197  void                QueryInit () Line 1271  void                QueryInit ()
      ***/       ***/
   
    /* Setting up other user interfaces */     /* Setting up other user interfaces */
    /* needs a little bit more work */  
   
    /* Setting up different network parameters */     /* Setting up different network parameters */
    /* Maximum number of simultaneous open sockets */     /* Maximum number of simultaneous open sockets */
Line 1211  void                QueryInit () Line 1284  void                QueryInit ()
    Amaya->reqlist = HTList_new ();     Amaya->reqlist = HTList_new ();
    Amaya->docid_status = HTList_new ();     Amaya->docid_status = HTList_new ();
    Amaya->open_requests = 0;     Amaya->open_requests = 0;
      
 #ifdef CATCH_SIG  #ifdef CATCH_SIG
    signal (SIGPIPE, SIG_IGN);     signal (SIGPIPE, SIG_IGN);
 #endif  #endif
Line 1577  status_urlName); Line 1650  status_urlName);
    } else {     } 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);  
             AHTReqContext_delete (me);              AHTReqContext_delete (me);
          }           }
    }     }
Line 1672  void               *context_tcbf; Line 1744  void               *context_tcbf;
 #  ifndef _WINDOWS  #  ifndef _WINDOWS
    if ((fd = open (fileName, O_RDONLY)) == -1)     if ((fd = open (fileName, O_RDONLY)) == -1)
 #  else /* _WINDOWS */  #  else /* _WINDOWS */
    if ((fd = open (fileName, _O_RDONLY)) == -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 */
Line 1779  char               *outputfile; Line 1851  char               *outputfile;
 #else  #else
    HTRequest_setPreemptive (me->request, NO);     HTRequest_setPreemptive (me->request, NO);
 #endif /* _WINDOWS */  #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 1801  char               *outputfile; Line 1874  char               *outputfile;
   
    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);
      /* prepare the URLname that will be displayed in teh status bar */
      ChopURL (me->status_urlName, me->urlName);
      TtaSetStatus (me->docid, 1, TtaGetMessage (AMAYA, AM_REMOTE_SAVING),
                        me->status_urlName);
    status = HTLoadAbsolute (urlName, me->request);     status = HTLoadAbsolute (urlName, me->request);
   
   #ifndef _WINDOWS
    if (status == HT_ERROR || me->reqStatus == HT_END || me->reqStatus == HT_ERR || HTError_hasSeverity (HTRequest_error (me->request), ERR_INFO))     if (status == HT_ERROR || me->reqStatus == HT_END || me->reqStatus == HT_ERR || HTError_hasSeverity (HTRequest_error (me->request), ERR_INFO))
   #else
        if (status == HT_ERROR)
   #endif /* !_WINDOWS */
      {       {
        status = HT_ERROR;         status = HT_ERROR;
            /*  
        AHTReqContext_delete (me);         AHTReqContext_delete (me);
            */  
      }            }     
    else     else
      {       {
        /* prepare the URLname that will be displayed in teh status bar */  
        ChopURL (me->status_urlName, me->urlName);  
        TtaSetStatus (me->docid, 1, TtaGetMessage (AMAYA, AM_REMOTE_SAVING),  
                      me->status_urlName);  
   
         /* 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))
Line 1880  int                 docid; Line 1954  int                 docid;
                            case HT_NEW_PENDING:                             case HT_NEW_PENDING:
                            case HT_WAITING:                             case HT_WAITING:
                            default:                             default:
 #                 ifndef _WINDOWS  
                               RequestKillAllXtevents (me);  
 #                 endif /* !_WINDOWS */  
                               me->reqStatus = HT_ABORT;                                me->reqStatus = HT_ABORT;
 #                 ifndef _WINDOWS  #                 ifndef _WINDOWS
                                   HTRequest_kill (me->request);                                RequestKillAllXtevents (me);
                                     #                 endif _WINDOWS
                                 HTRequest_kill (me->request);
                                 
                               if ((me->mode & AMAYA_ASYNC) ||                                if ((me->mode & AMAYA_ASYNC) ||
                                   (me->mode & AMAYA_IASYNC))                                    (me->mode & AMAYA_IASYNC))
                                 {                                  {
   
                                    AHTReqContext_delete (me);                                     AHTReqContext_delete (me);
                                 }                                  }
 #               else                                AHTReqContext_delete (me);
                                 AHTReqContext_delete (me);                                
 #               endif /* !WINDOWS */                                cur = Amaya->reqlist;
                                 
                                   cur = Amaya->reqlist;  
   
                               open_requests--;                                open_requests--;
   
                               break;                                break;

Removed from v.1.73  
changed lines
  Added in v.1.74


Webmaster