mirror of
https://github.com/moparisthebest/curl
synced 2024-08-13 17:03:50 -04:00
curl tool: reviewed code moved to tool_*.[ch] files
Overhauled FindWin32CACert()
This commit is contained in:
parent
a6c168b893
commit
84221006c9
@ -11,7 +11,8 @@ SOURCE \
|
|||||||
main.c hugehelp.c urlglob.c writeout.c writeenv.c \
|
main.c hugehelp.c urlglob.c writeout.c writeenv.c \
|
||||||
getpass.c homedir.c curlutil.c xattr.c \
|
getpass.c homedir.c curlutil.c xattr.c \
|
||||||
tool_bname.c tool_cfgable.c tool_convert.c tool_dirhie.c \
|
tool_bname.c tool_cfgable.c tool_convert.c tool_dirhie.c \
|
||||||
tool_doswin.c tool_mfiles.c tool_myfunc.c tool_vms.c
|
tool_doswin.c tool_mfiles.c tool_msgs.c tool_myfunc.c \
|
||||||
|
tool_vms.c
|
||||||
|
|
||||||
SOURCEPATH ../../../lib
|
SOURCEPATH ../../../lib
|
||||||
SOURCE \
|
SOURCE \
|
||||||
|
@ -17,13 +17,15 @@ CURLX_ONES = $(top_srcdir)/lib/strtoofft.c \
|
|||||||
CURL_CFILES = main.c hugehelp.c urlglob.c writeout.c writeenv.c \
|
CURL_CFILES = main.c hugehelp.c urlglob.c writeout.c writeenv.c \
|
||||||
getpass.c homedir.c curlutil.c xattr.c \
|
getpass.c homedir.c curlutil.c xattr.c \
|
||||||
tool_bname.c tool_cfgable.c tool_convert.c tool_dirhie.c \
|
tool_bname.c tool_cfgable.c tool_convert.c tool_dirhie.c \
|
||||||
tool_doswin.c tool_mfiles.c tool_myfunc.c tool_vms.c
|
tool_doswin.c tool_mfiles.c tool_msgs.c tool_myfunc.c \
|
||||||
|
tool_vms.c
|
||||||
|
|
||||||
CURL_HFILES = hugehelp.h setup.h config-win32.h config-mac.h \
|
CURL_HFILES = hugehelp.h setup.h config-win32.h config-mac.h \
|
||||||
config-riscos.h urlglob.h version.h xattr.h \
|
config-riscos.h urlglob.h version.h xattr.h \
|
||||||
writeout.h writeenv.h getpass.h homedir.h curlutil.h \
|
writeout.h writeenv.h getpass.h homedir.h curlutil.h \
|
||||||
tool_bname.h tool_cfgable.h tool_convert.h tool_dirhie.h \
|
tool_bname.h tool_cfgable.h tool_convert.h tool_dirhie.h \
|
||||||
tool_doswin.h tool_mfiles.h tool_myfunc.h tool_vms.h
|
tool_doswin.h tool_mfiles.h tool_msgs.h tool_myfunc.h \
|
||||||
|
tool_sdecls.h tool_vms.h
|
||||||
|
|
||||||
curl_SOURCES = $(CURL_CFILES) $(CURLX_ONES) $(CURL_HFILES)
|
curl_SOURCES = $(CURL_CFILES) $(CURLX_ONES) $(CURL_HFILES)
|
||||||
|
|
||||||
|
@ -121,7 +121,7 @@ RCD = rc.exe /dDEBUGBUILD=1
|
|||||||
|
|
||||||
CFLAGS = /I../lib /I../include /nologo /W3 /GX /DWIN32 /YX /FD /c /D_BIND_TO_CURRENT_VCLIBS_VERSION=1
|
CFLAGS = /I../lib /I../include /nologo /W3 /GX /DWIN32 /YX /FD /c /D_BIND_TO_CURRENT_VCLIBS_VERSION=1
|
||||||
LFLAGS = /nologo /out:$(PROGRAM_NAME) /subsystem:console /machine:$(MACHINE)
|
LFLAGS = /nologo /out:$(PROGRAM_NAME) /subsystem:console /machine:$(MACHINE)
|
||||||
RESFLAGS = /i../lib /i../include
|
RESFLAGS = /i../include
|
||||||
|
|
||||||
# This manifest thing is for VC8, enabled by the maketgz script that
|
# This manifest thing is for VC8, enabled by the maketgz script that
|
||||||
# builds the VC8 version of this makefile. Left commented out in the VC6
|
# builds the VC8 version of this makefile. Left commented out in the VC6
|
||||||
@ -147,6 +147,7 @@ RELEASE_OBJS= \
|
|||||||
tool_dirhier.obj \
|
tool_dirhier.obj \
|
||||||
tool_doswinr.obj \
|
tool_doswinr.obj \
|
||||||
tool_mfilesr.obj \
|
tool_mfilesr.obj \
|
||||||
|
tool_msgsr.obj \
|
||||||
tool_myfuncr.obj \
|
tool_myfuncr.obj \
|
||||||
tool_vmsr.obj \
|
tool_vmsr.obj \
|
||||||
urlglobr.obj \
|
urlglobr.obj \
|
||||||
@ -169,6 +170,7 @@ DEBUG_OBJS= \
|
|||||||
tool_dirhied.obj \
|
tool_dirhied.obj \
|
||||||
tool_doswind.obj \
|
tool_doswind.obj \
|
||||||
tool_mfilesd.obj \
|
tool_mfilesd.obj \
|
||||||
|
tool_msgsd.obj \
|
||||||
tool_myfuncd.obj \
|
tool_myfuncd.obj \
|
||||||
tool_vmsd.obj \
|
tool_vmsd.obj \
|
||||||
urlglobd.obj \
|
urlglobd.obj \
|
||||||
@ -326,6 +328,8 @@ tool_doswinr.obj: tool_doswin.c
|
|||||||
$(CCR) $(CFLAGS) /Fo"$@" tool_doswin.c
|
$(CCR) $(CFLAGS) /Fo"$@" tool_doswin.c
|
||||||
tool_mfilesr.obj: tool_mfiles.c
|
tool_mfilesr.obj: tool_mfiles.c
|
||||||
$(CCR) $(CFLAGS) /Fo"$@" tool_mfiles.c
|
$(CCR) $(CFLAGS) /Fo"$@" tool_mfiles.c
|
||||||
|
tool_msgsr.obj: tool_msgs.c
|
||||||
|
$(CCR) $(CFLAGS) /Fo"$@" tool_msgs.c
|
||||||
tool_myfuncr.obj: tool_myfunc.c
|
tool_myfuncr.obj: tool_myfunc.c
|
||||||
$(CCR) $(CFLAGS) /Fo"$@" tool_myfunc.c
|
$(CCR) $(CFLAGS) /Fo"$@" tool_myfunc.c
|
||||||
tool_vmsr.obj: tool_vms.c
|
tool_vmsr.obj: tool_vms.c
|
||||||
@ -368,6 +372,8 @@ tool_doswind.obj: tool_doswin.c
|
|||||||
$(CCD) $(CFLAGS) /Fo"$@" tool_doswin.c
|
$(CCD) $(CFLAGS) /Fo"$@" tool_doswin.c
|
||||||
tool_mfilesd.obj: tool_mfiles.c
|
tool_mfilesd.obj: tool_mfiles.c
|
||||||
$(CCD) $(CFLAGS) /Fo"$@" tool_mfiles.c
|
$(CCD) $(CFLAGS) /Fo"$@" tool_mfiles.c
|
||||||
|
tool_msgsd.obj: tool_msgs.c
|
||||||
|
$(CCD) $(CFLAGS) /Fo"$@" tool_msgs.c
|
||||||
tool_myfuncd.obj: tool_myfunc.c
|
tool_myfuncd.obj: tool_myfunc.c
|
||||||
$(CCD) $(CFLAGS) /Fo"$@" tool_myfunc.c
|
$(CCD) $(CFLAGS) /Fo"$@" tool_myfunc.c
|
||||||
tool_vmsd.obj: tool_vms.c
|
tool_vmsd.obj: tool_vms.c
|
||||||
|
107
src/main.c
107
src/main.c
@ -98,6 +98,7 @@
|
|||||||
#include "tool_dirhie.h"
|
#include "tool_dirhie.h"
|
||||||
#include "tool_doswin.h"
|
#include "tool_doswin.h"
|
||||||
#include "tool_mfiles.h"
|
#include "tool_mfiles.h"
|
||||||
|
#include "tool_msgs.h"
|
||||||
#include "tool_myfunc.h"
|
#include "tool_myfunc.h"
|
||||||
#include "tool_vms.h"
|
#include "tool_vms.h"
|
||||||
#ifdef USE_MANUAL
|
#ifdef USE_MANUAL
|
||||||
@ -266,49 +267,6 @@ static int ftruncate64(int fd, curl_off_t where)
|
|||||||
|
|
||||||
#endif /* WIN32 */
|
#endif /* WIN32 */
|
||||||
|
|
||||||
#define WARN_PREFIX "Warning: "
|
|
||||||
#define WARN_TEXTWIDTH (79 - (int)strlen(WARN_PREFIX))
|
|
||||||
/* produce this text message to the user unless mute was selected */
|
|
||||||
static void warnf(struct Configurable *config, const char *fmt, ...)
|
|
||||||
{
|
|
||||||
if(!config->mute) {
|
|
||||||
va_list ap;
|
|
||||||
int len;
|
|
||||||
char *ptr;
|
|
||||||
char print_buffer[256];
|
|
||||||
|
|
||||||
va_start(ap, fmt);
|
|
||||||
len = vsnprintf(print_buffer, sizeof(print_buffer), fmt, ap);
|
|
||||||
va_end(ap);
|
|
||||||
|
|
||||||
ptr = print_buffer;
|
|
||||||
while(len > 0) {
|
|
||||||
fputs(WARN_PREFIX, config->errors);
|
|
||||||
|
|
||||||
if(len > (int)WARN_TEXTWIDTH) {
|
|
||||||
int cut = WARN_TEXTWIDTH-1;
|
|
||||||
|
|
||||||
while(!ISSPACE(ptr[cut]) && cut) {
|
|
||||||
cut--;
|
|
||||||
}
|
|
||||||
if(0 == cut)
|
|
||||||
/* not a single cutting position was found, just cut it at the
|
|
||||||
max text width then! */
|
|
||||||
cut = WARN_TEXTWIDTH-1;
|
|
||||||
|
|
||||||
(void)fwrite(ptr, cut + 1, 1, config->errors);
|
|
||||||
fputs("\n", config->errors);
|
|
||||||
ptr += cut+1; /* skip the space too */
|
|
||||||
len -= cut;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
fputs(ptr, config->errors);
|
|
||||||
len = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This is the main global constructor for the app. Call this before
|
* This is the main global constructor for the app. Call this before
|
||||||
* _any_ libcurl usage. If this fails, *NO* libcurl functions may be
|
* _any_ libcurl usage. If this fails, *NO* libcurl functions may be
|
||||||
@ -346,22 +304,6 @@ static int SetHTTPrequest(struct Configurable *config,
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void helpf(FILE *errors, const char *fmt, ...)
|
|
||||||
{
|
|
||||||
va_list ap;
|
|
||||||
if(fmt) {
|
|
||||||
va_start(ap, fmt);
|
|
||||||
fputs("curl: ", errors); /* prefix it */
|
|
||||||
vfprintf(errors, fmt, ap);
|
|
||||||
va_end(ap);
|
|
||||||
}
|
|
||||||
fprintf(errors, "curl: try 'curl --help' "
|
|
||||||
#ifdef USE_MANUAL
|
|
||||||
"or 'curl --manual' "
|
|
||||||
#endif
|
|
||||||
"for more information\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
static void help(void)
|
static void help(void)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
@ -3169,11 +3111,6 @@ static size_t my_fwrite(void *buffer, size_t sz, size_t nmemb, void *stream)
|
|||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct InStruct {
|
|
||||||
int fd;
|
|
||||||
struct Configurable *config;
|
|
||||||
};
|
|
||||||
|
|
||||||
#define MAX_SEEK 2147483647
|
#define MAX_SEEK 2147483647
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -3588,39 +3525,6 @@ int my_trace(CURL *handle, curl_infotype type,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#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%
|
|
||||||
*/
|
|
||||||
static void FindWin32CACert(struct Configurable *config,
|
|
||||||
const char *bundle_file)
|
|
||||||
{
|
|
||||||
/* only check for cert file if "we" support SSL */
|
|
||||||
if(curlinfo->features & CURL_VERSION_SSL) {
|
|
||||||
DWORD buflen;
|
|
||||||
char *ptr = NULL;
|
|
||||||
char *retval = malloc(sizeof (TCHAR) * (MAX_PATH + 1));
|
|
||||||
if(!retval)
|
|
||||||
return;
|
|
||||||
retval[0] = '\0';
|
|
||||||
buflen = SearchPathA(NULL, bundle_file, NULL, MAX_PATH+2, retval, &ptr);
|
|
||||||
if(buflen > 0) {
|
|
||||||
GetStr(&config->cacert, retval);
|
|
||||||
}
|
|
||||||
Curl_safefree(retval);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define RETRY_SLEEP_DEFAULT 1000 /* ms */
|
#define RETRY_SLEEP_DEFAULT 1000 /* ms */
|
||||||
#define RETRY_SLEEP_MAX 600000 /* ms == 10 minutes */
|
#define RETRY_SLEEP_MAX 600000 /* ms == 10 minutes */
|
||||||
|
|
||||||
@ -4238,8 +4142,13 @@ operate(struct Configurable *config, int argc, argv_item_t argv[])
|
|||||||
if(env)
|
if(env)
|
||||||
curl_free(env);
|
curl_free(env);
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
else
|
else {
|
||||||
FindWin32CACert(config, "curl-ca-bundle.crt");
|
res = FindWin32CACert(config, "curl-ca-bundle.crt");
|
||||||
|
if(res) {
|
||||||
|
clean_getout(config);
|
||||||
|
goto quit_curl;
|
||||||
|
}
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,50 +23,7 @@
|
|||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
#include "setup.h"
|
#include "setup.h"
|
||||||
|
|
||||||
typedef enum {
|
#include "tool_sdecls.h"
|
||||||
HTTPREQ_UNSPEC,
|
|
||||||
HTTPREQ_GET,
|
|
||||||
HTTPREQ_HEAD,
|
|
||||||
HTTPREQ_POST,
|
|
||||||
HTTPREQ_SIMPLEPOST,
|
|
||||||
HTTPREQ_CUSTOM,
|
|
||||||
HTTPREQ_LAST
|
|
||||||
} HttpReq;
|
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
TRACE_NONE, /* no trace/verbose output at all */
|
|
||||||
TRACE_BIN, /* tcpdump inspired look */
|
|
||||||
TRACE_ASCII, /* like *BIN but without the hex output */
|
|
||||||
TRACE_PLAIN /* -v/--verbose type */
|
|
||||||
} trace;
|
|
||||||
|
|
||||||
struct OutStruct {
|
|
||||||
char *filename;
|
|
||||||
bool alloc_filename;
|
|
||||||
FILE *stream;
|
|
||||||
struct Configurable *config;
|
|
||||||
curl_off_t bytes; /* amount written so far */
|
|
||||||
curl_off_t init; /* original size (non-zero when appending) */
|
|
||||||
};
|
|
||||||
|
|
||||||
/*
|
|
||||||
* A chain of these 'getout' nodes contain URL's to fetch and where to
|
|
||||||
* place URL's contents.
|
|
||||||
*/
|
|
||||||
|
|
||||||
struct getout {
|
|
||||||
struct getout *next; /* next one */
|
|
||||||
char *url; /* the URL we deal with */
|
|
||||||
char *outfile; /* where to store the output */
|
|
||||||
char *infile; /* file to upload, if GETOUT_UPLOAD is set */
|
|
||||||
int flags; /* options - composed of GETOUT_* bits */
|
|
||||||
};
|
|
||||||
|
|
||||||
#define GETOUT_OUTFILE (1<<0) /* set when outfile is deemed done */
|
|
||||||
#define GETOUT_URL (1<<1) /* set when URL is deemed done */
|
|
||||||
#define GETOUT_USEREMOTE (1<<2) /* use remote file name locally */
|
|
||||||
#define GETOUT_UPLOAD (1<<3) /* if set, -T has been used */
|
|
||||||
#define GETOUT_NOUPLOAD (1<<4) /* if set, -T "" has been used */
|
|
||||||
|
|
||||||
struct Configurable {
|
struct Configurable {
|
||||||
CURL *easy; /* once we have one, we keep it here */
|
CURL *easy; /* once we have one, we keep it here */
|
||||||
@ -120,7 +77,7 @@ struct Configurable {
|
|||||||
struct curl_slist *mail_rcpt;
|
struct curl_slist *mail_rcpt;
|
||||||
bool proxytunnel;
|
bool proxytunnel;
|
||||||
bool ftp_append; /* APPE on ftp */
|
bool ftp_append; /* APPE on ftp */
|
||||||
bool mute; /* shutup */
|
bool mute; /* don't show messages, --silent given */
|
||||||
bool use_ascii; /* select ascii or text transfer */
|
bool use_ascii; /* select ascii or text transfer */
|
||||||
bool autoreferer; /* automatically set referer */
|
bool autoreferer; /* automatically set referer */
|
||||||
bool failonerror; /* fail on (HTTP) errors */
|
bool failonerror; /* fail on (HTTP) errors */
|
||||||
@ -178,8 +135,8 @@ struct Configurable {
|
|||||||
bool proxyanyauth;
|
bool proxyanyauth;
|
||||||
char *writeout; /* %-styled format string to output */
|
char *writeout; /* %-styled format string to output */
|
||||||
bool writeenv; /* write results to environment, if available */
|
bool writeenv; /* write results to environment, if available */
|
||||||
FILE *errors; /* if stderr redirect is requested */
|
FILE *errors; /* errors stream, defaults to stderr */
|
||||||
bool errors_fopened;
|
bool errors_fopened; /* whether errors stream isn't stderr */
|
||||||
struct curl_slist *quote;
|
struct curl_slist *quote;
|
||||||
struct curl_slist *postquote;
|
struct curl_slist *postquote;
|
||||||
struct curl_slist *prequote;
|
struct curl_slist *prequote;
|
||||||
|
@ -27,6 +27,11 @@
|
|||||||
# include <libgen.h>
|
# include <libgen.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef WIN32
|
||||||
|
# include <curl/curl.h>
|
||||||
|
# include "tool_cfgable.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "tool_bname.h"
|
#include "tool_bname.h"
|
||||||
#include "tool_doswin.h"
|
#include "tool_doswin.h"
|
||||||
|
|
||||||
@ -225,5 +230,59 @@ static char *rename_if_dos_device_name (char *file_name)
|
|||||||
return 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 */
|
#endif /* MSDOS || WIN32 */
|
||||||
|
|
||||||
|
@ -27,6 +27,12 @@
|
|||||||
|
|
||||||
char *sanitize_dos_name(char *file_name);
|
char *sanitize_dos_name(char *file_name);
|
||||||
|
|
||||||
|
#ifdef WIN32
|
||||||
|
|
||||||
|
CURLcode FindWin32CACert(struct Configurable *config, const char *bundle_file);
|
||||||
|
|
||||||
|
#endif /* WIN32 */
|
||||||
|
|
||||||
#endif /* MSDOS || WIN32 */
|
#endif /* MSDOS || WIN32 */
|
||||||
|
|
||||||
#endif /* HEADER_CURL_TOOL_DOSWIN_H */
|
#endif /* HEADER_CURL_TOOL_DOSWIN_H */
|
||||||
|
100
src/tool_msgs.c
Normal file
100
src/tool_msgs.c
Normal file
@ -0,0 +1,100 @@
|
|||||||
|
/***************************************************************************
|
||||||
|
* _ _ ____ _
|
||||||
|
* Project ___| | | | _ \| |
|
||||||
|
* / __| | | | |_) | |
|
||||||
|
* | (__| |_| | _ <| |___
|
||||||
|
* \___|\___/|_| \_\_____|
|
||||||
|
*
|
||||||
|
* Copyright (C) 1998 - 2011, 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 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"
|
||||||
|
|
||||||
|
#define ENABLE_CURLX_PRINTF
|
||||||
|
/* use our own printf() functions */
|
||||||
|
#include "curlx.h"
|
||||||
|
|
||||||
|
#include "tool_cfgable.h"
|
||||||
|
#include "tool_msgs.h"
|
||||||
|
|
||||||
|
#include "memdebug.h" /* keep this as LAST include */
|
||||||
|
|
||||||
|
#define WARN_PREFIX "Warning: "
|
||||||
|
#define WARN_TEXTWIDTH (79 - (int)strlen(WARN_PREFIX))
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Emit warning formatted message on configured 'errors' stream unless
|
||||||
|
* mute (--silent) was selected.
|
||||||
|
*/
|
||||||
|
|
||||||
|
void warnf(struct Configurable *config, const char *fmt, ...)
|
||||||
|
{
|
||||||
|
if(!config->mute) {
|
||||||
|
va_list ap;
|
||||||
|
int len;
|
||||||
|
char *ptr;
|
||||||
|
char print_buffer[256];
|
||||||
|
|
||||||
|
va_start(ap, fmt);
|
||||||
|
len = vsnprintf(print_buffer, sizeof(print_buffer), fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
|
||||||
|
ptr = print_buffer;
|
||||||
|
while(len > 0) {
|
||||||
|
fputs(WARN_PREFIX, config->errors);
|
||||||
|
|
||||||
|
if(len > (int)WARN_TEXTWIDTH) {
|
||||||
|
int cut = WARN_TEXTWIDTH-1;
|
||||||
|
|
||||||
|
while(!ISSPACE(ptr[cut]) && cut) {
|
||||||
|
cut--;
|
||||||
|
}
|
||||||
|
if(0 == cut)
|
||||||
|
/* not a single cutting position was found, just cut it at the
|
||||||
|
max text width then! */
|
||||||
|
cut = WARN_TEXTWIDTH-1;
|
||||||
|
|
||||||
|
(void)fwrite(ptr, cut + 1, 1, config->errors);
|
||||||
|
fputs("\n", config->errors);
|
||||||
|
ptr += cut+1; /* skip the space too */
|
||||||
|
len -= cut;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
fputs(ptr, config->errors);
|
||||||
|
len = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Emit help formatted message on given stream.
|
||||||
|
*/
|
||||||
|
|
||||||
|
void helpf(FILE *errors, const char *fmt, ...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
if(fmt) {
|
||||||
|
va_start(ap, fmt);
|
||||||
|
fputs("curl: ", errors); /* prefix it */
|
||||||
|
vfprintf(errors, fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
}
|
||||||
|
fprintf(errors, "curl: try 'curl --help' "
|
||||||
|
#ifdef USE_MANUAL
|
||||||
|
"or 'curl --manual' "
|
||||||
|
#endif
|
||||||
|
"for more information\n");
|
||||||
|
}
|
||||||
|
|
31
src/tool_msgs.h
Normal file
31
src/tool_msgs.h
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
#ifndef HEADER_CURL_TOOL_MSGS_H
|
||||||
|
#define HEADER_CURL_TOOL_MSGS_H
|
||||||
|
/***************************************************************************
|
||||||
|
* _ _ ____ _
|
||||||
|
* Project ___| | | | _ \| |
|
||||||
|
* / __| | | | |_) | |
|
||||||
|
* | (__| |_| | _ <| |___
|
||||||
|
* \___|\___/|_| \_\_____|
|
||||||
|
*
|
||||||
|
* Copyright (C) 1998 - 2011, 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 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"
|
||||||
|
|
||||||
|
void warnf(struct Configurable *config, const char *fmt, ...);
|
||||||
|
|
||||||
|
void helpf(FILE *errors, const char *fmt, ...);
|
||||||
|
|
||||||
|
#endif /* HEADER_CURL_TOOL_MSGS_H */
|
||||||
|
|
128
src/tool_sdecls.h
Normal file
128
src/tool_sdecls.h
Normal file
@ -0,0 +1,128 @@
|
|||||||
|
#ifndef HEADER_CURL_TOOL_SDECLS_H
|
||||||
|
#define HEADER_CURL_TOOL_SDECLS_H
|
||||||
|
/***************************************************************************
|
||||||
|
* _ _ ____ _
|
||||||
|
* Project ___| | | | _ \| |
|
||||||
|
* / __| | | | |_) | |
|
||||||
|
* | (__| |_| | _ <| |___
|
||||||
|
* \___|\___/|_| \_\_____|
|
||||||
|
*
|
||||||
|
* Copyright (C) 1998 - 2011, 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 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"
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* OutStruct variables keep track of information relative to curl's
|
||||||
|
* output writing, which may take place to stdout or to some file.
|
||||||
|
*
|
||||||
|
* 'filename' member is a pointer to either a file name string or to
|
||||||
|
* string "-" to indicate that output is written to stdout.
|
||||||
|
*
|
||||||
|
* 'alloc_filename' member is TRUE when string pointed by 'filename' has been
|
||||||
|
* dynamically allocated and 'belongs' to this OutStruct, otherwise FALSE.
|
||||||
|
*
|
||||||
|
* 'stream' member is a pointer to a stream controlling object as returned
|
||||||
|
* from a 'fopen' call or stdout. When 'stdout' this shall not be closed.
|
||||||
|
*
|
||||||
|
* 'bytes' member represents amount written, and 'init' initial file size.
|
||||||
|
*/
|
||||||
|
|
||||||
|
struct OutStruct {
|
||||||
|
char *filename; /* pointer to file name or "-" string */
|
||||||
|
bool alloc_filename; /* allocated filename belongs to this */
|
||||||
|
FILE *stream; /* stdout or stream controlling object */
|
||||||
|
struct Configurable *config; /* pointer back to Configurable struct */
|
||||||
|
curl_off_t bytes; /* amount written so far */
|
||||||
|
curl_off_t init; /* original size (non-zero when appending) */
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* InStruct variables keep track of information relative to curl's
|
||||||
|
* input reading, which may take place from stdin or from some file.
|
||||||
|
*
|
||||||
|
* 'fd' member is either 'stdin' file descriptor number STDIN_FILENO
|
||||||
|
* or a file descriptor as returned from an 'open' call for some file.
|
||||||
|
*
|
||||||
|
* 'config' member is a pointer to associated 'Configurable' struct.
|
||||||
|
*
|
||||||
|
* TODO: evaluate if an additional struct member should be added to
|
||||||
|
* allow easier handling of 'stdin' vs other 'file' descriptors.
|
||||||
|
*/
|
||||||
|
|
||||||
|
struct InStruct {
|
||||||
|
int fd;
|
||||||
|
struct Configurable *config;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* A linked list of these 'getout' nodes contain URL's to fetch,
|
||||||
|
* as well as information relative to where URL contents should
|
||||||
|
* be stored or which file should be uploaded.
|
||||||
|
*/
|
||||||
|
|
||||||
|
struct getout {
|
||||||
|
struct getout *next; /* next one */
|
||||||
|
char *url; /* the URL we deal with */
|
||||||
|
char *outfile; /* where to store the output */
|
||||||
|
char *infile; /* file to upload, if GETOUT_UPLOAD is set */
|
||||||
|
int flags; /* options - composed of GETOUT_* bits */
|
||||||
|
};
|
||||||
|
|
||||||
|
#define GETOUT_OUTFILE (1<<0) /* set when outfile is deemed done */
|
||||||
|
#define GETOUT_URL (1<<1) /* set when URL is deemed done */
|
||||||
|
#define GETOUT_USEREMOTE (1<<2) /* use remote file name locally */
|
||||||
|
#define GETOUT_UPLOAD (1<<3) /* if set, -T has been used */
|
||||||
|
#define GETOUT_NOUPLOAD (1<<4) /* if set, -T "" has been used */
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 'trace' enumeration represents curl's output look'n feel possibilities.
|
||||||
|
*/
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
TRACE_NONE, /* no trace/verbose output at all */
|
||||||
|
TRACE_BIN, /* tcpdump inspired look */
|
||||||
|
TRACE_ASCII, /* like *BIN but without the hex output */
|
||||||
|
TRACE_PLAIN /* -v/--verbose type */
|
||||||
|
} trace;
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 'HttpReq' enumeration represents HTTP request types.
|
||||||
|
*/
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
HTTPREQ_UNSPEC, /* first in list */
|
||||||
|
HTTPREQ_GET,
|
||||||
|
HTTPREQ_HEAD,
|
||||||
|
HTTPREQ_POST,
|
||||||
|
HTTPREQ_SIMPLEPOST,
|
||||||
|
HTTPREQ_CUSTOM,
|
||||||
|
HTTPREQ_LAST /* last in list */
|
||||||
|
} HttpReq;
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Complete struct declarations which have Configurable struct members,
|
||||||
|
* just in case this header is directly included in some source file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "tool_cfgable.h"
|
||||||
|
|
||||||
|
#endif /* HEADER_CURL_TOOL_SDECLS_H */
|
||||||
|
|
@ -45,8 +45,8 @@ RSC=rc.exe
|
|||||||
# PROP Target_Dir ""
|
# PROP Target_Dir ""
|
||||||
# ADD BASE CPP /nologo /MDd /W3 /Gm /GX /Zi /Od /I "..\lib" /I "..\include" /I "." /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_CONSOLE" /FD /GZ /c
|
# ADD BASE CPP /nologo /MDd /W3 /Gm /GX /Zi /Od /I "..\lib" /I "..\include" /I "." /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_CONSOLE" /FD /GZ /c
|
||||||
# ADD CPP /nologo /MDd /W3 /Gm /GX /Zi /Od /I "..\lib" /I "..\include" /I "." /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_CONSOLE" /FD /GZ /c
|
# ADD CPP /nologo /MDd /W3 /Gm /GX /Zi /Od /I "..\lib" /I "..\include" /I "." /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_CONSOLE" /FD /GZ /c
|
||||||
# ADD BASE RSC /l 0x409 /i "..\lib" /i "..\include" /d "_DEBUG"
|
# ADD BASE RSC /l 0x409 /i "..\include" /d "_DEBUG"
|
||||||
# ADD RSC /l 0x409 /i "..\lib" /i "..\include" /d "_DEBUG"
|
# ADD RSC /l 0x409 /i "..\include" /d "_DEBUG"
|
||||||
BSC32=bscmake.exe
|
BSC32=bscmake.exe
|
||||||
# ADD BASE BSC32 /nologo
|
# ADD BASE BSC32 /nologo
|
||||||
# ADD BSC32 /nologo
|
# ADD BSC32 /nologo
|
||||||
@ -69,8 +69,8 @@ LINK32=link.exe
|
|||||||
# PROP Target_Dir ""
|
# PROP Target_Dir ""
|
||||||
# ADD BASE CPP /nologo /MD /W3 /GX /O2 /I "..\lib" /I "..\include" /I "." /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_CONSOLE" /FD /c
|
# ADD BASE CPP /nologo /MD /W3 /GX /O2 /I "..\lib" /I "..\include" /I "." /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_CONSOLE" /FD /c
|
||||||
# ADD CPP /nologo /MD /W3 /GX /O2 /I "..\lib" /I "..\include" /I "." /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_CONSOLE" /FD /c
|
# ADD CPP /nologo /MD /W3 /GX /O2 /I "..\lib" /I "..\include" /I "." /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_CONSOLE" /FD /c
|
||||||
# ADD BASE RSC /l 0x409 /i "..\lib" /i "..\include" /d "NDEBUG"
|
# ADD BASE RSC /l 0x409 /i "..\include" /d "NDEBUG"
|
||||||
# ADD RSC /l 0x409 /i "..\lib" /i "..\include" /d "NDEBUG"
|
# ADD RSC /l 0x409 /i "..\include" /d "NDEBUG"
|
||||||
BSC32=bscmake.exe
|
BSC32=bscmake.exe
|
||||||
# ADD BASE BSC32 /nologo
|
# ADD BASE BSC32 /nologo
|
||||||
# ADD BSC32 /nologo
|
# ADD BSC32 /nologo
|
||||||
@ -93,8 +93,8 @@ LINK32=link.exe
|
|||||||
# PROP Target_Dir ""
|
# PROP Target_Dir ""
|
||||||
# ADD BASE CPP /nologo /MDd /W3 /Gm /GX /Zi /Od /I "..\lib" /I "..\include" /I "." /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_CONSOLE" /D "CURL_STATICLIB" /FD /GZ /c
|
# ADD BASE CPP /nologo /MDd /W3 /Gm /GX /Zi /Od /I "..\lib" /I "..\include" /I "." /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_CONSOLE" /D "CURL_STATICLIB" /FD /GZ /c
|
||||||
# ADD CPP /nologo /MDd /W3 /Gm /GX /Zi /Od /I "..\lib" /I "..\include" /I "." /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_CONSOLE" /D "CURL_STATICLIB" /FD /GZ /c
|
# ADD CPP /nologo /MDd /W3 /Gm /GX /Zi /Od /I "..\lib" /I "..\include" /I "." /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_CONSOLE" /D "CURL_STATICLIB" /FD /GZ /c
|
||||||
# ADD BASE RSC /l 0x409 /i "..\lib" /i "..\include" /d "_DEBUG"
|
# ADD BASE RSC /l 0x409 /i "..\include" /d "_DEBUG"
|
||||||
# ADD RSC /l 0x409 /i "..\lib" /i "..\include" /d "_DEBUG"
|
# ADD RSC /l 0x409 /i "..\include" /d "_DEBUG"
|
||||||
BSC32=bscmake.exe
|
BSC32=bscmake.exe
|
||||||
# ADD BASE BSC32 /nologo
|
# ADD BASE BSC32 /nologo
|
||||||
# ADD BSC32 /nologo
|
# ADD BSC32 /nologo
|
||||||
@ -117,8 +117,8 @@ LINK32=link.exe
|
|||||||
# PROP Target_Dir ""
|
# PROP Target_Dir ""
|
||||||
# ADD BASE CPP /nologo /MD /W3 /GX /O2 /I "..\lib" /I "..\include" /I "." /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_CONSOLE" /D "CURL_STATICLIB" /FD /c
|
# ADD BASE CPP /nologo /MD /W3 /GX /O2 /I "..\lib" /I "..\include" /I "." /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_CONSOLE" /D "CURL_STATICLIB" /FD /c
|
||||||
# ADD CPP /nologo /MD /W3 /GX /O2 /I "..\lib" /I "..\include" /I "." /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_CONSOLE" /D "CURL_STATICLIB" /FD /c
|
# ADD CPP /nologo /MD /W3 /GX /O2 /I "..\lib" /I "..\include" /I "." /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_CONSOLE" /D "CURL_STATICLIB" /FD /c
|
||||||
# ADD BASE RSC /l 0x409 /i "..\lib" /i "..\include" /d "NDEBUG"
|
# ADD BASE RSC /l 0x409 /i "..\include" /d "NDEBUG"
|
||||||
# ADD RSC /l 0x409 /i "..\lib" /i "..\include" /d "NDEBUG"
|
# ADD RSC /l 0x409 /i "..\include" /d "NDEBUG"
|
||||||
BSC32=bscmake.exe
|
BSC32=bscmake.exe
|
||||||
# ADD BASE BSC32 /nologo
|
# ADD BASE BSC32 /nologo
|
||||||
# ADD BSC32 /nologo
|
# ADD BSC32 /nologo
|
||||||
@ -195,6 +195,10 @@ SOURCE=.\tool_mfiles.c
|
|||||||
# End Source File
|
# End Source File
|
||||||
# Begin Source File
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\tool_msgs.c
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
SOURCE=.\tool_myfunc.c
|
SOURCE=.\tool_myfunc.c
|
||||||
# End Source File
|
# End Source File
|
||||||
# Begin Source File
|
# Begin Source File
|
||||||
@ -283,10 +287,18 @@ SOURCE=.\tool_mfiles.h
|
|||||||
# End Source File
|
# End Source File
|
||||||
# Begin Source File
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\tool_msgs.h
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
SOURCE=.\tool_myfunc.h
|
SOURCE=.\tool_myfunc.h
|
||||||
# End Source File
|
# End Source File
|
||||||
# Begin Source File
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\tool_sdecls.h
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
SOURCE=.\tool_vms.h
|
SOURCE=.\tool_vms.h
|
||||||
# End Source File
|
# End Source File
|
||||||
# Begin Source File
|
# Begin Source File
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#ifndef HEADER_CURL_VERSION_H
|
#ifndef HEADER_CURL_TOOL_VERSION_H
|
||||||
#define HEADER_CURL_VERSION_H
|
#define HEADER_CURL_TOOL_VERSION_H
|
||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
* _ _ ____ _
|
* _ _ ____ _
|
||||||
* Project ___| | | | _ \| |
|
* Project ___| | | | _ \| |
|
||||||
@ -21,8 +21,6 @@
|
|||||||
* KIND, either express or implied.
|
* KIND, either express or implied.
|
||||||
*
|
*
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
#include "setup.h"
|
|
||||||
|
|
||||||
#include <curl/curlver.h>
|
#include <curl/curlver.h>
|
||||||
|
|
||||||
#define CURL_NAME "curl"
|
#define CURL_NAME "curl"
|
||||||
@ -33,4 +31,4 @@
|
|||||||
#define CURL_VERSION_PATCH LIBCURL_VERSION_PATCH
|
#define CURL_VERSION_PATCH LIBCURL_VERSION_PATCH
|
||||||
#define CURL_ID CURL_NAME " " CURL_VERSION " (" OS ") "
|
#define CURL_ID CURL_NAME " " CURL_VERSION " (" OS ") "
|
||||||
|
|
||||||
#endif /* HEADER_CURL_VERSION_H */
|
#endif /* HEADER_CURL_TOOL_VERSION_H */
|
||||||
|
Loading…
Reference in New Issue
Block a user