summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn Christopher Anderson <jchris@apache.org>2009-01-12 01:48:36 +0000
committerJohn Christopher Anderson <jchris@apache.org>2009-01-12 01:48:36 +0000
commitf5e38acc625d4bb73934e121a9d6abb75e507460 (patch)
tree41e03518ee8bfa43c1226629d265ae66299ab444 /src
parent2417e37a68178c3212c9374d73bea5a2522ab418 (diff)
rename _form to _show and move the funcs in the design doc to design.show.docs
git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@733576 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src')
-rw-r--r--src/couchdb/Makefile.am4
-rw-r--r--src/couchdb/couch_httpd_show.erl (renamed from src/couchdb/couch_httpd_form.erl)50
-rw-r--r--src/couchdb/couch_query_servers.erl7
3 files changed, 34 insertions, 27 deletions
diff --git a/src/couchdb/Makefile.am b/src/couchdb/Makefile.am
index 7fb2ec68..8e280c70 100644
--- a/src/couchdb/Makefile.am
+++ b/src/couchdb/Makefile.am
@@ -55,7 +55,7 @@ source_files = \
couch_httpd.erl \
couch_httpd_db.erl \
couch_httpd_external.erl \
- couch_httpd_form.erl \
+ couch_httpd_show.erl \
couch_httpd_view.erl \
couch_httpd_misc_handlers.erl \
couch_key_tree.erl \
@@ -91,7 +91,7 @@ compiled_files = \
couch_httpd.beam \
couch_httpd_db.beam \
couch_httpd_external.beam \
- couch_httpd_form.beam \
+ couch_httpd_show.beam \
couch_httpd_view.beam \
couch_httpd_misc_handlers.beam \
couch_key_tree.beam \
diff --git a/src/couchdb/couch_httpd_form.erl b/src/couchdb/couch_httpd_show.erl
index f4fa2c18..d4b4997b 100644
--- a/src/couchdb/couch_httpd_form.erl
+++ b/src/couchdb/couch_httpd_show.erl
@@ -10,9 +10,9 @@
% License for the specific language governing permissions and limitations under
% the License.
--module(couch_httpd_form).
+-module(couch_httpd_show).
--export([handle_form_req/2]).
+-export([handle_doc_show_req/2]).
-include("couch_db.hrl").
@@ -22,7 +22,7 @@
start_json_response/2,send_chunk/2,end_json_response/1,
start_chunked_response/3, send_error/4]).
-handle_form_req(#httpd{method='GET',path_parts=[_, _, DesignName, FormName, Docid]}=Req, Db) ->
+handle_doc_show_req(#httpd{method='GET',path_parts=[_, _, DesignName, ShowName, Docid]}=Req, Db) ->
DesignId = <<"_design/", DesignName/binary>>,
% Anyway we can dry up this error handling?
case (catch couch_httpd_db:couch_doc_open(Db, DesignId, [], [])) of
@@ -33,40 +33,46 @@ handle_form_req(#httpd{method='GET',path_parts=[_, _, DesignName, FormName, Doci
DesignDoc ->
#doc{body={Props}} = DesignDoc,
Lang = proplists:get_value(<<"language">>, Props, <<"javascript">>),
- case proplists:get_value(<<"forms">>, Props, nil) of
- {Forms} ->
- case proplists:get_value(FormName, Forms, nil) of
+ case proplists:get_value(<<"show">>, Props, nil) of
+ {DocAndViews} ->
+ case proplists:get_value(<<"docs">>, DocAndViews, nil) of
nil ->
- throw({not_found, missing_form});
- FormSrc ->
- case (catch couch_httpd_db:couch_doc_open(Db, Docid, [], [])) of
- {not_found, missing} ->
- throw({not_found, missing});
- {not_found, deleted} ->
- throw({not_found, deleted});
- Doc ->
- % ok we have everythign we need. let's make it happen.
- send_form_response(Lang, FormSrc, Doc, Req, Db)
+ throw({not_found, missing_show_docs});
+ {DocShows} ->
+ case proplists:get_value(ShowName, DocShows, nil) of
+ nil ->
+ throw({not_found, missing_show_doc_function});
+ ShowSrc ->
+ case (catch couch_httpd_db:couch_doc_open(
+ Db, Docid, [], [])) of
+ {not_found, missing} ->
+ throw({not_found, missing});
+ {not_found, deleted} ->
+ throw({not_found, deleted});
+ Doc ->
+ % ok we have everythign we need. let's make it happen.
+ send_doc_show_response(Lang, ShowSrc, Doc, Req, Db)
+ end
end
end;
nil ->
- throw({not_found, missing_form})
+ throw({not_found, missing_show})
end
end;
-handle_form_req(#httpd{method='GET'}=Req, _Db) ->
+handle_doc_show_req(#httpd{method='GET'}=Req, _Db) ->
send_error(Req, 404, <<"form_error">>, <<"Invalid path.">>);
-handle_form_req(Req, _Db) ->
+handle_doc_show_req(Req, _Db) ->
send_method_not_allowed(Req, "GET,HEAD").
-send_form_response(Lang, FormSrc, #doc{revs=[DocRev|_]}=Doc, #httpd{mochi_req=MReq}=Req, Db) ->
+send_doc_show_response(Lang, ShowSrc, #doc{revs=[DocRev|_]}=Doc, #httpd{mochi_req=MReq}=Req, Db) ->
% make a term with etag-effecting Req components, but not always changing ones.
Headers = MReq:get(headers),
Hlist = mochiweb_headers:to_list(Headers),
Accept = proplists:get_value('Accept', Hlist),
- <<SigInt:128/integer>> = erlang:md5(term_to_binary({Lang, FormSrc, DocRev, Accept})),
+ <<SigInt:128/integer>> = erlang:md5(term_to_binary({Lang, ShowSrc, DocRev, Accept})),
CurrentEtag = list_to_binary("\"" ++ lists:flatten(io_lib:format("form_~.36B",[SigInt])) ++ "\""),
EtagsToMatch = string:tokens(
couch_httpd:header_value(Req, "If-None-Match", ""), ", "),
@@ -77,7 +83,7 @@ send_form_response(Lang, FormSrc, #doc{revs=[DocRev|_]}=Doc, #httpd{mochi_req=MR
couch_httpd:send_response(Req, 304, [{"Etag", CurrentEtag}], <<>>);
false ->
% Run the external form renderer.
- {JsonResponse} = couch_query_servers:render_doc_form(Lang, FormSrc, Doc, Req, Db),
+ {JsonResponse} = couch_query_servers:render_doc_show(Lang, ShowSrc, Doc, Req, Db),
% Here we embark on the delicate task of replacing or creating the
% headers on the JsonResponse object. We need to control the Etag and
% Vary headers. If the external function controls the Etag, we'd have to
diff --git a/src/couchdb/couch_query_servers.erl b/src/couchdb/couch_query_servers.erl
index c4ed5c8b..8d473381 100644
--- a/src/couchdb/couch_query_servers.erl
+++ b/src/couchdb/couch_query_servers.erl
@@ -17,7 +17,7 @@
-export([init/1, terminate/2, handle_call/3, handle_cast/2, handle_info/2,code_change/3,stop/0]).
-export([start_doc_map/2, map_docs/2, stop_doc_map/1]).
--export([reduce/3, rereduce/3,validate_doc_update/5,render_doc_form/5]).
+-export([reduce/3, rereduce/3,validate_doc_update/5,render_doc_show/5]).
% -export([test/0]).
-include("couch_db.hrl").
@@ -122,11 +122,12 @@ validate_doc_update(Lang, FunSrc, EditDoc, DiskDoc, Ctx) ->
ok = ret_os_process(Lang, Pid)
end.
-render_doc_form(Lang, FormSrc, Doc, Req, Db) ->
+render_doc_show(Lang, ShowSrc, Doc, Req, Db) ->
Pid = get_os_process(Lang),
JsonDoc = couch_doc:to_json_obj(Doc, [revs]),
JsonReq = couch_httpd_external:json_req_obj(Req, Db),
- try couch_os_process:prompt(Pid, [<<"form">>, FormSrc, JsonDoc, JsonReq]) of
+ try couch_os_process:prompt(Pid,
+ [<<"show_doc">>, ShowSrc, JsonDoc, JsonReq]) of
FormResp ->
FormResp
after