From 4430e7762844c66428b6f822288beb71b7f82b95 Mon Sep 17 00:00:00 2001 From: SomeDude Date: Thu, 28 Feb 2008 19:16:00 +0100 Subject: [PATCH] version 0.1.14 --- CMakeLists.txt | 7 +- include/board.h | 5 ++ include/freenet/messagelistxml.h | 24 ++++++- include/global.h | 3 +- include/message.h | 1 + include/stringfunctions.h | 7 ++ src/board.cpp | 116 +++++++++++++++++++++------------- src/boardlist.cpp | 34 ++++++++-- src/freenet/boardlistxml.cpp | 5 +- src/freenet/messagelistinserter.cpp | 34 ++++++++++ src/freenet/messagelistrequester.cpp | 21 +++++- src/freenet/messagelistxml.cpp | 108 ++++++++++++++++++++++++++++++- src/freenet/messagerequester.cpp | 3 +- src/freenet/messagexml.cpp | 4 +- src/freenet/periodicdbmaintenance.cpp | 14 ++++ src/global.cpp | 31 +++++++-- src/http/pages/boardspage.cpp | 5 +- src/http/pages/createidentitypage.cpp | 6 +- src/http/pages/peerdetailspage.cpp | 45 +++++++++++-- src/message.cpp | 20 ++++++ src/nntp/nntpconnection.cpp | 26 ++++---- src/stringfunctions.cpp | 6 ++ 22 files changed, 441 insertions(+), 84 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5f976ac..9c0e66a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -100,7 +100,7 @@ ADD_EXECUTABLE(fms ${FMS_SRC} ${FMS_PLATFORM_SRC}) # link dl - For SQLite3 and shttpd - not for FreeBSD IF(CMAKE_COMPILER_IS_GNUCC) IF(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD") - ELSEIF(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD") + ELSE(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD") TARGET_LINK_LIBRARIES(fms dl) ENDIF(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD") ENDIF(CMAKE_COMPILER_IS_GNUCC) @@ -108,7 +108,7 @@ ENDIF(CMAKE_COMPILER_IS_GNUCC) # add -lcompat only for FreeBSD IF(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD") IF(CMAKE_COMPILER_IS_GNUCXX) - ADD_DEFINITIONS(-lcompat) + TARGET_LINK_LIBRARIES(fms compat) ENDIF(CMAKE_COMPILER_IS_GNUCXX) ENDIF(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD") @@ -119,7 +119,8 @@ ENDIF(WIN32) # add -lxnet and -lsocket on solaris IF(CMAKE_SYSTEM_NAME STREQUAL "SunOS") - ADD_DEFINITIONS(-lxnet -lsocket) + TARGET_LINK_LIBRARIES(fms xnet) + TARGET_LINK_LIBRARIES(fms socket) ENDIF(CMAKE_SYSTEM_NAME STREQUAL "SunOS") FIND_LIBRARY(SQLITE3_LIBRARY NAMES sqlite3 sqlite3_s) diff --git a/include/board.h b/include/board.h index 64797ae..a5479d3 100644 --- a/include/board.h +++ b/include/board.h @@ -13,6 +13,7 @@ public: Board(); Board(const long boardid); Board(const std::string &boardname); + Board(const long boardid, const std::string &boardname, const std::string &boarddescription, const std::string datecreated, const long lowmessageid, const long highmessageid, const long messagecount, const bool savereceivedmessages); const bool Load(const long boardid); const bool Load(const std::string &boardname); @@ -24,8 +25,11 @@ public: const long GetLowMessageID() const { return m_lowmessageid; } const long GetHighMessageID() const { return m_highmessageid; } const long GetMessageCount() const { return m_messagecount; } + const bool GetSaveReceivedMessages() const { return m_savereceivedmessages; } private: + void SetDateFromString(const std::string &datestring); + long m_boardid; std::string m_boardname; std::string m_boarddescription; @@ -33,6 +37,7 @@ private: long m_lowmessageid; // lowest id of all message currently in this board long m_highmessageid; // highest id of all message currently in this board long m_messagecount; // number of messages in this board + bool m_savereceivedmessages; }; #endif // _board_ diff --git a/include/freenet/messagelistxml.h b/include/freenet/messagelistxml.h index 3d3f993..1cbf861 100644 --- a/include/freenet/messagelistxml.h +++ b/include/freenet/messagelistxml.h @@ -15,6 +15,17 @@ private: long m_index; std::vector m_boards; }; + struct externalmessage + { + externalmessage(const std::string &type, const std::string identity, const std::string &date, const long index, const std::vector &boards):m_type(type),m_identity(identity),m_date(date),m_index(index),m_boards(boards) {} + externalmessage(const std::string &type, const std::string messagekey, const std::string &date, const std::vector &boards):m_type(type),m_messagekey(messagekey),m_date(date),m_boards(boards) {} + std::string m_type; + std::string m_identity; + std::string m_messagekey; + long m_index; + std::string m_date; + std::vector m_boards; + }; public: MessageListXML(); @@ -23,17 +34,28 @@ public: void ClearMessages() { m_messages.clear(); } - void AddMessage(const std::string &date, const long index, const std::vector boards); + void AddMessage(const std::string &date, const long index, const std::vector &boards); + void AddExternalMessage(const std::string &identity, const std::string &date, const long index, const std::vector &boards); + void AddExternalMessage(const std::string &messagekey, const std::string &date, const std::vector &boards); const std::vector::size_type MessageCount() { return m_messages.size(); } std::string GetDate(const long index); const long GetIndex(const long index); std::vector GetBoards(const long index); + const std::vector::size_type ExternalMessageCount() { return m_externalmessages.size(); } + std::string GetExternalType(const long index); + std::string GetExternalIdentity(const long index); + std::string GetExternalMessageKey(const long index); + const long GetExternalIndex(const long index); + std::string GetExternalDate(const long index); + std::vector GetExternalBoards(const long index); + private: void Initialize(); std::vector m_messages; + std::vector m_externalmessages; }; diff --git a/include/global.h b/include/global.h index 3abb065..55a1e63 100644 --- a/include/global.h +++ b/include/global.h @@ -5,12 +5,13 @@ //#include #include "pthreadwrapper/thread.h" -#define FMS_VERSION "0.1.13" +#define FMS_VERSION "0.1.14" // opens database and creates tables and initial inserts if necessary void SetupDB(); void ConvertDB0100To0101(); void ConvertDB0101To0103(); +void ConvertDB0103To0104(); // inserts default options into the database void SetupDefaultOptions(); // opens logfile and sets it up diff --git a/include/message.h b/include/message.h index c99b96d..9cda4a9 100644 --- a/include/message.h +++ b/include/message.h @@ -54,6 +54,7 @@ private: // checks vector of boards for any special administration boards - if it finds one true is returned, otherwise false const bool CheckForAdministrationBoard(const std::vector &boards); void HandleChangeTrust(); + void StripAdministrationBoards(); // removes administration boards from boards vector long m_messageid; bool m_addnewpostfromidentities; diff --git a/include/stringfunctions.h b/include/stringfunctions.h index ac803c9..bf5119d 100644 --- a/include/stringfunctions.h +++ b/include/stringfunctions.h @@ -91,6 +91,13 @@ std::string TrimWhitespace(const std::string &str); void UpperCase(const std::string &str, std::string &output); /** + \brief Converts a string to lower case + \param str string to convert to lower case + \param[out] string converted to lower case +*/ +void LowerCase(const std::string &str, std::string &output); + +/** \brief Decodes a URI encoded string \param aSrc string that is URI encoded \return URI decoded input string diff --git a/src/board.cpp b/src/board.cpp index e256dcb..aee9339 100644 --- a/src/board.cpp +++ b/src/board.cpp @@ -14,6 +14,7 @@ Board::Board() m_lowmessageid=0; m_highmessageid=0; m_messagecount=0; + m_savereceivedmessages=true; } Board::Board(const long boardid) @@ -26,6 +27,21 @@ Board::Board(const std::string &boardname) Load(boardname); } +Board::Board(const long boardid, const std::string &boardname, const std::string &boarddescription, const std::string datecreated, const long lowmessageid, const long highmessageid, const long messagecount, const bool savereceivedmessages) +{ + m_boardid=boardid; + m_boardname=boardname; + m_boarddescription=boarddescription; + m_lowmessageid=lowmessageid; + m_highmessageid=highmessageid; + m_messagecount=messagecount; + m_savereceivedmessages=savereceivedmessages; + + SetDateFromString(datecreated); + +} + + const bool Board::Load(const long boardid) { // clear current values @@ -37,7 +53,7 @@ const bool Board::Load(const long boardid) m_highmessageid=0; m_messagecount=0; - SQLite3DB::Statement st=m_db->Prepare("SELECT BoardName, BoardDescription, DateAdded FROM tblBoard WHERE BoardID=?;"); + SQLite3DB::Statement st=m_db->Prepare("SELECT BoardName, BoardDescription, DateAdded, HighMessageID, LowMessageID, MessageCount, SaveReceivedMessages FROM tblBoard LEFT JOIN vwBoardStats ON tblBoard.BoardID=vwBoardStats.BoardID WHERE tblBoard.BoardID=?;"); st.Bind(0,boardid); st.Step(); @@ -52,53 +68,25 @@ const bool Board::Load(const long boardid) st.ResultText(1,m_boarddescription); st.ResultText(2,tempstr); - // break out date created - date should be in format yyyy-mm-dd HH:MM:SS, so we split on "-", " " (space), and ":" - StringFunctions::SplitMultiple(tempstr,"- :",dateparts); - if(dateparts.size()>0) - { - StringFunctions::Convert(dateparts[0],tempint); - m_datecreated.SetYear(tempint); - } - if(dateparts.size()>1) - { - StringFunctions::Convert(dateparts[1],tempint); - m_datecreated.SetMonth(tempint); - } - if(dateparts.size()>2) - { - StringFunctions::Convert(dateparts[2],tempint); - m_datecreated.SetDay(tempint); - } - if(dateparts.size()>3) - { - StringFunctions::Convert(dateparts[3],tempint); - m_datecreated.SetHour(tempint); - } - if(dateparts.size()>4) - { - StringFunctions::Convert(dateparts[4],tempint); - m_datecreated.SetMinute(tempint); - } - if(dateparts.size()>5) + SetDateFromString(tempstr); + + tempint=0; + st.ResultInt(3,tempint); + m_highmessageid=tempint; + tempint=0; + st.ResultInt(4,tempint); + m_lowmessageid=tempint; + tempint=0; + st.ResultInt(5,tempint); + m_messagecount=tempint; + st.ResultText(6,tempstr); + if(tempstr=="true") { - StringFunctions::Convert(dateparts[5],tempint); - m_datecreated.SetSecond(tempint); + m_savereceivedmessages=true; } - - // get max and min ids and message count in this board - SQLite3DB::Statement bounds=m_db->Prepare("SELECT HighMessageID, LowMessageID, MessageCount FROM vwBoardStats WHERE BoardID=?;"); - bounds.Bind(0,boardid); - bounds.Step(); - - if(bounds.RowReturned()) + else { - int tempint; - bounds.ResultInt(0,tempint); - m_highmessageid=tempint; - bounds.ResultInt(1,tempint); - m_lowmessageid=tempint; - bounds.ResultInt(2,tempint); - m_messagecount=tempint; + m_savereceivedmessages=false; } return true; @@ -125,3 +113,41 @@ const bool Board::Load(const std::string &boardname) return false; } } + +void Board::SetDateFromString(const std::string &datestring) +{ + // break out date created - date should be in format yyyy-mm-dd HH:MM:SS, so we split on "-", " " (space), and ":" + int tempint=0; + std::vector dateparts; + StringFunctions::SplitMultiple(datestring,"- :",dateparts); + if(dateparts.size()>0) + { + StringFunctions::Convert(dateparts[0],tempint); + m_datecreated.SetYear(tempint); + } + if(dateparts.size()>1) + { + StringFunctions::Convert(dateparts[1],tempint); + m_datecreated.SetMonth(tempint); + } + if(dateparts.size()>2) + { + StringFunctions::Convert(dateparts[2],tempint); + m_datecreated.SetDay(tempint); + } + if(dateparts.size()>3) + { + StringFunctions::Convert(dateparts[3],tempint); + m_datecreated.SetHour(tempint); + } + if(dateparts.size()>4) + { + StringFunctions::Convert(dateparts[4],tempint); + m_datecreated.SetMinute(tempint); + } + if(dateparts.size()>5) + { + StringFunctions::Convert(dateparts[5],tempint); + m_datecreated.SetSecond(tempint); + } +} diff --git a/src/boardlist.cpp b/src/boardlist.cpp index 71c5e46..cd6e071 100644 --- a/src/boardlist.cpp +++ b/src/boardlist.cpp @@ -8,14 +8,40 @@ void BoardList::Load() { clear(); - int tempint; - SQLite3DB::Statement st=m_db->Prepare("SELECT BoardID FROM tblBoard ORDER BY BoardName;"); + int boardid=0; + std::string boardname=""; + std::string boarddescription=""; + std::string dateadded=""; + std::string savereceivedstr=""; + bool savereceived=false; + int highmessageid=0; + int lowmessageid=0; + int messagecount=0; + + SQLite3DB::Statement st=m_db->Prepare("SELECT tblBoard.BoardID, BoardName, BoardDescription, DateAdded, HighMessageID, LowMessageID, MessageCount, SaveReceivedMessages FROM tblBoard LEFT JOIN vwBoardStats ON tblBoard.BoardID=vwBoardStats.BoardID ORDER BY BoardName COLLATE NOCASE;"); st.Step(); while(st.RowReturned()) { - st.ResultInt(0,tempint); - push_back(Board(tempint)); + st.ResultInt(0,boardid); + st.ResultText(1,boardname); + st.ResultText(2,boarddescription); + st.ResultText(3,dateadded); + st.ResultInt(4,highmessageid); + st.ResultInt(5,lowmessageid); + st.ResultInt(6,messagecount); + st.ResultText(7,savereceivedstr); + + if(savereceivedstr=="true") + { + savereceived=true; + } + else + { + savereceived=false; + } + + push_back(Board(boardid,boardname,boarddescription,dateadded,lowmessageid,highmessageid,messagecount,savereceived)); st.Step(); } } diff --git a/src/freenet/boardlistxml.cpp b/src/freenet/boardlistxml.cpp index 4307c71..954a5b4 100644 --- a/src/freenet/boardlistxml.cpp +++ b/src/freenet/boardlistxml.cpp @@ -13,7 +13,9 @@ void BoardListXML::AddBoard(const std::string &name, const std::string &descript { if(name!="" && description!="") { - m_boards.push_back(board(name,description)); + std::string lowername=name; + StringFunctions::Convert(lowername,lowername); + m_boards.push_back(board(lowername,description)); } } @@ -95,6 +97,7 @@ const bool BoardListXML::ParseXML(const std::string &xml) if(txt) { name=txt->ValueStr(); + StringFunctions::LowerCase(name,name); } txt=hnd2.FirstChild("Description").FirstChild().ToText(); if(txt) diff --git a/src/freenet/messagelistinserter.cpp b/src/freenet/messagelistinserter.cpp index b608145..6fda244 100644 --- a/src/freenet/messagelistinserter.cpp +++ b/src/freenet/messagelistinserter.cpp @@ -165,6 +165,40 @@ void MessageListInserter::StartInsert(const long &localidentityid) } st.Finalize(); + + st=m_db->Prepare("SELECT MessageDate, MessageIndex, PublicKey, MessageID FROM tblMessage INNER JOIN tblIdentity ON tblMessage.IdentityID=tblIdentity.IdentityID WHERE MessageIndex IS NOT NULL ORDER BY MessageDate DESC, MessageTime DESC LIMIT 100;"); + SQLite3DB::Statement st2=m_db->Prepare("SELECT BoardName FROM tblBoard INNER JOIN tblMessageBoard ON tblBoard.BoardID=tblMessageBoard.BoardID WHERE tblMessageBoard.MessageID=?;"); + st.Step(); + while(st.RowReturned()) + { + std::string day; + int index; + std::string publickey; + std::vector boardlist; + int messageid; + + st.ResultText(0,day); + st.ResultInt(1,index); + st.ResultText(2,publickey); + st.ResultInt(3,messageid); + + st2.Bind(0,messageid); + st2.Step(); + while(st2.RowReturned()) + { + std::string boardname=""; + st2.ResultText(0,boardname); + StringFunctions::LowerCase(boardname,boardname); + boardlist.push_back(boardname); + st2.Step(); + } + st2.Reset(); + + mlxml.AddExternalMessage(publickey,day,index,boardlist); + + st.Step(); + } + // get last inserted messagelist index for this day index=0; st=m_db->Prepare("SELECT MAX(InsertIndex) FROM tblMessageListInserts WHERE LocalIdentityID=? AND Day=?;"); diff --git a/src/freenet/messagelistrequester.cpp b/src/freenet/messagelistrequester.cpp index 242d292..bbf8650 100644 --- a/src/freenet/messagelistrequester.cpp +++ b/src/freenet/messagelistrequester.cpp @@ -54,6 +54,7 @@ const bool MessageListRequester::HandleAllData(FCPMessage &message) { SQLite3DB::Statement st=m_db->Prepare("SELECT IdentityID FROM tblMessageRequests WHERE IdentityID=? AND Day=? AND RequestIndex=?;"); + SQLite3DB::Statement spk=m_db->Prepare("SELECT IdentityID FROM tblIdentity WHERE PublicKey=?;"); SQLite3DB::Statement mst=m_db->Prepare("INSERT INTO tblMessageRequests(IdentityID,Day,RequestIndex,FromMessageList) VALUES(?,?,?,'true');"); for(long i=0; iPrepare("INSERT INTO tblMessageListRequests(IdentityID,Day,RequestIndex,Found) VALUES(?,?,?,'true');"); st.Bind(0,identityid); diff --git a/src/freenet/messagelistxml.cpp b/src/freenet/messagelistxml.cpp index c05bb66..c2a9c82 100644 --- a/src/freenet/messagelistxml.cpp +++ b/src/freenet/messagelistxml.cpp @@ -9,11 +9,21 @@ MessageListXML::MessageListXML() Initialize(); } -void MessageListXML::AddMessage(const std::string &date, const long index, const std::vector boards) +void MessageListXML::AddMessage(const std::string &date, const long index, const std::vector &boards) { m_messages.push_back(message(date,index,boards)); } +void MessageListXML::AddExternalMessage(const std::string &identity, const std::string &date, const long index, const std::vector &boards) +{ + m_externalmessages.push_back(externalmessage("Keyed",identity,date,index,boards)); +} + +void MessageListXML::AddExternalMessage(const std::string &messagekey, const std::string &date, const std::vector &boards) +{ + m_externalmessages.push_back(externalmessage("Anonymous",messagekey,date,boards)); +} + std::vector MessageListXML::GetBoards(const long index) { if(index>=0 && index MessageListXML::GetExternalBoards(const long index) +{ + if(index>=0 && index(); + } +} + +std::string MessageListXML::GetExternalDate(const long index) +{ + if(index>=0 && index=0 && index=0 && index=0 && index=0 && index=0 && index::iterator i=m_externalmessages.begin(); i!=m_externalmessages.end(); i++) + { + TiXmlElement *tr=new TiXmlElement("ExternalMessage"); + tid->LinkEndChild(tr); + tr->LinkEndChild(XMLCreateTextElement("Type",(*i).m_type)); + if((*i).m_type=="Keyed") + { + tr->LinkEndChild(XMLCreateCDATAElement("Identity",(*i).m_identity)); + tr->LinkEndChild(XMLCreateTextElement("Index",(*i).m_index)); + } + else + { + tr->LinkEndChild(XMLCreateCDATAElement("MessageKey",(*i).m_messagekey)); + } + tr->LinkEndChild(XMLCreateTextElement("Date",(*i).m_date)); + TiXmlElement *brds=new TiXmlElement("Boards"); + tr->LinkEndChild(brds); + for(std::vector::iterator j=(*i).m_boards.begin(); j!=(*i).m_boards.end(); j++) + { + brds->LinkEndChild(XMLCreateCDATAElement("Board",(*j))); + } + } + td.Accept(&tp); return std::string(tp.CStr()); } @@ -82,6 +187,7 @@ std::string MessageListXML::GetXML() void MessageListXML::Initialize() { m_messages.clear(); + m_externalmessages.clear(); } const bool MessageListXML::ParseXML(const std::string &xml) diff --git a/src/freenet/messagerequester.cpp b/src/freenet/messagerequester.cpp index ac56c5c..adf8168 100644 --- a/src/freenet/messagerequester.cpp +++ b/src/freenet/messagerequester.cpp @@ -191,7 +191,7 @@ const bool MessageRequester::HandleAllData(FCPMessage &message) if(validmessage && savetoboardcount>0) { - st=m_db->Prepare("INSERT INTO tblMessage(IdentityID,FromName,MessageDate,MessageTime,Subject,MessageUUID,ReplyBoardID,Body) VALUES(?,?,?,?,?,?,?,?);"); + st=m_db->Prepare("INSERT INTO tblMessage(IdentityID,FromName,MessageDate,MessageTime,Subject,MessageUUID,ReplyBoardID,Body,MessageIndex) VALUES(?,?,?,?,?,?,?,?,?);"); st.Bind(0,identityid); st.Bind(1,GetIdentityName(identityid)); st.Bind(2,xml.GetDate()); @@ -200,6 +200,7 @@ const bool MessageRequester::HandleAllData(FCPMessage &message) st.Bind(5,xml.GetMessageID()); st.Bind(6,GetBoardID(xml.GetReplyBoard())); st.Bind(7,xml.GetBody()); + st.Bind(8,index); inserted=st.Step(true); int messageid=st.GetLastInsertRowID(); diff --git a/src/freenet/messagexml.cpp b/src/freenet/messagexml.cpp index 0de84c3..4b3252a 100644 --- a/src/freenet/messagexml.cpp +++ b/src/freenet/messagexml.cpp @@ -113,7 +113,9 @@ const bool MessageXML::ParseXML(const std::string &xml) { if(node2->FirstChild()) { - m_boards.push_back(node2->FirstChild()->ValueStr()); + std::string boardname=node2->FirstChild()->ValueStr(); + StringFunctions::LowerCase(boardname,boardname); + m_boards.push_back(boardname); } node2=node2->NextSibling("Board"); } diff --git a/src/freenet/periodicdbmaintenance.cpp b/src/freenet/periodicdbmaintenance.cpp index c615d60..63863f8 100644 --- a/src/freenet/periodicdbmaintenance.cpp +++ b/src/freenet/periodicdbmaintenance.cpp @@ -133,6 +133,20 @@ void PeriodicDBMaintenance::Do1DayMaintenance() st.Step(); } + // delete single use identities that are older than 7 days + date.SetToGMTime(); + date.Add(0,0,0,-7); + st=m_db->Prepare("DELETE FROM tblIdentity WHERE SingleUse='true' AND DateAddedPrepare("DELETE FROM tblLocalIdentity WHERE SingleUse='true' AND DateCreatedExecute("INSERT INTO tblDBVersion(Major,Minor) VALUES(1,1);"); + db->Execute("INSERT INTO tblDBVersion(Major,Minor) VALUES(1,4);"); } - db->Execute("UPDATE tblDBVersion SET Major=1, Minor=3;"); + db->Execute("UPDATE tblDBVersion SET Major=1, Minor=4;"); db->Execute("CREATE TABLE IF NOT EXISTS tblOption(\ Option TEXT UNIQUE,\ @@ -89,7 +95,8 @@ void SetupDB() InsertingBoardList BOOL CHECK(InsertingBoardList IN('true','false')) DEFAULT 'false',\ LastInsertedBoardList DATETIME,\ InsertingMessageList BOOL CHECK(InsertingMessageList IN('true','false')) DEFAULT 'false',\ - LastInsertedMessageList DATETIME\ + LastInsertedMessageList DATETIME,\ + DateCreated DATETIME\ );"); db->Execute("CREATE TABLE IF NOT EXISTS tblLocalIdentityInserts(\ @@ -193,7 +200,8 @@ void SetupDB() Subject TEXT,\ MessageUUID TEXT UNIQUE,\ ReplyBoardID INTEGER,\ - Body TEXT\ + Body TEXT,\ + MessageIndex INTEGER\ );"); db->Execute("CREATE TABLE IF NOT EXISTS tblMessageReplyTo(\ @@ -222,6 +230,8 @@ void SetupDB() Found BOOL CHECK(Found IN('true','false')) DEFAULT 'false'\ );"); + db->Execute("CREATE UNIQUE INDEX IF NOT EXISTS idxMessageRequest ON tblMessageRequests(IdentityID,Day,RequestIndex);"); + db->Execute("CREATE TABLE IF NOT EXISTS tblMessageInserts(\ LocalIdentityID INTEGER,\ Day DATE,\ @@ -437,6 +447,19 @@ void ConvertDB0101To0103() db->Execute("UPDATE tblDBVersion SET Major=1, Minor=3;"); } +void ConvertDB0103To0104() +{ + // add MessageIndex to tblMessage + DateTime date; + SQLite3DB::DB *db=SQLite3DB::DB::Instance(); + db->Execute("ALTER TABLE tblMessage ADD COLUMN MessageIndex INTEGER;"); + db->Execute("CREATE UNIQUE INDEX IF NOT EXISTS idxMessageRequest ON tblMessageRequests(IdentityID,Day,RequestIndex);"); + db->Execute("ALTER TABLE tblLocalIdentity ADD COLUMN DateCreated DATETIME;"); + date.SetToGMTime(); + db->Execute("UPDATE tblLocalIdentity SET DateCreated='"+date.Format("%Y-%m-%d %H:%M:%S")+"' WHERE DateCreated IS NULL;"); + db->Execute("UPDATE tblDBVersion SET Major=1, Minor=4;"); +} + void SetupDefaultOptions() { // 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 diff --git a/src/http/pages/boardspage.cpp b/src/http/pages/boardspage.cpp index 8d10aa6..f143d32 100644 --- a/src/http/pages/boardspage.cpp +++ b/src/http/pages/boardspage.cpp @@ -177,7 +177,7 @@ const std::string BoardsPage::GeneratePage(const std::string &method, const std: content+="
"; content+=""; - content+="NameDescriptionSave Received Messages"; + content+="NameDescriptionSave Received Messages *"; content+=""; while(st.RowReturned() && rownum
"; content+=""; content+=""; + content+="

