r3335 - in trunk/libminisip: . include include/libminisip/signaling/sdp source/subsystem_media source/subsystem_media/msrp source/subsystem_signaling/sdp source/subsystem_signaling/sip

mafe at minisip.org mafe at minisip.org
Wed Jun 27 10:50:23 CEST 2007


Author: mafe
Date: 2007-06-27 10:50:22 +0200 (Wed, 27 Jun 2007)
New Revision: 3335

Added:
   trunk/libminisip/source/subsystem_media/msrp/
   trunk/libminisip/source/subsystem_media/msrp/MSRPMessage.cxx
   trunk/libminisip/source/subsystem_media/msrp/MSRPMessage.h
   trunk/libminisip/source/subsystem_media/msrp/MSRPReceiver.cxx
   trunk/libminisip/source/subsystem_media/msrp/MSRPSender.cxx
Modified:
   trunk/libminisip/Makefile.am
   trunk/libminisip/configure.ac
   trunk/libminisip/include/Makefile.am
   trunk/libminisip/include/libminisip/signaling/sdp/SdpHeader.h
   trunk/libminisip/include/libminisip/signaling/sdp/SdpHeaderA.h
   trunk/libminisip/source/subsystem_signaling/sdp/SdpHeaderA.cxx
   trunk/libminisip/source/subsystem_signaling/sdp/SdpPacket.cxx
   trunk/libminisip/source/subsystem_signaling/sip/DefaultDialogHandler.cxx
   trunk/libminisip/source/subsystem_signaling/sip/SipDialogVoipServer.cxx
Log:

Added SDP I header. It describes a file transfer.

Added a MSRP (Message Session Relay Protocol) implementation.

Added SIP state machines to set up a file transfer session.

Added a method to SdpHeaderA to get filename/size/hash/type from the file
selector attribute in the A header.

The above code is not enabled unless libminisip is configured 
with "--enable-msrp". (this first commit will probably fail if msrp is not
enabled).






Modified: trunk/libminisip/Makefile.am
===================================================================
--- trunk/libminisip/Makefile.am	2007-06-26 12:46:59 UTC (rev 3334)
+++ trunk/libminisip/Makefile.am	2007-06-27 08:50:22 UTC (rev 3335)
@@ -102,6 +102,13 @@
 			source/subsystem_signaling/p2t/P2T.cxx
 endif
 
+libmsrp_src = 
+if MSRP_SUPPORT
+libmsrp_src = source/subsystem_media/msrp/MSRPMessage.cxx \
+ 			source/subsystem_media/msrp/MSRPMessage.h 
+endif
+
+
 if ZRTP_SUPPORT
 libzrtp_src = source/subsystem_media/zrtp/ZrtpHostBridgeMinisip.cxx
 endif
@@ -135,6 +142,7 @@
 		source/subsystem_signaling/sdp/SdpHeader.cxx \
 		source/subsystem_signaling/sdp/SdpHeaderA.cxx \
 		source/subsystem_signaling/sdp/SdpHeaderC.cxx \
+		source/subsystem_signaling/sdp/SdpHeaderI.cxx \
 		source/subsystem_signaling/sdp/SdpHeaderM.cxx \
 		source/subsystem_signaling/sdp/SdpHeaderO.cxx \
 		source/subsystem_signaling/sdp/SdpHeaderS.cxx \
@@ -147,6 +155,10 @@
 		source/subsystem_signaling/sip/SipDialogConfVoip.cxx \
 		source/subsystem_signaling/sip/SipDialogPresenceClient.cxx \
 		source/subsystem_signaling/sip/SipDialogPresenceServer.cxx \
+		source/subsystem_signaling/sip/SipDialogFileTransferClient.cxx \
+		source/subsystem_signaling/sip/SipDialogFileTransferClient.h \
+		source/subsystem_signaling/sip/SipDialogFileTransferServer.cxx \
+		source/subsystem_signaling/sip/SipDialogFileTransferServer.h \
 		source/subsystem_signaling/sip/SipSoftPhoneConfiguration.cxx \
 		source/subsystem_signaling/sip/DefaultDialogHandler.cxx \
 		source/subsystem_signaling/sip/PresenceMessageContent.cxx \
@@ -410,6 +422,7 @@
 			$(libmediahandler_src) \
 			$(libp2t_src) \
 			$(librtp_src) \
+			$(libmsrp_src) \
 			$(libzrtp_src) \
 			$(libsdp_src) \
 			$(libsoundcard_src) \

Modified: trunk/libminisip/configure.ac
===================================================================
--- trunk/libminisip/configure.ac	2007-06-26 12:46:59 UTC (rev 3334)
+++ trunk/libminisip/configure.ac	2007-06-27 08:50:22 UTC (rev 3335)
@@ -143,6 +143,18 @@
 AM_CONDITIONAL(HAS_GSM, test "${HAS_GSM}" = "yes")
 AC_SUBST(GSM_LIBS)
 
+dnl MSRP support
+AC_ARG_ENABLE(msrp,
+    AS_HELP_STRING([--enable-msrp],
+		   [enable MSRP file transfer protocol (default disabled)]),
+    [  if test "${enable_msrp}" = "yes"
+       then
+	   AC_DEFINE(MSRP_SUPPORT, [], [MSRP support])
+       fi ])
+AM_CONDITIONAL(MSRP_SUPPORT, test "${enable_msrp}" = "yes")
+
+
+
 dnl
 dnl PortAudio V19 support
 dnl

