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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
|
/*
* $Id: main.c 3717 2006-09-06 17:49:35Z gena01 $
*
* myYahoo Miranda Plugin
*
* Authors: Gennady Feldman (aka Gena01)
* Laurent Marechal (aka Peorth)
*
* This code is under GPL and is based on AIM, MSN and Miranda source code.
* I want to thank Robert Rainwater and George Hazan for their code and support
* and for answering some of my questions during development of this plugin.
*/
#include <windows.h>
#include "yahoo.h"
#include "http_gateway.h"
#include "version.h"
#include "resource.h"
#include <m_system.h>
#include <m_langpack.h>
#include <m_options.h>
#include <m_skin.h>
#include <m_message.h>
#include <m_idle.h>
#include <m_userinfo.h>
#include "options.h"
//#define HTTP_GATEWAY
extern char *szStartMsg;
/*
* Global Variables
*/
HINSTANCE hinstance;
PLUGINLINK *pluginLink;
char yahooProtocolName[MAX_PATH];
HANDLE hNetlibUser = NULL;
HANDLE YahooMenuItems[ MENU_ITEMS_COUNT ];
static HANDLE hHookOptsInit;
static HANDLE hHookModulesLoaded;
static HANDLE hHookSettingChanged;
static HANDLE hHookUserTyping;
static HANDLE hHookUserInfoInit;
HANDLE hHookContactDeleted;
HANDLE hHookIdle;
HANDLE hYahooNudge = NULL;
pthread_mutex_t connectionHandleMutex;
PLUGININFO pluginInfo={
sizeof(PLUGININFO),
#ifdef YAHOO_CVSBUILD
"Yahoo Protocol Beta/Nightly",
#else
"Yahoo Protocol",
#endif
__VERSION_DWORD,
"Yahoo Protocol support via libyahoo2 library. [Built: "__DATE__" "__TIME__"]",
"Gennady Feldman, Laurent Marechal",
"gena01@miranda-im.org",
"© 2003-2006 G.Feldman",
"http://www.miranda-im.org/download/details.php?action=viewfile&id=1248",
0, //not transient
0 //DEFMOD_PROTOCOLYAHOO - no core yahoo protocol
};
int yahooStatus = ID_STATUS_OFFLINE;
BOOL yahooLoggedIn = FALSE;
/*
* WINAPI DllMain - main entry point into a DLL
* Parameters:
* HINSTANCE hinst,
* DWORD fdwReason,
* LPVOID lpvReserved
* Returns :
* BOOL
*
*/
BOOL WINAPI DllMain(HINSTANCE hinst,DWORD fdwReason,LPVOID lpvReserved)
{
hinstance=hinst;
return TRUE;
}
/*
* MainInit - Called at very beginning of plugin
* Parameters: wparam , lparam
* Returns : int
*/
/*int MainInit(WPARAM wparam,LPARAM lparam)
{
return 0;
}*/
/*
* MirandaPluginInfo - Sets plugin info
* Parameters: (DWORD mirandaVersion)
*/
__declspec(dllexport) PLUGININFO* MirandaPluginInfo(DWORD mirandaVersion)
{
//
// We require Miranda 0.6
// This requires the latest trunk... experimental API used here
//
if (mirandaVersion < PLUGIN_MAKE_VERSION(0, 6, 0, 0)) {
MessageBox( NULL,
"Yahoo plugin cannot be loaded. It requires Miranda IM 0.6 or later.",
"Yahoo",
MB_OK|MB_ICONWARNING|MB_SETFOREGROUND|MB_TOPMOST );
return NULL;
}
return &pluginInfo;
}
/*
* Unload - Unloads plugin
* Parameters: void
*/
int __declspec(dllexport) Unload(void)
{
YAHOO_DebugLog("Unload");
//stop_timer();
if (yahooLoggedIn)
yahoo_logout();
YAHOO_DebugLog("Logged out");
pthread_mutex_destroy(&connectionHandleMutex);
LocalEventUnhook(hHookContactDeleted);
LocalEventUnhook(hHookIdle);
LocalEventUnhook(hHookModulesLoaded);
LocalEventUnhook(hHookOptsInit);
LocalEventUnhook(hHookSettingChanged);
LocalEventUnhook(hHookUserTyping);
if (szStartMsg)
free(szStartMsg);
YAHOO_DebugLog("Before Netlib_CloseHandle");
Netlib_CloseHandle( hNetlibUser );
return 0;
}
int YahooIdleEvent(WPARAM wParam, LPARAM lParam);
int OnDetailsInit(WPARAM wParam, LPARAM lParam);
/*
* Load - loads plugin into memory
*/
static int OnModulesLoaded( WPARAM wParam, LPARAM lParam )
{
char tModule[ 100 ], tModuleDescr[ 100 ];
NETLIBUSER nlu = {0};
if ( !ServiceExists( MS_DB_CONTACT_GETSETTING_STR )) {
MessageBox( NULL,
Translate("Yahoo plugin requires db3x plugin version 0.5.1.0 or later" ),
Translate("Yahoo"),
MB_OK );
return 1;
}
CharUpper( lstrcpy( tModule, yahooProtocolName ));
wsprintf(tModuleDescr, "%s plugin connections", yahooProtocolName);
nlu.cbSize = sizeof(nlu);
#ifdef HTTP_GATEWAY
nlu.flags = NUF_OUTGOING | NUF_HTTPGATEWAY| NUF_HTTPCONNS;
#else
nlu.flags = NUF_OUTGOING | NUF_HTTPCONNS;
#endif
nlu.szSettingsModule = tModule;
nlu.szDescriptiveName = Translate( tModuleDescr );
#ifdef HTTP_GATEWAY
// Here comes the Gateway Code!
nlu.szHttpGatewayHello = NULL;
nlu.szHttpGatewayUserAgent = "User-Agent: Mozilla/4.01 [en] (Win95; I)";
nlu.pfnHttpGatewayInit = YAHOO_httpGatewayInit;
nlu.pfnHttpGatewayBegin = NULL;
nlu.pfnHttpGatewayWrapSend = YAHOO_httpGatewayWrapSend;
nlu.pfnHttpGatewayUnwrapRecv = YAHOO_httpGatewayUnwrapRecv;
#endif
hNetlibUser = ( HANDLE )YAHOO_CallService( MS_NETLIB_REGISTERUSER, 0, ( LPARAM )&nlu );
hHookOptsInit = HookEvent( ME_OPT_INITIALISE, YahooOptInit );
hHookSettingChanged = HookEvent(ME_DB_CONTACT_SETTINGCHANGED, YAHOO_util_dbsettingchanged);
hHookIdle = HookEvent(ME_IDLE_CHANGED, YahooIdleEvent);
hHookUserInfoInit = HookEvent(ME_USERINFO_INITIALISE, OnDetailsInit);
// Add support for Plugin Uninstaller
//DBWriteContactSettingString(NULL, "Uninstall", "Yahoo", yahooProtocolName);
//add as a known module in DB Editor ++
CallService("DBEditorpp/RegisterSingleModule",(WPARAM)yahooProtocolName, 0);
//start_timer();
return 0;
}
//=====================================================
// Name : Load
// Parameters: PLUGINLINK *link
// Returns : int
// Description : Called when plugin is loaded into Miranda
//=====================================================
int __declspec(dllexport)Load(PLUGINLINK *link)
{
PROTOCOLDESCRIPTOR pd;
char path[MAX_PATH], tNudge[250];
char* protocolname;
pluginLink=link;
//
// Need to disable threading since we got our own routines.
//
DisableThreadLibraryCalls(hinstance);
GetModuleFileName( hinstance, path, sizeof( path ));
protocolname = strrchr(path,'\\');
if (protocolname != NULL) {
char* fend;
protocolname++;
fend = strrchr(path,'.');
if (fend != NULL)
*fend = '\0';
CharUpper( protocolname );
lstrcpyn(yahooProtocolName, protocolname, MAX_PATH);
} else
lstrcpy(yahooProtocolName, "YAHOO");
mir_snprintf( path, sizeof( path ), "%s/Status", yahooProtocolName );
CallService( MS_DB_SETSETTINGRESIDENT, TRUE, ( LPARAM )path );
mir_snprintf( path, sizeof( path ), "%s/YStatus", yahooProtocolName );
CallService( MS_DB_SETSETTINGRESIDENT, TRUE, ( LPARAM )path );
mir_snprintf( path, sizeof( path ), "%s/YAway", yahooProtocolName );
CallService( MS_DB_SETSETTINGRESIDENT, TRUE, ( LPARAM )path );
mir_snprintf( path, sizeof( path ), "%s/Mobile", yahooProtocolName );
CallService( MS_DB_SETSETTINGRESIDENT, TRUE, ( LPARAM )path );
mir_snprintf( path, sizeof( path ), "%s/YGMsg", yahooProtocolName );
CallService( MS_DB_SETSETTINGRESIDENT, TRUE, ( LPARAM )path );
mir_snprintf( path, sizeof( path ), "%s/IdleTS", yahooProtocolName );
CallService( MS_DB_SETSETTINGRESIDENT, TRUE, ( LPARAM )path );
mir_snprintf( path, sizeof( path ), "%s/PictLastCheck", yahooProtocolName );
CallService( MS_DB_SETSETTINGRESIDENT, TRUE, ( LPARAM )path );
mir_snprintf( path, sizeof( path ), "%s/PictLoading", yahooProtocolName );
CallService( MS_DB_SETSETTINGRESIDENT, TRUE, ( LPARAM )path );
// 1.
hHookModulesLoaded = HookEvent( ME_SYSTEM_MODULESLOADED, OnModulesLoaded );
// Create nudge event
lstrcpyn(tNudge, yahooProtocolName , sizeof( tNudge ) - 7);
lstrcat(tNudge, "/Nudge");
hYahooNudge = CreateHookableEvent(tNudge);
// 2.
ZeroMemory(&pd,sizeof(pd));
pd.cbSize=sizeof(pd);
pd.szName=yahooProtocolName;
pd.type=PROTOTYPE_PROTOCOL;
CallService(MS_PROTO_REGISTERMODULE,0,(LPARAM)&pd);
register_callbacks();
// 3.
yahoo_logoff_buddies();
SkinAddNewSoundEx(Translate( "mail" ), yahooProtocolName, "New E-mail available in Inbox" );
LoadYahooServices();
pthread_mutex_init(&connectionHandleMutex);
return 0;
}
|