diff options
author | Filipe David Borba Manana <fdmanana@apache.org> | 2010-09-27 19:14:37 +0000 |
---|---|---|
committer | Filipe David Borba Manana <fdmanana@apache.org> | 2010-09-27 19:14:37 +0000 |
commit | 6c6db011c2064597526c6f36878a282238dd2bf2 (patch) | |
tree | 9875a3237a385b3ff9d9f53be7642bafbabcbbfa /src | |
parent | c4e2e1416bcedbe654d56c3851a0d08cddfc4bee (diff) |
Replacing calls to couch_util:get_value with ?getv
git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@1001879 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src')
28 files changed, 213 insertions, 210 deletions
diff --git a/src/couchdb/couch_auth_cache.erl b/src/couchdb/couch_auth_cache.erl index 078bfcc1..d00a4fed 100644 --- a/src/couchdb/couch_auth_cache.erl +++ b/src/couchdb/couch_auth_cache.erl @@ -52,7 +52,7 @@ get_user_creds(UserName) -> {<<"salt">>, ?l2b(Salt)}, {<<"password_sha">>, ?l2b(HashedPwd)}]; UserProps when is_list(UserProps) -> - DocRoles = couch_util:get_value(<<"roles">>, UserProps), + DocRoles = ?getv(<<"roles">>, UserProps), [{<<"roles">>, [<<"_admin">> | DocRoles]}, {<<"salt">>, ?l2b(Salt)}, {<<"password_sha">>, ?l2b(HashedPwd)}] @@ -83,7 +83,7 @@ get_from_cache(UserName) -> validate_user_creds(nil) -> nil; validate_user_creds(UserCreds) -> - case couch_util:get_value(<<"_conflicts">>, UserCreds) of + case ?getv(<<"_conflicts">>, UserCreds) of undefined -> ok; _ConflictList -> @@ -240,7 +240,7 @@ add_cache_entry(UserName, Credentials, ATime, State) -> end, true = ets:insert(?BY_ATIME, {ATime, UserName}), true = ets:insert(?BY_USER, {UserName, {Credentials, ATime}}), - State#state{cache_size = couch_util:get_value(size, ets:info(?BY_USER))}. + State#state{cache_size = ?getv(size, ets:info(?BY_USER))}. free_mru_cache_entry() -> diff --git a/src/couchdb/couch_btree.erl b/src/couchdb/couch_btree.erl index 0e47bac7..3331e2eb 100644 --- a/src/couchdb/couch_btree.erl +++ b/src/couchdb/couch_btree.erl @@ -16,6 +16,7 @@ -export([fold/4, full_reduce/1, final_reduce/2, foldl/3, foldl/4]). -export([fold_reduce/4, lookup/2, get_state/1, set_options/2]). +-include("couch_db.hrl"). -define(CHUNK_THRESHOLD, 16#4ff). -record(btree, @@ -70,10 +71,10 @@ final_reduce(Reduce, {KVs, Reductions}) -> final_reduce(Reduce, {[], [Red | Reductions]}). fold_reduce(#btree{root=Root}=Bt, Fun, Acc, Options) -> - Dir = couch_util:get_value(dir, Options, fwd), - StartKey = couch_util:get_value(start_key, Options), - EndKey = couch_util:get_value(end_key, Options), - KeyGroupFun = couch_util:get_value(key_group_fun, Options, fun(_,_) -> true end), + Dir = ?getv(dir, Options, fwd), + StartKey = ?getv(start_key, Options), + EndKey = ?getv(end_key, Options), + KeyGroupFun = ?getv(key_group_fun, Options, fun(_,_) -> true end), {StartKey2, EndKey2} = case Dir of rev -> {EndKey, StartKey}; @@ -107,9 +108,9 @@ convert_fun_arity(Fun) when is_function(Fun, 3) -> Fun. % Already arity 3 make_key_in_end_range_function(#btree{less=Less}, fwd, Options) -> - case couch_util:get_value(end_key_gt, Options) of + case ?getv(end_key_gt, Options) of undefined -> - case couch_util:get_value(end_key, Options) of + case ?getv(end_key, Options) of undefined -> fun(_Key) -> true end; LastKey -> @@ -119,9 +120,9 @@ make_key_in_end_range_function(#btree{less=Less}, fwd, Options) -> fun(Key) -> Less(Key, EndKey) end end; make_key_in_end_range_function(#btree{less=Less}, rev, Options) -> - case couch_util:get_value(end_key_gt, Options) of + case ?getv(end_key_gt, Options) of undefined -> - case couch_util:get_value(end_key, Options) of + case ?getv(end_key, Options) of undefined -> fun(_Key) -> true end; LastKey -> @@ -142,10 +143,10 @@ foldl(Bt, Fun, Acc, Options) -> fold(#btree{root=nil}, _Fun, Acc, _Options) -> {ok, {[], []}, Acc}; fold(#btree{root=Root}=Bt, Fun, Acc, Options) -> - Dir = couch_util:get_value(dir, Options, fwd), + Dir = ?getv(dir, Options, fwd), InRange = make_key_in_end_range_function(Bt, Dir, Options), Result = - case couch_util:get_value(start_key, Options) of + case ?getv(start_key, Options) of undefined -> stream_node(Bt, [], Bt#btree.root, InRange, Dir, convert_fun_arity(Fun), Acc); diff --git a/src/couchdb/couch_db.erl b/src/couchdb/couch_db.erl index 36b61a7e..e26dee7f 100644 --- a/src/couchdb/couch_db.erl +++ b/src/couchdb/couch_db.erl @@ -270,8 +270,8 @@ get_design_docs(#db{fulldocinfo_by_id_btree=Btree}=Db) -> check_is_admin(#db{user_ctx=#user_ctx{name=Name,roles=Roles}}=Db) -> {Admins} = get_admins(Db), - AdminRoles = [<<"_admin">> | couch_util:get_value(<<"roles">>, Admins, [])], - AdminNames = couch_util:get_value(<<"names">>, Admins,[]), + AdminRoles = [<<"_admin">> | ?getv(<<"roles">>, Admins, [])], + AdminNames = ?getv(<<"names">>, Admins,[]), case AdminRoles -- Roles of AdminRoles -> % same list, not an admin role case AdminNames -- [Name] of @@ -289,9 +289,9 @@ check_is_reader(#db{user_ctx=#user_ctx{name=Name,roles=Roles}=UserCtx}=Db) -> ok -> ok; _ -> {Readers} = get_readers(Db), - ReaderRoles = couch_util:get_value(<<"roles">>, Readers,[]), + ReaderRoles = ?getv(<<"roles">>, Readers,[]), WithAdminRoles = [<<"_admin">> | ReaderRoles], - ReaderNames = couch_util:get_value(<<"names">>, Readers,[]), + ReaderNames = ?getv(<<"names">>, Readers,[]), case ReaderRoles ++ ReaderNames of [] -> ok; % no readers == public access _Else -> @@ -311,10 +311,10 @@ check_is_reader(#db{user_ctx=#user_ctx{name=Name,roles=Roles}=UserCtx}=Db) -> end. get_admins(#db{security=SecProps}) -> - couch_util:get_value(<<"admins">>, SecProps, {[]}). + ?getv(<<"admins">>, SecProps, {[]}). get_readers(#db{security=SecProps}) -> - couch_util:get_value(<<"readers">>, SecProps, {[]}). + ?getv(<<"readers">>, SecProps, {[]}). get_security(#db{security=SecProps}) -> {SecProps}. @@ -329,21 +329,21 @@ set_security(_, _) -> throw(bad_request). validate_security_object(SecProps) -> - Admins = couch_util:get_value(<<"admins">>, SecProps, {[]}), - Readers = couch_util:get_value(<<"readers">>, SecProps, {[]}), + Admins = ?getv(<<"admins">>, SecProps, {[]}), + Readers = ?getv(<<"readers">>, SecProps, {[]}), ok = validate_names_and_roles(Admins), ok = validate_names_and_roles(Readers), ok. % validate user input validate_names_and_roles({Props}) when is_list(Props) -> - case couch_util:get_value(<<"names">>,Props,[]) of + case ?getv(<<"names">>,Props,[]) of Ns when is_list(Ns) -> [throw("names must be a JSON list of strings") ||N <- Ns, not is_binary(N)], Ns; _ -> throw("names must be a JSON list of strings") end, - case couch_util:get_value(<<"roles">>,Props,[]) of + case ?getv(<<"roles">>,Props,[]) of Rs when is_list(Rs) -> [throw("roles must be a JSON list of strings") ||R <- Rs, not is_binary(R)], Rs; diff --git a/src/couchdb/couch_doc.erl b/src/couchdb/couch_doc.erl index f8c874b0..1063f501 100644 --- a/src/couchdb/couch_doc.erl +++ b/src/couchdb/couch_doc.erl @@ -195,26 +195,26 @@ transfer_fields([{<<"_rev">>, _Rev} | Rest], Doc) -> transfer_fields([{<<"_attachments">>, {JsonBins}} | Rest], Doc) -> Atts = lists:map(fun({Name, {BinProps}}) -> - case couch_util:get_value(<<"stub">>, BinProps) of + case ?getv(<<"stub">>, BinProps) of true -> - Type = couch_util:get_value(<<"content_type">>, BinProps), - RevPos = couch_util:get_value(<<"revpos">>, BinProps, nil), - DiskLen = couch_util:get_value(<<"length">>, BinProps), + Type = ?getv(<<"content_type">>, BinProps), + RevPos = ?getv(<<"revpos">>, BinProps, nil), + DiskLen = ?getv(<<"length">>, BinProps), {Enc, EncLen} = att_encoding_info(BinProps), #att{name=Name, data=stub, type=Type, att_len=EncLen, disk_len=DiskLen, encoding=Enc, revpos=RevPos}; _ -> - Type = couch_util:get_value(<<"content_type">>, BinProps, + Type = ?getv(<<"content_type">>, BinProps, ?DEFAULT_ATTACHMENT_CONTENT_TYPE), - RevPos = couch_util:get_value(<<"revpos">>, BinProps, 0), - case couch_util:get_value(<<"follows">>, BinProps) of + RevPos = ?getv(<<"revpos">>, BinProps, 0), + case ?getv(<<"follows">>, BinProps) of true -> - DiskLen = couch_util:get_value(<<"length">>, BinProps), + DiskLen = ?getv(<<"length">>, BinProps), {Enc, EncLen} = att_encoding_info(BinProps), #att{name=Name, data=follows, type=Type, encoding=Enc, att_len=EncLen, disk_len=DiskLen, revpos=RevPos}; _ -> - Value = couch_util:get_value(<<"data">>, BinProps), + Value = ?getv(<<"data">>, BinProps), Bin = base64:decode(Value), LenBin = size(Bin), #att{name=Name, data=Bin, type=Type, att_len=LenBin, @@ -225,8 +225,8 @@ transfer_fields([{<<"_attachments">>, {JsonBins}} | Rest], Doc) -> transfer_fields(Rest, Doc#doc{atts=Atts}); transfer_fields([{<<"_revisions">>, {Props}} | Rest], Doc) -> - RevIds = couch_util:get_value(<<"ids">>, Props), - Start = couch_util:get_value(<<"start">>, Props), + RevIds = ?getv(<<"ids">>, Props), + Start = ?getv(<<"start">>, Props), if not is_integer(Start) -> throw({doc_validation, "_revisions.start isn't an integer."}); not is_list(RevIds) -> @@ -261,12 +261,12 @@ transfer_fields([Field | Rest], #doc{body=Fields}=Doc) -> transfer_fields(Rest, Doc#doc{body=[Field|Fields]}). att_encoding_info(BinProps) -> - DiskLen = couch_util:get_value(<<"length">>, BinProps), - case couch_util:get_value(<<"encoding">>, BinProps) of + DiskLen = ?getv(<<"length">>, BinProps), + case ?getv(<<"encoding">>, BinProps) of undefined -> {identity, DiskLen}; Enc -> - EncodedLen = couch_util:get_value(<<"encoded_length">>, BinProps, DiskLen), + EncodedLen = ?getv(<<"encoded_length">>, BinProps, DiskLen), {list_to_existing_atom(?b2l(Enc)), EncodedLen} end. @@ -338,7 +338,7 @@ att_to_bin(#att{data=DataFun, att_len=Len}) when is_function(DataFun)-> ). get_validate_doc_fun(#doc{body={Props}}=DDoc) -> - case couch_util:get_value(<<"validate_doc_update">>, Props) of + case ?getv(<<"validate_doc_update">>, Props) of undefined -> nil; _Else -> @@ -473,7 +473,7 @@ doc_from_multi_part_stream(ContentType, DataFun) -> end. mp_parse_doc({headers, H}, []) -> - case couch_util:get_value("content-type", H) of + case ?getv("content-type", H) of {"application/json", _} -> fun (Next) -> mp_parse_doc(Next, []) diff --git a/src/couchdb/couch_httpd.erl b/src/couchdb/couch_httpd.erl index e853f97d..2ce4ebba 100644 --- a/src/couchdb/couch_httpd.erl +++ b/src/couchdb/couch_httpd.erl @@ -382,7 +382,7 @@ qs_value(Req, Key) -> qs_value(Req, Key, undefined). qs_value(Req, Key, Default) -> - couch_util:get_value(Key, qs(Req), Default). + ?getv(Key, qs(Req), Default). qs(#httpd{mochi_req=MochiReq}) -> MochiReq:parse_qs(). @@ -844,7 +844,7 @@ nil_callback(_Data)-> fun(Next) -> nil_callback(Next) end. get_boundary({"multipart/" ++ _, Opts}) -> - case couch_util:get_value("boundary", Opts) of + case ?getv("boundary", Opts) of S when is_list(S) -> S end; diff --git a/src/couchdb/couch_httpd_auth.erl b/src/couchdb/couch_httpd_auth.erl index f76898e1..b16a439e 100644 --- a/src/couchdb/couch_httpd_auth.erl +++ b/src/couchdb/couch_httpd_auth.erl @@ -69,14 +69,14 @@ default_authentication_handler(Req) -> nil -> throw({unauthorized, <<"Name or password is incorrect.">>}); UserProps -> - UserSalt = couch_util:get_value(<<"salt">>, UserProps, <<>>), + UserSalt = ?getv(<<"salt">>, UserProps, <<>>), PasswordHash = hash_password(?l2b(Pass), UserSalt), - ExpectedHash = couch_util:get_value(<<"password_sha">>, UserProps, nil), + ExpectedHash = ?getv(<<"password_sha">>, UserProps, nil), case couch_util:verify(ExpectedHash, PasswordHash) of true -> Req#httpd{user_ctx=#user_ctx{ name=?l2b(User), - roles=couch_util:get_value(<<"roles">>, UserProps, []) + roles=?getv(<<"roles">>, UserProps, []) }}; _Else -> throw({unauthorized, <<"Name or password is incorrect.">>}) @@ -180,7 +180,7 @@ cookie_authentication_handler(#httpd{mochi_req=MochiReq}=Req) -> case couch_auth_cache:get_user_creds(User) of nil -> Req; UserProps -> - UserSalt = couch_util:get_value(<<"salt">>, UserProps, <<"">>), + UserSalt = ?getv(<<"salt">>, UserProps, <<"">>), FullSecret = <<Secret/binary, UserSalt/binary>>, ExpectedHash = crypto:sha_mac(FullSecret, User ++ ":" ++ TimeStr), Hash = ?l2b(string:join(HashParts, ":")), @@ -194,7 +194,7 @@ cookie_authentication_handler(#httpd{mochi_req=MochiReq}=Req) -> ?LOG_DEBUG("Successful cookie auth as: ~p", [User]), Req#httpd{user_ctx=#user_ctx{ name=?l2b(User), - roles=couch_util:get_value(<<"roles">>, UserProps, []) + roles=?getv(<<"roles">>, UserProps, []) }, auth={FullSecret, TimeLeft < Timeout*0.9}}; _Else -> Req @@ -215,9 +215,9 @@ cookie_auth_header(#httpd{user_ctx=#user_ctx{name=User}, auth={Secret, true}}, H % or logout handler. % The login and logout handlers need to set the AuthSession cookie % themselves. - CookieHeader = couch_util:get_value("Set-Cookie", Headers, ""), + CookieHeader = ?getv("Set-Cookie", Headers, ""), Cookies = mochiweb_cookies:parse_cookie(CookieHeader), - AuthSession = couch_util:get_value("AuthSession", Cookies), + AuthSession = ?getv("AuthSession", Cookies), if AuthSession == undefined -> TimeStamp = make_cookie_time(), [cookie_auth_cookie(?b2l(User), Secret, TimeStamp)]; @@ -261,16 +261,16 @@ handle_session_req(#httpd{method='POST', mochi_req=MochiReq}=Req) -> _ -> [] end, - UserName = ?l2b(couch_util:get_value("name", Form, "")), - Password = ?l2b(couch_util:get_value("password", Form, "")), + UserName = ?l2b(?getv("name", Form, "")), + Password = ?l2b(?getv("password", Form, "")), ?LOG_DEBUG("Attempt Login: ~s",[UserName]), User = case couch_auth_cache:get_user_creds(UserName) of nil -> []; Result -> Result end, - UserSalt = couch_util:get_value(<<"salt">>, User, <<>>), + UserSalt = ?getv(<<"salt">>, User, <<>>), PasswordHash = hash_password(Password, UserSalt), - ExpectedHash = couch_util:get_value(<<"password_sha">>, User, nil), + ExpectedHash = ?getv(<<"password_sha">>, User, nil), case couch_util:verify(ExpectedHash, PasswordHash) of true -> % setup the session cookie @@ -287,8 +287,8 @@ handle_session_req(#httpd{method='POST', mochi_req=MochiReq}=Req) -> send_json(Req#httpd{req_body=ReqBody}, Code, Headers, {[ {ok, true}, - {name, couch_util:get_value(<<"name">>, User, null)}, - {roles, couch_util:get_value(<<"roles">>, User, [])} + {name, ?getv(<<"name">>, User, null)}, + {roles, ?getv(<<"roles">>, User, [])} ]}); _Else -> % clear the session diff --git a/src/couchdb/couch_httpd_db.erl b/src/couchdb/couch_httpd_db.erl index 93e93892..877ee99d 100644 --- a/src/couchdb/couch_httpd_db.erl +++ b/src/couchdb/couch_httpd_db.erl @@ -277,7 +277,7 @@ db_req(#httpd{method='POST',path_parts=[_,<<"_bulk_docs">>]}=Req, Db) -> couch_stats_collector:increment({httpd, bulk_requests}), couch_httpd:validate_ctype(Req, "application/json"), {JsonProps} = couch_httpd:json_body_obj(Req), - DocsArray = couch_util:get_value(<<"docs">>, JsonProps), + DocsArray = ?getv(<<"docs">>, JsonProps), case couch_httpd:header_value(Req, "X-Couch-Full-Commit") of "true" -> Options = [full_commit]; @@ -286,7 +286,7 @@ db_req(#httpd{method='POST',path_parts=[_,<<"_bulk_docs">>]}=Req, Db) -> _ -> Options = [] end, - case couch_util:get_value(<<"new_edits">>, JsonProps, true) of + case ?getv(<<"new_edits">>, JsonProps, true) of true -> Docs = lists:map( fun({ObjProps} = JsonObj) -> @@ -296,7 +296,7 @@ db_req(#httpd{method='POST',path_parts=[_,<<"_bulk_docs">>]}=Req, Db) -> <<>> -> couch_uuids:new(); Id0 -> Id0 end, - case couch_util:get_value(<<"_rev">>, ObjProps) of + case ?getv(<<"_rev">>, ObjProps) of undefined -> Revs = {0, []}; Rev -> @@ -307,7 +307,7 @@ db_req(#httpd{method='POST',path_parts=[_,<<"_bulk_docs">>]}=Req, Db) -> end, DocsArray), Options2 = - case couch_util:get_value(<<"all_or_nothing">>, JsonProps) of + case ?getv(<<"all_or_nothing">>, JsonProps) of true -> [all_or_nothing|Options]; _ -> Options end, @@ -357,7 +357,7 @@ db_req(#httpd{method='GET',path_parts=[_,<<"_all_docs">>]}=Req, Db) -> db_req(#httpd{method='POST',path_parts=[_,<<"_all_docs">>]}=Req, Db) -> {Fields} = couch_httpd:json_body_obj(Req), - case couch_util:get_value(<<"keys">>, Fields, nil) of + case ?getv(<<"keys">>, Fields, nil) of nil -> ?LOG_DEBUG("POST to _all_docs with no keys member.", []), all_docs_view(Req, Db, nil); @@ -478,7 +478,7 @@ all_docs_view(Req, Db, Keys) -> CurrentEtag = couch_httpd:make_etag(Info), couch_httpd:etag_respond(Req, CurrentEtag, fun() -> - TotalRowCount = couch_util:get_value(doc_count, Info), + TotalRowCount = ?getv(doc_count, Info), StartId = if is_binary(StartKey) -> StartKey; true -> StartDocId end, @@ -612,9 +612,9 @@ db_doc_req(#httpd{method='POST'}=Req, Db, DocId) -> couch_doc:validate_docid(DocId), couch_httpd:validate_ctype(Req, "multipart/form-data"), Form = couch_httpd:parse_form(Req), - case couch_util:get_value("_doc", Form) of + case ?getv("_doc", Form) of undefined -> - Rev = couch_doc:parse_rev(couch_util:get_value("_rev", Form)), + Rev = couch_doc:parse_rev(?getv("_rev", Form)), {ok, [{ok, Doc}]} = couch_db:open_doc_revs(Db, DocId, [Rev], []); Json -> Doc = couch_doc_from_req(Req, DocId, ?JSON_DECODE(Json)) diff --git a/src/couchdb/couch_httpd_oauth.erl b/src/couchdb/couch_httpd_oauth.erl index 05ee10e2..18e95b3c 100644 --- a/src/couchdb/couch_httpd_oauth.erl +++ b/src/couchdb/couch_httpd_oauth.erl @@ -18,7 +18,7 @@ % OAuth auth handler using per-node user db oauth_authentication_handler(#httpd{mochi_req=MochiReq}=Req) -> serve_oauth(Req, fun(URL, Params, Consumer, Signature) -> - AccessToken = couch_util:get_value("oauth_token", Params), + AccessToken = ?getv("oauth_token", Params), case couch_config:get("oauth_token_secrets", AccessToken) of undefined -> couch_httpd:send_error(Req, 400, <<"invalid_token">>, @@ -44,14 +44,14 @@ set_user_ctx(Req, AccessToken) -> case couch_auth_cache:get_user_creds(Name) of nil -> Req; User -> - Roles = couch_util:get_value(<<"roles">>, User, []), + Roles = ?getv(<<"roles">>, User, []), Req#httpd{user_ctx=#user_ctx{name=Name, roles=Roles}} end. % OAuth request_token handle_oauth_req(#httpd{path_parts=[_OAuth, <<"request_token">>], method=Method}=Req) -> serve_oauth(Req, fun(URL, Params, Consumer, Signature) -> - AccessToken = couch_util:get_value("oauth_token", Params), + AccessToken = ?getv("oauth_token", Params), TokenSecret = couch_config:get("oauth_token_secrets", AccessToken), case oauth:verify(Signature, atom_to_list(Method), URL, Params, Consumer, TokenSecret) of true -> @@ -88,7 +88,7 @@ serve_oauth_authorize(#httpd{method=Method}=Req) -> 'GET' -> % Confirm with the User that they want to authenticate the Consumer serve_oauth(Req, fun(URL, Params, Consumer, Signature) -> - AccessToken = couch_util:get_value("oauth_token", Params), + AccessToken = ?getv("oauth_token", Params), TokenSecret = couch_config:get("oauth_token_secrets", AccessToken), case oauth:verify(Signature, "GET", URL, Params, Consumer, TokenSecret) of true -> @@ -100,7 +100,7 @@ serve_oauth_authorize(#httpd{method=Method}=Req) -> 'POST' -> % If the User has confirmed, we direct the User back to the Consumer with a verification code serve_oauth(Req, fun(URL, Params, Consumer, Signature) -> - AccessToken = couch_util:get_value("oauth_token", Params), + AccessToken = ?getv("oauth_token", Params), TokenSecret = couch_config:get("oauth_token_secrets", AccessToken), case oauth:verify(Signature, "POST", URL, Params, Consumer, TokenSecret) of true -> @@ -129,24 +129,24 @@ serve_oauth(#httpd{mochi_req=MochiReq}=Req, Fun, FailSilently) -> end end, HeaderParams = oauth_uri:params_from_header_string(AuthHeader), - %Realm = couch_util:get_value("realm", HeaderParams), + %Realm = ?getv("realm", HeaderParams), Params = proplists:delete("realm", HeaderParams) ++ MochiReq:parse_qs(), ?LOG_DEBUG("OAuth Params: ~p", [Params]), - case couch_util:get_value("oauth_version", Params, "1.0") of + case ?getv("oauth_version", Params, "1.0") of "1.0" -> - case couch_util:get_value("oauth_consumer_key", Params, undefined) of + case ?getv("oauth_consumer_key", Params, undefined) of undefined -> case FailSilently of true -> Req; false -> couch_httpd:send_error(Req, 400, <<"invalid_consumer">>, <<"Invalid consumer.">>) end; ConsumerKey -> - SigMethod = couch_util:get_value("oauth_signature_method", Params), + SigMethod = ?getv("oauth_signature_method", Params), case consumer_lookup(ConsumerKey, SigMethod) of none -> couch_httpd:send_error(Req, 400, <<"invalid_consumer">>, <<"Invalid consumer (key or signature method).">>); Consumer -> - Signature = couch_util:get_value("oauth_signature", Params), + Signature = ?getv("oauth_signature", Params), URL = couch_httpd:absolute_uri(Req, MochiReq:get(raw_path)), Fun(URL, proplists:delete("oauth_signature", Params), Consumer, Signature) diff --git a/src/couchdb/couch_httpd_rewrite.erl b/src/couchdb/couch_httpd_rewrite.erl index 36b90928..276e0601 100644 --- a/src/couchdb/couch_httpd_rewrite.erl +++ b/src/couchdb/couch_httpd_rewrite.erl @@ -132,7 +132,7 @@ handle_rewrite_req(#httpd{ #doc{body={Props}} = DDoc, % get rules from ddoc - case couch_util:get_value(<<"rewrites">>, Props) of + case ?getv(<<"rewrites">>, Props) of undefined -> couch_httpd:send_error(Req, 404, <<"rewrite_error">>, <<"Invalid path.">>); @@ -215,7 +215,7 @@ try_bind_path([Dispatch|Rest], Method, PathParts, QueryList) -> % QueryArgs1 Bindings2 = lists:foldl(fun({K, V}, Acc) -> K1 = to_binding(K), - KV = case couch_util:get_value(K1, QueryArgs1) of + KV = case ?getv(K1, QueryArgs1) of undefined -> [{K1, V}]; _V1 -> [] end, @@ -288,7 +288,7 @@ replace_var(Key, Value, Bindings) -> get_var(VarName, Props, Default) -> VarName1 = to_binding(VarName), - couch_util:get_value(VarName1, Props, Default). + ?getv(VarName1, Props, Default). %% doc: build new patch from bindings. bindings are query args %% (+ dynamic query rewritten if needed) and bindings found in @@ -302,7 +302,7 @@ make_new_path([?MATCH_ALL|_Rest], _Bindings, Remaining, Acc) -> Acc1 = lists:reverse(Acc) ++ Remaining, Acc1; make_new_path([{bind, P}|Rest], Bindings, Remaining, Acc) -> - P2 = case couch_util:get_value({bind, P}, Bindings) of + P2 = case ?getv({bind, P}, Bindings) of undefined -> << "undefined">>; P1 -> P1 end, @@ -370,20 +370,20 @@ normalize_path1([Path|Rest], Acc) -> %% @doc transform json rule in erlang for pattern matching make_rule(Rule) -> - Method = case couch_util:get_value(<<"method">>, Rule) of + Method = case ?getv(<<"method">>, Rule) of undefined -> ?MATCH_ALL; M -> to_binding(M) end, - QueryArgs = case couch_util:get_value(<<"query">>, Rule) of + QueryArgs = case ?getv(<<"query">>, Rule) of undefined -> []; {Args} -> Args end, - FromParts = case couch_util:get_value(<<"from">>, Rule) of + FromParts = case ?getv(<<"from">>, Rule) of undefined -> [?MATCH_ALL]; From -> parse_path(From) end, - ToParts = case couch_util:get_value(<<"to">>, Rule) of + ToParts = case ?getv(<<"to">>, Rule) of undefined -> throw({error, invalid_rewrite_target}); To -> diff --git a/src/couchdb/couch_httpd_show.erl b/src/couchdb/couch_httpd_show.erl index d50ca83a..9c0d2101 100644 --- a/src/couchdb/couch_httpd_show.erl +++ b/src/couchdb/couch_httpd_show.erl @@ -95,7 +95,7 @@ show_etag(#httpd{user_ctx=UserCtx}=Req, Doc, DDoc, More) -> get_fun_key(DDoc, Type, Name) -> #doc{body={Props}} = DDoc, - Lang = couch_util:get_value(<<"language">>, Props, <<"javascript">>), + Lang = ?getv(<<"language">>, Props, <<"javascript">>), Src = couch_util:get_nested_json_value({Props}, [Type, Name]), {Lang, Src}. @@ -168,7 +168,7 @@ handle_view_list_req(#httpd{method='POST', % {Props2} = couch_httpd:json_body(Req), ReqBody = couch_httpd:body(Req), {Props2} = ?JSON_DECODE(ReqBody), - Keys = couch_util:get_value(<<"keys">>, Props2, nil), + Keys = ?getv(<<"keys">>, Props2, nil), handle_view_list(Req#httpd{req_body=ReqBody}, Db, DDoc, ListName, {DesignName, ViewName}, Keys); handle_view_list_req(#httpd{method='POST', @@ -176,7 +176,7 @@ handle_view_list_req(#httpd{method='POST', % {Props2} = couch_httpd:json_body(Req), ReqBody = couch_httpd:body(Req), {Props2} = ?JSON_DECODE(ReqBody), - Keys = couch_util:get_value(<<"keys">>, Props2, nil), + Keys = ?getv(<<"keys">>, Props2, nil), handle_view_list(Req#httpd{req_body=ReqBody}, Db, DDoc, ListName, {ViewDesignName, ViewName}, Keys); handle_view_list_req(#httpd{method='POST'}=Req, _Db, _DDoc) -> @@ -381,7 +381,7 @@ apply_etag({ExternalResponse}, CurrentEtag) -> % 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 % run it to check for a match, which sort of defeats the purpose. - case couch_util:get_value(<<"headers">>, ExternalResponse, nil) of + case ?getv(<<"headers">>, ExternalResponse, nil) of nil -> % no JSON headers % add our Etag and Vary headers to the response diff --git a/src/couchdb/couch_httpd_stats_handlers.erl b/src/couchdb/couch_httpd_stats_handlers.erl index 41aeaed0..0e708db5 100644 --- a/src/couchdb/couch_httpd_stats_handlers.erl +++ b/src/couchdb/couch_httpd_stats_handlers.erl @@ -40,7 +40,7 @@ handle_stats_req(Req) -> send_method_not_allowed(Req, "GET"). range(Req) -> - case couch_util:get_value("range", couch_httpd:qs(Req)) of + case ?getv("range", couch_httpd:qs(Req)) of undefined -> 0; Value -> @@ -48,7 +48,7 @@ range(Req) -> end. flush(Req) -> - case couch_util:get_value("flush", couch_httpd:qs(Req)) of + case ?getv("flush", couch_httpd:qs(Req)) of "true" -> couch_stats_aggregator:collect_sample(); _Else -> diff --git a/src/couchdb/couch_httpd_vhost.erl b/src/couchdb/couch_httpd_vhost.erl index 3dba2919..8aee966d 100644 --- a/src/couchdb/couch_httpd_vhost.erl +++ b/src/couchdb/couch_httpd_vhost.erl @@ -291,7 +291,7 @@ make_target([?MATCH_ALL|_Rest], _Bindings, Remaining, Acc) -> Acc1 = lists:reverse(Acc) ++ Remaining, Acc1; make_target([{bind, P}|Rest], Bindings, Remaining, Acc) -> - P2 = case couch_util:get_value({bind, P}, Bindings) of + P2 = case ?getv({bind, P}, Bindings) of undefined -> "undefined"; P1 -> P1 end, diff --git a/src/couchdb/couch_httpd_view.erl b/src/couchdb/couch_httpd_view.erl index 65598a68..cecbf8c0 100644 --- a/src/couchdb/couch_httpd_view.erl +++ b/src/couchdb/couch_httpd_view.erl @@ -63,7 +63,7 @@ handle_view_req(#httpd{method='POST', path_parts=[_, _, DName, _, ViewName]}=Req, Db, _DDoc) -> couch_httpd:validate_ctype(Req, "application/json"), {Fields} = couch_httpd:json_body_obj(Req), - case couch_util:get_value(<<"keys">>, Fields, nil) of + case ?getv(<<"keys">>, Fields, nil) of nil -> Fmt = "POST to view ~p/~p in database ~p with no keys member.", ?LOG_DEBUG(Fmt, [DName, ViewName, Db]), @@ -82,12 +82,12 @@ handle_temp_view_req(#httpd{method='POST'}=Req, Db) -> ok = couch_db:check_is_admin(Db), couch_stats_collector:increment({httpd, temporary_view_reads}), {Props} = couch_httpd:json_body_obj(Req), - Language = couch_util:get_value(<<"language">>, Props, <<"javascript">>), - {DesignOptions} = couch_util:get_value(<<"options">>, Props, {[]}), - MapSrc = couch_util:get_value(<<"map">>, Props), - Keys = couch_util:get_value(<<"keys">>, Props, nil), + Language = ?getv(<<"language">>, Props, <<"javascript">>), + {DesignOptions} = ?getv(<<"options">>, Props, {[]}), + MapSrc = ?getv(<<"map">>, Props), + Keys = ?getv(<<"keys">>, Props, nil), Reduce = get_reduce_type(Req), - case couch_util:get_value(<<"reduce">>, Props, null) of + case ?getv(<<"reduce">>, Props, null) of null -> QueryArgs = parse_view_params(Req, Keys, map), {ok, View, Group} = couch_view:get_temp_map_view(Db, Language, @@ -623,13 +623,13 @@ view_row_obj(_Db, {{Key, error}, Value}, _IncludeDocs) -> {[{key, Key}, {error, Value}]}; % include docs in the view output view_row_obj(Db, {{Key, DocId}, {Props}}, true) -> - Rev = case couch_util:get_value(<<"_rev">>, Props) of + Rev = case ?getv(<<"_rev">>, Props) of undefined -> nil; Rev0 -> couch_doc:parse_rev(Rev0) end, - IncludeId = couch_util:get_value(<<"_id">>, Props, DocId), + IncludeId = ?getv(<<"_id">>, Props, DocId), view_row_with_doc(Db, {{Key, DocId}, {Props}}, {IncludeId, Rev}); view_row_obj(Db, {{Key, DocId}, Value}, true) -> view_row_with_doc(Db, {{Key, DocId}, Value}, {DocId, nil}); diff --git a/src/couchdb/couch_native_process.erl b/src/couchdb/couch_native_process.erl index b512f712..5a1723ed 100644 --- a/src/couchdb/couch_native_process.erl +++ b/src/couchdb/couch_native_process.erl @@ -25,7 +25,7 @@ % % fun({Doc}) -> % % Below, we emit a single record - the _id as key, null as value -% DocId = couch_util:get_value(Doc, <<"_id">>, null), +% DocId = ?getv(Doc, <<"_id">>, null), % Emit(DocId, null) % end. % @@ -173,7 +173,7 @@ ddoc(State, {DDoc}, [FunPath, Args]) -> % load fun from the FunPath BFun = lists:foldl(fun (Key, {Props}) when is_list(Props) -> - couch_util:get_value(Key, Props, nil); + ?getv(Key, Props, nil); (_Key, Fun) when is_binary(Fun) -> Fun; (_Key, nil) -> diff --git a/src/couchdb/couch_query_servers.erl b/src/couchdb/couch_query_servers.erl index 6fc806f9..341f7204 100644 --- a/src/couchdb/couch_query_servers.erl +++ b/src/couchdb/couch_query_servers.erl @@ -315,7 +315,7 @@ terminate(_Reason, #qserver{pid_procs=PidProcs}) -> ok. handle_call({get_proc, #doc{body={Props}}=DDoc, DDocKey}, From, Server) -> - Lang = couch_util:get_value(<<"language">>, Props, <<"javascript">>), + Lang = ?getv(<<"language">>, Props, <<"javascript">>), case lang_proc(Lang, Server, fun(Procs) -> % find a proc in the set that has the DDoc proc_with_ddoc(DDoc, DDocKey, Procs) @@ -400,7 +400,7 @@ service_waitlist(#qserver{waitlist=Waitlist}=Server) -> % todo get rid of duplication service_waiting({{#doc{body={Props}}=DDoc, DDocKey}, From}, Server) -> - Lang = couch_util:get_value(<<"language">>, Props, <<"javascript">>), + Lang = ?getv(<<"language">>, Props, <<"javascript">>), case lang_proc(Lang, Server, fun(Procs) -> % find a proc in the set that has the DDoc proc_with_ddoc(DDoc, DDocKey, Procs) @@ -517,7 +517,7 @@ get_ddoc_process(#doc{} = DDoc, DDocKey) -> % process knows the ddoc case (catch proc_prompt(Proc, [<<"reset">>, {QueryConfig}])) of true -> - proc_set_timeout(Proc, couch_util:get_value(<<"timeout">>, QueryConfig)), + proc_set_timeout(Proc, ?getv(<<"timeout">>, QueryConfig)), link(Proc#proc.pid), gen_server:call(couch_query_servers, {unlink_proc, Proc#proc.pid}), Proc; @@ -534,7 +534,7 @@ get_os_process(Lang) -> {ok, Proc, {QueryConfig}} -> case (catch proc_prompt(Proc, [<<"reset">>, {QueryConfig}])) of true -> - proc_set_timeout(Proc, couch_util:get_value(<<"timeout">>, QueryConfig)), + proc_set_timeout(Proc, ?getv(<<"timeout">>, QueryConfig)), link(Proc#proc.pid), gen_server:call(couch_query_servers, {unlink_proc, Proc#proc.pid}), Proc; diff --git a/src/couchdb/couch_rep.erl b/src/couchdb/couch_rep.erl index e7c57d06..6dbd3c7c 100644 --- a/src/couchdb/couch_rep.erl +++ b/src/couchdb/couch_rep.erl @@ -67,7 +67,7 @@ replicate(Source, Target) when is_binary(Source), is_binary(Target) -> %% function handling POST to _replicate replicate({Props}=PostBody, UserCtx) -> RepId = make_replication_id(PostBody, UserCtx), - case couch_util:get_value(<<"cancel">>, Props, false) of + case ?getv(<<"cancel">>, Props, false) of true -> end_replication(RepId); false -> @@ -101,7 +101,7 @@ checkpoint(Server) -> gen_server:cast(Server, do_checkpoint). get_result(Server, {BaseId, _Extension}, {Props} = PostBody, UserCtx) -> - case couch_util:get_value(<<"continuous">>, Props, false) of + case ?getv(<<"continuous">>, Props, false) of true -> {ok, {continuous, ?l2b(BaseId)}}; false -> @@ -125,15 +125,15 @@ init(InitArgs) -> do_init([RepId, {PostProps} = RepDoc, UserCtx] = InitArgs) -> process_flag(trap_exit, true), - SourceProps = couch_util:get_value(<<"source">>, PostProps), - TargetProps = couch_util:get_value(<<"target">>, PostProps), + SourceProps = ?getv(<<"source">>, PostProps), + TargetProps = ?getv(<<"target">>, PostProps), - DocIds = couch_util:get_value(<<"doc_ids">>, PostProps, nil), - Continuous = couch_util:get_value(<<"continuous">>, PostProps, false), - CreateTarget = couch_util:get_value(<<"create_target">>, PostProps, false), + DocIds = ?getv(<<"doc_ids">>, PostProps, nil), + Continuous = ?getv(<<"continuous">>, PostProps, false), + CreateTarget = ?getv(<<"create_target">>, PostProps, false), ProxyParams = parse_proxy_params( - couch_util:get_value(<<"proxy">>, PostProps, [])), + ?getv(<<"proxy">>, PostProps, [])), Source = open_db(SourceProps, UserCtx, ProxyParams), Target = open_db(TargetProps, UserCtx, ProxyParams, CreateTarget), @@ -209,8 +209,8 @@ do_init([RepId, {PostProps} = RepDoc, UserCtx] = InitArgs) -> source_log = SourceLog, target_log = TargetLog, rep_starttime = httpd_util:rfc1123_date(), - src_starttime = couch_util:get_value(instance_start_time, SourceInfo), - tgt_starttime = couch_util:get_value(instance_start_time, TargetInfo), + src_starttime = ?getv(instance_start_time, SourceInfo), + tgt_starttime = ?getv(instance_start_time, TargetInfo), doc_ids = DocIds, rep_doc = RepDoc }, @@ -329,17 +329,17 @@ start_replication_server(Replicator) -> compare_replication_logs(SrcDoc, TgtDoc) -> #doc{body={RepRecProps}} = SrcDoc, #doc{body={RepRecPropsTgt}} = TgtDoc, - case couch_util:get_value(<<"session_id">>, RepRecProps) == - couch_util:get_value(<<"session_id">>, RepRecPropsTgt) of + case ?getv(<<"session_id">>, RepRecProps) == + ?getv(<<"session_id">>, RepRecPropsTgt) of true -> % if the records have the same session id, % then we have a valid replication history - OldSeqNum = couch_util:get_value(<<"source_last_seq">>, RepRecProps, 0), - OldHistory = couch_util:get_value(<<"history">>, RepRecProps, []), + OldSeqNum = ?getv(<<"source_last_seq">>, RepRecProps, 0), + OldHistory = ?getv(<<"history">>, RepRecProps, []), {OldSeqNum, OldHistory}; false -> - SourceHistory = couch_util:get_value(<<"history">>, RepRecProps, []), - TargetHistory = couch_util:get_value(<<"history">>, RepRecPropsTgt, []), + SourceHistory = ?getv(<<"history">>, RepRecProps, []), + TargetHistory = ?getv(<<"history">>, RepRecPropsTgt, []), ?LOG_INFO("Replication records differ. " "Scanning histories to find a common ancestor.", []), ?LOG_DEBUG("Record on source:~p~nRecord on target:~p~n", @@ -351,18 +351,18 @@ compare_rep_history(S, T) when S =:= [] orelse T =:= [] -> ?LOG_INFO("no common ancestry -- performing full replication", []), {0, []}; compare_rep_history([{S}|SourceRest], [{T}|TargetRest]=Target) -> - SourceId = couch_util:get_value(<<"session_id">>, S), + SourceId = ?getv(<<"session_id">>, S), case has_session_id(SourceId, Target) of true -> - RecordSeqNum = couch_util:get_value(<<"recorded_seq">>, S, 0), + RecordSeqNum = ?getv(<<"recorded_seq">>, S, 0), ?LOG_INFO("found a common replication record with source_seq ~p", [RecordSeqNum]), {RecordSeqNum, SourceRest}; false -> - TargetId = couch_util:get_value(<<"session_id">>, T), + TargetId = ?getv(<<"session_id">>, T), case has_session_id(TargetId, SourceRest) of true -> - RecordSeqNum = couch_util:get_value(<<"recorded_seq">>, T, 0), + RecordSeqNum = ?getv(<<"recorded_seq">>, T, 0), ?LOG_INFO("found a common replication record with source_seq ~p", [RecordSeqNum]), {RecordSeqNum, TargetRest}; @@ -454,7 +454,7 @@ terminate_cleanup(#state{source=Source, target=Target, stats=Stats}) -> has_session_id(_SessionId, []) -> false; has_session_id(SessionId, [{Props} | Rest]) -> - case couch_util:get_value(<<"session_id">>, Props, nil) of + case ?getv(<<"session_id">>, Props, nil) of SessionId -> true; _Else -> @@ -464,7 +464,7 @@ has_session_id(SessionId, [{Props} | Rest]) -> maybe_append_options(Options, {Props}) -> lists:foldl(fun(Option, Acc) -> Acc ++ - case couch_util:get_value(Option, Props, false) of + case ?getv(Option, Props, false) of true -> "+" ++ ?b2l(Option); false -> @@ -484,27 +484,27 @@ make_replication_id(RepProps, UserCtx) -> make_replication_id({Props}, UserCtx, 2) -> {ok, HostName} = inet:gethostname(), Port = mochiweb_socket_server:get(couch_httpd, port), - Src = get_rep_endpoint(UserCtx, couch_util:get_value(<<"source">>, Props)), - Tgt = get_rep_endpoint(UserCtx, couch_util:get_value(<<"target">>, Props)), + Src = get_rep_endpoint(UserCtx, ?getv(<<"source">>, Props)), + Tgt = get_rep_endpoint(UserCtx, ?getv(<<"target">>, Props)), maybe_append_filters({Props}, [HostName, Port, Src, Tgt]); make_replication_id({Props}, UserCtx, 1) -> {ok, HostName} = inet:gethostname(), - Src = get_rep_endpoint(UserCtx, couch_util:get_value(<<"source">>, Props)), - Tgt = get_rep_endpoint(UserCtx, couch_util:get_value(<<"target">>, Props)), + Src = get_rep_endpoint(UserCtx, ?getv(<<"source">>, Props)), + Tgt = get_rep_endpoint(UserCtx, ?getv(<<"target">>, Props)), maybe_append_filters({Props}, [HostName, Src, Tgt]). maybe_append_filters({Props}, Base) -> Base2 = Base ++ - case couch_util:get_value(<<"filter">>, Props) of + case ?getv(<<"filter">>, Props) of undefined -> - case couch_util:get_value(<<"doc_ids">>, Props) of + case ?getv(<<"doc_ids">>, Props) of undefined -> []; DocIds -> [DocIds] end; Filter -> - [Filter, couch_util:get_value(<<"query_params">>, Props, {[]})] + [Filter, ?getv(<<"query_params">>, Props, {[]})] end, couch_util:to_hex(couch_util:md5(term_to_binary(Base2))). @@ -512,10 +512,10 @@ maybe_add_trailing_slash(Url) -> re:replace(Url, "[^/]$", "&/", [{return, list}]). get_rep_endpoint(_UserCtx, {Props}) -> - Url = maybe_add_trailing_slash(couch_util:get_value(<<"url">>, Props)), - {BinHeaders} = couch_util:get_value(<<"headers">>, Props, {[]}), - {Auth} = couch_util:get_value(<<"auth">>, Props, {[]}), - case couch_util:get_value(<<"oauth">>, Auth) of + Url = maybe_add_trailing_slash(?getv(<<"url">>, Props)), + {BinHeaders} = ?getv(<<"headers">>, Props, {[]}), + {Auth} = ?getv(<<"auth">>, Props, {[]}), + case ?getv(<<"oauth">>, Auth) of undefined -> {remote, Url, [{?b2l(K),?b2l(V)} || {K,V} <- BinHeaders]}; {OAuth} -> @@ -580,9 +580,9 @@ open_db(Props, UserCtx, ProxyParams) -> open_db(Props, UserCtx, ProxyParams, false). open_db({Props}, _UserCtx, ProxyParams, CreateTarget) -> - Url = maybe_add_trailing_slash(couch_util:get_value(<<"url">>, Props)), - {AuthProps} = couch_util:get_value(<<"auth">>, Props, {[]}), - {BinHeaders} = couch_util:get_value(<<"headers">>, Props, {[]}), + Url = maybe_add_trailing_slash(?getv(<<"url">>, Props)), + {AuthProps} = ?getv(<<"auth">>, Props, {[]}), + {BinHeaders} = ?getv(<<"headers">>, Props, {[]}), Headers = [{?b2l(K),?b2l(V)} || {K,V} <- BinHeaders], DefaultHeaders = (#http_db{})#http_db.headers, Db1 = #http_db{ @@ -722,8 +722,8 @@ ensure_full_commit(#http_db{headers = Headers} = Target) -> headers = couch_util:proplist_apply_field({"Content-Type", "application/json"}, Headers) }, {ResultProps} = couch_rep_httpc:request(Req), - true = couch_util:get_value(<<"ok">>, ResultProps), - couch_util:get_value(<<"instance_start_time">>, ResultProps); + true = ?getv(<<"ok">>, ResultProps), + ?getv(<<"instance_start_time">>, ResultProps); ensure_full_commit(Target) -> {ok, NewDb} = couch_db:open_int(Target#db.name, []), UpdateSeq = couch_db:get_update_seq(Target), @@ -748,9 +748,9 @@ ensure_full_commit(#http_db{headers = Headers} = Source, RequiredSeq) -> headers = couch_util:proplist_apply_field({"Content-Type", "application/json"}, Headers) }, {ResultProps} = couch_rep_httpc:request(Req), - case couch_util:get_value(<<"ok">>, ResultProps) of + case ?getv(<<"ok">>, ResultProps) of true -> - couch_util:get_value(<<"instance_start_time">>, ResultProps); + ?getv(<<"instance_start_time">>, ResultProps); undefined -> nil end; ensure_full_commit(Source, RequiredSeq) -> {ok, NewDb} = couch_db:open_int(Source#db.name, []), @@ -775,7 +775,7 @@ update_local_doc(#http_db{} = Db, Doc) -> headers = [{"x-couch-full-commit", "false"} | Db#http_db.headers] }, {ResponseMembers} = couch_rep_httpc:request(Req), - Rev = couch_util:get_value(<<"rev">>, ResponseMembers), + Rev = ?getv(<<"rev">>, ResponseMembers), couch_doc:parse_rev(Rev); update_local_doc(Db, Doc) -> {ok, Result} = couch_db:update_doc(Db, Doc, [delay_commit]), @@ -805,7 +805,7 @@ parse_proxy_params(ProxyUrl) -> end. update_rep_doc({Props} = _RepDoc, KVs) -> - case couch_util:get_value(<<"_id">>, Props) of + case ?getv(<<"_id">>, Props) of undefined -> % replication triggered by POSTing to _replicate/ ok; @@ -838,7 +838,7 @@ update_rep_doc(RepDb, #doc{body = {RepDocBody}} = RepDoc, KVs) -> ). maybe_set_triggered({RepProps} = RepDoc, RepId) -> - case couch_util:get_value(<<"state">>, RepProps) of + case ?getv(<<"state">>, RepProps) of <<"triggered">> -> ok; _ -> diff --git a/src/couchdb/couch_rep_changes_feed.erl b/src/couchdb/couch_rep_changes_feed.erl index 7f7d3a38..773a2ced 100644 --- a/src/couchdb/couch_rep_changes_feed.erl +++ b/src/couchdb/couch_rep_changes_feed.erl @@ -48,7 +48,7 @@ stop(Server) -> init([Parent, #http_db{}=Source, Since, PostProps]) -> process_flag(trap_exit, true), - Feed = case couch_util:get_value(<<"continuous">>, PostProps, false) of + Feed = case ?getv(<<"continuous">>, PostProps, false) of false -> normal; true -> @@ -60,11 +60,11 @@ init([Parent, #http_db{}=Source, Since, PostProps]) -> {"since", Since}, {"feed", Feed} ], - QS = case couch_util:get_value(<<"filter">>, PostProps) of + QS = case ?getv(<<"filter">>, PostProps) of undefined -> BaseQS; FilterName -> - {Params} = couch_util:get_value(<<"query_params">>, PostProps, {[]}), + {Params} = ?getv(<<"query_params">>, PostProps, {[]}), lists:foldr( fun({K, V}, QSAcc) -> Ks = couch_util:to_list(K), @@ -126,8 +126,8 @@ init([_Parent, Source, Since, PostProps] = InitArgs) -> ChangesArgs = #changes_args{ style = all_docs, since = Since, - filter = ?b2l(couch_util:get_value(<<"filter">>, PostProps, <<>>)), - feed = case couch_util:get_value(<<"continuous">>, PostProps, false) of + filter = ?b2l(?getv(<<"filter">>, PostProps, <<>>)), + feed = case ?getv(<<"continuous">>, PostProps, false) of true -> "continuous"; false -> @@ -150,11 +150,11 @@ init([_Parent, Source, Since, PostProps] = InitArgs) -> {ok, #state{changes_loop=ChangesPid, init_args=InitArgs}}. filter_json_req(Db, PostProps) -> - case couch_util:get_value(<<"filter">>, PostProps) of + case ?getv(<<"filter">>, PostProps) of undefined -> {[]}; FilterName -> - {Query} = couch_util:get_value(<<"query_params">>, PostProps, {[]}), + {Query} = ?getv(<<"query_params">>, PostProps, {[]}), {ok, Info} = couch_db:get_db_info(Db), % simulate a request to db_name/_changes {[ @@ -307,7 +307,7 @@ handle_messages([Chunk|Rest], State) -> #state{reply_to=nil} -> State#state{ count = Count+1, - last_seq = couch_util:get_value(<<"seq">>, Props), + last_seq = ?getv(<<"seq">>, Props), partial_chunk = <<>>, rows=queue:in(Row,Rows) }; @@ -354,16 +354,16 @@ by_seq_loop(Server, Source, StartSeq) -> qs = [{limit, 1000}, {startkey, StartSeq}] }, {Results} = couch_rep_httpc:request(Req), - Rows = couch_util:get_value(<<"rows">>, Results), + Rows = ?getv(<<"rows">>, Results), if Rows =:= [] -> exit(normal); true -> ok end, EndSeq = lists:foldl(fun({RowInfoList}, _) -> - Id = couch_util:get_value(<<"id">>, RowInfoList), - Seq = couch_util:get_value(<<"key">>, RowInfoList), - {RowProps} = couch_util:get_value(<<"value">>, RowInfoList), + Id = ?getv(<<"id">>, RowInfoList), + Seq = ?getv(<<"key">>, RowInfoList), + {RowProps} = ?getv(<<"value">>, RowInfoList), RawRevs = [ - couch_util:get_value(<<"rev">>, RowProps), - couch_util:get_value(<<"conflicts">>, RowProps, []), - couch_util:get_value(<<"deleted_conflicts">>, RowProps, []) + ?getv(<<"rev">>, RowProps), + ?getv(<<"conflicts">>, RowProps, []), + ?getv(<<"deleted_conflicts">>, RowProps, []) ], ParsedRevs = couch_doc:parse_revs(lists:flatten(RawRevs)), Change = {[ diff --git a/src/couchdb/couch_rep_db_listener.erl b/src/couchdb/couch_rep_db_listener.erl index 926b2987..d2a2978e 100644 --- a/src/couchdb/couch_rep_db_listener.erl +++ b/src/couchdb/couch_rep_db_listener.erl @@ -142,7 +142,7 @@ consume_changes(ChangesQueue) -> has_valid_rep_id({Change}) -> - has_valid_rep_id(couch_util:get_value(<<"id">>, Change)); + has_valid_rep_id(?getv(<<"id">>, Change)); has_valid_rep_id(<<?DESIGN_DOC_PREFIX, _Rest/binary>>) -> false; has_valid_rep_id(_Else) -> @@ -150,12 +150,12 @@ has_valid_rep_id(_Else) -> process_change({Change}) -> - {RepProps} = JsonRepDoc = couch_util:get_value(doc, Change), - case couch_util:get_value(<<"deleted">>, Change, false) of + {RepProps} = JsonRepDoc = ?getv(doc, Change), + case ?getv(<<"deleted">>, Change, false) of true -> maybe_stop_replication(JsonRepDoc); false -> - case couch_util:get_value(<<"state">>, RepProps) of + case ?getv(<<"state">>, RepProps) of <<"completed">> -> maybe_stop_replication(JsonRepDoc); <<"error">> -> @@ -164,7 +164,7 @@ process_change({Change}) -> <<"triggered">> -> maybe_start_replication(JsonRepDoc); undefined -> - case couch_util:get_value(<<"replication_id">>, RepProps) of + case ?getv(<<"replication_id">>, RepProps) of undefined -> maybe_start_replication(JsonRepDoc); _ -> @@ -176,13 +176,13 @@ process_change({Change}) -> rep_user_ctx({RepDoc}) -> - case couch_util:get_value(<<"user_ctx">>, RepDoc) of + case ?getv(<<"user_ctx">>, RepDoc) of undefined -> #user_ctx{roles = [<<"_admin">>]}; {UserCtx} -> #user_ctx{ - name = couch_util:get_value(<<"name">>, UserCtx, null), - roles = couch_util:get_value(<<"roles">>, UserCtx, []) + name = ?getv(<<"name">>, UserCtx, null), + roles = ?getv(<<"roles">>, UserCtx, []) } end. @@ -190,7 +190,7 @@ rep_user_ctx({RepDoc}) -> maybe_start_replication({RepProps} = JsonRepDoc) -> UserCtx = rep_user_ctx(JsonRepDoc), RepId = couch_rep:make_replication_id(JsonRepDoc, UserCtx), - DocId = couch_util:get_value(<<"_id">>, RepProps), + DocId = ?getv(<<"_id">>, RepProps), case ets:lookup(?REP_ID_TO_DOC_ID_MAP, RepId) of [] -> true = ets:insert(?REP_ID_TO_DOC_ID_MAP, {RepId, DocId}), @@ -222,7 +222,7 @@ start_replication(RepDoc, RepId, UserCtx) -> maybe_stop_replication({RepProps}) -> - DocId = couch_util:get_value(<<"_id">>, RepProps), + DocId = ?getv(<<"_id">>, RepProps), case ets:lookup(?DOC_TO_REP_ID_MAP, DocId) of [{DocId, RepId}] -> couch_rep:end_replication(RepId), diff --git a/src/couchdb/couch_rep_httpc.erl b/src/couchdb/couch_rep_httpc.erl index 06d4748a..0b5b5328 100644 --- a/src/couchdb/couch_rep_httpc.erl +++ b/src/couchdb/couch_rep_httpc.erl @@ -34,7 +34,7 @@ do_request(Req) -> qs = QS } = Req, Url = full_url(Req), - Headers = case couch_util:get_value(<<"oauth">>, Auth) of + Headers = case ?getv(<<"oauth">>, Auth) of undefined -> Headers0; {OAuthProps} -> @@ -76,7 +76,7 @@ db_exists(Req, CanonicalUrl, CreateDB) -> url = Url } = Req, HeadersFun = fun(Method) -> - case couch_util:get_value(<<"oauth">>, Auth) of + case ?getv(<<"oauth">>, Auth) of undefined -> Headers0; {OAuthProps} -> @@ -190,7 +190,7 @@ process_response({error, Reason}, Req) -> redirected_request(Req, RedirectUrl) -> {Base, QStr, _} = mochiweb_util:urlsplit_path(RedirectUrl), QS = mochiweb_util:parse_qs(QStr), - Hdrs = case couch_util:get_value(<<"oauth">>, Req#http_db.auth) of + Hdrs = case ?getv(<<"oauth">>, Req#http_db.auth) of undefined -> Req#http_db.headers; _Else -> @@ -220,11 +220,11 @@ oauth_header(Url, QS, Action, Props) -> % erlang-oauth doesn't like iolists QSL = [{couch_util:to_list(K), ?b2l(?l2b(couch_util:to_list(V)))} || {K,V} <- QS], - ConsumerKey = ?b2l(couch_util:get_value(<<"consumer_key">>, Props)), - Token = ?b2l(couch_util:get_value(<<"token">>, Props)), - TokenSecret = ?b2l(couch_util:get_value(<<"token_secret">>, Props)), - ConsumerSecret = ?b2l(couch_util:get_value(<<"consumer_secret">>, Props)), - SignatureMethodStr = ?b2l(couch_util:get_value(<<"signature_method">>, Props, <<"HMAC-SHA1">>)), + ConsumerKey = ?b2l(?getv(<<"consumer_key">>, Props)), + Token = ?b2l(?getv(<<"token">>, Props)), + TokenSecret = ?b2l(?getv(<<"token_secret">>, Props)), + ConsumerSecret = ?b2l(?getv(<<"consumer_secret">>, Props)), + SignatureMethodStr = ?b2l(?getv(<<"signature_method">>, Props, <<"HMAC-SHA1">>)), SignatureMethodAtom = case SignatureMethodStr of "PLAINTEXT" -> plaintext; diff --git a/src/couchdb/couch_rep_missing_revs.erl b/src/couchdb/couch_rep_missing_revs.erl index 1eff6774..6e46c1ce 100644 --- a/src/couchdb/couch_rep_missing_revs.erl +++ b/src/couchdb/couch_rep_missing_revs.erl @@ -145,44 +145,44 @@ changes_loop(OurServer, SourceChangesServer, Target) -> get_missing_revs(#http_db{}=Target, Changes) -> Transform = fun({Props}) -> - C = couch_util:get_value(<<"changes">>, Props), - Id = couch_util:get_value(<<"id">>, Props), + C = ?getv(<<"changes">>, Props), + Id = ?getv(<<"id">>, Props), {Id, [R || {[{<<"rev">>, R}]} <- C]} end, IdRevsList = [Transform(Change) || Change <- Changes], SeqDict = changes_dictionary(Changes), {LastProps} = lists:last(Changes), - HighSeq = couch_util:get_value(<<"seq">>, LastProps), + HighSeq = ?getv(<<"seq">>, LastProps), Request = Target#http_db{ resource = "_missing_revs", method = post, body = {IdRevsList} }, {Resp} = couch_rep_httpc:request(Request), - case couch_util:get_value(<<"missing_revs">>, Resp) of + case ?getv(<<"missing_revs">>, Resp) of {MissingRevs} -> X = [{Id, dict:fetch(Id, SeqDict), couch_doc:parse_revs(RevStrs)} || {Id,RevStrs} <- MissingRevs], {HighSeq, X}; _ -> - exit({target_error, couch_util:get_value(<<"error">>, Resp)}) + exit({target_error, ?getv(<<"error">>, Resp)}) end; get_missing_revs(Target, Changes) -> Transform = fun({Props}) -> - C = couch_util:get_value(<<"changes">>, Props), - Id = couch_util:get_value(<<"id">>, Props), + C = ?getv(<<"changes">>, Props), + Id = ?getv(<<"id">>, Props), {Id, [couch_doc:parse_rev(R) || {[{<<"rev">>, R}]} <- C]} end, IdRevsList = [Transform(Change) || Change <- Changes], SeqDict = changes_dictionary(Changes), {LastProps} = lists:last(Changes), - HighSeq = couch_util:get_value(<<"seq">>, LastProps), + HighSeq = ?getv(<<"seq">>, LastProps), {ok, Results} = couch_db:get_missing_revs(Target, IdRevsList), {HighSeq, [{Id, dict:fetch(Id, SeqDict), Revs} || {Id, Revs, _} <- Results]}. changes_dictionary(ChangeList) -> - KVs = [{couch_util:get_value(<<"id">>,C), couch_util:get_value(<<"seq">>,C)} + KVs = [{?getv(<<"id">>,C), ?getv(<<"seq">>,C)} || {C} <- ChangeList], dict:from_list(KVs). diff --git a/src/couchdb/couch_rep_reader.erl b/src/couchdb/couch_rep_reader.erl index 4f81c8e4..1e496acf 100644 --- a/src/couchdb/couch_rep_reader.erl +++ b/src/couchdb/couch_rep_reader.erl @@ -253,7 +253,7 @@ open_doc_revs(#http_db{url = Url} = DbS, DocId, Revs) -> }, [Doc1 | Acc]; ({ErrorProps}, Acc) -> - Err = couch_util:get_value(<<"error">>, ErrorProps, + Err = ?getv(<<"error">>, ErrorProps, ?JSON_ENCODE({ErrorProps})), ?LOG_ERROR("Replicator: error accessing doc ~s at ~s, reason: ~s", [DocId, couch_util:url_strip_password(Url), Err]), @@ -268,14 +268,14 @@ open_doc(#http_db{url = Url} = DbS, DocId) -> qs=[{att_encoding_info, true}] }, {Props} = Json = couch_rep_httpc:request(Req), - case couch_util:get_value(<<"_id">>, Props) of + case ?getv(<<"_id">>, Props) of Id when is_binary(Id) -> #doc{id=Id, revs=Rev, atts=Atts} = Doc = couch_doc:from_json_obj(Json), [Doc#doc{ atts=[couch_rep_att:convert_stub(A, {DbS,Id,Rev}) || A <- Atts] }]; undefined -> - Err = couch_util:get_value(<<"error">>, Props, ?JSON_ENCODE(Json)), + Err = ?getv(<<"error">>, Props, ?JSON_ENCODE(Json)), ?LOG_ERROR("Replicator: error accessing doc ~s at ~s, reason: ~s", [DocId, couch_util:url_strip_password(Url), Err]), [] diff --git a/src/couchdb/couch_rep_writer.erl b/src/couchdb/couch_rep_writer.erl index f7bc9a72..47de670a 100644 --- a/src/couchdb/couch_rep_writer.erl +++ b/src/couchdb/couch_rep_writer.erl @@ -80,7 +80,7 @@ write_bulk_docs(#http_db{headers = Headers} = Db, Docs) -> }, ErrorsJson = case couch_rep_httpc:request(Request) of {FailProps} -> - exit({target_error, couch_util:get_value(<<"error">>, FailProps)}); + exit({target_error, ?getv(<<"error">>, FailProps)}); List when is_list(List) -> List end, @@ -164,8 +164,8 @@ streamer_fun(Boundary, JsonBytes, Atts) -> end. write_docs_1({Props}) -> - Id = couch_util:get_value(<<"id">>, Props), - Rev = couch_doc:parse_rev(couch_util:get_value(<<"rev">>, Props)), - ErrId = couch_util:to_existing_atom(couch_util:get_value(<<"error">>, Props)), - Reason = couch_util:get_value(<<"reason">>, Props), + Id = ?getv(<<"id">>, Props), + Rev = couch_doc:parse_rev(?getv(<<"rev">>, Props)), + ErrId = couch_util:to_existing_atom(?getv(<<"error">>, Props)), + Reason = ?getv(<<"reason">>, Props), {{Id, Rev}, {ErrId, Reason}}. diff --git a/src/couchdb/couch_server.erl b/src/couchdb/couch_server.erl index 2d96d5f3..5f536d3d 100644 --- a/src/couchdb/couch_server.erl +++ b/src/couchdb/couch_server.erl @@ -53,7 +53,7 @@ sup_start_link() -> open(DbName, Options) -> case gen_server:call(couch_server, {open, DbName, Options}, infinity) of {ok, Db} -> - Ctx = couch_util:get_value(user_ctx, Options, #user_ctx{}), + Ctx = ?getv(user_ctx, Options, #user_ctx{}), {ok, Db#db{user_ctx=Ctx}}; Error -> Error @@ -62,7 +62,7 @@ open(DbName, Options) -> create(DbName, Options) -> case gen_server:call(couch_server, {create, DbName, Options}, infinity) of {ok, Db} -> - Ctx = couch_util:get_value(user_ctx, Options, #user_ctx{}), + Ctx = ?getv(user_ctx, Options, #user_ctx{}), {ok, Db#db{user_ctx=Ctx}}; Error -> Error diff --git a/src/couchdb/couch_stream.erl b/src/couchdb/couch_stream.erl index 60af1c2b..4ba1fa93 100644 --- a/src/couchdb/couch_stream.erl +++ b/src/couchdb/couch_stream.erl @@ -173,7 +173,7 @@ foldl_decode(DecFun, Fd, [Pos|Rest], Md5, Md5Acc, Fun, Acc) -> foldl_decode(DecFun, Fd, Rest, Md5, Md5Acc2, Fun, Fun(Bin, Acc)). gzip_init(Options) -> - case couch_util:get_value(compression_level, Options, 0) of + case ?getv(compression_level, Options, 0) of Lvl when Lvl >= 1 andalso Lvl =< 9 -> Z = zlib:open(), % 15 = ?MAX_WBITS (defined in the zlib module) diff --git a/src/couchdb/couch_view.erl b/src/couchdb/couch_view.erl index 35bc80b6..19b6ee7f 100644 --- a/src/couchdb/couch_view.erl +++ b/src/couchdb/couch_view.erl @@ -91,7 +91,7 @@ cleanup_index_files(Db) -> % make unique list of group sigs Sigs = lists:map(fun(#doc{id = GroupId}) -> {ok, Info} = get_group_info(Db, GroupId), - ?b2l(couch_util:get_value(signature, Info)) + ?b2l(?getv(signature, Info)) end, [DD||DD <- DesignDocs, DD#doc.deleted == false]), FileList = list_index_files(Db), diff --git a/src/couchdb/couch_view_group.erl b/src/couchdb/couch_view_group.erl index f01befdf..f3d48d1d 100644 --- a/src/couchdb/couch_view_group.erl +++ b/src/couchdb/couch_view_group.erl @@ -502,16 +502,16 @@ get_group_info(State) -> % maybe move to another module design_doc_to_view_group(#doc{id=Id,body={Fields}}) -> - Language = couch_util:get_value(<<"language">>, Fields, <<"javascript">>), - {DesignOptions} = couch_util:get_value(<<"options">>, Fields, {[]}), - {RawViews} = couch_util:get_value(<<"views">>, Fields, {[]}), + Language = ?getv(<<"language">>, Fields, <<"javascript">>), + {DesignOptions} = ?getv(<<"options">>, Fields, {[]}), + {RawViews} = ?getv(<<"views">>, Fields, {[]}), % add the views to a dictionary object, with the map source as the key DictBySrc = lists:foldl( fun({Name, {MRFuns}}, DictBySrcAcc) -> - MapSrc = couch_util:get_value(<<"map">>, MRFuns), - RedSrc = couch_util:get_value(<<"reduce">>, MRFuns, null), - {ViewOptions} = couch_util:get_value(<<"options">>, MRFuns, {[]}), + MapSrc = ?getv(<<"map">>, MRFuns), + RedSrc = ?getv(<<"reduce">>, MRFuns, null), + {ViewOptions} = ?getv(<<"options">>, MRFuns, {[]}), View = case dict:find({MapSrc, ViewOptions}, DictBySrcAcc) of {ok, View0} -> View0; @@ -574,7 +574,7 @@ init_group(Db, Fd, #group{def_lang=Lang,views=Views}= {Count, Reduced} end, - case couch_util:get_value(<<"collation">>, Options, <<"default">>) of + case ?getv(<<"collation">>, Options, <<"default">>) of <<"default">> -> Less = fun couch_view:less_json_ids/2; <<"raw">> -> diff --git a/src/couchdb/couch_view_updater.erl b/src/couchdb/couch_view_updater.erl index 70a60950..d503219c 100644 --- a/src/couchdb/couch_view_updater.erl +++ b/src/couchdb/couch_view_updater.erl @@ -51,9 +51,9 @@ update(Owner, Group) -> % update status every half second couch_task_status:set_update_frequency(500), #group{ design_options = DesignOptions } = Group, - IncludeDesign = couch_util:get_value(<<"include_design">>, + IncludeDesign = ?getv(<<"include_design">>, DesignOptions, false), - LocalSeq = couch_util:get_value(<<"local_seq">>, DesignOptions, false), + LocalSeq = ?getv(<<"local_seq">>, DesignOptions, false), DocOpts = case LocalSeq of true -> [conflicts, deleted_conflicts, local_seq]; diff --git a/src/couchdb/couch_work_queue.erl b/src/couchdb/couch_work_queue.erl index 13ec7335..2ec748f5 100644 --- a/src/couchdb/couch_work_queue.erl +++ b/src/couchdb/couch_work_queue.erl @@ -20,6 +20,8 @@ -export([init/1, terminate/2]). -export([handle_call/3, handle_cast/2, code_change/3, handle_info/2]). +-include("couch_db.hrl"). + -record(q, { queue = queue:new(), blocked = [], @@ -59,9 +61,9 @@ close(Wq) -> init(Options) -> Q = #q{ - max_size = couch_util:get_value(max_size, Options), - max_items = couch_util:get_value(max_items, Options), - multi_workers = couch_util:get_value(multi_workers, Options, false) + max_size = ?getv(max_size, Options), + max_items = ?getv(max_items, Options), + multi_workers = ?getv(multi_workers, Options, false) }, {ok, Q}. |