diff -r -c RAToolSet-4.6.3/src/irr/birdwhoisc.cc RAToolSet-4.6.3-RIPE/src/irr/birdwhoisc.cc *** RAToolSet-4.6.3/src/irr/birdwhoisc.cc Thu Oct 14 20:13:22 1999 --- RAToolSet-4.6.3-RIPE/src/irr/birdwhoisc.cc Tue Mar 20 16:45:28 2001 *************** *** 9,14 **** --- 9,15 ---- #include "rpsl/object_log.hh" #include #include + #include #ifndef BUFFER_SIZE #define BUFFER_SIZE 2047 *************** *** 90,103 **** return true; } bool BirdWhoisClient::getResponse(char *&text, int &len) { int bytesRead; bool found = false; unsigned int endOfQuery; ! if (!response) ! // there may be some left over data after the previous query's response ! response = new Buffer; endOfQuery = 0; do { --- 91,162 ---- return true; } + // remove blank lines at the beginning of buffer, if possible + // returns true if something removed, else false + static bool removeLeadingBlankLines(Buffer &buf) + { + bool removedLines = false; + + // check if all remaining lines are blank + // this check is necessary to handle the case where the server + // returns object. + // after stripping RIPE comments, only blank lines are left, + // but if we remove them, then the "end-of-stream" double blank + // line is removed. + bool allBlank = true; + for (int i=0; allBlank && (i 0) && ((buf.getContents())[0] == '\n')) { + buf.flush(1); + removedLines = true; + } + } + + return removedLines; + } + + // remove comments at beginning of buffer + // returns true if something removed, else false + static bool removeLeadingRipeComments(Buffer &buf) + { + bool removedLines = false; + while ((buf.getSize() >= 2) && ((buf.getContents())[0] == '%')) { + char *contents = buf.getContents(); + char *eol = (char *)memchr(contents, '\n', buf.getSize()); + if (eol == NULL) { + // no EOL, no comment to strip (yet) + return removedLines; + } + buf.flush(eol-contents+1); + removedLines = true; + } + + return removedLines; + } + + // remove RIPE-style comments + static void stripRipeComments(Buffer &buf) + { + while (removeLeadingBlankLines(buf) || removeLeadingRipeComments(buf)) { + // do nothing + } + } + bool BirdWhoisClient::getResponse(char *&text, int &len) { int bytesRead; bool found = false; unsigned int endOfQuery; ! if (response != NULL) { ! delete response; ! } ! response = new Buffer; endOfQuery = 0; do { *************** *** 111,116 **** --- 170,184 ---- && response->contents[endOfQuery+2] == '\n') found = true; + if ((response->size == 2) && + (response->contents[0] == '\n') && + (response->contents[1] == '\n')) + { + delete response; + response = NULL; + return false; + } + if (found) break; *************** *** 125,130 **** --- 193,199 ---- response=NULL; return false; } + stripRipeComments(*response); } while (!found); Buffer *result = response; *************** *** 222,229 **** } #endif free(pzcKeys); } - return true; } bool BirdWhoisClient::getIndirectMembers(char *setName, --- 291,302 ---- } #endif free(pzcKeys); + return true; + } + else + { + return false; } } bool BirdWhoisClient::getIndirectMembers(char *setName,