Пример #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;
}