Back to index

lightning-sunbird  0.9+nobinonly
Classes | Functions | Variables
regxpcom.cpp File Reference
#include "stdlib.h"
#include "prenv.h"
#include "nspr.h"
#include "nsXPCOMPrivate.h"
#include "nsXPCOMGlue.h"
#include "nsIComponentManager.h"
#include "nsIComponentRegistrar.h"
#include "nsIServiceManager.h"
#include "nsCOMPtr.h"
#include "nsILocalFile.h"
#include "nsEmbedString.h"
#include "nsIDirectoryService.h"
#include "nsDirectoryServiceDefs.h"

Go to the source code of this file.

Classes

class  DirectoryServiceProvider

Functions

int startup_xpcom ()
void shutdown_xpcom ()
nsresult Register (const char *path)
void ReportSuccess (const char *file)
void ReportError (nsresult err, const char *file)
void printHelp ()
int ProcessArgs (int argc, char *argv[])
int main (int argc, char *argv[])

Variables

static PRBool gUnreg = PR_FALSE
static PRBool gQuiet = PR_FALSE
static const char * gXPCOMLocation = nsnull
static const char * gCompRegLocation = nsnull
static const char * gXPTIDatLocation = nsnull

Function Documentation

int main ( int  argc,
char *  argv[] 
)

Definition at line 367 of file regxpcom.cpp.

{
  int ret;
  nsresult rv;

  /* With no arguments, regxpcom will autoregister */
  if (argc <= 1)
  {
    startup_xpcom();
    nsCOMPtr<nsIComponentRegistrar> registrar;
    rv = NS_GetComponentRegistrar(getter_AddRefs(registrar));
    if (NS_FAILED(rv)) {
      printf("Can not aquire component registrar\n");
      return -1;
    }
    rv = registrar->AutoRegister(nsnull);
    ret = (NS_FAILED(rv)) ? -1 : 0;
    registrar = 0;
    shutdown_xpcom();
  } else
    ret = ProcessArgs(argc, argv);

  return ret;
}

Here is the call graph for this function:

Definition at line 257 of file regxpcom.cpp.

{
  printf(
"Mozilla regxpcom - a registration tool for xpcom components                    \n"
"                                                                               \n"
"Usage: regxpcom [options] [file-or-directory]                                  \n"
"                                                                               \n"
"Options:                                                                       \n"
"         -x path        Specifies the location of a directory containing the   \n"
"                        xpcom library which will be used when registering new  \n"
"                        component libraries.  This path will also be added to  \n"
"                        the \"load library\" path.  If not specified, the      \n"
"                        current working directory will be used.                \n"
"         -c path        Specifies the location of the compreg.dat file.  If    \n"
"                        not specifed, the compreg.dat file will be in its      \n"
"                        default location.                                      \n"
"         -d path        Specifies the location of the xpti.dat file.  If not   \n"
"                        specifed, the xpti.dat file will be in its default     \n"
"                        location.                                              \n"
"         -a             Option to register all files in the default component  \n"
"                        directories.  This is the default behavior if regxpcom \n"
"                        is called without any arguments.                       \n"
"         -h             Displays this help screen.  Must be the only option    \n"
"                        specified.                                             \n"
"         -u             Option to uninstall the files-or-directory instead of  \n"
"                        registering them.                                      \n"
"         -q             Quiets some of the output of regxpcom.                 \n\n");
}
int ProcessArgs ( int  argc,
char *  argv[] 
)

Definition at line 286 of file regxpcom.cpp.

{
  int i = 1, result = 0;
  nsresult res;

  while (i < argc) 
  {
    if (argv[i][0] == '-') 
    {
      int j;
      for (j = 1; argv[i][j] != '\0'; j++) 
      {
        switch (argv[i][j]) 
        {
          case 'h':
            printHelp();
            return 0;  // we are all done!

          case 'u':
            gUnreg = PR_TRUE;
            break;

          case 'q':
            gQuiet = PR_TRUE;
            break;

          case 'a':
          {
            res = Register(nsnull);
            if (NS_FAILED(res)) 
            {
              ReportError(res, "component directory");
              result = -1;
            } 
            else 
            {
              ReportSuccess("component directory");
            }
          }
          break;

          case 'x':
            gXPCOMLocation = argv[++i];
            j = strlen(gXPCOMLocation) - 1;
            break;

          case 'c':
            gCompRegLocation = argv[++i];
            j = strlen(gCompRegLocation) - 1;
            break;

          case 'd':
            gXPTIDatLocation = argv[++i];
            j = strlen(gXPTIDatLocation) - 1;
            break;

          default:
            printf("Unknown option '%c'\n", argv[i][j]);
        }
      }
    } 
    else
    {
      res = Register(argv[i]);
      
      if (NS_FAILED(res)) 
      {
        ReportError(res, argv[i]);
        result = -1;
      } 
      else 
      {
        ReportSuccess(argv[i]);
      }
    }
    i++;
  }
  return result;
}

