Skip to main content

Basic SDK Functions

The functions below are essential to start, stop and communicate with the VPN SDK.

User Login Credentials Needed

You must have an active user account in order to create a minimum viable VPN product. Press the 'Add a New User' button at https://app.vpnwholesaler.com/users to create one.

At the bare minimum and considering that you already have login credentials for an active VPN account, you should implement the following functions and commands in order to create a minimum viable VPN product:

  1. Initialize SDK
  2. Set API domain
  3. Login
  4. Set VPN type
  5. Set Binary Path
  6. Start VPN connection
  7. Stop VPN connection
  8. Finalize SDK

Initialize SDK​

Intializes the SDK with a callback and sets necessary path to OpenVPN binary.

Login required: No

Code: InitOVSCore

Input:

C Signature
    int InitOVSCore(callback)

Input Parameters:

Callback - reference to callback function with following signature:

void (char* notify_data)

Response:

int - returns 0 if SDK was intialized sucessfully and other value in case of failure

Code sample:

First, include the provided CoreAPI.h to your project:

macOS Code Sample
        #include "CoreAPI.h"

You can handle JSON using JSON-C:

        #include <json-c/json.h>

Then you should define callback function:

        static void EVCoreNotify(const char *szNotify)
{

}

The callback function should accept JSON encoded as string.

Once that's done, you can go ahead and intialize SDK by providing path to openvpn binary:

        int main(int argc, const char * argv[]) {
// insert code here...
int ret;
ret = InitOVSCore(EVCoreNotify);
if (ret != 0)
{
exit(1);
}
...
}

Finalize SDK​

Unloads SDK and finalizes all running threads. It is necessary to call this method before exit to avoid leaks.

Login required: No

Code: FinalizeOVSCore()

Input: None

Response: None

Code sample:

macOS Code Sample
    FinalizeOVSCore();

Send command​

Asynchronously sends command to SDK. Command result will be returned by calling the callback that was specified on initialization.

All operations in SDK are called asynchronously, and therefore a single callback is used to receive responses from all SDK functions. All responses are encoded as JSON and described in the relevant sections.

Login required: Depending on the command

CmdProc Code: CmdProc(szCmdData)

Input:

{
"cmd": int,
"data: { Command parameters }
}

Response:

Generally, responses carry the following JSON structure:

{
"code": integer
"err": integer
"data": { object }
}

Where:

code - the invoked command's notification event.

err - error code.

data - response based on the notification code.