Changeset 507
- Timestamp:
- 08/13/09 15:11:02 (4 years ago)
- Location:
- apps/iphone/superbook/trunk/DotTel_SDK/Classes
- Files:
-
- 4 modified
-
DnsResolver.h (modified) (2 diffs)
-
DnsResolver.m (modified) (4 diffs)
-
RecordTxt.h (modified) (2 diffs)
-
RecordTxt.m (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
apps/iphone/superbook/trunk/DotTel_SDK/Classes/DnsResolver.h
r496 r507 77 77 78 78 /** 79 * Retrieves all keyword TXT records in a domain and adds them to the provided 80 * array. Keyword TXT records are encapsulated in the RecordTxt class. 81 * Header TXT records (not keywords) are concatenated and returned as a string. 82 * Note that according to specs, there should only be a single Header TXT record 83 * per sub/domain. 84 * System messages are skipped. 79 * Retrieves all TXT records in a domain and adds them to the provided 80 * array. TXT records are encapsulated in the RecordTxt class. 85 81 * Also note that TXT records are returned in random order. 86 82 * … … 88 84 * @param txtArray the array to add the txt records to 89 85 * 90 * @return the domain's TXT header string. If no header string is found,91 * returns the empty @"" string86 * @return the number of TXT records in the domain. 0 should mean error 87 * 92 88 */ 93 - (NS String *)getTXTForTel:(NSString *)domain inArray:(NSMutableArray *)txtArray withError:(NSError **)error;89 - (NSUInteger)getTXTForTel:(NSString *)domain inArray:(NSMutableArray *)txtArray withError:(NSError **)error; 94 90 95 91 /** -
apps/iphone/superbook/trunk/DotTel_SDK/Classes/DnsResolver.m
r469 r507 79 79 } 80 80 81 // This method returns a header text as it parses the txt records 82 - (NSString *)getTXTForTel:(NSString *)domain inArray:(NSMutableArray *)txtArray withError:(NSError **)error { 83 84 NSMutableString *_headerText = nil; 85 81 // TODO: header will be made obsolete by NINFO 82 - (NSUInteger)getTXTForTel:(NSString *)domain inArray:(NSMutableArray *)txtArray withError:(NSError **)error { 83 86 84 #ifdef DEBUG 87 85 NSLog(@"Domain %@: Retrieving TXT Records", domain); … … 89 87 ldns_rr_list *txts = [self retrieveResourceRecordsOfType:LDNS_RR_TYPE_TXT fromDomain:domain withError:error]; 90 88 if (!txts) { 91 return _headerText;89 return 0; 92 90 } 93 91 … … 99 97 RecordTxt *theRec = [RecordTxt recordWithRr:ldns_rr_list_rr(txts, i) date:lookupDate]; 100 98 if (theRec.isValid) { 101 if ([theRec isHeader]) { 102 if (!_headerText) { 103 _headerText = [NSMutableString stringWithString:theRec.textValue]; 104 } else { 105 //NSLog(theRec.textValue); 106 [_headerText appendFormat:@"\n %@", theRec.textValue]; 107 } 108 } else { 109 [txtArray addObject:theRec]; 110 } 99 [txtArray addObject:theRec]; 111 100 } 112 101 } … … 115 104 [lookupDate release]; 116 105 117 return _headerText;106 return count; 118 107 119 108 } -
apps/iphone/superbook/trunk/DotTel_SDK/Classes/RecordTxt.h
r496 r507 33 33 #define LocTelStr(key) [[NSBundle mainBundle] localizedStringForKey:(key) value:@"" table:@"DotTel"] 34 34 35 enum RecordTxtSubTypes { 36 RecordTxtSubTypeString = 0, // string header (will be made obsolete by NINFO) 37 RecordTxtSubTypeDDS = 1, // domain display string 38 RecordTxtSubTypeKeyword = 2, // keyword 39 RecordTxtSubTypeOtherTSM = 3, // other .tel system message 40 RecordTxtSubTypeAdvert = 4, // .tad advert 41 }; 42 35 43 @interface RecordTxt : NSObject { 36 44 37 45 BOOL isValid; 38 39 BOOL isHeader; // Non-keyword header text string 40 BOOL isKeyword; // Structured Keyword (.tkw) 41 BOOL isSystemMessage; // System Message (.tsm) 46 NSUInteger subType; // RecordTxtSubTypes value 42 47 43 48 // Derived attributes … … 77 82 78 83 @property (readonly) BOOL isValid; 79 80 @property (readonly) BOOL isHeader; 81 @property (readonly) BOOL isKeyword; 82 @property (readonly) BOOL isSystemMessage; 84 @property (readonly) NSUInteger subType; 83 85 84 86 @property (readonly, nonatomic, retain) NSString *primaryDescription; -
apps/iphone/superbook/trunk/DotTel_SDK/Classes/RecordTxt.m
r497 r507 33 33 @interface RecordTxt (PrivateMethods) 34 34 35 - (BOOL)parseDisplayStringFromRecord:(const ldns_rr *)rr; 35 36 - (BOOL)parseKeywordsFromRecord:(const ldns_rr *)rr; 36 37 … … 42 43 43 44 @synthesize isValid; 44 @synthesize isHeader; 45 @synthesize isKeyword; 46 @synthesize isSystemMessage; 45 @synthesize subType; 47 46 @synthesize expiryDate; 48 47 … … 68 67 self = [super init]; 69 68 isValid = NO; 69 subType = RecordTxtSubTypeString; 70 70 return self; 71 71 } … … 75 75 trimCharacterSet = [[NSCharacterSet whitespaceCharacterSet] retain]; 76 76 isValid = NO; 77 isKeyword = NO;78 77 79 78 if (ldns_rr_get_type(rr) != LDNS_RR_TYPE_TXT) … … 86 85 if ([firstString isEqualToString:@".tkw"]) { 87 86 // parse keywords 88 isKeyword = YES;87 subType = RecordTxtSubTypeKeyword; 89 88 isValid = [self parseKeywordsFromRecord:rr]; 90 89 } else if ([firstString isEqualToString:@".tsm"]) { 91 // system message, do nothing 90 // system message 91 // let's see if it's something we know 92 NSString *smType = [self stringFromStringRdf:ldns_rr_rdf(rr,2)]; 93 if (smType != nil) { 94 if ([smType isEqualToString:@"dds"]) { 95 // Domain display string 96 subType = RecordTxtSubTypeDDS; 97 isValid = [self parseDisplayStringFromRecord:rr]; 98 return self; 99 } 100 } 101 subType = RecordTxtSubTypeOtherTSM; 92 102 return self; 93 103 } else if ([firstString isEqualToString:@".tad"]) { 94 104 // advert, do nothing for now 105 subType = RecordTxtSubTypeAdvert; 95 106 return self; 96 107 } else { 97 108 // header 98 isHeader = YES;109 subType = RecordTxtSubTypeString; 99 110 primaryDescription = [@"" retain]; 100 111 primaryValue = NULL; … … 110 121 111 122 return self; 123 } 124 125 - (BOOL)parseDisplayStringFromRecord:(const ldns_rr *)rr { 126 // That's the domain display string, which should replace the regular domain name 127 // ".tsm " "1" "dds" "John W. Smith" 128 129 // Check version 130 if ([[self stringFromStringRdf:ldns_rr_rdf(rr,1)] isEqualToString:@"1"]) { 131 // Version 1 132 textValue = [[self stringFromStringRdf:ldns_rr_rdf(rr,3)] retain]; 133 return TRUE; 134 } 135 textValue = nil; 136 return FALSE; 112 137 } 113 138 … … 167 192 168 193 - (NSMutableString *)stringFromStringRdf:(const ldns_rdf *)rdf { 194 if (rdf == NULL) { 195 return nil; 196 } 169 197 NSMutableString *res; 170 198 const uint8_t *data = ldns_rdf_data(rdf); … … 180 208 - (void)dealloc { 181 209 [trimCharacterSet release]; 210 // [primaryDescription release]; 211 // [primaryValue release]; 212 // [textValue release]; 213 // [keysAndValues release]; 214 // [expiryDate release]; 182 215 [super dealloc]; 183 216 }








