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

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

Webmaster