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

Annotation of /trunk/src/GPGOE.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 19 - (hide annotations)
Sun Jun 4 10:12:47 2006 UTC (18 years, 11 months ago) by twoaday
File MIME type: text/plain
File size: 5391 byte(s)
Prepare new release.


1 twoaday 1 /* GPGOE.c - GnuPG for Outlook Express
2     * Copyright (C) 2001, 2002, 2003, 2006 Timo Schulz
3     *
4     * This file is part of GPGOE.
5     *
6     * GPGOE is free software; you can redistribute it and/or modify
7     * it under the terms of the GNU Lesser General Public License as published by
8     * the Free Software Foundation; either version 2.1 of the License, or
9     * (at your option) any later version.
10     *
11     * GPGOE is distributed in the hope that it will be useful,
12     * but WITHOUT ANY WARRANTY; without even the implied warranty of
13     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14     * GNU General Public License for more details.
15     *
16     * You should have received a copy of the GNU Lesser General Public License
17     * along with GPGOE; if not, write to the Free Software Foundation,
18     * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
19     */
20    
21     #ifdef HAVE_CONFIG_H
22     #include <config.h>
23     #endif
24    
25     #include <windows.h>
26     #include <stdio.h>
27     #include "gpgme.h"
28     #include "GPGOE.h"
29    
30     /* Global DLL module handle. */
31     HINSTANCE mod_hinst_dll;
32    
33 twoaday 16 /* Outlook Express old window procedure. */
34     WNDPROC oe_proc_old;
35    
36 twoaday 1 /* DLL hook handle for the CBT function. */
37     static HHOOK ctb_hook = NULL;
38    
39     /* Outlook Express window handle. */
40     static HWND oe_hwnd = NULL;
41    
42 twoaday 18 /* We need a shared section to define variables which
43     will keep their values in all address spaces. */
44 twoaday 19 #ifndef __GNUC__
45     #pragma data_seg(".SHARDAT")
46 twoaday 18 #endif
47 twoaday 19 /* Supported GPGOE feature modes. */
48     int gpgoe_active_modes ATTR_SEC = 0;
49    
50     char gpgoe_pass_cache[HASH_BUCKETS][256];
51 twoaday 18 #ifndef __GNUC__
52     #pragma data_seg()
53     #endif
54 twoaday 1
55 twoaday 18
56 twoaday 1 /* Main DLL entry point. */
57     BOOL WINAPI
58     DllMain (HINSTANCE hinst_dll, DWORD reason, LPVOID reserved)
59     {
60     switch (reason) {
61     case DLL_PROCESS_ATTACH:
62     mod_hinst_dll = hinst_dll;
63     break;
64    
65     case DLL_PROCESS_DETACH:
66     mod_hinst_dll = NULL;
67     break;
68    
69     case DLL_THREAD_ATTACH:
70     break;
71    
72     case DLL_THREAD_DETACH:
73     break;
74     }
75    
76     return TRUE;
77     }
78    
79    
80 twoaday 12 /* Quick and dirty check if the dialog is a common dialog
81 twoaday 16 and the 'File {Open, Save}' style. */
82 twoaday 12 static int
83 twoaday 16 is_common_file_dlg (HWND h)
84 twoaday 12 {
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 twoaday 16
98 twoaday 1 /* CTB hook procedure.
99     Monitors the creation of all windows and subclass the window
100 twoaday 16 if it belongs to the Outlook Express (message) class. */
101 twoaday 1 static LRESULT CALLBACK
102     ctb_proc (int code, WPARAM wparam, LPARAM lparam)
103     {
104     HWND hwnd;
105     char wclass[256];
106    
107     if (code < 0)
108     return CallNextHookEx (ctb_hook, code, wparam, lparam);
109    
110     hwnd = (HWND)wparam;
111     switch (code) {
112     case HCBT_CREATEWND:
113     GetClassName (hwnd, wclass, sizeof (wclass) - 1);
114     if (!strcmp (wclass, "ATH_Note")) {
115     oe_proc_old = (WNDPROC) GetWindowLong (hwnd, GWL_WNDPROC);
116     if (!oe_proc_old)
117     show_error (NULL, "GPGOE", MB_ICONERROR|MB_OK,
118     "Could not get window procedure ec=%d",
119     (int)GetLastError ());
120     else if (!SetWindowLong (hwnd, GWL_WNDPROC, (LONG)(WNDPROC)oe_proc))
121     show_error (NULL, "GPGOE", MB_ICONERROR|MB_OK,
122     "Could not set window procedure: ec=%d",
123     (int)GetLastError ());
124     else
125     oe_hwnd = hwnd;
126     }
127 twoaday 16
128 twoaday 18 if ((gpgoe_active_modes & GPGOE_MODE_PLAINREPLY) &&
129     !strcmp (wclass, "Outlook Express Browser Class")) {
130 twoaday 16 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 twoaday 1 break;
141 twoaday 12
142 twoaday 19 case HCBT_ACTIVATE:
143 twoaday 18 #if 0
144 twoaday 19 if (plugin_active != NULL &&
145 twoaday 12 WaitForSingleObject (plugin_active, 0) == WAIT_OBJECT_0) {
146     char wclass[200];
147    
148     if (GetClassName (hwnd, wclass, sizeof (wclass)-1) <= 0 ||
149 twoaday 16 !strstr (wclass, "#32770") || !is_common_file_dlg (hwnd))
150 twoaday 12 break;
151     of_proc_old = (WNDPROC)GetWindowLong (hwnd, GWL_WNDPROC);
152     SetWindowLong (hwnd, GWL_WNDPROC, (LONG)(WNDPROC)of_proc);
153     }
154 twoaday 19 #endif
155 twoaday 12 break;
156 twoaday 1 }
157     return CallNextHookEx (ctb_hook, code, wparam, lparam);
158     }
159    
160    
161 twoaday 16 /* Initialize the hooks; a named mutex prevents that the
162     initialisation is done twice.
163     Return value: 0 on success. */
164 twoaday 1 int
165     gpgoe_initialize (void)
166     {
167 twoaday 19 reset_pass_cache ();
168 twoaday 1 CreateMutex (NULL, TRUE, "gpgoe");
169     if (GetLastError () == ERROR_ALREADY_EXISTS)
170     return 0;
171     ctb_hook = SetWindowsHookEx (WH_CBT, ctb_proc, mod_hinst_dll, 0);
172     return ctb_hook? 0 : (int)GetLastError ();
173     }
174    
175    
176 twoaday 16 /* Deinitialize the hooks and close all handles.
177     Return value: 0 on success. */
178 twoaday 1 int
179     gpgoe_remove (void)
180     {
181     HANDLE hd;
182 twoaday 16 int rc;
183 twoaday 19
184 twoaday 1 hd = CreateMutex (NULL, TRUE, "gpgoe");
185     if (GetLastError() == ERROR_ALREADY_EXISTS) {
186     oe_hwnd = NULL;
187     CloseHandle (hd);
188     }
189     SetWindowLong (oe_hwnd, GWL_WNDPROC, (LONG)(WNDPROC)oe_proc_old);
190     rc = UnhookWindowsHookEx (ctb_hook);
191 twoaday 19
192     /* reset global variables. */
193     reset_pass_cache ();
194     gpgoe_active_modes = 0;
195    
196 twoaday 1 return rc ? 0 : (int)GetLastError ();
197     }
198 twoaday 18
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     }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26