Diff for /Amaya/amaya/AHTBridge.c between versions 1.35 and 1.36

version 1.35, 1997/07/04 13:13:55 version 1.36, 1997/07/08 08:20:10
Line 61  static const SockOps ReadBits = FD_READ Line 61  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];
   
 /* Private functions */  /* Private functions */
   
Line 107  XtInputId          *id; Line 108  XtInputId          *id;
    /* 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 */
   
 #  ifdef HACK_WWW  
    HTEventCallback    *cbf;  
 #  else  
    HTEventCallback    *cbf;     HTEventCallback    *cbf;
   
    ops = FD_WRITE;     ops = FD_WRITE;
    cbf = (HTEventCallback *) __RetrieveCBF (*s, ops, &rqp);     cbf = (HTEventCallback *) __RetrieveCBF (*s, ops, &rqp);
 #  endif  
   
       if (cbf && (rqp == NULL)) {
   #ifdef DEBUG_LIBWWW
           fprintf(stderr, "AHTCallback_bridge_register, RQP is NULL\n");
   #endif
           if (sockets[*s]) {
             sockets[*s] = 0;
             XtRemoveInput (*id);
             (*cbf) (*s, 0, FD_CLOSE);
           }
           return (0);
       }
   
   
    me = HTRequest_context (rqp);     me = HTRequest_context (rqp);
    if (THD_TRACE)  
   #ifdef DEBUG_LIBWWW
       fprintf (stderr, "AHTBridge: Processing url %s \n", me->urlName);        fprintf (stderr, "AHTBridge: Processing url %s \n", me->urlName);
   #endif
   
    /* verify if there's any callback associated with the request */     /* verify if there's any callback associated with the request */
    if (!cbf || !rqp || rqp->priority == HT_PRIORITY_OFF) {     if (!(cbf) || !(rqp) || rqp->priority == HT_PRIORITY_OFF) {
       if (THD_TRACE)  #ifdef DEBUG_LIBWWW
          HTTrace ("Callback.... No callback found\n");           HTTrace ("Callback.... No callback found\n");
   #endif
               
       /* experimental */  
       /* remove the Xt input which caused this callback */        /* remove the Xt input which caused this callback */
 #     ifdef WWW_XWINDOWS  #     ifdef WWW_XWINDOWS
       XtRemoveInput (*id);        XtRemoveInput (*id);
Line 166  XtInputId          *id; Line 179  XtInputId          *id;
   
    me->reqStatus = HT_BUSY;     me->reqStatus = HT_BUSY;
    if ((status = (*cbf) (*s, rqp, ops)) != HT_OK)     if ((status = (*cbf) (*s, rqp, ops)) != HT_OK)
       HTTrace ("Callback.... received != HT_OK");  #ifdef DEBUG_LIBWWW
         HTTrace ("Callback.... returned a value != HT_OK");
   #endif
    /* Several states can happen after this callback. They     /* Several states can happen after this callback. They
     * are indicated by the me->reqStatus structure member and      * are indicated by the me->reqStatus structure member and
     * the fds external variables. The following lines examine      * the fds external variables. The following lines examine
Line 201  XtInputId          *id; Line 215  XtInputId          *id;
        * we are using the same old socket number.         * we are using the same old socket number.
        */         */
                 
        if (THD_TRACE)  #ifdef DEBUG_LIBWWW
           fprintf (stderr, "*** detected a reissue of request \n");            fprintf (stderr, "*** detected a reissue of request \n");
   #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)) {  /***   
       /* request has ended */       if ((me->request->net == (HTNet *) NULL) || 
 #     ifndef _WINDOWS       (me->reqStatus == HT_END || 
       if (THD_TRACE)       me->reqStatus == HT_ERR)) {
          fprintf (stderr, "(BF) removing Xtinput %lu !RWE, sock %d (Request has ended)\n", *id, *s);  ****/
 #     endif      /* !_WINDOWS */  
       if ((me->mode & AMAYA_ASYNC) || (me->mode & AMAYA_IASYNC)) {     if ((me->reqStatus == HT_END) ||
          /* free the memory allocated for async requests */         (me->reqStatus == HT_ERR)) {
           /* request has ended */
   #ifndef _WINDOWS
   #ifdef DEBUG_LIBWWW
          fprintf (stderr, "(BF) removing Xtinput %lu !RWE, sock %d (Request has ended)\n", *id, *s);
   #endif
   #endif   /* !_WINDOWS */
        if ((me->mode & AMAYA_ASYNC) || (me->mode & AMAYA_IASYNC)) {
   
          AHTPrintPendingRequestStatus (me->docid, YES);           AHTPrintPendingRequestStatus (me->docid, YES);
            /* 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        it's out of the critical section */
       critical section */  
    me->reqStatus = HT_WAITING;     me->reqStatus = HT_WAITING;
    return (0);     return (0);
 }  }
Line 260  HTAlertPar         *reply; Line 283  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) && me->outputfile && (me->output = fopen (me->outputfile, "wb")) == NULL) {        if ((me->output != stdout) && 
              /* the request is associated with a file */            me->outputfile && 
              me->outputfile[0] = EOS;   /* file could not be opened */            (me->output = fopen (me->outputfile, "wb")) == NULL) {
              TtaSetStatus (me->docid, 1, TtaGetMessage (AMAYA, AM_CANNOT_CREATE_FILE),          /* the request is associated with a file */
                            me->outputfile);          me->outputfile[0] = EOS;        /* file could not be opened */
              me->reqStatus = HT_ERR;          TtaSetStatus (me->docid, 1, 
              if (me->error_html)                        TtaGetMessage (AMAYA, AM_CANNOT_CREATE_FILE),
                  DocNetworkStatus[me->docid] |= AMAYA_NET_ERROR; /* so we can show the error message */                        me->outputfile);
           me->reqStatus = HT_ERR;
           if (me->error_html)
             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);
              HTRequest_setOutputStream (me->request, AHTFWriter_new (me->request, me->output, YES));              HTRequest_setOutputStream (me->request, AHTFWriter_new (me->request, me->output, YES));    
         /*change the status of the request */          /*change the status of the request */
         me->reqStatus = HT_WAITING;          me->reqStatus = HT_WAITING;
       }        }
    }      } 
    else if (me->reqStatus == HT_WAITING) {     else if (me->reqStatus == HT_WAITING) {
        
            /*change the status of the request */       /*change the status of the request */
         rewind (me->output);       rewind (me->output);
                 if (HTRequest_outputStream (me->request) == NULL)       if (HTRequest_outputStream (me->request) == NULL)
             HTRequest_setOutputStream (me->request, AHTFWriter_new (me->request, me->output, YES));         HTRequest_setOutputStream (me->request, AHTFWriter_new (me->request, me->output, YES));
    }      } 
    else {     else {
                  me->reqStatus = HT_ERR;       me->reqStatus = HT_ERR;
    }     }
         
   return ((me->reqStatus != HT_ERR) ? HT_OK : HT_ERROR);     return ((me->reqStatus != HT_ERR) ? HT_OK : HT_ERROR);
 }  }
   
 #else  #else
