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

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.53      cvs       166:    if ((me->mode & AMAYA_ASYNC)
                    167:        || (me->mode & AMAYA_IASYNC))
                    168:        /* set protection to avoid stopping an active request */
                    169:        me->mode |= AMAYA_ASYNC_SAFE_STOP;
                    170: 
                    171:        /* invoke the libwww callback */
1.52      cvs       172:    status = (*cbf) (socket, rqp, ops);
1.53      cvs       173: 
1.36      cvs       174: #ifdef DEBUG_LIBWWW
1.52      cvs       175:    if (status != HT_OK)
1.36      cvs       176:       HTTrace ("Callback.... returned a value != HT_OK");
                    177: #endif
1.7       cvs       178:    /* Several states can happen after this callback. They
                    179:     * are indicated by the me->reqStatus structure member and
                    180:     * the fds external variables. The following lines examine
                    181:     * the states and correspondly update the Xt event register
                    182:     *
                    183:     * Regarding the me->reqStatus member, we have the following
                    184:     * possible states:
                    185:     *   
                    186:     * HT_BUSY:    Request has blocked
                    187:     * HT_WAITING: Request has been reissued
                    188:     * HT_ABORT:   Request has been stopped
                    189:     * HT_END:     Request has ended
                    190:     */
                    191: 
1.53      cvs       192:    if ((me->mode & AMAYA_ASYNC)
                    193:        || (me->mode & AMAYA_IASYNC))
                    194:        /* remove protection to avoid stopping an active request */
                    195:        me->mode &= ~AMAYA_ASYNC_SAFE_STOP;
                    196: 
1.32      cvs       197:    if (me->reqStatus == HT_ABORT) {
1.11      cvs       198:    /* Has the user stopped the request? */
1.38      cvs       199:      me->reqStatus = HT_WAITING;
                    200:      StopRequest (me->docid);
                    201:      return (0);
1.32      cvs       202:    }
1.7       cvs       203: 
1.42      cvs       204:    if (me->reqStatus == HT_WAITING ||
                    205:        me->reqStatus == HT_NEW) {
1.38      cvs       206:      /* the request is being reissued */
                    207:      /*
                    208:       * (1) The old request has ended and the library
                    209:       * assigned the old socket number to a pending
                    210:       * request.
                    211:       *
                    212:       * (2) The request has been reissued after an 
                    213:       * authentication or redirection directive and
                    214:       * we are using the same old socket number.
                    215:       */
                    216:      
1.36      cvs       217: #ifdef DEBUG_LIBWWW
1.38      cvs       218:      fprintf (stderr, "*** detected a reissue of request \n");
1.36      cvs       219: #endif
1.38      cvs       220:      return (0);
1.32      cvs       221:    }
1.4       cvs       222: 
1.32      cvs       223:    /* we verify if the request exists. If it has ended, we will have
                    224:       a reqStatus with an HT_END value */
1.7       cvs       225: 
1.36      cvs       226:    if ((me->reqStatus == HT_END) ||
                    227:        (me->reqStatus == HT_ERR)) {
                    228:         /* request has ended */
                    229: #ifdef DEBUG_LIBWWW
1.40      cvs       230:        fprintf (stderr, "(BF) removing Xtinput %lu !RWE, sock %d (Request has ended)\n", *id, socket);
1.36      cvs       231: #endif
1.41      cvs       232: 
                    233:        if ((me->mode & AMAYA_ASYNC) || (me->mode & AMAYA_IASYNC))
                    234:         {
                    235:           /* free the memory allocated for async requests */
1.54      cvs       236:           /* IV: invert two following lines */
                    237:           AHTPrintPendingRequestStatus (me->docid, YES);
1.41      cvs       238:           AHTReqContext_delete (me);
                    239:         } 
1.43      cvs       240: 
1.41      cvs       241:        else if (me->reqStatus == HT_END &&
                    242:                HTError_hasSeverity (HTRequest_error (me->request),
                    243:                                     ERR_NON_FATAL))
                    244: 
1.38      cvs       245:         /* did the SYNC request end because of an error? If yes, report it back to the caller */
                    246:         me->reqStatus = HT_ERR;
                    247:        return (0);
1.32      cvs       248:    }
1.38      cvs       249: 
1.36      cvs       250:    /* The request is still alive, so change it's status to indicate 
                    251:       it's out of the critical section */
