text stringlengths 0 357 |
|---|
return success; |
} |
/** |
* If the fingerprint of the peerstate equals the given fingerprint, the |
* peerstate is marked as being verified. |
* |
* The given fingerprint is present only to ensure the peer has not changed |
* between fingerprint comparison and calling this function. |
* |
* @memberof dc_apeerstate_t |
* @param peerstate The peerstate object. |
* @param which_key Which key should be marked as being verified? DC_PS_GOSSIP_KEY (1) or DC_PS_PUBLIC_KEY (2) |
* @param fingerprint Fingerprint expected in the object |
* @param verified DC_BIDIRECT_VERIFIED (2): contact verified in both directions |
* @return 1=the given fingerprint is equal to the peer's fingerprint and |
* the verified-state is set; you should call dc_apeerstate_save_to_db() |
* to permanently store this state. |
* 0=the given fingerprint is not eqial to the peer's fingerprint, |
* verified-state not changed. |
*/ |
int dc_apeerstate_set_verified(dc_apeerstate_t* peerstate, int which_key, const char* fingerprint, int verified) |
{ |
int success = 0; |
if (peerstate==NULL |
|| (which_key!=DC_PS_GOSSIP_KEY && which_key!=DC_PS_PUBLIC_KEY) |
|| (verified!=DC_BIDIRECT_VERIFIED)) { |
goto cleanup; |
} |
if (which_key==DC_PS_PUBLIC_KEY |
&& peerstate->public_key_fingerprint!=NULL |
&& peerstate->public_key_fingerprint[0]!=0 |
&& fingerprint[0]!=0 |
&& strcasecmp(peerstate->public_key_fingerprint, fingerprint)==0) |
{ |
peerstate->to_save |= DC_SAVE_ALL; |
peerstate->verified_key = dc_key_ref(peerstate->public_key); |
peerstate->verified_key_fingerprint = dc_strdup(peerstate->public_key_fingerprint); |
success = 1; |
} |
if (which_key==DC_PS_GOSSIP_KEY |
&& peerstate->gossip_key_fingerprint!=NULL |
&& peerstate->gossip_key_fingerprint[0]!=0 |
&& fingerprint[0]!=0 |
&& strcasecmp(peerstate->gossip_key_fingerprint, fingerprint)==0) |
{ |
peerstate->to_save |= DC_SAVE_ALL; |
peerstate->verified_key = dc_key_ref(peerstate->gossip_key); |
peerstate->verified_key_fingerprint = dc_strdup(peerstate->gossip_key_fingerprint); |
success = 1; |
} |
cleanup: |
return success; |
} |
int dc_apeerstate_has_verified_key(const dc_apeerstate_t* peerstate, const dc_hash_t* fingerprints) |
{ |
if (peerstate==NULL || fingerprints==NULL) { |
return 0; |
} |
if (peerstate->verified_key |
&& peerstate->verified_key_fingerprint |
&& dc_hash_find_str(fingerprints, peerstate->verified_key_fingerprint)) { |
return 1; |
} |
return 0; |
} |
``` |
Filename: dc_array.c |
```c |
#include "dc_context.h" |
#include "dc_array.h" |
#define DC_ARRAY_MAGIC 0x000a11aa |
/** |
* Create an array object in memory. |
* |
* @private @memberof dc_array_t |
* @param context The context object that should be stored in the array object. May be NULL. |
* @param type 0 for a standard array of int or one of DC_ARRAY_*. |
* @param initsize Initial maximal size of the array. If you add more items, the internal data pointer is reallocated. |
* @return New array object of the requested size, the data should be set directly. |
*/ |
dc_array_t* dc_array_new_typed(dc_context_t* context, int type, size_t initsize) |
{ |
dc_array_t* array = NULL; |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.