AnyConnect Secure Mobility Client 5.1.10.233
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)
 
void EventAvailable ()
 
void ProcessEvents ()
 
void SetRequestType (RequestType e_RequestType)
 
- Public Member Functions inherited from ClientIfc
bool attach (ClientType clientType=ClientType_GUI, bool requestFullCapabilities=true, bool suppressAutoConnect=true)
 
void detach ()
 
void ProcessEvents ()
 
bool hasFullCapabilities ()
 
bool isConnected (bool bSilent=false)
 
bool isAvailable ()
 
bool isVPNServiceAvailable ()
 
bool isOperatingMode (OperatingMode opMode)
 
std::list< tstringgetHostNames ()
 
tstring getDefaultHostName ()
 
bool connect (tstring host)
 
bool connect (tstring host, unsigned int origin)
 
bool setNewTunnelGroup (const tstring &group)
 
void disconnect ()
 
void cancel ()
 
void getState ()
 
void getStats ()
 
void resetStats ()
 
void startStats ()
 
void stopStats ()
 
void exportStats (const tstring &tstrFilePath)
 
void setBannerResponse (bool bAccepted)
 
void setPreConnectReminderResponse ()
 
void setCertBlockedResponse (bool bUnblock)
 
void setCertWarningResponse (bool bConnect, bool bImportCert)
 
void UserSubmit ()
 
std::shared_ptr< PreferenceInfogetPreferences ()
 
unsigned int getPreferencesCount ()
 
bool savePreferences (const std::shared_ptr< PreferenceInfo > &spPreferenceInfo)
 
tstring getConnectHost ()
 
void setLastVpnError (VPNError vpnError)
 
VPNError getLastVpnError ()
 
bool isConnectRequestActive ()
 

Protected Member Functions

void StatsCB (VPNStats &stats)
 
void StateCB (const VPNState state, const VPNSubState subState, const tstring stateString)
 
void BannerCB (const tstring &banner)
 
void PreConnectReminderCB (const tstring &rtstrPreConnectReminder)
 
void NoticeCB (const tstring &notice, const MessageType type, const bool bSensitive=false)
 
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 ClientIfcBase
virtual void WMHintCB (const WMHint hint, const WMHintReason reason)
 
virtual void deliverWebLaunchHostCB (const tstring &activeHost)
 
void ResetQuarantinedReconnect ()
 
void ClientIfcTransmigration ()
 
bool attach (const ClientType clientType=ClientType_GUI, const bool requestFullCapabilities=true, const bool suppressAutoConnect=true, const bool bSuppressEventAvailableCB=false)
 
void detach ()
 
void ProcessEvents ()
 
bool hasFullCapabilities ()
 
bool isConnected (bool bSilent=false)
 
bool isAvailable ()
 
std::list< tstringgetHostNames ()
 
std::list< HostEntry > getHostEntries ()
 
tstring getDefaultHostName ()
 
bool connect (tstring host)
 
bool connect (tstring host, unsigned int origin)
 
bool setNewTunnelGroup (const tstring &group)
 
void disconnect ()
 
void cancel ()
 
void resetStats ()
 
void getState ()
 
VPNState getCurrentVPNState ()
 
VPNSubState getCurrentVPNSubState ()
 
VPNSubState getPreviousVPNSubState ()
 
STATE getCurrentState ()
 
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 startStats ()
 
void stopStats ()
 
void UserSubmit ()
 
void setBanner (const tstring &banner)
 
void setBannerResponse (bool bResponse)
 
void setPreConnectReminder (const tstring &tstrPreConnectReminder)
 
void setPreConnectReminderResponse ()
 
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, bool bSensitiveMsg=false)
 
void notice (MsgWithArg &notice, const MessageType type=MsgType_Info, bool bClearLastMsg=false, bool bForce=false, bool bStateMsg=false, bool bSensitiveMsg=false)
 
void getStats (void)
 
void setStats (VPNStats &stats)
 
