/// <summary> /// Sends in initial notification request for a new subscription where it makes sense to do so. /// </summary> /// <param name="subscribeRequest">The client request that resulted in the subscription creation.</param> /// <param name="sipAccount">The authenticated SIP account that created the subscription.</param> private void SendInitialNotification(SIPRequest subscribeRequest, ISIPAccount sipAccount) { if (SIPEventPackageType.IsValid(subscribeRequest.Header.Event)) { var eventPackage = SIPEventPackageType.Parse(subscribeRequest.Header.Event); if (eventPackage == SIPEventPackagesEnum.MessageSummary) { // Send a dummy message waiting indicator message so that a client can verify a notification request can // be received. var dstUri = subscribeRequest.Header.Contact[0].ContactURI; var accountURI = new SIPURI(sipAccount.SIPUsername, sipAccount.SIPDomain, null, dstUri.Scheme, dstUri.Protocol); var notifyReq = SIPRequest.GetRequest(SIPMethodsEnum.NOTIFY, subscribeRequest.Header.Contact[0].ContactURI, new SIPToHeader(null, accountURI.CopyOf(), CallProperties.CreateNewTag()), new SIPFromHeader(null, accountURI.CopyOf(), CallProperties.CreateNewTag())); notifyReq.Header.CallId = subscribeRequest.Header.CallId; notifyReq.Header.CSeq = subscribeRequest.Header.CSeq++; notifyReq.Header.Server = m_serverAgent; notifyReq.Header.Event = SIPEventPackageType.MESSAGE_SUMMARY_EVENT_VALUE; notifyReq.Header.SubscriptionState = "active"; notifyReq.Header.SetDateHeader(); notifyReq.Header.ContentType = SIPMIMETypes.MWI_CONTENT_TYPE; notifyReq.Body = "Messages-Waiting: no"; // A little trick here is using the remote SIP end point as the destination rather than the Contact URI. // Ideally some extra logic to check for IPv4 NAT should be applied. But since this server is known to // be operating in the cloud and only send NOTIFY requests to Internet clients it should be a reasonable // option. SIPNonInviteTransaction notifyTx = new SIPNonInviteTransaction(m_sipTransport, notifyReq, subscribeRequest.RemoteSIPEndPoint); notifyTx.SendRequest(); } } }
private SIPRequest GetRegistrationRequest(SIPEndPoint localSIPEndPoint) { try { string realm = (m_realm != null) ? m_realm : IPSocket.ParseHostFromSocket(m_registrarHost); SIPURI registerURI = m_sipAccountAOR.CopyOf(); registerURI.User = null; SIPRequest registerRequest = m_sipTransport.GetRequest( SIPMethodsEnum.REGISTER, registerURI, new SIPToHeader(null, m_sipAccountAOR, null), localSIPEndPoint); registerRequest.Header.From = new SIPFromHeader(null, m_sipAccountAOR, CallProperties.CreateNewTag()); registerRequest.Header.Contact[0] = new SIPContactHeader(null, m_contactURI); registerRequest.Header.CSeq = ++m_cseq; registerRequest.Header.CallId = m_callID; registerRequest.Header.UserAgent = (!UserAgent.IsNullOrBlank()) ? UserAgent : m_userAgent; registerRequest.Header.Expires = m_expiry; return(registerRequest); } catch (Exception excp) { logger.LogError("Exception GetRegistrationRequest. " + excp.Message); throw excp; } }
public SIPNotifierClient( SIPMonitorLogDelegate logDelegate, SIPTransport sipTransport, SIPEndPoint outboundProxy, SIPEventPackage sipEventPackage, SIPURI resourceURI, string authUsername, string authDomain, string authPassword, int expiry, string filter) { Log_External = logDelegate; m_sipTransport = sipTransport; m_outboundProxy = outboundProxy; m_sipEventPackage = sipEventPackage; m_authUsername = authUsername; m_authDomain = authDomain; m_authPassword = authPassword; m_expiry = (expiry > 0) ? expiry : DEFAULT_SUBSCRIBE_EXPIRY; m_filter = filter; m_resourceURI = resourceURI.CopyOf(); m_subscribeCallID = CallProperties.CreateNewCallId(); m_subscriptionFromTag = CallProperties.CreateNewTag(); }
private SIPRequest GetRegistrationRequest() { try { SIPURI registerURI = m_sipAccountAOR.CopyOf(); registerURI.User = null; SIPRequest registerRequest = SIPRequest.GetRequest( SIPMethodsEnum.REGISTER, registerURI, new SIPToHeader(this.UserDisplayName, m_sipAccountAOR, null), new SIPFromHeader(this.UserDisplayName, m_sipAccountAOR, CallProperties.CreateNewTag())); registerRequest.Header.Contact = new List <SIPContactHeader> { new SIPContactHeader(this.UserDisplayName, m_contactURI) }; registerRequest.Header.CSeq = ++m_cseq; registerRequest.Header.CallId = m_callID; registerRequest.Header.UserAgent = (!UserAgent.IsNullOrBlank()) ? UserAgent : m_userAgent; registerRequest.Header.Expires = m_expiry; return(registerRequest); } catch (Exception excp) { logger.LogError("Exception GetRegistrationRequest. " + excp.Message); throw excp; } }
private SIPRequest GetRegistrationRequest() { SIPURI registerURI = m_sipAccountAOR.CopyOf(); registerURI.User = null; SIPRequest registerRequest = SIPRequest.GetRequest( SIPMethodsEnum.REGISTER, registerURI, new SIPToHeader(this.UserDisplayName, m_sipAccountAOR, null), new SIPFromHeader(this.UserDisplayName, m_sipAccountAOR, CallProperties.CreateNewTag())); registerRequest.Header.Contact = new List <SIPContactHeader> { new SIPContactHeader(this.UserDisplayName, m_contactURI) }; registerRequest.Header.CSeq = ++m_cseq; registerRequest.Header.CallId = m_callID; registerRequest.Header.UserAgent = (!UserAgent.IsNullOrBlank()) ? UserAgent : SIPConstants.SipUserAgentVersionString; registerRequest.Header.Expires = m_expiry; if (m_customHeaders != null && m_customHeaders.Length > 0) { foreach (var header in m_customHeaders) { registerRequest.Header.UnknownHeaders.Add(header); } } if (AdjustRegister == null) { return(registerRequest); } return(AdjustRegister(registerRequest)); }
public SIPUserField CopyOf() { SIPUserField copy = new SIPUserField(); copy.Name = Name; copy.URI = URI.CopyOf(); copy.Parameters = Parameters.CopyOf(); return(copy); }
private SIPRequest GetRegistrationRequest() { try { SIPURI registerURI = m_sipAccountAOR.CopyOf(); registerURI.User = null; SIPRequest registerRequest = SIPRequest.GetRequest( SIPMethodsEnum.REGISTER, registerURI, new SIPToHeader(this.UserDisplayName, m_sipAccountAOR, null), new SIPFromHeader(this.UserDisplayName, m_sipAccountAOR, CallProperties.CreateNewTag())); registerRequest.Header.Contact = new List <SIPContactHeader> { new SIPContactHeader(this.UserDisplayName, m_contactURI) }; registerRequest.Header.CSeq = ++m_cseq; registerRequest.Header.CallId = m_callID; registerRequest.Header.UserAgent = (!UserAgent.IsNullOrBlank()) ? UserAgent : m_userAgent; registerRequest.Header.Expires = m_expiry; if (m_customHeaders != null && m_customHeaders.Length > 0) { foreach (var header in m_customHeaders) { registerRequest.Header.UnknownHeaders.Add(header); } } if (AdjustRegister == null) { return(registerRequest); } return(AdjustRegister(registerRequest)); } catch (Exception excp) { Logger.Logger.Error("Exception GetRegistrationRequest. ->" + excp.Message); throw excp; } }
/// <summary></summary> /// <param name="uacRecvdEndPoint">If this is non-null it indicates the contact header should be mangled based on the public socket the register request was demmed /// to have originated from rather then relying on the contact value recieved from the uac.</param> public SIPRegistrarBinding( SIPAccount sipAccount, SIPURI bindingURI, string callId, int cseq, string userAgent, SIPEndPoint remoteSIPEndPoint, SIPEndPoint proxySIPEndPoint, SIPEndPoint registrarSIPEndPoint, int expiry) { Id = Guid.NewGuid(); LastUpdate = DateTime.UtcNow; SIPAccountId = sipAccount.Id; SIPAccountName = sipAccount.SIPUsername + "@" + sipAccount.SIPDomain; Owner = sipAccount.Owner; AdminMemberId = sipAccount.AdminMemberId; m_contactURI = bindingURI.CopyOf(); m_mangledContactURI = m_contactURI.CopyOf(); CallId = callId; CSeq = cseq; UserAgent = userAgent; RemoteSIPEndPoint = remoteSIPEndPoint; m_proxySIPEndPoint = proxySIPEndPoint; m_registrarSIPEndPoint = registrarSIPEndPoint; //if (SIPTransport.IsPrivateAddress(sipRequest.Header.Contact[0].ContactURI.Host) && m_mangleUACContact) if (!sipAccount.DontMangleEnabled && Regex.Match(m_mangledContactURI.Host, @"(\d+\.){3}\d+").Success) { // The Contact URI Host is used by registrars as the contact socket for the user so it needs to be changed to reflect the socket // the intial request was received on in order to work around NAT. It's no good just relying on private addresses as a lot of User Agents // determine their public IP but NOT their public port so they send the wrong port in the Contact header. //logger.Debug("Mangling contact header from " + m_mangledContactURI.Host + " to " + IPSocket.GetSocketString(uacRecvdEndPoint) + "."); m_mangledContactURI.Host = remoteSIPEndPoint.GetIPEndPoint().ToString(); } m_expiry = expiry; }
public SIPEventPresence(SIPURI entity) { Entity = entity.CopyOf(); }
public SIPEventDialogInfo(int version, SIPEventDialogInfoStateEnum state, SIPURI entity) { Version = version; State = state; Entity = entity.CopyOf(); }