void AmSessionContainer::startSessionUAS(AmSipRequest& req)
{
  as_mut.lock();
  try {
	
    AmSession* session = getSession(req.callid,req.from_tag);
    if( session ){
	    
      // it's a forked-and-merged INVITE
      // reply 482 Loop detected
      throw AmSession::Exception(482, "Loop detected");
    }
    else {
      // Call-ID and From-Tag are unknown: it's a new session
      AmSession* session;
      if((session = createSession(req)) != 0){

	// update session's local tag (ID) if not already set
	session->setLocalTag();
	const string& local_tag = session->getLocalTag();
	// by default each session is in its own callgroup
	session->setCallgroup(local_tag);

	if (AmConfig::LogSessions) {
	  INFO("Starting UAS session %s app %s\n",
	       session->getLocalTag().c_str(), req.cmd.c_str());
	}

	session->start();

	addSession_unsafe(req.callid,req.from_tag,local_tag,session);
	session->postEvent(new AmSipRequestEvent(req));
      }
    }
  } 
  catch(const AmSession::Exception& e){
    ERROR("%i %s\n",e.code,e.reason.c_str());
    AmSipDialog::reply_error(req,e.code,e.reason);
  }
  catch(const string& err){
    ERROR("startSession: %s\n",err.c_str());
    AmSipDialog::reply_error(req,500,err);
  }
  catch(...){
    ERROR("unexpected exception\n");
    AmSipDialog::reply_error(req,500,"unexpected exception");
  }
  as_mut.unlock();
}
Esempio n. 2
0
string DIDial::dialout_pin(const string& application, 
			   const string& pin,
			   const string& user, 
			   const string& to_user			   
		       ) {
  DBG("dialout application '%s', user '%s', to_user '%s', pin '%s'", 
      application.c_str(), user.c_str(), to_user.c_str(), pin.c_str());

    // find pin
  map<string, DIDialoutInfo>::iterator it = DIDialFactory::dialout_pins.find(pin);
  if (it != DIDialFactory::dialout_pins.end()) {
    AmArg* a = new AmArg();
    a->setBorrowedPointer(new UACAuthCred(it->second.realm, 
					  it->second.user, 
					  it->second.pwd));
    
    AmSession* s = AmUAC::dialout(user.c_str(), application,  
				  "sip:"+to_user+"@"+it->second.realm,  
				  "<sip:" + it->second.user+"@"+it->second.realm + ">", 
				  "sip:"+it->second.user+"@"+it->second.realm, 
				  "<sip:" + to_user+"@"+it->second.realm + ">", 
				  string(""), // callid
				  a);
    if (s)
      return s->getLocalTag();
    else 
      return "<failed>\n";
  } else 
    return "incorrect dialout pin.\n";
}
void WebConferenceFactory::dialout(const AmArg& args, AmArg& ret) {
  for (int i=0;i<6;i++)
    assertArgCStr(args.get(1));

  string room        = args.get(0).asCStr();
  string adminpin    = args.get(1).asCStr();
  string callee      = args.get(2).asCStr();
  string from_user   = args.get(3).asCStr();
  string domain      = args.get(4).asCStr();
  string auth_user   = args.get(5).asCStr();
  string auth_pwd    = args.get(6).asCStr();

  string from = "sip:" + from_user + "@" + domain;
  string to   = "sip:" + callee + "@" + domain;

  // check adminpin
  rooms_mut.lock();
  ConferenceRoom* r = getRoom(room, adminpin);
  rooms_mut.unlock();
  if (NULL == r) {
      ret.push(1);
      ret.push("wrong adminpin");
      ret.push("");
      return;
  }

  DBG("dialout webconference room '%s', from '%s', to '%s'", 
      room.c_str(), from.c_str(), to.c_str());

  AmArg* a = new AmArg();
  a->setBorrowedPointer(new UACAuthCred("", auth_user, auth_pwd));

  AmSession* s = AmUAC::dialout(room.c_str(), APP_NAME,  to,  
				"<" + from +  ">", from, "<" + to + ">", 
				string(""), // local tag
				string(""), // hdrs
				a);
  if (s) {
    string localtag = s->getLocalTag();
    ret.push(0);
    ret.push("OK");
    ret.push(localtag.c_str());
    newParticipant(room, localtag, to);
    updateStatus(room, localtag,
		 ConferenceRoomParticipant::Connecting,
		 "INVITE");
  }
  else {
    ret.push(1);
    ret.push("internal error");
    ret.push("");
  }
}
Esempio n. 4
0
string DIDial::dialout(const string& application, 
		       const string& user, 
		       const string& from, 
		       const string& to) {
  DBG("dialout application '%s', user '%s', from '%s', to '%s'", 
      application.c_str(), user.c_str(), from.c_str(), to.c_str());

  AmSession* s = AmUAC::dialout(user.c_str(), application,  to,  
				"<" + from +  ">", from, "<" + to + ">");
  if (s)
    return s->getLocalTag();
  else 
    return "<failed>";  
}
AmSession* AmSessionContainer::startSessionUAC(AmSipRequest& req, AmArg* session_params) {
  AmSession* session = NULL;
  as_mut.lock();
  try {
    if((session = createSession(req, session_params)) != 0){
      session->dlg.updateStatusFromLocalRequest(req); // sets local tag as well
      session->setCallgroup(req.from_tag);

      session->setNegotiateOnReply(true);
      if (int err = session->sendInvite(req.hdrs)) {
	ERROR("INVITE could not be sent: error code = %d.\n", 
	      err);
	delete session;
	as_mut.unlock();
	return NULL;
      }

      if (AmConfig::LogSessions) {      
	INFO("Starting UAC session %s app %s\n",
	     session->getLocalTag().c_str(), req.cmd.c_str());
      }

      session->start();

      addSession_unsafe(req.callid,"",req.from_tag,session);
      // session does not get its own INVITE
      //      session->postEvent(new AmSipRequestEvent(req)); 
    }
  } 
  catch(const AmSession::Exception& e){
    ERROR("%i %s\n",e.code,e.reason.c_str());
    AmSipDialog::reply_error(req,e.code,e.reason);
  }
  catch(const string& err){
    ERROR("startSession: %s\n",err.c_str());
    AmSipDialog::reply_error(req,500,err);
  }
  catch(...){
    ERROR("unexpected exception\n");
    AmSipDialog::reply_error(req,500,"unexpected exception");
  }
  as_mut.unlock();
  return session;
}
Esempio n. 6
0
string DIDial::dialout_auth(const string& application, 
		       const string& user, 
		       const string& from, 
		       const string& to,
		       const string& a_realm, 
		       const string& a_user, 
		       const string& a_pwd
		       ) {
  DBG("dialout application '%s', user '%s', from '%s', to '%s'", 
      application.c_str(), user.c_str(), from.c_str(), to.c_str());

  AmArg* a = new AmArg();
  a->setBorrowedPointer(new UACAuthCred(a_realm, a_user, a_pwd));

  AmSession* s = AmUAC::dialout(user.c_str(), application,  to,  
				"<" + from +  ">", from, "<" + to + ">", 
				string(""), // callid
				a);
  if (s)
    return s->getLocalTag();
  else 
    return "<failed>\n";
}
void WebConferenceFactory::dialout(const AmArg& args, AmArg& ret) {
  for (int i=0;i<6;i++)
    assertArgCStr(args.get(i));

  string room        = args.get(0).asCStr();
  string adminpin    = args.get(1).asCStr();
  string callee      = args.get(2).asCStr();
  string from_user   = args.get(3).asCStr();
  string domain      = args.get(4).asCStr();
  string auth_user   = args.get(5).asCStr();
  string auth_pwd    = args.get(6).asCStr();
  string callee_domain;
  string headers;

  try {
    assertArgCStr(args.get(7));
    headers = args.get(7).asCStr();
    int i, len;
    len = headers.length();
    for (i = 0; i < len; i++) {
      if (headers[i] == '|') headers[i] = '\n';
    }
    if (headers[len - 1] != '\n') {
      headers += '\n';
    }
  }
  catch (AmArg::OutOfBoundsException &e) {
    headers = "";
  }

  try {
    assertArgCStr(args.get(8));
    callee_domain = args.get(8).asCStr();
  }
  catch (AmArg::OutOfBoundsException &e) {
    callee_domain = domain;
  }

  string from = "sip:" + from_user + "@" + domain;
  string to   = "sip:" + callee + "@" + callee_domain;

  // check adminpin
  rooms_mut.lock();
  
  // sweep rooms (if necessary)
  sweepRooms();

  ConferenceRoom* r = getRoom(room, adminpin);
  rooms_mut.unlock();
  if (NULL == r) {
      ret.push(1);
      ret.push("wrong adminpin");
      ret.push("");
      return;
  }

  DBG("dialout webconference room '%s', from '%s', to '%s'", 
      room.c_str(), from.c_str(), to.c_str());

  AmArg* a = new AmArg();
  a->setBorrowedPointer(new UACAuthCred("", auth_user, auth_pwd));

  AmSession* s = AmUAC::dialout(room.c_str(), APP_NAME,  to,  
				"<" + from +  ">", from, "<" + to + ">", 
				string(""), // callid
				headers, // headers
				a);
  if (s) {
    string localtag = s->getLocalTag();
    ret.push(0);
    ret.push("OK");
    ret.push(localtag.c_str());
    newParticipant(room, localtag, to);
    updateStatus(room, localtag,
		 ConferenceRoomParticipant::Connecting,
		 "INVITE");
  }
  else {
    ret.push(1);
    ret.push("internal error");
    ret.push("");
  }
}