text stringlengths 0 357 |
|---|
{ |
if (value==NULL) { |
return 0; /* attribute with no value results in an invalid header */ |
} |
if (strcasecmp(value, "1")==0 || strcasecmp(value, "0" /*deprecated*/)==0 || strcasecmp(value, "p" /*deprecated*/)==0) { |
return 1; /* PGP-type */ |
} |
return 0; /* unknown types result in an invalid header */ |
} |
#endif |
else if (strcasecmp(name, "prefer-encrypt")==0) |
{ |
if (value && strcasecmp(value, "mutual")==0) { |
aheader->prefer_encrypt = DC_PE_MUTUAL; |
return 1; |
} |
return 1; /* An Autocrypt level 0 client that sees the attribute with any other value (or that does not see the attribute at all) should interpret the value as nopreference.*/ |
} |
else if (strcasecmp(name, "keydata")==0) |
{ |
if (value==NULL |
|| aheader->public_key->binary || aheader->public_key->bytes) { |
return 0; /* there is already a k*/ |
} |
return dc_key_set_from_base64(aheader->public_key, value, DC_KEY_PUBLIC); |
} |
else if (name[0]=='_') |
{ |
/* Autocrypt-Level0: unknown attributes starting with an underscore can be safely ignored */ |
return 1; |
} |
/* Autocrypt-Level0: unknown attribute, treat the header as invalid */ |
return 0; |
} |
/** |
* @memberof dc_aheader_t |
*/ |
int dc_aheader_set_from_string(dc_aheader_t* aheader, const char* header_str__) |
{ |
/* according to RFC 5322 (Internet Message Format), the given string may contain `\r\n` before any whitespace. |
we can ignore this issue as |
(a) no key or value is expected to contain spaces, |
(b) for the key, non-base64-characters are ignored and |
(c) for parsing, we ignore `\r\n` as well as tabs for spaces */ |
#define AHEADER_WS "\t\r\n " |
char* header_str = NULL; |
char* p = NULL; |
char* beg_attr_name = NULL; |
char* after_attr_name = NULL; |
char* beg_attr_value = NULL; |
int success = 0; |
dc_aheader_empty(aheader); |
if (aheader==NULL || header_str__==NULL) { |
goto cleanup; |
} |
aheader->prefer_encrypt = DC_PE_NOPREFERENCE; /* value to use if the prefer-encrypted header is missing */ |
header_str = dc_strdup(header_str__); |
p = header_str; |
while (*p) |
{ |
p += strspn(p, AHEADER_WS "=;"); /* forward to first attribute name beginning */ |
beg_attr_name = p; |
beg_attr_value = NULL; |
p += strcspn(p, AHEADER_WS "=;"); /* get end of attribute name (an attribute may have no value) */ |
if (p!=beg_attr_name) |
{ |
/* attribute found */ |
after_attr_name = p; |
p += strspn(p, AHEADER_WS); /* skip whitespace between attribute name and possible `=` */ |
if (*p=='=') |
{ |
p += strspn(p, AHEADER_WS "="); /* skip spaces and equal signs */ |
/* read unquoted attribute value until the first semicolon */ |
beg_attr_value = p; |
p += strcspn(p, ";"); |
if (*p!='\0') { |
*p = '\0'; |
p++; |
} |
dc_trim(beg_attr_value); |
} |
else |
{ |
p += strspn(p, AHEADER_WS ";"); |
} |
*after_attr_name = '\0'; |
if (!add_attribute(aheader, beg_attr_name, beg_attr_value)) { |
goto cleanup; /* a bad attribute makes the whole header invalid */ |
} |
} |
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.