mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-23 09:04:13 +00:00
pick the debug mode from environment
This commit is contained in:
parent
1cf39479b6
commit
d498642de5
10 changed files with 45 additions and 124 deletions
|
@ -246,10 +246,7 @@ static NSMapTable *_flagMap = nil;
|
|||
NSData *content = [request convertToData];
|
||||
|
||||
[self setFlags: SENTREQUEST];
|
||||
if (YES == _debug)
|
||||
{
|
||||
NSLog(@"%@: set SENTREQUEST (-[%@])", self, NSStringFromSelector(_cmd));
|
||||
}
|
||||
NSDebugLog(@"%@: set SENTREQUEST (-[%@])", self, NSStringFromSelector(_cmd));
|
||||
|
||||
// TODO: more comparisons of _request and request
|
||||
if ([method isEqualToString: @"POST"] ||
|
||||
|
@ -258,19 +255,13 @@ static NSMapTable *_flagMap = nil;
|
|||
if ([content isEqualToData: [_request HTTPBody]])
|
||||
{
|
||||
[self setFlags: GOTREQUEST];
|
||||
if (YES == _debug)
|
||||
{
|
||||
NSLog(@"%@: set GOTREQUEST (-[%@])", self, NSStringFromSelector(_cmd));
|
||||
}
|
||||
NSDebugLog(@"%@: set GOTREQUEST (-[%@])", self, NSStringFromSelector(_cmd));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
[self setFlags: GOTREQUEST];
|
||||
if (YES == _debug)
|
||||
{
|
||||
NSLog(@"%@: set GOTREQUEST (-[%@])", self, NSStringFromSelector(_cmd));
|
||||
}
|
||||
NSDebugLog(@"%@: set GOTREQUEST (-[%@])", self, NSStringFromSelector(_cmd));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -279,10 +270,7 @@ willSendUnauthorized:(GSMimeDocument *)response
|
|||
with:(TestWebServer *)server
|
||||
{
|
||||
[self setFlags: NOTAUTHORIZED];
|
||||
if (YES == _debug)
|
||||
{
|
||||
NSLog(@"%@: set NOTAUTHORIZED (-[%@])", self, NSStringFromSelector(_cmd));
|
||||
}
|
||||
NSDebugLog(@"%@: set NOTAUTHORIZED (-[%@])", self, NSStringFromSelector(_cmd));
|
||||
}
|
||||
|
||||
- (void)handler:(id)handler
|
||||
|
@ -290,10 +278,7 @@ willSendUnauthorized:(GSMimeDocument *)response
|
|||
with:(TestWebServer *)server
|
||||
{
|
||||
[self setFlags: AUTHORIZED];
|
||||
if (YES == _debug)
|
||||
{
|
||||
NSLog(@"%@: set AUTHORIZED (-[%@])", self, NSStringFromSelector(_cmd));
|
||||
}
|
||||
NSDebugLog(@"%@: set AUTHORIZED (-[%@])", self, NSStringFromSelector(_cmd));
|
||||
}
|
||||
|
||||
- (void)handler:(id)handler
|
||||
|
@ -301,10 +286,7 @@ willSendUnauthorized:(GSMimeDocument *)response
|
|||
with:(TestWebServer *)server
|
||||
{
|
||||
[self setFlags: SENTRESPONSE];
|
||||
if (YES == _debug)
|
||||
{
|
||||
NSLog(@"%@: set SENTRESPONSE (-[%@])", self, NSStringFromSelector(_cmd));
|
||||
}
|
||||
NSDebugLog(@"%@: set SENTRESPONSE (-[%@])", self, NSStringFromSelector(_cmd));
|
||||
}
|
||||
|
||||
- (void)timeoutExceededByHandler:(id)handler
|
||||
|
@ -323,19 +305,13 @@ willSendUnauthorized:(GSMimeDocument *)response
|
|||
if ([(NSHTTPURLResponse *)redirectResponse statusCode] == _redirectStatusCode)
|
||||
{
|
||||
[self setFlags: GOTREDIRECT];
|
||||
if (YES == _debug)
|
||||
{
|
||||
NSLog(@"%@: set GOTREDIRECT (-[%@])", self, NSStringFromSelector(_cmd));
|
||||
}
|
||||
NSDebugLog(@"%@: set GOTREDIRECT (-[%@])", self, NSStringFromSelector(_cmd));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
[self setFlags: GOTREDIRECT];
|
||||
if (YES == _debug)
|
||||
{
|
||||
NSLog(@"%@: set GOTREDIRECT (-[%@])", self, NSStringFromSelector(_cmd));
|
||||
}
|
||||
NSDebugLog(@"%@: set GOTREDIRECT (-[%@])", self, NSStringFromSelector(_cmd));
|
||||
}
|
||||
|
||||
return _redirectRequest;
|
||||
|
@ -345,10 +321,7 @@ willSendUnauthorized:(GSMimeDocument *)response
|
|||
didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
|
||||
{
|
||||
[self setFlags: GOTUNAUTHORIZED];
|
||||
if (YES == _debug)
|
||||
{
|
||||
NSLog(@"%@: set GOTUNAUTHORIZED (-[%@])", self, NSStringFromSelector(_cmd));
|
||||
}
|
||||
NSDebugLog(@"%@: set GOTUNAUTHORIZED (-[%@])", self, NSStringFromSelector(_cmd));
|
||||
|
||||
if ([challenge previousFailureCount] == 0)
|
||||
{
|
||||
|
@ -401,19 +374,13 @@ didReceiveResponse:(NSURLResponse *)response
|
|||
if ([(NSHTTPURLResponse *)response statusCode] == _expectedStatusCode)
|
||||
{
|
||||
[self setFlags: GOTRESPONSE];
|
||||
if (YES == _debug)
|
||||
{
|
||||
NSLog(@"%@: set GOTRESPONSE (-[%@])", self, NSStringFromSelector(_cmd));
|
||||
}
|
||||
NSDebugLog(@"%@: set GOTRESPONSE (-[%@])", self, NSStringFromSelector(_cmd));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
[self setFlags: GOTRESPONSE];
|
||||
if (YES == _debug)
|
||||
{
|
||||
NSLog(@"%@: set GOTRESPONSE (-[%@])", self, NSStringFromSelector(_cmd));
|
||||
}
|
||||
NSDebugLog(@"%@: set GOTRESPONSE (-[%@])", self, NSStringFromSelector(_cmd));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -421,10 +388,7 @@ didReceiveResponse:(NSURLResponse *)response
|
|||
didReceiveData:(NSData *)data
|
||||
{
|
||||
[_received appendData: data];
|
||||
if (YES == _debug)
|
||||
{
|
||||
NSLog(@"%@: received data '%@' (-[%@])", self, data, NSStringFromSelector(_cmd));
|
||||
}
|
||||
NSDebugLog(@"%@: received data '%@' (-[%@])", self, data, NSStringFromSelector(_cmd));
|
||||
}
|
||||
|
||||
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
|
||||
|
@ -433,17 +397,11 @@ didReceiveResponse:(NSURLResponse *)response
|
|||
[_received isEqualToData: _expectedContent])
|
||||
{
|
||||
[self setFlags: GOTCONTENT];
|
||||
if (YES == _debug)
|
||||
{
|
||||
NSLog(@"%@: set GOTCONTENT (-[%@])", self, NSStringFromSelector(_cmd));
|
||||
}
|
||||
NSDebugLog(@"%@: set GOTCONTENT (-[%@])", self, NSStringFromSelector(_cmd));
|
||||
}
|
||||
|
||||
[self setFlags: GOTFINISH];
|
||||
if (YES == _debug)
|
||||
{
|
||||
NSLog(@"%@: set GOTFINISH (-[%@])", self, NSStringFromSelector(_cmd));
|
||||
}
|
||||
NSDebugLog(@"%@: set GOTFINISH (-[%@])", self, NSStringFromSelector(_cmd));
|
||||
|
||||
_done = YES;
|
||||
}
|
||||
|
@ -461,11 +419,8 @@ didReceiveResponse:(NSURLResponse *)response
|
|||
*/
|
||||
|
||||
[self setFlags: GOTFAIL];
|
||||
if (YES == _debug)
|
||||
{
|
||||
NSLog(@"%@: set GOTFAIL (-[%@])", self, NSStringFromSelector(_cmd));
|
||||
NSLog(@"%@: error %@", self, error);
|
||||
}
|
||||
NSDebugLog(@"%@: set GOTFAIL (-[%@])", self, NSStringFromSelector(_cmd));
|
||||
NSDebugLog(@"%@: error %@", self, error);
|
||||
|
||||
_done = YES;
|
||||
}
|
||||
|
|
|
@ -76,12 +76,7 @@
|
|||
NSString *path;
|
||||
BOOL ret = NO;
|
||||
|
||||
|
||||
|
||||
if(YES == _debug)
|
||||
{
|
||||
NSLog(@"%@: BEGIN\n%@", self, request);
|
||||
}
|
||||
NSDebugLog(@"%@: BEGIN\n%@", self, request);
|
||||
|
||||
if(nil != _delegate && [_delegate respondsToSelector: @selector(handler:gotRequest:with:)])
|
||||
{
|
||||
|
@ -105,10 +100,7 @@
|
|||
[_delegate handler: self willSendUnauthorized: response with: server];
|
||||
}
|
||||
|
||||
if(YES == _debug)
|
||||
{
|
||||
NSLog(@"%@: about to send Unauthorized\n%@", self, response);
|
||||
}
|
||||
NSDebugLog(@"%@: about to send Unauthorized\n%@", self, response);
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
@ -124,10 +116,7 @@
|
|||
if([[credentials objectAtIndex:0] isEqualToString: _login] &&
|
||||
[[credentials objectAtIndex:1] isEqualToString: _password])
|
||||
{
|
||||
if(YES == _debug)
|
||||
{
|
||||
NSLog(@"%@: got valid credentials", self);
|
||||
}
|
||||
NSDebugLog(@"%@: got valid credentials", self);
|
||||
|
||||
if(nil != _delegate && [_delegate respondsToSelector: @selector(handler:gotAuthorized:with:)])
|
||||
{
|
||||
|
@ -149,10 +138,7 @@
|
|||
[_delegate handler: self willSendUnauthorized: response with: server];
|
||||
}
|
||||
|
||||
if(YES == _debug)
|
||||
{
|
||||
NSLog(@"%@: about to send Unauthorized\n%@", self, response);
|
||||
}
|
||||
NSDebugLog(@"%@: about to send Unauthorized\n%@", self, response);
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
@ -183,10 +169,7 @@
|
|||
}
|
||||
|
||||
// TODO: may be to move at another place?
|
||||
if(YES == _debug)
|
||||
{
|
||||
NSLog(@"%@: about to send\n%@", self, response);
|
||||
}
|
||||
NSDebugLog(@"%@: about to send\n%@", self, response);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -361,11 +361,10 @@
|
|||
value: version
|
||||
parameters: nil];
|
||||
|
||||
if (YES == _debug)
|
||||
{
|
||||
NSLog(@"%@: got request\n%@", self, _request);
|
||||
}
|
||||
NSDebugLog(@"%@: got request\n%@", self, _request);
|
||||
|
||||
_response = [GSMimeDocument new];
|
||||
|
||||
if (nil != _delegate && [_delegate respondsToSelector: @selector(processRequest:response:for:)])
|
||||
{
|
||||
ret = [_delegate processRequest: _request response: _response for: self];
|
||||
|
@ -460,10 +459,7 @@
|
|||
// actual sending
|
||||
[data appendData: [_response rawMimeData]];
|
||||
|
||||
if (YES == _debug)
|
||||
{
|
||||
NSLog(@"%@: about to send response\n%@", self, _response);
|
||||
}
|
||||
NSDebugLog(@"%@: about to send response\n%@", self, _response);
|
||||
|
||||
[_cfh writeData: data];
|
||||
}
|
||||
|
|
|
@ -149,17 +149,13 @@
|
|||
{
|
||||
if ([_server port] != nil)
|
||||
{
|
||||
if (_debug)
|
||||
{
|
||||
NSWarnMLog(@"SimpleWebServer already started");
|
||||
}
|
||||
NSWarnMLog(@"SimpleWebServer already started");
|
||||
return;
|
||||
}
|
||||
|
||||
if (nil != _serverThread)
|
||||
{
|
||||
if (_debug)
|
||||
NSLog(@"Waiting for startup");
|
||||
NSDebugLog(@"Waiting for startup");
|
||||
if (![_serverThread isExecuting])
|
||||
{
|
||||
NSTimeInterval duration = 0.0;
|
||||
|
@ -199,10 +195,7 @@
|
|||
{
|
||||
if ([_server port] == nil)
|
||||
{
|
||||
if (YES == _debug)
|
||||
{
|
||||
NSWarnMLog(@"SimpleWebServer already stopped");
|
||||
}
|
||||
NSWarnMLog(@"SimpleWebServer already stopped");
|
||||
return;
|
||||
}
|
||||
if (nil != _serverThread)
|
||||
|
@ -363,6 +356,10 @@
|
|||
|
||||
- (void)setDebug:(BOOL)mode
|
||||
{
|
||||
NSProcessInfo *pi = [NSProcessInfo processInfo];
|
||||
|
||||
[pi setDebugLoggingEnabled: mode];
|
||||
|
||||
_debug = mode;
|
||||
}
|
||||
|
||||
|
@ -411,11 +408,9 @@
|
|||
}
|
||||
}
|
||||
|
||||
if (_debug)
|
||||
{
|
||||
NSLog(@"Starting web server with address %@, port %@ %@",
|
||||
_address, _port, secure ? @" with TLS" : @"");
|
||||
}
|
||||
NSDebugLog(@"Starting web server with address %@, port %@ %@",
|
||||
_address, _port, secure ? @" with TLS" : @"");
|
||||
|
||||
status = [_server setAddress: _address port: _port secure: secure];
|
||||
if (!status)
|
||||
{
|
||||
|
@ -430,10 +425,7 @@
|
|||
if (nil != _server && [_server port] != nil)
|
||||
{
|
||||
[_server stop]; // shut down the server
|
||||
if (YES == _debug)
|
||||
{
|
||||
NSLog(@"%@: stopped SimpleWebServer %@", self, _server);
|
||||
}
|
||||
NSDebugLog(@"%@: stopped SimpleWebServer %@", self, _server);
|
||||
DESTROY(_server);
|
||||
}
|
||||
}
|
||||
|
@ -447,10 +439,8 @@
|
|||
[self _startHTTPServer: extra];
|
||||
[_lock unlockWithCondition: STARTED];
|
||||
|
||||
if (YES == _debug)
|
||||
{
|
||||
NSLog(@"%@: enter into runloop in detached thread %@", self, [NSThread currentThread]);
|
||||
}
|
||||
NSDebugLog(@"%@: enter into runloop in detached thread %@", self, [NSThread currentThread]);
|
||||
|
||||
|
||||
while(!_threadToQuit && duration < MAXDURATION)
|
||||
{
|
||||
|
@ -459,10 +449,7 @@
|
|||
duration += TIMING;
|
||||
}
|
||||
|
||||
if (YES == _debug)
|
||||
{
|
||||
NSLog(@"%@: exit from runloop in detached thread %@", self, [NSThread currentThread]);
|
||||
}
|
||||
NSDebugLog(@"%@: exit from runloop in detached thread %@", self, [NSThread currentThread]);
|
||||
|
||||
if (duration >= MAXDURATION &&
|
||||
nil != _delegate &&
|
||||
|
|
|
@ -28,7 +28,7 @@ int main(int argc, char **argv, char **env)
|
|||
NSDictionary *refs;
|
||||
TestWebServer *server;
|
||||
NSURLConnectionTest *testCase;
|
||||
BOOL debug = NO;
|
||||
BOOL debug = GSDebugSet(@"dflt");
|
||||
|
||||
testClass = [bundle principalClass]; // NSURLConnectionTest
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ int main(int argc, char **argv, char **env)
|
|||
NSDictionary *refs;
|
||||
TestWebServer *server;
|
||||
NSURLConnectionTest *testCase;
|
||||
BOOL debug = NO;
|
||||
BOOL debug = GSDebugSet(@"dflt");
|
||||
|
||||
testClass = [bundle principalClass]; // NSURLConnectionTest
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@ int main(int argc, char **argv, char **env)
|
|||
NSDictionary *refs;
|
||||
TestWebServer *server;
|
||||
NSURLConnectionTest *testCase;
|
||||
BOOL debug = NO;
|
||||
BOOL debug = GSDebugSet(@"dflt");
|
||||
|
||||
testClass = [bundle principalClass]; // NSURLConnectionTest
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ int main(int argc, char **argv, char **env)
|
|||
NSDictionary *refs;
|
||||
TestWebServer *server;
|
||||
NSURLConnectionTest *testCase;
|
||||
BOOL debug = NO;
|
||||
BOOL debug = GSDebugSet(@"dflt");
|
||||
|
||||
testClass = [bundle principalClass]; // NSURLConnectionTest
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ int main(int argc, char **argv, char **env)
|
|||
{
|
||||
Class testClass;
|
||||
TestWebServer *server;
|
||||
BOOL debug = NO;
|
||||
BOOL debug = GSDebugSet(@"dflt");
|
||||
NSURL *url;
|
||||
NSError *error = nil;
|
||||
NSURLRequest *request;
|
||||
|
|
|
@ -29,7 +29,7 @@ int main(int argc, char **argv, char **env)
|
|||
TestWebServer *server;
|
||||
NSMutableString *payload;
|
||||
NSURLConnectionTest *testCase;
|
||||
BOOL debug = NO;
|
||||
BOOL debug = GSDebugSet(@"dflt");
|
||||
int i;
|
||||
|
||||
testClass = [bundle principalClass]; // NSURLConnectionTest
|
||||
|
|
Loading…
Reference in a new issue