diff options
author | Daniel Stenberg <daniel@haxx.se> | 2000-11-06 22:53:50 +0000 |
---|---|---|
committer | Daniel Stenberg <daniel@haxx.se> | 2000-11-06 22:53:50 +0000 |
commit | 9f4f16b55d7df262774aee227933347e0ae3846e (patch) | |
tree | 26ebae60a02e272ec1fb8d2ead8dfc7559372fd5 /lib | |
parent | e05922c4285bf72b2246c9909703c7411f98163b (diff) |
new getpass proto and function pointer usage
Diffstat (limited to 'lib')
-rw-r--r-- | lib/getpass.c | 7 | ||||
-rw-r--r-- | lib/getpass.h | 9 | ||||
-rw-r--r-- | lib/url.c | 28 | ||||
-rw-r--r-- | lib/urldata.h | 4 |
4 files changed, 40 insertions, 8 deletions
diff --git a/lib/getpass.c b/lib/getpass.c index 9dd08132a..d18f6d79f 100644 --- a/lib/getpass.c +++ b/lib/getpass.c @@ -68,7 +68,7 @@ # define perror(x) fprintf(stderr, "Error in: %s\n", x) #endif -void my_getpass(const char *prompt, char *buffer, int buflen) +int my_getpass(void *client, const char *prompt, char *buffer, int buflen) { FILE *infp; FILE *outfp; @@ -176,11 +176,12 @@ void my_getpass(const char *prompt, char *buffer, int buflen) signal(SIGTSTP, sigtstp); #endif + return 0; /* we always return success */ } #else /* WIN32 */ #include <stdio.h> #include <conio.h> -void my_getpass(const char *prompt, char *buffer, int buflen) +int my_getpass(void *client, const char *prompt, char *buffer, int buflen) { int i; printf("%s", prompt); @@ -195,6 +196,8 @@ void my_getpass(const char *prompt, char *buffer, int buflen) /* if user didn't hit ENTER, terminate buffer */ if (i==buflen) buffer[buflen-1]=0; + + return 0; /* we always return success */ } #endif diff --git a/lib/getpass.h b/lib/getpass.h index 91abe2214..1248030ee 100644 --- a/lib/getpass.h +++ b/lib/getpass.h @@ -1 +1,8 @@ -void my_getpass(const char *prompt, char* buffer, int buflen ); +#ifndef __GETPASS_H +#define __GETPASS_H +/* + * Returning non-zero will abort the continued operation! + */ +int my_getpass(void *client, char *prompt, char* buffer, int buflen ); + +#endif @@ -306,6 +306,9 @@ CURLcode curl_open(CURL **curl, char *url) /* use fread as default function to read input */ data->fread = (size_t (*)(char *, size_t, size_t, FILE *))fread; + /* set the default passwd function */ + data->fpasswd = my_getpass; + data->infilesize = -1; /* we don't know any size */ data->current_speed = -1; /* init to negative == impossible */ @@ -479,6 +482,12 @@ CURLcode curl_setopt(CURL *curl, CURLoption option, ...) case CURLOPT_PROGRESSDATA: data->progress_client = va_arg(param, void *); break; + case CURLOPT_PASSWDFUNCTION: + data->fpasswd = va_arg(param, curl_passwd_callback); + break; + case CURLOPT_PASSWDDATA: + data->passwd_client = va_arg(param, void *); + break; case CURLOPT_PROXYUSERPWD: data->proxyuserpwd = va_arg(param, char *); data->bits.proxy_user_passwd = data->proxyuserpwd?1:0; @@ -809,7 +818,10 @@ CURLcode curl_connect(CURL *curl, CURLconnect **in_connect) /* check for password, if no ask for one */ if( !data->passwd[0] ) { - my_getpass("password:", data->passwd, sizeof(data->passwd)); + if(!data->fpasswd || + data->fpasswd(data->passwd_client, + "password:", data->passwd, sizeof(data->passwd))) + return CURLE_BAD_PASSWORD_ENTERED; } } @@ -828,9 +840,12 @@ CURLcode curl_connect(CURL *curl, CURLconnect **in_connect) /* check for password, if no ask for one */ if( !data->proxypasswd[0] ) { - my_getpass("proxy password:", - data->proxypasswd, - sizeof(data->proxypasswd)); + if(!data->fpasswd || + data->fpasswd( data->passwd_client, + "proxy password:", + data->proxypasswd, + sizeof(data->proxypasswd))) + return CURLE_BAD_PASSWORD_ENTERED; } } @@ -1149,7 +1164,10 @@ CURLcode curl_connect(CURL *curl, CURLconnect **in_connect) /* check for password, if no ask for one */ if( !data->passwd[0] ) { - my_getpass("password:",data->passwd,sizeof(data->passwd)); + if(!data->fpasswd || + data->fpasswd(data->passwd_client, + "password:",data->passwd,sizeof(data->passwd))) + return CURLE_BAD_PASSWORD_ENTERED; } else { /* we have a password found in the URL, decode it! */ diff --git a/lib/urldata.h b/lib/urldata.h index 857e5e93f..5f5bb7b95 100644 --- a/lib/urldata.h +++ b/lib/urldata.h @@ -435,6 +435,10 @@ struct UrlData { curl_progress_callback fprogress; void *progress_client; /* pointer to pass to the progress callback */ + /* function to call instead of the internal for password */ + curl_passwd_callback fpasswd; + void *passwd_client; /* pointer to pass to the passwd callback */ + long timeout; /* in seconds, 0 means no timeout */ long infilesize; /* size of file to upload, -1 means unknown */ |