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

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

Webmaster