Modified: trunk/libminisip/include/Makefile.am
===================================================================
--- trunk/libminisip/include/Makefile.am	2007-06-26 12:46:59 UTC (rev 3334)
+++ trunk/libminisip/include/Makefile.am	2007-06-27 08:50:22 UTC (rev 3335)
@@ -58,6 +58,7 @@
 			libminisip/signaling/sdp/SdpHeader.h \
 			libminisip/signaling/sdp/SdpHeaderA.h \
 			libminisip/signaling/sdp/SdpHeaderC.h \
+			libminisip/signaling/sdp/SdpHeaderI.h \
 			libminisip/signaling/sdp/SdpHeaderM.h \
 			libminisip/signaling/sdp/SdpHeaderO.h \
 			libminisip/signaling/sdp/SdpPacket.h \

Modified: trunk/libminisip/include/libminisip/signaling/sdp/SdpHeader.h
===================================================================
--- trunk/libminisip/include/libminisip/signaling/sdp/SdpHeader.h	2007-06-26 12:46:59 UTC (rev 3334)
+++ trunk/libminisip/include/libminisip/signaling/sdp/SdpHeader.h	2007-06-27 08:50:22 UTC (rev 3335)
@@ -45,6 +45,7 @@
 #define SDP_HEADER_TYPE_S	4
 #define SDP_HEADER_TYPE_T	5
 #define SDP_HEADER_TYPE_V	6
+#define SDP_HEADER_TYPE_I	7
 
 #include<string>
 

Modified: trunk/libminisip/include/libminisip/signaling/sdp/SdpHeaderA.h
===================================================================
--- trunk/libminisip/include/libminisip/signaling/sdp/SdpHeaderA.h	2007-06-26 12:46:59 UTC (rev 3334)
+++ trunk/libminisip/include/libminisip/signaling/sdp/SdpHeaderA.h	2007-06-27 08:50:22 UTC (rev 3335)
@@ -52,8 +52,21 @@
 		std::string getAttributeType();
 		std::string getAttributeValue();
 
+		void getAttFromFileSelector();
+		
 		std::string getRtpMap(int format);
 
+		bool name;
+		bool type;
+		bool size;
+		bool hash;
+		
+		std::string filename;
+		std::string filetype;
+		std::string filesizes;
+		std::string hashused;
+		std::string hashforfile;
+
 	private:
 		std::string attributes;
 

