Browse Source

opt_fields added with decrypt

doc_update_sequoia
Volker Birk 7 years ago
parent
commit
246568f3b4
7 changed files with 120 additions and 56 deletions
  1. +0
    -10
      src/message.c
  2. +91
    -10
      src/message_api.c
  3. +14
    -12
      src/mime.c
  4. +7
    -13
      src/stringpair.c
  5. +6
    -9
      src/stringpair.h
  6. +1
    -1
      test/message_api_test.cc
  7. +1
    -1
      test/mime_test.cc

+ 0
- 10
src/message.c View File

@ -31,16 +31,6 @@ DYNAMIC_API message *new_message(
msg->from = from;
msg->to = to;
stringpair_t version;
version.key = "X-pEp-Version";
version.value = PEP_VERSION;
msg->opt_fields = new_stringpair_list(&version);
if (msg->opt_fields == NULL) {
free_message(msg);
return NULL;
}
return msg;
}


+ 91
- 10
src/message_api.c View File

@ -534,7 +534,6 @@ DYNAMIC_API PEP_STATUS encrypt_message(
PEP_STATUS status = PEP_STATUS_OK;
message * msg = NULL;
stringlist_t * keys = NULL;
bool free_src = false;
assert(session);
assert(src);
@ -621,8 +620,6 @@ DYNAMIC_API PEP_STATUS encrypt_message(
}
free_stringlist(keys);
if (free_src)
free_message(src);
if (msg->shortmsg == NULL)
msg->shortmsg = strdup("pEp");
@ -636,8 +633,6 @@ enomem:
pep_error:
free_stringlist(keys);
free_message(msg);
if (free_src)
free_message(src);
return status;
}
@ -790,6 +785,96 @@ static PEP_color keylist_color(PEP_SESSION session, stringlist_t *keylist)
return color;
}
static void add_opt_field(message *msg, const char *name, const char *value)
{
assert(msg);
if (msg && name && value) {
stringpair_t *pair = new_stringpair(name, value);
if (pair == NULL)
return;
stringpair_list_t *field = stringpair_list_add(msg->opt_fields, pair);
if (field == NULL)
return;
if (msg->opt_fields == NULL)
msg->opt_fields = field;
}
}
static char * keylist_to_string(const stringlist_t *keylist)
{
if (keylist) {
size_t size = stringlist_length(keylist);
const stringlist_t *_kl;
for (_kl = keylist; _kl && _kl->value; _kl = _kl->next) {
size += strlen(_kl->value);
}
char *result = calloc(1, size);
if (result == NULL)
return NULL;
char *_r = result;
for (_kl = keylist; _kl && _kl->value; _kl = _kl->next) {
_r = stpcpy(_r, _kl->value);
if (_kl->next && _kl->next->value)
_r = stpcpy(_r, ",");
}
return result;
}
else {
return NULL;
}
}
static const char * color_to_string(PEP_color color)
{
switch (color) {
case PEP_rating_cannot_decrypt:
return "cannot_decrypt";
case PEP_rating_have_no_key:
return "have_no_key";
case PEP_rating_unencrypted:
return "unencrypted";
case PEP_rating_unreliable:
return "unreliable";
case PEP_rating_reliable:
return "reliable";
case PEP_rating_trusted:
return "trusted";
case PEP_rating_trusted_and_anonymized:
return "trusted_and_anonymized";
case PEP_rating_fully_anonymous:
return "fully_anonymous";
case PEP_rating_under_attack:
return "unter_attack";
case PEP_rating_b0rken:
return "b0rken";
default:
return "undefined";
}
}
static void decorate_message(
message *msg,
stringlist_t *keylist,
PEP_color color
)
{
assert(msg);
add_opt_field(msg, "X-pEp-Version", "1.0");
add_opt_field(msg, "X-EncStatus", color_to_string(color));
char *_keylist = keylist_to_string(keylist);
add_opt_field(msg, "X-KeyList", _keylist);
free(_keylist);
}
DYNAMIC_API PEP_STATUS decrypt_message(
PEP_SESSION session,
message *src,
@ -806,7 +891,6 @@ DYNAMIC_API PEP_STATUS decrypt_message(
char *ptext = NULL;
size_t psize;
stringlist_t *_keylist = NULL;
bool free_src = false;
assert(session);
assert(src);
@ -975,8 +1059,7 @@ DYNAMIC_API PEP_STATUS decrypt_message(
}
theend:
if (free_src)
free_message(src);
decorate_message(msg, _keylist, *color);
*dst = msg;
*keylist = _keylist;
@ -989,8 +1072,6 @@ enomem:
pep_error:
free_message(msg);
free_stringlist(_keylist);
if (free_src)
free_message(src);
return status;
}


+ 14
- 12
src/mime.c View File

@ -553,17 +553,19 @@ static PEP_STATUS build_fields(const message *msg, struct mailimf_fields **resul
if (msg->opt_fields) {
stringpair_list_t *_l;
for (_l = msg->opt_fields; _l; _l = _l->next) {
for (_l = msg->opt_fields; _l && _l->value; _l = _l->next) {
char *key = _l->value->key;
char *value = _l->value->value;
char *_value = mailmime_encode_subject_header("utf-8", value, 0);
if (_value == NULL)
goto enomem;
if (key && value) {
char *_value = mailmime_encode_subject_header("utf-8", value, 0);
if (_value == NULL)
goto enomem;
r = _append_optional_field(fields_list, key, _value);
free(_value);
if (r)
goto enomem;
r = _append_optional_field(fields_list, key, _value);
free(_value);
if (r)
goto enomem;
}
}
}
@ -1161,11 +1163,11 @@ static PEP_STATUS read_fields(message *msg, clist *fieldlist)
if (r)
goto enomem;
stringpair_t pair;
pair.key = name;
pair.value = _value;
stringpair_t *pair = new_stringpair(name, _value);
if (pair == NULL)
goto enomem;
opt = stringpair_list_add(opt, &pair);
opt = stringpair_list_add(opt, pair);
free(_value);
if (opt == NULL)
goto enomem;


+ 7
- 13
src/stringpair.c View File

@ -50,18 +50,13 @@ DYNAMIC_API stringpair_t * stringpair_dup(const stringpair_t *src)
return new_stringpair(src->key, src->value);
}
DYNAMIC_API stringpair_list_t *new_stringpair_list(const stringpair_t *value)
DYNAMIC_API stringpair_list_t *new_stringpair_list(stringpair_t *value)
{
stringpair_list_t *result = calloc(1, sizeof(stringpair_list_t));
assert(result);
if (result && value) {
result->value = stringpair_dup(value);
if (result->value == 0) {
free(result);
return NULL;
}
}
if (result && value)
result->value = value;
return result;
}
@ -91,7 +86,7 @@ DYNAMIC_API stringpair_list_t *stringpair_list_dup(
DYNAMIC_API stringpair_list_t *stringpair_list_add(
stringpair_list_t *stringpair_list,
const stringpair_t *value
stringpair_t *value
)
{
assert(value);
@ -99,12 +94,11 @@ DYNAMIC_API stringpair_list_t *stringpair_list_add(
if (stringpair_list == NULL)
return new_stringpair_list(value);
if (stringpair_list->next != NULL)
if (stringpair_list->next)
return stringpair_list_add(stringpair_list->next, value);
if (stringpair_list->value == NULL) {
stringpair_list->value = stringpair_dup(value);
if (stringpair_list->value == NULL)
return NULL;
stringpair_list->value = value;
return stringpair_list;
}


+ 6
- 9
src/stringpair.h View File

@ -56,17 +56,15 @@ typedef struct _stringpair_list_t {
// new_stringpair_list() - allocate a new stringpair_list
//
// parameters:
// value (in) initial value as C string or NULL for empty
// list
// value (in) initial value
//
// return value:
// pointer to stringpair_list_t object or NULL if out of memory
//
// caveat:
// the value is being copied before being added to the list
// the original value is still being owned by the caller
// the ownership of the value goes to the stringpair_list
DYNAMIC_API stringpair_list_t *new_stringpair_list(const stringpair_t *value);
DYNAMIC_API stringpair_list_t *new_stringpair_list(stringpair_t *value);
// stringpair_list_dup() - duplicate a stringpair_list
@ -87,18 +85,17 @@ DYNAMIC_API stringpair_list_t *stringpair_list_dup(
// parameters:
// stringpair_list (in) stringpair_list struct or NULL to create a new
// one
// value (in) value as C string
// value (in) stringpair to add
//
// return value:
// pointer to last element in stringpair_list or NULL if out of memory
//
// caveat:
// the value is being copied before being added to the list
// the original value is still being owned by the caller
// the ownership of the value goes to the stringpair_list
DYNAMIC_API stringpair_list_t *stringpair_list_add(
stringpair_list_t *stringpair_list,
const stringpair_t *value
stringpair_t *value
);


+ 1
- 1
test/message_api_test.cc View File

@ -54,7 +54,7 @@ int main() {
cout << text2 << "\n";
message *msg3;
PEP_STATUS status3 = mime_decode_message(text2, &msg3);
PEP_STATUS status3 = mime_decode_message(text2, strlen(text2), &msg3);
assert(status3 == PEP_STATUS_OK);
string string3 = text2;
free(text2);


+ 1
- 1
test/mime_test.cc View File

@ -26,7 +26,7 @@ void test_mime_decoding(string filename) {
cout << "decoding message…\n";
message *msg3;
PEP_STATUS status3 = mime_decode_message(mimetext3.c_str(), &msg3);
PEP_STATUS status3 = mime_decode_message(mimetext3.c_str(), mimetext3.length(), &msg3);
assert(status3 == PEP_STATUS_OK);
assert(msg3);
cout << "decoded.\n\n";


Loading…
Cancel
Save