Skip to content

Commit

Permalink
curl tool: create tool_myfunc.[ch] which later on will hold my_* func…
Browse files Browse the repository at this point in the history
…tions

Additionally function my_useragent() now provides default User-Agent string
  • Loading branch information
yangtse committed Sep 17, 2011
1 parent f50d464 commit 260b0f4
Show file tree
Hide file tree
Showing 8 changed files with 105 additions and 19 deletions.
2 changes: 1 addition & 1 deletion packages/Symbian/group/curl.mmp
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
5 changes: 3 additions & 2 deletions src/Makefile.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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)

6 changes: 6 additions & 0 deletions src/Makefile.vc6
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ RELEASE_OBJS= \
tool_cfgabler.obj \
tool_convertr.obj \
tool_mfilesr.obj \
tool_myfuncr.obj \
urlglobr.obj \
writeoutr.obj \
xattrr.obj \
Expand All @@ -163,6 +164,7 @@ DEBUG_OBJS= \
tool_cfgabled.obj \
tool_convertd.obj \
tool_mfilesd.obj \
tool_myfuncd.obj \
urlglobd.obj \
writeoutd.obj \
xattrd.obj \
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
21 changes: 8 additions & 13 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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);

Expand Down
5 changes: 2 additions & 3 deletions src/tool_cfgable.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -123,3 +121,4 @@ void free_config_fields(struct Configurable *config)
/* config->outs not handled */

}

48 changes: 48 additions & 0 deletions src/tool_myfunc.c
Original file line number Diff line number Diff line change
@@ -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);
}

29 changes: 29 additions & 0 deletions src/tool_myfunc.h
Original file line number Diff line number Diff line change
@@ -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 */

8 changes: 8 additions & 0 deletions src/vc6curlsrc.dsp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 260b0f4

Please sign in to comment.