// decide if we need to send an API response or a file... void send_response(struct hitArgs *args, char *path, char *request_body, http_verb type) { int path_length=(int)strlen(path); if (path_ends_with(path, "cpu.api")) { return send_cpu_response(args, path, request_body); } if (path_ends_with(path, "temp.api")) { return send_temp_response(args, path, request_body); } send_file_response(args, path, request_body, path_length); }
int update_elap_entry(const char *fpath, const struct stat *sb, int tflag, struct FTW *ftwbuf){ //bj_ostream& os = bj_out; MARK_USED(sb); MARK_USED(ftwbuf); BRAIN_CK(glb_test_tak_mak != NULL_PT); switch (tflag) { case FTW_D: case FTW_DNR: case FTW_DP: break; default:{ ch_string pth_str = fpath; ch_string cnn_nm = SKG_CANON_NAME; if(path_ends_with(pth_str, cnn_nm)){ tak_mak& gg = *glb_test_tak_mak; long upd_it = gg.gen_rand_int32_ie(0, 2); if(upd_it > 0){ ch_string full_pth = path_get_directory(pth_str, true); ch_string elp_nm = full_pth + SKG_ELAPSED_NAME; update_elapsed(elp_nm); } } } break; } return (0); }
void send_file_response(struct hitArgs *args, char *path, char *request_body, int path_length) { STRING *response = new_string(1024); string_add(response, "HTTP/1.1 200 OK\n"); string_add(response, "Connection: close\n"); string_add(response, "Content-Type: "); if (!strcmp(path, "") || path_ends_with(path, "index.html")) { string_add(response, "text/html"); write_header(args->socketfd, string_chars(response), index_html_len); write(args->socketfd, index_html, index_html_len); } else if (path_ends_with(path, "code.js")) { string_add(response, "text/javascript"); write_header(args->socketfd, string_chars(response), code_js_len); write(args->socketfd, code_js, code_js_len); } else if (path_ends_with(path, "jquery-2-1-0-min.js")) { string_add(response, "text/javascript"); write_header(args->socketfd, string_chars(response), jquery_2_1_0_min_js_len); write(args->socketfd, jquery_2_1_0_min_js, jquery_2_1_0_min_js_len); } else if (path_ends_with(path, "flot.js")) { string_add(response, "text/javascript"); write_header(args->socketfd, string_chars(response), flot_js_len); write(args->socketfd, flot_js, flot_js_len); } else { notfound_404(args, "no such file"); } string_free(response); // allow socket to drain before closing sleep(1); }
int load_entry(const char *fpath, const struct stat *sb, int tflag, struct FTW *ftwbuf){ bj_ostream& os = bj_out; MARK_USED(sb); MARK_USED(ftwbuf); switch (tflag) { case FTW_D: case FTW_DNR: case FTW_DP: break; default:{ ch_string full_pth = fpath; ch_string cnn_nm = SKG_CANON_NAME; if(path_ends_with(full_pth, cnn_nm)){ canon_cnf the_cnf; os << full_pth; the_cnf.release_and_init(GSKE, true); bool all_ok = the_cnf.load_from(GSKE, full_pth); if(all_ok){ os << "LOAD OK"; //os << "LOAD OK"; //the_cnf.print_canon_cnf(os); } else { os << "LOAD OF " << full_pth << " FAILED !!"; } //os << bj_eol; the_cnf.release_and_init(GSKE, true); } } break; } return (0); }