Added: trunk/libminisip/source/subsystem_media/msrp/MSRPMessage.cxx
===================================================================
--- trunk/libminisip/source/subsystem_media/msrp/MSRPMessage.cxx	                        (rev 0)
+++ trunk/libminisip/source/subsystem_media/msrp/MSRPMessage.cxx	2007-06-27 08:50:22 UTC (rev 3335)
@@ -0,0 +1,487 @@
+
+//	#ifndef MSRPMessage_h
+//	#define MSRPMessage_h
+
+#include<libmutil/minilist.h>
+#include<libmutil/MemObject.h>
+#include<libmnetutil/Socket.h>
+#include<libmnetutil/ServerSocket.h>
+#include<libmnetutil/TCPSocket.h>
+#include<libmnetutil/NetworkException.h>
+#include<libmutil/CommandString.h>
+#include<libmutil/Thread.h>
+
+#include<list>
+#include<fstream>
+#include<iostream>
+#include<string>
+
+#include<sys/types.h>
+#include<netinet/in.h>
+
+#include"../../subsystem_media/msrp/MSRPMessage.h"
+
+#define SERVER_PORT 3333
+
+using namespace std;
+
+char chunk[1024];
+int chunkSize;
+char * byterange = "";
+
+string first;
+string second;
+string last;
+
+/*class MSRPMessage : public MObject{
+
+	public:
+		//MSRPMessage(TCPSocket *sock);
+		//MSRPMessage(char * buf, int buflenght);
+		
+		//virtual std::string getstring() const = 0;
+		
+		//char * chunk;
+		int lenght;
+
+};
+
+class MSRPHeader : public MObject{
+
+	public:
+		string attrib;
+		string val;
+
+		MSRPHeader(char *name, char *value){
+			attrib = name;
+			val = value;
+		}
+
+		string getString(){
+			return (attrib+val);
+		}
+};
+
+class MSRPMessageSend : public MSRPMessage{
+
+	public:
+		MSRPMessageSend(char * chunk, int chunklenght);
+		//MSRPMessageSend(TCPSocket * sock);
+		char * CreateMSRPSend(int &outlength);
+		string UpdateByteRange();
+		bool PutLastLine();
+};
+
+class MSRPMessageReport : public MSRPMessage{
+
+	public:
+		MSRPMessageReport(char * chunk, int chunklenght);
+		MSRPMessageReport(TCPSocket * sock);
+		string CreateMSRPReport();
+};
+
+class MSRPSender : public MObject{
+	
+	public:
+		MSRPSender(int argc, char **argv);
+		void setchunk();
+	
+		int BytesSet;
+		//int BytesLeft;
+		//int chunkSize;
+		int BytesIndex;
+		int BytesTotal;
+		
+		ifstream myfile;
+		string string_msg;
+
+		char * getStrMsg ( int outlenght);
+};
+*/
+
+MSRPSender::MSRPSender(const string Addr, int32_t Port, const string name, MRef<SipStack*>sipStack, const string callId){
+	sAddr = Addr;
+	sPort = Port;
+	fName = name;
+	sipstack = sipStack;
+	callid = callId;
+}
+
+void MSRPSender::run(){
+	cerr <<"MAFE: MSRPSender::run() started"<<endl;
+
+	string from_server;
+
+	int num_chunks;
+	TCPSocket *sock=NULL;
+	char report_rec[1000];
+	char * msg;
+	int pktLen=0;
+	//ifstream myfile;
+		
+	cerr <<"MAFE: creating socket, sAddr=<"<<sAddr<<"> and sPort=" << sPort << endl;
+	 try{	
+		sock = new TCPSocket(sAddr, sPort);
+		cerr << "MY IP ADDRESS IS "<< sock->getLocalAddress()->getString()<<endl;
+		
+	}catch(ConnectFailed &){
+	       	cerr << "Sorry, I could not connect to port "<< sPort << " on the server." << endl;
+		return;
+	
+	}catch(HostNotFound &){
+		cerr << "Sorry, the server <"<< sAddr<<"> could not be found"<< endl;
+		return;
+	}
+		
+	//cerr <<"MAFE: opening file..."<<endl;
+	myfile.open(fName.c_str(), ios::in|ios::binary|ios::ate);
+	if (myfile.is_open()){
+
+		cerr << "file open correctly" << endl;
+
+		//get size of file
+		myfile.seekg(0, ifstream::end);
+		int filesize = myfile.tellg();
+		myfile.seekg(0);
+
+		num_chunks = filesize/1024;
+
+		cerr <<"Filesize is "<<filesize<<endl;
+		//cerr <<num_chunks<<endl;
+
+		string brange;
+
+		if(num_chunks == 0){
+			brange = "1-"+itoa(filesize)+"/"+itoa(filesize);
+			byterange=(char*)brange.c_str();
+		}
+		else{
+			brange = "1-1024/"+itoa(filesize);
+			byterange=(char*) brange.c_str();
+		}
+		//cerr<<"Byte range is "<<byterange<<endl;
+
+		if(filesize%1024!=0)
+			num_chunks=num_chunks+1;
+
+		while(num_chunks !=0){
+
+			num_chunks--;
+			setchunk();
+
+			cerr<<"number of chunks "<<num_chunks<<endl;
+
+			MSRPMessageSend new_msg(chunk, chunkSize);
+			//cerr<<"MAFE:  created new object... "<<endl;
+			msg = new_msg.CreateMSRPSend(pktLen);
+			cerr<<"MAFE:     MSRPMessage created! "<<endl;
+
+			//int aux = htonl(chunkSize);
+			if (sock==NULL)
+				cerr<<"MAFE: socket is NULL"<<endl;
+			//int sendtam=sock->write((char*)&aux,sizeof(chunkSize));
+
+			cerr <<"will send " << pktLen<< " bytes"<<endl;
+			assert(sock);
+
+			int nsent=sock->write(msg, pktLen);
+
+			//cerr<<msg<<endl;
+			cerr <<"EEEEEEEEEEEEE: sent "<< nsent<<" bytes"<<endl; 
+
+			//int reprec = sock->read(report_rec, 1024);
+
+			//report_rec[reprec]=0;
+			//from_server=trim(string(report_rec));
+
+			//cerr<<"receiving "<<reprec<< " bytes"<<endl;
+			//cerr<<report_rec<<endl;
+
+			//string byterange = new_msg.UpdateByteRange();
+		}
+		
+		//int aux = htonl(0);
+		//int lastsent=sock->write((char*)&aux, sizeof(int));
+
+		//finalstring = sock->write("server quit", 12);
+		//cerr<<"final de fichero"<<finalstring<<endl;
+	}
+	CommandString cmd(callid, "MSRP_DONE");
+	sipstack->handleCommand(cmd);
+	
+	//cerr <<"MAFE: server shutting down..."<<endl;
+}
+			
+void MSRPSender::setchunk(){
+	
+//	ifstream myfile;
+
+	chunkSize = myfile.readsome(chunk, 1024);
+	//BytesSet += chunkSize;
+	//BytesIndex += BytesSet;
+	cerr << "Read " << chunkSize <<" bytes" << endl; 
+}
+
+MSRPReceiver::MSRPReceiver(const string fileName, int fileSize){
+	name = fileName;
+	sizercv = fileSize;
+}
+
+void MSRPReceiver::run(){
+
+	cerr <<"MAFE: MSRPReceiver::run() started on port "<< SERVER_PORT << endl;
+	//cerr<<"receiver before ssock"<<endl;
+
+	MRef<ServerSocket*> ssock = ServerSocket::create(SERVER_PORT);
+	//cerr << "MY IP ADDRESS IS "<< ssock->getLocalAddress()->getString()<<endl;
+
+	//cerr<<"receiver after ssock"<<endl;
+	
+	string from_client;
+	string new_chunk;
+	
+	string string_rep;
+	
+	char * loc;
+	char * loc2;
+	int j;
+	int lng;
+	int lngchunk;
+
+	ofstream SaveFile(name.c_str(), ios::trunc);  //get filename from SDP msg
+
+	cerr <<"waiting for client"<<endl;
+	MRef<StreamSocket*> client_sock = ssock->accept();
+	cerr <<"client connected"<<endl;
+	
+	cerr<<"size of file"<<sizercv<<endl;
+
+	int aux;
+	char receive_buf [10000];
+	char chunk_buffer_prov[1024];
+	int i;
+	//int rectam = client_sock->read((char*)&aux,sizeof(int));
+	//lng = ntohl(aux);
+
+	int chunkRcv = sizercv/1024;
+	if( (aux=sizercv%1024) !=0 )
+		chunkRcv=chunkRcv+1;
+
+	do{
+		cerr <<"chunks "<<chunkRcv<<endl;	
+		//cerr<<"sizeblock"<<lng<<endl;
+		//if(chunkRcv>0){
+
+			int nrecv = client_sock->read(receive_buf,10000);
+			cerr <<"EEEEEEEEEEEEEEEE: read "<< nrecv <<" bytes."<<endl;
+		
+			//cerr<<"buffer recibido "<<receive_buf<<endl;
+			
+			//receive_buf[nrecv]=0;				//it makes sure that this is a null-terminated string
+			//from_client=trim(string(receive_buf)); 		//trim away any leading or trailing whitespace
+		
+			loc = strstr(receive_buf,"Content-Type: ");
+			//loc2 = strstr(receive_buf, "-------");
+			
+			cerr<<"localizador del content type: "<<loc<<endl;
+
+			while(*loc != '\n'){
+				loc++;
+			}
+			if(chunkRcv>1){
+			for(j=0; j!=1024; j++){
+				chunk_buffer_prov[j]=*loc;
+				loc++;
+			}	
+			cerr<<"buffer provisional "<<chunk_buffer_prov<<endl;
+			SaveFile.write(chunk_buffer_prov,1024);
+			}
+			else{
+				for(j=0; j!=aux; j++){
+				chunk_buffer_prov[j]=*loc;
+				loc++;
+			}	
+			cerr<<"buffer provisional "<<chunk_buffer_prov<<endl;
+			SaveFile.write(chunk_buffer_prov,aux);
+			}
+
+	
+			//MSRPMessageReport new_rep(chunk_buffer_prov,lng);
+			//string_rep = new_rep.CreateMSRPReport();
+			//cerr<<"MAFE: Report created: "<<string_rep<<endl;
+			chunkRcv--;
+			//client_sock->write(string_rep.c_str(), string_rep.length());
+			//cerr<<"after write report"<<endl;
+		//}else;
+	}while(chunkRcv>0);
+}
+
+MSRPMessageSend::MSRPMessageSend(char * data, int len){
+
+	//mChunk = data;
+	//mChunkLength = len;
+}
+
+char* MSRPMessageSend::CreateMSRPSend(int& bufferSize){
+
+	list<MSRPHeader> hsend;
+	
+	char *nametemp;
+	char *valuetemp;
+	MSRPHeader temp(nametemp,valuetemp);
+	
+	string transc_id ="num_transc";
+	string first_line = "MSRP "+transc_id+" SEND\n";
+	string last_line= "";
+	string hdr = "";
+	string newbyterange;
+
+	MSRPMessageSend m(chunk,chunkSize);
+	
+	bool several_chunks=m.PutLastLine();
+	
+	if(several_chunks == true){
+		
+		last_line = "-------"+transc_id+"+";
+		newbyterange =m.UpdateByteRange();
+	}
+	else{	
+		last_line = "-------"+transc_id+"$";
+		newbyterange = byterange;
+	}
+	
+	hsend.push_back(MSRPHeader("To-Path: ","ToUri"));
+	hsend.push_back(MSRPHeader("From-Path: ","FromUri"));
+	hsend.push_back(MSRPHeader("Message-ID: ","messageID"));
+	hsend.push_back(MSRPHeader("Byte-Range: ",(char*)newbyterange.c_str()));
+	hsend.push_back(MSRPHeader("Failure-Report: ","failrep"));
+	hsend.push_back(MSRPHeader("Success-Report: ","succrep"));
+	hsend.push_back(MSRPHeader("Content-Type: ","contenttype"));
+
+	list<MSRPHeader>::iterator h = hsend.begin();
+
+	while(h != hsend.end()){
+		temp = *h;
+		hdr = hdr + temp.getString();
+		hdr = hdr + "\n";
+		h++;
+	}
+	hdr += "\n";
+
+	//cerr<<newbyterange<<endl;
+
+	//string all = first_line + hdr + chunk + last_line;
+	
+	string first= first_line+hdr;
+	
+	cerr<<"MAFE: allocating "<<first.size()+chunkSize+last_line.size()<<" bytes"<<endl;
+	char *pkt = (char*)malloc(first.size()+chunkSize +last_line.size());
+	
+	cerr<<"MAFE: memcpy1"<<endl;
+	memcpy(pkt, first.c_str(), first.size());
+	pkt = pkt+first.size();
+	cerr<<"MAFE: memcpy2"<<endl;
+	memcpy(pkt, chunk, chunkSize);
+	pkt = pkt+chunkSize;
+	cerr<<"MAFE: memcpy3"<<endl;
+	memcpy(pkt, last_line.c_str(), last_line.size());
+	cerr<<"MAFE: memcpy3 done"<<endl;
+	pkt = pkt - (chunkSize + first.size());
+
+	bufferSize=first.size()+chunkSize+last_line.size();
+	//cerr<<"MsrpMessage is: "<<pkt<<endl;
+
+	return pkt;
+}
+
+bool MSRPMessageSend::PutLastLine(){
+
+	bool sev_chunk_bool;
+	int i=0;
+	int sec;
+	first = "";
+	second = "";
+	last = "";
+	
+	//cerr<<byterange<<endl;
+	
+	string rangehere;
+	rangehere = byterange;
+
+	do{
+		first = first + byterange[i];
+		i++;
+	}while(byterange[i] != '-');
+	i++;
+
+	for(byterange[i] != '-'; byterange[i] != '/'; i++){
+		second = second + byterange[i];
+	}
+	i++;
+
+	for(byterange[i] != '/'; i<rangehere.length(); i++){
+		last = last + byterange[i];
+	}
+
+	if(second == last)
+		sev_chunk_bool = false;
+	else
+		sev_chunk_bool = true;
+	
+	//cerr<<sev_chunk_bool<<endl;
+	return(sev_chunk_bool);
+}
+
+string MSRPMessageSend::UpdateByteRange(){
+
+	string updbyterange;
+	int one;
+	int two;
+	
+	MSRPMessageSend m(chunk,chunkSize);
+		
+	one = atoi(first.c_str());
+	two = atoi(second.c_str());
+	
+	one = two + 1;
+	two = one + 1024;
+	
+	string strone = itoa(one);
+	string strtwo = itoa(two);
+	
+	updbyterange = strone+"-"+strtwo+"/"+last;
+		
+	//cerr<<updbyterange<<endl;
+	return(updbyterange);
+}
+
+MSRPMessageReport::MSRPMessageReport(char * chunk, int chunklenght){}
+
+string MSRPMessageReport::CreateMSRPReport(){
+
+	list<MSRPHeader> hreport;
+	
+	string transc_id = "numID";
+
+	string first_line = "MSRP "+transc_id+" REPORT\n";
+	string last_line = "-------"+transc_id+"$";
+
+	string hdrep;
+
+	hreport.push_back(MSRPHeader("To-Path: ","ToUri"));
+	hreport.push_back(MSRPHeader("From-Path: ","FromUri"));
+	hreport.push_back(MSRPHeader("Message-ID: ","messageID"));
+	hreport.push_back(MSRPHeader("Byte-Range: ","byterange"));
+	hreport.push_back(MSRPHeader("Status: ","status"));
+
+	list<MSRPHeader>::iterator hr = hreport.begin();
+		hdrep = hdrep + (*hr).getString();
+		hdrep = hdrep + "\n";
+		hdrep = hdrep + (*hr).getString();
+		hdrep = hdrep + "\n";
+		hr++;
+
+	string all = first_line + hdrep + last_line;
+	return(all);
+}
+

