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

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.50      cvs        15:  *         J. K./R. G. 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.64    ! cvs        26: #include "HTEvtLst.h"
1.4       cvs        27: 
1.58      cvs        28: #if 0
                     29: #define DEBUG_LIBWWW
                     30: #define THD_TRACE 1
                     31: #endif
                     32: 
1.22      cvs        33: #ifndef _WINDOWS
1.4       cvs        34: /* Amaya's X appcontext */
1.38      cvs        35: 
1.16      cvs        36: extern ThotAppContext app_cont;
1.4       cvs        37: 
1.32      cvs        38: /* Private functions */
1.4       cvs        39: #ifdef __STDC__
1.58      cvs        40: static void         RequestRegisterReadXtevent (SOCKET);
                     41: static void         RequestKillReadXtevent (SOCKET);
                     42: static void         RequestRegisterWriteXtevent ( SOCKET);
                     43: static void         RequestKillWriteXtevent (SOCKET);
                     44: static void         RequestRegisterExceptXtevent ( SOCKET);
                     45: static void         RequestKillExceptXtevent (SOCKET);
1.27      cvs        46: #else /* __STDC__ */
1.18      cvs        47: static void         RequesAddReadXtevent ();
1.7       cvs        48: static void         RequestKillReadXtevent ();
1.18      cvs        49: static void         RequesAddWriteXtevent ();
1.7       cvs        50: static void         RequestKillWriteXtevent ();
1.18      cvs        51: static void         RequestRegisterExceptXtevent ();
1.7       cvs        52: static void         RequestKillExceptXtevent ();
1.27      cvs        53: #endif /* __STDC__ */
1.58      cvs        54: 
1.59      cvs        55: #endif /* !_WINDOWS */
1.24      cvs        56: 
1.32      cvs        57: /* Private variables */
1.4       cvs        58: 
                     59: /*
1.58      cvs        60:  * this set of HTEventType map our WinSock "socket event HTEventType" into 
1.4       cvs        61:  * our read and write sets. Note that under the canonical Unix model,
                     62:  * a non-blocking socket passed to an accept() call will appear as readable, 
                     63:  * whilst a non-blocking call to connect() will appear as writeable. In add.
                     64:  * if the connection has been closed, the socket will appear readable under
                     65:  * BSD Unix semantics 
                     66:  */
1.32      cvs        67: 
1.58      cvs        68: static const HTEventType ReadBits = HTEvent_READ | HTEvent_ACCEPT | HTEvent_CLOSE;
                     69: static const HTEventType WriteBits = HTEvent_WRITE | HTEvent_CONNECT;
                     70: static const HTEventType ExceptBits = HTEvent_OOB;
                     71: 
                     72: typedef struct sStatus {
                     73:   XtInputId read;             /* the different XtId's */
                     74:   XtInputId write;
                     75:   XtInputId except;
                     76: } SocketStatus;
1.4       cvs        77: 
1.38      cvs        78: #define SOCK_TABLE_SIZE 67
                     79: #define HASH(s) ((s) % SOCK_TABLE_SIZE)
1.58      cvs        80: static SocketStatus persSockets[SOCK_TABLE_SIZE];
1.4       cvs        81: 
1.10      cvs        82: /*--------------------------------------------------------------------
                     83:   AHTCallback_bridge
1.11      cvs        84:   this function acts as a bridge between Xt and libwww. From the Xt
                     85:   point of view, this function is the callback handler whenever there's
                     86:   any activity on the sockets associated with the active requests. From
                     87:   the libwww point of view, this is the function that takes the initiative
                     88:   to invoke the callback function associated with an active request,
                     89:   whenever there's an activity in the socket associated to it.
                     90:   In this latter  aspect, this function is similar to the library's
                     91:   own __DoCallback()  function.
                     92:   Upon activation, the function looks up the request associated with the
                     93:   active socket and then looks up the cbf associated with that request.
                     94:   Upon completion of the execution of the request's cbf, it verifies
                     95:   the state of the request and, if it's an asynchronous request, deletes
                     96:   the memory allocated to it.
1.10      cvs        97:   -------------------------------------------------------------------*/
1.37      cvs        98: #ifndef _WINDOWS
1.4       cvs        99: #ifdef __STDC__
1.12      cvs       100: void *AHTCallback_bridge (caddr_t cd, int *s, XtInputId * id)
1.26      cvs       101: #else  /* __STDC__ */
1.12      cvs       102: void *AHTCallback_bridge (cd, s, id)
1.7       cvs       103: caddr_t             cd;
                    104: int                *s;
                    105: XtInputId          *id;
