From 62061956cdcbb8a30ad7aa9c01913c7f46b2a0e3 Mon Sep 17 00:00:00 2001 From: "av%netscape.com" Date: Sun, 25 Mar 2001 23:38:33 +0000 Subject: [PATCH] First time in. The Spy Plugin. Not part of the build. git-svn-id: svn://10.0.0.236/trunk@90396 18797224-902f-48f8-a5cc-f745e15eee43 --- .../modules/plugin/npspy/common/epmanager.cpp | 364 ++++++++ .../modules/plugin/npspy/common/fileutils.cpp | 102 ++ .../modules/plugin/npspy/common/format.cpp | 880 ++++++++++++++++++ .../modules/plugin/npspy/common/logfile.cpp | 69 ++ .../modules/plugin/npspy/common/logger.cpp | 383 ++++++++ .../modules/plugin/npspy/common/np_entry.cpp | 155 +++ .../modules/plugin/npspy/common/npn_gate.cpp | 336 +++++++ .../modules/plugin/npspy/common/npp_gate.cpp | 370 ++++++++ .../modules/plugin/npspy/common/plugload.cpp | 180 ++++ .../modules/plugin/npspy/common/profile.cpp | 34 + .../plugin/tools/spy/common/epmanager.cpp | 364 ++++++++ .../plugin/tools/spy/common/fileutils.cpp | 102 ++ .../plugin/tools/spy/common/format.cpp | 880 ++++++++++++++++++ .../plugin/tools/spy/common/logfile.cpp | 69 ++ .../plugin/tools/spy/common/logger.cpp | 383 ++++++++ .../plugin/tools/spy/common/np_entry.cpp | 155 +++ .../plugin/tools/spy/common/npn_gate.cpp | 336 +++++++ .../plugin/tools/spy/common/npp_gate.cpp | 370 ++++++++ .../plugin/tools/spy/common/plugload.cpp | 180 ++++ .../plugin/tools/spy/common/profile.cpp | 34 + 20 files changed, 5746 insertions(+) create mode 100644 mozilla/modules/plugin/npspy/common/epmanager.cpp create mode 100644 mozilla/modules/plugin/npspy/common/fileutils.cpp create mode 100644 mozilla/modules/plugin/npspy/common/format.cpp create mode 100644 mozilla/modules/plugin/npspy/common/logfile.cpp create mode 100644 mozilla/modules/plugin/npspy/common/logger.cpp create mode 100644 mozilla/modules/plugin/npspy/common/np_entry.cpp create mode 100644 mozilla/modules/plugin/npspy/common/npn_gate.cpp create mode 100644 mozilla/modules/plugin/npspy/common/npp_gate.cpp create mode 100644 mozilla/modules/plugin/npspy/common/plugload.cpp create mode 100644 mozilla/modules/plugin/npspy/common/profile.cpp create mode 100644 mozilla/modules/plugin/tools/spy/common/epmanager.cpp create mode 100644 mozilla/modules/plugin/tools/spy/common/fileutils.cpp create mode 100644 mozilla/modules/plugin/tools/spy/common/format.cpp create mode 100644 mozilla/modules/plugin/tools/spy/common/logfile.cpp create mode 100644 mozilla/modules/plugin/tools/spy/common/logger.cpp create mode 100644 mozilla/modules/plugin/tools/spy/common/np_entry.cpp create mode 100644 mozilla/modules/plugin/tools/spy/common/npn_gate.cpp create mode 100644 mozilla/modules/plugin/tools/spy/common/npp_gate.cpp create mode 100644 mozilla/modules/plugin/tools/spy/common/plugload.cpp create mode 100644 mozilla/modules/plugin/tools/spy/common/profile.cpp diff --git a/mozilla/modules/plugin/npspy/common/epmanager.cpp b/mozilla/modules/plugin/npspy/common/epmanager.cpp new file mode 100644 index 00000000000..5902e4512fd --- /dev/null +++ b/mozilla/modules/plugin/npspy/common/epmanager.cpp @@ -0,0 +1,364 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + * + */ + +#include "xp.h" + +#include "epmanager.h" +#include "logger.h" + +extern Logger * logger; + +InstanceList::InstanceList(NPP _instance) : + next(NULL), + instance(_instance) +{ +} + +InstanceList::~InstanceList() +{ +} + +PluginEntryPointList::PluginEntryPointList() : + next(NULL), + instances(NULL) +{ + mimetype[0] = '\0'; + memset((void *)&realNPPFuncs, 0, sizeof(realNPPFuncs)); + realShutdown = NULL; + hLib = NULL; +} + +PluginEntryPointList::~PluginEntryPointList() +{ +} + +NPPEntryPointManager::NPPEntryPointManager() : + mEntryPoints(NULL) +{ +} + +NPPEntryPointManager::~NPPEntryPointManager() +{ + for(PluginEntryPointList * eps = mEntryPoints; eps != NULL;) + { + for(InstanceList * instances = eps->instances; instances != NULL;) + { + InstanceList * next = instances->next; + delete instances; + instances = next; + } + + PluginEntryPointList * next = eps->next; + delete eps; + eps = next; + } +} + +void NPPEntryPointManager::createEntryPointsForPlugin(char * mimetype, NPPluginFuncs * funcs, NP_SHUTDOWN shutdownproc, XP_HLIB hLib) +{ + PluginEntryPointList * eps = new PluginEntryPointList(); + + if(eps == NULL) + return; + + strcpy(eps->mimetype, mimetype); + + if(funcs) + { + eps->realNPPFuncs.size = funcs->size; + eps->realNPPFuncs.version = funcs->version; + eps->realNPPFuncs.newp = funcs->newp; + eps->realNPPFuncs.destroy = funcs->destroy; + eps->realNPPFuncs.setwindow = funcs->setwindow; + eps->realNPPFuncs.newstream = funcs->newstream; + eps->realNPPFuncs.destroystream = funcs->destroystream; + eps->realNPPFuncs.asfile = funcs->asfile; + eps->realNPPFuncs.writeready = funcs->writeready; + eps->realNPPFuncs.write = funcs->write; + eps->realNPPFuncs.print = funcs->print; + eps->realNPPFuncs.event = funcs->event; + eps->realNPPFuncs.urlnotify = funcs->urlnotify; + eps->realNPPFuncs.javaClass = funcs->javaClass; + eps->realNPPFuncs.getvalue = funcs->getvalue; + eps->realNPPFuncs.setvalue = funcs->setvalue; + } + + eps->realShutdown = shutdownproc; + eps->hLib = hLib; + + eps->next = mEntryPoints; + mEntryPoints = eps; +} + +void NPPEntryPointManager::removeEntryPointsForPlugin(NPP instance, XP_HLIB * lib) +{ + NPPluginFuncs * eptoremove = findEntryPointsForInstance(instance); + + PluginEntryPointList * prev = NULL; + + for(PluginEntryPointList * eps = mEntryPoints; eps != NULL; eps = eps->next) + { + if(&eps->realNPPFuncs == eptoremove) + { + if(prev) + prev->next = eps->next; + else + mEntryPoints = eps->next; + + *lib = eps->hLib; + delete eps; + return; + } + + prev = eps; + } +} + +NPPluginFuncs * NPPEntryPointManager::findEntryPointsForPlugin(char * mimetype) +{ + for(PluginEntryPointList * eps = mEntryPoints; eps != NULL; eps = eps->next) + { + if(0 == stricmp(eps->mimetype, mimetype)) + return &eps->realNPPFuncs; + } + + return NULL; +} + +NPPluginFuncs * NPPEntryPointManager::findEntryPointsForInstance(NPP instance) +{ + for(PluginEntryPointList * eps = mEntryPoints; eps != NULL; eps = eps->next) + { + for(InstanceList * instances = eps->instances; instances != NULL; instances = instances->next) + { + if(instances->instance == instance) + return &eps->realNPPFuncs; + } + } + + return NULL; +} + +void NPPEntryPointManager::callNP_ShutdownAll() +{ + for(PluginEntryPointList * eps = mEntryPoints; eps != NULL; eps = eps->next) + { + if(eps->realShutdown) + { + logger->logSPY_NP_Shutdown(eps->mimetype); + eps->realShutdown(); + eps->realShutdown = NULL; // don't want to call it more than once + } + } +} + +void NPPEntryPointManager::callNP_Shutdown(NPP instance) +{ + for(PluginEntryPointList * eps = mEntryPoints; eps != NULL; eps = eps->next) + { + for(InstanceList * instances = eps->instances; instances != NULL; instances = instances->next) + { + if(instances->instance == instance) + { + if(eps->realShutdown) + { + logger->logSPY_NP_Shutdown(eps->mimetype); + eps->realShutdown(); + eps->realShutdown = NULL; // don't want to call it more than once + } + } + } + } +} + +NPError NPPEntryPointManager::callNPP_New(NPMIMEType pluginType, NPP instance, uint16 mode, int16 argc, char* argn[], char* argv[], NPSavedData* saved) +{ + NPPluginFuncs * nppfuncs = NULL; + + for(PluginEntryPointList * eps = mEntryPoints; eps != NULL; eps = eps->next) + { + if(0 == stricmp(eps->mimetype, pluginType)) + { + nppfuncs = &eps->realNPPFuncs; + + // now we should associate this plugin instance with plugin entry points + // so that later we could find entry points by instance rather than by mimetype + InstanceList * inst = new InstanceList(instance); + inst->next = eps->instances; + eps->instances = inst; + + break; + } + } + + if(!nppfuncs || !nppfuncs->newp) + return NPERR_GENERIC_ERROR; + + NPError rv = CallNPP_NewProc(nppfuncs->newp, pluginType, instance, mode, argc, argn, argv, saved); + + return rv; +} + +NPError NPPEntryPointManager::callNPP_Destroy(NPP instance, NPSavedData** save, BOOL * last) +{ + NPPluginFuncs * nppfuncs = NULL; + + BOOL done = FALSE; + + for(PluginEntryPointList * eps = mEntryPoints; eps != NULL; eps = eps->next) + { + InstanceList * prev = NULL; + for(InstanceList * instances = eps->instances; instances != NULL; instances = instances->next) + { + if(instances->instance == instance) + { + nppfuncs = &eps->realNPPFuncs; + done = TRUE; + + // check if this is the last one + if(eps->instances->next == NULL) + *last = TRUE; + else + { + // deassociate instance if this is not the last one + // last instance will be needed to find corresponding shutdown proc + if(prev) + prev->next = instances->next; + else + eps->instances = instances->next; + + delete instances; + } + + break; + } + prev = instances; + } + if(done) + break; + } + + if(!nppfuncs || !nppfuncs->destroy) + return NPERR_GENERIC_ERROR; + + return CallNPP_DestroyProc(nppfuncs->destroy, instance, save); +} + +NPError NPPEntryPointManager::callNPP_SetWindow(NPP instance, NPWindow* window) +{ + NPPluginFuncs * nppfuncs = findEntryPointsForInstance(instance); + if(!nppfuncs || !nppfuncs->setwindow) + return NPERR_GENERIC_ERROR; + + return CallNPP_SetWindowProc(nppfuncs->setwindow, instance, window); +} + +NPError NPPEntryPointManager::callNPP_NewStream(NPP instance, NPMIMEType type, NPStream* stream, NPBool seekable, uint16* stype) +{ + NPPluginFuncs * nppfuncs = findEntryPointsForInstance(instance); + if(!nppfuncs || !nppfuncs->newstream) + return NPERR_GENERIC_ERROR; + + return CallNPP_NewStreamProc(nppfuncs->newstream, instance, type, stream, seekable, stype); +} + +NPError NPPEntryPointManager::callNPP_DestroyStream(NPP instance, NPStream* stream, NPReason reason) +{ + NPPluginFuncs * nppfuncs = findEntryPointsForInstance(instance); + if(!nppfuncs || !nppfuncs->destroystream) + return NPERR_GENERIC_ERROR; + + return CallNPP_DestroyStreamProc(nppfuncs->destroystream, instance, stream, reason); +} + +int32 NPPEntryPointManager::callNPP_WriteReady(NPP instance, NPStream* stream) +{ + NPPluginFuncs * nppfuncs = findEntryPointsForInstance(instance); + if(!nppfuncs || !nppfuncs->writeready) + return NPERR_GENERIC_ERROR; + + return CallNPP_WriteReadyProc(nppfuncs->writeready, instance, stream); +} + +int32 NPPEntryPointManager::callNPP_Write(NPP instance, NPStream* stream, int32 offset, int32 len, void* buffer) +{ + NPPluginFuncs * nppfuncs = findEntryPointsForInstance(instance); + if(!nppfuncs || !nppfuncs->write) + return NPERR_GENERIC_ERROR; + + return CallNPP_WriteProc(nppfuncs->write, instance, stream, offset, len, buffer); +} + +void NPPEntryPointManager::callNPP_StreamAsFile(NPP instance, NPStream* stream, const char* fname) +{ + NPPluginFuncs * nppfuncs = findEntryPointsForInstance(instance); + if(!nppfuncs || !nppfuncs->asfile) + return; + + CallNPP_StreamAsFileProc(nppfuncs->asfile, instance, stream, fname); +} + +void NPPEntryPointManager::callNPP_Print(NPP instance, NPPrint* platformPrint) +{ + NPPluginFuncs * nppfuncs = findEntryPointsForInstance(instance); + if(!nppfuncs || !nppfuncs->print) + return; + + CallNPP_PrintProc(nppfuncs->print, instance, platformPrint); +} + +void NPPEntryPointManager::callNPP_URLNotify(NPP instance, const char* url, NPReason reason, void* notifyData) +{ + NPPluginFuncs * nppfuncs = findEntryPointsForInstance(instance); + if(!nppfuncs || !nppfuncs->urlnotify) + return; + + CallNPP_URLNotifyProc(nppfuncs->urlnotify, instance, url, reason, notifyData); +} + +NPError NPPEntryPointManager::callNPP_GetValue(NPP instance, NPPVariable variable, void *value) +{ + NPPluginFuncs * nppfuncs = findEntryPointsForInstance(instance); + if(!nppfuncs || !nppfuncs->getvalue) + return NPERR_GENERIC_ERROR; + + return CallNPP_GetValueProc(nppfuncs->getvalue, instance, variable, value); +} + +NPError NPPEntryPointManager::callNPP_SetValue(NPP instance, NPNVariable variable, void *value) +{ + NPPluginFuncs * nppfuncs = findEntryPointsForInstance(instance); + if(!nppfuncs || !nppfuncs->setvalue) + return NPERR_GENERIC_ERROR; + + return CallNPP_SetValueProc(nppfuncs->setvalue, instance, variable, value); +} + +int16 NPPEntryPointManager::callNPP_HandleEvent(NPP instance, void* event) +{ + NPPluginFuncs * nppfuncs = findEntryPointsForInstance(instance); + if(!nppfuncs || !nppfuncs->event) + return NPERR_GENERIC_ERROR; + + return CallNPP_HandleEventProc(nppfuncs->event, instance, event); +} diff --git a/mozilla/modules/plugin/npspy/common/fileutils.cpp b/mozilla/modules/plugin/npspy/common/fileutils.cpp new file mode 100644 index 00000000000..3062308d8fa --- /dev/null +++ b/mozilla/modules/plugin/npspy/common/fileutils.cpp @@ -0,0 +1,102 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + * + */ + +#include "xp.h" + +BOOL XP_IsFile(char * szFileName) +{ +#ifdef XP_WIN + OFSTRUCT of; + return (HFILE_ERROR != OpenFile(szFileName, &of, OF_EXIST)); +#endif +#ifdef XP_UNIX + struct stat s; + return (stat(szFileName, &s) != -1); +#endif +#ifdef XP_MAC /* HACK */ + return 1; +#endif +} + +void XP_DeleteFile(char * szFileName) +{ +#ifdef XP_WIN + DeleteFile(szFileName); +#else + remove(szFileName); +#endif +} + +XP_HFILE XP_CreateFile(char * szFileName) +{ +#ifdef XP_WIN + OFSTRUCT of; + HFILE hFile = OpenFile(szFileName, &of, OF_CREATE | OF_WRITE); + return (hFile != HFILE_ERROR) ? hFile : NULL; +#else + return (XP_HFILE)fopen(szFileName, "w+"); +#endif +} + +XP_HFILE XP_OpenFile(char * szFileName) +{ +#ifdef XP_WIN + OFSTRUCT of; + HFILE hFile = OpenFile(szFileName, &of, OF_READ | OF_WRITE); + return (hFile != HFILE_ERROR) ? hFile : NULL; +#else + return (XP_HFILE)fopen(szFileName, "r+"); +#endif +} + +void XP_CloseFile(XP_HFILE hFile) +{ + if(hFile != NULL) + { +#ifdef XP_WIN + CloseHandle((HANDLE)hFile); +#else + fclose(hFile); +#endif + } +} + +DWORD XP_WriteFile(XP_HFILE hFile, void * pBuf, int iSize) +{ +#ifdef XP_WIN + DWORD dwRet; + WriteFile((HANDLE)hFile, pBuf, iSize, &dwRet, NULL); + return dwRet; +#else + return (DWORD)fwrite(pBuf, iSize, 1, hFile); +#endif +} + +void XP_FlushFileBuffers(XP_HFILE hFile) +{ +#ifdef XP_WIN + FlushFileBuffers((HANDLE)hFile); +#else + fflush(hFile); +#endif +} diff --git a/mozilla/modules/plugin/npspy/common/format.cpp b/mozilla/modules/plugin/npspy/common/format.cpp new file mode 100644 index 00000000000..b4c94a19dee --- /dev/null +++ b/mozilla/modules/plugin/npspy/common/format.cpp @@ -0,0 +1,880 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + * + */ + +#include "xp.h" + +#include "format.h" +#include "logger.h" + +extern Logger * logger; + +char * FormatNPAPIError(int iError) +{ + static char szError[64]; + switch (iError) + { + case NPERR_NO_ERROR: + sprintf(szError, "NPERR_NO_ERROR"); + break; + case NPERR_GENERIC_ERROR: + sprintf(szError, "NPERR_GENERIC_ERROR"); + break; + case NPERR_INVALID_INSTANCE_ERROR: + sprintf(szError, "NPERR_INVALID_INSTANCE_ERROR"); + break; + case NPERR_INVALID_FUNCTABLE_ERROR: + sprintf(szError, "NPERR_INVALID_FUNCTABLE_ERROR"); + break; + case NPERR_MODULE_LOAD_FAILED_ERROR: + sprintf(szError, "NPERR_MODULE_LOAD_FAILED_ERROR"); + break; + case NPERR_OUT_OF_MEMORY_ERROR: + sprintf(szError, "NPERR_OUT_OF_MEMORY_ERROR"); + break; + case NPERR_INVALID_PLUGIN_ERROR: + sprintf(szError, "NPERR_INVALID_PLUGIN_ERROR"); + break; + case NPERR_INVALID_PLUGIN_DIR_ERROR: + sprintf(szError, "NPERR_INVALID_PLUGIN_DIR_ERROR"); + break; + case NPERR_INCOMPATIBLE_VERSION_ERROR: + sprintf(szError, "NPERR_INCOMPATIBLE_VERSION_ERROR"); + break; + case NPERR_INVALID_PARAM: + sprintf(szError, "NPERR_INVALID_PARAM"); + break; + case NPERR_INVALID_URL: + sprintf(szError, "NPERR_INVALID_URL"); + break; + case NPERR_FILE_NOT_FOUND: + sprintf(szError, "NPERR_FILE_NOT_FOUND"); + break; + case NPERR_NO_DATA: + sprintf(szError, "NPERR_NO_DATA"); + break; + case NPERR_STREAM_NOT_SEEKABLE: + sprintf(szError, "NPERR_STREAM_NOT_SEEKABLE"); + break; + default: + sprintf(szError, "Unlisted error"); + break; + } + return &szError[0]; +} + +char * FormatNPAPIReason(int iReason) +{ + static char szReason[64]; + switch (iReason) + { + case NPRES_DONE: + sprintf(szReason, "NPRES_DONE"); + break; + case NPRES_NETWORK_ERR: + sprintf(szReason, "NPRES_NETWORK_ERR"); + break; + case NPRES_USER_BREAK: + sprintf(szReason, "NPRES_USER_BREAK"); + break; + default: + sprintf(szReason, "Unlisted reason"); + break; + } + return &szReason[0]; +} + +char * FormatNPNVariable(NPNVariable var) +{ + static char szVar[80]; + switch (var) + { + case NPNVxDisplay: + sprintf(szVar, "%i -- NPNVxDisplay", var); + break; + case NPNVxtAppContext: + sprintf(szVar, "%i -- NPNVxtAppContext", var); + break; + case NPNVnetscapeWindow: + sprintf(szVar, "%i -- NPNVnetscapeWindow", var); + break; + case NPNVjavascriptEnabledBool: + sprintf(szVar, "%i -- NPNVjavascriptEnabledBool", var); + break; + case NPNVasdEnabledBool: + sprintf(szVar, "%i -- NPNVasdEnabledBool", var); + break; + case NPNVisOfflineBool: + sprintf(szVar, "%i -- NPNVisOfflineBool", var); + break; + default: + sprintf(szVar, "%i -- Unlisted variable", var); + break; + } + return &szVar[0]; +} + +char * FormatNPPVariable(NPPVariable var) +{ + static char szVar[80]; + switch (var) + { + case NPPVpluginNameString: + sprintf(szVar, "%i -- NPPVpluginNameString", var); + break; + case NPPVpluginDescriptionString: + sprintf(szVar, "%i -- NPPVpluginDescriptionString?", var); + break; + case NPPVpluginWindowBool: + sprintf(szVar, "%i -- NPPVpluginWindowBool?", var); + break; + case NPPVpluginTransparentBool: + sprintf(szVar, "%i -- NPPVpluginTransparentBool?", var); + break; + case NPPVjavaClass: + sprintf(szVar, "%i -- NPPVjavaClass?", var); + break; + case NPPVpluginWindowSize: + sprintf(szVar, "%i -- NPPVpluginWindowSize?", var); + break; + case NPPVpluginTimerInterval: + sprintf(szVar, "%i -- NPPVpluginTimerInterval?", var); + break; + case NPPVpluginScriptableInstance: + sprintf(szVar, "%i -- NPPVpluginScriptableInstance?", var); + break; + case NPPVpluginScriptableIID: + sprintf(szVar, "%i -- NPPVpluginScriptableIID?", var); + break; + default: + sprintf(szVar, "%i -- Unlisted variable?", var); + break; + } + return &szVar[0]; +} + +BOOL FormatPCHARArgument(char * szBuf, int iLength, LogArgumentStruct * parg) +{ + if(iLength <= parg->iLength) + return FALSE; + + if(parg->pData == NULL) + sprintf(szBuf, "%#08lx", parg->dwArg); + else + sprintf(szBuf, "%#08lx(\"%s\")", parg->dwArg, (char *)parg->pData); + return TRUE; +} + +BOOL FormatBOOLArgument(char * szBuf, int iLength, LogArgumentStruct * parg) +{ + if(iLength <= 8) + return FALSE; + + sprintf(szBuf, "%s", ((NPBool)parg->dwArg == TRUE) ? "TRUE" : "FALSE"); + return TRUE; +} + +BOOL FormatPBOOLArgument(char * szBuf, int iLength, LogArgumentStruct * parg) +{ + if(iLength <= 8) + return FALSE; + + sprintf(szBuf, "%#08lx(%s)", parg->dwArg, (*((NPBool *)parg->pData) == TRUE) ? "TRUE" : "FALSE"); + return TRUE; +} + +static void makeAbbreviatedString(char * szBuf, int iSize, DWORD dwArg, int iLength, int iWrap) +{ + if(dwArg == 0L) + { + szBuf[0] = '\0'; + return; + } + + if(iLength > iWrap) + { + int iRealWrap = (iSize > iWrap) ? iWrap : (iSize - 4); + memcpy((LPVOID)&szBuf[0], (LPVOID)dwArg, iRealWrap); + szBuf[iRealWrap] = '.'; + szBuf[iRealWrap + 1] = '.'; + szBuf[iRealWrap + 2] = '.'; + szBuf[iRealWrap + 3] = '\0'; + } + else + { + if(iLength >= iSize) + { + memcpy((LPVOID)&szBuf[0], (LPVOID)dwArg, iSize - 4); + szBuf[iSize] = '.'; + szBuf[iSize + 1] = '.'; + szBuf[iSize + 2] = '.'; + szBuf[iSize + 3] = '\0'; + } + else + { + memcpy((LPVOID)&szBuf[0], (LPVOID)dwArg, iLength); + szBuf[iLength] = '\0'; + } + } +} + +LogItemStruct * makeLogItemStruct(NPAPI_Action action, + DWORD dw1, DWORD dw2, DWORD dw3, DWORD dw4, + DWORD dw5, DWORD dw6, DWORD dw7, BOOL bShort) +{ + int iWrap = 10; + + LogItemStruct * plis = new LogItemStruct; + if(plis == NULL) + return NULL; + + plis->action = action; + plis->arg1.dwArg = dw1; + plis->arg2.dwArg = dw2; + plis->arg3.dwArg = dw3; + plis->arg4.dwArg = dw4; + plis->arg5.dwArg = dw5; + plis->arg6.dwArg = dw6; + plis->arg7.dwArg = dw7; + + char szTarget[1024] = {'\0'}; + char szBuf[1024] = {'\0'}; + + if(bShort) + return plis; + + switch (action) + { + case action_invalid: + break; + + // NPN action + case action_npn_version: + plis->arg1.pData = new int[1]; + *(int*)(plis->arg1.pData) = *((int*)dw1); + plis->arg1.iLength = sizeof(int); + + plis->arg2.pData = new int[1]; + *(int*)(plis->arg2.pData) = *((int*)dw2); + plis->arg2.iLength = sizeof(int); + + plis->arg3.pData = new int[1]; + *(int*)(plis->arg3.pData) = *((int*)dw3); + plis->arg3.iLength = sizeof(int); + + plis->arg4.pData = new int[1]; + *(int*)(plis->arg4.pData) = *((int*)dw4); + plis->arg4.iLength = sizeof(int); + + break; + case action_npn_get_url_notify: + if(dw2 != 0L) + { + plis->arg2.iLength = strlen((char *)dw2) + 1; + plis->arg2.pData = new char[plis->arg2.iLength]; + memcpy(plis->arg2.pData, (LPVOID)dw2, plis->arg2.iLength); + } + + if(dw3 != 0L) + { + makeAbbreviatedString(szTarget, sizeof(szTarget), dw3, strlen((char *)dw3), iWrap); + plis->arg3.iLength = strlen(szTarget) + 1; + plis->arg3.pData = new char[plis->arg3.iLength]; + memcpy(plis->arg3.pData, (LPVOID)&szTarget[0], plis->arg3.iLength); + } + break; + case action_npn_get_url: + { + if(dw2 != 0L) + { + plis->arg2.iLength = strlen((char *)dw2) + 1; + plis->arg2.pData = new char[plis->arg2.iLength]; + memcpy(plis->arg2.pData, (LPVOID)dw2, plis->arg2.iLength); + } + + if(dw3 != 0L) + { + makeAbbreviatedString(szTarget, sizeof(szTarget), dw3, strlen((char *)dw3), iWrap); + plis->arg3.iLength = strlen(szTarget) + 1; + plis->arg3.pData = new char[plis->arg3.iLength]; + memcpy(plis->arg3.pData, (LPVOID)&szTarget[0], plis->arg3.iLength); + } + break; + } + case action_npn_post_url_notify: + { + if(dw2 != 0L) + { + plis->arg2.iLength = strlen((char *)dw2) + 1; + plis->arg2.pData = new char[plis->arg2.iLength]; + memcpy(plis->arg2.pData, (LPVOID)dw2, plis->arg2.iLength); + } + + if(dw3 != 0L) + { + makeAbbreviatedString(szTarget, sizeof(szTarget), dw3, strlen((char *)dw3), iWrap); + plis->arg3.iLength = strlen(szTarget) + 1; + plis->arg3.pData = new char[plis->arg3.iLength]; + memcpy(plis->arg3.pData, (LPVOID)&szTarget[0], plis->arg3.iLength); + } + + makeAbbreviatedString(szBuf, sizeof(szBuf), dw5, strlen((char *)dw5), iWrap); + plis->arg5.iLength = (int)dw4 + 1; + plis->arg5.pData = new char[plis->arg5.iLength]; + memcpy(plis->arg5.pData, (LPVOID)&szBuf[0], plis->arg5.iLength); + + break; + } + case action_npn_post_url: + { + if(dw2 != 0L) + { + plis->arg2.iLength = strlen((char *)dw2) + 1; + plis->arg2.pData = new char[plis->arg2.iLength]; + memcpy(plis->arg2.pData, (LPVOID)dw2, plis->arg2.iLength); + } + + if(dw3 != 0L) + { + makeAbbreviatedString(szTarget, sizeof(szTarget), dw3, strlen((char *)dw3), iWrap); + plis->arg3.iLength = strlen(szTarget) + 1; + plis->arg3.pData = new char[plis->arg3.iLength]; + memcpy(plis->arg3.pData, (LPVOID)&szTarget[0], plis->arg3.iLength); + } + + makeAbbreviatedString(szBuf, sizeof(szBuf), dw5, strlen((char *)dw5), iWrap); + plis->arg5.iLength = (int)dw4 + 1; + plis->arg5.pData = new char[plis->arg5.iLength]; + memcpy(plis->arg5.pData, (LPVOID)&szBuf[0], plis->arg5.iLength); + + break; + } + case action_npn_new_stream: + { + if(dw2 != 0L) + { + plis->arg2.iLength = strlen((char *)dw2) + 1; + plis->arg2.pData = new char[plis->arg2.iLength]; + memcpy(plis->arg2.pData, (LPVOID)dw2, plis->arg2.iLength); + } + + makeAbbreviatedString(szTarget, sizeof(szTarget), dw3, strlen((char *)dw3), iWrap); + plis->arg3.iLength = strlen(szTarget) + 1; + plis->arg3.pData = new char[plis->arg3.iLength]; + memcpy(plis->arg3.pData, (LPVOID)&szTarget[0], plis->arg3.iLength); + + plis->arg4.pData = new char[sizeof(DWORD)]; + plis->arg4.iLength = sizeof(DWORD); + memcpy(plis->arg4.pData, (LPVOID)dw4, plis->arg4.iLength); + + break; + } + case action_npn_destroy_stream: + break; + case action_npn_request_read: + break; + case action_npn_write: + { + makeAbbreviatedString(szBuf, sizeof(szBuf), dw4, strlen((char *)dw4), iWrap); + plis->arg4.iLength = strlen(szBuf) + 1; + plis->arg4.pData = new char[plis->arg4.iLength]; + memcpy(plis->arg4.pData, (LPVOID)&szBuf[0], plis->arg4.iLength); + break; + } + case action_npn_status: + if(dw2 != 0L) + { + plis->arg2.iLength = strlen((char *)dw2) + 1; + plis->arg2.pData = new char[plis->arg2.iLength]; + memcpy(plis->arg2.pData, (LPVOID)dw2, plis->arg2.iLength); + } + break; + case action_npn_user_agent: + break; + case action_npn_mem_alloc: + break; + case action_npn_mem_free: + break; + case action_npn_mem_flush: + break; + case action_npn_reload_plugins: + break; + case action_npn_get_java_env: + break; + case action_npn_get_java_peer: + break; + case action_npn_get_value: + plis->arg3.iLength = sizeof(DWORD); + plis->arg3.pData = new char[plis->arg3.iLength]; + memcpy(plis->arg3.pData, (LPVOID)dw3, plis->arg3.iLength); + break; + case action_npn_set_value: + if(((NPPVariable)dw2 == NPPVpluginNameString) || ((NPPVariable)dw2 == NPPVpluginDescriptionString)) + { + makeAbbreviatedString(szBuf, sizeof(szBuf), dw3, strlen((char *)dw3), iWrap); + plis->arg3.iLength = strlen(szBuf) + 1; + plis->arg3.pData = new char[plis->arg3.iLength]; + memcpy(plis->arg3.pData, (LPVOID)&szBuf[0], plis->arg3.iLength); + } + else if(((NPPVariable)dw2 == NPPVpluginWindowBool) || ((NPPVariable)dw2 == NPPVpluginTransparentBool)) + { + plis->arg3.iLength = sizeof(NPBool); + plis->arg3.pData = new char[plis->arg3.iLength]; + memcpy(plis->arg3.pData, (LPVOID)dw3, plis->arg3.iLength); + } + else if((NPPVariable)dw2 == NPPVpluginWindowSize) + { + plis->arg3.iLength = sizeof(NPSize); + plis->arg3.pData = new char[plis->arg3.iLength]; + memcpy(plis->arg3.pData, (LPVOID)dw3, plis->arg3.iLength); + } + break; + case action_npn_invalidate_rect: + { + plis->arg2.iLength = sizeof(NPRect); + plis->arg2.pData = new char[plis->arg2.iLength]; + memcpy(plis->arg2.pData, (LPVOID)dw2, plis->arg2.iLength); + break; + } + case action_npn_invalidate_region: + break; + case action_npn_force_redraw: + break; + + // NPP action + case action_npp_new: + plis->arg1.iLength = strlen((char *)dw1) + 1; + plis->arg1.pData = new char[plis->arg1.iLength]; + memcpy(plis->arg1.pData, (LPVOID)dw1, plis->arg1.iLength); + break; + case action_npp_destroy: + plis->arg2.iLength = sizeof(DWORD); + plis->arg2.pData = new char[plis->arg2.iLength]; + memcpy(plis->arg2.pData, (LPVOID)dw2, plis->arg2.iLength); + break; + case action_npp_set_window: + plis->arg2.iLength = sizeof(NPWindow); + plis->arg2.pData = new char[plis->arg2.iLength]; + memcpy(plis->arg2.pData, (LPVOID)dw2, plis->arg2.iLength); + break; + case action_npp_new_stream: + plis->arg2.iLength = strlen((char *)dw2) + 1; + plis->arg2.pData = new char[plis->arg2.iLength]; + memcpy(plis->arg2.pData, (LPVOID)dw2, plis->arg2.iLength); + + plis->arg5.iLength = sizeof(uint16); + plis->arg5.pData = new char[plis->arg5.iLength]; + memcpy(plis->arg5.pData, (LPVOID)dw5, plis->arg5.iLength); + break; + case action_npp_destroy_stream: + break; + case action_npp_stream_as_file: + plis->arg3.iLength = strlen((char *)dw3) + 1; + plis->arg3.pData = new char[plis->arg3.iLength]; + memcpy(plis->arg3.pData, (LPVOID)dw3, plis->arg3.iLength); + break; + case action_npp_write_ready: + break; + case action_npp_write: + { + if(dw5 != 0L) + { + makeAbbreviatedString(szBuf, sizeof(szBuf), dw5, strlen((char *)dw5), iWrap); + plis->arg5.iLength = strlen(szBuf) + 1; + plis->arg5.pData = new char[plis->arg5.iLength]; + memcpy(plis->arg5.pData, (LPVOID)&szBuf[0], plis->arg5.iLength); + } + break; + } + case action_npp_print: + break; + case action_npp_handle_event: + break; + case action_npp_url_notify: + plis->arg2.iLength = strlen((char *)dw2) + 1; + plis->arg2.pData = new char[plis->arg2.iLength]; + memcpy(plis->arg2.pData, (LPVOID)dw2, plis->arg2.iLength); + break; + case action_npp_get_java_class: + break; + case action_npp_get_value: + break; + case action_npp_set_value: + break; + + default: + break; + } + + return plis; +} + +void freeLogItemStruct(LogItemStruct * lis) +{ + if(lis) + delete lis; +} + +int formatLogItem(LogItemStruct * plis, char * szOutput, BOOL bDOSStyle) +{ + int iRet = 0; + static char szString[1024]; + static char szEOL[8]; + static char szEOI[256]; + static char szEndOfItem[] = ""; + + if(bDOSStyle) + { + strcpy(szEOL, "\r\n"); + //strcpy(szEOI, szEndOfItem); + //strcat(szEOI, "\r\n"); + } + else + { + strcpy(szEOL, "\n"); + //strcpy(szEOI, szEndOfItem); + //strcat(szEOI, "\n"); + } + + szOutput[0] = '\0'; + + DWORD dw1 = plis->arg1.dwArg; + DWORD dw2 = plis->arg2.dwArg; + DWORD dw3 = plis->arg3.dwArg; + DWORD dw4 = plis->arg4.dwArg; + DWORD dw5 = plis->arg5.dwArg; + DWORD dw6 = plis->arg6.dwArg; + DWORD dw7 = plis->arg7.dwArg; + + char sz1[1024] = {'\0'}; + char sz2[1024] = {'\0'}; + char sz3[1024] = {'\0'}; + char sz4[1024] = {'\0'}; + char sz5[1024] = {'\0'}; + char sz6[1024] = {'\0'}; + + switch (plis->action) + { + case action_invalid: + break; + + // NPN action + case action_npn_version: + if((plis->arg1.pData != NULL)&&(plis->arg2.pData != NULL)&&(plis->arg3.pData != NULL)&&(plis->arg4.pData != NULL)) + sprintf(szString, "NPN_Version(%#08lx, %#08lx, %#08lx, %#08lx)%s", dw1,dw2,dw3,dw4,szEOL); + else + sprintf(szString, "NPN_Version(%#08lx, %#08lx, %#08lx, %#08lx)%s", dw1,dw2,dw3,dw4,szEOL); + break; + case action_npn_get_url_notify: + { + FormatPCHARArgument(sz2, sizeof(sz2), &plis->arg2); + FormatPCHARArgument(sz3, sizeof(sz3), &plis->arg3); + sprintf(szString, "NPN_GetURLNotify(%#08lx, %s, %s, %#08lx)%s", dw1,sz2,sz3,dw4,szEOL); + break; + } + case action_npn_get_url: + { + FormatPCHARArgument(sz2, sizeof(sz2), &plis->arg2); + FormatPCHARArgument(sz3, sizeof(sz3), &plis->arg3); + sprintf(szString, "NPN_GetURL(%#08lx, %s, %s)%s", dw1,sz2,sz3,szEOL); + break; + } + case action_npn_post_url_notify: + { + FormatPCHARArgument(sz2, sizeof(sz2), &plis->arg2); + FormatPCHARArgument(sz3, sizeof(sz3), &plis->arg3); + FormatPCHARArgument(sz5, sizeof(sz5), &plis->arg5); + FormatBOOLArgument(sz6, sizeof(sz6), &plis->arg6); + + sprintf(szString, "NPN_PostURLNotify(%#08lx, %s, %s, %li, %s, %s, %#08lx)%s", + dw1,sz2,sz3,(uint32)dw4,sz5,sz6,dw7,szEOL); + break; + } + case action_npn_post_url: + { + FormatPCHARArgument(sz2, sizeof(sz2), &plis->arg2); + FormatPCHARArgument(sz3, sizeof(sz3), &plis->arg3); + FormatPCHARArgument(sz5, sizeof(sz5), &plis->arg5); + FormatBOOLArgument(sz6, sizeof(sz6), &plis->arg6); + + sprintf(szString, "NPN_PostURL(%#08lx, %s, %s, %li, %s, %s)%s", + dw1,sz2,sz3,(uint32)dw4,sz5,sz6,szEOL); + break; + } + case action_npn_new_stream: + { + FormatPCHARArgument(sz2, sizeof(sz2), &plis->arg2); + FormatPCHARArgument(sz3, sizeof(sz3), &plis->arg3); + if(plis->arg4.pData != NULL) + sprintf(szString, "NPN_NewStream(%#08lx, %s, %s, %#08lx(%#08lx))%s", + dw1, sz2,sz3,dw4,*(DWORD *)plis->arg4.pData,szEOL); + else + sprintf(szString, "NPN_NewStream(%#08lx, \"%s\", \"%s\", %#08lx)%s", dw1, sz2,sz3,dw4,szEOL); + break; + } + case action_npn_destroy_stream: + sprintf(szString, "NPN_DestroyStream(%#08lx, %#08lx, %s)%s", dw1,dw2,FormatNPAPIReason((int)dw3),szEOL); + break; + case action_npn_request_read: + sprintf(szString, "NPN_RequestRead(%#08lx, %#08lx)%s", dw1, dw2, szEOL); + break; + case action_npn_write: + { + FormatPCHARArgument(sz4, sizeof(sz4), &plis->arg4); + sprintf(szString, "NPN_Write(%#08lx, %#08lx, %li, %s)%s", dw1, dw2, (int32)dw3, sz4, szEOL); + break; + } + case action_npn_status: + { + FormatPCHARArgument(sz2, sizeof(sz2), &plis->arg2); + sprintf(szString, "NPN_Status(%#08lx, %s)%s", dw1, sz2, szEOL); + break; + } + case action_npn_user_agent: + sprintf(szString, "NPN_UserAgent(%#08lx)%s", dw1, szEOL); + break; + case action_npn_mem_alloc: + sprintf(szString, "NPN_MemAlloc(%li)%s", dw1, szEOL); + break; + case action_npn_mem_free: + sprintf(szString, "NPN_MemFree(%#08lx)%s", dw1,szEOL); + break; + case action_npn_mem_flush: + sprintf(szString, "NPN_MemFlush(%li)%s", dw1, szEOL); + break; + case action_npn_reload_plugins: + { + FormatBOOLArgument(sz1, sizeof(sz1), &plis->arg1); + sprintf(szString, "NPN_ReloadPlugins(%s)%s", sz1,szEOL); + break; + } + case action_npn_get_java_env: + sprintf(szString, "NPN_GetJavaEnv()%s", szEOL); + break; + case action_npn_get_java_peer: + sprintf(szString, "NPN_GetJavaPeer(%#08lx)%s", dw1, szEOL); + break; + case action_npn_get_value: + { + switch(dw2) + { + case NPNVxDisplay: + case NPNVxtAppContext: + case NPNVnetscapeWindow: + if(dw3 != 0L) + sprintf(szString, "NPN_GetValue(%#08lx, %s, %#08lx(%#08lx))%s",dw1,FormatNPNVariable((NPNVariable)dw2),dw3,*(DWORD *)dw3,szEOL); + else + sprintf(szString, "NPN_GetValue(%#08lx, %s, %#08lx)%s",dw1,FormatNPNVariable((NPNVariable)dw2),dw3,szEOL); + break; + case NPNVjavascriptEnabledBool: + case NPNVasdEnabledBool: + case NPNVisOfflineBool: + if(dw3 != 0L) + sprintf(szString, "NPN_GetValue(%#08lx, %s, %#08lx(%s))%s", + dw1,FormatNPNVariable((NPNVariable)dw2),dw3, + (((NPBool)*(DWORD *)dw3) == TRUE) ? "TRUE" : "FALSE", szEOL); + else + sprintf(szString, "NPN_GetValue(%#08lx, %s, %#08lx)%s",dw1,FormatNPNVariable((NPNVariable)dw2),dw3,szEOL); + break; + default: + break; + } + break; + } + case action_npn_set_value: + + if(((NPPVariable)dw2 == NPPVpluginNameString) || ((NPPVariable)dw2 == NPPVpluginDescriptionString)) + { + FormatPCHARArgument(sz3, sizeof(sz3), &plis->arg3); + sprintf(szString, "NPN_SetValue(%#08lx, %s, %s)%s", dw1,FormatNPPVariable((NPPVariable)dw2),sz3,szEOL); + } + else if(((NPPVariable)dw2 == NPPVpluginWindowBool) || ((NPPVariable)dw2 == NPPVpluginTransparentBool)) + { + FormatPBOOLArgument(sz3, sizeof(sz3), &plis->arg3); + sprintf(szString, "NPN_SetValue(%#08lx, %s, %s)%s", + dw1,FormatNPPVariable((NPPVariable)dw2),sz3,szEOL); + } + else if((NPPVariable)dw2 == NPPVpluginWindowSize) + { + if(plis->arg3.pData != NULL) + { + int32 iWidth = ((NPSize *)plis->arg3.pData)->width; + int32 iHeight = ((NPSize *)plis->arg3.pData)->height; + sprintf(szString, "NPN_SetValue(%#08lx, %s, %#08lx(%li,%li))%s", + dw1,FormatNPPVariable((NPPVariable)dw2),dw3,iWidth,iHeight,szEOL); + } + else + sprintf(szString, "NPN_SetValue(%#08lx, %s, %#08lx(?,?))%s", + dw1,FormatNPPVariable((NPPVariable)dw2),dw3,szEOL); + } + else + sprintf(szString, "NPN_SetValue(%#08lx, %s, %#08lx(What is it?))%s", dw1,FormatNPPVariable((NPPVariable)dw2),dw3,szEOL); + break; + case action_npn_invalidate_rect: + { + if(plis->arg2.pData != NULL) + { + uint16 top = ((NPRect *)plis->arg2.pData)->top; + uint16 left = ((NPRect *)plis->arg2.pData)->left; + uint16 bottom = ((NPRect *)plis->arg2.pData)->bottom; + uint16 right = ((NPRect *)plis->arg2.pData)->right; + sprintf(szString, "NPN_InvalidateRect(%#08lx, %#08lx(%u,%u;%u,%u)%s", dw1,dw2,top,left,bottom,right,szEOL); + } + else + sprintf(szString, "NPN_InvalidateRect(%#08lx, %#08lx(?,?,?,?)%s", dw1,dw2,szEOL); + break; + } + case action_npn_invalidate_region: + sprintf(szString, "NPN_InvalidateRegion(%#08lx, %#08lx)%s", dw1,dw2,szEOL); + break; + case action_npn_force_redraw: + sprintf(szString, "NPN_ForceRedraw(%#08lx)%s", dw1,szEOL); + break; + + // NPP action + case action_npp_new: + { + char szMode[16]; + switch (dw3) + { + case NP_EMBED: + strcpy(szMode, "NP_EMBED"); + break; + case NP_FULL: + strcpy(szMode, "NP_FULL"); + break; + default: + strcpy(szMode, "[Invalide mode]"); + break; + } + sprintf(szString, "NPP_New(\"%s\", %#08lx, %s, %i, %#08lx, %#08lx, %#08lx)%s", + (char *)dw1,dw2,szMode,(int)dw4,dw5,dw6,dw7,szEOL); + break; + } + case action_npp_destroy: + sprintf(szString, "NPP_Destroy(%#08lx, %#08lx(%#08lx))%s", dw1, dw2, *(DWORD *)plis->arg2.pData,szEOL); + break; + case action_npp_set_window: + { + char szWindow[512]; + + if(plis->arg2.pData != NULL) + { + char szType[80]; + switch (((NPWindow*)plis->arg2.pData)->type) + { + case NPWindowTypeWindow: + sprintf(szType, "NPWindowTypeWindow"); + break; + case NPWindowTypeDrawable: + sprintf(szType, "NPWindowTypeDrawable"); + break; + default: + sprintf(szType, "[Unlisted type]"); + break; + } + sprintf(szWindow, "NPWindow: %#08lx, (%li,%li), (%li,%li), (%i,%i,%i,%i), %s", + ((NPWindow*)plis->arg2.pData)->window, + ((NPWindow*)plis->arg2.pData)->x, + ((NPWindow*)plis->arg2.pData)->y, + ((NPWindow*)plis->arg2.pData)->width, + ((NPWindow*)plis->arg2.pData)->height, + ((NPWindow*)plis->arg2.pData)->clipRect.top, + ((NPWindow*)plis->arg2.pData)->clipRect.left, + ((NPWindow*)plis->arg2.pData)->clipRect.bottom, + ((NPWindow*)plis->arg2.pData)->clipRect.right, szType); + sprintf(szString, "NPP_SetWindow(%#08lx, %#08lx)%s%s%s", dw1,dw2," ",szWindow,szEOL); + } + else + sprintf(szString, "NPP_SetWindow(%#08lx, %#08lx)%s", dw1,dw2,szEOL); + + break; + } + case action_npp_new_stream: + { + switch (*(int16 *)plis->arg5.pData) + { + case NP_NORMAL: + sprintf(sz5, "NP_NORMAL"); + break; + case NP_ASFILEONLY: + sprintf(sz5, "NP_ASFILEONLY"); + break; + case NP_ASFILE: + sprintf(sz5, "NP_ASFILE"); + break; + default: + sprintf(sz5, "[Unlisted type]"); + break; + } + FormatPCHARArgument(sz2, sizeof(sz2), &plis->arg2); + sprintf(szString, "NPP_NewStream(%#08lx, %s, %#08lx, %s, %s)%s", dw1, sz2, dw3, + ((NPBool)dw4 == TRUE) ? "TRUE" : "FALSE", sz5, szEOL); + break; + } + case action_npp_destroy_stream: + sprintf(szString, "NPP_DestroyStream(%#08lx, %#08lx, %s)%s", dw1,dw2,FormatNPAPIReason((int)dw3),szEOL); + break; + case action_npp_stream_as_file: + FormatPCHARArgument(sz3, sizeof(sz3), &plis->arg3); + sprintf(szString, "NPP_StreamAsFile(%#08lx, %#08lx, %s)%s", dw1,dw2,sz3,szEOL); + break; + case action_npp_write_ready: + sprintf(szString, "NPP_WriteReady(%#08lx, %#08lx)%s", dw1,dw2,szEOL); + break; + case action_npp_write: + { + FormatPCHARArgument(sz5, sizeof(sz5), &plis->arg5); + sprintf(szString, "NPP_Write(%#08lx, %#08lx, %li, %li, %s))%s",dw1,dw2,dw3,dw4,sz5,szEOL); + break; + } + case action_npp_print: + sprintf(szString, "NPP_Print(%#08lx, %#08lx)%s", dw1, dw2,szEOL); + break; + case action_npp_handle_event: + sprintf(szString, "NPP_HandleEvent(%#08lx, %#08lx)%s", dw1,dw2,szEOL); + break; + case action_npp_url_notify: + { + FormatPCHARArgument(sz2, sizeof(sz2), &plis->arg2); + sprintf(szString, "NPP_URLNotify(%#08lx, %s, %s, %#08lx)%s", dw1,sz2,FormatNPAPIReason((int)dw3),dw4,szEOL); + break; + } + case action_npp_get_java_class: + sprintf(szString, "NPP_GetJavaClass()%s",szEOL); + break; + case action_npp_get_value: + sprintf(szString, "NPP_GetValue(%#08lx, %s, %#08lx)%s", dw1,FormatNPPVariable((NPPVariable)dw2),dw3,szEOL); + break; + case action_npp_set_value: + sprintf(szString, "NPP_SetValue(%#08lx, %s, %#08lx)%s", dw1,FormatNPNVariable((NPNVariable)dw2),dw3,szEOL); + break; + + default: + sprintf(szString, "Unknown action%s",szEOL); + break; + } + strcat(szOutput, szString); + strcat(szOutput, szEOI); + iRet = strlen(szString) + strlen(szEOI) + 1; + return iRet; +} diff --git a/mozilla/modules/plugin/npspy/common/logfile.cpp b/mozilla/modules/plugin/npspy/common/logfile.cpp new file mode 100644 index 00000000000..6afecd9fad8 --- /dev/null +++ b/mozilla/modules/plugin/npspy/common/logfile.cpp @@ -0,0 +1,69 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + * + */ + +#include "xp.h" + +#include "logfile.h" +#include "plugload.h" + +CLogFile::CLogFile() : + hFile(NULL) +{ + szFileName[0] = '\0'; +} + +CLogFile::~CLogFile() +{ + if(hFile != NULL) + close(); +} + +BOOL CLogFile::create(char * filename, BOOL delete_existing) +{ + strcpy(szFileName, filename); + + if(!delete_existing && XP_IsFile(szFileName)) + return FALSE; + + hFile = XP_CreateFile(szFileName); + return (hFile != NULL); +} + +void CLogFile::close() +{ + if(hFile != NULL) + { + XP_CloseFile(hFile); + hFile = NULL; + } +} + +DWORD CLogFile::write(char * buf) +{ + return XP_WriteFile(hFile, buf, strlen(buf)); +} + +void CLogFile::flush() +{ + XP_FlushFileBuffers(hFile); +} diff --git a/mozilla/modules/plugin/npspy/common/logger.cpp b/mozilla/modules/plugin/npspy/common/logger.cpp new file mode 100644 index 00000000000..bd66182bdf5 --- /dev/null +++ b/mozilla/modules/plugin/npspy/common/logger.cpp @@ -0,0 +1,383 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + * + */ + +#include "xp.h" +#include + +#include "resource.h" +#include "logger.h" +#include "profile.h" +#include "plugload.h" + +Logger::Logger() : + bMutedAll(FALSE), + bOnTop(TRUE), + bToWindow(TRUE), + bToConsole(FALSE), + bToFile(FALSE), + bSPALID(FALSE) +{ + if(0 != GetPluginsDir(szFile, strlen(szFile))) + { + strcat(szFile, "\\"); + strcat(szFile, DEFAULT_LOG_FILE_NAME); + } + else + szFile[0] = '\0'; + + for(int i = 0; i < sizeof(bMutedCalls)/sizeof(BOOL); i++) + bMutedCalls[i] = FALSE; + + bMutedCalls[action_npn_mem_alloc] = TRUE; + bMutedCalls[action_npn_mem_free] = TRUE; + bMutedCalls[action_npn_mem_flush] = TRUE; +} + +Logger::~Logger() +{ +} + +BOOL Logger::init() +{ + if(bToFile) + filer.create(szFile, TRUE); + + return TRUE; +} + +void Logger::shut() +{ + filer.close(); +} + +#define MAX_OUTPUT_SIZE 8192 + +void Logger::logNS_NP_GetEntryPoints() +{ + char szLog[] = "NP_GetEntryPoints by Netscape\r\n"; + + if(bToConsole) + printf("%s", szLog); + + if(bToFile) + filer.write(szLog); + + if(bToWindow) + dumpStringToMainWindow(szLog); +} + +void Logger::logNS_NP_Initialize() +{ + char szLog[] = "NP_Initialize by Netscape\r\n"; + + if(bToConsole) + printf("%s", szLog); + + if(bToFile) + filer.write(szLog); + + if(bToWindow) + dumpStringToMainWindow(szLog); +} + +void Logger::logNS_NP_Shutdown() +{ + char szLog[] = "NP_Shutdown by Netscape\r\n"; + + if(bToConsole) + printf("%s", szLog); + + if(bToFile) + filer.write(szLog); + + if(bToWindow) + dumpStringToMainWindow(szLog); +} + +void Logger::logSPY_NP_GetEntryPoints(NPPluginFuncs * pNPPFuncs) +{ + char szLog[80] = "NP_GetEntryPoints by NPSpy\r\n"; + + if(bToConsole) + printf("%s", szLog); + + if(bToFile) + filer.write(szLog); + + if(bToWindow) + dumpStringToMainWindow(szLog); + + if(!pNPPFuncs) + return; + + char szLog1[80],szLog2[80],szLog3[80],szLog4[80],szLog5[80],szLog6[80],szLog7[80], + szLog8[80],szLog9[80],szLog10[80],szLog11[80],szLog12[80],szLog13[80],szLog14[80], + szLog15[80],szLog16[80],szLog17[80],szLog18[80],szLog19[80],szLog20[80]; + + sprintf(szLog1, "\r\n"); + sprintf(szLog2, " Plugin entry point table\r\n"); + sprintf(szLog3, " ========================\r\n"); + + if(pNPPFuncs->size) + sprintf(szLog4, " size = %i\r\n", pNPPFuncs->size); + else + sprintf(szLog4, " size = not set!\r\n"); + + if(pNPPFuncs->version) + sprintf(szLog5, " version = %i\r\n", pNPPFuncs->version); + else + sprintf(szLog5, " version = not set!\r\n"); + + if(pNPPFuncs->newp) + sprintf(szLog6, " newp = %#08lx\r\n", pNPPFuncs->newp); + else + sprintf(szLog6, " newp = not set!\r\n"); + + if(pNPPFuncs->destroy) + sprintf(szLog7, " destroy = %#08lx\r\n", pNPPFuncs->destroy); + else + sprintf(szLog7, " destroy = not set!\r\n"); + + if(pNPPFuncs->setwindow) + sprintf(szLog8, " setwindow = %#08lx\r\n", pNPPFuncs->setwindow); + else + sprintf(szLog8, " setwindow = not set!\r\n"); + + if(pNPPFuncs->newstream) + sprintf(szLog9, " newstream = %#08lx\r\n", pNPPFuncs->newstream); + else + sprintf(szLog9, " newstream = not set!\r\n"); + + if(pNPPFuncs->destroystream) + sprintf(szLog10, " destroystream = %#08lx\r\n", pNPPFuncs->destroystream); + else + sprintf(szLog10, " destroystream = not set!\r\n"); + + if(pNPPFuncs->asfile) + sprintf(szLog11, " asfile = %#08lx\r\n", pNPPFuncs->asfile); + else + sprintf(szLog11, " asfile = not set!\r\n"); + + if(pNPPFuncs->writeready) + sprintf(szLog12, " writeready = %#08lx\r\n", pNPPFuncs->writeready); + else + sprintf(szLog12, " writeready = not set!\r\n"); + + if(pNPPFuncs->write) + sprintf(szLog13, " write = %#08lx\r\n", pNPPFuncs->write); + else + sprintf(szLog13, " write = not set!\r\n"); + + if(pNPPFuncs->print) + sprintf(szLog14, " print = %#08lx\r\n", pNPPFuncs->print); + else + sprintf(szLog14, " print = not set!\r\n"); + + if(pNPPFuncs->event) + sprintf(szLog15, " event = %#08lx\r\n", pNPPFuncs->event); + else + sprintf(szLog15, " event = not set!\r\n"); + + if(pNPPFuncs->urlnotify) + sprintf(szLog16, " urlnotify = %#08lx\r\n", pNPPFuncs->urlnotify); + else + sprintf(szLog16, " urlnotify = not set!\r\n"); + + if(pNPPFuncs->javaClass) + sprintf(szLog17, " javaClass = %#08lx\r\n", pNPPFuncs->javaClass); + else + sprintf(szLog17, " javaClass = not set!\r\n"); + + if(pNPPFuncs->getvalue) + sprintf(szLog18, " getvalue = %#08lx\r\n", pNPPFuncs->getvalue); + else + sprintf(szLog18, " getvalue = not set!\r\n"); + + if(pNPPFuncs->setvalue) + sprintf(szLog19, " setvalue = %#08lx\r\n", pNPPFuncs->setvalue); + else + sprintf(szLog19, " setvalue = not set!\r\n"); + + sprintf(szLog20, "\r\n"); + + if(bToConsole) + { + printf("%s", szLog1); printf("%s", szLog2); printf("%s", szLog3); printf("%s", szLog4); + printf("%s", szLog5); printf("%s", szLog6); printf("%s", szLog7); printf("%s", szLog8); + printf("%s", szLog9); printf("%s", szLog10); printf("%s", szLog11); printf("%s", szLog12); + printf("%s", szLog13); printf("%s", szLog14); printf("%s", szLog15); printf("%s", szLog16); + printf("%s", szLog17); printf("%s", szLog18); printf("%s", szLog19); printf("%s", szLog20); + } + + if(bToFile) + { + filer.write(szLog1); filer.write(szLog2); filer.write(szLog3); filer.write(szLog4); + filer.write(szLog5); filer.write(szLog6); filer.write(szLog7); filer.write(szLog8); + filer.write(szLog9); filer.write(szLog10); filer.write(szLog11); filer.write(szLog12); + filer.write(szLog13); filer.write(szLog14); filer.write(szLog15); filer.write(szLog16); + filer.write(szLog17); filer.write(szLog18); filer.write(szLog19); filer.write(szLog20); + } + + if(bToWindow) + { + dumpStringToMainWindow(szLog1); dumpStringToMainWindow(szLog2); + dumpStringToMainWindow(szLog3); dumpStringToMainWindow(szLog4); + dumpStringToMainWindow(szLog5); dumpStringToMainWindow(szLog6); + dumpStringToMainWindow(szLog7); dumpStringToMainWindow(szLog8); + dumpStringToMainWindow(szLog9); dumpStringToMainWindow(szLog10); + dumpStringToMainWindow(szLog11); dumpStringToMainWindow(szLog12); + dumpStringToMainWindow(szLog13); dumpStringToMainWindow(szLog14); + dumpStringToMainWindow(szLog15); dumpStringToMainWindow(szLog16); + dumpStringToMainWindow(szLog17); dumpStringToMainWindow(szLog18); + dumpStringToMainWindow(szLog19); dumpStringToMainWindow(szLog20); + } +} + +void Logger::logSPY_NP_Initialize() +{ + char szLog[] = "NP_Initialize by NPSpy\r\n"; + + if(bToConsole) + printf("%s", szLog); + + if(bToFile) + filer.write(szLog); + + if(bToWindow) + dumpStringToMainWindow(szLog); +} + +void Logger::logSPY_NP_Shutdown(char * mimetype) +{ + char szLog[512] = "NP_Shutdown by NPSpy\r\n"; + if(mimetype) + { + strcat(szLog, " for \""); + strcat(szLog, mimetype); + strcat(szLog, "\""); + } + + if(bToConsole) + printf("%s", szLog); + + if(bToFile) + filer.write(szLog); + + if(bToWindow) + dumpStringToMainWindow(szLog); +} + +void Logger::logCall(NPAPI_Action action, DWORD dw1, DWORD dw2, DWORD dw3, DWORD dw4, DWORD dw5, DWORD dw6, DWORD dw7) +{ + if(isMuted(action)) + return; + + static char szLog[512]; + + LogItemStruct * lis = makeLogItemStruct(action, dw1, dw2, dw3, dw4, dw5, dw6, dw7); + int iLength = formatLogItem(lis, szLog, TRUE); + freeLogItemStruct(lis); + + if(bToConsole) + printf("%s", szLog); + + if(bToFile) + filer.write(szLog); + + if(bToWindow) + dumpStringToMainWindow(szLog); +} + +void Logger::logReturn(DWORD dwRet) +{ +} + +void Logger::setOnTop(BOOL ontop) +{ + bOnTop = ontop; +} + +void Logger::setToFile(BOOL tofile, char * filename) +{ + if(!filename || (strlen(filename) == 0) || (strlen(filename) > _MAX_PATH)) + { + bToFile = FALSE; + return; + } + + //don't screw up the file on false call + BOOL samefile = (stricmp(szFile, filename) == 0); + BOOL sameaction = (bToFile == tofile); + + if(sameaction) + { + if(samefile) + return; + + strcpy(szFile, filename); + + if(bToFile) + { + filer.close(); + filer.create(szFile, TRUE); + } + } + + if(!sameaction) + { + bToFile = tofile; + + if(!samefile) + strcpy(szFile, filename); + + if(bToFile) + filer.create(szFile, TRUE); + else + filer.close(); + } +} + +BOOL Logger::isMuted(NPAPI_Action action) +{ + if(bMutedAll) + return TRUE; + + if(action >= TOTAL_NUMBER_OF_API_CALLS) + { + assert(0); + return FALSE; + } + + return bMutedCalls[action]; +} + +BOOL * Logger::getMutedCalls() +{ + return &bMutedCalls[0]; +} + +void Logger::setMutedCalls(BOOL * mutedcalls) +{ + for(int i = 0; i < sizeof(bMutedCalls)/sizeof(BOOL); i++) + bMutedCalls[i] = mutedcalls[i]; +} diff --git a/mozilla/modules/plugin/npspy/common/np_entry.cpp b/mozilla/modules/plugin/npspy/common/np_entry.cpp new file mode 100644 index 00000000000..766cdf6b82a --- /dev/null +++ b/mozilla/modules/plugin/npspy/common/np_entry.cpp @@ -0,0 +1,155 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + * + */ + +#include "xp.h" + +#include "npapi.h" +#include "npupp.h" +#include "epmanager.h" +#include "logger.h" + +// we need to keep track of different plugins and different instances +// of the same plugin when we call NPP functions, so that we always +// call the right ones. Entry point manager will take care of it. +NPPEntryPointManager * epManager = NULL; + +Logger * logger = NULL; + +NPNetscapeFuncs NPNFuncs; + +NPError WINAPI NP_GetEntryPoints(NPPluginFuncs* pFuncs) +{ + // create the logger + if(!logger) + { + logger = NewLogger(); + if(logger) + { + logger->platformInit(); + logger->init(); + } + } + + if(logger) + logger->logNS_NP_GetEntryPoints(); + + if(pFuncs == NULL) + return NPERR_INVALID_FUNCTABLE_ERROR; + + if(pFuncs->size < sizeof(NPPluginFuncs)) + return NPERR_INVALID_FUNCTABLE_ERROR; + + pFuncs->version = (NP_VERSION_MAJOR << 8) | NP_VERSION_MINOR; + pFuncs->newp = NPP_New; + pFuncs->destroy = NPP_Destroy; + pFuncs->setwindow = NPP_SetWindow; + pFuncs->newstream = NPP_NewStream; + pFuncs->destroystream = NPP_DestroyStream; + pFuncs->asfile = NPP_StreamAsFile; + pFuncs->writeready = NPP_WriteReady; + pFuncs->write = NPP_Write; + pFuncs->print = NPP_Print; + pFuncs->event = NPP_HandleEvent; + pFuncs->urlnotify = NPP_URLNotify; + pFuncs->getvalue = NPP_GetValue; + pFuncs->setvalue = NPP_SetValue; + pFuncs->javaClass = NULL; + + return NPERR_NO_ERROR; +} + +NPError WINAPI NP_Initialize(NPNetscapeFuncs* pFuncs) +{ + // create the logger + if(!logger) + { + logger = NewLogger(); + if(logger) + { + logger->platformInit(); + logger->init(); + } + } + + if(logger) + logger->logNS_NP_Initialize(); + + if(pFuncs == NULL) + return NPERR_INVALID_FUNCTABLE_ERROR; + + if(HIBYTE(pFuncs->version) > NP_VERSION_MAJOR) + return NPERR_INCOMPATIBLE_VERSION_ERROR; + + if(pFuncs->size < sizeof NPNetscapeFuncs) + return NPERR_INVALID_FUNCTABLE_ERROR; + + NPNFuncs.size = pFuncs->size; + NPNFuncs.version = pFuncs->version; + NPNFuncs.geturlnotify = pFuncs->geturlnotify; + NPNFuncs.geturl = pFuncs->geturl; + NPNFuncs.posturlnotify = pFuncs->posturlnotify; + NPNFuncs.posturl = pFuncs->posturl; + NPNFuncs.requestread = pFuncs->requestread; + NPNFuncs.newstream = pFuncs->newstream; + NPNFuncs.write = pFuncs->write; + NPNFuncs.destroystream = pFuncs->destroystream; + NPNFuncs.status = pFuncs->status; + NPNFuncs.uagent = pFuncs->uagent; + NPNFuncs.memalloc = pFuncs->memalloc; + NPNFuncs.memfree = pFuncs->memfree; + NPNFuncs.memflush = pFuncs->memflush; + NPNFuncs.reloadplugins = pFuncs->reloadplugins; + NPNFuncs.getJavaEnv = pFuncs->getJavaEnv; + NPNFuncs.getJavaPeer = pFuncs->getJavaPeer; + NPNFuncs.getvalue = pFuncs->getvalue; + NPNFuncs.setvalue = pFuncs->setvalue; + NPNFuncs.invalidaterect = pFuncs->invalidaterect; + NPNFuncs.invalidateregion = pFuncs->invalidateregion; + NPNFuncs.forceredraw = pFuncs->forceredraw; + + // create entry point manager for real plugins + epManager = new NPPEntryPointManager(); + if(!epManager) + return NPERR_GENERIC_ERROR; + + return NPERR_NO_ERROR; +} + +NPError WINAPI NP_Shutdown() +{ + // should be safe because if they've already been called shutdown procs must be NULL + if(epManager) + epManager->callNP_ShutdownAll(); // this will log the action + + if(logger) + { + logger->shut(); + logger->platformShut(); + DeleteLogger(logger); + logger = NULL; + } + + delete epManager; + + return NPERR_NO_ERROR; +} diff --git a/mozilla/modules/plugin/npspy/common/npn_gate.cpp b/mozilla/modules/plugin/npspy/common/npn_gate.cpp new file mode 100644 index 00000000000..e92120f02f0 --- /dev/null +++ b/mozilla/modules/plugin/npspy/common/npn_gate.cpp @@ -0,0 +1,336 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + * + */ + +#include "xp.h" + +#include "npapi.h" +#include "npupp.h" + +#include "logger.h" + +extern Logger * logger; +extern NPNetscapeFuncs NPNFuncs; + +void NPN_Version(int* plugin_major, int* plugin_minor, int* netscape_major, int* netscape_minor) +{ + if(logger) + logger->logCall(action_npn_version, (DWORD)plugin_major, (DWORD)plugin_minor, (DWORD)netscape_major, (DWORD)netscape_minor); + + *plugin_major = NP_VERSION_MAJOR; + *plugin_minor = NP_VERSION_MINOR; + *netscape_major = HIBYTE(NPNFuncs.version); + *netscape_minor = LOBYTE(NPNFuncs.version); + + if(logger) + logger->logReturn(); +} + +NPError NPN_GetURLNotify(NPP instance, const char *url, const char *target, void* notifyData) +{ + int navMinorVers = NPNFuncs.version & 0xFF; + + NPError rv = NPERR_NO_ERROR; + + if(logger) + logger->logCall(action_npn_get_url_notify, (DWORD)instance, (DWORD)url, (DWORD)target, (DWORD)notifyData); + + if( navMinorVers >= NPVERS_HAS_NOTIFICATION ) + rv = NPNFuncs.geturlnotify(instance, url, target, notifyData); + else + rv = NPERR_INCOMPATIBLE_VERSION_ERROR; + + if(logger) + logger->logReturn(); + + return rv; +} + +NPError NPN_GetURL(NPP instance, const char *url, const char *target) +{ + if(logger) + logger->logCall(action_npn_get_url, (DWORD)instance, (DWORD)url, (DWORD)target); + + NPError rv = NPNFuncs.geturl(instance, url, target); + + if(logger) + logger->logReturn(); + + return rv; +} + +NPError NPN_PostURLNotify(NPP instance, const char* url, const char* window, uint32 len, const char* buf, NPBool file, void* notifyData) +{ + int navMinorVers = NPNFuncs.version & 0xFF; + + NPError rv = NPERR_NO_ERROR; + + if(logger) + logger->logCall(action_npn_post_url_notify, (DWORD)instance, (DWORD)url, (DWORD)window, (DWORD)len, (DWORD)buf, (DWORD)file, (DWORD)notifyData); + + if( navMinorVers >= NPVERS_HAS_NOTIFICATION ) + rv = NPNFuncs.posturlnotify(instance, url, window, len, buf, file, notifyData); + else + rv = NPERR_INCOMPATIBLE_VERSION_ERROR; + + if(logger) + logger->logReturn(); + + return rv; +} + +NPError NPN_PostURL(NPP instance, const char* url, const char* window, uint32 len, const char* buf, NPBool file) +{ + if(logger) + logger->logCall(action_npn_post_url, (DWORD)instance, (DWORD)url, (DWORD)window, (DWORD)len, (DWORD)buf, (DWORD)file); + + NPError rv = NPNFuncs.posturl(instance, url, window, len, buf, file); + + if(logger) + logger->logReturn(); + + return rv; +} + +NPError NPN_RequestRead(NPStream* stream, NPByteRange* rangeList) +{ + if(logger) + logger->logCall(action_npn_request_read, (DWORD)stream, (DWORD)rangeList); + + NPError rv = NPNFuncs.requestread(stream, rangeList); + + if(logger) + logger->logReturn(); + + return rv; +} + +NPError NPN_NewStream(NPP instance, NPMIMEType type, const char* target, NPStream** stream) +{ + int navMinorVersion = NPNFuncs.version & 0xFF; + + NPError rv = NPERR_NO_ERROR; + + if(logger) + logger->logCall(action_npn_new_stream, (DWORD)instance, (DWORD)type, (DWORD)target, (DWORD)stream); + + if( navMinorVersion >= NPVERS_HAS_STREAMOUTPUT ) + rv = NPNFuncs.newstream(instance, type, target, stream); + else + rv = NPERR_INCOMPATIBLE_VERSION_ERROR; + + if(logger) + logger->logReturn(); + + return rv; +} + +int32 NPN_Write(NPP instance, NPStream *stream, int32 len, void *buffer) +{ + int navMinorVersion = NPNFuncs.version & 0xFF; + + int32 rv = 0; + + if(logger) + logger->logCall(action_npn_write, (DWORD)instance, (DWORD)stream, (DWORD)len, (DWORD)buffer); + + if( navMinorVersion >= NPVERS_HAS_STREAMOUTPUT ) + rv = NPNFuncs.write(instance, stream, len, buffer); + else + rv = -1; + + if(logger) + logger->logReturn(); + + return rv; +} + +NPError NPN_DestroyStream(NPP instance, NPStream* stream, NPError reason) +{ + int navMinorVersion = NPNFuncs.version & 0xFF; + + NPError rv = NPERR_NO_ERROR; + + if(logger) + logger->logCall(action_npn_destroy_stream, (DWORD)instance, (DWORD)stream, (DWORD)reason); + + if( navMinorVersion >= NPVERS_HAS_STREAMOUTPUT ) + rv = NPNFuncs.destroystream(instance, stream, reason); + else + rv = NPERR_INCOMPATIBLE_VERSION_ERROR; + + if(logger) + logger->logReturn(); + + return rv; +} + +void NPN_Status(NPP instance, const char *message) +{ + if(logger) + logger->logCall(action_npn_status, (DWORD)instance, (DWORD)message); + + NPNFuncs.status(instance, message); +} + +const char* NPN_UserAgent(NPP instance) +{ + const char * rv = NULL; + + if(logger) + logger->logCall(action_npn_user_agent, (DWORD)instance); + + rv = NPNFuncs.uagent(instance); + + if(logger) + logger->logReturn(); + + return rv; +} + +void* NPN_MemAlloc(uint32 size) +{ + void * rv = NULL; + + if(logger) + logger->logCall(action_npn_mem_alloc, (DWORD)size); + + rv = NPNFuncs.memalloc(size); + + if(logger) + logger->logReturn(); + + return rv; +} + +void NPN_MemFree(void* ptr) +{ + if(logger) + logger->logCall(action_npn_mem_free, (DWORD)ptr); + + NPNFuncs.memfree(ptr); +} + +uint32 NPN_MemFlush(uint32 size) +{ + if(logger) + logger->logCall(action_npn_mem_flush, (DWORD)size); + + uint32 rv = NPNFuncs.memflush(size); + + if(logger) + logger->logReturn(); + + return rv; +} + +void NPN_ReloadPlugins(NPBool reloadPages) +{ + if(logger) + logger->logCall(action_npn_reload_plugins, (DWORD)reloadPages); + + NPNFuncs.reloadplugins(reloadPages); +} + +JRIEnv* NPN_GetJavaEnv(void) +{ + JRIEnv * rv = NULL; + + if(logger) + logger->logCall(action_npn_get_java_env); + + rv = NPNFuncs.getJavaEnv(); + + if(logger) + logger->logReturn(); + + return rv; +} + +jref NPN_GetJavaPeer(NPP instance) +{ + jref rv; + + if(logger) + logger->logCall(action_npn_get_java_peer, (DWORD)instance); + + rv = NPNFuncs.getJavaPeer(instance); + + if(logger) + logger->logReturn(); + + return rv; +} + +NPError NPN_GetValue(NPP instance, NPNVariable variable, void *value) +{ + NPError rv = NPERR_NO_ERROR; + + if(logger) + logger->logCall(action_npn_get_value, (DWORD)instance, (DWORD)variable, (DWORD)value); + + rv = NPNFuncs.getvalue(instance, variable, value); + + if(logger) + logger->logReturn(action_npn_get_value); + + return rv; +} + +NPError NPN_SetValue(NPP instance, NPPVariable variable, void *value) +{ + NPError rv = NPERR_NO_ERROR; + + if(logger) + logger->logCall(action_npn_set_value, (DWORD)instance, (DWORD)variable, (DWORD)value); + + rv = NPNFuncs.setvalue(instance, variable, value); + + if(logger) + logger->logReturn(); + + return rv; +} + +void NPN_InvalidateRect(NPP instance, NPRect *invalidRect) +{ + if(logger) + logger->logCall(action_npn_invalidate_rect, (DWORD)instance, (DWORD)invalidRect); + + NPNFuncs.invalidaterect(instance, invalidRect); +} + +void NPN_InvalidateRegion(NPP instance, NPRegion invalidRegion) +{ + if(logger) + logger->logCall(action_npn_invalidate_region, (DWORD)instance, (DWORD)invalidRegion); + + NPNFuncs.invalidateregion(instance, invalidRegion); +} + +void NPN_ForceRedraw(NPP instance) +{ + if(logger) + logger->logCall(action_npn_force_redraw, (DWORD)instance); + + NPNFuncs.forceredraw(instance); +} diff --git a/mozilla/modules/plugin/npspy/common/npp_gate.cpp b/mozilla/modules/plugin/npspy/common/npp_gate.cpp new file mode 100644 index 00000000000..2e19e255e52 --- /dev/null +++ b/mozilla/modules/plugin/npspy/common/npp_gate.cpp @@ -0,0 +1,370 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + * + */ + +#include "xp.h" + +#include "resource.h" +#include "epmanager.h" +#include "plugload.h" +#include "logger.h" + +extern NPNetscapeFuncs NPNFuncs; +extern Logger * logger; + +NPNetscapeFuncs fakeNPNFuncs; + +extern NPPEntryPointManager * epManager; + +jref NPP_GetJavaClass (void) +{ + if(logger) + logger->logCall(action_npp_get_java_class); + + if(logger) + logger->logReturn(); + return NULL; +} + +NPError NPP_New(NPMIMEType pluginType, + NPP instance, + uint16 mode, + int16 argc, + char* argn[], + char* argv[], + NPSavedData* saved) +{ + if(epManager == NULL) + return NPERR_GENERIC_ERROR; + + if(instance == NULL) + return NPERR_INVALID_INSTANCE_ERROR; + + if(logger) + logger->logCall(action_npp_new, (DWORD)pluginType, (DWORD)instance, (DWORD)mode, (DWORD)argc, (DWORD)argn, (DWORD)argv, (DWORD)saved); + +/* now action begins */ + + if(NULL == epManager->findEntryPointsForPlugin(pluginType)) + { + // if it is first time in, we don't have it yet + // scan plugins dir for available plugins to see if we have anything + // for the given mimetype + XP_HLIB hLib = LoadRealPlugin(pluginType); + if(!hLib) + { + // what do we do if we don't? + return NPERR_GENERIC_ERROR; + } + + NP_GETENTRYPOINTS real_NP_GetEntryPoints = (NP_GETENTRYPOINTS)GetProcAddress(hLib, "NP_GetEntryPoints"); + if(!real_NP_GetEntryPoints) + return NPERR_GENERIC_ERROR; + + NP_INITIALIZE real_NP_Initialize = (NP_INITIALIZE)GetProcAddress(hLib, "NP_Initialize"); + if(!real_NP_Initialize) + return NPERR_GENERIC_ERROR; + + NP_SHUTDOWN real_NP_Shutdown = (NP_SHUTDOWN)GetProcAddress(hLib, "NP_Shutdown"); + if(!real_NP_Shutdown) + return NPERR_GENERIC_ERROR; + + // fill callbacks structs + NPPluginFuncs realNPPFuncs; + memset(&realNPPFuncs, 0, sizeof(NPPluginFuncs)); + realNPPFuncs.size = sizeof(NPPluginFuncs); + + real_NP_GetEntryPoints(&realNPPFuncs); + + if(logger) + logger->logSPY_NP_GetEntryPoints(&realNPPFuncs); + + // store the table with the entry point manager + epManager->createEntryPointsForPlugin(pluginType, &realNPPFuncs, real_NP_Shutdown, hLib); + + // inform the plugin about our entry point it should call + memset((void *)&fakeNPNFuncs, 0, sizeof(fakeNPNFuncs)); + + fakeNPNFuncs.size = sizeof(fakeNPNFuncs); + fakeNPNFuncs.version = NPNFuncs.version; + fakeNPNFuncs.geturlnotify = NPN_GetURLNotify; + fakeNPNFuncs.geturl = NPN_GetURL; + fakeNPNFuncs.posturlnotify = NPN_PostURLNotify; + fakeNPNFuncs.posturl = NPN_PostURL; + fakeNPNFuncs.requestread = NPN_RequestRead; + fakeNPNFuncs.newstream = NPN_NewStream; + fakeNPNFuncs.write = NPN_Write; + fakeNPNFuncs.destroystream = NPN_DestroyStream; + fakeNPNFuncs.status = NPN_Status; + fakeNPNFuncs.uagent = NPN_UserAgent; + fakeNPNFuncs.memalloc = NPN_MemAlloc; + fakeNPNFuncs.memfree = NPN_MemFree; + fakeNPNFuncs.memflush = NPN_MemFlush; + fakeNPNFuncs.reloadplugins = NPN_ReloadPlugins; + fakeNPNFuncs.getJavaEnv = NPN_GetJavaEnv; + fakeNPNFuncs.getJavaPeer = NPN_GetJavaPeer; + fakeNPNFuncs.getvalue = NPN_GetValue; + fakeNPNFuncs.setvalue = NPN_SetValue; + fakeNPNFuncs.invalidaterect = NPN_InvalidateRect; + fakeNPNFuncs.invalidateregion = NPN_InvalidateRegion; + fakeNPNFuncs.forceredraw = NPN_ForceRedraw; + + if(logger) + logger->logSPY_NP_Initialize(); + + real_NP_Initialize(&fakeNPNFuncs); + } + + NPError rv = epManager->callNPP_New(pluginType, instance, mode, argc, argn, argv, saved); + + if(logger) + logger->logReturn(); + + return rv; +} + +NPError NPP_Destroy (NPP instance, NPSavedData** save) +{ + if(epManager == NULL) + return NPERR_GENERIC_ERROR; + + if(instance == NULL) + return NPERR_INVALID_INSTANCE_ERROR; + + BOOL last = FALSE; + + if(logger) + logger->logCall(action_npp_destroy, (DWORD)instance, (DWORD)save); + + NPError rv = epManager->callNPP_Destroy(instance, save, &last); + + if(logger) + logger->logReturn(); + + if(last && logger->bSPALID) + { + // this will log it + epManager->callNP_Shutdown(instance); + + XP_HLIB hLib = NULL; + + epManager->removeEntryPointsForPlugin(instance, &hLib); + + UnloadRealPlugin(hLib); + } + return rv; +} + +NPError NPP_SetWindow (NPP instance, NPWindow* pNPWindow) +{ + if(epManager == NULL) + return NPERR_GENERIC_ERROR; + + if(instance == NULL) + return NPERR_INVALID_INSTANCE_ERROR; + + if(logger) + logger->logCall(action_npp_set_window, (DWORD)instance, (DWORD)pNPWindow); + + NPError rv = epManager->callNPP_SetWindow(instance, pNPWindow); + + if(logger) + logger->logReturn(); + + return rv; +} + +NPError NPP_NewStream(NPP instance, + NPMIMEType type, + NPStream* stream, + NPBool seekable, + uint16* stype) +{ + if(epManager == NULL) + return NPERR_GENERIC_ERROR; + + if(instance == NULL) + return NPERR_INVALID_INSTANCE_ERROR; + + if(logger) + logger->logCall(action_npp_new_stream, (DWORD)instance, (DWORD)type, (DWORD)stream, (DWORD)seekable, (DWORD)stype); + + NPError rv = epManager->callNPP_NewStream(instance, type, stream, seekable, stype); + + if(logger) + logger->logReturn(); + + return rv; +} + +int32 NPP_WriteReady (NPP instance, NPStream *stream) +{ + if(epManager == NULL) + return NPERR_GENERIC_ERROR; + + if(instance == NULL) + return NPERR_INVALID_INSTANCE_ERROR; + + if(logger) + logger->logCall(action_npp_write_ready, (DWORD)instance, (DWORD)stream); + + int32 rv = epManager->callNPP_WriteReady(instance, stream); + + if(logger) + logger->logReturn(); + + return rv; +} + +int32 NPP_Write (NPP instance, NPStream *stream, int32 offset, int32 len, void *buffer) +{ + if(epManager == NULL) + return NPERR_GENERIC_ERROR; + + if(instance == NULL) + return NPERR_INVALID_INSTANCE_ERROR; + + if(logger) + logger->logCall(action_npp_write, (DWORD)instance, (DWORD)stream, (DWORD)offset, (DWORD)len, (DWORD)buffer); + + int32 rv = epManager->callNPP_Write(instance, stream, offset, len, buffer); + + if(logger) + logger->logReturn(); + + return rv; +} + +NPError NPP_DestroyStream (NPP instance, NPStream *stream, NPError reason) +{ + if(epManager == NULL) + return NPERR_GENERIC_ERROR; + + if(instance == NULL) + return NPERR_INVALID_INSTANCE_ERROR; + + if(logger) + logger->logCall(action_npp_destroy_stream, (DWORD)instance, (DWORD)stream, (DWORD)reason); + + NPError rv = epManager->callNPP_DestroyStream(instance, stream, reason); + + if(logger) + logger->logReturn(); + + return rv; +} + +void NPP_StreamAsFile (NPP instance, NPStream* stream, const char* fname) +{ + if(epManager == NULL) + return; + + if(instance == NULL) + return; + + if(logger) + logger->logCall(action_npp_stream_as_file, (DWORD)instance, (DWORD)stream, (DWORD)fname); + + epManager->callNPP_StreamAsFile(instance, stream, fname); +} + +void NPP_Print (NPP instance, NPPrint* printInfo) +{ + if(epManager == NULL) + return; + + if(logger) + logger->logCall(action_npp_print, (DWORD)instance, (DWORD)printInfo); + + epManager->callNPP_Print(instance, printInfo); +} + +void NPP_URLNotify(NPP instance, const char* url, NPReason reason, void* notifyData) +{ + if(epManager == NULL) + return; + + if(instance == NULL) + return; + + if(logger) + logger->logCall(action_npp_url_notify, (DWORD)instance, (DWORD)url, (DWORD)reason, (DWORD)notifyData); + + epManager->callNPP_URLNotify(instance, url, reason, notifyData); +} + +NPError NPP_GetValue(NPP instance, NPPVariable variable, void *value) +{ + if(epManager == NULL) + return NPERR_GENERIC_ERROR; + + if(instance == NULL) + return NPERR_INVALID_INSTANCE_ERROR; + + if(logger) + logger->logCall(action_npp_get_value, (DWORD)instance, (DWORD)variable, (DWORD)value); + + NPError rv = epManager->callNPP_GetValue(instance, variable, value); + + if(logger) + logger->logReturn(); + + return rv; +} + +NPError NPP_SetValue(NPP instance, NPNVariable variable, void *value) +{ + if(epManager == NULL) + return NPERR_GENERIC_ERROR; + + if(instance == NULL) + return NPERR_INVALID_INSTANCE_ERROR; + + if(logger) + logger->logCall(action_npp_set_value, (DWORD)instance, (DWORD)variable, (DWORD)value); + + NPError rv = epManager->callNPP_SetValue(instance, variable, value); + + if(logger) + logger->logReturn(); + + return rv; +} + +int16 NPP_HandleEvent(NPP instance, void* event) +{ + if(epManager == NULL) + return 0; + + if(instance == NULL) + return 0; + + if(logger) + logger->logCall(action_npp_handle_event, (DWORD)instance, (DWORD)event); + + int16 rv = epManager->callNPP_HandleEvent(instance, event); + + if(logger) + logger->logReturn(); + + return rv; +} diff --git a/mozilla/modules/plugin/npspy/common/plugload.cpp b/mozilla/modules/plugin/npspy/common/plugload.cpp new file mode 100644 index 00000000000..bc0955c20a8 --- /dev/null +++ b/mozilla/modules/plugin/npspy/common/plugload.cpp @@ -0,0 +1,180 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + * + */ + +#include "xp.h" + +DWORD GetPluginsDir(char * path, DWORD maxsize) +{ + if(!path) + return 0; + + path[0] = '\0'; + +#ifdef XP_WIN + + DWORD res = GetModuleFileName(NULL, path, maxsize); + if(res == 0) + return 0; + + if(path[strlen(path) - 1] == '\\') + path[lstrlen(path) - 1] = '\0'; + + char *p = strrchr(path, '\\'); + + if(p) + *p = '\0'; + + strcat(path, "\\plugins"); + +#endif + +#ifdef XP_UNIX + // Implement UNIX version +#endif + +#ifdef XP_MAC + // Implement Mac version +#endif + + res = strlen(path); + return res; +} + +XP_HLIB LoadRealPlugin(char * mimetype) +{ + if(!mimetype || !strlen(mimetype)) + return NULL; + +#ifdef XP_WIN + + BOOL bDone = FALSE; + WIN32_FIND_DATA ffdataStruct; + + char szPath[_MAX_PATH]; + char szFileName[_MAX_PATH]; + + GetPluginsDir(szPath, _MAX_PATH); + + strcpy(szFileName, szPath); + strcat(szFileName, "\\00*"); + + HANDLE handle = FindFirstFile(szFileName, &ffdataStruct); + if(handle == INVALID_HANDLE_VALUE) + { + FindClose(handle); + return NULL; + } + + DWORD versize = 0L; + DWORD zero = 0L; + char * verbuf = NULL; + + do + { + strcpy(szFileName, szPath); + strcat(szFileName, "\\"); + strcat(szFileName, ffdataStruct.cFileName); + if(!(ffdataStruct. dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) + { + versize = GetFileVersionInfoSize(szFileName, &zero); + if (versize > 0) + verbuf = new char[versize]; + else + continue; + + if(!verbuf) + continue; + + GetFileVersionInfo(szFileName, NULL, versize, verbuf); + + char *mimetypes = NULL; + UINT len = 0; + + if(!VerQueryValue(verbuf, "\\StringFileInfo\\040904E4\\MIMEType", (void **)&mimetypes, &len) + || !mimetypes || !len) + { + delete [] verbuf; + continue; + } + + // browse through a string of mimetypes + mimetypes[len] = '\0'; + char * type = mimetypes; + + BOOL more = TRUE; + while(more) + { + char * p = strchr(type, '|'); + if(p) + *p = '\0'; + else + more = FALSE; + + if(0 == stricmp(mimetype, type)) + { + // this is it! + delete [] verbuf; + FindClose(handle); + HINSTANCE hLib = LoadLibrary(szFileName); + return hLib; + } + + type = p; + type++; + } + + delete [] verbuf; + } + + } while(FindNextFile(handle, &ffdataStruct)); + + FindClose(handle); + +#endif + +#ifdef XP_UNIX + // Implement UNIX version +#endif + +#ifdef XP_MAC + // Implement Mac version +#endif + + return NULL; +} + +void UnloadRealPlugin(XP_HLIB hLib) +{ +#ifdef XP_WIN + if(!hLib) + FreeLibrary(hLib); +#endif + +#ifdef XP_UNIX + // Implement UNIX version +#endif + +#ifdef XP_MAC + // Implement Mac version +#endif +} diff --git a/mozilla/modules/plugin/npspy/common/profile.cpp b/mozilla/modules/plugin/npspy/common/profile.cpp new file mode 100644 index 00000000000..19cf4161d1f --- /dev/null +++ b/mozilla/modules/plugin/npspy/common/profile.cpp @@ -0,0 +1,34 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + * + */ + +#include "xp.h" + +#include "profile.h" + +Profile::Profile() +{ +} + +Profile::~Profile() +{ +} diff --git a/mozilla/modules/plugin/tools/spy/common/epmanager.cpp b/mozilla/modules/plugin/tools/spy/common/epmanager.cpp new file mode 100644 index 00000000000..5902e4512fd --- /dev/null +++ b/mozilla/modules/plugin/tools/spy/common/epmanager.cpp @@ -0,0 +1,364 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + * + */ + +#include "xp.h" + +#include "epmanager.h" +#include "logger.h" + +extern Logger * logger; + +InstanceList::InstanceList(NPP _instance) : + next(NULL), + instance(_instance) +{ +} + +InstanceList::~InstanceList() +{ +} + +PluginEntryPointList::PluginEntryPointList() : + next(NULL), + instances(NULL) +{ + mimetype[0] = '\0'; + memset((void *)&realNPPFuncs, 0, sizeof(realNPPFuncs)); + realShutdown = NULL; + hLib = NULL; +} + +PluginEntryPointList::~PluginEntryPointList() +{ +} + +NPPEntryPointManager::NPPEntryPointManager() : + mEntryPoints(NULL) +{ +} + +NPPEntryPointManager::~NPPEntryPointManager() +{ + for(PluginEntryPointList * eps = mEntryPoints; eps != NULL;) + { + for(InstanceList * instances = eps->instances; instances != NULL;) + { + InstanceList * next = instances->next; + delete instances; + instances = next; + } + + PluginEntryPointList * next = eps->next; + delete eps; + eps = next; + } +} + +void NPPEntryPointManager::createEntryPointsForPlugin(char * mimetype, NPPluginFuncs * funcs, NP_SHUTDOWN shutdownproc, XP_HLIB hLib) +{ + PluginEntryPointList * eps = new PluginEntryPointList(); + + if(eps == NULL) + return; + + strcpy(eps->mimetype, mimetype); + + if(funcs) + { + eps->realNPPFuncs.size = funcs->size; + eps->realNPPFuncs.version = funcs->version; + eps->realNPPFuncs.newp = funcs->newp; + eps->realNPPFuncs.destroy = funcs->destroy; + eps->realNPPFuncs.setwindow = funcs->setwindow; + eps->realNPPFuncs.newstream = funcs->newstream; + eps->realNPPFuncs.destroystream = funcs->destroystream; + eps->realNPPFuncs.asfile = funcs->asfile; + eps->realNPPFuncs.writeready = funcs->writeready; + eps->realNPPFuncs.write = funcs->write; + eps->realNPPFuncs.print = funcs->print; + eps->realNPPFuncs.event = funcs->event; + eps->realNPPFuncs.urlnotify = funcs->urlnotify; + eps->realNPPFuncs.javaClass = funcs->javaClass; + eps->realNPPFuncs.getvalue = funcs->getvalue; + eps->realNPPFuncs.setvalue = funcs->setvalue; + } + + eps->realShutdown = shutdownproc; + eps->hLib = hLib; + + eps->next = mEntryPoints; + mEntryPoints = eps; +} + +void NPPEntryPointManager::removeEntryPointsForPlugin(NPP instance, XP_HLIB * lib) +{ + NPPluginFuncs * eptoremove = findEntryPointsForInstance(instance); + + PluginEntryPointList * prev = NULL; + + for(PluginEntryPointList * eps = mEntryPoints; eps != NULL; eps = eps->next) + { + if(&eps->realNPPFuncs == eptoremove) + { + if(prev) + prev->next = eps->next; + else + mEntryPoints = eps->next; + + *lib = eps->hLib; + delete eps; + return; + } + + prev = eps; + } +} + +NPPluginFuncs * NPPEntryPointManager::findEntryPointsForPlugin(char * mimetype) +{ + for(PluginEntryPointList * eps = mEntryPoints; eps != NULL; eps = eps->next) + { + if(0 == stricmp(eps->mimetype, mimetype)) + return &eps->realNPPFuncs; + } + + return NULL; +} + +NPPluginFuncs * NPPEntryPointManager::findEntryPointsForInstance(NPP instance) +{ + for(PluginEntryPointList * eps = mEntryPoints; eps != NULL; eps = eps->next) + { + for(InstanceList * instances = eps->instances; instances != NULL; instances = instances->next) + { + if(instances->instance == instance) + return &eps->realNPPFuncs; + } + } + + return NULL; +} + +void NPPEntryPointManager::callNP_ShutdownAll() +{ + for(PluginEntryPointList * eps = mEntryPoints; eps != NULL; eps = eps->next) + { + if(eps->realShutdown) + { + logger->logSPY_NP_Shutdown(eps->mimetype); + eps->realShutdown(); + eps->realShutdown = NULL; // don't want to call it more than once + } + } +} + +void NPPEntryPointManager::callNP_Shutdown(NPP instance) +{ + for(PluginEntryPointList * eps = mEntryPoints; eps != NULL; eps = eps->next) + { + for(InstanceList * instances = eps->instances; instances != NULL; instances = instances->next) + { + if(instances->instance == instance) + { + if(eps->realShutdown) + { + logger->logSPY_NP_Shutdown(eps->mimetype); + eps->realShutdown(); + eps->realShutdown = NULL; // don't want to call it more than once + } + } + } + } +} + +NPError NPPEntryPointManager::callNPP_New(NPMIMEType pluginType, NPP instance, uint16 mode, int16 argc, char* argn[], char* argv[], NPSavedData* saved) +{ + NPPluginFuncs * nppfuncs = NULL; + + for(PluginEntryPointList * eps = mEntryPoints; eps != NULL; eps = eps->next) + { + if(0 == stricmp(eps->mimetype, pluginType)) + { + nppfuncs = &eps->realNPPFuncs; + + // now we should associate this plugin instance with plugin entry points + // so that later we could find entry points by instance rather than by mimetype + InstanceList * inst = new InstanceList(instance); + inst->next = eps->instances; + eps->instances = inst; + + break; + } + } + + if(!nppfuncs || !nppfuncs->newp) + return NPERR_GENERIC_ERROR; + + NPError rv = CallNPP_NewProc(nppfuncs->newp, pluginType, instance, mode, argc, argn, argv, saved); + + return rv; +} + +NPError NPPEntryPointManager::callNPP_Destroy(NPP instance, NPSavedData** save, BOOL * last) +{ + NPPluginFuncs * nppfuncs = NULL; + + BOOL done = FALSE; + + for(PluginEntryPointList * eps = mEntryPoints; eps != NULL; eps = eps->next) + { + InstanceList * prev = NULL; + for(InstanceList * instances = eps->instances; instances != NULL; instances = instances->next) + { + if(instances->instance == instance) + { + nppfuncs = &eps->realNPPFuncs; + done = TRUE; + + // check if this is the last one + if(eps->instances->next == NULL) + *last = TRUE; + else + { + // deassociate instance if this is not the last one + // last instance will be needed to find corresponding shutdown proc + if(prev) + prev->next = instances->next; + else + eps->instances = instances->next; + + delete instances; + } + + break; + } + prev = instances; + } + if(done) + break; + } + + if(!nppfuncs || !nppfuncs->destroy) + return NPERR_GENERIC_ERROR; + + return CallNPP_DestroyProc(nppfuncs->destroy, instance, save); +} + +NPError NPPEntryPointManager::callNPP_SetWindow(NPP instance, NPWindow* window) +{ + NPPluginFuncs * nppfuncs = findEntryPointsForInstance(instance); + if(!nppfuncs || !nppfuncs->setwindow) + return NPERR_GENERIC_ERROR; + + return CallNPP_SetWindowProc(nppfuncs->setwindow, instance, window); +} + +NPError NPPEntryPointManager::callNPP_NewStream(NPP instance, NPMIMEType type, NPStream* stream, NPBool seekable, uint16* stype) +{ + NPPluginFuncs * nppfuncs = findEntryPointsForInstance(instance); + if(!nppfuncs || !nppfuncs->newstream) + return NPERR_GENERIC_ERROR; + + return CallNPP_NewStreamProc(nppfuncs->newstream, instance, type, stream, seekable, stype); +} + +NPError NPPEntryPointManager::callNPP_DestroyStream(NPP instance, NPStream* stream, NPReason reason) +{ + NPPluginFuncs * nppfuncs = findEntryPointsForInstance(instance); + if(!nppfuncs || !nppfuncs->destroystream) + return NPERR_GENERIC_ERROR; + + return CallNPP_DestroyStreamProc(nppfuncs->destroystream, instance, stream, reason); +} + +int32 NPPEntryPointManager::callNPP_WriteReady(NPP instance, NPStream* stream) +{ + NPPluginFuncs * nppfuncs = findEntryPointsForInstance(instance); + if(!nppfuncs || !nppfuncs->writeready) + return NPERR_GENERIC_ERROR; + + return CallNPP_WriteReadyProc(nppfuncs->writeready, instance, stream); +} + +int32 NPPEntryPointManager::callNPP_Write(NPP instance, NPStream* stream, int32 offset, int32 len, void* buffer) +{ + NPPluginFuncs * nppfuncs = findEntryPointsForInstance(instance); + if(!nppfuncs || !nppfuncs->write) + return NPERR_GENERIC_ERROR; + + return CallNPP_WriteProc(nppfuncs->write, instance, stream, offset, len, buffer); +} + +void NPPEntryPointManager::callNPP_StreamAsFile(NPP instance, NPStream* stream, const char* fname) +{ + NPPluginFuncs * nppfuncs = findEntryPointsForInstance(instance); + if(!nppfuncs || !nppfuncs->asfile) + return; + + CallNPP_StreamAsFileProc(nppfuncs->asfile, instance, stream, fname); +} + +void NPPEntryPointManager::callNPP_Print(NPP instance, NPPrint* platformPrint) +{ + NPPluginFuncs * nppfuncs = findEntryPointsForInstance(instance); + if(!nppfuncs || !nppfuncs->print) + return; + + CallNPP_PrintProc(nppfuncs->print, instance, platformPrint); +} + +void NPPEntryPointManager::callNPP_URLNotify(NPP instance, const char* url, NPReason reason, void* notifyData) +{ + NPPluginFuncs * nppfuncs = findEntryPointsForInstance(instance); + if(!nppfuncs || !nppfuncs->urlnotify) + return; + + CallNPP_URLNotifyProc(nppfuncs->urlnotify, instance, url, reason, notifyData); +} + +NPError NPPEntryPointManager::callNPP_GetValue(NPP instance, NPPVariable variable, void *value) +{ + NPPluginFuncs * nppfuncs = findEntryPointsForInstance(instance); + if(!nppfuncs || !nppfuncs->getvalue) + return NPERR_GENERIC_ERROR; + + return CallNPP_GetValueProc(nppfuncs->getvalue, instance, variable, value); +} + +NPError NPPEntryPointManager::callNPP_SetValue(NPP instance, NPNVariable variable, void *value) +{ + NPPluginFuncs * nppfuncs = findEntryPointsForInstance(instance); + if(!nppfuncs || !nppfuncs->setvalue) + return NPERR_GENERIC_ERROR; + + return CallNPP_SetValueProc(nppfuncs->setvalue, instance, variable, value); +} + +int16 NPPEntryPointManager::callNPP_HandleEvent(NPP instance, void* event) +{ + NPPluginFuncs * nppfuncs = findEntryPointsForInstance(instance); + if(!nppfuncs || !nppfuncs->event) + return NPERR_GENERIC_ERROR; + + return CallNPP_HandleEventProc(nppfuncs->event, instance, event); +} diff --git a/mozilla/modules/plugin/tools/spy/common/fileutils.cpp b/mozilla/modules/plugin/tools/spy/common/fileutils.cpp new file mode 100644 index 00000000000..3062308d8fa --- /dev/null +++ b/mozilla/modules/plugin/tools/spy/common/fileutils.cpp @@ -0,0 +1,102 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + * + */ + +#include "xp.h" + +BOOL XP_IsFile(char * szFileName) +{ +#ifdef XP_WIN + OFSTRUCT of; + return (HFILE_ERROR != OpenFile(szFileName, &of, OF_EXIST)); +#endif +#ifdef XP_UNIX + struct stat s; + return (stat(szFileName, &s) != -1); +#endif +#ifdef XP_MAC /* HACK */ + return 1; +#endif +} + +void XP_DeleteFile(char * szFileName) +{ +#ifdef XP_WIN + DeleteFile(szFileName); +#else + remove(szFileName); +#endif +} + +XP_HFILE XP_CreateFile(char * szFileName) +{ +#ifdef XP_WIN + OFSTRUCT of; + HFILE hFile = OpenFile(szFileName, &of, OF_CREATE | OF_WRITE); + return (hFile != HFILE_ERROR) ? hFile : NULL; +#else + return (XP_HFILE)fopen(szFileName, "w+"); +#endif +} + +XP_HFILE XP_OpenFile(char * szFileName) +{ +#ifdef XP_WIN + OFSTRUCT of; + HFILE hFile = OpenFile(szFileName, &of, OF_READ | OF_WRITE); + return (hFile != HFILE_ERROR) ? hFile : NULL; +#else + return (XP_HFILE)fopen(szFileName, "r+"); +#endif +} + +void XP_CloseFile(XP_HFILE hFile) +{ + if(hFile != NULL) + { +#ifdef XP_WIN + CloseHandle((HANDLE)hFile); +#else + fclose(hFile); +#endif + } +} + +DWORD XP_WriteFile(XP_HFILE hFile, void * pBuf, int iSize) +{ +#ifdef XP_WIN + DWORD dwRet; + WriteFile((HANDLE)hFile, pBuf, iSize, &dwRet, NULL); + return dwRet; +#else + return (DWORD)fwrite(pBuf, iSize, 1, hFile); +#endif +} + +void XP_FlushFileBuffers(XP_HFILE hFile) +{ +#ifdef XP_WIN + FlushFileBuffers((HANDLE)hFile); +#else + fflush(hFile); +#endif +} diff --git a/mozilla/modules/plugin/tools/spy/common/format.cpp b/mozilla/modules/plugin/tools/spy/common/format.cpp new file mode 100644 index 00000000000..b4c94a19dee --- /dev/null +++ b/mozilla/modules/plugin/tools/spy/common/format.cpp @@ -0,0 +1,880 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + * + */ + +#include "xp.h" + +#include "format.h" +#include "logger.h" + +extern Logger * logger; + +char * FormatNPAPIError(int iError) +{ + static char szError[64]; + switch (iError) + { + case NPERR_NO_ERROR: + sprintf(szError, "NPERR_NO_ERROR"); + break; + case NPERR_GENERIC_ERROR: + sprintf(szError, "NPERR_GENERIC_ERROR"); + break; + case NPERR_INVALID_INSTANCE_ERROR: + sprintf(szError, "NPERR_INVALID_INSTANCE_ERROR"); + break; + case NPERR_INVALID_FUNCTABLE_ERROR: + sprintf(szError, "NPERR_INVALID_FUNCTABLE_ERROR"); + break; + case NPERR_MODULE_LOAD_FAILED_ERROR: + sprintf(szError, "NPERR_MODULE_LOAD_FAILED_ERROR"); + break; + case NPERR_OUT_OF_MEMORY_ERROR: + sprintf(szError, "NPERR_OUT_OF_MEMORY_ERROR"); + break; + case NPERR_INVALID_PLUGIN_ERROR: + sprintf(szError, "NPERR_INVALID_PLUGIN_ERROR"); + break; + case NPERR_INVALID_PLUGIN_DIR_ERROR: + sprintf(szError, "NPERR_INVALID_PLUGIN_DIR_ERROR"); + break; + case NPERR_INCOMPATIBLE_VERSION_ERROR: + sprintf(szError, "NPERR_INCOMPATIBLE_VERSION_ERROR"); + break; + case NPERR_INVALID_PARAM: + sprintf(szError, "NPERR_INVALID_PARAM"); + break; + case NPERR_INVALID_URL: + sprintf(szError, "NPERR_INVALID_URL"); + break; + case NPERR_FILE_NOT_FOUND: + sprintf(szError, "NPERR_FILE_NOT_FOUND"); + break; + case NPERR_NO_DATA: + sprintf(szError, "NPERR_NO_DATA"); + break; + case NPERR_STREAM_NOT_SEEKABLE: + sprintf(szError, "NPERR_STREAM_NOT_SEEKABLE"); + break; + default: + sprintf(szError, "Unlisted error"); + break; + } + return &szError[0]; +} + +char * FormatNPAPIReason(int iReason) +{ + static char szReason[64]; + switch (iReason) + { + case NPRES_DONE: + sprintf(szReason, "NPRES_DONE"); + break; + case NPRES_NETWORK_ERR: + sprintf(szReason, "NPRES_NETWORK_ERR"); + break; + case NPRES_USER_BREAK: + sprintf(szReason, "NPRES_USER_BREAK"); + break; + default: + sprintf(szReason, "Unlisted reason"); + break; + } + return &szReason[0]; +} + +char * FormatNPNVariable(NPNVariable var) +{ + static char szVar[80]; + switch (var) + { + case NPNVxDisplay: + sprintf(szVar, "%i -- NPNVxDisplay", var); + break; + case NPNVxtAppContext: + sprintf(szVar, "%i -- NPNVxtAppContext", var); + break; + case NPNVnetscapeWindow: + sprintf(szVar, "%i -- NPNVnetscapeWindow", var); + break; + case NPNVjavascriptEnabledBool: + sprintf(szVar, "%i -- NPNVjavascriptEnabledBool", var); + break; + case NPNVasdEnabledBool: + sprintf(szVar, "%i -- NPNVasdEnabledBool", var); + break; + case NPNVisOfflineBool: + sprintf(szVar, "%i -- NPNVisOfflineBool", var); + break; + default: + sprintf(szVar, "%i -- Unlisted variable", var); + break; + } + return &szVar[0]; +} + +char * FormatNPPVariable(NPPVariable var) +{ + static char szVar[80]; + switch (var) + { + case NPPVpluginNameString: + sprintf(szVar, "%i -- NPPVpluginNameString", var); + break; + case NPPVpluginDescriptionString: + sprintf(szVar, "%i -- NPPVpluginDescriptionString?", var); + break; + case NPPVpluginWindowBool: + sprintf(szVar, "%i -- NPPVpluginWindowBool?", var); + break; + case NPPVpluginTransparentBool: + sprintf(szVar, "%i -- NPPVpluginTransparentBool?", var); + break; + case NPPVjavaClass: + sprintf(szVar, "%i -- NPPVjavaClass?", var); + break; + case NPPVpluginWindowSize: + sprintf(szVar, "%i -- NPPVpluginWindowSize?", var); + break; + case NPPVpluginTimerInterval: + sprintf(szVar, "%i -- NPPVpluginTimerInterval?", var); + break; + case NPPVpluginScriptableInstance: + sprintf(szVar, "%i -- NPPVpluginScriptableInstance?", var); + break; + case NPPVpluginScriptableIID: + sprintf(szVar, "%i -- NPPVpluginScriptableIID?", var); + break; + default: + sprintf(szVar, "%i -- Unlisted variable?", var); + break; + } + return &szVar[0]; +} + +BOOL FormatPCHARArgument(char * szBuf, int iLength, LogArgumentStruct * parg) +{ + if(iLength <= parg->iLength) + return FALSE; + + if(parg->pData == NULL) + sprintf(szBuf, "%#08lx", parg->dwArg); + else + sprintf(szBuf, "%#08lx(\"%s\")", parg->dwArg, (char *)parg->pData); + return TRUE; +} + +BOOL FormatBOOLArgument(char * szBuf, int iLength, LogArgumentStruct * parg) +{ + if(iLength <= 8) + return FALSE; + + sprintf(szBuf, "%s", ((NPBool)parg->dwArg == TRUE) ? "TRUE" : "FALSE"); + return TRUE; +} + +BOOL FormatPBOOLArgument(char * szBuf, int iLength, LogArgumentStruct * parg) +{ + if(iLength <= 8) + return FALSE; + + sprintf(szBuf, "%#08lx(%s)", parg->dwArg, (*((NPBool *)parg->pData) == TRUE) ? "TRUE" : "FALSE"); + return TRUE; +} + +static void makeAbbreviatedString(char * szBuf, int iSize, DWORD dwArg, int iLength, int iWrap) +{ + if(dwArg == 0L) + { + szBuf[0] = '\0'; + return; + } + + if(iLength > iWrap) + { + int iRealWrap = (iSize > iWrap) ? iWrap : (iSize - 4); + memcpy((LPVOID)&szBuf[0], (LPVOID)dwArg, iRealWrap); + szBuf[iRealWrap] = '.'; + szBuf[iRealWrap + 1] = '.'; + szBuf[iRealWrap + 2] = '.'; + szBuf[iRealWrap + 3] = '\0'; + } + else + { + if(iLength >= iSize) + { + memcpy((LPVOID)&szBuf[0], (LPVOID)dwArg, iSize - 4); + szBuf[iSize] = '.'; + szBuf[iSize + 1] = '.'; + szBuf[iSize + 2] = '.'; + szBuf[iSize + 3] = '\0'; + } + else + { + memcpy((LPVOID)&szBuf[0], (LPVOID)dwArg, iLength); + szBuf[iLength] = '\0'; + } + } +} + +LogItemStruct * makeLogItemStruct(NPAPI_Action action, + DWORD dw1, DWORD dw2, DWORD dw3, DWORD dw4, + DWORD dw5, DWORD dw6, DWORD dw7, BOOL bShort) +{ + int iWrap = 10; + + LogItemStruct * plis = new LogItemStruct; + if(plis == NULL) + return NULL; + + plis->action = action; + plis->arg1.dwArg = dw1; + plis->arg2.dwArg = dw2; + plis->arg3.dwArg = dw3; + plis->arg4.dwArg = dw4; + plis->arg5.dwArg = dw5; + plis->arg6.dwArg = dw6; + plis->arg7.dwArg = dw7; + + char szTarget[1024] = {'\0'}; + char szBuf[1024] = {'\0'}; + + if(bShort) + return plis; + + switch (action) + { + case action_invalid: + break; + + // NPN action + case action_npn_version: + plis->arg1.pData = new int[1]; + *(int*)(plis->arg1.pData) = *((int*)dw1); + plis->arg1.iLength = sizeof(int); + + plis->arg2.pData = new int[1]; + *(int*)(plis->arg2.pData) = *((int*)dw2); + plis->arg2.iLength = sizeof(int); + + plis->arg3.pData = new int[1]; + *(int*)(plis->arg3.pData) = *((int*)dw3); + plis->arg3.iLength = sizeof(int); + + plis->arg4.pData = new int[1]; + *(int*)(plis->arg4.pData) = *((int*)dw4); + plis->arg4.iLength = sizeof(int); + + break; + case action_npn_get_url_notify: + if(dw2 != 0L) + { + plis->arg2.iLength = strlen((char *)dw2) + 1; + plis->arg2.pData = new char[plis->arg2.iLength]; + memcpy(plis->arg2.pData, (LPVOID)dw2, plis->arg2.iLength); + } + + if(dw3 != 0L) + { + makeAbbreviatedString(szTarget, sizeof(szTarget), dw3, strlen((char *)dw3), iWrap); + plis->arg3.iLength = strlen(szTarget) + 1; + plis->arg3.pData = new char[plis->arg3.iLength]; + memcpy(plis->arg3.pData, (LPVOID)&szTarget[0], plis->arg3.iLength); + } + break; + case action_npn_get_url: + { + if(dw2 != 0L) + { + plis->arg2.iLength = strlen((char *)dw2) + 1; + plis->arg2.pData = new char[plis->arg2.iLength]; + memcpy(plis->arg2.pData, (LPVOID)dw2, plis->arg2.iLength); + } + + if(dw3 != 0L) + { + makeAbbreviatedString(szTarget, sizeof(szTarget), dw3, strlen((char *)dw3), iWrap); + plis->arg3.iLength = strlen(szTarget) + 1; + plis->arg3.pData = new char[plis->arg3.iLength]; + memcpy(plis->arg3.pData, (LPVOID)&szTarget[0], plis->arg3.iLength); + } + break; + } + case action_npn_post_url_notify: + { + if(dw2 != 0L) + { + plis->arg2.iLength = strlen((char *)dw2) + 1; + plis->arg2.pData = new char[plis->arg2.iLength]; + memcpy(plis->arg2.pData, (LPVOID)dw2, plis->arg2.iLength); + } + + if(dw3 != 0L) + { + makeAbbreviatedString(szTarget, sizeof(szTarget), dw3, strlen((char *)dw3), iWrap); + plis->arg3.iLength = strlen(szTarget) + 1; + plis->arg3.pData = new char[plis->arg3.iLength]; + memcpy(plis->arg3.pData, (LPVOID)&szTarget[0], plis->arg3.iLength); + } + + makeAbbreviatedString(szBuf, sizeof(szBuf), dw5, strlen((char *)dw5), iWrap); + plis->arg5.iLength = (int)dw4 + 1; + plis->arg5.pData = new char[plis->arg5.iLength]; + memcpy(plis->arg5.pData, (LPVOID)&szBuf[0], plis->arg5.iLength); + + break; + } + case action_npn_post_url: + { + if(dw2 != 0L) + { + plis->arg2.iLength = strlen((char *)dw2) + 1; + plis->arg2.pData = new char[plis->arg2.iLength]; + memcpy(plis->arg2.pData, (LPVOID)dw2, plis->arg2.iLength); + } + + if(dw3 != 0L) + { + makeAbbreviatedString(szTarget, sizeof(szTarget), dw3, strlen((char *)dw3), iWrap); + plis->arg3.iLength = strlen(szTarget) + 1; + plis->arg3.pData = new char[plis->arg3.iLength]; + memcpy(plis->arg3.pData, (LPVOID)&szTarget[0], plis->arg3.iLength); + } + + makeAbbreviatedString(szBuf, sizeof(szBuf), dw5, strlen((char *)dw5), iWrap); + plis->arg5.iLength = (int)dw4 + 1; + plis->arg5.pData = new char[plis->arg5.iLength]; + memcpy(plis->arg5.pData, (LPVOID)&szBuf[0], plis->arg5.iLength); + + break; + } + case action_npn_new_stream: + { + if(dw2 != 0L) + { + plis->arg2.iLength = strlen((char *)dw2) + 1; + plis->arg2.pData = new char[plis->arg2.iLength]; + memcpy(plis->arg2.pData, (LPVOID)dw2, plis->arg2.iLength); + } + + makeAbbreviatedString(szTarget, sizeof(szTarget), dw3, strlen((char *)dw3), iWrap); + plis->arg3.iLength = strlen(szTarget) + 1; + plis->arg3.pData = new char[plis->arg3.iLength]; + memcpy(plis->arg3.pData, (LPVOID)&szTarget[0], plis->arg3.iLength); + + plis->arg4.pData = new char[sizeof(DWORD)]; + plis->arg4.iLength = sizeof(DWORD); + memcpy(plis->arg4.pData, (LPVOID)dw4, plis->arg4.iLength); + + break; + } + case action_npn_destroy_stream: + break; + case action_npn_request_read: + break; + case action_npn_write: + { + makeAbbreviatedString(szBuf, sizeof(szBuf), dw4, strlen((char *)dw4), iWrap); + plis->arg4.iLength = strlen(szBuf) + 1; + plis->arg4.pData = new char[plis->arg4.iLength]; + memcpy(plis->arg4.pData, (LPVOID)&szBuf[0], plis->arg4.iLength); + break; + } + case action_npn_status: + if(dw2 != 0L) + { + plis->arg2.iLength = strlen((char *)dw2) + 1; + plis->arg2.pData = new char[plis->arg2.iLength]; + memcpy(plis->arg2.pData, (LPVOID)dw2, plis->arg2.iLength); + } + break; + case action_npn_user_agent: + break; + case action_npn_mem_alloc: + break; + case action_npn_mem_free: + break; + case action_npn_mem_flush: + break; + case action_npn_reload_plugins: + break; + case action_npn_get_java_env: + break; + case action_npn_get_java_peer: + break; + case action_npn_get_value: + plis->arg3.iLength = sizeof(DWORD); + plis->arg3.pData = new char[plis->arg3.iLength]; + memcpy(plis->arg3.pData, (LPVOID)dw3, plis->arg3.iLength); + break; + case action_npn_set_value: + if(((NPPVariable)dw2 == NPPVpluginNameString) || ((NPPVariable)dw2 == NPPVpluginDescriptionString)) + { + makeAbbreviatedString(szBuf, sizeof(szBuf), dw3, strlen((char *)dw3), iWrap); + plis->arg3.iLength = strlen(szBuf) + 1; + plis->arg3.pData = new char[plis->arg3.iLength]; + memcpy(plis->arg3.pData, (LPVOID)&szBuf[0], plis->arg3.iLength); + } + else if(((NPPVariable)dw2 == NPPVpluginWindowBool) || ((NPPVariable)dw2 == NPPVpluginTransparentBool)) + { + plis->arg3.iLength = sizeof(NPBool); + plis->arg3.pData = new char[plis->arg3.iLength]; + memcpy(plis->arg3.pData, (LPVOID)dw3, plis->arg3.iLength); + } + else if((NPPVariable)dw2 == NPPVpluginWindowSize) + { + plis->arg3.iLength = sizeof(NPSize); + plis->arg3.pData = new char[plis->arg3.iLength]; + memcpy(plis->arg3.pData, (LPVOID)dw3, plis->arg3.iLength); + } + break; + case action_npn_invalidate_rect: + { + plis->arg2.iLength = sizeof(NPRect); + plis->arg2.pData = new char[plis->arg2.iLength]; + memcpy(plis->arg2.pData, (LPVOID)dw2, plis->arg2.iLength); + break; + } + case action_npn_invalidate_region: + break; + case action_npn_force_redraw: + break; + + // NPP action + case action_npp_new: + plis->arg1.iLength = strlen((char *)dw1) + 1; + plis->arg1.pData = new char[plis->arg1.iLength]; + memcpy(plis->arg1.pData, (LPVOID)dw1, plis->arg1.iLength); + break; + case action_npp_destroy: + plis->arg2.iLength = sizeof(DWORD); + plis->arg2.pData = new char[plis->arg2.iLength]; + memcpy(plis->arg2.pData, (LPVOID)dw2, plis->arg2.iLength); + break; + case action_npp_set_window: + plis->arg2.iLength = sizeof(NPWindow); + plis->arg2.pData = new char[plis->arg2.iLength]; + memcpy(plis->arg2.pData, (LPVOID)dw2, plis->arg2.iLength); + break; + case action_npp_new_stream: + plis->arg2.iLength = strlen((char *)dw2) + 1; + plis->arg2.pData = new char[plis->arg2.iLength]; + memcpy(plis->arg2.pData, (LPVOID)dw2, plis->arg2.iLength); + + plis->arg5.iLength = sizeof(uint16); + plis->arg5.pData = new char[plis->arg5.iLength]; + memcpy(plis->arg5.pData, (LPVOID)dw5, plis->arg5.iLength); + break; + case action_npp_destroy_stream: + break; + case action_npp_stream_as_file: + plis->arg3.iLength = strlen((char *)dw3) + 1; + plis->arg3.pData = new char[plis->arg3.iLength]; + memcpy(plis->arg3.pData, (LPVOID)dw3, plis->arg3.iLength); + break; + case action_npp_write_ready: + break; + case action_npp_write: + { + if(dw5 != 0L) + { + makeAbbreviatedString(szBuf, sizeof(szBuf), dw5, strlen((char *)dw5), iWrap); + plis->arg5.iLength = strlen(szBuf) + 1; + plis->arg5.pData = new char[plis->arg5.iLength]; + memcpy(plis->arg5.pData, (LPVOID)&szBuf[0], plis->arg5.iLength); + } + break; + } + case action_npp_print: + break; + case action_npp_handle_event: + break; + case action_npp_url_notify: + plis->arg2.iLength = strlen((char *)dw2) + 1; + plis->arg2.pData = new char[plis->arg2.iLength]; + memcpy(plis->arg2.pData, (LPVOID)dw2, plis->arg2.iLength); + break; + case action_npp_get_java_class: + break; + case action_npp_get_value: + break; + case action_npp_set_value: + break; + + default: + break; + } + + return plis; +} + +void freeLogItemStruct(LogItemStruct * lis) +{ + if(lis) + delete lis; +} + +int formatLogItem(LogItemStruct * plis, char * szOutput, BOOL bDOSStyle) +{ + int iRet = 0; + static char szString[1024]; + static char szEOL[8]; + static char szEOI[256]; + static char szEndOfItem[] = ""; + + if(bDOSStyle) + { + strcpy(szEOL, "\r\n"); + //strcpy(szEOI, szEndOfItem); + //strcat(szEOI, "\r\n"); + } + else + { + strcpy(szEOL, "\n"); + //strcpy(szEOI, szEndOfItem); + //strcat(szEOI, "\n"); + } + + szOutput[0] = '\0'; + + DWORD dw1 = plis->arg1.dwArg; + DWORD dw2 = plis->arg2.dwArg; + DWORD dw3 = plis->arg3.dwArg; + DWORD dw4 = plis->arg4.dwArg; + DWORD dw5 = plis->arg5.dwArg; + DWORD dw6 = plis->arg6.dwArg; + DWORD dw7 = plis->arg7.dwArg; + + char sz1[1024] = {'\0'}; + char sz2[1024] = {'\0'}; + char sz3[1024] = {'\0'}; + char sz4[1024] = {'\0'}; + char sz5[1024] = {'\0'}; + char sz6[1024] = {'\0'}; + + switch (plis->action) + { + case action_invalid: + break; + + // NPN action + case action_npn_version: + if((plis->arg1.pData != NULL)&&(plis->arg2.pData != NULL)&&(plis->arg3.pData != NULL)&&(plis->arg4.pData != NULL)) + sprintf(szString, "NPN_Version(%#08lx, %#08lx, %#08lx, %#08lx)%s", dw1,dw2,dw3,dw4,szEOL); + else + sprintf(szString, "NPN_Version(%#08lx, %#08lx, %#08lx, %#08lx)%s", dw1,dw2,dw3,dw4,szEOL); + break; + case action_npn_get_url_notify: + { + FormatPCHARArgument(sz2, sizeof(sz2), &plis->arg2); + FormatPCHARArgument(sz3, sizeof(sz3), &plis->arg3); + sprintf(szString, "NPN_GetURLNotify(%#08lx, %s, %s, %#08lx)%s", dw1,sz2,sz3,dw4,szEOL); + break; + } + case action_npn_get_url: + { + FormatPCHARArgument(sz2, sizeof(sz2), &plis->arg2); + FormatPCHARArgument(sz3, sizeof(sz3), &plis->arg3); + sprintf(szString, "NPN_GetURL(%#08lx, %s, %s)%s", dw1,sz2,sz3,szEOL); + break; + } + case action_npn_post_url_notify: + { + FormatPCHARArgument(sz2, sizeof(sz2), &plis->arg2); + FormatPCHARArgument(sz3, sizeof(sz3), &plis->arg3); + FormatPCHARArgument(sz5, sizeof(sz5), &plis->arg5); + FormatBOOLArgument(sz6, sizeof(sz6), &plis->arg6); + + sprintf(szString, "NPN_PostURLNotify(%#08lx, %s, %s, %li, %s, %s, %#08lx)%s", + dw1,sz2,sz3,(uint32)dw4,sz5,sz6,dw7,szEOL); + break; + } + case action_npn_post_url: + { + FormatPCHARArgument(sz2, sizeof(sz2), &plis->arg2); + FormatPCHARArgument(sz3, sizeof(sz3), &plis->arg3); + FormatPCHARArgument(sz5, sizeof(sz5), &plis->arg5); + FormatBOOLArgument(sz6, sizeof(sz6), &plis->arg6); + + sprintf(szString, "NPN_PostURL(%#08lx, %s, %s, %li, %s, %s)%s", + dw1,sz2,sz3,(uint32)dw4,sz5,sz6,szEOL); + break; + } + case action_npn_new_stream: + { + FormatPCHARArgument(sz2, sizeof(sz2), &plis->arg2); + FormatPCHARArgument(sz3, sizeof(sz3), &plis->arg3); + if(plis->arg4.pData != NULL) + sprintf(szString, "NPN_NewStream(%#08lx, %s, %s, %#08lx(%#08lx))%s", + dw1, sz2,sz3,dw4,*(DWORD *)plis->arg4.pData,szEOL); + else + sprintf(szString, "NPN_NewStream(%#08lx, \"%s\", \"%s\", %#08lx)%s", dw1, sz2,sz3,dw4,szEOL); + break; + } + case action_npn_destroy_stream: + sprintf(szString, "NPN_DestroyStream(%#08lx, %#08lx, %s)%s", dw1,dw2,FormatNPAPIReason((int)dw3),szEOL); + break; + case action_npn_request_read: + sprintf(szString, "NPN_RequestRead(%#08lx, %#08lx)%s", dw1, dw2, szEOL); + break; + case action_npn_write: + { + FormatPCHARArgument(sz4, sizeof(sz4), &plis->arg4); + sprintf(szString, "NPN_Write(%#08lx, %#08lx, %li, %s)%s", dw1, dw2, (int32)dw3, sz4, szEOL); + break; + } + case action_npn_status: + { + FormatPCHARArgument(sz2, sizeof(sz2), &plis->arg2); + sprintf(szString, "NPN_Status(%#08lx, %s)%s", dw1, sz2, szEOL); + break; + } + case action_npn_user_agent: + sprintf(szString, "NPN_UserAgent(%#08lx)%s", dw1, szEOL); + break; + case action_npn_mem_alloc: + sprintf(szString, "NPN_MemAlloc(%li)%s", dw1, szEOL); + break; + case action_npn_mem_free: + sprintf(szString, "NPN_MemFree(%#08lx)%s", dw1,szEOL); + break; + case action_npn_mem_flush: + sprintf(szString, "NPN_MemFlush(%li)%s", dw1, szEOL); + break; + case action_npn_reload_plugins: + { + FormatBOOLArgument(sz1, sizeof(sz1), &plis->arg1); + sprintf(szString, "NPN_ReloadPlugins(%s)%s", sz1,szEOL); + break; + } + case action_npn_get_java_env: + sprintf(szString, "NPN_GetJavaEnv()%s", szEOL); + break; + case action_npn_get_java_peer: + sprintf(szString, "NPN_GetJavaPeer(%#08lx)%s", dw1, szEOL); + break; + case action_npn_get_value: + { + switch(dw2) + { + case NPNVxDisplay: + case NPNVxtAppContext: + case NPNVnetscapeWindow: + if(dw3 != 0L) + sprintf(szString, "NPN_GetValue(%#08lx, %s, %#08lx(%#08lx))%s",dw1,FormatNPNVariable((NPNVariable)dw2),dw3,*(DWORD *)dw3,szEOL); + else + sprintf(szString, "NPN_GetValue(%#08lx, %s, %#08lx)%s",dw1,FormatNPNVariable((NPNVariable)dw2),dw3,szEOL); + break; + case NPNVjavascriptEnabledBool: + case NPNVasdEnabledBool: + case NPNVisOfflineBool: + if(dw3 != 0L) + sprintf(szString, "NPN_GetValue(%#08lx, %s, %#08lx(%s))%s", + dw1,FormatNPNVariable((NPNVariable)dw2),dw3, + (((NPBool)*(DWORD *)dw3) == TRUE) ? "TRUE" : "FALSE", szEOL); + else + sprintf(szString, "NPN_GetValue(%#08lx, %s, %#08lx)%s",dw1,FormatNPNVariable((NPNVariable)dw2),dw3,szEOL); + break; + default: + break; + } + break; + } + case action_npn_set_value: + + if(((NPPVariable)dw2 == NPPVpluginNameString) || ((NPPVariable)dw2 == NPPVpluginDescriptionString)) + { + FormatPCHARArgument(sz3, sizeof(sz3), &plis->arg3); + sprintf(szString, "NPN_SetValue(%#08lx, %s, %s)%s", dw1,FormatNPPVariable((NPPVariable)dw2),sz3,szEOL); + } + else if(((NPPVariable)dw2 == NPPVpluginWindowBool) || ((NPPVariable)dw2 == NPPVpluginTransparentBool)) + { + FormatPBOOLArgument(sz3, sizeof(sz3), &plis->arg3); + sprintf(szString, "NPN_SetValue(%#08lx, %s, %s)%s", + dw1,FormatNPPVariable((NPPVariable)dw2),sz3,szEOL); + } + else if((NPPVariable)dw2 == NPPVpluginWindowSize) + { + if(plis->arg3.pData != NULL) + { + int32 iWidth = ((NPSize *)plis->arg3.pData)->width; + int32 iHeight = ((NPSize *)plis->arg3.pData)->height; + sprintf(szString, "NPN_SetValue(%#08lx, %s, %#08lx(%li,%li))%s", + dw1,FormatNPPVariable((NPPVariable)dw2),dw3,iWidth,iHeight,szEOL); + } + else + sprintf(szString, "NPN_SetValue(%#08lx, %s, %#08lx(?,?))%s", + dw1,FormatNPPVariable((NPPVariable)dw2),dw3,szEOL); + } + else + sprintf(szString, "NPN_SetValue(%#08lx, %s, %#08lx(What is it?))%s", dw1,FormatNPPVariable((NPPVariable)dw2),dw3,szEOL); + break; + case action_npn_invalidate_rect: + { + if(plis->arg2.pData != NULL) + { + uint16 top = ((NPRect *)plis->arg2.pData)->top; + uint16 left = ((NPRect *)plis->arg2.pData)->left; + uint16 bottom = ((NPRect *)plis->arg2.pData)->bottom; + uint16 right = ((NPRect *)plis->arg2.pData)->right; + sprintf(szString, "NPN_InvalidateRect(%#08lx, %#08lx(%u,%u;%u,%u)%s", dw1,dw2,top,left,bottom,right,szEOL); + } + else + sprintf(szString, "NPN_InvalidateRect(%#08lx, %#08lx(?,?,?,?)%s", dw1,dw2,szEOL); + break; + } + case action_npn_invalidate_region: + sprintf(szString, "NPN_InvalidateRegion(%#08lx, %#08lx)%s", dw1,dw2,szEOL); + break; + case action_npn_force_redraw: + sprintf(szString, "NPN_ForceRedraw(%#08lx)%s", dw1,szEOL); + break; + + // NPP action + case action_npp_new: + { + char szMode[16]; + switch (dw3) + { + case NP_EMBED: + strcpy(szMode, "NP_EMBED"); + break; + case NP_FULL: + strcpy(szMode, "NP_FULL"); + break; + default: + strcpy(szMode, "[Invalide mode]"); + break; + } + sprintf(szString, "NPP_New(\"%s\", %#08lx, %s, %i, %#08lx, %#08lx, %#08lx)%s", + (char *)dw1,dw2,szMode,(int)dw4,dw5,dw6,dw7,szEOL); + break; + } + case action_npp_destroy: + sprintf(szString, "NPP_Destroy(%#08lx, %#08lx(%#08lx))%s", dw1, dw2, *(DWORD *)plis->arg2.pData,szEOL); + break; + case action_npp_set_window: + { + char szWindow[512]; + + if(plis->arg2.pData != NULL) + { + char szType[80]; + switch (((NPWindow*)plis->arg2.pData)->type) + { + case NPWindowTypeWindow: + sprintf(szType, "NPWindowTypeWindow"); + break; + case NPWindowTypeDrawable: + sprintf(szType, "NPWindowTypeDrawable"); + break; + default: + sprintf(szType, "[Unlisted type]"); + break; + } + sprintf(szWindow, "NPWindow: %#08lx, (%li,%li), (%li,%li), (%i,%i,%i,%i), %s", + ((NPWindow*)plis->arg2.pData)->window, + ((NPWindow*)plis->arg2.pData)->x, + ((NPWindow*)plis->arg2.pData)->y, + ((NPWindow*)plis->arg2.pData)->width, + ((NPWindow*)plis->arg2.pData)->height, + ((NPWindow*)plis->arg2.pData)->clipRect.top, + ((NPWindow*)plis->arg2.pData)->clipRect.left, + ((NPWindow*)plis->arg2.pData)->clipRect.bottom, + ((NPWindow*)plis->arg2.pData)->clipRect.right, szType); + sprintf(szString, "NPP_SetWindow(%#08lx, %#08lx)%s%s%s", dw1,dw2," ",szWindow,szEOL); + } + else + sprintf(szString, "NPP_SetWindow(%#08lx, %#08lx)%s", dw1,dw2,szEOL); + + break; + } + case action_npp_new_stream: + { + switch (*(int16 *)plis->arg5.pData) + { + case NP_NORMAL: + sprintf(sz5, "NP_NORMAL"); + break; + case NP_ASFILEONLY: + sprintf(sz5, "NP_ASFILEONLY"); + break; + case NP_ASFILE: + sprintf(sz5, "NP_ASFILE"); + break; + default: + sprintf(sz5, "[Unlisted type]"); + break; + } + FormatPCHARArgument(sz2, sizeof(sz2), &plis->arg2); + sprintf(szString, "NPP_NewStream(%#08lx, %s, %#08lx, %s, %s)%s", dw1, sz2, dw3, + ((NPBool)dw4 == TRUE) ? "TRUE" : "FALSE", sz5, szEOL); + break; + } + case action_npp_destroy_stream: + sprintf(szString, "NPP_DestroyStream(%#08lx, %#08lx, %s)%s", dw1,dw2,FormatNPAPIReason((int)dw3),szEOL); + break; + case action_npp_stream_as_file: + FormatPCHARArgument(sz3, sizeof(sz3), &plis->arg3); + sprintf(szString, "NPP_StreamAsFile(%#08lx, %#08lx, %s)%s", dw1,dw2,sz3,szEOL); + break; + case action_npp_write_ready: + sprintf(szString, "NPP_WriteReady(%#08lx, %#08lx)%s", dw1,dw2,szEOL); + break; + case action_npp_write: + { + FormatPCHARArgument(sz5, sizeof(sz5), &plis->arg5); + sprintf(szString, "NPP_Write(%#08lx, %#08lx, %li, %li, %s))%s",dw1,dw2,dw3,dw4,sz5,szEOL); + break; + } + case action_npp_print: + sprintf(szString, "NPP_Print(%#08lx, %#08lx)%s", dw1, dw2,szEOL); + break; + case action_npp_handle_event: + sprintf(szString, "NPP_HandleEvent(%#08lx, %#08lx)%s", dw1,dw2,szEOL); + break; + case action_npp_url_notify: + { + FormatPCHARArgument(sz2, sizeof(sz2), &plis->arg2); + sprintf(szString, "NPP_URLNotify(%#08lx, %s, %s, %#08lx)%s", dw1,sz2,FormatNPAPIReason((int)dw3),dw4,szEOL); + break; + } + case action_npp_get_java_class: + sprintf(szString, "NPP_GetJavaClass()%s",szEOL); + break; + case action_npp_get_value: + sprintf(szString, "NPP_GetValue(%#08lx, %s, %#08lx)%s", dw1,FormatNPPVariable((NPPVariable)dw2),dw3,szEOL); + break; + case action_npp_set_value: + sprintf(szString, "NPP_SetValue(%#08lx, %s, %#08lx)%s", dw1,FormatNPNVariable((NPNVariable)dw2),dw3,szEOL); + break; + + default: + sprintf(szString, "Unknown action%s",szEOL); + break; + } + strcat(szOutput, szString); + strcat(szOutput, szEOI); + iRet = strlen(szString) + strlen(szEOI) + 1; + return iRet; +} diff --git a/mozilla/modules/plugin/tools/spy/common/logfile.cpp b/mozilla/modules/plugin/tools/spy/common/logfile.cpp new file mode 100644 index 00000000000..6afecd9fad8 --- /dev/null +++ b/mozilla/modules/plugin/tools/spy/common/logfile.cpp @@ -0,0 +1,69 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + * + */ + +#include "xp.h" + +#include "logfile.h" +#include "plugload.h" + +CLogFile::CLogFile() : + hFile(NULL) +{ + szFileName[0] = '\0'; +} + +CLogFile::~CLogFile() +{ + if(hFile != NULL) + close(); +} + +BOOL CLogFile::create(char * filename, BOOL delete_existing) +{ + strcpy(szFileName, filename); + + if(!delete_existing && XP_IsFile(szFileName)) + return FALSE; + + hFile = XP_CreateFile(szFileName); + return (hFile != NULL); +} + +void CLogFile::close() +{ + if(hFile != NULL) + { + XP_CloseFile(hFile); + hFile = NULL; + } +} + +DWORD CLogFile::write(char * buf) +{ + return XP_WriteFile(hFile, buf, strlen(buf)); +} + +void CLogFile::flush() +{ + XP_FlushFileBuffers(hFile); +} diff --git a/mozilla/modules/plugin/tools/spy/common/logger.cpp b/mozilla/modules/plugin/tools/spy/common/logger.cpp new file mode 100644 index 00000000000..bd66182bdf5 --- /dev/null +++ b/mozilla/modules/plugin/tools/spy/common/logger.cpp @@ -0,0 +1,383 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + * + */ + +#include "xp.h" +#include + +#include "resource.h" +#include "logger.h" +#include "profile.h" +#include "plugload.h" + +Logger::Logger() : + bMutedAll(FALSE), + bOnTop(TRUE), + bToWindow(TRUE), + bToConsole(FALSE), + bToFile(FALSE), + bSPALID(FALSE) +{ + if(0 != GetPluginsDir(szFile, strlen(szFile))) + { + strcat(szFile, "\\"); + strcat(szFile, DEFAULT_LOG_FILE_NAME); + } + else + szFile[0] = '\0'; + + for(int i = 0; i < sizeof(bMutedCalls)/sizeof(BOOL); i++) + bMutedCalls[i] = FALSE; + + bMutedCalls[action_npn_mem_alloc] = TRUE; + bMutedCalls[action_npn_mem_free] = TRUE; + bMutedCalls[action_npn_mem_flush] = TRUE; +} + +Logger::~Logger() +{ +} + +BOOL Logger::init() +{ + if(bToFile) + filer.create(szFile, TRUE); + + return TRUE; +} + +void Logger::shut() +{ + filer.close(); +} + +#define MAX_OUTPUT_SIZE 8192 + +void Logger::logNS_NP_GetEntryPoints() +{ + char szLog[] = "NP_GetEntryPoints by Netscape\r\n"; + + if(bToConsole) + printf("%s", szLog); + + if(bToFile) + filer.write(szLog); + + if(bToWindow) + dumpStringToMainWindow(szLog); +} + +void Logger::logNS_NP_Initialize() +{ + char szLog[] = "NP_Initialize by Netscape\r\n"; + + if(bToConsole) + printf("%s", szLog); + + if(bToFile) + filer.write(szLog); + + if(bToWindow) + dumpStringToMainWindow(szLog); +} + +void Logger::logNS_NP_Shutdown() +{ + char szLog[] = "NP_Shutdown by Netscape\r\n"; + + if(bToConsole) + printf("%s", szLog); + + if(bToFile) + filer.write(szLog); + + if(bToWindow) + dumpStringToMainWindow(szLog); +} + +void Logger::logSPY_NP_GetEntryPoints(NPPluginFuncs * pNPPFuncs) +{ + char szLog[80] = "NP_GetEntryPoints by NPSpy\r\n"; + + if(bToConsole) + printf("%s", szLog); + + if(bToFile) + filer.write(szLog); + + if(bToWindow) + dumpStringToMainWindow(szLog); + + if(!pNPPFuncs) + return; + + char szLog1[80],szLog2[80],szLog3[80],szLog4[80],szLog5[80],szLog6[80],szLog7[80], + szLog8[80],szLog9[80],szLog10[80],szLog11[80],szLog12[80],szLog13[80],szLog14[80], + szLog15[80],szLog16[80],szLog17[80],szLog18[80],szLog19[80],szLog20[80]; + + sprintf(szLog1, "\r\n"); + sprintf(szLog2, " Plugin entry point table\r\n"); + sprintf(szLog3, " ========================\r\n"); + + if(pNPPFuncs->size) + sprintf(szLog4, " size = %i\r\n", pNPPFuncs->size); + else + sprintf(szLog4, " size = not set!\r\n"); + + if(pNPPFuncs->version) + sprintf(szLog5, " version = %i\r\n", pNPPFuncs->version); + else + sprintf(szLog5, " version = not set!\r\n"); + + if(pNPPFuncs->newp) + sprintf(szLog6, " newp = %#08lx\r\n", pNPPFuncs->newp); + else + sprintf(szLog6, " newp = not set!\r\n"); + + if(pNPPFuncs->destroy) + sprintf(szLog7, " destroy = %#08lx\r\n", pNPPFuncs->destroy); + else + sprintf(szLog7, " destroy = not set!\r\n"); + + if(pNPPFuncs->setwindow) + sprintf(szLog8, " setwindow = %#08lx\r\n", pNPPFuncs->setwindow); + else + sprintf(szLog8, " setwindow = not set!\r\n"); + + if(pNPPFuncs->newstream) + sprintf(szLog9, " newstream = %#08lx\r\n", pNPPFuncs->newstream); + else + sprintf(szLog9, " newstream = not set!\r\n"); + + if(pNPPFuncs->destroystream) + sprintf(szLog10, " destroystream = %#08lx\r\n", pNPPFuncs->destroystream); + else + sprintf(szLog10, " destroystream = not set!\r\n"); + + if(pNPPFuncs->asfile) + sprintf(szLog11, " asfile = %#08lx\r\n", pNPPFuncs->asfile); + else + sprintf(szLog11, " asfile = not set!\r\n"); + + if(pNPPFuncs->writeready) + sprintf(szLog12, " writeready = %#08lx\r\n", pNPPFuncs->writeready); + else + sprintf(szLog12, " writeready = not set!\r\n"); + + if(pNPPFuncs->write) + sprintf(szLog13, " write = %#08lx\r\n", pNPPFuncs->write); + else + sprintf(szLog13, " write = not set!\r\n"); + + if(pNPPFuncs->print) + sprintf(szLog14, " print = %#08lx\r\n", pNPPFuncs->print); + else + sprintf(szLog14, " print = not set!\r\n"); + + if(pNPPFuncs->event) + sprintf(szLog15, " event = %#08lx\r\n", pNPPFuncs->event); + else + sprintf(szLog15, " event = not set!\r\n"); + + if(pNPPFuncs->urlnotify) + sprintf(szLog16, " urlnotify = %#08lx\r\n", pNPPFuncs->urlnotify); + else + sprintf(szLog16, " urlnotify = not set!\r\n"); + + if(pNPPFuncs->javaClass) + sprintf(szLog17, " javaClass = %#08lx\r\n", pNPPFuncs->javaClass); + else + sprintf(szLog17, " javaClass = not set!\r\n"); + + if(pNPPFuncs->getvalue) + sprintf(szLog18, " getvalue = %#08lx\r\n", pNPPFuncs->getvalue); + else + sprintf(szLog18, " getvalue = not set!\r\n"); + + if(pNPPFuncs->setvalue) + sprintf(szLog19, " setvalue = %#08lx\r\n", pNPPFuncs->setvalue); + else + sprintf(szLog19, " setvalue = not set!\r\n"); + + sprintf(szLog20, "\r\n"); + + if(bToConsole) + { + printf("%s", szLog1); printf("%s", szLog2); printf("%s", szLog3); printf("%s", szLog4); + printf("%s", szLog5); printf("%s", szLog6); printf("%s", szLog7); printf("%s", szLog8); + printf("%s", szLog9); printf("%s", szLog10); printf("%s", szLog11); printf("%s", szLog12); + printf("%s", szLog13); printf("%s", szLog14); printf("%s", szLog15); printf("%s", szLog16); + printf("%s", szLog17); printf("%s", szLog18); printf("%s", szLog19); printf("%s", szLog20); + } + + if(bToFile) + { + filer.write(szLog1); filer.write(szLog2); filer.write(szLog3); filer.write(szLog4); + filer.write(szLog5); filer.write(szLog6); filer.write(szLog7); filer.write(szLog8); + filer.write(szLog9); filer.write(szLog10); filer.write(szLog11); filer.write(szLog12); + filer.write(szLog13); filer.write(szLog14); filer.write(szLog15); filer.write(szLog16); + filer.write(szLog17); filer.write(szLog18); filer.write(szLog19); filer.write(szLog20); + } + + if(bToWindow) + { + dumpStringToMainWindow(szLog1); dumpStringToMainWindow(szLog2); + dumpStringToMainWindow(szLog3); dumpStringToMainWindow(szLog4); + dumpStringToMainWindow(szLog5); dumpStringToMainWindow(szLog6); + dumpStringToMainWindow(szLog7); dumpStringToMainWindow(szLog8); + dumpStringToMainWindow(szLog9); dumpStringToMainWindow(szLog10); + dumpStringToMainWindow(szLog11); dumpStringToMainWindow(szLog12); + dumpStringToMainWindow(szLog13); dumpStringToMainWindow(szLog14); + dumpStringToMainWindow(szLog15); dumpStringToMainWindow(szLog16); + dumpStringToMainWindow(szLog17); dumpStringToMainWindow(szLog18); + dumpStringToMainWindow(szLog19); dumpStringToMainWindow(szLog20); + } +} + +void Logger::logSPY_NP_Initialize() +{ + char szLog[] = "NP_Initialize by NPSpy\r\n"; + + if(bToConsole) + printf("%s", szLog); + + if(bToFile) + filer.write(szLog); + + if(bToWindow) + dumpStringToMainWindow(szLog); +} + +void Logger::logSPY_NP_Shutdown(char * mimetype) +{ + char szLog[512] = "NP_Shutdown by NPSpy\r\n"; + if(mimetype) + { + strcat(szLog, " for \""); + strcat(szLog, mimetype); + strcat(szLog, "\""); + } + + if(bToConsole) + printf("%s", szLog); + + if(bToFile) + filer.write(szLog); + + if(bToWindow) + dumpStringToMainWindow(szLog); +} + +void Logger::logCall(NPAPI_Action action, DWORD dw1, DWORD dw2, DWORD dw3, DWORD dw4, DWORD dw5, DWORD dw6, DWORD dw7) +{ + if(isMuted(action)) + return; + + static char szLog[512]; + + LogItemStruct * lis = makeLogItemStruct(action, dw1, dw2, dw3, dw4, dw5, dw6, dw7); + int iLength = formatLogItem(lis, szLog, TRUE); + freeLogItemStruct(lis); + + if(bToConsole) + printf("%s", szLog); + + if(bToFile) + filer.write(szLog); + + if(bToWindow) + dumpStringToMainWindow(szLog); +} + +void Logger::logReturn(DWORD dwRet) +{ +} + +void Logger::setOnTop(BOOL ontop) +{ + bOnTop = ontop; +} + +void Logger::setToFile(BOOL tofile, char * filename) +{ + if(!filename || (strlen(filename) == 0) || (strlen(filename) > _MAX_PATH)) + { + bToFile = FALSE; + return; + } + + //don't screw up the file on false call + BOOL samefile = (stricmp(szFile, filename) == 0); + BOOL sameaction = (bToFile == tofile); + + if(sameaction) + { + if(samefile) + return; + + strcpy(szFile, filename); + + if(bToFile) + { + filer.close(); + filer.create(szFile, TRUE); + } + } + + if(!sameaction) + { + bToFile = tofile; + + if(!samefile) + strcpy(szFile, filename); + + if(bToFile) + filer.create(szFile, TRUE); + else + filer.close(); + } +} + +BOOL Logger::isMuted(NPAPI_Action action) +{ + if(bMutedAll) + return TRUE; + + if(action >= TOTAL_NUMBER_OF_API_CALLS) + { + assert(0); + return FALSE; + } + + return bMutedCalls[action]; +} + +BOOL * Logger::getMutedCalls() +{ + return &bMutedCalls[0]; +} + +void Logger::setMutedCalls(BOOL * mutedcalls) +{ + for(int i = 0; i < sizeof(bMutedCalls)/sizeof(BOOL); i++) + bMutedCalls[i] = mutedcalls[i]; +} diff --git a/mozilla/modules/plugin/tools/spy/common/np_entry.cpp b/mozilla/modules/plugin/tools/spy/common/np_entry.cpp new file mode 100644 index 00000000000..766cdf6b82a --- /dev/null +++ b/mozilla/modules/plugin/tools/spy/common/np_entry.cpp @@ -0,0 +1,155 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + * + */ + +#include "xp.h" + +#include "npapi.h" +#include "npupp.h" +#include "epmanager.h" +#include "logger.h" + +// we need to keep track of different plugins and different instances +// of the same plugin when we call NPP functions, so that we always +// call the right ones. Entry point manager will take care of it. +NPPEntryPointManager * epManager = NULL; + +Logger * logger = NULL; + +NPNetscapeFuncs NPNFuncs; + +NPError WINAPI NP_GetEntryPoints(NPPluginFuncs* pFuncs) +{ + // create the logger + if(!logger) + { + logger = NewLogger(); + if(logger) + { + logger->platformInit(); + logger->init(); + } + } + + if(logger) + logger->logNS_NP_GetEntryPoints(); + + if(pFuncs == NULL) + return NPERR_INVALID_FUNCTABLE_ERROR; + + if(pFuncs->size < sizeof(NPPluginFuncs)) + return NPERR_INVALID_FUNCTABLE_ERROR; + + pFuncs->version = (NP_VERSION_MAJOR << 8) | NP_VERSION_MINOR; + pFuncs->newp = NPP_New; + pFuncs->destroy = NPP_Destroy; + pFuncs->setwindow = NPP_SetWindow; + pFuncs->newstream = NPP_NewStream; + pFuncs->destroystream = NPP_DestroyStream; + pFuncs->asfile = NPP_StreamAsFile; + pFuncs->writeready = NPP_WriteReady; + pFuncs->write = NPP_Write; + pFuncs->print = NPP_Print; + pFuncs->event = NPP_HandleEvent; + pFuncs->urlnotify = NPP_URLNotify; + pFuncs->getvalue = NPP_GetValue; + pFuncs->setvalue = NPP_SetValue; + pFuncs->javaClass = NULL; + + return NPERR_NO_ERROR; +} + +NPError WINAPI NP_Initialize(NPNetscapeFuncs* pFuncs) +{ + // create the logger + if(!logger) + { + logger = NewLogger(); + if(logger) + { + logger->platformInit(); + logger->init(); + } + } + + if(logger) + logger->logNS_NP_Initialize(); + + if(pFuncs == NULL) + return NPERR_INVALID_FUNCTABLE_ERROR; + + if(HIBYTE(pFuncs->version) > NP_VERSION_MAJOR) + return NPERR_INCOMPATIBLE_VERSION_ERROR; + + if(pFuncs->size < sizeof NPNetscapeFuncs) + return NPERR_INVALID_FUNCTABLE_ERROR; + + NPNFuncs.size = pFuncs->size; + NPNFuncs.version = pFuncs->version; + NPNFuncs.geturlnotify = pFuncs->geturlnotify; + NPNFuncs.geturl = pFuncs->geturl; + NPNFuncs.posturlnotify = pFuncs->posturlnotify; + NPNFuncs.posturl = pFuncs->posturl; + NPNFuncs.requestread = pFuncs->requestread; + NPNFuncs.newstream = pFuncs->newstream; + NPNFuncs.write = pFuncs->write; + NPNFuncs.destroystream = pFuncs->destroystream; + NPNFuncs.status = pFuncs->status; + NPNFuncs.uagent = pFuncs->uagent; + NPNFuncs.memalloc = pFuncs->memalloc; + NPNFuncs.memfree = pFuncs->memfree; + NPNFuncs.memflush = pFuncs->memflush; + NPNFuncs.reloadplugins = pFuncs->reloadplugins; + NPNFuncs.getJavaEnv = pFuncs->getJavaEnv; + NPNFuncs.getJavaPeer = pFuncs->getJavaPeer; + NPNFuncs.getvalue = pFuncs->getvalue; + NPNFuncs.setvalue = pFuncs->setvalue; + NPNFuncs.invalidaterect = pFuncs->invalidaterect; + NPNFuncs.invalidateregion = pFuncs->invalidateregion; + NPNFuncs.forceredraw = pFuncs->forceredraw; + + // create entry point manager for real plugins + epManager = new NPPEntryPointManager(); + if(!epManager) + return NPERR_GENERIC_ERROR; + + return NPERR_NO_ERROR; +} + +NPError WINAPI NP_Shutdown() +{ + // should be safe because if they've already been called shutdown procs must be NULL + if(epManager) + epManager->callNP_ShutdownAll(); // this will log the action + + if(logger) + { + logger->shut(); + logger->platformShut(); + DeleteLogger(logger); + logger = NULL; + } + + delete epManager; + + return NPERR_NO_ERROR; +} diff --git a/mozilla/modules/plugin/tools/spy/common/npn_gate.cpp b/mozilla/modules/plugin/tools/spy/common/npn_gate.cpp new file mode 100644 index 00000000000..e92120f02f0 --- /dev/null +++ b/mozilla/modules/plugin/tools/spy/common/npn_gate.cpp @@ -0,0 +1,336 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + * + */ + +#include "xp.h" + +#include "npapi.h" +#include "npupp.h" + +#include "logger.h" + +extern Logger * logger; +extern NPNetscapeFuncs NPNFuncs; + +void NPN_Version(int* plugin_major, int* plugin_minor, int* netscape_major, int* netscape_minor) +{ + if(logger) + logger->logCall(action_npn_version, (DWORD)plugin_major, (DWORD)plugin_minor, (DWORD)netscape_major, (DWORD)netscape_minor); + + *plugin_major = NP_VERSION_MAJOR; + *plugin_minor = NP_VERSION_MINOR; + *netscape_major = HIBYTE(NPNFuncs.version); + *netscape_minor = LOBYTE(NPNFuncs.version); + + if(logger) + logger->logReturn(); +} + +NPError NPN_GetURLNotify(NPP instance, const char *url, const char *target, void* notifyData) +{ + int navMinorVers = NPNFuncs.version & 0xFF; + + NPError rv = NPERR_NO_ERROR; + + if(logger) + logger->logCall(action_npn_get_url_notify, (DWORD)instance, (DWORD)url, (DWORD)target, (DWORD)notifyData); + + if( navMinorVers >= NPVERS_HAS_NOTIFICATION ) + rv = NPNFuncs.geturlnotify(instance, url, target, notifyData); + else + rv = NPERR_INCOMPATIBLE_VERSION_ERROR; + + if(logger) + logger->logReturn(); + + return rv; +} + +NPError NPN_GetURL(NPP instance, const char *url, const char *target) +{ + if(logger) + logger->logCall(action_npn_get_url, (DWORD)instance, (DWORD)url, (DWORD)target); + + NPError rv = NPNFuncs.geturl(instance, url, target); + + if(logger) + logger->logReturn(); + + return rv; +} + +NPError NPN_PostURLNotify(NPP instance, const char* url, const char* window, uint32 len, const char* buf, NPBool file, void* notifyData) +{ + int navMinorVers = NPNFuncs.version & 0xFF; + + NPError rv = NPERR_NO_ERROR; + + if(logger) + logger->logCall(action_npn_post_url_notify, (DWORD)instance, (DWORD)url, (DWORD)window, (DWORD)len, (DWORD)buf, (DWORD)file, (DWORD)notifyData); + + if( navMinorVers >= NPVERS_HAS_NOTIFICATION ) + rv = NPNFuncs.posturlnotify(instance, url, window, len, buf, file, notifyData); + else + rv = NPERR_INCOMPATIBLE_VERSION_ERROR; + + if(logger) + logger->logReturn(); + + return rv; +} + +NPError NPN_PostURL(NPP instance, const char* url, const char* window, uint32 len, const char* buf, NPBool file) +{ + if(logger) + logger->logCall(action_npn_post_url, (DWORD)instance, (DWORD)url, (DWORD)window, (DWORD)len, (DWORD)buf, (DWORD)file); + + NPError rv = NPNFuncs.posturl(instance, url, window, len, buf, file); + + if(logger) + logger->logReturn(); + + return rv; +} + +NPError NPN_RequestRead(NPStream* stream, NPByteRange* rangeList) +{ + if(logger) + logger->logCall(action_npn_request_read, (DWORD)stream, (DWORD)rangeList); + + NPError rv = NPNFuncs.requestread(stream, rangeList); + + if(logger) + logger->logReturn(); + + return rv; +} + +NPError NPN_NewStream(NPP instance, NPMIMEType type, const char* target, NPStream** stream) +{ + int navMinorVersion = NPNFuncs.version & 0xFF; + + NPError rv = NPERR_NO_ERROR; + + if(logger) + logger->logCall(action_npn_new_stream, (DWORD)instance, (DWORD)type, (DWORD)target, (DWORD)stream); + + if( navMinorVersion >= NPVERS_HAS_STREAMOUTPUT ) + rv = NPNFuncs.newstream(instance, type, target, stream); + else + rv = NPERR_INCOMPATIBLE_VERSION_ERROR; + + if(logger) + logger->logReturn(); + + return rv; +} + +int32 NPN_Write(NPP instance, NPStream *stream, int32 len, void *buffer) +{ + int navMinorVersion = NPNFuncs.version & 0xFF; + + int32 rv = 0; + + if(logger) + logger->logCall(action_npn_write, (DWORD)instance, (DWORD)stream, (DWORD)len, (DWORD)buffer); + + if( navMinorVersion >= NPVERS_HAS_STREAMOUTPUT ) + rv = NPNFuncs.write(instance, stream, len, buffer); + else + rv = -1; + + if(logger) + logger->logReturn(); + + return rv; +} + +NPError NPN_DestroyStream(NPP instance, NPStream* stream, NPError reason) +{ + int navMinorVersion = NPNFuncs.version & 0xFF; + + NPError rv = NPERR_NO_ERROR; + + if(logger) + logger->logCall(action_npn_destroy_stream, (DWORD)instance, (DWORD)stream, (DWORD)reason); + + if( navMinorVersion >= NPVERS_HAS_STREAMOUTPUT ) + rv = NPNFuncs.destroystream(instance, stream, reason); + else + rv = NPERR_INCOMPATIBLE_VERSION_ERROR; + + if(logger) + logger->logReturn(); + + return rv; +} + +void NPN_Status(NPP instance, const char *message) +{ + if(logger) + logger->logCall(action_npn_status, (DWORD)instance, (DWORD)message); + + NPNFuncs.status(instance, message); +} + +const char* NPN_UserAgent(NPP instance) +{ + const char * rv = NULL; + + if(logger) + logger->logCall(action_npn_user_agent, (DWORD)instance); + + rv = NPNFuncs.uagent(instance); + + if(logger) + logger->logReturn(); + + return rv; +} + +void* NPN_MemAlloc(uint32 size) +{ + void * rv = NULL; + + if(logger) + logger->logCall(action_npn_mem_alloc, (DWORD)size); + + rv = NPNFuncs.memalloc(size); + + if(logger) + logger->logReturn(); + + return rv; +} + +void NPN_MemFree(void* ptr) +{ + if(logger) + logger->logCall(action_npn_mem_free, (DWORD)ptr); + + NPNFuncs.memfree(ptr); +} + +uint32 NPN_MemFlush(uint32 size) +{ + if(logger) + logger->logCall(action_npn_mem_flush, (DWORD)size); + + uint32 rv = NPNFuncs.memflush(size); + + if(logger) + logger->logReturn(); + + return rv; +} + +void NPN_ReloadPlugins(NPBool reloadPages) +{ + if(logger) + logger->logCall(action_npn_reload_plugins, (DWORD)reloadPages); + + NPNFuncs.reloadplugins(reloadPages); +} + +JRIEnv* NPN_GetJavaEnv(void) +{ + JRIEnv * rv = NULL; + + if(logger) + logger->logCall(action_npn_get_java_env); + + rv = NPNFuncs.getJavaEnv(); + + if(logger) + logger->logReturn(); + + return rv; +} + +jref NPN_GetJavaPeer(NPP instance) +{ + jref rv; + + if(logger) + logger->logCall(action_npn_get_java_peer, (DWORD)instance); + + rv = NPNFuncs.getJavaPeer(instance); + + if(logger) + logger->logReturn(); + + return rv; +} + +NPError NPN_GetValue(NPP instance, NPNVariable variable, void *value) +{ + NPError rv = NPERR_NO_ERROR; + + if(logger) + logger->logCall(action_npn_get_value, (DWORD)instance, (DWORD)variable, (DWORD)value); + + rv = NPNFuncs.getvalue(instance, variable, value); + + if(logger) + logger->logReturn(action_npn_get_value); + + return rv; +} + +NPError NPN_SetValue(NPP instance, NPPVariable variable, void *value) +{ + NPError rv = NPERR_NO_ERROR; + + if(logger) + logger->logCall(action_npn_set_value, (DWORD)instance, (DWORD)variable, (DWORD)value); + + rv = NPNFuncs.setvalue(instance, variable, value); + + if(logger) + logger->logReturn(); + + return rv; +} + +void NPN_InvalidateRect(NPP instance, NPRect *invalidRect) +{ + if(logger) + logger->logCall(action_npn_invalidate_rect, (DWORD)instance, (DWORD)invalidRect); + + NPNFuncs.invalidaterect(instance, invalidRect); +} + +void NPN_InvalidateRegion(NPP instance, NPRegion invalidRegion) +{ + if(logger) + logger->logCall(action_npn_invalidate_region, (DWORD)instance, (DWORD)invalidRegion); + + NPNFuncs.invalidateregion(instance, invalidRegion); +} + +void NPN_ForceRedraw(NPP instance) +{ + if(logger) + logger->logCall(action_npn_force_redraw, (DWORD)instance); + + NPNFuncs.forceredraw(instance); +} diff --git a/mozilla/modules/plugin/tools/spy/common/npp_gate.cpp b/mozilla/modules/plugin/tools/spy/common/npp_gate.cpp new file mode 100644 index 00000000000..2e19e255e52 --- /dev/null +++ b/mozilla/modules/plugin/tools/spy/common/npp_gate.cpp @@ -0,0 +1,370 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + * + */ + +#include "xp.h" + +#include "resource.h" +#include "epmanager.h" +#include "plugload.h" +#include "logger.h" + +extern NPNetscapeFuncs NPNFuncs; +extern Logger * logger; + +NPNetscapeFuncs fakeNPNFuncs; + +extern NPPEntryPointManager * epManager; + +jref NPP_GetJavaClass (void) +{ + if(logger) + logger->logCall(action_npp_get_java_class); + + if(logger) + logger->logReturn(); + return NULL; +} + +NPError NPP_New(NPMIMEType pluginType, + NPP instance, + uint16 mode, + int16 argc, + char* argn[], + char* argv[], + NPSavedData* saved) +{ + if(epManager == NULL) + return NPERR_GENERIC_ERROR; + + if(instance == NULL) + return NPERR_INVALID_INSTANCE_ERROR; + + if(logger) + logger->logCall(action_npp_new, (DWORD)pluginType, (DWORD)instance, (DWORD)mode, (DWORD)argc, (DWORD)argn, (DWORD)argv, (DWORD)saved); + +/* now action begins */ + + if(NULL == epManager->findEntryPointsForPlugin(pluginType)) + { + // if it is first time in, we don't have it yet + // scan plugins dir for available plugins to see if we have anything + // for the given mimetype + XP_HLIB hLib = LoadRealPlugin(pluginType); + if(!hLib) + { + // what do we do if we don't? + return NPERR_GENERIC_ERROR; + } + + NP_GETENTRYPOINTS real_NP_GetEntryPoints = (NP_GETENTRYPOINTS)GetProcAddress(hLib, "NP_GetEntryPoints"); + if(!real_NP_GetEntryPoints) + return NPERR_GENERIC_ERROR; + + NP_INITIALIZE real_NP_Initialize = (NP_INITIALIZE)GetProcAddress(hLib, "NP_Initialize"); + if(!real_NP_Initialize) + return NPERR_GENERIC_ERROR; + + NP_SHUTDOWN real_NP_Shutdown = (NP_SHUTDOWN)GetProcAddress(hLib, "NP_Shutdown"); + if(!real_NP_Shutdown) + return NPERR_GENERIC_ERROR; + + // fill callbacks structs + NPPluginFuncs realNPPFuncs; + memset(&realNPPFuncs, 0, sizeof(NPPluginFuncs)); + realNPPFuncs.size = sizeof(NPPluginFuncs); + + real_NP_GetEntryPoints(&realNPPFuncs); + + if(logger) + logger->logSPY_NP_GetEntryPoints(&realNPPFuncs); + + // store the table with the entry point manager + epManager->createEntryPointsForPlugin(pluginType, &realNPPFuncs, real_NP_Shutdown, hLib); + + // inform the plugin about our entry point it should call + memset((void *)&fakeNPNFuncs, 0, sizeof(fakeNPNFuncs)); + + fakeNPNFuncs.size = sizeof(fakeNPNFuncs); + fakeNPNFuncs.version = NPNFuncs.version; + fakeNPNFuncs.geturlnotify = NPN_GetURLNotify; + fakeNPNFuncs.geturl = NPN_GetURL; + fakeNPNFuncs.posturlnotify = NPN_PostURLNotify; + fakeNPNFuncs.posturl = NPN_PostURL; + fakeNPNFuncs.requestread = NPN_RequestRead; + fakeNPNFuncs.newstream = NPN_NewStream; + fakeNPNFuncs.write = NPN_Write; + fakeNPNFuncs.destroystream = NPN_DestroyStream; + fakeNPNFuncs.status = NPN_Status; + fakeNPNFuncs.uagent = NPN_UserAgent; + fakeNPNFuncs.memalloc = NPN_MemAlloc; + fakeNPNFuncs.memfree = NPN_MemFree; + fakeNPNFuncs.memflush = NPN_MemFlush; + fakeNPNFuncs.reloadplugins = NPN_ReloadPlugins; + fakeNPNFuncs.getJavaEnv = NPN_GetJavaEnv; + fakeNPNFuncs.getJavaPeer = NPN_GetJavaPeer; + fakeNPNFuncs.getvalue = NPN_GetValue; + fakeNPNFuncs.setvalue = NPN_SetValue; + fakeNPNFuncs.invalidaterect = NPN_InvalidateRect; + fakeNPNFuncs.invalidateregion = NPN_InvalidateRegion; + fakeNPNFuncs.forceredraw = NPN_ForceRedraw; + + if(logger) + logger->logSPY_NP_Initialize(); + + real_NP_Initialize(&fakeNPNFuncs); + } + + NPError rv = epManager->callNPP_New(pluginType, instance, mode, argc, argn, argv, saved); + + if(logger) + logger->logReturn(); + + return rv; +} + +NPError NPP_Destroy (NPP instance, NPSavedData** save) +{ + if(epManager == NULL) + return NPERR_GENERIC_ERROR; + + if(instance == NULL) + return NPERR_INVALID_INSTANCE_ERROR; + + BOOL last = FALSE; + + if(logger) + logger->logCall(action_npp_destroy, (DWORD)instance, (DWORD)save); + + NPError rv = epManager->callNPP_Destroy(instance, save, &last); + + if(logger) + logger->logReturn(); + + if(last && logger->bSPALID) + { + // this will log it + epManager->callNP_Shutdown(instance); + + XP_HLIB hLib = NULL; + + epManager->removeEntryPointsForPlugin(instance, &hLib); + + UnloadRealPlugin(hLib); + } + return rv; +} + +NPError NPP_SetWindow (NPP instance, NPWindow* pNPWindow) +{ + if(epManager == NULL) + return NPERR_GENERIC_ERROR; + + if(instance == NULL) + return NPERR_INVALID_INSTANCE_ERROR; + + if(logger) + logger->logCall(action_npp_set_window, (DWORD)instance, (DWORD)pNPWindow); + + NPError rv = epManager->callNPP_SetWindow(instance, pNPWindow); + + if(logger) + logger->logReturn(); + + return rv; +} + +NPError NPP_NewStream(NPP instance, + NPMIMEType type, + NPStream* stream, + NPBool seekable, + uint16* stype) +{ + if(epManager == NULL) + return NPERR_GENERIC_ERROR; + + if(instance == NULL) + return NPERR_INVALID_INSTANCE_ERROR; + + if(logger) + logger->logCall(action_npp_new_stream, (DWORD)instance, (DWORD)type, (DWORD)stream, (DWORD)seekable, (DWORD)stype); + + NPError rv = epManager->callNPP_NewStream(instance, type, stream, seekable, stype); + + if(logger) + logger->logReturn(); + + return rv; +} + +int32 NPP_WriteReady (NPP instance, NPStream *stream) +{ + if(epManager == NULL) + return NPERR_GENERIC_ERROR; + + if(instance == NULL) + return NPERR_INVALID_INSTANCE_ERROR; + + if(logger) + logger->logCall(action_npp_write_ready, (DWORD)instance, (DWORD)stream); + + int32 rv = epManager->callNPP_WriteReady(instance, stream); + + if(logger) + logger->logReturn(); + + return rv; +} + +int32 NPP_Write (NPP instance, NPStream *stream, int32 offset, int32 len, void *buffer) +{ + if(epManager == NULL) + return NPERR_GENERIC_ERROR; + + if(instance == NULL) + return NPERR_INVALID_INSTANCE_ERROR; + + if(logger) + logger->logCall(action_npp_write, (DWORD)instance, (DWORD)stream, (DWORD)offset, (DWORD)len, (DWORD)buffer); + + int32 rv = epManager->callNPP_Write(instance, stream, offset, len, buffer); + + if(logger) + logger->logReturn(); + + return rv; +} + +NPError NPP_DestroyStream (NPP instance, NPStream *stream, NPError reason) +{ + if(epManager == NULL) + return NPERR_GENERIC_ERROR; + + if(instance == NULL) + return NPERR_INVALID_INSTANCE_ERROR; + + if(logger) + logger->logCall(action_npp_destroy_stream, (DWORD)instance, (DWORD)stream, (DWORD)reason); + + NPError rv = epManager->callNPP_DestroyStream(instance, stream, reason); + + if(logger) + logger->logReturn(); + + return rv; +} + +void NPP_StreamAsFile (NPP instance, NPStream* stream, const char* fname) +{ + if(epManager == NULL) + return; + + if(instance == NULL) + return; + + if(logger) + logger->logCall(action_npp_stream_as_file, (DWORD)instance, (DWORD)stream, (DWORD)fname); + + epManager->callNPP_StreamAsFile(instance, stream, fname); +} + +void NPP_Print (NPP instance, NPPrint* printInfo) +{ + if(epManager == NULL) + return; + + if(logger) + logger->logCall(action_npp_print, (DWORD)instance, (DWORD)printInfo); + + epManager->callNPP_Print(instance, printInfo); +} + +void NPP_URLNotify(NPP instance, const char* url, NPReason reason, void* notifyData) +{ + if(epManager == NULL) + return; + + if(instance == NULL) + return; + + if(logger) + logger->logCall(action_npp_url_notify, (DWORD)instance, (DWORD)url, (DWORD)reason, (DWORD)notifyData); + + epManager->callNPP_URLNotify(instance, url, reason, notifyData); +} + +NPError NPP_GetValue(NPP instance, NPPVariable variable, void *value) +{ + if(epManager == NULL) + return NPERR_GENERIC_ERROR; + + if(instance == NULL) + return NPERR_INVALID_INSTANCE_ERROR; + + if(logger) + logger->logCall(action_npp_get_value, (DWORD)instance, (DWORD)variable, (DWORD)value); + + NPError rv = epManager->callNPP_GetValue(instance, variable, value); + + if(logger) + logger->logReturn(); + + return rv; +} + +NPError NPP_SetValue(NPP instance, NPNVariable variable, void *value) +{ + if(epManager == NULL) + return NPERR_GENERIC_ERROR; + + if(instance == NULL) + return NPERR_INVALID_INSTANCE_ERROR; + + if(logger) + logger->logCall(action_npp_set_value, (DWORD)instance, (DWORD)variable, (DWORD)value); + + NPError rv = epManager->callNPP_SetValue(instance, variable, value); + + if(logger) + logger->logReturn(); + + return rv; +} + +int16 NPP_HandleEvent(NPP instance, void* event) +{ + if(epManager == NULL) + return 0; + + if(instance == NULL) + return 0; + + if(logger) + logger->logCall(action_npp_handle_event, (DWORD)instance, (DWORD)event); + + int16 rv = epManager->callNPP_HandleEvent(instance, event); + + if(logger) + logger->logReturn(); + + return rv; +} diff --git a/mozilla/modules/plugin/tools/spy/common/plugload.cpp b/mozilla/modules/plugin/tools/spy/common/plugload.cpp new file mode 100644 index 00000000000..bc0955c20a8 --- /dev/null +++ b/mozilla/modules/plugin/tools/spy/common/plugload.cpp @@ -0,0 +1,180 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + * + */ + +#include "xp.h" + +DWORD GetPluginsDir(char * path, DWORD maxsize) +{ + if(!path) + return 0; + + path[0] = '\0'; + +#ifdef XP_WIN + + DWORD res = GetModuleFileName(NULL, path, maxsize); + if(res == 0) + return 0; + + if(path[strlen(path) - 1] == '\\') + path[lstrlen(path) - 1] = '\0'; + + char *p = strrchr(path, '\\'); + + if(p) + *p = '\0'; + + strcat(path, "\\plugins"); + +#endif + +#ifdef XP_UNIX + // Implement UNIX version +#endif + +#ifdef XP_MAC + // Implement Mac version +#endif + + res = strlen(path); + return res; +} + +XP_HLIB LoadRealPlugin(char * mimetype) +{ + if(!mimetype || !strlen(mimetype)) + return NULL; + +#ifdef XP_WIN + + BOOL bDone = FALSE; + WIN32_FIND_DATA ffdataStruct; + + char szPath[_MAX_PATH]; + char szFileName[_MAX_PATH]; + + GetPluginsDir(szPath, _MAX_PATH); + + strcpy(szFileName, szPath); + strcat(szFileName, "\\00*"); + + HANDLE handle = FindFirstFile(szFileName, &ffdataStruct); + if(handle == INVALID_HANDLE_VALUE) + { + FindClose(handle); + return NULL; + } + + DWORD versize = 0L; + DWORD zero = 0L; + char * verbuf = NULL; + + do + { + strcpy(szFileName, szPath); + strcat(szFileName, "\\"); + strcat(szFileName, ffdataStruct.cFileName); + if(!(ffdataStruct. dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) + { + versize = GetFileVersionInfoSize(szFileName, &zero); + if (versize > 0) + verbuf = new char[versize]; + else + continue; + + if(!verbuf) + continue; + + GetFileVersionInfo(szFileName, NULL, versize, verbuf); + + char *mimetypes = NULL; + UINT len = 0; + + if(!VerQueryValue(verbuf, "\\StringFileInfo\\040904E4\\MIMEType", (void **)&mimetypes, &len) + || !mimetypes || !len) + { + delete [] verbuf; + continue; + } + + // browse through a string of mimetypes + mimetypes[len] = '\0'; + char * type = mimetypes; + + BOOL more = TRUE; + while(more) + { + char * p = strchr(type, '|'); + if(p) + *p = '\0'; + else + more = FALSE; + + if(0 == stricmp(mimetype, type)) + { + // this is it! + delete [] verbuf; + FindClose(handle); + HINSTANCE hLib = LoadLibrary(szFileName); + return hLib; + } + + type = p; + type++; + } + + delete [] verbuf; + } + + } while(FindNextFile(handle, &ffdataStruct)); + + FindClose(handle); + +#endif + +#ifdef XP_UNIX + // Implement UNIX version +#endif + +#ifdef XP_MAC + // Implement Mac version +#endif + + return NULL; +} + +void UnloadRealPlugin(XP_HLIB hLib) +{ +#ifdef XP_WIN + if(!hLib) + FreeLibrary(hLib); +#endif + +#ifdef XP_UNIX + // Implement UNIX version +#endif + +#ifdef XP_MAC + // Implement Mac version +#endif +} diff --git a/mozilla/modules/plugin/tools/spy/common/profile.cpp b/mozilla/modules/plugin/tools/spy/common/profile.cpp new file mode 100644 index 00000000000..19cf4161d1f --- /dev/null +++ b/mozilla/modules/plugin/tools/spy/common/profile.cpp @@ -0,0 +1,34 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + * + */ + +#include "xp.h" + +#include "profile.h" + +Profile::Profile() +{ +} + +Profile::~Profile() +{ +}