# Session Management APIs for C and C++

The Session Management APIs are used to open or close the server connection, and to set and retrieve the server session parameters, such as transport type, authentication style.

This page contains information about the Session Management APIs for C and C++, including the description and syntax, and the input, input types, input description, and input return values.

## na_server_open

### Prototype

na_server_t* na_server_open(const char* server, int major, int minor);

### Description

Sets the server context and assigns default values to the session parameters.

Following are the default values:

username= ""

password= ""

style= NA_STYLE_LOGIN_PASSWORD

port= 80

transport= NA_SERVER_TRANSPORT_HTTP

servertype= NA_SERVER_TYPE_FILER

You can overwrite the default values by using the na_server* Core APIs.

Input | Type | Description
server | const char* | The name or the IP address of the server in IPv4 or IPv6 format.
major | int | The major version of the Data ONTAP API.
| For DataFabric Manager APIs for the OnCommand Package, you must pass 1 as the major version.
minor | int | The minor version of the Data ONTAP API.
| For DataFabric Manager APIs for the OnCommand Package, you must pass 0 as the minor version.

### Return value

- The address of the server context

- NULL on failure

[top]

## na_server_style

### Prototype

void na_server_style(na_server_t* srv, na_style_t style);

### Description

Sets the authentication mechanism to be used for communicating with the given server.

Input | Type | Description
srv | na_server_t * | The pointer to the server context.
style | na_style_t | The communication or authentication style that is to be set.. Following are the supported values: NA_STYLE_LOGIN_PASSWORD NA_STYLE_RPC NA_STYLE_HOSTSEQUIV NA_STYLE_CERTIFICATE If style=NA_STYLE_LOGIN_PASSWORD, you must provide an administrator user name and password with na_server_adminuser(). If style=NA_STYLE_RPC, your code should run on the Windows system so that a native Windows authentication based on remote procedure call is used. This is applicable for Data ONTAP APIs only. If style=NA_STYLE_HOSTSEQUIV, the server context authenticates the against the /etc/hosts.equiv file on the NetApp storage system. In such a case, you do not have to set the administrator user name and password. This is applicable for Data ONTAP APIs. If style=NA_STYLE_CERTIFICATE, you can use certificates to authenticate clients who attempt to connect to a server, without using login credentials. This style automatically sets HTTPS as the transport mechanism. You can use this authentication mechanism for DataFabric Manager APIs for the OnCommand Package only. To authenticate the server, server certificate verification and hostname verification is required. For more information, see the APIs na_server_set_client_cert_and_key(), na_server_set_ca_certs(), na_server_set_server_cert_verification(), and na_server_set_hostname_verification().

### Return value

None

[top]

## na_server_adminuser

### Prototype

int na_server_adminuser(na_server_t* srv, const char* login, const char* pwd);

### Description

Sets the user name and password for a server context, where authentication style is NA_STYLE_LOGIN_PASSWORD.

Input | Type | Description
srv | na_server_t* | The pointer to the server context.
login | const char* | The login name.
pwd | const char* | The password.

### Return value

- 1 (TRUE) on success

- 0 (FALSE) on failure

[top]

## na_server_set_server_type

### Prototype

int na_server_set_server_type(na_server_t *srv, na_server_type_t type);

### Description

Sets the type of system you are connecting to.

Input | Type | Description
srv | na_server_t* | Pointer to the server context.
type | na_server_type_t | The server type to be set. Following are the supported values: NA_SERVER_TYPE_FILER—to connect to a NetApp storage system. NA_SERVER_TYPE_DFM—to connect to a DataFabric Manager server. The default server type is NA_SERVER_TYPE_FILER.

### Return value

- 1 (TRUE) on success

- 0 (FALSE) on failure

## na_server_set_transport_type

### Prototype

int na_server_set_transport_type(na_server_t* srv, na_server_transport_t transport, const union zfd_setopt* transportarg);

### Description

- Overrides the default transport type.

- After setting the transport type, invoke the na_set_port() to set the port number used for that transport type.

Input | Type | Description
srv | na_server_t* | The pointer to the server context.
transport | na_server_transport_t | The transport type. Following are the supported transport types: NA_SERVER_TRANSPORT_HTTP NA_SERVER_TRANSPORT_HTTPS The default transport type is NA_SERVER_TRANSPORT_HTTP. For secure transport, use NA_SERVER_TRANSPORT_HTTPS as the transport type.
transportarg | const union zfd_setopt* | The transport argument. You should set transportarg to zero for both the HTTP and HTTPS transport protocols.

### Return value

- 1 (TRUE) on success

- 0 (FALSE) on failure

[top]

## na_server_set_vfiler

### Prototype

int na_server_set_vfiler(na_server_t* srv, const char * vfilerserver);

### Description

Sets the name of the vFiler unit on which the Data ONTAP API commands need to be invoked for the given server context.

After the command is set, all the API commands are executed on the vFiler unit through the actual server.

