From f2f45339dc378ed4d15b19ebf8d16e9f58d776e8 Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Thu, 17 Sep 2009 14:23:27 +0000 Subject: Moved Curl_rand() and Curl_srand() code from formdata.c and formdata.h into curl_rand.c and curl_rand.h --- lib/Makefile.Watcom | 13 ++++++-- lib/Makefile.inc | 4 +-- lib/Makefile.riscos | 5 ++- lib/Makefile.vc6 | 1 + lib/curl_rand.c | 62 ++++++++++++++++++++++++++++++++++++++ lib/curl_rand.h | 30 ++++++++++++++++++ lib/easy.c | 2 +- lib/formdata.c | 28 +---------------- lib/formdata.h | 13 +++----- lib/makefile.amiga | 2 +- packages/Symbian/group/libcurl.mmp | 3 +- packages/TPF/curl.mak | 1 + 12 files changed, 119 insertions(+), 45 deletions(-) create mode 100644 lib/curl_rand.c create mode 100644 lib/curl_rand.h diff --git a/lib/Makefile.Watcom b/lib/Makefile.Watcom index 1572c33ca..610ae640b 100644 --- a/lib/Makefile.Watcom +++ b/lib/Makefile.Watcom @@ -69,7 +69,8 @@ OBJS = $(OBJ_DIR)\base64.obj $(OBJ_DIR)\connect.obj & $(OBJ_DIR)\telnet.obj $(OBJ_DIR)\tftp.obj & $(OBJ_DIR)\timeval.obj $(OBJ_DIR)\transfer.obj & $(OBJ_DIR)\url.obj $(OBJ_DIR)\version.obj & - $(OBJ_DIR)\slist.obj $(OBJ_DIR)\nonblock.obj + $(OBJ_DIR)\slist.obj $(OBJ_DIR)\nonblock.obj & + $(OBJ_DIR)\curl_rand.obj # # Use $(OBJS) as a template to generate $(OBJS_STAT) and $(OBJS_DYN). @@ -185,7 +186,7 @@ $(OBJ_DIR)\formdata.obj: formdata.c setup.h config-win32.h ..\include\curl\curlb ..\include\curl\easy.h ..\include\curl\multi.h ..\include\curl\curl.h & urldata.h cookie.h formdata.h timeval.h http_chunks.h hostip.h hash.h & llist.h curl_addrinfo.h splay.h easyif.h strequal.h curl_memory.h & - ..\include\curl\mprintf.h memdebug.h + curl_rand.h ..\include\curl\mprintf.h memdebug.h $(OBJ_DIR)\cookie.obj: cookie.c setup.h config-win32.h ..\include\curl\curlbuild.h & ..\include\curl\curlrules.h setup_once.h ..\include\curl\mprintf.h & ..\include\curl\curl.h ..\include\curl\curlver.h & @@ -331,7 +332,7 @@ $(OBJ_DIR)\easy.obj: easy.c setup.h config-win32.h ..\include\curl\curlbuild.h & formdata.h timeval.h http_chunks.h hostip.h hash.h llist.h & curl_addrinfo.h splay.h transfer.h sslgen.h url.h getinfo.h share.h & strdup.h curl_memory.h progress.h easyif.h select.h sendf.h http_ntlm.h & - connect.h ..\include\curl\mprintf.h memdebug.h + curl_rand.h connect.h ..\include\curl\mprintf.h memdebug.h $(OBJ_DIR)\security.obj: security.c setup.h config-win32.h ..\include\curl\curlbuild.h & ..\include\curl\curlrules.h setup_once.h $(OBJ_DIR)\krb4.obj: krb4.c setup.h config-win32.h ..\include\curl\curlbuild.h & @@ -541,3 +542,9 @@ $(OBJ_DIR)\curl_addrinfo.obj: curl_addrinfo.c setup.h config-win32.h & ..\include\curl\curlrules.h ..\include\curl\easy.h & ..\include\curl\multi.h ..\include\curl\curl.h curl_addrinfo.h & ..\include\curl\mprintf.h curl_memory.h memdebug.h +$(OBJ_DIR)\curl_rand.obj: curl_rand.c setup.h config-win32.h & + ..\include\curl\curlbuild.h ..\include\curl\curlrules.h setup_once.h & + ..\include\curl\curl.h ..\include\curl\curlver.h & + ..\include\curl\curlrules.h ..\include\curl\easy.h & + ..\include\curl\multi.h ..\include\curl\curl.h curl_rand.h & + ..\include\curl\mprintf.h curl_memory.h memdebug.h diff --git a/lib/Makefile.inc b/lib/Makefile.inc index 99a6a723c..34961229c 100644 --- a/lib/Makefile.inc +++ b/lib/Makefile.inc @@ -5,7 +5,7 @@ CSOURCES = file.c timeval.c base64.c hostip.c progress.c formdata.c \ ldap.c ssluse.c version.c getenv.c escape.c mprintf.c telnet.c \ netrc.c getinfo.c transfer.c strequal.c easy.c security.c krb4.c \ krb5.c memdebug.c http_chunks.c strtok.c connect.c llist.c hash.c \ - multi.c content_encoding.c share.c http_digest.c md5.c \ + multi.c content_encoding.c share.c http_digest.c md5.c curl_rand.c \ http_negotiate.c http_ntlm.c inet_pton.c strtoofft.c strerror.c \ hostares.c hostasyn.c hostip4.c hostip6.c hostsyn.c hostthre.c \ inet_ntop.c parsedate.c select.c gtls.c sslgen.c tftp.c splay.c \ @@ -15,7 +15,7 @@ CSOURCES = file.c timeval.c base64.c hostip.c progress.c formdata.c \ HHEADERS = arpa_telnet.h netrc.h file.h timeval.h qssl.h hostip.h \ progress.h formdata.h cookie.h http.h sendf.h ftp.h url.h dict.h \ if2ip.h speedcheck.h urldata.h curl_ldap.h ssluse.h escape.h telnet.h \ - getinfo.h strequal.h krb4.h memdebug.h http_chunks.h \ + getinfo.h strequal.h krb4.h memdebug.h http_chunks.h curl_rand.h \ strtok.h connect.h llist.h hash.h content_encoding.h share.h \ curl_md5.h http_digest.h http_negotiate.h http_ntlm.h inet_pton.h \ strtoofft.h strerror.h inet_ntop.h curlx.h curl_memory.h setup.h \ diff --git a/lib/Makefile.riscos b/lib/Makefile.riscos index e34c97e67..d192f6fa5 100644 --- a/lib/Makefile.riscos +++ b/lib/Makefile.riscos @@ -13,7 +13,7 @@ objs = o.base64 o.connect o.cookie o.dict \ o.security o.select o.sendf o.speedcheck o.ssluse \ o.strequal o.strtok o.telnet o.timeval \ o.transfer o.url o.version o.strtoofft o.sslgen o.gtls \ - o.rawstr o.curl_addrinfo o.slist o.nonblock + o.rawstr o.curl_addrinfo o.slist o.nonblock o.curl_rand # Compile options: linkopts = -o libcurl @@ -36,6 +36,9 @@ o.cookie: c.cookie o.curl_addrinfo: c.curl_addrinfo gcc $(compileropts) -c -o curl_addrinfo.o c.curl_addrinfo +o.curl_rand: c.curl_rand + gcc $(compileropts) -c -o curl_rand.o c.curl_rand + o.dict: c.dict gcc $(compileropts) -c -o dict.o c.dict diff --git a/lib/Makefile.vc6 b/lib/Makefile.vc6 index 09fd14a9c..8ad31981d 100644 --- a/lib/Makefile.vc6 +++ b/lib/Makefile.vc6 @@ -450,6 +450,7 @@ X_OBJS= \ $(DIROBJ)\content_encoding.obj \ $(DIROBJ)\cookie.obj \ $(DIROBJ)\curl_addrinfo.obj \ + $(DIROBJ)\curl_rand.obj \ $(DIROBJ)\curl_sspi.obj \ $(DIROBJ)\dict.obj \ $(DIROBJ)\easy.obj \ diff --git a/lib/curl_rand.c b/lib/curl_rand.c new file mode 100644 index 000000000..7719e0f08 --- /dev/null +++ b/lib/curl_rand.c @@ -0,0 +1,62 @@ +/*************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * Copyright (C) 1998 - 2009, Daniel Stenberg, , 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. + * + * $Id$ + ***************************************************************************/ + +#include "setup.h" + +#include + +#include "curl_rand.h" + +#define _MPRINTF_REPLACE /* use our functions only */ +#include + +#include "curl_memory.h" +/* The last #include file should be: */ +#include "memdebug.h" + +/* Private pseudo-random number seed. Unsigned integer >= 32bit. Threads + mutual exclusion is not implemented to acess it since we do not require + high quality random numbers (only used in form boudary generation). */ + +static unsigned int randseed; + +/* Pseudo-random number support. */ + +unsigned int Curl_rand(void) +{ + unsigned int r; + /* Return an unsigned 32-bit pseudo-random number. */ + r = randseed = randseed * 1103515245 + 12345; + return (r << 16) | ((r >> 16) & 0xFFFF); +} + +void Curl_srand(void) +{ + /* Randomize pseudo-random number sequence. */ + + randseed = (unsigned int) time(NULL); + Curl_rand(); + Curl_rand(); + Curl_rand(); +} + diff --git a/lib/curl_rand.h b/lib/curl_rand.h new file mode 100644 index 000000000..f61ef06b0 --- /dev/null +++ b/lib/curl_rand.h @@ -0,0 +1,30 @@ +#ifndef HEADER_CURL_RAND_H +#define HEADER_CURL_RAND_H +/*************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * Copyright (C) 1998 - 2009, Daniel Stenberg, , 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. + * + * $Id$ + ***************************************************************************/ + +void Curl_srand(void); + +unsigned int Curl_rand(void); + +#endif /* HEADER_CURL_RAND_H */ diff --git a/lib/easy.c b/lib/easy.c index 10b1bd3ee..ff808f9a5 100644 --- a/lib/easy.c +++ b/lib/easy.c @@ -85,7 +85,7 @@ #include "http_ntlm.h" #include "connect.h" /* for Curl_getconnectinfo */ #include "slist.h" -#include "formdata.h" /* For Curl_srand(). */ +#include "curl_rand.h" #define _MPRINTF_REPLACE /* use our functions only */ #include diff --git a/lib/formdata.c b/lib/formdata.c index 8538e9f91..ab5f99118 100644 --- a/lib/formdata.c +++ b/lib/formdata.c @@ -108,12 +108,6 @@ Content-Disposition: form-data; name="FILECONTENT" /* Length of the random boundary string. */ #define BOUNDARY_LENGTH 40 -/* Private pseudo-random number seed. Unsigned integer >= 32bit. Threads - mutual exclusion is not implemented to acess it since we do not require - high quality random numbers (only used in form boudary generation). */ - -static unsigned int randseed; - #if !defined(CURL_DISABLE_HTTP) || defined(USE_SSLEAY) #include @@ -127,6 +121,7 @@ static unsigned int randseed; #include "urldata.h" /* for struct SessionHandle */ #include "easyif.h" /* for Curl_convert_... prototypes */ #include "formdata.h" +#include "curl_rand.h" #include "strequal.h" #include "curl_memory.h" @@ -1763,24 +1758,3 @@ char *Curl_FormBoundary(void) } #endif /* !defined(CURL_DISABLE_HTTP) || defined(USE_SSLEAY) */ - -/* Pseudo-random number support. This is always enabled, since called from - curl_global_init(). */ - -unsigned int Curl_rand(void) -{ - unsigned int r; - /* Return an unsigned 32-bit pseudo-random number. */ - r = randseed = randseed * 1103515245 + 12345; - return (r << 16) | ((r >> 16) & 0xFFFF); -} - -void Curl_srand(void) -{ - /* Randomize pseudo-random number sequence. */ - - randseed = (unsigned int) time(NULL); - Curl_rand(); - Curl_rand(); - Curl_rand(); -} diff --git a/lib/formdata.h b/lib/formdata.h index 0d9400a15..1ca0eef8b 100644 --- a/lib/formdata.h +++ b/lib/formdata.h @@ -1,6 +1,5 @@ -#ifndef __FORMDATA_H -#define __FORMDATA_H - +#ifndef HEADER_CURL_FORMDATA_H +#define HEADER_CURL_FORMDATA_H /*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | @@ -8,7 +7,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2008, Daniel Stenberg, , et al. + * Copyright (C) 1998 - 2009, Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms @@ -97,8 +96,4 @@ void Curl_formclean(struct FormData **); CURLcode Curl_formconvert(struct SessionHandle *, struct FormData *); -void Curl_srand(void); -unsigned int Curl_rand(void); - -#endif - +#endif /* HEADER_CURL_FORMDATA_H */ diff --git a/lib/makefile.amiga b/lib/makefile.amiga index d88707672..a86736846 100644 --- a/lib/makefile.amiga +++ b/lib/makefile.amiga @@ -17,7 +17,7 @@ OBJS = amigaos.c base64.c connect.c content_encoding.c cookie.c dict.c easy.c \ ldap.c llist.c md5.c memdebug.c mprintf.c multi.c netrc.c parsedate.c \ progress.c security.c select.c sendf.c share.c speedcheck.c ssluse.c \ strequal.c strtok.c telnet.c timeval.c transfer.c url.c version.c \ - sslgen.c gtls.c strerror.c rawstr.c curl_addrinfo.c \ + sslgen.c gtls.c strerror.c rawstr.c curl_addrinfo.c curl_rand.c \ socks_gssapi.c socks_sspi.c curl_sspi.c slist.c nonblock.c all: $(OBJS:.c=.o) diff --git a/packages/Symbian/group/libcurl.mmp b/packages/Symbian/group/libcurl.mmp index e4995bad1..32420acfb 100644 --- a/packages/Symbian/group/libcurl.mmp +++ b/packages/Symbian/group/libcurl.mmp @@ -31,7 +31,8 @@ SOURCE \ hostares.c hostasyn.c hostip4.c hostip6.c hostsyn.c hostthre.c \ inet_ntop.c parsedate.c select.c gtls.c sslgen.c tftp.c splay.c \ strdup.c socks.c ssh.c nss.c qssl.c rawstr.c curl_addrinfo.c \ - socks_gssapi.c socks_sspi.c curl_sspi.c slist.c nonblock.c + socks_gssapi.c socks_sspi.c curl_sspi.c slist.c nonblock.c \ + curl_rand.c USERINCLUDE ../../../lib ../../../include/curl #ifdef ENABLE_SSL diff --git a/packages/TPF/curl.mak b/packages/TPF/curl.mak index 7a45c2bb5..cd2d25666 100644 --- a/packages/TPF/curl.mak +++ b/packages/TPF/curl.mak @@ -35,6 +35,7 @@ C_SRC += connect.c C_SRC += content_encoding.c C_SRC += cookie.c C_SRC += curl_addrinfo.c +C_SRC += curl_rand.c C_SRC += curl_sspi.c C_SRC += dict.c C_SRC += easy.c -- cgit v1.2.3