void resource::dispatch( const reactive::http::request& request_, const reactive::web::router::parameters& parameters_, reactive::http::response& response_ ) const { // call preDispatch preDispatch(request_, parameters_, response_); if (request_.isGet()) { getAction(request_, parameters_, response_); } else if (request_.isPost()) { postAction(request_, parameters_, response_); } else if (request_.isPut()) { putAction(request_, parameters_, response_); } else if (request_.isDelete()) { deleteAction(request_, parameters_, response_); } else if (request_.isOptions()) { optionsAction(request_, parameters_, response_); } else if (request_.isTrace()) { traceAction(request_, parameters_, response_); } else if (request_.isPatch()) { patchAction(request_, parameters_, response_); } else if (request_.isConnect()) { connectAction(request_, parameters_, response_); } else { response_.setStatusCode(reactive::http::status::METHOD_NOT_ALLOWED); } // call postDispatch postDispatch(request_, parameters_, response_); }
void *doInput(void *details) { prodcons *toProg; Action action; const size_t BUFF_INC = 1000; char inputBuffer[BUFF_INC], *wholeBuffer, *newline, *stripped, *theinput, *firstspace, *command; char *rest; int temp, xboardmode = 0, done = 0; size_t commandLength, currentMaxLength, currentBufferLength; #ifdef DEBUG FILE *debugFile; debugFile = fopen("iolog.log","w"); setlinebuf(debugFile); #endif newline = NULL; toProg = ((threadParameter *) details)->input; wholeBuffer = (char *) xmalloc(BUFF_INC); currentMaxLength = BUFF_INC; while (done == 0) { currentBufferLength = 0; memset((void *) wholeBuffer, '\0', currentMaxLength); do { if (fgets(inputBuffer, BUFF_INC, stdin) == NULL) { done = -1; break; } currentBufferLength += BUFF_INC; if (currentBufferLength > currentMaxLength) { wholeBuffer = (char *) xrealloc((void *) wholeBuffer, currentBufferLength); currentMaxLength = currentBufferLength; } wholeBuffer = strcat(wholeBuffer, inputBuffer); newline = strchr(wholeBuffer, '\n'); } while (newline == NULL); if (newline == NULL) { fprintf(stderr, "Error reading from input\n"); continue; } *newline = '\0'; #ifdef DEBUG fprintf(debugFile,"%s\n",wholeBuffer); #endif stripped = strip(wholeBuffer); action.command = xstrdup(stripped); theinput = uppercase(stripped); free(stripped); if ((theinput != NULL) && (strlen(theinput) > 0)) { firstspace = strchr(theinput, ' '); if (firstspace == NULL) { commandLength = strlen(theinput); rest = NULL; } else { commandLength = firstspace - theinput; rest = xstrdup(firstspace + 1); } /* if (rest != NULL) { * printf("rest: %s\n",rest); * } */ command = (char *) xmalloc(commandLength + 1); memcpy(command, theinput, commandLength); command[commandLength] = '\0'; if (strcmp(command, "USERMOVE") == 0) { action.theType = USERMOVE; if (parseMove(rest, &action.data.move) < 0) { action.data.move.from = -1; } putAction(toProg, &action); if (rest != NULL) { free(rest); rest = NULL; } goto ENDPARSE; } if ((strcmp(command, "SP_SANMOVE") == 0) || ((!xboardmode) && (strcmp(command, "SANMOVE") == 0))) { action.theType = SP_SANMOVE; action.data.message = (char *) xstrdup(action.command + commandLength + 1); if (rest != NULL) { free(rest); rest = NULL; } putAction(toProg, &action); goto ENDPARSE; } if (strcmp(command, "XBOARD") == 0) { xboardmode = 1; action.theType = XBOARD; putAction(toProg, &action); if (rest != NULL) { free(rest); rest = NULL; } goto ENDPARSE; } if (strcmp(command, "PROTOVER") == 0) { action.theType = PROTOVER; action.data.message = rest; putAction(toProg, &action); goto ENDPARSE; } if (strcmp(command, "ACCEPTED") == 0) { action.theType = ACCEPTED; action.data.feature = stringToFeature(rest); if (rest != NULL) { free(rest); rest = NULL; } putAction(toProg, &action); goto ENDPARSE; } if (strcmp(command, "REJECTED") == 0) { action.theType = REJECTED; action.data.feature = stringToFeature(rest); if (rest != NULL) { free(rest); rest = NULL; } putAction(toProg, &action); goto ENDPARSE; } if (strcmp(command, "NEW") == 0) { action.theType = NEW; if (rest != NULL) { free(rest); rest = NULL; } putAction(toProg, &action); goto ENDPARSE; } if (strcmp(command, "VARIANT") == 0) { action.theType = VARIANT; action.data.message = rest; putAction(toProg, &action); goto ENDPARSE; } if (strcmp(command, "QUIT") == 0) { action.theType = QUIT; if (rest != NULL) { free(rest); rest = NULL; } putAction(toProg, &action); goto ENDPARSE; } if (strcmp(command, "RANDOM") == 0) { action.theType = RANDOM; if (rest != NULL) { free(rest); rest = NULL; } putAction(toProg, &action); goto ENDPARSE; } if (strcmp(command, "FORCE") == 0) { action.theType = FORCE; if (rest != NULL) { free(rest); rest = NULL; } putAction(toProg, &action); goto ENDPARSE; } if (strcmp(command, "GO") == 0) { action.theType = GO; if (rest != NULL) { free(rest); rest = NULL; } putAction(toProg, &action); goto ENDPARSE; } if (strcmp(command, "PLAYOTHER") == 0) { action.theType = PLAYOTHER; if (rest != NULL) { free(rest); rest = NULL; } putAction(toProg, &action); goto ENDPARSE; } if (strcmp(command, "WHITE") == 0) { action.theType = WHITE; if (rest != NULL) { free(rest); rest = NULL; } putAction(toProg, &action); goto ENDPARSE; } if (strcmp(command, "BLACK") == 0) { action.theType = BLACK; if (rest != NULL) { free(rest); rest = NULL; } putAction(toProg, &action); goto ENDPARSE; } if (strcmp(command, "LEVEL") == 0) { action.theType = LEVEL; if (parseLevel(rest, &action.data.timecontrol) == 0) { putAction(toProg, &action); } if (rest != NULL) { free(rest); rest = NULL; } goto ENDPARSE; } if (strcmp(command, "SD") == 0) { action.theType = SD; action.data.depth = parseInteger(rest); putAction(toProg, &action); if (rest != NULL) { free(rest); rest = NULL; } goto ENDPARSE; } if (strcmp(command, "ST") == 0) { action.theType = ST; action.data.time = parseInteger(rest) * 100; putAction(toProg, &action); if (rest != NULL) { free(rest); rest = NULL; } goto ENDPARSE; } if (strcmp(command, "TIME") == 0) { action.theType = TIME; action.data.time = parseInteger(rest); putAction(toProg, &action); if (rest != NULL) { free(rest); rest = NULL; } goto ENDPARSE; } if (strcmp(command, "OTIM") == 0) { action.theType = OTIM; action.data.time = parseInteger(rest); putAction(toProg, &action); if (rest != NULL) { free(rest); rest = NULL; } goto ENDPARSE; } if (strcmp(command, "?") == 0) { action.theType = MOVENOW; putAction(toProg, &action); if (rest != NULL) { free(rest); rest = NULL; } goto ENDPARSE; } if (strcmp(command, "PING") == 0) { action.theType = PING; action.data.time = parseInteger(rest); putAction(toProg, &action); if (rest != NULL) { free(rest); rest = NULL; } goto ENDPARSE; } if (strcmp(command, "DRAW") == 0) { action.theType = DRAW; if (rest != NULL) { free(rest); rest = NULL; } putAction(toProg, &action); goto ENDPARSE; } if (strcmp(command, "RESULT") == 0) { action.theType = RESULT; if (parseResult(rest, &action.data.result) == 0) { putAction(toProg, &action); } if (rest != NULL) { free(rest); rest = NULL; } goto ENDPARSE; } if (strcmp(command, "SETBOARD") == 0) { action.theType = SETBOARD; if (rest != NULL) { free(rest); rest = NULL; } action.data.message = (char *) xstrdup(action.command + commandLength + 1); putAction(toProg, &action); goto ENDPARSE; } if (strcmp(command, "EDIT") == 0) { action.theType = EDIT; if (rest != NULL) { free(rest); rest = NULL; } putAction(toProg, &action); goto ENDPARSE; } if (strcmp(command, "HINT") == 0) { action.theType = HINT; if (rest != NULL) { free(rest); rest = NULL; } putAction(toProg, &action); goto ENDPARSE; } if (strcmp(command, "BK") == 0) { action.theType = BK; if (rest != NULL) { free(rest); rest = NULL; } putAction(toProg, &action); goto ENDPARSE; } if (strcmp(command, "UNDO") == 0) { action.theType = UNDO; if (rest != NULL) { free(rest); rest = NULL; } putAction(toProg, &action); goto ENDPARSE; } if (strcmp(command, "REMOVE") == 0) { action.theType = REMOVE; if (rest != NULL) { free(rest); rest = NULL; } putAction(toProg, &action); goto ENDPARSE; } if (strcmp(command, "HARD") == 0) { action.theType = HARD; if (rest != NULL) { free(rest); rest = NULL; } putAction(toProg, &action); goto ENDPARSE; } if (strcmp(command, "EASY") == 0) { action.theType = EASY; if (rest != NULL) { free(rest); rest = NULL; } putAction(toProg, &action); goto ENDPARSE; } if (strcmp(command, "POST") == 0) { action.theType = POST; if (rest != NULL) { free(rest); rest = NULL; } putAction(toProg, &action); goto ENDPARSE; } if (strcmp(command, "NOPOST") == 0) { action.theType = NOPOST; if (rest != NULL) { free(rest); rest = NULL; } putAction(toProg, &action); goto ENDPARSE; } if (strcmp(command, "EXIT") == 0) { action.theType = EXIT; if (rest != NULL) { free(rest); rest = NULL; } putAction(toProg, &action); goto ENDPARSE; } if (strcmp(command, "ANALYZE") == 0) { action.theType = ANALYZE; if (rest != NULL) { free(rest); rest = NULL; } putAction(toProg, &action); goto ENDPARSE; } if (strcmp(command, ".") == 0) { action.theType = UPDATESTATUS; if (rest != NULL) { free(rest); rest = NULL; } putAction(toProg, &action); goto ENDPARSE; } if (strcmp(command, "NAME") == 0) { action.theType = NAME; action.data.message = rest; putAction(toProg, &action); goto ENDPARSE; } if (strcmp(command, "RATING") == 0) { action.theType = RATING; temp = parseRatings(rest, &action.data.ratings); if (rest != NULL) { free(rest); rest = NULL; } if (temp == 0) { putAction(toProg, &action); } else { free(action.command); } goto ENDPARSE; } if (strcmp(command, "ICS") == 0) { action.theType = ICS; action.data.message = rest; putAction(toProg, &action); goto ENDPARSE; } if (strcmp(command, "COMPUTER") == 0) { action.theType = COMPUTER; putAction(toProg, &action); if (rest != NULL) { free(rest); rest = NULL; } goto ENDPARSE; } if ((strcmp(command, "SP_DEBUG") == 0) || ((!xboardmode) && (strcmp(command, "DEBUG") == 0))){ action.theType = DEBUG; action.data.message = rest; putAction(toProg, &action); goto ENDPARSE; } if ((strcmp(command, "SP_MOVETOSAN") == 0) || ((!xboardmode) && (strcmp(command, "MOVETOSAN") == 0))){ action.theType = SP_MOVETOSAN; if (parseMove(rest, &action.data.move) < 0) { action.data.move.from = -1; } putAction(toProg, &action); if (rest != NULL) { free(rest); rest = NULL; } goto ENDPARSE; } if ((strcmp(command, "SP_BENCHMOVEUNMOVE") == 0) || ((!xboardmode) && (strcmp(command, "BENCHMOVEUNMOVE") == 0))) { action.theType = SP_BENCHMOVEUNMOVE; if (parseMove(rest, &action.data.move) < 0) { action.data.move.from = -1; } putAction(toProg, &action); if (rest != NULL) { free(rest); rest = NULL; } goto ENDPARSE; } if ((strcmp(command, "SP_BENCHMOVEGEN") == 0) || ((!xboardmode) && (strcmp(command, "BENCHMOVEGEN") == 0))){ action.theType = SP_BENCHMOVEGEN; action.data.time = parseInteger(rest); putAction(toProg, &action); if (rest != NULL) { free(rest); rest = NULL; } goto ENDPARSE; } if ((strcmp(command, "SP_BENCHMOVECYCLE") == 0) || ((!xboardmode) && (strcmp(command, "BENCHMOVECYCLE") == 0))) { action.theType = SP_BENCHMOVECYCLE; action.data.time = parseInteger(rest); putAction(toProg, &action); if (rest != NULL) { free(rest); rest = NULL; } goto ENDPARSE; } if ((strcmp(command, "SP_BENCHEVAL") == 0) || ((!xboardmode) && (strcmp(command, "BENCHEVAL") == 0))) { action.theType = SP_BENCHEVAL; action.data.time = parseInteger(rest); putAction(toProg, &action); if (rest != NULL) { free(rest); rest = NULL; } goto ENDPARSE; } if ((strcmp(command, "SP_PERFT") == 0) || ((!xboardmode) && (strcmp(command, "PERFT") == 0))) { action.theType = SP_PERFT; action.data.depth = parseInteger(rest); putAction(toProg, &action); if (rest != NULL) { free(rest); rest = NULL; } goto ENDPARSE; } if ((strcmp(command, "SP_EPDSUITE") == 0) || ((!xboardmode) && (strcmp(command, "EPDSUITE") == 0))) { action.theType = SP_EPDSUITE; action.data.message = (char *) xstrdup(action.command + commandLength + 1); if (rest != NULL) { free(rest); rest = NULL; } putAction(toProg, &action); goto ENDPARSE; } if ((strcmp(command, "SP_EPDLINE") == 0) || ((!xboardmode) && (strcmp(command, "EPDLINE") == 0))) { action.theType = SP_EPDLINE; action.data.message = (char *) xstrdup(action.command + commandLength + 1); if (rest != NULL) { free(rest); rest = NULL; } putAction(toProg, &action); goto ENDPARSE; } if ((strcmp(command, "SP_MODIFYBOOK") == 0) || ((!xboardmode) && (strcmp(command, "MODIFYBOOK") == 0))) { action.theType = SP_MODIFYBOOK; action.data.message = (char *) xstrdup(action.command + commandLength + 1); if (rest != NULL) { free(rest); rest = NULL; } putAction(toProg, &action); goto ENDPARSE; } if ((strcmp(command, "SP_CLOSEBOOK") == 0) || ((!xboardmode) && (strcmp(command, "CLOSEBOOK") == 0))) { action.theType = SP_CLOSEBOOK; if (rest != NULL) { free(rest); rest = NULL; } putAction(toProg, &action); goto ENDPARSE; } if ((strcmp(command, "SP_SHOWMOVES") == 0) || ((!xboardmode) && (strcmp(command, "SHOWMOVES") == 0))) { action.theType = SP_SHOWMOVES; if (rest != NULL) { free(rest); rest = NULL; } putAction(toProg, &action); goto ENDPARSE; } if ((strcmp(command, "SP_EVALUATE") == 0) || ((!xboardmode) && (strcmp(command, "EVALUATE") == 0))) { action.theType = SP_EVALUATE; if (rest != NULL) { free(rest); rest = NULL; } putAction(toProg, &action); goto ENDPARSE; } if (strcmp(command, "HELP") == 0) { action.theType = HELP; if (rest != NULL) { free(rest); rest = NULL; } putAction(toProg, &action); goto ENDPARSE; } if ((strcmp(command, "SP_EPDMINDEPTH") == 0) || ((!xboardmode) && (strcmp(command, "EPDMINDEPTH") == 0))) { action.theType = SP_EPDMINDEPTH; action.data.depth = parseInteger(rest); putAction(toProg, &action); if (rest != NULL) { free(rest); rest = NULL; } goto ENDPARSE; } action.theType = UNKNOWN_COMMAND; if (rest != NULL) { free(rest); rest = NULL; } putAction(toProg, &action); ENDPARSE:; } free(theinput); theinput = NULL; } free(wholeBuffer); #ifdef DEBUG fclose(debugFile); #endif return NULL; }