Diff for /Amaya/amaya/AHTBridge.c between versions 1.37 and 1.38

version 1.37, 1997/07/08 13:33:02 version 1.38, 1997/07/09 07:46:41
Line 26 Line 26
   
 #ifndef _WINDOWS  #ifndef _WINDOWS
 /* Amaya's X appcontext */  /* Amaya's X appcontext */
   
 extern ThotAppContext app_cont;  extern ThotAppContext app_cont;
   
 /* Private functions */  /* Private functions */
Line 61  static const SockOps ReadBits = FD_READ Line 62  static const SockOps ReadBits = FD_READ
 static const SockOps WriteBits = FD_WRITE | FD_CONNECT;  static const SockOps WriteBits = FD_WRITE | FD_CONNECT;
 static const SockOps ExceptBits = FD_OOB;  static const SockOps ExceptBits = FD_OOB;
   
 static XtInputId sockets[200];  #define SOCK_TABLE_SIZE 67
   #define HASH(s) ((s) % SOCK_TABLE_SIZE)
   static XtInputId persSockets[SOCK_TABLE_SIZE];
   
 /* Private functions */  /* Private functions */
   
Line 95  XtInputId          *id; Line 98  XtInputId          *id;
    HTRequest          *rqp = NULL;     HTRequest          *rqp = NULL;
    AHTReqContext      *me;     AHTReqContext      *me;
    SockOps             ops;          SockOps             ops;     
      int                 v;
   
    /* Libwww 5.0a does not take into account the ops parameter     /* Libwww 5.0a does not take into account the ops parameter
       in the invocation of for this function call */        in the invocation of for this function call */
      
    HTEventCallback    *cbf;     HTEventCallback    *cbf;
   
    ops = FD_WRITE;     ops = FD_WRITE;
    cbf = (HTEventCallback *) __RetrieveCBF (*s, ops, &rqp);     cbf = (HTEventCallback *) __RetrieveCBF (*s, ops, &rqp);
   
      /* if rqp is NULL, we are dealing with a persistent socket shutdown */
     if (cbf && (rqp == NULL)) {     if (!(cbf) || !(rqp) || rqp->priority == HT_PRIORITY_OFF) 
        {
 #ifdef DEBUG_LIBWWW  #ifdef DEBUG_LIBWWW
         fprintf(stderr, "AHTCallback_bridge_register, RQP is NULL\n");         HTTrace ("Callback.... No callback found\n");
 #endif  #endif
         if (sockets[*s]) {         /* remove the Xt input which caused this callback */
           sockets[*s] = 0;  #     ifdef WWW_XWINDOWS
           XtRemoveInput (*id);         XtRemoveInput (*id);
           (*cbf) (*s, 0, FD_CLOSE);  #     endif
         }         
         return (0);         /* if it's a persistent socket, remove it from the table */
     }         v = HASH (*s);
          if (persSockets[v]) 
            {
              persSockets[v] = 0;
              if (cbf)
                (*cbf) (*s, 0, FD_CLOSE);
            }
          return (0);
        }
      
    me = HTRequest_context (rqp);     me = HTRequest_context (rqp);
      
 #ifdef DEBUG_LIBWWW  
       fprintf (stderr, "AHTBridge: Processing url %s \n", me->urlName);  
 #endif  
   
    /* verify if there's any callback associated with the request */  
    if (!(cbf) || !(rqp) || rqp->priority == HT_PRIORITY_OFF) {  
 #ifdef DEBUG_LIBWWW  #ifdef DEBUG_LIBWWW
          HTTrace ("Callback.... No callback found\n");     fprintf (stderr, "AHTBridge: Processing url %s \n", me->urlName);
 #endif  #endif
            
       /* remove the Xt input which caused this callback */  
 #     ifdef WWW_XWINDOWS  
       XtRemoveInput (*id);  
 #     endif  
       /* put some more code to correctly destroy this request ?*/  
       return (0);  
    }  
   
    switch ((XtInputId) cd) {     switch ((XtInputId) cd) {
           case XtInputReadMask:     case XtInputReadMask:
                ops = me->read_ops;                 ops = me->read_ops;
                ops = FD_READ;                 ops = FD_READ;
                break;                 break;
Line 159  XtInputId          *id; Line 157  XtInputId          *id;
         
    /* first we change the status of the request, to say it     /* first we change the status of the request, to say it
       has entered a critical section */        has entered a critical section */
      
    /* JK: Clean this up */     /* JK: Clean this up */
    if ((HTRequest_outputStream(me->request) == (HTStream *) NULL))     if ((HTRequest_outputStream(me->request) == (HTStream *) NULL))
       fprintf(stderr,"\n **ERROR** opening %s\n\n",me->urlName);        fprintf(stderr,"\n **ERROR** opening %s\n\n", me->urlName);
   
    me->reqStatus = HT_BUSY;     me->reqStatus = HT_BUSY;
   
    if ((status = (*cbf) (*s, rqp, ops)) != HT_OK)     if ((status = (*cbf) (*s, rqp, ops)) != HT_OK)
 #ifdef DEBUG_LIBWWW  #ifdef DEBUG_LIBWWW
       HTTrace ("Callback.... returned a value != HT_OK");        HTTrace ("Callback.... returned a value != HT_OK");
Line 185  XtInputId          *id; Line 184  XtInputId          *id;
   
    if (me->reqStatus == HT_ABORT) {     if (me->reqStatus == HT_ABORT) {
    /* Has the user stopped the request? */     /* Has the user stopped the request? */
       me->reqStatus = HT_WAITING;       me->reqStatus = HT_WAITING;
       StopRequest (me->docid);       StopRequest (me->docid);
       return (0);       return (0);
    }     }
   
    if (me->reqStatus == HT_WAITING) {     if (me->reqStatus == HT_WAITING) {
       /* the request is being reissued */       /* the request is being reissued */
       /*       /*
        * (1) The old request has ended and the library        * (1) The old request has ended and the library
        * assigned the old socket number to a pending        * assigned the old socket number to a pending
        * request.        * request.
        *        *
        * (2) The request has been reissued after an         * (2) The request has been reissued after an 
        * authentication or redirection directive and        * authentication or redirection directive and
        * we are using the same old socket number.        * we are using the same old socket number.
        */        */
               
 #ifdef DEBUG_LIBWWW  #ifdef DEBUG_LIBWWW
           fprintf (stderr, "*** detected a reissue of request \n");       fprintf (stderr, "*** detected a reissue of request \n");
 #endif  #endif
        return (0);       return (0);
    }     }
   
    /* we verify if the request exists. If it has ended, we will have     /* we verify if the request exists. If it has ended, we will have
       a reqStatus with an HT_END value */        a reqStatus with an HT_END value */
   
 /***     
      if ((me->request->net == (HTNet *) NULL) ||   
      (me->reqStatus == HT_END ||   
      me->reqStatus == HT_ERR)) {  
 ****/  
   
    if ((me->reqStatus == HT_END) ||     if ((me->reqStatus == HT_END) ||
        (me->reqStatus == HT_ERR)) {         (me->reqStatus == HT_ERR)) {
         /* request has ended */          /* request has ended */
 #ifdef DEBUG_LIBWWW  #ifdef DEBUG_LIBWWW
        fprintf (stderr, "(BF) removing Xtinput %lu !RWE, sock %d (Request has ended)\n", *id, *s);         fprintf (stderr, "(BF) removing Xtinput %lu !RWE, sock %d (Request has ended)\n", *id, *s);
 #endif  #endif
      if ((me->mode & AMAYA_ASYNC) || (me->mode & AMAYA_IASYNC)) {         if ((me->mode & AMAYA_ASYNC) || (me->mode & AMAYA_IASYNC)) {
   
          AHTPrintPendingRequestStatus (me->docid, YES);           AHTPrintPendingRequestStatus (me->docid, YES);
          /* free the memory allocated for async requests */           /* free the memory allocated for async requests */
          AHTReqContext_delete (me);           AHTReqContext_delete (me);
       } else if (me->reqStatus != HT_END && HTError_hasSeverity (HTRequest_error (me->request), ERR_NON_FATAL))         } else if (me->reqStatus != HT_END && HTError_hasSeverity (HTRequest_error (me->request), ERR_NON_FATAL))
             /* did the SYNC request end because of an error? If yes, report it back to the caller */           /* did the SYNC request end because of an error? If yes, report it back to the caller */
             me->reqStatus = HT_ERR;           me->reqStatus = HT_ERR;
       return (0);         return (0);
    }     }
   
    /* The request is still alive, so change it's status to indicate      /* The request is still alive, so change it's status to indicate 
       it's out of the critical section */        it's out of the critical section */
    me->reqStatus = HT_WAITING;     me->reqStatus = HT_WAITING;
Line 269  HTAlertPar         *reply; Line 262  HTAlertPar         *reply;
    AHTReqContext      *me = HTRequest_context (request);     AHTReqContext      *me = HTRequest_context (request);
   
    if (me->reqStatus == HT_NEW) {     if (me->reqStatus == HT_NEW) {
       if ((me->output != stdout) &&        if ((me->output != stdout) && 
           me->outputfile &&            me->outputfile && 
           (me->output = fopen (me->outputfile, "wb")) == NULL) {           (me->output = fopen (me->outputfile, "wb")) == NULL) {
         /* the request is associated with a file */         /* the request is associated with a file */
         me->outputfile[0] = EOS;        /* file could not be opened */         me->outputfile[0] = EOS; /* file could not be opened */
         TtaSetStatus (me->docid, 1,          TtaSetStatus (me->docid, 1, 
                       TtaGetMessage (AMAYA, AM_CANNOT_CREATE_FILE),                       TtaGetMessage (AMAYA, AM_CANNOT_CREATE_FILE),
                       me->outputfile);                       me->outputfile);
         me->reqStatus = HT_ERR;         me->reqStatus = HT_ERR;
         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 we can show the error message */
       } else {        } else {
         if (THD_TRACE)          if (THD_TRACE)
           fprintf (stderr, "WIN_Activate_Request: Activating pending %s . Open fd %d\n", me->urlName, (int) me->output);            fprintf (stderr, "WIN_Activate_Request: Activating pending %s . Open fd %d\n", me->urlName, (int) me->output);
Line 302  HTAlertPar         *reply; Line 295  HTAlertPar         *reply;
    return ((me->reqStatus != HT_ERR) ? HT_OK : HT_ERROR);     return ((me->reqStatus != HT_ERR) ? HT_OK : HT_ERROR);
 }  }
   
 #else  #else /* _WINDOWS */
   
 /*----------------------------------------------------------------  /*----------------------------------------------------------------
   Add_NewSocket_to_Loop    Add_NewSocket_to_Loop
Line 330  HTAlertPar         *reply; Line 323  HTAlertPar         *reply;
 #endif /* __STDC__ */  #endif /* __STDC__ */
 {  {
    AHTReqContext      *me = HTRequest_context (request);     AHTReqContext      *me = HTRequest_context (request);
      int status = HT_OK;
   
 #ifdef DEBUG_LIBWWW  #ifdef DEBUG_LIBWWW
      fprintf (stderr, "(Activating a request\n");       fprintf (stderr, "(Activating a request\n");
Line 345  HTAlertPar         *reply; Line 339  HTAlertPar         *reply;
                        TtaGetMessage (AMAYA, AM_CANNOT_CREATE_FILE),                         TtaGetMessage (AMAYA, AM_CANNOT_CREATE_FILE),
                        me->outputfile);                         me->outputfile);
          me->reqStatus = HT_ERR;           me->reqStatus = HT_ERR;
            status = HT_ERROR;
          /* should the error be shown on the Amaya doc window? */           /* should the error be shown on the Amaya doc window? */
          if (me->error_html)           if (me->error_html)
            DocNetworkStatus[me->docid] |= AMAYA_NET_ERROR;              DocNetworkStatus[me->docid] |= AMAYA_NET_ERROR; 
        }          } 
        /* else {  
           HTRequest_setOutputStream (me->request,   
           AHTFWriter_new (me->request, me->output, YES));  
           me->reqStatus = HT_WAITING;  
           }*/  
 #ifdef DEBUG_LIBWWW  #ifdef DEBUG_LIBWWW
        fprintf (stderr, "ADDNEWSOCK: associated %s to FD %p\n",          fprintf (stderr, "ADDNEWSOCK: associated %s to FD %p\n", 
                 me->urlName, me->output);                   me->urlName, me->output); 
Line 375  HTAlertPar         *reply; Line 366  HTAlertPar         *reply;
                                   AHTFWriter_new (me->request, me->output, YES));                                    AHTFWriter_new (me->request, me->output, YES));
    }      } 
         
    return (HT_OK);     return (status);
 }  }
 #endif /* _WINDOWS */  #endif /* _WINDOWS */
   
