private void ContactAddedHandlerInternal(Bindings bindings, Binding binding, SipMessageReader request) { timer.Add(binding.Expires * 1000, bindings.Aor); if (binding.ConnectionAddresses.Transport == Transports.Tcp || binding.ConnectionAddresses.Transport == Transports.Tls) { bindingsByConnectionId.Replace(binding.ConnectionAddresses.ConnectionId, bindings.Aor); } if (bindings.IsNew) { AorAdded(bindings.Aor); } ContactAdded(bindings.Aor, binding, request); }
private void ReadUsers(int accountId, string fileName) { var sync = GetSync(accountId); sync.EnterWriteLock(); try { var users = NewAccount(accountId); accounts.Replace(accountId, users); using (var csv = new CsvReader(new StreamReader(fileName), false)) { csv.SkipEmptyLines = true; csv.MissingFieldAction = MissingFieldAction.ReplaceByEmpty; csv.DefaultParseErrorAction = ParseErrorAction.AdvanceToNextLine; int fieldCount = csv.FieldCount; string[] headers = csv.GetFieldHeaders(); while (csv.ReadNextRecord()) { var user = new CsvUser(); if (user.Read(csv)) { if (users.ContainsKey(user.Name) == false) { users.Add(user.Name, user); } } } } } catch (Exception) { // должно вызываться снаружи лока //OnError(ex.Message); } finally { sync.ExitWriteLock(); } OnReset(accountId); }
private void ReadAccount(int id, string fileName) { IAccount account; try { account = Account.Deserialize(id, fileName); } catch (Exception) { account = null; } if (account == null) { account = accounts1.GetValue(id); if (account != null) { accounts1.Remove(id); accounts2.Remove(account.DomainName); } } else { accounts1.Replace(id, account); accounts2.Replace(account.DomainName, account); } for (; ;) { int count1 = Thread.VolatileRead(ref count); if (count1 >= id) { break; } if (Interlocked.CompareExchange(ref count, id, count1) == count1) { break; } } }
public ErrorCodes Authorize(SipMessageReader reader, AuthSchemes scheme, out ArraySegment <byte> token, out int opaque, out bool proxy) { token = new ArraySegment <byte>(); //var credentials = reader.GetCredentialsByTargetname(scheme, targetname, out proxy); IAccount account; var credentials = FindCredentials(reader, out account, out proxy); if (HexEncoding.TryParseHex8(credentials.Opaque, out opaque) == false) { opaque = Interlocked.Increment(ref opaqueCount); } if (credentials.AuthScheme == AuthSchemes.None) { return(ErrorCodes.NoResponse); } if (credentials.MessageQop.Equals(auth) == false) { return(ErrorCodes.QopNotSupported); } var epid = reader.From.Epid; if (epid.IsInvalid) { return(ErrorCodes.EpidNotFound); } if (credentials.HasGssapiData) { if (credentials.Version != 3) { return(ErrorCodes.VersionNotSupported); } var sa = connectingAssociations.GetOrAdd(opaque, scheme, GetDomain(credentials.Targetname), SecurityAssociationFactory1); var result = sa.Authentication(credHandle, Convert.FromBase64String(credentials.GssapiData.IsValid ? credentials.GssapiData.ToString() : String.Empty), out token); if (result != ErrorCodes.Continue) { connectingAssociations.Remove(opaque); if (result == ErrorCodes.Ok) { if (sa.UserName.Equals(reader.From.AddrSpec.User.ToString(), StringComparison.OrdinalIgnoreCase) == false) { result = ErrorCodes.UsernameNotMatch; } else { if (IsAuthorized(GetDomain(credentials.Targetname), sa.UserName.ToLower()) == false) { result = ErrorCodes.NotAuthorized; } else { var old = authorizedAssociations.Replace(epid.ToString(), sa); if (old != null) { old.Dispose(); } } } } if (result != ErrorCodes.Ok) { sa.Dispose(); } } return(result); } else { // verify signature // SecurityAssociation sa; if (authorizedAssociations.TryGetValue(epid.ToString(), out sa) == false) { return(ErrorCodes.NotAuthenticated); } if (credentials.Crand == int.MinValue) { return(ErrorCodes.CrandRequired); } if (credentials.Cnum == int.MinValue) { return(ErrorCodes.CnumRequired); } if (credentials.HasResponse == false) { return(ErrorCodes.ResponseRequired); } if (credentials.Opaque.IsValid && opaque != sa.Opaque) { return(ErrorCodes.UnexpectedOpaque); } if (sa.VerifySignature(reader, credentials) == false) { return(ErrorCodes.InvalidSignature); } if (sa.UserName.Equals(reader.From.AddrSpec.User.ToString(), StringComparison.OrdinalIgnoreCase) == false) { return(ErrorCodes.UsernameNotMatch); } return(ErrorCodes.Ok); } }