bool MsgSocket::SetSyncLinkData( SimpleString DataForSL ) { if ( DataForSL.GetLength() <= 0 ) return false; SmartLocker SL_protectSend(protectSend); if ( receivedSyncLinkMsg == true || sendSyncLinkMsg == true ) { // TOO LATE #ifdef DEBUG if ( Debug & DBG_LINKSYNC ) { fprintf( stderr, "MsgSocket::SetSyncLinkData: connexion already open. Can not set SyncLink data.\n" ); } #endif return false; } // Copy data and set Length SyncLinkData = DataForSL; return true; }
void Attribute::GenerateHeaderDescription(const SimpleString& type, const SimpleString& name, SimpleString& str, bool end) { // "<"+ type + " name=\"" + name + "\"/>" at max TemporaryMemoryBuffer MemBuff( 1 + type.GetLength() + 7 + name.GetLength() + 4 ); if ( end == true ) { snprintf( (char*)MemBuff, MemBuff.GetLength(), "<%s name=\"%s\"/>", type.GetStr(), name.GetStr() ); } else { snprintf( (char*)MemBuff, MemBuff.GetLength(), "<%s name=\"%s\">", type.GetStr(), name.GetStr() ); } str += (char*)MemBuff; //str = str + "<"+ type + " name=\"" + name; //if(end) str = str + "\"/>"; //else str = str + "\">"; }
void ControlServer::ProcessAMessage(XMLMessage* msg) { // OmiscidTrace( "in ControlServer::ProcessAMessage\n"); // OmiscidTrace( "from pid = %u \n",msg->pid); if ( msg == NULL ) { // Nothing to do return; } xmlNodePtr node = msg->GetRootNode(); SmartLocker SL_AutoProtect(AutoProtect); // if( strcmp((const char*)node->name, "controlQuery") == 0 ) if ( ControlQueryValidator.ValidateDoc(msg->doc) ) { SL_AutoProtect.Unlock(); SimpleString id; xmlAttrPtr attr = XMLMessage::FindAttribute("id", node); if ( attr != (xmlAttrPtr)NULL ) { id = SimpleString((const char*)attr->children->content); } bool ReplyAnAnswer = true; // default SimpleString str; if ( node->children == NULL ) { //global description GenerateGlobalShortDescription(str); } else { // more precise request xmlNodePtr cur_node = node->children; for(; cur_node; cur_node = cur_node->next) { SimpleString name = (const char*)(cur_node->name); //std::cerr << "tag name="<<(*it)->name <<"\n"; if( name == InOutputAttribute::input_str.GetStr() || name == InOutputAttribute::output_str.GetStr() || name == InOutputAttribute::inoutput_str.GetStr() ) { // OmiscidTrace( " process io : %s \n", (*it)->name.GetStr()); ProcessInOutputQuery(cur_node, str); } else if( name == VariableAttribute::VariableStr ) { ProcessVariableQuery(cur_node, msg->pid, str); } else if( name == "connect" ) { ProcessConnectQuery(cur_node, str); } else if( name == "subscribe" ) { ProcessSubscribeQuery(cur_node, msg->pid, true, str); } else if( name == "unsubscribe" ) { ReplyAnAnswer = false; ProcessSubscribeQuery(cur_node, msg->pid, false, str); } else if( name == "lock" ) { ProcessLockQuery(cur_node, msg->pid, true, str); } else if( name == "unlock" ) { ProcessLockQuery(cur_node, msg->pid, false, str); } else if( name == "fullDescription" ) { ProcessFullDescriptionQuery(cur_node, str); } else { // Should not appear OmiscidError( "unknown tag : %s\n", name.GetStr() ); } } // OmiscidError( "Send : %s \n", str.GetStr()); } if ( ReplyAnAnswer == true ) { str = "<controlAnswer id=\""+id+"\">" + str + "</controlAnswer>"; #ifdef DEBUG SL_AutoProtect.Lock(); if ( ControlAnswerValidator.ValidateDoc( str ) == false ) { OmiscidError( "ControlServer::ProcessAMessage: bad ControlAnswer sent.\n" ); } SL_AutoProtect.Unlock(); #endif SmartLocker SL_TcpServer_listConnections(TcpServer::listConnections); MsgSocket* ms = FindClientFromId( msg->pid ); if( ms != (MsgSocket*)NULL ) { try { ms->Send((int)str.GetLength(), str.GetStr()); } catch( SocketException& e ) { OmiscidError( "Error when responding to a client request : %s (%d)\n", e.msg.GetStr(), e.err ); } } } } else { OmiscidError( "waited : controlQuery, received='%s'\n", node->name); msg->Display(stderr); } }
ServiceProxy::ServiceProxy( unsigned int PeerId, SimpleString eHostName, int eControlPort, ServiceProperties& ServiceProps ) : ControlClient(PeerId) { SimpleString TmpString; VariableAttribute * VarAtt; InOutputAttribute * IOAtt; int Pos; unsigned int Port; HostName = eHostName; ControlPort = eControlPort; FullDescription = false; // Is the description TmpString = ServiceProps["desc"].GetValue(); //if ( ServiceProps.IsDefined( "name" ) ) //{ // OmiscidError( "Warning, forced fallback for '%s' (%s).\n", // ServiceProps[NameString].GetValue().GetStr(), ServiceProps["id"].GetValue().GetStr() ); //} //else //{ // OmiscidError( "Warning, forced fallback for %8.8x.\n", PeerId ); //} //if ( TmpString == "forced fallback" ) // OmiscidTrace( "Working on'%s' (%s).\n", // ServiceProps[ControlServer::NameString].GetValue().GetStr(), ServiceProps["id"].GetValue().GetStr() ); if ( TmpString == "full" ) { FullDescription = true; } for( Pos = 0; Pos < ServiceProps.GetNumberOfProperties(); Pos++ ) { ServiceProperty& LocalProp = ServiceProps.GetProperty(Pos); if ( LocalProp.GetName() == "desc" ) { continue; } // SimpleString TmpName = LocalProp.GetName(); // Parse property TmpString = LocalProp.GetValue(); char * TmpChar = (char*)TmpString.GetStr(); switch( TmpString[0] ) { // Work on Variables case 'c': if ( TmpString.GetLength() <= 2 || TmpString[1] != '/' ) { FullDescription = false; continue; } // Ok, something like c/... VarAtt = new OMISCID_TLM VariableAttribute( LocalProp.GetName() ); if ( VarAtt == NULL ) { FullDescription = false; continue; } VarAtt->SetValue( TmpChar+2 ); VarAtt->SetAccessConstant(); listVariableName.Add( LocalProp.GetName() ); listVariableAttr.Add( VarAtt ); break; case 'r': if ( TmpString.GetLength() != 1 ) { FullDescription = false; continue; } // Ok, something like r/... VarAtt = new OMISCID_TLM VariableAttribute( LocalProp.GetName() ); if ( VarAtt == NULL ) { FullDescription = false; continue; } VarAtt->SetAccessRead(); listVariableName.Add( LocalProp.GetName() ); listVariableAttr.Add( VarAtt ); break; case 'w': if ( TmpString.GetLength() != 1 ) { FullDescription = false; continue; } // Ok, something like w/... VarAtt = new OMISCID_TLM VariableAttribute( LocalProp.GetName() ); if ( VarAtt == NULL ) { FullDescription = false; continue; } VarAtt->SetAccessReadWrite(); listVariableName.Add( LocalProp.GetName() ); listVariableAttr.Add( VarAtt ); break; // Work on Connectors case 'i': if ( TmpString[1] != '/' || TmpString[2] < '0' || TmpString[2] > '9' ) { FullDescription = false; continue; } // Check if we've got a correct port Port = 0; Port = atoi(TmpChar+2); if ( Port == 0 || Port >= 0x0000ffff ) { FullDescription = false; continue; } IOAtt = new OMISCID_TLM InOutputAttribute( LocalProp.GetName(), NULL, AnInput ); if ( IOAtt == NULL ) { FullDescription = false; continue; } IOAtt->SetTcpPort( (unsigned short)Port ); listInputName.Add( LocalProp.GetName() ); listInputAttr.Add( IOAtt ); break; case 'o': if ( TmpString[1] != '/' || TmpString[2] < '0' || TmpString[2] > '9' ) { FullDescription = false; continue; } // Check if we've got a correct port Port = 0; Port = atoi(TmpChar+2); if ( Port == 0 || Port >= 0x0000ffff ) { FullDescription = false; continue; } IOAtt = new OMISCID_TLM InOutputAttribute( LocalProp.GetName(), NULL, AnOutput ); if ( IOAtt == NULL ) { FullDescription = false; continue; } IOAtt->SetTcpPort( (unsigned short)Port ); listOutputName.Add( LocalProp.GetName() ); listOutputAttr.Add( IOAtt ); break; case 'd': if ( TmpString[1] != '/' || TmpString[2] < '0' || TmpString[2] > '9' ) { FullDescription = false; continue; } // Check if we've got a correct port Port = 0; Port = atoi(TmpChar+2); if ( Port == 0 || Port >= 0x0000ffff ) { FullDescription = false; continue; } IOAtt = new OMISCID_TLM InOutputAttribute( LocalProp.GetName(), NULL, AnInOutput ); if ( IOAtt == NULL ) { FullDescription = false; continue; } IOAtt->SetTcpPort( (unsigned short)Port ); listInOutputName.Add( LocalProp.GetName() ); listInOutputAttr.Add( IOAtt ); break; default: FullDescription = false; continue; } } //if ( FullDescription == false ) //{ // UpdateDescription(); //} }