"; + content+="* If you uncheck this box, any new messages you download that are posted to this board will be discarded."; + content+="

"; return "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n"+StringFunctions::Replace(m_template,"[CONTENT]",content); } diff --git a/src/http/pages/createidentitypage.cpp b/src/http/pages/createidentitypage.cpp index 2c55c02..c28fa64 100644 --- a/src/http/pages/createidentitypage.cpp +++ b/src/http/pages/createidentitypage.cpp @@ -1,5 +1,6 @@ #include "../../../include/http/pages/createidentitypage.h" #include "../../../include/stringfunctions.h" +#include "../../../include/datetime.h" #ifdef XMEM #include @@ -11,8 +12,10 @@ const std::string CreateIdentityPage::GeneratePage(const std::string &method, co if(queryvars.find("formaction")!=queryvars.end() && (*queryvars.find("formaction")).second=="create") { - SQLite3DB::Statement st=m_db->Prepare("INSERT INTO tblLocalIdentity(Name,PublishTrustList) VALUES(?,'true');"); + SQLite3DB::Statement st=m_db->Prepare("INSERT INTO tblLocalIdentity(Name,PublishTrustList,DateCreated) VALUES(?,'true',?);"); std::string name=""; + DateTime date; + date.SetToGMTime(); if(queryvars.find("name")!=queryvars.end()) { @@ -20,6 +23,7 @@ const std::string CreateIdentityPage::GeneratePage(const std::string &method, co } st.Bind(0,name); + st.Bind(1,date.Format("%Y-%m-%d %H:%M:%S")); st.Step(); content+="

