public void Register(string uri) { if (RegEvent != null) { RegEvent(this, new RegistrationChangedEventArgs("Registering", null)); } RegisterUA = new UserAgent(Stack); Message registerMsg = RegisterUA.CreateRegister(new SIPURI(uri)); registerMsg.InsertHeader(new Header("3600", "Expires")); RegisterUA.SendRequest(registerMsg); }
/// <summary> /// Initializes a new instance of the <see cref="T:SIPLib.SIP.Timer" /> class with default time outs. /// </summary> /// <param name="app">The app.</param> /// <param name="T1">The t1.</param> /// <param name="T2">The t2.</param> /// <param name="T4">The t4.</param> public Timer(UserAgent app, int T1 = 500, int T2 = 4000, int T4 = 5000) { this.T1 = T1; this.T2 = T2; this.T4 = T4; }
public override string[] Authenticate(UserAgent ua, Header header, SIPStack stack) { return new[] { Username + "@" + Realm, Password }; }
public void Invite(string uri, SDP sdp) { uri = checkURI(uri); if (IsRegistered()) { UserAgent cua = new UserAgent(Stack) { LocalParty = RegisterUA.LocalParty, RemoteParty = new Address(uri) }; Useragents.Add(cua); Message invite = cua.CreateRequest("INVITE"); invite.InsertHeader(new Header("application/sdp", "Content-Type")); invite.Body= sdp.ToString(); cua.SendRequest(invite); } else { Log.Error("isRegistered failed in invite message"); } }
public void SendMessage(string uri, string message, string contentType = "text/plain") { uri = checkURI(uri); UserAgent mua = new UserAgent(Stack) { LocalParty = PublicServiceIdentity, RemoteParty = new Address(uri) }; Useragents.Add(mua); Message m = mua.CreateRequest("MESSAGE", message); m.InsertHeader(new Header(contentType, "Content-Type")); mua.SendRequest(m); }
/// <summary> /// Initializes a new instance of the <see cref="T:SIPLib.SIP.InviteServerTransaction"/> class. /// </summary> /// <param name="app">Takes in a user agent.</param> public InviteServerTransaction(UserAgent app) : base(app) { Server = true; }
/// <summary> /// Notifies the associated SIP application that a dialog has been created. /// </summary> /// <param name="dialog">The dialog.</param> /// <param name="ua">The ua.</param> public void DialogCreated(Dialog dialog, UserAgent ua) { App.DialogCreated(dialog, ua, this); }
public override void ReceivedResponse(UserAgent ua, Message response, SIPStack stack) { Log.Info("Received response with code " + response.ResponseCode + " " + response.ResponseText); Log.Debug("\n\n" + response.ToString()); if (ResponseRecvEvent != null) { ResponseRecvEvent(this, new SipMessageEventArgs(response)); } }
/// <summary> /// Passes a received response to the associated SIP application. /// </summary> /// <param name="ua">The ua.</param> /// <param name="response">The response.</param> public void ReceivedResponse(UserAgent ua, Message response) { App.ReceivedResponse(ua, response, this); }
/// <summary> /// Passes the notification of a cancellation to the associated SIP application. /// </summary> /// <param name="ua">The ua.</param> /// <param name="request">The request.</param> public void Cancelled(UserAgent ua, Message request) { App.Cancelled(ua, request, this); }
/// <summary> /// Passes a received request to the associated SIP application. /// </summary> /// <param name="ua">The ua.</param> /// <param name="request">The request.</param> public void ReceivedRequest(UserAgent ua, Message request) { App.ReceivedRequest(ua, request, this); }
/// <summary> /// Sends a particular message through the associated SIP application. /// </summary> /// <param name="ua">The ua.</param> /// <param name="message">The message.</param> public void Sending(UserAgent ua, Message message) { App.Sending(ua, message, this); }
/// <summary> /// Handle received request /// </summary> /// <param name="m">The received message.</param> /// <param name="uri">The SIPURI that sent the message.</param> private void ReceivedRequest(Message m, SIPURI uri) { string branch = m.Headers["Via"][0].Attributes["branch"]; Transaction t; if (m.Method == "ACK") { if (branch == "0") { t = null; } else { t = FindTransaction(branch); if (t == null || (t.LastResponse != null && t.LastResponse.Is2XX())) { t = FindTransaction(Transaction.CreateId(branch, m.Method)); } } } else { t = FindTransaction(Transaction.CreateId(branch, m.Method)); } if (t == null) { UserAgent app = null; // Huh ? if ((m.Method != "CANCEL") && (m.Headers["To"][0].Attributes.ContainsKey("tag"))) { //In dialog request Dialog d = FindDialog(m); if (d == null) { if (m.Method != "ACK") { //Updated from latest code TODO UserAgent u = CreateServer(m, uri); if (u != null) { app = u; } else { // TODO: FIX NOTIFY ON SUBSCRIBE HANDLING if (m.Method != "NOTIFY") { Send(Message.CreateResponse(481, "Dialog does not exist", null, null, m)); return; } else { string branchID = m.Headers["Via"][0].Attributes["branch"]; if (_seenNotifys.ContainsKey(branchID) && _seenNotifys[branchID] > 1) { Send(Message.CreateResponse(481, "Dialog does not exist", null, null, m)); return; } else { if (_seenNotifys.ContainsKey(branchID)) { _seenNotifys[branchID] = _seenNotifys[branchID] + 1; } else { _seenNotifys[branchID] = 1; } } } return; } } else { _log.Info("No dialog for ACK, finding transaction"); if (t == null && branch != "0") { t = FindTransaction(Transaction.CreateId(branch, "INVITE")); } if (t != null && t.State != "terminated") { t.ReceivedRequest(m); return; } else { _log.Info("No existing transaction for ACK \n"); UserAgent u = CreateServer(m, uri); if (u != null) { app = u; } else { return; } } } } else { app = d; } } else if (m.Method != "CANCEL") { //Out of dialog request UserAgent u = CreateServer(m, uri); if (u != null) { //TODO error..... app = u; } else if (m.Method == "OPTIONS") { //Handle OPTIONS Message reply = Message.CreateResponse(200, "OK", null, null, m); reply.InsertHeader(new Header("INVITE,ACK,CANCEL,BYE,OPTION,MESSAGE,PUBLISH", "Allow")); Send(m); return; } else if (m.Method == "MESSAGE") { //Handle MESSAGE UserAgent ua = new UserAgent(this) { Request = m }; /*Message reply = ua.CreateResponse(200, "OK"); * Send(reply);*/ App.ReceivedRequest(ua, m, this); return; } else if (m.Method == "PUBLISH") { UserAgent ua = new UserAgent(this) { Request = m }; App.ReceivedRequest(ua, m, this); return; } else if (m.Method != "ACK") { Send(Message.CreateResponse(405, "Method not allowed", null, null, m)); return; } } else { //Cancel Request Transaction o = FindTransaction(Transaction.CreateId(m.Headers["Via"][0].Attributes["branch"], "INVITE")); if (o == null) { Send(Message.CreateResponse(481, "Original transaction does not exist", null, null, m)); return; } app = o.App; } if (app != null) { //t = Transaction.CreateServer(app.Stack, app, app.Request, app.Stack.Transport, app.Stack.Tag); // TODO: Check app or this ? t = Transaction.CreateServer(this, app, m, Transport, Tag); } else if (m.Method != "ACK") { Send(Message.CreateResponse(404, "Not found", null, null, m)); } } else { t.ReceivedRequest(m); } }
private static void UpdateServiceMetrics(Dictionary<string, float> metrics) { UserAgent pua = new UserAgent(_app.Stack) { RemoteParty = new Address("<sip:" + ServerURI + ">"), LocalParty = _localParty }; Message request = pua.CreateRequest("PUBLISH"); request.InsertHeader(new Header("service-description", "Event")); request.InsertHeader(new Header("application/SERV_DESC+xml", "Content-Type")); XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load("Resources/ServiceDescription.xml"); XmlNode node = xmlDoc.SelectSingleNode("Service/Metrics/TotalCPU"); node.InnerText = String.Format("{0:0.##}", metrics["totalCPU"]); node = xmlDoc.SelectSingleNode("Service/Metrics/CPU"); node.InnerText = String.Format("{0:0.##}", metrics["cpu"]); node = xmlDoc.SelectSingleNode("Service/Metrics/TotalMemory"); node.InnerText = String.Format("{0:0.##}", metrics["memAvailable"]) + " MB"; node = xmlDoc.SelectSingleNode("Service/Metrics/Memory"); node.InnerText = String.Format("{0:0.##}", ((metrics["memUsed"] / 1024) / 1024)) + " MB"; request.Body = xmlDoc.OuterXml; pua.SendRequest(request); }
/// <summary> /// Authenticates through the associated SIP application. /// </summary> /// <param name="ua">The ua.</param> /// <param name="header">The header.</param> /// <returns>System.String[][].</returns> public string[] Authenticate(UserAgent ua, Header header) { return(App.Authenticate(ua, header, this)); }
public override void DialogCreated(Dialog dialog, UserAgent ua, SIPStack stack) { Useragents.Remove(ua); Useragents.Add(dialog); Log.Info("New dialog created"); }
/// <summary> /// Creates a timer on the associated SIP application. /// </summary> /// <param name="obj">The obj.</param> /// <returns>Timer.</returns> public Timer CreateTimer(UserAgent obj) { return(App.CreateTimer(obj, this)); }
public void SendInvite(string uri) { uri = checkURI(uri); UserAgent cua = new UserAgent(Stack) { LocalParty = PublicServiceIdentity, RemoteParty = new Address(uri) }; Useragents.Add(cua); Message invite = cua.CreateRequest("INVITE"); cua.SendRequest(invite); }
/// <summary> /// Initializes a new instance of the <see cref="T:SIPLib.SIP.Transaction" /> class. /// </summary> /// <param name="app">The associated useragent / application</param> protected Transaction(UserAgent app) { Timers = new Dictionary <string, Timer>(); Timer = new Timer(App); App = app; }
public override string[] Authenticate(UserAgent ua, Header header, SIPStack sipStack) { throw new NotImplementedException(); }
/// <summary> /// Initializes a new instance of the <see cref="T:SIPLib.SIP.ClientTransaction"/> class. /// </summary> /// <param name="app">Takes in a useragent instance.</param> public ClientTransaction(UserAgent app) : base(app) { Server = false; }
/// <summary> /// Handle received request /// </summary> /// <param name="m">The received message.</param> /// <param name="uri">The SIPURI that sent the message.</param> private void ReceivedRequest(Message m, SIPURI uri) { string branch = m.Headers["Via"][0].Attributes["branch"]; Transaction t; if (m.Method == "ACK") { if (branch == "0") { t = null; } else { t = FindTransaction(branch); if (t == null || (t.LastResponse != null && t.LastResponse.Is2XX())) { t = FindTransaction(Transaction.CreateId(branch, m.Method)); } } } else { t = FindTransaction(Transaction.CreateId(branch, m.Method)); } if (t == null) { UserAgent app = null; // Huh ? if ((m.Method != "CANCEL") && (m.Headers["To"][0].Attributes.ContainsKey("tag"))) { //In dialog request Dialog d = FindDialog(m); if (d == null) { if (m.Method != "ACK") { //Updated from latest code TODO UserAgent u = CreateServer(m, uri); if (u != null) { app = u; } else { // TODO: FIX NOTIFY ON SUBSCRIBE HANDLING if (m.Method != "NOTIFY") { Send(Message.CreateResponse(481, "Dialog does not exist", null, null, m)); return; } else { string branchID = m.Headers["Via"][0].Attributes["branch"]; if (_seenNotifys.ContainsKey(branchID) && _seenNotifys[branchID] > 1) { Send(Message.CreateResponse(481, "Dialog does not exist", null, null, m)); return; } else { if (_seenNotifys.ContainsKey(branchID)) { _seenNotifys[branchID] = _seenNotifys[branchID] + 1; } else { _seenNotifys[branchID] = 1; } } } return; } } else { _log.Info("No dialog for ACK, finding transaction"); if (t == null && branch != "0") { t = FindTransaction(Transaction.CreateId(branch, "INVITE")); } if (t != null && t.State != "terminated") { t.ReceivedRequest(m); return; } else { _log.Info("No existing transaction for ACK \n"); UserAgent u = CreateServer(m, uri); if (u != null) { app = u; } else return; } } } else { app = d; } } else if (m.Method != "CANCEL") { //Out of dialog request UserAgent u = CreateServer(m, uri); if (u != null) { //TODO error..... app = u; } else if (m.Method == "OPTIONS") { //Handle OPTIONS Message reply = Message.CreateResponse(200, "OK", null, null, m); reply.InsertHeader(new Header("INVITE,ACK,CANCEL,BYE,OPTION,MESSAGE,PUBLISH", "Allow")); Send(m); return; } else if (m.Method == "MESSAGE") { //Handle MESSAGE UserAgent ua = new UserAgent(this) {Request = m}; /*Message reply = ua.CreateResponse(200, "OK"); Send(reply);*/ App.ReceivedRequest(ua, m, this); return; } else if (m.Method == "PUBLISH") { UserAgent ua = new UserAgent(this) {Request = m}; App.ReceivedRequest(ua, m, this); return; } else if (m.Method != "ACK") { Send(Message.CreateResponse(405, "Method not allowed", null, null, m)); return; } } else { //Cancel Request Transaction o = FindTransaction(Transaction.CreateId(m.Headers["Via"][0].Attributes["branch"], "INVITE")); if (o == null) { Send(Message.CreateResponse(481, "Original transaction does not exist", null, null, m)); return; } app = o.App; } if (app != null) { //t = Transaction.CreateServer(app.Stack, app, app.Request, app.Stack.Transport, app.Stack.Tag); // TODO: Check app or this ? t = Transaction.CreateServer(this, app, m, Transport, Tag); } else if (m.Method != "ACK") { Send(Message.CreateResponse(404, "Not found", null, null, m)); } } else { t.ReceivedRequest(m); } }
/// <summary> /// Stub to handle the authentication of the specified ua. /// </summary> /// <param name="ua">The ua.</param> /// <param name="header">The header.</param> /// <param name="sipStack">The sip stack.</param> /// <returns>System.String[].</returns> public abstract string[] Authenticate(UserAgent ua, Header header, SIPStack sipStack);
public void Invite(string uri) { uri = checkURI(uri); if (IsRegistered()) { UserAgent cua = new UserAgent(Stack) {LocalParty = RegisterUA.LocalParty, RemoteParty = new Address(uri)}; Useragents.Add(cua); Message invite = cua.CreateRequest("INVITE"); cua.SendRequest(invite); } else { Log.Error("isRegistered failed in invite message"); } }
/// <summary> /// Stub to alert on cancellation. /// </summary> /// <param name="ua">The ua.</param> /// <param name="request">The request.</param> /// <param name="sipStack">The sip stack.</param> public abstract void Cancelled(UserAgent ua, Message request, SIPStack sipStack);
public void Register(string username, string password, string realm) { Username = username; Password = password; Realm = realm; RegisterUA = new UserAgent(Stack); Message registerMsg = RegisterUA.CreateRegister(new SIPURI("sip:"+username+"@"+realm)); registerMsg.InsertHeader(new Header("3600", "Expires")); RegisterUA.SendRequest(registerMsg); }
/// <summary> /// Stub to create timers. /// </summary> /// <param name="obj">The obj.</param> /// <param name="sipStack">The sip stack.</param> /// <returns>Timer.</returns> public abstract Timer CreateTimer(UserAgent obj, SIPStack sipStack);
public void SendIM(string uri, string message,string contentType = "text/plain") { uri = checkURI(uri); if (IsRegistered()) { UserAgent mua = new UserAgent(Stack) {LocalParty = RegisterUA.LocalParty, RemoteParty = new Address(uri)}; Useragents.Add(mua); Message m = mua.CreateRequest("MESSAGE", message); m.InsertHeader(new Header(contentType, "Content-Type")); mua.SendRequest(m); } }
/// <summary> /// Authenticates through the associated SIP application. /// </summary> /// <param name="ua">The ua.</param> /// <param name="header">The header.</param> /// <returns>System.String[][].</returns> public string[] Authenticate(UserAgent ua, Header header) { return App.Authenticate(ua, header, this); }
private static void PublishService(bool determineIP, int port) { UserAgent pua = new UserAgent(_app.Stack) { RemoteParty = new Address("<sip:" + ServerURI + ">"), LocalParty = _localParty }; Message request = pua.CreateRequest("PUBLISH"); request.InsertHeader(new Header("service-description", "Event")); request.InsertHeader(new Header("application/SERV_DESC+xml", "Content-Type")); XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load("Resources/ServiceDescription.xml"); if (determineIP) { XmlNode IPnode = xmlDoc.SelectSingleNode("Service/Service_Config/Server_IP"); IPnode.InnerText = _localIP; } XmlNode Portnode = xmlDoc.SelectSingleNode("Service/Service_Config/Server_Port"); Portnode.InnerText = Convert.ToString(port); xmlDoc.Save("Resources/ServiceDescription.xml"); request.Body = xmlDoc.OuterXml; pua.SendRequest(request); ConsoleLog.Info("Sent service information to SRS"); }
public override Timer CreateTimer(UserAgent app, SIPStack stack) { return new Timer(app); }
/// <summary> /// Creates a timer on the associated SIP application. /// </summary> /// <param name="obj">The obj.</param> /// <returns>Timer.</returns> public Timer CreateTimer(UserAgent obj) { return App.CreateTimer(obj, this); }
public override void ReceivedRequest(UserAgent ua, Message request, SIPStack stack) { Log.Info("Received request with method " + request.Method.ToUpper()); Log.Debug("\n\n" + request.ToString()); if (RequestRecvEvent != null) { RequestRecvEvent(this, new SipMessageEventArgs(request, ua)); } }
public override void Sending(UserAgent ua, Message message, SIPStack stack) { if (Helpers.IsRequest(message)) { Log.Info("Sending request with method " + message.Method); } else { Log.Info("Sending response with code " + message.ResponseCode); } Log.Debug("\n\n" + message.ToString()); //TODO: Allow App to modify message before it gets sent?; }
public void SendInvite(string uri, SDP sdp) { uri = checkURI(uri); UserAgent cua = new UserAgent(Stack) { LocalParty = PublicServiceIdentity, RemoteParty = new Address(uri) }; Useragents.Add(cua); Message invite = cua.CreateRequest("INVITE"); invite.InsertHeader(new Header("application/sdp", "Content-Type")); invite.Body = sdp.ToString(); cua.SendRequest(invite); }
internal void Publish(string sipUri, string basic, string note, int expires) { UserAgent pua = new UserAgent(Stack) { LocalParty = PublicServiceIdentity, RemoteParty = new Address(sipUri) }; Useragents.Add(pua); Message request = pua.CreateRequest("PUBLISH"); request.InsertHeader(new Header("presence", "Event")); request.InsertHeader(new Header(pua.LocalParty.ToString(), "P-Preferred-Identity")); request.InsertHeader(new Header("application/pidf+xml", "Content-Type")); StringBuilder sb = new StringBuilder(); sb.Append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); sb.Append("<presence xmlns=\"urn:ietf:params:xml:ns:pidf\" xmlns:im=\"urn:ietf:params:xml:ns:pidf:im\" entity=\"" + sipUri + "\">\n"); sb.Append("<tuple id=\"Sharp_IMS_Client\">\n"); sb.Append("<status>\n"); sb.Append("<basic>" + basic + "</basic>\n"); sb.Append("</status>\n"); sb.Append("<note>" + note + "</note>\n"); sb.Append("</tuple>\n"); sb.Append("</presence>\n"); request.Body = sb.ToString(); pua.SendRequest(request); }
public override void Cancelled(UserAgent ua, Message request, SIPStack stack) { throw new NotImplementedException(); }
/// <summary> /// Initializes a new instance of the <see cref="T:SIPLib.SIP.SipMessageEventArgs"/> class based on SIP message and useragent. /// </summary> /// <param name="transferredMessage">The transferred message.</param> /// <param name="ua">The ua.</param> public SipMessageEventArgs(Message transferredMessage, UserAgent ua) { Message = transferredMessage; UA = ua; }