Browse Source

even more reorga

async_key_management
vb 7 years ago
parent
commit
cfc29e75c4
5 changed files with 456 additions and 438 deletions
  1. +278
    -0
      src/message.c
  2. +176
    -0
      src/message.h
  3. +1
    -1
      src/message_api.h
  4. +0
    -273
      src/transport.c
  5. +1
    -164
      src/transport.h

+ 278
- 0
src/message.c View File

@ -0,0 +1,278 @@
#include "pEp_internal.h"
#include <memory.h>
#include <assert.h>
DYNAMIC_API message *new_message(
PEP_msg_direction dir,
pEp_identity *from,
identity_list *to,
const char *shortmsg
)
{
message *msg = calloc(1, sizeof(message));
assert(msg);
if (msg == NULL)
return NULL;
if (shortmsg) {
msg->shortmsg = strdup(shortmsg);
assert(msg->shortmsg);
if (msg->shortmsg == NULL) {
free(msg);
return NULL;
}
}
msg->dir = dir;
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;
}
DYNAMIC_API void free_message(message *msg)
{
if (msg) {
free(msg->id);
free(msg->shortmsg);
free(msg->longmsg);
free(msg->longmsg_formatted);
free_bloblist(msg->attachments);
free(msg->sent);
free(msg->recv);
free_identity(msg->from);
free_identity_list(msg->to);
free_identity(msg->recv_by);
free_identity_list(msg->cc);
free_identity_list(msg->bcc);
free_identity_list(msg->reply_to);
free_stringlist(msg->in_reply_to);
free_stringlist(msg->references);
free_stringlist(msg->keywords);
free(msg->comments);
free_stringpair_list(msg->opt_fields);
free(msg);
}
}
DYNAMIC_API message * message_dup(const message *src)
{
message * msg = NULL;
pEp_identity * from = NULL;
identity_list * to = NULL;
assert(src);
from = identity_dup(src->from);
if (from == NULL)
goto enomem;
to = identity_list_dup(src->to);
if (to == NULL)
goto enomem;
msg = new_message(src->dir, from, to, src->shortmsg);
if (msg == NULL)
goto enomem;
if (src->id) {
msg->id = strdup(src->id);
assert(msg->id);
if (msg->id == NULL)
goto enomem;
}
if (src->longmsg) {
msg->longmsg = strdup(src->longmsg);
assert(msg->longmsg);
if (msg->longmsg == NULL)
goto enomem;
}
if (src->longmsg_formatted) {
msg->longmsg_formatted = strdup(src->longmsg_formatted);
assert(msg->longmsg_formatted);
if (msg->longmsg_formatted == NULL)
goto enomem;
}
if (src->attachments) {
msg->attachments = bloblist_dup(src->attachments);
if (msg->attachments == NULL)
goto enomem;
}
msg->rawmsg_ref = src->rawmsg_ref;
msg->rawmsg_size = src->rawmsg_size;
if (src->sent) {
msg->sent = malloc(sizeof(timestamp));
if (msg->sent == NULL)
goto enomem;
memcpy(msg->sent, src->sent, sizeof(timestamp));
}
if (src->recv) {
msg->recv = malloc(sizeof(timestamp));
if (msg->recv == NULL)
goto enomem;
memcpy(msg->recv, src->recv, sizeof(timestamp));
}
if (src->recv_by) {
msg->recv_by = identity_dup(src->recv_by);
if (msg->recv_by == NULL)
goto enomem;
}
if (src->cc) {
msg->cc = identity_list_dup(src->cc);
if (msg->cc == NULL)
goto enomem;
}
if (src->bcc) {
msg->bcc = identity_list_dup(src->bcc);
if (msg->bcc == NULL)
goto enomem;
}
if (src->reply_to) {
msg->reply_to = identity_list_dup(src->reply_to);
if (msg->reply_to == NULL)
goto enomem;
}
if (src->in_reply_to) {
msg->in_reply_to = stringlist_dup(src->in_reply_to);
assert(msg->in_reply_to);
if (msg->in_reply_to == NULL)
goto enomem;
}
msg->refering_msg_ref = src->refering_msg_ref;
if (src->references) {
msg->references = stringlist_dup(src->references);
if (msg->references == NULL)
goto enomem;
}
if (src->refered_by) {
msg->refered_by = message_ref_list_dup(src->refered_by);
if (msg->refered_by == NULL)
goto enomem;
}
if (src->keywords) {
msg->keywords = stringlist_dup(src->keywords);
if (msg->keywords == NULL)
goto enomem;
}
if (src->comments) {
msg->comments = strdup(src->comments);
assert(msg->comments);
if (msg->comments == NULL)
goto enomem;
}
if (src->opt_fields) {
msg->opt_fields = stringpair_list_dup(src->opt_fields);
if (msg->opt_fields == NULL)
goto enomem;
}
msg->enc_format = src->enc_format;
return msg;
enomem:
if (msg) {
free_message(msg);
}
else {
free_identity(from);
free_identity_list(to);
}
return NULL;
}
DYNAMIC_API message_ref_list *new_message_ref_list(message *msg)
{
message_ref_list *msg_list = calloc(1, sizeof(message_ref_list));
assert(msg_list);
if (msg_list == NULL)
return NULL;
msg_list->msg_ref = msg;
return msg_list;
}
DYNAMIC_API void free_message_ref_list(message_ref_list *msg_list)
{
if (msg_list) {
free_message_ref_list(msg_list->next);
free(msg_list);
}
}
DYNAMIC_API message_ref_list *message_ref_list_dup(
const message_ref_list *src
)
{
message_ref_list * msg_list = NULL;
assert(src);
msg_list = new_message_ref_list(src->msg_ref);
if (msg_list == NULL)
goto enomem;
if (src->next) {
msg_list->next = message_ref_list_dup(src->next);
if (msg_list->next == NULL)
goto enomem;
}
return msg_list;
enomem:
free_message_ref_list(msg_list);
return NULL;
}
DYNAMIC_API message_ref_list *message_ref_list_add(message_ref_list *msg_list, message *msg)
{
assert(msg);
if (msg_list == NULL)
return new_message_ref_list(msg);
if (msg_list->msg_ref == NULL) {
msg_list->msg_ref = msg;
return msg_list;
}
else if (msg_list->next == NULL) {
msg_list->next = new_message_ref_list(msg);
assert(msg_list->next);
return msg_list->next;
}
else {
return message_ref_list_add(msg_list->next, msg);
}
}

+ 176
- 0
src/message.h View File

@ -0,0 +1,176 @@
#pragma once
#include <time.h>
#include "pEpEngine.h"
#include "identity_list.h"
#include "bloblist.h"
#include "stringpair.h"
#ifdef __cplusplus
extern "C" {
#endif
// for time values all functions are using POSIX struct tm
typedef struct tm timestamp;
typedef enum _PEP_text_format {
PEP_text_format_plain = 0,
PEP_text_format_html,
PEP_text_format_other = 0xff
} PEP_text_format;
typedef enum _PEP_msg_direction {
PEP_dir_incoming = 0,
PEP_dir_outgoing
} PEP_msg_direction;
typedef enum _PEP_enc_format {
PEP_enc_none = 0, // message is in pieces and nor
// encoded nor encrypted
PEP_enc_none_MIME, // message is MIME encoded but not
// encrypted
PEP_enc_pieces, // message is encrypted but not
// MIME encoded
PEP_enc_MIME_multipart, // message is encrypted and MIME
// encoded; this is being used for
// PGP/MIME as well as S/MIME
PEP_enc_PEP // pEp encryption format
} PEP_enc_format;
struct _message_ref_list;
typedef struct _message {
PEP_msg_direction dir;
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)
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
identity_list *reply_to; // where a reply should go to
stringlist_t *in_reply_to; // list of UTF-8 strings with
// MessageIDs ofrefering messages
struct _message *refering_msg_ref; // reference to refering message
stringlist_t *references; // list of UTF-8 strings with references
struct _message_ref_list *refered_by; // list of references to messages being
// refered
stringlist_t *keywords; // list of UTF-8 strings with keywords
char *comments; // UTF-8 string with comments
stringpair_list_t *opt_fields; // optional fields
PEP_enc_format enc_format; // format of encrypted data
} message;
typedef struct _message_ref_list {
message *msg_ref; // reference to message
struct _message_ref_list *next;
} message_ref_list;
// new_message() - allocate new message
//
// parameters:
// dir (in) PEP_dir_incoming or PEP_dir_outgoing
// from (in) identity whom the message is from
// to (in) identity list whom the message is sent to
// shortmsg (in) 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
DYNAMIC_API message *new_message(
PEP_msg_direction dir,
pEp_identity *from,
identity_list *to,
const char *shortmsg
);
// free_message() - free message struct
//
// parameters:
// src (in) message struct to free
//
// caveat:
// raw data as well as referenced other messages aren't freed and remain
// in the ownership of the caller
DYNAMIC_API void free_message(message *src);
// message_dup - duplicate message (deep copy)
//
// parameters:
// msg (in) message to duplicate
//
// return value:
// pointer to duplicate of message pointed by msg or NULL
DYNAMIC_API message * message_dup(const message *msg);
// new_message_ref_list() - allocate new message reference list
//
// parameters:
// msg (in) message to add a reference to or NULL
//
// return value:
// pointer to new message_ref_list or NULL if out of memory
DYNAMIC_API message_ref_list *new_message_ref_list(message *msg);
// free_message_ref_list() - free message reference list
//
// parameters:
// msg_list (in) message_ref_list to free
DYNAMIC_API void free_message_ref_list(message_ref_list *msg_list);
// message_ref_list_dup() - duplicate message reference list
//
// paramters:
// src (in) message_ref_list to duplicate
//
// return value:
// pointer to new message_ref_list or NULL if out of memory
DYNAMIC_API message_ref_list *message_ref_list_dup(
const message_ref_list *src
);
// message_ref_list_add() - add a reference to a message to a message reference
// list
//
// parameters:
// msg_list (in) message_ref_list to add to
// msg (in) message to add a reference to
//
// return value:
// pointer to the last element of message_ref_list or NULL if out of
// memory
DYNAMIC_API message_ref_list *message_ref_list_add(message_ref_list *msg_list,
message *msg);
#ifdef __cplusplus
}
#endif

