Jan Gabriel Kunze 5 years ago
parent
commit
029a075568

+ 10
- 40
src/model/SIP180Ringing.java View File

*/ */
package model; package model;


import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import javax.sip.RequestEvent; import javax.sip.RequestEvent;
* *
* @author Jan * @author Jan
*/ */
public class SIP180Ringing implements Runnable
public class SIP180Ringing
{ {
private RequestEvent requestEvent;
private ExecutorService threadring; //für wiederholtes senden des Ringing Headers
private boolean callIncoming;
private Response responseRing; private Response responseRing;
private MessageFactory messageFactory;
private HeaderFactory headerFactory;
private String myTag;
private String proxyTag;
public static final Logger lgRing = OhmLogger.getLogger(); public static final Logger lgRing = OhmLogger.getLogger();
//private SubmissionPublisher<Integer> publisherZahl; //private SubmissionPublisher<Integer> publisherZahl;


public SIP180Ringing(RequestEvent requestEvent, String myTag, String proxyTag, ContactHeader contact, HeaderFactory headerFactory)
public SIP180Ringing(RequestEvent requestEvent, String myTag, ContactHeader contact,
HeaderFactory headerFactory, MessageFactory messageFactory)
{ {
this.requestEvent = requestEvent;
this.headerFactory = headerFactory;
threadring = Executors.newSingleThreadExecutor();
try try
{ {
responseRing = this.messageFactory.createResponse(180, this.requestEvent.getRequest());
responseRing.addHeader((ViaHeader) this.requestEvent.getRequest().getHeader("Via"));
responseRing.addHeader((FromHeader) this.requestEvent.getRequest().getHeader("From"));
responseRing = messageFactory.createResponse(180, requestEvent.getRequest());
responseRing.addHeader((ViaHeader) requestEvent.getRequest().getHeader("Via"));
responseRing.addHeader((FromHeader) requestEvent.getRequest().getHeader("From"));
//persönlichen Tag muss beim To-Header ergänzt werden //persönlichen Tag muss beim To-Header ergänzt werden
ToHeader tempTo = ((ToHeader) this.requestEvent.getRequest().getHeader("To"));
ToHeader tempTo = ((ToHeader) requestEvent.getRequest().getHeader("To"));
tempTo.setTag(myTag); tempTo.setTag(myTag);
responseRing.addHeader(tempTo); responseRing.addHeader(tempTo);
responseRing.addHeader((CallIdHeader) requestEvent.getRequest().getHeader("Call-ID")); responseRing.addHeader((CallIdHeader) requestEvent.getRequest().getHeader("Call-ID"));
responseRing.addHeader((CSeqHeader) this.requestEvent.getRequest().getHeader("Cseq"));
responseRing.addHeader((CSeqHeader) requestEvent.getRequest().getHeader("Cseq"));
responseRing.addHeader(contact); responseRing.addHeader(contact);
responseRing.addHeader(headerFactory.createSupportedHeader("replace,path,timer")); 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
responseRing.addHeader(headerFactory.createAllowHeader("NOTIFY,INVITE,ACK,CANCEL,BYE,REFER,INFO,OPTIONS,MESSAGE"));
responseRing.addHeader(headerFactory.createAllowEventsHeader("talk,hold,refer")); //für was wird er gebraucht
lgRing.info("180-Ringing Header erstellt"); lgRing.info("180-Ringing Header erstellt");
} }
catch (Exception ex) catch (Exception ex)
lgRing.getLogger(SIPmodel.class.getName()).log(Level.SEVERE, null, ex); lgRing.getLogger(SIPmodel.class.getName()).log(Level.SEVERE, null, ex);
} }
} }

public void start()
{
callIncoming = true;
}

public void stop()
{
callIncoming = false;
}

@Override
public void run()
{
while (callIncoming)
{
}
}
/** /**
* @return the responseRing * @return the responseRing
*/ */

