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; |
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"); |
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); |
instrument_js(request_uri, jscoverage_encoding, input_stream, output_stream); |
748 |
|
|
749 |
/* send the headers to the client */ |
/* send the headers to the client */ |
750 |
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) { |
892 |
|
|
893 |
Stream_write_file_contents(input_stream, f); |
Stream_write_file_contents(input_stream, f); |
894 |
|
|
895 |
instrument_js(abs_path, input_stream, output_stream); |
instrument_js(abs_path, jscoverage_encoding, input_stream, output_stream); |
896 |
|
|
897 |
if (HTTPExchange_write_response(exchange, output_stream->data, output_stream->length) != 0) { |
if (HTTPExchange_write_response(exchange, output_stream->data, output_stream->length) != 0) { |
898 |
HTTPServer_log_err("Warning: error writing to client\n"); |
HTTPServer_log_err("Warning: error writing to client\n"); |
978 |
document_root = argv[i] + 16; |
document_root = argv[i] + 16; |
979 |
} |
} |
980 |
|
|
981 |
|
else if (strcmp(argv[i], "--encoding") == 0) { |
982 |
|
i++; |
983 |
|
if (i == argc) { |
984 |
|
fatal("--encoding: option requires an argument"); |
985 |
|
} |
986 |
|
jscoverage_encoding = argv[i]; |
987 |
|
} |
988 |
|
else if (strncmp(argv[i], "--encoding=", 11) == 0) { |
989 |
|
jscoverage_encoding = argv[i] + 11; |
990 |
|
} |
991 |
|
|
992 |
else if (strcmp(argv[i], "--ip-address") == 0) { |
else if (strcmp(argv[i], "--ip-address") == 0) { |
993 |
i++; |
i++; |
994 |
if (i == argc) { |
if (i == argc) { |