restored LinkTable_print()
This commit is contained in:
parent
8110438cd1
commit
99761b249a
45
src/link.c
45
src/link.c
|
@ -78,7 +78,7 @@ static void HTML_to_LinkTable(GumboNode *node, LinkTable *linktbl)
|
||||||
(href = gumbo_get_attribute(&node->v.element.attributes, "href"))) {
|
(href = gumbo_get_attribute(&node->v.element.attributes, "href"))) {
|
||||||
/* if it is valid, copy the link onto the heap */
|
/* if it is valid, copy the link onto the heap */
|
||||||
LinkType type = linkname_type(href->value);
|
LinkType type = linkname_type(href->value);
|
||||||
if (type) {
|
if ( (type == LINK_DIR) || (type == LINK_FILE) ) {
|
||||||
LinkTable_add(linktbl, Link_new(href->value, type));
|
LinkTable_add(linktbl, Link_new(href->value, type));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -137,7 +137,7 @@ static CURL *Link_to_curl(Link *link)
|
||||||
|
|
||||||
void Link_get_stat(Link *this_link)
|
void Link_get_stat(Link *this_link)
|
||||||
{
|
{
|
||||||
if (this_link->type == LINK_FILE) {
|
if (this_link->type != LINK_INVALID) {
|
||||||
CURL *curl = Link_to_curl(this_link);
|
CURL *curl = Link_to_curl(this_link);
|
||||||
curl_easy_setopt(curl, CURLOPT_NOBODY, 1);
|
curl_easy_setopt(curl, CURLOPT_NOBODY, 1);
|
||||||
curl_easy_setopt(curl, CURLOPT_FILETIME, 1L);
|
curl_easy_setopt(curl, CURLOPT_FILETIME, 1L);
|
||||||
|
@ -187,23 +187,17 @@ static void LinkTable_fill(LinkTable *linktbl)
|
||||||
Link *head_link = linktbl->links[0];
|
Link *head_link = linktbl->links[0];
|
||||||
for (int i = 0; i < linktbl->num; i++) {
|
for (int i = 0; i < linktbl->num; i++) {
|
||||||
Link *this_link = linktbl->links[i];
|
Link *this_link = linktbl->links[i];
|
||||||
if (this_link->type) {
|
if (this_link->type != LINK_INVALID) {
|
||||||
char *url;
|
char *url;
|
||||||
url = path_append(head_link->f_url, this_link->linkname);
|
url = path_append(head_link->f_url, this_link->linkname);
|
||||||
strncpy(this_link->f_url, url, MAX_PATH_LEN);
|
strncpy(this_link->f_url, url, MAX_PATH_LEN);
|
||||||
free(url);
|
free(url);
|
||||||
|
|
||||||
char *unescaped_linkname;
|
char *unescaped_linkname;
|
||||||
unescaped_linkname = curl_easy_unescape(NULL, this_link->linkname, 0,
|
unescaped_linkname = curl_easy_unescape(NULL, this_link->linkname,
|
||||||
NULL);
|
0, NULL);
|
||||||
strncpy(this_link->linkname, unescaped_linkname, MAX_FILENAME_LEN);
|
strncpy(this_link->linkname, unescaped_linkname, MAX_FILENAME_LEN);
|
||||||
curl_free(unescaped_linkname);
|
curl_free(unescaped_linkname);
|
||||||
|
|
||||||
if (this_link->type == LINK_FILE && !(this_link->content_length)) {
|
|
||||||
Link_get_stat(this_link);
|
Link_get_stat(this_link);
|
||||||
} else if (this_link->type == LINK_DIR) {
|
|
||||||
this_link->time = head_link->time;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* Block until the LinkTable is filled up */
|
/* Block until the LinkTable is filled up */
|
||||||
|
@ -218,7 +212,7 @@ static void LinkTable_fill(LinkTable *linktbl)
|
||||||
static void LinkTable_gap_fill(LinkTable *linktbl)
|
static void LinkTable_gap_fill(LinkTable *linktbl)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < linktbl->num; i++) {
|
for (int i = 0; i < linktbl->num; i++) {
|
||||||
if (!linktbl->links[i]->type) {
|
if (linktbl->links[i]->type == LINK_INVALID) {
|
||||||
Link_get_stat(linktbl->links[i]);
|
Link_get_stat(linktbl->links[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -242,27 +236,28 @@ static void LinkTable_free(LinkTable *linktbl)
|
||||||
static void LinkTable_print(LinkTable *linktbl)
|
static void LinkTable_print(LinkTable *linktbl)
|
||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
// fprintf(stderr, "--------------------------------------------\n");
|
fprintf(stderr, "--------------------------------------------\n");
|
||||||
// fprintf(stderr, " LinkTable %p for %s\n", linktbl,
|
fprintf(stderr, " LinkTable %p for %s\n", linktbl,
|
||||||
// linktbl->links[0]->f_url);
|
linktbl->links[0]->f_url);
|
||||||
// fprintf(stderr, "--------------------------------------------\n");
|
fprintf(stderr, "--------------------------------------------\n");
|
||||||
for (int i = 0; i < linktbl->num; i++) {
|
for (int i = 0; i < linktbl->num; i++) {
|
||||||
Link *this_link = linktbl->links[i];
|
Link *this_link = linktbl->links[i];
|
||||||
// fprintf(stderr, "%d %c %lu %s %s\n",
|
fprintf(stderr, "%d %c %lu %s %s\n",
|
||||||
// i,
|
i,
|
||||||
// this_link->type,
|
this_link->type,
|
||||||
// this_link->content_length,
|
this_link->content_length,
|
||||||
// this_link->linkname,
|
this_link->linkname,
|
||||||
// this_link->f_url
|
this_link->f_url
|
||||||
// );
|
);
|
||||||
if (!this_link->type) {
|
if (this_link->type == LINK_INVALID) {
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
// fprintf(stderr, "--------------------------------------------\n");
|
fprintf(stderr, "--------------------------------------------\n");
|
||||||
fprintf(stderr, "LinkTable_print(): Invalid link count: %d, %s.\n", i,
|
fprintf(stderr, "LinkTable_print(): Invalid link count: %d, %s.\n", i,
|
||||||
linktbl->links[0]->f_url);
|
linktbl->links[0]->f_url);
|
||||||
|
fprintf(stderr, "--------------------------------------------\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
LinkTable *LinkTable_new(const char *url)
|
LinkTable *LinkTable_new(const char *url)
|
||||||
|
|
|
@ -10,7 +10,7 @@ typedef enum {
|
||||||
LINK_HEAD = 'H',
|
LINK_HEAD = 'H',
|
||||||
LINK_DIR = 'D',
|
LINK_DIR = 'D',
|
||||||
LINK_FILE = 'F',
|
LINK_FILE = 'F',
|
||||||
LINK_INVALID = '\0'
|
LINK_INVALID = 'I'
|
||||||
} LinkType;
|
} LinkType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue