Jan Gabriel Kunze 5 years ago
parent
commit
3531dfd856

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

@@ -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.sdp.SdpException;
import javax.sip.InvalidArgumentException;
import javax.sip.SipException;
import logger.OhmLogger;
import model.SIPmodel;
@@ -41,7 +38,7 @@ public class CommandInvite implements CommandInterface
view.getTxtArea().append("Einladung an " + view.getTxtcallIP().getText() + " gesendet\n");
model.sendInvitation(view.getTxtcallIP().getText(),view.getTxtServerIP().getText(), 5078);
}
catch (ParseException|InvalidArgumentException|SdpException|SipException ex)
catch (SipException ex)
{
view.getTxtArea().append("Einladung fehlgeschlagen\n");
lginvite.getLogger(CommandInvite.class.getName()).log(Level.SEVERE, null, ex);

+ 62
- 0
src/model/SIP100Trying.java View File

@@ -0,0 +1,62 @@
/*
* 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.logging.Level;
import java.util.logging.Logger;
import javax.sip.RequestEvent;
import javax.sip.header.AllowHeader;
import javax.sip.header.CSeqHeader;
import javax.sip.header.CallIdHeader;
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;
import javax.sip.message.Response;
import logger.OhmLogger;

/**
*
* @author Jan
*/
public class SIP100Trying
{
private Response tryResponse;
private static final Logger lgTry = OhmLogger.getLogger();

public SIP100Trying(MessageFactory messageFactory, RequestEvent requestEvent,
HeaderFactory headerFactory)
{
try
{ //
tryResponse = messageFactory.createResponse(100, requestEvent.getRequest());
tryResponse.addHeader((ViaHeader) requestEvent.getRequest().getHeader("Via"));
tryResponse.addHeader((FromHeader) requestEvent.getRequest().getHeader("From"));
tryResponse.addHeader((ToHeader) requestEvent.getRequest().getHeader("To"));
tryResponse.addHeader((CallIdHeader) requestEvent.getRequest().getHeader("Call-ID"));
tryResponse.addHeader((CSeqHeader) requestEvent.getRequest().getHeader("Cseq"));
SupportedHeader supp = headerFactory.createSupportedHeader("replace,path,timer"); //nachschauen
AllowHeader allow = headerFactory.createAllowHeader("NOTIFY,INVITE,ACK,CANCEL,BYE,REFER,INFO,OPTIONS,MESSAGE");
tryResponse.addHeader(supp);
tryResponse.addHeader(allow);
}
catch (Exception ex)
{
lgTry.getLogger(SIPmodel.class.getName()).log(Level.SEVERE, null, ex);
}

}

/**
* @return the tryResponse
*/
public Response getTryResponse()
{
return tryResponse;
}
}

+ 51
- 48
src/model/SIP180Ringing.java View File

@@ -5,87 +5,90 @@
*/
package model;

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.header.CSeqHeader;
import javax.sip.header.CallIdHeader;
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
{/*
private RequestEvent evtubergabe;
public class SIP180Ringing implements Runnable
{
private RequestEvent requestEvent;
private ExecutorService threadring;
private boolean run;
private Response responsering;
private boolean callIncoming;
private Response responseRing;
private MessageFactory messageFactory;
private HeaderFactory headerFactory;
private String myTag;
private String proxyTag;
public static final Logger lg = OhmLogger.getLogger();
public static final Logger lgRing = OhmLogger.getLogger();
//private SubmissionPublisher<Integer> publisherZahl;

public SIP180Ringing(RequestEvent evtubergabe, String myTag, ContactHeader contact)
public SIP180Ringing(RequestEvent requestEvent, String myTag, String proxyTag, ContactHeader contact, HeaderFactory headerFactory)
{
this.evtubergabe = evtubergabe;
threadring = Executors.newSingleThreadExecutor();
this.requestEvent = requestEvent;
this.headerFactory = headerFactory;
threadring = Executors.newSingleThreadExecutor();
try
{
responsering = this.messageFactory.createResponse(180, evtubergabe.getRequest());
responsering.addHeader((ViaHeader) evtubergabe.getRequest().getHeader("Via"));
responsering.addHeader((FromHeader) evtubergabe.getRequest().getHeader("From"));
AllowHeader allow = this.headerFactory.createAllowHeader("NOTIFY,INVITE,ACK,CANCEL,BYE,REFER,INFO,OPTIONS,MESSAGE");
//Bei Ringing muss persönlicher Tag ergänzt werden
ToHeader temptoring = (ToHeader) evtubergabe.getRequest().getHeader("To");
proxyTag = temptoring.getTag();
temptoring.setTag(String.valueOf(this.myTag));
responsering.addHeader(temptoring);
long cSequenz = ((CSeqHeader) evtubergabe.getRequest().getHeader("Cseq")).getSeqNumber();
responsering.addHeader((CSeqHeader) evtubergabe.getRequest().getHeader("Cseq"));
responsering.addHeader(contact);
responsering.addHeader(allow);
AllowEventsHeader allowevent = this.headerFactory.createAllowEventsHeader("talk,hold,refer,call-info");// für was gebraucht
responsering.addHeader(allowevent);
lg.info("Ringing Header erfolgreich erstellt");
responseRing = this.messageFactory.createResponse(180, this.requestEvent.getRequest());
responseRing.addHeader((ViaHeader) this.requestEvent.getRequest().getHeader("Via"));
responseRing.addHeader((FromHeader) this.requestEvent.getRequest().getHeader("From"));
//persönlichen Tag muss beim To-Header ergänzt werden
ToHeader tempTo = ((ToHeader) this.requestEvent.getRequest().getHeader("To"));
tempTo.setTag(myTag);
responseRing.addHeader(tempTo);
responseRing.addHeader((CallIdHeader) requestEvent.getRequest().getHeader("Call-ID"));
responseRing.addHeader((CSeqHeader) this.requestEvent.getRequest().getHeader("Cseq"));
responseRing.addHeader(contact);
responseRing.addHeader(headerFactory.createSupportedHeader("replace,path,timer"));
responseRing.addHeader(this.headerFactory.createAllowHeader("NOTIFY,INVITE,ACK,CANCEL,BYE,REFER,INFO,OPTIONS,MESSAGE"));
responseRing.addHeader(this.headerFactory.createAllowEventsHeader("talk,hold,refer")); //für was wird er gebraucht
lgRing.info("Ringing Header erfolgreich erstellt");
}
catch (Exception ex)
{
lg.info("Fehler bei erstellen des Ringing Headers");
lg.getLogger(SIPmodel.class.getName()).log(Level.SEVERE, null, ex);
lgRing.getLogger(SIPmodel.class.getName()).log(Level.SEVERE, null, ex);
}
}

public void start()
{
run = true;
threadring.submit(this);
callIncoming = true;
}

public void stop()
{
run = false;
callIncoming = false;
}

@Override
public void run()
{
while (run)
while (callIncoming)
{
try
{
this.sipProvider.sendResponse(responsering);
}
catch (SipException ex)
{
Logger.getLogger(SIP180Ringing.class.getName()).log(Level.SEVERE, null, ex);
}
try
{
sleep(1000);
}
catch (Exception e)
{
}
}
}
*/

/**
* @return the responseRing
*/
public Response getResponseRing()
{
return responseRing;
}
}

+ 2
- 1
src/model/SIP200Ok.java View File

@@ -72,6 +72,7 @@ public class SIP200Ok
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);
@@ -81,7 +82,7 @@ public class SIP200Ok
lg200Ok.getLogger(SIPmodel.class.getName()).log(Level.SEVERE, null, ex);
}
}
/**
* @return the response
*/

