diff options
Diffstat (limited to 'src/html.c')
-rw-r--r-- | src/html.c | 57 |
1 files changed, 50 insertions, 7 deletions
@@ -199,6 +199,45 @@ static int get_plugin_filepath(const char *program_dir, const char *plugin_name, return 0; } +typedef struct { + const char *str; + size_t size; +} string_view; + +static int is_hex_num(char c) { + return (c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F'); +} + +/* mangadex ids are in this format: aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee */ +static int looks_like_mangadex_id(const char *str) { + const int len = strlen(str); + if(len != 36) + return 0; + + string_view parts[] = { + { str, 8 }, + { str + 9, 4 }, + { str + 9 + 5, 4 }, + { str + 9 + 5 + 5, 4 }, + { str + 9 + 5 + 5 + 5, 12 } + }; + + for(size_t i = 0; i < 5; ++i) { + for(size_t j = 0; j < parts[i].size; ++j) { + const char c = parts[i].str[j]; + if(!is_hex_num(c)) + return 0; + } + } + + for(size_t i = 0; i < 4; ++i) { + if(parts[i].str[parts[i].size] != '-') + return 0; + } + + return 1; +} + int add_html(const char *name, const char *url, char *html_config_dir, char *program_dir, const char *start_after) { int result = 0; @@ -208,14 +247,18 @@ int add_html(const char *name, const char *url, char *html_config_dir, char *pro } char domain[2086]; - if(url_extract_domain(url, domain, sizeof(domain)) != 0) { - fprintf(stderr, "Url %s is too long\n", url); - return -1; - } + if(looks_like_mangadex_id(url)) { + strcpy(domain, "mangadex"); + } else { + if(url_extract_domain(url, domain, sizeof(domain)) != 0) { + fprintf(stderr, "Url %s is too long\n", url); + return -1; + } - if(domain[0] == '\0') { - fprintf(stderr, "Invalid url: %s\n", url); - return -1; + if(domain[0] == '\0') { + fprintf(stderr, "Invalid url: %s\n", url); + return -1; + } } char domain_plugin_path[PATH_MAX]; |