void ConnectMessagingEndPoint::sndMessage(MessageWrapper *mw){
   getLogStream(LOG_DEBUG) << "Serializing messagewrapper " << endl; 
   string serialized = serializeMessageWrapper(mw); 
   getLogStream(LOG_DEBUG) << "Sending message on _outstream " << endl;
   // Since this is a client we have only one outgoing stream 
   _sock_outstream.send(serialized.c_str(), strlen(serialized.c_str()) + 1);
 }
        inline auto& operator<<(LOut& mLOut, const T& mValue)
        {
            std::lock_guard<std::mutex> SSVU_UNIQUE_NAME{lo().mtx};

            if(!getLogSuppressed())
            {
                if(!mLOut.title.empty())
                {
                    auto tStr("[" + mLOut.title + "] ");
                    std::cout << getUniqueColor(tStr)
                              << Console::setStyle(Console::Style::Bold)
                              << std::left << std::setw(LOut::leftW) << tStr;
                    getLogStream() << std::left << std::setw(LOut::leftW)
                                   << tStr;
                    mLOut.title.clear();
                }

                mLOut.stream << Console::resetFmt();
                stringify<true>(mLOut.stream, mValue);
                mLOut.stream << Console::resetFmt();

                stringify<false>(getLogStream(), mValue);
            }

            return mLOut;
        }
Exemple #3
0
/*
 * Returns true if good match, otherwise false
 */
bool Parser::match(int token, const char* rulename){
	if (lexer->getToken() != token){
		getLogStream(ocfa::misc::LOG_EMERG) << lexer->getLinenumber() << ": Error: parse error in " << rulename << ", unexpected '" << lexer->getLexeme() << "'\n";
		exit(1);
	}
	getLogStream(ocfa::misc::LOG_DEBUG) <<lexer->getLinenumber() << ": " << lexer->getLexeme() << " in " << rulename << " OK\n";
	lexer->next();
	return true;
}
Exemple #4
0
int Parser::parse(){
	if (rulelist())
		return 1;

	if (lexer->next() == 0){
		getLogStream(ocfa::misc::LOG_EMERG) << lexer->getLinenumber() << ": symbols after end of parse, " <<  lexer->getLexeme().c_str() << std::endl;
		return 1;
	}

	if (!router::RuleList::getInstance()->has_rule()){
		getLogStream(ocfa::misc::LOG_EMERG) << "No rules in rulelist!\n";
		return 1;
	}

	return 0;
}
Exemple #5
0
	void closeLib() {
	   if (mLibHandle) {
	      getLogStream(ocfa::misc::LOG_NOTICE) << "Closing opened library. (handle=" <<  mLibHandle << ")" << std::endl;  
              dlclose(mLibHandle);
	   }
	   mLibHandle=0;
	}
Exemple #6
0
    void PgFileRepository::getStoreEntity(OcfaHandle & h, StoreEntity &se) {
      
      ocfaLog(LOG_DEBUG, ">> entering PgFileRepository::getStoreEntity");
      if (h == "") throw OcfaException("getStoreEntity called with empty handle",this);
      string query = "select repname from " + se.tableName() + " where id = " + string(h.c_str()) ;
      se.setHandle(h);
      getLogStream(LOG_DEBUG) << "Executing " << query << endl;
      PGresult *pgres = PQexec(d_connection,query.c_str());
      if (PQresultStatus(pgres) == PGRES_TUPLES_OK) {
	if (PQntuples(pgres) > 0) {

	  Filename repname(PQgetvalue(pgres, 0, 0));
	  se.setStoreName(repname);
	}
	else {
	  ocfaLog(LOG_ERR, "Error: OcfaHandle for StoreEntity not found in DB");
	  throw OcfaException("Error: OcfaHandle "+ h + " not found in DB", this);
	}
      }
      else {
	ocfaLog(LOG_ERR, "Could not get repname from db: " + ErrorMessage() +  " query=" + query);
	throw OcfaException("Cannot get RepName from db " + ErrorMessage() 
			    + " query=" + query, this);
      }
      ocfaLog(LOG_DEBUG, "exiting getStoreEntity");
      PQclear(pgres);
    }
            inline void flush()
            {
                std::lock_guard<std::mutex> SSVU_UNIQUE_NAME{mtx};

                stream.flush();
                getLogStream().flush();
            }
        /// @brief Interaction between the `lo()` object and a stream
        /// manipulator.
        inline auto& operator<<(LOut& mLOut, StdEndLine mManip)
        {
            std::lock_guard<std::mutex> SSVU_UNIQUE_NAME{lo().mtx};

            mManip(std::cout);
            mManip(getLogStream());
            return mLOut;
        }
