import Tabs from '@theme/Tabs'
import TabItem from '@theme/TabItem'

The **GW2GetPolicySettings** function provides a string corresponding to the contents of the policy settings file associated with the supplied **session**.

<Tabs>

<TabItem value="C++" label="C++" default>

```cpp

#include "glasswall.core2.api.h"

int GW2GetPolicySettings (
    Session session,
    char **policiesBuffer,
    size_t *policiesLength,
    Policy_format format);

```

**Parameters**

&emsp; **session** The ID of the session as returned by `GW2OpenSession`

&emsp; **policiesBuffer** A string pointer output parameter which is populated with the policy settings information. The memory used by this pointer does **not** need to be freed by the user. In the event of a failure this parameter may be set to nullptr.

&emsp; **policiesLength** An output parameter which is populated with the size in bytes of the memory pointed to by `policiesBuffer`

&emsp; **format** The format of the data. This must be `PF_XML`.

**Returns**

&emsp; Returns an integer indicating whether the function call was successful. Negative numbers indicate a failure. See the [Return Types](/embedded-engine/embedded-engine-api-overview#return-types) table for an explanation of the return codes.

</TabItem>

<TabItem value="C#" label="C#">

**Synopsis**

```csharp
/// <summary>
/// Retrieves policy settings for the session
/// </summary>
/// <param name="session">Current open Glasswall session</param>
/// <param name="policiesBufferPtr">A pointer to the object containing a pointer pointing to the policy data</param>
/// <param name="policiesLengthPtr">A pointer to a object containing the size in bytes </param>
public  int GetPolicySettings(
    int session,
    out IntPtr policiesBufferPtr,
    ref UIntPtr policiesLengthPtr,
    int format)

```

**Returns**

Returns an integer `GW2_RetStatus` enum value. Negative numbers indicate a failure.

</TabItem>

<TabItem value="Java" label="Java">

**Synopsis**

```java
import com.glasswall.core2javabridge.*;

public String GW2GetPolicySettingsString(int session, int format) throws GlasswallException
```

**Note**

The **GW2GetPolicySettingsString** function outputs the currently registered policy settings for the session specified by `session`. 

Refer to API Overview/Return types for valid enumerators for ```format```.

This functionality previously required two separate function calls to retrieve the policy setting data. This has now been streamlined to return the settings as a `String`. The two original functions have been deprecated.

**Returns**

The **GW2GetPolicySettingsString** function returns a `String` containing the policy settings.

A **GlasswallException** exception will be thrown if `session` is invalid, or if the policy settings could not be retrieved.

**Synopsis - Deprecated Functions**

```java
import com.glasswall.core2javabridge.*;

(Deprecated)
public int GW2GetPolicySettings(int session, int format) throws GlasswallException
public byte[] GetPolicyBuffer(int session) throws GlasswallException
```

**Description - Deprecated Functions**

The **GW2GetPolicySettings** function outputs the currently registered policy settings for the session specified by `session` to the internal policy buffer. Retrieve this data through use of **GetPolicyBuffer** function. 

Refer to API Overview/Return types for valid enumerators for ```format```.

**Returns - Deprecated Functions**

The **GW2GetPolicySettings** function returns a **GW2_RetStatus** enumeration converted to `int`. The value will be negative if an error occurred. `0` indicates success. Refer to the API Overview/Return types for details. 

The **GetPolicyBuffer** returns a `byte[]` containing the policy settings. This will be null if **GW2GetPolicySettings** has not been called.

A **GlasswallException** exception will be thrown if `session` is invalid, or if the policy settings could not be retrieved.

</TabItem>

<TabItem value="Python" label="Python">

**Synopsis**

Returns the content management configuration for a given session.

```py
def get_content_management_policy(self, session: int):
    """ Returns the content management configuration for a given session.

    Args:
        session (int): The session integer.

    Returns:
        xml_string (str): The XML string of the current content management configuration.
    """
```

**Returns**

xml_string (str): The XML string of the current content management configuration

</TabItem>

<TabItem value="JavaScript" label="JavaScript">


**Synopsis**
```jsx

/**
 * This function returns the policy settings used for the specified session
 *
 * @param {number} session The ID of the session.
 * @param {string} policiesBuffer The pointer to the policy buffer.
 * @param {number} policiesLength The size of the data in the policy buffer
 * @param {number} format The format of the policy.
 */

GW2GetPolicySettings(
    session,
    policiesBuffer,
    policiesLength,
    format)

```

**Returns**

Returns an integer `GW2_RetStatus` enum value. Negative numbers indicate a failure.

**Example**
```jsx

const ref = require('ref-napi');

...

function buffer_to_string(buffer, buffer_size) {

    if (!buffer.isNull() && ref.deref(buffer_size) > 0) {
        return Buffer.from(ref.reinterpret(ref.deref(buffer), ref.deref(buffer_size), 0)).toString();
    }
    else {
        return "";
    }
}

...

let policy_file_buffer = ref.alloc(ref.refType(ref.types.CString));
let policy_buffer_size = ref.alloc(ref.types.size_t, 0);

let return_status = gw.GW2GetPolicySettings(session_id, policy_file_buffer, policy_buffer_size, 0);
let xml_string = buffer_to_string(policy_file_buffer, policy_buffer_size);

...

```

</TabItem>

</Tabs>