1 | /* |
---|
2 | * Page.c -- Support for page retrieval. |
---|
3 | * |
---|
4 | * Copyright (c) Go Ahead Software Inc., 1995-1999. All Rights Reserved. |
---|
5 | * |
---|
6 | * See the file "license.txt" for usage and redistribution license requirements |
---|
7 | */ |
---|
8 | |
---|
9 | /******************************** Description *********************************/ |
---|
10 | |
---|
11 | /* |
---|
12 | * This module provides page retrieval handling. It provides support for |
---|
13 | * reading web pages from file systems and has expansion for ROMed web |
---|
14 | * pages. |
---|
15 | */ |
---|
16 | |
---|
17 | /********************************* Includes ***********************************/ |
---|
18 | |
---|
19 | #include "wsIntrn.h" |
---|
20 | |
---|
21 | /*********************************** Code *************************************/ |
---|
22 | /* |
---|
23 | * Open a web page. lpath is the local filename. path is the URL path name. |
---|
24 | */ |
---|
25 | |
---|
26 | int websPageOpen(webs_t wp, char_t *lpath, char_t *path, int mode, int perm) |
---|
27 | { |
---|
28 | a_assert(websValid(wp)); |
---|
29 | |
---|
30 | #if WEBS_PAGE_ROM |
---|
31 | return websRomPageOpen(wp, path, mode, perm); |
---|
32 | #else |
---|
33 | return (wp->docfd = gopen(lpath, mode, perm)); |
---|
34 | #endif /* WEBS_PAGE_ROM */ |
---|
35 | } |
---|
36 | |
---|
37 | /******************************************************************************/ |
---|
38 | /* |
---|
39 | * Close a web page |
---|
40 | */ |
---|
41 | |
---|
42 | void websPageClose(webs_t wp) |
---|
43 | { |
---|
44 | #if WEBS_PAGE_ROM |
---|
45 | websRomPageClose(wp->docfd); |
---|
46 | #else |
---|
47 | if (wp->docfd >= 0) { |
---|
48 | close(wp->docfd); |
---|
49 | wp->docfd = -1; |
---|
50 | } |
---|
51 | #endif |
---|
52 | } |
---|
53 | |
---|
54 | /******************************************************************************/ |
---|
55 | /* |
---|
56 | * Stat a web page lpath is the local filename. path is the URL path name. |
---|
57 | */ |
---|
58 | |
---|
59 | int websPageStat(webs_t wp, char_t *lpath, char_t *path, websStatType* sbuf) |
---|
60 | { |
---|
61 | #if WEBS_PAGE_ROM |
---|
62 | return websRomPageStat(path, sbuf); |
---|
63 | #else |
---|
64 | gstat_t s; |
---|
65 | |
---|
66 | if (gstat(lpath, &s) < 0) { |
---|
67 | return -1; |
---|
68 | } |
---|
69 | sbuf->size = s.st_size; |
---|
70 | sbuf->mtime = s.st_mtime; |
---|
71 | sbuf->isDir = s.st_mode & S_IFDIR; |
---|
72 | return 0; |
---|
73 | #endif |
---|
74 | } |
---|
75 | |
---|
76 | /******************************************************************************/ |
---|
77 | /* |
---|
78 | * Is this file a directory? |
---|
79 | */ |
---|
80 | |
---|
81 | int websPageIsDirectory(char_t *lpath) |
---|
82 | { |
---|
83 | #if WEBS_PAGE_ROM |
---|
84 | websStatType sbuf; |
---|
85 | |
---|
86 | if (websRomPageStat(lpath, &sbuf) >= 0) { |
---|
87 | return(sbuf.isDir); |
---|
88 | } else { |
---|
89 | return 0; |
---|
90 | } |
---|
91 | #else |
---|
92 | gstat_t sbuf; |
---|
93 | |
---|
94 | if (gstat(lpath, &sbuf) >= 0) { |
---|
95 | return(sbuf.st_mode & S_IFDIR); |
---|
96 | } else { |
---|
97 | return 0; |
---|
98 | } |
---|
99 | #endif |
---|
100 | } |
---|
101 | |
---|
102 | |
---|
103 | /******************************************************************************/ |
---|
104 | /* |
---|
105 | * Read a web page. Returns the number of _bytes_ read. |
---|
106 | * len is the size of buf, in bytes. |
---|
107 | */ |
---|
108 | |
---|
109 | int websPageReadData(webs_t wp, char *buf, int nBytes) |
---|
110 | { |
---|
111 | |
---|
112 | #if WEBS_PAGE_ROM |
---|
113 | a_assert(websValid(wp)); |
---|
114 | return websRomPageReadData(wp, buf, nBytes); |
---|
115 | #else |
---|
116 | a_assert(websValid(wp)); |
---|
117 | return read(wp->docfd, buf, nBytes); |
---|
118 | #endif |
---|
119 | } |
---|
120 | |
---|
121 | /******************************************************************************/ |
---|
122 | /* |
---|
123 | * Move file pointer offset bytes. |
---|
124 | */ |
---|
125 | |
---|
126 | void websPageSeek(webs_t wp, long offset) |
---|
127 | { |
---|
128 | a_assert(websValid(wp)); |
---|
129 | |
---|
130 | #if WEBS_PAGE_ROM |
---|
131 | websRomPageSeek(wp, offset, SEEK_CUR); |
---|
132 | #else |
---|
133 | lseek(wp->docfd, offset, SEEK_CUR); |
---|
134 | #endif |
---|
135 | } |
---|
136 | |
---|
137 | /******************************************************************************/ |
---|
138 | |
---|