Annotation of libwww/Library/src/HTHome.c, revision 2.29
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.29 ! frystyk 6: ** @(#) $Id: HTHome.c,v 2.28 1998/05/19 16:49:30 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.29 ! frystyk 46: char wd[HT_MAX_PATH+1];
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';
! 59: return result ? HTLocalToWWW(result) : NULL;
2.1 frystyk 60: }
61:
62:
63: /* Generate the anchor for the home page
64: ** -------------------------------------
65: **
66: ** As it involves file access, this should only be done once
67: ** when the program first runs.
68: ** This is a default algorithm -- browser don't HAVE to use this.
69: ** But consistency betwen browsers is STRONGLY recommended!
70: **
71: ** Priority order is:
72: **
73: ** 1 WWW_HOME environment variable (logical name, etc)
74: ** 2 ~/WWW/default.html
75: ** 3 /usr/local/bin/default.html
76: ** 4 http://www.w3.org/default.html
77: **
78: */
79: PUBLIC HTParentAnchor * HTHomeAnchor (void)
80: {
81: char * my_home_document = NULL;
82: char * home = (char *) getenv(LOGICAL_DEFAULT);
83: char * ref;
84: HTParentAnchor * anchor;
85:
86: /* Someone telnets in, they get a special home */
87: if (home) {
88: StrAllocCopy(my_home_document, home);
89: } else if (HTLib_secure()) { /* Telnet server */
90: FILE * fp = fopen(REMOTE_POINTER, "r");
91: char * status;
92: if (fp) {
2.10 frystyk 93: if ((my_home_document = (char *) HT_MALLOC(HT_MAX_PATH)) == NULL)
94: HT_OUTOFMEM("my_home_document ");
2.1 frystyk 95: status = fgets(my_home_document, HT_MAX_PATH, fp);
96: if (!status) {
2.10 frystyk 97: HT_FREE(my_home_document);
2.1 frystyk 98: my_home_document = NULL;
99: }
100: fclose(fp);
101: }
102: if (!my_home_document) StrAllocCopy(my_home_document, REMOTE_ADDRESS);
103: }
104:
105: if (!my_home_document) {
106: FILE * fp = NULL;
107: char * home = (char *) getenv("HOME");
108: if (home) {
2.10 frystyk 109: if ((my_home_document = (char *) HT_MALLOC(strlen(home)+1+ strlen(PERSONAL_DEFAULT)+1)) == NULL)
110: HT_OUTOFMEM("HTLocalName");
2.1 frystyk 111: sprintf(my_home_document, "%s/%s", home, PERSONAL_DEFAULT);
112: fp = fopen(my_home_document, "r");
113: }
114:
115: if (!fp) {
116: StrAllocCopy(my_home_document, LOCAL_DEFAULT_FILE);
117: fp = fopen(my_home_document, "r");
118: }
119: if (fp) {
120: fclose(fp);
121: } else {
122: if (WWWTRACE)
2.12 frystyk 123: HTTrace("Home Anchor. No local home document in ~/%s or %s\n",
2.1 frystyk 124: PERSONAL_DEFAULT, LOCAL_DEFAULT_FILE);
2.10 frystyk 125: HT_FREE(my_home_document);
2.1 frystyk 126: my_home_document = NULL;
127: }
128: }
2.12 frystyk 129:
2.1 frystyk 130: ref = HTParse(my_home_document ? my_home_document :
131: HTLib_secure() ? REMOTE_ADDRESS : LAST_RESORT, "file:",
132: PARSE_ACCESS|PARSE_HOST|PARSE_PATH|PARSE_PUNCTUATION);
133: if (my_home_document) {
134: if (WWWTRACE)
2.12 frystyk 135: HTTrace("Home Anchor. `%s\' used for custom home page as\n`%s\'\n",
2.1 frystyk 136: my_home_document, ref);
2.10 frystyk 137: HT_FREE(my_home_document);
2.1 frystyk 138: }
139: anchor = (HTParentAnchor*) HTAnchor_findAddress(ref);
2.10 frystyk 140: HT_FREE(ref);
2.1 frystyk 141: return anchor;
2.19 frystyk 142: }
143:
144: /*
2.22 frystyk 145: ** Creates a temporary anchor that doesn't exist
146: */
147: PUBLIC HTParentAnchor * HTTmpAnchor (HTUserProfile * up)
148: {
149: static int offset = 0; /* Just keep counting... */
150: time_t t = time(NULL);
151: char * tmpfile = HTGetTmpFileName(HTUserProfile_tmp(up));
152: char * tmpurl = HTParse(tmpfile, "file:", PARSE_ALL);
153: if (tmpfile && tmpurl && t >= 0) {
154: char * result;
155: if (!(result = (char *) HT_MALLOC(strlen(tmpurl)+20)))
156: HT_OUTOFMEM("HTTmpAnchor");
2.27 frystyk 157: #ifdef HAVE_LONG_TIME_T
2.23 frystyk 158: sprintf(result, "%s.%ld.%d", tmpurl, t, offset++);
2.27 frystyk 159: #else
160: sprintf(result, "%s.%d.%d", tmpurl, t, offset++);
161: #endif
2.22 frystyk 162: if (APP_TRACE) HTTrace("Tmp Anchor.. With location `%s\'\n", result);
163: return HTAnchor_parent(HTAnchor_findAddress(result));
164: HT_FREE(result);
165: }
166: HT_FREE(tmpfile);
167: HT_FREE(tmpurl);
168: return NULL;
169: }
170:
171: /*
2.19 frystyk 172: ** Standard interface to libwww TRACE messages. Pass this function a
173: ** string of characters and it will set up the appropriate TRACE flags.
174: ** The shortnames for the trace messages are not as intuitive as they
175: ** could be :-(. The string must be null terminated
176: */
177: PUBLIC int HTSetTraceMessageMask (const char * shortnames)
178: {
179: #ifdef WWWTRACE
180: WWWTRACE = 0;
2.24 frystyk 181: if (shortnames && *shortnames) {
2.21 frystyk 182: char * ptr = (char *) shortnames;
183: for(; *ptr; ptr++) {
2.19 frystyk 184: switch (*ptr) {
2.22 frystyk 185: case 'f': WWWTRACE |= SHOW_UTIL_TRACE; break;
186: case 'l': WWWTRACE |= SHOW_APP_TRACE; break;
2.19 frystyk 187: case 'c': WWWTRACE |= SHOW_CACHE_TRACE; break;
188: case 'g': WWWTRACE |= SHOW_SGML_TRACE; break;
2.22 frystyk 189: case 'b': WWWTRACE |= SHOW_BIND_TRACE; break;
190: case 't': WWWTRACE |= SHOW_THREAD_TRACE; break;
191: case 's': WWWTRACE |= SHOW_STREAM_TRACE; break;
192: case 'p': WWWTRACE |= SHOW_PROTOCOL_TRACE; break;
193: case 'm': WWWTRACE |= SHOW_MEM_TRACE; break;
2.28 frystyk 194: case 'q': WWWTRACE |= SHOW_SQL_TRACE; break;
2.22 frystyk 195: case 'u': WWWTRACE |= SHOW_URI_TRACE; break;
2.19 frystyk 196: case 'h': WWWTRACE |= SHOW_AUTH_TRACE; break;
2.22 frystyk 197: case 'a': WWWTRACE |= SHOW_ANCHOR_TRACE; break;
2.19 frystyk 198: case 'i': WWWTRACE |= SHOW_PICS_TRACE; break;
199: case 'o': WWWTRACE |= SHOW_CORE_TRACE; break;
2.26 frystyk 200: case 'x': WWWTRACE |= SHOW_MUX_TRACE; break;
2.19 frystyk 201: default:
202: if (WWWTRACE) HTTrace("Trace....... Bad argument\n");
203: }
204: }
2.20 frystyk 205: if (!WWWTRACE) WWWTRACE = SHOW_ALL_TRACE;
2.25 frystyk 206: } else {
207: WWWTRACE = SHOW_ALL_TRACE;
2.19 frystyk 208: }
209: return WWWTRACE;
210: #else
211: return 0;
212: #endif
2.1 frystyk 213: }
Webmaster