예제 #1
0
bool Configfile::provide()
{
    std::string tmp(_filename);
    tmp += ".new";

    std::ofstream fd(tmp.c_str());

    if (!fd.good())
    {
        _errors.push_back(STG(FMT("unable to open file '%s': %s")
            % tmp % strerror(errno)));
        return false;
    }

    if (!serialize(fd))
    {
        fd.close();
        return false;
    }

    fd.close();

    if (rename(tmp.c_str(), _filename.c_str()) != 0)
    {
        _errors.push_back(STG(FMT("unable to replace config file '%s': %s")
            % _filename % strerror(errno)));
        return false;
    }

    return true;
}
예제 #2
0
bool BoardGSM::KhompPvtGSM::doChannelHangup(CommandRequest &cmd)
{
    DBG(FUNC, PVT_FMT(_target, "(GSM) c"));

    bool ret = true;

    try
    {
        ScopedPvtLock lock(this);

        int owner_nr = 0;

        command(KHOMP_LOG, CM_DISCONNECT,
                STG(FMT("gsm_call_ref=%d") % (int)owner_nr).c_str());


        //ret = KhompPvt::doChannelHangup(cmd);

    }
    catch (ScopedLockFailed & err)
    {
        LOG(ERROR, PVT_FMT(_target,"(GSM) r (unable to lock %s!)") % err._msg.c_str() );
        return false;
    }

    DBG(FUNC, PVT_FMT(_target, "(GSM) r"));

    return ret;
}
RingbackDefs::RingbackStType BoardE1::KhompPvtR2::sendRingBackStatus(int rb_value)
{
    DBG(FUNC,PVT_FMT(_target, "(p=%p) this is the r2 ringback procedure") % this);   

    std::string cause = (rb_value == -1 ? "" : STG(FMT("r2_cond_b=\"%d\"") % rb_value));
    return (command(KHOMP_LOG, CM_RINGBACK, cause.c_str()) ?
            RingbackDefs::RBST_SUCCESS : RingbackDefs::RBST_FAILURE);
}
RingbackDefs::RingbackStType BoardE1::KhompPvtISDN::sendRingBackStatus(int rb_value)
{
    DBG(FUNC, PVT_FMT(target(), "this is the rdsi ringback procedure"));


    std::string cause = (rb_value == -1 ? "" : STG(FMT("isdn_cause=\"%d\"") % rb_value));
    return (command(KHOMP_LOG, CM_RINGBACK, cause.c_str()) ?
            RingbackDefs::RBST_SUCCESS : RingbackDefs::RBST_FAILURE);
}
예제 #5
0
void BoardGSM::KhompPvtGSM::reportFailToReceive(int fail_code)
{
    KhompPvt::reportFailToReceive(fail_code);

    command(KHOMP_LOG, CM_CONNECT);

    /* K3L may fail depending on its configuration (GsmModem) */
    if (!command(KHOMP_LOG, CM_DISCONNECT))
    {
        int owner_nr = 0;
        command(KHOMP_LOG, CM_DISCONNECT,
                STG(FMT("gsm_call_ref=\"%d\"") % owner_nr).c_str());
    }

}
int BoardE1::KhompPvtR2::makeCall(std::string params)
{
    DBG(FUNC,PVT_FMT(_target, "(R2) c"));   

    if (callR2()->_r2_category != -1)
        params += STG(FMT("r2_categ_a=\"%ld\"")
                % callR2()->_r2_category);

    int ret = KhompPvtE1::makeCall(params);

    call()->_cleanup_upon_hangup = (ret == ksInvalidParams);
    
    DBG(FUNC,PVT_FMT(_target, "(R2) r"));   

    return ret;
}
int BoardE1::KhompPvtR2::doChannelAnswer(CommandRequest &cmd)
{
    try
    {
        ScopedPvtLock lock(this);

        // is this a collect call?
        bool has_recv_collect_call = _call->_collect_call;

        // do we have to drop collect calls?
        bool has_drop_collect_call = Opt::_drop_collect_call
            || _call->_flags.check(Kflags::DROP_COLLECT)
            || _call->_flags.check(Kflags::FILTER_COLLECT);

        // do we have to drop THIS call?
        bool do_drop_call = has_drop_collect_call && has_recv_collect_call;

        // do we have to send ringback? yes we need !!!
        if(call()->_flags.check(Kflags::NEEDS_RINGBACK_CMD))
        {       
            call()->_flags.clear(Kflags::NEEDS_RINGBACK_CMD);
            std::string cause = ( do_drop_call ? STG(FMT("r2_cond_b=\"%d\"") % kgbBusy) : "" );
            command(KHOMP_LOG,CM_RINGBACK,cause.c_str());

            usleep(75000);
        }

        if(has_drop_collect_call) 
        {
            DBG(FUNC, PVT_FMT(target(), "dropping collect call"));
            command(KHOMP_LOG, CM_DROP_COLLECT_CALL);
        }

    }
    catch (ScopedLockFailed & err)
    {
        K::Logger::Logg(C_ERROR,PVT_FMT(_target,"unable to lock %s!") % err._msg.c_str() );
        return ksFail;
    }

    KhompPvtE1::doChannelAnswer(cmd);
}
예제 #8
0
bool Configfile::obtain()
{
    std::ifstream fd(_filename.c_str());

    if (!fd.is_open())
    {
        _errors.push_back(STG(FMT("unable to open file '%s': %s")
            % _filename % strerror(errno)));
        return false;
    };

    if (!deserialize(fd))
    {
        fd.close();
        return false;
    }

    fd.close();
    return true;
};
예제 #9
0
 NotFound(const std::string & type, const std::string & name, const std::string & me)
 : std::runtime_error(STG(FMT("%s '%s' not found on section '%s'") % type % name % me)) {};
