Back to index

lightning-sunbird  0.9+nobinonly
loghlp.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either the GNU General Public License Version 2 or later (the "GPL"), or
00026  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 #include "xp.h"
00039 
00040 #include "loghlp.h"
00041 
00042 extern CLogger * pLogger;
00043 
00044 LPSTR FormatNPAPIError(int iError)
00045 {
00046   static char szError[64];
00047   switch (iError)
00048   {
00049     case NPERR_NO_ERROR:
00050       wsprintf(szError, "NPERR_NO_ERROR");
00051       break;
00052     case NPERR_GENERIC_ERROR:
00053       wsprintf(szError, "NPERR_GENERIC_ERROR");
00054       break;
00055     case NPERR_INVALID_INSTANCE_ERROR:
00056       wsprintf(szError, "NPERR_INVALID_INSTANCE_ERROR");
00057       break;
00058     case NPERR_INVALID_FUNCTABLE_ERROR:
00059       wsprintf(szError, "NPERR_INVALID_FUNCTABLE_ERROR");
00060       break;
00061     case NPERR_MODULE_LOAD_FAILED_ERROR:
00062       wsprintf(szError, "NPERR_MODULE_LOAD_FAILED_ERROR");
00063       break;
00064     case NPERR_OUT_OF_MEMORY_ERROR:
00065       wsprintf(szError, "NPERR_OUT_OF_MEMORY_ERROR");
00066       break;
00067     case NPERR_INVALID_PLUGIN_ERROR:
00068       wsprintf(szError, "NPERR_INVALID_PLUGIN_ERROR");
00069       break;
00070     case NPERR_INVALID_PLUGIN_DIR_ERROR:
00071       wsprintf(szError, "NPERR_INVALID_PLUGIN_DIR_ERROR");
00072       break;
00073     case NPERR_INCOMPATIBLE_VERSION_ERROR:
00074       wsprintf(szError, "NPERR_INCOMPATIBLE_VERSION_ERROR");
00075       break;
00076     case NPERR_INVALID_PARAM:
00077       wsprintf(szError, "NPERR_INVALID_PARAM");
00078       break;
00079     case NPERR_INVALID_URL:
00080       wsprintf(szError, "NPERR_INVALID_URL");
00081       break;
00082     case NPERR_FILE_NOT_FOUND:
00083       wsprintf(szError, "NPERR_FILE_NOT_FOUND");
00084       break;
00085     case NPERR_NO_DATA:
00086       wsprintf(szError, "NPERR_NO_DATA");
00087       break;
00088     case NPERR_STREAM_NOT_SEEKABLE:
00089       wsprintf(szError, "NPERR_STREAM_NOT_SEEKABLE");
00090       break;
00091     default:
00092       wsprintf(szError, "Unlisted error");
00093       break;
00094   }
00095   return &szError[0];
00096 }
00097 
00098 LPSTR FormatNPAPIReason(int iReason)
00099 {
00100   static char szReason[64];
00101   switch (iReason)
00102   {
00103     case NPRES_DONE:
00104       wsprintf(szReason, "NPRES_DONE");
00105       break;
00106     case NPRES_NETWORK_ERR:
00107       wsprintf(szReason, "NPRES_NETWORK_ERR");
00108       break;
00109     case NPRES_USER_BREAK:
00110       wsprintf(szReason, "NPRES_USER_BREAK");
00111       break;
00112     default:
00113       wsprintf(szReason, "Unlisted reason");
00114       break;
00115   }
00116   return &szReason[0];
00117 }
00118 
00119 LPSTR FormatNPNVariable(NPNVariable var)
00120 {
00121   static char szVar[64];
00122   switch (var)
00123   {
00124     case NPNVxDisplay:
00125       wsprintf(szVar, "NPNVxDisplay");
00126       break;
00127     case NPNVxtAppContext:
00128       wsprintf(szVar, "NPNVxtAppContext");
00129       break;
00130     case NPNVnetscapeWindow:
00131       wsprintf(szVar, "NPNVnetscapeWindow");
00132       break;
00133     case NPNVjavascriptEnabledBool:
00134       wsprintf(szVar, "NPNVjavascriptEnabledBool");
00135       break;
00136     case NPNVasdEnabledBool:
00137       wsprintf(szVar, "NPNVasdEnabledBool");
00138       break;
00139     case NPNVisOfflineBool:
00140       wsprintf(szVar, "NPNVisOfflineBool");
00141       break;
00142     default:
00143       wsprintf(szVar, "Unlisted variable");
00144       break;
00145   }
00146   return &szVar[0];
00147 }
00148 
00149 LPSTR FormatNPPVariable(NPPVariable var)
00150 {
00151   static char szVar[64];
00152   switch (var)
00153   {
00154     case NPPVpluginNameString:
00155       wsprintf(szVar, "NPPVpluginNameString");
00156       break;
00157     case NPPVpluginDescriptionString:
00158       wsprintf(szVar, "NPPVpluginDescriptionString");
00159       break;
00160     case NPPVpluginWindowBool:
00161       wsprintf(szVar, "NPPVpluginWindowBool");
00162       break;
00163     case NPPVpluginTransparentBool:
00164       wsprintf(szVar, "NPPVpluginTransparentBool");
00165       break;
00166     case NPPVpluginWindowSize:
00167       wsprintf(szVar, "NPPVpluginWindowSize");
00168       break;
00169     case NPPVpluginKeepLibraryInMemory:
00170       wsprintf(szVar, "NPPVpluginKeepLibraryInMemory");
00171       break;
00172     default:
00173       wsprintf(szVar, "Unlisted variable");
00174       break;
00175   }
00176   return &szVar[0];
00177 }
00178 
00179 BOOL FormatPCHARArgument(LPSTR szBuf, int iLength, LogArgumentStruct * parg)
00180 {
00181   if(iLength <= parg->iLength)
00182     return FALSE;
00183 
00184   if(parg->pData == NULL)
00185     wsprintf(szBuf, "%#08lx", parg->dwArg);
00186   else
00187     wsprintf(szBuf, "%#08lx(\"%s\")", parg->dwArg, (LPSTR)parg->pData);
00188   return TRUE;
00189 }
00190 
00191 BOOL FormatBOOLArgument(LPSTR szBuf, int iLength, LogArgumentStruct * parg)
00192 {
00193   if(iLength <= 8)
00194     return FALSE;
00195 
00196   wsprintf(szBuf, "%s", ((NPBool)parg->dwArg == TRUE) ? "TRUE" : "FALSE");
00197   return TRUE;
00198 }
00199 
00200 BOOL FormatPBOOLArgument(LPSTR szBuf, int iLength, LogArgumentStruct * parg)
00201 {
00202   if(iLength <= 8)
00203     return FALSE;
00204 
00205   wsprintf(szBuf, "%#08lx(%s)", parg->dwArg, (*((NPBool *)parg->pData) == TRUE) ? "TRUE" : "FALSE");
00206   return TRUE;
00207 }
00208 
00209 static void makeAbbreviatedString(LPSTR szBuf, int iSize, DWORD dwArg, int iLength, int iWrap)
00210 {
00211   if(dwArg == 0L)
00212   {
00213     szBuf[0] = '\0';
00214     return;
00215   }
00216 
00217   if(iLength > iWrap)
00218   {
00219     int iRealWrap = (iSize > iWrap) ? iWrap : (iSize - 4);
00220     memcpy((LPVOID)&szBuf[0], (LPVOID)dwArg, iRealWrap);
00221     szBuf[iRealWrap]     = '.';
00222     szBuf[iRealWrap + 1] = '.';
00223     szBuf[iRealWrap + 2] = '.';
00224     szBuf[iRealWrap + 3] = '\0';
00225   }
00226   else
00227   {
00228     if(iLength >= iSize)
00229     {    
00230       memcpy((LPVOID)&szBuf[0], (LPVOID)dwArg, iSize - 4);
00231       szBuf[iSize]     = '.';
00232       szBuf[iSize + 1] = '.';
00233       szBuf[iSize + 2] = '.';
00234       szBuf[iSize + 3] = '\0';
00235     }
00236     else
00237     {
00238       memcpy((LPVOID)&szBuf[0], (LPVOID)dwArg, iLength);
00239       szBuf[iLength] = '\0';
00240     }
00241   }
00242 }
00243 
00244 LogItemStruct * makeLogItemStruct(NPAPI_Action action, 
00245                                   DWORD dwTimeEnter, DWORD dwTimeReturn, 
00246                                   DWORD dwRet, 
00247                                   DWORD dw1, DWORD dw2, DWORD dw3, DWORD dw4, 
00248                                   DWORD dw5, DWORD dw6, DWORD dw7, BOOL bShort)
00249 {
00250   int iWrap = pLogger->getStringDataWrap();
00251 
00252   LogItemStruct * plis = new LogItemStruct;
00253   if(plis == NULL)
00254     return NULL;
00255 
00256   plis->dwTimeEnter = dwTimeEnter;
00257   plis->dwTimeReturn = dwTimeReturn;
00258   plis->action = action;
00259   plis->dwReturnValue = dwRet;
00260   plis->arg1.dwArg = dw1;
00261   plis->arg2.dwArg = dw2;
00262   plis->arg3.dwArg = dw3;
00263   plis->arg4.dwArg = dw4;
00264   plis->arg5.dwArg = dw5;
00265   plis->arg6.dwArg = dw6;
00266   plis->arg7.dwArg = dw7;
00267 
00268   char szTarget[1024] = {'\0'};
00269   char szBuf[1024] = {'\0'};
00270 
00271   if(bShort)
00272     return plis;
00273 
00274   switch (action)
00275   {
00276     case action_invalid:
00277       break;
00278 
00279     // NPN action
00280     case action_npn_version:
00281       plis->arg1.pData = new int[1];
00282       *(int*)(plis->arg1.pData) = *((int*)dw1);
00283       plis->arg1.iLength = sizeof(int);
00284 
00285       plis->arg2.pData = new int[1];
00286       *(int*)(plis->arg2.pData) = *((int*)dw2);
00287       plis->arg2.iLength = sizeof(int);
00288 
00289       plis->arg3.pData = new int[1];
00290       *(int*)(plis->arg3.pData) = *((int*)dw3);
00291       plis->arg3.iLength = sizeof(int);
00292 
00293       plis->arg4.pData = new int[1];
00294       *(int*)(plis->arg4.pData) = *((int*)dw4);
00295       plis->arg4.iLength = sizeof(int);
00296 
00297       break;
00298     case action_npn_get_url_notify:
00299       if(dw2 != 0L)
00300       {
00301         plis->arg2.iLength = strlen((LPSTR)dw2) + 1;
00302         plis->arg2.pData = new char[plis->arg2.iLength];
00303         memcpy(plis->arg2.pData, (LPVOID)dw2, plis->arg2.iLength);
00304       }
00305 
00306       if(dw3 != 0L)
00307       {
00308         makeAbbreviatedString(szTarget, sizeof(szTarget), dw3, strlen((LPSTR)dw3), iWrap);
00309         plis->arg3.iLength = strlen(szTarget) + 1;
00310         plis->arg3.pData = new char[plis->arg3.iLength];
00311         memcpy(plis->arg3.pData, (LPVOID)&szTarget[0], plis->arg3.iLength);
00312       }
00313       break;
00314     case action_npn_get_url:
00315     {
00316       if(dw2 != 0L)
00317       {
00318         plis->arg2.iLength = strlen((LPSTR)dw2) + 1;
00319         plis->arg2.pData = new char[plis->arg2.iLength];
00320         memcpy(plis->arg2.pData, (LPVOID)dw2, plis->arg2.iLength);
00321       }
00322 
00323       if(dw3 != 0L)
00324       {
00325         makeAbbreviatedString(szTarget, sizeof(szTarget), dw3, strlen((LPSTR)dw3), iWrap);
00326         plis->arg3.iLength = strlen(szTarget) + 1;
00327         plis->arg3.pData = new char[plis->arg3.iLength];
00328         memcpy(plis->arg3.pData, (LPVOID)&szTarget[0], plis->arg3.iLength);
00329       }
00330       break;
00331     }
00332     case action_npn_post_url_notify:
00333     {
00334       if(dw2 != 0L)
00335       {
00336         plis->arg2.iLength = strlen((LPSTR)dw2) + 1;
00337         plis->arg2.pData = new char[plis->arg2.iLength];
00338         memcpy(plis->arg2.pData, (LPVOID)dw2, plis->arg2.iLength);
00339       }
00340 
00341       if(dw3 != 0L)
00342       {
00343         makeAbbreviatedString(szTarget, sizeof(szTarget), dw3, strlen((LPSTR)dw3), iWrap);
00344         plis->arg3.iLength = strlen(szTarget) + 1;
00345         plis->arg3.pData = new char[plis->arg3.iLength];
00346         memcpy(plis->arg3.pData, (LPVOID)&szTarget[0], plis->arg3.iLength);
00347       }
00348 
00349       
00350          // strlen not protected from 0!
00351          makeAbbreviatedString(szBuf, sizeof(szBuf), dw5, strlen((LPSTR)dw5), iWrap);
00352       plis->arg5.iLength = (int)dw4 + 1;
00353       plis->arg5.pData = new char[plis->arg5.iLength];
00354       memcpy(plis->arg5.pData, (LPVOID)&szBuf[0], plis->arg5.iLength);
00355 
00356       break;
00357     }
00358     case action_npn_post_url:
00359     {
00360       if(dw2 != 0L)
00361       {
00362         plis->arg2.iLength = strlen((LPSTR)dw2) + 1;
00363         plis->arg2.pData = new char[plis->arg2.iLength];
00364         memcpy(plis->arg2.pData, (LPVOID)dw2, plis->arg2.iLength);
00365       }
00366 
00367       if(dw3 != 0L)
00368       {
00369         makeAbbreviatedString(szTarget, sizeof(szTarget), dw3, strlen((LPSTR)dw3), iWrap);
00370         plis->arg3.iLength = strlen(szTarget) + 1;
00371         plis->arg3.pData = new char[plis->arg3.iLength];
00372         memcpy(plis->arg3.pData, (LPVOID)&szTarget[0], plis->arg3.iLength);
00373       }
00374 
00375          // strlen not protected from 0!
00376       makeAbbreviatedString(szBuf, sizeof(szBuf), dw5, strlen((LPSTR)dw5), iWrap);
00377       plis->arg5.iLength = (int)dw4 + 1;
00378       plis->arg5.pData = new char[plis->arg5.iLength];
00379       memcpy(plis->arg5.pData, (LPVOID)&szBuf[0], plis->arg5.iLength);
00380 
00381       break;
00382     }
00383     case action_npn_new_stream:
00384     {
00385       if(dw2 != 0L)
00386       {
00387         plis->arg2.iLength = strlen((LPSTR)dw2) + 1;
00388         plis->arg2.pData = new char[plis->arg2.iLength];
00389         memcpy(plis->arg2.pData, (LPVOID)dw2, plis->arg2.iLength);
00390       }
00391 
00392          // strlen not protected from 0!
00393       makeAbbreviatedString(szTarget, sizeof(szTarget), dw3, strlen((LPSTR)dw3), iWrap);
00394       plis->arg3.iLength = strlen(szTarget) + 1;
00395       plis->arg3.pData = new char[plis->arg3.iLength];
00396       memcpy(plis->arg3.pData, (LPVOID)&szTarget[0], plis->arg3.iLength);
00397 
00398       plis->arg4.pData = new char[sizeof(DWORD)];
00399       plis->arg4.iLength = sizeof(DWORD);
00400       memcpy(plis->arg4.pData, (LPVOID)dw4, plis->arg4.iLength);
00401 
00402       break;
00403     }
00404     case action_npn_destroy_stream:
00405       break;
00406     case action_npn_request_read:
00407       break;
00408     case action_npn_write:
00409     {
00410          // strlen not protected from 0!
00411       makeAbbreviatedString(szBuf, sizeof(szBuf), dw4, strlen((LPSTR)dw4), iWrap);
00412       plis->arg4.iLength = strlen(szBuf) + 1;
00413       plis->arg4.pData = new char[plis->arg4.iLength];
00414       memcpy(plis->arg4.pData, (LPVOID)&szBuf[0], plis->arg4.iLength);
00415       break;
00416     }
00417     case action_npn_status:
00418       if(dw2 != 0L)
00419       {
00420         plis->arg2.iLength = strlen((LPSTR)dw2) + 1;
00421         plis->arg2.pData = new char[plis->arg2.iLength];
00422         memcpy(plis->arg2.pData, (LPVOID)dw2, plis->arg2.iLength);
00423       }
00424       break;
00425     case action_npn_user_agent:
00426       break;
00427     case action_npn_mem_alloc:
00428       break;
00429     case action_npn_mem_free:
00430       break;
00431     case action_npn_mem_flush:
00432       break;
00433     case action_npn_reload_plugins:
00434       break;
00435     case action_npn_get_java_env:
00436       break;
00437     case action_npn_get_java_peer:
00438       break;
00439     case action_npn_get_value:
00440       plis->arg3.iLength = sizeof(DWORD);
00441       plis->arg3.pData = new char[plis->arg3.iLength];
00442       memcpy(plis->arg3.pData, (LPVOID)dw3, plis->arg3.iLength);
00443       break;
00444     case action_npn_set_value:
00445       if(((NPPVariable)dw2 == NPPVpluginNameString) || 
00446          ((NPPVariable)dw2 == NPPVpluginDescriptionString))
00447       {
00448         // strlen not protected from 0!
00449         makeAbbreviatedString(szBuf, sizeof(szBuf), dw3, strlen((char *)dw3), iWrap);
00450         plis->arg3.iLength = strlen(szBuf) + 1;
00451         plis->arg3.pData = new char[plis->arg3.iLength];
00452         memcpy(plis->arg3.pData, (LPVOID)&szBuf[0], plis->arg3.iLength);
00453       }
00454       else if(((NPPVariable)dw2 == NPPVpluginWindowBool) || 
00455               ((NPPVariable)dw2 == NPPVpluginTransparentBool) ||
00456               ((NPPVariable)dw2 == NPPVpluginKeepLibraryInMemory))
00457       {
00458         plis->arg3.iLength = sizeof(NPBool);
00459         plis->arg3.pData = new char[plis->arg3.iLength];
00460         memcpy(plis->arg3.pData, (LPVOID)dw3, plis->arg3.iLength);
00461       }
00462       else if((NPPVariable)dw2 == NPPVpluginWindowSize)
00463       {
00464         plis->arg3.iLength = sizeof(NPSize);
00465         plis->arg3.pData = new char[plis->arg3.iLength];
00466         memcpy(plis->arg3.pData, (LPVOID)dw3, plis->arg3.iLength);
00467       }
00468       break;
00469     case action_npn_invalidate_rect:
00470     {
00471       plis->arg2.iLength = sizeof(NPRect);
00472       plis->arg2.pData = new char[plis->arg2.iLength];
00473       memcpy(plis->arg2.pData, (LPVOID)dw2, plis->arg2.iLength);
00474       break;
00475     }
00476     case action_npn_invalidate_region:
00477       break;
00478     case action_npn_force_redraw:
00479       break;
00480 
00481     // NPP action
00482     case action_np_initialize:
00483       break;
00484     case action_np_shutdown:
00485       break;
00486     case action_npp_new:
00487       // strlen not protected from 0!
00488       plis->arg1.iLength = strlen((LPSTR)dw1) + 1;
00489       plis->arg1.pData = new char[plis->arg1.iLength];
00490       memcpy(plis->arg1.pData, (LPVOID)dw1, plis->arg1.iLength);
00491       break;
00492     case action_npp_destroy:
00493       plis->arg2.iLength = sizeof(DWORD);
00494       plis->arg2.pData = new char[plis->arg2.iLength];
00495       memcpy(plis->arg2.pData, (LPVOID)dw2, plis->arg2.iLength);
00496       break;
00497     case action_npp_set_window:
00498       plis->arg2.iLength = sizeof(NPWindow);
00499       plis->arg2.pData = new char[plis->arg2.iLength];
00500       memcpy(plis->arg2.pData, (LPVOID)dw2, plis->arg2.iLength);
00501       break;
00502     case action_npp_new_stream:
00503       // strlen not protected from 0!
00504       plis->arg2.iLength = strlen((LPSTR)dw2) + 1;
00505       plis->arg2.pData = new char[plis->arg2.iLength];
00506       memcpy(plis->arg2.pData, (LPVOID)dw2, plis->arg2.iLength);
00507 
00508       plis->arg5.iLength = sizeof(uint16);
00509       plis->arg5.pData = new char[plis->arg5.iLength];
00510       memcpy(plis->arg5.pData, (LPVOID)dw5, plis->arg5.iLength);
00511       break;
00512     case action_npp_destroy_stream:
00513       break;
00514     case action_npp_stream_as_file:
00515     {
00516       // strlen not protected from 0!
00517       char* str = dw3 ? (char*)dw3 : (char*)"";
00518       plis->arg3.iLength = strlen(str) + 1;
00519       plis->arg3.pData = new char[plis->arg3.iLength];
00520       memcpy(plis->arg3.pData, (LPVOID)str, plis->arg3.iLength);
00521       break;
00522     }
00523     case action_npp_write_ready:
00524       break;
00525     case action_npp_write:
00526     {
00527       if(dw5 != 0L)
00528       {
00529         makeAbbreviatedString(szBuf, sizeof(szBuf), dw5, strlen((LPSTR)dw5), iWrap);
00530         plis->arg5.iLength = strlen(szBuf) + 1;
00531         plis->arg5.pData = new char[plis->arg5.iLength];
00532         memcpy(plis->arg5.pData, (LPVOID)&szBuf[0], plis->arg5.iLength);
00533       }
00534       break;
00535     }
00536     case action_npp_print:
00537       break;
00538     case action_npp_handle_event:
00539       break;
00540     case action_npp_url_notify:
00541       // strlen not protected from 0!
00542       plis->arg2.iLength = strlen((LPSTR)dw2) + 1;
00543       plis->arg2.pData = new char[plis->arg2.iLength];
00544       memcpy(plis->arg2.pData, (LPVOID)dw2, plis->arg2.iLength);
00545       break;
00546     case action_npp_get_java_class:
00547       break;
00548     case action_np_get_mime_description:
00549       break;
00550     case action_npp_get_value:
00551       break;
00552     case action_npp_set_value:
00553       break;
00554 
00555     default:
00556       break;
00557   }
00558 
00559   return plis;
00560 }
00561 
00562 int formatLogItem(LogItemStruct * plis, LPSTR szOutput, LPSTR szEndOfItem, BOOL bDOSStyle)
00563 {
00564   int iRet = 0;
00565   static char szTime[128];
00566   static char szString[1024];
00567   static char szEOL[8];
00568   static char szEOI[256];
00569   static char szRet[256];
00570 
00571   if(bDOSStyle)
00572   {
00573     strcpy(szEOL, "\r\n");
00574     strcpy(szEOI, szEndOfItem);
00575     strcat(szEOI, "\r\n");
00576   }
00577   else
00578   {
00579     strcpy(szEOL, "\n");
00580     strcpy(szEOI, szEndOfItem);
00581     strcat(szEOI, "\n");
00582   }
00583 
00584   szRet[0] = '\0';
00585   szOutput[0] = '\0';
00586 
00587   wsprintf(szTime, "Time: %lu %lu (%li)%s", 
00588                    plis->dwTimeEnter, plis->dwTimeReturn, 
00589                    (long)plis->dwTimeReturn - (long)plis->dwTimeEnter, szEOL);
00590 
00591   DWORD dw1 = plis->arg1.dwArg;
00592   DWORD dw2 = plis->arg2.dwArg;
00593   DWORD dw3 = plis->arg3.dwArg;
00594   DWORD dw4 = plis->arg4.dwArg;
00595   DWORD dw5 = plis->arg5.dwArg;
00596   DWORD dw6 = plis->arg6.dwArg;
00597   DWORD dw7 = plis->arg7.dwArg;
00598 
00599   char sz1[1024] = {'\0'};
00600   char sz2[1024] = {'\0'};
00601   char sz3[1024] = {'\0'};
00602   char sz4[1024] = {'\0'};
00603   char sz5[1024] = {'\0'};
00604   char sz6[1024] = {'\0'};
00605 
00606   switch (plis->action)
00607   {
00608     case action_invalid:
00609       break;
00610 
00611     // NPN action
00612     case action_npn_version:
00613       if((plis->arg1.pData != NULL)&&(plis->arg2.pData != NULL)&&(plis->arg3.pData != NULL)&&(plis->arg4.pData != NULL))
00614       {
00615         wsprintf(szRet, "Plugin %i.%i, Netscape %i.%i%s", 
00616                  *(int*)plis->arg1.pData, *(int*)plis->arg2.pData,
00617                  *(int*)plis->arg3.pData, *(int*)plis->arg4.pData,szEOL);
00618         wsprintf(szString, "NPN_Version(%#08lx, %#08lx, %#08lx, %#08lx)%s%s", dw1,dw2,dw3,dw4,szEOL,szRet);
00619       }
00620       else
00621         wsprintf(szString, "NPN_Version(%#08lx, %#08lx, %#08lx, %#08lx)%s", dw1,dw2,dw3,dw4,szEOL);
00622       break;
00623     case action_npn_get_url_notify:
00624     {
00625       FormatPCHARArgument(sz2, sizeof(sz2), &plis->arg2);
00626       FormatPCHARArgument(sz3, sizeof(sz3), &plis->arg3);
00627       wsprintf(szRet, "Returns: %s%s", FormatNPAPIError((int)plis->dwReturnValue),szEOL);
00628       wsprintf(szString, "NPN_GetURLNotify(%#08lx, %s, %s, %#08lx)%s%s", dw1,sz2,sz3,dw4,szEOL,szRet);
00629       break;
00630     }
00631     case action_npn_get_url:
00632     {
00633       FormatPCHARArgument(sz2, sizeof(sz2), &plis->arg2);
00634       FormatPCHARArgument(sz3, sizeof(sz3), &plis->arg3);
00635       wsprintf(szRet, "Returns: %s%s", FormatNPAPIError((int)plis->dwReturnValue),szEOL);
00636       wsprintf(szString, "NPN_GetURL(%#08lx, %s, %s)%s%s", dw1,sz2,sz3,szEOL,szRet);
00637       break;
00638     }
00639     case action_npn_post_url_notify:
00640     {
00641       FormatPCHARArgument(sz2, sizeof(sz2), &plis->arg2);
00642       FormatPCHARArgument(sz3, sizeof(sz3), &plis->arg3);
00643       FormatPCHARArgument(sz5, sizeof(sz5), &plis->arg5);
00644       FormatBOOLArgument(sz6, sizeof(sz6), &plis->arg6);
00645 
00646       wsprintf(szRet, "Returns: %s%s", FormatNPAPIError((int)plis->dwReturnValue),szEOL);
00647       wsprintf(szString, "NPN_PostURLNotify(%#08lx, %s, %s, %li, %s, %s, %#08lx)%s%s", 
00648                dw1,sz2,sz3,(uint32)dw4,sz5,sz6,dw7,szEOL,szRet);
00649       break;
00650     }
00651     case action_npn_post_url:
00652     {
00653       FormatPCHARArgument(sz2, sizeof(sz2), &plis->arg2);
00654       FormatPCHARArgument(sz3, sizeof(sz3), &plis->arg3);
00655       FormatPCHARArgument(sz5, sizeof(sz5), &plis->arg5);
00656       FormatBOOLArgument(sz6, sizeof(sz6), &plis->arg6);
00657 
00658       wsprintf(szRet, "Returns: %s%s", FormatNPAPIError((int)plis->dwReturnValue),szEOL);
00659       wsprintf(szString, "NPN_PostURL(%#08lx, %s, %s, %li, %s, %s)%s%s", 
00660                dw1,sz2,sz3,(uint32)dw4,sz5,sz6,szEOL,szRet);
00661       break;
00662     }
00663     case action_npn_new_stream:
00664     {
00665       FormatPCHARArgument(sz2, sizeof(sz2), &plis->arg2);
00666       FormatPCHARArgument(sz3, sizeof(sz3), &plis->arg3);
00667       wsprintf(szRet, "Returns: %s%s", FormatNPAPIError((int)plis->dwReturnValue),szEOL);
00668       if(plis->arg4.pData != NULL)
00669         wsprintf(szString, "NPN_NewStream(%#08lx, %s, %s, %#08lx(%#08lx))%s%s", 
00670                  dw1, sz2,sz3,dw4,*(DWORD *)plis->arg4.pData,szEOL,szRet);
00671       else
00672         wsprintf(szString, "NPN_NewStream(%#08lx, \"%s\", \"%s\", %#08lx)%s%s", dw1, sz2,sz3,dw4,szEOL,szRet);
00673       break;
00674     }
00675     case action_npn_destroy_stream:
00676       wsprintf(szRet, "Returns: %s%s", FormatNPAPIError((int)plis->dwReturnValue),szEOL);
00677       wsprintf(szString, "NPN_DestroyStream(%#08lx, %#08lx, %s)%s%s", dw1,dw2,FormatNPAPIReason((int)dw3),szEOL,szRet);
00678       break;
00679     case action_npn_request_read:
00680       wsprintf(szRet, "Returns: %s%s", FormatNPAPIError((int)plis->dwReturnValue),szEOL);
00681       wsprintf(szString, "NPN_RequestRead(%#08lx, %#08lx)%s%s", dw1, dw2, szEOL, szRet);
00682       break;
00683     case action_npn_write:
00684     {
00685       FormatPCHARArgument(sz4, sizeof(sz4), &plis->arg4);
00686       wsprintf(szRet, "Returns: %li%s", plis->dwReturnValue,szEOL);
00687       wsprintf(szString, "NPN_Write(%#08lx, %#08lx, %li, %s)%s%s", dw1, dw2, (int32)dw3, sz4, szEOL, szRet);
00688       break;
00689     }
00690     case action_npn_status:
00691     {
00692       FormatPCHARArgument(sz2, sizeof(sz2), &plis->arg2);
00693       wsprintf(szString, "NPN_Status(%#08lx, %s)%s", dw1, sz2, szEOL);
00694       break;
00695     }
00696     case action_npn_user_agent:
00697       wsprintf(szRet, "Returns: %#08lx(\"%s\")%s", plis->dwReturnValue, (LPSTR)plis->dwReturnValue,szEOL);
00698       wsprintf(szString, "NPN_UserAgent(%#08lx)%s%s", dw1, szEOL, szRet);
00699       break;
00700     case action_npn_mem_alloc:
00701       wsprintf(szRet, "Returns: %#08lx%s", plis->dwReturnValue, szEOL);
00702       wsprintf(szString, "NPN_MemAlloc(%li)%s%s", dw1, szEOL, szRet);
00703       break;
00704     case action_npn_mem_free:
00705       wsprintf(szString, "NPN_MemFree(%#08lx)%s", dw1,szEOL);
00706       break;
00707     case action_npn_mem_flush:
00708       wsprintf(szRet, "Returns: %li%s", plis->dwReturnValue,szEOL);
00709       wsprintf(szString, "NPN_MemFlush(%li)%s%s", dw1, szEOL, szRet);
00710       break;
00711     case action_npn_reload_plugins:
00712     {
00713       FormatBOOLArgument(sz1, sizeof(sz1), &plis->arg1);
00714       wsprintf(szString, "NPN_ReloadPlugins(%s)%s", sz1,szEOL);
00715       break;
00716     }
00717     case action_npn_get_java_env:
00718       wsprintf(szRet, "Returns: %#08lx%s", plis->dwReturnValue,szEOL);
00719       wsprintf(szString, "NPN_GetJavaEnv()%s%s", szEOL, szRet);
00720       break;
00721     case action_npn_get_java_peer:
00722       wsprintf(szRet, "Returns: %#08lx%s", plis->dwReturnValue,szEOL);
00723       wsprintf(szString, "NPN_GetJavaPeer(%#08lx)%s%s", dw1, szEOL, szRet);
00724       break;
00725     case action_npn_get_value:
00726     {
00727       wsprintf(szRet, "Returns: %s%s", FormatNPAPIError((int)plis->dwReturnValue),szEOL);
00728       switch(dw2)
00729       {
00730         case NPNVxDisplay:
00731         case NPNVxtAppContext:
00732         case NPNVnetscapeWindow:
00733           if(dw3 != 0L)
00734             wsprintf(szString, "NPN_GetValue(%#08lx, %s, %#08lx(%#08lx))%s%s",dw1,FormatNPNVariable((NPNVariable)dw2),dw3,*(DWORD *)dw3,szEOL,szRet);
00735           else
00736             wsprintf(szString, "NPN_GetValue(%#08lx, %s, %#08lx)%s%s",dw1,FormatNPNVariable((NPNVariable)dw2),dw3,szEOL,szRet);
00737           break;
00738         case NPNVjavascriptEnabledBool:
00739         case NPNVasdEnabledBool:
00740         case NPNVisOfflineBool:
00741           if(dw3 != 0L)
00742             wsprintf(szString, "NPN_GetValue(%#08lx, %s, %#08lx(%s))%s%s",
00743                      dw1,FormatNPNVariable((NPNVariable)dw2),dw3,
00744                      (((NPBool)*(DWORD *)dw3) == TRUE) ? "TRUE" : "FALSE", szEOL, szRet);
00745           else
00746             wsprintf(szString, "NPN_GetValue(%#08lx, %s, %#08lx)%s%s",dw1,FormatNPNVariable((NPNVariable)dw2),dw3,szEOL,szRet);
00747           break;
00748         default:
00749           wsprintf(szRet, "Returns: %s%s", FormatNPAPIError((int)plis->dwReturnValue),szEOL);
00750           break;
00751       }
00752       break;
00753     }
00754     case action_npn_set_value:
00755       wsprintf(szRet, "Returns: %s%s", FormatNPAPIError((int)plis->dwReturnValue),szEOL);
00756 
00757       if(((NPPVariable)dw2 == NPPVpluginNameString) || 
00758          ((NPPVariable)dw2 == NPPVpluginDescriptionString))
00759       {
00760         FormatPCHARArgument(sz3, sizeof(sz3), &plis->arg3);
00761         wsprintf(szString, "NPN_SetValue(%#08lx, %s, %s)%s%s", dw1,FormatNPPVariable((NPPVariable)dw2),sz3,szEOL,szRet);
00762       }
00763       else if(((NPPVariable)dw2 == NPPVpluginWindowBool) || 
00764               ((NPPVariable)dw2 == NPPVpluginTransparentBool) ||
00765               ((NPPVariable)dw2 == NPPVpluginKeepLibraryInMemory))
00766       {
00767         FormatPBOOLArgument(sz3, sizeof(sz3), &plis->arg3);
00768         wsprintf(szString, "NPN_SetValue(%#08lx, %s, %s)%s%s", 
00769                  dw1,FormatNPPVariable((NPPVariable)dw2),sz3,szEOL,szRet);
00770       }
00771       else if((NPPVariable)dw2 == NPPVpluginWindowSize)
00772       {
00773         if(plis->arg3.pData != NULL)
00774         {
00775           int32 iWidth = ((NPSize *)plis->arg3.pData)->width;
00776           int32 iHeight = ((NPSize *)plis->arg3.pData)->height;
00777           wsprintf(szString, "NPN_SetValue(%#08lx, %s, %#08lx(%li,%li))%s%s", 
00778                    dw1,FormatNPPVariable((NPPVariable)dw2),dw3,iWidth,iHeight,szEOL,szRet);
00779         }
00780         else
00781           wsprintf(szString, "NPN_SetValue(%#08lx, %s, %#08lx(?,?))%s%s", 
00782                    dw1,FormatNPPVariable((NPPVariable)dw2),dw3,szEOL,szRet);
00783       }
00784       else
00785         wsprintf(szString, "NPN_SetValue(%#08lx, %s, %#08lx(What is it?))%s%s", dw1,FormatNPPVariable((NPPVariable)dw2),dw3,szEOL,szRet);
00786       break;
00787     case action_npn_invalidate_rect:
00788     {
00789       if(plis->arg2.pData != NULL)
00790       {
00791         uint16 top    = ((NPRect *)plis->arg2.pData)->top;
00792         uint16 left   = ((NPRect *)plis->arg2.pData)->left;
00793         uint16 bottom = ((NPRect *)plis->arg2.pData)->bottom;
00794         uint16 right  = ((NPRect *)plis->arg2.pData)->right;
00795         wsprintf(szString, "NPN_InvalidateRect(%#08lx, %#08lx(%u,%u;%u,%u)%s", dw1,dw2,top,left,bottom,right,szEOL);
00796       }
00797       else
00798         wsprintf(szString, "NPN_InvalidateRect(%#08lx, %#08lx(?,?,?,?)%s", dw1,dw2,szEOL);
00799       break;
00800     }
00801     case action_npn_invalidate_region:
00802       wsprintf(szString, "NPN_InvalidateRegion(%#08lx, %#08lx)%s", dw1,dw2,szEOL);
00803       break;
00804     case action_npn_force_redraw:
00805       wsprintf(szString, "NPN_ForceRedraw(%#08lx)%s", dw1,szEOL);
00806       break;
00807 
00808     // NPP action
00809     case action_np_initialize:
00810       wsprintf(szRet, "Returning: %s%s", FormatNPAPIError((int)plis->dwReturnValue),szEOL);
00811       wsprintf(szString, "Global initialization%s%s", szEOL, szRet);
00812       break;
00813     case action_np_shutdown:
00814       wsprintf(szString, "Global shutdown%s",szEOL);
00815       break;
00816     case action_npp_new:
00817     {
00818       wsprintf(szRet, "Returning: %s%s", FormatNPAPIError((int)plis->dwReturnValue),szEOL);
00819       char szMode[16];
00820       switch (dw3)
00821       {
00822         case NP_EMBED:
00823           strcpy(szMode, "NP_EMBED");
00824           break;
00825         case NP_FULL:
00826           strcpy(szMode, "NP_FULL");
00827           break;
00828         default:
00829           strcpy(szMode, "[Invalide mode]");
00830           break;
00831       }
00832       char szArgs[512] = "\0";
00833       int count = (int)dw4;
00834       char** names = (char **)dw5;
00835       char** values = (char **)dw6;
00836       if ((count > 0) && names && values) {
00837         wsprintf(szArgs, "\tArgument arrays:%s", szEOL);
00838         for (int i = 0; i < count; i++) {
00839           strcat(szArgs, "\t\t");
00840           strcat(szArgs, names[i]);
00841           strcat(szArgs, " -- ");
00842           strcat(szArgs, values[i]);
00843           strcat(szArgs, szEOL);
00844         }
00845       }
00846       wsprintf(szString, "NPP_New(\"%s\", %#08lx, %s, %i, %#08lx, %#08lx, %#08lx)%s%s%s", 
00847                (LPSTR)dw1,dw2,szMode,(int)dw4,dw5,dw6,dw7,szEOL,szArgs,szRet);
00848       break;
00849     }
00850     case action_npp_destroy:
00851       wsprintf(szRet, "Returning: %s%s", FormatNPAPIError((int)plis->dwReturnValue),szEOL);
00852       wsprintf(szString, "NPP_Destroy(%#08lx, %#08lx(%#08lx))%s%s", dw1, dw2, *(DWORD *)plis->arg2.pData,szEOL,szRet);
00853       break;
00854     case action_npp_set_window:
00855     {
00856       wsprintf(szRet, "Returning: %s%s", FormatNPAPIError((int)plis->dwReturnValue),szEOL);
00857       char szWindow[512];
00858 
00859       if(plis->arg2.pData != NULL)
00860       {
00861         char szType[80];
00862         switch (((NPWindow*)plis->arg2.pData)->type)
00863         {
00864           case NPWindowTypeWindow:
00865             wsprintf(szType, "NPWindowTypeWindow");
00866             break;
00867           case NPWindowTypeDrawable:
00868             wsprintf(szType, "NPWindowTypeDrawable");
00869             break;
00870           default:
00871             wsprintf(szType, "[Unlisted type]");
00872             break;
00873         }
00874         wsprintf(szWindow, "NPWindow: %#08lx, (%li,%li), (%li,%li), (%i,%i,%i,%i), %s", 
00875                  ((NPWindow*)plis->arg2.pData)->window, 
00876                  ((NPWindow*)plis->arg2.pData)->x, 
00877                  ((NPWindow*)plis->arg2.pData)->y, 
00878                  ((NPWindow*)plis->arg2.pData)->width, 
00879                  ((NPWindow*)plis->arg2.pData)->height, 
00880                  ((NPWindow*)plis->arg2.pData)->clipRect.top, 
00881                  ((NPWindow*)plis->arg2.pData)->clipRect.left, 
00882                  ((NPWindow*)plis->arg2.pData)->clipRect.bottom, 
00883                  ((NPWindow*)plis->arg2.pData)->clipRect.right, szType);
00884         wsprintf(szString, "NPP_SetWindow(%#08lx, %#08lx)%s%s%s%s", dw1,dw2,szEOL,szWindow,szEOL,szRet);
00885       }
00886       else
00887         wsprintf(szString, "NPP_SetWindow(%#08lx, %#08lx)%s%s", dw1,dw2,szEOL,szRet);
00888 
00889       break;
00890     }
00891     case action_npp_new_stream:
00892     {
00893       switch (*(int16 *)plis->arg5.pData)
00894       {
00895         case NP_NORMAL:
00896           wsprintf(sz5, "NP_NORMAL");
00897           break;
00898         case NP_ASFILEONLY:
00899           wsprintf(sz5, "NP_ASFILEONLY");
00900           break;
00901         case NP_ASFILE:
00902           wsprintf(sz5, "NP_ASFILE");
00903           break;
00904         default:
00905           wsprintf(sz5, "[Unlisted type]");
00906           break;
00907       }
00908       wsprintf(szRet, "Returning: %s%s", FormatNPAPIError((int)plis->dwReturnValue),szEOL);
00909       FormatPCHARArgument(sz2, sizeof(sz2), &plis->arg2);
00910       wsprintf(szString, "NPP_NewStream(%#08lx, %s, %#08lx, %s, %s)%s%s", dw1, sz2, dw3, 
00911                ((NPBool)dw4 == TRUE) ? "TRUE" : "FALSE", sz5, szEOL, szRet);
00912       break;
00913     }
00914     case action_npp_destroy_stream:
00915       wsprintf(szRet, "Returning: %s%s", FormatNPAPIError((int)plis->dwReturnValue),szEOL);
00916       wsprintf(szString, "NPP_DestroyStream(%#08lx, %#08lx, %s)%s%s", dw1,dw2,FormatNPAPIReason((int)dw3),szEOL,szRet);
00917       break;
00918     case action_npp_stream_as_file:
00919       FormatPCHARArgument(sz3, sizeof(sz3), &plis->arg3);
00920       wsprintf(szString, "NPP_StreamAsFile(%#08lx, %#08lx, %s)%s", dw1,dw2,sz3,szEOL);
00921       break;
00922     case action_npp_write_ready:
00923       wsprintf(szRet, "Returning: %li%s", plis->dwReturnValue,szEOL);
00924       wsprintf(szString, "NPP_WriteReady(%#08lx, %#08lx)%s%s", dw1,dw2,szEOL,szRet);
00925       break;
00926     case action_npp_write:
00927     {
00928       wsprintf(szRet, "Returning: %li%s", plis->dwReturnValue,szEOL);
00929       FormatPCHARArgument(sz5, sizeof(sz5), &plis->arg5);
00930       wsprintf(szString, "NPP_Write(%#08lx, %#08lx, %li, %li, %s))%s%s",dw1,dw2,dw3,dw4,sz5,szEOL,szRet);
00931       break;
00932     }
00933     case action_npp_print:
00934       wsprintf(szString, "NPP_Print(%#08lx, %#08lx)%s", dw1, dw2,szEOL);
00935       break;
00936     case action_npp_handle_event:
00937       wsprintf(szRet, "Returning: %i%s", (int16)plis->dwReturnValue,szEOL);
00938       wsprintf(szString, "NPP_HandleEvent(%#08lx, %#08lx)%s%s", dw1,dw2,szEOL,szRet);
00939       break;
00940     case action_npp_url_notify:
00941     {
00942       FormatPCHARArgument(sz2, sizeof(sz2), &plis->arg2);
00943       wsprintf(szString, "NPP_URLNotify(%#08lx, %s, %s, %#08lx)%s", dw1,sz2,FormatNPAPIReason((int)dw3),dw4,szEOL);
00944       break;
00945     }
00946     case action_npp_get_java_class:
00947       wsprintf(szRet, "Returning: %#08lx%s", plis->dwReturnValue,szEOL);
00948       wsprintf(szString, "NPP_GetJavaClass()%s%s",szEOL,szRet);
00949       break;
00950     case action_np_get_mime_description:
00951       wsprintf(szRet, "Returning: %#08lx%s", plis->dwReturnValue,szEOL);
00952       wsprintf(szString, "NPP_GetMIMEDescription()%s%s",szEOL,szRet);
00953       break;
00954     case action_npp_get_value:
00955       wsprintf(szRet, "Returning: %s%s", FormatNPAPIError((int)plis->dwReturnValue),szEOL);
00956       wsprintf(szString, "NPP_GetValue(%#08lx, %s, %#08lx)%s%s", dw1,FormatNPPVariable((NPPVariable)dw2),dw3,szEOL,szRet);
00957       break;
00958     case action_npp_set_value:
00959       wsprintf(szRet, "Returning: %s%s", FormatNPAPIError((int)plis->dwReturnValue),szEOL);
00960       wsprintf(szString, "NPP_SetValue(%#08lx, %s, %#08lx)%s%s", dw1,FormatNPNVariable((NPNVariable)dw2),dw3,szEOL,szRet);
00961       break;
00962 
00963     default:
00964       wsprintf(szString, "Unknown action%s",szEOL);
00965       break;
00966   }
00967   strcat(szOutput, szString);
00968   strcat(szOutput, szTime);
00969   strcat(szOutput, szEOI);
00970   iRet = strlen(szString) + strlen(szTime) + strlen(szEOI);
00971   return iRet;
00972 }