2 Copyright (C) 2004 Helge Hess
4 This file is part of SOPE.
6 SOPE is free software; you can redistribute it and/or modify it under
7 the terms of the GNU Lesser General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
11 SOPE is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14 License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with SOPE; see the file COPYING. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
22 #include "HandleCredentialsClient.h"
23 #include <NGObjWeb/WOResponse.h>
27 @interface NGXmlRpcClient(CallFailed)
28 - (id)callFailed:(WOResponse *)_response;
29 @end /* NGXmlRpcClient */
31 @implementation HandleCredentialsClient
34 [self->defLogin release];
35 [self->defPassword release];
41 - (void)setDefLogin:(NSString *)_login {
42 ASSIGNCOPY(self->defLogin, _login);
44 - (void)setDefPassword:(NSString *)_pwd {
45 ASSIGNCOPY(self->defPassword, _pwd);
50 - (NSString *)prompt:(NSString *)_prompt {
54 fprintf(stderr, "%s", [_prompt cString]);
56 fgets(clogin, 200, stdin);
57 clogin[strlen(clogin) - 1] = '\0';
58 login = [NSString stringWithCString:clogin];
62 - (NSString *)promptPassword:(NSString *)_prompt {
66 cpwd = getpass("password: ");
67 pwd = [NSString stringWithCString:cpwd];
71 - (id)callFailed:(WOResponse *)_response {
72 if ([_response status] == 401) {
77 wwwauth = [_response headerForKey:@"www-authenticate"];
78 if ([[wwwauth lowercaseString] hasPrefix:@"digest"])
79 [self logWithFormat:@"Digest authentication:\n'%@'", wwwauth];
81 // TODO: test credentials of URL
84 user = [self->defLogin autorelease];
88 user = [self prompt:@"login: "];
90 if (self->defPassword) {
91 pass = [self->defPassword autorelease];
92 self->defPassword = nil;
95 pass = [self promptPassword:@"password: "];
97 [self setUserName:user];
98 [self setPassword:pass];
100 /* this "should" return some kind of "need-pwd" object ... */
104 return [super callFailed:_response];
108 @end /* HandleCredentialsClient */