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

        char *connectString = "socket,host=localhost,port=2009";
        if( argc == 2 ) connectString = argv[1];
            
	nsresult rv = NS_InitXPCOM(NULL, NULL);
	NS_ASSERTION( NS_SUCCEEDED(rv), "NS_InitXPCOM failed" );

	(void) nsComponentManager::AutoRegister(nsIComponentManager::NS_Startup, nsnull);

	NS_WITH_SERVICE(bcIORBComponent, _orb, kORBCIID, &rv);
                    if (NS_FAILED(rv)) {
printf("NS_WITH_SERVICE(bcXPC in Marshal failed\n");
                    }

	NS_WITH_SERVICE(bcIXPCOMStubsAndProxies, xpcomStubsAndProxies, kXPCOMStubsAndProxies, &rv);
        if (NS_FAILED(rv)) {
           printf("bcXPCOMStubsAndProxie failed\n");
           return -1;
        }

	bcIORB *orb;
        _orb->GetORB(&orb);
        bcIStub *stub = nsnull;
	NS_WITH_SERVICE(nsIComponentManager, mComp, compManag, &rv);
	if (NS_FAILED(rv)) {
           printf("compManager failed\n");
           return -1;
        }
        urpITest *proxy = nsnull;
        xpcomStubsAndProxies->GetStub((nsISupports*)mComp, &stub);
        bcOID oid = orb->RegisterStub(stub);

	urpTransport* trans = new urpAcceptor();
	PRStatus status = trans->Open(connectString);
	if(status == PR_SUCCESS) printf("succes %ld\n",oid);
	else printf("failed\n");
	urpManager* mngr = new urpManager(PR_FALSE, orb, nsnull);
	rv = NS_OK;
	while(NS_SUCCEEDED(rv)) {
	    // rv = mngr->HandleRequest(trans->GetConnection());
            urpConnection *conn = trans->GetConnection();
            if( conn != NULL ) {
                // handle request in new thread
                localThreadArg *arg = new localThreadArg( mngr, conn );
                PRThread *thr = PR_CreateThread( PR_USER_THREAD,
                                                  thread_start_server,
                                                  arg,
                                                  PR_PRIORITY_NORMAL,
                                                  PR_GLOBAL_THREAD,
                                                  PR_UNJOINABLE_THREAD,
                                                  0);
                if( thr == nsnull ) {
                    rv = NS_ERROR_FAILURE;
                }
            } else {
                rv = NS_ERROR_FAILURE;
            }
	}
	return 1;
}
Exemplo n.º 2
0
int main(int argc, char *argv[])
{
	// These should be set by command switches but aren't at the moment
	PRBool bSearchForUnicodeProgIDs = PR_FALSE;
	PRBool bSearchForUnicodeLibraries = PR_FALSE;

	if (argc != 2)
	{
		fprintf(stderr, "Usage: dumpdeps <mozbindirectory>\n");
		return 1;
	}

	std::string sBinDirPath = argv[1];

	nsIServiceManager   *mServiceManager;
	nsILocalFile *pBinDirPath = nsnull;
	nsresult res = NS_NewLocalFile(sBinDirPath.c_str(), &pBinDirPath);

	// Initialise XPCOM
	if (pBinDirPath == nsnull)
	{
		fprintf(stderr, "Error: Could not create object to represent mozbindirectory - is the path correct?\n");
		return 1;
	}
	NS_InitXPCOM(&mServiceManager, pBinDirPath);
	NS_RELEASE(pBinDirPath);

	// Read the component registry to fill the arrays with CLSIDs
	ReadComponentRegistry();
	
	// Locate all libraries and add them to the components list
// BEGIN WINDOWS SPECIFIC
	for (int n = 0; n < 2; n++)
	{
		// Windows specific paths
		std::string sFolder;
		if (n == 0)
		{
			sFolder = sBinDirPath + "\\";
		}
		else if (n == 1)
		{
			sFolder = sBinDirPath + "\\components\\";
		}
		std::string sPattern = sFolder + "*.dll";
		WIN32_FIND_DATA findData;
		HANDLE h = FindFirstFile(sPattern.c_str(), &findData);
		if (h)
		{
			do {
				std::string fullPath = sFolder + findData.cFileName;
				listComponents.push_back(library(fullPath.c_str(), findData.cFileName));
			} while (FindNextFile(h, &findData));
		}
		FindClose(h);
	}
// END WINDOWS SPECIFIC

	// Enumerate through all libraries looking for dependencies
	std::vector<library>::const_iterator i;
	for (i = listComponents.begin(); i != listComponents.end(); i++)
	{
		char *pszBuffer = NULL;
		long nBufferSize = 0;
		if (ReadFileToBuffer((*i).mFullPath.c_str(), &pszBuffer, &nBufferSize))
		{
			printf("Library \"%s\"\n", (*i).mFullPath.c_str());

			// Print out implements
			printf("  Implements:\n");

			// Search for CIDs implemented by this library
			std::vector<factory>::const_iterator j;
			for (j = listCLSIDs.begin(); j != listCLSIDs.end(); j++)
			{
				if (LibraryImplementsCID((*i).mFile.c_str(), (*j).mCID))
				{
					OutputCID((*j).mCID);
				}
			}

			// Print out references
			printf("  References:\n");

			// Search for CIDs not implemented by this library but referenced
			for (j = listCLSIDs.begin(); j != listCLSIDs.end(); j++)
			{
				if (!LibraryImplementsCID((*i).mFile.c_str(), (*j).mCID) &&
					ScanBuffer(pszBuffer, nBufferSize, &(*j).mCID, sizeof((*j).mCID)) == 1)
				{
					OutputCID((*j).mCID);
				}
			}

			// Search for ProgIds
			wchar_t szWTmp[1024];		
			std::vector<progid2cid>::const_iterator k;
			for (k = listProgIDs.begin(); k != listProgIDs.end(); k++)
			{
				// Skip ProgIds that the library implements
				if (LibraryImplementsCID((*i).mFile.c_str(), (*k).mCID))
				{
					continue;
				}

				// Search for ANSI strings
				const char *szA = (*k).mProgID.c_str();
				int nLength = (*k).mProgID.length();
				if (ScanBuffer(pszBuffer, nBufferSize, szA, nLength) == 1)
				{
					OutputProgId(szA);
					continue;
				}

				if (bSearchForUnicodeProgIDs)
				{
					// Search for Unicode strings
					wchar_t *szW = A2W((*k).mProgID.c_str(), szWTmp, sizeof(szWTmp) / sizeof(szWTmp[0]));
					if (ScanBuffer(pszBuffer, nBufferSize, szW, nLength * sizeof(wchar_t)) == 1)
					{
						printf("UNICODE Progid\n");
						OutputProgId(szA);
						continue;
					}
				}
			}

			printf("  Statically linked to:\n");
			std::vector<library>::const_iterator l;
			for (l = listComponents.begin(); l != listComponents.end(); l++)
			{
				// Skip when the full path and the component point to the same thing
				if (i == l)
				{
					continue;
				}

				// Search for ANSI strings
				const char *szA = (*l).mFile.c_str();
				int nLength = (*l).mFile.length();
				if (ScanBuffer(pszBuffer, nBufferSize, szA, nLength) == 1)
				{
					OutputLibrary(szA);
					continue;
				}

				if (bSearchForUnicodeLibraries)
				{
					// Search for Unicode strings
					wchar_t *szW = A2W((*l).mFile.c_str(), szWTmp, sizeof(szWTmp) / sizeof(szWTmp[0]));
					if (ScanBuffer(pszBuffer, nBufferSize, szW, nLength * sizeof(wchar_t)) == 1)
					{
						printf("UNICODE library\n");
						OutputLibrary(szA);
						continue;
					}
				}
			}
			delete []pszBuffer;
		}
	}

	return 0;
}