diff --git a/plugins/webui/webui.c b/plugins/webui/webui.c index f8b0bd9..b83fb98 100644 --- a/plugins/webui/webui.c +++ b/plugins/webui/webui.c @@ -2094,6 +2094,8 @@ static int rss_ingest(json_t *feed, const char *xml, size_t len, json_t *out_new char enclosure[1024] = {0}, lenstr[64] = {0}, pub[128] = {0}; xml_tag_text(open, ilen, "title", title, sizeof title); xml_tag_text(open, ilen, "link", link, sizeof link); + /* Atom (and some RSS) carry the URL as instead. */ + if (!link[0]) xml_attr(open, ilen, "link", "href", link, sizeof link); xml_tag_text(open, ilen, "pubDate", pub, sizeof pub); if (!pub[0]) xml_tag_text(open, ilen, "published", pub, sizeof pub); find_magnet(open, ilen, magnet, sizeof magnet); @@ -2102,6 +2104,11 @@ static int rss_ingest(json_t *feed, const char *xml, size_t len, json_t *out_new xml_tag_text(open, ilen, "contentLength", lenstr, sizeof lenstr); if (!magnet[0] && strncmp(link, "magnet:", 7) == 0) snprintf(magnet, sizeof magnet, "%s", link); + /* A bare to a .torrent is a valid download source too. */ + char dl_url[1024] = {0}; + if (enclosure[0]) snprintf(dl_url, sizeof dl_url, "%s", enclosure); + else if (strncmp(link, "http", 4) == 0 && strncmp(magnet, "magnet:", 7) != 0) + snprintf(dl_url, sizeof dl_url, "%s", link); const char *key = magnet[0] ? magnet : (enclosure[0] ? enclosure : link); if (title[0] && key && *key) { @@ -2112,9 +2119,9 @@ static int rss_ingest(json_t *feed, const char *xml, size_t len, json_t *out_new } if (!seen) { json_t *art = json_pack( - "{s:s,s:s,s:s,s:s,s:I,s:s,s:b,s:b}", + "{s:s,s:s,s:s,s:s,s:s,s:I,s:s,s:b,s:b}", "title", title, "key", key, - "magnet", magnet, "torrentUrl", enclosure, + "magnet", magnet, "torrentUrl", dl_url, "link", link, "size", (json_int_t)strtoll(lenstr, NULL, 10), "pubDate", pub, "isRead", 0, "grabbed", 0); json_array_insert_new(articles, 0, art); @@ -2122,7 +2129,7 @@ static int rss_ingest(json_t *feed, const char *xml, size_t len, json_t *out_new if (out_new) json_array_append_new(out_new, json_pack( "{s:s,s:s,s:s,s:s}", "title", title, "key", key, - "magnet", magnet, "torrentUrl", enclosure)); + "magnet", magnet, "torrentUrl", dl_url)); } } p = close + strlen(close_tag); diff --git a/src/net/http_client.c b/src/net/http_client.c index d9ed57f..99a2328 100644 --- a/src/net/http_client.c +++ b/src/net/http_client.c @@ -5,7 +5,6 @@ * and chunked transfer-encoding, and follows 3xx redirects. This is deliberately * simple — it serves RSS/Torznab fetches, not a general-purpose user agent. */ #include "naut/http_client.h" -#include "naut/log.h" #include #include @@ -16,9 +15,15 @@ #include #include +#include + #include #include +/* This lib is linked into the plugin module too, which can't resolve the host's + * naut_log symbols, so keep diagnostics dependency-free. */ +#define HTTP_WARN(...) (void)fprintf(stderr, "http: " __VA_ARGS__) + #define HTTP_MAX_BODY (16 * 1024 * 1024) /* 16 MiB cap */ #define HTTP_MAX_REDIR 5 @@ -58,7 +63,7 @@ static int dial(const char *host, const char *port) { static bool conn_open(conn_t *c, const char *host, const char *port, bool tls) { memset(c, 0, sizeof *c); c->fd = dial(host, port); - if (c->fd < 0) { NAUT_WARN("http: connect %s:%s failed", host, port); return false; } + if (c->fd < 0) { HTTP_WARN("connect %s:%s failed\n", host, port); return false; } if (!tls) return true; c->ctx = SSL_CTX_new(TLS_client_method()); @@ -69,7 +74,7 @@ static bool conn_open(conn_t *c, const char *host, const char *port, bool tls) { SSL_set_fd(c->ssl, c->fd); SSL_set_tlsext_host_name(c->ssl, host); /* SNI */ if (SSL_connect(c->ssl) != 1) { - NAUT_WARN("http: TLS handshake with %s failed", host); + HTTP_WARN("TLS handshake with %s failed\n", host); conn_close(c); return false; }