|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* |
|
|
* |
|
|
* @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 |
|
|
public class SIPmodel implements SipListenerExt |
|
|
{ |
|
|
{ |
|
|
|
|
|
|
|
|
Properties properties; // Other properties. |
|
|
Properties properties; // Other properties. |
|
|
|
|
|
|
|
|
private int counter = 10; |
|
|
private int counter = 10; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private int myPort = 5060; |
|
|
private int myPort = 5060; |
|
|
private String myName = "129"; |
|
|
private String myName = "129"; |
|
|
private String protocolTyp = "UDP"; |
|
|
private String protocolTyp = "UDP"; |
|
|
private String myIPAddress; |
|
|
private String myIPAddress; |
|
|
private String proxyAddress; |
|
|
private String proxyAddress; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Boolean invite; //Bool für SDP falls ich anrufe |
|
|
Boolean invite; //Bool für SDP falls ich anrufe |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Hilfsvariablen wenn ich angerufen werde. evtl. noch optimieren |
|
|
//Hilfsvariablen wenn ich angerufen werde. evtl. noch optimieren |
|
|
RequestEvent evtWerdeAngerufen; |
|
|
RequestEvent evtWerdeAngerufen; |
|
|
Boolean werdeAngerufen; |
|
|
Boolean werdeAngerufen; |
|
|
private int countWerdeAngerufen; |
|
|
private int countWerdeAngerufen; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int tag = (new Random()).nextInt(); |
|
|
int tag = (new Random()).nextInt(); |
|
|
private int branch = hashCode(); |
|
|
private int branch = hashCode(); |
|
|
Address contactAddress; |
|
|
Address contactAddress; |
|
|
|
|
|
|
|
|
this.view = view; |
|
|
this.view = view; |
|
|
invite = true; |
|
|
invite = true; |
|
|
proxyAddress = ""; |
|
|
proxyAddress = ""; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
countWerdeAngerufen = 0; |
|
|
countWerdeAngerufen = 0; |
|
|
evtWerdeAngerufen = null; |
|
|
evtWerdeAngerufen = null; |
|
|
werdeAngerufen =false; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
werdeAngerufen = false; |
|
|
|
|
|
|
|
|
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(); |
|
|
String abc = InetAddress.getLocalHost().getHostAddress(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.myIPAddress = InetAddress.getLocalHost().getHostAddress(); |
|
|
this.myIPAddress = InetAddress.getLocalHost().getHostAddress(); |
|
|
|
|
|
|
|
|
this.sipFactory = SipFactory.getInstance(); |
|
|
this.sipFactory = SipFactory.getInstance(); |
|
|
|
|
|
|
|
|
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:129@" + this.myIPAddress + ":" + this.myPort); //+ ":" + this.myPort |
|
|
//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); |
|
|
this.contactHeader = this.headerFactory.createContactHeader(contactAddress); |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
int serverPort) throws ParseException, InvalidArgumentException, SipException, SdpException |
|
|
int serverPort) throws ParseException, InvalidArgumentException, SipException, SdpException |
|
|
{ |
|
|
{ |
|
|
invite = true; |
|
|
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 |
|
|
ToHeader to = this.headerFactory.createToHeader(addressto, null); // Integer.toString(tag) address + tag |
|
|
URI requestURI = addressto.getURI(); |
|
|
URI requestURI = addressto.getURI(); |
|
|
CallIdHeader callId = this.sipProvider.getNewCallId(); |
|
|
CallIdHeader callId = this.sipProvider.getNewCallId(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
request.setContent(createSDPHeader(), content); |
|
|
request.setContent(createSDPHeader(), content); |
|
|
this.sipProvider.sendRequest(request); |
|
|
this.sipProvider.sendRequest(request); |
|
|
|
|
|
|
|
|
lg.info("Erfolgreiches Senden der Invitation"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
public void processDialogTimeout(DialogTimeoutEvent timeoutEvent) |
|
|
|
|
|
{ |
|
|
|
|
|
|
|
|
lg.info("Erfolgreiches Senden der Invitation"); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public void processRequest(RequestEvent requestEvent) |
|
|
public void processRequest(RequestEvent requestEvent) |
|
|
{ |
|
|
{ |
|
|
lg.info("Bekomme Anfrage"); |
|
|
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 |
|
|
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"); |
|
|
lg.info("Option Request von Server, erstellen 200 OK zu Server"); |
|
|
try |
|
|
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 response = this.messageFactory.createResponse(200, requestEvent.getRequest()); |
|
|
response.addHeader((ViaHeader) requestEvent.getRequest().getHeader("Via")); |
|
|
response.addHeader((ViaHeader) requestEvent.getRequest().getHeader("Via")); |
|
|
response.addHeader((FromHeader) requestEvent.getRequest().getHeader("From")); |
|
|
response.addHeader((FromHeader) requestEvent.getRequest().getHeader("From")); |
|
|
|
|
|
|
|
|
this.sipProvider.sendResponse(response); |
|
|
this.sipProvider.sendResponse(response); |
|
|
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 Headers"); |
|
|
|
|
|
*/ |
|
|
} |
|
|
} |
|
|
catch (ParseException | SipException ex) |
|
|
catch (ParseException | SipException ex) |
|
|
{ |
|
|
{ |
|
|
|
|
|
|
|
|
//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 |
|
|
{ |
|
|
{ |
|
|
countWerdeAngerufen++; |
|
|
|
|
|
|
|
|
countWerdeAngerufen++; //bessere Lösung muss her!!, was schickt andere User oder Proxy bei nicht erreichen |
|
|
FromHeader abc = (FromHeader) requestEvent.getRequest().getHeader("From"); |
|
|
FromHeader abc = (FromHeader) requestEvent.getRequest().getHeader("From"); |
|
|
evtWerdeAngerufen = requestEvent; |
|
|
evtWerdeAngerufen = requestEvent; |
|
|
System.out.println(countWerdeAngerufen); |
|
|
System.out.println(countWerdeAngerufen); |
|
|
if(countWerdeAngerufen<7) |
|
|
|
|
|
|
|
|
if (countWerdeAngerufen < 7) |
|
|
{ |
|
|
{ |
|
|
werdeAngerufen = true; |
|
|
werdeAngerufen = true; |
|
|
lg.info("Hab Invitation bekommen"); |
|
|
lg.info("Hab Invitation bekommen"); |
|
|
|
|
|
|
|
|
view.getTxtArea().append("Sie waren nicht erreichbar\n"); |
|
|
view.getTxtArea().append("Sie waren nicht erreichbar\n"); |
|
|
countWerdeAngerufen = 0; |
|
|
countWerdeAngerufen = 0; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
else if ((Request.ACK).equals(requestEvent.getRequest().getMethod())) |
|
|
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 |
|
|
@Override |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try |
|
|
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 temp = (ToHeader) responseEvent.getResponse().getHeader("To"); |
|
|
|
|
|
|
|
|
ToHeader to = this.headerFactory.createToHeader(addresstob, temp.getTag()); // Integer.toString(tag) address + tag |
|
|
ToHeader to = this.headerFactory.createToHeader(addresstob, temp.getTag()); // Integer.toString(tag) address + tag |
|
|
URI requestURI = addresstob.getURI(); |
|
|
URI requestURI = addresstob.getURI(); |
|
|
|
|
|
|
|
|
//CallIdHeader tempcall = (CallIdHeader)responseEvent.getResponse().getHeader("Call-ID"); |
|
|
|
|
|
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.tag)); //this.contactAddress |
|
|
FromHeader from = this.headerFactory.createFromHeader(addresstob, String.valueOf(this.tag)); //this.contactAddress |
|
|
|
|
|
|
|
|
//set Authorization header evtl. user Name benutzen den es gibt |
|
|
//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.setURI(addresstest.getURI()); |
|
|
auth.setUsername(myName); |
|
|
auth.setUsername(myName); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
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 |
|
|
public SessionDescription createSDPHeader() throws SdpException |
|
|
{ |
|
|
{ |
|
|
/* |
|
|
/* |
|
|
|
|
|
|
|
|
mediavec.add(sdpFactory.createAttribute("rtpmap", "18 G729/8000")); |
|
|
mediavec.add(sdpFactory.createAttribute("rtpmap", "18 G729/8000")); |
|
|
mediavec.add(sdpFactory.createAttribute("ptime", "20")); |
|
|
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 |
|
|
{ |
|
|
{ |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
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 |
|
|
{ |
|
|
{ |
|
|
|
|
|
|
|
|
okandSDP.addHeader(content); |
|
|
okandSDP.addHeader(content); |
|
|
okandSDP.setContent(createSDPHeader(), content); |
|
|
okandSDP.setContent(createSDPHeader(), content); |
|
|
this.sipProvider.sendResponse(okandSDP); |
|
|
this.sipProvider.sendResponse(okandSDP); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
view.getTxtArea().append("Telefonat beginnt\n"); |
|
|
view.getTxtArea().append("Telefonat beginnt\n"); |
|
|
evtWerdeAngerufen =null; |
|
|
|
|
|
|
|
|
evtWerdeAngerufen = null; |
|
|
} |
|
|
} |
|
|
catch (ParseException | SipException | SdpException ex) |
|
|
catch (ParseException | SipException | SdpException ex) |
|
|
{ |
|
|
{ |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
else |
|
|
else |
|
|
|
|
|
{ |
|
|
view.getTxtArea().append("Zur Zeit gibt es keinen Anruf\n"); |
|
|
view.getTxtArea().append("Zur Zeit gibt es keinen Anruf\n"); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//Get Methoden falls man mal die Parameter braucht |
|
|
|
|
|
public void cancelcall() |
|
|
public void cancelcall() |
|
|
{ |
|
|
{ |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//Get Methoden falls man mal die Parameter braucht |
|
|
public String getmyName() |
|
|
public String getmyName() |
|
|
{ |
|
|
{ |
|
|
return myName; |
|
|
return myName; |
|
|
|
|
|
|
|
|
return myIPAddress; |
|
|
return myIPAddress; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Herausfinden bei welchen Events die unteren Funktionen aufgerufen werden -> evtl brauchbar |
|
|
@Override |
|
|
@Override |
|
|
public void processTimeout(TimeoutEvent timeoutEvent) |
|
|
public void processTimeout(TimeoutEvent timeoutEvent) |
|
|
{ |
|
|
{ |
|
|
|
|
|
|
|
|
public void processTransactionTerminated( |
|
|
public void processTransactionTerminated( |
|
|
TransactionTerminatedEvent transactionTerminatedEvent) |
|
|
TransactionTerminatedEvent transactionTerminatedEvent) |
|
|
{ |
|
|
{ |
|
|
//view.getTxtArea().append("processTransactionTerminated\n"); |
|
|
|
|
|
|
|
|
//view.getTxtArea().append("processTransactionTerminated\n"); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
|
|
|
|
|
|
{ |
|
|
{ |
|
|
//view.getTxtArea().append("processDialogTerminated\n"); |
|
|
//view.getTxtArea().append("processDialogTerminated\n"); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
public void processDialogTimeout(DialogTimeoutEvent timeoutEvent) |
|
|
|
|
|
{ |
|
|
|
|
|
//view.getTxtArea().append("processDialogTerminated\n"); |
|
|
|
|
|
} |
|
|
} |
|
|
} |