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
231
232
|
/*
Copyright (C) 2009 Ricardo Pescuma Domenecci
This is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this file; see the file license.txt. If
not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#include "commons.h"
// Prototypes ///////////////////////////////////////////////////////////////////////////
PLUGININFOEX pluginInfo={
sizeof(PLUGININFOEX),
#ifdef UNICODE
"IAX protocol (Unicode)",
#else
"IAX protocol (Ansi)",
#endif
PLUGIN_MAKE_VERSION(0,2,0,0),
"Provides support for Inter-Asterisk eXchange (IAX) protocol",
"Ricardo Pescuma Domenecci",
"pescuma@miranda-im.org",
"© 2009-2010 Ricardo Pescuma Domenecci",
"http://pescuma.org/miranda/iax",
UNICODE_AWARE,
0, //doesn't replace anything built-in
#ifdef UNICODE
{ 0x706e2aca, 0x4310, 0x49c5, { 0x93, 0x3c, 0xea, 0xa1, 0xd6, 0x52, 0xa2, 0x6f } } // {706E2ACA-4310-49c5-933C-EAA1D652A26F}
#else
{ 0x6d6a97da, 0x86ed, 0x422e, { 0x82, 0xe8, 0xd2, 0x6, 0x32, 0xb0, 0x7, 0x51 } } // {6D6A97DA-86ED-422e-82E8-D20632B00751}
#endif
};
HINSTANCE hInst;
PLUGINLINK *pluginLink;
MM_INTERFACE mmi;
UTF8_INTERFACE utfi;
LIST_INTERFACE li;
void * iaxclientDllCode = NULL;
std::vector<HANDLE> hHooks;
int ModulesLoaded(WPARAM wParam, LPARAM lParam);
int PreShutdown(WPARAM wParam, LPARAM lParam);
static int sttCompareProtocols(const IAXProto *p1, const IAXProto *p2)
{
return strcmp(p1->m_szModuleName, p2->m_szModuleName);
}
OBJLIST<IAXProto> instances(1, &sttCompareProtocols);
// Functions ////////////////////////////////////////////////////////////////////////////
extern "C" BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
hInst = hinstDLL;
return TRUE;
}
extern "C" __declspec(dllexport) PLUGININFO* MirandaPluginInfo(DWORD mirandaVersion)
{
pluginInfo.cbSize = sizeof(PLUGININFO);
return (PLUGININFO*) &pluginInfo;
}
extern "C" __declspec(dllexport) PLUGININFOEX* MirandaPluginInfoEx(DWORD mirandaVersion)
{
pluginInfo.cbSize = sizeof(PLUGININFOEX);
return &pluginInfo;
}
static const MUUID interfaces[] = { MIID_PROTOCOL, MIID_LAST };
extern "C" __declspec(dllexport) const MUUID* MirandaPluginInterfaces(void)
{
return interfaces;
}
static IAXProto *IAXProtoInit(const char* pszProtoName, const TCHAR* tszUserName)
{
HMEMORYMODULE iaxclient = MemoryLoadLibrary((const char *) iaxclientDllCode);
if (iaxclient == NULL)
{
MessageBox(NULL, TranslateT("Error loading iaxclient dll"), TranslateT("IAX"), MB_OK | MB_ICONERROR);
return NULL;
}
IAXProto *proto = new IAXProto(iaxclient, pszProtoName, tszUserName);
instances.insert(proto);
return proto;
}
static int IAXProtoUninit(IAXProto *proto)
{
instances.remove(proto);
return 0;
}
static void * LoadDllFromResource(LPCTSTR lpName)
{
HRSRC hRes = FindResource(hInst, lpName, RT_RCDATA);
if (hRes == NULL)
return NULL;
HGLOBAL hResLoad = LoadResource(hInst, hRes);
if (hResLoad == NULL)
return NULL;
return LockResource(hResLoad);
}
extern "C" int __declspec(dllexport) Load(PLUGINLINK *link)
{
pluginLink = link;
CHECK_VERSION("IAX");
iaxclientDllCode = LoadDllFromResource(MAKEINTRESOURCE(IDR_IAXCLIENT_DLL));
if (iaxclientDllCode == NULL)
{
MessageBox(NULL, TranslateT("Could not load iaxclient module"), TranslateT("IAX"), MB_OK | MB_ICONERROR);
return -1;
}
HMEMORYMODULE iaxclient = MemoryLoadLibrary((const char *) iaxclientDllCode);
if (iaxclient == NULL)
{
MessageBox(NULL, TranslateT("Error loading iaxclient dll"), TranslateT("IAX"), MB_OK | MB_ICONERROR);
return -1;
}
MemoryFreeLibrary(iaxclient);
// TODO Assert results here
mir_getMMI(&mmi);
mir_getUTFI(&utfi);
mir_getLI(&li);
hHooks.push_back( HookEvent(ME_SYSTEM_MODULESLOADED, ModulesLoaded) );
hHooks.push_back( HookEvent(ME_SYSTEM_PRESHUTDOWN, PreShutdown) );
PROTOCOLDESCRIPTOR pd = {0};
pd.cbSize = sizeof(pd);
pd.szName = MODULE_NAME;
pd.fnInit = (pfnInitProto) IAXProtoInit;
pd.fnUninit = (pfnUninitProto) IAXProtoUninit;
pd.type = PROTOTYPE_PROTOCOL;
CallService(MS_PROTO_REGISTERMODULE, 0, (LPARAM) &pd);
return 0;
}
extern "C" int __declspec(dllexport) Unload(void)
{
return 0;
}
// Called when all the modules are loaded
int ModulesLoaded(WPARAM wParam, LPARAM lParam)
{
if (!ServiceExists(MS_VOICESERVICE_REGISTER))
MessageBox(NULL, TranslateT("IAX needs Voice Service plugin to work!"), _T("IAX"), MB_OK | MB_ICONERROR);
// Add our modules to the KnownModules list
CallService("DBEditorpp/RegisterSingleModule", (WPARAM) MODULE_NAME, 0);
// Updater plugin support
if(ServiceExists(MS_UPDATE_REGISTER))
{
Update upd = {0};
char szCurrentVersion[30];
upd.cbSize = sizeof(upd);
upd.szComponentName = pluginInfo.shortName;
upd.szUpdateURL = UPDATER_AUTOREGISTER;
upd.szBetaVersionURL = "http://pescuma.org/miranda/iax_version.txt";
upd.szBetaChangelogURL = "http://pescuma.org/miranda/iax#Changelog";
upd.pbBetaVersionPrefix = (BYTE *)"IAX protocol ";
upd.cpbBetaVersionPrefix = strlen((char *)upd.pbBetaVersionPrefix);
#ifdef UNICODE
upd.szBetaUpdateURL = "http://pescuma.org/miranda/iaxW.zip";
#else
upd.szBetaUpdateURL = "http://pescuma.org/miranda/iax.zip";
#endif
upd.pbVersion = (BYTE *)CreateVersionStringPlugin((PLUGININFO*) &pluginInfo, szCurrentVersion);
upd.cpbVersion = strlen((char *)upd.pbVersion);
CallService(MS_UPDATE_REGISTER, 0, (LPARAM)&upd);
}
return 0;
}
int PreShutdown(WPARAM wParam, LPARAM lParam)
{
for(unsigned int i = 0; i < hHooks.size(); ++i)
UnhookEvent(hHooks[i]);
return 0;
}
|