1 //----------------------------------------------------------------------------
3 // Copyright (C) Intel Corporation, 2004 - 2006.
5 // File: CommonDefinitions.h
7 // Contents: Sample code for an IntelĀ® AMT Network client.
9 // Notes: This file contains type, function and constant definitions
10 // used throughout the code of the all sample applications.
12 //----------------------------------------------------------------------------
14 #ifndef COMMON_DEFINITIONS_H
15 #define COMMON_DEFINITIONS_H
18 #include "StatusCodeDefinitions.h"
21 * gsoapWinHTTP.h for gSoap WinHTTP extension - needed for TLS support
23 #include "gsoapWinHttp.h"
24 #include "StatusStrings.h"
28 * httpDigest.h for gSoap HTTP Digest support
30 #include "httpDigest.h"
36 void PrintAuthenticationNote();
37 bool CheckReturnStatus(unsigned int res, unsigned long status,const char *message);
38 bool ValidateIP(const char *uri);
39 void GetString(char *msg, char *s, bool hidden);
40 bool ChangeService(const char *uri, const char *newService, char *newUri);
41 bool DisplayWarning(const char *msg);
42 bool GetNumber(int *number);
43 void ReplaceSubstring(const char *oldString,const char *oldSubstr,
44 const char *newSubstr, char *newString);
45 void SetIPAddress(unsigned long &address, unsigned long bytes[]);
46 void NumberToIP(unsigned long address, unsigned long bytes[]);
47 void NumberToString(unsigned long number, char *string);
48 void IpToString(unsigned long address, char *string);
49 void StringToIP(const char *string, unsigned long &address);
50 void GuidToString(const unsigned char* guid, char* string);
51 bool ExtractIPFromUri(const char *uri, char *baseUrl);
52 void IsEmulator(const char *targetUrl, int *isEmulator);
53 bool GetOption(int *commandLineLength, char *argv[], int numOfArgs,
54 char **option, char **commandLine[]);
55 void PrintSuccess(bool print = true);
56 void FunctionCall(const char *message);
58 bool ParseCommandLine(int commandLineLength,char* commandLine[],char **target,
59 char **certName, bool *local, bool *krb,bool *verbose = NULL,
60 char **username = NULL, char **password = NULL);
63 bool ParseCommandLine(int commandLineLength,char* commandLine[],char **target,
64 char **certName = NULL,char **certPass = NULL,
66 char **username = NULL, char **password = NULL);
71 * Constants for the common use
73 static const int MAX_LINE_LEN = 1024;
74 static const int TIMEOUT = 80;
75 static const char *DEFAULT_USERNAME = "admin";
76 static const char *DEFAULT_PASSWORD = "admin";
77 static const char *CERT_NAME = "-certName";
78 static const char *USER = "-user";
79 static const char *PASS = "-pass";
80 static const char *VERBOSE = "-verbose";
82 static const char *LOCAL = "-local";
83 static const char *KRB = "-krb";
85 static const char *CERT_PASS = "-certPass";
89 * The structure that represents
90 * the gSOAP rintime environment
103 Soap(const char *url, const char *certName,
104 const char *username, const char *password,
105 bool local, bool krb)
107 Soap(const char *url, const char *certName,
108 const char *certPass, const char *username,
109 const char *password)
112 m_username = new char[MAX_LINE_LEN];
113 m_password = new char[MAX_LINE_LEN];
114 m_ip = new char[MAX_LINE_LEN];
116 SetUsername(DEFAULT_USERNAME);
117 SetPassword(DEFAULT_PASSWORD);
125 // To use the default user name, comment the following line:
126 GetString("Username: ", m_username, false);
130 SetUsername(username);
139 // To use the default password, comment the following line:
140 GetString("Password: ", m_password, true);
144 SetPassword(password);
150 SetSoap(certName,local,krb);
152 SetSoap(certName,certPass);
158 void Init(SOAP_NMAC struct Namespace *name = NULL)
160 m_soap->userid = m_username;
161 m_soap->passwd = m_password;
165 // setting namespace for the runtime environment
166 soap_set_namespaces(m_soap, name);
185 struct soap *GetSoap()
190 void SetIp(const char *url)
192 memset(m_ip, 0, MAX_LINE_LEN);
195 strncpy(m_ip, url, MAX_LINE_LEN - 1);
199 void SetUsername(const char *username)
201 memset(m_username,0,MAX_LINE_LEN);
204 strncpy(m_username, username, MAX_LINE_LEN - 1);
208 void SetPassword(const char *password)
210 memset(m_password,0,MAX_LINE_LEN);
213 strncpy(m_password, password, MAX_LINE_LEN - 1);
218 void SetSoap(const CHAR *certName, bool local, bool krb)
220 void SetSoap(const CHAR *certName, const char *certPass)
223 m_soap->recv_timeout = TIMEOUT;
224 m_soap->send_timeout = TIMEOUT;
225 m_soap->connect_timeout = TIMEOUT;
226 m_soap->accept_timeout = TIMEOUT;
229 // gsoap winhttp extension
230 soap_register_plugin( m_soap, winhttp_plugin );
231 soap_omode(m_soap, SOAP_IO_KEEPALIVE);
234 winhttp_set_certificate_name(m_soap, certName);
237 winhttp_set_local(m_soap,local);
238 winhttp_set_auth_scheme(m_soap,krb);
240 // gsoap HTTP Digest plugin
241 if ( strncmp(m_ip+strlen(m_ip)-5, ".asmx", 5)) {
242 soap_register_plugin(m_soap, http_digest);
244 soap_omode(m_soap, SOAP_IO_KEEPALIVE);
245 soap_imode(m_soap, SOAP_IO_KEEPALIVE);
246 if ( !strncmp(m_ip, "https:", 6) )
249 soap_ssl_client_context(m_soap,
253 "/usr/share/ssl/cert.pem",
254 "/usr/share/ssl/certs/", NULL);
256 printf("WARNING, pcucontrol has no support for ssl starting with openssl-1.1\n");
267 delete [] m_username;
272 delete [] m_password;
281 soap_destroy(m_soap);