src/message.h
author buff <andreas@pep-project.org>
Fri, 22 Jan 2021 12:26:53 +0100
branchIOSAD-186
changeset 5279 eef5d0a66d7d
parent 5246 67016f508d40
permissions -rw-r--r--
merge Release_2.1.11
     1 // This file is under GNU General Public License 3.0
     2 // see LICENSE.txt
     3 
     4 #ifndef MESSAGE_H
     5 #define MESSAGE_H
     6 
     7 #include <time.h>
     8 
     9 #include "pEpEngine.h"
    10 #include "identity_list.h"
    11 #include "bloblist.h"
    12 #include "stringlist.h"
    13 #include "stringpair.h"
    14 #include "timestamp.h"
    15 
    16 #ifdef __cplusplus
    17 extern "C" {
    18 #endif
    19 
    20 
    21 typedef enum _PEP_text_format {
    22     PEP_text_format_plain = 0,
    23     PEP_text_format_html,
    24     PEP_text_format_other = 0xff
    25 } PEP_text_format;
    26 
    27 typedef enum _PEP_msg_direction {
    28     PEP_dir_incoming = 0,
    29     PEP_dir_outgoing
    30 } PEP_msg_direction;
    31 
    32 struct _message_ref_list;
    33 
    34 typedef struct _message {
    35     PEP_msg_direction dir;
    36     char *id;                               // UTF-8 string of message ID
    37     char *shortmsg;                         // UTF-8 string of short message
    38     char *longmsg;                          // UTF-8 string of long message
    39                                             // (plain)
    40     char *longmsg_formatted;                // UTF-8 string of long message
    41                                             // (formatted)
    42     bloblist_t *attachments;                // blobs with attachements
    43     char *rawmsg_ref;                       // reference to raw message data
    44     size_t rawmsg_size;                     // size of raw message data
    45     timestamp *sent;                        // when the message is sent
    46     timestamp *recv;                        // when the message is received
    47     pEp_identity *from;                     // whom the message is from
    48     identity_list *to;                      // whom the message is to
    49     pEp_identity *recv_by;                  // via which identity the message
    50                                             // is received
    51     identity_list *cc;                      // whom a CC is being sent
    52     identity_list *bcc;                     // whom a BCC is being sent
    53     identity_list *reply_to;                // where a reply should go to
    54     stringlist_t *in_reply_to;              // list of UTF-8 strings with
    55                                             // MessageIDs of refering messages
    56     struct _message *refering_msg_ref;      // reference to refering message
    57     stringlist_t *references;               // list of UTF-8 strings with references
    58     struct _message_ref_list *refered_by;   // list of references to messages being
    59                                             // refered
    60     stringlist_t *keywords;                 // list of UTF-8 strings with keywords
    61     char *comments;                         // UTF-8 string with comments
    62     stringpair_list_t *opt_fields;          // optional fields
    63     PEP_enc_format enc_format;              // format of encrypted data
    64     char* _sender_fpr;                      // INTERNAL USE ONLY - fingerprint of 
    65                                             // sending signer.
    66                                             // (read_only to the outside)
    67 } message;
    68 
    69 typedef struct _message_ref_list {
    70     message *msg_ref;                       // reference to message
    71     struct _message_ref_list *next;
    72 } message_ref_list;
    73 
    74 // new_message() - allocate new message
    75 //
    76 //  parameters:
    77 //      dir (in)        PEP_dir_incoming or PEP_dir_outgoing
    78 //
    79 //  return value:
    80 //      pointer to new message or NULL if out of memory
    81 
    82 DYNAMIC_API message *new_message(
    83         PEP_msg_direction dir
    84     );
    85 
    86 
    87 // free_message() - free message struct
    88 //
    89 //  parameters:
    90 //      msg (in)        message struct to free
    91 //
    92 //  NOTA BENE:
    93 //      raw data (msg->rawmsg_ref) and referenced other messages (msg->refering_msg_ref)
    94 //      aren't freed and remain in the ownership of the caller!
    95 
    96 DYNAMIC_API void free_message(message *msg);
    97 
    98 
    99 // message_dup - duplicate message (deep copy)
   100 //
   101 //  parameters:
   102 //      msg (in)        message to duplicate
   103 //
   104 //  return value:
   105 //      pointer to duplicate of message pointed by msg or NULL
   106 //  NOTA BENE:
   107 //      not owned pointees (msg->rawmsg_ref and msg->refering_msg_ref) are shared!
   108 
   109 DYNAMIC_API message * message_dup(const message *msg);
   110 
   111 // message_transfer - assign ownership of all fields of the src message to
   112 //                    the dst message object passed in. Free respective memory
   113 //                    in the dst message, and reinitialise and pointers in 
   114 //                    the src message to NULL so that it can be freed properly
   115 //                    by its owner.
   116 //  parameters:
   117 //      dst (inout)        message to clobber and reassign values to
   118 //      src (inout)        message whose values will be transfered to dst
   119 //  NOTA BENE:
   120 //      not owned pointees (msg->rawmsg_ref and msg->refering_msg_ref) are shared!
   121 //      these are simply transferred.
   122 DYNAMIC_API void message_transfer(message* dst, message *src);
   123 
   124 
   125 // new_message_ref_list() - allocate new message reference list
   126 //
   127 //  parameters:
   128 //      msg (in)        message to add a reference to or NULL
   129 //
   130 //  return value:
   131 //      pointer to new message_ref_list or NULL if out of memory
   132 
   133 DYNAMIC_API message_ref_list *new_message_ref_list(message *msg);
   134 
   135 
   136 // free_message_ref_list() - free message reference list
   137 //
   138 //  parameters:
   139 //      msg_list (in)   message_ref_list to free
   140 
   141 DYNAMIC_API void free_message_ref_list(message_ref_list *msg_list);
   142 
   143 
   144 // message_ref_list_dup() - duplicate message reference list
   145 //
   146 //  paramters:
   147 //      src (in)        message_ref_list to duplicate
   148 //
   149 //  return value:
   150 //      pointer to new message_ref_list or NULL if out of memory
   151 
   152 DYNAMIC_API message_ref_list *message_ref_list_dup(
   153         const message_ref_list *src
   154     );
   155 
   156 // message_ref_list_add() - add a reference to a message to a message reference
   157 // list
   158 //
   159 //  parameters:
   160 //      msg_list (in)   message_ref_list to add to
   161 //      msg (in)        message to add a reference to
   162 //
   163 //  return value:
   164 //      pointer to the last element of message_ref_list or NULL if out of
   165 //      memory
   166 
   167 DYNAMIC_API message_ref_list *message_ref_list_add(message_ref_list *msg_list,
   168         message *msg);
   169 
   170 
   171 #ifdef __cplusplus
   172 }
   173 #endif
   174 
   175 #endif