This API supports the vFiler tunneling
feature.

Input | Type | Description
srv | na_server_t * | The pointer to the server context.
vfilerserver | const char * | The name of the vFiler unit that is to be set.

### Return value

- 1 (TRUE) on success

- 0 (FALSE) on failure

[top]

## na_server_set_port

### Prototype

int na_server_set_port(na_server_t* srv, int port);

### Description

Sets the port on which the API commands need to be invoked for the given server context.

Following is the default port on the storage system for Data ONTAP API communication:

HTTP=80

HTTPS=443

Set this port number if Data ONTAP does not have the default port settings.

Following is the default port on the server for DataFabric Manager APIs for the OnCommand Package communication:

HTTP=8080

HTTPS=8488

For DataFabric Manager APIs for the OnCommand Package, you must invoke this API to set the port.

Input | Type | Description
srv | na_server_t * | The pointer to the server context.
port | int | The port number that is to be set.

### Return value

- 1 (TRUE) on success

- 0 (FALSE) on failure

[top]

## na_server_set_timeout

### Prototype

int na_server_set_timeout(na_server_t* srv, int timeout);

### Description

Sets a connection timeout for the following actions:

- Establishing a connection with the server.

- Reading and writing data to and from the server socket used for API communication.

Input | Type | Description
srv | na_server_t * | The pointer to the server context.
timeout | int | The timeout value. This value is in seconds and should be zero or a positive number. If it is non-zero, the server uses non-blocking socket connection. If it is zero, the server uses blocking connection, which is the default behavior.

### Return value

- 1 (TRUE) on success

- 0 (FALSE) on failure

[top]

## na_server_set_vserver

### Prototype

int na_server_set_vserver(na_server_t* srv, const char* vsrv);

### Description

Sets the name of the Vserver to which a Cluster API need to be tunneled from a Cluster Management Interface.

Input | Type | Description
srv | na_server_t * | The pointer to the server context.
vsrv | const char * | The name of the Vserver that is to be set.

### Return value

- 1 (TRUE) on success

- 0 (FALSE) on failure

[top]

## na_server_invoke

### Prototype

na_elem_t* na_server_invoke(na_server_t* srv, const char* api, ...);

### Description

Invokes any API on the given server.

Enter the name-value pairs and terminate the list with NULL. You can enter only an even number of arguments to this function. The name-value pairs take only strings. All these contexts are then assembled and sent to the server.

Input | Type | Description
srv | na_server_t* | The pointer to the server context.
api | const char * | The name of the API that is to be invoked.
... | char * | The input arguments as a name-value pair.

### Return value

The pointer to the input output context that contains the server response

[top]

## na_server_invoke_elem

Prototype

na_elem_t* na_server_invoke_elem(na_server_t* srv, na_elem_t* elt);

Description

Sends the API request in the form of input output context, in which the API command and its input arguments are embedded.

After the API call ends, you must free the context elt by invoking na_elem_free().

While processing optional inputs from a dialog box, it is recommended that you construct an context chain instead of using na_server_invoke().

Input | Type | Description
srv | na_server_t* | The pointer to the server context.
elt | na_elem_t* | The pointer to the context chain.

### Return value

The pointer to the context that contains the server's reply

[top]

## na_server_close

### Prototype

int na_server_close(na_server_t* srv);

### Description

Clears the server context opened by na_server_open().This is done by freeing all the allocated resources for that server context.

You can have multiple server contexts opened at the same time and each opened server context has to be closed individually.

Input | Type | Description
srv | na_server_t* | The pointer to the server context.

### Return value

- 1 (TRUE) on success

- 0 (FALSE) on failure

[top]

## na_server_set_debugstyle

### Prototype

void na_server_set_debugstyle(na_server_t * srv, na_debug_style_t style);

### Description

Sets the debug style for the given server context.

Input | Type | Description
srv | na_server_t* | The pointer to the server context.
style | na_debug_style_t | The debug style that is to be set. The default value is NA_PRINT_DONT_PARSE, which prints the raw XML output derived from the server by using na_server_get_raw_xml_output. Following are the supported values for style: NA_NO_DEBUG NA_PRINT_DONT_PARSE NA_DONT_PRINT_DONT_PARSE

### Return value

None

[top]

## na_server_set_client_cert_and_key

### Prototype

int na_server_set_client_cert_and_key (na_server_t* srv, const char* cert, const char* key, const char* passwd);

### Description

Sets the client's certificate for authentication by the server in a Secure Sockets Layer (SSL) session.

Input | Type | Description
srv | na_server_t* | The pointer to the server context.
cert | const char* | The name of the file in Privacy Enhanced Mail (PEM) format that contains the certificate.
key | const char* | The name of the file in PEM format that contains the private key. If key = NULL, then the certificate file is used as the key file.
passwd | const char* | The password to access the private key file. passwd = NULL if the private key file is not password-protected.

### Return value

- 1 (TRUE) on success

- 0 (FALSE) on failure

