sync: more debug information when NDEBUG is not defined
authorEdouard Tisserant <edouard@pep-project.org>
Fri, 16 Dec 2016 19:13:00 +0100
changeset 149427ded4922ae2
parent 1492 cc9037bf19d2
child 1495 1397da6f9084
sync: more debug information when NDEBUG is not defined
src/sync.c
src/sync_impl.c
     1.1 --- a/src/sync.c	Thu Dec 15 17:34:04 2016 +0100
     1.2 +++ b/src/sync.c	Fri Dec 16 19:13:00 2016 +0100
     1.3 @@ -170,17 +170,21 @@
     1.4              break;
     1.5          else if(msg == NULL && timeout != 0){
     1.6              status = fsm_DeviceState_inject(session, Timeout, NULL, NULL, &timeout);
     1.7 +#ifndef NDEBUG
     1.8              char buffer[MAX_LINELENGTH];
     1.9              memset(buffer, 0, MAX_LINELENGTH);
    1.10              snprintf(buffer, MAX_LINELENGTH, "problem with timeout event : %d\n", (int) status);
    1.11              log_event(session, buffer, "pEp sync protocol", NULL, NULL);
    1.12              continue;
    1.13 +#endif
    1.14          }
    1.15          else if ((status = receive_sync_msg(session, msg, &timeout) != PEP_STATUS_OK)) {
    1.16 +#ifndef NDEBUG
    1.17              char buffer[MAX_LINELENGTH];
    1.18              memset(buffer, 0, MAX_LINELENGTH);
    1.19              snprintf(buffer, MAX_LINELENGTH, "problem with msg received: %d\n", (int) status);
    1.20              log_event(session, buffer, "pEp sync protocol", NULL, NULL);
    1.21 +#endif
    1.22          }
    1.23      }
    1.24  
     2.1 --- a/src/sync_impl.c	Thu Dec 15 17:34:04 2016 +0100
     2.2 +++ b/src/sync_impl.c	Fri Dec 16 19:13:00 2016 +0100
     2.3 @@ -484,6 +484,18 @@
     2.4      ASN_STRUCT_FREE(asn_DEF_DeviceGroup_Protocol, msg);
     2.5  }
     2.6  
     2.7 +int _append(const void *buffer, size_t size, void *appkey)
     2.8 +{
     2.9 +    char **dest_ptr = (char **)appkey;
    2.10 +    size_t osize = strlen(*dest_ptr);
    2.11 +    size_t nsize = size + osize;
    2.12 +    *dest_ptr = realloc(*dest_ptr, nsize + 1);
    2.13 +    if(*dest_ptr == NULL) return -1;
    2.14 +    memcpy(*dest_ptr + osize, buffer, size);
    2.15 +    (*dest_ptr)[nsize] = '\0';
    2.16 +    return 0;
    2.17 +}
    2.18 +
    2.19  PEP_STATUS unicast_msg(
    2.20          PEP_SESSION session,
    2.21          const Identity partner,
    2.22 @@ -566,6 +578,14 @@
    2.23      free_identity(me);
    2.24      me = NULL;
    2.25  
    2.26 +#ifndef NDEBUG
    2.27 +    asn_enc_rval_t er;
    2.28 +    er = xer_encode(&asn_DEF_DeviceGroup_Protocol, msg, 
    2.29 +                    XER_F_BASIC, _append, &_message->longmsg);
    2.30 +    if(er.encoded == -1)
    2.31 +        goto error;
    2.32 +#endif
    2.33 +
    2.34      if (encrypted) {
    2.35          if (msg->payload.present == DeviceGroup_Protocol__payload_PR_groupKeys || 
    2.36              msg->payload.present == DeviceGroup_Protocol__payload_PR_groupUpdate) {