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

Diff of /trunk/Src/wptOwnertrustDlg.cpp

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

revision 25 by twoaday, Wed Oct 12 10:04:26 2005 UTC revision 225 by twoaday, Tue Jun 6 13:37:59 2006 UTC
# Line 1  Line 1 
1  /* wptOwnertrust.cpp - Ownertrust im- and export  /* wptOwnertrust.cpp - Ownertrust im- and export
2   *      Copyright (C) 2001, 2002, 2003, 2005 Timo Schulz   *      Copyright (C) 2001, 2002, 2003, 2005, 2006 Timo Schulz
3   *      Copyright (C) 2005 g10 Code GmbH   *      Copyright (C) 2005 g10 Code GmbH
4   *   *
5   * This file is part of WinPT.   * This file is part of WinPT.
6   *   *
7   * WinPT is free software; you can redistribute it and/or modify   * WinPT is free software; you can redistribute it and/or modify
8   * it under the terms of the GNU General Public License as published by   * it under the terms of the GNU General Public License as published by
9   * the Free Software Foundation; either version 2 of the License, or   * the Free Software Foundation; either version 2 of the License, or
10   * (at your option) any later version.   * (at your option) any later version.
11   *   *
12   * WinPT is distributed in the hope that it will be useful,   * WinPT is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15   * GNU General Public License for more details.   * GNU General Public License for more details.
16   *   *
17   * You should have received a copy of the GNU General Public License   * You should have received a copy of the GNU General Public License
18   * along with WinPT; if not, write to the Free Software Foundation,   * along with WinPT; if not, write to the Free Software Foundation,
19   * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA   * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
20   */   */
21    #ifdef HAVE_CONFIG_H
22  #include <windows.h>  #include <config.h>
23  #include <errno.h>  #endif
24  #include <sys/stat.h>  
25    #include <windows.h>
26  #include "../resource.h"  #include <sys/stat.h>
27  #include "wptTypes.h"  
28  #include "wptGPG.h"  #include "resource.h"
29  #include "wptErrors.h"  #include "wptTypes.h"
30  #include "wptNLS.h"  #include "wptGPG.h"
31  #include "wptW32API.h"  #include "wptErrors.h"
32    #include "wptNLS.h"
33    #include "wptW32API.h"
34  /* Export the ownertrust to the file @fname.  
35     Return value: 0 on success. */  
36  static gpgme_error_t  /* Export the ownertrust to the file @fname.
37  gpg_export_ownertrust (const char *fname)     Return value: 0 on success. */
38  {  static gpgme_error_t
39      gpgme_error_t err;  gpg_export_ownertrust (const char *fname)
40      char *ot_data = NULL;  {
41      FILE *f;      gpgme_error_t err;
42        char *ot_data = NULL;
43      err = gpg_manage_ownertrust (&ot_data, 1);      FILE *f;
44      if (err)  
45          return err;      err = gpg_manage_ownertrust (&ot_data, 1);
46      f = fopen (fname, "wb");      if (err)
47      if (f) {          return err;
48          fwrite (ot_data, 1, strlen (ot_data), f);      f = fopen (fname, "wb");
49          fclose (f);      if (f) {
50      }          fwrite (ot_data, 1, strlen (ot_data), f);
51      else          fclose (f);
52          err = gpg_error_from_errno (errno);      }
53      free (ot_data);      else
54      return 0;          err = gpg_error (GPG_ERR_ENOENT);
55  }      safe_free (ot_data);
56        return 0;
57    }
58  /* Import the ownertrust from file @fname.  
59     Return value: 0 on success. */  
60  static gpgme_error_t  /* Import the ownertrust from file @fname.
61  gpg_import_ownertrust (const char *fname)     Return value: 0 on success. */
62  {  static gpgme_error_t
63      gpgme_error_t err;  gpg_import_ownertrust (const char *fname)
64      FILE *f;  {
65      struct stat st;      gpgme_error_t err;
66      char *ot_data;      FILE *f;
67        struct stat st;
68      if (stat (fname, &st))      char *ot_data;
69          return gpg_error_from_errno (errno);  
70      f = fopen (fname, "rb");      if (stat (fname, &st))
71      if (!f)          return gpg_error (GPG_ERR_ENOENT);
72          return gpg_error_from_errno (errno);      f = fopen (fname, "rb");
73      ot_data = (char*)calloc (1, st.st_size+1);      if (!f)
74      if (!ot_data)          return gpg_error (GPG_ERR_ENOENT);
75          BUG (NULL);      ot_data = (char*)calloc (1, st.st_size+1);
76      fread (ot_data, 1, st.st_size, f);      if (!ot_data)
77      fclose (f);          BUG (NULL);
78        fread (ot_data, 1, st.st_size, f);
79      err = gpg_manage_ownertrust (&ot_data, 0);      fclose (f);
80    
81      free (ot_data);      err = gpg_manage_ownertrust (&ot_data, 0);
82      return 0;  
83  }      safe_free (ot_data);
84        return 0;
85    }
86  /* Dialog procedure to manage the ownertrust. */  
87  BOOL CALLBACK  
88  ownertrust_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)  /* Dialog procedure to manage the ownertrust. */
89  {  BOOL CALLBACK
90      gpgme_error_t err;  ownertrust_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
91      const char *fname;  {
92            gpgme_error_t err;
93      switch( msg ) {      const char *fname;
94      case WM_INITDIALOG:      
95      #ifndef LANG_DE      switch( msg ) {
96          SetWindowText( dlg, _("Ownertrust") );      case WM_INITDIALOG:
97          SetDlgItemText( dlg, IDC_OWNERTRUST_INFO, _("File") );          SetWindowText (dlg, _("Ownertrust"));
98          SetDlgItemText( dlg, IDC_OWNERTRUST_DESC,          SetDlgItemText (dlg, IDC_OWNERTRUST_INFO, _("File"));
99                         _("Here it is possible to save or restore the ownertrust from the "          SetDlgItemText (dlg, IDC_OWNERTRUST_DESC,
100                           "'trustdb' file. This could be very useful because the values are NOT "                         _("Here it is possible to save or restore the ownertrust from the "
101                           "stored in the keyring.") );                           "'trustdb' file. This could be very useful because the values are NOT "
102      #endif                           "stored in the keyring."));
103          center_window( dlg, NULL );          SetDlgItemText (dlg, IDCANCEL, _("&Close"));
104          SetForegroundWindow( dlg );          center_window (dlg, NULL);
105          return TRUE;          SetForegroundWindow (dlg);
106                    return TRUE;
107      case WM_SYSCOMMAND:          
108          if (LOWORD (wparam) == SC_CLOSE)      case WM_COMMAND:
109              EndDialog (dlg, TRUE);          switch (LOWORD (wparam)) {
110          return TRUE;          case IDC_OWNERTRUST_EXPORT:
111                        fname = get_filesave_dlg (dlg, _("Select File Name for Output"), NULL, NULL);
112      case WM_COMMAND:              if (!fname)
113          switch (LOWORD (wparam)) {                  return TRUE;
114          case IDC_OWNERTRUST_EXPORT:              err = gpg_export_ownertrust (fname);
115              fname = get_filesave_dlg (dlg, _("Select file name for output"), NULL, NULL);              if (err) {
116              if (!fname)                  msg_box (dlg, gpgme_strerror( err ), _("Ownertrust"), MB_ERR );
117                  return TRUE;                  return TRUE;
118              err = gpg_export_ownertrust (fname);              }
119              if (err) {              status_box (dlg, _("Ownertrust successfully exported."), _("GnuPG Status"));
120                  msg_box (dlg, gpgme_strerror( err ), _("Ownertrust"), MB_ERR );              return TRUE;
121                  return TRUE;  
122              }          case IDC_OWNERTRUST_IMPORT:
123              status_box (dlg, _("Ownertrust successfully exported."), _("GnuPG Status"));              fname = get_fileopen_dlg (dlg, _("Select File Name for Input"), NULL, NULL);
124              return TRUE;              if (!fname)
125                    return TRUE;
126          case IDC_OWNERTRUST_IMPORT:              err = gpg_import_ownertrust (fname);
127              fname = get_fileopen_dlg (dlg, _("Select file name for input"), NULL, NULL);              if (err) {
128              if (!fname)                  msg_box (dlg, gpgme_strerror (err), _("Ownertrust"), MB_ERR);
129                  return TRUE;                  return TRUE;
130              err = gpg_import_ownertrust (fname);              }
131              if (err) {              status_box (dlg, _("Ownertrust succefully imported."), _("GnuPG Status"));
132                  msg_box (dlg, gpgme_strerror (err), _("Ownertrust"), MB_ERR);              return TRUE;
133                  return TRUE;              
134              }          case IDCANCEL:
135              status_box (dlg, _("Ownertrust succefully imported."), _("GnuPG Status"));              EndDialog (dlg, FALSE);
136              return TRUE;              return TRUE;
137                        }
138          case IDCANCEL:          break;
139              EndDialog (dlg, FALSE);      }
140              return TRUE;      
141          }      return FALSE;
142          break;  }
     }  
       
     return FALSE;  
 }  

Legend:
Removed from v.25  
changed lines
  Added in v.225

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26