couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cml...@apache.org
Subject svn commit: r660321 - in /incubator/couchdb/branches/mochijson: ./ src/couchdb/
Date Mon, 26 May 2008 21:51:56 GMT
Author: cmlenz
Date: Mon May 26 14:51:52 2008
New Revision: 660321

URL: http://svn.apache.org/viewvc?rev=660321&view=rev
Log:
mochijson branch: started transition to mochijson2. 'obj' is now 'struct'. Everything but
the welcome page broken right now.

Removed:
    incubator/couchdb/branches/mochijson/src/couchdb/cjson.erl
Modified:
    incubator/couchdb/branches/mochijson/LICENCE
    incubator/couchdb/branches/mochijson/src/couchdb/Makefile.am
    incubator/couchdb/branches/mochijson/src/couchdb/couch.app.tpl.in
    incubator/couchdb/branches/mochijson/src/couchdb/couch_db.hrl
    incubator/couchdb/branches/mochijson/src/couchdb/couch_db_update_notifier.erl
    incubator/couchdb/branches/mochijson/src/couchdb/couch_doc.erl
    incubator/couchdb/branches/mochijson/src/couchdb/couch_httpd.erl
    incubator/couchdb/branches/mochijson/src/couchdb/couch_query_servers.erl
    incubator/couchdb/branches/mochijson/src/couchdb/couch_rep.erl
    incubator/couchdb/branches/mochijson/src/couchdb/couch_view.erl

Modified: incubator/couchdb/branches/mochijson/LICENCE
URL: http://svn.apache.org/viewvc/incubator/couchdb/branches/mochijson/LICENCE?rev=660321&r1=660320&r2=660321&view=diff
==============================================================================
--- incubator/couchdb/branches/mochijson/LICENCE (original)
+++ incubator/couchdb/branches/mochijson/LICENCE Mon May 26 14:51:52 2008
@@ -254,31 +254,6 @@
 
 -------------------------------------------------------------------------------
 
-src/couchdb/cjson.erl:
-
-Copyright (c) 2006 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.
-
--------------------------------------------------------------------------------
-
 src/mochiweb:
 
 Copyright (c) 2007 Mochi Media, Inc.

Modified: incubator/couchdb/branches/mochijson/src/couchdb/Makefile.am
URL: http://svn.apache.org/viewvc/incubator/couchdb/branches/mochijson/src/couchdb/Makefile.am?rev=660321&r1=660320&r2=660321&view=diff
==============================================================================
--- incubator/couchdb/branches/mochijson/src/couchdb/Makefile.am (original)
+++ incubator/couchdb/branches/mochijson/src/couchdb/Makefile.am Mon May 26 14:51:52 2008
@@ -29,7 +29,6 @@
 couchincludedir = $(erlanglibdir)/couch-$(version)/include
 
 couch_file_collection = \
-    cjson.erl \
     couch_btree.erl \
     couch_db.erl \
     couch_db_update_notifier.erl \
@@ -49,7 +48,6 @@
     couch_view.erl
 
 couchebin_DATA = \
-    cjson.beam \
     couch.app \
     couch_btree.beam \
     couch_db.beam \