1.4       cvs       106: #endif /* __STDC__ */
                    107: {
1.11      cvs       108:    int                 status;  /* the status result of the libwwww call */
1.58      cvs       109:    HTEventType         type  = HTEvent_ALL;    
1.38      cvs       110:    int                 v;
1.40      cvs       111:    int                        socket = *s;
1.58      cvs       112:    ms_t                now = HTGetTimeInMillis();
                    113:    
                    114:    v = HASH (socket);
1.4       cvs       115: 
1.58      cvs       116:    /* convert the FD into an HTEventType which will allow us to find the
                    117:       request associated with the socket */
1.47      cvs       118: 
1.58      cvs       119:    /* I could send some other data here, like the event itself, right */
                    120:    switch ((XtInputId) cd) 
1.47      cvs       121:      {
1.58      cvs       122:      case XtInputReadMask:
                    123:        type = HTEvent_READ;
                    124:        break;
                    125:      case XtInputWriteMask:
                    126:        type = HTEvent_WRITE;
                    127:        break;
                    128:      case XtInputExceptMask:
                    129:        type = HTEvent_OOB;
                    130:        break;
                    131:      default:
                    132:        type = HTEvent_ALL; 
                    133:        break;
                    134:      } /* switch */
1.47      cvs       135:    
1.32      cvs       136:    /* Invokes the callback associated to the requests */
                    137:    
1.64    ! cvs       138:    CanDoStop_set (FALSE);
1.58      cvs       139:    if ((status = HTEventList_dispatch (socket, type, now)) != HT_OK)
                    140:      {
1.36      cvs       141: #ifdef DEBUG_LIBWWW
1.58      cvs       142:      HTTrace ("Callback.... returned a value != HT_OK");
1.36      cvs       143: #endif
1.58      cvs       144:      }
1.41      cvs       145: 
1.64    ! cvs       146:    CanDoStop_set (TRUE);
1.38      cvs       147: 
1.7       cvs       148:    return (0);
1.4       cvs       149: }
1.37      cvs       150: #endif /* !_WINDOWS */
1.41      cvs       151: 
                    152: /*--------------------------------------------------------------------
                    153:   ProcessTerminateRequest
                    154:   This function is called whenever a request has ended. If the requested
                    155:   ended normally, the function will call any callback associated to the
                    156:   request. Otherwise, it will just mark the request as over.
                    157:   -------------------------------------------------------------------*/
                    158: #ifdef __STDC__
1.56      cvs       159: void  ProcessTerminateRequest (HTRequest * request, HTResponse * response, void *param, int status)
1.41      cvs       160: #else
1.56      cvs       161: void ProcessTerminateRequest (request, response, param, status)
1.58      cvs       162: HTRequest *request;
                    163: HTResponse *response;
                    164: void *param;
                    165: int status;
