Exemple #1
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;
}