Exemple #9
0
SimpleExpression Parser::simple_expression(){
	std::string field = id();
	enum Operator oper = op();
	std::string value = id_list();
	if (field == "" || oper == OP_BAD_OPERATOR || value == ""){
		getLogStream(ocfa::misc::LOG_EMERG) << lexer->getLinenumber() << ": Broken expression '" << field << "' '" << oper << "' '" << value <<"'\n"; 
		exit(1);
	}
	return SimpleExpression(field, oper, value);
}
Exemple #10
0
/* XXX: ugly hack to allow "Microsoft Office Document" (without ") */
std::string Parser::id_list(){
	bool is_multiword = false;
	std::string idstring( id());
	while(lexer->getToken() == TOK_ID){
		idstring += " " + id();
		is_multiword = true;
	}
	if (is_multiword)
		getLogStream(ocfa::misc::LOG_WARNING) << lexer->getLinenumber() << ": Error prone multiword identifier ("<< idstring << ")\n";
	return idstring;
}
Exemple #11
0
/*
 * returns the final action or empty string upon error
 */
std::string Parser::action(){
	switch(lexer->getToken()){
	case TOK_ACT_JUMP:	match(TOK_ACT_JUMP, "action");		return "ACT_JUMP";
	case TOK_ACT_FORWARD:	match(TOK_ACT_FORWARD, "action");	return "ACT_FORWARD";
	case TOK_ACT_COMMIT:	match(TOK_ACT_COMMIT, "action");	return "ACT_COMMIT";
	default:
		getLogStream(ocfa::misc::LOG_EMERG) << lexer->getLinenumber() << ": unexpected token '" <<lexer->getLexeme() << "'\n";
		return "";
		break;
	}
}
Exemple #12
0
enum Operator Parser::op(){
	switch(lexer->getToken()){
	case TOK_SMATCH:	match(TOK_SMATCH, "operator");	return OP_SMATCH;
	case TOK_NOSMATCH:	match(TOK_NOSMATCH, "operator");return OP_NOSMATCH;
	case TOK_EQUAL:		match(TOK_EQUAL, "operator");	return OP_EQUAL;
	case TOK_NOTEQUAL:	match(TOK_NOTEQUAL, "operator");return OP_NOTEQUAL;
	case TOK_LESS:		match(TOK_LESS, "operator");	return OP_LESS;
	case TOK_MORE:		match(TOK_MORE, "operator");	return OP_MORE;
	case TOK_META:		
		match(TOK_META, "operator");	
		if (lexer->getLexeme() != "exists" && lexer->getLexeme() != "not_exists")
			getLogStream(ocfa::misc::LOG_EMERG) << lexer->getLinenumber() << ":  Operator META used but without exists/not_exists as operand which is required for the META operator. \n";
			
		return OP_META;
	default:
		getLogStream(ocfa::misc::LOG_EMERG) << lexer->getLinenumber() << ": unexpected token '" <<lexer->getLexeme() << "'\n";
		return OP_BAD_OPERATOR;
		break;
	}
}
    MessageWrapper *ConnectMessagingEndPoint::preprocessMessage(MessageWrapper *mw){
      Message *inmsg = 0; 
      switch (mw->getType()){
      case MessageWrapper::mwTask:{
	/* fall through */
	getLogStream(LOG_DEBUG) << "I've been assigned to a task" << endl;
	ostringstream ofs;
	ofs << mw->getAnyCastID();
	getLogStream(LOG_DEBUG) << "TASKID:" << ofs.str() << endl;
	// Store the MessageWrapper so that we can send an ack when we are done
	_taskmap[mw->getPayLoad()] = mw;
	mw = wrapMessage(mw->getPayLoad());
	return mw;
      }
      case MessageWrapper::mwTaskProgress:
      case MessageWrapper::mwUser:{
	      
	inmsg = mw->getPayLoad();
	if (inmsg == 0){
	  // Maybe just return here? Or do we consider the digiwash corrupt??
	  getLogStream(LOG_CRIT) << "Received messageWrapper with empty payload" << endl;
	  getLogStream(LOG_CRIT) << "anycastId is " << mw->getAnyCastID() << endl;
	  getLogStream(LOG_CRIT) << "type is " << static_cast<int>(mw->getType()) << endl;
	  throw OcfaException("Received a messagewrapper with empty payload!");
	}
	// FIXME : reintroduce priority check ?      
	getLogStream(LOG_DEBUG) << "returning message with type " << static_cast<int>(inmsg->getType())<< endl;
	return mw;
      }
	break;
      case MessageWrapper::mwInternalConnect:{
	getLogStream(LOG_ERR) << "mwInternalConnect in ConnectMessagingEndPoint" << endl;
	return 0;
      }
	break;
      case MessageWrapper::mwInternalDisconnect:{
	getLogStream(LOG_CRIT) << "Lost connection" << endl;      

	// throw away the envelope but keep the payload. The caller MUST delete msg1 !
	inmsg = new ConcreteMessage(_moduleinstance, _moduleinstance, Message::BROADCAST, Message::mtModuleDisconnect, "","",0 );
	//RJM:CODEREVIEW does this transfer responsability? if it does the interface is wrong. If it does not than
	//we have a tricky issue as normally inmsg is a pointer without responsablity, so we may need to delete it 
	//and set it to NULL here.
	mw->setPayLoad(inmsg);
	return mw;
      }
      }
      return 0; //This should not hapen;
    }
