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

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

Webmaster