1.7       cvs       252:    me->reqStatus = HT_WAITING;
                    253:    return (0);
1.4       cvs       254: }
1.37      cvs       255: #endif /* !_WINDOWS */
1.41      cvs       256: 
                    257: /*--------------------------------------------------------------------
                    258:   ProcessTerminateRequest
                    259:   This function is called whenever a request has ended. If the requested
                    260:   ended normally, the function will call any callback associated to the
                    261:   request. Otherwise, it will just mark the request as over.
                    262:   -------------------------------------------------------------------*/
                    263: #ifdef __STDC__
                    264: void  ProcessTerminateRequest (AHTReqContext *me)
                    265: #else
                    266: void ProcessTerminateRequest (me)
                    267: AHTReqContext *me;
                    268: #endif
                    269: {   
                    270:   /* Second Step: choose a correct treatment in function of the request's
                    271:      being associated with an error, with an interruption, or with a
                    272:      succesful completion */
                    273:    
                    274:   if (me->reqStatus == HT_END)
                    275:     {
1.52      cvs       276:       if (AmayaIsAlive () && me->terminate_cbf)
1.49      cvs       277:        (*me->terminate_cbf) (me->docid, 0, me->urlName, me->outputfile,
                    278:                              me->content_type, me->context_tcbf);
1.41      cvs       279:     }
1.42      cvs       280:   else if (me->reqStatus == HT_ABORT)
1.41      cvs       281:     /* either the application ended or the user pressed the stop 
                    282:        button. We erase the incoming file, if it exists */
                    283:     {
1.52      cvs       284:       if (AmayaIsAlive () && me->terminate_cbf)
                    285:        (*me->terminate_cbf) (me->docid, -1, me->urlName, me->outputfile,
                    286:                              me->content_type, me->context_tcbf);
1.41      cvs       287:       if (me->outputfile && me->outputfile[0] != EOS)
                    288:        {
                    289:          TtaFileUnlink (me->outputfile);
                    290:          me->outputfile[0] = EOS;
                    291:        }
                    292:     }
                    293:   else if (me->reqStatus == HT_ERR)
                    294:     {
                    295:       /* there was an error */
1.52      cvs       296:       if (AmayaIsAlive () && me->terminate_cbf)
1.49      cvs       297:        (*me->terminate_cbf) (me->docid, -1, me->urlName, me->outputfile,
                    298:                              me->content_type, me->context_tcbf);
1.41      cvs       299:       
                    300:       if (me->outputfile && me->outputfile[0] != EOS)
                    301:        {
                    302:          TtaFileUnlink (me->outputfile);
                    303:          me->outputfile[0] = EOS;
                    304:        }
                    305:     }
1.49      cvs       306: 
1.41      cvs       307: #ifdef _WINDOWS
                    308:    /* we erase the context if we're dealing with an asynchronous request */
                    309:   if ((me->mode & AMAYA_ASYNC) ||
                    310:       (me->mode & AMAYA_IASYNC)) {
                    311:     me->reqStatus = HT_END;
1.48      cvs       312:     AHTReqContext_delete (me);
1.41      cvs       313:   }
                    314: #endif /* _WINDOWS */
                    315: 
                    316: }   
1.4       cvs       317: 
1.32      cvs       318: #ifdef _WINDOWS
1.29      cvs       319: /*----------------------------------------------------------------
1.32      cvs       320:   WIN_Activate_Request
1.29      cvs       321:   when there are more open requests than available sockets, the 
                    322:   requests are put in a "pending state." When a socket becomes
                    323:   available, libwww associates it with a pending request and then
                    324:   calls this callback function. This function is responsible for
                    325:   opening the temporary file where the GET and POST  results
                    326:   will be stored. The function is also responsible for 
                    327:   registering the socket with the Xt event loop.
                    328:   Consult the libwww manual for more details on the signature
                    329:   of this function.
                    330:   ----------------------------------------------------------------*/
                    331: #ifdef __STDC__
