Annotation of Amaya/amaya/query.c, revision 1.219
1.14 cvs 1: /*
2: *
3: * (c) COPYRIGHT MIT and INRIA, 1996.
4: * Please first read the full copyright statement in file COPYRIGHT.
1.156 cvs 5: *
1.14 cvs 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.185 cvs 22: #ifdef _WINDOWS
23: #include <string.h>
1.130 cvs 24: #endif /* !_WINDOWS */
1.116 cvs 25: #define AMAYA_WWW_CACHE
1.168 cvs 26: #define AMAYA_LOST_UPDATE
1.116 cvs 27:
1.198 cvs 28: #if defined(_I18N_) || defined(__JIS__)
29: # ifdef _WINDOWS
30: # define CACHE_DIR_NAME L"\\libwww-cache\\"
31: # else
32: # define CACHE_DIR_NAME L"/libwww-cache/"
33: # endif /* _WINDOWS */
34: #else /* */
35: # ifdef _WINDOWS
36: # define CACHE_DIR_NAME "\\libwww-cache\\"
37: # else
38: # define CACHE_DIR_NAME "/libwww-cache/"
39: # endif /* _WINDOWS */
40: #endif /* */
41:
1.216 cvs 42: /* libwww default parameters */
1.176 cvs 43: #define DEFAULT_CACHE_SIZE 10
44: #define DEFAULT_MAX_CACHE_ENTRY_SIZE 3
1.177 cvs 45: #define DEFAULT_MAX_SOCKET 32
1.176 cvs 46: #define DEFAULT_DNS_TIMEOUT 1800L
1.151 cvs 47: #define DEFAULT_PERSIST_TIMEOUT 60L
1.165 cvs 48: #define DEFAULT_NET_EVENT_TIMEOUT 60000
1.216 cvs 49: /* defines the priority for image content negotiation */
50: #define IMAGE_ACCEPT_NEGOTIATION "*/*;q=0.1,image/*,image/gif,image/jpeg,image/png"
1.116 cvs 51:
1.12 cvs 52: /* Amaya includes */
1.25 cvs 53: #define THOT_EXPORT extern
1.4 cvs 54: #include "amaya.h"
1.214 cvs 55: #include "init_f.h"
1.130 cvs 56: #include <sys/types.h>
1.70 cvs 57: #include <fcntl.h>
1.140 cvs 58: #include "HTEvtLst.h"
1.157 cvs 59: #include "HTAABrow.h"
1.7 cvs 60:
1.141 cvs 61: #if defined(__svr4__) || defined (_AIX)
1.4 cvs 62: #define CATCH_SIG
63: #endif
64:
65: /* local structures coming from libwww and which are
1.17 cvs 66: not found in any .h file
1.7 cvs 67: */
1.68 cvs 68:
1.7 cvs 69: struct _HTStream
70: {
1.15 cvs 71: const HTStreamClass *isa;
72: FILE *fp;
1.45 cvs 73: BOOL leave_open; /* Close file when TtaFreeMemory? */
1.15 cvs 74: char *end_command; /* Command to execute */
75: BOOL remove_on_close; /* Remove file? */
76: char *filename; /* Name of file */
77: HTRequest *request; /* saved for callback */
78: HTRequestCallback *callback;
1.7 cvs 79: };
80:
1.15 cvs 81:
1.7 cvs 82: struct _HTError
83: {
84: HTErrorElement element; /* Index number into HTError */
85: HTSeverity severity; /* A la VMS */
86: BOOL ignore; /* YES if msg should not go to user */
87: void *par; /* Explanation, e.g. filename */
88: int length; /* For copying by generic routine */
89: char *where; /* Which function */
90: };
91:
1.4 cvs 92: /* Type definitions and global variables etc. local to this module */
93:
1.17 cvs 94: /*----------------------------------------------------------------------*/
95:
1.4 cvs 96: /*** private variables ***/
1.17 cvs 97:
1.4 cvs 98: static HTList *converters = NULL; /* List of global converters */
1.27 cvs 99: static HTList *acceptTypes = NULL; /* List of types for the Accept header */
1.193 cvs 100: static HTList *acceptLanguages = NULL; /* List of language priorities for the Accept header */
1.151 cvs 101: static HTList *transfer_encodings = NULL;
102: static HTList *content_encodings = NULL;
1.207 cvs 103: /* List of domains where we can do a safe PUT redirect */
104: static HTList *safeput_list = NULL;
105:
1.16 cvs 106: static int object_counter = 0; /* loaded objects counter */
1.191 cvs 107: static ThotBool AmayaAlive_flag; /* set to 1 if the application is active;
1.140 cvs 108: 0 if we have killed */
1.191 cvs 109: static ThotBool CanDoStop_flag; /* set to 1 if we can do a stop, 0
1.140 cvs 110: if we're inside a critical section */
1.214 cvs 111: static ThotBool UserAborted_flag; /* set to 1 if we're processing a user
112: induced stop request operation */
1.128 cvs 113: #ifdef AMAYA_WWW_CACHE
1.130 cvs 114: static int fd_cachelock; /* open handle to the .lock cache file */
115: #endif /* AMAYA_WWW_CACHE */
1.4 cvs 116:
1.15 cvs 117: #include "answer_f.h"
118: #include "query_f.h"
119: #include "AHTURLTools_f.h"
120: #include "AHTBridge_f.h"
121: #include "AHTMemConv_f.h"
122: #include "AHTFWrite_f.h"
1.4 cvs 123:
1.116 cvs 124: /* prototypes */
125:
126: #ifdef __STDC__
1.198 cvs 127: static void RecCleanCache (STRING dirname);
1.123 cvs 128: #ifdef _WINDOWS
1.70 cvs 129: int WIN_Activate_Request (HTRequest* , HTAlertOpcode, int, const char*, void*, HTAlertPar*);
1.116 cvs 130: #endif /* _WINDOWS */
1.207 cvs 131: static void SafePut_init (void);
132: static void SafePut_delete (void);
133: static ThotBool SafePut_query (char *url);
134:
1.70 cvs 135: #else
1.128 cvs 136: static void RecCleanCache (/* char *dirname */);
1.123 cvs 137: #ifdef _WINDOWS
1.128 cvs 138: int WIN_Activate_Request (/* HTRequest* , HTAlertOpcode, int, const char*, void*, HTAlertPar* */);
1.116 cvs 139: #endif /* _WINDOWS */
1.207 cvs 140: static void SafePut_init (/* void */);
141: static void SafePut_delete (/* void */);
142: static ThotBool SafePut_query (/* char *url */);
1.70 cvs 143: #endif /* __STDC__ */
1.116 cvs 144:
1.15 cvs 145:
1.130 cvs 146: #ifdef AMAYA_WWW_CACHE
147: /***************************************************************
148: lock functions, used to avoid concurrent use of the cache
149: Mostly based on W. Richard Stevens' APUE book.
150: ***************************************************************/
151: /*----------------------------------------------------------------------
152: set_cachelock
153: sets a write lock on filename.
154: Returns -1 in case of failure, otherwise, it'll open a handle on
155: filename and fd_cachelock will take its value.
156: ----------------------------------------------------------------------*/
157: #ifdef __STDC__
1.198 cvs 158: static int set_cachelock (STRING filename)
1.130 cvs 159: #else
160: static int set_cachelock (filename)
1.198 cvs 161: STRING filename;
1.130 cvs 162: #endif /* __STDC__ */
163: {
1.188 cvs 164: int status;
1.130 cvs 165: #ifdef _WINDOWS
1.188 cvs 166:
167: status = TtaFileExist (filename);
168: return ((status) ? 0 : -1);
1.130 cvs 169: #else
170: struct flock lock;
171:
172: lock.l_type = F_WRLCK;
173: lock.l_start = 0;
174: lock.l_whence = SEEK_SET;
175: lock.l_len = 0;
176:
177: fd_cachelock = open (filename, O_WRONLY);
178:
179: if (fd_cachelock == -1)
180: status = -1;
181: else
182: status = fcntl(fd_cachelock, F_SETLK, &lock);
183:
184: if (status == -1)
1.190 cvs 185: {
1.179 cvs 186: if (fd_cachelock > 0)
1.190 cvs 187: close (fd_cachelock);
1.179 cvs 188: fd_cachelock = 0;
1.178 cvs 189: }
1.130 cvs 190: return (status);
191: #endif /* _WINDOWS */
192: }
193:
194: /*----------------------------------------------------------------------
195: clear_cachelock
196: remove the write lock set on a filename.
197: It'll close the fd handle on filename and reset *fd to 0.
198: ----------------------------------------------------------------------*/
199: #ifdef __STDC__
200: static int clear_cachelock (void)
201: #else
202: static int clear_cachelock ()
203: int *fd;
204: #endif /* __STDC__ */
205: {
206: #ifdef _WINDOWS
207: return 0;
208: #else
209: int status;
210:
1.178 cvs 211: if (!fd_cachelock)
1.130 cvs 212: return (-1);
213:
1.178 cvs 214: status = close (fd_cachelock);
1.130 cvs 215: fd_cachelock = 0;
216:
217: return (status);
218: #endif /* _WINDOWS */
219: }
220:
221: /*----------------------------------------------------------------------
222: test_cachelock
223: returns 0 if a fd is not locked by other process, otherwise
224: returns the pid of the process who has the lock
225: ----------------------------------------------------------------------*/
226: #ifdef __STDC__
1.198 cvs 227: static int test_cachelock (STRING filename)
1.130 cvs 228: #else
229: static int test_cachelock (filename)
1.198 cvs 230: STRING filename;
231: #endif /* __STDC__ */
1.130 cvs 232: {
233: #ifdef _WINDOWS
1.185 cvs 234: /* if the lock is set, we can't unlink the file under Windows */
1.188 cvs 235: if (!TtaFileUnlink (filename))
236: return 0;
237: else
1.185 cvs 238: return -1;
1.130 cvs 239: #else
240: struct flock lock;
241: int fd, status;
242:
243: lock.l_type = F_WRLCK;
244: lock.l_start = 0;
245: lock.l_whence = SEEK_SET;
246: lock.l_len = 0;
247:
248: fd = open (filename, O_WRONLY);
249:
250: if (fd < 0)
251: return (-1);
252: /* is this file locked ? */
253: status = fcntl (fd, F_GETLK, &lock);
254: close (fd);
255:
256: if (status < 0)
257: return (-1);
258:
259: if (lock.l_type == F_UNLCK)
260: return (0); /* false, region is not locked by another proc */
261: return (lock.l_pid); /* true, return pid of lock owner */
262: #endif /* _WINDOWS */
263: }
264:
265: #endif /* AMAYA_WWW_CACHE */
266:
1.15 cvs 267: /*----------------------------------------------------------------------
1.17 cvs 268: GetDocIdStatus
269: gets the status associated to a docid
1.15 cvs 270: ----------------------------------------------------------------------*/
271: #ifdef __STDC__
272: AHTDocId_Status *GetDocIdStatus (int docid, HTList * documents)
273: #else
274: AHTDocID_Status *GetDocIdStatus (docid, documents)
275: int docid;
276: HTList *documents;
277:
278: #endif
279: {
280: AHTDocId_Status *me;
281: HTList *cur;
282:
283: if (documents)
284: {
285: cur = documents;
286:
287: while ((me = (AHTDocId_Status *) HTList_nextObject (cur)))
288: {
289: if (me->docid == docid)
290: return (me);
1.18 cvs 291: }
292: }
1.15 cvs 293: return (AHTDocId_Status *) NULL;
294:
295: }
296:
1.5 cvs 297: /*----------------------------------------------------------------------
1.27 cvs 298: AHTGuessAtom_for
299: Converts an Amaya type descriptor into the equivalent MIME type.
300: ----------------------------------------------------------------------*/
301: #ifdef __STDC__
1.198 cvs 302: static HTAtom *AHTGuessAtom_for (STRING urlName, PicType contentType)
1.27 cvs 303: #else
304: static HTAtom *AHTGuessAtom_for (urlName, contentType)
1.198 cvs 305: STRING urlName;
1.27 cvs 306: PicType contentType;
307: #endif
308: {
309: HTAtom *atom;
1.198 cvs 310: STRING filename;
1.160 cvs 311: HTEncoding enc = NULL;
312: HTEncoding cte = NULL;
313: HTLanguage lang = NULL;
1.50 cvs 314: double quality = 1.0;
1.27 cvs 315:
316: switch (contentType)
317: {
318: case xbm_type:
319: atom = HTAtom_for("image/xbm");
320: break;
321: case eps_type:
1.35 cvs 322: atom = HTAtom_for("application/postscript");
1.27 cvs 323: break;
324: case xpm_type:
325: atom = HTAtom_for("image/xpm");
326: break;
327: case gif_type:
328: atom = HTAtom_for("image/gif");
329: break;
330: case jpeg_type:
331: atom = HTAtom_for("image/jpeg");
332: break;
333: case png_type:
334: atom = HTAtom_for("image/png");
335: break;
336: case unknown_type:
337: default:
338: /*
339: ** Amaya could not detect the type, so
340: ** we try to use the filename's suffix to do so.
341: */
1.198 cvs 342: filename = AmayaParseUrl (urlName, _EMPTYSTR_, AMAYA_PARSE_PATH | AMAYA_PARSE_PUNCTUATION);
343: HTBind_getFormat (WideChar2ISO (filename), &atom, &enc, &cte, &lang, &quality);
1.45 cvs 344: TtaFreeMemory (filename);
1.27 cvs 345: if (atom == WWW_UNKNOWN)
346: /*
347: ** we could not identify the suffix, so we assign it
348: ** a default type
349: */
350: atom = HTAtom_for ("text/html");
351: break;
352: }
353:
354: return atom;
355: }
356:
357: /*----------------------------------------------------------------------
1.17 cvs 358: AHTReqContext_new
359: create a new Amaya Context Object and update the global Amaya
360: request status.
1.5 cvs 361: ----------------------------------------------------------------------*/
1.4 cvs 362: #ifdef __STDC__
363: static AHTReqContext *AHTReqContext_new (int docid)
364: #else
365: static AHTReqContext *AHTReqContext_new (docid)
366: int docid;
367:
368: #endif
369: {
370: AHTReqContext *me;
371: AHTDocId_Status *docid_status;
372:
373: if ((me = (AHTReqContext *) TtaGetMemory (sizeof (AHTReqContext))) == NULL)
1.116 cvs 374: outofmem (__FILE__, "AHTReqContext_new");
375:
376: /* clear the structure */
377: memset ((void *) me, 0, sizeof (AHTReqContext));
1.4 cvs 378:
1.81 cvs 379: /* Bind the Context object together with the Request Object */
380: me->request = HTRequest_new ();
381:
1.80 cvs 382: /* clean the associated file structure) */
1.79 cvs 383: HTRequest_setOutputStream (me->request, NULL);
1.81 cvs 384:
1.4 cvs 385: /* Initialize the other members of the structure */
1.17 cvs 386: me->reqStatus = HT_NEW; /* initial status of a request */
1.4 cvs 387: me->docid = docid;
388: HTRequest_setMethod (me->request, METHOD_GET);
389: HTRequest_setOutputFormat (me->request, WWW_SOURCE);
390: HTRequest_setContext (me->request, me);
1.116 cvs 391:
1.36 cvs 392: /* experimental */
393: me->read_sock = INVSOC;
394: me->write_sock = INVSOC;
395: me->except_sock = INVSOC;
1.4 cvs 396:
397: /* Update the global context */
398: HTList_appendObject (Amaya->reqlist, (void *) me);
399:
400: docid_status = GetDocIdStatus (docid, Amaya->docid_status);
401:
1.7 cvs 402: if (docid_status == NULL)
403: {
1.116 cvs 404: docid_status = (AHTDocId_Status *)
405: TtaGetMemory (sizeof (AHTDocId_Status));
1.7 cvs 406: docid_status->docid = docid;
407: docid_status->counter = 1;
408: HTList_addObject (Amaya->docid_status, (void *) docid_status);
409: }
410: else
1.4 cvs 411: docid_status->counter++;
412:
413: Amaya->open_requests++;
414:
1.74 cvs 415: #ifdef DEBUG_LIBWWW
416: fprintf (stderr, "AHTReqContext_new: Created object %p\n", me);
417: #endif
1.116 cvs 418:
1.4 cvs 419: return me;
420: }
421:
1.5 cvs 422: /*----------------------------------------------------------------------
1.17 cvs 423: AHTReqContext_delete
424: Delete an Amaya Context Object and update the global Amaya request
425: status.
1.5 cvs 426: ----------------------------------------------------------------------*/
1.4 cvs 427:
428: #ifdef __STDC__
1.191 cvs 429: ThotBool AHTReqContext_delete (AHTReqContext * me)
1.4 cvs 430: #else
1.191 cvs 431: ThotBool AHTReqContext_delete (me)
1.4 cvs 432: AHTReqContext *me;
433:
434: #endif
435: {
436: AHTDocId_Status *docid_status;
437:
1.7 cvs 438: if (me)
439: {
1.74 cvs 440: #ifdef DEBUG_LIBWWW
1.138 cvs 441: fprintf (stderr, "AHTReqContext_delete: Deleting object %p\n", me);
1.74 cvs 442: #endif
1.138 cvs 443: if (Amaya->reqlist)
444: HTList_removeObject (Amaya->reqlist, (void *) me);
445:
446: docid_status = GetDocIdStatus (me->docid, Amaya->docid_status);
447: if (docid_status)
448: {
449: docid_status->counter--;
450:
451: if (docid_status->counter == 0)
452: {
453: HTList_removeObject (Amaya->docid_status, (void *) docid_status);
454: TtaFreeMemory ((void *) docid_status);
455: }
456: }
1.215 cvs 457:
458: HTNoFreeStream_delete (HTRequest_outputStream (me->request));
459: HTRequest_setOutputStream (me->request, NULL);
1.190 cvs 460: /* JK: no longer needed in libwww 5.2.3
461: if (me->method != METHOD_PUT && HTRequest_outputStream (me->request))
462: AHTFWriter_FREE (HTRequest_outputStream (me->request));
463: */
1.138 cvs 464: HTRequest_delete (me->request);
465:
466: if (me->output && me->output != stdout)
467: {
1.85 cvs 468: #ifdef DEBUG_LIBWWW
1.138 cvs 469: fprintf (stderr, "AHTReqContext_delete: URL is %s, closing "
470: "FILE %p\n", me->urlName, me->output);
1.85 cvs 471: #endif
1.138 cvs 472: fclose (me->output);
473: me->output = NULL;
474: }
1.79 cvs 475:
1.138 cvs 476: if (me->error_stream != (char *) NULL)
477: HT_FREE (me->error_stream);
478: #ifndef _WINDOWS
479: #ifdef WWW_XWINDOWS
480: if (me->read_xtinput_id || me->write_xtinput_id ||
481: me->except_xtinput_id)
482: RequestKillAllXtevents(me);
483: #endif /* WWW_XWINDOWS */
484: #endif /* !_WINDOWS */
485:
486: if (me->reqStatus == HT_ABORT)
487: {
488: if (me->outputfile && me->outputfile[0] != EOS)
489: {
1.198 cvs 490: TtaFileUnlink (ISO2WideChar (me->outputfile));
1.138 cvs 491: me->outputfile[0] = EOS;
492: }
493: }
494:
495: if ((me->mode & AMAYA_ASYNC) || (me->mode & AMAYA_IASYNC))
496: /* for the ASYNC mode, free the memory we allocated in GetObjectWWW
497: or in PutObjectWWW */
498: {
499: if (me->urlName)
500: TtaFreeMemory (me->urlName);
501: if (me->outputfile)
502: TtaFreeMemory (me->outputfile);
503: }
1.206 cvs 504:
1.208 cvs 505: /* the real name to which we are publishing */
506: if (me->default_put_name)
507: TtaFreeMemory (me->default_put_name);
508:
1.206 cvs 509: /* @@ temp change for the %esc conversion */
510: if (me->method == METHOD_PUT && me->urlName)
511: TtaFreeMemory (me->urlName);
512:
1.138 cvs 513: if (me->content_type)
514: TtaFreeMemory (me->content_type);
515:
516: if (me->formdata)
517: HTAssocList_delete (me->formdata);
518:
519: /* to trace bugs */
520: memset ((void *) me, 0, sizeof (AHTReqContext));
521:
522: TtaFreeMemory ((void *) me);
523:
524: Amaya->open_requests--;
525:
526: return TRUE;
1.7 cvs 527: }
1.15 cvs 528: return FALSE;
1.4 cvs 529: }
530:
531:
1.15 cvs 532: /*----------------------------------------------------------------------
1.17 cvs 533: Thread_deleteAll
534: this function deletes the whole list of active threads.
1.5 cvs 535: ----------------------------------------------------------------------*/
1.4 cvs 536: #ifdef __STDC__
537: static void Thread_deleteAll (void)
538: #else
539: static void Thread_deleteAll ()
540: #endif
541: {
1.21 cvs 542: HTList *cur;
543: AHTReqContext *me;
544: AHTDocId_Status *docid_status;
545:
1.74 cvs 546: if (Amaya && Amaya->reqlist)
547: {
548: if (Amaya->open_requests > 0)
549: #ifdef DEBUG_LIBWWW
550: fprintf (stderr, "Thread_deleteAll: Killing %d outstanding "
551: "requests\n", Amaya->open_requests);
552: #endif
553: {
554: cur = Amaya->reqlist;
555:
556: /* erase the requests */
557: while ((me = (AHTReqContext *) HTList_removeLastObject (cur)))
558: {
559: if (me->request)
560: {
1.142 cvs 561: #ifndef _WINDOWS
562: #ifdef WWW_XWINDOWS
1.74 cvs 563: RequestKillAllXtevents (me);
1.142 cvs 564: #endif /* WWW_XWINDOWS */
1.138 cvs 565: #endif /* !_WINDOWS */
1.140 cvs 566: if (!HTRequest_kill (me->request))
567: AHTReqContext_delete (me);
1.74 cvs 568: }
569: } /* while */
570:
571: /* erase the docid_status entities */
572: while ((docid_status = (AHTDocId_Status *) HTList_removeLastObject ((void *) Amaya->docid_status)))
573: TtaFreeMemory ((void *) docid_status);
574:
575: } /* if */
1.84 cvs 576:
1.74 cvs 577: }
1.4 cvs 578: }
1.198 cvs 579:
1.5 cvs 580: /*----------------------------------------------------------------------
1.83 cvs 581: AHTOpen_file
582: ----------------------------------------------------------------------*/
583: #ifdef __STDC__
1.85 cvs 584: int AHTOpen_file (HTRequest * request)
1.83 cvs 585: #else
1.85 cvs 586: int AHTOpen_file (request)
1.83 cvs 587: HTRequest *request;
588:
589: #endif /* __STDC__ */
590: {
591: AHTReqContext *me; /* current request */
592:
593: me = HTRequest_context (request);
594:
1.93 cvs 595: if (!me)
596: return HT_ERROR;
597:
1.83 cvs 598: #ifdef DEBUG_LIBWWW
1.116 cvs 599: fprintf(stderr, "AHTOpen_file: start for object : %p\n", me);
1.85 cvs 600: #endif /* DEBUG_LIBWWW */
601:
602: if (me->reqStatus == HT_ABORT)
603: {
604: #ifdef DEBUG_LIBWWW
605: fprintf(stderr, "AHTOpen_file: caught an abort request, skipping it\n");
1.83 cvs 606: #endif /* DEBUG_LIBWWW */
607:
1.85 cvs 608: return HT_OK;
609: }
610:
1.136 cvs 611: if (me->method == METHOD_PUT)
612: {
613: me->reqStatus = HT_WAITING;
614: return HT_OK;
615: }
616:
1.85 cvs 617: if (HTRequest_outputStream (me->request))
618: {
619:
620: #ifdef DEBUG_LIBWWW
621: fprintf(stderr, "AHTOpen_file: output stream already existed for url %s\n", me->urlName);
622: #endif /* DEBUG_LIBWWW */
623: return HT_OK;
624: }
625:
626: #ifdef DEBUG_LIBWWW
627: fprintf(stderr, "AHTOpen_file: opening output stream for url %s\n", me->urlName);
628: #endif /* DEBUG_LIBWWW */
629:
1.83 cvs 630: if (!(me->output) &&
631: (me->output != stdout) &&
632: #ifndef _WINDOWS
633: (me->output = fopen (me->outputfile, "w")) == NULL)
634: {
1.116 cvs 635: #else /* !_WINDOWS */
1.83 cvs 636: (me->output = fopen (me->outputfile, "wb")) == NULL)
637: {
638: #endif /* !_WINDOWS */
639:
1.131 cvs 640: me->outputfile[0] = EOS; /* file could not be opened */
1.85 cvs 641: #ifdef DEBUG_LIBWWW
642: fprintf(stderr, "AHTOpen_file: couldn't open output stream for url %s\n", me->urlName);
643: #endif
1.83 cvs 644: TtaSetStatus (me->docid, 1,
645: TtaGetMessage (AMAYA, AM_CANNOT_CREATE_FILE),
1.198 cvs 646: ISO2WideChar (me->outputfile));
1.83 cvs 647: me->reqStatus = HT_ERR;
648: return (HT_ERROR);
649: }
650:
651: HTRequest_setOutputStream (me->request,
652: AHTFWriter_new (me->request,
653: me->output, YES));
654: me->reqStatus = HT_WAITING;
655:
656: return HT_OK;
657: }
658:
659: /*----------------------------------------------------------------------
1.17 cvs 660: redirection_handler
661: this function is registered to handle permanent and temporary
662: redirections.
663: ----------------------------------------------------------------------*/
1.4 cvs 664: #ifdef __STDC__
1.7 cvs 665: static int redirection_handler (HTRequest * request, HTResponse * response, void *param, int status)
1.4 cvs 666: #else
667: static int redirection_handler (request, context, status)
668: HTRequest *request;
669: HTResponse *response;
670: void *param;
671: int status;
672:
673: #endif
674: {
675:
676: HTAnchor *new_anchor = HTResponse_redirection (response);
1.7 cvs 677: AHTReqContext *me = HTRequest_context (request);
1.4 cvs 678: HTMethod method = HTRequest_method (request);
1.198 cvs 679: STRING ref;
1.206 cvs 680: STRING escape_src, dst;
1.98 cvs 681: char *tmp;
1.4 cvs 682:
1.153 cvs 683: if (!me)
684: /* if the redirect doesn't come from Amaya, we call libwww's standard
685: redirect filter */
686: return (HTRedirectFilter (request, response, param, status));
687:
1.7 cvs 688: if (!new_anchor)
689: {
690: if (PROT_TRACE)
691: HTTrace ("Redirection. No destination\n");
692: return HT_OK;
693: }
1.4 cvs 694:
695: /*
1.207 cvs 696: ** Only do redirect on GET, HEAD, and authorized domains for PUT
1.4 cvs 697: */
1.207 cvs 698: if ((me->method == METHOD_PUT && !SafePut_query (me->urlName))
699: || (me->method != METHOD_PUT && !HTMethod_isSafe (method)))
1.7 cvs 700: {
1.130 cvs 701: /*
702: ** If we got a 303 See Other then change the method to GET.
703: ** Otherwise ask the user whether we should continue.
704: */
705: if (status == HT_SEE_OTHER)
706: {
707: if (PROT_TRACE)
708: HTTrace("Redirection. Changing method from %s to GET\n",
709: HTMethod_name(method));
710: HTRequest_setMethod(request, METHOD_GET);
711: }
712: else
713: {
714: HTAlertCallback *prompt = HTAlert_find (HT_A_CONFIRM);
715: if (prompt)
716: {
717: if ((*prompt) (request, HT_A_CONFIRM, HT_MSG_REDIRECTION,
718: NULL, NULL, NULL) != YES)
1.153 cvs 719: return HT_OK;
1.130 cvs 720: }
721: }
1.7 cvs 722: }
1.4 cvs 723: /*
724: ** Start new request with the redirect anchor found in the headers.
725: ** Note that we reuse the same request object which means that we must
726: ** keep this around until the redirected request has terminated. It also
727: ** allows us in an easy way to keep track of the number of redirections
728: ** so that we can detect endless loops.
729: */
1.166 cvs 730:
1.7 cvs 731: if (HTRequest_doRetry (request))
732: {
1.174 cvs 733: /*
734: ** Start request with new credentials
735: */
736:
1.166 cvs 737: /* only do a redirect using a network protocol understood by Amaya */
1.198 cvs 738: if (IsValidProtocol (ISO2WideChar (new_anchor->parent->address)))
1.7 cvs 739: {
1.166 cvs 740: /* if it's a valid URL, we try to normalize it */
1.206 cvs 741: /* We use the pre-redirection anchor as a base name */
742: dst = ISO2WideChar (new_anchor->parent->address);
743: escape_src = EscapeURL (ISO2WideChar (me->urlName));
744: if (escape_src)
745: {
746: ref = AmayaParseUrl (dst, escape_src, AMAYA_PARSE_ALL);
747: TtaFreeMemory (escape_src);
748: }
749: else
750: ref = NULL;
751:
1.7 cvs 752: if (ref)
753: {
1.98 cvs 754: HT_FREE (new_anchor->parent->address);
1.217 cvs 755: new_anchor->parent->address = NULL;
1.98 cvs 756: tmp = NULL;
1.198 cvs 757: HTSACopy (&tmp, WideChar2ISO (ref));
1.98 cvs 758: new_anchor->parent->address = tmp;
759: TtaFreeMemory (ref);
1.7 cvs 760: }
1.98 cvs 761: else
1.166 cvs 762: return HT_OK; /* We can't redirect anymore */
1.7 cvs 763: }
1.166 cvs 764: else
765: return HT_OK; /* We can't redirect anymore */
1.7 cvs 766:
767: /* update the current file name */
1.206 cvs 768: if ((me->mode & AMAYA_ASYNC)
769: || (me->mode & AMAYA_IASYNC)
770: || (me->method == METHOD_PUT))
1.7 cvs 771: {
1.130 cvs 772: TtaFreeMemory (me->urlName);
1.198 cvs 773: me->urlName = WideChar2ISO (TtaStrdup (ISO2WideChar (new_anchor->parent->address)));
1.7 cvs 774: }
775: else
1.130 cvs 776: /* it's a SYNC mode, so we should keep the urlName */
777: {
778: strncpy (me->urlName, new_anchor->parent->address,
779: MAX_LENGTH - 1);
780: me->urlName[MAX_LENGTH - 1] = EOS;
781: }
1.38 cvs 782: ChopURL (me->status_urlName, me->urlName);
1.116 cvs 783:
1.190 cvs 784: /* @@ verify if this is important */
785: /* @@@ new libwww doesn't need this free stream while making
786: a PUT. Is it the case everywhere or just for PUT? */
787: if (me->method != METHOD_PUT
1.192 cvs 788: && me->request->orig_output_stream != NULL)
789: {
790: AHTFWriter_FREE (me->request->orig_output_stream);
791: me->request->orig_output_stream = NULL;
792: if (me->output != stdout) { /* Are we writing to a file? */
1.74 cvs 793: #ifdef DEBUG_LIBWWW
1.192 cvs 794: fprintf (stderr, "redirection_handler: New URL is %s, closing "
795: "FILE %p\n", me->urlName, me->output);
1.74 cvs 796: #endif
1.192 cvs 797: fclose (me->output);
798: me->output = NULL;
799: }
1.79 cvs 800: }
1.68 cvs 801:
1.174 cvs 802: /* tell the user what we're doing */
803: TtaSetStatus (me->docid, 1, TtaGetMessage (AMAYA, AM_RED_FETCHING),
1.198 cvs 804: ISO2WideChar (me->status_urlName));
1.174 cvs 805:
806:
1.171 cvs 807: /*
808: ** launch the request
809: */
1.192 cvs 810: /* add a link relationship? */
1.174 cvs 811: /* reset the request status */
1.116 cvs 812: me->reqStatus = HT_NEW;
1.105 cvs 813: /* clear the errors */
1.116 cvs 814: HTError_deleteAll (HTRequest_error (request));
1.105 cvs 815: HTRequest_setError (request, NULL);
1.192 cvs 816: /* clear the authentication credentials, as they get regenerated */
1.174 cvs 817: HTRequest_deleteCredentialsAll (request);
818:
1.171 cvs 819: if (me->method == METHOD_POST
820: || me->method == METHOD_PUT) /* PUT, POST etc. */
821: status = HTLoadAbsolute (me->urlName, request);
1.7 cvs 822: else
1.74 cvs 823: HTLoadAnchor (new_anchor, request);
1.7 cvs 824: }
825: else
1.68 cvs 826: {
1.74 cvs 827: HTRequest_addError (request, ERR_FATAL, NO, HTERR_MAX_REDIRECT,
828: NULL, 0, "HTRedirectFilter");
829: TtaSetStatus (me->docid, 1, TtaGetMessage (AMAYA, AM_REDIRECTIONS_LIMIT),
830: NULL);
1.173 cvs 831: /* so that we can show the error message */
1.74 cvs 832: if (me->error_html)
1.173 cvs 833: DocNetworkStatus[me->docid] |= AMAYA_NET_ERROR;
834: me->reqStatus = HT_ERR;
1.68 cvs 835: }
836:
1.4 cvs 837: /*
1.74 cvs 838: ** By returning HT_ERROR we make sure that this is the last handler to be
839: ** called. We do this as we don't want any other filter to delete the
840: ** request object now when we have just started a new one ourselves
841: */
1.4 cvs 842: return HT_ERROR;
843: }
844:
1.151 cvs 845: #ifdef AMAYA_LOST_UPDATE
846: /*----------------------------------------------------------------------
847: precondition_handler
848: 412 "Precondition failed" handler
849: ----------------------------------------------------------------------*/
850: #if __STDC__
851: static int precondition_handler (HTRequest * request, HTResponse * response, void *context, int status)
852: #else
853: static int precondition_handler (request, response, context, status)
854: HTRequest *request;
855: HTResponse *response;
856: void *context;
857: int status;
858: #endif /* __STDC__ */
859: {
1.168 cvs 860: AHTReqContext *me = (AHTReqContext *) HTRequest_context (request);
861: HTAlertCallback *prompt = HTAlert_find (HT_A_CONFIRM);
1.191 cvs 862: ThotBool force_put;
1.151 cvs 863:
864: if (!me)
865: return HT_OK; /* not an Amaya request */
866:
1.168 cvs 867: if (prompt)
868: force_put = (*prompt) (request, HT_A_CONFIRM, HT_MSG_RULES,
869: NULL, NULL, NULL);
870: else
871: force_put = NO;
872:
873: if (force_put)
874: {
875: /* start a new PUT request without preconditions */
876: /* @@ do we need to kill the request? */
877: if (me->output && me->output != stdout)
878: {
879: fclose (me->output);
880: me->output = NULL;
881: }
882: /*
883: ** reset the Amaya and libwww request status
884: */
1.176 cvs 885:
886: /* start with a new, clean request structure */
887: HTRequest_delete (me->request);
888: me->request = HTRequest_new ();
889: /* clean the associated file structure) */
890: HTRequest_setOutputStream (me->request, NULL);
891: /* Initialize the other members of the structure */
1.171 cvs 892: HTRequest_setMethod (me->request, METHOD_GET);
1.176 cvs 893: HTRequest_setOutputFormat (me->request, WWW_SOURCE);
894: HTRequest_setContext (me->request, me);
895: HTRequest_setPreemptive (me->request, NO);
896: /*
897: ** Make sure that the first request is flushed immediately and not
898: ** buffered in the output buffer
899: */
900: if (me->mode & AMAYA_FLUSH_REQUEST)
901: HTRequest_setFlush(me->request, YES);
902:
1.171 cvs 903: /* turn off preconditions */
904: HTRequest_setPreconditions(me->request, HT_NO_MATCH);
905: me->reqStatus = HT_NEW;
906: /* make the request */
1.176 cvs 907: status = HTPutDocumentAnchor (HTAnchor_parent (me->source),
908: me->dest, me->request);
1.168 cvs 909: /* stop here */
910: return HT_ERROR;
911: }
912: else
913: {
914: /* abort the request */
915: /* @@ should we call StopRequest here? */
916: me->reqStatus = HT_ABORT;
917: /* stop here */
918: return HT_ERROR;
919: }
920: }
1.151 cvs 921:
1.168 cvs 922: /*----------------------------------------------------------------------
923: check_handler
924: Request HEAD checker filter
925: ----------------------------------------------------------------------*/
926: static int check_handler (HTRequest * request, HTResponse * response,
1.151 cvs 927: void * param, int status)
928: {
1.168 cvs 929: AHTReqContext *me = (AHTReqContext *) HTRequest_context (request);
930: HTAlertCallback *prompt = HTAlert_find (HT_A_CONFIRM);
1.191 cvs 931: ThotBool force_put;
1.168 cvs 932:
933: if (!me)
934: return HT_OK; /* not an Amaya request */
935:
936: HTRequest_deleteAfter(me->request, check_handler);
937: /*
938: ** If head request showed that the document doesn't exist
939: ** then just go ahead and PUT it. Otherwise ask for help
940: */
941: if (status == HT_ERROR || status == HT_INTERRUPTED || status == HT_TIMEOUT)
942: {
943: /* we'd need to call terminate_handler, to free the resources */
944: /* abort the request */
945: /* @@ should we call StopRequest here? */
946: me->reqStatus = HT_ABORT;
947: /* stop here */
948: return HT_ERROR;
949: }
950: else if (status == HT_NO_ACCESS || status == HT_NO_PROXY_ACCESS)
951: {
952: /* we'd need to call terminate_handler, to free the resources */
953: /* abort the request */
954: /* @@ should we call StopRequest here? */
955: me->reqStatus = HT_ABORT;
956: /* stop here */
957: return HT_ERROR;
958: }
959: else if ( (abs(status)/100) != 2)
960: {
1.176 cvs 961: /* start with a new, clean request structure */
962: HTRequest_delete (me->request);
963: me->request = HTRequest_new ();
1.208 cvs 964: /* add the default PUT name */
965: HTRequest_setDefaultPutName (me->request, me->default_put_name);
1.176 cvs 966: /* clean the associated file structure) */
967: HTRequest_setOutputStream (me->request, NULL);
968: /* Initialize the other members of the structure */
1.171 cvs 969: HTRequest_setMethod (me->request, METHOD_GET);
1.176 cvs 970: HTRequest_setOutputFormat (me->request, WWW_SOURCE);
971: HTRequest_setContext (me->request, me);
972: HTRequest_setPreemptive (me->request, NO);
973: /*
974: ** Make sure that the first request is flushed immediately and not
975: ** buffered in the output buffer
976: */
977: if (me->mode & AMAYA_FLUSH_REQUEST)
978: HTRequest_setFlush(me->request, YES);
979:
980: /* turn on the special preconditions, to avoid having this
981: ressource appear before we do the PUT */
1.168 cvs 982: HTRequest_setPreconditions(me->request, HT_DONT_MATCH_ANY);
1.171 cvs 983: me->reqStatus = HT_NEW;
1.168 cvs 984: status = HTPutDocumentAnchor (HTAnchor_parent (me->source), me->dest, me->request);
985: return HT_ERROR; /* stop here */
1.176 cvs 986: }
1.168 cvs 987: else
988: {
989: if (prompt)
990: force_put = (*prompt) (request, HT_A_CONFIRM, HT_MSG_FILE_REPLACE,
991: NULL, NULL, NULL);
992: else
993: force_put = FALSE;
994:
995: if (force_put)
1.151 cvs 996: {
997: /* Start a new PUT request without preconditions */
1.176 cvs 998:
999: /* get a new, clean request structure */
1000: HTRequest_delete (me->request);
1001: me->request = HTRequest_new ();
1.208 cvs 1002: /* add the default PUT name */
1003: HTRequest_setDefaultPutName (me->request, me->default_put_name);
1.176 cvs 1004: /* clean the associated file structure) */
1005: HTRequest_setOutputStream (me->request, NULL);
1006: /* Initialize the other members of the structure */
1.171 cvs 1007: HTRequest_setMethod (me->request, METHOD_GET);
1.176 cvs 1008: HTRequest_setOutputFormat (me->request, WWW_SOURCE);
1009: HTRequest_setContext (me->request, me);
1010: HTRequest_setPreemptive (me->request, NO);
1011: /*
1012: ** Make sure that the first request is flushed immediately and not
1013: ** buffered in the output buffer
1014: */
1015: if (me->mode & AMAYA_FLUSH_REQUEST)
1016: HTRequest_setFlush(me->request, YES);
1017: /* remove the preconditions */
1.168 cvs 1018: HTRequest_setPreconditions(me->request, HT_NO_MATCH);
1.171 cvs 1019: me->reqStatus = HT_NEW;
1.176 cvs 1020: status = HTPutDocumentAnchor (HTAnchor_parent (me->source),
1021: me->dest, me->request);
1.168 cvs 1022: return HT_ERROR; /* stop here */
1.151 cvs 1023: }
1.168 cvs 1024: else
1025: {
1026: /* we'd need to call terminate_handler, to free the resources */
1027: /* abort the request */
1028: /* @@ should we call StopRequest here? */
1029: me->reqStatus = HT_ABORT;
1030: /* stop here */
1031: return HT_ERROR;
1032: }
1033: }
1034: return HT_ERROR;
1.151 cvs 1035: }
1036: #endif /* AMAYA_LOST_UPDATE */
1037:
1.5 cvs 1038: /*----------------------------------------------------------------------
1.17 cvs 1039: terminate_handler
1040: this function is registered to handle the result of the request
1.5 cvs 1041: ----------------------------------------------------------------------*/
1.4 cvs 1042: #if __STDC__
1.7 cvs 1043: static int terminate_handler (HTRequest * request, HTResponse * response, void *context, int status)
1.4 cvs 1044: #else
1045: static int terminate_handler (request, response, context, status)
1046: HTRequest *request;
1047: HTResponse *response;
1048: void *context;
1049: int status;
1.123 cvs 1050: #endif /* __STDC__ */
1.4 cvs 1051: {
1.116 cvs 1052: AHTReqContext *me = (AHTReqContext *) HTRequest_context (request);
1.191 cvs 1053: ThotBool error_flag;
1.116 cvs 1054: char *content_type;
1.184 cvs 1055: HTParentAnchor *anchor;
1.116 cvs 1056:
1057: if (!me)
1.214 cvs 1058: return HT_ERROR; /* not an Amaya request */
1.116 cvs 1059:
1060: if (me->reqStatus == HT_END)
1061: /* we have already processed this request! */
1062: return HT_OK;
1063:
1064: /* if Amaya was killed, treat with this request as if it were
1065: issued by a Stop button event */
1066:
1067: if (!AmayaIsAlive ())
1.80 cvs 1068: me->reqStatus = HT_ABORT;
1.74 cvs 1069:
1.77 cvs 1070: if (status == HT_LOADED ||
1071: status == HT_CREATED ||
1.79 cvs 1072: status == HT_NO_DATA ||
1.160 cvs 1073: /* kludge for work around libwww problem */
1074: (status == HT_INTERRUPTED && me->method == METHOD_PUT) ||
1.116 cvs 1075: #ifdef AMAYA_WWW_CACHE
1076: /* what status to use to know we're downloading from a cache? */
1077: status == HT_NOT_MODIFIED ||
1078: #endif /* AMAYA_WWW_CACHE */
1.79 cvs 1079: me->reqStatus == HT_ABORT)
1.74 cvs 1080: error_flag = FALSE;
1.13 cvs 1081: else
1.74 cvs 1082: error_flag = TRUE;
1.130 cvs 1083:
1.4 cvs 1084: /* output any errors from the server */
1.130 cvs 1085:
1.77 cvs 1086: /*
1.74 cvs 1087: ** me->output = output file which will receive an html file
1088: ** me->error_html = yes, output HTML errors in the screen
1089: ** request->error_stack == if there are any errors, they will be here
1090: ** me->error_stream_size If it's != 0 means an error message has already
1091: ** been written to the stack
1092: */
1093:
1.4 cvs 1094: /* First, we verify if there are any errors and if they are not
1.17 cvs 1095: ** yet written to the error stack. If no, then let's try to write them
1096: ** ourselves
1097: */
1.74 cvs 1098:
1099: #ifdef DEBUG_LIBWWW
1100: fprintf (stderr, "terminate_handler: URL is "
1101: "%s, closing FILE %p status is %d\n", me->urlName, me->output,
1102: status);
1.69 cvs 1103: #endif
1.74 cvs 1104:
1.69 cvs 1105: if (me->output && me->output != stdout)
1106: {
1.214 cvs 1107: /* we are writing to a local file */
1.74 cvs 1108: if (me->reqStatus != HT_ABORT)
1109: { /* if the request was not aborted and */
1.80 cvs 1110: if (error_flag &&
1111: me->error_html == TRUE)
1112: /* there were some errors and we want to print them */
1113: {
1114: if (me->error_stream_size == 0)/* and the stream is empty */
1.210 cvs 1115: {
1116: /* if the transfer was interrupted, the file may not be
1117: empty. So, we erase it */
1118: fflush (me->output);
1119: rewind (me->output);
1120: AHTError_MemPrint (request); /* copy errors from
1121: **the error stack
1122: ** into the error stream */
1123: }
1.80 cvs 1124: if (me->error_stream)
1125: { /* if the stream is non-empty */
1126: fprintf (me->output, me->error_stream);/* output the errors */
1.85 cvs 1127: /* Clear the error context, so that we can deal with
1128: this answer as if it were a normal reply */
1129: HTError_deleteAll( HTRequest_error (request));
1130: HTRequest_setError (request, NULL);
1131: error_flag = 0;
1.74 cvs 1132: }
1133: } /* if error_stack */
1.85 cvs 1134: }
1135:
1136: /* if != HT_ABORT */
1137:
1138: #ifdef DEBUG_LIBWWW
1139: fprintf (stderr, "terminate_handler: URL is %s, closing "
1140: "FILE %p\n", me->urlName, me->output);
1141: #endif
1.74 cvs 1142: fclose (me->output);
1143: me->output = NULL;
1.69 cvs 1144: }
1.80 cvs 1145:
1.214 cvs 1146: /* a very special handling so that we can put a message box
1147: to tell the user WHAT he has just done... */
1148: if (UserAborted_flag && me->method == METHOD_PUT)
1149: {
1150: HTRequest_addError (request, ERR_FATAL, NO, HTERR_INTERRUPTED,
1151: "Operation aborted by user", 0, NULL);
1152: }
1153:
1.80 cvs 1154: if (error_flag)
1155: me->reqStatus = HT_ERR;
1.214 cvs 1156: else
1157: if (me->reqStatus != HT_ABORT)
1158: me->reqStatus = HT_END;
1159:
1.116 cvs 1160: /* copy the content_type */
1.151 cvs 1161: if (!me->content_type)
1.88 cvs 1162: {
1.184 cvs 1163: anchor = HTRequest_anchor (request);
1164: if (anchor && HTAnchor_format (anchor))
1165: content_type = HTAtom_name (HTAnchor_format (anchor));
1.154 cvs 1166: else
1167: content_type = "www/unknown";
1168:
1.151 cvs 1169: if (content_type && content_type [0] != EOS)
1170: {
1171: /* libwww gives www/unknown when it gets an error. As this is
1172: an HTML test, we force the type to text/html */
1173: if (!strcmp (content_type, "www/unknown"))
1.198 cvs 1174: me->content_type = WideChar2ISO (TtaStrdup (TEXT("text/html")));
1.151 cvs 1175: else
1.198 cvs 1176: me->content_type = WideChar2ISO (TtaStrdup (ISO2WideChar (content_type)));
1.151 cvs 1177:
1178: /* Content-Type can be specified by an httpd server's admin.
1179: To be on the safe side, we normalize its case */
1.198 cvs 1180: ConvertToLowerCase (ISO2WideChar (me->content_type));
1.151 cvs 1181:
1.88 cvs 1182: #ifdef DEBUG_LIBWWW
1.151 cvs 1183: fprintf (stderr, "content type is: %s\n", me->content_type);
1.88 cvs 1184: #endif /* DEBUG_LIBWWW */
1.151 cvs 1185: }
1186: }
1.114 cvs 1187:
1.115 cvs 1188: /* to avoid a hangup while downloading css files */
1.140 cvs 1189: if (AmayaAlive_flag && (me->mode & AMAYA_LOAD_CSS))
1.116 cvs 1190: TtaSetStatus (me->docid, 1,
1191: TtaGetMessage (AMAYA, AM_ELEMENT_LOADED),
1.198 cvs 1192: ISO2WideChar (me->status_urlName));
1.116 cvs 1193:
1194: /* don't remove or Xt will hang up during the PUT */
1195: if (AmayaIsAlive () && ((me->method == METHOD_POST) ||
1196: (me->method == METHOD_PUT)))
1.7 cvs 1197: {
1.80 cvs 1198: PrintTerminateStatus (me, status);
1199: }
1.114 cvs 1200:
1.111 cvs 1201: ProcessTerminateRequest (request, response, context, status);
1.116 cvs 1202:
1.151 cvs 1203: /* stop here */
1.150 cvs 1204: return HT_ERROR;
1.4 cvs 1205: }
1206:
1.5 cvs 1207: /*----------------------------------------------------------------------
1.17 cvs 1208: AHTLoadTerminate_handler
1.74 cvs 1209: this is an application "AFTER" Callback. It's called by the library
1210: when a request has ended, so that we can setup the correct status.
1.5 cvs 1211: ----------------------------------------------------------------------*/
1.4 cvs 1212:
1213: #ifdef __STDC__
1.111 cvs 1214: int AHTLoadTerminate_handler (HTRequest * request, HTResponse * response, void *param, int status)
1.4 cvs 1215: #else
1.111 cvs 1216: int AHTLoadTerminate_handler (request, response, param, status)
1.4 cvs 1217: HTRequest *request;
1218: HTResponse *response;
1219: void *param;
1220: int status;
1.69 cvs 1221:
1.4 cvs 1222: #endif
1223: {
1.116 cvs 1224:
1225: /** @@@@ use this with printstatus ?? */
1226:
1.4 cvs 1227: AHTReqContext *me = HTRequest_context (request);
1228: HTAlertCallback *cbf;
1229: AHTDocId_Status *docid_status;
1230:
1.7 cvs 1231: switch (status)
1.116 cvs 1232: {
1233: case HT_LOADED:
1234: if (PROT_TRACE)
1235: HTTrace ("Load End.... OK: `%s\' has been accessed\n",
1236: me->status_urlName);
1.4 cvs 1237:
1.116 cvs 1238: docid_status = GetDocIdStatus (me->docid,
1239: Amaya->docid_status);
1.7 cvs 1240:
1.116 cvs 1241: if (docid_status != NULL && docid_status->counter > 1)
1242: TtaSetStatus (me->docid, 1,
1243: TtaGetMessage (AMAYA, AM_ELEMENT_LOADED),
1.198 cvs 1244: ISO2WideChar (me->status_urlName));
1.7 cvs 1245: break;
1.116 cvs 1246:
1247: case HT_NO_DATA:
1248: if (PROT_TRACE)
1249: HTTrace ("Load End.... OK BUT NO DATA: `%s\'\n",
1250: me->status_urlName);
1251: TtaSetStatus (me->docid, 1,
1252: TtaGetMessage (AMAYA, AM_LOADED_NO_DATA),
1.198 cvs 1253: ISO2WideChar (me->status_urlName));
1.116 cvs 1254: break;
1255:
1256: case HT_INTERRUPTED:
1257: if (PROT_TRACE)
1258: HTTrace ("Load End.... INTERRUPTED: `%s\'\n",
1259: me->status_urlName);
1260: TtaSetStatus (me->docid, 1,
1261: TtaGetMessage (AMAYA, AM_LOAD_ABORT),
1262: NULL);
1263: break;
1.7 cvs 1264:
1.116 cvs 1265: case HT_RETRY:
1266: if (PROT_TRACE)
1267: HTTrace ("Load End.... NOT AVAILABLE, RETRY AT %ld\n",
1268: HTResponse_retryTime (response));
1269: TtaSetStatus (me->docid, 1,
1270: TtaGetMessage (AMAYA, AM_NOT_AVAILABLE_RETRY),
1.198 cvs 1271: ISO2WideChar (me->status_urlName));
1.116 cvs 1272: break;
1.7 cvs 1273:
1.116 cvs 1274: case HT_ERROR:
1275: cbf = HTAlert_find (HT_A_MESSAGE);
1276: if (cbf)
1277: (*cbf) (request, HT_A_MESSAGE, HT_MSG_NULL, NULL,
1278: HTRequest_error (request), NULL);
1279: break;
1280:
1281: if (PROT_TRACE)
1282: HTTrace ("Load End.... ERROR: Can't access `%s\'\n",
1283: me->status_urlName ? me->status_urlName :"<UNKNOWN>");
1284: TtaSetStatus (me->docid, 1,
1285: TtaGetMessage (AMAYA, AM_CANNOT_LOAD),
1.198 cvs 1286: me->status_urlName ? ISO2WideChar (me->status_urlName) : TEXT("<UNKNOWN>"));
1.116 cvs 1287: break;
1288: default:
1289: if (PROT_TRACE)
1290: HTTrace ("Load End.... UNKNOWN RETURN CODE %d\n", status);
1291: break;
1292: }
1293:
1294: return HT_OK;
1295: }
1.7 cvs 1296:
1.116 cvs 1297: #ifdef DEBUG_LIBWWW
1298: static int LineTrace (const char * fmt, va_list pArgs)
1299: {
1300: return (vfprintf(stderr, fmt, pArgs));
1.4 cvs 1301: }
1.116 cvs 1302: #endif DEBUG_LIBWWW
1.4 cvs 1303:
1.27 cvs 1304: /*----------------------------------------------------------------------
1305: AHTAcceptTypesInit
1.74 cvs 1306: This function prepares the Accept header used by Amaya during
1307: the HTTP content negotiation phase
1.27 cvs 1308: ----------------------------------------------------------------------*/
1309: #ifdef __STDC__
1310: static void AHTAcceptTypesInit (HTList *c)
1311: #else /* __STDC__ */
1312: static void AHTAcceptTypesInit (c)
1313: HTList *c;
1314: #endif /* __STDC__ */
1315: {
1316: if (c == (HTList *) NULL)
1317: return;
1318:
1319: /* define here all the mime types that Amaya can accept */
1320:
1.74 cvs 1321: HTConversion_add (c, "image/png", "www/present",
1322: HTThroughLine, 1.0, 0.0, 0.0);
1323: HTConversion_add (c, "image/jpeg", "www/present",
1324: HTThroughLine, 1.0, 0.0, 0.0);
1325: HTConversion_add (c, "image/gif", "www/present",
1326: HTThroughLine, 1.0, 0.0, 0.0);
1327: HTConversion_add (c, "image/xbm", "www/present",
1328: HTThroughLine, 1.0, 0.0, 0.0);
1329: HTConversion_add (c, "image/xpm", "www/present",
1330: HTThroughLine, 1.0, 0.0, 0.0);
1.183 cvs 1331:
1.27 cvs 1332: /* Define here the equivalences between MIME types and file extensions for
1333: the types that Amaya can display */
1334:
1.176 cvs 1335: /* Initialize suffix bindings for local files */
1336: HTBind_init();
1337:
1.27 cvs 1338: /* Register the default set of file suffix bindings */
1339: HTFileInit ();
1340:
1341: /* Don't do any case distinction */
1342: HTBind_caseSensitive (FALSE);
1343: }
1.4 cvs 1344:
1.5 cvs 1345: /*----------------------------------------------------------------------
1.193 cvs 1346: AHTAcceptLanguagesInit
1347: This function prepares the Accept header used by Amaya during
1348: the HTTP content negotiation phase
1349: ----------------------------------------------------------------------*/
1350: #ifdef __STDC__
1.196 cvs 1351: static void AHTAcceptLanguagesInit (HTList *c)
1.193 cvs 1352: #else /* __STDC__ */
1.196 cvs 1353: static void AHTAcceptLanguagesInit (c)
1.193 cvs 1354: HTList *c;
1355: #endif /* __STDC__ */
1356: {
1.196 cvs 1357: STRING ptr;
1358: STRING lang_list;
1359: CHAR_T s[3];
1360: int count, lg;
1361: double quality;
1362: ThotBool still;
1.193 cvs 1363:
1364: if (c == (HTList *) NULL)
1365: return;
1366:
1.203 cvs 1367: lang_list = TtaGetEnvString ("ACCEPT_LANGUAGES");
1.197 cvs 1368: s[2] = EOS;
1.196 cvs 1369: if (lang_list && *lang_list != EOS)
1.193 cvs 1370: {
1371: /* add the default language first */
1372: HTLanguage_add (c, "*", -1.0);
1373: /* how many languages do we have? */
1.196 cvs 1374: ptr = lang_list;
1375: count = 0;
1376: while (*ptr != EOS)
1377: {
1378: while (*ptr != EOS &&
1379: (*ptr < 'A' || (*ptr > 'Z' && *ptr < 'a') || *ptr > 'z'))
1380: /* skip the whole separator */
1381: ptr++;
1382: lg = 0;
1383: while ((*ptr >= 'A' && *ptr <= 'Z') || (*ptr >= 'a' && *ptr <= 'z') || *ptr == '-')
1384: {
1385: /* it's a new language */
1386: ptr++;
1387: lg++;
1388: }
1389: if (lg >= 2)
1.193 cvs 1390: count++;
1.196 cvs 1391: if (*ptr != EOS)
1392: ptr++;
1393: }
1.193 cvs 1394:
1.196 cvs 1395: if (count > 0)
1.193 cvs 1396: quality = 1.1 - (double) count/10.0;
1397: else
1398: quality = 1.0;
1399:
1.196 cvs 1400: /*
1401: Read the languages from the registry, then inject them one, by one.
1402: The first one is the one with the highest priority.
1403: The libwww ask for the lowest priority first.
1404: */
1405: ptr--;
1406: still = TRUE;
1407: while (count)
1.193 cvs 1408: {
1.196 cvs 1409: while (still &&
1410: (*ptr < 'A' || (*ptr > 'Z' && *ptr < 'a') || *ptr > 'z'))
1411: /* skip the whole separator */
1412: if (ptr > lang_list)
1413: ptr--;
1414: else
1415: still = FALSE;
1416: lg = 0;
1417: while (still &&
1418: ((*ptr >= 'A' && *ptr <= 'Z') || (*ptr >= 'a' && *ptr <= 'z') || *ptr == '-'))
1419: {
1420: /* it's a new language */
1421: if (ptr > lang_list)
1422: ptr--;
1423: else
1424: still = FALSE;
1425: lg++;
1426: }
1427: if (lg >= 2)
1428: {
1429: if (still)
1430: ustrncpy (s, &ptr[1], 2);
1431: else
1432: ustrncpy (s, lang_list, 2);
1433: count--;
1.198 cvs 1434: HTLanguage_add (c, WideChar2ISO(s), quality);
1.196 cvs 1435: quality += 0.1;
1436: }
1437: ptr--;
1.193 cvs 1438: }
1439: }
1440: }
1441:
1442: /*----------------------------------------------------------------------
1.17 cvs 1443: AHTConverterInit
1444: Bindings between a source media type and a destination media type
1445: (conversion).
1.5 cvs 1446: ----------------------------------------------------------------------*/
1.15 cvs 1447: #ifdef __STDC__
1448: static void AHTConverterInit (HTList *c)
1449: #else /* __STDC__ */
1450: static void AHTConverterInit (c)
1451: HTList *c;
1452: #endif /* __STDC__ */
1.4 cvs 1453: {
1454:
1455: /* Handler for custom http error messages */
1.7 cvs 1456: HTConversion_add (c, "*/*", "www/debug", AHTMemConverter, 1.0, 0.0, 0.0);
1.4 cvs 1457:
1458: /*
1459: ** These are converters that converts to something other than www/present,
1460: ** that is not directly outputting someting to the user on the screen
1461: */
1462:
1.116 cvs 1463: HTConversion_add (c, "message/rfc822", "*/*", HTMIMEConvert,
1464: 1.0, 0.0, 0.0);
1.4 cvs 1465: HTConversion_add (c, "message/x-rfc822-foot", "*/*", HTMIMEFooter,
1466: 1.0, 0.0, 0.0);
1467: HTConversion_add (c, "message/x-rfc822-head", "*/*", HTMIMEHeader,
1468: 1.0, 0.0, 0.0);
1.116 cvs 1469: HTConversion_add(c,"message/x-rfc822-cont", "*/*", HTMIMEContinue,
1470: 1.0, 0.0, 0.0);
1471: HTConversion_add(c,"message/x-rfc822-partial","*/*", HTMIMEPartial,
1472: 1.0, 0.0, 0.0);
1.4 cvs 1473: HTConversion_add (c, "multipart/*", "*/*", HTBoundary,
1474: 1.0, 0.0, 0.0);
1475: HTConversion_add (c, "text/plain", "text/html", HTPlainToHTML,
1476: 1.0, 0.0, 0.0);
1477:
1478: /*
1.116 cvs 1479: ** The following conversions are converting ASCII output from various
1480: ** protocols to HTML objects.
1481: */
1.4 cvs 1482: HTConversion_add (c, "text/x-http", "*/*", HTTPStatus_new,
1483: 1.0, 0.0, 0.0);
1484:
1485: /*
1.116 cvs 1486: ** We also register a special content type guess stream that can figure out
1487: ** the content type by reading the first bytes of the stream
1488: */
1.4 cvs 1489: HTConversion_add (c, "www/unknown", "*/*", HTGuess_new,
1490: 1.0, 0.0, 0.0);
1491:
1.116 cvs 1492: #ifdef AMAYA_WWW_CACHE
1.4 cvs 1493: /*
1.116 cvs 1494: ** Register a persistent cache stream which can save an object to local
1495: ** file
1496: */
1.4 cvs 1497: HTConversion_add (c, "www/cache", "*/*", HTCacheWriter,
1498: 1.0, 0.0, 0.0);
1.116 cvs 1499: HTConversion_add(c,"www/cache-append", "*/*", HTCacheAppend,
1500: 1.0, 0.0, 0.0);
1501: #endif AMAYA_WWW_CACHE
1.4 cvs 1502:
1503: /*
1.116 cvs 1504: ** This dumps all other formats to local disk without any further
1505: ** action taken
1506: */
1.4 cvs 1507: HTConversion_add (c, "*/*", "www/present", HTSaveLocally,
1.190 cvs 1508: 0.3, 0.0, 0.0);
1.4 cvs 1509: }
1510:
1.27 cvs 1511:
1.15 cvs 1512: /*----------------------------------------------------------------------
1.17 cvs 1513: AHTProtocolInit
1514: Registers all amaya supported protocols.
1.15 cvs 1515: ----------------------------------------------------------------------*/
1.4 cvs 1516: static void AHTProtocolInit (void)
1517: {
1.116 cvs 1518: char *strptr;
1.4 cvs 1519:
1.116 cvs 1520: /*
1521: NB. Preemptive == YES means Blocking requests
1522: Non-preemptive == NO means Non-blocking requests
1523: */
1524: HTTransport_add("tcp", HT_TP_SINGLE, HTReader_new, HTWriter_new);
1525: HTTransport_add("buffered_tcp", HT_TP_SINGLE, HTReader_new,
1526: HTBufferWriter_new);
1527: HTProtocol_add ("http", "buffered_tcp", HTTP_PORT, NO, HTLoadHTTP, NULL);
1.136 cvs 1528: #ifdef _WINDOWS
1529: HTProtocol_add ("file", "local", 0, YES, HTLoadFile, NULL);
1530: #else
1.116 cvs 1531: HTProtocol_add ("file", "local", 0, NO, HTLoadFile, NULL);
1.198 cvs 1532: #endif /* _WINDOWS */
1.116 cvs 1533: #ifdef AMAYA_WWW_CACHE
1534: HTProtocol_add("cache", "local", 0, YES, HTLoadCache, NULL);
1535: #endif /* AMAYA_WWW_CACHE */
1.103 cvs 1536: #if 0 /* experimental code */
1.116 cvs 1537: HTProtocol_add ("ftp", "tcp", FTP_PORT, NO, HTLoadFTP, NULL);
1.17 cvs 1538: #endif
1.116 cvs 1539:
1540: /* initialize pipelining */
1.203 cvs 1541: strptr = (char *) TtaGetEnvString ("ENABLE_PIPELINING");
1.116 cvs 1542: if (strptr && *strptr && strcasecmp (strptr,"yes" ))
1543: HTTP_setConnectionMode (HTTP_11_NO_PIPELINING);
1.4 cvs 1544: }
1545:
1.15 cvs 1546: /*----------------------------------------------------------------------
1.17 cvs 1547: AHTNetInit
1548: Reegisters "before" and "after" request filters.
1.15 cvs 1549: ----------------------------------------------------------------------*/
1.4 cvs 1550: static void AHTNetInit (void)
1551: {
1552:
1553: /* Register BEFORE filters
1.74 cvs 1554: ** The BEFORE filters handle proxies, caches, rule files etc.
1555: ** The filters are called in the order by which the are registered
1556: ** Not done automaticly - may be done by application!
1557: */
1.4 cvs 1558:
1.116 cvs 1559: HTNet_addBefore (HTCredentialsFilter, "http://*", NULL, HT_FILTER_LATE);
1560: HTNet_addBefore (HTProxyFilter, NULL, NULL, HT_FILTER_LATE);
1.85 cvs 1561: HTHost_setActivateRequestCallback (AHTOpen_file);
1.4 cvs 1562:
1563: /* register AFTER filters
1.74 cvs 1564: ** The AFTER filters handle error messages, logging, redirection,
1565: ** authentication etc.
1566: ** The filters are called in the order by which the are registered
1567: ** Not done automaticly - may be done by application!
1568: */
1.4 cvs 1569:
1.116 cvs 1570: HTNet_addAfter (HTAuthFilter, "http://*", NULL, HT_NO_ACCESS,
1571: HT_FILTER_MIDDLE);
1572: HTNet_addAfter(HTAuthFilter, "http://*", NULL, HT_REAUTH,
1573: HT_FILTER_MIDDLE);
1574: HTNet_addAfter (redirection_handler, "http://*", NULL, HT_PERM_REDIRECT,
1575: HT_FILTER_MIDDLE);
1576: HTNet_addAfter (redirection_handler, "http://*", NULL, HT_FOUND,
1577: HT_FILTER_MIDDLE);
1578: HTNet_addAfter (redirection_handler, "http://*", NULL, HT_SEE_OTHER,
1579: HT_FILTER_MIDDLE);
1580: HTNet_addAfter (redirection_handler, "http://*", NULL, HT_TEMP_REDIRECT,
1581: HT_FILTER_MIDDLE);
1.168 cvs 1582: HTNet_addAfter(HTAuthInfoFilter, "http://*", NULL, HT_ALL,
1583: HT_FILTER_MIDDLE);
1.116 cvs 1584: HTNet_addAfter (HTUseProxyFilter, "http://*", NULL, HT_USE_PROXY,
1585: HT_FILTER_MIDDLE);
1.151 cvs 1586: #ifdef AMAYA_LOST_UPDATE
1587: HTNet_addAfter (precondition_handler, NULL, NULL, HT_PRECONDITION_FAILED,
1588: HT_FILTER_MIDDLE);
1589: #endif /* AMAYA_LOST_UPDATE */
1.111 cvs 1590: #ifndef _WINDOWS
1.116 cvs 1591: HTNet_addAfter (AHTLoadTerminate_handler, NULL, NULL, HT_ALL,
1592: HT_FILTER_LAST);
1.111 cvs 1593: #endif /* !_WINDOWS */
1.116 cvs 1594: /**** for later ?? ****/
1595: /* HTNet_addAfter(HTInfoFilter, NULL, NULL, HT_ALL, HT_FILTER_LATE); */
1.51 cvs 1596: /* handles all errors */
1.116 cvs 1597: HTNet_addAfter (terminate_handler, NULL, NULL, HT_ALL, HT_FILTER_LAST);
1.4 cvs 1598: }
1599:
1.15 cvs 1600: /*----------------------------------------------------------------------
1.17 cvs 1601: AHTAlertInit
1602: Register alert messages and their callbacks.
1.15 cvs 1603: ----------------------------------------------------------------------*/
1604: #ifdef __STDC__
1605: static void AHTAlertInit (void)
1606: #else
1607: static void AHTAlertInit ()
1608: #endif
1609: {
1610: HTAlert_add (AHTProgress, HT_A_PROGRESS);
1.120 cvs 1611: #ifdef __WINDOWS
1.70 cvs 1612: HTAlert_add ((HTAlertCallback *) WIN_Activate_Request, HT_PROG_CONNECT);
1.116 cvs 1613: #endif /* _WINDOWS */
1.15 cvs 1614: HTAlert_add (AHTError_print, HT_A_MESSAGE);
1.48 cvs 1615: HTError_setShow (~((unsigned int) 0 ) & ~((unsigned int) HT_ERR_SHOW_DEBUG)); /* process all messages except debug ones*/
1.15 cvs 1616: HTAlert_add (AHTConfirm, HT_A_CONFIRM);
1617: HTAlert_add (AHTPrompt, HT_A_PROMPT);
1618: HTAlert_add (AHTPromptUsernameAndPassword, HT_A_USER_PW);
1.116 cvs 1619: }
1620:
1.128 cvs 1621: /*----------------------------------------------------------------------
1622: libwww_CleanCache
1623: frontend to the recursive cache cleaning function
1624: ----------------------------------------------------------------------*/
1625: #ifdef __STDC__
1626: void libwww_CleanCache (void)
1627: #else
1628: void libwww_CleanCache ()
1629: Document doc;
1630: View view;
1631: #endif /* __STDC__ */
1632: {
1.130 cvs 1633: #ifdef AMAYA_WWW_CACHE
1.198 cvs 1634: STRING real_dir;
1635: STRING cache_dir;
1636: STRING tmp;
1.128 cvs 1637: int cache_size;
1.177 cvs 1638: int cache_expire;
1639: int cache_disconnect;
1.191 cvs 1640: ThotBool error;
1.185 cvs 1641: STRING ptr;
1.130 cvs 1642:
1.128 cvs 1643: if (!HTCacheMode_enabled ())
1.183 cvs 1644: /* don't do anything if we're not using a cache */
1645: return;
1.128 cvs 1646: /* temporarily close down the cache, purge it, then restart */
1.198 cvs 1647: tmp = ISO2WideChar (HTCacheMode_getRoot ());
1.190 cvs 1648: /* don't do anything if we don't have a valid cache dir */
1649: if (!tmp || *tmp == EOS)
1650: return;
1651: cache_dir = TtaStrdup (tmp);
1.128 cvs 1652: cache_size = HTCacheMode_maxSize ();
1.177 cvs 1653: cache_expire = HTCacheMode_expires ();
1654: cache_disconnect = HTCacheMode_disconnected ();
1655:
1.185 cvs 1656: /* get something we can work on :) */
1.198 cvs 1657: tmp = ISO2WideChar (HTWWWToLocal (WideChar2ISO (cache_dir), "file:", NULL));
1658: real_dir = TtaAllocString (ustrlen (tmp) + 20);
1659: ustrcpy (real_dir, tmp);
1.190 cvs 1660: HT_FREE (tmp);
1.185 cvs 1661:
1662: /* safeguard... abort the operation if cache_dir doesn't end with
1663: CACHE_DIR_NAME */
1664: error = TRUE;
1.198 cvs 1665: ptr = ustrstr (real_dir, CACHE_DIR_NAME);
1666: if (ptr && *ptr && !ustrcasecmp (ptr, CACHE_DIR_NAME))
1.185 cvs 1667: error = FALSE;
1668: if (error)
1669: return;
1670:
1.130 cvs 1671: /* remove the concurrent cache lock */
1672: #ifdef DEBUG_LIBWWW
1673: fprintf (stderr, "Clearing the cache lock\n");
1674: #endif /* DEBUG_LIBWWW */
1675: clear_cachelock ();
1.128 cvs 1676: HTCacheTerminate ();
1.185 cvs 1677: HTCacheMode_setEnabled (FALSE);
1678:
1679: RecCleanCache (real_dir);
1.128 cvs 1680:
1.177 cvs 1681: HTCacheMode_setExpires (cache_expire);
1682: HTCacheMode_setDisconnected (cache_disconnect);
1.198 cvs 1683: HTCacheInit (WideChar2ISO (cache_dir), cache_size);
1.130 cvs 1684: /* set a new concurrent cache lock */
1.198 cvs 1685: ustrcat (real_dir, TEXT(".lock"));
1.185 cvs 1686: if (set_cachelock (real_dir) == -1)
1.130 cvs 1687: /* couldn't open the .lock file, so, we close the cache to
1688: be in the safe side */
1689: {
1690: #ifdef DEBUG_LIBWWW
1691: fprintf (stderr, "couldnt set the cache lock\n");
1692: #endif /* DEBUG_LIBWWW */
1693: HTCacheTerminate ();
1.185 cvs 1694: HTCacheMode_setEnabled (FALSE);
1.130 cvs 1695: }
1696: #ifdef DEBUG_LIBWWW
1697: fprintf (stderr, "set a cache lock\n");
1698: #endif /* DEBUG_LIBWWW */
1.185 cvs 1699: TtaFreeMemory (real_dir);
1.128 cvs 1700: TtaFreeMemory (cache_dir);
1701: #endif /* AMAYA_WWW_CACHE */
1702: }
1703:
1.118 cvs 1704: #ifdef AMAYA_WWW_CACHE
1705: /*----------------------------------------------------------------------
1.128 cvs 1706: RecCleanCache
1.118 cvs 1707: Clears an existing cache directory
1708: ----------------------------------------------------------------------*/
1709: #ifdef __STDC__
1.198 cvs 1710: static void RecCleanCache (STRING dirname)
1.118 cvs 1711: #else
1.198 cvs 1712: static void RecCleanCache (dirname)
1713: STRING dirname;
1.118 cvs 1714: #endif /* __STDC__ */
1.128 cvs 1715:
1716: #ifdef _WINDOWS
1717: {
1718: HANDLE hFindFile;
1.191 cvs 1719: ThotBool status;
1.128 cvs 1720: WIN32_FIND_DATA ffd;
1721:
1.198 cvs 1722: CHAR_T t_dir [MAX_LENGTH];
1723: STRING ptr;
1.128 cvs 1724:
1.130 cvs 1725: /* create a t_dir name to start searching for files */
1.198 cvs 1726: if ((ustrlen (dirname) + 10) > MAX_LENGTH)
1.128 cvs 1727: /* ERROR: directory name is too big */
1728: return;
1729:
1.198 cvs 1730: ustrcpy (t_dir, dirname);
1.130 cvs 1731: /* save the end of the dirname. We'll use it to make
1732: a complete pathname when erasing files */
1.198 cvs 1733: ptr = &t_dir[ustrlen (t_dir)];
1734: ustrcat (t_dir, TEXT("*"));
1.128 cvs 1735:
1.130 cvs 1736: hFindFile = FindFirstFile (t_dir, &ffd);
1.128 cvs 1737:
1738: if (hFindFile == INVALID_HANDLE_VALUE)
1739: /* nothing to erase? */
1740: return;
1741:
1742: status = TRUE;
1.130 cvs 1743: while (status)
1744: {
1745: if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
1.133 cvs 1746: {
1747: /* it's a directory, erase it recursively */
1.198 cvs 1748: if (ustrcmp (ffd.cFileName, TEXT("..")) && ustrcmp (ffd.cFileName, TEXT(".")))
1.133 cvs 1749: {
1.198 cvs 1750: ustrcpy (ptr, ffd.cFileName);
1751: ustrcat (ptr, DIR_STR);
1.133 cvs 1752: RecCleanCache (t_dir);
1.198 cvs 1753: urmdir (t_dir);
1.133 cvs 1754: }
1755: }
1756: else
1.130 cvs 1757: {
1.133 cvs 1758: /* it's a file, erase it */
1.198 cvs 1759: ustrcpy (ptr, ffd.cFileName);
1.133 cvs 1760: TtaFileUnlink (t_dir);
1.130 cvs 1761: }
1762: status = FindNextFile (hFindFile, &ffd);
1763: }
1.128 cvs 1764: FindClose (hFindFile);
1765: }
1766:
1767: #else /* _WINDOWS */
1.118 cvs 1768: {
1769: DIR *dp;
1770: struct stat st;
1771: #ifdef HAVE_DIRENT_H
1772: struct dirent *d;
1773: #else
1774: struct direct *d;
1775: #endif /* HAVE_DIRENT_H */
1.128 cvs 1776: char filename[BUFSIZ+1];
1.118 cvs 1777:
1778: if ((dp = opendir (dirname)) == NULL)
1779: {
1780: /* @@@ we couldn't open the directory ... we need some msg */
1781: perror (dirname);
1.176 cvs 1782: return;
1.118 cvs 1783: }
1784:
1785: while ((d = readdir (dp)) != NULL)
1786: {
1787: /* skip the UNIX . and .. links */
1788: if (!strcmp (d->d_name, "..")
1789: || !strcmp (d->d_name, "."))
1790: continue;
1791:
1.188 cvs 1792: sprintf (filename, "%s%c%s", dirname, DIR_SEP, d->d_name);
1.118 cvs 1793: if (lstat (filename, &st) < 0 )
1794: {
1795: /* @@2 need some error message */
1796: perror (filename);
1797: continue;
1798: }
1799:
1800: switch (st.st_mode & S_IFMT)
1801: {
1802: case S_IFDIR:
1803: /* if we find a directory, we erase it, recursively */
1.128 cvs 1804: strcat (filename, DIR_STR);
1805: RecCleanCache (filename);
1806: rmdir (filename);
1.118 cvs 1807: break;
1808: case S_IFLNK:
1809: /* skip any links we find */
1810: continue;
1811: break;
1812: default:
1813: /* erase the filename */
1814: TtaFileUnlink (filename);
1815: break;
1816: }
1817: }
1818: closedir (dp);
1819: }
1.128 cvs 1820: #endif /* _WINDOWS */
1.118 cvs 1821: #endif /* AMAYA_WWW_CACHE */
1822:
1.116 cvs 1823: /*----------------------------------------------------------------------
1824: CacheInit
1825: Reads the cache settings from the thot.ini file.
1826: ----------------------------------------------------------------------*/
1.118 cvs 1827: #ifdef __STDC__
1.116 cvs 1828: static void CacheInit (void)
1.118 cvs 1829: #else
1830: static void Cacheinit ()
1831: #endif
1832:
1.116 cvs 1833: {
1834: #ifndef AMAYA_WWW_CACHE
1835: HTCacheMode_setEnabled (NO);
1836:
1837: #else /* AMAYA_WWW_CACHE */
1.198 cvs 1838: STRING strptr;
1839: STRING cache_dir = NULL;
1840: STRING real_dir = NULL;
1841: STRING cache_lockfile;
1.130 cvs 1842: int cache_size;
1.176 cvs 1843: int cache_entry_size;
1.191 cvs 1844: ThotBool cache_enabled;
1845: ThotBool cache_locked;
1846: ThotBool tmp_bool;
1.130 cvs 1847:
1.185 cvs 1848: int i;
1849:
1.116 cvs 1850: /* activate cache? */
1.203 cvs 1851: strptr = TtaGetEnvString ("ENABLE_CACHE");
1.198 cvs 1852: if (strptr && *strptr && ustrcasecmp (strptr, TEXT("yes")))
1.130 cvs 1853: cache_enabled = NO;
1.116 cvs 1854: else
1.130 cvs 1855: cache_enabled = YES;
1.116 cvs 1856:
1.151 cvs 1857: /* cache protected documents? */
1.203 cvs 1858: strptr = TtaGetEnvString ("CACHE_PROTECTED_DOCS");
1.198 cvs 1859: if (strptr && *strptr && !ustrcasecmp (strptr, TEXT("yes")))
1.151 cvs 1860: HTCacheMode_setProtected (YES);
1861: else
1862: HTCacheMode_setProtected (NO);
1863:
1.116 cvs 1864: /* get the cache dir (or use a default one) */
1.203 cvs 1865: strptr = TtaGetEnvString ("CACHE_DIR");
1.116 cvs 1866: if (strptr && *strptr)
1867: {
1.198 cvs 1868: real_dir = TtaAllocString (ustrlen (strptr) + ustrlen (CACHE_DIR_NAME) + 20);
1869: ustrcpy (real_dir, strptr);
1870: if (*(real_dir + ustrlen (real_dir) - 1) != DIR_SEP)
1871: ustrcat (real_dir, DIR_STR);
1.116 cvs 1872: }
1873: else
1874: {
1.198 cvs 1875: real_dir = TtaAllocString (ustrlen (TempFileDirectory)
1876: + ustrlen (CACHE_DIR_NAME) + 20);
1877: usprintf (real_dir, TEXT("%s%s"), TempFileDirectory, CACHE_DIR_NAME);
1.185 cvs 1878: }
1879:
1880: /* compatiblity with previous versions of Amaya: does real_dir
1881: include CACHE_DIR_NAME? If not, add it */
1.198 cvs 1882: strptr = ustrstr (real_dir, CACHE_DIR_NAME);
1.185 cvs 1883: if (!strptr)
1884: {
1.198 cvs 1885: ustrcat (real_dir, CACHE_DIR_NAME);
1.185 cvs 1886: }
1887: else
1888: {
1.198 cvs 1889: i = ustrlen (CACHE_DIR_NAME);
1.185 cvs 1890: if (strptr[i] != EOS)
1.198 cvs 1891: ustrcat (real_dir, CACHE_DIR_NAME);
1.116 cvs 1892: }
1.185 cvs 1893:
1.211 cvs 1894: /* convert the local cache dir into a file URL, as expected by
1895: libwww */
1896: cache_dir = HTLocalToWWW (WideChar2ISO (real_dir), "file:");
1.116 cvs 1897:
1898: /* get the cache size (or use a default one) */
1.203 cvs 1899: strptr = TtaGetEnvString ("CACHE_SIZE");
1.116 cvs 1900: if (strptr && *strptr)
1.198 cvs 1901: cache_size = uctoi (strptr);
1.116 cvs 1902: else
1903: cache_size = DEFAULT_CACHE_SIZE;
1904:
1.176 cvs 1905: /* get the max cached file size (or use a default one) */
1.198 cvs 1906: if (!TtaGetEnvInt (TEXT("MAX_CACHE_ENTRY_SIZE"), &cache_entry_size))
1.176 cvs 1907: cache_entry_size = DEFAULT_MAX_CACHE_ENTRY_SIZE;
1908:
1.130 cvs 1909: if (cache_enabled)
1.116 cvs 1910: {
1911: /* how to remove the lock? force remove it? */
1.198 cvs 1912: cache_lockfile = TtaAllocString (ustrlen (real_dir) + 20);
1913: ustrcpy (cache_lockfile, real_dir);
1914: ustrcat (cache_lockfile, TEXT(".lock"));
1.130 cvs 1915: cache_locked = FALSE;
1916: if (TtaFileExist (cache_lockfile)
1917: && !(cache_locked = test_cachelock (cache_lockfile)))
1.116 cvs 1918: {
1.130 cvs 1919: #ifdef DEBUG_LIBWWW
1920: fprintf (stderr, "found a stale cache, removing it\n");
1921: #endif /* DEBUG_LIBWWW */
1922: /* remove the lock and clean the cache (the clean cache
1923: will remove all, making the following call unnecessary */
1924: /* little trick to win some memory */
1.198 cvs 1925: strptr = ustrrchr (cache_lockfile, TEXT('.'));
1.130 cvs 1926: *strptr = EOS;
1927: RecCleanCache (cache_lockfile);
1928: *strptr = '.';
1.116 cvs 1929: }
1930:
1.130 cvs 1931: if (!cache_locked)
1932: {
1933: /* initialize the cache if there's no other amaya
1934: instance running */
1.177 cvs 1935: HTCacheMode_setMaxCacheEntrySize (cache_entry_size);
1.198 cvs 1936: if (TtaGetEnvBoolean (TEXT("CACHE_EXPIRE_IGNORE"), &tmp_bool)
1.177 cvs 1937: && tmp_bool)
1938: HTCacheMode_setExpires (HT_EXPIRES_IGNORE);
1939: else
1940: HTCacheMode_setExpires (HT_EXPIRES_AUTO);
1.198 cvs 1941: TtaGetEnvBoolean (TEXT("CACHE_DISCONNECTED_MODE"), &tmp_bool);
1.177 cvs 1942: if (tmp_bool)
1943: HTCacheMode_setDisconnected (HT_DISCONNECT_NORMAL);
1944: else
1945: HTCacheMode_setDisconnected (HT_DISCONNECT_NONE);
1.211 cvs 1946: if (HTCacheInit (cache_dir, cache_size))
1.130 cvs 1947: {
1.188 cvs 1948: if (set_cachelock (cache_lockfile) == -1)
1949: /* couldn't open the .lock file, so, we close the cache to
1950: be in the safe side */
1951: {
1952: HTCacheTerminate ();
1953: HTCacheMode_setEnabled (FALSE);
1954: #ifdef DEBUG_LIBWWW
1955: fprintf (stderr, "couldnt set the cache lock\n");
1956: #endif /* DEBUG_LIBWWW */
1957: }
1.130 cvs 1958: #ifdef DEBUG_LIBWWW
1.188 cvs 1959: else
1960: fprintf (stderr, "created the cache lock\n");
1.130 cvs 1961: #endif /* DEBUG_LIBWWW */
1962: }
1.188 cvs 1963: else
1964: {
1.130 cvs 1965: #ifdef DEBUG_LIBWWW
1.188 cvs 1966: fprintf (stderr, "couldn't create the cache\n");
1967: #endif /* DEBUG_LIBWWW */
1968: HTCacheTerminate ();
1969: }
1.130 cvs 1970: }
1971: else
1972: {
1.185 cvs 1973: HTCacheMode_setEnabled (FALSE);
1.130 cvs 1974: #ifdef DEBUG_LIBWWW
1975: fprintf (stderr, "lock detected, starting libwww without a cache/n");
1976: #endif /* DEBUG_LIBWWW */
1977: }
1978: TtaFreeMemory (cache_lockfile);
1.116 cvs 1979: }
1980: else
1.185 cvs 1981: {
1982: HTCacheMode_setEnabled (FALSE);
1983: }
1.116 cvs 1984: if (cache_dir)
1.211 cvs 1985: HT_FREE (cache_dir);
1.189 cvs 1986: if (real_dir)
1987: TtaFreeMemory (real_dir);
1.185 cvs 1988: /* warn the user if the cache isn't active */
1989: if (cache_enabled && !HTCacheMode_enabled ())
1.214 cvs 1990: InitInfo (TEXT("Cache"), TtaGetMessage (AMAYA, AM_CANT_CREATE_CACHE));
1.116 cvs 1991: #endif /* AMAYA_WWW_CACHE */
1.15 cvs 1992: }
1993:
1994: /*----------------------------------------------------------------------
1.97 cvs 1995: ProxyInit
1996: Reads any proxies settings which may be declared as environmental
1997: variables or in the thot.ini file. The former overrides the latter.
1998: ----------------------------------------------------------------------*/
1.118 cvs 1999: #ifdef __STDC__
1.97 cvs 2000: static void ProxyInit (void)
1.118 cvs 2001: #else
2002: static void ProxyInit ()
2003: #endif /* __STDC__ */
1.97 cvs 2004: {
1.198 cvs 2005: STRING strptr;
2006: STRING str = NULL;
2007: STRING name;
1.212 cvs 2008: ThotBool proxy_is_onlyproxy;
2009:
1.198 cvs 2010: char* strptrA;
1.97 cvs 2011:
2012: /* get the proxy settings from the thot.ini file */
1.203 cvs 2013: strptr = TtaGetEnvString ("HTTP_PROXY");
1.97 cvs 2014: if (strptr && *strptr)
1.216 cvs 2015: {
2016: /* does the proxy env string has an "http://" prefix? */
2017: if ( !ustrncasecmp( strptr, "http://", 7))
2018: HTProxy_add ("http", WideChar2ISO (strptr));
2019: else
2020: {
2021: strptrA = (char *) TtaGetMemory (ustrlen (strptr) + 9);
2022: strcpy (strptrA, "http://");
2023: strcat (strptrA, WideChar2ISO (strptr));
2024: HTProxy_add ("http", strptrA);
2025: TtaFreeMemory (strptrA);
2026: }
2027: }
2028:
1.97 cvs 2029: /* get the no_proxy settings from the thot.ini file */
1.212 cvs 2030: strptr = TtaGetEnvString ("PROXYDOMAIN");
1.97 cvs 2031: if (strptr && *strptr)
2032: {
2033: str = TtaStrdup (strptr); /* Get copy we can mutilate */
2034: strptr = str;
1.198 cvs 2035: strptrA = WideChar2ISO (strptr);
1.201 cvs 2036: while ((name = ISO2WideChar(HTNextField (&strptrA))) != NULL) {
1.198 cvs 2037: STRING portstr = ustrchr (name, TEXT(':'));
1.97 cvs 2038: unsigned port=0;
1.198 cvs 2039: if (portstr) {
2040: *portstr++ = EOS;
2041: if (*portstr) port = (unsigned) uctoi (portstr);
1.97 cvs 2042: }
2043: /* Register it for all access methods */
1.198 cvs 2044: HTNoProxy_add (WideChar2ISO (name), NULL, port);
1.97 cvs 2045: }
2046: TtaFreeMemory (str);
2047: }
1.212 cvs 2048:
2049: /* how should we interpret the proxy domain list? */
2050: TtaGetEnvBoolean ("PROXYDOMAIN_IS_ONLYPROXY", &proxy_is_onlyproxy);
2051: HTProxy_setNoProxyIsOnlyProxy (proxy_is_onlyproxy);
2052:
2053: /* use libwww's routine to get all proxy settings from the environment */
1.97 cvs 2054: HTProxy_getEnvVar ();
2055: }
2056:
1.207 cvs 2057: /*----------------------------------------------------------------------
2058: SafePut_init
2059: Sets up the domains which are authorized to make a redirect on
2060: a PUT.
2061: ----------------------------------------------------------------------*/
2062: #ifdef __STDC__
2063: static void SafePut_init (void)
2064: #else
2065: static void SafePut_init ()
2066: #endif /* __STDC__ */
2067: {
2068: STRING strptr;
2069: STRING str = NULL;
2070: char *strptrA, *ptr;
2071: char *domain;
2072:
2073: /* get the proxy settings from the thot.ini file */
2074: strptr = TtaGetEnvString ("SAFE_PUT_REDIRECT");
2075: if (strptr && *strptr)
2076: {
2077: /* Get copy we can mutilate */
2078: str = TtaStrdup (strptr);
2079: strptrA = WideChar2ISO (str);
2080: /* convert to lowercase */
2081: ptr = strptrA;
2082: while (*ptr)
2083: {
2084: *ptr = tolower (*ptr);
2085: ptr++;
2086: }
2087:
2088: /* create the list container */
2089: safeput_list = HTList_new ();
2090: /* store the domain list */
2091: while ((domain = HTNextField (&strptrA)) != NULL)
2092: HTList_addObject (safeput_list, TtaStrdup (domain));
2093:
2094: TtaFreeMemory (str);
2095: }
2096: }
2097:
2098: /*----------------------------------------------------------------------
2099: SafePut_delete
2100: Deletes the safeput_list variable
2101: ----------------------------------------------------------------------*/
2102: static void SafePut_delete (void)
2103: {
2104: HTList *cur = safeput_list;
2105: char *domain;
2106:
2107: if (!safeput_list)
2108: return;
2109:
2110: while ((domain = (char *) HTList_nextObject (cur)))
2111: TtaFreeMemory (domain);
2112: HTList_delete (safeput_list);
2113: safeput_list = NULL;
2114: }
2115:
2116: /*----------------------------------------------------------------------
2117: SafePut_query
2118: returns true if the domain to which belongs the URL accepts an automatic
2119: PUT redirect.
2120: ----------------------------------------------------------------------*/
2121: static ThotBool SafePut_query (char *url)
2122: {
2123: HTList *cur;
2124: char *me;
2125: ThotBool found;
2126:
2127: /* extract the domain path of the url and normalize it */
2128: /* domain = url; */
2129: cur = safeput_list;
2130: found = FALSE;
2131: while ((me = (char *) HTList_nextObject (cur)))
2132: {
2133: if (strstr (url, me))
2134: {
2135: found = TRUE;
2136: break;
2137: }
2138: }
2139:
2140: return (found);
2141: }
1.97 cvs 2142:
2143: /*----------------------------------------------------------------------
1.17 cvs 2144: AHTProfile_newAmaya
2145: creates the Amaya client profile for libwww.
1.15 cvs 2146: ----------------------------------------------------------------------*/
2147: #ifdef __STDC__
1.198 cvs 2148: static void AHTProfile_newAmaya (STRING AppName, STRING AppVersion)
1.15 cvs 2149: #else /* __STDC__ */
2150: static void AHTProfile_newAmaya (AppName, AppVersion)
1.198 cvs 2151: STRING AppName;
2152: STRING AppVersion;
1.15 cvs 2153: #endif /* __STDC__ */
1.4 cvs 2154: {
1.198 cvs 2155: STRING strptr;
1.158 cvs 2156:
1.4 cvs 2157: /* If the Library is not already initialized then do it */
2158: if (!HTLib_isInitialized ())
1.198 cvs 2159: HTLibInit (WideChar2ISO (AppName), WideChar2ISO (AppVersion));
1.4 cvs 2160:
2161: if (!converters)
2162: converters = HTList_new ();
1.27 cvs 2163: if (!acceptTypes)
2164: acceptTypes = HTList_new ();
1.193 cvs 2165: if (!acceptLanguages)
2166: acceptLanguages = HTList_new ();
1.151 cvs 2167: if (!transfer_encodings)
2168: transfer_encodings = HTList_new ();
2169: if (!content_encodings)
2170: content_encodings = HTList_new ();
1.4 cvs 2171:
1.169 cvs 2172: /* inhibits libwww's automatic file_suffix_binding */
2173: HTFile_doFileSuffixBinding (FALSE);
2174:
1.4 cvs 2175: /* Register the default set of transport protocols */
2176: HTTransportInit ();
2177:
2178: /* Register the default set of application protocol modules */
2179: AHTProtocolInit ();
2180:
1.116 cvs 2181: /* Register the default set of messages and dialog functions */
2182: AHTAlertInit ();
2183: HTAlert_setInteractive (YES);
2184:
2185: #ifdef AMAYA_WWW_CACHE
2186: /* Enable the persistent cache */
2187: CacheInit ();
2188: #else
2189: HTCacheMode_setEnabled (NO);
2190: #endif /* AMAYA_WWW_CACHE */
1.4 cvs 2191:
2192: /* Register the default set of BEFORE and AFTER filters */
2193: AHTNetInit ();
2194:
2195: /* Set up the default set of Authentication schemes */
1.167 cvs 2196: HTAA_newModule ("basic", HTBasic_generate, HTBasic_parse, NULL,
2197: HTBasic_delete);
1.158 cvs 2198: /* activate MDA by defaul */
1.203 cvs 2199: strptr = TtaGetEnvString ("ENABLE_MDA");
1.198 cvs 2200: if (!strptr || (strptr && *strptr && ustrcasecmp (strptr, TEXT("no"))))
1.158 cvs 2201: HTAA_newModule ("digest", HTDigest_generate, HTDigest_parse,
1.167 cvs 2202: HTDigest_updateInfo, HTDigest_delete);
1.4 cvs 2203:
1.97 cvs 2204: /* Get any proxy settings */
2205: ProxyInit ();
1.4 cvs 2206:
1.207 cvs 2207: /* Set up the domains where we accept a redirect on PUT */
2208: SafePut_init ();
2209:
1.4 cvs 2210: /* Register the default set of converters */
2211: AHTConverterInit (converters);
1.151 cvs 2212: HTFormat_setConversion (converters);
1.27 cvs 2213: AHTAcceptTypesInit (acceptTypes);
1.193 cvs 2214: AHTAcceptLanguagesInit (acceptLanguages);
1.4 cvs 2215:
2216: /* Register the default set of transfer encoders and decoders */
1.151 cvs 2217: HTTransferEncoderInit (transfer_encodings);
1.190 cvs 2218: HTFormat_setTransferCoding (transfer_encodings);
2219: /* Register the default set of content encoders and decoders */
2220: HTContentEncoderInit (content_encodings);
2221: /* ignore all other encoding formats (or libwww will send them
1.181 cvs 2222: thru a blackhole otherwise */
2223: HTCoding_add (content_encodings, "*", NULL, HTIdentityCoding, 1.0);
1.151 cvs 2224: if (HTList_count(content_encodings) > 0)
2225: HTFormat_setContentCoding(content_encodings);
2226: else
2227: {
2228: HTList_delete(content_encodings);
2229: content_encodings = NULL;
2230: }
1.4 cvs 2231:
2232: /* Register the default set of MIME header parsers */
1.74 cvs 2233: HTMIMEInit (); /* must be called again for language selector */
1.4 cvs 2234:
2235: /* Register the default set of Icons for directory listings */
1.27 cvs 2236: /*HTIconInit(NULL); *//* experimental */
1.4 cvs 2237: }
2238:
1.5 cvs 2239: /*----------------------------------------------------------------------
1.17 cvs 2240: AHTProfile_delete
2241: deletes the Amaya client profile.
1.5 cvs 2242: ----------------------------------------------------------------------*/
1.4 cvs 2243: #ifdef __STDC__
2244: static void AHTProfile_delete (void)
2245: #else
2246: static void AHTProfile_delete ()
1.7 cvs 2247: #endif /* __STDC__ */
1.4 cvs 2248: {
1.22 cvs 2249:
2250: /* free the Amaya global context */
1.151 cvs 2251:
2252: /* Clean up all the registred converters */
2253: HTFormat_deleteAll ();
2254: if (acceptTypes)
1.74 cvs 2255: HTConversion_deleteAll (acceptTypes);
1.193 cvs 2256: if (acceptLanguages)
2257: HTLanguage_deleteAll (acceptLanguages);
1.151 cvs 2258:
1.209 cvs 2259: StopAllRequests (1);
1.74 cvs 2260: HTList_delete (Amaya->docid_status);
2261: HTList_delete (Amaya->reqlist);
2262: TtaFreeMemory (Amaya);
1.61 cvs 2263:
1.120 cvs 2264: #ifdef _WINDOWS
1.209 cvs 2265: if (HTLib_isInitialized ())
1.151 cvs 2266: HTEventTerminate ();
1.198 cvs 2267: #endif /* _WINDOWS; */
1.74 cvs 2268:
1.151 cvs 2269: /* Clean up the persistent cache (if any) */
1.116 cvs 2270: #ifdef AMAYA_WWW_CACHE
1.151 cvs 2271: clear_cachelock ();
2272: HTCacheTerminate ();
1.116 cvs 2273: #endif /* AMAYA_WWW_CACHE */
1.217 cvs 2274:
1.218 cvs 2275: /* call remove functions that are not called automatically by libwww */
2276: HTNetCall_deleteBeforeAll (HTNet_before ());
2277: HTNetCall_deleteAfterAll (HTNet_after ());
2278: HTAA_deleteAllModules ();
2279: HTAlertCall_deleteAll (HTAlert_global () );
2280: HTAlert_setGlobal ((HTList *) NULL);
2281: /* these two functions are broken, so we can't call them right now
2282: HTHeader_deleteAll ();
2283: HTTimer_deleteAll ();
2284: */
2285: HTTransport_deleteAll ();
1.217 cvs 2286: /* remove bindings between suffixes, media types*/
2287: HTBind_deleteAll ();
1.151 cvs 2288: /* Terminate libwww */
2289: HTLibTerminate ();
1.4 cvs 2290: }
2291:
1.5 cvs 2292: /*----------------------------------------------------------------------
1.116 cvs 2293: AmayacontextInit
2294: initializes an internal Amaya context for our libwww interface
2295: ----------------------------------------------------------------------*/
2296: #ifdef __STDC__
2297: static void AmayaContextInit ()
2298: #else
2299: static void AmayaContextInit ()
2300: #endif
2301:
2302: {
1.140 cvs 2303: AmayaAlive_flag = TRUE;
1.116 cvs 2304: /* Initialization of the global context */
2305: Amaya = (AmayaContext *) TtaGetMemory (sizeof (AmayaContext));
2306: Amaya->reqlist = HTList_new ();
2307: Amaya->docid_status = HTList_new ();
2308: Amaya->open_requests = 0;
2309: }
2310:
2311: /*----------------------------------------------------------------------
1.17 cvs 2312: QueryInit
2313: initializes the libwww interface
1.5 cvs 2314: ----------------------------------------------------------------------*/
1.4 cvs 2315: #ifdef __STDC__
2316: void QueryInit ()
2317: #else
2318: void QueryInit ()
2319: #endif
2320: {
1.198 cvs 2321: STRING strptr;
1.151 cvs 2322: int tmp_i;
2323: long tmp_l;
1.4 cvs 2324:
1.116 cvs 2325: AmayaContextInit ();
1.4 cvs 2326: AHTProfile_newAmaya (HTAppName, HTAppVersion);
1.140 cvs 2327: CanDoStop_set (TRUE);
1.214 cvs 2328: UserAborted_flag = FALSE;
1.4 cvs 2329:
1.116 cvs 2330: #ifdef _WINDOWS
1.125 cvs 2331: HTEventInit ();
1.116 cvs 2332: #endif /* _WINDOWS */
1.72 cvs 2333:
1.123 cvs 2334: #ifndef _WINDOWS
1.116 cvs 2335: HTEvent_setRegisterCallback ((void *) AHTEvent_register);
2336: HTEvent_setUnregisterCallback ((void *) AHTEvent_unregister);
1.202 cvs 2337: #ifndef _GTK
1.120 cvs 2338: HTTimer_registerSetTimerCallback ((void *) AMAYA_SetTimer);
2339: HTTimer_registerDeleteTimerCallback ((void *) AMAYA_DeleteTimer);
1.202 cvs 2340: #endif /* _GTK */
1.116 cvs 2341: #endif /* !_WINDOWS */
1.190 cvs 2342:
1.213 cvs 2343: #ifdef HTDEBUG
2344: /* an undocumented option for being able to generate an HTTP protocol trace */
1.208 cvs 2345: strptr = TtaGetEnvString ("ENABLE_LIBWWW_DEBUG");
2346: if (strptr && *strptr)
2347: WWW_TraceFlag = SHOW_PROTOCOL_TRACE;
2348: else
2349: WWW_TraceFlag = 0;
1.213 cvs 2350: #endif /* HTDEBUG */
1.208 cvs 2351:
1.74 cvs 2352: #ifdef DEBUG_LIBWWW
1.116 cvs 2353: /* forwards error messages to our own function */
2354: WWW_TraceFlag = THD_TRACE;
1.138 cvs 2355: HTTrace_setCallback(LineTrace);
1.4 cvs 2356: /* Trace activation (for debugging) */
1.148 cvs 2357: /***
1.138 cvs 2358: WWW_TraceFlag = SHOW_CORE_TRACE | SHOW_THREAD_TRACE | SHOW_PROTOCOL_TRACE;
2359: WWW_TraceFlag |= 0xFFFFFFFFl;
2360: ***/
1.152 cvs 2361: #endif
2362:
1.148 cvs 2363: /* Setting up different network parameters */
1.151 cvs 2364:
1.148 cvs 2365: /* Maximum number of simultaneous open sockets */
1.203 cvs 2366: strptr = TtaGetEnvString ("MAX_SOCKET");
1.151 cvs 2367: if (strptr && *strptr)
1.198 cvs 2368: tmp_i = uctoi (strptr);
1.151 cvs 2369: else
2370: tmp_i = DEFAULT_MAX_SOCKET;
2371: HTNet_setMaxSocket (tmp_i);
2372:
1.148 cvs 2373: /* different network services timeouts */
1.151 cvs 2374: /* dns timeout */
1.203 cvs 2375: strptr = TtaGetEnvString ("DNS_TIMEOUT");
1.151 cvs 2376: if (strptr && *strptr)
1.198 cvs 2377: tmp_i = uctoi (strptr);
1.151 cvs 2378: else
2379: tmp_i = DEFAULT_DNS_TIMEOUT;
2380: HTDNS_setTimeout (tmp_i);
2381:
2382: /* persistent connections timeout */
1.203 cvs 2383: strptr = TtaGetEnvString ("PERSIST_CX_TIMEOUT");
1.151 cvs 2384: if (strptr && *strptr)
1.198 cvs 2385: tmp_l = uctol (strptr);
1.151 cvs 2386: else
2387: tmp_l = DEFAULT_PERSIST_TIMEOUT;
2388: HTHost_setPersistTimeout (tmp_l);
2389:
1.148 cvs 2390: /* default timeout in ms */
1.203 cvs 2391: strptr = TtaGetEnvString ("NET_EVENT_TIMEOUT");
1.151 cvs 2392: if (strptr && *strptr)
1.198 cvs 2393: tmp_i = uctoi (strptr);
1.151 cvs 2394: else
2395: tmp_i = DEFAULT_NET_EVENT_TIMEOUT;
2396: HTHost_setEventTimeout (tmp_i);
2397:
1.173 cvs 2398: HTRequest_setMaxRetry (8);
1.4 cvs 2399: #ifdef CATCH_SIG
1.148 cvs 2400: signal (SIGPIPE, SIG_IGN);
1.4 cvs 2401: #endif
1.15 cvs 2402: }
2403:
2404: /*----------------------------------------------------------------------
1.17 cvs 2405: LoopForStop
1.136 cvs 2406: a copy of the Thop event loop so we can handle the stop button in Unix
2407: and preemptive requests under Windows
1.15 cvs 2408: ----------------------------------------------------------------------*/
2409: #ifdef __STDC__
2410: static int LoopForStop (AHTReqContext * me)
2411: #else
2412: static int LoopForStop (AHTReqContext * me)
2413: #endif
2414: {
1.136 cvs 2415: #ifdef _WINDOWS
2416: MSG msg;
2417: unsigned long libwww_msg;
2418: HWND old_active_window, libwww_window;
2419: int status_req = HT_OK;
2420:
2421: old_active_window = GetActiveWindow ();
2422: libwww_window = HTEventList_getWinHandle (&libwww_msg);
1.137 cvs 2423:
1.149 cvs 2424: while (me->reqStatus != HT_END && me->reqStatus != HT_ERR
2425: && me->reqStatus != HT_ABORT && AmayaIsAlive () &&
2426: GetMessage (&msg, NULL, 0, 0))
2427: {
2428: if (msg.message != WM_QUIT)
2429: {
2430: TranslateMessage (&msg);
2431: DispatchMessage (&msg);
2432: }
2433: else
2434: break;
2435: }
1.136 cvs 2436: if (!AmayaIsAlive ())
2437: /* Amaya was killed by one of the callback handlers */
2438: exit (0);
2439: #else /* _WINDOWS */
1.25 cvs 2440: extern ThotAppContext app_cont;
1.51 cvs 2441: XEvent ev;
2442: XtInputMask status;
1.17 cvs 2443: int status_req = HT_OK;
1.15 cvs 2444:
2445: /* to test the async calls */
1.17 cvs 2446: /* Loop while waiting for new events, exists when the request is over */
1.15 cvs 2447: while (me->reqStatus != HT_ABORT &&
2448: me->reqStatus != HT_END &&
1.69 cvs 2449: me->reqStatus != HT_ERR) {
1.116 cvs 2450: if (!AmayaIsAlive ())
1.69 cvs 2451: /* Amaya was killed by one of the callback handlers */
2452: exit (0);
2453:
2454: status = XtAppPending (app_cont);
1.144 cvs 2455: if (status & XtIMXEvent)
2456: {
2457: XtAppNextEvent (app_cont, &ev);
2458: TtaHandleOneEvent (&ev);
2459: }
2460: else if (status != 0)
2461: XtAppProcessEvent (app_cont, XtIMAll);
1.69 cvs 2462: }
1.136 cvs 2463: #endif /* _WINDOWS */
1.69 cvs 2464: switch (me->reqStatus) {
2465: case HT_ERR:
2466: case HT_ABORT:
1.130 cvs 2467: status_req = NO;
1.15 cvs 2468: break;
2469:
1.69 cvs 2470: case HT_END:
1.130 cvs 2471: status_req = YES;
1.15 cvs 2472: break;
2473:
1.69 cvs 2474: default:
1.15 cvs 2475: break;
1.69 cvs 2476: }
1.15 cvs 2477: return (status_req);
1.4 cvs 2478: }
2479:
1.5 cvs 2480: /*----------------------------------------------------------------------
1.15 cvs 2481: QueryClose
1.21 cvs 2482: closes all existing threads, frees all non-automatically deallocated
2483: memory and then ends libwww.
1.5 cvs 2484: ----------------------------------------------------------------------*/
1.116 cvs 2485: void QueryClose ()
1.4 cvs 2486: {
1.24 cvs 2487:
1.140 cvs 2488: AmayaAlive_flag = FALSE;
1.24 cvs 2489:
1.116 cvs 2490: /* remove all the handlers and callbacks that may output a message to
2491: a non-existent Amaya window */
2492: HTEvent_setRegisterCallback ((HTEvent_registerCallback *) NULL);
2493: HTEvent_setUnregisterCallback ((HTEvent_unregisterCallback *) NULL);
2494: #ifndef _WINDOWS
2495: /** need to erase all existing timers too **/
2496: HTTimer_registerSetTimerCallback (NULL);
2497: HTTimer_registerDeleteTimerCallback (NULL);
2498: #endif /* !_WINDOWS */
2499: HTHost_setActivateRequestCallback (NULL);
2500: Thread_deleteAll ();
1.21 cvs 2501:
1.116 cvs 2502: HTProxy_deleteAll ();
2503: HTNoProxy_deleteAll ();
1.207 cvs 2504: SafePut_delete ();
1.116 cvs 2505: HTGateway_deleteAll ();
2506: AHTProfile_delete ();
2507: }
2508:
2509: /*----------------------------------------------------------------------
2510: NextNameValue
2511: ---------------------------------------------------------------------*/
2512: #ifdef __STDC__
2513: static char * NextNameValue (char ** pstr, char **name, char **value)
2514: #else
2515: static char * NextNameValue (pstr, name, value);
2516: char ** pstr;
2517: char **name;
2518: char **value;
2519: #endif /* __STDC__ */
2520: {
2521: char * p = *pstr;
2522: char * start = NULL;
2523: if (!pstr || !*pstr) return NULL;
2524:
2525: if (!*p) {
2526: *pstr = p;
2527: *name = NULL;
2528: *value = NULL;
2529: return NULL; /* No field */
2530: }
2531:
2532: /* Now search for the next '&' and ';' delimitators */
2533: start = p;
2534: while (*p && *p != '&' && *p != ';') p++;
2535: if (*p)
2536: *p++ = '\0';
2537: *pstr = p;
2538:
2539: /* Search for the name and value */
2540: *name = start;
2541: p = start;
2542:
2543: while(*p && *p != '=')
2544: p++;
2545: if (*p)
2546: *p++ = '\0';
2547: *value = p;
2548:
2549: return start;
2550: }
2551:
2552: /*----------------------------------------------------------------------
2553: PrepareFormdata
2554: ---------------------------------------------------------------------*/
2555: #ifdef __STDC__
1.198 cvs 2556: static HTAssocList * PrepareFormdata (STRING string)
1.116 cvs 2557: #else
2558: static HTAssocList * PrepareFormdata (string)
1.198 cvs 2559: STRING string;
1.116 cvs 2560: #endif /* __STDC__ */
2561: {
1.198 cvs 2562: char* tmp_string, *tmp_string_ptr;
2563: char* name;
2564: char* value;
2565: HTAssocList* formdata;
1.116 cvs 2566:
2567: if (!string)
2568: return NULL;
2569:
2570: /* store the ptr in another variable, as the original address will
2571: change
2572: */
2573:
1.198 cvs 2574: tmp_string_ptr = tmp_string = WideChar2ISO (TtaStrdup (string));
1.116 cvs 2575: formdata = HTAssocList_new();
2576:
2577: while (*tmp_string)
2578: {
2579: NextNameValue (&tmp_string, &name, &value);
2580: HTAssocList_addObject(formdata,
2581: name, value);
2582: }
2583:
2584: TtaFreeMemory (tmp_string_ptr);
2585: return formdata;
1.4 cvs 2586: }
2587:
1.216 cvs 2588: #ifdef __STDC__
2589: void AHTRequest_setCustomAcceptHeader (HTRequest *request, char *value)
2590: #else
2591: void AHTRequest_setCustomAcceptHeader (request, value)
2592: HTRequest *request;
2593: char *value;
2594: #endif /* __STDC__ */
2595: {
2596: HTRqHd rqhd = HTRequest_rqHd (request);
2597: rqhd = rqhd & (~HT_C_ACCEPT_TYPE);
2598: HTRequest_setRqHd (request, rqhd);
2599: HTRequest_addExtraHeader (request, "Accept:", value);
2600: }
2601:
2602:
1.99 cvs 2603:
2604: /*----------------------------------------------------------------------
2605: InvokeGetObjectWWW_callback
2606: A simple function to invoke a callback function whenever there's an error
2607: in GetObjectWWW
2608: ---------------------------------------------------------------------*/
2609:
1.116 cvs 2610: #ifdef __STDC__
1.198 cvs 2611: void InvokeGetObjectWWW_callback (int docid, STRING urlName, STRING outputfile, TTcbf *terminate_cbf, void *context_tcbf, int status)
1.99 cvs 2612: #else
1.111 cvs 2613: void InvokeGetObjectWWW_callback (docid, urlName, outputfile, terminate_cbf, context_tcbf, status)
1.99 cvs 2614: int docid;
1.198 cvs 2615: STRING urlName;
2616: STRING outputfile;
1.99 cvs 2617: TTcbf *terminate_cbf;
2618: void *context_tcbf;
1.116 cvs 2619: #endif /* __STDC__ */
1.99 cvs 2620: {
2621: if (!terminate_cbf)
2622: return;
2623:
1.116 cvs 2624: (*terminate_cbf) (docid, status, urlName, outputfile,
1.99 cvs 2625: NULL, context_tcbf);
2626: }
2627:
2628:
2629:
1.5 cvs 2630: /*----------------------------------------------------------------------
1.15 cvs 2631: GetObjectWWW
1.17 cvs 2632: this function requests a resource designated by a URLname into a
2633: temporary filename. The download can come from a simple GET operation,
2634: or can come from POSTING/GETTING a form. In the latter
2635: case, the function receives a query string to send to the server.
2636:
1.5 cvs 2637: 4 file retrieval modes are proposed:
2638: AMAYA_SYNC : blocking mode
2639: AMAYA_ISYNC : incremental, blocking mode
2640: AMAYA_ASYNC : non-blocking mode
2641: AMAYA_IASYNC : incremental, non-blocking mode
2642:
2643: In the incremental mode, each time a package arrives, it will be
2644: stored in the temporary file. In addition, if an
2645: incremental_callback function is defined, this function will be
2646: called and handled a copy of the newly received data package.
2647: Finally, if a terminate_callback function is defined, it will be
2648: invoked when the request terminates. The caller of this function
1.4 cvs 2649: can define two different contexts to be passed to the callback
2650: functions.
2651:
2652: When the function is called with the SYNC mode, the function will
2653: return only when the requested file has been loaded.
2654: The ASYNC mode will immediately return after setting up the
2655: call.
2656:
2657: Notes:
2658: At the end of a succesful request, the urlName string contains the
2659: name of the actually retrieved URL. As a URL can change over the time,
2660: (e.g., be redirected elsewhere), it is advised that the function
1.17 cvs 2661: caller verify the value of the urlName variable at the end of
1.4 cvs 2662: a request.
2663:
2664: Inputs:
2665: - docid Document identifier for the set of objects being
2666: retrieved.
2667: - urlName The URL to be retrieved (MAX_URL_LENGTH chars length)
2668: - outputfile A pointer to an empty string of MAX_URL_LENGTH.
2669: - mode The retrieval mode.
2670: - incremental_cbf
2671: - context_icbf
2672: Callback and context for the incremental modes
2673: - terminate_cbf
2674: - context_icbf
2675: Callback and context for a terminate handler
1.17 cvs 2676: -error_html if TRUE, then display any server error message as an
2677: HTML document.
1.88 cvs 2678: - content_type a string
2679:
1.4 cvs 2680: Outputs:
2681: - urlName The URL that was retrieved
2682: - outputfile The name of the temporary file which holds the
2683: retrieved data. (Only in case of success)
1.88 cvs 2684: - if content_type wasn't NULL, it will contain a copy of the parameter
2685: sent in the HTTP answer
1.4 cvs 2686: Returns:
2687: HT_ERROR
2688: HT_OK
1.5 cvs 2689:
2690: ----------------------------------------------------------------------*/
1.4 cvs 2691: #ifdef __STDC__
1.198 cvs 2692: int GetObjectWWW (int docid, STRING urlName, STRING formdata,
2693: STRING outputfile, int mode, TIcbf* incremental_cbf,
1.116 cvs 2694: void* context_icbf, TTcbf* terminate_cbf,
1.198 cvs 2695: void* context_tcbf, ThotBool error_html, STRING content_type)
1.4 cvs 2696: #else
1.127 cvs 2697: int GetObjectWWW (docid, urlName, formdata, outputfile, mode,
1.116 cvs 2698: incremental_cbf, context_icbf,
1.88 cvs 2699: terminate_cbf, context_tcbf, error_html, content_type)
1.73 cvs 2700: int docid;
1.198 cvs 2701: STRING urlName;
2702: STRING formdata;
2703: STRING outputfile;
1.73 cvs 2704: int mode;
2705: TIcbf *incremental_cbf;
2706: void *context_icbf;
2707: TTcbf *terminate_cbf;
2708: void *context_tcbf;
1.191 cvs 2709: ThotBool error_html;
1.198 cvs 2710: STRING content_type;
1.4 cvs 2711: #endif
2712: {
2713: AHTReqContext *me;
1.198 cvs 2714: STRING ref;
1.206 cvs 2715: STRING esc_url;
1.107 cvs 2716: int status, l;
1.114 cvs 2717: int tempsubdir;
1.191 cvs 2718: ThotBool bool_tmp;
1.7 cvs 2719:
1.116 cvs 2720: if (urlName == NULL || docid == 0 || outputfile == NULL)
2721: {
2722: /* no file to be loaded */
2723: TtaSetStatus (docid, 1, TtaGetMessage (AMAYA, AM_BAD_URL), urlName);
1.69 cvs 2724:
1.116 cvs 2725: if (error_html)
1.69 cvs 2726: /* so we can show the error message */
2727: DocNetworkStatus[docid] |= AMAYA_NET_ERROR;
1.116 cvs 2728: InvokeGetObjectWWW_callback (docid, urlName, outputfile, terminate_cbf,
2729: context_tcbf, HT_ERROR);
2730: return HT_ERROR;
2731: }
1.7 cvs 2732:
1.159 cvs 2733: /* if it's a 'docImage', we have already downloaded it */
1.198 cvs 2734: if (!ustrncmp (TEXT("internal:"), urlName, 9))
1.159 cvs 2735: {
1.198 cvs 2736: ustrcpy (outputfile, urlName);
1.159 cvs 2737: InvokeGetObjectWWW_callback (docid, urlName, outputfile,
2738: terminate_cbf, context_tcbf, HT_OK);
2739: return HT_OK;
2740: }
2741:
1.4 cvs 2742: /* do we support this protocol? */
1.116 cvs 2743: if (IsValidProtocol (urlName) == NO)
2744: {
2745: /* return error */
2746: outputfile[0] = EOS; /* file could not be opened */
2747: TtaSetStatus (docid, 1,
2748: TtaGetMessage (AMAYA, AM_GET_UNSUPPORTED_PROTOCOL),
2749: urlName);
2750:
2751: if (error_html)
1.69 cvs 2752: /* so we can show the error message */
2753: DocNetworkStatus[docid] |= AMAYA_NET_ERROR;
1.116 cvs 2754: InvokeGetObjectWWW_callback (docid, urlName, outputfile, terminate_cbf,
2755: context_tcbf, HT_ERROR);
2756: return HT_ERROR;
2757: }
1.4 cvs 2758:
1.114 cvs 2759: /* we store CSS in subdir named 0; all the other files go to a subidr
2760: named after their own docid */
2761:
2762: tempsubdir = (mode & AMAYA_LOAD_CSS) ? 0 : docid;
2763:
1.116 cvs 2764: /* create a tempfilename */
1.198 cvs 2765: usprintf (outputfile, TEXT("%s%c%d%c%04dAM"), TempFileDirectory, DIR_SEP, tempsubdir, DIR_SEP, object_counter);
1.116 cvs 2766: /* update the object_counter (used for the tempfilename) */
1.4 cvs 2767: object_counter++;
1.116 cvs 2768:
1.4 cvs 2769: /* normalize the URL */
1.206 cvs 2770: esc_url = EscapeURL (urlName);
2771: if (esc_url)
2772: {
2773: ref = AmayaParseUrl (esc_url, _EMPTYSTR_, AMAYA_PARSE_ALL);
2774: TtaFreeMemory (esc_url);
2775: }
2776: else
2777: ref = NULL;
2778:
1.4 cvs 2779: /* should we abort the request if we could not normalize the url? */
1.198 cvs 2780: if (ref == NULL || ref[0] == EOS) {
1.69 cvs 2781: /*error */
2782: outputfile[0] = EOS;
2783: TtaSetStatus (docid, 1, TtaGetMessage (AMAYA, AM_BAD_URL), urlName);
1.214 cvs 2784: if (ref)
2785: TtaFreeMemory (ref);
1.69 cvs 2786: if (error_html)
1.116 cvs 2787: /* so we can show the error message */
2788: DocNetworkStatus[docid] |= AMAYA_NET_ERROR;
1.99 cvs 2789: InvokeGetObjectWWW_callback (docid, urlName, outputfile, terminate_cbf,
1.116 cvs 2790: context_tcbf, HT_ERROR);
1.69 cvs 2791: return HT_ERROR;
2792: }
1.116 cvs 2793:
1.4 cvs 2794: /* verify if that file name existed */
1.9 cvs 2795: if (TtaFileExist (outputfile))
1.77 cvs 2796: TtaFileUnlink (outputfile);
1.116 cvs 2797:
1.4 cvs 2798: /* Initialize the request structure */
2799: me = AHTReqContext_new (docid);
1.116 cvs 2800: if (me == NULL)
2801: {
2802: outputfile[0] = EOS;
2803: /* need an error message here */
2804: TtaFreeMemory (ref);
2805: InvokeGetObjectWWW_callback (docid, urlName, outputfile, terminate_cbf,
2806: context_tcbf, HT_ERROR);
2807: return HT_ERROR;
2808: }
2809:
1.4 cvs 2810: /* Specific initializations for POST and GET */
1.116 cvs 2811: if (mode & AMAYA_FORM_POST)
2812: {
2813: me->method = METHOD_POST;
2814: HTRequest_setMethod (me->request, METHOD_POST);
2815: }
2816: else
2817: {
2818: me->method = METHOD_GET;
2819: if (!HasKnownFileSuffix (ref))
1.216 cvs 2820: {
2821: /* try to adjust the Accept header in an netwise economical way */
2822: if (mode & AMAYA_LOAD_IMAGE)
2823: AHTRequest_setCustomAcceptHeader (me->request, IMAGE_ACCEPT_NEGOTIATION);
2824: else if (mode & AMAYA_LOAD_CSS)
2825: AHTRequest_setCustomAcceptHeader (me->request, "*/*;q=0.1,css/*");
2826: /*
2827: HTRequest_setConversion(me->request, acceptTypes, TRUE);
2828: */
2829: }
2830: HTRequest_setLanguage (me->request, acceptLanguages, TRUE);
1.116 cvs 2831: }
1.93 cvs 2832:
1.116 cvs 2833: /* Common initialization for all HTML methods */
1.4 cvs 2834: me->mode = mode;
2835: me->error_html = error_html;
2836: me->incremental_cbf = incremental_cbf;
2837: me->context_icbf = context_icbf;
2838: me->terminate_cbf = terminate_cbf;
2839: me->context_tcbf = context_tcbf;
1.64 cvs 2840:
1.69 cvs 2841: /* for the async. request modes, we need to have our
1.4 cvs 2842: own copy of outputfile and urlname
1.116 cvs 2843: */
1.4 cvs 2844:
1.116 cvs 2845: if ((mode & AMAYA_ASYNC) || (mode & AMAYA_IASYNC))
2846: {
1.198 cvs 2847: l = ustrlen (outputfile);
1.116 cvs 2848: if (l > MAX_LENGTH)
2849: me->outputfile = TtaGetMemory (l + 2);
2850: else
2851: me->outputfile = TtaGetMemory (MAX_LENGTH + 2);
1.198 cvs 2852: strcpy (me->outputfile, WideChar2ISO (outputfile));
2853: l = ustrlen (urlName);
1.116 cvs 2854: if (l > MAX_LENGTH)
2855: me->urlName = TtaGetMemory (l + 2);
2856: else
2857: me->urlName = TtaGetMemory (MAX_LENGTH + 2);
1.198 cvs 2858: strcpy (me->urlName, WideChar2ISO (urlName));
1.116 cvs 2859: #ifdef _WINDOWS
2860: /* force windows ASYNC requests to always be non preemptive */
2861: HTRequest_setPreemptive (me->request, NO);
2862: #endif /*_WINDOWS */
2863: } /* AMAYA_ASYNC mode */
2864: else
2865: #ifdef _WINDOWS
2866: {
1.198 cvs 2867: me->outputfile = WideChar2ISO (outputfile);
2868: me->urlName = WideChar2ISO (urlName);
1.116 cvs 2869: /* force windows SYNC requests to always be non preemptive */
2870: HTRequest_setPreemptive (me->request, YES);
2871: }
2872: #else /* !_WINDOWS */
2873: {
2874: me->outputfile = outputfile;
2875: me->urlName = urlName;
2876: }
2877: /***
1.136 cvs 2878: In order to take into account the stop button,
2879: the requests will be always asynchronous, however, if mode=AMAYA_SYNC,
1.57 cvs 2880: we will loop until the document has been received or a stop signal
2881: generated
1.77 cvs 2882: ****/
1.116 cvs 2883: HTRequest_setPreemptive (me->request, NO);
2884: #endif /* _WINDOWS */
1.61 cvs 2885:
1.151 cvs 2886: /*
2887: ** Make sure that the first request is flushed immediately and not
2888: ** buffered in the output buffer
2889: */
2890: if (mode & AMAYA_FLUSH_REQUEST)
2891: HTRequest_setFlush(me->request, YES);
2892: HTRequest_setFlush(me->request, YES);
2893:
1.61 cvs 2894: /* prepare the URLname that will be displayed in teh status bar */
2895: ChopURL (me->status_urlName, me->urlName);
1.77 cvs 2896: TtaSetStatus (me->docid, 1,
2897: TtaGetMessage (AMAYA, AM_FETCHING),
1.198 cvs 2898: ISO2WideChar (me->status_urlName));
1.4 cvs 2899:
1.198 cvs 2900: me->anchor = (HTParentAnchor *) HTAnchor_findAddress (WideChar2ISO (ref));
1.45 cvs 2901: TtaFreeMemory (ref);
1.177 cvs 2902:
1.198 cvs 2903: TtaGetEnvBoolean (TEXT("CACHE_DISCONNECTED_MODE"), &bool_tmp);
1.177 cvs 2904: if (!bool_tmp && (mode & AMAYA_NOCACHE))
1.116 cvs 2905: HTRequest_setReloadMode (me->request, HT_CACHE_FLUSH);
2906:
2907: /* prepare the query string and format for POST */
2908: if (mode & AMAYA_FORM_POST)
1.114 cvs 2909: {
1.116 cvs 2910: HTAnchor_setFormat ((HTParentAnchor *) me->anchor,
2911: HTAtom_for ("application/x-www-form-urlencoded"));
2912: HTAnchor_setLength ((HTParentAnchor *) me->anchor, me->block_size);
2913: HTRequest_setEntityAnchor (me->request, me->anchor);
2914: }
1.114 cvs 2915:
1.127 cvs 2916: /* create the formdata element for libwww */
2917: if (formdata)
2918: me->formdata = PrepareFormdata (formdata);
2919:
1.116 cvs 2920: /* do the request */
2921: if (mode & AMAYA_FORM_POST)
1.119 cvs 2922: {
1.191 cvs 2923: /* this call doesn't give back a ThotBool */
1.119 cvs 2924: HTParentAnchor * posted = NULL;
2925:
2926: posted = HTPostFormAnchor (me->formdata, (HTAnchor *) me->anchor,
2927: me->request);
2928: status = posted ? YES : NO;
2929: }
1.127 cvs 2930: else if (formdata)
2931: status = HTGetFormAnchor(me->formdata, (HTAnchor *) me->anchor,
2932: me->request);
1.116 cvs 2933: else
1.77 cvs 2934: status = HTLoadAnchor ((HTAnchor *) me->anchor, me->request);
1.69 cvs 2935:
1.123 cvs 2936: /* @@@ may need some special windows error msg here */
1.116 cvs 2937: /* control the errors */
1.4 cvs 2938:
1.130 cvs 2939: if (status == NO)
1.116 cvs 2940: /* the request invocation failed */
2941: {
2942: /* show an error message on the status bar */
2943: DocNetworkStatus[docid] |= AMAYA_NET_ERROR;
2944: TtaSetStatus (docid, 1,
2945: TtaGetMessage (AMAYA, AM_CANNOT_LOAD),
2946: urlName);
2947: if (me->reqStatus == HT_NEW)
2948: /* manually invoke the last processing that usually gets done
2949: in a succesful request */
2950: InvokeGetObjectWWW_callback (docid, urlName, outputfile,
2951: terminate_cbf, context_tcbf, HT_ERROR);
2952: /* terminate_handler wasn't called */
1.136 cvs 2953: AHTReqContext_delete (me);
1.116 cvs 2954: }
2955: else
1.136 cvs 2956: /* end treatment for SYNC requests */
1.120 cvs 2957: if ((mode & AMAYA_SYNC) || (mode & AMAYA_ISYNC))
2958: {
1.136 cvs 2959: /* wait here untilt the asynchronous request finishes */
1.130 cvs 2960: status = LoopForStop (me);
1.136 cvs 2961: /* if status returns HT_ERROR, should we invoke the callback? */
1.120 cvs 2962: if (!HTRequest_kill (me->request))
2963: AHTReqContext_delete (me);
2964: }
1.130 cvs 2965:
1.136 cvs 2966: /* an interface problem!!! */
2967: return (status == YES ? 0 : -1);
1.4 cvs 2968: }
2969:
1.5 cvs 2970: /*----------------------------------------------------------------------
1.17 cvs 2971: PutObjectWWW
2972: frontend for uploading a resource to a URL. This function downloads
2973: a file to be uploaded into memory, it then calls UploadMemWWW to
2974: finish the job.
2975:
1.5 cvs 2976: 2 upload modes are proposed:
2977: AMAYA_SYNC : blocking mode
2978: AMAYA_ASYNC : non-blocking mode
2979:
1.4 cvs 2980: When the function is called with the SYNC mode, the function will
2981: return only when the file has been uploaded.
2982: The ASYNC mode will immediately return after setting up the
2983: call. Furthermore, at the end of an upload, the ASYNC mode will
2984: call back terminate_cbf, handling it the context defined in
2985: context_tcbf.
2986:
2987: Notes:
2988: At the end of a succesful request, the urlName string contains the
2989: name of the actually uploaded URL. As a URL can change over the time,
2990: (e.g., be redirected elsewhere), it is advised that the function
2991: caller verifies the value of the urlName variable at the end of
2992: a request.
2993:
2994: Inputs:
2995: - docid Document identifier for the set of objects being
2996: retrieved.
2997: - fileName A pointer to the local file to upload
2998: - urlName The URL to be uploaded (MAX_URL_LENGTH chars length)
2999: - mode The retrieval mode.
3000: - terminate_cbf
3001: - context_icbf
3002: Callback and context for a terminate handler
3003:
3004: Outputs:
3005: - urlName The URL that was uploaded
3006:
3007: Returns:
3008: HT_ERROR
3009: HT_OK
1.5 cvs 3010: ----------------------------------------------------------------------*/
1.4 cvs 3011: #ifdef __STDC__
1.198 cvs 3012: int PutObjectWWW (int docid, STRING fileName, STRING urlName, int mode, PicType contentType,
1.4 cvs 3013: TTcbf * terminate_cbf, void *context_tcbf)
3014: #else
1.26 cvs 3015: int PutObjectWWW (docid, urlName, fileName, mode, contentType,
1.4 cvs 3016: ,terminate_cbf, context_tcbf)
3017: int docid;
1.198 cvs 3018: STRING urlName;
3019: STRING fileName;
1.4 cvs 3020: int mode;
1.27 cvs 3021: PicType contentType;
1.4 cvs 3022: TTcbf *terminate_cbf;
3023: void *context_tcbf;
3024:
1.116 cvs 3025: #endif /* __STDC__ */
1.4 cvs 3026: {
1.116 cvs 3027: AHTReqContext *me;
1.4 cvs 3028: int status;
3029: int fd;
3030: struct stat file_stat;
1.116 cvs 3031: char *fileURL;
1.168 cvs 3032: char *etag = NULL;
1.169 cvs 3033: HTParentAnchor *dest_anc_parent;
1.198 cvs 3034: STRING tmp;
1.206 cvs 3035: STRING esc_url;
1.168 cvs 3036: int UsePreconditions;
1.191 cvs 3037: ThotBool lost_update_check = TRUE;
1.172 cvs 3038:
3039: /* should we protect the PUT against lost updates? */
1.203 cvs 3040: tmp = TtaGetEnvString ("ENABLE_LOST_UPDATE_CHECK");
1.198 cvs 3041: if (tmp && *tmp && ustrcasecmp (tmp, TEXT("yes")))
1.172 cvs 3042: lost_update_check = FALSE;
1.168 cvs 3043:
3044: UsePreconditions = mode & AMAYA_USE_PRECONDITIONS;
1.4 cvs 3045:
1.33 cvs 3046: AmayaLastHTTPErrorMsg [0] = EOS;
3047:
1.116 cvs 3048: if (urlName == NULL || docid == 0 || fileName == NULL
3049: || !TtaFileExist (fileName))
1.4 cvs 3050: /* no file to be uploaded */
3051: return HT_ERROR;
3052:
3053: /* do we support this protocol? */
1.7 cvs 3054: if (IsValidProtocol (urlName) == NO)
3055: {
3056: /* return error */
1.198 cvs 3057: TtaSetStatus (docid, 1, TtaGetMessage (AMAYA, AM_PUT_UNSUPPORTED_PROTOCOL), urlName);
1.7 cvs 3058: return HT_ERROR;
3059: }
1.116 cvs 3060:
3061: /* verify the file's size */
3062: #ifndef _WINDOWS
1.7 cvs 3063: if ((fd = open (fileName, O_RDONLY)) == -1)
1.116 cvs 3064: #else
1.198 cvs 3065: if ((fd = uopen (fileName, _O_RDONLY | _O_BINARY)) == -1)
1.116 cvs 3066: #endif /* _WINDOWS */
1.7 cvs 3067: {
3068: /* if we could not open the file, exit */
3069: /*error msg here */
3070: return (HT_ERROR);
3071: }
1.4 cvs 3072:
3073: fstat (fd, &file_stat);
1.137 cvs 3074: # ifdef _WINDOWS
3075: _close (fd);
3076: # else /* _WINDOWS */
1.116 cvs 3077: close (fd);
1.137 cvs 3078: # endif /* _WINDOWS */
1.4 cvs 3079:
1.7 cvs 3080: if (file_stat.st_size == 0)
3081: {
3082: /* file was empty */
3083: /*errmsg here */
3084: return (HT_ERROR);
3085: }
1.116 cvs 3086:
3087: /* prepare the request context */
1.4 cvs 3088: if (THD_TRACE)
1.116 cvs 3089: fprintf (stderr, "file size == %u\n", (unsigned) file_stat.st_size);
1.4 cvs 3090:
3091: me = AHTReqContext_new (docid);
1.7 cvs 3092: if (me == NULL)
3093: {
1.168 cvs 3094: /* @@ need an error message here */
1.151 cvs 3095: TtaHandlePendingEvents ();
1.7 cvs 3096: return (HT_ERROR);
1.208 cvs 3097: }
3098:
3099: /*
3100: ** Set up the original URL name
3101: */
3102: if (DocumentMeta[docid]->put_default_name)
3103: {
3104: char *ptr1, *ptr2;
3105: ptr1 = TtaGetEnvString ("DEFAULTNAME");
3106: if (ptr1 && *ptr1)
3107: {
3108: ptr2 = strstr (urlName, ptr1);
3109: if (ptr2)
3110: {
3111: me->default_put_name = TtaStrdup (urlName);
3112: me->default_put_name[strlen (me->default_put_name)
3113: - strlen (ptr1)] = EOS;
3114: HTRequest_setDefaultPutName (me->request, me->default_put_name);
3115: }
3116: }
1.7 cvs 3117: }
1.116 cvs 3118:
1.4 cvs 3119: me->mode = mode;
3120: me->incremental_cbf = (TIcbf *) NULL;
3121: me->context_icbf = (void *) NULL;
3122: me->terminate_cbf = terminate_cbf;
3123: me->context_tcbf = context_tcbf;
1.206 cvs 3124: esc_url = EscapeURL (urlName);
3125: me->urlName = TtaStrdup (WideChar2ISO (esc_url));
3126: TtaFreeMemory (esc_url);
1.116 cvs 3127: me->block_size = file_stat.st_size;
1.17 cvs 3128: /* select the parameters that distinguish a PUT from a GET/POST */
1.4 cvs 3129: me->method = METHOD_PUT;
3130: me->output = stdout;
1.17 cvs 3131: /* we are not expecting to receive any input from the server */
3132: me->outputfile = (char *) NULL;
1.4 cvs 3133:
1.134 cvs 3134: #ifdef _WINDOWS
3135: /* libwww's HTParse function doesn't take into account the drive name;
1.168 cvs 3136: so we sidestep it */
1.134 cvs 3137: fileURL = NULL;
3138: StrAllocCopy (fileURL, "file:");
1.198 cvs 3139: StrAllocCat (fileURL, WideChar2ISO (fileName));
1.134 cvs 3140: #else
1.116 cvs 3141: fileURL = HTParse (fileName, "file:/", PARSE_ALL);
1.134 cvs 3142: #endif /* _WINDOWS */
1.168 cvs 3143: me->source = HTAnchor_findAddress (fileURL);
1.116 cvs 3144: HT_FREE (fileURL);
1.206 cvs 3145: me->dest = HTAnchor_findAddress (me->urlName);
1.169 cvs 3146: /* we memorize the anchor's parent @ as we use it a number of times
3147: in the following lines */
3148: dest_anc_parent = HTAnchor_parent (me->dest);
1.168 cvs 3149:
1.169 cvs 3150: /*
3151: ** Set the Content-Type of the file we are uploading
3152: */
3153: /* we try to use any content-type previosuly associated
3154: with the parent. If it doesn't exist, we try to guess it
3155: from the URL */
1.198 cvs 3156: tmp = ISO2WideChar (HTAtom_name (HTAnchor_format (dest_anc_parent)));
3157: if (!tmp || !ustrcmp (tmp, TEXT("www/unknown")))
1.169 cvs 3158: {
1.198 cvs 3159: HTAnchor_setFormat (dest_anc_parent, AHTGuessAtom_for (ISO2WideChar (me->urlName), contentType));
3160: tmp = ISO2WideChar (HTAtom_name (HTAnchor_format (dest_anc_parent)));
1.169 cvs 3161: }
3162: /* .. and we give the same type to the source anchor */
3163: /* we go thru setOutputFormat, rather than change the parent's
3164: anchor, as that's the place that libwww expects it to be */
1.170 cvs 3165: HTAnchor_setFormat (HTAnchor_parent (me->source),
1.198 cvs 3166: HTAtom_for (WideChar2ISO (tmp)));
1.219 ! cvs 3167:
1.169 cvs 3168: HTRequest_setOutputFormat (me->request,
1.198 cvs 3169: HTAtom_for (WideChar2ISO (tmp)));
1.219 ! cvs 3170:
! 3171: #if 0 /* JK: code ready, but we're not going to use it yet */
! 3172: /*
! 3173: ** Set the Charset of the file we are uploading
! 3174: */
! 3175: /* we try to use any charset previosuly associated
! 3176: with the parent. If it doesn't exist, we try to guess it
! 3177: from the metadata */
! 3178: tmp = ISO2WideChar (HTAtom_name (HTAnchor_charset (dest_anc_parent)));
! 3179: if (!tmp)
! 3180: {
! 3181: HTAnchor_setCharset (dest_anc_parent, HTAtom_for ("iso-8859-3"));
! 3182: tmp = ISO2WideChar (HTAtom_name (HTAnchor_charset (dest_anc_parent)));
! 3183: }
! 3184: /* .. and we give the same charset to the source anchor */
! 3185: /* we go thru setCharSet, rather than change the parent's
! 3186: anchor, as that's the place that libwww expects it to be */
! 3187: HTAnchor_setCharset (HTAnchor_parent (me->source),
! 3188: HTAtom_for (WideChar2ISO (tmp)));
! 3189: #endif /* CHARSET */
! 3190:
! 3191: /*
! 3192: ** define other request characteristics
! 3193: */
1.116 cvs 3194: #ifdef _WINDOWS
1.136 cvs 3195: HTRequest_setPreemptive (me->request, NO);
1.116 cvs 3196: #else
1.134 cvs 3197: HTRequest_setPreemptive (me->request, NO);
1.116 cvs 3198: #endif /* _WINDOWS */
3199:
1.151 cvs 3200: /*
3201: ** Make sure that the first request is flushed immediately and not
3202: ** buffered in the output buffer
3203: */
3204: if (mode & AMAYA_FLUSH_REQUEST)
3205: HTRequest_setFlush(me->request, YES);
1.168 cvs 3206:
3207: /* Should we use preconditions? */
1.172 cvs 3208: if (lost_update_check)
1.168 cvs 3209: {
1.172 cvs 3210: if (UsePreconditions)
3211: etag = HTAnchor_etag (HTAnchor_parent (me->dest));
3212:
3213: if (etag)
3214: {
3215: HTRequest_setPreconditions(me->request, HT_MATCH_THIS);
3216: }
3217: else
3218: {
3219: HTRequest_setPreconditions(me->request, HT_NO_MATCH);
3220: HTRequest_addAfter(me->request, check_handler, NULL, NULL, HT_ALL,
3221: HT_FILTER_MIDDLE, YES);
1.175 cvs 3222: HTRequest_addAfter (me->request, HTAuthFilter, "http://*", NULL,
3223: HT_NO_ACCESS, HT_FILTER_MIDDLE, YES);
3224: HTRequest_addAfter (me->request, HTAuthFilter, "http://*", NULL,
3225: HT_REAUTH, HT_FILTER_MIDDLE, YES);
3226: HTRequest_addAfter (me->request, HTAuthInfoFilter, "http://*", NULL,
3227: HT_ALL, HT_FILTER_MIDDLE, YES);
3228: HTRequest_addAfter (me->request, HTUseProxyFilter, "http://*", NULL,
3229: HT_USE_PROXY, HT_FILTER_MIDDLE, YES);
1.172 cvs 3230: }
1.168 cvs 3231: }
3232: else
3233: {
1.172 cvs 3234: /* don't use preconditions */
1.168 cvs 3235: HTRequest_setPreconditions(me->request, HT_NO_MATCH);
3236: }
1.151 cvs 3237:
1.136 cvs 3238: /* don't use the cache while saving a document */
3239: HTRequest_setReloadMode (me->request, HT_CACHE_FLUSH);
1.116 cvs 3240:
1.164 cvs 3241: /* Throw away any reponse body */
3242: /*
3243: HTRequest_setOutputStream (me->request, HTBlackHole());
3244: */
3245:
1.168 cvs 3246: /* prepare the URLname that will be displayed in the status bar */
1.74 cvs 3247: ChopURL (me->status_urlName, me->urlName);
1.198 cvs 3248: TtaSetStatus (me->docid, 1, TtaGetMessage (AMAYA, AM_REMOTE_SAVING), ISO2WideChar (me->status_urlName));
1.114 cvs 3249:
1.164 cvs 3250: /* make the request */
1.172 cvs 3251: if (lost_update_check && (!UsePreconditions || !etag))
1.168 cvs 3252: status = HTHeadAnchor (me->dest, me->request);
3253: else
3254: status = HTPutDocumentAnchor (HTAnchor_parent (me->source), me->dest, me->request);
1.4 cvs 3255:
1.130 cvs 3256: if (status == YES && me->reqStatus != HT_ERR)
1.7 cvs 3257: {
1.168 cvs 3258: /* part of the stop button handler */
3259: if ((mode & AMAYA_SYNC) || (mode & AMAYA_ISYNC))
3260: status = LoopForStop (me);
1.15 cvs 3261: }
1.136 cvs 3262: if (!HTRequest_kill (me->request))
3263: AHTReqContext_delete (me);
1.168 cvs 3264:
1.116 cvs 3265: TtaHandlePendingEvents ();
1.90 cvs 3266:
1.130 cvs 3267: return (status == YES ? 0 : -1);
1.28 cvs 3268: }
1.4 cvs 3269:
1.5 cvs 3270: /*----------------------------------------------------------------------
1.138 cvs 3271: StopRequest
1.17 cvs 3272: stops (kills) all active requests associated with a docid
1.5 cvs 3273: ----------------------------------------------------------------------*/
1.4 cvs 3274: #ifdef __STDC__
3275: void StopRequest (int docid)
3276: #else
3277: void StopRequest (docid)
3278: int docid;
3279: #endif
3280: {
1.140 cvs 3281: if (Amaya && CanDoStop ())
1.138 cvs 3282: {
1.139 cvs 3283: #if 0 /* for later */
1.140 cvs 3284: AHTDocId_Status *docid_status;
3285: /* verify if there are any requests at all associated with docid */
1.138 cvs 3286: docid_status = (AHTDocId_Status *) GetDocIdStatus (docid,
3287: Amaya->docid_status);
3288: if (docid_status == (AHTDocId_Status *) NULL)
3289: return;
1.139 cvs 3290: #endif /* 0 */
1.138 cvs 3291: /* temporary call to stop all requests, as libwww changed its API */
3292: StopAllRequests (docid);
3293: }
3294: }
3295:
1.190 cvs 3296: /* @@@ the docid parameter isn't used... clean it up */
1.138 cvs 3297: /*----------------------------------------------------------------------
3298: StopAllRequests
3299: stops (kills) all active requests. We use the docid
3300: ----------------------------------------------------------------------*/
3301: #ifdef __STDC__
3302: void StopAllRequests (int docid)
3303: #else
1.140 cvs 3304: void StopAllRequests (docid)
1.138 cvs 3305: int docid;
3306: #endif
3307: {
1.4 cvs 3308: HTList *cur;
3309: AHTReqContext *me;
1.191 cvs 3310: static ThotBool lock_stop = 0;
3311: ThotBool async_flag;
1.116 cvs 3312:
1.138 cvs 3313: /* only do the stop if we're not being called while processing a
1.146 cvs 3314: request, and if we're not already dealing with a stop */
3315: if (Amaya && CanDoStop () && !lock_stop)
1.7 cvs 3316: {
1.100 cvs 3317: #ifdef DEBUG_LIBWWW
1.138 cvs 3318: fprintf (stderr, "StopRequest: number of Amaya requests "
3319: "before kill: %d\n", Amaya->open_requests);
1.100 cvs 3320: #endif /* DEBUG_LIBWWW */
1.150 cvs 3321: /* enter the critical section */
1.146 cvs 3322: lock_stop = TRUE;
1.214 cvs 3323: /* set a module global variable so that we can do special
3324: processing easier */
3325: UserAborted_flag = TRUE;
1.164 cvs 3326: /* expire all outstanding timers */
3327: HTTimer_expireAll ();
1.160 cvs 3328: /* HTNet_killAll (); */
1.116 cvs 3329: cur = Amaya->reqlist;
3330: while ((me = (AHTReqContext *) HTList_nextObject (cur)))
3331: {
1.140 cvs 3332: if (AmayaIsAlive ())
1.160 cvs 3333: {
1.161 cvs 3334: #ifdef DEBUG_LIBWWW
1.163 cvs 3335: fprintf (stderr,"StopRequest: killing req %p, url %s, status %d\n", me, me->urlName, me->reqStatus);
1.161 cvs 3336: #endif /* DEBUG_LIBWWW */
3337:
1.165 cvs 3338: if (me->reqStatus != HT_END && me->reqStatus != HT_ABORT)
1.163 cvs 3339: {
3340: if ((me->mode & AMAYA_ASYNC)
3341: || (me->mode & AMAYA_IASYNC))
3342: async_flag = TRUE;
3343: else
3344: async_flag = FALSE;
3345:
1.165 cvs 3346: /* change the status to say that the request aborted */
3347: me->reqStatus = HT_ABORT;
3348:
1.163 cvs 3349: /* kill the request, using the appropriate function */
3350: if (me->request->net)
3351: HTNet_killPipe (me->request->net);
3352: else
3353: {
1.160 cvs 3354: if (me->terminate_cbf)
1.198 cvs 3355: (*me->terminate_cbf) (me->docid, -1, ISO2WideChar (me->urlName),
3356: ISO2WideChar (me->outputfile),
3357: ISO2WideChar (me->content_type),
1.160 cvs 3358: me->context_tcbf);
1.164 cvs 3359:
3360: if (async_flag)
1.165 cvs 3361: /* explicitly free the request context for async
3362: requests. The sync requests context is freed by LoopForStop */
1.164 cvs 3363: AHTReqContext_delete (me);
1.160 cvs 3364: }
1.163 cvs 3365: cur = Amaya->reqlist;
3366: }
1.142 cvs 3367: #ifndef _WINDOWS
3368: #ifdef WWW_XWINDOWS
1.140 cvs 3369: /* to be on the safe side, remove all outstanding X events */
1.160 cvs 3370: else
3371: RequestKillAllXtevents (me);
1.142 cvs 3372: #endif /* WWW_XWINDOWS */
3373: #endif /* !_WINDOWS */
1.160 cvs 3374: }
1.116 cvs 3375: }
1.150 cvs 3376: /* Delete remaining channels */
3377: HTChannel_safeDeleteAll ();
1.214 cvs 3378: /* reset the stop status */
3379: UserAborted_flag = FALSE;
1.150 cvs 3380: /* exit the critical section */
1.148 cvs 3381: lock_stop = FALSE;
1.100 cvs 3382: #ifdef DEBUG_LIBWWW
1.138 cvs 3383: fprintf (stderr, "StopRequest: number of Amaya requests "
3384: "after kill: %d\n", Amaya->open_requests);
1.100 cvs 3385: #endif /* DEBUG_LIBWWW */
1.138 cvs 3386: }
3387: } /* StopAllRequests */
1.17 cvs 3388:
3389:
1.105 cvs 3390: /*----------------------------------------------------------------------
3391: AmayaIsAlive
1.140 cvs 3392: returns the value of the AmayaAlive_flag
1.105 cvs 3393: ----------------------------------------------------------------------*/
3394: #ifdef __STDC__
1.191 cvs 3395: ThotBool AmayaIsAlive (void)
1.105 cvs 3396: #else
1.191 cvs 3397: ThotBool AmayaIsAlive ()
1.105 cvs 3398: #endif /* _STDC_ */
3399: {
1.140 cvs 3400: return AmayaAlive_flag;
3401: }
3402:
3403: /*----------------------------------------------------------------------
3404: CanDoStop
3405: returns the value of the CanDoStop flag
3406: ----------------------------------------------------------------------*/
3407: #ifdef __STDC__
1.191 cvs 3408: ThotBool CanDoStop (void)
1.140 cvs 3409: #else
1.191 cvs 3410: ThotBool CanDoStop ()
1.140 cvs 3411: #endif /* _STDC_ */
3412: {
3413: return CanDoStop_flag;
3414: }
3415:
3416: /*----------------------------------------------------------------------
3417: CanDoStop_set
3418: sets the value of the CanDoStop flag
3419: ----------------------------------------------------------------------*/
3420: #ifdef __STDC__
1.191 cvs 3421: void CanDoStop_set (ThotBool value)
1.140 cvs 3422: #else
3423: void CanDoStop (value)
1.191 cvs 3424: ThotBool value;
1.140 cvs 3425: #endif /* _STDC_ */
3426: {
3427: CanDoStop_flag = value;
1.176 cvs 3428: }
3429:
3430: #ifdef __STDC__
3431: void libwww_updateNetworkConf (int status)
3432: #else
3433: void libwww_updateNetworkConf (status)
3434: int status;
3435: #endif /*__STDC__*/
3436: {
3437: /* @@@ the docid parameter isn't used... clean it up */
3438: int docid = 1;
3439:
3440: /* first, stop all current requests, as the network
3441: may make some changes */
3442: StopAllRequests (docid);
1.207 cvs 3443:
3444: if (status & AMAYA_SAFEPUT_RESTART)
3445: {
3446: SafePut_delete ();
3447: SafePut_init ();
3448: }
1.176 cvs 3449:
3450: if (status & AMAYA_PROXY_RESTART)
3451: {
3452: HTProxy_deleteAll ();
3453: ProxyInit ();
3454: }
3455:
3456: if (status & AMAYA_CACHE_RESTART)
3457: {
3458: clear_cachelock ();
3459: HTCacheTerminate ();
3460: HTCacheMode_setEnabled (NO);
3461: CacheInit ();
3462: }
1.193 cvs 3463:
3464: if (status & AMAYA_LANNEG_RESTART)
3465: {
3466: /* clear the current values */
3467: if (acceptLanguages)
3468: HTLanguage_deleteAll (acceptLanguages);
3469: /* read in the new ones */
3470: acceptLanguages = HTList_new ();
3471: AHTAcceptLanguagesInit (acceptLanguages);
3472: }
1.105 cvs 3473: }
1.116 cvs 3474:
1.69 cvs 3475: #endif /* AMAYA_JAVA */
1.77 cvs 3476:
1.116 cvs 3477: /*
3478: end of Module query.c
3479: */
Webmaster