+ 3
- 1
src/model/SIPInvite.java View File

@@ -6,6 +6,7 @@
package model;

import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.sdp.SessionDescription;
import javax.sip.address.Address;
@@ -63,8 +64,9 @@ public class SIPInvite
inviterequest.setContent(sessionDescription, content);
System.out.println(inviterequest);
}
catch (Exception e)
catch (Exception ex)
{
lgInvite.getLogger(SIPmodel.class.getName()).log(Level.SEVERE, null, ex);
}

}

+ 18
- 12
src/model/SIPSessionDescription.java View File

@@ -40,7 +40,7 @@ public class SIPSessionDescription
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
for (int i = 0; i < 4; i++)//Übertragung der RTP-Values in neues Array
{
cods[i] = codecs[i][0];
}
@@ -54,11 +54,12 @@ public class SIPSessionDescription
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)

if (anfrage == true)
{
for (int i = 0; i == codecs[0].length; i++)
mediavec.add(sdpFactory.createMediaDescription("audio", 6022, 1, "RTP/AVP", cods)); //(Übertragungstyp, Port, anzahl der Ports, Verbindungstyp,..)
mediavec.add(sdpFactory.createAttribute("sendrecv", null));
for (int i = 0; i == 4; i++)
{
System.out.println("Codecs: " + codecs[i][0] + " " + codecs[i][1]);
mediavec.add(sdpFactory.createAttribute("rtpmap", codecs[i][0] + " " + codecs[i][1]));
@@ -66,7 +67,6 @@ public class SIPSessionDescription
}
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)
@@ -74,17 +74,24 @@ public class SIPSessionDescription
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++)
int position = 0;
for (String stcodec : cods)
{
if (codecs[i][1].equals(reqSDP) && temp == true)
{
mediavec.add(sdpFactory.createAttribute("rtpmap", "8 G711a/8000"));
System.out.println("------Auswahl des codecs----");
if (reqSDP.contains(stcodec) && temp == true)
{
String tempcodec[]= new String [1];
tempcodec[0] = codecs[position][1];
mediavec.add(sdpFactory.createMediaDescription("audio", 6022, 1, "RTP/AVP", tempcodec)); //(Übertragungstyp, Port, anzahl der Ports, Verbindungstyp,..)
mediavec.add(sdpFactory.createAttribute("sendrecv", null));
mediavec.add(sdpFactory.createAttribute("rtpmap", codecs[position][0] + " " + codecs[position][1]));
temp = false;
}
position++;
}
}
sessionDescription.setAttributes(mediavec);
@@ -100,7 +107,6 @@ public class SIPSessionDescription
*/
public SessionDescription getSessionDescription()
{
System.out.println(sessionDescription);
return sessionDescription;
}
}

