Annotation of Amaya/amaya/query.c, revision 1.124
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: /*
1.83 cvs 9: * query.c : contains all the functions for requesting and publishing
1.19 cvs 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.92 cvs 14: * J. Kahan/R. Guetari Windows 95/NT routines
1.19 cvs 15: */
1.17 cvs 16:
1.44 cvs 17: #ifndef AMAYA_JAVA
18:
1.116 cvs 19: /* defines to include elsewhere
20: *********************************/
21:
1.124 ! cvs 22: #ifndef _WINDOWS
1.116 cvs 23: #define AMAYA_WWW_CACHE
1.124 ! cvs 24: #endif /* !_WINDOWS */
1.116 cvs 25:
26: /*** for windows? ***/
27:
28: #ifndef _WINDOWS
1.122 cvs 29: #define CACHE_DIR_NAME "/libwww-cache"
1.116 cvs 30: #else
1.122 cvs 31: #define CACHE_DIR_NAME "\libwww-cache"
1.116 cvs 32: #endif /* !_WINDOWS */
33:
34:
35:
36: #define DEFAULT_CACHE_SIZE 5
37:
38:
1.12 cvs 39: /* Amaya includes */
1.25 cvs 40: #define THOT_EXPORT extern
1.4 cvs 41: #include "amaya.h"
1.70 cvs 42: #ifdef _WINDOWS
43: #include <fcntl.h>
44: #endif /* _WINDOWS */
1.7 cvs 45:
1.4 cvs 46: #if defined(__svr4__)
47: #define CATCH_SIG
48: #endif
49:
50: /* local structures coming from libwww and which are
1.17 cvs 51: not found in any .h file
1.7 cvs 52: */
1.68 cvs 53:
1.7 cvs 54: struct _HTStream
55: {
1.15 cvs 56: const HTStreamClass *isa;
57: FILE *fp;
1.45 cvs 58: BOOL leave_open; /* Close file when TtaFreeMemory? */
1.15 cvs 59: char *end_command; /* Command to execute */
60: BOOL remove_on_close; /* Remove file? */
61: char *filename; /* Name of file */
62: HTRequest *request; /* saved for callback */
63: HTRequestCallback *callback;
1.7 cvs 64: };
65:
1.15 cvs 66:
1.7 cvs 67: struct _HTError
68: {
69: HTErrorElement element; /* Index number into HTError */
70: HTSeverity severity; /* A la VMS */
71: BOOL ignore; /* YES if msg should not go to user */
72: void *par; /* Explanation, e.g. filename */
73: int length; /* For copying by generic routine */
74: char *where; /* Which function */
75: };
76:
1.4 cvs 77: /* Type definitions and global variables etc. local to this module */
78:
1.17 cvs 79: /*----------------------------------------------------------------------*/
80:
1.4 cvs 81: /*** private variables ***/
1.17 cvs 82:
1.4 cvs 83: static HTList *converters = NULL; /* List of global converters */
1.27 cvs 84: static HTList *acceptTypes = NULL; /* List of types for the Accept header */
1.4 cvs 85: static HTList *encodings = NULL;
1.16 cvs 86: static int object_counter = 0; /* loaded objects counter */
1.116 cvs 87: static boolean AmayaAlive; /* set to 1 if the application is active;
88: 0 if we have killed */
1.4 cvs 89:
1.15 cvs 90: #include "answer_f.h"
91: #include "query_f.h"
92: #include "AHTURLTools_f.h"
93: #include "AHTBridge_f.h"
94: #include "AHTMemConv_f.h"
95: #include "AHTFWrite_f.h"
1.4 cvs 96:
1.116 cvs 97: /* prototypes */
98:
99: #ifdef __STDC__
1.123 cvs 100: #ifdef _WINDOWS
1.70 cvs 101: int WIN_Activate_Request (HTRequest* , HTAlertOpcode, int, const char*, void*, HTAlertPar*);
1.116 cvs 102: #endif /* _WINDOWS */
1.70 cvs 103: #else
1.123 cvs 104: #ifdef _WINDOWS
1.70 cvs 105: int WIN_Activate_Request ();
1.116 cvs 106: #endif /* _WINDOWS */
1.70 cvs 107: #endif /* __STDC__ */
1.116 cvs 108:
1.15 cvs 109:
110: /*----------------------------------------------------------------------
1.17 cvs 111: GetDocIdStatus
112: gets the status associated to a docid
1.15 cvs 113: ----------------------------------------------------------------------*/
114: #ifdef __STDC__
115: AHTDocId_Status *GetDocIdStatus (int docid, HTList * documents)
116: #else
117: AHTDocID_Status *GetDocIdStatus (docid, documents)
118: int docid;
119: HTList *documents;
120:
121: #endif
122: {
123: AHTDocId_Status *me;
124: HTList *cur;
125:
126: if (documents)
127: {
128: cur = documents;
129:
130: while ((me = (AHTDocId_Status *) HTList_nextObject (cur)))
131: {
132: if (me->docid == docid)
133: return (me);
1.18 cvs 134: }
135: }
1.15 cvs 136: return (AHTDocId_Status *) NULL;
137:
138: }
139:
1.5 cvs 140: /*----------------------------------------------------------------------
1.27 cvs 141: AHTGuessAtom_for
142: Converts an Amaya type descriptor into the equivalent MIME type.
143: ----------------------------------------------------------------------*/
144: #ifdef __STDC__
145: static HTAtom *AHTGuessAtom_for (char *urlName, PicType contentType)
146: #else
147: static HTAtom *AHTGuessAtom_for (urlName, contentType)
148: char *urlName;
149: PicType contentType;
150: #endif
151: {
152: HTAtom *atom;
153: char *filename;
154: HTEncoding enc;
155: HTEncoding cte;
156: HTLanguage lang;
1.50 cvs 157: double quality = 1.0;
1.27 cvs 158:
159: switch (contentType)
160: {
161: case xbm_type:
162: atom = HTAtom_for("image/xbm");
163: break;
164: case eps_type:
1.35 cvs 165: atom = HTAtom_for("application/postscript");
1.27 cvs 166: break;
167: case xpm_type:
168: atom = HTAtom_for("image/xpm");
169: break;
170: case gif_type:
171: atom = HTAtom_for("image/gif");
172: break;
173: case jpeg_type:
174: atom = HTAtom_for("image/jpeg");
175: break;
176: case png_type:
177: atom = HTAtom_for("image/png");
178: break;
179: case unknown_type:
180: default:
181: /*
182: ** Amaya could not detect the type, so
183: ** we try to use the filename's suffix to do so.
184: */
1.45 cvs 185: filename = AmayaParseUrl (urlName, "", AMAYA_PARSE_PATH | AMAYA_PARSE_PUNCTUATION);
1.27 cvs 186: HTBind_getFormat (filename, &atom, &enc, &cte, &lang, &quality);
1.45 cvs 187: TtaFreeMemory (filename);
1.27 cvs 188: if (atom == WWW_UNKNOWN)
189: /*
190: ** we could not identify the suffix, so we assign it
191: ** a default type
192: */
193: atom = HTAtom_for ("text/html");
194: break;
195: }
196:
197: return atom;
198: }
199:
200: /*----------------------------------------------------------------------
1.17 cvs 201: AHTReqContext_new
202: create a new Amaya Context Object and update the global Amaya
203: request status.
1.5 cvs 204: ----------------------------------------------------------------------*/
1.4 cvs 205: #ifdef __STDC__
206: static AHTReqContext *AHTReqContext_new (int docid)
207: #else
208: static AHTReqContext *AHTReqContext_new (docid)
209: int docid;
210:
211: #endif
212: {
213: AHTReqContext *me;
214: AHTDocId_Status *docid_status;
215:
216: if ((me = (AHTReqContext *) TtaGetMemory (sizeof (AHTReqContext))) == NULL)
1.116 cvs 217: outofmem (__FILE__, "AHTReqContext_new");
218:
219: /* clear the structure */
220: memset ((void *) me, 0, sizeof (AHTReqContext));
1.4 cvs 221:
1.81 cvs 222: /* Bind the Context object together with the Request Object */
223: me->request = HTRequest_new ();
224:
1.116 cvs 225: /*
226: ** Make sure that the first request is flushed immediately and not
227: ** buffered in the output buffer
228: */
229: HTRequest_setFlush(me->request, YES);
230:
1.80 cvs 231: /* clean the associated file structure) */
1.79 cvs 232: HTRequest_setOutputStream (me->request, NULL);
1.81 cvs 233:
1.4 cvs 234: /* Initialize the other members of the structure */
1.17 cvs 235: me->reqStatus = HT_NEW; /* initial status of a request */
1.4 cvs 236: me->docid = docid;
237: HTRequest_setMethod (me->request, METHOD_GET);
238: HTRequest_setOutputFormat (me->request, WWW_SOURCE);
239: HTRequest_setContext (me->request, me);
1.116 cvs 240:
1.36 cvs 241: /* experimental */
242: me->read_sock = INVSOC;
243: me->write_sock = INVSOC;
244: me->except_sock = INVSOC;
1.4 cvs 245:
246: /* Update the global context */
247: HTList_appendObject (Amaya->reqlist, (void *) me);
248:
249: docid_status = GetDocIdStatus (docid, Amaya->docid_status);
250:
1.7 cvs 251: if (docid_status == NULL)
252: {
1.116 cvs 253: docid_status = (AHTDocId_Status *)
254: TtaGetMemory (sizeof (AHTDocId_Status));
1.7 cvs 255: docid_status->docid = docid;
256: docid_status->counter = 1;
257: HTList_addObject (Amaya->docid_status, (void *) docid_status);
258: }
259: else
1.4 cvs 260: docid_status->counter++;
261:
262: Amaya->open_requests++;
263:
1.74 cvs 264: #ifdef DEBUG_LIBWWW
265: fprintf (stderr, "AHTReqContext_new: Created object %p\n", me);
266: #endif
1.116 cvs 267:
1.4 cvs 268: return me;
269: }
270:
1.5 cvs 271: /*----------------------------------------------------------------------
1.17 cvs 272: AHTReqContext_delete
273: Delete an Amaya Context Object and update the global Amaya request
274: status.
1.5 cvs 275: ----------------------------------------------------------------------*/
1.4 cvs 276:
277: #ifdef __STDC__
1.15 cvs 278: boolean AHTReqContext_delete (AHTReqContext * me)
1.4 cvs 279: #else
1.15 cvs 280: boolean AHTReqContext_delete (me)
1.4 cvs 281: AHTReqContext *me;
282:
283: #endif
284: {
285: AHTDocId_Status *docid_status;
286:
1.7 cvs 287: if (me)
288: {
1.4 cvs 289:
1.74 cvs 290: #ifdef DEBUG_LIBWWW
291: fprintf (stderr, "AHTReqContext_delete: Deleting object %p\n", me);
292: #endif
293:
1.7 cvs 294: if (Amaya->reqlist)
295: HTList_removeObject (Amaya->reqlist, (void *) me);
1.4 cvs 296:
1.7 cvs 297: docid_status = GetDocIdStatus (me->docid, Amaya->docid_status);
1.4 cvs 298:
1.7 cvs 299: if (docid_status)
300: {
301: docid_status->counter--;
302:
303: if (docid_status->counter == 0)
304: {
305: HTList_removeObject (Amaya->docid_status, (void *) docid_status);
306: TtaFreeMemory ((void *) docid_status);
307: }
308: }
1.79 cvs 309: if (HTRequest_outputStream (me->request))
310: AHTFWriter_FREE (me->request->output_stream);
1.7 cvs 311: HTRequest_delete (me->request);
1.85 cvs 312:
1.89 cvs 313: if (me->output && me->output != stdout)
1.85 cvs 314: {
315: #ifdef DEBUG_LIBWWW
316: fprintf (stderr, "AHTReqContext_delete: URL is %s, closing "
317: "FILE %p\n", me->urlName, me->output);
318: #endif
319: fclose (me->output);
320: me->output = NULL;
321: }
1.79 cvs 322:
1.7 cvs 323: if (me->error_stream != (char *) NULL)
1.70 cvs 324: HT_FREE (me->error_stream);
325: # ifndef _WINDOWS
326: # ifdef WWW_XWINDOWS
1.21 cvs 327: if (me->read_xtinput_id || me->write_xtinput_id ||
328: me->except_xtinput_id)
329: RequestKillAllXtevents(me);
1.70 cvs 330: # endif /* WWW_XWINDOWS */
331: # endif /* !_WINDOWS */
1.74 cvs 332:
1.99 cvs 333: if (me->reqStatus == HT_ABORT)
334: {
335: if (me->outputfile && me->outputfile[0] != EOS)
336: {
337: TtaFileUnlink (me->outputfile);
338: me->outputfile[0] = EOS;
339: }
340: }
341:
1.74 cvs 342: if ((me->mode & AMAYA_ASYNC) || (me->mode & AMAYA_IASYNC))
343: /* for the ASYNC mode, free the memory we allocated in GetObjectWWW
344: or in PutObjectWWW */
345: {
1.79 cvs 346: if (me->urlName)
347: TtaFreeMemory (me->urlName);
348: if (me->outputfile)
349: TtaFreeMemory (me->outputfile);
1.74 cvs 350: }
1.113 cvs 351:
352: if (me->content_type)
353: TtaFreeMemory (me->content_type);
1.116 cvs 354: /* @@@ need to do this better */
355: if (me->formdata)
356: HTAssocList_delete (me->formdata);
357:
358: /* to trace bugs */
359: memset ((void *) me, 0, sizeof (AHTReqContext));
1.99 cvs 360:
1.7 cvs 361: TtaFreeMemory ((void *) me);
1.116 cvs 362:
1.7 cvs 363: Amaya->open_requests--;
1.116 cvs 364:
1.15 cvs 365: return TRUE;
1.7 cvs 366: }
1.15 cvs 367: return FALSE;
1.4 cvs 368: }
369:
370:
1.15 cvs 371: /*----------------------------------------------------------------------
1.17 cvs 372: Thread_deleteAll
373: this function deletes the whole list of active threads.
1.5 cvs 374: ----------------------------------------------------------------------*/
1.4 cvs 375: #ifdef __STDC__
376: static void Thread_deleteAll (void)
377: #else
378: static void Thread_deleteAll ()
379: #endif
380: {
1.21 cvs 381: HTList *cur;
382: AHTReqContext *me;
383: AHTDocId_Status *docid_status;
384:
1.74 cvs 385: if (Amaya && Amaya->reqlist)
386: {
387: if (Amaya->open_requests > 0)
388: #ifdef DEBUG_LIBWWW
389: fprintf (stderr, "Thread_deleteAll: Killing %d outstanding "
390: "requests\n", Amaya->open_requests);
391: #endif
392: {
393: cur = Amaya->reqlist;
394:
395: /* erase the requests */
396: while ((me = (AHTReqContext *) HTList_removeLastObject (cur)))
397: {
398: if (me->request)
399: {
1.70 cvs 400: # ifndef _WINDOWS
1.74 cvs 401: RequestKillAllXtevents (me);
1.70 cvs 402: # endif /* !_WINDOWS */
1.92 cvs 403:
404: if (me->request->net)
405: HTRequest_kill (me->request);
1.96 cvs 406: #ifndef _WINDOWS
407: AHTReqContext_delete (me);
408: #endif /* _WINDOWS */
1.74 cvs 409: }
410: } /* while */
411:
412: /* erase the docid_status entities */
413: while ((docid_status = (AHTDocId_Status *) HTList_removeLastObject ((void *) Amaya->docid_status)))
414: TtaFreeMemory ((void *) docid_status);
415:
416: } /* if */
1.84 cvs 417:
1.74 cvs 418: }
1.4 cvs 419: }
420:
1.5 cvs 421: /*----------------------------------------------------------------------
1.83 cvs 422: AHTOpen_file
423: ----------------------------------------------------------------------*/
424: #ifdef __STDC__
1.85 cvs 425: int AHTOpen_file (HTRequest * request)
1.83 cvs 426: #else
1.85 cvs 427: int AHTOpen_file (request)
1.83 cvs 428: HTRequest *request;
429:
430: #endif /* __STDC__ */
431: {
432: AHTReqContext *me; /* current request */
433:
434: me = HTRequest_context (request);
435:
1.93 cvs 436:
437: if (!me)
438: return HT_ERROR;
439:
1.83 cvs 440: #ifdef DEBUG_LIBWWW
1.116 cvs 441: fprintf(stderr, "AHTOpen_file: start for object : %p\n", me);
1.85 cvs 442: #endif /* DEBUG_LIBWWW */
443:
444: if (me->reqStatus == HT_ABORT)
445: {
446: #ifdef DEBUG_LIBWWW
447: fprintf(stderr, "AHTOpen_file: caught an abort request, skipping it\n");
1.83 cvs 448: #endif /* DEBUG_LIBWWW */
449:
1.85 cvs 450: return HT_OK;
451: }
452:
453: if (HTRequest_outputStream (me->request))
454: {
455:
456: #ifdef DEBUG_LIBWWW
457: fprintf(stderr, "AHTOpen_file: output stream already existed for url %s\n", me->urlName);
458: #endif /* DEBUG_LIBWWW */
459: return HT_OK;
460: }
461:
462: #ifdef DEBUG_LIBWWW
463: fprintf(stderr, "AHTOpen_file: opening output stream for url %s\n", me->urlName);
464: #endif /* DEBUG_LIBWWW */
465:
1.83 cvs 466: if (!(me->output) &&
467: (me->output != stdout) &&
468: #ifndef _WINDOWS
469: (me->output = fopen (me->outputfile, "w")) == NULL)
470: {
1.116 cvs 471: #else /* !_WINDOWS */
1.83 cvs 472: (me->output = fopen (me->outputfile, "wb")) == NULL)
473: {
474: #endif /* !_WINDOWS */
475:
476: me->outputfile[0] = '\0'; /* file could not be opened */
1.85 cvs 477: #ifdef DEBUG_LIBWWW
478: fprintf(stderr, "AHTOpen_file: couldn't open output stream for url %s\n", me->urlName);
479: #endif
1.83 cvs 480: TtaSetStatus (me->docid, 1,
481: TtaGetMessage (AMAYA, AM_CANNOT_CREATE_FILE),
482: me->outputfile);
483: me->reqStatus = HT_ERR;
484: return (HT_ERROR);
485: }
486:
487: HTRequest_setOutputStream (me->request,
488: AHTFWriter_new (me->request,
489: me->output, YES));
490: me->reqStatus = HT_WAITING;
491:
492: return HT_OK;
493: }
494:
495: /*----------------------------------------------------------------------
1.17 cvs 496: redirection_handler
497: this function is registered to handle permanent and temporary
498: redirections.
499: ----------------------------------------------------------------------*/
1.4 cvs 500: #ifdef __STDC__
1.7 cvs 501: static int redirection_handler (HTRequest * request, HTResponse * response, void *param, int status)
1.4 cvs 502: #else
503: static int redirection_handler (request, context, status)
504: HTRequest *request;
505: HTResponse *response;
506: void *param;
507: int status;
508:
509: #endif
510: {
511:
512: HTAnchor *new_anchor = HTResponse_redirection (response);
1.7 cvs 513: AHTReqContext *me = HTRequest_context (request);
1.4 cvs 514: HTMethod method = HTRequest_method (request);
1.98 cvs 515: char *ref;
516: char *tmp;
1.4 cvs 517:
1.7 cvs 518: if (!new_anchor)
519: {
520: if (PROT_TRACE)
521: HTTrace ("Redirection. No destination\n");
522: return HT_OK;
523: }
1.4 cvs 524:
525: /*
526: ** Only do redirect on GET and HEAD
527: */
1.7 cvs 528: if (!HTMethod_isSafe (method))
529: {
530: HTAlertCallback *prompt = HTAlert_find (HT_A_CONFIRM);
531: if (prompt)
532: {
533: if ((*prompt) (request, HT_A_CONFIRM, HT_MSG_REDIRECTION,
534: NULL, NULL, NULL) != YES)
535: return HT_ERROR;
536: }
537: }
1.4 cvs 538:
539: /*
540: ** Start new request with the redirect anchor found in the headers.
541: ** Note that we reuse the same request object which means that we must
542: ** keep this around until the redirected request has terminated. It also
543: ** allows us in an easy way to keep track of the number of redirections
544: ** so that we can detect endless loops.
545: */
1.17 cvs 546:
1.7 cvs 547: if (HTRequest_doRetry (request))
548: {
549: /* do we need to normalize the URL? */
550: if (strncmp (new_anchor->parent->address, "http:", 5))
551: {
552: /* Yes, so we use the pre-redirection anchor as a base name */
1.74 cvs 553: ref = AmayaParseUrl (new_anchor->parent->address,
554: me->urlName, AMAYA_PARSE_ALL);
1.7 cvs 555: if (ref)
556: {
1.98 cvs 557: HT_FREE (new_anchor->parent->address);
558: tmp = NULL;
559: HTSACopy (&tmp, ref);
560: new_anchor->parent->address = tmp;
561: TtaFreeMemory (ref);
1.7 cvs 562: }
1.98 cvs 563: else
564: return HT_ERROR; /* We can't redirect anymore */
1.7 cvs 565: }
566:
567: /* update the current file name */
1.116 cvs 568: TtaFreeMemory (me->urlName);
569: me->urlName = TtaStrdup (new_anchor->parent->address);
570:
1.21 cvs 571: if (strlen (new_anchor->parent->address) > (MAX_LENGTH - 2))
1.7 cvs 572: {
1.116 cvs 573: strncpy (me->urlName, new_anchor->parent->address,
574: MAX_LENGTH - 1);
1.21 cvs 575: me->urlName[MAX_LENGTH - 1] = EOS;
1.7 cvs 576: }
577: else
1.74 cvs 578: strcpy (me->urlName, new_anchor->parent->address);
1.7 cvs 579:
1.38 cvs 580: ChopURL (me->status_urlName, me->urlName);
1.116 cvs 581:
1.7 cvs 582: TtaSetStatus (me->docid, 1, TtaGetMessage (AMAYA, AM_RED_FETCHING),
1.38 cvs 583: me->status_urlName);
1.7 cvs 584:
585: /* Start request with new credentials */
1.64 cvs 586:
1.79 cvs 587: if (HTRequest_outputStream (me->request) != NULL) {
1.85 cvs 588: AHTFWriter_FREE (request->output_stream);
589: if (me->output != stdout) { /* Are we writing to a file? */
1.74 cvs 590: #ifdef DEBUG_LIBWWW
1.79 cvs 591: fprintf (stderr, "redirection_handler: New URL is %s, closing "
1.74 cvs 592: "FILE %p\n", me->urlName, me->output);
593: #endif
1.79 cvs 594: fclose (me->output);
595: me->output = NULL;
596: }
1.64 cvs 597: }
1.68 cvs 598:
1.105 cvs 599: /* reset the status */
1.116 cvs 600: me->reqStatus = HT_NEW;
1.105 cvs 601: /* clear the errors */
1.116 cvs 602: HTError_deleteAll (HTRequest_error (request));
1.105 cvs 603: HTRequest_setError (request, NULL);
1.116 cvs 604:
1.7 cvs 605: if (me->method == METHOD_PUT || me->method == METHOD_POST) /* PUT, POST etc. */
1.74 cvs 606: status = HTLoadAbsolute (me->urlName, request);
1.7 cvs 607: else
1.74 cvs 608: HTLoadAnchor (new_anchor, request);
1.7 cvs 609: }
610: else
1.68 cvs 611: {
1.74 cvs 612: HTRequest_addError (request, ERR_FATAL, NO, HTERR_MAX_REDIRECT,
613: NULL, 0, "HTRedirectFilter");
614: TtaSetStatus (me->docid, 1, TtaGetMessage (AMAYA, AM_REDIRECTIONS_LIMIT),
615: NULL);
616: if (me->error_html)
617: DocNetworkStatus[me->docid] |= AMAYA_NET_ERROR;
618: /* so that we can show the error message */
1.68 cvs 619: }
620:
1.4 cvs 621: /*
1.74 cvs 622: ** By returning HT_ERROR we make sure that this is the last handler to be
623: ** called. We do this as we don't want any other filter to delete the
624: ** request object now when we have just started a new one ourselves
625: */
1.4 cvs 626: return HT_ERROR;
627: }
628:
1.5 cvs 629: /*----------------------------------------------------------------------
1.17 cvs 630: terminate_handler
631: this function is registered to handle the result of the request
1.5 cvs 632: ----------------------------------------------------------------------*/
1.4 cvs 633: #if __STDC__
1.7 cvs 634: static int terminate_handler (HTRequest * request, HTResponse * response, void *context, int status)
1.4 cvs 635: #else
636: static int terminate_handler (request, response, context, status)
637: HTRequest *request;
638: HTResponse *response;
639: void *context;
640: int status;
1.123 cvs 641: #endif /* __STDC__ */
1.4 cvs 642: {
1.116 cvs 643: AHTReqContext *me = (AHTReqContext *) HTRequest_context (request);
644: boolean error_flag;
645: char *content_type;
646:
647: if (!me)
648: return HT_OK; /* not an Amaya request */
649:
650: if (me->reqStatus == HT_END)
651: /* we have already processed this request! */
652: return HT_OK;
653:
654: /* if Amaya was killed, treat with this request as if it were
655: issued by a Stop button event */
656:
657: if (!AmayaIsAlive ())
1.80 cvs 658: me->reqStatus = HT_ABORT;
1.74 cvs 659:
1.77 cvs 660: if (status == HT_LOADED ||
661: status == HT_CREATED ||
1.79 cvs 662: status == HT_NO_DATA ||
1.116 cvs 663: #ifdef AMAYA_WWW_CACHE
664: /* what status to use to know we're downloading from a cache? */
665: status == HT_NOT_MODIFIED ||
666: #endif /* AMAYA_WWW_CACHE */
1.79 cvs 667: me->reqStatus == HT_ABORT)
1.74 cvs 668: error_flag = FALSE;
1.13 cvs 669: else
1.74 cvs 670: error_flag = TRUE;
671:
1.4 cvs 672: /* output any errors from the server */
1.74 cvs 673:
1.77 cvs 674: /*
1.74 cvs 675: ** me->output = output file which will receive an html file
676: ** me->error_html = yes, output HTML errors in the screen
677: ** request->error_stack == if there are any errors, they will be here
678: ** me->error_stream_size If it's != 0 means an error message has already
679: ** been written to the stack
680: */
681:
1.4 cvs 682: /* First, we verify if there are any errors and if they are not
1.17 cvs 683: ** yet written to the error stack. If no, then let's try to write them
684: ** ourselves
685: */
1.74 cvs 686:
687: #ifdef DEBUG_LIBWWW
688: fprintf (stderr, "terminate_handler: URL is "
689: "%s, closing FILE %p status is %d\n", me->urlName, me->output,
690: status);
1.69 cvs 691: #endif
1.74 cvs 692:
1.69 cvs 693: if (me->output && me->output != stdout)
694: {
1.74 cvs 695: /* we are writing to a file */
696: if (me->reqStatus != HT_ABORT)
697: { /* if the request was not aborted and */
1.80 cvs 698: if (error_flag &&
699: me->error_html == TRUE)
700: /* there were some errors and we want to print them */
701: {
702: if (me->error_stream_size == 0)/* and the stream is empty */
703: AHTError_MemPrint (request); /* copy errors from
1.74 cvs 704: **the error stack
1.77 cvs 705: ** into the error stream */
1.80 cvs 706: if (me->error_stream)
707: { /* if the stream is non-empty */
708: fprintf (me->output, me->error_stream);/* output the errors */
1.85 cvs 709: /* Clear the error context, so that we can deal with
710: this answer as if it were a normal reply */
711: HTError_deleteAll( HTRequest_error (request));
712: HTRequest_setError (request, NULL);
713: error_flag = 0;
1.74 cvs 714: }
715: } /* if error_stack */
1.85 cvs 716: }
717:
718: /* if != HT_ABORT */
719:
720: #ifdef DEBUG_LIBWWW
721: fprintf (stderr, "terminate_handler: URL is %s, closing "
722: "FILE %p\n", me->urlName, me->output);
723: #endif
1.74 cvs 724: fclose (me->output);
725: me->output = NULL;
1.69 cvs 726: }
1.80 cvs 727:
728: if (error_flag)
729: me->reqStatus = HT_ERR;
730: else if (me->reqStatus != HT_ABORT)
731: me->reqStatus = HT_END;
1.116 cvs 732:
733: /* copy the content_type */
734: content_type = request->anchor->content_type->name;
1.114 cvs 735: if (content_type && content_type [0] != EOS)
1.88 cvs 736: {
1.114 cvs 737: /* libwww gives www/unknown when it gets an error. As this is
738: an HTML test, we force the type to text/html */
739: if (!strcmp (content_type, "www/unknown"))
740: me->content_type = TtaStrdup ("text/html");
741: else
742: me->content_type = TtaStrdup (content_type);
743:
744: /* Content-Type can be specified by an httpd server's admin. To be on
745: the safe side, we normalize its case */
746: ConvertToLowerCase (me->content_type);
747:
1.88 cvs 748: #ifdef DEBUG_LIBWWW
749: fprintf (stderr, "content type is: %s\n", me->content_type);
750: #endif /* DEBUG_LIBWWW */
1.114 cvs 751: }
752:
1.115 cvs 753: /* to avoid a hangup while downloading css files */
754: if (AmayaAlive && (me->mode & AMAYA_LOAD_CSS))
1.116 cvs 755: TtaSetStatus (me->docid, 1,
756: TtaGetMessage (AMAYA, AM_ELEMENT_LOADED),
757: me->status_urlName);
758:
759: /* don't remove or Xt will hang up during the PUT */
760: if (AmayaIsAlive () && ((me->method == METHOD_POST) ||
761: (me->method == METHOD_PUT)))
1.7 cvs 762: {
1.80 cvs 763: PrintTerminateStatus (me, status);
1.116 cvs 764:
1.80 cvs 765: }
1.114 cvs 766:
1.111 cvs 767: ProcessTerminateRequest (request, response, context, status);
1.116 cvs 768:
1.111 cvs 769: return HT_OK;
1.4 cvs 770: }
771:
1.5 cvs 772: /*----------------------------------------------------------------------
1.17 cvs 773: AHTLoadTerminate_handler
1.74 cvs 774: this is an application "AFTER" Callback. It's called by the library
775: when a request has ended, so that we can setup the correct status.
1.5 cvs 776: ----------------------------------------------------------------------*/
1.4 cvs 777:
778: #ifdef __STDC__
1.111 cvs 779: int AHTLoadTerminate_handler (HTRequest * request, HTResponse * response, void *param, int status)
1.4 cvs 780: #else
1.111 cvs 781: int AHTLoadTerminate_handler (request, response, param, status)
1.4 cvs 782: HTRequest *request;
783: HTResponse *response;
784: void *param;
785: int status;
1.69 cvs 786:
1.4 cvs 787: #endif
788: {
1.116 cvs 789:
790: /** @@@@ use this with printstatus ?? */
791:
1.4 cvs 792: AHTReqContext *me = HTRequest_context (request);
793: HTAlertCallback *cbf;
794: AHTDocId_Status *docid_status;
795:
1.123 cvs 796: #ifdef _WINDOWS
797: /* @@@ I have problems with the trace variables under windows */
1.124 ! cvs 798: return HT_OK;
1.123 cvs 799: #endif /* _WINDOWS */
800:
1.7 cvs 801: switch (status)
1.116 cvs 802: {
803: case HT_LOADED:
804: if (PROT_TRACE)
805: HTTrace ("Load End.... OK: `%s\' has been accessed\n",
806: me->status_urlName);
1.4 cvs 807:
1.116 cvs 808: docid_status = GetDocIdStatus (me->docid,
809: Amaya->docid_status);
1.7 cvs 810:
1.116 cvs 811: if (docid_status != NULL && docid_status->counter > 1)
812: TtaSetStatus (me->docid, 1,
813: TtaGetMessage (AMAYA, AM_ELEMENT_LOADED),
1.74 cvs 814: me->status_urlName);
1.7 cvs 815: break;
1.116 cvs 816:
817: case HT_NO_DATA:
818: if (PROT_TRACE)
819: HTTrace ("Load End.... OK BUT NO DATA: `%s\'\n",
820: me->status_urlName);
821: TtaSetStatus (me->docid, 1,
822: TtaGetMessage (AMAYA, AM_LOADED_NO_DATA),
823: me->status_urlName);
824: break;
825:
826: case HT_INTERRUPTED:
827: if (PROT_TRACE)
828: HTTrace ("Load End.... INTERRUPTED: `%s\'\n",
829: me->status_urlName);
830: TtaSetStatus (me->docid, 1,
831: TtaGetMessage (AMAYA, AM_LOAD_ABORT),
832: NULL);
833: break;
1.7 cvs 834:
1.116 cvs 835: case HT_RETRY:
836: if (PROT_TRACE)
837: HTTrace ("Load End.... NOT AVAILABLE, RETRY AT %ld\n",
838: HTResponse_retryTime (response));
839: TtaSetStatus (me->docid, 1,
840: TtaGetMessage (AMAYA, AM_NOT_AVAILABLE_RETRY),
841: me->status_urlName);
842: break;
1.7 cvs 843:
1.116 cvs 844: case HT_ERROR:
845: cbf = HTAlert_find (HT_A_MESSAGE);
846: if (cbf)
847: (*cbf) (request, HT_A_MESSAGE, HT_MSG_NULL, NULL,
848: HTRequest_error (request), NULL);
849: break;
850:
851: if (PROT_TRACE)
852: HTTrace ("Load End.... ERROR: Can't access `%s\'\n",
853: me->status_urlName ? me->status_urlName :"<UNKNOWN>");
854: TtaSetStatus (me->docid, 1,
855: TtaGetMessage (AMAYA, AM_CANNOT_LOAD),
856: me->status_urlName ? me->status_urlName : "<UNKNOWN>");
857: break;
858: default:
859: if (PROT_TRACE)
860: HTTrace ("Load End.... UNKNOWN RETURN CODE %d\n", status);
861: break;
862: }
863:
864: return HT_OK;
865: }
1.7 cvs 866:
1.116 cvs 867: #ifdef DEBUG_LIBWWW
868: static int LineTrace (const char * fmt, va_list pArgs)
869: {
870: return (vfprintf(stderr, fmt, pArgs));
1.4 cvs 871: }
1.116 cvs 872: #endif DEBUG_LIBWWW
1.4 cvs 873:
1.27 cvs 874: /*----------------------------------------------------------------------
875: AHTAcceptTypesInit
1.74 cvs 876: This function prepares the Accept header used by Amaya during
877: the HTTP content negotiation phase
1.27 cvs 878: ----------------------------------------------------------------------*/
879: #ifdef __STDC__
880: static void AHTAcceptTypesInit (HTList *c)
881: #else /* __STDC__ */
882: static void AHTAcceptTypesInit (c)
883: HTList *c;
884: #endif /* __STDC__ */
885: {
886: if (c == (HTList *) NULL)
887: return;
888:
889: /* define here all the mime types that Amaya can accept */
890:
1.74 cvs 891: HTConversion_add (c, "image/png", "www/present",
892: HTThroughLine, 1.0, 0.0, 0.0);
893: HTConversion_add (c, "image/jpeg", "www/present",
894: HTThroughLine, 1.0, 0.0, 0.0);
895: HTConversion_add (c, "image/gif", "www/present",
896: HTThroughLine, 1.0, 0.0, 0.0);
897: HTConversion_add (c, "image/xbm", "www/present",
898: HTThroughLine, 1.0, 0.0, 0.0);
899: HTConversion_add (c, "image/xpm", "www/present",
900: HTThroughLine, 1.0, 0.0, 0.0);
901: HTConversion_add (c, "application/postscript",
902: "www/present", HTThroughLine, 1.0, 0.0, 0.0);
1.4 cvs 903:
1.27 cvs 904: /* Define here the equivalences between MIME types and file extensions for
905: the types that Amaya can display */
906:
907: /* Register the default set of file suffix bindings */
908: HTFileInit ();
909:
910: /* Don't do any case distinction */
911: HTBind_caseSensitive (FALSE);
912: }
1.4 cvs 913:
1.5 cvs 914: /*----------------------------------------------------------------------
1.17 cvs 915: AHTConverterInit
916: Bindings between a source media type and a destination media type
917: (conversion).
1.5 cvs 918: ----------------------------------------------------------------------*/
1.15 cvs 919: #ifdef __STDC__
920: static void AHTConverterInit (HTList *c)
921: #else /* __STDC__ */
922: static void AHTConverterInit (c)
923: HTList *c;
924: #endif /* __STDC__ */
1.4 cvs 925: {
926:
927: /* Handler for custom http error messages */
1.7 cvs 928: HTConversion_add (c, "*/*", "www/debug", AHTMemConverter, 1.0, 0.0, 0.0);
1.4 cvs 929:
930: /*
931: ** These are converters that converts to something other than www/present,
932: ** that is not directly outputting someting to the user on the screen
933: */
934:
1.116 cvs 935: HTConversion_add (c, "message/rfc822", "*/*", HTMIMEConvert,
936: 1.0, 0.0, 0.0);
1.4 cvs 937: HTConversion_add (c, "message/x-rfc822-foot", "*/*", HTMIMEFooter,
938: 1.0, 0.0, 0.0);
939: HTConversion_add (c, "message/x-rfc822-head", "*/*", HTMIMEHeader,
940: 1.0, 0.0, 0.0);
1.116 cvs 941: HTConversion_add(c,"message/x-rfc822-cont", "*/*", HTMIMEContinue,
942: 1.0, 0.0, 0.0);
943: HTConversion_add(c,"message/x-rfc822-partial","*/*", HTMIMEPartial,
944: 1.0, 0.0, 0.0);
1.4 cvs 945: HTConversion_add (c, "multipart/*", "*/*", HTBoundary,
946: 1.0, 0.0, 0.0);
947: HTConversion_add (c, "text/plain", "text/html", HTPlainToHTML,
948: 1.0, 0.0, 0.0);
949:
950: /*
1.116 cvs 951: ** The following conversions are converting ASCII output from various
952: ** protocols to HTML objects.
953: */
1.4 cvs 954: HTConversion_add (c, "text/x-http", "*/*", HTTPStatus_new,
955: 1.0, 0.0, 0.0);
956:
957: /*
1.116 cvs 958: ** We also register a special content type guess stream that can figure out
959: ** the content type by reading the first bytes of the stream
960: */
1.4 cvs 961: HTConversion_add (c, "www/unknown", "*/*", HTGuess_new,
962: 1.0, 0.0, 0.0);
963:
1.116 cvs 964: #ifdef AMAYA_WWW_CACHE
1.4 cvs 965: /*
1.116 cvs 966: ** Register a persistent cache stream which can save an object to local
967: ** file
968: */
1.4 cvs 969: HTConversion_add (c, "www/cache", "*/*", HTCacheWriter,
970: 1.0, 0.0, 0.0);
1.116 cvs 971: HTConversion_add(c,"www/cache-append", "*/*", HTCacheAppend,
972: 1.0, 0.0, 0.0);
973: #endif AMAYA_WWW_CACHE
1.4 cvs 974:
975: /*
1.116 cvs 976: ** This dumps all other formats to local disk without any further
977: ** action taken
978: */
1.4 cvs 979: HTConversion_add (c, "*/*", "www/present", HTSaveLocally,
980: 0.3, 0.0, 0.0);
1.116 cvs 981:
1.4 cvs 982: }
983:
1.27 cvs 984:
1.15 cvs 985: /*----------------------------------------------------------------------
1.17 cvs 986: AHTProtocolInit
987: Registers all amaya supported protocols.
1.15 cvs 988: ----------------------------------------------------------------------*/
1.4 cvs 989: static void AHTProtocolInit (void)
990: {
1.116 cvs 991: char *strptr;
1.4 cvs 992:
1.116 cvs 993: /*
994: NB. Preemptive == YES means Blocking requests
995: Non-preemptive == NO means Non-blocking requests
996: */
997: HTTransport_add("tcp", HT_TP_SINGLE, HTReader_new, HTWriter_new);
998: HTTransport_add("buffered_tcp", HT_TP_SINGLE, HTReader_new,
999: HTBufferWriter_new);
1000: HTProtocol_add ("http", "buffered_tcp", HTTP_PORT, NO, HTLoadHTTP, NULL);
1001: HTProtocol_add ("file", "local", 0, NO, HTLoadFile, NULL);
1002: #ifdef AMAYA_WWW_CACHE
1003: HTProtocol_add("cache", "local", 0, YES, HTLoadCache, NULL);
1004: #endif /* AMAYA_WWW_CACHE */
1.103 cvs 1005: #if 0 /* experimental code */
1.116 cvs 1006: HTProtocol_add ("ftp", "tcp", FTP_PORT, NO, HTLoadFTP, NULL);
1.17 cvs 1007: #endif
1.116 cvs 1008:
1009: /* initialize pipelining */
1.121 cvs 1010: strptr = (char *) TtaGetEnvString ("ENABLE_PIPELINING");
1.116 cvs 1011: if (strptr && *strptr && strcasecmp (strptr,"yes" ))
1012: HTTP_setConnectionMode (HTTP_11_NO_PIPELINING);
1.4 cvs 1013: }
1014:
1.15 cvs 1015: /*----------------------------------------------------------------------
1.17 cvs 1016: AHTNetInit
1017: Reegisters "before" and "after" request filters.
1.15 cvs 1018: ----------------------------------------------------------------------*/
1.4 cvs 1019: static void AHTNetInit (void)
1020: {
1021:
1022: /* Register BEFORE filters
1.74 cvs 1023: ** The BEFORE filters handle proxies, caches, rule files etc.
1024: ** The filters are called in the order by which the are registered
1025: ** Not done automaticly - may be done by application!
1026: */
1.4 cvs 1027:
1.116 cvs 1028: #ifdef AMAYA_WWW_CACHE
1029: HTNet_addBefore (HTCacheFilter, "http://*", NULL, HT_FILTER_MIDDLE);
1030: #endif /* AMAYA_WWW_CACHE */
1031: HTNet_addBefore (HTCredentialsFilter, "http://*", NULL, HT_FILTER_LATE);
1032: HTNet_addBefore (HTProxyFilter, NULL, NULL, HT_FILTER_LATE);
1.85 cvs 1033: HTHost_setActivateRequestCallback (AHTOpen_file);
1.4 cvs 1034:
1035: /* register AFTER filters
1.74 cvs 1036: ** The AFTER filters handle error messages, logging, redirection,
1037: ** authentication etc.
1038: ** The filters are called in the order by which the are registered
1039: ** Not done automaticly - may be done by application!
1040: */
1.4 cvs 1041:
1.116 cvs 1042: HTNet_addAfter (HTAuthFilter, "http://*", NULL, HT_NO_ACCESS,
1043: HT_FILTER_MIDDLE);
1044: HTNet_addAfter(HTAuthFilter, "http://*", NULL, HT_REAUTH,
1045: HT_FILTER_MIDDLE);
1046: HTNet_addAfter (redirection_handler, "http://*", NULL, HT_PERM_REDIRECT,
1047: HT_FILTER_MIDDLE);
1048: HTNet_addAfter (redirection_handler, "http://*", NULL, HT_FOUND,
1049: HT_FILTER_MIDDLE);
1050: HTNet_addAfter (redirection_handler, "http://*", NULL, HT_SEE_OTHER,
1051: HT_FILTER_MIDDLE);
1052: HTNet_addAfter (redirection_handler, "http://*", NULL, HT_TEMP_REDIRECT,
1053: HT_FILTER_MIDDLE);
1054: HTNet_addAfter (HTUseProxyFilter, "http://*", NULL, HT_USE_PROXY,
1055: HT_FILTER_MIDDLE);
1056: #ifdef AMAYA_WWW_CACHE
1057: HTNet_addAfter (HTCacheUpdateFilter, "http://*", NULL, HT_NOT_MODIFIED,
1058: HT_FILTER_MIDDLE);
1059: #endif /* AMAYA_WWW_CACHE */
1.111 cvs 1060: #ifndef _WINDOWS
1.116 cvs 1061: HTNet_addAfter (AHTLoadTerminate_handler, NULL, NULL, HT_ALL,
1062: HT_FILTER_LAST);
1.111 cvs 1063: #endif /* !_WINDOWS */
1.116 cvs 1064: /**** for later ?? ****/
1065: /* HTNet_addAfter(HTInfoFilter, NULL, NULL, HT_ALL, HT_FILTER_LATE); */
1.51 cvs 1066: /* handles all errors */
1.116 cvs 1067: HTNet_addAfter (terminate_handler, NULL, NULL, HT_ALL, HT_FILTER_LAST);
1.4 cvs 1068: }
1069:
1.15 cvs 1070: /*----------------------------------------------------------------------
1.17 cvs 1071: AHTAlertInit
1072: Register alert messages and their callbacks.
1.15 cvs 1073: ----------------------------------------------------------------------*/
1074: #ifdef __STDC__
1075: static void AHTAlertInit (void)
1076: #else
1077: static void AHTAlertInit ()
1078: #endif
1079: {
1080: HTAlert_add (AHTProgress, HT_A_PROGRESS);
1.120 cvs 1081: #ifdef __WINDOWS
1.70 cvs 1082: HTAlert_add ((HTAlertCallback *) WIN_Activate_Request, HT_PROG_CONNECT);
1.116 cvs 1083: #endif /* _WINDOWS */
1.15 cvs 1084: HTAlert_add (AHTError_print, HT_A_MESSAGE);
1.48 cvs 1085: HTError_setShow (~((unsigned int) 0 ) & ~((unsigned int) HT_ERR_SHOW_DEBUG)); /* process all messages except debug ones*/
1.15 cvs 1086: HTAlert_add (AHTConfirm, HT_A_CONFIRM);
1087: HTAlert_add (AHTPrompt, HT_A_PROMPT);
1088: HTAlert_add (AHTPromptPassword, HT_A_SECRET);
1089: HTAlert_add (AHTPromptUsernameAndPassword, HT_A_USER_PW);
1.116 cvs 1090: #ifdef AMAYA_WWW_CACHE
1.117 cvs 1091: /***
1092: HTAlert_add (AHTConfirm, HT_MSG_CACHE_LOCK);
1093: ***/
1.116 cvs 1094: #endif /* AMAYA_WWW_CACHE */
1095: }
1096:
1.120 cvs 1097: #ifndef _WINDOWS
1098: /* @@@ needs specific win functions */
1.118 cvs 1099: #ifdef AMAYA_WWW_CACHE
1100: /*----------------------------------------------------------------------
1101: CleanCache
1102: Clears an existing cache directory
1103: ----------------------------------------------------------------------*/
1104: #ifdef __STDC__
1105: void CleanCache (char *dirname)
1106: #else
1107: void CleanCache (dirname)
1108: char *dirname;
1109: #endif /* __STDC__ */
1110: {
1111: DIR *dp;
1112: struct stat st;
1113: #ifdef HAVE_DIRENT_H
1114: struct dirent *d;
1115: #else
1116: struct direct *d;
1117: #endif /* HAVE_DIRENT_H */
1118: char filename [BUFSIZ+1];
1119:
1120: if ((dp = opendir (dirname)) == NULL)
1121: {
1122: /* @@@ we couldn't open the directory ... we need some msg */
1123: perror (dirname);
1124: exit;
1125: }
1126:
1127: while ((d = readdir (dp)) != NULL)
1128: {
1129: #ifndef _WINDOWS
1130: /* skip the UNIX . and .. links */
1131: if (!strcmp (d->d_name, "..")
1132: || !strcmp (d->d_name, "."))
1133: continue;
1134: #endif _WINDOWS
1135:
1136: sprintf (filename, "%s%s", dirname, d->d_name);
1137: if (lstat (filename, &st) < 0 )
1138: {
1139: /* @@2 need some error message */
1140: perror (filename);
1141: continue;
1142: }
1143:
1144: switch (st.st_mode & S_IFMT)
1145: {
1146: case S_IFDIR:
1147: /* if we find a directory, we erase it, recursively */
1148: strcat (filename, "/");
1149: CleanCache (filename);
1150: break;
1151: case S_IFLNK:
1152: /* skip any links we find */
1153: continue;
1154: break;
1155: default:
1156: /* erase the filename */
1157: TtaFileUnlink (filename);
1158: break;
1159: }
1160: }
1161: closedir (dp);
1162: /* erase the directory */
1163: rmdir (dirname);
1164: }
1165: #endif /* AMAYA_WWW_CACHE */
1.120 cvs 1166: #endif /* !_WINDOWS */
1.118 cvs 1167:
1.116 cvs 1168: /*----------------------------------------------------------------------
1169: CacheInit
1170: Reads the cache settings from the thot.ini file.
1171: ----------------------------------------------------------------------*/
1.118 cvs 1172: #ifdef __STDC__
1.116 cvs 1173: static void CacheInit (void)
1.118 cvs 1174: #else
1175: static void Cacheinit ()
1176: #endif
1177:
1.116 cvs 1178: {
1179: #ifndef AMAYA_WWW_CACHE
1180: HTCacheMode_setEnabled (NO);
1181:
1182: #else /* AMAYA_WWW_CACHE */
1183: char *strptr;
1184: int cache_size;
1185: char *cache_dir = NULL;
1186: boolean cache;
1187:
1188: /* activate cache? */
1189: strptr = (char *) TtaGetEnvString ("ENABLE_CACHE");
1190: if (strptr && *strptr && strcasecmp (strptr,"yes" ))
1191: cache = NO;
1192: else
1193: cache = YES;
1194:
1195: /* get the cache dir (or use a default one) */
1196: strptr = (char *) TtaGetEnvString ("CACHE_DIR");
1197: if (strptr && *strptr)
1198: {
1199: cache_dir = TtaGetMemory (strlen (strptr) + strlen (CACHE_DIR_NAME) + 1);
1200: strcpy (cache_dir, strptr);
1201: }
1202: else
1203: {
1.122 cvs 1204: cache_dir = TtaGetMemory (strlen (TempFileDirectory)
1.116 cvs 1205: + strlen (CACHE_DIR_NAME) + 1);
1.122 cvs 1206: strcpy (cache_dir, TempFileDirectory);
1.116 cvs 1207: }
1208: strcat (cache_dir, CACHE_DIR_NAME);
1209:
1210: /* get the cache size (or use a default one) */
1211: strptr = (char *) TtaGetEnvString ("CACHE_SIZE");
1212: if (strptr && *strptr)
1213: cache_size = atoi (strptr);
1214: else
1215: cache_size = DEFAULT_CACHE_SIZE;
1216:
1217: if (cache)
1218: {
1219: /* how to remove the lock? force remove it? */
1220: /* @@@ugly hack to remove the .lock file ... */
1221: /* we would need something to remove the index, clear
1222: the directory, etc. attention to dir-sep */
1223: strptr = TtaGetMemory (strlen (cache_dir) + 20);
1224: strcpy (strptr, cache_dir);
1225: #ifndef _WINDOWS
1226: strcat (strptr, "/.lock");
1227: #else
1.123 cvs 1228: strcat (strptr, "\\.lock");
1.116 cvs 1229: #endif /* !_WINDOWS */
1230: if (TtaFileExist (strptr))
1231: {
1232: /* remove the lock and clean the cache (the clean cache will remove
1233: all, making the following call unnecessary */
1.118 cvs 1234: strcpy (strptr, cache_dir);
1235: /* @@@ add DIRSEP */
1236: strcat (strptr, "/");
1.120 cvs 1237: #ifndef _WINDOWS
1.118 cvs 1238: CleanCache (strptr);
1.120 cvs 1239: #endif /* !_WINDOWS */
1.116 cvs 1240: }
1241: TtaFreeMemory (strptr);
1242:
1243: /* store this in our libwww context */
1244: HTCacheInit (cache_dir, cache_size);
1245: HTCacheMode_setExpires(HT_EXPIRES_AUTO);
1246: }
1247: else
1248: HTCacheMode_setEnabled (NO);
1249:
1250: if (cache_dir)
1251: TtaFreeMemory (cache_dir);
1252: #endif /* AMAYA_WWW_CACHE */
1.15 cvs 1253: }
1254:
1255: /*----------------------------------------------------------------------
1.97 cvs 1256: ProxyInit
1257: Reads any proxies settings which may be declared as environmental
1258: variables or in the thot.ini file. The former overrides the latter.
1259: ----------------------------------------------------------------------*/
1.118 cvs 1260: #ifdef __STDC__
1.97 cvs 1261: static void ProxyInit (void)
1.118 cvs 1262: #else
1263: static void ProxyInit ()
1264: #endif /* __STDC__ */
1.97 cvs 1265: {
1266: char *strptr;
1267: char *str = NULL;
1268: char *name;
1269:
1270: /* get the proxy settings from the thot.ini file */
1271: strptr = (char *) TtaGetEnvString ("HTTP_PROXY");
1272: if (strptr && *strptr)
1273: HTProxy_add ("http", strptr);
1274: /* get the no_proxy settings from the thot.ini file */
1275: strptr = (char *) TtaGetEnvString ("NO_PROXY");
1276: if (strptr && *strptr)
1277: {
1278: str = TtaStrdup (strptr); /* Get copy we can mutilate */
1279: strptr = str;
1280: while ((name = HTNextField (&strptr)) != NULL) {
1281: char *portstr = strchr (name, ':');
1282: unsigned port=0;
1283: if (portstr) {
1284: *portstr++ = '\0';
1.116 cvs 1285: if (*portstr) port = (unsigned) atoi (portstr);
1.97 cvs 1286: }
1287: /* Register it for all access methods */
1288: HTNoProxy_add (name, NULL, port);
1289: }
1290: TtaFreeMemory (str);
1291: }
1292:
1293: /* use libw3's routine to get all proxy settings from the environment */
1294: HTProxy_getEnvVar ();
1295: }
1296:
1297:
1298: /*----------------------------------------------------------------------
1.17 cvs 1299: AHTProfile_newAmaya
1300: creates the Amaya client profile for libwww.
1.15 cvs 1301: ----------------------------------------------------------------------*/
1302: #ifdef __STDC__
1303: static void AHTProfile_newAmaya (char *AppName, char *AppVersion)
1304: #else /* __STDC__ */
1305: static void AHTProfile_newAmaya (AppName, AppVersion)
1306: char *AppName;
1307: char *AppVersion;
1308: #endif /* __STDC__ */
1.4 cvs 1309: {
1310: /* If the Library is not already initialized then do it */
1311: if (!HTLib_isInitialized ())
1312: HTLibInit (AppName, AppVersion);
1313:
1314: if (!converters)
1315: converters = HTList_new ();
1.27 cvs 1316: if (!acceptTypes)
1317: acceptTypes = HTList_new ();
1.4 cvs 1318: if (!encodings)
1319: encodings = HTList_new ();
1320:
1321: /* Register the default set of transport protocols */
1322: HTTransportInit ();
1323:
1324: /* Register the default set of application protocol modules */
1325: AHTProtocolInit ();
1326:
1.116 cvs 1327: /* Register the default set of messages and dialog functions */
1328: AHTAlertInit ();
1329: HTAlert_setInteractive (YES);
1330:
1331: #ifdef AMAYA_WWW_CACHE
1332: /* Enable the persistent cache */
1333: CacheInit ();
1334: #else
1335: HTCacheMode_setEnabled (NO);
1336: #endif /* AMAYA_WWW_CACHE */
1.4 cvs 1337:
1338: /* Register the default set of BEFORE and AFTER filters */
1339: AHTNetInit ();
1340:
1341: /* Set up the default set of Authentication schemes */
1342: HTAAInit ();
1343:
1.97 cvs 1344: /* Get any proxy settings */
1345: ProxyInit ();
1.4 cvs 1346:
1347: /* Register the default set of converters */
1348: AHTConverterInit (converters);
1.27 cvs 1349: AHTAcceptTypesInit (acceptTypes);
1.4 cvs 1350: HTFormat_setConversion (converters);
1351:
1352: /* Register the default set of transfer encoders and decoders */
1.116 cvs 1353: HTTransferEncoderInit (encodings); /* chunks ??? */
1.4 cvs 1354: HTFormat_setTransferCoding (encodings);
1355:
1356: /* Register the default set of MIME header parsers */
1.74 cvs 1357: HTMIMEInit (); /* must be called again for language selector */
1.4 cvs 1358:
1359: /* Register the default set of Icons for directory listings */
1.27 cvs 1360: /*HTIconInit(NULL); *//* experimental */
1.4 cvs 1361:
1362: }
1363:
1.5 cvs 1364: /*----------------------------------------------------------------------
1.17 cvs 1365: AHTProfile_delete
1366: deletes the Amaya client profile.
1.5 cvs 1367: ----------------------------------------------------------------------*/
1.4 cvs 1368: #ifdef __STDC__
1369: static void AHTProfile_delete (void)
1370: #else
1371: static void AHTProfile_delete ()
1.7 cvs 1372: #endif /* __STDC__ */
1.4 cvs 1373: {
1.22 cvs 1374:
1375: /* free the Amaya global context */
1.74 cvs 1376: if (!converters)
1377: HTConversion_deleteAll (converters);
1378: if (!acceptTypes)
1379: HTConversion_deleteAll (acceptTypes);
1380: if (!encodings)
1381: HTCoding_deleteAll (encodings);
1382:
1383: HTList_delete (Amaya->docid_status);
1384: HTList_delete (Amaya->reqlist);
1385: TtaFreeMemory (Amaya);
1386: {
1.61 cvs 1387:
1.74 cvs 1388: if (HTLib_isInitialized ())
1389:
1.120 cvs 1390: #ifdef _WINDOWS
1.61 cvs 1391: HTEventTerminate ();
1.120 cvs 1392: #endif _WINDOWS;
1.74 cvs 1393:
1394: /* Clean up the persistent cache (if any) */
1.116 cvs 1395: #ifdef AMAYA_WWW_CACHE
1396: HTCacheTerminate ();
1397: #endif /* AMAYA_WWW_CACHE */
1.74 cvs 1398:
1399: /* Clean up all the global preferences */
1400: HTFormat_deleteAll ();
1401:
1402: /* Terminate libwww */
1403: HTLibTerminate ();
1404: }
1.4 cvs 1405: }
1406:
1.5 cvs 1407: /*----------------------------------------------------------------------
1.116 cvs 1408: AmayacontextInit
1409: initializes an internal Amaya context for our libwww interface
1410: ----------------------------------------------------------------------*/
1411: #ifdef __STDC__
1412: static void AmayaContextInit ()
1413: #else
1414: static void AmayaContextInit ()
1415: #endif
1416:
1417: {
1418: AmayaAlive = TRUE;
1419: /* Initialization of the global context */
1420: Amaya = (AmayaContext *) TtaGetMemory (sizeof (AmayaContext));
1421: Amaya->reqlist = HTList_new ();
1422: Amaya->docid_status = HTList_new ();
1423: Amaya->open_requests = 0;
1424: }
1425:
1426: /*----------------------------------------------------------------------
1.17 cvs 1427: QueryInit
1428: initializes the libwww interface
1.5 cvs 1429: ----------------------------------------------------------------------*/
1.4 cvs 1430: #ifdef __STDC__
1431: void QueryInit ()
1432: #else
1433: void QueryInit ()
1434: #endif
1435: {
1436:
1.116 cvs 1437: AmayaContextInit ();
1438:
1.4 cvs 1439: AHTProfile_newAmaya (HTAppName, HTAppVersion);
1.116 cvs 1440:
1.69 cvs 1441: /* New AHTBridge stuff */
1.4 cvs 1442:
1.116 cvs 1443: #ifdef _WINDOWS
1.120 cvs 1444: /*** AHTEventInit (); this was the call to my AHTEvent module HTEvtLst today***/
1445: HTEventInit;
1.116 cvs 1446: #endif /* _WINDOWS */
1.72 cvs 1447:
1.123 cvs 1448: #ifndef _WINDOWS
1.116 cvs 1449: HTEvent_setRegisterCallback ((void *) AHTEvent_register);
1450: HTEvent_setUnregisterCallback ((void *) AHTEvent_unregister);
1.120 cvs 1451: HTTimer_registerSetTimerCallback ((void *) AMAYA_SetTimer);
1452: HTTimer_registerDeleteTimerCallback ((void *) AMAYA_DeleteTimer);
1.116 cvs 1453: #endif /* !_WINDOWS */
1454:
1455: #ifdef AMAYA_WWW_CACHE
1456: /***
1457: WWW_TraceFlag = CACHE_TRACE;
1458: ***/
1459: #endif
1.72 cvs 1460:
1.74 cvs 1461: #ifdef DEBUG_LIBWWW
1.116 cvs 1462: /* forwards error messages to our own function */
1463: WWW_TraceFlag = THD_TRACE;
1464: HTTrace_setCallback(LineTrace);
1.74 cvs 1465: #endif
1.4 cvs 1466:
1467: /* Trace activation (for debugging) */
1.7 cvs 1468: /*
1.116 cvs 1469: WWW_TraceFlag = SHOW_CORE_TRACE | SHOW_THREAD_TRACE | PROT_TRACE;
1470:
1.4 cvs 1471: WWW_TraceFlag = SHOW_APP_TRACE | SHOW_UTIL_TRACE |
1472: SHOW_BIND_TRACE | SHOW_THREAD_TRACE |
1473: SHOW_STREAM_TRACE | SHOW_PROTOCOL_TRACE |
1474: SHOW_URI_TRACE | SHOW_AUTH_TRACE | SHOW_ANCHOR_TRACE |
1475: SHOW_CORE_TRACE;
1476:
1.7 cvs 1477: */
1.4 cvs 1478:
1479: /***
1480: WWW_TraceFlag = SHOW_CORE_TRACE | SHOW_AUTH_TRACE | SHOW_ANCHOR_TRACE |
1481: SHOW_PROTOCOL_TRACE| SHOW_APP_TRACE | SHOW_UTIL_TRACE;
1482: ***/
1483:
1484: /* Setting up other user interfaces */
1485:
1486: /* Setting up different network parameters */
1.17 cvs 1487: /* Maximum number of simultaneous open sockets */
1.4 cvs 1488: HTNet_setMaxSocket (8);
1.75 cvs 1489: /* different network services timeouts */
1.109 cvs 1490: HTDNS_setTimeout (60);
1.120 cvs 1491: #ifdef __WINDOWS
1.75 cvs 1492: /* under windows, the libwww persistent socket handling has
1493: ** some bugs. The following line inhibits idle socket reusal.
1494: ** this is a bit slower, but avoids crashes and gives us time
1495: ** to distribute Amaya before having to patch up libwww.
1496: */
1.76 cvs 1497: HTHost_setPersistTimeout (-1L);
1.75 cvs 1498: #else
1.76 cvs 1499: HTHost_setPersistTimeout (60L);
1.75 cvs 1500: #endif /* _WINDOWS */
1.116 cvs 1501: HTHost_setEventTimeout (1000);
1.75 cvs 1502:
1.4 cvs 1503: #ifdef CATCH_SIG
1.18 cvs 1504: signal (SIGPIPE, SIG_IGN);
1.4 cvs 1505: #endif
1.15 cvs 1506: }
1507:
1.69 cvs 1508: #ifndef _WINDOWS
1.15 cvs 1509: /*----------------------------------------------------------------------
1.17 cvs 1510: LoopForStop
1511: a copy of the Thop event loop so we can handle the stop button.
1.69 cvs 1512: Not useful for windows code (Ramzi).
1.15 cvs 1513: ----------------------------------------------------------------------*/
1514: #ifdef __STDC__
1515: static int LoopForStop (AHTReqContext * me)
1516: #else
1517: static int LoopForStop (AHTReqContext * me)
1518: #endif
1519: {
1520:
1.25 cvs 1521: extern ThotAppContext app_cont;
1.51 cvs 1522: XEvent ev;
1523: XtInputMask status;
1.17 cvs 1524: int status_req = HT_OK;
1.15 cvs 1525:
1526: /* to test the async calls */
1.17 cvs 1527: /* Loop while waiting for new events, exists when the request is over */
1.15 cvs 1528: while (me->reqStatus != HT_ABORT &&
1529: me->reqStatus != HT_END &&
1.69 cvs 1530: me->reqStatus != HT_ERR) {
1.116 cvs 1531: if (!AmayaIsAlive ())
1.69 cvs 1532: /* Amaya was killed by one of the callback handlers */
1533: exit (0);
1534:
1535: status = XtAppPending (app_cont);
1536: if (status & XtIMXEvent) {
1537: XtAppNextEvent (app_cont, &ev);
1538: TtaHandleOneEvent (&ev);
1539: } else if (status & (XtIMAll & (~XtIMXEvent))) {
1540: XtAppProcessEvent (app_cont, (XtIMAll & (~XtIMXEvent)));
1541: } else {
1542: XtAppNextEvent (app_cont, &ev);
1543: TtaHandleOneEvent (&ev);
1544: }
1545: }
1.4 cvs 1546:
1.69 cvs 1547: switch (me->reqStatus) {
1548: case HT_ERR:
1549: case HT_ABORT:
1.15 cvs 1550: status_req = HT_ERROR;
1551: break;
1552:
1.69 cvs 1553: case HT_END:
1.15 cvs 1554: status_req = HT_OK;
1555: break;
1556:
1.69 cvs 1557: default:
1.15 cvs 1558: break;
1.69 cvs 1559: }
1.15 cvs 1560: return (status_req);
1.4 cvs 1561: }
1.69 cvs 1562: #endif /* _WINDOWS */
1.4 cvs 1563:
1.5 cvs 1564: /*----------------------------------------------------------------------
1.15 cvs 1565: QueryClose
1.21 cvs 1566: closes all existing threads, frees all non-automatically deallocated
1567: memory and then ends libwww.
1.5 cvs 1568: ----------------------------------------------------------------------*/
1.116 cvs 1569: void QueryClose ()
1.4 cvs 1570: {
1.24 cvs 1571:
1.116 cvs 1572: AmayaAlive = FALSE;
1.24 cvs 1573:
1.116 cvs 1574: /* remove all the handlers and callbacks that may output a message to
1575: a non-existent Amaya window */
1.21 cvs 1576:
1.116 cvs 1577: HTNet_deleteAfter (AHTLoadTerminate_handler);
1578: HTNet_deleteAfter (redirection_handler);
1579: HTAlertCall_deleteAll (HTAlert_global () );
1580: HTAlert_setGlobal ((HTList *) NULL);
1581: HTEvent_setRegisterCallback ((HTEvent_registerCallback *) NULL);
1582: HTEvent_setUnregisterCallback ((HTEvent_unregisterCallback *) NULL);
1583: #ifndef _WINDOWS
1584: /** need to erase all existing timers too **/
1585: HTTimer_registerSetTimerCallback (NULL);
1586: HTTimer_registerDeleteTimerCallback (NULL);
1587: #endif /* !_WINDOWS */
1588: HTHost_setActivateRequestCallback (NULL);
1589: Thread_deleteAll ();
1.21 cvs 1590:
1.116 cvs 1591: HTProxy_deleteAll ();
1592: HTNoProxy_deleteAll ();
1593: HTGateway_deleteAll ();
1594: AHTProfile_delete ();
1595: }
1596:
1597: /*----------------------------------------------------------------------
1598: NextNameValue
1599: ---------------------------------------------------------------------*/
1600: #ifdef __STDC__
1601: static char * NextNameValue (char ** pstr, char **name, char **value)
1602: #else
1603: static char * NextNameValue (pstr, name, value);
1604: char ** pstr;
1605: char **name;
1606: char **value;
1607: #endif /* __STDC__ */
1608: {
1609: char * p = *pstr;
1610: char * start = NULL;
1611: if (!pstr || !*pstr) return NULL;
1612:
1613: if (!*p) {
1614: *pstr = p;
1615: *name = NULL;
1616: *value = NULL;
1617: return NULL; /* No field */
1618: }
1619:
1620: /* Now search for the next '&' and ';' delimitators */
1621: start = p;
1622: while (*p && *p != '&' && *p != ';') p++;
1623: if (*p)
1624: *p++ = '\0';
1625: *pstr = p;
1626:
1627: /* Search for the name and value */
1628: *name = start;
1629: p = start;
1630:
1631: while(*p && *p != '=')
1632: p++;
1633: if (*p)
1634: *p++ = '\0';
1635: *value = p;
1636:
1637: return start;
1638: }
1639:
1640: /*----------------------------------------------------------------------
1641: PrepareFormdata
1642: ---------------------------------------------------------------------*/
1643: #ifdef __STDC__
1644: static HTAssocList * PrepareFormdata (char *string)
1645: #else
1646: static HTAssocList * PrepareFormdata (string)
1647: char *string;
1648: #endif /* __STDC__ */
1649: {
1650: char * tmp_string, * tmp_string_ptr;
1651: char * name;
1652: char * value;
1653: HTAssocList * formdata;
1654:
1655: if (!string)
1656: return NULL;
1657:
1658: /* store the ptr in another variable, as the original address will
1659: change
1660: */
1661:
1662: tmp_string_ptr = tmp_string = TtaStrdup (string);
1663: formdata = HTAssocList_new();
1664:
1665: while (*tmp_string)
1666: {
1667: NextNameValue (&tmp_string, &name, &value);
1668: HTAssocList_addObject(formdata,
1669: name, value);
1670: }
1671:
1672: TtaFreeMemory (tmp_string_ptr);
1673: return formdata;
1.4 cvs 1674: }
1675:
1.99 cvs 1676:
1677: /*----------------------------------------------------------------------
1678: InvokeGetObjectWWW_callback
1679: A simple function to invoke a callback function whenever there's an error
1680: in GetObjectWWW
1681: ---------------------------------------------------------------------*/
1682:
1.116 cvs 1683: #ifdef __STDC__
1684: void InvokeGetObjectWWW_callback (int docid, char *urlName, char *outputfile, TTcbf *terminate_cbf, void *context_tcbf, int status)
1.99 cvs 1685: #else
1.111 cvs 1686: void InvokeGetObjectWWW_callback (docid, urlName, outputfile, terminate_cbf, context_tcbf, status)
1.99 cvs 1687: int docid;
1688: char *urlName;
1689: char *outputfile;
1690: TTcbf *terminate_cbf;
1691: void *context_tcbf;
1.116 cvs 1692: #endif /* __STDC__ */
1.99 cvs 1693: {
1694: if (!terminate_cbf)
1695: return;
1696:
1.116 cvs 1697: (*terminate_cbf) (docid, status, urlName, outputfile,
1.99 cvs 1698: NULL, context_tcbf);
1699: }
1700:
1701:
1702:
1.5 cvs 1703: /*----------------------------------------------------------------------
1.15 cvs 1704: GetObjectWWW
1.17 cvs 1705: this function requests a resource designated by a URLname into a
1706: temporary filename. The download can come from a simple GET operation,
1707: or can come from POSTING/GETTING a form. In the latter
1708: case, the function receives a query string to send to the server.
1709:
1.5 cvs 1710: 4 file retrieval modes are proposed:
1711: AMAYA_SYNC : blocking mode
1712: AMAYA_ISYNC : incremental, blocking mode
1713: AMAYA_ASYNC : non-blocking mode
1714: AMAYA_IASYNC : incremental, non-blocking mode
1715:
1716: In the incremental mode, each time a package arrives, it will be
1717: stored in the temporary file. In addition, if an
1718: incremental_callback function is defined, this function will be
1719: called and handled a copy of the newly received data package.
1720: Finally, if a terminate_callback function is defined, it will be
1721: invoked when the request terminates. The caller of this function
1.4 cvs 1722: can define two different contexts to be passed to the callback
1723: functions.
1724:
1725: When the function is called with the SYNC mode, the function will
1726: return only when the requested file has been loaded.
1727: The ASYNC mode will immediately return after setting up the
1728: call.
1729:
1730: Notes:
1731: At the end of a succesful request, the urlName string contains the
1732: name of the actually retrieved URL. As a URL can change over the time,
1733: (e.g., be redirected elsewhere), it is advised that the function
1.17 cvs 1734: caller verify the value of the urlName variable at the end of
1.4 cvs 1735: a request.
1736:
1737: Inputs:
1738: - docid Document identifier for the set of objects being
1739: retrieved.
1740: - urlName The URL to be retrieved (MAX_URL_LENGTH chars length)
1741: - outputfile A pointer to an empty string of MAX_URL_LENGTH.
1742: - mode The retrieval mode.
1743: - incremental_cbf
1744: - context_icbf
1745: Callback and context for the incremental modes
1746: - terminate_cbf
1747: - context_icbf
1748: Callback and context for a terminate handler
1.17 cvs 1749: -error_html if TRUE, then display any server error message as an
1750: HTML document.
1.88 cvs 1751: - content_type a string
1752:
1.4 cvs 1753: Outputs:
1754: - urlName The URL that was retrieved
1755: - outputfile The name of the temporary file which holds the
1756: retrieved data. (Only in case of success)
1.88 cvs 1757: - if content_type wasn't NULL, it will contain a copy of the parameter
1758: sent in the HTTP answer
1.4 cvs 1759: Returns:
1760: HT_ERROR
1761: HT_OK
1.5 cvs 1762:
1763: ----------------------------------------------------------------------*/
1.4 cvs 1764: #ifdef __STDC__
1.116 cvs 1765: int GetObjectWWW (int docid, char* urlName, char* postString,
1766: char* outputfile, int mode, TIcbf* incremental_cbf,
1767: void* context_icbf, TTcbf* terminate_cbf,
1.88 cvs 1768: void* context_tcbf, boolean error_html, char *content_type)
1.4 cvs 1769: #else
1.116 cvs 1770: int GetObjectWWW (docid, urlName, postString, outputfile, mode,
1771: incremental_cbf, context_icbf,
1.88 cvs 1772: terminate_cbf, context_tcbf, error_html, content_type)
1.73 cvs 1773: int docid;
1774: char *urlName;
1775: char *postString;
1776: char *outputfile;
1777: int mode;
1778: TIcbf *incremental_cbf;
1779: void *context_icbf;
1780: TTcbf *terminate_cbf;
1781: void *context_tcbf;
1782: boolean error_html;
1.88 cvs 1783: char *content_type;
1.4 cvs 1784: #endif
1785: {
1786: AHTReqContext *me;
1787: char *ref;
1.107 cvs 1788: int status, l;
1.114 cvs 1789: int tempsubdir;
1.7 cvs 1790:
1.116 cvs 1791: if (urlName == NULL || docid == 0 || outputfile == NULL)
1792: {
1793: /* no file to be loaded */
1794: TtaSetStatus (docid, 1, TtaGetMessage (AMAYA, AM_BAD_URL), urlName);
1.69 cvs 1795:
1.116 cvs 1796: if (error_html)
1.69 cvs 1797: /* so we can show the error message */
1798: DocNetworkStatus[docid] |= AMAYA_NET_ERROR;
1.116 cvs 1799: InvokeGetObjectWWW_callback (docid, urlName, outputfile, terminate_cbf,
1800: context_tcbf, HT_ERROR);
1801: return HT_ERROR;
1802: }
1.7 cvs 1803:
1.4 cvs 1804: /* do we support this protocol? */
1.116 cvs 1805: if (IsValidProtocol (urlName) == NO)
1806: {
1807: /* return error */
1808: outputfile[0] = EOS; /* file could not be opened */
1809: TtaSetStatus (docid, 1,
1810: TtaGetMessage (AMAYA, AM_GET_UNSUPPORTED_PROTOCOL),
1811: urlName);
1812:
1813: if (error_html)
1.69 cvs 1814: /* so we can show the error message */
1815: DocNetworkStatus[docid] |= AMAYA_NET_ERROR;
1.116 cvs 1816: InvokeGetObjectWWW_callback (docid, urlName, outputfile, terminate_cbf,
1817: context_tcbf, HT_ERROR);
1818: return HT_ERROR;
1819: }
1.4 cvs 1820:
1.114 cvs 1821: /* we store CSS in subdir named 0; all the other files go to a subidr
1822: named after their own docid */
1823:
1824: tempsubdir = (mode & AMAYA_LOAD_CSS) ? 0 : docid;
1825:
1.116 cvs 1826: /* create a tempfilename */
1827: sprintf (outputfile, "%s%c%d%c%04dAM",
1828: TempFileDirectory, DIR_SEP, tempsubdir, DIR_SEP, object_counter);
1829: /* update the object_counter (used for the tempfilename) */
1.4 cvs 1830: object_counter++;
1.116 cvs 1831:
1.4 cvs 1832: /* normalize the URL */
1.45 cvs 1833: ref = AmayaParseUrl (urlName, "", AMAYA_PARSE_ALL);
1.4 cvs 1834: /* should we abort the request if we could not normalize the url? */
1.69 cvs 1835: if (ref == (char*) NULL || ref[0] == EOS) {
1836: /*error */
1837: outputfile[0] = EOS;
1838: TtaSetStatus (docid, 1, TtaGetMessage (AMAYA, AM_BAD_URL), urlName);
1839:
1840: if (error_html)
1.116 cvs 1841: /* so we can show the error message */
1842: DocNetworkStatus[docid] |= AMAYA_NET_ERROR;
1.99 cvs 1843: InvokeGetObjectWWW_callback (docid, urlName, outputfile, terminate_cbf,
1.116 cvs 1844: context_tcbf, HT_ERROR);
1.69 cvs 1845: return HT_ERROR;
1846: }
1.116 cvs 1847:
1.4 cvs 1848: /* verify if that file name existed */
1.9 cvs 1849: if (TtaFileExist (outputfile))
1.77 cvs 1850: TtaFileUnlink (outputfile);
1.116 cvs 1851:
1.4 cvs 1852: /* Initialize the request structure */
1853: me = AHTReqContext_new (docid);
1.116 cvs 1854: if (me == NULL)
1855: {
1856: outputfile[0] = EOS;
1857: /* need an error message here */
1858: TtaFreeMemory (ref);
1859: InvokeGetObjectWWW_callback (docid, urlName, outputfile, terminate_cbf,
1860: context_tcbf, HT_ERROR);
1861: return HT_ERROR;
1862: }
1863:
1.4 cvs 1864: /* Specific initializations for POST and GET */
1.116 cvs 1865: if (mode & AMAYA_FORM_POST)
1866: {
1867: me->method = METHOD_POST;
1868: if (postString)
1869: {
1870: me->mem_ptr = TtaStrdup (postString);
1871: me->block_size = strlen (postString);
1872: }
1873: HTRequest_setMethod (me->request, METHOD_POST);
1874: }
1875: else
1876: {
1877: me->method = METHOD_GET;
1878: if (!HasKnownFileSuffix (ref))
1879: HTRequest_setConversion(me->request, acceptTypes, TRUE);
1880: }
1.93 cvs 1881:
1.116 cvs 1882: /* Common initialization for all HTML methods */
1.4 cvs 1883: me->mode = mode;
1884: me->error_html = error_html;
1885: me->incremental_cbf = incremental_cbf;
1886: me->context_icbf = context_icbf;
1887: me->terminate_cbf = terminate_cbf;
1888: me->context_tcbf = context_tcbf;
1.64 cvs 1889:
1.69 cvs 1890: /* for the async. request modes, we need to have our
1.4 cvs 1891: own copy of outputfile and urlname
1.116 cvs 1892: */
1.4 cvs 1893:
1.116 cvs 1894: if ((mode & AMAYA_ASYNC) || (mode & AMAYA_IASYNC))
1895: {
1896: l = strlen (outputfile);
1897: if (l > MAX_LENGTH)
1898: me->outputfile = TtaGetMemory (l + 2);
1899: else
1900: me->outputfile = TtaGetMemory (MAX_LENGTH + 2);
1901: strcpy (me->outputfile, outputfile);
1902: l = strlen (urlName);
1903: if (l > MAX_LENGTH)
1904: me->urlName = TtaGetMemory (l + 2);
1905: else
1906: me->urlName = TtaGetMemory (MAX_LENGTH + 2);
1907: strcpy (me->urlName, urlName);
1908: #ifdef _WINDOWS
1909: /* force windows ASYNC requests to always be non preemptive */
1910: HTRequest_setPreemptive (me->request, NO);
1911: #endif /*_WINDOWS */
1912: } /* AMAYA_ASYNC mode */
1913: else
1914: #ifdef _WINDOWS
1915: {
1916: me->outputfile = outputfile;
1917: me->urlName = urlName;
1918: /* force windows SYNC requests to always be non preemptive */
1.123 cvs 1919: /* @@@ verify this */
1.116 cvs 1920: HTRequest_setPreemptive (me->request, YES);
1921: }
1922: #else /* !_WINDOWS */
1923: {
1924: me->outputfile = outputfile;
1925: me->urlName = urlName;
1926: }
1927: /***
1.57 cvs 1928: Change for taking into account the stop button:
1929: The requests will be always asynchronous, however, if mode=AMAYA_SYNC,
1930: we will loop until the document has been received or a stop signal
1931: generated
1.77 cvs 1932: ****/
1.116 cvs 1933: HTRequest_setPreemptive (me->request, NO);
1934: #endif /* _WINDOWS */
1.61 cvs 1935:
1936: /* prepare the URLname that will be displayed in teh status bar */
1937: ChopURL (me->status_urlName, me->urlName);
1.77 cvs 1938: TtaSetStatus (me->docid, 1,
1939: TtaGetMessage (AMAYA, AM_FETCHING),
1940: me->status_urlName);
1.4 cvs 1941:
1942: me->anchor = (HTParentAnchor *) HTAnchor_findAddress (ref);
1.45 cvs 1943: TtaFreeMemory (ref);
1.4 cvs 1944:
1.114 cvs 1945: if (mode & AMAYA_NOCACHE)
1.116 cvs 1946: HTRequest_setReloadMode (me->request, HT_CACHE_FLUSH);
1947:
1948: /* prepare the query string and format for POST */
1949: if (mode & AMAYA_FORM_POST)
1.114 cvs 1950: {
1.116 cvs 1951: HTAnchor_setFormat ((HTParentAnchor *) me->anchor,
1952: HTAtom_for ("application/x-www-form-urlencoded"));
1953: HTAnchor_setLength ((HTParentAnchor *) me->anchor, me->block_size);
1954: HTRequest_setEntityAnchor (me->request, me->anchor);
1955: HTRequest_setEntityAnchor (me->request, me->anchor);
1956: me->formdata = PrepareFormdata (postString);
1957: }
1.114 cvs 1958:
1.116 cvs 1959: /* do the request */
1960: if (mode & AMAYA_FORM_POST)
1.119 cvs 1961: {
1962: /* this call doesn't give back a boolean */
1963: HTParentAnchor * posted = NULL;
1964:
1965: posted = HTPostFormAnchor (me->formdata, (HTAnchor *) me->anchor,
1966: me->request);
1967: status = posted ? YES : NO;
1968: }
1.116 cvs 1969: else
1.77 cvs 1970: status = HTLoadAnchor ((HTAnchor *) me->anchor, me->request);
1.69 cvs 1971:
1.123 cvs 1972: #ifndef _WINDOWS
1973: /* @@@ may need some special windows error msg here */
1.116 cvs 1974: /* control the errors */
1975: if (status != HT_OK
1976: && HTError_hasSeverity (HTRequest_error (me->request), ERR_NON_FATAL))
1977: status = HT_ERROR;
1.123 cvs 1978: #endif /* !_WINDOWS */
1979: /* @@@test the effect of HTRequest_kill () */
1.85 cvs 1980:
1.116 cvs 1981: #if 0
1982: /** *this should go to term_d @@@@ */
1983: if (me->reqStatus == HT_CACHE)
1.93 cvs 1984: {
1.116 cvs 1985: AHTPrintPendingRequestStatus (me->docid, YES);
1986: /* free the memory allocated for async requests */
1987: InvokeGetObjectWWW_callback (docid, urlName, outputfile,
1988: terminate_cbf, context_tcbf, HT_OK);
1989: AHTReqContext_delete (me);
1990: return HT_OK;
1.93 cvs 1991: }
1.116 cvs 1992: #endif
1.4 cvs 1993:
1.116 cvs 1994: if (status == HT_ERROR)
1995: /* the request invocation failed */
1996: {
1997: /* show an error message on the status bar */
1998: DocNetworkStatus[docid] |= AMAYA_NET_ERROR;
1999: TtaSetStatus (docid, 1,
2000: TtaGetMessage (AMAYA, AM_CANNOT_LOAD),
2001: urlName);
2002: if (me->reqStatus == HT_NEW)
2003: /* manually invoke the last processing that usually gets done
2004: in a succesful request */
2005: InvokeGetObjectWWW_callback (docid, urlName, outputfile,
2006: terminate_cbf, context_tcbf, HT_ERROR);
2007: /* terminate_handler wasn't called */
2008: if (mode & AMAYA_SYNC || mode & AMAYA_ISYNC)
2009: AHTReqContext_delete (me);
2010: }
2011: else
2012: /* end treatment for SYNC requests */
1.120 cvs 2013: if ((mode & AMAYA_SYNC) || (mode & AMAYA_ISYNC))
2014: {
1.116 cvs 2015: #ifndef _WINDOWS
1.120 cvs 2016: /* part of the UNIX stop button handler */
2017: if (status != HT_ERROR)
2018: status = LoopForStop (me);
1.116 cvs 2019: #endif /* _!WINDOWS */
1.120 cvs 2020: /* @@@ this doesn't seem correct ... me->request may not exist ... */
2021: if (!HTRequest_kill (me->request))
2022: AHTReqContext_delete (me);
2023: }
2024: return (status);
1.4 cvs 2025: }
2026:
1.5 cvs 2027: /*----------------------------------------------------------------------
1.17 cvs 2028: PutObjectWWW
2029: frontend for uploading a resource to a URL. This function downloads
2030: a file to be uploaded into memory, it then calls UploadMemWWW to
2031: finish the job.
2032:
1.5 cvs 2033: 2 upload modes are proposed:
2034: AMAYA_SYNC : blocking mode
2035: AMAYA_ASYNC : non-blocking mode
2036:
1.4 cvs 2037: When the function is called with the SYNC mode, the function will
2038: return only when the file has been uploaded.
2039: The ASYNC mode will immediately return after setting up the
2040: call. Furthermore, at the end of an upload, the ASYNC mode will
2041: call back terminate_cbf, handling it the context defined in
2042: context_tcbf.
2043:
2044: Notes:
2045: At the end of a succesful request, the urlName string contains the
2046: name of the actually uploaded URL. As a URL can change over the time,
2047: (e.g., be redirected elsewhere), it is advised that the function
2048: caller verifies the value of the urlName variable at the end of
2049: a request.
2050:
2051: Inputs:
2052: - docid Document identifier for the set of objects being
2053: retrieved.
2054: - fileName A pointer to the local file to upload
2055: - urlName The URL to be uploaded (MAX_URL_LENGTH chars length)
2056: - mode The retrieval mode.
2057: - terminate_cbf
2058: - context_icbf
2059: Callback and context for a terminate handler
2060:
2061: Outputs:
2062: - urlName The URL that was uploaded
2063:
2064: Returns:
2065: HT_ERROR
2066: HT_OK
1.5 cvs 2067: ----------------------------------------------------------------------*/
1.4 cvs 2068: #ifdef __STDC__
1.27 cvs 2069: int PutObjectWWW (int docid, char *fileName, char *urlName, int mode, PicType contentType,
1.4 cvs 2070: TTcbf * terminate_cbf, void *context_tcbf)
2071: #else
1.26 cvs 2072: int PutObjectWWW (docid, urlName, fileName, mode, contentType,
1.4 cvs 2073: ,terminate_cbf, context_tcbf)
2074: int docid;
2075: char *urlName;
2076: char *fileName;
2077: int mode;
1.27 cvs 2078: PicType contentType;
1.4 cvs 2079: TTcbf *terminate_cbf;
2080: void *context_tcbf;
2081:
1.116 cvs 2082: #endif /* __STDC__ */
1.4 cvs 2083: {
1.116 cvs 2084: AHTReqContext *me;
1.4 cvs 2085: int status;
2086: int fd;
2087: struct stat file_stat;
1.116 cvs 2088: char *fileURL;
1.4 cvs 2089:
1.33 cvs 2090: AmayaLastHTTPErrorMsg [0] = EOS;
2091:
1.116 cvs 2092: if (urlName == NULL || docid == 0 || fileName == NULL
2093: || !TtaFileExist (fileName))
1.4 cvs 2094: /* no file to be uploaded */
2095: return HT_ERROR;
2096:
2097: /* do we support this protocol? */
1.7 cvs 2098: if (IsValidProtocol (urlName) == NO)
2099: {
2100: /* return error */
1.77 cvs 2101: TtaSetStatus (docid, 1,
2102: TtaGetMessage (AMAYA, AM_PUT_UNSUPPORTED_PROTOCOL),
1.7 cvs 2103: urlName);
2104: return HT_ERROR;
2105: }
1.116 cvs 2106:
2107: /* verify the file's size */
2108: #ifndef _WINDOWS
1.7 cvs 2109: if ((fd = open (fileName, O_RDONLY)) == -1)
1.116 cvs 2110: #else
1.74 cvs 2111: if ((fd = open (fileName, _O_RDONLY | _O_BINARY)) == -1)
1.116 cvs 2112: #endif /* _WINDOWS */
1.7 cvs 2113: {
2114: /* if we could not open the file, exit */
2115: /*error msg here */
2116: return (HT_ERROR);
2117: }
1.4 cvs 2118:
2119: fstat (fd, &file_stat);
1.116 cvs 2120: close (fd);
1.4 cvs 2121:
1.7 cvs 2122: if (file_stat.st_size == 0)
2123: {
2124: /* file was empty */
2125: /*errmsg here */
2126: return (HT_ERROR);
2127: }
1.116 cvs 2128:
2129: /* prepare the request context */
1.4 cvs 2130:
2131: if (THD_TRACE)
1.116 cvs 2132: fprintf (stderr, "file size == %u\n", (unsigned) file_stat.st_size);
1.4 cvs 2133:
2134: me = AHTReqContext_new (docid);
2135:
1.7 cvs 2136: if (me == NULL)
2137: {
2138: /* need an error message here */
2139: TtaHandlePendingEvents ();
2140: return (HT_ERROR);
2141: }
1.116 cvs 2142:
1.4 cvs 2143: me->mode = mode;
2144: me->incremental_cbf = (TIcbf *) NULL;
2145: me->context_icbf = (void *) NULL;
2146: me->terminate_cbf = terminate_cbf;
2147: me->context_tcbf = context_tcbf;
2148: me->urlName = urlName;
1.116 cvs 2149: me->block_size = file_stat.st_size;
1.17 cvs 2150: /* select the parameters that distinguish a PUT from a GET/POST */
1.4 cvs 2151: me->method = METHOD_PUT;
2152: HTRequest_setMethod (me->request, METHOD_PUT);
2153: me->output = stdout;
1.17 cvs 2154: /* we are not expecting to receive any input from the server */
2155: me->outputfile = (char *) NULL;
1.4 cvs 2156:
1.116 cvs 2157: fileURL = HTParse (fileName, "file:/", PARSE_ALL);
2158: me->anchor = (HTParentAnchor *) HTAnchor_findAddress (fileURL);
2159: HT_FREE (fileURL);
1.114 cvs 2160:
1.28 cvs 2161: /* Set the Content-Type of the file we are uploading */
1.77 cvs 2162: HTAnchor_setFormat ((HTParentAnchor *) me->anchor,
2163: AHTGuessAtom_for (me->urlName, contentType));
1.116 cvs 2164: HTAnchor_setLength ((HTParentAnchor *) me->anchor, me->block_size);
1.17 cvs 2165:
1.4 cvs 2166: HTRequest_setEntityAnchor (me->request, me->anchor);
1.116 cvs 2167: #ifdef _WINDOWS
2168: HTRequest_setPreemptive (me->request, YES);
2169: #else
2170: HTRequest_setPreemptive (me->request, NO);
2171: #endif /* _WINDOWS */
2172:
2173: if (mode & AMAYA_NOCACHE)
2174: HTRequest_setReloadMode (me->request, HT_CACHE_FLUSH);
2175:
1.74 cvs 2176: /* prepare the URLname that will be displayed in teh status bar */
2177: ChopURL (me->status_urlName, me->urlName);
2178: TtaSetStatus (me->docid, 1, TtaGetMessage (AMAYA, AM_REMOTE_SAVING),
2179: me->status_urlName);
1.114 cvs 2180:
1.116 cvs 2181: status = HTPutDocumentAbsolute (me->anchor, urlName, me->request);
1.4 cvs 2182:
1.116 cvs 2183: if (status != HT_ERROR && me->reqStatus != HT_ERR)
1.7 cvs 2184: {
2185: /* part of the stop button handler */
2186: if ((mode & AMAYA_SYNC) || (mode & AMAYA_ISYNC))
2187: {
1.120 cvs 2188: #ifndef _WINDOWS
1.7 cvs 2189: status = LoopForStop (me);
1.120 cvs 2190: #endif /* _WINDOWS */
2191: if (!HTRequest_kill (me->request))
2192: AHTReqContext_delete (me);
1.7 cvs 2193: }
1.15 cvs 2194: }
1.116 cvs 2195: else
2196: {
2197: if (! HTRequest_kill (me->request))
2198: AHTReqContext_delete (me);
2199: }
2200:
2201: TtaHandlePendingEvents ();
1.90 cvs 2202:
1.116 cvs 2203: return status;
1.28 cvs 2204: }
1.4 cvs 2205:
1.5 cvs 2206: /*----------------------------------------------------------------------
1.17 cvs 2207: Stop Request
2208: stops (kills) all active requests associated with a docid
1.5 cvs 2209: ----------------------------------------------------------------------*/
1.4 cvs 2210: #ifdef __STDC__
2211: void StopRequest (int docid)
2212: #else
2213: void StopRequest (docid)
2214: int docid;
2215: #endif
2216: {
2217: HTList *cur;
2218: AHTDocId_Status *docid_status;
2219: AHTReqContext *me;
1.108 cvs 2220: #ifdef DEBUG_LIBWWW
2221: int open_requests;
2222: #endif /* DEBUG_LIBWWW */
1.116 cvs 2223:
2224:
2225: if (Amaya && libDoStop)
1.7 cvs 2226: {
1.100 cvs 2227: #ifdef DEBUG_LIBWWW
1.116 cvs 2228: fprintf (stderr, "StopRequest: number of Amaya requests : %d\n",
2229: Amaya->open_requests);
1.100 cvs 2230: #endif /* DEBUG_LIBWWW */
2231:
1.116 cvs 2232: docid_status = (AHTDocId_Status *) GetDocIdStatus (docid,
2233: Amaya->docid_status);
2234: /* verify if there are any requests at all associated with docid */
2235:
2236: if (docid_status == (AHTDocId_Status *) NULL)
2237: return;
1.108 cvs 2238: #ifdef DEBUG_LIBWWW
1.116 cvs 2239: open_requests = docid_status->counter;
1.108 cvs 2240: #endif /* DEBUG_LIBWWW */
1.4 cvs 2241:
1.116 cvs 2242: /* First, kill all pending requests */
2243: /* We first inhibit the activation of pending requests */
2244: HTHost_disable_PendingReqLaunch ();
2245: cur = Amaya->reqlist;
2246: while ((me = (AHTReqContext *) HTList_nextObject (cur)))
2247: {
2248: if (me->docid == docid && me->reqStatus == HT_NEW)
2249: {
2250: /* If we have an ASYNC request, we kill it.
2251: ** If it's a SYNC request, we just mark it as aborted
2252: */
2253: me->reqStatus = HT_ABORT;
2254: if (((me->mode & AMAYA_IASYNC)
2255: || (me->mode & AMAYA_ASYNC))
2256: && !(me->mode & AMAYA_ASYNC_SAFE_STOP))
2257: {
2258: /* delete the amaya/libwww request context */
2259: if (!HTRequest_kill (me->request))
2260: /* if the above function returns NO (0), it means
2261: ** that there was no network context and that
2262: ** terminate_handler wasn't called. So, we erase
2263: ** this context ourselves
2264: */
1.96 cvs 2265: AHTReqContext_delete (me);
1.116 cvs 2266:
2267: cur = Amaya->reqlist;
1.108 cvs 2268: #ifdef DEBUG_LIBWWW
1.116 cvs 2269: /* update the number of open requests */
2270: open_requests--;
1.108 cvs 2271: #endif /* DEBUG_LIBWWW */
1.116 cvs 2272: }
2273: }
2274: }
1.108 cvs 2275:
1.85 cvs 2276: /* enable the activation of pending requests */
1.116 cvs 2277: HTHost_enable_PendingReqLaunch ();
1.85 cvs 2278:
1.116 cvs 2279: cur = Amaya->reqlist;
2280: while ((me = (AHTReqContext *) HTList_nextObject (cur)))
2281: {
2282: if (me->docid == docid)
2283: {
2284: /* kill this request */
2285:
2286: switch (me->reqStatus)
2287: {
2288: case HT_ABORT:
1.108 cvs 2289: #ifdef DEBUG_LIBWWW
1.116 cvs 2290: fprintf (stderr, "Stop: url %s says abort", me->urlName);
1.108 cvs 2291: #endif /* DEBUG_LIBWWW */
1.116 cvs 2292: break;
1.100 cvs 2293:
1.116 cvs 2294: case HT_END:
2295: #ifdef DEBUG_LIBWWW
2296: fprintf (stderr, "Stop: url %s says end", me->urlName);
2297: #endif /* DEBUG_LIBWWW */
2298: break;
2299:
2300: case HT_BUSY:
2301: me->reqStatus = HT_ABORT;
1.108 cvs 2302: #ifdef DEBUG_LIBWWW
1.116 cvs 2303: fprintf (stderr, "Stop: url %s going from busy to abort\n",
2304: me->urlName);
1.108 cvs 2305: #endif /* DEBUG_LIBWWW */
1.116 cvs 2306: break;
1.100 cvs 2307:
1.116 cvs 2308: case HT_NEW_PENDING:
2309: case HT_WAITING:
2310: default:
1.108 cvs 2311: #ifdef DEBUG_LIBWWW
1.116 cvs 2312: fprintf (stderr, "Stop: url %s says NEW_PENDING, WAITING",
2313: me->urlName);
1.108 cvs 2314: #endif /* DEBUG_LIBWWW */
1.116 cvs 2315: me->reqStatus = HT_ABORT;
2316:
2317: if (((me->mode & AMAYA_IASYNC)
2318: || (me->mode & AMAYA_ASYNC))
2319: && !(me->mode & AMAYA_ASYNC_SAFE_STOP))
2320: {
2321: /* delete the amaya/libwww request context */
2322: if (!HTRequest_kill (me->request))
2323: /* if the above function returns NO (0), it means
2324: ** that there was no network context and that
2325: ** terminate_handler wasn't called. So, we erase
2326: ** this context ourselves
2327: */
2328: AHTReqContext_delete (me);
1.96 cvs 2329:
1.116 cvs 2330: cur = Amaya->reqlist;
1.108 cvs 2331: #ifdef DEBUG_LIBWWW
1.116 cvs 2332: /* update the number of open requests */
2333: open_requests--;
1.108 cvs 2334: #endif /* DEBUG_LIBWWW */
1.116 cvs 2335: }
2336:
1.108 cvs 2337: #ifdef DEBUG_LIBWWW
1.116 cvs 2338: if (HTHost_isIdle (reqHost))
2339: fprintf (stderr, "StopRequst: After killing, Host is "
2340: "idle\n");
2341: else
2342: fprintf (stderr, "StopRequest: After killing, Host isn't "
2343: "idle\n");
1.108 cvs 2344: #endif /* DEBUG_LIBWWW */
1.95 cvs 2345:
1.108 cvs 2346: #ifdef DEBUG_LIBWWW
1.116 cvs 2347: open_requests--;
1.108 cvs 2348: #endif /* DEBUG_LIBWWW */
1.93 cvs 2349: break;
2350:
1.116 cvs 2351: } /* switch */
2352: } /* if me docid */
2353: } /* while */
2354:
1.100 cvs 2355: #ifdef DEBUG_LIBWWW
1.116 cvs 2356: fprintf (stderr, "StopRequest: number of Amaya requests : "
2357: "%d\n", Amaya->open_requests);
1.100 cvs 2358: #endif /* DEBUG_LIBWWW */
1.7 cvs 2359: } /* if amaya open requests */
1.93 cvs 2360:
1.85 cvs 2361: } /* StopRequest */
1.17 cvs 2362:
2363:
1.105 cvs 2364: /*----------------------------------------------------------------------
2365: AmayaIsAlive
2366: returns the status of the AmayaAlive flag
2367: ----------------------------------------------------------------------*/
2368: #ifdef __STDC__
2369: boolean AmayaIsAlive (void)
2370: #else
2371: boolean AmayaIsAlive ()
2372: #endif /* _STDC_ */
2373: {
2374: return AmayaAlive;
2375: }
1.116 cvs 2376:
1.69 cvs 2377: #endif /* AMAYA_JAVA */
1.77 cvs 2378:
1.116 cvs 2379: /*
2380: end of Module query.c
2381: */
1.17 cvs 2382:
2383:
Webmaster