void exportStats (const tstring &tstrFilePath)
 
void initState (VPNState state, VPNState previousState, VPNSubState subState)
 
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 bActiveHostFriendlyName=false)
 
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 IsAHSCachingRestricted ()
 
bool suppressConnectionErrorPopups ()
 
tstring getCaptivePortalDetectedMsg ()
 
void setProxyAuthPrompts (ProxyIfc *pProxy, const tstring &promptMsg)
 
bool handleIpcMessage (CIpcMessage *pIpcMessage)
 
void signalDisconnectedToEventNtfctnThread ()
 
bool IsCsdTokenVerified () const
 
void activateConnectMgrTunnelInitiationCompletionEvent ()
 
bool isConnectRequestActive ()
 
bool isConnectRequestCleanup ()
 
bool syncProfileChange (const tstring &profileName)
 
tstring getConnectHost ()
 
tstring getMgmtTunnelHostname ()
 
VPN_TUNNEL_SCOPE getVpnTunnelScope ()
 
bool isStandaloneConnection ()
 
void sendSSoLogoutPrompt (ConnectPromptInfo &cpi)
 
void setExternalSSOLogoutUrlFromAgent (const tstring &logoutUrl)
 

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

Constructor & Destructor Documentation

◆ CLIClientImpl()

CLIClientImpl::CLIClientImpl ( )
25 : me_RequestType(REQ_END),
26 ms_user(),
27 ms_pswd(),
28 ms_group(),
29 mb_exit(false),
30 mb_eventAvailable(false),
31 mb_ConnectingStateReceived(false) { }

◆ ~CLIClientImpl()

CLIClientImpl::~CLIClientImpl ( )
virtual
33{ }

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 ClientIfcBase.

88{
89 bool bBannerAccepted = true;
90 setBannerResponse(bBannerAccepted);
91}
void setBannerResponse(bool bAccepted)

◆ 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 ClientIfcBase.

442{
443 setCertBlockedResponse(false);
444}

◆ 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 ClientIfcBase.

450{
451 setCertWarningResponse(false, false);
452}

◆ connect()

void CLIClientImpl::connect ( std::string host,
std::string user,
std::string password,
std::string group )
162{
163 me_RequestType = REQ_CONNECT;
164 // save these user input values until requested by the API.
165 //
166#ifdef UNICODE
167 ms_user = convertMultiByteToWide(user);
168 ms_pswd = convertMultiByteToWide(pswd);
169 ms_group = convertMultiByteToWide(group);
170#else
171 ms_user = user;
172 ms_pswd = pswd;
173 ms_group = group;
174#endif
175
176 // This is the main method for initiating a VPN connection.
177 // The method can be found in ClientIfc.
178 //
179#ifdef UNICODE
180 ClientIfc::connect(convertMultiByteToWide(host));
181#else
182 ClientIfc::connect(host);
183#endif
184}
bool connect(tstring host)

◆ convertMultiByteToWide()

std::wstring CLIClientImpl::convertMultiByteToWide ( const std::string & sInputData)
460{
461 std::wstring wsDataBuffer;
462
463 // determine number of bytes that will be written
464 //
465#ifdef _WIN32
466 int bufSize = MultiByteToWideChar(CP_UTF8, 0, sInputData.c_str(),
467 -1, NULL, 0);
468#else
469 int bufSize = mbstowcs(NULL, sInputData.c_str(), 0);
470#endif
471
472 if (bufSize > 0)
473 {
474 wchar_t *wzTmpBuf = new wchar_t[bufSize];
475#ifdef _WIN32
476 int converted = MultiByteToWideChar(CP_UTF8, 0, sInputData.c_str(),
477 -1, wzTmpBuf, bufSize);
478 converted--; // drop the terminating NULL.
479#else
480 int converted = mbstowcs(wzTmpBuf, sInputData.c_str(), bufSize);
481#endif
482 wsDataBuffer.assign(wzTmpBuf, converted);
483 delete[] wzTmpBuf;
484 }
485 else
486 {
487 printf("convertMultiByteToWide : Conversion failed\n");
488 }
489
490 return wsDataBuffer;
491}

