Annotation of libwww/Robot/src/HTRobot.c, revision 1.31
1.1 frystyk 1: /* HTRobot.c
2: ** W3C MINI ROBOT
3: **
4: ** (c) COPRIGHT MIT 1995.
5: ** Please first read the full copyright statement in the file COPYRIGH.
6: **
7: ** This program illustrates how to travers links using the Anchor object
8: **
9: ** Authors:
10: ** HFN Henrik Frystyk Nielsen, (frystyk@w3.org)
11: **
12: ** History:
13: ** Dec 04 95 First version
14: */
15:
16: #include "WWWLib.h" /* Global Library Include file */
17: #include "WWWApp.h" /* Application stuff */
1.17 frystyk 18: #include "WWWTrans.h"
1.10 frystyk 19: #include "WWWInit.h"
1.9 frystyk 20:
1.4 frystyk 21: #include "HText.h"
1.1 frystyk 22:
23: #include "HTRobot.h" /* Implemented here */
24:
1.14 frystyk 25: #ifndef W3C_VERSION
26: #define W3C_VERSION "unspecified"
1.1 frystyk 27: #endif
28:
29: #define APP_NAME "W3CRobot"
1.14 frystyk 30: #define APP_VERSION W3C_VERSION
1.1 frystyk 31:
32: #define DEFAULT_OUTPUT_FILE "robot.out"
33: #define DEFAULT_RULE_FILE "robot.conf"
34: #define DEFAULT_LOG_FILE "robot.log"
1.7 frystyk 35: #define DEFAULT_DEPTH 0
1.1 frystyk 36:
37: #define SHOW_MSG (WWWTRACE || HTAlert_interactive())
38:
1.7 frystyk 39: #define DEFAULT_TIMEOUT 10 /* timeout in seconds */
1.1 frystyk 40:
41: #if defined(__svr4__)
42: #define CATCH_SIG
43: #endif
44:
45: typedef enum _MRFlags {
1.2 frystyk 46: MR_IMG = 0x1,
47: MR_LINK = 0x2,
1.12 frystyk 48: MR_PREEMPTIVE= 0x4,
49: MR_TIME = 0x8
1.1 frystyk 50: } MRFlags;
51:
52: typedef struct _Robot {
53: HTRequest * request;
1.7 frystyk 54: HTRequest * timeout; /* Until we get a server eventloop */
1.1 frystyk 55: HTParentAnchor * anchor;
1.2 frystyk 56: int depth; /* How deep is our tree */
1.30 frystyk 57: int cnt; /* Count of requests */
1.2 frystyk 58: HTList * hyperdoc; /* List of our HyperDoc Objects */
1.4 frystyk 59: HTList * htext; /* List of our HText Objects */
1.1 frystyk 60: struct timeval * tv; /* Timeout on socket */
61: char * cwd; /* Current dir URL */
62: char * rules;
63: char * logfile;
64: char * outputfile;
65: FILE * output;
66: MRFlags flags;
67: } Robot;
68:
69: typedef enum _LoadState {
70: L_INVALID = -2,
71: L_LOADING = -1,
72: L_SUCCESS = 0,
73: L_ERROR
74: } LoadState;
75:
76: /*
77: ** The HyperDoc object is bound to the anchor and contains information about
78: ** where we are in the search for recursive searches
79: */
80: typedef struct _HyperDoc {
81: HTParentAnchor * anchor;
82: LoadState state;
83: int depth;
84: } HyperDoc;
85:
86: /*
87: ** This is the HText object that is created every time we start parsing a
88: ** HTML object
89: */
1.4 frystyk 90: struct _HText {
1.1 frystyk 91: HTRequest * request;
1.4 frystyk 92: };
1.1 frystyk 93:
94: PUBLIC HText * HTMainText = NULL;
95: PUBLIC HTParentAnchor * HTMainAnchor = NULL;
96: PUBLIC HTStyleSheet * styleSheet = NULL;
97:
98: /* ------------------------------------------------------------------------- */
99:
1.13 eric 100: /* Standard (non-error) Output
101: ** ---------------------------
102: */
103: PUBLIC int OutputData(const char * fmt, ...)
104: {
105: int ret;
106: va_list pArgs;
107: va_start(pArgs, fmt);
108: ret = vfprintf(stdout, fmt, pArgs);
109: va_end(pArgs);
110: return ret;
111: }
112:
113: /* ------------------------------------------------------------------------- */
114:
1.2 frystyk 115: /* Create a "HyperDoc" object
116: ** --------------------------
117: ** A HyperDoc object contains information about whether we have already
118: ** started checking the anchor and the depth in our search
119: */
120: PRIVATE HyperDoc * HyperDoc_new (Robot * mr,HTParentAnchor * anchor, int depth)
121: {
122: HyperDoc * hd;
1.14 frystyk 123: if ((hd = (HyperDoc *) HT_CALLOC(1, sizeof(HyperDoc))) == NULL)
124: HT_OUTOFMEM("HyperDoc_new");
1.2 frystyk 125: hd->state = L_INVALID;
126: hd->depth = depth;
127:
128: /* Bind the HyperDoc object together with the Anchor Object */
129: hd->anchor = anchor;
130: HTAnchor_setDocument(anchor, (void *) hd);
131:
132: /* Add this HyperDoc object to our list */
133: if (!mr->hyperdoc) mr->hyperdoc = HTList_new();
134: HTList_addObject(mr->hyperdoc, (void *) hd);
135: return hd;
136: }
137:
138: /* Delete a "HyperDoc" object
139: ** --------------------------
140: */
141: PRIVATE BOOL HyperDoc_delete (HyperDoc * hd)
142: {
143: if (hd) {
1.11 frystyk 144: HT_FREE (hd);
1.2 frystyk 145: return YES;
146: }
147: return NO;
148: }
149:
1.1 frystyk 150: /* Create a Command Line Object
151: ** ----------------------------
152: */
153: PRIVATE Robot * Robot_new (void)
154: {
155: Robot * me;
1.14 frystyk 156: if ((me = (Robot *) HT_CALLOC(1, sizeof(Robot))) == NULL ||
157: (me->tv = (struct timeval*) HT_CALLOC(1, sizeof(struct timeval))) == NULL)
158: HT_OUTOFMEM("Robot_new");
1.2 frystyk 159: me->hyperdoc = HTList_new();
1.4 frystyk 160: me->htext = HTList_new();
1.1 frystyk 161: me->tv->tv_sec = DEFAULT_TIMEOUT;
1.25 frystyk 162: me->cwd = HTGetCurrentDirectoryURL();
1.1 frystyk 163: me->output = OUTPUT;
1.30 frystyk 164: me->cnt = 1;
1.1 frystyk 165:
1.7 frystyk 166: /* We keep an extra timeout request object for the timeout_handler */
167: me->timeout = HTRequest_new();
168: HTRequest_setContext (me->timeout, me);
169:
1.1 frystyk 170: /* Bind the Robot object together with the Request Object */
171: me->request = HTRequest_new();
172: HTRequest_setContext (me->request, me);
173: return me;
174: }
175:
176: /* Delete a Command Line Object
177: ** ----------------------------
178: */
179: PRIVATE BOOL Robot_delete (Robot * me)
180: {
181: if (me) {
1.2 frystyk 182: if (me->hyperdoc) {
183: HTList * cur = me->hyperdoc;
184: HyperDoc * pres;
185: while ((pres = (HyperDoc *) HTList_nextObject(cur)))
186: HyperDoc_delete(pres);
187: HTList_delete(me->hyperdoc);
188: }
1.4 frystyk 189: if (me->htext) {
190: HTList * cur = me->htext;
191: HText * pres;
192: while ((pres = (HText *) HTList_nextObject(cur)))
193: HText_free(pres);
194: HTList_delete(me->htext);
195: }
1.1 frystyk 196: if (me->logfile) HTLog_close();
197: if (me->output && me->output != STDOUT) fclose(me->output);
1.12 frystyk 198: if (me->flags & MR_TIME) {
199: time_t local = time(NULL);
1.13 eric 200: HTTrace("Robot terminated %s\n",HTDateTimeStr(&local,YES));
1.12 frystyk 201: }
1.11 frystyk 202: HT_FREE(me->cwd);
203: HT_FREE(me->tv);
204: HT_FREE(me);
1.1 frystyk 205: return YES;
206: }
207: return NO;
208: }
209:
1.2 frystyk 210: /*
211: ** This function creates a new request object and initializes it
212: */
213: PRIVATE HTRequest * Thread_new (Robot * mr, HTMethod method)
214: {
215: HTRequest * newreq = HTRequest_new();
216: HTRequest_setContext (newreq, mr);
1.7 frystyk 217: if (mr->flags & MR_PREEMPTIVE) HTRequest_setPreemptive(newreq, YES);
1.5 frystyk 218: HTRequest_addRqHd(newreq, HT_C_HOST);
1.2 frystyk 219: HTRequest_setMethod(newreq, method);
1.30 frystyk 220: mr->cnt++;
1.2 frystyk 221: return newreq;
222: }
223:
224: PRIVATE BOOL Thread_delete (Robot * mr, HTRequest * request)
225: {
226: if (mr && request) {
227: HTRequest_delete(request);
1.30 frystyk 228: mr->cnt--;
1.2 frystyk 229: return YES;
230: }
231: return NO;
232: }
233:
234: /*
235: ** Cleanup and make sure we close all connections including the persistent
236: ** ones
237: */
1.1 frystyk 238: PRIVATE void Cleanup (Robot * me, int status)
239: {
240: Robot_delete(me);
1.29 eric 241: HTProfile_delete();
1.1 frystyk 242: #ifdef VMS
243: exit(status ? status : 1);
244: #else
245: exit(status ? status : 0);
246: #endif
247: }
248:
249: #ifdef CATCH_SIG
250: #include <signal.h>
251: /* SetSignal
252: ** This function sets up signal handlers. This might not be necessary to
253: ** call if the application has its own handlers (lossage on SVR4)
254: */
255: PRIVATE void SetSignal (void)
256: {
257: /* On some systems (SYSV) it is necessary to catch the SIGPIPE signal
258: ** when attemting to connect to a remote host where you normally should
259: ** get `connection refused' back
260: */
261: if (signal(SIGPIPE, SIG_IGN) == SIG_ERR) {
1.13 eric 262: if (PROT_TRACE) HTTrace("HTSignal.... Can't catch SIGPIPE\n");
1.1 frystyk 263: } else {
1.13 eric 264: if (PROT_TRACE) HTTrace("HTSignal.... Ignoring SIGPIPE\n");
1.1 frystyk 265: }
266: }
267: #endif /* CATCH_SIG */
268:
269: PRIVATE void VersionInfo (void)
270: {
1.13 eric 271: OutputData("\n\nW3C Reference Software\n\n");
272: OutputData("\tW3C Mini Robot (%s) version %s.\n",
1.1 frystyk 273: APP_NAME, APP_VERSION);
1.13 eric 274: OutputData("\tW3C Reference Library version %s.\n\n",HTLib_version());
275: OutputData("Please send feedback to <libwww@w3.org>\n");
1.1 frystyk 276: }
277:
278: /* terminate_handler
279: ** -----------------
1.2 frystyk 280: ** This function is registered to handle the result of the request.
281: ** If no more requests are pending then terminate program
1.1 frystyk 282: */
1.15 frystyk 283: PRIVATE int terminate_handler (HTRequest * request, void * param, int status)
1.1 frystyk 284: {
285: Robot * mr = (Robot *) HTRequest_context(request);
1.2 frystyk 286: Thread_delete(mr, request);
1.30 frystyk 287: if (HTNet_isEmpty()) {
288: if (SHOW_MSG) HTTrace("Robot....... Everything is finished...\n");
289: Cleanup(mr, 0);
290: }
291: if (SHOW_MSG) HTTrace("Robot....... %d outstanding requests\n", mr->cnt);
1.1 frystyk 292: return HT_OK;
293: }
294:
295: /* timeout_handler
296: ** ---------------
297: ** This function is registered to handle timeout in select eventloop
1.7 frystyk 298: **
299: ** BUG: This doesn't work as we don't get the right request object
300: ** back from the event loop
1.1 frystyk 301: */
302: PRIVATE int timeout_handler (HTRequest * request)
303: {
1.27 frystyk 304: #if 0
1.2 frystyk 305: Robot * mr = (Robot *) HTRequest_context(request);
1.27 frystyk 306: #endif
1.25 frystyk 307: if (SHOW_MSG) HTTrace("Robot....... We don't know how to handle timeout...\n");
1.7 frystyk 308: #if 0
1.1 frystyk 309: HTRequest_kill(request);
1.2 frystyk 310: Thread_delete(mr, request);
1.7 frystyk 311: #endif
1.4 frystyk 312: return HT_OK;
1.1 frystyk 313: }
314:
315: /* ------------------------------------------------------------------------- */
316: /* HTEXT INTERFACE */
317: /* ------------------------------------------------------------------------- */
318:
319: PUBLIC HText * HText_new2 (HTRequest * request, HTParentAnchor * anchor,
320: HTStream * stream)
321: {
322: HText * me;
1.4 frystyk 323: Robot * mr = (Robot *) HTRequest_context(request);
1.14 frystyk 324: if ((me = (HText *) HT_CALLOC(1, sizeof(HText))) == NULL)
325: HT_OUTOFMEM("HText_new2");
1.4 frystyk 326:
327: /* Bind the HText object together with the Request Object */
1.1 frystyk 328: me->request = request;
1.4 frystyk 329:
330: /* Add this HyperDoc object to our list */
331: if (!mr->htext) mr->htext = HTList_new();
332: HTList_addObject(mr->htext, (void *) me);
1.1 frystyk 333: return me;
334: }
335:
1.4 frystyk 336: PUBLIC void HText_free (HText * me) {
1.11 frystyk 337: if (me) HT_FREE (me);
1.4 frystyk 338: }
339:
1.1 frystyk 340: PUBLIC void HText_beginAnchor (HText * text, HTChildAnchor * anchor)
341: {
342: if (text && anchor) {
1.2 frystyk 343: Robot * mr = (Robot *) HTRequest_context(text->request);
1.1 frystyk 344: HTAnchor * dest = HTAnchor_followMainLink((HTAnchor *) anchor);
345: HTParentAnchor * dest_parent = HTAnchor_parent(dest);
1.7 frystyk 346: char * uri = HTAnchor_address((HTAnchor *) dest_parent);
1.1 frystyk 347: HyperDoc * hd = HTAnchor_document(dest_parent);
348:
1.13 eric 349: if (SHOW_MSG) HTTrace("Robot....... Found `%s\' - ", uri ? uri : "NULL");
1.7 frystyk 350:
1.2 frystyk 351: /* Test whether we already have a hyperdoc for this document */
352: if (mr->flags & MR_LINK && dest_parent && !hd) {
1.1 frystyk 353: HTParentAnchor * parent = HTRequest_parent(text->request);
354: HyperDoc * last = HTAnchor_document(parent);
355: int depth = last ? last->depth+1 : 0;
1.2 frystyk 356: HTRequest * newreq = Thread_new(mr, METHOD_GET);
357: HyperDoc_new(mr, dest_parent, depth);
1.7 frystyk 358: HTRequest_setParent(newreq, HTRequest_anchor(text->request));
359: if (depth >= mr->depth) {
360: if (SHOW_MSG)
1.13 eric 361: HTTrace("loading at depth %d using HEAD\n", depth);
1.7 frystyk 362: HTRequest_setMethod(newreq, METHOD_HEAD);
1.30 frystyk 363: HTRequest_setOutputFormat(newreq, WWW_DEBUG);
1.7 frystyk 364: } else {
1.13 eric 365: if (SHOW_MSG) HTTrace("loading at depth %d\n", depth);
1.2 frystyk 366: }
367: if (HTLoadAnchor((HTAnchor *) dest_parent, newreq) != YES) {
1.13 eric 368: if (SHOW_MSG) HTTrace("not tested!\n");
1.2 frystyk 369: Thread_delete(mr, newreq);
370: }
1.7 frystyk 371: } else {
1.18 frystyk 372: if (SHOW_MSG) HTTrace("duplicate or max depth reached\n");
1.2 frystyk 373: }
1.11 frystyk 374: HT_FREE(uri);
1.2 frystyk 375: }
376: }
377:
378: PUBLIC void HText_appendImage (HText * text, HTChildAnchor * anchor,
1.14 frystyk 379: const char *alt, const char * align, BOOL isMap)
1.2 frystyk 380: {
381: if (text && anchor) {
382: Robot * mr = (Robot *) HTRequest_context(text->request);
383: HTParentAnchor * dest = (HTParentAnchor *)
384: HTAnchor_followMainLink((HTAnchor *) anchor);
385: HyperDoc * hd = HTAnchor_document(dest);
1.1 frystyk 386:
1.2 frystyk 387: /* Test whether we already have a hyperdoc for this document */
388: if (mr->flags & MR_IMG && dest && !hd) {
389: HTParentAnchor * parent = HTRequest_parent(text->request);
390: HyperDoc * last = HTAnchor_document(parent);
391: int depth = last ? last->depth+1 : 0;
392: HTRequest * newreq = Thread_new(mr, METHOD_HEAD);
393: HyperDoc_new(mr, dest, depth);
394: if (SHOW_MSG) {
395: char * uri = HTAnchor_address((HTAnchor *) dest);
1.13 eric 396: HTTrace("Robot....... Checking Image `%s\'\n", uri);
1.11 frystyk 397: HT_FREE(uri);
1.2 frystyk 398: }
399: if (HTLoadAnchor((HTAnchor *) dest, newreq) != YES) {
400: if (SHOW_MSG)
1.13 eric 401: HTTrace("Robot....... Image not tested!\n");
1.2 frystyk 402: Thread_delete(mr, newreq);
1.1 frystyk 403: }
404: }
405: }
406: }
407:
408: PUBLIC void HText_endAnchor (HText * text) {}
1.14 frystyk 409: PUBLIC void HText_appendText (HText * text, const char * str) {}
1.1 frystyk 410: PUBLIC void HText_appendCharacter (HText * text, char ch) {}
411: PUBLIC void HText_endAppend (HText * text) {}
412: PUBLIC void HText_setStyle (HText * text, HTStyle * style) {}
413: PUBLIC void HText_beginAppend (HText * text) {}
414: PUBLIC void HText_appendParagraph (HText * text) {}
415:
416: /* ------------------------------------------------------------------------- */
417: /* MAIN PROGRAM */
418: /* ------------------------------------------------------------------------- */
419:
420: int main (int argc, char ** argv)
421: {
422: int status = 0;
423: int arg;
424: HTChunk * keywords = NULL; /* From command line */
425: int keycnt = 0;
1.12 frystyk 426: Robot * mr = NULL;
1.1 frystyk 427:
428: /* Starts Mac GUSI socket library */
429: #ifdef GUSI
430: GUSISetup(GUSIwithSIOUXSockets);
431: GUSISetup(GUSIwithInternetSockets);
432: #endif
433:
434: #ifdef __MWERKS__ /* STR */
435: InitGraf((Ptr) &qd.thePort);
436: InitFonts();
437: InitWindows();
438: InitMenus(); TEInit();
439: InitDialogs(nil);
440: InitCursor();
441: SIOUXSettings.asktosaveonclose = false;
442: argc=ccommand(&argv);
443: #endif
444:
1.27 frystyk 445: /* Initiate W3C Reference Library with a robot profile */
446: HTProfile_newRobot(APP_NAME, APP_VERSION);
447:
448: /* Add the default HTML parser to the set of converters */
449: {
450: HTList * converters = HTFormat_conversion();
451: HTMLInit(converters);
452: }
1.1 frystyk 453:
1.12 frystyk 454: /* Build a new robot object */
455: mr = Robot_new();
456:
1.1 frystyk 457: /* Scan command Line for parameters */
458: for (arg=1; arg<argc; arg++) {
459: if (*argv[arg] == '-') {
460:
461: /* non-interactive */
1.17 frystyk 462: if (!strcmp(argv[arg], "-n")) {
1.1 frystyk 463: HTAlert_setInteractive(NO);
464:
465: /* log file */
466: } else if (!strcmp(argv[arg], "-l")) {
467: mr->logfile = (arg+1 < argc && *argv[arg+1] != '-') ?
468: argv[++arg] : DEFAULT_LOG_FILE;
469:
470: /* rule file */
471: } else if (!strcmp(argv[arg], "-r")) {
472: mr->rules = (arg+1 < argc && *argv[arg+1] != '-') ?
473: argv[++arg] : DEFAULT_RULE_FILE;
474:
475: /* output filename */
476: } else if (!strcmp(argv[arg], "-o")) {
477: mr->outputfile = (arg+1 < argc && *argv[arg+1] != '-') ?
478: argv[++arg] : DEFAULT_OUTPUT_FILE;
479:
480: /* timeout -- Change the default request timeout */
481: } else if (!strcmp(argv[arg], "-timeout")) {
482: int timeout = (arg+1 < argc && *argv[arg+1] != '-') ?
483: atoi(argv[++arg]) : DEFAULT_TIMEOUT;
484: if (timeout > 0) mr->tv->tv_sec = timeout;
485:
1.7 frystyk 486: /* preemptive or non-preemptive access */
1.1 frystyk 487: } else if (!strcmp(argv[arg], "-single")) {
1.7 frystyk 488: HTRequest_setPreemptive(mr->request, YES);
489: mr->flags |= MR_PREEMPTIVE;
1.2 frystyk 490:
491: /* test inlined images */
492: } else if (!strcmp(argv[arg], "-img")) {
493: mr->flags |= MR_IMG;
494:
495: /* load anchors */
496: } else if (!strcmp(argv[arg], "-link")) {
497: mr->flags |= MR_LINK;
1.7 frystyk 498: mr->depth = (arg+1 < argc && *argv[arg+1] != '-') ?
499: atoi(argv[++arg]) : DEFAULT_DEPTH;
1.2 frystyk 500:
1.7 frystyk 501: /* preemptive or non-preemptive access */
1.2 frystyk 502: } else if (!strcmp(argv[arg], "-single")) {
1.7 frystyk 503: HTRequest_setPreemptive(mr->request, YES);
504: mr->flags |= MR_PREEMPTIVE;
1.1 frystyk 505:
1.12 frystyk 506: /* Output start and end time */
507: } else if (!strcmp(argv[arg], "-ss")) {
508: time_t local = time(NULL);
1.13 eric 509: HTTrace("Robot started on %s\n",
1.12 frystyk 510: HTDateTimeStr(&local, YES));
511: mr->flags |= MR_TIME;
512:
1.1 frystyk 513: /* print version and exit */
514: } else if (!strcmp(argv[arg], "-version")) {
515: VersionInfo();
516: Cleanup(mr, 0);
517:
518: #ifdef WWWTRACE
519: /* trace flags */
520: } else if (!strncmp(argv[arg], "-v", 2)) {
1.24 frystyk 521: HTSetTraceMessageMask(argv[arg]+2);
1.1 frystyk 522: #endif
523:
524: } else {
1.13 eric 525: if (SHOW_MSG) HTTrace("Bad Argument (%s)\n", argv[arg]);
1.1 frystyk 526: }
1.17 frystyk 527: } else { /* If no leading `-' then check for URL or keywords */
1.1 frystyk 528: if (!keycnt) {
529: char * ref = HTParse(argv[arg], mr->cwd, PARSE_ALL);
530: mr->anchor = (HTParentAnchor *) HTAnchor_findAddress(ref);
1.7 frystyk 531: HyperDoc_new(mr, mr->anchor, 0);
1.1 frystyk 532: keycnt = 1;
1.11 frystyk 533: HT_FREE(ref);
1.1 frystyk 534: } else { /* Check for successive keyword arguments */
535: char *escaped = HTEscape(argv[arg], URL_XALPHAS);
536: if (keycnt++ <= 1)
1.5 frystyk 537: keywords = HTChunk_new(128);
1.1 frystyk 538: else
1.5 frystyk 539: HTChunk_putc(keywords, ' ');
540: HTChunk_puts(keywords, HTStrip(escaped));
1.11 frystyk 541: HT_FREE(escaped);
1.1 frystyk 542: }
543: }
544: }
545:
546: #ifdef CATCH_SIG
547: SetSignal();
548: #endif
549:
550: if (!keycnt) {
1.13 eric 551: if (SHOW_MSG) HTTrace("Please specify URL to check.\n");
1.1 frystyk 552: Cleanup(mr, -1);
553: }
554:
1.23 manoli 555: /* Testing that HTTrace is working */
556: HTTrace ("Welcome to the W3C mini Robot\n");
557:
1.1 frystyk 558: /* Rule file specified? */
559: if (mr->rules) {
560: char * rules = HTParse(mr->rules, mr->cwd, PARSE_ALL);
1.27 frystyk 561: if (!HTLoadRules(rules))
1.13 eric 562: if (SHOW_MSG) HTTrace("Can't access rules\n");
1.11 frystyk 563: HT_FREE(rules);
1.1 frystyk 564: }
565:
566: /* Output file specified? */
567: if (mr->outputfile) {
568: if ((mr->output = fopen(mr->outputfile, "wb")) == NULL) {
1.13 eric 569: if (SHOW_MSG) HTTrace("Can't open `%s'\n", mr->outputfile);
1.1 frystyk 570: mr->output = OUTPUT;
571: }
572: }
573:
574: /* Log file specifed? */
575: if (mr->logfile) HTLog_open(mr->logfile, YES, YES);
576:
1.27 frystyk 577: /* Register our own someterminater filter */
1.15 frystyk 578: HTNetCall_addAfter(terminate_handler, NULL, HT_ALL);
1.1 frystyk 579:
580: /* Set timeout on sockets */
1.16 frystyk 581: HTEventrg_registerTimeout(mr->tv, mr->timeout, timeout_handler, NO);
1.1 frystyk 582:
583: /* Start the request */
584: if (keywords) /* Search */
1.28 frystyk 585: status = HTSearchAnchor(keywords, (HTAnchor *)mr->anchor, mr->request);
1.1 frystyk 586: else
587: status = HTLoadAnchor((HTAnchor *) mr->anchor, mr->request);
588:
1.5 frystyk 589: if (keywords) HTChunk_delete(keywords);
1.1 frystyk 590: if (status != YES) {
1.13 eric 591: if (SHOW_MSG) HTTrace("Can't access resource\n");
1.1 frystyk 592: Cleanup(mr, -1);
593: }
594:
595: /* Go into the event loop... */
1.16 frystyk 596: HTEventrg_loop(mr->request);
1.1 frystyk 597:
598: /* Only gets here if event loop fails */
599: Cleanup(mr, 0);
600: return 0;
601: }
Webmaster