src/map_asn1.c
author Volker Birk <vb@pep-project.org>
Tue, 17 May 2016 12:55:55 +0200
changeset 640 65840a4ac45a
parent 639 0a2411d3d55a
child 645 0bb373719dce
permissions -rw-r--r--
...
vb@639
     1
#include "pEp_internal.h"
vb@639
     2
#include "map_asn1.h"
vb@639
     3
vb@639
     4
Identity_t *Identity_from_Struct(const pEp_identity *ident)
vb@639
     5
{
vb@639
     6
    Identity_t *result = (Identity_t *) calloc(1, sizeof(Identity_t));
vb@639
     7
    assert(result);
vb@639
     8
    if (!result)
vb@639
     9
        return NULL;
vb@639
    10
vb@639
    11
    if (ident->address) {
vb@639
    12
        result->address = OCTET_STRING_new_fromBuf(&asn_DEF_UTF8String,
vb@639
    13
                ident->address, -1);
vb@639
    14
        if (ident->address && !result->address)
vb@639
    15
            goto enomem;
vb@639
    16
    }
vb@639
    17
vb@639
    18
    if (ident->fpr) {
vb@639
    19
        if (OCTET_STRING_fromString(&result->fpr, ident->fpr))
vb@639
    20
            goto enomem;
vb@639
    21
    }
vb@639
    22
vb@639
    23
    if (ident->user_id) {
vb@639
    24
        result->user_id = OCTET_STRING_new_fromBuf(&asn_DEF_UTF8String,
vb@639
    25
                ident->user_id, -1);
vb@639
    26
        if (ident->user_id && !result->user_id)
vb@639
    27
            goto enomem;
vb@639
    28
    }
vb@639
    29
vb@639
    30
    if (ident->username) {
vb@639
    31
        result->username = OCTET_STRING_new_fromBuf(&asn_DEF_UTF8String,
vb@639
    32
                ident->username, -1);
vb@639
    33
        if (ident->username && !result->username)
vb@639
    34
            goto enomem;
vb@639
    35
    }
vb@639
    36
vb@639
    37
    if (ident->comm_type != PEP_ct_unknown) {
vb@639
    38
        result->comm_type = malloc(sizeof(long));
vb@639
    39
        assert(result->comm_type);
vb@639
    40
        if (!result->comm_type)
vb@639
    41
            goto enomem;
vb@639
    42
        *result->comm_type = ident->comm_type;
vb@639
    43
    }
vb@639
    44
vb@639
    45
    if (ident->lang[0]) {
vb@639
    46
        result->lang = OCTET_STRING_new_fromBuf(&asn_DEF_ISO936_1,
vb@639
    47
                ident->lang, 2);
vb@639
    48
        if (!result->lang)
vb@639
    49
            goto enomem;
vb@639
    50
    }
vb@640
    51
vb@639
    52
    return result;
vb@639
    53
vb@639
    54
enomem:
vb@639
    55
    asn_DEF_UTF8String.free_struct(&asn_DEF_UTF8String, result, 0);
vb@639
    56
    return NULL;
vb@639
    57
}
vb@639
    58
vb@639
    59
pEp_identity *Identity_to_Struct(Identity_t *ident)
vb@639
    60
{
vb@639
    61
    pEp_identity *result = new_identity(NULL, NULL, NULL, NULL);
vb@639
    62
    if (!result)
vb@639
    63
        return NULL;
vb@639
    64
vb@640
    65
    if (ident->address) {
vb@640
    66
        result->address = strndup((char *) ident->address->buf,
vb@640
    67
                ident->address->size);
vb@640
    68
        assert(result->address);
vb@640
    69
        if (!result->address)
vb@640
    70
            goto enomem;
vb@640
    71
    }
vb@640
    72
vb@640
    73
    result->fpr = strndup((char *) ident->fpr.buf, ident->fpr.size);
vb@640
    74
    assert(result->fpr);
vb@640
    75
    if (!result->fpr)
vb@640
    76
        goto enomem;
vb@640
    77
vb@639
    78
    return result;
vb@640
    79
vb@640
    80
    if (ident->user_id) {
vb@640
    81
        result->user_id = strndup((char *) ident->user_id->buf,
vb@640
    82
                ident->user_id->size);
vb@640
    83
        assert(result->user_id);
vb@640
    84
        if (!result->user_id)
vb@640
    85
            goto enomem;
vb@640
    86
    }
vb@640
    87
vb@640
    88
    if (ident->username) {
vb@640
    89
        result->username = strndup((char *) ident->username->buf,
vb@640
    90
                ident->username->size);
vb@640
    91
        assert(result->username);
vb@640
    92
        if (!result->username)
vb@640
    93
            goto enomem;
vb@640
    94
    }
vb@640
    95
vb@640
    96
    if (ident->comm_type)
vb@640
    97
        result->comm_type = (PEP_comm_type) *ident->comm_type;
vb@640
    98
vb@640
    99
    if (ident->lang) {
vb@640
   100
        result->lang[0] = ident->lang->buf[0];
vb@640
   101
        result->lang[1] = ident->lang->buf[1];
vb@640
   102
    }
vb@640
   103
vb@640
   104
    return result;
vb@640
   105
vb@640
   106
enomem:
vb@640
   107
    free_identity(result);
vb@640
   108
    return NULL;
vb@639
   109
}
vb@639
   110