2 Copyright (C) 2004-2005 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>
28 @interface NGXmlRpcClient(CallFailed)
29 - (id)callFailed:(WOResponse *)_response;
30 @end /* NGXmlRpcClient */
32 @implementation HandleCredentialsClient
35 [self->defLogin release];
36 [self->defPassword release];
42 - (void)setDefLogin:(NSString *)_login {
43 ASSIGNCOPY(self->defLogin, _login);
45 - (void)setDefPassword:(NSString *)_pwd {
46 ASSIGNCOPY(self->defPassword, _pwd);
51 - (NSString *)prompt:(NSString *)_prompt {
55 fprintf(stderr, "%s", [_prompt cString]);
57 fgets(clogin, 200, stdin);
58 clogin[strlen(clogin) - 1] = '\0';
59 login = [NSString stringWithCString:clogin];
63 - (NSString *)promptPassword:(NSString *)_prompt {
67 cpwd = getpass("password: ");
68 pwd = [NSString stringWithCString:cpwd];
72 - (id)callFailed:(WOResponse *)_response {
73 if ([_response status] == 401) {
78 wwwauth = [_response headerForKey:@"www-authenticate"];
79 if ([[wwwauth lowercaseString] hasPrefix:@"digest"])
80 [self logWithFormat:@"Digest authentication:\n'%@'", wwwauth];
82 // TODO: test credentials of URL
85 user = [self->defLogin autorelease];
89 user = [self prompt:@"login: "];
91 if (self->defPassword) {
92 pass = [self->defPassword autorelease];
93 self->defPassword = nil;
96 pass = [self promptPassword:@"password: "];
98 [self setUserName:user];
99 [self setPassword:pass];
101 /* this "should" return some kind of "need-pwd" object ... */
105 return [super callFailed:_response];
109 @end /* HandleCredentialsClient */