+ 22
- 91
src/model/SIPmodel.java View File

@@ -13,7 +13,6 @@ import java.text.ParseException;
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.sdp.SdpException;
import javax.sip.DialogTerminatedEvent;
import javax.sip.IOExceptionEvent;
import javax.sip.InvalidArgumentException;
@@ -118,13 +117,11 @@ public class SIPmodel implements SipListenerExt
System.exit(-1);
}
}

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

public void sendRegister(String serverIP, int serverPort) throws ParseException, InvalidArgumentException, SipException
{
proxyAddress = serverIP + ":" + serverPort;
@@ -132,41 +129,14 @@ public class SIPmodel implements SipListenerExt
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
int serverPort) throws SipException
{ //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();
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);

CSeqHeader cSeq = this.headerFactory.createCSeqHeader(cSequenz, "INVITE");

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, "INVITE", callID, cSeq, from, to, via, maxForwards);
request.addHeader(contactHeader);
request.addHeader(allow);
request.addHeader(expire);
ContentTypeHeader content = headerFactory.createContentTypeHeader("application", "sdp");
request.addHeader(content);
SIPSessionDescription sdp = new SIPSessionDescription(myName, myIPAddress, evtWerdeAngerufen, invite);
request.setContent(sdp.getSessionDescription(), content);
SIPSessionDescription sdp = new SIPSessionDescription(myName, myIPAddress, evtWerdeAngerufen, true);
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");
}

