|
|
@@ -35,8 +35,9 @@ import logger.OhmLogger; |
|
|
|
|
|
|
|
/** |
|
|
|
* |
|
|
|
* @author Jan |
|
|
|
komplettes Model für SIPmodel |
|
|
|
* @author Jan komplettes Model für SIPmodel evtl. Vererbung und für jeden SIP |
|
|
|
* Response/Request eigene Klasse oder Interface da es langsam unübersichtlich |
|
|
|
* wird :( ACK schicken muss noch ergänzt werden BYE muss noch ergänzt werden. |
|
|
|
*/ |
|
|
|
public class SIPmodel implements SipListenerExt |
|
|
|
{ |
|
|
@@ -52,21 +53,20 @@ public class SIPmodel implements SipListenerExt |
|
|
|
Properties properties; // Other properties. |
|
|
|
|
|
|
|
private int counter = 10; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private int myPort = 5060; |
|
|
|
private String myName = "129"; |
|
|
|
private String protocolTyp = "UDP"; |
|
|
|
private String myIPAddress; |
|
|
|
private String proxyAddress; |
|
|
|
|
|
|
|
|
|
|
|
Boolean invite; //Bool für SDP falls ich anrufe |
|
|
|
|
|
|
|
|
|
|
|
//Hilfsvariablen wenn ich angerufen werde. evtl. noch optimieren |
|
|
|
RequestEvent evtWerdeAngerufen; |
|
|
|
Boolean werdeAngerufen; |
|
|
|
private int countWerdeAngerufen; |
|
|
|
|
|
|
|
|
|
|
|
int tag = (new Random()).nextInt(); |
|
|
|
private int branch = hashCode(); |
|
|
|
Address contactAddress; |
|
|
@@ -77,16 +77,16 @@ public class SIPmodel implements SipListenerExt |
|
|
|
this.view = view; |
|
|
|
invite = true; |
|
|
|
proxyAddress = ""; |
|
|
|
|
|
|
|
|
|
|
|
countWerdeAngerufen = 0; |
|
|
|
evtWerdeAngerufen = null; |
|
|
|
werdeAngerufen =false; |
|
|
|
|
|
|
|
werdeAngerufen = false; |
|
|
|
|
|
|
|
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(); |
|
|
@@ -101,7 +101,7 @@ public class SIPmodel implements SipListenerExt |
|
|
|
this.sipProvider = this.sipStack.createSipProvider(this.listeningPoint); |
|
|
|
this.sipProvider.addSipListener(this); |
|
|
|
//this.contactAddress = this.addressFactory.createAddress("sip:129@" + this.myIPAddress + ":" + this.myPort); //+ ":" + this.myPort |
|
|
|
this.contactAddress = this.addressFactory.createAddress("sip:" + myName+ "@" + this.myIPAddress + ":" + this.myPort); |
|
|
|
this.contactAddress = this.addressFactory.createAddress("sip:" + myName + "@" + this.myIPAddress + ":" + this.myPort); |
|
|
|
this.contactHeader = this.headerFactory.createContactHeader(contactAddress); |
|
|
|
|
|
|
|
} |
|
|
@@ -147,8 +147,7 @@ public class SIPmodel implements SipListenerExt |
|
|
|
int serverPort) throws ParseException, InvalidArgumentException, SipException, SdpException |
|
|
|
{ |
|
|
|
invite = true; |
|
|
|
Address addressto = this.addressFactory.createAddress("sip:" + sipaddresse + "@" + proxyaddresse); |
|
|
|
//Address addressto = this.addressFactory.createAddress("sip:121@192.168.100.11"); |
|
|
|
Address addressto = this.addressFactory.createAddress("sip:" + sipaddresse + "@" + proxyaddresse); |
|
|
|
ToHeader to = this.headerFactory.createToHeader(addressto, null); // Integer.toString(tag) address + tag |
|
|
|
URI requestURI = addressto.getURI(); |
|
|
|
CallIdHeader callId = this.sipProvider.getNewCallId(); |
|
|
@@ -170,25 +169,23 @@ public class SIPmodel implements SipListenerExt |
|
|
|
|
|
|
|
request.setContent(createSDPHeader(), content); |
|
|
|
this.sipProvider.sendRequest(request); |
|
|
|
|
|
|
|
lg.info("Erfolgreiches Senden der Invitation"); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void processDialogTimeout(DialogTimeoutEvent timeoutEvent) |
|
|
|
{ |
|
|
|
lg.info("Erfolgreiches Senden der Invitation"); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void processRequest(RequestEvent requestEvent) |
|
|
|
{ |
|
|
|
lg.info("Bekomme Anfrage"); |
|
|
|
//Kommunikation mit Server das man zur Verfügung steht |
|
|
|
if ((Request.OPTIONS).equals(requestEvent.getRequest().getMethod())) //Options Anfrage von Server nach erfolgreicher Registrierung |
|
|
|
{ |
|
|
|
lg.info("Option Request von Server, erstellen 200 OK zu Server"); |
|
|
|
try |
|
|
|
{ |
|
|
|
this.sipProvider.sendResponse(create200Ok(requestEvent)); |
|
|
|
view.getTxtArea().append("Server Option Request erfolgreich beantwortet\n"); |
|
|
|
lg.info("Erfolgreiches senden des Headers"); |
|
|
|
/* |
|
|
|
Response response = this.messageFactory.createResponse(200, requestEvent.getRequest()); |
|
|
|
response.addHeader((ViaHeader) requestEvent.getRequest().getHeader("Via")); |
|
|
|
response.addHeader((FromHeader) requestEvent.getRequest().getHeader("From")); |
|
|
@@ -206,6 +203,7 @@ public class SIPmodel implements SipListenerExt |
|
|
|
this.sipProvider.sendResponse(response); |
|
|
|
view.getTxtArea().append("Server Option Request erfolgreich beantwortet\n"); |
|
|
|
lg.info("Erfolgreiches senden des Headers"); |
|
|
|
*/ |
|
|
|
} |
|
|
|
catch (ParseException | SipException ex) |
|
|
|
{ |
|
|
@@ -215,11 +213,11 @@ public class SIPmodel implements SipListenerExt |
|
|
|
//Aktive Kommunikation |
|
|
|
else if ((Request.INVITE).equals(requestEvent.getRequest().getMethod())) // Invite von anderem Benutzer |
|
|
|
{ |
|
|
|
countWerdeAngerufen++; |
|
|
|
countWerdeAngerufen++; //bessere Lösung muss her!!, was schickt andere User oder Proxy bei nicht erreichen |
|
|
|
FromHeader abc = (FromHeader) requestEvent.getRequest().getHeader("From"); |
|
|
|
evtWerdeAngerufen = requestEvent; |
|
|
|
System.out.println(countWerdeAngerufen); |
|
|
|
if(countWerdeAngerufen<7) |
|
|
|
if (countWerdeAngerufen < 7) |
|
|
|
{ |
|
|
|
werdeAngerufen = true; |
|
|
|
lg.info("Hab Invitation bekommen"); |
|
|
@@ -232,13 +230,36 @@ public class SIPmodel implements SipListenerExt |
|
|
|
view.getTxtArea().append("Sie waren nicht erreichbar\n"); |
|
|
|
countWerdeAngerufen = 0; |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
else if ((Request.ACK).equals(requestEvent.getRequest().getMethod())) |
|
|
|
{ |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else if ((Request.CANCEL).equals(requestEvent.getRequest().getMethod())) |
|
|
|
{ |
|
|
|
try |
|
|
|
{ |
|
|
|
//Cancel Request -> Response 200 Ok + Response 487 Request Terminated |
|
|
|
//200 Ok |
|
|
|
werdeAngerufen = false; |
|
|
|
evtWerdeAngerufen = null; // sicher ist sicher |
|
|
|
this.sipProvider.sendResponse(create200Ok(requestEvent)); |
|
|
|
view.getTxtArea().append("Anrufender canceld Anfrage\n"); |
|
|
|
lg.info("Erfolgreiches senden des 200 OkHeaders auf CancelAnfrage"); |
|
|
|
//487 Request Terminated |
|
|
|
|
|
|
|
} |
|
|
|
catch (ParseException | SipException ex) |
|
|
|
{ |
|
|
|
Logger.getLogger(SIPmodel.class.getName()).log(Level.SEVERE, null, ex); |
|
|
|
} |
|
|
|
} |
|
|
|
else if ((Request.BYE).equals(requestEvent.getRequest().getMethod())) |
|
|
|
{ |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
@@ -252,23 +273,25 @@ public class SIPmodel implements SipListenerExt |
|
|
|
|
|
|
|
try |
|
|
|
{ |
|
|
|
Address addresstob = this.addressFactory.createAddress("sip:129@192.168.100.11"); //"sip:Jan@192.168.100.11" |
|
|
|
//Address addresstob = this.addressFactory.createAddress("sip:129@192.168.100.11"); //"sip:Jan@192.168.100.11" |
|
|
|
Address addresstob = this.addressFactory.createAddress("sip:" + myName + "@" + proxyAddress); |
|
|
|
ToHeader temp = (ToHeader) responseEvent.getResponse().getHeader("To"); |
|
|
|
|
|
|
|
ToHeader to = this.headerFactory.createToHeader(addresstob, temp.getTag()); // Integer.toString(tag) address + tag |
|
|
|
URI requestURI = addresstob.getURI(); |
|
|
|
|
|
|
|
//CallIdHeader tempcall = (CallIdHeader)responseEvent.getResponse().getHeader("Call-ID"); |
|
|
|
CallIdHeader callId = (CallIdHeader) responseEvent.getResponse().getHeader("Call-ID"); |
|
|
|
FromHeader from = this.headerFactory.createFromHeader(addresstob, String.valueOf(this.tag)); //this.contactAddress |
|
|
|
|
|
|
|
//set Authorization header evtl. user Name benutzen den es gibt |
|
|
|
WWWAuthenticateHeader abc = (WWWAuthenticateHeader) responseEvent.getResponse().getHeader("WWW-Authenticate"); |
|
|
|
AuthorizationHeader auth = this.headerFactory.createAuthorizationHeader("Digest");//was kommt in den string |
|
|
|
//wird WWWAuthenticateHeader überhaupt benötigt??? |
|
|
|
WWWAuthenticateHeader wwwauth = (WWWAuthenticateHeader) responseEvent.getResponse().getHeader("WWW-Authenticate"); |
|
|
|
|
|
|
|
auth.setRealm(abc.getRealm()); |
|
|
|
auth.setNonce(abc.getNonce()); |
|
|
|
Address addresstest = this.addressFactory.createAddress("sip:" + myName + "@192.168.100.11"); //vielleicht passwort setzen "sip:"+myName+":\"\"@192.168.100.11" |
|
|
|
//wird bei AuthorizationHeader wirklich alles benötigt? war glaub nur mal Test -> testen!! |
|
|
|
AuthorizationHeader auth = this.headerFactory.createAuthorizationHeader("Digest");//was kommt in den string |
|
|
|
auth.setRealm(wwwauth.getRealm()); |
|
|
|
auth.setNonce(wwwauth.getNonce()); |
|
|
|
//Address addresstest = this.addressFactory.createAddress("sip:" + myName + "@192.168.100.11"); //vielleicht passwort setzen "sip:"+myName+":\"\"@192.168.100.11" |
|
|
|
Address addresstest = this.addressFactory.createAddress("sip:" + myName + "@" + proxyAddress); |
|
|
|
auth.setURI(addresstest.getURI()); |
|
|
|
auth.setUsername(myName); |
|
|
|
|
|
|
@@ -304,6 +327,23 @@ public class SIPmodel implements SipListenerExt |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
public Response create200Ok(RequestEvent requestEvent) throws ParseException |
|
|
|
{ |
|
|
|
Response response = this.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 = 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) requestEvent.getRequest().getHeader("Call-ID")); |
|
|
|
response.addHeader(allow); |
|
|
|
response.addHeader(allowevents); |
|
|
|
return response; |
|
|
|
} |
|
|
|
|
|
|
|
public SessionDescription createSDPHeader() throws SdpException |
|
|
|
{ |
|
|
|
/* |
|
|
@@ -335,7 +375,7 @@ public class SIPmodel implements SipListenerExt |
|
|
|
mediavec.add(sdpFactory.createAttribute("rtpmap", "18 G729/8000")); |
|
|
|
mediavec.add(sdpFactory.createAttribute("ptime", "20")); |
|
|
|
} |
|
|
|
else//Vergleich von eigenen Codecs mit Codecs der anruft und Rückgabe entsprechend wählen |
|
|
|
else//Vergleich von eigenen Codecs mit Codecs der anruft -> Rückgabe entsprechend wählen |
|
|
|
{ |
|
|
|
|
|
|
|
} |
|
|
@@ -347,9 +387,9 @@ public class SIPmodel implements SipListenerExt |
|
|
|
public void annehmen() //Fehlende Bedingung |
|
|
|
{ |
|
|
|
RequestEvent requestEvent; |
|
|
|
if ((requestEvent=evtWerdeAngerufen) != null && werdeAngerufen==true) |
|
|
|
if ((requestEvent = evtWerdeAngerufen) != null && werdeAngerufen == true) |
|
|
|
{ |
|
|
|
countWerdeAngerufen =0; |
|
|
|
countWerdeAngerufen = 0; |
|
|
|
|
|
|
|
try |
|
|
|
{ |
|
|
@@ -409,9 +449,9 @@ public class SIPmodel implements SipListenerExt |
|
|
|
okandSDP.addHeader(content); |
|
|
|
okandSDP.setContent(createSDPHeader(), content); |
|
|
|
this.sipProvider.sendResponse(okandSDP); |
|
|
|
|
|
|
|
|
|
|
|
view.getTxtArea().append("Telefonat beginnt\n"); |
|
|
|
evtWerdeAngerufen =null; |
|
|
|
evtWerdeAngerufen = null; |
|
|
|
} |
|
|
|
catch (ParseException | SipException | SdpException ex) |
|
|
|
{ |
|
|
@@ -420,16 +460,18 @@ public class SIPmodel implements SipListenerExt |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
view.getTxtArea().append("Zur Zeit gibt es keinen Anruf\n"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
//Get Methoden falls man mal die Parameter braucht |
|
|
|
public void cancelcall() |
|
|
|
{ |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
//Get Methoden falls man mal die Parameter braucht |
|
|
|
public String getmyName() |
|
|
|
{ |
|
|
|
return myName; |
|
|
@@ -445,6 +487,7 @@ public class SIPmodel implements SipListenerExt |
|
|
|
return myIPAddress; |
|
|
|
} |
|
|
|
|
|
|
|
// Herausfinden bei welchen Events die unteren Funktionen aufgerufen werden -> evtl brauchbar |
|
|
|
@Override |
|
|
|
public void processTimeout(TimeoutEvent timeoutEvent) |
|
|
|
{ |
|
|
@@ -461,7 +504,7 @@ public class SIPmodel implements SipListenerExt |
|
|
|
public void processTransactionTerminated( |
|
|
|
TransactionTerminatedEvent transactionTerminatedEvent) |
|
|
|
{ |
|
|
|
//view.getTxtArea().append("processTransactionTerminated\n"); |
|
|
|
//view.getTxtArea().append("processTransactionTerminated\n"); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
@@ -470,4 +513,10 @@ public class SIPmodel implements SipListenerExt |
|
|
|
{ |
|
|
|
//view.getTxtArea().append("processDialogTerminated\n"); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void processDialogTimeout(DialogTimeoutEvent timeoutEvent) |
|
|
|
{ |
|
|
|
//view.getTxtArea().append("processDialogTerminated\n"); |
|
|
|
} |
|
|
|
} |