merge default into my branch roker-linux
authorRoker <roker@pep-project.org>
Mon, 18 Jul 2016 08:54:43 +0200
branchroker-linux
changeset 90579bfd4454dac
parent 878 9ab0833d2c8b
parent 904 a3c701c6109f
child 916 b01eb9f041ff
merge default into my branch
     1.1 --- a/asn.1/pEpEngineASN1/pEpEngineASN1.vcxproj	Thu Jul 14 15:18:27 2016 +0200
     1.2 +++ b/asn.1/pEpEngineASN1/pEpEngineASN1.vcxproj	Mon Jul 18 08:54:43 2016 +0200
     1.3 @@ -60,14 +60,24 @@
     1.4        <GenerateDebugInformation>true</GenerateDebugInformation>
     1.5      </Link>
     1.6      <PreBuildEvent>
     1.7 +      <Command>
     1.8 +      </Command>
     1.9 +    </PreBuildEvent>
    1.10 +    <PreBuildEvent>
    1.11 +      <Message>ASN.1 source generation</Message>
    1.12 +    </PreBuildEvent>
    1.13 +    <CustomBuildStep>
    1.14        <Command>cd ..
    1.15  asn1c -gen-PER -fincludes-quoted -fcompound-names -pdu=PEP.Message pEp.asn1 devicegroup.asn1
    1.16  del converter-sample.c
    1.17  </Command>
    1.18 -    </PreBuildEvent>
    1.19 -    <PreBuildEvent>
    1.20 -      <Message>ASN.1 source generation</Message>
    1.21 -    </PreBuildEvent>
    1.22 +    </CustomBuildStep>
    1.23 +    <CustomBuildStep>
    1.24 +      <Message>compiling ASN.1 description</Message>
    1.25 +    </CustomBuildStep>
    1.26 +    <CustomBuildStep>
    1.27 +      <Outputs>$(ProjectDir)..\DeviceGroup-Protocol.c;%(Outputs)</Outputs>
    1.28 +    </CustomBuildStep>
    1.29    </ItemDefinitionGroup>
    1.30    <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
    1.31      <ClCompile>
    1.32 @@ -86,11 +96,21 @@
    1.33        <OptimizeReferences>true</OptimizeReferences>
    1.34      </Link>
    1.35      <PreBuildEvent>
    1.36 +      <Command>
    1.37 +      </Command>
    1.38 +    </PreBuildEvent>
    1.39 +    <CustomBuildStep>
    1.40        <Command>cd ..
    1.41  asn1c -gen-PER -fincludes-quoted -fcompound-names -pdu=PEP.Message pEp.asn1 devicegroup.asn1
    1.42  del converter-sample.c
    1.43  </Command>
    1.44 -    </PreBuildEvent>
    1.45 +    </CustomBuildStep>
    1.46 +    <CustomBuildStep>
    1.47 +      <Message>compiling ASN.1 description</Message>
    1.48 +    </CustomBuildStep>
    1.49 +    <CustomBuildStep>
    1.50 +      <Outputs>$(ProjectDir)..\DeviceGroup-Protocol.c;%(Outputs)</Outputs>
    1.51 +    </CustomBuildStep>
    1.52    </ItemDefinitionGroup>
    1.53    <ItemGroup>
    1.54      <Text Include="ReadMe.txt" />
     2.1 --- a/pEpEngine.vcxproj	Thu Jul 14 15:18:27 2016 +0200
     2.2 +++ b/pEpEngine.vcxproj	Mon Jul 18 08:54:43 2016 +0200
     2.3 @@ -116,6 +116,7 @@
     2.4      <ClCompile Include="src\sync_actions.c" />
     2.5      <ClCompile Include="src\sync_driver.c" />
     2.6      <ClCompile Include="src\sync_fsm.c" />
     2.7 +    <ClCompile Include="src\sync_send_actions.c" />
     2.8      <ClCompile Include="src\timestamp.c" />
     2.9      <ClCompile Include="src\transport.c" />
    2.10      <ClCompile Include="src\trans_auto.c" />
     3.1 --- a/pEpEngine.vcxproj.filters	Thu Jul 14 15:18:27 2016 +0200
     3.2 +++ b/pEpEngine.vcxproj.filters	Mon Jul 18 08:54:43 2016 +0200
     3.3 @@ -90,6 +90,9 @@
     3.4      <ClCompile Include="src\baseprotocol.c">
     3.5        <Filter>Quelldateien</Filter>
     3.6      </ClCompile>
     3.7 +    <ClCompile Include="src\sync_send_actions.c">
     3.8 +      <Filter>Quelldateien</Filter>
     3.9 +    </ClCompile>
    3.10    </ItemGroup>
    3.11    <ItemGroup>
    3.12      <ClInclude Include="src\keymanagement.h">
     4.1 --- a/src/bloblist.c	Thu Jul 14 15:18:27 2016 +0200
     4.2 +++ b/src/bloblist.c	Mon Jul 18 08:54:43 2016 +0200
     4.3 @@ -41,13 +41,18 @@
     4.4  
     4.5  DYNAMIC_API void free_bloblist(bloblist_t *bloblist)
     4.6  {
     4.7 -    if (bloblist) {
     4.8 -        if (bloblist->next)
     4.9 -            free_bloblist(bloblist->next);
    4.10 -        free(bloblist->value);
    4.11 -        free(bloblist->mime_type);
    4.12 -        free(bloblist->filename);
    4.13 -        free(bloblist);
    4.14 +    bloblist_t *curr;
    4.15 +    bloblist_t *next;
    4.16 +    
    4.17 +    curr = bloblist;
    4.18 +    
    4.19 +    while (curr) {
    4.20 +        next = curr->next;
    4.21 +        free(curr->value);
    4.22 +        free(curr->mime_type);
    4.23 +        free(curr->filename);
    4.24 +        free(curr);
    4.25 +        curr = next;
    4.26      }
    4.27  }
    4.28  
    4.29 @@ -56,7 +61,10 @@
    4.30      bloblist_t *bloblist = NULL;
    4.31  
    4.32      assert(src);
    4.33 +    if (src == NULL)
    4.34 +        return NULL;
    4.35  
    4.36 +    // head
    4.37      char *blob2 = malloc(src->size);
    4.38      assert(blob2);
    4.39      if (blob2 == NULL)
    4.40 @@ -69,12 +77,26 @@
    4.41          goto enomem;
    4.42      blob2 = NULL;
    4.43  
    4.44 -    if (src->next) {
    4.45 -        bloblist->next = bloblist_dup(src->next);
    4.46 -        if (bloblist->next == NULL)
    4.47 +    bloblist_t* src_curr = src->next;
    4.48 +    bloblist_t** dst_curr_ptr = &bloblist->next;
    4.49 +    
    4.50 +    // list
    4.51 +    while (src_curr) {
    4.52 +        blob2 = malloc(src_curr->size);
    4.53 +
    4.54 +        assert(blob2);
    4.55 +        if (blob2 == NULL)
    4.56              goto enomem;
    4.57 +
    4.58 +        memcpy(blob2, src_curr->value, src_curr->size);
    4.59 +        *dst_curr_ptr = new_bloblist(blob2, src_curr->size, src_curr->mime_type, src_curr->filename);
    4.60 +        if (*dst_curr_ptr == NULL)
    4.61 +            goto enomem;
    4.62 +        
    4.63 +        src_curr = src_curr->next;
    4.64 +        dst_curr_ptr = &((*dst_curr_ptr)->next);
    4.65      }
    4.66 -
    4.67 +        
    4.68      return bloblist;
    4.69  
    4.70  enomem:
    4.71 @@ -87,11 +109,16 @@
    4.72          const char *mime_type, const char *filename)
    4.73  {
    4.74      assert(blob);
    4.75 -
    4.76 +    if (blob == NULL)
    4.77 +        return NULL;
    4.78 +    
    4.79      if (bloblist == NULL)
    4.80          return new_bloblist(blob, size, mime_type, filename);
    4.81  
    4.82 -    if (bloblist->value == NULL) {
    4.83 +    if (bloblist->value == NULL) { // empty list
    4.84 +        if (bloblist->next != NULL)
    4.85 +            return NULL; // invalid list
    4.86 +            
    4.87          if (mime_type) {
    4.88              bloblist->mime_type = strdup(mime_type);
    4.89              if (bloblist->mime_type == NULL) {
    4.90 @@ -108,20 +135,25 @@
    4.91              }
    4.92          }
    4.93  
    4.94 -        assert((blob == NULL && size == 0) || (blob && size));
    4.95 -
    4.96          bloblist->value = blob;
    4.97          bloblist->size = size;
    4.98  
    4.99          return bloblist;
   4.100      }
   4.101  
   4.102 -    if (bloblist->next == NULL) {
   4.103 -        bloblist->next = new_bloblist(blob, size, mime_type, filename);
   4.104 -        return bloblist->next;
   4.105 -    }
   4.106 -
   4.107 -    return bloblist_add(bloblist->next, blob, size, mime_type, filename);
   4.108 +    bloblist_t* list_curr = bloblist;
   4.109 +    
   4.110 +    while (list_curr->next)
   4.111 +        list_curr = list_curr->next;
   4.112 +    
   4.113 +    list_curr->next = new_bloblist(blob, size, mime_type, filename);
   4.114 +    
   4.115 +    assert(list_curr->next);
   4.116 +    if (list_curr->next == NULL)
   4.117 +        return NULL;
   4.118 +   
   4.119 +    return list_curr->next;
   4.120 +    
   4.121  }
   4.122  
   4.123  DYNAMIC_API int bloblist_length(const bloblist_t *bloblist)
     5.1 --- a/src/bloblist.h	Thu Jul 14 15:18:27 2016 +0200
     5.2 +++ b/src/bloblist.h	Mon Jul 18 08:54:43 2016 +0200
     5.3 @@ -68,11 +68,14 @@
     5.4  //      filename (in)  file name of the blob or NULL if unknown
     5.5  //
     5.6  //  return value:
     5.7 -//      pointer to the last element of bloblist or NULL if out of memory
     5.8 +//      pointer to the last element of bloblist or NULL if out of memory or
     5.9 +//      NULL passed in as blob value
    5.10  //
    5.11  //  caveat:
    5.12  //      the ownership of the blob goes to the bloblist; mime_type and filename
    5.13 -//      are being copied, the originals remain in the ownership of the caller
    5.14 +//      are being copied, the originals remain in the ownership of the caller.
    5.15 +//      bloblist input parameter equal to NULL or with value == NULL is a valid
    5.16 +//      empty input list.
    5.17  
    5.18  DYNAMIC_API bloblist_t *bloblist_add(bloblist_t *bloblist, char *blob, size_t size,
    5.19          const char *mime_type, const char *filename);
     6.1 --- a/src/etpan_mime.c	Thu Jul 14 15:18:27 2016 +0200
     6.2 +++ b/src/etpan_mime.c	Mon Jul 18 08:54:43 2016 +0200
     6.3 @@ -755,9 +755,10 @@
     6.4          if (_type == NULL)
     6.5              return ENOMEM;
     6.6  
     6.7 -        strcpy(_type, _main_type);
     6.8 -        strcat(_type, "/");
     6.9 -        strcat(_type, content->ct_subtype);
    6.10 +        strncpy(_type, _main_type, len);
    6.11 +        len -= strlen(_main_type);
    6.12 +        strncat(_type, "/", len--);
    6.13 +        strncat(_type, content->ct_subtype, len);
    6.14  
    6.15          if (content->ct_parameters) {
    6.16              clistiter *cur;
     7.1 --- a/src/identity_list.c	Thu Jul 14 15:18:27 2016 +0200
     7.2 +++ b/src/identity_list.c	Mon Jul 18 08:54:43 2016 +0200
     7.3 @@ -14,6 +14,7 @@
     7.4          return NULL;
     7.5  
     7.6      id_list->ident = ident;
     7.7 +    id_list->next = NULL;
     7.8  
     7.9      return id_list;
    7.10  }
    7.11 @@ -32,23 +33,43 @@
    7.12      if (id_list == NULL)
    7.13          return NULL;
    7.14  
    7.15 -    if (src->next) {
    7.16 -        id_list->next = identity_list_dup(src->next);
    7.17 -        if (id_list->next == NULL) {
    7.18 +    identity_list* src_curr = src->next;
    7.19 +    identity_list** dst_curr_ptr = &id_list->next;
    7.20 +    
    7.21 +    while (src_curr) {
    7.22 +        _ident = identity_dup(src_curr->ident);
    7.23 +        if (_ident == NULL) {
    7.24              free_identity_list(id_list);
    7.25              return NULL;
    7.26          }
    7.27 +        
    7.28 +        *dst_curr_ptr = new_identity_list(_ident);
    7.29 +        if (*dst_curr_ptr == NULL) {
    7.30 +            free_identity(_ident);
    7.31 +            free_identity_list(id_list);
    7.32 +            return NULL;
    7.33 +        }
    7.34 +        
    7.35 +        src_curr = src_curr->next;
    7.36 +        dst_curr_ptr = &((*dst_curr_ptr)->next);
    7.37      }
    7.38 -
    7.39 +    
    7.40      return id_list;
    7.41 +    
    7.42  }
    7.43  
    7.44  DYNAMIC_API void free_identity_list(identity_list *id_list)
    7.45  {
    7.46 -    if (id_list) {
    7.47 -        free_identity_list(id_list->next);
    7.48 -        free_identity(id_list->ident);
    7.49 -        free(id_list);
    7.50 +    identity_list *curr;
    7.51 +    identity_list *next;
    7.52 +    
    7.53 +    curr = id_list;
    7.54 +    
    7.55 +    while (curr) {
    7.56 +        next = curr->next;
    7.57 +        free_identity(curr->ident);
    7.58 +        free(curr);
    7.59 +        curr = next;
    7.60      }
    7.61  }
    7.62  
    7.63 @@ -61,17 +82,26 @@
    7.64      if (id_list == NULL)
    7.65          return new_identity_list(ident);
    7.66  
    7.67 +    // empty list
    7.68      if (id_list->ident == NULL) {
    7.69 +        if (id_list->next)
    7.70 +            return NULL; // invalid list
    7.71 +            
    7.72          id_list->ident = ident;
    7.73 +        
    7.74 +        if (id_list->ident == NULL)
    7.75 +            return NULL;
    7.76 +        
    7.77          return id_list;
    7.78      }
    7.79 -    else if (id_list->next == NULL) {
    7.80 -        id_list->next = new_identity_list(ident);
    7.81 -        return id_list->next;
    7.82 -    }
    7.83 -    else {
    7.84 -        return identity_list_add(id_list->next, ident);
    7.85 -    }
    7.86 + 
    7.87 +    identity_list* list_curr = id_list;
    7.88 +    while (list_curr->next)
    7.89 +        list_curr = list_curr->next;
    7.90 +    
    7.91 +    list_curr->next = new_identity_list(ident);
    7.92 +    
    7.93 +    return list_curr->next;
    7.94  }
    7.95  
    7.96  DYNAMIC_API int identity_list_length(const identity_list *id_list)
     8.1 --- a/src/message_api.c	Thu Jul 14 15:18:27 2016 +0200
     8.2 +++ b/src/message_api.c	Mon Jul 18 08:54:43 2016 +0200
     8.3 @@ -101,15 +101,22 @@
     8.4      if (longmsg == NULL)
     8.5          longmsg = "";
     8.6  
     8.7 -    ptext = calloc(1, strlen(shortmsg) + strlen(longmsg) + 12);
     8.8 +    size_t bufsize = strlen(shortmsg) + strlen(longmsg) + 12;
     8.9 +    ptext = calloc(1, bufsize);
    8.10      assert(ptext);
    8.11      if (ptext == NULL)
    8.12          return NULL;
    8.13  
    8.14 -    strcpy(ptext, "Subject: ");
    8.15 -    strcat(ptext, shortmsg);
    8.16 -    strcat(ptext, "\n\n");
    8.17 -    strcat(ptext, longmsg);
    8.18 +    strncpy(ptext, "Subject: ", bufsize);
    8.19 +    bufsize -= 9;
    8.20 +    
    8.21 +    strncat(ptext, shortmsg, bufsize);
    8.22 +    bufsize -= strlen(shortmsg);
    8.23 +    
    8.24 +    strncat(ptext, "\n\n", bufsize);
    8.25 +    bufsize -= 2;
    8.26 +    
    8.27 +    strncat(ptext, longmsg, bufsize);
    8.28  
    8.29      return ptext;
    8.30  }
    8.31 @@ -329,8 +336,7 @@
    8.32      PEP_STATUS status = PEP_STATUS_OK;
    8.33      bool free_ptext = false;
    8.34      char *ptext = NULL;
    8.35 -    char *ctext;
    8.36 -    char *_ctext = NULL;
    8.37 +    char *ctext = NULL;
    8.38      char *mimetext = NULL;
    8.39      size_t csize;
    8.40      assert(dst->longmsg == NULL);
    8.41 @@ -402,13 +408,7 @@
    8.42          goto enomem;
    8.43      dst->attachments = _a;
    8.44  
    8.45 -    _ctext = malloc(csize);
    8.46 -    assert(_ctext);
    8.47 -    if (_ctext == NULL)
    8.48 -        goto enomem;
    8.49 -    memcpy(_ctext, ctext, csize);
    8.50 -
    8.51 -    _a = bloblist_add(_a, _ctext, csize, "application/octet-stream",
    8.52 +    _a = bloblist_add(_a, ctext, csize, "application/octet-stream",
    8.53          "msg.asc");
    8.54      if (_a == NULL)
    8.55          goto enomem;
    8.56 @@ -421,7 +421,7 @@
    8.57  pep_error:
    8.58      if (free_ptext)
    8.59          free(ptext);
    8.60 -    free(_ctext);
    8.61 +    free(ctext);
    8.62      return status;
    8.63  }
    8.64  
    8.65 @@ -433,7 +433,7 @@
    8.66      )
    8.67  {
    8.68      PEP_STATUS status = PEP_STATUS_OK;
    8.69 -    char *ctext;
    8.70 +    char *ctext = NULL;
    8.71      size_t csize;
    8.72      char *ptext = NULL;
    8.73      bool free_ptext = false;
    8.74 @@ -464,10 +464,7 @@
    8.75              free(ptext);
    8.76          free_ptext = false;
    8.77          if (ctext) {
    8.78 -            dst->longmsg = strndup(ctext, csize);
    8.79 -            assert(dst->longmsg);
    8.80 -            if (dst->longmsg == NULL)
    8.81 -                goto enomem;
    8.82 +            dst->longmsg = ctext;
    8.83          }
    8.84          else {
    8.85              goto pep_error;
    8.86 @@ -478,10 +475,7 @@
    8.87          status = encrypt_and_sign(session, keys, ptext, strlen(ptext), &ctext,
    8.88              &csize);
    8.89          if (ctext) {
    8.90 -            dst->longmsg = strndup(ctext, csize);
    8.91 -            assert(dst->longmsg);
    8.92 -            if (dst->longmsg == NULL)
    8.93 -                goto enomem;
    8.94 +            dst->longmsg = ctext;
    8.95          }
    8.96          else {
    8.97              goto pep_error;
    8.98 @@ -499,13 +493,8 @@
    8.99          status = encrypt_and_sign(session, keys, ptext, strlen(ptext), &ctext,
   8.100              &csize);
   8.101          if (ctext) {
   8.102 -            char *_ctext = malloc(csize);
   8.103 -            assert(_ctext);
   8.104 -            if (_ctext == NULL)
   8.105 -                goto enomem;
   8.106 -            memcpy(_ctext, ctext, csize);
   8.107  
   8.108 -            bloblist_t *_a = bloblist_add(dst->attachments, _ctext, csize,
   8.109 +            bloblist_t *_a = bloblist_add(dst->attachments, ctext, csize,
   8.110                  "application/octet-stream", "PGPexch.htm.pgp");
   8.111              if (_a == NULL)
   8.112                  goto enomem;
   8.113 @@ -547,8 +536,8 @@
   8.114                          if (filename == NULL)
   8.115                              goto enomem;
   8.116  
   8.117 -                        strcpy(filename, _s->filename);
   8.118 -                        strcpy(filename + len, ".pgp");
   8.119 +                        strncpy(filename, _s->filename, len);
   8.120 +                        strncpy(filename + len, ".pgp", 5);
   8.121                      }
   8.122                      else {
   8.123                          filename = calloc(1, 20);
   8.124 @@ -560,15 +549,7 @@
   8.125                          snprintf(filename, 20, "Attachment%d.pgp", n);
   8.126                      }
   8.127  
   8.128 -                    char *_ctext = malloc(csize);
   8.129 -                    assert(_ctext);
   8.130 -                    if (_ctext == NULL) {
   8.131 -                        free(filename);
   8.132 -                        goto enomem;
   8.133 -                    }
   8.134 -                    memcpy(_ctext, ctext, csize);
   8.135 -
   8.136 -                    _d = bloblist_add(_d, _ctext, csize, "application/octet-stream",
   8.137 +                    _d = bloblist_add(_d, ctext, csize, "application/octet-stream",
   8.138                          filename);
   8.139                      free(filename);
   8.140                      if (_d == NULL)
   8.141 @@ -1346,10 +1327,8 @@
   8.142                  if (msg == NULL)
   8.143                      goto enomem;
   8.144  
   8.145 -                msg->longmsg = strdup(ptext);
   8.146 -                assert(msg->longmsg);
   8.147 -                if (msg->longmsg == NULL)
   8.148 -                    goto enomem;
   8.149 +                msg->longmsg = ptext;
   8.150 +                ptext = NULL;
   8.151  
   8.152                  bloblist_t *_m = msg->attachments;
   8.153                  if (_m == NULL && src->attachments && src->attachments->value) {
   8.154 @@ -1379,10 +1358,8 @@
   8.155  
   8.156                          if (ptext) {
   8.157                              if (is_encrypted_html_attachment(_s)) {
   8.158 -                                msg->longmsg_formatted = strdup(ptext);
   8.159 -                                assert(msg->longmsg_formatted);
   8.160 -                                if (msg->longmsg_formatted == NULL)
   8.161 -                                    goto pep_error;
   8.162 +                                msg->longmsg_formatted = ptext;
   8.163 +                                ptext = NULL;
   8.164                              }
   8.165                              else {
   8.166                                  static const char * const mime_type = "application/octet-stream";
   8.167 @@ -1391,18 +1368,14 @@
   8.168                                  if (filename == NULL)
   8.169                                      goto enomem;
   8.170  
   8.171 -                                char *_ptext = malloc(psize);
   8.172 -                                assert(_ptext);
   8.173 -                                if (_ptext == NULL)
   8.174 -                                    goto enomem;
   8.175 -                                memcpy(_ptext, ptext, psize);
   8.176 -
   8.177 -                                _m = bloblist_add(_m, _ptext, psize, mime_type,
   8.178 +                                _m = bloblist_add(_m, ptext, psize, mime_type,
   8.179                                      filename);
   8.180                                  free(filename);
   8.181                                  if (_m == NULL)
   8.182                                      goto enomem;
   8.183  
   8.184 +                                ptext = NULL;
   8.185 +
   8.186                                  if (msg->attachments == NULL)
   8.187                                      msg->attachments = _m;
   8.188                              }
   8.189 @@ -1512,8 +1485,7 @@
   8.190              status = cryptotech[crypto].decrypt_and_verify(session, ctext,
   8.191                  csize, &re_ptext, &re_psize, &_keylist);
   8.192              
   8.193 -            if (re_ptext)
   8.194 -                free(re_ptext);
   8.195 +            free(re_ptext);
   8.196              
   8.197              if (status > PEP_CANNOT_DECRYPT_UNKNOWN)
   8.198                  goto pep_error;
   8.199 @@ -1591,6 +1563,7 @@
   8.200      status = PEP_OUT_OF_MEMORY;
   8.201  
   8.202  pep_error:
   8.203 +    free(ptext);
   8.204      free_message(msg);
   8.205      free_stringlist(_keylist);
   8.206  
     9.1 --- a/src/pEpEngine.h	Thu Jul 14 15:18:27 2016 +0200
     9.2 +++ b/src/pEpEngine.h	Mon Jul 18 08:54:43 2016 +0200
     9.3 @@ -71,6 +71,8 @@
     9.4      PEP_CONTRAINTS_VIOLATED                         = 0x0802,
     9.5      PEP_CANNOT_ENCODE                               = 0x0803,
     9.6  
     9.7 +    PEP_SYNC_NO_TRUSTWORDS_CALLBACK                 = 0x0901,
     9.8 +
     9.9      PEP_COMMIT_FAILED                               = 0xff01,
    9.10  
    9.11      PEP_CANNOT_CREATE_TEMP_FILE                     = -5,
    10.1 --- a/src/stringlist.c	Thu Jul 14 15:18:27 2016 +0200
    10.2 +++ b/src/stringlist.c	Mon Jul 18 08:54:43 2016 +0200
    10.3 @@ -41,6 +41,10 @@
    10.4      
    10.5      while (src_curr) {
    10.6          *dst_curr_ptr = new_stringlist(src_curr->value);
    10.7 +        if (*dst_curr_ptr == NULL) {
    10.8 +            free_stringlist(dst);
    10.9 +            return NULL;
   10.10 +        }
   10.11          src_curr = src_curr->next;
   10.12          dst_curr_ptr = &((*dst_curr_ptr)->next);
   10.13      }
    11.1 --- a/src/stringpair.c	Thu Jul 14 15:18:27 2016 +0200
    11.2 +++ b/src/stringpair.c	Mon Jul 18 08:54:43 2016 +0200
    11.3 @@ -85,7 +85,16 @@
    11.4  
    11.5      while (src_curr) {
    11.6          copy_pair = stringpair_dup(src_curr->value);
    11.7 +        if (copy_pair == NULL) {
    11.8 +            free_stringpair_list(dst);
    11.9 +            return NULL;
   11.10 +        }
   11.11          *dst_curr_ptr = new_stringpair_list(copy_pair);
   11.12 +        if (*dst_curr_ptr == NULL) {
   11.13 +            free_stringpair(copy_pair);
   11.14 +            free_stringpair_list(dst);
   11.15 +            return NULL;
   11.16 +        }
   11.17          src_curr = src_curr->next;
   11.18          dst_curr_ptr = &((*dst_curr_ptr)->next);
   11.19      }
    12.1 --- a/src/sync_actions.c	Thu Jul 14 15:18:27 2016 +0200
    12.2 +++ b/src/sync_actions.c	Mon Jul 18 08:54:43 2016 +0200
    12.3 @@ -2,202 +2,11 @@
    12.4  
    12.5  #include <assert.h>
    12.6  #include "pEp_internal.h"
    12.7 -#include "keymanagement.h"
    12.8  #include "message.h"
    12.9  #include "sync_fsm.h"
   12.10 -#include "baseprotocol.h"
   12.11 -#include "map_asn1.h"
   12.12 -#include "../asn.1/Beacon.h"
   12.13 -#include "../asn.1/HandshakeRequest.h"
   12.14 -#include "../asn.1/GroupKeys.h"
   12.15  
   12.16  
   12.17 -// sendBeacon() - send Beacon message
   12.18 -//
   12.19 -//  params:
   12.20 -//      session (in)        session handle
   12.21 -//      state (in)          state the state machine is in
   12.22 -//      partner (in)        (must be NULL)
   12.23 -//
   12.24 -//  returns:
   12.25 -//      PEP_STATUS_OK or any other value on error
   12.26 -
   12.27 -PEP_STATUS sendBeacon(
   12.28 -        PEP_SESSION session,
   12.29 -        DeviceState_state state,
   12.30 -        const Identity partner
   12.31 -    )
   12.32 -{
   12.33 -    PEP_STATUS status = PEP_STATUS_OK;
   12.34 -    Beacon_t *msg = NULL;
   12.35 -    char *payload = NULL;
   12.36 -    message *_message = NULL;
   12.37 -    pEp_identity *me = NULL;
   12.38 -
   12.39 -    assert(session);
   12.40 -    assert(!partner);
   12.41 -    if (!(session && !partner))
   12.42 -        return PEP_ILLEGAL_VALUE;
   12.43 -
   12.44 -    assert(session->messageToSend);
   12.45 -    if (!session->messageToSend)
   12.46 -        return PEP_SEND_FUNCTION_NOT_REGISTERED;
   12.47 -
   12.48 -    msg = (Beacon_t *) calloc(1, sizeof(Beacon_t));
   12.49 -    assert(msg);
   12.50 -    if (!msg)
   12.51 -        goto enomem;
   12.52 -
   12.53 -    int32_t seq;
   12.54 -    status = sequence_value(session, "DeviceGroup", &seq);
   12.55 -    if (status != PEP_STATUS_OK)
   12.56 -        goto error;
   12.57 -    msg->header.sequence = (long) seq;
   12.58 -
   12.59 -    msg->state = (long) state;
   12.60 -
   12.61 -    me = new_identity(NULL, NULL, NULL, NULL);
   12.62 -    if (!me)
   12.63 -        goto enomem;
   12.64 -    status = myself(session, me);
   12.65 -    if (status != PEP_STATUS_OK)
   12.66 -        goto error;
   12.67 -    if (Identity_from_Struct(me, &msg->me) == NULL)
   12.68 -        goto enomem;
   12.69 -
   12.70 -    if (asn_check_constraints(&asn_DEF_Beacon, msg, NULL, NULL)) {
   12.71 -        status = PEP_CONTRAINTS_VIOLATED;
   12.72 -        goto error;
   12.73 -    }
   12.74 -
   12.75 -    ssize_t size = uper_encode_to_new_buffer(&asn_DEF_Beacon,
   12.76 -            NULL, msg, (void **) &payload);
   12.77 -    if (size == -1) {
   12.78 -        status = PEP_CANNOT_ENCODE;
   12.79 -        goto error;
   12.80 -    }
   12.81 -
   12.82 -    status = prepare_message(me, partner, payload, size, &_message);
   12.83 -    if (status != PEP_STATUS_OK)
   12.84 -        goto error;
   12.85 -    payload = NULL;
   12.86 -
   12.87 -    free_identity(me);
   12.88 -    me = NULL;
   12.89 -
   12.90 -    status = session->messageToSend(session->sync_obj, _message);
   12.91 -
   12.92 -    free_message(_message);
   12.93 -    ASN_STRUCT_FREE(asn_DEF_Beacon, msg);
   12.94 -
   12.95 -    return status;
   12.96 -
   12.97 -enomem:
   12.98 -    status = PEP_OUT_OF_MEMORY;
   12.99 -error:
  12.100 -    ASN_STRUCT_FREE(asn_DEF_Beacon, msg);
  12.101 -    free(payload);
  12.102 -    free_message(_message);
  12.103 -    free_identity(me);
  12.104 -    return status;
  12.105 -}
  12.106 -
  12.107 -
  12.108 -// sendHandshakeRequest() - send HandshakeRequest message
  12.109 -//
  12.110 -//  params:
  12.111 -//      session (in)        session handle
  12.112 -//      state (in)          state the state machine is in
  12.113 -//      partner (in)        partner to communicate with
  12.114 -//
  12.115 -//  returns:
  12.116 -//      PEP_STATUS_OK or any other value on error
  12.117 -
  12.118 -PEP_STATUS sendHandshakeRequest(
  12.119 -        PEP_SESSION session,
  12.120 -        DeviceState_state state,
  12.121 -        const Identity partner
  12.122 -    )
  12.123 -{
  12.124 -    PEP_STATUS status = PEP_STATUS_OK;
  12.125 -    HandshakeRequest_t *msg = NULL;
  12.126 -    char *payload = NULL;
  12.127 -    message *_message = NULL;
  12.128 -    pEp_identity *me = NULL;
  12.129 -
  12.130 -    assert(session);
  12.131 -    assert(partner);
  12.132 -    if (!(session && partner))
  12.133 -        return PEP_ILLEGAL_VALUE;
  12.134 -
  12.135 -    assert(session->messageToSend);
  12.136 -    if (!session->messageToSend)
  12.137 -        return PEP_SEND_FUNCTION_NOT_REGISTERED;
  12.138 -
  12.139 -    msg = (HandshakeRequest_t *) calloc(1, sizeof(HandshakeRequest_t));
  12.140 -    assert(msg);
  12.141 -    if (!msg)
  12.142 -        goto enomem;
  12.143 -
  12.144 -    int32_t seq;
  12.145 -    status = sequence_value(session, "DeviceGroup", &seq);
  12.146 -    if (status != PEP_STATUS_OK)
  12.147 -        goto error;
  12.148 -    msg->header.sequence = (long) seq;
  12.149 -
  12.150 -    msg->state = (long) state;
  12.151 -
  12.152 -    me = new_identity(NULL, NULL, NULL, NULL);
  12.153 -    if (!me)
  12.154 -        goto enomem;
  12.155 -    status = myself(session, me);
  12.156 -    if (status != PEP_STATUS_OK)
  12.157 -        goto error;
  12.158 -    if (Identity_from_Struct(me, &msg->me) == NULL)
  12.159 -        goto enomem;
  12.160 -
  12.161 -    if (Identity_from_Struct(partner, &msg->partner) == NULL)
  12.162 -        goto enomem;
  12.163 -
  12.164 -    if (asn_check_constraints(&asn_DEF_HandshakeRequest, msg, NULL, NULL)) {
  12.165 -        status = PEP_CONTRAINTS_VIOLATED;
  12.166 -        goto error;
  12.167 -    }
  12.168 -
  12.169 -    ssize_t size = uper_encode_to_new_buffer(&asn_DEF_HandshakeRequest,
  12.170 -            NULL, msg, (void **) &payload);
  12.171 -    if (size == -1) {
  12.172 -        status = PEP_CANNOT_ENCODE;
  12.173 -        goto error;
  12.174 -    }
  12.175 -
  12.176 -    status = prepare_message(me, partner, payload, size, &_message);
  12.177 -    if (status != PEP_STATUS_OK)
  12.178 -        goto error;
  12.179 -    payload = NULL;
  12.180 -
  12.181 -    free_identity(me);
  12.182 -    me = NULL;
  12.183 -
  12.184 -    status = session->messageToSend(session->sync_obj, _message);
  12.185 -
  12.186 -    free_message(_message);
  12.187 -    ASN_STRUCT_FREE(asn_DEF_HandshakeRequest, msg);
  12.188 -
  12.189 -    return status;
  12.190 -
  12.191 -enomem:
  12.192 -    status = PEP_OUT_OF_MEMORY;
  12.193 -error:
  12.194 -    ASN_STRUCT_FREE(asn_DEF_HandshakeRequest, msg);
  12.195 -    free(payload);
  12.196 -    free_message(_message);
  12.197 -    free_identity(me);
  12.198 -    return status;
  12.199 -}
  12.200 -
  12.201 -
  12.202 -// showHandshake() - 
  12.203 +// showHandshake() - trigger the handshake dialog of the application
  12.204  //
  12.205  //  params:
  12.206  //      session (in)        session handle
  12.207 @@ -214,21 +23,30 @@
  12.208      )
  12.209  {
  12.210      PEP_STATUS status = PEP_STATUS_OK;
  12.211 -
  12.212      assert(session);
  12.213      assert(partner);
  12.214 +    assert(session->showHandshake);
  12.215      if (!(session && partner))
  12.216          return PEP_ILLEGAL_VALUE;
  12.217 +    if (!session->showHandshake)
  12.218 +        return PEP_SYNC_NO_TRUSTWORDS_CALLBACK;
  12.219  
  12.220 -    // working code
  12.221 +    pEp_identity *me = NULL;
  12.222 +    status = get_identity(session, partner->address, PEP_OWN_USERID, &me);
  12.223 +    if (status != PEP_STATUS_OK)
  12.224 +        goto error;
  12.225 +    
  12.226 +    status = session->showHandshake(session, me, partner);
  12.227 +    if (status != PEP_STATUS_OK)
  12.228 +        goto error;
  12.229  
  12.230 -
  12.231 +    free_identity(me);
  12.232      return status;
  12.233  
  12.234  enomem:
  12.235      status = PEP_OUT_OF_MEMORY;
  12.236  error:
  12.237 -    // free...
  12.238 +    free_identity(me);
  12.239      return status;
  12.240  }
  12.241  
  12.242 @@ -304,95 +122,3 @@
  12.243      return status;
  12.244  }
  12.245  
  12.246 -
  12.247 -// sendGroupKeys() - send GroupKeys message
  12.248 -//
  12.249 -//  params:
  12.250 -//      session (in)        session handle
  12.251 -//      state (in)          state the state machine is in
  12.252 -//      partner (in)        (must be NULL)
  12.253 -//
  12.254 -//  returns:
  12.255 -//      PEP_STATUS_OK or any other value on error
  12.256 -
  12.257 -PEP_STATUS sendGroupKeys(
  12.258 -        PEP_SESSION session,
  12.259 -        DeviceState_state state,
  12.260 -        const Identity partner
  12.261 -    )
  12.262 -{
  12.263 -    PEP_STATUS status = PEP_STATUS_OK;
  12.264 -    GroupKeys_t *msg = NULL;
  12.265 -    char *payload = NULL;
  12.266 -    message *_message = NULL;
  12.267 -    pEp_identity *me = NULL;
  12.268 -
  12.269 -    assert(session);
  12.270 -    assert(!partner);
  12.271 -    if (!(session && !partner))
  12.272 -        return PEP_ILLEGAL_VALUE;
  12.273 -
  12.274 -    assert(session->messageToSend);
  12.275 -    if (!session->messageToSend)
  12.276 -        return PEP_SEND_FUNCTION_NOT_REGISTERED;
  12.277 -
  12.278 -    msg = (GroupKeys_t *) calloc(1, sizeof(GroupKeys_t));
  12.279 -    assert(msg);
  12.280 -    if (!msg)
  12.281 -        goto enomem;
  12.282 -
  12.283 -    int32_t seq;
  12.284 -    status = sequence_value(session, "DeviceGroup", &seq);
  12.285 -    if (status != PEP_STATUS_OK)
  12.286 -        goto error;
  12.287 -    msg->header.sequence = (long) seq;
  12.288 -
  12.289 -    msg->state = (long) state;
  12.290 -
  12.291 -    me = new_identity(NULL, NULL, NULL, NULL);
  12.292 -    if (!me)
  12.293 -        goto enomem;
  12.294 -    status = myself(session, me);
  12.295 -    if (status != PEP_STATUS_OK)
  12.296 -        goto error;
  12.297 -    if (Identity_from_Struct(me, &msg->me) == NULL)
  12.298 -        goto enomem;
  12.299 -
  12.300 -    if (asn_check_constraints(&asn_DEF_GroupKeys, msg, NULL, NULL)) {
  12.301 -        status = PEP_CONTRAINTS_VIOLATED;
  12.302 -        goto error;
  12.303 -    }
  12.304 -
  12.305 -    ssize_t size = uper_encode_to_new_buffer(&asn_DEF_GroupKeys,
  12.306 -            NULL, msg, (void **) &payload);
  12.307 -    if (size == -1) {
  12.308 -        status = PEP_CANNOT_ENCODE;
  12.309 -        goto error;
  12.310 -    }
  12.311 -
  12.312 -    status = prepare_message(me, partner, payload, size, &_message);
  12.313 -    if (status != PEP_STATUS_OK)
  12.314 -        goto error;
  12.315 -    payload = NULL;
  12.316 -
  12.317 -    free_identity(me);
  12.318 -    me = NULL;
  12.319 -
  12.320 -    status = session->messageToSend(session->sync_obj, _message);
  12.321 -
  12.322 -    free_message(_message);
  12.323 -    ASN_STRUCT_FREE(asn_DEF_GroupKeys, msg);
  12.324 -
  12.325 -    return status;
  12.326 -
  12.327 -enomem:
  12.328 -    status = PEP_OUT_OF_MEMORY;
  12.329 -error:
  12.330 -    ASN_STRUCT_FREE(asn_DEF_GroupKeys, msg);
  12.331 -    free(payload);
  12.332 -    free_message(_message);
  12.333 -    free_identity(me);
  12.334 -    return status;
  12.335 -}
  12.336 -
  12.337 -
    13.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    13.2 +++ b/src/sync_send_actions.c	Mon Jul 18 08:54:43 2016 +0200
    13.3 @@ -0,0 +1,289 @@
    13.4 +// Send Actions for DeviceState state machine
    13.5 +
    13.6 +#include <assert.h>
    13.7 +#include "pEp_internal.h"
    13.8 +#include "keymanagement.h"
    13.9 +#include "message.h"
   13.10 +#include "sync_fsm.h"
   13.11 +#include "baseprotocol.h"
   13.12 +#include "map_asn1.h"
   13.13 +#include "../asn.1/Beacon.h"
   13.14 +#include "../asn.1/HandshakeRequest.h"
   13.15 +#include "../asn.1/GroupKeys.h"
   13.16 +
   13.17 +
   13.18 +// sendBeacon() - send Beacon message
   13.19 +//
   13.20 +//  params:
   13.21 +//      session (in)        session handle
   13.22 +//      state (in)          state the state machine is in
   13.23 +//      partner (in)        (must be NULL)
   13.24 +//
   13.25 +//  returns:
   13.26 +//      PEP_STATUS_OK or any other value on error
   13.27 +
   13.28 +PEP_STATUS sendBeacon(
   13.29 +        PEP_SESSION session,
   13.30 +        DeviceState_state state,
   13.31 +        const Identity partner
   13.32 +    )
   13.33 +{
   13.34 +    PEP_STATUS status = PEP_STATUS_OK;
   13.35 +    Beacon_t *msg = NULL;
   13.36 +    char *payload = NULL;
   13.37 +    message *_message = NULL;
   13.38 +    pEp_identity *me = NULL;
   13.39 +
   13.40 +    assert(session);
   13.41 +    assert(!partner);
   13.42 +    if (!(session && !partner))
   13.43 +        return PEP_ILLEGAL_VALUE;
   13.44 +
   13.45 +    assert(session->messageToSend);
   13.46 +    if (!session->messageToSend)
   13.47 +        return PEP_SEND_FUNCTION_NOT_REGISTERED;
   13.48 +
   13.49 +    msg = (Beacon_t *) calloc(1, sizeof(Beacon_t));
   13.50 +    assert(msg);
   13.51 +    if (!msg)
   13.52 +        goto enomem;
   13.53 +
   13.54 +    int32_t seq;
   13.55 +    status = sequence_value(session, "DeviceGroup", &seq);
   13.56 +    if (status != PEP_STATUS_OK)
   13.57 +        goto error;
   13.58 +    msg->header.sequence = (long) seq;
   13.59 +
   13.60 +    msg->state = (long) state;
   13.61 +
   13.62 +    me = new_identity(NULL, NULL, NULL, NULL);
   13.63 +    if (!me)
   13.64 +        goto enomem;
   13.65 +    status = myself(session, me);
   13.66 +    if (status != PEP_STATUS_OK)
   13.67 +        goto error;
   13.68 +    if (Identity_from_Struct(me, &msg->me) == NULL)
   13.69 +        goto enomem;
   13.70 +
   13.71 +    if (asn_check_constraints(&asn_DEF_Beacon, msg, NULL, NULL)) {
   13.72 +        status = PEP_CONTRAINTS_VIOLATED;
   13.73 +        goto error;
   13.74 +    }
   13.75 +
   13.76 +    ssize_t size = uper_encode_to_new_buffer(&asn_DEF_Beacon,
   13.77 +            NULL, msg, (void **) &payload);
   13.78 +    if (size == -1) {
   13.79 +        status = PEP_CANNOT_ENCODE;
   13.80 +        goto error;
   13.81 +    }
   13.82 +
   13.83 +    status = prepare_message(me, partner, payload, size, &_message);
   13.84 +    if (status != PEP_STATUS_OK)
   13.85 +        goto error;
   13.86 +    payload = NULL;
   13.87 +
   13.88 +    free_identity(me);
   13.89 +    me = NULL;
   13.90 +
   13.91 +    status = session->messageToSend(session->sync_obj, _message);
   13.92 +
   13.93 +    free_message(_message);
   13.94 +    ASN_STRUCT_FREE(asn_DEF_Beacon, msg);
   13.95 +
   13.96 +    return status;
   13.97 +
   13.98 +enomem:
   13.99 +    status = PEP_OUT_OF_MEMORY;
  13.100 +error:
  13.101 +    ASN_STRUCT_FREE(asn_DEF_Beacon, msg);
  13.102 +    free(payload);
  13.103 +    free_message(_message);
  13.104 +    free_identity(me);
  13.105 +    return status;
  13.106 +}
  13.107 +
  13.108 +
  13.109 +// sendHandshakeRequest() - send HandshakeRequest message
  13.110 +//
  13.111 +//  params:
  13.112 +//      session (in)        session handle
  13.113 +//      state (in)          state the state machine is in
  13.114 +//      partner (in)        partner to communicate with
  13.115 +//
  13.116 +//  returns:
  13.117 +//      PEP_STATUS_OK or any other value on error
  13.118 +
  13.119 +PEP_STATUS sendHandshakeRequest(
  13.120 +        PEP_SESSION session,
  13.121 +        DeviceState_state state,
  13.122 +        const Identity partner
  13.123 +    )
  13.124 +{
  13.125 +    PEP_STATUS status = PEP_STATUS_OK;
  13.126 +    HandshakeRequest_t *msg = NULL;
  13.127 +    char *payload = NULL;
  13.128 +    message *_message = NULL;
  13.129 +    pEp_identity *me = NULL;
  13.130 +
  13.131 +    assert(session);
  13.132 +    assert(partner);
  13.133 +    if (!(session && partner))
  13.134 +        return PEP_ILLEGAL_VALUE;
  13.135 +
  13.136 +    assert(session->messageToSend);
  13.137 +    if (!session->messageToSend)
  13.138 +        return PEP_SEND_FUNCTION_NOT_REGISTERED;
  13.139 +
  13.140 +    msg = (HandshakeRequest_t *) calloc(1, sizeof(HandshakeRequest_t));
  13.141 +    assert(msg);
  13.142 +    if (!msg)
  13.143 +        goto enomem;
  13.144 +
  13.145 +    int32_t seq;
  13.146 +    status = sequence_value(session, "DeviceGroup", &seq);
  13.147 +    if (status != PEP_STATUS_OK)
  13.148 +        goto error;
  13.149 +    msg->header.sequence = (long) seq;
  13.150 +
  13.151 +    msg->state = (long) state;
  13.152 +
  13.153 +    me = new_identity(NULL, NULL, NULL, NULL);
  13.154 +    if (!me)
  13.155 +        goto enomem;
  13.156 +    status = myself(session, me);
  13.157 +    if (status != PEP_STATUS_OK)
  13.158 +        goto error;
  13.159 +    if (Identity_from_Struct(me, &msg->me) == NULL)
  13.160 +        goto enomem;
  13.161 +
  13.162 +    if (Identity_from_Struct(partner, &msg->partner) == NULL)
  13.163 +        goto enomem;
  13.164 +
  13.165 +    if (asn_check_constraints(&asn_DEF_HandshakeRequest, msg, NULL, NULL)) {
  13.166 +        status = PEP_CONTRAINTS_VIOLATED;
  13.167 +        goto error;
  13.168 +    }
  13.169 +
  13.170 +    ssize_t size = uper_encode_to_new_buffer(&asn_DEF_HandshakeRequest,
  13.171 +            NULL, msg, (void **) &payload);
  13.172 +    if (size == -1) {
  13.173 +        status = PEP_CANNOT_ENCODE;
  13.174 +        goto error;
  13.175 +    }
  13.176 +
  13.177 +    status = prepare_message(me, partner, payload, size, &_message);
  13.178 +    if (status != PEP_STATUS_OK)
  13.179 +        goto error;
  13.180 +    payload = NULL;
  13.181 +
  13.182 +    free_identity(me);
  13.183 +    me = NULL;
  13.184 +
  13.185 +    status = session->messageToSend(session->sync_obj, _message);
  13.186 +
  13.187 +    free_message(_message);
  13.188 +    ASN_STRUCT_FREE(asn_DEF_HandshakeRequest, msg);
  13.189 +
  13.190 +    return status;
  13.191 +
  13.192 +enomem:
  13.193 +    status = PEP_OUT_OF_MEMORY;
  13.194 +error:
  13.195 +    ASN_STRUCT_FREE(asn_DEF_HandshakeRequest, msg);
  13.196 +    free(payload);
  13.197 +    free_message(_message);
  13.198 +    free_identity(me);
  13.199 +    return status;
  13.200 +}
  13.201 +
  13.202 +
  13.203 +// sendGroupKeys() - send GroupKeys message
  13.204 +//
  13.205 +//  params:
  13.206 +//      session (in)        session handle
  13.207 +//      state (in)          state the state machine is in
  13.208 +//      partner (in)        (must be NULL)
  13.209 +//
  13.210 +//  returns:
  13.211 +//      PEP_STATUS_OK or any other value on error
  13.212 +
  13.213 +PEP_STATUS sendGroupKeys(
  13.214 +        PEP_SESSION session,
  13.215 +        DeviceState_state state,
  13.216 +        const Identity partner
  13.217 +    )
  13.218 +{
  13.219 +    PEP_STATUS status = PEP_STATUS_OK;
  13.220 +    GroupKeys_t *msg = NULL;
  13.221 +    char *payload = NULL;
  13.222 +    message *_message = NULL;
  13.223 +    pEp_identity *me = NULL;
  13.224 +
  13.225 +    assert(session);
  13.226 +    assert(!partner);
  13.227 +    if (!(session && !partner))
  13.228 +        return PEP_ILLEGAL_VALUE;
  13.229 +
  13.230 +    assert(session->messageToSend);
  13.231 +    if (!session->messageToSend)
  13.232 +        return PEP_SEND_FUNCTION_NOT_REGISTERED;
  13.233 +
  13.234 +    msg = (GroupKeys_t *) calloc(1, sizeof(GroupKeys_t));
  13.235 +    assert(msg);
  13.236 +    if (!msg)
  13.237 +        goto enomem;
  13.238 +
  13.239 +    int32_t seq;
  13.240 +    status = sequence_value(session, "DeviceGroup", &seq);
  13.241 +    if (status != PEP_STATUS_OK)
  13.242 +        goto error;
  13.243 +    msg->header.sequence = (long) seq;
  13.244 +
  13.245 +    msg->state = (long) state;
  13.246 +
  13.247 +    me = new_identity(NULL, NULL, NULL, NULL);
  13.248 +    if (!me)
  13.249 +        goto enomem;
  13.250 +    status = myself(session, me);
  13.251 +    if (status != PEP_STATUS_OK)
  13.252 +        goto error;
  13.253 +    if (Identity_from_Struct(me, &msg->me) == NULL)
  13.254 +        goto enomem;
  13.255 +
  13.256 +    if (asn_check_constraints(&asn_DEF_GroupKeys, msg, NULL, NULL)) {
  13.257 +        status = PEP_CONTRAINTS_VIOLATED;
  13.258 +        goto error;
  13.259 +    }
  13.260 +
  13.261 +    ssize_t size = uper_encode_to_new_buffer(&asn_DEF_GroupKeys,
  13.262 +            NULL, msg, (void **) &payload);
  13.263 +    if (size == -1) {
  13.264 +        status = PEP_CANNOT_ENCODE;
  13.265 +        goto error;
  13.266 +    }
  13.267 +
  13.268 +    status = prepare_message(me, partner, payload, size, &_message);
  13.269 +    if (status != PEP_STATUS_OK)
  13.270 +        goto error;
  13.271 +    payload = NULL;
  13.272 +
  13.273 +    free_identity(me);
  13.274 +    me = NULL;
  13.275 +
  13.276 +    status = session->messageToSend(session->sync_obj, _message);
  13.277 +
  13.278 +    free_message(_message);
  13.279 +    ASN_STRUCT_FREE(asn_DEF_GroupKeys, msg);
  13.280 +
  13.281 +    return status;
  13.282 +
  13.283 +enomem:
  13.284 +    status = PEP_OUT_OF_MEMORY;
  13.285 +error:
  13.286 +    ASN_STRUCT_FREE(asn_DEF_GroupKeys, msg);
  13.287 +    free(payload);
  13.288 +    free_message(_message);
  13.289 +    free_identity(me);
  13.290 +    return status;
  13.291 +}
  13.292 +
    14.1 --- a/sync/Makefile	Thu Jul 14 15:18:27 2016 +0200
    14.2 +++ b/sync/Makefile	Mon Jul 18 08:54:43 2016 +0200
    14.3 @@ -1,6 +1,6 @@
    14.4  include ../Makefile.conf
    14.5  
    14.6 -all: .statemachines
    14.7 +all: .statemachines .skeletons
    14.8  
    14.9  skeleton: .skeletons
   14.10  
    15.1 --- a/sync/gen_actions_skeleton.ysl2	Thu Jul 14 15:18:27 2016 +0200
    15.2 +++ b/sync/gen_actions_skeleton.ysl2	Mon Jul 18 08:54:43 2016 +0200
    15.3 @@ -9,11 +9,16 @@
    15.4  tstylesheet {
    15.5      include ./functions.ysl2
    15.6  
    15.7 -    template "/protocol/fsm" document "../src/{@filename}_actions.c.skeleton", "text" {
    15.8 +    template "/protocol" {
    15.9 +        apply "fsm", mode=send, 0;
   15.10 +        apply "fsm", mode=other, 0;
   15.11 +    }
   15.12 +
   15.13 +    template "fsm", mode=send document "../src/{@filename}_send_actions.c", "text" {
   15.14          const "name", "@name";
   15.15          const "filename", "@filename";
   15.16          ||
   15.17 -        // Actions for «@name» state machine
   15.18 +        // Send Actions for «@name» state machine
   15.19  
   15.20          #include <assert.h>
   15.21          #include "pEp_internal.h"
   15.22 @@ -28,29 +33,32 @@
   15.23                  | #include "../asn.1/«substring(@name, 5, 255)».h"
   15.24          |
   15.25          for "func:distinctName(//action)"
   15.26 -            call "action"
   15.27 -                with "action", ".",
   15.28 -                with "fsm", "$name",
   15.29 -                with "filename", "$filename";
   15.30 -        |
   15.31 +            if "substring(@name, 1, 4) = 'send'"
   15.32 +                call "send_action"
   15.33 +                    with "action", ".",
   15.34 +                    with "fsm", "$name",
   15.35 +                    with "filename", "$filename";
   15.36      }
   15.37  
   15.38 -    function "action" {
   15.39 -        param "action";
   15.40 -        param "fsm";
   15.41 -        param "filename", "'###'";
   15.42 -        choose {
   15.43 -            when "substring($action/@name, 1, 4) = 'send'"
   15.44 -                call "send_action"
   15.45 -                    with "action", "$action",
   15.46 -                    with "fsm", "$fsm",
   15.47 +    template "fsm", mode=other document "../src/{@filename}_actions.c.skeleton", "text" {
   15.48 +        const "name", "@name";
   15.49 +        const "filename", "@filename";
   15.50 +        ||
   15.51 +        // Actions for «@name» state machine
   15.52 +
   15.53 +        #include <assert.h>
   15.54 +        #include "pEp_internal.h"
   15.55 +        #include "keymanagement.h"
   15.56 +        #include "message.h"
   15.57 +        #include "«@filename»_fsm.h"
   15.58 +
   15.59 +        ||
   15.60 +        for "func:distinctName(//action)"
   15.61 +            if "substring(@name, 1, 4) != 'send'"
   15.62 +                call "other_action"
   15.63 +                    with "action", ".",
   15.64 +                    with "fsm", "$name",
   15.65                      with "filename", "$filename";
   15.66 -            otherwise
   15.67 -                call "other_action"
   15.68 -                    with "action", "$action",
   15.69 -                    with "fsm", "$fsm",
   15.70 -                    with "filename", "$filename";
   15.71 -        }
   15.72      }
   15.73  
   15.74      function "paramcheck" {
    16.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    16.2 +++ b/test/bloblist_test.cc	Mon Jul 18 08:54:43 2016 +0200
    16.3 @@ -0,0 +1,131 @@
    16.4 +#include <stdlib.h>
    16.5 +#include <string.h>
    16.6 +#include "platform.h"
    16.7 +#include <iostream>
    16.8 +#include <fstream>
    16.9 +#include <assert.h>
   16.10 +
   16.11 +#include "bloblist.h"
   16.12 +
   16.13 +using namespace std;
   16.14 +
   16.15 +/*
   16.16 + *     char *address;              // C string with address UTF-8 encoded
   16.17 +    char *fpr;                  // C string with fingerprint UTF-8 encoded
   16.18 +    char *user_id;              // C string with user ID UTF-8 encoded
   16.19 +    char *username;             // C string with user name UTF-8 encoded
   16.20 +    PEP_comm_type comm_type;    // type of communication with this ID
   16.21 +    char lang[3];               // language of conversation
   16.22 +                                // ISO 639-1 ALPHA-2, last byte is 0
   16.23 +    bool me;                    // if this is the local user herself/himself
   16.24 +    */
   16.25 +
   16.26 +bool test_blob_equals(size_t size1, char* blob1, size_t size2, char* blob2) {
   16.27 +    if (size1 != size2)
   16.28 +        return false;
   16.29 +    size_t i;
   16.30 +    for (i = 0; i < size1; i++) {
   16.31 +        if (blob1[i] != blob2[i])
   16.32 +            return false;
   16.33 +    }
   16.34 +    return true;
   16.35 +}
   16.36 +
   16.37 +bool test_bloblist_node_equals(bloblist_t* val1, bloblist_t* val2) {
   16.38 +    assert(val1);
   16.39 +    assert(val2);
   16.40 +    assert(val1->size == val2->size);
   16.41 +    assert(test_blob_equals(val1->size, val1->value, val2->size, val2->value));
   16.42 +    return( ((!val1->mime_type && !val2->mime_type) || (strcmp(val1->mime_type, val2->mime_type) == 0))
   16.43 +        && ((!val1->filename && !val2->filename) || (strcmp(val1->filename, val2->filename) == 0)));
   16.44 +}
   16.45 +
   16.46 +int main() {
   16.47 +    cout << "\n*** data structures: bloblist_test ***\n\n";
   16.48 +    char* text1 = strdup("This is just some text.");
   16.49 +    char* text2 = strdup("More text.");
   16.50 +    char* text3 = strdup("Unpleasant news and witty one-liners.");
   16.51 +    char* text4 = strdup("I AM URDNOT WREX AND THIS IS MY PLANET!");
   16.52 +    bloblist_t* bl1 = new_bloblist(text1, strlen(text1) + 1, "text/plain", NULL);
   16.53 +    bloblist_t* bl2 = new_bloblist(text2, strlen(text2) + 1, "text/richtext", "bob.rtf");
   16.54 +    bloblist_t* bl3 = new_bloblist(text3, strlen(text3) + 1, NULL, "dummy.bin");
   16.55 +    bloblist_t* bl4 = new_bloblist(text4, strlen(text4) + 1, NULL, NULL);
   16.56 +    
   16.57 +    bloblist_t* bl_arr[4] = {bl1, bl2, bl3, bl4};
   16.58 +        
   16.59 +    int i;
   16.60 +        
   16.61 +    cout << "duping one-element bloblist...\n";
   16.62 +    
   16.63 +    bloblist_t* new_bl = bloblist_dup(bl1);
   16.64 +    assert(new_bl);
   16.65 +    assert(test_bloblist_node_equals(bl1, new_bl));
   16.66 +    assert(new_bl->next == NULL);
   16.67 +    assert(bl1->value != new_bl->value);
   16.68 +    assert(bl1->mime_type != new_bl->mime_type || !(bl1->mime_type || new_bl->mime_type));
   16.69 +    assert(bl1->filename != new_bl->filename || !(bl1->filename || new_bl->filename));
   16.70 +    cout << "one-element bloblist duplicated.\n\n";
   16.71 +    
   16.72 +    cout << "freeing bloblist...\n";
   16.73 +    free_bloblist(new_bl);
   16.74 +    new_bl = NULL;
   16.75 +    
   16.76 +    bloblist_t* p;
   16.77 +    cout << "\ncreating four-element list...\n";
   16.78 +    bloblist_t* to_copy = bl_arr[0];
   16.79 +    new_bl = bloblist_add(new_bl, strdup(to_copy->value), to_copy->size, to_copy->mime_type, to_copy->filename);
   16.80 +    for (i = 1; i < 4; i++) {
   16.81 +        to_copy = bl_arr[i];
   16.82 +        p = bloblist_add(new_bl, strdup(to_copy->value), to_copy->size, to_copy->mime_type, to_copy->filename);
   16.83 +
   16.84 +        assert(p);
   16.85 +    }
   16.86 +    
   16.87 +    p = new_bl;
   16.88 +    
   16.89 +    for (i = 0; i < 4; i++) {
   16.90 +        assert(p);
   16.91 +        
   16.92 +        assert(test_bloblist_node_equals(p, bl_arr[i]));
   16.93 +        assert(p->value != bl_arr[i]->value);
   16.94 +        assert(p->mime_type != bl_arr[i]->mime_type || !(p->mime_type || bl_arr[i]->mime_type));
   16.95 +        assert(p->filename != bl_arr[i]->filename || !(p->filename || bl_arr[i]->filename));
   16.96 +        
   16.97 +        p = p->next;
   16.98 +    }
   16.99 +    assert(p == NULL);
  16.100 +    
  16.101 +    cout << "\nduplicating four-element list...\n\n";
  16.102 +    bloblist_t* duplist = bloblist_dup(new_bl);
  16.103 +    
  16.104 +    p = new_bl;
  16.105 +    bloblist_t* dup_p = duplist;
  16.106 +    
  16.107 +    while (dup_p) {
  16.108 +        assert(test_bloblist_node_equals(p, dup_p));
  16.109 +        assert(p != dup_p);
  16.110 +        assert(p->value != dup_p->value);
  16.111 +        assert(p->mime_type != dup_p->mime_type || !(p->mime_type || dup_p->mime_type));
  16.112 +        assert(p->filename != dup_p->filename || !(p->filename || dup_p->filename));
  16.113 +
  16.114 +        dup_p = dup_p->next;
  16.115 +        p = p->next;
  16.116 +        assert((p == NULL) == (dup_p == NULL));
  16.117 +    }
  16.118 +    cout << "\nfour-element bloblist successfully duplicated.\n\n";
  16.119 +
  16.120 +    cout << "freeing bloblists...\n";
  16.121 +    free_bloblist(new_bl);
  16.122 +    free_bloblist(duplist);
  16.123 +    new_bl = NULL;
  16.124 +    duplist = NULL;
  16.125 +    free(text1);
  16.126 +    free(text2);
  16.127 +    free(text3);
  16.128 +    free(text4);    
  16.129 +    cout << "done.\n";
  16.130 +        
  16.131 +    
  16.132 +    return 0;
  16.133 +}
  16.134 +
    17.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    17.2 +++ b/test/identity_list_test.cc	Mon Jul 18 08:54:43 2016 +0200
    17.3 @@ -0,0 +1,172 @@
    17.4 +#include <stdlib.h>
    17.5 +#include <string.h>
    17.6 +#include "platform.h"
    17.7 +#include <iostream>
    17.8 +#include <fstream>
    17.9 +#include <assert.h>
   17.10 +
   17.11 +#include "identity_list.h"
   17.12 +
   17.13 +using namespace std;
   17.14 +
   17.15 +/*
   17.16 + *     char *address;              // C string with address UTF-8 encoded
   17.17 +    char *fpr;                  // C string with fingerprint UTF-8 encoded
   17.18 +    char *user_id;              // C string with user ID UTF-8 encoded
   17.19 +    char *username;             // C string with user name UTF-8 encoded
   17.20 +    PEP_comm_type comm_type;    // type of communication with this ID
   17.21 +    char lang[3];               // language of conversation
   17.22 +                                // ISO 639-1 ALPHA-2, last byte is 0
   17.23 +    bool me;                    // if this is the local user herself/himself
   17.24 +    */
   17.25 +
   17.26 +int test_identity_equals(pEp_identity* val1, pEp_identity* val2) {
   17.27 +    assert(val1);
   17.28 +    assert(val2);
   17.29 +    assert(val1->address);
   17.30 +    assert(val2->address);
   17.31 +    assert(val1->fpr);
   17.32 +    assert(val2->fpr);
   17.33 +    assert(val1->username);
   17.34 +    assert(val2->username);
   17.35 +    return((strcmp(val1->address, val2->address) == 0) && (strcmp(val1->fpr, val2->fpr) == 0)
   17.36 +        && (strcmp(val1->username, val2->username) == 0) && (val1->comm_type == val2->comm_type)
   17.37 +        && (val1->lang[0] == val2->lang[0]) && (val1->lang[1] == val2->lang[1])
   17.38 +        && (val1->lang[2] == val2->lang[2]) && (val1->me == val2->me));
   17.39 +}
   17.40 +
   17.41 +int main() {
   17.42 +    cout << "\n*** data structures: identity_list_test ***\n\n";
   17.43 +
   17.44 +    pEp_identity* id1 = new_identity(
   17.45 +        "leon.schumacher@digitalekho.com",
   17.46 +        "8BD08954C74D830EEFFB5DEB2682A17F7C87F73D",
   17.47 +        "23",
   17.48 +        "Leon Schumacher"
   17.49 +    );
   17.50 +    id1->comm_type = PEP_ct_pEp;
   17.51 +    
   17.52 +    pEp_identity* id2 = new_identity(
   17.53 +        "krista@kgrothoff.org",
   17.54 +        "62D4932086185C15917B72D30571AFBCA5493553",
   17.55 +        "42",
   17.56 +        "Krista Bennett Grothoff"
   17.57 +    );
   17.58 +    
   17.59 +    id2->comm_type = PEP_ct_OpenPGP;
   17.60 +
   17.61 +    pEp_identity* id3 = new_identity(
   17.62 +        "krista@pep-project.org",
   17.63 +        "51BF42D25BB5B154D71BF6CD3CF25B776D149247",
   17.64 +        "10",
   17.65 +        "Krista Grothoff"
   17.66 +    );
   17.67 +    
   17.68 +    id3->comm_type = PEP_ct_OTR;
   17.69 +
   17.70 +    pEp_identity* id4 = new_identity(
   17.71 +        "papa@smurf.lu",
   17.72 +        "00001111222233334444555566667777DEADBEEF",
   17.73 +        "667",
   17.74 +        "Papa Smurf"
   17.75 +    );
   17.76 +    
   17.77 +    id4->comm_type = PEP_ct_key_b0rken;
   17.78 +    
   17.79 +    pEp_identity* id_arr[4] = {id1, id2, id3, id4};
   17.80 +        
   17.81 +    int i;
   17.82 +        
   17.83 +    cout << "creating one-element identity_list...\n";
   17.84 +    
   17.85 +    pEp_identity* new_id = identity_dup(id1);
   17.86 +    assert(new_id);
   17.87 +    identity_list* idlist = new_identity_list(new_id);
   17.88 +    assert(idlist->ident);
   17.89 +    assert(test_identity_equals(id1, idlist->ident));
   17.90 +    assert(idlist->next == NULL);
   17.91 +    cout << "one-element identity_list created, next element is NULL\n\n";
   17.92 +    
   17.93 +    cout << "duplicating one-element list...\n";
   17.94 +    identity_list* duplist = identity_list_dup(idlist);
   17.95 +    pEp_identity* srcid = idlist->ident;
   17.96 +    pEp_identity* dstid = duplist->ident;
   17.97 +    assert(dstid);
   17.98 +    assert(test_identity_equals(srcid, dstid));
   17.99 +    assert(srcid->address != dstid->address);   // test deep copies 
  17.100 +    assert(srcid->fpr != dstid->fpr);
  17.101 +    assert(srcid->username != dstid->username);
  17.102 +    assert(duplist->next == NULL);
  17.103 +    cout << "one-element identity_list duplicated.\n\n";
  17.104 +    
  17.105 +    cout << "freeing identity_lists...\n";
  17.106 +    free_identity_list(idlist); // will free srcid
  17.107 +    free_identity_list(duplist);
  17.108 +    idlist = NULL;
  17.109 +    duplist = NULL;
  17.110 +    srcid = NULL;
  17.111 +    
  17.112 +    identity_list* p;
  17.113 +    cout << "\ncreating four-element list...\n";
  17.114 +    idlist = identity_list_add(idlist, identity_dup(id_arr[0]));
  17.115 +    for (i = 1; i < 4; i++) {
  17.116 +        p = identity_list_add(idlist, identity_dup(id_arr[i]));
  17.117 +        assert(p);
  17.118 +    }
  17.119 +    
  17.120 +    p = idlist;
  17.121 +    
  17.122 +    for (i = 0; i < 4; i++) {
  17.123 +        assert(p);
  17.124 +        
  17.125 +        srcid = p->ident;
  17.126 +        assert(srcid);
  17.127 +        
  17.128 +        assert(test_identity_equals(srcid, id_arr[i]));
  17.129 +        assert(srcid->address != id_arr[i]->address);   // test deep copies
  17.130 +        assert(srcid->fpr != id_arr[i]->fpr);
  17.131 +        assert(srcid->username != id_arr[i]->username);
  17.132 +
  17.133 +        p = p->next;
  17.134 +    }
  17.135 +    assert(p == NULL);
  17.136 +    
  17.137 +    cout << "\nduplicating four-element list...\n\n";
  17.138 +    duplist = identity_list_dup(idlist);
  17.139 +    
  17.140 +    p = idlist;
  17.141 +    identity_list* dup_p = duplist;
  17.142 +    
  17.143 +    while (dup_p) {
  17.144 +        srcid = p->ident;
  17.145 +        dstid = dup_p->ident;
  17.146 +
  17.147 +        assert(dstid);
  17.148 +        
  17.149 +        assert(test_identity_equals(srcid, dstid));
  17.150 +
  17.151 +        assert(srcid != dstid);   // test deep copies
  17.152 +        assert(srcid->address != dstid->address);   // test deep copies
  17.153 +        assert(srcid->fpr != dstid->fpr);
  17.154 +        assert(srcid->username != dstid->username);
  17.155 +        
  17.156 +        i++;
  17.157 +        p = p->next;
  17.158 +
  17.159 +        dup_p = dup_p->next;
  17.160 +        assert((p == NULL) == (dup_p == NULL));
  17.161 +    }
  17.162 +    cout << "\nfour-element identity_list successfully duplicated.\n\n";
  17.163 +
  17.164 +    cout << "freeing identity_lists...\n";
  17.165 +    free_identity_list(idlist); // will free srcid
  17.166 +    free_identity_list(duplist);
  17.167 +    idlist = NULL;
  17.168 +    duplist = NULL;
  17.169 +    
  17.170 +    cout << "done.\n";
  17.171 +        
  17.172 +    
  17.173 +    return 0;
  17.174 +}
  17.175 +