Annotation of libwww/Robot/src/HTRobot.c, revision 1.27
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: {
1.2 frystyk 238: HTNet_killAll();
1.1 frystyk 239: Robot_delete(me);
240: HTLibTerminate();
241: #ifdef VMS
242: exit(status ? status : 1);
243: #else
244: exit(status ? status : 0);
245: #endif
246: }
247:
248: #ifdef CATCH_SIG
249: #include <signal.h>
250: /* SetSignal
251: ** This function sets up signal handlers. This might not be necessary to
252: ** call if the application has its own handlers (lossage on SVR4)
253: */
254: PRIVATE void SetSignal (void)
255: {
256: /* On some systems (SYSV) it is necessary to catch the SIGPIPE signal
257: ** when attemting to connect to a remote host where you normally should
258: ** get `connection refused' back
259: */
260: if (signal(SIGPIPE, SIG_IGN) == SIG_ERR) {
1.13 eric 261: if (PROT_TRACE) HTTrace("HTSignal.... Can't catch SIGPIPE\n");
1.1 frystyk 262: } else {
1.13 eric 263: if (PROT_TRACE) HTTrace("HTSignal.... Ignoring SIGPIPE\n");
1.1 frystyk 264: }
265: }
266: #endif /* CATCH_SIG */
267:
268: PRIVATE void VersionInfo (void)
269: {
1.13 eric 270: OutputData("\n\nW3C Reference Software\n\n");
271: OutputData("\tW3C Mini Robot (%s) version %s.\n",
1.1 frystyk 272: APP_NAME, APP_VERSION);
1.13 eric 273: OutputData("\tW3C Reference Library version %s.\n\n",HTLib_version());
274: OutputData("Please send feedback to <libwww@w3.org>\n");
1.1 frystyk 275: }
276:
277: /* terminate_handler
278: ** -----------------
1.2 frystyk 279: ** This function is registered to handle the result of the request.
280: ** If no more requests are pending then terminate program
1.1 frystyk 281: */
1.15 frystyk 282: PRIVATE int terminate_handler (HTRequest * request, void * param, int status)
1.1 frystyk 283: {
284: Robot * mr = (Robot *) HTRequest_context(request);
285: if (mr->logfile) HTLog_add(request, status);
1.2 frystyk 286: Thread_delete(mr, request);
1.3 frystyk 287: if (HTNet_isEmpty()) Cleanup(mr, 0);
1.1 frystyk 288: return HT_OK;
289: }
290:
291: /* timeout_handler
292: ** ---------------
293: ** This function is registered to handle timeout in select eventloop
1.7 frystyk 294: **
295: ** BUG: This doesn't work as we don't get the right request object
296: ** back from the event loop
1.1 frystyk 297: */
298: PRIVATE int timeout_handler (HTRequest * request)
299: {
1.27 ! frystyk 300: #if 0
1.2 frystyk 301: Robot * mr = (Robot *) HTRequest_context(request);
1.27 ! frystyk 302: #endif
1.25 frystyk 303: if (SHOW_MSG) HTTrace("Robot....... We don't know how to handle timeout...\n");
1.7 frystyk 304: #if 0
1.1 frystyk 305: HTRequest_kill(request);
1.2 frystyk 306: Thread_delete(mr, request);
1.7 frystyk 307: #endif
1.4 frystyk 308: return HT_OK;
1.1 frystyk 309: }
310:
311: /* ------------------------------------------------------------------------- */
312: /* HTEXT INTERFACE */
313: /* ------------------------------------------------------------------------- */
314:
315: PUBLIC HText * HText_new2 (HTRequest * request, HTParentAnchor * anchor,
316: HTStream * stream)
317: {
318: HText * me;
1.4 frystyk 319: Robot * mr = (Robot *) HTRequest_context(request);
1.14 frystyk 320: if ((me = (HText *) HT_CALLOC(1, sizeof(HText))) == NULL)
321: HT_OUTOFMEM("HText_new2");
1.4 frystyk 322:
323: /* Bind the HText object together with the Request Object */
1.1 frystyk 324: me->request = request;
1.4 frystyk 325:
326: /* Add this HyperDoc object to our list */
327: if (!mr->htext) mr->htext = HTList_new();
328: HTList_addObject(mr->htext, (void *) me);
1.1 frystyk 329: return me;
330: }
331:
1.4 frystyk 332: PUBLIC void HText_free (HText * me) {
1.11 frystyk 333: if (me) HT_FREE (me);
1.4 frystyk 334: }
335:
1.1 frystyk 336: PUBLIC void HText_beginAnchor (HText * text, HTChildAnchor * anchor)
337: {
338: if (text && anchor) {
1.2 frystyk 339: Robot * mr = (Robot *) HTRequest_context(text->request);
1.1 frystyk 340: HTAnchor * dest = HTAnchor_followMainLink((HTAnchor *) anchor);
341: HTParentAnchor * dest_parent = HTAnchor_parent(dest);
1.7 frystyk 342: char * uri = HTAnchor_address((HTAnchor *) dest_parent);
1.1 frystyk 343: HyperDoc * hd = HTAnchor_document(dest_parent);
344:
1.13 eric 345: if (SHOW_MSG) HTTrace("Robot....... Found `%s\' - ", uri ? uri : "NULL");
1.7 frystyk 346:
1.2 frystyk 347: /* Test whether we already have a hyperdoc for this document */
348: if (mr->flags & MR_LINK && dest_parent && !hd) {
1.1 frystyk 349: HTParentAnchor * parent = HTRequest_parent(text->request);
350: HyperDoc * last = HTAnchor_document(parent);
351: int depth = last ? last->depth+1 : 0;
1.2 frystyk 352: HTRequest * newreq = Thread_new(mr, METHOD_GET);
353: HyperDoc_new(mr, dest_parent, depth);
1.7 frystyk 354: HTRequest_setParent(newreq, HTRequest_anchor(text->request));
355: if (depth >= mr->depth) {
356: if (SHOW_MSG)
1.13 eric 357: HTTrace("loading at depth %d using HEAD\n", depth);
1.7 frystyk 358: HTRequest_setMethod(newreq, METHOD_HEAD);
359: HTRequest_setOutputFormat(newreq, WWW_MIME);
360: } else {
1.13 eric 361: if (SHOW_MSG) HTTrace("loading at depth %d\n", depth);
1.2 frystyk 362: }
363: if (HTLoadAnchor((HTAnchor *) dest_parent, newreq) != YES) {
1.13 eric 364: if (SHOW_MSG) HTTrace("not tested!\n");
1.2 frystyk 365: Thread_delete(mr, newreq);
366: }
1.7 frystyk 367: } else {
1.18 frystyk 368: if (SHOW_MSG) HTTrace("duplicate or max depth reached\n");
1.2 frystyk 369: }
1.11 frystyk 370: HT_FREE(uri);
1.2 frystyk 371: }
372: }
373:
374: PUBLIC void HText_appendImage (HText * text, HTChildAnchor * anchor,
1.14 frystyk 375: const char *alt, const char * align, BOOL isMap)
1.2 frystyk 376: {
377: if (text && anchor) {
378: Robot * mr = (Robot *) HTRequest_context(text->request);
379: HTParentAnchor * dest = (HTParentAnchor *)
380: HTAnchor_followMainLink((HTAnchor *) anchor);
381: HyperDoc * hd = HTAnchor_document(dest);
1.1 frystyk 382:
1.2 frystyk 383: /* Test whether we already have a hyperdoc for this document */
384: if (mr->flags & MR_IMG && dest && !hd) {
385: HTParentAnchor * parent = HTRequest_parent(text->request);
386: HyperDoc * last = HTAnchor_document(parent);
387: int depth = last ? last->depth+1 : 0;
388: HTRequest * newreq = Thread_new(mr, METHOD_HEAD);
389: HyperDoc_new(mr, dest, depth);
390: if (SHOW_MSG) {
391: char * uri = HTAnchor_address((HTAnchor *) dest);
1.13 eric 392: HTTrace("Robot....... Checking Image `%s\'\n", uri);
1.11 frystyk 393: HT_FREE(uri);
1.2 frystyk 394: }
395: if (HTLoadAnchor((HTAnchor *) dest, newreq) != YES) {
396: if (SHOW_MSG)
1.13 eric 397: HTTrace("Robot....... Image not tested!\n");
1.2 frystyk 398: Thread_delete(mr, newreq);
1.1 frystyk 399: }
400: }
401: }
402: }
403:
404: PUBLIC void HText_endAnchor (HText * text) {}
1.14 frystyk 405: PUBLIC void HText_appendText (HText * text, const char * str) {}
1.1 frystyk 406: PUBLIC void HText_appendCharacter (HText * text, char ch) {}
407: PUBLIC void HText_endAppend (HText * text) {}
408: PUBLIC void HText_setStyle (HText * text, HTStyle * style) {}
409: PUBLIC void HText_beginAppend (HText * text) {}
410: PUBLIC void HText_appendParagraph (HText * text) {}
411:
412: /* ------------------------------------------------------------------------- */
413: /* MAIN PROGRAM */
414: /* ------------------------------------------------------------------------- */
415:
416: int main (int argc, char ** argv)
417: {
418: int status = 0;
419: int arg;
420: HTChunk * keywords = NULL; /* From command line */
421: int keycnt = 0;
1.12 frystyk 422: Robot * mr = NULL;
1.1 frystyk 423:
424: /* Starts Mac GUSI socket library */
425: #ifdef GUSI
426: GUSISetup(GUSIwithSIOUXSockets);
427: GUSISetup(GUSIwithInternetSockets);
428: #endif
429:
430: #ifdef __MWERKS__ /* STR */
431: InitGraf((Ptr) &qd.thePort);
432: InitFonts();
433: InitWindows();
434: InitMenus(); TEInit();
435: InitDialogs(nil);
436: InitCursor();
437: SIOUXSettings.asktosaveonclose = false;
438: argc=ccommand(&argv);
439: #endif
440:
1.27 ! frystyk 441: /* Initiate W3C Reference Library with a robot profile */
! 442: HTProfile_newRobot(APP_NAME, APP_VERSION);
! 443:
! 444: /* Add the default HTML parser to the set of converters */
! 445: {
! 446: HTList * converters = HTFormat_conversion();
! 447: HTMLInit(converters);
! 448: }
1.1 frystyk 449:
1.12 frystyk 450: /* Build a new robot object */
451: mr = Robot_new();
452:
1.1 frystyk 453: /* Scan command Line for parameters */
454: for (arg=1; arg<argc; arg++) {
455: if (*argv[arg] == '-') {
456:
457: /* non-interactive */
1.17 frystyk 458: if (!strcmp(argv[arg], "-n")) {
1.1 frystyk 459: HTAlert_setInteractive(NO);
460:
461: /* log file */
462: } else if (!strcmp(argv[arg], "-l")) {
463: mr->logfile = (arg+1 < argc && *argv[arg+1] != '-') ?
464: argv[++arg] : DEFAULT_LOG_FILE;
465:
466: /* rule file */
467: } else if (!strcmp(argv[arg], "-r")) {
468: mr->rules = (arg+1 < argc && *argv[arg+1] != '-') ?
469: argv[++arg] : DEFAULT_RULE_FILE;
470:
471: /* output filename */
472: } else if (!strcmp(argv[arg], "-o")) {
473: mr->outputfile = (arg+1 < argc && *argv[arg+1] != '-') ?
474: argv[++arg] : DEFAULT_OUTPUT_FILE;
475:
476: /* timeout -- Change the default request timeout */
477: } else if (!strcmp(argv[arg], "-timeout")) {
478: int timeout = (arg+1 < argc && *argv[arg+1] != '-') ?
479: atoi(argv[++arg]) : DEFAULT_TIMEOUT;
480: if (timeout > 0) mr->tv->tv_sec = timeout;
481:
1.7 frystyk 482: /* preemptive or non-preemptive access */
1.1 frystyk 483: } else if (!strcmp(argv[arg], "-single")) {
1.7 frystyk 484: HTRequest_setPreemptive(mr->request, YES);
485: mr->flags |= MR_PREEMPTIVE;
1.2 frystyk 486:
487: /* test inlined images */
488: } else if (!strcmp(argv[arg], "-img")) {
489: mr->flags |= MR_IMG;
490:
491: /* load anchors */
492: } else if (!strcmp(argv[arg], "-link")) {
493: mr->flags |= MR_LINK;
1.7 frystyk 494: mr->depth = (arg+1 < argc && *argv[arg+1] != '-') ?
495: atoi(argv[++arg]) : DEFAULT_DEPTH;
1.2 frystyk 496:
1.7 frystyk 497: /* preemptive or non-preemptive access */
1.2 frystyk 498: } else if (!strcmp(argv[arg], "-single")) {
1.7 frystyk 499: HTRequest_setPreemptive(mr->request, YES);
500: mr->flags |= MR_PREEMPTIVE;
1.1 frystyk 501:
1.12 frystyk 502: /* Output start and end time */
503: } else if (!strcmp(argv[arg], "-ss")) {
504: time_t local = time(NULL);
1.13 eric 505: HTTrace("Robot started on %s\n",
1.12 frystyk 506: HTDateTimeStr(&local, YES));
507: mr->flags |= MR_TIME;
508:
1.1 frystyk 509: /* print version and exit */
510: } else if (!strcmp(argv[arg], "-version")) {
511: VersionInfo();
512: Cleanup(mr, 0);
513:
514: #ifdef WWWTRACE
515: /* trace flags */
516: } else if (!strncmp(argv[arg], "-v", 2)) {
1.24 frystyk 517: HTSetTraceMessageMask(argv[arg]+2);
1.1 frystyk 518: #endif
519:
520: } else {
1.13 eric 521: if (SHOW_MSG) HTTrace("Bad Argument (%s)\n", argv[arg]);
1.1 frystyk 522: }
1.17 frystyk 523: } else { /* If no leading `-' then check for URL or keywords */
1.1 frystyk 524: if (!keycnt) {
525: char * ref = HTParse(argv[arg], mr->cwd, PARSE_ALL);
526: mr->anchor = (HTParentAnchor *) HTAnchor_findAddress(ref);
1.7 frystyk 527: HyperDoc_new(mr, mr->anchor, 0);
1.1 frystyk 528: keycnt = 1;
1.11 frystyk 529: HT_FREE(ref);
1.1 frystyk 530: } else { /* Check for successive keyword arguments */
531: char *escaped = HTEscape(argv[arg], URL_XALPHAS);
532: if (keycnt++ <= 1)
1.5 frystyk 533: keywords = HTChunk_new(128);
1.1 frystyk 534: else
1.5 frystyk 535: HTChunk_putc(keywords, ' ');
536: HTChunk_puts(keywords, HTStrip(escaped));
1.11 frystyk 537: HT_FREE(escaped);
1.1 frystyk 538: }
539: }
540: }
541:
542: #ifdef CATCH_SIG
543: SetSignal();
544: #endif
545:
546: if (!keycnt) {
1.13 eric 547: if (SHOW_MSG) HTTrace("Please specify URL to check.\n");
1.1 frystyk 548: Cleanup(mr, -1);
549: }
550:
1.23 manoli 551: /* Testing that HTTrace is working */
552: HTTrace ("Welcome to the W3C mini Robot\n");
553:
1.1 frystyk 554: /* Rule file specified? */
555: if (mr->rules) {
556: char * rules = HTParse(mr->rules, mr->cwd, PARSE_ALL);
1.27 ! frystyk 557: if (!HTLoadRules(rules))
1.13 eric 558: if (SHOW_MSG) HTTrace("Can't access rules\n");
1.11 frystyk 559: HT_FREE(rules);
1.1 frystyk 560: }
561:
562: /* Output file specified? */
563: if (mr->outputfile) {
564: if ((mr->output = fopen(mr->outputfile, "wb")) == NULL) {
1.13 eric 565: if (SHOW_MSG) HTTrace("Can't open `%s'\n", mr->outputfile);
1.1 frystyk 566: mr->output = OUTPUT;
567: }
568: }
569:
570: /* Log file specifed? */
571: if (mr->logfile) HTLog_open(mr->logfile, YES, YES);
572:
1.27 ! frystyk 573: /* Register our own someterminater filter */
1.15 frystyk 574: HTNetCall_addAfter(terminate_handler, NULL, HT_ALL);
1.1 frystyk 575:
576: /* Set timeout on sockets */
1.16 frystyk 577: HTEventrg_registerTimeout(mr->tv, mr->timeout, timeout_handler, NO);
1.1 frystyk 578:
579: /* Start the request */
580: if (keywords) /* Search */
1.27 ! frystyk 581: status = HTSearchAnchor(keywords, mr->anchor, mr->request);
1.1 frystyk 582: else
583: status = HTLoadAnchor((HTAnchor *) mr->anchor, mr->request);
584:
1.5 frystyk 585: if (keywords) HTChunk_delete(keywords);
1.1 frystyk 586: if (status != YES) {
1.13 eric 587: if (SHOW_MSG) HTTrace("Can't access resource\n");
1.1 frystyk 588: Cleanup(mr, -1);
589: }
590:
591: /* Go into the event loop... */
1.16 frystyk 592: HTEventrg_loop(mr->request);
1.1 frystyk 593:
594: /* Only gets here if event loop fails */
595: Cleanup(mr, 0);
596: return 0;
597: }
Webmaster