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

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

Webmaster