예제 #10
0
int BoardFXO::KhompPvtFXO::makeCall(std::string params)
{
    DBG(FUNC,PVT_FMT(_target, "(FXO) c"));

    int ret = ksSuccess;

    /* we always have audio */
    call()->_flags.set(Kflags::HAS_PRE_AUDIO);
    
    if(callFXO()->_call_info_drop == 0 && !callFXO()->_call_info_report)
    {
        command(KHOMP_LOG, CM_DISABLE_CALL_ANSWER_INFO);
    }

    if (!callFXO()->_pre_digits.empty())
    {
        /* Seize the line at local PABX. */

        callFXO()->_flags.set(Kflags::CALL_WAIT_SEIZE);

        if (!command(KHOMP_LOG, CM_SEIZE, call()->_orig_addr.c_str()))
            return ksFail;            

        int timeout = 150;

        if(!loopWhileFlagTimed(Kflags::CALL_WAIT_SEIZE, timeout))
            return ksFail;

        if (callFXO()->_flags.check(Kflags::CALL_WAIT_SEIZE) || (timeout <= 0))
            return ksFail;

        /* Grab line from local PABX. */

        callFXO()->_flags.set(Kflags::WAIT_SEND_DTMF);

        if (!command(KHOMP_LOG, CM_DIAL_DTMF, callFXO()->_pre_digits.c_str()))
            return ksFail;            
        
        if(!loopWhileFlagTimed(Kflags::WAIT_SEND_DTMF, timeout))
            return ksFail;

        if (callFXO()->_flags.check(Kflags::WAIT_SEND_DTMF) || (timeout <= 0))
            return ksFail;

        /* Seize line from public central (works because the     *
        * continuous cadence is always detected by the k3l api. */

        callFXO()->_flags.set(Kflags::CALL_WAIT_SEIZE);

        if (!command(KHOMP_LOG, CM_SEIZE, call()->_orig_addr.c_str()))
            return ksFail;

        if(!loopWhileFlagTimed(Kflags::CALL_WAIT_SEIZE, timeout))
            return ksFail;

        if (callFXO()->_flags.check(Kflags::CALL_WAIT_SEIZE) || (timeout <= 0))
            return ksFail;

        /* we want the audio as soon as dialing ends */
        callFXO()->_flags.set(Kflags::EARLY_RINGBACK);
    
        if (!command(KHOMP_LOG, CM_DIAL_DTMF, call()->_dest_addr.c_str()))
            return ksFail;
    }
    else
    {
        /* we want the audio as soon as dialing ends */
        callFXO()->_flags.set(Kflags::EARLY_RINGBACK);


        if(!call()->_orig_addr.empty())
            params += STG(FMT(" orig_addr=\"%s\"") % _call->_orig_addr);


        ret = KhompPvt::makeCall(params);

        if(ret != ksSuccess)
        {
            LOG(ERROR, PVT_FMT(target(), "Fail on make call"));
        }

        call()->_cleanup_upon_hangup = (ret == ksInvalidParams);
    }

    DBG(FUNC,PVT_FMT(_target, "(FXO) r"));
    return ret;
}
예제 #11
0
bool Configfile::deserialize(std::ifstream & fd)
{
    Section * section = NULL;

    /* default selection! */
    if (!select(&section))
    {
        _errors.push_back("default selection has failed!");
        return false;
    }

    size_t count = 0;

    while (fd.good())
    {
        std::string str;

        /* read one line! */
        std::getline(fd, str);

        size_t lst = str.size() - 1;

        if (str.size() >= 1 && str[lst] == '\r') //cuida das quebras de linha do tipo \r\n
        {
            str.erase(lst,1);
            --lst;
        }

        /* empty line! */
        if (str.size() == 0)
            continue;

        /* comment! */
        if (str[0] == '#')
            continue;

        ++count;

        if (str[0] == '[' && str[lst] == ']')
        {
            str.erase(0,1);   --lst;
            str.erase(lst,1); --lst;

            if (!select(&section, str))
            {
                _errors.push_back(STG(FMT("erroneous section '%s'") % str));

                /* ignore this section */
                section = NULL;
                continue;
            }
        }
        else
        {
            std::string::size_type pos = str.find('=');

            if (pos == std::string::npos)
            {
                _errors.push_back(STG(FMT("erroneous separator '%s'") % str));
                continue;
            };

            if (section == NULL)
            {
                _errors.push_back(STG(FMT("no section for option '%s'") % str));
                continue;
            }

            std::string  opt(str.substr(0,pos));
            std::string  val(str.substr(pos+1));

            if (_ignores.find(opt) != _ignores.end())
                continue;

            if (val == "@") val = "";

            if (adjust(section, opt, val))
                continue;

            _errors.push_back(STG(FMT("option '%s' does "
                "not exist or '%s' is not a valid value (at section '%s')")
                % opt % val % section->name()));
        }
    }

    // retorna 'true' se arquivo tinha alguma coisa valida.
    return (count != 0);
}