#include void handle_view(evapp_ctx *ctx) { u_int64_t id = 0; char dbname[32]; struct app_settings *settings; evapp_db *db; HDF *hdf; struct evhttp_request *request = evapp_request(ctx); // XXX: use shared response buffer from the ctx by // first draining it. Or not - drain at the end. bool loaded = false; assert(request && ctx); settings = evapp_get_state(ctx); if (!settings) { send_error(ctx, "application state unavailable"); return; } if (!get_last_value_as_uint64(ctx, &id)) { send_not_found(ctx, "no valid object id was supplied"); return; } // returns a pointer back into the request object. if (!get_database_from_uri(request->uri, dbname, sizeof(dbname))) { send_not_found(ctx, "no valid object type was found"); return; } // Find our interface and call the loader. db = evapp_db_select(ctx, dbname); if (db && db->load) loaded = db->load(ctx, id, &hdf); if (!loaded) { send_not_found(ctx, "object does not exist"); return; } // Set an XSRF protection token just in case if (evapp_get_xsrf_protection(ctx) && !set_xsrf_token(ctx, hdf)) { send_not_found(ctx, "xsrf token subsystem failure"); hdf_destroy(&hdf); return; } if (!template_render(ctx, hdf, "/view/", dbname)) send_not_found(ctx, "template not found"); hdf_destroy(&hdf); return; }