Commit 84221006 authored by Yang Tse's avatar Yang Tse
Browse files

curl tool: reviewed code moved to tool_*.[ch] files

Overhauled FindWin32CACert()
parent a6c168b8
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -11,7 +11,8 @@ SOURCE \
    main.c hugehelp.c urlglob.c writeout.c writeenv.c \
    getpass.c homedir.c curlutil.c xattr.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
SOURCE \
+4 −2
Original line number Diff line number Diff line
@@ -17,13 +17,15 @@ CURLX_ONES = $(top_srcdir)/lib/strtoofft.c \
CURL_CFILES = main.c hugehelp.c urlglob.c writeout.c writeenv.c \
	getpass.c homedir.c curlutil.c xattr.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 \
	config-riscos.h urlglob.h version.h xattr.h \
	writeout.h writeenv.h getpass.h homedir.h curlutil.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)
+7 −1
Original line number Diff line number Diff line
@@ -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
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
# builds the VC8 version of this makefile. Left commented out in the VC6
@@ -147,6 +147,7 @@ RELEASE_OBJS= \
	tool_dirhier.obj \
	tool_doswinr.obj \
	tool_mfilesr.obj \
	tool_msgsr.obj \
	tool_myfuncr.obj \
	tool_vmsr.obj \
	urlglobr.obj \
@@ -169,6 +170,7 @@ DEBUG_OBJS= \
	tool_dirhied.obj \
	tool_doswind.obj \
	tool_mfilesd.obj \
	tool_msgsd.obj \
	tool_myfuncd.obj \
	tool_vmsd.obj \
	urlglobd.obj \
@@ -326,6 +328,8 @@ tool_doswinr.obj: tool_doswin.c
	$(CCR) $(CFLAGS) /Fo"$@" tool_doswin.c
tool_mfilesr.obj: 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
	$(CCR) $(CFLAGS) /Fo"$@" tool_myfunc.c
tool_vmsr.obj: tool_vms.c
@@ -368,6 +372,8 @@ tool_doswind.obj: tool_doswin.c
	$(CCD) $(CFLAGS) /Fo"$@" tool_doswin.c
tool_mfilesd.obj: 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
	$(CCD) $(CFLAGS) /Fo"$@" tool_myfunc.c
tool_vmsd.obj: tool_vms.c
+8 −99
Original line number Diff line number Diff line
@@ -98,6 +98,7 @@
#include "tool_dirhie.h"
#include "tool_doswin.h"
#include "tool_mfiles.h"
#include "tool_msgs.h"
#include "tool_myfunc.h"
#include "tool_vms.h"
#ifdef USE_MANUAL
@@ -266,49 +267,6 @@ static int ftruncate64(int fd, curl_off_t where)

#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
 * _any_ libcurl usage. If this fails, *NO* libcurl functions may be
@@ -346,22 +304,6 @@ static int SetHTTPrequest(struct Configurable *config,
  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)
{
  int i;
@@ -3169,11 +3111,6 @@ static size_t my_fwrite(void *buffer, size_t sz, size_t nmemb, void *stream)
  return rc;
}

struct InStruct {
  int fd;
  struct Configurable *config;
};

#define MAX_SEEK 2147483647

/*
@@ -3588,39 +3525,6 @@ int my_trace(CURL *handle, curl_infotype type,
  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_MAX     600000 /* ms == 10 minutes */

@@ -4238,8 +4142,13 @@ operate(struct Configurable *config, int argc, argv_item_t argv[])
    if(env)
      curl_free(env);
#ifdef WIN32
    else
      FindWin32CACert(config, "curl-ca-bundle.crt");
    else {
      res = FindWin32CACert(config, "curl-ca-bundle.crt");
      if(res) {
        clean_getout(config);
        goto quit_curl;
      }
    }
#endif
  }

+4 −47
Original line number Diff line number Diff line
@@ -23,50 +23,7 @@
 ***************************************************************************/
#include "setup.h"

typedef enum {
  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 */
#include "tool_sdecls.h"

struct Configurable {
  CURL *easy;               /* once we have one, we keep it here */
@@ -120,7 +77,7 @@ struct Configurable {
  struct curl_slist *mail_rcpt;
  bool proxytunnel;
  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 autoreferer;         /* automatically set referer */
  bool failonerror;         /* fail on (HTTP) errors */
@@ -178,8 +135,8 @@ struct Configurable {
  bool proxyanyauth;
  char *writeout;           /* %-styled format string to output */
  bool writeenv;            /* write results to environment, if available */
  FILE *errors;             /* if stderr redirect is requested */
  bool errors_fopened;
  FILE *errors;             /* errors stream, defaults to stderr */
  bool errors_fopened;      /* whether errors stream isn't stderr */
  struct curl_slist *quote;
  struct curl_slist *postquote;
  struct curl_slist *prequote;
Loading