aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2000-11-06 22:53:50 +0000
committerDaniel Stenberg <daniel@haxx.se>2000-11-06 22:53:50 +0000
commit9f4f16b55d7df262774aee227933347e0ae3846e (patch)
tree26ebae60a02e272ec1fb8d2ead8dfc7559372fd5
parente05922c4285bf72b2246c9909703c7411f98163b (diff)
new getpass proto and function pointer usage
-rw-r--r--include/curl/curl.h16
-rw-r--r--lib/getpass.c7
-rw-r--r--lib/getpass.h9
-rw-r--r--lib/url.c28
-rw-r--r--lib/urldata.h4
5 files changed, 55 insertions, 9 deletions
diff --git a/include/curl/curl.h b/include/curl/curl.h
index 4a1245e58..f0a17011a 100644
--- a/include/curl/curl.h
+++ b/include/curl/curl.h
@@ -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;
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
diff --git a/lib/url.c b/lib/url.c
index 590348029..d1613ebd6 100644
--- a/lib/url.c
+++ b/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:",
- 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 */