summaryrefslogtreecommitdiff
path: root/plugins/MirOTR/src/dllmain.cpp
blob: bb72c7746b04c5ede27f0c81ef481d16f2949704 (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
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
// dllmain.cpp : Definiert den Einstiegspunkt für die DLL-Anwendung.
#include "stdafx.h"

CLIST_INTERFACE *pcli;
HANDLE hEventWindow;
HINSTANCE hInst;

int hLangpack;

PLUGININFOEX pluginInfo={
	sizeof(PLUGININFOEX),
	__PLUGIN_NAME,
	PLUGIN_MAKE_VERSION(__MAJOR_VERSION, __MINOR_VERSION, __RELEASE_NUM, __BUILD_NUM),
	__DESCRIPTION,
	__AUTHOR,
	__COPYRIGHT,
	__AUTHORWEB,
	UNICODE_AWARE,
	// {12D8FAAD-78AB-4E3C-9854-320E9EA5CC9F}
	{0x12d8faad, 0x78ab, 0x4e3c, {0x98, 0x54, 0x32, 0xe, 0x9e, 0xa5, 0xcc, 0x9f}}
};

BOOL APIENTRY DllMain(HMODULE hModule, DWORD, LPVOID)
{
	hInst = hModule;
	return TRUE;
}

extern "C" __declspec(dllexport) PLUGININFOEX* MirandaPluginInfoEx(DWORD)
{
	return &pluginInfo;
}

int ModulesLoaded(WPARAM, LPARAM)
{
	lib_cs_lock();
	otr_user_state = otrl_userstate_create();

	// this calls ReadPrivkeyFiles (above) to set filename values (also called on ME_FOLDERS_PATH_CHANGED)
	InitOptions();

	InitDBFilter();
	InitMenu();

	InitSRMM();

	hEventWindow = HookEvent(ME_MSG_WINDOWEVENT, WindowEvent);

	if (options.bHaveSecureIM && !db_get_b(0, MODULENAME, "sim_warned", 0)) {
		db_set_b(0, MODULENAME, "sim_warned", 1);
		options.default_policy = OTRL_POLICY_MANUAL_MOD;
		SaveOptions();
		MessageBox(nullptr, TranslateW(LANG_OTR_SECUREIM_TEXT), TranslateW(LANG_OTR_SECUREIM_TITLE), 0x30);
	}
	return 0;
}

extern "C" __declspec(dllexport) int Load(void)
{
	DEBUGOUTA("LOAD MIROTR");

	mir_getLP(&pluginInfo);
	pcli = Clist_GetInterface();

	InitIcons();

	OTRL_INIT;
	INITCOMMONCONTROLSEX icce = {0};
	icce.dwSize = sizeof(icce);
	icce.dwICC = ICC_LISTVIEW_CLASSES|ICC_PROGRESS_CLASS;
	InitCommonControlsEx(&icce);

	db_set_resident(MODULENAME, "TrustLevel");

	////////////////////////////////////////////////////////////////////////////
	// init plugin
	PROTOCOLDESCRIPTOR pd = { 0 };
	pd.cbSize = sizeof(pd);
	pd.szName = MODULENAME;
	pd.type = PROTOTYPE_ENCRYPTION;
	Proto_RegisterModule(&pd);

	// remove us as a filter to all contacts - fix filter type problem
	if(db_get_b(0, MODULENAME, "FilterOrderFix", 0) != 2) {
		for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact))
			Proto_RemoveFromContact(hContact, MODULENAME);
		db_set_b(0, MODULENAME, "FilterOrderFix", 2);
	}

	// create our services
	CreateProtoServiceFunction(MODULENAME, PSS_MESSAGE, SVC_OTRSendMessage);
	CreateProtoServiceFunction(MODULENAME, PSR_MESSAGE, SVC_OTRRecvMessage);

	// hook modules loaded for updater support
	HookEvent(ME_SYSTEM_MODULESLOADED, ModulesLoaded);

	return 0;
}

extern "C" __declspec(dllexport) int Unload(void)
{
	//UnhookEvent(hSettingChanged);
	UnhookEvent(hEventWindow);
	//UnhookEvent(hEventDbEventAddedFilter);
	//UnhookEvent(hEventDbEventAdded);
	DEBUGOUTA("UNLOAD MIROTR");
	DeinitSRMM();
	DeinitDBFilter();

	lib_cs_lock();
	otrl_userstate_free(otr_user_state);

	return 0;
}