@@ -8,11 +8,8 @@ package controller.commands; | |||
import controller.CommandInterface; | |||
import gui.Hauptfenster; | |||
import java.text.ParseException; | |||
import java.util.logging.Level; | |||
import java.util.logging.Logger; | |||
import javax.sip.InvalidArgumentException; | |||
import javax.sip.SipException; | |||
import logger.OhmLogger; | |||
import model.SIPmodel; | |||
@@ -41,7 +38,7 @@ public class CommandRegister implements CommandInterface | |||
model.sendRegister(view.getTxtServerIP().getText(), 5060); | |||
} | |||
catch (ParseException|InvalidArgumentException|SipException ex) | |||
catch (Exception ex) | |||
{ | |||
view.getTxtArea().append("Registrierung fehlgeschlagen\n"); | |||
lgregister.getLogger(CommandRegister.class.getName()).log(Level.SEVERE, null, ex); |
@@ -5,31 +5,12 @@ | |||
*/ | |||
package model; | |||
import static java.lang.Thread.sleep; | |||
import java.util.concurrent.ExecutorService; | |||
import java.util.concurrent.Executors; | |||
import java.util.logging.Level; | |||
import java.util.logging.Logger; | |||
import javax.sip.RequestEvent; | |||
import javax.sip.SipException; | |||
import javax.sip.header.AllowEventsHeader; | |||
import javax.sip.header.AllowHeader; | |||
import javax.sip.header.CSeqHeader; | |||
import javax.sip.header.ContactHeader; | |||
import javax.sip.header.FromHeader; | |||
import javax.sip.header.HeaderFactory; | |||
import javax.sip.header.ToHeader; | |||
import javax.sip.header.ViaHeader; | |||
import javax.sip.message.MessageFactory; | |||
import javax.sip.message.Response; | |||
import logger.OhmLogger; | |||
/** | |||
* | |||
* @author Jan | |||
*/ | |||
public class SIP180Ringing implements Runnable | |||
{ | |||
public class SIP180Ringing | |||
{/* | |||
private RequestEvent evtubergabe; | |||
private ExecutorService threadring; | |||
private boolean run; | |||
@@ -106,4 +87,5 @@ public class SIP180Ringing implements Runnable | |||
} | |||
} | |||
} | |||
*/ | |||
} |
@@ -5,15 +5,19 @@ | |||
*/ | |||
package model; | |||
import java.util.logging.Level; | |||
import java.util.logging.Logger; | |||
import javax.sdp.SessionDescription; | |||
import javax.sip.RequestEvent; | |||
import javax.sip.header.AllowEventsHeader; | |||
import javax.sip.header.AllowHeader; | |||
import javax.sip.header.CSeqHeader; | |||
import javax.sip.header.CallIdHeader; | |||
import javax.sip.header.ContactHeader; | |||
import javax.sip.header.ContentTypeHeader; | |||
import javax.sip.header.FromHeader; | |||
import javax.sip.header.HeaderFactory; | |||
import javax.sip.header.SupportedHeader; | |||
import javax.sip.header.ToHeader; | |||
import javax.sip.header.ViaHeader; | |||
import javax.sip.message.MessageFactory; | |||
@@ -28,21 +32,26 @@ public class SIP200Ok | |||
{ | |||
private Response response; | |||
private static final Logger lg200Ok = OhmLogger.getLogger(); | |||
private RequestEvent requestEvent; | |||
private HeaderFactory headerFactory; | |||
public SIP200Ok(MessageFactory messageFactory, RequestEvent requestEvent, | |||
ContactHeader contactHeader, HeaderFactory headerFactory) | |||
{ | |||
this.requestEvent = requestEvent; | |||
this.headerFactory = headerFactory; | |||
try | |||
{ | |||
Response response = messageFactory.createResponse(200, requestEvent.getRequest()); | |||
response.addHeader((ViaHeader) requestEvent.getRequest().getHeader("Via")); | |||
response.addHeader((FromHeader) requestEvent.getRequest().getHeader("From")); | |||
response.addHeader((ToHeader) requestEvent.getRequest().getHeader("To")); | |||
response.addHeader((CallIdHeader) requestEvent.getRequest().getHeader("Call-ID")); | |||
response.addHeader((CSeqHeader) requestEvent.getRequest().getHeader("Cseq")); | |||
response = messageFactory.createResponse(Response.OK, this.requestEvent.getRequest()); | |||
response.addHeader((ViaHeader) this.requestEvent.getRequest().getHeader("Via")); | |||
response.addHeader((FromHeader) this.requestEvent.getRequest().getHeader("From")); | |||
response.addHeader((ToHeader) this.requestEvent.getRequest().getHeader("To")); | |||
response.addHeader((CallIdHeader) this.requestEvent.getRequest().getHeader("Call-ID")); | |||
response.addHeader((CSeqHeader) this.requestEvent.getRequest().getHeader("Cseq")); | |||
response.addHeader(contactHeader); | |||
AllowHeader allow = headerFactory.createAllowHeader("NOTIFY,INVITE,ACK,CANCEL,BYE,REFER,INFO,OPTIONS,MESSAGE"); | |||
AllowEventsHeader allowevents = headerFactory.createAllowEventsHeader("talk,hold,refer,call-info"); | |||
response.addHeader((CallIdHeader) requestEvent.getRequest().getHeader("Call-ID")); | |||
AllowHeader allow = this.headerFactory.createAllowHeader("NOTIFY,INVITE,ACK,CANCEL,BYE,REFER,INFO,OPTIONS,MESSAGE"); | |||
AllowEventsHeader allowevents = this.headerFactory.createAllowEventsHeader("talk,hold,refer,call-info"); | |||
response.addHeader((CallIdHeader) this.requestEvent.getRequest().getHeader("Call-ID")); | |||
response.addHeader(allow); | |||
response.addHeader(allowevents); | |||
lg200Ok.info("200Ok Header erfolgreich erstellt"); | |||
@@ -53,6 +62,26 @@ public class SIP200Ok | |||
} | |||
} | |||
public void addSDP(SessionDescription sdp, String myTag) | |||
{ | |||
try | |||
{ | |||
response.removeHeader("To"); | |||
ToHeader temptoring = (ToHeader) requestEvent.getRequest().getHeader("To"); | |||
temptoring.setTag(myTag); //evtl. besseren Tag | |||
response.addHeader(temptoring); //evtl noch Ergänzungen | |||
SupportedHeader supp = this.headerFactory.createSupportedHeader("replace,path,timer");//nachschauen für was es gebraucht wird | |||
response.addHeader(supp); | |||
ContentTypeHeader content = headerFactory.createContentTypeHeader("application", "sdp"); | |||
response.addHeader(content); | |||
response.setContent(sdp, content); | |||
} | |||
catch (Exception ex) | |||
{ | |||
lg200Ok.getLogger(SIPmodel.class.getName()).log(Level.SEVERE, null, ex); | |||
} | |||
} | |||
/** | |||
* @return the response | |||
*/ |
@@ -0,0 +1,79 @@ | |||
/* | |||
* To change this license header, choose License Headers in Project Properties. | |||
* To change this template file, choose Tools | Templates | |||
* and open the template in the editor. | |||
*/ | |||
package model; | |||
import java.util.ArrayList; | |||
import java.util.logging.Logger; | |||
import javax.sdp.SessionDescription; | |||
import javax.sip.address.Address; | |||
import javax.sip.address.AddressFactory; | |||
import javax.sip.address.URI; | |||
import javax.sip.header.AllowHeader; | |||
import javax.sip.header.CSeqHeader; | |||
import javax.sip.header.CallIdHeader; | |||
import javax.sip.header.ContactHeader; | |||
import javax.sip.header.ContentTypeHeader; | |||
import javax.sip.header.ExpiresHeader; | |||
import javax.sip.header.FromHeader; | |||
import javax.sip.header.HeaderFactory; | |||
import javax.sip.header.MaxForwardsHeader; | |||
import javax.sip.header.ToHeader; | |||
import javax.sip.header.ViaHeader; | |||
import javax.sip.message.MessageFactory; | |||
import javax.sip.message.Request; | |||
import logger.OhmLogger; | |||
/** | |||
* | |||
* @author Jan | |||
*/ | |||
public class SIPInvite | |||
{ | |||
private Request inviterequest; | |||
private static final Logger lgInvite = OhmLogger.getLogger(); | |||
public SIPInvite(String sipaddresse, String proxyaddresse, String myIPAddress, | |||
int myPort, | |||
String myTag, int branch, CallIdHeader callID, long cSequenz, | |||
AddressFactory addressFactory, SessionDescription sessionDescription, | |||
HeaderFactory headerFactory, MessageFactory messageFactory, ContactHeader contactHeader) | |||
{ | |||
try | |||
{ | |||
Address addressto = addressFactory.createAddress("sip:" + sipaddresse + "@" + proxyaddresse); | |||
ToHeader to = headerFactory.createToHeader(addressto, null); // Integer.toString(myTag) address + myTag | |||
URI requestURI = addressto.getURI(); | |||
FromHeader from = headerFactory.createFromHeader(addressto, String.valueOf(myTag)); //this.contactAddress | |||
ArrayList via = new ArrayList(); //Via needs a List as input | |||
ViaHeader viaheader = headerFactory.createViaHeader(myIPAddress, myPort, "UDP", String.valueOf(branch)); | |||
via.add(viaheader); | |||
CSeqHeader cSeq = headerFactory.createCSeqHeader(cSequenz, "INVITE"); | |||
MaxForwardsHeader maxForwards = headerFactory.createMaxForwardsHeader(70); | |||
AllowHeader allow = headerFactory.createAllowHeader("NOTIFY,INVITE,ACK,CANCEL,BYE,REFER,INFO,OPTIONS,MESSAGE"); | |||
ExpiresHeader expire = headerFactory.createExpiresHeader(3600); //int value | |||
inviterequest = messageFactory.createRequest(requestURI, "INVITE", callID, cSeq, from, to, via, maxForwards); | |||
inviterequest.addHeader(contactHeader); | |||
inviterequest.addHeader(allow); | |||
inviterequest.addHeader(expire); | |||
ContentTypeHeader content = headerFactory.createContentTypeHeader("application", "sdp"); | |||
inviterequest.addHeader(content); | |||
inviterequest.setContent(sessionDescription, content); | |||
System.out.println(inviterequest); | |||
} | |||
catch (Exception e) | |||
{ | |||
} | |||
} | |||
/** | |||
* @return the inviterequest | |||
*/ | |||
public Request getInviterequest() | |||
{ | |||
return inviterequest; | |||
} | |||
} |
@@ -0,0 +1,74 @@ | |||
/* | |||
* To change this license header, choose License Headers in Project Properties. | |||
* To change this template file, choose Tools | Templates | |||
* and open the template in the editor. | |||
*/ | |||
package model; | |||
import java.util.ArrayList; | |||
import java.util.logging.Level; | |||
import java.util.logging.Logger; | |||
import javax.sip.address.Address; | |||
import javax.sip.address.AddressFactory; | |||
import javax.sip.address.URI; | |||
import javax.sip.header.AllowHeader; | |||
import javax.sip.header.CSeqHeader; | |||
import javax.sip.header.CallIdHeader; | |||
import javax.sip.header.ContactHeader; | |||
import javax.sip.header.ExpiresHeader; | |||
import javax.sip.header.FromHeader; | |||
import javax.sip.header.HeaderFactory; | |||
import javax.sip.header.MaxForwardsHeader; | |||
import javax.sip.header.ToHeader; | |||
import javax.sip.header.ViaHeader; | |||
import javax.sip.message.MessageFactory; | |||
import javax.sip.message.Request; | |||
import logger.OhmLogger; | |||
/** | |||
* | |||
* @author Jan | |||
*/ | |||
public class SIPRegister | |||
{ | |||
private static final Logger lgRegister = OhmLogger.getLogger(); | |||
private Request request; | |||
public SIPRegister(String proxyAddress, String myTag, String myIPAddress, int myPort, | |||
int branch, AddressFactory addressFactory, HeaderFactory headerFactory, | |||
MessageFactory messageFactory, ContactHeader contactHeader, CallIdHeader callID) | |||
{ | |||
try | |||
{ | |||
Address addressto = addressFactory.createAddress("sip:" + proxyAddress); //evtl. mit Port: sip:192.168.100.11:5060 | |||
ToHeader to = headerFactory.createToHeader(addressto, null); // Integer.toString(myTag) address + myTag | |||
URI requestURI = addressto.getURI(); | |||
FromHeader from = headerFactory.createFromHeader(addressto, myTag); //this.contactAddress | |||
ArrayList via = new ArrayList(); //Via needs a List as input | |||
ViaHeader viaheader = headerFactory.createViaHeader(myIPAddress, myPort, "UDP", String.valueOf(branch)); | |||
via.add(viaheader); | |||
CSeqHeader cSeq = headerFactory.createCSeqHeader(1L, "REGISTER"); | |||
MaxForwardsHeader maxForwards = headerFactory.createMaxForwardsHeader(70); | |||
AllowHeader allow = headerFactory.createAllowHeader("NOTIFY,INVITE,ACK,CANCEL,BYE,REFER,INFO,OPTIONS,MESSAGE"); | |||
ExpiresHeader expire = headerFactory.createExpiresHeader(3600); //int value | |||
request = messageFactory.createRequest(requestURI, "REGISTER", callID, cSeq, from, to, via, maxForwards); | |||
request.addHeader(contactHeader); | |||
request.addHeader(allow); | |||
request.addHeader(expire); | |||
lgRegister.info("Erfolgreiche Register-Header erstellt"); | |||
} | |||
catch (Exception ex) | |||
{ | |||
lgRegister.getLogger(SIPmodel.class.getName()).log(Level.SEVERE, null, ex); | |||
} | |||
} | |||
/** | |||
* @return the request | |||
*/ | |||
public Request getRequest() | |||
{ | |||
return request; | |||
} | |||
} |
@@ -0,0 +1,106 @@ | |||
/* | |||
* To change this license header, choose License Headers in Project Properties. | |||
* To change this template file, choose Tools | Templates | |||
* and open the template in the editor. | |||
*/ | |||
package model; | |||
import java.util.ArrayList; | |||
import java.util.Vector; | |||
import java.util.logging.Level; | |||
import java.util.logging.Logger; | |||
import javax.sdp.SdpFactory; | |||
import javax.sdp.SessionDescription; | |||
import javax.sip.RequestEvent; | |||
import logger.OhmLogger; | |||
/** | |||
* | |||
* @author Jan | |||
*/ | |||
public class SIPSessionDescription | |||
{ | |||
private SdpFactory sdpFactory; | |||
private SessionDescription sessionDescription; | |||
private Vector mediavec; | |||
private String cods[]; | |||
private String[][] codecs; | |||
private static final Logger lgSessionDescription = OhmLogger.getLogger(); | |||
public SIPSessionDescription(String myName, String myIPAddress, | |||
RequestEvent requestEvent, Boolean anfrage) | |||
{ | |||
codecs = new String[4][2]; // Alle unterstützen Codecs eintragen | |||
codecs[0][0] = "0"; | |||
codecs[0][1] = "PCMU/8000"; | |||
codecs[1][0] = "4"; | |||
codecs[1][1] = "G723/8000"; | |||
codecs[2][0] = "8"; | |||
codecs[2][1] = "PCMA/8000"; | |||
codecs[3][0] = "18"; | |||
codecs[3][1] = "G729/8000"; | |||
cods = new String[codecs.length]; | |||
for (int i = 0; i < cods.length; i++)//Übertragung der RTP-Values in neues Array | |||
{ | |||
cods[i] = codecs[i][0]; | |||
} | |||
mediavec = new Vector(); | |||
try | |||
{ | |||
sdpFactory = SdpFactory.getInstance(); | |||
sessionDescription = sdpFactory.createSessionDescription(); | |||
sessionDescription.setOrigin(sdpFactory.createOrigin(myName, 8000, 8000, "IN", "IP4", myIPAddress)); | |||
sessionDescription.setSessionName(sdpFactory.createSessionName("SIP Call")); | |||
sessionDescription.setConnection(sdpFactory.createConnection("IN", "IP4", myIPAddress)); | |||
//Media Body | |||
mediavec.add(sdpFactory.createMediaDescription("audio", 6022, 1, "RTP/AVP", cods)); //(Übertragungstyp, Port, anzahl der Ports, Verbindungstyp,..) | |||
mediavec.add(sdpFactory.createAttribute("sendrecv", null)); | |||
if (anfrage = true) | |||
{ | |||
for (int i = 0; i == codecs[0].length; i++) | |||
{ | |||
System.out.println("Codecs: " + codecs[i][0] + " " + codecs[i][1]); | |||
mediavec.add(sdpFactory.createAttribute("rtpmap", codecs[i][0] + " " + codecs[i][1])); | |||
} | |||
} | |||
else//Vergleich von eigenen Codecs mit Codecs der anruft -> Rückgabe entsprechend wählen | |||
{ | |||
//herausfiltern der zulässigen bei Nachrichtenanfrage | |||
String[] reqbody = (requestEvent.getRequest()).toString().split("\\s|" + System.getProperty("line.seperator")); | |||
ArrayList<String> reqSDP = new ArrayList<>(); | |||
for (String req : reqbody) | |||
{ | |||
if (req.startsWith("a=rtpmap")) | |||
{ | |||
reqSDP.add(req.replace("a=rtpmap:", "")); | |||
System.out.println(reqSDP); | |||
} | |||
} | |||
boolean temp = true; //evtl noch was besseres da so erster Codec nicht bester verwendet wird | |||
for (int i = 0; i == codecs[0].length; i++) | |||
{ | |||
if (codecs[i][1].equals(reqSDP) && temp == true) | |||
{ | |||
mediavec.add(sdpFactory.createAttribute("rtpmap", "8 G711a/8000")); | |||
temp = false; | |||
} | |||
} | |||
} | |||
sessionDescription.setAttributes(mediavec); | |||
} | |||
catch (Exception ex) | |||
{ | |||
lgSessionDescription.getLogger(SIPmodel.class.getName()).log(Level.SEVERE, null, ex); | |||
} | |||
} | |||
/** | |||
* @return the sessionDescription | |||
*/ | |||
public SessionDescription getSessionDescription() | |||
{ | |||
System.out.println(sessionDescription); | |||
return sessionDescription; | |||
} | |||
} |
@@ -14,8 +14,6 @@ import java.util.*; | |||
import java.util.logging.Level; | |||
import java.util.logging.Logger; | |||
import javax.sdp.SdpException; | |||
import javax.sdp.SdpFactory; | |||
import javax.sdp.SessionDescription; | |||
import javax.sip.DialogTerminatedEvent; | |||
import javax.sip.IOExceptionEvent; | |||
import javax.sip.InvalidArgumentException; | |||
@@ -70,8 +68,8 @@ public class SIPmodel implements SipListenerExt | |||
public long cSequenz = 1; | |||
private String proxyTag; | |||
private int myTag = (new Random()).nextInt(); | |||
private int branch = hashCode(); | |||
private String myTag = String.valueOf(new Random().nextInt()); | |||
private int branch = Integer.valueOf(hashCode()); | |||
public Address contactAddress; | |||
public ContactHeader contactHeader; | |||
@@ -123,43 +121,28 @@ public class SIPmodel implements SipListenerExt | |||
public int hashCode() | |||
{ | |||
int temp = myTag * (new Random(100)).nextInt(); | |||
int temp = Integer.valueOf(myTag)* (new Random(100)).nextInt(); | |||
return temp; | |||
} | |||
public void sendRegister(String serverIP, int serverPort) throws ParseException, InvalidArgumentException, SipException | |||
{ | |||
lg.info("Vorbereiten des Registrierungs Headers"); | |||
proxyAddress = serverIP + ":" + serverPort; | |||
Address addressto = this.addressFactory.createAddress("sip:" + proxyAddress); //evtl. mit Port: sip:192.168.100.11:5060 | |||
ToHeader to = this.headerFactory.createToHeader(addressto, null); // Integer.toString(myTag) address + myTag | |||
URI requestURI = addressto.getURI(); | |||
CallIdHeader callId = this.sipProvider.getNewCallId(); | |||
FromHeader from = this.headerFactory.createFromHeader(addressto, String.valueOf(this.myTag)); //this.contactAddress | |||
ArrayList via = new ArrayList(); //Via needs a List as input | |||
ViaHeader viaheader = this.headerFactory.createViaHeader(this.myIPAddress, this.myPort, "UDP", String.valueOf(branch)); | |||
via.add(viaheader); | |||
CSeqHeader cSeq = this.headerFactory.createCSeqHeader(1L, "REGISTER"); | |||
MaxForwardsHeader maxForwards = this.headerFactory.createMaxForwardsHeader(70); | |||
AllowHeader allow = this.headerFactory.createAllowHeader("NOTIFY,INVITE,ACK,CANCEL,BYE,REFER,INFO,OPTIONS,MESSAGE"); | |||
ExpiresHeader expire = this.headerFactory.createExpiresHeader(3600); //int value | |||
Request request = this.messageFactory.createRequest(requestURI, "REGISTER", callId, cSeq, from, to, via, maxForwards); | |||
request.addHeader(contactHeader); | |||
request.addHeader(allow); | |||
request.addHeader(expire); | |||
this.sipProvider.sendRequest(request); | |||
SIPRegister register = new SIPRegister(proxyAddress, myTag, myIPAddress, myPort, branch, addressFactory, headerFactory, messageFactory, contactHeader, sipProvider.getNewCallId()); | |||
this.sipProvider.sendRequest(register.getRequest()); | |||
lg.info("Erfolgreiches Senden der Registrierung"); | |||
} | |||
public void sendInvitation(String sipaddresse, String proxyaddresse, | |||
int serverPort) throws ParseException, InvalidArgumentException, SipException, SdpException | |||
{ | |||
{ //ServerPort wird nicht verwendet? | |||
invite = true; | |||
callID = this.sipProvider.getNewCallId(); | |||
Address addressto = this.addressFactory.createAddress("sip:" + sipaddresse + "@" + proxyaddresse); | |||
ToHeader to = this.headerFactory.createToHeader(addressto, null); // Integer.toString(myTag) address + myTag | |||
URI requestURI = addressto.getURI(); | |||
callID = this.sipProvider.getNewCallId(); | |||
FromHeader from = this.headerFactory.createFromHeader(addressto, String.valueOf(this.myTag)); //this.contactAddress | |||
FromHeader from = this.headerFactory.createFromHeader(addressto, myTag); //this.contactAddress | |||
ArrayList via = new ArrayList(); //Via needs a List as input | |||
ViaHeader viaheader = this.headerFactory.createViaHeader(this.myIPAddress, this.myPort, "UDP", String.valueOf(branch)); | |||
via.add(viaheader); | |||
@@ -175,8 +158,14 @@ public class SIPmodel implements SipListenerExt | |||
request.addHeader(expire); | |||
ContentTypeHeader content = headerFactory.createContentTypeHeader("application", "sdp"); | |||
request.addHeader(content); | |||
request.setContent(createSDPHeader(null), content); | |||
this.sipProvider.sendRequest(request); | |||
SIPSessionDescription sdp = new SIPSessionDescription(myName, myIPAddress, evtWerdeAngerufen, invite); | |||
request.setContent(sdp.getSessionDescription(), content); | |||
SIPInvite sipinvite = new SIPInvite(sipaddresse, proxyaddresse, myIPAddress, myPort, myTag, branch, callID, cSequenz, addressFactory, sdp.getSessionDescription(), headerFactory, messageFactory, contactHeader); | |||
this.sipProvider.sendRequest(sipinvite.getInviterequest()); | |||
lg.info("Erfolgreiches Senden der Invitation"); | |||
} | |||
@@ -190,11 +179,12 @@ public class SIPmodel implements SipListenerExt | |||
lg.info("Option Request von Server, erstellen 200 OK zu Server"); | |||
try | |||
{ | |||
this.sipProvider.sendResponse(create200Ok(requestEvent)); | |||
SIP200Ok tempOk = new SIP200Ok(messageFactory, requestEvent, contactHeader, headerFactory); | |||
this.sipProvider.sendResponse(tempOk.getResponse()); | |||
view.getTxtArea().append("Server Option Request erfolgreich beantwortet\n"); | |||
lg.info("Erfolgreiches senden des Headers"); | |||
lg.info("Erfolgreiches senden des 200Ok-Headers"); | |||
} | |||
catch (ParseException | SipException ex) | |||
catch (SipException ex) | |||
{ | |||
lg.getLogger(SIPmodel.class.getName()).log(Level.SEVERE, null, ex); | |||
} | |||
@@ -243,14 +233,14 @@ public class SIPmodel implements SipListenerExt | |||
//Cancel Request -> Response 200 Ok + Response 487 Request Terminated | |||
//200 Ok | |||
werdeAngerufen = false; | |||
evtWerdeAngerufen = null; // sicher ist sicher | |||
this.sipProvider.sendResponse(create200Ok(requestEvent)); | |||
evtWerdeAngerufen = null; // sicher ist sicher | |||
SIP200Ok tempOk = new SIP200Ok(messageFactory, requestEvent, contactHeader, headerFactory); | |||
this.sipProvider.sendResponse(tempOk.getResponse()); | |||
view.getTxtArea().append("Anrufender canceld Anfrage\n"); | |||
lg.info("Erfolgreiches senden des 200 OkHeaders auf CancelAnfrage"); | |||
//487 Request Terminated | |||
} | |||
catch (ParseException | SipException ex) | |||
catch (SipException ex) | |||
{ | |||
Logger.getLogger(SIPmodel.class.getName()).log(Level.SEVERE, null, ex); | |||
} | |||
@@ -259,7 +249,8 @@ public class SIPmodel implements SipListenerExt | |||
{ | |||
try | |||
{ | |||
this.sipProvider.sendResponse(create200Ok(requestEvent)); | |||
SIP200Ok tempOk = new SIP200Ok(messageFactory, requestEvent, contactHeader, headerFactory); | |||
this.sipProvider.sendResponse(tempOk.getResponse()); | |||
} | |||
catch (Exception ex) | |||
{ | |||
@@ -284,7 +275,7 @@ public class SIPmodel implements SipListenerExt | |||
ToHeader to = this.headerFactory.createToHeader(addresstob, temp.getTag()); // Integer.toString(myTag) address + myTag | |||
URI requestURI = addresstob.getURI(); | |||
CallIdHeader callId = (CallIdHeader) responseEvent.getResponse().getHeader("Call-ID"); | |||
FromHeader from = this.headerFactory.createFromHeader(addresstob, String.valueOf(this.myTag)); //this.contactAddress | |||
FromHeader from = this.headerFactory.createFromHeader(addresstob, this.myTag); //this.contactAddress | |||
WWWAuthenticateHeader wwwauth = (WWWAuthenticateHeader) responseEvent.getResponse().getHeader("WWW-Authenticate"); | |||
//wird bei AuthorizationHeader wirklich alles benötigt? war glaub nur mal Test -> testen!! | |||
@@ -334,22 +325,7 @@ public class SIPmodel implements SipListenerExt | |||
} | |||
public Response create200Ok(RequestEvent requestEvent) throws ParseException | |||
{ | |||
Response response = messageFactory.createResponse(200, requestEvent.getRequest()); | |||
response.addHeader((ViaHeader) requestEvent.getRequest().getHeader("Via")); | |||
response.addHeader((FromHeader) requestEvent.getRequest().getHeader("From")); | |||
response.addHeader((ToHeader) requestEvent.getRequest().getHeader("To")); | |||
response.addHeader((CallIdHeader) requestEvent.getRequest().getHeader("Call-ID")); | |||
response.addHeader((CSeqHeader) requestEvent.getRequest().getHeader("Cseq")); | |||
response.addHeader(contactHeader); | |||
AllowHeader allow = headerFactory.createAllowHeader("NOTIFY,INVITE,ACK,CANCEL,BYE,REFER,INFO,OPTIONS,MESSAGE"); | |||
AllowEventsHeader allowevents = headerFactory.createAllowEventsHeader("talk,hold,refer,call-info"); | |||
response.addHeader((CallIdHeader) requestEvent.getRequest().getHeader("Call-ID")); | |||
response.addHeader(allow); | |||
response.addHeader(allowevents); | |||
return response; | |||
} | |||
public Response create180Ringing(RequestEvent requestEvent) throws ParseException, SipException | |||
{ | |||
@@ -361,7 +337,7 @@ public class SIPmodel implements SipListenerExt | |||
//Bei Ringing muss persönlicher Tag ergänzt werden | |||
ToHeader temptoring = (ToHeader) requestEvent.getRequest().getHeader("To"); | |||
proxyTag = temptoring.getTag(); | |||
temptoring.setTag(String.valueOf(this.myTag)); | |||
temptoring.setTag(this.myTag); | |||
responsering.addHeader(temptoring); | |||
cSequenz = ((CSeqHeader) requestEvent.getRequest().getHeader("Cseq")).getSeqNumber(); | |||
responsering.addHeader((CSeqHeader) requestEvent.getRequest().getHeader("Cseq")); | |||
@@ -376,57 +352,12 @@ public class SIPmodel implements SipListenerExt | |||
{ | |||
} | |||
public SessionDescription createSDPHeader(ArrayList<String> reqSDP) throws SdpException | |||
{ | |||
SdpFactory sdpFactory = SdpFactory.getInstance(); | |||
SessionDescription sessionDescription = sdpFactory.createSessionDescription(); | |||
sessionDescription.setOrigin(sdpFactory.createOrigin(myName, 8000, 8000, "IN", "IP4", myIPAddress)); | |||
sessionDescription.setSessionName(sdpFactory.createSessionName("SIP Call")); | |||
sessionDescription.setConnection(sdpFactory.createConnection("IN", "IP4", myIPAddress)); | |||
//Media Body | |||
Vector mediavec = new Vector(); | |||
String cods[] = new String[codecs.length]; | |||
System.out.println("System out: " + codecs.length); | |||
for (int i = 0; i < cods.length; i++)//Übertragung der RTP-Values in neues Array | |||
{ | |||
cods[i] = codecs[i][0]; | |||
} | |||
mediavec.add(sdpFactory.createMediaDescription("audio", 6022, 1, "RTP/AVP", cods)); //(Übertragungstyp, Port, anzahl der Ports, Verbindungstyp,..) | |||
mediavec.add(sdpFactory.createAttribute("sendrecv", null)); | |||
if (invite = true) | |||
{ | |||
for (int i = 0; i == codecs[0].length; i++) | |||
{ | |||
System.out.println("Codecs: " + codecs[i][0] + " " + codecs[i][1]); | |||
mediavec.add(sdpFactory.createAttribute("rtpmap", codecs[i][0] + " " + codecs[i][1])); | |||
} | |||
} | |||
else//Vergleich von eigenen Codecs mit Codecs der anruft -> Rückgabe entsprechend wählen | |||
{ | |||
boolean temp = true; //evtl noch was besseres da so erster Codec nicht bester verwendet wird | |||
for (int i = 0; i == codecs[0].length; i++) | |||
{ | |||
if (codecs[i][1].equals(reqSDP) && temp == true) | |||
{ | |||
mediavec.add(sdpFactory.createAttribute("rtpmap", "8 G711a/8000")); | |||
temp = false; | |||
} | |||
} | |||
} | |||
sessionDescription.setAttributes(mediavec); | |||
return sessionDescription; | |||
} | |||
public void annehmen() //Fehlende Bedingung | |||
{ | |||
RequestEvent requestEvent; | |||
if ((requestEvent = evtWerdeAngerufen) != null && werdeAngerufen == true) | |||
{ | |||
countWerdeAngerufen = 0; | |||
try | |||
{ | |||
callID = (CallIdHeader) requestEvent.getRequest().getHeader("Call-ID"); | |||
@@ -455,7 +386,7 @@ public class SIPmodel implements SipListenerExt | |||
responsering.addHeader((FromHeader) requestEvent.getRequest().getHeader("From")); | |||
ToHeader temptoring = (ToHeader) requestEvent.getRequest().getHeader("To"); | |||
String tempTag = String.valueOf(this.myTag + Math.random()); | |||
String tempTag = String.valueOf(Integer.valueOf(myTag)+ Math.random()); | |||
temptoring.setTag(tempTag); //evtl. besseren Tag | |||
responsering.addHeader(temptoring); | |||
@@ -471,8 +402,9 @@ public class SIPmodel implements SipListenerExt | |||
//Jetzt kommt 200 Ok SIP Header + SDP (SIP/SDP) | |||
//Sdp Header erstellen nächster Schritt | |||
invite = false; | |||
Response okandSDP = this.messageFactory.createResponse(Response.OK, requestEvent.getRequest()); | |||
/* | |||
//invite = false; | |||
//Response okandSDP = this.messageFactory.createResponse(Response.OK, requestEvent.getRequest()); | |||
//okandSDP.addHeader((ViaHeader) requestEvent.getRequest().getHeader("Via")); | |||
okandSDP.addHeader((FromHeader) requestEvent.getRequest().getHeader("From")); | |||
@@ -486,23 +418,17 @@ public class SIPmodel implements SipListenerExt | |||
ContentTypeHeader content = headerFactory.createContentTypeHeader("application", "sdp"); | |||
okandSDP.addHeader(content); | |||
String[] reqbody = (requestEvent.getRequest()).toString().split("\\s|" + System.getProperty("line.seperator"));//Req. Body in Zeilen aufteilen | |||
ArrayList<String> reqSDP = new ArrayList<>(); | |||
for (String req : reqbody)//jeden String durchgehen und nach Codecs suchen die unterstützt werden | |||
{ | |||
if (req.startsWith("a=rtpmap")) | |||
{ | |||
reqSDP.add(req.replace("a=rtpmap:", "")); | |||
System.out.println(reqSDP); | |||
} | |||
} | |||
okandSDP.setContent(createSDPHeader(reqSDP), content); | |||
SIPSessionDescription sdp = new SIPSessionDescription(myName, myIPAddress, requestEvent, invite); | |||
okandSDP.setContent(sdp.getSessionDescription(), content); | |||
this.sipProvider.sendResponse(okandSDP); | |||
*/ | |||
SIP200Ok tempOk = new SIP200Ok(messageFactory, requestEvent, contactHeader, headerFactory); | |||
SIPSessionDescription sdp = new SIPSessionDescription(myName, myIPAddress, requestEvent, invite); | |||
tempOk.addSDP(sdp.getSessionDescription(), myTag); | |||
view.getTxtArea().append("Telefonat beginnt\n"); | |||
evtWerdeAngerufen = null; | |||
} | |||
catch (ParseException | SipException | SdpException ex) | |||
catch (ParseException | SipException ex) | |||
{ | |||
Logger.getLogger(SIPmodel.class.getName()).log(Level.SEVERE, null, ex); | |||
@@ -630,7 +556,7 @@ public class SIPmodel implements SipListenerExt | |||
/** | |||
* @return the myTag | |||
*/ | |||
public int getMyTag() | |||
public String getMyTag() | |||
{ | |||
return myTag; | |||
} | |||
@@ -638,7 +564,7 @@ public class SIPmodel implements SipListenerExt | |||
/** | |||
* @param myTag the myTag to set | |||
*/ | |||
public void setMyTag(int myTag) | |||
public void setMyTag(String myTag) | |||
{ | |||
this.myTag = myTag; | |||
} |