1.32      cvs       332: int                 WIN_Activate_Request (HTRequest * request, HTAlertOpcode op, int msgnum, const char *dfault, void *input, HTAlertPar * reply)
1.29      cvs       333: #else
1.32      cvs       334: int                 WIN_Activate_Request (request, op, msgnum, dfault, input, reply)
1.29      cvs       335: HTRequest          *request;
                    336: HTAlertOpcode       op;
                    337: int                 msgnum;
                    338: const char         *dfault;
                    339: void               *input;
                    340: HTAlertPar         *reply;
                    341: 
                    342: #endif /* __STDC__ */
                    343: {
                    344:    AHTReqContext      *me = HTRequest_context (request);
                    345: 
1.32      cvs       346:    if (me->reqStatus == HT_NEW) {
1.40      cvs       347:      if (!(me->output) &&
                    348:          (me->output != stdout) && 
1.38      cvs       349:         me->outputfile && 
                    350:         (me->output = fopen (me->outputfile, "wb")) == NULL) {
                    351:        /* the request is associated with a file */
                    352:        me->outputfile[0] = EOS;        /* file could not be opened */
                    353:        TtaSetStatus (me->docid, 1, 
                    354:                     TtaGetMessage (AMAYA, AM_CANNOT_CREATE_FILE),
                    355:                     me->outputfile);
                    356:        me->reqStatus = HT_ERR;
                    357:        if (me->error_html)
                    358:         DocNetworkStatus[me->docid] |= AMAYA_NET_ERROR; /* so we can show the error message */
1.32      cvs       359:       } else {
1.36      cvs       360:        if (THD_TRACE)
                    361:          fprintf (stderr, "WIN_Activate_Request: Activating pending %s . Open fd %d\n", me->urlName, (int) me->output);
                    362:        HTRequest_setOutputStream (me->request, AHTFWriter_new (me->request, me->output, YES));    
1.32      cvs       363:         /*change the status of the request */
                    364:         me->reqStatus = HT_WAITING;
                    365:       }
                    366:    } 
                    367:    else if (me->reqStatus == HT_WAITING) {
1.36      cvs       368:      
                    369:      /*change the status of the request */
                    370:      rewind (me->output);
                    371:      if (HTRequest_outputStream (me->request) == NULL)
                    372:        HTRequest_setOutputStream (me->request, AHTFWriter_new (me->request, me->output, YES));
1.32      cvs       373:    } 
                    374:    else {
1.36      cvs       375:      me->reqStatus = HT_ERR;
1.32      cvs       376:    }
                    377:    
1.36      cvs       378:    return ((me->reqStatus != HT_ERR) ? HT_OK : HT_ERROR);
1.32      cvs       379: }
                    380: 
1.38      cvs       381: #else /* _WINDOWS */
1.32      cvs       382: 
                    383: /*----------------------------------------------------------------
                    384:   Add_NewSocket_to_Loop
                    385:   when there are more open requests than available sockets, the 
                    386:   requests are put in a "pending state." When a socket becomes
                    387:   available, libwww associates it with a pending request and then
                    388:   calls this callback function. This function is responsible for
                    389:   opening the temporary file where the GET and POST  results
                    390:   will be stored. The function is also responsible for 
                    391:   registering the socket with the Xt event loop.
                    392:   Consult the libwww manual for more details on the signature
                    393:   of this function.
                    394:   ----------------------------------------------------------------*/
                    395: #ifdef __STDC__
                    396: int                 Add_NewSocket_to_Loop (HTRequest * request, HTAlertOpcode op, int msgnum, const char *dfault, void *input, HTAlertPar * reply)
                    397: #else
                    398: int                 Add_NewSocket_to_Loop (request, op, msgnum, dfault, input, reply)
                    399: HTRequest          *request;
                    400: HTAlertOpcode       op;
                    401: int                 msgnum;
                    402: const char         *dfault;
                    403: void               *input;
                    404: HTAlertPar         *reply;
