Back to index

lightning-sunbird  0.9+nobinonly
nsXIEngine.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
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 Communicator client code, released
00016  * March 31, 1998.
00017  *
00018  * The Initial Developer of the Original Code is
00019  * Netscape Communications Corporation.
00020  * Portions created by the Initial Developer are Copyright (C) 1998
00021  * the Initial Developer. All Rights Reserved.
00022  *
00023  * Contributor(s):
00024  *   Samir Gehani <sgehani@netscape.com>
00025  *
00026  * Alternatively, the contents of this file may be used under the terms of
00027  * either the GNU General Public License Version 2 or later (the "GPL"), or
00028  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00029  * in which case the provisions of the GPL or the LGPL are applicable instead
00030  * of those above. If you wish to allow use of your version of this file only
00031  * under the terms of either the GPL or the LGPL, and not to allow others to
00032  * use your version of this file under the terms of the MPL, indicate your
00033  * decision by deleting the provisions above and replace them with the notice
00034  * and other provisions required by the GPL or the LGPL. If you do not delete
00035  * the provisions above, a recipient may use your version of this file under
00036  * the terms of any one of the MPL, the GPL or the LGPL.
00037  *
00038  * ***** END LICENSE BLOCK ***** */
00039 
00040 #ifndef _NS_XIENGINE_H_
00041 #define _NS_XIENGINE_H_
00042 
00043 #include "XIDefines.h"
00044 #include "nsXInstaller.h"
00045 #include "nsComponent.h"
00046 #include "nsComponentList.h"
00047 #include "nsInstallDlg.h"
00048 #include "nsZipExtractor.h"
00049 
00050 #include "xpistub.h"
00051 
00052 #define STANDALONE 1
00053 #include "zipfile.h"
00054 #include <ctype.h>
00055 
00056 #include <stdio.h>
00057 #include <stdlib.h>
00058 #include <malloc.h>
00059 #include <string.h>
00060 #include <unistd.h>
00061 #include <dlfcn.h>
00062 #include <sys/stat.h>
00063 
00064 /*------------------------------------------------------------------------*
00065  *   XPI Stub Glue
00066  *------------------------------------------------------------------------*/
00067 typedef nsresult (*pfnXPI_Init) 
00068                  (const char *aProgramDir, const char *aLogName,
00069                   pfnXPIProgress progressCB);
00070 typedef nsresult (*pfnXPI_Install) 
00071                  (const char *file, const char *args, long flags);
00072 typedef void     (*pfnXPI_Exit)();
00073 
00074 typedef struct _xpistub_t 
00075 {
00076     const char      *name;
00077     void            *handle;
00078     pfnXPI_Init     fn_init;
00079     pfnXPI_Install  fn_install;
00080     pfnXPI_Exit     fn_exit;
00081 } xpistub_t;
00082 
00083 #define TYPE_UNDEF 0
00084 #define TYPE_PROXY 1
00085 #define TYPE_HTTP 2
00086 #define TYPE_FTP 3
00087 
00088 typedef struct _conn
00089 {
00090   unsigned char type; // TYPE_UNDEF, etc.
00091   char *URL;      // URL this connection is for
00092   void *conn;     // pointer to open connection
00093 } CONN;
00094 
00095 /*------------------------------------------------------------------------*
00096  *   nsXIEngine
00097  *------------------------------------------------------------------------*/
00098 class nsXIEngine
00099 {
00100 public:
00101     nsXIEngine();
00102     ~nsXIEngine();
00103 
00104     int     Download(int aCustom, nsComponentList *aComps);
00105     int     Extract(nsComponent *aXPIEngine);
00106     int     Install(int aCustom, nsComponentList *aComps, char *aDestination);
00107     int     DeleteXPIs(int aCustom, nsComponentList *aComps);
00108 
00109     static void ProgressCallback(const char* aMsg, PRInt32 aVal, PRInt32 aMax);
00110     static int  ExistAllXPIs(int aCustom, nsComponentList *aComps, int *aTotal);
00111 
00112     enum
00113     {
00114         OK          = 0,
00115         E_PARAM     = -1201,
00116         E_MEM       = -1202,
00117         E_OPEN_MKR  = -1203,
00118         E_WRITE_MKR = -1204,
00119         E_READ_MKR  = -1205,
00120         E_FIND_COMP = -1206,
00121         E_STAT      = -1207
00122     };
00123 
00124 private:
00125     int     MakeUniqueTmpDir();
00126     int     ParseURL(char *aURL, char **aHost, char **aDir);
00127     int     LoadXPIStub(xpistub_t *aStub, char *aDestionation);
00128     int     InstallXPI(nsComponent *aComp, xpistub_t *aStub);
00129     int     UnloadXPIStub(xpistub_t *aStub);
00130     int     GetFileSize(char *aPath);
00131     int     SetDLMarker(char *aCompName);
00132     int     GetDLMarkedComp(nsComponentList *aComps, int aCustom,
00133                             nsComponent **aOutComp, int *aOutCompNum);
00134     int     DelDLMarker();
00135     int     TotalToDownload(int aCustom, nsComponentList *aComps);
00136     PRBool  CRCCheckDownloadedArchives(char *dlPath, short dlPathLen, 
00137               nsComponent *currComp, int count, int aCustom);
00138     PRBool  IsArchiveFile(char *path);
00139     int     VerifyArchive(char *szArchive);
00140     PRBool  CheckConn( char *URL, int type, CONN *myConn, PRBool force );
00141     char    *mTmp;
00142     int     mTotalComps;
00143     char    *mOriginalDir;
00144 };
00145 
00146 #endif /* _NS_XIENGINE_H_ */