Annotation of libwww/Library/src/HTFile.c, revision 1.133.2.4
1.72 frystyk 1: /* HTFile.c
2: ** FILE ACCESS
3: **
1.79 frystyk 4: ** (c) COPYRIGHT MIT 1995.
1.72 frystyk 5: ** Please first read the full copyright statement in the file COPYRIGH.
1.133.2.4! eric 6: ** @(#) $Id: HTFile.c,v 1.133.2.3 1996/11/06 00:38:38 frystyk Exp $
1.1 timbl 7: **
8: ** This is unix-specific code in general, with some VMS bits.
1.8 timbl 9: ** These are routines for file access used by browsers.
1.1 timbl 10: **
11: ** History:
12: ** Feb 91 Written Tim Berners-Lee CERN/CN
13: ** Apr 91 vms-vms access included using DECnet syntax
14: ** 26 Jun 92 (JFG) When running over DECnet, suppressed FTP.
15: ** Fixed access bug for relative names on VMS.
1.28 duns 16: ** Sep 93 (MD) Access to VMS files allows sharing.
17: ** 15 Nov 93 (MD) Moved HTVMSname to HTVMSUTILS.C
1.52 duns 18: ** 22 Feb 94 (MD) Excluded two routines if we are not READING directories
1.61 frystyk 19: ** 18 May 94 (HF) Directory stuff removed and stream handling updated,
20: ** error messages introduced etc.
1.120 frystyk 21: ** HFN Separated transport
1.1 timbl 22: **
23: ** Bugs:
1.2 timbl 24: ** FTP: Cannot access VMS files from a unix machine.
25: ** How can we know that the
1.1 timbl 26: ** target machine runs VMS?
27: */
28:
1.67 frystyk 29: /* Library Includes */
1.112 frystyk 30: #include "sysdep.h"
1.120 frystyk 31: #include "WWWUtil.h"
32: #include "WWWCore.h"
1.124 frystyk 33: #include "WWWDir.h"
34: #include "WWWTrans.h"
1.126 frystyk 35: #include "HTNetMan.h"
1.120 frystyk 36: #include "HTReqMan.h"
1.124 frystyk 37: #include "HTMulti.h"
1.67 frystyk 38: #include "HTFile.h" /* Implemented here */
39:
1.91 frystyk 40: /* Final states have negative value */
1.80 frystyk 41: typedef enum _FileState {
1.95 frystyk 42: FS_RETRY = -4,
43: FS_ERROR = -3,
44: FS_NO_DATA = -2,
45: FS_GOT_DATA = -1,
46: FS_BEGIN = 0,
47: FS_DO_CN,
48: FS_NEED_OPEN_FILE,
49: FS_NEED_BODY,
50: FS_PARSE_DIR,
51: FS_TRY_FTP
1.80 frystyk 52: } FileState;
53:
1.91 frystyk 54: /* This is the context structure for the this module */
1.77 frystyk 55: typedef struct _file_info {
1.80 frystyk 56: FileState state; /* Current state of the connection */
1.95 frystyk 57: char * local; /* Local representation of file name */
1.125 frystyk 58: struct stat stat_info; /* Contains actual file chosen */
1.133.2.1 eric 59: HTNet * net;
1.77 frystyk 60: } file_info;
1.2 timbl 61:
1.80 frystyk 62: struct _HTStream {
1.112 frystyk 63: const HTStreamClass * isa;
1.80 frystyk 64: };
65:
1.120 frystyk 66: struct _HTInputStream {
67: const HTInputStreamClass * isa;
68: };
69:
1.123 frystyk 70: #if 0
1.95 frystyk 71: PRIVATE BOOL HTTakeBackup = YES;
1.123 frystyk 72: #endif
1.1 timbl 73:
1.95 frystyk 74: PRIVATE HTDirReadme dir_readme = HT_DIR_README_TOP;
75: PRIVATE HTDirAccess dir_access = HT_DIR_OK;
76: PRIVATE HTDirShow dir_show = HT_DS_SIZE+HT_DS_DATE+HT_DS_DES+HT_DS_ICON;
77: PRIVATE HTDirKey dir_key = HT_DK_CINS;
1.2 timbl 78:
1.61 frystyk 79: /* ------------------------------------------------------------------------- */
1.11 timbl 80:
1.95 frystyk 81: /* Directory Access
82: ** ----------------
83: */
84: PUBLIC BOOL HTFile_setDirAccess (HTDirAccess mode)
85: {
86: dir_access = mode;
87: return YES;
88: }
89:
90: PUBLIC HTDirAccess HTFile_dirAccess (void)
91: {
92: return dir_access;
93: }
94:
95: /* Directory Readme
96: ** ----------------
97: */
98: PUBLIC BOOL HTFile_setDirReadme (HTDirReadme mode)
99: {
100: dir_readme = mode;
101: return YES;
102: }
103:
104: PUBLIC HTDirReadme HTFile_dirReadme (void)
105: {
106: return dir_readme;
107: }
108:
109: /* HTFile_readDir
110: ** --------------
111: ** Reads the directory "path"
112: ** Returns:
113: ** HT_ERROR Error
1.107 frystyk 114: ** HT_FORBIDDEN Directory reading not allowed
1.95 frystyk 115: ** HT_LOADED Successfully read the directory
1.1 timbl 116: */
1.95 frystyk 117: PRIVATE int HTFile_readDir (HTRequest * request, file_info *file)
1.1 timbl 118: {
1.112 frystyk 119: #ifdef HAVE_READDIR
120: DIR * dp;
1.95 frystyk 121: struct stat file_info;
1.124 frystyk 122: HTParentAnchor * anchor = HTRequest_anchor(request);
123: char *url = HTAnchor_physical(anchor);
1.95 frystyk 124: char fullname[HT_MAX_PATH+1];
125: char *name;
1.111 eric 126: if (PROT_TRACE) HTTrace("Reading..... directory\n");
1.95 frystyk 127: if (dir_access == HT_DIR_FORBID) {
1.100 frystyk 128: HTRequest_addError(request, ERR_FATAL, NO, HTERR_FORBIDDEN,
1.95 frystyk 129: NULL, 0, "HTFile_readDir");
1.107 frystyk 130: return HT_FORBIDDEN;
1.95 frystyk 131: }
132:
133: /* Initialize path name for stat() */
134: if (*(name = (url+strlen(url)-1)) != '/') {
135: char *newurl = NULL;
136: StrAllocCopy(newurl, url);
137: StrAllocCat(newurl, "/");
1.110 frystyk 138: HT_FREE(file->local);
1.123 frystyk 139: file->local = HTWWWToLocal(newurl, "", HTRequest_userProfile(request));
1.110 frystyk 140: HT_FREE(newurl);
1.95 frystyk 141: }
142: strcpy(fullname, file->local);
143: name = fullname+strlen(fullname); /* Point to end of fullname */
144:
145: /* Check if access is enabled */
146: if (dir_access == HT_DIR_SELECTIVE) {
147: strcpy(name, DEFAULT_DIR_FILE);
148: if (HT_STAT(fullname, &file_info)) {
1.80 frystyk 149: if (PROT_TRACE)
1.111 eric 150: HTTrace(
1.95 frystyk 151: "Read dir.... `%s\' not found\n", DEFAULT_DIR_FILE);
1.100 frystyk 152: HTRequest_addError(request, ERR_FATAL, NO, HTERR_FORBIDDEN,
1.95 frystyk 153: NULL, 0, "HTFile_readDir");
1.107 frystyk 154: return HT_FORBIDDEN;
1.1 timbl 155: }
156: }
157:
1.95 frystyk 158: if ((dp = opendir(file->local))) {
1.112 frystyk 159: struct dirent * dirbuf;
1.95 frystyk 160: HTDir *dir = HTDir_new(request, dir_show, dir_key);
161: char datestr[20];
162: char sizestr[10];
163: HTFileMode mode;
164: #ifdef HT_REENTRANT
1.130 frystyk 165: struct dirent result; /* For readdir_r */
1.129 frystyk 166: while ((dirbuf = (struct dirent *) readdir_r(dp, &result)))
1.95 frystyk 167: #else
168: while ((dirbuf = readdir(dp)))
169: #endif /* HT_REENTRANT */
170: {
171: /* Current and parent directories are never shown in list */
1.112 frystyk 172: #ifdef HAVE_DIRENT_INO
1.95 frystyk 173: if (!dirbuf->d_ino ||
174: !strcmp(dirbuf->d_name, ".") || !strcmp(dirbuf->d_name, ".."))
1.112 frystyk 175: #else
176: if (!strcmp(dirbuf->d_name, ".") || !strcmp(dirbuf->d_name, ".."))
177: #endif
1.95 frystyk 178: continue;
179:
180: /* Make a lstat on the file */
181: strcpy(name, dirbuf->d_name);
182: if (HT_LSTAT(fullname, &file_info)) {
183: if (PROT_TRACE)
1.111 eric 184: HTTrace("Read dir.... lstat failed: %s\n",fullname);
1.95 frystyk 185: continue;
186: }
1.1 timbl 187:
1.95 frystyk 188: /* Convert stat info to fit our setup */
1.103 frystyk 189: if (((mode_t) file_info.st_mode & S_IFMT) == S_IFDIR) {
1.95 frystyk 190: #ifdef VMS
191: char *dot = strstr(name, ".DIR"); /* strip .DIR part... */
192: if (dot) *dot = '\0';
193: #endif /* VMS */
194: mode = HT_IS_DIR;
195: if (dir_show & HT_DS_SIZE) strcpy(sizestr, "-");
196: } else {
197: mode = HT_IS_FILE;
198: if (dir_show & HT_DS_SIZE)
199: HTNumToStr(file_info.st_size, sizestr, 10);
200: }
201: if (dir_show & HT_DS_DATE)
202: HTDateDirStr(&file_info.st_mtime, datestr, 20);
1.1 timbl 203:
1.95 frystyk 204: /* Add to the list */
205: if (HTDir_addElement(dir, name, datestr, sizestr, mode) != YES)
206: break;
207: }
208: closedir(dp);
209: HTDir_free(dir);
1.127 frystyk 210: return HT_LOADED;
211: } else {
1.100 frystyk 212: HTRequest_addSystemError(request, ERR_FATAL, errno, NO, "opendir");
1.127 frystyk 213: return HT_ERROR;
214: }
1.112 frystyk 215: #else
1.114 eric 216: return HT_ERROR; /* needed for WWW_MSWINDOWS */
1.112 frystyk 217: #endif /* HAVE_READDIR */
1.1 timbl 218: }
219:
220: /* Determine write access to a file
1.2 timbl 221: ** --------------------------------
1.80 frystyk 222: ** If stat_info is NULL then the function calls stat() on it's own,
223: ** otherwise it uses the information found in stat_info
1.2 timbl 224: ** On exit,
225: ** return value YES if file can be accessed and can be written to.
226: **
227: ** Bugs:
228: ** 1. No code for non-unix systems.
229: ** 2. Isn't there a quicker way?
1.1 timbl 230: */
1.112 frystyk 231: PRIVATE BOOL HTEditable (const char * filename, struct stat * stat_info)
1.80 frystyk 232: {
1.112 frystyk 233: #ifdef GETGROUPS_T
1.80 frystyk 234: int i;
235: uid_t myUid;
236: int ngroups; /* The number of groups */
1.1 timbl 237: struct stat fileStatus;
1.80 frystyk 238: struct stat *fileptr = stat_info ? stat_info : &fileStatus;
1.112 frystyk 239: GETGROUPS_T groups[NGROUPS];
1.80 frystyk 240: if (!stat_info) {
1.90 frystyk 241: if (HT_STAT(filename, &fileStatus))
1.80 frystyk 242: return NO; /* Can't even access file! */
243: }
1.1 timbl 244: ngroups = getgroups(NGROUPS, groups); /* Groups to which I belong */
245: myUid = geteuid(); /* Get my user identifier */
246:
1.95 frystyk 247: if (PROT_TRACE) {
1.1 timbl 248: int i;
1.111 eric 249: HTTrace(
1.19 timbl 250: "File mode is 0%o, uid=%d, gid=%d. My uid=%d, %d groups (",
1.80 frystyk 251: (unsigned int) fileptr->st_mode, (int) fileptr->st_uid,
252: (int) fileptr->st_gid, (int) myUid, ngroups);
1.111 eric 253: for (i=0; i<ngroups; i++) HTTrace(" %d", (int) groups[i]);
254: HTTrace(")\n");
1.1 timbl 255: }
256:
1.80 frystyk 257: if (fileptr->st_mode & 0002) /* I can write anyway? */
1.1 timbl 258: return YES;
259:
1.80 frystyk 260: if ((fileptr->st_mode & 0200) /* I can write my own file? */
261: && (fileptr->st_uid == myUid))
1.1 timbl 262: return YES;
263:
1.80 frystyk 264: if (fileptr->st_mode & 0020) /* Group I am in can write? */
1.1 timbl 265: {
266: for (i=0; i<ngroups; i++) {
1.80 frystyk 267: if (groups[i] == fileptr->st_gid)
1.1 timbl 268: return YES;
269: }
270: }
1.111 eric 271: if (PROT_TRACE) HTTrace("\tFile is not editable.\n");
1.1 timbl 272: return NO; /* If no excuse, can't do */
1.80 frystyk 273: #else
274: /*
275: ** We don't know and can't find out. Can we be sure that when opening
276: ** a file in mode "a" that the file is not modified?
277: */
278: return NO;
1.112 frystyk 279: #endif /* GETGROUPS_T */
1.1 timbl 280: }
1.80 frystyk 281:
1.91 frystyk 282: /* FileCleanup
283: ** -----------
1.80 frystyk 284: ** This function closes the connection and frees memory.
1.91 frystyk 285: ** Returns YES on OK, else NO
1.80 frystyk 286: */
1.91 frystyk 287: PRIVATE int FileCleanup (HTRequest *req, int status)
1.80 frystyk 288: {
1.126 frystyk 289: HTNet * net = HTRequest_net(req);
290: file_info * file = (file_info *) HTNet_context(net);
291: HTStream * input = HTRequest_inputStream(req);
1.106 frystyk 292:
293: /* Free stream with data TO Local file system */
1.107 frystyk 294: if (HTRequest_isDestination(req))
295: HTRequest_removeDestination(req);
1.126 frystyk 296: else if (input) {
1.106 frystyk 297: if (status == HT_INTERRUPTED)
1.126 frystyk 298: (*input->isa->abort)(input, NULL);
1.106 frystyk 299: else
1.126 frystyk 300: (*input->isa->_free)(input);
301: HTRequest_setInputStream(req, NULL);
1.106 frystyk 302: }
303:
1.91 frystyk 304: if (file) {
1.110 frystyk 305: HT_FREE(file->local);
306: HT_FREE(file);
1.80 frystyk 307: }
1.128 frystyk 308: HTNet_delete(net, status);
1.91 frystyk 309: return YES;
1.80 frystyk 310: }
311:
312:
1.1 timbl 313: /* Load a document
314: ** ---------------
315: **
316: ** On entry,
1.80 frystyk 317: ** request This is the request structure
1.1 timbl 318: ** On exit,
1.91 frystyk 319: ** returns HT_ERROR Error has occured in call back
320: ** HT_OK Call back was OK
1.1 timbl 321: */
1.133.2.2 eric 322: PRIVATE int FileEvent (SOCKET soc, void * pVoid, HTEventType type);
1.133.2.1 eric 323:
324: PUBLIC int HTLoadFile (SOCKET soc, HTRequest * request)
1.1 timbl 325: {
1.133.2.1 eric 326: file_info *file; /* Specific access information */
1.124 frystyk 327: HTNet * net = HTRequest_net(request);
328: HTParentAnchor * anchor = HTRequest_anchor(request);
1.133.2.1 eric 329:
330: if (PROT_TRACE) HTTrace("HTLoadFile.. Looking for `%s\'\n",
331: HTAnchor_physical(anchor));
332: if ((file = (file_info *) HT_CALLOC(1, sizeof(file_info))) == NULL)
333: HT_OUTOFMEM("HTLoadFILE");
334: file->state = FS_BEGIN;
335: file->net = net;
336: HTNet_setContext(net, file);
337: HTNet_setEventCallback(net, FileEvent);
338: HTNet_setEventParam(net, file); /* callbacks get http* */
339:
1.133.2.3 frystyk 340: return FileEvent(soc, file, HTEvent_BEGIN); /* get it started - ops is ignored */
1.133.2.1 eric 341: }
342:
1.133.2.2 eric 343: PRIVATE int FileEvent (SOCKET soc, void * pVoid, HTEventType type)
1.133.2.1 eric 344: {
1.133.2.4! eric 345: file_info *file = pVoid; /* Specific access information */
1.133.2.1 eric 346: int status = HT_ERROR;
347: HTNet * net = file->net;
348: HTRequest * request = HTNet_request(net);
349: HTParentAnchor * anchor = HTRequest_anchor(request);
1.45 luotonen 350:
1.91 frystyk 351: /*
352: ** Initiate a new file structure and bind to request structure
353: ** This is actually state FILE_BEGIN, but it can't be in the state
354: ** machine as we need the structure first.
355: */
1.133.2.1 eric 356: if (type == HTEvent_CLOSE) { /* Interrupted */
1.107 frystyk 357: HTRequest_addError(request, ERR_FATAL, NO, HTERR_INTERRUPTED,
1.131 frystyk 358: NULL, 0, "HTLoadFile");
1.107 frystyk 359: FileCleanup(request, HT_INTERRUPTED);
1.91 frystyk 360: return HT_OK;
1.133.2.4! eric 361: }
! 362:
1.36 luotonen 363:
1.80 frystyk 364: /* Now jump into the machine. We know the state from the previous run */
365: while (1) {
366: switch (file->state) {
1.95 frystyk 367: case FS_BEGIN:
1.102 frystyk 368: if (HTLib_secure()) {
1.80 frystyk 369: if (PROT_TRACE)
1.111 eric 370: HTTrace("LoadFile.... No access to local file system\n");
1.95 frystyk 371: file->state = FS_TRY_FTP;
1.80 frystyk 372: break;
373: }
1.123 frystyk 374: file->local = HTWWWToLocal(HTAnchor_physical(anchor), "",
375: HTRequest_userProfile(request));
1.95 frystyk 376: if (!file->local) {
377: file->state = FS_TRY_FTP;
1.80 frystyk 378: break;
1.2 timbl 379: }
1.125 frystyk 380: file->state = FS_DO_CN;
1.86 frystyk 381: break;
382:
1.95 frystyk 383: case FS_DO_CN:
1.80 frystyk 384: /*
385: ** If we have to do content negotiation then find the object that
386: ** fits best into either what the client has indicated in the
1.86 frystyk 387: ** accept headers or what the client has registered on its own.
1.80 frystyk 388: ** The object chosen can in fact be a directory! However, content
1.133.2.1 eric 389: ** negotiation only makes sense if we can read the directory!
1.80 frystyk 390: ** We stat the file in order to find the size and to see it if
391: ** exists.
392: */
1.132 frystyk 393: if (HTRequest_negotiation(request) &&
394: HTMethod_isSafe(HTRequest_method(request))) {
1.125 frystyk 395: char * conneg = HTMulti(request, file->local,&file->stat_info);
396: if (conneg) {
397: HT_FREE(file->local);
398: file->local = conneg;
399: HTAnchor_setPhysical(anchor, conneg);
400: if (PROT_TRACE)
401: HTTrace("Load File... Found `%s\'\n", conneg);
1.80 frystyk 402: } else {
1.125 frystyk 403: if (PROT_TRACE)
404: HTTrace("Load File... Not found - even tried content negotiation\n");
1.126 frystyk 405: HTRequest_addError(request, ERR_INFO, NO, HTERR_NOT_FOUND,
406: NULL, 0, "HTLoadFile");
1.125 frystyk 407: file->state = FS_ERROR;
408: break;
1.80 frystyk 409: }
1.125 frystyk 410: } else {
411: if (HT_STAT(file->local, &file->stat_info) == -1) {
412: if (PROT_TRACE)
413: HTTrace("Load.File... Not found `%s\'\n", file->local);
414: HTRequest_addError(request, ERR_FATAL, NO, HTERR_NOT_FOUND,
415: NULL, 0, "HTLoadFile");
416: file->state = FS_ERROR;
417: break;
1.80 frystyk 418: }
1.125 frystyk 419: }
420:
421: /*
422: ** Check to see if the 'localname' is in fact a directory
423: */
424: if (((file->stat_info.st_mode) & S_IFMT) == S_IFDIR) {
425: file->state = FS_PARSE_DIR;
426: break;
427: }
428:
429: /*
1.132 frystyk 430: ** If empty file then only serve it if it is editable. We also get
431: ** the bindings for the file suffixes in lack of better bindings
1.125 frystyk 432: */
433: {
434: BOOL editable = HTEditable(file->local, &file->stat_info);
1.133 frystyk 435: HTBind_getAnchorBindings(anchor);
436: if (editable) HTAnchor_appendAllow(anchor, METHOD_PUT);
1.125 frystyk 437: if (file->stat_info.st_size)
438: HTAnchor_setLength(anchor, file->stat_info.st_size);
439: if (!editable && !file->stat_info.st_size) {
440: HTRequest_addError(request, ERR_FATAL,NO,HTERR_NO_CONTENT,
441: NULL, 0, "HTLoadFile");
442: file->state = FS_NO_DATA;
443: } else
444: file->state = FS_NEED_OPEN_FILE;
1.2 timbl 445: }
1.80 frystyk 446: break;
1.61 frystyk 447:
1.95 frystyk 448: case FS_NEED_OPEN_FILE:
1.120 frystyk 449: status = HTFileOpen(net, file->local, HT_FT_RDONLY);
450: if (status == HT_OK) {
451: /*
452: ** Create the stream pipe FROM the channel to the application.
453: ** The target for the input stream pipe is set up using the
1.132 frystyk 454: ** stream stack.
1.120 frystyk 455: */
1.133.2.1 eric 456: net->readStream = HTStreamStack(HTAnchor_format(anchor),
457: HTRequest_outputFormat(request),
458: HTRequest_outputStream(request),
459: request, YES);
1.126 frystyk 460: HTRequest_setOutputConnected(request, YES);
461:
1.120 frystyk 462: /*
463: ** Create the stream pipe TO the channel from the application
464: ** and hook it up to the request object
465: */
466: {
467: HTOutputStream * output = HTNet_getOutput(net, NULL, 0);
468: HTRequest_setInputStream(request, (HTStream *) output);
469: }
1.80 frystyk 470:
1.120 frystyk 471: /*
472: ** Set up concurrent read/write if this request isn't the
473: ** source for a PUT or POST. As source we don't start reading
474: ** before all destinations are ready. If destination then
475: ** register the input stream and get ready for read
476: */
477: if (HTRequest_isDestination(request)) {
1.133.2.1 eric 478: HTEvent_register(HTNet_socket(net), HTEvent_READ, &net->event);
1.120 frystyk 479: HTRequest_linkDestination(request);
1.82 frystyk 480: }
1.120 frystyk 481: if (HTRequest_isSource(request) &&
482: !HTRequest_destinationsReady(request))
483: return HT_OK;
1.126 frystyk 484: HTRequest_addError(request, ERR_INFO, NO, HTERR_OK,
485: NULL, 0, "HTLoadFile");
1.120 frystyk 486: file->state = FS_NEED_BODY;
1.106 frystyk 487:
1.116 frystyk 488: #ifndef NO_UNIX_IO
1.120 frystyk 489: /* If we are _not_ using preemptive mode and we are Unix fd's
490: ** then return here to get the same effect as when we are
491: ** connecting to a socket. That way, HTFile acts just like any
492: ** other protocol module even though we are in fact doing
493: ** blocking connect
494: */
495: if (!net->preemptive) {
496: if (PROT_TRACE) HTTrace("HTLoadFile.. returning\n");
1.133.2.1 eric 497: HTEvent_register(HTNet_socket(net), HTEvent_READ, &net->event);
1.132 frystyk 498: return HT_OK;
1.120 frystyk 499: }
1.116 frystyk 500: #endif
1.131 frystyk 501: } else if (status == HT_WOULD_BLOCK || status == HT_PENDING)
1.120 frystyk 502: return HT_OK;
1.126 frystyk 503: else {
504: HTRequest_addError(request, ERR_INFO, NO, HTERR_INTERNAL,
505: NULL, 0, "HTLoadFile");
1.120 frystyk 506: file->state = FS_ERROR; /* Error or interrupt */
1.126 frystyk 507: }
1.107 frystyk 508: break;
1.82 frystyk 509:
1.95 frystyk 510: case FS_NEED_BODY:
1.133.2.1 eric 511: status = HTHost_read(net->host);
1.80 frystyk 512: if (status == HT_WOULD_BLOCK)
1.91 frystyk 513: return HT_OK;
1.108 frystyk 514: else if (status == HT_LOADED || status == HT_CLOSED) {
1.95 frystyk 515: file->state = FS_GOT_DATA;
1.126 frystyk 516: } else {
517: HTRequest_addError(request, ERR_INFO, NO, HTERR_FORBIDDEN,
518: NULL, 0, "HTLoadFile");
1.95 frystyk 519: file->state = FS_ERROR;
1.126 frystyk 520: }
1.80 frystyk 521: break;
1.1 timbl 522:
1.95 frystyk 523: case FS_PARSE_DIR:
524: status = HTFile_readDir(request, file);
525: if (status == HT_LOADED)
526: file->state = FS_GOT_DATA;
1.127 frystyk 527: else
1.95 frystyk 528: file->state = FS_ERROR;
1.80 frystyk 529: break;
530:
1.95 frystyk 531: case FS_TRY_FTP:
1.80 frystyk 532: {
1.99 frystyk 533: char *url = HTAnchor_physical(anchor);
1.80 frystyk 534: HTAnchor *anchor;
535: char *newname = NULL;
536: StrAllocCopy(newname, "ftp:");
537: if (!strncmp(url, "file:", 5))
538: StrAllocCat(newname, url+5);
539: else
540: StrAllocCat(newname, url);
541: anchor = HTAnchor_findAddress(newname);
1.109 frystyk 542: HTRequest_setAnchor(request, anchor);
1.110 frystyk 543: HT_FREE(newname);
1.91 frystyk 544: FileCleanup(request, HT_IGNORE);
1.97 frystyk 545: return HTLoad(request, YES);
1.80 frystyk 546: }
547: break;
1.1 timbl 548:
1.95 frystyk 549: case FS_GOT_DATA:
1.83 frystyk 550: if (HTRequest_isPostWeb(request)) {
1.87 frystyk 551: if (HTRequest_isDestination(request)) {
1.124 frystyk 552: HTRequest * source = HTRequest_source(request);
1.87 frystyk 553: HTLink *link =
1.126 frystyk 554: HTLink_find((HTAnchor *)HTRequest_anchor(source),
1.99 frystyk 555: (HTAnchor *) anchor);
1.104 frystyk 556: HTLink_setResult(link, HT_LINK_OK);
1.87 frystyk 557: }
1.107 frystyk 558: }
559: FileCleanup(request, HT_LOADED);
1.91 frystyk 560: return HT_OK;
1.80 frystyk 561: break;
562:
1.95 frystyk 563: case FS_NO_DATA:
1.83 frystyk 564: if (HTRequest_isPostWeb(request)) {
1.87 frystyk 565: if (HTRequest_isDestination(request)) {
1.124 frystyk 566: HTRequest * source = HTRequest_source(request);
1.87 frystyk 567: HTLink *link =
1.126 frystyk 568: HTLink_find((HTAnchor *)HTRequest_anchor(source),
1.99 frystyk 569: (HTAnchor *) anchor);
1.104 frystyk 570: HTLink_setResult(link, HT_LINK_OK);
1.87 frystyk 571: }
1.107 frystyk 572: }
573: FileCleanup(request, HT_NO_DATA);
1.91 frystyk 574: return HT_OK;
1.80 frystyk 575: break;
576:
1.95 frystyk 577: case FS_RETRY:
1.83 frystyk 578: if (HTRequest_isPostWeb(request)) {
1.87 frystyk 579: if (HTRequest_isDestination(request)) {
1.124 frystyk 580: HTRequest * source = HTRequest_source(request);
1.87 frystyk 581: HTLink *link =
1.126 frystyk 582: HTLink_find((HTAnchor *)HTRequest_anchor(source),
1.99 frystyk 583: (HTAnchor *) anchor);
1.104 frystyk 584: HTLink_setResult(link, HT_LINK_ERROR);
1.87 frystyk 585: }
1.107 frystyk 586: HTRequest_killPostWeb(request);
587: }
588: FileCleanup(request, HT_RETRY);
1.91 frystyk 589: return HT_OK;
1.80 frystyk 590: break;
591:
1.95 frystyk 592: case FS_ERROR:
1.83 frystyk 593: if (HTRequest_isPostWeb(request)) {
1.87 frystyk 594: if (HTRequest_isDestination(request)) {
1.124 frystyk 595: HTRequest * source = HTRequest_source(request);
1.87 frystyk 596: HTLink *link =
1.126 frystyk 597: HTLink_find((HTAnchor *)HTRequest_anchor(source),
1.99 frystyk 598: (HTAnchor *) anchor);
1.104 frystyk 599: HTLink_setResult(link, HT_LINK_ERROR);
1.87 frystyk 600: }
1.107 frystyk 601: HTRequest_killPostWeb(request);
602: }
603: FileCleanup(request, HT_ERROR);
1.91 frystyk 604: return HT_OK;
1.80 frystyk 605: break;
606: }
607: } /* End of while(1) */
1.1 timbl 608: }
Webmaster