mirror of
https://github.com/moparisthebest/curl
synced 2024-12-21 23:58:49 -05:00
new getpass proto and function pointer usage
This commit is contained in:
parent
e05922c428
commit
9f4f16b55d
@ -99,7 +99,12 @@ typedef size_t (*curl_read_callback)(char *buffer,
|
||||
size_t nitems,
|
||||
FILE *instream);
|
||||
|
||||
/* All possible error codes from this version of urlget(). Future versions
|
||||
typedef int (*curl_passwd_callback)(void *clientp,
|
||||
char *prompt,
|
||||
char *buffer,
|
||||
int buflen);
|
||||
|
||||
/* All possible error codes from all sorts of curl functions. Future versions
|
||||
may return other values, stay prepared.
|
||||
|
||||
Always add new return codes last. Never *EVER* remove any. The return
|
||||
@ -166,6 +171,8 @@ typedef enum {
|
||||
|
||||
CURLE_HTTP_PORT_FAILED, /* HTTP Interface operation failed */
|
||||
|
||||
CURLE_BAD_PASSWORD_ENTERED, /* when the my_getpass() returns fail */
|
||||
|
||||
CURL_LAST
|
||||
} CURLcode;
|
||||
|
||||
@ -404,6 +411,13 @@ typedef enum {
|
||||
this option is used only if SSL_VERIFYPEER is true */
|
||||
CINIT(CAINFO, OBJECTPOINT, 65),
|
||||
|
||||
/* Function pointer to replace the internal password prompt */
|
||||
CINIT(PASSWDFUNCTION, FUNCTIONPOINT, 66),
|
||||
|
||||
/* Custom pointer that gets passed as first argument to the password
|
||||
function */
|
||||
CINIT(PASSWDDATA, OBJECTPOINT, 67),
|
||||
|
||||
CURLOPT_LASTENTRY /* the last unusued */
|
||||
} CURLoption;
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
26
lib/url.c
26
lib/url.c
@ -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:",
|
||||
if(!data->fpasswd ||
|
||||
data->fpasswd( data->passwd_client,
|
||||
"proxy password:",
|
||||
data->proxypasswd,
|
||||
sizeof(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! */
|
||||
|
@ -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 */
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user