Exemple #14
0
int Parser::rulelistline(){

	switch(lexer->getToken()){
	case TOK_ID:		return rule();		break;
	case TOK_LABEL:		return !label();	break; /* label returns true upon match */
	default:
		getLogStream(ocfa::misc::LOG_EMERG) << lexer->getLinenumber() << ": Error: parse error in rulelistline, unexpected '" << lexer->getLexeme() << "'\n";
		return 1;
		break;
	}
	
	return 0;
}
Exemple #15
0
 StreamPartition::~StreamPartition() {
    if (mStartTime) {
      time_t wasted=time(NULL) - mStartTime;
      if (wasted > 1) {
        getLogStream(ocfa::misc::LOG_INFO) << "Wasted "<< wasted << " seconds copying out data (+ calculating digest) that could simply have been designated using CarvFS." << std::endl;           
      }
    }
    if (mMeta) {
         map < string, misc::MetaValue * >::const_iterator p;
         for (p = mMeta->begin(); p != mMeta->end(); ++p) {
            delete p->second;
         }
         delete mMeta;
         mMeta=0;
    }
 }
Exemple #16
0
 size_t StreamPartition::streamRead(char *buf, size_t count)   {
     off_t realoffset=mPartitionOffset+mReadOffset;
     //Make sure not to read past the end of the partition.
     size_t realcount=count;
     off_t dataleft = mSize - mReadOffset;
     if ((((off_t) count) > dataleft) ) {
         realcount= (size_t) dataleft;
     }
     if (realcount == 0) {
        return 0;
     } 
     size_t rdbytes= tsk_img_read(mImage, realoffset,buf,realcount);
     if (rdbytes == (size_t) -1) {
        getLogStream(ocfa::misc::LOG_ERR) << "tsk_img_read returned -1 while requesting for " << realcount << " bytes of data at offset " << realoffset << std::endl;
        return 0;
     }
     mReadOffset+= rdbytes;
     return rdbytes;        
 }   