+ 1
- 1
src/message_api.h View File

@ -4,7 +4,7 @@
extern "C" {
#endif
#include "transport.h"
#include "message.h"
// encrypt_message() - encrypt message in memory


+ 0
- 273
src/transport.c View File

@ -29,276 +29,3 @@ DYNAMIC_API void release_transport_system(PEP_SESSION session, bool out_last)
// nothing yet
}
DYNAMIC_API message *new_message(
PEP_msg_direction dir,
pEp_identity *from,
identity_list *to,
const char *shortmsg
)
{
message *msg = calloc(1, sizeof(message));
assert(msg);
if (msg == NULL)
return NULL;
if (shortmsg) {
msg->shortmsg = strdup(shortmsg);
assert(msg->shortmsg);
if (msg->shortmsg == NULL) {
free(msg);
return NULL;
}
}
msg->dir = dir;
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;
}
DYNAMIC_API void free_message(message *msg)
{
if (msg) {
free(msg->id);
free(msg->shortmsg);
free(msg->longmsg);
free(msg->longmsg_formatted);
free_bloblist(msg->attachments);
free(msg->sent);
free(msg->recv);
free_identity(msg->from);
free_identity_list(msg->to);
free_identity(msg->recv_by);
free_identity_list(msg->cc);
free_identity_list(msg->bcc);
free_identity_list(msg->reply_to);
free_stringlist(msg->in_reply_to);
free_stringlist(msg->references);
free_stringlist(msg->keywords);
free(msg->comments);
free_stringpair_list(msg->opt_fields);
free(msg);
}
}
DYNAMIC_API message * message_dup(const message *src)
{
message * msg = NULL;
pEp_identity * from = NULL;
identity_list * to = NULL;
assert(src);
from = identity_dup(src->from);
if (from == NULL)
goto enomem;
to = identity_list_dup(src->to);
if (to == NULL)
goto enomem;
msg = new_message(src->dir, from, to, src->shortmsg);
if (msg == NULL)
goto enomem;
if (src->id) {
msg->id = strdup(src->id);
assert(msg->id);
if (msg->id == NULL)
goto enomem;
}
if (src->longmsg) {
msg->longmsg = strdup(src->longmsg);
assert(msg->longmsg);
if (msg->longmsg == NULL)
goto enomem;
}
if (src->longmsg_formatted) {
msg->longmsg_formatted = strdup(src->longmsg_formatted);
assert(msg->longmsg_formatted);
if (msg->longmsg_formatted == NULL)
goto enomem;
}
if (src->attachments) {
msg->attachments = bloblist_dup(src->attachments);
if (msg->attachments == NULL)
goto enomem;
}
msg->rawmsg_ref = src->rawmsg_ref;
msg->rawmsg_size = src->rawmsg_size;
if (src->sent) {
msg->sent = malloc(sizeof(timestamp));
if (msg->sent == NULL)
goto enomem;
memcpy(msg->sent, src->sent, sizeof(timestamp));
}
if (src->recv) {
msg->recv = malloc(sizeof(timestamp));
if (msg->recv == NULL)
goto enomem;
memcpy(msg->recv, src->recv, sizeof(timestamp));
}
if (src->recv_by) {
msg->recv_by = identity_dup(src->recv_by);
if (msg->recv_by == NULL)
goto enomem;
}
if (src->cc) {
msg->cc = identity_list_dup(src->cc);
if (msg->cc == NULL)
goto enomem;
}
if (src->bcc) {
msg->bcc = identity_list_dup(src->bcc);
if (msg->bcc == NULL)
goto enomem;
}
if (src->reply_to) {
msg->reply_to = identity_list_dup(src->reply_to);
if (msg->reply_to == NULL)
goto enomem;
}
if (src->in_reply_to) {
msg->in_reply_to = stringlist_dup(src->in_reply_to);
assert(msg->in_reply_to);
if (msg->in_reply_to == NULL)
goto enomem;
}
msg->refering_msg_ref = src->refering_msg_ref;
if (src->references) {
msg->references = stringlist_dup(src->references);
if (msg->references == NULL)
goto enomem;
}
if (src->refered_by) {
msg->refered_by = message_ref_list_dup(src->refered_by);
if (msg->refered_by == NULL)
goto enomem;
}
if (src->keywords) {
msg->keywords = stringlist_dup(src->keywords);
if (msg->keywords == NULL)
goto enomem;
}
if (src->comments) {
msg->comments = strdup(src->comments);
assert(msg->comments);
if (msg->comments == NULL)
goto enomem;
}
if (src->opt_fields) {
msg->opt_fields = stringpair_list_dup(src->opt_fields);
if (msg->opt_fields == NULL)
goto enomem;
}
msg->enc_format = src->enc_format;
return msg;
enomem:
if (msg) {
free_message(msg);
}
else {
free_identity(from);
free_identity_list(to);
}
return NULL;
}
DYNAMIC_API message_ref_list *new_message_ref_list(message *msg)
{
message_ref_list *msg_list = calloc(1, sizeof(message_ref_list));
assert(msg_list);
if (msg_list == NULL)
return NULL;
msg_list->msg_ref = msg;
return msg_list;
}
DYNAMIC_API void free_message_ref_list(message_ref_list *msg_list)
{
if (msg_list) {
free_message_ref_list(msg_list->next);
free(msg_list);
}
}
DYNAMIC_API message_ref_list *message_ref_list_dup(
const message_ref_list *src
)
{
message_ref_list * msg_list = NULL;
assert(src);
msg_list = new_message_ref_list(src->msg_ref);
if (msg_list == NULL)
goto enomem;
if (src->next) {
msg_list->next = message_ref_list_dup(src->next);
if (msg_list->next == NULL)
goto enomem;
}
return msg_list;
enomem:
free_message_ref_list(msg_list);
return NULL;
}
DYNAMIC_API message_ref_list *message_ref_list_add(message_ref_list *msg_list, message *msg)
{
assert(msg);
if (msg_list == NULL)
return new_message_ref_list(msg);
if (msg_list->msg_ref == NULL) {
msg_list->msg_ref = msg;
return msg_list;
}
else if (msg_list->next == NULL) {
msg_list->next = new_message_ref_list(msg);
assert(msg_list->next);
return msg_list->next;
}
else {
return message_ref_list_add(msg_list->next, msg);
}
}

