Back to index

lightning-sunbird  0.9+nobinonly
format.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 "format.h"
00041 #include "logger.h"
00042 
00043 extern Logger * logger;
00044 
00045 char * FormatNPAPIError(int iError)
00046 {
00047   static char szError[64];
00048   switch (iError)
00049   {
00050     case NPERR_NO_ERROR:
00051       sprintf(szError, "NPERR_NO_ERROR");
00052       break;
00053     case NPERR_GENERIC_ERROR:
00054       sprintf(szError, "NPERR_GENERIC_ERROR");
00055       break;
00056     case NPERR_INVALID_INSTANCE_ERROR:
00057       sprintf(szError, "NPERR_INVALID_INSTANCE_ERROR");
00058       break;
00059     case NPERR_INVALID_FUNCTABLE_ERROR:
00060       sprintf(szError, "NPERR_INVALID_FUNCTABLE_ERROR");
00061       break;
00062     case NPERR_MODULE_LOAD_FAILED_ERROR:
00063       sprintf(szError, "NPERR_MODULE_LOAD_FAILED_ERROR");
00064       break;
00065     case NPERR_OUT_OF_MEMORY_ERROR:
00066       sprintf(szError, "NPERR_OUT_OF_MEMORY_ERROR");
00067       break;
00068     case NPERR_INVALID_PLUGIN_ERROR:
00069       sprintf(szError, "NPERR_INVALID_PLUGIN_ERROR");
00070       break;
00071     case NPERR_INVALID_PLUGIN_DIR_ERROR:
00072       sprintf(szError, "NPERR_INVALID_PLUGIN_DIR_ERROR");
00073       break;
00074     case NPERR_INCOMPATIBLE_VERSION_ERROR:
00075       sprintf(szError, "NPERR_INCOMPATIBLE_VERSION_ERROR");
00076       break;
00077     case NPERR_INVALID_PARAM:
00078       sprintf(szError, "NPERR_INVALID_PARAM");
00079       break;
00080     case NPERR_INVALID_URL:
00081       sprintf(szError, "NPERR_INVALID_URL");
00082       break;
00083     case NPERR_FILE_NOT_FOUND:
00084       sprintf(szError, "NPERR_FILE_NOT_FOUND");
00085       break;
00086     case NPERR_NO_DATA:
00087       sprintf(szError, "NPERR_NO_DATA");
00088       break;
00089     case NPERR_STREAM_NOT_SEEKABLE:
00090       sprintf(szError, "NPERR_STREAM_NOT_SEEKABLE");
00091       break;
00092     default:
00093       sprintf(szError, "Unlisted error");
00094       break;
00095   }
00096   return &szError[0];
00097 }
00098 
00099 char * FormatNPAPIReason(int iReason)
00100 {
00101   static char szReason[64];
00102   switch (iReason)
00103   {
00104     case NPRES_DONE:
00105       sprintf(szReason, "NPRES_DONE");
00106       break;
00107     case NPRES_NETWORK_ERR:
00108       sprintf(szReason, "NPRES_NETWORK_ERR");
00109       break;
00110     case NPRES_USER_BREAK:
00111       sprintf(szReason, "NPRES_USER_BREAK");
00112       break;
00113     default:
00114       sprintf(szReason, "Unlisted reason");
00115       break;
00116   }
00117   return &szReason[0];
00118 }
00119 
00120 char * FormatNPNVariable(NPNVariable var)
00121 {
00122   static char szVar[80];
00123   switch (var)
00124   {
00125     case NPNVxDisplay:
00126       sprintf(szVar, "%i -- NPNVxDisplay", var);
00127       break;
00128     case NPNVxtAppContext:
00129       sprintf(szVar, "%i -- NPNVxtAppContext", var);
00130       break;
00131     case NPNVnetscapeWindow:
00132       sprintf(szVar, "%i -- NPNVnetscapeWindow", var);
00133       break;
00134     case NPNVjavascriptEnabledBool:
00135       sprintf(szVar, "%i -- NPNVjavascriptEnabledBool", var);
00136       break;
00137     case NPNVasdEnabledBool:
00138       sprintf(szVar, "%i -- NPNVasdEnabledBool", var);
00139       break;
00140     case NPNVisOfflineBool:
00141       sprintf(szVar, "%i -- NPNVisOfflineBool", var);
00142       break;
00143     default:
00144       sprintf(szVar, "%i -- Unlisted variable", var);
00145       break;
00146   }
00147   return &szVar[0];
00148 }
00149 
00150 char * FormatNPPVariable(NPPVariable var)
00151 {
00152   static char szVar[80];
00153   switch (var)
00154   {
00155     case NPPVpluginNameString:
00156       sprintf(szVar, "%i -- NPPVpluginNameString", var);
00157       break;
00158     case NPPVpluginDescriptionString:
00159       sprintf(szVar, "%i -- NPPVpluginDescriptionString?", var);
00160       break;
00161     case NPPVpluginWindowBool:
00162       sprintf(szVar, "%i -- NPPVpluginWindowBool?", var);
00163       break;
00164     case NPPVpluginTransparentBool:
00165       sprintf(szVar, "%i -- NPPVpluginTransparentBool?", var);
00166       break;
00167     case NPPVjavaClass:
00168       sprintf(szVar, "%i -- NPPVjavaClass?", var);
00169       break;
00170     case NPPVpluginWindowSize:
00171       sprintf(szVar, "%i -- NPPVpluginWindowSize?", var);
00172       break;
00173     case NPPVpluginTimerInterval:
00174       sprintf(szVar, "%i -- NPPVpluginTimerInterval?", var);
00175       break;
00176     case NPPVpluginScriptableInstance:
00177       sprintf(szVar, "%i -- NPPVpluginScriptableInstance?", var);
00178       break;
00179     case NPPVpluginScriptableIID:
00180       sprintf(szVar, "%i -- NPPVpluginScriptableIID?", var);
00181       break;
00182     default:
00183       sprintf(szVar, "%i -- Unlisted variable?", var);
00184       break;
00185   }
00186   return &szVar[0];
00187 }
00188 
00189 BOOL FormatPCHARArgument(char * szBuf, int iLength, LogArgumentStruct * parg)
00190 {
00191   if(iLength <= parg->iLength)
00192     return FALSE;
00193 
00194   if(parg->pData == NULL)
00195     sprintf(szBuf, "%#08lx", parg->dwArg);
00196   else
00197     sprintf(szBuf, "%#08lx(\"%s\")", parg->dwArg, (char *)parg->pData);
00198   return TRUE;
00199 }
00200 
00201 BOOL FormatBOOLArgument(char * szBuf, int iLength, LogArgumentStruct * parg)
00202 {
00203   if(iLength <= 8)
00204     return FALSE;
00205 
00206   sprintf(szBuf, "%s", ((NPBool)parg->dwArg == TRUE) ? "TRUE" : "FALSE");
00207   return TRUE;
00208 }
00209 
00210 BOOL FormatPBOOLArgument(char * szBuf, int iLength, LogArgumentStruct * parg)
00211 {
00212   if(iLength <= 8)
00213     return FALSE;
00214 
00215   sprintf(szBuf, "%#08lx(%s)", parg->dwArg, (*((NPBool *)parg->pData) == TRUE) ? "TRUE" : "FALSE");
00216   return TRUE;
00217 }
00218 
00219 static void makeAbbreviatedString(char * szBuf, int iSize, DWORD dwArg, int iLength, int iWrap)
00220 {
00221   if(dwArg == 0L)
00222   {
00223     szBuf[0] = '\0';
00224     return;
00225   }
00226 
00227   if(iLength > iWrap)
00228   {
00229     int iRealWrap = (iSize > iWrap) ? iWrap : (iSize - 4);
00230     memcpy((LPVOID)&szBuf[0], (LPVOID)dwArg, iRealWrap);
00231     szBuf[iRealWrap]     = '.';
00232     szBuf[iRealWrap + 1] = '.';
00233     szBuf[iRealWrap + 2] = '.';
00234     szBuf[iRealWrap + 3] = '\0';
00235   }
00236   else
00237   {
00238     if(iLength >= iSize)
00239     {    
00240       memcpy((LPVOID)&szBuf[0], (LPVOID)dwArg, iSize - 4);
00241       szBuf[iSize]     = '.';
00242       szBuf[iSize + 1] = '.';
00243       szBuf[iSize + 2] = '.';
00244       szBuf[iSize + 3] = '\0';
00245     }
00246     else
00247     {
00248       memcpy((LPVOID)&szBuf[0], (LPVOID)dwArg, iLength);
00249       szBuf[iLength] = '\0';
00250     }
00251   }
00252 }
00253 
00254 LogItemStruct * makeLogItemStruct(NPAPI_Action action, 
00255                                   DWORD dw1, DWORD dw2, DWORD dw3, DWORD dw4, 
00256                                   DWORD dw5, DWORD dw6, DWORD dw7, BOOL bShort)
00257 {
00258   int iWrap = 10;
00259 
00260   LogItemStruct * plis = new LogItemStruct;
00261   if(plis == NULL)
00262     return NULL;
00263 
00264   plis->action = action;
00265   plis->arg1.dwArg = dw1;
00266   plis->arg2.dwArg = dw2;
00267   plis->arg3.dwArg = dw3;
00268   plis->arg4.dwArg = dw4;
00269   plis->arg5.dwArg = dw5;
00270   plis->arg6.dwArg = dw6;
00271   plis->arg7.dwArg = dw7;
00272 
00273   char szTarget[1024] = {'\0'};
00274   char szBuf[1024] = {'\0'};
00275 
00276   if(bShort)
00277     return plis;
00278 
00279   switch (action)
00280   {
00281     case action_invalid:
00282       break;
00283 
00284     // NPN action
00285     case action_npn_version:
00286       plis->arg1.pData = new int[1];
00287       *(int*)(plis->arg1.pData) = *((int*)dw1);
00288       plis->arg1.iLength = sizeof(int);
00289 
00290       plis->arg2.pData = new int[1];
00291       *(int*)(plis->arg2.pData) = *((int*)dw2);
00292       plis->arg2.iLength = sizeof(int);
00293 
00294       plis->arg3.pData = new int[1];
00295       *(int*)(plis->arg3.pData) = *((int*)dw3);
00296       plis->arg3.iLength = sizeof(int);
00297 
00298       plis->arg4.pData = new int[1];
00299       *(int*)(plis->arg4.pData) = *((int*)dw4);
00300       plis->arg4.iLength = sizeof(int);
00301 
00302       break;
00303     case action_npn_get_url_notify:
00304       if(dw2 != 0L)
00305       {
00306         plis->arg2.iLength = strlen((char *)dw2) + 1;
00307         plis->arg2.pData = new char[plis->arg2.iLength];
00308         memcpy(plis->arg2.pData, (LPVOID)dw2, plis->arg2.iLength);
00309       }
00310 
00311       if(dw3 != 0L)
00312       {
00313         makeAbbreviatedString(szTarget, sizeof(szTarget), dw3, strlen((char *)dw3), iWrap);
00314         plis->arg3.iLength = strlen(szTarget) + 1;
00315         plis->arg3.pData = new char[plis->arg3.iLength];
00316         memcpy(plis->arg3.pData, (LPVOID)&szTarget[0], plis->arg3.iLength);
00317       }
00318       break;
00319     case action_npn_get_url:
00320     {
00321       if(dw2 != 0L)
00322       {
00323         plis->arg2.iLength = strlen((char *)dw2) + 1;
00324         plis->arg2.pData = new char[plis->arg2.iLength];
00325         memcpy(plis->arg2.pData, (LPVOID)dw2, plis->arg2.iLength);
00326       }
00327 
00328       if(dw3 != 0L)
00329       {
00330         makeAbbreviatedString(szTarget, sizeof(szTarget), dw3, strlen((char *)dw3), iWrap);
00331         plis->arg3.iLength = strlen(szTarget) + 1;
00332         plis->arg3.pData = new char[plis->arg3.iLength];
00333         memcpy(plis->arg3.pData, (LPVOID)&szTarget[0], plis->arg3.iLength);
00334       }
00335       break;
00336     }
00337     case action_npn_post_url_notify:
00338     {
00339       if(dw2 != 0L)
00340       {
00341         plis->arg2.iLength = strlen((char *)dw2) + 1;
00342         plis->arg2.pData = new char[plis->arg2.iLength];
00343         memcpy(plis->arg2.pData, (LPVOID)dw2, plis->arg2.iLength);
00344       }
00345 
00346       if(dw3 != 0L)
00347       {
00348         makeAbbreviatedString(szTarget, sizeof(szTarget), dw3, strlen((char *)dw3), iWrap);
00349         plis->arg3.iLength = strlen(szTarget) + 1;
00350         plis->arg3.pData = new char[plis->arg3.iLength];
00351         memcpy(plis->arg3.pData, (LPVOID)&szTarget[0], plis->arg3.iLength);
00352       }
00353 
00354       makeAbbreviatedString(szBuf, sizeof(szBuf), dw5, strlen((char *)dw5), iWrap);
00355       plis->arg5.iLength = (int)dw4 + 1;
00356       plis->arg5.pData = new char[plis->arg5.iLength];
00357       memcpy(plis->arg5.pData, (LPVOID)&szBuf[0], plis->arg5.iLength);
00358 
00359       break;
00360     }
00361     case action_npn_post_url:
00362     {
00363       if(dw2 != 0L)
00364       {
00365         plis->arg2.iLength = strlen((char *)dw2) + 1;
00366         plis->arg2.pData = new char[plis->arg2.iLength];
00367         memcpy(plis->arg2.pData, (LPVOID)dw2, plis->arg2.iLength);
00368       }
00369 
00370       if(dw3 != 0L)
00371       {
00372         makeAbbreviatedString(szTarget, sizeof(szTarget), dw3, strlen((char *)dw3), iWrap);
00373         plis->arg3.iLength = strlen(szTarget) + 1;
00374         plis->arg3.pData = new char[plis->arg3.iLength];
00375         memcpy(plis->arg3.pData, (LPVOID)&szTarget[0], plis->arg3.iLength);
00376       }
00377 
00378       makeAbbreviatedString(szBuf, sizeof(szBuf), dw5, strlen((char *)dw5), iWrap);
00379       plis->arg5.iLength = (int)dw4 + 1;
00380       plis->arg5.pData = new char[plis->arg5.iLength];
00381       memcpy(plis->arg5.pData, (LPVOID)&szBuf[0], plis->arg5.iLength);
00382 
00383       break;
00384     }
00385     case action_npn_new_stream:
00386     {
00387       if(dw2 != 0L)
00388       {
00389         plis->arg2.iLength = strlen((char *)dw2) + 1;
00390         plis->arg2.pData = new char[plis->arg2.iLength];
00391         memcpy(plis->arg2.pData, (LPVOID)dw2, plis->arg2.iLength);
00392       }
00393 
00394       makeAbbreviatedString(szTarget, sizeof(szTarget), dw3, strlen((char *)dw3), iWrap);
00395       plis->arg3.iLength = strlen(szTarget) + 1;
00396       plis->arg3.pData = new char[plis->arg3.iLength];
00397       memcpy(plis->arg3.pData, (LPVOID)&szTarget[0], plis->arg3.iLength);
00398 
00399       plis->arg4.pData = new char[sizeof(DWORD)];
00400       plis->arg4.iLength = sizeof(DWORD);
00401       memcpy(plis->arg4.pData, (LPVOID)dw4, plis->arg4.iLength);
00402 
00403       break;
00404     }
00405     case action_npn_destroy_stream:
00406       break;
00407     case action_npn_request_read:
00408       break;
00409     case action_npn_write:
00410     {
00411       makeAbbreviatedString(szBuf, sizeof(szBuf), dw4, strlen((char *)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((char *)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) || ((NPPVariable)dw2 == NPPVpluginDescriptionString))
00446       {
00447         makeAbbreviatedString(szBuf, sizeof(szBuf), dw3, strlen((char *)dw3), iWrap);
00448         plis->arg3.iLength = strlen(szBuf) + 1;
00449         plis->arg3.pData = new char[plis->arg3.iLength];
00450         memcpy(plis->arg3.pData, (LPVOID)&szBuf[0], plis->arg3.iLength);
00451       }
00452       else if(((NPPVariable)dw2 == NPPVpluginWindowBool) || ((NPPVariable)dw2 == NPPVpluginTransparentBool))
00453       {
00454         plis->arg3.iLength = sizeof(NPBool);
00455         plis->arg3.pData = new char[plis->arg3.iLength];
00456         memcpy(plis->arg3.pData, (LPVOID)dw3, plis->arg3.iLength);
00457       }
00458       else if((NPPVariable)dw2 == NPPVpluginWindowSize)
00459       {
00460         plis->arg3.iLength = sizeof(NPSize);
00461         plis->arg3.pData = new char[plis->arg3.iLength];
00462         memcpy(plis->arg3.pData, (LPVOID)dw3, plis->arg3.iLength);
00463       }
00464       break;
00465     case action_npn_invalidate_rect:
00466     {
00467       plis->arg2.iLength = sizeof(NPRect);
00468       plis->arg2.pData = new char[plis->arg2.iLength];
00469       memcpy(plis->arg2.pData, (LPVOID)dw2, plis->arg2.iLength);
00470       break;
00471     }
00472     case action_npn_invalidate_region:
00473       break;
00474     case action_npn_force_redraw:
00475       break;
00476 
00477     // NPP action
00478     case action_npp_new:
00479       plis->arg1.iLength = strlen((char *)dw1) + 1;
00480       plis->arg1.pData = new char[plis->arg1.iLength];
00481       memcpy(plis->arg1.pData, (LPVOID)dw1, plis->arg1.iLength);
00482       break;
00483     case action_npp_destroy:
00484       plis->arg2.iLength = sizeof(DWORD);
00485       plis->arg2.pData = new char[plis->arg2.iLength];
00486       memcpy(plis->arg2.pData, (LPVOID)dw2, plis->arg2.iLength);
00487       break;
00488     case action_npp_set_window:
00489       plis->arg2.iLength = sizeof(NPWindow);
00490       plis->arg2.pData = new char[plis->arg2.iLength];
00491       memcpy(plis->arg2.pData, (LPVOID)dw2, plis->arg2.iLength);
00492       break;
00493     case action_npp_new_stream:
00494       plis->arg2.iLength = strlen((char *)dw2) + 1;
00495       plis->arg2.pData = new char[plis->arg2.iLength];
00496       memcpy(plis->arg2.pData, (LPVOID)dw2, plis->arg2.iLength);
00497 
00498       plis->arg5.iLength = sizeof(uint16);
00499       plis->arg5.pData = new char[plis->arg5.iLength];
00500       memcpy(plis->arg5.pData, (LPVOID)dw5, plis->arg5.iLength);
00501       break;
00502     case action_npp_destroy_stream:
00503       break;
00504     case action_npp_stream_as_file:
00505       plis->arg3.iLength = strlen((char *)dw3) + 1;
00506       plis->arg3.pData = new char[plis->arg3.iLength];
00507       memcpy(plis->arg3.pData, (LPVOID)dw3, plis->arg3.iLength);
00508       break;
00509     case action_npp_write_ready:
00510       break;
00511     case action_npp_write:
00512     {
00513       if(dw5 != 0L)
00514       {
00515         makeAbbreviatedString(szBuf, sizeof(szBuf), dw5, strlen((char *)dw5), iWrap);
00516         plis->arg5.iLength = strlen(szBuf) + 1;
00517         plis->arg5.pData = new char[plis->arg5.iLength];
00518         memcpy(plis->arg5.pData, (LPVOID)&szBuf[0], plis->arg5.iLength);
00519       }
00520       break;
00521     }
00522     case action_npp_print:
00523       break;
00524     case action_npp_handle_event:
00525       break;
00526     case action_npp_url_notify:
00527       plis->arg2.iLength = strlen((char *)dw2) + 1;
00528       plis->arg2.pData = new char[plis->arg2.iLength];
00529       memcpy(plis->arg2.pData, (LPVOID)dw2, plis->arg2.iLength);
00530       break;
00531     case action_npp_get_java_class:
00532       break;
00533     case action_npp_get_value:
00534       break;
00535     case action_npp_set_value:
00536       break;
00537 
00538     default:
00539       break;
00540   }
00541 
00542   return plis;
00543 }
00544 
00545 void freeLogItemStruct(LogItemStruct * lis)
00546 {
00547   if(lis)
00548     delete lis;
00549 }
00550 
00551 int formatLogItem(LogItemStruct * plis, char * szOutput, BOOL bDOSStyle)
00552 {
00553   int iRet = 0;
00554   static char szString[1024];
00555   static char szEOL[8];
00556   static char szEOI[256];
00557   static char szEndOfItem[] = "";
00558 
00559   if(bDOSStyle)
00560   {
00561     strcpy(szEOL, "\r\n");
00562     //strcpy(szEOI, szEndOfItem);
00563     //strcat(szEOI, "\r\n");
00564   }
00565   else
00566   {
00567     strcpy(szEOL, "\n");
00568     //strcpy(szEOI, szEndOfItem);
00569     //strcat(szEOI, "\n");
00570   }
00571 
00572   szOutput[0] = '\0';
00573 
00574   DWORD dw1 = plis->arg1.dwArg;
00575   DWORD dw2 = plis->arg2.dwArg;
00576   DWORD dw3 = plis->arg3.dwArg;
00577   DWORD dw4 = plis->arg4.dwArg;
00578   DWORD dw5 = plis->arg5.dwArg;
00579   DWORD dw6 = plis->arg6.dwArg;
00580   DWORD dw7 = plis->arg7.dwArg;
00581 
00582   char sz1[1024] = {'\0'};
00583   char sz2[1024] = {'\0'};
00584   char sz3[1024] = {'\0'};
00585   char sz4[1024] = {'\0'};
00586   char sz5[1024] = {'\0'};
00587   char sz6[1024] = {'\0'};
00588 
00589   switch (plis->action)
00590   {
00591     case action_invalid:
00592       break;
00593 
00594     // NPN action
00595     case action_npn_version:
00596       if((plis->arg1.pData != NULL)&&(plis->arg2.pData != NULL)&&(plis->arg3.pData != NULL)&&(plis->arg4.pData != NULL))
00597         sprintf(szString, "NPN_Version(%#08lx, %#08lx, %#08lx, %#08lx)%s", dw1,dw2,dw3,dw4,szEOL);
00598       else
00599         sprintf(szString, "NPN_Version(%#08lx, %#08lx, %#08lx, %#08lx)%s", dw1,dw2,dw3,dw4,szEOL);
00600       break;
00601     case action_npn_get_url_notify:
00602     {
00603       FormatPCHARArgument(sz2, sizeof(sz2), &plis->arg2);
00604       FormatPCHARArgument(sz3, sizeof(sz3), &plis->arg3);
00605       sprintf(szString, "NPN_GetURLNotify(%#08lx, %s, %s, %#08lx)%s", dw1,sz2,sz3,dw4,szEOL);
00606       break;
00607     }
00608     case action_npn_get_url:
00609     {
00610       FormatPCHARArgument(sz2, sizeof(sz2), &plis->arg2);
00611       FormatPCHARArgument(sz3, sizeof(sz3), &plis->arg3);
00612       sprintf(szString, "NPN_GetURL(%#08lx, %s, %s)%s", dw1,sz2,sz3,szEOL);
00613       break;
00614     }
00615     case action_npn_post_url_notify:
00616     {
00617       FormatPCHARArgument(sz2, sizeof(sz2), &plis->arg2);
00618       FormatPCHARArgument(sz3, sizeof(sz3), &plis->arg3);
00619       FormatPCHARArgument(sz5, sizeof(sz5), &plis->arg5);
00620       FormatBOOLArgument(sz6, sizeof(sz6), &plis->arg6);
00621 
00622       sprintf(szString, "NPN_PostURLNotify(%#08lx, %s, %s, %li, %s, %s, %#08lx)%s", 
00623                dw1,sz2,sz3,(uint32)dw4,sz5,sz6,dw7,szEOL);
00624       break;
00625     }
00626     case action_npn_post_url:
00627     {
00628       FormatPCHARArgument(sz2, sizeof(sz2), &plis->arg2);
00629       FormatPCHARArgument(sz3, sizeof(sz3), &plis->arg3);
00630       FormatPCHARArgument(sz5, sizeof(sz5), &plis->arg5);
00631       FormatBOOLArgument(sz6, sizeof(sz6), &plis->arg6);
00632 
00633       sprintf(szString, "NPN_PostURL(%#08lx, %s, %s, %li, %s, %s)%s", 
00634                dw1,sz2,sz3,(uint32)dw4,sz5,sz6,szEOL);
00635       break;
00636     }
00637     case action_npn_new_stream:
00638     {
00639       FormatPCHARArgument(sz2, sizeof(sz2), &plis->arg2);
00640       FormatPCHARArgument(sz3, sizeof(sz3), &plis->arg3);
00641       if(plis->arg4.pData != NULL)
00642         sprintf(szString, "NPN_NewStream(%#08lx, %s, %s, %#08lx(%#08lx))%s", 
00643                  dw1, sz2,sz3,dw4,*(DWORD *)plis->arg4.pData,szEOL);
00644       else
00645         sprintf(szString, "NPN_NewStream(%#08lx, \"%s\", \"%s\", %#08lx)%s", dw1, sz2,sz3,dw4,szEOL);
00646       break;
00647     }
00648     case action_npn_destroy_stream:
00649       sprintf(szString, "NPN_DestroyStream(%#08lx, %#08lx, %s)%s", dw1,dw2,FormatNPAPIReason((int)dw3),szEOL);
00650       break;
00651     case action_npn_request_read:
00652       sprintf(szString, "NPN_RequestRead(%#08lx, %#08lx)%s", dw1, dw2, szEOL);
00653       break;
00654     case action_npn_write:
00655     {
00656       FormatPCHARArgument(sz4, sizeof(sz4), &plis->arg4);
00657       sprintf(szString, "NPN_Write(%#08lx, %#08lx, %li, %s)%s", dw1, dw2, (int32)dw3, sz4, szEOL);
00658       break;
00659     }
00660     case action_npn_status:
00661     {
00662       FormatPCHARArgument(sz2, sizeof(sz2), &plis->arg2);
00663       sprintf(szString, "NPN_Status(%#08lx, %s)%s", dw1, sz2, szEOL);
00664       break;
00665     }
00666     case action_npn_user_agent:
00667       sprintf(szString, "NPN_UserAgent(%#08lx)%s", dw1, szEOL);
00668       break;
00669     case action_npn_mem_alloc:
00670       sprintf(szString, "NPN_MemAlloc(%li)%s", dw1, szEOL);
00671       break;
00672     case action_npn_mem_free:
00673       sprintf(szString, "NPN_MemFree(%#08lx)%s", dw1,szEOL);
00674       break;
00675     case action_npn_mem_flush:
00676       sprintf(szString, "NPN_MemFlush(%li)%s", dw1, szEOL);
00677       break;
00678     case action_npn_reload_plugins:
00679     {
00680       FormatBOOLArgument(sz1, sizeof(sz1), &plis->arg1);
00681       sprintf(szString, "NPN_ReloadPlugins(%s)%s", sz1,szEOL);
00682       break;
00683     }
00684     case action_npn_get_java_env:
00685       sprintf(szString, "NPN_GetJavaEnv()%s", szEOL);
00686       break;
00687     case action_npn_get_java_peer:
00688       sprintf(szString, "NPN_GetJavaPeer(%#08lx)%s", dw1, szEOL);
00689       break;
00690     case action_npn_get_value:
00691     {
00692       switch(dw2)
00693       {
00694         case NPNVxDisplay:
00695         case NPNVxtAppContext:
00696         case NPNVnetscapeWindow:
00697           if(dw3 != 0L)
00698             sprintf(szString, "NPN_GetValue(%#08lx, %s, %#08lx(%#08lx))%s",dw1,FormatNPNVariable((NPNVariable)dw2),dw3,*(DWORD *)dw3,szEOL);
00699           else
00700             sprintf(szString, "NPN_GetValue(%#08lx, %s, %#08lx)%s",dw1,FormatNPNVariable((NPNVariable)dw2),dw3,szEOL);
00701           break;
00702         case NPNVjavascriptEnabledBool:
00703         case NPNVasdEnabledBool:
00704         case NPNVisOfflineBool:
00705           if(dw3 != 0L)
00706             sprintf(szString, "NPN_GetValue(%#08lx, %s, %#08lx(%s))%s",
00707                      dw1,FormatNPNVariable((NPNVariable)dw2),dw3,
00708                      (((NPBool)*(DWORD *)dw3) == TRUE) ? "TRUE" : "FALSE", szEOL);
00709           else
00710             sprintf(szString, "NPN_GetValue(%#08lx, %s, %#08lx)%s",dw1,FormatNPNVariable((NPNVariable)dw2),dw3,szEOL);
00711           break;
00712         default:
00713           break;
00714       }
00715       break;
00716     }
00717     case action_npn_set_value:
00718 
00719       if(((NPPVariable)dw2 == NPPVpluginNameString) || ((NPPVariable)dw2 == NPPVpluginDescriptionString))
00720       {
00721         FormatPCHARArgument(sz3, sizeof(sz3), &plis->arg3);
00722         sprintf(szString, "NPN_SetValue(%#08lx, %s, %s)%s", dw1,FormatNPPVariable((NPPVariable)dw2),sz3,szEOL);
00723       }
00724       else if(((NPPVariable)dw2 == NPPVpluginWindowBool) || ((NPPVariable)dw2 == NPPVpluginTransparentBool))
00725       {
00726         FormatPBOOLArgument(sz3, sizeof(sz3), &plis->arg3);
00727         sprintf(szString, "NPN_SetValue(%#08lx, %s, %s)%s", 
00728                  dw1,FormatNPPVariable((NPPVariable)dw2),sz3,szEOL);
00729       }
00730       else if((NPPVariable)dw2 == NPPVpluginWindowSize)
00731       {
00732         if(plis->arg3.pData != NULL)
00733         {
00734           int32 iWidth = ((NPSize *)plis->arg3.pData)->width;
00735           int32 iHeight = ((NPSize *)plis->arg3.pData)->height;
00736           sprintf(szString, "NPN_SetValue(%#08lx, %s, %#08lx(%li,%li))%s", 
00737                    dw1,FormatNPPVariable((NPPVariable)dw2),dw3,iWidth,iHeight,szEOL);
00738         }
00739         else
00740           sprintf(szString, "NPN_SetValue(%#08lx, %s, %#08lx(?,?))%s", 
00741                    dw1,FormatNPPVariable((NPPVariable)dw2),dw3,szEOL);
00742       }
00743       else
00744         sprintf(szString, "NPN_SetValue(%#08lx, %s, %#08lx(What is it?))%s", dw1,FormatNPPVariable((NPPVariable)dw2),dw3,szEOL);
00745       break;
00746     case action_npn_invalidate_rect:
00747     {
00748       if(plis->arg2.pData != NULL)
00749       {
00750         uint16 top    = ((NPRect *)plis->arg2.pData)->top;
00751         uint16 left   = ((NPRect *)plis->arg2.pData)->left;
00752         uint16 bottom = ((NPRect *)plis->arg2.pData)->bottom;
00753         uint16 right  = ((NPRect *)plis->arg2.pData)->right;
00754         sprintf(szString, "NPN_InvalidateRect(%#08lx, %#08lx(%u,%u;%u,%u)%s", dw1,dw2,top,left,bottom,right,szEOL);
00755       }
00756       else
00757         sprintf(szString, "NPN_InvalidateRect(%#08lx, %#08lx(?,?,?,?)%s", dw1,dw2,szEOL);
00758       break;
00759     }
00760     case action_npn_invalidate_region:
00761       sprintf(szString, "NPN_InvalidateRegion(%#08lx, %#08lx)%s", dw1,dw2,szEOL);
00762       break;
00763     case action_npn_force_redraw:
00764       sprintf(szString, "NPN_ForceRedraw(%#08lx)%s", dw1,szEOL);
00765       break;
00766 
00767     // NPP action
00768     case action_npp_new:
00769     {
00770       char szMode[16];
00771       switch (dw3)
00772       {
00773         case NP_EMBED:
00774           strcpy(szMode, "NP_EMBED");
00775           break;
00776         case NP_FULL:
00777           strcpy(szMode, "NP_FULL");
00778           break;
00779         default:
00780           strcpy(szMode, "[Invalide mode]");
00781           break;
00782       }
00783       sprintf(szString, "NPP_New(\"%s\", %#08lx, %s, %i, %#08lx, %#08lx, %#08lx)%s", 
00784                (char *)dw1,dw2,szMode,(int)dw4,dw5,dw6,dw7,szEOL);
00785       break;
00786     }
00787     case action_npp_destroy:
00788       sprintf(szString, "NPP_Destroy(%#08lx, %#08lx(%#08lx))%s", dw1, dw2, *(DWORD *)plis->arg2.pData,szEOL);
00789       break;
00790     case action_npp_set_window:
00791     {
00792       char szWindow[512];
00793 
00794       if(plis->arg2.pData != NULL)
00795       {
00796         char szType[80];
00797         switch (((NPWindow*)plis->arg2.pData)->type)
00798         {
00799           case NPWindowTypeWindow:
00800             sprintf(szType, "NPWindowTypeWindow");
00801             break;
00802           case NPWindowTypeDrawable:
00803             sprintf(szType, "NPWindowTypeDrawable");
00804             break;
00805           default:
00806             sprintf(szType, "[Unlisted type]");
00807             break;
00808         }
00809         sprintf(szWindow, "NPWindow: %#08lx, (%li,%li), (%li,%li), (%i,%i,%i,%i), %s", 
00810                  ((NPWindow*)plis->arg2.pData)->window, 
00811                  ((NPWindow*)plis->arg2.pData)->x, 
00812                  ((NPWindow*)plis->arg2.pData)->y, 
00813                  ((NPWindow*)plis->arg2.pData)->width, 
00814                  ((NPWindow*)plis->arg2.pData)->height, 
00815                  ((NPWindow*)plis->arg2.pData)->clipRect.top, 
00816                  ((NPWindow*)plis->arg2.pData)->clipRect.left, 
00817                  ((NPWindow*)plis->arg2.pData)->clipRect.bottom, 
00818                  ((NPWindow*)plis->arg2.pData)->clipRect.right, szType);
00819         sprintf(szString, "NPP_SetWindow(%#08lx, %#08lx)%s%s%s", dw1,dw2," ",szWindow,szEOL);
00820       }
00821       else
00822         sprintf(szString, "NPP_SetWindow(%#08lx, %#08lx)%s", dw1,dw2,szEOL);
00823 
00824       break;
00825     }
00826     case action_npp_new_stream:
00827     {
00828       switch (*(int16 *)plis->arg5.pData)
00829       {
00830         case NP_NORMAL:
00831           sprintf(sz5, "NP_NORMAL");
00832           break;
00833         case NP_ASFILEONLY:
00834           sprintf(sz5, "NP_ASFILEONLY");
00835           break;
00836         case NP_ASFILE:
00837           sprintf(sz5, "NP_ASFILE");
00838           break;
00839         default:
00840           sprintf(sz5, "[Unlisted type]");
00841           break;
00842       }
00843       FormatPCHARArgument(sz2, sizeof(sz2), &plis->arg2);
00844       sprintf(szString, "NPP_NewStream(%#08lx, %s, %#08lx, %s, %s)%s", dw1, sz2, dw3, 
00845                ((NPBool)dw4 == TRUE) ? "TRUE" : "FALSE", sz5, szEOL);
00846       break;
00847     }
00848     case action_npp_destroy_stream:
00849       sprintf(szString, "NPP_DestroyStream(%#08lx, %#08lx, %s)%s", dw1,dw2,FormatNPAPIReason((int)dw3),szEOL);
00850       break;
00851     case action_npp_stream_as_file:
00852       FormatPCHARArgument(sz3, sizeof(sz3), &plis->arg3);
00853       sprintf(szString, "NPP_StreamAsFile(%#08lx, %#08lx, %s)%s", dw1,dw2,sz3,szEOL);
00854       break;
00855     case action_npp_write_ready:
00856       sprintf(szString, "NPP_WriteReady(%#08lx, %#08lx)%s", dw1,dw2,szEOL);
00857       break;
00858     case action_npp_write:
00859     {
00860       FormatPCHARArgument(sz5, sizeof(sz5), &plis->arg5);
00861       sprintf(szString, "NPP_Write(%#08lx, %#08lx, %li, %li, %s))%s",dw1,dw2,dw3,dw4,sz5,szEOL);
00862       break;
00863     }
00864     case action_npp_print:
00865       sprintf(szString, "NPP_Print(%#08lx, %#08lx)%s", dw1, dw2,szEOL);
00866       break;
00867     case action_npp_handle_event:
00868       sprintf(szString, "NPP_HandleEvent(%#08lx, %#08lx)%s", dw1,dw2,szEOL);
00869       break;
00870     case action_npp_url_notify:
00871     {
00872       FormatPCHARArgument(sz2, sizeof(sz2), &plis->arg2);
00873       sprintf(szString, "NPP_URLNotify(%#08lx, %s, %s, %#08lx)%s", dw1,sz2,FormatNPAPIReason((int)dw3),dw4,szEOL);
00874       break;
00875     }
00876     case action_npp_get_java_class:
00877       sprintf(szString, "NPP_GetJavaClass()%s",szEOL);
00878       break;
00879     case action_npp_get_value:
00880       sprintf(szString, "NPP_GetValue(%#08lx, %s, %#08lx)%s", dw1,FormatNPPVariable((NPPVariable)dw2),dw3,szEOL);
00881       break;
00882     case action_npp_set_value:
00883       sprintf(szString, "NPP_SetValue(%#08lx, %s, %#08lx)%s", dw1,FormatNPNVariable((NPNVariable)dw2),dw3,szEOL);
00884       break;
00885 
00886     default:
00887       sprintf(szString, "Unknown action%s",szEOL);
00888       break;
00889   }
00890   strcat(szOutput, szString);
00891   strcat(szOutput, szEOI);
00892   iRet = strlen(szString) + strlen(szEOI) + 1;
00893   return iRet;
00894 }