Annotation of Amaya/amaya/AHTBridge.c, revision 1.52

1.9       cvs         1: /*
                      2:  *
                      3:  *  (c) COPYRIGHT MIT and INRIA, 1996.
                      4:  *  Please first read the full copyright statement in file COPYRIGHT.
                      5:  *
                      6:  */
                      7:  
1.14      cvs         8: /*
                      9:  * AHTBridge.c : This module implements the callback setup and
                     10:  * handlers between the Xt, libwww, and Amaya procedures. It's responsible
                     11:  * for assigning, modifying, and supressing Xt events to the active
                     12:  * requests.
                     13:  *
                     14:  * Author: J Kahan
1.50      cvs        15:  *         J. K./R. G. Windows NT/95 routines
1.14      cvs        16:  *
                     17:  */
1.23      cvs        18: #ifndef AMAYA_JAVA
                     19: 
1.16      cvs        20: #define THOT_EXPORT extern
1.4       cvs        21: #include "amaya.h"
1.10      cvs        22: #include "AHTBridge_f.h"
                     23: #include "AHTFWrite_f.h"
                     24: #include "query_f.h"
                     25: #include "answer_f.h"
1.4       cvs        26: 
1.22      cvs        27: #ifndef _WINDOWS
1.4       cvs        28: /* Amaya's X appcontext */
1.38      cvs        29: 
1.16      cvs        30: extern ThotAppContext app_cont;
1.4       cvs        31: 
1.32      cvs        32: /* Private functions */
1.4       cvs        33: #ifdef __STDC__
1.18      cvs        34: static void         RequestRegisterReadXtevent (AHTReqContext *, SOCKET);
1.7       cvs        35: static void         RequestKillReadXtevent (AHTReqContext *);
1.18      cvs        36: static void         RequestRegisterWriteXtevent (AHTReqContext *, SOCKET);
1.7       cvs        37: static void         RequestKillWriteXtevent (AHTReqContext *);
1.18      cvs        38: static void         RequestRegisterExceptXtevent (AHTReqContext *, SOCKET);
1.7       cvs        39: static void         RequestKillExceptXtevent (AHTReqContext *);
1.27      cvs        40: #else /* __STDC__ */
1.18      cvs        41: static void         RequesAddReadXtevent ();
1.7       cvs        42: static void         RequestKillReadXtevent ();
1.18      cvs        43: static void         RequesAddWriteXtevent ();
1.7       cvs        44: static void         RequestKillWriteXtevent ();
1.18      cvs        45: static void         RequestRegisterExceptXtevent ();
1.7       cvs        46: static void         RequestKillExceptXtevent ();
1.27      cvs        47: #endif /* __STDC__ */
1.24      cvs        48: #endif /* _WINDOWS */
                     49: 
1.32      cvs        50: /* Private variables */
1.4       cvs        51: 
                     52: /*
                     53:  * this set of SockOps map our WinSock "socket event SockOps" into 
                     54:  * our read and write sets. Note that under the canonical Unix model,
                     55:  * a non-blocking socket passed to an accept() call will appear as readable, 
                     56:  * whilst a non-blocking call to connect() will appear as writeable. In add.
                     57:  * if the connection has been closed, the socket will appear readable under
                     58:  * BSD Unix semantics 
                     59:  */
1.32      cvs        60: 
1.10      cvs        61: static const SockOps ReadBits = FD_READ | FD_ACCEPT | FD_CLOSE;
                     62: static const SockOps WriteBits = FD_WRITE | FD_CONNECT;
                     63: static const SockOps ExceptBits = FD_OOB;
1.4       cvs        64: 
1.38      cvs        65: #define SOCK_TABLE_SIZE 67
                     66: #define HASH(s) ((s) % SOCK_TABLE_SIZE)
                     67: static XtInputId persSockets[SOCK_TABLE_SIZE];
1.35      cvs        68: 
1.32      cvs        69: /* Private functions */
1.4       cvs        70: 
1.10      cvs        71: /*--------------------------------------------------------------------
                     72:   AHTCallback_bridge
1.11      cvs        73:   this function acts as a bridge between Xt and libwww. From the Xt
                     74:   point of view, this function is the callback handler whenever there's
                     75:   any activity on the sockets associated with the active requests. From
                     76:   the libwww point of view, this is the function that takes the initiative
                     77:   to invoke the callback function associated with an active request,
                     78:   whenever there's an activity in the socket associated to it.
                     79:   In this latter  aspect, this function is similar to the library's
                     80:   own __DoCallback()  function.
                     81:   Upon activation, the function looks up the request associated with the
                     82:   active socket and then looks up the cbf associated with that request.
                     83:   Upon completion of the execution of the request's cbf, it verifies
                     84:   the state of the request and, if it's an asynchronous request, deletes
                     85:   the memory allocated to it.
1.10      cvs        86:   -------------------------------------------------------------------*/
1.37      cvs        87: #ifndef _WINDOWS
1.4       cvs        88: #ifdef __STDC__
1.12      cvs        89: void *AHTCallback_bridge (caddr_t cd, int *s, XtInputId * id)
1.26      cvs        90: #else  /* __STDC__ */
1.12      cvs        91: void *AHTCallback_bridge (cd, s, id)
1.7       cvs        92: caddr_t             cd;
                     93: int                *s;
                     94: XtInputId          *id;
