From 3c2eb92acfa67da802b1dd2baadb189d25bb96b4 Mon Sep 17 00:00:00 2001 From: RĂ¼diger Timm Date: Fri, 20 Aug 2004 09:08:00 +0000 Subject: INTEGRATION: CWS nsplugin2 (1.1.4); FILE ADDED 2004/08/06 08:06:09 rchen 1.1.4.10: chnaged by rchen for chinese char 2004/08/06 03:00:56 jmeng 1.1.4.9: rewrite restoreUTF8 2004/06/22 08:26:54 rchen 1.1.4.8: Modify the way to find path of staroffice installation place Issue number: Submitted by: Reviewed by: 2004/06/17 07:27:44 jmeng 1.1.4.7: changed by Robert 2004/06/17 05:16:22 jmeng 1.1.4.6: changed by robert 2004/06/16 11:34:39 jmeng 1.1.4.5: bug in read windows version info 2004/06/16 09:14:41 jmeng 1.1.4.4: add a include file for windows 2004/06/16 09:08:46 jmeng 1.1.4.3: changed by Robert 2004/06/15 04:58:12 jmeng 1.1.4.2: run for SRC680_m42 2004/05/27 03:55:40 jmeng 1.1.4.1: add nsplugin module for Mozilla plugin of StarOffice --- extensions/source/nsplugin/source/so_env.cxx | 354 +++++++++++++++++++++++++++ 1 file changed, 354 insertions(+) create mode 100644 extensions/source/nsplugin/source/so_env.cxx (limited to 'extensions') diff --git a/extensions/source/nsplugin/source/so_env.cxx b/extensions/source/nsplugin/source/so_env.cxx new file mode 100644 index 000000000000..1e18a862551b --- /dev/null +++ b/extensions/source/nsplugin/source/so_env.cxx @@ -0,0 +1,354 @@ +/************************************************************************* + * + * $RCSfile: so_env.cxx,v $ + * + * $Revision: 1.2 $ + * + * last change: $Author: rt $ $Date: 2004-08-20 10:08:00 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRUNTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRUNTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc.. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifdef UNIX +#include +#include +#ifdef NP_LINUX +#include +#else +#include +#endif +// For vsnprintf() +#define NSP_vsnprintf vsnprintf +#endif // End UNIX + +#ifdef WNT +#define _WINDOWS + +#include +#include +#include +#include +#include +// For vsnprintf() +#define NSP_vsnprintf _vsnprintf +#endif // End WNT + +#include +#include +#include "so_env.hxx" +#include "ns_debug.hxx" + +// Tranform all strings like %20 in pPath to one char like space +/*int retoreUTF8(char* pPath) +{ + // Prepare buf + int len = strlen(pPath) + 1; + char* pBuf = (char*)malloc(len); + memset(pBuf, 0, len); + + // Store the original pBuf and pPath + char* pBufCur = pBuf; + char* pPathCur = pPath; + // ie, for %20, UTF8Numbers[0][0] = 2, UTF8Numbers[1][0] = 0 + char UTF8Numbers[2][2] = {{0, 0}, {0,0}}; + int temp; + + while (*pPathCur) { + if (('%' == *pPathCur) && (0 != *(pPathCur + 1)) + && (0 != *(pPathCur + 2))) + { + UTF8Numbers[0][0] = *(pPathCur + 1); + UTF8Numbers[1][0] = *(pPathCur + 2); + temp = 0; + temp = atoi(UTF8Numbers[0])*16 + atoi(UTF8Numbers[1]); + *pBufCur = (char)temp; + pBufCur++; + pPathCur += 3; + } else { + *pBufCur++ = *pPathCur++; + } + } + + *pBufCur = 0; + strcpy(pPath, pBuf); + free(pBuf); + return 0; +}*/ + +int +restoreUTF8(char *pPath) +{ + unsigned char *s, *d; + +#define XDIGIT(c) ((c) <= '9' ? (c) - '0' : ((c) & 0x4F) - 'A' + 10) + + s = d = (unsigned char *)pPath; + do { + if (*s == '%' && s[1] && s[2]) { + *d++ = (XDIGIT (s[1]) << 4) + XDIGIT (s[2]); + s += 2; + } else + *d++ = *s; + } while (*s++); + debug_fprintf(NSP_LOG_APPEND, "after restoreUTF8, pPath is %s\n", pPath); + return 0; +} + +// *aResult points the static string holding "/opt/staroffice8" +int findReadSversion(void** aResult, int bWnt, const char* tag, const char* entry) +{ +#ifdef UNIX + // The real space to hold "/opt/staroffice8" + static char realFileName[NPP_PATH_MAX] = {0}; + memset(realFileName, 0, NPP_PATH_MAX); + *aResult = realFileName; + + // Filename of lnk file, eg. "soffice" + char lnkFileName[NPP_PATH_MAX] = {0}; + char* pTempZero = NULL; + sprintf(lnkFileName, "%s/.mozilla/plugins/%s", getenv("HOME"), "libnpsoplugin.so"); + if ((0 > readlink(lnkFileName, realFileName, NPP_PATH_MAX)) || + (NULL == (pTempZero = strstr(realFileName, "/program/libnpsoplugin.so")))) + { + *realFileName = 0; + return -1; + } + *pTempZero = 0; + return 0; +#endif +#ifdef WNT + static char realFileName[NPP_PATH_MAX] = {0}; + *aResult = realFileName; + HKEY hKey; + DWORD dwBufLen = NPP_PATH_MAX; + LONG lRet; + + debug_fprintf(NSP_LOG_APPEND, "1 before before strstr realFileName is %s\n", realFileName); + lRet = RegOpenKeyEx( HKEY_LOCAL_MACHINE, + "SOFTWARE\\MozillaPlugins\\@sun.com/npsopluginmi;version=1.0", + 0, KEY_QUERY_VALUE, &hKey ); + debug_fprintf(NSP_LOG_APPEND, "2 before before strstr realFileName is %s\n", realFileName); + if( lRet != ERROR_SUCCESS ) + return FALSE; + + lRet = RegQueryValueEx( hKey, "Path", NULL, NULL, + (LPBYTE) realFileName, &dwBufLen); + debug_fprintf(NSP_LOG_APPEND, "3 before before strstr realFileName is %s\n", realFileName); + if( (lRet != ERROR_SUCCESS) || (dwBufLen > NPP_PATH_MAX) ) + return FALSE; + + RegCloseKey( hKey ); + char* pTempZero = NULL; + debug_fprintf(NSP_LOG_APPEND, "before strstr realFileName is %s\n", realFileName); + if (NULL == (pTempZero = strstr(realFileName, "\\program"))) + { + *realFileName = 0; + return -1; + } + *pTempZero = 0; + debug_fprintf(NSP_LOG_APPEND, "realFileName is %s\n", realFileName); + return 0; +#endif +} + +// Return the install dir path of staroffice, return value like "/home/build/staroffice" +const char* findInstallDir() +{ + static char* pInstall = NULL; + debug_fprintf(NSP_LOG_APPEND, "start of findInstallDir()\n"); + if (!pInstall) + { + findReadSversion((void**)&pInstall, 0, "["SECTION_NAME"]", SOFFICE_VERSION"="); + if (!pInstall) + pInstall = ""; + } + return pInstall; +} + +// Return the program dir path of staroffice, return value like "/home/build/staroffice/program" +const char* findProgramDir() +{ + static char sProgram[NPP_BUFFER_SIZE] = {0}; + if (!sProgram[0]) + { + sprintf(sProgram, "%s/program", findInstallDir()); +#ifdef WNT + UnixToDosPath(sProgram); +#endif + } + return sProgram; +} + +// Return the nsplugin executable file path, return value like "/home/build/staroffice/program/nsplugin" +const char* findNsExeFile() +{ + static char sNsExe[NPP_BUFFER_SIZE] = {0}; + + if (!sNsExe[0]) + { + sprintf(sNsExe, "%s/%s", findProgramDir(), PLUGIN_EXE_FILE_NAME); +#ifdef WNT + UnixToDosPath(sNsExe); +#endif + } + return sNsExe; +} + +// Return: "/home/build/staroffice/program" + original system library path +const char* getNewLibraryPath() +{ + static char pLPATH[NPP_PATH_MAX*4] = {0}; + + if (!pLPATH[0]) + { + const char* pProgram = findProgramDir(); + strcpy(pLPATH, "LD_LIBRARY_PATH="); + strcat(pLPATH, pProgram); + + char* pLD = getenv("LD_LIBRARY_PATH"); + if (pLD) + { + strcat(pLPATH, ":"); + strcat(pLPATH, pLD); + } + } + return pLPATH; +} + + +// Return SO executable absolute path, like "/home/build/staroffice/program/soffice" +const char* findSofficeExecutable() +{ + static char pSofficeExeccutable[NPP_PATH_MAX] = {0}; + if (!pSofficeExeccutable[0]) + { + sprintf(pSofficeExeccutable, "%s/%s", findProgramDir(), STAROFFICE_EXE_FILE_NAME); +#ifdef WNT + UnixToDosPath(pSofficeExeccutable); +#endif + } + + return pSofficeExeccutable; +} + +// Change Dos path such as c:\program\soffice to c:/program/soffice +int DosToUnixPath(char* sPath) +{ + if (!sPath) + return -1; + char* p = sPath; + while (*p) + { + if(*p == '\\') + *p = '/'; + p++; + } + return 0; + +} + +// Change Unix path such as program/soffice to program\soffice +int UnixToDosPath(char* sPath) +{ + if (!sPath) + return -1; + char* p = sPath; + while (*p) + { + if(*p == '/') + *p = '\\'; + p++; + } + return 0; + +} + +void NSP_WriteLog(int level, const char* pFormat, ...) +{ +#ifdef DEBUG + va_list ap; + char msgBuf[NPP_BUFFER_SIZE]; + static char logName[NPP_PATH_MAX] = {0}; + FILE * fp = NULL; + int dwPos,dwWriteBytes; + + va_start(ap,pFormat); + NSP_vsnprintf(msgBuf, NPP_BUFFER_SIZE, pFormat, ap); + va_end(ap); + + if (!logName[0]) + { +#ifdef UNIX + const char* homeDir = getenv("HOME"); + sprintf(logName,"%s/%s",homeDir,"nsplugin.log"); +#endif // End UNIX +#ifdef WNT + char szPath[MAX_PATH]; + if (!SHGetSpecialFolderPath(NULL, szPath, CSIDL_APPDATA, 0)) + { + return; + } + char* homeDir = szPath; + sprintf(logName,"%s\\%s", szPath, "nsplugin.log"); +#endif // End WNT + } + else + fp = fopen(logName, "a+"); + + if (!fp) + return; + fputs(msgBuf, fp); + fclose(fp); +#endif +} + -- cgit v1.2.3