@@ -359,76 +329,37 @@ public class SIPmodel implements SipListenerExt
{
countWerdeAngerufen = 0;
try
{
{
//Werte für weitere Kommunikation abspeichern
callID = (CallIdHeader) requestEvent.getRequest().getHeader("Call-ID");
//Trying Message to Server (Response Trying)
Response responsetry = this.messageFactory.createResponse(100, requestEvent.getRequest());
responsetry.addHeader((ViaHeader) requestEvent.getRequest().getHeader("Via"));
responsetry.addHeader((FromHeader) requestEvent.getRequest().getHeader("From"));
responsetry.addHeader((ToHeader) requestEvent.getRequest().getHeader("To"));
responsetry.addHeader((CallIdHeader) requestEvent.getRequest().getHeader("Call-ID"));
responsetry.addHeader((CSeqHeader) requestEvent.getRequest().getHeader("Cseq"));

CSeqHeader tempcs = (CSeqHeader) requestEvent.getRequest().getHeader("Cseq");
tempcs.getSeqNumber();
SupportedHeader supp = this.headerFactory.createSupportedHeader("replace,path,timer"); //nachschauen
AllowHeader allow = this.headerFactory.createAllowHeader("NOTIFY,INVITE,ACK,CANCEL,BYE,REFER,INFO,OPTIONS,MESSAGE");

responsetry.addHeader(supp);
responsetry.addHeader(allow);
this.sipProvider.sendResponse(responsetry);
CSeqHeader tempCs = (CSeqHeader) requestEvent.getRequest().getHeader("Cseq");
cSequenz = tempCs.getSeqNumber();
FromHeader tempFrom = (FromHeader) requestEvent.getRequest().getHeader("From");
proxyTag = tempFrom.getTag();
//Trying Header erzeugen und abschicken
SIP100Trying tempTrying = new SIP100Trying(messageFactory, requestEvent, headerFactory);
this.sipProvider.sendResponse(tempTrying.getTryResponse());
view.getTxtArea().append("Trying geschickt\n");
lg.info("Trying ist raus");

//Ringing Message to Server (Responste Ringing)
Response responsering = this.messageFactory.createResponse(180, requestEvent.getRequest());
responsering.addHeader((ViaHeader) requestEvent.getRequest().getHeader("Via"));
responsering.addHeader((FromHeader) requestEvent.getRequest().getHeader("From"));

ToHeader temptoring = (ToHeader) requestEvent.getRequest().getHeader("To");
String tempTag = String.valueOf(Integer.valueOf(myTag)+ Math.random());
temptoring.setTag(tempTag); //evtl. besseren Tag
responsering.addHeader(temptoring);

responsering.addHeader((CSeqHeader) requestEvent.getRequest().getHeader("Cseq"));
responsering.addHeader(contactHeader);
responsering.addHeader(supp);
responsering.addHeader(allow);

AllowEventsHeader allowevent = this.headerFactory.createAllowEventsHeader("talk,hold");// für was gebraucht
responsering.addHeader(allowevent);
this.sipProvider.sendResponse(responsering);
//Ringing Message to Server (Responste Ringing)From tag: proxyTag, To Tag, persönlicher Tag
SIP180Ringing tempRinging = new SIP180Ringing(requestEvent, myTag, proxyTag, contactHeader, headerFactory);
sipProvider.sendResponse(tempRinging.getResponseRing());
view.getTxtArea().append("Ringing geschickt\n");

//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());
//okandSDP.addHeader((ViaHeader) requestEvent.getRequest().getHeader("Via"));
okandSDP.addHeader((FromHeader) requestEvent.getRequest().getHeader("From"));

okandSDP.addHeader(temptoring); //evtl noch Ergänzungen

okandSDP.addHeader((CSeqHeader) requestEvent.getRequest().getHeader("Cseq"));
okandSDP.addHeader(contactHeader);
okandSDP.addHeader(supp);
okandSDP.addHeader(allow);
okandSDP.addHeader(allowevent);
ContentTypeHeader content = headerFactory.createContentTypeHeader("application", "sdp");
okandSDP.addHeader(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);
invite = false;
SIP200Ok respcall = new SIP200Ok(messageFactory, requestEvent, contactHeader, headerFactory);
SIPSessionDescription sdp = new SIPSessionDescription(myName, myIPAddress, requestEvent, false);
respcall.addSDP(sdp.getSessionDescription(), myTag);
System.out.println(respcall.getResponse());
this.sipProvider.sendResponse(respcall.getResponse());
view.getTxtArea().append("Telefonat beginnt\n");
evtWerdeAngerufen = null;
}
catch (ParseException | SipException ex)
catch (SipException ex)
{
Logger.getLogger(SIPmodel.class.getName()).log(Level.SEVERE, null, ex);


Loading…
Cancel
Save