Added Buffer->Controller logging capabilities.

This commit is contained in:
Thulinma 2014-01-08 01:40:26 +01:00
parent ce5b99774d
commit d625e68c5f
4 changed files with 23 additions and 5 deletions

View file

@ -180,7 +180,6 @@ namespace Buffer {
if ( !usr->S.Received().get().empty()){ if ( !usr->S.Received().get().empty()){
switch (usr->S.Received().get()[0]){ switch (usr->S.Received().get()[0]){
case 'P': { //Push 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))){ if (thisStream->checkWaitingIP(usr->S.Received().get().substr(2))){
usr->S.Received().get().clear(); usr->S.Received().get().clear();
Socket::Connection tmp = usr->S; Socket::Connection tmp = usr->S;
@ -326,7 +325,6 @@ namespace Buffer {
// disconnect listener // disconnect listener
buffer_running = false; buffer_running = false;
std::cout << "Buffer shutting down" << std::endl;
SS.close(); SS.close();
delete thisStream; delete thisStream;
return 0; return 0;

View file

@ -6,6 +6,16 @@
#include <stdlib.h> #include <stdlib.h>
namespace Buffer { 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. /// Stores the singleton reference.
Stream * Stream::ref = 0; Stream * Stream::ref = 0;
@ -72,6 +82,9 @@ namespace Buffer {
} }
} }
Storage["ctrl_log"] = ctrl_log;
ctrl_log.null();
ret = Storage.toString(); ret = Storage.toString();
Storage["log"].null(); Storage["log"].null();
return ret; return ret;
@ -93,14 +106,14 @@ namespace Buffer {
if (pass == waiting_ip.substr(1)){ if (pass == waiting_ip.substr(1)){
return true; return true;
}else{ }else{
std::cout << "Password '" << pass << "' incorrect" << std::endl; Log("BUFF", "Push to stream " + name + " denied, incorrect password: "+pass);
return false; return false;
} }
}else{ }else{
if (ip == waiting_ip || ip == "::ffff:" + waiting_ip){ if (ip == waiting_ip || ip == "::ffff:" + waiting_ip){
return true; return true;
}else{ }else{
std::cout << ip << " != (::ffff:)" << waiting_ip << std::endl; Log("BUFF", "Push to stream " + name + " denied, wrong IP: "+ip+" != (::ffff:)"+waiting_ip);
return false; return false;
} }
} }
@ -199,7 +212,7 @@ namespace Buffer {
for (it = metadata.tracks.begin(); it != metadata.tracks.end(); ++it){ for (it = metadata.tracks.begin(); it != metadata.tracks.end(); ++it){
if ((it->first & (sockNo << 16)) == (sockNo << 16)){ if ((it->first & (sockNo << 16)) == (sockNo << 16)){
toDelete.insert(it->first); 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()){ while (toDelete.size()){

View file

@ -81,6 +81,8 @@ namespace Buffer {
bool parsePacket(std::string & buffer); bool parsePacket(std::string & buffer);
/// Thread-safe parsePacket override. /// Thread-safe parsePacket override.
bool parsePacket(Socket::Connection & c); 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<int> & allowedTracks); DTSC::livePos getNext(DTSC::livePos & pos, std::set<int> & allowedTracks);
private: private:
void deletionCallback(DTSC::livePos deleting); void deletionCallback(DTSC::livePos deleting);

View file

@ -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]);
}
}
} }
} }
} }