summaryrefslogtreecommitdiff
path: root/GnuPG/contactmenu.cpp
blob: db84b784deeec79744b4eb6ba87756d7290bc33f (plain)
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
#include "gnupgplugin.h"

HANDLE useencryption;
HANDLE sendpublickey;

// service namen der menueintraege
char *svcuseencryption="GnuPGPlugin/UseEncryption";
char *svcsendpublickey="GnuPGPlugin/SendPublicKey";

int UpdateContactMenu(WPARAM wparam, LPARAM lparam)
{
	DBVARIANT dbv;
	CLISTMENUITEM cmi;
	char keyuserid[keyuseridsize];
	BOOL ischecked;
	
	int error=DBGetContactSetting(NULL,pluginid,dbkeyuserid,&dbv);
	if (!error) strcpy(keyuserid,dbv.pszVal); 
	else strcpy(keyuserid,"");
	DBFreeVariant(&dbv);
	
	ZeroMemory(&cmi,sizeof(cmi));
	cmi.cbSize=sizeof(CLISTMENUITEM);
	cmi.flags=CMIM_FLAGS|CMIF_NOTOFFLINE;
	if (strlen(keyuserid)==0) cmi.flags|=CMIF_HIDDEN;
	CallService(MS_CLIST_MODIFYMENUITEM,(WPARAM)sendpublickey,(LPARAM)&cmi);
	
	error=DBGetContactSetting((HANDLE)wparam,pluginid,dbkeyuserid,&dbv);
	if (!error) strcpy(keyuserid,dbv.pszVal); 
	else strcpy(keyuserid,"");
	DBFreeVariant(&dbv);
	
	ZeroMemory(&cmi,sizeof(cmi));
	cmi.cbSize=sizeof(CLISTMENUITEM);
	cmi.flags=CMIM_FLAGS|CMIF_HIDDEN;
	
	if (strlen(keyuserid)!=0)
	{
		cmi.flags=CMIM_FLAGS;
		
		ischecked=DBGetContactSettingByte((HANDLE)wparam,pluginid,dbuseencryption,FALSE);
		if (ischecked) cmi.flags|=CMIF_CHECKED;
	}
	
	CallService(MS_CLIST_MODIFYMENUITEM,(WPARAM)useencryption,(LPARAM)&cmi);
	return 0;
}

int UseEncryptionService(WPARAM wparam, LPARAM lparam)
{
	BOOL ischecked=DBGetContactSettingByte((HANDLE)wparam,pluginid,dbuseencryption,FALSE);  
	DBWriteContactSettingByte((HANDLE)wparam,pluginid,dbuseencryption,(BYTE)!ischecked);
	return 0;
}

int SendPublicKeyService(WPARAM wparam, LPARAM lparam)
{
	int error;
	DBVARIANT dbv;
	char keyuserid[keyuseridsize];
	char keybuffer[keybuffersize];
	char keyid[keyidsize];
	gpgResult gpgresult;
	
	error=DBGetContactSetting(NULL,pluginid,dbkeyuserid,&dbv);
	if (!error) strcpy(keyuserid,dbv.pszVal); 
	else strcpy(keyuserid,"");
	DBFreeVariant(&dbv);
	
	// sollte nicht auftreten
	if (strlen(keyuserid)==0)
	{
		ErrorMessage(txterror,txtinvaliduserid,txtverifyoptions);
		return 0;
	}
	
	getNextPart(keyid,keyuserid,txtidseparator);
	ZeroMemory(keybuffer,sizeof(keybuffer));
	gpgresult=gpgExportPublicKey(keybuffer,keyid);
	
	if (gpgresult!=gpgSuccess)
	{
		ErrorMessage(txterror,txtexportpublickeyfailed,txtverifyoptions);
		return 0;
	}
	
	CallService(MS_MSG_SENDMESSAGE,wparam,(LPARAM)keybuffer);
	return 0;
}