text
stringlengths
0
357
" AND independent=0 "
" GROUP BY timestamp "
" ORDER BY timestamp;");
sqlite3_bind_int (stmt, 1, DC_CONTACT_ID_SELF);
sqlite3_bind_int64 (stmt, 2, locations_send_begin);
sqlite3_bind_int64 (stmt, 3, locations_last_sent);
sqlite3_bind_int (stmt, 4, DC_CONTACT_ID_SELF);
while (sqlite3_step(stmt)==SQLITE_ROW)
{
uint32_t location_id = sqlite3_column_int(stmt, 0);
char* latitude = dc_ftoa(sqlite3_column_double(stmt, 1));
char* longitude = dc_ftoa(sqlite3_column_double(stmt, 2));
char* accuracy = dc_ftoa(sqlite3_column_double(stmt, 3));
char* timestamp = get_kml_timestamp(sqlite3_column_int64 (stmt, 4));
dc_strbuilder_catf(&ret,
"<Placemark>"
"<Timestamp><when>%s</when></Timestamp>"
"<Point><coordinates accuracy=\"%s\">%s,%s</coordinates></Point>"
"</Placemark>\n",
timestamp,
accuracy,
longitude, // reverse order!
latitude);
location_count++;
if (last_added_location_id) {
*last_added_location_id = location_id;
}
free(latitude);
free(longitude);
free(accuracy);
free(timestamp);
}
if (location_count==0) {
goto cleanup;
}
dc_strbuilder_cat(&ret,
"</Document>\n"
"</kml>");
success = 1;
cleanup:
sqlite3_finalize(stmt);
free(self_addr);
if (!success) {
free(ret.buf);
}
return success? ret.buf : NULL;
}
char* dc_get_message_kml(dc_context_t* context, time_t timestamp, double latitude, double longitude)
{
char* timestamp_str = NULL;
char* latitude_str = NULL;
char* longitude_str = NULL;
char* ret = NULL;
if (context==NULL || context->magic!=DC_CONTEXT_MAGIC) {
goto cleanup;
}
timestamp_str = get_kml_timestamp(timestamp);
latitude_str = dc_ftoa(latitude);
longitude_str = dc_ftoa(longitude);
ret = dc_mprintf(
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
"<kml xmlns=\"http://www.opengis.net/kml/2.2\">\n"
"<Document>\n"
"<Placemark>"
"<Timestamp><when>%s</when></Timestamp>"
"<Point><coordinates>%s,%s</coordinates></Point>"
"</Placemark>\n"
"</Document>\n"
"</kml>",
timestamp_str,
longitude_str, // reverse order!
latitude_str);
cleanup:
free(latitude_str);
free(longitude_str);
free(timestamp_str);
return ret;
}
void dc_set_kml_sent_timestamp(dc_context_t* context,
uint32_t chat_id, time_t timestamp)
{
sqlite3_stmt* stmt = NULL;
stmt = dc_sqlite3_prepare(context->sql,