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

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

Webmaster