Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,6 @@ ParsePush KEYWORD1
#######################################

begin KEYWORD2
setServerURL KEYWORD2
setHostFingerprint KEYWORD2
setClientInsecure KEYWORD2
21 changes: 21 additions & 0 deletions src/internal/ParseClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ class ParseClient {
private:
char applicationId[41]; // APPLICATION_ID_MAX_LEN
char clientKey[41]; // CLIENT_KEY_MAX_LEN
char serverURL[100]; // SERVER_URL_MAX_LEN
char hostFingerprint[100]; // HOST_FINGERPRINT_MAX_LEN
char installationId[37]; // INSTALLATION_ID_MAX_LEN
char sessionToken[41]; // SESSION_TOKEN_MAX_LEN

Expand Down Expand Up @@ -92,6 +94,25 @@ class ParseClient {
*
*/
void setServerURL(const char *serverURL);

/*! \fn void setHostFingerprint(const char *hostFingerprint)
* \brief Set the host fingerprint this client.
*
* Set the custom host fingerprint for this client. This needs to be called
* API request.
*
* \param hostFingerprint The host fingerprint of the serverURL.
*
*/
void setHostFingerprint(const char *hostFingerprint);

/*! \fn setClientInsecure()
* \brief Sets the connection client to insecure
*
*
*
*/
void setClientInsecure();

/*! \fn void setInstallationId(const char *installationId)
* \brief Set the installation object id for this client.
Expand Down
31 changes: 29 additions & 2 deletions src/internal/esp8266/ParseClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ static void sendAndEchoToSerial(WiFiClientSecure& client, const char *line) {
ParseClient::ParseClient() {
memset(applicationId, 0, sizeof(applicationId));
memset(clientKey, 0, sizeof(clientKey));
memset(serverURL, 0, sizeof(serverURL));
memset(hostFingerprint, 0, sizeof(hostFingerprint));
memset(installationId, 0, sizeof(installationId));
memset(sessionToken, 0, sizeof(sessionToken));
memset(lastPushTime, 0, sizeof(lastPushTime));
Expand Down Expand Up @@ -110,6 +112,29 @@ void ParseClient::begin(const char *applicationId, const char *clientKey) {
restoreKeys();
}

void ParseClient::setServerURL(const char *serverURL) {
Serial.print("setting serverURL(");
Serial.print(serverURL ? serverURL : "NULL");
Serial.println(")");
if(serverURL) {
strncpy(this->serverURL, serverURL, sizeof(this->serverURL));
}
}

void ParseClient::setHostFingerprint(const char *hostFingerprint) {
Serial.print("setting hostFingerprint(");
Serial.print(hostFingerprint ? hostFingerprint : "NULL");
Serial.println(")");
if(hostFingerprint) {
strncpy(this->hostFingerprint, hostFingerprint, sizeof(this->hostFingerprint));
}
}

void ParseClient::setClientInsecure() {
Serial.println("setting connection client insecure");
client.setInsecure();
}

void ParseClient::setInstallationId(const char *installationId) {
if (installationId) {
if (strcmp(this->installationId, installationId))
Expand Down Expand Up @@ -201,8 +226,10 @@ ParseResponse ParseClient::sendRequest(const String& httpVerb, const String& htt

int retry = 3;
bool connected;

client.setFingerprint(hostFingerprint);

while(!(connected = client.connect(PARSE_API, SSL_PORT)) && retry--) {
while(!(connected = client.connect(serverURL, SSL_PORT)) && retry--) {
Serial.printf("connecting...%d\n", retry);
yield();
}
Expand All @@ -220,7 +247,7 @@ ParseResponse ParseClient::sendRequest(const String& httpVerb, const String& htt
snprintf(buff, sizeof(buff) - 1, "%s %s HTTP/1.1\r\n", httpVerb.c_str(), httpPath.c_str());
}
sendAndEchoToSerial(client, buff);
snprintf(buff, sizeof(buff) - 1, "Host: %s\r\n", PARSE_API);
snprintf(buff, sizeof(buff) - 1, "Host: %s\r\n", serverURL);
sendAndEchoToSerial(client, buff);
snprintf(buff, sizeof(buff) - 1, "X-Parse-Client-Version: %s\r\n", CLIENT_VERSION);
sendAndEchoToSerial(client, buff);
Expand Down