/[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 189 by siliconforks, Tue Sep 23 03:48:37 2008 UTC revision 255 by siliconforks, Sun Oct 5 18:10:10 2008 UTC
# Line 242  Line 242 
242      return c - '0';      return c - '0';
243    }    }
244    else if ('A' <= c && c <= 'F') {    else if ('A' <= c && c <= 'F') {
245      return c - 'A';      return c - 'A' + 10;
246    }    }
247    else if ('a' <= c && c <= 'f') {    else if ('a' <= c && c <= 'f') {
248      return c - 'a';      return c - 'a' + 10;
249    }    }
250    else {    else {
251      return 0;      return 0;
# Line 566  Line 566 
566    
567  static int write_json(Coverage * coverage, const char * path) {  static int write_json(Coverage * coverage, const char * path) {
568    /* write the JSON */    /* write the JSON */
569    FILE * f = fopen(path, "w");    FILE * f = fopen(path, "wb");
570    if (f == NULL) {    if (f == NULL) {
571      return -1;      return -1;
572    }    }
# Line 630  Line 630 
630      struct stat buf;      struct stat buf;
631      if (stat(path, &buf) == 0) {      if (stat(path, &buf) == 0) {
632        /* it exists: merge */        /* it exists: merge */
633        FILE * f = fopen(path, "r");        FILE * f = fopen(path, "rb");
634        if (f == NULL) {        if (f == NULL) {
635          result = 1;          result = 1;
636        }        }
# Line 852  Line 852 
852      free(encoding);      free(encoding);
853      Stream_delete(input_stream);      Stream_delete(input_stream);
854      if (result == JSCOVERAGE_ERROR_ENCODING_NOT_SUPPORTED) {      if (result == JSCOVERAGE_ERROR_ENCODING_NOT_SUPPORTED) {
       free(characters);  
855        send_response(client_exchange, 502, "Encoding not supported\n");        send_response(client_exchange, 502, "Encoding not supported\n");
856        goto done;        goto done;
857      }      }
858      else if (result == JSCOVERAGE_ERROR_INVALID_BYTE_SEQUENCE) {      else if (result == JSCOVERAGE_ERROR_INVALID_BYTE_SEQUENCE) {
       free(characters);  
859        send_response(client_exchange, 502, "Error decoding response\n");        send_response(client_exchange, 502, "Error decoding response\n");
860        goto done;        goto done;
861      }      }
# Line 933  Line 931 
931    /* add the `Server' response-header (RFC 2616 14.38, 3.8) */    /* add the `Server' response-header (RFC 2616 14.38, 3.8) */
932    HTTPExchange_add_response_header(exchange, HTTP_SERVER, "jscoverage-server/" VERSION);    HTTPExchange_add_response_header(exchange, HTTP_SERVER, "jscoverage-server/" VERSION);
933    
934      char * decoded_path = NULL;
935    char * filesystem_path = NULL;    char * filesystem_path = NULL;
936    
937    const char * abs_path = HTTPExchange_get_abs_path(exchange);    const char * abs_path = HTTPExchange_get_abs_path(exchange);
938    assert(*abs_path != '\0');    assert(*abs_path != '\0');
939    
940    if (str_starts_with(abs_path, "/jscoverage")) {    decoded_path = decode_uri_component(abs_path);
941    
942      if (str_starts_with(decoded_path, "/jscoverage")) {
943      handle_jscoverage_request(exchange);      handle_jscoverage_request(exchange);
944      goto done;      goto done;
945    }    }
946    
947    if (strstr(abs_path, "..") != NULL) {    if (strstr(decoded_path, "..") != NULL) {
948      send_response(exchange, 403, "Forbidden\n");      send_response(exchange, 403, "Forbidden\n");
949      goto done;      goto done;
950    }    }
951    
952    filesystem_path = make_path(document_root, abs_path + 1);    filesystem_path = make_path(document_root, decoded_path + 1);
953    size_t filesystem_path_length = strlen(filesystem_path);    size_t filesystem_path_length = strlen(filesystem_path);
954    if (filesystem_path_length > 0 && filesystem_path[filesystem_path_length - 1] == '/') {    if (filesystem_path_length > 0 && filesystem_path[filesystem_path_length - 1] == '/') {
955      /* stat on Windows doesn't work with trailing slash */      /* stat on Windows doesn't work with trailing slash */
# Line 1052  Line 1053 
1053    
1054  done:  done:
1055    free(filesystem_path);    free(filesystem_path);
1056      free(decoded_path);
1057  }  }
1058    
1059  static void handler(HTTPExchange * exchange) {  static void handler(HTTPExchange * exchange) {
# Line 1092  Line 1094 
1094      else if (strcmp(argv[i], "--report-dir") == 0) {      else if (strcmp(argv[i], "--report-dir") == 0) {
1095        i++;        i++;
1096        if (i == argc) {        if (i == argc) {
1097          fatal("--report-dir: option requires an argument");          fatal_command_line("--report-dir: option requires an argument");
1098        }        }
1099        report_directory = argv[i];        report_directory = argv[i];
1100      }      }
# Line 1103  Line 1105 
1105      else if (strcmp(argv[i], "--document-root") == 0) {      else if (strcmp(argv[i], "--document-root") == 0) {
1106        i++;        i++;
1107        if (i == argc) {        if (i == argc) {
1108          fatal("--document-root: option requires an argument");          fatal_command_line("--document-root: option requires an argument");
1109        }        }
1110        document_root = argv[i];        document_root = argv[i];
1111      }      }
# Line 1114  Line 1116 
1116      else if (strcmp(argv[i], "--encoding") == 0) {      else if (strcmp(argv[i], "--encoding") == 0) {
1117        i++;        i++;
1118        if (i == argc) {        if (i == argc) {
1119          fatal("--encoding: option requires an argument");          fatal_command_line("--encoding: option requires an argument");
1120        }        }
1121        jscoverage_encoding = argv[i];        jscoverage_encoding = argv[i];
1122      }      }
# Line 1125  Line 1127 
1127      else if (strcmp(argv[i], "--ip-address") == 0) {      else if (strcmp(argv[i], "--ip-address") == 0) {
1128        i++;        i++;
1129        if (i == argc) {        if (i == argc) {
1130          fatal("--ip-address: option requires an argument");          fatal_command_line("--ip-address: option requires an argument");
1131        }        }
1132        ip_address = argv[i];        ip_address = argv[i];
1133      }      }
# Line 1140  Line 1142 
1142      else if (strcmp(argv[i], "--no-instrument") == 0) {      else if (strcmp(argv[i], "--no-instrument") == 0) {
1143        i++;        i++;
1144        if (i == argc) {        if (i == argc) {
1145          fatal("--no-instrument: option requires an argument");          fatal_command_line("--no-instrument: option requires an argument");
1146        }        }
1147        no_instrument[num_no_instrument] = argv[i];        no_instrument[num_no_instrument] = argv[i];
1148        num_no_instrument++;        num_no_instrument++;
# Line 1153  Line 1155 
1155      else if (strcmp(argv[i], "--port") == 0) {      else if (strcmp(argv[i], "--port") == 0) {
1156        i++;        i++;
1157        if (i == argc) {        if (i == argc) {
1158          fatal("--port: option requires an argument");          fatal_command_line("--port: option requires an argument");
1159        }        }
1160        port = argv[i];        port = argv[i];
1161      }      }
# Line 1170  Line 1172 
1172      }      }
1173    
1174      else if (strncmp(argv[i], "-", 1) == 0) {      else if (strncmp(argv[i], "-", 1) == 0) {
1175        fatal("unrecognized option `%s'", argv[i]);        fatal_command_line("unrecognized option `%s'", argv[i]);
1176      }      }
1177      else {      else {
1178        fatal("too many arguments");        fatal_command_line("too many arguments");
1179      }      }
1180    }    }
1181    
# Line 1181  Line 1183 
1183    char * end;    char * end;
1184    unsigned long numeric_port = strtoul(port, &end, 10);    unsigned long numeric_port = strtoul(port, &end, 10);
1185    if (*end != '\0') {    if (*end != '\0') {
1186      fatal("--port: option must be an integer");      fatal_command_line("--port: option must be an integer");
1187    }    }
1188    if (numeric_port > UINT16_MAX) {    if (numeric_port > UINT16_MAX) {
1189      fatal("--port: option must be 16 bits");      fatal_command_line("--port: option must be 16 bits");
1190    }    }
1191    
1192    /* is this a shutdown? */    /* is this a shutdown? */

Legend:
Removed from v.189  
changed lines
  Added in v.255

  ViewVC Help
Powered by ViewVC 1.1.24