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