Added: trunk/libminisip/source/subsystem_media/msrp/MSRPMessage.h
===================================================================
--- trunk/libminisip/source/subsystem_media/msrp/MSRPMessage.h	                        (rev 0)
+++ trunk/libminisip/source/subsystem_media/msrp/MSRPMessage.h	2007-06-27 08:50:22 UTC (rev 3335)
@@ -0,0 +1,123 @@
+
+#ifndef MSRPMessage_H
+#define MSRPMessage_H
+
+#include<libmutil/minilist.h>
+#include<libmutil/MemObject.h>
+#include<libmnetutil/Socket.h>
+#include<libmnetutil/TCPSocket.h>
+#include<libmnetutil/ServerSocket.h>
+#include<libmnetutil/NetworkException.h>
+#include<libmutil/CommandString.h>
+#include<libmutil/Thread.h>
+
+#include<libmsip/SipStack.h>
+
+#include<list>
+#include<fstream>
+#include<iostream>
+#include<string>
+
+#define SERVER_PORT 3333
+
+using namespace std;
+
+class MSRPMessage : public MObject{
+
+	public:
+		//MSRPMessage(TCPSocket *sock);
+		//MSRPMessage(char * buf, int buflenght);
+		
+		//virtual std::string getstring() const = 0;
+		
+		//char * chunk;
+		int lenght;
+};
+
+class MSRPHeader : public MObject{
+
+	public:
+		string attrib;
+		string val;
+		
+		MSRPHeader(char* name, char* value){
+			attrib = name;
+			val = value;
+		}
+
+		string getString(){
+			return (attrib+val);
+		}
+};
+
+class MSRPMessageSend : public MSRPMessage{
+
+	public:
+		MSRPMessageSend(char * chunk, int chunklength);
+		
+		//virtual ~MSRPMessageSend();
+
+		//MSRPMessageSend(TCPSocket * sock);
+		char * CreateMSRPSend(int &outlength);
+		//string CreateMSRPSend();
+		string UpdateByteRange();
+		bool PutLastLine();
+/*	
+	private:
+		char * mChunk;
+		int mChunkLength;*/
+};
+
+class MSRPMessageReport : public MSRPMessage{
+
+	public:
+		MSRPMessageReport(char * chunk, int chunklenght);
+		MSRPMessageReport(TCPSocket * sock);
+		string CreateMSRPReport();
+
+		//string getString(){
+		//	return "test";
+		//}
+};
+
+class MSRPSender : public Runnable{
+	
+	public:
+		MSRPSender(const std::string serverAddr, int32_t serverPort, const std::string nameOfFile, MRef<SipStack*> stack, const std::string callId);
+					
+		//virtual ~MSRPSender();
+
+		void run();
+		void setchunk();
+
+		int BytesSet;
+		int BytesLeft;
+		int BytesIndex;
+		int BytesTotal;
+		
+		ifstream myfile;
+		string string_msg;
+		string filetosend;		
+		
+	private:
+		//char chunk[8];
+
+		string sAddr;
+		string fName;
+		int32_t sPort;
+		MRef<SipStack*> sipstack;
+		string callid;
+};
+
+class MSRPReceiver : public Runnable{
+
+	public:
+		MSRPReceiver(const std::string filename, int file_size);
+		void run();	
+	private:
+		char chunk[1024];
+		string name;
+		int sizercv;
+};
+
+#endif

