void WebThings::collect_garbage() { if (stale_count) { // mark all nodes reachable from the roots for (Thing *t = things; t; t = (Thing *)t->next) t->reachable(gc_phase); /* for (Proxy *proxy = proxies; proxy; proxy = (Proxy *)proxy->next) { reachable(proxy->properties); reachable(proxy->proxies); } */ // now sweep through the nodes reachable from the stale list // and delete the ones that aren't reachable from the roots for (unsigned int i = 0; i < stale_count; ++i) { JSON *json = get_json(stale[i]); if (!json->marked(gc_phase)) { json->sweep(gc_phase); for (unsigned int j = i; j < stale_count - 1; ++j) stale[j] = stale[j+1]; --stale_count; } } gc_phase = !gc_phase; JSON::set_gc_phase(gc_phase); // to ensure new nodes are marked correctly } }
void log_create(pid_t pid, pid_t ppid, enum create_type type) { if(!fout) { return; } else if(get_json()) { fprintf(fout, "\t{\n"); fprintf(fout, "\t\t\"pid\": %d,\n", pid); fprintf(fout, "\t\t\"type\": \"create\""); if(type != CREATE_ROOT) { fprintf(fout, ",\n"); fprintf(fout, "\t\t\"parent_pid\": %d,\n", ppid); if(type == CREATE_FORK) { fprintf(fout, "\t\t\"fork\": true\n"); } else { fprintf(fout, "\t\t\"clone\": true\n"); } } else { fprintf(fout, "\n"); } fprintf(fout, "\t},\n"); } else { if(type == CREATE_ROOT) { fprintf(fout, "%d:root_process\n", pid); } else { fprintf(fout, "%d:%s_parent:%d\n", pid, type == CREATE_FORK ? "fork" : "clone", ppid); } } fflush(fout); }
void WebThings::reachable(NPIndex index) { JSON *json = get_json(index); if (json) json->reachable(gc_phase); }
static void check (const MCPP::HTTPResponse & response) { // 2xx is not a Yggdrasil error if ((response.Status/100)==2) return; // It's a Yggdrasil error, parse // and throw auto obj=get_json(response); throw Error( response.Status, get_value<String>( obj, error_key ), get_value<String>( obj, error_message_key ), get_opt_value<String>( obj, cause_key ) ); }
bool finalize_report() { if(!fout) { return true; } else if(get_json()) { fprintf(fout, "]\n"); } return !fclose(fout); }
static void json_rpc_call(struct evhttp_request *req, void *arg) { struct json_rpc_tt *jt = (struct json_rpc_tt *)arg; struct json_object *obj = get_json(req->input_buffer); if (obj == NULL) send_http_reply(req, HTTP_PARSE_ERROR_STATUS, HTTP_PARSE_ERROR_REASON, JSON_RPC_PARSE_ERROR); else json_rpc_process_request(jt->jr, obj, jrpc_result, (void *)req); }
int main2() { ProfilerStart("test2.txt"); std::ifstream myfile; myfile.open("test.txt"); //myfile<<"wtf?"; //get_pilot_json("90376921","201407120000",myfile); //fclose(fp); get_json(myfile); std::cout << "!!!Hello World!!!" << std::endl; // prints !!!Hello World!!! myfile.close(); ProfilerStop(); return 0; }
bool init_report() { if(!get_report()) { return true; } fout = fopen(get_report_file().c_str(), "w"); if(!fout) { return false; } if(get_json()) { fprintf(fout, "[\n"); } return true; }
int commands_action::run(acl::string& out) { acl::json* json = get_json(); if (json == NULL) { logger_error("json null"); return 400; } if (cmd_ == "list") return http_forward<list_req_t, list_res_t>(addr_, *json, out); else if (cmd_ == "stat") return http_forward<stat_req_t, stat_res_t>(addr_, *json, out); else if (cmd_ == "start") { if (!enabled<start_req_t, start_req_data_t>(*json, out)) return 400; return http_forward<start_req_t, start_res_t>(addr_, *json, out); } else if (cmd_ == "stop") { if (!enabled<stop_req_t, stop_req_data_t>(*json, out)) return 400; return http_forward<stop_req_t, stop_res_t>(addr_, *json, out); } else if (cmd_ == "kill") { if (!enabled<kill_req_t, kill_req_data_t>(*json, out)) return 400; return http_forward<kill_req_t, kill_res_t>(addr_, *json, out); } else if (cmd_ == "reload") { if (!enabled<reload_req_t, reload_req_data_t>(*json, out)) return 400; return http_forward<reload_req_t, reload_res_t>(addr_, *json, out); } else if (cmd_ == "restart") { if (!enabled<restart_req_t, restart_req_data_t>(*json, out)) return 400; return http_forward<restart_req_t, restart_res_t>(addr_, *json, out); } else { logger_error("unknown cmd=%s", cmd_.c_str()); return 400; } }
Promise<T> Client::dispatch (MCPP::HTTPRequest request) { return dispatch<T>( std::move(request), [] (Promise<MCPP::HTTPResponse> p) { auto response=p.Get(); check(response); return T(get_json(response)); } ); }
int commands_action::run(acl::string& out) { acl::json* json = get_json(); if (json == NULL) { logger_error("json null"); return 400; } if (cmd_ == "start") { if (!enabled<start_req_t, start_req_data_t>(*json, out)) return 400; return http_forward<start_req_t, start_res_t>(addr_, *json, out); } else if (cmd_ == "stop") { if (!enabled<stop_req_t, stop_req_data_t>(*json, out)) return 400; return http_forward<stop_req_t, stop_res_t>(addr_, *json, out); } else if (cmd_ == "kill") { if (!enabled<kill_req_t, kill_req_data_t>(*json, out)) return 400; return http_forward<kill_req_t, kill_res_t>(addr_, *json, out); } else if (cmd_ == "reload") { if (!enabled<reload_req_t, reload_req_data_t>(*json, out)) return 400; return http_forward<reload_req_t, reload_res_t>(addr_, *json, out); } else if (cmd_ == "restart") { if (!enabled<restart_req_t, restart_req_data_t>(*json, out)) return 400; return http_forward<restart_req_t, restart_res_t>(addr_, *json, out); } // the other commands maybe be safety for master_ctld else return http_forward(addr_, cmd_, json->to_string(), out); }
Promise<String> Client::ServerSession ( const String & username, const String & server_id, const Vector<Byte> & secret, const Vector<Byte> & public_key ) { // Building a custom GET request auto request=get_request(); request.URL=String::Format( session_url, String::Format( server_endpoint, MCPP::URL::Encode(username), MCPP::URL::Encode( get_hash(server_id,secret,public_key) ) ) ); // Dispatch return http.Execute( std::move(request) ).Then([] (Promise<MCPP::HTTPResponse> p) { auto response=p.Get(); check(response); // If the server returned nothing, // that's its way of letting us now // we failed if (response.Body.Count()==0) throw std::runtime_error(session_fail); auto obj=get_json(response); return get_value<String>( obj, session_id_key ); }); }