Line 400  HTPriority          p; Line 391  HTPriority          p;
 {  {
    AHTReqContext      *me;      /* current request */     AHTReqContext      *me;      /* current request */
    int                 status;  /* libwww status associated with the socket number */     int                 status;  /* libwww status associated with the socket number */
   #ifndef _WINDOWS
      int                 v;
   #endif /* _WINDOWS */
   
    /* verify this under UNIX */  
    if (sock == INVSOC)     if (sock == INVSOC)
       return (0);       return (0);
   
    /* get the request associated to the socket number */     /* get the request associated to the socket number */
   
      if (rqp == NULL) 
        {
 #ifndef _WINDOWS   #ifndef _WINDOWS 
    if (rqp == NULL && ops == FD_CLOSE) {         if (ops == FD_CLOSE)
          {
 #ifdef DEBUG_LIBWWW  #ifdef DEBUG_LIBWWW
         fprintf(stderr, "HTEvent_register: ***** RQP is NULL @@@@@\n");           fprintf(stderr, "HTEvent_register: ***** RQP is NULL @@@@@\n");
 #endif /* DEBUG_LIBWWW */  #endif /* DEBUG_LIBWWW */
         if (sockets[sock] != 0) {           v = HASH (sock);
           XtRemoveInput (sockets[sock]);           if (persSockets[v] != 0) 
         }             {
                XtRemoveInput (persSockets[v]);
         sockets[sock] = XtAppAddInput (app_cont,              }
                                        sock,           
                                        (XtPointer) XtInputReadMask,           persSockets[v] = XtAppAddInput (app_cont, 
                                        (XtInputCallbackProc) AHTCallback_bridge,                                           sock,
                                        (XtPointer) XtInputReadMask);                                           (XtPointer) XtInputReadMask,
         return (status);                                           (XtInputCallbackProc) AHTCallback_bridge,
    }                                           (XtPointer) XtInputReadMask);
          } /* *fd_close */
        }
 #endif /* !_WINDOWS */  #endif /* !_WINDOWS */
      else /* rqp */
    if (rqp)  
      {       {
         me = HTRequest_context (rqp);         me = HTRequest_context (rqp);
          
 #ifndef _WINDOWS  #ifndef _WINDOWS
         if (sockets[sock] != 0) {         v = HASH (sock);
           XtRemoveInput (sockets[sock]);         if (persSockets[v] != 0) {
           sockets[sock] = 0;           XtRemoveInput (persSockets[v]);
         }                    persSockets[v] = 0;
          }          
 #endif /* _WINDOWS */  #endif /* _WINDOWS */
          /* verify if we need to open the output file */ 
     /*** VERY EXPERIMENTAL ***/         if (me->reqStatus == HT_NEW)
     me->read_sock = sock;           {
     me->write_sock = FD_CLOSE;  
     /*** END OF VERY EXPERIMENTAL ***/  
   
         /* verify if we need to open the fd */   
         if (me->reqStatus == HT_NEW)  
           {  
   
 #ifdef _WINDOWS  #ifdef _WINDOWS
                 HTEventrg_unregister (sock, FD_ALL);             /* Erase any trailing events */
              HTEventrg_unregister (sock, FD_ALL);
 #endif  #endif
                      /* we are opening a pending request */
                 /* we are opening a pending request */  #ifndef _WINDOWS
              if ((me->output != stdout) && 
                  (me->output = fopen (me->outputfile, "w")) == NULL)
   #else
              if ((me->output != stdout) &&                if ((me->output != stdout) && 
                  (me->output = fopen (me->outputfile, "w")) == NULL)                   (me->output = fopen (me->outputfile, "wb")) == NULL)
   #endif /* !_WINDOWS */
                {                 {
                  me->outputfile[0] = '\0';      /* file could not be opened */                   me->outputfile[0] = '\0';      /* file could not be opened */
                  TtaSetStatus (me->docid, 1,                    TtaSetStatus (me->docid, 1, 
Line 462  HTPriority          p; Line 457  HTPriority          p;
                  return (HT_ERROR);                   return (HT_ERROR);
                }                 }
 #ifdef DEBUG_LIBWWW  #ifdef DEBUG_LIBWWW
              fprintf (stderr, "ADDNEWSOCK: associated %s to FILE %p\n", me->urlName, me->output);              fprintf (stderr, "ADDNEWSOCK: associated %s to FILE %p\n",
 #endif                      me->urlName, me->output); 
              HTRequest_setOutputStream (me->request,  #endif /* DEBUG_LIBWWW */
                                         AHTFWriter_new (me->request, me->output, YES));             HTRequest_setOutputStream (me->request,
              me->reqStatus = HT_WAITING;                                        AHTFWriter_new (me->request, me->output, YES));
                           me->reqStatus = HT_WAITING;
              if (THD_TRACE)           }
                fprintf (stderr, "AHTEvent_register: Activating pending request url %s, fd %d\n", me->urlName, (int) me->output);         
           }         if (THD_TRACE)
            fprintf (stderr, "AHTEvent_register: URL %s, SOCK %d, ops %lu \n",
         if (THD_TRACE)                    me->urlName, sock, ops);
            fprintf (stderr, "AHTEvent_register: url %s, sock %d, ops %lu \n",         
                     me->urlName, sock, ops);  
   
 #ifndef _WINDOWS  #ifndef _WINDOWS
         if (ops & ReadBits)         if (ops & ReadBits)
           {           {
              me->read_ops = ops;             me->read_ops = ops;
              RequestRegisterReadXtevent (me, sock);             RequestRegisterReadXtevent (me, sock);
           }           }
          
         if (ops & WriteBits)         if (ops & WriteBits)
           {           {
              me->write_ops = ops;             me->write_ops = ops;
              RequestRegisterWriteXtevent (me, sock);             RequestRegisterWriteXtevent (me, sock);
           }           }
          
         if (ops & ExceptBits)         if (ops & ExceptBits)
           {           {
              me->except_ops = ops;             me->except_ops = ops;
              RequestRegisterExceptXtevent (me, sock);             RequestRegisterExceptXtevent (me, sock);
           }           }
 #endif   /* !_WINDOWS */  #endif   /* !_WINDOWS */
      }         
        } /* if *rqp */
      
    status = HTEventrg_register (sock, rqp, ops,     status = HTEventrg_register (sock, rqp, ops,
                                              cbf, p);                                  cbf, p);
    return (status);     return (status);
 }  }
   
Line 520  SockOps             ops; Line 513  SockOps             ops;
 #endif /* __STDC__ */  #endif /* __STDC__ */
 {  {
    int                 status;     int                 status;
   
    HTRequest          *rqp = NULL;     HTRequest          *rqp = NULL;
    AHTReqContext      *me;     AHTReqContext      *me;
   #ifndef _WINDOWS
      int                 v;
   #endif /* _WINDOWS */
   
   
    /* Libwww 5.0a does not take into account the third parameter     /* Libwww 5.0a does not take into account the third parameter
       **  for this function call */        **  for this function call */
   
 #ifndef _WINDOWS  #ifndef _WINDOWS
      
    HTEventCallback     *cbf = (HTEventCallback *) __RetrieveCBF (sock, (SockOps) NULL, &rqp);     HTEventCallback     *cbf = (HTEventCallback *) __RetrieveCBF (sock, (SockOps) NULL, &rqp);
      #endif /* _WINDOWS */
   
      if (sock == INVSOC)
        return HT_OK;
   
   #ifndef _WINDOWS   
 #ifdef DEBUG_LIBWWW  #ifdef DEBUG_LIBWWW
    fprintf (stderr, "AHTEventUnregister: cbf = %d, sock = %d, rqp = %d, ops= %x", cbf, sock, rqp, ops);     fprintf (stderr, "AHTEventUnregister: cbf = %d, sock = %d, rqp = %d, ops= %x", cbf, sock, rqp, ops);
 #endif  #endif /* DEBUG_LIBWWW */
      
    if (sockets[sock] != 0) {     v = HASH (sock);
      XtRemoveInput (sockets[sock]);     if (persSockets[v] != 0) {
      sockets[sock] = 0;       XtRemoveInput (persSockets[v]);
        persSockets[v] = 0;
    }     }
   
    if (cbf)     if (cbf)
      {       {
        if (rqp)         if (rqp && (me = HTRequest_context (rqp)) )
          {           {
            me = HTRequest_context (rqp);  
              
            if (ops & ReadBits)              if (ops & ReadBits) 
              RequestKillReadXtevent (me);               RequestKillReadXtevent (me);
                         
Line 554  SockOps             ops; Line 553  SockOps             ops;
                         
            if (ops & ExceptBits)             if (ops & ExceptBits)
              RequestKillExceptXtevent (me);               RequestKillExceptXtevent (me);
 /**** for windows? ***  
         if (me->reqStatus == HT_END)  
           AHTReqContext_delete (me);  
 *****/  
          }           }
      }       }
   
 #endif /* !_WINDOWS */  #endif /* !_WINDOWS */
   
    status = HTEventrg_unregister (sock, ops);     status = HTEventrg_unregister (sock, ops);

Removed from v.1.37  
changed lines
  Added in v.1.38


Webmaster