Diff for /Amaya/amaya/query.c between versions 1.50 and 1.51

version 1.50, 1997/04/02 18:50:43 version 1.51, 1997/05/20 08:35:52
Line 11 Line 11
  * (redirection, authentication needed, not found, etc.)   * (redirection, authentication needed, not found, etc.)
  *   *
  * Author: J. Kahan   * Author: J. Kahan
  *   *         R. Guetari (W3C/INRIA) Windows 95/NT routines
  */   */
   
 #ifndef AMAYA_JAVA  #ifndef AMAYA_JAVA
Line 213  int                 docid; Line 213  int                 docid;
    /* 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->output = NULL;
 #ifndef _WINDOWS  #  ifndef _WINDOWS
    me->read_xtinput_id = (XtInputId) NULL;     me->read_xtinput_id = (XtInputId) NULL;
    me->write_xtinput_id = (XtInputId) NULL;     me->write_xtinput_id = (XtInputId) NULL;
    me->except_xtinput_id = (XtInputId) NULL;     me->except_xtinput_id = (XtInputId) NULL;
 #endif  #  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);
Line 390  static void         Thread_deleteAll () Line 390  static void         Thread_deleteAll ()
                {                 {
                   if (me->request)                    if (me->request)
                     {                      {
 #ifndef _WINDOWS  #                      ifndef _WINDOWS
                        RequestKillAllXtevents (me);                         RequestKillAllXtevents (me);
 #endif /* !_WINDOWS */  #                      endif /* !_WINDOWS */
                        AHTReqContext_delete (me);                         AHTReqContext_delete (me);
                     }                      }
                }                /* while */                 }                /* while */
Line 984  static void         AHTNetInit (void) Line 984  static void         AHTNetInit (void)
  */   */
   
 #ifndef HACK_WWW  #ifndef HACK_WWW
      HTNet_addAfter (HTAuthFilter, "http://*", NULL, HT_NO_ACCESS, 5);
    HTNet_addAfter (HTAuthFilter, "http://*", NULL, HT_NO_ACCESS,     HTNet_addAfter (redirection_handler, "http://*", NULL, HT_TEMP_REDIRECT, 5);
                    5);     HTNet_addAfter (redirection_handler, "http://*", NULL, HT_PERM_REDIRECT, 5);
      HTNet_addAfter (HTUseProxyFilter, "http://*", NULL, HT_USE_PROXY, 5);
    HTNet_addAfter (redirection_handler, "http://*", NULL, HT_TEMP_REDIRECT,     HTNet_addAfter (AHTLoadTerminate_handler, NULL, NULL, HT_ALL, HT_FILTER_LAST);       
                    5);     /* handles all errors */
    HTNet_addAfter (redirection_handler, "http://*", NULL, HT_PERM_REDIRECT,  
                    5);  
    HTNet_addAfter (HTUseProxyFilter, "http://*", NULL, HT_USE_PROXY,  
                    5);  
   
    HTNet_addAfter (AHTLoadTerminate_handler, NULL, NULL, HT_ALL, HT_FILTER_LAST);       /* 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  #endif
 }  }
Line 1010  static void         AHTAlertInit (void) Line 1004  static void         AHTAlertInit (void)
 static void         AHTAlertInit ()  static void         AHTAlertInit ()
 #endif  #endif
 {  {
   
    HTAlert_add (AHTProgress, HT_A_PROGRESS);     HTAlert_add (AHTProgress, HT_A_PROGRESS);
    HTAlert_add ((HTAlertCallback *) Add_NewSocket_to_Loop, HT_PROG_CONNECT);     HTAlert_add ((HTAlertCallback *) Add_NewSocket_to_Loop, HT_PROG_CONNECT);
    HTAlert_add (AHTError_print, HT_A_MESSAGE);     HTAlert_add (AHTError_print, HT_A_MESSAGE);
Line 1198  static int          LoopForStop (AHTReqC Line 1191  static int          LoopForStop (AHTReqC
 #endif  #endif
 {  {
   
 #ifndef _WINDOWS  #  ifndef _WINDOWS
    extern ThotAppContext app_cont;     extern ThotAppContext app_cont;
    XEvent              ev;     XEvent                ev;
    XtInputMask         status;     XtInputMask           status;
   #  else  /* _WINDOWS */
 #endif /* !_WINDOWS */     MSG ev;
   #  endif /* _WINDOWS */
    int                 status_req = HT_OK;     int                 status_req = HT_OK;
   
    /* to test the async calls  */     /* to test the async calls  */
