Skip to content

Commit dd263e3

Browse files
committed
lib/fetch: remove fetchListHTTP
its unused and probably doesn't work well.
1 parent dfe2fcb commit dd263e3

File tree

3 files changed

+0
-252
lines changed

3 files changed

+0
-252
lines changed

lib/fetch/fetch.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,6 @@ fetchList(struct url_list *ue, struct url *URL, const char *pattern,
161161
return (fetchListFile(ue, URL, pattern, flags));
162162
else if (strcasecmp(URL->scheme, SCHEME_FTP) == 0)
163163
return (fetchListFTP(ue, URL, pattern, flags));
164-
else if (strcasecmp(URL->scheme, SCHEME_HTTP) == 0)
165-
return (fetchListHTTP(ue, URL, pattern, flags));
166-
else if (strcasecmp(URL->scheme, SCHEME_HTTPS) == 0)
167-
return (fetchListHTTP(ue, URL, pattern, flags));
168164
url_seterr(URL_BAD_SCHEME);
169165
return -1;
170166
}

lib/fetch/fetch.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,6 @@ fetchIO *fetchXGetHTTP(struct url *, struct url_stat *, const char *);
117117
fetchIO *fetchGetHTTP(struct url *, const char *);
118118
fetchIO *fetchPutHTTP(struct url *, const char *);
119119
int fetchStatHTTP(struct url *, struct url_stat *, const char *);
120-
int fetchListHTTP(struct url_list *, struct url *, const char *,
121-
const char *);
122120

123121
/* FTP-specific functions */
124122
fetchIO *fetchXGetFTP(struct url *, struct url_stat *, const char *);

lib/fetch/http.c