1.41      cvs       166: #endif
                    167: {   
1.58      cvs       168:   AHTReqContext *me = HTRequest_context (request);
1.56      cvs       169: 
1.58      cvs       170:   /* choose a correct treatment in function of the request's
1.41      cvs       171:      being associated with an error, with an interruption, or with a
                    172:      succesful completion */
1.64    ! cvs       173: 
        !           174: #ifdef DEBUG_LIBWWW  
        !           175:   if (THD_TRACE)
        !           176:     fprintf (stderr,"ProcessTerminateRequest: processing req %p, url %s, status %d\n", me, me->urlName, me->reqStatus);  
        !           177: #endif /* DEBUG_LIBWWW */
1.41      cvs       178:   if (me->reqStatus == HT_END)
                    179:     {
1.58      cvs       180:       if (AmayaIsAlive ()  && me->terminate_cbf)
1.49      cvs       181:        (*me->terminate_cbf) (me->docid, 0, me->urlName, me->outputfile,
                    182:                              me->content_type, me->context_tcbf);
1.58      cvs       183: 
1.41      cvs       184:     }
1.42      cvs       185:   else if (me->reqStatus == HT_ABORT)
1.41      cvs       186:     /* either the application ended or the user pressed the stop 
                    187:        button. We erase the incoming file, if it exists */
                    188:     {
1.52      cvs       189:       if (AmayaIsAlive () && me->terminate_cbf)
                    190:        (*me->terminate_cbf) (me->docid, -1, me->urlName, me->outputfile,
                    191:                              me->content_type, me->context_tcbf);
1.41      cvs       192:       if (me->outputfile && me->outputfile[0] != EOS)
                    193:        {
                    194:          TtaFileUnlink (me->outputfile);
                    195:          me->outputfile[0] = EOS;
                    196:        }
                    197:     }
                    198:   else if (me->reqStatus == HT_ERR)
                    199:     {
                    200:       /* there was an error */
1.58      cvs       201:       if (AmayaIsAlive && me->terminate_cbf)
1.49      cvs       202:        (*me->terminate_cbf) (me->docid, -1, me->urlName, me->outputfile,
                    203:                              me->content_type, me->context_tcbf);
1.41      cvs       204:       
                    205:       if (me->outputfile && me->outputfile[0] != EOS)
                    206:        {
                    207:          TtaFileUnlink (me->outputfile);
                    208:          me->outputfile[0] = EOS;
                    209:        }
                    210:     }
1.58      cvs       211: 
1.41      cvs       212:    /* we erase the context if we're dealing with an asynchronous request */
1.61      cvs       213:   if ((me->mode & AMAYA_ASYNC)
                    214:       || (me->mode & AMAYA_IASYNC))
1.58      cvs       215:     {
1.63      cvs       216:       Document doc = me->docid;
1.58      cvs       217:       me->reqStatus = HT_END;
                    218:       /*** @@@ do we need this? yes!! **/
                    219:       AHTLoadTerminate_handler (request, response, param, status);
                    220:       AHTReqContext_delete (me);
1.63      cvs       221:       AHTPrintPendingRequestStatus (doc, YES);
1.58      cvs       222:     }
                    223: }
1.4       cvs       224: 
1.32      cvs       225: #ifdef _WINDOWS
1.29      cvs       226: /*----------------------------------------------------------------
1.32      cvs       227:   WIN_Activate_Request
1.29      cvs       228:   when there are more open requests than available sockets, the 
                    229:   requests are put in a "pending state." When a socket becomes
                    230:   available, libwww associates it with a pending request and then
                    231:   calls this callback function. This function is responsible for
                    232:   opening the temporary file where the GET and POST  results
                    233:   will be stored. The function is also responsible for 
                    234:   registering the socket with the Xt event loop.
                    235:   Consult the libwww manual for more details on the signature
                    236:   of this function.
                    237:   ----------------------------------------------------------------*/
                    238: #ifdef __STDC__
1.32      cvs       239: int                 WIN_Activate_Request (HTRequest * request, HTAlertOpcode op, int msgnum, const char *dfault, void *input, HTAlertPar * reply)
1.29      cvs       240: #else
1.32      cvs       241: int                 WIN_Activate_Request (request, op, msgnum, dfault, input, reply)
1.29      cvs       242: HTRequest          *request;
                    243: HTAlertOpcode       op;
                    244: int                 msgnum;
                    245: const char         *dfault;
                    246: void               *input;
                    247: HTAlertPar         *reply;
                    248: 
                    249: #endif /* __STDC__ */
                    250: {
                    251:    AHTReqContext      *me = HTRequest_context (request);
                    252: 
1.58      cvs       253:    if (me->reqStatus == HT_NEW) 
                    254:      {
                    255:        if (!(me->output)
                    256:           && (me->output != stdout) 
                    257:           && me->outputfile
                    258:           &&  (me->output = fopen (me->outputfile, "wb")) == NULL) {
                    259:         /* the request is associated with a file */
                    260:         me->outputfile[0] = EOS;       /* file could not be opened */
                    261:         TtaSetStatus (me->docid, 1, 
                    262:                       TtaGetMessage (AMAYA, AM_CANNOT_CREATE_FILE),
                    263:                       me->outputfile);
                    264:         me->reqStatus = HT_ERR;
                    265: 
                    266:         if (me->error_html)
                    267:           DocNetworkStatus[me->docid] |= AMAYA_NET_ERROR; /* so we can show the error message */
                    268:        } 
                    269:        else
                    270:         {
                    271: #ifdef DEBUG_LIBWWW
                    272:           if (THD_TRACE)
                    273:             fprintf (stderr, "WIN_Activate_Request: Activating pending %s. "
                    274:                      "Open fd %d\n", me->urlName, (int) me->output);
                    275: #endif /* DEBUG_LIBWWW */
                    276:           HTRequest_setOutputStream (me->request, AHTFWriter_new (me->request, me->output, YES));    
                    277:           /*change the status of the request */
                    278:           me->reqStatus = HT_WAITING;
                    279:         }
                    280:      } 
                    281:    else if (me->reqStatus == HT_WAITING)
                    282:      {
                    283:        /*change the status of the request */
                    284:        rewind (me->output);
                    285:        if (HTRequest_outputStream (me->request) == NULL)
                    286:         HTRequest_setOutputStream (me->request, AHTFWriter_new (me->request, me->output, YES));
                    287:      } 
1.32      cvs       288:    else {
1.36      cvs       289:      me->reqStatus = HT_ERR;
1.32      cvs       290:    }
                    291:    
1.36      cvs       292:    return ((me->reqStatus != HT_ERR) ? HT_OK : HT_ERROR);
1.32      cvs       293: }
                    294: 
1.60      cvs       295: #endif /* WINDOWS but should be an else */
                    296: /* #else  */ /* _WINDOWS */
                    297: 
                    298: #ifndef _WINDOWS
1.32      cvs       299: 
1.11      cvs       300: /*----------------------------------------------------------------------
                    301:   AHTEvent_register
                    302:   callback called by libwww whenever a socket is open and associated
                    303:   to a request. It sets the pertinent Xt events so that the Xt Event
                    304:   loops gets an interruption whenever there's action of the socket. 
                    305:   In addition, it registers the request with libwww.
                    306:   ----------------------------------------------------------------------*/
1.4       cvs       307: #ifdef __STDC__
1.58      cvs       308: int AHTEvent_register (SOCKET sock, HTEventType type, HTEvent *event)
1.4       cvs       309: #else
1.58      cvs       310: int AHTEvent_register (sock, type, event)
                    311: SOCKET sock;
                    312: HTEventType type;
                    313: HTEvent *event;
1.7       cvs       314: #endif /* __STDC__ */
1.4       cvs       315: {
1.58      cvs       316:   int  status;
1.7       cvs       317: 
1.40      cvs       318:   if (sock == INVSOC)
                    319:     {
1.36      cvs       320: #ifdef DEBUG_LIBWWW
1.58      cvs       321:       fprintf(stderr, "AHTEvent_register: sock = INVSOC\n");
1.37      cvs       322: #endif /* DEBUG_LIBWWW */
1.58      cvs       323:       return (0);
                    324:     }
1.43      cvs       325: 
1.33      cvs       326: #ifndef _WINDOWS
1.58      cvs       327:        /* need something special for HTEvent_CLOSE */
                    328:   if (type & ReadBits)
                    329:     RequestRegisterReadXtevent (sock);
                    330:   
                    331:   if (type & WriteBits)
                    332:     RequestRegisterWriteXtevent (sock);
                    333:   
                    334:   if (type & ExceptBits)
                    335:     RequestRegisterExceptXtevent (sock);
1.33      cvs       336: #endif  /* !_WINDOWS */
1.58      cvs       337:   
1.51      cvs       338: #ifdef _WINDOWS   
1.50      cvs       339:   /* under windows, libwww requires an explicit FD_CLOSE registration 
1.58      cvs       340:      to detect HTTP responses not having a Content-Length header */
                    341:   status = HTEventList_register (sock, type | HTEvent_CLOSE , event);
1.50      cvs       342: #else
1.58      cvs       343:   status = HTEventList_register (sock, type, event);
1.51      cvs       344: #endif /* _WINDOWS */
1.58      cvs       345:   
                    346:   return (status);
                    347: }
1.50      cvs       348: 
1.58      cvs       349: #endif /* _WINDOWS */
1.34      cvs       350: 
                    351: /*----------------------------------------------------------------------
                    352:   AHTEvent_unregister
                    353:   callback called by libwww each time a request is unregistered. This
                    354:   function takes care of unregistering the pertinent Xt events
                    355:   associated with the request's socket. In addition, it unregisters
                    356:   the request from libwww.
                    357:   ----------------------------------------------------------------------*/
                    358: #ifdef __STDC__
