Annotation of libwww/Library/src/HTHome.c, revision 2.35
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.35 ! frystyk 6: ** @(#) $Id: HTHome.c,v 2.34 1999/02/22 22:10:11 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.32 frystyk 60: return result ? HTLocalToWWW(result, NULL) : 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 {
2.34 frystyk 123: HTTRACE(APP_TRACE, "Home Anchor. No local home document in ~/%s or %s\n" _
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) {
2.34 frystyk 134: HTTRACE(APP_TRACE, "Home Anchor. `%s\' used for custom home page as\n`%s\'\n" _
135: my_home_document _ ref);
2.10 frystyk 136: HT_FREE(my_home_document);
2.1 frystyk 137: }
138: anchor = (HTParentAnchor*) HTAnchor_findAddress(ref);
2.10 frystyk 139: HT_FREE(ref);
2.1 frystyk 140: return anchor;
2.19 frystyk 141: }
142:
143: /*
2.22 frystyk 144: ** Creates a temporary anchor that doesn't exist
145: */
146: PUBLIC HTParentAnchor * HTTmpAnchor (HTUserProfile * up)
147: {
148: static int offset = 0; /* Just keep counting... */
149: time_t t = time(NULL);
150: char * tmpfile = HTGetTmpFileName(HTUserProfile_tmp(up));
151: char * tmpurl = HTParse(tmpfile, "file:", PARSE_ALL);
152: if (tmpfile && tmpurl && t >= 0) {
153: char * result;
154: if (!(result = (char *) HT_MALLOC(strlen(tmpurl)+20)))
155: HT_OUTOFMEM("HTTmpAnchor");
2.27 frystyk 156: #ifdef HAVE_LONG_TIME_T
2.23 frystyk 157: sprintf(result, "%s.%ld.%d", tmpurl, t, offset++);
2.27 frystyk 158: #else
159: sprintf(result, "%s.%d.%d", tmpurl, t, offset++);
160: #endif
2.34 frystyk 161: HTTRACE(APP_TRACE, "Tmp Anchor.. With location `%s\'\n" _ result);
2.22 frystyk 162: return HTAnchor_parent(HTAnchor_findAddress(result));
163: HT_FREE(result);
164: }
165: HT_FREE(tmpfile);
166: HT_FREE(tmpurl);
167: return NULL;
168: }
169:
170: /*
2.31 frystyk 171: ** Takes a string of the form "a=b" containing HTML form data, escapes
172: ** it accordingly and puts it into the association list so that it
173: ** readily can be passed to any of the HTAccess function that handles
174: ** HTML form data.
175: */
176: PUBLIC BOOL HTParseFormInput (HTAssocList * list, const char * str)
177: {
178: if (list && str) {
179: char * me = NULL;
180: char * name = NULL;
181: char * value = NULL;
182: StrAllocCopy(me, str);
183: value = strchr(me, '=');
184: if (value)
185: *value++ = '\0';
186: else
187: value = "";
188: name = HTStrip(me);
189:
190: /* Escape the name and value */
191: if (name) {
192: char * escaped_name = HTEscape(name, URL_XALPHAS);
193: char * escaped_value = HTEscape(value, URL_XALPHAS);
2.34 frystyk 194: HTTRACE(APP_TRACE, "Form data... Adding name `%s\' with value `%s\' to %p\n" _
195: escaped_name _ escaped_value _ list);
2.31 frystyk 196: HTAssocList_addObject(list, escaped_name, escaped_value);
197: HT_FREE(escaped_name);
198: HT_FREE(escaped_value);
199: }
200: HT_FREE(me);
201: return YES;
202: }
203: return NO;
204: }
205:
206: /*
2.19 frystyk 207: ** Standard interface to libwww TRACE messages. Pass this function a
208: ** string of characters and it will set up the appropriate TRACE flags.
209: ** The shortnames for the trace messages are not as intuitive as they
210: ** could be :-(. The string must be null terminated
211: */
212: PUBLIC int HTSetTraceMessageMask (const char * shortnames)
213: {
2.35 ! frystyk 214: #if defined(HTDEBUG) && defined(WWWTRACE)
2.19 frystyk 215: WWWTRACE = 0;
2.24 frystyk 216: if (shortnames && *shortnames) {
2.21 frystyk 217: char * ptr = (char *) shortnames;
218: for(; *ptr; ptr++) {
2.19 frystyk 219: switch (*ptr) {
2.22 frystyk 220: case 'f': WWWTRACE |= SHOW_UTIL_TRACE; break;
221: case 'l': WWWTRACE |= SHOW_APP_TRACE; break;
2.19 frystyk 222: case 'c': WWWTRACE |= SHOW_CACHE_TRACE; break;
223: case 'g': WWWTRACE |= SHOW_SGML_TRACE; break;
2.22 frystyk 224: case 'b': WWWTRACE |= SHOW_BIND_TRACE; break;
225: case 't': WWWTRACE |= SHOW_THREAD_TRACE; break;
226: case 's': WWWTRACE |= SHOW_STREAM_TRACE; break;
227: case 'p': WWWTRACE |= SHOW_PROTOCOL_TRACE; break;
228: case 'm': WWWTRACE |= SHOW_MEM_TRACE; break;
2.28 frystyk 229: case 'q': WWWTRACE |= SHOW_SQL_TRACE; break;
2.22 frystyk 230: case 'u': WWWTRACE |= SHOW_URI_TRACE; break;
2.19 frystyk 231: case 'h': WWWTRACE |= SHOW_AUTH_TRACE; break;
2.22 frystyk 232: case 'a': WWWTRACE |= SHOW_ANCHOR_TRACE; break;
2.19 frystyk 233: case 'i': WWWTRACE |= SHOW_PICS_TRACE; break;
234: case 'o': WWWTRACE |= SHOW_CORE_TRACE; break;
2.26 frystyk 235: case 'x': WWWTRACE |= SHOW_MUX_TRACE; break;
2.31 frystyk 236: case '*': WWWTRACE |= SHOW_ALL_TRACE; break;
2.19 frystyk 237: default:
2.34 frystyk 238: if (WWWTRACE) HTTRACE(APP_TRACE, "Trace....... Bad argument\n");
2.19 frystyk 239: }
240: }
2.20 frystyk 241: if (!WWWTRACE) WWWTRACE = SHOW_ALL_TRACE;
2.25 frystyk 242: } else {
243: WWWTRACE = SHOW_ALL_TRACE;
2.19 frystyk 244: }
245: return WWWTRACE;
246: #else
247: return 0;
248: #endif
2.1 frystyk 249: }
Webmaster