Added: trunk/libminisip/source/subsystem_media/msrp/MSRPReceiver.cxx
===================================================================
--- trunk/libminisip/source/subsystem_media/msrp/MSRPReceiver.cxx	                        (rev 0)
+++ trunk/libminisip/source/subsystem_media/msrp/MSRPReceiver.cxx	2007-06-27 08:50:22 UTC (rev 3335)
@@ -0,0 +1,58 @@
+// MSRPReceiver.cxx
+
+#include<libmnetutil/ServerSocket.h> 
+#include<libmutil/stringutils.h>  //removes whitespace from start and end of strings
+
+#include"../../subsystem_media/msrp/MSRPReceiver.h"
+
+#define SERVER_PORT 3333   //This defines the port number that the server will open
+
+using namespace std;
+
+void MSRPReceiver::run(){
+
+	//Creating a server socket
+	
+	//MRef<IP4ServerSocket*> ssock = new IP4ServerSocket(SERVER_PORT);
+	MRef<ServerSocket*> ssock = ServerSocket::create(SERVER_PORT);;
+
+	//string from_client;
+	//char transc_id_recv[8];
+	int i=0;
+	int j;
+	//char first_line_recv[];
+	//char last_line_recv[];
+
+	//list<MSRPHeader> header_recvs;
+	
+	//MSRPMessage M_get;
+	
+	//MSRPMessageReport M_Report;
+
+	MRef<StreamSocket *> client_sock = ssock->accept();
+		
+	do{
+		//Receive a chunk of data from client
+	
+		client_sock.read(first_line_recv, 18);
+		
+		if(first_line_recv[14] == "S" && first_line_recv[15] == "E" && first_line_recv[16] == "N" && first_line_recv[17] == "D"){
+		
+			for( i=5; i<13, i++ ){
+				transc_id_recv[j]==first_line_recv[i];
+			}
+
+		}
+		
+		for( i=0; i<8; i++)
+		client_sock.read(header_recvs[i], sizeof(header_recvs));
+
+		M_get.getchunk(client_sock);
+		
+		M_Report.CreateMSRPReport(M_get.received_chunk, sizeof(M_get.received_chunk));
+
+		client_sock.read(last_line_recv, 16);
+
+	}while(last_line_recv[15]=="+");
+
+}

