Initial import
This commit is contained in:
commit
660133c812
28 changed files with 3983 additions and 0 deletions
113
CallCapture/CallCapture.cpp
Normal file
113
CallCapture/CallCapture.cpp
Normal file
|
@ -0,0 +1,113 @@
|
|||
#include <stdlib.h>
|
||||
#include <getopt.h>
|
||||
#include <syslog.h>
|
||||
#include <stdio.h>
|
||||
#include <pcre.h>
|
||||
|
||||
#include "PatchCordProxy.h"
|
||||
#include "UserDataStore.h"
|
||||
|
||||
#define VECTORS_COUNT 8
|
||||
#define DEFAULT_USER_NUMBER 1
|
||||
|
||||
int main(int argc, const char* argv[])
|
||||
{
|
||||
printf("\n");
|
||||
printf("CallCapture for BrandMeister DMR Master Server\n");
|
||||
printf("Copyright 2015 Artem Prilutskiy (R3ABM, cyanide.burnout@gmail.com)\n");
|
||||
printf("\n");
|
||||
|
||||
// Start up
|
||||
|
||||
struct option options[] =
|
||||
{
|
||||
{ "expression", required_argument, NULL, 'e' },
|
||||
{ "connection", required_argument, NULL, 'c' },
|
||||
{ "identity", required_argument, NULL, 'i' },
|
||||
{ "link", required_argument, NULL, 'l' },
|
||||
{ NULL, 0, NULL, 0 }
|
||||
};
|
||||
|
||||
pcre* expression = NULL;
|
||||
const char* file = NULL;
|
||||
uint32_t number = 10;
|
||||
|
||||
int position = 0;
|
||||
const char* error = NULL;
|
||||
|
||||
int selection = 0;
|
||||
while ((selection = getopt_long(argc, const_cast<char* const*>(argv), "e:c:l:", options, NULL)) != EOF)
|
||||
switch (selection)
|
||||
{
|
||||
case 'e':
|
||||
expression = pcre_compile(optarg, 0, &error, &position, NULL);
|
||||
break;
|
||||
|
||||
case 'c':
|
||||
file = optarg;
|
||||
break;
|
||||
|
||||
case 'i':
|
||||
openlog(optarg, 0, LOG_USER);
|
||||
break;
|
||||
|
||||
case 'l':
|
||||
number = atoi(optarg);
|
||||
break;
|
||||
}
|
||||
|
||||
if ((expression == NULL) &&
|
||||
(error != NULL))
|
||||
{
|
||||
printf("Error compiling regular expression: %s (at %d)\n", error, position);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if ((expression == NULL) ||
|
||||
(file == NULL))
|
||||
{
|
||||
printf(
|
||||
"Usage: %s"
|
||||
" --expression <regular expression>"
|
||||
" --connection <path to configuration file>"
|
||||
" --link <link number>"
|
||||
" [--identity <identity>]"
|
||||
"\n",
|
||||
argv[0]);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
// Main
|
||||
|
||||
UserDataStore store(file);
|
||||
PatchCordProxy proxy(number);
|
||||
|
||||
char* line = NULL;
|
||||
size_t length = 0;
|
||||
ssize_t read;
|
||||
|
||||
while ((read = getline(&line, &length, stdin)) != EOF)
|
||||
{
|
||||
syslog(LOG_DEBUG, "%s", line);
|
||||
|
||||
int vectors[VECTORS_COUNT];
|
||||
int count = pcre_exec(expression, NULL, line, length, 0, 0, vectors, VECTORS_COUNT);
|
||||
if (count > 0)
|
||||
{
|
||||
const char* call;
|
||||
pcre_get_substring(line, vectors, count, 1, &call);
|
||||
|
||||
uint32_t number = store.getPrivateIDForCall(call);
|
||||
if (number == 0)
|
||||
number = DEFAULT_USER_NUMBER;
|
||||
proxy.setTalkerID(number);
|
||||
syslog(LOG_INFO, "*** Found call-sign: %s (ID: %d)", call, number);
|
||||
|
||||
pcre_free_substring(call);
|
||||
}
|
||||
}
|
||||
|
||||
pcre_free(expression);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue