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