altos-map: Switch from json FD ops to json FILE ops
authorKeith Packard <keithp@keithp.com>
Sun, 7 Oct 2018 17:32:48 +0000 (10:32 -0700)
committerKeith Packard <keithp@keithp.com>
Sun, 7 Oct 2018 17:32:48 +0000 (10:32 -0700)
Older versions (in Debian stable) do not have the fd-based operations.

Signed-off-by: Keith Packard <keithp@keithp.com>
map-server/altos-map/altos-map-fake [new file with mode: 0755]
map-server/altos-map/altos-map.c
map-server/altos-map/altos-mapc-fake [deleted file]

diff --git a/map-server/altos-map/altos-map-fake b/map-server/altos-map/altos-map-fake
new file mode 100755 (executable)
index 0000000..1bf5f8e
--- /dev/null
@@ -0,0 +1,5 @@
+#!/bin/sh
+# map-N43.799102,W120.586281-hybrid-20.jpg
+export QUERY_STRING="lat=43.799102&lon=-120.586281&zoom=20"
+export REMOTE_ADDR="127.0.0.1"
+./altos-map
index 690ec72..3870107 100644 (file)
@@ -226,16 +226,23 @@ int main(int argc, char **argv)
        if (s < 0)
                fail(408, "Cannot connect AltOS map daemon");
 
+       FILE    *sf = fdopen(s, "r+");
+
+       if (sf == NULL)
+               fail(400, "allocation failure");
+
        json_t *request = json_pack("{s:f s:f s:i s:s}", "lat", lat, "lon", lon, "zoom", zoom, "remote_addr", remote_addr);
 
        if (request == NULL)
                fail(400, "Cannot create JSON request");
 
-       if (json_dumpfd(request, s, 0) < 0)
+       if (json_dumpf(request, sf, 0) < 0)
                fail(400, "Cannot write JSON request");
 
+       fflush(sf);
+
        json_error_t    error;
-       json_t          *reply = json_loadfd(s, 0, &error);
+       json_t          *reply = json_loadf(sf, 0, &error);
 
        if (!reply)
                fail(400, "Cannot read JSON reply");
diff --git a/map-server/altos-map/altos-mapc-fake b/map-server/altos-map/altos-mapc-fake
deleted file mode 100755 (executable)
index 9e22f76..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-#!/bin/sh
-# map-N43.799102,W120.586281-hybrid-20.jpg
-export QUERY_STRING="lat=43.799102&lon=-120.586281&zoom=20"
-export REMOTE_ADDR="127.0.0.1"
-./altos-mapc
-