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

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

Webmaster