Annotation of libwww/Library/src/HTHome.c, revision 2.30
2.1 frystyk 1: /* HTHome.c
2.2 frystyk 2: ** ANCHOR TRANSLATIONS
2.1 frystyk 3: **
4: ** (c) COPYRIGHT MIT 1995.
5: ** Please first read the full copyright statement in the file COPYRIGH.
2.30 ! frystyk 6: ** @(#) $Id: HTHome.c,v 2.29 1998/05/25 07:23:48 frystyk Exp $
2.1 frystyk 7: **
8: ** Authors
9: ** TBL Tim Berners-Lee timbl@w3.org
10: ** JFG Jean-Francois Groff jfg@dxcern.cern.ch
11: ** DD Denis DeLaRoca (310) 825-4580 <CSP1DWD@mvs.oac.ucla.edu>
2.2 frystyk 12: ** HFN Henrik Frystyk
2.1 frystyk 13: ** History
14: ** 8 Jun 92 Telnet hopping prohibited as telnet is not secure TBL
15: ** 26 Jun 92 When over DECnet, suppressed FTP, Gopher and News. JFG
16: ** 6 Oct 92 Moved HTClientHost and HTlogfile into here. TBL
17: ** 17 Dec 92 Tn3270 added, bug fix. DD
18: ** 4 Feb 93 Access registration, Search escapes bad chars TBL
19: ** PARAMETERS TO HTSEARCH AND HTLOADRELATIVE CHANGED
20: ** 28 May 93 WAIS gateway explicit if no WAIS library linked in.
21: ** Dec 93 Bug change around, more reentrant, etc
22: ** 09 May 94 logfile renamed to HTlogfile to avoid clash with WAIS
2.13 frystyk 23: ** 8 Jul 94 Insulate free from _free structure element.
2.1 frystyk 24: ** Sep 95 Rewritten, HFN
25: ** Nov 95 Spawned from HTAccess.c
26: */
27:
28: /* Library include files */
29: #include "WWWLib.h"
30: #include "HTHome.h" /* Implemented here */
31:
32: /* ------------------------------------------------------------------------- */
33:
34: /* Find Related Name
35: ** -----------------
36: ** Creates a string that can be used as a related name when
37: ** calling HTParse initially.
38: **
39: ** The code for this routine originates from the Linemode
40: ** browser and was moved here by howcome@w3.org
41: ** in order for all clients to take advantage.
2.18 frystyk 42: ** The string returned must be freed by the caller
2.1 frystyk 43: */
2.18 frystyk 44: PUBLIC char * HTGetCurrentDirectoryURL (void)
2.1 frystyk 45: {
2.30 ! frystyk 46: char wd[HT_MAX_PATH+2];
2.1 frystyk 47:
2.14 frystyk 48: #ifdef HAVE_GETCWD /* System V variant SIGN CHANGED TBL 921006 !! */
2.29 frystyk 49: char * result = (char *) getcwd(wd, sizeof(wd));
2.14 frystyk 50: #else
2.12 frystyk 51: #ifdef HAVE_GETWD
2.29 frystyk 52: char * result = (char *) getwd(wd);
2.12 frystyk 53: #else
54: #error "This platform does not support neither getwd nor getcwd\n"
2.29 frystyk 55: char * result = NULL;
2.14 frystyk 56: #endif /* HAVE_GETWD */
2.12 frystyk 57: #endif /* HAVE_GETCWD */
2.29 frystyk 58: *(wd+HT_MAX_PATH) = '\0';
2.30 ! frystyk 59: if (*(wd+strlen(wd)-1) != '/') strcat(wd, "/");
2.29 frystyk 60: return result ? HTLocalToWWW(result) : NULL;
2.1 frystyk 61: }
62:
63:
64: /* Generate the anchor for the home page
65: ** -------------------------------------
66: **
67: ** As it involves file access, this should only be done once
68: ** when the program first runs.
69: ** This is a default algorithm -- browser don't HAVE to use this.
70: ** But consistency betwen browsers is STRONGLY recommended!
71: **
72: ** Priority order is:
73: **
74: ** 1 WWW_HOME environment variable (logical name, etc)
75: ** 2 ~/WWW/default.html
76: ** 3 /usr/local/bin/default.html
77: ** 4 http://www.w3.org/default.html
78: **
79: */
80: PUBLIC HTParentAnchor * HTHomeAnchor (void)
81: {
82: char * my_home_document = NULL;
83: char * home = (char *) getenv(LOGICAL_DEFAULT);
84: char * ref;
85: HTParentAnchor * anchor;
86:
87: /* Someone telnets in, they get a special home */
88: if (home) {
89: StrAllocCopy(my_home_document, home);
90: } else if (HTLib_secure()) { /* Telnet server */
91: FILE * fp = fopen(REMOTE_POINTER, "r");
92: char * status;
93: if (fp) {
2.10 frystyk 94: if ((my_home_document = (char *) HT_MALLOC(HT_MAX_PATH)) == NULL)
95: HT_OUTOFMEM("my_home_document ");
2.1 frystyk 96: status = fgets(my_home_document, HT_MAX_PATH, fp);
97: if (!status) {
2.10 frystyk 98: HT_FREE(my_home_document);
2.1 frystyk 99: my_home_document = NULL;
100: }
101: fclose(fp);
102: }
103: if (!my_home_document) StrAllocCopy(my_home_document, REMOTE_ADDRESS);
104: }
105:
106: if (!my_home_document) {
107: FILE * fp = NULL;
108: char * home = (char *) getenv("HOME");
109: if (home) {
2.10 frystyk 110: if ((my_home_document = (char *) HT_MALLOC(strlen(home)+1+ strlen(PERSONAL_DEFAULT)+1)) == NULL)
111: HT_OUTOFMEM("HTLocalName");
2.1 frystyk 112: sprintf(my_home_document, "%s/%s", home, PERSONAL_DEFAULT);
113: fp = fopen(my_home_document, "r");
114: }
115:
116: if (!fp) {
117: StrAllocCopy(my_home_document, LOCAL_DEFAULT_FILE);
118: fp = fopen(my_home_document, "r");
119: }
120: if (fp) {
121: fclose(fp);
122: } else {
123: if (WWWTRACE)
2.12 frystyk 124: HTTrace("Home Anchor. No local home document in ~/%s or %s\n",
2.1 frystyk 125: PERSONAL_DEFAULT, LOCAL_DEFAULT_FILE);
2.10 frystyk 126: HT_FREE(my_home_document);
2.1 frystyk 127: my_home_document = NULL;
128: }
129: }
2.12 frystyk 130:
2.1 frystyk 131: ref = HTParse(my_home_document ? my_home_document :
132: HTLib_secure() ? REMOTE_ADDRESS : LAST_RESORT, "file:",
133: PARSE_ACCESS|PARSE_HOST|PARSE_PATH|PARSE_PUNCTUATION);
134: if (my_home_document) {
135: if (WWWTRACE)
2.12 frystyk 136: HTTrace("Home Anchor. `%s\' used for custom home page as\n`%s\'\n",
2.1 frystyk 137: my_home_document, ref);
2.10 frystyk 138: HT_FREE(my_home_document);
2.1 frystyk 139: }
140: anchor = (HTParentAnchor*) HTAnchor_findAddress(ref);
2.10 frystyk 141: HT_FREE(ref);
2.1 frystyk 142: return anchor;
2.19 frystyk 143: }
144:
145: /*
2.22 frystyk 146: ** Creates a temporary anchor that doesn't exist
147: */
148: PUBLIC HTParentAnchor * HTTmpAnchor (HTUserProfile * up)
149: {
150: static int offset = 0; /* Just keep counting... */
151: time_t t = time(NULL);
152: char * tmpfile = HTGetTmpFileName(HTUserProfile_tmp(up));
153: char * tmpurl = HTParse(tmpfile, "file:", PARSE_ALL);
154: if (tmpfile && tmpurl && t >= 0) {
155: char * result;
156: if (!(result = (char *) HT_MALLOC(strlen(tmpurl)+20)))
157: HT_OUTOFMEM("HTTmpAnchor");
2.27 frystyk 158: #ifdef HAVE_LONG_TIME_T
2.23 frystyk 159: sprintf(result, "%s.%ld.%d", tmpurl, t, offset++);
2.27 frystyk 160: #else
161: sprintf(result, "%s.%d.%d", tmpurl, t, offset++);
162: #endif
2.22 frystyk 163: if (APP_TRACE) HTTrace("Tmp Anchor.. With location `%s\'\n", result);
164: return HTAnchor_parent(HTAnchor_findAddress(result));
165: HT_FREE(result);
166: }
167: HT_FREE(tmpfile);
168: HT_FREE(tmpurl);
169: return NULL;
170: }
171:
172: /*
2.19 frystyk 173: ** Standard interface to libwww TRACE messages. Pass this function a
174: ** string of characters and it will set up the appropriate TRACE flags.
175: ** The shortnames for the trace messages are not as intuitive as they
176: ** could be :-(. The string must be null terminated
177: */
178: PUBLIC int HTSetTraceMessageMask (const char * shortnames)
179: {
180: #ifdef WWWTRACE
181: WWWTRACE = 0;
2.24 frystyk 182: if (shortnames && *shortnames) {
2.21 frystyk 183: char * ptr = (char *) shortnames;
184: for(; *ptr; ptr++) {
2.19 frystyk 185: switch (*ptr) {
2.22 frystyk 186: case 'f': WWWTRACE |= SHOW_UTIL_TRACE; break;
187: case 'l': WWWTRACE |= SHOW_APP_TRACE; break;
2.19 frystyk 188: case 'c': WWWTRACE |= SHOW_CACHE_TRACE; break;
189: case 'g': WWWTRACE |= SHOW_SGML_TRACE; break;
2.22 frystyk 190: case 'b': WWWTRACE |= SHOW_BIND_TRACE; break;
191: case 't': WWWTRACE |= SHOW_THREAD_TRACE; break;
192: case 's': WWWTRACE |= SHOW_STREAM_TRACE; break;
193: case 'p': WWWTRACE |= SHOW_PROTOCOL_TRACE; break;
194: case 'm': WWWTRACE |= SHOW_MEM_TRACE; break;
2.28 frystyk 195: case 'q': WWWTRACE |= SHOW_SQL_TRACE; break;
2.22 frystyk 196: case 'u': WWWTRACE |= SHOW_URI_TRACE; break;
2.19 frystyk 197: case 'h': WWWTRACE |= SHOW_AUTH_TRACE; break;
2.22 frystyk 198: case 'a': WWWTRACE |= SHOW_ANCHOR_TRACE; break;
2.19 frystyk 199: case 'i': WWWTRACE |= SHOW_PICS_TRACE; break;
200: case 'o': WWWTRACE |= SHOW_CORE_TRACE; break;
2.26 frystyk 201: case 'x': WWWTRACE |= SHOW_MUX_TRACE; break;
2.19 frystyk 202: default:
203: if (WWWTRACE) HTTrace("Trace....... Bad argument\n");
204: }
205: }
2.20 frystyk 206: if (!WWWTRACE) WWWTRACE = SHOW_ALL_TRACE;
2.25 frystyk 207: } else {
208: WWWTRACE = SHOW_ALL_TRACE;
2.19 frystyk 209: }
210: return WWWTRACE;
211: #else
212: return 0;
213: #endif
2.1 frystyk 214: }
Webmaster