Jan Gabriel Kunze 5 years ago
parent
commit
cbb42b3041

+ 19
- 0
src/controller/commands/CommandAnnehmen.java View File

private static final Logger lginvite = OhmLogger.getLogger(); private static final Logger lginvite = OhmLogger.getLogger();
private SIPmodel model; private SIPmodel model;
private Hauptfenster view; private Hauptfenster view;
//private InputStream istream;
//Socket s;
public CommandAnnehmen(SIPmodel model, Hauptfenster view) public CommandAnnehmen(SIPmodel model, Hauptfenster view)
{ {
this.model = model; this.model = model;
{ {
{ {
model.annehmen(); model.annehmen();
try
{
//s = new Socket(model.getMyIPAdress(),model.getMyPort());
view.getTxtArea().append("Socket geöffnet");
//istream = s.getInputStream();
//System.out.println(istream);
}
catch(Exception ex)
{
}
} }
} }
@Override @Override

+ 18
- 19
src/controller/commands/CommandBeenden.java View File

* To change this template file, choose Tools | Templates * To change this template file, choose Tools | Templates
* and open the template in the editor. * and open the template in the editor.
*/ */

package controller.commands; package controller.commands;


import controller.CommandInterface; import controller.CommandInterface;


/** /**
* *
* @author Jan
* Muss noch komplett implementiert werden
* -> Bye bei laufendem Gespräch
* -> Cancel bei laufender Anfrage, sollte beides recht schnell gehen wenn ihr Lust habt.
* @author Jan Muss noch komplett implementiert werden -> Bye bei laufendem
* Gespräch -> Cancel bei laufender Anfrage, sollte beides recht schnell gehen
* wenn ihr Lust habt.
* *
*/ */
public class CommandBeenden implements CommandInterface public class CommandBeenden implements CommandInterface
{
private static final Logger lginvite = OhmLogger.getLogger();
{
private static final Logger lginvite = OhmLogger.getLogger();
private SIPmodel model; private SIPmodel model;
private Hauptfenster view; private Hauptfenster view;

public CommandBeenden(SIPmodel model, Hauptfenster view) public CommandBeenden(SIPmodel model, Hauptfenster view)
{ {
this.model = model; this.model = model;
this.view = view;
this.view = view;
} }
@Override @Override
public void execute()
{/*
public void execute()
{

view.getTxtArea().append("Anruf beenden\n");
try try
{
view.getTxtArea().append("Anruf beenden\n");
model.cancelcall();
{
model.byecall(view.getTxtcallUser().getText());
} }
catch (ParseException|InvalidArgumentException|SdpException|SipException ex)
catch (Exception e)
{ {
view.getTxtArea().append("Einladung fehlgeschlagen\n");
lginvite.getLogger(CommandBeenden.class.getName()).log(Level.SEVERE, null, ex);
}*/
}
} }

@Override @Override
public void undo() public void undo()
{ {
} }


@Override @Override

+ 1
- 1
src/gui/Hauptfenster.form View File

<Property name="text" type="java.lang.String" value="xxx.xxx.xxx.xxx"/> <Property name="text" type="java.lang.String" value="xxx.xxx.xxx.xxx"/>
</Properties> </Properties>
</Component> </Component>
<Component class="javax.swing.JTextField" name="txtcallIP">
<Component class="javax.swing.JTextField" name="txtcallUser">
<Properties> <Properties>
<Property name="text" type="java.lang.String" value="name"/> <Property name="text" type="java.lang.String" value="name"/>
</Properties> </Properties>

+ 12
- 5
src/gui/Hauptfenster.java View File

*/ */
public class Hauptfenster extends javax.swing.JFrame public class Hauptfenster extends javax.swing.JFrame
{ {
/**
* @return the txtcallUser
*/
public javax.swing.JTextField getTxtcallUser()
{
return txtcallUser;
}
/** /**
* @return the btnannehmen * @return the btnannehmen
*/ */
jPanel2 = new javax.swing.JPanel(); jPanel2 = new javax.swing.JPanel();
lblmyIP = new javax.swing.JLabel(); lblmyIP = new javax.swing.JLabel();
txtServerIP = new javax.swing.JTextField(); txtServerIP = new javax.swing.JTextField();
txtcallIP = new javax.swing.JTextField();
txtcallUser = new javax.swing.JTextField();


setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);


txtServerIP.setText("xxx.xxx.xxx.xxx"); txtServerIP.setText("xxx.xxx.xxx.xxx");
jPanel2.add(txtServerIP); jPanel2.add(txtServerIP);


txtcallIP.setText("name");
jPanel2.add(txtcallIP);
txtcallUser.setText("name");
jPanel2.add(txtcallUser);


jPanel3.add(jPanel2); jPanel3.add(jPanel2);


private javax.swing.JLabel lblmyIP; private javax.swing.JLabel lblmyIP;
private javax.swing.JTextArea txtArea; private javax.swing.JTextArea txtArea;
private javax.swing.JTextField txtServerIP; private javax.swing.JTextField txtServerIP;
private javax.swing.JTextField txtcallIP;
private javax.swing.JTextField txtcallUser;
// End of variables declaration//GEN-END:variables // End of variables declaration//GEN-END:variables


/** /**
*/ */
public javax.swing.JTextField getTxtcallIP() public javax.swing.JTextField getTxtcallIP()
{ {
return txtcallIP;
return txtcallUser;
} }
} }

+ 132
- 0
src/model/Audioaufnahme.java View File

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package model;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.concurrent.ExecutorService;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.DataLine;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.SourceDataLine;
import javax.sound.sampled.TargetDataLine;

/**
*
* @author Jan
*/
public class Audioaufnahme implements Runnable
{
AudioFormat format;
TargetDataLine mic;
AudioInputStream audioInput;
//AudioOutputStream audioOutput;
SourceDataLine sourceData;
private ExecutorService audioausgabe;
ByteArrayOutputStream out;

public Audioaufnahme()
{
float sampleRate = 48000;
int sampleSizeInBits = 16;
int channels = 1;
boolean signed = true;
boolean bigEndian = true;
try
{
format = new AudioFormat(sampleRate, sampleSizeInBits, channels, signed, bigEndian);
mic = AudioSystem.getTargetDataLine(format);
DataLine.Info info = new DataLine.Info(TargetDataLine.class, format);
mic = (TargetDataLine) AudioSystem.getLine(info);
}
catch (Exception e)
{
System.out.println("Fehler bei dem Audioformat des Mikrophones");
Logger.getLogger(Audioaufnahme.class.getName()).log(Level.SEVERE, null, e);
}
}

public void startaufnahme()
{
out = new ByteArrayOutputStream();
try
{
mic.open(format);
int numBytesRead;
int CHUNCK_SIZE = 1024;
byte[] data = new byte[mic.getBufferSize() / 5];
mic.start();
int bytesRead = 0;

try
{
while (bytesRead < 1000000)
{
numBytesRead = mic.read(data, 0, CHUNCK_SIZE);
bytesRead = bytesRead + numBytesRead;
out.write(data, 0, numBytesRead);
}

}
catch (Exception e)
{
e.printStackTrace();
}
mic.close();
}
catch (LineUnavailableException ex)
{
Logger.getLogger(Audioaufnahme.class.getName()).log(Level.SEVERE, null, ex);
}
}
public void playAudio()
{
try
{
byte audioData[] = out.toByteArray();
InputStream byteArrayInputStream = new ByteArrayInputStream(
audioData);
audioInput = new AudioInputStream(byteArrayInputStream, format, audioData.length / format.getFrameSize());
DataLine.Info dataLineInfo = new DataLine.Info(SourceDataLine.class, format);
sourceData = (SourceDataLine) AudioSystem.getLine(dataLineInfo);
sourceData.open(format);
sourceData.start();
int cnt = 0;
byte tempBuffer[] = new byte[1000000];
try
{
while ((cnt = audioInput.read(tempBuffer, 0, tempBuffer.length)) != -1)
{
if (cnt > 0)
{
sourceData.write(tempBuffer, 0, cnt);
}
}
}
catch (IOException e)
{
e.printStackTrace();
}
sourceData.drain();
sourceData.close();
}
catch (Exception e)
{

}
}

@Override
public void run()
{
}
}

+ 95
- 0
src/model/Audioausgabe.java View File

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package model;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.DataLine;
import javax.sound.sampled.SourceDataLine;
import javax.sound.sampled.TargetDataLine;

/**
*
* @author Jan
*/
public class Audioausgabe implements Runnable
{
AudioFormat format;
AudioInputStream audioInput;
SourceDataLine sourceData;
private ExecutorService audioausgabe;
ByteArrayOutputStream output;

public Audioausgabe()
{
audioausgabe = Executors.newSingleThreadExecutor();
float sampleRate = 48000;
int sampleSizeInBits = 16;
int channels = 1;
boolean signed = true;
boolean bigEndian = true;
try
{
format = new AudioFormat(sampleRate, sampleSizeInBits, channels, signed, bigEndian);
DataLine.Info info = new DataLine.Info(TargetDataLine.class, format);
}
catch (Exception e)
{
System.out.println("Fehler bei dem Audioformat des Mikrophones");
Logger.getLogger(Audioausgabe.class.getName()).log(Level.SEVERE, null, e);
}
}
public void playAudio()
{
try
{
byte audioData[] = output.toByteArray();
InputStream byteArrayInputStream = new ByteArrayInputStream(
audioData);
audioInput = new AudioInputStream(byteArrayInputStream, format, audioData.length / format.getFrameSize());
DataLine.Info dataLineInfo = new DataLine.Info(SourceDataLine.class, format);
sourceData = (SourceDataLine) AudioSystem.getLine(dataLineInfo);
sourceData.open(format);
sourceData.start();
int cnt = 0;
byte tempBuffer[] = new byte[1000000];
try
{
while ((cnt = audioInput.read(tempBuffer, 0, tempBuffer.length)) != -1)
{
if (cnt > 0)
{
sourceData.write(tempBuffer, 0, cnt);
}
}
}
catch (IOException e)
{
e.printStackTrace();
}
sourceData.drain();
sourceData.close();
}
catch (Exception e)
{

}
}

@Override
public void run()
{
}
}

+ 107
- 0
src/model/SIPRinging.java View File

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package model;

import static java.lang.Thread.sleep;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.sip.RequestEvent;
import javax.sip.SipException;
import javax.sip.header.AllowEventsHeader;
import javax.sip.header.AllowHeader;
import javax.sip.header.CSeqHeader;
import javax.sip.header.FromHeader;
import javax.sip.header.ToHeader;
import javax.sip.header.ViaHeader;
import javax.sip.message.Response;

/**
*
* @author Jan
*/
public class SIPRinging implements Runnable
{
private RequestEvent evtubergabe;
private ExecutorService threadring;
private boolean run;
private Response responsering;
//private SubmissionPublisher<Integer> publisherZahl;

public SIPRinging(RequestEvent evtubergabe)
{
this.evtubergabe = evtubergabe;
threadring = Executors.newSingleThreadExecutor();
try
{
responsering = this.messageFactory.createResponse(180, evtubergabe.getRequest());
}
catch (Exception ex)
{
lg.getLogger(SIPmodel.class.getName()).log(Level.SEVERE, null, ex);
}
}

public void start()
{
run = true;
threadring.submit(this);
}

public void stop()
{
run = false;
}

public void createRingingHeader()
{
try
{
responsering.addHeader((ViaHeader) evtubergabe.getRequest().getHeader("Via"));
responsering.addHeader((FromHeader) evtubergabe.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) evtubergabe.getRequest().getHeader("To");
proxyTag = temptoring.getTag();
temptoring.setTag(String.valueOf(this.myTag));
responsering.addHeader(temptoring);
cSequenz = ((CSeqHeader) evtubergabe.getRequest().getHeader("Cseq")).getSeqNumber();
responsering.addHeader((CSeqHeader) evtubergabe.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);
}
catch (Exception ex)
{
lg.getLogger(SIPmodel.class.getName()).log(Level.SEVERE, null, ex);
}
}

@Override
public void run()
{
while (run)
{
try
{
this.sipProvider.sendResponse(responsering);
}
catch (SipException ex)
{
Logger.getLogger(SIPRinging.class.getName()).log(Level.SEVERE, null, ex);
}
try
{
sleep(1000);
}
catch (Exception e)
{
}
}
}
}

+ 162
- 87
src/model/SIPmodel.java View File

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

Loading…
Cancel
Save