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
CURLE_HTTP_PORT_FAILED, /* HTTP Interface operation failed */
+ CURLE_BAD_PASSWORD_ENTERED, /* when the my_getpass() returns fail */
+
CURL_LAST
} CURLcode;
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;
# 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;
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);
/* if user didn't hit ENTER, terminate buffer */
if (i==buflen)
buffer[buflen-1]=0;
+
+ return 0; /* we always return success */
}
#endif
-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
/* 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 */
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;
/* 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;
}
}
/* 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;
}
}
/* 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! */
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 */