AnyConnect Secure Mobility Client  4.8.02045
CLIClientImpl Class Reference

#include <CLIClientImpl.h>

Public Member Functions

void printHostList ()
 
void printDefaultHost ()
 
void connect (std::string host, std::string user, std::string password, std::string group)
 
void disconnect ()
 
void showGroups (std::string host)
 
void getStats ()
 
void setUserData (ConnectPromptInfo &ConnectPrompt)
 
void printGroupList (ConnectPromptInfo &ConnectPrompt)
 
std::wstring convertMultiByteToWide (const std::string &sInputData)
 
- Public Member Functions inherited from ClientIfc
bool attach (ClientType clientType=ClientType_GUI, bool requestFullCapabilities=true, bool suppressAutoConnect=true)
 
void detach ()
 
virtual void ProcessEvents ()
 
bool hasFullCapabilities ()
 
bool isConnected ()
 
bool isAvailable ()
 
bool isVPNServiceAvailable ()
 
bool isOperatingMode (OperatingMode opMode)
 
std::list< tstringgetHostNames ()
 
tstring getDefaultHostName ()
 
bool connect (tstring host)
 
virtual bool setNewTunnelGroup (const tstring &group)
 
void cancel ()
 
void getState ()
 
void getStats ()
 
void resetStats ()
 
void startStats ()
 
void stopStats ()
 
void exportStats (const tstring &tstrFilePath)
 
void setBannerResponse (bool bAccepted)
 
void setCertBlockedResponse (bool bUnblock)
 
void setCertWarningResponse (bool bConnect, bool bImportCert)
 
void UserSubmit ()
 
PreferenceInfogetPreferences ()
 
bool savePreferences ()
 
tstring getConnectHost ()
 
void setLastVpnError (VPNError vpnError)
 
VPNError getLastVpnError ()
 
virtual bool connect (tstring host)
 
bool connect (tstring host, unsigned int origin)
 

Protected Member Functions

void StatsCB (VPNStats &stats)
 
void StateCB (const VPNState state, const VPNSubState subState, const tstring stateString)
 
void BannerCB (const tstring &banner)
 
void NoticeCB (const tstring notice, const MessageType type)
 
void ExitNoticeCB (const tstring &notice, const int returnCode)
 
void ServiceReadyCB ()
 
void UserPromptCB (ConnectPromptInfo &ConnectPrompt)
 
void CertBlockedCB (const tstring &rtstrUntrustedServer)
 
void CertWarningCB (const tstring &rtstrUntrustedServer, const std::list< tstring > &rltstrCertErrors, bool bAllowImport)
 
- Protected Member Functions inherited from ClientIfc
virtual void WMHintCB (const WMHint hint, const WMHintReason reason)
 
virtual void deliverWebLaunchHostCB (const tstring &activeHost)
 
virtual void EventAvailable ()
 
- Protected Member Functions inherited from ClientIfcBase
AgentIfc & getAgentIfc ()
 
virtual std::list< HostEntry > getHostEntries ()
 
bool connect (tstring host, unsigned int origin)
 
VPNState getCurrentState ()
 
VPNSubState getCurrentSubState ()
 
VPNSubState getPreviousSubState ()
 
tstring getStateText ()
 
void setNetworkStates (NETENV_STATE netEnvState, NETCTRL_STATE netCtrlState, NETWORK_TYPE netType, bool bACBrowserForCPRemediation, bool bUpdateUI)
 
void refreshOperatingModeForCurrentNetStates ()
 
NETENV_STATE getCurrentNetEnvState ()
 
NETENV_STATE getPreviousNetEnvState ()
 
NETCTRL_STATE getCurrentNetCtrlState ()
 
NETWORK_TYPE getCurrentNetType ()
 
bool isACBrowserForCPRemediation ()
 
tstring getNetworkStatusText (const VPNState state, const VPNSubState subState, const NETENV_STATE netEnvState, const NETCTRL_STATE netCtrlState)
 
PreferenceInfogetPreferences ()
 
bool savePreferences ()
 
void setBanner (const tstring &banner)
 
void setBannerResponse (bool bResponse)
 
bool getUserResponse ()
 
bool isUserResponseSet ()
 
void setCertBlocked (const tstring &tstrUntrustedServer)
 
void setCertWarning (const tstring &rtstrUntrustedServer, const std::list< tstring > &rltstrCertErrors, bool bAllowImport)
 
bool getCertImportResponse ()
 
void setUserPrompt (ConnectPromptInfo &ConnectPrompt)
 
