src/transport.c
author vb
Tue, 30 Dec 2014 13:04:17 +0100
changeset 39 66b5cc6cb987
parent 38 271bea5552dc
child 40 3e7aa2f67b7e
permissions -rw-r--r--
...
vb@28
     1
#include "pEp_internal.h"
vb@23
     2
vb@23
     3
#include <memory.h>
vb@23
     4
#include <assert.h>
vb@23
     5
vb@28
     6
PEP_STATUS init_transport_system(PEP_SESSION session)
vb@23
     7
{
vb@30
     8
    assert(session);
vb@30
     9
vb@28
    10
    pEpSession *_session = (pEpSession *) session;
vb@28
    11
    PEP_transport_t* transports = _session->transports;
vb@28
    12
vb@23
    13
    assert(PEP_trans__count == 1);
vb@23
    14
    memset(transports, 0, sizeof(PEP_transport_t) * PEP_trans__count);
vb@23
    15
vb@23
    16
    transports[0].id = PEP_trans_auto;
vb@23
    17
vb@23
    18
    return PEP_STATUS_OK;
vb@23
    19
}
vb@28
    20
vb@28
    21
void release_transport_system(PEP_SESSION session)
vb@28
    22
{
vb@30
    23
    assert(session);
vb@28
    24
    // nothing yet
vb@28
    25
}
vb@29
    26
vb@39
    27
identity_list *new_identity_list(pEp_identity *ident)
vb@29
    28
{
vb@29
    29
    identity_list *id_list = calloc(1, sizeof(identity_list));
vb@29
    30
    assert(id_list);
vb@29
    31
    if (id_list == NULL)
vb@29
    32
        return NULL;
vb@29
    33
vb@39
    34
    id_list->ident = ident;
vb@29
    35
vb@29
    36
    return id_list;
vb@29
    37
}
vb@29
    38
vb@37
    39
identity_list *identity_list_dup(const identity_list *src)
vb@37
    40
{
vb@37
    41
    assert(src);
vb@37
    42
vb@37
    43
    identity_list *id_list = new_identity_list(src->ident);
vb@37
    44
    assert(id_list);
vb@37
    45
    if (id_list == NULL)
vb@37
    46
        return NULL;
vb@37
    47
vb@37
    48
    if (src->next) {
vb@37
    49
        id_list->next = identity_list_dup(src->next);
vb@37
    50
        if (id_list->next == NULL) {
vb@37
    51
            free_identity_list(id_list);
vb@37
    52
            return NULL;
vb@37
    53
        }
vb@37
    54
    }
vb@37
    55
vb@37
    56
    return id_list;
vb@37
    57
}
vb@37
    58
vb@29
    59
void free_identity_list(identity_list *id_list)
vb@29
    60
{
vb@29
    61
    if (id_list) {
vb@29
    62
        free_identity_list(id_list->next);
vb@29
    63
        free_identity(id_list->ident);
vb@29
    64
        free(id_list);
vb@29
    65
    }
vb@29
    66
}
vb@29
    67
vb@39
    68
identity_list *identity_list_add(identity_list *id_list, pEp_identity *ident)
vb@29
    69
{
vb@29
    70
    assert(ident);
vb@29
    71
vb@38
    72
    if (id_list == NULL)
vb@38
    73
        return new_identity_list(ident);
vb@38
    74
vb@29
    75
    if (id_list->ident == NULL) {
vb@39
    76
        id_list->ident = ident;
vb@39
    77
        return id_list;
vb@29
    78
    }
vb@29
    79
    else if (id_list->next == NULL) {
vb@29
    80
        id_list->next = new_identity_list(ident);
vb@29
    81
        return id_list->next;
vb@29
    82
    }
vb@29
    83
    else {
vb@29
    84
        return identity_list_add(id_list->next, ident);
vb@29
    85
    }
vb@29
    86
}
vb@29
    87
vb@39
    88
