NamedList& NamedList::copySubParams(const NamedList& original, const String& prefix, bool skipPrefix, bool replace) { XDebug(DebugInfo,"NamedList::copySubParams(%p,\"%s\",%s,%s) [%p]", &original,prefix.c_str(),String::boolText(skipPrefix), String::boolText(replace),this); if (prefix) { unsigned int offs = skipPrefix ? prefix.length() : 0; ObjList* dest = &m_params; for (const ObjList* l = original.m_params.skipNull(); l; l = l->skipNext()) { const NamedString* s = static_cast<const NamedString*>(l->get()); if (s->name().startsWith(prefix)) { const char* name = s->name().c_str() + offs; if (!*name) continue; if (!replace) dest = dest->append(new NamedString(name,*s)); else if (offs) setParam(name,*s); else setParam(s->name(),*s); } } } return *this; }
SIPEvent* SIPEngine::getEvent() { Lock lock(this); ObjList* l = m_transList.skipNull(); if (!l) return 0; u_int64_t time = Time::now(); for (; l; l = l->skipNext()) { SIPTransaction* t = static_cast<SIPTransaction*>(l->get()); SIPEvent* e = t->getEvent(true,time); if (e) { DDebug(this,DebugInfo,"Got pending event %p (state %s) from transaction %p [%p]", e,SIPTransaction::stateName(e->getState()),t,this); if (t->getState() == SIPTransaction::Invalid) m_transList.remove(t); return e; } } time = Time::now(); for (l = m_transList.skipNull(); l; l = l->skipNext()) { SIPTransaction* t = static_cast<SIPTransaction*>(l->get()); SIPEvent* e = t->getEvent(false,time); if (e) { DDebug(this,DebugInfo,"Got event %p (state %s) from transaction %p [%p]", e,SIPTransaction::stateName(e->getState()),t,this); if (t->getState() == SIPTransaction::Invalid) m_transList.remove(t); return e; } } return 0; }
// Utility: print the result of dns query // Return the code static int printResult(int type, int code, const char* dname, ObjList& result, String* error) { #ifdef DEBUG if (!code) { String s; int crt = 0; for (ObjList* o = result.skipNull(); o; o = o->skipNext()) { DnsRecord* rec = static_cast<DnsRecord*>(o->get()); if (!s) s << "\r\n-----"; s << "\r\n" << ++crt << ":"; rec->dump(s); } if (s) s << "\r\n-----"; Debug(DebugAll,"%s query for '%s' got %d records%s", lookup(type,Resolver::s_types),dname,result.count(),s.safe()); } else { String dummy; if (!error) { error = &dummy; #ifdef _WINDOWS Thread::errorString(dummy,code); #elif defined(__NAMESER) dummy = hstrerror(code); #endif } Debug(DebugNote,"%s query for '%s' failed with code %d error=%s", lookup(type,Resolver::s_types),dname,code,TelEngine::c_safe(error)); } #endif return code; }
bool HashList::resync() { XDebug(DebugAll,"HashList::resync() [%p]",this); bool moved = false; for (unsigned int n = 0; n < m_size; n++) { ObjList* l = m_lists[n]; while (l) { GenObject* obj = l->get(); if (obj) { unsigned int i = obj->toString().hash() % m_size; if (i != n) { bool autoDel = l->autoDelete(); m_lists[n]->remove(obj,false); if (!m_lists[i]) m_lists[i] = new ObjList; m_lists[i]->append(obj)->setDelete(autoDel); moved = true; continue; } } l = l->next(); } } return moved; }
GenObject* ObjList::remove(bool delobj) { GenObject *tmp = m_obj; if (m_next) { ObjList *n = m_next; m_next = n->next(); m_obj = n->get(); m_delete = n->m_delete; n->m_obj = 0; n->m_next = 0; n->destruct(); } else m_obj = 0; if (delobj && tmp) { XDebug(DebugInfo,"ObjList::remove() deleting %p",tmp); // Don't use TelEngine::destruct(): the compiler will call the non-template // function (which doesn't reset the pointer) tmp->destruct(); tmp = 0; } return tmp; }
ObjList LifeForm::perceive(double rad){ if (rad>100) rad=100; if (rad<2) rad=2; // int i=0; // assert(i==1); // update_position(); SmartPointer<LifeForm> self = SmartPointer<LifeForm>(this); // cout<<this->species_name(); // cout<<"in perceive"<<endl; std::vector<SmartPointer<LifeForm>> vector = space.nearby(this->position(), rad); auto b = vector.begin(); auto e = vector.end(); ObjList info;// = vector while (b!=e) { auto in = this->info_about_them(*b); info.push_back(in); b++; } //energy cost energy-=perceive_cost(rad); if (energy<min_energy) { self->die(); } return info; };
void ListIterator::assign(HashList& list, int offset) { clear(); m_hashList = &list; m_length = list.count(); if (!m_length) return; m_objects = new GenObject* [m_length]; m_hashes = new unsigned int[m_length]; offset = (m_length - offset) % m_length; unsigned int i = 0; for (unsigned int n = 0; n < list.length(); n++) { ObjList* l = list.getList(n); if (!l) continue; for (l = l->skipNull(); i < m_length; l = l->skipNext()) { if (!l) break; unsigned int idx = ((i++) + offset) % m_length; m_objects[idx] = l->get(); m_hashes[idx] = l->get()->toString().hash(); } } while (i < m_length) m_objects[((i++) + offset) % m_length] = 0; }
void RTPGroup::run() { DDebug(DebugInfo,"RTPGroup::run() [%p]",this); bool ok = true; while (ok) { unsigned long msec = m_sleep; if (msec < s_sleep) msec = s_sleep; lock(); Time t; ObjList* l = &m_processors; m_listChanged = false; for (ok = false;l;l = l->next()) { RTPProcessor* p = static_cast<RTPProcessor*>(l->get()); if (p) { ok = true; p->timerTick(t); // the list is protected from other threads but can be changed // from this one so if it happened we just break out and try // again later rather than using an expensive ListIterator if (m_listChanged) break; } } unlock(); Thread::msleep(msec,true); } DDebug(DebugInfo,"RTPGroup::run() ran out of processors [%p]",this); }
String ExpEvaluator::dump() const { String res; for (ObjList* l = m_opcodes.skipNull(); l; l = l->skipNext()) { const ExpOperation* o = static_cast<const ExpOperation*>(l->get()); const char* oper = getOperator(o->opcode()); if (oper) { res << " " << oper; continue; } switch (o->opcode()) { case OpcPush: if (o->number()) res << " " << (int)o->number(); else res << " '" << *o << "'"; break; case OpcField: res << " " << o->name(); break; case OpcFunc: res << " " << o->name() << "(" << (int)o->number() << ")"; break; default: res << " [" << o->opcode() << "]"; } } return res; }
double byf69::average_bearing(ObjList nearby) { double sum = 0; for (ObjList::iterator i = nearby.begin(); i != nearby.end(); i++) { sum += i->bearing; } return sum / nearby.size(); }
// Update members with data taken from a SDP, return true if something changed bool SDPMedia::update(const char* formats, int rport, int lport, bool force) { DDebug(DebugAll,"SDPMedia::update('%s',%d,%d,%s) [%p]", formats,rport,lport,String::boolText(force),this); bool chg = false; String tmp(formats); if (tmp && (m_formats != tmp)) { if (tmp.find(',') < 0) { // single format received, check if acceptable if (m_formats && !force && m_formats.find(tmp) < 0) { Debug(DebugNote,"Not changing to '%s' from '%s' [%p]", formats,m_formats.c_str(),this); tmp.clear(); } } else if (m_formats && !force) { // from received list keep only already offered formats ObjList* l1 = tmp.split(',',false); ObjList* l2 = m_formats.split(',',false); for (ObjList* fmt = l1->skipNull(); fmt; ) { if (l2->find(fmt->get()->toString())) fmt = fmt->skipNext(); else { fmt->remove(); fmt = fmt->skipNull(); } } tmp.clear(); tmp.append(l1,","); TelEngine::destruct(l1); TelEngine::destruct(l2); if (tmp.null()) Debug(DebugNote,"Not changing formats '%s' [%p]",m_formats.c_str(),this); } if (tmp && (m_formats != tmp)) { chg = true; m_formats = tmp; int q = m_formats.find(','); m_format = m_formats.substr(0,q); Debug(DebugInfo,"Choosing offered '%s' format '%s' [%p]", c_str(),m_format.c_str(),this); } } if (rport >= 0) { tmp = rport; if (m_rPort != tmp) { chg = true; m_rPort = tmp; } } if (lport >= 0) { tmp = lport; if (m_lPort != tmp) { m_localChanged = true; chg = true; m_lPort = tmp; } } return chg; }
void Socket::timerTick(const Time& when) { for (ObjList* l = &m_filters; l; l = l->next()) { SocketFilter* filter = static_cast<SocketFilter*>(l->get()); if (filter) filter->timerTick(when); } }
ExpOperation* ExpEvaluator::popOpcode() { ObjList* l = &m_opcodes; for (ObjList* p = l; p; p = p->next()) { if (p->get()) l = p; } return static_cast<ExpOperation*>(l->remove(false)); }
ExpOperation* ExpEvaluator::popOne(ObjList& stack) { GenObject* o = 0; for (ObjList* l = stack.skipNull(); l; l=l->skipNext()) o = l->get(); stack.remove(o,false); DDebug(DebugInfo,"Popped: %p",o); return static_cast<ExpOperation*>(o); }
NamedList::NamedList(const NamedList& original) : String(original) { ObjList* dest = &m_params; for (const ObjList* l = original.m_params.skipNull(); l; l = l->skipNext()) { const NamedString* p = static_cast<const NamedString*>(l->get()); dest = dest->append(new NamedString(p->name(),*p)); } }
ObjList* ObjList::operator+(int index) const { if (index < 0) return 0; ObjList *obj = const_cast<ObjList*>(this); for (;obj;obj=obj->next(),index--) if (!index) break; return obj; }
GenObject* HashList::remove(GenObject* obj, bool delobj, bool useHash) { ObjList* n = 0; if (useHash && obj) n = find(obj,obj->toString().hash()); else n = find(obj); return n ? n->remove(delobj) : 0; }
ExpEvaluator::ExpEvaluator(const ExpEvaluator& original) : m_operators(original.m_operators), m_extender(0) { extender(original.extender()); for (ObjList* l = original.m_opcodes.skipNull(); l; l = l->skipNext()) { const ExpOperation* o = static_cast<const ExpOperation*>(l->get()); m_opcodes.append(new ExpOperation(*o)); } }
ExpEvaluator::ExpEvaluator(const ExpEvaluator& original) : m_operators(original.m_operators), m_unaryOps(original.unaryOps()), m_inError(false), m_lineNo(original.lineNumber()), m_extender(0) { extender(original.extender()); for (ObjList* l = original.m_opcodes.skipNull(); l; l = l->skipNext()) { const ExpOperation* o = static_cast<const ExpOperation*>(l->get()); m_opcodes.append(o->clone()); } }
CallInfo* CallList::find(const CallEndpoint* call) { ObjList* l = m_calls.skipNull(); for (; l; l = l->skipNext()) { CallInfo* info = static_cast<CallInfo*>(l->get()); if (info->call() == call) return info; } return 0; }
// Remove a specific parameter NamedList& NamedList::clearParam(NamedString* param, bool delParam) { if (!param) return *this; ObjList* o = m_params.find(param); if (o) o->remove(delParam); XDebug(DebugInfo,"NamedList::clearParam(%p) found=%p",param,o); return *this; }
bool ExpEvaluator::runEvaluate(ObjList& stack) const { DDebug(DebugInfo,"runEvaluate(%p)",&stack); for (ObjList* l = m_opcodes.skipNull(); l; l = l->skipNext()) { const ExpOperation* o = static_cast<const ExpOperation*>(l->get()); if (!runOperation(stack,*o)) return false; } return true; }
ToneConsumer::ToneConsumer(const String& id, const String& name) : m_id(id), m_name(name), m_mode(Mono), m_detFax(true), m_detCont(false), m_detDtmf(true), m_detDnis(false), m_fax(s_paramsCNG), m_cont(s_paramsCOTv) { Debug(&plugin,DebugAll,"ToneConsumer::ToneConsumer(%s,'%s') [%p]", id.c_str(),name.c_str(),this); for (int i = 0; i < 4; i++) { m_dtmfL[i].assign(s_paramsDtmfL[i]); m_dtmfH[i].assign(s_paramsDtmfH[i]); } init(); String tmp = name; tmp.startSkip("tone/",false); if (tmp.startSkip("mixed/",false)) m_mode = Mixed; else if (tmp.startSkip("left/",false)) m_mode = Left; else if (tmp.startSkip("right/",false)) m_mode = Right; else tmp.startSkip("mono/",false); if (m_mode != Mono) m_format = "2*slin"; if (tmp && (tmp != "*")) { // individual detection requested m_detFax = m_detCont = m_detDtmf = m_detDnis = false; ObjList* k = tmp.split(',',false); for (ObjList* l = k; l; l = l->next()) { String* s = static_cast<String*>(l->get()); if (!s) continue; m_detFax = m_detFax || (*s == "fax"); m_detCont = m_detCont || (*s == "cotv"); m_detDtmf = m_detDtmf || (*s == "dtmf"); if (*s == "rfax") { // detection of receiving Fax requested m_fax.assign(s_paramsCED); m_detFax = true; } else if (*s == "cots") { // detection of COT Send tone requested m_cont.assign(s_paramsCOTs); m_detCont = true; } else if (*s == "callsetup") { // call setup info in the form *ANI*DNIS* m_detDnis = true; } } TelEngine::destruct(k); } s_mutex.lock(); s_count++; s_mutex.unlock(); }
// Insert a record into a list in the proper location // Order records ascending by their order // Look at ascPref for records with the same order bool DnsRecord::insert(ObjList& list, DnsRecord* rec, bool ascPref) { if (!rec || list.find(rec)) return false; XDebug(DebugAll,"DnsRecord::insert(%p) order=%d pref=%d",rec,rec->order(),rec->pref()); ObjList* o = list.skipNull(); for (; o; o = o->skipNext()) { DnsRecord* crt = static_cast<DnsRecord*>(o->get()); if (rec->order() > crt->order()) continue; if (rec->order() == crt->order()) { for (; o; o = o->skipNext()) { DnsRecord* crt = static_cast<DnsRecord*>(o->get()); if (crt->order() != rec->order()) break; if (crt->pref() == rec->pref()) continue; if (ascPref == (rec->pref() < crt->pref())) break; } } break; } if (o) o->insert(rec); else list.append(rec); return true; }
ObjInfo byf69::find_closest(ObjList nearby) { ObjInfo closest{}; double dist = INFINITY; for (ObjList::iterator i = nearby.begin(); i != nearby.end(); i++) { if (i->distance < dist) { closest = *i; dist = i->distance; } } return closest; }
NamedList& NamedList::copyParams(const NamedList& original, const String& list, char childSep) { XDebug(DebugInfo,"NamedList::copyParams(%p,\"%s\",'%.1s') [%p]", &original,list.c_str(),&childSep,this); ObjList* l = list.split(',',false); if (l) { copyParams(original,l,childSep); l->destruct(); } return *this; }
// Find the info object associated with a remote peer by alias name MGCPEpInfo* MGCPEndpoint::findAlias(const String& alias) { if (alias.null()) return 0; Lock lock(this); for (ObjList* o = m_remote.skipNull(); o; o = o->skipNext()) { MGCPEpInfo* info = static_cast<MGCPEpInfo*>(o->get()); if (alias == info->alias) return info; } return 0; }
void CallEndpoint::destroyed() { #ifdef DEBUG ObjList* l = m_data.skipNull(); for (; l; l=l->skipNext()) { DataEndpoint* e = static_cast<DataEndpoint*>(l->get()); Debug(DebugAll,"Endpoint at %p type '%s' refcount=%d",e,e->name().c_str(),e->refcount()); } #endif disconnect(true,0,true); m_data.clear(); }
// Try to start RTP for all media bool SDPSession::startRtp(RefObject* context) { if (m_rtpForward || !m_rtpMedia || (m_mediaStatus != MediaStarted)) return false; DDebug(m_parser,DebugAll,"SDPSession::startRtp(%p) [%p]",context,this); bool ok = false; for (ObjList* o = m_rtpMedia->skipNull(); o; o = o->skipNext()) { SDPMedia* m = static_cast<SDPMedia*>(o->get()); ok = dispatchRtp(m,m_rtpAddr,true,false,context) || ok; } return ok; }
SIPTransaction* SIPEngine::addMessage(SIPMessage* message) { DDebug(this,DebugInfo,"addMessage(%p) [%p]",message,this); if (!message) return 0; // make sure outgoing messages are well formed if (message->isOutgoing()) message->complete(this); // locate the branch parameter of last Via header - added by the UA const MimeHeaderLine* hl = message->getLastHeader("Via"); if (!hl) #ifdef SIP_STRICT return 0; #else Debug(this,DebugMild,"Received message with no Via header! (sender bug)"); #endif const NamedString* br = hl ? hl->getParam("branch") : 0; String branch; if (br && br->startsWith("z9hG4bK")) branch = *br; Lock lock(this); SIPTransaction* forked = 0; ObjList* l = &m_transList; for (; l; l = l->next()) { SIPTransaction* t = static_cast<SIPTransaction*>(l->get()); if (!t) continue; switch (t->processMessage(message,branch)) { case SIPTransaction::Matched: return t; case SIPTransaction::NoDialog: forked = t; break; case SIPTransaction::NoMatch: default: break; } } if (forked) return forkInvite(message,forked); if (message->isAnswer()) { Debug(this,DebugInfo,"Message %p was an unhandled answer [%p]",message,this); return 0; } if (message->isACK()) { DDebug(this,DebugAll,"Message %p was an unhandled ACK [%p]",message,this); return 0; } message->complete(this); return new SIPTransaction(message,this,message->isOutgoing()); }