1.4       cvs        95: #endif /* __STDC__ */
                     96: {
1.11      cvs        97:    int                 status;  /* the status result of the libwwww call */
1.7       cvs        98:    HTRequest          *rqp = NULL;
                     99:    AHTReqContext      *me;
1.11      cvs       100:    SockOps             ops;    
1.38      cvs       101:    int                 v;
1.40      cvs       102:    int                        socket = *s;
                    103:    HTEventCallback    *cbf;
1.4       cvs       104: 
1.10      cvs       105:    /* Libwww 5.0a does not take into account the ops parameter
1.11      cvs       106:       in the invocation of for this function call */
1.47      cvs       107: 
1.13      cvs       108:    ops = FD_WRITE;
1.40      cvs       109:    cbf = (HTEventCallback *) __RetrieveCBF (socket, ops, &rqp);
1.47      cvs       110:    
                    111:    v = HASH (socket);
                    112:    if (persSockets[v]) 
                    113:      {
                    114:        persSockets[v] = 0;
                    115:        /* we're not sure what can be the value of rqp */
                    116:        rqp = NULL;
                    117:      }
                    118:    
1.38      cvs       119:    /* if rqp is NULL, we are dealing with a persistent socket shutdown */
                    120:    if (!(cbf) || !(rqp) || rqp->priority == HT_PRIORITY_OFF) 
                    121:      {
1.43      cvs       122:        if (cbf)
1.47      cvs       123:         (*cbf) (socket, 0, FD_READ);
1.43      cvs       124: 
1.47      cvs       125:    /* remove the Xt input which caused this callback */
                    126: #  ifdef WWW_XWINDOWS
                    127:        XtRemoveInput (*id);
                    128: #  endif
1.38      cvs       129:        return (0);
                    130:      }
                    131:    
1.7       cvs       132:    me = HTRequest_context (rqp);
1.38      cvs       133:    
1.36      cvs       134: #ifdef DEBUG_LIBWWW
1.38      cvs       135:    fprintf (stderr, "AHTBridge: Processing url %s \n", me->urlName);
1.36      cvs       136: #endif
1.38      cvs       137:    
1.32      cvs       138:    switch ((XtInputId) cd) {
1.38      cvs       139:    case XtInputReadMask:
1.19      cvs       140:               ops = me->read_ops;
                    141:               ops = FD_READ;
                    142:               break;
1.32      cvs       143:          case XtInputWriteMask:
1.7       cvs       144:               ops = me->write_ops;
                    145:               ops = FD_WRITE;
                    146:               break;
1.32      cvs       147:          case XtInputExceptMask:
1.7       cvs       148:               ops = me->except_ops;
                    149:               ops = FD_OOB;
                    150:               break;
1.32      cvs       151:          default:
                    152:               break;
                    153:    } /* switch */
1.17      cvs       154: 
1.32      cvs       155:    /* Invokes the callback associated to the requests */
                    156:    
                    157:    /* first we change the status of the request, to say it
                    158:       has entered a critical section */
1.38      cvs       159:    
1.43      cvs       160:    /* JK: An early warning of problems */
1.32      cvs       161:    if ((HTRequest_outputStream(me->request) == (HTStream *) NULL))
1.38      cvs       162:       fprintf(stderr,"\n **ERROR** opening %s\n\n", me->urlName);
1.32      cvs       163: 
                    164:    me->reqStatus = HT_BUSY;
1.38      cvs       165: 
1.52    ! cvs       166:    status = (*cbf) (socket, rqp, ops);
1.36      cvs       167: #ifdef DEBUG_LIBWWW
1.52    ! cvs       168:    if (status != HT_OK)
1.36      cvs       169:       HTTrace ("Callback.... returned a value != HT_OK");
                    170: #endif
1.7       cvs       171:    /* Several states can happen after this callback. They
                    172:     * are indicated by the me->reqStatus structure member and
                    173:     * the fds external variables. The following lines examine
                    174:     * the states and correspondly update the Xt event register
                    175:     *
                    176:     * Regarding the me->reqStatus member, we have the following
                    177:     * possible states:
                    178:     *   
                    179:     * HT_BUSY:    Request has blocked
                    180:     * HT_WAITING: Request has been reissued
                    181:     * HT_ABORT:   Request has been stopped
                    182:     * HT_END:     Request has ended
                    183:     */
                    184: 
1.32      cvs       185:    if (me->reqStatus == HT_ABORT) {
1.11      cvs       186:    /* Has the user stopped the request? */
1.38      cvs       187:      me->reqStatus = HT_WAITING;
1.49      cvs       188:      me->mode &= ~AMAYA_ASYNC_SAFE_STOP;
1.38      cvs       189:      StopRequest (me->docid);
                    190:      return (0);
1.32      cvs       191:    }
1.7       cvs       192: 
1.42      cvs       193:    if (me->reqStatus == HT_WAITING ||
                    194:        me->reqStatus == HT_NEW) {
1.38      cvs       195:      /* the request is being reissued */
                    196:      /*
                    197:       * (1) The old request has ended and the library
                    198:       * assigned the old socket number to a pending
                    199:       * request.
                    200:       *
                    201:       * (2) The request has been reissued after an 
                    202:       * authentication or redirection directive and
                    203:       * we are using the same old socket number.
                    204:       */
                    205:      
1.36      cvs       206: #ifdef DEBUG_LIBWWW
1.38      cvs       207:      fprintf (stderr, "*** detected a reissue of request \n");
1.36      cvs       208: #endif
1.38      cvs       209:      return (0);
1.32      cvs       210:    }
1.4       cvs       211: 
1.32      cvs       212:    /* we verify if the request exists. If it has ended, we will have
                    213:       a reqStatus with an HT_END value */
1.7       cvs       214: 
1.36      cvs       215:    if ((me->reqStatus == HT_END) ||
                    216:        (me->reqStatus == HT_ERR)) {
                    217:         /* request has ended */
                    218: #ifdef DEBUG_LIBWWW
1.40      cvs       219:        fprintf (stderr, "(BF) removing Xtinput %lu !RWE, sock %d (Request has ended)\n", *id, socket);
1.36      cvs       220: #endif
1.41      cvs       221: 
                    222:        if ((me->mode & AMAYA_ASYNC) || (me->mode & AMAYA_IASYNC))
                    223:         {
                    224:           AHTPrintPendingRequestStatus (me->docid, YES);
                    225:           /* free the memory allocated for async requests */
                    226:           AHTReqContext_delete (me);
                    227:         } 
1.43      cvs       228: 
1.41      cvs       229:        else if (me->reqStatus == HT_END &&
                    230:                HTError_hasSeverity (HTRequest_error (me->request),
                    231:                                     ERR_NON_FATAL))
                    232: 
1.38      cvs       233:         /* did the SYNC request end because of an error? If yes, report it back to the caller */
                    234:         me->reqStatus = HT_ERR;
                    235:        return (0);
1.32      cvs       236:    }
1.38      cvs       237: 
1.36      cvs       238:    /* The request is still alive, so change it's status to indicate 
                    239:       it's out of the critical section */
1.7       cvs       240:    me->reqStatus = HT_WAITING;
                    241:    return (0);
1.4       cvs       242: }
1.37      cvs       243: #endif /* !_WINDOWS */
1.41      cvs       244: 
                    245: /*--------------------------------------------------------------------
                    246:   ProcessTerminateRequest
                    247:   This function is called whenever a request has ended. If the requested
                    248:   ended normally, the function will call any callback associated to the
                    249:   request. Otherwise, it will just mark the request as over.
                    250:   -------------------------------------------------------------------*/
                    251: #ifdef __STDC__
                    252: void  ProcessTerminateRequest (AHTReqContext *me)
                    253: #else
                    254: void ProcessTerminateRequest (me)
                    255: AHTReqContext *me;
                    256: #endif
                    257: {   
                    258:   /* Second Step: choose a correct treatment in function of the request's
                    259:      being associated with an error, with an interruption, or with a
                    260:      succesful completion */
                    261:    
                    262:   if (me->reqStatus == HT_END)
                    263:     {
1.52    ! cvs       264:       if (AmayaIsAlive () && me->terminate_cbf)
1.49      cvs       265:        (*me->terminate_cbf) (me->docid, 0, me->urlName, me->outputfile,
                    266:                              me->content_type, me->context_tcbf);
1.41      cvs       267:     }
1.42      cvs       268:   else if (me->reqStatus == HT_ABORT)
1.41      cvs       269:     /* either the application ended or the user pressed the stop 
                    270:        button. We erase the incoming file, if it exists */
                    271:     {
1.52    ! cvs       272:       if (AmayaIsAlive () && me->terminate_cbf)
        !           273:        (*me->terminate_cbf) (me->docid, -1, me->urlName, me->outputfile,
        !           274:                              me->content_type, me->context_tcbf);
1.41      cvs       275:       if (me->outputfile && me->outputfile[0] != EOS)
                    276:        {
                    277:          TtaFileUnlink (me->outputfile);
                    278:          me->outputfile[0] = EOS;
                    279:        }
                    280:     }
                    281:   else if (me->reqStatus == HT_ERR)
                    282:     {
                    283:       /* there was an error */
1.52    ! cvs       284:       if (AmayaIsAlive () && me->terminate_cbf)
1.49      cvs       285:        (*me->terminate_cbf) (me->docid, -1, me->urlName, me->outputfile,
                    286:                              me->content_type, me->context_tcbf);
1.41      cvs       287:       
                    288:       if (me->outputfile && me->outputfile[0] != EOS)
                    289:        {
                    290:          TtaFileUnlink (me->outputfile);
                    291:          me->outputfile[0] = EOS;
                    292:        }
                    293:     }
1.49      cvs       294: 
1.41      cvs       295: #ifdef _WINDOWS
                    296:    /* we erase the context if we're dealing with an asynchronous request */
                    297:   if ((me->mode & AMAYA_ASYNC) ||
                    298:       (me->mode & AMAYA_IASYNC)) {
                    299:     me->reqStatus = HT_END;
1.48      cvs       300:     AHTReqContext_delete (me);
1.41      cvs       301:   }
                    302: #endif /* _WINDOWS */
                    303: 
                    304: }   
