void __cdecl main(int argc, char **argv) { SERVICE_TABLE_ENTRY dispatchTable[] = { { G_SERVICENAME, (LPSERVICE_MAIN_FUNCTION)SLPDServiceMain}, { NULL, NULL} }; /*------------------------*/ /* Parse the command line */ /*------------------------*/ if(SLPDParseCommandLine(argc,argv)) { SLPFatal("Invalid command line\n"); } switch(G_SlpdCommandLine.action) { case SLPD_DEBUG: SLPDCmdDebugService(argc, argv); break; case SLPD_INSTALL: SLPDCmdInstallService(); break; case SLPD_REMOVE: SLPDCmdRemoveService(); break; default: SLPDPrintUsage(); StartServiceCtrlDispatcher(dispatchTable); break; } }
/*=========================================================================*/ int SLPDParseCommandLine(int argc,char* argv[]) /* Must be called to initialize the command line */ /* */ /* argc (IN) the argc as passed to main() */ /* */ /* argv (IN) the argv as passed to main() */ /* */ /* Returns - zero on success. non-zero on usage error */ /*=========================================================================*/ { int i; /* Set defaults */ memset(&G_SlpdCommandLine,0,sizeof(SLPDCommandLine)); #ifndef WIN32 strcpy(G_SlpdCommandLine.cfgfile,SLPD_CONFFILE); strcpy(G_SlpdCommandLine.logfile,SLPD_LOGFILE); strcpy(G_SlpdCommandLine.regfile,SLPD_REGFILE); strcpy(G_SlpdCommandLine.pidfile,SLPD_PIDFILE); #ifdef ENABLE_SECURITY strcpy(G_SlpdCommandLine.spifile,SLPD_SPIFILE); #endif #else ExpandEnvironmentStrings(SLPD_CONFFILE,G_SlpdCommandLine.cfgfile,MAX_PATH); ExpandEnvironmentStrings(SLPD_LOGFILE,G_SlpdCommandLine.logfile,MAX_PATH); ExpandEnvironmentStrings(SLPD_REGFILE,G_SlpdCommandLine.regfile,MAX_PATH); ExpandEnvironmentStrings(SLPD_PIDFILE,G_SlpdCommandLine.pidfile,MAX_PATH); #ifdef ENABLE_SECURITY ExpandEnvironmentStrings(SLPD_SPIFILE,G_SlpdCommandLine.spifile,MAX_PATH); #endif G_SlpdCommandLine.action = -1; #endif G_SlpdCommandLine.detach = 1; for(i=1; i<argc; i++) { #ifdef WIN32 if(strcmp(argv[i],"-install") == 0) { G_SlpdCommandLine.action = SLPD_INSTALL; } else if(strcmp(argv[i],"-remove") == 0) { G_SlpdCommandLine.action = SLPD_REMOVE; } else if(strcmp(argv[i],"-debug") == 0) { G_SlpdCommandLine.action = SLPD_DEBUG; } else #endif if(strcmp(argv[i],"-l") == 0) { i++; if(i >= argc) goto USAGE; strncpy(G_SlpdCommandLine.logfile,argv[i],MAX_PATH-1); } else if(strcmp(argv[i],"-r") == 0) { i++; if(i >= argc) goto USAGE; strncpy(G_SlpdCommandLine.regfile,argv[i],MAX_PATH-1); } else if(strcmp(argv[i],"-c") == 0) { i++; if(i >= argc) goto USAGE; strncpy(G_SlpdCommandLine.cfgfile,argv[i],MAX_PATH-1); } #ifdef ENABLE_SECURITY else if(strcmp(argv[i],"-s") == 0) { i++; if(i >= argc) goto USAGE; strncpy(G_SlpdCommandLine.spifile,argv[i],MAX_PATH-1); } #endif else if(strcmp(argv[i],"-p") == 0) { i++; if(i >= argc) goto USAGE; strncpy(G_SlpdCommandLine.pidfile,argv[i],MAX_PATH-1); } else if(strcmp(argv[i],"-d") == 0) { G_SlpdCommandLine.detach = 0; } else if((strcmp(argv[i], "-v") == 0) || (strcmp(argv[i], "-V") == 0) || (strcmp(argv[i], "--version") == 0) || (strcmp(argv[i], "-version") == 0)) { #ifdef WIN32 printf("slpd version: %s\n", SLP_VERSION); #else /* UNIX */ printf("slpd version: %s\n", VERSION); #endif /* Show options. */ printf("compile options:\n" " debugging: " #ifdef DEBUG "enabled" #else "disabled" #endif /* NDEBUG */ "\n" " predicates: " #ifdef ENABLE_PREDICATES "enabled" #else "disabled" #endif /* ENABLE_PREDICATES */ "\n" " slpv1 compatability: " #ifdef ENABLE_SLPv1 "enabled" #else "disabled" #endif /* ENABLE_SLPv1 */ "\n" " slpv2 security: " #ifdef ENABLE_SECURITY "enabled" #else "disabled" #endif /* ENABLE_SECURITY */ "\n" ); exit(1); } else { goto USAGE; } } return 0; USAGE: SLPDPrintUsage(); return 1; }
/*=========================================================================*/ int SLPDParseCommandLine(int argc,char* argv[]) /* Must be called to initialize the command line */ /* */ /* argc (IN) the argc as passed to main() */ /* */ /* argv (IN) the argv as passed to main() */ /* */ /* Returns - zero on success. non-zero on usage error */ /*=========================================================================*/ { int i; /* Set defaults */ memset(&G_SlpdCommandLine,0,sizeof(SLPDCommandLine)); strcpy(G_SlpdCommandLine.cfgfile,"/etc/slp.conf"); strcpy(G_SlpdCommandLine.logfile,"/var/log/slpd.log"); strcpy(G_SlpdCommandLine.regfile,"/etc/slp.reg"); strcpy(G_SlpdCommandLine.pidfile,"/var/run/slpd.pid"); #ifdef WIN32 G_SlpdCommandLine.action = -1; #endif #if(defined DEBUG) G_SlpdCommandLine.detach = 0; #else G_SlpdCommandLine.detach = 1; #endif for(i=1; i<argc; i++) { #ifdef WIN32 if(strcmp(argv[i],"-install") == 0) { G_SlpdCommandLine.action = SLPD_INSTALL; } else if(strcmp(argv[i],"-remove") == 0) { G_SlpdCommandLine.action = SLPD_REMOVE; } else if(strcmp(argv[i],"-debug") == 0) { G_SlpdCommandLine.action = SLPD_DEBUG; } else #endif if(strcmp(argv[i],"-l") == 0) { i++; if(i >= argc) goto USAGE; strncpy(G_SlpdCommandLine.logfile,argv[i],MAX_PATH); } else if(strcmp(argv[i],"-r") == 0) { i++; if(i >= argc) goto USAGE; strncpy(G_SlpdCommandLine.regfile,argv[i],MAX_PATH); } else if(strcmp(argv[i],"-c") == 0) { i++; if(i >= argc) goto USAGE; strncpy(G_SlpdCommandLine.cfgfile,argv[i],MAX_PATH); } else if(strcmp(argv[i],"-p") == 0) { i++; if(i >= argc) goto USAGE; strncpy(G_SlpdCommandLine.pidfile,argv[i],MAX_PATH); } else if(strcmp(argv[i],"-d") == 0) { G_SlpdCommandLine.detach = 0; } else if((strcmp(argv[i], "-v") == 0) || (strcmp(argv[i], "-V") == 0) || (strcmp(argv[i], "--version") == 0) || (strcmp(argv[i], "-version") == 0)) { printf("slpd version: %s\n", VERSION); exit(1); } else if((strcmp(argv[i], "-h") == 0) || (strcmp(argv[i], "-help") == 0) || (strcmp(argv[i], "--help") == 0)) { SLPDPrintUsage(); exit(1); } else { goto USAGE; } } return 0; USAGE: SLPDPrintUsage(); return 1; }