Added: trunk/libminisip/source/subsystem_media/msrp/MSRPSender.cxx
===================================================================
--- trunk/libminisip/source/subsystem_media/msrp/MSRPSender.cxx	                        (rev 0)
+++ trunk/libminisip/source/subsystem_media/msrp/MSRPSender.cxx	2007-06-27 08:50:22 UTC (rev 3335)
@@ -0,0 +1,68 @@
+MSRPSender.cxx */
+#include<libmnetutil/TCPSocket.h> 
+
+#include<libmnetutil/NetworkException.h> //ConnectFailed && HostNotFound
+#include<libmutil/trim.h>  //removes whitespace from start and end of strings
+
+#include <iostream>
+#include <fstream>
+
+#include"../../subsystem_media/msrp/MSRPSender.h"
+#include"../../subsystem_media/msrp/MSRPMessage.h"
+
+using namespace std;
+
+void MSRPSender::run(){
+	cerr <<"MAFE: MSRPSender::run() started"<<endl;
+	
+	MRef<MSRPSender*> msrpSender;
+	//= new MSRPSender*(const string serverAdd, int32_t serverPort, const string filename);
+	//char new_chunk[] = "";	
+	//ifstream myfile;
+	MRef<MSRPMessageSend*> M_Send;
+
+	/*if (argc!=4){
+		return 1;
+	}
+	else{*/
+
+//-------if (no TCPSocket open between offerer and answerer) { --> verify with the URI received by SIP messages.
+
+	TCPSocket *sock;
+	try{
+		//Create a TCP connection to the server (address and port given
+		//as arguments to the application).
+		sock = new TCPSocket(msrpSender->serverAdd, msrpSender->serverPort);
+	}catch(ConnectFailed &){
+		cerr << "Sorry, I could not connect to port "<< msrpSender.serverPort << " on the server." << endl;
+		return -3;
+	
+	}catch(HostNotFound &){
+		cerr << "Sorry, the server <"<< msrpSender.serverAdd<<"> could not be found"<< endl;
+		return -3;
+	}
+//-----	} else;
+
+	myfile.open(filetosend,ios::in|ios::binary|ios::ate);
+	if (myfile.is_open()) 
+	{
+		while( !myfile.eof() )
+		{
+			while(M_Send.BytesLeft != 0)
+			{
+				 M_Send.CreateMSRPSend(setchunk.set_chunk, sizeof(setchunk.set_chunk));
+
+					// ToDo Receive_Report;
+				 }
+				else;
+
+				// error detect. with Report -->cerr << "Sorry, chunk not received correctly, trying again" << endl;
+
+			}
+		}
+	}
+	else
+		cerr << "Unable to open file" << endl;
+		
+	sock->close();
+}