void setCertBlockedResponse (bool bUnlock)
 
void setCertWarningResponse (bool bConnect, bool bImportCert)
 
void insertStateToConnectPrompt (ConnectPromptInfo &ConnectPrompt)
 
void ExitNotice (const tstring &tstrNotice, const int code=0)
 
void notice (const tstring tstrNotice, const MessageType type=MsgType_Info, bool bClearLastMsg=false, bool bForce=false, bool bStateMsg=false)
 
void notice (MsgWithArg &notice, const MessageType type=MsgType_Info, bool bClearLastMsg=false, bool bForce=false, bool bStateMsg=false)
 
void getStats (void)
 
void setStats (VPNStats &stats)
 
void exportStats (const tstring &tstrFilePath)
 
void setState (VPNState state, VPNState previousState, VPNSubState subState=VPNSS_NORMAL, bool bUpdateStateMsg=true, bool bOnlyUpdateUI=false)
 
void setWMHint (WMHint hint, WMHintReason reason)
 
bool isLastConnectType (const ConnectPromptType connPromptType)
 
bool isOperatingMode (OperatingMode opMode)
 
void setOperatingMode (OperatingMode opMode)
 
void unsetOperatingMode (OperatingMode opMode)
 
bool CanRemediateCaptivePortal ()
 
bool policyAllowsCaptivePortalRemediation ()
 
bool isEventShutdown ()
 
bool isUsingEventModel ()
 
time_t getLastDisconnectTime ()
 
ConnectPromptInfo getConnectPromptInfo ()
 
void resetConnectPromptPasswordData ()
 
void setStandaloneConnection (bool isStandalone)
 
void deliverActiveHost (const tstring &activeHost, ConnectProtocolType vpnProtocol=PROTOCOL_TYPE_UNKNOWN)
 
bool isVPNServiceReady ()
 
void resetLastDisconnectTime (time_t time=1)
 
void processMinimize ()
 
void setEnrollClientCert (CertObj *pCert)
 
void linuxCertImportWarnUser ()
 
void linuxCertImportWarnUserResponse (bool bAccept)
 
void setDefaultHost (tstring &host)
 
void setLastVpnError (VPNError vpnError)
 
VPNError getLastVpnError ()
 
bool requestImportLocalization (const tstring tstrLocale, const std::vector< unsigned char > &MoFileData)
 
void startAHS (const unsigned int uiReason, const ProxyIfc &proxy)
 
void AHSSelectedHost (const unsigned int uiReason, const std::vector< tstring > &headendList, const long statusReturnCode, const tstring &extraInfo)
 
std::vector< tstringgetAHSHostList ()
 
unsigned int getAHSState ()
 
bool isAHSHasRun ()
 
bool suppressConnectionErrorPopups ()
 
tstring getCaptivePortalDetectedMsg ()
 
void setProxyAuthPrompts (ProxyIfc *pProxy, const tstring &promptMsg)
 
bool handleIpcMessage (CIpcMessage *pIpcMessage)
 
bool IsCsdTokenVerified () const
 
void activateConnectMgrTunnelInitiationCompletionEvent ()
 
bool isConnectRequestActive ()
 
bool syncProfileChange (const tstring &profileName)
 
tstring getConnectHost ()
 
tstring getMgmtTunnelHostname ()
 
VPN_TUNNEL_SCOPE getVpnTunnelScope ()
 
bool isStandaloneConnection ()
 
void sendSSoLogoutPrompt (ConnectPromptInfo &cpi)
 

Additional Inherited Members

- Static Protected Member Functions inherited from ClientIfcBase
static tstring getNoticeTypeText (MessageType msgType)
 
static tstring getStateText (VPNState state, VPNSubState subState=VPNSS_NORMAL, NETENV_STATE netEnvState=NES_NETWORK_ACCESSIBLE, const tstring &tstrConnectedHost=tstring())
 
static tstring getNetCtrlText (NETCTRL_STATE netCtrlState)
 
static tstring getNetEnvText (NETENV_STATE netEnvState, bool bSimple=false)
 
static tstring getNetTypeText (NETWORK_TYPE netType)
 
static tstring getQuarantinedStatusText ()
 
static tstring getNetworkStatusSimpleText (const NETENV_STATE netEnvState, const NETCTRL_STATE netCtrlState)
 

Detailed Description

This is an example application demonstrating the implementation of the AnyConnect API

Member Function Documentation

◆ BannerCB()

