curl tool: code moved to tool_*.[ch] files
This commit is contained in:
parent
ca2c326361
commit
49b79b7631
@ -80,7 +80,7 @@ removethis(){
|
|||||||
# Ensure that buildconf runs from the subdirectory where configure.ac lives
|
# Ensure that buildconf runs from the subdirectory where configure.ac lives
|
||||||
#
|
#
|
||||||
if test ! -f configure.ac ||
|
if test ! -f configure.ac ||
|
||||||
test ! -f src/main.c ||
|
test ! -f src/tool_main.c ||
|
||||||
test ! -f lib/urldata.h ||
|
test ! -f lib/urldata.h ||
|
||||||
test ! -f include/curl/curl.h; then
|
test ! -f include/curl/curl.h; then
|
||||||
echo "Can not run buildconf from outside of curl's source subdirectory!"
|
echo "Can not run buildconf from outside of curl's source subdirectory!"
|
||||||
|
@ -8,7 +8,7 @@ UID 0x00000000 0xF0206442
|
|||||||
|
|
||||||
SOURCEPATH ../../../src
|
SOURCEPATH ../../../src
|
||||||
SOURCE \
|
SOURCE \
|
||||||
main.c hugehelp.c urlglob.c writeout.c writeenv.c \
|
hugehelp.c urlglob.c writeout.c writeenv.c \
|
||||||
getpass.c homedir.c curlutil.c xattr.c \
|
getpass.c homedir.c curlutil.c xattr.c \
|
||||||
tool_binmode.c \
|
tool_binmode.c \
|
||||||
tool_bname.c \
|
tool_bname.c \
|
||||||
@ -25,11 +25,20 @@ SOURCE \
|
|||||||
tool_doswin.c \
|
tool_doswin.c \
|
||||||
tool_easysrc.c \
|
tool_easysrc.c \
|
||||||
tool_formparse.c \
|
tool_formparse.c \
|
||||||
|
tool_getparam.c \
|
||||||
|
tool_help.c \
|
||||||
|
tool_helpers.c \
|
||||||
tool_libinfo.c \
|
tool_libinfo.c \
|
||||||
|
tool_main.c \
|
||||||
tool_mfiles.c \
|
tool_mfiles.c \
|
||||||
tool_msgs.c \
|
tool_msgs.c \
|
||||||
tool_myfunc.c \
|
tool_operate.c \
|
||||||
|
tool_operhlp.c \
|
||||||
|
tool_panykey.c \
|
||||||
|
tool_paramhlp.c \
|
||||||
|
tool_parsecfg.c \
|
||||||
tool_setopt.c \
|
tool_setopt.c \
|
||||||
|
tool_sleep.c \
|
||||||
tool_vms.c
|
tool_vms.c
|
||||||
|
|
||||||
SOURCEPATH ../../../lib
|
SOURCEPATH ../../../lib
|
||||||
|
@ -14,7 +14,7 @@ CURLX_ONES = $(top_srcdir)/lib/strtoofft.c \
|
|||||||
$(top_srcdir)/lib/rawstr.c \
|
$(top_srcdir)/lib/rawstr.c \
|
||||||
$(top_srcdir)/lib/nonblock.c
|
$(top_srcdir)/lib/nonblock.c
|
||||||
|
|
||||||
CURL_CFILES = main.c hugehelp.c urlglob.c writeout.c writeenv.c \
|
CURL_CFILES = hugehelp.c urlglob.c writeout.c writeenv.c \
|
||||||
getpass.c homedir.c curlutil.c xattr.c \
|
getpass.c homedir.c curlutil.c xattr.c \
|
||||||
tool_binmode.c \
|
tool_binmode.c \
|
||||||
tool_bname.c \
|
tool_bname.c \
|
||||||
@ -31,11 +31,20 @@ CURL_CFILES = main.c hugehelp.c urlglob.c writeout.c writeenv.c \
|
|||||||
tool_doswin.c \
|
tool_doswin.c \
|
||||||
tool_easysrc.c \
|
tool_easysrc.c \
|
||||||
tool_formparse.c \
|
tool_formparse.c \
|
||||||
|
tool_getparam.c \
|
||||||
|
tool_help.c \
|
||||||
|
tool_helpers.c \
|
||||||
tool_libinfo.c \
|
tool_libinfo.c \
|
||||||
|
tool_main.c \
|
||||||
tool_mfiles.c \
|
tool_mfiles.c \
|
||||||
tool_msgs.c \
|
tool_msgs.c \
|
||||||
tool_myfunc.c \
|
tool_operate.c \
|
||||||
|
tool_operhlp.c \
|
||||||
|
tool_panykey.c \
|
||||||
|
tool_paramhlp.c \
|
||||||
|
tool_parsecfg.c \
|
||||||
tool_setopt.c \
|
tool_setopt.c \
|
||||||
|
tool_sleep.c \
|
||||||
tool_vms.c
|
tool_vms.c
|
||||||
|
|
||||||
CURL_HFILES = hugehelp.h setup.h config-win32.h config-mac.h \
|
CURL_HFILES = hugehelp.h setup.h config-win32.h config-mac.h \
|
||||||
@ -56,12 +65,21 @@ CURL_HFILES = hugehelp.h setup.h config-win32.h config-mac.h \
|
|||||||
tool_doswin.h \
|
tool_doswin.h \
|
||||||
tool_easysrc.h \
|
tool_easysrc.h \
|
||||||
tool_formparse.h \
|
tool_formparse.h \
|
||||||
|
tool_getparam.h \
|
||||||
|
tool_help.h \
|
||||||
|
tool_helpers.h \
|
||||||
tool_libinfo.h \
|
tool_libinfo.h \
|
||||||
|
tool_main.h \
|
||||||
tool_mfiles.h \
|
tool_mfiles.h \
|
||||||
tool_msgs.h \
|
tool_msgs.h \
|
||||||
tool_myfunc.h \
|
tool_operate.h \
|
||||||
|
tool_operhlp.h \
|
||||||
|
tool_panykey.h \
|
||||||
|
tool_paramhlp.h \
|
||||||
|
tool_parsecfg.h \
|
||||||
tool_sdecls.h \
|
tool_sdecls.h \
|
||||||
tool_setopt.h \
|
tool_setopt.h \
|
||||||
|
tool_sleep.h \
|
||||||
tool_vms.h
|
tool_vms.h
|
||||||
|
|
||||||
curl_SOURCES = $(CURL_CFILES) $(CURLX_ONES) $(CURL_HFILES)
|
curl_SOURCES = $(CURL_CFILES) $(CURLX_ONES) $(CURL_HFILES)
|
||||||
|
@ -42,7 +42,7 @@ PROGRAM_NAME = curl.exe
|
|||||||
# Verify that current subdir is curl's 'src'
|
# Verify that current subdir is curl's 'src'
|
||||||
# -------------------------------------------
|
# -------------------------------------------
|
||||||
|
|
||||||
!IF ! EXIST(.\main.c)
|
!IF ! EXIST(.\tool_main.c)
|
||||||
! MESSAGE Can not process this makefile from outside of curl's 'src' subdirectory.
|
! MESSAGE Can not process this makefile from outside of curl's 'src' subdirectory.
|
||||||
! MESSAGE Change to curl's 'src' subdirectory, and try again.
|
! MESSAGE Change to curl's 'src' subdirectory, and try again.
|
||||||
! ERROR See previous message.
|
! ERROR See previous message.
|
||||||
@ -137,7 +137,6 @@ RELEASE_OBJS= \
|
|||||||
getpassr.obj \
|
getpassr.obj \
|
||||||
homedirr.obj \
|
homedirr.obj \
|
||||||
hugehelpr.obj \
|
hugehelpr.obj \
|
||||||
mainr.obj \
|
|
||||||
nonblockr.obj \
|
nonblockr.obj \
|
||||||
rawstrr.obj \
|
rawstrr.obj \
|
||||||
strtoofftr.obj \
|
strtoofftr.obj \
|
||||||
@ -156,11 +155,20 @@ RELEASE_OBJS= \
|
|||||||
tool_doswinr.obj \
|
tool_doswinr.obj \
|
||||||
tool_easysrcr.obj \
|
tool_easysrcr.obj \
|
||||||
tool_formparser.obj \
|
tool_formparser.obj \
|
||||||
|
tool_getparamr.obj \
|
||||||
|
tool_helpr.obj \
|
||||||
|
tool_helpersr.obj \
|
||||||
tool_libinfor.obj \
|
tool_libinfor.obj \
|
||||||
|
tool_mainr.obj \
|
||||||
tool_mfilesr.obj \
|
tool_mfilesr.obj \
|
||||||
tool_msgsr.obj \
|
tool_msgsr.obj \
|
||||||
tool_myfuncr.obj \
|
tool_operater.obj \
|
||||||
|
tool_operhlpr.obj \
|
||||||
|
tool_panykeyr.obj \
|
||||||
|
tool_paramhlpr.obj \
|
||||||
|
tool_parsecfgr.obj \
|
||||||
tool_setoptr.obj \
|
tool_setoptr.obj \
|
||||||
|
tool_sleepr.obj \
|
||||||
tool_vmsr.obj \
|
tool_vmsr.obj \
|
||||||
urlglobr.obj \
|
urlglobr.obj \
|
||||||
writeoutr.obj \
|
writeoutr.obj \
|
||||||
@ -172,7 +180,6 @@ DEBUG_OBJS= \
|
|||||||
getpassd.obj \
|
getpassd.obj \
|
||||||
homedird.obj \
|
homedird.obj \
|
||||||
hugehelpd.obj \
|
hugehelpd.obj \
|
||||||
maind.obj \
|
|
||||||
nonblockd.obj \
|
nonblockd.obj \
|
||||||
rawstrd.obj \
|
rawstrd.obj \
|
||||||
strtoofftd.obj \
|
strtoofftd.obj \
|
||||||
@ -191,11 +198,20 @@ DEBUG_OBJS= \
|
|||||||
tool_doswind.obj \
|
tool_doswind.obj \
|
||||||
tool_easysrcd.obj \
|
tool_easysrcd.obj \
|
||||||
tool_formparsed.obj \
|
tool_formparsed.obj \
|
||||||
|
tool_getparamd.obj \
|
||||||
|
tool_helpd.obj \
|
||||||
|
tool_helpersd.obj \
|
||||||
tool_libinfod.obj \
|
tool_libinfod.obj \
|
||||||
|
tool_maind.obj \
|
||||||
tool_mfilesd.obj \
|
tool_mfilesd.obj \
|
||||||
tool_msgsd.obj \
|
tool_msgsd.obj \
|
||||||
tool_myfuncd.obj \
|
tool_operated.obj \
|
||||||
|
tool_operhlpd.obj \
|
||||||
|
tool_panykeyd.obj \
|
||||||
|
tool_paramhlpd.obj \
|
||||||
|
tool_parsecfgd.obj \
|
||||||
tool_setoptd.obj \
|
tool_setoptd.obj \
|
||||||
|
tool_sleepd.obj \
|
||||||
tool_vmsd.obj \
|
tool_vmsd.obj \
|
||||||
urlglobd.obj \
|
urlglobd.obj \
|
||||||
writeoutd.obj \
|
writeoutd.obj \
|
||||||
@ -370,22 +386,38 @@ tool_easysrcr.obj: tool_easysrc.c
|
|||||||
$(CCR) $(CFLAGS) /Fo"$@" tool_easysrc.c
|
$(CCR) $(CFLAGS) /Fo"$@" tool_easysrc.c
|
||||||
tool_formparser.obj: tool_formparse.c
|
tool_formparser.obj: tool_formparse.c
|
||||||
$(CCR) $(CFLAGS) /Fo"$@" tool_formparse.c
|
$(CCR) $(CFLAGS) /Fo"$@" tool_formparse.c
|
||||||
|
tool_getparamr.obj: tool_getparam.c
|
||||||
|
$(CCR) $(CFLAGS) /Fo"$@" tool_getparam.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_libinfor.obj: tool_libinfo.c
|
tool_libinfor.obj: tool_libinfo.c
|
||||||
$(CCR) $(CFLAGS) /Fo"$@" tool_libinfo.c
|
$(CCR) $(CFLAGS) /Fo"$@" tool_libinfo.c
|
||||||
|
tool_mainr.obj: tool_main.c
|
||||||
|
$(CCR) $(CFLAGS) /Fo"$@" tool_main.c
|
||||||
tool_mfilesr.obj: tool_mfiles.c
|
tool_mfilesr.obj: tool_mfiles.c
|
||||||
$(CCR) $(CFLAGS) /Fo"$@" tool_mfiles.c
|
$(CCR) $(CFLAGS) /Fo"$@" tool_mfiles.c
|
||||||
tool_msgsr.obj: tool_msgs.c
|
tool_msgsr.obj: tool_msgs.c
|
||||||
$(CCR) $(CFLAGS) /Fo"$@" tool_msgs.c
|
$(CCR) $(CFLAGS) /Fo"$@" tool_msgs.c
|
||||||
tool_myfuncr.obj: tool_myfunc.c
|
tool_operater.obj: tool_operate.c
|
||||||
$(CCR) $(CFLAGS) /Fo"$@" tool_myfunc.c
|
$(CCR) $(CFLAGS) /Fo"$@" tool_operate.c
|
||||||
|
tool_operhlpr.obj: tool_operhlp.c
|
||||||
|
$(CCR) $(CFLAGS) /Fo"$@" tool_operhlp.c
|
||||||
|
tool_panykeyr.obj: tool_panykey.c
|
||||||
|
$(CCR) $(CFLAGS) /Fo"$@" tool_panykey.c
|
||||||
|
tool_paramhlpr.obj: tool_paramhlp.c
|
||||||
|
$(CCR) $(CFLAGS) /Fo"$@" tool_paramhlp.c
|
||||||
|
tool_parsecfgr.obj: tool_parsecfg.c
|
||||||
|
$(CCR) $(CFLAGS) /Fo"$@" tool_parsecfg.c
|
||||||
tool_setoptr.obj: tool_setopt.c
|
tool_setoptr.obj: tool_setopt.c
|
||||||
$(CCR) $(CFLAGS) /Fo"$@" tool_setopt.c
|
$(CCR) $(CFLAGS) /Fo"$@" tool_setopt.c
|
||||||
|
tool_sleepr.obj: tool_sleep.c
|
||||||
|
$(CCR) $(CFLAGS) /Fo"$@" tool_sleep.c
|
||||||
tool_vmsr.obj: tool_vms.c
|
tool_vmsr.obj: tool_vms.c
|
||||||
$(CCR) $(CFLAGS) /Fo"$@" tool_vms.c
|
$(CCR) $(CFLAGS) /Fo"$@" tool_vms.c
|
||||||
xattrr.obj: xattr.c
|
xattrr.obj: xattr.c
|
||||||
$(CCR) $(CFLAGS) /Fo"$@" xattr.c
|
$(CCR) $(CFLAGS) /Fo"$@" xattr.c
|
||||||
mainr.obj: main.c
|
|
||||||
$(CCR) $(CFLAGS) /Fo"$@" main.c
|
|
||||||
curlr.res : curl.rc
|
curlr.res : curl.rc
|
||||||
$(RCR) $(RESFLAGS) /Fo"$@" curl.rc
|
$(RCR) $(RESFLAGS) /Fo"$@" curl.rc
|
||||||
|
|
||||||
@ -438,22 +470,38 @@ tool_easysrcd.obj: tool_easysrc.c
|
|||||||
$(CCD) $(CFLAGS) /Fo"$@" tool_easysrc.c
|
$(CCD) $(CFLAGS) /Fo"$@" tool_easysrc.c
|
||||||
tool_formparsed.obj: tool_formparse.c
|
tool_formparsed.obj: tool_formparse.c
|
||||||
$(CCD) $(CFLAGS) /Fo"$@" tool_formparse.c
|
$(CCD) $(CFLAGS) /Fo"$@" tool_formparse.c
|
||||||
|
tool_getparamd.obj: tool_getparam.c
|
||||||
|
$(CCD) $(CFLAGS) /Fo"$@" tool_getparam.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_libinfod.obj: tool_libinfo.c
|
tool_libinfod.obj: tool_libinfo.c
|
||||||
$(CCD) $(CFLAGS) /Fo"$@" tool_libinfo.c
|
$(CCD) $(CFLAGS) /Fo"$@" tool_libinfo.c
|
||||||
|
tool_maind.obj: tool_main.c
|
||||||
|
$(CCD) $(CFLAGS) /Fo"$@" tool_main.c
|
||||||
tool_mfilesd.obj: tool_mfiles.c
|
tool_mfilesd.obj: tool_mfiles.c
|
||||||
$(CCD) $(CFLAGS) /Fo"$@" tool_mfiles.c
|
$(CCD) $(CFLAGS) /Fo"$@" tool_mfiles.c
|
||||||
tool_msgsd.obj: tool_msgs.c
|
tool_msgsd.obj: tool_msgs.c
|
||||||
$(CCD) $(CFLAGS) /Fo"$@" tool_msgs.c
|
$(CCD) $(CFLAGS) /Fo"$@" tool_msgs.c
|
||||||
tool_myfuncd.obj: tool_myfunc.c
|
tool_operated.obj: tool_operate.c
|
||||||
$(CCD) $(CFLAGS) /Fo"$@" tool_myfunc.c
|
$(CCD) $(CFLAGS) /Fo"$@" tool_operate.c
|
||||||
|
tool_operhlpd.obj: tool_operhlp.c
|
||||||
|
$(CCD) $(CFLAGS) /Fo"$@" tool_operhlp.c
|
||||||
|
tool_panykeyd.obj: tool_panykey.c
|
||||||
|
$(CCD) $(CFLAGS) /Fo"$@" tool_panykey.c
|
||||||
|
tool_paramhlpd.obj: tool_paramhlp.c
|
||||||
|
$(CCD) $(CFLAGS) /Fo"$@" tool_paramhlp.c
|
||||||
|
tool_parsecfgd.obj: tool_parsecfg.c
|
||||||
|
$(CCD) $(CFLAGS) /Fo"$@" tool_parsecfg.c
|
||||||
tool_setoptd.obj: tool_setopt.c
|
tool_setoptd.obj: tool_setopt.c
|
||||||
$(CCD) $(CFLAGS) /Fo"$@" tool_setopt.c
|
$(CCD) $(CFLAGS) /Fo"$@" tool_setopt.c
|
||||||
|
tool_sleepd.obj: tool_sleep.c
|
||||||
|
$(CCD) $(CFLAGS) /Fo"$@" tool_sleep.c
|
||||||
tool_vmsd.obj: tool_vms.c
|
tool_vmsd.obj: tool_vms.c
|
||||||
$(CCD) $(CFLAGS) /Fo"$@" tool_vms.c
|
$(CCD) $(CFLAGS) /Fo"$@" tool_vms.c
|
||||||
xattrd.obj: xattr.c
|
xattrd.obj: xattr.c
|
||||||
$(CCD) $(CFLAGS) /Fo"$@" xattr.c
|
$(CCD) $(CFLAGS) /Fo"$@" xattr.c
|
||||||
maind.obj: main.c
|
|
||||||
$(CCD) $(CFLAGS) /Fo"$@" main.c
|
|
||||||
curld.res : curl.rc
|
curld.res : curl.rc
|
||||||
$(RCD) $(RESFLAGS) /Fo"$@" curl.rc
|
$(RCD) $(RESFLAGS) /Fo"$@" curl.rc
|
||||||
|
|
||||||
|
4309
src/main.c
4309
src/main.c
File diff suppressed because it is too large
Load Diff
@ -231,6 +231,19 @@ static char *rename_if_dos_device_name (char *file_name)
|
|||||||
return file_name;
|
return file_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(MSDOS) && (defined(__DJGPP__) || defined(__GO32__))
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Disable program default argument globbing. We do it on our own.
|
||||||
|
*/
|
||||||
|
char **__crt0_glob_function(char *arg)
|
||||||
|
{
|
||||||
|
(void)arg;
|
||||||
|
return (char**)0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* MSDOS && (__DJGPP__ || __GO32__) */
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -27,6 +27,12 @@
|
|||||||
|
|
||||||
char *sanitize_dos_name(char *file_name);
|
char *sanitize_dos_name(char *file_name);
|
||||||
|
|
||||||
|
#if defined(MSDOS) && (defined(__DJGPP__) || defined(__GO32__))
|
||||||
|
|
||||||
|
char **__crt0_glob_function(char *arg);
|
||||||
|
|
||||||
|
#endif /* MSDOS && (__DJGPP__ || __GO32__) */
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
|
|
||||||
CURLcode FindWin32CACert(struct Configurable *config, const char *bundle_file);
|
CURLcode FindWin32CACert(struct Configurable *config, const char *bundle_file);
|
||||||
|
@ -31,3 +31,4 @@ extern struct curl_slist *easysrc_remarks;
|
|||||||
void dumpeasysrc(struct Configurable *config);
|
void dumpeasysrc(struct Configurable *config);
|
||||||
|
|
||||||
#endif /* HEADER_CURL_TOOL_EASYSRC_H */
|
#endif /* HEADER_CURL_TOOL_EASYSRC_H */
|
||||||
|
|
||||||
|
1604
src/tool_getparam.c
Normal file
1604
src/tool_getparam.c
Normal file
File diff suppressed because it is too large
Load Diff
46
src/tool_getparam.h
Normal file
46
src/tool_getparam.h
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
#ifndef HEADER_CURL_TOOL_GETPARAM_H
|
||||||
|
#define HEADER_CURL_TOOL_GETPARAM_H
|
||||||
|
/***************************************************************************
|
||||||
|
* _ _ ____ _
|
||||||
|
* Project ___| | | | _ \| |
|
||||||
|
* / __| | | | |_) | |
|
||||||
|
* | (__| |_| | _ <| |___
|
||||||
|
* \___|\___/|_| \_\_____|
|
||||||
|
*
|
||||||
|
* Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||||
|
*
|
||||||
|
* This software is licensed as described in the file COPYING, which
|
||||||
|
* you should have received as part of this distribution. The terms
|
||||||
|
* are also available at http://curl.haxx.se/docs/copyright.html.
|
||||||
|
*
|
||||||
|
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
||||||
|
* copies of the Software, and permit persons to whom the Software is
|
||||||
|
* furnished to do so, under the terms of the COPYING file.
|
||||||
|
*
|
||||||
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||||
|
* KIND, either express or implied.
|
||||||
|
*
|
||||||
|
***************************************************************************/
|
||||||
|
#include "setup.h"
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
PARAM_OK,
|
||||||
|
PARAM_OPTION_AMBIGUOUS,
|
||||||
|
PARAM_OPTION_UNKNOWN,
|
||||||
|
PARAM_REQUIRES_PARAMETER,
|
||||||
|
PARAM_BAD_USE,
|
||||||
|
PARAM_HELP_REQUESTED,
|
||||||
|
PARAM_GOT_EXTRA_PARAMETER,
|
||||||
|
PARAM_BAD_NUMERIC,
|
||||||
|
PARAM_LIBCURL_DOESNT_SUPPORT,
|
||||||
|
PARAM_NO_MEM,
|
||||||
|
PARAM_LAST
|
||||||
|
} ParameterError;
|
||||||
|
|
||||||
|
ParameterError getparameter(char *flag,
|
||||||
|
char *nextarg,
|
||||||
|
bool *usedarg,
|
||||||
|
struct Configurable *config);
|
||||||
|
|
||||||
|
#endif /* HEADER_CURL_TOOL_GETPARAM_H */
|
||||||
|
|
238
src/tool_help.c
Normal file
238
src/tool_help.c
Normal file
@ -0,0 +1,238 @@
|
|||||||
|
/***************************************************************************
|
||||||
|
* _ _ ____ _
|
||||||
|
* Project ___| | | | _ \| |
|
||||||
|
* / __| | | | |_) | |
|
||||||
|
* | (__| |_| | _ <| |___
|
||||||
|
* \___|\___/|_| \_\_____|
|
||||||
|
*
|
||||||
|
* Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||||
|
*
|
||||||
|
* This software is licensed as described in the file COPYING, which
|
||||||
|
* you should have received as part of this distribution. The terms
|
||||||
|
* are also available at http://curl.haxx.se/docs/copyright.html.
|
||||||
|
*
|
||||||
|
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
||||||
|
* copies of the Software, and permit persons to whom the Software is
|
||||||
|
* furnished to do so, under the terms of the COPYING file.
|
||||||
|
*
|
||||||
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||||
|
* KIND, either express or implied.
|
||||||
|
*
|
||||||
|
***************************************************************************/
|
||||||
|
#include "setup.h"
|
||||||
|
|
||||||
|
#include "tool_panykey.h"
|
||||||
|
#include "tool_help.h"
|
||||||
|
|
||||||
|
#include "memdebug.h" /* keep this as LAST include */
|
||||||
|
|
||||||
|
#ifdef MSDOS
|
||||||
|
# define USE_WATT32
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* A few of these source lines are >80 columns wide, but that's only because
|
||||||
|
* breaking the strings narrower makes this chunk look even worse!
|
||||||
|
*
|
||||||
|
* Starting with 7.18.0, this list of command line options is sorted based
|
||||||
|
* on the long option name. It is not done automatically, although a command
|
||||||
|
* line like the following can help out:
|
||||||
|
*
|
||||||
|
* curl --help | cut -c5- | grep "^-" | sort
|
||||||
|
*/
|
||||||
|
|
||||||
|
static const char *const helptext[] = {
|
||||||
|
"Usage: curl [options...] <url>",
|
||||||
|
"Options: (H) means HTTP/HTTPS only, (F) means FTP only",
|
||||||
|
" --anyauth Pick \"any\" authentication method (H)",
|
||||||
|
" -a, --append Append to target file when uploading (F/SFTP)",
|
||||||
|
" --basic Use HTTP Basic Authentication (H)",
|
||||||
|
" --cacert FILE CA certificate to verify peer against (SSL)",
|
||||||
|
" --capath DIR CA directory to verify peer against (SSL)",
|
||||||
|
" -E, --cert CERT[:PASSWD] Client certificate file and password (SSL)",
|
||||||
|
" --cert-type TYPE Certificate file type (DER/PEM/ENG) (SSL)",
|
||||||
|
" --ciphers LIST SSL ciphers to use (SSL)",
|
||||||
|
" --compressed Request compressed response (using deflate or gzip)",
|
||||||
|
" -K, --config FILE Specify which config file to read",
|
||||||
|
" --connect-timeout SECONDS Maximum time allowed for connection",
|
||||||
|
" -C, --continue-at OFFSET Resumed transfer offset",
|
||||||
|
" -b, --cookie STRING/FILE String or file to read cookies from (H)",
|
||||||
|
" -c, --cookie-jar FILE Write cookies to this file after operation (H)",
|
||||||
|
" --create-dirs Create necessary local directory hierarchy",
|
||||||
|
" --crlf Convert LF to CRLF in upload",
|
||||||
|
" --crlfile FILE Get a CRL list in PEM format from the given file",
|
||||||
|
" -d, --data DATA HTTP POST data (H)",
|
||||||
|
" --data-ascii DATA HTTP POST ASCII data (H)",
|
||||||
|
" --data-binary DATA HTTP POST binary data (H)",
|
||||||
|
" --data-urlencode DATA HTTP POST data url encoded (H)",
|
||||||
|
" --delegation STRING GSS-API delegation permission",
|
||||||
|
" --digest Use HTTP Digest Authentication (H)",
|
||||||
|
" --disable-eprt Inhibit using EPRT or LPRT (F)",
|
||||||
|
" --disable-epsv Inhibit using EPSV (F)",
|
||||||
|
" -D, --dump-header FILE Write the headers to this file",
|
||||||
|
" --egd-file FILE EGD socket path for random data (SSL)",
|
||||||
|
" --engine ENGINGE Crypto engine (SSL). \"--engine list\" for list",
|
||||||
|
#ifdef USE_ENVIRONMENT
|
||||||
|
" --environment Write results to environment variables (RISC OS)",
|
||||||
|
#endif
|
||||||
|
" -f, --fail Fail silently (no output at all) on HTTP errors (H)",
|
||||||
|
" -F, --form CONTENT Specify HTTP multipart POST data (H)",
|
||||||
|
" --form-string STRING Specify HTTP multipart POST data (H)",
|
||||||
|
" --ftp-account DATA Account data string (F)",
|
||||||
|
" --ftp-alternative-to-user COMMAND "
|
||||||
|
"String to replace \"USER [name]\" (F)",
|
||||||
|
" --ftp-create-dirs Create the remote dirs if not present (F)",
|
||||||
|
" --ftp-method [MULTICWD/NOCWD/SINGLECWD] Control CWD usage (F)",
|
||||||
|
" --ftp-pasv Use PASV/EPSV instead of PORT (F)",
|
||||||
|
" -P, --ftp-port ADR Use PORT with given address instead of PASV (F)",
|
||||||
|
" --ftp-skip-pasv-ip Skip the IP address for PASV (F)\n"
|
||||||
|
" --ftp-pret Send PRET before PASV (for drftpd) (F)",
|
||||||
|
" --ftp-ssl-ccc Send CCC after authenticating (F)",
|
||||||
|
" --ftp-ssl-ccc-mode ACTIVE/PASSIVE Set CCC mode (F)",
|
||||||
|
" --ftp-ssl-control Require SSL/TLS for ftp login, "
|
||||||
|
"clear for transfer (F)",
|
||||||
|
" -G, --get Send the -d data with a HTTP GET (H)",
|
||||||
|
" -g, --globoff Disable URL sequences and ranges using {} and []",
|
||||||
|
" -H, --header LINE Custom header to pass to server (H)",
|
||||||
|
" -I, --head Show document info only",
|
||||||
|
" -h, --help This help text",
|
||||||
|
" --hostpubmd5 MD5 "
|
||||||
|
"Hex encoded MD5 string of the host public key. (SSH)",
|
||||||
|
" -0, --http1.0 Use HTTP 1.0 (H)",
|
||||||
|
" --ignore-content-length Ignore the HTTP Content-Length header",
|
||||||
|
" -i, --include Include protocol headers in the output (H/F)",
|
||||||
|
" -k, --insecure Allow connections to SSL sites without certs (H)",
|
||||||
|
" --interface INTERFACE Specify network interface/address to use",
|
||||||
|
" -4, --ipv4 Resolve name to IPv4 address",
|
||||||
|
" -6, --ipv6 Resolve name to IPv6 address",
|
||||||
|
" -j, --junk-session-cookies Ignore session cookies read from file (H)",
|
||||||
|
" --keepalive-time SECONDS Interval between keepalive probes",
|
||||||
|
" --key KEY Private key file name (SSL/SSH)",
|
||||||
|
" --key-type TYPE Private key file type (DER/PEM/ENG) (SSL)",
|
||||||
|
" --krb LEVEL Enable Kerberos with specified security level (F)",
|
||||||
|
" --libcurl FILE Dump libcurl equivalent code of this command line",
|
||||||
|
" --limit-rate RATE Limit transfer speed to this rate",
|
||||||
|
" -l, --list-only List only names of an FTP directory (F)",
|
||||||
|
" --local-port RANGE Force use of these local port numbers",
|
||||||
|
" -L, --location Follow redirects (H)",
|
||||||
|
" --location-trusted like --location and send auth to other hosts (H)",
|
||||||
|
" -M, --manual Display the full manual",
|
||||||
|
" --mail-from FROM Mail from this address",
|
||||||
|
" --mail-rcpt TO Mail to this receiver(s)",
|
||||||
|
" --max-filesize BYTES Maximum file size to download (H/F)",
|
||||||
|
" --max-redirs NUM Maximum number of redirects allowed (H)",
|
||||||
|
" -m, --max-time SECONDS Maximum time allowed for the transfer",
|
||||||
|
" --negotiate Use HTTP Negotiate Authentication (H)",
|
||||||
|
" -n, --netrc Must read .netrc for user name and password",
|
||||||
|
" --netrc-optional Use either .netrc or URL; overrides -n",
|
||||||
|
" --netrc-file FILE Set up the netrc filename to use",
|
||||||
|
" -N, --no-buffer Disable buffering of the output stream",
|
||||||
|
" --no-keepalive Disable keepalive use on the connection",
|
||||||
|
" --no-sessionid Disable SSL session-ID reusing (SSL)",
|
||||||
|
" --noproxy List of hosts which do not use proxy",
|
||||||
|
" --ntlm Use HTTP NTLM authentication (H)",
|
||||||
|
" -o, --output FILE Write output to <file> instead of stdout",
|
||||||
|
" --pass PASS Pass phrase for the private key (SSL/SSH)",
|
||||||
|
" --post301 "
|
||||||
|
"Do not switch to GET after following a 301 redirect (H)",
|
||||||
|
" --post302 "
|
||||||
|
"Do not switch to GET after following a 302 redirect (H)",
|
||||||
|
" -#, --progress-bar Display transfer progress as a progress bar",
|
||||||
|
" --proto PROTOCOLS Enable/disable specified protocols",
|
||||||
|
" --proto-redir PROTOCOLS "
|
||||||
|
"Enable/disable specified protocols on redirect",
|
||||||
|
" -x, --proxy [PROTOCOL://]HOST[:PORT] Use proxy on given port",
|
||||||
|
" --proxy-anyauth Pick \"any\" proxy authentication method (H)",
|
||||||
|
" --proxy-basic Use Basic authentication on the proxy (H)",
|
||||||
|
" --proxy-digest Use Digest authentication on the proxy (H)",
|
||||||
|
" --proxy-negotiate Use Negotiate authentication on the proxy (H)",
|
||||||
|
" --proxy-ntlm Use NTLM authentication on the proxy (H)",
|
||||||
|
" -U, --proxy-user USER[:PASSWORD] Proxy user and password",
|
||||||
|
" --proxy1.0 HOST[:PORT] Use HTTP/1.0 proxy on given port",
|
||||||
|
" -p, --proxytunnel Operate through a HTTP proxy tunnel (using CONNECT)",
|
||||||
|
" --pubkey KEY Public key file name (SSH)",
|
||||||
|
" -Q, --quote CMD Send command(s) to server before transfer (F/SFTP)",
|
||||||
|
" --random-file FILE File for reading random data from (SSL)",
|
||||||
|
" -r, --range RANGE Retrieve only the bytes within a range",
|
||||||
|
" --raw Do HTTP \"raw\", without any transfer decoding (H)",
|
||||||
|
" -e, --referer Referer URL (H)",
|
||||||
|
" -J, --remote-header-name Use the header-provided filename (H)",
|
||||||
|
" -O, --remote-name Write output to a file named as the remote file",
|
||||||
|
" --remote-name-all Use the remote file name for all URLs",
|
||||||
|
" -R, --remote-time Set the remote file's time on the local output",
|
||||||
|
" -X, --request COMMAND Specify request command to use",
|
||||||
|
" --resolve HOST:PORT:ADDRESS Force resolve of HOST:PORT to ADDRESS",
|
||||||
|
" --retry NUM "
|
||||||
|
"Retry request NUM times if transient problems occur",
|
||||||
|
" --retry-delay SECONDS "
|
||||||
|
"When retrying, wait this many seconds between each",
|
||||||
|
" --retry-max-time SECONDS Retry only within this period",
|
||||||
|
" -S, --show-error "
|
||||||
|
"Show error. With -s, make curl show errors when they occur",
|
||||||
|
" -s, --silent Silent mode. Don't output anything",
|
||||||
|
" --socks4 HOST[:PORT] SOCKS4 proxy on given host + port",
|
||||||
|
" --socks4a HOST[:PORT] SOCKS4a proxy on given host + port",
|
||||||
|
" --socks5 HOST[:PORT] SOCKS5 proxy on given host + port",
|
||||||
|
" --socks5-hostname HOST[:PORT] "
|
||||||
|
"SOCKS5 proxy, pass host name to proxy",
|
||||||
|
#if defined(HAVE_GSSAPI) || defined(USE_WINDOWS_SSPI)
|
||||||
|
" --socks5-gssapi-service NAME SOCKS5 proxy service name for gssapi",
|
||||||
|
" --socks5-gssapi-nec Compatibility with NEC SOCKS5 server",
|
||||||
|
#endif
|
||||||
|
" -Y, --speed-limit RATE "
|
||||||
|
"Stop transfers below speed-limit for 'speed-time' secs",
|
||||||
|
" -y, --speed-time SECONDS "
|
||||||
|
"Time for trig speed-limit abort. Defaults to 30",
|
||||||
|
" --ssl Try SSL/TLS (FTP, IMAP, POP3, SMTP)",
|
||||||
|
" --ssl-reqd Require SSL/TLS (FTP, IMAP, POP3, SMTP)",
|
||||||
|
" -2, --sslv2 Use SSLv2 (SSL)",
|
||||||
|
" -3, --sslv3 Use SSLv3 (SSL)",
|
||||||
|
" --stderr FILE Where to redirect stderr. - means stdout",
|
||||||
|
" --tcp-nodelay Use the TCP_NODELAY option",
|
||||||
|
" -t, --telnet-option OPT=VAL Set telnet option",
|
||||||
|
" --tftp-blksize VALUE Set TFTP BLKSIZE option (must be >512)",
|
||||||
|
" -z, --time-cond TIME Transfer based on a time condition",
|
||||||
|
" -1, --tlsv1 Use TLSv1 (SSL)",
|
||||||
|
" --trace FILE Write a debug trace to the given file",
|
||||||
|
" --trace-ascii FILE Like --trace but without the hex output",
|
||||||
|
" --trace-time Add time stamps to trace/verbose output",
|
||||||
|
" --tr-encoding Request compressed transfer encoding (H)",
|
||||||
|
" -T, --upload-file FILE Transfer FILE to destination",
|
||||||
|
" --url URL URL to work with",
|
||||||
|
" -B, --use-ascii Use ASCII/text transfer",
|
||||||
|
" -u, --user USER[:PASSWORD] Server user and password",
|
||||||
|
" --tlsuser USER TLS username",
|
||||||
|
" --tlspassword STRING TLS password",
|
||||||
|
" --tlsauthtype STRING TLS authentication type (default SRP)",
|
||||||
|
" -A, --user-agent STRING User-Agent to send to server (H)",
|
||||||
|
" -v, --verbose Make the operation more talkative",
|
||||||
|
" -V, --version Show version number and quit",
|
||||||
|
#ifdef USE_WATT32
|
||||||
|
" --wdebug Turn on Watt-32 debugging",
|
||||||
|
#endif
|
||||||
|
" -w, --write-out FORMAT What to output after completion",
|
||||||
|
" --xattr Store metadata in extended file attributes",
|
||||||
|
" -q If used as the first parameter disables .curlrc",
|
||||||
|
NULL
|
||||||
|
};
|
||||||
|
|
||||||
|
#ifdef NETWARE
|
||||||
|
# define PRINT_LINES_PAUSE 23
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __SYMBIAN32__
|
||||||
|
# define PRINT_LINES_PAUSE 16
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void tool_help(void)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
for(i = 0; helptext[i]; i++) {
|
||||||
|
puts(helptext[i]);
|
||||||
|
#ifdef PRINT_LINES_PAUSE
|
||||||
|
if(i && ((i % PRINT_LINES_PAUSE) == 0))
|
||||||
|
tool_pressanykey();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,5 +1,5 @@
|
|||||||
#ifndef HEADER_CURL_TOOL_MYFUNC_H
|
#ifndef HEADER_CURL_TOOL_HELP_H
|
||||||
#define HEADER_CURL_TOOL_MYFUNC_H
|
#define HEADER_CURL_TOOL_HELP_H
|
||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
* _ _ ____ _
|
* _ _ ____ _
|
||||||
* Project ___| | | | _ \| |
|
* Project ___| | | | _ \| |
|
||||||
@ -23,7 +23,7 @@
|
|||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
#include "setup.h"
|
#include "setup.h"
|
||||||
|
|
||||||
char *my_useragent(void);
|
void tool_help(void);
|
||||||
|
|
||||||
#endif /* HEADER_CURL_TOOL_MYFUNC_H */
|
#endif /* HEADER_CURL_TOOL_HELP_H */
|
||||||
|
|
78
src/tool_helpers.c
Normal file
78
src/tool_helpers.c
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
/***************************************************************************
|
||||||
|
* _ _ ____ _
|
||||||
|
* Project ___| | | | _ \| |
|
||||||
|
* / __| | | | |_) | |
|
||||||
|
* | (__| |_| | _ <| |___
|
||||||
|
* \___|\___/|_| \_\_____|
|
||||||
|
*
|
||||||
|
* Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||||
|
*
|
||||||
|
* This software is licensed as described in the file COPYING, which
|
||||||
|
* you should have received as part of this distribution. The terms
|
||||||
|
* are also available at http://curl.haxx.se/docs/copyright.html.
|
||||||
|
*
|
||||||
|
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
||||||
|
* copies of the Software, and permit persons to whom the Software is
|
||||||
|
* furnished to do so, under the terms of the COPYING file.
|
||||||
|
*
|
||||||
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||||
|
* KIND, either express or implied.
|
||||||
|
*
|
||||||
|
***************************************************************************/
|
||||||
|
#include "setup.h"
|
||||||
|
|
||||||
|
#include <curl/curl.h>
|
||||||
|
|
||||||
|
#include "rawstr.h"
|
||||||
|
|
||||||
|
#define ENABLE_CURLX_PRINTF
|
||||||
|
/* use our own printf() functions */
|
||||||
|
#include "curlx.h"
|
||||||
|
|
||||||
|
#include "tool_cfgable.h"
|
||||||
|
#include "tool_msgs.h"
|
||||||
|
#include "tool_getparam.h"
|
||||||
|
#include "tool_helpers.h"
|
||||||
|
|
||||||
|
#include "memdebug.h" /* keep this as LAST include */
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Helper functions that are used from more tha one source file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
const char *param2text(int res)
|
||||||
|
{
|
||||||
|
ParameterError error = (ParameterError)res;
|
||||||
|
switch(error) {
|
||||||
|
case PARAM_GOT_EXTRA_PARAMETER:
|
||||||
|
return "had unsupported trailing garbage";
|
||||||
|
case PARAM_OPTION_UNKNOWN:
|
||||||
|
return "is unknown";
|
||||||
|
case PARAM_OPTION_AMBIGUOUS:
|
||||||
|
return "is ambiguous";
|
||||||
|
case PARAM_REQUIRES_PARAMETER:
|
||||||
|
return "requires parameter";
|
||||||
|
case PARAM_BAD_USE:
|
||||||
|
return "is badly used here";
|
||||||
|
case PARAM_BAD_NUMERIC:
|
||||||
|
return "expected a proper numerical parameter";
|
||||||
|
case PARAM_LIBCURL_DOESNT_SUPPORT:
|
||||||
|
return "the installed libcurl version doesn't support this";
|
||||||
|
case PARAM_NO_MEM:
|
||||||
|
return "out of memory";
|
||||||
|
default:
|
||||||
|
return "unknown error";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int SetHTTPrequest(struct Configurable *config, HttpReq req, HttpReq *store)
|
||||||
|
{
|
||||||
|
if((*store == HTTPREQ_UNSPEC) ||
|
||||||
|
(*store == req)) {
|
||||||
|
*store = req;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
warnf(config, "You can only select one HTTP request!\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
31
src/tool_helpers.h
Normal file
31
src/tool_helpers.h
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
#ifndef HEADER_CURL_TOOL_HELPERS_H
|
||||||
|
#define HEADER_CURL_TOOL_HELPERS_H
|
||||||
|
/***************************************************************************
|
||||||
|
* _ _ ____ _
|
||||||
|
* Project ___| | | | _ \| |
|
||||||
|
* / __| | | | |_) | |
|
||||||
|
* | (__| |_| | _ <| |___
|
||||||
|
* \___|\___/|_| \_\_____|
|
||||||
|
*
|
||||||
|
* Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||||
|
*
|
||||||
|
* This software is licensed as described in the file COPYING, which
|
||||||
|
* you should have received as part of this distribution. The terms
|
||||||
|
* are also available at http://curl.haxx.se/docs/copyright.html.
|
||||||
|
*
|
||||||
|
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
||||||
|
* copies of the Software, and permit persons to whom the Software is
|
||||||
|
* furnished to do so, under the terms of the COPYING file.
|
||||||
|
*
|
||||||
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||||
|
* KIND, either express or implied.
|
||||||
|
*
|
||||||
|
***************************************************************************/
|
||||||
|
#include "setup.h"
|
||||||
|
|
||||||
|
const char *param2text(int res);
|
||||||
|
|
||||||
|
int SetHTTPrequest(struct Configurable *config, HttpReq req, HttpReq *store);
|
||||||
|
|
||||||
|
#endif /* HEADER_CURL_TOOL_HELPERS_H */
|
||||||
|
|
112
src/tool_main.c
Normal file
112
src/tool_main.c
Normal file
@ -0,0 +1,112 @@
|
|||||||
|
/***************************************************************************
|
||||||
|
* _ _ ____ _
|
||||||
|
* Project ___| | | | _ \| |
|
||||||
|
* / __| | | | |_) | |
|
||||||
|
* | (__| |_| | _ <| |___
|
||||||
|
* \___|\___/|_| \_\_____|
|
||||||
|
*
|
||||||
|
* Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||||
|
*
|
||||||
|
* This software is licensed as described in the file COPYING, which
|
||||||
|
* you should have received as part of this distribution. The terms
|
||||||
|
* are also available at http://curl.haxx.se/docs/copyright.html.
|
||||||
|
*
|
||||||
|
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
||||||
|
* copies of the Software, and permit persons to whom the Software is
|
||||||
|
* furnished to do so, under the terms of the COPYING file.
|
||||||
|
*
|
||||||
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||||
|
* KIND, either express or implied.
|
||||||
|
*
|
||||||
|
***************************************************************************/
|
||||||
|
#include "setup.h"
|
||||||
|
|
||||||
|
#include <curl/curl.h>
|
||||||
|
|
||||||
|
#include <sys/stat.h>
|
||||||
|
|
||||||
|
#ifdef HAVE_UNISTD_H
|
||||||
|
# include <unistd.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define ENABLE_CURLX_PRINTF
|
||||||
|
/* use our own printf() functions */
|
||||||
|
#include "curlx.h"
|
||||||
|
|
||||||
|
#include "tool_cfgable.h"
|
||||||
|
#include "tool_convert.h"
|
||||||
|
#include "tool_operate.h"
|
||||||
|
#include "tool_panykey.h"
|
||||||
|
#include "tool_vms.h"
|
||||||
|
#include "tool_main.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This is low-level hard-hacking memory leak tracking and similar. Using
|
||||||
|
* the library level code from this client-side is ugly, but we do this
|
||||||
|
* anyway for convenience.
|
||||||
|
*/
|
||||||
|
#include "memdebug.h" /* keep this as LAST include */
|
||||||
|
|
||||||
|
#ifdef __VMS
|
||||||
|
static int vms_show = 0;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Ensure that file descriptors 0, 1 and 2 (stdin, stdout, stderr) are
|
||||||
|
* open before starting to run. Otherwise, the first three network
|
||||||
|
* sockets opened by curl could be used for input sources, downloaded data
|
||||||
|
* or error logs as they will effectively be stdin, stdout and/or stderr.
|
||||||
|
*/
|
||||||
|
static void main_checkfds(void)
|
||||||
|
{
|
||||||
|
#ifdef HAVE_PIPE
|
||||||
|
int fd[2] = { STDIN_FILENO, STDIN_FILENO };
|
||||||
|
while(fd[0] == STDIN_FILENO ||
|
||||||
|
fd[0] == STDOUT_FILENO ||
|
||||||
|
fd[0] == STDERR_FILENO ||
|
||||||
|
fd[1] == STDIN_FILENO ||
|
||||||
|
fd[1] == STDOUT_FILENO ||
|
||||||
|
fd[1] == STDERR_FILENO)
|
||||||
|
if(pipe(fd) < 0)
|
||||||
|
return; /* Out of handles. This isn't really a big problem now, but
|
||||||
|
will be when we try to create a socket later. */
|
||||||
|
close(fd[0]);
|
||||||
|
close(fd[1]);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
** curl tool main function.
|
||||||
|
*/
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
int res;
|
||||||
|
struct Configurable config;
|
||||||
|
|
||||||
|
memset(&config, 0, sizeof(struct Configurable));
|
||||||
|
|
||||||
|
config.errors = stderr; /* default errors to stderr */
|
||||||
|
|
||||||
|
main_checkfds();
|
||||||
|
|
||||||
|
res = operate(&config, argc, argv);
|
||||||
|
|
||||||
|
#ifdef __SYMBIAN32__
|
||||||
|
if(config.showerror)
|
||||||
|
tool_pressanykey();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
free_config_fields(&config);
|
||||||
|
|
||||||
|
#ifdef __NOVELL_LIBC__
|
||||||
|
if(getenv("_IN_NETWARE_BASH_") == NULL)
|
||||||
|
tool_pressanykey();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __VMS
|
||||||
|
vms_special_exit(res, vms_show);
|
||||||
|
#else
|
||||||
|
return res;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
44
src/tool_main.h
Normal file
44
src/tool_main.h
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
#ifndef HEADER_CURL_TOOL_MAIN_H
|
||||||
|
#define HEADER_CURL_TOOL_MAIN_H
|
||||||
|
/***************************************************************************
|
||||||
|
* _ _ ____ _
|
||||||
|
* Project ___| | | | _ \| |
|
||||||
|
* / __| | | | |_) | |
|
||||||
|
* | (__| |_| | _ <| |___
|
||||||
|
* \___|\___/|_| \_\_____|
|
||||||
|
*
|
||||||
|
* Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||||
|
*
|
||||||
|
* This software is licensed as described in the file COPYING, which
|
||||||
|
* you should have received as part of this distribution. The terms
|
||||||
|
* are also available at http://curl.haxx.se/docs/copyright.html.
|
||||||
|
*
|
||||||
|
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
||||||
|
* copies of the Software, and permit persons to whom the Software is
|
||||||
|
* furnished to do so, under the terms of the COPYING file.
|
||||||
|
*
|
||||||
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||||
|
* KIND, either express or implied.
|
||||||
|
*
|
||||||
|
***************************************************************************/
|
||||||
|
#include "setup.h"
|
||||||
|
|
||||||
|
#define DEFAULT_MAXREDIRS 50L
|
||||||
|
|
||||||
|
#define RETRY_SLEEP_DEFAULT 1000L /* ms */
|
||||||
|
#define RETRY_SLEEP_MAX 600000L /* ms == 10 minutes */
|
||||||
|
|
||||||
|
#ifndef STDIN_FILENO
|
||||||
|
# define STDIN_FILENO fileno(stdin)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef STDOUT_FILENO
|
||||||
|
# define STDOUT_FILENO fileno(stdout)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef STDERR_FILENO
|
||||||
|
# define STDERR_FILENO fileno(stderr)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* HEADER_CURL_TOOL_MAIN_H */
|
||||||
|
|
1541
src/tool_operate.c
Normal file
1541
src/tool_operate.c
Normal file
File diff suppressed because it is too large
Load Diff
29
src/tool_operate.h
Normal file
29
src/tool_operate.h
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
#ifndef HEADER_CURL_TOOL_OPERATE_H
|
||||||
|
#define HEADER_CURL_TOOL_OPERATE_H
|
||||||
|
/***************************************************************************
|
||||||
|
* _ _ ____ _
|
||||||
|
* Project ___| | | | _ \| |
|
||||||
|
* / __| | | | |_) | |
|
||||||
|
* | (__| |_| | _ <| |___
|
||||||
|
* \___|\___/|_| \_\_____|
|
||||||
|
*
|
||||||
|
* Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||||
|
*
|
||||||
|
* This software is licensed as described in the file COPYING, which
|
||||||
|
* you should have received as part of this distribution. The terms
|
||||||
|
* are also available at http://curl.haxx.se/docs/copyright.html.
|
||||||
|
*
|
||||||
|
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
||||||
|
* copies of the Software, and permit persons to whom the Software is
|
||||||
|
* furnished to do so, under the terms of the COPYING file.
|
||||||
|
*
|
||||||
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||||
|
* KIND, either express or implied.
|
||||||
|
*
|
||||||
|
***************************************************************************/
|
||||||
|
#include "setup.h"
|
||||||
|
|
||||||
|
int operate(struct Configurable *config, int argc, argv_item_t argv[]);
|
||||||
|
|
||||||
|
#endif /* HEADER_CURL_TOOL_OPERATE_H */
|
||||||
|
|
231
src/tool_operhlp.c
Normal file
231
src/tool_operhlp.c
Normal file
@ -0,0 +1,231 @@
|
|||||||
|
/***************************************************************************
|
||||||
|
* _ _ ____ _
|
||||||
|
* Project ___| | | | _ \| |
|
||||||
|
* / __| | | | |_) | |
|
||||||
|
* | (__| |_| | _ <| |___
|
||||||
|
* \___|\___/|_| \_\_____|
|
||||||
|
*
|
||||||
|
* Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||||
|
*
|
||||||
|
* This software is licensed as described in the file COPYING, which
|
||||||
|
* you should have received as part of this distribution. The terms
|
||||||
|
* are also available at http://curl.haxx.se/docs/copyright.html.
|
||||||
|
*
|
||||||
|
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
||||||
|
* copies of the Software, and permit persons to whom the Software is
|
||||||
|
* furnished to do so, under the terms of the COPYING file.
|
||||||
|
*
|
||||||
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||||
|
* KIND, either express or implied.
|
||||||
|
*
|
||||||
|
***************************************************************************/
|
||||||
|
#include "setup.h"
|
||||||
|
|
||||||
|
#include <curl/curl.h>
|
||||||
|
|
||||||
|
#include "rawstr.h"
|
||||||
|
|
||||||
|
#define ENABLE_CURLX_PRINTF
|
||||||
|
/* use our own printf() functions */
|
||||||
|
#include "curlx.h"
|
||||||
|
|
||||||
|
#include "version.h"
|
||||||
|
|
||||||
|
#include "tool_cfgable.h"
|
||||||
|
#include "tool_convert.h"
|
||||||
|
#include "tool_operhlp.h"
|
||||||
|
|
||||||
|
#include "memdebug.h" /* keep this as LAST include */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* my_useragent: returns allocated string with default user agent
|
||||||
|
*/
|
||||||
|
char *my_useragent(void)
|
||||||
|
{
|
||||||
|
char useragent[256]; /* we don't want a larger default user agent */
|
||||||
|
|
||||||
|
snprintf(useragent, sizeof(useragent),
|
||||||
|
CURL_NAME "/" CURL_VERSION " (" OS ") " "%s", curl_version());
|
||||||
|
|
||||||
|
return strdup(useragent);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Print list of OpenSSL supported engines
|
||||||
|
*/
|
||||||
|
void list_engines(const struct curl_slist *engines)
|
||||||
|
{
|
||||||
|
puts("Build-time engines:");
|
||||||
|
if(!engines) {
|
||||||
|
puts(" <none>");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for(; engines; engines = engines->next)
|
||||||
|
printf(" %s\n", engines->data);
|
||||||
|
}
|
||||||
|
|
||||||
|
void clean_getout(struct Configurable *config)
|
||||||
|
{
|
||||||
|
struct getout *next;
|
||||||
|
struct getout *node = config->url_list;
|
||||||
|
|
||||||
|
while(node) {
|
||||||
|
next = node->next;
|
||||||
|
Curl_safefree(node->url);
|
||||||
|
Curl_safefree(node->outfile);
|
||||||
|
Curl_safefree(node->infile);
|
||||||
|
Curl_safefree(node);
|
||||||
|
node = next;
|
||||||
|
}
|
||||||
|
config->url_list = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool output_expected(const char *url, const char *uploadfile)
|
||||||
|
{
|
||||||
|
if(!uploadfile)
|
||||||
|
return TRUE; /* download */
|
||||||
|
if(checkprefix("http://", url) || checkprefix("https://", url))
|
||||||
|
return TRUE; /* HTTP(S) upload */
|
||||||
|
|
||||||
|
return FALSE; /* non-HTTP upload, probably no output should be expected */
|
||||||
|
}
|
||||||
|
|
||||||
|
bool stdin_upload(const char *uploadfile)
|
||||||
|
{
|
||||||
|
return (curlx_strequal(uploadfile, "-") ||
|
||||||
|
curlx_strequal(uploadfile, ".")) ? TRUE : FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Adds the file name to the URL if it doesn't already have one.
|
||||||
|
* url will be freed before return if the returned pointer is different
|
||||||
|
*/
|
||||||
|
char *add_file_name_to_url(CURL *curl, char *url, const char *filename)
|
||||||
|
{
|
||||||
|
/* If no file name part is given in the URL, we add this file name */
|
||||||
|
char *ptr = strstr(url, "://");
|
||||||
|
if(ptr)
|
||||||
|
ptr += 3;
|
||||||
|
else
|
||||||
|
ptr = url;
|
||||||
|
ptr = strrchr(ptr, '/');
|
||||||
|
if(!ptr || !strlen(++ptr)) {
|
||||||
|
/* The URL has no file name part, add the local file name. In order
|
||||||
|
to be able to do so, we have to create a new URL in another
|
||||||
|
buffer.*/
|
||||||
|
|
||||||
|
/* We only want the part of the local path that is on the right
|
||||||
|
side of the rightmost slash and backslash. */
|
||||||
|
const char *filep = strrchr(filename, '/');
|
||||||
|
char *file2 = strrchr(filep?filep:filename, '\\');
|
||||||
|
char *encfile;
|
||||||
|
|
||||||
|
if(file2)
|
||||||
|
filep = file2 + 1;
|
||||||
|
else if(filep)
|
||||||
|
filep++;
|
||||||
|
else
|
||||||
|
filep = filename;
|
||||||
|
|
||||||
|
/* URL encode the file name */
|
||||||
|
encfile = curl_easy_escape(curl, filep, 0 /* use strlen */);
|
||||||
|
if(encfile) {
|
||||||
|
char *urlbuffer = malloc(strlen(url) + strlen(encfile) + 3);
|
||||||
|
if(!urlbuffer) {
|
||||||
|
Curl_safefree(url);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
if(ptr)
|
||||||
|
/* there is a trailing slash on the URL */
|
||||||
|
sprintf(urlbuffer, "%s%s", url, encfile);
|
||||||
|
else
|
||||||
|
/* there is no trailing slash on the URL */
|
||||||
|
sprintf(urlbuffer, "%s/%s", url, encfile);
|
||||||
|
|
||||||
|
curl_free(encfile);
|
||||||
|
|
||||||
|
Curl_safefree(url);
|
||||||
|
url = urlbuffer; /* use our new URL instead! */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Extracts the name portion of the URL.
|
||||||
|
* Returns a heap-allocated string, or NULL if no name part
|
||||||
|
*/
|
||||||
|
char *get_url_file_name(const char *url)
|
||||||
|
{
|
||||||
|
char *fn = NULL;
|
||||||
|
|
||||||
|
/* Find and get the remote file name */
|
||||||
|
const char *pc = strstr(url, "://");
|
||||||
|
if(pc)
|
||||||
|
pc += 3;
|
||||||
|
else
|
||||||
|
pc = url;
|
||||||
|
pc = strrchr(pc, '/');
|
||||||
|
|
||||||
|
if(pc) {
|
||||||
|
/* duplicate the string beyond the slash */
|
||||||
|
pc++;
|
||||||
|
fn = *pc ? strdup(pc): NULL;
|
||||||
|
}
|
||||||
|
return fn;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This is the main global constructor for the app. Call this before
|
||||||
|
* _any_ libcurl usage. If this fails, *NO* libcurl functions may be
|
||||||
|
* used, or havoc may be the result.
|
||||||
|
*/
|
||||||
|
CURLcode main_init(void)
|
||||||
|
{
|
||||||
|
#if defined(__DJGPP__) || defined(__GO32__)
|
||||||
|
/* stop stat() wasting time */
|
||||||
|
_djstat_flags |= _STAT_INODE | _STAT_EXEC_MAGIC | _STAT_DIRSIZE;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return curl_global_init(CURL_GLOBAL_DEFAULT);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This is the main global destructor for the app. Call this after
|
||||||
|
* _all_ libcurl usage is done.
|
||||||
|
*/
|
||||||
|
void main_free(void)
|
||||||
|
{
|
||||||
|
curl_global_cleanup();
|
||||||
|
convert_cleanup();
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef CURLDEBUG
|
||||||
|
void memory_tracking_init(void)
|
||||||
|
{
|
||||||
|
char *env;
|
||||||
|
/* if CURL_MEMDEBUG is set, this starts memory tracking message logging */
|
||||||
|
env = curlx_getenv("CURL_MEMDEBUG");
|
||||||
|
if(env) {
|
||||||
|
/* use the value as file name */
|
||||||
|
char fname[CURL_MT_LOGFNAME_BUFSIZE];
|
||||||
|
if(strlen(env) >= CURL_MT_LOGFNAME_BUFSIZE)
|
||||||
|
env[CURL_MT_LOGFNAME_BUFSIZE-1] = '\0';
|
||||||
|
strcpy(fname, env);
|
||||||
|
curl_free(env);
|
||||||
|
curl_memdebug(fname);
|
||||||
|
/* this weird stuff here is to make curl_free() get called
|
||||||
|
before curl_memdebug() as otherwise memory tracking will
|
||||||
|
log a free() without an alloc! */
|
||||||
|
}
|
||||||
|
/* if CURL_MEMLIMIT is set, this enables fail-on-alloc-number-N feature */
|
||||||
|
env = curlx_getenv("CURL_MEMLIMIT");
|
||||||
|
if(env) {
|
||||||
|
char *endptr;
|
||||||
|
long num = strtol(env, &endptr, 10);
|
||||||
|
if((endptr != env) && (endptr == env + strlen(env)) && (num > 0))
|
||||||
|
curl_memlimit(num);
|
||||||
|
curl_free(env);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
51
src/tool_operhlp.h
Normal file
51
src/tool_operhlp.h
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
#ifndef HEADER_CURL_TOOL_OPERHLP_H
|
||||||
|
#define HEADER_CURL_TOOL_OPERHLP_H
|
||||||
|
/***************************************************************************
|
||||||
|
* _ _ ____ _
|
||||||
|
* Project ___| | | | _ \| |
|
||||||
|
* / __| | | | |_) | |
|
||||||
|
* | (__| |_| | _ <| |___
|
||||||
|
* \___|\___/|_| \_\_____|
|
||||||
|
*
|
||||||
|
* Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||||
|
*
|
||||||
|
* This software is licensed as described in the file COPYING, which
|
||||||
|
* you should have received as part of this distribution. The terms
|
||||||
|
* are also available at http://curl.haxx.se/docs/copyright.html.
|
||||||
|
*
|
||||||
|
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
||||||
|
* copies of the Software, and permit persons to whom the Software is
|
||||||
|
* furnished to do so, under the terms of the COPYING file.
|
||||||
|
*
|
||||||
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||||
|
* KIND, either express or implied.
|
||||||
|
*
|
||||||
|
***************************************************************************/
|
||||||
|
#include "setup.h"
|
||||||
|
|
||||||
|
char *my_useragent(void);
|
||||||
|
|
||||||
|
void list_engines(const struct curl_slist *engines);
|
||||||
|
|
||||||
|
void clean_getout(struct Configurable *config);
|
||||||
|
|
||||||
|
bool output_expected(const char *url, const char *uploadfile);
|
||||||
|
|
||||||
|
bool stdin_upload(const char *uploadfile);
|
||||||
|
|
||||||
|
char *add_file_name_to_url(CURL *curl, char *url, const char *filename);
|
||||||
|
|
||||||
|
char *get_url_file_name(const char *url);
|
||||||
|
|
||||||
|
CURLcode main_init(void);
|
||||||
|
|
||||||
|
void main_free(void);
|
||||||
|
|
||||||
|
#ifdef CURLDEBUG
|
||||||
|
void memory_tracking_init(void);
|
||||||
|
#else
|
||||||
|
# define memory_tracking_init() Curl_nop_stmt
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* HEADER_CURL_TOOL_OPERHLP_H */
|
||||||
|
|
@ -21,28 +21,20 @@
|
|||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
#include "setup.h"
|
#include "setup.h"
|
||||||
|
|
||||||
#include <curl/curl.h>
|
#if defined(__SYMBIAN32__) || defined(NETWARE)
|
||||||
|
|
||||||
#define ENABLE_CURLX_PRINTF
|
#include "tool_panykey.h"
|
||||||
/* use our own printf() functions */
|
|
||||||
#include "curlx.h"
|
|
||||||
|
|
||||||
#include "version.h"
|
|
||||||
#include "tool_myfunc.h"
|
|
||||||
|
|
||||||
#include "memdebug.h" /* keep this as LAST include */
|
#include "memdebug.h" /* keep this as LAST include */
|
||||||
|
|
||||||
/*
|
void tool_pressanykey(void)
|
||||||
* my_useragent: returns allocated string with default user agent
|
|
||||||
*/
|
|
||||||
|
|
||||||
char *my_useragent(void)
|
|
||||||
{
|
{
|
||||||
char useragent[256]; /* we don't want a larger default user agent */
|
#if defined(__SYMBIAN32__)
|
||||||
|
getchar();
|
||||||
snprintf(useragent, sizeof(useragent),
|
#elif defined(NETWARE)
|
||||||
CURL_NAME "/" CURL_VERSION " (" OS ") " "%s", curl_version());
|
pressanykey();
|
||||||
|
#endif
|
||||||
return strdup(useragent);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif /* __SYMBIAN32__ || NETWARE */
|
||||||
|
|
37
src/tool_panykey.h
Normal file
37
src/tool_panykey.h
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
#ifndef HEADER_CURL_TOOL_PANYKEY_H
|
||||||
|
#define HEADER_CURL_TOOL_PANYKEY_H
|
||||||
|
/***************************************************************************
|
||||||
|
* _ _ ____ _
|
||||||
|
* Project ___| | | | _ \| |
|
||||||
|
* / __| | | | |_) | |
|
||||||
|
* | (__| |_| | _ <| |___
|
||||||
|
* \___|\___/|_| \_\_____|
|
||||||
|
*
|
||||||
|
* Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||||
|
*
|
||||||
|
* This software is licensed as described in the file COPYING, which
|
||||||
|
* you should have received as part of this distribution. The terms
|
||||||
|
* are also available at http://curl.haxx.se/docs/copyright.html.
|
||||||
|
*
|
||||||
|
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
||||||
|
* copies of the Software, and permit persons to whom the Software is
|
||||||
|
* furnished to do so, under the terms of the COPYING file.
|
||||||
|
*
|
||||||
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||||
|
* KIND, either express or implied.
|
||||||
|
*
|
||||||
|
***************************************************************************/
|
||||||
|
#include "setup.h"
|
||||||
|
|
||||||
|
#if defined(__SYMBIAN32__) || defined(NETWARE)
|
||||||
|
|
||||||
|
void tool_pressanykey(void);
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
#define tool_pressanykey() Curl_nop_stmt
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* HEADER_CURL_TOOL_PANYKEY_H */
|
||||||
|
|
384
src/tool_paramhlp.c
Normal file
384
src/tool_paramhlp.c
Normal file
@ -0,0 +1,384 @@
|
|||||||
|
/***************************************************************************
|
||||||
|
* _ _ ____ _
|
||||||
|
* Project ___| | | | _ \| |
|
||||||
|
* / __| | | | |_) | |
|
||||||
|
* | (__| |_| | _ <| |___
|
||||||
|
* \___|\___/|_| \_\_____|
|
||||||
|
*
|
||||||
|
* Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||||
|
*
|
||||||
|
* This software is licensed as described in the file COPYING, which
|
||||||
|
* you should have received as part of this distribution. The terms
|
||||||
|
* are also available at http://curl.haxx.se/docs/copyright.html.
|
||||||
|
*
|
||||||
|
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
||||||
|
* copies of the Software, and permit persons to whom the Software is
|
||||||
|
* furnished to do so, under the terms of the COPYING file.
|
||||||
|
*
|
||||||
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||||
|
* KIND, either express or implied.
|
||||||
|
*
|
||||||
|
***************************************************************************/
|
||||||
|
#include "setup.h"
|
||||||
|
|
||||||
|
#include <curl/curl.h>
|
||||||
|
|
||||||
|
#include "rawstr.h"
|
||||||
|
|
||||||
|
#define ENABLE_CURLX_PRINTF
|
||||||
|
/* use our own printf() functions */
|
||||||
|
#include "curlx.h"
|
||||||
|
|
||||||
|
#include "homedir.h"
|
||||||
|
#include "getpass.h"
|
||||||
|
|
||||||
|
#include "tool_cfgable.h"
|
||||||
|
#include "tool_getparam.h"
|
||||||
|
#include "tool_msgs.h"
|
||||||
|
#include "tool_paramhlp.h"
|
||||||
|
|
||||||
|
#include "memdebug.h" /* keep this as LAST include */
|
||||||
|
|
||||||
|
struct getout *new_getout(struct Configurable *config)
|
||||||
|
{
|
||||||
|
struct getout *node =malloc(sizeof(struct getout));
|
||||||
|
struct getout *last= config->url_last;
|
||||||
|
if(node) {
|
||||||
|
/* clear the struct */
|
||||||
|
memset(node, 0, sizeof(struct getout));
|
||||||
|
|
||||||
|
/* append this new node last in the list */
|
||||||
|
if(last)
|
||||||
|
last->next = node;
|
||||||
|
else
|
||||||
|
config->url_list = node; /* first node */
|
||||||
|
|
||||||
|
/* move the last pointer */
|
||||||
|
config->url_last = node;
|
||||||
|
|
||||||
|
node->flags = config->default_node_flags;
|
||||||
|
}
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
|
||||||
|
ParameterError file2string(char **bufp, FILE *file)
|
||||||
|
{
|
||||||
|
char buffer[256];
|
||||||
|
char *ptr;
|
||||||
|
char *string = NULL;
|
||||||
|
size_t stringlen = 0;
|
||||||
|
size_t buflen;
|
||||||
|
|
||||||
|
if(file) {
|
||||||
|
while(fgets(buffer, sizeof(buffer), file)) {
|
||||||
|
if((ptr = strchr(buffer, '\r')) != NULL)
|
||||||
|
*ptr = '\0';
|
||||||
|
if((ptr = strchr(buffer, '\n')) != NULL)
|
||||||
|
*ptr = '\0';
|
||||||
|
buflen = strlen(buffer);
|
||||||
|
if((ptr = realloc(string, stringlen+buflen+1)) == NULL) {
|
||||||
|
Curl_safefree(string);
|
||||||
|
return PARAM_NO_MEM;
|
||||||
|
}
|
||||||
|
string = ptr;
|
||||||
|
strcpy(string+stringlen, buffer);
|
||||||
|
stringlen += buflen;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*bufp = string;
|
||||||
|
return PARAM_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
ParameterError file2memory(char **bufp, size_t *size, FILE *file)
|
||||||
|
{
|
||||||
|
char *newbuf;
|
||||||
|
char *buffer = NULL;
|
||||||
|
size_t alloc = 512;
|
||||||
|
size_t nused = 0;
|
||||||
|
size_t nread;
|
||||||
|
|
||||||
|
if(file) {
|
||||||
|
do {
|
||||||
|
if(!buffer || (alloc == nused)) {
|
||||||
|
/* size_t overflow detection for huge files */
|
||||||
|
if(alloc+1 > ((size_t)-1)/2) {
|
||||||
|
Curl_safefree(buffer);
|
||||||
|
return PARAM_NO_MEM;
|
||||||
|
}
|
||||||
|
alloc *= 2;
|
||||||
|
/* allocate an extra char, reserved space, for null termination */
|
||||||
|
if((newbuf = realloc(buffer, alloc+1)) == NULL) {
|
||||||
|
Curl_safefree(buffer);
|
||||||
|
return PARAM_NO_MEM;
|
||||||
|
}
|
||||||
|
buffer = newbuf;
|
||||||
|
}
|
||||||
|
nread = fread(buffer+nused, 1, alloc-nused, file);
|
||||||
|
nused += nread;
|
||||||
|
} while(nread);
|
||||||
|
/* null terminate the buffer in case it's used as a string later */
|
||||||
|
buffer[nused] = '\0';
|
||||||
|
/* free trailing slack space, if possible */
|
||||||
|
if(alloc != nused) {
|
||||||
|
if((newbuf = realloc(buffer, nused+1)) != NULL)
|
||||||
|
buffer = newbuf;
|
||||||
|
}
|
||||||
|
/* discard buffer if nothing was read */
|
||||||
|
if(!nused) {
|
||||||
|
Curl_safefree(buffer); /* no string */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*size = nused;
|
||||||
|
*bufp = buffer;
|
||||||
|
return PARAM_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
void cleanarg(char *str)
|
||||||
|
{
|
||||||
|
#ifdef HAVE_WRITABLE_ARGV
|
||||||
|
/* now that GetStr has copied the contents of nextarg, wipe the next
|
||||||
|
* argument out so that the username:password isn't displayed in the
|
||||||
|
* system process list */
|
||||||
|
if(str) {
|
||||||
|
size_t len = strlen(str);
|
||||||
|
memset(str, ' ', len);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
(void)str;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Parse the string and write the integer in the given address. Return
|
||||||
|
* non-zero on failure, zero on success.
|
||||||
|
*
|
||||||
|
* The string must start with a digit to be valid.
|
||||||
|
*
|
||||||
|
* Since this function gets called with the 'nextarg' pointer from within the
|
||||||
|
* getparameter a lot, we must check it for NULL before accessing the str
|
||||||
|
* data.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int str2num(long *val, const char *str)
|
||||||
|
{
|
||||||
|
if(str && ISDIGIT(*str)) {
|
||||||
|
char *endptr;
|
||||||
|
long num = strtol(str, &endptr, 10);
|
||||||
|
if((endptr != str) && (endptr == str + strlen(str))) {
|
||||||
|
*val = num;
|
||||||
|
return 0; /* Ok */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 1; /* badness */
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Parse the string and modify the long in the given address. Return
|
||||||
|
* non-zero on failure, zero on success.
|
||||||
|
*
|
||||||
|
* The string is a list of protocols
|
||||||
|
*
|
||||||
|
* Since this function gets called with the 'nextarg' pointer from within the
|
||||||
|
* getparameter a lot, we must check it for NULL before accessing the str
|
||||||
|
* data.
|
||||||
|
*/
|
||||||
|
|
||||||
|
long proto2num(struct Configurable *config, long *val, const char *str)
|
||||||
|
{
|
||||||
|
char *buffer;
|
||||||
|
const char *sep = ",";
|
||||||
|
char *token;
|
||||||
|
|
||||||
|
static struct sprotos {
|
||||||
|
const char *name;
|
||||||
|
long bit;
|
||||||
|
} const protos[] = {
|
||||||
|
{ "all", CURLPROTO_ALL },
|
||||||
|
{ "http", CURLPROTO_HTTP },
|
||||||
|
{ "https", CURLPROTO_HTTPS },
|
||||||
|
{ "ftp", CURLPROTO_FTP },
|
||||||
|
{ "ftps", CURLPROTO_FTPS },
|
||||||
|
{ "scp", CURLPROTO_SCP },
|
||||||
|
{ "sftp", CURLPROTO_SFTP },
|
||||||
|
{ "telnet", CURLPROTO_TELNET },
|
||||||
|
{ "ldap", CURLPROTO_LDAP },
|
||||||
|
{ "ldaps", CURLPROTO_LDAPS },
|
||||||
|
{ "dict", CURLPROTO_DICT },
|
||||||
|
{ "file", CURLPROTO_FILE },
|
||||||
|
{ "tftp", CURLPROTO_TFTP },
|
||||||
|
{ "imap", CURLPROTO_IMAP },
|
||||||
|
{ "imaps", CURLPROTO_IMAPS },
|
||||||
|
{ "pop3", CURLPROTO_POP3 },
|
||||||
|
{ "pop3s", CURLPROTO_POP3S },
|
||||||
|
{ "smtp", CURLPROTO_SMTP },
|
||||||
|
{ "smtps", CURLPROTO_SMTPS },
|
||||||
|
{ "rtsp", CURLPROTO_RTSP },
|
||||||
|
{ "gopher", CURLPROTO_GOPHER },
|
||||||
|
{ NULL, 0 }
|
||||||
|
};
|
||||||
|
|
||||||
|
if(!str)
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
buffer = strdup(str); /* because strtok corrupts it */
|
||||||
|
|
||||||
|
for(token = strtok(buffer, sep);
|
||||||
|
token;
|
||||||
|
token = strtok(NULL, sep)) {
|
||||||
|
enum e_action { allow, deny, set } action = allow;
|
||||||
|
|
||||||
|
struct sprotos const *pp;
|
||||||
|
|
||||||
|
/* Process token modifiers */
|
||||||
|
while(!ISALNUM(*token)) { /* may be NULL if token is all modifiers */
|
||||||
|
switch (*token++) {
|
||||||
|
case '=':
|
||||||
|
action = set;
|
||||||
|
break;
|
||||||
|
case '-':
|
||||||
|
action = deny;
|
||||||
|
break;
|
||||||
|
case '+':
|
||||||
|
action = allow;
|
||||||
|
break;
|
||||||
|
default: /* Includes case of terminating NULL */
|
||||||
|
Curl_safefree(buffer);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for(pp=protos; pp->name; pp++) {
|
||||||
|
if(curlx_raw_equal(token, pp->name)) {
|
||||||
|
switch (action) {
|
||||||
|
case deny:
|
||||||
|
*val &= ~(pp->bit);
|
||||||
|
break;
|
||||||
|
case allow:
|
||||||
|
*val |= pp->bit;
|
||||||
|
break;
|
||||||
|
case set:
|
||||||
|
*val = pp->bit;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!(pp->name)) { /* unknown protocol */
|
||||||
|
/* If they have specified only this protocol, we say treat it as
|
||||||
|
if no protocols are allowed */
|
||||||
|
if(action == set)
|
||||||
|
*val = 0;
|
||||||
|
warnf(config, "unrecognized protocol '%s'\n", token);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Curl_safefree(buffer);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses the given string looking for an offset (which may be
|
||||||
|
* a larger-than-integer value).
|
||||||
|
*
|
||||||
|
* @param val the offset to populate
|
||||||
|
* @param str the buffer containing the offset
|
||||||
|
* @return zero if successful, non-zero if failure.
|
||||||
|
*/
|
||||||
|
int str2offset(curl_off_t *val, const char *str)
|
||||||
|
{
|
||||||
|
#if(CURL_SIZEOF_CURL_OFF_T > CURL_SIZEOF_LONG)
|
||||||
|
*val = curlx_strtoofft(str, NULL, 0);
|
||||||
|
if((*val == CURL_OFF_T_MAX || *val == CURL_OFF_T_MIN) && (ERRNO == ERANGE))
|
||||||
|
return 1;
|
||||||
|
#else
|
||||||
|
*val = strtol(str, NULL, 0);
|
||||||
|
if((*val == LONG_MIN || *val == LONG_MAX) && ERRNO == ERANGE)
|
||||||
|
return 1;
|
||||||
|
#endif
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void checkpasswd(const char *kind, /* for what purpose */
|
||||||
|
char **userpwd) /* pointer to allocated string */
|
||||||
|
{
|
||||||
|
char *ptr;
|
||||||
|
if(!*userpwd)
|
||||||
|
return;
|
||||||
|
|
||||||
|
ptr = strchr(*userpwd, ':');
|
||||||
|
if(!ptr) {
|
||||||
|
/* no password present, prompt for one */
|
||||||
|
char passwd[256]="";
|
||||||
|
char prompt[256];
|
||||||
|
size_t passwdlen;
|
||||||
|
size_t userlen = strlen(*userpwd);
|
||||||
|
char *passptr;
|
||||||
|
|
||||||
|
/* build a nice-looking prompt */
|
||||||
|
curlx_msnprintf(prompt, sizeof(prompt),
|
||||||
|
"Enter %s password for user '%s':",
|
||||||
|
kind, *userpwd);
|
||||||
|
|
||||||
|
/* get password */
|
||||||
|
getpass_r(prompt, passwd, sizeof(passwd));
|
||||||
|
passwdlen = strlen(passwd);
|
||||||
|
|
||||||
|
/* extend the allocated memory area to fit the password too */
|
||||||
|
passptr = realloc(*userpwd,
|
||||||
|
passwdlen + 1 + /* an extra for the colon */
|
||||||
|
userlen + 1); /* an extra for the zero */
|
||||||
|
|
||||||
|
if(passptr) {
|
||||||
|
/* append the password separated with a colon */
|
||||||
|
passptr[userlen]=':';
|
||||||
|
memcpy(&passptr[userlen+1], passwd, passwdlen+1);
|
||||||
|
*userpwd = passptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ParameterError add2list(struct curl_slist **list, const char *ptr)
|
||||||
|
{
|
||||||
|
struct curl_slist *newlist = curl_slist_append(*list, ptr);
|
||||||
|
if(newlist)
|
||||||
|
*list = newlist;
|
||||||
|
else
|
||||||
|
return PARAM_NO_MEM;
|
||||||
|
|
||||||
|
return PARAM_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ftpfilemethod(struct Configurable *config, const char *str)
|
||||||
|
{
|
||||||
|
if(curlx_raw_equal("singlecwd", str))
|
||||||
|
return CURLFTPMETHOD_SINGLECWD;
|
||||||
|
if(curlx_raw_equal("nocwd", str))
|
||||||
|
return CURLFTPMETHOD_NOCWD;
|
||||||
|
if(curlx_raw_equal("multicwd", str))
|
||||||
|
return CURLFTPMETHOD_MULTICWD;
|
||||||
|
warnf(config, "unrecognized ftp file method '%s', using default\n", str);
|
||||||
|
return CURLFTPMETHOD_MULTICWD;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ftpcccmethod(struct Configurable *config, const char *str)
|
||||||
|
{
|
||||||
|
if(curlx_raw_equal("passive", str))
|
||||||
|
return CURLFTPSSL_CCC_PASSIVE;
|
||||||
|
if(curlx_raw_equal("active", str))
|
||||||
|
return CURLFTPSSL_CCC_ACTIVE;
|
||||||
|
warnf(config, "unrecognized ftp CCC method '%s', using default\n", str);
|
||||||
|
return CURLFTPSSL_CCC_PASSIVE;
|
||||||
|
}
|
||||||
|
|
||||||
|
long delegation(struct Configurable *config, char *str)
|
||||||
|
{
|
||||||
|
if(curlx_raw_equal("none", str))
|
||||||
|
return CURLGSSAPI_DELEGATION_NONE;
|
||||||
|
if(curlx_raw_equal("policy", str))
|
||||||
|
return CURLGSSAPI_DELEGATION_POLICY_FLAG;
|
||||||
|
if(curlx_raw_equal("always", str))
|
||||||
|
return CURLGSSAPI_DELEGATION_FLAG;
|
||||||
|
warnf(config, "unrecognized delegation method '%s', using none\n", str);
|
||||||
|
return CURLGSSAPI_DELEGATION_NONE;
|
||||||
|
}
|
||||||
|
|
53
src/tool_paramhlp.h
Normal file
53
src/tool_paramhlp.h
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
#ifndef HEADER_CURL_TOOL_PARAMHLP_H
|
||||||
|
#define HEADER_CURL_TOOL_PARAMHLP_H
|
||||||
|
/***************************************************************************
|
||||||
|
* _ _ ____ _
|
||||||
|
* Project ___| | | | _ \| |
|
||||||
|
* / __| | | | |_) | |
|
||||||
|
* | (__| |_| | _ <| |___
|
||||||
|
* \___|\___/|_| \_\_____|
|
||||||
|
*
|
||||||
|
* Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||||
|
*
|
||||||
|
* This software is licensed as described in the file COPYING, which
|
||||||
|
* you should have received as part of this distribution. The terms
|
||||||
|
* are also available at http://curl.haxx.se/docs/copyright.html.
|
||||||
|
*
|
||||||
|
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
||||||
|
* copies of the Software, and permit persons to whom the Software is
|
||||||
|
* furnished to do so, under the terms of the COPYING file.
|
||||||
|
*
|
||||||
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||||
|
* KIND, either express or implied.
|
||||||
|
*
|
||||||
|
***************************************************************************/
|
||||||
|
#include "setup.h"
|
||||||
|
|
||||||
|
struct getout *new_getout(struct Configurable *config);
|
||||||
|
|
||||||
|
ParameterError file2string(char **bufp, FILE *file);
|
||||||
|
|
||||||
|
ParameterError file2memory(char **bufp, size_t *size, FILE *file);
|
||||||
|
|
||||||
|
void cleanarg(char *str);
|
||||||
|
|
||||||
|
int str2num(long *val, const char *str);
|
||||||
|
|
||||||
|
long proto2num(struct Configurable *config, long *val, const char *str);
|
||||||
|
|
||||||
|
int str2offset(curl_off_t *val, const char *str);
|
||||||
|
|
||||||
|
void checkpasswd(const char *kind, char **userpwd);
|
||||||
|
|
||||||
|
ParameterError add2list(struct curl_slist **list, const char *ptr);
|
||||||
|
|
||||||
|
int ftpfilemethod(struct Configurable *config, const char *str);
|
||||||
|
|
||||||
|
int ftpcccmethod(struct Configurable *config, const char *str);
|
||||||
|
|
||||||
|
long delegation(struct Configurable *config, char *str);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* HEADER_CURL_TOOL_PARAMHLP_H */
|
||||||
|
|
309
src/tool_parsecfg.c
Normal file
309
src/tool_parsecfg.c
Normal file
@ -0,0 +1,309 @@
|
|||||||
|
/***************************************************************************
|
||||||
|
* _ _ ____ _
|
||||||
|
* Project ___| | | | _ \| |
|
||||||
|
* / __| | | | |_) | |
|
||||||
|
* | (__| |_| | _ <| |___
|
||||||
|
* \___|\___/|_| \_\_____|
|
||||||
|
*
|
||||||
|
* Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||||
|
*
|
||||||
|
* This software is licensed as described in the file COPYING, which
|
||||||
|
* you should have received as part of this distribution. The terms
|
||||||
|
* are also available at http://curl.haxx.se/docs/copyright.html.
|
||||||
|
*
|
||||||
|
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
||||||
|
* copies of the Software, and permit persons to whom the Software is
|
||||||
|
* furnished to do so, under the terms of the COPYING file.
|
||||||
|
*
|
||||||
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||||
|
* KIND, either express or implied.
|
||||||
|
*
|
||||||
|
***************************************************************************/
|
||||||
|
#include "setup.h"
|
||||||
|
|
||||||
|
#include <curl/curl.h>
|
||||||
|
|
||||||
|
#define ENABLE_CURLX_PRINTF
|
||||||
|
/* 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_msgs.h"
|
||||||
|
#include "tool_parsecfg.h"
|
||||||
|
|
||||||
|
#include "memdebug.h" /* keep this as LAST include */
|
||||||
|
|
||||||
|
#define CURLRC DOT_CHAR "curlrc"
|
||||||
|
#define ISSEP(x) (((x) == '=') || ((x) == ':'))
|
||||||
|
|
||||||
|
static const char *unslashquote(const char *line, char *param);
|
||||||
|
static char *my_get_line(FILE *fp);
|
||||||
|
|
||||||
|
/* return 0 on everything-is-fine, and non-zero otherwise */
|
||||||
|
int parseconfig(const char *filename,
|
||||||
|
struct Configurable *config)
|
||||||
|
{
|
||||||
|
int res;
|
||||||
|
FILE *file;
|
||||||
|
char filebuffer[512];
|
||||||
|
bool usedarg;
|
||||||
|
char *home;
|
||||||
|
int rc = 0;
|
||||||
|
|
||||||
|
if(!filename || !*filename) {
|
||||||
|
/* NULL or no file name attempts to load .curlrc from the homedir! */
|
||||||
|
|
||||||
|
#ifndef __AMIGA__
|
||||||
|
filename = CURLRC; /* sensible default */
|
||||||
|
home = homedir(); /* portable homedir finder */
|
||||||
|
if(home) {
|
||||||
|
if(strlen(home) < (sizeof(filebuffer) - strlen(CURLRC))) {
|
||||||
|
snprintf(filebuffer, sizeof(filebuffer),
|
||||||
|
"%s%s%s", home, DIR_CHAR, CURLRC);
|
||||||
|
|
||||||
|
#ifdef WIN32
|
||||||
|
/* Check if the file exists - if not, try CURLRC in the same
|
||||||
|
* directory as our executable
|
||||||
|
*/
|
||||||
|
file = fopen(filebuffer, "r");
|
||||||
|
if(file != NULL) {
|
||||||
|
fclose(file);
|
||||||
|
filename = filebuffer;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
/* Get the filename of our executable. GetModuleFileName is
|
||||||
|
* already declared via inclusions done in setup header file.
|
||||||
|
* We assume that we are using the ASCII version here.
|
||||||
|
*/
|
||||||
|
int n = GetModuleFileName(0, filebuffer, sizeof(filebuffer));
|
||||||
|
if(n > 0 && n < (int)sizeof(filebuffer)) {
|
||||||
|
/* We got a valid filename - get the directory part */
|
||||||
|
char *lastdirchar = strrchr(filebuffer, '\\');
|
||||||
|
if(lastdirchar) {
|
||||||
|
size_t remaining;
|
||||||
|
*lastdirchar = 0;
|
||||||
|
/* If we have enough space, build the RC filename */
|
||||||
|
remaining = sizeof(filebuffer) - strlen(filebuffer);
|
||||||
|
if(strlen(CURLRC) < remaining - 1) {
|
||||||
|
snprintf(lastdirchar, remaining,
|
||||||
|
"%s%s", DIR_CHAR, CURLRC);
|
||||||
|
/* Don't bother checking if it exists - we do
|
||||||
|
* that later
|
||||||
|
*/
|
||||||
|
filename = filebuffer;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#else /* WIN32 */
|
||||||
|
filename = filebuffer;
|
||||||
|
#endif /* WIN32 */
|
||||||
|
}
|
||||||
|
Curl_safefree(home); /* we've used it, now free it */
|
||||||
|
}
|
||||||
|
|
||||||
|
# else /* __AMIGA__ */
|
||||||
|
/* On AmigaOS all the config files are into env:
|
||||||
|
*/
|
||||||
|
filename = "ENV:" CURLRC;
|
||||||
|
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
if(strcmp(filename,"-"))
|
||||||
|
file = fopen(filename, "r");
|
||||||
|
else
|
||||||
|
file = stdin;
|
||||||
|
|
||||||
|
if(file) {
|
||||||
|
char *line;
|
||||||
|
char *aline;
|
||||||
|
char *option;
|
||||||
|
char *param;
|
||||||
|
int lineno = 0;
|
||||||
|
bool alloced_param;
|
||||||
|
|
||||||
|
while(NULL != (aline = my_get_line(file))) {
|
||||||
|
lineno++;
|
||||||
|
line = aline;
|
||||||
|
alloced_param=FALSE;
|
||||||
|
|
||||||
|
/* line with # in the first non-blank column is a comment! */
|
||||||
|
while(*line && ISSPACE(*line))
|
||||||
|
line++;
|
||||||
|
|
||||||
|
switch(*line) {
|
||||||
|
case '#':
|
||||||
|
case '/':
|
||||||
|
case '\r':
|
||||||
|
case '\n':
|
||||||
|
case '*':
|
||||||
|
case '\0':
|
||||||
|
Curl_safefree(aline);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* the option keywords starts here */
|
||||||
|
option = line;
|
||||||
|
while(*line && !ISSPACE(*line) && !ISSEP(*line))
|
||||||
|
line++;
|
||||||
|
/* ... and has ended here */
|
||||||
|
|
||||||
|
if(*line)
|
||||||
|
*line++ = '\0'; /* zero terminate, we have a local copy of the data */
|
||||||
|
|
||||||
|
#ifdef DEBUG_CONFIG
|
||||||
|
fprintf(stderr, "GOT: %s\n", option);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* pass spaces and separator(s) */
|
||||||
|
while(*line && (ISSPACE(*line) || ISSEP(*line)))
|
||||||
|
line++;
|
||||||
|
|
||||||
|
/* the parameter starts here (unless quoted) */
|
||||||
|
if(*line == '\"') {
|
||||||
|
/* quoted parameter, do the quote dance */
|
||||||
|
line++;
|
||||||
|
param = malloc(strlen(line) + 1); /* parameter */
|
||||||
|
if(!param) {
|
||||||
|
/* out of memory */
|
||||||
|
Curl_safefree(aline);
|
||||||
|
rc = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
alloced_param = TRUE;
|
||||||
|
(void)unslashquote(line, param);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
param = line; /* parameter starts here */
|
||||||
|
while(*line && !ISSPACE(*line))
|
||||||
|
line++;
|
||||||
|
*line = '\0'; /* zero terminate */
|
||||||
|
}
|
||||||
|
|
||||||
|
if(param && !*param) {
|
||||||
|
/* do this so getparameter can check for required parameters.
|
||||||
|
Otherwise it always thinks there's a parameter. */
|
||||||
|
if(alloced_param)
|
||||||
|
Curl_safefree(param);
|
||||||
|
param = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef DEBUG_CONFIG
|
||||||
|
fprintf(stderr, "PARAM: \"%s\"\n",(param ? param : "(null)"));
|
||||||
|
#endif
|
||||||
|
res = getparameter(option, param, &usedarg, config);
|
||||||
|
|
||||||
|
if(param && *param && !usedarg)
|
||||||
|
/* we passed in a parameter that wasn't used! */
|
||||||
|
res = PARAM_GOT_EXTRA_PARAMETER;
|
||||||
|
|
||||||
|
if(res != PARAM_OK) {
|
||||||
|
/* the help request isn't really an error */
|
||||||
|
if(!strcmp(filename, "-")) {
|
||||||
|
filename = (char *)"<stdin>";
|
||||||
|
}
|
||||||
|
if(PARAM_HELP_REQUESTED != res) {
|
||||||
|
const char *reason = param2text(res);
|
||||||
|
warnf(config, "%s:%d: warning: '%s' %s\n",
|
||||||
|
filename, lineno, option, reason);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(alloced_param)
|
||||||
|
Curl_safefree(param);
|
||||||
|
|
||||||
|
Curl_safefree(aline);
|
||||||
|
}
|
||||||
|
if(file != stdin)
|
||||||
|
fclose(file);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
rc = 1; /* couldn't open the file */
|
||||||
|
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copies the string from line to the buffer at param, unquoting
|
||||||
|
* backslash-quoted characters and NUL-terminating the output string.
|
||||||
|
* Stops at the first non-backslash-quoted double quote character or the
|
||||||
|
* end of the input string. param must be at least as long as the input
|
||||||
|
* string. Returns the pointer after the last handled input character.
|
||||||
|
*/
|
||||||
|
static const char *unslashquote(const char *line, char *param)
|
||||||
|
{
|
||||||
|
while(*line && (*line != '\"')) {
|
||||||
|
if(*line == '\\') {
|
||||||
|
char out;
|
||||||
|
line++;
|
||||||
|
|
||||||
|
/* default is to output the letter after the backslash */
|
||||||
|
switch(out = *line) {
|
||||||
|
case '\0':
|
||||||
|
continue; /* this'll break out of the loop */
|
||||||
|
case 't':
|
||||||
|
out = '\t';
|
||||||
|
break;
|
||||||
|
case 'n':
|
||||||
|
out = '\n';
|
||||||
|
break;
|
||||||
|
case 'r':
|
||||||
|
out = '\r';
|
||||||
|
break;
|
||||||
|
case 'v':
|
||||||
|
out = '\v';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
*param++ = out;
|
||||||
|
line++;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
*param++ = *line++;
|
||||||
|
}
|
||||||
|
*param = '\0'; /* always zero terminate */
|
||||||
|
return line;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Reads a line from the given file, ensuring is NUL terminated.
|
||||||
|
* The pointer must be freed by the caller.
|
||||||
|
* NULL is returned on an out of memory condition.
|
||||||
|
*/
|
||||||
|
static char *my_get_line(FILE *fp)
|
||||||
|
{
|
||||||
|
char buf[4096];
|
||||||
|
char *nl = NULL;
|
||||||
|
char *retval = NULL;
|
||||||
|
|
||||||
|
do {
|
||||||
|
if(NULL == fgets(buf, sizeof(buf), fp))
|
||||||
|
break;
|
||||||
|
if(!retval) {
|
||||||
|
retval = strdup(buf);
|
||||||
|
if(!retval)
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
char *ptr;
|
||||||
|
ptr = realloc(retval, strlen(retval) + strlen(buf) + 1);
|
||||||
|
if(!ptr) {
|
||||||
|
Curl_safefree(retval);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
retval = ptr;
|
||||||
|
strcat(retval, buf);
|
||||||
|
}
|
||||||
|
nl = strchr(retval, '\n');
|
||||||
|
} while(!nl);
|
||||||
|
|
||||||
|
if(nl)
|
||||||
|
*nl = '\0';
|
||||||
|
|
||||||
|
return retval;
|
||||||
|
}
|
||||||
|
|
30
src/tool_parsecfg.h
Normal file
30
src/tool_parsecfg.h
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
#ifndef HEADER_CURL_TOOL_PARSECFG_H
|
||||||
|
#define HEADER_CURL_TOOL_PARSECFG_H
|
||||||
|
/***************************************************************************
|
||||||
|
* _ _ ____ _
|
||||||
|
* Project ___| | | | _ \| |
|
||||||
|
* / __| | | | |_) | |
|
||||||
|
* | (__| |_| | _ <| |___
|
||||||
|
* \___|\___/|_| \_\_____|
|
||||||
|
*
|
||||||
|
* Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||||
|
*
|
||||||
|
* This software is licensed as described in the file COPYING, which
|
||||||
|
* you should have received as part of this distribution. The terms
|
||||||
|
* are also available at http://curl.haxx.se/docs/copyright.html.
|
||||||
|
*
|
||||||
|
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
||||||
|
* copies of the Software, and permit persons to whom the Software is
|
||||||
|
* furnished to do so, under the terms of the COPYING file.
|
||||||
|
*
|
||||||
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||||
|
* KIND, either express or implied.
|
||||||
|
*
|
||||||
|
***************************************************************************/
|
||||||
|
#include "setup.h"
|
||||||
|
|
||||||
|
int parseconfig(const char *filename,
|
||||||
|
struct Configurable *config);
|
||||||
|
|
||||||
|
#endif /* HEADER_CURL_TOOL_PARSECFG_H */
|
||||||
|
|
58
src/tool_sleep.c
Normal file
58
src/tool_sleep.c
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
/***************************************************************************
|
||||||
|
* _ _ ____ _
|
||||||
|
* Project ___| | | | _ \| |
|
||||||
|
* / __| | | | |_) | |
|
||||||
|
* | (__| |_| | _ <| |___
|
||||||
|
* \___|\___/|_| \_\_____|
|
||||||
|
*
|
||||||
|
* Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||||
|
*
|
||||||
|
* This software is licensed as described in the file COPYING, which
|
||||||
|
* you should have received as part of this distribution. The terms
|
||||||
|
* are also available at http://curl.haxx.se/docs/copyright.html.
|
||||||
|
*
|
||||||
|
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
||||||
|
* copies of the Software, and permit persons to whom the Software is
|
||||||
|
* furnished to do so, under the terms of the COPYING file.
|
||||||
|
*
|
||||||
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||||
|
* KIND, either express or implied.
|
||||||
|
*
|
||||||
|
***************************************************************************/
|
||||||
|
#include "setup.h"
|
||||||
|
|
||||||
|
#ifdef HAVE_SYS_SELECT_H
|
||||||
|
# include <sys/select.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef HAVE_SYS_POLL_H
|
||||||
|
# include <sys/poll.h>
|
||||||
|
#elif defined(HAVE_POLL_H)
|
||||||
|
# include <poll.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef MSDOS
|
||||||
|
# include <dos.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "tool_sleep.h"
|
||||||
|
|
||||||
|
#include "memdebug.h" /* keep this as LAST include */
|
||||||
|
|
||||||
|
void tool_go_sleep(long ms)
|
||||||
|
{
|
||||||
|
#if defined(MSDOS)
|
||||||
|
delay(ms);
|
||||||
|
#elif defined(WIN32)
|
||||||
|
Sleep(ms);
|
||||||
|
#elif defined(HAVE_POLL_FINE)
|
||||||
|
poll((void *)0, 0, (int)ms);
|
||||||
|
#else
|
||||||
|
struct timeval timeout;
|
||||||
|
timeout.tv_sec = ms / 1000L;
|
||||||
|
ms = ms % 1000L;
|
||||||
|
timeout.tv_usec = ms * 1000L;
|
||||||
|
select(0, NULL, NULL, NULL, &timeout);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
29
src/tool_sleep.h
Normal file
29
src/tool_sleep.h
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
#ifndef HEADER_CURL_TOOL_SLEEP_H
|
||||||
|
#define HEADER_CURL_TOOL_SLEEP_H
|
||||||
|
/***************************************************************************
|
||||||
|
* _ _ ____ _
|
||||||
|
* Project ___| | | | _ \| |
|
||||||
|
* / __| | | | |_) | |
|
||||||
|
* | (__| |_| | _ <| |___
|
||||||
|
* \___|\___/|_| \_\_____|
|
||||||
|
*
|
||||||
|
* Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||||
|
*
|
||||||
|
* This software is licensed as described in the file COPYING, which
|
||||||
|
* you should have received as part of this distribution. The terms
|
||||||
|
* are also available at http://curl.haxx.se/docs/copyright.html.
|
||||||
|
*
|
||||||
|
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
||||||
|
* copies of the Software, and permit persons to whom the Software is
|
||||||
|
* furnished to do so, under the terms of the COPYING file.
|
||||||
|
*
|
||||||
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||||
|
* KIND, either express or implied.
|
||||||
|
*
|
||||||
|
***************************************************************************/
|
||||||
|
#include "setup.h"
|
||||||
|
|
||||||
|
void tool_go_sleep(long ms);
|
||||||
|
|
||||||
|
#endif /* HEADER_CURL_TOOL_SLEEP_H */
|
||||||
|
|
@ -155,10 +155,6 @@ SOURCE=.\hugehelp.c
|
|||||||
# End Source File
|
# End Source File
|
||||||
# Begin Source File
|
# Begin Source File
|
||||||
|
|
||||||
SOURCE=.\main.c
|
|
||||||
# End Source File
|
|
||||||
# Begin Source File
|
|
||||||
|
|
||||||
SOURCE=..\lib\nonblock.c
|
SOURCE=..\lib\nonblock.c
|
||||||
# End Source File
|
# End Source File
|
||||||
# Begin Source File
|
# Begin Source File
|
||||||
@ -231,10 +227,26 @@ SOURCE=.\tool_formparse.c
|
|||||||
# End Source File
|
# End Source File
|
||||||
# Begin Source File
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\tool_getparam.c
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\tool_help.c
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\tool_helpers.c
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
SOURCE=.\tool_libinfo.c
|
SOURCE=.\tool_libinfo.c
|
||||||
# End Source File
|
# End Source File
|
||||||
# Begin Source File
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\tool_main.c
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
SOURCE=.\tool_mfiles.c
|
SOURCE=.\tool_mfiles.c
|
||||||
# End Source File
|
# End Source File
|
||||||
# Begin Source File
|
# Begin Source File
|
||||||
@ -243,7 +255,23 @@ SOURCE=.\tool_msgs.c
|
|||||||
# End Source File
|
# End Source File
|
||||||
# Begin Source File
|
# Begin Source File
|
||||||
|
|
||||||
SOURCE=.\tool_myfunc.c
|
SOURCE=.\tool_operate.c
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\tool_operhlp.c
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\tool_panykey.c
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\tool_paramhlp.c
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\tool_parsecfg.c
|
||||||
# End Source File
|
# End Source File
|
||||||
# Begin Source File
|
# Begin Source File
|
||||||
|
|
||||||
@ -251,6 +279,10 @@ SOURCE=.\tool_setopt.c
|
|||||||
# End Source File
|
# End Source File
|
||||||
# Begin Source File
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\tool_sleep.c
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
SOURCE=.\tool_vms.c
|
SOURCE=.\tool_vms.c
|
||||||
# End Source File
|
# End Source File
|
||||||
# Begin Source File
|
# Begin Source File
|
||||||
@ -371,10 +403,26 @@ SOURCE=.\tool_formparse.h
|
|||||||
# End Source File
|
# End Source File
|
||||||
# Begin Source File
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\tool_getparam.h
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\tool_help.h
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\tool_helpers.h
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
SOURCE=.\tool_libinfo.h
|
SOURCE=.\tool_libinfo.h
|
||||||
# End Source File
|
# End Source File
|
||||||
# Begin Source File
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\tool_main.h
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
SOURCE=.\tool_mfiles.h
|
SOURCE=.\tool_mfiles.h
|
||||||
# End Source File
|
# End Source File
|
||||||
# Begin Source File
|
# Begin Source File
|
||||||
@ -383,7 +431,23 @@ SOURCE=.\tool_msgs.h
|
|||||||
# End Source File
|
# End Source File
|
||||||
# Begin Source File
|
# Begin Source File
|
||||||
|
|
||||||
SOURCE=.\tool_myfunc.h
|
SOURCE=.\tool_operate.h
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\tool_operhlp.h
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\tool_panykey.h
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\tool_paramhlp.h
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\tool_parsecfg.h
|
||||||
# End Source File
|
# End Source File
|
||||||
# Begin Source File
|
# Begin Source File
|
||||||
|
|
||||||
@ -395,6 +459,10 @@ SOURCE=.\tool_setopt.h
|
|||||||
# End Source File
|
# End Source File
|
||||||
# Begin Source File
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\tool_sleep.h
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
SOURCE=.\tool_vms.h
|
SOURCE=.\tool_vms.h
|
||||||
# End Source File
|
# End Source File
|
||||||
# Begin Source File
|
# Begin Source File
|
||||||
|
Loading…
Reference in New Issue
Block a user