This example can be found in examples\c\restserver\restserver.c
.
This example shows how to enable the REST server using the PST SDK. The REST server enables network-based access to the PST Tracker using the HTTP protocol. GET and POST requests can be made to the server to send and receive data and change parameters. The REST interface offers a programming language independent interface to the PST Tracker. Besides accessing the REST server directly using a browser, a networking library like Curl can be used to interface with the server programatically.
When compiling and running this example, please make sure that the required dependencies can be found by the executable (e.g. by copying the Redist
directory into the build directory. When the PST SDK has been installed through the PST Software Suite installer the Redist folder can be found in the Development folder.).
#ifdef WIN32
#include <windows.h>
#else
#include <unistd.h>
#endif
static void Exithandler(int sig);
#ifdef WIN32
BOOL WINAPI ConsoleHandler(DWORD CEvent)
{
Exithandler(CEvent);
return TRUE;
}
#endif
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
static void Exithandler(int sig)
{
exit(0);
}
void PrintLastErrorMessage()
{
char* last_error_message = NULL;
{
last_error_message = "Failed to allocate memory error.";
}
printf("last error message: %s \n", last_error_message);
}
{
{
PrintLastErrorMessage();
exit(status);
}
}
int main(int argc, char *argv[])
{
#ifdef WIN32
SetConsoleCtrlHandler((PHANDLER_ROUTINE)ConsoleHandler, TRUE);
#else
signal(SIGTERM, Exithandler);
signal(SIGKILL, Exithandler);
signal(SIGQUIT, Exithandler);
signal(SIGINT, Exithandler);
#endif
#ifdef WIN32
#else
CheckErrorCode(
pst_tracker_init4(&ctracker,
"",
"config.cfg",
"models.db", argv[1]));
#endif
printf("PST REST server enabled. See the PST SDK Manual for example commands.\n");
#ifdef WIN32
Sleep(60000);
#else
sleep(60);
#endif
return 0;
}