1 /* Licensed to the Apache Software Foundation (ASF) under one or more
2 * contributor license agreements. See the NOTICE file distributed with
3 * this work for additional information regarding copyright ownership.
4 * The ASF licenses this file to You under the Apache License, Version 2.0
5 * (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
24 * Compare a string to a mask
26 * @ - uppercase letter
27 * # - lowercase letter
30 * * - swallow remaining characters
31 * <x> - exact match for any other character
33 static int checkmask(const char *data, const char *mask)
37 for (i = 0; mask[i] != '\0' && mask[i] != '*'; i++) {
63 return (data[i] == '\0');
67 * Converts 8 hex digits to a time integer
69 static int hex2sec(const char *x)
74 for (i = 0, j = 0; i < 8; i++) {
85 return -1; /* so that it works with 8-byte ints */
90 int main(int argc, char **argv)
97 char path[FILENAME_MAX + 1];
99 time_t date, lmod, expire;
102 char sdate[30], slmod[30], sexpire[30];
103 const char time_format[] = "%e %b %Y %R";
106 printf("Usage: cls directory\n");
110 d = opendir(argv[1]);
121 if (s[0] == '.' || s[0] == '#')
123 sprintf(path, "%s/%s", argv[1], s);
124 fp = fopen(path, "r");
129 if (fgets(line, 1034, fp) == NULL) {
134 if (!checkmask(line, "&&&&&&&& &&&&&&&& &&&&&&&& &&&&&&&& &&&&&&&&\n")) {
135 fprintf(stderr, "Bad cache file\n");
139 date = hex2sec(line);
140 lmod = hex2sec(line + 9);
141 expire = hex2sec(line + 18);
142 ver = hex2sec(line + 27);
143 len = hex2sec(line + 35);
144 if (fgets(line, 1034, fp) == NULL) {
151 if (strncmp(line, "X-URL: ", 7) != 0 || line[i - 1] != '\n') {
152 fprintf(stderr, "Bad cache file\n");
158 strftime(sdate, 30, time_format, &ts);
165 strftime(slmod, 30, time_format, &ts);
171 ts = *gmtime(&expire);
172 strftime(sexpire, 30, time_format, &ts);
175 strcpy(sexpire, "-");
177 printf("%s: %d; %s %s %s\n", line + 7, ver, sdate, slmod, sexpire);