Lines changed: 0 additions & 246 deletions
Original file line numberDiff line numberDiff line change
@@ -1329,249 +1329,3 @@ enum http_states {
13291329
ST_TAGAX,
13301330
ST_TAGAQ
13311331
};
1332-
1333-
struct index_parser {
1334-
struct url_list *ue;
1335-
struct url *url;
1336-
enum http_states state;
1337-
};
1338-
1339-
static ssize_t
1340-
parse_index(struct index_parser *parser, char *buf, size_t len)
1341-
{
1342-
char *end_attr, p = *buf;
1343-
1344-
switch (parser->state) {
1345-
case ST_NONE:
1346-
/* Plain text, not in markup */
1347-
if (p == '<')
1348-
parser->state = ST_LT;
1349-
return 1;
1350-
case ST_LT:
1351-
/* In tag -- "<" already found */
1352-
if (p == '>')
1353-
parser->state = ST_NONE;
1354-
else if (p == 'a' || p == 'A')
1355-
parser->state = ST_LTA;
1356-
else if (!isspace((unsigned char)p))
1357-
parser->state = ST_TAG;
1358-
return 1;
1359-
case ST_LTA:
1360-
/* In tag -- "<a" already found */
1361-
if (p == '>')
1362-
parser->state = ST_NONE;
1363-
else if (p == '"')
1364-
parser->state = ST_TAGAQ;
1365-
else if (isspace((unsigned char)p))
1366-
parser->state = ST_TAGA;
1367-
else
1368-
parser->state = ST_TAG;
1369-
return 1;
1370-
case ST_TAG:
1371-
/* In tag, but not "<a" -- disregard */
1372-
if (p == '>')
1373-
parser->state = ST_NONE;
1374-
return 1;
1375-
case ST_TAGA:
1376-
/* In a-tag -- "<a " already found */
1377-
if (p == '>')
1378-
parser->state = ST_NONE;
1379-
else if (p == '"')
1380-
parser->state = ST_TAGAQ;
1381-
else if (p == 'h' || p == 'H')
1382-
parser->state = ST_H;
1383-
else if (!isspace((unsigned char)p))
1384-
parser->state = ST_TAGAX;
1385-
return 1;
1386-
case ST_TAGAX:
1387-
/* In unknown keyword in a-tag */
1388-
if (p == '>')
1389-
parser->state = ST_NONE;
1390-
else if (p == '"')
1391-
parser->state = ST_TAGAQ;
1392-
else if (isspace((unsigned char)p))
1393-
parser->state = ST_TAGA;
1394-
return 1;
1395-
case ST_TAGAQ:
1396-
/* In a-tag, unknown argument for keys. */
1397-
if (p == '>')
1398-
parser->state = ST_NONE;
1399-
else if (p == '"')
1400-
parser->state = ST_TAGA;
1401-
return 1;
1402-
case ST_H:
1403-
/* In a-tag -- "<a h" already found */
1404-
if (p == '>')
1405-
parser->state = ST_NONE;
1406-
else if (p == '"')
1407-
parser->state = ST_TAGAQ;
1408-
else if (p == 'r' || p == 'R')
1409-
parser->state = ST_R;
1410-
else if (isspace((unsigned char)p))
1411-
parser->state = ST_TAGA;
1412-
else
1413-
parser->state = ST_TAGAX;
1414-
return 1;
1415-
case ST_R:
1416-
/* In a-tag -- "<a hr" already found */
1417-
if (p == '>')
1418-
parser->state = ST_NONE;
1419-
else if (p == '"')
1420-
parser->state = ST_TAGAQ;
1421-
else if (p == 'e' || p == 'E')
1422-
parser->state = ST_E;
1423-
else if (isspace((unsigned char)p))
1424-
parser->state = ST_TAGA;
1425-
else
1426-
parser->state = ST_TAGAX;
1427-
return 1;
1428-
case ST_E:
1429-
/* In a-tag -- "<a hre" already found */
1430-
if (p == '>')
1431-
parser->state = ST_NONE;
1432-
else if (p == '"')
1433-
parser->state = ST_TAGAQ;
1434-
else if (p == 'f' || p == 'F')
1435-
parser->state = ST_F;
1436-
else if (isspace((unsigned char)p))
1437-
parser->state = ST_TAGA;
1438-
else
1439-
parser->state = ST_TAGAX;
1440-
return 1;
1441-
case ST_F:
1442-
/* In a-tag -- "<a href" already found */
1443-
if (p == '>')
1444-
parser->state = ST_NONE;
1445-
else if (p == '"')
1446-
parser->state = ST_TAGAQ;
1447-
else if (p == '=')
1448-
parser->state = ST_HREF;
1449-
else if (!isspace((unsigned char)p))
1450-
parser->state = ST_TAGAX;
1451-
return 1;
1452-
case ST_HREF:
1453-
/* In a-tag -- "<a href=" already found */
1454-
if (p == '>')
1455-
parser->state = ST_NONE;
1456-
else if (p == '"')
1457-
parser->state = ST_HREFQ;
1458-
else if (!isspace((unsigned char)p))
1459-
parser->state = ST_TAGA;
1460-
return 1;
1461-
case ST_HREFQ:
1462-
/* In href of the a-tag */
1463-
end_attr = memchr(buf, '"', len);
1464-
if (end_attr == NULL)
1465-
return 0;
1466-
*end_attr = '\0';
1467-
parser->state = ST_TAGA;
1468-
if (fetch_add_entry(parser->ue, parser->url, buf, 1))
1469-
return -1;
1470-
return end_attr + 1 - buf;
1471-
}
1472-
return -1;
1473-
}
1474-
1475-
struct http_index_cache {
1476-
struct http_index_cache *next;
1477-
struct url *location;
1478-
struct url_list ue;
1479-
};
1480-
1481-
static struct http_index_cache *index_cache;
1482-
1483-
/*
1484-
* List a directory
1485-
*/
1486-
int
1487-
fetchListHTTP(struct url_list *ue, struct url *url, const char *pattern, const char *flags)
1488-
{
1489-
fetchIO *f;
1490-
char buf[2 * PATH_MAX];
1491-
size_t buf_len, sum_processed;
1492-
ssize_t read_len, processed;
1493-
struct index_parser state;
1494-
struct http_index_cache *cache = NULL;
1495-
int do_cache, ret;
1496-
1497-
(void)pattern;
1498-
1499-
do_cache = CHECK_FLAG('c');
1500-
1501-
if (do_cache) {
1502-
for (cache = index_cache; cache != NULL; cache = cache->next) {
1503-
if (strcmp(cache->location->scheme, url->scheme))
1504-
continue;
1505-
if (strcmp(cache->location->user, url->user))
1506-
continue;
1507-
if (strcmp(cache->location->pwd, url->pwd))
1508-
continue;
1509-
if (strcmp(cache->location->host, url->host))
1510-
continue;
1511-
if (cache->location->port != url->port)
1512-
continue;
1513-
if (strcmp(cache->location->doc, url->doc))
1514-
continue;
1515-
return fetchAppendURLList(ue, &cache->ue);
1516-
}
1517-
1518-
cache = malloc(sizeof(*cache));
1519-
if (cache == NULL)
1520-
return -1;
1521-
fetchInitURLList(&cache->ue);
1522-
cache->location = fetchCopyURL(url);
1523-
}
1524-
1525-
f = fetchGetHTTP(url, flags);
1526-
if (f == NULL) {
1527-
if (do_cache) {
1528-
fetchFreeURLList(&cache->ue);
1529-
fetchFreeURL(cache->location);
1530-
free(cache);
1531-
}
1532-
return -1;
1533-
}
1534-
1535-
state.url = url;
1536-
state.state = ST_NONE;
1537-
if (do_cache) {
1538-
state.ue = &cache->ue;
1539-
} else {
1540-
state.ue = ue;
1541-
}
1542-
1543-
buf_len = 0;
1544-
1545-
while ((read_len = fetchIO_read(f, buf + buf_len, sizeof(buf) - buf_len)) > 0) {
1546-
buf_len += read_len;
1547-
sum_processed = 0;
1548-
do {
1549-
processed = parse_index(&state, buf + sum_processed, buf_len);
1550-
if (processed == -1)
1551-
break;
1552-
buf_len -= processed;
1553-
sum_processed += processed;
1554-
} while (processed != 0 && buf_len > 0);
1555-
if (processed == -1) {
1556-
read_len = -1;
1557-
break;
1558-
}
1559-
memmove(buf, buf + sum_processed, buf_len);
1560-
}
1561-
1562-
fetchIO_close(f);
1563-
1564-
ret = read_len < 0 ? -1 : 0;
1565-
1566-
if (do_cache) {
1567-
if (ret == 0) {
1568-
cache->next = index_cache;
1569-
index_cache = cache;
1570-
}
1571-
1572-
if (fetchAppendURLList(ue, &cache->ue))
1573-
ret = -1;
1574-
}
1575-
1576-
return ret;
1577-
}

0 commit comments

Comments
 (0)