/[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 189 by siliconforks, Tue Sep 23 03:48:37 2008 UTC revision 253 by siliconforks, Sun Oct 5 18:09:02 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 933  Line 933 
933    /* add the `Server' response-header (RFC 2616 14.38, 3.8) */    /* add the `Server' response-header (RFC 2616 14.38, 3.8) */
934    HTTPExchange_add_response_header(exchange, HTTP_SERVER, "jscoverage-server/" VERSION);    HTTPExchange_add_response_header(exchange, HTTP_SERVER, "jscoverage-server/" VERSION);
935    
936      char * decoded_path = NULL;
937    char * filesystem_path = NULL;    char * filesystem_path = NULL;
938    
939    const char * abs_path = HTTPExchange_get_abs_path(exchange);    const char * abs_path = HTTPExchange_get_abs_path(exchange);
940    assert(*abs_path != '\0');    assert(*abs_path != '\0');
941    
942    if (str_starts_with(abs_path, "/jscoverage")) {    decoded_path = decode_uri_component(abs_path);
943    
944      if (str_starts_with(decoded_path, "/jscoverage")) {
945      handle_jscoverage_request(exchange);      handle_jscoverage_request(exchange);
946      goto done;      goto done;
947    }    }
948    
949    if (strstr(abs_path, "..") != NULL) {    if (strstr(decoded_path, "..") != NULL) {
950      send_response(exchange, 403, "Forbidden\n");      send_response(exchange, 403, "Forbidden\n");
951      goto done;      goto done;
952    }    }
953    
954    filesystem_path = make_path(document_root, abs_path + 1);    filesystem_path = make_path(document_root, decoded_path + 1);
955    size_t filesystem_path_length = strlen(filesystem_path);    size_t filesystem_path_length = strlen(filesystem_path);
956    if (filesystem_path_length > 0 && filesystem_path[filesystem_path_length - 1] == '/') {    if (filesystem_path_length > 0 && filesystem_path[filesystem_path_length - 1] == '/') {
957      /* stat on Windows doesn't work with trailing slash */      /* stat on Windows doesn't work with trailing slash */
# Line 1052  Line 1055 
1055    
1056  done:  done:
1057    free(filesystem_path);    free(filesystem_path);
1058      free(decoded_path);
1059  }  }
1060    
1061  static void handler(HTTPExchange * exchange) {  static void handler(HTTPExchange * exchange) {
# Line 1092  Line 1096 
1096      else if (strcmp(argv[i], "--report-dir") == 0) {      else if (strcmp(argv[i], "--report-dir") == 0) {
1097        i++;        i++;
1098        if (i == argc) {        if (i == argc) {
1099          fatal("--report-dir: option requires an argument");          fatal_command_line("--report-dir: option requires an argument");
1100        }        }
1101        report_directory = argv[i];        report_directory = argv[i];
1102      }      }
# Line 1103  Line 1107 
1107      else if (strcmp(argv[i], "--document-root") == 0) {      else if (strcmp(argv[i], "--document-root") == 0) {
1108        i++;        i++;
1109        if (i == argc) {        if (i == argc) {
1110          fatal("--document-root: option requires an argument");          fatal_command_line("--document-root: option requires an argument");
1111        }        }
1112        document_root = argv[i];        document_root = argv[i];
1113      }      }
# Line 1114  Line 1118 
1118      else if (strcmp(argv[i], "--encoding") == 0) {      else if (strcmp(argv[i], "--encoding") == 0) {
1119        i++;        i++;
1120        if (i == argc) {        if (i == argc) {
1121          fatal("--encoding: option requires an argument");          fatal_command_line("--encoding: option requires an argument");
1122        }        }
1123        jscoverage_encoding = argv[i];        jscoverage_encoding = argv[i];
1124      }      }
# Line 1125  Line 1129 
1129      else if (strcmp(argv[i], "--ip-address") == 0) {      else if (strcmp(argv[i], "--ip-address") == 0) {
1130        i++;        i++;
1131        if (i == argc) {        if (i == argc) {
1132          fatal("--ip-address: option requires an argument");          fatal_command_line("--ip-address: option requires an argument");
1133        }        }
1134        ip_address = argv[i];        ip_address = argv[i];
1135      }      }
# Line 1140  Line 1144 
1144      else if (strcmp(argv[i], "--no-instrument") == 0) {      else if (strcmp(argv[i], "--no-instrument") == 0) {
1145        i++;        i++;
1146        if (i == argc) {        if (i == argc) {
1147          fatal("--no-instrument: option requires an argument");          fatal_command_line("--no-instrument: option requires an argument");
1148        }        }
1149        no_instrument[num_no_instrument] = argv[i];        no_instrument[num_no_instrument] = argv[i];
1150        num_no_instrument++;        num_no_instrument++;
# Line 1153  Line 1157 
1157      else if (strcmp(argv[i], "--port") == 0) {      else if (strcmp(argv[i], "--port") == 0) {
1158        i++;        i++;
1159        if (i == argc) {        if (i == argc) {
1160          fatal("--port: option requires an argument");          fatal_command_line("--port: option requires an argument");
1161        }        }
1162        port = argv[i];        port = argv[i];
1163      }      }
# Line 1170  Line 1174 
1174      }      }
1175    
1176      else if (strncmp(argv[i], "-", 1) == 0) {      else if (strncmp(argv[i], "-", 1) == 0) {
1177        fatal("unrecognized option `%s'", argv[i]);        fatal_command_line("unrecognized option `%s'", argv[i]);
1178      }      }
1179      else {      else {
1180        fatal("too many arguments");        fatal_command_line("too many arguments");
1181      }      }
1182    }    }
1183    
# Line 1181  Line 1185 
1185    char * end;    char * end;
1186    unsigned long numeric_port = strtoul(port, &end, 10);    unsigned long numeric_port = strtoul(port, &end, 10);
1187    if (*end != '\0') {    if (*end != '\0') {
1188      fatal("--port: option must be an integer");      fatal_command_line("--port: option must be an integer");
1189    }    }
1190    if (numeric_port > UINT16_MAX) {    if (numeric_port > UINT16_MAX) {
1191      fatal("--port: option must be 16 bits");      fatal_command_line("--port: option must be 16 bits");
1192    }    }
1193    
1194    /* is this a shutdown? */    /* is this a shutdown? */

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

  ViewVC Help
Powered by ViewVC 1.1.24