|
|
|
|
|
|
|
|
public class SIPmodel implements SipListenerExt |
|
|
public class SIPmodel implements SipListenerExt |
|
|
{ |
|
|
{ |
|
|
Hauptfenster view; //später entfernen wegen Zugriff |
|
|
Hauptfenster view; //später entfernen wegen Zugriff |
|
|
private static final Logger lg = OhmLogger.getLogger(); |
|
|
|
|
|
SipFactory sipFactory; // Used to access the SIP API. |
|
|
|
|
|
SipStack sipStack; // The SIP stack. |
|
|
|
|
|
SipProvider sipProvider; // Used to send SIP messages. |
|
|
|
|
|
MessageFactory messageFactory; // Used to create SIP message factory. |
|
|
|
|
|
HeaderFactory headerFactory; // Used to create SIP headers. |
|
|
|
|
|
AddressFactory addressFactory; // Used to create SIP URIs. |
|
|
|
|
|
ListeningPoint listeningPoint; // SIP listening IP address/port. |
|
|
|
|
|
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; |
|
|
|
|
|
|
|
|
public static final Logger lg = OhmLogger.getLogger(); |
|
|
|
|
|
public SipFactory sipFactory; // Used to access the SIP API. |
|
|
|
|
|
public SipStack sipStack; // The SIP stack. |
|
|
|
|
|
public SipProvider sipProvider; // Used to send SIP messages. |
|
|
|
|
|
public MessageFactory messageFactory; // Used to create SIP message factory. |
|
|
|
|
|
public HeaderFactory headerFactory; // Used to create SIP headers. |
|
|
|
|
|
public AddressFactory addressFactory; // Used to create SIP URIs. |
|
|
|
|
|
public ListeningPoint listeningPoint; // SIP listening IP address/port. |
|
|
|
|
|
public Properties properties; // Other properties. |
|
|
|
|
|
|
|
|
|
|
|
private String[][] codecs; //unterstütze Codecs[RTP-Parameter][CodecBezeichnung] |
|
|
|
|
|
|
|
|
|
|
|
public int myPort = 5060; |
|
|
|
|
|
public String myName = "129"; |
|
|
|
|
|
public String protocolTyp = "UDP"; |
|
|
|
|
|
public String myIPAddress; |
|
|
|
|
|
public String proxyAddress; |
|
|
|
|
|
public CallIdHeader callID; |
|
|
|
|
|
|
|
|
Boolean invite; //Bool für SDP falls ich anrufe |
|
|
Boolean invite; //Bool für SDP falls ich anrufe |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Boolean werdeAngerufen; |
|
|
Boolean werdeAngerufen; |
|
|
private int countWerdeAngerufen; |
|
|
private int countWerdeAngerufen; |
|
|
|
|
|
|
|
|
int tag = (new Random()).nextInt(); |
|
|
|
|
|
private int branch = hashCode(); |
|
|
|
|
|
Address contactAddress; |
|
|
|
|
|
private ContactHeader contactHeader; |
|
|
|
|
|
|
|
|
public long cSequenz = 1; |
|
|
|
|
|
public String proxyTag; |
|
|
|
|
|
public int myTag = (new Random()).nextInt(); |
|
|
|
|
|
public int branch = hashCode(); |
|
|
|
|
|
public Address contactAddress; |
|
|
|
|
|
public ContactHeader contactHeader; |
|
|
|
|
|
|
|
|
public SIPmodel(Hauptfenster view) //Konstruktor für eigene Daten |
|
|
public SIPmodel(Hauptfenster view) //Konstruktor für eigene Daten |
|
|
{ |
|
|
{ |
|
|
|
|
|
|
|
|
countWerdeAngerufen = 0; |
|
|
countWerdeAngerufen = 0; |
|
|
evtWerdeAngerufen = null; |
|
|
evtWerdeAngerufen = null; |
|
|
werdeAngerufen = false; |
|
|
werdeAngerufen = false; |
|
|
|
|
|
codecs = new String[4][2]; // Alle unterstützen Codecs eintragen |
|
|
|
|
|
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"; |
|
|
|
|
|
|
|
|
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.sipFactory.setPathName("gov.nist"); |
|
|
this.sipFactory.setPathName("gov.nist"); |
|
|
this.properties = new Properties(); |
|
|
this.properties = new Properties(); |
|
|
|
|
|
|
|
|
//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); |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
catch (Exception e) |
|
|
catch (Exception e) |
|
|
{ |
|
|
{ |
|
|
System.out.println("Fehler bei Initialisierung eigener Addresse"); |
|
|
System.out.println("Fehler bei Initialisierung eigener Addresse"); |
|
|
System.exit(-1); |
|
|
System.exit(-1); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public int hashCode() |
|
|
public int hashCode() |
|
|
{ |
|
|
{ |
|
|
int temp = tag * (new Random(100)).nextInt(); |
|
|
|
|
|
|
|
|
int temp = myTag * (new Random(100)).nextInt(); |
|
|
return temp; |
|
|
return temp; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
lg.info("Vorbereiten des Registrierungs Headers"); |
|
|
lg.info("Vorbereiten des Registrierungs Headers"); |
|
|
proxyAddress = serverIP + ":" + serverPort; |
|
|
proxyAddress = serverIP + ":" + serverPort; |
|
|
Address addressto = this.addressFactory.createAddress("sip:" + proxyAddress); //evtl. mit Port: sip:192.168.100.11:5060 |
|
|
Address addressto = this.addressFactory.createAddress("sip:" + proxyAddress); //evtl. mit Port: sip:192.168.100.11:5060 |
|
|
ToHeader to = this.headerFactory.createToHeader(addressto, null); // Integer.toString(tag) address + tag |
|
|
|
|
|
|
|
|
ToHeader to = this.headerFactory.createToHeader(addressto, null); // Integer.toString(myTag) address + myTag |
|
|
URI requestURI = addressto.getURI(); |
|
|
URI requestURI = addressto.getURI(); |
|
|
CallIdHeader callId = this.sipProvider.getNewCallId(); |
|
|
CallIdHeader callId = this.sipProvider.getNewCallId(); |
|
|
FromHeader from = this.headerFactory.createFromHeader(addressto, String.valueOf(this.tag)); //this.contactAddress |
|
|
|
|
|
|
|
|
FromHeader from = this.headerFactory.createFromHeader(addressto, String.valueOf(this.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 = this.headerFactory.createViaHeader(this.myIPAddress, this.myPort, "UDP", String.valueOf(branch)); |
|
|
ViaHeader viaheader = this.headerFactory.createViaHeader(this.myIPAddress, this.myPort, "UDP", String.valueOf(branch)); |
|
|
via.add(viaheader); |
|
|
via.add(viaheader); |
|
|
|
|
|
|
|
|
{ |
|
|
{ |
|
|
invite = true; |
|
|
invite = true; |
|
|
Address addressto = this.addressFactory.createAddress("sip:" + sipaddresse + "@" + proxyaddresse); |
|
|
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(myTag) address + myTag |
|
|
URI requestURI = addressto.getURI(); |
|
|
URI requestURI = addressto.getURI(); |
|
|
CallIdHeader callId = this.sipProvider.getNewCallId(); |
|
|
|
|
|
FromHeader from = this.headerFactory.createFromHeader(addressto, String.valueOf(this.tag)); //this.contactAddress |
|
|
|
|
|
|
|
|
callID = this.sipProvider.getNewCallId(); |
|
|
|
|
|
FromHeader from = this.headerFactory.createFromHeader(addressto, String.valueOf(this.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 = this.headerFactory.createViaHeader(this.myIPAddress, this.myPort, "UDP", String.valueOf(branch)); |
|
|
ViaHeader viaheader = this.headerFactory.createViaHeader(this.myIPAddress, this.myPort, "UDP", String.valueOf(branch)); |
|
|
via.add(viaheader); |
|
|
via.add(viaheader); |
|
|
CSeqHeader cSeq = this.headerFactory.createCSeqHeader(1L, "INVITE"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CSeqHeader cSeq = this.headerFactory.createCSeqHeader(cSequenz, "INVITE"); |
|
|
|
|
|
|
|
|
MaxForwardsHeader maxForwards = this.headerFactory.createMaxForwardsHeader(70); |
|
|
MaxForwardsHeader maxForwards = this.headerFactory.createMaxForwardsHeader(70); |
|
|
AllowHeader allow = this.headerFactory.createAllowHeader("NOTIFY,INVITE,ACK,CANCEL,BYE,REFER,INFO,OPTIONS,MESSAGE"); |
|
|
AllowHeader allow = this.headerFactory.createAllowHeader("NOTIFY,INVITE,ACK,CANCEL,BYE,REFER,INFO,OPTIONS,MESSAGE"); |
|
|
ExpiresHeader expire = this.headerFactory.createExpiresHeader(3600); //int value |
|
|
ExpiresHeader expire = this.headerFactory.createExpiresHeader(3600); //int value |
|
|
Request request = this.messageFactory.createRequest(requestURI, "INVITE", callId, cSeq, from, to, via, maxForwards); |
|
|
|
|
|
|
|
|
Request request = this.messageFactory.createRequest(requestURI, "INVITE", callID, cSeq, from, to, via, maxForwards); |
|
|
request.addHeader(contactHeader); |
|
|
request.addHeader(contactHeader); |
|
|
request.addHeader(allow); |
|
|
request.addHeader(allow); |
|
|
request.addHeader(expire); |
|
|
request.addHeader(expire); |
|
|
|
|
|
|
|
|
ContentTypeHeader content = headerFactory.createContentTypeHeader("application", "sdp"); |
|
|
ContentTypeHeader content = headerFactory.createContentTypeHeader("application", "sdp"); |
|
|
request.addHeader(content); |
|
|
request.addHeader(content); |
|
|
|
|
|
|
|
|
request.setContent(createSDPHeader(), content); |
|
|
|
|
|
|
|
|
request.setContent(createSDPHeader(null), content); |
|
|
this.sipProvider.sendRequest(request); |
|
|
this.sipProvider.sendRequest(request); |
|
|
|
|
|
|
|
|
lg.info("Erfolgreiches Senden der Invitation"); |
|
|
lg.info("Erfolgreiches Senden der Invitation"); |
|
|
|
|
|
|
|
|
this.sipProvider.sendResponse(create200Ok(requestEvent)); |
|
|
this.sipProvider.sendResponse(create200Ok(requestEvent)); |
|
|
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"); |
|
|
/* |
|
|
|
|
|
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")); |
|
|
|
|
|
//Kontakt Header |
|
|
|
|
|
response.addHeader(contactHeader); |
|
|
|
|
|
//Accept Header für application/sdp |
|
|
|
|
|
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); |
|
|
|
|
|
this.sipProvider.sendResponse(response); |
|
|
|
|
|
view.getTxtArea().append("Server Option Request erfolgreich beantwortet\n"); |
|
|
|
|
|
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 |
|
|
{ |
|
|
{ |
|
|
|
|
|
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 |
|
|
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) |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
else if ((Request.CANCEL).equals(requestEvent.getRequest().getMethod())) |
|
|
else if ((Request.CANCEL).equals(requestEvent.getRequest().getMethod())) |
|
|
{ |
|
|
{ |
|
|
|
|
|
view.getTxtArea().append("Anruf wurde gecancelt"); |
|
|
try |
|
|
try |
|
|
{ |
|
|
{ |
|
|
//Cancel Request -> Response 200 Ok + Response 487 Request Terminated |
|
|
//Cancel Request -> Response 200 Ok + Response 487 Request Terminated |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
else if ((Request.BYE).equals(requestEvent.getRequest().getMethod())) |
|
|
else if ((Request.BYE).equals(requestEvent.getRequest().getMethod())) |
|
|
{ |
|
|
{ |
|
|
|
|
|
try |
|
|
|
|
|
{ |
|
|
|
|
|
this.sipProvider.sendResponse(create200Ok(requestEvent)); |
|
|
|
|
|
} |
|
|
|
|
|
catch (Exception ex) |
|
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (responseEvent.getResponse().getStatusCode() == Response.UNAUTHORIZED) |
|
|
if (responseEvent.getResponse().getStatusCode() == Response.UNAUTHORIZED) |
|
|
{ |
|
|
{ |
|
|
|
|
|
|
|
|
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:" + myName + "@" + proxyAddress); |
|
|
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(myTag) address + myTag |
|
|
URI requestURI = addresstob.getURI(); |
|
|
URI requestURI = addresstob.getURI(); |
|
|
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 |
|
|
|
|
|
|
|
|
|
|
|
//set Authorization header evtl. user Name benutzen den es gibt |
|
|
|
|
|
//wird WWWAuthenticateHeader überhaupt benötigt??? |
|
|
|
|
|
|
|
|
FromHeader from = this.headerFactory.createFromHeader(addresstob, String.valueOf(this.myTag)); //this.contactAddress |
|
|
WWWAuthenticateHeader wwwauth = (WWWAuthenticateHeader) responseEvent.getResponse().getHeader("WWW-Authenticate"); |
|
|
WWWAuthenticateHeader wwwauth = (WWWAuthenticateHeader) responseEvent.getResponse().getHeader("WWW-Authenticate"); |
|
|
|
|
|
|
|
|
//wird bei AuthorizationHeader wirklich alles benötigt? war glaub nur mal Test -> testen!! |
|
|
//wird bei AuthorizationHeader wirklich alles benötigt? war glaub nur mal Test -> testen!! |
|
|
|
|
|
|
|
|
{ |
|
|
{ |
|
|
lg.info("Erfolgreichen Response (200 OK) bekommen"); |
|
|
lg.info("Erfolgreichen Response (200 OK) bekommen"); |
|
|
} |
|
|
} |
|
|
|
|
|
else if (responseEvent.getResponse().getStatusCode() == Response.RINGING) |
|
|
|
|
|
{ |
|
|
|
|
|
ToHeader temp = (ToHeader) responseEvent.getResponse().getHeader("To"); |
|
|
|
|
|
proxyTag = temp.getTag(); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return response; |
|
|
return response; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public SessionDescription createSDPHeader() throws SdpException |
|
|
|
|
|
|
|
|
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(String.valueOf(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 SIPmodel() |
|
|
|
|
|
{ |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public SessionDescription createSDPHeader(ArrayList<String> reqSDP) throws SdpException |
|
|
{ |
|
|
{ |
|
|
/* |
|
|
|
|
|
String contentparam = "v=0\r\n" + "o=129 1202 1202" + " IN IP4 192.168.100.247\r\n" + "s=SIP Call\r\n" |
|
|
|
|
|
+ "c=192.168.100.247\r\n" + "t=0 0\r\n" + "m=audio 6022 RTP/AVP 0 4 18\r\n" |
|
|
|
|
|
+ "a=rtpmap:0 PCMU/8000\r\n" + "a=rtpmap:4 G723/8000\r\n" + "a=rtpmap:18 G729A/8000\r\n" + |
|
|
|
|
|
"a=ptime:20\r\n"; |
|
|
|
|
|
*/ |
|
|
|
|
|
SdpFactory sdpFactory = SdpFactory.getInstance(); |
|
|
SdpFactory sdpFactory = SdpFactory.getInstance(); |
|
|
SessionDescription sessionDescription = sdpFactory.createSessionDescription(); |
|
|
SessionDescription sessionDescription = sdpFactory.createSessionDescription(); |
|
|
sessionDescription.setOrigin(sdpFactory.createOrigin(myName, 8000, 8000, "IN", "IP4", myIPAddress)); |
|
|
sessionDescription.setOrigin(sdpFactory.createOrigin(myName, 8000, 8000, "IN", "IP4", myIPAddress)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Media Body |
|
|
//Media Body |
|
|
Vector mediavec = new Vector(); |
|
|
Vector mediavec = new Vector(); |
|
|
|
|
|
String cods[] = new String[codecs.length]; |
|
|
|
|
|
System.out.println("System out: " + codecs.length); |
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < cods.length; i++)//Übertragung der RTP-Values in neues Array |
|
|
|
|
|
{ |
|
|
|
|
|
cods[i] = codecs[i][0]; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
mediavec.add(sdpFactory.createMediaDescription("audio", 6022, 1, "RTP/AVP", cods)); //(Übertragungstyp, Port, anzahl der Ports, Verbindungstyp,..) |
|
|
|
|
|
mediavec.add(sdpFactory.createAttribute("sendrecv", null)); |
|
|
if (invite = true) |
|
|
if (invite = true) |
|
|
{ |
|
|
{ |
|
|
String sdpformat[] = |
|
|
|
|
|
|
|
|
for (int i = 0; i == codecs[0].length; i++) |
|
|
{ |
|
|
{ |
|
|
"0", "4", "8", "18", |
|
|
|
|
|
}; |
|
|
|
|
|
mediavec.add(sdpFactory.createMediaDescription("audio", 6022, 1, "RTP/AVP", sdpformat)); //(Übertragungstyp, Port, anzahl der Ports, Verbindungstyp,..) |
|
|
|
|
|
//Media Attribute |
|
|
|
|
|
mediavec.add(sdpFactory.createAttribute("sendrecv", null)); |
|
|
|
|
|
mediavec.add(sdpFactory.createAttribute("rtpmap", "0 PCMU/8000")); |
|
|
|
|
|
mediavec.add(sdpFactory.createAttribute("rtpmap", "4 G723/8000")); |
|
|
|
|
|
mediavec.add(sdpFactory.createAttribute("rtpmap", "8 PCMA/8000")); |
|
|
|
|
|
mediavec.add(sdpFactory.createAttribute("rtpmap", "18 G729/8000")); |
|
|
|
|
|
mediavec.add(sdpFactory.createAttribute("ptime", "20")); |
|
|
|
|
|
|
|
|
System.out.println("Codecs: " + codecs[i][0] + " " + codecs[i][1]); |
|
|
|
|
|
mediavec.add(sdpFactory.createAttribute("rtpmap", codecs[i][0] + " " + codecs[i][1])); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
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 |
|
|
{ |
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
boolean temp = true; //evtl noch was besseres da so erster Codec nicht bester verwendet wird |
|
|
|
|
|
for (int i = 0; i == codecs[0].length; i++) |
|
|
|
|
|
{ |
|
|
|
|
|
if (codecs[i][1].equals(reqSDP) && temp == true) |
|
|
|
|
|
{ |
|
|
|
|
|
mediavec.add(sdpFactory.createAttribute("rtpmap", "8 G711a/8000")); |
|
|
|
|
|
temp = false; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
sessionDescription.setAttributes(mediavec); |
|
|
sessionDescription.setAttributes(mediavec); |
|
|
|
|
|
|
|
|
return sessionDescription; |
|
|
return sessionDescription; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try |
|
|
try |
|
|
{ |
|
|
{ |
|
|
|
|
|
callID = (CallIdHeader) requestEvent.getRequest().getHeader("Call-ID"); |
|
|
//Trying Message to Server (Response Trying) |
|
|
//Trying Message to Server (Response Trying) |
|
|
Response responsetry = this.messageFactory.createResponse(100, requestEvent.getRequest()); |
|
|
Response responsetry = this.messageFactory.createResponse(100, requestEvent.getRequest()); |
|
|
responsetry.addHeader((ViaHeader) requestEvent.getRequest().getHeader("Via")); |
|
|
responsetry.addHeader((ViaHeader) requestEvent.getRequest().getHeader("Via")); |
|
|
|
|
|
|
|
|
responsetry.addHeader((CallIdHeader) requestEvent.getRequest().getHeader("Call-ID")); |
|
|
responsetry.addHeader((CallIdHeader) requestEvent.getRequest().getHeader("Call-ID")); |
|
|
responsetry.addHeader((CSeqHeader) requestEvent.getRequest().getHeader("Cseq")); |
|
|
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 |
|
|
SupportedHeader supp = this.headerFactory.createSupportedHeader("replace,path,timer"); //nachschauen |
|
|
AllowHeader allow = this.headerFactory.createAllowHeader("NOTIFY,INVITE,ACK,CANCEL,BYE,REFER,INFO,OPTIONS,MESSAGE"); |
|
|
AllowHeader allow = this.headerFactory.createAllowHeader("NOTIFY,INVITE,ACK,CANCEL,BYE,REFER,INFO,OPTIONS,MESSAGE"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
responsering.addHeader((FromHeader) requestEvent.getRequest().getHeader("From")); |
|
|
responsering.addHeader((FromHeader) requestEvent.getRequest().getHeader("From")); |
|
|
|
|
|
|
|
|
ToHeader temptoring = (ToHeader) requestEvent.getRequest().getHeader("To"); |
|
|
ToHeader temptoring = (ToHeader) requestEvent.getRequest().getHeader("To"); |
|
|
String tempTag = String.valueOf(this.tag + Math.random()); |
|
|
|
|
|
|
|
|
String tempTag = String.valueOf(this.myTag + Math.random()); |
|
|
temptoring.setTag(tempTag); //evtl. besseren Tag |
|
|
temptoring.setTag(tempTag); //evtl. besseren Tag |
|
|
responsering.addHeader(temptoring); |
|
|
responsering.addHeader(temptoring); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Jetzt kommt 200 Ok SIP Header + SDP (SIP/SDP) |
|
|
//Jetzt kommt 200 Ok SIP Header + SDP (SIP/SDP) |
|
|
//Sdp Header erstellen nächster Schritt |
|
|
//Sdp Header erstellen nächster Schritt |
|
|
invite = false; |
|
|
invite = false; |
|
|
System.out.println(requestEvent.getDialog()); |
|
|
|
|
|
Response okandSDP = this.messageFactory.createResponse(Response.OK, requestEvent.getRequest()); |
|
|
Response okandSDP = this.messageFactory.createResponse(Response.OK, requestEvent.getRequest()); |
|
|
//okandSDP.addHeader((ViaHeader) requestEvent.getRequest().getHeader("Via")); |
|
|
//okandSDP.addHeader((ViaHeader) requestEvent.getRequest().getHeader("Via")); |
|
|
okandSDP.addHeader((FromHeader) requestEvent.getRequest().getHeader("From")); |
|
|
okandSDP.addHeader((FromHeader) requestEvent.getRequest().getHeader("From")); |
|
|
|
|
|
|
|
|
okandSDP.addHeader(allowevent); |
|
|
okandSDP.addHeader(allowevent); |
|
|
ContentTypeHeader content = headerFactory.createContentTypeHeader("application", "sdp"); |
|
|
ContentTypeHeader content = headerFactory.createContentTypeHeader("application", "sdp"); |
|
|
okandSDP.addHeader(content); |
|
|
okandSDP.addHeader(content); |
|
|
okandSDP.setContent(createSDPHeader(), content); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String[] reqbody = (requestEvent.getRequest()).toString().split("\\s|" + System.getProperty("line.seperator"));//Req. Body in Zeilen aufteilen |
|
|
|
|
|
ArrayList<String> reqSDP = new ArrayList<>(); |
|
|
|
|
|
for (String req : reqbody)//jeden String durchgehen und nach Codecs suchen die unterstützt werden |
|
|
|
|
|
{ |
|
|
|
|
|
if (req.startsWith("a=rtpmap")) |
|
|
|
|
|
{ |
|
|
|
|
|
reqSDP.add(req.replace("a=rtpmap:", "")); |
|
|
|
|
|
System.out.println(reqSDP); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
okandSDP.setContent(createSDPHeader(reqSDP), content); |
|
|
this.sipProvider.sendResponse(okandSDP); |
|
|
this.sipProvider.sendResponse(okandSDP); |
|
|
|
|
|
|
|
|
view.getTxtArea().append("Telefonat beginnt\n"); |
|
|
view.getTxtArea().append("Telefonat beginnt\n"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public void cancelcall() |
|
|
|
|
|
|
|
|
public void byecall(String calluser) throws ParseException, InvalidArgumentException, SipException |
|
|
{ |
|
|
{ |
|
|
|
|
|
invite = false; |
|
|
|
|
|
Address addressLine = this.addressFactory.createAddress("sip:" + calluser + "@" + proxyAddress); |
|
|
|
|
|
URI requestURI = addressLine.getURI(); |
|
|
|
|
|
|
|
|
|
|
|
Address addressfrom = this.addressFactory.createAddress("sip:" + myName + "@" + myIPAddress); |
|
|
|
|
|
FromHeader from = this.headerFactory.createFromHeader(addressfrom, String.valueOf(this.myTag)); |
|
|
|
|
|
|
|
|
|
|
|
Address addressTo = this.addressFactory.createAddress("sip:" + myName + "@" + proxyAddress); |
|
|
|
|
|
ToHeader to = this.headerFactory.createToHeader(addressTo, proxyTag); // Ergänzung TAG!! |
|
|
|
|
|
|
|
|
|
|
|
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); |
|
|
|
|
|
|
|
|
|
|
|
cSequenz++; |
|
|
|
|
|
CSeqHeader cSeq = this.headerFactory.createCSeqHeader(cSequenz, "BYE"); |
|
|
|
|
|
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, "BYE", callID, cSeq, from, to, via, maxForwards); |
|
|
|
|
|
request.addHeader(contactHeader); |
|
|
|
|
|
request.addHeader(allow); |
|
|
|
|
|
request.addHeader(expire); |
|
|
|
|
|
this.sipProvider.sendRequest(request); |
|
|
|
|
|
invite = false; |
|
|
|
|
|
|
|
|
|
|
|
lg.info("Erfolgreiches Senden des BYE Headers"); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//Get Methoden falls man mal die Parameter braucht |
|
|
//Get Methoden falls man mal die Parameter braucht |