Modified: trunk/libminisip/source/subsystem_signaling/sdp/SdpHeaderA.cxx
===================================================================
--- trunk/libminisip/source/subsystem_signaling/sdp/SdpHeaderA.cxx	2007-06-26 12:46:59 UTC (rev 3334)
+++ trunk/libminisip/source/subsystem_signaling/sdp/SdpHeaderA.cxx	2007-06-27 08:50:22 UTC (rev 3335)
@@ -39,7 +39,7 @@
 
 using namespace std;
 
-SdpHeaderA::SdpHeaderA(string buildFrom) : SdpHeader(SDP_HEADER_TYPE_A, 9){
+SdpHeaderA::SdpHeaderA(string buildFrom) : SdpHeader(SDP_HEADER_TYPE_A, 10){
 	massert(buildFrom.substr(0,2)=="a=");
 	attributes= trim(buildFrom.substr(2, buildFrom.length()-2));
 }
@@ -67,6 +67,82 @@
 	return attributes.substr( 0, pos );
 }
 
+void SdpHeaderA::getAttFromFileSelector(){
+	size_t pos;
+	size_t pos2;
+	
+	name = false;
+	type = false;
+	size = false;
+	hash = false;
+	
+	pos=14;
+	pos2=14;
+	
+	int searchname;
+	int searchtype;
+	int searchsize;
+	int poshash;
+	int iter;
+	int counter=0;
+
+	for(iter=15; iter<strlen(attributes.c_str()); iter++){
+		if(attributes[iter] == ':')
+			counter++;
+	}
+	//cerr<<counter<<endl;
+
+	while(counter!=1){
+		
+		counter --;
+		pos2 = attributes.find( ":",pos);
+		
+		//cerr<<pos2<<endl;
+		
+		pos= pos2-4;
+
+		//cerr<<( attributes.substr(pos, 4) )<<endl;
+
+		if( attributes.substr(pos, 4) == "name"){
+			name = true;
+			searchname = attributes.find('"',pos2+2);
+			//cerr<<searchname<<endl;
+			filename = ( attributes.substr(pos2+2,(searchname-pos2-2)) );
+			//cerr<<filename<<endl;
+		}	
+		else;
+		if( attributes.substr(pos, 4) == "type"){
+			type = true;
+			searchtype = attributes.find(" ",pos2);
+			//cerr<<searchtype<<endl;
+			filetype = ( attributes.substr(pos2+1,(searchtype-pos2)) );
+			//cerr<<filetype<<endl;
+		}
+		else;
+		if( attributes.substr(pos, 4) == "size"){
+			size = true;
+			searchsize = attributes.find(" ", pos2);
+			//cerr<<searchsize<<endl;
+			filesizes = ( attributes.substr(pos2+1,(searchsize-pos2)) );
+			//cerr<<filesizes<<endl;
+		}	
+		else;
+		if( attributes.substr(pos, 4) == "hash"){
+			hash = true;
+			poshash = attributes.find( ":", pos2+1);
+			hashused = ( attributes.substr(pos2+1,poshash-pos2-1));
+			hashforfile = ( attributes.substr(poshash+1,(strlen(attributes.c_str())-poshash)) );
+			//cerr<<"used hash "<<hashused<<endl;
+			//cerr<<"hash "<<hashforfile<<endl;
+		}
+		else;
+	
+		pos2++;
+		pos = pos2;
+	}
+}
+
+
 string SdpHeaderA::getAttributeValue(){
 	if( getAttributeType() == "property" )
 		return attributes;
@@ -79,3 +155,4 @@
 	return attributes.substr( pos + 1, attributes.length() - 2 );
 }
 
+

Modified: trunk/libminisip/source/subsystem_signaling/sdp/SdpPacket.cxx
===================================================================
--- trunk/libminisip/source/subsystem_signaling/sdp/SdpPacket.cxx	2007-06-26 12:46:59 UTC (rev 3334)
+++ trunk/libminisip/source/subsystem_signaling/sdp/SdpPacket.cxx	2007-06-27 08:50:22 UTC (rev 3335)
@@ -44,8 +44,8 @@
 #include<libminisip/signaling/sdp/SdpHeaderT.h>
 #include<libminisip/signaling/sdp/SdpHeaderM.h>
 #include<libminisip/signaling/sdp/SdpHeaderA.h>
+#include<libminisip/signaling/sdp/SdpHeaderI.h>
 
-
 #include<iostream>
 #include<sys/types.h>
 
@@ -75,6 +75,9 @@
 			case 's':
 				addHeader(MRef<SdpHeader*>(new SdpHeaderS(lines[i])));
 				break;