Line 1212  static int          LoopForStop (AHTReqC Line 1206  static int          LoopForStop (AHTReqC
           me->reqStatus != HT_END &&            me->reqStatus != HT_END &&
           me->reqStatus != HT_ERR)            me->reqStatus != HT_ERR)
      {       {
   
 #ifndef _WINDOWS  
         if (!AmayaIsAlive)          if (!AmayaIsAlive)
           /* Amaya was killed by one of the callback handlers */            /* Amaya was killed by one of the callback handlers */
           exit (0);            exit (0);
   
   #       ifndef _WINDOWS
         status = XtAppPending (app_cont);          status = XtAppPending (app_cont);
         if (status & XtIMXEvent)          if (status & XtIMXEvent)
           {            {
Line 1234  static int          LoopForStop (AHTReqC Line 1227  static int          LoopForStop (AHTReqC
              XtAppNextEvent (app_cont, &ev);               XtAppNextEvent (app_cont, &ev);
              TtaHandleOneEvent (&ev);               TtaHandleOneEvent (&ev);
           }            }
 #endif /* !_WINDOWS */  #       else  /* _WINDOWS */
           if (GetMessage (&ev, NULL, 0, 0))
              TtaHandleOneWindowEvent (&ev);
   #       endif /* !_WINDOWS */
      }       }
   
    switch (me->reqStatus)     switch (me->reqStatus)
Line 1374  boolean             error_html; Line 1370  boolean             error_html;
    char               *ref;     char               *ref;
    int                 status;     int                 status;
    HTList             *cur, *pending;     HTList             *cur, *pending;
   #  ifdef _WINDOWS
      DWORD               attribs;
   #  endif /* _WINDOWS */
   
    if (urlName == NULL || docid == 0 || outputfile == NULL)     if (urlName == NULL || docid == 0 || outputfile == NULL)
      {       {
Line 1402  boolean             error_html; Line 1401  boolean             error_html;
    /* verify if a docid directory exists */     /* verify if a docid directory exists */
   
    tmp_dir = TtaGetMemory (strlen (TempFileDirectory) + 5 + 1);     tmp_dir = TtaGetMemory (strlen (TempFileDirectory) + 5 + 1);
   #  ifndef _WINDOWS
    sprintf (tmp_dir, "%s/%d", TempFileDirectory, docid);     sprintf (tmp_dir, "%s/%d", TempFileDirectory, docid);
   #  else  /* _WINDOWS */
      sprintf (tmp_dir, "C:\\TEMP\\AMAYA\\%d", docid);
   #  endif /* _WINDOWS */
   
   #  ifndef _WINDOWS
    tmp_fp = fopen (tmp_dir, "r");     tmp_fp = fopen (tmp_dir, "r");
    if (tmp_fp == 0)     if (tmp_fp == 0)
   #  else /* _WINDOWS */
      attribs = GetFileAttributes (tmp_dir) ;
   
      if (attribs == 0xFFFFFFFF)
   #  endif /* _WINDOWS */
      {       {
         /*directory did not exist */          /*directory did not exist */
         if (mkdir (tmp_dir, S_IRWXU) == -1)          if (mkdir (tmp_dir, S_IRWXU) == -1) {
           {             /*error */
              /*error */             outputfile[0] = EOS;
              outputfile[0] = EOS;             TtaSetStatus (docid, 1, TtaGetMessage (AMAYA, AM_CACHE_ERROR), urlName);
              TtaSetStatus (docid, 1, TtaGetMessage (AMAYA, AM_CACHE_ERROR),             
                            urlName);             if (error_html)
                 DocNetworkStatus[docid] |= AMAYA_NET_ERROR; /* so we can show the error message */
              if (error_html)             return HT_ERROR;
                DocNetworkStatus[docid] |= AMAYA_NET_ERROR; /* so we can show the error message */          }
              return HT_ERROR;  
           }  
      }       }
   #  ifndef _WINDOWS
    else     else
       fclose (tmp_fp);        fclose (tmp_fp);
   #  endif /* !_WINDOWS */
   
    /*create a tempfilename */     /*create a tempfilename */
   
   #  ifndef _WINDOWS
    sprintf (outputfile, "%s/%04dAM", tmp_dir, object_counter);     sprintf (outputfile, "%s/%04dAM", tmp_dir, object_counter);
   #  else  /* _WINDOWS */
      sprintf (outputfile, "%s\\%04dAM", tmp_dir, object_counter);
   #  endif /* _WINDOWS */
   
    TtaFreeMemory (tmp_dir);     TtaFreeMemory (tmp_dir);
   
Line 1437  boolean             error_html; Line 1450  boolean             error_html;
   
    /* should we abort the request if we could not normalize the url? */     /* should we abort the request if we could not normalize the url? */
   
    if (ref == (char *) NULL || ref[0] == EOS)     if (ref == (char*) NULL || ref[0] == EOS)
      {       {
         /*error */          /*error */
         outputfile[0] = EOS;          outputfile[0] = EOS;
Line 1532  boolean             error_html; Line 1545  boolean             error_html;
   
    if ((mode & AMAYA_ASYNC) || (mode & AMAYA_IASYNC))     if ((mode & AMAYA_ASYNC) || (mode & AMAYA_IASYNC))
      {       {
         char               *tmp;          char* tmp;
   
         tmp = TtaGetMemory (strlen (outputfile) + 1);          tmp = TtaGetMemory (strlen (outputfile) + 1);
         strcpy (tmp, outputfile);          strcpy (tmp, outputfile);
Line 1615  generated Line 1628  generated
   
         if ((mode & AMAYA_SYNC) || (mode & AMAYA_ISYNC))          if ((mode & AMAYA_SYNC) || (mode & AMAYA_ISYNC))
           {            {
   #            ifndef _WINDOWS
              status = LoopForStop (me);               status = LoopForStop (me);
   #            endif /* _WINDOWS */ 
              AHTReqContext_delete (me);               AHTReqContext_delete (me);
           }            }
         else          else
Line 1789  void               *context_tcbf; Line 1804  void               *context_tcbf;
    return (status);     return (status);
 }  }
   
   #ifdef _WINDOWS
   /*----------------------------------------------------------------------
     WIN_GetObjectWWW
     ----------------------------------------------------------------------*/
   #ifdef __STDC__
   int WIN_GetObjectWWW (int doc_id, char* URL_name, char* output_file, boolean error_HTML)
   #else /* __STDC__ */
   int WIN_GetObjectWWW (int doc_id, char* URL_name, char* output_file, boolean error_HTML)
   int     doc_id;
   char*   URL_name;
   char*   output_file;
   boolean error_HTML;
   #endif /* __STDC__ */
   {
      HTRequest* WIN_request    = HTRequest_new ();
      HTList*    WIN_converters = HTList_new ();           /* List of converters */
      HTList*    WIN_encodings  = HTList_new ();           /* List of encoders */
      HTChunk*   WIN_chunk      = NULL;
   
      FILE*      WIN_tmp_fp;
      char*      WIN_tmp_dir;
      char*      WIN_ref;
      DWORD      WIN_attribs;
   
      if (URL_name == NULL || doc_id == 0 || output_file == NULL) {
         /* no file to be loaded */
         TtaSetStatus (doc_id, 1, TtaGetMessage (AMAYA, AM_BAD_URL), URL_name);
   
         if (error_HTML)
            DocNetworkStatus[doc_id] |= AMAYA_NET_ERROR; /* so we can show the error message */
         return HT_ERROR;
      }
   
      /* do we support this protocol? */
      if (IsValidProtocol (URL_name) == NO) {
         /* return error */
         output_file[0] = EOS;     /* file could not be opened */
         TtaSetStatus (doc_id, 1, TtaGetMessage (AMAYA, AM_GET_UNSUPPORTED_PROTOCOL), URL_name);
      
         if (error_HTML)
            DocNetworkStatus[doc_id] |= AMAYA_NET_ERROR; /* so we can show the error message */
         return HT_ERROR;
      }
   
      /* verify if a docid directory exists */
      WIN_tmp_dir = TtaGetMemory (strlen (TempFileDirectory) + 5 + 1);
      sprintf (WIN_tmp_dir, "C:\\TEMP\\AMAYA\\%d", doc_id);
   
      WIN_attribs = GetFileAttributes (WIN_tmp_dir) ;
   
      if (WIN_attribs == 0xFFFFFFFF) {
         /*directory did not exist */
         if (mkdir (WIN_tmp_dir, S_IRWXU) == -1) {
            /*error */
             output_file[0] = EOS;
             TtaSetStatus (doc_id, 1, TtaGetMessage (AMAYA, AM_CACHE_ERROR), URL_name);
              
             if (error_HTML)
                DocNetworkStatus[doc_id] |= AMAYA_NET_ERROR; /* so we can show the error message */
             return HT_ERROR;
         }
      }
   
      /*create a tempfilename */
      sprintf (output_file, "%s\\%04dAM", WIN_tmp_dir, object_counter);
      TtaFreeMemory (WIN_tmp_dir);
   
      /* update the object_counter */
      object_counter++;
   
      /* normalize the URL */
      WIN_ref = AmayaParseUrl (URL_name, "", AMAYA_PARSE_ALL);
   
      /* should we abort the request if we could not normalize the url? */
   
      if (WIN_ref == (char*) NULL || WIN_ref[0] == EOS) {
         /*error */
         output_file[0] = EOS;
         TtaSetStatus (doc_id, 1, TtaGetMessage (AMAYA, AM_BAD_URL), URL_name);
   
         if (error_HTML)
            DocNetworkStatus[doc_id] |= AMAYA_NET_ERROR; /* so we can show the error message */
         return HT_ERROR;
      }
      /* verify if that file name existed */
      if (TtaFileExist (output_file))
         TtaFileUnlink (output_file);
   
      /* try to open the outputfile */
      if ((WIN_tmp_fp = fopen (output_file, "wb")) == NULL) {
         output_file[0] = EOS;     /* file could not be opened */
         TtaSetStatus (doc_id, 1, TtaGetMessage (AMAYA, AM_CANNOT_CREATE_FILE), output_file);
         TtaFreeMemory (WIN_ref);
       
         if (error_HTML)
            DocNetworkStatus[doc_id] |= AMAYA_NET_ERROR; /* so we can show the error message */
         return (HT_ERROR);
      }
   
      HTLibInit ("Amaya for Windows", "1.0a");
   
      /* Register the default set of transport protocols */
      HTTransportInit ();
      
      /* Register the default set of protocol modules */
      HTProtocolInit ();
      
      /* Register the default set of BEFORE and AFTER callback functions */
      HTNetInit ();
      
      /* Register the default set of converters */
      HTConverterInit (WIN_converters);
      HTFormat_setConversion (WIN_converters);
      
      /* Register the default set of transfer encoders and decoders */
      HTEncoderInit (WIN_encodings);
      HTFormat_setTransferCoding (WIN_encodings);
      
      /* Register the default set of MIME header parsers */
      HTMIMEInit ();
      
      /* Set up the request and pass it to the Library */
      HTRequest_setOutputFormat (WIN_request, WWW_SOURCE);
      HTRequest_setPreemptive (WIN_request, YES);
      if (WIN_ref) {
         char*     WIN_cwd          = HTGetCurrentDirectoryURL ();
         char*     WIN_absolute_url = HTParse (WIN_ref, WIN_cwd, PARSE_ALL);
         HTAnchor* WIN_anchor       = HTAnchor_findAddress (WIN_absolute_url);
         WIN_chunk                  = HTLoadAnchorToChunk (WIN_anchor, WIN_request);
         HT_FREE (WIN_absolute_url);
         HT_FREE (WIN_cwd);
         
          /* If chunk != NULL then we have the data */
         if (WIN_chunk) {
            char* WIN_string = HTChunk_toCString (WIN_chunk);
            if (WIN_string)
               fprintf (WIN_tmp_fp, "%s", WIN_string);
            HT_FREE (WIN_string);
         }
      }
      
      /* Clean up the request */
      HTRequest_delete(WIN_request);
      HTFormat_deleteAll();
      
      /* Terminate the Library */
      HTLibTerminate();
      fclose (WIN_tmp_fp);
      return 0;
   }
   #endif /* _WINDOWS */
   
 /*----------------------------------------------------------------------  /*----------------------------------------------------------------------
   UploadMemWWW    UploadMemWWW
   low level interface function to libwww for uploading a block of    low level interface function to libwww for uploading a block of
Line 1892  char               *outputfile; Line 2059  char               *outputfile;
   
         if ((mode & AMAYA_SYNC) || (mode & AMAYA_ISYNC))          if ((mode & AMAYA_SYNC) || (mode & AMAYA_ISYNC))
           {            {
   #            ifndef _WINDOWS
              status = LoopForStop (me);               status = LoopForStop (me);
   #            endif /* _WINDOWS */ 
              AHTReqContext_delete (me);               AHTReqContext_delete (me);
           }            }
      }       }
Line 1949  int                 docid; Line 2118  int                 docid;
                            case HT_NEW_PENDING:                             case HT_NEW_PENDING:
                            case HT_WAITING:                             case HT_WAITING:
                            default:                             default:
 #ifndef _WINDOWS  #                             ifndef _WINDOWS
                               RequestKillAllXtevents (me);                                RequestKillAllXtevents (me);
 #endif  #                             endif
                               me->reqStatus = HT_ABORT;                                me->reqStatus = HT_ABORT;
                               HTRequest_kill (me->request);                                HTRequest_kill (me->request);
   

Removed from v.1.50  
changed lines
  Added in v.1.51


Webmaster