1.4       cvs       305: 
1.32      cvs       306: #ifdef _WINDOWS
1.29      cvs       307: /*----------------------------------------------------------------
1.32      cvs       308:   WIN_Activate_Request
1.29      cvs       309:   when there are more open requests than available sockets, the 
                    310:   requests are put in a "pending state." When a socket becomes
                    311:   available, libwww associates it with a pending request and then
                    312:   calls this callback function. This function is responsible for
                    313:   opening the temporary file where the GET and POST  results
                    314:   will be stored. The function is also responsible for 
                    315:   registering the socket with the Xt event loop.
                    316:   Consult the libwww manual for more details on the signature
                    317:   of this function.
                    318:   ----------------------------------------------------------------*/
                    319: #ifdef __STDC__
1.32      cvs       320: int                 WIN_Activate_Request (HTRequest * request, HTAlertOpcode op, int msgnum, const char *dfault, void *input, HTAlertPar * reply)
1.29      cvs       321: #else
1.32      cvs       322: int                 WIN_Activate_Request (request, op, msgnum, dfault, input, reply)
1.29      cvs       323: HTRequest          *request;
                    324: HTAlertOpcode       op;
                    325: int                 msgnum;
                    326: const char         *dfault;
                    327: void               *input;
                    328: HTAlertPar         *reply;
                    329: 
                    330: #endif /* __STDC__ */
                    331: {
                    332:    AHTReqContext      *me = HTRequest_context (request);
                    333: 
1.32      cvs       334:    if (me->reqStatus == HT_NEW) {
1.40      cvs       335:      if (!(me->output) &&
                    336:          (me->output != stdout) && 
1.38      cvs       337:         me->outputfile && 
                    338:         (me->output = fopen (me->outputfile, "wb")) == NULL) {
                    339:        /* the request is associated with a file */
                    340:        me->outputfile[0] = EOS;        /* file could not be opened */
                    341:        TtaSetStatus (me->docid, 1, 
                    342:                     TtaGetMessage (AMAYA, AM_CANNOT_CREATE_FILE),
                    343:                     me->outputfile);
                    344:        me->reqStatus = HT_ERR;
                    345:        if (me->error_html)
                    346:         DocNetworkStatus[me->docid] |= AMAYA_NET_ERROR; /* so we can show the error message */
1.32      cvs       347:       } else {
1.36      cvs       348:        if (THD_TRACE)
                    349:          fprintf (stderr, "WIN_Activate_Request: Activating pending %s . Open fd %d\n", me->urlName, (int) me->output);
                    350:        HTRequest_setOutputStream (me->request, AHTFWriter_new (me->request, me->output, YES));    
1.32      cvs       351:         /*change the status of the request */
                    352:         me->reqStatus = HT_WAITING;
                    353:       }
                    354:    } 
                    355:    else if (me->reqStatus == HT_WAITING) {
1.36      cvs       356:      
                    357:      /*change the status of the request */
                    358:      rewind (me->output);
                    359:      if (HTRequest_outputStream (me->request) == NULL)
                    360:        HTRequest_setOutputStream (me->request, AHTFWriter_new (me->request, me->output, YES));
1.32      cvs       361:    } 
                    362:    else {
1.36      cvs       363:      me->reqStatus = HT_ERR;
1.32      cvs       364:    }
                    365:    
1.36      cvs       366:    return ((me->reqStatus != HT_ERR) ? HT_OK : HT_ERROR);
1.32      cvs       367: }
                    368: 
