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