int waste_srvmain_start(int argc, char **argv) { SetProgramDirectory(argv[0]); g_log_level=ds_Console; _logfile=stderr; { bool dohelp=false; if (argc<2) { dohelp=true; } else { if (!strcmp(argv[1],"-i")) { log_printf(ds_Console,"Interactive!"); } else if (!strcmp(argv[1],"-L")) { char *szLI2; szLI2=(char*)malloc(sK0[3]); safe_strncpy(szLI2,(char*)sK1[3],sK0[3]); dpi(szLI2,4); RelpaceCr(szLI2); fprintf(_logfile,"\n\n%s\n",szLI2); memset(szLI2,0,sK0[3]);free(szLI2); return 1; } else if (!strcmp(argv[1],"-d")) { if (argc==3) { log_printf(ds_Console,"Forking DAEMON!"); log_UpdatePath(argv[2],true); #ifndef _WIN32 daemon(1,0); #endif log_printf(ds_Console,"DAEMON!"); } else { dohelp=true; }; } else { dohelp=true; }; }; if (dohelp) { char *szCR2; szCR2=(char*)malloc(sK0[1]); safe_strncpy(szCR2,(char*)sK1[1],sK0[1]); dpi(szCR2,2); RelpaceCr(szCR2); log_printf(ds_Console, "%s\n" "%s\n" "\n" "Usage: wastesrv <-i> | -d <logfile>\n" "\t -L print license\n" "\t -i interactive mode\n" "\t -d daemon mode (on linux this will put wastesrv in the background)\n" "\n" "\twastesrv.ini must to be present on Windows\n" "\tthe config is default.pr0 to default.pr4\n", g_nameverstr, szCR2 ); memset(szCR2,0,sK0[1]);free(szCR2); return 1; }; }; installsighandler(); log_printf(ds_Console,"%s starting up...",g_nameverstr); MYSRAND(); if (!g_exit) //emergency break! { strcat(g_config_prefix,"default"); #ifdef _WIN32 WSADATA wsaData; if (WSAStartup(MAKEWORD(2, 0), &wsaData)) { memset(&g_key,0,sizeof(g_key)); MessageBox(NULL,"Error initializing Winsock\n",APP_NAME " Error",0); return 1; } #endif UnifiedReadConfig(); InitialLoadDb(); PrepareDownloadDirectory(); if (!g_key.bits) { reloadKey( g_config->ReadInt(CONFIG_storepass,CONFIG_storepass_DEFAULT)? g_config->ReadString(CONFIG_keypass,CONFIG_keypass_DEFAULT): NULL ); }; InitializeNetworkparts(); } return (g_exit); }
int waste_main_start(int argc, char **argv) { SetProgramDirectory(argv[0]); g_log_level=ds_Console; //g_log_level=ds_Debug; _logfile=stderr; installsighandler(); log_printf(ds_Console,"%s starting up...",g_nameverstr); MYSRAND(); #ifdef _DEFINE_WXUI extern void ParseArgv (const char *, bool); int i; for (i = 1; i < argc; i++) { ParseArgv(argv[i], true); } extern int g_opt_forceProfileDlg; if (Prefs_SelectProfile(g_opt_forceProfileDlg)) return 1; strcat(g_config_prefix,g_profile_name); #else strcat(g_config_prefix,"default"); #endif if (!g_exit) //emergency break! { #ifdef _WIN32 WSADATA wsaData; if (WSAStartup(MAKEWORD(2, 0), &wsaData)) { memset(&g_key,0,sizeof(g_key)); MessageBox(NULL,"Error initializing Winsock\n",APP_NAME " Error",0); return 1; } #endif UnifiedReadConfig(); InitialLoadDb(); PrepareDownloadDirectory(); int need_setup=0; #ifndef _DEFINE_SRV need_setup=g_config->ReadInt(CONFIG_valid,0)<5; if (need_setup) { #ifdef _DEFINE_WXUI ::wxMessageBox(_T("This is your first time running WASTE.\n" "Please open the 'Preferences' window and press\n" "'Generate a new private key...', so that you can\n" "join and use the WASTE network."), _T("Welcome to WASTE"), wxICON_HAND|wxOK); g_config->WriteInt(CONFIG_valid,5); g_config->Flush(); #else if (!DialogBox(hInstance,MAKEINTRESOURCE(IDD_SETUPWIZ),NULL,SetupWi zProc)) { delete g_config; memset(&g_key,0,sizeof(g_key)); return 1; }; g_config->WriteInt(CONFIG_valid,5); g_config->Flush(); #endif }; #endif /* _DEFINE_SRV */ if (!g_key.bits && !need_setup) { reloadKey( g_config->ReadInt(CONFIG_storepass,CONFIG_storepass_DEFAULT)? g_config->ReadString(CONFIG_keypass,CONFIG_keypass_DEFAULT): NULL ); }; InitializeNetworkparts(); #ifdef _DEFINE_WXUI int x; for (x = 0; x < SEARCHCACHE_NUMITEMS; x ++) g_searchcache[x]=new SearchCacheItem; #endif #ifndef _DEFINE_SRV extern char *g_opt_wasteOpen; if (g_opt_wasteOpen) { handleWasteURL(g_opt_wasteOpen); free(g_opt_wasteOpen); g_opt_wasteOpen = NULL; }; #endif /* _DEFINE_SRV */ } return (g_exit); }
int main(int argc, char **argv) { g_log_level=ds_Console; _logfile=stderr; bool daemonise = false; const char *profile = NULL; const char *logpath = NULL; const char *pid = NULL; { bool dohelp = true; int i; for (i = 1; i < argc; i++) { if (!strcmp(argv[i],"-i")) { log_printf(ds_Console,"Interactive!"); daemonise = false; dohelp = false; } else if (!strcmp(argv[i],"-L")) { char *szLI2; szLI2=(char*)malloc(sK0[3]); safe_strncpy(szLI2,(char*)sK1[3],sK0[3]); dpi(szLI2,4); RelpaceCr(szLI2); fprintf(_logfile,"\n\n%s\n",szLI2); memset(szLI2,0,sK0[3]);free(szLI2); return 1; } else if (!strcmp(argv[i],"-d")) { daemonise = true; if (++i < argc) { logpath = argv[i]; dohelp = false; } else break; } else if (!strcmp(argv[i],"-p")) { if (++i < argc) { profile = argv[i]; dohelp = false; } else break; } else if (!strcmp(argv[i],"-P")) { if (++i < argc) { pid = argv[i]; FILE *pidfile = fopen(pid,"w"); if (pidfile != NULL) { fprintf(pidfile, "%i\n", (int)getpid() ); fclose(pidfile); } dohelp = false; } else break; } else break; } if (dohelp) { char *szCR2; szCR2=(char*)malloc(sK0[1]); safe_strncpy(szCR2,(char*)sK1[1],sK0[1]); dpi(szCR2,2); RelpaceCr(szCR2); log_printf(ds_Console, "%s\n" "%s\n" "\n" "Usage: wastesrv [-p <profile>] [-L] [-i] [-P <PID file>| [-d <logfile>]\n" "\t -L print license\n" "\t -p profile to use (default)\n" "\t -i interactive mode\n" "\t -P PID file to write PID in\n" "\t -d daemon mode (on *nix this will put wastesrv in the background)\n" "\n" "\twastesrv.ini must to be present on Windows\n" "\tthe config is default.pr0 to default.pr4\n", g_nameverstr, szCR2 ); memset(szCR2,0,sK0[1]);free(szCR2); return 1; } } if (daemonise) { assert(logpath); log_printf(ds_Console,"Forking DAEMON!"); log_UpdatePath(logpath, true); #ifndef _WIN32 daemon(1,0); #endif log_printf(ds_Console,"DAEMON!"); } if (!profile) profile = "default"; // TODO: gvdl should take a directory argument SetProgramDirectory(argv[0]); installsighandler(); log_printf(ds_Console,"%s starting up...%s.pr0",g_nameverstr, profile); MYSRAND(); if (!g_exit) //emergency break! { strcat(g_config_prefix, profile); #ifdef _WIN32 WSADATA wsaData; if (WSAStartup(MAKEWORD(2, 0), &wsaData)) { memset(&g_key,0,sizeof(g_key)); MessageBox(NULL,"Error initializing Winsock\n",APP_NAME " Error",0); return 1; } #endif UnifiedReadConfig(); InitialLoadDb(); PrepareDownloadDirectory(); if (!g_key.bits) { reloadKey( g_config->ReadInt(CONFIG_storepass,CONFIG_storepass_DEFAULT), (char *) g_config->ReadString(CONFIG_keypass,CONFIG_keypass_DEFAULT)); }; InitializeNetworkparts(); //main_AddNodes(); LoadNetQ(); // run loop while (!g_exit) { DoMainLoop(); Sleep(33); }; // exit log_printf(ds_Console,"cleaning up"); SaveDbToDisk(); delete g_listen; delete g_dns; if (g_newdatabase != g_database) delete g_newdatabase; delete g_database; }; SaveNetQ(); int x; for (x = 0; x < g_recvs.GetSize(); x ++) delete g_recvs.Get(x); for (x = 0; x < g_sends.GetSize(); x ++) delete g_sends.Get(x); for (x = 0; x < g_new_net.GetSize(); x ++) delete g_new_net.Get(x); for (x = 0; x < g_uploads.GetSize(); x ++) free(g_uploads.Get(x)); if (g_aclist) free(g_aclist); KillPkList(); delete g_mql; delete g_config; memset(&g_key,0,sizeof(g_key)); #ifdef _WIN32 WSACleanup(); #endif log_UpdatePath(NULL); return 0; }