1.29      cvs       405: 
1.32      cvs       406: #endif /* __STDC__ */
                    407: {
                    408:    AHTReqContext      *me = HTRequest_context (request);
1.38      cvs       409:    int status = HT_OK;
1.4       cvs       410: 
1.36      cvs       411: #ifdef DEBUG_LIBWWW
1.32      cvs       412:      fprintf (stderr, "(Activating a request\n");
1.36      cvs       413: #endif
1.30      cvs       414: 
1.40      cvs       415:      /* request was aborted (redirection, authentication) and now is is
                    416:        being automatically reissued */
                    417: 
                    418:      if (me->reqStatus == HT_BUSY && me->output) {
                    419:        fclose (me->output);
                    420:        me->output = NULL;
                    421:      }
                    422: 
                    423:      /* the request is active, open the output file */
                    424:      if (!(me->output) &&
                    425:         (me->output != stdout) && 
                    426:         me->outputfile &&
                    427:         !(me->output = fopen (me->outputfile, "w"))) {
                    428:        me->outputfile[0] = EOS;        
                    429:        /* file could not be opened */
                    430:        TtaSetStatus (me->docid, 1, 
                    431:                     TtaGetMessage (AMAYA, AM_CANNOT_CREATE_FILE),
                    432:                     me->outputfile);
                    433:        me->reqStatus = HT_ERR;
                    434:        status = HT_ERROR;
                    435:        /* should the error be shown on the Amaya doc window? */
                    436:        if (me->error_html)
                    437:         DocNetworkStatus[me->docid] |= AMAYA_NET_ERROR; 
                    438:      }
1.38      cvs       439: 
1.40      cvs       440:      if (me->output) {
                    441:        
                    442:        HTRequest_setOutputStream (me->request,
                    443:                                  AHTFWriter_new (me->request, 
                    444:                                                  me->output, 
                    445:                                                  YES));
                    446:        me->reqStatus = HT_WAITING;
1.43      cvs       447: #ifdef DEBUG_LIBWWW
                    448:         fprintf (stderr, "Add_NewSocket_to_Loop: Activating "
                    449:                  "pending %s . Open fd %p, stream %p\n", 
                    450:                  me->urlName, (int) me->output, HTRequest_outputStream(me->request));
                    451: #endif
                    452: 
1.40      cvs       453:      }
1.43      cvs       454: #ifdef DEBUG_LIBWWW
                    455:      else {
                    456:         fprintf (stderr, "Add_NewSocket_to_Loop: Error, me->output == NULL\n"
                    457:                  "for URL %s . Open fd %p, stream %p\n", 
                    458:                  me->urlName, (int) me->output, HTRequest_outputStream(me->request));
                    459:      }
                    460: #endif
1.40      cvs       461: 
1.32      cvs       462:    
1.40      cvs       463:      return (status);
1.4       cvs       464: }
1.32      cvs       465: #endif /* _WINDOWS */
1.4       cvs       466: 
1.11      cvs       467: /*----------------------------------------------------------------------
                    468:   AHTEvent_register
                    469:   callback called by libwww whenever a socket is open and associated
                    470:   to a request. It sets the pertinent Xt events so that the Xt Event
                    471:   loops gets an interruption whenever there's action of the socket. 
                    472:   In addition, it registers the request with libwww.
                    473:   ----------------------------------------------------------------------*/
1.4       cvs       474: #ifdef __STDC__
1.7       cvs       475: int                 AHTEvent_register (SOCKET sock, HTRequest * rqp, SockOps ops, HTEventCallback * cbf, HTPriority p)
1.4       cvs       476: #else
1.7       cvs       477: int                 AHTEvent_register (sock, rqp, ops, cbf, p)
                    478: SOCKET              sock;
                    479: HTRequest          *rqp;
                    480: SockOps             ops;
                    481: HTEventCallback    *cbf;
                    482: HTPriority          p;
                    483: 
                    484: #endif /* __STDC__ */
