1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
|
// main.cpp : main module of the plugin
//
#include "gnupgplugin.h"
HINSTANCE dllinstance;
PLUGINLINK *pluginLink;
PLUGININFO pluginInfo = {
sizeof(PLUGININFO),
"GnuPG Plugin (Ansi/Unicode)",
0x00070002, // version dword
"OpenPGP/GnuPG Plugin v0.7.0.2 by Zakhar V. Bardymov ("__DATE__")\n"
" based on GnuPG Plugin v0.0.0.4 by Harald Treder",
"Harald Treder, Zakhar V. Bardymov",
"harald.treder(at)gmx.de, zvb(at)irkutsk.ru",
"GPLv2",
"http://www.miranda-im.org",
UNICODE_AWARE, // right now the only flag, UNICODE_AWARE, is recognized here
0 // doesn't replace anything built-in
};
struct MM_INTERFACE mmi;
struct LIST_INTERFACE li;
struct UTF8_INTERFACE utfi;
UINT storepassphraseschecked;
UINT autoimportpublickeyschecked;
UINT loggingonchecked;
char starttag[plugintagsize];
char endtag[plugintagsize];
char *pluginid="GnuPGPlugin";
char logfile[fullfilenamesize];
// zeichenketten zur identifizierung von werten in der datenbank
char *dbexecutable="Executable";
char *dbhomedirectory="HomeDirectory";
char *dbstorepassphrases="StorePassphrases";
char *dbautoimportpublickeys="AutoImportPublicKeys";
char *dblistpublickeys="ListPublicKeys";
char *dblistsecretkeys="ListSecretKeys";
char *dbimportpublickey="ImportPublicKey";
char *dbexportpublickey="ExportPublicKey";
char *dbdetectuserid="DetectUserID";
char *dbencrypt="Encrypt";
char *dbdecrypt="Decrypt";
char *dbtempdir="Tempdir";
char *dbkeyuserid="KeyUserID";
char *dbkey="Key";
char *dbkeymodified="KeyModified";
char *dbuseencryption="UseEncryption";
char *dbstarttag="StartTag";
char *dbendtag="EndTag";
char *dbloggingon="LoggingOn";
char *dblogfile="LogFile";
void ErrorMessage(const char *alevel, const char *atext, const char *ahint)
{
char buf[errormessagesize];
strcpy(buf,Translate(atext));
strcat(buf," ");
strcat(buf,Translate(ahint));
MessageBoxA(NULL,buf,Translate(alevel),MB_OK);
}
void LogMessage(const char *astart, const char *atext, const char *aend)
{
if (loggingonchecked!=BST_CHECKED)
return;
FILE *log=fopen(logfile,"a");
if (log)
{
fputs(astart,log);
fputs(atext,log);
fputs(aend,log);
fclose(log);
}
}
// DllMain
extern "C" BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
dllinstance=hinstDLL;
return TRUE;
}
int AddContact(WPARAM wparam, LPARAM lparam)
{
CallService(MS_PROTO_ADDTOCONTACT,wparam,(LPARAM)pluginid);
return 0;
}
void getcontactsetting(char *ostr, const char *key, const char *defstr)
// zvb: Created to be used in MainInit.
{
DBVARIANT dbv;
int err=DBGetContactSetting(NULL,pluginid,key,&dbv);
strcpy(ostr,(!err?dbv.pszVal:defstr));
DBFreeVariant(&dbv);
}
int MainInit(WPARAM wparam, LPARAM lparam)
{
PROTOCOLDESCRIPTOR pd;
CLISTMENUITEM cmi;
HANDLE hcontact;
// zvb: slightly more readable now:
getcontactsetting(gpgExecutable,dbexecutable,txtgpgexecutable);
getcontactsetting(gpgHomeDirectory,dbhomedirectory,txtgpghomedirectory);
getcontactsetting(gpgArgsListPublicKeys,dblistpublickeys,txtgpgargslistpublickeys);
getcontactsetting(gpgArgsListSecretKeys,dblistsecretkeys,txtgpgargslistsecretkeys);
getcontactsetting(gpgArgsImportPublicKey,dbimportpublickey,txtgpgargsimportpublickey);
getcontactsetting(gpgArgsExportPublicKey,dbexportpublickey,txtgpgargsexportpublickey);
getcontactsetting(gpgArgsDetectUserID,dbdetectuserid,txtgpgargsdetectuserid);
getcontactsetting(gpgArgsEncrypt,dbencrypt,txtgpgargsencrypt);
getcontactsetting(gpgArgsDecrypt,dbdecrypt,txtgpgargsdecrypt);
getcontactsetting(gpgTempdir,dbtempdir,txtgpgtempdir);
getcontactsetting(starttag,dbstarttag,"<GnuPG Plugin>\r\n");
getcontactsetting(endtag,dbendtag,"\r\n</GnuPG Plugin>");
getcontactsetting(logfile,dblogfile,"c:\\miranda-gnupg.log");
loggingonchecked=DBGetContactSettingDword(NULL,pluginid,dbloggingon,BST_UNCHECKED);
storepassphraseschecked
=DBGetContactSettingDword(NULL,pluginid,dbstorepassphrases,BST_CHECKED);
autoimportpublickeyschecked
=DBGetContactSettingDword(NULL,pluginid,dbautoimportpublickeys,BST_CHECKED);
if (existsFile(gpgExecutable))
{
updateKeyUserIDs(publickeyuserid);
updateKeyUserIDs(secretkeyuserid);
}
else
ErrorMessage(txtwarning,txtinvalidexecutable,txtverifyoptions);
HookEvent(ME_OPT_INITIALISE,OptionsInit);
HookEvent(ME_USERINFO_INITIALISE,UserInfoInit);
// register encryption protocol
ZeroMemory(&pd,sizeof(pd));
pd.cbSize=sizeof(PROTOCOLDESCRIPTOR);
pd.szName=pluginid;
pd.type=PROTOTYPE_ENCRYPTION;
CallService(MS_PROTO_REGISTERMODULE,0,(LPARAM)&pd);
// send/receive functions registration
CreateProtoServiceFunction(pluginid,PSR_MESSAGE,RecvMsgSvc);
CreateProtoServiceFunction(pluginid,PSS_MESSAGE,SendMsgSvc);
// zvb: let the Unicode calls be served by them too.
CreateProtoServiceFunction(pluginid,PSR_MESSAGE"W",RecvMsgSvc);
CreateProtoServiceFunction(pluginid,PSS_MESSAGE"W",SendMsgSvc);
// add the protocol to all contacts found in DB
for (
hcontact=(HANDLE)CallService(MS_DB_CONTACT_FINDFIRST,0,0);
hcontact;
hcontact=(HANDLE)CallService(MS_DB_CONTACT_FINDNEXT,(WPARAM)hcontact,0)
)
if (!CallService(MS_PROTO_ISPROTOONCONTACT,(WPARAM)hcontact,(LPARAM)pluginid))
CallService(MS_PROTO_ADDTOCONTACT,(WPARAM)hcontact,(LPARAM)pluginid);
// kontakte zur laufzeit in die protokoll kette einhaengen
HookEvent(ME_DB_CONTACT_ADDED,AddContact);
CreateServiceFunction(svcuseencryption,UseEncryptionService);
CreateServiceFunction(svcsendpublickey,SendPublicKeyService);
// set contact menu items
ZeroMemory(&cmi,sizeof(cmi));
cmi.cbSize=sizeof(CLISTMENUITEM);
// encryption menuitem
cmi.pszName=Translate(txtuseencryption);
cmi.position=menuitemposition;
cmi.pszService=svcuseencryption;
useencryption=(HANDLE)CallService(MS_CLIST_ADDCONTACTMENUITEM,0,(LPARAM)&cmi);
// sendpublickey menuitem
cmi.pszName=Translate(txtsendpublickey);
cmi.position=menuitemposition+1;
cmi.pszService=svcsendpublickey;
sendpublickey=(HANDLE)CallService(MS_CLIST_ADDCONTACTMENUITEM,0,(LPARAM)&cmi);
// hook event fuer menumodifikation
HookEvent(ME_CLIST_PREBUILDCONTACTMENU,UpdateContactMenu);
return 0;
}
// MirandaPluginInfo
extern "C" __declspec(dllexport) PLUGININFO *MirandaPluginInfo(DWORD mirandaVersion)
{
/*
if (mirandaVersion<PLUGIN_MAKE_VERSION(0,7,0,0))
{
MessageBoxA(NULL,
"Failure: GnuPG Plugin requires Miranda IM 0.7.0.0 or later.",
"GnuPG Plugin for Miranda IM",MB_OK|MB_ICONWARNING|MB_SETFOREGROUND|MB_TOPMOST);
return NULL;
}
*/
return &pluginInfo;
}
// Load
extern "C" __declspec(dllexport) int Load(PLUGINLINK *link)
{
pluginLink=link;
// set the memory, lists & utf8 managers
mir_getMMI(&mmi);
mir_getLI(&li);
mir_getUTFI(&utfi);
HookEvent(ME_SYSTEM_MODULESLOADED,MainInit);
initPassphrases();
initKeyUserIDs(publickeyuserid);
initKeyUserIDs(secretkeyuserid);
return 0;
}
// Unload
extern "C" __declspec(dllexport) int Unload(void)
{
releaseKeyUserIDs(secretkeyuserid);
releaseKeyUserIDs(publickeyuserid);
releasePassphrases();
return 0;
}
|