Basic login parse.

This commit is contained in:
XMRig 2017-06-06 06:35:17 +03:00
parent 7deee3240b
commit 26b8206332
2 changed files with 32 additions and 0 deletions

View file

@ -136,6 +136,21 @@ void Client::send(char *data)
} }
bool Client::parseLogin(const json_t *result, int *code)
{
const char *id = json_string_value(json_object_get(result, "id"));
if (!id || strlen(id) >= sizeof(m_rpcId)) {
*code = 1;
return false;
}
memset(m_rpcId, 0, sizeof(m_rpcId));
memcpy(m_rpcId, id, strlen(id));
return true;
}
int Client::resolve(const char *host) int Client::resolve(const char *host)
{ {
setState(HostLookupState); setState(HostLookupState);
@ -227,6 +242,21 @@ void Client::parseResponse(int64_t id, const json_t *result, const json_t *error
return; return;
} }
if (!json_is_object(result)) {
return;
}
if (id == 1) {
int code = -1;
if (!parseLogin(result, &code)) {
LOG_ERR("[%s:%u] login error code: %d", m_host, m_port, code);
return close();
}
return;
}
} }

View file

@ -58,6 +58,7 @@ public:
private: private:
constexpr static size_t kRecvBufSize = 4096; constexpr static size_t kRecvBufSize = 4096;
bool parseLogin(const json_t *result, int *code);
int resolve(const char *host); int resolve(const char *host);
void close(); void close();
void connect(struct sockaddr *addr); void connect(struct sockaddr *addr);
@ -75,6 +76,7 @@ private:
static Client *getClient(void *data); static Client *getClient(void *data);
char *m_host; char *m_host;
char m_rpcId[64];
IClientListener *m_listener; IClientListener *m_listener;
int64_t m_retries; int64_t m_retries;
int64_t m_sequence; int64_t m_sequence;