bloblist_t *new_bloblist(char *blob, size_t size, const char *mime_type,
vb@39
    89
        const char *file_name)
vb@38
    90
{
vb@38
    91
    bloblist_t * bloblist = calloc(1, sizeof(bloblist_t));
vb@38
    92
    if (bloblist == NULL)
vb@38
    93
        return NULL;
vb@38
    94
    bloblist->data_ref = blob;
vb@38
    95
    bloblist->size = size;
vb@39
    96
    if (mime_type) {
vb@39
    97
        bloblist->mime_type = strdup(mime_type);
vb@39
    98
        if (bloblist->mime_type == NULL) {
vb@39
    99
            free(bloblist);
vb@39
   100
            return NULL;
vb@39
   101
        }
vb@39
   102
    }
vb@39
   103
    if (file_name) {
vb@39
   104
        bloblist->file_name = strdup(file_name);
vb@39
   105
        if (bloblist->file_name == NULL) {
vb@39
   106
            free(bloblist->mime_type);
vb@39
   107
            free(bloblist);
vb@39
   108
            return NULL;
vb@39
   109
        }
vb@39
   110
    }
vb@38
   111
    return bloblist;
vb@38
   112
}
vb@38
   113
vb@38
   114
bloblist_t *bloblist_dup(const bloblist_t *src)
vb@38
   115
{
vb@38
   116
    assert(src);
vb@38
   117
vb@38
   118
    if (src) {
vb@39
   119
        bloblist_t * dst = new_bloblist(src->data_ref, src->size,
vb@39
   120
                src->mime_type, src->file_name);
vb@38
   121
        if (dst == NULL)
vb@38
   122
            return NULL;
vb@38
   123
        dst->next = bloblist_dup(src->next);
vb@38
   124
        return dst;
vb@38
   125
    }
vb@38
   126
    else
vb@38
   127
        return NULL;
vb@38
   128
}
vb@38
   129
vb@38
   130
void free_bloblist(bloblist_t *bloblist)
vb@38
   131
{
vb@39
   132
    if (bloblist) {
vb@39
   133
        if (bloblist->next)
vb@39
   134
            free_bloblist(bloblist->next);
vb@39
   135
        if (bloblist->mime_type)
vb@39
   136
            free(bloblist->mime_type);
vb@39
   137
        if (bloblist->file_name)
vb@39
   138
            free(bloblist->file_name);
vb@39
   139
        free(bloblist);
vb@39
   140
    }
vb@38
   141
}
vb@38
   142
vb@39
   143
bloblist_t *bloblist_add(bloblist_t *bloblist, char *blob, size_t size,
vb@39
   144
        const char *mime_type, const char *file_name)
vb@38
   145
{
vb@38
   146
    assert(blob);
vb@38
   147
vb@38
   148
    if (bloblist == NULL)
vb@39
   149
        return new_bloblist(blob, size, mime_type, file_name);
vb@38
   150
vb@38
   151
    if (bloblist->data_ref == NULL) {
vb@38
   152
        bloblist->data_ref = blob;
vb@38
   153
        bloblist->size = size;
vb@39
   154
        if (mime_type) {
vb@39
   155
            bloblist->mime_type = strdup(mime_type);
vb@39
   156
            if (bloblist->mime_type == NULL) {
vb@39
   157
                free(bloblist);
vb@39
   158
                return NULL;
vb@39
   159
            }
vb@39
   160
        }
vb@39
   161
        if (file_name) {
vb@39
   162
            bloblist->file_name = strdup(file_name);
vb@39
   163
            if (bloblist->file_name == NULL) {
vb@39
   164
                free(bloblist->mime_type);
vb@39
   165
                free(bloblist);
vb@39
   166
                return NULL;
vb@39
   167
            }
vb@39
   168
        }
vb@38
   169
        return bloblist;
vb@38
   170
    }
vb@38
   171
vb@38
   172
    if (bloblist->next == NULL) {
vb@39
   173
        bloblist->next = new_bloblist(blob, size, mime_type, file_name);
vb@38
   174
        return bloblist->next;
vb@38
   175
    }
vb@38
   176
vb@39
   177
    return bloblist_add(bloblist->next, blob, size, mime_type, file_name);
vb@38
   178
}
vb@38
   179