1.38      cvs       369: #else /* _WINDOWS */
1.32      cvs       370: 
                    371: /*----------------------------------------------------------------
                    372:   Add_NewSocket_to_Loop
                    373:   when there are more open requests than available sockets, the 
                    374:   requests are put in a "pending state." When a socket becomes
                    375:   available, libwww associates it with a pending request and then
                    376:   calls this callback function. This function is responsible for
                    377:   opening the temporary file where the GET and POST  results
                    378:   will be stored. The function is also responsible for 
                    379:   registering the socket with the Xt event loop.
                    380:   Consult the libwww manual for more details on the signature
                    381:   of this function.
                    382:   ----------------------------------------------------------------*/
                    383: #ifdef __STDC__
                    384: int                 Add_NewSocket_to_Loop (HTRequest * request, HTAlertOpcode op, int msgnum, const char *dfault, void *input, HTAlertPar * reply)
                    385: #else
                    386: int                 Add_NewSocket_to_Loop (request, op, msgnum, dfault, input, reply)
                    387: HTRequest          *request;
                    388: HTAlertOpcode       op;
                    389: int                 msgnum;
                    390: const char         *dfault;
                    391: void               *input;
                    392: HTAlertPar         *reply;
1.29      cvs       393: 
1.32      cvs       394: #endif /* __STDC__ */
                    395: {
                    396:    AHTReqContext      *me = HTRequest_context (request);
1.38      cvs       397:    int status = HT_OK;
1.4       cvs       398: 
1.36      cvs       399: #ifdef DEBUG_LIBWWW
1.32      cvs       400:      fprintf (stderr, "(Activating a request\n");
1.36      cvs       401: #endif
1.30      cvs       402: 
1.40      cvs       403:      /* request was aborted (redirection, authentication) and now is is
                    404:        being automatically reissued */
                    405: 
                    406:      if (me->reqStatus == HT_BUSY && me->output) {
                    407:        fclose (me->output);
                    408:        me->output = NULL;
                    409:      }
                    410: 
                    411:      /* the request is active, open the output file */
                    412:      if (!(me->output) &&
                    413:         (me->output != stdout) && 
                    414:         me->outputfile &&
                    415:         !(me->output = fopen (me->outputfile, "w"))) {
                    416:        me->outputfile[0] = EOS;        
                    417:        /* file could not be opened */
                    418:        TtaSetStatus (me->docid, 1, 
                    419:                     TtaGetMessage (AMAYA, AM_CANNOT_CREATE_FILE),
                    420:                     me->outputfile);
                    421:        me->reqStatus = HT_ERR;
                    422:        status = HT_ERROR;
                    423:        /* should the error be shown on the Amaya doc window? */
                    424:        if (me->error_html)
                    425:         DocNetworkStatus[me->docid] |= AMAYA_NET_ERROR; 
                    426:      }
1.38      cvs       427: 
1.40      cvs       428:      if (me->output) {
                    429:        
                    430:        HTRequest_setOutputStream (me->request,
                    431:                                  AHTFWriter_new (me->request, 
                    432:                                                  me->output, 
                    433:                                                  YES));
                    434:        me->reqStatus = HT_WAITING;
1.43      cvs       435: #ifdef DEBUG_LIBWWW
                    436:         fprintf (stderr, "Add_NewSocket_to_Loop: Activating "
                    437:                  "pending %s . Open fd %p, stream %p\n", 
                    438:                  me->urlName, (int) me->output, HTRequest_outputStream(me->request));
                    439: #endif
                    440: 
1.40      cvs       441:      }
1.43      cvs       442: #ifdef DEBUG_LIBWWW
                    443:      else {
                    444:         fprintf (stderr, "Add_NewSocket_to_Loop: Error, me->output == NULL\n"
                    445:                  "for URL %s . Open fd %p, stream %p\n", 
                    446:                  me->urlName, (int) me->output, HTRequest_outputStream(me->request));
                    447:      }
                    448: #endif
1.40      cvs       449: 
1.32      cvs       450:    
1.40      cvs       451:      return (status);
1.4       cvs       452: }
1.32      cvs       453: #endif /* _WINDOWS */
1.4       cvs       454: 
1.11      cvs       455: /*----------------------------------------------------------------------
                    456:   AHTEvent_register
                    457:   callback called by libwww whenever a socket is open and associated
                    458:   to a request. It sets the pertinent Xt events so that the Xt Event
                    459:   loops gets an interruption whenever there's action of the socket. 
                    460:   In addition, it registers the request with libwww.
                    461:   ----------------------------------------------------------------------*/
