diff options
author | Daniel Stenberg <daniel@haxx.se> | 2021-06-18 23:49:25 +0200 |
---|---|---|
committer | Daniel Stenberg <daniel@haxx.se> | 2021-06-24 09:07:40 +0200 |
commit | a5ab72d5edd72eba3485c790b42006d407e6f162 (patch) | |
tree | fe3cd7a06d7311102b58be7887231d7fd5c59e64 /tests/libtest | |
parent | 9accc48850568353fde9a0d60dcbaf08ef6164f5 (diff) | |
download | curl-a5ab72d5edd72eba3485c790b42006d407e6f162.tar.gz |
test677: IMAP CONNECT_ONLY, custom command and then exit
Adjusted ftpserver.pl to add support for the IMAP IDLE command
Adjusted test 660 to sync with the fix
Diffstat (limited to 'tests/libtest')
-rw-r--r-- | tests/libtest/Makefile.inc | 6 | ||||
-rw-r--r-- | tests/libtest/lib677.c | 117 |
2 files changed, 122 insertions, 1 deletions
diff --git a/tests/libtest/Makefile.inc b/tests/libtest/Makefile.inc index 60cd65320..c2d0a6e8e 100644 --- a/tests/libtest/Makefile.inc +++ b/tests/libtest/Makefile.inc @@ -48,7 +48,7 @@ noinst_PROGRAMS = chkhostname libauthretry libntlmconnect \ lib599 \ lib643 lib645 lib650 lib651 lib652 lib653 lib654 lib655 lib658 \ lib659 lib661 lib666 lib667 lib668 \ - lib670 lib671 lib672 lib673 lib674 lib676 lib678 \ + lib670 lib671 lib672 lib673 lib674 lib676 lib677 lib678 \ lib1156 \ lib1500 lib1501 lib1502 lib1503 lib1504 lib1505 lib1506 lib1507 lib1508 \ lib1509 lib1510 lib1511 lib1512 lib1513 lib1514 lib1515 lib1517 \ @@ -406,6 +406,10 @@ lib676_SOURCES = lib676.c $(SUPPORTFILES) $(TESTUTIL) $(WARNLESS) lib676_LDADD = $(TESTUTIL_LIBS) lib676_CPPFLAGS = $(AM_CPPFLAGS) +lib677_SOURCES = lib677.c $(SUPPORTFILES) $(TESTUTIL) $(WARNLESS) $(MULTIBYTE) +lib677_LDADD = $(TESTUTIL_LIBS) +lib677_CPPFLAGS = $(AM_CPPFLAGS) + lib678_SOURCES = lib678.c $(SUPPORTFILES) $(TESTUTIL) $(WARNLESS) $(MULTIBYTE) lib678_LDADD = $(TESTUTIL_LIBS) lib678_CPPFLAGS = $(AM_CPPFLAGS) diff --git a/tests/libtest/lib677.c b/tests/libtest/lib677.c new file mode 100644 index 000000000..48d5919fe --- /dev/null +++ b/tests/libtest/lib677.c @@ -0,0 +1,117 @@ +/*************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * Copyright (C) 1998 - 2021, Daniel Stenberg, <daniel@haxx.se>, et al. + * + * This software is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at https://curl.se/docs/copyright.html. + * + * You may opt to use, copy, modify, merge, publish, distribute and/or sell + * copies of the Software, and permit persons to whom the Software is + * furnished to do so, under the terms of the COPYING file. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ***************************************************************************/ +#include "test.h" + +#include "testutil.h" +#include "warnless.h" +#include "memdebug.h" + +static const char cmd[] = "A1 IDLE\r\n"; +static char buf[1024]; + +int test(char *URL) +{ + CURLM *mcurl; + CURL *curl; + int mrun; + curl_socket_t sock = CURL_SOCKET_BAD; + time_t start = time(NULL); + int state = 0; + ssize_t pos = 0; + + curl_global_init(CURL_GLOBAL_DEFAULT); + mcurl = curl_multi_init(); + if(!mcurl) + return 1; + curl = curl_easy_init(); + if(!curl) + goto fail; + + curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); + curl_easy_setopt(curl, CURLOPT_URL, URL); + curl_easy_setopt(curl, CURLOPT_CONNECT_ONLY, 1L); + curl_multi_add_handle(mcurl, curl); + + while(time(NULL) - start < 5) { + struct curl_waitfd waitfd; + + curl_multi_perform(mcurl, &mrun); + for(;;) { + int i; + struct CURLMsg *m = curl_multi_info_read(mcurl, &i); + + if(!m) + break; + if(m->msg == CURLMSG_DONE && m->easy_handle == curl) { + curl_easy_getinfo(curl, CURLINFO_ACTIVESOCKET, &sock); + if(sock == CURL_SOCKET_BAD) + return 3; + printf("Connected fine, extracted socket. Moving on\n"); + } + } + + if(sock != CURL_SOCKET_BAD) { + waitfd.events = state ? CURL_WAIT_POLLIN : CURL_WAIT_POLLOUT; + waitfd.revents = 0; + curl_easy_getinfo(curl, CURLINFO_ACTIVESOCKET, &sock); + waitfd.fd = sock; + } + curl_multi_wait(mcurl, &waitfd, sock == CURL_SOCKET_BAD ? 0 : 1, 500, + &mrun); + if((sock != CURL_SOCKET_BAD) && (waitfd.revents & waitfd.events)) { + size_t len = 0; + + if(!state) { + curl_easy_send(curl, cmd + pos, sizeof(cmd) - 1 - pos, &len); + if(len > 0) + pos += len; + else + pos = 0; + if(pos == sizeof(cmd) - 1) { + state++; + pos = 0; + } + } + else if(pos < (ssize_t)sizeof(buf)) { + curl_easy_recv(curl, buf + pos, sizeof(buf) - pos, &len); + if(len > 0) + pos += len; + } + if(len <= 0) + sock = CURL_SOCKET_BAD; + } + } + + if(state) { + fwrite(buf, pos, 1, stdout); + putchar('\n'); + } + + curl_multi_remove_handle(mcurl, curl); + fail: + curl_easy_cleanup(curl); + curl_multi_cleanup(mcurl); + + curl_global_cleanup(); + return 0; +} + |