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

The **GW2RegisterLicenceFile** registers the licence file to a session.

If neither **GW2RegisterLicenceFile** or **GW2RegisterLicenceMemory** is registered with a session, the Editor will attempt to search for the licence in the default location. This is a file called gwkey.lic located in the same folder as the Editor library. If that cannot be found then the library will be considered unlicenced and some processes may fail with licence expiry issues.

<Tabs>

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

**Synopsis**

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

```cpp

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

```

**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 (GW2RegisterLicenceFile(session, "gwkey.lic") < 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**

The **RegisterLicenceFile** method requests that session **session** uses the licence specified in the file whose name is the string pointed to by **filename**. The Licence will be applied to all processing performed by Glasswall for that session.

```csharp
    /// <param name="session">Current open Glasswall session</param>
    /// <param name="filePath">The file path to the licence file to be registered</param>
    public int RegisterLicenceFile(int session, string filePath)
```

**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 GW2RegisterLicenceFile(int session, String licenceFilePath) throws GlasswallException, NullPointerException

(Deprecated)
public int GW2RegisterLicenceFile(int session, byte[] licenceFilePath) throws GlasswallException, NullPointerException
```

**Note**

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

**Returns**

The **GW2RegisterLicenceFile** 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 `licenceFilePath` is null or empty.

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

</TabItem>

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

Licence registration for each session is handled automatically in the Python wrapper, and it is not necessary for users to call `GW2RegisterLicenceFile` or `GW2RegisterLicenceMemory` manually.

By default, the `Editor` class expects a valid licence file to be located in the same directory as the `library_path`. You can also specify a different path to a `gwkey.lic` licence file using the `licence` argument.

```py
import glasswall


# Load the Glasswall Editor library with a specified licence file
editor = glasswall.Editor(r"C:\gwpw\libraries\10.0", licence=r"C:\gwpw\licence\gwkey.lic")
```

Alternatively, you can pass the licence data in-memory as a bytes, bytearray, or io.BytesIO object.

```py
import glasswall


# Alternatively, load the licence from in-memory bytes or bytearray
with open(r"C:\gwpw\licence\gwkey.lic", "rb") as f:
    licence_data = f.read()

editor = glasswall.Editor(
    r"C:\gwpw\libraries\10.0", 
    licence=licence_data  # In-memory licence data
)
```

</TabItem>

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

**Synopsis**

The **RegisterLicenceFile** method requests that session **session** uses the licence specified in the file whose name is the string pointed to by **filename**. The Licence will be applied to all processing performed by Glasswall for that session.

```jsx
    /**
     * Sets what licence file should be loaded for the session.
     * @param {number} session The ID of the session.
     * @param {string} filename The filename from which to load the licence.
     * @returns {number} Status of the operation; 0 for success, non-zero for failure.
     */
    GW2RegisterLicenceFile(session, filename)
```

**Returns**

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

</TabItem>

</Tabs>