/[winpt]/trunk/Src/wptGPGMEData.cpp
ViewVC logotype

Diff of /trunk/Src/wptGPGMEData.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 226 by twoaday, Mon Jun 12 13:40:21 2006 UTC revision 455 by twoaday, Thu Aug 2 20:01:53 2012 UTC
# Line 29  Line 29 
29    
30  #include "wptUtil.h"  #include "wptUtil.h"
31  #include "wptGPG.h"  #include "wptGPG.h"
32    #include "wptTypes.h"
33    
34    /* Default buffer size */
35    #define BUFSIZE 128
36    
37    
38  /* Implement a word based line break. @inp is the input buffer  /* Implement a word based line break. @inp is the input buffer
# Line 43  wrap_lines (char *inp, size_t inlen, siz Line 47  wrap_lines (char *inp, size_t inlen, siz
47      size_t n;      size_t n;
48    
49      inp[inlen] = 0;      inp[inlen] = 0;
50      if (inp[inlen-2] == '\r' && inp[inlen-1] == '\n')      if (inlen > 2 && inp[inlen-2] == '\r' && inp[inlen-1] == '\n')
51          end_is_le = 1;          end_is_le = 1;
52      out = (char *)calloc (1, 4*inlen/3+2+1);      out = (char *)calloc (1, 4*inlen/3+2+1);
53      if (!out)      if (!out)
# Line 129  gpgme_error_t Line 133  gpgme_error_t
133  gpg_data_mail_quote (gpgme_data_t *r_dh)  gpg_data_mail_quote (gpgme_data_t *r_dh)
134  {  {
135      gpgme_data_t dh;      gpgme_data_t dh;
136      char buf[128];      char buf[BUFSIZE+1];
137    
138      if (!*r_dh)      if (!*r_dh)
139          return gpg_error (GPG_ERR_INV_ARG);          return gpg_error (GPG_ERR_INV_ARG);
140      gpgme_data_new (&dh);      gpgme_data_new (&dh);
141      while (gpg_data_readline (*r_dh, buf, sizeof (buf)-1)) {      while (gpg_data_readline (*r_dh, buf, DIM (buf)-1)) {
142          gpgme_data_write (dh, "> ", 2);          gpgme_data_write (dh, "> ", 2);
143          gpgme_data_write (dh, buf, strlen (buf));          gpgme_data_write (dh, buf, strlen (buf));
144      }      }
# Line 152  is_armor_header (const char *line) Line 156  is_armor_header (const char *line)
156          "Comment:",          "Comment:",
157          "Charset:",          "Charset:",
158          "Hash:",          "Hash:",
159          "MessageID",          "MessageID:",
160          NULL          NULL
161      };      };
     int i;  
162    
163      for (i=0; header[i] != NULL; i++) {      for (size_t i=0; header[i] != NULL; i++) {
164          if (!strncmp (line, header[i], strlen (header[i])))          if (!strncmp (line, header[i], strlen (header[i])))
165              return -1;              return -1;
166      }      }
# Line 165  is_armor_header (const char *line) Line 168  is_armor_header (const char *line)
168  }  }
169    
170    
   
171  /* Extract the plaintext data from the escaped data object @sig.  /* Extract the plaintext data from the escaped data object @sig.
172     The plaintxt is stored in @r_plain.     The plaintxt is stored in @r_plain.
173     Return value: 0 on success. */     Return value: 0 on success. */
# Line 174  gpg_data_extract_plaintext (gpgme_data_t Line 176  gpg_data_extract_plaintext (gpgme_data_t
176  {  {
177      gpgme_data_t plain;      gpgme_data_t plain;
178      gpgme_error_t err;      gpgme_error_t err;
179      char line[128+32];      char line[BUFSIZE+32];
180      int pos = 0;      int pos = 0;
181            
182      if (r_plain)      if (r_plain)
# Line 183  gpg_data_extract_plaintext (gpgme_data_t Line 185  gpg_data_extract_plaintext (gpgme_data_t
185      if (err)      if (err)
186          return err;          return err;
187            
188      while (gpg_data_readline (sig, line, 128) > 0) {      while (gpg_data_readline (sig, line, BUFSIZE) > 0) {
189          if (!strncmp (line, "-----BEGIN PGP SIGNED MESSAGE", 29) ||          if (!strncmp (line, "-----BEGIN PGP SIGNED MESSAGE", 29) ||
190              is_armor_header (line))              is_armor_header (line))
191              continue;              continue;
# Line 192  gpg_data_extract_plaintext (gpgme_data_t Line 194  gpg_data_extract_plaintext (gpgme_data_t
194      }      }
195    
196      /* We just support 1 nesting level. */      /* We just support 1 nesting level. */
197      while (gpg_data_readline (sig, line, 128) > 0 ) {      while (gpg_data_readline (sig, line, BUFSIZE) > 0 ) {
198          if (!strncmp( line, "-----BEGIN PGP SIGNATURE", 24))          if (!strncmp (line, "-----BEGIN PGP SIGNATURE", 24))
199              break; /* end of plaintext */              break; /* end of plaintext */
200          if (!strncmp (line, "- -", 3))          if (!strncmp (line, "- -", 3))
201              pos = 2;              pos = 2;
# Line 214  gpg_data_extract_plaintext (gpgme_data_t Line 216  gpg_data_extract_plaintext (gpgme_data_t
216  gpgme_error_t  gpgme_error_t
217  gpg_data_release_and_set_file (gpgme_data_t dh, const char *fname)  gpg_data_release_and_set_file (gpgme_data_t dh, const char *fname)
218  {  {
219      char *p = NULL;      FILE *fp = fopen (fname, "wb");
     FILE *fp;  
     size_t n;  
       
     fp = fopen (fname, "wb");  
220      if (fp == NULL)      if (fp == NULL)
221          return gpg_error (GPG_ERR_ENOENT);          return gpg_error (GPG_ERR_ENOENT);
222            
223      p = gpgme_data_release_and_get_mem (dh, &n);      size_t n;
224      if (p) {      char *p = gpgme_data_release_and_get_mem (dh, &n);
225        if (p != NULL) {
226          fwrite (p, 1, n, fp);          fwrite (p, 1, n, fp);
227          fflush (fp);          fflush (fp);
228          memset (p, 0xFF, n);          wipememory (p, n);
229          gpgme_free (p);          gpgme_free (p);
230      }      }
231      fclose (fp);      fclose (fp);
# Line 238  gpg_data_release_and_set_file (gpgme_dat Line 237  gpg_data_release_and_set_file (gpgme_dat
237     gpgme data object @dh into @line.     gpgme data object @dh into @line.
238     Return value: numbers of chars read. */     Return value: numbers of chars read. */
239  size_t  size_t
240  gpg_data_readline (gpgme_data_t dh, char *line, size_t nbytes)  gpg_data_readline (gpgme_data_t dh, char *line, size_t maxbytes)
241  {  {
242      char ch = 0;      char ch = 0;
243      int nread = 0, pos = 0;      int nread = 0, pos = 0;
# Line 246  gpg_data_readline (gpgme_data_t dh, char Line 245  gpg_data_readline (gpgme_data_t dh, char
245      if (!dh)      if (!dh)
246          return 0;          return 0;
247            
248      memset (line, 0, nbytes);      memset (line, 0, maxbytes);
249      while ((nread=gpgme_data_read (dh, &ch, 1)) > 0) {      while ((nread=gpgme_data_read (dh, &ch, 1)) > 0) {
250          if (!nread)          if (!nread)
251              break;              break;
# Line 256  gpg_data_readline (gpgme_data_t dh, char Line 255  gpg_data_readline (gpgme_data_t dh, char
255              break;              break;
256          }          }
257          line[pos++] = ch;          line[pos++] = ch;
258          if (pos > (int)nbytes) {          if (pos > (int)maxbytes-1) {
259              line[pos++] = '\0';              line[pos] = '\0';
260              break;              break;
261          }          }
262      }      }

Legend:
Removed from v.226  
changed lines
  Added in v.455

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26