1.58      cvs       359: int AHTEvent_unregister (SOCKET sock, HTEventType type)
1.34      cvs       360: #else
1.58      cvs       361: int AHTEvent_unregister (sock, type)
1.34      cvs       362: SOCKET              sock;
1.58      cvs       363: HTEventType         type;
1.34      cvs       364: 
                    365: #endif /* __STDC__ */
                    366: {
1.58      cvs       367:   int    status;
1.38      cvs       368: 
                    369: #ifndef _WINDOWS   
1.58      cvs       370:    /* remove the Xt event hooks */
                    371:    if (type & ReadBits) 
                    372:      RequestKillReadXtevent (sock);
                    373:    
                    374:    if (type & WriteBits)
                    375:      RequestKillWriteXtevent (sock);
                    376:    
                    377:    if (type & ExceptBits) 
                    378:      RequestKillExceptXtevent (sock);
1.36      cvs       379: #endif /* !_WINDOWS */
1.35      cvs       380: 
1.58      cvs       381:    /* @@@ if this is the default for windows, no need to have AHTEvent_..
                    382:       in windows!! */
1.35      cvs       383: 
1.58      cvs       384:    /* call libwww's default routine */
                    385:    status = HTEventList_unregister (sock, type);
                    386:    
1.7       cvs       387:    return (status);
1.4       cvs       388: }
1.35      cvs       389: 
                    390: #ifndef _WINDOWS
1.4       cvs       391: 
1.58      cvs       392: /* Private functions */
                    393: 
1.11      cvs       394: /*----------------------------------------------------------------------
                    395:   RequestKillAllXtevents
                    396:   front-end for kill all Xt events associated with the request pointed
                    397:   to by "me".
                    398:   ----------------------------------------------------------------------*/
1.4       cvs       399: #ifdef __STDC__
1.7       cvs       400: void                RequestKillAllXtevents (AHTReqContext * me)
1.4       cvs       401: #else
1.7       cvs       402: void                RequestKillAllXtevents (me)
                    403: AHTReqContext      *me;
                    404: #endif /* __STDC__ */
1.4       cvs       405: {
1.58      cvs       406:   int sock = INVSOC;
                    407: 
                    408:   return;
                    409: 
                    410:   /* @@@ what to do with this one? @@@ */
                    411:   if (me->read_sock != INVSOC)
                    412:     sock = me->read_sock;
                    413:   else
                    414:     if (me->write_sock != INVSOC)
                    415:           sock = me->write_sock;
                    416:   else
                    417:     if (me->except_sock != INVSOC)
                    418:           sock = me->except_sock;
                    419: 
                    420: #ifdef DEBUG_LIBWWW
1.7       cvs       421:    if (THD_TRACE)
1.58      cvs       422:       fprintf (stderr, "RequestKillAllXtEvents: Clearing XtInputs\n");
                    423: #endif /* DEBUG_LIBWWW */
1.4       cvs       424: 
1.58      cvs       425: 
                    426:    RequestKillReadXtevent (sock);
                    427:    RequestKillWriteXtevent (sock);
                    428:    RequestKillExceptXtevent (sock);
1.4       cvs       429: }
                    430: 
1.11      cvs       431: /*----------------------------------------------------------------------
1.18      cvs       432:   RequestRegisterReadXtevent
                    433:   Registers with Xt the read events associated with socket sock
                    434:   ----------------------------------------------------------------------*/
                    435: #ifdef __STDC__
1.58      cvs       436: static void         RequestRegisterReadXtevent (SOCKET sock)
1.18      cvs       437: #else
1.58      cvs       438: static void         RequestRegisterReadXtevent (sock)
1.18      cvs       439: SOCKET sock;
                    440: #endif /* __STDC__ */
                    441: {
1.58      cvs       442:   int v;
                    443: 
                    444:   v = HASH (sock);
                    445: 
                    446:   if (!persSockets[v].read)
1.18      cvs       447:     {
1.58      cvs       448:       persSockets[v].read  =
                    449:        XtAppAddInput (app_cont,
                    450:                       sock,
                    451:                       (XtPointer) XtInputReadMask,
                    452:                       (XtInputCallbackProc) AHTCallback_bridge,
                    453:                       (XtPointer) XtInputReadMask);
                    454:       
                    455: #ifdef DEBUG_LIBWWW
1.18      cvs       456:       if (THD_TRACE)
1.58      cvs       457:        fprintf (stderr, "RegisterReadXtEvent: adding XtInput %lu Socket %d\n",
                    458:                 persSockets[v].read, sock);
                    459: #endif /* DEBUG_LIBWWW */
1.18      cvs       460:     }
                    461: 
                    462: }
                    463: 
                    464: /*----------------------------------------------------------------------
1.11      cvs       465:   RequestKillReadXtevent
                    466:   kills any read Xt event associated with the request pointed to by "me".
                    467:   ----------------------------------------------------------------------*/
