/[james]/httplint/httplint.c
ViewVC logotype

Diff of /httplint/httplint.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 42 by james, Wed Dec 17 18:45:44 2003 UTC revision 59 by james, Mon Apr 5 11:16:27 2004 UTC
# Line 1  Line 1 
1  /*  /*
2   * HTTP Header Lint   * HTTP Header Lint
3   * Licensed under the same license as Curl   * Licensed under the MIT License
4   *                http://curl.haxx.se/docs/copyright.html   *                http://www.opensource.org/licenses/mit-license
5   * Copyright 2003 James Bursa <bursa@users.sourceforge.net>   * Copyright 2004 James Bursa <bursa@users.sourceforge.net>
6   */   */
7    
8  /*  /*
# Line 32  Line 32 
32    
33    
34  bool start;  bool start;
35    bool html = false;
36  CURL *curl;  CURL *curl;
37  int status_code;  int status_code;
38  char error_buffer[CURL_ERROR_SIZE];  char error_buffer[CURL_ERROR_SIZE];
39  regex_t re_status_line, re_token, re_token_value, re_content_type, re_ugly,  regex_t re_status_line, re_token, re_token_value, re_content_type, re_ugly,
40      re_absolute_uri, re_etag, re_server, re_transfer_coding, re_upgrade,      re_absolute_uri, re_etag, re_server, re_transfer_coding, re_upgrade,
41      re_rfc1123, re_rfc1036, re_asctime;      re_rfc1123, re_rfc1036, re_asctime, re_cookie_nameval, re_cookie_expires;
42    
43    
44  void init(void);  void init(void);
# Line 81  void header_transfer_encoding_callback(c Line 82  void header_transfer_encoding_callback(c
82  void header_upgrade(const char *s);  void header_upgrade(const char *s);
83  void header_vary(const char *s);  void header_vary(const char *s);
84  void header_via(const char *s);  void header_via(const char *s);
85    void header_set_cookie(const char *s);
86  void die(const char *error);  void die(const char *error);
 void warning(const char *message);  
 void error(const char *message);  
87  void print(const char *s, size_t len);  void print(const char *s, size_t len);
88  void lookup(const char *key);  void lookup(const char *key);
89    
# Line 114  struct header_entry { Line 114  struct header_entry {
114    { "Pragma", header_pragma, 0, 0 },    { "Pragma", header_pragma, 0, 0 },
115    { "Retry-After", header_retry_after, 0, 0 },    { "Retry-After", header_retry_after, 0, 0 },
116    { "Server", header_server, 0, 0 },    { "Server", header_server, 0, 0 },
117      { "Set-Cookie", header_set_cookie, 0, 0 },
118    { "Trailer", header_trailer, 0, 0 },    { "Trailer", header_trailer, 0, 0 },
119    { "Transfer-Encoding", header_transfer_encoding, 0, 0 },    { "Transfer-Encoding", header_transfer_encoding, 0, 0 },
120    { "Upgrade", header_upgrade, 0, 0 },    { "Upgrade", header_upgrade, 0, 0 },
# Line 127  struct header_entry { Line 128  struct header_entry {
128   */   */
129  int main(int argc, char *argv[])  int main(int argc, char *argv[])
130  {  {
131    int i;    int i = 1;
132    
133    if (argc < 2)    if (argc < 2)
134      die("Usage: httplint url [url ...]");      die("Usage: httplint [--html] url [url ...]");
135    
136    init();    init();
137    
138    for (i = 1; i != argc; i++)    if (1 < argc && strcmp(argv[1], "--html") == 0) {
139        html = true;
140        i++;
141      }
142    
143      for (; i != argc; i++)
144      check_url(argv[i]);      check_url(argv[i]);
145    
146    curl_global_cleanup();    curl_global_cleanup();
# Line 177  void init(void) Line 183  void init(void)
183        "^HTTP/([0-9]+)[.]([0-9]+) ([0-9][0-9][0-9]) ([\t -~€-ÿ]*)$",        "^HTTP/([0-9]+)[.]([0-9]+) ([0-9][0-9][0-9]) ([\t -~€-ÿ]*)$",
184        REG_EXTENDED);        REG_EXTENDED);
185    regcomp_wrapper(&re_token,    regcomp_wrapper(&re_token,
186        "^([-0-9a-zA-Z_.]+)",        "^([-0-9a-zA-Z_.!]+)",
187        REG_EXTENDED);        REG_EXTENDED);
188    regcomp_wrapper(&re_token_value,    regcomp_wrapper(&re_token_value,
189        "^([-0-9a-zA-Z_.]+)(=([-0-9a-zA-Z_.]+|\"([^\"]|[\\].)*\"))?",        "^([-0-9a-zA-Z_.!]+)(=([-0-9a-zA-Z_.!]+|\"([^\"]|[\\].)*\"))?",
190        REG_EXTENDED);        REG_EXTENDED);
191    regcomp_wrapper(&re_content_type,    regcomp_wrapper(&re_content_type,
192        "^([-0-9a-zA-Z_.]+)/([-0-9a-zA-Z_.]+)[ \t]*"        "^([-0-9a-zA-Z_.]+)/([-0-9a-zA-Z_.]+)[ \t]*"
# Line 194  void init(void) Line 200  void init(void)
200        "^(W/[ \t]*)?\"([^\"]|[\\].)*\"$",        "^(W/[ \t]*)?\"([^\"]|[\\].)*\"$",
201        REG_EXTENDED);        REG_EXTENDED);
202    regcomp_wrapper(&re_server,    regcomp_wrapper(&re_server,
203        "^((([-0-9a-zA-Z_.]+(/[-0-9a-zA-Z_.]+)?)|(\\(.*\\)))[ \t]*)+$",        "^((([-0-9a-zA-Z_.!]+(/[-0-9a-zA-Z_.]+)?)|(\\(.*\\)))[ \t]*)+$",
204        REG_EXTENDED);        REG_EXTENDED);
205    regcomp_wrapper(&re_transfer_coding,    regcomp_wrapper(&re_transfer_coding,
206        "^([-0-9a-zA-Z_.]+)[ \t]*"        "^([-0-9a-zA-Z_.]+)[ \t]*"
# Line 205  void init(void) Line 211  void init(void)
211        "^([-0-9a-zA-Z_.](/[-0-9a-zA-Z_.])?)+$",        "^([-0-9a-zA-Z_.](/[-0-9a-zA-Z_.])?)+$",
212        REG_EXTENDED);        REG_EXTENDED);
213    regcomp_wrapper(&re_ugly,    regcomp_wrapper(&re_ugly,
214        "^[a-zA-Z0-9]+://[^/]+[/a-zA-Z0-9-_]*$",        "^[a-zA-Z0-9]+://[^/]+[-/a-zA-Z0-9_]*$",
215        REG_EXTENDED);        REG_EXTENDED);
216    regcomp_wrapper(&re_rfc1123,    regcomp_wrapper(&re_rfc1123,
217        "^(Mon|Tue|Wed|Thu|Fri|Sat|Sun), ([0123][0-9]) "        "^(Mon|Tue|Wed|Thu|Fri|Sat|Sun), ([0123][0-9]) "
# Line 222  void init(void) Line 228  void init(void)
228        "(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) ([ 12][0-9]) "        "(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) ([ 12][0-9]) "
229        "([012][0-9]):([0-5][0-9]):([0-5][0-9]) ([0-9]{4})$",        "([012][0-9]):([0-5][0-9]):([0-5][0-9]) ([0-9]{4})$",
230        REG_EXTENDED);        REG_EXTENDED);
231      regcomp_wrapper(&re_cookie_nameval,
232          "^[^;, ]+=[^;, ]*$",
233          REG_EXTENDED);
234      regcomp_wrapper(&re_cookie_expires,
235          "^(Mon|Tue|Wed|Thu|Fri|Sat|Sun), ([0123][0-9])-"
236          "(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)-([0-9]{4}) "
237          "([012][0-9]):([0-5][0-9]):([0-5][0-9]) GMT$",
238          REG_EXTENDED);
239  }  }
240    
241    
# Line 253  void check_url(const char *url) Line 267  void check_url(const char *url)
267    for (i = 0; i != sizeof header_table / sizeof header_table[0]; i++)    for (i = 0; i != sizeof header_table / sizeof header_table[0]; i++)
268      header_table[i].count = 0;      header_table[i].count = 0;
269    
270    printf("Checking URL %s\n", url);    if (!html)
271    if (strncmp(url, "http", 4))      printf("Checking URL %s\n", url);
272      warning("this is not an http or https url");    if (strncmp(url, "http", 4)) {
273        if (html)
274          printf("<p class='warning'>");
275        printf("Warning: this is not an http or https url");
276        if (html)
277          printf("</p>");
278        printf("\n");
279      }
280    
281    if (curl_easy_setopt(curl, CURLOPT_URL, url))    if (curl_easy_setopt(curl, CURLOPT_URL, url))
282      die("Failed to set curl options");      die("Failed to set curl options");
283    
284      if (html)
285        printf("<ul>\n");
286    code = curl_easy_perform(curl);    code = curl_easy_perform(curl);
287      if (html)
288        printf("</ul>\n");
289    if (code != CURLE_OK && code != CURLE_WRITE_ERROR) {    if (code != CURLE_OK && code != CURLE_WRITE_ERROR) {
290      error(error_buffer);      if (html)
291          printf("<p class='error'>");
292        printf("Error: ");
293        print(error_buffer, strlen(error_buffer));
294        printf(".");
295        if (html)
296          printf("</p>");
297        printf("\n");
298      return;      return;
299    } else {    } else {
300      printf("\n");      printf("\n");
301        if (html)
302          printf("<ul>");
303      for (i = 0; i != sizeof header_table / sizeof header_table[0]; i++) {      for (i = 0; i != sizeof header_table / sizeof header_table[0]; i++) {
304        if (header_table[i].count == 0 && header_table[i].missing)        if (header_table[i].count == 0 && header_table[i].missing)
305          lookup(header_table[i].missing);          lookup(header_table[i].missing);
# Line 275  void check_url(const char *url) Line 309  void check_url(const char *url)
309    r = regexec(&re_ugly, url, 0, 0, 0);    r = regexec(&re_ugly, url, 0, 0, 0);
310    if (r)    if (r)
311      lookup("ugly");      lookup("ugly");
312    
313      if (html)
314        printf("</ul>");
315  }  }
316    
317    
# Line 288  size_t header_callback(char *ptr, size_t Line 325  size_t header_callback(char *ptr, size_t
325    
326    UNUSED(stream);    UNUSED(stream);
327    
328    printf("* ");    printf(html ? "<li><code>" : "* ");
329    print(ptr, size);    print(ptr, size);
330    printf("\n");    printf(html ? "</code><ul>" : "\n");
331    
332    if (size < 2 || ptr[size - 2] != 13 || ptr[size - 1] != 10) {    if (size < 2 || ptr[size - 2] != 13 || ptr[size - 1] != 10) {
333      lookup("notcrlf");      lookup("notcrlf");
334        if (html)
335          printf("</ul></li>\n");
336      return size;      return size;
337    }    }
338    if (sizeof s <= size) {    if (sizeof s <= size) {
339      warning("header too long: ignored\n");      lookup("headertoolong");
340        if (html)
341          printf("</ul></li>\n");
342      return size;      return size;
343    }    }
344    strncpy(s, ptr, size);    strncpy(s, ptr, size);
# Line 308  size_t header_callback(char *ptr, size_t Line 349  size_t header_callback(char *ptr, size_t
349    
350    if (s[0] == 0) {    if (s[0] == 0) {
351      /* empty header indicates end of headers */      /* empty header indicates end of headers */
352      puts("End of headers.");      lookup("endofheaders");
353        if (html)
354          printf("</ul></li>\n");
355      return 0;      return 0;
356    
357    } else if (start) {    } else if (start) {
# Line 326  size_t header_callback(char *ptr, size_t Line 369  size_t header_callback(char *ptr, size_t
369      check_header(name, skip_lws(value));      check_header(name, skip_lws(value));
370    }    }
371    
372      if (html)
373        printf("</ul></li>\n");
374    return size;    return size;
375  }  }
376    
# Line 398  void check_header(const char *name, cons Line 443  void check_header(const char *name, cons
443    if (header) {    if (header) {
444      header->count++;      header->count++;
445      header->handler(value);      header->handler(value);
446    } else    } else if ((name[0] == 'X' || name[0] == 'x') && name[1] == '-') {
447        lookup("xheader");
448      } else {
449      lookup("nonstandard");      lookup("nonstandard");
450      }
451  }  }
452    
453    
# Line 412  bool parse_date(const char *s, struct tm Line 460  bool parse_date(const char *s, struct tm
460    int len = strlen(s);    int len = strlen(s);
461    regmatch_t pmatch[20];    regmatch_t pmatch[20];
462    
463      tm->tm_isdst = 0;
464      tm->tm_gmtoff = 0;
465      tm->tm_zone = "GMT";
466    
467    if (len == 29) {    if (len == 29) {
468      /* RFC 1123 */      /* RFC 1123 */
469      r = regexec(&re_rfc1123, s, 20, pmatch, 0);      r = regexec(&re_rfc1123, s, 20, pmatch, 0);
# Line 554  bool parse_list(const char *s, regex_t * Line 606  bool parse_list(const char *s, regex_t *
606    do {    do {
607      r = regexec(preg, s, 20, pmatch, 0);      r = regexec(preg, s, 20, pmatch, 0);
608      if (r) {      if (r) {
609          if (html)
610            printf("<li class='error'>");
611        printf("    Failed to match list item %i\n", items + 1);        printf("    Failed to match list item %i\n", items + 1);
612          if (html)
613            printf("</li>\n");
614        return false;        return false;
615      }      }
616    
# Line 567  bool parse_list(const char *s, regex_t * Line 623  bool parse_list(const char *s, regex_t *
623      if (*s == 0)      if (*s == 0)
624        break;        break;
625      if (*s != ',') {      if (*s != ',') {
626          if (html)
627            printf("<li class='error'>");
628        printf("    Expecting , after list item %i\n", items);        printf("    Expecting , after list item %i\n", items);
629          if (html)
630            printf("</li>\n");
631        return false;        return false;
632      }      }
633      while (*s == ',')      while (*s == ',')
# Line 575  bool parse_list(const char *s, regex_t * Line 635  bool parse_list(const char *s, regex_t *
635    } while (*s != 0);    } while (*s != 0);
636    
637    if (items < n || m < items) {    if (items < n || m < items) {
638        if (html)
639          printf("<li class='error'>");
640      printf("    %i items in list, but there should be ", items);      printf("    %i items in list, but there should be ", items);
641      if (m == UINT_MAX)      if (m == UINT_MAX)
642        printf("at least %i\n", n);        printf("at least %i\n", n);
643      else      else
644        printf("between %i and %i\n", n, m);        printf("between %i and %i\n", n, m);
645        if (html)
646          printf("</li>\n");
647      return false;      return false;
648    }    }
649    
# Line 649  void header_cache_control_callback(const Line 713  void header_cache_control_callback(const
713        (int (*)(const void *, const void *)) strcasecmp);        (int (*)(const void *, const void *)) strcasecmp);
714    
715    if (!dir) {    if (!dir) {
716      printf("    Cache-Control directive '%s':\n", name);      if (html)
717          printf("<li class='warning'>");
718        printf("    Cache-Control directive '");
719        print(name, strlen(name));
720        printf("':\n");
721        if (html)
722          printf("</li>\n");
723      lookup("unknowncachecont");      lookup("unknowncachecont");
724    }    }
725  }  }
# Line 694  void header_content_encoding_callback(co Line 764  void header_content_encoding_callback(co
764        sizeof content_coding_list[0],        sizeof content_coding_list[0],
765        (int (*)(const void *, const void *)) strcasecmp);        (int (*)(const void *, const void *)) strcasecmp);
766    if (!dir) {    if (!dir) {
767        if (html)
768          printf("<li class='warning'>");
769      printf("    Content-Encoding '%s':\n", name);      printf("    Content-Encoding '%s':\n", name);
770        if (html)
771          printf("</li>\n");
772      lookup("unknowncontenc");      lookup("unknowncontenc");
773    }    }
774  }  }
# Line 817  void header_last_modified(const char *s) Line 891  void header_last_modified(const char *s)
891    time0 = time(0);    time0 = time(0);
892    if (!parse_date(s, &tm))    if (!parse_date(s, &tm))
893      return;      return;
894    time1 = mktime(&tm);    time1 = mktime_from_utc(&tm);
895    
896    diff = difftime(time1, time0);    diff = difftime(time1, time0);
897    if (10 < diff)    if (10 < diff)
# Line 909  void header_transfer_encoding_callback(c Line 983  void header_transfer_encoding_callback(c
983        sizeof transfer_coding_list[0],        sizeof transfer_coding_list[0],
984        (int (*)(const void *, const void *)) strcasecmp);        (int (*)(const void *, const void *)) strcasecmp);
985    if (!dir) {    if (!dir) {
986        if (html)
987          printf("<li class='warning'>");
988      printf("    Transfer-Encoding '%s':\n", name);      printf("    Transfer-Encoding '%s':\n", name);
989        if (html)
990          printf("</li>\n");
991      lookup("unknowntransenc");      lookup("unknowntransenc");
992    }    }
993  }  }
# Line 938  void header_via(const char *s) Line 1016  void header_via(const char *s)
1016    lookup("via");    lookup("via");
1017  }  }
1018    
1019    /* http://wp.netscape.com/newsref/std/cookie_spec.html */
1020  /**  void header_set_cookie(const char *s)
  * Print an error message and exit.  
  */  
 void die(const char *error)  
