| 74 | } |
| 75 | |
| 76 | void ServerList::readServerList() { |
| 77 | char* base = (char*)theData; |
| 78 | char* endS = base + theLen; |
| 79 | const char* tokenIdentifier = "TOKEN: "; |
| 80 | const char* noTokenIdentifier = "NOTOK: "; |
| 81 | const char* errorIdentifier = "ERROR: "; |
| 82 | const char* noticeIdentifier = "NOTICE: "; |
| 83 | // walks entire reply including HTTP headers |
| 84 | while (base < endS) { |
| 85 | // find next newline |
| 86 | char* scan = base; |
| 87 | while (scan < endS && *scan != '\n') { |
| 88 | scan++; |
| 89 | } |
| 90 | |
| 91 | // if no newline then no more complete replies |
| 92 | if (scan >= endS) { |
| 93 | break; |
| 94 | } |
| 95 | *scan++ = '\0'; |
| 96 | |
| 97 | // look for TOKEN: and save token if found also look for NOTOK: |
| 98 | // and record "badtoken" into the token string and print an |
| 99 | // error |
| 100 | if (strncmp(base, tokenIdentifier, strlen(tokenIdentifier)) == 0) { |
| 101 | strncpy(startupInfo->token, (char*)(base + strlen(tokenIdentifier)), |
| 102 | TokenLen); |
| 103 | #ifdef DEBUG |
| 104 | printError("got token:"); |
| 105 | printError(startupInfo->token); |
| 106 | #endif |
| 107 | base = scan; |
| 108 | continue; |
| 109 | } |
| 110 | else if (!strncmp(base, noTokenIdentifier, |
| 111 | strlen(noTokenIdentifier))) { |
| 112 | printError("ERROR: did not get token:"); |
| 113 | printError(base); |
| 114 | strcpy(startupInfo->token, "badtoken\0"); |
| 115 | base = scan; |
| 116 | continue; |
| 117 | } |
| 118 | else if (!strncmp(base, errorIdentifier, strlen(errorIdentifier))) { |
| 119 | printError(base); |
| 120 | strcpy(startupInfo->token, "badtoken\0"); |
| 121 | base = scan; |
| 122 | continue; |
| 123 | } |
| 124 | else if (!strncmp(base, noticeIdentifier, strlen(noticeIdentifier))) { |
| 125 | printError(base); |
| 126 | base = scan; |
| 127 | continue; |
| 128 | } |
| 129 | // parse server info |
| 130 | char* scan2, *name, *version, *infoServer, *address, *title; |
| 131 | name = base; |
| 132 | version = name; |
| 133 | while (*version && !isspace(*version)) { version++; } |
nothing calls this directly
no test coverage detected