Changeset 567
- Timestamp:
- 11/09/09 11:07:04 (4 years ago)
- Location:
- apps/blackberry/branches/1.5/blackberry/src/org/telnic/blackberry/lookup
- Files:
-
- 3 modified
-
LookupResult.java (modified) (4 diffs)
-
LookupTelname.java (modified) (19 diffs)
-
LookupWorker.java (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
apps/blackberry/branches/1.5/blackberry/src/org/telnic/blackberry/lookup/LookupResult.java
r339 r567 32 32 * 33 33 * @author Ben Dowling, Jonathan Maycock 34 * @version $Id: LookupResult.java,v 1.1 2 2009/03/05 11:41:48jm2 Exp $34 * @version $Id: LookupResult.java,v 1.13 2009/11/06 11:54:52 jm2 Exp $ 35 35 */ 36 36 public class LookupResult implements Persistable … … 72 72 private Vector locRecords; 73 73 74 /**75 * The nInfo records.76 */77 private Vector nInfoRecords;78 79 74 // stores the time (in seconds) that this record was last updated 80 75 /** … … 159 154 return locRecords; 160 155 } 161 162 163 /**164 * Sets the nInfo records.165 *166 * @param nInfoRecords the nInfoRecords167 */168 public synchronized void setNInfoRecords (final Vector nInfoRecords)169 {170 this.nInfoRecords = nInfoRecords;171 172 updated = System.currentTimeMillis() / THOUSAND;173 174 setMinTtl( this.nInfoRecords );175 }176 156 177 /**178 * Gets the NINFO records.179 *180 * @return the ninfo records181 */182 public synchronized Vector getNInfoRecords ()183 {184 return nInfoRecords;185 }186 187 188 157 /** 189 158 * Sets the loc records. … … 233 202 public long validFor () 234 203 { 235 if (txtRecords == null && naptrRecords == null && locRecords == null && nInfoRecords == null)204 if (txtRecords == null && naptrRecords == null && locRecords == null) 236 205 { 237 206 ttl = 0; 238 207 } 239 else if (txtRecords.isEmpty() && naptrRecords.isEmpty() && locRecords.isEmpty() && nInfoRecords.isEmpty())208 else if (txtRecords.isEmpty() && naptrRecords.isEmpty() && locRecords.isEmpty()) 240 209 { 241 210 ttl = 0; -
apps/blackberry/branches/1.5/blackberry/src/org/telnic/blackberry/lookup/LookupTelname.java
r339 r567 27 27 import org.telnic.blackberry.TelnameApp; 28 28 import org.telnic.blackberry.dns.DNS; 29 import org.telnic.blackberry.dns.DNSTxtDDSResourceRecord; 30 import org.telnic.blackberry.dns.DNSTxtHeaderResourceRecord; 31 import org.telnic.blackberry.dns.DNSTxtKeywordResourceRecord; 32 import org.telnic.blackberry.dns.DNSTxtLongLabelResourceRecord; 33 import org.telnic.blackberry.dns.DNSTxtPDDXResourceRecord; 29 34 import org.telnic.blackberry.dns.LookupCompleteActionListener; 30 35 import org.telnic.blackberry.dns.LookupWorkerCompletedListener; … … 38 43 * 39 44 * @author Ben Dowling, Jonathan Maycock 40 * @version $Id: LookupTelname.java,v 1.2 1 2009/01/29 16:47:04jm2 Exp $45 * @version $Id: LookupTelname.java,v 1.22 2009/11/06 11:55:17 jm2 Exp $ 41 46 */ 42 47 public class LookupTelname implements LookupWorkerCompletedListener, Cancellable … … 72 77 */ 73 78 public static final int STATUS_TIMEOUT = 5; 74 75 /** 76 * The telname. 77 */ 78 private String telname; 79 80 /** 81 * The top level telname for LOC/TXT. 82 */ 83 private String telnameTop; 79 80 /** 81 * The Keyword Prefix. 82 */ 83 public static final String KEYWORD_PREFIX = "_kw"; 84 85 /** 86 * The private domain.. 87 */ 88 private String privateDomain; 89 90 /** 91 * The public domain. 92 */ 93 private String publicDomain; 84 94 85 95 /** … … 133 143 private int type = 0; 134 144 145 /** 146 * The version of the domain being looked up. 147 */ 148 private boolean isVersionOne = false; 149 150 /** 151 * The availability of keywords for this domain. 152 */ 153 private boolean keywordsAvailable = false; 154 155 /** 156 * The private availability for this domain. 157 */ 158 private boolean privateDataAvailable = false; 135 159 136 160 /** … … 144 168 private int parentStatus; 145 169 146 private boolean naptrDone = false;147 private boolean txtDone = false;148 private boolean locDone = false;149 private boolean nInfoDone= false;170 /** 171 * Boolean indicating whether this is a version lookup. 172 */ 173 private boolean versionLookup = false; 150 174 151 175 ConnectionManager cm; … … 168 192 completeListener = l; 169 193 } 170 194 195 /** 196 * Perform a lookup for a version check. 197 * 198 * @param telnameVal the version domain. 199 */ 200 public void performVersionLookup (final String telnameVal) 201 { 202 this.versionLookup = true; 203 performLookup( telnameVal ); 204 } 205 206 /** 207 * Perform a lookup of a public domain. 208 * 209 * @param telnameVal the public domain. 210 */ 211 public void performLookup (final String telnameVal) 212 { 213 performLookup( telnameVal, telnameVal ); 214 } 171 215 172 216 /** … … 174 218 * 175 219 * @param telnameVal the telnameVal 176 */ 177 public void performLookup (final String telnameVal) 220 * @param telnameTopVal the top level domain 221 */ 222 public void performLookup (final String telnameVal, final String telnameTopVal) 178 223 { 179 224 Logger.logMessage( "Performing lookup of " + telnameVal, Options.KEY_LOG_APPLICATION ); … … 183 228 return; 184 229 } 185 186 naptrDone = false; 187 txtDone = false; 188 locDone = false; 189 nInfoDone = false; 190 191 this.telname = telnameVal; 192 this.telnameTop = telnameVal; 230 231 this.privateDomain = telnameVal; 232 this.publicDomain = telnameTopVal; 193 233 194 234 cancelled = false; … … 212 252 UiApplication.getUiApplication().invokeLater( new Runnable() 213 253 { 254 214 255 public void run () 215 256 { … … 230 271 lookupResult = new LookupResult( telnameVal ); 231 272 cm = TelnameApp.getDnsConnectionManager(); 232 performNaptrLookup( telnameVal ); 233 } 234 } ); 235 } 236 // if we don't have network coverage return the 237 // cachedResult which could be expired or null 238 else if (!cancelled) 239 { 240 Logger.logMessage( "No network - returning cache", Options.KEY_LOG_NETWORK ); 241 // there is no cached result - but no network coverage 242 // either so no point trying to do a lookup 243 244 status = LookupTelname.STATUS_NO_NETWORK; 245 246 UiApplication.getUiApplication().invokeLater( new Runnable() 247 { 248 public void run () 249 { 250 completeListener.lookupTelnameComplete( cachedResult ); 251 } 252 } ); 253 } 254 } 255 256 /** 257 * Perform lookup. 258 * 259 * @param telnameVal the telnameVal 260 * @param telnameTopVal the top level domain 261 */ 262 public void performLookup (final String telnameVal, final String telnameTopVal) 263 { 264 Logger.logMessage( "Performing lookup of " + telnameVal, Options.KEY_LOG_APPLICATION ); 265 if (completeListener == null) 266 { 267 // no point doing any work if nobody wants to know the result! 268 return; 269 } 270 271 this.telname = telnameVal; 272 this.telnameTop = telnameTopVal; 273 274 cancelled = false; 275 276 // check if we have sufficient network coverage to open a connection 277 final boolean hasCoverage = (RadioInfo.getState() == RadioInfo.STATE_ON) 278 && (RadioInfo.getSignalLevel() != RadioInfo.LEVEL_NO_COVERAGE); 279 280 // check the cache for lookup results 281 if (!cancelled) 282 { 283 Logger.logMessage( "Checking for cached result: " + LookupResultDataStore.numResults(), 284 Options.KEY_LOG_APPLICATION ); 285 cachedResult = LookupResultDataStore.getLookupResult( telnameVal ); 286 } 287 288 // if we have a valid cache result return it 289 if (!cancelled && cachedResult != null && cachedResult.isValid()) 290 { 291 Logger.logMessage( "Valid cached result found", Options.KEY_LOG_APPLICATION ); 292 UiApplication.getUiApplication().invokeLater( new Runnable() 293 { 294 295 public void run () 296 { 297 Logger.logMessage( "Returning Cached Result", Options.KEY_LOG_APPLICATION ); 298 completeListener.lookupTelnameComplete( cachedResult ); 299 } 300 } ); 301 } 302 // otherwise try and lookup a new result 303 else if (!cancelled && hasCoverage) 304 { 305 Logger.logMessage( "Trying lookup", Options.KEY_LOG_APPLICATION ); 306 307 UiApplication.getUiApplication().invokeLater( new Runnable() 308 { 309 public void run () 310 { 311 lookupResult = new LookupResult( telnameVal ); 312 cm = TelnameApp.getDnsConnectionManager(); 313 performNaptrLookup( telname ); 273 274 //lookup public tst domain first, to retrieve .tsm and check version 275 performTxtLookup( publicDomain ); 314 276 } 315 277 } ); … … 506 468 * java.util.Vector) 507 469 */ 508 public void lookupWorkerCompleted (final int statusVal, final int type, final Vector answers )509 { 470 public void lookupWorkerCompleted (final int statusVal, final int type, final Vector answers, String domain) 471 { 510 472 Logger.logMessage( "Lookup Worker Completed: " + type, Options.KEY_LOG_NETWORK ); 473 if (answers != null) 474 { 475 Logger.logMessage( "Returned Answer Set: " + answers.size(), Options.KEY_LOG_NETWORK ); 476 } 511 477 512 478 switch (statusVal) 513 479 { 514 515 480 case LookupCompleteActionListener.LOOKUP_COMPLETE_OK: { 516 481 this.status = LookupTelname.STATUS_OK; … … 549 514 550 515 if (statusVal == LookupCompleteActionListener.LOOKUP_COMPLETE_OK && !cancelled) 551 { 552 Logger.logMessage( "Txt Lookup Complete", Options.KEY_LOG_APPLICATION ); 553 lookupResult.setTxtRecords( answers ); 554 txtDone = true; 555 556 Logger.logMessage( "Checking Complete Status: NAPTR(" + naptrDone + ") TXT(" + txtDone + ") LOC(" + locDone +") NINFO(" + nInfoDone +")", Options.KEY_LOG_APPLICATION ); 516 { 517 if (!cancelled) 557 518 { 558 if ( naptrDone && txtDone && locDone && nInfoDone)519 if (domain.equals( publicDomain )) 559 520 { 560 //done, so finish; 561 finish(); 521 522 if (versionLookup) 523 { 524 //if we've done a version lookup, just fetch the txt records, removing any non plain text records 525 Vector processedAnswers = new Vector(); 526 for (int i = 0; i < answers.size(); i++) 527 { 528 if (answers.elementAt( i ) instanceof DNSTxtHeaderResourceRecord) 529 { 530 processedAnswers.addElement( answers.elementAt( i ) ); 531 } 532 } 533 lookupResult.setTxtRecords( processedAnswers ); 534 535 //then perform a naptr lookup of the public domain. 536 performNaptrLookup( publicDomain ); 537 return; 538 } 539 540 //looked up public domain. check version to determine following lookups. 541 //text lookup done. check for DDS. 542 for (int i = 0; i < answers.size(); i++) 543 { 544 if (answers.elementAt( i ) instanceof DNSTxtPDDXResourceRecord) 545 { 546 //check the version. 547 DNSTxtPDDXResourceRecord sysRecord = (DNSTxtPDDXResourceRecord) answers.elementAt( i ); 548 isVersionOne = sysRecord.isVersionOne(); 549 keywordsAvailable = sysRecord.isKeyWordsAvailable(); 550 privateDataAvailable = sysRecord.isPrivateDataAvailable(); 551 break; 552 } 553 } 554 555 if (isVersionOne) 556 { 557 Vector processedAnswers = new Vector(); 558 for (int i = 0; i < answers.size(); i++) 559 { 560 //for a version 1 domain, take the txt header and keywords from the public domain 561 if (answers.elementAt( i ) instanceof DNSTxtHeaderResourceRecord || answers.elementAt( i ) instanceof DNSTxtKeywordResourceRecord ) 562 { 563 processedAnswers.addElement( answers.elementAt( i ) ); 564 } 565 566 //if its also a public lookup, take the DDS and long labels. 567 if (publicDomain.equals( privateDomain ) 568 && (answers.elementAt( i ) instanceof DNSTxtLongLabelResourceRecord 569 || answers.elementAt( i ) instanceof DNSTxtDDSResourceRecord)) 570 { 571 processedAnswers.addElement( answers.elementAt( i ) ); 572 } 573 } 574 lookupResult.setTxtRecords( processedAnswers ); 575 } 576 else 577 { 578 Vector processedAnswers = new Vector(); 579 for (int i = 0; i < answers.size(); i++) 580 { 581 //for any other version, we don't want any info if it is a private lookup. if it is a public, we copy the long labels and dds. 582 if (publicDomain.equals( privateDomain ) 583 && (answers.elementAt( i ) instanceof DNSTxtLongLabelResourceRecord 584 || answers.elementAt( i ) instanceof DNSTxtDDSResourceRecord)) 585 { 586 processedAnswers.addElement( answers.elementAt( i ) ); 587 } 588 } 589 lookupResult.setTxtRecords( processedAnswers ); 590 } 591 Logger.logMessage( "Public Txt Lookup Complete", Options.KEY_LOG_APPLICATION ); 592 593 if (privateDomain.equals( publicDomain )) 594 { 595 if (isVersionOne) 596 { 597 //in version one domains, when doing a public lookup, go and do NAPTRs next 598 performNaptrLookup( publicDomain ); 599 } 600 else 601 { 602 //in version one+ domains, when doing a public lookup, go and do NINFO next 603 performNinfoLookup( publicDomain ); 604 } 605 } 606 else 607 { 608 //for private domains, lookup the private txt records next, regardless of version. 609 performTxtLookup( privateDomain ); 610 } 611 } 612 else if (domain.equals( privateDomain )) 613 { 614 //looked up private domain. Obtain DDS and log labels and add to already obtained text records. 615 Vector processedAnswers = lookupResult.getTxtRecords(); 616 if (processedAnswers == null) 617 { 618 processedAnswers = new Vector(); 619 } 620 for (int i = 0; i < answers.size(); i++) 621 { 622 //for any private lookup, we get the DDS and LL from the private domain, and add to any from the public lookup. 623 if ((answers.elementAt( i ) instanceof DNSTxtLongLabelResourceRecord 624 || answers.elementAt( i ) instanceof DNSTxtDDSResourceRecord)) 625 { 626 processedAnswers.addElement( answers.elementAt( i ) ); 627 } 628 } 629 lookupResult.setTxtRecords( processedAnswers ); 630 631 Logger.logMessage( "Private Txt Lookup Complete", Options.KEY_LOG_APPLICATION ); 632 633 if (isVersionOne) 634 { 635 //in version one domains, when doing a public lookup, go and do NAPTRs next 636 performNaptrLookup( privateDomain ); 637 } 638 else 639 { 640 //in version one+ domains, when doing a public lookup, go and do NINFO next 641 performNinfoLookup( privateDomain ); 642 } 643 } 644 else if (domain.equals( KEYWORD_PREFIX + "." + publicDomain )) 645 { 646 //keyword lookup complete. get keywords, and add to text records. 647 Vector processedAnswers = lookupResult.getTxtRecords(); 648 if (processedAnswers == null) 649 { 650 processedAnswers = new Vector(); 651 } 652 for (int i = 0; i < answers.size(); i++) 653 { 654 //for any private lookup, we get the DDS and LL from the private domain, and add to any from the public lookup. 655 if (answers.elementAt( i ) instanceof DNSTxtKeywordResourceRecord ) 656 { 657 processedAnswers.addElement( answers.elementAt( i ) ); 658 } 659 } 660 lookupResult.setTxtRecords( processedAnswers ); 661 662 Logger.logMessage( "Private Txt Lookup Complete", Options.KEY_LOG_APPLICATION ); 663 664 finish(); 562 665 } 563 666 } … … 570 673 } 571 674 } 572 } 675 } 676 573 677 else if (type == DNS.TYPE_LOC) 574 678 { … … 578 682 { 579 683 Logger.logMessage( "Loc Lookup Complete", Options.KEY_LOG_APPLICATION ); 580 lookupResult.setLocRecords( answers ); 581 locDone = true; 684 lookupResult.setLocRecords( answers ); 582 685 583 686 if (!cancelled) 584 687 { 585 performNinfoLookup( telnameTop ); 688 if (isVersionOne) 689 { 690 //the LOC lookup is the last one, so finish. 691 finish(); 692 } 693 else 694 { 695 //for v1+ domains, might need to look keywords up in _kw domains. Check value of kwa. 696 if (keywordsAvailable) 697 { 698 performTxtLookup( KEYWORD_PREFIX + "." + publicDomain ); 699 } 700 else 701 { 702 //no keywords available, so finish 703 finish(); 704 } 705 } 586 706 } 587 707 } … … 599 719 600 720 if (statusVal == LookupCompleteActionListener.LOOKUP_COMPLETE_OK && !cancelled) 601 { 721 { 602 722 Logger.logMessage( "NInfo Lookup Complete", Options.KEY_LOG_APPLICATION ); 603 lookupResult.setNInfoRecords( answers ); 604 nInfoDone = true; 723 //if returning from a NINFO lookup, add the value as a text header to the text records. 724 //NINFO lookups only occur on V1+ domains. 725 726 Vector processedAnswers = lookupResult.getTxtRecords(); 727 if (processedAnswers == null) 728 { 729 processedAnswers = new Vector(); 730 } 731 for (int i = 0; i < answers.size(); i++) 732 { 733 if (answers.elementAt( i ) instanceof DNSTxtHeaderResourceRecord) 734 { 735 processedAnswers.addElement( answers.elementAt( i ) ); 736 } 737 } 738 lookupResult.setTxtRecords( processedAnswers ); 605 739 606 740 if (!cancelled) 607 741 { 608 perform TxtLookup( telnameTop);609 } 610 } 742 performNaptrLookup( privateDomain ); 743 } 744 } 611 745 else 612 746 { … … 624 758 { 625 759 Logger.logMessage( "Naptr Lookup Complete", Options.KEY_LOG_APPLICATION ); 626 lookupResult.setNaptrRecords( answers ); 627 naptrDone = true; 628 760 lookupResult.setNaptrRecords( answers ); 629 761 630 762 if (!cancelled) 631 763 { 632 performLocLookup( telnameTop ); 764 if (versionLookup) 765 { 766 //if version lookup, finish 767 finish(); 768 } 769 else 770 { 771 performLocLookup( privateDomain ); 772 } 633 773 } 634 774 } … … 638 778 } 639 779 } 640 } 641 780 781 } 782 783 public boolean isPrivateDataAvailable () 784 { 785 return privateDataAvailable; 786 } 787 788 642 789 private void finish() 643 790 { 644 791 if (!cancelled) 645 792 { 646 Logger.logMessage( "Storing result in cache + " + telname,793 Logger.logMessage( "Storing result in cache + " + privateDomain, 647 794 Options.KEY_LOG_APPLICATION ); 648 LookupResultDataStore.setLookupResult( telname, lookupResult );795 LookupResultDataStore.setLookupResult( privateDomain, lookupResult ); 649 796 650 797 Logger.logMessage( "Lookup complete", Options.KEY_LOG_APPLICATION ); … … 700 847 public String getTelname () 701 848 { 702 return telname;849 return privateDomain; 703 850 } 704 851 … … 730 877 } 731 878 879 public boolean isPrivateLookup() 880 { 881 return !(publicDomain.equals( privateDomain )); 882 } 732 883 733 884 public void setAutomated (boolean automated) -
apps/blackberry/branches/1.5/blackberry/src/org/telnic/blackberry/lookup/LookupWorker.java
r339 r567 42 42 * 43 43 * @author John Cundall, Ben Dowling 44 * @version $Id: LookupWorker.java,v 1.1 1 2008/12/19 15:06:58jm2 Exp $44 * @version $Id: LookupWorker.java,v 1.12 2009/11/06 11:55:31 jm2 Exp $ 45 45 */ 46 46 … … 96 96 */ 97 97 private boolean automated = false; 98 99 98 100 99 /** … … 112 111 } 113 112 114 115 113 /** 116 114 * setLookupWorkerCompletedListener. … … 122 120 completionListener = l; 123 121 } 124 125 122 126 123 /** … … 145 142 completeLookup( LookupCompleteActionListener.LOOKUP_COMPLETE_OK, queryType, answers ); 146 143 } 147 148 } 149 144 } 150 145 151 146 /** … … 309 304 } 310 305 311 312 306 /** 313 307 * doQuery. … … 323 317 } 324 318 325 326 319 /** 327 320 * Complete lookup. … … 356 349 public void run () 357 350 { 358 completionListener.lookupWorkerCompleted( status, type, answers );351 completionListener.lookupWorkerCompleted( status, type, answers, telname ); 359 352 } 360 361 353 } ); 362 354 } 363 355 } 364 356 365 366 357 public boolean isAutomated () 367 358 { … … 369 360 } 370 361 371 372 362 public void setAutomated (boolean automated) 373 363 {








