This commit is contained in:
Markus Koch 2020-05-03 20:13:25 +02:00
parent 6e5b86c076
commit c0de012044
2 changed files with 19 additions and 13 deletions

View File

@ -203,7 +203,14 @@ GList *dijkstra_search_get_route(struct dijkstra_search *search,
return l;
}
int printb(char **buf, int *offset, const char *__restrict __format, ...)
/*!
* \brief sdprintf printf to a dynamic buffer
* \param buf The character buffer. Will append if not NULL;
* \param offset Should be set to strlen when continuing a string. Will be incremented automatically.
* \param __format printf format string
* \return the number of bytes written
*/
int sdprintf(char **buf, int *offset, const char *__restrict __format, ...)
{
va_list vargs;
int len;
@ -236,7 +243,7 @@ int dijkstra_search_route_to_geojson(struct dijkstra_search *search,
*buf = NULL;
printb(buf, &offset, "[");
sdprintf(buf, &offset, "[");
for (l = route; l != NULL; l = l->next) {
node = (struct dijkstra_node*) l->data;
@ -258,31 +265,31 @@ int dijkstra_search_route_to_geojson(struct dijkstra_search *search,
format_str = "Go %s onto %s.";
if (node_last != search->start)
printb(buf, &offset, ",");
printb(buf, &offset, "\n");
printb(buf, &offset, "{\"type\": \"Feature\",\n"
sdprintf(buf, &offset, ",");
sdprintf(buf, &offset, "\n");
sdprintf(buf, &offset, "{\"type\": \"Feature\",\n"
" \"geometry\": {\n"
" \"type\": \"LineString\", \"coordinates\": [[%f,%f],[%f,%f]]\n"
" },\n",
node_last->position.x, node_last->position.y,
node->position.x, node->position.y);
printb(buf, &offset, " \"properties\": {\n"
sdprintf(buf, &offset, " \"properties\": {\n"
" \"heading\": \"%f\",\n"
" \"through\": \"%s\",\n",
heading, search->states[node->uid]->cheapest_path->name);
printb(buf, &offset, " \"description\": \"");
printb(buf, &offset, format_str, relative_direction_str, search->states[node->uid]->cheapest_path->name);
printb(buf, &offset, "\"\n");
sdprintf(buf, &offset, " \"description\": \"");
sdprintf(buf, &offset, format_str, relative_direction_str, search->states[node->uid]->cheapest_path->name);
sdprintf(buf, &offset, "\"\n");
printb(buf, &offset, " }\n");
printb(buf, &offset, "}");
sdprintf(buf, &offset, " }\n");
sdprintf(buf, &offset, "}");
last_heading = heading;
}
node_last = node;
}
printb(buf, &offset, "\n]\n");
sdprintf(buf, &offset, "\n]\n");
return offset;
}

View File

@ -117,7 +117,6 @@ static void dijkstra_serv_soup_callback (SoupServer *server,
soup_message_set_status (msg, SOUP_STATUS_OK);
}
soup_message_set_response (msg, "application/json", SOUP_MEMORY_COPY,
body, body_len);
free(body);