1.4       cvs       468: #ifdef __STDC__
1.58      cvs       469: static void         RequestKillReadXtevent (SOCKET sock)
1.4       cvs       470: #else
1.58      cvs       471: static void         RequestKillReadXtevent (sock)
                    472: SOCKET              sock;
1.7       cvs       473: #endif /* __STDC__ */
1.4       cvs       474: {
1.58      cvs       475:   int v;
                    476: 
                    477:   v = HASH (sock);
                    478: 
                    479:   if (persSockets[v].read)
                    480:     {
                    481: #ifdef DEBUG_LIBWWW
                    482:       if (THD_TRACE)
                    483:        fprintf (stderr, "UnregisterReadXtEvent: Clearing XtInput %lu\n",
                    484:                 persSockets[v].read);
                    485: #endif /* DEBUG_LIBWWW */
                    486:       XtRemoveInput (persSockets[v].read);
                    487:       persSockets[v].read = (XtInputId) NULL;
                    488:     }
1.18      cvs       489: }
                    490: 
                    491: /*----------------------------------------------------------------------
                    492:   RequestRegisterWriteXtevent
                    493:   Registers with Xt the write events associated with socket sock
                    494:   ----------------------------------------------------------------------*/
                    495: #ifdef __STDC__
1.58      cvs       496: static void         RequestRegisterWriteXtevent (SOCKET sock)
1.18      cvs       497: #else
1.58      cvs       498: static void         RequestRegisterWriteXtevent (sock)
1.18      cvs       499: SOCKET              sock;
                    500: 
                    501: #endif /* __STDC__ */
                    502: {
1.58      cvs       503:   int v;
                    504:   v = HASH (sock);
1.18      cvs       505: 
1.58      cvs       506:   if (!persSockets[v].write)
                    507:     {   
                    508:       persSockets[v].write =
                    509:        XtAppAddInput (app_cont,
                    510:                       sock,
1.18      cvs       511:                   (XtPointer) XtInputWriteMask,
                    512:                   (XtInputCallbackProc) AHTCallback_bridge,
                    513:                   (XtPointer) XtInputWriteMask);
1.58      cvs       514: #ifdef DEBUG_LIBWWW   
1.18      cvs       515:   if (THD_TRACE)
1.58      cvs       516:     fprintf (stderr, "RegisterWriteXtEvent: Adding XtInput %lu Socket %d\n",
                    517:             persSockets[v].write, sock);
                    518: #endif /* DEBUG_LIBWWW */
                    519:   
                    520:     }
1.4       cvs       521: }
                    522: 
1.11      cvs       523: /*----------------------------------------------------------------------
                    524:   RequestKillWriteXtevent
                    525:   kills any write Xt event associated with the request pointed to
                    526:   by "me".
                    527:   ----------------------------------------------------------------------*/
1.4       cvs       528: #ifdef __STDC__
1.58      cvs       529: static void         RequestKillWriteXtevent (SOCKET sock)
1.4       cvs       530: #else
1.58      cvs       531: static void         RequestKillWriteXtevent (sock)
                    532: SOCKET sock;
1.7       cvs       533: #endif /* __STDC__ */
1.4       cvs       534: {
1.58      cvs       535:   int v;
                    536: 
                    537:   v = HASH (sock);
                    538: 
                    539:   if (persSockets[v].write)
                    540:     {
                    541: #ifdef DEBUG_LIBWWW   
                    542:       if (THD_TRACE)
                    543:        fprintf (stderr, "UnRegisterWriteXtEvent: Clearing Write XtInputs "
                    544:                 "%lu\n",
                    545:                 persSockets[v].write);
                    546: #endif /* DEBUG_LIBWWW */
                    547:       XtRemoveInput (persSockets[v].write);
                    548:       persSockets[v].write =  (XtInputId) NULL;
                    549:     }
1.18      cvs       550: }
                    551: 
                    552: /*----------------------------------------------------------------------
                    553:   RequestRegisterExceptXtevent
                    554:   Registers with Xt the except events associated with socket sock
                    555:   ----------------------------------------------------------------------*/
                    556: #ifdef __STDC__
