tdlight/td/telegram/td_json_client.cpp
levlam dd9964ae3a Don't crash on nullptr passed to td_json_client.
GitOrigin-RevId: b064ab5d839a5747d9bf1d289238fa77da219585
2018-09-21 16:41:22 +03:00

46 lines
1.2 KiB
C++

//
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2018
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#include "td/telegram/td_json_client.h"
#include "td/telegram/ClientJson.h"
#include "td/utils/Slice.h"
extern "C" int td_json_client_square(int x, const char *str) {
return x * x;
}
void *td_json_client_create() {
return new td::ClientJson();
}
void td_json_client_destroy(void *client) {
delete static_cast<td::ClientJson *>(client);
}
void td_json_client_send(void *client, const char *request) {
static_cast<td::ClientJson *>(client)->send(td::Slice(request == nullptr ? "" : request));
}
const char *td_json_client_receive(void *client, double timeout) {
auto slice = static_cast<td::ClientJson *>(client)->receive(timeout);
if (slice.empty()) {
return nullptr;
} else {
return slice.c_str();
}
}
const char *td_json_client_execute(void *client, const char *request) {
auto slice = static_cast<td::ClientJson *>(client)->execute(td::Slice(request == nullptr ? "" : request));
if (slice.empty()) {
return nullptr;
} else {
return slice.c_str();
}
}