Ejemplo n.º 1
0
void MyCCDialog::onDtmf(int event, int duration) {
  DBG("MyCCDialog::onDtmf, got event %d, duration %d.\n", event, duration);

  switch (state) {
  case CC_Collecting_PIN: {
    // flush the playlist (stop playing) 
    // if a key is entered
    playlist.flush(); 
    
    if(event <10) {
      pin +=int2str(event);
      DBG("pin is now '%s'\n", pin.c_str());
    } else {
      	AmArg di_args,ret;
	di_args.push(pin.c_str());
	cc_acc->invoke("getCredit", di_args, ret);
	credit = ret.get(0).asInt();
      if (credit < 0) {
	addToPlaylist(MyCCFactory::IncorrectPIN);	
	pin = "";
      } else if (credit == 0) {
	addToPlaylist(MyCCFactory::OutOfCredit);
	pin = "";
      } else {
	number = "";
	state = CC_Collecting_Number;
	addToPlaylist(MyCCFactory::EnterNumber);
      }
    } 
  } break;
  case CC_Collecting_Number: {
    // flush the playlist (stop playing) 
    // if a key is entered
    playlist.flush(); 
    if(event <10) {
      number +=int2str(event);
      DBG("number is now '%s'\n", number.c_str());
    } else {
      if (getCalleeStatus() == None) {
	state = CC_Dialing;
	connectCallee(number + " <sip:" + number+ MyCCFactory::ConnectSuffix + ">", 
		      "sip:"+number+MyCCFactory::ConnectSuffix);
	addToPlaylist(MyCCFactory::Dialing);
      }
    }   
  }
    break;
    case CC_Dialing: 
    case CC_Connected: 
  default: break;
  };
}
Ejemplo n.º 2
0
void B2BTransDialog::onSessionStart(const AmSipRequest& req)
{
  DBG("B2BTransDialog connecting callee\n");

  std::ostringstream os;
  os << "r_uri=" << req.r_uri << "; ";
  os << "to=" << req.to << "; ";
  os << "from_uri=" << req.from_uri << "; ";
  os << "from=" << req.from;
  DBG(os.str().c_str());
  
  connectCallee("<sip:[email protected]>","sip:[email protected]",req.from_uri,req.from);
}
Ejemplo n.º 3
0
void C2DCallerDialog::process(AmEvent* event)
{
  AmAudioEvent* audio_event = dynamic_cast<AmAudioEvent*>(event);
  if(audio_event && audio_event->event_id == AmAudioEvent::cleared) {

    if(getCalleeStatus() != None)
      return;
    AmMediaProcessor::instance()->removeSession(this);

    connectCallee(string("<") + callee_uri + ">", callee_uri);
    return;
  }

  AmB2BCallerSession::process(event);
}
Ejemplo n.º 4
0
void ServiceLineCallerDialog::onDtmf(int event, int duration)
{
  DBG("DTMF event %d duration %d\n", event, duration);
  if (getCalleeStatus() != None)
    return;
  
  if ((event < 10) && (event >= 0) && 
      (!ServiceLineFactory::callee_numbers[event].empty())) {
    connectCallee("sip:"+ServiceLineFactory::callee_numbers[event]+"@"+ServiceLineFactory::GWDomain, 
		  "sip:"+ServiceLineFactory::callee_numbers[event]+"@"+ServiceLineFactory::GWDomain, 
		  "sip:"+ServiceLineFactory::GWUser+"@"+ServiceLineFactory::GWDomain, 
		  "sip:"+ServiceLineFactory::GWUser+"@"+ServiceLineFactory::GWDomain);
  }

  return;
  
}
Ejemplo n.º 5
0
void CallTimerDialog::onInvite(const AmSipRequest& req)
{

  if (dlg.getStatus() == AmSipDialog::Connected) {
    DBG("not acting on re-Invite\n");
    return;
  }
    
  setReceiving(false);
  AmMediaProcessor::instance()->removeSession(this);

  m_state = BB_Dialing;

  if(dlg.reply(req, 100, "Trying") != 0) {
    throw AmSession::Exception(500,"Failed to reply 100");
  }

  invite_req = req;
  size_t pos1, pos2, hdr_start;

  // remove P-App-Name, P-App-Param header
  if (findHeader(invite_req.hdrs,PARAM_HDR, pos1, pos2, 
		 hdr_start)) {
    while (invite_req.hdrs[pos2]=='\r' ||invite_req.hdrs[pos2]=='\n') 
      pos2++;

    hdr_start -= 11; //"P-App-Param"
    invite_req.hdrs.erase(hdr_start, pos2-hdr_start);
  }

  if (findHeader(invite_req.hdrs,"P-App-Name", pos1, pos2, 
		 hdr_start)) {
    while (invite_req.hdrs[pos2]=='\r' ||invite_req.hdrs[pos2]=='\n') 
      pos2++;
    hdr_start -= 10; //"P-App-Name"
    invite_req.hdrs.erase(hdr_start, pos2-hdr_start);
  }

  dlg.updateStatus(invite_req);
  recvd_req.insert(std::make_pair(invite_req.cseq,invite_req));
  
  set_sip_relay_only(true);
  connectCallee(invite_req.to, invite_req.r_uri, true);
}
Ejemplo n.º 6
0
void CallBackDialog::process(AmEvent* ev)
{
  // audio events
  AmAudioEvent* audio_ev = dynamic_cast<AmAudioEvent*>(ev);
  if (audio_ev  && 
      audio_ev->event_id == AmAudioEvent::noAudio) {
    DBG("########## noAudio event #########\n");
    if (CBTellingNumber == state) {
      state = CBConnecting;
      string callee = "sip:" + call_number + "@" + CallBackFactory::gw_domain;
      string caller = "sip:" + CallBackFactory::gw_user + "@" +  CallBackFactory::gw_domain;
      connectCallee(callee, callee, 
		    caller, caller);
    }
    return;
  }
  
  AmB2ABSession::process(ev);
}
Ejemplo n.º 7
0
void AnnounceCallerDialog::process(AmEvent* event)
{

  AmAudioEvent* audio_event = dynamic_cast<AmAudioEvent*>(event);
  if(audio_event && (audio_event->event_id == AmAudioEvent::cleared)){

    if (getCalleeStatus() != None)
      return;
	
    // detach this session from the media
    // because we will stay in signaling only
    AmMediaProcessor::instance()->removeSession(this);

    connectCallee(callee_addr, callee_uri);
    return;
  }
    
  AmB2BCallerSession::process(event);
}
Ejemplo n.º 8
0
void SWPrepaidSIPDialog::onInvite(const AmSipRequest& req)
{
  // TODO: do reinvites get here? if so, don't set a timer then

  // TODO: errors thrown as exception don't seem to trigger a reply?

  // this will prevent us from being added to media processor
  setInOut(NULL,NULL);

  m_uuid = getHeader(req.hdrs,"P-Caller-Uuid");
  if(!m_uuid.length()) {
    ERROR("Application header P-Caller-Uuid not found\n");
    throw AmSession::Exception(500, "could not get UUID parameter");
  }

  m_proxy = getHeader(req.hdrs,"P-Proxy");
  if(!m_proxy.length()) {
    ERROR("Application header P-Proxy not found\n");
    throw AmSession::Exception(500, "could not get PROXY parameter");
  }

  m_ruri = getHeader(req.hdrs,"P-R-Uri");
  if(!m_ruri.length()) {
    ERROR("Application header P-R-Uri not found\n");
    throw AmSession::Exception(500, "could not get RURI parameter");
  }

  m_dest = getHeader(req.hdrs,"P-Acc-Dest");

  if(!m_dest.length()) {
    ERROR("Application header P-Acc-Dest not found\n");
    throw AmSession::Exception(500, "could not get destination pattern parameter");
  }

  DBG("UUID '%s' and pattern '%s' prepared for prepaid processing\n", m_uuid.c_str(), m_dest.c_str());

  m_starttime = time(NULL);
  m_localreq = req;

  AmArg di_args,ret;
  di_args.push(m_uuid.c_str());
  di_args.push((int)m_starttime);
  di_args.push(m_dest.c_str());
  m_cc_acc->invoke("getCredit", di_args, ret);
  m_credit = ret.get(0).asInt();

  if(m_credit == -1) {
    ERROR("Failed to fetch credit from accounting module\n");
    if(dlg.reply(req, 500, "Failed to fetch credit") != 0) {
      throw AmSession::Exception(500,"Failed to fetch credit");
    }
    return;
  }
  else if(m_credit == 0) {
    DBG("No credit left\n");
    m_state = CC_Teardown;
    if(dlg.reply(req, 402, "Unsufficient Credit") != 0) {
      throw AmSession::Exception(500,"Failed to reply 402");
    }
    setStopped();
    //throw AmSession::Exception(402, "Unsufficient Credit");
  }
  else {
    DBG("Credit for UUID %s is %d seconds, calling %s now\n", m_uuid.c_str(), m_credit, req.r_uri.c_str());
    m_state = CC_Dialing;

    if(dlg.reply(req, 101, "Connecting") != 0) {
      throw AmSession::Exception(500,"Failed to reply 101");
    }

    invite_req = req;
    dlg.updateStatus(req);
    recvd_req.insert(std::make_pair(req.cseq,req));

    connectCallee("<" + m_ruri + ">", m_proxy + ";sw_prepaid", true);
    set_sip_relay_only(true);
  }
}
Ejemplo n.º 9
0
void DSMCall::B2BconnectCallee(const string& remote_party,
				 const string& remote_uri,
				 bool relayed_invite) {
  connectCallee(remote_party, remote_uri, relayed_invite);
}