From f7bfdbabf2d5398f4c266eabb0992a04af661f22 Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Thu, 6 Oct 2011 17:39:00 +0200 Subject: curl tool: reviewed code moved to tool_*.[ch] files --- src/.gitignore | 1 + src/Makefile.inc | 23 ++-- src/Makefile.vc6 | 66 ++++++------ src/curl.rc | 2 +- src/curlutil.c | 135 ------------------------ src/curlutil.h | 48 --------- src/getpass.c | 265 ---------------------------------------------- src/getpass.h | 36 ------- src/homedir.c | 113 -------------------- src/homedir.h | 28 ----- src/tool_cb_dbg.c | 5 +- src/tool_getparam.c | 3 +- src/tool_getpass.c | 260 +++++++++++++++++++++++++++++++++++++++++++++ src/tool_getpass.h | 36 +++++++ src/tool_homedir.c | 112 ++++++++++++++++++++ src/tool_homedir.h | 28 +++++ src/tool_operate.c | 21 ++-- src/tool_operhlp.c | 3 +- src/tool_paramhlp.c | 5 +- src/tool_parsecfg.c | 3 +- src/tool_util.c | 135 ++++++++++++++++++++++++ src/tool_util.h | 56 ++++++++++ src/tool_version.h | 34 ++++++ src/tool_writeenv.c | 118 +++++++++++++++++++++ src/tool_writeenv.h | 35 +++++++ src/tool_writeout.c | 290 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/tool_writeout.h | 28 +++++ src/tool_xattr.c | 78 ++++++++++++++ src/tool_xattr.h | 28 +++++ src/vc6curlsrc.dsp | 64 +++++------ src/version.h | 34 ------ src/writeenv.c | 118 --------------------- src/writeenv.h | 28 ----- src/writeout.c | 297 ---------------------------------------------------- src/writeout.h | 28 ----- src/xattr.c | 78 -------------- src/xattr.h | 28 ----- 37 files changed, 1340 insertions(+), 1330 deletions(-) delete mode 100644 src/curlutil.c delete mode 100644 src/curlutil.h delete mode 100644 src/getpass.c delete mode 100644 src/getpass.h delete mode 100644 src/homedir.c delete mode 100644 src/homedir.h create mode 100644 src/tool_getpass.c create mode 100644 src/tool_getpass.h create mode 100644 src/tool_homedir.c create mode 100644 src/tool_homedir.h create mode 100644 src/tool_util.c create mode 100644 src/tool_util.h create mode 100644 src/tool_version.h create mode 100644 src/tool_writeenv.c create mode 100644 src/tool_writeenv.h create mode 100644 src/tool_writeout.c create mode 100644 src/tool_writeout.h create mode 100644 src/tool_xattr.c create mode 100644 src/tool_xattr.h delete mode 100644 src/version.h delete mode 100644 src/writeenv.c delete mode 100644 src/writeenv.h delete mode 100644 src/writeout.c delete mode 100644 src/writeout.h delete mode 100644 src/xattr.c delete mode 100644 src/xattr.h (limited to 'src') diff --git a/src/.gitignore b/src/.gitignore index eca86f94d..d99cc3f7c 100644 --- a/src/.gitignore +++ b/src/.gitignore @@ -6,5 +6,6 @@ stamp-h2 Makefile.vc8.dist Makefile.vc9.dist version.h.dist +tool_version.h.dist Makefile.vc10.dist config-win32.h diff --git a/src/Makefile.inc b/src/Makefile.inc index d2ee0e679..1660bc403 100644 --- a/src/Makefile.inc +++ b/src/Makefile.inc @@ -14,8 +14,7 @@ CURLX_ONES = $(top_srcdir)/lib/strtoofft.c \ $(top_srcdir)/lib/rawstr.c \ $(top_srcdir)/lib/nonblock.c -CURL_CFILES = hugehelp.c writeout.c writeenv.c \ - getpass.c homedir.c curlutil.c xattr.c \ +CURL_CFILES = hugehelp.c \ tool_binmode.c \ tool_bname.c \ tool_cb_dbg.c \ @@ -32,8 +31,10 @@ CURL_CFILES = hugehelp.c writeout.c writeenv.c \ tool_easysrc.c \ tool_formparse.c \ tool_getparam.c \ + tool_getpass.c \ tool_help.c \ tool_helpers.c \ + tool_homedir.c \ tool_libinfo.c \ tool_main.c \ tool_mfiles.c \ @@ -46,11 +47,14 @@ CURL_CFILES = hugehelp.c writeout.c writeenv.c \ tool_setopt.c \ tool_sleep.c \ tool_urlglob.c \ - tool_vms.c + tool_util.c \ + tool_vms.c \ + tool_writeenv.c \ + tool_writeout.c \ + tool_xattr.c CURL_HFILES = hugehelp.h setup.h config-win32.h config-mac.h \ - config-riscos.h version.h xattr.h \ - writeout.h writeenv.h getpass.h homedir.h curlutil.h \ + config-riscos.h \ tool_binmode.h \ tool_bname.h \ tool_cb_dbg.h \ @@ -67,8 +71,10 @@ CURL_HFILES = hugehelp.h setup.h config-win32.h config-mac.h \ tool_easysrc.h \ tool_formparse.h \ tool_getparam.h \ + tool_getpass.h \ tool_help.h \ tool_helpers.h \ + tool_homedir.h \ tool_libinfo.h \ tool_main.h \ tool_mfiles.h \ @@ -82,7 +88,12 @@ CURL_HFILES = hugehelp.h setup.h config-win32.h config-mac.h \ tool_setopt.h \ tool_sleep.h \ tool_urlglob.h \ - tool_vms.h + tool_util.h \ + tool_version.h \ + tool_vms.h \ + tool_writeenv.h \ + tool_writeout.h \ + tool_xattr.h curl_SOURCES = $(CURL_CFILES) $(CURLX_ONES) $(CURL_HFILES) diff --git a/src/Makefile.vc6 b/src/Makefile.vc6 index fe03afe52..dbd32f175 100644 --- a/src/Makefile.vc6 +++ b/src/Makefile.vc6 @@ -133,9 +133,6 @@ CFLAGS = $(CFLAGS) /DUSE_WINDOWS_SSPI /I$(WINDOWS_SDK_PATH)\include !ENDIF RELEASE_OBJS= \ - curlutilr.obj \ - getpassr.obj \ - homedirr.obj \ hugehelpr.obj \ nonblockr.obj \ rawstrr.obj \ @@ -156,8 +153,10 @@ RELEASE_OBJS= \ tool_easysrcr.obj \ tool_formparser.obj \ tool_getparamr.obj \ + tool_getpassr.obj \ tool_helpr.obj \ tool_helpersr.obj \ + tool_homedirr.obj \ tool_libinfor.obj \ tool_mainr.obj \ tool_mfilesr.obj \ @@ -170,15 +169,14 @@ RELEASE_OBJS= \ tool_setoptr.obj \ tool_sleepr.obj \ tool_urlglobr.obj \ + tool_utilr.obj \ tool_vmsr.obj \ - writeoutr.obj \ - xattrr.obj \ + tool_writeenvr.obj \ + tool_writeoutr.obj \ + tool_xattrr.obj \ curlr.res DEBUG_OBJS= \ - curlutild.obj \ - getpassd.obj \ - homedird.obj \ hugehelpd.obj \ nonblockd.obj \ rawstrd.obj \ @@ -199,8 +197,10 @@ DEBUG_OBJS= \ tool_easysrcd.obj \ tool_formparsed.obj \ tool_getparamd.obj \ + tool_getpassd.obj \ tool_helpd.obj \ tool_helpersd.obj \ + tool_homedird.obj \ tool_libinfod.obj \ tool_maind.obj \ tool_mfilesd.obj \ @@ -213,9 +213,11 @@ DEBUG_OBJS= \ tool_setoptd.obj \ tool_sleepd.obj \ tool_urlglobd.obj \ + tool_utild.obj \ tool_vmsd.obj \ - writeoutd.obj \ - xattrd.obj \ + tool_writeenvd.obj \ + tool_writeoutd.obj \ + tool_xattrd.obj \ curld.res ################################################# @@ -340,14 +342,6 @@ debug: $(DEBUG_OBJS) ## Release hugehelpr.obj: hugehelp.c $(CCR) $(CFLAGS) /Zm200 /Fo"$@" hugehelp.c -writeoutr.obj: writeout.c - $(CCR) $(CFLAGS) /Fo"$@" writeout.c -getpassr.obj: getpass.c - $(CCR) $(CFLAGS) /Fo"$@" getpass.c -homedirr.obj: homedir.c - $(CCR) $(CFLAGS) /Fo"$@" homedir.c -curlutilr.obj: curlutil.c - $(CCR) $(CFLAGS) /Fo"$@" curlutil.c nonblockr.obj: ../lib/nonblock.c $(CCR) $(CFLAGS) /Fo"$@" ../lib/nonblock.c rawstrr.obj: ../lib/rawstr.c @@ -386,10 +380,14 @@ tool_formparser.obj: tool_formparse.c $(CCR) $(CFLAGS) /Fo"$@" tool_formparse.c tool_getparamr.obj: tool_getparam.c $(CCR) $(CFLAGS) /Fo"$@" tool_getparam.c +tool_getpassr.obj: tool_getpass.c + $(CCR) $(CFLAGS) /Fo"$@" tool_getpass.c tool_helpr.obj: tool_help.c $(CCR) $(CFLAGS) /Fo"$@" tool_help.c tool_helpersr.obj: tool_helpers.c $(CCR) $(CFLAGS) /Fo"$@" tool_helpers.c +tool_homedirr.obj: tool_homedir.c + $(CCR) $(CFLAGS) /Fo"$@" tool_homedir.c tool_libinfor.obj: tool_libinfo.c $(CCR) $(CFLAGS) /Fo"$@" tool_libinfo.c tool_mainr.obj: tool_main.c @@ -414,24 +412,22 @@ tool_sleepr.obj: tool_sleep.c $(CCR) $(CFLAGS) /Fo"$@" tool_sleep.c tool_urlglobr.obj: tool_urlglob.c $(CCR) $(CFLAGS) /Fo"$@" tool_urlglob.c +tool_utilr.obj: tool_util.c + $(CCR) $(CFLAGS) /Fo"$@" tool_util.c tool_vmsr.obj: tool_vms.c $(CCR) $(CFLAGS) /Fo"$@" tool_vms.c -xattrr.obj: xattr.c - $(CCR) $(CFLAGS) /Fo"$@" xattr.c +tool_writeenvr.obj: tool_writeenv.c + $(CCR) $(CFLAGS) /Fo"$@" tool_writeenv.c +tool_writeoutr.obj: tool_writeout.c + $(CCR) $(CFLAGS) /Fo"$@" tool_writeout.c +tool_xattrr.obj: tool_xattr.c + $(CCR) $(CFLAGS) /Fo"$@" tool_xattr.c curlr.res : curl.rc $(RCR) $(RESFLAGS) /Fo"$@" curl.rc ## Debug hugehelpd.obj: hugehelp.c $(CCD) $(CFLAGS) /Zm200 /Fo"$@" hugehelp.c -writeoutd.obj: writeout.c - $(CCD) $(CFLAGS) /Fo"$@" writeout.c -getpassd.obj: getpass.c - $(CCD) $(CFLAGS) /Fo"$@" getpass.c -homedird.obj: homedir.c - $(CCD) $(CFLAGS) /Fo"$@" homedir.c -curlutild.obj: curlutil.c - $(CCD) $(CFLAGS) /Fo"$@" curlutil.c nonblockd.obj: ../lib/nonblock.c $(CCD) $(CFLAGS) /Fo"$@" ../lib/nonblock.c rawstrd.obj: ../lib/rawstr.c @@ -470,10 +466,14 @@ tool_formparsed.obj: tool_formparse.c $(CCD) $(CFLAGS) /Fo"$@" tool_formparse.c tool_getparamd.obj: tool_getparam.c $(CCD) $(CFLAGS) /Fo"$@" tool_getparam.c +tool_getpassd.obj: tool_getpass.c + $(CCD) $(CFLAGS) /Fo"$@" tool_getpass.c tool_helpd.obj: tool_help.c $(CCD) $(CFLAGS) /Fo"$@" tool_help.c tool_helpersd.obj: tool_helpers.c $(CCD) $(CFLAGS) /Fo"$@" tool_helpers.c +tool_homedird.obj: tool_homedir.c + $(CCD) $(CFLAGS) /Fo"$@" tool_homedir.c tool_libinfod.obj: tool_libinfo.c $(CCD) $(CFLAGS) /Fo"$@" tool_libinfo.c tool_maind.obj: tool_main.c @@ -498,10 +498,16 @@ tool_sleepd.obj: tool_sleep.c $(CCD) $(CFLAGS) /Fo"$@" tool_sleep.c tool_urlglobd.obj: tool_urlglob.c $(CCD) $(CFLAGS) /Fo"$@" tool_urlglob.c +tool_utild.obj: tool_util.c + $(CCD) $(CFLAGS) /Fo"$@" tool_util.c tool_vmsd.obj: tool_vms.c $(CCD) $(CFLAGS) /Fo"$@" tool_vms.c -xattrd.obj: xattr.c - $(CCD) $(CFLAGS) /Fo"$@" xattr.c +tool_writeenvd.obj: tool_writeenv.c + $(CCD) $(CFLAGS) /Fo"$@" tool_writeenv.c +tool_writeoutd.obj: tool_writeout.c + $(CCD) $(CFLAGS) /Fo"$@" tool_writeout.c +tool_xattrd.obj: tool_xattr.c + $(CCD) $(CFLAGS) /Fo"$@" tool_xattr.c curld.res : curl.rc $(RCD) $(RESFLAGS) /Fo"$@" curl.rc diff --git a/src/curl.rc b/src/curl.rc index 58e439d3b..3db59bd3c 100644 --- a/src/curl.rc +++ b/src/curl.rc @@ -20,7 +20,7 @@ * ***************************************************************************/ #include -#include "version.h" +#include "tool_version.h" LANGUAGE 0x09,0x01 diff --git a/src/curlutil.c b/src/curlutil.c deleted file mode 100644 index a524b65b4..000000000 --- a/src/curlutil.c +++ /dev/null @@ -1,135 +0,0 @@ -/*************************************************************************** - * _ _ ____ _ - * 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" - -#include "curlutil.h" - -#include "memdebug.h" /* keep this as LAST include */ - -#if defined(WIN32) && !defined(MSDOS) - -struct timeval cutil_tvnow(void) -{ - /* - ** GetTickCount() is available on _all_ Windows versions from W95 up - ** to nowadays. Returns milliseconds elapsed since last system boot, - ** increases monotonically and wraps once 49.7 days have elapsed. - */ - struct timeval now; - DWORD milliseconds = GetTickCount(); - now.tv_sec = milliseconds / 1000; - now.tv_usec = (milliseconds % 1000) * 1000; - return now; -} - -#elif defined(HAVE_CLOCK_GETTIME_MONOTONIC) - -struct timeval cutil_tvnow(void) -{ - /* - ** clock_gettime() is granted to be increased monotonically when the - ** monotonic clock is queried. Time starting point is unspecified, it - ** could be the system start-up time, the Epoch, or something else, - ** in any case the time starting point does not change once that the - ** system has started up. - */ - struct timeval now; - struct timespec tsnow; - if(0 == clock_gettime(CLOCK_MONOTONIC, &tsnow)) { - now.tv_sec = tsnow.tv_sec; - now.tv_usec = tsnow.tv_nsec / 1000; - } - /* - ** Even when the configure process has truly detected monotonic clock - ** availability, it might happen that it is not actually available at - ** run-time. When this occurs simply fallback to other time source. - */ -#ifdef HAVE_GETTIMEOFDAY - else - (void)gettimeofday(&now, NULL); -#else - else { - now.tv_sec = (long)time(NULL); - now.tv_usec = 0; - } -#endif - return now; -} - -#elif defined(HAVE_GETTIMEOFDAY) - -struct timeval cutil_tvnow(void) -{ - /* - ** gettimeofday() is not granted to be increased monotonically, due to - ** clock drifting and external source time synchronization it can jump - ** forward or backward in time. - */ - struct timeval now; - (void)gettimeofday(&now, NULL); - return now; -} - -#else - -struct timeval cutil_tvnow(void) -{ - /* - ** time() returns the value of time in seconds since the Epoch. - */ - struct timeval now; - now.tv_sec = (long)time(NULL); - now.tv_usec = 0; - return now; -} - -#endif - -/* - * Make sure that the first argument is the more recent time, as otherwise - * we'll get a weird negative time-diff back... - * - * Returns: the time difference in number of milliseconds. - */ -long cutil_tvdiff(struct timeval newer, struct timeval older) -{ - return (newer.tv_sec-older.tv_sec)*1000+ - (newer.tv_usec-older.tv_usec)/1000; -} - -/* - * Same as cutil_tvdiff but with full usec resolution. - * - * Returns: the time difference in seconds with subsecond resolution. - */ -double cutil_tvdiff_secs(struct timeval newer, struct timeval older) -{ - return (double)(newer.tv_sec-older.tv_sec)+ - (double)(newer.tv_usec-older.tv_usec)/1000000.0; -} - -/* return the number of seconds in the given input timeval struct */ -long cutil_tvlong(struct timeval t1) -{ - return t1.tv_sec; -} - diff --git a/src/curlutil.h b/src/curlutil.h deleted file mode 100644 index e0d9cb167..000000000 --- a/src/curlutil.h +++ /dev/null @@ -1,48 +0,0 @@ -#ifndef HEADER_CURL_SRC_UTIL_H -#define HEADER_CURL_SRC_UTIL_H -/*************************************************************************** - * _ _ ____ _ - * 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" - - -struct timeval cutil_tvnow(void); - -/* - * Make sure that the first argument (t1) is the more recent time and t2 is - * the older time, as otherwise you get a weird negative time-diff back... - * - * Returns: the time difference in number of milliseconds. - */ -long cutil_tvdiff(struct timeval t1, struct timeval t2); - -/* - * Same as cutil_tvdiff but with full usec resolution. - * - * Returns: the time difference in seconds with subsecond resolution. - */ -double cutil_tvdiff_secs(struct timeval t1, struct timeval t2); - -long cutil_tvlong(struct timeval t1); - - -#endif /* HEADER_CURL_SRC_UTIL_H */ - diff --git a/src/getpass.c b/src/getpass.c deleted file mode 100644 index a154d107c..000000000 --- a/src/getpass.c +++ /dev/null @@ -1,265 +0,0 @@ -/*************************************************************************** - * _ _ ____ _ - * 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" - -#ifndef HAVE_GETPASS_R -/* this file is only for systems without getpass_r() */ - -#ifdef HAVE_UNISTD_H -#include -#endif - -#ifdef HAVE_FCNTL_H -#include -#endif -#ifdef HAVE_TERMIOS_H -#include -#else -#ifdef HAVE_TERMIO_H -#include -#endif -#endif - -#ifdef __VMS -# include descrip -# include starlet -# include iodef -#endif - -#ifdef WIN32 -# include -#endif - -#ifdef NETWARE -# ifdef __NOVELL_LIBC__ -# include -# else -# include -# endif -#endif - -#include "getpass.h" - -#include "memdebug.h" /* keep this as LAST include */ - -#ifdef __VMS -/* VMS implementation */ -char *getpass_r(const char *prompt, char *buffer, size_t buflen) -{ - long sts; - short chan; - - /* MSK, 23-JAN-2004, iosbdef.h wasn't in VAX V7.2 or CC 6.4 */ - /* distribution so I created this. May revert back later to */ - /* struct _iosb iosb; */ - struct _iosb - { - short int iosb$w_status; /* status */ - short int iosb$w_bcnt; /* byte count */ - int unused; /* unused */ - } iosb; - - $DESCRIPTOR(ttdesc, "TT"); - - buffer[0]='\0'; - sts = sys$assign(&ttdesc, &chan,0,0); - if(sts & 1) { - sts = sys$qiow(0, chan, - IO$_READPROMPT | IO$M_NOECHO, - &iosb, 0, 0, buffer, buflen, 0, 0, - prompt, strlen(prompt)); - - if((sts & 1) && (iosb.iosb$w_status&1)) - buffer[iosb.iosb$w_bcnt] = '\0'; - - sts = sys$dassgn(chan); - } - return buffer; /* we always return success */ -} -#define DONE -#endif /* __VMS */ - -#ifdef __SYMBIAN32__ -#define getch() getchar() -#endif - -#if defined(WIN32) || defined(__SYMBIAN32__) - -char *getpass_r(const char *prompt, char *buffer, size_t buflen) -{ - size_t i; - fputs(prompt, stderr); - - for(i=0; i=1?2:1); - } -#ifndef __SYMBIAN32__ - /* since echo is disabled, print a newline */ - fputs("\n", stderr); -#endif - /* if user didn't hit ENTER, terminate buffer */ - if(i==buflen) - buffer[buflen-1]=0; - - return buffer; /* we always return success */ -} -#define DONE -#endif /* WIN32 || __SYMBIAN32__ */ - -#ifdef NETWARE -/* NetWare implementation */ -#ifdef __NOVELL_LIBC__ -char *getpass_r(const char *prompt, char *buffer, size_t buflen) -{ - return getpassword(prompt, buffer, buflen); -} -#else -char *getpass_r(const char *prompt, char *buffer, size_t buflen) -{ - size_t i = 0; - - printf("%s", prompt); - do { - buffer[i++] = getch(); - if(buffer[i-1] == '\b') { - /* remove this letter and if this is not the first key, - remove the previous one as well */ - if(i > 1) { - printf("\b \b"); - i = i - 2; - } - else { - RingTheBell(); - i = i - 1; - } - } - else if(buffer[i-1] != 13) - putchar('*'); - - } while((buffer[i-1] != 13) && (i < buflen)); - buffer[i-1] = 0; - printf("\r\n"); - return buffer; -} -#endif /* __NOVELL_LIBC__ */ -#define DONE -#endif /* NETWARE */ - -#ifndef DONE /* not previously provided */ - -#ifdef HAVE_TERMIOS_H -#define struct_term struct termios -#else -#ifdef HAVE_TERMIO_H -#define struct_term struct termio -#else -#undef struct_term -#endif -#endif - -static bool ttyecho(bool enable, int fd) -{ -#ifdef struct_term - static struct_term withecho; - static struct_term noecho; -#endif - if(!enable) { - /* disable echo by extracting the current 'withecho' mode and remove the - ECHO bit and set back the struct */ -#ifdef HAVE_TERMIOS_H - tcgetattr(fd, &withecho); - noecho = withecho; - noecho.c_lflag &= ~ECHO; - tcsetattr(fd, TCSANOW, &noecho); -#else /* HAVE_TERMIOS_H */ -#ifdef HAVE_TERMIO_H - ioctl(fd, TCGETA, &withecho); - noecho = withecho; - noecho.c_lflag &= ~ECHO; - ioctl(fd, TCSETA, &noecho); -#else /* HAVE_TERMIO_H */ -/* neither HAVE_TERMIO_H nor HAVE_TERMIOS_H, we can't disable echo! */ - (void)fd; /* prevent compiler warning on unused variable */ - return FALSE; /* not disabled */ -#endif -#endif - return TRUE; /* disabled */ - } - else { - /* re-enable echo, assumes we disabled it before (and set the structs we - now use to reset the terminal status) */ -#ifdef HAVE_TERMIOS_H - tcsetattr(fd, TCSAFLUSH, &withecho); -#else /* HAVE_TERMIOS_H */ -#ifdef HAVE_TERMIO_H - ioctl(fd, TCSETA, &withecho); -#else -/* neither HAVE_TERMIO_H nor HAVE_TERMIOS_H */ - return FALSE; /* not enabled */ -#endif -#endif - return TRUE; /* enabled */ - } -} - -char *getpass_r(const char *prompt, /* prompt to display */ - char *password, /* buffer to store password in */ - size_t buflen) /* size of buffer to store password in */ -{ - ssize_t nread; - bool disabled; - int fd=open("/dev/tty", O_RDONLY); - if(-1 == fd) - fd = 1; /* use stdin if the tty couldn't be used */ - - disabled = ttyecho(FALSE, fd); /* disable terminal echo */ - - fputs(prompt, stderr); - nread=read(fd, password, buflen); - if(nread > 0) - password[--nread]=0; /* zero terminate where enter is stored */ - else - password[0]=0; /* got nothing */ - - if(disabled) { - /* if echo actually was disabled, add a newline */ - fputs("\n", stderr); - (void)ttyecho(TRUE, fd); /* enable echo */ - } - - if(1 != fd) - close(fd); - - return password; /* return pointer to buffer */ -} - -#endif /* DONE */ -#endif /* HAVE_GETPASS_R */ diff --git a/src/getpass.h b/src/getpass.h deleted file mode 100644 index 7d714fcf3..000000000 --- a/src/getpass.h +++ /dev/null @@ -1,36 +0,0 @@ -#ifndef HEADER_CURL_GETPASS_H -#define HEADER_CURL_GETPASS_H -/*************************************************************************** - * _ _ ____ _ - * 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" - -#ifndef HAVE_GETPASS_R -/* If there's a system-provided function named like this, we trust it is - also found in one of the standard headers. */ - -/* - * Returning NULL will abort the continued operation! - */ -char* getpass_r(const char *prompt, char* buffer, size_t buflen ); -#endif - -#endif /* HEADER_CURL_GETPASS_H */ diff --git a/src/homedir.c b/src/homedir.c deleted file mode 100644 index 80ffe0752..000000000 --- a/src/homedir.c +++ /dev/null @@ -1,113 +0,0 @@ -/*************************************************************************** - * _ _ ____ _ - * 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" - -#ifdef HAVE_PWD_H -#include -#endif -#ifdef HAVE_UNISTD_H -#include -#endif -#ifdef __VMS -#include -#endif - -#include "homedir.h" - -#include "memdebug.h" /* keep this as LAST include */ - -static -char *GetEnv(const char *variable, char do_expand) -{ - char *env = NULL; -#ifdef WIN32 - char buf1[1024], buf2[1024]; - DWORD rc; - - /* Don't use getenv(); it doesn't find variable added after program was - * started. Don't accept truncated results (i.e. rc >= sizeof(buf1)). */ - - rc = GetEnvironmentVariable(variable, buf1, sizeof(buf1)); - if(rc > 0 && rc < sizeof(buf1)) { - env = buf1; - variable = buf1; - } - if(do_expand && strchr(variable,'%')) { - /* buf2 == variable if not expanded */ - rc = ExpandEnvironmentStrings (variable, buf2, sizeof(buf2)); - if(rc > 0 && rc < sizeof(buf2) && - !strchr(buf2,'%')) /* no vars still unexpanded */ - env = buf2; - } -#else - (void)do_expand; -#ifdef __VMS - env = getenv(variable); - if(env && strcmp("HOME",variable) == 0) { - env = decc_translate_vms(env); - } -#else - /* no length control */ - env = getenv(variable); -#endif -#endif - return (env && env[0])?strdup(env):NULL; -} - -/* return the home directory of the current user as an allocated string */ -char *homedir(void) -{ - char *home; - - home = GetEnv("CURL_HOME", FALSE); - if(home) - return home; - - home = GetEnv("HOME", FALSE); - if(home) - return home; - -#if defined(HAVE_GETPWUID) && defined(HAVE_GETEUID) - { - struct passwd *pw = getpwuid(geteuid()); - - if(pw) { -#ifdef __VMS - home = decc_translate_vms(pw->pw_dir); -#else - home = pw->pw_dir; -#endif - if(home && home[0]) - home = strdup(home); - else - home = NULL; - } - } -#endif /* PWD-stuff */ -#ifdef WIN32 - home = GetEnv("APPDATA", TRUE); - if(!home) - home = GetEnv("%USERPROFILE%\\Application Data", TRUE); /* Normally only - on Win-2K/XP */ -#endif /* WIN32 */ - return home; -} diff --git a/src/homedir.h b/src/homedir.h deleted file mode 100644 index 252fd0ecc..000000000 --- a/src/homedir.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef HEADER_CURL_HOMEDIR_H -#define HEADER_CURL_HOMEDIR_H -/*************************************************************************** - * _ _ ____ _ - * 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" - -char *homedir(void); - -#endif /* HEADER_CURL_HOMEDIR_H */ diff --git a/src/tool_cb_dbg.c b/src/tool_cb_dbg.c index 7b20a0c01..7ac9a7339 100644 --- a/src/tool_cb_dbg.c +++ b/src/tool_cb_dbg.c @@ -27,11 +27,10 @@ /* use our own printf() functions */ #include "curlx.h" -#include "curlutil.h" - #include "tool_cfgable.h" #include "tool_msgs.h" #include "tool_cb_dbg.h" +#include "tool_util.h" #include "memdebug.h" /* keep this as LAST include */ @@ -60,7 +59,7 @@ int tool_debug_cb(CURL *handle, curl_infotype type, (void)handle; /* not used */ if(config->tracetime) { - tv = cutil_tvnow(); + tv = tvnow(); if(!known_offset) { epoch_offset = time(NULL) - tv.tv_sec; known_offset = 1; diff --git a/src/tool_getparam.c b/src/tool_getparam.c index f18c9168e..bb36b4246 100644 --- a/src/tool_getparam.c +++ b/src/tool_getparam.c @@ -33,8 +33,6 @@ # include "hugehelp.h" #endif -#include "version.h" - #include "tool_binmode.h" #include "tool_cfgable.h" #include "tool_cb_prg.h" @@ -46,6 +44,7 @@ #include "tool_msgs.h" #include "tool_paramhlp.h" #include "tool_parsecfg.h" +#include "tool_version.h" #include "memdebug.h" /* keep this as LAST include */ diff --git a/src/tool_getpass.c b/src/tool_getpass.c new file mode 100644 index 000000000..b6aa5dd5e --- /dev/null +++ b/src/tool_getpass.c @@ -0,0 +1,260 @@ +/*************************************************************************** + * _ _ ____ _ + * 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" + +#ifndef HAVE_GETPASS_R +/* this file is only for systems without getpass_r() */ + +#ifdef HAVE_UNISTD_H +# include +#endif + +#ifdef HAVE_FCNTL_H +# include +#endif + +#ifdef HAVE_TERMIOS_H +# include +#elif defined(HAVE_TERMIO_H) +# include +#endif + +#ifdef __VMS +# include descrip +# include starlet +# include iodef +#endif + +#ifdef WIN32 +# include +#endif + +#ifdef NETWARE +# ifdef __NOVELL_LIBC__ +# include +# else +# include +# endif +#endif + +#define _MPRINTF_REPLACE +#include + +#include "tool_getpass.h" + +#include "memdebug.h" /* keep this as LAST include */ + +#ifdef __VMS +/* VMS implementation */ +char *getpass_r(const char *prompt, char *buffer, size_t buflen) +{ + long sts; + short chan; + + /* MSK, 23-JAN-2004, iosbdef.h wasn't in VAX V7.2 or CC 6.4 */ + /* distribution so I created this. May revert back later to */ + /* struct _iosb iosb; */ + struct _iosb + { + short int iosb$w_status; /* status */ + short int iosb$w_bcnt; /* byte count */ + int unused; /* unused */ + } iosb; + + $DESCRIPTOR(ttdesc, "TT"); + + buffer[0] = '\0'; + sts = sys$assign(&ttdesc, &chan, 0, 0); + if(sts & 1) { + sts = sys$qiow(0, chan, + IO$_READPROMPT | IO$M_NOECHO, + &iosb, 0, 0, buffer, buflen, 0, 0, + prompt, strlen(prompt)); + + if((sts & 1) && (iosb.iosb$w_status & 1)) + buffer[iosb.iosb$w_bcnt] = '\0'; + + sts = sys$dassgn(chan); + } + return buffer; /* we always return success */ +} +#define DONE +#endif /* __VMS */ + +#ifdef __SYMBIAN32__ +# define getch() getchar() +#endif + +#if defined(WIN32) || defined(__SYMBIAN32__) + +char *getpass_r(const char *prompt, char *buffer, size_t buflen) +{ + size_t i; + fputs(prompt, stderr); + + for(i = 0; i < buflen; i++) { + buffer[i] = (char)getch(); + if(buffer[i] == '\r' || buffer[i] == '\n') { + buffer[i] = '\0'; + break; + } + else + if(buffer[i] == '\b') + /* remove this letter and if this is not the first key, remove the + previous one as well */ + i = i - (i >= 1) ? 2 : 1; + } +#ifndef __SYMBIAN32__ + /* since echo is disabled, print a newline */ + fputs("\n", stderr); +#endif + /* if user didn't hit ENTER, terminate buffer */ + if(i == buflen) + buffer[buflen-1] = '\0'; + + return buffer; /* we always return success */ +} +#define DONE +#endif /* WIN32 || __SYMBIAN32__ */ + +#ifdef NETWARE +/* NetWare implementation */ +#ifdef __NOVELL_LIBC__ +char *getpass_r(const char *prompt, char *buffer, size_t buflen) +{ + return getpassword(prompt, buffer, buflen); +} +#else +char *getpass_r(const char *prompt, char *buffer, size_t buflen) +{ + size_t i = 0; + + printf("%s", prompt); + do { + buffer[i++] = getch(); + if(buffer[i-1] == '\b') { + /* remove this letter and if this is not the first key, + remove the previous one as well */ + if(i > 1) { + printf("\b \b"); + i = i - 2; + } + else { + RingTheBell(); + i = i - 1; + } + } + else if(buffer[i-1] != 13) + putchar('*'); + + } while((buffer[i-1] != 13) && (i < buflen)); + buffer[i-1] = '\0'; + printf("\r\n"); + return buffer; +} +#endif /* __NOVELL_LIBC__ */ +#define DONE +#endif /* NETWARE */ + +#ifndef DONE /* not previously provided */ + +#ifdef HAVE_TERMIOS_H +# define struct_term struct termios +#elif defined(HAVE_TERMIO_H) +# define struct_term struct termio +#else +# undef struct_term +#endif + +static bool ttyecho(bool enable, int fd) +{ +#ifdef struct_term + static struct_term withecho; + static struct_term noecho; +#endif + if(!enable) { + /* disable echo by extracting the current 'withecho' mode and remove the + ECHO bit and set back the struct */ +#ifdef HAVE_TERMIOS_H + tcgetattr(fd, &withecho); + noecho = withecho; + noecho.c_lflag &= ~ECHO; + tcsetattr(fd, TCSANOW, &noecho); +#elif defined(HAVE_TERMIO_H) + ioctl(fd, TCGETA, &withecho); + noecho = withecho; + noecho.c_lflag &= ~ECHO; + ioctl(fd, TCSETA, &noecho); +#else + /* neither HAVE_TERMIO_H nor HAVE_TERMIOS_H, we can't disable echo! */ + (void)fd; + return FALSE; /* not disabled */ +#endif + return TRUE; /* disabled */ + } + else { + /* re-enable echo, assumes we disabled it before (and set the structs we + now use to reset the terminal status) */ +#ifdef HAVE_TERMIOS_H + tcsetattr(fd, TCSAFLUSH, &withecho); +#elif defined(HAVE_TERMIO_H) + ioctl(fd, TCSETA, &withecho); +#else + return FALSE; /* not enabled */ +#endif + return TRUE; /* enabled */ + } +} + +char *getpass_r(const char *prompt, /* prompt to display */ + char *password, /* buffer to store password in */ + size_t buflen) /* size of buffer to store password in */ +{ + ssize_t nread; + bool disabled; + int fd = open("/dev/tty", O_RDONLY); + if(-1 == fd) + fd = 1; /* use stdin if the tty couldn't be used */ + + disabled = ttyecho(FALSE, fd); /* disable terminal echo */ + + fputs(prompt, stderr); + nread = read(fd, password, buflen); + if(nread > 0) + password[--nread] = '\0'; /* zero terminate where enter is stored */ + else + password[0] = '\0'; /* got nothing */ + + if(disabled) { + /* if echo actually was disabled, add a newline */ + fputs("\n", stderr); + (void)ttyecho(TRUE, fd); /* enable echo */ + } + + if(1 != fd) + close(fd); + + return password; /* return pointer to buffer */ +} + +#endif /* DONE */ +#endif /* HAVE_GETPASS_R */ diff --git a/src/tool_getpass.h b/src/tool_getpass.h new file mode 100644 index 000000000..506d0feef --- /dev/null +++ b/src/tool_getpass.h @@ -0,0 +1,36 @@ +#ifndef HEADER_CURL_TOOL_GETPASS_H +#define HEADER_CURL_TOOL_GETPASS_H +/*************************************************************************** + * _ _ ____ _ + * 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" + +#ifndef HAVE_GETPASS_R +/* If there's a system-provided function named like this, we trust it is + also found in one of the standard headers. */ + +/* + * Returning NULL will abort the continued operation! + */ +char* getpass_r(const char *prompt, char* buffer, size_t buflen); +#endif + +#endif /* HEADER_CURL_TOOL_GETPASS_H */ diff --git a/src/tool_homedir.c b/src/tool_homedir.c new file mode 100644 index 000000000..95d25c74f --- /dev/null +++ b/src/tool_homedir.c @@ -0,0 +1,112 @@ +/*************************************************************************** + * _ _ ____ _ + * 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" + +#ifdef HAVE_PWD_H +# include +#endif +#ifdef HAVE_UNISTD_H +# include +#endif +#ifdef __VMS +# include +#endif + +#include "tool_homedir.h" + +#include "memdebug.h" /* keep this as LAST include */ + +static char *GetEnv(const char *variable, char do_expand) +{ + char *env = NULL; +#ifdef WIN32 + char buf1[1024], buf2[1024]; + DWORD rc; + + /* Don't use getenv(); it doesn't find variable added after program was + * started. Don't accept truncated results (i.e. rc >= sizeof(buf1)). */ + + rc = GetEnvironmentVariable(variable, buf1, sizeof(buf1)); + if(rc > 0 && rc < sizeof(buf1)) { + env = buf1; + variable = buf1; + } + if(do_expand && strchr(variable,'%')) { + /* buf2 == variable if not expanded */ + rc = ExpandEnvironmentStrings (variable, buf2, sizeof(buf2)); + if(rc > 0 && rc < sizeof(buf2) && + !strchr(buf2,'%')) /* no vars still unexpanded */ + env = buf2; + } +#else + (void)do_expand; +#ifdef __VMS + env = getenv(variable); + if(env && strcmp("HOME",variable) == 0) { + env = decc_translate_vms(env); + } +#else + /* no length control */ + env = getenv(variable); +#endif +#endif + return (env && env[0]) ? strdup(env) : NULL; +} + +/* return the home directory of the current user as an allocated string */ +char *homedir(void) +{ + char *home; + + home = GetEnv("CURL_HOME", FALSE); + if(home) + return home; + + home = GetEnv("HOME", FALSE); + if(home) + return home; + +#if defined(HAVE_GETPWUID) && defined(HAVE_GETEUID) + { + struct passwd *pw = getpwuid(geteuid()); + + if(pw) { +#ifdef __VMS + home = decc_translate_vms(pw->pw_dir); +#else + home = pw->pw_dir; +#endif + if(home && home[0]) + home = strdup(home); + else + home = NULL; + } + } +#endif /* PWD-stuff */ +#ifdef WIN32 + home = GetEnv("APPDATA", TRUE); + if(!home) + home = GetEnv("%USERPROFILE%\\Application Data", TRUE); /* Normally only + on Win-2K/XP */ +#endif /* WIN32 */ + return home; +} diff --git a/src/tool_homedir.h b/src/tool_homedir.h new file mode 100644 index 000000000..109c1f282 --- /dev/null +++ b/src/tool_homedir.h @@ -0,0 +1,28 @@ +#ifndef HEADER_CURL_TOOL_HOMEDIR_H +#define HEADER_CURL_TOOL_HOMEDIR_H +/*************************************************************************** + * _ _ ____ _ + * 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" + +char *homedir(void); + +#endif /* HEADER_CURL_TOOL_HOMEDIR_H */ diff --git a/src/tool_operate.c b/src/tool_operate.c index 9a06098a0..3ee1d10d2 100644 --- a/src/tool_operate.c +++ b/src/tool_operate.c @@ -47,15 +47,6 @@ /* use our own printf() functions */ #include "curlx.h" -#include "curlutil.h" -#include "homedir.h" -#include "writeout.h" -#include "xattr.h" - -#ifdef USE_ENVIRONMENT -# include "writeenv.h" -#endif - #include "tool_binmode.h" #include "tool_cfgable.h" #include "tool_cb_dbg.h" @@ -70,6 +61,7 @@ #include "tool_easysrc.h" #include "tool_getparam.h" #include "tool_helpers.h" +#include "tool_homedir.h" #include "tool_libinfo.h" #include "tool_main.h" #include "tool_msgs.h" @@ -79,6 +71,10 @@ #include "tool_setopt.h" #include "tool_sleep.h" #include "tool_urlglob.h" +#include "tool_util.h" +#include "tool_writeenv.h" +#include "tool_writeout.h" +#include "tool_xattr.h" #include "memdebug.h" /* keep this as LAST include */ @@ -1210,7 +1206,7 @@ int operate(struct Configurable *config, int argc, argv_item_t argv[]) retry_numretries = config->req_retry; retry_sleep = retry_sleep_default; /* ms */ - retrystart = cutil_tvnow(); + retrystart = tvnow(); for(;;) { res = curl_easy_perform(curl); @@ -1227,7 +1223,7 @@ int operate(struct Configurable *config, int argc, argv_item_t argv[]) time */ if(retry_numretries && (!config->retry_maxtime || - (cutil_tvdiff(cutil_tvnow(), retrystart)< + (tvdiff(tvnow(), retrystart) < config->retry_maxtime*1000L)) ) { enum { RETRY_NO, @@ -1349,10 +1345,9 @@ int operate(struct Configurable *config, int argc, argv_item_t argv[]) if(config->writeout) ourWriteOut(curl, config->writeout); -#ifdef USE_ENVIRONMENT + if(config->writeenv) ourWriteEnv(curl); -#endif /* ** Code within this loop may jump directly here to label 'show_error' diff --git a/src/tool_operhlp.c b/src/tool_operhlp.c index d7dbe13c1..808d2d564 100644 --- a/src/tool_operhlp.c +++ b/src/tool_operhlp.c @@ -29,11 +29,10 @@ /* use our own printf() functions */ #include "curlx.h" -#include "version.h" - #include "tool_cfgable.h" #include "tool_convert.h" #include "tool_operhlp.h" +#include "tool_version.h" #include "memdebug.h" /* keep this as LAST include */ diff --git a/src/tool_paramhlp.c b/src/tool_paramhlp.c index 97681c1bd..adb12ce70 100644 --- a/src/tool_paramhlp.c +++ b/src/tool_paramhlp.c @@ -29,11 +29,10 @@ /* use our own printf() functions */ #include "curlx.h" -#include "homedir.h" -#include "getpass.h" - #include "tool_cfgable.h" #include "tool_getparam.h" +#include "tool_getpass.h" +#include "tool_homedir.h" #include "tool_msgs.h" #include "tool_paramhlp.h" diff --git a/src/tool_parsecfg.c b/src/tool_parsecfg.c index 44d077e37..b60d31830 100644 --- a/src/tool_parsecfg.c +++ b/src/tool_parsecfg.c @@ -27,11 +27,10 @@ /* use our own printf() functions */ #include "curlx.h" -#include "homedir.h" - #include "tool_cfgable.h" #include "tool_getparam.h" #include "tool_helpers.h" +#include "tool_homedir.h" #include "tool_msgs.h" #include "tool_parsecfg.h" diff --git a/src/tool_util.c b/src/tool_util.c new file mode 100644 index 000000000..79c998295 --- /dev/null +++ b/src/tool_util.c @@ -0,0 +1,135 @@ +/*************************************************************************** + * _ _ ____ _ + * 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" + +#include "tool_util.h" + +#include "memdebug.h" /* keep this as LAST include */ + +#if defined(WIN32) && !defined(MSDOS) + +struct timeval tool_tvnow(void) +{ + /* + ** GetTickCount() is available on _all_ Windows versions from W95 up + ** to nowadays. Returns milliseconds elapsed since last system boot, + ** increases monotonically and wraps once 49.7 days have elapsed. + */ + struct timeval now; + DWORD milliseconds = GetTickCount(); + now.tv_sec = milliseconds / 1000; + now.tv_usec = (milliseconds % 1000) * 1000; + return now; +} + +#elif defined(HAVE_CLOCK_GETTIME_MONOTONIC) + +struct timeval tool_tvnow(void) +{ + /* + ** clock_gettime() is granted to be increased monotonically when the + ** monotonic clock is queried. Time starting point is unspecified, it + ** could be the system start-up time, the Epoch, or something else, + ** in any case the time starting point does not change once that the + ** system has started up. + */ + struct timeval now; + struct timespec tsnow; + if(0 == clock_gettime(CLOCK_MONOTONIC, &tsnow)) { + now.tv_sec = tsnow.tv_sec; + now.tv_usec = tsnow.tv_nsec / 1000; + } + /* + ** Even when the configure process has truly detected monotonic clock + ** availability, it might happen that it is not actually available at + ** run-time. When this occurs simply fallback to other time source. + */ +#ifdef HAVE_GETTIMEOFDAY + else + (void)gettimeofday(&now, NULL); +#else + else { + now.tv_sec = (long)time(NULL); + now.tv_usec = 0; + } +#endif + return now; +} + +#elif defined(HAVE_GETTIMEOFDAY) + +struct timeval tool_tvnow(void) +{ + /* + ** gettimeofday() is not granted to be increased monotonically, due to + ** clock drifting and external source time synchronization it can jump + ** forward or backward in time. + */ + struct timeval now; + (void)gettimeofday(&now, NULL); + return now; +} + +#else + +struct timeval tool_tvnow(void) +{ + /* + ** time() returns the value of time in seconds since the Epoch. + */ + struct timeval now; + now.tv_sec = (long)time(NULL); + now.tv_usec = 0; + return now; +} + +#endif + +/* + * Make sure that the first argument is the more recent time, as otherwise + * we'll get a weird negative time-diff back... + * + * Returns: the time difference in number of milliseconds. + */ +long tool_tvdiff(struct timeval newer, struct timeval older) +{ + return (newer.tv_sec-older.tv_sec)*1000+ + (newer.tv_usec-older.tv_usec)/1000; +} + +/* + * Same as tool_tvdiff but with full usec resolution. + * + * Returns: the time difference in seconds with subsecond resolution. + */ +double tool_tvdiff_secs(struct timeval newer, struct timeval older) +{ + return (double)(newer.tv_sec-older.tv_sec)+ + (double)(newer.tv_usec-older.tv_usec)/1000000.0; +} + +/* return the number of seconds in the given input timeval struct */ +long tool_tvlong(struct timeval t1) +{ + return t1.tv_sec; +} + diff --git a/src/tool_util.h b/src/tool_util.h new file mode 100644 index 000000000..7c2a2978a --- /dev/null +++ b/src/tool_util.h @@ -0,0 +1,56 @@ +#ifndef HEADER_CURL_TOOL_UTIL_H +#define HEADER_CURL_TOOL_UTIL_H +/*************************************************************************** + * _ _ ____ _ + * 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" + +struct timeval tool_tvnow(void); + +/* + * Make sure that the first argument (t1) is the more recent time and t2 is + * the older time, as otherwise you get a weird negative time-diff back... + * + * Returns: the time difference in number of milliseconds. + */ +long tool_tvdiff(struct timeval t1, struct timeval t2); + +/* + * Same as tool_tvdiff but with full usec resolution. + * + * Returns: the time difference in seconds with subsecond resolution. + */ +double tool_tvdiff_secs(struct timeval t1, struct timeval t2); + +long tool_tvlong(struct timeval t1); + +#undef tvnow +#undef tvdiff +#undef tvdiff_secs +#undef tvlong + +#define tvnow() tool_tvnow() +#define tvdiff(a,b) tool_tvdiff((a), (b)) +#define tvdiff_secs(a,b) tool_tvdiff_secs((a), (b)) +#define tvlong(a) tool_tvlong((a)) + +#endif /* HEADER_CURL_TOOL_UTIL_H */ + diff --git a/src/tool_version.h b/src/tool_version.h new file mode 100644 index 000000000..569526bfe --- /dev/null +++ b/src/tool_version.h @@ -0,0 +1,34 @@ +#ifndef HEADER_CURL_TOOL_VERSION_H +#define HEADER_CURL_TOOL_VERSION_H +/*************************************************************************** + * _ _ ____ _ + * 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 + +#define CURL_NAME "curl" +#define CURL_COPYRIGHT LIBCURL_COPYRIGHT +#define CURL_VERSION LIBCURL_VERSION +#define CURL_VERSION_MAJOR LIBCURL_VERSION_MAJOR +#define CURL_VERSION_MINOR LIBCURL_VERSION_MINOR +#define CURL_VERSION_PATCH LIBCURL_VERSION_PATCH +#define CURL_ID CURL_NAME " " CURL_VERSION " (" OS ") " + +#endif /* HEADER_CURL_TOOL_VERSION_H */ diff --git a/src/tool_writeenv.c b/src/tool_writeenv.c new file mode 100644 index 000000000..232ab697c --- /dev/null +++ b/src/tool_writeenv.c @@ -0,0 +1,118 @@ +/*************************************************************************** + * _ _ ____ _ + * 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" + +#ifdef USE_ENVIRONMENT + +#ifdef __riscos__ +# include +#endif + +#include + +#define _MPRINTF_REPLACE /* use our functions only */ +#include + +#include "tool_writeenv.h" + +#include "memdebug.h" /* keep this as LAST include */ + +static const struct +{ + const char * name; + CURLINFO id; + enum { + writeenv_NONE, + writeenv_DOUBLE, + writeenv_LONG, + writeenv_STRING + } type; +} variables[14] = +{ + {"curl_url_effective", CURLINFO_EFFECTIVE_URL, writeenv_STRING}, + {"curl_http_code", CURLINFO_RESPONSE_CODE, writeenv_LONG}, + {"curl_time_total", CURLINFO_TOTAL_TIME, writeenv_DOUBLE}, + {"curl_time_namelookup", CURLINFO_NAMELOOKUP_TIME, writeenv_DOUBLE}, + {"curl_time_connect", CURLINFO_CONNECT_TIME, writeenv_DOUBLE}, + {"curl_time_pretransfer", CURLINFO_PRETRANSFER_TIME, writeenv_DOUBLE}, + {"curl_time_starttransfer", CURLINFO_STARTTRANSFER_TIME, writeenv_DOUBLE}, + {"curl_size_header", CURLINFO_HEADER_SIZE, writeenv_LONG}, + {"curl_size_request", CURLINFO_REQUEST_SIZE, writeenv_LONG}, + {"curl_size_download", CURLINFO_SIZE_DOWNLOAD, writeenv_DOUBLE}, + {"curl_size_upload", CURLINFO_SIZE_UPLOAD, writeenv_DOUBLE}, + {"curl_speed_download", CURLINFO_SPEED_DOWNLOAD, writeenv_DOUBLE}, + {"curl_speed_upload", CURLINFO_SPEED_UPLOAD, writeenv_DOUBLE}, + {NULL, 0, writeenv_NONE} + }; + +static void internalSetEnv(const char * name, char * value) +{ + /* Add your OS-specific code here. */ +#ifdef __riscos__ + _kernel_setenv(name, value); +#elif defined (CURLDEBUG) + curl_memlog("ENV %s = %s\n", name, value); +#endif + return; +} + +void ourWriteEnv(CURL *curl) +{ + unsigned int i; + char *string, numtext[10]; + long longinfo; + double doubleinfo; + + for(i=0; variables[i].name; i++) { + switch (variables[i].type) { + case writeenv_STRING: + if(curl_easy_getinfo(curl, variables[i].id, &string) == CURLE_OK) + internalSetEnv(variables[i].name, string); + else + internalSetEnv(variables[i].name, NULL); + break; + + case writeenv_LONG: + if(curl_easy_getinfo(curl, variables[i].id, &longinfo) == CURLE_OK) { + curl_msprintf(numtext, "%5ld", longinfo); + internalSetEnv(variables[i].name, numtext); + } + else + internalSetEnv(variables[i].name, NULL); + break; + case writeenv_DOUBLE: + if(curl_easy_getinfo(curl, variables[i].id, &doubleinfo) == CURLE_OK) { + curl_msprintf(numtext, "%6.2f", doubleinfo); + internalSetEnv(variables[i].name, numtext); + } + else + internalSetEnv(variables[i].name, NULL); + break; + default: + break; + } + } + + return; +} + +#endif diff --git a/src/tool_writeenv.h b/src/tool_writeenv.h new file mode 100644 index 000000000..74fdc97d9 --- /dev/null +++ b/src/tool_writeenv.h @@ -0,0 +1,35 @@ +#ifndef HEADER_CURL_TOOL_WRITEENV_H +#define HEADER_CURL_TOOL_WRITEENV_H +/*************************************************************************** + * _ _ ____ _ + * 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" + +#ifdef USE_ENVIRONMENT + +void ourWriteEnv(CURL *curl); + +#else +# define ourWriteEnv(x) Curl_nop_stmt +#endif + +#endif /* HEADER_CURL_TOOL_WRITEENV_H */ + diff --git a/src/tool_writeout.c b/src/tool_writeout.c new file mode 100644 index 000000000..1ea1c9881 --- /dev/null +++ b/src/tool_writeout.c @@ -0,0 +1,290 @@ +/*************************************************************************** + * _ _ ____ _ + * 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" + +#include + +#define _MPRINTF_REPLACE /* we want curl-functions instead of native ones */ +#include + +#include "tool_writeout.h" + +#include "memdebug.h" /* keep this as LAST include */ + +typedef enum { + VAR_NONE, /* must be the first */ + VAR_TOTAL_TIME, + VAR_NAMELOOKUP_TIME, + VAR_CONNECT_TIME, + VAR_APPCONNECT_TIME, + VAR_PRETRANSFER_TIME, + VAR_STARTTRANSFER_TIME, + VAR_SIZE_DOWNLOAD, + VAR_SIZE_UPLOAD, + VAR_SPEED_DOWNLOAD, + VAR_SPEED_UPLOAD, + VAR_HTTP_CODE, + VAR_HTTP_CODE_PROXY, + VAR_HEADER_SIZE, + VAR_REQUEST_SIZE, + VAR_EFFECTIVE_URL, + VAR_CONTENT_TYPE, + VAR_NUM_CONNECTS, + VAR_REDIRECT_TIME, + VAR_REDIRECT_COUNT, + VAR_FTP_ENTRY_PATH, + VAR_REDIRECT_URL, + VAR_SSL_VERIFY_RESULT, + VAR_NUM_OF_VARS /* must be the last */ +} replaceid; + +struct variable { + const char *name; + replaceid id; +}; + + +static const struct variable replacements[]={ + {"url_effective", VAR_EFFECTIVE_URL}, + {"http_code", VAR_HTTP_CODE}, + {"response_code", VAR_HTTP_CODE}, + {"http_connect", VAR_HTTP_CODE_PROXY}, + {"time_total", VAR_TOTAL_TIME}, + {"time_namelookup", VAR_NAMELOOKUP_TIME}, + {"time_connect", VAR_CONNECT_TIME}, + {"time_appconnect", VAR_APPCONNECT_TIME}, + {"time_pretransfer", VAR_PRETRANSFER_TIME}, + {"time_starttransfer", VAR_STARTTRANSFER_TIME}, + {"size_header", VAR_HEADER_SIZE}, + {"size_request", VAR_REQUEST_SIZE}, + {"size_download", VAR_SIZE_DOWNLOAD}, + {"size_upload", VAR_SIZE_UPLOAD}, + {"speed_download", VAR_SPEED_DOWNLOAD}, + {"speed_upload", VAR_SPEED_UPLOAD}, + {"content_type", VAR_CONTENT_TYPE}, + {"num_connects", VAR_NUM_CONNECTS}, + {"time_redirect", VAR_REDIRECT_TIME}, + {"num_redirects", VAR_REDIRECT_COUNT}, + {"ftp_entry_path", VAR_FTP_ENTRY_PATH}, + {"redirect_url", VAR_REDIRECT_URL}, + {"ssl_verify_result", VAR_SSL_VERIFY_RESULT}, + {NULL, VAR_NONE} +}; + +void ourWriteOut(CURL *curl, const char *writeinfo) +{ + FILE *stream = stdout; + const char *ptr = writeinfo; + char *stringp; + long longinfo; + double doubleinfo; + + while(ptr && *ptr) { + if('%' == *ptr) { + if('%' == ptr[1]) { + /* an escaped %-letter */ + fputc('%', stream); + ptr += 2; + } + else { + /* this is meant as a variable to output */ + char *end; + char keepit; + int i; + if(('{' == ptr[1]) && ((end = strchr(ptr, '}')) != NULL)) { + bool match = FALSE; + ptr += 2; /* pass the % and the { */ + keepit = *end; + *end = 0; /* zero terminate */ + for(i = 0; replacements[i].name; i++) { + if(curl_strequal(ptr, replacements[i].name)) { + match = TRUE; + switch(replacements[i].id) { + case VAR_EFFECTIVE_URL: + if((CURLE_OK == + curl_easy_getinfo(curl, CURLINFO_EFFECTIVE_URL, &stringp)) + && stringp) + fputs(stringp, stream); + break; + case VAR_HTTP_CODE: + if(CURLE_OK == + curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &longinfo)) + fprintf(stream, "%03ld", longinfo); + break; + case VAR_HTTP_CODE_PROXY: + if(CURLE_OK == + curl_easy_getinfo(curl, CURLINFO_HTTP_CONNECTCODE, + &longinfo)) + fprintf(stream, "%03ld", longinfo); + break; + case VAR_HEADER_SIZE: + if(CURLE_OK == + curl_easy_getinfo(curl, CURLINFO_HEADER_SIZE, &longinfo)) + fprintf(stream, "%ld", longinfo); + break; + case VAR_REQUEST_SIZE: + if(CURLE_OK == + curl_easy_getinfo(curl, CURLINFO_REQUEST_SIZE, &longinfo)) + fprintf(stream, "%ld", longinfo); + break; + case VAR_NUM_CONNECTS: + if(CURLE_OK == + curl_easy_getinfo(curl, CURLINFO_NUM_CONNECTS, &longinfo)) + fprintf(stream, "%ld", longinfo); + break; + case VAR_REDIRECT_COUNT: + if(CURLE_OK == + curl_easy_getinfo(curl, CURLINFO_REDIRECT_COUNT, &longinfo)) + fprintf(stream, "%ld", longinfo); + break; + case VAR_REDIRECT_TIME: + if(CURLE_OK == + curl_easy_getinfo(curl, CURLINFO_REDIRECT_TIME, + &doubleinfo)) + fprintf(stream, "%.3f", doubleinfo); + break; + case VAR_TOTAL_TIME: + if(CURLE_OK == + curl_easy_getinfo(curl, CURLINFO_TOTAL_TIME, &doubleinfo)) + fprintf(stream, "%.3f", doubleinfo); + break; + case VAR_NAMELOOKUP_TIME: + if(CURLE_OK == + curl_easy_getinfo(curl, CURLINFO_NAMELOOKUP_TIME, + &doubleinfo)) + fprintf(stream, "%.3f", doubleinfo); + break; + case VAR_CONNECT_TIME: + if(CURLE_OK == + curl_easy_getinfo(curl, CURLINFO_CONNECT_TIME, &doubleinfo)) + fprintf(stream, "%.3f", doubleinfo); + break; + case VAR_APPCONNECT_TIME: + if(CURLE_OK == + curl_easy_getinfo(curl, CURLINFO_APPCONNECT_TIME, + &doubleinfo)) + fprintf(stream, "%.3f", doubleinfo); + break; + case VAR_PRETRANSFER_TIME: + if(CURLE_OK == + curl_easy_getinfo(curl, CURLINFO_PRETRANSFER_TIME, + &doubleinfo)) + fprintf(stream, "%.3f", doubleinfo); + break; + case VAR_STARTTRANSFER_TIME: + if(CURLE_OK == + curl_easy_getinfo(curl, CURLINFO_STARTTRANSFER_TIME, + &doubleinfo)) + fprintf(stream, "%.3f", doubleinfo); + break; + case VAR_SIZE_UPLOAD: + if(CURLE_OK == + curl_easy_getinfo(curl, CURLINFO_SIZE_UPLOAD, &doubleinfo)) + fprintf(stream, "%.0f", doubleinfo); + break; + case VAR_SIZE_DOWNLOAD: + if(CURLE_OK == + curl_easy_getinfo(curl, CURLINFO_SIZE_DOWNLOAD, + &doubleinfo)) + fprintf(stream, "%.0f", doubleinfo); + break; + case VAR_SPEED_DOWNLOAD: + if(CURLE_OK == + curl_easy_getinfo(curl, CURLINFO_SPEED_DOWNLOAD, + &doubleinfo)) + fprintf(stream, "%.3f", doubleinfo); + break; + case VAR_SPEED_UPLOAD: + if(CURLE_OK == + curl_easy_getinfo(curl, CURLINFO_SPEED_UPLOAD, &doubleinfo)) + fprintf(stream, "%.3f", doubleinfo); + break; + case VAR_CONTENT_TYPE: + if((CURLE_OK == + curl_easy_getinfo(curl, CURLINFO_CONTENT_TYPE, &stringp)) + && stringp) + fputs(stringp, stream); + break; + case VAR_FTP_ENTRY_PATH: + if((CURLE_OK == + curl_easy_getinfo(curl, CURLINFO_FTP_ENTRY_PATH, &stringp)) + && stringp) + fputs(stringp, stream); + break; + case VAR_REDIRECT_URL: + if((CURLE_OK == + curl_easy_getinfo(curl, CURLINFO_REDIRECT_URL, &stringp)) + && stringp) + fputs(stringp, stream); + break; + case VAR_SSL_VERIFY_RESULT: + if(CURLE_OK == + curl_easy_getinfo(curl, CURLINFO_SSL_VERIFYRESULT, + &longinfo)) + fprintf(stream, "%ld", longinfo); + break; + default: + break; + } + break; + } + } + if(!match) { + fprintf(stderr, "curl: unknown --write-out variable: '%s'\n", ptr); + } + ptr = end + 1; /* pass the end */ + *end = keepit; + } + else { + /* illegal syntax, then just output the characters that are used */ + fputc('%', stream); + fputc(ptr[1], stream); + ptr += 2; + } + } + } + else if('\\' == *ptr) { + switch(ptr[1]) { + case 'r': + fputc('\r', stream); + break; + case 'n': + fputc('\n', stream); + break; + case 't': + fputc('\t', stream); + break; + default: + /* unknown, just output this */ + fputc(*ptr, stream); + fputc(ptr[1], stream); + break; + } + ptr += 2; + } + else { + fputc(*ptr, stream); + ptr++; + } + } + +} diff --git a/src/tool_writeout.h b/src/tool_writeout.h new file mode 100644 index 000000000..815cfcfff --- /dev/null +++ b/src/tool_writeout.h @@ -0,0 +1,28 @@ +#ifndef HEADER_CURL_TOOL_WRITEOUT_H +#define HEADER_CURL_TOOL_WRITEOUT_H +/*************************************************************************** + * _ _ ____ _ + * 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" + +void ourWriteOut(CURL *curl, const char *out); + +#endif /* HEADER_CURL_TOOL_WRITEOUT_H */ diff --git a/src/tool_xattr.c b/src/tool_xattr.c new file mode 100644 index 000000000..1f3883fa6 --- /dev/null +++ b/src/tool_xattr.c @@ -0,0 +1,78 @@ +/*************************************************************************** + * _ _ ____ _ + * 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" + +#ifdef HAVE_FSETXATTR +# include /* header from libc, not from libattr */ +#endif + +#include + +#include "tool_xattr.h" + +#include "memdebug.h" /* keep this as LAST include */ + +#ifdef HAVE_FSETXATTR + +/* mapping table of curl metadata to extended attribute names */ +static const struct xattr_mapping { + const char *attr; /* name of the xattr */ + CURLINFO info; +} mappings[] = { + /* mappings proposed by + * http://freedesktop.org/wiki/CommonExtendedAttributes + */ + { "user.xdg.origin.url", CURLINFO_EFFECTIVE_URL }, + { "user.mime_type", CURLINFO_CONTENT_TYPE }, + { NULL, CURLINFO_NONE } /* last element, abort loop here */ +}; + +/* store metadata from the curl request alongside the downloaded + * file using extended attributes + */ +int fwrite_xattr(CURL *curl, int fd) +{ + int i = 0; + int err = 0; + /* loop through all xattr-curlinfo pairs and abort on a set error */ + while(err == 0 && mappings[i].attr != NULL) { + char *value = NULL; + CURLcode rc = curl_easy_getinfo(curl, mappings[i].info, &value); + if(rc == CURLE_OK && value) { +#ifdef HAVE_FSETXATTR_6 + err = fsetxattr(fd, mappings[i].attr, value, strlen(value), 0, 0); +#elif defined(HAVE_FSETXATTR_5) + err = fsetxattr(fd, mappings[i].attr, value, strlen(value), 0); +#endif + } + i++; + } + return err; +} +#else +int fwrite_xattr(CURL *curl, int fd) +{ + (void)curl; + (void)fd; + return 0; +} +#endif diff --git a/src/tool_xattr.h b/src/tool_xattr.h new file mode 100644 index 000000000..14c8c944b --- /dev/null +++ b/src/tool_xattr.h @@ -0,0 +1,28 @@ +#ifndef HEADER_CURL_TOOL_XATTR_H +#define HEADER_CURL_TOOL_XATTR_H +/*************************************************************************** + * _ _ ____ _ + * 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" + +int fwrite_xattr(CURL *curl, int fd); + +#endif /* HEADER_CURL_TOOL_XATTR_H */ diff --git a/src/vc6curlsrc.dsp b/src/vc6curlsrc.dsp index d2f6a2fa0..4711703bc 100644 --- a/src/vc6curlsrc.dsp +++ b/src/vc6curlsrc.dsp @@ -139,18 +139,6 @@ LINK32=link.exe # PROP Default_Filter "" # Begin Source File -SOURCE=.\curlutil.c -# End Source File -# Begin Source File - -SOURCE=.\getpass.c -# End Source File -# Begin Source File - -SOURCE=.\homedir.c -# End Source File -# Begin Source File - SOURCE=.\hugehelp.c # End Source File # Begin Source File @@ -231,6 +219,10 @@ SOURCE=.\tool_getparam.c # End Source File # Begin Source File +SOURCE=.\tool_getpass.c +# End Source File +# Begin Source File + SOURCE=.\tool_help.c # End Source File # Begin Source File @@ -239,6 +231,10 @@ SOURCE=.\tool_helpers.c # End Source File # Begin Source File +SOURCE=.\tool_homedir.c +# End Source File +# Begin Source File + SOURCE=.\tool_libinfo.c # End Source File # Begin Source File @@ -287,19 +283,23 @@ SOURCE=.\tool_urlglob.c # End Source File # Begin Source File +SOURCE=.\tool_util.c +# End Source File +# Begin Source File + SOURCE=.\tool_vms.c # End Source File # Begin Source File -SOURCE=.\writeenv.c +SOURCE=.\tool_writeenv.c # End Source File # Begin Source File -SOURCE=.\writeout.c +SOURCE=.\tool_writeout.c # End Source File # Begin Source File -SOURCE=.\xattr.c +SOURCE=.\tool_xattr.c # End Source File # End Group # Begin Group "Header Files" @@ -311,18 +311,6 @@ SOURCE=".\config-win32.h" # End Source File # Begin Source File -SOURCE=.\curlutil.h -# End Source File -# Begin Source File - -SOURCE=.\getpass.h -# End Source File -# Begin Source File - -SOURCE=.\homedir.h -# End Source File -# Begin Source File - SOURCE=.\hugehelp.h # End Source File # Begin Source File @@ -407,6 +395,10 @@ SOURCE=.\tool_getparam.h # End Source File # Begin Source File +SOURCE=.\tool_getpass.h +# End Source File +# Begin Source File + SOURCE=.\tool_help.h # End Source File # Begin Source File @@ -415,6 +407,10 @@ SOURCE=.\tool_helpers.h # End Source File # Begin Source File +SOURCE=.\tool_homedir.h +# End Source File +# Begin Source File + SOURCE=.\tool_libinfo.h # End Source File # Begin Source File @@ -467,23 +463,27 @@ SOURCE=.\tool_urlglob.h # End Source File # Begin Source File -SOURCE=.\tool_vms.h +SOURCE=.\tool_util.h # End Source File # Begin Source File -SOURCE=.\version.h +SOURCE=.\tool_version.h +# End Source File +# Begin Source File + +SOURCE=.\tool_vms.h # End Source File # Begin Source File -SOURCE=.\writeenv.h +SOURCE=.\tool_writeenv.h # End Source File # Begin Source File -SOURCE=.\writeout.h +SOURCE=.\tool_writeout.h # End Source File # Begin Source File -SOURCE=.\xattr.h +SOURCE=.\tool_xattr.h # End Source File # End Group # Begin Group "Resource Files" diff --git a/src/version.h b/src/version.h deleted file mode 100644 index 569526bfe..000000000 --- a/src/version.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef HEADER_CURL_TOOL_VERSION_H -#define HEADER_CURL_TOOL_VERSION_H -/*************************************************************************** - * _ _ ____ _ - * 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 - -#define CURL_NAME "curl" -#define CURL_COPYRIGHT LIBCURL_COPYRIGHT -#define CURL_VERSION LIBCURL_VERSION -#define CURL_VERSION_MAJOR LIBCURL_VERSION_MAJOR -#define CURL_VERSION_MINOR LIBCURL_VERSION_MINOR -#define CURL_VERSION_PATCH LIBCURL_VERSION_PATCH -#define CURL_ID CURL_NAME " " CURL_VERSION " (" OS ") " - -#endif /* HEADER_CURL_TOOL_VERSION_H */ diff --git a/src/writeenv.c b/src/writeenv.c deleted file mode 100644 index b509449e2..000000000 --- a/src/writeenv.c +++ /dev/null @@ -1,118 +0,0 @@ -/*************************************************************************** - * _ _ ____ _ - * 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" - -#ifdef USE_ENVIRONMENT - -#ifdef __riscos__ -#include -#endif - -#include - -#define _MPRINTF_REPLACE /* use our functions only */ -#include - -#include "writeenv.h" - -#include "memdebug.h" /* keep this as LAST include */ - -static const struct -{ - const char * name; - CURLINFO id; - enum { - writeenv_NONE, - writeenv_DOUBLE, - writeenv_LONG, - writeenv_STRING - } type; -} variables[14] = -{ - {"curl_url_effective", CURLINFO_EFFECTIVE_URL, writeenv_STRING}, - {"curl_http_code", CURLINFO_RESPONSE_CODE, writeenv_LONG}, - {"curl_time_total", CURLINFO_TOTAL_TIME, writeenv_DOUBLE}, - {"curl_time_namelookup", CURLINFO_NAMELOOKUP_TIME, writeenv_DOUBLE}, - {"curl_time_connect", CURLINFO_CONNECT_TIME, writeenv_DOUBLE}, - {"curl_time_pretransfer", CURLINFO_PRETRANSFER_TIME, writeenv_DOUBLE}, - {"curl_time_starttransfer", CURLINFO_STARTTRANSFER_TIME, writeenv_DOUBLE}, - {"curl_size_header", CURLINFO_HEADER_SIZE, writeenv_LONG}, - {"curl_size_request", CURLINFO_REQUEST_SIZE, writeenv_LONG}, - {"curl_size_download", CURLINFO_SIZE_DOWNLOAD, writeenv_DOUBLE}, - {"curl_size_upload", CURLINFO_SIZE_UPLOAD, writeenv_DOUBLE}, - {"curl_speed_download", CURLINFO_SPEED_DOWNLOAD, writeenv_DOUBLE}, - {"curl_speed_upload", CURLINFO_SPEED_UPLOAD, writeenv_DOUBLE}, - {NULL, 0, writeenv_NONE} - }; - -static void internalSetEnv(const char * name, char * value) -{ - /* Add your OS-specific code here. */ -#ifdef __riscos__ - _kernel_setenv(name, value); -#elif defined (CURLDEBUG) - curl_memlog("ENV %s = %s\n", name, value); -#endif - return; -} - -void ourWriteEnv(CURL *curl) -{ - unsigned int i; - char *string, numtext[10]; - long longinfo; - double doubleinfo; - - for(i=0; variables[i].name; i++) { - switch (variables[i].type) { - case writeenv_STRING: - if(curl_easy_getinfo(curl, variables[i].id, &string) == CURLE_OK) - internalSetEnv(variables[i].name, string); - else - internalSetEnv(variables[i].name, NULL); - break; - - case writeenv_LONG: - if(curl_easy_getinfo(curl, variables[i].id, &longinfo) == CURLE_OK) { - curl_msprintf(numtext, "%5ld", longinfo); - internalSetEnv(variables[i].name, numtext); - } - else - internalSetEnv(variables[i].name, NULL); - break; - case writeenv_DOUBLE: - if(curl_easy_getinfo(curl, variables[i].id, &doubleinfo) == CURLE_OK) { - curl_msprintf(numtext, "%6.2f", doubleinfo); - internalSetEnv(variables[i].name, numtext); - } - else - internalSetEnv(variables[i].name, NULL); - break; - default: - break; - } - } - - return; -} - -#endif diff --git a/src/writeenv.h b/src/writeenv.h deleted file mode 100644 index 0816c34f9..000000000 --- a/src/writeenv.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef HEADER_CURL_WRITEENV_H -#define HEADER_CURL_WRITEENV_H -/*************************************************************************** - * _ _ ____ _ - * 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" - -void ourWriteEnv(CURL *curl); - -#endif /* HEADER_CURL_WRITEENV_H */ diff --git a/src/writeout.c b/src/writeout.c deleted file mode 100644 index 7e4105067..000000000 --- a/src/writeout.c +++ /dev/null @@ -1,297 +0,0 @@ -/*************************************************************************** - * _ _ ____ _ - * 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" - -#ifdef HAVE_SYS_TYPES_H -#include -#endif -#ifdef HAVE_SYS_SELECT_H -#include -#endif - -#include - -#define _MPRINTF_REPLACE /* we want curl-functions instead of native ones */ -#include - -#include "writeout.h" - -#include "memdebug.h" /* keep this as LAST include */ - -typedef enum { - VAR_NONE, /* must be the first */ - VAR_TOTAL_TIME, - VAR_NAMELOOKUP_TIME, - VAR_CONNECT_TIME, - VAR_APPCONNECT_TIME, - VAR_PRETRANSFER_TIME, - VAR_STARTTRANSFER_TIME, - VAR_SIZE_DOWNLOAD, - VAR_SIZE_UPLOAD, - VAR_SPEED_DOWNLOAD, - VAR_SPEED_UPLOAD, - VAR_HTTP_CODE, - VAR_HTTP_CODE_PROXY, - VAR_HEADER_SIZE, - VAR_REQUEST_SIZE, - VAR_EFFECTIVE_URL, - VAR_CONTENT_TYPE, - VAR_NUM_CONNECTS, - VAR_REDIRECT_TIME, - VAR_REDIRECT_COUNT, - VAR_FTP_ENTRY_PATH, - VAR_REDIRECT_URL, - VAR_SSL_VERIFY_RESULT, - VAR_NUM_OF_VARS /* must be the last */ -} replaceid; - -struct variable { - const char *name; - replaceid id; -}; - - -static const struct variable replacements[]={ - {"url_effective", VAR_EFFECTIVE_URL}, - {"http_code", VAR_HTTP_CODE}, - {"response_code", VAR_HTTP_CODE}, - {"http_connect", VAR_HTTP_CODE_PROXY}, - {"time_total", VAR_TOTAL_TIME}, - {"time_namelookup", VAR_NAMELOOKUP_TIME}, - {"time_connect", VAR_CONNECT_TIME}, - {"time_appconnect", VAR_APPCONNECT_TIME}, - {"time_pretransfer", VAR_PRETRANSFER_TIME}, - {"time_starttransfer", VAR_STARTTRANSFER_TIME}, - {"size_header", VAR_HEADER_SIZE}, - {"size_request", VAR_REQUEST_SIZE}, - {"size_download", VAR_SIZE_DOWNLOAD}, - {"size_upload", VAR_SIZE_UPLOAD}, - {"speed_download", VAR_SPEED_DOWNLOAD}, - {"speed_upload", VAR_SPEED_UPLOAD}, - {"content_type", VAR_CONTENT_TYPE}, - {"num_connects", VAR_NUM_CONNECTS}, - {"time_redirect", VAR_REDIRECT_TIME}, - {"num_redirects", VAR_REDIRECT_COUNT}, - {"ftp_entry_path", VAR_FTP_ENTRY_PATH}, - {"redirect_url", VAR_REDIRECT_URL}, - {"ssl_verify_result", VAR_SSL_VERIFY_RESULT}, - {NULL, VAR_NONE} -}; - -void ourWriteOut(CURL *curl, const char *writeinfo) -{ - FILE *stream = stdout; - const char *ptr=writeinfo; - char *stringp; - long longinfo; - double doubleinfo; - - while(ptr && *ptr) { - if('%' == *ptr) { - if('%' == ptr[1]) { - /* an escaped %-letter */ - fputc('%', stream); - ptr+=2; - } - else { - /* this is meant as a variable to output */ - char *end; - char keepit; - int i; - if(('{' == ptr[1]) && ((end = strchr(ptr, '}')) != NULL)) { - bool match = FALSE; - ptr+=2; /* pass the % and the { */ - keepit=*end; - *end=0; /* zero terminate */ - for(i=0; replacements[i].name; i++) { - if(curl_strequal(ptr, replacements[i].name)) { - match = TRUE; - switch(replacements[i].id) { - case VAR_EFFECTIVE_URL: - if((CURLE_OK == - curl_easy_getinfo(curl, CURLINFO_EFFECTIVE_URL, &stringp)) - && stringp) - fputs(stringp, stream); - break; - case VAR_HTTP_CODE: - if(CURLE_OK == - curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &longinfo)) - fprintf(stream, "%03ld", longinfo); - break; - case VAR_HTTP_CODE_PROXY: - if(CURLE_OK == - curl_easy_getinfo(curl, CURLINFO_HTTP_CONNECTCODE, - &longinfo)) - fprintf(stream, "%03ld", longinfo); - break; - case VAR_HEADER_SIZE: - if(CURLE_OK == - curl_easy_getinfo(curl, CURLINFO_HEADER_SIZE, &longinfo)) - fprintf(stream, "%ld", longinfo); - break; - case VAR_REQUEST_SIZE: - if(CURLE_OK == - curl_easy_getinfo(curl, CURLINFO_REQUEST_SIZE, &longinfo)) - fprintf(stream, "%ld", longinfo); - break; - case VAR_NUM_CONNECTS: - if(CURLE_OK == - curl_easy_getinfo(curl, CURLINFO_NUM_CONNECTS, &longinfo)) - fprintf(stream, "%ld", longinfo); - break; - case VAR_REDIRECT_COUNT: - if(CURLE_OK == - curl_easy_getinfo(curl, CURLINFO_REDIRECT_COUNT, &longinfo)) - fprintf(stream, "%ld", longinfo); - break; - case VAR_REDIRECT_TIME: - if(CURLE_OK == - curl_easy_getinfo(curl, CURLINFO_REDIRECT_TIME, - &doubleinfo)) - fprintf(stream, "%.3f", doubleinfo); - break; - case VAR_TOTAL_TIME: - if(CURLE_OK == - curl_easy_getinfo(curl, CURLINFO_TOTAL_TIME, &doubleinfo)) - fprintf(stream, "%.3f", doubleinfo); - break; - case VAR_NAMELOOKUP_TIME: - if(CURLE_OK == - curl_easy_getinfo(curl, CURLINFO_NAMELOOKUP_TIME, - &doubleinfo)) - fprintf(stream, "%.3f", doubleinfo); - break; - case VAR_CONNECT_TIME: - if(CURLE_OK == - curl_easy_getinfo(curl, CURLINFO_CONNECT_TIME, &doubleinfo)) - fprintf(stream, "%.3f", doubleinfo); - break; - case VAR_APPCONNECT_TIME: - if(CURLE_OK == - curl_easy_getinfo(curl, CURLINFO_APPCONNECT_TIME, - &doubleinfo)) - fprintf(stream, "%.3f", doubleinfo); - break; - case VAR_PRETRANSFER_TIME: - if(CURLE_OK == - curl_easy_getinfo(curl, CURLINFO_PRETRANSFER_TIME, - &doubleinfo)) - fprintf(stream, "%.3f", doubleinfo); - break; - case VAR_STARTTRANSFER_TIME: - if(CURLE_OK == - curl_easy_getinfo(curl, CURLINFO_STARTTRANSFER_TIME, - &doubleinfo)) - fprintf(stream, "%.3f", doubleinfo); - break; - case VAR_SIZE_UPLOAD: - if(CURLE_OK == - curl_easy_getinfo(curl, CURLINFO_SIZE_UPLOAD, &doubleinfo)) - fprintf(stream, "%.0f", doubleinfo); - break; - case VAR_SIZE_DOWNLOAD: - if(CURLE_OK == - curl_easy_getinfo(curl, CURLINFO_SIZE_DOWNLOAD, - &doubleinfo)) - fprintf(stream, "%.0f", doubleinfo); - break; - case VAR_SPEED_DOWNLOAD: - if(CURLE_OK == - curl_easy_getinfo(curl, CURLINFO_SPEED_DOWNLOAD, - &doubleinfo)) - fprintf(stream, "%.3f", doubleinfo); - break; - case VAR_SPEED_UPLOAD: - if(CURLE_OK == - curl_easy_getinfo(curl, CURLINFO_SPEED_UPLOAD, &doubleinfo)) - fprintf(stream, "%.3f", doubleinfo); - break; - case VAR_CONTENT_TYPE: - if((CURLE_OK == - curl_easy_getinfo(curl, CURLINFO_CONTENT_TYPE, &stringp)) - && stringp) - fputs(stringp, stream); - break; - case VAR_FTP_ENTRY_PATH: - if((CURLE_OK == - curl_easy_getinfo(curl, CURLINFO_FTP_ENTRY_PATH, &stringp)) - && stringp) - fputs(stringp, stream); - break; - case VAR_REDIRECT_URL: - if((CURLE_OK == - curl_easy_getinfo(curl, CURLINFO_REDIRECT_URL, &stringp)) - && stringp) - fputs(stringp, stream); - break; - case VAR_SSL_VERIFY_RESULT: - if(CURLE_OK == - curl_easy_getinfo(curl, CURLINFO_SSL_VERIFYRESULT, - &longinfo)) - fprintf(stream, "%ld", longinfo); - break; - default: - break; - } - break; - } - } - if(!match) { - fprintf(stderr, "curl: unknown --write-out variable: '%s'\n", ptr); - } - ptr=end+1; /* pass the end */ - *end = keepit; - } - else { - /* illegal syntax, then just output the characters that are used */ - fputc('%', stream); - fputc(ptr[1], stream); - ptr+=2; - } - } - } - else if('\\' == *ptr) { - switch(ptr[1]) { - case 'r': - fputc('\r', stream); - break; - case 'n': - fputc('\n', stream); - break; - case 't': - fputc('\t', stream); - break; - default: - /* unknown, just output this */ - fputc(*ptr, stream); - fputc(ptr[1], stream); - break; - } - ptr+=2; - } - else { - fputc(*ptr, stream); - ptr++; - } - } - -} diff --git a/src/writeout.h b/src/writeout.h deleted file mode 100644 index 92d8ea5a9..000000000 --- a/src/writeout.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef HEADER_CURL_WRITEOUT_H -#define HEADER_CURL_WRITEOUT_H -/*************************************************************************** - * _ _ ____ _ - * 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" - -void ourWriteOut(CURL *curl, const char *out); - -#endif /* HEADER_CURL_WRITEOUT_H */ diff --git a/src/xattr.c b/src/xattr.c deleted file mode 100644 index 146acf94c..000000000 --- a/src/xattr.c +++ /dev/null @@ -1,78 +0,0 @@ -/*************************************************************************** - * _ _ ____ _ - * 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" - -#ifdef HAVE_FSETXATTR -#include -#include /* include header from libc, not from libattr */ -#endif - -#include -#include "xattr.h" - -#include "memdebug.h" /* keep this as LAST include */ - -#ifdef HAVE_FSETXATTR - -/* mapping table of curl metadata to extended attribute names */ -static const struct xattr_mapping { - const char *attr; /* name of the xattr */ - CURLINFO info; -} mappings[] = { - /* mappings proposed by - * http://freedesktop.org/wiki/CommonExtendedAttributes - */ - { "user.xdg.origin.url", CURLINFO_EFFECTIVE_URL }, - { "user.mime_type", CURLINFO_CONTENT_TYPE }, - { NULL, CURLINFO_NONE } /* last element, abort loop here */ -}; - -/* store metadata from the curl request alongside the downloaded - * file using extended attributes - */ -int fwrite_xattr(CURL *curl, int fd) -{ - int i = 0; - int err = 0; - /* loop through all xattr-curlinfo pairs and abort on a set error */ - while(err == 0 && mappings[i].attr != NULL) { - char *value = NULL; - CURLcode rc = curl_easy_getinfo(curl, mappings[i].info, &value); - if(rc == CURLE_OK && value) { -#ifdef HAVE_FSETXATTR_6 - err = fsetxattr( fd, mappings[i].attr, value, strlen(value), 0, 0 ); -#elif defined(HAVE_FSETXATTR_5) - err = fsetxattr( fd, mappings[i].attr, value, strlen(value), 0 ); -#endif - } - i++; - } - return err; -} -#else -int fwrite_xattr(CURL *curl, int fd) -{ - (void)curl; - (void)fd; - return 0; -} -#endif diff --git a/src/xattr.h b/src/xattr.h deleted file mode 100644 index ef528eafa..000000000 --- a/src/xattr.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef HEADER_CURL_XATTR_H -#define HEADER_CURL_XATTR_H -/*************************************************************************** - * _ _ ____ _ - * 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" - -int fwrite_xattr(CURL *curl, int fd); - -#endif /* HEADER_CURL_XATTR_H */ -- cgit v1.2.3