+			case 'i':
+				addHeader(MRef<SdpHeader*>(new SdpHeaderI(lines[i])));
+				break;
 			case 'c':{
 				MRef<SdpHeaderC*> c = new SdpHeaderC(lines[i]);
 				if( lastM )

Modified: trunk/libminisip/source/subsystem_signaling/sip/DefaultDialogHandler.cxx
===================================================================
--- trunk/libminisip/source/subsystem_signaling/sip/DefaultDialogHandler.cxx	2007-06-26 12:46:59 UTC (rev 3334)
+++ trunk/libminisip/source/subsystem_signaling/sip/DefaultDialogHandler.cxx	2007-06-27 08:50:22 UTC (rev 3335)
@@ -47,6 +47,8 @@
 #include<libminisip/signaling/sip/SipDialogConfVoip.h>
 #include<libminisip/signaling/sip/SipDialogPresenceClient.h>
 #include<libminisip/signaling/sip/SipDialogPresenceServer.h>
+#include"SipDialogFileTransferClient.h"
+#include"SipDialogFileTransferServer.h"
 #include<libminisip/signaling/conference/ConfMessageRouter.h>
 
 #ifdef _WIN32_WCE
@@ -224,35 +226,37 @@
 
 			sipStack->enqueueCommand(cmd, HIGH_PRIO_QUEUE );
 			mdbg("signaling/sip") << cmd << endl;
-		}
-		//start SipDialogVoIP
-		else{
-			MRef<SipIdentity *> id = lookupTarget(inv->getUri());
+		}else{
+			//...extract something you need for the test...
+			if  (/*invite contains file transfer session*/ true){
 
-			// get a session from the mediaHandler
-			MRef<Session *> mediaSession = 
-				mediaHandler->createSession(/*phoneconf->securityConfig*/ id, pkt->getCallId() );
+				MRef<SipIdentity *> id = lookupTarget(inv->getUri());
+				cerr << "MAFE: creating file transfer server"<<endl;
 
-/*			MRef<SipDialogConfig*> callConf = new SipDialogConfig(phoneconf->inherited);
+				MRef<SipDialog *> ftransf = new SipDialogFileTransferServer(sipStack, phoneconf, id, phoneconf, pkt->getCallId() );
+				sipStack->addDialog( ftransf );
+				SipSMCommand cmd(pkt, SipSMCommand::transaction_layer, SipSMCommand::dialog_layer);
+				sipStack->enqueueCommand(cmd, HIGH_PRIO_QUEUE );
+			}else{
+				MRef<SipIdentity *> id = lookupTarget(inv->getUri());
 
-			if( id ){
-				cerr << "Got a call from Id " << id->getSipUri() << endl;
-				callConf->useIdentity( id );
-			}
-*/
-			MRef<SipDialog*> voipCall;
+				// get a session from the mediaHandler
+				MRef<Session *> mediaSession = 
+					mediaHandler->createSession(/*phoneconf->securityConfig*/ id, pkt->getCallId() );
+
+				MRef<SipDialog*> voipCall;
 				voipCall = new SipDialogVoipServer(sipStack,
 						id,
 						phoneconf,
 						mediaSession,
 						pkt->getCallId());
-			sipStack->addDialog(voipCall);
+				sipStack->addDialog(voipCall);
 
 
-			SipSMCommand cmd(pkt, SipSMCommand::transaction_layer, SipSMCommand::dialog_layer);
-
-			sipStack->enqueueCommand(cmd, HIGH_PRIO_QUEUE );
-			mdbg("signaling/sip") << cmd << endl;
+				SipSMCommand cmd(pkt, SipSMCommand::transaction_layer, SipSMCommand::dialog_layer);
+				sipStack->enqueueCommand(cmd, HIGH_PRIO_QUEUE );
+				mdbg("signaling/sip") << cmd << endl;
+			}
 		}
 		return true;
 	}
@@ -337,6 +341,25 @@
 
 		return true;
 	}
+
+
+	if (cmdstr.getOp() == "start_filetransfer"){
+		cerr << "DefaultDialogHandler: Creating SipDialogFileTransferClient for start_filetransfer_client command"<< endl;
+		
+//		MRef<SipDialogConfig*> conf = new SipDialogConfig(phoneconf->inherited);
+
+		MRef<SipDialogFileTransferClient*> pres(new SipDialogFileTransferClient(sipStack, phoneconf, phoneconf->defaultIdentity, phoneconf->useSTUN ));
+
+		sipStack->addDialog( MRef<SipDialog*>(*pres) );
+		
+		CommandString command(cmdstr);
+		cmdstr.setDestinationId(pres->getCallId());
+		SipSMCommand cmd( cmdstr, SipSMCommand::dialog_layer, SipSMCommand::dialog_layer);
+		sipStack->enqueueCommand(cmd, HIGH_PRIO_QUEUE);
+
+		return true;
+	}
+
 	
 	if (cmdstr.getOp() == SipCommandString::start_presence_server){
 		cerr << "DefaultDialogHandler: Creating SipDialogPresenceServer for start_presence_server command"<< endl;

Modified: trunk/libminisip/source/subsystem_signaling/sip/SipDialogVoipServer.cxx
===================================================================
--- trunk/libminisip/source/subsystem_signaling/sip/SipDialogVoipServer.cxx	2007-06-26 12:46:59 UTC (rev 3334)
+++ trunk/libminisip/source/subsystem_signaling/sip/SipDialogVoipServer.cxx	2007-06-27 08:50:22 UTC (rev 3335)
@@ -63,6 +63,8 @@
 
 #ifdef _WIN32_WCE
 #	include"../include/minisip_wce_extra_includes.h"
+#include"../..subsytem_media/msrp/MSRPSender.h"
+
 #endif
 
 using namespace std;



More information about the Minisip-devel mailing list