X-Git-Url: http://git.cascardo.eti.br/?a=blobdiff_plain;f=frontend%2Fcgi%2Fcgi.c;h=736fb6862a3ce683d5884651e436f317ffafcfb7;hb=c20ec0c3434e57719d487a8628048188cf787ffb;hp=73adcda2332b789cdb627855d926e239b3d91a15;hpb=1c0ac6667f2f374edc70211edf3411e390dbc9b1;p=cascardo%2Fatompub.git diff --git a/frontend/cgi/cgi.c b/frontend/cgi/cgi.c index 73adcda..736fb68 100644 --- a/frontend/cgi/cgi.c +++ b/frontend/cgi/cgi.c @@ -33,27 +33,47 @@ cgi_serve_request (AtomCtx *ctx) return; if (path == NULL) { - path = atom_config_get_str (ctx, "cgi", "index"); + if ((path = atom_config_get_str (ctx, "cgi", "index")) == NULL) + { + /* We do not want to disclose our configuration is empty. + * The requester cannot distinguish an empty configuration + * from a non-existent index. + */ + fprintf (stdout, "Status: 404 Not Found\n\n"); + return; + } } if (!strcmp (method, "GET")) { - IRI *iri; - AtomResource *atom; + AtomID *id; + AtomEntry *atom; AtomError *error; - iri = iri_new (); - iri_set_path (iri, path); - atom = atom_retrieve_resource (ctx, iri); - iri_delete (iri); + char *req; + id = atom_id_new_from_frontend (ctx, path); + if (id == NULL || (req = atom_id_to_backend (ctx, id)) == NULL) + { + atom = NULL; + error = atom_error_new (); + atom_error_code_set (error, 404); + atom_error_message_set (error, "Resource not found"); + atom_error_set (ctx, error); + } + else + { + atom = atom_retrieve_entry (ctx, req); + } + if (id != NULL) + atom_id_delete (id); if (atom) { char * str; size_t len; char *header = "Content-type: application/atom+xml\n\n"; write (1, header, strlen (header)); - atom_resource_string (atom, &str, &len); + atom_entry_string (atom, &str, &len); write (1, str, len); g_free (str); - atom_resource_delete (atom); + atom_entry_delete (atom); } else if ((error = atom_error_get (ctx)) != NULL) { @@ -71,3 +91,12 @@ cgi_serve_request (AtomCtx *ctx) fprintf (stdout, "Status: 501 Not Implemented\n\n"); } } + +AtomFrontend * +cgi_frontend (void) +{ + AtomFrontend *frontend; + frontend = atom_frontend_new (); + atom_frontend_map_entries_set (frontend, atom_map_frontend_requests); + return frontend; +}