1.58      cvs       557: static void         RequestRegisterExceptXtevent (SOCKET sock)
1.18      cvs       558: #else
1.58      cvs       559: static void         RequestRegisterExceptXtevent (sock)
1.18      cvs       560: SOCKET              sock;
                    561: 
                    562: #endif /* __STDC__ */
                    563: {
1.58      cvs       564:   int v;
                    565: 
                    566:   v = HASH (sock);
                    567: 
                    568:    if (!persSockets[v].except)
1.18      cvs       569:      {
1.58      cvs       570:    
                    571:        persSockets[v].except =
                    572:         XtAppAddInput (app_cont,
                    573:                        sock,
                    574:                        (XtPointer) XtInputExceptMask,
                    575:                        (XtInputCallbackProc) AHTCallback_bridge,
                    576:                        (XtPointer) XtInputExceptMask);
                    577: #ifdef DEBUG_LIBWWW      
                    578:    if (THD_TRACE)
                    579:      fprintf (stderr, "RegisterExceptXtEvent: adding XtInput %lu Socket %d\n",
                    580:              persSockets[v].except, sock);
                    581: #endif /* DEBUG_LIBWWW */
1.18      cvs       582:      }
1.4       cvs       583: }
                    584: 
1.11      cvs       585: /*----------------------------------------------------------------------
                    586:   RequestKillExceptXtevent
                    587:   kills any exception Xt event associated with the request pointed to
                    588:   by "me".
                    589:   ----------------------------------------------------------------------*/
1.4       cvs       590: #ifdef __STDC__
1.58      cvs       591: static void         RequestKillExceptXtevent (SOCKET sock)
1.4       cvs       592: #else
1.58      cvs       593: static void         RequestKillExceptXtevent (sock)
                    594: SOCKET sock;
1.7       cvs       595: #endif /* __STDC__ */
1.4       cvs       596: {
1.58      cvs       597:   int v;
                    598: 
                    599:   v = HASH (sock);
                    600:   if (persSockets[v].except)
                    601:     {
                    602: #ifdef DEBUG_LIBWWW   
                    603:       if (THD_TRACE)
                    604:        fprintf (stderr, "UnregisterExceptXtEvent: Clearing Except XtInputs "
                    605:                 "%lu\n", persSockets[v].except);
                    606: #endif /* DEBUG_LIBWWW */
                    607:       XtRemoveInput (persSockets[v].except);
                    608:       persSockets[v].except = (XtInputId) NULL;
                    609:     }
                    610: }
                    611: 
                    612: /*----------------------------------------------------------------------
                    613:   Xt Timer functions 
                    614:   ----------------------------------------------------------------------*/
                    615: 
                    616: struct _HTTimer {
                    617:     ms_t        millis;         /* Relative value in millis */
                    618:     ms_t        expires;        /* Absolute value in millis */
                    619:     BOOL        relative;
                    620:     BOOL        repetitive;
                    621:     void *      param;          /* Client supplied context */
                    622:     HTTimerCallback * cbf;
                    623: };
                    624: 
                    625: struct _AmayaTimer {
                    626:   HTTimer *libwww_timer;
                    627:   XtIntervalId xt_timer;
                    628: };
                    629: 
                    630: typedef struct _AmayaTimer AmayaTimer;
                    631: 
                    632: static HTList *Timers = NULL;
                    633: 
                    634: /*----------------------------------------------------------------------
                    635:   ----------------------------------------------------------------------*/
                    636: void *TimerCallback (XtPointer cdata, XtIntervalId *id)
                    637: {
                    638:   HTList *cur, *last;
                    639:   AmayaTimer *me;
                    640:   HTTimer *libwww_timer;
                    641: 
                    642:   if (!AmayaIsAlive () 
                    643:       || Timers == NULL)
                    644:     return (0);
                    645: 
                    646:   /* find the timer from the uid */
                    647:   last = cur = Timers;
                    648:   while ((me = (AmayaTimer * ) HTList_nextObject (cur)))
                    649:     {
                    650:       if (me->xt_timer == *id)
                    651:        break;
                    652:       last = cur;
                    653:     }
                    654: 
                    655:   if (me)
                    656:     {
                    657:       libwww_timer = me->libwww_timer;
                    658:       /* remove the element from the list @@@ can be optimized later */
                    659:       HTList_quickRemoveElement(cur, last);
                    660:       TtaFreeMemory (me);
                    661:       HTTimer_dispatch (libwww_timer);
                    662:     }
                    663: 
                    664:   return (0);
                    665: }
                    666: 
                    667: /*----------------------------------------------------------------------
1.59      cvs       668:   KillAllTimers
1.58      cvs       669:   ----------------------------------------------------------------------*/
1.59      cvs       670: #ifdef __STDC__
                    671: void KillAllTimers (void)
                    672: #else
