Return to query.c CVS log | Up to [Public] / Amaya / amaya |
1.14 cvs 1: /* 2: * 3: * (c) COPYRIGHT MIT and INRIA, 1996. 4: * Please first read the full copyright statement in file COPYRIGHT. 5: * 6: */ 1.4 cvs 7: 1.19 cvs 8: /* 9: * query.c : contains all the functions for requesting iand publishing 10: * URLs via libwww. It handles any eventual HTTP error code 11: * (redirection, authentication needed, not found, etc.) 12: * 1.69 cvs 13: * Author: J. Kahan 1.75 cvs 14: * R. Guetari/J. Kahan Windows 95/NT routines 1.19 cvs 15: */ 1.17 cvs 16: 1.44 cvs 17: #ifndef AMAYA_JAVA 18: 1.12 cvs 19: /* Amaya includes */ 1.25 cvs 20: #define THOT_EXPORT extern 1.4 cvs 21: #include "amaya.h" 1.70 cvs 22: #ifdef _WINDOWS 23: #include <fcntl.h> 24: #endif /* _WINDOWS */ 1.7 cvs 25: 1.4 cvs 26: #if defined(__svr4__) 27: #define CATCH_SIG 28: #endif 29: 30: /* local structures coming from libwww and which are 1.17 cvs 31: not found in any .h file 1.7 cvs 32: */ 1.68 cvs 33: 1.7 cvs 34: struct _HTStream 35: { 1.15 cvs 36: const HTStreamClass *isa; 37: FILE *fp; 1.45 cvs 38: BOOL leave_open; /* Close file when TtaFreeMemory? */ 1.15 cvs 39: char *end_command; /* Command to execute */ 40: BOOL remove_on_close; /* Remove file? */ 41: char *filename; /* Name of file */ 42: HTRequest *request; /* saved for callback */ 43: HTRequestCallback *callback; 1.7 cvs 44: }; 45: 1.15 cvs 46: 1.7 cvs 47: struct _HTError 48: { 49: HTErrorElement element; /* Index number into HTError */ 50: HTSeverity severity; /* A la VMS */ 51: BOOL ignore; /* YES if msg should not go to user */ 52: void *par; /* Explanation, e.g. filename */ 53: int length; /* For copying by generic routine */ 54: char *where; /* Which function */ 55: }; 56: 57: 58: struct _HTHost 59: { 60: char *hostname; /* name of host + optional port */ 61: time_t ntime; /* Creation time */ 62: char *type; /* Peer type */ 63: int version; /* Peer version */ 64: HTMethod methods; /* Public methods (bit-flag) */ 65: char *server; /* Server name */ 66: char *user_agent; /* User Agent */ 67: char *range_units; /* Acceptable range units */ 68: HTTransportMode mode; /* Supported mode */ 69: HTChannel *channel; /* Persistent channel */ 70: HTList *pipeline; /* Pipe line of net objects */ 71: HTList *pending; /* List of pending Net objects */ 72: time_t expires; /* Persistent channel expires time */ 73: }; 1.4 cvs 74: 75: /* Type definitions and global variables etc. local to this module */ 76: 1.17 cvs 77: /*----------------------------------------------------------------------*/ 78: 1.4 cvs 79: /*** private variables ***/ 1.17 cvs 80: 1.4 cvs 81: static HTList *converters = NULL; /* List of global converters */ 1.27 cvs 82: static HTList *acceptTypes = NULL; /* List of types for the Accept header */ 1.4 cvs 83: static HTList *encodings = NULL; 1.16 cvs 84: static int object_counter = 0; /* loaded objects counter */ 1.24 cvs 85: static boolean AmayaIsAlive; 1.4 cvs 86: 1.15 cvs 87: #include "answer_f.h" 88: #include "query_f.h" 89: #include "AHTURLTools_f.h" 90: #include "AHTBridge_f.h" 91: #include "AHTMemConv_f.h" 92: #include "AHTFWrite_f.h" 1.4 cvs 93: 1.70 cvs 94: #ifdef _WINDOWS 95: #ifdef __STDC__ 96: int WIN_Activate_Request (HTRequest* , HTAlertOpcode, int, const char*, void*, HTAlertPar*); 97: #else 98: int WIN_Activate_Request (); 99: #endif /* __STDC__ */ 100: #endif /* _WINDOWS */ 1.15 cvs 101: 102: /*---------------------------------------------------------------------- 1.17 cvs 103: GetDocIdStatus 104: gets the status associated to a docid 1.15 cvs 105: ----------------------------------------------------------------------*/ 106: #ifdef __STDC__ 107: AHTDocId_Status *GetDocIdStatus (int docid, HTList * documents) 108: #else 109: AHTDocID_Status *GetDocIdStatus (docid, documents) 110: int docid; 111: HTList *documents; 112: 113: #endif 114: { 115: AHTDocId_Status *me; 116: HTList *cur; 117: 118: if (documents) 119: { 120: cur = documents; 121: 122: while ((me = (AHTDocId_Status *) HTList_nextObject (cur))) 123: { 124: if (me->docid == docid) 125: return (me); 1.18 cvs 126: } 127: } 1.15 cvs 128: return (AHTDocId_Status *) NULL; 129: 130: } 131: 1.5 cvs 132: /*---------------------------------------------------------------------- 1.27 cvs 133: AHTGuessAtom_for 134: Converts an Amaya type descriptor into the equivalent MIME type. 135: ----------------------------------------------------------------------*/ 136: #ifdef __STDC__ 137: static HTAtom *AHTGuessAtom_for (char *urlName, PicType contentType) 138: #else 139: static HTAtom *AHTGuessAtom_for (urlName, contentType) 140: char *urlName; 141: PicType contentType; 142: #endif 143: { 144: HTAtom *atom; 145: char *filename; 146: HTEncoding enc; 147: HTEncoding cte; 148: HTLanguage lang; 1.50 cvs 149: double quality = 1.0; 1.27 cvs 150: 151: switch (contentType) 152: { 153: case xbm_type: 154: atom = HTAtom_for("image/xbm"); 155: break; 156: case eps_type: 1.35 cvs 157: atom = HTAtom_for("application/postscript"); 1.27 cvs 158: break; 159: case xpm_type: 160: atom = HTAtom_for("image/xpm"); 161: break; 162: case gif_type: 163: atom = HTAtom_for("image/gif"); 164: break; 165: case jpeg_type: 166: atom = HTAtom_for("image/jpeg"); 167: break; 168: case png_type: 169: atom = HTAtom_for("image/png"); 170: break; 171: case unknown_type: 172: default: 173: /* 174: ** Amaya could not detect the type, so 175: ** we try to use the filename's suffix to do so. 176: */ 1.45 cvs 177: filename = AmayaParseUrl (urlName, "", AMAYA_PARSE_PATH | AMAYA_PARSE_PUNCTUATION); 1.27 cvs 178: HTBind_getFormat (filename, &atom, &enc, &cte, &lang, &quality); 1.45 cvs 179: TtaFreeMemory (filename); 1.27 cvs 180: if (atom == WWW_UNKNOWN) 181: /* 182: ** we could not identify the suffix, so we assign it 183: ** a default type 184: */ 185: atom = HTAtom_for ("text/html"); 186: break; 187: } 188: 189: return atom; 190: } 191: 192: /*---------------------------------------------------------------------- 1.17 cvs 193: AHTReqContext_new 194: create a new Amaya Context Object and update the global Amaya 195: request status. 1.5 cvs 196: ----------------------------------------------------------------------*/ 1.4 cvs 197: #ifdef __STDC__ 198: static AHTReqContext *AHTReqContext_new (int docid) 199: #else 200: static AHTReqContext *AHTReqContext_new (docid) 201: int docid; 202: 203: #endif 204: { 205: AHTReqContext *me; 206: AHTDocId_Status *docid_status; 207: 208: if ((me = (AHTReqContext *) TtaGetMemory (sizeof (AHTReqContext))) == NULL) 209: outofmem (__FILE__, "Context_new"); 210: 1.81 cvs 211: /* Bind the Context object together with the Request Object */ 212: me->request = HTRequest_new (); 213: 1.80 cvs 214: /* clean the associated file structure) */ 1.79 cvs 215: HTRequest_setOutputStream (me->request, NULL); 1.81 cvs 216: 1.4 cvs 217: /* Initialize the other members of the structure */ 1.17 cvs 218: me->reqStatus = HT_NEW; /* initial status of a request */ 1.4 cvs 219: me->output = NULL; 1.51 cvs 220: # ifndef _WINDOWS 1.4 cvs 221: me->read_xtinput_id = (XtInputId) NULL; 222: me->write_xtinput_id = (XtInputId) NULL; 223: me->except_xtinput_id = (XtInputId) NULL; 1.51 cvs 224: # endif 1.4 cvs 225: me->docid = docid; 226: HTRequest_setMethod (me->request, METHOD_GET); 227: HTRequest_setOutputFormat (me->request, WWW_SOURCE); 228: HTRequest_setContext (me->request, me); 229: me->read_ops = 0; 230: me->write_ops = 0; 231: me->except_ops = 0; 1.36 cvs 232: /* experimental */ 233: me->read_sock = INVSOC; 234: me->write_sock = INVSOC; 235: me->except_sock = INVSOC; 1.4 cvs 236: 237: /* Update the global context */ 238: HTList_appendObject (Amaya->reqlist, (void *) me); 239: 240: docid_status = GetDocIdStatus (docid, Amaya->docid_status); 241: 1.7 cvs 242: if (docid_status == NULL) 243: { 244: docid_status = (AHTDocId_Status *) TtaGetMemory (sizeof (AHTDocId_Status)); 245: docid_status->docid = docid; 246: docid_status->counter = 1; 247: HTList_addObject (Amaya->docid_status, (void *) docid_status); 248: } 249: else 1.4 cvs 250: docid_status->counter++; 251: 252: 253: Amaya->open_requests++; 254: 255: /* error stream handling */ 256: me->error_stream = (char *) NULL; 257: me->error_stream_size = 0; 1.74 cvs 258: 259: #ifdef DEBUG_LIBWWW 260: fprintf (stderr, "AHTReqContext_new: Created object %p\n", me); 261: #endif 1.4 cvs 262: return me; 1.74 cvs 263: 1.4 cvs 264: } 265: 1.5 cvs 266: /*---------------------------------------------------------------------- 1.17 cvs 267: AHTReqContext_delete 268: Delete an Amaya Context Object and update the global Amaya request 269: status. 1.5 cvs 270: ----------------------------------------------------------------------*/ 1.4 cvs 271: 272: #ifdef __STDC__ 1.15 cvs 273: boolean AHTReqContext_delete (AHTReqContext * me) 1.4 cvs 274: #else 1.15 cvs 275: boolean AHTReqContext_delete (me) 1.4 cvs 276: AHTReqContext *me; 277: 278: #endif 279: { 280: AHTDocId_Status *docid_status; 281: 1.7 cvs 282: if (me) 283: { 1.4 cvs 284: 1.74 cvs 285: #ifdef DEBUG_LIBWWW 286: fprintf (stderr, "AHTReqContext_delete: Deleting object %p\n", me); 287: #endif 288: 1.7 cvs 289: if (Amaya->reqlist) 290: HTList_removeObject (Amaya->reqlist, (void *) me); 1.4 cvs 291: 1.7 cvs 292: docid_status = GetDocIdStatus (me->docid, Amaya->docid_status); 1.4 cvs 293: 1.7 cvs 294: if (docid_status) 295: { 296: docid_status->counter--; 297: 298: if (docid_status->counter == 0) 299: { 300: HTList_removeObject (Amaya->docid_status, (void *) docid_status); 301: TtaFreeMemory ((void *) docid_status); 302: } 303: } 1.79 cvs 304: 305: if (HTRequest_outputStream (me->request)) 306: AHTFWriter_FREE (me->request->output_stream); 307: 1.7 cvs 308: HTRequest_delete (me->request); 1.79 cvs 309: 1.7 cvs 310: if (me->error_stream != (char *) NULL) 1.70 cvs 311: HT_FREE (me->error_stream); 312: # ifndef _WINDOWS 313: # ifdef WWW_XWINDOWS 1.21 cvs 314: if (me->read_xtinput_id || me->write_xtinput_id || 315: me->except_xtinput_id) 316: RequestKillAllXtevents(me); 1.70 cvs 317: # endif /* WWW_XWINDOWS */ 318: # endif /* !_WINDOWS */ 1.74 cvs 319: 320: if ((me->mode & AMAYA_ASYNC) || (me->mode & AMAYA_IASYNC)) 321: /* for the ASYNC mode, free the memory we allocated in GetObjectWWW 322: or in PutObjectWWW */ 323: { 1.79 cvs 324: if (me->urlName) 325: TtaFreeMemory (me->urlName); 326: if (me->outputfile) 327: TtaFreeMemory (me->outputfile); 1.74 cvs 328: } 329: 1.7 cvs 330: TtaFreeMemory ((void *) me); 1.4 cvs 331: 1.7 cvs 332: Amaya->open_requests--; 1.4 cvs 333: 1.15 cvs 334: return TRUE; 1.4 cvs 335: 1.7 cvs 336: } 1.15 cvs 337: return FALSE; 1.4 cvs 338: } 339: 340: 1.15 cvs 341: /*---------------------------------------------------------------------- 342: AHTUpload_callback 1.17 cvs 343: callback handler for executing the PUT command 1.15 cvs 344: ----------------------------------------------------------------------*/ 1.4 cvs 345: #ifdef __STDC__ 346: static int AHTUpload_callback (HTRequest * request, HTStream * target) 347: #else 348: static int AHTUpload_callback (request, target) 349: HTRequest *request; 350: HTStream *target; 351: 352: #endif 353: { 354: AHTReqContext *me = HTRequest_context (request); 1.7 cvs 355: HTParentAnchor *entity = HTRequest_entityAnchor (request); 356: int len = HTAnchor_length (entity); 1.4 cvs 357: int status; 358: 359: /* Send the data down the pipe */ 1.7 cvs 360: 1.4 cvs 361: status = (*target->isa->put_block) (target, me->mem_ptr, len); 362: 1.7 cvs 363: if (status == HT_LOADED || status == HT_OK) 364: { 1.13 cvs 365: if (PROT_TRACE) 366: HTTrace ("Posting Data Target is SAVED\n"); 367: (*target->isa->flush) (target); 368: return (HT_LOADED); 1.7 cvs 369: } 370: if (status == HT_WOULD_BLOCK) 371: { 372: if (PROT_TRACE) 373: HTTrace ("Posting Data Target WOULD BLOCK\n"); 1.74 cvs 374: #ifdef _WINDOWS 375: return HT_CONTINUE; 376: #else 377: return HT_WOULD_BLOCK; 378: #endif /* _WINDOWS */ 379: 1.7 cvs 380: return HT_WOULD_BLOCK; 381: } 382: else if (status == HT_PAUSE) 383: { 384: if (PROT_TRACE) 385: HTTrace ("Posting Data Target PAUSED\n"); 386: return HT_PAUSE; 387: } 388: else if (status > 0) 389: { /* Stream specific return code */ 390: if (PROT_TRACE) 391: HTTrace ("Posting Data. Target returns %d\n", status); 392: return status; 393: } 394: else 395: { /* we have a real error */ 396: if (PROT_TRACE) 397: HTTrace ("Posting Data Target ERROR %d\n", status); 398: return status; 399: } 1.4 cvs 400: } 401: 1.5 cvs 402: /*---------------------------------------------------------------------- 1.17 cvs 403: Thread_deleteAll 404: this function deletes the whole list of active threads. 1.5 cvs 405: ----------------------------------------------------------------------*/ 1.4 cvs 406: #ifdef __STDC__ 407: static void Thread_deleteAll (void) 408: #else 409: static void Thread_deleteAll () 410: #endif 411: { 1.21 cvs 412: HTList *cur; 413: AHTReqContext *me; 414: AHTDocId_Status *docid_status; 415: 1.74 cvs 416: if (Amaya && Amaya->reqlist) 417: { 418: if (Amaya->open_requests > 0) 419: #ifdef DEBUG_LIBWWW 420: fprintf (stderr, "Thread_deleteAll: Killing %d outstanding " 421: "requests\n", Amaya->open_requests); 422: #endif 423: { 424: cur = Amaya->reqlist; 425: 426: HTNet_killAll (); 427: /* erase the requests */ 428: while ((me = (AHTReqContext *) HTList_removeLastObject (cur))) 429: { 430: if (me->request) 431: { 1.70 cvs 432: # ifndef _WINDOWS 1.74 cvs 433: RequestKillAllXtevents (me); 1.70 cvs 434: # endif /* !_WINDOWS */ 1.74 cvs 435: AHTReqContext_delete (me); 436: } 437: } /* while */ 438: 439: /* erase the docid_status entities */ 440: while ((docid_status = (AHTDocId_Status *) HTList_removeLastObject ((void *) Amaya->docid_status))) 441: TtaFreeMemory ((void *) docid_status); 442: 443: } /* if */ 444: } 1.4 cvs 445: } 446: 1.5 cvs 447: /*---------------------------------------------------------------------- 1.17 cvs 448: redirection_handler 449: this function is registered to handle permanent and temporary 450: redirections. 451: ----------------------------------------------------------------------*/ 1.4 cvs 452: #ifdef __STDC__ 1.7 cvs 453: static int redirection_handler (HTRequest * request, HTResponse * response, void *param, int status) 1.4 cvs 454: #else 455: static int redirection_handler (request, context, status) 456: HTRequest *request; 457: HTResponse *response; 458: void *param; 459: int status; 460: 461: #endif 462: { 463: 464: char *ref; 465: HTAnchor *new_anchor = HTResponse_redirection (response); 1.7 cvs 466: AHTReqContext *me = HTRequest_context (request); 1.4 cvs 467: HTMethod method = HTRequest_method (request); 468: 469: 1.7 cvs 470: if (!new_anchor) 471: { 472: if (PROT_TRACE) 473: HTTrace ("Redirection. No destination\n"); 474: return HT_OK; 475: } 1.4 cvs 476: 477: /* 478: ** Only do redirect on GET and HEAD 479: */ 1.7 cvs 480: if (!HTMethod_isSafe (method)) 481: { 482: HTAlertCallback *prompt = HTAlert_find (HT_A_CONFIRM); 483: 484: if (prompt) 485: { 486: if ((*prompt) (request, HT_A_CONFIRM, HT_MSG_REDIRECTION, 487: NULL, NULL, NULL) != YES) 488: return HT_ERROR; 489: } 490: } 1.4 cvs 491: 492: /* 493: ** Start new request with the redirect anchor found in the headers. 494: ** Note that we reuse the same request object which means that we must 495: ** keep this around until the redirected request has terminated. It also 496: ** allows us in an easy way to keep track of the number of redirections 497: ** so that we can detect endless loops. 498: */ 1.17 cvs 499: 1.7 cvs 500: if (HTRequest_doRetry (request)) 501: { 502: /* do we need to normalize the URL? */ 503: if (strncmp (new_anchor->parent->address, "http:", 5)) 504: { 505: /* Yes, so we use the pre-redirection anchor as a base name */ 1.74 cvs 506: ref = AmayaParseUrl (new_anchor->parent->address, 507: me->urlName, AMAYA_PARSE_ALL); 1.7 cvs 508: if (ref) 509: { 1.74 cvs 510: TtaFreeMemory (new_anchor->parent->address); 511: new_anchor->parent->address = ref; 1.7 cvs 512: } 513: } 514: 515: /* update the current file name */ 1.21 cvs 516: if (strlen (new_anchor->parent->address) > (MAX_LENGTH - 2)) 1.7 cvs 517: { 1.74 cvs 518: strncpy (me->urlName, new_anchor->parent->address, 519: MAX_LENGTH - 1); 1.21 cvs 520: me->urlName[MAX_LENGTH - 1] = EOS; 1.7 cvs 521: } 522: else 1.74 cvs 523: strcpy (me->urlName, new_anchor->parent->address); 1.7 cvs 524: 1.38 cvs 525: ChopURL (me->status_urlName, me->urlName); 526: 1.7 cvs 527: TtaSetStatus (me->docid, 1, TtaGetMessage (AMAYA, AM_RED_FETCHING), 1.38 cvs 528: me->status_urlName); 1.7 cvs 529: 530: /* Start request with new credentials */ 1.64 cvs 531: 1.79 cvs 532: if (HTRequest_outputStream (me->request) != NULL) { 1.74 cvs 533: #ifdef DEBUG_LIBWWW 1.79 cvs 534: fprintf (stderr, "redirection_handler: New URL is %s, closing " 1.74 cvs 535: "FILE %p\n", me->urlName, me->output); 536: #endif 1.79 cvs 537: AHTFWriter_FREE (request->output_stream); 538: if (me->output != stdout) { /* Are we writing to a file? */ 539: fclose (me->output); 540: me->output = NULL; 541: } 1.64 cvs 542: } 1.68 cvs 543: 1.69 cvs 544: me->reqStatus = HT_NEW; /* reset the status */ 1.7 cvs 545: if (me->method == METHOD_PUT || me->method == METHOD_POST) /* PUT, POST etc. */ 1.74 cvs 546: status = HTLoadAbsolute (me->urlName, request); 1.7 cvs 547: else 1.74 cvs 548: HTLoadAnchor (new_anchor, request); 1.7 cvs 549: } 550: else 1.68 cvs 551: { 1.74 cvs 552: HTRequest_addError (request, ERR_FATAL, NO, HTERR_MAX_REDIRECT, 553: NULL, 0, "HTRedirectFilter"); 554: TtaSetStatus (me->docid, 1, TtaGetMessage (AMAYA, AM_REDIRECTIONS_LIMIT), 555: NULL); 556: if (me->error_html) 557: DocNetworkStatus[me->docid] |= AMAYA_NET_ERROR; 558: /* so that we can show the error message */ 1.68 cvs 559: } 560: 1.4 cvs 561: /* 1.74 cvs 562: ** By returning HT_ERROR we make sure that this is the last handler to be 563: ** called. We do this as we don't want any other filter to delete the 564: ** request object now when we have just started a new one ourselves 565: */ 1.4 cvs 566: return HT_ERROR; 567: } 568: 1.5 cvs 569: /*---------------------------------------------------------------------- 1.17 cvs 570: terminate_handler 571: this function is registered to handle the result of the request 1.5 cvs 572: ----------------------------------------------------------------------*/ 1.4 cvs 573: #if __STDC__ 1.7 cvs 574: static int terminate_handler (HTRequest * request, HTResponse * response, void *context, int status) 1.4 cvs 575: #else 576: static int terminate_handler (request, response, context, status) 577: HTRequest *request; 578: HTResponse *response; 579: void *context; 580: int status; 581: #endif 582: { 583: AHTReqContext *me = (AHTReqContext *) HTRequest_context (request); 1.13 cvs 584: boolean error_flag; 1.4 cvs 585: 586: if (!me) 1.74 cvs 587: return HT_OK; /* not an Amaya request */ 588: 1.80 cvs 589: /* if Amaya was killed, treat with this request as if it were 590: issued by a Stop button event */ 591: if (!AmayaIsAlive) 592: me->reqStatus = HT_ABORT; 1.74 cvs 593: 1.77 cvs 594: if (status == HT_LOADED || 595: status == HT_CREATED || 1.79 cvs 596: status == HT_NO_DATA || 597: me->reqStatus == HT_ABORT) 1.74 cvs 598: error_flag = FALSE; 1.13 cvs 599: else 1.74 cvs 600: error_flag = TRUE; 601: 1.4 cvs 602: /* output any errors from the server */ 1.74 cvs 603: 1.77 cvs 604: /* 1.74 cvs 605: ** me->output = output file which will receive an html file 606: ** me->error_html = yes, output HTML errors in the screen 607: ** request->error_stack == if there are any errors, they will be here 608: ** me->error_stream_size If it's != 0 means an error message has already 609: ** been written to the stack 610: */ 611: 1.4 cvs 612: /* First, we verify if there are any errors and if they are not 1.17 cvs 613: ** yet written to the error stack. If no, then let's try to write them 614: ** ourselves 615: */ 1.74 cvs 616: 617: #ifdef DEBUG_LIBWWW 618: fprintf (stderr, "terminate_handler: URL is " 619: "%s, closing FILE %p status is %d\n", me->urlName, me->output, 620: status); 1.69 cvs 621: #endif 1.74 cvs 622: 1.69 cvs 623: if (me->output && me->output != stdout) 624: { 1.74 cvs 625: /* we are writing to a file */ 626: if (me->reqStatus != HT_ABORT) 627: { /* if the request was not aborted and */ 1.80 cvs 628: if (error_flag && 629: me->error_html == TRUE) 630: /* there were some errors and we want to print them */ 631: { 632: if (me->error_stream_size == 0)/* and the stream is empty */ 633: AHTError_MemPrint (request); /* copy errors from 1.74 cvs 634: **the error stack 1.77 cvs 635: ** into the error stream */ 1.80 cvs 636: if (me->error_stream) 637: { /* if the stream is non-empty */ 638: fprintf (me->output, me->error_stream);/* output the errors */ 639: error_flag = 0; 640: 1.74 cvs 641: } 642: } /* if error_stack */ 643: } /* if != HT_ABORT */ 644: fclose (me->output); 645: me->output = NULL; 1.69 cvs 646: } 1.80 cvs 647: 1.74 cvs 648: 1.80 cvs 649: if (error_flag) 650: me->reqStatus = HT_ERR; 651: else if (me->reqStatus != HT_ABORT) 652: me->reqStatus = HT_END; 653: 654: /* don't remove or Xt will hang up during the PUT */ 655: 1.28 cvs 656: if (AmayaIsAlive && ((me->method == METHOD_POST) || 657: (me->method == METHOD_PUT))) 1.7 cvs 658: { 1.80 cvs 659: PrintTerminateStatus (me, status); 660: 661: } 662: 1.72 cvs 663: #ifdef _WINDOWS 1.80 cvs 664: /* Try to add this to AHTEventrg.c */ 665: ProcessTerminateRequest (me); 666: #endif /* WINDOWS */ 1.71 cvs 667: 668: return HT_OK; 1.4 cvs 669: } 670: 1.5 cvs 671: /*---------------------------------------------------------------------- 1.17 cvs 672: AHTLoadTerminate_handler 1.74 cvs 673: this is an application "AFTER" Callback. It's called by the library 674: when a request has ended, so that we can setup the correct status. 1.5 cvs 675: ----------------------------------------------------------------------*/ 1.4 cvs 676: 677: #ifdef __STDC__ 1.7 cvs 678: static int AHTLoadTerminate_handler (HTRequest * request, HTResponse * response, void *param, int status) 1.4 cvs 679: #else 680: static int AHTLoadTerminate_handler (request, response, param, status) 681: HTRequest *request; 682: HTResponse *response; 683: void *param; 684: int status; 1.69 cvs 685: 1.4 cvs 686: #endif 687: { 688: AHTReqContext *me = HTRequest_context (request); 689: HTAlertCallback *cbf; 690: AHTDocId_Status *docid_status; 691: 1.7 cvs 692: switch (status) 693: { 694: case HT_LOADED: 695: if (PROT_TRACE) 696: HTTrace ("Load End.... OK: `%s\' has been accessed\n", 1.38 cvs 697: me->status_urlName); 1.4 cvs 698: 1.7 cvs 699: docid_status = GetDocIdStatus (me->docid, 700: Amaya->docid_status); 701: 702: if (docid_status != NULL && docid_status->counter > 1) 1.74 cvs 703: TtaSetStatus (me->docid, 1, 704: TtaGetMessage (AMAYA, AM_ELEMENT_LOADED), 705: me->status_urlName); 1.7 cvs 706: break; 707: 708: case HT_NO_DATA: 709: if (PROT_TRACE) 1.74 cvs 710: HTTrace ("Load End.... OK BUT NO DATA: `%s\'\n", 711: me->status_urlName); 712: TtaSetStatus (me->docid, 1, 713: TtaGetMessage (AMAYA, AM_LOADED_NO_DATA), 1.38 cvs 714: me->status_urlName); 1.7 cvs 715: break; 716: 717: case HT_INTERRUPTED: 718: if (PROT_TRACE) 1.74 cvs 719: HTTrace ("Load End.... INTERRUPTED: `%s\'\n", 720: me->status_urlName); 721: TtaSetStatus (me->docid, 1, 722: TtaGetMessage (AMAYA, AM_LOAD_ABORT), 723: NULL); 1.7 cvs 724: break; 725: 726: case HT_RETRY: 727: if (PROT_TRACE) 728: HTTrace ("Load End.... NOT AVAILABLE, RETRY AT %ld\n", 729: HTResponse_retryTime (response)); 1.74 cvs 730: TtaSetStatus (me->docid, 1, 731: TtaGetMessage (AMAYA, AM_NOT_AVAILABLE_RETRY), 1.38 cvs 732: me->status_urlName); 1.7 cvs 733: break; 734: 735: case HT_ERROR: 736: 737: cbf = HTAlert_find (HT_A_MESSAGE); 738: if (cbf) 739: (*cbf) (request, HT_A_MESSAGE, HT_MSG_NULL, NULL, 740: HTRequest_error (request), NULL); 741: break; 742: 743: if (PROT_TRACE) 744: HTTrace ("Load End.... ERROR: Can't access `%s\'\n", 1.74 cvs 745: me->status_urlName ? me->status_urlName :"<UNKNOWN>"); 746: TtaSetStatus (me->docid, 1, 747: TtaGetMessage (AMAYA, AM_CANNOT_LOAD), 1.38 cvs 748: me->status_urlName ? me->status_urlName : "<UNKNOWN>"); 1.7 cvs 749: break; 750: default: 751: if (PROT_TRACE) 752: HTTrace ("Load End.... UNKNOWN RETURN CODE %d\n", status); 753: break; 754: } 755: 1.4 cvs 756: return HT_OK; 757: } 758: 1.27 cvs 759: /*---------------------------------------------------------------------- 760: AHTAcceptTypesInit 1.74 cvs 761: This function prepares the Accept header used by Amaya during 762: the HTTP content negotiation phase 1.27 cvs 763: ----------------------------------------------------------------------*/ 764: #ifdef __STDC__ 765: static void AHTAcceptTypesInit (HTList *c) 766: #else /* __STDC__ */ 767: static void AHTAcceptTypesInit (c) 768: HTList *c; 769: #endif /* __STDC__ */ 770: { 771: if (c == (HTList *) NULL) 772: return; 773: 774: /* define here all the mime types that Amaya can accept */ 775: 1.74 cvs 776: HTConversion_add (c, "image/png", "www/present", 777: HTThroughLine, 1.0, 0.0, 0.0); 778: HTConversion_add (c, "image/jpeg", "www/present", 779: HTThroughLine, 1.0, 0.0, 0.0); 780: HTConversion_add (c, "image/gif", "www/present", 781: HTThroughLine, 1.0, 0.0, 0.0); 782: HTConversion_add (c, "image/xbm", "www/present", 783: HTThroughLine, 1.0, 0.0, 0.0); 784: HTConversion_add (c, "image/xpm", "www/present", 785: HTThroughLine, 1.0, 0.0, 0.0); 786: HTConversion_add (c, "application/postscript", 787: "www/present", HTThroughLine, 1.0, 0.0, 0.0); 1.4 cvs 788: 1.27 cvs 789: /* Define here the equivalences between MIME types and file extensions for 790: the types that Amaya can display */ 791: 792: /* Register the default set of file suffix bindings */ 793: HTFileInit (); 794: 795: /* Don't do any case distinction */ 796: HTBind_caseSensitive (FALSE); 797: } 1.4 cvs 798: 1.5 cvs 799: /*---------------------------------------------------------------------- 1.17 cvs 800: AHTConverterInit 801: Bindings between a source media type and a destination media type 802: (conversion). 1.5 cvs 803: ----------------------------------------------------------------------*/ 1.15 cvs 804: #ifdef __STDC__ 805: static void AHTConverterInit (HTList *c) 806: #else /* __STDC__ */ 807: static void AHTConverterInit (c) 808: HTList *c; 809: #endif /* __STDC__ */ 1.4 cvs 810: { 811: 812: /* Handler for custom http error messages */ 1.7 cvs 813: HTConversion_add (c, "*/*", "www/debug", AHTMemConverter, 1.0, 0.0, 0.0); 1.4 cvs 814: 815: /* 816: ** These are converters that converts to something other than www/present, 817: ** that is not directly outputting someting to the user on the screen 818: */ 819: 820: HTConversion_add (c, "message/rfc822", "*/*", HTMIMEConvert, 1.0, 0.0, 0.0); 821: HTConversion_add (c, "message/x-rfc822-foot", "*/*", HTMIMEFooter, 822: 1.0, 0.0, 0.0); 823: HTConversion_add (c, "message/x-rfc822-head", "*/*", HTMIMEHeader, 824: 1.0, 0.0, 0.0); 825: HTConversion_add (c, "multipart/*", "*/*", HTBoundary, 826: 1.0, 0.0, 0.0); 827: HTConversion_add (c, "text/plain", "text/html", HTPlainToHTML, 828: 1.0, 0.0, 0.0); 829: 830: 831: /* 832: ** The following conversions are converting ASCII output from various 833: ** protocols to HTML objects. 834: */ 835: HTConversion_add (c, "text/x-http", "*/*", HTTPStatus_new, 836: 1.0, 0.0, 0.0); 837: HTConversion_add (c, "text/x-nntp-list", "*/*", HTNewsList, 838: 1.0, 0.0, 0.0); 839: HTConversion_add (c, "text/x-nntp-over", "*/*", HTNewsGroup, 840: 1.0, 0.0, 0.0); 841: 842: 843: /* 844: ** We also register a special content type guess stream that can figure out 845: ** the content type by reading the first bytes of the stream 846: */ 847: HTConversion_add (c, "www/unknown", "*/*", HTGuess_new, 848: 1.0, 0.0, 0.0); 849: 850: /* 851: ** Register a persistent cache stream which can save an object to local 852: ** file 853: */ 854: HTConversion_add (c, "www/cache", "*/*", HTCacheWriter, 855: 1.0, 0.0, 0.0); 856: 857: /* 858: ** This dumps all other formats to local disk without any further 859: ** action taken 860: */ 861: HTConversion_add (c, "*/*", "www/present", HTSaveLocally, 862: 0.3, 0.0, 0.0); 863: 864: } 865: 1.27 cvs 866: 1.15 cvs 867: /*---------------------------------------------------------------------- 1.17 cvs 868: AHTProtocolInit 869: Registers all amaya supported protocols. 1.15 cvs 870: ----------------------------------------------------------------------*/ 1.4 cvs 871: static void AHTProtocolInit (void) 872: { 873: 1.17 cvs 874: /* 1.74 cvs 875: NB. Preemptive == YES means Blocking requests 876: Non-preemptive == NO means Non-blocking requests 1.17 cvs 877: */ 1.4 cvs 878: 1.63 cvs 879: HTProtocol_add ("http", "buffered_tcp", NO, HTLoadHTTP, NULL); 1.4 cvs 880: /* HTProtocol_add ("http", "tcp", NO, HTLoadHTTP, NULL); */ 881: HTProtocol_add ("file", "local", NO, HTLoadFile, NULL); 882: HTProtocol_add ("cache", "local", NO, HTLoadCache, NULL); 1.36 cvs 883: HTProtocol_add ("ftp", "tcp", NO, HTLoadFTP, NULL); 1.17 cvs 884: #if 0 /* experimental code */ 1.4 cvs 885: HTProtocol_add ("telnet", "", YES, HTLoadTelnet, NULL); 886: HTProtocol_add ("tn3270", "", YES, HTLoadTelnet, NULL); 887: HTProtocol_add ("rlogin", "", YES, HTLoadTelnet, NULL); 888: HTProtocol_add ("nntp", "tcp", NO, HTLoadNews, NULL); 889: HTProtocol_add ("news", "tcp", NO, HTLoadNews, NULL); 1.17 cvs 890: #endif 1.4 cvs 891: } 892: 1.15 cvs 893: /*---------------------------------------------------------------------- 1.17 cvs 894: AHTNetInit 895: Reegisters "before" and "after" request filters. 1.15 cvs 896: ----------------------------------------------------------------------*/ 1.4 cvs 897: static void AHTNetInit (void) 898: { 899: 900: /* Register BEFORE filters 1.74 cvs 901: ** The BEFORE filters handle proxies, caches, rule files etc. 902: ** The filters are called in the order by which the are registered 903: ** Not done automaticly - may be done by application! 904: */ 905: 1.4 cvs 906: 1.74 cvs 907: HTNet_addBefore (HTCredentialsFilter, "http://*", NULL, 6); 908: HTNet_addBefore (HTProxyFilter, NULL, NULL, 10); 1.4 cvs 909: 910: /* register AFTER filters 1.74 cvs 911: ** The AFTER filters handle error messages, logging, redirection, 912: ** authentication etc. 913: ** The filters are called in the order by which the are registered 914: ** Not done automaticly - may be done by application! 915: */ 1.4 cvs 916: 1.82 ! cvs 917: HTNet_addAfter (HTAuthFilter, "http://*", NULL, HT_NO_ACCESS, HT_FILTER_MIDDLE); ! 918: HTNet_addAfter (redirection_handler, "http://*", NULL, HT_TEMP_REDIRECT, HT_FILTER_MIDDLE); ! 919: HTNet_addAfter (redirection_handler, "http://*", NULL, HT_PERM_REDIRECT, HT_FILTER_MIDDLE); ! 920: HTNet_addAfter (HTUseProxyFilter, "http://*", NULL, HT_USE_PROXY, HT_FILTER_MIDDLE); 1.51 cvs 921: HTNet_addAfter (AHTLoadTerminate_handler, NULL, NULL, HT_ALL, HT_FILTER_LAST); 922: /* handles all errors */ 1.7 cvs 923: HTNet_addAfter (terminate_handler, NULL, NULL, HT_ALL, HT_FILTER_LAST); 1.4 cvs 924: } 925: 1.15 cvs 926: /*---------------------------------------------------------------------- 1.17 cvs 927: AHTAlertInit 928: Register alert messages and their callbacks. 1.15 cvs 929: ----------------------------------------------------------------------*/ 930: #ifdef __STDC__ 931: static void AHTAlertInit (void) 932: #else 933: static void AHTAlertInit () 934: #endif 935: { 936: HTAlert_add (AHTProgress, HT_A_PROGRESS); 1.70 cvs 937: # ifndef _WINDOWS 1.15 cvs 938: HTAlert_add ((HTAlertCallback *) Add_NewSocket_to_Loop, HT_PROG_CONNECT); 1.70 cvs 939: # else /* _WINDOWS */ 940: HTAlert_add ((HTAlertCallback *) WIN_Activate_Request, HT_PROG_CONNECT); 941: # endif /* _WINDOWS */ 1.15 cvs 942: HTAlert_add (AHTError_print, HT_A_MESSAGE); 1.48 cvs 943: HTError_setShow (~((unsigned int) 0 ) & ~((unsigned int) HT_ERR_SHOW_DEBUG)); /* process all messages except debug ones*/ 1.15 cvs 944: HTAlert_add (AHTConfirm, HT_A_CONFIRM); 945: HTAlert_add (AHTPrompt, HT_A_PROMPT); 946: HTAlert_add (AHTPromptPassword, HT_A_SECRET); 947: HTAlert_add (AHTPromptUsernameAndPassword, HT_A_USER_PW); 948: } 949: 950: /*---------------------------------------------------------------------- 1.17 cvs 951: AHTProfile_newAmaya 952: creates the Amaya client profile for libwww. 1.15 cvs 953: ----------------------------------------------------------------------*/ 954: #ifdef __STDC__ 955: static void AHTProfile_newAmaya (char *AppName, char *AppVersion) 956: #else /* __STDC__ */ 957: static void AHTProfile_newAmaya (AppName, AppVersion) 958: char *AppName; 959: char *AppVersion; 960: #endif /* __STDC__ */ 1.4 cvs 961: { 962: /* If the Library is not already initialized then do it */ 963: if (!HTLib_isInitialized ()) 964: HTLibInit (AppName, AppVersion); 965: 966: if (!converters) 967: converters = HTList_new (); 1.27 cvs 968: if (!acceptTypes) 969: acceptTypes = HTList_new (); 1.4 cvs 970: if (!encodings) 971: encodings = HTList_new (); 972: 973: /* Register the default set of transport protocols */ 974: HTTransportInit (); 975: 976: /* Register the default set of application protocol modules */ 977: AHTProtocolInit (); 978: 979: /* Enable the persistent cache */ 980: /* HTCacheInit (NULL, 20); */ 981: 982: /* Register the default set of BEFORE and AFTER filters */ 983: AHTNetInit (); 984: 985: /* Set up the default set of Authentication schemes */ 986: HTAAInit (); 987: 988: /* Get any proxy or gateway environment variables */ 989: HTProxy_getEnvVar (); 990: 991: /* Register the default set of converters */ 992: AHTConverterInit (converters); 1.27 cvs 993: AHTAcceptTypesInit (acceptTypes); 1.4 cvs 994: HTFormat_setConversion (converters); 995: 996: /* Register the default set of transfer encoders and decoders */ 997: HTEncoderInit (encodings); /* chunks ??? */ 998: HTFormat_setTransferCoding (encodings); 999: 1000: /* Register the default set of MIME header parsers */ 1.74 cvs 1001: HTMIMEInit (); /* must be called again for language selector */ 1.4 cvs 1002: 1003: /* Register the default set of Icons for directory listings */ 1.27 cvs 1004: /*HTIconInit(NULL); *//* experimental */ 1.4 cvs 1005: 1006: /* Register the default set of messages and dialog functions */ 1007: AHTAlertInit (); 1008: HTAlert_setInteractive (YES); 1009: } 1010: 1.5 cvs 1011: /*---------------------------------------------------------------------- 1.17 cvs 1012: AHTProfile_delete 1013: deletes the Amaya client profile. 1.5 cvs 1014: ----------------------------------------------------------------------*/ 1.4 cvs 1015: #ifdef __STDC__ 1016: static void AHTProfile_delete (void) 1017: #else 1018: static void AHTProfile_delete () 1.7 cvs 1019: #endif /* __STDC__ */ 1.4 cvs 1020: { 1.22 cvs 1021: 1022: /* free the Amaya global context */ 1.74 cvs 1023: if (!converters) 1024: HTConversion_deleteAll (converters); 1025: if (!acceptTypes) 1026: HTConversion_deleteAll (acceptTypes); 1027: if (!encodings) 1028: HTCoding_deleteAll (encodings); 1029: 1030: HTList_delete (Amaya->docid_status); 1031: HTList_delete (Amaya->reqlist); 1032: TtaFreeMemory (Amaya); 1033: { 1.61 cvs 1034: 1.74 cvs 1035: if (HTLib_isInitialized ()) 1036: 1.61 cvs 1037: # ifdef _WINDOWS 1038: HTEventTerminate (); 1039: # endif _WINDOWS; 1.74 cvs 1040: 1041: /* Clean up the persistent cache (if any) */ 1042: HTCacheTerminate (); 1043: 1044: /* Clean up all the global preferences */ 1045: HTFormat_deleteAll (); 1046: 1047: /* Terminate libwww */ 1048: HTLibTerminate (); 1049: } 1.4 cvs 1050: } 1051: 1.5 cvs 1052: /*---------------------------------------------------------------------- 1.17 cvs 1053: QueryInit 1054: initializes the libwww interface 1.5 cvs 1055: ----------------------------------------------------------------------*/ 1.4 cvs 1056: #ifdef __STDC__ 1057: void QueryInit () 1058: #else 1059: void QueryInit () 1060: #endif 1061: { 1062: 1.24 cvs 1063: AmayaIsAlive = TRUE; 1.4 cvs 1064: AHTProfile_newAmaya (HTAppName, HTAppVersion); 1065: 1.69 cvs 1066: /* New AHTBridge stuff */ 1.4 cvs 1067: 1.54 cvs 1068: # ifdef _WINDOWS 1.75 cvs 1069: AHTEventInit (); 1.54 cvs 1070: # endif _WINDOWS; 1.72 cvs 1071: 1.70 cvs 1072: HTEvent_setRegisterCallback (AHTEvent_register); 1.78 cvs 1073: /*** a effacer ***/ 1074: HTEvent_setUnregisterCallback (AHTEvent_unregister); 1075: /*** ***/ 1.4 cvs 1076: 1.72 cvs 1077: # ifndef _WINDOWS 1078: HTEvent_setUnregisterCallback (AHTEvent_unregister); 1079: # endif /* _WINDOWS */ 1080: 1.74 cvs 1081: #ifdef DEBUG_LIBWWW 1082: WWW_TraceFlag = SHOW_CORE_TRACE | SHOW_THREAD_TRACE | PROT_TRACE; 1083: #endif 1.4 cvs 1084: 1085: /* Trace activation (for debugging) */ 1.7 cvs 1086: /* 1.4 cvs 1087: WWW_TraceFlag = SHOW_APP_TRACE | SHOW_UTIL_TRACE | 1088: SHOW_BIND_TRACE | SHOW_THREAD_TRACE | 1089: SHOW_STREAM_TRACE | SHOW_PROTOCOL_TRACE | 1090: SHOW_URI_TRACE | SHOW_AUTH_TRACE | SHOW_ANCHOR_TRACE | 1091: SHOW_CORE_TRACE; 1092: 1.7 cvs 1093: */ 1.4 cvs 1094: 1095: /*** 1096: WWW_TraceFlag = SHOW_CORE_TRACE | SHOW_AUTH_TRACE | SHOW_ANCHOR_TRACE | 1097: SHOW_PROTOCOL_TRACE| SHOW_APP_TRACE | SHOW_UTIL_TRACE; 1098: ***/ 1099: 1100: /* Setting up other user interfaces */ 1101: 1102: /* Setting up different network parameters */ 1.17 cvs 1103: /* Maximum number of simultaneous open sockets */ 1.4 cvs 1104: HTNet_setMaxSocket (8); 1.75 cvs 1105: /* different network services timeouts */ 1.4 cvs 1106: HTDNS_setTimeout (3600); 1.75 cvs 1107: #ifdef _WINDOWS 1108: /* under windows, the libwww persistent socket handling has 1109: ** some bugs. The following line inhibits idle socket reusal. 1110: ** this is a bit slower, but avoids crashes and gives us time 1111: ** to distribute Amaya before having to patch up libwww. 1112: */ 1.76 cvs 1113: HTHost_setPersistTimeout (-1L); 1.75 cvs 1114: #else 1.76 cvs 1115: HTHost_setPersistTimeout (60L); 1.75 cvs 1116: #endif /* _WINDOWS */ 1117: 1.17 cvs 1118: /* Cache is disabled in this version */ 1.4 cvs 1119: HTCacheMode_setEnabled (0); 1120: 1121: /* Initialization of the global context */ 1122: Amaya = (AmayaContext *) TtaGetMemory (sizeof (AmayaContext)); 1123: Amaya->reqlist = HTList_new (); 1124: Amaya->docid_status = HTList_new (); 1125: Amaya->open_requests = 0; 1.74 cvs 1126: 1.4 cvs 1127: #ifdef CATCH_SIG 1.18 cvs 1128: signal (SIGPIPE, SIG_IGN); 1.4 cvs 1129: #endif 1.15 cvs 1130: } 1131: 1.69 cvs 1132: #ifndef _WINDOWS 1.15 cvs 1133: /*---------------------------------------------------------------------- 1.17 cvs 1134: LoopForStop 1135: a copy of the Thop event loop so we can handle the stop button. 1.69 cvs 1136: Not useful for windows code (Ramzi). 1.15 cvs 1137: ----------------------------------------------------------------------*/ 1138: #ifdef __STDC__ 1139: static int LoopForStop (AHTReqContext * me) 1140: #else 1141: static int LoopForStop (AHTReqContext * me) 1142: #endif 1143: { 1144: 1.25 cvs 1145: extern ThotAppContext app_cont; 1.51 cvs 1146: XEvent ev; 1147: XtInputMask status; 1.17 cvs 1148: int status_req = HT_OK; 1.15 cvs 1149: 1150: /* to test the async calls */ 1.17 cvs 1151: /* Loop while waiting for new events, exists when the request is over */ 1.15 cvs 1152: while (me->reqStatus != HT_ABORT && 1153: me->reqStatus != HT_END && 1.69 cvs 1154: me->reqStatus != HT_ERR) { 1155: if (!AmayaIsAlive) 1156: /* Amaya was killed by one of the callback handlers */ 1157: exit (0); 1158: 1159: status = XtAppPending (app_cont); 1160: if (status & XtIMXEvent) { 1161: XtAppNextEvent (app_cont, &ev); 1162: TtaHandleOneEvent (&ev); 1163: } else if (status & (XtIMAll & (~XtIMXEvent))) { 1164: XtAppProcessEvent (app_cont, (XtIMAll & (~XtIMXEvent))); 1165: } else { 1166: XtAppNextEvent (app_cont, &ev); 1167: TtaHandleOneEvent (&ev); 1168: } 1169: } 1.4 cvs 1170: 1.69 cvs 1171: switch (me->reqStatus) { 1172: case HT_ERR: 1173: case HT_ABORT: 1.15 cvs 1174: status_req = HT_ERROR; 1175: break; 1176: 1.69 cvs 1177: case HT_END: 1.15 cvs 1178: status_req = HT_OK; 1179: break; 1180: 1.69 cvs 1181: default: 1.15 cvs 1182: break; 1.69 cvs 1183: } 1.15 cvs 1184: return (status_req); 1.4 cvs 1185: } 1.69 cvs 1186: #endif /* _WINDOWS */ 1.4 cvs 1187: 1.5 cvs 1188: /*---------------------------------------------------------------------- 1.15 cvs 1189: QueryClose 1.21 cvs 1190: closes all existing threads, frees all non-automatically deallocated 1191: memory and then ends libwww. 1.5 cvs 1192: ----------------------------------------------------------------------*/ 1.4 cvs 1193: void QueryClose () 1194: { 1.24 cvs 1195: 1196: AmayaIsAlive = FALSE; 1197: 1.21 cvs 1198: /* remove all the handlers and callbacks that may output a message to 1199: a non-existent Amaya window */ 1200: 1201: HTNet_deleteAfter (AHTLoadTerminate_handler); 1202: HTNet_deleteAfter (redirection_handler); 1203: HTAlertCall_deleteAll (HTAlert_global () ); 1.23 cvs 1204: HTAlert_setGlobal ((HTList *) NULL); 1.24 cvs 1205: HTEvent_setRegisterCallback ((HTEvent_registerCallback *) NULL); 1.27 cvs 1206: HTEvent_setUnregisterCallback ((HTEvent_unregisterCallback *) NULL); 1.69 cvs 1207: 1.4 cvs 1208: Thread_deleteAll (); 1.21 cvs 1209: 1.4 cvs 1210: HTProxy_deleteAll (); 1211: HTNoProxy_deleteAll (); 1212: HTGateway_deleteAll (); 1213: AHTProfile_delete (); 1214: } 1215: 1.5 cvs 1216: /*---------------------------------------------------------------------- 1.15 cvs 1217: GetObjectWWW 1.17 cvs 1218: this function requests a resource designated by a URLname into a 1219: temporary filename. The download can come from a simple GET operation, 1220: or can come from POSTING/GETTING a form. In the latter 1221: case, the function receives a query string to send to the server. 1222: 1.5 cvs 1223: 4 file retrieval modes are proposed: 1224: AMAYA_SYNC : blocking mode 1225: AMAYA_ISYNC : incremental, blocking mode 1226: AMAYA_ASYNC : non-blocking mode 1227: AMAYA_IASYNC : incremental, non-blocking mode 1228: 1229: In the incremental mode, each time a package arrives, it will be 1230: stored in the temporary file. In addition, if an 1231: incremental_callback function is defined, this function will be 1232: called and handled a copy of the newly received data package. 1233: Finally, if a terminate_callback function is defined, it will be 1234: invoked when the request terminates. The caller of this function 1.4 cvs 1235: can define two different contexts to be passed to the callback 1236: functions. 1237: 1238: When the function is called with the SYNC mode, the function will 1239: return only when the requested file has been loaded. 1240: The ASYNC mode will immediately return after setting up the 1241: call. 1242: 1243: Notes: 1244: At the end of a succesful request, the urlName string contains the 1245: name of the actually retrieved URL. As a URL can change over the time, 1246: (e.g., be redirected elsewhere), it is advised that the function 1.17 cvs 1247: caller verify the value of the urlName variable at the end of 1.4 cvs 1248: a request. 1249: 1250: Inputs: 1251: - docid Document identifier for the set of objects being 1252: retrieved. 1253: - urlName The URL to be retrieved (MAX_URL_LENGTH chars length) 1254: - outputfile A pointer to an empty string of MAX_URL_LENGTH. 1255: - mode The retrieval mode. 1256: - incremental_cbf 1257: - context_icbf 1258: Callback and context for the incremental modes 1259: - terminate_cbf 1260: - context_icbf 1261: Callback and context for a terminate handler 1.17 cvs 1262: -error_html if TRUE, then display any server error message as an 1263: HTML document. 1.4 cvs 1264: 1265: Outputs: 1266: - urlName The URL that was retrieved 1267: - outputfile The name of the temporary file which holds the 1268: retrieved data. (Only in case of success) 1269: Returns: 1270: HT_ERROR 1271: HT_OK 1.5 cvs 1272: 1273: ----------------------------------------------------------------------*/ 1.4 cvs 1274: #ifdef __STDC__ 1.52 cvs 1275: int GetObjectWWW (int docid, char* urlName, char* postString, char* outputfile, int mode, 1276: TIcbf* incremental_cbf, void* context_icbf, TTcbf* terminate_cbf, 1277: void* context_tcbf, boolean error_html) 1.4 cvs 1278: #else 1.52 cvs 1279: int GetObjectWWW (docid, urlName, postString, outputfile, mode, incremental_cbf, context_icbf, 1280: terminate_cbf, context_tcbf, error_html) 1.73 cvs 1281: int docid; 1282: char *urlName; 1283: char *postString; 1284: char *outputfile; 1285: int mode; 1286: TIcbf *incremental_cbf; 1287: void *context_icbf; 1288: TTcbf *terminate_cbf; 1289: void *context_tcbf; 1290: boolean error_html; 1.4 cvs 1291: #endif 1292: { 1293: AHTReqContext *me; 1294: char *ref; 1295: int status; 1.7 cvs 1296: 1.69 cvs 1297: if (urlName == NULL || docid == 0 || outputfile == NULL) { 1298: /* no file to be loaded */ 1299: TtaSetStatus (docid, 1, TtaGetMessage (AMAYA, AM_BAD_URL), urlName); 1300: 1301: if (error_html) 1302: /* so we can show the error message */ 1303: DocNetworkStatus[docid] |= AMAYA_NET_ERROR; 1304: return HT_ERROR; 1305: 1306: } 1.7 cvs 1307: 1.4 cvs 1308: /* do we support this protocol? */ 1.69 cvs 1309: if (IsValidProtocol (urlName) == NO) { 1310: /* return error */ 1311: outputfile[0] = EOS; /* file could not be opened */ 1312: TtaSetStatus (docid, 1, TtaGetMessage (AMAYA, AM_GET_UNSUPPORTED_PROTOCOL), urlName); 1313: 1314: if (error_html) 1315: /* so we can show the error message */ 1316: DocNetworkStatus[docid] |= AMAYA_NET_ERROR; 1317: return HT_ERROR; 1318: } 1.4 cvs 1319: 1.58 cvs 1320: /*create a tempfilename */ 1.59 cvs 1321: sprintf (outputfile, "%s%c%d%c%04dAM", TempFileDirectory, DIR_SEP, docid, DIR_SEP, object_counter); 1.4 cvs 1322: 1323: /* update the object_counter */ 1324: object_counter++; 1325: /* normalize the URL */ 1.45 cvs 1326: ref = AmayaParseUrl (urlName, "", AMAYA_PARSE_ALL); 1.4 cvs 1327: /* should we abort the request if we could not normalize the url? */ 1.69 cvs 1328: if (ref == (char*) NULL || ref[0] == EOS) { 1329: /*error */ 1330: outputfile[0] = EOS; 1331: TtaSetStatus (docid, 1, TtaGetMessage (AMAYA, AM_BAD_URL), urlName); 1332: 1333: if (error_html) 1334: /* so we can show the error message */ 1335: DocNetworkStatus[docid] |= AMAYA_NET_ERROR; 1.4 cvs 1336: 1.69 cvs 1337: return HT_ERROR; 1338: } 1.4 cvs 1339: /* verify if that file name existed */ 1.9 cvs 1340: if (TtaFileExist (outputfile)) 1.77 cvs 1341: TtaFileUnlink (outputfile); 1.4 cvs 1342: 1343: /* Initialize the request structure */ 1344: me = AHTReqContext_new (docid); 1.69 cvs 1345: if (me == NULL) { 1.77 cvs 1346: outputfile[0] = EOS; 1347: /* need an error message here */ 1348: TtaFreeMemory (ref); 1349: return (HT_ERROR); 1.69 cvs 1350: } 1.77 cvs 1351: 1.4 cvs 1352: /* Specific initializations for POST and GET */ 1.69 cvs 1353: if (mode & AMAYA_FORM_POST) { 1.77 cvs 1354: me->method = METHOD_POST; 1355: if (postString) { 1356: me->mem_ptr = postString; 1357: me->block_size = strlen (postString); 1358: } else { 1359: me->mem_ptr = ""; 1360: me->block_size = 0; 1361: } 1362: HTRequest_setMethod (me->request, METHOD_POST); 1.69 cvs 1363: HTRequest_setPostCallback (me->request, AHTUpload_callback); 1364: } else { 1.77 cvs 1365: me->method = METHOD_GET; 1366: me->dest = (HTParentAnchor *) NULL; /*useful only for PUT and POST methods */ 1367: if (!HasKnownFileSuffix (ref)) 1368: HTRequest_setConversion(me->request, acceptTypes, TRUE); 1.69 cvs 1369: } 1.4 cvs 1370: 1371: /* Common initialization */ 1372: me->mode = mode; 1373: me->error_html = error_html; 1374: me->incremental_cbf = incremental_cbf; 1375: me->context_icbf = context_icbf; 1376: me->terminate_cbf = terminate_cbf; 1377: me->context_tcbf = context_tcbf; 1.64 cvs 1378: 1.69 cvs 1379: /* for the async. request modes, we need to have our 1.4 cvs 1380: own copy of outputfile and urlname 1381: */ 1382: 1.69 cvs 1383: if ((mode & AMAYA_ASYNC) || (mode & AMAYA_IASYNC)) { 1.77 cvs 1384: char* tmp; 1385: 1.69 cvs 1386: tmp = TtaGetMemory (strlen (outputfile) + 1); 1387: strcpy (tmp, outputfile); 1388: me->outputfile = tmp; 1389: 1390: tmp = TtaGetMemory (MAX_LENGTH + 1); 1391: strncpy (tmp, urlName, MAX_LENGTH); 1392: tmp[MAX_LENGTH] = EOS; 1393: me->urlName = tmp; 1394: # ifdef _WINDOWS 1395: HTRequest_setPreemptive (me->request, NO); 1396: } else { 1.77 cvs 1397: me->outputfile = outputfile; 1398: me->urlName = urlName; 1399: HTRequest_setPreemptive (me->request, YES); 1.61 cvs 1400: } 1.69 cvs 1401: # else /* _WINDOWS */ 1402: } else { 1.77 cvs 1403: me->outputfile = outputfile; 1404: me->urlName = urlName; 1.61 cvs 1405: } 1.77 cvs 1406: /*** 1.57 cvs 1407: Change for taking into account the stop button: 1408: The requests will be always asynchronous, however, if mode=AMAYA_SYNC, 1409: we will loop until the document has been received or a stop signal 1410: generated 1.77 cvs 1411: ****/ 1412: HTRequest_setPreemptive (me->request, NO); 1.69 cvs 1413: # endif /* _WINDOWS */ 1.61 cvs 1414: 1415: /* prepare the URLname that will be displayed in teh status bar */ 1416: ChopURL (me->status_urlName, me->urlName); 1417: 1.77 cvs 1418: TtaSetStatus (me->docid, 1, 1419: TtaGetMessage (AMAYA, AM_FETCHING), 1420: me->status_urlName); 1.4 cvs 1421: 1422: me->anchor = (HTParentAnchor *) HTAnchor_findAddress (ref); 1.45 cvs 1423: TtaFreeMemory (ref); 1.4 cvs 1424: 1.69 cvs 1425: if (mode & AMAYA_FORM_POST) { 1426: HTAnchor_setFormat ((HTParentAnchor *) me->anchor, HTAtom_for ("application/x-www-form-urlencoded")); 1427: HTAnchor_setLength ((HTParentAnchor *) me->anchor, me->block_size); 1428: HTRequest_setEntityAnchor (me->request, me->anchor); 1429: 1430: status = HTLoadAbsolute (urlName, me->request); 1431: } else 1.77 cvs 1432: status = HTLoadAnchor ((HTAnchor *) me->anchor, me->request); 1.69 cvs 1433: 1.72 cvs 1434: #ifndef _WINDOWS 1.77 cvs 1435: if (status == HT_ERROR || 1436: me->reqStatus == HT_END || 1437: me->reqStatus == HT_ERR) 1438: { 1439: /* in case of error, free all allocated memory and exit */ 1.82 ! cvs 1440: if (me->output) { 1.77 cvs 1441: fclose (me->output); 1.82 ! cvs 1442: me->output = NULL; ! 1443: } ! 1444: 1.72 cvs 1445: if (me->reqStatus == HT_ERR) { 1.77 cvs 1446: status = HT_ERROR; 1447: /* show an error message on the status bar */ 1448: DocNetworkStatus[me->docid] |= AMAYA_NET_ERROR; 1449: TtaSetStatus (me->docid, 1, TtaGetMessage (AMAYA, AM_CANNOT_LOAD), me-> 1450: status_urlName); 1.72 cvs 1451: } else 1.77 cvs 1452: status = HT_OK; 1.72 cvs 1453: 1454: AHTReqContext_delete (me); 1.77 cvs 1455: } else { 1.72 cvs 1456: /* part of the stop button handler */ 1457: if ((mode & AMAYA_SYNC) || (mode & AMAYA_ISYNC)) { 1458: status = LoopForStop (me); 1459: AHTReqContext_delete (me); 1460: } 1461: } 1.79 cvs 1462: /* TtaHandlePendingEvents (); */ 1.72 cvs 1463: 1464: #else /* !_WINDOWS */ 1465: 1.71 cvs 1466: if (status == HT_ERROR) { 1467: 1.77 cvs 1468: /* in case of error, close any open files, free all allocated 1469: memory and exit */ 1470: if (me->output && me->output != stdout) 1.69 cvs 1471: fclose (me->output); 1472: 1473: if (me->reqStatus == HT_ERR) { 1.77 cvs 1474: status = HT_ERROR; 1475: /* show an error message on the status bar */ 1476: DocNetworkStatus[me->docid] |= AMAYA_NET_ERROR; 1477: TtaSetStatus (me->docid, 1, 1478: TtaGetMessage (AMAYA, AM_CANNOT_LOAD), 1479: me->status_urlName); 1.69 cvs 1480: } else 1.77 cvs 1481: status = HT_OK; 1.69 cvs 1482: 1483: AHTReqContext_delete (me); 1484: } else { 1.77 cvs 1485: /* part of the stop button handler */ 1486: if ((mode & AMAYA_SYNC) || (mode & AMAYA_ISYNC)) { 1487: AHTReqContext_delete (me); 1.69 cvs 1488: } 1.64 cvs 1489: } 1.79 cvs 1490: /*TtaHandlePendingEvents (); */ 1.4 cvs 1491: 1.72 cvs 1492: #endif /* !_WINDOWS */ 1493: 1.4 cvs 1494: return (status); 1495: } 1496: 1.5 cvs 1497: /*---------------------------------------------------------------------- 1.17 cvs 1498: PutObjectWWW 1499: frontend for uploading a resource to a URL. This function downloads 1500: a file to be uploaded into memory, it then calls UploadMemWWW to 1501: finish the job. 1502: 1.5 cvs 1503: 2 upload modes are proposed: 1504: AMAYA_SYNC : blocking mode 1505: AMAYA_ASYNC : non-blocking mode 1506: 1.4 cvs 1507: When the function is called with the SYNC mode, the function will 1508: return only when the file has been uploaded. 1509: The ASYNC mode will immediately return after setting up the 1510: call. Furthermore, at the end of an upload, the ASYNC mode will 1511: call back terminate_cbf, handling it the context defined in 1512: context_tcbf. 1513: 1514: Notes: 1515: At the end of a succesful request, the urlName string contains the 1516: name of the actually uploaded URL. As a URL can change over the time, 1517: (e.g., be redirected elsewhere), it is advised that the function 1518: caller verifies the value of the urlName variable at the end of 1519: a request. 1520: 1521: Inputs: 1522: - docid Document identifier for the set of objects being 1523: retrieved. 1524: - fileName A pointer to the local file to upload 1525: - urlName The URL to be uploaded (MAX_URL_LENGTH chars length) 1526: - mode The retrieval mode. 1527: - terminate_cbf 1528: - context_icbf 1529: Callback and context for a terminate handler 1530: 1531: Outputs: 1532: - urlName The URL that was uploaded 1533: 1534: Returns: 1535: HT_ERROR 1536: HT_OK 1.5 cvs 1537: ----------------------------------------------------------------------*/ 1.4 cvs 1538: #ifdef __STDC__ 1.27 cvs 1539: int PutObjectWWW (int docid, char *fileName, char *urlName, int mode, PicType contentType, 1.4 cvs 1540: TTcbf * terminate_cbf, void *context_tcbf) 1541: #else 1.26 cvs 1542: int PutObjectWWW (docid, urlName, fileName, mode, contentType, 1.4 cvs 1543: ,terminate_cbf, context_tcbf) 1544: int docid; 1545: char *urlName; 1546: char *fileName; 1547: int mode; 1.27 cvs 1548: PicType contentType; 1.4 cvs 1549: TTcbf *terminate_cbf; 1550: void *context_tcbf; 1551: 1552: #endif 1553: { 1.7 cvs 1554: /*AHTReqContext *me; */ 1.4 cvs 1555: int status; 1556: 1557: int fd; 1558: struct stat file_stat; 1559: char *mem_ptr; 1560: unsigned long block_size; 1561: 1.33 cvs 1562: AmayaLastHTTPErrorMsg [0] = EOS; 1563: 1.4 cvs 1564: if (urlName == NULL || docid == 0 || fileName == NULL || 1.9 cvs 1565: !TtaFileExist (fileName)) 1.4 cvs 1566: /* no file to be uploaded */ 1567: return HT_ERROR; 1568: 1569: /* do we support this protocol? */ 1.7 cvs 1570: if (IsValidProtocol (urlName) == NO) 1571: { 1572: /* return error */ 1.77 cvs 1573: TtaSetStatus (docid, 1, 1574: TtaGetMessage (AMAYA, AM_PUT_UNSUPPORTED_PROTOCOL), 1.7 cvs 1575: urlName); 1576: return HT_ERROR; 1577: } 1.4 cvs 1578: /* read the file into memory */ 1.70 cvs 1579: # ifndef _WINDOWS 1.7 cvs 1580: if ((fd = open (fileName, O_RDONLY)) == -1) 1.70 cvs 1581: # else /* _WINDOWS */ 1.74 cvs 1582: if ((fd = open (fileName, _O_RDONLY | _O_BINARY)) == -1) 1.70 cvs 1583: # endif /* _WINDOWS */ 1.7 cvs 1584: { 1585: /* if we could not open the file, exit */ 1586: /*error msg here */ 1587: return (HT_ERROR); 1588: } 1.4 cvs 1589: 1590: fstat (fd, &file_stat); 1591: 1.7 cvs 1592: if (file_stat.st_size == 0) 1593: { 1594: /* file was empty */ 1595: /*errmsg here */ 1596: close (fd); 1597: return (HT_ERROR); 1598: } 1.4 cvs 1599: block_size = file_stat.st_size; 1600: 1601: if (THD_TRACE) 1602: fprintf (stderr, "file size == %u\n", (unsigned) block_size); 1603: 1604: mem_ptr = (char *) TtaGetMemory (block_size); 1605: 1.7 cvs 1606: if (mem_ptr == (char *) NULL) 1607: { 1608: /* could not allocate enough memory */ 1609: /*errmsg here */ 1610: close (fd); 1611: return (HT_ERROR); 1612: } 1.4 cvs 1613: read (fd, mem_ptr, block_size); 1614: 1615: close (fd); 1616: 1.27 cvs 1617: status = UploadMemWWW (docid, METHOD_PUT, urlName, contentType, mem_ptr, 1.4 cvs 1618: block_size, mode, terminate_cbf, 1619: context_tcbf, (char *) NULL); 1620: 1621: TtaFreeMemory (mem_ptr); 1.28 cvs 1622: TtaHandlePendingEvents (); 1.4 cvs 1623: return (status); 1624: } 1625: 1.5 cvs 1626: /*---------------------------------------------------------------------- 1.17 cvs 1627: UploadMemWWW 1628: low level interface function to libwww for uploading a block of 1629: memory to a URL. 1.5 cvs 1630: ----------------------------------------------------------------------*/ 1.4 cvs 1631: #ifdef __STDC__ 1632: int UploadMemWWW (int docid, HTMethod method, 1.27 cvs 1633: char *urlName, PicType contentType, char *mem_ptr, unsigned long block_size, 1.4 cvs 1634: int mode, TTcbf * terminate_cbf, void *context_tcbf, 1635: char *outputfile) 1636: #else 1.27 cvs 1637: int UploadMemWWW (docid, method, urlName, contentType, mem_ptr, block_size, mode, 1.4 cvs 1638: terminate_cbf, context_tcbf, outputfile) 1639: int docid; 1640: HTMethod method; 1641: char *urlName; 1.27 cvs 1642: PicType contentType; 1.4 cvs 1643: char *mem_ptr; 1644: usigned long block_size; 1645: int mode; 1646: TTcbf *terminate_cbf; 1647: void *context_tcbf; 1648: char *outputfile; 1.7 cvs 1649: 1.4 cvs 1650: #endif 1651: { 1652: AHTReqContext *me; 1653: int status; 1654: 1655: if (mem_ptr == (char *) NULL || 1656: block_size == 0 || 1657: docid == 0 || 1.7 cvs 1658: urlName == (char *) NULL) 1659: { 1660: /* nothing to be uploaded */ 1661: return HT_ERROR; 1662: } 1.4 cvs 1663: 1664: /* Initialize the request structure */ 1665: me = AHTReqContext_new (docid); 1666: 1.7 cvs 1667: if (me == NULL) 1668: { 1669: /* need an error message here */ 1670: TtaHandlePendingEvents (); 1671: return (HT_ERROR); 1672: } 1.4 cvs 1673: me->mode = mode; 1674: 1675: me->incremental_cbf = (TIcbf *) NULL; 1676: me->context_icbf = (void *) NULL; 1677: me->terminate_cbf = terminate_cbf; 1678: me->context_tcbf = context_tcbf; 1679: 1680: me->output = stdout; 1681: me->outputfile = (char *) NULL; 1682: me->urlName = urlName; 1683: 1.70 cvs 1684: #ifdef _WINDOWS 1685: HTRequest_setPreemptive (me->request, YES); 1686: #else 1.4 cvs 1687: HTRequest_setPreemptive (me->request, NO); 1.70 cvs 1688: #endif /* _WINDOWS */ 1.74 cvs 1689: 1.17 cvs 1690: /* select the parameters that distinguish a PUT from a GET/POST */ 1.4 cvs 1691: me->method = METHOD_PUT; 1692: HTRequest_setMethod (me->request, METHOD_PUT); 1693: me->output = stdout; 1.17 cvs 1694: /* we are not expecting to receive any input from the server */ 1695: me->outputfile = (char *) NULL; 1.4 cvs 1696: 1697: me->mem_ptr = mem_ptr; 1698: me->block_size = block_size; 1.17 cvs 1699: 1700: /* set the callback which will actually copy data into the 1701: output stream */ 1702: 1.4 cvs 1703: HTRequest_setPostCallback (me->request, AHTUpload_callback); 1.72 cvs 1704: 1.4 cvs 1705: me->anchor = (HTParentAnchor *) HTAnchor_findAddress (urlName); 1.7 cvs 1706: 1.28 cvs 1707: /* Set the Content-Type of the file we are uploading */ 1.77 cvs 1708: HTAnchor_setFormat ((HTParentAnchor *) me->anchor, 1709: AHTGuessAtom_for (me->urlName, contentType)); 1.17 cvs 1710: 1.7 cvs 1711: HTAnchor_setLength ((HTParentAnchor *) me->anchor, me->block_size); 1.4 cvs 1712: HTRequest_setEntityAnchor (me->request, me->anchor); 1.74 cvs 1713: /* prepare the URLname that will be displayed in teh status bar */ 1714: ChopURL (me->status_urlName, me->urlName); 1715: TtaSetStatus (me->docid, 1, TtaGetMessage (AMAYA, AM_REMOTE_SAVING), 1716: me->status_urlName); 1.4 cvs 1717: status = HTLoadAbsolute (urlName, me->request); 1718: 1.74 cvs 1719: #ifndef _WINDOWS 1.77 cvs 1720: if (status == HT_ERROR || 1721: me->reqStatus == HT_END || 1722: me->reqStatus == HT_ERR || 1723: HTError_hasSeverity (HTRequest_error (me->request), ERR_INFO)) 1.74 cvs 1724: #else 1725: if (status == HT_ERROR) 1726: #endif /* !_WINDOWS */ 1.7 cvs 1727: { 1.17 cvs 1728: status = HT_ERROR; 1.28 cvs 1729: } 1.7 cvs 1730: else 1731: { 1732: /* part of the stop button handler */ 1.4 cvs 1733: 1.7 cvs 1734: if ((mode & AMAYA_SYNC) || (mode & AMAYA_ISYNC)) 1735: { 1.70 cvs 1736: # ifndef _WINDOWS 1.7 cvs 1737: status = LoopForStop (me); 1.70 cvs 1738: # endif /* !_WINDOWS */ 1.7 cvs 1739: } 1.15 cvs 1740: } 1.77 cvs 1741: AHTReqContext_delete (me); 1.4 cvs 1742: return (status); 1.28 cvs 1743: } 1.4 cvs 1744: 1745: 1746: 1.5 cvs 1747: /*---------------------------------------------------------------------- 1.17 cvs 1748: Stop Request 1749: stops (kills) all active requests associated with a docid 1.5 cvs 1750: ----------------------------------------------------------------------*/ 1.4 cvs 1751: #ifdef __STDC__ 1752: void StopRequest (int docid) 1753: #else 1754: void StopRequest (docid) 1755: int docid; 1756: #endif 1757: { 1758: HTList *cur; 1759: AHTDocId_Status *docid_status; 1760: AHTReqContext *me; 1761: int open_requests; 1762: 1.7 cvs 1763: if (Amaya) 1764: { 1.4 cvs 1765: 1.7 cvs 1766: cur = Amaya->reqlist; 1767: docid_status = (AHTDocId_Status *) GetDocIdStatus (docid, 1.4 cvs 1768: Amaya->docid_status); 1769: 1.7 cvs 1770: /* verify if there are any requests at all associated with docid */ 1.4 cvs 1771: 1.7 cvs 1772: if (docid_status == (AHTDocId_Status *) NULL) 1773: return; 1.4 cvs 1774: 1.7 cvs 1775: open_requests = docid_status->counter; 1.4 cvs 1776: 1.7 cvs 1777: while ((me = (AHTReqContext *) HTList_nextObject (cur))) 1778: { 1779: if (me->docid == docid) 1780: { 1781: /* kill this request */ 1.4 cvs 1782: 1.7 cvs 1783: switch (me->reqStatus) 1784: { 1785: case HT_ABORT: 1786: break; 1.4 cvs 1787: 1.7 cvs 1788: case HT_BUSY: 1789: me->reqStatus = HT_ABORT; 1790: break; 1791: case HT_NEW_PENDING: 1792: case HT_WAITING: 1793: default: 1.74 cvs 1794: me->reqStatus = HT_ABORT; 1.70 cvs 1795: # ifndef _WINDOWS 1.7 cvs 1796: RequestKillAllXtevents (me); 1.74 cvs 1797: # endif _WINDOWS 1798: 1.79 cvs 1799: HTRequest_kill (me->request); 1.71 cvs 1800: if ((me->mode & AMAYA_ASYNC) || 1801: (me->mode & AMAYA_IASYNC)) 1.7 cvs 1802: { 1803: AHTReqContext_delete (me); 1804: } 1.75 cvs 1805: 1.74 cvs 1806: cur = Amaya->reqlist; 1807: 1.7 cvs 1808: open_requests--; 1.4 cvs 1809: 1.7 cvs 1810: break; 1.4 cvs 1811: 1.7 cvs 1812: } /* switch */ 1813: } /* if me docid */ 1814: } /* while */ 1815: } /* if amaya open requests */ 1.4 cvs 1816: } /* StopRequest */ 1.17 cvs 1817: 1818: /* 1819: end of Module query.c 1820: */ 1821: 1.69 cvs 1822: #endif /* AMAYA_JAVA */ 1.77 cvs 1823: 1824: 1.17 cvs 1825: 1826: