public static ObscureUrl CreatePublishReachCalendarUrl(string externalUrl, Guid mailboxGuid, string domain, string existingIdentity, SecurityIdentifier reachUserSid) { Util.ThrowOnNullOrEmptyArgument(externalUrl, "externalUrl"); Util.ThrowOnNullOrEmptyArgument(domain, "domain"); Util.ThrowOnNullArgument(reachUserSid, "reachUserSid"); if (!ExternalUser.IsValidReachSid(reachUserSid)) { throw new ArgumentException("Not an valid reach user sid.", "reachUserSid"); } SharingDataType reachCalendar = SharingDataType.ReachCalendar; string text = string.IsNullOrEmpty(existingIdentity) ? Guid.NewGuid().ToString("N") : ObscureUrl.ParseGuidIdentity(reachCalendar, existingIdentity).ToString("N"); string text2 = ObscureUrl.CalculateHashString(ObscureKind.Normal, text); string uriString = string.Format("{0}/{1}/{2}@{3}/{4}{5}/{6}/{7}", new object[] { externalUrl.TrimEnd(new char[] { '/' }), reachCalendar.ExternalName, mailboxGuid.ToString("N"), domain, text, text2, reachUserSid.ToString(), reachCalendar.PublishResourceName }); ObscureUrl obscureUrl = new ObscureUrl(new Uri(uriString, UriKind.Absolute), reachCalendar, mailboxGuid, domain, text, ObscureKind.Normal, reachUserSid); ExTraceGlobals.SharingTracer.TraceDebug <ObscureUrl, string>(0L, "ObscureUrl.CreatePublishReachCalendarUrl(): Created an instance of ObscureUrl: {0} - {1}.", obscureUrl, obscureUrl.TraceInfo); return(obscureUrl); }
internal static bool TryParse(string url, out ObscureUrl obscureUrl) { obscureUrl = null; if (!Uri.IsWellFormedUriString(url, UriKind.Absolute)) { ExTraceGlobals.SharingTracer.TraceError <string>(0L, "ObscureUrl.TryParse(): The string '{0}' is not an Absolute Uri.", url); return(false); } Uri uri = new Uri(url, UriKind.Absolute); string localPath = uri.LocalPath; ExTraceGlobals.SharingTracer.TraceDebug <string>(0L, "ObscureUrl.TryParse(): Get path of url: {0}", localPath); Match match = ObscureUrl.ObscureUrlRegex.Match(localPath); if (!match.Success) { ExTraceGlobals.SharingTracer.TraceDebug <string>(0L, "ObscureUrl.TryParse(): The string '{0}' is not desired ObscureUrl. ", url); return(false); } SharingDataType sharingDataType = SharingDataType.FromPublishResourceName(match.Result("${datatype}")); Guid guid = Guid.Empty; Exception ex = null; try { guid = new Guid(match.Result("${mailboxguid}")); } catch (FormatException ex2) { ex = ex2; } catch (OverflowException ex3) { ex = ex3; } if (ex != null) { ExTraceGlobals.SharingTracer.TraceDebug <string, Exception>(0L, "ObscureUrl.TryParse(): The string '{0}' is not desired ObscureUrl. Exception = {1}.", url, ex); return(false); } string text = match.Result("${guid}"); string x = match.Result("${hash}"); SecurityIdentifier securityIdentifier = null; string text2 = match.Result("${sid}"); if (sharingDataType == SharingDataType.ReachCalendar) { if (!StringComparer.Ordinal.Equals(x, ObscureUrl.CalculateHashString(ObscureKind.Normal, text))) { ExTraceGlobals.SharingTracer.TraceDebug <string>(0L, "ObscureUrl.TryParse(): Incorrect hash value for reachUrl:'{0}'", url); return(false); } if (string.IsNullOrEmpty(text2)) { ExTraceGlobals.SharingTracer.TraceDebug <string>(0L, "ObscureUrl.TryParse(): sid value missing for reachUrl:'{0}'", url); return(false); } securityIdentifier = new SecurityIdentifier(text2); if (!ExternalUser.IsValidReachSid(securityIdentifier)) { ExTraceGlobals.SharingTracer.TraceDebug <string>(0L, "ObscureUrl.TryParse(): Not a valid reach sid:'{0}'", url); return(false); } obscureUrl = new ObscureUrl(uri, sharingDataType, guid, match.Result("${domain}"), text, ObscureKind.Normal, securityIdentifier); ExTraceGlobals.SharingTracer.TraceDebug <string, string>(0L, "ObscureUrl.TryParse(): The url {0} is parsed as ReachCalendar ObscureUrl {1}.", url, obscureUrl.TraceInfo); return(true); } else { if (sharingDataType != SharingDataType.Calendar) { ExTraceGlobals.SharingTracer.TraceDebug <SharingDataType>(0L, "ObscureUrl.TryParse(): Sharing Datatype:{0} is not supported ", sharingDataType); return(false); } if (!string.IsNullOrEmpty(text2)) { ExTraceGlobals.SharingTracer.TraceDebug <string>(0L, "ObscureUrl.TryParse(): SID is not applicable for published calendar url:'{0}'", url); return(false); } foreach (object obj in Enum.GetValues(typeof(ObscureKind))) { ObscureKind obscureKind = (ObscureKind)obj; if (StringComparer.Ordinal.Equals(x, ObscureUrl.CalculateHashString(obscureKind, text))) { obscureUrl = new ObscureUrl(uri, sharingDataType, guid, match.Result("${domain}"), text, obscureKind, securityIdentifier); ExTraceGlobals.SharingTracer.TraceDebug <string, string>(0L, "ObscureUrl.TryParse(): The url {0} is parsed as Calendar ObscureUrl {1}.", url, obscureUrl.TraceInfo); return(true); } } ExTraceGlobals.SharingTracer.TraceDebug <string>(0L, "ObscureUrl.TryParse(): Incorrect hash value for Calendar url:{0}", url); return(false); } }