Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/Cocoanetics/DTFoundation
Browse files Browse the repository at this point in the history
…into HEAD
  • Loading branch information
odrobnik committed Mar 1, 2013
2 parents 8e8a4ba + 87de8b7 commit dee7455
Show file tree
Hide file tree
Showing 8 changed files with 140 additions and 89 deletions.
44 changes: 44 additions & 0 deletions AppledocSettings.plist
@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>--project-name</key>
<string>DTFoundation</string>
<key>--project-company</key>
<string>Cocoanetics</string>
<key>--project-version</key>
<string>1.0</string>
<key>--company-id</key>
<string>com.cocoanetics</string>
<key>--docset-atom-filename</key>
<string>DTFoundation.atom</string>
<key>--docset-feed-url</key>
<string>https://docs.cocoanetics.com/DTFoundation/%DOCSETATOMFILENAME</string>
<key>--docset-package-url</key>
<string>https://docs.cocoanetics.com/DTFoundation/%DOCSETPACKAGEFILENAME</string>
<key>--docset-fallback-url</key>
<string>https://docs.cocoanetics.com/DTFoundation/</string>
<key>--create-docset</key>
<true/>
<key>--publish-docset</key>
<true/>
<key>--install-docset</key>
<false/>
<key>--logformat</key>
<string>xcode</string>
<key>--keep-intermediate-files</key>
<true/>
<key>--no-repeat-first-par</key>
<true/>
<key>--ignore</key>
<array>
<string>*.m</string>
<string>Core/Externals</string>
<string>Demo</string>
</array>
<key>--index-desc</key>
<string>Readme.markdown</string>
<key>--warn-invalid-crossref</key>
<false/>
</dict>
</plist>
133 changes: 65 additions & 68 deletions Core/Source/DTASN1Parser.m
Expand Up @@ -17,8 +17,10 @@ @implementation DTASN1Parser
NSError *_parserError;
BOOL _abortParsing;

NSDateFormatter *_UTCFormatter;

