From ef72de007fc8c63650349c3d026c70335025013c Mon Sep 17 00:00:00 2001 From: Curtis McEnroe Date: Thu, 5 Sep 2019 20:04:48 -0400 Subject: Use CURLINFO_CONTENT_TYPE Oops, didn't see this. --- bin/title.c | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) (limited to 'bin') diff --git a/bin/title.c b/bin/title.c index 6f882223..02076073 100644 --- a/bin/title.c +++ b/bin/title.c @@ -18,11 +18,9 @@ #include #include #include -#include #include #include #include -#include #include #include @@ -82,22 +80,11 @@ static void showTitle(const char *title) { } static CURL *curl; -static bool html; static struct { char buf[8192]; size_t len; } body; -static const char ContentType[] = "Content-Type: text/html"; - -static size_t handleHeader(char *buf, size_t size, size_t nitems, void *user) { - (void)user; - size_t len = size * nitems; - if (sizeof(ContentType) - 1 < len) len = sizeof(ContentType) - 1; - if (!strncasecmp(buf, ContentType, len)) html = true; - return size * nitems; -} - // HE COMES static const char TitlePattern[] = "([^<]*)"; static regex_t TitleRegex; @@ -125,11 +112,14 @@ static CURLcode fetchTitle(const char *url) { CURLcode code = curl_easy_setopt(curl, CURLOPT_URL, url); if (code) return code; - html = false; curl_easy_setopt(curl, CURLOPT_NOBODY, 1L); code = curl_easy_perform(curl); if (code) return code; - if (!html) return CURLE_OK; + + char *type; + code = curl_easy_getinfo(curl, CURLINFO_CONTENT_TYPE, &type); + if (code) return code; + if (strncmp(type, "text/html", 9)) return CURLE_OK; body.len = 0; curl_easy_setopt(curl, CURLOPT_NOBODY, 0L); @@ -155,7 +145,6 @@ int main(int argc, char *argv[]) { curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L); curl_easy_setopt(curl, CURLOPT_MAXREDIRS, 3L); - curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, handleHeader); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, handleBody); if (argc > 1) { -- cgit 1.4.1
Commit message (Expand)Author
2018-10-22Add more URL schemesJune McEnroe
2018-10-22Rework status lineJune McEnroe
2018-10-22Rename status and verbose tagsJune McEnroe
2018-09-16Revert "Race parallel connects"June McEnroe
2018-09-16Race parallel connectsJune McEnroe
2018-09-15Call tls_error when tls_connect_socket failsJune McEnroe
2018-09-15Try successive getaddrinfo resultsJune McEnroe
2018-09-15Render README from chatte.7June McEnroe
2018-09-14Factor out uiPrompt to call on nick changeJune McEnroe
2018-09-14Run test binaries with set -e and semicolonsJune McEnroe
2018-09-14Fail target when any test binary failsJune McEnroe
2018-09-14Run tests in default targetJune McEnroe
2018-09-14Add termEvent testsJune McEnroe
2018-09-14Check width of entire next word including codesJune McEnroe
2018-09-14Remove word handling from formatParseJune McEnroe
2018-09-14Apply consecutive formatting codes at onceJune McEnroe
2018-09-14Add tests for formatParseJune McEnroe
2018-09-13Preview with nick in input windowJune McEnroe
2018-09-13Never send PRIVMSG to TagStatus or TagVerboseJune McEnroe
2018-09-13Move color selection to format.cJune McEnroe
2018-09-13Fix len for format->split at end of stringJune McEnroe
2018-09-13Avoid uninitialized x in uiReadJune McEnroe
2018-09-13Add IRCDefault to colors enumJune McEnroe
2018-09-13Return a format->split even at the end of the stringJune McEnroe
2018-09-13Fix weird tab-complete after commaJune McEnroe
2018-09-13Rewrite UI againJune McEnroe
2018-09-12Add note about C-oJune McEnroe
2018-09-12Use formatParse split to position input cursorJune McEnroe
2018-09-12Factor out IRC formatting parsingJune McEnroe
2018-09-11Add /help equivalent to /manJune McEnroe
2018-09-11Don't render every PM as a pingJune McEnroe
2018-09-11Add urlOpenMatchJune McEnroe
2018-09-10Depend on man.sh for chroot.tar targetJune McEnroe
2018-09-10Set LESSSECURE=1 in man.shJune McEnroe
2018-09-10Add /man commandJune McEnroe
2018-09-10Install man page in chrootJune McEnroe
2018-09-10Install man pageJune McEnroe
2018-09-10Split keys into subsections and document colorsJune McEnroe
2018-09-10Add "blank" lines to chatte.1June McEnroe
2018-09-10Document key bindings in chatte.1June McEnroe
2018-09-08Document slash commands in chatte.1June McEnroe