@@ -5,8 +5,6 @@ | |||
*/ | |||
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; | |||
@@ -26,40 +24,30 @@ import logger.OhmLogger; | |||
* | |||
* @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 MessageFactory messageFactory; | |||
private HeaderFactory headerFactory; | |||
private String myTag; | |||
private String proxyTag; | |||
public static final Logger lgRing = OhmLogger.getLogger(); | |||
//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 | |||
{ | |||
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 | |||
ToHeader tempTo = ((ToHeader) this.requestEvent.getRequest().getHeader("To")); | |||
ToHeader tempTo = ((ToHeader) 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((CSeqHeader) 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 | |||
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"); | |||
} | |||
catch (Exception ex) | |||
@@ -67,24 +55,6 @@ public class SIP180Ringing implements Runnable | |||
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 | |||
*/ |
@@ -34,16 +34,18 @@ public class SIP200Ok | |||
private static final Logger lg200Ok = OhmLogger.getLogger(); | |||
private RequestEvent requestEvent; | |||
private HeaderFactory headerFactory; | |||
private ContactHeader contactHeader; | |||
public SIP200Ok(MessageFactory messageFactory, RequestEvent requestEvent, | |||
ContactHeader contactHeader, HeaderFactory headerFactory) | |||
{ | |||
this.requestEvent = requestEvent; | |||
this.headerFactory = headerFactory; | |||
this.contactHeader = contactHeader; | |||
try | |||
{ | |||
response = messageFactory.createResponse(Response.OK, this.requestEvent.getRequest()); | |||
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((ToHeader) this.requestEvent.getRequest().getHeader("To")); | |||
response.addHeader((CallIdHeader) this.requestEvent.getRequest().getHeader("Call-ID")); | |||
@@ -65,14 +67,13 @@ 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 | |||
temptoring.setTag(myTag); | |||
response.addHeader(temptoring); | |||
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); |
@@ -38,18 +38,21 @@ public class SIPInvite | |||
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) | |||
String myTag, String 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 | |||
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)); | |||
ViaHeader viaheader = headerFactory.createViaHeader(myIPAddress, myPort, "UDP", branch); | |||
via.add(viaheader); | |||
CSeqHeader cSeq = headerFactory.createCSeqHeader(cSequenz, "INVITE"); | |||
MaxForwardsHeader maxForwards = headerFactory.createMaxForwardsHeader(70); |
@@ -35,7 +35,7 @@ public class SIPRegister | |||
private static final Logger lgRegister = OhmLogger.getLogger(); | |||
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) | |||
{ | |||
try | |||
@@ -45,7 +45,7 @@ public class SIPRegister | |||
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)); | |||
ViaHeader viaheader = headerFactory.createViaHeader(myIPAddress, myPort, "UDP", branch); | |||
via.add(viaheader); | |||
CSeqHeader cSeq = headerFactory.createCSeqHeader(1L, "REGISTER"); | |||
MaxForwardsHeader maxForwards = headerFactory.createMaxForwardsHeader(70); |
@@ -23,29 +23,26 @@ public class SIPSessionDescription | |||
private SdpFactory sdpFactory; | |||
private SessionDescription sessionDescription; | |||
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(); | |||
public SIPSessionDescription(String myName, String myIPAddress, | |||
RequestEvent requestEvent, Boolean anfrage) | |||
{ | |||
//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(); | |||
try | |||
{ | |||
@@ -55,16 +52,14 @@ public class SIPSessionDescription | |||
sessionDescription.setSessionName(sdpFactory.createSessionName("SIP Call")); | |||
sessionDescription.setConnection(sdpFactory.createConnection("IN", "IP4", myIPAddress)); | |||
//Media Body | |||
//Media Bod | |||
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)); | |||
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 | |||
@@ -78,23 +73,21 @@ public class SIPSessionDescription | |||
reqSDP.add(req.replace("a=rtpmap:", "")); | |||
} | |||
} | |||
boolean temp = true; //evtl noch was besseres da so erster Codec nicht bester verwendet wird | |||
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++; | |||
} | |||
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); | |||
lgSessionDescription.info("SDP Header erstellt"); |
@@ -41,7 +41,7 @@ public class SIPUnauthReq | |||
public SIPUnauthReq(String myName, String proxyAddress, String myTag, | |||
String myIPAddress, | |||
int branch, long cseq, int myPort, | |||
String branch, long cseq, int myPort, | |||
ContactHeader contactHeader, | |||
AddressFactory addressFactory, HeaderFactory headerFactory, | |||
ResponseEvent responseEvent, MessageFactory messageFactory) | |||
@@ -67,7 +67,7 @@ public class SIPUnauthReq | |||
auth.setUsername(myName); | |||
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); | |||
CSeqHeader cSeq = headerFactory.createCSeqHeader(cseq, "REGISTER"); |
@@ -9,6 +9,7 @@ import gov.nist.javax.sip.DialogTimeoutEvent; | |||
import gov.nist.javax.sip.SipListenerExt; | |||
import gui.Hauptfenster; | |||
import java.net.InetAddress; | |||
import java.security.SecureRandom; | |||
import java.text.ParseException; | |||
import java.util.*; | |||
import java.util.logging.Level; | |||
@@ -38,6 +39,9 @@ import logger.OhmLogger; | |||
*/ | |||
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 | |||
public static final Logger lg = OhmLogger.getLogger(); | |||
public SipFactory sipFactory; // Used to access the SIP API. | |||
@@ -56,34 +60,38 @@ public class SIPmodel implements SipListenerExt | |||
public String proxyAddress; | |||
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 | |||
RequestEvent evtWerdeAngerufen; | |||
Boolean werdeAngerufen; | |||
private int countWerdeAngerufen; | |||
private long cSequenz = 1; | |||
private long cSequenz; | |||
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 ContactHeader contactHeader; | |||
public SIPmodel(Hauptfenster view) //Konstruktor für eigene Daten | |||
{ | |||
this.view = view; | |||
invite = true; | |||
anrufer = false; | |||
anrufAngenommen = false; | |||
anrufCancel = false; | |||
proxyAddress = ""; | |||
countWerdeAngerufen = 0; | |||
evtWerdeAngerufen = null; | |||
proxyTag = ""; | |||
line = ""; | |||
cSequenz = 1; | |||
werdeAngerufen = false; | |||
myTag = createString(8); //erzeugt Random Tag mit Länge 8 | |||
branch = createString(18);//erzeugt Random branch mit Länge 18 | |||
try | |||
{ | |||
//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.sipFactory = SipFactory.getInstance(); | |||
this.sipFactory.setPathName("gov.nist"); | |||
@@ -96,7 +104,7 @@ public class SIPmodel implements SipListenerExt | |||
this.listeningPoint = this.sipStack.createListeningPoint(this.myIPAddress, this.myPort, this.protocolTyp); | |||
this.sipProvider = this.sipStack.createSipProvider(this.listeningPoint); | |||
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); | |||
} | |||
catch (Exception e) | |||
@@ -105,11 +113,17 @@ public class SIPmodel implements SipListenerExt | |||
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 | |||
{ | |||
proxyAddress = serverIP + ":" + serverPort; | |||
@@ -117,12 +131,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 SipException | |||
{ //ServerPort wird nicht verwendet? | |||
invite = true; | |||
resetCallParameter(); | |||
anrufer = true; | |||
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); | |||
this.sipProvider.sendRequest(sipinvite.getInviterequest()); | |||
lg.info("Erfolgreiches Senden der Invitation"); | |||
@@ -150,32 +166,56 @@ public class SIPmodel implements SipListenerExt | |||
//Aktive Kommunikation | |||
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 | |||
{ | |||
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); | |||
} | |||
} | |||
@@ -190,8 +230,7 @@ public class SIPmodel implements SipListenerExt | |||
{ | |||
//Cancel Request -> Response 200 Ok + Response 487 Request Terminated | |||
//200 Ok | |||
werdeAngerufen = false; | |||
evtWerdeAngerufen = null; // sicher ist sicher | |||
anrufCancel = true; | |||
SIP200Ok tempOk = new SIP200Ok(messageFactory, requestEvent, contactHeader, headerFactory); | |||
this.sipProvider.sendResponse(tempOk.getResponse()); | |||
view.getTxtArea().append("Anrufender canceld Anfrage\n"); | |||
@@ -210,9 +249,9 @@ public class SIPmodel implements SipListenerExt | |||
SIP200Ok tempOk = new SIP200Ok(messageFactory, requestEvent, contactHeader, headerFactory); | |||
this.sipProvider.sendResponse(tempOk.getResponse()); | |||
} | |||
catch (Exception ex) | |||
catch (SipException ex) | |||
{ | |||
Logger.getLogger(SIPmodel.class.getName()).log(Level.SEVERE, null, ex); | |||
} | |||
} | |||
} | |||
@@ -234,7 +273,6 @@ public class SIPmodel implements SipListenerExt | |||
{ | |||
lg.getLogger(SIPmodel.class.getName()).log(Level.SEVERE, null, ex); | |||
} | |||
} | |||
else if (responseEvent.getResponse().getStatusCode() == Response.OK) | |||
{ | |||
@@ -244,82 +282,12 @@ public class SIPmodel implements SipListenerExt | |||
{ | |||
ToHeader temp = (ToHeader) responseEvent.getResponse().getHeader("To"); | |||
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 | |||
{ | |||
invite = false; | |||
Address addressLine = this.addressFactory.createAddress("sip:" + calluser + "@" + proxyAddress); | |||
URI requestURI = addressLine.getURI(); | |||
@@ -343,11 +311,20 @@ public class SIPmodel implements SipListenerExt | |||
request.addHeader(allow); | |||
request.addHeader(expire); | |||
this.sipProvider.sendRequest(request); | |||
invite = false; | |||
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 | |||
public String getmyName() | |||
{ | |||
@@ -448,7 +425,7 @@ public class SIPmodel implements SipListenerExt | |||
/** | |||
* @return the branch | |||
*/ | |||
public int getBranch() | |||
public String getBranch() | |||
{ | |||
return branch; | |||
} |