Exemple #17
0
int Parser::rule(){
	Expression *expr;
	std::string act;
	std::string target;
	
	expr = expression();
	match(TOK_SEMICOLON, "rule, expr part");
	act = action();
	match(TOK_SEMICOLON, "rule, action part");
	target = id();	
	match(TOK_SEMICOLON, "rule, target part");
	
	if ( act == "" || target == "" || expr == 0){
		getLogStream(ocfa::misc::LOG_EMERG) << lexer->getLinenumber() << ": Bad rule " << act.c_str() << " " << target.c_str() << std::endl;
		return 1;
	}
	
	RuleList::getInstance()->addRule( 
            new router::Rule(expr,
                             act,
                             target));
	return 0;
}
Exemple #18
0
	PolicyLoader(std::string myLib,std::string loadername):ocfa::OcfaObject("PolicyLoader","misc"),mLibHandle(0),mConstructor(0) {
           getLogStream(ocfa::misc::LOG_DEBUG) << "myLib='" << myLib << "'" << std::endl;
	   if (myLib.c_str()[0] != '/') {
	      getLogStream(ocfa::misc::LOG_DEBUG) << "No absolute path given" << std::endl;
	       std::string libpath=ocfa::misc::OcfaConfig::Instance()->getValue("ocfaroot");
	       
	       libpath += std::string("/lib/");
	       if (myLib.substr(0,3) != "lib") {
                  libpath += "lib";
		  libpath += myLib;
		  libpath += ".so";
		  getLogStream(ocfa::misc::LOG_DEBUG) << "Rewritten libpath to: '" << libpath << "'" << std::endl;
	       } else {
	          libpath += myLib;
		  getLogStream(ocfa::misc::LOG_DEBUG) << "Appended myLib to libpath. libpath now: '" << libpath << "'" << std::endl;
	       }
	       myLib=libpath;
	   } else {
             getLogStream(ocfa::misc::LOG_DEBUG) << "myLib unchanged" << std::endl;
	   }
	   getLogStream(ocfa::misc::LOG_DEBUG) << "Patched myLib='" << myLib << "'" << std::endl;
	   mLibHandle=dlopen(myLib.c_str(),RTLD_NOW|RTLD_GLOBAL);
	   if (mLibHandle == 0) {
              throw ocfa::misc::OcfaException( std::string("Problem loading library '") + 
			                 myLib + 
					 std::string("' (") + 
					 std::string(dlerror()) + 
					 std::string(")")
					 ,this);
	   }
	   mConstructor = VoidToFunction<TConstructor>::cast(dlsym(mLibHandle,loadername.c_str()));
	   if (mConstructor == 0) {
	      std::string errString=std::string("Problem looking up symbol '") + loadername + std::string("' in library '")  + 
		      myLib + std::string("' (") + std::string(dlerror()) + std::string(")");
              dlclose(mLibHandle);
	      throw ocfa::misc::OcfaException(errString,this);
	   }
	   getLogStream(ocfa::misc::LOG_NOTICE) << "Successfully loaded " <<  myLib << " (handle=" << mLibHandle << ")" << std::endl; 
	}
Exemple #19
0
    /* FIVES-PH:*/
    Rule(Expression* expr, string finalaction, string target): OcfaObject("Rule", "router"), _LimitVector(), _FinalAction(NULL), _Name(), _Negate(false), _DataType(RDT_SCALARMETA), _Expression(expr) {
                setFinalAction(finalaction, target, "");
		getLogStream(ocfa::misc::LOG_DEBUG) << "Added rule: " << *this << "\n";
        }
