Skip to content

Commit 9694d7f

Browse files
committed
better handle api response
1 parent 15b802f commit 9694d7f

File tree

3 files changed

+198
-189
lines changed

3 files changed

+198
-189
lines changed

AuthClient.cpp

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ AuthClient::~AuthClient() {
1818
void AuthClient::init(char* appid, char* scope, unsigned long bts) {
1919
this->appid = appid;
2020
this->scope = scope;
21-
this->bootts = bts;
21+
this->bootts = bts;
2222
}
2323

2424
bool AuthClient::connect() {
@@ -70,22 +70,22 @@ void AuthClient::writeln(char* str) {
7070
}
7171

7272
bool AuthClient::readln(char *buffer, size_t buflen) {
73-
size_t pos = 0;
74-
while (true) {
75-
while (true) {
76-
uint8_t byte = client->read();
77-
if (byte == '\n') {
78-
// EOF found.
79-
if (pos < buflen) {
80-
if (pos > 0 && buffer[pos - 1] == '\r')
81-
pos--;
82-
buffer[pos] = '\0';
83-
}
84-
else {
85-
buffer[buflen - 1] = '\0';
86-
}
87-
return true;
88-
}
73+
size_t pos = 0;
74+
while (true) {
75+
while (true) {
76+
uint8_t byte = client->read();
77+
if (byte == '\n') {
78+
// EOF found.
79+
if (pos < buflen) {
80+
if (pos > 0 && buffer[pos - 1] == '\r')
81+
pos--;
82+
buffer[pos] = '\0';
83+
}
84+
else {
85+
buffer[buflen - 1] = '\0';
86+
}
87+
return true;
88+
}
8989

9090
if (byte != 255) {
9191
if (pos < buflen) buffer[pos++] = byte;
@@ -94,9 +94,9 @@ bool AuthClient::readln(char *buffer, size_t buflen) {
9494
buffer[pos++] = '\0';
9595
return true;
9696
}
97-
}
98-
}
99-
return false;
97+
}
98+
}
99+
return false;
100100
}
101101

102102
bool processTok(char* key, char* buff, char **p) {
@@ -177,19 +177,19 @@ int AuthClient::getGearToken(char mode, char* token, char* tokensecret, char* en
177177
write("Authorization: OAuth ");
178178

179179
//OAUTH_CALLBACK
180-
/* this header is too long -- have to break into smaller chunks to write */
180+
/* this header is too long -- have to break into smaller chunks to write */
181181
*buff = '\0';
182182
append(buff,OAUTH_CALLBACK,0);
183183
strcat(buff,"\"appid%3D");
184-
strcat(buff,appid);
184+
strcat(buff,appid);
185185
write(buff);
186186

187-
*buff = '\0';
187+
*buff = '\0';
188188
strcat(buff,"%26scope%3D");
189-
strcat(buff,scope);
189+
strcat(buff,scope);
190190
strcat(buff,"%26verifier%3D");
191-
strcat(buff,VERIFIER);
192-
strcat(buff,"\",");
191+
strcat(buff,VERIFIER);
192+
strcat(buff,"\",");
193193
write(buff);
194194

195195
*buff = '\0';
@@ -246,8 +246,8 @@ int AuthClient::getGearToken(char mode, char* token, char* tokensecret, char* en
246246
*buff = '\0';
247247
append(buff,(char *)OAUTH_TIMESTAMP,0);
248248

249-
//Bypass NTP
250-
sprintf(strtail(buff),"\"%lu\"",bootts+millis()/1000);
249+
//Bypass NTP
250+
sprintf(strtail(buff),"\"%lu\"",bootts+millis()/1000);
251251

252252
strcat(signbase,"%26"); //&
253253
encode(strtail(signbase),buff);
@@ -314,7 +314,7 @@ int AuthClient::getGearToken(char mode, char* token, char* tokensecret, char* en
314314
Serial.println("Finish OAuth HTTP request..");
315315
#endif
316316

317-
delay(2000);
317+
delay(2000);
318318

319319
int httpstatus = 0;
320320
char pline = 0;

0 commit comments

Comments
 (0)