113498266Sopenharmony_ci/*************************************************************************** 213498266Sopenharmony_ci * _ _ ____ _ 313498266Sopenharmony_ci * Project ___| | | | _ \| | 413498266Sopenharmony_ci * / __| | | | |_) | | 513498266Sopenharmony_ci * | (__| |_| | _ <| |___ 613498266Sopenharmony_ci * \___|\___/|_| \_\_____| 713498266Sopenharmony_ci * 813498266Sopenharmony_ci * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al. 913498266Sopenharmony_ci * 1013498266Sopenharmony_ci * This software is licensed as described in the file COPYING, which 1113498266Sopenharmony_ci * you should have received as part of this distribution. The terms 1213498266Sopenharmony_ci * are also available at https://curl.se/docs/copyright.html. 1313498266Sopenharmony_ci * 1413498266Sopenharmony_ci * You may opt to use, copy, modify, merge, publish, distribute and/or sell 1513498266Sopenharmony_ci * copies of the Software, and permit persons to whom the Software is 1613498266Sopenharmony_ci * furnished to do so, under the terms of the COPYING file. 1713498266Sopenharmony_ci * 1813498266Sopenharmony_ci * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 1913498266Sopenharmony_ci * KIND, either express or implied. 2013498266Sopenharmony_ci * 2113498266Sopenharmony_ci * SPDX-License-Identifier: curl 2213498266Sopenharmony_ci * 2313498266Sopenharmony_ci ***************************************************************************/ 2413498266Sopenharmony_ci#include "test.h" 2513498266Sopenharmony_ci#include "memdebug.h" 2613498266Sopenharmony_ci 2713498266Sopenharmony_ciint test(char *URL) 2813498266Sopenharmony_ci{ 2913498266Sopenharmony_ci CURLcode res; 3013498266Sopenharmony_ci CURL *curl = NULL; 3113498266Sopenharmony_ci char *newURL = NULL; 3213498266Sopenharmony_ci struct curl_slist *slist = NULL; 3313498266Sopenharmony_ci 3413498266Sopenharmony_ci if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) { 3513498266Sopenharmony_ci fprintf(stderr, "curl_global_init() failed\n"); 3613498266Sopenharmony_ci return TEST_ERR_MAJOR_BAD; 3713498266Sopenharmony_ci } 3813498266Sopenharmony_ci 3913498266Sopenharmony_ci curl = curl_easy_init(); 4013498266Sopenharmony_ci if(!curl) { 4113498266Sopenharmony_ci fprintf(stderr, "curl_easy_init() failed\n"); 4213498266Sopenharmony_ci res = TEST_ERR_MAJOR_BAD; 4313498266Sopenharmony_ci goto test_cleanup; 4413498266Sopenharmony_ci } 4513498266Sopenharmony_ci 4613498266Sopenharmony_ci /* test: CURLFTPMETHOD_SINGLECWD with absolute path should 4713498266Sopenharmony_ci skip CWD to entry path */ 4813498266Sopenharmony_ci newURL = aprintf("%s/folderA/661", URL); 4913498266Sopenharmony_ci test_setopt(curl, CURLOPT_URL, newURL); 5013498266Sopenharmony_ci test_setopt(curl, CURLOPT_VERBOSE, 1L); 5113498266Sopenharmony_ci test_setopt(curl, CURLOPT_IGNORE_CONTENT_LENGTH, 1L); 5213498266Sopenharmony_ci test_setopt(curl, CURLOPT_FTP_FILEMETHOD, (long) CURLFTPMETHOD_SINGLECWD); 5313498266Sopenharmony_ci res = curl_easy_perform(curl); 5413498266Sopenharmony_ci if(res != CURLE_REMOTE_FILE_NOT_FOUND) 5513498266Sopenharmony_ci goto test_cleanup; 5613498266Sopenharmony_ci 5713498266Sopenharmony_ci curl_free(newURL); 5813498266Sopenharmony_ci newURL = aprintf("%s/folderB/661", URL); 5913498266Sopenharmony_ci test_setopt(curl, CURLOPT_URL, newURL); 6013498266Sopenharmony_ci res = curl_easy_perform(curl); 6113498266Sopenharmony_ci if(res != CURLE_REMOTE_FILE_NOT_FOUND) 6213498266Sopenharmony_ci goto test_cleanup; 6313498266Sopenharmony_ci 6413498266Sopenharmony_ci /* test: CURLFTPMETHOD_NOCWD with absolute path should 6513498266Sopenharmony_ci never emit CWD (for both new and reused easy handle) */ 6613498266Sopenharmony_ci curl_easy_cleanup(curl); 6713498266Sopenharmony_ci curl = curl_easy_init(); 6813498266Sopenharmony_ci if(!curl) { 6913498266Sopenharmony_ci fprintf(stderr, "curl_easy_init() failed\n"); 7013498266Sopenharmony_ci res = TEST_ERR_MAJOR_BAD; 7113498266Sopenharmony_ci goto test_cleanup; 7213498266Sopenharmony_ci } 7313498266Sopenharmony_ci 7413498266Sopenharmony_ci curl_free(newURL); 7513498266Sopenharmony_ci newURL = aprintf("%s/folderA/661", URL); 7613498266Sopenharmony_ci test_setopt(curl, CURLOPT_URL, newURL); 7713498266Sopenharmony_ci test_setopt(curl, CURLOPT_VERBOSE, 1L); 7813498266Sopenharmony_ci test_setopt(curl, CURLOPT_IGNORE_CONTENT_LENGTH, 1L); 7913498266Sopenharmony_ci test_setopt(curl, CURLOPT_FTP_FILEMETHOD, (long) CURLFTPMETHOD_NOCWD); 8013498266Sopenharmony_ci res = curl_easy_perform(curl); 8113498266Sopenharmony_ci if(res != CURLE_REMOTE_FILE_NOT_FOUND) 8213498266Sopenharmony_ci goto test_cleanup; 8313498266Sopenharmony_ci 8413498266Sopenharmony_ci /* curve ball: CWD /folderB before reusing connection with _NOCWD */ 8513498266Sopenharmony_ci curl_free(newURL); 8613498266Sopenharmony_ci newURL = aprintf("%s/folderB/661", URL); 8713498266Sopenharmony_ci test_setopt(curl, CURLOPT_URL, newURL); 8813498266Sopenharmony_ci test_setopt(curl, CURLOPT_FTP_FILEMETHOD, (long) CURLFTPMETHOD_SINGLECWD); 8913498266Sopenharmony_ci res = curl_easy_perform(curl); 9013498266Sopenharmony_ci if(res != CURLE_REMOTE_FILE_NOT_FOUND) 9113498266Sopenharmony_ci goto test_cleanup; 9213498266Sopenharmony_ci 9313498266Sopenharmony_ci curl_free(newURL); 9413498266Sopenharmony_ci newURL = aprintf("%s/folderA/661", URL); 9513498266Sopenharmony_ci test_setopt(curl, CURLOPT_URL, newURL); 9613498266Sopenharmony_ci test_setopt(curl, CURLOPT_FTP_FILEMETHOD, (long) CURLFTPMETHOD_NOCWD); 9713498266Sopenharmony_ci res = curl_easy_perform(curl); 9813498266Sopenharmony_ci if(res != CURLE_REMOTE_FILE_NOT_FOUND) 9913498266Sopenharmony_ci goto test_cleanup; 10013498266Sopenharmony_ci 10113498266Sopenharmony_ci /* test: CURLFTPMETHOD_NOCWD with home-relative path should 10213498266Sopenharmony_ci not emit CWD for first FTP access after login */ 10313498266Sopenharmony_ci curl_easy_cleanup(curl); 10413498266Sopenharmony_ci curl = curl_easy_init(); 10513498266Sopenharmony_ci if(!curl) { 10613498266Sopenharmony_ci fprintf(stderr, "curl_easy_init() failed\n"); 10713498266Sopenharmony_ci res = TEST_ERR_MAJOR_BAD; 10813498266Sopenharmony_ci goto test_cleanup; 10913498266Sopenharmony_ci } 11013498266Sopenharmony_ci 11113498266Sopenharmony_ci slist = curl_slist_append(NULL, "SYST"); 11213498266Sopenharmony_ci if(!slist) { 11313498266Sopenharmony_ci fprintf(stderr, "curl_slist_append() failed\n"); 11413498266Sopenharmony_ci res = TEST_ERR_MAJOR_BAD; 11513498266Sopenharmony_ci goto test_cleanup; 11613498266Sopenharmony_ci } 11713498266Sopenharmony_ci 11813498266Sopenharmony_ci test_setopt(curl, CURLOPT_URL, URL); 11913498266Sopenharmony_ci test_setopt(curl, CURLOPT_VERBOSE, 1L); 12013498266Sopenharmony_ci test_setopt(curl, CURLOPT_NOBODY, 1L); 12113498266Sopenharmony_ci test_setopt(curl, CURLOPT_FTP_FILEMETHOD, (long) CURLFTPMETHOD_NOCWD); 12213498266Sopenharmony_ci test_setopt(curl, CURLOPT_QUOTE, slist); 12313498266Sopenharmony_ci res = curl_easy_perform(curl); 12413498266Sopenharmony_ci if(res) 12513498266Sopenharmony_ci goto test_cleanup; 12613498266Sopenharmony_ci 12713498266Sopenharmony_ci /* test: CURLFTPMETHOD_SINGLECWD with home-relative path should 12813498266Sopenharmony_ci not emit CWD for first FTP access after login */ 12913498266Sopenharmony_ci curl_easy_cleanup(curl); 13013498266Sopenharmony_ci curl = curl_easy_init(); 13113498266Sopenharmony_ci if(!curl) { 13213498266Sopenharmony_ci fprintf(stderr, "curl_easy_init() failed\n"); 13313498266Sopenharmony_ci res = TEST_ERR_MAJOR_BAD; 13413498266Sopenharmony_ci goto test_cleanup; 13513498266Sopenharmony_ci } 13613498266Sopenharmony_ci 13713498266Sopenharmony_ci test_setopt(curl, CURLOPT_URL, URL); 13813498266Sopenharmony_ci test_setopt(curl, CURLOPT_VERBOSE, 1L); 13913498266Sopenharmony_ci test_setopt(curl, CURLOPT_NOBODY, 1L); 14013498266Sopenharmony_ci test_setopt(curl, CURLOPT_FTP_FILEMETHOD, (long) CURLFTPMETHOD_SINGLECWD); 14113498266Sopenharmony_ci test_setopt(curl, CURLOPT_QUOTE, slist); 14213498266Sopenharmony_ci res = curl_easy_perform(curl); 14313498266Sopenharmony_ci if(res) 14413498266Sopenharmony_ci goto test_cleanup; 14513498266Sopenharmony_ci 14613498266Sopenharmony_ci /* test: CURLFTPMETHOD_NOCWD with home-relative path should 14713498266Sopenharmony_ci not emit CWD for second FTP access when not needed + 14813498266Sopenharmony_ci bonus: see if path buffering survives curl_easy_reset() */ 14913498266Sopenharmony_ci curl_easy_reset(curl); 15013498266Sopenharmony_ci test_setopt(curl, CURLOPT_URL, URL); 15113498266Sopenharmony_ci test_setopt(curl, CURLOPT_VERBOSE, 1L); 15213498266Sopenharmony_ci test_setopt(curl, CURLOPT_NOBODY, 1L); 15313498266Sopenharmony_ci test_setopt(curl, CURLOPT_FTP_FILEMETHOD, (long) CURLFTPMETHOD_NOCWD); 15413498266Sopenharmony_ci test_setopt(curl, CURLOPT_QUOTE, slist); 15513498266Sopenharmony_ci res = curl_easy_perform(curl); 15613498266Sopenharmony_ci 15713498266Sopenharmony_ci 15813498266Sopenharmony_citest_cleanup: 15913498266Sopenharmony_ci 16013498266Sopenharmony_ci if(res) 16113498266Sopenharmony_ci fprintf(stderr, "test encountered error %d\n", res); 16213498266Sopenharmony_ci curl_slist_free_all(slist); 16313498266Sopenharmony_ci curl_free(newURL); 16413498266Sopenharmony_ci curl_easy_cleanup(curl); 16513498266Sopenharmony_ci curl_global_cleanup(); 16613498266Sopenharmony_ci 16713498266Sopenharmony_ci return (int)res; 16813498266Sopenharmony_ci} 169