"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/tool_parsecfg.c" between
curl-7.65.3.tar.xz and curl-7.66.0.tar.xz

About: cURL is a powerful commandline tool to transfer data from or to a server, using one of the supported protocols HTTP(S), FTP(S), SCP, SFTP, TFTP, DICT, TELNET, LDAP(S) or FILE.

tool_parsecfg.c  (curl-7.65.3.tar.xz):tool_parsecfg.c  (curl-7.66.0.tar.xz)
skipping to change at line 37 skipping to change at line 37
#include "tool_cfgable.h" #include "tool_cfgable.h"
#include "tool_getparam.h" #include "tool_getparam.h"
#include "tool_helpers.h" #include "tool_helpers.h"
#include "tool_homedir.h" #include "tool_homedir.h"
#include "tool_msgs.h" #include "tool_msgs.h"
#include "tool_parsecfg.h" #include "tool_parsecfg.h"
#include "memdebug.h" /* keep this as LAST include */ #include "memdebug.h" /* keep this as LAST include */
#define CURLRC DOT_CHAR "curlrc"
/* only acknowledge colon or equals as separators if the option was not /* only acknowledge colon or equals as separators if the option was not
specified with an initial dash! */ specified with an initial dash! */
#define ISSEP(x,dash) (!dash && (((x) == '=') || ((x) == ':'))) #define ISSEP(x,dash) (!dash && (((x) == '=') || ((x) == ':')))
static const char *unslashquote(const char *line, char *param); static const char *unslashquote(const char *line, char *param);
static char *my_get_line(FILE *fp); static char *my_get_line(FILE *fp);
#ifdef WIN32
static FILE *execpath(const char *filename)
{
char filebuffer[512];
/* 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.
*/
unsigned long len = GetModuleFileNameA(0, filebuffer, sizeof(filebuffer));
if(len > 0 && len < 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(filename) < remaining - 1) {
msnprintf(lastdirchar, remaining, "%s%s", DIR_CHAR, filename);
return fopen(filebuffer, FOPEN_READTEXT);
}
}
}
return NULL;
}
#endif
/* return 0 on everything-is-fine, and non-zero otherwise */ /* return 0 on everything-is-fine, and non-zero otherwise */
int parseconfig(const char *filename, struct GlobalConfig *global) int parseconfig(const char *filename, struct GlobalConfig *global)
{ {
FILE *file = NULL; FILE *file = NULL;
char filebuffer[512];
bool usedarg = FALSE; bool usedarg = FALSE;
int rc = 0; int rc = 0;
struct OperationConfig *operation = global->first; struct OperationConfig *operation = global->first;
char *pathalloc = NULL;
if(!filename || !*filename) { if(!filename || !*filename) {
/* NULL or no file name attempts to load .curlrc from the homedir! */ /* NULL or no file name attempts to load .curlrc from the homedir! */
#ifndef __AMIGA__
char *home = homedir(); /* portable homedir finder */ char *home = homedir(); /* portable homedir finder */
filename = CURLRC; /* sensible default */ #ifndef WIN32
if(home) { if(home) {
if(strlen(home) < (sizeof(filebuffer) - strlen(CURLRC))) { pathalloc = curl_maprintf("%s%s.curlrc", home, DIR_CHAR);
msnprintf(filebuffer, sizeof(filebuffer), if(!pathalloc) {
"%s%s%s", home, DIR_CHAR, CURLRC); free(home);
return 1; /* out of memory */
#ifdef WIN32
/* Check if the file exists - if not, try CURLRC in the same
* directory as our executable
*/
file = fopen(filebuffer, FOPEN_READTEXT);
if(file != NULL) {
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.
*/
unsigned long len = GetModuleFileNameA(0, filebuffer,
sizeof(filebuffer));
if(len > 0 && len < 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) {
msnprintf(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 */ filename = pathalloc;
} }
#else /* Windows */
if(home) {
int i = 0;
char prefix = '.';
do {
/* check for .curlrc then _curlrc in the home dir */
pathalloc = curl_maprintf("%s%s%ccurlrc", home, DIR_CHAR, prefix);
if(!pathalloc) {
free(home);
return 1; /* out of memory */
}
# else /* __AMIGA__ */ /* Check if the file exists - if not, try _curlrc */
/* On AmigaOS all the config files are into env: file = fopen(pathalloc, FOPEN_READTEXT);
*/ if(file) {
filename = "ENV:" CURLRC; filename = pathalloc;
break;
}
prefix = '_';
} while(++i < 2);
}
if(!filename) {
/* check for .curlrc then _curlrc in the dir of the executable */
file = execpath(".curlrc");
if(!file)
file = execpath("_curlrc");
}
#endif #endif
Curl_safefree(home); /* we've used it, now free it */
} }
if(!file) { /* WIN32: no need to fopen() again */ if(!file && filename) { /* no need to fopen() again */
if(strcmp(filename, "-")) if(strcmp(filename, "-"))
file = fopen(filename, FOPEN_READTEXT); file = fopen(filename, FOPEN_READTEXT);
else else
file = stdin; file = stdin;
} }
if(file) { if(file) {
char *line; char *line;
char *aline; char *aline;
char *option; char *option;
skipping to change at line 233 skipping to change at line 246
res = PARAM_GOT_EXTRA_PARAMETER; res = PARAM_GOT_EXTRA_PARAMETER;
if(res == PARAM_NEXT_OPERATION) { if(res == PARAM_NEXT_OPERATION) {
if(operation->url_list && operation->url_list->url) { if(operation->url_list && operation->url_list->url) {
/* Allocate the next config */ /* Allocate the next config */
operation->next = malloc(sizeof(struct OperationConfig)); operation->next = malloc(sizeof(struct OperationConfig));
if(operation->next) { if(operation->next) {
/* Initialise the newly created config */ /* Initialise the newly created config */
config_init(operation->next); config_init(operation->next);
/* Copy the easy handle */
operation->next->easy = global->easy;
/* Set the global config pointer */ /* Set the global config pointer */
operation->next->global = global; operation->next->global = global;
/* Update the last operation pointer */ /* Update the last operation pointer */
global->last = operation->next; global->last = operation->next;
/* Move onto the new config */ /* Move onto the new config */
operation->next->prev = operation; operation->next->prev = operation;
operation = operation->next; operation = operation->next;
} }
skipping to change at line 277 skipping to change at line 287
Curl_safefree(param); Curl_safefree(param);
Curl_safefree(aline); Curl_safefree(aline);
} }
if(file != stdin) if(file != stdin)
fclose(file); fclose(file);
} }
else else
rc = 1; /* couldn't open the file */ rc = 1; /* couldn't open the file */
free(pathalloc);
return rc; return rc;
} }
/* /*
* Copies the string from line to the buffer at param, unquoting * Copies the string from line to the buffer at param, unquoting
* backslash-quoted characters and NUL-terminating the output string. * backslash-quoted characters and NUL-terminating the output string.
* Stops at the first non-backslash-quoted double quote character or the * 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 * 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. * string. Returns the pointer after the last handled input character.
*/ */
 End of changes. 14 change blocks. 
54 lines changed or deleted 65 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)