1.4       cvs       462: #ifdef __STDC__
1.7       cvs       463: int                 AHTEvent_register (SOCKET sock, HTRequest * rqp, SockOps ops, HTEventCallback * cbf, HTPriority p)
1.4       cvs       464: #else
1.7       cvs       465: int                 AHTEvent_register (sock, rqp, ops, cbf, p)
                    466: SOCKET              sock;
                    467: HTRequest          *rqp;
                    468: SockOps             ops;
                    469: HTEventCallback    *cbf;
                    470: HTPriority          p;
                    471: 
                    472: #endif /* __STDC__ */
1.4       cvs       473: {
1.40      cvs       474:   AHTReqContext      *me;      /* current request */
                    475:   int                 status;  /* libwww status associated with 
                    476:                                  the socket number */
                    477:   int                 v;
1.7       cvs       478: 
1.43      cvs       479: #ifdef DEBUG_LIBWWW
                    480:          fprintf(stderr, "HTEvent_register\n");
                    481: #endif /* DEBUG_LIBWWW */
1.40      cvs       482:   if (sock == INVSOC)
                    483:     return (0);
1.4       cvs       484: 
1.47      cvs       485:   /* get the request associated to the socket number */
1.43      cvs       486: 
1.47      cvs       487: #ifndef _WINDOWS
                    488:   v = HASH (sock);
                    489:   if (persSockets[v] != 0)
                    490:     {
                    491:       XtRemoveInput (persSockets[v]);
                    492:       persSockets[v] = 0;      
                    493:     }
                    494: #endif
1.7       cvs       495: 
1.40      cvs       496:   if (rqp == NULL) 
                    497:     {
1.37      cvs       498: #ifndef _WINDOWS 
1.40      cvs       499:       if (ops == FD_CLOSE)
                    500:        {
1.36      cvs       501: #ifdef DEBUG_LIBWWW
1.40      cvs       502:          fprintf(stderr, "HTEvent_register: ***** RQP is NULL @@@@@\n");
1.37      cvs       503: #endif /* DEBUG_LIBWWW */
1.43      cvs       504: 
1.40      cvs       505:          persSockets[v] = XtAppAddInput (app_cont, 
                    506:                                          sock,
                    507:                                          (XtPointer) XtInputReadMask,
                    508:                                          (XtInputCallbackProc) AHTCallback_bridge,
                    509:                                          (XtPointer) XtInputReadMask);
                    510:        } /* *fd_close */
1.43      cvs       511: 
1.39      cvs       512: #endif /* !_WINDOWS */
1.40      cvs       513:     }
                    514:   else /* rqp */
                    515:     {
                    516:       me = HTRequest_context (rqp);
1.47      cvs       517:       
                    518:       /* Erase any trailing events */
1.43      cvs       519:       /*         HTEventrg_unregister (sock, FD_ALL); */
1.47      cvs       520:       
1.33      cvs       521: #ifndef _WINDOWS
1.38      cvs       522:        if (ops & ReadBits)
                    523:         {
                    524:           me->read_ops = ops;
                    525:           RequestRegisterReadXtevent (me, sock);
                    526:         }
                    527:        
                    528:        if (ops & WriteBits)
                    529:         {
                    530:           me->write_ops = ops;
                    531:           RequestRegisterWriteXtevent (me, sock);
                    532:         }
                    533:        
                    534:        if (ops & ExceptBits)
                    535:         {
                    536:           me->except_ops = ops;
                    537:           RequestRegisterExceptXtevent (me, sock);
                    538:         }
1.33      cvs       539: #endif  /* !_WINDOWS */
1.38      cvs       540:        
1.43      cvs       541: #ifdef DEBUG_LIBWWW
                    542:        fprintf (stderr, "AHTEvent_register: URL %s, SOCK %d, 
                    543:                 ops %lu, fd %p \n",
                    544:                me->urlName, sock, ops, me->output);
                    545: #endif /* DEBUG_LIBWWW */       
1.38      cvs       546:      } /* if *rqp */
1.50      cvs       547: 
1.51      cvs       548: #ifdef _WINDOWS   
1.50      cvs       549:   /* under windows, libwww requires an explicit FD_CLOSE registration 
                    550:    to detect HTTP responses not having a Content-Length header */
                    551:    status = HTEventrg_register (sock, rqp, ops | FD_CLOSE,
                    552:                                cbf, p);
                    553: #else
1.37      cvs       554:    status = HTEventrg_register (sock, rqp, ops,
1.38      cvs       555:                                cbf, p);
1.51      cvs       556: #endif /* _WINDOWS */
1.50      cvs       557: 
1.7       cvs       558:    return (status);
1.4       cvs       559: }
1.34      cvs       560: 
                    561: /*----------------------------------------------------------------------
                    562:   AHTEvent_unregister
                    563:   callback called by libwww each time a request is unregistered. This
                    564:   function takes care of unregistering the pertinent Xt events
                    565:   associated with the request's socket. In addition, it unregisters
                    566:   the request from libwww.
                    567:   ----------------------------------------------------------------------*/
                    568: #ifdef __STDC__
                    569: int                 AHTEvent_unregister (SOCKET sock, SockOps ops)
                    570: #else
                    571: int                 AHTEvent_unregister (sock, ops)
                    572: SOCKET              sock;
                    573: SockOps             ops;
                    574: 
                    575: #endif /* __STDC__ */
                    576: {
                    577:    int                 status;
                    578:    HTRequest          *rqp = NULL;
1.39      cvs       579: #ifndef _WINDOWS
1.34      cvs       580:    AHTReqContext      *me;
1.44      cvs       581: #endif /* _WINDOWS */
                    582: 
1.38      cvs       583:    int                 v;
1.34      cvs       584: 
                    585:    /* Libwww 5.0a does not take into account the third parameter
                    586:       **  for this function call */
                    587: 
1.36      cvs       588: #ifndef _WINDOWS
                    589:    HTEventCallback     *cbf = (HTEventCallback *) __RetrieveCBF (sock, (SockOps) NULL, &rqp);
1.38      cvs       590: #endif /* _WINDOWS */
                    591: 
                    592:    if (sock == INVSOC)
                    593:      return HT_OK;
                    594: 
                    595: #ifndef _WINDOWS   
1.36      cvs       596: #ifdef DEBUG_LIBWWW
1.52    ! cvs       597:    fprintf (stderr, "AHTEventUnregister: cbf = %d, sock = %d, rqp = %d, ops= %x\n", cbf, sock, rqp, ops);
1.38      cvs       598: #endif /* DEBUG_LIBWWW */
                    599: 
                    600:    v = HASH (sock);
1.47      cvs       601:    if (persSockets[v] != 0) 
                    602:      {
                    603:        XtRemoveInput (persSockets[v]);
                    604:        persSockets[v] = 0;
                    605:      }
1.43      cvs       606: 
1.7       cvs       607:    if (cbf)
                    608:      {
1.38      cvs       609:        if (rqp && (me = HTRequest_context (rqp)) )
1.36      cvs       610:         {
                    611:           if (ops & ReadBits) 
                    612:             RequestKillReadXtevent (me);
                    613:           
                    614:           if (ops & WriteBits)
                    615:             RequestKillWriteXtevent (me);
                    616:           
                    617:           if (ops & ExceptBits)
                    618:             RequestKillExceptXtevent (me);
                    619:         }
1.7       cvs       620:      }
1.36      cvs       621: #endif /* !_WINDOWS */
1.35      cvs       622: 
1.7       cvs       623:    status = HTEventrg_unregister (sock, ops);
1.35      cvs       624: 
1.7       cvs       625:    return (status);
1.4       cvs       626: }
1.35      cvs       627: 
                    628: #ifndef _WINDOWS
