doc_update_sequoia
vb 8 years ago
parent 41a37f7b91
commit 5186f7ccba

@ -1,3 +1,5 @@
#pragma once
#ifdef __cplusplus
extern "C" {
#endif

@ -4,6 +4,9 @@
#include <libetpan/libetpan.h>
#include <assert.h>
#include <string.h>
#include <stdlib.h>
#define NOT_IMPLEMENTED assert(0);
PEP_STATUS encrypt_message(
PEP_SESSION session,
@ -40,25 +43,30 @@ PEP_STATUS encrypt_message(
return PEP_OUT_OF_MEMORY;
}
stringlist_t *_x;
for (_x = extra; _x && _x->value; _x = _x->next) {
if (stringlist_add(keys, _x->value) == NULL) {
free_message(msg);
stringlist_t *_k = keys;
if (extra) {
_k = stringlist_append(_k, extra);
if (_k == NULL) {
free_stringlist(keys);
free_message(msg);
return PEP_OUT_OF_MEMORY;
}
}
bool dest_keys_found = false;
identity_list * _il;
for (_il = msg->to; _il && _il->ident; _il = _il->next) {
status = update_identity(session, _il->ident);
if (status != PEP_STATUS_OK) {
PEP_STATUS _status = update_identity(session, _il->ident);
if (_status != PEP_STATUS_OK) {
free_message(msg);
free_stringlist(keys);
return status;
return _status;
}
if (_il->ident->fpr) {
if (stringlist_add(keys, _il->ident->fpr) == NULL) {
dest_keys_found = true;
_k = stringlist_add(_k, _il->ident->fpr);
if (_k == NULL) {
free_message(msg);
free_stringlist(keys);
return PEP_OUT_OF_MEMORY;
@ -68,22 +76,20 @@ PEP_STATUS encrypt_message(
status = PEP_KEY_NOT_FOUND;
}
int _own_keys = 1;
if (extra)
_own_keys += stringlist_length(extra);
if (stringlist_length(keys) > _own_keys) {
if (dest_keys_found) {
char *ptext;
char *ctext = NULL;
size_t csize = 0;
switch (format) {
case PEP_enc_MIME_multipart:
NOT_IMPLEMENTED
break;
case PEP_enc_pieces:
if (src->shortmsg && src->longmsg) {
ptext = calloc(1, strlen(src->shortmsg) + strlen(src->longmsg) + 12);
ptext = calloc(1, strlen(src->shortmsg) + strlen(src->longmsg)
+ 12);
if (ptext == NULL) {
free_message(msg);
free_stringlist(keys);
@ -93,10 +99,10 @@ PEP_STATUS encrypt_message(
strcat(ptext, src->shortmsg);
strcat(ptext, "\n\n");
strcat(ptext, src->longmsg);
status = encrypt_and_sign(session, keys, ptext, strlen(ptext), &ctext, &csize);
status = encrypt_and_sign(session, keys, ptext, strlen(ptext),
&ctext, &csize);
if (ctext) {
msg->longmsg = ctext;
msg->longmsg_size = csize;
msg->shortmsg = strdup("pEp");
}
else {
@ -106,10 +112,10 @@ PEP_STATUS encrypt_message(
}
else if (src->shortmsg) {
ptext = src->shortmsg;
status = encrypt_and_sign(session, keys, ptext, strlen(ptext), &ctext, &csize);
status = encrypt_and_sign(session, keys, ptext, strlen(ptext),
&ctext, &csize);
if (ctext) {
msg->shortmsg = ctext;
msg->shortmsg_size = csize;
}
else {
free_message(msg);
@ -118,10 +124,10 @@ PEP_STATUS encrypt_message(
}
else if (src->longmsg) {
ptext = src->longmsg;
status = encrypt_and_sign(session, keys, ptext, strlen(ptext), &ctext, &csize);
status = encrypt_and_sign(session, keys, ptext, strlen(ptext),
&ctext, &csize);
if (ctext) {
msg->longmsg = ctext;
msg->longmsg_size = csize;
msg->shortmsg = strdup("pEp");
}
else {
@ -131,10 +137,10 @@ PEP_STATUS encrypt_message(
}
if (msg && msg->longmsg_formatted) {
ptext = src->longmsg_formatted;
status = encrypt_and_sign(session, keys, ptext, strlen(ptext), &ctext, &csize);
status = encrypt_and_sign(session, keys, ptext, strlen(ptext),
&ctext, &csize);
if (ctext) {
msg->longmsg_formatted = ctext;
msg->longmsg_formatted_size = csize;
}
else {
free_message(msg);
@ -143,7 +149,7 @@ PEP_STATUS encrypt_message(
}
if (msg) {
bloblist_t *_s;
bloblist_t *_d = new_bloblist(NULL, 0);
bloblist_t *_d = new_bloblist(NULL, 0, NULL, NULL);
if (_d == NULL) {
free_message(msg);
free_stringlist(keys);
@ -153,9 +159,16 @@ PEP_STATUS encrypt_message(
for (_s = src->attachments; _s && _s->data_ref; _s = _s->next) {
int psize = _s->size;
ptext = _s->data_ref;
status = encrypt_and_sign(session, keys, ptext, psize, &ctext, &csize);
status = encrypt_and_sign(session, keys, ptext, psize,
&ctext, &csize);
if (ctext) {
_d = bloblist_add(_d, ctext, csize);
_d = bloblist_add(_d, ctext, csize, _s->mime_type,
_s->file_name);
if (_d == NULL) {
free_message(msg);
free_stringlist(keys);
return PEP_OUT_OF_MEMORY;
}
}
else {
free_message(msg);
@ -163,6 +176,7 @@ PEP_STATUS encrypt_message(
break;
}
}
msg->enc_format = PEP_enc_pieces;
*dst = msg;
}
break;
@ -186,6 +200,8 @@ PEP_STATUS decrypt_message(
{
PEP_STATUS status = PEP_STATUS_OK;
NOT_IMPLEMENTED
return status;
}

@ -1,14 +1,25 @@
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
#include "transport.h"
typedef enum _PEP_enc_format {
PEP_enc_none = 0,
PEP_enc_MIME_multipart,
PEP_enc_pieces
} PEP_enc_format;
// encrypt_message() - encrypt message in memory
//
// parameters:
// session session handle
// src message to encrypt
// extra extra keys for encryption
// dst pointer to encrypted message or NULL on failure
// format encryption format
//
// return value:
// error status or PEP_STATUS_OK on success; PEP_KEY_NOT_FOUND if one
// or more keys couldn't be found, but the message could be encrypted
// with other keys
PEP_STATUS encrypt_message(
PEP_SESSION session,
@ -18,6 +29,17 @@ PEP_STATUS encrypt_message(
PEP_enc_format format
);
// decrypt_message() - decrypt message in memory
//
// parameters:
// session session handle
// src message to decrypt
// dst pointer to decrypted message or NULL on failure
//
// return value:
// error status or PEP_STATUS_OK on success
PEP_STATUS decrypt_message(
PEP_SESSION session,
const message *src,

@ -269,6 +269,27 @@ stringlist_t *new_stringlist(const char *value)
return result;
}
DYNAMIC_API stringlist_t *stringlist_dup(const stringlist_t *src)
{
assert(src);
if (src == NULL)
return NULL;
stringlist_t *dst = new_stringlist(src->value);
if (dst == NULL)
return NULL;
if (src->next) {
dst->next = stringlist_dup(src->next);
if (dst->next == NULL) {
free(dst);
return NULL;
}
}
return dst;
}
stringlist_t *stringlist_add(stringlist_t *stringlist, const char *value)
{
assert(value);
@ -294,6 +315,24 @@ stringlist_t *stringlist_add(stringlist_t *stringlist, const char *value)
return stringlist->next;
}
DYNAMIC_API stringlist_t *stringlist_append(stringlist_t *stringlist,
stringlist_t *second)
{
assert(stringlist);
if (second == NULL || second->value == NULL)
return stringlist;
stringlist_t *_s = stringlist;
stringlist_t *_s2;
for (_s2 = second; _s2 != NULL; _s2 = _s2->next) {
_s = stringlist_add(_s, _s2->value);
if (_s == NULL)
return NULL;
}
return _s;
}
int stringlist_length(const stringlist_t *stringlist)
{
int len = 1;

@ -126,6 +126,17 @@ typedef struct _stringlist_t {
DYNAMIC_API stringlist_t *new_stringlist(const char *value);
// stringlist_dup() - duplicate a stringlist
//
// parameters:
// src (in) stringlist to copy
//
// return value:
// pointer to stringlist_t object or NULL if out of memory
DYNAMIC_API stringlist_t *stringlist_dup(const stringlist_t *src);
// stringlist_add() - add key to stringlist
//
// parameters:
@ -142,6 +153,23 @@ DYNAMIC_API stringlist_t *new_stringlist(const char *value);
DYNAMIC_API stringlist_t *stringlist_add(stringlist_t *stringlist, const char *value);
// stringlist_append() - append stringlist to stringlist
//
// parameters:
// stringlist (in) stringlist struct to append to
// second (in) stringlist struct to append
//
// return value:
// pointer to last element in stringlist or NULL if out of memory
//
// caveat:
// all values are being copied before being added to the list
// the original values are still being owned by the caller
DYNAMIC_API stringlist_t *stringlist_append(stringlist_t *stringlist,
stringlist_t *second);
// stringlist_length() - get length of stringlist
//
// parameters:

@ -24,21 +24,14 @@ void release_transport_system(PEP_SESSION session)
// nothing yet
}
identity_list *new_identity_list(const pEp_identity *ident)
identity_list *new_identity_list(pEp_identity *ident)
{
identity_list *id_list = calloc(1, sizeof(identity_list));
assert(id_list);
if (id_list == NULL)
return NULL;
if (ident) {
id_list->ident = identity_dup(ident);
assert(id_list->ident);
if (id_list->ident == NULL) {
free(id_list);
return NULL;
}
}
id_list->ident = ident;
return id_list;
}
@ -72,7 +65,7 @@ void free_identity_list(identity_list *id_list)
}
}
identity_list *identity_list_add(identity_list *id_list, const pEp_identity *ident)
identity_list *identity_list_add(identity_list *id_list, pEp_identity *ident)
{
assert(ident);
@ -80,16 +73,11 @@ identity_list *identity_list_add(identity_list *id_list, const pEp_identity *ide
return new_identity_list(ident);
if (id_list->ident == NULL) {
id_list->ident = identity_dup(ident);
assert(id_list->ident);
if (id_list->ident == NULL)
return NULL;
else
return id_list;
id_list->ident = ident;
return id_list;
}
else if (id_list->next == NULL) {
id_list->next = new_identity_list(ident);
assert(id_list->next);
return id_list->next;
}
else {
@ -97,13 +85,29 @@ identity_list *identity_list_add(identity_list *id_list, const pEp_identity *ide
}
}
bloblist_t *new_bloblist(char *blob, size_t size)
bloblist_t *new_bloblist(char *blob, size_t size, const char *mime_type,
const char *file_name)
{
bloblist_t * bloblist = calloc(1, sizeof(bloblist_t));
if (bloblist == NULL)
return NULL;
bloblist->data_ref = blob;
bloblist->size = size;
if (mime_type) {
bloblist->mime_type = strdup(mime_type);
if (bloblist->mime_type == NULL) {
free(bloblist);
return NULL;
}
}
if (file_name) {
bloblist->file_name = strdup(file_name);
if (bloblist->file_name == NULL) {
free(bloblist->mime_type);
free(bloblist);
return NULL;
}
}
return bloblist;
}
@ -112,7 +116,8 @@ bloblist_t *bloblist_dup(const bloblist_t *src)
assert(src);
if (src) {
bloblist_t * dst = new_bloblist(src->data_ref, src->size);
bloblist_t * dst = new_bloblist(src->data_ref, src->size,
src->mime_type, src->file_name);
if (dst == NULL)
return NULL;
dst->next = bloblist_dup(src->next);
@ -124,36 +129,58 @@ bloblist_t *bloblist_dup(const bloblist_t *src)
void free_bloblist(bloblist_t *bloblist)
{
if (bloblist && bloblist->next)
free_bloblist(bloblist->next);
free(bloblist);
if (bloblist) {
if (bloblist->next)
free_bloblist(bloblist->next);
if (bloblist->mime_type)
free(bloblist->mime_type);
if (bloblist->file_name)
free(bloblist->file_name);
free(bloblist);
}
}
bloblist_t *bloblist_add(bloblist_t *bloblist, char *blob, size_t size)
bloblist_t *bloblist_add(bloblist_t *bloblist, char *blob, size_t size,
const char *mime_type, const char *file_name)
{
assert(blob);
if (bloblist == NULL)
return new_bloblist(blob, size);
return new_bloblist(blob, size, mime_type, file_name);
if (bloblist->data_ref == NULL) {
bloblist->data_ref = blob;
bloblist->size = size;
if (mime_type) {
bloblist->mime_type = strdup(mime_type);
if (bloblist->mime_type == NULL) {
free(bloblist);
return NULL;
}
}
if (file_name) {
bloblist->file_name = strdup(file_name);
if (bloblist->file_name == NULL) {
free(bloblist->mime_type);
free(bloblist);
return NULL;
}
}
return bloblist;
}
if (bloblist->next == NULL) {
bloblist->next = new_bloblist(blob, size);
bloblist->next = new_bloblist(blob, size, mime_type, file_name);
return bloblist->next;
}
return bloblist_add(bloblist->next, blob, size);
return bloblist_add(bloblist->next, blob, size, mime_type, file_name);
}
message *new_message(
PEP_msg_direction dir,
const pEp_identity *from,
const identity_list *to,
pEp_identity *from,
identity_list *to,
const char *shortmsg
)
{
@ -162,31 +189,18 @@ message *new_message(
if (msg == NULL)
return NULL;
if (msg->shortmsg) {
if (shortmsg) {
msg->shortmsg = strdup(shortmsg);
assert(msg->shortmsg);
if (msg->shortmsg == NULL) {
free(msg);
return NULL;
}
msg->shortmsg_size = strlen(msg->shortmsg);
}
msg->dir = dir;
msg->from = identity_dup(from);
assert(msg->from);
if (msg->from == NULL) {
free_message(msg);
return NULL;
}
msg->to = identity_list_dup(to);
assert(msg->to);
if (msg->to == NULL) {
free_message(msg);
return NULL;
}
msg->from = from;
msg->to = to;
return msg;
}
@ -198,7 +212,6 @@ void free_message(message *msg)
free(msg->longmsg);
free(msg->longmsg_formatted);
free_bloblist(msg->attachments);
free(msg->rawmsg);
free_identity_list(msg->to);
free_identity_list(msg->cc);
free_identity_list(msg->bcc);

@ -2,7 +2,6 @@
#include "pEpEngine.h"
#include <time.h>
#include <stdlib.h>
// all functions are using POSIX struct tm
@ -24,10 +23,57 @@ typedef struct _identity_list {
struct _identity_list *next;
} identity_list;
identity_list *new_identity_list(const pEp_identity *ident);
// new_identity_list() - allocate a new identity list
//
// parameters:
// ident identity to move for first element
//
// return value:
// new identity_list or NULL if out of memory
//
// caveat:
// ident is being moved, the caller loses ownership
identity_list *new_identity_list(pEp_identity *ident);
// identity_list_dup() - duplicate identity_list (deep copy)
//
// parameters:
// id_list identity_list to copy
//
// return value:
// new identity_list or NULL if out of memory
identity_list *identity_list_dup(const identity_list *src);
// free_identity_list() - free memory allocated by identity_list
//
// parameters:
// id_list identity_list to free
//
// caveat:
// this function frees all identities in the list additional to the
// identity_list itself
void free_identity_list(identity_list *id_list);
identity_list *identity_list_add(identity_list *id_list, const pEp_identity *ident);
// identity_list_add - add identity to an identity_list
//
// parameters:
// id_list identity_list to add to
// ident identity being added
//
// return value:
// pointer to the last element in identity_list or NULL if out of memory
//
// caveat:
// ident is being moved, the caller loses ownership
identity_list *identity_list_add(identity_list *id_list, pEp_identity *ident);
typedef enum _PEP_msg_format {
PEP_format_plain = 0,
@ -40,73 +86,210 @@ typedef enum _PEP_msg_direction {
} PEP_msg_direction;
typedef struct _bloblist_t {
char *data_ref;
size_t size;
char *data_ref; // reference to blob
size_t size; // size of blob
char *mime_type; // UTF-8 string of MIME type of blob or
// NULL if unknown
char *file_name; // UTF-8 string of file name of blob or
// NULL if unknown
struct _bloblist_t *next;
} bloblist_t;
bloblist_t *new_bloblist(char *blob, size_t size);
// new_bloblist() - allocate a new bloblist
//
// parameters:
// blob pointer to blob to add to the list
// size size of the blob
// mime_type MIME type of the blob data or NULL if unknown
// file_name file name of origin of blob data or NULL if unknown
//
// return value:
// pointer to new bloblist_t or NULL if out of memory
//
// caveat:
// the blob isn't copied, but only a reference is handled; the blob
// remains in the ownership of the caller and must not be deleted until
// the bloblist is deleted first; mime_type and file_name are being
// copied, the originals remain in the ownership of the caller
bloblist_t *new_bloblist(char *blob, size_t size, const char *mime_type,
const char *file_name);
// bloblist_dup() - duplicate bloblist (deep copy)
//
// paramters:
// src bloblist to duplicate
//
// return value:
// new bloblist or NULL if out of memory
//
// caveat:
// the blobs referenced by the lists aren't copied, so both bloblists
// reference the same blob data; mime_types and file_names are duplicated
// as well, though
bloblist_t *bloblist_dup(const bloblist_t *src);
// free_bloblist() - free bloblist
//
// parameters:
// bloblist bloblist to free
//
// caveat:
// the blobs in the bloblist aren't freed and remain in the ownership of
// the caller; all other data is being freed
void free_bloblist(bloblist_t *bloblist);
bloblist_t *bloblist_add(bloblist_t *bloblist, char *blob, size_t size);
// bloblist_add() - add reference to a blob to bloblist
//
// parameters:
// bloblist bloblist to add to
// blob reference to a blob
// size size of the blob
// mime_type MIME type of the blob or NULL if unknown
// file_name file name of the blob or NULL if unknown
//
// return value:
// pointer to the last element of bloblist or NULL if out of memory
//
// caveat:
// the blob isn't copied, instead a reference is added to bloblist;
// mime_type and file_name are copied, the originals remain in the
// ownership of the caller
bloblist_t *bloblist_add(bloblist_t *bloblist, char *blob, size_t size,
const char *mime_type, const char *file_name);
typedef enum _PEP_enc_format {
PEP_enc_none = 0,
PEP_enc_MIME_multipart,
PEP_enc_pieces
} PEP_enc_format;
struct _message_ref_list;
typedef struct _message {
PEP_msg_direction dir;
char * id;
size_t id_size;
char * shortmsg;
size_t shortmsg_size;
char * longmsg;
size_t longmsg_size;
char * longmsg_formatted;
size_t longmsg_formatted_size;
PEP_msg_format format;
bloblist_t * attachments;
char * rawmsg;
size_t rawmsg_size;
timestamp sent;
timestamp recv;
pEp_identity *from;
identity_list *to;
pEp_identity *recv_by;
identity_list *cc;
identity_list *bcc;
char * refering_id;
size_t refering_id_size;
struct _message *refering_msg;
struct _message_ref_list *refered_by;
bool encrypted;
char * id; // UTF-8 string of message ID
char * shortmsg; // UTF-8 string of short message
char * longmsg; // UTF-8 string of long message
// (plain)
char * longmsg_formatted; // UTF-8 string of long message
// (formatted)
PEP_msg_format format; // format type
bloblist_t * attachments; // blobs with attachements
char * rawmsg_ref; // reference to raw message data
size_t rawmsg_size; // size of raw message data
timestamp sent; // when the message is sent
timestamp recv; // when the message is received
pEp_identity *from; // whom the message is from
identity_list *to; // whom the message is to
pEp_identity *recv_by; // via which identity the message
// is received
identity_list *cc; // whom a CC is being sent
identity_list *bcc; // whom a BCC is being sent
char * refering_id; // UTF-8 string of refering message ID
struct _message *refering_msg_ref; // reference to refering message
struct _message_ref_list *refered_by; // list of references to messages being
// refered
PEP_enc_format enc_format; // format of encrypted data
} message;
typedef struct _message_ref_list {
message *msg_ref;
message *msg_ref; // reference to message
struct _message_ref_list *next;
} message_ref_list;
// new_message() - allocate new message
//
// parameters:
// dir PEP_dir_incoming or PEP_dir_outgoing
// from identity whom the message is from
// to identity list whom the message is sent to
// shortmsg UTF-8 string of short message
//
// return value:
// pointer to new message or NULL if out of memory
//
// caveat:
// from and to are moved into the message, the caller loses ownership for
// them; shortmsg is being copied, the ownership of the original remains
// with the caller
message *new_message(
PEP_msg_direction dir,
const pEp_identity *from,
const identity_list *to,
pEp_identity *from,
identity_list *to,
const char *shortmsg
);
// free_message() - free message struct
//
// parameters:
// msg message struct to free
//
// caveat:
// raw data as well as referenced other messages aren't freed and remain
// in the ownership of the caller
void free_message(message *msg);
// new_message_ref_list() - allocate new message reference list
//
// parameters:
// msg message to add a reference to or NULL
//
// return value:
// pointer to new message_ref_list or NULL if out of memory
message_ref_list *new_message_ref_list(message *msg);
// free_message_ref_list() - free message reference list
//
// parameters:
// msg_list message_ref_list to free
void free_message_ref_list(message_ref_list *msg_list);
message_ref_list *message_ref_list_add(message_ref_list *msg_list, message *msg);
// message_ref_list_add() - add a reference to a message to a message reference
// list
//
// parameters:
// msg_list message_ref_list to add to
// msg message to add a reference to
//
// return value:
// pointer to the last element of message_ref_list or NULL if out of
// memory
message_ref_list *message_ref_list_add(message_ref_list *msg_list,
message *msg);
typedef PEP_STATUS (*sendto_t)(PEP_SESSION session, const message *msg);
typedef PEP_STATUS (*readnext_t)(PEP_SESSION session, message **msg, PEP_transport_t **via);
typedef PEP_STATUS (*readnext_t)(PEP_SESSION session, message **msg,
PEP_transport_t **via);
struct _PEP_transport_t {
uint8_t id;
sendto_t sendto;
readnext_t readnext;
bool long_message_supported;
PEP_msg_format native_format;
uint8_t id; // transport ID
sendto_t sendto; // sendto function
readnext_t readnext; // readnext function
bool long_message_supported; // flag if this transport supports
// long messages
bool formatted_message_supported; // flag if this transport supports
// formatted messages
PEP_msg_format native_format; // native format of the transport
};
typedef uint64_t transports_mask;

@ -9,11 +9,12 @@ CXX=g++ -std=gnu++11 -DWIN32
LD=g++
LDFLAGS=-pthread -L../src -lpEpEngine -lstdc++
else
CC=g++ -std=gnu++11
CXX=g++ -std=gnu++11
LD=g++
LDFLAGS=-L~/lib -pthread -L../src -lpEpEngine -lstdc++
LDFLAGS=-L$(HOME)/lib -pthread -lpEpEngine -lstdc++
endif
CXXFLAGS=-g -O0
CXXFLAGS=-g -O0 -I../src
# CXXFLAGS=-O3 -DNDEBUG
TARGET=pEpEngineTest
@ -44,8 +45,11 @@ pEpEngine.dll: ../src/pEpEngine.dll
.PHONY: clean
clean:
rm -f *.o $(TARGET) *.exe *.a *~ pEpEngine.dll
rm -f *.o $(TARGET) *.exe *.a *~ pEpEngine.dll message_api_test
test: all
LD_LIBRARY_PATH=~/lib:../src ./pEpEngineTest
message_api_test: message_api_test.o
$(CXX) $(LDFLAGS) -o message_api_test message_api_test.o

@ -0,0 +1,28 @@
#include <iostream>
#include <assert.h>
#include "message_api.h"
using namespace std;
int main() {
PEP_SESSION session;
cout << "calling init()\n";
PEP_STATUS status1 = init(&session);
assert(status1 == PEP_STATUS_OK);
assert(session);
cout << "init() completed.\n";
pEp_identity * me = new_identity("outlooktest@dingens.org", NULL, "23", "Outlook Test");
me->me = true;
identity_list *to = new_identity_list(new_identity("vb@dingens.org", NULL, "42", "Volker Birk"));
message *msg = new_message(PEP_dir_outgoing, me, to, "hello, world");
free_message(msg);
cout << "calling release()\n";
release(session);
return 0;
}
Loading…
Cancel
Save