1.4       cvs       485: {
1.40      cvs       486:   AHTReqContext      *me;      /* current request */
1.55    ! cvs       487:   int                 status;  /* libwww status associated with the socket number */
        !           488: # ifndef _WINDOWS 
1.40      cvs       489:   int                 v;
1.55    ! cvs       490: # endif /* _WINDOWS */
1.7       cvs       491: 
1.43      cvs       492: #ifdef DEBUG_LIBWWW
                    493:          fprintf(stderr, "HTEvent_register\n");
                    494: #endif /* DEBUG_LIBWWW */
1.40      cvs       495:   if (sock == INVSOC)
                    496:     return (0);
1.4       cvs       497: 
1.47      cvs       498:   /* get the request associated to the socket number */
1.43      cvs       499: 
1.47      cvs       500: #ifndef _WINDOWS
                    501:   v = HASH (sock);
                    502:   if (persSockets[v] != 0)
                    503:     {
                    504:       XtRemoveInput (persSockets[v]);
                    505:       persSockets[v] = 0;      
                    506:     }
                    507: #endif
1.7       cvs       508: 
1.40      cvs       509:   if (rqp == NULL) 
                    510:     {
1.37      cvs       511: #ifndef _WINDOWS 
1.40      cvs       512:       if (ops == FD_CLOSE)
                    513:        {
1.36      cvs       514: #ifdef DEBUG_LIBWWW
1.40      cvs       515:          fprintf(stderr, "HTEvent_register: ***** RQP is NULL @@@@@\n");
1.37      cvs       516: #endif /* DEBUG_LIBWWW */
1.43      cvs       517: 
1.40      cvs       518:          persSockets[v] = XtAppAddInput (app_cont, 
                    519:                                          sock,
                    520:                                          (XtPointer) XtInputReadMask,
                    521:                                          (XtInputCallbackProc) AHTCallback_bridge,
                    522:                                          (XtPointer) XtInputReadMask);
                    523:        } /* *fd_close */
1.43      cvs       524: 
1.39      cvs       525: #endif /* !_WINDOWS */
1.40      cvs       526:     }
                    527:   else /* rqp */
                    528:     {
                    529:       me = HTRequest_context (rqp);
1.47      cvs       530:       
                    531:       /* Erase any trailing events */
1.43      cvs       532:       /*         HTEventrg_unregister (sock, FD_ALL); */
1.47      cvs       533:       
1.33      cvs       534: #ifndef _WINDOWS
1.38      cvs       535:        if (ops & ReadBits)
                    536:         {
                    537:           me->read_ops = ops;
                    538:           RequestRegisterReadXtevent (me, sock);
                    539:         }
                    540:        
                    541:        if (ops & WriteBits)
                    542:         {
                    543:           me->write_ops = ops;
                    544:           RequestRegisterWriteXtevent (me, sock);
                    545:         }
                    546:        
                    547:        if (ops & ExceptBits)
                    548:         {
                    549:           me->except_ops = ops;
                    550:           RequestRegisterExceptXtevent (me, sock);
                    551:         }
1.33      cvs       552: #endif  /* !_WINDOWS */
1.38      cvs       553:        
1.43      cvs       554: #ifdef DEBUG_LIBWWW
                    555:        fprintf (stderr, "AHTEvent_register: URL %s, SOCK %d, 
                    556:                 ops %lu, fd %p \n",
                    557:                me->urlName, sock, ops, me->output);
                    558: #endif /* DEBUG_LIBWWW */       
1.38      cvs       559:      } /* if *rqp */
1.50      cvs       560: 
1.51      cvs       561: #ifdef _WINDOWS   
1.50      cvs       562:   /* under windows, libwww requires an explicit FD_CLOSE registration 
                    563:    to detect HTTP responses not having a Content-Length header */
                    564:    status = HTEventrg_register (sock, rqp, ops | FD_CLOSE,
                    565:                                cbf, p);
                    566: #else
1.37      cvs       567:    status = HTEventrg_register (sock, rqp, ops,
1.38      cvs       568:                                cbf, p);
1.51      cvs       569: #endif /* _WINDOWS */
1.50      cvs       570: 
1.7       cvs       571:    return (status);
1.4       cvs       572: }
1.34      cvs       573: 
                    574: /*----------------------------------------------------------------------
                    575:   AHTEvent_unregister
                    576:   callback called by libwww each time a request is unregistered. This
                    577:   function takes care of unregistering the pertinent Xt events
                    578:   associated with the request's socket. In addition, it unregisters
                    579:   the request from libwww.
                    580:   ----------------------------------------------------------------------*/
                    581: #ifdef __STDC__
                    582: int                 AHTEvent_unregister (SOCKET sock, SockOps ops)
                    583: #else
                    584: int                 AHTEvent_unregister (sock, ops)
                    585: SOCKET              sock;
                    586: SockOps             ops;
                    587: 
                    588: #endif /* __STDC__ */
                    589: {
                    590:    int                 status;
                    591:    HTRequest          *rqp = NULL;
1.55    ! cvs       592: #  ifndef _WINDOWS
1.34      cvs       593:    AHTReqContext      *me;
1.55    ! cvs       594:    int                 v;
        !           595: #  endif /* _WINDOWS */
1.44      cvs       596: 
1.34      cvs       597: 
                    598:    /* Libwww 5.0a does not take into account the third parameter
                    599:       **  for this function call */
                    600: 
1.36      cvs       601: #ifndef _WINDOWS
                    602:    HTEventCallback     *cbf = (HTEventCallback *) __RetrieveCBF (sock, (SockOps) NULL, &rqp);
1.38      cvs       603: #endif /* _WINDOWS */
                    604: 
                    605:    if (sock == INVSOC)
                    606:      return HT_OK;
                    607: 
                    608: #ifndef _WINDOWS   
1.36      cvs       609: #ifdef DEBUG_LIBWWW
1.52      cvs       610:    fprintf (stderr, "AHTEventUnregister: cbf = %d, sock = %d, rqp = %d, ops= %x\n", cbf, sock, rqp, ops);
1.38      cvs       611: #endif /* DEBUG_LIBWWW */
                    612: 
                    613:    v = HASH (sock);
1.47      cvs       614:    if (persSockets[v] != 0) 
                    615:      {
                    616:        XtRemoveInput (persSockets[v]);
                    617:        persSockets[v] = 0;
                    618:      }
1.43      cvs       619: 
1.7       cvs       620:    if (cbf)
                    621:      {
1.38      cvs       622:        if (rqp && (me = HTRequest_context (rqp)) )
1.36      cvs       623:         {
                    624:           if (ops & ReadBits) 
                    625:             RequestKillReadXtevent (me);
                    626:           
                    627:           if (ops & WriteBits)
                    628:             RequestKillWriteXtevent (me);
                    629:           
                    630:           if (ops & ExceptBits)
                    631:             RequestKillExceptXtevent (me);
                    632:         }
1.7       cvs       633:      }
1.36      cvs       634: #endif /* !_WINDOWS */
1.35      cvs       635: 
1.7       cvs       636:    status = HTEventrg_unregister (sock, ops);
1.35      cvs       637: 
1.7       cvs       638:    return (status);
1.4       cvs       639: }
1.35      cvs       640: 
                    641: #ifndef _WINDOWS