Exemple #20
0
 MmlsFactory::MmlsFactory(std::map<std::string,ocfa::misc::Scalar> *attributes):ocfa::OcfaObject("MmlsFactory","tsk"),mCpLib(0){
    mCpLib=carvpath_init(1,0);
    if (mCpLib == 0) {
       getLogStream(ocfa::misc::LOG_ERR) << "Problem initializing libcarvpath: " << carvpath_error_as_string(errno) << std::endl;                
    }
 }
    // this method should only be called by client-like applications
    bool ConnectMessagingEndPoint::connect(){
      ACE_SOCK_Connector _connector_send, _connector_receive ;

      // try creating a listen in range 23200-30000
      int baseport=23200;
      ReceiveSockHandler *receivesockhandler = 0;

      while (baseport < 30000){
	try {
	  receivesockhandler = new ReceiveSockHandler(baseport);
	  break;
	} catch (std::string &e){
	  getLogStream(LOG_INFO) << "SockHandler construct failed for port " << baseport << endl;
	  baseport++;
	}
      }
      if (receivesockhandler == 0){
	throw OcfaException("Create listen failed");
      } else {
	getLogStream(LOG_DEBUG) << "Listening on " << baseport << endl;
      }

      if (ACE_Reactor::instance()->register_handler(receivesockhandler, ACE_Event_Handler::ACCEPT_MASK) == -1){
	ocfaLog(LOG_ERR,"Register of receivehandler failed");
	return false;
      }
     
      // now start the thread which waits for incoming connections
      activate();

      // connect our outgoing stream
      if (_connector_send.connect(_sock_outstream,_remote_addr_send) == -1){
	ocfaLog(LOG_ERR, "connect failed"); 
	return false;  
      } else {
	ocfaLog(LOG_DEBUG, "Connector open succeeded");	
	// connected ! 
	// create message holding info, serialize and send
	ACE_INET_Addr localendpoint;
	_sock_outstream.get_local_addr(localendpoint);
	ostringstream instname; 
	instname << "Inst" << localendpoint.get_port_number();

	// delete the old modinst and replace with a more accurate one
	string mname = _moduleinstance->getModuleName();
	string mnamespace = _moduleinstance->getNameSpace(); 
	delete(_moduleinstance);
	ocfaLog(LOG_DEBUG,"IP is: " + string(localendpoint.get_host_addr()));
	_moduleinstance = new ModuleInstance(localendpoint.get_host_addr(), mname, mnamespace, instname.str());
	_moduleinstance->setPort(localendpoint.get_port_number());

	ModuleInstance *mcopy = new ModuleInstance(*_moduleinstance); 
	mcopy->setPort(localendpoint.get_port_number());
	ostringstream strbaseport;
	strbaseport << baseport;
	Message *sockinfo = new ConcreteMessage(_moduleinstance, mcopy, Message::BROADCAST, Message::mtModuleInstance, strbaseport.str(), "", 0);
	//RJM:CODEREVIEW shouldn't we be deleting mcopy
	MessageWrapper *msgwrapper = new MessageWrapper(MessageWrapper::mwInternalConnect, sockinfo);  
	getLogStream(LOG_DEBUG) << "MessageType: " <<  static_cast<int>(sockinfo->getType()) 
				<< " moduleinstance: " << sockinfo->getReceiver()->getInstanceURI() << endl;
        sndMessage(msgwrapper);	
	ocfaLog(LOG_DEBUG, "Sent message. Deleting");  
	delete msgwrapper;
	delete sockinfo;
	return true;
      }
    }
 void ConnectMessagingEndPoint::sendMessage(Message &inMessage){
   getLogStream(LOG_DEBUG) << "Creating messagewrapper" << endl;
   MessageWrapper *omsg = new MessageWrapper(MessageWrapper::mwUser, &inMessage);
   sndMessage(omsg); 
   delete omsg;
 }
 void ConnectMessagingEndPoint::sendTask(Message *msg, unsigned int id){
   getLogStream(LOG_ERR) << "sendTask not implemented" << endl;
 }