1 /* Copyright 1999-2004 The Apache Software Foundation
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
23 * Compare a string to a mask
25 * @ - uppercase letter
26 * # - lowercase letter
29 * * - swallow remaining characters
30 * <x> - exact match for any other character
32 static int checkmask(const char *data, const char *mask)
36 for (i = 0; mask[i] != '\0' && mask[i] != '*'; i++) {
62 return (data[i] == '\0');
66 * Converts 8 hex digits to a time integer
68 static int hex2sec(const char *x)
73 for (i = 0, j = 0; i < 8; i++) {
84 return -1; /* so that it works with 8-byte ints */
89 int main(int argc, char **argv)
96 char path[FILENAME_MAX + 1];
98 time_t date, lmod, expire;
101 char sdate[30], slmod[30], sexpire[30];
102 const char time_format[] = "%e %b %Y %R";
105 printf("Usage: cls directory\n");
109 d = opendir(argv[1]);
120 if (s[0] == '.' || s[0] == '#')
122 sprintf(path, "%s/%s", argv[1], s);
123 fp = fopen(path, "r");
128 if (fgets(line, 1034, fp) == NULL) {
133 if (!checkmask(line, "&&&&&&&& &&&&&&&& &&&&&&&& &&&&&&&& &&&&&&&&\n")) {
134 fprintf(stderr, "Bad cache file\n");
138 date = hex2sec(line);
139 lmod = hex2sec(line + 9);
140 expire = hex2sec(line + 18);
141 ver = hex2sec(line + 27);
142 len = hex2sec(line + 35);
143 if (fgets(line, 1034, fp) == NULL) {
150 if (strncmp(line, "X-URL: ", 7) != 0 || line[i - 1] != '\n') {
151 fprintf(stderr, "Bad cache file\n");
157 strftime(sdate, 30, time_format, &ts);
164 strftime(slmod, 30, time_format, &ts);
170 ts = *gmtime(&expire);
171 strftime(sexpire, 30, time_format, &ts);
174 strcpy(sexpire, "-");
176 printf("%s: %d; %s %s %s\n", line + 7, ver, sdate, slmod, sexpire);