text
stringlengths
0
357
kml->curr.timestamp = mkgmtime(&tmval);
if (kml->curr.timestamp>time(NULL)) {
kml->curr.timestamp = time(NULL);
}
}
else if (kml->tag&TAG_COORDINATES) {
char* comma = strchr(val, ',');
if (comma) {
char* longitude = val; // reverse order!
char* latitude = comma+1;
*comma = 0;
comma = strchr(latitude, ',');
if (comma) { *comma = 0; }
kml->curr.latitude = dc_atof(latitude);
kml->curr.longitude = dc_atof(longitude);
}
}
free(val);
}
}
static void kml_endtag_cb(void* userdata, const char* tag)
{
dc_kml_t* kml = (dc_kml_t*)userdata;
if (strcmp(tag, "placemark")==0)
{
if (kml->tag&TAG_PLACEMARK && kml->curr.timestamp
&& kml->curr.latitude && kml->curr.longitude)
{
dc_location_t* location = calloc(1, sizeof(dc_location_t));
*location = kml->curr;
dc_array_add_ptr(kml->locations, location);
}
kml->tag = 0;
}
}
dc_kml_t* dc_kml_parse(dc_context_t* context,
const char* content, size_t content_bytes)
{
dc_kml_t* kml = calloc(1, sizeof(dc_kml_t));
char* content_nullterminated = NULL;
dc_saxparser_t saxparser;
if (context==NULL || context->magic!=DC_CONTEXT_MAGIC) {
goto cleanup;
}
if (content_bytes > 1*1024*1024) {
dc_log_warning(context, 0,
"A kml-files with %i bytes is larger than reasonably expected.",
content_bytes);
goto cleanup;
}
content_nullterminated = dc_null_terminate(content, content_bytes);
if (content_nullterminated==NULL) {
goto cleanup;
}
kml->locations = dc_array_new_typed(context, DC_ARRAY_LOCATIONS, 100);
dc_saxparser_init (&saxparser, kml);
dc_saxparser_set_tag_handler (&saxparser, kml_starttag_cb, kml_endtag_cb);
dc_saxparser_set_text_handler(&saxparser, kml_text_cb);
dc_saxparser_parse (&saxparser, content_nullterminated);
cleanup:
free(content_nullterminated);
return kml;
}
void dc_kml_unref(dc_kml_t* kml)
{
if (kml==NULL) {
return;
}
dc_array_unref(kml->locations);
free(kml->addr);
free(kml);
}
uint32_t dc_save_locations(dc_context_t* context,
uint32_t chat_id, uint32_t contact_id,
const dc_array_t* locations,
int independent)
{
sqlite3_stmt* stmt_test = NULL;
sqlite3_stmt* stmt_insert = NULL;
time_t newest_timestamp = 0;
uint32_t newest_location_id = 0;
if (context==NULL || context->magic!=DC_CONTEXT_MAGIC