From fdecb56cbfcafe5b770c4181133655b89973f41e Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Mon, 19 Sep 2011 18:18:17 +0200 Subject: curl tool: reviewed code moved to tool_*.[ch] files --- src/tool_doswin.c | 202 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 202 insertions(+) create mode 100644 src/tool_doswin.c (limited to 'src/tool_doswin.c') diff --git a/src/tool_doswin.c b/src/tool_doswin.c new file mode 100644 index 000000000..2b900e161 --- /dev/null +++ b/src/tool_doswin.c @@ -0,0 +1,202 @@ +/*************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * Copyright (C) 1998 - 2011, Daniel Stenberg, , 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 http://curl.haxx.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 "setup.h" + +#if defined(MSDOS) || defined(WIN32) + +#if defined(HAVE_LIBGEN_H) && defined(HAVE_BASENAME) +# include +#endif + +#include "tool_bname.h" +#include "tool_doswin.h" + +#include "memdebug.h" /* keep this as LAST include */ + +#ifdef WIN32 +# undef PATH_MAX +# define PATH_MAX MAX_PATH +#endif + +#ifndef S_ISCHR +# ifdef S_IFCHR +# define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR) +# else +# define S_ISCHR(m) (0) /* cannot tell if file is a device */ +# endif +#endif + +#ifdef WIN32 +# define _use_lfn(f) (0, 1) /* long file names always available */ +#elif !defined(__DJGPP__) || (__DJGPP__ < 2) /* DJGPP 2.0 has _use_lfn() */ +# define _use_lfn(f) (1, 0) /* long file names never available */ +#endif + +static const char *msdosify (const char *file_name); +static char *rename_if_dos_device_name (char *file_name); + +/* + * sanitize_dos_name: returns a newly allocated string holding a + * valid file name which will be a transformation of given argument + * in case this wasn't already a valid file name. + * + * This function takes ownership of given argument, free'ing it before + * returning. Caller is responsible of free'ing returned string. Upon + * out of memory condition function returns NULL. + */ + +char *sanitize_dos_name(char *file_name) +{ + char new_name[PATH_MAX]; + + if(!file_name) + return NULL; + + if(strlen(file_name) >= PATH_MAX) + file_name[PATH_MAX-1] = '\0'; /* truncate it */ + + strcpy(new_name, msdosify(file_name)); + + free(file_name); + + return strdup(rename_if_dos_device_name(new_name)); +} + +/* The following functions are taken with modification from the DJGPP + * port of tar 1.12. They use algorithms originally from DJTAR. */ + +static const char *msdosify (const char *file_name) +{ + static char dos_name[PATH_MAX]; + static const char illegal_chars_dos[] = ".+, ;=[]" /* illegal in DOS */ + "|<>\\\":?*"; /* illegal in DOS & W95 */ + static const char *illegal_chars_w95 = &illegal_chars_dos[8]; + int idx, dot_idx; + const char *s = file_name; + char *d = dos_name; + const char *const dlimit = dos_name + sizeof(dos_name) - 1; + const char *illegal_aliens = illegal_chars_dos; + size_t len = sizeof(illegal_chars_dos) - 1; + + /* Support for Windows 9X VFAT systems, when available. */ + if(_use_lfn(file_name)) { + illegal_aliens = illegal_chars_w95; + len -= (illegal_chars_w95 - illegal_chars_dos); + } + + /* Get past the drive letter, if any. */ + if(s[0] >= 'A' && s[0] <= 'z' && s[1] == ':') { + *d++ = *s++; + *d++ = *s++; + } + + for(idx = 0, dot_idx = -1; *s && d < dlimit; s++, d++) { + if(memchr(illegal_aliens, *s, len)) { + /* Dots are special: DOS doesn't allow them as the leading character, + and a file name cannot have more than a single dot. We leave the + first non-leading dot alone, unless it comes too close to the + beginning of the name: we want sh.lex.c to become sh_lex.c, not + sh.lex-c. */ + if(*s == '.') { + if(idx == 0 && (s[1] == '/' || (s[1] == '.' && s[2] == '/'))) { + /* Copy "./" and "../" verbatim. */ + *d++ = *s++; + if(*s == '.') + *d++ = *s++; + *d = *s; + } + else if(idx == 0) + *d = '_'; + else if(dot_idx >= 0) { + if(dot_idx < 5) { /* 5 is a heuristic ad-hoc'ery */ + d[dot_idx - idx] = '_'; /* replace previous dot */ + *d = '.'; + } + else + *d = '-'; + } + else + *d = '.'; + + if(*s == '.') + dot_idx = idx; + } + else if(*s == '+' && s[1] == '+') { + if(idx - 2 == dot_idx) { /* .c++, .h++ etc. */ + *d++ = 'x'; + *d = 'x'; + } + else { + /* libg++ etc. */ + memcpy (d, "plus", 4); + d += 3; + } + s++; + idx++; + } + else + *d = '_'; + } + else + *d = *s; + if(*s == '/') { + idx = 0; + dot_idx = -1; + } + else + idx++; + } + + *d = '\0'; + return dos_name; +} + +static char *rename_if_dos_device_name (char *file_name) +{ + /* We could have a file whose name is a device on MS-DOS. Trying to + * retrieve such a file would fail at best and wedge us at worst. We need + * to rename such files. */ + char *base; + struct_stat st_buf; + char fname[PATH_MAX]; + + strncpy(fname, file_name, PATH_MAX-1); + fname[PATH_MAX-1] = '\0'; + base = basename(fname); + if(((stat(base, &st_buf)) == 0) && (S_ISCHR(st_buf.st_mode))) { + size_t blen = strlen(base); + + if(strlen(fname) >= PATH_MAX-1) { + /* Make room for the '_' */ + blen--; + base[blen] = '\0'; + } + /* Prepend a '_'. */ + memmove(base + 1, base, blen + 1); + base[0] = '_'; + strcpy(file_name, fname); + } + return file_name; +} + +#endif /* MSDOS || WIN32 */ + -- cgit v1.2.1 From 57119495daf2873f7396a718de3bfe97cdaa11e1 Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Mon, 19 Sep 2011 19:45:58 +0200 Subject: curl tool: fix compiler warning --- src/tool_doswin.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'src/tool_doswin.c') diff --git a/src/tool_doswin.c b/src/tool_doswin.c index 2b900e161..f3ac21141 100644 --- a/src/tool_doswin.c +++ b/src/tool_doswin.c @@ -32,6 +32,33 @@ #include "memdebug.h" /* keep this as LAST include */ +/* + * Macros ALWAYS_TRUE and ALWAYS_FALSE are used to avoid compiler warnings. + */ + +#define ALWAYS_TRUE (1) +#define ALWAYS_FALSE (0) + +#if defined(_MSC_VER) && !defined(__POCC__) +# undef ALWAYS_TRUE +# undef ALWAYS_FALSE +# if (_MSC_VER < 1500) +# define ALWAYS_TRUE (0, 1) +# define ALWAYS_FALSE (1, 0) +# else +# define ALWAYS_TRUE \ +__pragma(warning(push)) \ +__pragma(warning(disable:4127)) \ +(1) \ +__pragma(warning(pop)) +# define ALWAYS_FALSE \ +__pragma(warning(push)) \ +__pragma(warning(disable:4127)) \ +(0) \ +__pragma(warning(pop)) +# endif +#endif + #ifdef WIN32 # undef PATH_MAX # define PATH_MAX MAX_PATH -- cgit v1.2.1 From 49c35a7f9f90cd02e0e79965cfa6e1df0797bec0 Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Mon, 19 Sep 2011 20:27:25 +0200 Subject: curl tool: truly fix compiler warning --- src/tool_doswin.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/tool_doswin.c') diff --git a/src/tool_doswin.c b/src/tool_doswin.c index f3ac21141..dc9062798 100644 --- a/src/tool_doswin.c +++ b/src/tool_doswin.c @@ -73,9 +73,9 @@ __pragma(warning(pop)) #endif #ifdef WIN32 -# define _use_lfn(f) (0, 1) /* long file names always available */ +# define _use_lfn(f) ALWAYS_TRUE /* long file names always available */ #elif !defined(__DJGPP__) || (__DJGPP__ < 2) /* DJGPP 2.0 has _use_lfn() */ -# define _use_lfn(f) (1, 0) /* long file names never available */ +# define _use_lfn(f) ALWAYS_FALSE /* long file names never available */ #endif static const char *msdosify (const char *file_name); -- cgit v1.2.1 From 84221006c9acf2b97a80564364df22e03184a1d8 Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Tue, 20 Sep 2011 15:58:35 +0200 Subject: curl tool: reviewed code moved to tool_*.[ch] files Overhauled FindWin32CACert() --- src/tool_doswin.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) (limited to 'src/tool_doswin.c') diff --git a/src/tool_doswin.c b/src/tool_doswin.c index dc9062798..7fab33b80 100644 --- a/src/tool_doswin.c +++ b/src/tool_doswin.c @@ -27,6 +27,11 @@ # include #endif +#ifdef WIN32 +# include +# include "tool_cfgable.h" +#endif + #include "tool_bname.h" #include "tool_doswin.h" @@ -225,5 +230,59 @@ static char *rename_if_dos_device_name (char *file_name) return file_name; } +#ifdef WIN32 + +/* + * Function to find CACert bundle on a Win32 platform using SearchPath. + * (SearchPath is already declared via inclusions done in setup header file) + * (Use the ASCII version instead of the unicode one!) + * The order of the directories it searches is: + * 1. application's directory + * 2. current working directory + * 3. Windows System directory (e.g. C:\windows\system32) + * 4. Windows Directory (e.g. C:\windows) + * 5. all directories along %PATH% + * + * For WinXP and later search order actually depends on registry value: + * HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\SafeProcessSearchMode + */ + +CURLcode FindWin32CACert(struct Configurable *config, const char *bundle_file) +{ + CURLcode result = CURLE_OK; + + curl_version_info_data *info = curl_version_info(CURLVERSION_NOW); + + /* search and set cert file only if "we" support SSL */ + if(info->features & CURL_VERSION_SSL) { + + DWORD res_len; + DWORD buf_tchar_size = PATH_MAX + 1; + DWORD buf_bytes_size = sizeof(TCHAR) * buf_tchar_size; + char *ptr = NULL; + + char *buf = malloc(buf_bytes_size); + if(!buf) + return CURLE_OUT_OF_MEMORY; + buf[0] = '\0'; + + res_len = SearchPathA(NULL, bundle_file, NULL, buf_tchar_size, buf, &ptr); + if(res_len > 0) { + Curl_safefree(config->cacert); + config->cacert = strdup(buf); + if(!config->cacert) + result = CURLE_OUT_OF_MEMORY; + } + else + result = CURLE_SSL_CACERT; + + free(buf); + } + + return result; +} + +#endif /* WIN32 */ + #endif /* MSDOS || WIN32 */ -- cgit v1.2.1 From fb3845a438cad9ef09eb1b0b86388ce99a726502 Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Thu, 22 Sep 2011 11:16:34 +0200 Subject: curl tool: reviewed code moved to tool_*.[ch] files my_setopt and my_setopt_str no longer ignores curl_easy_setopt result. Fixed some OOM handling issues. --- src/tool_doswin.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'src/tool_doswin.c') diff --git a/src/tool_doswin.c b/src/tool_doswin.c index 7fab33b80..5250b2cee 100644 --- a/src/tool_doswin.c +++ b/src/tool_doswin.c @@ -30,6 +30,7 @@ #ifdef WIN32 # include # include "tool_cfgable.h" +# include "tool_libinfo.h" #endif #include "tool_bname.h" @@ -251,10 +252,8 @@ CURLcode FindWin32CACert(struct Configurable *config, const char *bundle_file) { CURLcode result = CURLE_OK; - curl_version_info_data *info = curl_version_info(CURLVERSION_NOW); - - /* search and set cert file only if "we" support SSL */ - if(info->features & CURL_VERSION_SSL) { + /* search and set cert file only if libcurl supports SSL */ + if(curlinfo->features & CURL_VERSION_SSL) { DWORD res_len; DWORD buf_tchar_size = PATH_MAX + 1; -- cgit v1.2.1 From 49b79b76316248d5233d08006234933913faaa3b Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Wed, 5 Oct 2011 00:03:20 +0200 Subject: curl tool: code moved to tool_*.[ch] files --- src/tool_doswin.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/tool_doswin.c') diff --git a/src/tool_doswin.c b/src/tool_doswin.c index 5250b2cee..b45522b53 100644 --- a/src/tool_doswin.c +++ b/src/tool_doswin.c @@ -231,6 +231,19 @@ static char *rename_if_dos_device_name (char *file_name) return file_name; } +#if defined(MSDOS) && (defined(__DJGPP__) || defined(__GO32__)) + +/* + * Disable program default argument globbing. We do it on our own. + */ +char **__crt0_glob_function(char *arg) +{ + (void)arg; + return (char**)0; +} + +#endif /* MSDOS && (__DJGPP__ || __GO32__) */ + #ifdef WIN32 /* -- cgit v1.2.1 From 17f48fe87979f159e2d8769d678641c60f4c0eed Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Fri, 7 Oct 2011 20:50:57 +0200 Subject: libcurl: some OOM handling fixes --- src/tool_doswin.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/tool_doswin.c') diff --git a/src/tool_doswin.c b/src/tool_doswin.c index b45522b53..b23b50af1 100644 --- a/src/tool_doswin.c +++ b/src/tool_doswin.c @@ -109,7 +109,7 @@ char *sanitize_dos_name(char *file_name) strcpy(new_name, msdosify(file_name)); - free(file_name); + Curl_safefree(file_name); return strdup(rename_if_dos_device_name(new_name)); } @@ -288,7 +288,7 @@ CURLcode FindWin32CACert(struct Configurable *config, const char *bundle_file) else result = CURLE_SSL_CACERT; - free(buf); + Curl_safefree(buf); } return result; -- cgit v1.2.1 From b9660dc4b290781ff6535dec32258ec14e6ff0b5 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 17 Nov 2011 18:03:21 +0100 Subject: FindWin32CACert: return OK even if CA cert isn't found Bug: http://curl.haxx.se/mail/lib-2011-11/0180.html Reported by: Mark Brand --- src/tool_doswin.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'src/tool_doswin.c') diff --git a/src/tool_doswin.c b/src/tool_doswin.c index b23b50af1..ef3899ee9 100644 --- a/src/tool_doswin.c +++ b/src/tool_doswin.c @@ -285,8 +285,6 @@ CURLcode FindWin32CACert(struct Configurable *config, const char *bundle_file) if(!config->cacert) result = CURLE_OUT_OF_MEMORY; } - else - result = CURLE_SSL_CACERT; Curl_safefree(buf); } -- cgit v1.2.1 From 919c97fa65a5c00f7044e849eeb0095408413505 Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Fri, 6 Apr 2012 23:35:15 +0200 Subject: curl tool: use configuration files from lib directory Configuration files such as curl_config.h and all config-*.h no longer exist nor are generated/copied into 'src' directory, now these only exist in 'lib' directory from where curl tool sources uses them. Additionally old src/setup.h has been refactored into src/tool_setup.h which now pulls lib/setup.h The possibility of a makefile needing an include path adjustment exists. --- src/tool_doswin.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/tool_doswin.c') diff --git a/src/tool_doswin.c b/src/tool_doswin.c index ef3899ee9..02957dbb9 100644 --- a/src/tool_doswin.c +++ b/src/tool_doswin.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2011, Daniel Stenberg, , et al. + * Copyright (C) 1998 - 2012, Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms @@ -19,7 +19,7 @@ * KIND, either express or implied. * ***************************************************************************/ -#include "setup.h" +#include "tool_setup.h" #if defined(MSDOS) || defined(WIN32) -- cgit v1.2.1 From 01b0f1061da2bd7a8703f4c8aa846a9088d7ab3e Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Sun, 8 Apr 2012 13:50:18 +0200 Subject: curl tool: make curl.h first header included in tool_setup.h --- src/tool_doswin.c | 1 - 1 file changed, 1 deletion(-) (limited to 'src/tool_doswin.c') diff --git a/src/tool_doswin.c b/src/tool_doswin.c index 02957dbb9..c1ba48ea9 100644 --- a/src/tool_doswin.c +++ b/src/tool_doswin.c @@ -28,7 +28,6 @@ #endif #ifdef WIN32 -# include # include "tool_cfgable.h" # include "tool_libinfo.h" #endif -- cgit v1.2.1 From 08e0ad7b3974811127f7d61c016fee540f91d343 Mon Sep 17 00:00:00 2001 From: Gisle Vanem Date: Wed, 20 Jun 2012 23:40:42 +0200 Subject: tool_doswin.c: fix djgpp function _use_lfn() used without a prototype http://curl.haxx.se/mail/archive-2012-06/0028.html --- src/tool_doswin.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/tool_doswin.c') diff --git a/src/tool_doswin.c b/src/tool_doswin.c index c1ba48ea9..4fae91d32 100644 --- a/src/tool_doswin.c +++ b/src/tool_doswin.c @@ -81,6 +81,8 @@ __pragma(warning(pop)) # define _use_lfn(f) ALWAYS_TRUE /* long file names always available */ #elif !defined(__DJGPP__) || (__DJGPP__ < 2) /* DJGPP 2.0 has _use_lfn() */ # define _use_lfn(f) ALWAYS_FALSE /* long file names never available */ +#elif defined(__DJGPP__) +# include /* _use_lfn(f) prototype */ #endif static const char *msdosify (const char *file_name); -- cgit v1.2.1