Compare commits

..

No commits in common. "e5acc545977016764ebcc04ad405c0100a54f9b6" and "0cab4dc449894e0db22d6a301ef681a46035c092" have entirely different histories.

2 changed files with 21 additions and 62 deletions

View File

@ -1,9 +1,6 @@
CC = clang CC = clang
CFLAGS_GLIB = $(shell pkgconf --cflags --libs glib-2.0) CFLAGS_GEOCLUE = -I/usr/include/libgeoclue-2.0 -I/usr/include/gio-unix-2.0 -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -I/usr/include/libmount -I/usr/include/blkid -I/usr/include/sysprof-6 -pthread
CFLAGS_GEOCLUE = $(shell pkgconf --cflags --libs libgeoclue-2.0) CFLAGS = -Wall -Wextra -g $(CFLAGS_GEOCLUE) -ljson-c -lcurl -lgeoclue-2 -lglib-2.0 -lgobject-2.0
CFLAGS_JSONC = $(shell pkgconf --cflags --libs json-c)
CFLAGS_CURL = $(shell pkgconf --cflags --libs libcurl)
CFLAGS = -Wall -Wextra -g $(CFLAGS_GLIB) $(CFLAGS_GEOCLUE) $(CFLAGS_JSONC) $(CFLAGS_CURL)
SRCS = src/main.c SRCS = src/main.c
phonetrackd := phonetrackd phonetrackd := phonetrackd

View File

@ -1,16 +1,7 @@
#include <json-c/json.h>
#include <curl/curl.h> #include <curl/curl.h>
#include <geoclue.h> #include <geoclue.h>
struct location_data {
double latitude;
double longitude;
double altitude;
double accuracy;
double heading;
double speed;
unsigned long timestamp;
};
GClueSimple *geoclue_simple = NULL; GClueSimple *geoclue_simple = NULL;
GClueClient *geoclue_client = NULL; GClueClient *geoclue_client = NULL;
GMainLoop *main_loop; GMainLoop *main_loop;
@ -25,68 +16,41 @@ gboolean on_location_timeout(gpointer user_data) {
return FALSE; return FALSE;
} }
int upload_location_data(struct location_data *location) {
char *location_url_base = getenv("PHONETRACK_URL");
if (location_url_base == NULL) {
return 1;
}
size_t url_base_length = strlen(location_url_base);
char *location_url_params = g_strdup_printf("?lat=%f&lon=%f&alt=%f&acc=%f&bearing=%f&speed=%f&timestamp=%lu&sat=%i&bat=%f",
location->latitude, location->longitude, location->altitude, location->accuracy, location->heading, location->speed, location->timestamp, 0, 100.0F);
char *location_url = calloc(url_base_length + strlen(location_url_params) + 1, sizeof(char));
strcat(location_url, location_url_base);
strcat(location_url, location_url_params);
g_free(location_url_params);
CURL *upload_request;
upload_request = curl_easy_init();
curl_easy_setopt(upload_request, CURLOPT_URL, location_url);
curl_easy_setopt(upload_request, CURLOPT_USERAGENT, "phonetrack-linux");
CURLcode response = curl_easy_perform(upload_request);
curl_easy_cleanup(upload_request);
free(location_url);
return response;
}
void get_location(GClueSimple *simple) { void get_location(GClueSimple *simple) {
(void) simple; (void) simple;
GClueLocation *location; GClueLocation *location;
gdouble latitude, longitude, altitude, accuracy;
GVariant *timestamp; GVariant *timestamp;
// const char *description; // const char *description;
struct location_data *location_struct = calloc(1, sizeof(struct location_data));
location = gclue_simple_get_location(simple); location = gclue_simple_get_location(simple);
json_object *location_json = json_object_new_object();
location_struct->latitude = gclue_location_get_latitude(location); latitude = gclue_location_get_latitude(location);
location_struct->longitude = gclue_location_get_longitude(location); longitude = gclue_location_get_longitude(location);
location_struct->altitude = gclue_location_get_altitude(location); altitude = gclue_location_get_altitude(location);
location_struct->accuracy = gclue_location_get_accuracy(location); accuracy = gclue_location_get_accuracy(location);
location_struct->heading = gclue_location_get_heading(location);
location_struct->speed = gclue_location_get_speed(location);
json_object *latitude_json = json_object_new_double(latitude);
json_object_object_add(location_json, "lat", latitude_json);
json_object *longitude_json = json_object_new_double(longitude);
json_object_object_add(location_json, "lon", longitude_json);
json_object *altitude_json = json_object_new_double(altitude);
json_object_object_add(location_json, "alt", altitude_json);
json_object *accuracy_json = json_object_new_double(accuracy);
json_object_object_add(location_json, "acc", accuracy_json);
timestamp = gclue_location_get_timestamp(location); timestamp = gclue_location_get_timestamp(location);
if (timestamp) { if (timestamp) {
unsigned long timestamp_sec, timestamp_usec; unsigned long timestamp_sec, timestamp_usec;
g_variant_get(timestamp, "(tt)", &timestamp_sec, &timestamp_usec); g_variant_get(timestamp, "(tt)", &timestamp_sec, &timestamp_usec);
location_struct->timestamp = timestamp_sec; json_object *timestamp_json = json_object_new_int(timestamp_sec);
json_object_object_add(location_json, "tst", timestamp_json);
} }
if (location_struct->latitude == 0.0F && location_struct->longitude == 0.0F) { const char *location_payload = json_object_to_json_string(location_json);
return; printf("%s\n", location_payload);
}
upload_location_data(location_struct);
free(location_struct);
} }
void on_geoclue_client_active(GClueClient *geoclue_client, GParamSpec *parameter_spec, gpointer user_data) { void on_geoclue_client_active(GClueClient *geoclue_client, GParamSpec *parameter_spec, gpointer user_data) {
@ -131,8 +95,6 @@ int main(int argc, const char *argv[]) {
(void) argc; (void) argc;
(void) argv; (void) argv;
curl_global_init(CURL_GLOBAL_ALL);
gclue_simple_new("phonetrackd", GCLUE_ACCURACY_LEVEL_EXACT, NULL, on_geoclue_ready, NULL); gclue_simple_new("phonetrackd", GCLUE_ACCURACY_LEVEL_EXACT, NULL, on_geoclue_ready, NULL);
main_loop = g_main_loop_new(NULL, FALSE); main_loop = g_main_loop_new(NULL, FALSE);