webui: handle RSS link torrent URLs

This commit is contained in:
ookami125 2026-06-23 02:12:53 -04:00
parent 0249ce330d
commit 15905c2f35
2 changed files with 18 additions and 6 deletions

View file

@ -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}; char enclosure[1024] = {0}, lenstr[64] = {0}, pub[128] = {0};
xml_tag_text(open, ilen, "title", title, sizeof title); xml_tag_text(open, ilen, "title", title, sizeof title);
xml_tag_text(open, ilen, "link", link, sizeof link); xml_tag_text(open, ilen, "link", link, sizeof link);
/* Atom (and some RSS) carry the URL as <link href="..."> instead. */
if (!link[0]) xml_attr(open, ilen, "link", "href", link, sizeof link);
xml_tag_text(open, ilen, "pubDate", pub, sizeof pub); xml_tag_text(open, ilen, "pubDate", pub, sizeof pub);
if (!pub[0]) xml_tag_text(open, ilen, "published", pub, sizeof pub); if (!pub[0]) xml_tag_text(open, ilen, "published", pub, sizeof pub);
find_magnet(open, ilen, magnet, sizeof magnet); 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); xml_tag_text(open, ilen, "contentLength", lenstr, sizeof lenstr);
if (!magnet[0] && strncmp(link, "magnet:", 7) == 0) if (!magnet[0] && strncmp(link, "magnet:", 7) == 0)
snprintf(magnet, sizeof magnet, "%s", link); snprintf(magnet, sizeof magnet, "%s", link);
/* A bare <link> 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); const char *key = magnet[0] ? magnet : (enclosure[0] ? enclosure : link);
if (title[0] && key && *key) { 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) { if (!seen) {
json_t *art = json_pack( 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, "title", title, "key", key,
"magnet", magnet, "torrentUrl", enclosure, "magnet", magnet, "torrentUrl", dl_url, "link", link,
"size", (json_int_t)strtoll(lenstr, NULL, 10), "size", (json_int_t)strtoll(lenstr, NULL, 10),
"pubDate", pub, "isRead", 0, "grabbed", 0); "pubDate", pub, "isRead", 0, "grabbed", 0);
json_array_insert_new(articles, 0, art); 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) if (out_new)
json_array_append_new(out_new, json_pack( json_array_append_new(out_new, json_pack(
"{s:s,s:s,s:s,s:s}", "title", title, "key", key, "{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); p = close + strlen(close_tag);

View file

@ -5,7 +5,6 @@
* and chunked transfer-encoding, and follows 3xx redirects. This is deliberately * and chunked transfer-encoding, and follows 3xx redirects. This is deliberately
* simple it serves RSS/Torznab fetches, not a general-purpose user agent. */ * simple it serves RSS/Torznab fetches, not a general-purpose user agent. */
#include "naut/http_client.h" #include "naut/http_client.h"
#include "naut/log.h"
#include <errno.h> #include <errno.h>
#include <netdb.h> #include <netdb.h>
@ -16,9 +15,15 @@
#include <sys/socket.h> #include <sys/socket.h>
#include <sys/time.h> #include <sys/time.h>
#include <stdio.h>
#include <openssl/ssl.h> #include <openssl/ssl.h>
#include <openssl/err.h> #include <openssl/err.h>
/* 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_BODY (16 * 1024 * 1024) /* 16 MiB cap */
#define HTTP_MAX_REDIR 5 #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) { static bool conn_open(conn_t *c, const char *host, const char *port, bool tls) {
memset(c, 0, sizeof *c); memset(c, 0, sizeof *c);
c->fd = dial(host, port); 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; if (!tls) return true;
c->ctx = SSL_CTX_new(TLS_client_method()); 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_fd(c->ssl, c->fd);
SSL_set_tlsext_host_name(c->ssl, host); /* SNI */ SSL_set_tlsext_host_name(c->ssl, host); /* SNI */
if (SSL_connect(c->ssl) != 1) { 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); conn_close(c);
return false; return false;
} }