1.4       cvs       629: 
1.11      cvs       630: /*----------------------------------------------------------------------
                    631:   RequestKillAllXtevents
                    632:   front-end for kill all Xt events associated with the request pointed
                    633:   to by "me".
                    634:   ----------------------------------------------------------------------*/
1.4       cvs       635: #ifdef __STDC__
1.7       cvs       636: void                RequestKillAllXtevents (AHTReqContext * me)
1.4       cvs       637: #else
1.7       cvs       638: void                RequestKillAllXtevents (me)
                    639: AHTReqContext      *me;
                    640: #endif /* __STDC__ */
1.4       cvs       641: {
1.7       cvs       642:    if (THD_TRACE)
                    643:       fprintf (stderr, "Request_kill: Clearing Xtinputs\n");
1.4       cvs       644: 
1.7       cvs       645:    RequestKillReadXtevent (me);
                    646:    RequestKillWriteXtevent (me);
                    647:    RequestKillExceptXtevent (me);
1.4       cvs       648: }
                    649: 
1.11      cvs       650: /*----------------------------------------------------------------------
1.18      cvs       651:   RequestRegisterReadXtevent
                    652:   Registers with Xt the read events associated with socket sock
                    653:   ----------------------------------------------------------------------*/
                    654: #ifdef __STDC__
                    655: static void         RequestRegisterReadXtevent (AHTReqContext * me, SOCKET sock)
                    656: #else
                    657: static void         RequestRegisterReadXtevent (me, sock)
                    658: AHTReqContext      *me;
                    659: SOCKET sock;
                    660: #endif /* __STDC__ */
                    661: {
                    662:   if (me->read_xtinput_id)
                    663:     {
                    664:       if (THD_TRACE)
                    665:        fprintf (stderr, "Request_kill: Clearing Xtinput %lu Socket %d R\n", me->read_xtinput_id, sock);
                    666:       XtRemoveInput (me->read_xtinput_id);
                    667:     }
                    668: 
                    669:   me->read_xtinput_id =
                    670:     XtAppAddInput (app_cont,
                    671:                   sock,
                    672:                   (XtPointer) XtInputReadMask,
                    673:                   (XtInputCallbackProc) AHTCallback_bridge,
                    674:                   (XtPointer) XtInputReadMask);
                    675: 
1.26      cvs       676:    if (THD_TRACE)
1.18      cvs       677:     fprintf (stderr, "(BT) adding Xtinput %lu Socket %d R\n",
                    678:             me->read_xtinput_id, sock);
                    679: 
                    680: }
                    681: 
                    682: /*----------------------------------------------------------------------
1.11      cvs       683:   RequestKillReadXtevent
                    684:   kills any read Xt event associated with the request pointed to by "me".
                    685:   ----------------------------------------------------------------------*/
