curl tool: create tool_myfunc.[ch] which later on will hold my_* functions
Additionally function my_useragent() now provides default User-Agent string
This commit is contained in:
Родитель
f50d4647d0
Коммит
260b0f4d0c
|
@ -10,7 +10,7 @@ SOURCEPATH ../../../src
|
|||
SOURCE \
|
||||
main.c hugehelp.c urlglob.c writeout.c writeenv.c \
|
||||
getpass.c homedir.c curlutil.c os-specific.c xattr.c \
|
||||
tool_cfgable.c tool_convert.c tool_mfiles.c
|
||||
tool_cfgable.c tool_convert.c tool_mfiles.c tool_myfunc.c
|
||||
|
||||
SOURCEPATH ../../../lib
|
||||
SOURCE \
|
||||
|
|
|
@ -16,12 +16,13 @@ CURLX_ONES = $(top_srcdir)/lib/strtoofft.c \
|
|||
|
||||
CURL_CFILES = main.c hugehelp.c urlglob.c writeout.c writeenv.c \
|
||||
getpass.c homedir.c curlutil.c os-specific.c xattr.c \
|
||||
tool_cfgable.c tool_convert.c tool_mfiles.c
|
||||
tool_cfgable.c tool_convert.c tool_mfiles.c tool_myfunc.c
|
||||
|
||||
CURL_HFILES = hugehelp.h setup.h config-win32.h config-mac.h \
|
||||
config-riscos.h urlglob.h version.h os-specific.h \
|
||||
writeout.h writeenv.h getpass.h homedir.h curlutil.h \
|
||||
xattr.h tool_cfgable.h tool_convert.h tool_mfiles.h
|
||||
xattr.h tool_cfgable.h tool_convert.h tool_mfiles.h \
|
||||
tool_myfunc.h
|
||||
|
||||
curl_SOURCES = $(CURL_CFILES) $(CURLX_ONES) $(CURL_HFILES)
|
||||
|
||||
|
|
|
@ -145,6 +145,7 @@ RELEASE_OBJS= \
|
|||
tool_cfgabler.obj \
|
||||
tool_convertr.obj \
|
||||
tool_mfilesr.obj \
|
||||
tool_myfuncr.obj \
|
||||
urlglobr.obj \
|
||||
writeoutr.obj \
|
||||
xattrr.obj \
|
||||
|
@ -163,6 +164,7 @@ DEBUG_OBJS= \
|
|||
tool_cfgabled.obj \
|
||||
tool_convertd.obj \
|
||||
tool_mfilesd.obj \
|
||||
tool_myfuncd.obj \
|
||||
urlglobd.obj \
|
||||
writeoutd.obj \
|
||||
xattrd.obj \
|
||||
|
@ -314,6 +316,8 @@ tool_convertr.obj: tool_convert.c
|
|||
$(CCR) $(CFLAGS) /Fo"$@" tool_convert.c
|
||||
tool_mfilesr.obj: tool_mfiles.c
|
||||
$(CCR) $(CFLAGS) /Fo"$@" tool_mfiles.c
|
||||
tool_myfuncr.obj: tool_myfunc.c
|
||||
$(CCR) $(CFLAGS) /Fo"$@" tool_myfunc.c
|
||||
xattrr.obj: xattr.c
|
||||
$(CCR) $(CFLAGS) /Fo"$@" xattr.c
|
||||
mainr.obj: main.c
|
||||
|
@ -348,6 +352,8 @@ tool_convertd.obj: tool_convert.c
|
|||
$(CCD) $(CFLAGS) /Fo"$@" tool_convert.c
|
||||
tool_mfilesd.obj: tool_mfiles.c
|
||||
$(CCD) $(CFLAGS) /Fo"$@" tool_mfiles.c
|
||||
tool_myfuncd.obj: tool_myfunc.c
|
||||
$(CCD) $(CFLAGS) /Fo"$@" tool_myfunc.c
|
||||
xattrd.obj: xattr.c
|
||||
$(CCD) $(CFLAGS) /Fo"$@" xattr.c
|
||||
maind.obj: main.c
|
||||
|
|
21
src/main.c
21
src/main.c
|
@ -114,6 +114,7 @@
|
|||
#include "tool_convert.h"
|
||||
#include "tool_mfiles.h"
|
||||
#include "tool_cfgable.h"
|
||||
#include "tool_myfunc.h"
|
||||
#ifdef USE_MANUAL
|
||||
# include "hugehelp.h"
|
||||
#endif
|
||||
|
@ -4132,7 +4133,6 @@ static int
|
|||
operate(struct Configurable *config, int argc, argv_item_t argv[])
|
||||
{
|
||||
char errorbuffer[CURL_ERROR_SIZE];
|
||||
char useragent[256]; /* buah, we don't want a larger default user agent */
|
||||
struct ProgressData progressbar;
|
||||
struct getout *urlnode;
|
||||
struct getout *nextnode;
|
||||
|
@ -4150,8 +4150,6 @@ operate(struct Configurable *config, int argc, argv_item_t argv[])
|
|||
curl_off_t uploadfilesize; /* -1 means unknown */
|
||||
bool stillflags=TRUE;
|
||||
|
||||
bool allocuseragent=FALSE;
|
||||
|
||||
char *httpgetfields=NULL;
|
||||
|
||||
CURL *curl;
|
||||
|
@ -4281,14 +4279,14 @@ operate(struct Configurable *config, int argc, argv_item_t argv[])
|
|||
helpf(config->errors, "no URL specified!\n");
|
||||
return CURLE_FAILED_INIT;
|
||||
}
|
||||
if(NULL == config->useragent) {
|
||||
/* set non-zero default values: */
|
||||
snprintf(useragent, sizeof(useragent),
|
||||
CURL_NAME "/" CURL_VERSION " (" OS ") " "%s", curl_version());
|
||||
config->useragent= useragent;
|
||||
|
||||
if(!config->useragent)
|
||||
config->useragent = my_useragent();
|
||||
if(!config->useragent) {
|
||||
clean_getout(config);
|
||||
res = CURLE_OUT_OF_MEMORY;
|
||||
goto quit_curl;
|
||||
}
|
||||
else
|
||||
allocuseragent = TRUE;
|
||||
|
||||
/* On WIN32 we can't set the path to curl-ca-bundle.crt
|
||||
* at compile time. So we look here for the file in two ways:
|
||||
|
@ -5393,9 +5391,6 @@ operate(struct Configurable *config, int argc, argv_item_t argv[])
|
|||
if(heads.stream && (heads.stream != stdout))
|
||||
fclose(heads.stream);
|
||||
|
||||
if(allocuseragent)
|
||||
Curl_safefree(config->useragent);
|
||||
|
||||
if(config->trace_fopened && config->trace_stream)
|
||||
fclose(config->trace_stream);
|
||||
|
||||
|
|
|
@ -38,9 +38,7 @@ void free_config_fields(struct Configurable *config)
|
|||
|
||||
Curl_safefree(config->random_file);
|
||||
Curl_safefree(config->egd_file);
|
||||
|
||||
/* config->useragent not handled */
|
||||
|
||||
Curl_safefree(config->useragent);
|
||||
Curl_safefree(config->cookie);
|
||||
Curl_safefree(config->cookiejar);
|
||||
Curl_safefree(config->cookiefile);
|
||||
|
@ -123,3 +121,4 @@ void free_config_fields(struct Configurable *config)
|
|||
/* config->outs not handled */
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* 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 "version.h"
|
||||
#include "tool_myfunc.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);
|
||||
}
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
#ifndef HEADER_CURL_TOOL_MYFUNC_H
|
||||
#define HEADER_CURL_TOOL_MYFUNC_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);
|
||||
|
||||
#endif /* HEADER_CURL_TOOL_MYFUNC_H */
|
||||
|
|
@ -187,6 +187,10 @@ SOURCE=.\tool_mfiles.c
|
|||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\tool_myfunc.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\urlglob.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
@ -259,6 +263,10 @@ SOURCE=.\tool_mfiles.h
|
|||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\tool_myfunc.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\urlglob.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
|
Загрузка…
Ссылка в новой задаче