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