1.58      cvs       673: void KillAllTimers ()
1.59      cvs       674: #endif /* __STDC__ */
1.58      cvs       675: {
                    676:   /* @@@ maybe add something else to kill the Xt things */
                    677:   if (Timers)
                    678:     HTList_delete (Timers);
                    679: 
                    680: }
                    681: 
                    682: /*----------------------------------------------------------------------
1.59      cvs       683:  AMAYA_SetTimer
                    684:  ----------------------------------------------------------------------*/
                    685: #ifdef __STDC__
                    686: void AMAYA_SetTimer (HTTimer *libwww_timer)
                    687: #else
                    688: void AMAYA_SetTimer (libwww_timer)
                    689: HTTimer *libwww_timer;
                    690: #endif /* __STDC__ */
1.58      cvs       691: {
                    692:   HTList *cur, *last;
                    693:   AmayaTimer *me;
                    694: 
                    695:   if (!AmayaIsAlive 
                    696:       || libwww_timer == NULL
                    697:       || libwww_timer->expires == 0)
                    698:     return;
                    699: 
                    700:   if (Timers == NULL)
                    701:     Timers = HTList_new ();
                    702: 
                    703:   /* see if this timer existed already */
                    704:   last = cur = Timers;
                    705:   while ((me = (AmayaTimer * ) HTList_nextObject (cur)))
                    706:     {
                    707:       if (me->libwww_timer == libwww_timer)
                    708:        break;
                    709:       last = cur;
                    710:     }
                    711: 
                    712:   if (me)
                    713:     {
                    714:     /* remove the old timer */
                    715:       if (me->xt_timer) 
                    716:        {
                    717:          XtRemoveTimeOut (me->xt_timer);
1.59      cvs       718:          me->xt_timer = (XtIntervalId) NULL;
1.58      cvs       719:        }
                    720:     }
                    721:   else
                    722:     {
                    723:       /* create a new element */
                    724:       me = TtaGetMemory (sizeof (AmayaTimer));
                    725:       /* and add it to the list */
                    726:       HTList_addObject(last, (void *) me);
                    727:       me->libwww_timer = libwww_timer;
                    728:     }
                    729: 
                    730:   /* add a new time out */
                    731:   me->xt_timer = XtAppAddTimeOut (app_cont,
                    732:                                 me->libwww_timer->millis,
                    733:                                 (XtTimerCallbackProc) TimerCallback,
                    734:                                 (XtPointer *) (void *) me);
                    735: 
                    736: }
                    737: 
                    738: /*----------------------------------------------------------------------
1.59      cvs       739:   AMAYA_DeleteTimer
1.58      cvs       740:   ----------------------------------------------------------------------*/
1.59      cvs       741: #ifdef __STDC__
                    742: void AMAYA_DeleteTimer (HTTimer *libwww_timer)
                    743: #else
                    744: void AMAYA_DeleteTimer (libwww_timer)
                    745: HTTimer *libwww_timer;
                    746: #endif /* __STDC__ */
1.58      cvs       747: {
                    748:   HTList *cur, *last;
                    749:   AmayaTimer *me;
                    750: 
1.59      cvs       751:   if (Timers == NULL || libwww_timer == NULL)
1.58      cvs       752:     return;
                    753: 
                    754:   /* find the id */
                    755:   last = cur = Timers;
                    756:   while ((me = (AmayaTimer * ) HTList_nextObject (cur)))
                    757:     {
1.59      cvs       758:       if (me->libwww_timer == libwww_timer)
1.58      cvs       759:        break;
                    760:       last = cur;
                    761:     }
                    762: 
                    763:   if (me)
                    764:     {
                    765:       /* remove the Xt timer */
                    766:       XtRemoveTimeOut (me->xt_timer);
                    767:       /* and the element from the list */
                    768:       HTList_quickRemoveElement(cur, last);
                    769:       TtaFreeMemory (me);
                    770:     }
1.31      cvs       771: }
1.58      cvs       772: 
1.32      cvs       773: #endif /* !_WINDOWS */
1.31      cvs       774: 
1.23      cvs       775: #endif /* !AMAYA_JAVA */
1.58      cvs       776: 
                    777: 
                    778: 
                    779: 
                    780: 
1.11      cvs       781: 

Webmaster