예제 #1
0
bool TMdPrm::cfgChange( TCfg &co, const TVariant &pc )
{
    //Change TYPE parameter
    if(co.name() == "TYPE") { setType(co.getS()); return true; }
    if(mDA) mDA->cfgChange(co, pc);
    if(!autoC()) modif();
    return true;
}
예제 #2
0
void MTable::setVal( TCfg &cf, const string &val, bool tr )
{
    if(!cf.dblVal()) {
	cf.setS(val);
	if(!tr && cf.fld().flg()&TCfg::TransltText && !cf.noTransl()) Mess->translReg(val, "db:"+fullDBName()+"#"+cf.name());
    }
    else cf.setS(val, (tr?TCfg::DblValTwo:TCfg::DblValOne));
}
예제 #3
0
파일: sound.cpp 프로젝트: Strongc/openscada
bool TMdContr::cfgChange( TCfg &co, const TVariant &pc )
{
    TController::cfgChange(co, pc);

    if(startStat() && (co.name() == "CARD" || co.name() == "SMPL_RATE" || co.name() == "SMPL_TYPE")) stop();

    return true;
}
예제 #4
0
파일: dbf_mod.cpp 프로젝트: alimon/oscada
void MTable::fieldPrmSet( TCfg &e_cfg, db_str_rec &n_rec )
{
    memset(&n_rec, 0, sizeof(db_str_rec));

    strncpy(n_rec.name, e_cfg.name().c_str(), 10);
    switch(e_cfg.fld().type())
    {
	case TFld::String:
	    n_rec.tip_fild  = 'C';
	    n_rec.len_fild  = vmin(255,e_cfg.fld().len());
	    n_rec.dec_field = 0;
	    break;
	case TFld::Integer:
	    n_rec.tip_fild = 'N';
	    n_rec.len_fild = (e_cfg.fld().len() == 0) ? 5 : vmin(255,e_cfg.fld().len());
	    n_rec.dec_field = 0;
	    break;
	case TFld::Real:
	    n_rec.tip_fild = 'N';
	    n_rec.len_fild = (e_cfg.fld().len() == 0) ? 7 : vmin(255,e_cfg.fld().len());
	    n_rec.dec_field = (e_cfg.fld().dec() == 0) ? 2 : vmin(255,e_cfg.fld().dec());
	    break;
	case TFld::Boolean:
	    n_rec.tip_fild  = 'L';
	    n_rec.len_fild  = 1;
	    n_rec.dec_field = 0;
	    break;
	default: break;
    }
}
예제 #5
0
void MTable::setVal( TCfg &cfg, const string &val )
{
    switch( cfg.fld().type() )
    {
	case TFld::String:	cfg.setS(val);	break;
	case TFld::Integer:	cfg.setI(atoi(val.c_str()));	break;
	case TFld::Real:	cfg.setR(atof(val.c_str()));	break;
	case TFld::Boolean:	cfg.setB(atoi(val.c_str()));	break;
	default: break;
    }
}
예제 #6
0
string MTable::getVal( TCfg &cfg )
{
    switch( cfg.fld().type() )
    {
	case TFld::String:	return cfg.getS();
	case TFld::Integer:	return SYS->int2str(cfg.getI());
	case TFld::Real:	return SYS->real2str(cfg.getR());
	case TFld::Boolean:	return SYS->int2str(cfg.getB());
	default: break;
    }
    return "";
}
예제 #7
0
파일: tconfig.cpp 프로젝트: alimon/oscada
bool TCfg::operator==( TCfg &cfg )
{
    if(fld().type() == cfg.fld().type())
	switch(fld().type()) {
	    case TFld::String:	return (getS() == cfg.getS());
	    case TFld::Integer:	return (getI() == cfg.getI());
	    case TFld::Real:	return (getR() == cfg.getR());
	    case TFld::Boolean:	return (getB() == cfg.getB());
	    default: break;
	}
    return false;
}
예제 #8
0
bool TMdContr::cfgChange( TCfg &icfg )
{
    TController::cfgChange(icfg);

    try
    {
	if(icfg.name() == "EndPoint" && enableStat())
	{
	    tr.at().setAddr("TCP:"+epParse());
	    ResAlloc res(nodeRes(), false);
	    SecuritySetting ss("", -1);
	    if(epLst.find(icfg.getS()) != epLst.end()) ss = epLst[icfg.getS()];
	    res.release();

	    if(ss.policy.size() && mSecPol.fld().values().find(ss.policy) != string::npos)
	    {
		setSecPolicy(ss.policy);
		setSecMessMode(ss.messageMode);
	    }

	    XML_N req("opc.tcp");

	    //> Send FindServers request for EndPoints list provide
	    req.setAttr("id", "FindServers");
	    reqService(req);

	    res.request(true);
	    epLst.clear();
	    for(unsigned i_s = 0; i_s < req.childSize(); i_s++)
		for(unsigned i_d = 0; i_d < req.childGet(i_s)->childSize(); i_d++)
		    epLst[req.childGet(i_s)->childGet(i_d)->text()] = SecuritySetting();
	    res.release();

	    //> Send GetEndpoints request for EndPoints list provide
	    req.clear()->setAttr("id", "GetEndpoints");
	    reqService(req);

	    res.request(true);
	    for(unsigned i_ch = 0; i_ch < req.childSize(); i_ch++)
	    {
		XML_N *xep = req.childGet(i_ch);
		string ep = xep->attr("endpointUrl");
		if(epLst.find(ep) != epLst.end()) ep += "/"+TSYS::strParse(xep->attr("securityPolicyUri"),1,"#")+"/"+xep->attr("securityMode");
		epLst[ep] = SecuritySetting(TSYS::strParse(xep->attr("securityPolicyUri"),1,"#"), atoi(xep->attr("securityMode").c_str()));
	    }
	}
	else if(icfg.name() == "SecPolicy")
	{
	    if(icfg.getS() == "None" && secMessMode() != MS_None)	setSecMessMode(MS_None);
	    if(icfg.getS() != "None" && secMessMode() == MS_None)	setSecMessMode(MS_Sign);
	}
	else if(icfg.name() == "SecMessMode" &&
		((icfg.getI() != MS_None && secPolicy() == "None") || (icfg.getI() == MS_None && secPolicy() != "None")))
	    return false;
    } catch(...) { }

    return true;
}
예제 #9
0
파일: dbf_mod.cpp 프로젝트: alimon/oscada
void MTable::setVal( TCfg &cfg, const string &val )
{
    switch(cfg.fld().type()) {
	case TFld::String: {
	    //Remove spaces from end
	    int i;
	    for(i = val.size(); i > 0 && val[i-1] == ' '; i--) ;
	    cfg.setS(Mess->codeConvIn(codepage.c_str(),val.substr(0,i)));
	    break;
	}
	case TFld::Integer:	cfg.setI(s2i(val));	break;
	case TFld::Real:	cfg.setR(s2r(val));	break;
	case TFld::Boolean:	cfg.setB(val.c_str()[0]=='T');	break;
	default: break;
    }
}
예제 #10
0
void readFlg( TCfg& cfg, const char *name, int& flag ) throw (TException) {
	const char *s;
	//try {
	  
	s = cfg.getValue( name );
	//} catch( TRequestExc &e ) {
	//	sprintf( msg, "в конфигурационном файле отсутствует параметр %s", name );
	//	logfile->error(msg);
	//	sprintf( msg, "сообщение класса:%s", e.text() );
	//	logfile->error(msg);
	//	throw;
	//}
	//sprintf( msg, "%s = %s", name, s );
	//logfile->debug(msg);

	if( s[0] == 0 || ( s[0] == '0' && s[1] == 0 ) ) {
		flag = 0;
		return;
	}
	if( s[0] == '1' && s[1] == 0 ) {
		flag = 1;
		return;
	}

	sprintf( msg, "Параметр %s должен быть 0, 1 или пустым. Его значение %s", name, s );
	throw TException( 1, msg );
	//logfile->error(msg);
	//sprintf( msg, "Его значение %s", s );
	//logfile->error(msg);
	//return 1;
}
예제 #11
0
void readInt( TCfg& cfg, const char *name, int &val ) throw (TException) {
	const char *s;
	char *rest;
	//try {
	s = cfg.getValue( name );
	//} catch( TRequestExc &e ) {
	//	sprintf( msg, "в конфигурационном файле отсутствует параметр %s", name );
	//	logfile->error(msg);
	//	sprintf( msg, "сообщение класса: %s", e.text() );
	//	logfile->error(msg);
	//	throw;
	//}
	//sprintf( msg, "%s = %s", name, s );
	//logfile->debug(msg);
	long a = strtol( s, &rest, 10 );
	while( isspace(*rest) )
		rest++;
	if( *rest != 0 ) {
		sprintf( msg, "Параметр %s должен быть целым числом. Его значение %s", name, s );
		throw TException( 1, msg );
		//logfile->error(msg);
		//sprintf( msg, "его значение %s", s );
		//logfile->error(msg);
		//return 1;
	}
	val = a;
	return;
}
예제 #12
0
string MTable::getVal( TCfg &cfg, uint8_t RqFlg )
{
    string rez = cfg.getS(RqFlg);
    if(rez == EVAL_STR)	return "NULL";
    if(cfg.fld().type() == TFld::String) {
	if(Mess->translDyn() && (cfg.fld().flg()&TFld::TransltText)) rez = trL(rez, Mess->lang2Code());
	string prntRes = rez;
	bool isBin = false;
	for(unsigned iCh = 0; !isBin && iCh < prntRes.size(); ++iCh)
	    switch(prntRes[iCh]) {
		case 0: isBin = true; break;
		case '\'': prntRes.insert(iCh, 1, prntRes[iCh]); ++iCh; break;
	    }
	return isBin ? "X'"+TSYS::strDecode(rez, TSYS::Bin)+"'" : "'"+prntRes+"'";
    }

    return "'" + rez + "'";
}
예제 #13
0
TVariant TConfig::objFunc( const string &iid, vector<TVariant> &prms, const string &user )
{
    // ElTp cfg(string nm) - config variable 'nm' get.
    //  nm - config variable name.
    if(iid == "cfg" && prms.size() >= 1) {
	TCfg *cf = at(prms[0].getS(), true);
	if(!cf) return EVAL_REAL;
	return *cf;
    }
    // ElTp cfgSet(string nm, ElTp val) - set config variable 'nm' to 'val'.
    //  nm - config variable name;
    //  val - variable value.
    if(iid == "cfgSet" && prms.size() >= 2) {
	TCfg *cf = at(prms[0].getS(), true);
	if(!cf || (cf->fld().flg()&TFld::NoWrite)) return false;
	*(TVariant*)cf = prms[1];
	return true;
    }

    return TVariant();
}
예제 #14
0
파일: tconfig.cpp 프로젝트: alimon/oscada
TVariant TConfig::objFunc( const string &iid, vector<TVariant> &prms,
    const string &user, int perm, const string &owner )
{
    // ElTp cfg(string nm) - config variable 'nm' get.
    //  nm - config variable name.
    if(iid == "cfg" && prms.size() >= 1 &&
	    SYS->security().at().access(user,SEC_RD,TSYS::strParse(owner,0,":"),TSYS::strParse(owner,1,":"),perm)) {
	TCfg *cf = at(prms[0].getS(), true);
	if(!cf) return EVAL_REAL;
	return *cf;
    }
    // ElTp cfgSet(string nm, ElTp val) - set config variable 'nm' to 'val'.
    //  nm - config variable name;
    //  val - variable value.
    if(iid == "cfgSet" && prms.size() >= 2 &&
	    SYS->security().at().access(user,SEC_WR,TSYS::strParse(owner,0,":"),TSYS::strParse(owner,1,":"),perm)) {
	TCfg *cf = at(prms[0].getS(), true);
	if(!cf || (cf->fld().flg()&TFld::NoWrite)) return false;
	*(TVariant*)cf = prms[1];
	return true;
    }

    return TVariant();
}
예제 #15
0
파일: dbf_mod.cpp 프로젝트: alimon/oscada
string MTable::getVal( TCfg &cfg, db_str_rec *fld_rec )
{
    string rez;
    switch(cfg.fld().type()) {
	case TFld::Boolean:	rez = cfg.getB() ? "T" : "F";	break;
	case TFld::Integer:	rez = i2s(cfg.getI());		break;
	case TFld::Real: {
	    if(!fld_rec)	{ rez = r2s(cfg.getR()); break; }

	    char str[200];
	    snprintf(str, sizeof(str), "%*.*f", fld_rec->len_fild, fld_rec->dec_field, cfg.getR());
	    rez = str;
	    break;
	}
	default: rez = Mess->codeConvOut(codepage, cfg.getS());	break;
    }

    return rez;
}
예제 #16
0
string MTable::getVal( TCfg &cfg, bool toEnc, uint8_t RqFlg )
{
    switch(cfg.fld().type()) {
	case TFld::String: {
	    if(!toEnc) return cfg.getS(RqFlg);
	    string prntRes = cfg.getS(RqFlg);
	    bool isBin = false;
	    for(unsigned iCh = 0; !isBin && iCh < prntRes.size(); ++iCh)
		switch(prntRes[iCh]) {
		    case 0: isBin = true; break;
		    case '\'':	prntRes.insert(iCh,1,prntRes[iCh]); ++iCh; break;
		}
	    return isBin ? "X'"+TSYS::strDecode(cfg.getS(RqFlg),TSYS::Bin)+"'" : "'"+prntRes+"'";
	    break;
	}
	default: return toEnc ? "'"+cfg.getS(RqFlg)+"'" : cfg.getS(RqFlg);
    }

    return "";
}
예제 #17
0
void MTable::setVal( TCfg &cf, const string &ival, bool tr )
{
    string val = (ival==DB_NULL) ? EVAL_STR : ival;
    switch(cf.fld().type()) {
	case TFld::String:
	    if(!cf.extVal()) {
		if(!tr || (cf.fld().flg()&TFld::TransltText && !cf.noTransl())) cf.setS(val);
		if(!tr && cf.fld().flg()&TFld::TransltText && !cf.noTransl()) Mess->translReg(val, "db:"+fullDBName()+"#"+cf.name());
	    }
	    else {
		if(!tr) {
		    cf.setS(val, TCfg::ExtValOne);
		    cf.setS("", TCfg::ExtValTwo);	//!! Sets for clean up from previous Two value
		    cf.setS("db:"+fullDBName()+"#"+cf.name(), TCfg::ExtValThree);
		} else cf.setS(val, TCfg::ExtValTwo);
	    }
	    break;
	default: cf.setS(val); break;
    }
}
예제 #18
0
bool MTable::fieldSeek( int row, TConfig &cfg, vector< vector<string> > *full )
{
    MtxAlloc resource(owner().connRes, true);
    if(!owner().enableStat())	return false;
    mLstUse = SYS->sysTm();

    vector< vector<string> >	inTbl,
				&tbl = full ? *full : inTbl;

    //Request
    if(!full || !full->size() || row == 0) {
	tbl.clear();
	vector<string> row, cf_el;

	// Request preparing
	map<string,int> headers;
	cfg.cfgList(cf_el);
	char *attrs[cf_el.size()+1];
	row.reserve(cf_el.size());
	string fltr; int fltrN = 0;
	for(unsigned iC = 0, iA = 0; iC < cf_el.size(); iC++) {
	    TCfg &cf = cfg.cfg(cf_el[iC]);
	    if(cf.isKey() && cf.keyUse()) { fltr += "("+cf_el[iC]+"="+getVal(cf)+")"; fltrN++; }
	    else if(cf.isKey() || cf.view()) {
		headers[cf_el[iC]] = row.size();
		row.push_back(cf_el[iC]);
		attrs[iA++] = (char*)cf_el[iC].c_str();	attrs[iA] = NULL;
	    }
	}
	tbl.push_back(row);
	if(fltrN > 1)	fltr = "&"+fltr;
	if(fltr.empty())fltr = "(objectclass=*)";

	// Request
	LDAPMessage	*result, *entry;
	if(ldap_search_s(owner().ldp,("ou="+name()+","+owner().bdn).c_str(),LDAP_SCOPE_ONE,fltr.c_str(),attrs,0,&result) != LDAP_SUCCESS) return false;
	for(entry = ldap_first_entry(owner().ldp,result); entry; entry = ldap_next_entry(owner().ldp,entry)) {
	    row.clear(); row.resize(headers.size());
	    char *a, **vals;
	    BerElement *ber;
	    bool entrMatch = true;
	    for(a = ldap_first_attribute(owner().ldp,entry,&ber); a != NULL && entrMatch; a = ldap_next_attribute(owner().ldp,entry,ber)) {
		string attr = a;
		ldap_memfree(a);
		string val;
		if((vals=ldap_get_values(owner().ldp,entry,attr.c_str())) != NULL) {
		    for(int iV = 0; vals[iV] != NULL; iV++) val += vals[iV];
		    ldap_value_free(vals);
		}

		TCfg *cf = NULL;	//cfg.at(attr, true);
		for(unsigned iC = 0; iC < cf_el.size() && !cf; iC++)
		    if(strcasecmp(attr.c_str(),cf_el[iC].c_str()) == 0) { cf = cfg.at(cf_el[iC], true); attr = cf_el[iC]; }

		if(cf) {
		    if(cf->isKey() && (val.empty() || (cf->keyUse() && getVal(*cf) != val)))	entrMatch = false;
		    if(headers.find(attr) != headers.end()) row[headers[attr]] = val;
		}
	    }
	    if(entrMatch) {
		// Late checking for keys
		for(unsigned iC = 0; iC < cf_el.size() && entrMatch; iC++) {
		    TCfg &cf = cfg.cfg(cf_el[iC]);
		    if(cf.isKey() && !cf.keyUse() && row[headers[cf_el[iC]]].empty())	entrMatch = false;
		}
		if(entrMatch) tbl.push_back(row);
	    }
	}
	ldap_msgfree(result);
    }

    if(tbl.size() < 2 || (full && (row+1) >= tbl.size())) return false;

    //Processing of the query
    row = full ? row+1 : 1;
    for(unsigned iFld = 0; iFld < tbl[0].size(); iFld++) {
	string sid = tbl[0][iFld];
	TCfg *cf = cfg.at(sid, true);
	if(cf) setVal(*cf, tbl[row][iFld]);
    }

    return true;
}
예제 #19
0
string MTable::getVal( TCfg &cf )
{
    return Mess->codeConvOut(codepage, cf.getS());
}
예제 #20
0
void MTable::setVal( TCfg &cf, const string &val )
{
    cf.setS(Mess->codeConvIn(codepage,val));
}