bool ChanAssistList::received(Message& msg, int id) { String* chanId = msg.getParam("id"); if (!chanId || chanId->null()) return (id < Private) && Module::received(msg,id); Lock mylock(this); RefPointer <ChanAssist> ca = find(*chanId); switch (id) { case Startup: if (ca) { Debug(this,DebugNote,"Channel '%s' already assisted!",chanId->c_str()); mylock.drop(); ca->msgStartup(msg); return false; } ca = create(msg,*chanId); if (ca) { m_calls.append(ca); mylock.drop(); ca->msgStartup(msg); } return false; case Hangup: if (ca) { removeAssist(ca); mylock.drop(); ca->msgHangup(msg); ca->deref(); ca = 0; } return false; case Execute: if (ca) { mylock.drop(); ca->msgExecute(msg); return false; } ca = create(msg,*chanId); if (ca) { m_calls.append(ca); mylock.drop(); ca->msgStartup(msg); ca->msgExecute(msg); } return false; case Disconnected: mylock.drop(); return ca && ca->msgDisconnect(msg,msg.getValue("reason")); default: mylock.drop(); if (ca) return received(msg,id,ca); return (id < Private) && Module::received(msg,id); } }
bool FaxDriver::msgExecute(Message& msg, String& dest) { static const Regexp r("^\\([^/]*\\)/\\(.*\\)$"); if (!dest.matches(r)) return false; bool transmit = false; if ((dest.matchString(1) == "send") || (dest.matchString(1) == "transmit")) transmit = true; else if (dest.matchString(1) != "receive") { Debug(this,DebugWarn,"Invalid fax method '%s', use 'receive' or 'transmit'", dest.matchString(1).c_str()); return false; } dest = dest.matchString(2); RefPointer<FaxChan> fc; CallEndpoint* ce = static_cast<CallEndpoint *>(msg.userData()); if (ce) { fc = new FaxChan(true,dest,transmit,msg); fc->initChan(); fc->deref(); if (fc->connect(ce,msg.getValue("reason"))) { msg.setParam("peerid",fc->id()); msg.setParam("targetid",fc->id()); fc->answer(msg,msg.getValue("id",ce->id())); return true; } } else { fc = new FaxChan(false,dest,transmit,msg); fc->initChan(); fc->deref(); Message m("call.route"); fc->complete(m); fc->setParams(m,fc->guessType(msg),FaxChan::guessT38(msg)); m.userData(fc); String callto = msg.getValue("caller"); if (callto) m.addParam("caller",callto); callto = msg.getValue("direct"); if (callto.null()) { const char* targ = msg.getValue("target"); if (!targ) { Debug(DebugWarn,"Outgoing fax call with no target!"); return false; } m.addParam("called",targ); if (!Engine::dispatch(m) || m.retValue().null()) { Debug(this,DebugWarn,"Outgoing fax call but no route!"); return false; } callto = m.retValue(); } m = "call.execute"; m.addParam("callto",callto); m.retValue().clear(); if (Engine::dispatch(m)) { fc->callAccept(m); return true; } Debug(this,DebugWarn,"Outgoing fax call not accepted!"); } return false; }