src/transport.c
changeset 81 044ce1c7fc9c
parent 76 6da29caa5dae
child 89 aef5a4bc78f3
     1.1 --- a/src/transport.c	Sun Mar 01 01:07:35 2015 +0100
     1.2 +++ b/src/transport.c	Sun Mar 01 15:32:16 2015 +0100
     1.3 @@ -94,8 +94,10 @@
     1.4          const char *file_name)
     1.5  {
     1.6      bloblist_t * bloblist = calloc(1, sizeof(bloblist_t));
     1.7 +    assert(bloblist);
     1.8      if (bloblist == NULL)
     1.9          return NULL;
    1.10 +
    1.11      if (mime_type) {
    1.12          bloblist->mime_type = strdup(mime_type);
    1.13          if (bloblist->mime_type == NULL) {
    1.14 @@ -103,6 +105,7 @@
    1.15              return NULL;
    1.16          }
    1.17      }
    1.18 +
    1.19      if (file_name) {
    1.20          bloblist->file_name = strdup(file_name);
    1.21          if (bloblist->file_name == NULL) {
    1.22 @@ -111,8 +114,10 @@
    1.23              return NULL;
    1.24          }
    1.25      }
    1.26 +
    1.27      bloblist->data = blob;
    1.28      bloblist->size = size;
    1.29 +
    1.30      return bloblist;
    1.31  }
    1.32  
    1.33 @@ -128,6 +133,29 @@
    1.34      }
    1.35  }
    1.36  
    1.37 +DYNAMIC_API bloblist_t *bloblist_dup(const bloblist_t *src)
    1.38 +{
    1.39 +    bloblist_t *bloblist = NULL;
    1.40 +
    1.41 +    assert(src);
    1.42 +
    1.43 +    bloblist = new_bloblist(src->data, src->size, src->mime_type, src->file_name);
    1.44 +    if (bloblist == NULL)
    1.45 +        goto enomem;
    1.46 +
    1.47 +    if (src->next) {
    1.48 +        bloblist->next = bloblist_dup(src->next);
    1.49 +        if (bloblist->next == NULL)
    1.50 +            goto enomem;
    1.51 +    }
    1.52 +
    1.53 +    return bloblist;
    1.54 +
    1.55 +enomem:
    1.56 +    free_bloblist(bloblist);
    1.57 +    return NULL;
    1.58 +}
    1.59 +
    1.60  DYNAMIC_API bloblist_t *bloblist_add(bloblist_t *bloblist, char *blob, size_t size,
    1.61          const char *mime_type, const char *file_name)
    1.62  {
    1.63 @@ -206,12 +234,119 @@
    1.64          free_identity(msg->recv_by);
    1.65          free_identity_list(msg->cc);
    1.66          free_identity_list(msg->bcc);
    1.67 +        free_identity(msg->reply_to);
    1.68          free(msg->refering_id);
    1.69 -        free_message_ref_list(msg->refered_by);
    1.70          free(msg);
    1.71      }
    1.72  }
    1.73  
    1.74 +DYNAMIC_API message * message_dup(const message *src)
    1.75 +{
    1.76 +    message * msg = NULL;
    1.77 +    pEp_identity * from = NULL;
    1.78 +    identity_list * to = NULL;
    1.79 +
    1.80 +    assert(src);
    1.81 +
    1.82 +    from = identity_dup(src->from);
    1.83 +    if (from == NULL)
    1.84 +        goto enomem;
    1.85 +
    1.86 +    to = identity_list_dup(src->to);
    1.87 +    if (to == NULL)
    1.88 +        goto enomem;
    1.89 +
    1.90 +    msg = new_message(src->dir, from, to, src->shortmsg);
    1.91 +    if (msg == NULL)
    1.92 +        goto enomem;
    1.93 +
    1.94 +    if (src->id) {
    1.95 +        msg->id = strdup(src->id);
    1.96 +        assert(msg->id);
    1.97 +        if (msg->id == NULL)
    1.98 +            goto enomem;
    1.99 +    }
   1.100 +
   1.101 +    if (src->longmsg) {
   1.102 +        msg->longmsg = strdup(src->longmsg);
   1.103 +        assert(msg->longmsg);
   1.104 +        if (msg->longmsg == NULL)
   1.105 +            goto enomem;
   1.106 +    }
   1.107 +    
   1.108 +    if (src->longmsg_formatted) {
   1.109 +        msg->longmsg_formatted = strdup(src->longmsg_formatted);
   1.110 +        assert(msg->longmsg_formatted);
   1.111 +        if (msg->longmsg_formatted == NULL)
   1.112 +            goto enomem;
   1.113 +    }
   1.114 +
   1.115 +    if (src->attachments) {
   1.116 +        msg->attachments = bloblist_dup(src->attachments);
   1.117 +        if (msg->attachments == NULL)
   1.118 +            goto enomem;
   1.119 +    }
   1.120 +
   1.121 +    msg->rawmsg_ref = src->rawmsg_ref;
   1.122 +    msg->rawmsg_size = src->rawmsg_size;
   1.123 +    msg->sent = src->sent;
   1.124 +    msg->recv = src->recv;
   1.125 +
   1.126 +    if (src->recv_by) {
   1.127 +        msg->recv_by = identity_dup(src->recv_by);
   1.128 +        if (msg->recv_by == NULL)
   1.129 +            goto enomem;
   1.130 +    }
   1.131 +
   1.132 +    if (src->cc) {
   1.133 +        msg->cc = identity_list_dup(src->cc);
   1.134 +        if (msg->cc == NULL)
   1.135 +            goto enomem;
   1.136 +    }
   1.137 +
   1.138 +    if (src->bcc) {
   1.139 +        msg->bcc = identity_list_dup(src->bcc);
   1.140 +        if (msg->bcc == NULL)
   1.141 +            goto enomem;
   1.142 +    }
   1.143 +
   1.144 +    if (src->reply_to) {
   1.145 +        msg->reply_to = identity_dup(src->reply_to);
   1.146 +        if (msg->reply_to == NULL)
   1.147 +            goto enomem;
   1.148 +    }
   1.149 +
   1.150 +    if (src->refering_id) {
   1.151 +        msg->refering_id = strdup(src->refering_id);
   1.152 +        assert(msg->refering_id);
   1.153 +        if (msg->refering_id == NULL)
   1.154 +            goto enomem;
   1.155 +    }
   1.156 +
   1.157 +    msg->refering_msg_ref = src->refering_msg_ref;
   1.158 +    
   1.159 +    if (src->refered_by) {
   1.160 +        msg->refered_by = message_ref_list_dup(src->refered_by);
   1.161 +        if (msg->refered_by == NULL)
   1.162 +            goto enomem;
   1.163 +    }
   1.164 +
   1.165 +    msg->enc_format = src->enc_format;
   1.166 +
   1.167 +    return msg;
   1.168 +
   1.169 +enomem:
   1.170 +    if (msg) {
   1.171 +        free_message(msg);
   1.172 +    }
   1.173 +    else {
   1.174 +        free_identity(from);
   1.175 +        free_identity_list(to);
   1.176 +    }
   1.177 +
   1.178 +    return NULL;
   1.179 +}
   1.180 +
   1.181  DYNAMIC_API message_ref_list *new_message_ref_list(message *msg)
   1.182  {
   1.183      message_ref_list *msg_list = calloc(1, sizeof(message_ref_list));
   1.184 @@ -232,6 +367,31 @@
   1.185      }
   1.186  }
   1.187  
   1.188 +DYNAMIC_API message_ref_list *message_ref_list_dup(
   1.189 +        const message_ref_list *src
   1.190 +    )
   1.191 +{
   1.192 +    message_ref_list * msg_list = NULL;
   1.193 +
   1.194 +    assert(src);
   1.195 +
   1.196 +    msg_list = new_message_ref_list(src->msg_ref);
   1.197 +    if (msg_list == NULL)
   1.198 +        goto enomem;
   1.199 +
   1.200 +    if (src->next) {
   1.201 +        msg_list->next = message_ref_list_dup(src->next);
   1.202 +        if (msg_list->next == NULL)
   1.203 +            goto enomem;
   1.204 +    }
   1.205 +
   1.206 +    return msg_list;
   1.207 +
   1.208 +enomem:
   1.209 +    free_message_ref_list(msg_list);
   1.210 +    return NULL;
   1.211 +}
   1.212 +
   1.213  DYNAMIC_API message_ref_list *message_ref_list_add(message_ref_list *msg_list, message *msg)
   1.214  {
   1.215      assert(msg);