Add API versioning to the JSON-RPC API

This commit is contained in:
Franz Heinzmann (Frando)
2022-07-15 14:26:55 +02:00
parent 15019ce02b
commit 361b7f5b69
7 changed files with 32 additions and 20 deletions

View File

@@ -4453,17 +4453,29 @@ mod jsonrpc {
#[no_mangle]
pub unsafe extern "C" fn dc_jsonrpc_init(
account_manager: *mut dc_accounts_t,
api_version: *const libc::c_char,
) -> *mut dc_jsonrpc_instance_t {
if account_manager.is_null() {
eprintln!("ignoring careless call to dc_jsonrpc_init()");
return ptr::null_mut();
}
let api_version = to_string_lossy(api_version);
let cmd_api =
deltachat_jsonrpc::api::CommandApi::from_arc((*account_manager).inner.clone());
let rpc_api = match &api_version {
"v0" => {
deltachat_jsonrpc::api::DeltaChatApiV0::from_arc((*account_manager).inner.clone())
}
_ => {
error!(
ctx,
"The requested JSON-RPC API version is not supported.", err
);
return ptr::null_mut();
}
};
let (request_handle, receiver) = RpcClient::new();
let handle = RpcSession::new(request_handle, cmd_api);
let handle = RpcSession::new(request_handle, rpc_api);
let instance = dc_jsonrpc_instance_t { receiver, handle };