text
stringlengths
0
357
hasher.init(&hasher);
hasher.add(&hasher, (const uint8_t*)member_cs.buf, strlen(member_cs.buf));
binary_hash = malloc(hasher.size);
hasher.finish(&hasher, binary_hash);
}
/* output the first 8 bytes as 16 hex-characters - CAVE: if the lenght changes here, also adapt dc_extract_grpid_from_rfc724_mid() */
ret = calloc(1, 256);
if (ret==NULL) {
goto cleanup;
}
for (i = 0; i < 8; i++) {
sprintf(&ret[i*2], "%02x", (int)binary_hash[i]);
}
free(binary_hash);
#endif
cleanup:
dc_array_free_ptr(member_addrs);
dc_array_unref(member_addrs);
free(member_ids_str);
sqlite3_finalize(stmt);
sqlite3_free(q3);
free(member_cs.buf);
return ret;
}
static uint32_t create_group_record(dc_context_t* context, const char* grpid, const char* grpname, int create_blocked, int create_verified)
{
uint32_t chat_id = 0;
sqlite3_stmt* stmt = NULL;
stmt = dc_sqlite3_prepare(context->sql,
"INSERT INTO chats (type, name, grpid, blocked) VALUES(?, ?, ?, ?);");
sqlite3_bind_int (stmt, 1, create_verified? DC_CHAT_TYPE_VERIFIED_GROUP : DC_CHAT_TYPE_GROUP);
sqlite3_bind_text(stmt, 2, grpname, -1, SQLITE_STATIC);
sqlite3_bind_text(stmt, 3, grpid, -1, SQLITE_STATIC);
sqlite3_bind_int (stmt, 4, create_blocked);
if (sqlite3_step(stmt)!=SQLITE_DONE) {
goto cleanup;
}
chat_id = dc_sqlite3_get_rowid(context->sql, "chats", "grpid", grpid);
cleanup:
sqlite3_finalize(stmt);
return chat_id;
}
/*******************************************************************************
* Handle groups for received messages
******************************************************************************/
static void create_or_lookup_adhoc_group(dc_context_t* context, dc_mimeparser_t* mime_parser,
int allow_creation, int create_blocked,
int32_t from_id, const dc_array_t* to_ids,/*does not contain SELF*/
uint32_t* ret_chat_id, int* ret_chat_id_blocked)
{
/* if we're here, no grpid was found, check there is an existing ad-hoc
group matching the to-list or if we can create one */
dc_array_t* member_ids = NULL;
uint32_t chat_id = 0;
int chat_id_blocked = 0;
int i = 0;
dc_array_t* chat_ids = NULL;
char* chat_ids_str = NULL;
char* q3 = NULL;
sqlite3_stmt* stmt = NULL;
char* grpid = NULL;
char* grpname = NULL;
/* build member list from the given ids */
if (dc_array_get_cnt(to_ids)==0 || dc_mimeparser_is_mailinglist_message(mime_parser)) {
goto cleanup; /* too few contacts or a mailinglist */
}
member_ids = dc_array_duplicate(to_ids);
if (!dc_array_search_id(member_ids, from_id, NULL)) { dc_array_add_id(member_ids, from_id); }
if (!dc_array_search_id(member_ids, DC_CONTACT_ID_SELF, NULL)) { dc_array_add_id(member_ids, DC_CONTACT_ID_SELF); }
if (dc_array_get_cnt(member_ids) < 3) {
goto cleanup; /* too few contacts given */
}
/* check if the member list matches other chats, if so, choose the one with the most recent activity */
chat_ids = search_chat_ids_by_contact_ids(context, member_ids);
if (dc_array_get_cnt(chat_ids)>0) {
chat_ids_str = dc_array_get_string(chat_ids, ",");
q3 = sqlite3_mprintf("SELECT c.id, c.blocked "
" FROM chats c "
" LEFT JOIN msgs m ON m.chat_id=c.id "
" WHERE c.id IN(%s) "
" ORDER BY m.timestamp DESC, m.id DESC "
" LIMIT 1;",
chat_ids_str);
stmt = dc_sqlite3_prepare(context->sql, q3);
if (sqlite3_step(stmt)==SQLITE_ROW) {
chat_id = sqlite3_column_int(stmt, 0);