/[gpgoe]/trunk/src/GPGOE.c
ViewVC logotype

Diff of /trunk/src/GPGOE.c

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

revision 1 by twoaday, Fri Mar 24 13:36:54 2006 UTC revision 19 by twoaday, Sun Jun 4 10:12:47 2006 UTC
# Line 27  Line 27 
27  #include "gpgme.h"  #include "gpgme.h"
28  #include "GPGOE.h"  #include "GPGOE.h"
29    
   
30  /* Global DLL module handle. */  /* Global DLL module handle. */
31  HINSTANCE mod_hinst_dll;  HINSTANCE mod_hinst_dll;
32    
33    /* Outlook Express old window procedure. */
34    WNDPROC oe_proc_old;
35    
36  /* DLL hook handle for the CBT function. */  /* DLL hook handle for the CBT function. */
37  static HHOOK ctb_hook = NULL;  static HHOOK ctb_hook = NULL;
38    
39  /* Outlook Express window handle. */  /* Outlook Express window handle. */
40  static HWND oe_hwnd = NULL;  static HWND oe_hwnd = NULL;
41    
42  /* Outlook Express old window procedure. */  /* We need a shared section to define variables which
43  WNDPROC oe_proc_old;     will keep their values in all address spaces. */
44    #ifndef __GNUC__
45    #pragma  data_seg(".SHARDAT")
46    #endif
47    /* Supported GPGOE feature modes. */
48    int gpgoe_active_modes ATTR_SEC = 0;
49    
50    char gpgoe_pass_cache[HASH_BUCKETS][256];
51    #ifndef __GNUC__
52    #pragma data_seg()
53    #endif
54    
55    
56  /* Main DLL entry point. */  /* Main DLL entry point. */
# Line 65  DllMain (HINSTANCE hinst_dll, DWORD reas Line 77  DllMain (HINSTANCE hinst_dll, DWORD reas
77  }  }
78    
79    
80    /* Quick and dirty check if the dialog is a common dialog
81       and the 'File {Open, Save}' style. */
82    static int
83    is_common_file_dlg (HWND h)
84    {
85        HWND button = GetDlgItem (h, 1040);
86        char wclass[200];
87    
88        if (button == NULL)
89            return 0;
90        if (GetClassName (button, wclass, 200) > 0
91            && !stricmp (wclass, "Button"))
92            return -1;
93        return 0;
94    }
95    
96    
97    
98  /* CTB hook procedure.  /* CTB hook procedure.
99     Monitors the creation of all windows and subclass the window     Monitors the creation of all windows and subclass the window
100     if it belongs to the Outlook Express message class. */     if it belongs to the Outlook Express (message) class. */
101  static LRESULT CALLBACK  static LRESULT CALLBACK
102  ctb_proc (int code, WPARAM wparam, LPARAM lparam)  ctb_proc (int code, WPARAM wparam, LPARAM lparam)
103  {  {
# Line 94  ctb_proc (int code, WPARAM wparam, LPARA Line 124  ctb_proc (int code, WPARAM wparam, LPARA
124              else              else
125                  oe_hwnd = hwnd;                  oe_hwnd = hwnd;
126          }          }
127    
128            if ((gpgoe_active_modes & GPGOE_MODE_PLAINREPLY) &&
129                !strcmp (wclass, "Outlook Express Browser Class")) {
130                oe_main_proc_old = (WNDPROC)GetWindowLong (hwnd, GWL_WNDPROC);
131                if (!oe_main_proc_old)
132                    show_error (NULL, "GPGOE", MB_ICONERROR|MB_OK,
133                                "Could not get window procedure ec=%d",
134                                (int)GetLastError ());
135                else if (!SetWindowLong (hwnd, GWL_WNDPROC, (LONG)(WNDPROC)oe_main_proc))
136                    show_error (NULL, "GPGOE", MB_ICONERROR|MB_OK,
137                                "Could not set window procedure: ec=%d",
138                                (int)GetLastError ());
139            }
140            break;
141    
142        case HCBT_ACTIVATE:
143    #if 0
144            if (plugin_active != NULL &&
145                WaitForSingleObject (plugin_active, 0) == WAIT_OBJECT_0) {
146                char wclass[200];
147    
148                if (GetClassName (hwnd, wclass, sizeof (wclass)-1) <= 0 ||
149                    !strstr (wclass, "#32770") || !is_common_file_dlg (hwnd))
150                    break;
151                of_proc_old = (WNDPROC)GetWindowLong (hwnd, GWL_WNDPROC);
152                SetWindowLong (hwnd, GWL_WNDPROC, (LONG)(WNDPROC)of_proc);
153            }
154    #endif
155          break;          break;
156      }        }  
157      return CallNextHookEx (ctb_hook, code, wparam, lparam);      return CallNextHookEx (ctb_hook, code, wparam, lparam);
158  }  }
159    
160    
161  /* Initialize the hooks.  /* Initialize the hooks; a named mutex prevents that the
162     To prevent double initialisation, we use a named mutex. */     initialisation is done twice.
163       Return value: 0 on success. */
164  int  int
165  gpgoe_initialize (void)  gpgoe_initialize (void)
166  {  {
167        reset_pass_cache ();
168      CreateMutex (NULL, TRUE, "gpgoe");      CreateMutex (NULL, TRUE, "gpgoe");
169      if (GetLastError () == ERROR_ALREADY_EXISTS)      if (GetLastError () == ERROR_ALREADY_EXISTS)
170          return 0;          return 0;
# Line 113  gpgoe_initialize (void) Line 173  gpgoe_initialize (void)
173  }  }
174    
175    
176  /* Deinitialize the hooks and close all handles. */  /* Deinitialize the hooks and close all handles.
177       Return value: 0 on success. */
178  int  int
179  gpgoe_remove (void)  gpgoe_remove (void)
180  {  {
     int rc = 0;  
181      HANDLE hd;      HANDLE hd;
182        int rc;
183        
184      hd = CreateMutex (NULL, TRUE, "gpgoe");      hd = CreateMutex (NULL, TRUE, "gpgoe");
185      if (GetLastError() == ERROR_ALREADY_EXISTS) {      if (GetLastError() == ERROR_ALREADY_EXISTS) {
186          oe_hwnd = NULL;          oe_hwnd = NULL;
# Line 127  gpgoe_remove (void) Line 188  gpgoe_remove (void)
188      }      }
189      SetWindowLong (oe_hwnd, GWL_WNDPROC, (LONG)(WNDPROC)oe_proc_old);      SetWindowLong (oe_hwnd, GWL_WNDPROC, (LONG)(WNDPROC)oe_proc_old);
190      rc = UnhookWindowsHookEx (ctb_hook);      rc = UnhookWindowsHookEx (ctb_hook);
191    
192        /* reset global variables. */
193        reset_pass_cache ();
194        gpgoe_active_modes = 0;
195    
196      return rc ? 0 : (int)GetLastError ();      return rc ? 0 : (int)GetLastError ();
197  }  }
198    
199    
200    /* Change the active plug-in modes, enable mode @mode. */
201    void
202    gpgoe_set_active_modes (int mode)
203    {
204        gpgoe_active_modes = mode;
205    }
206    
207    
208    int
209    gpgoe_get_active_modes (void)
210    {
211        return gpgoe_active_modes;
212    }

Legend:
Removed from v.1  
changed lines
  Added in v.19

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26