Jan Gabriel Kunze 5 years ago
parent
commit
2dcea4b2ed

+ 1
- 4
src/controller/commands/CommandRegister.java View File



import controller.CommandInterface; import controller.CommandInterface;
import gui.Hauptfenster; import gui.Hauptfenster;
import java.text.ParseException;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import javax.sip.InvalidArgumentException;
import javax.sip.SipException;
import logger.OhmLogger; import logger.OhmLogger;
import model.SIPmodel; import model.SIPmodel;


model.sendRegister(view.getTxtServerIP().getText(), 5060); model.sendRegister(view.getTxtServerIP().getText(), 5060);
} }
catch (ParseException|InvalidArgumentException|SipException ex)
catch (Exception ex)
{ {
view.getTxtArea().append("Registrierung fehlgeschlagen\n"); view.getTxtArea().append("Registrierung fehlgeschlagen\n");
lgregister.getLogger(CommandRegister.class.getName()).log(Level.SEVERE, null, ex); lgregister.getLogger(CommandRegister.class.getName()).log(Level.SEVERE, null, ex);

+ 3
- 21
src/model/SIP180Ringing.java View File

*/ */
package model; 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 * @author Jan
*/ */
public class SIP180Ringing implements Runnable
{
public class SIP180Ringing
{/*
private RequestEvent evtubergabe; private RequestEvent evtubergabe;
private ExecutorService threadring; private ExecutorService threadring;
private boolean run; private boolean run;
} }
} }
} }
*/
} }

+ 38
- 9
src/model/SIP200Ok.java View File

*/ */
package model; package model;


import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import javax.sdp.SessionDescription;
import javax.sip.RequestEvent; import javax.sip.RequestEvent;
import javax.sip.header.AllowEventsHeader; import javax.sip.header.AllowEventsHeader;
import javax.sip.header.AllowHeader; import javax.sip.header.AllowHeader;
import javax.sip.header.CSeqHeader; import javax.sip.header.CSeqHeader;
import javax.sip.header.CallIdHeader; import javax.sip.header.CallIdHeader;
import javax.sip.header.ContactHeader; import javax.sip.header.ContactHeader;
import javax.sip.header.ContentTypeHeader;
import javax.sip.header.FromHeader; import javax.sip.header.FromHeader;
import javax.sip.header.HeaderFactory; import javax.sip.header.HeaderFactory;
import javax.sip.header.SupportedHeader;
import javax.sip.header.ToHeader; import javax.sip.header.ToHeader;
import javax.sip.header.ViaHeader; import javax.sip.header.ViaHeader;
import javax.sip.message.MessageFactory; import javax.sip.message.MessageFactory;
{ {
private Response response; private Response response;
private static final Logger lg200Ok = OhmLogger.getLogger(); private static final Logger lg200Ok = OhmLogger.getLogger();
private RequestEvent requestEvent;
private HeaderFactory headerFactory;

public SIP200Ok(MessageFactory messageFactory, RequestEvent requestEvent, public SIP200Ok(MessageFactory messageFactory, RequestEvent requestEvent,
ContactHeader contactHeader, HeaderFactory headerFactory) ContactHeader contactHeader, HeaderFactory headerFactory)
{ {
this.requestEvent = requestEvent;
this.headerFactory = headerFactory;
try 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); 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(allow);
response.addHeader(allowevents); response.addHeader(allowevents);
lg200Ok.info("200Ok Header erfolgreich erstellt"); lg200Ok.info("200Ok Header erfolgreich erstellt");
} }
} }


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 * @return the response
*/ */

+ 79
- 0
src/model/SIPInvite.java View File

/*
* 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;
}
}

+ 74
- 0
src/model/SIPRegister.java View File

/*
* 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;
}
}

+ 106
- 0
src/model/SIPSessionDescription.java View File

/*
* 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;
}
}

+ 43
- 117
src/model/SIPmodel.java View File

import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import javax.sdp.SdpException; import javax.sdp.SdpException;
import javax.sdp.SdpFactory;
import javax.sdp.SessionDescription;
import javax.sip.DialogTerminatedEvent; import javax.sip.DialogTerminatedEvent;
import javax.sip.IOExceptionEvent; import javax.sip.IOExceptionEvent;
import javax.sip.InvalidArgumentException; import javax.sip.InvalidArgumentException;


public long cSequenz = 1; public long cSequenz = 1;
private String proxyTag; 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 Address contactAddress;
public ContactHeader contactHeader; public ContactHeader contactHeader;




public int hashCode() public int hashCode()
{ {
int temp = myTag * (new Random(100)).nextInt();
int temp = Integer.valueOf(myTag)* (new Random(100)).nextInt();
return temp; return temp;
} }


public void sendRegister(String serverIP, int serverPort) throws ParseException, InvalidArgumentException, SipException public void sendRegister(String serverIP, int serverPort) throws ParseException, InvalidArgumentException, SipException
{ {
lg.info("Vorbereiten des Registrierungs Headers");
proxyAddress = serverIP + ":" + serverPort; 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"); lg.info("Erfolgreiches Senden der Registrierung");
} }


public void sendInvitation(String sipaddresse, String proxyaddresse, public void sendInvitation(String sipaddresse, String proxyaddresse,
int serverPort) throws ParseException, InvalidArgumentException, SipException, SdpException int serverPort) throws ParseException, InvalidArgumentException, SipException, SdpException
{
{ //ServerPort wird nicht verwendet?
invite = true; invite = true;
callID = this.sipProvider.getNewCallId();
Address addressto = this.addressFactory.createAddress("sip:" + sipaddresse + "@" + proxyaddresse); Address addressto = this.addressFactory.createAddress("sip:" + sipaddresse + "@" + proxyaddresse);
ToHeader to = this.headerFactory.createToHeader(addressto, null); // Integer.toString(myTag) address + myTag ToHeader to = this.headerFactory.createToHeader(addressto, null); // Integer.toString(myTag) address + myTag
URI requestURI = addressto.getURI(); 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 ArrayList via = new ArrayList(); //Via needs a List as input
ViaHeader viaheader = this.headerFactory.createViaHeader(this.myIPAddress, this.myPort, "UDP", String.valueOf(branch)); ViaHeader viaheader = this.headerFactory.createViaHeader(this.myIPAddress, this.myPort, "UDP", String.valueOf(branch));
via.add(viaheader); via.add(viaheader);
request.addHeader(expire); request.addHeader(expire);
ContentTypeHeader content = headerFactory.createContentTypeHeader("application", "sdp"); ContentTypeHeader content = headerFactory.createContentTypeHeader("application", "sdp");
request.addHeader(content); 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"); lg.info("Erfolgreiches Senden der Invitation");
} }
lg.info("Option Request von Server, erstellen 200 OK zu Server"); lg.info("Option Request von Server, erstellen 200 OK zu Server");
try 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"); 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); lg.getLogger(SIPmodel.class.getName()).log(Level.SEVERE, null, ex);
} }
//Cancel Request -> Response 200 Ok + Response 487 Request Terminated //Cancel Request -> Response 200 Ok + Response 487 Request Terminated
//200 Ok //200 Ok
werdeAngerufen = false; 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"); view.getTxtArea().append("Anrufender canceld Anfrage\n");
lg.info("Erfolgreiches senden des 200 OkHeaders auf CancelAnfrage"); lg.info("Erfolgreiches senden des 200 OkHeaders auf CancelAnfrage");
//487 Request Terminated //487 Request Terminated

} }
catch (ParseException | SipException ex)
catch (SipException ex)
{ {
Logger.getLogger(SIPmodel.class.getName()).log(Level.SEVERE, null, ex); Logger.getLogger(SIPmodel.class.getName()).log(Level.SEVERE, null, ex);
} }
{ {
try try
{ {
this.sipProvider.sendResponse(create200Ok(requestEvent));
SIP200Ok tempOk = new SIP200Ok(messageFactory, requestEvent, contactHeader, headerFactory);
this.sipProvider.sendResponse(tempOk.getResponse());
} }
catch (Exception ex) catch (Exception ex)
{ {
ToHeader to = this.headerFactory.createToHeader(addresstob, temp.getTag()); // Integer.toString(myTag) address + myTag ToHeader to = this.headerFactory.createToHeader(addresstob, temp.getTag()); // Integer.toString(myTag) address + myTag
URI requestURI = addresstob.getURI(); URI requestURI = addresstob.getURI();
CallIdHeader callId = (CallIdHeader) responseEvent.getResponse().getHeader("Call-ID"); 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"); WWWAuthenticateHeader wwwauth = (WWWAuthenticateHeader) responseEvent.getResponse().getHeader("WWW-Authenticate");


//wird bei AuthorizationHeader wirklich alles benötigt? war glaub nur mal Test -> testen!! //wird bei AuthorizationHeader wirklich alles benötigt? war glaub nur mal Test -> testen!!


} }


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 public Response create180Ringing(RequestEvent requestEvent) throws ParseException, SipException
{ {
//Bei Ringing muss persönlicher Tag ergänzt werden //Bei Ringing muss persönlicher Tag ergänzt werden
ToHeader temptoring = (ToHeader) requestEvent.getRequest().getHeader("To"); ToHeader temptoring = (ToHeader) requestEvent.getRequest().getHeader("To");
proxyTag = temptoring.getTag(); proxyTag = temptoring.getTag();
temptoring.setTag(String.valueOf(this.myTag));
temptoring.setTag(this.myTag);
responsering.addHeader(temptoring); responsering.addHeader(temptoring);
cSequenz = ((CSeqHeader) requestEvent.getRequest().getHeader("Cseq")).getSeqNumber(); cSequenz = ((CSeqHeader) requestEvent.getRequest().getHeader("Cseq")).getSeqNumber();
responsering.addHeader((CSeqHeader) requestEvent.getRequest().getHeader("Cseq")); responsering.addHeader((CSeqHeader) requestEvent.getRequest().getHeader("Cseq"));
{ {
} }


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 public void annehmen() //Fehlende Bedingung
{ {
RequestEvent requestEvent; RequestEvent requestEvent;
if ((requestEvent = evtWerdeAngerufen) != null && werdeAngerufen == true) if ((requestEvent = evtWerdeAngerufen) != null && werdeAngerufen == true)
{ {
countWerdeAngerufen = 0; countWerdeAngerufen = 0;

try try
{ {
callID = (CallIdHeader) requestEvent.getRequest().getHeader("Call-ID"); callID = (CallIdHeader) requestEvent.getRequest().getHeader("Call-ID");
responsering.addHeader((FromHeader) requestEvent.getRequest().getHeader("From")); responsering.addHeader((FromHeader) requestEvent.getRequest().getHeader("From"));


ToHeader temptoring = (ToHeader) requestEvent.getRequest().getHeader("To"); 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 temptoring.setTag(tempTag); //evtl. besseren Tag
responsering.addHeader(temptoring); responsering.addHeader(temptoring);




//Jetzt kommt 200 Ok SIP Header + SDP (SIP/SDP) //Jetzt kommt 200 Ok SIP Header + SDP (SIP/SDP)
//Sdp Header erstellen nächster Schritt //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((ViaHeader) requestEvent.getRequest().getHeader("Via"));
okandSDP.addHeader((FromHeader) requestEvent.getRequest().getHeader("From")); okandSDP.addHeader((FromHeader) requestEvent.getRequest().getHeader("From"));


ContentTypeHeader content = headerFactory.createContentTypeHeader("application", "sdp"); ContentTypeHeader content = headerFactory.createContentTypeHeader("application", "sdp");
okandSDP.addHeader(content); 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); 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"); view.getTxtArea().append("Telefonat beginnt\n");
evtWerdeAngerufen = null; evtWerdeAngerufen = null;
} }
catch (ParseException | SipException | SdpException ex)
catch (ParseException | SipException ex)
{ {
Logger.getLogger(SIPmodel.class.getName()).log(Level.SEVERE, null, ex); Logger.getLogger(SIPmodel.class.getName()).log(Level.SEVERE, null, ex);


/** /**
* @return the myTag * @return the myTag
*/ */
public int getMyTag()
public String getMyTag()
{ {
return myTag; return myTag;
} }
/** /**
* @param myTag the myTag to set * @param myTag the myTag to set
*/ */
public void setMyTag(int myTag)
public void setMyTag(String myTag)
{ {
this.myTag = myTag; this.myTag = myTag;
} }

Loading…
Cancel
Save