Line 319  HTAlertPar         *reply; Line 345  HTAlertPar         *reply;
 {  {
    AHTReqContext      *me = HTRequest_context (request);     AHTReqContext      *me = HTRequest_context (request);
   
    if (THD_TRACE)  #ifdef DEBUG_LIBWWW
      fprintf (stderr, "(Activating a request\n");       fprintf (stderr, "(Activating a request\n");
   #endif
   
    if (me->reqStatus == HT_NEW || me->reqStatus == HT_PENDING) {       if (me->reqStatus == HT_NEW) {
         /* the request is active, open the output file */         /* the request is active, open the output file */
        if ((me->output != stdout) && !(me->output = fopen (me->outputfile, "w"))) {         if ((me->output != stdout) && 
            me->outputfile[0] = EOS;                  !(me->output = fopen (me->outputfile, "w"))) {
            /* file could not be opened */           me->outputfile[0] = EOS;       
            TtaSetStatus (me->docid, 1, TtaGetMessage (AMAYA, AM_CANNOT_CREATE_FILE), me->outputfile);           /* file could not be opened */
            me->reqStatus = HT_ERR;           TtaSetStatus (me->docid, 1, 
            /* should the error be shown on the Amaya doc window? */                         TtaGetMessage (AMAYA, AM_CANNOT_CREATE_FILE),
            if (me->error_html)                         me->outputfile);
                DocNetworkStatus[me->docid] |= AMAYA_NET_ERROR;            me->reqStatus = HT_ERR;
            /* should the error be shown on the Amaya doc window? */
            if (me->error_html)
              DocNetworkStatus[me->docid] |= AMAYA_NET_ERROR; 
        }          } 
        /* else {         /* else {
              HTRequest_setOutputStream (me->request, 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;
 #ifdef JOSE            }*/
            fprintf (stderr, "ADDNEWSOCK: associated %s to fd %d\n", me->urlName, me->output);   #ifdef DEBUG_LIBWWW
          fprintf (stderr, "ADDNEWSOCK: associated %s to FD %p\n", 
                   me->urlName, me->output); 
 #endif  #endif
        if (me->output) {         if (me->output) {
           if (THD_TRACE)           if (THD_TRACE)
              fprintf (stderr, "Add_NewSocket_to_Loop: Activating pending %s . Open fd %d\n", me->urlName, (int) me->output);               fprintf (stderr, "Add_NewSocket_to_Loop: Activating pending %s . Open fd %d\n", me->urlName, (int) me->output);
   
           HTRequest_setOutputStream (me->request, AHTFWriter_new (me->request, me->output, YES));            HTRequest_setOutputStream (me->request, AHTFWriter_new (me->request, me->output, YES));
           me->reqStatus = HT_WAITING;            me->reqStatus = HT_WAITING;
        }         }
Line 352  HTAlertPar         *reply; Line 385  HTAlertPar         *reply;
        /* request was aborted and now is is being reissued */         /* request was aborted and now is is being reissued */
        rewind (me->output);         rewind (me->output);
        /* verify if this is OK */         /* verify if this is OK */
        HTRequest_setOutputStream (me->request, AHTFWriter_new (me->request, me->output, YES));         HTRequest_setOutputStream (me->request, 
                                     AHTFWriter_new (me->request, me->output, YES));
    }      } 
         
    return (HT_OK);     return (HT_OK);
Line 395  HTPriority          p; Line 429  HTPriority          p;
 #endif  #endif
 */  */
   
   
    if ((status = HTEventrg_register (sock, rqp, ops,     if ((status = HTEventrg_register (sock, rqp, ops,
                                      cbf, p)) != HT_OK)                                       cbf, p)) != HT_OK)
       return (status);        return (status);
   
   #ifndef _WINDOWS
   
      if (rqp == NULL && ops == FD_CLOSE) {
   #ifdef DEBUG_LIBWWW
           fprintf(stderr, "HTEvent_register: ***** RQP is NULL @@@@@\n");
   #endif
           if (sockets[sock] != 0) {
             XtRemoveInput (sockets[sock]);
           }
   
           sockets[sock] = XtAppAddInput (app_cont, 
                                          sock,
                                          (XtPointer) XtInputReadMask,
                                          (XtInputCallbackProc) AHTCallback_bridge,
                                          (XtPointer) XtInputReadMask);
           return (status);
      }
   #endif /* _WINDOWS */
   
    if (rqp)     if (rqp)
      {       {
         me = HTRequest_context (rqp);          me = HTRequest_context (rqp);
   
   #ifndef _WINDOWS
           if (sockets[sock] != 0) {
             XtRemoveInput (sockets[sock]);
             sockets[sock] = 0;
   #endif /* _WINDOWS */
           }         
   
     /*** VERY EXPERIMENTAL ***/      /*** VERY EXPERIMENTAL ***/
     me->read_sock = sock;      me->read_sock = sock;
     me->write_sock = FD_CLOSE;      me->write_sock = FD_CLOSE;
Line 412  HTPriority          p; Line 473  HTPriority          p;
         if (me->reqStatus == HT_NEW)          if (me->reqStatus == HT_NEW)
           {            {
              /* we are opening a pending request */               /* we are opening a pending request */
              if ((me->output != stdout) && (me->output = fopen (me->outputfile, "w")) == NULL)               if ((me->output != stdout) && 
                    (me->output = fopen (me->outputfile, "w")) == NULL)
                {                 {
                   me->outputfile[0] = '\0';     /* file could not be opened */                   me->outputfile[0] = '\0';      /* file could not be opened */
                   TtaSetStatus (me->docid, 1, TtaGetMessage (AMAYA, AM_CANNOT_CREATE_FILE),                   TtaSetStatus (me->docid, 1, 
                                 me->outputfile);                                 TtaGetMessage (AMAYA, AM_CANNOT_CREATE_FILE),
                   me->reqStatus = HT_ERR;                                 me->outputfile);
                   return (HT_ERROR);                   me->reqStatus = HT_ERR;
                    return (HT_ERROR);
                }                 }
 #ifdef JOSE  #ifdef DEBUG_LIBWWW
            fprintf (stderr, "ADDNEWSOCK: associated %s to fd %d\n", me->urlName, me->output);                fprintf (stderr, "ADDNEWSOCK: associated %s to FILE %p\n", me->urlName, me->output); 
 #endif  #endif
              HTRequest_setOutputStream (me->request,               HTRequest_setOutputStream (me->request,
                              AHTFWriter_new (me->request, me->output, YES));                                          AHTFWriter_new (me->request, me->output, YES));
              me->reqStatus = HT_WAITING;               me->reqStatus = HT_WAITING;
                
              if (THD_TRACE)               if (THD_TRACE)
                 fprintf (stderr, "AHTEvent_register: Activating pending request url %s, fd %d\n", me->urlName, (int) me->output);                 fprintf (stderr, "AHTEvent_register: Activating pending request url %s, fd %d\n", me->urlName, (int) me->output);
           }            }
   
         if (THD_TRACE)          if (THD_TRACE)
Line 458  HTPriority          p; Line 521  HTPriority          p;
    return (status);     return (status);
 }  }
   
   
 /*----------------------------------------------------------------------  /*----------------------------------------------------------------------
   AHTEvent_unregister    AHTEvent_unregister
   callback called by libwww each time a request is unregistered. This    callback called by libwww each time a request is unregistered. This
Line 483  SockOps             ops; Line 545  SockOps             ops;
    /* 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 */
   
    HTEventCallback    *cbf = (HTEventCallback *) __RetrieveCBF (sock, (SockOps) NULL, &rqp);  
   
 #ifndef _WINDOWS  #ifndef _WINDOWS
      
      HTEventCallback     *cbf = (HTEventCallback *) __RetrieveCBF (sock, (SockOps) NULL, &rqp);
      
   #ifdef DEBUG_LIBWWW
      fprintf (stderr, "AHTEventUnregister: cbf = %d, sock = %d, rqp = %d, ops= %x", cbf, sock, rqp, ops);
   #endif
      
      if (sockets[sock] != 0) {
        XtRemoveInput (sockets[sock]);
        sockets[sock] = 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);
              
              if (ops & WriteBits)             if (ops & WriteBits)
                 RequestKillWriteXtevent (me);               RequestKillWriteXtevent (me);
              
              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);
   
Line 696  AHTReqContext      *me; Line 772  AHTReqContext      *me;
   
   
   
   
   
   
   
   
   
   
   

Removed from v.1.35  
changed lines
  Added in v.1.36


Webmaster