mirror of
https://github.com/owntracks/recorder.git
synced 2026-02-13 20:49:51 +00:00
add --debug to ot-recorder
This commit is contained in:
13
README.md
13
README.md
@@ -137,7 +137,7 @@ This section lists the most important options of the _recorder_ with their long
|
||||
|
||||
`--geokey` sets the Google API key for reverse geo lookups. If you do more than 2500 (currently) reverse-geo requests per day, you'll need an API key for Google's geocoding service. Specify that here.
|
||||
|
||||
|
||||
`--debug` enables a bit of additional debugging on stderr.
|
||||
|
||||
## The HTTP server
|
||||
|
||||
@@ -746,9 +746,18 @@ You need a current version of the Mosquitto library (and you probably require th
|
||||
### Debian
|
||||
|
||||
```
|
||||
apt-get install build-essential linux-headers-$(uname -r) libcurl4-openssl-dev libmosquitto-dev liblua5.2-dev
|
||||
apt-get install build-essential linux-headers-$(uname -r) libcurl4-openssl-dev libmosquitto-dev liblua5.2-dev libsodium-dev
|
||||
```
|
||||
|
||||
### Centos 7
|
||||
|
||||
```
|
||||
yum groupinstall 'Development Tools'
|
||||
yum install libmosquitto-devel libcurl-devel lua-devel
|
||||
```
|
||||
|
||||
libsodium is in epel-stable
|
||||
|
||||
### Ubuntu
|
||||
|
||||
```
|
||||
|
||||
14
recorder.c
14
recorder.c
@@ -317,6 +317,7 @@ static void putrec(struct udata *ud, time_t now, UT_string *reltopic, UT_string
|
||||
if ((fp = pathn("a", "rec", username, device, "rec")) == NULL) {
|
||||
olog(LOG_ERR, "Cannot write REC for %s/%s: %m",
|
||||
UB(username), UB(device));
|
||||
return;
|
||||
}
|
||||
|
||||
fprintf(fp, RECFORMAT, isotime(now),
|
||||
@@ -574,7 +575,8 @@ struct mosquitto_message *decrypt(struct udata *ud, const struct mosquitto_messa
|
||||
olog(LOG_ERR, "no decryption key for %s in %s", UB(userdev), m->topic);
|
||||
return (NULL);
|
||||
}
|
||||
// fprintf(stderr, "Key for %s is [%s]\n", UB(userdev), key);
|
||||
|
||||
debug(ud, "Key for %s is [%s]", UB(userdev), key);
|
||||
|
||||
if ((msg = malloc(sizeof(struct mosquitto_message))) == NULL) {
|
||||
return (NULL);
|
||||
@@ -593,7 +595,7 @@ struct mosquitto_message *decrypt(struct udata *ud, const struct mosquitto_messa
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
// fprintf(stderr, "START DECRYPT. clen==%lu\n", ciphertext_len);
|
||||
debug(ud, "START DECRYPT. clen==%lu", ciphertext_len);
|
||||
|
||||
if ((cleartext = calloc(n, sizeof(unsigned char))) == NULL) {
|
||||
free(ciphertext);
|
||||
@@ -614,7 +616,7 @@ struct mosquitto_message *decrypt(struct udata *ud, const struct mosquitto_messa
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
// printf("DECRYPTED: %s\n", (char *)cleartext);
|
||||
debug(ud, "DECRYPTED: %s", (char *)cleartext);
|
||||
free(ciphertext);
|
||||
|
||||
msg->payload = (void *)cleartext;
|
||||
@@ -1253,6 +1255,7 @@ void usage(char *prog)
|
||||
printf(" --hosted use OwnTracks Hosted\n");
|
||||
printf(" --norec don't maintain REC files\n");
|
||||
printf(" --geokey optional Google reverse-geo API key\n");
|
||||
printf(" --debug additional debugging\n");
|
||||
printf("\n");
|
||||
printf("Options override these environment variables:\n");
|
||||
printf(" $OTR_HOST MQTT hostname\n");
|
||||
@@ -1316,6 +1319,7 @@ int main(int argc, char **argv)
|
||||
#endif /* WITH_LUA */
|
||||
udata.label = strdup("Recorder");
|
||||
udata.geokey = NULL; /* default: no API key */
|
||||
udata.debug = FALSE;
|
||||
|
||||
if ((p = getenv("OTR_HOST")) != NULL) {
|
||||
hostname = strdup(p);
|
||||
@@ -1356,6 +1360,7 @@ int main(int argc, char **argv)
|
||||
{ "label", required_argument, 0, 10},
|
||||
{ "norec", no_argument, 0, 11},
|
||||
{ "geokey", required_argument, 0, 12},
|
||||
{ "debug", required_argument, 0, 13},
|
||||
#ifdef WITH_LUA
|
||||
{ "lua-script", required_argument, 0, 7},
|
||||
#endif
|
||||
@@ -1373,6 +1378,9 @@ int main(int argc, char **argv)
|
||||
break;
|
||||
|
||||
switch (ch) {
|
||||
case 13:
|
||||
udata.debug = TRUE;
|
||||
break;
|
||||
case 12:
|
||||
udata.geokey = strdup(optarg);
|
||||
break;
|
||||
|
||||
1
udata.h
1
udata.h
@@ -41,6 +41,7 @@ struct udata {
|
||||
#endif
|
||||
char *label; /* Server label */
|
||||
char *geokey; /* Google reverse-geo API key */
|
||||
int debug; /* enable for debugging */
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
19
util.c
19
util.c
@@ -35,6 +35,7 @@
|
||||
#include <errno.h>
|
||||
#include <stdarg.h>
|
||||
#include <math.h>
|
||||
#include "udata.h"
|
||||
|
||||
#ifndef LINESIZE
|
||||
# define LINESIZE 8192
|
||||
@@ -289,6 +290,24 @@ void olog(int level, char *fmt, ...)
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
void debug(struct udata *ud, char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
static UT_string *u = NULL;
|
||||
|
||||
if (ud->debug == FALSE)
|
||||
return;
|
||||
|
||||
va_start(ap, fmt);
|
||||
utstring_renew(u);
|
||||
|
||||
utstring_printf_va(u, fmt, ap);
|
||||
|
||||
fprintf(stderr, "+++++ [%s]\n", UB(u));
|
||||
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
const char *yyyymm(time_t t) {
|
||||
static char buf[] = "YYYY-MM";
|
||||
|
||||
|
||||
2
util.h
2
util.h
@@ -9,6 +9,7 @@
|
||||
#include <time.h>
|
||||
#include <syslog.h>
|
||||
#include "json.h"
|
||||
#include "udata.h"
|
||||
#include "utstring.h"
|
||||
|
||||
#define UB(x) utstring_body(x)
|
||||
@@ -34,5 +35,6 @@ void geohash_setprec(int precision);
|
||||
int geohash_prec(void);
|
||||
void lowercase(char *s);
|
||||
double haversine_dist(double th1, double ph1, double th2, double ph2);
|
||||
void debug(struct udata *, char *fmt, ...);
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user