Back to index

lightning-sunbird  0.9+nobinonly
nsXPComStub.cpp
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.
00015  *
00016  * The Initial Developer of the Original Code is IBM Corporation.
00017  * Portions created by IBM Corporation are Copyright (C) 2004
00018  * IBM Corporation. All Rights Reserved.
00019  *
00020  * Contributor(s):
00021  *   Darin Fisher <darin@meer.net>
00022  *   Benjamin Smedberg <bsmedberg@covad.net>
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 "nsXPCOM.h"
00039 #include "nsXPCOMPrivate.h"
00040 #include "nsStringAPI.h"
00041 
00042 #include <string.h>
00043 
00044 static const XPCOMFunctions kFrozenFunctions = {
00045     XPCOM_GLUE_VERSION,
00046     sizeof(XPCOMFunctions),
00047     &NS_InitXPCOM2_P,
00048     &NS_ShutdownXPCOM_P,
00049     &NS_GetServiceManager_P,
00050     &NS_GetComponentManager_P,
00051     &NS_GetComponentRegistrar_P,
00052     &NS_GetMemoryManager_P,
00053     &NS_NewLocalFile_P,
00054     &NS_NewNativeLocalFile_P,
00055     &NS_RegisterXPCOMExitRoutine_P,
00056     &NS_UnregisterXPCOMExitRoutine_P,
00057 
00058     // these functions were added post 1.4
00059     &NS_GetDebug_P,
00060     &NS_GetTraceRefcnt_P,
00061 
00062     // these functions were added post 1.6
00063     &NS_StringContainerInit_P,
00064     &NS_StringContainerFinish_P,
00065     &NS_StringGetData_P,
00066     &NS_StringSetData_P,
00067     &NS_StringSetDataRange_P,
00068     &NS_StringCopy_P,
00069     &NS_CStringContainerInit_P,
00070     &NS_CStringContainerFinish_P,
00071     &NS_CStringGetData_P,
00072     &NS_CStringSetData_P,
00073     &NS_CStringSetDataRange_P,
00074     &NS_CStringCopy_P,
00075     &NS_CStringToUTF16_P,
00076     &NS_UTF16ToCString_P,
00077     &NS_StringCloneData_P,
00078     &NS_CStringCloneData_P,
00079 
00080     // these functions were added post 1.7 (post Firefox 1.0)
00081     &NS_Alloc_P,
00082     &NS_Realloc_P,
00083     &NS_Free_P,
00084     &NS_StringContainerInit2_P,
00085     &NS_CStringContainerInit2_P,
00086     &NS_StringGetMutableData_P,
00087     &NS_CStringGetMutableData_P,
00088     &NS_InitXPCOM3_P
00089 };  
00090 
00091 extern "C" NS_EXPORT nsresult
00092 NS_GetFrozenFunctions(XPCOMFunctions *functions, const char* /* libraryPath */)
00093 {
00094     if (!functions)
00095         return NS_ERROR_OUT_OF_MEMORY;
00096 
00097     if (functions->version != XPCOM_GLUE_VERSION)
00098         return NS_ERROR_FAILURE;
00099 
00100     PRUint32 size = functions->size;
00101     if (size > sizeof(XPCOMFunctions))
00102         size = sizeof(XPCOMFunctions);
00103 
00104     size -= offsetof(XPCOMFunctions, init);
00105 
00106     memcpy(&functions->init, &kFrozenFunctions.init, size);
00107 
00108     return NS_OK;
00109 }
00110 
00111 /*
00112  * Stubs for nsXPCOM.h
00113  */
00114 
00115 #undef NS_InitXPCOM2
00116 extern "C" NS_EXPORT nsresult
00117 NS_InitXPCOM2(nsIServiceManager **result,
00118               nsIFile *binDirectory,
00119               nsIDirectoryServiceProvider *dirProvider)
00120 {
00121   return NS_InitXPCOM2_P(result, binDirectory, dirProvider);
00122 }
00123 
00124 #undef NS_InitXPCOM3
00125 extern "C" NS_EXPORT nsresult
00126 NS_InitXPCOM3(nsIServiceManager **result,
00127              nsIFile *binDirectory,
00128              nsIDirectoryServiceProvider *dirProvider,
00129              nsStaticModuleInfo const *staticComponents,
00130              PRUint32 componentCount)
00131 {
00132   return NS_InitXPCOM3_P(result, binDirectory, dirProvider,
00133                          staticComponents, componentCount);
00134 }
00135 
00136 #undef NS_ShutdownXPCOM
00137 extern "C" NS_EXPORT nsresult
00138 NS_ShutdownXPCOM(nsIServiceManager *svcMgr)
00139 {
00140   return NS_ShutdownXPCOM_P(svcMgr);
00141 }
00142 
00143 #undef NS_GetServiceManager
00144 extern "C" NS_EXPORT nsresult
00145 NS_GetServiceManager(nsIServiceManager* *result)
00146 {
00147   return NS_GetServiceManager_P(result);
00148 }
00149 
00150 #undef NS_GetComponentManager
00151 extern "C" NS_EXPORT nsresult
00152 NS_GetComponentManager(nsIComponentManager* *result)
00153 {
00154   return NS_GetComponentManager_P(result);
00155 }
00156 
00157 #undef NS_GetComponentRegistrar
00158 extern "C" NS_EXPORT nsresult
00159 NS_GetComponentRegistrar(nsIComponentRegistrar* *result)
00160 {
00161   return NS_GetComponentRegistrar_P(result);
00162 }
00163 
00164 #undef NS_GetMemoryManager
00165 extern "C" NS_EXPORT nsresult
00166 NS_GetMemoryManager(nsIMemory* *result)
00167 {
00168   return NS_GetMemoryManager_P(result);
00169 }
00170 
00171 #undef NS_NewLocalFile
00172 extern "C" NS_EXPORT nsresult
00173 NS_NewLocalFile(const nsAString &path,
00174                 PRBool followLinks,
00175                 nsILocalFile **result)
00176 {
00177   return NS_NewLocalFile_P(path, followLinks, result);
00178 }
00179 
00180 #undef NS_NewNativeLocalFile
00181 extern "C" NS_EXPORT nsresult
00182 NS_NewNativeLocalFile(const nsACString &path,
00183                       PRBool followLinks,
00184                       nsILocalFile **result)
00185 {
00186   return NS_NewNativeLocalFile_P(path, followLinks, result);
00187 }
00188 
00189 #undef NS_GetDebug
00190 extern "C" NS_EXPORT nsresult
00191 NS_GetDebug(nsIDebug **result)
00192 {
00193   return NS_GetDebug_P(result);
00194 }
00195 
00196 #undef NS_GetTraceRefcnt
00197 extern "C" NS_EXPORT nsresult
00198 NS_GetTraceRefcnt(nsITraceRefcnt **result)
00199 {
00200   return NS_GetTraceRefcnt_P(result);
00201 }
00202 
00203 #undef NS_Alloc
00204 extern "C" NS_EXPORT void*
00205 NS_Alloc(PRSize size)
00206 {
00207   return NS_Alloc_P(size);
00208 }
00209 
00210 #undef NS_Realloc
00211 extern "C" NS_EXPORT void*
00212 NS_Realloc(void* ptr, PRSize size)
00213 {
00214   return NS_Realloc_P(ptr, size);
00215 }
00216 
00217 #undef NS_Free
00218 extern "C" NS_EXPORT void
00219 NS_Free(void* ptr)
00220 {
00221   NS_Free_P(ptr);
00222 }
00223 
00224 /*
00225  * Stubs for nsXPCOMPrivate.h
00226  */
00227 
00228 #undef NS_RegisterXPCOMExitRoutine
00229 extern "C" NS_EXPORT nsresult
00230 NS_RegisterXPCOMExitRoutine(XPCOMExitRoutine exitRoutine, PRUint32 priority)
00231 {
00232   return NS_RegisterXPCOMExitRoutine_P(exitRoutine, priority);
00233 }
00234 
00235 #undef NS_UnregisterXPCOMExitRoutine
00236 extern "C" NS_EXPORT nsresult
00237 NS_UnregisterXPCOMExitRoutine(XPCOMExitRoutine exitRoutine)
00238 {
00239   return NS_UnregisterXPCOMExitRoutine_P(exitRoutine);
00240 }
00241 
00242 /*
00243  * Stubs for nsStringAPI.h
00244  */
00245 
00246 #undef NS_StringContainerInit
00247 extern "C" NS_EXPORT nsresult
00248 NS_StringContainerInit(nsStringContainer &aStr)
00249 {
00250   return NS_StringContainerInit_P(aStr);
00251 }
00252 
00253 #undef NS_StringContainerInit2
00254 extern "C" NS_EXPORT nsresult
00255 NS_StringContainerInit2(nsStringContainer &aStr,
00256                         const PRUnichar   *aData,
00257                         PRUint32           aDataLength,
00258                         PRUint32           aFlags)
00259 {   
00260   return NS_StringContainerInit2_P(aStr, aData, aDataLength, aFlags);
00261 }
00262 
00263 #undef NS_StringContainerFinish
00264 extern "C" NS_EXPORT void
00265 NS_StringContainerFinish(nsStringContainer &aStr)
00266 {
00267   NS_StringContainerFinish_P(aStr);
00268 }
00269 
00270 #undef NS_StringGetData
00271 extern "C" NS_EXPORT PRUint32
00272 NS_StringGetData(const nsAString &aStr, const PRUnichar **aBuf, PRBool *aTerm)
00273 {
00274   return NS_StringGetData_P(aStr, aBuf, aTerm);
00275 }
00276 
00277 #undef NS_StringGetMutableData
00278 extern "C" NS_EXPORT PRUint32
00279 NS_StringGetMutableData(nsAString &aStr, PRUint32 aLen, PRUnichar **aBuf)
00280 {
00281   return NS_StringGetMutableData_P(aStr, aLen, aBuf);
00282 }
00283 
00284 #undef NS_StringCloneData
00285 extern "C" NS_EXPORT PRUnichar *
00286 NS_StringCloneData(const nsAString &aStr)
00287 {
00288   return NS_StringCloneData_P(aStr);
00289 }
00290 
00291 #undef NS_StringSetData
00292 extern "C" NS_EXPORT nsresult
00293 NS_StringSetData(nsAString &aStr, const PRUnichar *aBuf, PRUint32 aCount)
00294 {
00295   return NS_StringSetData_P(aStr, aBuf, aCount);
00296 }
00297 
00298 #undef NS_StringSetDataRange
00299 extern "C" NS_EXPORT nsresult
00300 NS_StringSetDataRange(nsAString &aStr, PRUint32 aCutStart, PRUint32 aCutLength,
00301                       const PRUnichar *aBuf, PRUint32 aCount)
00302 {
00303   return NS_StringSetDataRange_P(aStr, aCutStart, aCutLength, aBuf, aCount);
00304 }
00305 
00306 #undef NS_StringCopy
00307 extern "C" NS_EXPORT nsresult
00308 NS_StringCopy(nsAString &aDest, const nsAString &aSrc)
00309 {
00310   return NS_StringCopy_P(aDest, aSrc);
00311 }
00312 
00313 #undef NS_CStringContainerInit
00314 extern "C" NS_EXPORT nsresult
00315 NS_CStringContainerInit(nsCStringContainer &aStr)
00316 {
00317   return NS_CStringContainerInit_P(aStr);
00318 }
00319 
00320 #undef NS_CStringContainerInit2
00321 extern "C" NS_EXPORT nsresult
00322 NS_CStringContainerInit2(nsCStringContainer &aStr,
00323                          const char         *aData,
00324                          PRUint32            aDataLength,
00325                          PRUint32            aFlags)
00326 {   
00327   return NS_CStringContainerInit2_P(aStr, aData, aDataLength, aFlags);
00328 }
00329 
00330 #undef NS_CStringContainerFinish
00331 extern "C" NS_EXPORT void
00332 NS_CStringContainerFinish(nsCStringContainer &aStr)
00333 {
00334   NS_CStringContainerFinish_P(aStr);
00335 }
00336 
00337 #undef NS_CStringGetData
00338 extern "C" NS_EXPORT PRUint32
00339 NS_CStringGetData(const nsACString &aStr, const char **aBuf, PRBool *aTerm)
00340 {
00341   return NS_CStringGetData_P(aStr, aBuf, aTerm);
00342 }
00343 
00344 #undef NS_CStringGetMutableData
00345 extern "C" NS_EXPORT PRUint32
00346 NS_CStringGetMutableData(nsACString &aStr, PRUint32 aLen, char **aBuf)
00347 {
00348   return NS_CStringGetMutableData_P(aStr, aLen, aBuf);
00349 }
00350 
00351 #undef NS_CStringCloneData
00352 extern "C" NS_EXPORT char *
00353 NS_CStringCloneData(const nsACString &aStr)
00354 {
00355   return NS_CStringCloneData_P(aStr);
00356 }
00357 
00358 #undef NS_CStringSetData
00359 extern "C" NS_EXPORT nsresult
00360 NS_CStringSetData(nsACString &aStr, const char *aBuf, PRUint32 aCount)
00361 {
00362   return NS_CStringSetData_P(aStr, aBuf, aCount);
00363 }
00364 
00365 #undef NS_CStringSetDataRange
00366 extern "C" NS_EXPORT nsresult
00367 NS_CStringSetDataRange(nsACString &aStr, PRUint32 aCutStart, PRUint32 aCutLength,
00368                        const char *aBuf, PRUint32 aCount)
00369 {
00370   return NS_CStringSetDataRange_P(aStr, aCutStart, aCutLength, aBuf, aCount);
00371 }
00372 
00373 #undef NS_CStringCopy
00374 extern "C" NS_EXPORT nsresult
00375 NS_CStringCopy(nsACString &aDest, const nsACString &aSrc)
00376 {
00377   return NS_CStringCopy_P(aDest, aSrc);
00378 }
00379 
00380 #undef NS_CStringToUTF16
00381 extern "C" NS_EXPORT nsresult
00382 NS_CStringToUTF16(const nsACString &aSrc, nsCStringEncoding aSrcEncoding, nsAString &aDest)
00383 {
00384   return NS_CStringToUTF16_P(aSrc, aSrcEncoding, aDest);
00385 }
00386 
00387 #undef NS_UTF16ToCString
00388 extern "C" NS_EXPORT nsresult
00389 NS_UTF16ToCString(const nsAString &aSrc, nsCStringEncoding aDestEncoding, nsACString &aDest)
00390 {
00391   return NS_UTF16ToCString_P(aSrc, aDestEncoding, aDest);
00392 }