+ 1
- 164
src/transport.h View File

@ -1,19 +1,12 @@
#pragma once
#include <time.h>
#include "pEpEngine.h"
#include "identity_list.h"
#include "bloblist.h"
#include "stringpair.h"
#include "message.h"
#ifdef __cplusplus
extern "C" {
#endif
// for time values all functions are using POSIX struct tm
typedef struct tm timestamp;
typedef enum _PEP_transports {
// auto transport chooses transport per message automatically
PEP_trans_auto = 0,
@ -25,162 +18,6 @@ typedef enum _PEP_transports {
typedef struct _PEP_transport_t PEP_transport_t;
typedef enum _PEP_text_format {
PEP_text_format_plain = 0,
PEP_text_format_html,
PEP_text_format_other = 0xff
} PEP_text_format;
typedef enum _PEP_msg_direction {
PEP_dir_incoming = 0,
PEP_dir_outgoing
} PEP_msg_direction;
typedef enum _PEP_enc_format {
PEP_enc_none = 0, // message is in pieces and nor
// encoded nor encrypted
PEP_enc_none_MIME, // message is MIME encoded but not
// encrypted
PEP_enc_pieces, // message is encrypted but not
// MIME encoded
PEP_enc_MIME_multipart, // message is encrypted and MIME
// encoded; this is being used for
// PGP/MIME as well as S/MIME
PEP_enc_PEP // pEp encryption format
} PEP_enc_format;
struct _message_ref_list;
typedef struct _message {
PEP_msg_direction dir;
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)
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
identity_list *reply_to; // where a reply should go to
stringlist_t *in_reply_to; // list of UTF-8 strings with
// MessageIDs ofrefering messages
struct _message *refering_msg_ref; // reference to refering message
stringlist_t *references; // list of UTF-8 strings with references
struct _message_ref_list *refered_by; // list of references to messages being
// refered
stringlist_t *keywords; // list of UTF-8 strings with keywords
char *comments; // UTF-8 string with comments
stringpair_list_t *opt_fields; // optional fields
PEP_enc_format enc_format; // format of encrypted data
} message;
typedef struct _message_ref_list {
message *msg_ref; // reference to message
struct _message_ref_list *next;
} message_ref_list;
// new_message() - allocate new message
//
// parameters:
// dir (in) PEP_dir_incoming or PEP_dir_outgoing
// from (in) identity whom the message is from
// to (in) identity list whom the message is sent to
// shortmsg (in) 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
DYNAMIC_API message *new_message(
PEP_msg_direction dir,
pEp_identity *from,
identity_list *to,
const char *shortmsg
);
// free_message() - free message struct
//
// parameters:
// src (in) message struct to free
//
// caveat:
// raw data as well as referenced other messages aren't freed and remain
// in the ownership of the caller
DYNAMIC_API void free_message(message *src);
// message_dup - duplicate message (deep copy)
//
// parameters:
// msg (in) message to duplicate
//
// return value:
// pointer to duplicate of message pointed by msg or NULL
DYNAMIC_API message * message_dup(const message *msg);
// new_message_ref_list() - allocate new message reference list
//
// parameters:
// msg (in) message to add a reference to or NULL
//
// return value:
// pointer to new message_ref_list or NULL if out of memory
DYNAMIC_API message_ref_list *new_message_ref_list(message *msg);
// free_message_ref_list() - free message reference list
//
// parameters:
// msg_list (in) message_ref_list to free
DYNAMIC_API void free_message_ref_list(message_ref_list *msg_list);
// message_ref_list_dup() - duplicate message reference list
//
// paramters:
// src (in) message_ref_list to duplicate
//
// return value:
// pointer to new message_ref_list or NULL if out of memory
DYNAMIC_API message_ref_list *message_ref_list_dup(
const message_ref_list *src
);
// message_ref_list_add() - add a reference to a message to a message reference
// list
//
// parameters:
// msg_list (in) message_ref_list to add to
// msg (in) message to add a reference to
//
// return value:
// pointer to the last element of message_ref_list or NULL if out of
// memory
DYNAMIC_API 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);


Loading…
Cancel
Save