◆ disconnect()

void CLIClientImpl::disconnect ( )
189{
190 me_RequestType = REQ_DISCONNECT;
192 // To ensure VPN service receive the disconnect message,
193 // do a short sleep before CLI terminates.
194 //
195 // NOTE: This is done only for demonstration purposes and would not be
196 // needed in a GUI or other program that runs continuously. A more elegant way
197 // to handle this case is to terminate the CLI after checking the disconnect callback message
198 // from API.
199 //
200#ifdef _WIN32
201 Sleep(1500);
202#else
203 sleep(1);
204#endif
205}
void disconnect()

◆ EventAvailable()

void CLIClientImpl::EventAvailable ( )
virtual

This method should be overridden by the client application to exercise some control over the delivery of events from the other protected methods in this class.

This might be necessary in cases where a GUI/CLI is being written and the data from this API needs to be delivered in the GUI/CLI or main thread. In this case, you should override this method and when it is called by the API post an event to your event queue (message pump, etc.). After this event executes in your GUI/CLI or main thread, call the method ClientIfc::ProcessEvents to have events delivered to your client application.

Reimplemented from ClientIfcBase.

500{
501 mtx.lock();
502 mb_eventAvailable = true;
503 mtx.unlock();
504}

◆ 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 ClientIfcBase.

139{
140#ifdef UNICODE
141 printf("ExitNoticeCB (%d): %S\n", returnCode, notice.c_str());
142#else
143 printf("ExitNoticeCB (%d): %s\n", returnCode, notice.c_str());
144#endif
145}

◆ getStats()

void CLIClientImpl::getStats ( void )

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

209{
210 me_RequestType = REQ_STATISTICS;
211 if (isConnected())
212 {
213 // To ensure we receive the first set of stats before we try to print,
214 // do a short sleep.
215 //
216 // NOTE: This is done only for demonstration purposes and would not be
217 // needed in a GUI or other program that runs continuously.
218 //
220 }
221 else
222 {
223 printf("Tunnel not up, no stats to print.\n");
224 mb_exit = true;
225 }
226}
void getStats()
bool isConnected(bool bSilent=false)

◆ NoticeCB()

void CLIClientImpl::NoticeCB ( const tstring & notice,
const MessageType type,
const bool bSensitive = false )
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 ClientIfcBase.

111{
112 std::string msgType;
113 switch(type)
114 {
115 case MsgType_Error:
116 msgType = "Error";
117 break;
118 case MsgType_Warn:
119 msgType = "Warn";
120 break;
121 case MsgType_Info:
122 msgType = "Info";
123 break;
124 default:
125 msgType = "Unknown";
126 break;
127 }
128
129#ifdef UNICODE
130 printf("Notice (%s): %S\n", msgType.c_str(), notice.c_str());
131#else
132 printf("Notice (%s): %s\n", msgType.c_str(), notice.c_str());
133#endif
134}
@ MsgType_Error
Definition api.h:110
@ MsgType_Info
Definition api.h:113
@ MsgType_Warn
Definition api.h:112

◆ PreConnectReminderCB()

void CLIClientImpl::PreConnectReminderCB ( const tstring & rtstrPreConnectReminder)
protectedvirtual

If a pre-connect reminder needs to be acknowledged, this CB delivers the pre-connect reminder to the client.

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

In a GUI, a pre-connect reminder would typically be displayed in a modal dialog with an OK button selection.

See also
setPreConnectReminderResponse() to set the user acknowledgement to the pre-connect reminder message.

Reimplemented from ClientIfcBase.

