void ScaleScript::setFuncList(const NamedList &l) { func_hash.clear(); for(auto it = l.begin(); it != l.end(); ++it){ ScriptScaleStruct::fromNamedMap((*it).value< NamedMap >(), func_hash); } }
void TestPlugin::initialize() { NamedList* httpdconf = 0; Output("Initializing module TestHttpBase"); Configuration cfg; cfg = Engine::configFile("httpserver"); cfg.load(); for (unsigned int i = 0; i < cfg.sections(); i++) { httpdconf = cfg.getSection(i); String name = httpdconf ? httpdconf->c_str() : ""; if (! name.startSkip("listener ",false)) continue; name.trimBlanks(); httpdconf->String::operator=(name); break; // XXX only first listener } if (m_first) m_testThread = new TestThread; m_testThread->configure(*httpdconf); if (m_first) { m_first = false; m_testThread->startup(); Engine::install(new TestHandler("http.request")); } // delete httpdconf; }
void CallInfo::fillParam(NamedList& target, const String& name, bool clear) { NamedString* param = getParam(name); if (param) target.setParam(name,param->c_str()); else if (clear) target.clearParam(name); }
void TestThread::configure(const NamedList& conf) { Lock mylock(this); m_serverAddr = conf.getValue("addr", "0.0.0.0"); if(m_serverAddr == "0.0.0.0") m_serverAddr = "127.0.0.1"; m_serverPort = conf.getIntValue("port", 80); }
// Append all paramters from one named list to another, inserting keys prefix static void putNamedList(NamedList& dst, const NamedList& src, String prefix) { unsigned int n = src.length(); for (unsigned int i = 0; i < n; i++) { const NamedString* param = src.getParam(i); if (param) dst.addParam(prefix + param->name(),*param); } }
void RTPReceiver::stats(NamedList& stat) const { if (m_session) stat.setParam("remoteip",m_session->UDPSession::transport()->remoteAddr().host()); stat.setParam("lostpkts",String(m_ioLostPkt)); stat.setParam("synclost",String(m_syncLost)); stat.setParam("wrongssrc",String(m_wrongSSRC)); stat.setParam("seqslost",String(m_seqLost)); }
SDPSession::SDPSession(SDPParser* parser, NamedList& params) : m_parser(parser), m_mediaStatus(MediaMissing), m_rtpForward(false), m_sdpForward(false), m_rtpMedia(0), m_sdpSession(0), m_sdpVersion(0) { m_rtpForward = params.getBoolValue("rtp_forward"); m_secure = params.getBoolValue("secure",parser->m_secure); m_rfc2833 = parser->m_rfc2833; setRfc2833(params.getParam("rfc2833")); }
// Put the list of net media in a parameter list void SDPMedia::putMedia(NamedList& msg, bool putPort) { msg.addParam("media" + suffix(),"yes"); msg.addParam("formats" + suffix(),formats()); msg.addParam("transport" + suffix(),transport()); if (mappings()) msg.addParam("rtp_mapping" + suffix(),mappings()); if (isAudio()) msg.addParam("rtp_rfc2833",rfc2833()); if (putPort) msg.addParam("rtp_port" + suffix(),remotePort()); if (remoteCrypto()) msg.addParam("crypto" + suffix(),remoteCrypto()); // must handle encryption differently const char* enc = getValue("encryption"); if (enc) msg.addParam("encryption" + suffix(),enc); clearParam("encryption"); unsigned int n = length(); for (unsigned int i = 0; i < n; i++) { const NamedString* param = getParam(i); if (param) msg.addParam("sdp" + suffix() + "_" + param->name(),*param); } }
void SS7Testing::setParams(const NamedList& params, bool setSeq) { if (!m_timer.interval() || params.getParam(YSTRING("interval"))) m_timer.interval(params,"interval",20,1000,true); m_len = params.getIntValue(YSTRING("length"),m_len); m_sharing = params.getBoolValue(YSTRING("sharing"),m_sharing); if (m_len > 1024) m_len = 1024; if (setSeq || !m_seq) m_seq = params.getIntValue(YSTRING("sequence"),m_seq); const String* lbl = params.getParam(YSTRING("address")); if (!TelEngine::null(lbl)) { // TYPE,opc,dpc,sls,spare SS7PointCode::Type t = SS7PointCode::Other; ObjList* l = lbl->split(','); const GenObject* o = l->at(0); if (o) { t = SS7PointCode::lookup(o->toString()); if (t == SS7PointCode::Other) t = m_lbl.type(); } if (t != SS7PointCode::Other) { o = l->at(1); if (o) { SS7PointCode c(m_lbl.opc()); if (c.assign(o->toString(),t)) m_lbl.assign(t,m_lbl.dpc(),c,m_lbl.sls(),m_lbl.spare()); } o = l->at(2); if (o) { SS7PointCode c(m_lbl.dpc()); if (c.assign(o->toString(),t)) m_lbl.assign(t,c,m_lbl.opc(),m_lbl.sls(),m_lbl.spare()); } o = l->at(3); if (o) { int sls = o->toString().toInteger(-1); if (sls >= 0) m_lbl.setSls(sls); } o = l->at(4); if (o) { int spare = o->toString().toInteger(-1); if (spare >= 0) m_lbl.setSpare(spare); } } delete l; } }
ActionPointMapping MetaSprite::generateActionPointMapping(const NamedList<ActionPointFunction>& apFunctions, ErrorList& err) { bool valid = true; auto addError = [&](const std::string msg) { err.addError(std::move(msg)); valid = false; }; auto addApfError = [&](const ActionPointFunction& apf, const std::string msg) { err.addError(std::make_unique<ListItemError>(&apf, std::move(msg))); valid = false; }; ActionPointMapping ret; if (apFunctions.empty()) { addError("Expected at least one action point function"); return ret; } if (apFunctions.size() > MAX_ACTION_POINT_FUNCTIONS) { addError("Too many action point functions (max " + std::to_string(MAX_ACTION_POINT_FUNCTIONS) + ")"); return ret; } ret.reserve(apFunctions.size()); for (unsigned i = 0; i < apFunctions.size(); i++) { const unsigned romValue = (i + 1) * 2; assert(romValue <= 255 - 2); const ActionPointFunction& apf = apFunctions.at(i); if (not apf.name.isValid()) { addApfError(apf, "Missing action point function name"); } auto success = ret.emplace(apf.name, romValue); if (success.second == false) { addApfError(apf, "Action point function name already exists: " + apf.name); } } if (not valid) { ret.clear(); } return ret; }
unsigned char SS7Layer4::getSIO(const NamedList& params, unsigned char sif, unsigned char prio, unsigned char ni) { if ((prio & 0x30) == 0) prio <<= 4; if ((ni & 0xc0) == 0) ni <<= 6; sif = params.getIntValue(YSTRING("service"),sif & 0x0f); prio = SS7MSU::getPriority(params.getValue(YSTRING("priority")),prio & 0x30); if ((prio & 0x30) == 0) prio <<= 4; ni = SS7MSU::getNetIndicator(params.getValue(YSTRING("netindicator")),ni & 0xc0); if ((ni & 0xc0) == 0) ni <<= 6; return (sif & 0x0f) | (prio & 0x30) | (ni & 0xc0); }
bool SS7Testing::control(NamedList& params) { String* ret = params.getParam(YSTRING("completion")); const String* oper = params.getParam(YSTRING("operation")); const char* cmp = params.getValue(YSTRING("component")); int cmd = oper ? oper->toInteger(s_dict_control,-1) : -1; if (ret) { if (oper && (cmd < 0)) return false; String part = params.getValue(YSTRING("partword")); if (cmp) { if (toString() != cmp) return false; for (const TokenDict* d = s_dict_control; d->token; d++) Module::itemComplete(*ret,d->token,part); return true; } return Module::itemComplete(*ret,toString(),part); } if (!(cmp && toString() == cmp)) return false; if (cmd >= 0) { Lock mylock(this); setParams(params,true); switch (cmd) { case CMD_STOP: m_timer.stop(); return true; case CMD_START: if (!(m_timer.interval() && m_lbl.length())) return false; m_timer.start(); return sendTraffic(); case CMD_SINGLE: if (!m_lbl.length()) return false; m_timer.stop(); return sendTraffic(); case CMD_RESET: m_timer.stop(); m_lbl.assign(SS7PointCode::Other,m_lbl.opc(),m_lbl.dpc(),m_lbl.sls()); return true; } } return SignallingComponent::control(params); }
void readPalette(const XmlTag* tag, NamedList<PaletteInput>& palettes) { assert(tag->name == "palette"); palettes.insert_back(); auto& palette = palettes.back(); palette.name = tag->getAttributeId("name"); palette.paletteImageFilename = tag->getAttributeFilename("image"); palette.rowsPerFrame = tag->getAttributeUnsigned("rows-per-frame"); palette.skipFirstFrame = tag->getAttributeBoolean("skip-first"); if (tag->hasAttribute("animation-delay")) { palette.animationDelay = tag->getAttributeUnsigned("animation-delay"); } }
// Append a parameter to a buffer from a list or dictionary void appendParam(ObjList& msg, NamedList& params, unsigned char value, TokenDict* dict, unsigned char defValue) { unsigned char a[3] = {value,1}; const char* name = lookup(value,ETSIModem::s_msgParams); a[2] = lookup(params.getValue(name),dict,defValue); msg.append(new DataBlock(a,sizeof(a))); }
void RTPSession::getStats(NamedList& stats) const { if (m_send) m_send->stats(stats); if (m_recv) m_recv->stats(stats); stats.setParam("wrongsrc",String(m_wrongSrc)); }
void CallInfo::fillParams(NamedList& target) { unsigned int n = length(); for (unsigned int i = 0; i < n; i++) { NamedString* param = getParam(i); if (param) target.setParam(param->name(),param->c_str()); } }
// Update members from a dispatched "chan.rtp" message void SDPMedia::update(const NamedList& msg, bool pickFormat) { DDebug(DebugAll,"SDPMedia::update('%s',%s) [%p]", msg.c_str(),String::boolText(pickFormat),this); m_id = msg.getValue("rtpid",m_id); m_lPort = msg.getValue("localport",m_lPort); if (pickFormat) { const char* format = msg.getValue("format"); if (format) { m_format = format; if ((m_formats != m_format) && (msg.getIntValue("remoteport") > 0)) { Debug(DebugNote,"Choosing started '%s' format '%s' [%p]", c_str(),format,this); m_formats = m_format; } } } }
UART::UART(State state, const NamedList& params, const char* name) : m_modem(params,this), m_state(Idle), m_error(ENone), m_parity(0), m_expectedParity(false), m_accumulator(8) { debugName(name); unsigned char dataBits = params.getIntValue("databits",8); if (dataBits < 1 || dataBits > 8) dataBits = 8; m_accumulator.dataBits(dataBits); m_parity = params.getIntValue("parity"); reset(state); }
bool CallInfo::copyParam(const NamedList& original, const String& name, bool clear) { NamedString* param = original.getParam(name); if (param) { setParam(name,param->c_str()); return true; } else if (clear) clearParam(name); return false; }
// Append a parameter to a buffer // Truncate it or set error if fail is true and parameter length exceeds maxLen // Return: 0 if the parameter is missing // -1 if the parameter is too long // 1 on success int appendParam(ObjList& msg, NamedList& params, unsigned char value, unsigned char maxLen, bool fail) { NamedString* ns = params.getParam(lookup(value,ETSIModem::s_msgParams)); if (!ns) return 0; unsigned char len = ns->length(); if (len > maxLen) { if (fail) { params.setParam("error",ns->name() + "-too-long"); return -1; } len = maxLen; } DataBlock* data = new DataBlock; unsigned char a[2] = {value,len}; FSKModem::addRaw(*data,a,sizeof(a)); FSKModem::addRaw(*data,(void*)ns->c_str(),len); msg.append(data); return 1; }
// Update RTP/SDP data from parameters // Return true if media changed bool SDPSession::updateRtpSDP(const NamedList& params) { DDebug(m_parser,DebugAll,"SDPSession::updateRtpSDP(%s) [%p]",params.c_str(),this); String addr; ObjList* tmp = updateRtpSDP(params,addr,m_rtpMedia); if (tmp) { bool chg = (m_rtpLocalAddr != addr); m_rtpLocalAddr = addr; return setMedia(tmp) || chg; } return false; }
// response = md5(md5(username:realm:password):nonce:md5(method:uri)) // qop=auth --> response = md5(md5(username:realm:password):nonce:nc:cnonce:qop:md5(method:uri)) void SIPEngine::buildAuth(const String& username, const String& realm, const String& passwd, const String& nonce, const String& method, const String& uri, String& response, const NamedList& qop) { XDebug(DebugAll,"SIP Building auth: '%s:%s:%s' '%s' '%s:%s'", username.c_str(),realm.c_str(),passwd.c_str(),nonce.c_str(),method.c_str(),uri.c_str()); MD5 m1,m2; m1 << username << ":" << realm << ":" << passwd; m2 << method << ":" << uri; String tmp; tmp << m1.hexDigest() << ":" << nonce << ":"; if (qop) { if (qop == YSTRING("auth")) tmp << qop[YSTRING("nc")] << ":" << qop[YSTRING("cnonce")] << ":" << qop.c_str() << ":"; else Debug(DebugStub,"SIPEngine::buildAuth() not implemented for qop=%s", qop.c_str()); } tmp << m2.hexDigest(); m1.clear(); m1.update(tmp); response = m1.hexDigest(); }
// Put the list of net media in a parameter list void SDPSession::putMedia(NamedList& msg, ObjList* mList, bool putPort) { if (!mList) return; bool audio = false; bool other = false; for (mList = mList->skipNull(); mList; mList = mList->skipNext()) { SDPMedia* m = static_cast<SDPMedia*>(mList->get()); m->putMedia(msg,putPort); if (m->isAudio()) audio = true; else other = true; } if (other && !audio) msg.setParam("media",String::boolText(false)); }
// Put the list of net media in a parameter list void SDPMedia::putMedia(NamedList& msg, bool putPort) { msg.addParam("media" + suffix(),"yes"); msg.addParam("formats" + suffix(),formats()); msg.addParam("transport" + suffix(),transport()); if (mappings()) msg.addParam("rtp_mapping" + suffix(),mappings()); if (isAudio()) msg.addParam("rtp_rfc2833",rfc2833()); if (putPort) msg.addParam("rtp_port" + suffix(),remotePort()); if (remoteCrypto()) msg.addParam("crypto" + suffix(),remoteCrypto()); // must handle encryption differently const char* enc = m_rAttrs.getValue("encryption"); if (enc) msg.addParam("encryption" + suffix(),enc); putNamedList(msg, m_rAttrs, "sdp" + suffix() + "_"); putNamedList(msg, m_fmtps, "fmtp_"); }
int ExpEvaluator::evaluate(NamedList& results, unsigned int index, const char* prefix) const { ObjList stack; if (!evaluate(stack)) return -1; String idx(prefix); if (index) idx << index << "."; int column = 0; for (ObjList* r = stack.skipNull(); r; r = r->skipNext()) { column++; const ExpOperation* res = static_cast<const ExpOperation*>(r->get()); String name = res->name(); if (name.null()) name = column; results.setParam(idx+name,*res); } return column; }
// Create a buffer containing the byte representation of a message to be sent // and another one with the header bool ETSIModem::createMsg(NamedList& params, DataBlock& data) { int type = lookup(params,s_msg); switch (type) { case MsgCallSetup: break; case MsgMWI: case MsgCharge: case MsgSMS: Debug(this,DebugStub,"Create message '%s' not implemented [%p]", params.c_str(),this); return false; default: Debug(this,DebugNote,"Can't create unknown message '%s' [%p]", params.c_str(),this); return false; } ObjList msg; bool fail = !params.getBoolValue("force-send",true); // DateTime - ETSI EN 300 659-3 - 5.4.1 String datetime = params.getValue("datetime"); unsigned char dt[4]; bool ok = false; if (datetime.isBoolean()) if (datetime.toBoolean()) ok = getDateTime(dt); else ; else ok = getDateTime(dt,&datetime); if (ok) { DataBlock* dtParam = new DataBlock(0,10); unsigned char* d = (unsigned char*)dtParam->data(); d[0] = DateTime; d[1] = 8; // Set date and time: %.2d%.2d%.2d%.2d month:day:hour:minute for (int i = 0, j = 2; i < 4; i++, j += 2) { d[j] = '0' + dt[i] / 10; d[j+1] = '0' + dt[i] % 10; } msg.append(dtParam); } else DDebug(this,DebugInfo,"Can't set datetime parameter from '%s' [%p]", datetime.c_str(),this); // CallerId/CallerIdReason - ETSI EN 300 659-3 - 5.4.2: Max caller id 20 // Parameter is missing: append reason (default caller absence: 0x4f: unavailable) int res = appendParam(msg,params,CallerId,20,fail); if (res == -1) return false; if (!res) appendParam(msg,params,CallerIdReason,s_dict_callerAbsence,0x4f); // CallerName/CallerNameReason - ETSI EN 300 659-3 - 5.4.5: Max caller name 50 // Parameter is missing: append reason (default callername absence: 0x4f: unavailable) res = appendParam(msg,params,CallerName,50,fail); if (res == -1) return false; if (!res) appendParam(msg,params,CallerNameReason,s_dict_callerAbsence,0x4f); // Build message unsigned char len = 0; unsigned char hdr[2] = {type}; data.assign(&hdr,sizeof(hdr)); for (ObjList* o = msg.skipNull(); o; o = o->skipNext()) { DataBlock* msgParam = static_cast<DataBlock*>(o->get()); if (len + msgParam->length() > 255) { if (!fail) { Debug(this,DebugNote,"Trucating %s message length to %u bytes [%p]", params.c_str(),data.length(),this); break; } params.setParam("error","message-too-long"); return false; } len += msgParam->length(); data += *msgParam; } if (!len) { params.setParam("error","empty-message"); return false; } unsigned char* buf = ((unsigned char*)(data.data())); buf[1] = len; m_chksum = 0; for (unsigned int i = 0; i < data.length(); i++) m_chksum += buf[i]; unsigned char crcVal = 256 - (m_chksum & 0xff); FSKModem::addRaw(data,&crcVal,1); return true; }
QDomElement Sp2Pw::getWindowXml( VtlWidget * parent ) { Figures * fig = dynamic_cast<Figures*>(parent); if (!fig ) { qWarning () << "BAD WIDGET TYPE!!!!"; return QDomElement(); } FakeApplicationWindow app; FakeSimpleMdiWindow * mdi = new FakeSimpleMdiWindow(&app, "PopupMdiWindow"); if (buttonType() == LeftButton ) mdi->addParam ("popup", "lb"); else if (buttonType() == RightButton ) mdi->addParam ("popup", "rb"); int x = 0, y = 0; calculatePwPos (fig, 300, 75, x, y); mdi->setWindowTitle (fig->toolTip()); mdi->setGeometry (QRect(x, y, 300, 155)); FakeTable * t = new FakeTable (mdi, "VtlTable"); t->setGeometry (QRect(0, 0, 305, 155)); t->setNumRows (2); t->setNumCols (1); t->setLeftMargin (100); t->setTopMargin (0); NamedList l ("ROWS"); { NamedMap m("ROWS"); m["h"] = 75; m["l"] = "Завдання"; l.append ( QVariant::fromValue ( m )); } { NamedMap m("ROWS"); m["h"] = 75; m["l"] = "Завдання 2"; l.append ( QVariant::fromValue ( m )); } t->setRows (l); NamedList c ("COLS"); { NamedMap m("COLS"); m["w"] = 200; m["l"] = ""; c.append ( QVariant::fromValue( m ) ); } t->setCols (c); FakeCell * cell = new FakeCell (0, 0); t->setItem(0, 0, cell); cell->setCellType (FakeCell::SPINBOX_CELL); cell->setFont (QFont("Tahoma", 26)); cell->setNumDigits ( fig->getFloatDigits() ); cell->setMinInc ( fig->getFloatDigits() ); FakeCell * cell1 = new FakeCell (1, 0); t->setItem(1, 0, cell1); cell1->setCellType (FakeCell::SPINBOX_CELL); cell1->setFont (QFont("Tahoma", 26)); cell1->setNumDigits ( fig->getFloatDigits() ); cell1->setMinInc ( fig->getFloatDigits() ); XmlObjectSaverBase<VtlWrapper> saver; saver.save (mdi->selfWrapper()); return saver.document().firstChild().toElement(); }
// Update from parameters. Build a default SDP if no media is found in params bool SDPSession::updateSDP(const NamedList& params) { DDebug(m_parser,DebugAll,"SDPSession::updateSdp('%s') [%p]",params.c_str(),this); bool defaults = true; const char* sdpPrefix = params.getValue("osdp-prefix","osdp"); ObjList* lst = 0; unsigned int n = params.length(); String defFormats; m_parser->getAudioFormats(defFormats); for (unsigned int i = 0; i < n; i++) { const NamedString* p = params.getParam(i); if (!p) continue; // search for rtp_port or rtp_port_MEDIANAME parameters String tmp(p->name()); if (!tmp.startSkip("media",false)) continue; if (tmp && (tmp[0] != '_')) continue; // since we found at least one media declaration disable defaults defaults = false; // now tmp holds the suffix for the media, null for audio bool audio = tmp.null(); // check if media is supported, default only for audio if (!p->toBoolean(audio)) continue; String fmts = params.getValue("formats" + tmp); if (audio && fmts.null()) fmts = defFormats; if (fmts.null()) continue; String trans = params.getValue("transport" + tmp,"RTP/AVP"); String crypto; if (m_secure) crypto = params.getValue("crypto" + tmp); if (audio) tmp = "audio"; else tmp >> "_"; SDPMedia* rtp = 0; // try to take the media descriptor from the old list if (m_rtpMedia) { ObjList* om = m_rtpMedia->find(tmp); if (om) rtp = static_cast<SDPMedia*>(om->remove(false)); } bool append = false; if (rtp) rtp->update(fmts); else { rtp = new SDPMedia(tmp,trans,fmts); append = true; } rtp->crypto(crypto,false); if (sdpPrefix) { for (unsigned int j = 0; j < n; j++) { const NamedString* param = params.getParam(j); if (!param) continue; tmp = param->name(); if (tmp.startSkip(sdpPrefix + rtp->suffix() + "_",false) && (tmp.find('_') < 0)) rtp->parameter(tmp,*param,append); } } if (!lst) lst = new ObjList; lst->append(rtp); } if (defaults && !lst) { lst = new ObjList; lst->append(new SDPMedia("audio","RTP/AVP",params.getValue("formats",defFormats))); } return setMedia(lst); }