Index: cups/auth.c =================================================================== --- cups/auth.c (revision 8566) +++ cups/auth.c (working copy) @@ -83,10 +83,10 @@ */ int /* O - 0 on success, -1 on error */ -cupsDoAuthentication(http_t *http, /* I - Connection to server or @code CUPS_HTTP_DEFAULT@ */ - const char *method,/* I - Request method ("GET", "POST", "PUT") */ - const char *resource) - /* I - Resource path */ +cupsDoAuthentication( + http_t *http, /* I - Connection to server or @code CUPS_HTTP_DEFAULT@ */ + const char *method, /* I - Request method ("GET", "POST", "PUT") */ + const char *resource) /* I - Resource path */ { const char *password; /* Password string */ char prompt[1024], /* Prompt for user */ @@ -103,6 +103,12 @@ DEBUG_printf(("2cupsDoAuthentication: WWW-Authenticate=\"%s\"", httpGetField(http, HTTP_FIELD_WWW_AUTHENTICATE))); + if (!http) + http = _cupsConnect(); + + if (!http || !method || !resource) + return (-1); + /* * Clear the current authentication string... */ @@ -154,7 +160,7 @@ "Digest", 5) != 0; http->userpass[0] = '\0'; - if ((password = cupsGetPassword(prompt)) == NULL) + if ((password = cupsGetPassword2(prompt, http, method, resource)) == NULL) return (-1); if (!password[0]) Index: cups/usersys.c =================================================================== --- cups/usersys.c (revision 8566) +++ cups/usersys.c (working copy) @@ -23,6 +23,7 @@ * server. * cupsSetEncryption() - Set the encryption preference. * cupsSetPasswordCB() - Set the password callback for CUPS. + * cupsSetPasswordCB2() - Set the advanced password callback for CUPS. * cupsSetServer() - Set the default server name. * cupsSetUser() - Set the default user name. * cupsUser() - Return the current user's name. @@ -87,11 +88,40 @@ const char * /* O - Password */ cupsGetPassword(const char *prompt) /* I - Prompt string */ { - return ((*_cupsGlobals()->password_cb)(prompt)); + _cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */ + + + return ((cg->password_cb)(prompt, NULL, NULL, NULL, cg->password_data)); } /* + * 'cupsGetPassword2()' - Get a password from the user using the advanced + * callback. + * + * Uses the current password callback function. Returns @code NULL@ if the + * user does not provide a password. + * + * @since CUPS 1.4@ + */ + +const char * /* O - Password */ +cupsGetPassword2(const char *prompt, /* I - Prompt string */ + http_t *http, /* I - Connection to server or @code CUPS_HTTP_DEFAULT@ */ + const char *method, /* I - Request method ("GET", "POST", "PUT") */ + const char *resource) /* I - Resource path */ +{ + _cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */ + + + if (!http) + http = _cupsConnect(); + + return ((cg->password_cb)(prompt, http, method, resource, cg->password_data)); +} + + +/* * 'cupsServer()' - Return the hostname/address of the default server. * * The returned value can be a fully-qualified hostname, a numeric @@ -140,10 +170,37 @@ _cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */ - if (cb == (const char *(*)(const char *))0) - cg->password_cb = _cupsGetPassword; + if (cb == (cups_password_cb_t)0) + cg->password_cb = (cups_password_cb2_t)_cupsGetPassword; else + cg->password_cb = (cups_password_cb2_t)cb; + + cg->password_data = NULL; +} + + +/* + * 'cupsSetPasswordCB2()' - Set the advanced password callback for CUPS. + * + * Pass @code NULL@ to restore the default (console) password callback. + * + * @since CUPS 1.4@ + */ + +void +cupsSetPasswordCB2( + cups_password_cb2_t cb, /* I - Callback function */ + void *user_data) /* I - User data pointer */ +{ + _cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */ + + + if (cb == (cups_password_cb2_t)0) + cg->password_cb = (cups_password_cb2_t)_cupsGetPassword; + else cg->password_cb = cb; + + cg->password_data = user_data; } Index: cups/cups.h =================================================================== --- cups/cups.h (revision 8566) +++ cups/cups.h (working copy) @@ -125,6 +125,12 @@ typedef const char *(*cups_password_cb_t)(const char *prompt); /**** Password callback ****/ +typedef const char *(*cups_password_cb2_t)(const char *prompt, http_t *http, + const char *method, + const char *resource, + void *user_data); + /**** New password callback @since CUPS 1.4@ ****/ + typedef void (*cups_device_cb_t)(const char *device_class, const char *device_id, const char *device_info, const char *device_make_and_model, @@ -294,6 +300,9 @@ void *user_data) _CUPS_API_1_4; extern cups_dest_t *cupsGetNamedDest(http_t *http, const char *name, const char *instance) _CUPS_API_1_4; +extern const char *cupsGetPassword2(const char *prompt, http_t *http, + const char *method, + const char *resource) _CUPS_API_1_4; extern http_status_t cupsGetPPD3(http_t *http, const char *name, time_t *modtime, char *buffer, size_t bufsize) _CUPS_API_1_4; @@ -309,6 +318,8 @@ extern http_status_t cupsSendRequest(http_t *http, ipp_t *request, const char *resource, size_t length) _CUPS_API_1_4; +extern void cupsSetPasswordCB2(cups_password_cb2_t cb, + void *user_data) _CUPS_API_1_4; extern http_status_t cupsStartDocument(http_t *http, const char *name, int job_id, const char *docname, const char *format, Index: cups/globals.c =================================================================== --- cups/globals.c (revision 8566) +++ cups/globals.c (working copy) @@ -112,7 +112,7 @@ */ globals->encryption = (http_encryption_t)-1; - globals->password_cb = _cupsGetPassword; + globals->password_cb = (cups_password_cb2_t)_cupsGetPassword; cups_env_init(globals); } Index: cups/globals.h =================================================================== --- cups/globals.h (revision 8566) +++ cups/globals.h (working copy) @@ -120,7 +120,8 @@ char user[65], /* User name */ server[256], /* Server address */ servername[256];/* Server hostname */ - cups_password_cb_t password_cb; /* Password callback */ + cups_password_cb2_t password_cb; /* Password callback */ + void *password_data; /* Password user data */ /* util.c */ http_t *http; /* Current server connection */