go on...
authorvb
Sun, 01 Mar 2015 21:51:53 +0100
changeset 82d0ad5655688a
parent 81 044ce1c7fc9c
child 83 c5d82f11689a
go on...
src/message_api.c
src/platform_windows.cpp
src/platform_windows.h
     1.1 --- a/src/message_api.c	Sun Mar 01 15:32:16 2015 +0100
     1.2 +++ b/src/message_api.c	Sun Mar 01 21:51:53 2015 +0100
     1.3 @@ -33,6 +33,61 @@
     1.4      return ptext;
     1.5  }
     1.6  
     1.7 +static int seperate_short_and_long(const char *src, char **shortmsg, char **longmsg)
     1.8 +{
     1.9 +    char *_shortmsg = NULL;
    1.10 +    char *_longmsg = NULL;
    1.11 +
    1.12 +    assert(src);
    1.13 +    assert(shortmsg);
    1.14 +    assert(longmsg);
    1.15 +
    1.16 +    *shortmsg = NULL;
    1.17 +    *longmsg = NULL;
    1.18 +
    1.19 +    if (strncmp(src, "subject: ", 9) == 0) {
    1.20 +        char *line_end = strchr(src, '\n');
    1.21 +        
    1.22 +        if (line_end == NULL) {
    1.23 +            _shortmsg = strdup(src + 9);
    1.24 +            if (_shortmsg == NULL)
    1.25 +                goto enomem;
    1.26 +            // _longmsg = NULL;
    1.27 +        }
    1.28 +        else {
    1.29 +            size_t n = line_end - src;
    1.30 +            if (*(line_end - 1) == '\r')
    1.31 +                _shortmsg = strndup(src + 9, n - 1);
    1.32 +            else
    1.33 +                _shortmsg = strndup(src + 9, n);
    1.34 +            if (_shortmsg == NULL)
    1.35 +                goto enomem;
    1.36 +            _longmsg = strdup(src + n);
    1.37 +            if (_longmsg == NULL)
    1.38 +                goto enomem;
    1.39 +        }
    1.40 +    }
    1.41 +    else {
    1.42 +        _shortmsg = strdup("pEp");
    1.43 +        if (_shortmsg == NULL)
    1.44 +            goto enomem;
    1.45 +        _longmsg = strdup(src);
    1.46 +        if (_longmsg == NULL)
    1.47 +            goto enomem;
    1.48 +    }
    1.49 +    
    1.50 +    *shortmsg = _shortmsg;
    1.51 +    *longmsg = _longmsg;
    1.52 +
    1.53 +    return 0;
    1.54 +
    1.55 +enomem:
    1.56 +    free(_shortmsg);
    1.57 +    free(_longmsg);
    1.58 +
    1.59 +    return -1;
    1.60 +}
    1.61 +
    1.62  static message * clone_to_empty_message(const message * src)
    1.63  {
    1.64      pEp_identity *from = NULL;
    1.65 @@ -44,8 +99,6 @@
    1.66      assert(src->from);
    1.67      assert(src->to);
    1.68  
    1.69 -    msg->dir = src->dir;
    1.70 -
    1.71      from = identity_dup(src->from);
    1.72      if (from == NULL)
    1.73          goto enomem;
    1.74 @@ -60,6 +113,8 @@
    1.75      if (msg == NULL)
    1.76          goto enomem;
    1.77  
    1.78 +    msg->dir = src->dir;
    1.79 +
    1.80      if (src->cc) {
    1.81          msg->cc = identity_list_dup(src->cc);
    1.82          if (msg->cc == NULL)
    1.83 @@ -373,9 +428,55 @@
    1.84  
    1.85      switch (enc_format) {
    1.86          case PEP_enc_none:
    1.87 +            if (src->enc_format == PEP_enc_PEP) {
    1.88 +                // TODO: implement
    1.89 +                NOT_IMPLEMENTED
    1.90 +            }
    1.91 +
    1.92              break;
    1.93  
    1.94          case PEP_enc_none_MIME:
    1.95 +            if (src->enc_format == PEP_enc_PEP) {
    1.96 +                // TODO: implement
    1.97 +                NOT_IMPLEMENTED
    1.98 +            }
    1.99 +
   1.100 +            char *ctext = src->longmsg;
   1.101 +            size_t csize = strlen(src->longmsg);
   1.102 +            char *ptext;
   1.103 +            size_t psize;
   1.104 +            stringlist_t *keylist;
   1.105 +
   1.106 +            status = decrypt_and_verify(session, ctext, csize, &ptext, &psize,
   1.107 +                    &keylist);
   1.108 +            if (ptext == NULL)
   1.109 +                goto pep_error;
   1.110 +
   1.111 +            if (src->enc_format == PEP_enc_MIME_multipart) {
   1.112 +                if (src->shortmsg == NULL || strcmp(src->shortmsg, "pEp") == 0)
   1.113 +                {
   1.114 +                    char * shortmsg;
   1.115 +                    char * longmsg;
   1.116 +
   1.117 +                    int r = seperate_short_and_long(ptext, &shortmsg,
   1.118 +                            &longmsg);
   1.119 +                    free(ptext);
   1.120 +                    if (r == -1)
   1.121 +                        goto enomem;
   1.122 +
   1.123 +                    msg->shortmsg = shortmsg;
   1.124 +                    msg->longmsg = longmsg;
   1.125 +                }
   1.126 +                else {
   1.127 +                    msg->shortmsg = strdup(src->shortmsg);
   1.128 +                    if (msg->shortmsg == NULL)
   1.129 +                        goto enomem;
   1.130 +                    msg->longmsg = ptext;
   1.131 +                }
   1.132 +            }
   1.133 +            else {
   1.134 +                
   1.135 +            }
   1.136              break;
   1.137  
   1.138          default:
     2.1 --- a/src/platform_windows.cpp	Sun Mar 01 15:32:16 2015 +0100
     2.2 +++ b/src/platform_windows.cpp	Sun Mar 01 21:51:53 2015 +0100
     2.3 @@ -203,9 +203,15 @@
     2.4      return (long) (r & ((1<<31)-1));
     2.5  }
     2.6  
     2.7 -#ifndef strtok_r
     2.8 -#define strtok_r(A, B, C) strtok_s((A), (B), (C))
     2.9 -#endif
    2.10 +char *strndup(const char *s1, size_t n)
    2.11 +{
    2.12 +    char *str = (char *) calloc(n + 1, 1);
    2.13 +    if (str == NULL)
    2.14 +        return NULL;
    2.15 +
    2.16 +    strncpy(str, s1, n);
    2.17 +    return str;
    2.18 +}
    2.19  
    2.20  } // "C"
    2.21  
     3.1 --- a/src/platform_windows.h	Sun Mar 01 15:32:16 2015 +0100
     3.2 +++ b/src/platform_windows.h	Sun Mar 01 21:51:53 2015 +0100
     3.3 @@ -19,11 +19,11 @@
     3.4  int dlclose(void *handle);
     3.5  void *dlsym(void *handle, const char *symbol);
     3.6  
     3.7 -char *strtok_r(
     3.8 -        char *restrict str,
     3.9 -        const char *restrict sep,
    3.10 -        char **restrict lasts
    3.11 -    );
    3.12 +#ifndef strtok_r
    3.13 +#define strtok_r(A, B, C) strtok_s((A), (B), (C))
    3.14 +#endif
    3.15 +
    3.16 +char *strndup(const char *s1, size_t n);
    3.17  
    3.18  const char *windoze_local_db(void);
    3.19  const char *windoze_system_db(void);