Browse Source

streamline

doc_update_sequoia
Volker Birk 7 years ago
parent
commit
604ab22e65
6 changed files with 40 additions and 56 deletions
  1. +8
    -15
      src/bloblist.c
  2. +1
    -1
      src/bloblist.h
  3. +19
    -16
      src/message_api.c
  4. +4
    -4
      src/mime.c
  5. +4
    -10
      src/stringlist.c
  6. +4
    -10
      src/stringpair.c

+ 8
- 15
src/bloblist.c View File

@ -38,7 +38,7 @@ DYNAMIC_API bloblist_t *new_bloblist(char *blob, size_t size, const char *mime_t
return NULL;
}
bloblist->data = blob;
bloblist->value = blob;
bloblist->size = size;
}
@ -50,7 +50,7 @@ DYNAMIC_API void free_bloblist(bloblist_t *bloblist)
if (bloblist) {
if (bloblist->next)
free_bloblist(bloblist->next);
free(bloblist->data);
free(bloblist->value);
free(bloblist->mime_type);
free(bloblist->filename);
free(bloblist);
@ -68,7 +68,7 @@ DYNAMIC_API bloblist_t *bloblist_dup(const bloblist_t *src)
if (blob2 == NULL)
goto enomem;
memcpy(blob2, src->data, src->size);
memcpy(blob2, src->value, src->size);
blob2[src->size] = 0; // safeguard
bloblist = new_bloblist(blob2, src->size, src->mime_type, src->filename);
@ -98,7 +98,7 @@ DYNAMIC_API bloblist_t *bloblist_add(bloblist_t *bloblist, char *blob, size_t si
if (bloblist == NULL)
return new_bloblist(blob, size, mime_type, filename);
if (bloblist->data == NULL) {
if (bloblist->value == NULL) {
if (mime_type) {
bloblist->mime_type = strdup(mime_type);
if (bloblist->mime_type == NULL) {
@ -124,7 +124,7 @@ DYNAMIC_API bloblist_t *bloblist_add(bloblist_t *bloblist, char *blob, size_t si
}
blob[size] = 0; // safeguard
bloblist->data = blob;
bloblist->value = blob;
bloblist->size = size;
return bloblist;
@ -140,17 +140,10 @@ DYNAMIC_API bloblist_t *bloblist_add(bloblist_t *bloblist, char *blob, size_t si
DYNAMIC_API int bloblist_length(const bloblist_t *bloblist)
{
int len = 1;
bloblist_t *_bloblist;
int len = 0;
assert(bloblist);
if (bloblist->data == NULL)
return 0;
for (_bloblist = bloblist->next; _bloblist != NULL;
_bloblist = _bloblist->next)
len += 1;
for (bloblist_t *_bl = bloblist; _bl && _bl->value; _bl = _bl->next)
len++;
return len;
}

+ 1
- 1
src/bloblist.h View File

@ -8,7 +8,7 @@ extern "C" {
typedef struct _bloblist_t {
char *data; // blob
char *value; // blob
size_t size; // size of blob
char *mime_type; // UTF-8 string of MIME type of blob or
// NULL if unknown


+ 19
- 16
src/message_api.c View File

@ -59,23 +59,23 @@ void import_attached_keys(PEP_SESSION session, const message *msg)
assert(msg);
bloblist_t *bl;
for (bl = msg->attachments; bl && bl->data; bl = bl->next) {
assert(bl && bl->data && bl->size);
for (bl = msg->attachments; bl && bl->value; bl = bl->next) {
assert(bl && bl->value && bl->size);
if (bl->mime_type == NULL ||
is_mime_type(bl, "application/octet-stream")) {
if (is_fileending(bl, ".pgp") || is_fileending(bl, ".gpg") ||
is_fileending(bl, ".key") ||
string_equality(bl->filename, "key.asc"))
import_key(session, bl->data, bl->size);
import_key(session, bl->value, bl->size);
}
else if (is_mime_type(bl, "application/pgp-keys")) {
import_key(session, bl->data, bl->size);
import_key(session, bl->value, bl->size);
}
else if (is_mime_type(bl, "text/plain")) {
if (is_fileending(bl, ".pgp") || is_fileending(bl, ".gpg") ||
is_fileending(bl, ".key") || is_fileending(bl, ".asc"))
import_key(session, bl->data, bl->size);
import_key(session, bl->value, bl->size);
}
}
}
@ -136,7 +136,7 @@ PEP_cryptotech determine_encryption_format(message *msg)
}
else if (msg->attachments && msg->attachments->next &&
is_mime_type(msg->attachments, "application/pgp-encrypted") &&
is_PGP_message_text(msg->attachments->next->data)
is_PGP_message_text(msg->attachments->next->value)
) {
msg->enc_format = PEP_enc_PGP_MIME;
return PEP_crypt_OpenPGP;
@ -540,9 +540,9 @@ static PEP_STATUS encrypt_PGP_in_pieces(
bloblist_t *_s = src->attachments;
bloblist_t *_d = dst->attachments;
for (int n = 0; _s && _s->data; _s = _s->next) {
for (int n = 0; _s && _s->value; _s = _s->next) {
int psize = _s->size;
char *ptext = _s->data;
char *ptext = _s->value;
status = encrypt_and_sign(session, keys, ptext, psize, &ctext,
&csize);
if (ctext) {
@ -675,7 +675,12 @@ DYNAMIC_API PEP_STATUS encrypt_message(
}
}
if (dest_keys_found) {
if (!dest_keys_found) {
free_stringlist(keys);
attach_own_key(session, src);
return PEP_UNENCRYPTED;
}
else {
msg = clone_to_empty_message(src);
if (msg == NULL)
goto enomem;
@ -704,9 +709,6 @@ DYNAMIC_API PEP_STATUS encrypt_message(
goto pep_error;
}
}
else {
attach_own_key(session, src);
}
free_stringlist(keys);
@ -981,11 +983,12 @@ DYNAMIC_API PEP_STATUS decrypt_message(
switch (src->enc_format) {
case PEP_enc_none:
status = PEP_UNENCRYPTED;
break;
import_attached_keys(session, src);
*color = PEP_rating_unencrypted;
return PEP_UNENCRYPTED;
case PEP_enc_PGP_MIME:
ctext = src->attachments->next->data;
ctext = src->attachments->next->value;
csize = src->attachments->next->size;
status = cryptotech[crypto].decrypt_and_verify(session, ctext,
@ -1052,7 +1055,7 @@ DYNAMIC_API PEP_STATUS decrypt_message(
for (_s = src->attachments; _s; _s = _s->next) {
if (is_encrypted_attachment(_s)) {
stringlist_t *_keylist = NULL;
ctext = _s->data;
ctext = _s->value;
csize = _s->size;
status = decrypt_and_verify(session, ctext, csize,


+ 4
- 4
src/mime.c View File

@ -218,7 +218,7 @@ static PEP_STATUS mime_attachment(
else
mime_type = blob->mime_type;
mime = get_file_part(blob->filename, mime_type, blob->data, blob->size);
mime = get_file_part(blob->filename, mime_type, blob->value, blob->size);
assert(mime);
if (mime == NULL)
goto enomem;
@ -647,7 +647,7 @@ static PEP_STATUS mime_encode_message_plain(
bloblist_t *_a;
for (_a = msg->attachments; _a != NULL; _a = _a->next) {
assert(_a->data);
assert(_a->value);
assert(_a->size);
status = mime_attachment(_a, &submime);
@ -697,10 +697,10 @@ static PEP_STATUS mime_encode_message_PGP_MIME(
char *plaintext;
assert(msg->attachments && msg->attachments->next &&
msg->attachments->next->data);
msg->attachments->next->value);
subject = (msg->shortmsg) ? msg->shortmsg : "pEp";
plaintext = msg->attachments->next->data;
plaintext = msg->attachments->next->value;
mime = part_multiple_new("multipart/encrypted");
assert(mime);


+ 4
- 10
src/stringlist.c View File

@ -95,17 +95,11 @@ DYNAMIC_API stringlist_t *stringlist_append(
DYNAMIC_API int stringlist_length(const stringlist_t *stringlist)
{
int len = 1;
stringlist_t *_stringlist;
int len = 0;
assert(stringlist);
if (stringlist->value == NULL)
return 0;
for (_stringlist=stringlist->next; _stringlist!=NULL;
_stringlist=_stringlist->next)
len += 1;
const stringlist_t *_sl;
for (_sl = stringlist; _sl && _sl->value; _sl = _sl->next)
len++;
return len;
}


+ 4
- 10
src/stringpair.c View File

@ -133,17 +133,11 @@ DYNAMIC_API int stringpair_list_length(
const stringpair_list_t *stringpair_list
)
{
int len = 1;
stringpair_list_t *_stringpair_list;
int len = 0;
assert(stringpair_list);
if (stringpair_list->value == NULL)
return 0;
for (_stringpair_list=stringpair_list->next; _stringpair_list!=NULL;
_stringpair_list=_stringpair_list->next)
len += 1;
stringpair_list_t *_sl;
for (_sl = stringpair_list; _sl && _sl->value; _sl = _sl->next)
len++;
return len;
}


Loading…
Cancel
Save