static already_AddRefed<nsIFile> GetAppIni(int argc, const char *argv[]) { nsCOMPtr<nsIFile> appini; nsresult rv; // Allow firefox.exe to launch XULRunner apps via -app <application.ini> // Note that -app must be the *first* argument. const char *appDataFile = getenv("XUL_APP_FILE"); if (appDataFile && *appDataFile) { rv = XRE_GetFileFromPath(appDataFile, getter_AddRefs(appini)); NS_ENSURE_SUCCESS(rv, nullptr); } else if (argc > 1 && IsArg(argv[1], "app")) { if (argc == 2) { return nullptr; } rv = XRE_GetFileFromPath(argv[2], getter_AddRefs(appini)); NS_ENSURE_SUCCESS(rv, nullptr); char appEnv[MAXPATHLEN]; snprintf(appEnv, MAXPATHLEN, "XUL_APP_FILE=%s", argv[2]); if (putenv(appEnv)) { return nullptr; } } return appini.forget(); }
void cArgs_idb::SetCmdLine( int argc, char* argv[] ) { // start log flog = FileOpenOrDie( "makeidb.log", "w" ); // log start time time_t t0 = time( NULL ); char atime[32]; strcpy( atime, ctime( &t0 ) ); atime[24] = '\0'; // remove the newline fprintf( flog, "Make img database: %s ", atime ); // parse command line args if( argc < 3 ) { printf( "Usage: makeidb <source-file> [options].\n" ); exit( 42 ); } for( int i = 1; i < argc; ++i ) { // echo to log fprintf( flog, "%s ", argv[i] ); if( argv[i][0] != '-' ) infile = argv[i]; else if( GetArgStr( outdir, "-idb=", argv[i] ) ) ; else if( GetArgStr( crop, "-crop=", argv[i] ) ) ; else if( GetArgStr( lens, "-lens=", argv[i] ) ) ; else if( GetArgStr( clk, "-k=", argv[i] ) ) ; else if( GetArg( &zmin, "-zmin=%d", argv[i] ) ) ; else if( GetArg( &zmax, "-zmax=%d", argv[i] ) ) ; else if( GetArg( &xml_type, "-xmltype=%d", argv[i] ) ) ; else if( GetArg( &xml_min, "-xmlmin=%d", argv[i] ) ) ; else if( GetArg( &xml_max, "-xmlmax=%d", argv[i] ) ) ; else if( IsArg( "-nf", argv[i] ) ) NoFolds = true; else { printf( "Did not understand option [%s].\n", argv[i] ); exit( 42 ); } } fprintf( flog, "\n" ); fflush( flog ); }
static int do_main(int argc, char* argv[]) { nsCOMPtr<nsIFile> appini; nsresult rv; // Allow firefox.exe to launch XULRunner apps via -app <application.ini> // Note that -app must be the *first* argument. const char *appDataFile = getenv("XUL_APP_FILE"); if (appDataFile && *appDataFile) { rv = XRE_GetFileFromPath(appDataFile, getter_AddRefs(appini)); if (NS_FAILED(rv)) { Output("Invalid path found: '%s'", appDataFile); return 255; } } else if (argc > 1 && IsArg(argv[1], "app")) { if (argc == 2) { Output("Incorrect number of arguments passed to -app"); return 255; } rv = XRE_GetFileFromPath(argv[2], getter_AddRefs(appini)); if (NS_FAILED(rv)) { Output("application.ini path not recognized: '%s'", argv[2]); return 255; } char appEnv[MAXPATHLEN]; snprintf(appEnv, MAXPATHLEN, "XUL_APP_FILE=%s", argv[2]); if (putenv(appEnv)) { Output("Couldn't set %s.\n", appEnv); return 255; } argv[2] = argv[0]; argv += 2; argc -= 2; } #ifdef MOZ_WIDGET_GONK /* Called to start the boot animation */ (void) NativeWindow(); #endif if (appini) { nsXREAppData *appData; rv = XRE_CreateAppData(appini, &appData); if (NS_FAILED(rv)) { Output("Couldn't read application.ini"); return 255; } int result = XRE_main(argc, argv, appData, 0); XRE_FreeAppData(appData); return result; } return XRE_main(argc, argv, &sAppData, 0); }
int main(int argc, char* argv[]) { ScopedLogging log; nsCOMPtr<nsILocalFile> appini; nsresult rv = XRE_GetBinaryPath(argv[0], getter_AddRefs(appini)); if (NS_FAILED(rv)) { Output("Couldn't calculate the application directory."); return 255; } appini->SetNativeLeafName(NS_LITERAL_CSTRING("application.ini")); // Allow firefox.exe to launch XULRunner apps via -app <application.ini> // Note that -app must be the *first* argument. char *appEnv = nsnull; const char *appDataFile = PR_GetEnv("XUL_APP_FILE"); if (appDataFile && *appDataFile) { rv = XRE_GetFileFromPath(appDataFile, getter_AddRefs(appini)); if (NS_FAILED(rv)) { Output("Invalid path found: '%s'", appDataFile); return 255; } } else if (argc > 1 && IsArg(argv[1], "app")) { if (argc == 2) { Output("Incorrect number of arguments passed to -app"); return 255; } rv = XRE_GetFileFromPath(argv[2], getter_AddRefs(appini)); if (NS_FAILED(rv)) { Output("application.ini path not recognized: '%s'", argv[2]); return 255; } appEnv = PR_smprintf("XUL_APP_FILE=%s", argv[2]); PR_SetEnv(appEnv); argv[2] = argv[0]; argv += 2; argc -= 2; } nsXREAppData *appData; rv = XRE_CreateAppData(appini, &appData); if (NS_FAILED(rv)) { Output("Couldn't read application.ini"); return 255; } int result = XRE_main(argc, argv, appData); XRE_FreeAppData(appData); if (appEnv) PR_smprintf_free(appEnv); return result; }
void CArgs_alnmon::SetCmdLine( int argc, char* argv[] ) { // start log flog = FileOpenOrDie( "cross_lowres.log", "w" ); // log start time time_t t0 = time( NULL ); char atime[32]; strcpy( atime, ctime( &t0 ) ); atime[24] = '\0'; // remove the newline fprintf( flog, "Assemble stack: %s ", atime ); // parse command line args if( argc < 2 ) { printf( "Usage: cross_lowres -z=i,j [options].\n" ); exit( 42 ); } vector<int> vi; for( int i = 1; i < argc; ++i ) { // echo to log fprintf( flog, "%s ", argv[i] ); if( GetArgList( vi, "-z=", argv[i] ) ) { if( 2 == vi.size() ) { zmin = vi[0]; zmax = vi[1]; } else { fprintf( flog, "Bad format in -z [%s].\n", argv[i] ); exit( 42 ); } } else if( IsArg( "-table", argv[i] ) ) table = true; else { printf( "Did not understand option '%s'.\n", argv[i] ); exit( 42 ); } } fprintf( flog, "\n\n" ); fflush( flog ); }
bool CArgs::SetCmdLine( int argc, char* argv[] ) { // Parse command line args vector<int> vi; for( int i = 1; i < argc; ++i ) { if( GetArgStr( tempdir, "-temp=", argv[i] ) ) { printf( "Temp dir: '%s'.\n", tempdir ); GetIDB( tempdir ); } else if( GetArgStr( cachedir, "-cache=", argv[i] ) ) printf( "Cache dir: '%s'.\n", cachedir ); else if( GetArgStr( prior, "-prior=", argv[i] ) ) printf( "Prior solutions: '%s'.\n", prior ); else if( GetArgStr( mode, "-mode=", argv[i] ) ) printf( "Mode: '%s'.\n", mode ); else if( GetArg( &nwks, "-nwks=%d", argv[i] ) ) ; else if( GetArgList( vi, "-zi=", argv[i] ) ) { if( 2 == vi.size() ) { zilo = vi[0]; zihi = vi[1]; printf( "zi [%d %d]\n", zilo, zihi ); } else { printf( "Bad format in -zi [%s].\n", argv[i] ); return false; } } else if( GetArgList( vi, "-zo=", argv[i] ) ) { if( 2 == vi.size() ) { zolo = vi[0]; zohi = vi[1]; printf( "zo [%d %d]\n", zolo, zohi ); } else { printf( "Bad format in -zo [%s].\n", argv[i] ); return false; } } else if( GetArg( &Wr, "-Wr=T,%lf", argv[i] ) ) { regtype = 'T'; printf( "Rglizer Wr: T, %g\n", Wr ); } else if( GetArg( &Wr, "-Wr=R,%lf", argv[i] ) ) { regtype = 'R'; printf( "Rglizer Wr: R, %g\n", Wr ); } else if( GetArg( &Etol, "-Etol=%lf", argv[i] ) ) printf( "Error tol: %g\n", Etol ); else if( GetArg( &iters, "-iters=%d", argv[i] ) ) printf( "Iterations: %d\n", iters ); else if( GetArg( &splitmin, "-splitmin=%d", argv[i] ) ) printf( "Split-min: %d\n", splitmin ); else if( GetArg( &maxthreads, "-maxthreads=%d", argv[i] ) ) printf( "Maxthreads: %d\n", maxthreads ); else if( IsArg( "-untwist", argv[i] ) ) untwist = true; else { printf( "Did not understand option '%s'.\n", argv[i] ); return false; } } return true; }
void CArgs_scp::SetCmdLine( int argc, char* argv[] ) { // label output by layer b for( int i = 1; i < argc; ++i ) { if( GetArg( &zb, "-zb=%d", argv[i] ) ) break; } if( zb < 0 ) { printf( "scapeops: Missing -zb option!!\n" ); exit( 42 ); } // start log char buf[256]; sprintf( buf, "scplogs/scp_%d.log", zb ); flog = FileOpenOrDie( buf, "w" ); // log start time time_t t0 = time( NULL ); char atime[32]; strcpy( atime, ctime( &t0 ) ); atime[24] = '\0'; // remove the newline fprintf( flog, "Scapeops start: %s ", atime ); // parse command line args if( argc < 6 ) { printf( "Usage: See scapeops.cpp comments.\n" ); exit( 42 ); } const char *pchar; for( int i = 1; i < argc; ++i ) { // echo to log fprintf( flog, "%s ", argv[i] ); if( argv[i][0] != '-' ) srcmons = argv[i]; else if( GetArgStr( script, "-script=", argv[i] ) ) ; else if( GetArgStr( pchar, "-idb=", argv[i] ) ) idb = pchar; else if( GetArg( &za, "-za=%d", argv[i] ) ) ; else if( GetArg( &zb, "-zb=%d", argv[i] ) ) ; else if( GetArg( &abctr, "-abctr=%lf", argv[i] ) ) ; else if( IsArg( "-mb", argv[i] ) ) ismb = true; else if( IsArg( "-ab", argv[i] ) ) isab = true; else if( IsArg( "-abdbg", argv[i] ) ) abdbg = true; else { printf( "Did not understand option [%s].\n", argv[i] ); exit( 42 ); } } fprintf( flog, "\n" ); fflush( flog ); if( !ismb && !isab ) { fprintf( flog, "No operations specified.\n" ); exit( 0 ); } }
int main(int argc, char *argv[]) { afs_int32 code; char *whoami = argv[0]; afs_uint32 serverList[MAXSERVERS]; struct afsconf_cell cellinfo; char *cell; const char *cellservdb, *dbpath, *lclpath; int a; char arg[32]; char default_lclpath[AFSDIR_PATH_MAX]; int servers; int initFlags; int level; /* security level for Ubik */ afs_int32 i; char clones[MAXHOSTSPERCELL]; afs_uint32 host = ntohl(INADDR_ANY); char *auditFileName = NULL; struct rx_service *tservice; struct rx_securityClass *sca[1]; struct rx_securityClass *scm[3]; extern int rx_stackSize; #ifdef AFS_AIX32_ENV /* * The following signal action for AIX is necessary so that in case of a * crash (i.e. core is generated) we can include the user's data section * in the core dump. Unfortunately, by default, only a partial core is * generated which, in many cases, isn't too useful. */ struct sigaction nsa; sigemptyset(&nsa.sa_mask); nsa.sa_handler = SIG_DFL; nsa.sa_flags = SA_FULLDUMP; sigaction(SIGABRT, &nsa, NULL); sigaction(SIGSEGV, &nsa, NULL); #endif osi_audit_init(); if (argc == 0) { usage: printf("Usage: kaserver [-noAuth] [-database <dbpath>] " "[-auditlog <log path>] [-audit-interface <file|sysvmq>] " "[-rxbind] [-localfiles <lclpath>] [-minhours <n>] " "[-servers <serverlist>] [-crossrealm] " /*" [-enable_peer_stats] [-enable_process_stats] " */ "[-help]\n"); exit(1); } #ifdef AFS_NT40_ENV /* initialize winsock */ if (afs_winsockInit() < 0) { ReportErrorEventAlt(AFSEVT_SVR_WINSOCK_INIT_FAILED, 0, argv[0], 0); fprintf(stderr, "%s: Couldn't initialize winsock.\n", whoami); exit(1); } #endif /* Initialize dirpaths */ if (!(initAFSDirPath() & AFSDIR_SERVER_PATHS_OK)) { #ifdef AFS_NT40_ENV ReportErrorEventAlt(AFSEVT_SVR_NO_INSTALL_DIR, 0, argv[0], 0); #endif fprintf(stderr, "%s: Unable to obtain AFS server directory.\n", argv[0]); exit(2); } cellservdb = AFSDIR_SERVER_ETC_DIRPATH; dbpath = AFSDIR_SERVER_KADB_FILEPATH; strcompose(default_lclpath, AFSDIR_PATH_MAX, AFSDIR_SERVER_LOCAL_DIRPATH, "/", AFSDIR_KADB_FILE, NULL); lclpath = default_lclpath; debugOutput = 0; servers = 0; initFlags = 0; level = rxkad_crypt; for (a = 1; a < argc; a++) { int arglen = strlen(argv[a]); lcstring(arg, argv[a], sizeof(arg)); #define IsArg(a) (strncmp (arg,a, arglen) == 0) if (strcmp(arg, "-database") == 0) { dbpath = argv[++a]; if (strcmp(lclpath, default_lclpath) == 0) lclpath = dbpath; } else if (strncmp(arg, "-auditlog", arglen) == 0) { auditFileName = argv[++a]; } else if (strncmp(arg, "-audit-interface", arglen) == 0) { char *interface = argv[++a]; if (osi_audit_interface(interface)) { printf("Invalid audit interface '%s'\n", interface); exit(1); } } else if (strcmp(arg, "-localfiles") == 0) lclpath = argv[++a]; else if (strcmp(arg, "-servers") == 0) debugOutput++, servers = 1; else if (strcmp(arg, "-noauth") == 0) debugOutput++, initFlags |= 1; else if (strcmp(arg, "-fastkeys") == 0) debugOutput++, initFlags |= 4; else if (strcmp(arg, "-dbfixup") == 0) debugOutput++, initFlags |= 8; else if (strcmp(arg, "-cellservdb") == 0) { cellservdb = argv[++a]; initFlags |= 2; debugOutput++; } else if (IsArg("-crypt")) level = rxkad_crypt; else if (IsArg("-safe")) level = rxkad_crypt; else if (IsArg("-clear")) level = rxkad_clear; else if (IsArg("-sorry")) level = rxkad_clear; else if (IsArg("-debug")) verbose_track = 0; else if (IsArg("-crossrealm")) krb4_cross = 1; else if (IsArg("-rxbind")) rxBind = 1; else if (IsArg("-minhours")) { MinHours = atoi(argv[++a]); } else if (IsArg("-enable_peer_stats")) { rx_enablePeerRPCStats(); } else if (IsArg("-enable_process_stats")) { rx_enableProcessRPCStats(); } else if (*arg == '-') { /* hack to support help flag */ goto usage; } } if (auditFileName) { osi_audit_file(auditFileName); } if ((code = ka_CellConfig(cellservdb))) goto abort; cell = ka_LocalCell(); KA_conf = afsconf_Open(cellservdb); if (!KA_conf) { code = KANOCELLS; abort: afs_com_err(whoami, code, "Failed getting cell info"); exit(1); } #ifdef AUTH_DBM_LOG kalog_Init(); #else /* NT & HPUX do not have dbm package support. So we can only do some * text logging. So open the AuthLog file for logging and redirect * stdin and stdout to it */ OpenLog(AFSDIR_SERVER_KALOG_FILEPATH); SetupLogSignals(); #endif fprintf(stderr, "%s: WARNING: kaserver is deprecated due to its weak security " "properties. Migrating to a Kerberos 5 KDC is advised. " "http://www.openafs.org/no-more-des.html\n", whoami); ViceLog(0, ("WARNING: kaserver is deprecated due to its weak security properties. " "Migrating to a Kerberos 5 KDC is advised. " "http://www.openafs.org/no-more-des.html\n")); code = afsconf_GetExtendedCellInfo(KA_conf, cell, AFSCONF_KAUTHSERVICE, &cellinfo, clones); if (servers) { if ((code = ubik_ParseServerList(argc, argv, &myHost, serverList))) { afs_com_err(whoami, code, "Couldn't parse server list"); exit(1); } cellinfo.hostAddr[0].sin_addr.s_addr = myHost; for (i = 1; i < MAXSERVERS; i++) { if (!serverList[i]) break; cellinfo.hostAddr[i].sin_addr.s_addr = serverList[i]; } cellinfo.numServers = i; } else { code = convert_cell_to_ubik(&cellinfo, &myHost, serverList); if (code) goto abort; ViceLog(0, ("Using server list from %s cell database.\n", cell)); } /* initialize audit user check */ osi_audit_set_user_check(KA_conf, KA_IsLocalRealmMatch); /* initialize ubik */ if (level == rxkad_clear) ubik_SetClientSecurityProcs(afsconf_ClientAuth, afsconf_UpToDate, KA_conf); else if (level == rxkad_crypt) ubik_SetClientSecurityProcs(afsconf_ClientAuthSecure, afsconf_UpToDate, KA_conf); else { ViceLog(0, ("Unsupported security level %d\n", level)); exit(5); } ViceLog(0, ("Using level %s for Ubik connections.\n", (level == rxkad_crypt ? "crypt" : "clear"))); ubik_SetServerSecurityProcs(afsconf_BuildServerSecurityObjects, afsconf_CheckAuth, KA_conf); ubik_nBuffers = 80; if (rxBind) { afs_int32 ccode; if (AFSDIR_SERVER_NETRESTRICT_FILEPATH || AFSDIR_SERVER_NETINFO_FILEPATH) { char reason[1024]; ccode = parseNetFiles(SHostAddrs, NULL, NULL, ADDRSPERSITE, reason, AFSDIR_SERVER_NETINFO_FILEPATH, AFSDIR_SERVER_NETRESTRICT_FILEPATH); } else { ccode = rx_getAllAddr(SHostAddrs, ADDRSPERSITE); } if (ccode == 1) { host = SHostAddrs[0]; rx_InitHost(host, htons(AFSCONF_KAUTHPORT)); } } /* Disable jumbograms */ rx_SetNoJumbo(); if (servers) code = ubik_ServerInit(myHost, htons(AFSCONF_KAUTHPORT), serverList, dbpath, &KA_dbase); else code = ubik_ServerInitByInfo(myHost, htons(AFSCONF_KAUTHPORT), &cellinfo, clones, dbpath, &KA_dbase); if (code) { afs_com_err(whoami, code, "Ubik init failed"); exit(2); } sca[RX_SCINDEX_NULL] = rxnull_NewServerSecurityObject(); tservice = rx_NewServiceHost(host, 0, KA_AUTHENTICATION_SERVICE, "AuthenticationService", sca, 1, KAA_ExecuteRequest); if (tservice == (struct rx_service *)0) { ViceLog(0, ("Could not create Authentication rx service\n")); exit(3); } rx_SetMinProcs(tservice, 1); rx_SetMaxProcs(tservice, 1); tservice = rx_NewServiceHost(host, 0, KA_TICKET_GRANTING_SERVICE, "TicketGrantingService", sca, 1, KAT_ExecuteRequest); if (tservice == (struct rx_service *)0) { ViceLog(0, ("Could not create Ticket Granting rx service\n")); exit(3); } rx_SetMinProcs(tservice, 1); rx_SetMaxProcs(tservice, 1); scm[RX_SCINDEX_NULL] = sca[RX_SCINDEX_NULL]; scm[RX_SCINDEX_VAB] = 0; scm[RX_SCINDEX_KAD] = rxkad_NewServerSecurityObject(rxkad_crypt, 0, kvno_admin_key, 0); tservice = rx_NewServiceHost(host, 0, KA_MAINTENANCE_SERVICE, "Maintenance", scm, 3, KAM_ExecuteRequest); if (tservice == (struct rx_service *)0) { ViceLog(0, ("Could not create Maintenance rx service\n")); exit(3); } rx_SetMinProcs(tservice, 1); rx_SetMaxProcs(tservice, 1); rx_SetStackSize(tservice, 10000); tservice = rx_NewServiceHost(host, 0, RX_STATS_SERVICE_ID, "rpcstats", scm, 3, RXSTATS_ExecuteRequest); if (tservice == (struct rx_service *)0) { ViceLog(0, ("Could not create rpc stats rx service\n")); exit(3); } rx_SetMinProcs(tservice, 2); rx_SetMaxProcs(tservice, 4); initialize_dstats(); /* allow super users to manage RX statistics */ rx_SetRxStatUserOk(KA_rxstat_userok); rx_StartServer(0); /* start handling req. of all types */ if (init_kaprocs(lclpath, initFlags)) return -1; if ((code = init_krb_udp())) { ViceLog(0, ("Failed to initialize UDP interface; code = %d.\n", code)); ViceLog(0, ("Running without UDP access.\n")); } ViceLog(0, ("Starting to process AuthServer requests\n")); rx_ServerProc(NULL); /* donate this LWP */ return 0; }
int main(int argc, char* argv[]) { if (argc > 1 && (IsArg(argv[1], "h") || IsArg(argv[1], "help") || IsArg(argv[1], "?"))) { Usage(argv[0]); return 0; } if (argc == 2 && (IsArg(argv[1], "v") || IsArg(argv[1], "version"))) { nsCAutoString milestone; nsCAutoString version; GetGREVersion(argv[0], &milestone, &version); Output(PR_FALSE, "Mozilla XULRunner %s - %s\n", milestone.get(), version.get()); return 0; } if (argc > 1) { nsCAutoString milestone; nsresult rv = GetGREVersion(argv[0], &milestone, nsnull); if (NS_FAILED(rv)) return 2; if (IsArg(argv[1], "gre-version")) { if (argc != 2) { Usage(argv[0]); return 1; } printf("%s\n", milestone.get()); return 0; } if (IsArg(argv[1], "install-app")) { if (argc < 3 || argc > 5) { Usage(argv[0]); return 1; } char *appLocation = argv[2]; char *installTo = nsnull; if (argc > 3) { installTo = argv[3]; if (!*installTo) // left blank? installTo = nsnull; } char *leafName = nsnull; if (argc > 4) { leafName = argv[4]; if (!*leafName) leafName = nsnull; } nsCOMPtr<nsIFile> regDir; rv = GetXULRunnerDir(argv[0], getter_AddRefs(regDir)); if (NS_FAILED(rv)) return 2; return InstallXULApp(regDir, appLocation, installTo, leafName); } } const char *appDataFile = PR_GetEnv("XUL_APP_FILE"); if (!(appDataFile && *appDataFile)) { if (argc < 2) { Usage(argv[0]); return 1; } if (IsArg(argv[1], "app")) { if (argc == 2) { Usage(argv[0]); return 1; } argv[1] = argv[0]; ++argv; --argc; } appDataFile = argv[1]; argv[1] = argv[0]; ++argv; --argc; static char kAppEnv[MAXPATHLEN]; PR_snprintf(kAppEnv, MAXPATHLEN, "XUL_APP_FILE=%s", appDataFile); PR_SetEnv(kAppEnv); } nsCOMPtr<nsILocalFile> appDataLF; nsresult rv = XRE_GetFileFromPath(appDataFile, getter_AddRefs(appDataLF)); if (NS_FAILED(rv)) { Output(PR_TRUE, "Error: unrecognized application.ini path.\n"); return 2; } AutoAppData appData(appDataLF); if (!appData) { Output(PR_TRUE, "Error: couldn't parse application.ini.\n"); return 2; } return XRE_main(argc, argv, appData); }
int main(int argc, char* argv[]) { //argv 1 should be a valid filename, and argv 2 is optionally something that a output stream //can be opened against. after that, options. if(argc < 2 || IsArg(argv[1])) { Help(); return 0; } bool bFileout = argc >2 && !IsArg(argv[2]); //check input file can be opened std::ifstream in(argv[1], std::ios_base::binary); if(!in.is_open()) { tcout << "couldn't open " << argv[1] << " for reading.\n\n"; Help(); return 0; } //check output file can be opened std::ofstream outfile; if(bFileout) { outfile.open(argv[2], std::ios_base::trunc); if(!outfile.is_open()) { tcout << "couldn't open " << argv[2] << "for writing.\n\n"; Help(); in.close(); return 0; } } //stream to the output file, or std out if no file was provided std::ostream& out = outfile.is_open() ? outfile : std::cout; Arguments A; ReadArgs(argc, bFileout ? 2:1, argv, A); //write out pre-amble //insert a comment to indicate that this file was auto generated from some other file { char out_buffer[1024]; sprintf(out_buffer, kCommentFormat, argv[1]); int sprintf_count = strlen(out_buffer); out.write(out_buffer, sprintf_count); } bool bWroteNamespace = false; if(!A.ns.empty()) { char out_buffer[1024]; sprintf(out_buffer, kNamespaceFormat, A.ns.c_str()); int sprintf_count = strlen(out_buffer); out.write(out_buffer, sprintf_count); bWroteNamespace = true; } //usual cheese to get file size in.seekg(0, std::ios_base::end); size_t filesize = in.tellg(); in.seekg(0, std::ios_base::beg); //same trick as for namespace to get the id out { char out_buffer[1024]; sprintf(out_buffer, kIdentifierFormat, A.id.c_str()); int sprintf_count = strlen(out_buffer); //array size, for use in code out << "const unsigned short "; out.write(out_buffer, sprintf_count); out << "_len = " << filesize << ";" << std::endl; //and now, the array out << "const unsigned char "; out.write(out_buffer, sprintf_count); } out << "[" << filesize << "] PROGMEM = {\n\t"; //stream the data through int restart = 0; for(unsigned i=0; i<filesize; ) { static const size_t bufferLen = 1024; //buffer has to be unsigned for the sprintf to work as required. unsigned char in_buffer[bufferLen]; const size_t chunk = i+bufferLen < filesize ? bufferLen : filesize-i; in.read(reinterpret_cast<char*>(in_buffer), chunk); for(unsigned j=0; j<chunk; ++j) { char out_buffer[128]; sprintf(out_buffer, "0x%.2hX,", in_buffer[j]); out << out_buffer; ++restart; if(restart > 10) { out << "\n\t"; restart = 0; } } i += chunk; } //post-amble - close array, then namespace out << "\n};\n"; if(bWroteNamespace) { out << "}//end namespace\n"; } if(outfile.is_open()) outfile.close(); in.close(); return 0; }
int main(int argc, char* argv[]) { bool LongFlag=false; bool HierFlag=true; int ResetUsage=0; int DeleteUser=0; int SetFactor=0; int SetPrio=0; int SetAccum=0; int SetBegin=0; int SetLast=0; bool ResetAll=false; int GetResList=0; std::string pool; bool GroupRollup = false; myDistro->Init( argc, argv ); config(); MinLastUsageTime=time(0)-60*60*24; // Default to show only users active in the last day for (int i=1; i<argc; i++) { if (IsArg(argv[i],"setprio")) { if (i+2>=argc) usage(argv[0]); SetPrio=i; i+=2; } else if (IsArg(argv[i],"setfactor")) { if (i+2>=argc) usage(argv[0]); SetFactor=i; i+=2; } else if (IsArg(argv[i],"setbegin")) { if (i+2>=argc) usage(argv[0]); SetBegin=i; i+=2; } else if (IsArg(argv[i],"setaccum")) { if (i+2>=argc) usage(argv[0]); SetAccum=i; i+=2; } else if (IsArg(argv[i],"setlast")) { if (i+2>=argc) usage(argv[0]); SetLast=i; i+=2; } else if (IsArg(argv[i],"resetusage")) { if (i+1>=argc) usage(argv[0]); ResetUsage=i; i+=1; } else if (IsArg(argv[i],"delete",3)) { if (i+1>=argc) usage(argv[0]); DeleteUser=i; i+=1; } else if (IsArg(argv[i],"resetall")) { ResetAll=true; } else if (IsArg(argv[i],"long",1)) { LongFlag=true; } else if (IsArg(argv[i],"hierarchical",2) || IsArg(argv[i],"heir")) { HierFlag=true; DashHier=true; } else if (IsArg(argv[i],"flat",2)) { HierFlag=false; DashHier=true; } else if (IsArg(argv[i],"grouprollup")) { GroupRollup=true; } else if (IsArg(argv[i],"grouporder")) { GroupOrder=true; HierFlag = false; DashHier = true; } else if (IsArg(argv[i],"quotas",1)) { DetailFlag |= DetailQuotas; DashQuota = true; } else if (IsArg(argv[i],"surplus")) { DetailFlag |= DetailSurplus; DashQuota = true; } else if (IsArg(argv[i],"sortkey",2)) { DetailFlag |= DetailSortKey; DashSortKey = true; } else if (IsArg(argv[i],"all")) { DetailFlag |= DetailAll; DashAll = true; } else if (IsArg(argv[i],"most",2)) { DetailFlag |= DetailMost; #ifdef DEBUG DetailFlag |= DetailGroup; #endif DashAll = true; } else if (IsArg(argv[i],"groupid")) { DetailFlag |= DetailGroup; } else if (IsArg(argv[i],"order")) { DetailFlag |= DetailOrder; } else if (IsArg(argv[i],"activefrom")) { if (argc-i<=3) usage(argv[0]); int month=atoi(argv[i+1]); int day=atoi(argv[i+2]); int year=atoi(argv[i+3]); MinLastUsageTime=CalcTime(month,day,year); // printf("Date translation: %d/%d/%d = %d\n",month,day,year,FromDate); i+=3; } else if (IsArg(argv[i],"allusers")) { MinLastUsageTime=-1; } else if (IsArg(argv[i],"usage",2)) { DetailFlag |= DetailUsage | DetailUseTime1 | DetailUseTime2; } else if (IsArg(argv[i],"priority",4)) { DetailFlag |= DetailPrios; } else if (IsArg(argv[i],"getreslist",6)) { if (argc-i<=1) usage(argv[0]); GetResList=i; i+=1; } else if (IsArg(argv[i],"pool",1)) { if (argc-i<=1) usage(argv[0]); pool = argv[i+1]; i++; } else { usage(argv[0]); } } //---------------------------------------------------------- // Get info on our negotiator Daemon negotiator(DT_NEGOTIATOR, NULL, (pool != "") ? pool.c_str() : NULL); if (!negotiator.locate()) { fprintf(stderr, "%s: Can't locate negotiator in %s\n", argv[0], (pool != "") ? pool.c_str() : "local pool"); exit(1); } if (SetPrio) { // set priority char* tmp; if( ! (tmp = strchr(argv[SetPrio+1], '@')) ) { fprintf( stderr, "%s: You must specify the full name of the submittor you wish\n", argv[0] ); fprintf( stderr, "\tto update the priority of (%s or %s)\n", "*****@*****.**", "*****@*****.**" ); exit(1); } float Priority=atof(argv[SetPrio+2]); // send request Sock* sock; if( !(sock = negotiator.startCommand(SET_PRIORITY, Stream::reli_sock, 0) ) || !sock->put(argv[SetPrio+1]) || !sock->put(Priority) || !sock->end_of_message()) { fprintf( stderr, "failed to send SET_PRIORITY command to negotiator\n" ); exit(1); } sock->close(); delete sock; printf("The priority of %s was set to %f\n",argv[SetPrio+1],Priority); } else if (SetFactor) { // set priority char* tmp; if( ! (tmp = strchr(argv[SetFactor+1], '@')) ) { fprintf( stderr, "%s: You must specify the full name of the submittor you wish\n", argv[0] ); fprintf( stderr, "\tto update the priority of (%s or %s)\n", "*****@*****.**", "*****@*****.**" ); exit(1); } float Factor=atof(argv[SetFactor+2]); if (Factor<1) { fprintf( stderr, "Priority factors must be greater than or equal to " "1.\n"); exit(1); } // send request Sock* sock; if( !(sock = negotiator.startCommand(SET_PRIORITYFACTOR, Stream::reli_sock, 0) ) || !sock->put(argv[SetFactor+1]) || !sock->put(Factor) || !sock->end_of_message()) { fprintf( stderr, "failed to send SET_PRIORITYFACTOR command to negotiator\n" ); exit(1); } sock->close(); delete sock; printf("The priority factor of %s was set to %f\n",argv[SetFactor+1],Factor); } else if (SetAccum) { // set accumulated usage char* tmp; if( ! (tmp = strchr(argv[SetAccum+1], '@')) ) { fprintf( stderr, "%s: You must specify the full name of the submittor you wish\n", argv[0] ); fprintf( stderr, "\tto update the Accumulated usage of (%s or %s)\n", "*****@*****.**", "*****@*****.**" ); exit(1); } float accumUsage=atof(argv[SetAccum+2]); if (accumUsage<0.0) { fprintf( stderr, "Usage must be greater than 0 seconds\n"); exit(1); } // send request Sock* sock; if( !(sock = negotiator.startCommand(SET_ACCUMUSAGE, Stream::reli_sock, 0) ) || !sock->put(argv[SetAccum+1]) || !sock->put(accumUsage) || !sock->end_of_message()) { fprintf( stderr, "failed to send SET_ACCUMUSAGE command to negotiator\n" ); exit(1); } sock->close(); delete sock; printf("The Accumulated Usage of %s was set to %f\n",argv[SetAccum+1],accumUsage); } else if (SetBegin) { // set begin usage time char* tmp; if( ! (tmp = strchr(argv[SetBegin+1], '@')) ) { fprintf( stderr, "%s: You must specify the full name of the submittor you wish\n", argv[0] ); fprintf( stderr, "\tto update the begin usage time of (%s or %s)\n", "*****@*****.**", "*****@*****.**" ); exit(1); } int beginTime=atoi(argv[SetBegin+2]); if (beginTime<0) { fprintf( stderr, "Time must be greater than 0 seconds\n"); exit(1); } // send request Sock* sock; if( !(sock = negotiator.startCommand(SET_BEGINTIME, Stream::reli_sock, 0) ) || !sock->put(argv[SetBegin+1]) || !sock->put(beginTime) || !sock->end_of_message()) { fprintf( stderr, "failed to send SET_BEGINTIME command to negotiator\n" ); exit(1); } sock->close(); delete sock; printf("The Begin Usage Time of %s was set to %d\n", argv[SetBegin+1],beginTime); } else if (SetLast) { // set last usage time char* tmp; if( ! (tmp = strchr(argv[SetLast+1], '@')) ) { fprintf( stderr, "%s: You must specify the full name of the submittor you wish\n", argv[0] ); fprintf( stderr, "\tto update the last usage time of (%s or %s)\n", "*****@*****.**", "*****@*****.**" ); exit(1); } int lastTime=atoi(argv[SetLast+2]); if (lastTime<0) { fprintf( stderr, "Time must be greater than 0 seconds\n"); exit(1); } // send request Sock* sock; if( !(sock = negotiator.startCommand(SET_LASTTIME, Stream::reli_sock, 0) ) || !sock->put(argv[SetLast+1]) || !sock->put(lastTime) || !sock->end_of_message()) { fprintf( stderr, "failed to send SET_LASTTIME command to negotiator\n" ); exit(1); } sock->close(); delete sock; printf("The Last Usage Time of %s was set to %d\n", argv[SetLast+1],lastTime); } else if (ResetUsage) { // set priority char* tmp; if( ! (tmp = strchr(argv[ResetUsage+1], '@')) ) { fprintf( stderr, "%s: You must specify the full name of the submittor you wish\n", argv[0] ); fprintf( stderr, "\tto update the priority of (%s or %s)\n", "*****@*****.**", "*****@*****.**" ); exit(1); } // send request Sock* sock; if( !(sock = negotiator.startCommand(RESET_USAGE, Stream::reli_sock, 0) ) || !sock->put(argv[ResetUsage+1]) || !sock->end_of_message()) { fprintf( stderr, "failed to send RESET_USAGE command to negotiator\n" ); exit(1); } sock->close(); delete sock; printf("The accumulated usage of %s was reset\n",argv[ResetUsage+1]); } else if (DeleteUser) { // remove a user record from the accountant char* tmp; if( ! (tmp = strchr(argv[DeleteUser+1], '@')) ) { fprintf( stderr, "%s: You must specify the full name of the record you wish\n", argv[0] ); fprintf( stderr, "\tto delete (%s or %s)\n", "*****@*****.**", "*****@*****.**" ); exit(1); } // send request Sock* sock; if( !(sock = negotiator.startCommand(DELETE_USER, Stream::reli_sock, 0) ) || !sock->put(argv[DeleteUser+1]) || !sock->end_of_message()) { fprintf( stderr, "failed to send DELETE_USER command to negotiator\n" ); exit(1); } sock->close(); delete sock; printf("The accountant record named %s was deleted\n",argv[DeleteUser+1]); } else if (ResetAll) { // send request if( ! negotiator.sendCommand(RESET_ALL_USAGE, Stream::reli_sock, 0) ) { fprintf( stderr, "failed to send RESET_ALL_USAGE command to negotiator\n" ); exit(1); } printf("The accumulated usage was reset for all users\n"); } else if (GetResList) { // get resource list char* tmp; if( ! (tmp = strchr(argv[GetResList+1], '@')) ) { fprintf( stderr, "%s: You must specify the full name of the submittor you wish\n", argv[0] ); fprintf( stderr, "\tto update the priority of (%s or %s)\n", "*****@*****.**", "*****@*****.**" ); exit(1); } // send request Sock* sock; if( !(sock = negotiator.startCommand(GET_RESLIST, Stream::reli_sock, 0) ) || !sock->put(argv[GetResList+1]) || !sock->end_of_message()) { fprintf( stderr, "failed to send GET_RESLIST command to negotiator\n" ); exit(1); } // get reply sock->decode(); AttrList* ad=new AttrList(); if (!ad->initAttrListFromStream(*sock) || !sock->end_of_message()) { fprintf( stderr, "failed to get classad from negotiator\n" ); exit(1); } sock->close(); delete sock; if (LongFlag) ad->fPrint(stdout); else PrintResList(ad); } else { // list priorities Sock* sock; if (!(sock = negotiator.startCommand((GroupRollup) ? GET_PRIORITY_ROLLUP : GET_PRIORITY, Stream::reli_sock, 0)) || !sock->end_of_message()) { fprintf(stderr, "failed to send %s command to negotiator\n", (GroupRollup) ? "GET_PRIORITY_ROLLUP" : "GET_PRIORITY"); exit(1); } // get reply sock->decode(); AttrList* ad=new AttrList(); if (!ad->initAttrListFromStream(*sock) || !sock->end_of_message()) { fprintf( stderr, "failed to get classad from negotiator\n" ); exit(1); } sock->close(); delete sock; // if no details specified, show priorities if ( ! DetailFlag) { DetailFlag = DetailDefault; #ifdef DEBUG DetailFlag |= DetailGroup; #endif } // if showing only prio, don't bother showing groups if ( ! (DetailFlag & ~DetailPrios) && GroupPrioIsMeaningless) { if ( ! DashHier ) HierFlag = false; HideGroups = !HierFlag; } if (LongFlag) ad->fPrint(stdout); else ProcessInfo(ad,GroupRollup,HierFlag); } exit(0); return 0; }
int main(int argc, char **argv) { register afs_int32 code; char op[8]; char name[PR_MAXNAMELEN]; afs_int32 id, oid = ANONYMOUSID, gid; afs_int32 pos; unsigned int i; int n; struct prentry entry; prlist alist; idlist lid; namelist lnames; struct hostent *hostinfo; struct in_addr *hostaddr; afs_int32 *ptr; char *foo; afs_int32 over; char *cell; #ifdef AFS_AIX32_ENV /* * The following signal action for AIX is necessary so that in case of a * crash (i.e. core is generated) we can include the user's data section * in the core dump. Unfortunately, by default, only a partial core is * generated which, in many cases, isn't too useful. */ struct sigaction nsa; sigemptyset(&nsa.sa_mask); nsa.sa_handler = SIG_DFL; nsa.sa_flags = SA_FULLDUMP; sigaction(SIGSEGV, &nsa, NULL); #endif whoami = argv[0]; initialize_PT_error_table(); strcpy(confdir, AFSDIR_CLIENT_ETC_DIRPATH); cell = 0; n = 1; while (n < argc) { int arglen = strlen(argv[n]); char arg[256]; lcstring(arg, argv[n], sizeof(arg)); #define IsArg(a) (strncmp (arg,a, arglen) == 0) if (IsArg("-testconfdir")) strncpy(confdir, argv[++n], sizeof(confdir)); else if (IsArg("client")) strncpy(confdir, AFSDIR_CLIENT_ETC_DIRPATH, sizeof(confdir)); else if (IsArg("server")) strncpy(confdir, AFSDIR_SERVER_ETC_DIRPATH, sizeof(confdir)); else if (IsArg("0") || IsArg("1") || IsArg("2")) security = atoi(argv[n]); else if (IsArg("-ignoreexist")) ignoreExist++; else if (IsArg("-cell")) cell = argv[++n]; else { printf ("Usage is: 'prclient [-testconfdir <dir> | server | client] [0 | 1 | 2] [-ignoreExist] [-cell <cellname>]\n"); exit(1); } n++; } printf("Using CellServDB file in %s\n", confdir); if (security == 0) printf("Making unauthenticated connection to prserver\n"); code = pr_Initialize(security, confdir, cell); if (code) { afs_com_err(whoami, code, "Couldn't initialize protection library"); exit(1); } while (1) { char *s; printf("pr> "); s = fgets(line, sizeof(line), stdin); if (s == NULL) break; lineProgress = 0; code = GetString(op, sizeof(op)); if (code) { afs_com_err(whoami, PRBADARG, "error reading opcode in line '%s', got '%.*s'", line, sizeof(op), op); exit(1); } if (strlen(op) == 0) continue; /* no input */ if (!strcmp(op, "cr")) { if (GetString(name, sizeof(name)) || GetInt32(&id) || GetInt32(&oid)) code = PRBADARG; /* use ubik_Call to do the work, finding an up server and handling * the job of finding a sync site, if need be */ else code = ubik_PR_INewEntry(pruclient, 0, name, id, oid); if (CodeOk(code)) afs_com_err(whoami, code, "on %s %s %d %d", op, name, id, oid); } else if (!strcmp(op, "sf")) { afs_int32 mask, access, gq, uq; if (GetInt32(&id) || GetXInt32(&mask) || GetXInt32(&access) || GetInt32(&gq) || GetInt32(&uq)) code = PRBADARG; else code = ubik_PR_SetFieldsEntry(pruclient, 0, id, mask, access, gq, uq, 0, 0); if (CodeOk(code)) afs_com_err(whoami, code, "on %s %d %x %x %d %d", op, id, mask, access, gq, uq); } else if (!strcmp(op, "ce")) { char newname[PR_MAXNAMELEN]; afs_int32 newid; if (GetInt32(&id) || GetString(newname, sizeof(newname)) || GetInt32(&oid) || GetInt32(&newid)) code = PRBADARG; else code = ubik_PR_ChangeEntry(pruclient, 0, id, newname, oid, newid); if (CodeOk(code)) afs_com_err(whoami, code, "on %s %d %s %d %d", op, id, newname, oid, newid); } else if (!strcmp(op, "wh")) { /* scanf("%d",&id); */ if (GetInt32(&id)) code = PRBADARG; else code = ubik_PR_WhereIsIt(pruclient, 0, id, &pos); if (CodeOk(code)) printf("%s\n", pr_ErrorMsg(code)); else printf("location %d\n", pos); } else if (!strcmp(op, "du")) { memset(&entry, 0, sizeof(entry)); /* scanf("%d",&pos); */ if (GetInt32(&pos)) code = PRBADARG; else code = ubik_PR_DumpEntry(pruclient, 0, pos, (struct prdebugentry *)&entry); if (CodeOk(code)) printf("%s\n", pr_ErrorMsg(code)); if (code == PRSUCCESS) { PrintEntry(pos, &entry, /*indent */ 0); #if 0 printf("The contents of the entry for %d are:\n", entry.id); printf("flags %d next %d\n", entry.flags, entry.next); printf("Groups (or members) \n"); for (i = 0; i < PRSIZE; i++) printf("%d\n", entry.entries[i]); printf("nextID %d nextname %d name %s\n", entry.nextID, entry.nextName, entry.name); printf("owner %d creator %d\n", entry.owner, entry.creator); #endif } } else if (!strcmp(op, "add") || !strcmp(op, "au")) { /* scanf("%d %d",&id,&gid); */ if (GetInt32(&id) || GetInt32(&gid)) code = PRBADARG; else code = ubik_PR_AddToGroup(pruclient, 0, id, gid); if (CodeOk(code)) afs_com_err(whoami, code, "on %s %d %d", op, id, gid); } else if (!strcmp(op, "iton")) { lid.idlist_val = (afs_int32 *) malloc(20 * sizeof(afs_int32)); ptr = lid.idlist_val; lid.idlist_len = 0; foo = line; skip(&foo); while ((lid.idlist_len < 20) && (sscanf(foo, "%d", ptr) != EOF)) { lid.idlist_len++; skip(&foo); ptr++; } if (*foo) { fprintf(stderr, "too many values specified; max is %d\n", 20); } lnames.namelist_val = 0; lnames.namelist_len = 0; code = ubik_PR_IDToName(pruclient, 0, &lid, &lnames); if (CodeOk(code)) printf("%s\n", pr_ErrorMsg(code)); if (code == PRSUCCESS) { for (i = 0; i < lnames.namelist_len; i++) { printf("id %d name %s\n", lid.idlist_val[i], lnames.namelist_val[i]); } free(lnames.namelist_val); } free(lid.idlist_val); lid.idlist_val = 0; lid.idlist_len = 0; } else if (!strcmp(op, "ntoi")) { lnames.namelist_val = (prname *) malloc(PR_MAXLIST * PR_MAXNAMELEN); lnames.namelist_len = 0; foo = line; skip(&foo); for (i = 0; ((lnames.namelist_len < PR_MAXLIST) && (sscanf(foo, "%s", lnames.namelist_val[i]) != EOF)); i++) { lnames.namelist_len++; skip(&foo); } if (*foo) { fprintf(stderr, "too many values specified; max is %d\n", PR_MAXLIST); } lid.idlist_val = 0; lid.idlist_len = 0; code = ubik_PR_NameToID(pruclient, 0, &lnames, &lid); if (CodeOk(code)) printf("%s\n", pr_ErrorMsg(code)); if (code == PRSUCCESS) { for (i = 0; i < lid.idlist_len; i++) printf("name %s id %d\n", lnames.namelist_val[i], lid.idlist_val[i]); free(lid.idlist_val); } free(lnames.namelist_val); lnames.namelist_val = 0; lnames.namelist_len = 0; } else if (!strcmp(op, "del")) { /* scanf("%d",&id); */ if (GetInt32(&id)) code = PRBADARG; else code = ubik_PR_Delete(pruclient, 0, id); if (CodeOk(code)) printf("%s\n", pr_ErrorMsg(code)); } else if (!strcmp(op, "dg")) { /* scanf("%d",&id); */ if (GetInt32(&id)) code = PRBADARG; else code = ubik_PR_Delete(pruclient, 0, id); if (CodeOk(code)) printf("%s\n", pr_ErrorMsg(code)); } else if (!strcmp(op, "rm")) { /* scanf("%d %d",&id,&gid); */ if (GetInt32(&id) || GetInt32(&gid)) code = PRBADARG; else code = ubik_PR_RemoveFromGroup(pruclient, 0, id, gid); if (CodeOk(code)) printf("%s\n", pr_ErrorMsg(code)); } #if defined(SUPERGROUPS) else if (!strcmp(op, "lsg")) { alist.prlist_len = 0; alist.prlist_val = 0; /* scanf("%d",&id); */ if (GetInt32(&id)) code = PRBADARG; else code = ubik_PR_ListSuperGroups(pruclient, 0, id, &alist, &over); if (CodeOk(code)) printf("%s\n", pr_ErrorMsg(code)); if (code == PRSUCCESS) { ptr = alist.prlist_val; if (over) { printf("Number of groups greater than PR_MAXGROUPS!\n"); printf("Excess of %d.\n", over); } for (i = 0; i < alist.prlist_len; i++, ptr++) printf("%d\n", *ptr); free(alist.prlist_val); alist.prlist_len = 0; alist.prlist_val = 0; } } #endif /* SUPERGROUPS */ else if (!strcmp(op, "l")) { alist.prlist_len = 0; alist.prlist_val = 0; /* scanf("%d",&id); */ if (GetInt32(&id)) code = PRBADARG; else code = ubik_PR_GetCPS(pruclient, 0, id, &alist, &over); if (CodeOk(code)) printf("%s\n", pr_ErrorMsg(code)); if (code == PRSUCCESS) { ptr = alist.prlist_val; if (over) { printf("Number of groups greater than PR_MAXGROUPS!\n"); printf("Excess of %d.\n", over); } for (i = 0; i < alist.prlist_len; i++, ptr++) printf("%d\n", *ptr); free(alist.prlist_val); alist.prlist_len = 0; alist.prlist_val = 0; } } else if (!strcmp(op, "lh")) { alist.prlist_len = 0; alist.prlist_val = 0; /* scanf("%d",&id); */ if (GetString(name, sizeof(name))) code = PRBADARG; else if (!(hostinfo = gethostbyname(name))) code = PRBADARG; else { hostaddr = (struct in_addr *)hostinfo->h_addr_list[0]; id = ntohl(hostaddr->s_addr); code = ubik_PR_GetHostCPS(pruclient, 0, id, &alist, &over); } if (CodeOk(code)) printf("%s\n", pr_ErrorMsg(code)); if (code == PRSUCCESS) { ptr = alist.prlist_val; if (over) { printf("Number of groups greater than PR_MAXGROUPS!\n"); printf("Excess of %d.\n", over); } for (i = 0; i < alist.prlist_len; i++, ptr++) printf("%d\n", *ptr); free(alist.prlist_val); alist.prlist_len = 0; alist.prlist_val = 0; } } #if defined(SUPERGROUPS) else if (!strcmp(op, "m")) { alist.prlist_len = 0; alist.prlist_val = 0; /* scanf("%d",&id); */ if (GetInt32(&id)) code = PRBADARG; else code = ubik_PR_ListElements(pruclient, 0, id, &alist, &over); if (CodeOk(code)) printf("%s\n", pr_ErrorMsg(code)); if (code == PRSUCCESS) { ptr = alist.prlist_val; if (over) { printf("Number of groups greater than PR_MAXGROUPS!\n"); printf("Excess of %d.\n", over); } for (i = 0; i < alist.prlist_len; i++, ptr++) printf("%d\n", *ptr); free(alist.prlist_val); alist.prlist_len = 0; alist.prlist_val = 0; } } #endif /* SUPERGROUPS */ else if (!strcmp(op, "nu")) { /* scanf("%s",name); */ if (GetString(name, sizeof(name))) code = PRBADARG; else code = pr_CreateUser(name, &id); if (CodeOk(code)) printf("%s\n", pr_ErrorMsg(code)); if (code == PRSUCCESS) printf("Id is %d.\n", id); } else if (!strcmp(op, "ng")) { /* scanf("%s",name); */ if (GetString(name, sizeof(name))) code = PRBADARG; else code = ubik_PR_NewEntry(pruclient, 0, name, 1, oid, &id); if (CodeOk(code)) printf("%s\n", pr_ErrorMsg(code)); if (code == PRSUCCESS) printf("Id is %d.\n", id); } else if (!strcmp(op, "lm")) { code = ubik_PR_ListMax(pruclient, 0, &id, &gid); if (CodeOk(code)) printf("%s\n", pr_ErrorMsg(code)); if (code == PRSUCCESS) printf("Max user id is %d, max (really min) group is %d.\n", id, gid); } else if (!strcmp(op, "smu")) { /* scanf("%d",&id); */ if (GetInt32(&id)) code = PRBADARG; else code = ubik_PR_SetMax(pruclient, 0, id, 0); if (CodeOk(code)) printf("%s\n", pr_ErrorMsg(code)); } else if (!strcmp(op, "smg")) { /* scanf("%d",&id); */ if (GetInt32(&id)) code = PRBADARG; else code = ubik_PR_SetMax(pruclient, 0, id, 1); if (CodeOk(code)) printf("%s\n", pr_ErrorMsg(code)); } else if (!strcmp(op, "sin")) { /* scanf("%d",&id); */ if (GetInt32(&id)) code = PRBADARG; else code = pr_SIdToName(id, name); if (CodeOk(code)) printf("%s\n", pr_ErrorMsg(code)); if (code == PRSUCCESS) printf("id %d name %s\n", id, name); } else if (!strcmp(op, "sni")) { /* scanf("%s",name); */ if (GetString(name, sizeof(name))) code = PRBADARG; else code = pr_SNameToId(name, &id); if (CodeOk(code)) printf("%s\n", pr_ErrorMsg(code)); if (code == PRSUCCESS) printf("name %s id %d\n", name, id); } else if (!strcmp(op, "fih")) { char tname[128]; struct PrUpdateEntry uentry; memset(&uentry, 0, sizeof(uentry)); /* scanf("%s",name); */ if (GetString(name, sizeof(name))) { code = PRBADARG; continue; } code = pr_SNameToId(name, &id); if (CodeOk(code)) { printf("%s\n", pr_ErrorMsg(code)); continue; } code = pr_SIdToName(id, tname); if (code == PRSUCCESS) { printf ("Warning: Id hash for %s (id %d) seems correct at the db; rehashing it anyway\n", name, id); /* continue;*/ } uentry.Mask = PRUPDATE_IDHASH; code = ubik_PR_UpdateEntry(pruclient, 0, 0, name, &uentry); if (code) { printf("Failed to update entry %s (err=%d)\n", name, code); continue; } } else if (!strcmp(op, "fnh")) { int tid; struct PrUpdateEntry uentry; memset(&uentry, 0, sizeof(uentry)); /* scanf("%d", &id); */ if (GetInt32(&id)) { code = PRBADARG; continue; } code = pr_SIdToName(id, name); if (CodeOk(code)) { printf("%s\n", pr_ErrorMsg(code)); continue; } code = pr_SNameToId(name, &tid); if (code == PRSUCCESS) { printf ("Name hash for %d (name is %s) seems correct at the db; rehashing it anyway\n", id, name); /* continue;*/ } uentry.Mask = PRUPDATE_NAMEHASH; code = ubik_PR_UpdateEntry(pruclient, 0, id, "_foo_", &uentry); if (code) { printf("Failed to update entry with id %d (err=%d)\n", id, code); continue; } } #if defined(SUPERGROUPS) else if (!strcmp(op, "fih")) { char tname[128]; struct PrUpdateEntry uentry; memset(&uentry, 0, sizeof(uentry)); /* scanf("%s",name); */ if (GetString(name, sizeof(name))) { code = PRBADARG; continue; } code = pr_SNameToId(name, &id); if (CodeOk(code)) { printf("%s\n", pr_ErrorMsg(code)); continue; } code = pr_SIdToName(id, tname); if (code == PRSUCCESS) { printf ("Warning: Id hash for %s (id %d) seems correct at the db; rehashing it anyway\n", name, id); /* continue;*/ } uentry.Mask = PRUPDATE_IDHASH; code = ubik_PR_UpdateEntry(pruclient, 0, 0, name, &uentry); if (code) { printf("Failed to update entry %s (err=%d)\n", name, code); continue; } } else if (!strcmp(op, "fnh")) { int tid; struct PrUpdateEntry uentry; memset(&uentry, 0, sizeof(uentry)); /* scanf("%d", &id); */ if (GetInt32(&id)) { code = PRBADARG; continue; } code = pr_SIdToName(id, name); if (CodeOk(code)) { printf("%s\n", pr_ErrorMsg(code)); continue; } code = pr_SNameToId(name, &tid); if (code == PRSUCCESS) { printf ("Name hash for %d (name is %s) seems correct at the db; rehashing it anyway\n", id, name); /* continue;*/ } uentry.Mask = PRUPDATE_NAMEHASH; code = ubik_PR_UpdateEntry(pruclient, 0, id, "_foo_", &uentry); if (code) { printf("Failed to update entry with id %d (err=%d)\n", id, code); continue; } } #endif /* SUPERGROUPS */ else if (!strcmp(op, "?")) PrintHelp(); else if (!strcmp(op, "q")) exit(0); else printf("Unknown op: '%s'! ? for help\n", op); } }
int main(int argc, char **argv) { nsresult rv; char *lastSlash; char iniPath[MAXPATHLEN]; char tmpPath[MAXPATHLEN]; char greDir[MAXPATHLEN]; PRBool greFound = PR_FALSE; #if defined(XP_MACOSX) CFBundleRef appBundle = CFBundleGetMainBundle(); if (!appBundle) return 1; CFURLRef resourcesURL = CFBundleCopyResourcesDirectoryURL(appBundle); if (!resourcesURL) return 1; CFURLRef absResourcesURL = CFURLCopyAbsoluteURL(resourcesURL); CFRelease(resourcesURL); if (!absResourcesURL) return 1; CFURLRef iniFileURL = CFURLCreateCopyAppendingPathComponent(kCFAllocatorDefault, absResourcesURL, CFSTR("application.ini"), false); CFRelease(absResourcesURL); if (!iniFileURL) return 1; CFStringRef iniPathStr = CFURLCopyFileSystemPath(iniFileURL, kCFURLPOSIXPathStyle); CFRelease(iniFileURL); if (!iniPathStr) return 1; CFStringGetCString(iniPathStr, iniPath, sizeof(iniPath), kCFStringEncodingUTF8); CFRelease(iniPathStr); #else #ifdef XP_WIN wchar_t wide_path[MAX_PATH]; if (!::GetModuleFileNameW(NULL, wide_path, MAX_PATH)) return 1; WideCharToMultiByte(CP_UTF8, 0, wide_path,-1, iniPath, MAX_PATH, NULL, NULL); #elif defined(XP_OS2) PPIB ppib; PTIB ptib; DosGetInfoBlocks(&ptib, &ppib); DosQueryModuleName(ppib->pib_hmte, sizeof(iniPath), iniPath); #elif defined(XP_BEOS) BEntry e((const char *)argv[0], true); // traverse symlink BPath p; status_t err; err = e.GetPath(&p); NS_ASSERTION(err == B_OK, "realpath failed"); if (err == B_OK) // p.Path returns a pointer, so use strcpy to store path in iniPath strcpy(iniPath, p.Path()); #else // on unix, there is no official way to get the path of the current binary. // instead of using the MOZILLA_FIVE_HOME hack, which doesn't scale to // multiple applications, we will try a series of techniques: // // 1) use realpath() on argv[0], which works unless we're loaded from the // PATH // 2) manually walk through the PATH and look for ourself // 3) give up struct stat fileStat; if (!realpath(argv[0], iniPath) || stat(iniPath, &fileStat)) { const char *path = getenv("PATH"); if (!path) return 1; char *pathdup = strdup(path); if (!pathdup) return 1; PRBool found = PR_FALSE; char *token = strtok(pathdup, ":"); while (token) { sprintf(tmpPath, "%s/%s", token, argv[0]); if (realpath(tmpPath, iniPath) && stat(iniPath, &fileStat) == 0) { found = PR_TRUE; break; } token = strtok(NULL, ":"); } free (pathdup); if (!found) return 1; } #endif lastSlash = strrchr(iniPath, PATH_SEPARATOR_CHAR); if (!lastSlash) return 1; *(++lastSlash) = '\0'; // On Linux/Win, look for XULRunner in appdir/xulrunner snprintf(greDir, sizeof(greDir), "%sxulrunner" XPCOM_FILE_PATH_SEPARATOR XPCOM_DLL, iniPath); greFound = FolderExists(greDir); strncpy(lastSlash, "application.ini", sizeof(iniPath) - (lastSlash - iniPath)); #endif // If -app parameter was passed in, it is now time to take it under // consideration. const char *appDataFile; appDataFile = getenv("XUL_APP_FILE"); if (!appDataFile || !*appDataFile) if (argc > 1 && IsArg(argv[1], "app")) { if (argc == 2) { Output(PR_FALSE, "specify APP-FILE (optional)\n"); return 1; } argv[1] = argv[0]; ++argv; --argc; appDataFile = argv[1]; argv[1] = argv[0]; ++argv; --argc; char kAppEnv[MAXPATHLEN]; snprintf(kAppEnv, MAXPATHLEN, "XUL_APP_FILE=%s", appDataFile); if (putenv(kAppEnv)) Output(PR_FALSE, "Couldn't set %s.\n", kAppEnv); char *result = (char*) calloc(sizeof(char), MAXPATHLEN); if (NS_FAILED(GetRealPath(appDataFile, &result))) { Output(PR_TRUE, "Invalid application.ini path.\n"); return 1; } // We have a valid application.ini path passed in to the -app parameter // but not yet a valid greDir, so lets look for it also on the same folder // as the stub. if (!greFound) { lastSlash = strrchr(iniPath, PATH_SEPARATOR_CHAR); if (!lastSlash) return 1; *(++lastSlash) = '\0'; snprintf(greDir, sizeof(greDir), "%s" XPCOM_DLL, iniPath); greFound = FolderExists(greDir); } // copy it back. strcpy(iniPath, result); } nsINIParser parser; rv = parser.Init(iniPath); if (NS_FAILED(rv)) { fprintf(stderr, "Could not read application.ini\n"); return 1; } #ifdef WINCE // On Windows Mobile and WinCE, we can save a lot of time by not // waiting for XUL and XPCOM to load up. Let's see if we can find // an existing app window to forward our command-line to now. // Shouldn't attempt this if the -no-remote parameter has been provided. bool noRemote = false; for (int i = 1; i < argc; i++) { if (IsArg(argv[i], "no-remote")) { noRemote = true; break; } } if (!noRemote) { char windowName[512]; // Is there a const for appname like VERSION_MAXLEN? rv = parser.GetString("App", "Name", windowName, sizeof(windowName)); if (NS_FAILED(rv)) { fprintf(stderr, "Couldn't figure out the application name\n"); return 1; } // Lookup the hidden message window created by nsNativeAppSupport strncat(windowName, "MessageWindow", sizeof(windowName) - strlen(windowName)); WCHAR wWindowName[512]; MultiByteToWideChar(CP_UTF8, 0, windowName, -1, wWindowName, sizeof(wWindowName)); HWND wnd = ::FindWindowW(wWindowName, NULL); if (wnd) { // Forward the command-line and bail out ForwardToWindow(wnd); return 0; } } #endif if (!greFound) { char minVersion[VERSION_MAXLEN]; // If a gecko maxVersion is not specified, we assume that the app uses only // frozen APIs, and is therefore compatible with any xulrunner 1.x. char maxVersion[VERSION_MAXLEN] = "1.*"; GREVersionRange range = { minVersion, PR_TRUE, maxVersion, PR_TRUE }; rv = parser.GetString("Gecko", "MinVersion", minVersion, sizeof(minVersion)); if (NS_FAILED(rv)) { fprintf(stderr, "The application.ini does not specify a [Gecko] MinVersion\n"); return 1; } rv = parser.GetString("Gecko", "MaxVersion", maxVersion, sizeof(maxVersion)); if (NS_SUCCEEDED(rv)) range.upperInclusive = PR_TRUE; static const GREProperty kProperties[] = { { "xulrunner", "true" } }; rv = GRE_GetGREPathWithProperties(&range, 1, kProperties, NS_ARRAY_LENGTH(kProperties), greDir, sizeof(greDir)); if (NS_FAILED(rv)) { // XXXbsmedberg: Do something much smarter here: notify the // user/offer to download/? Output(PR_FALSE, "Could not find compatible GRE between version %s and %s.\n", range.lower, range.upper); return 1; } #ifdef XP_UNIX // Using a symlinked greDir will fail during startup. Not sure why, but if // we resolve the symlink, everything works as expected. char resolved_greDir[MAXPATHLEN] = ""; if (realpath(greDir, resolved_greDir) && *resolved_greDir) { strncpy(greDir, resolved_greDir, MAXPATHLEN); } #endif } #ifdef XP_OS2 // On OS/2 we need to set BEGINLIBPATH to be able to find XULRunner DLLs strcpy(tmpPath, greDir); lastSlash = strrchr(tmpPath, PATH_SEPARATOR_CHAR); if (lastSlash) { *lastSlash = '\0'; } DosSetExtLIBPATH(tmpPath, BEGIN_LIBPATH); #endif rv = XPCOMGlueStartup(greDir); if (NS_FAILED(rv)) { if (rv == NS_ERROR_OUT_OF_MEMORY) { char applicationName[2000] = "this application"; parser.GetString("App", "Name", applicationName, sizeof(applicationName)); Output(PR_TRUE, "Not enough memory available to start %s.\n", applicationName); } else { Output(PR_TRUE, "Couldn't load XPCOM.\n"); } return 1; } static const nsDynamicFunctionLoad kXULFuncs[] = { { "XRE_CreateAppData", (NSFuncPtr*) &XRE_CreateAppData }, { "XRE_FreeAppData", (NSFuncPtr*) &XRE_FreeAppData }, { "XRE_main", (NSFuncPtr*) &XRE_main }, { nsnull, nsnull } }; rv = XPCOMGlueLoadXULFunctions(kXULFuncs); if (NS_FAILED(rv)) { Output(PR_TRUE, "Couldn't load XRE functions.\n"); return 1; } NS_LogInit(); int retval; { // Scope COMPtr and AutoAppData nsCOMPtr<nsILocalFile> iniFile; #ifdef XP_WIN // On Windows and Windows CE, iniPath is UTF-8 encoded, // so we need to convert it. rv = NS_NewLocalFile(NS_ConvertUTF8toUTF16(iniPath), PR_FALSE, getter_AddRefs(iniFile)); #else rv = NS_NewNativeLocalFile(nsDependentCString(iniPath), PR_FALSE, getter_AddRefs(iniFile)); #endif if (NS_FAILED(rv)) { Output(PR_TRUE, "Couldn't find application.ini file.\n"); return 1; } AutoAppData appData(iniFile); if (!appData) { Output(PR_TRUE, "Error: couldn't parse application.ini.\n"); return 1; } NS_ASSERTION(appData->directory, "Failed to get app directory."); if (!appData->xreDirectory) { // chop "libxul.so" off the GRE path lastSlash = strrchr(greDir, PATH_SEPARATOR_CHAR); if (lastSlash) { *lastSlash = '\0'; } #ifdef XP_WIN // same as iniPath. NS_NewLocalFile(NS_ConvertUTF8toUTF16(greDir), PR_FALSE, &appData->xreDirectory); #else NS_NewNativeLocalFile(nsDependentCString(greDir), PR_FALSE, &appData->xreDirectory); #endif } retval = XRE_main(argc, argv, appData); } NS_LogTerm(); XPCOMGlueShutdown(); return retval; }
int main(int argc, char* argv[]) { if (argc > 1 && (IsArg(argv[1], "h") || IsArg(argv[1], "help") || IsArg(argv[1], "?"))) { Usage(); return 0; } if (argc == 2 && (IsArg(argv[1], "v") || IsArg(argv[1], "version"))) { Output(PR_FALSE, "Mozilla XULRunner %s\n", GRE_BUILD_ID); return 0; } if (argc > 1) { PRBool registerGlobal = IsArg(argv[1], "register-global"); PRBool registerUser = IsArg(argv[1], "register-user"); if (registerGlobal || registerUser) { if (argc != 2) { Usage(); return 1; } nsCOMPtr<nsIFile> regDir; nsresult rv = GetXULRunnerDir(argv[0], getter_AddRefs(regDir)); if (NS_FAILED(rv)) return 2; return RegisterXULRunner(registerGlobal, regDir, kGREProperties, NS_ARRAY_LENGTH(kGREProperties)) ? 0 : 2; } registerGlobal = IsArg(argv[1], "unregister-global"); registerUser = IsArg(argv[1], "unregister-user"); if (registerGlobal || registerUser) { if (argc != 2) { Usage(); return 1; } nsCOMPtr<nsIFile> regDir; nsresult rv = GetXULRunnerDir(argv[0], getter_AddRefs(regDir)); if (NS_FAILED(rv)) return 2; UnregisterXULRunner(registerGlobal, regDir); return 0; } if (IsArg(argv[1], "find-gre")) { if (argc != 3) { Usage(); return 1; } char path[MAXPATHLEN]; static const GREVersionRange vr = { argv[2], PR_TRUE, argv[2], PR_TRUE }; static const GREProperty kProperties[] = { { "xulrunner", "true" } }; nsresult rv = GRE_GetGREPathWithProperties(&vr, 1, kProperties, NS_ARRAY_LENGTH(kProperties), path, sizeof(path)); if (NS_FAILED(rv)) return 1; printf("%s\n", path); return 0; } if (IsArg(argv[1], "gre-version")) { if (argc != 2) { Usage(); return 1; } printf("%s\n", GRE_BUILD_ID); return 0; } if (IsArg(argv[1], "install-app")) { if (argc < 3 || argc > 5) { Usage(); return 1; } char *appLocation = argv[2]; char *installTo = nsnull; if (argc > 3) { installTo = argv[3]; if (!*installTo) // left blank? installTo = nsnull; } char *leafName = nsnull; if (argc > 4) { leafName = argv[4]; if (!*leafName) leafName = nsnull; } nsCOMPtr<nsIFile> regDir; nsresult rv = GetXULRunnerDir(argv[0], getter_AddRefs(regDir)); if (NS_FAILED(rv)) return 2; return InstallXULApp(regDir, appLocation, installTo, leafName); } } geckoVersion = ParseVersion(GRE_BUILD_ID); const char *appDataFile = PR_GetEnv("XUL_APP_FILE"); if (!(appDataFile && *appDataFile)) { if (argc < 2) { Usage(); return 1; } if (IsArg(argv[1], "app")) { if (argc == 2) { Usage(); return 1; } argv[1] = argv[0]; ++argv; --argc; } appDataFile = argv[1]; argv[1] = argv[0]; ++argv; --argc; static char kAppEnv[MAXPATHLEN]; PR_snprintf(kAppEnv, MAXPATHLEN, "XUL_APP_FILE=%s", appDataFile); PR_SetEnv(kAppEnv); } nsCAutoString vendor, name, version, buildID, appID, copyright; nsXREAppData appData = { sizeof(nsXREAppData), 0 }; int rv = LoadAppData(appDataFile, &appData, vendor, name, version, buildID, appID, copyright); if (!rv) rv = XRE_main(argc, argv, &appData); NS_IF_RELEASE(appData.directory); return rv; }
int main(int argc, char **argv) { nsresult rv; char *lastSlash; char iniPath[MAXPATHLEN]; char tmpPath[MAXPATHLEN]; char greDir[MAXPATHLEN]; bool greFound = false; #if defined(XP_MACOSX) CFBundleRef appBundle = CFBundleGetMainBundle(); if (!appBundle) return 1; CFURLRef resourcesURL = CFBundleCopyResourcesDirectoryURL(appBundle); if (!resourcesURL) return 1; CFURLRef absResourcesURL = CFURLCopyAbsoluteURL(resourcesURL); CFRelease(resourcesURL); if (!absResourcesURL) return 1; CFURLRef iniFileURL = CFURLCreateCopyAppendingPathComponent(kCFAllocatorDefault, absResourcesURL, CFSTR("application.ini"), false); CFRelease(absResourcesURL); if (!iniFileURL) return 1; CFStringRef iniPathStr = CFURLCopyFileSystemPath(iniFileURL, kCFURLPOSIXPathStyle); CFRelease(iniFileURL); if (!iniPathStr) return 1; CFStringGetCString(iniPathStr, iniPath, sizeof(iniPath), kCFStringEncodingUTF8); CFRelease(iniPathStr); #else #ifdef XP_WIN wchar_t wide_path[MAX_PATH]; if (!::GetModuleFileNameW(NULL, wide_path, MAX_PATH)) return 1; WideCharToMultiByte(CP_UTF8, 0, wide_path,-1, iniPath, MAX_PATH, NULL, NULL); #elif defined(XP_OS2) PPIB ppib; PTIB ptib; DosGetInfoBlocks(&ptib, &ppib); DosQueryModuleName(ppib->pib_hmte, sizeof(iniPath), iniPath); #else // on unix, there is no official way to get the path of the current binary. // instead of using the MOZILLA_FIVE_HOME hack, which doesn't scale to // multiple applications, we will try a series of techniques: // // 1) use realpath() on argv[0], which works unless we're loaded from the // PATH // 2) manually walk through the PATH and look for ourself // 3) give up struct stat fileStat; strncpy(tmpPath, argv[0], sizeof(tmpPath)); lastSlash = strrchr(tmpPath, '/'); if (lastSlash) { *lastSlash = 0; realpath(tmpPath, iniPath); } else { const char *path = getenv("PATH"); if (!path) return 1; char *pathdup = strdup(path); if (!pathdup) return 1; bool found = false; char *token = strtok(pathdup, ":"); while (token) { sprintf(tmpPath, "%s/%s", token, argv[0]); if (stat(tmpPath, &fileStat) == 0) { found = true; lastSlash = strrchr(tmpPath, '/'); *lastSlash = 0; realpath(tmpPath, iniPath); break; } token = strtok(NULL, ":"); } free (pathdup); if (!found) return 1; } lastSlash = iniPath + strlen(iniPath); *lastSlash = '/'; #endif #ifndef XP_UNIX lastSlash = strrchr(iniPath, PATH_SEPARATOR_CHAR); if (!lastSlash) return 1; #endif *(++lastSlash) = '\0'; // On Linux/Win, look for XULRunner in appdir/xulrunner snprintf(greDir, sizeof(greDir), "%sxulrunner" XPCOM_FILE_PATH_SEPARATOR XPCOM_DLL, iniPath); greFound = FolderExists(greDir); #ifdef XP_UNIX if (greFound) { char resolved_greDir[MAXPATHLEN] = ""; if (realpath(greDir, resolved_greDir) && *resolved_greDir) { strncpy(greDir, resolved_greDir, MAXPATHLEN); } } #endif strncpy(lastSlash, "application.ini", sizeof(iniPath) - (lastSlash - iniPath)); #endif // If -app parameter was passed in, it is now time to take it under // consideration. const char *appDataFile; appDataFile = getenv("XUL_APP_FILE"); if (!appDataFile || !*appDataFile) if (argc > 1 && IsArg(argv[1], "app")) { if (argc == 2) { Output(false, "specify APP-FILE (optional)\n"); return 1; } argv[1] = argv[0]; ++argv; --argc; appDataFile = argv[1]; argv[1] = argv[0]; ++argv; --argc; char kAppEnv[MAXPATHLEN]; snprintf(kAppEnv, MAXPATHLEN, "XUL_APP_FILE=%s", appDataFile); if (putenv(kAppEnv)) Output(false, "Couldn't set %s.\n", kAppEnv); char *result = (char*) calloc(sizeof(char), MAXPATHLEN); if (NS_FAILED(GetRealPath(appDataFile, &result))) { Output(true, "Invalid application.ini path.\n"); return 1; } // We have a valid application.ini path passed in to the -app parameter // but not yet a valid greDir, so lets look for it also on the same folder // as the stub. if (!greFound) { lastSlash = strrchr(iniPath, PATH_SEPARATOR_CHAR); if (!lastSlash) return 1; *(++lastSlash) = '\0'; snprintf(greDir, sizeof(greDir), "%s" XPCOM_DLL, iniPath); greFound = FolderExists(greDir); } // copy it back. strcpy(iniPath, result); } nsINIParser parser; rv = parser.Init(iniPath); if (NS_FAILED(rv)) { fprintf(stderr, "Could not read application.ini\n"); return 1; } if (!greFound) { #ifdef XP_MACOSX // Check for <bundle>/Contents/Frameworks/XUL.framework/libxpcom.dylib CFURLRef fwurl = CFBundleCopyPrivateFrameworksURL(appBundle); CFURLRef absfwurl = nullptr; if (fwurl) { absfwurl = CFURLCopyAbsoluteURL(fwurl); CFRelease(fwurl); } if (absfwurl) { CFURLRef xulurl = CFURLCreateCopyAppendingPathComponent(NULL, absfwurl, CFSTR("XUL.framework"), true); if (xulurl) { CFURLRef xpcomurl = CFURLCreateCopyAppendingPathComponent(NULL, xulurl, CFSTR("libxpcom.dylib"), false); if (xpcomurl) { char tbuffer[MAXPATHLEN]; if (CFURLGetFileSystemRepresentation(xpcomurl, true, (UInt8*) tbuffer, sizeof(tbuffer)) && access(tbuffer, R_OK | X_OK) == 0) { if (realpath(tbuffer, greDir)) { greFound = true; } else { greDir[0] = '\0'; } } CFRelease(xpcomurl); } CFRelease(xulurl); } CFRelease(absfwurl); } #endif if (!greFound) { Output(false, "Could not find the Mozilla runtime.\n"); return 1; } } #ifdef XP_OS2 // On OS/2 we need to set BEGINLIBPATH to be able to find XULRunner DLLs strcpy(tmpPath, greDir); lastSlash = strrchr(tmpPath, PATH_SEPARATOR_CHAR); if (lastSlash) { *lastSlash = '\0'; } DosSetExtLIBPATH(tmpPath, BEGIN_LIBPATH); #endif rv = XPCOMGlueStartup(greDir); if (NS_FAILED(rv)) { if (rv == NS_ERROR_OUT_OF_MEMORY) { char applicationName[2000] = "this application"; parser.GetString("App", "Name", applicationName, sizeof(applicationName)); Output(true, "Not enough memory available to start %s.\n", applicationName); } else { Output(true, "Couldn't load XPCOM.\n"); } return 1; } static const nsDynamicFunctionLoad kXULFuncs[] = { { "XRE_CreateAppData", (NSFuncPtr*) &XRE_CreateAppData }, { "XRE_FreeAppData", (NSFuncPtr*) &XRE_FreeAppData }, { "XRE_main", (NSFuncPtr*) &XRE_main }, { nullptr, nullptr } }; rv = XPCOMGlueLoadXULFunctions(kXULFuncs); if (NS_FAILED(rv)) { Output(true, "Couldn't load XRE functions.\n"); return 1; } NS_LogInit(); int retval; { // Scope COMPtr and AutoAppData nsCOMPtr<nsIFile> iniFile; #ifdef XP_WIN // On Windows iniPath is UTF-8 encoded so we need to convert it. rv = NS_NewLocalFile(NS_ConvertUTF8toUTF16(iniPath), false, getter_AddRefs(iniFile)); #else rv = NS_NewNativeLocalFile(nsDependentCString(iniPath), false, getter_AddRefs(iniFile)); #endif if (NS_FAILED(rv)) { Output(true, "Couldn't find application.ini file.\n"); return 1; } AutoAppData appData(iniFile); if (!appData) { Output(true, "Error: couldn't parse application.ini.\n"); return 1; } NS_ASSERTION(appData->directory, "Failed to get app directory."); if (!appData->xreDirectory) { // chop "libxul.so" off the GRE path lastSlash = strrchr(greDir, PATH_SEPARATOR_CHAR); if (lastSlash) { *lastSlash = '\0'; } #ifdef XP_WIN // same as iniPath. NS_NewLocalFile(NS_ConvertUTF8toUTF16(greDir), false, &appData->xreDirectory); #else NS_NewNativeLocalFile(nsDependentCString(greDir), false, &appData->xreDirectory); #endif } retval = XRE_main(argc, argv, appData, 0); } NS_LogTerm(); return retval; }