1021  {  {
1022    fprintf(stderr, "httplint: %s\n", error);    bool ok = true;
1023    exit(EXIT_FAILURE);    int r;
1024  }    const char *semi = strchr(s, ';');
1025      const char *s2;
1026      struct tm tm;
1027      double diff;
1028      time_t time0, time1;
1029      regmatch_t pmatch[20];
1030    
1031      if (semi)
1032        s2 = strndup(s, semi - s);
1033      else
1034        s2 = s;
1035    
1036  /**    r = regexec(&re_cookie_nameval, s2, 0, 0, 0);
1037   * Print a warning message.    if (r) {
1038   */      lookup("cookiebadnameval");
1039  void warning(const char *message)      ok = false;
1040  {    }
1041    printf("Warning: %s\n", message);  
1042      if (!semi)
1043        return;
1044    
1045      s = skip_lws(semi + 1);
1046    
1047      while (*s) {
1048        semi = strchr(s, ';');
1049        if (semi)
1050          s2 = strndup(s, semi - s);
1051        else
1052          s2 = s;
1053    
1054        if (strncasecmp(s2, "expires=", 8) == 0) {
1055          s2 += 8;
1056          r = regexec(&re_cookie_expires, s2, 20, pmatch, 0);
1057          if (r == 0) {
1058            tm.tm_mday = atoi(s2 + pmatch[2].rm_so);
1059            tm.tm_mon = month(s2 + pmatch[3].rm_so);
1060            tm.tm_year = atoi(s2 + pmatch[4].rm_so) - 1900;
1061            tm.tm_hour = atoi(s2 + pmatch[5].rm_so);
1062            tm.tm_min = atoi(s2 + pmatch[6].rm_so);
1063            tm.tm_sec = atoi(s2 + pmatch[7].rm_so);
1064    
1065            time0 = time(0);
1066            time1 = mktime_from_utc(&tm);
1067    
1068            diff = difftime(time0, time1);
1069            if (10 < diff) {
1070              lookup("cookiepastdate");
1071              ok = false;
1072            }
1073          } else {
1074            lookup("cookiebaddate");
1075            ok = false;
1076          }
1077        } else if (strncasecmp(s2, "domain=", 7) == 0) {
1078        } else if (strncasecmp(s2, "path=", 5) == 0) {
1079          if (s2[5] != '/') {
1080            lookup("cookiebadpath");
1081            ok = false;
1082          }
1083        } else if (strcasecmp(s, "secure") == 0) {
1084        } else {
1085          if (html)
1086            printf("<li class='warning'>");
1087          printf("    Set-Cookie field '%s':\n", s2);
1088          if (html)
1089            printf("</li>\n");
1090          lookup("cookieunknownfield");
1091          ok = false;
1092        }
1093    
1094        if (semi)
1095          s = skip_lws(semi + 1);
1096        else
1097          break;
1098      }
1099    
1100      if (ok)
1101        lookup("ok");
1102  }  }
1103    
1104    
1105  /**  /**
1106   * Print an error message.   * Print an error message and exit.
1107   */   */
1108  void error(const char *message)  void die(const char *error)
1109  {  {
1110    printf("Error: %s\n", message);    fprintf(stderr, "httplint: %s\n", error);
1111      exit(EXIT_FAILURE);
1112  }  }
1113    
1114    
# Line 974  void print(const char *s, size_t len) Line 1119  void print(const char *s, size_t len)
1119  {  {
1120    size_t i;    size_t i;
1121    for (i = 0; i != len; i++) {    for (i = 0; i != len; i++) {
1122      if (31 < s[i] && s[i] < 127)      if (html && s[i] == '<')
1123          printf("&lt;");
1124        else if (html && s[i] == '>')
1125          printf("&gt;");
1126        else if (html && s[i] == '&')
1127          printf("&amp;");
1128        else if (31 < s[i] && s[i] < 127)
1129        putchar(s[i]);        putchar(s[i]);
1130      else      else {
1131          if (html)
1132            printf("<span class='cc'>");
1133        printf("[%.2x]", s[i]);        printf("[%.2x]", s[i]);
1134          if (html)
1135            printf("</span>");
1136        }
1137    }    }
1138  }  }
1139    
# Line 1042  struct message_entry { Line 1198  struct message_entry {
1198                    "of header names, or \"*\"." },                    "of header names, or \"*\"." },
1199    { "contentrange", "Warning: The Content-Range header should not be returned "    { "contentrange", "Warning: The Content-Range header should not be returned "
1200                      "by the server for this request." },                      "by the server for this request." },
1201      { "cookiebaddate", "Error: The expires date must be in the form "
1202                         "\"Wdy, DD-Mon-YYYY HH:MM:SS GMT\"." },
1203      { "cookiebadnameval", "Error: A Set-Cookie header must start with "
1204                            "name=value, each excluding semi-colon, comma and "
1205                            "white space." },
1206      { "cookiebadpath", "Error: The path does not start with \"/\"." },
1207      { "cookiepastdate", "Warning: The expires date is in the past. The cookie "
1208                          "will be deleted by browsers." },
1209      { "cookieunknownfield", "Warning: This is not a standard Set-Cookie "
1210                              "field." },
1211      { "endofheaders", "End of headers." },
1212    { "futurehttp", "Warning: I only understand HTTP/1.1. Check for a newer "    { "futurehttp", "Warning: I only understand HTTP/1.1. Check for a newer "
1213                    "version of this tool." },                    "version of this tool." },
1214    { "futurelastmod", "Error: The specified Last-Modified date-time is in "    { "futurelastmod", "Error: The specified Last-Modified date-time is in "
1215                       "the future." },                       "the future." },
1216      { "headertoolong", "Warning: Header too long: ignored." },
1217    { "missingcolon", "Error: Headers must be of the form 'Name: value'." },    { "missingcolon", "Error: Headers must be of the form 'Name: value'." },
1218    { "missingcontenttype", "Warning: No Content-Type header was present. The "    { "missingcontenttype", "Warning: No Content-Type header was present. The "
1219                            "client will have to guess the media type or ask "                            "client will have to guess the media type or ask "
# Line 1086  struct message_entry { Line 1254  struct message_entry {
1254    { "via", "This header was added by a proxy, cache or gateway." },    { "via", "This header was added by a proxy, cache or gateway." },
1255    { "wrongdate", "Warning: The server date-time differs from this system's "    { "wrongdate", "Warning: The server date-time differs from this system's "
1256                   "date-time by more than 10 seconds. Check that both the "                   "date-time by more than 10 seconds. Check that both the "
1257                   "system clocks are correct." }                   "system clocks are correct." },
1258      { "xheader", "This is an extension header. I don't know how to check it." }
1259  };  };
1260    
1261    
# Line 1108  void lookup(const char *key) Line 1277  void lookup(const char *key)
1277    else    else
1278      s = key;      s = key;
1279    
1280    printf("    ");    if (html) {
1281    x = 4;      if (strncmp(s, "Warning:", 8) == 0)
1282    while (*s) {        printf("<li class='warning'>");
1283      spc = strchr(s, ' ');      else if (strncmp(s, "Error:", 6) == 0)
1284      if (!spc)        printf("<li class='error'>");
1285        spc = s + strlen(s);      else if (strncmp(s, "OK", 2) == 0)
1286      if (75 < x + (spc - s)) {        printf("<li class='ok'>");
       printf("\n    ");  
       x = 4;  
     }  
     x += spc - s + 1;  
     printf("%.*s ", spc - s, s);  
     if (*spc)  
       s = spc + 1;  
1287      else      else
1288        s = spc;        printf("<li>");
1289        for (; *s; s++) {
1290          if (strncmp(s, "http://", 7) == 0) {
1291            spc = strchr(s, ' ');
1292            printf("<a href='%.*s'>%.*s</a>", spc - s, s, spc - s, s);
1293            s = spc;
1294          }
1295          switch (*s) {
1296            case '<': printf("&lt;"); break;
1297            case '>': printf("&gt;"); break;
1298            case '&': printf("&amp;"); break;
1299            default: printf("%c", *s); break;
1300          }
1301        }
1302        printf("</li>\n");
1303    
1304      } else {
1305        printf("    ");
1306        x = 4;
1307        while (*s) {
1308          spc = strchr(s, ' ');
1309          if (!spc)
1310            spc = s + strlen(s);
1311          if (75 < x + (spc - s)) {
1312            printf("\n    ");
1313            x = 4;
1314          }
1315          x += spc - s + 1;
1316          printf("%.*s ", spc - s, s);
1317          if (*spc)
1318            s = spc + 1;
1319          else
1320            s = spc;
1321        }
1322        printf("\n\n");
1323    }    }
   printf("\n\n");  
1324  }  }
1325    

Legend:
Removed from v.42  
changed lines
  Added in v.59

  ViewVC Help
Powered by ViewVC 1.1.26