1.4       cvs       642: 
1.11      cvs       643: /*----------------------------------------------------------------------
                    644:   RequestKillAllXtevents
                    645:   front-end for kill all Xt events associated with the request pointed
                    646:   to by "me".
                    647:   ----------------------------------------------------------------------*/
1.4       cvs       648: #ifdef __STDC__
1.7       cvs       649: void                RequestKillAllXtevents (AHTReqContext * me)
1.4       cvs       650: #else
1.7       cvs       651: void                RequestKillAllXtevents (me)
                    652: AHTReqContext      *me;
                    653: #endif /* __STDC__ */
1.4       cvs       654: {
1.7       cvs       655:    if (THD_TRACE)
                    656:       fprintf (stderr, "Request_kill: Clearing Xtinputs\n");
1.4       cvs       657: 
1.7       cvs       658:    RequestKillReadXtevent (me);
                    659:    RequestKillWriteXtevent (me);
                    660:    RequestKillExceptXtevent (me);
1.4       cvs       661: }
                    662: 
1.11      cvs       663: /*----------------------------------------------------------------------
1.18      cvs       664:   RequestRegisterReadXtevent
                    665:   Registers with Xt the read events associated with socket sock
                    666:   ----------------------------------------------------------------------*/
                    667: #ifdef __STDC__
                    668: static void         RequestRegisterReadXtevent (AHTReqContext * me, SOCKET sock)
                    669: #else
                    670: static void         RequestRegisterReadXtevent (me, sock)
                    671: AHTReqContext      *me;
                    672: SOCKET sock;
                    673: #endif /* __STDC__ */
                    674: {
                    675:   if (me->read_xtinput_id)
                    676:     {
                    677:       if (THD_TRACE)
                    678:        fprintf (stderr, "Request_kill: Clearing Xtinput %lu Socket %d R\n", me->read_xtinput_id, sock);
                    679:       XtRemoveInput (me->read_xtinput_id);
                    680:     }
                    681: 
                    682:   me->read_xtinput_id =
                    683:     XtAppAddInput (app_cont,
                    684:                   sock,
                    685:                   (XtPointer) XtInputReadMask,
                    686:                   (XtInputCallbackProc) AHTCallback_bridge,
                    687:                   (XtPointer) XtInputReadMask);
                    688: 
1.26      cvs       689:    if (THD_TRACE)
1.18      cvs       690:     fprintf (stderr, "(BT) adding Xtinput %lu Socket %d R\n",
                    691:             me->read_xtinput_id, sock);
                    692: 
                    693: }
                    694: 
                    695: /*----------------------------------------------------------------------
1.11      cvs       696:   RequestKillReadXtevent
                    697:   kills any read Xt event associated with the request pointed to by "me".
                    698:   ----------------------------------------------------------------------*/
