/[jscoverage]/trunk/jscoverage-server.c
ViewVC logotype

Diff of /trunk/jscoverage-server.c

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

revision 146 by siliconforks, Thu Jun 19 19:33:05 2008 UTC revision 177 by siliconforks, Sat Sep 20 23:30:26 2008 UTC
# Line 29  Line 29 
29  #include <pthread.h>  #include <pthread.h>
30  #endif  #endif
31    
32    #include "global.h"
33  #include "http-server.h"  #include "http-server.h"
34  #include "instrument-js.h"  #include "instrument-js.h"
35  #include "resource-manager.h"  #include "resource-manager.h"
36  #include "stream.h"  #include "stream.h"
37  #include "util.h"  #include "util.h"
38    
39    const char * jscoverage_encoding = "ISO-8859-1";
40    
41  typedef struct SourceCache {  typedef struct SourceCache {
42    char * url;    char * url;
43    Stream * source;    Stream * source;
# Line 616  Line 619 
619    }    }
620  }  }
621    
622  static void instrument_js(const char * id, Stream * input_stream, Stream * output_stream) {  static void instrument_js(const char * id, const char * encoding, Stream * input_stream, Stream * output_stream) {
623    LOCK(&javascript_mutex);    LOCK(&javascript_mutex);
624    jscoverage_instrument_js(id, input_stream, output_stream);    jscoverage_instrument_js(id, encoding, input_stream, output_stream);
625    UNLOCK(&javascript_mutex);    UNLOCK(&javascript_mutex);
626    
627    const struct Resource * resource = get_resource("report.js");    const struct Resource * resource = get_resource("report.js");
# Line 741  Line 744 
744    
745      const char * request_uri = HTTPExchange_get_request_uri(client_exchange);      const char * request_uri = HTTPExchange_get_request_uri(client_exchange);
746      Stream * output_stream = Stream_new(0);      Stream * output_stream = Stream_new(0);
747      instrument_js(request_uri, input_stream, output_stream);      char * encoding = HTTPMessage_get_charset(HTTPExchange_get_response_message(server_exchange));
748        if (encoding == NULL) {
749          instrument_js(request_uri, jscoverage_encoding, input_stream, output_stream);
750        }
751        else {
752          instrument_js(request_uri, encoding, input_stream, output_stream);
753          free(encoding);
754        }
755    
756      /* send the headers to the client */      /* send the headers to the client */
757      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) {
# Line 889  Line 899 
899    
900        Stream_write_file_contents(input_stream, f);        Stream_write_file_contents(input_stream, f);
901    
902        instrument_js(abs_path, input_stream, output_stream);        instrument_js(abs_path, jscoverage_encoding, input_stream, output_stream);
903    
904        if (HTTPExchange_write_response(exchange, output_stream->data, output_stream->length) != 0) {        if (HTTPExchange_write_response(exchange, output_stream->data, output_stream->length) != 0) {
905          HTTPServer_log_err("Warning: error writing to client\n");          HTTPServer_log_err("Warning: error writing to client\n");
# Line 975  Line 985 
985        document_root = argv[i] + 16;        document_root = argv[i] + 16;
986      }      }
987    
988        else if (strcmp(argv[i], "--encoding") == 0) {
989          i++;
990          if (i == argc) {
991            fatal("--encoding: option requires an argument");
992          }
993          jscoverage_encoding = argv[i];
994        }
995        else if (strncmp(argv[i], "--encoding=", 11) == 0) {
996          jscoverage_encoding = argv[i] + 11;
997        }
998    
999      else if (strcmp(argv[i], "--ip-address") == 0) {      else if (strcmp(argv[i], "--ip-address") == 0) {
1000        i++;        i++;
1001        if (i == argc) {        if (i == argc) {

Legend:
Removed from v.146  
changed lines
  Added in v.177

  ViewVC Help
Powered by ViewVC 1.1.24