Internal symbols that aren't static are now prefixed with 'Curl_'

This commit is contained in:
Daniel Stenberg 2001-01-05 10:11:41 +00:00
parent 9f9cac7402
commit 4031104404
53 changed files with 670 additions and 593 deletions

View File

@ -6,6 +6,11 @@
History of Changes History of Changes
Daniel (5 January 2001)
- The krb4 support was broken in the release. Fixed now.
- Huge internal symbol rename operation.
Version 7.5.2 Version 7.5.2
Daniel (4 January 2001) Daniel (4 January 2001)

View File

@ -12,6 +12,13 @@ INTERNALS
Thus, the largest amount of code and complexity is in the library part. Thus, the largest amount of code and complexity is in the library part.
SYMBOLS
=======
All symbols used internally must use a 'Curl_' prefix if they're used in
more than a single file. Single file symbols must be made static. Public
symbols must use a 'curl_' prefix. (There are exceptions, but they are
destined to change to this pattern in the future.)
CVS CVS
=== ===

View File

@ -435,8 +435,10 @@ typedef enum {
NOTE: they return TRUE if the strings match *case insensitively*. NOTE: they return TRUE if the strings match *case insensitively*.
*/ */
extern int (strequal)(const char *s1, const char *s2); extern int (Curl_strequal)(const char *s1, const char *s2);
extern int (strnequal)(const char *s1, const char *s2, size_t n); extern int (Curl_strnequal)(const char *s1, const char *s2, size_t n);
#define strequal(a,b) Curl_strequal(a,b)
#define strnequal(a,b,c) Curl_strnequal(a,b,c)
/* external form function */ /* external form function */
int curl_formparse(char *string, int curl_formparse(char *string,

View File

@ -55,26 +55,28 @@
#include <stdarg.h> #include <stdarg.h>
int mprintf(const char *format, ...); int Curl_mprintf(const char *format, ...);
int mfprintf(FILE *fd, const char *format, ...); int Curl_mfprintf(FILE *fd, const char *format, ...);
int msprintf(char *buffer, const char *format, ...); int Curl_msprintf(char *buffer, const char *format, ...);
int msnprintf(char *buffer, size_t maxlength, const char *format, ...); int Curl_msnprintf(char *buffer, size_t maxlength, const char *format, ...);
int mvprintf(const char *format, va_list args); int Curl_mvprintf(const char *format, va_list args);
int mvfprintf(FILE *fd, const char *format, va_list args); int Curl_mvfprintf(FILE *fd, const char *format, va_list args);
int mvsprintf(char *buffer, const char *format, va_list args); int Curl_mvsprintf(char *buffer, const char *format, va_list args);
int mvsnprintf(char *buffer, size_t maxlength, const char *format, va_list args); int Curl_mvsnprintf(char *buffer, size_t maxlength, const char *format, va_list args);
char *maprintf(const char *format, ...); char *Curl_maprintf(const char *format, ...);
char *mvaprintf(const char *format, va_list args); char *Curl_mvaprintf(const char *format, va_list args);
#ifdef _MPRINTF_REPLACE #ifdef _MPRINTF_REPLACE
# define printf mprintf # define printf Curl_mprintf
# define fprintf mfprintf # define fprintf Curl_mfprintf
# define sprintf msprintf # define sprintf Curl_msprintf
# define snprintf msnprintf # define snprintf Curl_msnprintf
# define vprintf mvprintf # define vprintf Curl_mvprintf
# define vfprintf mvfprintf # define vfprintf Curl_mvfprintf
# define vsprintf mvsprintf # define vsprintf Curl_mvsprintf
# define vsnprintf mvsnprintf # define vsnprintf Curl_mvsnprintf
# define aprintf Curl_maprintf
# define vaprintf Curl_mvaprintf
#endif #endif
#endif /* H_MPRINTF */ #endif /* H_MPRINTF */

View File

@ -63,6 +63,7 @@
#define SYNCH 242 /* for telfunc calls */ #define SYNCH 242 /* for telfunc calls */
#ifdef TELCMDS #ifdef TELCMDS
static
char *telcmds[] = { char *telcmds[] = {
"EOF", "SUSP", "ABORT", "EOR", "EOF", "SUSP", "ABORT", "EOR",
"SE", "NOP", "DMARK", "BRK", "IP", "AO", "AYT", "EC", "SE", "NOP", "DMARK", "BRK", "IP", "AO", "AYT", "EC",
@ -124,6 +125,7 @@ extern char *telcmds[];
#define NTELOPTS (1+TELOPT_NEW_ENVIRON) #define NTELOPTS (1+TELOPT_NEW_ENVIRON)
#ifdef TELOPTS #ifdef TELOPTS
static
char *telopts[NTELOPTS+1] = { char *telopts[NTELOPTS+1] = {
"BINARY", "ECHO", "RCP", "SUPPRESS GO AHEAD", "NAME", "BINARY", "ECHO", "RCP", "SUPPRESS GO AHEAD", "NAME",
"STATUS", "TIMING MARK", "RCTE", "NAOL", "NAOP", "STATUS", "TIMING MARK", "RCTE", "NAOL", "NAOP",

View File

@ -55,7 +55,7 @@ static int pos(char c)
} }
#if 1 #if 1
int base64_encode(const void *data, int size, char **str) int Curl_base64_encode(const void *data, int size, char **str)
{ {
char *s, *p; char *s, *p;
int i; int i;
@ -93,7 +93,7 @@ int base64_encode(const void *data, int size, char **str)
} }
#endif #endif
int base64_decode(const char *str, void *data) int Curl_base64_decode(const char *str, void *data)
{ {
const char *p; const char *p;
unsigned char *q; unsigned char *q;

View File

@ -34,6 +34,7 @@
#ifndef __BASE64_H #ifndef __BASE64_H
#define __BASE64_H #define __BASE64_H
int base64_encode(const void *data, int size, char **str); int Curl_base64_encode(const void *data, int size, char **str);
int Curl_base64_decode(const char *str, void *data);
#endif #endif

View File

@ -100,9 +100,10 @@ Example set of cookies:
* *
***************************************************************************/ ***************************************************************************/
struct Cookie *cookie_add(struct CookieInfo *c, struct Cookie *
bool httpheader, /* TRUE if HTTP header-style line */ Curl_cookie_add(struct CookieInfo *c,
char *lineptr) /* first non-space of the line */ bool httpheader, /* TRUE if HTTP header-style line */
char *lineptr) /* first non-space of the line */
{ {
struct Cookie *clist; struct Cookie *clist;
char what[MAX_COOKIE_LINE]; char what[MAX_COOKIE_LINE];
@ -347,7 +348,7 @@ struct Cookie *cookie_add(struct CookieInfo *c,
* called before any cookies are set. File may be NULL. * called before any cookies are set. File may be NULL.
* *
****************************************************************************/ ****************************************************************************/
struct CookieInfo *cookie_init(char *file) struct CookieInfo *Curl_cookie_init(char *file)
{ {
char line[MAX_COOKIE_LINE]; char line[MAX_COOKIE_LINE];
struct CookieInfo *c; struct CookieInfo *c;
@ -375,7 +376,7 @@ struct CookieInfo *cookie_init(char *file)
while(*lineptr && isspace((int)*lineptr)) while(*lineptr && isspace((int)*lineptr))
lineptr++; lineptr++;
cookie_add(c, TRUE, lineptr); Curl_cookie_add(c, TRUE, lineptr);
} }
else { else {
/* This might be a netscape cookie-file line, get it! */ /* This might be a netscape cookie-file line, get it! */
@ -383,7 +384,7 @@ struct CookieInfo *cookie_init(char *file)
while(*lineptr && isspace((int)*lineptr)) while(*lineptr && isspace((int)*lineptr))
lineptr++; lineptr++;
cookie_add(c, FALSE, lineptr); Curl_cookie_add(c, FALSE, lineptr);
} }
} }
if(fromfile) if(fromfile)
@ -405,8 +406,8 @@ struct CookieInfo *cookie_init(char *file)
* *
****************************************************************************/ ****************************************************************************/
struct Cookie *cookie_getlist(struct CookieInfo *c, struct Cookie *Curl_cookie_getlist(struct CookieInfo *c,
char *host, char *path, bool secure) char *host, char *path, bool secure)
{ {
struct Cookie *newco; struct Cookie *newco;
struct Cookie *co; struct Cookie *co;
@ -473,7 +474,7 @@ struct Cookie *cookie_getlist(struct CookieInfo *c,
* *
****************************************************************************/ ****************************************************************************/
void cookie_freelist(struct Cookie *co) void Curl_cookie_freelist(struct Cookie *co)
{ {
struct Cookie *next; struct Cookie *next;
if(co) { if(co) {
@ -493,7 +494,7 @@ void cookie_freelist(struct Cookie *co)
* Free a "cookie object" previous created with cookie_init(). * Free a "cookie object" previous created with cookie_init().
* *
****************************************************************************/ ****************************************************************************/
void cookie_cleanup(struct CookieInfo *c) void Curl_cookie_cleanup(struct CookieInfo *c)
{ {
struct Cookie *co; struct Cookie *co;
struct Cookie *next; struct Cookie *next;

View File

@ -63,10 +63,10 @@ struct CookieInfo {
#define MAX_NAME 256 #define MAX_NAME 256
#define MAX_NAME_TXT "255" #define MAX_NAME_TXT "255"
struct Cookie *cookie_add(struct CookieInfo *, bool, char *); struct Cookie *Curl_cookie_add(struct CookieInfo *, bool, char *);
struct CookieInfo *cookie_init(char *); struct CookieInfo *Curl_cookie_init(char *);
struct Cookie *cookie_getlist(struct CookieInfo *, char *, char *, bool); struct Cookie *Curl_cookie_getlist(struct CookieInfo *, char *, char *, bool);
void cookie_freelist(struct Cookie *); void Curl_cookie_freelist(struct Cookie *);
void cookie_cleanup(struct CookieInfo *); void Curl_cookie_cleanup(struct CookieInfo *);
#endif #endif

View File

@ -80,12 +80,12 @@
#define _MPRINTF_REPLACE /* use our functions only */ #define _MPRINTF_REPLACE /* use our functions only */
#include <curl/mprintf.h> #include <curl/mprintf.h>
CURLcode dict_done(struct connectdata *conn) CURLcode Curl_dict_done(struct connectdata *conn)
{ {
return CURLE_OK; return CURLE_OK;
} }
CURLcode dict(struct connectdata *conn) CURLcode Curl_dict(struct connectdata *conn)
{ {
int nth; int nth;
char *word; char *word;

View File

@ -23,7 +23,7 @@
* *
* $Id$ * $Id$
*****************************************************************************/ *****************************************************************************/
CURLcode dict(struct connectdata *conn); CURLcode Curl_dict(struct connectdata *conn);
CURLcode dict_done(struct connectdata *conn); CURLcode Curl_dict_done(struct connectdata *conn);
#endif #endif

View File

@ -58,7 +58,6 @@
#endif #endif
#include "progress.h" #include "progress.h"
#include "speedcheck.h"
#include "sendf.h" #include "sendf.h"
#include <curl/types.h> #include <curl/types.h>
@ -69,7 +68,7 @@
<butlerm@xmission.com>. */ <butlerm@xmission.com>. */
CURLcode CURLcode
Transfer(CURLconnect *c_conn, Curl_Transfer(CURLconnect *c_conn,
/* READ stuff */ /* READ stuff */
int sockfd, /* socket to read from or -1 */ int sockfd, /* socket to read from or -1 */
int size, /* -1 if unknown at this point */ int size, /* -1 if unknown at this point */

View File

@ -23,14 +23,18 @@
* $Id$ * $Id$
*****************************************************************************/ *****************************************************************************/
CURLcode CURLcode
Transfer (struct connectdata *data, Curl_Transfer (struct connectdata *data,
int sockfd, /* socket to read from or -1 */ int sockfd, /* socket to read from or -1 */
int size, /* -1 if unknown at this point */ int size, /* -1 if unknown at this point */
bool getheader, /* TRUE if header parsing is wanted */ bool getheader, /* TRUE if header parsing is wanted */
long *bytecountp, /* return number of bytes read */ long *bytecountp, /* return number of bytes read */
int writesockfd, /* socket to write to, it may very well be int writesockfd, /* socket to write to, it may very well be
the same we read from. -1 disables */ the same we read from. -1 disables */
long *writebytecountp /* return number of bytes written */ long *writebytecountp /* return number of bytes written */
); );
/* "hackish" define to make sources compile without too much human editing.
Don't use "Tranfer()" anymore! */
#define Transfer(a,b,c,d,e,f,g) Curl_Transfer(a,b,c,d,e,f,g)
#endif #endif

View File

@ -106,7 +106,7 @@ CURLcode file(struct connectdata *conn)
struct UrlData *data = conn->data; struct UrlData *data = conn->data;
char *buf = data->buffer; char *buf = data->buffer;
int bytecount = 0; int bytecount = 0;
struct timeval start = tvnow(); struct timeval start = Curl_tvnow();
struct timeval now = start; struct timeval now = start;
int fd; int fd;
char *actual_path = curl_unescape(path, 0); char *actual_path = curl_unescape(path, 0);
@ -139,7 +139,7 @@ CURLcode file(struct connectdata *conn)
it avoids problems with select() and recv() on file descriptors it avoids problems with select() and recv() on file descriptors
in Winsock */ in Winsock */
if(expected_size != -1) if(expected_size != -1)
pgrsSetDownloadSize(data, expected_size); Curl_pgrsSetDownloadSize(data, expected_size);
while (res == CURLE_OK) { while (res == CURLE_OK) {
nread = read(fd, buf, BUFSIZE-1); nread = read(fd, buf, BUFSIZE-1);
@ -155,16 +155,16 @@ CURLcode file(struct connectdata *conn)
to prevent CR/LF translation (this then goes to a binary mode to prevent CR/LF translation (this then goes to a binary mode
file descriptor). */ file descriptor). */
res = client_write(data, CLIENTWRITE_BODY, buf, nread); res = Curl_client_write(data, CLIENTWRITE_BODY, buf, nread);
if(res) if(res)
return res; return res;
now = tvnow(); now = Curl_tvnow();
if(pgrsUpdate(data)) if(Curl_pgrsUpdate(data))
res = CURLE_ABORTED_BY_CALLBACK; res = CURLE_ABORTED_BY_CALLBACK;
} }
now = tvnow(); now = Curl_tvnow();
if(pgrsUpdate(data)) if(Curl_pgrsUpdate(data))
res = CURLE_ABORTED_BY_CALLBACK; res = CURLE_ABORTED_BY_CALLBACK;
close(fd); close(fd);

View File

@ -91,16 +91,10 @@ static void GetStr(char **string,
* *
***************************************************************************/ ***************************************************************************/
int curl_formparse(char *input,
struct HttpPost **httppost,
struct HttpPost **last_post)
{
return FormParse(input, httppost, last_post);
}
#define FORM_FILE_SEPARATOR ',' #define FORM_FILE_SEPARATOR ','
#define FORM_TYPE_SEPARATOR ';' #define FORM_TYPE_SEPARATOR ';'
static
int FormParse(char *input, int FormParse(char *input,
struct HttpPost **httppost, struct HttpPost **httppost,
struct HttpPost **last_post) struct HttpPost **last_post)
@ -298,6 +292,13 @@ int FormParse(char *input,
return 0; return 0;
} }
int curl_formparse(char *input,
struct HttpPost **httppost,
struct HttpPost **last_post)
{
return FormParse(input, httppost, last_post);
}
static int AddFormData(struct FormData **formp, static int AddFormData(struct FormData **formp,
void *line, void *line,
long length) long length)
@ -339,7 +340,7 @@ static int AddFormDataf(struct FormData **formp,
} }
char *MakeFormBoundary(void) char *Curl_FormBoundary(void)
{ {
char *retstring; char *retstring;
static int randomizer=0; /* this is just so that two boundaries within static int randomizer=0; /* this is just so that two boundaries within
@ -367,7 +368,7 @@ char *MakeFormBoundary(void)
} }
/* Used from http.c */ /* Used from http.c */
void FormFree(struct FormData *form) void Curl_FormFree(struct FormData *form)
{ {
struct FormData *next; struct FormData *next;
do { do {
@ -400,8 +401,8 @@ void curl_formfree(struct HttpPost *form)
} while((form=next)); /* continue */ } while((form=next)); /* continue */
} }
struct FormData *getFormData(struct HttpPost *post, struct FormData *Curl_getFormData(struct HttpPost *post,
int *sizep) int *sizep)
{ {
struct FormData *form = NULL; struct FormData *form = NULL;
struct FormData *firstform; struct FormData *firstform;
@ -415,7 +416,7 @@ struct FormData *getFormData(struct HttpPost *post,
if(!post) if(!post)
return NULL; /* no input => no output! */ return NULL; /* no input => no output! */
boundary = MakeFormBoundary(); boundary = Curl_FormBoundary();
/* Make the first line of the output */ /* Make the first line of the output */
AddFormDataf(&form, AddFormDataf(&form,
@ -439,7 +440,7 @@ struct FormData *getFormData(struct HttpPost *post,
/* If used, this is a link to more file names, we must then do /* If used, this is a link to more file names, we must then do
the magic to include several files with the same field name */ the magic to include several files with the same field name */
fileboundary = MakeFormBoundary(); fileboundary = Curl_FormBoundary();
size += AddFormDataf(&form, size += AddFormDataf(&form,
"\r\nContent-Type: multipart/mixed," "\r\nContent-Type: multipart/mixed,"
@ -535,24 +536,11 @@ struct FormData *getFormData(struct HttpPost *post,
return firstform; return firstform;
} }
int FormInit(struct Form *form, struct FormData *formdata ) int Curl_FormInit(struct Form *form, struct FormData *formdata )
{ {
if(!formdata) if(!formdata)
return 1; /* error */ return 1; /* error */
#if 0
struct FormData *lastnode=formdata;
/* find the last node in the list */
while(lastnode->next) {
lastnode = lastnode->next;
}
/* Now, make sure that we'll send a nice terminating sequence at the end
* of the post. We *DONT* add this string to the size of the data since this
* is actually AFTER the data. */
AddFormDataf(&lastnode, "\r\n\r\n");
#endif
form->data = formdata; form->data = formdata;
form->sent = 0; form->sent = 0;
@ -560,10 +548,10 @@ int FormInit(struct Form *form, struct FormData *formdata )
} }
/* fread() emulation */ /* fread() emulation */
int FormReader(char *buffer, int Curl_FormReader(char *buffer,
size_t size, size_t size,
size_t nitems, size_t nitems,
FILE *mydata) FILE *mydata)
{ {
struct Form *form; struct Form *form;
int wantedsize; int wantedsize;
@ -638,7 +626,7 @@ int main(int argc, char **argv)
} }
} }
form=getFormData(httppost, &size); form=Curl_getFormData(httppost, &size);
FormInit(&formread, form); FormInit(&formread, form);

View File

@ -36,23 +36,19 @@ struct Form {
been sent in a previous invoke */ been sent in a previous invoke */
}; };
int FormParse(char *string, int Curl_FormInit(struct Form *form, struct FormData *formdata );
struct HttpPost **httppost,
struct HttpPost **last_post);
int FormInit(struct Form *form, struct FormData *formdata ); struct FormData *Curl_getFormData(struct HttpPost *post,
int *size);
struct FormData *getFormData(struct HttpPost *post,
int *size);
/* fread() emulation */ /* fread() emulation */
int FormReader(char *buffer, int Curl_FormReader(char *buffer,
size_t size, size_t size,
size_t nitems, size_t nitems,
FILE *mydata); FILE *mydata);
char *MakeFormBoundary(void); char *Curl_FormBoundary(void);
void FormFree(struct FormData *); void Curl_FormFree(struct FormData *);
#endif #endif

134
lib/ftp.c
View File

@ -69,15 +69,21 @@
#include "download.h" #include "download.h"
#include "escape.h" #include "escape.h"
#include "http.h" /* for HTTP proxy tunnel stuff */ #include "http.h" /* for HTTP proxy tunnel stuff */
#include "ftp.h"
#ifdef KRB4 #ifdef KRB4
#include "security.h" #include "security.h"
#include "krb4.h"
#endif #endif
/* The last #include file should be: */ /* The last #include file should be: */
#ifdef MALLOCDEBUG #ifdef MALLOCDEBUG
#include "memdebug.h" #include "memdebug.h"
#endif #endif
/* easy-to-use macro: */
#define ftpsendf Curl_ftpsendf
/* returns last node in linked list */ /* returns last node in linked list */
static struct curl_slist *slist_get_last(struct curl_slist *list) static struct curl_slist *slist_get_last(struct curl_slist *list)
{ {
@ -202,9 +208,13 @@ static CURLcode AllowServerConnect(struct UrlData *data,
#define lastline(line) (isdigit((int)line[0]) && isdigit((int)line[1]) && \ #define lastline(line) (isdigit((int)line[0]) && isdigit((int)line[1]) && \
isdigit((int)line[2]) && (' ' == line[3])) isdigit((int)line[2]) && (' ' == line[3]))
int GetLastResponse(int sockfd, char *buf, /*
struct connectdata *conn, * We allow the ftpcode pointer to be NULL if no reply integer is wanted
int *ftpcode) */
int Curl_GetFTPResponse(int sockfd, char *buf,
struct connectdata *conn,
int *ftpcode)
{ {
int nread; int nread;
int keepon=TRUE; int keepon=TRUE;
@ -220,12 +230,13 @@ int GetLastResponse(int sockfd, char *buf,
#define SELECT_TIMEOUT 2 #define SELECT_TIMEOUT 2
int error = SELECT_OK; int error = SELECT_OK;
*ftpcode=0; /* 0 for errors */ if(ftpcode)
*ftpcode=0; /* 0 for errors */
if(data->timeout) { if(data->timeout) {
/* if timeout is requested, find out how much remaining time we have */ /* if timeout is requested, find out how much remaining time we have */
timeout = data->timeout - /* timeout time */ timeout = data->timeout - /* timeout time */
(tvlong(tvnow()) - tvlong(conn->now)); /* spent time */ (Curl_tvlong(Curl_tvnow()) - Curl_tvlong(conn->now)); /* spent time */
if(timeout <=0 ) { if(timeout <=0 ) {
failf(data, "Transfer aborted due to timeout"); failf(data, "Transfer aborted due to timeout");
return -SELECT_TIMEOUT; /* already too little time */ return -SELECT_TIMEOUT; /* already too little time */
@ -306,13 +317,14 @@ int GetLastResponse(int sockfd, char *buf,
if(error) if(error)
return -error; return -error;
*ftpcode=atoi(buf); /* return the initial number like this */ if(ftpcode)
*ftpcode=atoi(buf); /* return the initial number like this */
return nread; return nread;
} }
/* -- who are we? -- */ /* -- who are we? -- */
char *getmyhost(char *buf, int buf_size) char *Curl_getmyhost(char *buf, int buf_size)
{ {
#if defined(HAVE_GETHOSTNAME) #if defined(HAVE_GETHOSTNAME)
gethostname(buf, buf_size); gethostname(buf, buf_size);
@ -330,7 +342,7 @@ char *getmyhost(char *buf, int buf_size)
/* ftp_connect() should do everything that is to be considered a part /* ftp_connect() should do everything that is to be considered a part
of the connection phase. */ of the connection phase. */
CURLcode ftp_connect(struct connectdata *conn) CURLcode Curl_ftp_connect(struct connectdata *conn)
{ {
/* this is FTP and no proxy */ /* this is FTP and no proxy */
int nread; int nread;
@ -356,14 +368,14 @@ CURLcode ftp_connect(struct connectdata *conn)
if (data->bits.tunnel_thru_httpproxy) { if (data->bits.tunnel_thru_httpproxy) {
/* We want "seamless" FTP operations through HTTP proxy tunnel */ /* We want "seamless" FTP operations through HTTP proxy tunnel */
result = GetHTTPProxyTunnel(data, data->firstsocket, result = Curl_ConnectHTTPProxyTunnel(data, data->firstsocket,
data->hostname, data->remote_port); data->hostname, data->remote_port);
if(CURLE_OK != result) if(CURLE_OK != result)
return result; return result;
} }
/* The first thing we do is wait for the "220*" line: */ /* The first thing we do is wait for the "220*" line: */
nread = GetLastResponse(data->firstsocket, buf, conn, &ftpcode); nread = Curl_GetFTPResponse(data->firstsocket, buf, conn, &ftpcode);
if(nread < 0) if(nread < 0)
return CURLE_OPERATION_TIMEOUTED; return CURLE_OPERATION_TIMEOUTED;
@ -396,7 +408,7 @@ CURLcode ftp_connect(struct connectdata *conn)
ftpsendf(data->firstsocket, conn, "USER %s", ftp->user); ftpsendf(data->firstsocket, conn, "USER %s", ftp->user);
/* wait for feedback */ /* wait for feedback */
nread = GetLastResponse(data->firstsocket, buf, conn, &ftpcode); nread = Curl_GetFTPResponse(data->firstsocket, buf, conn, &ftpcode);
if(nread < 0) if(nread < 0)
return CURLE_OPERATION_TIMEOUTED; return CURLE_OPERATION_TIMEOUTED;
@ -410,7 +422,7 @@ CURLcode ftp_connect(struct connectdata *conn)
/* 331 Password required for ... /* 331 Password required for ...
(the server requires to send the user's password too) */ (the server requires to send the user's password too) */
ftpsendf(data->firstsocket, conn, "PASS %s", ftp->passwd); ftpsendf(data->firstsocket, conn, "PASS %s", ftp->passwd);
nread = GetLastResponse(data->firstsocket, buf, conn, &ftpcode); nread = Curl_GetFTPResponse(data->firstsocket, buf, conn, &ftpcode);
if(nread < 0) if(nread < 0)
return CURLE_OPERATION_TIMEOUTED; return CURLE_OPERATION_TIMEOUTED;
@ -459,7 +471,7 @@ CURLcode ftp_connect(struct connectdata *conn)
/* argument is already checked for validity */ /* argument is already checked for validity */
CURLcode ftp_done(struct connectdata *conn) CURLcode Curl_ftp_done(struct connectdata *conn)
{ {
struct UrlData *data = conn->data; struct UrlData *data = conn->data;
struct FTP *ftp = data->proto.ftp; struct FTP *ftp = data->proto.ftp;
@ -496,7 +508,7 @@ CURLcode ftp_done(struct connectdata *conn)
if(!data->bits.no_body) { if(!data->bits.no_body) {
/* now let's see what the server says about the transfer we /* now let's see what the server says about the transfer we
just performed: */ just performed: */
nread = GetLastResponse(data->firstsocket, buf, conn, &ftpcode); nread = Curl_GetFTPResponse(data->firstsocket, buf, conn, &ftpcode);
if(nread < 0) if(nread < 0)
return CURLE_OPERATION_TIMEOUTED; return CURLE_OPERATION_TIMEOUTED;
@ -516,7 +528,7 @@ CURLcode ftp_done(struct connectdata *conn)
if (qitem->data) { if (qitem->data) {
ftpsendf(data->firstsocket, conn, "%s", qitem->data); ftpsendf(data->firstsocket, conn, "%s", qitem->data);
nread = GetLastResponse(data->firstsocket, buf, conn, &ftpcode); nread = Curl_GetFTPResponse(data->firstsocket, buf, conn, &ftpcode);
if(nread < 0) if(nread < 0)
return CURLE_OPERATION_TIMEOUTED; return CURLE_OPERATION_TIMEOUTED;
@ -570,7 +582,7 @@ CURLcode _ftp(struct connectdata *conn)
if (qitem->data) { if (qitem->data) {
ftpsendf(data->firstsocket, conn, "%s", qitem->data); ftpsendf(data->firstsocket, conn, "%s", qitem->data);
nread = GetLastResponse(data->firstsocket, buf, conn, &ftpcode); nread = Curl_GetFTPResponse(data->firstsocket, buf, conn, &ftpcode);
if(nread < 0) if(nread < 0)
return CURLE_OPERATION_TIMEOUTED; return CURLE_OPERATION_TIMEOUTED;
@ -587,7 +599,7 @@ CURLcode _ftp(struct connectdata *conn)
/* change directory first! */ /* change directory first! */
if(ftp->dir && ftp->dir[0]) { if(ftp->dir && ftp->dir[0]) {
ftpsendf(data->firstsocket, conn, "CWD %s", ftp->dir); ftpsendf(data->firstsocket, conn, "CWD %s", ftp->dir);
nread = GetLastResponse(data->firstsocket, buf, conn, &ftpcode); nread = Curl_GetFTPResponse(data->firstsocket, buf, conn, &ftpcode);
if(nread < 0) if(nread < 0)
return CURLE_OPERATION_TIMEOUTED; return CURLE_OPERATION_TIMEOUTED;
@ -602,7 +614,7 @@ CURLcode _ftp(struct connectdata *conn)
again a grey area as the MDTM is not kosher RFC959 */ again a grey area as the MDTM is not kosher RFC959 */
ftpsendf(data->firstsocket, conn, "MDTM %s", ftp->file); ftpsendf(data->firstsocket, conn, "MDTM %s", ftp->file);
nread = GetLastResponse(data->firstsocket, buf, conn, &ftpcode); nread = Curl_GetFTPResponse(data->firstsocket, buf, conn, &ftpcode);
if(nread < 0) if(nread < 0)
return CURLE_OPERATION_TIMEOUTED; return CURLE_OPERATION_TIMEOUTED;
@ -639,7 +651,7 @@ CURLcode _ftp(struct connectdata *conn)
ftpsendf(data->firstsocket, conn, "TYPE %s", ftpsendf(data->firstsocket, conn, "TYPE %s",
(data->bits.ftp_ascii)?"A":"I"); (data->bits.ftp_ascii)?"A":"I");
nread = GetLastResponse(data->firstsocket, buf, conn, &ftpcode); nread = Curl_GetFTPResponse(data->firstsocket, buf, conn, &ftpcode);
if(nread < 0) if(nread < 0)
return CURLE_OPERATION_TIMEOUTED; return CURLE_OPERATION_TIMEOUTED;
@ -652,7 +664,7 @@ CURLcode _ftp(struct connectdata *conn)
ftpsendf(data->firstsocket, conn, "SIZE %s", ftp->file); ftpsendf(data->firstsocket, conn, "SIZE %s", ftp->file);
nread = GetLastResponse(data->firstsocket, buf, conn, &ftpcode); nread = Curl_GetFTPResponse(data->firstsocket, buf, conn, &ftpcode);
if(nread < 0) if(nread < 0)
return CURLE_OPERATION_TIMEOUTED; return CURLE_OPERATION_TIMEOUTED;
@ -664,7 +676,7 @@ CURLcode _ftp(struct connectdata *conn)
filesize = atoi(buf+4); filesize = atoi(buf+4);
sprintf(buf, "Content-Length: %d\r\n", filesize); sprintf(buf, "Content-Length: %d\r\n", filesize);
result = client_write(data, CLIENTWRITE_BOTH, buf, 0); result = Curl_client_write(data, CLIENTWRITE_BOTH, buf, 0);
if(result) if(result)
return result; return result;
@ -680,7 +692,7 @@ CURLcode _ftp(struct connectdata *conn)
/* format: "Tue, 15 Nov 1994 12:45:26 GMT" */ /* format: "Tue, 15 Nov 1994 12:45:26 GMT" */
strftime(buf, BUFSIZE-1, "Last-Modified: %a, %d %b %Y %H:%M:%S %Z\r\n", strftime(buf, BUFSIZE-1, "Last-Modified: %a, %d %b %Y %H:%M:%S %Z\r\n",
tm); tm);
result = client_write(data, CLIENTWRITE_BOTH, buf, 0); result = Curl_client_write(data, CLIENTWRITE_BOTH, buf, 0);
if(result) if(result)
return result; return result;
} }
@ -699,18 +711,20 @@ CURLcode _ftp(struct connectdata *conn)
char myhost[256] = ""; char myhost[256] = "";
if(data->ftpport) { if(data->ftpport) {
if(if2ip(data->ftpport, myhost, sizeof(myhost))) { if(Curl_if2ip(data->ftpport, myhost, sizeof(myhost))) {
h = GetHost(data, myhost, &hostdataptr); h = Curl_gethost(data, myhost, &hostdataptr);
} }
else { else {
if(strlen(data->ftpport)>1) if(strlen(data->ftpport)>1)
h = GetHost(data, data->ftpport, &hostdataptr); h = Curl_gethost(data, data->ftpport, &hostdataptr);
if(h) if(h)
strcpy(myhost, data->ftpport); /* buffer overflow risk */ strcpy(myhost, data->ftpport); /* buffer overflow risk */
} }
} }
if(! *myhost) { if(! *myhost) {
h=GetHost(data, getmyhost(myhost, sizeof(myhost)), &hostdataptr); h=Curl_gethost(data,
Curl_getmyhost(myhost, sizeof(myhost)),
&hostdataptr);
} }
infof(data, "We connect from %s\n", myhost); infof(data, "We connect from %s\n", myhost);
@ -788,7 +802,7 @@ CURLcode _ftp(struct connectdata *conn)
porttouse & 255); porttouse & 255);
} }
nread = GetLastResponse(data->firstsocket, buf, conn, &ftpcode); nread = Curl_GetFTPResponse(data->firstsocket, buf, conn, &ftpcode);
if(nread < 0) if(nread < 0)
return CURLE_OPERATION_TIMEOUTED; return CURLE_OPERATION_TIMEOUTED;
@ -801,7 +815,7 @@ CURLcode _ftp(struct connectdata *conn)
ftpsendf(data->firstsocket, conn, "PASV"); ftpsendf(data->firstsocket, conn, "PASV");
nread = GetLastResponse(data->firstsocket, buf, conn, &ftpcode); nread = Curl_GetFTPResponse(data->firstsocket, buf, conn, &ftpcode);
if(nread < 0) if(nread < 0)
return CURLE_OPERATION_TIMEOUTED; return CURLE_OPERATION_TIMEOUTED;
@ -856,7 +870,7 @@ CURLcode _ftp(struct connectdata *conn)
} }
else { else {
/* normal, direct, ftp connection */ /* normal, direct, ftp connection */
he = GetHost(data, newhost, &hostdataptr); he = Curl_gethost(data, newhost, &hostdataptr);
if(!he) { if(!he) {
failf(data, "Can't resolve new host %s", newhost); failf(data, "Can't resolve new host %s", newhost);
return CURLE_FTP_CANT_GET_HOST; return CURLE_FTP_CANT_GET_HOST;
@ -961,8 +975,8 @@ CURLcode _ftp(struct connectdata *conn)
if (data->bits.tunnel_thru_httpproxy) { if (data->bits.tunnel_thru_httpproxy) {
/* We want "seamless" FTP operations through HTTP proxy tunnel */ /* We want "seamless" FTP operations through HTTP proxy tunnel */
result = GetHTTPProxyTunnel(data, data->secondarysocket, result = Curl_ConnectHTTPProxyTunnel(data, data->secondarysocket,
newhost, newport); newhost, newport);
if(CURLE_OK != result) if(CURLE_OK != result)
return result; return result;
} }
@ -977,7 +991,7 @@ CURLcode _ftp(struct connectdata *conn)
ftpsendf(data->firstsocket, conn, "TYPE %s", ftpsendf(data->firstsocket, conn, "TYPE %s",
(data->bits.ftp_ascii)?"A":"I"); (data->bits.ftp_ascii)?"A":"I");
nread = GetLastResponse(data->firstsocket, buf, conn, &ftpcode); nread = Curl_GetFTPResponse(data->firstsocket, buf, conn, &ftpcode);
if(nread < 0) if(nread < 0)
return CURLE_OPERATION_TIMEOUTED; return CURLE_OPERATION_TIMEOUTED;
@ -1008,7 +1022,7 @@ CURLcode _ftp(struct connectdata *conn)
ftpsendf(data->firstsocket, conn, "SIZE %s", ftp->file); ftpsendf(data->firstsocket, conn, "SIZE %s", ftp->file);
nread = GetLastResponse(data->firstsocket, buf, conn, &ftpcode); nread = Curl_GetFTPResponse(data->firstsocket, buf, conn, &ftpcode);
if(nread < 0) if(nread < 0)
return CURLE_OPERATION_TIMEOUTED; return CURLE_OPERATION_TIMEOUTED;
@ -1069,7 +1083,7 @@ CURLcode _ftp(struct connectdata *conn)
else else
ftpsendf(data->firstsocket, conn, "STOR %s", ftp->file); ftpsendf(data->firstsocket, conn, "STOR %s", ftp->file);
nread = GetLastResponse(data->firstsocket, buf, conn, &ftpcode); nread = Curl_GetFTPResponse(data->firstsocket, buf, conn, &ftpcode);
if(nread < 0) if(nread < 0)
return CURLE_OPERATION_TIMEOUTED; return CURLE_OPERATION_TIMEOUTED;
@ -1090,7 +1104,7 @@ CURLcode _ftp(struct connectdata *conn)
/* When we know we're uploading a specified file, we can get the file /* When we know we're uploading a specified file, we can get the file
size prior to the actual upload. */ size prior to the actual upload. */
pgrsSetUploadSize(data, data->infilesize); Curl_pgrsSetUploadSize(data, data->infilesize);
result = Transfer(conn, -1, -1, FALSE, NULL, /* no download */ result = Transfer(conn, -1, -1, FALSE, NULL, /* no download */
data->secondarysocket, bytecountp); data->secondarysocket, bytecountp);
@ -1149,7 +1163,7 @@ CURLcode _ftp(struct connectdata *conn)
/* Set type to ASCII */ /* Set type to ASCII */
ftpsendf(data->firstsocket, conn, "TYPE A"); ftpsendf(data->firstsocket, conn, "TYPE A");
nread = GetLastResponse(data->firstsocket, buf, conn, &ftpcode); nread = Curl_GetFTPResponse(data->firstsocket, buf, conn, &ftpcode);
if(nread < 0) if(nread < 0)
return CURLE_OPERATION_TIMEOUTED; return CURLE_OPERATION_TIMEOUTED;
@ -1171,7 +1185,7 @@ CURLcode _ftp(struct connectdata *conn)
ftpsendf(data->firstsocket, conn, "TYPE %s", ftpsendf(data->firstsocket, conn, "TYPE %s",
(data->bits.ftp_ascii)?"A":"I"); (data->bits.ftp_ascii)?"A":"I");
nread = GetLastResponse(data->firstsocket, buf, conn, &ftpcode); nread = Curl_GetFTPResponse(data->firstsocket, buf, conn, &ftpcode);
if(nread < 0) if(nread < 0)
return CURLE_OPERATION_TIMEOUTED; return CURLE_OPERATION_TIMEOUTED;
@ -1192,7 +1206,7 @@ CURLcode _ftp(struct connectdata *conn)
ftpsendf(data->firstsocket, conn, "SIZE %s", ftp->file); ftpsendf(data->firstsocket, conn, "SIZE %s", ftp->file);
nread = GetLastResponse(data->firstsocket, buf, conn, &ftpcode); nread = Curl_GetFTPResponse(data->firstsocket, buf, conn, &ftpcode);
if(nread < 0) if(nread < 0)
return CURLE_OPERATION_TIMEOUTED; return CURLE_OPERATION_TIMEOUTED;
@ -1236,7 +1250,7 @@ CURLcode _ftp(struct connectdata *conn)
ftpsendf(data->firstsocket, conn, "REST %d", data->resume_from); ftpsendf(data->firstsocket, conn, "REST %d", data->resume_from);
nread = GetLastResponse(data->firstsocket, buf, conn, &ftpcode); nread = Curl_GetFTPResponse(data->firstsocket, buf, conn, &ftpcode);
if(nread < 0) if(nread < 0)
return CURLE_OPERATION_TIMEOUTED; return CURLE_OPERATION_TIMEOUTED;
@ -1249,7 +1263,7 @@ CURLcode _ftp(struct connectdata *conn)
ftpsendf(data->firstsocket, conn, "RETR %s", ftp->file); ftpsendf(data->firstsocket, conn, "RETR %s", ftp->file);
} }
nread = GetLastResponse(data->firstsocket, buf, conn, &ftpcode); nread = Curl_GetFTPResponse(data->firstsocket, buf, conn, &ftpcode);
if(nread < 0) if(nread < 0)
return CURLE_OPERATION_TIMEOUTED; return CURLE_OPERATION_TIMEOUTED;
@ -1341,7 +1355,7 @@ CURLcode _ftp(struct connectdata *conn)
/* -- deal with the ftp server! -- */ /* -- deal with the ftp server! -- */
/* argument is already checked for validity */ /* argument is already checked for validity */
CURLcode ftp(struct connectdata *conn) CURLcode Curl_ftp(struct connectdata *conn)
{ {
CURLcode retcode; CURLcode retcode;
@ -1403,3 +1417,39 @@ CURLcode ftp(struct connectdata *conn)
return retcode; return retcode;
} }
/*
* ftpsendf() sends the formated string as a ftp command to a ftp server
*
* NOTE: we build the command in a fixed-length buffer, which sets length
* restrictions on the command!
*
*/
size_t Curl_ftpsendf(int fd, struct connectdata *conn, char *fmt, ...)
{
size_t bytes_written;
char s[256];
va_list ap;
va_start(ap, fmt);
vsnprintf(s, 250, fmt, ap);
va_end(ap);
if(conn->data->bits.verbose)
fprintf(conn->data->err, "> %s\n", s);
strcat(s, "\r\n"); /* append a trailing CRLF */
#ifdef KRB4
if(conn->sec_complete && conn->data->cmdchannel) {
bytes_written = sec_fprintf(conn, conn->data->cmdchannel, s);
fflush(conn->data->cmdchannel);
}
else
#endif /* KRB4 */
{
bytes_written = swrite(fd, s, strlen(s));
}
return(bytes_written);
}

View File

@ -23,11 +23,18 @@
* *
* $Id$ * $Id$
*****************************************************************************/ *****************************************************************************/
CURLcode ftp(struct connectdata *conn); CURLcode Curl_ftp(struct connectdata *conn);
CURLcode ftp_done(struct connectdata *conn); CURLcode Curl_ftp_done(struct connectdata *conn);
CURLcode ftp_connect(struct connectdata *conn); CURLcode Curl_ftp_connect(struct connectdata *conn);
size_t Curl_ftpsendf(int fd, struct connectdata *, char *fmt, ...);
struct curl_slist *curl_slist_append(struct curl_slist *list, char *data); struct curl_slist *curl_slist_append(struct curl_slist *list, char *data);
void curl_slist_free_all(struct curl_slist *list); void curl_slist_free_all(struct curl_slist *list);
/* The kerberos stuff needs this: */
int Curl_GetFTPResponse(int sockfd, char *buf,
struct connectdata *conn,
int *ftpcode);
#endif #endif

View File

@ -33,6 +33,7 @@
#include "memdebug.h" #include "memdebug.h"
#endif #endif
static
char *GetEnv(char *variable) char *GetEnv(char *variable)
{ {
#ifdef WIN32 #ifdef WIN32

View File

@ -23,7 +23,6 @@
* $Id$ * $Id$
*****************************************************************************/ *****************************************************************************/
/* Unix and Win32 getenv function call */ #include <curl/curl.h>
char *GetEnv(char *variable);
#endif #endif

View File

@ -103,14 +103,14 @@
#define min(a, b) ((a) < (b) ? (a) : (b)) #define min(a, b) ((a) < (b) ? (a) : (b))
#endif #endif
CURLcode CURLcode static
_Transfer(struct connectdata *c_conn) _Transfer(struct connectdata *c_conn)
{ {
size_t nread; /* number of bytes read */ size_t nread; /* number of bytes read */
int bytecount = 0; /* total number of bytes read */ int bytecount = 0; /* total number of bytes read */
int writebytecount = 0; /* number of bytes written */ int writebytecount = 0; /* number of bytes written */
long contentlength=0; /* size of incoming data */ long contentlength=0; /* size of incoming data */
struct timeval start = tvnow(); struct timeval start = Curl_tvnow();
struct timeval now = start; /* current time */ struct timeval now = start; /* current time */
bool header = TRUE; /* incoming data has HTTP header */ bool header = TRUE; /* incoming data has HTTP header */
int headerline = 0; /* counts header lines to better track the int headerline = 0; /* counts header lines to better track the
@ -151,19 +151,19 @@ _Transfer(struct connectdata *c_conn)
myalarm (0); /* switch off the alarm-style timeout */ myalarm (0); /* switch off the alarm-style timeout */
now = tvnow(); now = Curl_tvnow();
start = now; start = now;
#define KEEP_READ 1 #define KEEP_READ 1
#define KEEP_WRITE 2 #define KEEP_WRITE 2
pgrsTime(data, TIMER_PRETRANSFER); Curl_pgrsTime(data, TIMER_PRETRANSFER);
speedinit(data); Curl_speedinit(data);
if (!conn->getheader) { if (!conn->getheader) {
header = FALSE; header = FALSE;
if(conn->size > 0) if(conn->size > 0)
pgrsSetDownloadSize(data, conn->size); Curl_pgrsSetDownloadSize(data, conn->size);
} }
/* we want header and/or body, if neither then don't do this! */ /* we want header and/or body, if neither then don't do this! */
if(conn->getheader || if(conn->getheader ||
@ -314,7 +314,7 @@ _Transfer(struct connectdata *c_conn)
if ('\n' == *p) if ('\n' == *p)
p++; /* pass the \n byte */ p++; /* pass the \n byte */
pgrsSetDownloadSize(data, conn->size); Curl_pgrsSetDownloadSize(data, conn->size);
header = FALSE; /* no more header to parse! */ header = FALSE; /* no more header to parse! */
@ -324,8 +324,8 @@ _Transfer(struct connectdata *c_conn)
if (data->bits.http_include_header) if (data->bits.http_include_header)
writetype |= CLIENTWRITE_BODY; writetype |= CLIENTWRITE_BODY;
urg = client_write(data, writetype, data->headerbuff, urg = Curl_client_write(data, writetype, data->headerbuff,
p - data->headerbuff); p - data->headerbuff);
if(urg) if(urg)
return urg; return urg;
@ -374,7 +374,7 @@ _Transfer(struct connectdata *c_conn)
} }
else if(data->cookies && else if(data->cookies &&
strnequal("Set-Cookie: ", p, 11)) { strnequal("Set-Cookie: ", p, 11)) {
cookie_add(data->cookies, TRUE, &p[12]); Curl_cookie_add(data->cookies, TRUE, &p[12]);
} }
else if(strnequal("Last-Modified:", p, else if(strnequal("Last-Modified:", p,
strlen("Last-Modified:")) && strlen("Last-Modified:")) &&
@ -398,7 +398,7 @@ _Transfer(struct connectdata *c_conn)
if (data->bits.http_include_header) if (data->bits.http_include_header)
writetype |= CLIENTWRITE_BODY; writetype |= CLIENTWRITE_BODY;
urg = client_write(data, writetype, p, hbuflen); urg = Curl_client_write(data, writetype, p, hbuflen);
if(urg) if(urg)
return urg; return urg;
@ -484,9 +484,9 @@ _Transfer(struct connectdata *c_conn)
bytecount += nread; bytecount += nread;
pgrsSetDownloadCounter(data, (double)bytecount); Curl_pgrsSetDownloadCounter(data, (double)bytecount);
urg = client_write(data, CLIENTWRITE_BODY, str, nread); urg = Curl_client_write(data, CLIENTWRITE_BODY, str, nread);
if(urg) if(urg)
return urg; return urg;
@ -513,7 +513,7 @@ _Transfer(struct connectdata *c_conn)
break; break;
} }
writebytecount += nread; writebytecount += nread;
pgrsSetUploadCounter(data, (double)writebytecount); Curl_pgrsSetUploadCounter(data, (double)writebytecount);
/* convert LF to CRLF if so asked */ /* convert LF to CRLF if so asked */
if (data->crlf) { if (data->crlf) {
@ -543,11 +543,11 @@ _Transfer(struct connectdata *c_conn)
break; break;
} }
now = tvnow(); now = Curl_tvnow();
if(pgrsUpdate(data)) if(Curl_pgrsUpdate(data))
urg = CURLE_ABORTED_BY_CALLBACK; urg = CURLE_ABORTED_BY_CALLBACK;
else else
urg = speedcheck (data, now); urg = Curl_speedcheck (data, now);
if (urg) if (urg)
return urg; return urg;
@ -560,7 +560,7 @@ _Transfer(struct connectdata *c_conn)
conn->upload_bufsize=(long)min(data->progress.ulspeed, BUFSIZE); conn->upload_bufsize=(long)min(data->progress.ulspeed, BUFSIZE);
} }
if (data->timeout && (tvdiff (now, start) > data->timeout)) { if (data->timeout && (Curl_tvdiff (now, start) > data->timeout)) {
failf (data, "Operation timed out with %d out of %d bytes received", failf (data, "Operation timed out with %d out of %d bytes received",
bytecount, conn->size); bytecount, conn->size);
return CURLE_OPERATION_TIMEOUTED; return CURLE_OPERATION_TIMEOUTED;
@ -573,7 +573,7 @@ _Transfer(struct connectdata *c_conn)
contentlength-bytecount); contentlength-bytecount);
return CURLE_PARTIAL_FILE; return CURLE_PARTIAL_FILE;
} }
if(pgrsUpdate(data)) if(Curl_pgrsUpdate(data))
return CURLE_ABORTED_BY_CALLBACK; return CURLE_ABORTED_BY_CALLBACK;
if(conn->bytecountp) if(conn->bytecountp)
@ -592,10 +592,10 @@ CURLcode curl_transfer(CURL *curl)
struct UrlData *data = curl; struct UrlData *data = curl;
struct connectdata *c_connect=NULL; struct connectdata *c_connect=NULL;
pgrsStartNow(data); Curl_pgrsStartNow(data);
do { do {
pgrsTime(data, TIMER_STARTSINGLE); Curl_pgrsTime(data, TIMER_STARTSINGLE);
res = curl_connect(curl, (CURLconnect **)&c_connect); res = curl_connect(curl, (CURLconnect **)&c_connect);
if(res == CURLE_OK) { if(res == CURLE_OK) {
res = curl_do(c_connect); res = curl_do(c_connect);

View File

@ -62,7 +62,7 @@
/* --- resolve name or IP-number --- */ /* --- resolve name or IP-number --- */
char *MakeIP(unsigned long num,char *addr, int addr_len) static char *MakeIP(unsigned long num,char *addr, int addr_len)
{ {
#if defined(HAVE_INET_NTOA) || defined(HAVE_INET_NTOA_R) #if defined(HAVE_INET_NTOA) || defined(HAVE_INET_NTOA_R)
struct in_addr in; struct in_addr in;
@ -83,14 +83,17 @@ char *MakeIP(unsigned long num,char *addr, int addr_len)
return (addr); return (addr);
} }
/* The original code to this function was stolen from the Dancer source code, /* The original code to this function was once stolen from the Dancer source
written by Bjorn Reese, it has since been patched and modified. */ code, written by Bjorn Reese, it has since been patched and modified
considerably. */
#ifndef INADDR_NONE #ifndef INADDR_NONE
#define INADDR_NONE (unsigned long) ~0 #define INADDR_NONE (unsigned long) ~0
#endif #endif
struct hostent *GetHost(struct UrlData *data,
char *hostname, struct hostent *Curl_gethost(struct UrlData *data,
char **bufp) char *hostname,
char **bufp)
{ {
struct hostent *h = NULL; struct hostent *h = NULL;
unsigned long in; unsigned long in;

View File

@ -23,6 +23,8 @@
* $Id$ * $Id$
*****************************************************************************/ *****************************************************************************/
struct hostent *GetHost(struct UrlData *data, char *hostname, char **bufp ); struct hostent *Curl_gethost(struct UrlData *data,
char *hostname,
char **bufp);
#endif #endif

View File

@ -105,6 +105,150 @@
#include "memdebug.h" #include "memdebug.h"
#endif #endif
/*
* The add_buffer series of functions are used to build one large memory chunk
* from repeated function invokes. Used so that the entire HTTP request can
* be sent in one go.
*/
static CURLcode
add_buffer(send_buffer *in, void *inptr, size_t size);
/*
* add_buffer_init() returns a fine buffer struct
*/
static
send_buffer *add_buffer_init(void)
{
send_buffer *blonk;
blonk=(send_buffer *)malloc(sizeof(send_buffer));
if(blonk) {
memset(blonk, 0, sizeof(send_buffer));
return blonk;
}
return NULL; /* failed, go home */
}
/*
* add_buffer_send() sends a buffer and frees all associated memory.
*/
static
size_t add_buffer_send(int sockfd, struct connectdata *conn, send_buffer *in)
{
size_t amount;
if(conn->data->bits.verbose) {
fputs("> ", conn->data->err);
/* this data _may_ contain binary stuff */
fwrite(in->buffer, in->size_used, 1, conn->data->err);
}
amount = ssend(sockfd, conn, in->buffer, in->size_used);
if(in->buffer)
free(in->buffer);
free(in);
return amount;
}
/*
* add_bufferf() builds a buffer from the formatted input
*/
static
CURLcode add_bufferf(send_buffer *in, char *fmt, ...)
{
CURLcode result = CURLE_OUT_OF_MEMORY;
char *s;
va_list ap;
va_start(ap, fmt);
s = Curl_mvaprintf(fmt, ap); /* this allocs a new string to append */
va_end(ap);
if(s) {
result = add_buffer(in, s, strlen(s));
free(s);
}
return result;
}
/*
* add_buffer() appends a memory chunk to the existing one
*/
static
CURLcode add_buffer(send_buffer *in, void *inptr, size_t size)
{
char *new_rb;
int new_size;
if(size > 0) {
if(!in->buffer ||
((in->size_used + size) > (in->size_max - 1))) {
new_size = (in->size_used+size)*2;
if(in->buffer)
/* we have a buffer, enlarge the existing one */
new_rb = (char *)realloc(in->buffer, new_size);
else
/* create a new buffer */
new_rb = (char *)malloc(new_size);
if(!new_rb)
return CURLE_OUT_OF_MEMORY;
in->buffer = new_rb;
in->size_max = new_size;
}
memcpy(&in->buffer[in->size_used], inptr, size);
in->size_used += size;
}
return CURLE_OK;
}
/* end of the add_buffer functions */
/*****************************************************************************/
/*
* Read everything until a newline.
*/
static
int GetLine(int sockfd, char *buf, struct UrlData *data)
{
int nread;
int read_rc=1;
char *ptr;
ptr=buf;
/* get us a full line, terminated with a newline */
for(nread=0;
(nread<BUFSIZE) && read_rc;
nread++, ptr++) {
#ifdef USE_SSLEAY
if (data->ssl.use) {
read_rc = SSL_read(data->ssl.handle, ptr, 1);
}
else {
#endif
read_rc = sread(sockfd, ptr, 1);
#ifdef USE_SSLEAY
}
#endif /* USE_SSLEAY */
if (*ptr == '\n')
break;
}
*ptr=0; /* zero terminate */
if(data->bits.verbose) {
fputs("< ", data->err);
fwrite(buf, 1, nread, data->err);
fputs("\n", data->err);
}
return nread;
}
/* /*
* This function checks the linked list of custom HTTP headers for a particular * This function checks the linked list of custom HTTP headers for a particular
* header (prefix). * header (prefix).
@ -123,13 +267,13 @@ bool static checkheaders(struct UrlData *data, char *thisheader)
} }
/* /*
* GetHTTPProxyTunnel() requires that we're connected to a HTTP proxy. This * ConnectHTTPProxyTunnel() requires that we're connected to a HTTP proxy. This
* function will issue the necessary commands to get a seamless tunnel through * function will issue the necessary commands to get a seamless tunnel through
* this proxy. After that, the socket can be used just as a normal socket. * this proxy. After that, the socket can be used just as a normal socket.
*/ */
CURLcode GetHTTPProxyTunnel(struct UrlData *data, int tunnelsocket, CURLcode Curl_ConnectHTTPProxyTunnel(struct UrlData *data, int tunnelsocket,
char *hostname, int remote_port) char *hostname, int remote_port)
{ {
int httperror=0; int httperror=0;
int subversion=0; int subversion=0;
@ -170,7 +314,7 @@ CURLcode GetHTTPProxyTunnel(struct UrlData *data, int tunnelsocket,
return CURLE_OK; return CURLE_OK;
} }
CURLcode http_connect(struct connectdata *conn) CURLcode Curl_http_connect(struct connectdata *conn)
{ {
struct UrlData *data; struct UrlData *data;
CURLcode result; CURLcode result;
@ -186,16 +330,15 @@ CURLcode http_connect(struct connectdata *conn)
if (conn->protocol & PROT_HTTPS) { if (conn->protocol & PROT_HTTPS) {
if (data->bits.httpproxy) { if (data->bits.httpproxy) {
/* HTTPS through a proxy can only be done with a tunnel */ /* HTTPS through a proxy can only be done with a tunnel */
result = GetHTTPProxyTunnel(data, data->firstsocket, result = Curl_ConnectHTTPProxyTunnel(data, data->firstsocket,
data->hostname, data->remote_port); data->hostname, data->remote_port);
if(CURLE_OK != result) if(CURLE_OK != result)
return result; return result;
} }
/* now, perform the SSL initialization for this socket */ /* now, perform the SSL initialization for this socket */
if(UrgSSLConnect (data)) { if(Curl_SSLConnect(data))
return CURLE_SSL_CONNECT_ERROR; return CURLE_SSL_CONNECT_ERROR;
}
} }
if(data->bits.user_passwd && !data->bits.this_is_a_follow) { if(data->bits.user_passwd && !data->bits.this_is_a_follow) {
@ -209,14 +352,14 @@ CURLcode http_connect(struct connectdata *conn)
/* called from curl_close() when this struct is about to get wasted, free /* called from curl_close() when this struct is about to get wasted, free
protocol-specific resources */ protocol-specific resources */
CURLcode http_close(struct connectdata *conn) CURLcode Curl_http_close(struct connectdata *conn)
{ {
if(conn->data->auth_host) if(conn->data->auth_host)
free(conn->data->auth_host); free(conn->data->auth_host);
return CURLE_OK; return CURLE_OK;
} }
CURLcode http_done(struct connectdata *conn) CURLcode Curl_http_done(struct connectdata *conn)
{ {
struct UrlData *data; struct UrlData *data;
long *bytecount = &conn->bytecount; long *bytecount = &conn->bytecount;
@ -228,7 +371,7 @@ CURLcode http_done(struct connectdata *conn)
if(data->bits.http_formpost) { if(data->bits.http_formpost) {
*bytecount = http->readbytecount + http->writebytecount; *bytecount = http->readbytecount + http->writebytecount;
FormFree(http->sendit); /* Now free that whole lot */ Curl_FormFree(http->sendit); /* Now free that whole lot */
data->fread = http->storefread; /* restore */ data->fread = http->storefread; /* restore */
data->in = http->in; /* restore */ data->in = http->in; /* restore */
@ -244,7 +387,7 @@ CURLcode http_done(struct connectdata *conn)
} }
CURLcode http(struct connectdata *conn) CURLcode Curl_http(struct connectdata *conn)
{ {
struct UrlData *data=conn->data; struct UrlData *data=conn->data;
char *buf = data->buffer; /* this is a short cut to the buffer */ char *buf = data->buffer; /* this is a short cut to the buffer */
@ -284,29 +427,29 @@ CURLcode http(struct connectdata *conn)
!data->auth_host || !data->auth_host ||
strequal(data->auth_host, data->hostname)) { strequal(data->auth_host, data->hostname)) {
sprintf(data->buffer, "%s:%s", data->user, data->passwd); sprintf(data->buffer, "%s:%s", data->user, data->passwd);
if(base64_encode(data->buffer, strlen(data->buffer), if(Curl_base64_encode(data->buffer, strlen(data->buffer),
&authorization) >= 0) { &authorization) >= 0) {
data->ptr_userpwd = maprintf( "Authorization: Basic %s\015\012", data->ptr_userpwd = aprintf( "Authorization: Basic %s\015\012",
authorization); authorization);
free(authorization); free(authorization);
} }
} }
} }
if((data->bits.set_range) && !checkheaders(data, "Range:")) { if((data->bits.set_range) && !checkheaders(data, "Range:")) {
data->ptr_rangeline = maprintf("Range: bytes=%s\015\012", data->range); data->ptr_rangeline = aprintf("Range: bytes=%s\015\012", data->range);
} }
if((data->bits.http_set_referer) && !checkheaders(data, "Referer:")) { if((data->bits.http_set_referer) && !checkheaders(data, "Referer:")) {
data->ptr_ref = maprintf("Referer: %s\015\012", data->referer); data->ptr_ref = aprintf("Referer: %s\015\012", data->referer);
} }
if(data->cookie && !checkheaders(data, "Cookie:")) { if(data->cookie && !checkheaders(data, "Cookie:")) {
data->ptr_cookie = maprintf("Cookie: %s\015\012", data->cookie); data->ptr_cookie = aprintf("Cookie: %s\015\012", data->cookie);
} }
if(data->cookies) { if(data->cookies) {
co = cookie_getlist(data->cookies, co = Curl_cookie_getlist(data->cookies,
host, host,
ppath, ppath,
conn->protocol&PROT_HTTPS?TRUE:FALSE); conn->protocol&PROT_HTTPS?TRUE:FALSE);
} }
if ((data->bits.httpproxy) && !(conn->protocol&PROT_HTTPS)) { if ((data->bits.httpproxy) && !(conn->protocol&PROT_HTTPS)) {
/* The path sent to the proxy is in fact the entire URL */ /* The path sent to the proxy is in fact the entire URL */
@ -315,7 +458,7 @@ CURLcode http(struct connectdata *conn)
if(data->bits.http_formpost) { if(data->bits.http_formpost) {
/* we must build the whole darned post sequence first, so that we have /* we must build the whole darned post sequence first, so that we have
a size of the whole shebang before we start to send it */ a size of the whole shebang before we start to send it */
http->sendit = getFormData(data->httppost, &http->postsize); http->sendit = Curl_getFormData(data->httppost, &http->postsize);
} }
if(!checkheaders(data, "Host:")) { if(!checkheaders(data, "Host:")) {
@ -323,9 +466,9 @@ CURLcode http(struct connectdata *conn)
(!(conn->protocol&PROT_HTTPS) && (data->remote_port == PORT_HTTP)) ) (!(conn->protocol&PROT_HTTPS) && (data->remote_port == PORT_HTTP)) )
/* If (HTTPS on port 443) OR (non-HTTPS on port 80) then don't include /* If (HTTPS on port 443) OR (non-HTTPS on port 80) then don't include
the port number in the host string */ the port number in the host string */
data->ptr_host = maprintf("Host: %s\r\n", host); data->ptr_host = aprintf("Host: %s\r\n", host);
else else
data->ptr_host = maprintf("Host: %s:%d\r\n", host, data->remote_port); data->ptr_host = aprintf("Host: %s:%d\r\n", host, data->remote_port);
} }
if(!checkheaders(data, "Pragma:")) if(!checkheaders(data, "Pragma:"))
@ -389,7 +532,7 @@ CURLcode http(struct connectdata *conn)
if(count) { if(count) {
add_buffer(req_buffer, "\r\n", 2); add_buffer(req_buffer, "\r\n", 2);
} }
cookie_freelist(store); /* free the cookie list */ Curl_cookie_freelist(store); /* free the cookie list */
co=NULL; co=NULL;
} }
@ -451,7 +594,7 @@ CURLcode http(struct connectdata *conn)
} }
if(data->bits.http_formpost) { if(data->bits.http_formpost) {
if(FormInit(&http->form, http->sendit)) { if(Curl_FormInit(&http->form, http->sendit)) {
failf(data, "Internal HTTP POST error!\n"); failf(data, "Internal HTTP POST error!\n");
return CURLE_HTTP_POST_ERROR; return CURLE_HTTP_POST_ERROR;
} }
@ -461,15 +604,15 @@ CURLcode http(struct connectdata *conn)
data->fread = data->fread =
(size_t (*)(char *, size_t, size_t, FILE *)) (size_t (*)(char *, size_t, size_t, FILE *))
FormReader; /* set the read function to read from the Curl_FormReader; /* set the read function to read from the
generated form data */ generated form data */
data->in = (FILE *)&http->form; data->in = (FILE *)&http->form;
add_bufferf(req_buffer, add_bufferf(req_buffer,
"Content-Length: %d\r\n", http->postsize-2); "Content-Length: %d\r\n", http->postsize-2);
/* set upload size to the progress meter */ /* set upload size to the progress meter */
pgrsSetUploadSize(data, http->postsize); Curl_pgrsSetUploadSize(data, http->postsize);
data->request_size = data->request_size =
add_buffer_send(data->firstsocket, conn, req_buffer); add_buffer_send(data->firstsocket, conn, req_buffer);
@ -478,7 +621,7 @@ CURLcode http(struct connectdata *conn)
data->firstsocket, data->firstsocket,
&http->writebytecount); &http->writebytecount);
if(result) { if(result) {
FormFree(http->sendit); /* free that whole lot */ Curl_FormFree(http->sendit); /* free that whole lot */
return result; return result;
} }
} }
@ -494,7 +637,7 @@ CURLcode http(struct connectdata *conn)
add_bufferf(req_buffer, "\015\012"); add_bufferf(req_buffer, "\015\012");
/* set the upload size to the progress meter */ /* set the upload size to the progress meter */
pgrsSetUploadSize(data, data->infilesize); Curl_pgrsSetUploadSize(data, data->infilesize);
/* this sends the buffer and frees all the buffer resources */ /* this sends the buffer and frees all the buffer resources */
data->request_size = data->request_size =

View File

@ -25,13 +25,13 @@
*****************************************************************************/ *****************************************************************************/
/* ftp can use this as well */ /* ftp can use this as well */
CURLcode GetHTTPProxyTunnel(struct UrlData *data, int tunnelsocket, CURLcode Curl_ConnectHTTPProxyTunnel(struct UrlData *data, int tunnelsocket,
char *hostname, int remote_port); char *hostname, int remote_port);
/* protocol-specific functions set up to be called by the main engine */ /* protocol-specific functions set up to be called by the main engine */
CURLcode http(struct connectdata *conn); CURLcode Curl_http(struct connectdata *conn);
CURLcode http_done(struct connectdata *conn); CURLcode Curl_http_done(struct connectdata *conn);
CURLcode http_connect(struct connectdata *conn); CURLcode Curl_http_connect(struct connectdata *conn);
CURLcode http_close(struct connectdata *conn); CURLcode Curl_http_close(struct connectdata *conn);
#endif #endif

View File

@ -72,7 +72,7 @@
#define SYS_ERROR -1 #define SYS_ERROR -1
char *if2ip(char *interface, char *buf, int buf_size) char *Curl_if2ip(char *interface, char *buf, int buf_size)
{ {
int dummy; int dummy;
char *ip=NULL; char *ip=NULL;

View File

@ -25,9 +25,9 @@
#include "setup.h" #include "setup.h"
#if ! defined(WIN32) && ! defined(__BEOS__) #if ! defined(WIN32) && ! defined(__BEOS__)
extern char *if2ip(char *interface, char *buf, int buf_size); extern char *Curl_if2ip(char *interface, char *buf, int buf_size);
#else #else
#define if2ip(a,b,c) NULL #define Curl_if2ip(a,b,c) NULL
#endif #endif
#endif #endif

View File

@ -47,6 +47,9 @@
#include <string.h> #include <string.h>
#include <krb.h> #include <krb.h>
#include "ftp.h"
#include "sendf.h"
/* The last #include file should be: */ /* The last #include file should be: */
#ifdef MALLOCDEBUG #ifdef MALLOCDEBUG
#include "memdebug.h" #include "memdebug.h"
@ -95,7 +98,8 @@ strlcpy (char *dst, const char *src, size_t dst_sz)
else else
return n + strlen (src); return n + strlen (src);
} }
#else
size_t strlcpy (char *dst, const char *src, size_t dst_sz);
#endif #endif
static int static int
@ -284,7 +288,8 @@ krb4_auth(void *app_data, struct connectdata *conn)
size_t nread; size_t nread;
int l = sizeof(local_addr); int l = sizeof(local_addr);
if(getsockname(conn->data->firstsocket, LOCAL_ADDR, &l) < 0) if(getsockname(conn->data->firstsocket,
(struct sockaddr *)LOCAL_ADDR, &l) < 0)
perror("getsockname()"); perror("getsockname()");
checksum = getpid(); checksum = getpid();
@ -327,15 +332,15 @@ krb4_auth(void *app_data, struct connectdata *conn)
/*printf("Local address is %s\n", inet_ntoa(localaddr->sin_addr));***/ /*printf("Local address is %s\n", inet_ntoa(localaddr->sin_addr));***/
/*printf("Remote address is %s\n", inet_ntoa(remoteaddr->sin_addr));***/ /*printf("Remote address is %s\n", inet_ntoa(remoteaddr->sin_addr));***/
if(base64_encode(adat.dat, adat.length, &p) < 0) { if(Curl_base64_encode(adat.dat, adat.length, &p) < 0) {
printf("Out of memory base64-encoding.\n"); printf("Out of memory base64-encoding.\n");
return AUTH_CONTINUE; return AUTH_CONTINUE;
} }
/*ret = command("ADAT %s", p)*/ /*ret = command("ADAT %s", p)*/
ftpsendf(conn->data->firstsocket, conn, "ADAT %s", p); Curl_ftpsendf(conn->data->firstsocket, conn, "ADAT %s", p);
/* wait for feedback */ /* wait for feedback */
nread = GetLastResponse(conn->data->firstsocket, nread = Curl_GetFTPResponse(conn->data->firstsocket,
conn->data->buffer, conn); conn->data->buffer, conn, NULL);
if(nread < 0) if(nread < 0)
return /*CURLE_OPERATION_TIMEOUTED*/-1; return /*CURLE_OPERATION_TIMEOUTED*/-1;
free(p); free(p);
@ -351,7 +356,7 @@ krb4_auth(void *app_data, struct connectdata *conn)
return AUTH_ERROR; return AUTH_ERROR;
} }
p += 5; p += 5;
len = base64_decode(p, adat.dat); len = Curl_base64_decode(p, adat.dat);
if(len < 0){ if(len < 0){
printf("Failed to decode base64 from server.\n"); printf("Failed to decode base64 from server.\n");
return AUTH_ERROR; return AUTH_ERROR;
@ -389,8 +394,6 @@ struct sec_client_mech krb4_client_mech = {
void krb_kauth(struct connectdata *conn) void krb_kauth(struct connectdata *conn)
{ {
int ret;
char buf[1024];
des_cblock key; des_cblock key;
des_key_schedule schedule; des_key_schedule schedule;
KTEXT_ST tkt, tktcopy; KTEXT_ST tkt, tktcopy;
@ -405,10 +408,11 @@ void krb_kauth(struct connectdata *conn)
save = set_command_prot(conn, prot_private); save = set_command_prot(conn, prot_private);
/*ret = command("SITE KAUTH %s", name);***/ /*ret = command("SITE KAUTH %s", name);***/
ftpsendf(conn->data->firstsocket, conn, Curl_ftpsendf(conn->data->firstsocket, conn,
"SITE KAUTH %s", conn->data->user); "SITE KAUTH %s", conn->data->user);
/* wait for feedback */ /* wait for feedback */
nread = GetLastResponse(conn->data->firstsocket, conn->data->buffer, conn); nread = Curl_GetFTPResponse(conn->data->firstsocket, conn->data->buffer,
conn, NULL);
if(nread < 0) if(nread < 0)
return /*CURLE_OPERATION_TIMEOUTED*/; return /*CURLE_OPERATION_TIMEOUTED*/;
@ -427,7 +431,7 @@ void krb_kauth(struct connectdata *conn)
return; return;
} }
p += 2; p += 2;
tmp = base64_decode(p, &tkt.dat); tmp = Curl_base64_decode(p, &tkt.dat);
if(tmp < 0){ if(tmp < 0){
printf("Failed to decode base64 in reply.\n"); printf("Failed to decode base64 in reply.\n");
set_command_prot(conn, save); set_command_prot(conn, save);
@ -476,7 +480,7 @@ void krb_kauth(struct connectdata *conn)
memset(key, 0, sizeof(key)); memset(key, 0, sizeof(key));
memset(schedule, 0, sizeof(schedule)); memset(schedule, 0, sizeof(schedule));
memset(passwd, 0, sizeof(passwd)); memset(passwd, 0, sizeof(passwd));
if(base64_encode(tktcopy.dat, tktcopy.length, &p) < 0) { if(Curl_base64_encode(tktcopy.dat, tktcopy.length, &p) < 0) {
failf(conn->data, "Out of memory base64-encoding.\n"); failf(conn->data, "Out of memory base64-encoding.\n");
set_command_prot(conn, save); set_command_prot(conn, save);
/*code = -1;***/ /*code = -1;***/
@ -484,10 +488,11 @@ void krb_kauth(struct connectdata *conn)
} }
memset (tktcopy.dat, 0, tktcopy.length); memset (tktcopy.dat, 0, tktcopy.length);
/*ret = command("SITE KAUTH %s %s", name, p);***/ /*ret = command("SITE KAUTH %s %s", name, p);***/
ftpsendf(conn->data->firstsocket, conn, Curl_ftpsendf(conn->data->firstsocket, conn,
"SITE KAUTH %s %s", name, p); "SITE KAUTH %s %s", name, p);
/* wait for feedback */ /* wait for feedback */
nread = GetLastResponse(conn->data->firstsocket, conn->data->buffer, conn); nread = Curl_GetFTPResponse(conn->data->firstsocket, conn->data->buffer,
conn, NULL);
if(nread < 0) if(nread < 0)
return /*CURLE_OPERATION_TIMEOUTED*/; return /*CURLE_OPERATION_TIMEOUTED*/;
free(p); free(p);

View File

@ -117,18 +117,18 @@ static void * DynaGetFunction(char *name)
static int WriteProc(void *param, char *text, int len) static int WriteProc(void *param, char *text, int len)
{ {
struct UrlData *data = (struct UrlData *)param; struct UrlData *data = (struct UrlData *)param;
client_write(data, CLIENTWRITE_BODY, text, 0); Curl_client_write(data, CLIENTWRITE_BODY, text, 0);
return 0; return 0;
} }
CURLcode ldap_done(struct connectdata *conn) CURLcode Curl_ldap_done(struct connectdata *conn)
{ {
return CURLE_OK; return CURLE_OK;
} }
/*********************************************************************** /***********************************************************************
*/ */
CURLcode ldap(struct connectdata *conn) CURLcode Curl_ldap(struct connectdata *conn)
{ {
CURLcode status = CURLE_OK; CURLcode status = CURLE_OK;
int rc; int rc;

View File

@ -23,7 +23,7 @@
* *
* $Id$ * $Id$
*****************************************************************************/ *****************************************************************************/
CURLcode ldap(struct connectdata *conn); CURLcode Curl_ldap(struct connectdata *conn);
CURLcode ldap_done(struct connectdata *conn); CURLcode Curl_ldap_done(struct connectdata *conn);
#endif /* __LDAP_H */ #endif /* __LDAP_H */

View File

@ -135,7 +135,7 @@ int curl_sclose(int sockfd, int line, char *source)
int res=sclose(sockfd); int res=sclose(sockfd);
fprintf(logfile?logfile:stderr, "FD %s:%d sclose(%d)\n", fprintf(logfile?logfile:stderr, "FD %s:%d sclose(%d)\n",
source, line, sockfd); source, line, sockfd);
return sockfd; return res;
} }
FILE *curl_fopen(char *file, char *mode, int line, char *source) FILE *curl_fopen(char *file, char *mode, int line, char *source)

View File

@ -207,7 +207,7 @@ struct asprintf {
size_t alloc; /* length of alloc */ size_t alloc; /* length of alloc */
}; };
int msprintf(char *buffer, const char *format, ...); int Curl_msprintf(char *buffer, const char *format, ...);
static int dprintf_DollarString(char *input, char **end) static int dprintf_DollarString(char *input, char **end)
{ {
@ -955,11 +955,11 @@ static int dprintf_formatf(
if(width >= 0) { if(width >= 0) {
/* RECURSIVE USAGE */ /* RECURSIVE USAGE */
fptr += msprintf(fptr, "%d", width); fptr += Curl_msprintf(fptr, "%d", width);
} }
if(prec >= 0) { if(prec >= 0) {
/* RECURSIVE USAGE */ /* RECURSIVE USAGE */
fptr += msprintf(fptr, ".%d", prec); fptr += Curl_msprintf(fptr, ".%d", prec);
} }
if (p->flags & FLAGS_LONG) if (p->flags & FLAGS_LONG)
strcat(fptr, "l"); strcat(fptr, "l");
@ -1025,7 +1025,7 @@ static int addbyter(int output, FILE *data)
return -1; return -1;
} }
int msnprintf(char *buffer, size_t maxlength, const char *format, ...) int Curl_msnprintf(char *buffer, size_t maxlength, const char *format, ...)
{ {
va_list ap_save; /* argument pointer */ va_list ap_save; /* argument pointer */
int retcode; int retcode;
@ -1045,7 +1045,7 @@ int msnprintf(char *buffer, size_t maxlength, const char *format, ...)
return retcode; return retcode;
} }
int mvsnprintf(char *buffer, size_t maxlength, const char *format, va_list ap_save) int Curl_mvsnprintf(char *buffer, size_t maxlength, const char *format, va_list ap_save)
{ {
int retcode; int retcode;
struct nsprintf info; struct nsprintf info;
@ -1092,7 +1092,7 @@ static int alloc_addbyter(int output, FILE *data)
} }
char *maprintf(const char *format, ...) char *Curl_maprintf(const char *format, ...)
{ {
va_list ap_save; /* argument pointer */ va_list ap_save; /* argument pointer */
int retcode; int retcode;
@ -1113,7 +1113,7 @@ char *maprintf(const char *format, ...)
return NULL; return NULL;
} }
char *mvaprintf(const char *format, va_list ap_save) char *Curl_mvaprintf(const char *format, va_list ap_save)
{ {
int retcode; int retcode;
struct asprintf info; struct asprintf info;
@ -1140,7 +1140,7 @@ static int storebuffer(int output, FILE *data)
return output; /* act like fputc() ! */ return output; /* act like fputc() ! */
} }
int msprintf(char *buffer, const char *format, ...) int Curl_msprintf(char *buffer, const char *format, ...)
{ {
va_list ap_save; /* argument pointer */ va_list ap_save; /* argument pointer */
int retcode; int retcode;
@ -1153,7 +1153,7 @@ int msprintf(char *buffer, const char *format, ...)
extern int fputc(int, FILE *); extern int fputc(int, FILE *);
int mprintf(const char *format, ...) int Curl_mprintf(const char *format, ...)
{ {
int retcode; int retcode;
va_list ap_save; /* argument pointer */ va_list ap_save; /* argument pointer */
@ -1163,7 +1163,7 @@ int mprintf(const char *format, ...)
return retcode; return retcode;
} }
int mfprintf(FILE *whereto, const char *format, ...) int Curl_mfprintf(FILE *whereto, const char *format, ...)
{ {
int retcode; int retcode;
va_list ap_save; /* argument pointer */ va_list ap_save; /* argument pointer */
@ -1173,7 +1173,7 @@ int mfprintf(FILE *whereto, const char *format, ...)
return retcode; return retcode;
} }
int mvsprintf(char *buffer, const char *format, va_list ap_save) int Curl_mvsprintf(char *buffer, const char *format, va_list ap_save)
{ {
int retcode; int retcode;
retcode = dprintf_formatf(&buffer, storebuffer, format, ap_save); retcode = dprintf_formatf(&buffer, storebuffer, format, ap_save);
@ -1181,12 +1181,12 @@ int mvsprintf(char *buffer, const char *format, va_list ap_save)
return retcode; return retcode;
} }
int mvprintf(const char *format, va_list ap_save) int Curl_mvprintf(const char *format, va_list ap_save)
{ {
return dprintf_formatf(stdout, fputc, format, ap_save); return dprintf_formatf(stdout, fputc, format, ap_save);
} }
int mvfprintf(FILE *whereto, const char *format, va_list ap_save) int Curl_mvfprintf(FILE *whereto, const char *format, va_list ap_save)
{ {
return dprintf_formatf(whereto, fputc, format, ap_save); return dprintf_formatf(whereto, fputc, format, ap_save);
} }

View File

@ -51,15 +51,15 @@ enum {
#define LOGINSIZE 64 #define LOGINSIZE 64
#define PASSWORDSIZE 64 #define PASSWORDSIZE 64
int ParseNetrc(char *host, int Curl_parsenetrc(char *host,
char *login, char *login,
char *password) char *password)
{ {
FILE *file; FILE *file;
char netrcbuffer[256]; char netrcbuffer[256];
int retcode=1; int retcode=1;
char *home = GetEnv("HOME"); /* portable environment reader */ char *home = curl_getenv("HOME"); /* portable environment reader */
int state=NOTHING; int state=NOTHING;
char state_login=0; char state_login=0;

View File

@ -22,7 +22,7 @@
* *
* $Id$ * $Id$
*****************************************************************************/ *****************************************************************************/
int ParseNetrc(char *host, int Curl_parsenetrc(char *host,
char *login, char *login,
char *password); char *password);
#endif #endif

View File

@ -45,7 +45,7 @@
#include "progress.h" #include "progress.h"
void time2str(char *r, int t) static void time2str(char *r, int t)
{ {
int h = (t/3600); int h = (t/3600);
int m = (t-(h*3600))/60; int m = (t-(h*3600))/60;
@ -55,7 +55,7 @@ void time2str(char *r, int t)
/* The point of this function would be to return a string of the input data, /* The point of this function would be to return a string of the input data,
but never longer than 5 columns. Add suffix k, M, G when suitable... */ but never longer than 5 columns. Add suffix k, M, G when suitable... */
char *max5data(double bytes, char *max5) static char *max5data(double bytes, char *max5)
{ {
#define ONE_KILOBYTE 1024 #define ONE_KILOBYTE 1024
#define ONE_MEGABYTE (1024*1024) #define ONE_MEGABYTE (1024*1024)
@ -91,16 +91,16 @@ char *max5data(double bytes, char *max5)
*/ */
void pgrsDone(struct UrlData *data) void Curl_pgrsDone(struct UrlData *data)
{ {
if(!(data->progress.flags & PGRS_HIDE)) { if(!(data->progress.flags & PGRS_HIDE)) {
data->progress.lastshow=0; data->progress.lastshow=0;
pgrsUpdate(data); /* the final (forced) update */ Curl_pgrsUpdate(data); /* the final (forced) update */
fprintf(data->err, "\n"); fprintf(data->err, "\n");
} }
} }
void pgrsTime(struct UrlData *data, timerid timer) void Curl_pgrsTime(struct UrlData *data, timerid timer)
{ {
switch(timer) { switch(timer) {
default: default:
@ -111,19 +111,19 @@ void pgrsTime(struct UrlData *data, timerid timer)
/* This is set at the start of a single fetch, there may be several /* This is set at the start of a single fetch, there may be several
fetches within an operation, why we add all other times relative fetches within an operation, why we add all other times relative
to this one */ to this one */
data->progress.t_startsingle = tvnow(); data->progress.t_startsingle = Curl_tvnow();
break; break;
case TIMER_NAMELOOKUP: case TIMER_NAMELOOKUP:
data->progress.t_nslookup += tvdiff(tvnow(), data->progress.t_nslookup += Curl_tvdiff(Curl_tvnow(),
data->progress.t_startsingle); data->progress.t_startsingle);
break; break;
case TIMER_CONNECT: case TIMER_CONNECT:
data->progress.t_connect += tvdiff(tvnow(), data->progress.t_connect += Curl_tvdiff(Curl_tvnow(),
data->progress.t_startsingle); data->progress.t_startsingle);
break; break;
case TIMER_PRETRANSFER: case TIMER_PRETRANSFER:
data->progress.t_pretransfer += tvdiff(tvnow(), data->progress.t_pretransfer += Curl_tvdiff(Curl_tvnow(),
data->progress.t_startsingle); data->progress.t_startsingle);
break; break;
case TIMER_POSTRANSFER: case TIMER_POSTRANSFER:
@ -132,22 +132,22 @@ void pgrsTime(struct UrlData *data, timerid timer)
} }
} }
void pgrsStartNow(struct UrlData *data) void Curl_pgrsStartNow(struct UrlData *data)
{ {
data->progress.start = tvnow(); data->progress.start = Curl_tvnow();
} }
void pgrsSetDownloadCounter(struct UrlData *data, double size) void Curl_pgrsSetDownloadCounter(struct UrlData *data, double size)
{ {
data->progress.downloaded = size; data->progress.downloaded = size;
} }
void pgrsSetUploadCounter(struct UrlData *data, double size) void Curl_pgrsSetUploadCounter(struct UrlData *data, double size)
{ {
data->progress.uploaded = size; data->progress.uploaded = size;
} }
void pgrsSetDownloadSize(struct UrlData *data, double size) void Curl_pgrsSetDownloadSize(struct UrlData *data, double size)
{ {
if(size > 0) { if(size > 0) {
data->progress.size_dl = size; data->progress.size_dl = size;
@ -155,7 +155,7 @@ void pgrsSetDownloadSize(struct UrlData *data, double size)
} }
} }
void pgrsSetUploadSize(struct UrlData *data, double size) void Curl_pgrsSetUploadSize(struct UrlData *data, double size)
{ {
if(size > 0) { if(size > 0) {
data->progress.size_ul = size; data->progress.size_ul = size;
@ -171,7 +171,7 @@ void pgrsSetUploadSize(struct UrlData *data, double size)
*/ */
int pgrsUpdate(struct UrlData *data) int Curl_pgrsUpdate(struct UrlData *data)
{ {
struct timeval now; struct timeval now;
int result; int result;
@ -210,15 +210,15 @@ int pgrsUpdate(struct UrlData *data)
data->progress.flags |= PGRS_HEADERS_OUT; /* headers are shown */ data->progress.flags |= PGRS_HEADERS_OUT; /* headers are shown */
} }
now = tvnow(); /* what time is it */ now = Curl_tvnow(); /* what time is it */
if(data->progress.lastshow == tvlong(now)) if(data->progress.lastshow == Curl_tvlong(now))
return 0; /* never update this more than once a second if the end isn't return 0; /* never update this more than once a second if the end isn't
reached */ reached */
data->progress.lastshow = now.tv_sec; data->progress.lastshow = now.tv_sec;
/* The exact time spent so far */ /* The exact time spent so far */
data->progress.timespent = tvdiff (now, data->progress.start); data->progress.timespent = Curl_tvdiff (now, data->progress.start);
/* The average download speed this far */ /* The average download speed this far */
data->progress.dlspeed = data->progress.downloaded/(data->progress.timespent!=0.0?data->progress.timespent:1.0); data->progress.dlspeed = data->progress.downloaded/(data->progress.timespent!=0.0?data->progress.timespent:1.0);

View File

@ -36,14 +36,14 @@ typedef enum {
TIMER_LAST /* must be last */ TIMER_LAST /* must be last */
} timerid; } timerid;
void pgrsDone(struct UrlData *data); void Curl_pgrsDone(struct UrlData *data);
void pgrsStartNow(struct UrlData *data); void Curl_pgrsStartNow(struct UrlData *data);
void pgrsSetDownloadSize(struct UrlData *data, double size); void Curl_pgrsSetDownloadSize(struct UrlData *data, double size);
void pgrsSetUploadSize(struct UrlData *data, double size); void Curl_pgrsSetUploadSize(struct UrlData *data, double size);
void pgrsSetDownloadCounter(struct UrlData *data, double size); void Curl_pgrsSetDownloadCounter(struct UrlData *data, double size);
void pgrsSetUploadCounter(struct UrlData *data, double size); void Curl_pgrsSetUploadCounter(struct UrlData *data, double size);
int pgrsUpdate(struct UrlData *data); int Curl_pgrsUpdate(struct UrlData *data);
void pgrsTime(struct UrlData *data, timerid timer); void Curl_pgrsTime(struct UrlData *data, timerid timer);
/* Don't show progress for sizes smaller than: */ /* Don't show progress for sizes smaller than: */

View File

@ -40,13 +40,22 @@
#ifdef KRB4 #ifdef KRB4
#define _MPRINTF_REPLACE /* we want curl-functions instead of native ones */
#include <curl/mprintf.h> #include <curl/mprintf.h>
#include "security.h" #include "security.h"
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <netdb.h> #include <netdb.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#include "base64.h" #include "base64.h"
#include "sendf.h"
#include "ftp.h"
/* The last #include file should be: */ /* The last #include file should be: */
#ifdef MALLOCDEBUG #ifdef MALLOCDEBUG
#include "memdebug.h" #include "memdebug.h"
@ -64,6 +73,7 @@ static struct {
{ prot_private, "private" } { prot_private, "private" }
}; };
#if 0
static const char * static const char *
level_to_name(enum protection_level level) level_to_name(enum protection_level level)
{ {
@ -73,6 +83,7 @@ level_to_name(enum protection_level level)
return level_names[i].name; return level_names[i].name;
return "unknown"; return "unknown";
} }
#endif
#ifndef FTP_SERVER /* not used in server */ #ifndef FTP_SERVER /* not used in server */
static enum protection_level static enum protection_level
@ -319,7 +330,7 @@ sec_vfprintf2(struct connectdata *conn, FILE *f, const char *fmt, va_list ap)
if(conn->data_prot == prot_clear) if(conn->data_prot == prot_clear)
return vfprintf(f, fmt, ap); return vfprintf(f, fmt, ap);
else { else {
buf = maprintf(fmt, ap); buf = aprintf(fmt, ap);
ret = buffer_write(&conn->out_buffer, buf, strlen(buf)); ret = buffer_write(&conn->out_buffer, buf, strlen(buf));
free(buf); free(buf);
return ret; return ret;
@ -360,7 +371,7 @@ sec_read_msg(struct connectdata *conn, char *s, int level)
int code; int code;
buf = malloc(strlen(s)); buf = malloc(strlen(s));
len = base64_decode(s + 4, buf); /* XXX */ len = Curl_base64_decode(s + 4, buf); /* XXX */
len = (*mech->decode)(conn->app_data, buf, len, level, conn); len = (*mech->decode)(conn->app_data, buf, len, level, conn);
if(len < 0) if(len < 0)
@ -390,7 +401,7 @@ sec_vfprintf(struct connectdata *conn, FILE *f, const char *fmt, va_list ap)
if(!conn->sec_complete) if(!conn->sec_complete)
return vfprintf(f, fmt, ap); return vfprintf(f, fmt, ap);
buf = maprintf(fmt, ap); buf = aprintf(fmt, ap);
len = (*mech->encode)(conn->app_data, buf, strlen(buf), len = (*mech->encode)(conn->app_data, buf, strlen(buf),
conn->command_prot, &enc, conn->command_prot, &enc,
conn); conn);
@ -399,7 +410,7 @@ sec_vfprintf(struct connectdata *conn, FILE *f, const char *fmt, va_list ap)
failf(conn->data, "Failed to encode command.\n"); failf(conn->data, "Failed to encode command.\n");
return -1; return -1;
} }
if(base64_encode(enc, len, &buf) < 0){ if(Curl_base64_encode(enc, len, &buf) < 0){
failf(conn->data, "Out of memory base64-encoding.\n"); failf(conn->data, "Out of memory base64-encoding.\n");
return -1; return -1;
} }
@ -461,7 +472,6 @@ sec_status(void)
static int static int
sec_prot_internal(struct connectdata *conn, int level) sec_prot_internal(struct connectdata *conn, int level)
{ {
int ret;
char *p; char *p;
unsigned int s = 1048576; unsigned int s = 1048576;
size_t nread; size_t nread;
@ -472,11 +482,11 @@ sec_prot_internal(struct connectdata *conn, int level)
} }
if(level){ if(level){
ftpsendf(conn->data->firstsocket, conn, Curl_ftpsendf(conn->data->firstsocket, conn,
"PBSZ %u", s); "PBSZ %u", s);
/* wait for feedback */ /* wait for feedback */
nread = GetLastResponse(conn->data->firstsocket, nread = Curl_GetFTPResponse(conn->data->firstsocket,
conn->data->buffer, conn); conn->data->buffer, conn, NULL);
if(nread < 0) if(nread < 0)
return /*CURLE_OPERATION_TIMEOUTED*/-1; return /*CURLE_OPERATION_TIMEOUTED*/-1;
if(/*ret != COMPLETE*/conn->data->buffer[0] != '2'){ if(/*ret != COMPLETE*/conn->data->buffer[0] != '2'){
@ -491,11 +501,11 @@ sec_prot_internal(struct connectdata *conn, int level)
conn->buffer_size = s; conn->buffer_size = s;
} }
ftpsendf(conn->data->firstsocket, conn, Curl_ftpsendf(conn->data->firstsocket, conn,
"PROT %c", level["CSEP"]); "PROT %c", level["CSEP"]);
/* wait for feedback */ /* wait for feedback */
nread = GetLastResponse(conn->data->firstsocket, nread = Curl_GetFTPResponse(conn->data->firstsocket,
conn->data->buffer, conn); conn->data->buffer, conn, NULL);
if(nread < 0) if(nread < 0)
return /*CURLE_OPERATION_TIMEOUTED*/-1; return /*CURLE_OPERATION_TIMEOUTED*/-1;
if(/*ret != COMPLETE*/conn->data->buffer[0] != '2'){ if(/*ret != COMPLETE*/conn->data->buffer[0] != '2'){
@ -600,11 +610,11 @@ sec_login(struct connectdata *conn)
} }
infof(data, "Trying %s...\n", (*m)->name); infof(data, "Trying %s...\n", (*m)->name);
/*ret = command("AUTH %s", (*m)->name);***/ /*ret = command("AUTH %s", (*m)->name);***/
ftpsendf(conn->data->firstsocket, conn, Curl_ftpsendf(conn->data->firstsocket, conn,
"AUTH %s", (*m)->name); "AUTH %s", (*m)->name);
/* wait for feedback */ /* wait for feedback */
nread = GetLastResponse(conn->data->firstsocket, nread = Curl_GetFTPResponse(conn->data->firstsocket,
conn->data->buffer, conn); conn->data->buffer, conn, NULL);
if(nread < 0) if(nread < 0)
return /*CURLE_OPERATION_TIMEOUTED*/-1; return /*CURLE_OPERATION_TIMEOUTED*/-1;
if(/*ret != CONTINUE*/conn->data->buffer[0] != '3'){ if(/*ret != CONTINUE*/conn->data->buffer[0] != '3'){

View File

@ -52,7 +52,7 @@
/* infof() is for info message along the way */ /* infof() is for info message along the way */
void infof(struct UrlData *data, char *fmt, ...) void Curl_infof(struct UrlData *data, char *fmt, ...)
{ {
va_list ap; va_list ap;
if(data->bits.verbose) { if(data->bits.verbose) {
@ -66,7 +66,7 @@ void infof(struct UrlData *data, char *fmt, ...)
/* failf() is for messages stating why we failed, the LAST one will be /* failf() is for messages stating why we failed, the LAST one will be
returned for the user (if requested) */ returned for the user (if requested) */
void failf(struct UrlData *data, char *fmt, ...) void Curl_failf(struct UrlData *data, char *fmt, ...)
{ {
va_list ap; va_list ap;
va_start(ap, fmt); va_start(ap, fmt);
@ -78,13 +78,13 @@ void failf(struct UrlData *data, char *fmt, ...)
} }
/* sendf() sends the formated data to the server */ /* sendf() sends the formated data to the server */
size_t sendf(int fd, struct UrlData *data, char *fmt, ...) size_t Curl_sendf(int fd, struct UrlData *data, char *fmt, ...)
{ {
size_t bytes_written; size_t bytes_written;
char *s; char *s;
va_list ap; va_list ap;
va_start(ap, fmt); va_start(ap, fmt);
s = mvaprintf(fmt, ap); s = vaprintf(fmt, ap);
va_end(ap); va_end(ap);
if(!s) if(!s)
return 0; /* failure */ return 0; /* failure */
@ -104,43 +104,8 @@ size_t sendf(int fd, struct UrlData *data, char *fmt, ...)
return(bytes_written); return(bytes_written);
} }
/*
* ftpsendf() sends the formated string as a ftp command to a ftp server
*
* NOTE: we build the command in a fixed-length buffer, which sets length
* restrictions on the command!
*
*/
size_t ftpsendf(int fd, struct connectdata *conn, char *fmt, ...)
{
size_t bytes_written;
char s[256];
va_list ap;
va_start(ap, fmt);
vsnprintf(s, 250, fmt, ap);
va_end(ap);
if(conn->data->bits.verbose)
fprintf(conn->data->err, "> %s\n", s);
strcat(s, "\r\n"); /* append a trailing CRLF */
#ifdef KRB4
if(conn->sec_complete && conn->data->cmdchannel) {
bytes_written = sec_fprintf(conn, conn->data->cmdchannel, s);
fflush(conn->data->cmdchannel);
}
else
#endif /* KRB4 */
{
bytes_written = swrite(fd, s, strlen(s));
}
return(bytes_written);
}
/* ssend() sends plain (binary) data to the server */ /* ssend() sends plain (binary) data to the server */
size_t ssend(int fd, struct connectdata *conn, void *mem, size_t len) size_t Curl_ssend(int fd, struct connectdata *conn, void *mem, size_t len)
{ {
size_t bytes_written; size_t bytes_written;
struct UrlData *data=conn->data; /* conn knows data, not vice versa */ struct UrlData *data=conn->data; /* conn knows data, not vice versa */
@ -170,10 +135,10 @@ size_t ssend(int fd, struct connectdata *conn, void *mem, size_t len)
The bit pattern defines to what "streams" to write to. Body and/or header. The bit pattern defines to what "streams" to write to. Body and/or header.
The defines are in sendf.h of course. The defines are in sendf.h of course.
*/ */
CURLcode client_write(struct UrlData *data, CURLcode Curl_client_write(struct UrlData *data,
int type, int type,
char *ptr, char *ptr,
size_t len) size_t len)
{ {
size_t wrote; size_t wrote;
@ -198,92 +163,3 @@ CURLcode client_write(struct UrlData *data,
return CURLE_OK; return CURLE_OK;
} }
/*
* add_buffer_init() returns a fine buffer struct
*/
send_buffer *add_buffer_init(void)
{
send_buffer *blonk;
blonk=(send_buffer *)malloc(sizeof(send_buffer));
if(blonk) {
memset(blonk, 0, sizeof(send_buffer));
return blonk;
}
return NULL; /* failed, go home */
}
/*
* add_buffer_send() sends a buffer and frees all associated memory.
*/
size_t add_buffer_send(int sockfd, struct connectdata *conn, send_buffer *in)
{
size_t amount;
if(conn->data->bits.verbose) {
fputs("> ", conn->data->err);
/* this data _may_ contain binary stuff */
fwrite(in->buffer, in->size_used, 1, conn->data->err);
}
amount = ssend(sockfd, conn, in->buffer, in->size_used);
if(in->buffer)
free(in->buffer);
free(in);
return amount;
}
/*
* add_bufferf() builds a buffer from the formatted input
*/
CURLcode add_bufferf(send_buffer *in, char *fmt, ...)
{
CURLcode result = CURLE_OUT_OF_MEMORY;
char *s;
va_list ap;
va_start(ap, fmt);
s = mvaprintf(fmt, ap); /* this allocs a new string to append */
va_end(ap);
if(s) {
result = add_buffer(in, s, strlen(s));
free(s);
}
return result;
}
/*
* add_buffer() appends a memory chunk to the existing one
*/
CURLcode add_buffer(send_buffer *in, void *inptr, size_t size)
{
char *new_rb;
int new_size;
if(size > 0) {
if(!in->buffer ||
((in->size_used + size) > (in->size_max - 1))) {
new_size = (in->size_used+size)*2;
if(in->buffer)
/* we have a buffer, enlarge the existing one */
new_rb = (char *)realloc(in->buffer, new_size);
else
/* create a new buffer */
new_rb = (char *)malloc(new_size);
if(!new_rb)
return CURLE_OUT_OF_MEMORY;
in->buffer = new_rb;
in->size_max = new_size;
}
memcpy(&in->buffer[in->size_used], inptr, size);
in->size_used += size;
}
return CURLE_OK;
}

View File

@ -23,11 +23,15 @@
* $Id$ * $Id$
*****************************************************************************/ *****************************************************************************/
size_t ftpsendf(int fd, struct connectdata *, char *fmt, ...); size_t Curl_sendf(int fd, struct UrlData *, char *fmt, ...);
size_t sendf(int fd, struct UrlData *, char *fmt, ...); size_t Curl_ssend(int fd, struct connectdata *, void *fmt, size_t len);
size_t ssend(int fd, struct connectdata *, void *fmt, size_t len); void Curl_infof(struct UrlData *, char *fmt, ...);
void infof(struct UrlData *, char *fmt, ...); void Curl_failf(struct UrlData *, char *fmt, ...);
void failf(struct UrlData *, char *fmt, ...);
#define sendf Curl_sendf
#define ssend Curl_ssend
#define infof Curl_infof
#define failf Curl_failf
struct send_buffer { struct send_buffer {
char *buffer; char *buffer;
@ -40,12 +44,7 @@ typedef struct send_buffer send_buffer;
#define CLIENTWRITE_HEADER 2 #define CLIENTWRITE_HEADER 2
#define CLIENTWRITE_BOTH (CLIENTWRITE_BODY|CLIENTWRITE_HEADER) #define CLIENTWRITE_BOTH (CLIENTWRITE_BODY|CLIENTWRITE_HEADER)
CURLcode client_write(struct UrlData *data, int type, char *ptr, CURLcode Curl_client_write(struct UrlData *data, int type, char *ptr,
size_t len); size_t len);
send_buffer *add_buffer_init(void);
CURLcode add_buffer(send_buffer *in, void *inptr, size_t size);
CURLcode add_bufferf(send_buffer *in, char *fmt, ...);
size_t add_buffer_send(int sockfd, struct connectdata *conn, send_buffer *in);
#endif #endif

View File

@ -33,24 +33,24 @@
#include "sendf.h" #include "sendf.h"
#include "speedcheck.h" #include "speedcheck.h"
void speedinit(struct UrlData *data) void Curl_speedinit(struct UrlData *data)
{ {
memset(&data->keeps_speed, 0, sizeof(struct timeval)); memset(&data->keeps_speed, 0, sizeof(struct timeval));
} }
CURLcode speedcheck(struct UrlData *data, CURLcode Curl_speedcheck(struct UrlData *data,
struct timeval now) struct timeval now)
{ {
if((data->progress.current_speed >= 0) && if((data->progress.current_speed >= 0) &&
data->low_speed_time && data->low_speed_time &&
(tvlong(data->keeps_speed) != 0) && (Curl_tvlong(data->keeps_speed) != 0) &&
(data->progress.current_speed < data->low_speed_limit)) { (data->progress.current_speed < data->low_speed_limit)) {
/* We are now below the "low speed limit". If we are below it /* We are now below the "low speed limit". If we are below it
for "low speed time" seconds we consider that enough reason for "low speed time" seconds we consider that enough reason
to abort the download. */ to abort the download. */
if( tvdiff(now, data->keeps_speed) > data->low_speed_time) { if( Curl_tvdiff(now, data->keeps_speed) > data->low_speed_time) {
/* we have been this slow for long enough, now die */ /* we have been this slow for long enough, now die */
failf(data, failf(data,
"Operation too slow. " "Operation too slow. "

View File

@ -27,8 +27,8 @@
#include "timeval.h" #include "timeval.h"
void speedinit(struct UrlData *data); void Curl_speedinit(struct UrlData *data);
CURLcode speedcheck(struct UrlData *data, CURLcode Curl_speedcheck(struct UrlData *data,
struct timeval now); struct timeval now);
#endif #endif

View File

@ -62,9 +62,10 @@ static int passwd_callback(char *buf, int num, int verify
* from) source from the SSLeay package written by Eric Young * from) source from the SSLeay package written by Eric Young
* (eay@cryptsoft.com). */ * (eay@cryptsoft.com). */
int SSL_cert_stuff(struct UrlData *data, static
char *cert_file, int cert_stuff(struct UrlData *data,
char *key_file) char *cert_file,
char *key_file)
{ {
if (cert_file != NULL) { if (cert_file != NULL) {
SSL *ssl; SSL *ssl;
@ -124,6 +125,7 @@ int SSL_cert_stuff(struct UrlData *data,
#endif #endif
#ifdef USE_SSLEAY #ifdef USE_SSLEAY
static
int cert_verify_callback(int ok, X509_STORE_CTX *ctx) int cert_verify_callback(int ok, X509_STORE_CTX *ctx)
{ {
X509 *err_cert; X509 *err_cert;
@ -139,7 +141,7 @@ int cert_verify_callback(int ok, X509_STORE_CTX *ctx)
/* ====================================================== */ /* ====================================================== */
int int
UrgSSLConnect (struct UrlData *data) Curl_SSLConnect (struct UrlData *data)
{ {
#ifdef USE_SSLEAY #ifdef USE_SSLEAY
int err; int err;
@ -163,7 +165,7 @@ UrgSSLConnect (struct UrlData *data)
RAND_screen(); RAND_screen();
#else #else
int len; int len;
char *area = MakeFormBoundary(); char *area = Curl_FormBoundary();
if(!area) if(!area)
return 3; /* out of memory */ return 3; /* out of memory */
@ -198,7 +200,7 @@ UrgSSLConnect (struct UrlData *data)
} }
if(data->cert) { if(data->cert) {
if (!SSL_cert_stuff(data, data->cert, data->cert)) { if (!cert_stuff(data, data->cert, data->cert)) {
failf(data, "couldn't use certificate!\n"); failf(data, "couldn't use certificate!\n");
return 2; return 2;
} }

View File

@ -22,8 +22,5 @@
* *
* $Id$ * $Id$
*****************************************************************************/ *****************************************************************************/
int SSL_cert_stuff(struct UrlData *data, int Curl_SSLConnect (struct UrlData *data);
char *cert_file,
char *key_file);
int UrgSSLConnect (struct UrlData *data);
#endif #endif

View File

@ -25,7 +25,7 @@
#include <string.h> #include <string.h>
int strequal(const char *first, const char *second) int Curl_strequal(const char *first, const char *second)
{ {
#if defined(HAVE_STRCASECMP) #if defined(HAVE_STRCASECMP)
return !strcasecmp(first, second); return !strcasecmp(first, second);
@ -45,7 +45,7 @@ int strequal(const char *first, const char *second)
#endif #endif
} }
int strnequal(const char *first, const char *second, size_t max) int Curl_strnequal(const char *first, const char *second, size_t max)
{ {
#if defined(HAVE_STRCASECMP) #if defined(HAVE_STRCASECMP)
return !strncasecmp(first, second, max); return !strncasecmp(first, second, max);

View File

@ -22,7 +22,10 @@
* *
* $Id$ * $Id$
*****************************************************************************/ *****************************************************************************/
int strequal(const char *first, const char *second); int Curl_strequal(const char *first, const char *second);
int strnequal(const char *first, const char *second, size_t max); int Curl_strnequal(const char *first, const char *second, size_t max);
#define strequal(a,b) Curl_strequal(a,b)
#define strnequal(a,b,c) Curl_strnequal(a,b,c)
#endif #endif

View File

@ -81,7 +81,6 @@
#define TELOPTS #define TELOPTS
#define TELCMDS #define TELCMDS
#define SLC_NAMES
#include "arpa_telnet.h" #include "arpa_telnet.h"
@ -98,10 +97,12 @@
#define SB_EOF() (subpointer >= subend) #define SB_EOF() (subpointer >= subend)
#define SB_LEN() (subend - subpointer) #define SB_LEN() (subend - subpointer)
static
void telwrite(struct UrlData *data, void telwrite(struct UrlData *data,
unsigned char *buffer, /* Data to write */ unsigned char *buffer, /* Data to write */
int count); /* Number of bytes to write */ int count); /* Number of bytes to write */
static
void telrcv(struct UrlData *data, void telrcv(struct UrlData *data,
unsigned char *inbuf, /* Data received from socket */ unsigned char *inbuf, /* Data received from socket */
int count); /* Number of bytes received */ int count); /* Number of bytes received */
@ -155,6 +156,7 @@ static int him[256];
static int himq[256]; static int himq[256];
static int him_preferred[256]; static int him_preferred[256];
static
void init_telnet(struct UrlData *data) void init_telnet(struct UrlData *data)
{ {
telrcv_state = TS_DATA; telrcv_state = TS_DATA;
@ -246,6 +248,7 @@ static void send_negotiation(struct UrlData *data, int cmd, int option)
printoption(data, "SENT", cmd, option); printoption(data, "SENT", cmd, option);
} }
static
void set_remote_option(struct UrlData *data, int option, int newstate) void set_remote_option(struct UrlData *data, int option, int newstate)
{ {
if(newstate == YES) if(newstate == YES)
@ -326,6 +329,7 @@ void set_remote_option(struct UrlData *data, int option, int newstate)
} }
} }
static
void rec_will(struct UrlData *data, int option) void rec_will(struct UrlData *data, int option)
{ {
switch(him[option]) switch(him[option])
@ -377,6 +381,7 @@ void rec_will(struct UrlData *data, int option)
} }
} }
static
void rec_wont(struct UrlData *data, int option) void rec_wont(struct UrlData *data, int option)
{ {
switch(him[option]) switch(him[option])
@ -500,6 +505,7 @@ void set_local_option(struct UrlData *data, int option, int newstate)
} }
} }
static
void rec_do(struct UrlData *data, int option) void rec_do(struct UrlData *data, int option)
{ {
switch(us[option]) switch(us[option])
@ -550,7 +556,8 @@ void rec_do(struct UrlData *data, int option)
break; break;
} }
} }
static
void rec_dont(struct UrlData *data, int option) void rec_dont(struct UrlData *data, int option)
{ {
switch(us[option]) switch(us[option])
@ -669,6 +676,7 @@ static void suboption(struct UrlData *data)
return; return;
} }
static
void telrcv(struct UrlData *data, void telrcv(struct UrlData *data,
unsigned char *inbuf, /* Data received from socket */ unsigned char *inbuf, /* Data received from socket */
int count) /* Number of bytes received */ int count) /* Number of bytes received */
@ -689,7 +697,7 @@ void telrcv(struct UrlData *data,
break; /* Ignore \0 after CR */ break; /* Ignore \0 after CR */
} }
client_write(data, CLIENTWRITE_BODY, (char *)&c, 1); Curl_client_write(data, CLIENTWRITE_BODY, (char *)&c, 1);
continue; continue;
case TS_DATA: case TS_DATA:
@ -703,7 +711,7 @@ void telrcv(struct UrlData *data,
telrcv_state = TS_CR; telrcv_state = TS_CR;
} }
client_write(data, CLIENTWRITE_BODY, (char *)&c, 1); Curl_client_write(data, CLIENTWRITE_BODY, (char *)&c, 1);
continue; continue;
case TS_IAC: case TS_IAC:
@ -727,7 +735,7 @@ void telrcv(struct UrlData *data,
telrcv_state = TS_SB; telrcv_state = TS_SB;
continue; continue;
case IAC: case IAC:
client_write(data, CLIENTWRITE_BODY, (char *)&c, 1); Curl_client_write(data, CLIENTWRITE_BODY, (char *)&c, 1);
break; break;
case DM: case DM:
case NOP: case NOP:
@ -818,6 +826,7 @@ void telrcv(struct UrlData *data,
} }
} }
static
void telwrite(struct UrlData *data, void telwrite(struct UrlData *data,
unsigned char *buffer, /* Data to write */ unsigned char *buffer, /* Data to write */
int count) /* Number of bytes to write */ int count) /* Number of bytes to write */
@ -847,12 +856,12 @@ void telwrite(struct UrlData *data,
} }
} }
CURLcode telnet_done(struct connectdata *conn) CURLcode Curl_telnet_done(struct connectdata *conn)
{ {
return CURLE_OK; return CURLE_OK;
} }
CURLcode telnet(struct connectdata *conn) CURLcode Curl_telnet(struct connectdata *conn)
{ {
struct UrlData *data = conn->data; struct UrlData *data = conn->data;
int sockfd = data->firstsocket; int sockfd = data->firstsocket;

View File

@ -23,7 +23,7 @@
* *
* $Id$ * $Id$
*****************************************************************************/ *****************************************************************************/
CURLcode telnet(struct connectdata *conn); CURLcode Curl_telnet(struct connectdata *conn);
CURLcode telnet_done(struct connectdata *conn); CURLcode Curl_telnet_done(struct connectdata *conn);
#endif #endif

View File

@ -53,7 +53,7 @@ gettimeofday (struct timeval *tp, void *nothing)
#endif #endif
#endif #endif
struct timeval tvnow () struct timeval Curl_tvnow ()
{ {
struct timeval now; struct timeval now;
#ifdef HAVE_GETTIMEOFDAY #ifdef HAVE_GETTIMEOFDAY
@ -65,12 +65,12 @@ struct timeval tvnow ()
return now; return now;
} }
double tvdiff (struct timeval t1, struct timeval t2) double Curl_tvdiff (struct timeval t1, struct timeval t2)
{ {
return (double)(t1.tv_sec - t2.tv_sec) + ((t1.tv_usec-t2.tv_usec)/1000000.0); return (double)(t1.tv_sec - t2.tv_sec) + ((t1.tv_usec-t2.tv_usec)/1000000.0);
} }
long tvlong (struct timeval t1) long Curl_tvlong (struct timeval t1)
{ {
return t1.tv_sec; return t1.tv_sec;
} }

View File

@ -42,8 +42,8 @@ struct timeval {
#endif #endif
#endif #endif
struct timeval tvnow (); struct timeval Curl_tvnow ();
double tvdiff (struct timeval t1, struct timeval t2); double Curl_tvdiff (struct timeval t1, struct timeval t2);
long tvlong (struct timeval t1); long Curl_tvlong (struct timeval t1);
#endif #endif

146
lib/url.c
View File

@ -87,7 +87,6 @@
#include "if2ip.h" #include "if2ip.h"
#include "download.h" #include "download.h"
#include "sendf.h" #include "sendf.h"
#include "speedcheck.h"
#include "getpass.h" #include "getpass.h"
#include "progress.h" #include "progress.h"
#include "cookie.h" #include "cookie.h"
@ -224,7 +223,7 @@ void static urlfree(struct UrlData *data, bool totally)
/* the URL is allocated, free it! */ /* the URL is allocated, free it! */
free(data->url); free(data->url);
cookie_cleanup(data->cookies); Curl_cookie_cleanup(data->cookies);
free(data); free(data);
@ -248,6 +247,7 @@ CURLcode curl_close(CURL *curl)
return CURLE_OK; return CURLE_OK;
} }
static
int my_getpass(void *clientp, char *prompt, char* buffer, int buflen ) int my_getpass(void *clientp, char *prompt, char* buffer, int buflen )
{ {
char *retbuf; char *retbuf;
@ -381,7 +381,7 @@ CURLcode curl_setopt(CURL *curl, CURLoption option, ...)
case CURLOPT_COOKIEFILE: case CURLOPT_COOKIEFILE:
cookiefile = (char *)va_arg(param, void *); cookiefile = (char *)va_arg(param, void *);
if(cookiefile) { if(cookiefile) {
data->cookies = cookie_init(cookiefile); data->cookies = Curl_cookie_init(cookiefile);
} }
break; break;
case CURLOPT_WRITEHEADER: case CURLOPT_WRITEHEADER:
@ -533,50 +533,11 @@ CURLcode curl_setopt(CURL *curl, CURLoption option, ...)
return CURLE_OK; return CURLE_OK;
} }
/*
* Read everything until a newline.
*/
int GetLine(int sockfd, char *buf, struct UrlData *data)
{
int nread;
int read_rc=1;
char *ptr;
ptr=buf;
/* get us a full line, terminated with a newline */
for(nread=0;
(nread<BUFSIZE) && read_rc;
nread++, ptr++) {
#ifdef USE_SSLEAY
if (data->ssl.use) {
read_rc = SSL_read(data->ssl.handle, ptr, 1);
}
else {
#endif
read_rc = sread(sockfd, ptr, 1);
#ifdef USE_SSLEAY
}
#endif /* USE_SSLEAY */
if (*ptr == '\n')
break;
}
*ptr=0; /* zero terminate */
if(data->bits.verbose) {
fputs("< ", data->err);
fwrite(buf, 1, nread, data->err);
fputs("\n", data->err);
}
return nread;
}
#ifndef WIN32 #ifndef WIN32
#ifndef RETSIGTYPE #ifndef RETSIGTYPE
#define RETSIGTYPE void #define RETSIGTYPE void
#endif #endif
static
RETSIGTYPE alarmfunc(int signal) RETSIGTYPE alarmfunc(int signal)
{ {
/* this is for "-ansi -Wall -pedantic" to stop complaining! (rabe) */ /* this is for "-ansi -Wall -pedantic" to stop complaining! (rabe) */
@ -865,9 +826,9 @@ static CURLcode _connect(CURL *curl, CURLconnect **in_connect)
char *proxy=NULL; char *proxy=NULL;
char proxy_env[128]; char proxy_env[128];
no_proxy=GetEnv("no_proxy"); no_proxy=curl_getenv("no_proxy");
if(!no_proxy) if(!no_proxy)
no_proxy=GetEnv("NO_PROXY"); no_proxy=curl_getenv("NO_PROXY");
if(!no_proxy || !strequal("*", no_proxy)) { if(!no_proxy || !strequal("*", no_proxy)) {
/* NO_PROXY wasn't specified or it wasn't just an asterisk */ /* NO_PROXY wasn't specified or it wasn't just an asterisk */
@ -899,22 +860,22 @@ static CURLcode _connect(CURL *curl, CURLconnect **in_connect)
strcpy(envp, "_proxy"); strcpy(envp, "_proxy");
/* read the protocol proxy: */ /* read the protocol proxy: */
prox=GetEnv(proxy_env); prox=curl_getenv(proxy_env);
if(!prox) { if(!prox) {
/* There was no lowercase variable, try the uppercase version: */ /* There was no lowercase variable, try the uppercase version: */
for(envp = proxy_env; *envp; envp++) for(envp = proxy_env; *envp; envp++)
*envp = toupper(*envp); *envp = toupper(*envp);
prox=GetEnv(proxy_env); prox=curl_getenv(proxy_env);
} }
if(prox && *prox) { /* don't count "" strings */ if(prox && *prox) { /* don't count "" strings */
proxy = prox; /* use this */ proxy = prox; /* use this */
} }
else { else {
proxy = GetEnv("all_proxy"); /* default proxy to use */ proxy = curl_getenv("all_proxy"); /* default proxy to use */
if(!proxy) if(!proxy)
proxy=GetEnv("ALL_PROXY"); proxy=curl_getenv("ALL_PROXY");
} }
if(proxy && *proxy) { if(proxy && *proxy) {
@ -935,7 +896,7 @@ static CURLcode _connect(CURL *curl, CURLconnect **in_connect)
*/ */
char *reurl; char *reurl;
reurl = maprintf("%s://%s", conn->proto, data->url); reurl = aprintf("%s://%s", conn->proto, data->url);
if(!reurl) if(!reurl)
return CURLE_OUT_OF_MEMORY; return CURLE_OUT_OF_MEMORY;
@ -984,9 +945,9 @@ static CURLcode _connect(CURL *curl, CURLconnect **in_connect)
data->port = PORT_HTTP; data->port = PORT_HTTP;
data->remote_port = PORT_HTTP; data->remote_port = PORT_HTTP;
conn->protocol |= PROT_HTTP; conn->protocol |= PROT_HTTP;
conn->curl_do = http; conn->curl_do = Curl_http;
conn->curl_done = http_done; conn->curl_done = Curl_http_done;
conn->curl_close = http_close; conn->curl_close = Curl_http_close;
} }
else if (strequal(conn->proto, "HTTPS")) { else if (strequal(conn->proto, "HTTPS")) {
#ifdef USE_SSLEAY #ifdef USE_SSLEAY
@ -996,10 +957,10 @@ static CURLcode _connect(CURL *curl, CURLconnect **in_connect)
conn->protocol |= PROT_HTTP; conn->protocol |= PROT_HTTP;
conn->protocol |= PROT_HTTPS; conn->protocol |= PROT_HTTPS;
conn->curl_do = http; conn->curl_do = Curl_http;
conn->curl_done = http_done; conn->curl_done = Curl_http_done;
conn->curl_connect = http_connect; conn->curl_connect = Curl_http_connect;
conn->curl_close = http_close; conn->curl_close = Curl_http_close;
#else /* USE_SSLEAY */ #else /* USE_SSLEAY */
failf(data, "libcurl was built with SSL disabled, https: not supported!"); failf(data, "libcurl was built with SSL disabled, https: not supported!");
@ -1017,9 +978,9 @@ static CURLcode _connect(CURL *curl, CURLconnect **in_connect)
conn->ppath = conn->path; conn->ppath = conn->path;
} }
conn->protocol |= PROT_GOPHER; conn->protocol |= PROT_GOPHER;
conn->curl_do = http; conn->curl_do = Curl_http;
conn->curl_done = http_done; conn->curl_done = Curl_http_done;
conn->curl_close = http_close; conn->curl_close = Curl_http_close;
} }
else if(strequal(conn->proto, "FTP")) { else if(strequal(conn->proto, "FTP")) {
char *type; char *type;
@ -1032,14 +993,14 @@ static CURLcode _connect(CURL *curl, CURLconnect **in_connect)
!data->bits.tunnel_thru_httpproxy) { !data->bits.tunnel_thru_httpproxy) {
/* Unless we have asked to tunnel ftp operations through the proxy, we /* Unless we have asked to tunnel ftp operations through the proxy, we
switch and use HTTP operations only */ switch and use HTTP operations only */
conn->curl_do = http; conn->curl_do = Curl_http;
conn->curl_done = http_done; conn->curl_done = Curl_http_done;
conn->curl_close = http_close; conn->curl_close = Curl_http_close;
} }
else { else {
conn->curl_do = ftp; conn->curl_do = Curl_ftp;
conn->curl_done = ftp_done; conn->curl_done = Curl_ftp_done;
conn->curl_connect = ftp_connect; conn->curl_connect = Curl_ftp_connect;
} }
conn->ppath++; /* don't include the initial slash */ conn->ppath++; /* don't include the initial slash */
@ -1076,8 +1037,8 @@ static CURLcode _connect(CURL *curl, CURLconnect **in_connect)
data->port = PORT_TELNET; data->port = PORT_TELNET;
data->remote_port = PORT_TELNET; data->remote_port = PORT_TELNET;
conn->curl_do = telnet; conn->curl_do = Curl_telnet;
conn->curl_done = telnet_done; conn->curl_done = Curl_telnet_done;
} }
else if (strequal(conn->proto, "DICT")) { else if (strequal(conn->proto, "DICT")) {
@ -1085,16 +1046,16 @@ static CURLcode _connect(CURL *curl, CURLconnect **in_connect)
if(!data->port) if(!data->port)
data->port = PORT_DICT; data->port = PORT_DICT;
data->remote_port = PORT_DICT; data->remote_port = PORT_DICT;
conn->curl_do = dict; conn->curl_do = Curl_dict;
conn->curl_done = dict_done; conn->curl_done = Curl_dict_done;
} }
else if (strequal(conn->proto, "LDAP")) { else if (strequal(conn->proto, "LDAP")) {
conn->protocol |= PROT_LDAP; conn->protocol |= PROT_LDAP;
if(!data->port) if(!data->port)
data->port = PORT_LDAP; data->port = PORT_LDAP;
data->remote_port = PORT_LDAP; data->remote_port = PORT_LDAP;
conn->curl_do = ldap; conn->curl_do = Curl_ldap;
conn->curl_done = ldap_done; conn->curl_done = Curl_ldap_done;
} }
else if (strequal(conn->proto, "FILE")) { else if (strequal(conn->proto, "FILE")) {
conn->protocol |= PROT_FILE; conn->protocol |= PROT_FILE;
@ -1114,7 +1075,7 @@ static CURLcode _connect(CURL *curl, CURLconnect **in_connect)
} }
if(data->bits.use_netrc) { if(data->bits.use_netrc) {
if(ParseNetrc(data->hostname, data->user, data->passwd)) { if(Curl_parsenetrc(data->hostname, data->user, data->passwd)) {
infof(data, "Couldn't find host %s in the .netrc file, using defaults", infof(data, "Couldn't find host %s in the .netrc file, using defaults",
data->hostname); data->hostname);
} }
@ -1196,7 +1157,7 @@ static CURLcode _connect(CURL *curl, CURLconnect **in_connect)
data->remote_port = data->port; /* it is the same port */ data->remote_port = data->port; /* it is the same port */
/* Connect to target host right on */ /* Connect to target host right on */
conn->hp = GetHost(data, conn->name, &conn->hostent_buf); conn->hp = Curl_gethost(data, conn->name, &conn->hostent_buf);
if(!conn->hp) { if(!conn->hp) {
failf(data, "Couldn't resolve host '%s'", conn->name); failf(data, "Couldn't resolve host '%s'", conn->name);
return CURLE_COULDNT_RESOLVE_HOST; return CURLE_COULDNT_RESOLVE_HOST;
@ -1252,7 +1213,7 @@ static CURLcode _connect(CURL *curl, CURLconnect **in_connect)
} }
/* connect to proxy */ /* connect to proxy */
conn->hp = GetHost(data, proxyptr, &conn->hostent_buf); conn->hp = Curl_gethost(data, proxyptr, &conn->hostent_buf);
if(!conn->hp) { if(!conn->hp) {
failf(data, "Couldn't resolve proxy '%s'", proxyptr); failf(data, "Couldn't resolve proxy '%s'", proxyptr);
return CURLE_COULDNT_RESOLVE_PROXY; return CURLE_COULDNT_RESOLVE_PROXY;
@ -1260,7 +1221,7 @@ static CURLcode _connect(CURL *curl, CURLconnect **in_connect)
free(proxydup); /* free the duplicate pointer and not the modified */ free(proxydup); /* free the duplicate pointer and not the modified */
} }
pgrsTime(data, TIMER_NAMELOOKUP); Curl_pgrsTime(data, TIMER_NAMELOOKUP);
data->firstsocket = socket(AF_INET, SOCK_STREAM, 0); data->firstsocket = socket(AF_INET, SOCK_STREAM, 0);
@ -1292,12 +1253,12 @@ static CURLcode _connect(CURL *curl, CURLconnect **in_connect)
char myhost[256] = ""; char myhost[256] = "";
unsigned long in; unsigned long in;
if(if2ip(data->device, myhost, sizeof(myhost))) { if(Curl_if2ip(data->device, myhost, sizeof(myhost))) {
h = GetHost(data, myhost, &hostdataptr); h = Curl_gethost(data, myhost, &hostdataptr);
} }
else { else {
if(strlen(data->device)>1) { if(strlen(data->device)>1) {
h = GetHost(data, data->device, &hostdataptr); h = Curl_gethost(data, data->device, &hostdataptr);
} }
if(h) { if(h) {
/* we know data->device is shorter than the myhost array */ /* we know data->device is shorter than the myhost array */
@ -1307,7 +1268,7 @@ static CURLcode _connect(CURL *curl, CURLconnect **in_connect)
if(! *myhost) { if(! *myhost) {
/* need to fix this /* need to fix this
h=GetHost(data, h=Curl_gethost(data,
getmyhost(*myhost,sizeof(myhost)), getmyhost(*myhost,sizeof(myhost)),
hostent_buf, hostent_buf,
sizeof(hostent_buf)); sizeof(hostent_buf));
@ -1384,7 +1345,7 @@ static CURLcode _connect(CURL *curl, CURLconnect **in_connect)
} }
if(hostdataptr) if(hostdataptr)
free(hostdataptr); /* allocated by GetHost() */ free(hostdataptr); /* allocated by Curl_gethost() */
} /* end of device selection support */ } /* end of device selection support */
#endif /* end of HAVE_INET_NTOA */ #endif /* end of HAVE_INET_NTOA */
@ -1443,32 +1404,35 @@ static CURLcode _connect(CURL *curl, CURLconnect **in_connect)
char *authorization; char *authorization;
snprintf(data->buffer, BUFSIZE, "%s:%s", snprintf(data->buffer, BUFSIZE, "%s:%s",
data->proxyuser, data->proxypasswd); data->proxyuser, data->proxypasswd);
if(base64_encode(data->buffer, strlen(data->buffer), if(Curl_base64_encode(data->buffer, strlen(data->buffer),
&authorization) >= 0) { &authorization) >= 0) {
data->ptr_proxyuserpwd = data->ptr_proxyuserpwd =
maprintf("Proxy-authorization: Basic %s\015\012", authorization); aprintf("Proxy-authorization: Basic %s\015\012", authorization);
free(authorization); free(authorization);
} }
} }
if((conn->protocol&PROT_HTTP) || data->bits.httpproxy) { if((conn->protocol&PROT_HTTP) || data->bits.httpproxy) {
if(data->useragent) { if(data->useragent) {
data->ptr_uagent = maprintf("User-Agent: %s\015\012", data->useragent); data->ptr_uagent =
aprintf("User-Agent: %s\015\012", data->useragent);
} }
} }
if(conn->curl_connect) { if(conn->curl_connect) {
/* is there a connect() procedure? */ /* is there a connect() procedure? */
conn->now = tvnow(); /* set this here for timeout purposes in the
connect procedure, it is later set again for the /* set start time here for timeout purposes in the
progress meter purpose */ connect procedure, it is later set again for the
progress meter purpose */
conn->now = Curl_tvnow();
result = conn->curl_connect(conn); result = conn->curl_connect(conn);
if(result != CURLE_OK) if(result != CURLE_OK)
return result; /* pass back errors */ return result; /* pass back errors */
} }
pgrsTime(data, TIMER_CONNECT); /* we're connected */ Curl_pgrsTime(data, TIMER_CONNECT); /* we're connected */
conn->now = tvnow(); /* time this *after* the connect is done */ conn->now = Curl_tvnow(); /* time this *after* the connect is done */
conn->bytecount = 0; conn->bytecount = 0;
/* Figure out the ip-number and the first host name it shows: */ /* Figure out the ip-number and the first host name it shows: */
@ -1560,7 +1524,7 @@ CURLcode curl_done(CURLconnect *c_connect)
else else
result = CURLE_OK; result = CURLE_OK;
pgrsDone(data); /* done with the operation */ Curl_pgrsDone(data); /* done with the operation */
conn->state = CONN_DONE; conn->state = CONN_DONE;

View File

@ -22,6 +22,7 @@
* *
* $Id$ * $Id$
*****************************************************************************/ *****************************************************************************/
int GetLine(int sockfd, char *buf, struct UrlData *data);
/* empty */
#endif #endif

View File

@ -33,9 +33,6 @@ char *curl_version(void)
{ {
static char version[200]; static char version[200];
char *ptr; char *ptr;
#if defined(USE_SSLEAY)
static char sub[2];
#endif
strcpy(version, LIBCURL_NAME " " LIBCURL_VERSION ); strcpy(version, LIBCURL_NAME " " LIBCURL_VERSION );
ptr=strchr(version, '\0'); ptr=strchr(version, '\0');
@ -47,17 +44,19 @@ char *curl_version(void)
(SSLEAY_VERSION_NUMBER>>20)&0xff, (SSLEAY_VERSION_NUMBER>>20)&0xff,
(SSLEAY_VERSION_NUMBER>>12)&0xf); (SSLEAY_VERSION_NUMBER>>12)&0xf);
#else #else
if(SSLEAY_VERSION_NUMBER&0x0f) { {
sub[0]=(SSLEAY_VERSION_NUMBER&0x0f) + 'a' -1; char sub[2];
if(SSLEAY_VERSION_NUMBER&0x0f) {
sub[0]=(SSLEAY_VERSION_NUMBER&0x0f) + 'a' -1;
}
else
sub[0]=0;
sprintf(ptr, " (SSL %x.%x.%x%s)",
(SSLEAY_VERSION_NUMBER>>12)&0xff,
(SSLEAY_VERSION_NUMBER>>8)&0xf,
(SSLEAY_VERSION_NUMBER>>4)&0xf, sub);
} }
else
sub[0]=0;
sprintf(ptr, " (SSL %x.%x.%x%s)",
(SSLEAY_VERSION_NUMBER>>12)&0xff,
(SSLEAY_VERSION_NUMBER>>8)&0xf,
(SSLEAY_VERSION_NUMBER>>4)&0xf, sub);
#endif #endif
ptr=strchr(ptr, '\0'); ptr=strchr(ptr, '\0');
#endif #endif

View File

@ -690,7 +690,7 @@ static ParameterError getparameter(char *flag, /* f or -long-flag */
/* we already have a string, we append this one /* we already have a string, we append this one
with a separating &-letter */ with a separating &-letter */
char *oldpost=config->postfields; char *oldpost=config->postfields;
config->postfields=maprintf("%s&%s", oldpost, postdata); config->postfields=aprintf("%s&%s", oldpost, postdata);
free(oldpost); free(oldpost);
free(postdata); free(postdata);
} }