Skip to content

Commit 8ac75b6

Browse files
authored
Merge pull request #19 from DJMarlow/master
Additional Methods for Custom Server URL and Connection Security
2 parents 372d263 + e35ece4 commit 8ac75b6

File tree

3 files changed

+53
-2
lines changed

3 files changed

+53
-2
lines changed

keywords.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,6 @@ ParsePush KEYWORD1
2121
#######################################
2222

2323
begin KEYWORD2
24+
setServerURL KEYWORD2
25+
setHostFingerprint KEYWORD2
26+
setClientInsecure KEYWORD2

src/internal/ParseClient.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ class ParseClient {
4040
private:
4141
char applicationId[41]; // APPLICATION_ID_MAX_LEN
4242
char clientKey[41]; // CLIENT_KEY_MAX_LEN
43+
char serverURL[100]; // SERVER_URL_MAX_LEN
44+
char hostFingerprint[100]; // HOST_FINGERPRINT_MAX_LEN
4345
char installationId[37]; // INSTALLATION_ID_MAX_LEN
4446
char sessionToken[41]; // SESSION_TOKEN_MAX_LEN
4547

@@ -92,6 +94,25 @@ class ParseClient {
9294
*
9395
*/
9496
void setServerURL(const char *serverURL);
97+
98+
/*! \fn void setHostFingerprint(const char *hostFingerprint)
99+
* \brief Set the host fingerprint this client.
100+
*
101+
* Set the custom host fingerprint for this client. This needs to be called
102+
* API request.
103+
*
104+
* \param hostFingerprint The host fingerprint of the serverURL.
105+
*
106+
*/
107+
void setHostFingerprint(const char *hostFingerprint);
108+
109+
/*! \fn setClientInsecure()
110+
* \brief Sets the connection client to insecure
111+
*
112+
*
113+
*
114+
*/
115+
void setClientInsecure();
95116

96117
/*! \fn void setInstallationId(const char *installationId)
97118
* \brief Set the installation object id for this client.

src/internal/esp8266/ParseClient.cpp

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ static void sendAndEchoToSerial(WiFiClientSecure& client, const char *line) {
8181
ParseClient::ParseClient() {
8282
memset(applicationId, 0, sizeof(applicationId));
8383
memset(clientKey, 0, sizeof(clientKey));
84+
memset(serverURL, 0, sizeof(serverURL));
85+
memset(hostFingerprint, 0, sizeof(hostFingerprint));
8486
memset(installationId, 0, sizeof(installationId));
8587
memset(sessionToken, 0, sizeof(sessionToken));
8688
memset(lastPushTime, 0, sizeof(lastPushTime));
@@ -110,6 +112,29 @@ void ParseClient::begin(const char *applicationId, const char *clientKey) {
110112
restoreKeys();
111113
}
112114

115+
void ParseClient::setServerURL(const char *serverURL) {
116+
Serial.print("setting serverURL(");
117+
Serial.print(serverURL ? serverURL : "NULL");
118+
Serial.println(")");
119+
if(serverURL) {
120+
strncpy(this->serverURL, serverURL, sizeof(this->serverURL));
121+
}
122+
}
123+
124+
void ParseClient::setHostFingerprint(const char *hostFingerprint) {
125+
Serial.print("setting hostFingerprint(");
126+
Serial.print(hostFingerprint ? hostFingerprint : "NULL");
127+
Serial.println(")");
128+
if(hostFingerprint) {
129+
strncpy(this->hostFingerprint, hostFingerprint, sizeof(this->hostFingerprint));
130+
}
131+
}
132+
133+
void ParseClient::setClientInsecure() {
134+
Serial.println("setting connection client insecure");
135+
client.setInsecure();
136+
}
137+
113138
void ParseClient::setInstallationId(const char *installationId) {
114139
if (installationId) {
115140
if (strcmp(this->installationId, installationId))
@@ -201,8 +226,10 @@ ParseResponse ParseClient::sendRequest(const String& httpVerb, const String& htt
201226

202227
int retry = 3;
203228
bool connected;
229+
230+
client.setFingerprint(hostFingerprint);
204231

205-
while(!(connected = client.connect(PARSE_API, SSL_PORT)) && retry--) {
232+
while(!(connected = client.connect(serverURL, SSL_PORT)) && retry--) {
206233
Serial.printf("connecting...%d\n", retry);
207234
yield();
208235
}
@@ -220,7 +247,7 @@ ParseResponse ParseClient::sendRequest(const String& httpVerb, const String& htt
220247
snprintf(buff, sizeof(buff) - 1, "%s %s HTTP/1.1\r\n", httpVerb.c_str(), httpPath.c_str());
221248
}
222249
sendAndEchoToSerial(client, buff);
223-
snprintf(buff, sizeof(buff) - 1, "Host: %s\r\n", PARSE_API);
250+
snprintf(buff, sizeof(buff) - 1, "Host: %s\r\n", serverURL);
224251
sendAndEchoToSerial(client, buff);
225252
snprintf(buff, sizeof(buff) - 1, "X-Parse-Client-Version: %s\r\n", CLIENT_VERSION);
226253
sendAndEchoToSerial(client, buff);

0 commit comments

Comments
 (0)