summaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rw-r--r--plugins/check_curl.c99
1 files changed, 4 insertions, 95 deletions
diff --git a/plugins/check_curl.c b/plugins/check_curl.c
index f7c7596..b002637 100644
--- a/plugins/check_curl.c
+++ b/plugins/check_curl.c
@@ -184,7 +184,6 @@ int curlhelp_parse_statusline (const char*, curlhelp_statusline *);
184void curlhelp_free_statusline (curlhelp_statusline *); 184void curlhelp_free_statusline (curlhelp_statusline *);
185char *perfd_time_ssl (double microsec); 185char *perfd_time_ssl (double microsec);
186char *get_header_value (const struct phr_header* headers, const size_t nof_headers, const char* header); 186char *get_header_value (const struct phr_header* headers, const size_t nof_headers, const char* header);
187static time_t parse_time_string (const char *string);
188int check_document_dates (const curlhelp_write_curlbuf *, char (*msg)[DEFAULT_BUFFER_SIZE]); 187int check_document_dates (const curlhelp_write_curlbuf *, char (*msg)[DEFAULT_BUFFER_SIZE]);
189 188
190void remove_newlines (char *); 189void remove_newlines (char *);
@@ -1563,98 +1562,6 @@ get_header_value (const struct phr_header* headers, const size_t nof_headers, co
1563 return NULL; 1562 return NULL;
1564} 1563}
1565 1564
1566/* TODO: use CURL_EXTERN time_t curl_getdate(const char *p, const time_t *unused); here */
1567static time_t
1568parse_time_string (const char *string)
1569{
1570 struct tm tm;
1571 time_t t;
1572 memset (&tm, 0, sizeof(tm));
1573
1574 /* Like this: Tue, 25 Dec 2001 02:59:03 GMT */
1575
1576 if (isupper (string[0]) && /* Tue */
1577 islower (string[1]) &&
1578 islower (string[2]) &&
1579 ',' == string[3] &&
1580 ' ' == string[4] &&
1581 (isdigit(string[5]) || string[5] == ' ') && /* 25 */
1582 isdigit (string[6]) &&
1583 ' ' == string[7] &&
1584 isupper (string[8]) && /* Dec */
1585 islower (string[9]) &&
1586 islower (string[10]) &&
1587 ' ' == string[11] &&
1588 isdigit (string[12]) && /* 2001 */
1589 isdigit (string[13]) &&
1590 isdigit (string[14]) &&
1591 isdigit (string[15]) &&
1592 ' ' == string[16] &&
1593 isdigit (string[17]) && /* 02: */
1594 isdigit (string[18]) &&
1595 ':' == string[19] &&
1596 isdigit (string[20]) && /* 59: */
1597 isdigit (string[21]) &&
1598 ':' == string[22] &&
1599 isdigit (string[23]) && /* 03 */
1600 isdigit (string[24]) &&
1601 ' ' == string[25] &&
1602 'G' == string[26] && /* GMT */
1603 'M' == string[27] && /* GMT */
1604 'T' == string[28]) {
1605
1606 tm.tm_sec = 10 * (string[23]-'0') + (string[24]-'0');
1607 tm.tm_min = 10 * (string[20]-'0') + (string[21]-'0');
1608 tm.tm_hour = 10 * (string[17]-'0') + (string[18]-'0');
1609 tm.tm_mday = 10 * (string[5] == ' ' ? 0 : string[5]-'0') + (string[6]-'0');
1610 tm.tm_mon = (!strncmp (string+8, "Jan", 3) ? 0 :
1611 !strncmp (string+8, "Feb", 3) ? 1 :
1612 !strncmp (string+8, "Mar", 3) ? 2 :
1613 !strncmp (string+8, "Apr", 3) ? 3 :
1614 !strncmp (string+8, "May", 3) ? 4 :
1615 !strncmp (string+8, "Jun", 3) ? 5 :
1616 !strncmp (string+8, "Jul", 3) ? 6 :
1617 !strncmp (string+8, "Aug", 3) ? 7 :
1618 !strncmp (string+8, "Sep", 3) ? 8 :
1619 !strncmp (string+8, "Oct", 3) ? 9 :
1620 !strncmp (string+8, "Nov", 3) ? 10 :
1621 !strncmp (string+8, "Dec", 3) ? 11 :
1622 -1);
1623 tm.tm_year = ((1000 * (string[12]-'0') +
1624 100 * (string[13]-'0') +
1625 10 * (string[14]-'0') +
1626 (string[15]-'0'))
1627 - 1900);
1628
1629 tm.tm_isdst = 0; /* GMT is never in DST, right? */
1630
1631 if (tm.tm_mon < 0 || tm.tm_mday < 1 || tm.tm_mday > 31)
1632 return 0;
1633
1634 /*
1635 This is actually wrong: we need to subtract the local timezone
1636 offset from GMT from this value. But, that's ok in this usage,
1637 because we only comparing these two GMT dates against each other,
1638 so it doesn't matter what time zone we parse them in.
1639 */
1640
1641 t = mktime (&tm);
1642 if (t == (time_t) -1) t = 0;
1643
1644 if (verbose) {
1645 const char *s = string;
1646 while (*s && *s != '\r' && *s != '\n')
1647 fputc (*s++, stdout);
1648 printf (" ==> %lu\n", (unsigned long) t);
1649 }
1650
1651 return t;
1652
1653 } else {
1654 return 0;
1655 }
1656}
1657
1658int 1565int
1659check_document_dates (const curlhelp_write_curlbuf *header_buf, char (*msg)[DEFAULT_BUFFER_SIZE]) 1566check_document_dates (const curlhelp_write_curlbuf *header_buf, char (*msg)[DEFAULT_BUFFER_SIZE])
1660{ 1567{
@@ -1680,8 +1587,10 @@ check_document_dates (const curlhelp_write_curlbuf *header_buf, char (*msg)[DEFA
1680 snprintf (*msg, DEFAULT_BUFFER_SIZE, _("%sDocument modification date unknown, "), *msg); 1587 snprintf (*msg, DEFAULT_BUFFER_SIZE, _("%sDocument modification date unknown, "), *msg);
1681 date_result = max_state_alt(STATE_CRITICAL, date_result); 1588 date_result = max_state_alt(STATE_CRITICAL, date_result);
1682 } else { 1589 } else {
1683 time_t srv_data = parse_time_string (server_date); 1590 time_t srv_data = curl_getdate (server_date, NULL);
1684 time_t doc_data = parse_time_string (document_date); 1591 time_t doc_data = curl_getdate (document_date, NULL);
1592 if (verbose >= 2)
1593 printf ("* server date: '%s' (%d), doc_date: '%s' (%d)\n", server_date, srv_data, document_date, doc_data);
1685 if (srv_data <= 0) { 1594 if (srv_data <= 0) {
1686 snprintf (*msg, DEFAULT_BUFFER_SIZE, _("%sServer date \"%100s\" unparsable, "), *msg, server_date); 1595 snprintf (*msg, DEFAULT_BUFFER_SIZE, _("%sServer date \"%100s\" unparsable, "), *msg, server_date);
1687 date_result = max_state_alt(STATE_CRITICAL, date_result); 1596 date_result = max_state_alt(STATE_CRITICAL, date_result);