## na_server_set_server_cert_verification

### Prototype

int na_server_set_server_cert_verification (na_server_t *srv, int enable);

### Description

Enables or disables the server certificate verification by the client.

When the authentication style is set to STYLE_CERTIFICATE, server certificate verification is enabled by default. Otherwise, you have to set the transport type to HTTPS, and then provide the trusted CA certificates by using the na_server_set_ca_certs() API to verify the server certificate.

Hostname verification is enabled by default during server certificate verification.

Input | Type | Description
srv | na_server_t* | The pointer to the server context.
enable | int | The state of the server certificate verification. Set enable = 1 to enable server certificate verification, and set 0 to disable.

### Return value

- 1 (TRUE) on success

- 0 (FALSE) on failure

[top]

## na_server_is_server_cert_verification_enabled

### Prototype

int na_server_is_server_cert_verification_enabled (na_server_t* srv);

### Description

Determines whether server certificate verification is enabled.

Input | Type | Description
srv | na_server_t* | The pointer to the server context.

### Return value

- 1 (TRUE) if server certificate verification enabled

- 0 (FALSE) if server certificate verification disabled

[top]

## na_server_set_ca_certs

### Prototype

int na_server_set_ca_certs (na_server_t* srv, const char* CAfile);

### Description

Sets the location of trusted certificates that is used for server certificate verification during an SSL session.

The APIs na_server_set_ca_certs() and na_server_set_client_cert_and_key() can be used to build a client certificate chain that is sent to the server during an SSL session.

Input | Type | Description
srv | na_server_t* | The pointer to the server context.
CAfile | const char* | The name of the file in Privacy Enhanced Mail (PEM) format that contains the trusted certificate. The file can contain several certificates from the trusted Certificate Authority.

### Return value

- 1 (TRUE) on success

- 0 (FALSE) on failure

[top]

## na_server_set_hostname_verification

### Prototype

int na_server_set_hostname_verification (na_server_t *srv, int enable);

### Description

Enables or disables hostname verification during server certificate verification.

You must use the na_server_open() API to specify the hostname it is connecting to.

Hostname verification ensures that the hostname to which the client connects, matches that with the hostname in the certificate (CN name) that the server sends during an SSL session.

Hostname verification is enabled by default during server certificate verification.

Input | Type | Description
srv | na_server_t* | The pointer to the server context.
enable | int | The state of the server certificate verification. Set enable = 1 to enable hostname certificate verification, and set 0 to disable.

### Return value

- 1 (TRUE) on success

- 0 (FALSE) on failure

[top]

## na_server_is_hostname_verification_enabled

### Prototype

int na_server_is_hostname_verification_enabled (na_server_t* srv);

### Description

Determines whether hostname verification is enabled.

Input | Type | Description
srv | na_server_t * | The pointer to the server context.

### Return value

- 1 (TRUE) if hostname verification is enabled

- 0 (FALSE) if hostname verification is disabled

[top]

## na_server_get_style

### Prototype

na_style_t na_server_get_style(na_server_t* srv);

### Description

Gets the authentication style used by the given server context.

Input | Type | Description
srv | na_server_t * | The pointer to the server context.

### Return value

The server style.

Following are the possible return values:

- NA_STYLE_LOGIN_PASSWORD

- NA_STYLE_RPC

- NA_STYLE_HOSTSEQUIV

- NA_STYLE_CERTIFICATE

[top]

## na_server_get_transport_type

### Prototype

na_server_transport_t na_server_get_transport_type(na_server_t* srv)

### Description

Gets the transport type used by the given server context.

Input | Type | Description
srv | na_server_t* | The pointer to the server context.

### Return value

The current transport type used for the given server context.

Following are the possible return values:

- NA_SERVER_TRANSPORT_HTTP

- NA_SERVER_TRANSPORT_HTTPS

[top]

## na_server_get_port

### Prototype

int na_server_get_port (na_server_t * srv);

Description

Gets the port number for the given server context used for invoking API commands.

Input | Type | Description
srv | na_server_t * | The pointer to the server context.

### Return value

None

[top]

## na_server_get_timeout

### Prototype

const char* na_server_get_timeout(na_server_t *srv);

### Description

Gets the connection timeout value of the given server context.

Input | Type | Description
srv | na_server_t * | The pointer to the server context.

### Return value

The connection timeout value (in seconds)

[top]

## na_server_get_vserver

### Prototype

const char* na_server_get_vserver();

### Description

Gets the name of the Vserver to which a Cluster API need to be tunneled from a Cluster Management Interface.

### Return value

Name of the Vserver

[top]

## na_server_get_raw_xml_output

### Prototype

char * na_server_get_raw_xml_output(na_server_t * srv);

### Description

Gets the output of the API invoked in raw XML format.

The debug style of the server should be set to NA_PRINT_DONT_PARSE before using this API.

Input | Type | Description
srv | na_server_t * | The pointer to the server context.

### Return value

The raw XML output

[top]