text stringlengths 0 357 |
|---|
char* self_addr = NULL; |
char* self_addr_urlencoded = NULL; |
char* self_name = NULL; |
char* self_name_urlencoded = NULL; |
char* fingerprint = NULL; |
char* invitenumber = NULL; |
char* auth = NULL; |
dc_chat_t* chat = NULL; |
char* group_name = NULL; |
char* group_name_urlencoded= NULL; |
if (context==NULL || context->magic!=DC_CONTEXT_MAGIC) { |
goto cleanup; |
} |
dc_ensure_secret_key_exists(context); |
// invitenumber will be used to allow starting the handshake, auth will be used to verify the fingerprint |
invitenumber = dc_token_lookup(context, DC_TOKEN_INVITENUMBER, group_chat_id); |
if (invitenumber==NULL) { |
invitenumber = dc_create_id(); |
dc_token_save(context, DC_TOKEN_INVITENUMBER, group_chat_id, invitenumber); |
} |
auth = dc_token_lookup(context, DC_TOKEN_AUTH, group_chat_id); |
if (auth==NULL) { |
auth = dc_create_id(); |
dc_token_save(context, DC_TOKEN_AUTH, group_chat_id, auth); |
} |
if ((self_addr = dc_sqlite3_get_config(context->sql, "configured_addr", NULL))==NULL) { |
dc_log_error(context, 0, "Not configured, cannot generate QR code."); |
goto cleanup; |
} |
self_name = dc_sqlite3_get_config(context->sql, "displayname", ""); |
if ((fingerprint=get_self_fingerprint(context))==NULL) { |
goto cleanup; |
} |
self_addr_urlencoded = dc_urlencode(self_addr); |
self_name_urlencoded = dc_urlencode(self_name); |
if (group_chat_id) |
{ |
// parameters used: a=g=x=i=s= |
chat = dc_get_chat(context, group_chat_id); |
if (chat==NULL) { |
dc_log_error(context, 0, "Cannot get QR-code for chat-id %i", group_chat_id); |
goto cleanup; |
} |
group_name = dc_chat_get_name(chat); |
group_name_urlencoded = dc_urlencode(group_name); |
qr = dc_mprintf(DC_OPENPGP4FPR_SCHEME "%s#a=%s&g=%s&x=%s&i=%s&s=%s", fingerprint, self_addr_urlencoded, group_name_urlencoded, chat->grpid, invitenumber, auth); |
} |
else |
{ |
// parameters used: a=n=i=s= |
qr = dc_mprintf(DC_OPENPGP4FPR_SCHEME "%s#a=%s&n=%s&i=%s&s=%s", fingerprint, self_addr_urlencoded, self_name_urlencoded, invitenumber, auth); |
} |
dc_log_info(context, 0, "Generated QR code: %s", qr); |
cleanup: |
free(self_addr_urlencoded); |
free(self_addr); |
free(self_name); |
free(self_name_urlencoded); |
free(fingerprint); |
free(invitenumber); |
free(auth); |
dc_chat_unref(chat); |
free(group_name); |
free(group_name_urlencoded); |
return qr? qr : dc_strdup(NULL); |
} |
/** |
* Join an out-of-band-verification initiated on another device with dc_get_securejoin_qr(). |
* This function is typically called when dc_check_qr() returns |
* lot.state=DC_QR_ASK_VERIFYCONTACT or lot.state=DC_QR_ASK_VERIFYGROUP. |
* |
* This function takes some time and sends and receives several messages. |
* You should call it in a separate thread; if you want to abort it, you should |
* call dc_stop_ongoing_process(). |
* |
* @memberof dc_context_t |
* @param context The context object |
* @param qr The text of the scanned QR code. Typically, the same string as given |
* to dc_check_qr(). |
* @return Chat-id of the joined chat, the UI may redirect to the this chat. |
* If the out-of-band verification failed or was aborted, 0 is returned. |
*/ |
uint32_t dc_join_securejoin(dc_context_t* context, const char* qr) |
{ |
/* ========================================================== |
==== Bob - the joiner's side ===== |
==== Step 2 in "Setup verified contact" protocol ===== |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.