Skip to content

Commit

Permalink
Revert "use ejson NIF module to speed encoding/decoding json and remo…
Browse files Browse the repository at this point in the history
…ve mochiweb"

This reverts commit 42b5e59.

Needed to keep RB013 support. This patch will be reintroduced in next
release after freezing current version. Next version of couchbeam will
only be compatible with erlang R13B04.
  • Loading branch information
benoitc committed May 4, 2011
1 parent 9803d34 commit c3e08db
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 318 deletions.
28 changes: 0 additions & 28 deletions NOTICE
Expand Up @@ -9,31 +9,3 @@ couchbeam is released under the MIT license. See the LICENSE file for the comple
couchbeam:couchbeam_deps
------------------------
Copyright 2007-2008 Basho Technologies

couchbeam_util, couchbeam_mime
------------------------------

parse_qs, quote_pluys, urldecode, urlsplit function have been taken from
Mochiweb project under MIT license.

Copyright (c) 2007 Mochi Media, Inc.

Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

2 changes: 1 addition & 1 deletion rebar.config
Expand Up @@ -6,7 +6,7 @@

{deps, [
%% mochiweb for JSON and header parsing
{ejson, ".*", {git,"http://github.com/benoitc/ejson.git","master"}},
{mochiweb, ".*", {git,"http://github.com/mochi/mochiweb.git","master"}},

%% erlang-oauth for oauth authentification
{oauth, ".*", {git,"http://github.com/benoitc/erlang-oauth.git","master"}},
Expand Down
34 changes: 17 additions & 17 deletions src/couchbeam.erl
Expand Up @@ -177,7 +177,7 @@ server_info(#server{options=IbrowseOpts}=Server) ->
Url = binary_to_list(iolist_to_binary(server_url(Server))),
case request(get, Url, ["200"], IbrowseOpts) of
{ok, _Status, _Headers, Body} ->
Version = ejson:decode(Body),
Version = couchbeam_util:json_decode(Body),
{ok, Version};
Error -> Error
end.
Expand Down Expand Up @@ -208,7 +208,7 @@ get_uuids(Server, Count) ->
replicate(#server{options=IbrowseOpts}=Server, RepObj) ->
Url = make_url(Server, "_replicate", []),
Headers = [{"Content-Type", "application/json"}],
JsonObj = ejson:encode(RepObj),
JsonObj = couchbeam_util:json_encode(RepObj),

case request_stream({self(), once}, post, Url, IbrowseOpts, Headers,
JsonObj) of
Expand Down Expand Up @@ -246,7 +246,7 @@ all_dbs(#server{options=IbrowseOpts}=Server) ->
Url = make_url(Server, "_all_dbs", []),
case request(get, Url, ["200"], IbrowseOpts) of
{ok, _, _, Body} ->
AllDbs = ejson:decode(Body),
AllDbs = couchbeam_util:json_decode(Body),
{ok, AllDbs};
Error ->
Error
Expand Down Expand Up @@ -345,7 +345,7 @@ delete_db(#server{options=IbrowseOpts}=Server, DbName) ->
Url = make_url(Server, dbname(DbName), []),
case request(delete, Url, ["200"], IbrowseOpts) of
{ok, _, _, Body} ->
{ok, ejson:decode(Body)};
{ok, couchbeam_util:json_decode(Body)};
Error ->
Error
end.
Expand All @@ -356,7 +356,7 @@ db_info(#db{server=Server, name=DbName, options=IbrowseOpts}) ->
Url = make_url(Server, DbName, []),
case request(get, Url, ["200"], IbrowseOpts) of
{ok, _Status, _Headers, Body} ->
Infos = ejson:decode(Body),
Infos = couchbeam_util:json_decode(Body),
{ok, Infos};
{error, {ok, "404", _, _}} ->
{error, db_not_found};
Expand Down Expand Up @@ -388,7 +388,7 @@ open_doc(#db{server=Server, options=IbrowseOpts}=Db, DocId, Params) ->
Url = make_url(Server, doc_url(Db, DocId1), Params),
case db_request(get, Url, ["200", "201"], IbrowseOpts) of
{ok, _, _, Body} ->
{ok, ejson:decode(Body)};
{ok, couchbeam_util:json_decode(Body)};
Error ->
Error
end.
Expand Down Expand Up @@ -421,11 +421,11 @@ save_doc(#db{server=Server, options=IbrowseOpts}=Db, {Props}=Doc, Options) ->
couchbeam_util:encode_docid(DocId1)
end,
Url = make_url(Server, doc_url(Db, DocId), Options),
Body = ejson:encode(Doc),
Body = couchbeam_util:json_encode(Doc),
Headers = [{"Content-Type", "application/json"}],
case db_request(put, Url, ["201", "202"], IbrowseOpts, Headers, Body) of
{ok, _, _, RespBody} ->
{JsonProp} = ejson:decode(RespBody),
{JsonProp} = couchbeam_util:json_decode(RespBody),
NewRev = couchbeam_util:get_value(<<"rev">>, JsonProp),
NewDocId = couchbeam_util:get_value(<<"id">>, JsonProp),
Doc1 = couchbeam_doc:set_value(<<"_rev">>, NewRev,
Expand Down Expand Up @@ -491,21 +491,21 @@ save_docs(#db{server=Server, options=IbrowseOpts}=Db, Docs, Options) ->
{Options2, Body} = case couchbeam_util:get_value("all_or_nothing",
Options1, false) of
true ->
Body1 = ejson:encode({[
Body1 = couchbeam_util:json_encode({[
{<<"all_or_nothing">>, true},
{<<"docs">>, Docs1}
]}),

{proplists:delete("all_or_nothing", Options1), Body1};
_ ->
Body1 = ejson:encode({[{<<"docs">>, Docs1}]}),
Body1 = couchbeam_util:json_encode({[{<<"docs">>, Docs1}]}),
{Options1, Body1}
end,
Url = make_url(Server, [db_url(Db), "/", "_bulk_docs"], Options2),
Headers = [{"Content-Type", "application/json"}],
case db_request(post, Url, ["201"], IbrowseOpts, Headers, Body) of
{ok, _, _, RespBody} ->
{ok, ejson:decode(RespBody)};
{ok, couchbeam_util:json_decode(RespBody)};
Error ->
Error
end.
Expand Down Expand Up @@ -624,7 +624,7 @@ put_attachment(#db{server=Server, options=IbrowseOpts}=Db, DocId, Name, Body, Op

case db_request(put, Url, ["201"], IbrowseOpts, FinalHeaders, Body) of
{ok, _, _, RespBody} ->
{[{<<"ok">>, true}|R]} = ejson:decode(RespBody),
{[{<<"ok">>, true}|R]} = couchbeam_util:json_decode(RespBody),
{ok, {R}};
Error ->
Error
Expand Down Expand Up @@ -661,7 +661,7 @@ delete_attachment(#db{server=Server, options=IbrowseOpts}=Db, DocOrDocId, Name,
Url = make_url(Server, [db_url(Db), "/", DocId, "/", Name], Options2),
case db_request(delete, Url, ["200"], IbrowseOpts) of
{ok, _, _, RespBody} ->
{[{<<"ok">>,true}|R]} = ejson:decode(RespBody),
{[{<<"ok">>,true}|R]} = couchbeam_util:json_decode(RespBody),
{ok, {R}};

Error ->
Expand Down Expand Up @@ -738,7 +738,7 @@ view(#db{server=Server}=Db, ViewName, Options) ->
undefined ->
{get, Options1, []};
Keys ->
Body1 = ejson:encode({[{<<"keys">>, Keys}]}),
Body1 = couchbeam_util:json_encode({[{<<"keys">>, Keys}]}),
{post, proplists:delete("keys", Options1), Body1}
end,
Headers = case Method of
Expand Down Expand Up @@ -771,7 +771,7 @@ ensure_full_commit(#db{server=Server, options=IbrowseOpts}=Db, Options) ->
Headers = [{"Content-Type", "application/json"}],
case db_request(post, Url, ["201"], IbrowseOpts, Headers) of
{ok, _, _, Body} ->
{[{<<"ok">>, true}|R]} = ejson:decode(Body),
{[{<<"ok">>, true}|R]} = couchbeam_util:json_decode(Body),
{ok, R};
Error ->
Error
Expand Down Expand Up @@ -922,7 +922,7 @@ make_url(Server=#server{prefix=Prefix}, Path, Query) ->
[server_url(Server),
Prefix, "/",
Path,
[ ["?", couchbeam_util:urlencode(Query1)] || Query1 =/= [] ]
[ ["?", mochiweb_util:urlencode(Query1)] || Query1 =/= [] ]
])).

db_request(Method, Url, Expect, Options) ->
Expand Down Expand Up @@ -1053,7 +1053,7 @@ get_new_uuids(Server=#server{host=Host, port=Port, options=IbrowseOptions}) ->
Url = make_url(Server, "_uuids", [{"count", "1000"}]),
case request(get, Url, ["200"], IbrowseOptions) of
{ok, _Status, _Headers, Body} ->
{[{<<"uuids">>, Uuids}]} = ejson:decode(Body),
{[{<<"uuids">>, Uuids}]} = couchbeam_util:json_decode(Body),
ServerUuids = #server_uuids{host_port={Host,
Port}, uuids=Uuids},
ets:insert(couchbeam_uuids, ServerUuids),
Expand Down
2 changes: 1 addition & 1 deletion src/couchbeam_attachments.erl
Expand Up @@ -74,7 +74,7 @@ attachment_acceptor(Pid, PidRef, Timeout, IbrowseRef) ->
%% AName::string()) -> json_obj()
%% @doc add attachment to a doc and encode it. Give possibility to send attachments inline.
add_inline(Doc, Content, AName) ->
ContentType = couchbeam_util:guess_mime(AName),
ContentType = mochiweb_util:guess_mime(AName),
add_inline(Doc, Content, AName, ContentType).

%% @spec add_inline(Doc::json_obj(), Content::attachment_content(),
Expand Down
6 changes: 3 additions & 3 deletions src/couchbeam_changes.erl
Expand Up @@ -22,9 +22,9 @@ wait_for_change(Reqid, ReqStatus, Acc) ->
Change = iolist_to_binary(lists:reverse(Acc)),
try
if ReqStatus >= 400 ->
{error, {ReqStatus, ejson:decode(Change)}};
{error, {ReqStatus, couchbeam_util:json_decode(Change)}};
true ->
{ok, ejson:decode(Change)}
{ok, couchbeam_util:json_decode(Change)}
end
catch
throw:{invalid_json, Error} ->
Expand Down Expand Up @@ -106,7 +106,7 @@ handle_messages([Chunk|Rest], Pid, PidRef, IbrowseRef, State) ->
decode_row(<<",", Rest/binary>>) ->
decode_row(Rest);
decode_row(Row) ->
ejson:decode(Row).
couchbeam_util:json_decode(Row).



74 changes: 0 additions & 74 deletions src/couchbeam_mime.erl

This file was deleted.

0 comments on commit c3e08db

Please sign in to comment.