95{
96#ifdef UNICODE
97 printf("\n%S", rtstrPreConnectReminder.c_str());
98#else
99 printf("\n%s", rtstrPreConnectReminder.c_str());
100#endif
101
102 printf( "Press enter key to continue... " );
103 std::cin.get();
105}
void setPreConnectReminderResponse()

◆ printDefaultHost()

void CLIClientImpl::printDefaultHost ( )
344{
345#ifdef UNICODE
346 printf("Default host: %S\n", getDefaultHostName().c_str());
347#else
348 printf("Default host: %s\n", getDefaultHostName().c_str());
349#endif
350}
tstring getDefaultHostName()

◆ printGroupList()

void CLIClientImpl::printGroupList ( ConnectPromptInfo & ConnectPrompt)
355{
356 std::list<tstring> promptNames;
357 // get the list of PromptEntry received.
358 //
359 ConnectPrompt.getListPromptNames(promptNames);
360
361 std::list<tstring> :: iterator name_iter;
362 for (name_iter = promptNames.begin();
363 name_iter != promptNames.end(); ++name_iter)
364 {
365 PromptEntry *entry = ConnectPrompt.getPromptEntry(*name_iter);
366 // For this demo program, we'll assume any combo box is for
367 // group selection.
368 //
369 if (entry->getPromptType() == Prompt_Combo)
370 {
371 tstring groupList;
372 std::list<tstring>::const_iterator lo_Citer;
373
374 for (lo_Citer = entry->getValueOptions().begin();
375 lo_Citer != entry->getValueOptions().end(); ++lo_Citer)
376 {
377 tstring value = *lo_Citer;
378 groupList += SEP + (*lo_Citer);
379 }
380
381
382#ifdef UNICODE
383 printf("Group List: %S\n", groupList.c_str());
384#else
385 printf("Group List: %s\n", groupList.c_str());
386#endif
387 }
388
389 }
390}
@ Prompt_Combo
Definition api.h:262
#define tstring
Definition api.h:35
PromptEntry * getPromptEntry(const tstring &promptName) const
const std::list< tstring > & getListPromptNames(std::list< tstring > &listPromptNames) const
const std::list< tstring > & getValueOptions() const
PromptType getPromptType() const

◆ printHostList()

void CLIClientImpl::printHostList ( )
322{
323 // getHostNames can be found in ClientIfc
324 //
325 std::list<tstring> hostList = getHostNames();
326 std::list<tstring> :: iterator host_iter;
327 tstring hosts;
328 for (host_iter = hostList.begin();
329 host_iter != hostList.end(); ++host_iter)
330 {
331 hosts += *host_iter + SEP;
332 }
333
334#ifdef UNICODE
335 printf("Host List:\n\t%S\n", hosts.c_str());
336#else
337 printf("Host List:\n\t%s\n", hosts.c_str());
338#endif
339}
std::list< tstring > getHostNames()

◆ ProcessEvents()

void CLIClientImpl::ProcessEvents ( )
509{
510 while (!mb_exit)
511 {
512 mtx.lock();
513 if (mb_eventAvailable)
514 {
515 mb_eventAvailable = false;
517 }
518 mtx.unlock();
519 std::this_thread::sleep_for(std::chrono::milliseconds(20));
520 }
521}
void ProcessEvents()

◆ 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 ClientIfcBase.

237{ }

◆ SetRequestType()

void CLIClientImpl::SetRequestType ( RequestType e_RequestType)
525{
526 me_RequestType = e_RequestType;
527}

◆ 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 &).

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

◆ showGroups()

void CLIClientImpl::showGroups ( std::string host)
149{
150 me_RequestType = REQ_GROUPLIST;
151#ifdef UNICODE
152 ClientIfc::connect(convertMultiByteToWide(host));
153#else
154 ClientIfc::connect(host);
155#endif
156}

◆ 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 ClientIfcBase.

