summaryrefslogtreecommitdiffstats
path: root/plugins/check_curl.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/check_curl.c')
-rw-r--r--plugins/check_curl.c49
1 files changed, 45 insertions, 4 deletions
diff --git a/plugins/check_curl.c b/plugins/check_curl.c
index 45a52f0e..30c947fb 100644
--- a/plugins/check_curl.c
+++ b/plugins/check_curl.c
@@ -114,7 +114,7 @@ int curlhelp_initbuffer (curlhelp_curlbuf*);
114int curlhelp_buffer_callback (void*, size_t , size_t , void*); 114int curlhelp_buffer_callback (void*, size_t , size_t , void*);
115void curlhelp_freebuffer (curlhelp_curlbuf*); 115void curlhelp_freebuffer (curlhelp_curlbuf*);
116 116
117int curlhelp_parse_statusline (char*, curlhelp_statusline *); 117int curlhelp_parse_statusline (const char*, curlhelp_statusline *);
118void curlhelp_free_statusline (curlhelp_statusline *); 118void curlhelp_free_statusline (curlhelp_statusline *);
119 119
120void remove_newlines (char *); 120void remove_newlines (char *);
@@ -700,17 +700,58 @@ curlhelp_freebuffer (curlhelp_curlbuf *buf)
700 buf->buf = NULL; 700 buf->buf = NULL;
701} 701}
702 702
703/* TODO: when redirecting we get more than one HTTP header, make sure 703/* TODO: should be moved into 'gl' and should be probed, glibc has
704 * we parse the last one 704 * a strrstr
705 */ 705 */
706const char*
707strrstr2(const char *haystack, const char *needle)
708{
709 int counter;
710 size_t len;
711 const char *prev_pos;
712 const char *pos;
713
714 if (haystack == NULL || needle == NULL)
715 return NULL;
716
717 if (haystack[0] == '\0' || needle[0] == '\0')
718 return NULL;
719
720 counter = 0;
721 prev_pos = NULL;
722 pos = haystack;
723 len = strlen (needle);
724 for (;;) {
725 pos = strstr (pos, needle);
726 if (pos == NULL) {
727 if (counter == 0)
728 return NULL;
729 else
730 return prev_pos;
731 }
732 counter++;
733 prev_pos = pos;
734 pos += len;
735 if (*pos == '\0') return prev_pos;
736 }
737}
738
706int 739int
707curlhelp_parse_statusline (char *buf, curlhelp_statusline *status_line) 740curlhelp_parse_statusline (const char *buf, curlhelp_statusline *status_line)
708{ 741{
709 char *first_line_end; 742 char *first_line_end;
710 char *p; 743 char *p;
711 size_t first_line_len; 744 size_t first_line_len;
712 char *pp; 745 char *pp;
746 const char *start;
713 747
748 /* find last start of a new header */
749 start = strrstr2 (buf, "\r\nHTTP");
750 if (start != NULL) {
751 start += 2;
752 buf = start;
753 }
754
714 first_line_end = strstr(buf, "\r\n"); 755 first_line_end = strstr(buf, "\r\n");
715 if (first_line_end == NULL) return -1; 756 if (first_line_end == NULL) return -1;
716 757