text stringlengths 0 357 |
|---|
int dc_keyring_load_self_private_for_decrypting(dc_keyring_t* keyring, const char* self_addr, dc_sqlite3_t* sql) |
{ |
if (keyring==NULL || self_addr==NULL || sql==NULL) { |
return 0; |
} |
sqlite3_stmt* stmt = dc_sqlite3_prepare(sql, |
"SELECT private_key FROM keypairs ORDER BY addr=? DESC, is_default DESC;"); |
sqlite3_bind_text (stmt, 1, self_addr, -1, SQLITE_STATIC); |
while (sqlite3_step(stmt) == SQLITE_ROW) { |
dc_key_t* key = dc_key_new(); |
if (dc_key_set_from_stmt(key, stmt, 0, DC_KEY_PRIVATE)) { |
dc_keyring_add(keyring, key); |
} |
dc_key_unref(key); /* unref in any case, dc_keyring_add() adds its own reference */ |
} |
sqlite3_finalize(stmt); |
return 1; |
} |
``` |
Filename: dc_location.c |
```c |
#include "dc_context.h" |
#include "dc_saxparser.h" |
#include "dc_mimefactory.h" |
/******************************************************************************* |
* create kml-files |
******************************************************************************/ |
static char* get_kml_timestamp(time_t utc) |
{ |
// Returns a string formatted as YYYY-MM-DDTHH:MM:SSZ. The trailing `Z` indicates UTC. |
struct tm wanted_struct; |
memcpy(&wanted_struct, gmtime(&utc), sizeof(struct tm)); |
return dc_mprintf("%04i-%02i-%02iT%02i:%02i:%02iZ", |
(int)wanted_struct.tm_year+1900, (int)wanted_struct.tm_mon+1, (int)wanted_struct.tm_mday, |
(int)wanted_struct.tm_hour, (int)wanted_struct.tm_min, (int)wanted_struct.tm_sec); |
} |
char* dc_get_location_kml(dc_context_t* context, uint32_t chat_id, |
uint32_t* last_added_location_id) |
{ |
int success = 0; |
sqlite3_stmt* stmt = NULL; |
char* self_addr = NULL; |
time_t now = time(NULL); |
time_t locations_send_begin = 0; |
time_t locations_send_until = 0; |
time_t locations_last_sent = 0; |
int location_count = 0; |
dc_strbuilder_t ret; |
dc_strbuilder_init(&ret, 1000); |
if (context==NULL || context->magic!=DC_CONTEXT_MAGIC) { |
goto cleanup; |
} |
// get info about the contact and the chat |
self_addr = dc_sqlite3_get_config(context->sql, "configured_addr", ""); |
stmt = dc_sqlite3_prepare(context->sql, |
"SELECT locations_send_begin, locations_send_until, locations_last_sent" |
" FROM chats " |
" WHERE id=?;"); |
sqlite3_bind_int(stmt, 1, chat_id); |
if (sqlite3_step(stmt)!=SQLITE_ROW) { |
goto cleanup; |
} |
locations_send_begin = sqlite3_column_int64(stmt, 0); |
locations_send_until = sqlite3_column_int64(stmt, 1); |
locations_last_sent = sqlite3_column_int64(stmt, 2); |
sqlite3_finalize(stmt); |
stmt = NULL; |
if (locations_send_begin==0 || now>locations_send_until) { |
goto cleanup; |
} |
// build kml file |
dc_strbuilder_catf(&ret, |
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" |
"<kml xmlns=\"http://www.opengis.net/kml/2.2\">\n" |
"<Document addr=\"%s\">\n", |
self_addr); |
stmt = dc_sqlite3_prepare(context->sql, |
"SELECT id, latitude, longitude, accuracy, timestamp " |
" FROM locations " |
" WHERE from_id=? " |
" AND timestamp>=? " |
" AND (timestamp>=? OR timestamp=(SELECT MAX(timestamp) FROM locations WHERE from_id=?)) " |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.