bool PopCommand::pass() { if ( !d->m ) { log( "PASS Command" ); d->m = SaslMechanism::create( "plain", this, d->pop ); if ( !d->m ) { d->pop->err( "Plaintext authentication disallowed" ); return true; } d->m->setState( SaslMechanism::Authenticating ); d->m->setLogin( d->pop->user()->login() ); EString pw=nextArg(); while ( d->args->count() ) { pw += " "; pw += nextArg(); } d->m->setSecret( pw ); d->m->execute(); } if ( !d->m->done() ) return false; if ( d->m->state() == SaslMechanism::Succeeded ) return session(); d->pop->err( "Authentication failed" ); return true; }
bool PopCommand::apop() { class Apop : public Plain { public: Apop( EventHandler * ev, const UString & s ) : Plain( ev ), challenge( s ) {} void verify() { UString s( challenge ); s.append( storedSecret() ); if ( storedSecret().isEmpty() || MD5::hash( s.utf8() ).hex() == secret().utf8() ) { setState( Succeeded ); } else { setState( Failed ); } } private: UString challenge; }; if ( !d->m ) { log( "APOP Command" ); Utf8Codec c; d->m = new Apop( this, c.toUnicode( d->pop->challenge() ) ); d->m->setState( SaslMechanism::Authenticating ); d->m->setLogin( c.toUnicode( nextArg() ) ); d->m->setSecret( nextArg() ); d->m->execute(); } if ( !d->m->done() ) return false; if ( d->m->state() == SaslMechanism::Succeeded ) { d->pop->setUser( d->m->user(), d->m->name() ); d->cmd = Session; return session(); } else { d->pop->err( "Authentication failed" ); } return true; }
bool PopCommand::uidl() { ::Session * s = d->pop->session(); if ( d->args->count() == 1 ) { bool ok; uint msn = nextArg().number( &ok ); if ( !ok || msn < 1 || msn > s->count() ) { d->pop->err( "Bad message number" ); return true; } uint uid = s->uid( msn ); log( "UIDL command (" + fn( uid ) + ")" ); d->pop->ok( fn( msn ) + " " + fn( s->mailbox()->uidvalidity() ) + fn( uid ) ); } else { log( "UIDL command" ); uint msn = 1; d->pop->ok( "Done" ); while ( msn <= s->count() ) { uint uid = s->uid( msn ); d->pop->enqueue( fn( msn ) + " " + fn( s->mailbox()->uidvalidity() ) + "/" + fn( uid ) + "\r\n" ); msn++; } d->pop->enqueue( ".\r\n" ); } return true; }
bool PopCommand::dele() { ::Session * s = d->pop->session(); bool ok; uint msn = nextArg().number( &ok ); uint uid = 0; if ( ok ) { uid = s->uid( msn ); log( "DELE command (" + fn( uid ) + ")" ); } else { log( "DELE command" ); } if ( s->readOnly() ) { d->pop->err( "Invalid message number" ); } else if ( uid ) { d->pop->markForDeletion( uid ); d->pop->ok( "Done" ); } else { d->pop->err( "Invalid message number" ); } return true; }
int main(int argc, char **argv) { char *sosuFile = makeTempFile("sosu"); uint64 value; uint64 max = toValue64(nextArg()); errorCase(max < 11); errorCase(max == UINT64MAX); SosuFp = fileOpen(sosuFile, "a+b"); SosuCnt = 0; for(value = 11; value <= max; value += 2) { if((value & 0x3ffe) == 0) cmdTitle_x(xcout("Prime2tox - %I64u", value)); if( value % 3 != 0 && value % 5 != 0 && value % 7 != 0 && IsSosu(value) ) AddSosu(value); } cmdTitle("Prime2tox - Completed"); DispSosu(); fileClose(SosuFp); removeFile(sosuFile); memFree(sosuFile); }
bool PopCommand::user() { if ( !d->user ) { log( "USER Command" ); if ( !d->pop->accessPermitted() ) { d->pop->err( "Must enable TLS before login" ); return true; } d->user = new ::User; Utf8Codec c; d->user->setLogin( c.toUnicode( nextArg() ) ); d->pop->setUser( d->user, "POP3 login" ); if ( c.valid() ) { d->user->refresh( this ); } else { d->pop->err( "Argument encoding error: " + c.error() ); d->pop->badUser(); return true; } } if ( d->user->state() == User::Unverified ) return false; if ( d->user->state() == User::Nonexistent ) { d->pop->err( "No such user" ); d->pop->badUser(); } else { d->pop->ok( "Done" ); } return true; }
int main(int argc, char **argv) { readArgs: if(argIs("/D")) { MaxDepth = toValue(nextArg()); goto readArgs; } if(argIs("/W")) { Field_W = toValue(nextArg()); goto readArgs; } if(argIs("/H")) { Field_H = toValue(nextArg()); goto readArgs; } if(argIs("/F")) { SetField(nextArg()); goto readArgs; } errorCase(!m_isRange(MaxDepth, 0, IMAX)); errorCase(!m_isRange(Field_W, 1, FIELD_W_MAX)); errorCase(!m_isRange(Field_H, 1, FIELD_H_MAX)); readCmds: if(argIs("/C")) // curr eval { cout("%u\n", GetEval()); goto readCmds; } if(argIs("/N")) // next eval { uint evals[FIELD_W_MAX]; uint index; GetNextEvals(evals); for(index = 0; index < Field_W; index++) cout("%u\n", evals[index]); goto readCmds; } }
/** --insert, --append, and --subnode all take the same arguments */ static void parseInsertionArgs(XmlEdOp op_type, XmlEdAction* op, char *const*const argv, int *argi) { XmlEdArg arg; op->op = op_type; op->arg1 = nextArg(argv, argi); parseNextArg(argv, argi, OPT_JUST_TYPE); op->type = parseNextArg(argv, argi, OPT_NODE_TYPE); parseNextArg(argv, argi, OPT_JUST_NAME); op->arg3 = nextArg(argv, argi); /* test if value is given */ op->arg2 = 0; arg = argv[*argi]; if (!arg) return; if (!strcmp(arg, "-v") || !strcmp(arg, "--value")) { parseNextArg(argv, argi, OPT_JUST_VAL); op->arg2 = nextArg(argv, argi); } }
int main(int argc, char **argv) { ServerDomain = nextArg(); ServerPort = toValue(nextArg()); MutexName = nextArg(); StartEventName = nextArg(); AnswerEventName = nextArg(); ParamsFile = nextArg(); AnswerFile = nextArg(); errorCase(isEmptyJTkn(ServerDomain)); errorCase(ServerPort < 1 || 0xffff < ServerPort); errorCase(isEmptyJTkn(MutexName)); errorCase(isEmptyJTkn(StartEventName)); errorCase(isEmptyJTkn(AnswerEventName)); errorCase(isEmptyJTkn(ParamsFile)); errorCase(isEmptyJTkn(AnswerFile)); MutexHandle = mutexOpen(MutexName); StartEventHandle = eventOpen(StartEventName); AnswerEventHandle = eventOpen(AnswerEventName); StopAppEventHandle = eventOpen_x(xcout("cerulean.charlotte Factory Requester stop app event object %s %u", c_md5_makeHexHashLine(ServerDomain), ServerPort)); if(argIs("/T")) { Serializer = TextFltr; Deserializer = TextFltr; } if(argIs("/TS") || argIs("/TP")) { Serializer = TextFltr; } if(argIs("/TD") || argIs("/TA")) { Deserializer = TextFltr; } if(argIs("/S")) { eventSet(StopAppEventHandle); } else if(argIs("/1")) { error(); // todo: request at once } else { MainLoop(); } handleClose(MutexHandle); handleClose(StartEventHandle); handleClose(AnswerEventHandle); handleClose(StopAppEventHandle); }
int main(int argc, char **argv) { if(argIs("/F")) { ForceMode = 1; } if(hasArgs(1)) { AntiSVN(nextArg()); return; } AntiSVN(c_dropDir()); }
bool PopCommand::auth() { if ( !d->m ) { log( "AUTH Command" ); EString t = nextArg().lower(); d->m = SaslMechanism::create( t, this, d->pop ); if ( !d->m ) { d->pop->err( "SASL mechanism " + t.quoted() + " not available" ); return true; } EString s( nextArg() ); EString * r = 0; if ( !s.isEmpty() ) r = new EString( s ); d->pop->setReader( this ); d->m->readInitialResponse( r ); } if ( !d->m->done() ) return false; if ( d->m->state() == SaslMechanism::Succeeded ) { d->pop->setReader( 0 ); d->pop->setUser( d->m->user(), d->m->name() ); d->cmd = Session; return session(); } else if ( d->m->state() == SaslMechanism::Terminated ) { d->pop->err( "Authentication terminated" ); } else { d->pop->err( "Authentication failed" ); } return true; }
/** * like nextArg(), but additionally look for next arg in @choices */ static XmlNodeType parseNextArg(char *const*const argv, int *argi, const OptionSpec choices[], int choices_count) { const char* arg = nextArg(argv, argi); int i; for (i = 0; i < choices_count; i++) { if ((arg[0] == '-' && arg[1] == choices[i].shortOpt) || (strcmp(arg, choices[i].longOpt) == 0)) return choices[i].type; } edUsage(argv[0], EXIT_BAD_ARGS); return 0; /* never reach here */ }
static void Main2(char *tmplProject, char *tmplDir, int utFlag, int m2Flag) { char *project = nextArg(); errorCase(!existDir(tmplDir)); // 2bs ? errorCase_m(!lineExp("<1,30,__09AZaz>", project), "不正なプロジェクト名です。"); errorCase_m(existPath(project), "既に存在します。"); createDir(project); copyDir(tmplDir, project); addCwd(project); { coExecute("qq -f"); RenamePaths(tmplProject, project); addCwd(existDir(TESTER_PROJ_LDIR) ? TESTER_PROJ_LDIR : project); { ChangeAppIdent("Program.cs"); if(utFlag) { char *csprojFile = xcout("%s.csproj", project); if(existFile(csprojFile)) { ResolveRelHintPath(csprojFile); } memFree(csprojFile); } } unaddCwd(); removeFileIfExist("C:\\Factory\\tmp\\Sections.txt"); // 意図しない検索結果を trep しないように、念のため検索結果をクリア coExecute_x(xcout("Search.exe %s", tmplProject)); coExecute_x(xcout("trep.exe /F %s", project)); // execute("START ."); execute_x(xcout("%s.sln", project)); if(m2Flag) execute("START C:\\Dev\\CSharp\\Module2\\Module2"); } unaddCwd(); }
CmdLineParser::Result CmdLineParser::parse() { TRACE_OBJ bool showHelp = false; while (m_error.isEmpty() && hasMoreArgs()) { const QString &arg = nextArg().toLower(); if (arg == QLatin1String("-collectionfile")) handleCollectionFileOption(); else if (arg == QLatin1String("-showurl")) handleShowUrlOption(); else if (arg == QLatin1String("-enableremotecontrol")) m_enableRemoteControl = true; else if (arg == QLatin1String("-show")) handleShowOption(); else if (arg == QLatin1String("-hide")) handleHideOption(); else if (arg == QLatin1String("-activate")) handleActivateOption(); else if (arg == QLatin1String("-register")) handleRegisterOption(); else if (arg == QLatin1String("-unregister")) handleUnregisterOption(); else if (arg == QLatin1String("-setcurrentfilter")) handleSetCurrentFilterOption(); else if (arg == QLatin1String("-remove-search-index")) m_removeSearchIndex = true; else if (arg == QLatin1String("-rebuild-search-index")) m_rebuildSearchIndex = true; else if (arg == QLatin1String("-help")) showHelp = true; else m_error = tr("Unknown option: %1").arg(arg); } if (!m_error.isEmpty()) { showMessage(m_error + QLatin1String("\n\n\n") + tr(helpMessage), true); return Error; } else if (showHelp) { showMessage(tr(helpMessage), false); return Help; } return Ok; }
static int ensureNoMoreArgs() { return nextArg() ? throwError("too many parameters\n") : 0; }
bool PopCommand::retr( bool lines ) { ::Session * s = d->pop->session(); if ( !d->started ) { bool ok; uint msn = nextArg().number( &ok ); if ( ok ) log( "RETR command (" + fn( s->uid( msn ) ) + ")" ); else log( "RETR command" ); if ( !ok || msn < 1 || msn > s->count() ) { log( "Bad message number " +fn(s->uid(msn))+" "+fn(msn)+"<"+fn(s->count()), Log::Significant); d->pop->err( "Bad message number" ); return true; } if ( lines ) { d->n = nextArg().number( &ok ); if ( !ok ) { log( "Bad line count "+fn(d->n), Log::Significant); d->pop->err( "Bad line count" ); return true; } } d->message = d->pop->message( s->uid( msn ) ); if ( !d->message ) { log( "No such message "+fn(s->uid(msn))+" "+fn(msn), Log::Significant); d->pop->err( "No such message" ); return true; } d->started = true; Fetcher * f = new Fetcher( d->message, this ); if ( !d->message->hasBodies() ) f->fetch( Fetcher::Body ); if ( !d->message->hasHeaders() ) f->fetch( Fetcher::OtherHeader ); if ( !d->message->hasAddresses() ) f->fetch( Fetcher::Addresses ); f->execute(); } if ( !( d->message->hasBodies() && d->message->hasHeaders() && d->message->hasAddresses() ) ) return false; if ( d->message->rfc822Size() > 2 ) d->pop->ok( "Done" ); else { log( "Aborting due to overlapping session", Log::Significant ); d->pop->abort( "Overlapping sessions" ); return true; } Buffer * b = new Buffer; b->append( d->message->rfc822( true ) ); // XXX always downgrades int ln = d->n; bool header = true; int lnhead = 0; int lnbody = 0; int msize = b->size(); EString * t; while ( ( t = b->removeLine() ) != 0 ) { if ( header && t->isEmpty() ) header = false; if ( !header && lines && ln-- < 0 ) break; if ( header ) lnhead++; else lnbody++; if ( t->startsWith( "." ) ) d->pop->enqueue( "." ); d->pop->enqueue( *t ); d->pop->enqueue( "\r\n" ); } EString st = b->string( b->size() ); if ( !st.isEmpty() && !( !header && lines && ln-- < 0 ) ) { if ( st.startsWith( "." ) ) d->pop->enqueue( "." ); d->pop->enqueue( st ); d->pop->enqueue( "\r\n" ); } d->pop->enqueue( ".\r\n" ); if( !lines ) log( "Retrieved " + fn( lnhead ) + ":" + fn( lnbody ) + "/" + fn( msize ) + " " + d->message->header()->messageId().forlog(), Log::Significant ); return true; }
int main(int argc, char **argv) { AddModule(nextArg()); }
int main(int argc, char **argv) { int changed = 0; if(argIs("/D")) { GameDir = nextArg(); goto readArgs; } // Check 'GameDir' { char *file; errorCase_m(!existDir(GameDir), "Wrong Game-Dir"); file = combine(GameDir, "koumajou.exe"); errorCase_m(!existFile(file), "Wrong Game-Dir, koumajou.exe does not exist!"); memFree(file); file = combine(GameDir, "data"); errorCase_m(!existDir(file), "Wrong Game-Dir, data does not exist!"); memFree(file); } LoadSaveData(); ShowSaveData(); readArgs: if(argIs("/S")) { StageNo = toValue(nextArg()); changed = 1; goto readArgs; } if(argIs("/H")) { HiScore = toValue(nextArg()); changed = 1; goto readArgs; } if(argIs("/E+")) { ExtraOpened = 1; changed = 1; goto readArgs; } if(argIs("/E-")) { ExtraOpened = 0; changed = 1; goto readArgs; } if(changed) { cout(">\n"); ShowSaveData(); OutputSaveData(); } }
int main(int argc,char ** argv){ struct donneesPub dp; int i, nThread=0; char *tmp; int type=0; type=PROCESS; dp.fname=NULL; dp.verbose=0; for(i=1;i<argc;i++){ if(!strcmp("-n",argv[i])){ if(!(tmp=nextArg(argc, argv,&i))) usage(); nThread=atoi(tmp); continue; } if(!strcmp("-f",argv[i])){ if(!(dp.fname=nextArg(argc, argv,&i))) usage(); continue; } if(!strcmp("-T",argv[i])){ type=THREAD; continue; } if(!strcmp("-v",argv[i])){ dp.verbose=TRUE; continue; } /* Option inconnue */ printf("Ignoring unknown option: %s\n", argv[i]); } if(!(dp.fname && nThread)) usage(); if(type==THREAD){ if(dp.verbose) printf("By thread\n"); load=loadThread; terminer=terminerThread; eType="thread"; LISTE_RESULTATS=LISTE_RESULTATS_TREADS; }else{ if(dp.verbose) printf("By process. Use -T to test with multithreading\n"); load=loadProcess; eType="process"; terminer=terminerProcess; LISTE_RESULTATS=LISTE_RESULTATS_PROCESS; } initialise(nThread,&dp); maitre(&dp); return 0; }
int main(int argc, char **argv) { int i, nThread = 0; char *tmp; int type = 0; int clients; type = PROCESS; dp.fname = NULL; dp.verbose = 0; int serveur = 1; char *host; host = NULL; clients = 0; for (i = 1; i < argc; i++) { if (!strcmp("-n", argv[i])) { if (!(tmp = nextArg(argc, argv, &i))) usage(); nThread = atoi(tmp); continue; } if (!strcmp("-f", argv[i])) { if (!(dp.fname = nextArg(argc, argv, &i))) usage(); continue; } if (!strcmp("-v", argv[i])) { dp.verbose = TRUE; continue; } if (!strcmp("-c", argv[i])) { if (!(clients = atoi(nextArg(argc, argv, &i)))) usage(); continue; } if (!strcmp("--server", argv[i])) { if (!(host = nextArg(argc, argv, &i))) usage(); serveur = 0; continue; } /* Option inconnue */ printf("Ignoring unknown option: %s\n", argv[i]); } if (serveur) { if (!(dp.fname && nThread)) usage(); if (clients > 0) { configureServeur(clients); setupClients(type, dp.fname, nThread); } } else { configureClient(host); dp.fname = malloc(512); memset(dp.fname, 0, 512); getConfiguration(&type, dp.fname, &nThread); } if (dp.verbose) printf("By process.\n"); load = loadProcess; eType = "process"; terminer = terminerProcess; LISTE_RESULTATS = LISTE_RESULTATS_PROCESS; initialise(nThread); if (serveur) { maitre(); } else { maitreClient(); free(dp.fname); } clean(); return 0; }
/** * This is the main function for 'edit' option */ int edMain(int argc, char **argv) { int i, ops_count, max_ops_count = 8, n, start = 0; XmlEdAction* ops = xmlMalloc(sizeof(XmlEdAction) * max_ops_count); static edOptions g_ops; int nCount = 0; if (argc < 3) edUsage(argv[0], EXIT_BAD_ARGS); edInitOptions(&g_ops); start = edParseOptions(&g_ops, argc, argv); parseNSArr(ns_arr, &nCount, argc-start, argv+start); /* * Parse command line and fill array of operations */ ops_count = 0; i = start + nCount; while (i < argc) { const char *arg = nextArg(argv, &i); if (arg[0] == '-') { if (ops_count >= max_ops_count) { max_ops_count *= 2; ops = xmlRealloc(ops, sizeof(XmlEdAction) * max_ops_count); } ops[ops_count].type = XML_UNDEFINED; if (!strcmp(arg, "-d") || !strcmp(arg, "--delete")) { ops[ops_count].op = XML_ED_DELETE; ops[ops_count].arg1 = nextArg(argv, &i); ops[ops_count].arg2 = 0; } else if (!strcmp(arg, "--var")) { ops[ops_count].op = XML_ED_VAR; ops[ops_count].arg1 = nextArg(argv, &i); ops[ops_count].arg2 = nextArg(argv, &i); } else if (!strcmp(arg, "-m") || !strcmp(arg, "--move")) { ops[ops_count].op = XML_ED_MOVE; ops[ops_count].arg1 = nextArg(argv, &i); ops[ops_count].arg2 = nextArg(argv, &i); } else if (!strcmp(arg, "-u") || !strcmp(arg, "--update")) { ops[ops_count].op = XML_ED_UPDATE; ops[ops_count].arg1 = nextArg(argv, &i); ops[ops_count].type = parseNextArg(argv, &i, OPT_VAL_OR_EXP); ops[ops_count].arg2 = nextArg(argv, &i); } else if (!strcmp(arg, "-r") || !strcmp(arg, "--rename")) { ops[ops_count].op = XML_ED_RENAME; ops[ops_count].arg1 = nextArg(argv, &i); ops[ops_count].type = parseNextArg(argv, &i, OPT_JUST_VAL); ops[ops_count].arg2 = nextArg(argv, &i); } else if (!strcmp(arg, "-i") || !strcmp(arg, "--insert")) { parseInsertionArgs(XML_ED_INSERT, &ops[ops_count], argv, &i); } else if (!strcmp(arg, "-a") || !strcmp(arg, "--append")) { parseInsertionArgs(XML_ED_APPEND, &ops[ops_count], argv, &i); } else if (!strcmp(arg, "-s") || !strcmp(arg, "--subnode")) { parseInsertionArgs(XML_ED_SUBNODE, &ops[ops_count], argv, &i); } else { fprintf(stderr, "Warning: unrecognized option '%s'\n", arg); } ops_count++; } else { i--; /* it was a filename, we didn't use it */ break; } } xmlKeepBlanksDefault(0); if ((!g_ops.noblanks) || g_ops.preserveFormat) xmlKeepBlanksDefault(1); if (i >= argc) { edOutput("-", ops, ops_count, &g_ops); } for (n=i; n<argc; n++) { edOutput(argv[n], ops, ops_count, &g_ops); } xmlFree(ops); cleanupNSArr(ns_arr); xmlCleanupParser(); xmlCleanupGlobals(); return 0; }