anchor.diff:  
   -export([content_types_accepted/0, content_types_provided/0,
   		get_client/0, get_client/1, post_client/1,
  -		patch_client/3, delete_client/1]).
  +		patch_client/4, delete_client/1]).
   
   -include_lib("radius/include/radius.hrl").
   -include("ocs.hrl").
  
positive.code: 		ContentTypes :: list().
  %% @doc Provides list of resource representations accepted.
  content_types_accepted() ->
  	["application/json"].
  
  -spec content_types_provided() -> ContentTypes
  	when
  
negative.code: 			{error, 400}
  	end.
  
  -spec patch_client(Ip, Etag, ContentType, ReqBody) -> Result
  	when
  		Ip :: string(),
  		Etag :: undefined | string(),
  		ContentType :: string(),
  		ReqBody :: list(),
  		Result :: {ok, Headers :: [tuple()], Body :: iolist()}
  			| {error, ErrorCode :: integer()} .
  %% @doc	Respond to `PATCH /ocs/v1/client/{id}' request and
  %% Updates a existing `client''s password or attributes.
  patch_client(Ip, undefined, CType, ReqBody) ->
  	patch_client0(Ip, undefined, CType, ReqBody);
  patch_client(Ip, Etag, CType, ReqBody) ->
  	try
  		Etag1 = etag(Etag), 
  		patch_client0(Ip, Etag1, CType, ReqBody)
  	catch
  		_:_ ->
  			{error, 400}
  	end.
  %% @hidden
  patch_client0(Ip, Etag, CType, ReqBody) ->
  	case inet:parse_address(Ip) of
  		{ok, Address} ->
  			patch_client1(Address, Etag, CType, ReqBody);
  		{error, einval} ->
  			{error, 400}
  	end.
  %% @hidden
  patch_client1(Id, Etag, CType, ReqBody) ->
  	case ocs:find_client(Id) of
  		{ok, #client{port = Port, protocol = Protocol, secret = Secret,
  				last_modified = CurrentEtag}}
  				when CurrentEtag == Etag; Etag == undefined ->
  			patch_client2(Id, Etag, CType, ReqBody, Port, Protocol, Secret);
  		{ok, #client{last_modified = _NonMatchingEtag}} ->
  			{error, 412};
  		{error, _Reason} ->
  			{error, 404}
  	end.
  %% @hidden
  patch_client2(Id, Etag, "application/json", ReqBody, CurrPort,
  		CurrProtocol, CurrSecret) ->
  	try
  		{struct, Object} = mochijson:decode(ReqBody),
  		case Object of
  			[{"secret", NewPassword}] ->
  				Protocol_Atom = string:to_upper(atom_to_list(CurrProtocol)),
  				patch_client3(Id, CurrPort, Protocol_Atom, NewPassword, Etag);
  			[{"port", NewPort},{"protocol", RADIUS}]
  					when RADIUS =:= "radius"; RADIUS =:= "RADIUS" ->
  				patch_client4(Id, NewPort, radius, CurrSecret, Etag);
  			[{"port", NewPort},{"protocol", DIAMETER}]
  					when DIAMETER =:= "diameter"; DIAMETER =:= "DIAMETER" ->
  				patch_client4(Id, NewPort, diameter, CurrSecret, Etag)
  		end
  	catch
  		throw : _ ->
  			{error, 400}
  	end;
  patch_client2(Id, Etag, "application/json-patch+json", ReqBody, CurrPort,
  		CurrProtocol, CurrSecret) ->
  	try
  		{array, [Operation]}= mochijson:decode(ReqBody),
  		{struct, [{"op", "replace"}, {"path", Path}, {"value", V}]} = Operation,
  		case Path of
  			"/secret" ->
  				case V of
  					V when is_list(V) ->
  						Protocol_Atom = string:to_upper(atom_to_list(CurrProtocol)),
  						patch_client3(Id, CurrPort, Protocol_Atom, V, Etag);
  					_ ->
  						{error, 422}
  				end;
  			_ ->
  				{error, 409}
  		end
  	catch
  		throw : _ ->
  			{error, 400}
  	end.
  %% @hidden
  patch_client3(Id, Port, Protocol, NewPassword, Etag) ->
  	IDstr = inet:ntoa(Id),
  	ok = ocs:update_client(Id, NewPassword),
  	RespObj =[{id, IDstr}, {href, "/ocs/v1/client/" ++ IDstr},
  