void CLIClientImpl::BannerCB ( const tstring banner)
protectedvirtual

If a banner needs to be acknowledged, this CB delivers the banner to the client.

NOTE: Connection establishment will block until the method setBannerResponse() is called.

In a GUI, a banner would typically be displayed in a modal dialog with an accept or decline button selection.

See also
setBannerResponse() to set the user response to the banner.

Implements ClientIfc.

48 {
49  bool bBannerAccepted = true;
50  setBannerResponse(bBannerAccepted);
51 }

◆ CertBlockedCB()

void CLIClientImpl::CertBlockedCB ( const tstring rtstrUntrustedServer)
protectedvirtual

This method is called when the preference to block untrusted servers is enabled and the current VPN server being connected to is untrusted. Clients should present an error to the user notifying them that the current connection to rtstrUntrustedServer is being blocked. The client should also provide a way for the user to change the preference to block untrusted servers.

The user response must be indicated using setCertBlockedResponse

Implements ClientIfc.

386 {
387  setCertBlockedResponse(false);
388 }

◆ CertWarningCB()

void CLIClientImpl::CertWarningCB ( const tstring rtstrUntrustedServer,
const std::list< tstring > &  rltstrCertErrors,
bool  bAllowImport 
)
protectedvirtual

This method is called when connections to untrusted VPN servers is allowed by policies and the current VPN server being connected to is untrusted. Clients should present a warning to the user notifying them that the current connection to rtstrUntrustedServer is unsafe. The reason the VPN server is untrusted is provided in rltstrCertErrors. The client should provide a way for the user to connect once, connect and always trust or cancel the connection. If bAllowImport is set to false then the always trust option should not be presented to users.

The user response must be indicated using setCertWarningResponse

Implements ClientIfc.

394 {
395  setCertWarningResponse(false, false);
396 }

◆ disconnect()

void CLIClientImpl::disconnect ( )
virtual

Use this method to initiate a disconnect of the active VPN connection.

An indication of VPN disconnect is received via the StateCB method.

Reimplemented from ClientIfc.

133 {
135  // To ensure VPN service receive the disconnect message,
136  // do a short sleep before CLI terminates.
137  //
138  // NOTE: This is done only for demonstration purposes and would not be
139  // needed in a GUI or other program that runs continuously. A more elegant way
140  // to handle this case is to terminate the CLI after checking the disconnect callback message
141  // from API.
142  //
143 #ifdef _WIN32
144  Sleep(1500);
145 #else
146  sleep(1);
147 #endif
148 }

◆ ExitNoticeCB()

void CLIClientImpl::ExitNoticeCB ( const tstring tstrNotice,
const int  returnCode 
)
protectedvirtual

This CB would likely occur only during a connection when it was detected that the software needed to be upgraded, or when Start Before Logon (SBL) is being used.