Modified: incubator/couchdb/branches/mochijson/src/couchdb/couch.app.tpl.in
URL: http://svn.apache.org/viewvc/incubator/couchdb/branches/mochijson/src/couchdb/couch.app.tpl.in?rev=660321&r1=660320&r2=660321&view=diff
==============================================================================
--- incubator/couchdb/branches/mochijson/src/couchdb/couch.app.tpl.in (original)
+++ incubator/couchdb/branches/mochijson/src/couchdb/couch.app.tpl.in Mon May 26 14:51:52
2008
@@ -2,7 +2,6 @@
              [{description,"@package_name@"},
               {vsn,"@version@"},
               {modules,[couch_btree,
-                        cjson,
                         couch_db,
                         couch_doc,
                         couch_query_servers,

Modified: incubator/couchdb/branches/mochijson/src/couchdb/couch_db.hrl
URL: http://svn.apache.org/viewvc/incubator/couchdb/branches/mochijson/src/couchdb/couch_db.hrl?rev=660321&r1=660320&r2=660321&view=diff
==============================================================================
--- incubator/couchdb/branches/mochijson/src/couchdb/couch_db.hrl (original)
+++ incubator/couchdb/branches/mochijson/src/couchdb/couch_db.hrl Mon May 26 14:51:52 2008
@@ -55,7 +55,7 @@
     revs = [], % in the form [{RevId, IsAvailable}, ...]
 
     % the json body object.
-    body = {obj, []},
+    body = {struct, []},
 
     % each attachment contains:
     %    {data, Type, <<binary>>}

Modified: incubator/couchdb/branches/mochijson/src/couchdb/couch_db_update_notifier.erl
URL: http://svn.apache.org/viewvc/incubator/couchdb/branches/mochijson/src/couchdb/couch_db_update_notifier.erl?rev=660321&r1=660320&r2=660321&view=diff
==============================================================================
--- incubator/couchdb/branches/mochijson/src/couchdb/couch_db_update_notifier.erl (original)
+++ incubator/couchdb/branches/mochijson/src/couchdb/couch_db_update_notifier.erl Mon May
26 14:51:52 2008
@@ -52,8 +52,8 @@
     FunAcc2 = Fun(Event, FunAcc),
     {ok, {Fun, FunAcc2}};
 handle_event({EventAtom, DbName}, Port) ->
-    Obj = {obj, [{type, atom_to_list(EventAtom)}, {db, DbName}]},
-    true = port_command(Port, cjson:encode(Obj) ++ "\n"),
+    Obj = {struct, [{type, atom_to_list(EventAtom)}, {db, DbName}]},
+    true = port_command(Port, mochijson2:encode(Obj) ++ "\n"),
     {ok, Port}.
 
 handle_call(_Request, State) ->

Modified: incubator/couchdb/branches/mochijson/src/couchdb/couch_doc.erl
URL: http://svn.apache.org/viewvc/incubator/couchdb/branches/mochijson/src/couchdb/couch_doc.erl?rev=660321&r1=660320&r2=660321&view=diff
==============================================================================
--- incubator/couchdb/branches/mochijson/src/couchdb/couch_doc.erl (original)
+++ incubator/couchdb/branches/mochijson/src/couchdb/couch_doc.erl Mon May 26 14:51:52 2008
@@ -19,14 +19,14 @@
 -include("couch_db.hrl").
 
 to_json_obj(#doc{id=Id,deleted=Del,body=Body,revs=Revs,meta=Meta}=Doc,Options)->
-    {obj, [{"_id", Id}] ++
+    {struct, [{"_id", Id}] ++
         case Revs of
         [] -> [];
         _ -> [{"_rev", lists:nth(1, Revs)}]
         end ++
         case Del of
         false ->
-            {obj, BodyProps} = Body,
+            {struct, BodyProps} = Body,
             BodyProps;
         true ->
             [{"_deleted", true}]
@@ -39,7 +39,7 @@
         lists:map(
             fun({revs_info, RevsInfo}) ->
                 JsonRevsInfo =
-                [{obj, [{rev, Rev}, {status, atom_to_list(Status)}]} ||
+                [{struct, [{rev, Rev}, {status, atom_to_list(Status)}]} ||
                     {Rev, Status} <- RevsInfo],
                 {"_revs_info", list_to_tuple(JsonRevsInfo)};
             ({conflicts, Conflicts}) ->
@@ -51,7 +51,7 @@
         true -> % return the full rev list and the binaries as strings.
             BinProps = lists:map(
                 fun({Name, {Type, BinValue}}) ->
-                    {Name, {obj, [
+                    {Name, {struct, [
                         {"content_type", Type},
                         {"data", couch_util:encodeBase64(bin_to_binary(BinValue))}
                     ]}}
@@ -59,12 +59,12 @@
                 Doc#doc.attachments),
             case BinProps of
             [] -> [];
-            _ -> [{"_attachments", {obj, BinProps}}]
+            _ -> [{"_attachments", {struct, BinProps}}]
             end;
         false ->
             BinProps = lists:map(
                 fun({Name, {Type, BinValue}}) ->
-                    {Name, {obj, [
+                    {Name, {struct, [
                         {"stub", true},
                         {"content_type", Type},
                         {"length", bin_size(BinValue)}
@@ -73,14 +73,14 @@
                 Doc#doc.attachments),
             case BinProps of
                 [] -> [];
-                _ -> [{"_attachments", {obj, BinProps}}]
+                _ -> [{"_attachments", {struct, BinProps}}]
             end
         end
-        }.
+    }.
 
-from_json_obj({obj, Props}) ->
-    {obj,JsonBins} = proplists:get_value("_attachments", Props, {obj, []}),
-    Bins = lists:flatmap(fun({Name, {obj, BinProps}}) ->
+from_json_obj({struct, Props}) ->
+    {struct, JsonBins} = proplists:get_value("_attachments", Props, {struct, []}),
+    Bins = lists:flatmap(fun({Name, {struct, BinProps}}) ->
         case proplists:get_value("stub", BinProps) of
         true ->
             [{Name, stub}];
@@ -114,7 +114,7 @@
         id = proplists:get_value("_id", Props, ""),
         revs = Revs,
         deleted = proplists:get_value("_deleted", Props, false),
-        body = {obj, [{Key, Value} || {[FirstChar|_]=Key, Value} <- Props, FirstChar /=
$_]},
+        body = {struct, [{Key, Value} || {[FirstChar|_]=Key, Value} <- Props, FirstChar
/= $_]},
         attachments = Bins
         }.
 
@@ -176,9 +176,9 @@
     {ok, Bin, _Sp2} = couch_stream:read(Fd, Sp, Len),
     Bin.
 
-get_view_functions(#doc{body={obj, Fields}}) ->
+get_view_functions(#doc{body={struct, Fields}}) ->
     Lang = proplists:get_value("language", Fields, "javascript"),
-    {obj, Views} = proplists:get_value("views", Fields, {obj, []}),
+    {struct, Views} = proplists:get_value("views", Fields, {struct, []}),
     {Lang, [{ViewName, Value} || {ViewName, Value} <- Views, is_list(Value)]};
 get_view_functions(_Doc) ->
     none.

Modified: incubator/couchdb/branches/mochijson/src/couchdb/couch_httpd.erl
URL: http://svn.apache.org/viewvc/incubator/couchdb/branches/mochijson/src/couchdb/couch_httpd.erl?rev=660321&r1=660320&r2=660321&view=diff
==============================================================================
--- incubator/couchdb/branches/mochijson/src/couchdb/couch_httpd.erl (original)
+++ incubator/couchdb/branches/mochijson/src/couchdb/couch_httpd.erl Mon May 26 14:51:52 2008
@@ -111,9 +111,9 @@
 % Global request handlers
 
 handle_welcome_request(Req, 'GET') ->
-    send_json(Req, {obj, [
-        {"couchdb", "Welcome"},
-        {"version", couch_server:get_version()}
+    send_json(Req, {struct, [
+        {"couchdb", <<"Welcome">>},
+        {"version", iolist_to_binary(couch_server:get_version())}
     ]});
 
 handle_welcome_request(_Req, _Method) ->
@@ -127,19 +127,19 @@
     throw({method_not_allowed, "GET,HEAD"}).
 
 handle_replicate_request(Req, 'POST') ->
-    {obj, Props} = cjson:decode(Req:recv_body()),
+    {struct, Props} = mochijson2:decode(Req:recv_body()),
     Source = proplists:get_value("source", Props),
     Target = proplists:get_value("target", Props),
-    {obj, Options} = proplists:get_value("options", Props, {obj, []}),
-    {ok, {obj, JsonResults}} = couch_rep:replicate(Source, Target, Options),
-    send_json(Req, {obj, [{ok, true} | JsonResults]});
+    {struct, Options} = proplists:get_value("options", Props, {struct, []}),
+    {ok, {struct, JsonResults}} = couch_rep:replicate(Source, Target, Options),
+    send_json(Req, {struct, [{ok, true} | JsonResults]});
 
 handle_replicate_request(_Req, _Method) ->
     throw({method_not_allowed, "POST"}).
 
 handle_restart_request(Req, 'POST') ->
     couch_server:remote_restart(),
-    send_json(Req, {obj, [{ok, true}]});
+    send_json(Req, {struct, [{ok, true}]});
 
 handle_restart_request(_Req, _Method) ->
     throw({method_not_allowed, "POST"}).
@@ -154,7 +154,7 @@
 handle_db_request(Req, 'PUT', {DbName, []}) ->
     case couch_server:create(DbName, []) of
         {ok, _Db} ->
-            send_json(Req, 201, {obj, [{ok, true}]});
+            send_json(Req, 201, {struct, [{ok, true}]});
         {error, database_already_exists} ->
             Msg = io_lib:format("Database ~p already exists.", [DbName]),
             throw({database_already_exists, Msg});
@@ -173,21 +173,21 @@
 
 handle_db_request(Req, 'DELETE', {DbName, _Db, []}) ->
     ok = couch_server:delete(DbName),
-    send_json(Req, 200, {obj, [
+    send_json(Req, 200, {struct, [
         {ok, true}
     ]});
 
 handle_db_request(Req, 'GET', {DbName, Db, []}) ->
     {ok, DbInfo} = couch_db:get_db_info(Db),
-    send_json(Req, {obj, [{db_name, DbName} | DbInfo]});
+    send_json(Req, {struct, [{db_name, DbName} | DbInfo]});
 
 handle_db_request(Req, 'POST', {_DbName, Db, []}) ->
     % TODO: Etag handling
-    Json = cjson:decode(Req:recv_body()),
+    Json = mochijson2:decode(Req:recv_body()),
     Doc = couch_doc:from_json_obj(Json),
     DocId = couch_util:new_uuid(),
     {ok, NewRev} = couch_db:update_doc(Db, Doc#doc{id=DocId, revs=[]}, []),
-    send_json(Req, 201, {obj, [
+    send_json(Req, 201, {struct, [
         {ok, true},
         {id, DocId},
         {rev, NewRev}
@@ -198,13 +198,13 @@
 
 handle_db_request(Req, 'POST', {_DbName, Db, ["_bulk_docs"]}) ->
     Options = [], % put options here.
-    {obj, JsonProps} = cjson:decode(Req:recv_body()),
+    {struct, JsonProps} = mochijson2:decode(Req:recv_body()),
     DocsArray = proplists:get_value("docs", JsonProps),
     % convert all the doc elements to native docs
     case proplists:get_value("new_edits", JsonProps, true) of
     true ->
         Docs = lists:map(
-            fun({obj, ObjProps} = JsonObj) ->
+            fun({struct, ObjProps} = JsonObj) ->
                 Doc = couch_doc:from_json_obj(JsonObj),
                 Id = case Doc#doc.id of
                     "" -> couch_util:new_uuid();
@@ -222,10 +222,10 @@
         % output the results
         DocResults = lists:zipwith(
             fun(Doc, NewRev) ->
-                {obj, [{"id", Doc#doc.id}, {"rev", NewRev}]}
+                {struct, [{"id", Doc#doc.id}, {"rev", NewRev}]}
             end,
             Docs, ResultRevs),
-        send_json(Req, 201, {obj, [
+        send_json(Req, 201, {struct, [
             {ok, true},
             {new_revs, list_to_tuple(DocResults)}
         ]});
@@ -233,7 +233,7 @@
     false ->
         Docs = [couch_doc:from_json_obj(JsonObj) || JsonObj <- tuple_to_list(DocsArray)],
         ok = couch_db:save_docs(Db, Docs, Options),
-        send_json(Req, 201, {obj, [
+        send_json(Req, 201, {struct, [
             {ok, true}
         ]})
     end;
@@ -243,7 +243,7 @@
 
 handle_db_request(Req, 'POST', {_DbName, Db, ["_compact"]}) ->
     ok = couch_db:start_compact(Db),
-    send_json(Req, 202, {obj, [
+    send_json(Req, 202, {struct, [
         {ok, true}
     ]});
 
@@ -254,7 +254,7 @@
     case Req:parse_qs() of
         [{"q", Query}] when (length(Query) > 0) ->
             {ok, Response} = couch_ft_query:execute(DbName, Query),
-            send_json(Req, {obj, [{ok, true} | Response]});
+            send_json(Req, {struct, [{ok, true} | Response]});
         _Error ->
             throw({no_fulltext_query, "Empty Query String"})
     end;
@@ -284,7 +284,7 @@
     AdapterFun = fun(#full_doc_info{id=Id}=FullDocInfo, Offset, Acc) ->
         case couch_doc:to_doc_info(FullDocInfo) of
         #doc_info{deleted=false, rev=Rev} ->
-            FoldlFun({{Id, Id}, {obj, [{rev, Rev}]}}, Offset, Acc);
+            FoldlFun({{Id, Id}, {struct, [{rev, Rev}]}}, Offset, Acc);
         #doc_info{deleted=true} ->
             {ok, Acc}
         end
@@ -324,7 +324,7 @@
                 conflict_revs=ConflictRevs,
                 deleted_conflict_revs=DelConflictRevs
             } = DocInfo,
-            Json = {obj,
+            Json = {struct,
                 [{"rev", Rev}] ++
                 case ConflictRevs of
                     []  ->  [];
@@ -369,7 +369,7 @@
         case couch_view:get_reduce_view({DbName, "_design/" ++ DocId, ViewName}) of
         {ok, View} ->
             {ok, Value} = couch_view:reduce(View, {StartKey, StartDocId}, {EndKey, EndDocId}),
-            send_json(Req, {obj, [{ok,true}, {result, Value}]});
+            send_json(Req, {struct, [{ok,true}, {result, Value}]});
         _ ->
             throw({not_found, Reason})
         end
@@ -379,12 +379,12 @@
     throw({method_not_allowed, "GET,HEAD"});
 
 handle_db_request(Req, 'POST', {_DbName, Db, ["_missing_revs"]}) ->
-    {obj, JsonDocIdRevs} = cjson:decode(Req:recv_body()),
+    {struct, JsonDocIdRevs} = mochijson2:decode(Req:recv_body()),
     DocIdRevs = [{Id, tuple_to_list(Revs)} || {Id, Revs} <- JsonDocIdRevs],
     {ok, Results} = couch_db:get_missing_revs(Db, DocIdRevs),
     JsonResults = [{Id, list_to_tuple(Revs)} || {Id, Revs} <- Results],
-    send_json(Req, {obj, [
-        {missing_revs, {obj, JsonResults}}
+    send_json(Req, {struct, [
+        {missing_revs, {struct, JsonResults}}
     ]});
 
 handle_db_request(Req, 'POST', {DbName, _Db, ["_temp_view"]}) ->
@@ -403,7 +403,7 @@
         "application/json" -> ok;
         Else -> throw({incorrect_mime_type, Else})
     end,
-    {obj, Props} = cjson:decode(Req:recv_body()),
+    {struct, Props} = mochijson2:decode(Req:recv_body()),
     Language = proplists:get_value("language", Props, "javascript"),
     MapSrc = proplists:get_value("map", Props),
     case proplists:get_value("reduce", Props, null) of
@@ -421,7 +421,7 @@
         {ok, View} = couch_view:get_reduce_view(
                 {temp, DbName, Language, MapSrc, RedSrc}),
         {ok, Value} = couch_view:reduce(View, {StartKey, StartDocId}, {EndKey, EndDocId}),
-        send_json(Req, {obj, [{ok,true}, {result, Value}]})
+        send_json(Req, {struct, [{ok,true}, {result, Value}]})
     end;
 
 handle_db_request(_Req, _Method, {_DbName, _Db, ["_temp_view"]}) ->
@@ -460,7 +460,7 @@
         throw({bad_request, "Document rev and etag have different values"})
     end,
     {ok, NewRev} = couch_db:delete_doc(Db, DocId, [RevToDelete]),
-    send_json(Req, 200, {obj, [
+    send_json(Req, 200, {struct, [
         {ok, true},
         {id, DocId},
         {rev, NewRev}
@@ -510,11 +510,11 @@
                 case Result of
                 {ok, Doc} ->
                     JsonDoc = couch_doc:to_json_obj(Doc, Options),
-                    Json = lists:flatten(cjson:encode({obj, [{ok, JsonDoc}]})),
+                    Json = lists:flatten(mochijson2:encode({struct, [{ok, JsonDoc}]})),
                     Resp:write_chunk(AccSeparator ++ Json);
                 {{not_found, missing}, RevId} ->
-                    Json = {obj, [{"missing", RevId}]},
-                    Json = lists:flatten(cjson:encode(Json)),
+                    Json = {struct, [{"missing", RevId}]},
+                    Json = lists:flatten(mochijson2:encode(Json)),
                     Resp:write_chunk(AccSeparator ++ Json)
                 end,
                 "," % AccSeparator now has a comma
@@ -525,7 +525,7 @@
     end;
 
 handle_doc_request(Req, 'PUT', _DbName, Db, DocId) ->
-    Json = {obj, DocProps} = cjson:decode(Req:recv_body(?MAX_DOC_SIZE)),
+    Json = {struct, DocProps} = mochijson2:decode(Req:recv_body(?MAX_DOC_SIZE)),
     DocRev = proplists:get_value("_rev", DocProps),
     Etag = case Req:get_header_value("If-Match") of
         undefined ->
@@ -549,7 +549,7 @@
     Doc = couch_doc:from_json_obj(Json),
 
     {ok, NewRev} = couch_db:update_doc(Db, Doc#doc{id=DocId, revs=Revs}, []),
-    send_json(Req, 201, [{"Etag", "\"" ++ NewRev ++ "\""}], {obj, [
+    send_json(Req, 201, [{"Etag", "\"" ++ NewRev ++ "\""}], {struct, [
         {ok, true},
         {id, DocId},
         {rev, NewRev}
@@ -601,14 +601,14 @@
         {"", _} ->
             Args;
         {"key", Value} ->
-            JsonKey = cjson:decode(Value),
+            JsonKey = mochijson2:decode(Value),
             Args#view_query_args{start_key=JsonKey,end_key=JsonKey};
         {"startkey_docid", DocId} ->
             Args#view_query_args{start_docid=DocId};
         {"startkey", Value} ->
-            Args#view_query_args{start_key=cjson:decode(Value)};
+            Args#view_query_args{start_key=mochijson2:decode(Value)};
         {"endkey", Value} ->
-            Args#view_query_args{end_key=cjson:decode(Value)};
+            Args#view_query_args{end_key=mochijson2:decode(Value)};
         {"count", Value} ->
             case (catch list_to_integer(Value)) of
             Count when is_integer(Count) ->
@@ -705,11 +705,11 @@
             JsonBegin = io_lib:format("{\"total_rows\":~w,\"offset\":~w,\"rows\":[",
                     [TotalViewCount, Offset2]),
             Resp2:write_chunk(lists:flatten(JsonBegin)),
-            JsonObj = {obj, [{id, DocId}, {key, Key}, {value, Value}]},
-            {ok, {AccCount + 1, 0, Resp2, [cjson:encode(JsonObj) | AccRevRows]}};
+            JsonObj = {struct, [{id, DocId}, {key, Key}, {value, Value}]},
+            {ok, {AccCount + 1, 0, Resp2, [mochijson2:encode(JsonObj) | AccRevRows]}};
         {_, AccCount, _, Resp} ->
-            JsonObj = {obj, [{id, DocId}, {key, Key}, {value, Value}]},
-            {ok, {AccCount + 1, 0, Resp, [cjson:encode(JsonObj), "," | AccRevRows]}}
+            JsonObj = {struct, [{id, DocId}, {key, Key}, {value, Value}]},
+            {ok, {AccCount + 1, 0, Resp, [mochijson2:encode(JsonObj), "," | AccRevRows]}}
         end
     end,
 
@@ -730,12 +730,12 @@
             Resp2 = start_json_response(Req, 200),
             JsonBegin = io_lib:format("{\"total_rows\":~w,\"offset\":~w,\"rows\":[\r\n",
                     [TotalViewCount, Offset]),
-            JsonObj = {obj, [{id, DocId}, {key, Key}, {value, Value}]},
-            Resp2:write_chunk(lists:flatten(JsonBegin ++ cjson:encode(JsonObj))),
+            JsonObj = {struct, [{id, DocId}, {key, Key}, {value, Value}]},
+            Resp2:write_chunk(lists:flatten(JsonBegin ++ mochijson2:encode(JsonObj))),
             {ok, {AccCount - 1, 0, Resp2, AccRevRows}};
         {_, AccCount, _, Resp} when (AccCount > 0) ->
-            JsonObj = {obj, [{"id", DocId}, {"key", Key}, {"value", Value}]},
-            Resp:write_chunk(",\r\n" ++  lists:flatten(cjson:encode(JsonObj))),
+            JsonObj = {struct, [{"id", DocId}, {"key", Key}, {"value", Value}]},
+            Resp:write_chunk(",\r\n" ++  lists:flatten(mochijson2:encode(JsonObj))),
             {ok, {AccCount - 1, 0, Resp, AccRevRows}}
         end
     end,
@@ -749,7 +749,7 @@
     {ok, {_, _, undefined, _}} ->
         % nothing found in the view, nothing has been returned
         % send empty view
-        send_json(Req, 200, {obj, [
+        send_json(Req, 200, {struct, [
             {total_rows, TotalRows},
             {rows, {}}
         ]});
@@ -789,7 +789,7 @@
         {"open_revs", "all"} ->
             Args#doc_query_args{open_revs=all};
         {"open_revs", RevsJsonStr} ->
-            JsonArray = cjson:decode(RevsJsonStr),
+            JsonArray = mochijson2:decode(RevsJsonStr),
             Args#doc_query_args{open_revs=tuple_to_list(JsonArray)};
         _Else -> % unknown key value pair, ignore.
             Args
@@ -822,7 +822,7 @@
         _ ->
             lists:flatten(io_lib:format("~p", [Reason])) % else term to text
         end,
-    Json = {obj, [
+    Json = {struct, [
         {error, atom_to_list(Atom)},
         {reason, FormattedReason}
     ]},
@@ -871,7 +871,7 @@
 
 send_json(Req, Code, Headers, Value) ->
     ContentType = negotiate_content_type(Req),
-    Body = cjson:encode(Value),
+    Body = mochijson2:encode(Value),
     Resp = Req:respond({Code, [{"Content-Type", ContentType}] ++ Headers,
                         Body}),
     {ok, Resp}.

Modified: incubator/couchdb/branches/mochijson/src/couchdb/couch_query_servers.erl
URL: http://svn.apache.org/viewvc/incubator/couchdb/branches/mochijson/src/couchdb/couch_query_servers.erl?rev=660321&r1=660320&r2=660321&view=diff
==============================================================================
--- incubator/couchdb/branches/mochijson/src/couchdb/couch_query_servers.erl (original)
+++ incubator/couchdb/branches/mochijson/src/couchdb/couch_query_servers.erl Mon May 26 14:51:52
2008
@@ -50,8 +50,8 @@
     end.
 
 read_json(Port) ->
-    case cjson:decode(readline(Port)) of
-    {obj, [{"log", Msg}]} when is_list(Msg) ->
+    case mochijson2:decode(readline(Port)) of
+    {struct, [{"log", Msg}]} when is_list(Msg) ->
         % we got a message to log. Log it and continue
         ?LOG_INFO("Query Server Log Message: ~s", [Msg]),
         read_json(Port);
@@ -64,11 +64,11 @@
 
 % send command and get a response.
 prompt(Port, Json) ->
-    writeline(Port, cjson:encode(Json)),
+    writeline(Port, mochijson2:encode(Json)),
     case read_json(Port) of
-    {obj, [{"error", Id}, {"reason", Reason}]} ->
+    {struct, [{"error", Id}, {"reason", Reason}]} ->
         throw({list_to_atom(Id),Reason});
-    {obj, [{"reason", Reason}, {"error", Id}]} ->
+    {struct, [{"reason", Reason}, {"error", Id}]} ->
         throw({list_to_atom(Id),Reason});
     Result ->
         Result

Modified: incubator/couchdb/branches/mochijson/src/couchdb/couch_rep.erl
URL: http://svn.apache.org/viewvc/incubator/couchdb/branches/mochijson/src/couchdb/couch_rep.erl?rev=660321&r1=660320&r2=660321&view=diff
==============================================================================
--- incubator/couchdb/branches/mochijson/src/couchdb/couch_rep.erl (original)
+++ incubator/couchdb/branches/mochijson/src/couchdb/couch_rep.erl Mon May 26 14:51:52 2008
@@ -71,8 +71,8 @@
         end
     end,
 
-    #doc{body={obj,OldRepHistoryProps}} = RepRecSrc,
-    #doc{body={obj,OldRepHistoryPropsTrg}} = RepRecTgt,
+    #doc{body={struct, OldRepHistoryProps}} = RepRecSrc,
+    #doc{body={struct, OldRepHistoryPropsTrg}} = RepRecTgt,
 
     SeqNum =
     case OldRepHistoryProps == OldRepHistoryPropsTrg of
@@ -91,10 +91,10 @@
     case NewSeqNum == SeqNum andalso OldRepHistoryProps /= [] of
     true ->
         % nothing changed, don't record results
-        {ok, {obj, OldRepHistoryProps}};
+        {ok, {struct, OldRepHistoryProps}};
     false ->
         HistEntries =[
-            {obj,
+            {struct,
                 [{"start_time", StartTime},
                 {"end_time", httpd_util:rfc1123_date()},
                 {"start_last_seq", SeqNum},
@@ -102,7 +102,7 @@
             | tuple_to_list(proplists:get_value("history", OldRepHistoryProps, {}))],
         % something changed, record results
         NewRepHistory =
-            {obj,
+            {struct,
                 [{"session_id", couch_util:new_uuid()},
                 {"source_last_seq", NewSeqNum},
                 {"history", list_to_tuple(lists:sublist(HistEntries, 50))}]},
@@ -211,12 +211,12 @@
     [] ->
         {Url, []};
     _ ->
-        {Url, [], "application/json; charset=utf-8", lists:flatten(cjson:encode(JsonBody))}
+        {Url, [], "application/json; charset=utf-8", lists:flatten(mochijson2:encode(JsonBody))}
     end,
     {ok, {{_, ResponseCode,_},_Headers, ResponseBody}} = http:request(Action, Request, [],
[]),
     if
     ResponseCode >= 200, ResponseCode < 500 ->
-        cjson:decode(ResponseBody)
+        mochijson2:decode(ResponseBody)
     end.
 
 enum_docs0(_InFun, [], Acc) ->
@@ -240,10 +240,10 @@
 
 enum_docs_since(DbUrl, StartSeq, InFun, InAcc) when is_list(DbUrl) ->
     Url = DbUrl ++ "_all_docs_by_seq?startkey=" ++ integer_to_list(StartSeq),
-    {obj, Results} = do_http_request(Url, get),
+    {struct, Results} = do_http_request(Url, get),
     DocInfoList=
-    lists:map(fun({obj, RowInfoList}) ->
-        {obj, RowValueProps} = proplists:get_value("value", RowInfoList),
+    lists:map(fun({struct, RowInfoList}) ->
+        {struct, RowValueProps} = proplists:get_value("value", RowInfoList),
         #doc_info{
             id=proplists:get_value("id", RowInfoList),
             rev=proplists:get_value("rev", RowValueProps),
@@ -259,12 +259,12 @@
     couch_db:enum_docs_since(DbSource, StartSeq, Fun, Acc).
 
 get_missing_revs(DbUrl, DocIdRevsList) when is_list(DbUrl) ->
-    JsonDocIdRevsList = {obj,
+    JsonDocIdRevsList = {struct,
         [{Id, list_to_tuple(RevList)} || {Id, RevList} <- DocIdRevsList]},
-    {obj, ResponseMembers} =
+    {struct, ResponseMembers} =
     do_http_request(DbUrl ++ "_missing_revs",
         post, JsonDocIdRevsList),
-    {obj, DocMissingRevsList} = proplists:get_value("missing_revs", ResponseMembers),
+    {struct, DocMissingRevsList} = proplists:get_value("missing_revs", ResponseMembers),
     {ok, [{Id, tuple_to_list(MissingRevs)} || {Id, MissingRevs} <- DocMissingRevsList]};
 get_missing_revs(Db, DocId) ->
     couch_db:get_missing_revs(Db, DocId).
@@ -272,7 +272,7 @@
 
 update_doc(DbUrl, #doc{id=DocId}=Doc, _Options) when is_list(DbUrl) ->
     Url = DbUrl ++ url_encode(DocId),
-    {obj, ResponseMembers} =
+    {struct, ResponseMembers} =
         do_http_request(Url, put, couch_doc:to_json_obj(Doc, [revs,attachments])),
     RevId = proplists:get_value("_rev", ResponseMembers),
     {ok, RevId};
@@ -283,8 +283,8 @@
     ok;
 save_docs(DbUrl, Docs, []) when is_list(DbUrl) ->
     JsonDocs = [couch_doc:to_json_obj(Doc, [revs,attachments]) || Doc <- Docs],
-    {obj, Returned} =
-        do_http_request(DbUrl ++ "_bulk_docs", post, {obj, [{new_edits, false}, {docs, list_to_tuple(JsonDocs)}]}),
+    {struct, Returned} =
+        do_http_request(DbUrl ++ "_bulk_docs", post, {struct, [{new_edits, false}, {docs,
list_to_tuple(JsonDocs)}]}),
     true = proplists:get_value("ok", Returned),
     ok;
 save_docs(Db, Docs, Options) ->
@@ -293,7 +293,7 @@
 
 open_doc(DbUrl, DocId, []) when is_list(DbUrl) ->
     case do_http_request(DbUrl ++ url_encode(DocId), get) of
-    {obj, [{"error", ErrId}, {"reason", Reason}]} ->
+    {struct, [{"error", ErrId}, {"reason", Reason}]} ->
         {list_to_atom(ErrId), Reason};
     Doc  ->
         {ok, couch_doc:from_json_obj(Doc)}
@@ -308,14 +308,14 @@
             % latest is only option right now
             "latest=true"
         end, Options),
-    RevsQueryStrs = lists:flatten(cjson:encode(list_to_tuple(Revs))),
+    RevsQueryStrs = lists:flatten(mochijson2:encode(list_to_tuple(Revs))),
     Url = DbUrl ++ DocId ++ "?" ++ couch_util:implode(["revs=true", "attachments=true", "open_revs="
++ RevsQueryStrs ] ++ QueryOptionStrs, "&"),
     JsonResults = do_http_request(Url, get, []),
     Results =
     lists:map(
-        fun({obj, [{"missing", Rev}]}) ->
+        fun({struct, [{"missing", Rev}]}) ->
             {{not_found, missing}, Rev};
-        ({obj, [{"ok", JsonDoc}]}) ->
+        ({struct, [{"ok", JsonDoc}]}) ->
             {ok, couch_doc:from_json_obj(JsonDoc)}
         end, tuple_to_list(JsonResults)),
     {ok, Results};

Modified: incubator/couchdb/branches/mochijson/src/couchdb/couch_view.erl
URL: http://svn.apache.org/viewvc/incubator/couchdb/branches/mochijson/src/couchdb/couch_view.erl?rev=660321&r1=660320&r2=660321&view=diff
==============================================================================
--- incubator/couchdb/branches/mochijson/src/couchdb/couch_view.erl (original)
+++ incubator/couchdb/branches/mochijson/src/couchdb/couch_view.erl Mon May 26 14:51:52 2008
@@ -152,14 +152,14 @@
     Count.
                 
 
-design_doc_to_view_group(#doc{id=Id,body={obj, Fields}}) ->
+design_doc_to_view_group(#doc{id=Id,body={struct, Fields}}) ->
     Language = proplists:get_value("language", Fields, "javascript"),
-    {obj, RawViews} = proplists:get_value("views", Fields, {obj, []}),
+    {struct, RawViews} = proplists:get_value("views", Fields, {struct, []}),
             
     % add the views to a dictionary object, with the map source as the key
     DictBySrc =
     lists:foldl(
-        fun({Name, {obj, MRFuns}}, DictBySrcAcc) ->
+        fun({Name, {struct, MRFuns}}, DictBySrcAcc) ->
             MapSrc = proplists:get_value("map", MRFuns),
             RedSrc = proplists:get_value("reduce", MRFuns, null),
             View =
@@ -516,7 +516,7 @@
 type_sort(V) when is_integer(V) -> 1;
 type_sort(V) when is_float(V) -> 1;
 type_sort(V) when is_list(V) -> 2;
-type_sort({obj, _}) -> 4; % must come before tuple test below
+type_sort({struct, _}) -> 4; % must come before tuple test below
 type_sort(V) when is_tuple(V) -> 3;
 type_sort(V) when is_binary(V) -> 5.
 
@@ -529,7 +529,7 @@
     atom_sort(A) < atom_sort(B);
 less_same_type(A,B) when is_list(A) ->
     couch_util:collate(A, B) < 0;
-less_same_type({obj, AProps}, {obj, BProps}) ->
+less_same_type({struct, AProps}, {struct, BProps}) ->
     less_props(AProps, BProps);
 less_same_type(A, B) when is_tuple(A) ->
     less_list(tuple_to_list(A),tuple_to_list(B));



Mime
View raw message