11use cups_rs:: {
2- auth:: { set_password_callback, get_password, do_authentication} ,
3- get_destination, create_job, Result ,
2+ Result ,
3+ auth:: { do_authentication, get_password, set_password_callback} ,
4+ create_job, get_destination,
45} ;
56use std:: io:: { self , Write } ;
67
@@ -14,14 +15,14 @@ fn main() -> Result<()> {
1415 println ! ( "Prompt: {}" , prompt) ;
1516 println ! ( "Method: {}" , method) ;
1617 println ! ( "Resource: {}" , resource) ;
17-
18+
1819 print ! ( "Enter password (or 'q' to quit): " ) ;
1920 io:: stdout ( ) . flush ( ) . unwrap ( ) ;
20-
21+
2122 let mut input = String :: new ( ) ;
2223 io:: stdin ( ) . read_line ( & mut input) . unwrap ( ) ;
2324 let input = input. trim ( ) ;
24-
25+
2526 if input == "q" || input. is_empty ( ) {
2627 println ! ( "Authentication cancelled" ) ;
2728 None
@@ -38,16 +39,14 @@ fn main() -> Result<()> {
3839 }
3940
4041 // Try to access a printer that might require authentication
41- let printer_name = std:: env:: args ( )
42- . nth ( 1 )
43- . unwrap_or_else ( || "PDF" . to_string ( ) ) ;
42+ let printer_name = std:: env:: args ( ) . nth ( 1 ) . unwrap_or_else ( || "PDF" . to_string ( ) ) ;
4443
4544 println ! ( "\n Trying to access printer: {}" , printer_name) ;
46-
45+
4746 match get_destination ( & printer_name) {
4847 Ok ( destination) => {
4948 println ! ( "Successfully connected to: {}" , destination. full_name( ) ) ;
50-
49+
5150 // Try to create a job (this might trigger authentication)
5251 println ! ( "Attempting to create a job..." ) ;
5352 match create_job ( & destination, "Authentication test job" ) {
@@ -56,7 +55,7 @@ fn main() -> Result<()> {
5655 }
5756 Err ( e) => {
5857 println ! ( "Job creation failed: {}" , e) ;
59-
58+
6059 // Try manual authentication
6160 println ! ( "Attempting manual authentication..." ) ;
6261 match do_authentication ( None , "POST" , "/" ) {
@@ -74,12 +73,12 @@ fn main() -> Result<()> {
7473 // Test removing the callback
7574 println ! ( "\n Removing password callback..." ) ;
7675 set_password_callback ( None ) ?;
77-
76+
7877 match get_password ( "Test prompt after removal:" , None , "GET" , "/test" ) {
7978 Some ( password) => println ! ( "Unexpected password: {}" , password) ,
8079 None => println ! ( "Callback correctly removed - no password provided" ) ,
8180 }
8281
8382 println ! ( "\n Authentication example completed!" ) ;
8483 Ok ( ( ) )
85- }
84+ }
0 commit comments