public void AddNAPTRResult(RecordNAPTR naptrRecord) { //logger.Debug("Checking NAPTR record for " + URI.ToString() + " " + naptrRecord.ToString() + "."); SIPServicesEnum sipServicesEnum = SIPServicesEnum.none; if (naptrRecord.Service == SIPDNSManager.NAPTR_SIP_UDP_SERVICE) { sipServicesEnum = SIPServicesEnum.sipudp; } else if (naptrRecord.Service == SIPDNSManager.NAPTR_SIP_TCP_SERVICE) { sipServicesEnum = SIPServicesEnum.siptcp; } else if (naptrRecord.Service == SIPDNSManager.NAPTR_SIPS_TCP_SERVICE) { sipServicesEnum = SIPServicesEnum.sipstcp; } if (sipServicesEnum != SIPServicesEnum.none) { //logger.Debug(" adding NAPTR lookup result for " + URI.ToString() + " of " + naptrRecord.ToString() + "."); SIPDNSServiceResult sipNAPTRResult = new SIPDNSServiceResult(sipServicesEnum, naptrRecord.Order, naptrRecord.RR.TTL, naptrRecord.Replacement, 0, DateTime.Now); if (SIPNAPTRResults == null) { SIPNAPTRResults = new Dictionary <SIPServicesEnum, SIPDNSServiceResult>() { { sipServicesEnum, sipNAPTRResult } }; } else { SIPNAPTRResults.Add(sipServicesEnum, sipNAPTRResult); } } }
private static Uri SelectSmpUriFromDnsResponse(Response dnsResponse) { RecordNAPTR firstMatchedNaptrRecord = dnsResponse.Answers .Select(r => r.RECORD) .Cast <RecordNAPTR>() .FirstOrDefault(); if (firstMatchedNaptrRecord == null) { throw new InvalidDataException( "No DNS NAPTR record found to get the SMP REST binding from"); } MatchCollection matches = SmpHttpRegex.Matches(firstMatchedNaptrRecord.REGEXP); if (matches.Count == 0) { throw new InvalidDataException( $"DNS NAPTR record value REGEXP: \"{firstMatchedNaptrRecord.REGEXP}\" doesn't match regular expression: \"{SmpHttpRegexPattern}\""); } Match firstMatch = matches[0]; if (firstMatch.Groups.Count < 2) { throw new InvalidDataException( $"DNS NAPTR record value REGEXP: \"{firstMatchedNaptrRecord.REGEXP}\" doesn't match regular expression: \"{SmpHttpRegexPattern}\""); } // First group is always the entire matched string like "!^.*$!http://40.115.23.114:38080/". // Second group is always only the matched parts like "http://40.115.23.114:38080/" string matched = firstMatch.Groups[1].Value; return(new Uri(matched)); }