// lookup bitmask what delegate methods are implemented
struct
struct
{
unsigned int delegateSupportsDocumentStart:1;
unsigned int delegateSupportsDocumentEnd:1;
Expand Down Expand Up @@ -47,6 +49,11 @@ - (id)initWithData:(NSData *)data
_data = data;
_dataLength = [data length];

// has to end with Z
_UTCFormatter = [[NSDateFormatter alloc] init];
_UTCFormatter.dateFormat = @"yyMMddHHmmss'Z'";
_UTCFormatter.timeZone = [NSTimeZone timeZoneWithAbbreviation:@"UTC"];

if (!_dataLength)
{
return nil;
Expand Down Expand Up @@ -83,7 +90,7 @@ - (NSUInteger)_parseLengthAtLocation:(NSUInteger)location lengthOfLength:(NSUInt
{
retValue = (NSUInteger)buffer;
}
else if (buffer>0x80)
else if (buffer>0x80)
{
// next n bytes describe the length length
NSUInteger lengthLength = buffer-0x80;
Expand All @@ -105,7 +112,7 @@ - (NSUInteger)_parseLengthAtLocation:(NSUInteger)location lengthOfLength:(NSUInt

free(lengthBytes);
}
else
else
{
// length 0x80 means "indefinite"
[self _parseErrorEncountered:@"Indefinite Length form encounted, not implemented"];
Expand All @@ -121,12 +128,15 @@ - (NSUInteger)_parseLengthAtLocation:(NSUInteger)location lengthOfLength:(NSUInt

- (BOOL)_parseValueWithTag:(NSUInteger)tag dataRange:(NSRange)dataRange
{
if (!dataRange.length)
{
return NO;
}

switch (tag)
if (!dataRange.length && tag != DTASN1TypeNull)
{
NSLog(@"Encountered zero length data for tag %ld", tag);

// only NULL can have zero length
return NO;
}

switch (tag)
{
case DTASN1TypeBoolean:
{
Expand Down Expand Up @@ -172,15 +182,15 @@ - (BOOL)_parseValueWithTag:(NSUInteger)tag dataRange:(NSRange)dataRange

[_delegate parser:self foundNumber:number];
}
else
else
{
// send number as data if supported, too long for 32 bit
sendAsData = YES;
}
free(buffer);
free(buffer);
}
else
else
{
// send number as data if supported, delegate does not want numbers
sendAsData = YES;
Expand All @@ -191,7 +201,7 @@ - (BOOL)_parseValueWithTag:(NSUInteger)tag dataRange:(NSRange)dataRange
char *buffer = malloc(dataRange.length);
[_data getBytes:buffer range:dataRange];
NSData *data = [NSData dataWithBytesNoCopy:buffer length:dataRange.length freeWhenDone:YES];

[_delegate parser:self foundData:data];
}

Expand All @@ -202,21 +212,23 @@ - (BOOL)_parseValueWithTag:(NSUInteger)tag dataRange:(NSRange)dataRange
{
if (_delegateFlags.delegateSupportsData)
{
char *buffer = malloc(dataRange.length);
[_data getBytes:buffer range:dataRange];

// primitive encoding
NSUInteger unusedBits = buffer[0];

if (unusedBits>0)
{
[self _parseErrorEncountered:@"Encountered bit string with unused bits > 0, not implemented"];
free(buffer);
return NO;
}
char *buffer = malloc(dataRange.length);
[_data getBytes:buffer range:dataRange];
// primitive encoding
NSUInteger unusedBits = buffer[0];
if (unusedBits>0)
{
[self _parseErrorEncountered:@"Encountered bit string with unused bits > 0, not implemented"];
free(buffer);
return NO;
}

NSData *data = [NSData dataWithBytesNoCopy:buffer+1 length:dataRange.length-1 freeWhenDone:YES];
NSData *data = [NSData dataWithBytes:buffer+1 length:dataRange.length-1];
[_delegate parser:self foundData:data];

free(buffer);
}

break;
Expand All @@ -231,7 +243,7 @@ - (BOOL)_parseValueWithTag:(NSUInteger)tag dataRange:(NSRange)dataRange
NSData *data = [NSData dataWithBytesNoCopy:buffer length:dataRange.length freeWhenDone:YES];

[_delegate parser:self foundData:data];
}
}

break;
}
Expand Down Expand Up @@ -264,7 +276,7 @@ - (BOOL)_parseValueWithTag:(NSUInteger)tag dataRange:(NSRange)dataRange
NSUInteger value=0;

BOOL more = NO;
do
do
{
unsigned char b = buffer[i];
value = value * 128;
Expand All @@ -281,7 +293,7 @@ - (BOOL)_parseValueWithTag:(NSUInteger)tag dataRange:(NSRange)dataRange
{
[self _parseErrorEncountered:@"Invalid object identifier with more bit set on last octed"];
free(buffer);

return NO;
}
} while (more);
Expand Down Expand Up @@ -324,12 +336,7 @@ - (BOOL)_parseValueWithTag:(NSUInteger)tag dataRange:(NSRange)dataRange

NSString *string = [[NSString alloc] initWithBytesNoCopy:buffer length:dataRange.length encoding:NSASCIIStringEncoding freeWhenDone:YES];

// has to end with Z
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
formatter.dateFormat = @"yyMMddHHmmss'Z'";
formatter.timeZone = [NSTimeZone timeZoneWithAbbreviation:@"UTC"];

NSDate *parsedDate = [formatter dateFromString:string];
NSDate *parsedDate = [_UTCFormatter dateFromString:string];

if (parsedDate)
{
Expand Down Expand Up @@ -363,7 +370,7 @@ - (BOOL)_parseRange:(NSRange)range

NSUInteger location = range.location;

do
do
{
if (_abortParsing)
{
Expand All @@ -375,9 +382,8 @@ - (BOOL)_parseRange:(NSRange)range
[_data getBytes:&tagByte range:NSMakeRange(location, 1)];
location++;


BOOL isSeq = tagByte & 32;
BOOL isContext = tagByte & 128;
// BOOL isSeq = tagByte & 32;
// BOOL isContext = tagByte & 128;

//NSUInteger tagClass = tagByte >> 6;
DTASN1Type tagType = tagByte & 31;
Expand All @@ -404,18 +410,6 @@ - (BOOL)_parseRange:(NSRange)range
// make range
NSRange subRange = NSMakeRange(location, length);

if (isContext)
{
//NSLog(@"[%d]", tagType);
}
else
{
if (isSeq)
{
//NSLog(@"%d", tagType);
}
}

if (tagConstructed)
{
// constructed element
Expand All @@ -435,7 +429,7 @@ - (BOOL)_parseRange:(NSRange)range
[_delegate parser:self didEndContainerWithType:tagType];
}
}
else
else
{
// primitive
if (![self _parseValueWithTag:tagType dataRange:subRange])
Expand Down Expand Up @@ -463,19 +457,22 @@ - (BOOL)_parseRange:(NSRange)range

- (BOOL)parse
{
if (_delegateFlags.delegateSupportsDocumentStart)
@autoreleasepool
{
[_delegate parserDidStartDocument:self];
}

BOOL result = [self _parseRange:NSMakeRange(0, _dataLength)];

if (result && _delegateFlags.delegateSupportsDocumentEnd)
{
[_delegate parserDidEndDocument:self];
if (_delegateFlags.delegateSupportsDocumentStart)
{
[_delegate parserDidStartDocument:self];
}

BOOL result = [self _parseRange:NSMakeRange(0, _dataLength)];

if (result && _delegateFlags.delegateSupportsDocumentEnd)
{
[_delegate parserDidEndDocument:self];
}

return result;
}

return result;
}

- (void)abortParsing
Expand Down Expand Up @@ -503,7 +500,7 @@ - (void)setDelegate:(__unsafe_unretained id<DTASN1ParserDelegate>)delegate;
{
_delegateFlags.delegateSupportsDocumentEnd = YES;
}

if ([_delegate respondsToSelector:@selector(parser:didStartContainerWithType:)])
{
_delegateFlags.delegateSupportsContainerStart = YES;
Expand All @@ -523,7 +520,7 @@ - (void)setDelegate:(__unsafe_unretained id<DTASN1ParserDelegate>)delegate;
{
_delegateFlags.delegateSupportsString = YES;
}

if ([_delegate respondsToSelector:@selector(parserFoundNull:)])
{
_delegateFlags.delegateSupportsNull = YES;
Expand All @@ -538,12 +535,12 @@ - (void)setDelegate:(__unsafe_unretained id<DTASN1ParserDelegate>)delegate;
{
_delegateFlags.delegateSupportsData = YES;
}

if ([_delegate respondsToSelector:@selector(parser:foundNumber:)])
{
_delegateFlags.delegateSupportsNumber = YES;
}

if ([_delegate respondsToSelector:@selector(parser:foundObjectIdentifier:)])
{
_delegateFlags.delegateSupportsObjectIdentifier = YES;
Expand Down
1 change: 1 addition & 0 deletions Core/Source/DTObjectBlockExecutor.h
Expand Up @@ -14,6 +14,7 @@

/**
Convenience method to create a block executor with a deallocation block
@param block The block to execute when the created receiver is being deallocated
*/
+ (id)blockExecutorWithDeallocBlock:(void(^)())block;

Expand Down
1 change: 1 addition & 0 deletions Core/Source/NSObject+DTRuntime.h
Expand Up @@ -19,6 +19,7 @@

/**
Adds a block to be executed as soon as the receiver's memory is deallocated
@param block The block to execute when the receiver is being deallocated
*/
- (void)addDeallocBlock:(void(^)())block;

Expand Down
25 changes: 12 additions & 13 deletions Core/Source/iOS/DTActivityTitleView.m
Expand Up @@ -54,19 +54,6 @@ - (id)init
- (void)layoutSubviews
{
[super layoutSubviews];

CGFloat gap = 5.0;
CGFloat height = self.activityIndicator.frame.size.height;
CGSize neededSize = [self.titleLabel.text sizeWithFont:self.titleLabel.font];

if (height < neededSize.height)
{
height = neededSize.height;
}

CGRect titleRect = CGRectMake(self.activityIndicator.frame.size.width+gap, 0, neededSize.width, height);
self.titleLabel.frame = titleRect;
self.bounds = CGRectMake(0, 0, self.activityIndicator.frame.size.width+neededSize.width+gap, height);
}

#pragma mark - Properties
Expand All @@ -93,6 +80,18 @@ - (BOOL)busy
- (void)setTitle:(NSString *)title
{
self.titleLabel.text = title;
CGFloat gap = 5.0;
CGFloat height = self.activityIndicator.frame.size.height;
CGSize neededSize = [self.titleLabel.text sizeWithFont:self.titleLabel.font];

if (height < neededSize.height)
{
height = neededSize.height;
}

CGRect titleRect = CGRectMake(self.activityIndicator.frame.size.width+gap, 0, neededSize.width, height);
self.titleLabel.frame = titleRect;
self.bounds = CGRectMake(0, 0, self.activityIndicator.frame.size.width+neededSize.width+gap, height);
[self setNeedsLayout];
}

Expand Down

0 comments on commit dee7455

Please sign in to comment.