コード例 #1
0
ファイル: methods.py プロジェクト: legionus/billing
def jsonrpc_process(headers, request):
	notification = 'id' not in request

	LOG.info(repr(request) + ": notification=" + str(notification))

	def error(errcode, data = None):
		if not notification:
			return message.jsonrpc_response_error(request, errcode, data)
		return None

	for n in ['jsonrpc','method']:
		if n not in request:
			return error('InvalidRequest')

	if request.get('method').upper() not in methods:
		return error('MethodNotFound')

	try:
		method = methods[request.get('method').upper()]
		params = request.get('params',None)

		if method['auth']:
			if isinstance(params, list) and len(params) > 0 and secure.jsonrpc_is_auth(params[0]):
				sign = params[0]
				params = params[1:]
				if not secure.jsonrpc_auth(headers, sign, request):
					return error('AuthFailure')

			elif isinstance(params, dict) and secure.jsonrpc_is_auth(params.get('auth',None)):
				sign = params['auth']
				del params['auth']
				if not secure.jsonrpc_auth(headers, sign, request):
					return error('AuthFailure')
			else:
				return error('AuthFailure')

		if method['validator']:
			params = method['validator'].check(params)

		res = method['func'](params)

		if notification or not res:
			return None

		if res[0] == JSONRPC_RESULT:
			return message.jsonrpc_response(request, res[1])

		if res[0] == JSONRPC_ERROR:
			return message.jsonrpc_response_error(request, res[1], res[2])

		if res[0] == JSONRPC_HTTP:
			return (res[1], res[2], res[3])

	except ValidError, e:
		return error('InvalidParams', str(e))
コード例 #2
0
ファイル: methods.py プロジェクト: legionus/billing
	def error(errcode, data = None):
		if not notification:
			return message.jsonrpc_response_error(request, errcode, data)
		return None