Unlike the other callback methods, this method provides a default implementation (calling the system's exit() function). If clients of the API wish to override this behavior, they are responsible for ensuring that the current running process exits with the return code specified by returnCode.

Caution: IF YOU OVERRIDE THIS METHOD AND DO NOT EXIT WITH THE PROPER CODE SOFTWARE UPDATE FUNCTIONALITY IN YOUR CLIENT WILL BREAK

Reimplemented from ClientIfc.

83 {
84 #ifdef UNICODE
85  printf("ExitNoticeCB (%d): %S\n", returnCode, notice.c_str());
86 #else
87  printf("ExitNoticeCB (%d): %s\n", returnCode, notice.c_str());
88 #endif
89 }

◆ getStats()

void CLIClientImpl::getStats ( void  )

This method demonstrates accessing the statistics data delivered via the ClientIfc::StatsCB method.

152 {
153  if (isConnected())
154  {
155  // To ensure we receive the first set of stats before we try to print,
156  // do a short sleep.
157  //
158  // NOTE: This is done only for demonstration purposes and would not be
159  // needed in a GUI or other program that runs continuously.
160  //
161 #ifdef _WIN32
162  Sleep(1500);
163 #else
164  sleep(1);
165 #endif
166 
168  + mo_VPNStats.getStatValue(VPNStats::State);
170  + mo_VPNStats.getStatValue(VPNStats::TunnelingMode);
172  + mo_VPNStats.getStatValue(VPNStats::TimeConnected);
174  + mo_VPNStats.getStatValue(VPNStats::BytesSent);
176  + mo_VPNStats.getStatValue(VPNStats::BytesReceived);
177 
178  // Now get the data for the active protocol.
179  //
180  // NOTE: There is also Secure and non-secure route information. This
181  // data can be retrieved in a manner similar to protocolInfo
182  // using the methods getSecureRoutes() and getNonsecureRoutes()
183  //
184  std::list<ProtocolInfo *> protInfo = mo_VPNStats.getProtocolInfo();
185  for (std::list<ProtocolInfo *>::iterator iter = protInfo.begin();
186  iter != protInfo.end();
187  iter++)
188  {
189  if ((*iter)->isActive())
190  {
192  +(*iter)->getProtocolValue(ProtocolInfo::Cipher);
194  +(*iter)->getProtocolValue(ProtocolInfo::Protocol);
196  +(*iter)->getProtocolValue(ProtocolInfo::Compression);
197  }
198  }
199 
200 #ifdef UNICODE
201  printf("VPN Stats:%S\n",stats.c_str());
202 #else
203  printf("VPN Stats:%s\n",stats.c_str());
204 #endif
205  }
206  else
207  {
208  printf("Tunnel not up, no stats to print.\n");
209  }
210 }

◆ NoticeCB()

void CLIClientImpl::NoticeCB ( const tstring  notice,
const MessageType  type 
)
protectedvirtual

Messages are delivered via the NoticeCB and can come from multiple sources. There are four message types (error, warning, info and status). See the MessageType enum in api.h for the list.

Clients using the API as an embedded application (not user visible) might want to further characterize messages. One option here is to use the AnyConnect message catalog and assign message codes as the translations for various messages. An application could then track messages based on its own error code scheme.

Implements ClientIfc.

55 {
56  std::string msgType;
57  switch(type)
58  {
59  case MsgType_Error:
60  msgType = "Error";
61  break;
62  case MsgType_Warn:
63  msgType = "Warn";
64  break;
65  case MsgType_Info:
66  msgType = "Info";
67  break;
68  default:
69  msgType = "Unknown";
70  break;
71  }
72 
73 #ifdef UNICODE
74  printf("Notice (%s): %S\n", msgType.c_str(), notice.c_str());
75 #else
76  printf("Notice (%s): %s\n", msgType.c_str(), notice.c_str());
77 #endif
78 }

◆ ServiceReadyCB()

void CLIClientImpl::ServiceReadyCB ( )
protectedvirtual

Under normal operating conditions, this CB is called as soon as the attach method completes. In case the service (vpn agent) is not ready, this CB is not called until it is.

Any API calls made prior to this CB being called will result in a NoticeCB error message.

Implements ClientIfc.

221 { }

◆ setUserData()

void CLIClientImpl::setUserData ( ConnectPromptInfo ConnectPrompt)

Method with example of parsing ConnectPromptInfo.

This method is triggered by an API call on the method UserPromptCB(ConnectPromptInfo &).

252 {
253 #ifdef UNICODE
254  printf("User Message: %S\n", ConnectPrompt.getMessage().c_str());
255 #else
256  printf("User Message: %s\n", ConnectPrompt.getMessage().c_str());
257 #endif
258 
259  // Create a list to hold the names of the individual PromptEntry objects.
260  //
261  std::list<tstring> promptNames;
262  // Get the list of names associated with the PromptEntry objects.
263  //
264  ConnectPrompt.getListPromptNames(promptNames);
265  // This set of code cycles through the list of names that reference the
266  // individual PromptEntry objects. As each name is accessed it can be used
267  // to retrieve a specific instance of a PromptEntry object. There is also a
268  // method (ConnectPromptInfo::getListPromptEntry()) to retrieve the list of
269  // PromptEntry objects directly, allowing the individual PromtpEntry object
270  // to be accessed in a different manner if desired.
271  //
272  std::list<tstring> :: iterator name_iter;
273  for (name_iter = promptNames.begin();
274  name_iter != promptNames.end(); ++name_iter)
275  {
276  // name_iter represents a single name from the promptNames list.
277  //
278  tstring promptName = *name_iter;
279  PromptEntry *entry = ConnectPrompt.getPromptEntry(promptName);
280 
281  // For this demo program, we'll assume any combo box is for
282  // group selection.
283  //
284  if (entry->getPromptType() == Prompt_Combo)
285  {
286  entry->setValue(ms_group);
287  }
288  tstring entryName = entry->getPromptName();
289 
290  // PromptEntry::Username and PromptEntry::Password are string currently
291  // resolving to the wide char values "username" and "password".
292  //
293  if (entryName == PromptEntry::Username)
294  {
295  entry->setValue(ms_user);
296  }
297  else if (entryName == PromptEntry::Password)
298  {
299  entry->setValue(ms_pswd);
300  }
301  }
302 }

◆ StateCB()

void CLIClientImpl::StateCB ( const VPNState  state,
const VPNSubState  subState,
const tstring  stateString 
)
protectedvirtual

Callback used to deliver VPN state and state change string. The stateString delivered by this method is localized.

See the VPNState enum found in api.h for set of valid states.

Implements ClientIfc.

37 {
38 #ifdef UNICODE
39  printf("Current State (%d): %S\n", state, stateString.c_str());
40 #else
41  printf("Current State (%d): %s\n", state, stateString.c_str());
42 #endif
43 }

◆ StatsCB()

void CLIClientImpl::StatsCB ( VPNStats stats)
protectedvirtual

Callback used to deliver new statistics related to the VPN connection.

When a connection is active, a new set of statistics is delivered each second.

See also
resetStats(), stopStats() and startStats()

Implements ClientIfc.

380 {
381  mo_VPNStats = stats;
382 }

◆ UserPromptCB()

void CLIClientImpl::UserPromptCB ( ConnectPromptInfo ConnectPrompt)
protectedvirtual

This method supports prompting for single or multiple values. All prompts are considered mandatory.

The ConnectPromptInfo object contains a list of PromptEntry instances. The labels and their default values (if any) can be found in these instances. After the data has been collected from the user it can be set into these same instances. When ready, the client application should call the method UserSubmit() to have the responses read by the API.

Implements ClientIfc.

225 {
226  if (me_RequestType == REQ_CONNECT)
227  {
228  // For example purposes, only allow one try at setting user data.
229  //
230  me_RequestType = REQ_END;
231  // Look for requested user input fields and fill in previously
232  // stored values.
233  //
234  setUserData(ConnectPrompt);
235  // Now that the user data has been entered, submit the response.
236  //
237  UserSubmit();
238  }
239  else if (me_RequestType == REQ_GROUPLIST)
240  {
241  printGroupList(ConnectPrompt);
242  }
243 
244 }
VPNStats::getStatValue
const tstring & getStatValue(tstring &label)
ClientIfc::UserSubmit
void UserSubmit()
MsgType_Warn
Definition: api.h:97
ClientIfc::disconnect
void disconnect()
VPNStats::BytesSent
static tstring BytesSent
Definition: VPNStats.h:107
VPNStats::getTranslatedLabel
static tstring getTranslatedLabel(tstring &label)
ProtocolInfo::Protocol
static tstring Protocol
Definition: ProtocolInfo.h:41
PromptEntry::setValue
bool setValue(const tstring &value)
ClientIfc::setBannerResponse
void setBannerResponse(bool bAccepted)
ConnectPromptInfo::getMessage
const tstring & getMessage() const
VPNStats::TimeConnected
static tstring TimeConnected
Definition: VPNStats.h:99
VPNStats::getProtocolInfo
const std::list< ProtocolInfo * > & getProtocolInfo()
MsgType_Info
Definition: api.h:98
VPNStats::TunnelingMode
static tstring TunnelingMode
Definition: VPNStats.h:168
ConnectPromptInfo::getPromptEntry
PromptEntry * getPromptEntry(const tstring &promptName) const
PromptEntry::Password
static tstring Password
Definition: PromptEntry.h:127
PromptEntry::getPromptName
const tstring & getPromptName() const
tstring
#define tstring
Definition: api.h:24
CLIClientImpl::setUserData
void setUserData(ConnectPromptInfo &ConnectPrompt)
Definition: CLIClientImpl.cpp:251
Prompt_Combo
Definition: api.h:240
MsgType_Error
Definition: api.h:95
PromptEntry
Definition: PromptEntry.h:39
VPNStats::State
static tstring State
Definition: VPNStats.h:95
ClientIfc::isConnected
bool isConnected()
ProtocolInfo::Cipher
static tstring Cipher
Definition: ProtocolInfo.h:44
ConnectPromptInfo::getListPromptNames
const std::list< tstring > & getListPromptNames(std::list< tstring > &listPromptNames) const
PromptEntry::getPromptType
PromptType getPromptType() const
ProtocolInfo::Compression
static tstring Compression
Definition: ProtocolInfo.h:47
PromptEntry::Username
static tstring Username
Definition: PromptEntry.h:123
VPNStats::BytesReceived
static tstring BytesReceived
Definition: VPNStats.h:108