/[jscoverage]/tags/jscoverage-0.4/jscoverage-server.c
ViewVC logotype

Diff of /tags/jscoverage-0.4/jscoverage-server.c

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

revision 133 by siliconforks, Thu Jun 19 05:53:29 2008 UTC revision 299 by siliconforks, Mon Oct 13 02:39:58 2008 UTC
# Line 22  Line 22 
22  #include <assert.h>  #include <assert.h>
23  #include <ctype.h>  #include <ctype.h>
24  #include <signal.h>  #include <signal.h>
25    #include <stdint.h>
26  #include <string.h>  #include <string.h>
27    
28  #include <dirent.h>  #include <dirent.h>
# Line 29  Line 30 
30  #include <pthread.h>  #include <pthread.h>
31  #endif  #endif
32    
33    #include "encoding.h"
34    #include "global.h"
35  #include "http-server.h"  #include "http-server.h"
36  #include "instrument-js.h"  #include "instrument-js.h"
37  #include "resource-manager.h"  #include "resource-manager.h"
38  #include "stream.h"  #include "stream.h"
39  #include "util.h"  #include "util.h"
40    
41    static const char * specified_encoding = NULL;
42    const char * jscoverage_encoding = "ISO-8859-1";
43    bool jscoverage_highlight = true;
44    
45  typedef struct SourceCache {  typedef struct SourceCache {
46    char * url;    char * url;
47    Stream * source;    uint16_t * characters;
48      size_t num_characters;
49    struct SourceCache * next;    struct SourceCache * next;
50  } SourceCache;  } SourceCache;
51    
# Line 78  Line 86 
86  #define UNLOCK pthread_mutex_unlock  #define UNLOCK pthread_mutex_unlock
87  #endif  #endif
88    
89  static Stream * find_cached_source(const char * url) {  static const SourceCache * find_cached_source(const char * url) {
90    Stream * result = NULL;    SourceCache * result = NULL;
91    LOCK(&source_cache_mutex);    LOCK(&source_cache_mutex);
92    for (SourceCache * p = source_cache; p != NULL; p = p->next) {    for (SourceCache * p = source_cache; p != NULL; p = p->next) {
93      if (strcmp(url, p->url) == 0) {      if (strcmp(url, p->url) == 0) {
94        result = p->source;        result = p;
95        break;        break;
96      }      }
97    }    }
# Line 91  Line 99 
99    return result;    return result;
100  }  }
101    
102  static void add_cached_source(const char * url, Stream * source) {  static void add_cached_source(const char * url, uint16_t * characters, size_t num_characters) {
103    SourceCache * new_source_cache = xmalloc(sizeof(SourceCache));    SourceCache * new_source_cache = xmalloc(sizeof(SourceCache));
104    new_source_cache->url = xstrdup(url);    new_source_cache->url = xstrdup(url);
105    new_source_cache->source = source;    new_source_cache->characters = characters;
106      new_source_cache->num_characters = num_characters;
107    LOCK(&source_cache_mutex);    LOCK(&source_cache_mutex);
108    new_source_cache->next = source_cache;    new_source_cache->next = source_cache;
109    source_cache = new_source_cache;    source_cache = new_source_cache;
110    UNLOCK(&source_cache_mutex);    UNLOCK(&source_cache_mutex);
111  }  }
112    
113  static int get(const char * url, Stream * stream) __attribute__((warn_unused_result));  static int get(const char * url, uint16_t ** characters, size_t * num_characters) __attribute__((warn_unused_result));
114    
115  static int get(const char * url, Stream * stream) {  static int get(const char * url, uint16_t ** characters, size_t * num_characters) {
116    char * host = NULL;    char * host = NULL;
117    uint16_t port;    uint16_t port;
118    char * abs_path = NULL;    char * abs_path = NULL;
119    char * query = NULL;    char * query = NULL;
120    HTTPConnection * connection = NULL;    HTTPConnection * connection = NULL;
121    HTTPExchange * exchange = NULL;    HTTPExchange * exchange = NULL;
122      Stream * stream = NULL;
123    
124    int result = URL_parse(url, &host, &port, &abs_path, &query);    int result = URL_parse(url, &host, &port, &abs_path, &query);
125    if (result != 0) {    if (result != 0) {
# Line 134  Line 144 
144      goto done;      goto done;
145    }    }
146    
147      stream = Stream_new(0);
148    result = HTTPExchange_read_entire_response_entity_body(exchange, stream);    result = HTTPExchange_read_entire_response_entity_body(exchange, stream);
149    if (result != 0) {    if (result != 0) {
150      goto done;      goto done;
151    }    }
152      char * encoding = HTTPMessage_get_charset(HTTPExchange_get_response_message(exchange));
153      if (encoding == NULL) {
154        encoding = xstrdup(jscoverage_encoding);
155      }
156      result = jscoverage_bytes_to_characters(encoding, stream->data, stream->length, characters, num_characters);
157      free(encoding);
158      if (result != 0) {
159        goto done;
160      }
161    
162    result = 0;    result = 0;
163    
164  done:  done:
165      if (stream != NULL) {
166        Stream_delete(stream);
167      }
168    if (exchange != NULL) {    if (exchange != NULL) {
169      HTTPExchange_delete(exchange);      HTTPExchange_delete(exchange);
170    }    }
# Line 215  Line 238 
238    return result;    return result;
239  }  }
240    
241    static unsigned int hex_value(char c) {
242      if ('0' <= c && c <= '9') {
243        return c - '0';
244      }
245      else if ('A' <= c && c <= 'F') {
246        return c - 'A' + 10;
247      }
248      else if ('a' <= c && c <= 'f') {
249        return c - 'a' + 10;
250      }
251      else {
252        return 0;
253      }
254    }
255    
256    static char * decode_uri_component(const char * s) {
257      size_t length = strlen(s);
258      char * result = xmalloc(length + 1);
259      char * p = result;
260      while (*s != '\0') {
261        if (*s == '%') {
262          if (s[1] == '\0' || s[2] == '\0') {
263            *p = '\0';
264            return result;
265          }
266          *p = hex_value(s[1]) * 16 + hex_value(s[2]);
267          s += 2;
268        }
269        else {
270          *p = *s;
271        }
272        p++;
273        s++;
274      }
275      *p = '\0';
276      return result;
277    }
278    
279  static const char * get_entity(char c) {  static const char * get_entity(char c) {
280    switch(c) {    switch(c) {
281    case '<':    case '<':
# Line 400  Line 461 
461    putc('"', f);    putc('"', f);
462  }  }
463    
464    static void write_source(const char * id, const uint16_t * characters, size_t num_characters, FILE * f) {
465      Stream * output = Stream_new(num_characters);
466      jscoverage_write_source(id, characters, num_characters, output);
467      fwrite(output->data, 1, output->length, f);
468      Stream_delete(output);
469    }
470    
471  static void write_json_for_file(const FileCoverage * file_coverage, int i, void * p) {  static void write_json_for_file(const FileCoverage * file_coverage, int i, void * p) {
472    FILE * f = p;    FILE * f = p;
473    
# Line 410  Line 478 
478    write_js_quoted_string(f, file_coverage->id, strlen(file_coverage->id));    write_js_quoted_string(f, file_coverage->id, strlen(file_coverage->id));
479    
480    fputs(":{\"coverage\":[", f);    fputs(":{\"coverage\":[", f);
481    for (uint32_t i = 0; i <= file_coverage->num_lines; i++) {    for (uint32_t i = 0; i < file_coverage->num_coverage_lines; i++) {
482      if (i > 0) {      if (i > 0) {
483        putc(',', f);        putc(',', f);
484      }      }
485      int timesExecuted = file_coverage->lines[i];      int timesExecuted = file_coverage->coverage_lines[i];
486      if (timesExecuted < 0) {      if (timesExecuted < 0) {
487        fputs("null", f);        fputs("null", f);
488      }      }
# Line 423  Line 491 
491      }      }
492    }    }
493    fputs("],\"source\":", f);    fputs("],\"source\":", f);
494    if (file_coverage->source == NULL) {    if (file_coverage->source_lines == NULL) {
495      if (proxy) {      if (proxy) {
496        Stream * stream = find_cached_source(file_coverage->id);        const SourceCache * cached = find_cached_source(file_coverage->id);
497        if (stream == NULL) {        if (cached == NULL) {
498          stream = Stream_new(0);          uint16_t * characters;
499          if (get(file_coverage->id, stream) == 0) {          size_t num_characters;
500            write_js_quoted_string(f, stream->data, stream->length);          if (get(file_coverage->id, &characters, &num_characters) == 0) {
501            add_cached_source(file_coverage->id, stream);            write_source(file_coverage->id, characters, num_characters, f);
502              add_cached_source(file_coverage->id, characters, num_characters);
503          }          }
504          else {          else {
505            fputs("\"\"", f);            fputs("[]", f);
506            HTTPServer_log_err("Warning: cannot retrieve URL: %s\n", file_coverage->id);            HTTPServer_log_err("Warning: cannot retrieve URL: %s\n", file_coverage->id);
           Stream_delete(stream);  
507          }          }
508        }        }
509        else {        else {
510          write_js_quoted_string(f, stream->data, stream->length);          write_source(file_coverage->id, cached->characters, cached->num_characters, f);
511        }        }
512      }      }
513      else {      else {
# Line 449  Line 517 
517          FILE * source_file = fopen(source_path, "rb");          FILE * source_file = fopen(source_path, "rb");
518          free(source_path);          free(source_path);
519          if (source_file == NULL) {          if (source_file == NULL) {
520            fputs("\"\"", f);            fputs("[]", f);
521            HTTPServer_log_err("Warning: cannot open file: %s\n", file_coverage->id);            HTTPServer_log_err("Warning: cannot open file: %s\n", file_coverage->id);
522          }          }
523          else {          else {
524            Stream * stream = Stream_new(0);            Stream * stream = Stream_new(0);
525            Stream_write_file_contents(stream, source_file);            Stream_write_file_contents(stream, source_file);
526            fclose(source_file);            fclose(source_file);
527            write_js_quoted_string(f, stream->data, stream->length);            uint16_t * characters;
528              size_t num_characters;
529              int result = jscoverage_bytes_to_characters(jscoverage_encoding, stream->data, stream->length, &characters, &num_characters);
530            Stream_delete(stream);            Stream_delete(stream);
531              if (result == JSCOVERAGE_ERROR_ENCODING_NOT_SUPPORTED) {
532                fputs("[]", f);
533                HTTPServer_log_err("Warning: encoding %s not supported\n", jscoverage_encoding);
534              }
535              else if (result == JSCOVERAGE_ERROR_INVALID_BYTE_SEQUENCE) {
536                fputs("[]", f);
537                HTTPServer_log_err("Warning: error decoding %s in file %s\n", jscoverage_encoding, file_coverage->id);
538              }
539              else {
540                write_source(file_coverage->id, characters, num_characters, f);
541                free(characters);
542              }
543          }          }
544        }        }
545        else {        else {
546          /* path does not begin with / */          /* path does not begin with / */
547          fputs("\"\"", f);          fputs("[]", f);
548          HTTPServer_log_err("Warning: invalid source path: %s\n", file_coverage->id);          HTTPServer_log_err("Warning: invalid source path: %s\n", file_coverage->id);
549        }        }
550      }      }
551    }    }
552    else {    else {
553      write_js_quoted_string(f, file_coverage->source, strlen(file_coverage->source));      fputc('[', f);
554        for (uint32_t i = 0; i < file_coverage->num_source_lines; i++) {
555          if (i > 0) {
556            fputc(',', f);
557          }
558          char * source_line = file_coverage->source_lines[i];
559          write_js_quoted_string(f, source_line, strlen(source_line));
560        }
561        fputc(']', f);
562    }    }
563    fputc('}', f);    fputc('}', f);
564  }  }
# Line 477  Line 567 
567    
568  static int write_json(Coverage * coverage, const char * path) {  static int write_json(Coverage * coverage, const char * path) {
569    /* write the JSON */    /* write the JSON */
570    FILE * f = fopen(path, "w");    FILE * f = fopen(path, "wb");
571    if (f == NULL) {    if (f == NULL) {
572      return -1;      return -1;
573    }    }
# Line 525  Line 615 
615      }      }
616    
617      mkdir_if_necessary(report_directory);      mkdir_if_necessary(report_directory);
618      char * path = make_path(report_directory, "jscoverage.json");      char * current_report_directory;
619        if (str_starts_with(abs_path, "/jscoverage-store/") && abs_path[18] != '\0') {
620          char * dir = decode_uri_component(abs_path + 18);
621          current_report_directory = make_path(report_directory, dir);
622          free(dir);
623        }
624        else {
625          current_report_directory = xstrdup(report_directory);
626        }
627        mkdir_if_necessary(current_report_directory);
628        char * path = make_path(current_report_directory, "jscoverage.json");
629    
630      /* check if the JSON file exists */      /* check if the JSON file exists */
631      struct stat buf;      struct stat buf;
632      if (stat(path, &buf) == 0) {      if (stat(path, &buf) == 0) {
633        /* it exists: merge */        /* it exists: merge */
634        FILE * f = fopen(path, "r");        FILE * f = fopen(path, "rb");
635        if (f == NULL) {        if (f == NULL) {
636          result = 1;          result = 1;
637        }        }
# Line 542  Line 642 
642          }          }
643        }        }
644        if (result != 0) {        if (result != 0) {
645            free(current_report_directory);
646          free(path);          free(path);
647          Coverage_delete(coverage);          Coverage_delete(coverage);
648          send_response(exchange, 500, "Could not merge with existing coverage data\n");          send_response(exchange, 500, "Could not merge with existing coverage data\n");
# Line 553  Line 654 
654      free(path);      free(path);
655      Coverage_delete(coverage);      Coverage_delete(coverage);
656      if (result != 0) {      if (result != 0) {
657          free(current_report_directory);
658        send_response(exchange, 500, "Could not write coverage data\n");        send_response(exchange, 500, "Could not write coverage data\n");
659        return;        return;
660      }      }
661    
662      /* copy other files */      /* copy other files */
663      jscoverage_copy_resources(report_directory);      jscoverage_copy_resources(current_report_directory);
664      path = make_path(report_directory, "jscoverage.js");      path = make_path(current_report_directory, "jscoverage.js");
665        free(current_report_directory);
666      FILE * f = fopen(path, "ab");      FILE * f = fopen(path, "ab");
667      free(path);      free(path);
668      if (f == NULL) {      if (f == NULL) {
# Line 608  Line 711 
711        return;        return;
712      }      }
713      if (strcmp(abs_path, "/jscoverage.js") == 0) {      if (strcmp(abs_path, "/jscoverage.js") == 0) {
714        const char * s = "jscoverage_isServer = true;\r\n";        const char * s = "jscoverage_isServer = true;\n";
715        if (HTTPExchange_write_response(exchange, s, strlen(s)) != 0) {        if (HTTPExchange_write_response(exchange, s, strlen(s)) != 0) {
716          HTTPServer_log_err("Warning: error writing to client\n");          HTTPServer_log_err("Warning: error writing to client\n");
717        }        }
# Line 616  Line 719 
719    }    }
720  }  }
721    
722  static void instrument_js(const char * id, Stream * input_stream, Stream * output_stream) {  static void instrument_js(const char * id, const uint16_t * characters, size_t num_characters, Stream * output_stream) {
   LOCK(&javascript_mutex);  
   jscoverage_instrument_js(id, input_stream, output_stream);  
   UNLOCK(&javascript_mutex);  
   
723    const struct Resource * resource = get_resource("report.js");    const struct Resource * resource = get_resource("report.js");
724    Stream_write(output_stream, resource->data, resource->length);    Stream_write(output_stream, resource->data, resource->length);
725    
726      LOCK(&javascript_mutex);
727      jscoverage_instrument_js(id, characters, num_characters, output_stream);
728      UNLOCK(&javascript_mutex);
729  }  }
730    
731  static bool is_hop_by_hop_header(const char * h) {  static bool is_hop_by_hop_header(const char * h) {
# Line 740  Line 843 
843      }      }
844    
845      const char * request_uri = HTTPExchange_get_request_uri(client_exchange);      const char * request_uri = HTTPExchange_get_request_uri(client_exchange);
846        char * encoding = HTTPMessage_get_charset(HTTPExchange_get_response_message(server_exchange));
847        if (encoding == NULL) {
848          encoding = xstrdup(jscoverage_encoding);
849        }
850        uint16_t * characters;
851        size_t num_characters;
852        int result = jscoverage_bytes_to_characters(encoding, input_stream->data, input_stream->length, &characters, &num_characters);
853        free(encoding);
854        Stream_delete(input_stream);
855        if (result == JSCOVERAGE_ERROR_ENCODING_NOT_SUPPORTED) {
856          send_response(client_exchange, 502, "Encoding not supported\n");
857          goto done;
858        }
859        else if (result == JSCOVERAGE_ERROR_INVALID_BYTE_SEQUENCE) {
860          send_response(client_exchange, 502, "Error decoding response\n");
861          goto done;
862        }
863    
864      Stream * output_stream = Stream_new(0);      Stream * output_stream = Stream_new(0);
865      instrument_js(request_uri, input_stream, output_stream);      instrument_js(request_uri, characters, num_characters, output_stream);
866    
867      /* send the headers to the client */      /* send the headers to the client */
868      for (const HTTPHeader * h = HTTPExchange_get_response_headers(server_exchange); h != NULL; h = h->next) {      for (const HTTPHeader * h = HTTPExchange_get_response_headers(server_exchange); h != NULL; h = h->next) {
869        if (is_hop_by_hop_header(h->name) || strcasecmp(h->name, HTTP_CONTENT_LENGTH) == 0) {        if (is_hop_by_hop_header(h->name) || strcasecmp(h->name, HTTP_CONTENT_LENGTH) == 0) {
870          continue;          continue;
871        }        }
872          else if (strcasecmp(h->name, HTTP_CONTENT_TYPE) == 0) {
873            HTTPExchange_add_response_header(client_exchange, HTTP_CONTENT_TYPE, "text/javascript; charset=ISO-8859-1");
874            continue;
875          }
876        HTTPExchange_add_response_header(client_exchange, h->name, h->value);        HTTPExchange_add_response_header(client_exchange, h->name, h->value);
877      }      }
878      add_via_header(HTTPExchange_get_response_message(client_exchange), HTTPExchange_get_response_http_version(server_exchange));      add_via_header(HTTPExchange_get_response_message(client_exchange), HTTPExchange_get_response_http_version(server_exchange));
# Line 758  Line 883 
883        HTTPServer_log_err("Warning: error writing to client\n");        HTTPServer_log_err("Warning: error writing to client\n");
884      }      }
885    
886      /* input_stream goes on the cache */      /* characters go on the cache */
887      /*      /*
888      Stream_delete(input_stream);      free(characters);
889      */      */
890      Stream_delete(output_stream);      Stream_delete(output_stream);
891      add_cached_source(request_uri, input_stream);      add_cached_source(request_uri, characters, num_characters);
892    }    }
893    else {    else {
894      /* does not need instrumentation */      /* does not need instrumentation */
# Line 811  Line 936 
936    /* add the `Server' response-header (RFC 2616 14.38, 3.8) */    /* add the `Server' response-header (RFC 2616 14.38, 3.8) */
937    HTTPExchange_add_response_header(exchange, HTTP_SERVER, "jscoverage-server/" VERSION);    HTTPExchange_add_response_header(exchange, HTTP_SERVER, "jscoverage-server/" VERSION);
938    
939      char * decoded_path = NULL;
940    char * filesystem_path = NULL;    char * filesystem_path = NULL;
941    
942    const char * abs_path = HTTPExchange_get_abs_path(exchange);    const char * abs_path = HTTPExchange_get_abs_path(exchange);
943    assert(*abs_path != '\0');    assert(*abs_path != '\0');
944    
945    if (str_starts_with(abs_path, "/jscoverage")) {    decoded_path = decode_uri_component(abs_path);
946    
947      if (str_starts_with(decoded_path, "/jscoverage")) {
948      handle_jscoverage_request(exchange);      handle_jscoverage_request(exchange);
949      goto done;      goto done;
950    }    }
951    
952    if (strstr(abs_path, "..") != NULL) {    if (strstr(decoded_path, "..") != NULL) {
953      send_response(exchange, 403, "Forbidden\n");      send_response(exchange, 403, "Forbidden\n");
954      goto done;      goto done;
955    }    }
956    
957    filesystem_path = make_path(document_root, abs_path + 1);    filesystem_path = make_path(document_root, decoded_path + 1);
958    size_t filesystem_path_length = strlen(filesystem_path);    size_t filesystem_path_length = strlen(filesystem_path);
959    if (filesystem_path_length > 0 && filesystem_path[filesystem_path_length - 1] == '/') {    if (filesystem_path_length > 0 && filesystem_path[filesystem_path_length - 1] == '/') {
960      /* stat on Windows doesn't work with trailing slash */      /* stat on Windows doesn't work with trailing slash */
# Line 881  Line 1009 
1009        goto done;        goto done;
1010      }      }
1011    
1012        /*
1013        When do we send a charset with Content-Type?
1014        if Content-Type is "text" or "application"
1015          if instrumented JavaScript
1016            use Content-Type: application/javascript; charset=ISO-8859-1
1017          else if --encoding is given
1018            use that encoding
1019          else
1020            send no charset
1021        else
1022          send no charset
1023        */
1024      const char * content_type = get_content_type(filesystem_path);      const char * content_type = get_content_type(filesystem_path);
1025      HTTPExchange_set_response_header(exchange, HTTP_CONTENT_TYPE, content_type);      if (strcmp(content_type, "text/javascript") == 0 && ! is_no_instrument(abs_path)) {
1026      const char * request_uri = HTTPExchange_get_request_uri(exchange);        HTTPExchange_set_response_header(exchange, HTTP_CONTENT_TYPE, "text/javascript; charset=ISO-8859-1");
     if (strcmp(content_type, "text/javascript") == 0 && ! is_no_instrument(request_uri)) {  
       Stream * input_stream = Stream_new(0);  
       Stream * output_stream = Stream_new(0);  
1027    
1028          Stream * input_stream = Stream_new(0);
1029        Stream_write_file_contents(input_stream, f);        Stream_write_file_contents(input_stream, f);
1030    
1031        instrument_js(request_uri, input_stream, output_stream);        uint16_t * characters;
1032          size_t num_characters;
1033          int result = jscoverage_bytes_to_characters(jscoverage_encoding, input_stream->data, input_stream->length, &characters, &num_characters);
1034          Stream_delete(input_stream);
1035    
1036          if (result == JSCOVERAGE_ERROR_ENCODING_NOT_SUPPORTED) {
1037            send_response(exchange, 500, "Encoding not supported\n");
1038            goto done;
1039          }
1040          else if (result == JSCOVERAGE_ERROR_INVALID_BYTE_SEQUENCE) {
1041            send_response(exchange, 500, "Error decoding JavaScript file\n");
1042            goto done;
1043          }
1044    
1045          Stream * output_stream = Stream_new(0);
1046          instrument_js(abs_path, characters, num_characters, output_stream);
1047          free(characters);
1048    
1049        if (HTTPExchange_write_response(exchange, output_stream->data, output_stream->length) != 0) {        if (HTTPExchange_write_response(exchange, output_stream->data, output_stream->length) != 0) {
1050          HTTPServer_log_err("Warning: error writing to client\n");          HTTPServer_log_err("Warning: error writing to client\n");
1051        }        }
   
       Stream_delete(input_stream);  
1052        Stream_delete(output_stream);        Stream_delete(output_stream);
1053      }      }
1054      else {      else {
1055          /* send the Content-Type with charset if necessary */
1056          if (specified_encoding != NULL && (str_starts_with(content_type, "text/") || str_starts_with(content_type, "application/"))) {
1057            char * content_type_with_charset = NULL;
1058            xasprintf(&content_type_with_charset, "%s; charset=%s", content_type, specified_encoding);
1059            HTTPExchange_set_response_header(exchange, HTTP_CONTENT_TYPE, content_type_with_charset);
1060            free(content_type_with_charset);
1061          }
1062          else {
1063            HTTPExchange_set_response_header(exchange, HTTP_CONTENT_TYPE, content_type);
1064          }
1065    
1066        char buffer[8192];        char buffer[8192];
1067        size_t bytes_read;        size_t bytes_read;
1068        while ((bytes_read = fread(buffer, 1, 8192, f)) > 0) {        while ((bytes_read = fread(buffer, 1, 8192, f)) > 0) {
# Line 917  Line 1080 
1080    
1081  done:  done:
1082    free(filesystem_path);    free(filesystem_path);
1083      free(decoded_path);
1084  }  }
1085    
1086  static void handler(HTTPExchange * exchange) {  static void handler(HTTPExchange * exchange) {
# Line 957  Line 1121 
1121      else if (strcmp(argv[i], "--report-dir") == 0) {      else if (strcmp(argv[i], "--report-dir") == 0) {
1122        i++;        i++;
1123        if (i == argc) {        if (i == argc) {
1124          fatal("--report-dir: option requires an argument");          fatal_command_line("--report-dir: option requires an argument");
1125        }        }
1126        report_directory = argv[i];        report_directory = argv[i];
1127      }      }
# Line 968  Line 1132 
1132      else if (strcmp(argv[i], "--document-root") == 0) {      else if (strcmp(argv[i], "--document-root") == 0) {
1133        i++;        i++;
1134        if (i == argc) {        if (i == argc) {
1135          fatal("--document-root: option requires an argument");          fatal_command_line("--document-root: option requires an argument");
1136        }        }
1137        document_root = argv[i];        document_root = argv[i];
1138      }      }
# Line 976  Line 1140 
1140        document_root = argv[i] + 16;        document_root = argv[i] + 16;
1141      }      }
1142    
1143        else if (strcmp(argv[i], "--encoding") == 0) {
1144          i++;
1145          if (i == argc) {
1146            fatal_command_line("--encoding: option requires an argument");
1147          }
1148          jscoverage_encoding = argv[i];
1149          specified_encoding = jscoverage_encoding;
1150        }
1151        else if (strncmp(argv[i], "--encoding=", 11) == 0) {
1152          jscoverage_encoding = argv[i] + 11;
1153          specified_encoding = jscoverage_encoding;
1154        }
1155    
1156      else if (strcmp(argv[i], "--ip-address") == 0) {      else if (strcmp(argv[i], "--ip-address") == 0) {
1157        i++;        i++;
1158        if (i == argc) {        if (i == argc) {
1159          fatal("--ip-address: option requires an argument");          fatal_command_line("--ip-address: option requires an argument");
1160        }        }
1161        ip_address = argv[i];        ip_address = argv[i];
1162      }      }
# Line 987  Line 1164 
1164        ip_address = argv[i] + 13;        ip_address = argv[i] + 13;
1165      }      }
1166    
1167        else if (strcmp(argv[i], "--no-highlight") == 0) {
1168          jscoverage_highlight = false;
1169        }
1170    
1171      else if (strcmp(argv[i], "--no-instrument") == 0) {      else if (strcmp(argv[i], "--no-instrument") == 0) {
1172        i++;        i++;
1173        if (i == argc) {        if (i == argc) {
1174          fatal("--no-instrument: option requires an argument");          fatal_command_line("--no-instrument: option requires an argument");
1175        }        }
1176        no_instrument[num_no_instrument] = argv[i];        no_instrument[num_no_instrument] = argv[i];
1177        num_no_instrument++;        num_no_instrument++;
# Line 1003  Line 1184 
1184      else if (strcmp(argv[i], "--port") == 0) {      else if (strcmp(argv[i], "--port") == 0) {
1185        i++;        i++;
1186        if (i == argc) {        if (i == argc) {
1187          fatal("--port: option requires an argument");          fatal_command_line("--port: option requires an argument");
1188        }        }
1189        port = argv[i];        port = argv[i];
1190      }      }
# Line 1020  Line 1201 
1201      }      }
1202    
1203      else if (strncmp(argv[i], "-", 1) == 0) {      else if (strncmp(argv[i], "-", 1) == 0) {
1204        fatal("unrecognized option `%s'", argv[i]);        fatal_command_line("unrecognized option `%s'", argv[i]);
1205      }      }
1206      else {      else {
1207        fatal("too many arguments");        fatal_command_line("too many arguments");
1208      }      }
1209    }    }
1210    
# Line 1031  Line 1212 
1212    char * end;    char * end;
1213    unsigned long numeric_port = strtoul(port, &end, 10);    unsigned long numeric_port = strtoul(port, &end, 10);
1214    if (*end != '\0') {    if (*end != '\0') {
1215      fatal("--port: option must be an integer");      fatal_command_line("--port: option must be an integer");
1216    }    }
1217    if (numeric_port > UINT16_MAX) {    if (numeric_port > UINT16_MAX) {
1218      fatal("--port: option must be 16 bits");      fatal_command_line("--port: option must be 16 bits");
1219    }    }
1220    
1221    /* is this a shutdown? */    /* is this a shutdown? */
# Line 1042  Line 1223 
1223  #ifdef __MINGW32__  #ifdef __MINGW32__
1224      WSADATA data;      WSADATA data;
1225      if (WSAStartup(MAKEWORD(1, 1), &data) != 0) {      if (WSAStartup(MAKEWORD(1, 1), &data) != 0) {
1226        fatal("Could not start Winsock");        fatal("could not start Winsock");
1227      }      }
1228  #endif  #endif
1229    
# Line 1104  Line 1285 
1285      SourceCache * p = source_cache;      SourceCache * p = source_cache;
1286      source_cache = source_cache->next;      source_cache = source_cache->next;
1287      free(p->url);      free(p->url);
1288      Stream_delete(p->source);      free(p->characters);
1289      free(p);      free(p);
1290    }    }
1291    UNLOCK(&source_cache_mutex);    UNLOCK(&source_cache_mutex);

Legend:
Removed from v.133  
changed lines
  Added in v.299

  ViewVC Help
Powered by ViewVC 1.1.24