#include <vector>\r
#include "pthreadwrapper/thread.h"\r
\r
-#define FMS_VERSION "0.2.11"\r
+#define FMS_VERSION "0.2.12"\r
\r
// opens database and creates tables and initial inserts if necessary\r
void SetupDB();\r
void ConvertDB0106To0107();\r
void ConvertDB0107To0108();\r
void ConvertDB0108To0109();\r
+void ConvertDB0109To0110();\r
// inserts default options into the database\r
void SetupDefaultOptions();\r
// opens logfile and sets it up\r
\r
struct fileattachment\r
{\r
- fileattachment(const std::string &filename, const std::vector<unsigned char> &data):m_filename(filename),m_data(data) {}\r
+ fileattachment(const std::string &filename, const std::string &mimetype, const std::vector<unsigned char> &data):m_filename(filename),m_mimetype(mimetype),m_data(data) {}\r
std::string m_filename;\r
+ std::string m_mimetype;\r
std::vector<unsigned char> m_data;\r
};\r
\r
StringFunctions::Convert(idparts[1],fileinsertid);\r
\r
SQLite3DB::Statement st=m_db->Prepare("UPDATE tblFileInserts SET Key=?, Data=NULL WHERE FileInsertID=?;");\r
- st.Bind(0,message["URI"]);\r
+ st.Bind(0,StringFunctions::UriDecode(message["URI"]));\r
st.Bind(1,fileinsertid);\r
st.Step();\r
\r
std::string fileinsertidstr="";\r
std::string sizestr="";\r
std::string filename="";\r
+ std::string mimetype="";\r
int datalen=-1;\r
std::vector<char> data;\r
\r
StringFunctions::Convert(fileinsertid,fileinsertidstr);\r
\r
\r
- SQLite3DB::Statement st=m_db->Prepare("SELECT FileName,Size,Data FROM tblFileInserts WHERE FileInsertID=?;");\r
+ SQLite3DB::Statement st=m_db->Prepare("SELECT FileName,Size,Data,MimeType FROM tblFileInserts WHERE FileInsertID=?;");\r
st.Bind(0,fileinsertid);\r
st.Step();\r
\r
data.resize(datalen,0);\r
st.ResultBlob(2,&data[0],datalen);\r
data.resize(datalen);\r
+ st.ResultText(3,mimetype);\r
\r
StringFunctions::Convert(data.size(),sizestr);\r
\r
message.SetName("ClientPut");\r
message["URI"]="CHK@";\r
message["TargetFilename"]=filename;\r
+ if(mimetype!="")\r
+ {\r
+ message["Metadata.ContentType"]=mimetype;\r
+ }\r
message["Identifier"]=m_fcpuniquename+"|"+fileinsertidstr;\r
message["UploadFrom"]="direct";\r
message["DataLength"]=sizestr;\r
major=1;\r
minor=9;\r
}\r
+ if(major==1 && minor==9)\r
+ {\r
+ ConvertDB0109To0110();\r
+ major=1;\r
+ minor=10;\r
+ }\r
}\r
else\r
{\r
- db->Execute("INSERT INTO tblDBVersion(Major,Minor) VALUES(1,9);");\r
+ db->Execute("INSERT INTO tblDBVersion(Major,Minor) VALUES(1,10);");\r
}\r
\r
- db->Execute("UPDATE tblDBVersion SET Major=1, Minor=9;");\r
+ db->Execute("UPDATE tblDBVersion SET Major=1, Minor=10;");\r
\r
db->Execute("CREATE TABLE IF NOT EXISTS tblOption(\\r
Option TEXT UNIQUE,\\r
FileName TEXT,\\r
Key TEXT,\\r
Size INTEGER,\\r
+ MimeType TEXT,\\r
Data BLOB\\r
);");\r
\r
db->Execute("INSERT INTO tblIdentity(PublicKey,DateAdded,AddedMethod) VALUES('SSK@~mimyB1kmH4f7Cgsd2wM2Qv2NxrZHRMM6IY8~7EWRVQ,fxTKkR0TYhgMYb-vEGAv55sMOxCGD2xhE4ZxWHxdPz4,AQACAAE/','"+date.Format("%Y-%m-%d %H:%M:%S")+"','Initial Identity');");\r
// insert garfield's public key\r
db->Execute("INSERT INTO tblIdentity(PublicKey,DateAdded,AddedMethod) VALUES('SSK@T8l1IEGU4-PoASFzgc2GYhIgRzUvZsKdoQWeuLHuTmM,QLxAPfkGis8l5NafNpSCdbxzXhBlu9WL8svcqJw9Mpo,AQACAAE/','"+date.Format("%Y-%m-%d %H:%M:%S")+"','Initial Identity');");\r
+ // insert alek's public key\r
+ db->Execute("INSERT INTO tblIdentity(PublicKey,DateAdded,AddedMethod) VALUES('SSK@lTjeI6V0lQsktXqaqJ6Iwk4TdsHduQI54rdUpHfhGbg,0oTYfrxxx8OmdU1~60gqpf3781qzEicM4Sz97mJsBM4,AQACAAE/','"+date.Format("%Y-%m-%d %H:%M:%S")+"','Initial Identity');");\r
+ // insert Luke771's public key\r
+ db->Execute("INSERT INTO tblIdentity(PublicKey,DateAdded,AddedMethod) VALUES('SSK@mdXK~ZVlfTZhF1SLBrvZ--i0vOsOpa~w9wv~~psQ-04,gXonsXKc7aexKSO8Gt8Fwre4Qgmmbt2WueO7VzxNKkk,AQACAAE/','"+date.Format("%Y-%m-%d %H:%M:%S")+"','Initial Identity');");\r
+ // insert falafel's public key\r
+ db->Execute("INSERT INTO tblIdentity(PublicKey,DateAdded,AddedMethod) VALUES('SSK@IxVqeqM0LyYdTmYAf5z49SJZUxr7NtQkOqVYG0hvITw,RM2wnMn5zAufCMt5upkkgq25B1elfBAxc7htapIWg1c,AQACAAE/','"+date.Format("%Y-%m-%d %H:%M:%S")+"','Initial Identity');");\r
+ // insert cptn_insano's public key\r
+ db->Execute("INSERT INTO tblIdentity(PublicKey,DateAdded,AddedMethod) VALUES('SSK@bloE1LJ~qzSYUkU2nt7sB9kq060D4HTQC66pk5Q8NpA,DOOASUnp0kj6tOdhZJ-h5Tk7Ka50FSrUgsH7tCG1usU,AQACAAE/','"+date.Format("%Y-%m-%d %H:%M:%S")+"','Initial Identity');");\r
+ // insert Flink's public key\r
+ db->Execute("INSERT INTO tblIdentity(PublicKey,DateAdded,AddedMethod) VALUES('SSK@q2TtkNBOuuniyJ56~8NSopCs3ttwe5KlB31ugZtWmXA,6~PzIupS8YK7L6oFNpXGKJmHT2kBMDfwTg73nHdNur8,AQACAAE/','"+date.Format("%Y-%m-%d %H:%M:%S")+"','Initial Identity');");\r
\r
// TODO remove sometime after 0.1.17\r
FixCapitalBoardNames();\r
db->Execute("UPDATE tblDBVersion SET Major=1, Minor=9;");\r
}\r
\r
+void ConvertDB0109To0110()\r
+{\r
+ SQLite3DB::DB *db=SQLite3DB::DB::Instance();\r
+ db->Execute("ALTER TABLE tblFileInserts ADD COLUMN MimeType TEXT;");\r
+ db->Execute("UPDATE tblDBVersion SET Major=1, Minor=10;");\r
+}\r
+\r
void SetupDefaultOptions()\r
{\r
// OptionValue should always be inserted as a string, even if the option really isn't a string - just to keep the field data type consistent\r
\r
st.Bind(0,"HTTPAccessControl");\r
st.Bind(1,"-0.0.0.0/0,+127.0.0.1");\r
- st.Bind(2,"Comma separated list of addresses and/or subnet masks that are allowed access to the administration pages. Default is localhost only. + allows a host, - denies as host.");\r
+ st.Bind(2,"Comma separated list of addresses and/or subnet masks that are allowed access to the administration pages. Default is localhost only. + allows a host, - denies a host.");\r
st.Step();\r
st.Reset();\r
\r
st.Step();\r
st.Reset();\r
\r
+ st.Bind(0,"FProxyPort");\r
+ st.Bind(1,"8888");\r
+ st.Bind(2,"The port that Freenet is listening for http connections on.");\r
+ st.Step();\r
+ st.Reset();\r
+\r
st.Bind(0,"MessageBase");\r
st.Bind(1,"fms");\r
st.Bind(2,"A unique string shared by all clients who want to communicate with each other. This should not be changed unless you want to create your own separate communications network.");\r
\r
std::string node="localhost";\r
Option::Instance()->Get("FCPHost",node);\r
+ std::string fproxyport="8888";\r
+ Option::Instance()->Get("FProxyPort",fproxyport);\r
\r
while(st.RowReturned())\r
{\r
st.ResultText(1,filename);\r
st.ResultText(2,sizestr);\r
\r
- content+="<a href=\"http://"+node+":8888/"+StringFunctions::UriEncode(key)+"\">"+SanitizeOutput(filename)+"</a> - "+sizestr+" bytes";\r
+ content+="<a href=\"http://"+node+":"+fproxyport+"/"+StringFunctions::UriEncode(key)+"\">"+SanitizeOutput(filename)+"</a> - "+sizestr+" bytes";\r
content+="<br>";\r
\r
st.Step();\r
std::string hidden="";\r
int freesiteedition=-1;\r
\r
+ std::string fproxyport="8888";\r
+ Option::Instance()->Get("FProxyPort",fproxyport);\r
+\r
if(queryvars.find("identityid")!=queryvars.end() && (*queryvars.find("identityid")).second!="")\r
{\r
identityidstr=(*queryvars.find("identityid")).second;\r
content+="<tr><td>Public Key</td><td class=\"smaller\">"+SanitizeOutput(publickey)+"</td></tr>";\r
if(usk!="")\r
{\r
- content+="<tr><td>Freesite</td><td class=\"smaller\"><a href=\"http://"+fcphost+":8888/"+SanitizeOutput(usk)+"\">"+SanitizeOutput(usk)+"</a></td></tr>";\r
+ content+="<tr><td>Freesite</td><td class=\"smaller\"><a href=\"http://"+fcphost+":"+fproxyport+"/"+SanitizeOutput(usk)+"\">"+SanitizeOutput(usk)+"</a></td></tr>";\r
}\r
content+="<tr><td>Date Added</td><td>"+dateadded+"</td></tr>";\r
content+="<tr><td>Last Seen</td><td>"+lastseen+"</td></tr>";\r
// add a binary file attachment\r
else if((*i)->GetName()!="" && (*i)->GetLength()>0 && (*i)->GetContent())\r
{\r
+ std::string contenttype="";\r
std::vector<unsigned char> data((*i)->GetContent(),(*i)->GetContent()+(*i)->GetContentLength());\r
- m_fileattachments.push_back(fileattachment((*i)->GetName(),data));\r
+ if((*i)->GetContentType())\r
+ {\r
+ contenttype=(*i)->GetContentType();\r
+ // find first ; tab cr or lf and erase it and everything after it\r
+ std::string::size_type endpos=contenttype.find_first_of(";\t\r\n ");\r
+ if(endpos!=std::string::npos)\r
+ {\r
+ contenttype.erase(endpos);\r
+ }\r
+ }\r
+ m_fileattachments.push_back(fileattachment((*i)->GetName(),contenttype,data));\r
}\r
}\r
\r
st.Step();\r
\r
// insert file attachments into database\r
- st=m_db->Prepare("INSERT INTO tblFileInserts(MessageUUID,FileName,Size,Data) VALUES(?,?,?,?);");\r
+ st=m_db->Prepare("INSERT INTO tblFileInserts(MessageUUID,FileName,Size,MimeType,Data) VALUES(?,?,?,?,?);");\r
for(std::vector<fileattachment>::iterator i=m_fileattachments.begin(); i!=m_fileattachments.end(); i++)\r
{\r
st.Bind(0,m_messageuuid);\r
st.Bind(1,(*i).m_filename);\r
st.Bind(2,(long)(*i).m_data.size());\r
- st.Bind(3,&((*i).m_data[0]),(*i).m_data.size());\r
+ st.Bind(3,(*i).m_mimetype);\r
+ st.Bind(4,&((*i).m_data[0]),(*i).m_data.size());\r
st.Step();\r
st.Reset();\r
}\r