示例#1
0
// Attach a tone detector on "chan.attach" as consumer or sniffer
bool AttachHandler::received(Message& msg)
{
    String cons(msg.getValue("consumer"));
    if (!cons.startsWith("tone/"))
	cons.clear();
    String snif(msg.getValue("sniffer"));
    if (!snif.startsWith("tone/"))
	snif.clear();
    if (cons.null() && snif.null())
	return false;
    CallEndpoint* ch = static_cast<CallEndpoint*>(msg.userObject("CallEndpoint"));
    RefPointer<DataEndpoint> de = static_cast<DataEndpoint*>(msg.userObject("DataEndpoint"));
    DataSource* ds = static_cast<DataSource*>(msg.userObject("DataSource"));
    if (ch) {
	if (cons) {
	    ToneConsumer* c = new ToneConsumer(ch->id(),cons);
	    c->setFaxDivert(msg);
	    ch->setConsumer(c);
	    c->deref();
	}
	if (snif) {
	    de = ch->setEndpoint();
	    // try to reinit sniffer if one already exists
	    ToneConsumer* c = static_cast<ToneConsumer*>(de->getSniffer(snif));
	    if (c) {
		c->init();
		c->setFaxDivert(msg);
	    }
	    else {
		c = new ToneConsumer(ch->id(),snif);
		c->setFaxDivert(msg);
		de->addSniffer(c);
		c->deref();
	    }
	}
	return msg.getBoolValue("single");
    }
    else if (ds && cons) {
	ToneConsumer* c = new ToneConsumer(msg.getValue("id"),cons);
	c->setFaxDivert(msg);
	bool ok = DataTranslator::attachChain(ds,c);
	if (ok)
	    msg.userData(c);
	else
	    msg.setParam("reason","attach-failure");
	c->deref();
	return ok && msg.getBoolValue("single");
    }
    else if (de && cons) {
	ToneConsumer* c = new ToneConsumer(msg.getValue("id"),cons);
	c->setFaxDivert(msg);
	de->setConsumer(c);
	c->deref();
	return msg.getBoolValue("single");
    }
    else
	Debug(&plugin,DebugWarn,"ToneDetector attach request with no call endpoint!");
    return false;
}
示例#2
0
// Attach a tone detector on "chan.attach" as consumer or sniffer
bool AttachHandler::received(Message& msg)
{
    String cons(msg.getValue("consumer"));
    if (!cons.startsWith("mrcp/"))
	cons.clear();
    String snif(msg.getValue("sniffer"));
    if (!snif.startsWith("mrcp/"))
	snif.clear();
    if (cons.null() && snif.null())
	return false;
    CallEndpoint* ch = static_cast<CallEndpoint *>(msg.userObject(YATOM("CallEndpoint")));
    if (ch) {
	if (cons) {
	    MrcpConsumer* c = new MrcpConsumer(ch->id(),cons,msg.getValue("format","slin"));
	    if (c->init(msg))
		ch->setConsumer(c);
	    c->deref();
	}
	if (snif) {
	    RefPointer<DataEndpoint> de = ch->setEndpoint();
	    // try to reinit sniffer if one already exists
	    MrcpConsumer* c = static_cast<MrcpConsumer*>(de->getSniffer(snif));
	    if (c)
		c->init(msg);
	    else {
		c = new MrcpConsumer(ch->id(),snif,msg.getValue("format","slin"));
		if (c->init(msg))
		    de->addSniffer(c);
		c->deref();
	    }
	}
	return msg.getBoolValue("single");
    }
    else
	Debug(&plugin,DebugWarn,"Attach request with no call endpoint!");
    return false;
}
示例#3
0
// Attach a tone detector on "chan.record" - needs just a CallEndpoint
bool RecordHandler::received(Message& msg)
{
    String src(msg.getValue("call"));
    String id(msg.getValue("id"));
    if (!src.startsWith("mrcp/"))
	return false;
    CallEndpoint* ch = static_cast<CallEndpoint *>(msg.userObject(YATOM("CallEndpoint")));
    RefPointer<DataEndpoint> de = static_cast<DataEndpoint *>(msg.userObject(YATOM("DataEndpoint")));
    if (ch) {
	id = ch->id();
	if (!de)
	    de = ch->setEndpoint();
    }
    if (de) {
	MrcpConsumer* c = new MrcpConsumer(id,src,msg.getValue("format","slin"));
	if (c->init(msg))
	    de->setCallRecord(c);
	c->deref();
	return true;
    }
    else
	Debug(&plugin,DebugWarn,"Record request with no call endpoint!");
    return false;
}
示例#4
0
// Attach a tone detector on "chan.record" - needs just a CallEndpoint
bool RecordHandler::received(Message& msg)
{
    String src(msg.getValue("call"));
    String id(msg.getValue("id"));
    if (!src.startsWith("tone/"))
	return false;
    CallEndpoint* ch = static_cast<CallEndpoint *>(msg.userObject("CallEndpoint"));
    RefPointer<DataEndpoint> de = static_cast<DataEndpoint *>(msg.userObject("DataEndpoint"));
    if (ch) {
	id = ch->id();
	if (!de)
	    de = ch->setEndpoint();
    }
    if (de) {
	ToneConsumer* c = new ToneConsumer(id,src);
	c->setFaxDivert(msg);
	de->setCallRecord(c);
	c->deref();
	return true;
    }
    else
	Debug(&plugin,DebugWarn,"ToneDetector record request with no call endpoint!");
    return false;
}
示例#5
0
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;
}