void HttpHandler::HandleRequest(const HttpRequest* req, HttpResponse* resp) { switch (req->Method()) { case HttpRequest::METHOD_HEAD: HandleHead(req, resp); break; case HttpRequest::METHOD_GET: HandleGet(req, resp); break; case HttpRequest::METHOD_POST: HandlePost(req, resp); break; case HttpRequest::METHOD_PUT: HandlePut(req, resp); break; case HttpRequest::METHOD_DELETE: HandleDelete(req, resp); break; case HttpRequest::METHOD_OPTIONS: HandleOptions(req, resp); break; case HttpRequest::METHOD_TRACE: HandleTrace(req, resp); break; case HttpRequest::METHOD_CONNECT: HandleConnect(req, resp); break; default: MethodNotAllowed(req, resp); break; } }
ThreadError HandleExtensionHeaders(Message &message, uint8_t &nextHeader, bool receive) { ThreadError error = kThreadError_None; ExtensionHeader extensionHeader; while (receive == true || nextHeader == kProtoHopOpts) { VerifyOrExit(message.GetOffset() <= message.GetLength(), error = kThreadError_Drop); message.Read(message.GetOffset(), sizeof(extensionHeader), &extensionHeader); switch (nextHeader) { case kProtoHopOpts: SuccessOrExit(error = HandleOptions(message)); break; case kProtoFragment: SuccessOrExit(error = HandleFragment(message)); break; case kProtoDstOpts: SuccessOrExit(error = HandleOptions(message)); break; case kProtoIp6: case kProtoRouting: case kProtoNone: ExitNow(error = kThreadError_Drop); default: ExitNow(); } nextHeader = extensionHeader.GetNextHeader(); } exit: return error; }
int main(int argc, char **argv) { char SrvCmd[_SIZ_MSGBUFF] = { 0 }; char ClientMsg[_SIZ_MSGBUFF] = { 0 }; char ErrorMsg[_SIZ_GENFIELD] = { 0 }; int Status = -1, firstOpt = 0; int i = 0; firstOpt = HandleOptions(argc, argv); if (1 == firstOpt) { Usage(argv[0]); exit(1); } ReadConfig(); if (TRC_OpenEx(LOGFILE, LOGNAME, 9, _TRC_NEXT_DAY, _LOG_2MB_LIMIT) != _RET_SUCCESS) { fprintf(stderr, "%s: Test program error: Could not open log file [%s]. Quit.\n", TRC_GetTime(), "stderr"); TRC_Shutdown(); exit(1); } /**** Initialize Alarm Events ****/ if (TRC_InitAlarm(LOGFILE, config.servername, ShutDownSrv) != _RET_SUCCESS) { TRC_Send(LOGFILE, _TRC_LVL_INFO, "%s:FATAL ERROR: Could not Init alarm - program exiting.\n", TRC_GetTime()); TRC_Shutdown(); exit(1); } TRC_Send(LOGFILE, _TRC_LVL_WARN, "%s: Logfile and Alarm Init completed. Setting Queues...\n", TRC_GetTime()); setQueue(); do { TRC_Send(LOGFILE, _TRC_LVL_INFO, "%s: Waiting for next command:\n", TRC_GetTime()); Status = TLK_DMQ_ServerGet(hPRIMARY, _TLK_TYPDEL, ClientMsg); if (Status != _RET_SUCCESS) continue; /* Skip to begining of loop */ SrvCmd[0] = '\0'; Status = PRS_VFI_GetToken(_PRS_VFI_CMDID, _SIZ_GENFIELD, SrvCmd); if (Status == _RET_SUCCESS) vfeiCmd(SrvCmd); else deliCmd(); } while (1); ShutDownSrv(); return 0; }
int main(int argc,char *argv[]) { int infilepos; if (argc == 1 || 1 > (infilepos = HandleOptions(argc,argv)) ) { /* If no arguments we call the Usage routine and exit */ Usage(argv[0]); return 1; } /* handle the program options */ if( infilepos == 0 ) { Usage(argv[0]); return 1; } infile = argv[infilepos]; printf("IN: %s\nBT: %s\n", infile, batchfile ? batchfile : "<none>"); /* The code of your application goes here */ return 0; }
int main(int argc,char *argv[]) { int argno, i; char *filebasename; #define MAXPATH 80 char filename[MAXPATH]; unsigned int tonegens_used; // bitmap of tone generators used unsigned int num_tonegens_used; // count of tone generators used printf("MIDITONES_SCROLL V%s, (C) 2011 Len Shustek\n", VERSION); printf("See the source code for license information.\n\n"); if (argc == 1) { /* no arguments */ SayUsage(argv[0]); return 1; } /* process options */ argno = HandleOptions(argc,argv); filebasename = argv[argno]; /* Open the input file */ strlcpy(filename, filebasename, MAXPATH); strlcat(filename, ".bin", MAXPATH); infile = fopen(filename, "rb"); if (!infile) { fprintf(stderr, "Unable to open input file %s", filename); return 1; } /* Open the output file */ if (codeoutput) { strlcpy(filename, filebasename, MAXPATH); strlcat(filename, ".c", MAXPATH); outfile = fopen(filename, "w"); if (!infile) { fprintf(stderr, "Unable to open output file %s", filename); return 1; } } else outfile = stdout; /* Read the whole input file into memory */ fseek(infile, 0, SEEK_END); /* find file size */ buflen = ftell(infile); fseek(infile, 0, SEEK_SET); buffer = (unsigned char *) malloc (buflen+1); if (!buffer) { fprintf(stderr, "Unable to allocate %ld bytes for the file", buflen); return 1; } fread(buffer, buflen, 1, infile); fclose(infile); printf("Processing %s.bin, %ld bytes\n", filebasename, buflen); if (codeoutput) { time_t rawtime; time (&rawtime); fprintf(outfile, "// Playtune bytestream for file \"%s.bin\"", filebasename); fprintf(outfile, " created by MIDITONES_SCROLL V%s on %s\n", VERSION, asctime(localtime(&rawtime))); fprintf(outfile, "byte PROGMEM score [] = {\n"); } /* Process the commmands sequentially */ fprintf(outfile, "\n"); if (codeoutput) fprintf(outfile, "//"); fprintf(outfile, "duration time "); for (i=0; i< MAX_TONEGENS; ++i) fprintf(outfile, " gen%-2d", i); fprintf(outfile," bytestream code\n\n"); for (gen=0; gen<MAX_TONEGENS; ++gen) gen_status[gen] = SILENT; tonegens_used = 0; lastbufptr = buffer; for (bufptr = buffer; bufptr < buffer+buflen; ++bufptr) { cmd = *bufptr; if (cmd < 0x80) { //***** delay delay = ((unsigned int)cmd << 8) + *++bufptr; print_status(); // tone generator status now timenow += delay; // advance time } else { gen = cmd & 0x0f; if (gen >= MAX_TONEGENS) file_error ("too many tone generators used", bufptr); cmd = cmd & 0xf0; if (cmd == 0x90) {//****** note on gen_status[gen] = *++bufptr; // note number if (gen_status[gen] > 127) file_error ("note higher than 127", bufptr); tonegens_used |= 1<<gen; // record that we used this generator at least once } else if (cmd == 0x80) { //****** note off if (gen_status[gen] == SILENT) file_error ("tone generator not on", bufptr); gen_status[gen] = SILENT; } else if (cmd == 0xf0) { // end of score } else file_error ("unknownn command", bufptr); } } delay = 0; --bufptr; if (codeoutput) --bufptr; //don't do 0xF0 because don't want the trailing comma print_status(); // print final status if (codeoutput) { fprintf(outfile, " 0xf0};\n"); num_tonegens_used = countbits(tonegens_used); fprintf(outfile, "// This score contains %ld bytes, and %d tone generator%s used.\n", buflen, num_tonegens_used, num_tonegens_used == 1 ? " is" : "s are"); } printf ("Done.\n"); }
int main(int argc,char *argv[]) { int argno; fprintf(stderr, "SPI decoder, V%s\n", VERSION); argno = HandleOptions(argc,argv); if (fileread) { if ((datfile = fopen(DATFILENAME,"r")) == NULL) // opne to read from .dat file fatal_err(DATFILENAME " open for read failed"); fprintf(stderr, "Reading from " DATFILENAME "\n"); } else { char dev_name[80]; sprintf(dev_name, "\\\\.\\COM%d", comport); fprintf(stderr, "Opening serial port on %s...", dev_name); handle_serial = CreateFile(dev_name, GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); if (handle_serial!=INVALID_HANDLE_VALUE) { dcbSerialParams.BaudRate = 115200; dcbSerialParams.ByteSize = 8; dcbSerialParams.StopBits = ONESTOPBIT; dcbSerialParams.Parity = NOPARITY; dcbSerialParams.DCBlength = sizeof(DCB); if(SetCommState(handle_serial, &dcbSerialParams) == 0) fatal_err("Error setting serial port parameters"); timeouts.ReadIntervalTimeout = 100; // msec timeouts.ReadTotalTimeoutConstant = 200; // msec timeouts.ReadTotalTimeoutMultiplier = 0; // msec timeouts.WriteTotalTimeoutConstant = 50; timeouts.WriteTotalTimeoutMultiplier = 10; if(SetCommTimeouts(handle_serial, &timeouts) == 0) fatal_err("Error setting serial port timeouts"); fprintf(stderr,"OK\n"); } else fatal_err("Failed"); if ((datfile = fopen(DATFILENAME,"a")) == NULL) // open to append to .dat file fatal_err(DATFILENAME " open for append failed"); } if ((outfile = fopen(OUTFILENAME,"a")) == NULL) fatal_err(OUTFILENAME " open failed"); if ((pktfile = fopen(PKTFILENAME,"a")) == NULL) fatal_err(PKTFILENAME " open failed"); fprintf(pktfile, "\n"); // atexit(cleanup); fprintf(stderr, "Starting.\n"); while(!kbhit()) { more_data: if (fileread) { // read from .dat file if (!fgets(line, MAX_LINE, datfile)) { output("***end of file"); fprintf(stderr, "***end of file"); cleanup(); exit(0); } ++linecnt; bytes_read = strlen(line); output("got %d bytes from the file\n", bytes_read); } else { // read from serial port // printf("reading serial port com%d...\n", comport); ReadFile(handle_serial, line, MAX_LINE, &bytes_read, NULL); line[bytes_read]='\0'; if (bytes_read != 0) { output("got %d bytes from serial port\n", bytes_read); fprintf(stderr, "got %d bytes from the serial port\n", bytes_read); fprintf(datfile, "%s\n", line); } } if (strcmp(line, "SPI Sniffer\n") == 0) { fprintf(stderr, "\"SPI Sniffer\" header line read\n"); continue; } // output("decode %n bytes: %s\n", bytes_read, line); lineptr = line; while (*lineptr != '\0') { skip_to_next_data(); // process input up to next master/slave data pair if (*lineptr == '\0')break; next_command: if (!read_data_pair()) goto more_data; isread = master_data & 0x80; // "read register" flag bit isburst = master_data & 0x40; // "burst" flag bit regnum = master_data & 0x3f; // register number 0 to 63 if (isread) { // config register read if (regnum >= 0x30 && regnum <= 0x3d && !isburst) { // no, is really command strobe command_strobe(); } else { if(isburst){ if (regnum == 0x3f) { // read RX FIFO: receive packet if (!chip_selected) exit_msg("burst RX FIFO write without chip selected", regnum); show_config_reg("read", true); packet.xmit = false; while (1) { // show all burst read data from FIFO if (!skip_timestamp()) goto next_command; if (*lineptr == ']') break; // ends with chip unselect if (!read_data_pair()) goto next_command; output(" %02X", slave_data); if (packet.length < MAX_PKT) { packet.data[packet.length++] = slave_data; } } output("\n"); packet_decode(); } else { // burst read of other than FIFO: consecutive config registers if (!skip_to_next_data()) goto next_command; while (1) { if (!skip_timestamp()) goto next_command; if (*lineptr == ']') break; // ends with chip unselect if (!read_data_pair()) goto next_command; regval = slave_data; show_config_reg("read", false); if (++regnum >= 0x40) exit_msg("burst read of too many config registers", regnum); } } } else { // regular single-register read if (!read_data_pair()) goto next_command; regval = slave_data; show_config_reg("read", false); } } } else { // register write if (regnum >= 0x30 && regnum <= 0x3d && !isburst) { // no, is really command strobe command_strobe(); } else if (regnum == 0x3e) { // write power table if (isburst) { if (!chip_selected) exit_msg("burst power table write without chip selected", regnum); show_config_reg("write", true); while (1) { // show all burst write data to power table if (!skip_timestamp()) goto next_command; if (*lineptr == ']') break; // ends with chip unselect if (!read_data_pair()) goto next_command; output(" %02X", master_data); } output("\n"); } else { // non-burst write to power table if (!read_data_pair()) goto next_command; regval = master_data; show_config_reg("write", false); } } else if (regnum == 0x3f) { // write TX FIFO: transmit packet if (!isburst) exit_msg("implement non-burst TX FIFO write", regnum); if (!chip_selected) exit_msg("burst TX FIFO write without chip selected", regnum); show_config_reg("write", true); packet.xmit = true; while (1) { // show all burst write data to FIFO if (!skip_timestamp()) goto next_command; if (*lineptr == ']') break; // ends with chip unselect if (!read_data_pair()) goto next_command; output(" %02X", master_data); if (packet.length < MAX_PKT) { packet.data[packet.length++] = master_data; } } output("\n"); packet_decode(); } else { // writing config register(s) if (isburst) { // burst config register write int bytes_bursted, bytes_changed, start_reg, end_reg; bytes_bursted = 0; bytes_changed = 0; start_reg = regnum; // output("burst config write\n"); if (!chip_selected) output("burst write without chip selected at reg %02X", regnum); while (1) { // read all the burst write data if (!skip_timestamp()) goto next_command; if (*lineptr == ']') break; // ends with chip unselect if (regnum > 0x2e) exit_msg("too much burst data", regnum); if (!read_data_pair()) goto next_command; new_config_regs[regnum++] = master_data; ++bytes_bursted; } end_reg = regnum-1; for (regnum=start_reg; regnum<end_reg; ++regnum) { // show only those that changed if ((new_config_regs[regnum] != current_config_regs[regnum])) { regval = new_config_regs[regnum]; show_config_reg(" wrote", false); current_config_regs[regnum] = new_config_regs[regnum]; ++bytes_changed; } } show_delta_time(); output(" burst wrote %d registers, and %d changed\n", bytes_bursted, bytes_changed); } else { // single register write if (!read_data_pair()) goto next_command; regval = master_data; show_config_reg("write", false); current_config_regs[regnum] = regval; } } } } } return 0; }
/* Activity() * ===================================================================== * The KEY call to enter the XFORM_DO() */ void Activity( void ) { int quit = FALSE; WORD button; WORD msg[8]; do { button = xform_do( tree, 0, msg ); /* Front Tree Button Handling */ if( IsActiveTree( ad_front ) ) { quit = handle_front( button, msg ); continue; } /* Available Fonts Tree Button Handling */ if( IsActiveTree( ad_inactive ) ) { quit = HandleAvailable( button, msg ); continue; } /* Options Tree Button Handling */ if( IsActiveTree( ad_options ) ) { quit = HandleOptions( button, msg ); continue; } /* Path Tree Button Handling */ if( IsActiveTree( ad_path ) ) { quit = HandlePath( button, msg ); continue; } /* Points Tree Button Handling */ if( IsActiveTree( ad_points ) ) { quit = HandlePoints( button, msg ); continue; } /* Cache Tree Button Handling */ if( IsActiveTree( ad_cache ) ) { quit = HandleCache( button, msg ); continue; } /* Add Pointsize Tree Button Handling */ if( IsActiveTree( ad_add ) ) { quit = HandleAdd( button, msg ); continue; } }while( !quit ); if( CheckAccClose() ) return; Wm_Closed( (int*)msg ); }