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

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

Webmaster