From d625e68c5feaaeac0129e3b8cd31892e8cb4c255 Mon Sep 17 00:00:00 2001 From: Thulinma Date: Wed, 8 Jan 2014 01:40:26 +0100 Subject: [PATCH] Added Buffer->Controller logging capabilities. --- src/buffer/buffer.cpp | 2 -- src/buffer/buffer_stream.cpp | 19 ++++++++++++++++--- src/buffer/buffer_stream.h | 2 ++ src/controller/controller.cpp | 5 +++++ 4 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/buffer/buffer.cpp b/src/buffer/buffer.cpp index 13212a45..e96f579f 100644 --- a/src/buffer/buffer.cpp +++ b/src/buffer/buffer.cpp @@ -180,7 +180,6 @@ namespace Buffer { if ( !usr->S.Received().get().empty()){ switch (usr->S.Received().get()[0]){ case 'P': { //Push - std::cout << "Push attempt from IP " << usr->S.Received().get().substr(2) << std::endl; if (thisStream->checkWaitingIP(usr->S.Received().get().substr(2))){ usr->S.Received().get().clear(); Socket::Connection tmp = usr->S; @@ -326,7 +325,6 @@ namespace Buffer { // disconnect listener buffer_running = false; - std::cout << "Buffer shutting down" << std::endl; SS.close(); delete thisStream; return 0; diff --git a/src/buffer/buffer_stream.cpp b/src/buffer/buffer_stream.cpp index 4526ff41..c69167e2 100644 --- a/src/buffer/buffer_stream.cpp +++ b/src/buffer/buffer_stream.cpp @@ -6,6 +6,16 @@ #include namespace Buffer { + + static JSON::Value ctrl_log; + + void Stream::Log(std::string type, std::string message){ + JSON::Value l; + l.append(type); + l.append(message); + ctrl_log.append(l); + } + /// Stores the singleton reference. Stream * Stream::ref = 0; @@ -71,6 +81,9 @@ namespace Buffer { oIt->second.removeMember("commentheader"); } } + + Storage["ctrl_log"] = ctrl_log; + ctrl_log.null(); ret = Storage.toString(); Storage["log"].null(); @@ -93,14 +106,14 @@ namespace Buffer { if (pass == waiting_ip.substr(1)){ return true; }else{ - std::cout << "Password '" << pass << "' incorrect" << std::endl; + Log("BUFF", "Push to stream " + name + " denied, incorrect password: "+pass); return false; } }else{ if (ip == waiting_ip || ip == "::ffff:" + waiting_ip){ return true; }else{ - std::cout << ip << " != (::ffff:)" << waiting_ip << std::endl; + Log("BUFF", "Push to stream " + name + " denied, wrong IP: "+ip+" != (::ffff:)"+waiting_ip); return false; } } @@ -199,7 +212,7 @@ namespace Buffer { for (it = metadata.tracks.begin(); it != metadata.tracks.end(); ++it){ if ((it->first & (sockNo << 16)) == (sockNo << 16)){ toDelete.insert(it->first); - std::cout << "Input lost, removing track: " << it->second.getIdentifier() << std::endl; + Log("BUFF", "Stream "+name+" lost input for track: "+ it->second.getIdentifier()); } } while (toDelete.size()){ diff --git a/src/buffer/buffer_stream.h b/src/buffer/buffer_stream.h index cce88dd3..c586c281 100644 --- a/src/buffer/buffer_stream.h +++ b/src/buffer/buffer_stream.h @@ -81,6 +81,8 @@ namespace Buffer { bool parsePacket(std::string & buffer); /// Thread-safe parsePacket override. bool parsePacket(Socket::Connection & c); + /// Logs a message to the controller. + void Log(std::string type, std::string message); DTSC::livePos getNext(DTSC::livePos & pos, std::set & allowedTracks); private: void deletionCallback(DTSC::livePos deleting); diff --git a/src/controller/controller.cpp b/src/controller/controller.cpp index 7a04b178..b29a6371 100644 --- a/src/controller/controller.cpp +++ b/src/controller/controller.cpp @@ -488,6 +488,11 @@ int main(int argc, char ** argv){ } } } + if (Request.isMember("ctrl_log") && Request["ctrl_log"].size() > 0){ + for (JSON::ArrIter it = Request["ctrl_log"].ArrBegin(); it != Request["ctrl_log"].ArrEnd(); it++){ + Controller::Log((*it)[0u], (*it)[1u]); + } + } } } }