Created Identity

"; diff --git a/src/http/pages/peerdetailspage.cpp b/src/http/pages/peerdetailspage.cpp index 83b1b34..7f06fd2 100644 --- a/src/http/pages/peerdetailspage.cpp +++ b/src/http/pages/peerdetailspage.cpp @@ -9,35 +9,70 @@ const std::string PeerDetailsPage::GeneratePage(const std::string &method, const { std::string content=""; int identityid=0; + std::string identityidstr=""; std::string name; std::string publickey; std::string messagetrust; std::string trustlisttrust; std::string keypart=""; std::string lastseen=""; + std::string dateadded=""; if(queryvars.find("identityid")!=queryvars.end() && (*queryvars.find("identityid")).second!="") { + identityidstr=(*queryvars.find("identityid")).second; StringFunctions::Convert((*queryvars.find("identityid")).second,identityid); } - SQLite3DB::Statement st=m_db->Prepare("SELECT Name,PublicKey,LastSeen FROM tblIdentity WHERE IdentityID=?;"); + if(identityid!=0 && queryvars.find("formaction")!=queryvars.end() && (*queryvars.find("formaction")).second=="deletemessages") + { + SQLite3DB::Statement del=m_db->Prepare("DELETE FROM tblMessage WHERE IdentityID=?;"); + del.Bind(0,identityid); + del.Step(); + } + + SQLite3DB::Statement st=m_db->Prepare("SELECT Name,PublicKey,DateAdded,LastSeen FROM tblIdentity WHERE IdentityID=?;"); st.Bind(0,identityid); st.Step(); + content+=""; if(st.RowReturned()) { st.ResultText(0,name); st.ResultText(1,publickey); - st.ResultText(2,lastseen); + st.ResultText(2,dateadded); + st.ResultText(3,lastseen); - content+="
"; content+=""; - content+=""; + content+=""; + content+=""; content+=""; - content+="
Name"+SanitizeOutput(name)+"
Public Key"+SanitizeOutput(publickey)+"
Public Key"+SanitizeOutput(publickey)+"
Date Added"+dateadded+"
Last Seen"+lastseen+"
"; } + // get message count posted by this identity + st=m_db->Prepare("SELECT COUNT(MessageID) FROM tblMessage WHERE IdentityID=?;"); + st.Bind(0,identityid); + st.Step(); + + if(st.RowReturned()) + { + std::string messagecountstr="0"; + st.ResultText(0,messagecountstr); + content+=""; + content+="Message Count"; + content+=""+messagecountstr; + content+="  
"; + content+=""; + content+=""; + content+=""; + content+="
"; + content+=""; + content+=""; + } + + content+=""; + + st=m_db->Prepare("SELECT Name,PublicKey,MessageTrust,TrustListTrust,tblIdentity.IdentityID FROM tblPeerTrust INNER JOIN tblIdentity ON tblPeerTrust.TargetIdentityID=tblIdentity.IdentityID WHERE tblPeerTrust.IdentityID=? ORDER BY Name COLLATE NOCASE;"); st.Bind(0,identityid); st.Step(); diff --git a/src/message.cpp b/src/message.cpp index d8adc87..f4a6ea6 100644 --- a/src/message.cpp +++ b/src/message.cpp @@ -630,6 +630,7 @@ const bool Message::StartFreenetInsert() xml.SetDate(m_datetime.Format("%Y-%m-%d")); xml.SetTime(m_datetime.Format("%H:%M:%S")); + StripAdministrationBoards(); for(std::vector::iterator i=m_boards.begin(); i!=m_boards.end(); i++) { xml.AddBoard((*i)); @@ -678,3 +679,22 @@ const bool Message::StartFreenetInsert() return true; } + +void Message::StripAdministrationBoards() +{ + SQLite3DB::Statement st=m_db->Prepare("SELECT tblBoard.BoardID FROM tblBoard INNER JOIN tblAdministrationBoard ON tblBoard.BoardID=tblAdministrationBoard.BoardID WHERE BoardName=?;"); + for(std::vector::iterator i=m_boards.begin(); i!=m_boards.end(); ) + { + st.Bind(0,(*i)); + st.Step(); + if(st.RowReturned()) + { + i=m_boards.erase(i); + } + else + { + i++; + } + st.Reset(); + } +} diff --git a/src/nntp/nntpconnection.cpp b/src/nntp/nntpconnection.cpp index fa35f4f..cc5cffe 100644 --- a/src/nntp/nntpconnection.cpp +++ b/src/nntp/nntpconnection.cpp @@ -317,7 +317,7 @@ const bool NNTPConnection::HandleListCommand(const NNTPCommand &command) show=uwildmat((*i).GetBoardName().c_str(),arg2.c_str()); } - if(show==true) + if(show==true && (*i).GetSaveReceivedMessages()==true) { tempstr << (*i).GetBoardName() << " " << (*i).GetHighMessageID() << " " << (*i).GetLowMessageID() << " " << (m_status.m_allowpost ? "y" : "n"); SendBufferedLine(tempstr.str()); @@ -348,7 +348,7 @@ const bool NNTPConnection::HandleListCommand(const NNTPCommand &command) show=uwildmat((*i).GetBoardName().c_str(),arg2.c_str()); } - if(show==true) + if(show==true && (*i).GetSaveReceivedMessages()==true) { tempstr << (*i).GetBoardName() << "\t" << (*i).GetBoardDescription(); SendBufferedLine(tempstr.str()); @@ -559,9 +559,12 @@ const bool NNTPConnection::HandleNewGroupsCommand(const NNTPCommand &command) for(BoardList::iterator i=bl.begin(); i!=bl.end(); i++) { - std::ostringstream tempstr; - tempstr << (*i).GetBoardName() << " " << (*i).GetHighMessageID() << " " << (*i).GetLowMessageID() << " " << m_status.m_allowpost ? "y" : "n"; - SendBufferedLine(tempstr.str()); + if((*i).GetSaveReceivedMessages()==true) + { + std::ostringstream tempstr; + tempstr << (*i).GetBoardName() << " " << (*i).GetHighMessageID() << " " << (*i).GetLowMessageID() << " " << m_status.m_allowpost ? "y" : "n"; + SendBufferedLine(tempstr.str()); + } } SendBufferedLine("."); @@ -784,16 +787,13 @@ void NNTPConnection::HandlePostedMessage(const std::string &message) { mess.HandleAdministrationMessage(); } + if(mess.StartFreenetInsert()) + { + SendBufferedLine("240 Article received OK"); + } else { - if(mess.StartFreenetInsert()) - { - SendBufferedLine("240 Article received OK"); - } - else - { - SendBufferedLine("441 Posting failed. Make sure the identity you are sending with exists!"); - } + SendBufferedLine("441 Posting failed. Make sure the identity you are sending with exists!"); } } else diff --git a/src/stringfunctions.cpp b/src/stringfunctions.cpp index bed3622..bd757aa 100644 --- a/src/stringfunctions.cpp +++ b/src/stringfunctions.cpp @@ -9,6 +9,12 @@ namespace StringFunctions { +void LowerCase(const std::string &str, std::string &output) +{ + output=str; + std::transform(str.begin(),str.end(),output.begin(),tolower); +} + std::string Replace(const std::string &input, const std::string &find, const std::string &replace) { std::string returnstr=input; -- 2.7.4