}
static void
+test_evbuffer_readln(void)
+{
+ struct evbuffer *evb = evbuffer_new();
+ const char *s;
+ char *cp = NULL;
+ size_t sz;
+ setup_test("Testing evbuffer_readln(): ");
+
+ /* Test EOL_ANY. */
+ s = "complex silly newline\r\n\n\r\n\n\rmore\0\n";
+ evbuffer_add(evb, s, strlen(s)+2);
+ cp = evbuffer_readln(evb, &sz, EVBUFFER_EOL_ANY);
+ if (!cp || sz != strlen(cp) || strcmp(cp, "complex silly newline"))
+ goto done;
+ free(cp);
+ cp = evbuffer_readln(evb, &sz, EVBUFFER_EOL_ANY);
+ if (!cp || sz != 5 || memcmp(cp, "more\0\0", 6))
+ goto done;
+ if (EVBUFFER_LENGTH(evb) != 0)
+ goto done;
+ s = "\nno newline";
+ evbuffer_add(evb, s, strlen(s));
+ free(cp);
+ cp = evbuffer_readln(evb, &sz, EVBUFFER_EOL_ANY);
+ if (!cp || sz || strcmp(cp, ""))
+ goto done;
+ free(cp);
+ cp = evbuffer_readln(evb, &sz, EVBUFFER_EOL_ANY);
+ if (cp)
+ goto done;
+ evbuffer_drain(evb, EVBUFFER_LENGTH(evb));
+ if (EVBUFFER_LENGTH(evb) != 0)
+ goto done;
+
+ /* Test EOL_CRLF */
+ s = "Line with\rin the middle\nLine with good crlf\r\n\nfinal\n";
+ evbuffer_add(evb, s, strlen(s));
+ cp = evbuffer_readln(evb, &sz, EVBUFFER_EOL_CRLF);
+ if (!cp || sz != strlen(cp) || strcmp(cp, "Line with\rin the middle"))
+ goto done;
+
+ free(cp);
+ cp = evbuffer_readln(evb, &sz, EVBUFFER_EOL_CRLF);
+ if (!cp || sz != strlen(cp) || strcmp(cp, "Line with good crlf"))
+ goto done;
+ free(cp);
+ cp = evbuffer_readln(evb, &sz, EVBUFFER_EOL_CRLF);
+ if (!cp || sz != strlen(cp) || strcmp(cp, ""))
+ goto done;
+ free(cp);
+ cp = evbuffer_readln(evb, &sz, EVBUFFER_EOL_CRLF);
+ if (!cp || sz != strlen(cp) || strcmp(cp, "final"))
+ goto done;
+ s = "x";
+ evbuffer_add(evb, s, 1);
+ free(cp);
+ cp = evbuffer_readln(evb, &sz, EVBUFFER_EOL_CRLF);
+ if (cp)
+ goto done;
+
+ /* Test CRLF_STRICT */
+ s = " and a bad crlf\nand a good one\r\n\r\nMore\r";
+ evbuffer_add(evb, s, strlen(s));
+ cp = evbuffer_readln(evb, &sz, EVBUFFER_EOL_CRLF_STRICT);
+ if (!cp || sz != strlen(cp) ||
+ strcmp(cp, "x and a bad crlf\nand a good one"))
+ goto done;
+ free(cp);
+ cp = evbuffer_readln(evb, &sz, EVBUFFER_EOL_CRLF_STRICT);
+ if (!cp || sz != strlen(cp) || strcmp(cp, ""))
+ goto done;
+ free(cp);
+ cp = evbuffer_readln(evb, &sz, EVBUFFER_EOL_CRLF_STRICT);
+ if (cp)
+ goto done;
+ evbuffer_add(evb, "\n", 1);
+ cp = evbuffer_readln(evb, &sz, EVBUFFER_EOL_CRLF_STRICT);
+ if (!cp || sz != strlen(cp) || strcmp(cp, "More"))
+ goto done;
+ if (EVBUFFER_LENGTH(evb) != 0)
+ goto done;
+
+ /* Test LF */
+ s = "An\rand a nl\n\nText";
+ evbuffer_add(evb, s, strlen(s));
+ cp = evbuffer_readln(evb, &sz, EVBUFFER_EOL_LF);
+ if (!cp || sz != strlen(cp) || strcmp(cp, "An\rand a nl"))
+ goto done;
+ free(cp);
+ cp = evbuffer_readln(evb, &sz, EVBUFFER_EOL_LF);
+ if (!cp || sz != strlen(cp) || strcmp(cp, ""))
+ goto done;
+ free(cp);
+ cp = evbuffer_readln(evb, &sz, EVBUFFER_EOL_LF);
+ if (cp)
+ goto done;
+ evbuffer_add(evb, "\n", 1);
+ cp = evbuffer_readln(evb, &sz, EVBUFFER_EOL_LF);
+ if (!cp || sz != strlen(cp) || strcmp(cp, "Text"))
+ goto done;
+
+ test_ok = 1;
+ done:
+ evbuffer_free(evb);
+ if (cp) free(cp);
+ cleanup_test();
+}
+
+void
test_evbuffer_find(void)
{
u_char* p;