Here is the call graph for this function:

nsresult Register ( const char *  path)

Definition at line 185 of file regxpcom.cpp.

{ 
  startup_xpcom();

  nsresult rv;
  nsCOMPtr<nsILocalFile> spec;
  
  if (path) {
    rv = NS_NewNativeLocalFile(nsEmbedCString(path), 
                               PR_TRUE, 
                               getter_AddRefs(spec));
  }

  nsCOMPtr<nsIComponentRegistrar> registrar;
  rv = NS_GetComponentRegistrar(getter_AddRefs(registrar));
  if (NS_FAILED(rv)) {
    printf("Can not aquire component registrar\n");
    return rv;
  }

  if (gUnreg)
    rv = registrar->AutoUnregister(spec);
  else
    rv = registrar->AutoRegister(spec);

  spec = 0;
  registrar = 0;

  shutdown_xpcom();
  return rv;
}

Here is the call graph for this function:

void ReportError ( nsresult  err,
const char *  file 
)

Definition at line 229 of file regxpcom.cpp.

{
  if (gUnreg)
    printf("Unregistration failed: (");
  else
    printf("Registration failed: (");
  
  switch (err) 
  {
    case NS_ERROR_FACTORY_NOT_LOADED:
      printf("Factory not loaded");
      break;
    case NS_NOINTERFACE:
      printf("No Interface");
      break;
    case NS_ERROR_NULL_POINTER:
      printf("Null pointer");
      break;
    case NS_ERROR_OUT_OF_MEMORY:
      printf("Out of memory");
      break;
    default:
      printf("%x", (unsigned)err);
  }
  
  printf(") %s\n", file);
}
void ReportSuccess ( const char *  file)

Definition at line 218 of file regxpcom.cpp.

{
  if (gQuiet)
    return;

  if (gUnreg)
    printf("Unregistration successful for %s\n", file);
  else
    printf("Registration successful for %s\n", file);
}

Here is the caller graph for this function:

Definition at line 167 of file regxpcom.cpp.

{
  nsresult rv;

  rv = NS_ShutdownXPCOM(nsnull);

  if (NS_FAILED(rv)) {
    printf("Can not shutdown XPCOM cleanly\n");
  }

  rv = XPCOMGlueShutdown();
  
  if (NS_FAILED(rv)) {
    printf("Can not shutdown XPCOM Glue cleanly\n");
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 109 of file regxpcom.cpp.

{
  nsresult rv;

  if (gXPCOMLocation) {
    int len = strlen(gXPCOMLocation);
    char* xpcomPath = (char*) malloc(len + sizeof(XPCOM_DLL) + sizeof(XPCOM_FILE_PATH_SEPARATOR) + 1);
    sprintf(xpcomPath, "%s" XPCOM_FILE_PATH_SEPARATOR XPCOM_DLL, gXPCOMLocation);

    rv = XPCOMGlueStartup(xpcomPath);

    free(xpcomPath);

    const char* path = getenv(XPCOM_SEARCH_KEY);
    if (!path) {
      path = "";
    }
  }
  else 
  {
    rv = XPCOMGlueStartup(nsnull);
  }

  if (NS_FAILED(rv)) 
  {
    printf("Can not initialize XPCOM Glue\n");
    return -1;
  }

  DirectoryServiceProvider *provider = new DirectoryServiceProvider();
  if ( !provider )
  {
    NS_WARNING("GRE_Startup failed");
    XPCOMGlueShutdown();
    return -1;
  }

  nsCOMPtr<nsILocalFile> file;
  if (gXPCOMLocation) 
  {
    rv = NS_NewNativeLocalFile(nsEmbedCString(gXPCOMLocation), 
                               PR_TRUE, 
                               getter_AddRefs(file));
  }

  NS_ADDREF(provider);
  rv = NS_InitXPCOM2(nsnull, file, provider);
  NS_RELEASE(provider);
    
  if (NS_FAILED(rv)) {
    printf("Can not initialize XPCOM\n");
    XPCOMGlueShutdown();
    return -1;
  }

  return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

const char* gCompRegLocation = nsnull [static]

Definition at line 60 of file regxpcom.cpp.

PRBool gQuiet = PR_FALSE [static]

Definition at line 57 of file regxpcom.cpp.

PRBool gUnreg = PR_FALSE [static]

Definition at line 57 of file regxpcom.cpp.

const char* gXPCOMLocation = nsnull [static]

Definition at line 59 of file regxpcom.cpp.

const char* gXPTIDatLocation = nsnull [static]

Definition at line 61 of file regxpcom.cpp.