|
|
@ -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; |
|
|
|