diff options
author | sje <sje@4f64403b-2f21-0410-a795-97e2b3489a10> | 2006-11-01 14:44:17 +0000 |
---|---|---|
committer | sje <sje@4f64403b-2f21-0410-a795-97e2b3489a10> | 2006-11-01 14:44:17 +0000 |
commit | b61df7acc1235b3b2a66217d0d7358199c5d37f9 (patch) | |
tree | 70f74e5b04249d9ce70259ef70b38bcdf869cf64 /ping/ping.cpp | |
parent | 9c6d8a640911d336cc1e758310bbfccaf547d2d2 (diff) |
git-svn-id: https://server.scottellis.com.au/svn/mim_plugs@11 4f64403b-2f21-0410-a795-97e2b3489a10
Diffstat (limited to 'ping/ping.cpp')
-rw-r--r-- | ping/ping.cpp | 173 |
1 files changed, 173 insertions, 0 deletions
diff --git a/ping/ping.cpp b/ping/ping.cpp new file mode 100644 index 0000000..c1cbfb5 --- /dev/null +++ b/ping/ping.cpp @@ -0,0 +1,173 @@ +#include "common.h"
+#include "ping.h"
+#include <list>
+HINSTANCE hInst;
+PLUGINLINK *pluginLink;
+
+HANDLE hNetlibUser = 0;
+HANDLE hFillListEvent = 0;
+
+bool use_raw_ping = true;
+
+// plugin stuff
+PLUGININFO pluginInfo={
+ sizeof(PLUGININFO),
+ "Ping Plugin",
+ PLUGIN_MAKE_VERSION(0, 7, 0, 1),
+ "Ping labelled IP addresses or domain names.",
+ "Scott Ellis",
+ "mail@scottellis.com.au",
+ "© 2005 Scott Ellis",
+ "http://www.scottellis.com.au/",
+ 0, //not transient
+ 0 //doesn't replace anything built-in
+};
+
+extern "C" BOOL WINAPI DllMain(HINSTANCE hinstDLL,DWORD fdwReason,LPVOID lpvReserved)
+{
+ hInst=hinstDLL;
+ return TRUE;
+}
+
+extern "C" PING_API PLUGININFO* MirandaPluginInfo(DWORD mirandaVersion)
+{
+ return &pluginInfo;
+}
+
+void CreatePluginServices() {
+ // general
+ CreateServiceFunction(PLUG "/Ping", PluginPing);
+ CreateServiceFunction(PLUG "/DblClick", DblClick);
+
+ // list
+ CreateServiceFunction(PLUG "/ClearPingList", ClearPingList);
+ CreateServiceFunction(PLUG "/GetPingList", GetPingList);
+ CreateServiceFunction(PLUG "/SetPingList", SetPingList);
+ CreateServiceFunction(PLUG "/SetAndSavePingList", SetAndSavePingList);
+ CreateServiceFunction(PLUG "/LoadPingList", LoadPingList);
+ CreateServiceFunction(PLUG "/SavePingList", SavePingList);
+
+ reload_event_handle = CreateHookableEvent(PLUG "/ListReload");
+
+ //log
+ CreateServiceFunction(PLUG "/Log", Log);
+ CreateServiceFunction(PLUG "/ViewLogData", ViewLogData);
+ CreateServiceFunction(PLUG "/GetLogFilename", GetLogFilename);
+ CreateServiceFunction(PLUG "/SetLogFilename", SetLogFilename);
+
+ // menu
+ CreateServiceFunction(PLUG "/DisableAll", PingDisableAll);
+ CreateServiceFunction(PLUG "/EnableAll", PingEnableAll);
+ CreateServiceFunction(PLUG "/ToggleEnabled", ToggleEnabled);
+ CreateServiceFunction(PLUG "/ShowGraph", ShowGraph);
+ CreateServiceFunction(PLUG "/Edit", EditContact);
+
+}
+
+int OnShutdown(WPARAM wParam, LPARAM lParam) {
+ graphs_cleanup();
+
+ UnhookEvent(hFillListEvent);
+
+ if(use_raw_ping)
+ cleanup_raw_ping();
+ else
+ ICMP::get_instance()->stop();
+
+ DeinitList();
+
+ return 0;
+}
+
+int OnModulesLoaded(WPARAM wParam, LPARAM lParam) {
+
+ NETLIBUSER nl_user = {0};
+ nl_user.cbSize = sizeof(nl_user);
+ nl_user.szSettingsModule = PLUG;
+ //nl_user.flags = NUF_OUTGOING | NUF_HTTPGATEWAY | NUF_NOOPTIONS;
+ //nl_user.flags = NUF_OUTGOING | NUF_NOOPTIONS;
+ nl_user.flags = NUF_OUTGOING | NUF_HTTPCONNS;
+ nl_user.szDescriptiveName = "Ping Plugin";
+ nl_user.szHttpGatewayHello = 0;
+ nl_user.szHttpGatewayUserAgent = 0;
+ nl_user.pfnHttpGatewayInit = 0;
+ nl_user.pfnHttpGatewayWrapSend = 0;
+ nl_user.pfnHttpGatewayUnwrapRecv = 0;
+
+ hNetlibUser = (HANDLE)CallService(MS_NETLIB_REGISTERUSER, 0, (LPARAM)&nl_user);
+
+ InitIcons();
+
+ InitMenus();
+
+ hFillListEvent = HookEvent(PLUG "/ListReload", FillList);
+
+ if(!DBGetContactSettingByte(0, PLUG, "PingPlugImport", 0)) {
+ if(DBGetContactSettingDword(0, "PingPlug", "NumEntries", 0)) {
+ import_ping_addresses();
+ DBWriteContactSettingByte(0, PLUG, "PingPlugImport", 1);
+ }
+ }
+
+ InitList();
+
+ CallService(PLUG "/LoadPingList", 0, 0);
+
+ graphs_init();
+
+ if(options.logging) CallService(PLUG "/Log", (WPARAM)"start", 0);
+
+ return 0;
+}
+
+extern "C" PING_API int Load(PLUGINLINK *link)
+{
+ pluginLink=link;
+
+ if(init_raw_ping()) {
+ //MessageBox(0, Translate("Failed to initialize. Plugin disabled."), Translate("Ping Plugin"), MB_OK | MB_ICONERROR);
+ //return 1;
+ use_raw_ping = false;
+ }
+ DBWriteContactSettingByte(0, PLUG, "UsingRawSockets", (BYTE)use_raw_ping);
+
+ DuplicateHandle( GetCurrentProcess(), GetCurrentThread(), GetCurrentProcess(), &mainThread, THREAD_SET_CONTEXT, FALSE, 0 );
+ hWakeEvent = CreateEvent(NULL, FALSE, FALSE, "Local\\ThreadWaitEvent");
+
+ InitializeCriticalSection(&list_cs);
+ InitializeCriticalSection(&thread_finished_cs);
+ InitializeCriticalSection(&list_changed_cs);
+ InitializeCriticalSection(&data_list_cs);
+
+ // create services before loading options - so we can have the 'getlogfilename' service!
+ CreatePluginServices();
+
+ LoadOptions();
+
+ SkinAddNewSound("PingTimeout", "Ping Timout", 0);
+ SkinAddNewSound("PingReply", "Ping Reply", 0);
+
+ HookEvent(ME_SYSTEM_MODULESLOADED, OnModulesLoaded);
+
+ HookEvent(ME_OPT_INITIALISE, PingOptInit );
+
+ HookEvent(ME_SYSTEM_PRESHUTDOWN, OnShutdown);
+
+ return 0;
+}
+
+extern "C" PING_API int Unload(void)
+{
+ SavePingList(0, 0);
+
+ DeleteCriticalSection(&list_cs);
+ DeleteCriticalSection(&thread_finished_cs);
+ DeleteCriticalSection(&list_changed_cs);
+ DeleteCriticalSection(&data_list_cs);
+
+ CloseHandle( mainThread );
+
+ if(options.logging) CallService(PLUG "/Log", (WPARAM)"stop", 0);
+
+ return 0;
+}
|