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