40{
41#ifdef UNICODE
42 printf("Current State (%d): %S\n", state, stateString.c_str());
43#else
44 printf("Current State (%d): %s\n", state, stateString.c_str());
45#endif
46
47 switch(me_RequestType)
48 {
49 case REQ_STATE:
50 mb_exit = true;
51 break;
52 case REQ_DISCONNECT:
53 if (VPNState::DISCONNECTED == state)
54 {
55 mb_exit = true;
56 }
57 break;
58 case REQ_CONNECT:
59 if (VPNState::CONNECTED == state)
60 {
61 mb_exit = true;
62 }
63
64 // API may report the current state of VPN (ie., DISCONNECTED) when a connect request is received.
65 // States reported after receiving CONNECTING state should be considered for the current connection
66 // attempt. Exit the main processing loop for DISCONNECTED or CONNECTED states only after CONNECTING
67 // state is received.
68 //
69 if (VPNState::CONNECTING == state)
70 {
71 mb_ConnectingStateReceived = true;
72 }
73
74 if (mb_ConnectingStateReceived &&
75 ((VPNState::DISCONNECTED == state) || (VPNState::CONNECTED == state)))
76 {
77 mb_exit = true;
78 }
79 break;
80 default:
81 break;
82 }
83}
@ CONNECTING
Definition api.h:148
@ CONNECTED
Definition api.h:146
@ DISCONNECTED
Definition api.h:147

◆ 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 ClientIfcBase.

395{
396 if (REQ_STATISTICS == me_RequestType)
397 {
399 + rStats.getStatValue(VPNStats::State);
401 + rStats.getStatValue(VPNStats::TunnelingMode);
403 + rStats.getStatValue(VPNStats::TimeConnected);
405 + rStats.getStatValue(VPNStats::BytesSent);
407 + rStats.getStatValue(VPNStats::BytesReceived);
408
409 // Now get the data for the active protocol.
410 //
411 // NOTE: There is also Secure and non-secure route information. This
412 // data can be retrieved in a manner similar to protocolInfo
413 // using the methods getSecureRoutes() and getNonsecureRoutes()
414 //
415 std::list<ProtocolInfo *> protInfo = rStats.getProtocolInfo();
416 for (std::list<ProtocolInfo *>::iterator iter = protInfo.begin();
417 iter != protInfo.end();
418 iter++)
419 {
420 if ((*iter)->isActive())
421 {
423 +(*iter)->getProtocolValue(ProtocolInfo::Cipher);
425 +(*iter)->getProtocolValue(ProtocolInfo::Protocol);
427 +(*iter)->getProtocolValue(ProtocolInfo::Compression);
428 }
429 }
430
431#ifdef UNICODE
432 printf("VPN Stats:%S\n",stats.c_str());
433#else
434 printf("VPN Stats:%s\n",stats.c_str());
435#endif
436 mb_exit = true;
437 }
438}
static tstring Protocol
Definition ProtocolInfo.h:42
static tstring Compression
Definition ProtocolInfo.h:48
static tstring Cipher
Definition ProtocolInfo.h:45
static tstring BytesReceived
Definition VPNStats.h:99
static tstring BytesSent
Definition VPNStats.h:98
static tstring TunnelingMode
Definition VPNStats.h:159
static tstring getTranslatedLabel(tstring &label)
static tstring State
Definition VPNStats.h:86
static tstring TimeConnected
Definition VPNStats.h:90

◆ 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 ClientIfcBase.

241{
242 if (me_RequestType == REQ_CONNECT)
243 {
244 // For example purposes, only allow one try at setting user data.
245 //
246 // Look for requested user input fields and fill in previously
247 // stored values.
248 //
249 setUserData(ConnectPrompt);
250 // Now that the user data has been entered, submit the response.
251 //
252 UserSubmit();
253 }
254 else if (me_RequestType == REQ_GROUPLIST)
255 {
256 printGroupList(ConnectPrompt);
257 mb_exit = true;
258 }
259}
void setUserData(ConnectPromptInfo &ConnectPrompt)
Definition CLIClientImpl.cpp:266
void UserSubmit()