X-Git-Url: http://www.privoxy.org/gitweb/?a=blobdiff_plain;f=miscutil.c;h=6298e9de1205a3d9c328f47ee03cfa510be40535;hb=f09cf90bb03348ea74740a292aa48813c55f1875;hp=499579f7f4b2eda4162174383f3d2be7cb512e2b;hpb=afa231b8e31bbf0489303df30d103db2d737cd18;p=privoxy.git diff --git a/miscutil.c b/miscutil.c index 499579f7..6298e9de 100644 --- a/miscutil.c +++ b/miscutil.c @@ -7,7 +7,7 @@ * to deserve their own file but don't really fit in * any other file. * - * Copyright : Written by and Copyright (C) 2001-2020 the + * Copyright : Written by and Copyright (C) 2001-2022 the * Privoxy team. https://www.privoxy.org/ * * Based on the Internet Junkbuster originally written @@ -242,7 +242,7 @@ void write_pid_file(const char *pid_file) * * Function : hash_string * - * Description : Take a string and compute a (hopefuly) unique numeric + * Description : Take a string and compute a (hopefully) unique numeric * integer value. This is useful to "switch" a string. * * Parameters : @@ -560,6 +560,43 @@ char *string_toupper(const char *string) } +/********************************************************************* + * + * Function : string_tolower + * + * Description : Produce a copy of string with all convertible + * characters converted to lowercase. + * + * Parameters : + * 1 : string = string to convert + * + * Returns : Lowercase copy of string if possible, + * NULL on out-of-memory or if string was NULL. + * + *********************************************************************/ +char *string_tolower(const char *string) +{ + char *result, *p; + const char *q; + + if (!string || ((result = (char *)zalloc(strlen(string) + 1)) == NULL)) + { + return NULL; + } + + q = string; + p = result; + + while (*q != '\0') + { + *p++ = (char)privoxy_tolower(*q++); + } + + return result; + +} + + /********************************************************************* * * Function : string_move @@ -596,7 +633,7 @@ void string_move(char *dst, char *src) * 1 : string = string to be duplicated * 2 : len = number of bytes to duplicate * - * Returns : pointer to copy, or NULL if failiure + * Returns : pointer to copy, or NULL if failure * *********************************************************************/ char *bindup(const char *string, size_t len) @@ -663,8 +700,7 @@ char * make_path(const char * dir, const char * file) * Relative path, so start with the base directory. */ path_size += strlen(basedir) + 1; /* +1 for the slash */ - path = malloc(path_size); - if (!path) log_error(LOG_LEVEL_FATAL, "malloc failed!"); + path = malloc_or_die(path_size); strlcpy(path, basedir, path_size); strlcat(path, "/", path_size); strlcat(path, dir, path_size); @@ -672,8 +708,7 @@ char * make_path(const char * dir, const char * file) else #endif /* defined unix */ { - path = malloc(path_size); - if (!path) log_error(LOG_LEVEL_FATAL, "malloc failed!"); + path = malloc_or_die(path_size); strlcpy(path, dir, path_size); } @@ -965,6 +1000,49 @@ time_t timegm(struct tm *tm) #endif /* !defined(HAVE_TIMEGM) && defined(HAVE_TZSET) && defined(HAVE_PUTENV) */ +/********************************************************************* + * + * Function : host_is_ip_address + * + * Description : Checks whether or not a host is specified by + * IP address. Does not actually validate the + * address. + * + * Parameters : + * 1 : host = The host name to check + * + * Returns : 1 => Yes + * 0 => No + * + *********************************************************************/ +extern int host_is_ip_address(const char *host) +{ + const char *p; + + if (NULL != strstr(host, ":")) + { + /* Assume an IPv6 address. */ + return 1; + } + + for (p = host; *p; p++) + { + if ((*p != '.') && !privoxy_isdigit(*p)) + { + /* Not a dot or digit so it can't be an IPv4 address. */ + return 0; + } + } + + /* + * Host only consists of dots and digits so + * assume that is an IPv4 address. + */ + return 1; + +} + + /* Local Variables: tab-width: 3