+ 6
- 5
src/model/SIP200Ok.java View File

private static final Logger lg200Ok = OhmLogger.getLogger(); private static final Logger lg200Ok = OhmLogger.getLogger();
private RequestEvent requestEvent; private RequestEvent requestEvent;
private HeaderFactory headerFactory; private HeaderFactory headerFactory;
private ContactHeader contactHeader;
public SIP200Ok(MessageFactory messageFactory, RequestEvent requestEvent, public SIP200Ok(MessageFactory messageFactory, RequestEvent requestEvent,
ContactHeader contactHeader, HeaderFactory headerFactory) ContactHeader contactHeader, HeaderFactory headerFactory)
{ {
this.requestEvent = requestEvent; this.requestEvent = requestEvent;
this.headerFactory = headerFactory; this.headerFactory = headerFactory;
this.contactHeader = contactHeader;
try try
{ {
response = messageFactory.createResponse(Response.OK, this.requestEvent.getRequest()); response = messageFactory.createResponse(Response.OK, this.requestEvent.getRequest());
response.addHeader((ViaHeader) this.requestEvent.getRequest().getHeader("Via")); response.addHeader((ViaHeader) this.requestEvent.getRequest().getHeader("Via"));
System.out.println(this.requestEvent.getRequest().getHeader("Via"));
response.addHeader((FromHeader) this.requestEvent.getRequest().getHeader("From")); response.addHeader((FromHeader) this.requestEvent.getRequest().getHeader("From"));
response.addHeader((ToHeader) this.requestEvent.getRequest().getHeader("To")); response.addHeader((ToHeader) this.requestEvent.getRequest().getHeader("To"));
response.addHeader((CallIdHeader) this.requestEvent.getRequest().getHeader("Call-ID")); response.addHeader((CallIdHeader) this.requestEvent.getRequest().getHeader("Call-ID"));
public void addSDP(SessionDescription sdp, String myTag) public void addSDP(SessionDescription sdp, String myTag)
{ {
try try
{
{
response.removeHeader("To"); response.removeHeader("To");
ToHeader temptoring = (ToHeader) requestEvent.getRequest().getHeader("To"); ToHeader temptoring = (ToHeader) requestEvent.getRequest().getHeader("To");
temptoring.setTag(myTag); //evtl. besseren Tag
response.addHeader(temptoring); //evtl noch Ergänzungen
temptoring.setTag(myTag);
response.addHeader(temptoring);
SupportedHeader supp = this.headerFactory.createSupportedHeader("replace,path,timer");//nachschauen für was es gebraucht wird SupportedHeader supp = this.headerFactory.createSupportedHeader("replace,path,timer");//nachschauen für was es gebraucht wird
response.addHeader(supp); response.addHeader(supp);
ContentTypeHeader content = headerFactory.createContentTypeHeader("application", "sdp"); ContentTypeHeader content = headerFactory.createContentTypeHeader("application", "sdp");
response.addHeader(content); response.addHeader(content);
response.setContent(sdp, content); response.setContent(sdp, content);

+ 8
- 5
src/model/SIPInvite.java View File



public SIPInvite(String sipaddresse, String proxyaddresse, String myIPAddress, public SIPInvite(String sipaddresse, String proxyaddresse, String myIPAddress,
int myPort, int myPort,
String myTag, int branch, CallIdHeader callID, long cSequenz,
AddressFactory addressFactory, SessionDescription sessionDescription,
HeaderFactory headerFactory, MessageFactory messageFactory, ContactHeader contactHeader)
String myTag, String branch, CallIdHeader callID,
long cSequenz,
AddressFactory addressFactory,
SessionDescription sessionDescription,
HeaderFactory headerFactory, MessageFactory messageFactory,
ContactHeader contactHeader)
{ {
try try
{ {
Address addressto = addressFactory.createAddress("sip:" + sipaddresse + "@" + proxyaddresse); Address addressto = addressFactory.createAddress("sip:" + sipaddresse + "@" + proxyaddresse);
ToHeader to = headerFactory.createToHeader(addressto, null); // Integer.toString(myTag) address + myTag ToHeader to = headerFactory.createToHeader(addressto, null); // Integer.toString(myTag) address + myTag
URI requestURI = addressto.getURI(); URI requestURI = addressto.getURI();
FromHeader from = headerFactory.createFromHeader(addressto, String.valueOf(myTag)); //this.contactAddress
FromHeader from = 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 = headerFactory.createViaHeader(myIPAddress, myPort, "UDP", String.valueOf(branch));
ViaHeader viaheader = headerFactory.createViaHeader(myIPAddress, myPort, "UDP", branch);
via.add(viaheader); via.add(viaheader);
CSeqHeader cSeq = headerFactory.createCSeqHeader(cSequenz, "INVITE"); CSeqHeader cSeq = headerFactory.createCSeqHeader(cSequenz, "INVITE");
MaxForwardsHeader maxForwards = headerFactory.createMaxForwardsHeader(70); MaxForwardsHeader maxForwards = headerFactory.createMaxForwardsHeader(70);

+ 2
- 2
src/model/SIPRegister.java View File

private static final Logger lgRegister = OhmLogger.getLogger(); private static final Logger lgRegister = OhmLogger.getLogger();
public SIPRegister(String proxyAddress, String myTag, String myIPAddress, int myPort, public SIPRegister(String proxyAddress, String myTag, String myIPAddress, int myPort,
int branch, AddressFactory addressFactory, HeaderFactory headerFactory,
String branch, AddressFactory addressFactory, HeaderFactory headerFactory,
MessageFactory messageFactory, ContactHeader contactHeader, CallIdHeader callID) MessageFactory messageFactory, ContactHeader contactHeader, CallIdHeader callID)
{ {
try try
URI requestURI = addressto.getURI(); URI requestURI = addressto.getURI();
FromHeader from = headerFactory.createFromHeader(addressto, myTag); //this.contactAddress FromHeader from = 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 = headerFactory.createViaHeader(myIPAddress, myPort, "UDP", String.valueOf(branch));
ViaHeader viaheader = headerFactory.createViaHeader(myIPAddress, myPort, "UDP", branch);
via.add(viaheader); via.add(viaheader);
CSeqHeader cSeq = headerFactory.createCSeqHeader(1L, "REGISTER"); CSeqHeader cSeq = headerFactory.createCSeqHeader(1L, "REGISTER");
MaxForwardsHeader maxForwards = headerFactory.createMaxForwardsHeader(70); MaxForwardsHeader maxForwards = headerFactory.createMaxForwardsHeader(70);

+ 26
- 33
src/model/SIPSessionDescription.java View File

private SdpFactory sdpFactory; private SdpFactory sdpFactory;
private SessionDescription sessionDescription; private SessionDescription sessionDescription;
private Vector mediavec; private Vector mediavec;
private String cods[]; //Hilfsarray für [RTP-Notation]
private String[][] codecs; //[RTP-Notation][Codec/SampelRate]
private String codsRTP[]; //[RTP-Notation]
private String codecs[]; //[Codec/SampelRate]
private static final Logger lgSessionDescription = OhmLogger.getLogger(); private static final Logger lgSessionDescription = OhmLogger.getLogger();


public SIPSessionDescription(String myName, String myIPAddress, public SIPSessionDescription(String myName, String myIPAddress,
RequestEvent requestEvent, Boolean anfrage) RequestEvent requestEvent, Boolean anfrage)
{ {
//Hier alle unterstützen Codecs eintragen [RTP-Notation][Codec/SampelRate] //Hier alle unterstützen Codecs eintragen [RTP-Notation][Codec/SampelRate]
codecs = new String[4][2];
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";
codsRTP = new String[4];
codsRTP[0]= "0";
codsRTP[1] ="4";
codsRTP[2]= "8";
codsRTP[3]= "18";
cods = new String[codecs.length];
for (int i = 0; i < 4; i++)//Übertragung der RTP-Values in neues Array
{
cods[i] = codecs[i][0];
}
codecs = new String[4];
codecs[0] = "PCMU/8000";
codecs[1] = "G723/8000";
codecs[2]= "PCMA/8000";
codecs[3]= "G729/8000";
mediavec = new Vector(); mediavec = new Vector();
try try
{ {
sessionDescription.setSessionName(sdpFactory.createSessionName("SIP Call")); sessionDescription.setSessionName(sdpFactory.createSessionName("SIP Call"));
sessionDescription.setConnection(sdpFactory.createConnection("IN", "IP4", myIPAddress)); sessionDescription.setConnection(sdpFactory.createConnection("IN", "IP4", myIPAddress));


//Media Body

//Media Bod
if (anfrage == true) if (anfrage == true)
{ {
mediavec.add(sdpFactory.createMediaDescription("audio", 6022, 1, "RTP/AVP", cods)); //(Übertragungstyp, Port, anzahl der Ports, Verbindungstyp,..)
mediavec.add(sdpFactory.createMediaDescription("audio", 6022, 1, "RTP/AVP", codsRTP)); //(Übertragungstyp, Port, anzahl der Ports, Verbindungstyp,..)
mediavec.add(sdpFactory.createAttribute("sendrecv", null)); mediavec.add(sdpFactory.createAttribute("sendrecv", null));
for (int i = 0; i == 4; i++)
for (int i = 0; i < codsRTP.length; i++)
{ {
System.out.println("Codecs: " + codecs[i][0] + " " + codecs[i][1]);
mediavec.add(sdpFactory.createAttribute("rtpmap", codecs[i][0] + " " + codecs[i][1]));
mediavec.add(sdpFactory.createAttribute("rtpmap", codsRTP[i] + " " + codecs[i]));
} }
} }
else//Vergleich von eigenen Codecs mit Codecs der anruft -> Rückgabe entsprechend wählen else//Vergleich von eigenen Codecs mit Codecs der anruft -> Rückgabe entsprechend wählen
reqSDP.add(req.replace("a=rtpmap:", "")); reqSDP.add(req.replace("a=rtpmap:", ""));
} }
} }
boolean temp = true; //evtl noch was besseres da so erster Codec nicht bester verwendet wird
int position = 0; int position = 0;
for (String stcodec : cods)
ArrayList<String> tempList = new ArrayList<>();
for (String stcodec : codsRTP)
{ {
System.out.println("------Auswahl des codecs----");
if (reqSDP.contains(stcodec) && temp == true)
if (reqSDP.contains(stcodec))
{ {
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;
tempList.add(stcodec);
mediavec.add(sdpFactory.createAttribute("rtpmap", codsRTP[position] + " " + codecs[position]));
} }
position++; position++;
} }
String[] tempArray = tempList.toArray(new String[tempList.size()]);
mediavec.add(sdpFactory.createMediaDescription("audio", 6022, 1, "RTP/AVP", tempArray)); //(Übertragungstyp, Port, anzahl der Ports, Verbindungstyp,..)
mediavec.add(sdpFactory.createAttribute("sendrecv", null));
} }
sessionDescription.setAttributes(mediavec); sessionDescription.setAttributes(mediavec);
lgSessionDescription.info("SDP Header erstellt"); lgSessionDescription.info("SDP Header erstellt");

+ 2
- 2
src/model/SIPUnauthReq.java View File



public SIPUnauthReq(String myName, String proxyAddress, String myTag, public SIPUnauthReq(String myName, String proxyAddress, String myTag,
String myIPAddress, String myIPAddress,
int branch, long cseq, int myPort,
String branch, long cseq, int myPort,
ContactHeader contactHeader, ContactHeader contactHeader,
AddressFactory addressFactory, HeaderFactory headerFactory, AddressFactory addressFactory, HeaderFactory headerFactory,
ResponseEvent responseEvent, MessageFactory messageFactory) ResponseEvent responseEvent, MessageFactory messageFactory)
auth.setUsername(myName); auth.setUsername(myName);


ArrayList via = new ArrayList(); //Via needs a List as input ArrayList via = new ArrayList(); //Via needs a List as input
ViaHeader viaheader = headerFactory.createViaHeader(myIPAddress, myPort, "UDP", String.valueOf(branch + 2));// String.valueOf(hashCode())string branch
ViaHeader viaheader = headerFactory.createViaHeader(myIPAddress, myPort, "UDP", branch + 10);// String.valueOf(hashCode())string branch
via.add(viaheader); via.add(viaheader);


CSeqHeader cSeq = headerFactory.createCSeqHeader(cseq, "REGISTER"); CSeqHeader cSeq = headerFactory.createCSeqHeader(cseq, "REGISTER");

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

import gov.nist.javax.sip.SipListenerExt; import gov.nist.javax.sip.SipListenerExt;
import gui.Hauptfenster; import gui.Hauptfenster;
import java.net.InetAddress; import java.net.InetAddress;
import java.security.SecureRandom;
import java.text.ParseException; import java.text.ParseException;
import java.util.*; import java.util.*;
import java.util.logging.Level; import java.util.logging.Level;
*/ */
public class SIPmodel implements SipListenerExt public class SIPmodel implements SipListenerExt
{ {
private static final String TEST = "0123456789abcdefghijklmnopqrstuvwxyz";//für Random String
private static final SecureRandom RANDOM = new SecureRandom(); //für Random String

Hauptfenster view; //später entfernen wegen Zugriff Hauptfenster view; //später entfernen wegen Zugriff
public static final Logger lg = OhmLogger.getLogger(); public static final Logger lg = OhmLogger.getLogger();
public SipFactory sipFactory; // Used to access the SIP API. public SipFactory sipFactory; // Used to access the SIP API.
public String proxyAddress; public String proxyAddress;
public CallIdHeader callID; public CallIdHeader callID;


Boolean invite; //Bool für SDP falls ich anrufe

Boolean anrufer; //Hilfsvariable ob ich selbst anrufer bin
Boolean anrufAngenommen;
Boolean anrufCancel;
//Hilfsvariablen wenn ich angerufen werde. evtl. noch optimieren //Hilfsvariablen wenn ich angerufen werde. evtl. noch optimieren
RequestEvent evtWerdeAngerufen;
Boolean werdeAngerufen; Boolean werdeAngerufen;
private int countWerdeAngerufen;


private long cSequenz = 1;
private long cSequenz;
private String proxyTag; private String proxyTag;
private String myTag = String.valueOf(new Random().nextInt());
private int branch = Integer.valueOf(hashCode());
private String myTag;
private String branch;
private String line;
private Address contactAddress; private Address contactAddress;
private ContactHeader contactHeader; private ContactHeader contactHeader;


public SIPmodel(Hauptfenster view) //Konstruktor für eigene Daten public SIPmodel(Hauptfenster view) //Konstruktor für eigene Daten
{ {
this.view = view; this.view = view;
invite = true;
anrufer = false;
anrufAngenommen = false;
anrufCancel = false;
proxyAddress = ""; proxyAddress = "";

countWerdeAngerufen = 0;
evtWerdeAngerufen = null;
proxyTag = "";
line = "";
cSequenz = 1;
werdeAngerufen = false; werdeAngerufen = false;


myTag = createString(8); //erzeugt Random Tag mit Länge 8
branch = createString(18);//erzeugt Random branch mit Länge 18

try try
{ {
//wird an sich erstmal nicht gebraucht aber später sinnvoll um eigene Daten zu initialisieren //wird an sich erstmal nicht gebraucht aber später sinnvoll um eigene Daten zu initialisieren
String abc = InetAddress.getLocalHost().getHostAddress();
this.myIPAddress = InetAddress.getLocalHost().getHostAddress(); this.myIPAddress = InetAddress.getLocalHost().getHostAddress();
this.sipFactory = SipFactory.getInstance(); this.sipFactory = SipFactory.getInstance();
this.sipFactory.setPathName("gov.nist"); this.sipFactory.setPathName("gov.nist");
this.listeningPoint = this.sipStack.createListeningPoint(this.myIPAddress, this.myPort, this.protocolTyp); this.listeningPoint = this.sipStack.createListeningPoint(this.myIPAddress, this.myPort, this.protocolTyp);
this.sipProvider = this.sipStack.createSipProvider(this.listeningPoint); this.sipProvider = this.sipStack.createSipProvider(this.listeningPoint);
this.sipProvider.addSipListener(this); this.sipProvider.addSipListener(this);
this.contactAddress = this.addressFactory.createAddress("sip:" + myName + "@" + this.myIPAddress + ":" + this.myPort);
this.contactAddress = this.addressFactory.createAddress("sip:" + this.myName + "@" + this.myIPAddress + ":" + this.myPort);
this.contactHeader = this.headerFactory.createContactHeader(contactAddress); this.contactHeader = this.headerFactory.createContactHeader(contactAddress);
} }
catch (Exception e) catch (Exception e)
System.exit(-1); System.exit(-1);
} }
} }
public int hashCode()

private String createString(int anzahl)
{ {
int temp = Integer.valueOf(myTag)* (new Random(100)).nextInt();
return temp;
StringBuilder sb = new StringBuilder();
for (int i = 0; i < anzahl; i++)
{
sb.append(TEST.charAt(RANDOM.nextInt(TEST.length())));
}
return sb.toString();
} }

public void sendRegister(String serverIP, int serverPort) throws ParseException, InvalidArgumentException, SipException public void sendRegister(String serverIP, int serverPort) throws ParseException, InvalidArgumentException, SipException
{ {
proxyAddress = serverIP + ":" + serverPort; proxyAddress = serverIP + ":" + serverPort;
this.sipProvider.sendRequest(register.getRequest()); 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 SipException int serverPort) throws SipException
{ //ServerPort wird nicht verwendet? { //ServerPort wird nicht verwendet?
invite = true;
resetCallParameter();
anrufer = true;
callID = this.sipProvider.getNewCallId(); callID = this.sipProvider.getNewCallId();
SIPSessionDescription sdp = new SIPSessionDescription(myName, myIPAddress, evtWerdeAngerufen, true);
SIPSessionDescription sdp = new SIPSessionDescription(myName, myIPAddress, null, anrufer);
SIPInvite sipinvite = new SIPInvite(sipaddresse, proxyaddresse, myIPAddress, myPort, myTag, branch, callID, cSequenz, addressFactory, sdp.getSessionDescription(), headerFactory, messageFactory, contactHeader); SIPInvite sipinvite = new SIPInvite(sipaddresse, proxyaddresse, myIPAddress, myPort, myTag, branch, callID, cSequenz, addressFactory, sdp.getSessionDescription(), headerFactory, messageFactory, contactHeader);
this.sipProvider.sendRequest(sipinvite.getInviterequest()); this.sipProvider.sendRequest(sipinvite.getInviterequest());
lg.info("Erfolgreiches Senden der Invitation"); lg.info("Erfolgreiches Senden der Invitation");
//Aktive Kommunikation //Aktive Kommunikation
else if ((Request.INVITE).equals(requestEvent.getRequest().getMethod())) // Invite von anderem Benutzer else if ((Request.INVITE).equals(requestEvent.getRequest().getMethod())) // Invite von anderem Benutzer
{ {
resetCallParameter();
anrufer = false;
//Falls Anruf ankommt, wichtige Variablen Zwischenspeichern (Branch, Cseq, CallID, proxyTag)
branch = ((ViaHeader) requestEvent.getRequest().getHeader("Via")).getBranch();
cSequenz = ((CSeqHeader) requestEvent.getRequest().getHeader("Cseq")).getSeqNumber();
proxyTag = ((FromHeader) requestEvent.getRequest().getHeader("From")).getTag();
callID = ((CallIdHeader) requestEvent.getRequest().getHeader("CallID"));
//Standartabfolge sobald man angerufen wird
try try
{ {
this.sipProvider.sendResponse(create180Ringing(requestEvent));
view.getTxtArea().append("Ringing geschickt\n");
}
catch (Exception ex)//Exceptions evtl. genauer definieren
{
lg.getLogger(SIPmodel.class.getName()).log(Level.SEVERE, null, ex);
}
countWerdeAngerufen++; //bessere Lösung muss her!!, was schickt andere User oder Proxy bei nicht erreichen
FromHeader abc = (FromHeader) requestEvent.getRequest().getHeader("From");
//Trying Response erzeugen und abschicken
SIP100Trying tempTrying = new SIP100Trying(messageFactory, requestEvent, headerFactory);
sipProvider.sendResponse(tempTrying.getTryResponse());
view.getTxtArea().append("Trying geschickt\n");
lg.info("Trying ist raus");


evtWerdeAngerufen = requestEvent;
System.out.println(countWerdeAngerufen);
if (countWerdeAngerufen < 7)
{
werdeAngerufen = true;
lg.info("Hab Invitation bekommen");
view.getTxtArea().append("Werde von " + abc.getAddress() + " angerufen\n");
//Ringing Response erzeugen und abschicken noch Schleife mit "Anruf annehmen"
SIP180Ringing tempRinging = new SIP180Ringing(requestEvent, myTag, contactHeader, headerFactory, messageFactory);
Timer timer = new Timer();
timer.scheduleAtFixedRate(new TimerTask()
{
@Override
public void run()
{
try
{
if (anrufAngenommen != true)
{
sipProvider.sendResponse(tempRinging.getResponseRing());
}
else if(anrufAngenommen==true)
{
SIP200Ok respcall = new SIP200Ok(messageFactory, requestEvent, contactHeader, headerFactory);
SIPSessionDescription sdp = new SIPSessionDescription(myName, myIPAddress, requestEvent, anrufer);
respcall.addSDP(sdp.getSessionDescription(), myTag);
sipProvider.sendResponse(respcall.getResponse());
view.getTxtArea().append("Telefonat beginnt\n");
timer.cancel();
}
}
catch (SipException ex)
{

}
}
}, 0, 1000);
} }
else
catch (SipException ex)
{ {
werdeAngerufen = false;
lg.info("Leider waren Sie nicht erreichbar");
view.getTxtArea().append("Sie waren nicht erreichbar\n");
countWerdeAngerufen = 0;
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;
evtWerdeAngerufen = null; // sicher ist sicher
anrufCancel = true;
SIP200Ok tempOk = new SIP200Ok(messageFactory, requestEvent, contactHeader, headerFactory); SIP200Ok tempOk = new SIP200Ok(messageFactory, requestEvent, contactHeader, headerFactory);
this.sipProvider.sendResponse(tempOk.getResponse()); this.sipProvider.sendResponse(tempOk.getResponse());
view.getTxtArea().append("Anrufender canceld Anfrage\n"); view.getTxtArea().append("Anrufender canceld Anfrage\n");
SIP200Ok tempOk = new SIP200Ok(messageFactory, requestEvent, contactHeader, headerFactory); SIP200Ok tempOk = new SIP200Ok(messageFactory, requestEvent, contactHeader, headerFactory);
this.sipProvider.sendResponse(tempOk.getResponse()); this.sipProvider.sendResponse(tempOk.getResponse());
} }
catch (Exception ex)
catch (SipException ex)
{ {
Logger.getLogger(SIPmodel.class.getName()).log(Level.SEVERE, null, ex);
} }
} }
} }
{ {
lg.getLogger(SIPmodel.class.getName()).log(Level.SEVERE, null, ex); lg.getLogger(SIPmodel.class.getName()).log(Level.SEVERE, null, ex);
} }

} }
else if (responseEvent.getResponse().getStatusCode() == Response.OK) else if (responseEvent.getResponse().getStatusCode() == Response.OK)
{ {
{ {
ToHeader temp = (ToHeader) responseEvent.getResponse().getHeader("To"); ToHeader temp = (ToHeader) responseEvent.getResponse().getHeader("To");
proxyTag = temp.getTag(); proxyTag = temp.getTag();

}

}


public Response create180Ringing(RequestEvent requestEvent) throws ParseException, SipException
{
Response responsering = this.messageFactory.createResponse(180, requestEvent.getRequest());
responsering.addHeader((ViaHeader) requestEvent.getRequest().getHeader("Via"));
responsering.addHeader((FromHeader) requestEvent.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) requestEvent.getRequest().getHeader("To");
proxyTag = temptoring.getTag();
temptoring.setTag(this.myTag);
responsering.addHeader(temptoring);
cSequenz = ((CSeqHeader) requestEvent.getRequest().getHeader("Cseq")).getSeqNumber();
responsering.addHeader((CSeqHeader) requestEvent.getRequest().getHeader("Cseq"));
responsering.addHeader(contactHeader);
responsering.addHeader(allow);
AllowEventsHeader allowevent = this.headerFactory.createAllowEventsHeader("talk,hold,refer,call-info");// für was gebraucht
responsering.addHeader(allowevent);
return responsering;
}
public void annehmen() //Fehlende Bedingung
{
RequestEvent requestEvent;
if ((requestEvent = evtWerdeAngerufen) != null && werdeAngerufen == true)
{
countWerdeAngerufen = 0;
try
{
//Werte für weitere Kommunikation abspeichern
callID = (CallIdHeader) requestEvent.getRequest().getHeader("Call-ID");
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 Header erzeugen und abschicken 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");

//200OK Header mit Session Description erstellen
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 (SipException ex)
{
Logger.getLogger(SIPmodel.class.getName()).log(Level.SEVERE, null, ex);
}
}
else
{
view.getTxtArea().append("Zur Zeit gibt es keinen Anruf\n");
} }


} }


public void byecall(String calluser) throws ParseException, InvalidArgumentException, SipException public void byecall(String calluser) throws ParseException, InvalidArgumentException, SipException
{ {
invite = false;
Address addressLine = this.addressFactory.createAddress("sip:" + calluser + "@" + proxyAddress); Address addressLine = this.addressFactory.createAddress("sip:" + calluser + "@" + proxyAddress);
URI requestURI = addressLine.getURI(); URI requestURI = addressLine.getURI();


request.addHeader(allow); request.addHeader(allow);
request.addHeader(expire); request.addHeader(expire);
this.sipProvider.sendRequest(request); this.sipProvider.sendRequest(request);
invite = false;

lg.info("Erfolgreiches Senden des BYE Headers"); lg.info("Erfolgreiches Senden des BYE Headers");
} }


public void resetCallParameter()
{
anrufAngenommen = false;
anrufer = false;
}

public void anrufAnnehmen()
{
anrufAngenommen = true;
}

//Get Methoden falls man mal die Parameter braucht //Get Methoden falls man mal die Parameter braucht
public String getmyName() public String getmyName()
{ {
/** /**
* @return the branch * @return the branch
*/ */
public int getBranch()
public String getBranch()
{ {
return branch; return branch;
} }

Loading…
Cancel
Save