@@ -86,8 +86,14 @@ bool AuthClient::readln(char *buffer, size_t buflen) {
8686 }
8787 return true ;
8888 }
89- if (pos < buflen)
90- buffer[pos++] = byte;
89+
90+ if (byte != 255 ) {
91+ if (pos < buflen) buffer[pos++] = byte;
92+ }
93+ else {
94+ buffer[pos++] = ' \0 ' ;
95+ return true ;
96+ }
9197 }
9298 }
9399 return false ;
@@ -315,41 +321,43 @@ int AuthClient::getGearToken(char mode, char* token, char* tokensecret, char* en
315321 while (true ) {
316322 if (readln (buff, (size_t )MAXHEADERLINESIZE)) {
317323
318- #ifdef DEBUG_H
319- Serial.println (buff);
320- #endif
321-
322- if (pline<2 ) {
324+ #ifdef DEBUG_H
325+ Serial.println (buff);
326+ #endif
327+ if (httpstatus==0 ) {
323328 if (strncmp (buff," HTTP" ,4 )==0 ) {
324329 buff[12 ] = ' \0 ' ;
325330 httpstatus = atoi (buff+9 );
326331 }
327332 }
328333 else {
329- char *p;
330- char *s, *t ;
331-
332- int last = 0 ;
333- p = buff ;
334- while (*p != ' \0 ' ) {
335- s = p;
336- while (*s!= ' = ' && *s!= ' \0 ' && *s!= ' & ' ) s++; /* seek for = */
337- t= s;
338- while (*t!= ' \0 ' && *t!= ' & ' ) t++; /* seek for & */
339- *s = ' \0 ' ;
340- if (*t == ' \0 ' ) last = 1 ;
341- *t = ' \0 ' ;
342-
343- if (strcmp (p," oauth_token" )==0 ) strcpy (token,s+1 );
344- else if (strcmp (p," oauth_token_secret" )==0 ) strcpy (tokensecret,s+1 );
345- else if (strcmp (p," endpoint" )==0 ) strcpy (endpoint,s+1 );
346- delay (400 );
347-
348- if (!last) p = t+ 1 ; else break ;
349- }
350- return httpstatus;
334+ if ( strlen (buff) < 1 ) {
335+ readln (buff, ( size_t )MAXHEADERLINESIZE) ;
336+ char *p;
337+ char *s, *t ;
338+ int last = 0 ;
339+ p = buff;
340+ while (*p != ' \0 ' ) {
341+ s = p;
342+ while (*s!= ' = ' && *s!= ' \0 ' && *s!= ' & ' ) s++; // seek for =
343+ t= s;
344+ while (*t!= ' \0 ' && *t!= ' & ' ) t++; // seek for &
345+ *s = ' \0 ' ;
346+ if ( *t == ' \0 ' ) last = 1 ;
347+ *t = ' \0 ' ;
348+ if (strcmp (p," oauth_token" )==0 ) strcpy (token,s+1 );
349+ else if (strcmp (p," oauth_token_secret" )==0 ) strcpy (tokensecret,s+1 );
350+ else if (strcmp (p," endpoint" )==0 ) strcpy (endpoint,s+1 );
351+ delay (200 );
352+ if (!last) p = t+ 1 ; else break ;
353+ }
354+ return httpstatus;
355+ }
351356 }
352- if (strlen (buff)<6 ) pline++;
357+
358+
359+
360+
353361 }
354362 else {
355363 return 0 ;
0 commit comments