Annotation of Amaya/amaya/query.c, revision 1.222
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.220 cvs 1069:
1070: /* trying to protect against this problem... hard to place
1071: the detection elsewhere :-/ */
1072: if (IsHTTP09Error (request))
1073: status = -1;
1074:
1.77 cvs 1075: if (status == HT_LOADED ||
1076: status == HT_CREATED ||
1.79 cvs 1077: status == HT_NO_DATA ||
1.160 cvs 1078: /* kludge for work around libwww problem */
1079: (status == HT_INTERRUPTED && me->method == METHOD_PUT) ||
1.116 cvs 1080: #ifdef AMAYA_WWW_CACHE
1081: /* what status to use to know we're downloading from a cache? */
1082: status == HT_NOT_MODIFIED ||
1083: #endif /* AMAYA_WWW_CACHE */
1.79 cvs 1084: me->reqStatus == HT_ABORT)
1.74 cvs 1085: error_flag = FALSE;
1.220 cvs 1086: else
1.74 cvs 1087: error_flag = TRUE;
1.130 cvs 1088:
1.4 cvs 1089: /* output any errors from the server */
1.130 cvs 1090:
1.77 cvs 1091: /*
1.74 cvs 1092: ** me->output = output file which will receive an html file
1093: ** me->error_html = yes, output HTML errors in the screen
1094: ** request->error_stack == if there are any errors, they will be here
1095: ** me->error_stream_size If it's != 0 means an error message has already
1096: ** been written to the stack
1097: */
1098:
1.4 cvs 1099: /* First, we verify if there are any errors and if they are not
1.17 cvs 1100: ** yet written to the error stack. If no, then let's try to write them
1101: ** ourselves
1102: */
1.74 cvs 1103:
1104: #ifdef DEBUG_LIBWWW
1105: fprintf (stderr, "terminate_handler: URL is "
1106: "%s, closing FILE %p status is %d\n", me->urlName, me->output,
1107: status);
1.69 cvs 1108: #endif
1.74 cvs 1109:
1.69 cvs 1110: if (me->output && me->output != stdout)
1111: {
1.214 cvs 1112: /* we are writing to a local file */
1.74 cvs 1113: if (me->reqStatus != HT_ABORT)
1114: { /* if the request was not aborted and */
1.80 cvs 1115: if (error_flag &&
1116: me->error_html == TRUE)
1117: /* there were some errors and we want to print them */
1118: {
1119: if (me->error_stream_size == 0)/* and the stream is empty */
1.210 cvs 1120: {
1121: /* if the transfer was interrupted, the file may not be
1122: empty. So, we erase it */
1123: fflush (me->output);
1124: rewind (me->output);
1125: AHTError_MemPrint (request); /* copy errors from
1126: **the error stack
1127: ** into the error stream */
1128: }
1.80 cvs 1129: if (me->error_stream)
1130: { /* if the stream is non-empty */
1131: fprintf (me->output, me->error_stream);/* output the errors */
1.85 cvs 1132: /* Clear the error context, so that we can deal with
1133: this answer as if it were a normal reply */
1134: HTError_deleteAll( HTRequest_error (request));
1135: HTRequest_setError (request, NULL);
1136: error_flag = 0;
1.74 cvs 1137: }
1138: } /* if error_stack */
1.85 cvs 1139: }
1140:
1141: /* if != HT_ABORT */
1142:
1143: #ifdef DEBUG_LIBWWW
1144: fprintf (stderr, "terminate_handler: URL is %s, closing "
1145: "FILE %p\n", me->urlName, me->output);
1146: #endif
1.74 cvs 1147: fclose (me->output);
1148: me->output = NULL;
1.69 cvs 1149: }
1.80 cvs 1150:
1.214 cvs 1151: /* a very special handling so that we can put a message box
1152: to tell the user WHAT he has just done... */
1153: if (UserAborted_flag && me->method == METHOD_PUT)
1154: {
1155: HTRequest_addError (request, ERR_FATAL, NO, HTERR_INTERRUPTED,
1156: "Operation aborted by user", 0, NULL);
1157: }
1158:
1.80 cvs 1159: if (error_flag)
1160: me->reqStatus = HT_ERR;
1.214 cvs 1161: else
1162: if (me->reqStatus != HT_ABORT)
1163: me->reqStatus = HT_END;
1164:
1.116 cvs 1165: /* copy the content_type */
1.151 cvs 1166: if (!me->content_type)
1.88 cvs 1167: {
1.184 cvs 1168: anchor = HTRequest_anchor (request);
1169: if (anchor && HTAnchor_format (anchor))
1170: content_type = HTAtom_name (HTAnchor_format (anchor));
1.154 cvs 1171: else
1172: content_type = "www/unknown";
1173:
1.151 cvs 1174: if (content_type && content_type [0] != EOS)
1175: {
1176: /* libwww gives www/unknown when it gets an error. As this is
1177: an HTML test, we force the type to text/html */
1178: if (!strcmp (content_type, "www/unknown"))
1.198 cvs 1179: me->content_type = WideChar2ISO (TtaStrdup (TEXT("text/html")));
1.151 cvs 1180: else
1.198 cvs 1181: me->content_type = WideChar2ISO (TtaStrdup (ISO2WideChar (content_type)));
1.151 cvs 1182:
1183: /* Content-Type can be specified by an httpd server's admin.
1184: To be on the safe side, we normalize its case */
1.198 cvs 1185: ConvertToLowerCase (ISO2WideChar (me->content_type));
1.151 cvs 1186:
1.88 cvs 1187: #ifdef DEBUG_LIBWWW
1.151 cvs 1188: fprintf (stderr, "content type is: %s\n", me->content_type);
1.88 cvs 1189: #endif /* DEBUG_LIBWWW */
1.151 cvs 1190: }
1191: }
1.114 cvs 1192:
1.115 cvs 1193: /* to avoid a hangup while downloading css files */
1.140 cvs 1194: if (AmayaAlive_flag && (me->mode & AMAYA_LOAD_CSS))
1.116 cvs 1195: TtaSetStatus (me->docid, 1,
1196: TtaGetMessage (AMAYA, AM_ELEMENT_LOADED),
1.198 cvs 1197: ISO2WideChar (me->status_urlName));
1.116 cvs 1198:
1199: /* don't remove or Xt will hang up during the PUT */
1200: if (AmayaIsAlive () && ((me->method == METHOD_POST) ||
1201: (me->method == METHOD_PUT)))
1.7 cvs 1202: {
1.80 cvs 1203: PrintTerminateStatus (me, status);
1204: }
1.114 cvs 1205:
1.111 cvs 1206: ProcessTerminateRequest (request, response, context, status);
1.116 cvs 1207:
1.151 cvs 1208: /* stop here */
1.150 cvs 1209: return HT_ERROR;
1.4 cvs 1210: }
1211:
1.5 cvs 1212: /*----------------------------------------------------------------------
1.17 cvs 1213: AHTLoadTerminate_handler
1.74 cvs 1214: this is an application "AFTER" Callback. It's called by the library
1215: when a request has ended, so that we can setup the correct status.
1.5 cvs 1216: ----------------------------------------------------------------------*/
1.4 cvs 1217:
1218: #ifdef __STDC__
1.111 cvs 1219: int AHTLoadTerminate_handler (HTRequest * request, HTResponse * response, void *param, int status)
1.4 cvs 1220: #else
1.111 cvs 1221: int AHTLoadTerminate_handler (request, response, param, status)
1.4 cvs 1222: HTRequest *request;
1223: HTResponse *response;
1224: void *param;
1225: int status;
1.69 cvs 1226:
1.4 cvs 1227: #endif
1228: {
1.116 cvs 1229:
1230: /** @@@@ use this with printstatus ?? */
1231:
1.4 cvs 1232: AHTReqContext *me = HTRequest_context (request);
1233: HTAlertCallback *cbf;
1234: AHTDocId_Status *docid_status;
1235:
1.7 cvs 1236: switch (status)
1.116 cvs 1237: {
1238: case HT_LOADED:
1239: if (PROT_TRACE)
1240: HTTrace ("Load End.... OK: `%s\' has been accessed\n",
1241: me->status_urlName);
1.4 cvs 1242:
1.116 cvs 1243: docid_status = GetDocIdStatus (me->docid,
1244: Amaya->docid_status);
1.7 cvs 1245:
1.116 cvs 1246: if (docid_status != NULL && docid_status->counter > 1)
1247: TtaSetStatus (me->docid, 1,
1248: TtaGetMessage (AMAYA, AM_ELEMENT_LOADED),
1.198 cvs 1249: ISO2WideChar (me->status_urlName));
1.7 cvs 1250: break;
1.116 cvs 1251:
1252: case HT_NO_DATA:
1253: if (PROT_TRACE)
1254: HTTrace ("Load End.... OK BUT NO DATA: `%s\'\n",
1255: me->status_urlName);
1256: TtaSetStatus (me->docid, 1,
1257: TtaGetMessage (AMAYA, AM_LOADED_NO_DATA),
1.198 cvs 1258: ISO2WideChar (me->status_urlName));
1.116 cvs 1259: break;
1260:
1261: case HT_INTERRUPTED:
1262: if (PROT_TRACE)
1263: HTTrace ("Load End.... INTERRUPTED: `%s\'\n",
1264: me->status_urlName);
1265: TtaSetStatus (me->docid, 1,
1266: TtaGetMessage (AMAYA, AM_LOAD_ABORT),
1267: NULL);
1268: break;
1.7 cvs 1269:
1.116 cvs 1270: case HT_RETRY:
1271: if (PROT_TRACE)
1272: HTTrace ("Load End.... NOT AVAILABLE, RETRY AT %ld\n",
1273: HTResponse_retryTime (response));
1274: TtaSetStatus (me->docid, 1,
1275: TtaGetMessage (AMAYA, AM_NOT_AVAILABLE_RETRY),
1.198 cvs 1276: ISO2WideChar (me->status_urlName));
1.116 cvs 1277: break;
1.7 cvs 1278:
1.116 cvs 1279: case HT_ERROR:
1280: cbf = HTAlert_find (HT_A_MESSAGE);
1281: if (cbf)
1282: (*cbf) (request, HT_A_MESSAGE, HT_MSG_NULL, NULL,
1283: HTRequest_error (request), NULL);
1284: break;
1285:
1286: if (PROT_TRACE)
1287: HTTrace ("Load End.... ERROR: Can't access `%s\'\n",
1288: me->status_urlName ? me->status_urlName :"<UNKNOWN>");
1289: TtaSetStatus (me->docid, 1,
1290: TtaGetMessage (AMAYA, AM_CANNOT_LOAD),
1.198 cvs 1291: me->status_urlName ? ISO2WideChar (me->status_urlName) : TEXT("<UNKNOWN>"));
1.116 cvs 1292: break;
1293: default:
1294: if (PROT_TRACE)
1295: HTTrace ("Load End.... UNKNOWN RETURN CODE %d\n", status);
1296: break;
1297: }
1298:
1299: return HT_OK;
1300: }
1.7 cvs 1301:
1.116 cvs 1302: #ifdef DEBUG_LIBWWW
1303: static int LineTrace (const char * fmt, va_list pArgs)
1304: {
1305: return (vfprintf(stderr, fmt, pArgs));
1.4 cvs 1306: }
1.116 cvs 1307: #endif DEBUG_LIBWWW
1.4 cvs 1308:
1.27 cvs 1309: /*----------------------------------------------------------------------
1310: AHTAcceptTypesInit
1.74 cvs 1311: This function prepares the Accept header used by Amaya during
1312: the HTTP content negotiation phase
1.27 cvs 1313: ----------------------------------------------------------------------*/
1314: #ifdef __STDC__
1315: static void AHTAcceptTypesInit (HTList *c)
1316: #else /* __STDC__ */
1317: static void AHTAcceptTypesInit (c)
1318: HTList *c;
1319: #endif /* __STDC__ */
1320: {
1321: if (c == (HTList *) NULL)
1322: return;
1323:
1324: /* define here all the mime types that Amaya can accept */
1325:
1.74 cvs 1326: HTConversion_add (c, "image/png", "www/present",
1327: HTThroughLine, 1.0, 0.0, 0.0);
1328: HTConversion_add (c, "image/jpeg", "www/present",
1329: HTThroughLine, 1.0, 0.0, 0.0);
1330: HTConversion_add (c, "image/gif", "www/present",
1331: HTThroughLine, 1.0, 0.0, 0.0);
1332: HTConversion_add (c, "image/xbm", "www/present",
1333: HTThroughLine, 1.0, 0.0, 0.0);
1334: HTConversion_add (c, "image/xpm", "www/present",
1335: HTThroughLine, 1.0, 0.0, 0.0);
1.183 cvs 1336:
1.27 cvs 1337: /* Define here the equivalences between MIME types and file extensions for
1338: the types that Amaya can display */
1339:
1.176 cvs 1340: /* Initialize suffix bindings for local files */
1341: HTBind_init();
1342:
1.27 cvs 1343: /* Register the default set of file suffix bindings */
1344: HTFileInit ();
1345:
1346: /* Don't do any case distinction */
1347: HTBind_caseSensitive (FALSE);
1348: }
1.4 cvs 1349:
1.5 cvs 1350: /*----------------------------------------------------------------------
1.193 cvs 1351: AHTAcceptLanguagesInit
1352: This function prepares the Accept header used by Amaya during
1353: the HTTP content negotiation phase
1354: ----------------------------------------------------------------------*/
1355: #ifdef __STDC__
1.196 cvs 1356: static void AHTAcceptLanguagesInit (HTList *c)
1.193 cvs 1357: #else /* __STDC__ */
1.196 cvs 1358: static void AHTAcceptLanguagesInit (c)
1.193 cvs 1359: HTList *c;
1360: #endif /* __STDC__ */
1361: {
1.196 cvs 1362: STRING ptr;
1363: STRING lang_list;
1364: CHAR_T s[3];
1365: int count, lg;
1366: double quality;
1367: ThotBool still;
1.193 cvs 1368:
1369: if (c == (HTList *) NULL)
1370: return;
1371:
1.203 cvs 1372: lang_list = TtaGetEnvString ("ACCEPT_LANGUAGES");
1.197 cvs 1373: s[2] = EOS;
1.196 cvs 1374: if (lang_list && *lang_list != EOS)
1.193 cvs 1375: {
1376: /* add the default language first */
1377: HTLanguage_add (c, "*", -1.0);
1378: /* how many languages do we have? */
1.196 cvs 1379: ptr = lang_list;
1380: count = 0;
1381: while (*ptr != EOS)
1382: {
1383: while (*ptr != EOS &&
1384: (*ptr < 'A' || (*ptr > 'Z' && *ptr < 'a') || *ptr > 'z'))
1385: /* skip the whole separator */
1386: ptr++;
1387: lg = 0;
1388: while ((*ptr >= 'A' && *ptr <= 'Z') || (*ptr >= 'a' && *ptr <= 'z') || *ptr == '-')
1389: {
1390: /* it's a new language */
1391: ptr++;
1392: lg++;
1393: }
1394: if (lg >= 2)
1.193 cvs 1395: count++;
1.196 cvs 1396: if (*ptr != EOS)
1397: ptr++;
1398: }
1.193 cvs 1399:
1.196 cvs 1400: if (count > 0)
1.193 cvs 1401: quality = 1.1 - (double) count/10.0;
1402: else
1403: quality = 1.0;
1404:
1.196 cvs 1405: /*
1406: Read the languages from the registry, then inject them one, by one.
1407: The first one is the one with the highest priority.
1408: The libwww ask for the lowest priority first.
1409: */
1410: ptr--;
1411: still = TRUE;
1412: while (count)
1.193 cvs 1413: {
1.196 cvs 1414: while (still &&
1415: (*ptr < 'A' || (*ptr > 'Z' && *ptr < 'a') || *ptr > 'z'))
1416: /* skip the whole separator */
1417: if (ptr > lang_list)
1418: ptr--;
1419: else
1420: still = FALSE;
1421: lg = 0;
1422: while (still &&
1423: ((*ptr >= 'A' && *ptr <= 'Z') || (*ptr >= 'a' && *ptr <= 'z') || *ptr == '-'))
1424: {
1425: /* it's a new language */
1426: if (ptr > lang_list)
1427: ptr--;
1428: else
1429: still = FALSE;
1430: lg++;
1431: }
1432: if (lg >= 2)
1433: {
1434: if (still)
1435: ustrncpy (s, &ptr[1], 2);
1436: else
1437: ustrncpy (s, lang_list, 2);
1438: count--;
1.198 cvs 1439: HTLanguage_add (c, WideChar2ISO(s), quality);
1.196 cvs 1440: quality += 0.1;
1441: }
1442: ptr--;
1.193 cvs 1443: }
1444: }
1445: }
1446:
1447: /*----------------------------------------------------------------------
1.17 cvs 1448: AHTConverterInit
1449: Bindings between a source media type and a destination media type
1450: (conversion).
1.5 cvs 1451: ----------------------------------------------------------------------*/
1.15 cvs 1452: #ifdef __STDC__
1453: static void AHTConverterInit (HTList *c)
1454: #else /* __STDC__ */
1455: static void AHTConverterInit (c)
1456: HTList *c;
1457: #endif /* __STDC__ */
1.4 cvs 1458: {
1459:
1460: /* Handler for custom http error messages */
1.7 cvs 1461: HTConversion_add (c, "*/*", "www/debug", AHTMemConverter, 1.0, 0.0, 0.0);
1.4 cvs 1462:
1463: /*
1464: ** These are converters that converts to something other than www/present,
1465: ** that is not directly outputting someting to the user on the screen
1466: */
1467:
1.116 cvs 1468: HTConversion_add (c, "message/rfc822", "*/*", HTMIMEConvert,
1469: 1.0, 0.0, 0.0);
1.4 cvs 1470: HTConversion_add (c, "message/x-rfc822-foot", "*/*", HTMIMEFooter,
1471: 1.0, 0.0, 0.0);
1472: HTConversion_add (c, "message/x-rfc822-head", "*/*", HTMIMEHeader,
1473: 1.0, 0.0, 0.0);
1.116 cvs 1474: HTConversion_add(c,"message/x-rfc822-cont", "*/*", HTMIMEContinue,
1475: 1.0, 0.0, 0.0);
1476: HTConversion_add(c,"message/x-rfc822-partial","*/*", HTMIMEPartial,
1477: 1.0, 0.0, 0.0);
1.4 cvs 1478: HTConversion_add (c, "multipart/*", "*/*", HTBoundary,
1479: 1.0, 0.0, 0.0);
1480: HTConversion_add (c, "text/plain", "text/html", HTPlainToHTML,
1481: 1.0, 0.0, 0.0);
1482:
1483: /*
1.116 cvs 1484: ** The following conversions are converting ASCII output from various
1485: ** protocols to HTML objects.
1486: */
1.4 cvs 1487: HTConversion_add (c, "text/x-http", "*/*", HTTPStatus_new,
1488: 1.0, 0.0, 0.0);
1489:
1490: /*
1.116 cvs 1491: ** We also register a special content type guess stream that can figure out
1492: ** the content type by reading the first bytes of the stream
1493: */
1.4 cvs 1494: HTConversion_add (c, "www/unknown", "*/*", HTGuess_new,
1495: 1.0, 0.0, 0.0);
1496:
1.116 cvs 1497: #ifdef AMAYA_WWW_CACHE
1.4 cvs 1498: /*
1.116 cvs 1499: ** Register a persistent cache stream which can save an object to local
1500: ** file
1501: */
1.4 cvs 1502: HTConversion_add (c, "www/cache", "*/*", HTCacheWriter,
1503: 1.0, 0.0, 0.0);
1.116 cvs 1504: HTConversion_add(c,"www/cache-append", "*/*", HTCacheAppend,
1505: 1.0, 0.0, 0.0);
1506: #endif AMAYA_WWW_CACHE
1.4 cvs 1507:
1508: /*
1.116 cvs 1509: ** This dumps all other formats to local disk without any further
1510: ** action taken
1511: */
1.4 cvs 1512: HTConversion_add (c, "*/*", "www/present", HTSaveLocally,
1.190 cvs 1513: 0.3, 0.0, 0.0);
1.4 cvs 1514: }
1515:
1.27 cvs 1516:
1.15 cvs 1517: /*----------------------------------------------------------------------
1.17 cvs 1518: AHTProtocolInit
1519: Registers all amaya supported protocols.
1.15 cvs 1520: ----------------------------------------------------------------------*/
1.4 cvs 1521: static void AHTProtocolInit (void)
1522: {
1.116 cvs 1523: char *strptr;
1.4 cvs 1524:
1.116 cvs 1525: /*
1526: NB. Preemptive == YES means Blocking requests
1527: Non-preemptive == NO means Non-blocking requests
1528: */
1529: HTTransport_add("tcp", HT_TP_SINGLE, HTReader_new, HTWriter_new);
1530: HTTransport_add("buffered_tcp", HT_TP_SINGLE, HTReader_new,
1531: HTBufferWriter_new);
1532: HTProtocol_add ("http", "buffered_tcp", HTTP_PORT, NO, HTLoadHTTP, NULL);
1.136 cvs 1533: #ifdef _WINDOWS
1534: HTProtocol_add ("file", "local", 0, YES, HTLoadFile, NULL);
1535: #else
1.116 cvs 1536: HTProtocol_add ("file", "local", 0, NO, HTLoadFile, NULL);
1.198 cvs 1537: #endif /* _WINDOWS */
1.116 cvs 1538: #ifdef AMAYA_WWW_CACHE
1539: HTProtocol_add("cache", "local", 0, YES, HTLoadCache, NULL);
1540: #endif /* AMAYA_WWW_CACHE */
1.103 cvs 1541: #if 0 /* experimental code */
1.116 cvs 1542: HTProtocol_add ("ftp", "tcp", FTP_PORT, NO, HTLoadFTP, NULL);
1.17 cvs 1543: #endif
1.116 cvs 1544:
1545: /* initialize pipelining */
1.203 cvs 1546: strptr = (char *) TtaGetEnvString ("ENABLE_PIPELINING");
1.116 cvs 1547: if (strptr && *strptr && strcasecmp (strptr,"yes" ))
1548: HTTP_setConnectionMode (HTTP_11_NO_PIPELINING);
1.4 cvs 1549: }
1550:
1.15 cvs 1551: /*----------------------------------------------------------------------
1.17 cvs 1552: AHTNetInit
1553: Reegisters "before" and "after" request filters.
1.15 cvs 1554: ----------------------------------------------------------------------*/
1.4 cvs 1555: static void AHTNetInit (void)
1556: {
1557:
1558: /* Register BEFORE filters
1.74 cvs 1559: ** The BEFORE filters handle proxies, caches, rule files etc.
1560: ** The filters are called in the order by which the are registered
1561: ** Not done automaticly - may be done by application!
1562: */
1.4 cvs 1563:
1.116 cvs 1564: HTNet_addBefore (HTCredentialsFilter, "http://*", NULL, HT_FILTER_LATE);
1565: HTNet_addBefore (HTProxyFilter, NULL, NULL, HT_FILTER_LATE);
1.85 cvs 1566: HTHost_setActivateRequestCallback (AHTOpen_file);
1.4 cvs 1567:
1568: /* register AFTER filters
1.74 cvs 1569: ** The AFTER filters handle error messages, logging, redirection,
1570: ** authentication etc.
1571: ** The filters are called in the order by which the are registered
1572: ** Not done automaticly - may be done by application!
1573: */
1.4 cvs 1574:
1.116 cvs 1575: HTNet_addAfter (HTAuthFilter, "http://*", NULL, HT_NO_ACCESS,
1576: HT_FILTER_MIDDLE);
1577: HTNet_addAfter(HTAuthFilter, "http://*", NULL, HT_REAUTH,
1578: HT_FILTER_MIDDLE);
1579: HTNet_addAfter (redirection_handler, "http://*", NULL, HT_PERM_REDIRECT,
1580: HT_FILTER_MIDDLE);
1581: HTNet_addAfter (redirection_handler, "http://*", NULL, HT_FOUND,
1582: HT_FILTER_MIDDLE);
1583: HTNet_addAfter (redirection_handler, "http://*", NULL, HT_SEE_OTHER,
1584: HT_FILTER_MIDDLE);
1585: HTNet_addAfter (redirection_handler, "http://*", NULL, HT_TEMP_REDIRECT,
1586: HT_FILTER_MIDDLE);
1.168 cvs 1587: HTNet_addAfter(HTAuthInfoFilter, "http://*", NULL, HT_ALL,
1588: HT_FILTER_MIDDLE);
1.116 cvs 1589: HTNet_addAfter (HTUseProxyFilter, "http://*", NULL, HT_USE_PROXY,
1590: HT_FILTER_MIDDLE);
1.151 cvs 1591: #ifdef AMAYA_LOST_UPDATE
1592: HTNet_addAfter (precondition_handler, NULL, NULL, HT_PRECONDITION_FAILED,
1593: HT_FILTER_MIDDLE);
1594: #endif /* AMAYA_LOST_UPDATE */
1.111 cvs 1595: #ifndef _WINDOWS
1.116 cvs 1596: HTNet_addAfter (AHTLoadTerminate_handler, NULL, NULL, HT_ALL,
1597: HT_FILTER_LAST);
1.111 cvs 1598: #endif /* !_WINDOWS */
1.116 cvs 1599: /**** for later ?? ****/
1600: /* HTNet_addAfter(HTInfoFilter, NULL, NULL, HT_ALL, HT_FILTER_LATE); */
1.51 cvs 1601: /* handles all errors */
1.116 cvs 1602: HTNet_addAfter (terminate_handler, NULL, NULL, HT_ALL, HT_FILTER_LAST);
1.4 cvs 1603: }
1604:
1.15 cvs 1605: /*----------------------------------------------------------------------
1.17 cvs 1606: AHTAlertInit
1607: Register alert messages and their callbacks.
1.15 cvs 1608: ----------------------------------------------------------------------*/
1609: #ifdef __STDC__
1610: static void AHTAlertInit (void)
1611: #else
1612: static void AHTAlertInit ()
1613: #endif
1614: {
1615: HTAlert_add (AHTProgress, HT_A_PROGRESS);
1.120 cvs 1616: #ifdef __WINDOWS
1.70 cvs 1617: HTAlert_add ((HTAlertCallback *) WIN_Activate_Request, HT_PROG_CONNECT);
1.116 cvs 1618: #endif /* _WINDOWS */
1.15 cvs 1619: HTAlert_add (AHTError_print, HT_A_MESSAGE);
1.48 cvs 1620: HTError_setShow (~((unsigned int) 0 ) & ~((unsigned int) HT_ERR_SHOW_DEBUG)); /* process all messages except debug ones*/
1.15 cvs 1621: HTAlert_add (AHTConfirm, HT_A_CONFIRM);
1622: HTAlert_add (AHTPrompt, HT_A_PROMPT);
1623: HTAlert_add (AHTPromptUsernameAndPassword, HT_A_USER_PW);
1.116 cvs 1624: }
1625:
1.128 cvs 1626: /*----------------------------------------------------------------------
1627: libwww_CleanCache
1628: frontend to the recursive cache cleaning function
1629: ----------------------------------------------------------------------*/
1630: #ifdef __STDC__
1631: void libwww_CleanCache (void)
1632: #else
1633: void libwww_CleanCache ()
1634: Document doc;
1635: View view;
1636: #endif /* __STDC__ */
1637: {
1.130 cvs 1638: #ifdef AMAYA_WWW_CACHE
1.198 cvs 1639: STRING real_dir;
1640: STRING cache_dir;
1641: STRING tmp;
1.128 cvs 1642: int cache_size;
1.177 cvs 1643: int cache_expire;
1644: int cache_disconnect;
1.191 cvs 1645: ThotBool error;
1.185 cvs 1646: STRING ptr;
1.130 cvs 1647:
1.128 cvs 1648: if (!HTCacheMode_enabled ())
1.183 cvs 1649: /* don't do anything if we're not using a cache */
1650: return;
1.128 cvs 1651: /* temporarily close down the cache, purge it, then restart */
1.198 cvs 1652: tmp = ISO2WideChar (HTCacheMode_getRoot ());
1.190 cvs 1653: /* don't do anything if we don't have a valid cache dir */
1654: if (!tmp || *tmp == EOS)
1655: return;
1656: cache_dir = TtaStrdup (tmp);
1.128 cvs 1657: cache_size = HTCacheMode_maxSize ();
1.177 cvs 1658: cache_expire = HTCacheMode_expires ();
1659: cache_disconnect = HTCacheMode_disconnected ();
1660:
1.185 cvs 1661: /* get something we can work on :) */
1.198 cvs 1662: tmp = ISO2WideChar (HTWWWToLocal (WideChar2ISO (cache_dir), "file:", NULL));
1663: real_dir = TtaAllocString (ustrlen (tmp) + 20);
1664: ustrcpy (real_dir, tmp);
1.190 cvs 1665: HT_FREE (tmp);
1.185 cvs 1666:
1667: /* safeguard... abort the operation if cache_dir doesn't end with
1668: CACHE_DIR_NAME */
1669: error = TRUE;
1.198 cvs 1670: ptr = ustrstr (real_dir, CACHE_DIR_NAME);
1671: if (ptr && *ptr && !ustrcasecmp (ptr, CACHE_DIR_NAME))
1.185 cvs 1672: error = FALSE;
1673: if (error)
1674: return;
1675:
1.130 cvs 1676: /* remove the concurrent cache lock */
1677: #ifdef DEBUG_LIBWWW
1678: fprintf (stderr, "Clearing the cache lock\n");
1679: #endif /* DEBUG_LIBWWW */
1680: clear_cachelock ();
1.128 cvs 1681: HTCacheTerminate ();
1.185 cvs 1682: HTCacheMode_setEnabled (FALSE);
1683:
1684: RecCleanCache (real_dir);
1.128 cvs 1685:
1.177 cvs 1686: HTCacheMode_setExpires (cache_expire);
1687: HTCacheMode_setDisconnected (cache_disconnect);
1.198 cvs 1688: HTCacheInit (WideChar2ISO (cache_dir), cache_size);
1.130 cvs 1689: /* set a new concurrent cache lock */
1.198 cvs 1690: ustrcat (real_dir, TEXT(".lock"));
1.185 cvs 1691: if (set_cachelock (real_dir) == -1)
1.130 cvs 1692: /* couldn't open the .lock file, so, we close the cache to
1693: be in the safe side */
1694: {
1695: #ifdef DEBUG_LIBWWW
1696: fprintf (stderr, "couldnt set the cache lock\n");
1697: #endif /* DEBUG_LIBWWW */
1698: HTCacheTerminate ();
1.185 cvs 1699: HTCacheMode_setEnabled (FALSE);
1.130 cvs 1700: }
1701: #ifdef DEBUG_LIBWWW
1702: fprintf (stderr, "set a cache lock\n");
1703: #endif /* DEBUG_LIBWWW */
1.185 cvs 1704: TtaFreeMemory (real_dir);
1.128 cvs 1705: TtaFreeMemory (cache_dir);
1706: #endif /* AMAYA_WWW_CACHE */
1707: }
1708:
1.118 cvs 1709: #ifdef AMAYA_WWW_CACHE
1710: /*----------------------------------------------------------------------
1.128 cvs 1711: RecCleanCache
1.118 cvs 1712: Clears an existing cache directory
1713: ----------------------------------------------------------------------*/
1714: #ifdef __STDC__
1.198 cvs 1715: static void RecCleanCache (STRING dirname)
1.118 cvs 1716: #else
1.198 cvs 1717: static void RecCleanCache (dirname)
1718: STRING dirname;
1.118 cvs 1719: #endif /* __STDC__ */
1.128 cvs 1720:
1721: #ifdef _WINDOWS
1722: {
1723: HANDLE hFindFile;
1.191 cvs 1724: ThotBool status;
1.128 cvs 1725: WIN32_FIND_DATA ffd;
1726:
1.198 cvs 1727: CHAR_T t_dir [MAX_LENGTH];
1728: STRING ptr;
1.128 cvs 1729:
1.130 cvs 1730: /* create a t_dir name to start searching for files */
1.198 cvs 1731: if ((ustrlen (dirname) + 10) > MAX_LENGTH)
1.128 cvs 1732: /* ERROR: directory name is too big */
1733: return;
1734:
1.198 cvs 1735: ustrcpy (t_dir, dirname);
1.130 cvs 1736: /* save the end of the dirname. We'll use it to make
1737: a complete pathname when erasing files */
1.198 cvs 1738: ptr = &t_dir[ustrlen (t_dir)];
1739: ustrcat (t_dir, TEXT("*"));
1.128 cvs 1740:
1.130 cvs 1741: hFindFile = FindFirstFile (t_dir, &ffd);
1.128 cvs 1742:
1743: if (hFindFile == INVALID_HANDLE_VALUE)
1744: /* nothing to erase? */
1745: return;
1746:
1747: status = TRUE;
1.130 cvs 1748: while (status)
1749: {
1750: if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
1.133 cvs 1751: {
1752: /* it's a directory, erase it recursively */
1.198 cvs 1753: if (ustrcmp (ffd.cFileName, TEXT("..")) && ustrcmp (ffd.cFileName, TEXT(".")))
1.133 cvs 1754: {
1.198 cvs 1755: ustrcpy (ptr, ffd.cFileName);
1756: ustrcat (ptr, DIR_STR);
1.133 cvs 1757: RecCleanCache (t_dir);
1.198 cvs 1758: urmdir (t_dir);
1.133 cvs 1759: }
1760: }
1761: else
1.130 cvs 1762: {
1.133 cvs 1763: /* it's a file, erase it */
1.198 cvs 1764: ustrcpy (ptr, ffd.cFileName);
1.133 cvs 1765: TtaFileUnlink (t_dir);
1.130 cvs 1766: }
1767: status = FindNextFile (hFindFile, &ffd);
1768: }
1.128 cvs 1769: FindClose (hFindFile);
1770: }
1771:
1772: #else /* _WINDOWS */
1.118 cvs 1773: {
1774: DIR *dp;
1775: struct stat st;
1776: #ifdef HAVE_DIRENT_H
1777: struct dirent *d;
1778: #else
1779: struct direct *d;
1780: #endif /* HAVE_DIRENT_H */
1.128 cvs 1781: char filename[BUFSIZ+1];
1.118 cvs 1782:
1783: if ((dp = opendir (dirname)) == NULL)
1784: {
1785: /* @@@ we couldn't open the directory ... we need some msg */
1786: perror (dirname);
1.176 cvs 1787: return;
1.118 cvs 1788: }
1789:
1790: while ((d = readdir (dp)) != NULL)
1791: {
1792: /* skip the UNIX . and .. links */
1793: if (!strcmp (d->d_name, "..")
1794: || !strcmp (d->d_name, "."))
1795: continue;
1796:
1.188 cvs 1797: sprintf (filename, "%s%c%s", dirname, DIR_SEP, d->d_name);
1.118 cvs 1798: if (lstat (filename, &st) < 0 )
1799: {
1800: /* @@2 need some error message */
1801: perror (filename);
1802: continue;
1803: }
1804:
1805: switch (st.st_mode & S_IFMT)
1806: {
1807: case S_IFDIR:
1808: /* if we find a directory, we erase it, recursively */
1.128 cvs 1809: strcat (filename, DIR_STR);
1810: RecCleanCache (filename);
1811: rmdir (filename);
1.118 cvs 1812: break;
1813: case S_IFLNK:
1814: /* skip any links we find */
1815: continue;
1816: break;
1817: default:
1818: /* erase the filename */
1819: TtaFileUnlink (filename);
1820: break;
1821: }
1822: }
1823: closedir (dp);
1824: }
1.128 cvs 1825: #endif /* _WINDOWS */
1.118 cvs 1826: #endif /* AMAYA_WWW_CACHE */
1827:
1.116 cvs 1828: /*----------------------------------------------------------------------
1829: CacheInit
1830: Reads the cache settings from the thot.ini file.
1831: ----------------------------------------------------------------------*/
1.118 cvs 1832: #ifdef __STDC__
1.116 cvs 1833: static void CacheInit (void)
1.118 cvs 1834: #else
1835: static void Cacheinit ()
1836: #endif
1837:
1.116 cvs 1838: {
1839: #ifndef AMAYA_WWW_CACHE
1840: HTCacheMode_setEnabled (NO);
1841:
1842: #else /* AMAYA_WWW_CACHE */
1.198 cvs 1843: STRING strptr;
1844: STRING cache_dir = NULL;
1845: STRING real_dir = NULL;
1846: STRING cache_lockfile;
1.130 cvs 1847: int cache_size;
1.176 cvs 1848: int cache_entry_size;
1.191 cvs 1849: ThotBool cache_enabled;
1850: ThotBool cache_locked;
1851: ThotBool tmp_bool;
1.130 cvs 1852:
1.185 cvs 1853: int i;
1854:
1.116 cvs 1855: /* activate cache? */
1.203 cvs 1856: strptr = TtaGetEnvString ("ENABLE_CACHE");
1.198 cvs 1857: if (strptr && *strptr && ustrcasecmp (strptr, TEXT("yes")))
1.130 cvs 1858: cache_enabled = NO;
1.116 cvs 1859: else
1.130 cvs 1860: cache_enabled = YES;
1.116 cvs 1861:
1.151 cvs 1862: /* cache protected documents? */
1.203 cvs 1863: strptr = TtaGetEnvString ("CACHE_PROTECTED_DOCS");
1.198 cvs 1864: if (strptr && *strptr && !ustrcasecmp (strptr, TEXT("yes")))
1.151 cvs 1865: HTCacheMode_setProtected (YES);
1866: else
1867: HTCacheMode_setProtected (NO);
1868:
1.116 cvs 1869: /* get the cache dir (or use a default one) */
1.203 cvs 1870: strptr = TtaGetEnvString ("CACHE_DIR");
1.116 cvs 1871: if (strptr && *strptr)
1872: {
1.198 cvs 1873: real_dir = TtaAllocString (ustrlen (strptr) + ustrlen (CACHE_DIR_NAME) + 20);
1874: ustrcpy (real_dir, strptr);
1875: if (*(real_dir + ustrlen (real_dir) - 1) != DIR_SEP)
1876: ustrcat (real_dir, DIR_STR);
1.116 cvs 1877: }
1878: else
1879: {
1.198 cvs 1880: real_dir = TtaAllocString (ustrlen (TempFileDirectory)
1881: + ustrlen (CACHE_DIR_NAME) + 20);
1882: usprintf (real_dir, TEXT("%s%s"), TempFileDirectory, CACHE_DIR_NAME);
1.185 cvs 1883: }
1884:
1885: /* compatiblity with previous versions of Amaya: does real_dir
1886: include CACHE_DIR_NAME? If not, add it */
1.198 cvs 1887: strptr = ustrstr (real_dir, CACHE_DIR_NAME);
1.185 cvs 1888: if (!strptr)
1889: {
1.198 cvs 1890: ustrcat (real_dir, CACHE_DIR_NAME);
1.185 cvs 1891: }
1892: else
1893: {
1.198 cvs 1894: i = ustrlen (CACHE_DIR_NAME);
1.185 cvs 1895: if (strptr[i] != EOS)
1.198 cvs 1896: ustrcat (real_dir, CACHE_DIR_NAME);
1.116 cvs 1897: }
1.185 cvs 1898:
1.211 cvs 1899: /* convert the local cache dir into a file URL, as expected by
1900: libwww */
1901: cache_dir = HTLocalToWWW (WideChar2ISO (real_dir), "file:");
1.116 cvs 1902:
1903: /* get the cache size (or use a default one) */
1.203 cvs 1904: strptr = TtaGetEnvString ("CACHE_SIZE");
1.116 cvs 1905: if (strptr && *strptr)
1.198 cvs 1906: cache_size = uctoi (strptr);
1.116 cvs 1907: else
1908: cache_size = DEFAULT_CACHE_SIZE;
1909:
1.176 cvs 1910: /* get the max cached file size (or use a default one) */
1.198 cvs 1911: if (!TtaGetEnvInt (TEXT("MAX_CACHE_ENTRY_SIZE"), &cache_entry_size))
1.176 cvs 1912: cache_entry_size = DEFAULT_MAX_CACHE_ENTRY_SIZE;
1913:
1.130 cvs 1914: if (cache_enabled)
1.116 cvs 1915: {
1916: /* how to remove the lock? force remove it? */
1.198 cvs 1917: cache_lockfile = TtaAllocString (ustrlen (real_dir) + 20);
1918: ustrcpy (cache_lockfile, real_dir);
1919: ustrcat (cache_lockfile, TEXT(".lock"));
1.130 cvs 1920: cache_locked = FALSE;
1921: if (TtaFileExist (cache_lockfile)
1922: && !(cache_locked = test_cachelock (cache_lockfile)))
1.116 cvs 1923: {
1.130 cvs 1924: #ifdef DEBUG_LIBWWW
1925: fprintf (stderr, "found a stale cache, removing it\n");
1926: #endif /* DEBUG_LIBWWW */
1927: /* remove the lock and clean the cache (the clean cache
1928: will remove all, making the following call unnecessary */
1929: /* little trick to win some memory */
1.198 cvs 1930: strptr = ustrrchr (cache_lockfile, TEXT('.'));
1.130 cvs 1931: *strptr = EOS;
1932: RecCleanCache (cache_lockfile);
1933: *strptr = '.';
1.116 cvs 1934: }
1935:
1.130 cvs 1936: if (!cache_locked)
1937: {
1938: /* initialize the cache if there's no other amaya
1939: instance running */
1.177 cvs 1940: HTCacheMode_setMaxCacheEntrySize (cache_entry_size);
1.198 cvs 1941: if (TtaGetEnvBoolean (TEXT("CACHE_EXPIRE_IGNORE"), &tmp_bool)
1.177 cvs 1942: && tmp_bool)
1943: HTCacheMode_setExpires (HT_EXPIRES_IGNORE);
1944: else
1945: HTCacheMode_setExpires (HT_EXPIRES_AUTO);
1.198 cvs 1946: TtaGetEnvBoolean (TEXT("CACHE_DISCONNECTED_MODE"), &tmp_bool);
1.177 cvs 1947: if (tmp_bool)
1948: HTCacheMode_setDisconnected (HT_DISCONNECT_NORMAL);
1949: else
1950: HTCacheMode_setDisconnected (HT_DISCONNECT_NONE);
1.211 cvs 1951: if (HTCacheInit (cache_dir, cache_size))
1.130 cvs 1952: {
1.188 cvs 1953: if (set_cachelock (cache_lockfile) == -1)
1954: /* couldn't open the .lock file, so, we close the cache to
1955: be in the safe side */
1956: {
1957: HTCacheTerminate ();
1958: HTCacheMode_setEnabled (FALSE);
1959: #ifdef DEBUG_LIBWWW
1960: fprintf (stderr, "couldnt set the cache lock\n");
1961: #endif /* DEBUG_LIBWWW */
1962: }
1.130 cvs 1963: #ifdef DEBUG_LIBWWW
1.188 cvs 1964: else
1965: fprintf (stderr, "created the cache lock\n");
1.130 cvs 1966: #endif /* DEBUG_LIBWWW */
1967: }
1.188 cvs 1968: else
1969: {
1.130 cvs 1970: #ifdef DEBUG_LIBWWW
1.188 cvs 1971: fprintf (stderr, "couldn't create the cache\n");
1972: #endif /* DEBUG_LIBWWW */
1973: HTCacheTerminate ();
1974: }
1.130 cvs 1975: }
1976: else
1977: {
1.185 cvs 1978: HTCacheMode_setEnabled (FALSE);
1.130 cvs 1979: #ifdef DEBUG_LIBWWW
1980: fprintf (stderr, "lock detected, starting libwww without a cache/n");
1981: #endif /* DEBUG_LIBWWW */
1982: }
1983: TtaFreeMemory (cache_lockfile);
1.116 cvs 1984: }
1985: else
1.185 cvs 1986: {
1987: HTCacheMode_setEnabled (FALSE);
1988: }
1.116 cvs 1989: if (cache_dir)
1.211 cvs 1990: HT_FREE (cache_dir);
1.189 cvs 1991: if (real_dir)
1992: TtaFreeMemory (real_dir);
1.185 cvs 1993: /* warn the user if the cache isn't active */
1994: if (cache_enabled && !HTCacheMode_enabled ())
1.214 cvs 1995: InitInfo (TEXT("Cache"), TtaGetMessage (AMAYA, AM_CANT_CREATE_CACHE));
1.116 cvs 1996: #endif /* AMAYA_WWW_CACHE */
1.15 cvs 1997: }
1998:
1999: /*----------------------------------------------------------------------
1.97 cvs 2000: ProxyInit
2001: Reads any proxies settings which may be declared as environmental
2002: variables or in the thot.ini file. The former overrides the latter.
2003: ----------------------------------------------------------------------*/
1.118 cvs 2004: #ifdef __STDC__
1.97 cvs 2005: static void ProxyInit (void)
1.118 cvs 2006: #else
2007: static void ProxyInit ()
2008: #endif /* __STDC__ */
1.97 cvs 2009: {
1.198 cvs 2010: STRING strptr;
2011: STRING str = NULL;
2012: STRING name;
1.212 cvs 2013: ThotBool proxy_is_onlyproxy;
2014:
1.198 cvs 2015: char* strptrA;
1.97 cvs 2016:
2017: /* get the proxy settings from the thot.ini file */
1.203 cvs 2018: strptr = TtaGetEnvString ("HTTP_PROXY");
1.97 cvs 2019: if (strptr && *strptr)
1.216 cvs 2020: {
2021: /* does the proxy env string has an "http://" prefix? */
2022: if ( !ustrncasecmp( strptr, "http://", 7))
2023: HTProxy_add ("http", WideChar2ISO (strptr));
2024: else
2025: {
2026: strptrA = (char *) TtaGetMemory (ustrlen (strptr) + 9);
2027: strcpy (strptrA, "http://");
2028: strcat (strptrA, WideChar2ISO (strptr));
2029: HTProxy_add ("http", strptrA);
2030: TtaFreeMemory (strptrA);
2031: }
2032: }
2033:
1.97 cvs 2034: /* get the no_proxy settings from the thot.ini file */
1.212 cvs 2035: strptr = TtaGetEnvString ("PROXYDOMAIN");
1.97 cvs 2036: if (strptr && *strptr)
2037: {
2038: str = TtaStrdup (strptr); /* Get copy we can mutilate */
2039: strptr = str;
1.198 cvs 2040: strptrA = WideChar2ISO (strptr);
1.201 cvs 2041: while ((name = ISO2WideChar(HTNextField (&strptrA))) != NULL) {
1.198 cvs 2042: STRING portstr = ustrchr (name, TEXT(':'));
1.97 cvs 2043: unsigned port=0;
1.198 cvs 2044: if (portstr) {
2045: *portstr++ = EOS;
2046: if (*portstr) port = (unsigned) uctoi (portstr);
1.97 cvs 2047: }
2048: /* Register it for all access methods */
1.198 cvs 2049: HTNoProxy_add (WideChar2ISO (name), NULL, port);
1.97 cvs 2050: }
2051: TtaFreeMemory (str);
2052: }
1.212 cvs 2053:
2054: /* how should we interpret the proxy domain list? */
2055: TtaGetEnvBoolean ("PROXYDOMAIN_IS_ONLYPROXY", &proxy_is_onlyproxy);
2056: HTProxy_setNoProxyIsOnlyProxy (proxy_is_onlyproxy);
2057:
2058: /* use libwww's routine to get all proxy settings from the environment */
1.97 cvs 2059: HTProxy_getEnvVar ();
2060: }
2061:
1.207 cvs 2062: /*----------------------------------------------------------------------
2063: SafePut_init
2064: Sets up the domains which are authorized to make a redirect on
2065: a PUT.
2066: ----------------------------------------------------------------------*/
2067: #ifdef __STDC__
2068: static void SafePut_init (void)
2069: #else
2070: static void SafePut_init ()
2071: #endif /* __STDC__ */
2072: {
2073: STRING strptr;
2074: STRING str = NULL;
2075: char *strptrA, *ptr;
2076: char *domain;
2077:
2078: /* get the proxy settings from the thot.ini file */
2079: strptr = TtaGetEnvString ("SAFE_PUT_REDIRECT");
2080: if (strptr && *strptr)
2081: {
2082: /* Get copy we can mutilate */
2083: str = TtaStrdup (strptr);
2084: strptrA = WideChar2ISO (str);
2085: /* convert to lowercase */
2086: ptr = strptrA;
2087: while (*ptr)
2088: {
2089: *ptr = tolower (*ptr);
2090: ptr++;
2091: }
2092:
2093: /* create the list container */
2094: safeput_list = HTList_new ();
2095: /* store the domain list */
2096: while ((domain = HTNextField (&strptrA)) != NULL)
2097: HTList_addObject (safeput_list, TtaStrdup (domain));
2098:
2099: TtaFreeMemory (str);
2100: }
2101: }
2102:
2103: /*----------------------------------------------------------------------
2104: SafePut_delete
2105: Deletes the safeput_list variable
2106: ----------------------------------------------------------------------*/
2107: static void SafePut_delete (void)
2108: {
2109: HTList *cur = safeput_list;
2110: char *domain;
2111:
2112: if (!safeput_list)
2113: return;
2114:
2115: while ((domain = (char *) HTList_nextObject (cur)))
2116: TtaFreeMemory (domain);
2117: HTList_delete (safeput_list);
2118: safeput_list = NULL;
2119: }
2120:
2121: /*----------------------------------------------------------------------
2122: SafePut_query
2123: returns true if the domain to which belongs the URL accepts an automatic
2124: PUT redirect.
2125: ----------------------------------------------------------------------*/
2126: static ThotBool SafePut_query (char *url)
2127: {
2128: HTList *cur;
2129: char *me;
2130: ThotBool found;
2131:
2132: /* extract the domain path of the url and normalize it */
2133: /* domain = url; */
2134: cur = safeput_list;
2135: found = FALSE;
2136: while ((me = (char *) HTList_nextObject (cur)))
2137: {
2138: if (strstr (url, me))
2139: {
2140: found = TRUE;
2141: break;
2142: }
2143: }
2144:
2145: return (found);
2146: }
1.97 cvs 2147:
2148: /*----------------------------------------------------------------------
1.17 cvs 2149: AHTProfile_newAmaya
2150: creates the Amaya client profile for libwww.
1.15 cvs 2151: ----------------------------------------------------------------------*/
2152: #ifdef __STDC__
1.198 cvs 2153: static void AHTProfile_newAmaya (STRING AppName, STRING AppVersion)
1.15 cvs 2154: #else /* __STDC__ */
2155: static void AHTProfile_newAmaya (AppName, AppVersion)
1.198 cvs 2156: STRING AppName;
2157: STRING AppVersion;
1.15 cvs 2158: #endif /* __STDC__ */
1.4 cvs 2159: {
1.198 cvs 2160: STRING strptr;
1.158 cvs 2161:
1.4 cvs 2162: /* If the Library is not already initialized then do it */
2163: if (!HTLib_isInitialized ())
1.198 cvs 2164: HTLibInit (WideChar2ISO (AppName), WideChar2ISO (AppVersion));
1.4 cvs 2165:
2166: if (!converters)
2167: converters = HTList_new ();
1.27 cvs 2168: if (!acceptTypes)
2169: acceptTypes = HTList_new ();
1.193 cvs 2170: if (!acceptLanguages)
2171: acceptLanguages = HTList_new ();
1.151 cvs 2172: if (!transfer_encodings)
2173: transfer_encodings = HTList_new ();
2174: if (!content_encodings)
2175: content_encodings = HTList_new ();
1.4 cvs 2176:
1.169 cvs 2177: /* inhibits libwww's automatic file_suffix_binding */
2178: HTFile_doFileSuffixBinding (FALSE);
2179:
1.4 cvs 2180: /* Register the default set of transport protocols */
2181: HTTransportInit ();
2182:
2183: /* Register the default set of application protocol modules */
2184: AHTProtocolInit ();
2185:
1.116 cvs 2186: /* Register the default set of messages and dialog functions */
2187: AHTAlertInit ();
2188: HTAlert_setInteractive (YES);
2189:
2190: #ifdef AMAYA_WWW_CACHE
2191: /* Enable the persistent cache */
2192: CacheInit ();
2193: #else
2194: HTCacheMode_setEnabled (NO);
2195: #endif /* AMAYA_WWW_CACHE */
1.4 cvs 2196:
2197: /* Register the default set of BEFORE and AFTER filters */
2198: AHTNetInit ();
2199:
2200: /* Set up the default set of Authentication schemes */
1.167 cvs 2201: HTAA_newModule ("basic", HTBasic_generate, HTBasic_parse, NULL,
2202: HTBasic_delete);
1.158 cvs 2203: /* activate MDA by defaul */
1.203 cvs 2204: strptr = TtaGetEnvString ("ENABLE_MDA");
1.198 cvs 2205: if (!strptr || (strptr && *strptr && ustrcasecmp (strptr, TEXT("no"))))
1.158 cvs 2206: HTAA_newModule ("digest", HTDigest_generate, HTDigest_parse,
1.167 cvs 2207: HTDigest_updateInfo, HTDigest_delete);
1.4 cvs 2208:
1.97 cvs 2209: /* Get any proxy settings */
2210: ProxyInit ();
1.4 cvs 2211:
1.207 cvs 2212: /* Set up the domains where we accept a redirect on PUT */
2213: SafePut_init ();
2214:
1.4 cvs 2215: /* Register the default set of converters */
2216: AHTConverterInit (converters);
1.151 cvs 2217: HTFormat_setConversion (converters);
1.27 cvs 2218: AHTAcceptTypesInit (acceptTypes);
1.193 cvs 2219: AHTAcceptLanguagesInit (acceptLanguages);
1.4 cvs 2220:
2221: /* Register the default set of transfer encoders and decoders */
1.151 cvs 2222: HTTransferEncoderInit (transfer_encodings);
1.190 cvs 2223: HTFormat_setTransferCoding (transfer_encodings);
2224: /* Register the default set of content encoders and decoders */
2225: HTContentEncoderInit (content_encodings);
2226: /* ignore all other encoding formats (or libwww will send them
1.181 cvs 2227: thru a blackhole otherwise */
2228: HTCoding_add (content_encodings, "*", NULL, HTIdentityCoding, 1.0);
1.151 cvs 2229: if (HTList_count(content_encodings) > 0)
2230: HTFormat_setContentCoding(content_encodings);
2231: else
2232: {
2233: HTList_delete(content_encodings);
2234: content_encodings = NULL;
2235: }
1.4 cvs 2236:
2237: /* Register the default set of MIME header parsers */
1.74 cvs 2238: HTMIMEInit (); /* must be called again for language selector */
1.4 cvs 2239:
2240: /* Register the default set of Icons for directory listings */
1.27 cvs 2241: /*HTIconInit(NULL); *//* experimental */
1.4 cvs 2242: }
2243:
1.5 cvs 2244: /*----------------------------------------------------------------------
1.17 cvs 2245: AHTProfile_delete
2246: deletes the Amaya client profile.
1.5 cvs 2247: ----------------------------------------------------------------------*/
1.4 cvs 2248: #ifdef __STDC__
2249: static void AHTProfile_delete (void)
2250: #else
2251: static void AHTProfile_delete ()
1.7 cvs 2252: #endif /* __STDC__ */
1.4 cvs 2253: {
1.22 cvs 2254:
2255: /* free the Amaya global context */
1.151 cvs 2256:
2257: /* Clean up all the registred converters */
2258: HTFormat_deleteAll ();
2259: if (acceptTypes)
1.74 cvs 2260: HTConversion_deleteAll (acceptTypes);
1.193 cvs 2261: if (acceptLanguages)
2262: HTLanguage_deleteAll (acceptLanguages);
1.151 cvs 2263:
1.209 cvs 2264: StopAllRequests (1);
1.74 cvs 2265: HTList_delete (Amaya->docid_status);
2266: HTList_delete (Amaya->reqlist);
2267: TtaFreeMemory (Amaya);
1.61 cvs 2268:
1.120 cvs 2269: #ifdef _WINDOWS
1.209 cvs 2270: if (HTLib_isInitialized ())
1.151 cvs 2271: HTEventTerminate ();
1.198 cvs 2272: #endif /* _WINDOWS; */
1.74 cvs 2273:
1.151 cvs 2274: /* Clean up the persistent cache (if any) */
1.116 cvs 2275: #ifdef AMAYA_WWW_CACHE
1.151 cvs 2276: clear_cachelock ();
2277: HTCacheTerminate ();
1.116 cvs 2278: #endif /* AMAYA_WWW_CACHE */
1.217 cvs 2279:
1.218 cvs 2280: /* call remove functions that are not called automatically by libwww */
2281: HTNetCall_deleteBeforeAll (HTNet_before ());
2282: HTNetCall_deleteAfterAll (HTNet_after ());
2283: HTAA_deleteAllModules ();
2284: HTAlertCall_deleteAll (HTAlert_global () );
2285: HTAlert_setGlobal ((HTList *) NULL);
2286: /* these two functions are broken, so we can't call them right now
2287: HTHeader_deleteAll ();
2288: HTTimer_deleteAll ();
2289: */
2290: HTTransport_deleteAll ();
1.217 cvs 2291: /* remove bindings between suffixes, media types*/
2292: HTBind_deleteAll ();
1.151 cvs 2293: /* Terminate libwww */
2294: HTLibTerminate ();
1.4 cvs 2295: }
2296:
1.5 cvs 2297: /*----------------------------------------------------------------------
1.116 cvs 2298: AmayacontextInit
2299: initializes an internal Amaya context for our libwww interface
2300: ----------------------------------------------------------------------*/
2301: #ifdef __STDC__
2302: static void AmayaContextInit ()
2303: #else
2304: static void AmayaContextInit ()
2305: #endif
2306:
2307: {
1.140 cvs 2308: AmayaAlive_flag = TRUE;
1.116 cvs 2309: /* Initialization of the global context */
2310: Amaya = (AmayaContext *) TtaGetMemory (sizeof (AmayaContext));
2311: Amaya->reqlist = HTList_new ();
2312: Amaya->docid_status = HTList_new ();
2313: Amaya->open_requests = 0;
2314: }
2315:
2316: /*----------------------------------------------------------------------
1.17 cvs 2317: QueryInit
2318: initializes the libwww interface
1.5 cvs 2319: ----------------------------------------------------------------------*/
1.4 cvs 2320: #ifdef __STDC__
2321: void QueryInit ()
2322: #else
2323: void QueryInit ()
2324: #endif
2325: {
1.198 cvs 2326: STRING strptr;
1.151 cvs 2327: int tmp_i;
2328: long tmp_l;
1.4 cvs 2329:
1.116 cvs 2330: AmayaContextInit ();
1.4 cvs 2331: AHTProfile_newAmaya (HTAppName, HTAppVersion);
1.140 cvs 2332: CanDoStop_set (TRUE);
1.214 cvs 2333: UserAborted_flag = FALSE;
1.4 cvs 2334:
1.116 cvs 2335: #ifdef _WINDOWS
1.125 cvs 2336: HTEventInit ();
1.116 cvs 2337: #endif /* _WINDOWS */
1.72 cvs 2338:
1.123 cvs 2339: #ifndef _WINDOWS
1.116 cvs 2340: HTEvent_setRegisterCallback ((void *) AHTEvent_register);
2341: HTEvent_setUnregisterCallback ((void *) AHTEvent_unregister);
1.202 cvs 2342: #ifndef _GTK
1.120 cvs 2343: HTTimer_registerSetTimerCallback ((void *) AMAYA_SetTimer);
2344: HTTimer_registerDeleteTimerCallback ((void *) AMAYA_DeleteTimer);
1.202 cvs 2345: #endif /* _GTK */
1.116 cvs 2346: #endif /* !_WINDOWS */
1.190 cvs 2347:
1.213 cvs 2348: #ifdef HTDEBUG
2349: /* an undocumented option for being able to generate an HTTP protocol trace */
1.208 cvs 2350: strptr = TtaGetEnvString ("ENABLE_LIBWWW_DEBUG");
2351: if (strptr && *strptr)
2352: WWW_TraceFlag = SHOW_PROTOCOL_TRACE;
2353: else
2354: WWW_TraceFlag = 0;
1.213 cvs 2355: #endif /* HTDEBUG */
1.208 cvs 2356:
1.74 cvs 2357: #ifdef DEBUG_LIBWWW
1.116 cvs 2358: /* forwards error messages to our own function */
2359: WWW_TraceFlag = THD_TRACE;
1.138 cvs 2360: HTTrace_setCallback(LineTrace);
1.4 cvs 2361: /* Trace activation (for debugging) */
1.148 cvs 2362: /***
1.138 cvs 2363: WWW_TraceFlag = SHOW_CORE_TRACE | SHOW_THREAD_TRACE | SHOW_PROTOCOL_TRACE;
2364: WWW_TraceFlag |= 0xFFFFFFFFl;
2365: ***/
1.152 cvs 2366: #endif
2367:
1.148 cvs 2368: /* Setting up different network parameters */
1.151 cvs 2369:
1.148 cvs 2370: /* Maximum number of simultaneous open sockets */
1.203 cvs 2371: strptr = TtaGetEnvString ("MAX_SOCKET");
1.151 cvs 2372: if (strptr && *strptr)
1.198 cvs 2373: tmp_i = uctoi (strptr);
1.151 cvs 2374: else
2375: tmp_i = DEFAULT_MAX_SOCKET;
2376: HTNet_setMaxSocket (tmp_i);
2377:
1.148 cvs 2378: /* different network services timeouts */
1.151 cvs 2379: /* dns timeout */
1.203 cvs 2380: strptr = TtaGetEnvString ("DNS_TIMEOUT");
1.151 cvs 2381: if (strptr && *strptr)
1.198 cvs 2382: tmp_i = uctoi (strptr);
1.151 cvs 2383: else
2384: tmp_i = DEFAULT_DNS_TIMEOUT;
2385: HTDNS_setTimeout (tmp_i);
2386:
2387: /* persistent connections timeout */
1.203 cvs 2388: strptr = TtaGetEnvString ("PERSIST_CX_TIMEOUT");
1.151 cvs 2389: if (strptr && *strptr)
1.198 cvs 2390: tmp_l = uctol (strptr);
1.151 cvs 2391: else
2392: tmp_l = DEFAULT_PERSIST_TIMEOUT;
2393: HTHost_setPersistTimeout (tmp_l);
2394:
1.148 cvs 2395: /* default timeout in ms */
1.203 cvs 2396: strptr = TtaGetEnvString ("NET_EVENT_TIMEOUT");
1.151 cvs 2397: if (strptr && *strptr)
1.198 cvs 2398: tmp_i = uctoi (strptr);
1.151 cvs 2399: else
2400: tmp_i = DEFAULT_NET_EVENT_TIMEOUT;
2401: HTHost_setEventTimeout (tmp_i);
2402:
1.173 cvs 2403: HTRequest_setMaxRetry (8);
1.4 cvs 2404: #ifdef CATCH_SIG
1.148 cvs 2405: signal (SIGPIPE, SIG_IGN);
1.4 cvs 2406: #endif
1.15 cvs 2407: }
2408:
2409: /*----------------------------------------------------------------------
1.17 cvs 2410: LoopForStop
1.136 cvs 2411: a copy of the Thop event loop so we can handle the stop button in Unix
2412: and preemptive requests under Windows
1.15 cvs 2413: ----------------------------------------------------------------------*/
2414: #ifdef __STDC__
2415: static int LoopForStop (AHTReqContext * me)
2416: #else
2417: static int LoopForStop (AHTReqContext * me)
2418: #endif
2419: {
1.136 cvs 2420: #ifdef _WINDOWS
2421: MSG msg;
2422: unsigned long libwww_msg;
2423: HWND old_active_window, libwww_window;
2424: int status_req = HT_OK;
2425:
2426: old_active_window = GetActiveWindow ();
2427: libwww_window = HTEventList_getWinHandle (&libwww_msg);
1.137 cvs 2428:
1.149 cvs 2429: while (me->reqStatus != HT_END && me->reqStatus != HT_ERR
2430: && me->reqStatus != HT_ABORT && AmayaIsAlive () &&
2431: GetMessage (&msg, NULL, 0, 0))
2432: {
2433: if (msg.message != WM_QUIT)
2434: {
2435: TranslateMessage (&msg);
2436: DispatchMessage (&msg);
2437: }
2438: else
2439: break;
2440: }
1.136 cvs 2441: if (!AmayaIsAlive ())
2442: /* Amaya was killed by one of the callback handlers */
2443: exit (0);
2444: #else /* _WINDOWS */
1.25 cvs 2445: extern ThotAppContext app_cont;
1.51 cvs 2446: XEvent ev;
2447: XtInputMask status;
1.17 cvs 2448: int status_req = HT_OK;
1.15 cvs 2449:
2450: /* to test the async calls */
1.17 cvs 2451: /* Loop while waiting for new events, exists when the request is over */
1.15 cvs 2452: while (me->reqStatus != HT_ABORT &&
2453: me->reqStatus != HT_END &&
1.69 cvs 2454: me->reqStatus != HT_ERR) {
1.116 cvs 2455: if (!AmayaIsAlive ())
1.69 cvs 2456: /* Amaya was killed by one of the callback handlers */
2457: exit (0);
2458:
2459: status = XtAppPending (app_cont);
1.144 cvs 2460: if (status & XtIMXEvent)
2461: {
2462: XtAppNextEvent (app_cont, &ev);
2463: TtaHandleOneEvent (&ev);
2464: }
2465: else if (status != 0)
2466: XtAppProcessEvent (app_cont, XtIMAll);
1.69 cvs 2467: }
1.136 cvs 2468: #endif /* _WINDOWS */
1.69 cvs 2469: switch (me->reqStatus) {
2470: case HT_ERR:
2471: case HT_ABORT:
1.130 cvs 2472: status_req = NO;
1.15 cvs 2473: break;
2474:
1.69 cvs 2475: case HT_END:
1.130 cvs 2476: status_req = YES;
1.15 cvs 2477: break;
2478:
1.69 cvs 2479: default:
1.15 cvs 2480: break;
1.69 cvs 2481: }
1.15 cvs 2482: return (status_req);
1.4 cvs 2483: }
2484:
1.5 cvs 2485: /*----------------------------------------------------------------------
1.15 cvs 2486: QueryClose
1.21 cvs 2487: closes all existing threads, frees all non-automatically deallocated
2488: memory and then ends libwww.
1.5 cvs 2489: ----------------------------------------------------------------------*/
1.116 cvs 2490: void QueryClose ()
1.4 cvs 2491: {
1.24 cvs 2492:
1.140 cvs 2493: AmayaAlive_flag = FALSE;
1.24 cvs 2494:
1.116 cvs 2495: /* remove all the handlers and callbacks that may output a message to
2496: a non-existent Amaya window */
2497: HTEvent_setRegisterCallback ((HTEvent_registerCallback *) NULL);
2498: HTEvent_setUnregisterCallback ((HTEvent_unregisterCallback *) NULL);
2499: #ifndef _WINDOWS
2500: /** need to erase all existing timers too **/
2501: HTTimer_registerSetTimerCallback (NULL);
2502: HTTimer_registerDeleteTimerCallback (NULL);
2503: #endif /* !_WINDOWS */
2504: HTHost_setActivateRequestCallback (NULL);
2505: Thread_deleteAll ();
1.21 cvs 2506:
1.116 cvs 2507: HTProxy_deleteAll ();
2508: HTNoProxy_deleteAll ();
1.207 cvs 2509: SafePut_delete ();
1.116 cvs 2510: HTGateway_deleteAll ();
2511: AHTProfile_delete ();
2512: }
2513:
2514: /*----------------------------------------------------------------------
2515: NextNameValue
2516: ---------------------------------------------------------------------*/
2517: #ifdef __STDC__
2518: static char * NextNameValue (char ** pstr, char **name, char **value)
2519: #else
2520: static char * NextNameValue (pstr, name, value);
2521: char ** pstr;
2522: char **name;
2523: char **value;
2524: #endif /* __STDC__ */
2525: {
2526: char * p = *pstr;
2527: char * start = NULL;
2528: if (!pstr || !*pstr) return NULL;
2529:
2530: if (!*p) {
2531: *pstr = p;
2532: *name = NULL;
2533: *value = NULL;
2534: return NULL; /* No field */
2535: }
2536:
2537: /* Now search for the next '&' and ';' delimitators */
2538: start = p;
2539: while (*p && *p != '&' && *p != ';') p++;
2540: if (*p)
2541: *p++ = '\0';
2542: *pstr = p;
2543:
2544: /* Search for the name and value */
2545: *name = start;
2546: p = start;
2547:
2548: while(*p && *p != '=')
2549: p++;
2550: if (*p)
2551: *p++ = '\0';
2552: *value = p;
2553:
2554: return start;
2555: }
2556:
2557: /*----------------------------------------------------------------------
2558: PrepareFormdata
2559: ---------------------------------------------------------------------*/
2560: #ifdef __STDC__
1.198 cvs 2561: static HTAssocList * PrepareFormdata (STRING string)
1.116 cvs 2562: #else
2563: static HTAssocList * PrepareFormdata (string)
1.198 cvs 2564: STRING string;
1.116 cvs 2565: #endif /* __STDC__ */
2566: {
1.198 cvs 2567: char* tmp_string, *tmp_string_ptr;
2568: char* name;
2569: char* value;
2570: HTAssocList* formdata;
1.116 cvs 2571:
2572: if (!string)
2573: return NULL;
2574:
2575: /* store the ptr in another variable, as the original address will
2576: change
2577: */
2578:
1.198 cvs 2579: tmp_string_ptr = tmp_string = WideChar2ISO (TtaStrdup (string));
1.116 cvs 2580: formdata = HTAssocList_new();
2581:
2582: while (*tmp_string)
2583: {
2584: NextNameValue (&tmp_string, &name, &value);
2585: HTAssocList_addObject(formdata,
2586: name, value);
2587: }
2588:
2589: TtaFreeMemory (tmp_string_ptr);
2590: return formdata;
1.4 cvs 2591: }
2592:
1.216 cvs 2593: #ifdef __STDC__
2594: void AHTRequest_setCustomAcceptHeader (HTRequest *request, char *value)
2595: #else
2596: void AHTRequest_setCustomAcceptHeader (request, value)
2597: HTRequest *request;
2598: char *value;
2599: #endif /* __STDC__ */
2600: {
2601: HTRqHd rqhd = HTRequest_rqHd (request);
2602: rqhd = rqhd & (~HT_C_ACCEPT_TYPE);
2603: HTRequest_setRqHd (request, rqhd);
1.221 cvs 2604: HTRequest_addExtraHeader (request, "Accept", value);
1.216 cvs 2605: }
2606:
2607:
1.99 cvs 2608:
2609: /*----------------------------------------------------------------------
2610: InvokeGetObjectWWW_callback
2611: A simple function to invoke a callback function whenever there's an error
2612: in GetObjectWWW
2613: ---------------------------------------------------------------------*/
2614:
1.116 cvs 2615: #ifdef __STDC__
1.198 cvs 2616: void InvokeGetObjectWWW_callback (int docid, STRING urlName, STRING outputfile, TTcbf *terminate_cbf, void *context_tcbf, int status)
1.99 cvs 2617: #else
1.111 cvs 2618: void InvokeGetObjectWWW_callback (docid, urlName, outputfile, terminate_cbf, context_tcbf, status)
1.99 cvs 2619: int docid;
1.198 cvs 2620: STRING urlName;
2621: STRING outputfile;
1.99 cvs 2622: TTcbf *terminate_cbf;
2623: void *context_tcbf;
1.116 cvs 2624: #endif /* __STDC__ */
1.99 cvs 2625: {
2626: if (!terminate_cbf)
2627: return;
2628:
1.116 cvs 2629: (*terminate_cbf) (docid, status, urlName, outputfile,
1.99 cvs 2630: NULL, context_tcbf);
2631: }
2632:
2633:
2634:
1.5 cvs 2635: /*----------------------------------------------------------------------
1.15 cvs 2636: GetObjectWWW
1.17 cvs 2637: this function requests a resource designated by a URLname into a
2638: temporary filename. The download can come from a simple GET operation,
2639: or can come from POSTING/GETTING a form. In the latter
2640: case, the function receives a query string to send to the server.
2641:
1.5 cvs 2642: 4 file retrieval modes are proposed:
2643: AMAYA_SYNC : blocking mode
2644: AMAYA_ISYNC : incremental, blocking mode
2645: AMAYA_ASYNC : non-blocking mode
2646: AMAYA_IASYNC : incremental, non-blocking mode
2647:
2648: In the incremental mode, each time a package arrives, it will be
2649: stored in the temporary file. In addition, if an
2650: incremental_callback function is defined, this function will be
2651: called and handled a copy of the newly received data package.
2652: Finally, if a terminate_callback function is defined, it will be
2653: invoked when the request terminates. The caller of this function
1.4 cvs 2654: can define two different contexts to be passed to the callback
2655: functions.
2656:
2657: When the function is called with the SYNC mode, the function will
2658: return only when the requested file has been loaded.
2659: The ASYNC mode will immediately return after setting up the
2660: call.
2661:
2662: Notes:
2663: At the end of a succesful request, the urlName string contains the
2664: name of the actually retrieved URL. As a URL can change over the time,
2665: (e.g., be redirected elsewhere), it is advised that the function
1.17 cvs 2666: caller verify the value of the urlName variable at the end of
1.4 cvs 2667: a request.
2668:
2669: Inputs:
2670: - docid Document identifier for the set of objects being
2671: retrieved.
2672: - urlName The URL to be retrieved (MAX_URL_LENGTH chars length)
2673: - outputfile A pointer to an empty string of MAX_URL_LENGTH.
2674: - mode The retrieval mode.
2675: - incremental_cbf
2676: - context_icbf
2677: Callback and context for the incremental modes
2678: - terminate_cbf
2679: - context_icbf
2680: Callback and context for a terminate handler
1.17 cvs 2681: -error_html if TRUE, then display any server error message as an
2682: HTML document.
1.88 cvs 2683: - content_type a string
2684:
1.4 cvs 2685: Outputs:
2686: - urlName The URL that was retrieved
2687: - outputfile The name of the temporary file which holds the
2688: retrieved data. (Only in case of success)
1.88 cvs 2689: - if content_type wasn't NULL, it will contain a copy of the parameter
2690: sent in the HTTP answer
1.4 cvs 2691: Returns:
2692: HT_ERROR
2693: HT_OK
1.5 cvs 2694:
2695: ----------------------------------------------------------------------*/
1.4 cvs 2696: #ifdef __STDC__
1.198 cvs 2697: int GetObjectWWW (int docid, STRING urlName, STRING formdata,
2698: STRING outputfile, int mode, TIcbf* incremental_cbf,
1.116 cvs 2699: void* context_icbf, TTcbf* terminate_cbf,
1.198 cvs 2700: void* context_tcbf, ThotBool error_html, STRING content_type)
1.4 cvs 2701: #else
1.127 cvs 2702: int GetObjectWWW (docid, urlName, formdata, outputfile, mode,
1.116 cvs 2703: incremental_cbf, context_icbf,
1.88 cvs 2704: terminate_cbf, context_tcbf, error_html, content_type)
1.73 cvs 2705: int docid;
1.198 cvs 2706: STRING urlName;
2707: STRING formdata;
2708: STRING outputfile;
1.73 cvs 2709: int mode;
2710: TIcbf *incremental_cbf;
2711: void *context_icbf;
2712: TTcbf *terminate_cbf;
2713: void *context_tcbf;
1.191 cvs 2714: ThotBool error_html;
1.198 cvs 2715: STRING content_type;
1.4 cvs 2716: #endif
2717: {
2718: AHTReqContext *me;
1.198 cvs 2719: STRING ref;
1.206 cvs 2720: STRING esc_url;
1.107 cvs 2721: int status, l;
1.114 cvs 2722: int tempsubdir;
1.191 cvs 2723: ThotBool bool_tmp;
1.7 cvs 2724:
1.116 cvs 2725: if (urlName == NULL || docid == 0 || outputfile == NULL)
2726: {
2727: /* no file to be loaded */
2728: TtaSetStatus (docid, 1, TtaGetMessage (AMAYA, AM_BAD_URL), urlName);
1.69 cvs 2729:
1.116 cvs 2730: if (error_html)
1.69 cvs 2731: /* so we can show the error message */
2732: DocNetworkStatus[docid] |= AMAYA_NET_ERROR;
1.116 cvs 2733: InvokeGetObjectWWW_callback (docid, urlName, outputfile, terminate_cbf,
2734: context_tcbf, HT_ERROR);
2735: return HT_ERROR;
2736: }
1.7 cvs 2737:
1.159 cvs 2738: /* if it's a 'docImage', we have already downloaded it */
1.198 cvs 2739: if (!ustrncmp (TEXT("internal:"), urlName, 9))
1.159 cvs 2740: {
1.198 cvs 2741: ustrcpy (outputfile, urlName);
1.159 cvs 2742: InvokeGetObjectWWW_callback (docid, urlName, outputfile,
2743: terminate_cbf, context_tcbf, HT_OK);
2744: return HT_OK;
2745: }
2746:
1.4 cvs 2747: /* do we support this protocol? */
1.116 cvs 2748: if (IsValidProtocol (urlName) == NO)
2749: {
2750: /* return error */
2751: outputfile[0] = EOS; /* file could not be opened */
2752: TtaSetStatus (docid, 1,
2753: TtaGetMessage (AMAYA, AM_GET_UNSUPPORTED_PROTOCOL),
2754: urlName);
2755:
2756: if (error_html)
1.69 cvs 2757: /* so we can show the error message */
2758: DocNetworkStatus[docid] |= AMAYA_NET_ERROR;
1.116 cvs 2759: InvokeGetObjectWWW_callback (docid, urlName, outputfile, terminate_cbf,
2760: context_tcbf, HT_ERROR);
2761: return HT_ERROR;
2762: }
1.4 cvs 2763:
1.114 cvs 2764: /* we store CSS in subdir named 0; all the other files go to a subidr
2765: named after their own docid */
2766:
2767: tempsubdir = (mode & AMAYA_LOAD_CSS) ? 0 : docid;
2768:
1.116 cvs 2769: /* create a tempfilename */
1.198 cvs 2770: usprintf (outputfile, TEXT("%s%c%d%c%04dAM"), TempFileDirectory, DIR_SEP, tempsubdir, DIR_SEP, object_counter);
1.116 cvs 2771: /* update the object_counter (used for the tempfilename) */
1.4 cvs 2772: object_counter++;
1.116 cvs 2773:
1.4 cvs 2774: /* normalize the URL */
1.206 cvs 2775: esc_url = EscapeURL (urlName);
2776: if (esc_url)
2777: {
2778: ref = AmayaParseUrl (esc_url, _EMPTYSTR_, AMAYA_PARSE_ALL);
2779: TtaFreeMemory (esc_url);
2780: }
2781: else
2782: ref = NULL;
2783:
1.4 cvs 2784: /* should we abort the request if we could not normalize the url? */
1.198 cvs 2785: if (ref == NULL || ref[0] == EOS) {
1.69 cvs 2786: /*error */
2787: outputfile[0] = EOS;
2788: TtaSetStatus (docid, 1, TtaGetMessage (AMAYA, AM_BAD_URL), urlName);
1.214 cvs 2789: if (ref)
2790: TtaFreeMemory (ref);
1.69 cvs 2791: if (error_html)
1.116 cvs 2792: /* so we can show the error message */
2793: DocNetworkStatus[docid] |= AMAYA_NET_ERROR;
1.99 cvs 2794: InvokeGetObjectWWW_callback (docid, urlName, outputfile, terminate_cbf,
1.116 cvs 2795: context_tcbf, HT_ERROR);
1.69 cvs 2796: return HT_ERROR;
2797: }
1.116 cvs 2798:
1.4 cvs 2799: /* verify if that file name existed */
1.9 cvs 2800: if (TtaFileExist (outputfile))
1.77 cvs 2801: TtaFileUnlink (outputfile);
1.116 cvs 2802:
1.4 cvs 2803: /* Initialize the request structure */
2804: me = AHTReqContext_new (docid);
1.116 cvs 2805: if (me == NULL)
2806: {
2807: outputfile[0] = EOS;
2808: /* need an error message here */
2809: TtaFreeMemory (ref);
2810: InvokeGetObjectWWW_callback (docid, urlName, outputfile, terminate_cbf,
2811: context_tcbf, HT_ERROR);
2812: return HT_ERROR;
2813: }
2814:
1.4 cvs 2815: /* Specific initializations for POST and GET */
1.222 ! cvs 2816: if (mode & AMAYA_FORM_POST
! 2817: #ifdef ANNOTATIONS
! 2818: || mode & AMAYA_ANNOT_POST
! 2819: #endif /* ANNOTATIONS */
! 2820: )
1.116 cvs 2821: {
2822: me->method = METHOD_POST;
2823: HTRequest_setMethod (me->request, METHOD_POST);
2824: }
2825: else
2826: {
2827: me->method = METHOD_GET;
2828: if (!HasKnownFileSuffix (ref))
1.216 cvs 2829: {
2830: /* try to adjust the Accept header in an netwise economical way */
2831: if (mode & AMAYA_LOAD_IMAGE)
2832: AHTRequest_setCustomAcceptHeader (me->request, IMAGE_ACCEPT_NEGOTIATION);
2833: else if (mode & AMAYA_LOAD_CSS)
2834: AHTRequest_setCustomAcceptHeader (me->request, "*/*;q=0.1,css/*");
2835: /*
2836: HTRequest_setConversion(me->request, acceptTypes, TRUE);
2837: */
2838: }
2839: HTRequest_setLanguage (me->request, acceptLanguages, TRUE);
1.116 cvs 2840: }
1.93 cvs 2841:
1.116 cvs 2842: /* Common initialization for all HTML methods */
1.4 cvs 2843: me->mode = mode;
2844: me->error_html = error_html;
2845: me->incremental_cbf = incremental_cbf;
2846: me->context_icbf = context_icbf;
2847: me->terminate_cbf = terminate_cbf;
2848: me->context_tcbf = context_tcbf;
1.64 cvs 2849:
1.69 cvs 2850: /* for the async. request modes, we need to have our
1.4 cvs 2851: own copy of outputfile and urlname
1.116 cvs 2852: */
1.4 cvs 2853:
1.116 cvs 2854: if ((mode & AMAYA_ASYNC) || (mode & AMAYA_IASYNC))
2855: {
1.198 cvs 2856: l = ustrlen (outputfile);
1.116 cvs 2857: if (l > MAX_LENGTH)
2858: me->outputfile = TtaGetMemory (l + 2);
2859: else
2860: me->outputfile = TtaGetMemory (MAX_LENGTH + 2);
1.198 cvs 2861: strcpy (me->outputfile, WideChar2ISO (outputfile));
2862: l = ustrlen (urlName);
1.116 cvs 2863: if (l > MAX_LENGTH)
2864: me->urlName = TtaGetMemory (l + 2);
2865: else
2866: me->urlName = TtaGetMemory (MAX_LENGTH + 2);
1.198 cvs 2867: strcpy (me->urlName, WideChar2ISO (urlName));
1.116 cvs 2868: #ifdef _WINDOWS
2869: /* force windows ASYNC requests to always be non preemptive */
2870: HTRequest_setPreemptive (me->request, NO);
2871: #endif /*_WINDOWS */
2872: } /* AMAYA_ASYNC mode */
2873: else
2874: #ifdef _WINDOWS
2875: {
1.198 cvs 2876: me->outputfile = WideChar2ISO (outputfile);
2877: me->urlName = WideChar2ISO (urlName);
1.116 cvs 2878: /* force windows SYNC requests to always be non preemptive */
2879: HTRequest_setPreemptive (me->request, YES);
2880: }
2881: #else /* !_WINDOWS */
2882: {
2883: me->outputfile = outputfile;
2884: me->urlName = urlName;
2885: }
2886: /***
1.136 cvs 2887: In order to take into account the stop button,
2888: the requests will be always asynchronous, however, if mode=AMAYA_SYNC,
1.57 cvs 2889: we will loop until the document has been received or a stop signal
2890: generated
1.77 cvs 2891: ****/
1.116 cvs 2892: HTRequest_setPreemptive (me->request, NO);
2893: #endif /* _WINDOWS */
1.61 cvs 2894:
1.151 cvs 2895: /*
2896: ** Make sure that the first request is flushed immediately and not
2897: ** buffered in the output buffer
2898: */
2899: if (mode & AMAYA_FLUSH_REQUEST)
2900: HTRequest_setFlush(me->request, YES);
2901: HTRequest_setFlush(me->request, YES);
2902:
1.61 cvs 2903: /* prepare the URLname that will be displayed in teh status bar */
2904: ChopURL (me->status_urlName, me->urlName);
1.77 cvs 2905: TtaSetStatus (me->docid, 1,
2906: TtaGetMessage (AMAYA, AM_FETCHING),
1.198 cvs 2907: ISO2WideChar (me->status_urlName));
1.4 cvs 2908:
1.198 cvs 2909: me->anchor = (HTParentAnchor *) HTAnchor_findAddress (WideChar2ISO (ref));
1.45 cvs 2910: TtaFreeMemory (ref);
1.177 cvs 2911:
1.198 cvs 2912: TtaGetEnvBoolean (TEXT("CACHE_DISCONNECTED_MODE"), &bool_tmp);
1.177 cvs 2913: if (!bool_tmp && (mode & AMAYA_NOCACHE))
1.116 cvs 2914: HTRequest_setReloadMode (me->request, HT_CACHE_FLUSH);
2915:
2916: /* prepare the query string and format for POST */
2917: if (mode & AMAYA_FORM_POST)
1.114 cvs 2918: {
1.116 cvs 2919: HTAnchor_setFormat ((HTParentAnchor *) me->anchor,
2920: HTAtom_for ("application/x-www-form-urlencoded"));
2921: HTAnchor_setLength ((HTParentAnchor *) me->anchor, me->block_size);
2922: HTRequest_setEntityAnchor (me->request, me->anchor);
2923: }
1.114 cvs 2924:
1.127 cvs 2925: /* create the formdata element for libwww */
2926: if (formdata)
2927: me->formdata = PrepareFormdata (formdata);
2928:
1.116 cvs 2929: /* do the request */
2930: if (mode & AMAYA_FORM_POST)
1.119 cvs 2931: {
1.191 cvs 2932: /* this call doesn't give back a ThotBool */
1.119 cvs 2933: HTParentAnchor * posted = NULL;
2934:
2935: posted = HTPostFormAnchor (me->formdata, (HTAnchor *) me->anchor,
2936: me->request);
2937: status = posted ? YES : NO;
2938: }
1.222 ! cvs 2939: #ifdef ANNOTATIONS
! 2940: if (mode & AMAYA_ANNOT_POST)
! 2941: {
! 2942: /* @@@ a very ugly patch :))) */
! 2943: HTParentAnchor * posted = NULL;
! 2944:
! 2945: me->source = HTAnchor_findAddress (DocumentURLs[docid]);
! 2946: HTAnchor_setFormat (HTAnchor_parent (me->source),
! 2947: HTAtom_for ("application/xml"));
! 2948: posted = HTPostAnchor (HTAnchor_parent (me->source),
! 2949: (HTAnchor *) me->anchor,
! 2950: me->request);
! 2951: status = posted ? YES : NO;
! 2952: }
! 2953: #endif /* ANNOTATIONS */
1.127 cvs 2954: else if (formdata)
2955: status = HTGetFormAnchor(me->formdata, (HTAnchor *) me->anchor,
2956: me->request);
1.116 cvs 2957: else
1.77 cvs 2958: status = HTLoadAnchor ((HTAnchor *) me->anchor, me->request);
1.69 cvs 2959:
1.123 cvs 2960: /* @@@ may need some special windows error msg here */
1.116 cvs 2961: /* control the errors */
1.4 cvs 2962:
1.130 cvs 2963: if (status == NO)
1.116 cvs 2964: /* the request invocation failed */
2965: {
2966: /* show an error message on the status bar */
2967: DocNetworkStatus[docid] |= AMAYA_NET_ERROR;
2968: TtaSetStatus (docid, 1,
2969: TtaGetMessage (AMAYA, AM_CANNOT_LOAD),
2970: urlName);
2971: if (me->reqStatus == HT_NEW)
2972: /* manually invoke the last processing that usually gets done
2973: in a succesful request */
2974: InvokeGetObjectWWW_callback (docid, urlName, outputfile,
2975: terminate_cbf, context_tcbf, HT_ERROR);
2976: /* terminate_handler wasn't called */
1.136 cvs 2977: AHTReqContext_delete (me);
1.116 cvs 2978: }
2979: else
1.136 cvs 2980: /* end treatment for SYNC requests */
1.120 cvs 2981: if ((mode & AMAYA_SYNC) || (mode & AMAYA_ISYNC))
2982: {
1.136 cvs 2983: /* wait here untilt the asynchronous request finishes */
1.130 cvs 2984: status = LoopForStop (me);
1.136 cvs 2985: /* if status returns HT_ERROR, should we invoke the callback? */
1.120 cvs 2986: if (!HTRequest_kill (me->request))
2987: AHTReqContext_delete (me);
2988: }
1.130 cvs 2989:
1.136 cvs 2990: /* an interface problem!!! */
2991: return (status == YES ? 0 : -1);
1.4 cvs 2992: }
2993:
1.5 cvs 2994: /*----------------------------------------------------------------------
1.17 cvs 2995: PutObjectWWW
2996: frontend for uploading a resource to a URL. This function downloads
2997: a file to be uploaded into memory, it then calls UploadMemWWW to
2998: finish the job.
2999:
1.5 cvs 3000: 2 upload modes are proposed:
3001: AMAYA_SYNC : blocking mode
3002: AMAYA_ASYNC : non-blocking mode
3003:
1.4 cvs 3004: When the function is called with the SYNC mode, the function will
3005: return only when the file has been uploaded.
3006: The ASYNC mode will immediately return after setting up the
3007: call. Furthermore, at the end of an upload, the ASYNC mode will
3008: call back terminate_cbf, handling it the context defined in
3009: context_tcbf.
3010:
3011: Notes:
3012: At the end of a succesful request, the urlName string contains the
3013: name of the actually uploaded URL. As a URL can change over the time,
3014: (e.g., be redirected elsewhere), it is advised that the function
3015: caller verifies the value of the urlName variable at the end of
3016: a request.
3017:
3018: Inputs:
3019: - docid Document identifier for the set of objects being
3020: retrieved.
3021: - fileName A pointer to the local file to upload
3022: - urlName The URL to be uploaded (MAX_URL_LENGTH chars length)
3023: - mode The retrieval mode.
3024: - terminate_cbf
3025: - context_icbf
3026: Callback and context for a terminate handler
3027:
3028: Outputs:
3029: - urlName The URL that was uploaded
3030:
3031: Returns:
3032: HT_ERROR
3033: HT_OK
1.5 cvs 3034: ----------------------------------------------------------------------*/
1.4 cvs 3035: #ifdef __STDC__
1.198 cvs 3036: int PutObjectWWW (int docid, STRING fileName, STRING urlName, int mode, PicType contentType,
1.4 cvs 3037: TTcbf * terminate_cbf, void *context_tcbf)
3038: #else
1.26 cvs 3039: int PutObjectWWW (docid, urlName, fileName, mode, contentType,
1.4 cvs 3040: ,terminate_cbf, context_tcbf)
3041: int docid;
1.198 cvs 3042: STRING urlName;
3043: STRING fileName;
1.4 cvs 3044: int mode;
1.27 cvs 3045: PicType contentType;
1.4 cvs 3046: TTcbf *terminate_cbf;
3047: void *context_tcbf;
3048:
1.116 cvs 3049: #endif /* __STDC__ */
1.4 cvs 3050: {
1.116 cvs 3051: AHTReqContext *me;
1.4 cvs 3052: int status;
3053: int fd;
3054: struct stat file_stat;
1.116 cvs 3055: char *fileURL;
1.168 cvs 3056: char *etag = NULL;
1.169 cvs 3057: HTParentAnchor *dest_anc_parent;
1.198 cvs 3058: STRING tmp;
1.206 cvs 3059: STRING esc_url;
1.168 cvs 3060: int UsePreconditions;
1.191 cvs 3061: ThotBool lost_update_check = TRUE;
1.172 cvs 3062:
3063: /* should we protect the PUT against lost updates? */
1.203 cvs 3064: tmp = TtaGetEnvString ("ENABLE_LOST_UPDATE_CHECK");
1.198 cvs 3065: if (tmp && *tmp && ustrcasecmp (tmp, TEXT("yes")))
1.172 cvs 3066: lost_update_check = FALSE;
1.168 cvs 3067:
3068: UsePreconditions = mode & AMAYA_USE_PRECONDITIONS;
1.4 cvs 3069:
1.33 cvs 3070: AmayaLastHTTPErrorMsg [0] = EOS;
3071:
1.116 cvs 3072: if (urlName == NULL || docid == 0 || fileName == NULL
3073: || !TtaFileExist (fileName))
1.4 cvs 3074: /* no file to be uploaded */
3075: return HT_ERROR;
3076:
3077: /* do we support this protocol? */
1.7 cvs 3078: if (IsValidProtocol (urlName) == NO)
3079: {
3080: /* return error */
1.198 cvs 3081: TtaSetStatus (docid, 1, TtaGetMessage (AMAYA, AM_PUT_UNSUPPORTED_PROTOCOL), urlName);
1.7 cvs 3082: return HT_ERROR;
3083: }
1.116 cvs 3084:
3085: /* verify the file's size */
3086: #ifndef _WINDOWS
1.7 cvs 3087: if ((fd = open (fileName, O_RDONLY)) == -1)
1.116 cvs 3088: #else
1.198 cvs 3089: if ((fd = uopen (fileName, _O_RDONLY | _O_BINARY)) == -1)
1.116 cvs 3090: #endif /* _WINDOWS */
1.7 cvs 3091: {
3092: /* if we could not open the file, exit */
3093: /*error msg here */
3094: return (HT_ERROR);
3095: }
1.4 cvs 3096:
3097: fstat (fd, &file_stat);
1.222 ! cvs 3098: #ifdef _WINDOWS
1.137 cvs 3099: _close (fd);
1.222 ! cvs 3100: #else /* _WINDOWS */
1.116 cvs 3101: close (fd);
1.222 ! cvs 3102: #endif /* _WINDOWS */
1.4 cvs 3103:
1.7 cvs 3104: if (file_stat.st_size == 0)
3105: {
3106: /* file was empty */
3107: /*errmsg here */
3108: return (HT_ERROR);
3109: }
1.116 cvs 3110:
3111: /* prepare the request context */
1.4 cvs 3112: if (THD_TRACE)
1.116 cvs 3113: fprintf (stderr, "file size == %u\n", (unsigned) file_stat.st_size);
1.4 cvs 3114:
3115: me = AHTReqContext_new (docid);
1.7 cvs 3116: if (me == NULL)
3117: {
1.168 cvs 3118: /* @@ need an error message here */
1.151 cvs 3119: TtaHandlePendingEvents ();
1.7 cvs 3120: return (HT_ERROR);
1.208 cvs 3121: }
3122:
3123: /*
3124: ** Set up the original URL name
3125: */
3126: if (DocumentMeta[docid]->put_default_name)
3127: {
3128: char *ptr1, *ptr2;
3129: ptr1 = TtaGetEnvString ("DEFAULTNAME");
3130: if (ptr1 && *ptr1)
3131: {
3132: ptr2 = strstr (urlName, ptr1);
3133: if (ptr2)
3134: {
3135: me->default_put_name = TtaStrdup (urlName);
3136: me->default_put_name[strlen (me->default_put_name)
3137: - strlen (ptr1)] = EOS;
3138: HTRequest_setDefaultPutName (me->request, me->default_put_name);
3139: }
3140: }
1.7 cvs 3141: }
1.116 cvs 3142:
1.4 cvs 3143: me->mode = mode;
3144: me->incremental_cbf = (TIcbf *) NULL;
3145: me->context_icbf = (void *) NULL;
3146: me->terminate_cbf = terminate_cbf;
3147: me->context_tcbf = context_tcbf;
1.206 cvs 3148: esc_url = EscapeURL (urlName);
3149: me->urlName = TtaStrdup (WideChar2ISO (esc_url));
3150: TtaFreeMemory (esc_url);
1.116 cvs 3151: me->block_size = file_stat.st_size;
1.17 cvs 3152: /* select the parameters that distinguish a PUT from a GET/POST */
1.4 cvs 3153: me->method = METHOD_PUT;
3154: me->output = stdout;
1.17 cvs 3155: /* we are not expecting to receive any input from the server */
3156: me->outputfile = (char *) NULL;
1.4 cvs 3157:
1.134 cvs 3158: #ifdef _WINDOWS
3159: /* libwww's HTParse function doesn't take into account the drive name;
1.168 cvs 3160: so we sidestep it */
1.134 cvs 3161: fileURL = NULL;
3162: StrAllocCopy (fileURL, "file:");
1.198 cvs 3163: StrAllocCat (fileURL, WideChar2ISO (fileName));
1.134 cvs 3164: #else
1.116 cvs 3165: fileURL = HTParse (fileName, "file:/", PARSE_ALL);
1.134 cvs 3166: #endif /* _WINDOWS */
1.168 cvs 3167: me->source = HTAnchor_findAddress (fileURL);
1.116 cvs 3168: HT_FREE (fileURL);
1.206 cvs 3169: me->dest = HTAnchor_findAddress (me->urlName);
1.169 cvs 3170: /* we memorize the anchor's parent @ as we use it a number of times
3171: in the following lines */
3172: dest_anc_parent = HTAnchor_parent (me->dest);
1.168 cvs 3173:
1.169 cvs 3174: /*
3175: ** Set the Content-Type of the file we are uploading
3176: */
3177: /* we try to use any content-type previosuly associated
3178: with the parent. If it doesn't exist, we try to guess it
3179: from the URL */
1.198 cvs 3180: tmp = ISO2WideChar (HTAtom_name (HTAnchor_format (dest_anc_parent)));
3181: if (!tmp || !ustrcmp (tmp, TEXT("www/unknown")))
1.169 cvs 3182: {
1.198 cvs 3183: HTAnchor_setFormat (dest_anc_parent, AHTGuessAtom_for (ISO2WideChar (me->urlName), contentType));
3184: tmp = ISO2WideChar (HTAtom_name (HTAnchor_format (dest_anc_parent)));
1.169 cvs 3185: }
3186: /* .. and we give the same type to the source anchor */
3187: /* we go thru setOutputFormat, rather than change the parent's
3188: anchor, as that's the place that libwww expects it to be */
1.170 cvs 3189: HTAnchor_setFormat (HTAnchor_parent (me->source),
1.198 cvs 3190: HTAtom_for (WideChar2ISO (tmp)));
1.219 cvs 3191:
1.169 cvs 3192: HTRequest_setOutputFormat (me->request,
1.198 cvs 3193: HTAtom_for (WideChar2ISO (tmp)));
1.219 cvs 3194:
3195: #if 0 /* JK: code ready, but we're not going to use it yet */
3196: /*
3197: ** Set the Charset of the file we are uploading
3198: */
3199: /* we try to use any charset previosuly associated
3200: with the parent. If it doesn't exist, we try to guess it
3201: from the metadata */
3202: tmp = ISO2WideChar (HTAtom_name (HTAnchor_charset (dest_anc_parent)));
3203: if (!tmp)
3204: {
3205: HTAnchor_setCharset (dest_anc_parent, HTAtom_for ("iso-8859-3"));
3206: tmp = ISO2WideChar (HTAtom_name (HTAnchor_charset (dest_anc_parent)));
3207: }
3208: /* .. and we give the same charset to the source anchor */
3209: /* we go thru setCharSet, rather than change the parent's
3210: anchor, as that's the place that libwww expects it to be */
3211: HTAnchor_setCharset (HTAnchor_parent (me->source),
3212: HTAtom_for (WideChar2ISO (tmp)));
3213: #endif /* CHARSET */
3214:
3215: /*
3216: ** define other request characteristics
3217: */
1.116 cvs 3218: #ifdef _WINDOWS
1.136 cvs 3219: HTRequest_setPreemptive (me->request, NO);
1.116 cvs 3220: #else
1.134 cvs 3221: HTRequest_setPreemptive (me->request, NO);
1.116 cvs 3222: #endif /* _WINDOWS */
3223:
1.151 cvs 3224: /*
3225: ** Make sure that the first request is flushed immediately and not
3226: ** buffered in the output buffer
3227: */
3228: if (mode & AMAYA_FLUSH_REQUEST)
3229: HTRequest_setFlush(me->request, YES);
1.168 cvs 3230:
3231: /* Should we use preconditions? */
1.172 cvs 3232: if (lost_update_check)
1.168 cvs 3233: {
1.172 cvs 3234: if (UsePreconditions)
3235: etag = HTAnchor_etag (HTAnchor_parent (me->dest));
3236:
3237: if (etag)
3238: {
3239: HTRequest_setPreconditions(me->request, HT_MATCH_THIS);
3240: }
3241: else
3242: {
3243: HTRequest_setPreconditions(me->request, HT_NO_MATCH);
3244: HTRequest_addAfter(me->request, check_handler, NULL, NULL, HT_ALL,
3245: HT_FILTER_MIDDLE, YES);
1.175 cvs 3246: HTRequest_addAfter (me->request, HTAuthFilter, "http://*", NULL,
3247: HT_NO_ACCESS, HT_FILTER_MIDDLE, YES);
3248: HTRequest_addAfter (me->request, HTAuthFilter, "http://*", NULL,
3249: HT_REAUTH, HT_FILTER_MIDDLE, YES);
3250: HTRequest_addAfter (me->request, HTAuthInfoFilter, "http://*", NULL,
3251: HT_ALL, HT_FILTER_MIDDLE, YES);
3252: HTRequest_addAfter (me->request, HTUseProxyFilter, "http://*", NULL,
3253: HT_USE_PROXY, HT_FILTER_MIDDLE, YES);
1.172 cvs 3254: }
1.168 cvs 3255: }
3256: else
3257: {
1.172 cvs 3258: /* don't use preconditions */
1.168 cvs 3259: HTRequest_setPreconditions(me->request, HT_NO_MATCH);
3260: }
1.151 cvs 3261:
1.136 cvs 3262: /* don't use the cache while saving a document */
3263: HTRequest_setReloadMode (me->request, HT_CACHE_FLUSH);
1.116 cvs 3264:
1.164 cvs 3265: /* Throw away any reponse body */
3266: /*
3267: HTRequest_setOutputStream (me->request, HTBlackHole());
3268: */
3269:
1.168 cvs 3270: /* prepare the URLname that will be displayed in the status bar */
1.74 cvs 3271: ChopURL (me->status_urlName, me->urlName);
1.198 cvs 3272: TtaSetStatus (me->docid, 1, TtaGetMessage (AMAYA, AM_REMOTE_SAVING), ISO2WideChar (me->status_urlName));
1.114 cvs 3273:
1.164 cvs 3274: /* make the request */
1.172 cvs 3275: if (lost_update_check && (!UsePreconditions || !etag))
1.168 cvs 3276: status = HTHeadAnchor (me->dest, me->request);
3277: else
3278: status = HTPutDocumentAnchor (HTAnchor_parent (me->source), me->dest, me->request);
1.4 cvs 3279:
1.130 cvs 3280: if (status == YES && me->reqStatus != HT_ERR)
1.7 cvs 3281: {
1.168 cvs 3282: /* part of the stop button handler */
3283: if ((mode & AMAYA_SYNC) || (mode & AMAYA_ISYNC))
3284: status = LoopForStop (me);
1.15 cvs 3285: }
1.136 cvs 3286: if (!HTRequest_kill (me->request))
3287: AHTReqContext_delete (me);
1.168 cvs 3288:
1.116 cvs 3289: TtaHandlePendingEvents ();
1.90 cvs 3290:
1.130 cvs 3291: return (status == YES ? 0 : -1);
1.28 cvs 3292: }
1.4 cvs 3293:
1.5 cvs 3294: /*----------------------------------------------------------------------
1.138 cvs 3295: StopRequest
1.17 cvs 3296: stops (kills) all active requests associated with a docid
1.5 cvs 3297: ----------------------------------------------------------------------*/
1.4 cvs 3298: #ifdef __STDC__
3299: void StopRequest (int docid)
3300: #else
3301: void StopRequest (docid)
3302: int docid;
3303: #endif
3304: {
1.140 cvs 3305: if (Amaya && CanDoStop ())
1.138 cvs 3306: {
1.139 cvs 3307: #if 0 /* for later */
1.140 cvs 3308: AHTDocId_Status *docid_status;
3309: /* verify if there are any requests at all associated with docid */
1.138 cvs 3310: docid_status = (AHTDocId_Status *) GetDocIdStatus (docid,
3311: Amaya->docid_status);
3312: if (docid_status == (AHTDocId_Status *) NULL)
3313: return;
1.139 cvs 3314: #endif /* 0 */
1.138 cvs 3315: /* temporary call to stop all requests, as libwww changed its API */
3316: StopAllRequests (docid);
3317: }
3318: }
3319:
1.190 cvs 3320: /* @@@ the docid parameter isn't used... clean it up */
1.138 cvs 3321: /*----------------------------------------------------------------------
3322: StopAllRequests
3323: stops (kills) all active requests. We use the docid
3324: ----------------------------------------------------------------------*/
3325: #ifdef __STDC__
3326: void StopAllRequests (int docid)
3327: #else
1.140 cvs 3328: void StopAllRequests (docid)
1.138 cvs 3329: int docid;
3330: #endif
3331: {
1.4 cvs 3332: HTList *cur;
3333: AHTReqContext *me;
1.191 cvs 3334: static ThotBool lock_stop = 0;
3335: ThotBool async_flag;
1.116 cvs 3336:
1.138 cvs 3337: /* only do the stop if we're not being called while processing a
1.146 cvs 3338: request, and if we're not already dealing with a stop */
3339: if (Amaya && CanDoStop () && !lock_stop)
1.7 cvs 3340: {
1.100 cvs 3341: #ifdef DEBUG_LIBWWW
1.138 cvs 3342: fprintf (stderr, "StopRequest: number of Amaya requests "
3343: "before kill: %d\n", Amaya->open_requests);
1.100 cvs 3344: #endif /* DEBUG_LIBWWW */
1.150 cvs 3345: /* enter the critical section */
1.146 cvs 3346: lock_stop = TRUE;
1.214 cvs 3347: /* set a module global variable so that we can do special
3348: processing easier */
3349: UserAborted_flag = TRUE;
1.164 cvs 3350: /* expire all outstanding timers */
3351: HTTimer_expireAll ();
1.160 cvs 3352: /* HTNet_killAll (); */
1.116 cvs 3353: cur = Amaya->reqlist;
3354: while ((me = (AHTReqContext *) HTList_nextObject (cur)))
3355: {
1.140 cvs 3356: if (AmayaIsAlive ())
1.160 cvs 3357: {
1.161 cvs 3358: #ifdef DEBUG_LIBWWW
1.163 cvs 3359: fprintf (stderr,"StopRequest: killing req %p, url %s, status %d\n", me, me->urlName, me->reqStatus);
1.161 cvs 3360: #endif /* DEBUG_LIBWWW */
3361:
1.165 cvs 3362: if (me->reqStatus != HT_END && me->reqStatus != HT_ABORT)
1.163 cvs 3363: {
3364: if ((me->mode & AMAYA_ASYNC)
3365: || (me->mode & AMAYA_IASYNC))
3366: async_flag = TRUE;
3367: else
3368: async_flag = FALSE;
3369:
1.165 cvs 3370: /* change the status to say that the request aborted */
3371: me->reqStatus = HT_ABORT;
3372:
1.163 cvs 3373: /* kill the request, using the appropriate function */
3374: if (me->request->net)
3375: HTNet_killPipe (me->request->net);
3376: else
3377: {
1.160 cvs 3378: if (me->terminate_cbf)
1.198 cvs 3379: (*me->terminate_cbf) (me->docid, -1, ISO2WideChar (me->urlName),
3380: ISO2WideChar (me->outputfile),
3381: ISO2WideChar (me->content_type),
1.160 cvs 3382: me->context_tcbf);
1.164 cvs 3383:
3384: if (async_flag)
1.165 cvs 3385: /* explicitly free the request context for async
3386: requests. The sync requests context is freed by LoopForStop */
1.164 cvs 3387: AHTReqContext_delete (me);
1.160 cvs 3388: }
1.163 cvs 3389: cur = Amaya->reqlist;
3390: }
1.142 cvs 3391: #ifndef _WINDOWS
3392: #ifdef WWW_XWINDOWS
1.140 cvs 3393: /* to be on the safe side, remove all outstanding X events */
1.160 cvs 3394: else
3395: RequestKillAllXtevents (me);
1.142 cvs 3396: #endif /* WWW_XWINDOWS */
3397: #endif /* !_WINDOWS */
1.160 cvs 3398: }
1.116 cvs 3399: }
1.150 cvs 3400: /* Delete remaining channels */
3401: HTChannel_safeDeleteAll ();
1.214 cvs 3402: /* reset the stop status */
3403: UserAborted_flag = FALSE;
1.150 cvs 3404: /* exit the critical section */
1.148 cvs 3405: lock_stop = FALSE;
1.100 cvs 3406: #ifdef DEBUG_LIBWWW
1.138 cvs 3407: fprintf (stderr, "StopRequest: number of Amaya requests "
3408: "after kill: %d\n", Amaya->open_requests);
1.100 cvs 3409: #endif /* DEBUG_LIBWWW */
1.138 cvs 3410: }
3411: } /* StopAllRequests */
1.17 cvs 3412:
3413:
1.105 cvs 3414: /*----------------------------------------------------------------------
3415: AmayaIsAlive
1.140 cvs 3416: returns the value of the AmayaAlive_flag
1.105 cvs 3417: ----------------------------------------------------------------------*/
3418: #ifdef __STDC__
1.191 cvs 3419: ThotBool AmayaIsAlive (void)
1.105 cvs 3420: #else
1.191 cvs 3421: ThotBool AmayaIsAlive ()
1.105 cvs 3422: #endif /* _STDC_ */
3423: {
1.140 cvs 3424: return AmayaAlive_flag;
3425: }
3426:
3427: /*----------------------------------------------------------------------
3428: CanDoStop
3429: returns the value of the CanDoStop flag
3430: ----------------------------------------------------------------------*/
3431: #ifdef __STDC__
1.191 cvs 3432: ThotBool CanDoStop (void)
1.140 cvs 3433: #else
1.191 cvs 3434: ThotBool CanDoStop ()
1.140 cvs 3435: #endif /* _STDC_ */
3436: {
3437: return CanDoStop_flag;
3438: }
3439:
3440: /*----------------------------------------------------------------------
3441: CanDoStop_set
3442: sets the value of the CanDoStop flag
3443: ----------------------------------------------------------------------*/
3444: #ifdef __STDC__
1.191 cvs 3445: void CanDoStop_set (ThotBool value)
1.140 cvs 3446: #else
3447: void CanDoStop (value)
1.191 cvs 3448: ThotBool value;
1.140 cvs 3449: #endif /* _STDC_ */
3450: {
3451: CanDoStop_flag = value;
1.176 cvs 3452: }
3453:
3454: #ifdef __STDC__
3455: void libwww_updateNetworkConf (int status)
3456: #else
3457: void libwww_updateNetworkConf (status)
3458: int status;
3459: #endif /*__STDC__*/
3460: {
3461: /* @@@ the docid parameter isn't used... clean it up */
3462: int docid = 1;
3463:
3464: /* first, stop all current requests, as the network
3465: may make some changes */
3466: StopAllRequests (docid);
1.207 cvs 3467:
3468: if (status & AMAYA_SAFEPUT_RESTART)
3469: {
3470: SafePut_delete ();
3471: SafePut_init ();
3472: }
1.176 cvs 3473:
3474: if (status & AMAYA_PROXY_RESTART)
3475: {
3476: HTProxy_deleteAll ();
3477: ProxyInit ();
3478: }
3479:
3480: if (status & AMAYA_CACHE_RESTART)
3481: {
3482: clear_cachelock ();
3483: HTCacheTerminate ();
3484: HTCacheMode_setEnabled (NO);
3485: CacheInit ();
3486: }
1.193 cvs 3487:
3488: if (status & AMAYA_LANNEG_RESTART)
3489: {
3490: /* clear the current values */
3491: if (acceptLanguages)
3492: HTLanguage_deleteAll (acceptLanguages);
3493: /* read in the new ones */
3494: acceptLanguages = HTList_new ();
3495: AHTAcceptLanguagesInit (acceptLanguages);
3496: }
1.105 cvs 3497: }
1.116 cvs 3498:
1.69 cvs 3499: #endif /* AMAYA_JAVA */
1.77 cvs 3500:
1.116 cvs 3501: /*
3502: end of Module query.c
3503: */
Webmaster