void startSetupParser(void *data, const char *name, const char **attr) { CVSCPLog *pLog = (CVSCPLog *)data; if (NULL == pLog) return; if ((0 == strcmp(name, "setup")) && (0 == depth_setup_parser)) { for (int i = 0; attr[i]; i += 2) { std::string attribute = attr[i + 1]; vscp_trim(attribute); if (0 == strcmp(attr[i], "path")) { if (!attribute.empty()) { pLog->m_path = attribute; } } else if (0 == strcmp(attr[i], "filter")) { if (!attribute.empty()) { if (!vscp_readFilterFromString(&pLog->m_vscpfilter, attribute)) { syslog(LOG_ERR, "Unable to read event receive filter."); } } } else if (0 == strcmp(attr[i], "mask")) { if (!attribute.empty()) { if (!vscp_readMaskFromString(&pLog->m_vscpfilter, attribute)) { syslog(LOG_ERR, "Unable to read event receive mask."); } } } else if (0 == strcmp(attr[i], "brewrite")) { if (!attribute.empty()) { if (0 == vscp_strcasecmp(attribute.c_str(), "TRUE")) { pLog->m_flags |= LOG_FILE_OVERWRITE; } } } else if (0 == strcmp(attr[i], "bworksfmt")) { if (!attribute.empty()) { if (0 == vscp_strcasecmp(attribute.c_str(), "TRUE")) { pLog->m_flags |= LOG_FILE_VSCP_WORKS; } } } } } depth_setup_parser++; }
void startSetupParser( void *data, const char *name, const char **attr ) { Csocketcan *pObj = (Csocketcan *)data; if (NULL == pObj) return; if ((0 == strcmp(name, "setup")) && (0 == depth_setup_parser)) { for (int i = 0; attr[i]; i += 2) { std::string attribute = attr[i + 1]; vscp_trim(attribute); if (0 == strcasecmp(attr[i], "interface")) { if (!attribute.empty()) { pObj->m_interface = attribute; } } else if (0 == strcasecmp(attr[i], "filter")) { if (!attribute.empty()) { if (!vscp_readFilterFromString(&pObj->m_vscpfilter, attribute)) { syslog(LOG_ERR, "Unable to read event receive filter."); } } } else if (0 == strcasecmp(attr[i], "mask")) { if (!attribute.empty()) { if (!vscp_readMaskFromString(&pObj->m_vscpfilter, attribute)) { syslog(LOG_ERR, "Unable to read event receive mask."); } } } } } depth_setup_parser++; }
bool Cmqttobj::open( const char *pUsername, const char *pPassword, const char *pHost, const char *pPrefix, const char *pConfig) { bool rv = true; wxString str; wxString wxstr = wxString::FromAscii(pConfig); m_username = wxString::FromAscii(pUsername); m_password = wxString::FromAscii(pPassword); m_host = wxString::FromAscii(pHost); m_prefix = wxString::FromAscii(pPrefix); // Parse the configuration string. It should // have the following form // path // wxStringTokenizer tkz(wxString::FromAscii(pConfig), _(";\n")); // Check if we should publish or subscribe if ( tkz.HasMoreTokens() ) { // Check for subscribe/publish str = tkz.GetNextToken(); str.Trim(); str.Trim(false); str.MakeUpper(); if ( wxNOT_FOUND != str.Find( _("PUBLISH") ) ) { m_bSubscribe = false; } } // Get topic from configuration string if ( tkz.HasMoreTokens() ) { m_topic = tkz.GetNextToken(); } // Get MQTT host from configuration string if ( tkz.HasMoreTokens() ) { m_hostMQTT = tkz.GetNextToken(); } // Get MQTT host port from configuration string if ( tkz.HasMoreTokens() ) { m_portMQTT = vscp_readStringValue(tkz.GetNextToken()); } // Get MQTT user from configuration string if ( tkz.HasMoreTokens() ) { m_usernameMQTT = tkz.GetNextToken(); } // Get MQTT password from configuration string if ( tkz.HasMoreTokens() ) { m_passwordMQTT = tkz.GetNextToken(); } // Get MQTT keep alive from configuration string if ( tkz.HasMoreTokens() ) { m_keepalive = vscp_readStringValue(tkz.GetNextToken()); } // First log on to the host and get configuration // variables if ( VSCP_ERROR_SUCCESS != m_srv.doCmdOpen( m_host, m_username, m_password) ) { #ifndef WIN32 syslog(LOG_ERR, "%s", (const char *) "Unable to connect to VSCP TCP/IP interface. Terminating!"); #endif return false; } // Find the channel id uint32_t ChannelID; m_srv.doCmdGetChannelID( &ChannelID ); // The server should hold configuration data for each sensor // we want to monitor. // // We look for // // _type - “subscribe” to subscribe to a MQTT topic. ”publish” to // publish events to a MQTT topic. Defaults to “subscribe”. // // _topic - This is a text string identifying the topic. It is // recommended that this string starts with “vscp/”. // Defaults to “vscp” // // _qos - MQTT QOS value. Defaults to 0. // // _host - IP address + port or a DNS resolvable address + port on the // form host:port to the remote host. // Mandatory and must be declared either in the configuration // string or in this variable. Defaults to “localhost:1883” // // _user - Username used to log in on the remote sever. // Defaults to empty. // // _password - Password used to login on the remote server. // Defaults to empty. // // _keepalive - Keepalive value for channel. Defaults to 60. // // _filter - Standard VSCP filter in string form. // 1,0x0000,0x0006, // ff:ff:ff:ff:ff:ff:ff:01:00:00:00:00:00:00:00:00 // as priority,class,type,GUID // Used to filter what events that is received from // the mqtt interface. If not give all events // are received. // _mask - Standard VSCP mask in string form. // 1,0x0000,0x0006, // ff:ff:ff:ff:ff:ff:ff:01:00:00:00:00:00:00:00:00 // as priority,class,type,GUID // Used to filter what events that is received from // the mqtt interface. If not give all events // are received. // wxString strName = m_prefix + wxString::FromAscii("_type"); m_srv.getVariableString(strName, &str); // Check for subscribe/publish str = tkz.GetNextToken(); str.Trim(); str.Trim(false); str.MakeUpper(); if ( wxNOT_FOUND != str.Find(_("publish") ) ) { m_bSubscribe = false; } strName = m_prefix + wxString::FromAscii("_topic"); if ( VSCP_ERROR_SUCCESS == m_srv.getVariableString( strName, &str ) ) { m_topic = str; } strName = m_prefix + wxString::FromAscii("_host"); if ( VSCP_ERROR_SUCCESS == m_srv.getVariableString( strName, &m_hostMQTT ) ) { m_hostMQTT = str; } strName = m_prefix + wxString::FromAscii("_username"); if ( VSCP_ERROR_SUCCESS == m_srv.getVariableString( strName, &str ) ) { m_usernameMQTT = str; } strName = m_prefix + wxString::FromAscii("_password"); if ( VSCP_ERROR_SUCCESS == m_srv.getVariableString( strName, &m_passwordMQTT ) ) { m_passwordMQTT = str; } strName = m_prefix + wxString::FromAscii("_keepalive"); int intval; if ( VSCP_ERROR_SUCCESS == m_srv.getVariableInt( strName, &intval ) ) { m_keepalive = intval; } strName = m_prefix + wxString::FromAscii( "_qos" ); if ( VSCP_ERROR_SUCCESS == m_srv.getVariableInt( strName, &intval ) ) { m_topic_list[ 0 ].qos = intval; } strName = m_prefix + wxString::FromAscii("_filter"); if ( VSCP_ERROR_SUCCESS == m_srv.getVariableString( strName, &str ) ) { vscp_readFilterFromString(&m_vscpfilter, str); } strName = m_prefix + wxString::FromAscii("_mask"); if ( VSCP_ERROR_SUCCESS == m_srv.getVariableString( strName, &str ) ) { vscp_readMaskFromString(&m_vscpfilter, str); } strName = m_prefix + wxString::FromAscii("_simplify"); if ( VSCP_ERROR_SUCCESS == m_srv.getVariableString( strName, &str ) ) { m_simplify = str; } if ( m_simplify.Length() ) { m_bSimplify = true; wxStringTokenizer tkzSimple( m_simplify, _(",\n")); // simple class if ( tkzSimple.HasMoreTokens() ) { m_simple_class = vscp_readStringValue(tkzSimple.GetNextToken()); } // simple type if ( tkzSimple.HasMoreTokens() ) { m_simple_type = vscp_readStringValue(tkzSimple.GetNextToken()); } // simple coding if ( tkzSimple.HasMoreTokens() ) { m_simple_coding = vscp_readStringValue(tkzSimple.GetNextToken()); } // simple zone if ( tkzSimple.HasMoreTokens() ) { m_simple_zone = vscp_readStringValue(tkzSimple.GetNextToken()); } // simple subzone if (tkzSimple.HasMoreTokens()) { m_simple_subzone = vscp_readStringValue(tkzSimple.GetNextToken()); } } else { m_bSimplify = false; } if ( m_bSubscribe ) { m_topic_list[ 0 ].topic = new char( m_topic.Length() + 1 ); if ( NULL != m_topic_list[ 0 ].topic ) { memset( (void *)m_topic_list[ 0 ].topic, 0, m_topic.Length() + 1 ); memcpy( ( void * )m_topic_list[ 0 ].topic, m_topic.mbc_str(), m_topic.Length() ); } } // Close the channel m_srv.doCmdClose(); // start the worker thread m_pthreadWork = new CWrkThread(); if (NULL != m_pthreadWork) { m_pthreadWork->m_pObj = this; m_pthreadWork->Create(); m_pthreadWork->Run(); } else { rv = false; } return rv; }
bool CUserList::addUser( const wxString& strUser, bool bUnpackNote ) { wxString strToken; wxString user; wxString password; wxString fullname; wxString strNote; vscpEventFilter filter; wxString userRights; wxString allowedRemotes; wxString allowedEvents; wxStringTokenizer tkz( strUser, _(";") ); // user if ( tkz.HasMoreTokens() ) { user = tkz.GetNextToken(); } // password if ( tkz.HasMoreTokens() ) { password = tkz.GetNextToken(); } // fullname if ( tkz.HasMoreTokens() ) { fullname = tkz.GetNextToken(); } // filter if ( tkz.HasMoreTokens() ) { vscp_readFilterFromString( &filter, tkz.GetNextToken() ); } // mask if ( tkz.HasMoreTokens() ) { vscp_readMaskFromString( &filter, tkz.GetNextToken() ); } // user rights if ( tkz.HasMoreTokens() ) { userRights = tkz.GetNextToken(); } // allowed remotes if ( tkz.HasMoreTokens() ) { allowedRemotes = tkz.GetNextToken(); } // allowed events if ( tkz.HasMoreTokens() ) { allowedEvents = tkz.GetNextToken(); } // note if ( tkz.HasMoreTokens() ) { if ( bUnpackNote ) { wxString wxstr = tkz.GetNextToken(); size_t len = wxBase64Decode( NULL, 0, wxstr ); if ( 0 == len ) return false; uint8_t *pbuf = new uint8_t[len]; if ( NULL == pbuf ) return false; len = wxBase64Decode( pbuf, len, wxstr ); strNote = wxString::FromUTF8( (const char *)pbuf, len ); delete [] pbuf; } else { strNote = tkz.GetNextToken(); } } return addUser( user, password, fullname, strNote, &filter, userRights, allowedRemotes, allowedEvents ); }
bool CRawEthernet::open(const char *pUsername, const char *pPassword, const char *pHost, short port, const char *pPrefix, const char *pConfig) { bool rv = true; wxString wxstr = wxString::FromAscii(pConfig); m_username = wxString::FromAscii(pUsername); m_password = wxString::FromAscii(pPassword); m_host = wxString::FromAscii(pHost); m_port = port; m_prefix = wxString::FromAscii(pPrefix); // Parse the configuration string. It should // have the following form // path // wxStringTokenizer tkz(wxString::FromAscii(pConfig), _(";\n")); // Look for rawethernet interface in configuration string if (tkz.HasMoreTokens()) { // Interface m_interface = tkz.GetNextToken(); } // Local Mac wxString localMac; if (tkz.HasMoreTokens()) { localMac = tkz.GetNextToken(); localMac.MakeUpper(); wxStringTokenizer tkzmac(localMac, _(":\n")); for (int i = 0; i < 6; i++) { if (!tkzmac.HasMoreTokens()) break; wxString str = _("0X") + tkzmac.GetNextToken(); m_localMac[ i ] = vscp_readStringValue(str); m_localGUIDtx.setAt((9 + i), m_localMac[ i ]); m_localGUIDrx.setAt((9 + i), m_localMac[ i ]); } } // First log on to the host and get configuration // variables if ( VSCP_ERROR_SUCCESS != m_srv.doCmdOpen( m_host, m_username, m_password ) ) { syslog(LOG_ERR, "%s", (const char *) "Unable to connect to VSCP TCP/IP interface. Terminating!"); return false; } // Find the channel id uint32_t ChannelID; m_srv.doCmdGetChannelID(&ChannelID); // The server should hold configuration data for each sensor // we want to monitor. // // We look for // // _interface - The ethernet interface to use. Typically this // is “eth0, eth0, eth1... // // _localmac - The MAC address for our outgoing frames. // Typically on the form 00:26:55:CA:1F:DA // // _filter - Standard VSCP filter in string form. // 1,0x0000,0x0006, // ff:ff:ff:ff:ff:ff:ff:01:00:00:00:00:00:00:00:00 // as priority,class,type,GUID // Used to filter what events that is received from // the socketcan interface. If not give all events // are received. // _mask - Standard VSCP mask in string form. // 1,0x0000,0x0006, // ff:ff:ff:ff:ff:ff:ff:01:00:00:00:00:00:00:00:00 // as priority,class,type,GUID // Used to filter what events that is received from // the socketcan interface. If not give all events // are received. // wxString str; wxString strName = m_prefix + wxString::FromAscii("_interface"); m_srv.getVariableString(strName, &m_interface); // Local Mac if (tkz.HasMoreTokens()) { localMac = tkz.GetNextToken(); localMac.MakeUpper(); wxStringTokenizer tkzmac(localMac, _(":\n")); for (int i = 0; i < 6; i++) { if (!tkzmac.HasMoreTokens()) break; wxString str = _("0X") + tkzmac.GetNextToken(); m_localMac[ i ] = vscp_readStringValue(str); m_localGUIDtx.setAt((9 + i), m_localMac[ i ]); m_localGUIDrx.setAt((9 + i), m_localMac[ i ]); } } strName = m_prefix + wxString::FromAscii("_filter"); if (VSCP_ERROR_SUCCESS == m_srv.getVariableString(strName, &str)) { vscp_readFilterFromString(&m_vscpfilter, str); } strName = m_prefix + wxString::FromAscii("_mask"); if (VSCP_ERROR_SUCCESS == m_srv.getVariableString(strName, &str)) { vscp_readMaskFromString(&m_vscpfilter, str); } // start the read workerthread m_preadWorkThread = new CWrkReadThread(); if (NULL != m_preadWorkThread) { m_preadWorkThread->m_pObj = this; m_preadWorkThread->Create(); m_preadWorkThread->Run(); } else { rv = false; } // start the write workerthread m_pwriteWorkThread = new CWrkWriteThread(); if (NULL != m_pwriteWorkThread) { m_pwriteWorkThread->m_pObj = this; m_pwriteWorkThread->Create(); m_pwriteWorkThread->Run(); } else { rv = false; } // Close the channel m_srv.doCmdClose(); return rv; }
bool CVSCPLog::open(const char *pUsername, const char *pPassword, const char *pHost, short port, const char *pPrefix, const char *pConfig) { std::string str = std::string(pConfig); m_username = std::string(pUsername); m_password = std::string(pPassword); m_host = std::string(pHost); m_port = port; m_prefix = std::string(pPrefix); // Parse the configuration string. It should // have the following form // path // std::deque<std::string> tokens; vscp_split(tokens, std::string(pConfig), ";"); // Check for path in configuration string if (tokens.empty()) { syslog(LOG_ERR, "A path must be configured."); } // Path m_path = tokens.front(); tokens.pop_front(); // Check for rewrite in configuration string // valid is "true|false" if (!tokens.empty()) { std::string str; str = tokens.front(); tokens.pop_front(); vscp_trim(str); if (0 == vscp_strcasecmp(str.c_str(), "TRUE")) { m_flags |= LOG_FILE_OVERWRITE; } else { m_flags &= ~LOG_FILE_OVERWRITE; } } // Check for vscpworksfmt in configuration string // valid is "true|false" if (!tokens.empty()) { std::string str; str = tokens.front(); tokens.pop_front(); vscp_trim(str); if (0 == vscp_strcasecmp(str.c_str(), "TRUE")) { m_flags |= LOG_FILE_VSCP_WORKS; } else { m_flags &= ~LOG_FILE_VSCP_WORKS; } } // Filter if (!tokens.empty()) { std::string str; str = tokens.front(); tokens.pop_front(); vscp_readFilterFromString(&m_vscpfilter, str); } // Mask if (!tokens.empty()) { std::string str; str = tokens.front(); tokens.pop_front(); vscp_readMaskFromString(&m_vscpfilter, str); } // start the worker thread m_pWorkObj = new CLogWrkThreadObj(); if (NULL != m_pWorkObj) { m_pWorkObj->m_pLog = this; if (pthread_create(&m_pWrkThread, NULL, threadWorker, m_pWorkObj)) { syslog(LOG_CRIT, "Unable to start logger driver worker thread."); return false; } } else { syslog(LOG_CRIT, "Unable to allocate thread object."); return false; } return true; }
bool Csocketcan::open(const char *pUsername, const char *pPassword, const char *pHost, short port, const char *pPrefix, const char *pConfig) { bool rv = true; wxString wxstr = wxString::FromAscii(pConfig); m_username = wxString::FromAscii(pUsername); m_password = wxString::FromAscii(pPassword); m_host = wxString::FromAscii(pHost); m_port = port; m_prefix = wxString::FromAscii(pPrefix); // Parse the configuration string. It should // have the following form // path // wxStringTokenizer tkz(wxString::FromAscii(pConfig), _(";\n")); // Check for socketcan interface in configuration string if (tkz.HasMoreTokens()) { // Interface m_interface = tkz.GetNextToken(); } // First log on to the host and get configuration // variables if ( VSCP_ERROR_SUCCESS != m_srv.doCmdOpen(m_host, m_username, m_password ) ) { syslog(LOG_ERR, "%s", (const char *) "Unable to connect to VSCP TCP/IP interface. Terminating!"); return false; } // Find the channel id uint32_t ChannelID; m_srv.doCmdGetChannelID(&ChannelID); //m_srv.doCmdGetGUID( m_ifguid ); // The server should hold configuration data for each sensor // we want to monitor. // // We look for // // _interface - The socketcan interface to use. Typically this // is “can0, can0, can1... // // _filter - Standard VSCP filter in string form. // 1,0x0000,0x0006, // ff:ff:ff:ff:ff:ff:ff:01:00:00:00:00:00:00:00:00 // as priority,class,type,GUID // Used to filter what events that is received from // the socketcan interface. If not give all events // are received. // _mask - Standard VSCP mask in string form. // 1,0x0000,0x0006, // ff:ff:ff:ff:ff:ff:ff:01:00:00:00:00:00:00:00:00 // as priority,class,type,GUID // Used to filter what events that is received from // the socketcan interface. If not give all events // are received. // wxString str; wxString strName = m_prefix + wxString::FromAscii("_interface"); m_srv.getVariableString(strName, &m_interface); strName = m_prefix + wxString::FromAscii("_filter"); if (m_srv.getVariableString(strName, &str)) { vscp_readFilterFromString(&m_vscpfilter, str); } strName = m_prefix + wxString::FromAscii("_mask"); if (m_srv.getVariableString(strName, &str)) { vscp_readMaskFromString(&m_vscpfilter, str); } m_srv.doClrInputQueue(); // start the workerthread m_pthreadWorker = new CSocketCanWorkerTread(); if (NULL != m_pthreadWorker) { m_pthreadWorker->m_pObj = this; m_pthreadWorker->Create(); m_pthreadWorker->Run(); } else { rv = false; } // Close the channel m_srv.doCmdClose(); return rv; }
bool Csocketcan::open(const char *pUsername, const char *pPassword, const char *pHost, short port, const char *pPrefix, const char *pConfig) { bool rv = true; std::string wxstr = std::string(pConfig); m_username = std::string(pUsername); m_password = std::string(pPassword); m_host = std::string(pHost); m_port = port; m_prefix = std::string(pPrefix); // Parse the configuration string. It should // have the following form path std::deque<std::string> tokens; vscp_split( tokens, std::string(pConfig), ";" ); // Check for socketcan interface in configuration string if (!tokens.empty()) { // Interface m_interface = tokens.front(); tokens.pop_front(); } // First log on to the host and get configuration // variables if (VSCP_ERROR_SUCCESS != m_srv.doCmdOpen(m_host, m_port, m_username, m_password)) { syslog(LOG_ERR, "%s", (const char *)"Unable to connect to " "VSCP TCP/IP interface. Terminating!"); return false; } // Find the channel id uint32_t ChannelID; m_srv.doCmdGetChannelID(&ChannelID); // m_srv.doCmdGetGUID( m_ifguid ); // The server should hold configuration data for each sensor // we want to monitor. // // We look for // // _interface - The socketcan interface to use. Typically this // is “can0, can0, can1... // // _filter - Standard VSCP filter in string form. // 1,0x0000,0x0006, // ff:ff:ff:ff:ff:ff:ff:01:00:00:00:00:00:00:00:00 // as priority,class,type,GUID // Used to filter what events that is received from // the socketcan interface. If not give all events // are received. // _mask - Standard VSCP mask in string form. // 1,0x0000,0x0006, // ff:ff:ff:ff:ff:ff:ff:01:00:00:00:00:00:00:00:00 // as priority,class,type,GUID // Used to filter what events that is received from // the socketcan interface. If not give all events // are received. // // <setup interface="vcan0" // filter="" // mask="" /> // std::string str; std::string strName = m_prefix + std::string("_interface"); m_srv.getRemoteVariableValue(strName, m_interface); strName = m_prefix + std::string("_filter"); if (m_srv.getRemoteVariableValue(strName, str)) { vscp_readFilterFromString(&m_vscpfilter, str); } strName = m_prefix + std::string("_mask"); if (m_srv.getRemoteVariableValue(strName, str)) { vscp_readMaskFromString(&m_vscpfilter, str); } m_srv.doClrInputQueue(); // XML setup std::string strSetupXML; strName = m_prefix + std::string("_setup"); if (VSCP_ERROR_SUCCESS == m_srv.getRemoteVariableValue(strName, strSetupXML, true)) { XML_Parser xmlParser = XML_ParserCreate("UTF-8"); XML_SetUserData(xmlParser, this); XML_SetElementHandler(xmlParser, startSetupParser, endSetupParser); int bytes_read; void *buff = XML_GetBuffer(xmlParser, XML_BUFF_SIZE); strncpy((char *)buff, strSetupXML.c_str(), strSetupXML.length()); bytes_read = strSetupXML.length(); if (!XML_ParseBuffer(xmlParser, bytes_read, bytes_read == 0)) { syslog(LOG_ERR, "Failed parse XML setup."); } XML_ParserFree(xmlParser); } // start the workerthread if ( pthread_create( &m_threadWork, NULL, workerThread, this ) ) { syslog( LOG_CRIT, "Unable to start worker thread." ); return false; } // Close the channel m_srv.doCmdClose(); return rv; }