1.4       cvs       686: #ifdef __STDC__
1.7       cvs       687: static void         RequestKillReadXtevent (AHTReqContext * me)
1.4       cvs       688: #else
1.7       cvs       689: static void         RequestKillReadXtevent (me)
                    690: AHTReqContext      *me;
                    691: #endif /* __STDC__ */
1.4       cvs       692: {
1.7       cvs       693:    if (me->read_xtinput_id)
                    694:      {
                    695:        if (THD_TRACE)
1.18      cvs       696:           fprintf (stderr, "Request_kill: Clearing Xtinput %lu R\n", me->read_xtinput_id);
1.7       cvs       697:        XtRemoveInput (me->read_xtinput_id);
                    698:        me->read_xtinput_id = (XtInputId) NULL;
                    699:      }
1.18      cvs       700: }
                    701: 
                    702: /*----------------------------------------------------------------------
                    703:   RequestRegisterWriteXtevent
                    704:   Registers with Xt the write events associated with socket sock
                    705:   ----------------------------------------------------------------------*/
                    706: #ifdef __STDC__
                    707: static void         RequestRegisterWriteXtevent (AHTReqContext * me, SOCKET sock)
                    708: #else
                    709: static void         RequestRegisterWriteXtevent (me, sock)
                    710: AHTReqContext      *me;
                    711: SOCKET              sock;
                    712: 
                    713: #endif /* __STDC__ */
                    714: {
                    715:    if (me->write_xtinput_id)
                    716:     {
                    717:       if (THD_TRACE)
                    718:        fprintf (stderr, "Request_kill: Clearing Xtinput %lu Socket %d W\n", me->write_xtinput_id, sock);
                    719:       XtRemoveInput (me->write_xtinput_id);
                    720:     }
                    721: 
                    722:   me->write_xtinput_id =
                    723:     XtAppAddInput (app_cont,
                    724:                   sock,
                    725:                   (XtPointer) XtInputWriteMask,
                    726:                   (XtInputCallbackProc) AHTCallback_bridge,
                    727:                   (XtPointer) XtInputWriteMask);
                    728: 
                    729:   if (THD_TRACE)
                    730:     fprintf (stderr, "(BT) adding Xtinput %lu Socket %d W\n",
                    731:             me->write_xtinput_id, sock);
1.4       cvs       732: }
                    733: 
