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

The GW2RegisterPoliciesFile registers the content management policy XML file to a session.

If neither **GW2RegisterPoliciesFile** or **GW2RegisterPoliciesMemory** is registered with a session, the default policies will be applied to that session. The default policy sets all content management switches to Sanitise.

<Tabs>

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

**Synopsis**

The **GW2RegisterPoliciesFile** function requests that **session** uses the policies specified in the file whose name is the string pointed to by **filename.** The format of the policies is in the format specified by **format**. The policies will be applied to all processing performed by Glasswall for that session.

```cpp

#include "glasswall.core2.api.h"
int GW2RegisterPoliciesFile(Session session, const char *filename, Policy_format format);

```

**Returns**

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

**Example**

```cpp

    #include "glasswall.core2.api.h"

    HANDLE session = GW2OpenSession();
    if (!session)
        /* deal with error */
    else
        if (GW2RegisterPoliciesFile(session, "Office_Binary_Policies.xml",  PF_XML) < 0)
            /* deal with error */
        else
            /* the file has been successfully registered */

    ...

    /* later */
    if (GW2CloseSession(session) < 0)
        /* error closing session */

```

</TabItem>

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

**Synopsis**

Registers with the session referred to by session, the file pointed to by policiesFilePath, with a format  specified
by policiesFormat

```csharp
/// <param name="session">ID number for the session</param>
/// <param name="policiesFilePath">The file path to the file to be processed</param>
/// <param name="policiesFormat">Format of the policy file</param>
public int RegisterPoliciesFile(
    int session,
    string policiesFilePath,
    int policiesFormat

```

**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 int GW2RegisterPoliciesFile(int session, String policiesFilePath, int format) throws GlasswallException, NullPointerException

(Deprecated)
public int GW2RegisterPoliciesFile(int session, byte[] policiesFilePath, int format) throws GlasswallException, NullPointerException
```

**Description**

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

The **GW2RegisterPoliciesFile** function parameters have been updated to use `String` in place of `byte[]`. The original function has been deprecated.

**Returns**

The **GW2RegisterPoliciesFile** 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. 

A **NullPointerException** exception will be thrown if `policiesFilePath` is null or empty.

A **GlasswallException** exception will be thrown if `session` is invalid, if the `policiesFilePath` could not be retrieved, or if the `policiesFilePath` could not be converted to UTF-8.

</TabItem>

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

**Synopsis**

Sets the content management policy configuration. If input_file is None then default settings (sanitise) are applied.

```py
def set_content_management_policy(self, session: int, input_file: Union[None, str, bytes, bytearray, io.BytesIO, "glasswall.content_management.policies.policy.Policy"] = None, policy_format=0):
    """ Sets the content management policy configuration. If input_file is None then default settings (sanitise) are applied.

    Args:
        session (int): The session integer.
        input_file (Union[None, str, bytes, bytearray, io.BytesIO, glasswall.content_management.policies.policy.Policy], optional): Default None (sanitise). The content management policy to apply.
        policy_format (int): The format of the content management policy. 0=XML.

    Returns:
        - result (glasswall.GwReturnObj): Depending on the input 'input_file':
            - If input_file is a str file path:
                - gw_return_object (glasswall.GwReturnObj): A GwReturnObj instance with the attributes 'session', 'input_file', 'policy_format', 'status'.

            - If input_file is a file in memory:
                - gw_return_object (glasswall.GwReturnObj): A GwReturnObj instance with the attributes 'session', 'buffer', 'buffer_length', 'policy_format', 'status'.
    """
```

**Returns**

An object with different attributes depending on the type of `input_file`.

- If input_file is a str file path:
    - gw_return_object (glasswall.GwReturnObj): A GwReturnObj instance with the attributes 'session', 'input_file', 'policy_format', 'status'.

- If input_file is a file in memory:
    - gw_return_object (glasswall.GwReturnObj): A GwReturnObj instance with the attributes 'session', 'buffer', 'buffer_length', 'policy_format', 'status'.

The status attribute is an integer `GW2_RetStatus` enum value. Negative numbers indicate a failure.

</TabItem>

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

**Synopsis**

This function requests that the specified session uses the polices in the specified file.

```jsx
/**
 * @param {number} session The ID of the session.
 * @param {string} filename The filename from which to load policy settings.
 * @param {number} format - The format of the policy to be registered.
 */

GW2RegisterPoliciesFile(
    session,
    filename,
    format)

```

**Returns**

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

</TabItem>

</Tabs>