⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 test1.cxx

📁 Diameter协议栈
💻 CXX
📖 第 1 页 / 共 2 页
字号:
  EapContinuedPolicyElement md5Method;};// My application session (not used in this test program).class StandAloneAuthApplication : public AAA_JobData,                                  public PANA_PaaEventInterface{ public:  StandAloneAuthApplication(PANA_PaaSessionChannel &ch, ACE_Semaphore &sem)     : paaSession(ch, *this),      handle(EapJobHandle(AAA_GroupedJob::Create                          (ch.Node().Task().Job(), this, "standalone"))),      eap(boost::shared_ptr<MyStandAloneAuthSwitchStateMachine>	  (new MyStandAloneAuthSwitchStateMachine           (*ch.Node().Task().reactor(), handle))),      semaphore(sem),      identityMethod(EapContinuedPolicyElement(EapType(1))),      md5Method(EapContinuedPolicyElement(EapType(4))),      notificationMethod(EapContinuedPolicyElement(EapType(2)))  {    // start paa session    paaSession.Start();    paaSession.EnableDhcpBootstrap() = true;    // Policy settings for the authenticator    identityMethod.AddContinuedPolicyElement      (&md5Method, EapContinuedPolicyElement::PolicyOnSuccess);    identityMethod.AddContinuedPolicyElement      (&notificationMethod, EapContinuedPolicyElement::PolicyOnFailure);    eap->Policy().InitialPolicyElement(&identityMethod);  }  virtual ~StandAloneAuthApplication() {    paaSession.Stop();    }  void EapStart(bool &nap) {     eap->Stop();      eap->Start();  }  void EapResponse(AAAMessageBlock *response, bool nap) {      eap->Receive(response);  }  void EapAltReject() {  }  void Authorize(PANA_AuthorizationArgs &args) {     PANA_AuthScriptCtl::Print(args);  }  bool IsKeyAvailable(diameter_octetstring_t &key) {     return false;  }  bool IsUserAuthorized() {      return true;  }  void Notification(diameter_octetstring_t &msg) {      std::cout << "PANA notification: " << msg << std::endl;      paaSession.Stop();  }  bool ResumeSession() {      return false;  }  void Disconnect(ACE_UINT32 cause) {     eap->Stop();  }  void Error(ACE_UINT32 resultCode) {  }  MyStandAloneAuthSwitchStateMachine& Eap() {      return *eap;   }  ACE_Semaphore& Semaphore() { return semaphore; }  PANA_PaaSession &paa() { return paaSession; } private:  PANA_PaaSession paaSession;  EapJobHandle handle;  boost::shared_ptr<MyStandAloneAuthSwitchStateMachine> eap;  ACE_Semaphore &semaphore;  EapContinuedPolicyElement identityMethod;  EapContinuedPolicyElement md5Method;  EapContinuedPolicyElement notificationMethod;};class StandAloneSessionFactoryAdapter : public PANA_PaaSessionFactory{   public:      StandAloneSessionFactoryAdapter(PANA_Node &n, ACE_Semaphore &s) :          PANA_PaaSessionFactory(n), node(n), sem(s) { }      PANA_PaaSession *Create() {         StandAloneAuthApplication *app = new StandAloneAuthApplication             (*this, sem);         if (app) {	    return &(app->paa());	 }         return (0);      }   protected:      PANA_Node &node;      ACE_Semaphore &sem;};// ----------------- Definition --------------void MyPeerSwitchStateMachine::Send(AAAMessageBlock *b){  std::cout << "EAP Response sent from peer" << std::endl;  //ACE_INET_Addr newAddr("192.168.1.1:0");  JobData(Type2Type<PeerApplication>()).pac().EapSendResponse(b);}void MyPeerSwitchStateMachine::Success()  {    std::cout << "Authentication success detected at peer" << std::endl;    std::cout << "Welcome to the world, " 	      << PeerIdentity() 	      << " !!!" << std::endl;    // Let PANA bind on success to the EAP event   JobData(Type2Type<PeerApplication>()).pac().EapSuccess();  }void MyPeerSwitchStateMachine::Failure()  {    std::cout << "Authentication failure detected at peer" << std::endl;    std::cout << "Sorry, " 	      << PeerIdentity() 	      << " try next time !!!" << std::endl;    JobData(Type2Type<PeerApplication>()).pac().EapFailure();    JobData(Type2Type<PeerApplication>()).Eap().Stop();    //JobData(Type2Type<PeerApplication>()).Semaphore().release();  }void MyPeerSwitchStateMachine::Notification(std::string &str)  {    std::cout << "Following notification received" << std::endl;    std::cout << str << std::endl;  }void MyPeerSwitchStateMachine::Abort()  {    std::cout << "Peer aborted for an error in state machine" << std::endl;    JobData(Type2Type<PeerApplication>()).Eap().Stop();    JobData(Type2Type<PeerApplication>()).pac().EapFailure();    //JobData(Type2Type<PeerApplication>()).Semaphore().release();  }std::string& MyPeerSwitchStateMachine::InputIdentity()   {    if (gUserName.length() > 0) {        return gUserName;    }        identity = std::string("user2");    std::cout << "Input username (within 10sec.): " << std::endl;    std::cin >> identity;    std::cout << "username = " << identity << std::endl;    return identity;  }void MyStandAloneAuthSwitchStateMachine::Send(AAAMessageBlock *b)  {    std::cout << "EAP Request sent from authenticator" << std::endl;    JobData(Type2Type<StandAloneAuthApplication>()).paa().EapSendRequest(b);  }void MyStandAloneAuthSwitchStateMachine::Success(AAAMessageBlock *b)  {    std::cout << "EAP Success sent from authenticator" << std::endl;    JobData(Type2Type<StandAloneAuthApplication>()).paa().EapSuccess(b);  }void MyStandAloneAuthSwitchStateMachine::Success()  {    std::cout << "Success without an EAP Success" << std::endl;    JobData(Type2Type<StandAloneAuthApplication>()).Eap().Stop();    JobData(Type2Type<StandAloneAuthApplication>()).paa().EapSuccess();  }void MyStandAloneAuthSwitchStateMachine::Failure(AAAMessageBlock *b)  {    std::cout << "EAP Failure sent from authenticator" << std::endl;    JobData(Type2Type<StandAloneAuthApplication>()).paa().EapFailure(b);    JobData(Type2Type<StandAloneAuthApplication>()).Eap().Stop();  }void MyStandAloneAuthSwitchStateMachine::Failure()  {    std::cout << "Failure without an EAP Failure" << std::endl;    JobData(Type2Type<StandAloneAuthApplication>()).paa().EapFailure();    JobData(Type2Type<StandAloneAuthApplication>()).Eap().Stop();    //JobData(Type2Type<StandAloneAuthApplication>()).Semaphore().release();  }void MyStandAloneAuthSwitchStateMachine::Abort()  {    std::cout << "Session aborted for an error in state machine" << std::endl;    JobData(Type2Type<StandAloneAuthApplication>()).Eap().Stop();    JobData(Type2Type<StandAloneAuthApplication>()).paa().EapFailure();    //JobData(Type2Type<StandAloneAuthApplication>()).Semaphore().release();  }int main(int argc, char **argv){  std::string cfgfile;  std::string userdb;    bool b_client = false;  // Gather command line options  ACE_Get_Opt opt(argc, argv, "cf:u:U:P:A:", 1);      for (int c; (c = opt()) != (-1); ) {      switch (c) {          case 'f': cfgfile.assign(opt.optarg); break;          case 'c': b_client = true; break;          case 'u': userdb.assign(opt.optarg); break;              case 'U': gUserName.assign(opt.optarg); break;          case 'P': gPasswd.assign(opt.optarg); break;          case 'A': gPacAddrFromEp.assign(opt.optarg); break;      }  }  if ((opt.argc() < 1) ||      (cfgfile.length() == 0)) {    std::cout << "Usage: pana_test [-c] -f [configuration file]" << std::endl;    return (0);  }  else if (! b_client && (userdb.length() == 0)) {    std::cout << "Usage: pana_test [-c] -f [configuration file] -u [user db]" << std::endl;    return (0);  }  // Initialize the log.#ifdef WIN32  EapLogMsg_S::instance()->open("EAP", ACE_Log_Msg::STDERR);#else  EapLogMsg_S::instance()->open("EAP", ACE_Log_Msg::STDERR);#endif  EapLogMsg_S::instance()->enable_debug_messages();  // Register the mapping from EapType to the creator of the  // user-defined method class for each user-defined method  // implementation.  EapMethodStateMachineCreator<MyEapAuthIdentityStateMachine>     myAuthIdentityCreator;  EapMethodStateMachineCreator<MyEapPeerMD5ChallengeStateMachine>     myPeerMD5ChallengeCreator;  EapMethodStateMachineCreator<MyEapAuthMD5ChallengeStateMachine>     myAuthMD5ChallengeCreator;  EapMethodRegistrar methodRegistrar;  methodRegistrar.registerMethod    (std::string("Identity"), EapType(1),      Authenticator, myAuthIdentityCreator);  methodRegistrar.registerMethod    (std::string("MD5-Challenge"), EapType(4),      Peer, myPeerMD5ChallengeCreator);  methodRegistrar.registerMethod    (std::string("MD5-Challenge"), EapType(4), Authenticator,      myAuthMD5ChallengeCreator);  EapTask task;  ACE_Semaphore semaphore(0);  task.Start(5);    try {      if (b_client) {          PANA_Node node(task, cfgfile);          PeerApplication peer(node, semaphore);          peer.pac().Start();          semaphore.acquire();          task.Stop();      }      else {          USER_DB_OPEN(userdb);          PANA_Node node(task, cfgfile);          StandAloneSessionFactoryAdapter factory(node, semaphore);          if (gPacAddrFromEp.length() > 0) {	      ACE_INET_Addr pac(gPacAddrFromEp.data());              factory.PacFound(pac);	  }          semaphore.acquire();          task.Stop();          USER_DB_CLOSE();      }  }  catch (PANA_Exception &e) {      std::cout << "PANA exception: " << e.description() << std::endl;  }  catch (...) {      std::cout << "Unknown exception ... aborting" << std::endl;  }  return 0;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -