1 /* Access Manager HTAccess.c
20 #include "HTBrowse.h" /* Need global HTClientHost */
28 #define HT_NO_DATA -9999
30 PUBLIC int HTDiag = 0; /* Diagnostics: load source as text */
32 /* Telnet or "rlogin" access
33 ** -------------------------
35 PRIVATE int remote_session ARGS2(char *, access, char *, host)
38 char * hostname = strchr(host, '@');
39 char * port = strchr(host, ':');
41 BOOL rlogin = strcmp(access, "rlogin");
44 *hostname++ = 0; /* Split */
47 user = 0; /* No user specified */
49 if (port) *port++ = 0; /* Split */
52 sprintf(command, "%s%s%s %s %s", access,
57 if (TRACE) fprintf(stderr, "HTaccess: Command is: %s\n", command);
59 return HT_NO_DATA; /* Ok - it was done but no data */
63 #ifdef MULTINET /* VMS varieties */
64 if (!rlogin) { /* telnet */
65 if (user) printf("When you are connected, log in as %s\n", user);
66 sprintf(command, "TELNET %s%s %s",
71 sprintf(command, "RLOGIN%s%s%s%s %s", access,
72 user ? "/USERNAME=" : "",
78 if (TRACE) fprintf(stderr, "HTaccess: Command is: %s\n", command);
80 return HT_NO_DATA; /* Ok - it was done but no data */
91 if (!rlogin) { /* telnet only */
92 if (user) printf("When you are connected, log in as %s\n", user);
93 sprintf(command, "TELNET %s", /* @@ Bug: port ignored */
95 if (TRACE) fprintf(stderr, "HTaccess: Command is: %s\n", command);
97 return HT_NO_DATA; /* Ok - it was done but no data */
103 "Sorry, this browser was compiled without the %s access option.\n",
106 "\nTo access the information you must %s to %s", access, hostname);
107 if (port) fprintf(stderr," (port %s)", port);
108 if (user) fprintf(stderr," logging in with username %s", user);
109 fprintf(stderr, ".\n");
114 /* Open a file descriptor for a document
115 ** -------------------------------------
118 ** addr must point to the fully qualified hypertext reference.
121 ** returns <0 Error has occured.
122 ** >=0 Value of file descriptor or socket to be used
124 ** *pFormat Set to the format of the file, if known.
128 PRIVATE int HTOpen ARGS3(
131 HTParentAnchor *,anchor)
133 char * access=0; /* Name of access method */
136 char * gateway_parameter;
137 char * addr = (char *)malloc(strlen(addr1)+1);
139 if (addr == NULL) outofmem(__FILE__, "HTOpen");
140 strcpy(addr, addr1); /* Copy to play with */
142 access = HTParse(addr, "file:", PARSE_ACCESS);
144 gateway_parameter = (char *)malloc(strlen(access)+20);
145 if (gateway_parameter == NULL) outofmem(__FILE__, "HTOpen");
146 strcpy(gateway_parameter, "WWW_");
147 strcat(gateway_parameter, access);
148 strcat(gateway_parameter, "_GATEWAY");
149 gateway = getenv(gateway_parameter);
150 free(gateway_parameter);
153 status = HTLoadHTTP(addr, gateway, anchor, HTDiag);
155 if (status<0) fprintf(stderr, /* For simple users */
156 "Cannot connect to information gateway %s\n", gateway);
158 } else if (0==strcmp(access, "http")) {
159 status = HTLoadHTTP(addr, 0, anchor, HTDiag);
161 if (status<0) fprintf(stderr, /* For simple users */
162 "Cannot connect to information server.\n");
164 } else if (0==strcmp(access, "file")) {
165 status = HTOpenFile(addr, pFormat, anchor);
167 } else if (0==strcmp(access, "news")) {
168 status = HTLoadNews(addr, anchor, HTDiag);
169 if (status>0) status = HT_LOADED;
171 } else if (0==strcmp(access, "gopher")) {
172 status = HTLoadGopher(addr, anchor, HTDiag);
173 if (status>0) status = HT_LOADED;
175 } else if (!strcmp(access, "telnet") || /* TELNET */
176 !strcmp(access, "rlogin")) { /* RLOGIN */
177 char * host = HTParse(addr, "", PARSE_HOST);
178 remote_session(access, host);
181 } else if (0==strcmp(access, "wais")) {
183 "HTAccess: For WAIS access set WWW_wais_GATEWAY to gateway address.\n");
187 "HTAccess: name scheme `%s' unknown by this browser version.\n",
197 /* Close socket opened for reading a file
198 ** --------------------------------------
202 PUBLIC int HTClose ARGS1(int,soc)
204 PRIVATE int HTClose ARGS1(int,soc)
207 return HTFTP_close_file(soc);
215 ** anchor is the node_anchor for the document
216 ** full_address The address of the file to be accessed.
219 ** returns YES Success in opening file
224 PUBLIC BOOL HTLoadDocument ARGS3(HTParentAnchor *,anchor,
225 CONST char *,full_address,
233 if (text=(HText *)HTAnchor_document(anchor)) { /* Already loaded */
238 fprintf(stderr, "HTBrowse: Document already in memory.\n");
240 WWWErwiseStatus = CL_ALREADY_LOADED;
244 if (TRACE) fprintf(stderr, "HTBrowse: Document already in memory.\n");
251 prompt_set("Retrieving document...");
257 new_file_number = HTOpen(full_address, &format, anchor);
259 /* Log the access if necessary
264 fprintf(logfile, "%24.24s %s %s %s\n",
266 HTClientHost ? HTClientHost : "local",
267 new_file_number<0 ? "FAIL" : "GET",
269 fflush(logfile); /* Actually update it on disk */
270 if (TRACE) fprintf(stderr, "Log: %24.24s %s %s %s\n",
272 HTClientHost ? HTClientHost : "local",
273 new_file_number<0 ? "FAIL" : "GET",
278 if (new_file_number == HT_LOADED) {
280 printf("HTAccess: `%s' has been accessed.\n",
284 WWWErwiseStatus = CL_COMPLETED;
285 WWWErwiseConnection->fd = -1;
290 if (new_file_number == HT_NO_DATA) {
292 printf("HTAccess: `%s' has been accessed, No data left.\n",
296 WWWErwiseStatus = CL_FAILED;
301 if (new_file_number<0) { /* Failure in accessing a file */
304 user_message("Can't access `%s'", full_address);
306 printf("\nWWW: Can't access `%s'\n", full_address);
309 WWWErwiseStatus = CL_FAILED;
313 exit(2); /* Can't get first page */
320 printf("WWW: Opened `%s' as fd %d\n",
321 full_address, new_file_number);
326 * Do the rest elsewhere (if this connection can be loaded
327 * using non blocking transfer)
330 if(WWWErwiseConnection->function) {
331 WWWErwiseConnection->fd = new_file_number;
337 HTParseFormat(HTDiag ? WWW_PLAINTEXT : format, anchor, new_file_number);
339 HTClose(new_file_number);
343 } /* HTLoadDocument */
346 /* Load a document from absolute name
350 ** relative_name The relative address of the file to be accessed.
353 ** returns YES Success in opening file
359 PUBLIC BOOL HTLoadAbsolute ARGS2(CONST char *,addr, BOOL, filter)
361 return HTLoadDocument(
362 HTAnchor_parent(HTAnchor_findAddress(addr)),
367 /* Load a document from relative name
371 ** relative_name The relative address of the file to be accessed.
374 ** returns YES Success in opening file
380 PUBLIC BOOL HTLoadRelative ARGS1(CONST char *,relative_name)
382 char * full_address = 0;
386 char * current_address =
387 HTAnchor_address((HTAnchor*)HTMainAnchor);
389 StrAllocCopy(mycopy, relative_name);
391 stripped = HTStrip(mycopy);
392 full_address = HTParse(stripped,
394 PARSE_ACCESS|PARSE_HOST|PARSE_PATH|PARSE_PUNCTUATION);
395 result = HTLoadAbsolute(full_address, NO);
397 free(current_address);
402 /* Load if necessary, and select an anchor
403 ** --------------------------------------
406 ** destination The child or parenet anchor to be loaded.
409 ** returns YES Success
414 PUBLIC BOOL HTLoadAnchor ARGS1(HTAnchor *,destination)
416 HTParentAnchor * parent;
418 if (!destination) return NO; /* No link */
420 parent = HTAnchor_parent(destination);
422 if ( /* HTAnchor_document (parent) == NULL) { */ parent != HTMainAnchor) { /* If not already loaded */
424 char * address = HTAnchor_address((HTAnchor*) parent);
425 result = HTLoadDocument(parent, address, NO);
427 if (!result) return NO;
430 if (destination != (HTAnchor *)parent) /* If child anchor */
431 HText_selectAnchor(HTMainText,
432 (HTChildAnchor*)destination); /* Double display? @@ */
442 ** Performs a keyword search on word given by the user. Adds the keyword to
443 ** the end of the current address and attempts to open the new address.
446 ** *keywords space-separated keyword list or similar search list
447 ** HTMainAnchor global must be valid.
450 PUBLIC BOOL HTSearch ARGS1(char *,keywords)
453 char * p; /* pointer to first non-blank */
455 char * address = HTAnchor_address((HTAnchor*)HTMainAnchor);
458 p = HTStrip(keywords);
464 s=strchr(address, '?'); /* Find old search string */
465 if (s) *s = 0; /* Chop old search off */
467 StrAllocCat(address, "?");
468 StrAllocCat(address, p);
470 result = HTLoadRelative(address);
478 * Why everything is so hardcoded ????
481 PUBLIC char *HTSearchAddress ARGS1(char *,keywords)
483 char * p; /* pointer to first non-blank */
485 char * address = HTAnchor_address((HTAnchor*)HTMainAnchor);
486 char * current_address;
492 p = HTStrip(keywords);
498 s=strchr(address, '?'); /* Find old search string */
499 if (s) *s = 0; /* Chop old search off */
501 StrAllocCat(address, "?");
502 StrAllocCat(address, p);
504 StrAllocCopy(mycopy, address);
506 current_address = HTAnchor_address((HTAnchor*)HTMainAnchor);
508 stripped = HTStrip(mycopy);
510 full_address = HTParse(stripped,
512 PARSE_ACCESS|PARSE_HOST|PARSE_PATH|PARSE_PUNCTUATION);