Back to index

lightning-sunbird  0.9+nobinonly
logging.c
Go to the documentation of this file.
00001 /* ***** BEGIN LICENSE BLOCK *****
00002  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00003  *
00004  * The contents of this file are subject to the Mozilla Public License Version
00005  * 1.1 (the "License"); you may not use this file except in compliance with
00006  * the License. You may obtain a copy of the License at
00007  * http://www.mozilla.org/MPL/
00008  *
00009  * Software distributed under the License is distributed on an "AS IS" basis,
00010  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00011  * for the specific language governing rights and limitations under the
00012  * License.
00013  *
00014  * The Original Code is Mozilla Navigator.
00015  *
00016  * The Initial Developer of the Original Code is
00017  * Netscape Communications Corp.
00018  * Portions created by the Initial Developer are Copyright (C) 2001
00019  * the Initial Developer. All Rights Reserved.
00020  *
00021  * Contributor(s):
00022  *   Sean Su <ssu@netscape.com>
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either of the GNU General Public License Version 2 or later (the "GPL"),
00026  * or 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 "extern.h"
00039 #include "logging.h"
00040 #include "extra.h"
00041 #include "ifuncns.h"
00042 #include "xpi.h"
00043 
00044 #define E_USER_CANCEL         -813
00045 
00046 int AppendToGlobalMessageStream(char *szInfo)
00047 {
00048   DWORD dwInfoLen = strlen(szInfo);
00049   DWORD dwMessageLen;
00050 
00051   if(gErrorMessageStream.bEnabled && gErrorMessageStream.szMessage)
00052   {
00053     dwMessageLen = strlen(gErrorMessageStream.szMessage);
00054     if((dwInfoLen + dwMessageLen) >= gErrorMessageStream.dwMessageBufSize)
00055     {
00056       if(NS_GlobalReAlloc(&gErrorMessageStream.szMessage,
00057                           gErrorMessageStream.dwMessageBufSize,
00058                           dwInfoLen + dwMessageLen + MAX_BUF_TINY) == NULL)
00059         return(WIZ_OUT_OF_MEMORY);
00060 
00061       gErrorMessageStream.dwMessageBufSize = dwInfoLen +
00062                                              dwMessageLen +
00063                                              MAX_BUF_TINY;
00064     }
00065 
00066     strcat(gErrorMessageStream.szMessage, szInfo);
00067   }
00068 
00069   return(WIZ_OK);
00070 }
00071 
00072 void LogISTime(int iType)
00073 {
00074   char       szBuf[MAX_BUF];
00075   time_t     rawtime;
00076   struct tm* timeinfo;
00077 
00078   time ( &rawtime );
00079   timeinfo = localtime ( &rawtime );
00080 
00081   if(iType == W_START)
00082     sprintf(szBuf, "Start Log: %s\n", asctime (timeinfo));
00083   else
00084     sprintf(szBuf, "End Log: %s\n", asctime (timeinfo));
00085 
00086   UpdateInstallStatusLog(szBuf);
00087 }
00088 
00089 void LogISProductInfo(void)
00090 {
00091   char szBuf[MAX_BUF];
00092 
00093   sprintf(szBuf, "\n    Product Info:\n");
00094   UpdateInstallStatusLog(szBuf);
00095 
00096   switch(sgProduct.ulMode)
00097   {
00098     case SILENT:
00099       sprintf(szBuf, "        Install mode: Silent\n");
00100       break;
00101     case AUTO:
00102       sprintf(szBuf, "        Install mode: Auto\n");
00103       break;
00104     default:
00105       sprintf(szBuf, "        Install mode: Normal\n");
00106       break;
00107   }
00108   UpdateInstallStatusLog(szBuf);
00109 
00110   sprintf(szBuf, "        Company name: %s\n        Product name (external): %s\n        Product name (internal): %s\n        Uninstall Filename: %s\n        UserAgent: %s\n        Alternate search path: %s\n",
00111            sgProduct.szCompanyName,
00112            sgProduct.szProductName,
00113            sgProduct.szProductNameInternal,
00114            sgProduct.szUninstallFilename,
00115            sgProduct.szUserAgent,
00116            sgProduct.szAlternateArchiveSearchPath);
00117   UpdateInstallStatusLog(szBuf);
00118 }
00119 
00120 void LogISDestinationPath(void)
00121 {
00122   char szBuf[MAX_BUF];
00123 
00124   sprintf(szBuf,
00125            "\n    Destination Path:\n        Main: %s\n        SubPath: %s\n",
00126            sgProduct.szPath,
00127            sgProduct.szSubPath);
00128   UpdateInstallStatusLog(szBuf);
00129 }
00130 
00131 void LogISSetupType(void)
00132 {
00133   char szBuf[MAX_BUF_TINY];
00134 
00135   switch(ulSetupType)
00136   {
00137     case ST_RADIO3:
00138       sprintf(szBuf, "\n    Setup Type: %s\n",
00139                diSetupType.stSetupType3.szDescriptionShort);
00140       break;
00141 
00142     case ST_RADIO2:
00143       sprintf(szBuf, "\n    Setup Type: %s\n",
00144                diSetupType.stSetupType2.szDescriptionShort);
00145       break;
00146 
00147     case ST_RADIO1:
00148       sprintf(szBuf, "\n    Setup Type: %s\n",
00149                diSetupType.stSetupType1.szDescriptionShort);
00150       break;
00151 
00152     default:
00153       sprintf(szBuf, "\n    Setup Type: %s\n",
00154                diSetupType.stSetupType0.szDescriptionShort);
00155       break;
00156   }
00157 
00158   UpdateInstallStatusLog(szBuf);
00159 }
00160 
00161 void LogISComponentsSelected(void)
00162 {
00163   char szBuf[MAX_BUF_TINY];
00164   siC  *siCNode;
00165   BOOL bFoundComponentSelected;
00166 
00167   sprintf(szBuf, "\n    Components selected:\n");
00168   UpdateInstallStatusLog(szBuf);
00169 
00170   bFoundComponentSelected = FALSE;
00171   siCNode = siComponents;
00172   do
00173   {
00174     if(siCNode == NULL)
00175       break;
00176 
00177     if(siCNode->dwAttributes & SIC_SELECTED)
00178     {
00179       if(!siCNode->bForceUpgrade)
00180         sprintf(szBuf,
00181                  "        %s\n",
00182                  siCNode->szDescriptionShort);
00183       else
00184         sprintf(szBuf,
00185                  "        %s (Required)\n",
00186                  siCNode->szDescriptionShort);
00187 
00188       UpdateInstallStatusLog(szBuf);
00189       bFoundComponentSelected = TRUE;
00190     }
00191 
00192     siCNode = siCNode->Next;
00193   } while((siCNode != NULL) && (siCNode != siComponents));
00194 
00195   if(!bFoundComponentSelected)
00196   {
00197     sprintf(szBuf, "        none\n");
00198     UpdateInstallStatusLog(szBuf);
00199   }
00200 }
00201 
00202 void LogISComponentsToDownload(void)
00203 {
00204   char szBuf[MAX_BUF_TINY];
00205   char szArchivePath[MAX_BUF_MEDIUM];
00206   siC  *siCNode;
00207   BOOL bFoundComponentSelected;
00208   BOOL bFoundComponentsToDownload;
00209 
00210   sprintf(szBuf, "\n    Components to download:\n");
00211   UpdateInstallStatusLog(szBuf);
00212 
00213   bFoundComponentSelected = FALSE;
00214   bFoundComponentsToDownload = FALSE;
00215   siCNode = siComponents;
00216   do
00217   {
00218     if(siCNode == NULL)
00219       break;
00220 
00221     if(siCNode->dwAttributes & SIC_SELECTED)
00222     {
00223 
00224       if(LocateJar(siCNode,
00225                    szArchivePath,
00226                    sizeof(szArchivePath),
00227                    gbPreviousUnfinishedDownload) == AP_NOT_FOUND)
00228       {
00229         sprintf(szBuf,
00230                  "        %s will be downloaded\n",
00231                  siCNode->szDescriptionShort);
00232         bFoundComponentsToDownload = TRUE;
00233       }
00234       else
00235         sprintf(szBuf,
00236                  "        %s found: %s\n",
00237                  siCNode->szDescriptionShort,
00238                  szArchivePath);
00239 
00240       UpdateInstallStatusLog(szBuf);
00241       bFoundComponentSelected = TRUE;
00242     }
00243 
00244     siCNode = siCNode->Next;
00245   } while((siCNode != NULL) && (siCNode != siComponents));
00246 
00247   if(!bFoundComponentSelected)
00248   {
00249     sprintf(szBuf, "        none\n");
00250     UpdateInstallStatusLog(szBuf);
00251   }
00252   if(!bFoundComponentsToDownload)
00253   {
00254     sprintf(szBuf, "        **\n        ** All components have been found locally.  No components will be downloaded.\n        **\n");
00255     UpdateInstallStatusLog(szBuf);
00256   }
00257 }
00258 
00259 void LogISDownloadProtocol(DWORD dwProtocolType)
00260 {
00261   char szBuf[MAX_BUF];
00262   char szProtocolType[MAX_BUF];
00263 
00264   switch(dwProtocolType)
00265   {
00266     case UP_HTTP:
00267       strcpy(szProtocolType, "HTTP");
00268       break;
00269 
00270     default:
00271       strcpy(szProtocolType, "FTP");
00272       break;
00273   }
00274 
00275   sprintf(szBuf, "\n    Download protocol: %s\n", szProtocolType);
00276   UpdateInstallStatusLog(szBuf);
00277 }
00278 
00279 void LogISDownloadStatus(char *szStatus, char *szFailedFile)
00280 {
00281   char szBuf[MAX_BUF];
00282   siC   *siCObject = NULL;
00283   DWORD dwIndex;
00284 
00285   if(szFailedFile)
00286     sprintf(szBuf,
00287              "\n    Download status: %s\n          file: %s\n\n",
00288              szStatus,
00289              szFailedFile);
00290   else
00291     sprintf(szBuf,
00292              "\n    Download status: %s\n",
00293              szStatus);
00294   UpdateInstallStatusLog(szBuf);
00295 
00296   dwIndex = 0;
00297   siCObject = SiCNodeGetObject(dwIndex, TRUE, AC_ALL);
00298   while(siCObject)
00299   {
00300     if(siCObject->dwAttributes & SIC_SELECTED)
00301     {
00302       sprintf(szBuf, "        %s: NetRetries:%d, CRCRetries:%d, NetTimeOuts:%d\n",
00303                siCObject->szDescriptionShort,
00304                siCObject->iNetRetries,
00305                siCObject->iCRCRetries,
00306                siCObject->iNetTimeOuts);
00307       UpdateInstallStatusLog(szBuf);
00308     }
00309 
00310     ++dwIndex;
00311     siCObject = SiCNodeGetObject(dwIndex, TRUE, AC_ALL);
00312   }
00313 }
00314 
00315 void LogISComponentsFailedCRC(char *szList, int iWhen)
00316 {
00317   char szBuf[MAX_BUF];
00318 
00319   if(iWhen == W_STARTUP)
00320   {
00321     if(szList && (*szList != '\0'))
00322       sprintf(szBuf,
00323                "\n    Components corrupted (startup):\n%s",
00324                szList);
00325     else
00326       sprintf(szBuf,
00327                "\n    Components corrupted (startup):\n        none\n");
00328   }
00329   else
00330   {
00331     if(szList && (*szList != '\0'))
00332       sprintf(szBuf,
00333                "\n    Components corrupted (download):\n%s",
00334                szList);
00335     else
00336       sprintf(szBuf,
00337                "\n    Components corrupted (download):\n        none\n");
00338   }
00339 
00340   UpdateInstallStatusLog(szBuf);
00341 }
00342 
00343 void LogISXPInstall(int iWhen)
00344 {
00345   char szBuf[MAX_BUF];
00346 
00347   if(iWhen == W_START)
00348     sprintf(szBuf, "\n    XPInstall Start\n");
00349   else
00350     sprintf(szBuf, "    XPInstall End\n");
00351 
00352   UpdateInstallStatusLog(szBuf);
00353 }
00354 
00355 void LogISXPInstallComponent(char *szComponentName)
00356 {
00357   char szBuf[MAX_BUF];
00358 
00359   sprintf(szBuf, "        %s", szComponentName);
00360   UpdateInstallStatusLog(szBuf);
00361 }
00362 
00363 void LogISXPInstallComponentResult(DWORD dwErrorNumber)
00364 {
00365   char szBuf[MAX_BUF];
00366   char szErrorString[MAX_BUF];
00367 
00368 //  GetErrorString(dwErrorNumber, szErrorString, sizeof(szErrorString));
00369   sprintf(szBuf, ": %d %s\n", dwErrorNumber, szErrorString);
00370   UpdateInstallStatusLog(szBuf);
00371 }
00372 
00373 void LogISLaunchApps(int iWhen)
00374 {
00375   char szBuf[MAX_BUF];
00376 
00377   if(iWhen == W_START)
00378     sprintf(szBuf, "\n    Launch Apps Start\n");
00379   else
00380     sprintf(szBuf, "    Launch Apps End\n");
00381 
00382   UpdateInstallStatusLog(szBuf);
00383 }
00384 
00385 void LogISLaunchAppsComponent(char *szComponentName)
00386 {
00387   char szBuf[MAX_BUF];
00388 
00389   sprintf(szBuf, "        launching %s\n", szComponentName);
00390   UpdateInstallStatusLog(szBuf);
00391 }
00392 
00393 void LogISLaunchAppsComponentUncompress(char *szComponentName, DWORD dwErr)
00394 {
00395   char szBuf[MAX_BUF];
00396 
00397   sprintf(szBuf, "        uncompressing %s: %d\n", szComponentName, dwErr);
00398   UpdateInstallStatusLog(szBuf);
00399 }
00400 
00401 void LogISProcessXpcomFile(int iStatus, int iResult)
00402 {
00403   char szBuf[MAX_BUF];
00404 
00405   if(iStatus == LIS_SUCCESS)
00406     sprintf(szBuf, "\n    Uncompressing Xpcom Succeeded: %d\n", iResult);
00407   else
00408     sprintf(szBuf, "\n    Uncompressing Xpcom Failed: %d\n", iResult);
00409 
00410   UpdateInstallStatusLog(szBuf);
00411 }
00412 
00413 void LogISDiskSpace(dsN *dsnComponentDSRequirement)
00414 {
00415   ULONG     ulDSAvailable;
00416   dsN       *dsnTemp = NULL;
00417   char      szBuf[MAX_BUF];
00418   char      szDSRequired[MAX_BUF_TINY];
00419   char      szDSAvailable[MAX_BUF_TINY];
00420 
00421   if(dsnComponentDSRequirement != NULL)
00422   {
00423     sprintf(szBuf, "\n    Disk Space Info:\n");
00424     UpdateInstallStatusLog(szBuf);
00425     dsnTemp = dsnComponentDSRequirement;
00426     do
00427     {
00428       if(!dsnTemp)
00429         break;
00430 
00431       ulDSAvailable = GetDiskSpaceAvailable(dsnTemp->szVDSPath);
00432       _itoa(ulDSAvailable, szDSAvailable, 10);
00433       _itoa(dsnTemp->ulSpaceRequired, szDSRequired, 10);
00434       sprintf(szBuf,
00435                "             Path: %s\n         Required: %sKB\n        Available: %sKB\n",
00436                dsnTemp->szVDSPath,
00437                szDSRequired,
00438                szDSAvailable);
00439       UpdateInstallStatusLog(szBuf);
00440 
00441       dsnTemp = dsnTemp->Next;
00442     } while((dsnTemp != NULL) && (dsnTemp != dsnComponentDSRequirement));
00443   }
00444 }
00445 
00446 void LogISTurboMode(BOOL bTurboMode)
00447 {
00448   char szBuf[MAX_BUF];
00449 
00450   if(bTurboMode)
00451     sprintf(szBuf, "\n    Turbo Mode: true\n");
00452   else
00453     sprintf(szBuf, "\n    Turbo Mode: false\n");
00454 
00455   UpdateInstallStatusLog(szBuf);
00456 }
00457 
00458 void LogMSProductInfo(void)
00459 {
00460   char szBuf[MAX_BUF];
00461   char szOSType[MAX_BUF_TINY];
00462 
00463   GetOSTypeString(szOSType, sizeof(szOSType));
00464   if(*gSystemInfo.szExtraString != '\0')
00465     sprintf(szBuf, "UserAgent=%s/%s (%s,%d.%d.%d,%s)",
00466              sgProduct.szProductName,
00467              sgProduct.szUserAgent,
00468              szOSType,
00469              gSystemInfo.ulMajorVersion,
00470              gSystemInfo.ulMinorVersion,
00471              gSystemInfo.ulBuildNumber,
00472              gSystemInfo.szExtraString);
00473   else
00474     sprintf(szBuf, "UserAgent=%s/%s (%s,%d.%d.%d)",
00475              sgProduct.szProductName,
00476              sgProduct.szUserAgent,
00477              szOSType,
00478              gSystemInfo.ulMajorVersion,
00479              gSystemInfo.ulMinorVersion,
00480              gSystemInfo.ulBuildNumber);
00481 
00482   AppendToGlobalMessageStream(szBuf);
00483 }
00484 
00485 void LogMSDownloadProtocol(DWORD dwProtocolType)
00486 {
00487   char szMessageStream[MAX_BUF_TINY];
00488   char szProtocolType[MAX_BUF];
00489 
00490   switch(dwProtocolType)
00491   {
00492     case UP_HTTP:
00493       strcpy(szProtocolType, "HTTP");
00494       break;
00495 
00496     default:
00497       strcpy(szProtocolType, "FTP");
00498       break;
00499   }
00500 
00501   sprintf(szMessageStream, "&DownloadProtocol=%s", szProtocolType);
00502   AppendToGlobalMessageStream(szMessageStream);
00503 }
00504 
00505 void LogMSDownloadStatus(int iDownloadStatus)
00506 {
00507   char szMessageStream[MAX_BUF_TINY];
00508 
00509   sprintf(szMessageStream, "&DownloadStatus=%d", iDownloadStatus);
00510   AppendToGlobalMessageStream(szMessageStream);
00511   gErrorMessageStream.bSendMessage = TRUE;
00512 }
00513 
00514 void LogMSDownloadFileStatus(void)
00515 {
00516   siC   *siCObject = NULL;
00517   DWORD dwIndex;
00518   char  szMessageStream[MAX_BUF];
00519 
00520   memset(szMessageStream, 0, sizeof(szMessageStream));
00521   dwIndex = 0;
00522   siCObject = SiCNodeGetObject(dwIndex, TRUE, AC_ALL);
00523   while(siCObject)
00524   {
00525     if(siCObject->iNetRetries ||
00526        siCObject->iCRCRetries ||
00527        siCObject->iNetTimeOuts)
00528     {
00529       char szFileInfo[MAX_BUF_SMALL];
00530 
00531       sprintf(szFileInfo,
00532                "&%s=%d,%d,%d",
00533                siCObject->szArchiveName,
00534                siCObject->iNetRetries,
00535                siCObject->iCRCRetries,
00536                siCObject->iNetTimeOuts);
00537 
00538       strcat(szMessageStream, szFileInfo);
00539     }
00540     ++dwIndex;
00541     siCObject = SiCNodeGetObject(dwIndex, TRUE, AC_ALL);
00542   }
00543 
00544   if(*szMessageStream != '\0')
00545     AppendToGlobalMessageStream(szMessageStream);
00546 }
00547 
00548 void LogMSXPInstallStatus(char *szFile, int iErr)
00549 {
00550   char szMessageStream[MAX_BUF];
00551   static BOOL bAlreadyLogged = FALSE;
00552 
00553   if(bAlreadyLogged)
00554     return;
00555 
00556   if(szFile)
00557     sprintf(szMessageStream, "&XPInstallStatus=%d&XPInstallFile=%s", iErr, szFile);
00558   else
00559     sprintf(szMessageStream, "&XPInstallStatus=%d", iErr);
00560 
00561   AppendToGlobalMessageStream(szMessageStream);
00562   bAlreadyLogged = TRUE;
00563   if((iErr != E_REBOOT) &&
00564     (((iErr == E_USER_CANCEL) &&
00565        !gErrorMessageStream.bShowConfirmation) ||
00566      ((iErr != E_USER_CANCEL) &&
00567       (iErr != WIZ_OK))))
00568     gErrorMessageStream.bSendMessage = TRUE;
00569 }
00570 
00571 void LogMSTurboMode(BOOL bTurboMode)
00572 {
00573   char szMessageStream[MAX_BUF];
00574 
00575   sprintf(szMessageStream, "&TM=%d", bTurboMode);
00576   AppendToGlobalMessageStream(szMessageStream);
00577 }
00578