1.4       cvs       699: #ifdef __STDC__
1.7       cvs       700: static void         RequestKillReadXtevent (AHTReqContext * me)
1.4       cvs       701: #else
1.7       cvs       702: static void         RequestKillReadXtevent (me)
                    703: AHTReqContext      *me;
                    704: #endif /* __STDC__ */
1.4       cvs       705: {
1.7       cvs       706:    if (me->read_xtinput_id)
                    707:      {
                    708:        if (THD_TRACE)
1.18      cvs       709:           fprintf (stderr, "Request_kill: Clearing Xtinput %lu R\n", me->read_xtinput_id);
1.7       cvs       710:        XtRemoveInput (me->read_xtinput_id);
                    711:        me->read_xtinput_id = (XtInputId) NULL;
                    712:      }
1.18      cvs       713: }
                    714: 
                    715: /*----------------------------------------------------------------------
                    716:   RequestRegisterWriteXtevent
                    717:   Registers with Xt the write events associated with socket sock
                    718:   ----------------------------------------------------------------------*/
                    719: #ifdef __STDC__
                    720: static void         RequestRegisterWriteXtevent (AHTReqContext * me, SOCKET sock)
                    721: #else
                    722: static void         RequestRegisterWriteXtevent (me, sock)
                    723: AHTReqContext      *me;
                    724: SOCKET              sock;
                    725: 
                    726: #endif /* __STDC__ */
                    727: {
                    728:    if (me->write_xtinput_id)
                    729:     {
                    730:       if (THD_TRACE)
                    731:        fprintf (stderr, "Request_kill: Clearing Xtinput %lu Socket %d W\n", me->write_xtinput_id, sock);
                    732:       XtRemoveInput (me->write_xtinput_id);
                    733:     }
                    734: 
                    735:   me->write_xtinput_id =
                    736:     XtAppAddInput (app_cont,
                    737:                   sock,
                    738:                   (XtPointer) XtInputWriteMask,
                    739:                   (XtInputCallbackProc) AHTCallback_bridge,
                    740:                   (XtPointer) XtInputWriteMask);
                    741: 
                    742:   if (THD_TRACE)
                    743:     fprintf (stderr, "(BT) adding Xtinput %lu Socket %d W\n",
                    744:             me->write_xtinput_id, sock);
1.4       cvs       745: }
                    746: 
