Moved Curl_rand() and Curl_srand() code from formdata.c and formdata.h

into curl_rand.c and curl_rand.h
This commit is contained in:
Yang Tse 2009-09-17 14:23:27 +00:00
parent be5c815f63
commit f2f45339dc
12 changed files with 119 additions and 45 deletions

View File

@ -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

View File

@ -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 \

View File

@ -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

View File

@ -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 \

62
lib/curl_rand.c Normal file
View File

@ -0,0 +1,62 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 1998 - 2009, 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.
*
* $Id$
***************************************************************************/
#include "setup.h"
#include <curl/curl.h>
#include "curl_rand.h"
#define _MPRINTF_REPLACE /* use our functions only */
#include <curl/mprintf.h>
#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();
}

30
lib/curl_rand.h Normal file
View File

@ -0,0 +1,30 @@
#ifndef HEADER_CURL_RAND_H
#define HEADER_CURL_RAND_H
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 1998 - 2009, 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.
*
* $Id$
***************************************************************************/
void Curl_srand(void);
unsigned int Curl_rand(void);
#endif /* HEADER_CURL_RAND_H */

View File

@ -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 <curl/mprintf.h>

View File

@ -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 <stdio.h>
@ -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();
}

View File

@ -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, <daniel@haxx.se>, et al.
* Copyright (C) 1998 - 2009, 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
@ -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 */

View File

@ -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)

View File

@ -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

View File

@ -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