vb@29
   180
message *new_message(
vb@38
   181
        PEP_msg_direction dir,
vb@39
   182
        pEp_identity *from,
vb@39
   183
        identity_list *to,
vb@29
   184
        const char *shortmsg
vb@29
   185
    )
vb@29
   186
{
vb@29
   187
    message *msg = calloc(1, sizeof(message));
vb@29
   188
    assert(msg);
vb@29
   189
    if (msg == NULL)
vb@29
   190
        return NULL;
vb@29
   191
vb@39
   192
    if (shortmsg) {
vb@37
   193
        msg->shortmsg = strdup(shortmsg);
vb@37
   194
        assert(msg->shortmsg);
vb@37
   195
        if (msg->shortmsg == NULL) {
vb@37
   196
            free(msg);
vb@37
   197
            return NULL;
vb@37
   198
        }
vb@29
   199
    }
vb@29
   200
vb@29
   201
    msg->dir = dir;
vb@39
   202
    msg->from = from;
vb@39
   203
    msg->to = to;
vb@29
   204
vb@29
   205
    return msg;
vb@29
   206
}
vb@29
   207
vb@29
   208
void free_message(message *msg)
vb@29
   209
{
vb@29
   210
    free(msg->id);
vb@29
   211
    free(msg->shortmsg);
vb@29
   212
    free(msg->longmsg);
vb@29
   213
    free(msg->longmsg_formatted);
vb@38
   214
    free_bloblist(msg->attachments);
vb@29
   215
    free_identity_list(msg->to);
vb@29
   216
    free_identity_list(msg->cc);
vb@29
   217
    free_identity_list(msg->bcc);
vb@29
   218
    free(msg->refering_id);
vb@29
   219
    free_message_ref_list(msg->refered_by);
vb@29
   220
    free(msg);
vb@29
   221
}
vb@29
   222
vb@29
   223
message_ref_list *new_message_ref_list(message *msg)
vb@29
   224
{
vb@29
   225
    message_ref_list *msg_list = calloc(1, sizeof(message_ref_list));
vb@29
   226
    assert(msg_list);
vb@29
   227
    if (msg_list == NULL)
vb@29
   228
        return NULL;
vb@29
   229
vb@29
   230
    msg_list->msg_ref = msg;
vb@29
   231
vb@29
   232
    return msg_list;
vb@29
   233
}
vb@29
   234
vb@29
   235
void free_message_ref_list(message_ref_list *msg_list)
vb@29
   236
{
vb@29
   237
    if (msg_list) {
vb@29
   238
        free_message_ref_list(msg_list->next);
vb@29
   239
        free(msg_list);
vb@29
   240
    }
vb@29
   241
}
vb@29
   242
vb@29
   243
message_ref_list *message_ref_list_add(message_ref_list *msg_list, message *msg)
vb@29
   244
{
vb@29
   245
    assert(msg);
vb@29
   246
vb@38
   247
    if (msg_list == NULL)
vb@38
   248
        return new_message_ref_list(msg);
vb@38
   249
vb@29
   250
    if (msg_list->msg_ref == NULL) {
vb@29
   251
        msg_list->msg_ref = msg;
vb@29
   252
        return msg_list;
vb@29
   253
    }
vb@29
   254
    else if (msg_list->next == NULL) {
vb@29
   255
        msg_list->next = new_message_ref_list(msg);
vb@29
   256
        assert(msg_list->next);
vb@29
   257
        return msg_list->next;
vb@29
   258
    }
vb@29
   259
    else {
vb@29
   260
        return message_ref_list_add(msg_list->next, msg);
vb@29
   261
    }
vb@29
   262
}
vb@29
   263