1.11      cvs       734: /*----------------------------------------------------------------------
                    735:   RequestKillWriteXtevent
                    736:   kills any write Xt event associated with the request pointed to
                    737:   by "me".
                    738:   ----------------------------------------------------------------------*/
1.4       cvs       739: #ifdef __STDC__
1.7       cvs       740: static void         RequestKillWriteXtevent (AHTReqContext * me)
1.4       cvs       741: #else
1.7       cvs       742: static void         RequestKillWriteXtevent (me)
                    743: AHTReqContext      *me;
                    744: #endif /* __STDC__ */
1.4       cvs       745: {
1.7       cvs       746:    if (me->write_xtinput_id)
                    747:      {
                    748:        if (THD_TRACE)
                    749:           fprintf (stderr, "Request_kill: Clearing Write Xtinputs %lu\n", me->write_xtinput_id);
                    750:        XtRemoveInput (me->write_xtinput_id);
                    751:        me->write_xtinput_id = (XtInputId) NULL;
                    752:      }
1.18      cvs       753: }
                    754: 
                    755: /*----------------------------------------------------------------------
                    756:   RequestRegisterExceptXtevent
                    757:   Registers with Xt the except events associated with socket sock
                    758:   ----------------------------------------------------------------------*/
                    759: #ifdef __STDC__
                    760: static void         RequestRegisterExceptXtevent (AHTReqContext * me, SOCKET sock)
                    761: #else
                    762: static void         RequestRegisterExceptXtevent (me, sock)
                    763: AHTReqContext      *me;
                    764: SOCKET              sock;
                    765: 
                    766: #endif /* __STDC__ */
                    767: {
                    768:    if (me->except_xtinput_id)
                    769:      {
                    770:        if (THD_TRACE)
                    771:           fprintf (stderr, "Request_kill: Clearing Xtinput %lu Socket %d E\n", me->except_xtinput_id, sock);
                    772:        XtRemoveInput (me->except_xtinput_id);
                    773:      }
                    774: 
                    775:   me->except_xtinput_id =
                    776:     XtAppAddInput (app_cont,
                    777:                   sock,
                    778:                   (XtPointer) XtInputExceptMask,
                    779:                   (XtInputCallbackProc) AHTCallback_bridge,
                    780:                   (XtPointer) XtInputExceptMask);
                    781: 
                    782:   if (THD_TRACE)
                    783:     fprintf (stderr, "(BT) adding Xtinput %lu Socket %d E\n",
                    784:             me->write_xtinput_id, sock);
                    785: 
1.4       cvs       786: }
                    787: 
1.11      cvs       788: /*----------------------------------------------------------------------
                    789:   RequestKillExceptXtevent
                    790:   kills any exception Xt event associated with the request pointed to
                    791:   by "me".
                    792:   ----------------------------------------------------------------------*/
1.4       cvs       793: #ifdef __STDC__
1.7       cvs       794: static void         RequestKillExceptXtevent (AHTReqContext * me)
1.4       cvs       795: #else
1.7       cvs       796: static void         RequestKillExceptXtevent (me)
                    797: AHTReqContext      *me;
                    798: #endif /* __STDC__ */
1.4       cvs       799: {
1.7       cvs       800:    if (me->except_xtinput_id)
                    801:      {
                    802:        if (THD_TRACE)
                    803:           fprintf (stderr, "Request_kill: Clearing Except Xtinputs %lu\n", me->except_xtinput_id);
                    804:        XtRemoveInput (me->except_xtinput_id);
                    805:        me->except_xtinput_id = (XtInputId) NULL;
                    806:      }
1.31      cvs       807: }
1.32      cvs       808: #endif /* !_WINDOWS */
1.31      cvs       809: 
1.23      cvs       810: #endif /* !AMAYA_JAVA */
1.11      cvs       811: 

Webmaster