root/apps/outlook/branches/1.6/DotTelSystem/Lookup/LookupResult.cs
@
646
| Revision 646, 59.0 kB (checked in by jonmaycock, 3 years ago) |
|---|
| Line | |
|---|---|
| 1 | ///<summary> |
| 2 | /// Author: Ben Dowling & Nick Brunwin |
| 3 | ///------------------------ |
| 4 | ///Copyright (c) 2008, Telnic Ltd. |
| 5 | /// |
| 6 | ///All rights reserved. |
| 7 | /// |
| 8 | ///Redistribution and use in source and binary forms, with or |
| 9 | ///without modification, are permitted provided that the following |
| 10 | ///conditions are met: |
| 11 | /// |
| 12 | ///* Redistributions of source code must retain the above |
| 13 | /// copyright notice, this list of conditions and the |
| 14 | /// following disclaimer. |
| 15 | ///* Redistributions in binary form must reproduce the above |
| 16 | /// copyright notice, this list of conditions and the following |
| 17 | /// disclaimer in the documentation and/or other materials |
| 18 | /// provided with the distribution. |
| 19 | ///* Neither the name of the Telnic Ltd. nor the names of its |
| 20 | /// contributors may be used to endorse or promote products |
| 21 | /// derived from this software without specific prior written |
| 22 | /// permission. |
| 23 | /// |
| 24 | ///THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND |
| 25 | ///CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, |
| 26 | ///INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 27 | ///MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 28 | ///DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
| 29 | ///CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 30 | ///SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 31 | ///LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF |
| 32 | ///USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
| 33 | ///AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 34 | ///LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING |
| 35 | ///IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
| 36 | ///THE POSSIBILITY OF SUCH DAMAGE. |
| 37 | ///-------------------------- |
| 38 | ///</summary> |
| 39 | using System; |
| 40 | using org.telnic.outlook.dns; |
| 41 | using System.Xml; |
| 42 | using org.telnic.outlook.util; |
| 43 | using System.Collections; |
| 44 | using System.Collections.Generic; |
| 45 | using org.telnic.outlook.dns.records; |
| 46 | using org.telnic.outlook.dns.records.txt; |
| 47 | using org.telnic.outlook.uri; |
| 48 | using System.Text; |
| 49 | using org.telnic.outlook.prefs; |
| 50 | |
| 51 | namespace org.telnic.outlook.lookup |
| 52 | { |
| 53 | |
| 54 | /// <summary> The Class LookupResult.</summary> |
| 55 | [Serializable] |
| 56 | public class LookupResult |
| 57 | { |
| 58 | /// <summary> The Constant ONE_MONTH.</summary> |
| 59 | private const long ONE_MONTH = 60 * 60 * 24 * 30; |
| 60 | |
| 61 | /// <summary> The telname.</summary> |
| 62 | private string telname; |
| 63 | |
| 64 | private string publicTelname; |
| 65 | |
| 66 | /// <summary> The naptr records.</summary> |
| 67 | private System.Collections.ArrayList naptrRecords; |
| 68 | /// <summary> The status of the naptr lookup.</summary> |
| 69 | private LookupWorker.LookupStatus naptrStatus; |
| 70 | |
| 71 | public LookupWorker.LookupStatus NaptrStatus |
| 72 | { |
| 73 | set |
| 74 | { |
| 75 | naptrStatus = value; |
| 76 | } |
| 77 | get |
| 78 | { |
| 79 | return naptrStatus; |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | /// <summary> The txt records.</summary> |
| 84 | private System.Collections.ArrayList locRecords; |
| 85 | /// <summary> The status of the txt lookup.</summary> |
| 86 | private LookupWorker.LookupStatus locStatus; |
| 87 | |
| 88 | public LookupWorker.LookupStatus LocStatus |
| 89 | { |
| 90 | set |
| 91 | { |
| 92 | locStatus = value; |
| 93 | } |
| 94 | get |
| 95 | { |
| 96 | return locStatus; |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | /// <summary> The txt records.</summary> |
| 101 | private System.Collections.ArrayList txtRecords; |
| 102 | /// <summary> The status of the txt lookup.</summary> |
| 103 | private LookupWorker.LookupStatus txtStatus; |
| 104 | |
| 105 | public LookupWorker.LookupStatus TxtStatus |
| 106 | { |
| 107 | set |
| 108 | { |
| 109 | txtStatus = value; |
| 110 | } |
| 111 | get |
| 112 | { |
| 113 | return txtStatus; |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | /// <summary> The version records.</summary> |
| 118 | private System.Collections.ArrayList versionRecords; |
| 119 | /// <summary> The status of the txt lookup.</summary> |
| 120 | private LookupWorker.LookupStatus versionStatus; |
| 121 | |
| 122 | public LookupWorker.LookupStatus VersionStatus |
| 123 | { |
| 124 | set |
| 125 | { |
| 126 | versionStatus = value; |
| 127 | } |
| 128 | get |
| 129 | { |
| 130 | return versionStatus; |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | /// <summary> The txt records.</summary> |
| 135 | private System.Collections.ArrayList nInfoRecords; |
| 136 | /// <summary> The status of the txt lookup.</summary> |
| 137 | private LookupWorker.LookupStatus nInfoStatus; |
| 138 | |
| 139 | public LookupWorker.LookupStatus NInfoStatus |
| 140 | { |
| 141 | set |
| 142 | { |
| 143 | nInfoStatus = value; |
| 144 | } |
| 145 | get |
| 146 | { |
| 147 | return nInfoStatus; |
| 148 | } |
| 149 | } |
| 150 | |
| 151 | /// <summary> The keyword records.</summary> |
| 152 | private System.Collections.ArrayList keywordRecords; |
| 153 | /// <summary> The status of the keyword lookup.</summary> |
| 154 | private LookupWorker.LookupStatus keywordStatus; |
| 155 | |
| 156 | public LookupWorker.LookupStatus KeywordStatus |
| 157 | { |
| 158 | set |
| 159 | { |
| 160 | keywordStatus = value; |
| 161 | } |
| 162 | get |
| 163 | { |
| 164 | return keywordStatus; |
| 165 | } |
| 166 | } |
| 167 | |
| 168 | /// <summary> The long label records.</summary> |
| 169 | private System.Collections.ArrayList longLabelRecords; |
| 170 | |
| 171 | |
| 172 | /// <summary> |
| 173 | /// Check for equality based on matching resource records |
| 174 | /// don't compare TTL etc |
| 175 | /// </summary> |
| 176 | /// <param name="lr">The LookupResult to compare it to</param> |
| 177 | /// <returns>True if the results contain the same records</returns> |
| 178 | public bool Equals(LookupResult lr) |
| 179 | { |
| 180 | if (lr == null) |
| 181 | { |
| 182 | // return false if we got a successful lookup |
| 183 | if (naptrStatus == LookupWorker.LookupStatus.Ok && txtStatus == LookupWorker.LookupStatus.Ok |
| 184 | && locStatus == LookupWorker.LookupStatus.Ok && nInfoStatus == LookupWorker.LookupStatus.Ok |
| 185 | && keywordStatus == LookupWorker.LookupStatus.Ok && versionStatus == LookupWorker.LookupStatus.Ok) |
| 186 | { |
| 187 | return false; |
| 188 | } |
| 189 | // if we didn't get a successful lookup then we wouldn't have cached the result, |
| 190 | // so assume that there has been no change |
| 191 | return true; |
| 192 | } |
| 193 | |
| 194 | |
| 195 | // check if we've got the same telname |
| 196 | if (telname != lr.telname) return false; |
| 197 | |
| 198 | // check if we've got the same dds |
| 199 | if (ddsValue != lr.ddsValue) return false; |
| 200 | |
| 201 | // check if we've got the pddxVersion |
| 202 | if (pddxVersion != lr.pddxVersion) return false; |
| 203 | |
| 204 | // if neither of us have any records then we must be the same (empty) |
| 205 | if (!HasResults() && !lr.HasResults()) return true; |
| 206 | |
| 207 | // check that we have the same number of records |
| 208 | try |
| 209 | { |
| 210 | if (naptrRecords.Count != lr.NaptrRecords.Count) return false; |
| 211 | if (txtRecords.Count != lr.TxtRecords.Count) return false; |
| 212 | if (locRecords.Count != lr.LocRecords.Count) return false; |
| 213 | if (nInfoRecords.Count != lr.NInfoRecords.Count) return false; |
| 214 | if (keywordRecords.Count != lr.KeywordRecords.Count) return false; |
| 215 | if (longLabelRecords.Count != lr.longLabelRecords.Count) return false; |
| 216 | if (versionRecords.Count != lr.versionRecords.Count) return false; |
| 217 | } |
| 218 | catch (Exception) |
| 219 | { |
| 220 | // one of us doesn't have any records, so we can't be the same |
| 221 | return false; |
| 222 | } |
| 223 | |
| 224 | if (!this.CompareNaptrLists(naptrRecords, lr.naptrRecords)) |
| 225 | { |
| 226 | return false; |
| 227 | } |
| 228 | if (!this.CompareNaptrLists(lr.naptrRecords, naptrRecords)) |
| 229 | { |
| 230 | return false; |
| 231 | } |
| 232 | |
| 233 | if (!this.CompareTxtRecordLists(txtRecords, lr.txtRecords)) |
| 234 | { |
| 235 | return false; |
| 236 | } |
| 237 | if (!this.CompareTxtRecordLists(lr.txtRecords, txtRecords)) |
| 238 | { |
| 239 | return false; |
| 240 | } |
| 241 | |
| 242 | if (!this.CompareNInfoRecordLists(nInfoRecords, lr.NInfoRecords)) |
| 243 | { |
| 244 | return false; |
| 245 | } |
| 246 | if (!this.CompareNInfoRecordLists(lr.NInfoRecords, nInfoRecords)) |
| 247 | { |
| 248 | return false; |
| 249 | } |
| 250 | |
| 251 | if (!this.CompareLocRecordLists(locRecords, lr.locRecords)) |
| 252 | { |
| 253 | return false; |
| 254 | } |
| 255 | if (!this.CompareLocRecordLists(lr.locRecords, locRecords)) |
| 256 | { |
| 257 | return false; |
| 258 | } |
| 259 | |
| 260 | if (!this.CompareKeywordRecordLists(keywordRecords, lr.keywordRecords)) |
| 261 | { |
| 262 | return false; |
| 263 | } |
| 264 | if (!this.CompareKeywordRecordLists(lr.keywordRecords, keywordRecords)) |
| 265 | { |
| 266 | return false; |
| 267 | } |
| 268 | |
| 269 | if (!this.CompareLongLabelRecordLists(longLabelRecords, lr.longLabelRecords)) |
| 270 | { |
| 271 | return false; |
| 272 | } |
| 273 | if (!this.CompareLongLabelRecordLists(lr.longLabelRecords, longLabelRecords)) |
| 274 | { |
| 275 | return false; |
| 276 | } |
| 277 | |
| 278 | if (!this.CompareTxtRecordLists(versionRecords, lr.versionRecords)) |
| 279 | { |
| 280 | return false; |
| 281 | } |
| 282 | if (!this.CompareTxtRecordLists(lr.versionRecords, versionRecords)) |
| 283 | { |
| 284 | return false; |
| 285 | } |
| 286 | |
| 287 | return true; |
| 288 | } |
| 289 | |
| 290 | private bool CompareNaptrLists(ArrayList first, ArrayList second) |
| 291 | { |
| 292 | for (int i = 0; i < first.Count; i++) |
| 293 | { |
| 294 | bool notfound = true; |
| 295 | DNSTelnameNaptrResourceRecord r1 = (DNSTelnameNaptrResourceRecord)first[i]; |
| 296 | for (int j = 0; j < second.Count; j++) |
| 297 | { |
| 298 | DNSTelnameNaptrResourceRecord r2 = (DNSTelnameNaptrResourceRecord)second[j]; |
| 299 | // make sure both are the same type |
| 300 | // compare replaceStr if they're NTN |
| 301 | // compare URIs if they are terminal |
| 302 | if (r1.NonTerminal == r2.NonTerminal) |
| 303 | { |
| 304 | if ((r1.NonTerminal && r1.replaceStr == r2.replaceStr) |
| 305 | || (r1.Uri == r2.Uri && r1.ServiceStr == r2.ServiceStr)) |
| 306 | { |
| 307 | notfound = false; |
| 308 | break; |
| 309 | } |
| 310 | } |
| 311 | } |
| 312 | if (notfound) |
| 313 | { |
| 314 | return false; |
| 315 | } |
| 316 | } |
| 317 | return true; |
| 318 | } |
| 319 | |
| 320 | private bool CompareTxtRecordLists(ArrayList first, ArrayList second) |
| 321 | { |
| 322 | if (first.Count == second.Count) |
| 323 | { |
| 324 | foreach(DNSTxtResourceRecord r1 in first) |
| 325 | { |
| 326 | bool found = false; |
| 327 | foreach (DNSTxtResourceRecord r2 in second) |
| 328 | { |
| 329 | if (r1.Equals(r2)) |
| 330 | { |
| 331 | found = true; |
| 332 | } |
| 333 | } |
| 334 | if (!found) |
| 335 | { |
| 336 | return false; |
| 337 | } |
| 338 | } |
| 339 | return true; |
| 340 | } |
| 341 | return false; |
| 342 | } |
| 343 | |
| 344 | private bool CompareNInfoRecordLists(ArrayList first, ArrayList second) |
| 345 | { |
| 346 | if (first.Count == second.Count) |
| 347 | { |
| 348 | foreach (DNSNInfoResourceRecord r1 in first) |
| 349 | { |
| 350 | bool found = false; |
| 351 | foreach (DNSNInfoResourceRecord r2 in second) |
| 352 | { |
| 353 | if (r1.Equals(r2)) |
| 354 | { |
| 355 | found = true; |
| 356 | } |
| 357 | } |
| 358 | if (!found) |
| 359 | { |
| 360 | return false; |
| 361 | } |
| 362 | } |
| 363 | return true; |
| 364 | } |
| 365 | return false; |
| 366 | } |
| 367 | |
| 368 | private bool CompareKeywordRecordLists(ArrayList first, ArrayList second) |
| 369 | { |
| 370 | if (first.Count == second.Count) |
| 371 | { |
| 372 | foreach (DNSTxtResourceRecord r1 in first) |
| 373 | { |
| 374 | bool found = false; |
| 375 | foreach (DNSTxtResourceRecord r2 in second) |
| 376 | { |
| 377 | if (r1.Equals(r2)) |
| 378 | { |
| 379 | found = true; |
| 380 | } |
| 381 | } |
| 382 | if (!found) |
| 383 | { |
| 384 | return false; |
| 385 | } |
| 386 | } |
| 387 | return true; |
| 388 | } |
| 389 | return false; |
| 390 | } |
| 391 | |
| 392 | private bool CompareLongLabelRecordLists(ArrayList first, ArrayList second) |
| 393 | { |
| 394 | if (first.Count == second.Count) |
| 395 | { |
| 396 | foreach (DNSTxtResourceRecord r1 in first) |
| 397 | { |
| 398 | bool found = false; |
| 399 | foreach (DNSTxtResourceRecord r2 in second) |
| 400 | { |
| 401 | if (r1.Equals(r2)) |
| 402 | { |
| 403 | found = true; |
| 404 | } |
| 405 | } |
| 406 | if (!found) |
| 407 | { |
| 408 | return false; |
| 409 | } |
| 410 | } |
| 411 | return true; |
| 412 | } |
| 413 | return false; |
| 414 | } |
| 415 | |
| 416 | private bool CompareLocRecordLists(ArrayList first, ArrayList second) |
| 417 | { |
| 418 | for (int i = 0; i < first.Count; i++) |
| 419 | { |
| 420 | bool notfound = true; |
| 421 | DNSLocResourceRecord r1 = (DNSLocResourceRecord)first[i]; |
| 422 | for (int j = 0; j < second.Count; j++) |
| 423 | { |
| 424 | DNSLocResourceRecord r2 = (DNSLocResourceRecord)second[j]; |
| 425 | if (r1.Latitude == r2.Latitude && r1.Longitude == r2.Longitude) |
| 426 | { |
| 427 | notfound = false; |
| 428 | break; |
| 429 | } |
| 430 | } |
| 431 | if (notfound) |
| 432 | { |
| 433 | return false; |
| 434 | } |
| 435 | } |
| 436 | return true; |
| 437 | } |
| 438 | |
| 439 | /// <summary> |
| 440 | /// returns true if there is at least one actual result (TXT or NAPTR or LOC) |
| 441 | /// </summary> |
| 442 | /// <returns>true if there is at least one actual result (TXT or NAPTR or LOC)</returns> |
| 443 | public bool HasResults() |
| 444 | { |
| 445 | if (naptrRecords != null && naptrRecords.Count > 0) return true; |
| 446 | if (txtRecords != null && txtRecords.Count > 0) return true; |
| 447 | if (locRecords != null && locRecords.Count > 0) return true; |
| 448 | if (nInfoRecords != null && nInfoRecords.Count > 0) return true; |
| 449 | if (keywordRecords != null && keywordRecords.Count > 0) return true; |
| 450 | if (longLabelRecords != null && longLabelRecords.Count > 0) return true; |
| 451 | //Version Records deliberately not included |
| 452 | |
| 453 | return false; |
| 454 | } |
| 455 | |
| 456 | /// <summary> stores the time (in seconds) that this record was last updated</summary> |
| 457 | private long updated = 0; |
| 458 | |
| 459 | // stores how long this record is valid for in seconds |
| 460 | // record expires at (updated + ttl) seconds |
| 461 | /// <summary> The ttl.</summary> |
| 462 | private long ttl = LookupResult.ONE_MONTH; |
| 463 | |
| 464 | |
| 465 | /// <summary> The Constructor. |
| 466 | /// |
| 467 | /// </summary> |
| 468 | /// <param name="telname">the telname |
| 469 | /// </param> |
| 470 | public LookupResult(string telname, string publicTelname) |
| 471 | { |
| 472 | this.telname = telname; |
| 473 | this.publicTelname = publicTelname; |
| 474 | } |
| 475 | |
| 476 | |
| 477 | // returns how many seconds this lookup is valid for |
| 478 | /// <summary> Valid for. |
| 479 | /// |
| 480 | /// </summary> |
| 481 | /// <returns> the long |
| 482 | /// </returns> |
| 483 | public virtual long validFor() |
| 484 | { |
| 485 | // none of the results should be null, so if they are set ttl to 0 |
| 486 | if (txtRecords == null && naptrRecords == null && locRecords == null && nInfoRecords == null && keywordRecords == null && versionRecords == null) |
| 487 | { |
| 488 | ttl = 0; |
| 489 | } // if we don't have any actual results we can't work out a ttl, so set to 0 |
| 490 | else if (txtRecords.Count == 0 && naptrRecords.Count == 0 && locRecords.Count == 0 && nInfoRecords.Count == 0 && keywordRecords.Count == 0 && versionRecords.Count == 0) |
| 491 | { |
| 492 | ttl = 0; |
| 493 | } |
| 494 | return (updated + ttl) - ((System.DateTime.Now.Ticks - 621355968000000000) / 10000 / 1000); |
| 495 | } |
| 496 | |
| 497 | /// <summary> Gets the naptr records. |
| 498 | /// |
| 499 | /// </summary> |
| 500 | /// <returns> the naptr records |
| 501 | /// </returns> |
| 502 | /// <summary> Sets the naptr records. If there are any long labels matching a naptr it updates it's long label field |
| 503 | /// |
| 504 | /// </summary> |
| 505 | /// <param name="naptrRecords">the naptr records |
| 506 | /// </param> |
| 507 | virtual public System.Collections.ArrayList NaptrRecords |
| 508 | { |
| 509 | get |
| 510 | { |
| 511 | lock (this) |
| 512 | { |
| 513 | return naptrRecords; |
| 514 | } |
| 515 | } |
| 516 | |
| 517 | set |
| 518 | { |
| 519 | lock (this) |
| 520 | { |
| 521 | this.naptrRecords = value; |
| 522 | //naptrRecords.Sort(); |
| 523 | updated = (System.DateTime.Now.Ticks - 621355968000000000) / 10000 / 1000; |
| 524 | setMinTtl(this.naptrRecords); |
| 525 | if (!(this.longLabelRecords == null)) |
| 526 | { |
| 527 | foreach (DNSTelnameNaptrResourceRecord naptr in this.naptrRecords) |
| 528 | { |
| 529 | foreach (DNSLongLabelTxtResourceRecord label in this.longLabelRecords) |
| 530 | { |
| 531 | if ((naptr.Order == label.Order) && (naptr.Preference == label.Priority)) |
| 532 | { |
| 533 | Logger.Log(Logger.Section.Lookups, "Long label matched " + label.TxtStr); |
| 534 | naptr.LongLabels = label.LongLabels; |
| 535 | } |
| 536 | } |
| 537 | } |
| 538 | } |
| 539 | } |
| 540 | } |
| 541 | |
| 542 | } |
| 543 | |
| 544 | virtual public System.Collections.ArrayList LocRecords |
| 545 | { |
| 546 | get |
| 547 | { |
| 548 | lock (this) |
| 549 | { |
| 550 | return locRecords; |
| 551 | } |
| 552 | } |
| 553 | |
| 554 | set |
| 555 | { |
| 556 | lock (this) |
| 557 | { |
| 558 | this.locRecords = value; |
| 559 | updated = (System.DateTime.Now.Ticks - 621355968000000000) / 10000 / 1000; |
| 560 | setMinTtl(this.locRecords); |
| 561 | } |
| 562 | } |
| 563 | } |
| 564 | |
| 565 | virtual public System.Collections.ArrayList NInfoRecords |
| 566 | { |
| 567 | get |
| 568 | { |
| 569 | lock (this) |
| 570 | { |
| 571 | return this.nInfoRecords; |
| 572 | } |
| 573 | } |
| 574 | |
| 575 | set |
| 576 | { |
| 577 | lock (this) |
| 578 | { |
| 579 | this.nInfoRecords = value; |
| 580 | this.updated = (System.DateTime.Now.Ticks - 621355968000000000) / 10000 / 1000; |
| 581 | this.setMinTtl(this.nInfoRecords); |
| 582 | } |
| 583 | } |
| 584 | } |
| 585 | |
| 586 | /// <summary> |
| 587 | /// Checks for existing Naptrs and tries to match them to update their longLabel field |
| 588 | /// </summary> |
| 589 | virtual public System.Collections.ArrayList LongLabelRecords |
| 590 | { |
| 591 | get |
| 592 | { |
| 593 | lock (this) |
| 594 | { |
| 595 | return this.longLabelRecords; |
| 596 | } |
| 597 | } |
| 598 | |
| 599 | set |
| 600 | { |
| 601 | lock (this) |
| 602 | { |
| 603 | this.longLabelRecords = value; |
| 604 | //naptrRecords.Sort(); |
| 605 | this.updated = (System.DateTime.Now.Ticks - 621355968000000000) / 10000 / 1000; |
| 606 | this.setMinTtl(this.longLabelRecords); |
| 607 | |
| 608 | if (!(this.naptrRecords == null)) |
| 609 | { |
| 610 | foreach (DNSTelnameNaptrResourceRecord naptr in this.naptrRecords) |
| 611 | { |
| 612 | foreach (DNSLongLabelTxtResourceRecord label in this.longLabelRecords) |
| 613 | { |
| 614 | if ((naptr.Order == label.Order) && (naptr.Preference == label.Priority)) |
| 615 | { |
| 616 | Logger.Log(Logger.Section.Lookups, "Long label matched " + label.TxtStr); |
| 617 | naptr.LongLabels = label.LongLabels; |
| 618 | } |
| 619 | } |
| 620 | } |
| 621 | } |
| 622 | } |
| 623 | } |
| 624 | } |
| 625 | |
| 626 | |
| 627 | |
| 628 | /// <summary> Gets the txt records. |
| 629 | /// |
| 630 | /// </summary> |
| 631 | /// <returns> the txt records |
| 632 | /// </returns> |
| 633 | /// <summary> Sets the txt records. |
| 634 | /// Removes and process service messages. Removes keywords. Removes long labels and adds them to their own list. |
| 635 | /// </summary> |
| 636 | /// <param name="txtRecords">the txt records |
| 637 | /// </param> |
| 638 | virtual public System.Collections.ArrayList TxtRecords |
| 639 | { |
| 640 | get |
| 641 | { |
| 642 | lock (this) |
| 643 | { |
| 644 | return txtRecords; |
| 645 | } |
| 646 | } |
| 647 | |
| 648 | set |
| 649 | { |
| 650 | lock (this) |
| 651 | { |
| 652 | if (this.txtRecords == null) |
| 653 | { |
| 654 | this.txtRecords = value; |
| 655 | } |
| 656 | else |
| 657 | { |
| 658 | this.txtRecords.AddRange(value); |
| 659 | } |
| 660 | Logger.Log(Logger.Section.Lookups, this.txtRecords.Count + " txt entries found."); |
| 661 | updated = (System.DateTime.Now.Ticks - 621355968000000000) / 10000 / 1000; |
| 662 | setMinTtl(this.txtRecords); |
| 663 | //interpret understood service messages |
| 664 | List<DNSTxtResourceRecord> toBeRemoved = new List<DNSTxtResourceRecord>(); |
| 665 | ArrayList addLongLabels = new ArrayList(); |
| 666 | this.txtRecords.Reverse(); |
| 667 | foreach (DNSTxtResourceRecord txtRecord in this.txtRecords) |
| 668 | { |
| 669 | if (typeof(DNSTxtServiceMessageResourceRecord).IsInstanceOfType(txtRecord)) |
| 670 | { |
| 671 | ((DNSTxtServiceMessageResourceRecord)txtRecord).Process(this); |
| 672 | toBeRemoved.Add((DNSTxtResourceRecord)txtRecord); |
| 673 | } |
| 674 | if (typeof(DNSLongLabelTxtResourceRecord).IsInstanceOfType(txtRecord)) |
| 675 | { |
| 676 | addLongLabels.Add((DNSLongLabelTxtResourceRecord)txtRecord); |
| 677 | toBeRemoved.Add((DNSTxtResourceRecord)txtRecord); |
| 678 | } |
| 679 | if (typeof(DNSStructuredKeywordsTxtResourceRecord).IsInstanceOfType(txtRecord)) |
| 680 | { |
| 681 | toBeRemoved.Add((DNSTxtResourceRecord)txtRecord); |
| 682 | } |
| 683 | } |
| 684 | foreach (DNSTxtResourceRecord o in toBeRemoved) |
| 685 | { |
| 686 | this.txtRecords.Remove(o); |
| 687 | } |
| 688 | this.LongLabelRecords = addLongLabels; |
| 689 | } |
| 690 | } |
| 691 | } |
| 692 | |
| 693 | /// <summary> |
| 694 | /// Removes and process service messages. Removes keywords. Removes long labels and adds them to their own list. |
| 695 | /// </summary> |
| 696 | virtual public System.Collections.ArrayList VersionRecords |
| 697 | { |
| 698 | get |
| 699 | { |
| 700 | lock (this) |
| 701 | { |
| 702 | return versionRecords; |
| 703 | } |
| 704 | } |
| 705 | |
| 706 | set |
| 707 | { |
| 708 | lock (this) |
| 709 | { |
| 710 | this.versionRecords = value; |
| 711 | this.versionRecords.Reverse() ; |
| 712 | updated = (System.DateTime.Now.Ticks - 621355968000000000) / 10000 / 1000; |
| 713 | setMinTtl(this.versionRecords); |
| 714 | ArrayList toBeRemoved = new ArrayList(); |
| 715 | ArrayList pddxRecords = new ArrayList(); |
| 716 | ArrayList addKeywords = new ArrayList(); |
| 717 | ArrayList addLongLabels = new ArrayList(); |
| 718 | foreach (DNSTxtResourceRecord versionRecord in this.versionRecords) |
| 719 | { |
| 720 | if (typeof(DNSPDDXTxtServiceMessageResourceRecord).IsInstanceOfType(versionRecord)) |
| 721 | { |
| 722 | Logger.Log(Logger.Section.Lookups, "Version Record Found pddxVersion = " + PddxVersion); |
| 723 | pddxRecords.Add((DNSPDDXTxtServiceMessageResourceRecord)versionRecord); |
| 724 | ((DNSPDDXTxtServiceMessageResourceRecord)versionRecord).Process(this); |
| 725 | Logger.Log(Logger.Section.Lookups, "Version Record Found pddxVersion = " + PddxVersion); |
| 726 | toBeRemoved.Add((DNSTxtResourceRecord)versionRecord); |
| 727 | } |
| 728 | if (typeof(DNSStructuredKeywordsTxtResourceRecord).IsInstanceOfType(versionRecord)) |
| 729 | { |
| 730 | addKeywords.Add((DNSStructuredKeywordsTxtResourceRecord)versionRecord); |
| 731 | toBeRemoved.Add((DNSTxtResourceRecord)versionRecord); |
| 732 | } |
| 733 | if (typeof(DNSDDSTxtServiceMessageResourceRecord).IsInstanceOfType(versionRecord)) |
| 734 | { |
| 735 | ((DNSDDSTxtServiceMessageResourceRecord)versionRecord).Process(this); |
| 736 | toBeRemoved.Add((DNSTxtResourceRecord)versionRecord); |
| 737 | } |
| 738 | if (typeof(DNSLongLabelTxtResourceRecord).IsInstanceOfType(versionRecord)) |
| 739 | { |
| 740 | addLongLabels.Add((DNSLongLabelTxtResourceRecord)versionRecord); |
| 741 | toBeRemoved.Add((DNSTxtResourceRecord)versionRecord); |
| 742 | } |
| 743 | |
| 744 | } |
| 745 | foreach (DNSTxtResourceRecord o in toBeRemoved) |
| 746 | { |
| 747 | this.versionRecords.Remove(o); |
| 748 | } |
| 749 | this.txtRecords = this.versionRecords; |
| 750 | this.versionRecords = pddxRecords; |
| 751 | this.KeywordRecords = addKeywords; |
| 752 | this.LongLabelRecords = addLongLabels; |
| 753 | } |
| 754 | } |
| 755 | } |
| 756 | |
| 757 | /// <summary> |
| 758 | /// Removes any records which aren't keywords |
| 759 | /// </summary> |
| 760 | virtual public System.Collections.ArrayList KeywordRecords |
| 761 | { |
| 762 | get |
| 763 | { |
| 764 | lock (this) |
| 765 | { |
| 766 | return keywordRecords; |
| 767 | } |
| 768 | } |
| 769 | |
| 770 | set |
| 771 | { |
| 772 | lock (this) |
| 773 | { |
| 774 | this.keywordRecords = value; |
| 775 | //Logger.Log(Logger.Section.Lookups, this.keywordRecords.Count + " keyword entries found when PDDX <> 1."); |
| 776 | //txtRecords.Sort(); |
| 777 | updated = (System.DateTime.Now.Ticks - 621355968000000000) / 10000 / 1000; |
| 778 | setMinTtl(this.keywordRecords); |
| 779 | //get rid of service messages so they don't get in the way |
| 780 | List<DNSTxtResourceRecord> toBeRemoved = new List<DNSTxtResourceRecord>(); |
| 781 | foreach (DNSTxtResourceRecord txtRecord in this.keywordRecords) |
| 782 | { |
| 783 | if (!typeof(DNSStructuredKeywordsTxtResourceRecord).IsInstanceOfType(txtRecord)) |
| 784 | { |
| 785 | toBeRemoved.Add((DNSTxtResourceRecord)txtRecord); |
| 786 | } |
| 787 | } |
| 788 | foreach (DNSTxtResourceRecord o in toBeRemoved) |
| 789 | { |
| 790 | this.keywordRecords.Remove(o); |
| 791 | } |
| 792 | |
| 793 | } |
| 794 | } |
| 795 | |
| 796 | } |
| 797 | |
| 798 | |
| 799 | |
| 800 | |
| 801 | private bool canBeFriended = true; |
| 802 | /// <summary> |
| 803 | /// True if the domain this result is for can be friended |
| 804 | /// </summary> |
| 805 | public bool CanBeFriended |
| 806 | { |
| 807 | get |
| 808 | { |
| 809 | return this.canBeFriended; |
| 810 | } |
| 811 | |
| 812 | set |
| 813 | { |
| 814 | this.canBeFriended = value; |
| 815 | } |
| 816 | } |
| 817 | |
| 818 | private string pddxVersion = ""; |
| 819 | /// <summary> |
| 820 | /// The Version found in the PDDX version record |
| 821 | /// </summary> |
| 822 | public string PddxVersion |
| 823 | { |
| 824 | get |
| 825 | { |
| 826 | return this.pddxVersion; |
| 827 | } |
| 828 | |
| 829 | set |
| 830 | { |
| 831 | this.pddxVersion = value; |
| 832 | } |
| 833 | } |
| 834 | |
| 835 | private string ddsValue = null; |
| 836 | /// <summary> |
| 837 | /// Returns the vlaue of the DDS |
| 838 | /// </summary> |
| 839 | public string DdsValue |
| 840 | { |
| 841 | get |
| 842 | { |
| 843 | return this.ddsValue; |
| 844 | } |
| 845 | |
| 846 | set |
| 847 | { |
| 848 | this.ddsValue = value; |
| 849 | } |
| 850 | } |
| 851 | |
| 852 | /// <summary> Gets the telname. |
| 853 | /// |
| 854 | /// </summary> |
| 855 | /// <returns> the telname |
| 856 | /// </returns> |
| 857 | virtual public System.String Telname |
| 858 | { |
| 859 | get |
| 860 | { |
| 861 | return telname; |
| 862 | } |
| 863 | } |
| 864 | |
| 865 | /// <summary> |
| 866 | /// Gets the telname for this result that should be presented to the user |
| 867 | /// </summary> |
| 868 | virtual public string PublicTelname |
| 869 | { |
| 870 | get |
| 871 | { |
| 872 | return this.publicTelname; |
| 873 | } |
| 874 | } |
| 875 | |
| 876 | /// <summary> Checks if is valid. |
| 877 | /// Return true if this result has expired |
| 878 | /// ie. the time now is past the ttl |
| 879 | /// </summary> |
| 880 | /// <returns> true, if is valid |
| 881 | /// </returns> |
| 882 | virtual public bool Valid |
| 883 | { |
| 884 | |
| 885 | get |
| 886 | { |
| 887 | try |
| 888 | { |
| 889 | long valid = validFor(); |
| 890 | return valid >= -1; |
| 891 | } |
| 892 | catch (Exception) |
| 893 | { |
| 894 | return false; |
| 895 | } |
| 896 | } |
| 897 | |
| 898 | } |
| 899 | |
| 900 | /// <summary> |
| 901 | /// set the ttl of this object to the minimum ttl of all the given records |
| 902 | /// </summary> |
| 903 | /// <param name="resourceRecords"></param> |
| 904 | private void setMinTtl(System.Collections.ArrayList resourceRecords) |
| 905 | { |
| 906 | foreach (DNSResourceRecord d in resourceRecords) |
| 907 | { |
| 908 | long currentTtl = d.TTL; |
| 909 | if (currentTtl < ttl) |
| 910 | { |
| 911 | ttl = currentTtl; |
| 912 | } |
| 913 | } |
| 914 | } |
| 915 | |
| 916 | private static string[] specialDomains = null; |
| 917 | |
| 918 | /// <summary> |
| 919 | /// Evaluates whether the domain is a special domain name that doesn't get displayed to the user |
| 920 | /// </summary> |
| 921 | /// <param name="domain">The domain name that may be special</param> |
| 922 | /// <returns>True if the domain name is special</returns> |
| 923 | private static bool IsSpecialDomain(string domain) |
| 924 | { |
| 925 | if(LookupResult.specialDomains == null) |
| 926 | { |
| 927 | LookupResult.specialDomains = Preferences.GetPreference("list.specialdomains").Split(','); |
| 928 | } |
| 929 | foreach (string dom in LookupResult.specialDomains) |
| 930 | { |
| 931 | if (dom == domain) |
| 932 | { |
| 933 | return true; |
| 934 | } |
| 935 | } |
| 936 | return false; |
| 937 | } |
| 938 | |
| 939 | /// <summary> |
| 940 | /// Generates an XML representation of this results object |
| 941 | /// </summary> |
| 942 | /// <returns></returns> |
| 943 | public XmlElement XML() |
| 944 | { |
| 945 | // create the root element |
| 946 | XmlDocument doc = new XmlDocument(); |
| 947 | XmlElement root = doc.CreateElement("TelnicLookupResults"); |
| 948 | |
| 949 | // create child nodes and add them |
| 950 | XmlElement domainElement = doc.CreateElement("Domain"); |
| 951 | if (TelnameChecker.IsEnum(telname)) |
| 952 | { |
| 953 | domainElement.InnerText = UriHandler.getInstance().FormatEnum(telname); |
| 954 | } |
| 955 | else |
| 956 | { |
| 957 | //domainElement.InnerText = this.publicTelname; |
| 958 | //string[] crumbs = this.publicTelname.Substring(0, this.publicTelname.Length - 4).Split('.'); |
| 959 | string[] crumbs = this.publicTelname.Substring(0, this.publicTelname.Length - 4).Split('.'); |
| 960 | if (crumbs.Length > 0) |
| 961 | { |
| 962 | if (LookupResult.IsSpecialDomain(crumbs[crumbs.Length - 1]) && (crumbs.Length > 1)) |
| 963 | { |
| 964 | domainElement.InnerText = crumbs[crumbs.Length - 2]; |
| 965 | } |
| 966 | else |
| 967 | { |
| 968 | domainElement.InnerText = crumbs[crumbs.Length - 1]; |
| 969 | } |
| 970 | XmlElement crumbsElement = doc.CreateElement("Crumbs"); |
| 971 | for (int i = 0; i < crumbs.Length; i++) |
| 972 | { |
| 973 | XmlElement crumbElement = doc.CreateElement("Crumb"); |
| 974 | XmlElement crumbNameElement = doc.CreateElement("CrumbName"); |
| 975 | crumbNameElement.InnerText = Gnu.Inet.Encoding.IDNA.ToUnicode(crumbs[i]); |
| 976 | crumbElement.AppendChild(crumbNameElement); |
| 977 | if (i > 0) |
| 978 | { |
| 979 | StringBuilder s = new StringBuilder(); |
| 980 | for (int j = i; j < crumbs.Length; j++) |
| 981 | { |
| 982 | s.Append(crumbs[j]); |
| 983 | s.Append('.'); |
| 984 | } |
| 985 | s.Append("tel"); |
| 986 | XmlElement crumbLinkElement = doc.CreateElement("CrumbLink"); |
| 987 | crumbLinkElement.InnerText = s.ToString(); |
| 988 | crumbElement.AppendChild(crumbLinkElement); |
| 989 | } |
| 990 | crumbsElement.AppendChild(crumbElement); |
| 991 | } |
| 992 | root.AppendChild(crumbsElement); |
| 993 | } |
| 994 | else |
| 995 | { |
| 996 | domainElement.InnerText = crumbs[crumbs.Length - 1]; |
| 997 | } |
| 998 | } |
| 999 | root.AppendChild(domainElement); |
| 1000 | |
| 1001 | if (naptrStatus != LookupWorker.LookupStatus.Ok) |
| 1002 | { |
| 1003 | XmlElement naptrStatusElement = doc.CreateElement("NaptrErrorStatus"); |
| 1004 | naptrStatusElement.InnerText = LookupWorker.FormatStatus(NaptrStatus); |
| 1005 | root.AppendChild(naptrStatusElement); |
| 1006 | } |
| 1007 | |
| 1008 | if (keywordStatus != LookupWorker.LookupStatus.Ok) |
| 1009 | { |
| 1010 | XmlElement keywordStatusElement = doc.CreateElement("KeywordErrorStatus"); |
| 1011 | keywordStatusElement.InnerText = LookupWorker.FormatStatus(KeywordStatus); |
| 1012 | root.AppendChild(keywordStatusElement); |
| 1013 | } |
| 1014 | |
| 1015 | if (txtStatus != LookupWorker.LookupStatus.Ok) |
| 1016 | { |
| 1017 | XmlElement txtStatusElement = doc.CreateElement("TxtRecordErrorStatus"); |
| 1018 | txtStatusElement.InnerText = LookupWorker.FormatStatus(TxtStatus); |
| 1019 | root.AppendChild(txtStatusElement); |
| 1020 | } |
| 1021 | |
| 1022 | if (locStatus != LookupWorker.LookupStatus.Ok) |
| 1023 | { |
| 1024 | XmlElement locStatusElement = doc.CreateElement("LocRecordErrorStatus"); |
| 1025 | locStatusElement.InnerText = LookupWorker.FormatStatus(LocStatus); |
| 1026 | root.AppendChild(locStatusElement); |
| 1027 | } |
| 1028 | |
| 1029 | if (this.nInfoStatus != LookupWorker.LookupStatus.Ok) |
| 1030 | { |
| 1031 | XmlElement nInfoStatusElement = doc.CreateElement("NInfoRecordErrorStatus"); |
| 1032 | nInfoStatusElement.InnerText = LookupWorker.FormatStatus(this.nInfoStatus); |
| 1033 | root.AppendChild(nInfoStatusElement); |
| 1034 | } |
| 1035 | if (this.naptrRecords.Count == 0 && this.locRecords.Count == 0 && this.txtRecords.Count == 0 && (this.nInfoRecords == null || this.nInfoRecords.Count == 0 ) |
| 1036 | && (this.keywordRecords == null || this.keywordRecords.Count == 0)) |
| 1037 | { |
| 1038 | XmlElement messageElement = doc.CreateElement("Message"); |
| 1039 | messageElement.InnerText = DotTelSystem.Properties.Resources.LookUpResult_Message_NoRecordsExistOnThisDomain; |
| 1040 | root.AppendChild(messageElement); |
| 1041 | } |
| 1042 | |
| 1043 | XmlElement ttlElement = doc.CreateElement("ValidFor"); |
| 1044 | try |
| 1045 | { |
| 1046 | ttlElement.InnerText = validFor().ToString(); |
| 1047 | } |
| 1048 | catch (Exception) |
| 1049 | { |
| 1050 | ttlElement.InnerText = ""; |
| 1051 | } |
| 1052 | root.AppendChild(ttlElement); |
| 1053 | |
| 1054 | XmlElement lastLookUpTimeElement = doc.CreateElement("LastLookUpTime"); |
| 1055 | DateTime lastLookUpDateTime = new DateTime((this.updated * 10000000L) + 621355968000000000); |
| 1056 | lastLookUpTimeElement.InnerXml = System.Xml.XmlConvert.ToString(lastLookUpDateTime, |
| 1057 | XmlDateTimeSerializationMode.Local); |
| 1058 | root.AppendChild(lastLookUpTimeElement); |
| 1059 | |
| 1060 | if (this.ddsValue != null) |
| 1061 | { |
| 1062 | XmlElement ddsValueElement = doc.CreateElement("ddsValue"); |
| 1063 | Logger.Log(Logger.Section.Results_Screen, "DDS - " + this.ddsValue); |
| 1064 | ddsValueElement.InnerXml = GetSafeValue(this.ddsValue); |
| 1065 | Logger.Log(Logger.Section.Results_Screen, "DDS - " + ddsValueElement.InnerXml); |
| 1066 | root.AppendChild(ddsValueElement); |
| 1067 | } |
| 1068 | |
| 1069 | |
| 1070 | |
| 1071 | // add the NAPTR results |
| 1072 | XmlElement naptrResultsElement = doc.CreateElement("NaptrResults"); |
| 1073 | root.AppendChild(naptrResultsElement); |
| 1074 | |
| 1075 | if (NaptrRecords != null) |
| 1076 | { |
| 1077 | foreach (DNSTelnameNaptrResourceRecord rr in NaptrRecords) |
| 1078 | { |
| 1079 | |
| 1080 | if (rr.NonTerminal) |
| 1081 | { |
| 1082 | XmlElement naptrRecord = doc.CreateElement("NonTerminalNaptrRecord"); |
| 1083 | naptrResultsElement.AppendChild(naptrRecord); |
| 1084 | |
| 1085 | XmlElement displayElement = doc.CreateElement("DisplayName"); |
| 1086 | displayElement.InnerText = rr.NTNDisplayName; |
| 1087 | naptrRecord.AppendChild(displayElement); |
| 1088 | |
| 1089 | Logger.Log(Logger.Section.Results_Screen, "Non terminal: " + rr.ReplaceStr); |
| 1090 | XmlElement uriElement = doc.CreateElement("Uri"); |
| 1091 | uriElement.InnerText = Uri.UnescapeDataString(rr.ReplaceStr).Replace("\\", "\\\\"); |
| 1092 | naptrRecord.AppendChild(uriElement); |
| 1093 | |
| 1094 | if (rr.LongLabels.Count > 0) |
| 1095 | { |
| 1096 | XmlElement longLabelsElement = doc.CreateElement("LongLabels"); |
| 1097 | foreach (string longLabel in rr.LongLabels) |
| 1098 | { |
| 1099 | XmlElement longLabelElement = doc.CreateElement("LongLabel"); |
| 1100 | XmlElement longLabelNameElement = doc.CreateElement("LongLabelName"); |
| 1101 | |
| 1102 | longLabelNameElement.InnerText = GetSafeValue(longLabel); |
| 1103 | longLabelElement.AppendChild(longLabelNameElement); |
| 1104 | longLabelsElement.AppendChild(longLabelElement); |
| 1105 | } |
| 1106 | naptrRecord.AppendChild(longLabelsElement); |
| 1107 | } |
| 1108 | } |
| 1109 | else |
| 1110 | { |
| 1111 | if (UriHandler.getInstance().Launchable(rr.ServiceType) || |
| 1112 | (typeof(DNSUnlinkedTelnameNaptrResourceRecord).IsInstanceOfType(rr) && ((DNSUnlinkedTelnameNaptrResourceRecord)rr).Display)) |
| 1113 | { |
| 1114 | XmlElement naptrRecord = doc.CreateElement("TerminalNaptrRecord"); |
| 1115 | naptrResultsElement.AppendChild(naptrRecord); |
| 1116 | |
| 1117 | XmlElement serviceElement = doc.CreateElement("ServiceType"); |
| 1118 | serviceElement.InnerText = rr.ServiceType; |
| 1119 | naptrRecord.AppendChild(serviceElement); |
| 1120 | |
| 1121 | XmlElement serviceNameElement = doc.CreateElement("ServiceName"); |
| 1122 | serviceNameElement.InnerText = UriHandler.getInstance().ServiceName(rr.ServiceType); |
| 1123 | naptrRecord.AppendChild(serviceNameElement); |
| 1124 | |
| 1125 | XmlElement uriElement = doc.CreateElement("Uri"); |
| 1126 | uriElement.InnerText = rr.Uri.Replace("\\", "\\\\"); |
| 1127 | naptrRecord.AppendChild(uriElement); |
| 1128 | |
| 1129 | XmlElement nameElement = doc.CreateElement("Name"); |
| 1130 | |
| 1131 | if (typeof(DNSUnlinkedTelnameNaptrResourceRecord).IsInstanceOfType(rr)) |
| 1132 | { |
| 1133 | nameElement.InnerText = ((DNSUnlinkedTelnameNaptrResourceRecord)rr).Text; |
| 1134 | } |
| 1135 | else |
| 1136 | { |
| 1137 | nameElement.InnerText = UriHandler.getInstance().Format(rr.ServiceType, rr.Uri); |
| 1138 | XmlElement launchElement = doc.CreateElement("Launchable"); |
| 1139 | launchElement.InnerText = "true"; |
| 1140 | naptrRecord.AppendChild(launchElement); |
| 1141 | } |
| 1142 | naptrRecord.AppendChild(nameElement); |
| 1143 | |
| 1144 | XmlElement categoriesElement = doc.CreateElement("LocationIndicatorHints"); |
| 1145 | XmlElement categoriesCountElement = doc.CreateElement("Count"); |
| 1146 | categoriesCountElement.InnerText = rr.Catagories.Count.ToString(); |
| 1147 | categoriesElement.AppendChild(categoriesCountElement); |
| 1148 | |
| 1149 | foreach (string lih in rr.Catagories) |
| 1150 | { |
| 1151 | XmlElement categoryElement = doc.CreateElement("LocationIndicatorHint"); |
| 1152 | XmlElement categoryNameElement = doc.CreateElement("Name"); |
| 1153 | categoryNameElement.InnerText = lih; |
| 1154 | categoryElement.AppendChild(categoryNameElement); |
| 1155 | XmlElement categoryPTElement = doc.CreateElement("PresentedText"); |
| 1156 | categoryPTElement.InnerText = DNSTelnameNaptrResourceRecord.GetLocationIndicatorHintPresentedText(lih); |
| 1157 | categoryElement.AppendChild(categoryPTElement); |
| 1158 | categoriesElement.AppendChild(categoryElement); |
| 1159 | } |
| 1160 | |
| 1161 | XmlElement concatenatedCategoriesElement = doc.CreateElement("ConcatenatedCategories"); |
| 1162 | if (rr.Catagories.Count > 0) |
| 1163 | { |
| 1164 | string[] cats = rr.Catagories.ToArray(); |
| 1165 | for (int i = 0; i < cats.Length; i++) |
| 1166 | { |
| 1167 | cats[i] = DNSTelnameNaptrResourceRecord.GetLocationIndicatorHintPresentedText(cats[i]); |
| 1168 | } |
| 1169 | concatenatedCategoriesElement.InnerText = String.Join( |
| 1170 | DotTelSystem.Properties.Resources.LookUpResult_LocationIndicatorHintsSeparator, cats); |
| 1171 | } |
| 1172 | else |
| 1173 | { |
| 1174 | concatenatedCategoriesElement.InnerText = " "; |
| 1175 | } |
| 1176 | categoriesElement.AppendChild(concatenatedCategoriesElement); |
| 1177 | |
| 1178 | naptrRecord.AppendChild(categoriesElement); |
| 1179 | |
| 1180 | XmlElement iconElement = doc.CreateElement("Icon"); |
| 1181 | iconElement.InnerText = UriHandler.getInstance().GetIcon(rr.ServiceType, rr.Catagories, rr.WasEncrypted); |
| 1182 | naptrRecord.AppendChild(iconElement); |
| 1183 | |
| 1184 | XmlElement labelsElement = doc.CreateElement("XLabels"); |
| 1185 | XmlElement xlblCount = doc.CreateElement("Count"); |
| 1186 | xlblCount.InnerText = rr.Labels.Count.ToString(); |
| 1187 | labelsElement.AppendChild(xlblCount); |
| 1188 | foreach (string label in rr.Labels) |
| 1189 | { |
| 1190 | XmlElement labelElement = doc.CreateElement("XLabel"); |
| 1191 | XmlElement labelNameElement = doc.CreateElement("XLabelName"); |
| 1192 | labelNameElement.InnerText = GetSafeValue(label).Replace('-', ' ').Replace(':', ' '); |
| 1193 | labelElement.AppendChild(labelNameElement); |
| 1194 | labelsElement.AppendChild(labelElement); |
| 1195 | } |
| 1196 | naptrRecord.AppendChild(labelsElement); |
| 1197 | |
| 1198 | if (rr.LongLabels.Count > 0) |
| 1199 | { |
| 1200 | Logger.Log(Logger.Section.Results_Screen, "Long Label count: " + rr.LongLabels.Count); |
| 1201 | XmlElement longLabelsElement = doc.CreateElement("LongLabels"); |
| 1202 | foreach (string longLabel in rr.LongLabels) |
| 1203 | { |
| 1204 | XmlElement longLabelElement = doc.CreateElement("LongLabel"); |
| 1205 | XmlElement longLabelNameElement = doc.CreateElement("LongLabelName"); |
| 1206 | longLabelNameElement.InnerText = GetSafeValue(longLabel); |
| 1207 | longLabelElement.AppendChild(longLabelNameElement); |
| 1208 | longLabelsElement.AppendChild(longLabelElement); |
| 1209 | } |
| 1210 | naptrRecord.AppendChild(longLabelsElement); |
| 1211 | } |
| 1212 | |
| 1213 | |
| 1214 | } |
| 1215 | |
| 1216 | } |
| 1217 | |
| 1218 | } |
| 1219 | |
| 1220 | } |
| 1221 | |
| 1222 | // add the LOC results |
| 1223 | XmlElement locResultsElement = doc.CreateElement("LocResults"); |
| 1224 | root.AppendChild(locResultsElement); |
| 1225 | |
| 1226 | if (this.LocRecords != null) |
| 1227 | { |
| 1228 | foreach (DNSLocResourceRecord rr in this.LocRecords) |
| 1229 | { |
| 1230 | XmlElement locRecord = doc.CreateElement("LocRecord"); |
| 1231 | locResultsElement.AppendChild(locRecord); |
| 1232 | |
| 1233 | XmlElement lonElement = doc.CreateElement("Longitude"); |
| 1234 | lonElement.InnerText = rr.Longitude; |
| 1235 | locRecord.AppendChild(lonElement); |
| 1236 | |
| 1237 | XmlElement latElement = doc.CreateElement("Latitude"); |
| 1238 | latElement.InnerText = rr.Latitude; |
| 1239 | locRecord.AppendChild(latElement); |
| 1240 | |
| 1241 | XmlElement altElement = doc.CreateElement("Altitude"); |
| 1242 | altElement.InnerText = rr.Altitude; |
| 1243 | locRecord.AppendChild(altElement); |
| 1244 | |
| 1245 | XmlElement locEscElement = doc.CreateElement("LocationWithEscapedQuotes"); |
| 1246 | locEscElement.InnerText = String.Format("{0} {1}", rr.Longitude, rr.Latitude).Replace("'", "\\'"); |
| 1247 | locRecord.AppendChild(locEscElement); |
| 1248 | } |
| 1249 | } |
| 1250 | |
| 1251 | // add the TXT results |
| 1252 | //Commented out because we shouldn't be displaying an txtRecords |
| 1253 | if (pddxVersion == "1") |
| 1254 | { |
| 1255 | XmlElement txtResultsElement = doc.CreateElement("TxtResults"); |
| 1256 | root.AppendChild(txtResultsElement); |
| 1257 | |
| 1258 | if (TxtRecords != null) |
| 1259 | { |
| 1260 | foreach (DNSTxtResourceRecord rr in TxtRecords) |
| 1261 | { |
| 1262 | if (!typeof(DNSEnhancedTxtResourceRecord).IsInstanceOfType(rr)) |
| 1263 | { |
| 1264 | XmlElement txtRecord = doc.CreateElement("TxtRecord"); |
| 1265 | txtResultsElement.AppendChild(txtRecord); |
| 1266 | |
| 1267 | XmlElement stringElement = doc.CreateElement("String"); |
| 1268 | stringElement.InnerText = stringElement.InnerText = GetSafeValue(rr.TxtStr); |
| 1269 | txtRecord.AppendChild(stringElement); |
| 1270 | } |
| 1271 | } |
| 1272 | } |
| 1273 | } |
| 1274 | |
| 1275 | // add the Keyword results |
| 1276 | XmlElement keywordResultsElement = doc.CreateElement("KeywordResults"); |
| 1277 | root.AppendChild(keywordResultsElement); |
| 1278 | |
| 1279 | if (KeywordRecords != null) |
| 1280 | { |
| 1281 | foreach (DNSTxtResourceRecord rr in KeywordRecords) |
| 1282 | { |
| 1283 | if (typeof(DNSEnhancedTxtResourceRecord).IsInstanceOfType(rr)) |
| 1284 | { |
| 1285 | if (typeof(DNSStructuredKeywordsTxtResourceRecord).IsInstanceOfType(rr)) |
| 1286 | { |
| 1287 | XmlElement keywordRecord = doc.CreateElement("EnhancedTxtRecord"); |
| 1288 | keywordResultsElement.AppendChild(keywordRecord); |
| 1289 | |
| 1290 | DNSStructuredKeywordsTxtResourceRecord dnssktrr = (DNSStructuredKeywordsTxtResourceRecord)rr; |
| 1291 | |
| 1292 | if (dnssktrr.FreeText != null) |
| 1293 | { |
| 1294 | XmlElement typeElement = doc.CreateElement("Type"); |
| 1295 | typeElement.InnerText = "FreeText"; |
| 1296 | keywordRecord.AppendChild(typeElement); |
| 1297 | |
| 1298 | XmlElement pairElement = doc.CreateElement("PrimaryPair"); |
| 1299 | XmlElement keyElement = doc.CreateElement("Key"); |
| 1300 | keyElement.InnerText = ""; |
| 1301 | pairElement.AppendChild(keyElement); |
| 1302 | |
| 1303 | string value = GetSafeValue(dnssktrr.FreeText); |
| 1304 | //string value = System.Security.SecurityElement.Escape(StripCharactersHTMLFears(dnssktrr.FreeText)); |
| 1305 | if (value != "") |
| 1306 | { |
| 1307 | XmlElement valueElement = doc.CreateElement("Value"); |
| 1308 | valueElement.InnerText = value; |
| 1309 | pairElement.AppendChild(valueElement); |
| 1310 | } |
| 1311 | keywordRecord.AppendChild(pairElement); |
| 1312 | } |
| 1313 | } |
| 1314 | } |
| 1315 | } |
| 1316 | foreach (DNSTxtResourceRecord rr in KeywordRecords) |
| 1317 | { |
| 1318 | if (typeof(DNSEnhancedTxtResourceRecord).IsInstanceOfType(rr)) |
| 1319 | { |
| 1320 | if (typeof(DNSStructuredKeywordsTxtResourceRecord).IsInstanceOfType(rr)) |
| 1321 | { |
| 1322 | XmlElement keywordRecord = doc.CreateElement("EnhancedTxtRecord"); |
| 1323 | keywordResultsElement.AppendChild(keywordRecord); |
| 1324 | |
| 1325 | DNSStructuredKeywordsTxtResourceRecord dnssktrr = (DNSStructuredKeywordsTxtResourceRecord)rr; |
| 1326 | |
| 1327 | XmlElement countElement = doc.CreateElement("Count"); |
| 1328 | countElement.InnerText = "" + dnssktrr.KeywordsAndValues.Count; |
| 1329 | keywordRecord.AppendChild(countElement); |
| 1330 | bool primary = true; |
| 1331 | foreach (KeyValuePair<string, string> kvp in dnssktrr.KeywordsAndValues) |
| 1332 | { |
| 1333 | XmlElement typeElement = doc.CreateElement("Type"); |
| 1334 | if (dnssktrr.IsStructured()) |
| 1335 | { |
| 1336 | typeElement.InnerText = "Structured"; |
| 1337 | } |
| 1338 | else |
| 1339 | { |
| 1340 | typeElement.InnerText = "Other"; |
| 1341 | } |
| 1342 | keywordRecord.AppendChild(typeElement); |
| 1343 | |
| 1344 | //string key = System.Security.SecurityElement.Escape(StripCharactersHTMLFears(kvp.Key)); |
| 1345 | //string value = System.Security.SecurityElement.Escape(StripCharactersHTMLFears(kvp.Value)); |
| 1346 | string key = GetSafeValue(kvp.Key); |
| 1347 | string value = GetSafeValue(kvp.Value); |
| 1348 | XmlElement pairElement = null; |
| 1349 | if (primary && dnssktrr.IsStructured()) |
| 1350 | { |
| 1351 | primary = false; |
| 1352 | pairElement = doc.CreateElement("PrimaryPair"); |
| 1353 | } |
| 1354 | else |
| 1355 | { |
| 1356 | pairElement = doc.CreateElement("Pair"); |
| 1357 | } |
| 1358 | XmlElement keyElement = doc.CreateElement("Key"); |
| 1359 | keyElement.InnerText = key; |
| 1360 | pairElement.AppendChild(keyElement); |
| 1361 | Logger.Log(Logger.Section.Results_Screen,"Key: " + key); |
| 1362 | XmlElement keyNameElement = doc.CreateElement("Key-name"); |
| 1363 | keyNameElement.InnerText = dnssktrr.KeysToHumanReadableValues[kvp.Key]; |
| 1364 | |
| 1365 | |
| 1366 | pairElement.AppendChild(keyNameElement); |
| 1367 | |
| 1368 | if (value != "") |
| 1369 | { |
| 1370 | XmlElement valueElement = doc.CreateElement("Value"); |
| 1371 | if (value.EndsWith(":")) |
| 1372 | { |
| 1373 | valueElement.InnerText = value.Substring(0,value.Length-1); |
| 1374 | } |
| 1375 | else |
| 1376 | { |
| 1377 | valueElement.InnerText = value; |
| 1378 | } |
| 1379 | |
| 1380 | pairElement.AppendChild(valueElement); |
| 1381 | } |
| 1382 | |
| 1383 | keywordRecord.AppendChild(pairElement); |
| 1384 | |
| 1385 | } |
| 1386 | } |
| 1387 | } |
| 1388 | } |
| 1389 | } |
| 1390 | |
| 1391 | XmlElement nInfoResultsElement = doc.CreateElement("NInfoResults"); |
| 1392 | root.AppendChild(nInfoResultsElement); |
| 1393 | |
| 1394 | if (NInfoRecords != null) |
| 1395 | { |
| 1396 | foreach (DNSNInfoResourceRecord rr in this.NInfoRecords) |
| 1397 | { |
| 1398 | XmlElement nInfoRecord = doc.CreateElement("NInfoRecord"); |
| 1399 | nInfoResultsElement.AppendChild(nInfoRecord); |
| 1400 | |
| 1401 | XmlElement stringElement = doc.CreateElement("String"); |
| 1402 | stringElement.InnerText = GetSafeValue(rr.TxtStr); |
| 1403 | //stringElement.InnerText = System.Security.SecurityElement.Escape(StripCharactersHTMLFears(rr.TxtStr)) |
| 1404 | // .Replace("\r\n", "<br />").Replace("\n", "<br />").Replace("\r", "<br />").Replace("'", "'"); |
| 1405 | nInfoRecord.AppendChild(stringElement); |
| 1406 | } |
| 1407 | } |
| 1408 | return root; |
| 1409 | |
| 1410 | } |
| 1411 | |
| 1412 | private string GetSafeValue(string p) |
| 1413 | { |
| 1414 | return System.Security.SecurityElement.Escape(StripCharactersHTMLFears(p)) |
| 1415 | .Replace("\r\n", "<br />").Replace("\n", "<br />").Replace("\r", "<br />") |
| 1416 | .Replace("'", "'"); |
| 1417 | } |
| 1418 | |
| 1419 | /*private static void MakeLabelText(string label, XmlElement labelNameElement) |
| 1420 | { |
| 1421 | labelNameElement.InnerText = System.Security.SecurityElement.Escape(StripCharactersHTMLFears(label)) |
| 1422 | .Replace("\r\n", "<br />").Replace("\n", "<br />").Replace("\r", "<br />") |
| 1423 | .Replace("'", "'").Replace('-', ' ').Replace(':', ' '); |
| 1424 | }*/ |
| 1425 | |
| 1426 | |
| 1427 | /// <summary> |
| 1428 | /// There are certain characters that XML can't handle so these must be removed before they are passed |
| 1429 | /// </summary> |
| 1430 | /// <param name="s"></param> |
| 1431 | /// <returns></returns> |
| 1432 | private static string StripCharactersHTMLFears(string s) |
| 1433 | { |
| 1434 | StringBuilder sb = new StringBuilder(s.Length); |
| 1435 | foreach (char c in s) |
| 1436 | { |
| 1437 | int i = (int)c; |
| 1438 | if (!(i <= 8 || i == 11 || i == 12 || (i >= 14 && i <= 31) || (i >= 127 && i <= 159) || (i >= 55296 && i <= 57343))) |
| 1439 | { |
| 1440 | sb.Append(c); |
| 1441 | } |
| 1442 | } |
| 1443 | return sb.ToString(); |
| 1444 | } |
| 1445 | |
| 1446 | private bool changed; |
| 1447 | /// <summary> |
| 1448 | /// True if this result is different from the previous result for the domain. |
| 1449 | /// Can be unflagged if the user has seen the change. |
| 1450 | /// </summary> |
| 1451 | public bool Changed |
| 1452 | { |
| 1453 | get |
| 1454 | { |
| 1455 | return this.changed; |
| 1456 | } |
| 1457 | set |
| 1458 | { |
| 1459 | this.changed = value; |
| 1460 | } |
| 1461 | } |
| 1462 | |
| 1463 | |
| 1464 | } |
| 1465 | } |
Note: See TracBrowser
for help on using the browser.