1.11      cvs       747: /*----------------------------------------------------------------------
                    748:   RequestKillWriteXtevent
                    749:   kills any write Xt event associated with the request pointed to
                    750:   by "me".
                    751:   ----------------------------------------------------------------------*/
1.4       cvs       752: #ifdef __STDC__
1.7       cvs       753: static void         RequestKillWriteXtevent (AHTReqContext * me)
1.4       cvs       754: #else
1.7       cvs       755: static void         RequestKillWriteXtevent (me)
                    756: AHTReqContext      *me;
                    757: #endif /* __STDC__ */
1.4       cvs       758: {
1.7       cvs       759:    if (me->write_xtinput_id)
                    760:      {
                    761:        if (THD_TRACE)
                    762:           fprintf (stderr, "Request_kill: Clearing Write Xtinputs %lu\n", me->write_xtinput_id);
                    763:        XtRemoveInput (me->write_xtinput_id);
                    764:        me->write_xtinput_id = (XtInputId) NULL;
                    765:      }
1.18      cvs       766: }
                    767: 
                    768: /*----------------------------------------------------------------------
                    769:   RequestRegisterExceptXtevent
                    770:   Registers with Xt the except events associated with socket sock
                    771:   ----------------------------------------------------------------------*/
                    772: #ifdef __STDC__
                    773: static void         RequestRegisterExceptXtevent (AHTReqContext * me, SOCKET sock)
                    774: #else
                    775: static void         RequestRegisterExceptXtevent (me, sock)
                    776: AHTReqContext      *me;
                    777: SOCKET              sock;
                    778: 
                    779: #endif /* __STDC__ */
                    780: {
                    781:    if (me->except_xtinput_id)
                    782:      {
                    783:        if (THD_TRACE)
                    784:           fprintf (stderr, "Request_kill: Clearing Xtinput %lu Socket %d E\n", me->except_xtinput_id, sock);
                    785:        XtRemoveInput (me->except_xtinput_id);
                    786:      }
                    787: 
                    788:   me->except_xtinput_id =
                    789:     XtAppAddInput (app_cont,
                    790:                   sock,
                    791:                   (XtPointer) XtInputExceptMask,
                    792:                   (XtInputCallbackProc) AHTCallback_bridge,
                    793:                   (XtPointer) XtInputExceptMask);
                    794: 
                    795:   if (THD_TRACE)
                    796:     fprintf (stderr, "(BT) adding Xtinput %lu Socket %d E\n",
                    797:             me->write_xtinput_id, sock);
                    798: 
1.4       cvs       799: }
                    800: 
1.11      cvs       801: /*----------------------------------------------------------------------
                    802:   RequestKillExceptXtevent
                    803:   kills any exception Xt event associated with the request pointed to
                    804:   by "me".
                    805:   ----------------------------------------------------------------------*/
1.4       cvs       806: #ifdef __STDC__
1.7       cvs       807: static void         RequestKillExceptXtevent (AHTReqContext * me)
1.4       cvs       808: #else
1.7       cvs       809: static void         RequestKillExceptXtevent (me)
                    810: AHTReqContext      *me;
                    811: #endif /* __STDC__ */
1.4       cvs       812: {
1.7       cvs       813:    if (me->except_xtinput_id)
                    814:      {
                    815:        if (THD_TRACE)
                    816:           fprintf (stderr, "Request_kill: Clearing Except Xtinputs %lu\n", me->except_xtinput_id);
                    817:        XtRemoveInput (me->except_xtinput_id);
                    818:        me->except_xtinput_id = (XtInputId) NULL;
                    819:      }
1.31      cvs       820: }
1.32      cvs       821: #endif /* !_WINDOWS */
1.31      cvs       822: 
1.23      cvs       823: #endif /* !AMAYA_JAVA */
1.11      cvs       824: 

Webmaster