WaveFile::WaveFile(unsigned char * rawData, unsigned int rawDataSize, bool ownsData) : SND::SoundFile("WaveFile", rawData, rawDataSize, ownsData) , m_waveData(0) , m_waveDataSize(0) { processHeader(); }
void main(int argc, char *argv[]) { int numrecs; if (argc < 2) { fprintf(stderr,"Usage: %s binary-file ascii-file\n"); exit(1); } binaryFile = fopen(argv[1],"r"); if (binaryFile == NULL) { fprintf(stderr,"Unable to open input file '%s' for reading\n", argv[1]); exit(1); } asciiFile = fopen(argv[2],"w"); if (asciiFile == NULL) { fprintf(stderr,"Unable to open output file '%s' for writing\n", argv[2]); exit(1); } numrecs = processHeader(); processRecords(numrecs); fclose(asciiFile); fclose(binaryFile); }
void PluckerBookReader::setFont(FontType font, bool start) { switch (font) { case FT_REGULAR: break; case FT_H1: case FT_H2: case FT_H3: case FT_H4: case FT_H5: case FT_H6: processHeader(font, start); break; case FT_BOLD: safeAddControl(BOLD, start); break; case FT_TT: safeAddControl(CODE, start); break; case FT_SMALL: break; case FT_SUB: safeAddControl(SUB, start); break; case FT_SUP: safeAddControl(SUP, start); break; } }
static void readAndProcessHeaders(TSession * const sessionP, time_t const deadline, const char ** const errorP, uint16_t * const httpErrorCodeP) { /*---------------------------------------------------------------------------- Read all the HTTP headers from the session *sessionP, which has at least one header coming. Update *sessionP to reflect the information in the headers. If we find an error in the headers or while trying to read them, we return a text explanation of the problem as *errorP and an appropriate HTTP error code as *httpErrorCodeP. Otherwise, we return *errorP = NULL and nothing as *httpErrorCodeP. -----------------------------------------------------------------------------*/ bool endOfHeaders; assert(!sessionP->validRequest); /* Calling us doesn't make sense if there is already a valid request */ *errorP = NULL; /* initial assumption */ endOfHeaders = false; /* Caller assures us there is at least one header */ while (!endOfHeaders && !*errorP) { char * header; bool error; readHeader(sessionP->connP, deadline, &endOfHeaders, &header, &error); if (error) { xmlrpc_asprintf(errorP, "Failed to read headers from " "client connection."); *httpErrorCodeP = 408; /* Request Timeout */ } else { if (!endOfHeaders) { char * p; char * fieldName; p = &header[0]; getFieldNameToken(&p, &fieldName, errorP, httpErrorCodeP); if (!*errorP) { char * fieldValue; NextToken((const char **)&p); fieldValue = p; TableAdd(&sessionP->requestHeaderFields, fieldName, fieldValue); processHeader(fieldName, fieldValue, sessionP, errorP, httpErrorCodeP); } } } } }
VCFReader::VCFReader(const std::string& filename, std::vector< graphite::Sample::SharedPtr >& bamSamplePtrs, Region::SharedPtr regionPtr, VCFWriter::SharedPtr vcfWriter) : m_filename(filename), m_region_ptr(nullptr), m_file_stream_ptr(nullptr), m_preloaded_variant(nullptr), m_vcf_writer(vcfWriter) { openFile(); // open the vcf processHeader(bamSamplePtrs); // read the header setRegion(regionPtr); }
static void readAndProcessHeaders(TSession * const sessionP, time_t const deadline, uint16_t * const httpErrorCodeP) { /*---------------------------------------------------------------------------- Read all the HTTP headers from the session *sessionP, which has at least one header coming. Update *sessionP to reflect the information in the headers. If we find an error in the headers or while trying to read them, we return an appropriate HTTP error code as *httpErrorCodeP. Otherwise, we return *httpErrorCodeP = 0. -----------------------------------------------------------------------------*/ bool endOfHeaders; /* Calling us doesn't make sense if there is already a valid request */ if (sessionP->validRequest) { return; } *httpErrorCodeP = 0; /* initial assumption */ endOfHeaders = false; /* Caller assures us there is at least one header */ while (!endOfHeaders && !*httpErrorCodeP) { char * header; bool error; readHeader(sessionP->conn, deadline, &endOfHeaders, &header, &error); if (error) *httpErrorCodeP = 408; /* Request Timeout */ else { if (!endOfHeaders) { char * p; char * fieldName; p = &header[0]; getFieldNameToken(&p, &fieldName, httpErrorCodeP); if (!*httpErrorCodeP) { char * fieldValue; NextToken((const char **)&p); fieldValue = p; TableAdd(&sessionP->request_headers, fieldName, fieldValue); processHeader(fieldName, fieldValue, sessionP, httpErrorCodeP); } } } } }
void CSlowDataDecoder::processHeader() { // Do we have a complete and valid header already? if (m_header != NULL) return; for (unsigned int i = 1U; i <= (SLOW_DATA_BLOCK_SIZE - 1U); i++, m_headerPtr++) { m_headerData[m_headerPtr] = m_buffer[i]; if (m_headerPtr >= SLOW_DATA_FULL_BLOCK_SIZE) m_headerPtr = 0U; } // Look for a header starting immediately after the data sync bool res = processHeader(m_headerData); if (res) return; // Look for a header starting one block after the data sync processHeader(m_headerData + SLOW_DATA_BLOCK_SIZE - 1U); }
void process(void) { uint64_t num_errors = 0, num_valid_ops = 0, num_valid_bytes = 0; entry entry; int dump_version = processHeader(); /* Exclude the final checksum for RDB >= 5. Will be checked at the end. */ if (dump_version >= 5) { if (positions[0].size < 8) { printf("RDB version >= 5 but no room for checksum.\n"); exit(1); } positions[0].size -= 8; } level = 1; while(positions[0].offset < positions[0].size) { positions[1] = positions[0]; entry = loadEntry(); if (!entry.success) { printValid(num_valid_ops, num_valid_bytes); printErrorStack(&entry); num_errors++; num_valid_ops = 0; num_valid_bytes = 0; /* search for next valid entry */ uint64_t offset = positions[0].offset + 1; int i = 0; while (!entry.success && offset < positions[0].size) { positions[1].offset = (size_t)offset; WIN_PORT_FIX /* cast (size_t) */ /* find 3 consecutive valid entries */ for (i = 0; i < 3; i++) { entry = loadEntry(); if (!entry.success) break; } /* check if we found 3 consecutive valid entries */ if (i < 3) { offset++; } } /* print how many bytes we have skipped to find a new valid opcode */ if (offset < positions[0].size) { printSkipped(offset - positions[0].offset, offset); } positions[0].offset = (size_t)offset; WIN_PORT_FIX /* cast (size_t) */ } else {
void convertCS229toAIFF(FILE* outfile, FILE* infile) { File_Data data; data.samples = -1; processHeader(infile, &data); if(!validateData(data)) { fprintf(stderr, "Error occured in header.\n"); exit(-1); } getSamplesCS229(infile, &data); writeHeaderAIFF(outfile, data); setupSoundAIFF(outfile, data); writeSamplesAIFF(outfile, data); }
void DBGNet::receivePack(DBGResponsePack* pack) { if(!processHeader(pack->header())) { return; } DBGResponseTag* tag = NULL; pack->rewind(); while((tag = pack->next()) != NULL) { tag->process(this, pack); } shipStack(); }
File_Data CS229toTemp(FILE* outfile, FILE* infile) { File_Data data; data.samples = -1; strncpy(data.format, "CS229", 5); processHeader(infile, &data); if(!validateData(data)) { fprintf(stderr, "Error occured in header.\n"); exit(-1); } getSamplesCS229(infile, &data); writeSamplesCS229(outfile, data); return data; }
/** * Executes the algorithm. */ void LoadAscii::exec() { std::string filename = getProperty("Filename"); std::ifstream file(filename.c_str()); if (!file) { g_log.error("Unable to open file: " + filename); throw Exception::FileError("Unable to open file: ", filename); } std::string sepOption = getProperty("Separator"); m_columnSep = m_separatorIndex[sepOption]; // Process the header information. processHeader(file); // Read the data MatrixWorkspace_sptr outputWS = boost::dynamic_pointer_cast<MatrixWorkspace>(readData(file)); outputWS->mutableRun().addProperty("Filename", filename); setProperty("OutputWorkspace", outputWS); }
void CDExtraClientThread::receive() { // While receiving and not exitting while (m_transmit == CLIENT_RECEIVE && !m_killed) { // Get the audio from the RX NETWORK_TYPE type = m_protocol.read(); switch (type) { case NETWORK_NONE: break; case NETWORK_HEADER: { CHeaderData* header = m_protocol.readHeader(); if (header != NULL) processHeader(header); } break; case NETWORK_DATA: { unsigned char buffer[DV_FRAME_LENGTH_BYTES]; unsigned int length; bool sync, end; length = m_protocol.readData(buffer, DV_FRAME_LENGTH_BYTES, sync, end); processFrame(buffer, sync, end); } break; } if (m_watchdog.hasExpired()) { m_dongle->setMode(DVDMODE_IDLE); m_protocol.reset(); resetReceiver(); } if (m_squelchInvert) { if (!m_controller->getSquelch()) m_tx = transmit(true); } else { if (m_controller->getSquelch()) m_tx = transmit(true); } Sleep(FRAME_TIME_MS / 4UL); } }
/** Trims the cs229 sample data for every element in the pointer highlow Size is the amount of highlow combinations there are **/ void trimCS229(highlow_t *highlow, int size) { File_Data data; data.samples = -1; processHeader(stdin, &data); if(!validateData(data)) { fprintf(stderr, "Error occured in header.\n"); exit(-1); } getSamplesCS229(stdin, &data); int i; for(i = 0; i < size; i++) { cut(&data, highlow[i].low, highlow[i].high); } writeHeaderCS229(stdout, data); writeSamplesCS229(stdout, data); }
void CSlowDataDecoder::addData(const unsigned char* data) { wxASSERT(data != NULL); switch (m_state) { case SDD_FIRST: m_buffer[0] = data[0] ^ SCRAMBLER_BYTE1; m_buffer[1] = data[1] ^ SCRAMBLER_BYTE2; m_buffer[2] = data[2] ^ SCRAMBLER_BYTE3; m_state = SDD_SECOND; return; case SDD_SECOND: m_buffer[3] = data[0] ^ SCRAMBLER_BYTE1; m_buffer[4] = data[1] ^ SCRAMBLER_BYTE2; m_buffer[5] = data[2] ^ SCRAMBLER_BYTE3; m_state = SDD_FIRST; processHeader(); break; } }
/** Processes the whole CS229 file starting after the "CS229 at the top of the file" Thie will call processHeader and getSamplesCS229 to process the data of the file **/ File_Data processCS229(FILE *file) { char line[MAX_LINE_LENGTH]; File_Data data; strncpy(data.format, "CS229\0", 6); data.samples = -1; data.channels = -1; data.sampleRate = -1; data.bitDepth = -1; processHeader(file, &data); if(data.success == 0) { fprintf(stderr, "Error reading header.\n"); exit(EXIT_FAILURE); } getSamplesCS229(file, &data); if(data.sampleRate < 0 || data.bitDepth < 0 || data.channels < 0 || data.channels > 32 || (data.bitDepth != 8 && data.bitDepth != 16 && data.bitDepth != 32)) { data.success = 0; } else { data.success = 1; strcpy(data.duration, findDuration(data.sampleRate, data.channels, data.samples, data.duration)); } return data; }
void Client::continueRemote(pollfd * ufds) { short revent = ufds->revents; if( (revent & (POLLIN | POLLOUT)) == 0) { remote->closeSocket(); return ; } if(revent & POLLOUT) { if(cacheState == CACHE_NO_SET && headStart) { std::cerr<<client->getBuffer()<<std::endl; client->setAvaliable(processHeaderCL(client->getBuffer(), client->getAvaliable())); std::cerr<<client->getBuffer()<<std::endl; } remote->sendData(client->getBuffer(), client->getAvaliable()); remote->resetWritten(); client->resetAvaliable(); } if(revent & POLLIN) { int tmpr = remote->recvData(); if(tmpr > 0) { recvedLen += tmpr; } if(cacheState == CACHE_NO_SET && headStart) { std::cerr<<remote->getBuffer()<<std::endl; headStart = false; std::stringstream ss; remote->getBuffer()[7] = '0'; ss<<remote->getBuffer(); std::string protocol; int code = 0; ss>>protocol>>code; if(/*protocol.compare("HTTP/1.0") == 0 && */code == 200 && processHeader(remote->getBuffer()) == 0) { if(contentLen >= 0 && contentLen <= 5*1024*1024) { cacheState = CACHE_WRITE; } recvedLen -= headerLen; } }
ProRataSICReader::ProRataSICReader( const string &sFile ) { sFileName = ""; /* if ( !access( sFile.c_str(), R_OK ) ) { cout << "Error: " << sFile << " is not readable." << endl; iCurrentIdentifierPointer = 0; return ; } else { sFileName = sFile; } */ if ( sFileName != "" ) { processHeader( sFileName.c_str() ); } iCurrentIdentifierPointer = 1; }
/** Shows the sample data to stdout. The specified file should be positioned right after the CS229 to start the file **/ File_Data showCS229(FILE* file, int width, int zoom, int chan, int curses) { File_Data data; data.samples = -1; processHeader(file, &data); if(!validateData(data)) { if(curses) endwin(); fprintf(stderr, "Error occured in header.\n"); exit(-1); } getSamplesCS229(file, &data); if(curses) { int rows, cols; getmaxyx(stdscr, rows, cols); int botSamp = (rows - 3) / data.channels; showSamplesRange(data, width, zoom, chan, curses, 0, botSamp, 0, botSamp*(rows - 3) - botSamp * data.channels); } else showSamples(data, width, zoom, chan, curses); return data; }
void CDummyRepeaterThread::receive() { m_clockCount = 0U; m_busy = false; unsigned int hangCount = 0U; // While receiving and not exitting while (m_transmit == CLIENT_RECEIVE && !m_killed) { // Get the audio from the RX NETWORK_TYPE type; for (;;) { type = m_protocol->read(); if (type == NETWORK_NONE) { break; } else if (type == NETWORK_HEADER) { CHeaderData* header = m_protocol->readHeader(); if (header != NULL) { processHeader(header); m_watchdog.start(); m_clockCount = 0U; hangCount = 0U; m_busy = true; } break; } else if (type == NETWORK_DATA) { unsigned char buffer[DV_FRAME_LENGTH_BYTES]; unsigned char seqNo; unsigned int length = m_protocol->readData(buffer, DV_FRAME_LENGTH_BYTES, seqNo); if (length != 0U) { bool end = processFrame(buffer, seqNo); if (end) hangCount = 30U; else hangCount = 0U; m_watchdog.reset(); m_clockCount = 0U; } break; } else if (type == NETWORK_TEXT) { wxString text, reflector; LINK_STATUS status; m_protocol->readText(text, status, reflector); ::wxGetApp().showSlowData(text); } else if (type == NETWORK_TEMPTEXT) { wxString text; m_protocol->readTempText(text); } else if (type == NETWORK_STATUS1) { wxString text = m_protocol->readStatus1(); ::wxGetApp().showStatus1(text); } else if (type == NETWORK_STATUS2) { wxString text = m_protocol->readStatus2(); ::wxGetApp().showStatus2(text); } else if (type == NETWORK_STATUS3) { wxString text = m_protocol->readStatus3(); ::wxGetApp().showStatus3(text); } else if (type == NETWORK_STATUS4) { wxString text = m_protocol->readStatus4(); ::wxGetApp().showStatus4(text); } else if (type == NETWORK_STATUS5) { wxString text = m_protocol->readStatus5(); ::wxGetApp().showStatus5(text); } } // Have we missed a data frame? if (type == NETWORK_NONE && m_busy) { m_clockCount++; if (m_clockCount == 8U) { // Create a silence frame unsigned char buffer[DV_FRAME_LENGTH_BYTES]; ::memcpy(buffer, NULL_FRAME_DATA_BYTES, DV_FRAME_LENGTH_BYTES); processFrame(buffer, m_networkSeqNo); m_clockCount = 0U; } } if (m_watchdog.isRunning() && m_watchdog.hasExpired()) { wxLogMessage(wxT("Network watchdog has expired")); m_dongle->setMode(DVDMODE_IDLE); m_protocol->reset(); resetReceiver(); } if (hangCount > 0U) { hangCount--; if (hangCount == 0U) { m_dongle->setMode(DVDMODE_IDLE); resetReceiver(); } } checkController(); Sleep(DSTAR_FRAME_TIME_MS / 4UL); } }
void process() { uint64_t num_errors = 0, num_valid_ops = 0, num_valid_bytes = 0; entry entry; int dump_version = processHeader(); /* Exclude the final checksum for RDB >= 5. Will be checked at the end. */ if (dump_version >= 5) { if (positions[0].size < 8) { printf("RDB version >= 5 but no room for checksum.\n"); exit(1); } positions[0].size -= 8;; } level = 1; while(positions[0].offset < positions[0].size) { positions[1] = positions[0]; entry = loadEntry(); if (!entry.success) { uint64_t offset; int i; printValid(num_valid_ops, num_valid_bytes); printErrorStack(&entry); num_errors++; num_valid_ops = 0; num_valid_bytes = 0; /* search for next valid entry */ offset = positions[0].offset + 1; i = 0; while (!entry.success && offset < positions[0].size) { positions[1].offset = (size_t)offset; /* find 3 consecutive valid entries */ for (i = 0; i < 3; i++) { entry = loadEntry(); if (!entry.success) break; } /* check if we found 3 consecutive valid entries */ if (i < 3) { offset++; } } /* print how many bytes we have skipped to find a new valid opcode */ if (offset < positions[0].size) { printSkipped(offset - positions[0].offset, offset); } positions[0].offset = (size_t)offset; } else { num_valid_ops++; num_valid_bytes += positions[1].offset - positions[0].offset; /* advance position */ positions[0] = positions[1]; } free(entry.key); } /* because there is another potential error, * print how many valid ops we have processed */ printValid(num_valid_ops, num_valid_bytes); /* expect an eof */ if (entry.type != REDIS_EOF) { /* last byte should be EOF, add error */ errors.level = 0; SHIFT_ERROR(positions[0].offset, "Expected EOF, got %s", types[entry.type]); /* this is an EOF error so reset type */ entry.type = -1; printErrorStack(&entry); num_errors++; } /* Verify checksum */ if (dump_version >= 5) { uint64_t crc = crc64(0,positions[0].data,positions[0].size); uint64_t crc2; unsigned char *p = (unsigned char*)positions[0].data+positions[0].size; crc2 = ((uint64_t)p[0] << 0) | ((uint64_t)p[1] << 8) | ((uint64_t)p[2] << 16) | ((uint64_t)p[3] << 24) | ((uint64_t)p[4] << 32) | ((uint64_t)p[5] << 40) | ((uint64_t)p[6] << 48) | ((uint64_t)p[7] << 56); if (crc != crc2) { SHIFT_ERROR(positions[0].offset, "RDB CRC64 does not match."); } else { printf("CRC64 checksum is OK\n"); } } /* print summary on errors */ if (num_errors) { printf("\n"); printf("Total unprocessable opcodes: %llu\n", (unsigned long long) num_errors); } }
void CDVAPClientThread::receive() { m_rxPollTimer.start(); resetReceiver(); // While receiving and not exitting while (m_transmit == CS_RECEIVE && !m_killed) { switch (m_state) { case RXS_LISTENING: { CHeaderData* header = m_dvap->readHeader(); if (header != NULL) { bool res = processHeader(header); if (!res) { // Either the checksum failed, or this is a DD packet // wxLogInfo(wxT("Radio header invalid")); setState(RXS_LISTENING); } else { // A valid header and is a DV packet // wxLogInfo(wxT("Found valid radio header")); setState(RXS_PROCESS_DATA); } } } break; case RXS_PROCESS_DATA: { unsigned char data[15U]; bool end; int length = m_dvap->readData(data, 15U, end); if (length == -1) break; if (end) { wxLogMessage(wxT("Found end sync")); setState(RXS_LISTENING); break; } bool res = ::memcmp(data + VOICE_FRAME_LENGTH_BYTES, DATA_SYNC_BYTES, DATA_FRAME_LENGTH_BYTES) == 0; if (res) { wxLogMessage(wxT("Found data sync at frame %u"), m_syncCount); m_syncCount = 0U; processFrame(data, true); } else if (m_syncCount == 20U) { wxLogMessage(wxT("Regenerating data sync")); m_syncCount = 0U; processFrame(data, true); } else { m_syncCount++; processFrame(data, false); } } break; default: break; } if (m_rxPollTimer.hasExpired()) { m_dvap->writePoll(); m_rxPollTimer.reset(); } Sleep(FRAME_TIME_MS / 2UL); m_rxPollTimer.clock(); } m_rxPollTimer.stop(); }
void KviHttpRequest::processData(KviDataBuffer * data) { // unsigned char obuffer[BUFFER_SIZE]; if(m_bChunkedTransferEncoding && m_bIgnoreRemainingData) { // In chunked transfer encoding mode there may be additional headers // after the last chunk of data. We simply ignore them. return; } if(!m_bHeaderProcessed) { // time to process the header m_p->pBuffer->append(*data); int idx = m_p->pBuffer->find((const unsigned char *)"\r\n\r\n",4); if(idx == -1) { // header not complete if(m_p->pBuffer->size() > 4096) { resetInternalStatus(); m_szLastError = __tr2qs("Header too long: exceeded 4096 bytes"); emit terminated(false); } return; } KviCString szHeader((const char *)(m_p->pBuffer->data()),idx); m_p->pBuffer->remove(idx + 4); if(!processHeader(szHeader)) return; m_bHeaderProcessed = true; if(m_eProcessingType == StoreToFile) { if(!openFile())return; } m_uReceivedSize = m_p->pBuffer->size(); // here the header is complete and the eventual remaining data is in m_p->pBuffer. data has been already used. } else { // header already processed m_uReceivedSize += data->size(); // here the header is complete and some data *might* be already in m_p->pBuffer. data is unused yet. // Optimisation: If the transfer is NOT chunked (so we don't have to parse it) // and the requested processing type is either Blocks or StoreToFile // then we just can avoid to copy the data to m_p->pBuffer. // This is a good optimisation since for large files we can save allocating // space for and moving megabytes of data... if((!m_bChunkedTransferEncoding) && ((m_eProcessingType == Blocks) || (m_eProcessingType == StoreToFile))) { switch(m_eProcessingType) { case Blocks: emit binaryData(*data); break; case StoreToFile: m_p->pFile->write((const char *)(data->data()),data->size()); break; default: break; } if(((m_uTotalSize > 0) && (m_uReceivedSize > m_uTotalSize)) || ((m_uMaxContentLength > 0) && (m_uReceivedSize > m_uMaxContentLength))) { resetInternalStatus(); m_szLastError=__tr2qs("The amount of received data exceeds expected length"); emit terminated(false); } return; } // need to append to m_p->pBuffer and process it m_p->pBuffer->append(*data); } // we're processing data in m_p->pBuffer here if(m_bChunkedTransferEncoding) { // The transfer encoding is chunked: the buffer contains // chunks of data with an initial header composed // of a hexadecimal length, an optional bullshit and a single CRLF // The transfer terminates when we read a last chunk of size 0 // that may be followed by optional headers... // This sux :) while(m_p->pBuffer->size() > 0) // <-- note that we may exit from this loop also for other conditions (there is a goto below) { // we process chunks of parts of chunks at a time. if(m_uRemainingChunkSize > 0) { // process the current chunk data unsigned int uProcessSize = m_uRemainingChunkSize; if(uProcessSize > (unsigned int)m_p->pBuffer->size())uProcessSize = m_p->pBuffer->size(); m_uRemainingChunkSize -= uProcessSize; switch(m_eProcessingType) { case Blocks: if((unsigned int)m_p->pBuffer->size() == uProcessSize) { // avoid copying to a new buffer emit binaryData(*m_p->pBuffer); } else { // must copy KviDataBuffer tmp(uProcessSize,m_p->pBuffer->data()); emit binaryData(tmp); m_p->pBuffer->remove(uProcessSize); } break; case Lines: if((unsigned int)m_p->pBuffer->size() == uProcessSize) { // avoid copying to a new buffer emitLines(m_p->pBuffer); } else { // must copy KviDataBuffer tmp(uProcessSize,m_p->pBuffer->data()); emitLines(&tmp); m_p->pBuffer->remove(uProcessSize); } break; case StoreToFile: m_p->pFile->write((const char *)(m_p->pBuffer->data()),uProcessSize); m_p->pBuffer->remove(uProcessSize); break; default: // nothing.. just make gcc happy break; } // now either the buffer is empty or there is another chunk header: continue looping } else { // We're looking for the beginning of a chunk now. // Note that we might be at the end of a previous chunk that has a CRLF terminator // we need to skip it. int crlf = m_p->pBuffer->find((const unsigned char *)"\r\n",2); if(crlf != -1) { if(crlf == 0) { // This is a plain CRLF at the beginning of the buffer BEFORE a chunk header. // It comes from the previous chunk terminator. Skip it. m_p->pBuffer->remove(2); } else { // got a chunk header KviCString szHeader((const char *)(m_p->pBuffer->data()),crlf); szHeader.cutFromFirst(' '); // now szHeader should contain a hexadecimal chunk length... (why the hell it is hex and not decimal ????) QString szHexHeader = szHeader.ptr(); bool bOk; m_uRemainingChunkSize = szHexHeader.toLong(&bOk,16); if(!bOk) { resetInternalStatus(); m_szLastError = __tr2qs("Protocol error: invalid chunk size"); emit terminated(false); return; } m_p->pBuffer->remove(crlf+2); if(m_uRemainingChunkSize == 0) { // this is the last chunk of data. It may be followed by optional headers // but we actually don't need them (since we're surely not in HEAD mode) m_bIgnoreRemainingData = true; m_p->pBuffer->clear(); goto check_stream_length; } } // the rest is valid data of a non-zero chunk: continue looping } else { // chunk header not complete if(m_p->pBuffer->size() > 4096) { resetInternalStatus(); m_szLastError = __tr2qs("Chunk header too long: exceeded 4096 bytes"); emit terminated(false); return; } goto check_stream_length; } } } } else { // the transfer encoding is not chunked: m_p->pBuffer contains only valid data switch(m_eProcessingType) { case Blocks: if(m_p->pBuffer->size() > 0)emit binaryData(*m_p->pBuffer); m_p->pBuffer->clear(); break; case Lines: if(m_p->pBuffer->size() > 0)emitLines(m_p->pBuffer); break; case StoreToFile: m_p->pFile->write((const char *)(m_p->pBuffer->data()),m_p->pBuffer->size()); m_p->pBuffer->clear(); break; default: // nothing.. just make gcc happy break; } } check_stream_length: if(((m_uTotalSize > 0) && (m_uReceivedSize > m_uTotalSize)) || ((m_uMaxContentLength > 0) && (m_uReceivedSize > m_uMaxContentLength))) { resetInternalStatus(); m_szLastError=__tr2qs("The amount of received data exceeds expected length"); emit terminated(false); } return; }
void CDVToolReaderThread::processFile() { m_stopped = false; DVTFR_TYPE type; unsigned char header[RADIO_HEADER_LENGTH_BYTES]; unsigned int n = m_reader->read(header, RADIO_HEADER_LENGTH_BYTES, type); if (n == 0U || type != DVTFR_HEADER) { // Release the input file m_reader->close(); delete m_reader; m_reader = NULL; return; } processHeader(header); // Clear any state that may be hanging around m_slowDataDecoder.reset(); m_dataBuffer.clear(); m_dongle->setMode(DVDMODE_DECODE); for (;;) { DVTFR_TYPE type; unsigned char frame[RADIO_HEADER_LENGTH_BYTES]; unsigned int n = m_reader->read(frame, RADIO_HEADER_LENGTH_BYTES, type); // End of file? if (n == 0U || type != DVTFR_DETAIL) break; if (n != DV_FRAME_LENGTH_BYTES) { wxLogError(wxT("Invalid frame size of %u in the file"), n); ::wxGetApp().error(_("Invalid frame size in the file.")); break; } // Don't pass data re-sync to the slow data processor if (::memcmp(frame + VOICE_FRAME_LENGTH_BYTES, DATA_SYNC_BYTES, DATA_FRAME_LENGTH_BYTES) != 0) processSlowData(frame + VOICE_FRAME_LENGTH_BYTES); else m_slowDataDecoder.sync(); m_dataBuffer.addData(frame, VOICE_FRAME_LENGTH_BYTES); Sleep(FRAME_TIME_MS); } Sleep(FRAME_TIME_MS * 30U); m_dongle->setMode(DVDMODE_IDLE); // Clear the GUI ::wxGetApp().showHeader(NULL); // Release the input file m_reader->close(); delete m_reader; m_reader = NULL; wxLogMessage(wxT("Finished processing the file")); m_stopped = true; }
void transport::send(ref <vmime::message> msg, utility::progressListener* progress) { // Extract expeditor mailbox expeditor; try { const mailbox& mbox = *msg->getHeader()->findField(fields::FROM)-> getValue().dynamicCast <const mailbox>(); expeditor = mbox; } catch (exceptions::no_such_field&) { throw exceptions::no_expeditor(); } // Extract sender mailbox sender; try { const mailbox& mbox = *msg->getHeader()->findField(fields::SENDER)-> getValue().dynamicCast <const mailbox>(); sender = mbox; } catch (exceptions::no_such_field&) { sender = expeditor; } // Extract recipients mailboxList recipients; try { const addressList& to = *msg->getHeader()->findField(fields::TO)-> getValue().dynamicCast <const addressList>(); extractMailboxes(recipients, to); } catch (exceptions::no_such_field&) { } try { const addressList& cc = *msg->getHeader()->findField(fields::CC)-> getValue().dynamicCast <const addressList>(); extractMailboxes(recipients, cc); } catch (exceptions::no_such_field&) { } try { const addressList& bcc = *msg->getHeader()->findField(fields::BCC)-> getValue().dynamicCast <const addressList>(); extractMailboxes(recipients, bcc); } catch (exceptions::no_such_field&) { } // Process message header by removing fields that should be removed // before transmitting the message to MSA, and adding missing fields // which are required/recommended by the RFCs. ref <header> hdr = msg->getHeader()->clone().dynamicCast <header>(); processHeader(hdr); // To avoid cloning message body (too much overhead), use processed // header during the time we are generating the message to a stream. // Revert it back to original header after. struct XChangeMsgHeader { XChangeMsgHeader(vmime::ref <vmime::message> _msg, vmime::ref <vmime::header> _hdr) : msg(_msg), hdr(msg->getHeader()) { // Set new header msg->setHeader(_hdr); } ~XChangeMsgHeader() { // Revert original header msg->setHeader(hdr); } private: vmime::ref <vmime::message> msg; vmime::ref <vmime::header> hdr; } headerExchanger(msg, hdr); send(msg, expeditor, recipients, progress, sender); }
abyss_bool RequestRead(TSession * const sessionP) { uint16_t httpErrorCode; /* zero for no error */ char * requestLine; readRequestLine(sessionP, &requestLine, &httpErrorCode); if (!httpErrorCode) { TMethod httpMethod; const char * host; const char * path; const char * query; unsigned short port; abyss_bool moreHeaders=false; parseRequestLine(requestLine, &httpMethod, &sessionP->version, &host, &port, &path, &query, &moreHeaders, &httpErrorCode); if (!httpErrorCode) initRequestInfo(&sessionP->request_info, sessionP->version, strdup(requestLine), httpMethod, host, port, path, query); while (moreHeaders && !httpErrorCode) { char * p; abyss_bool succeeded; succeeded = ConnReadHeader(sessionP->conn, &p); if (!succeeded) httpErrorCode = 408; /* Request Timeout */ else { if (!*p) /* We have reached the empty line so all the request was read. */ moreHeaders = FALSE; else { char * fieldName; getFieldNameToken(&p, &fieldName, &httpErrorCode); if (!httpErrorCode) { char * fieldValue; NextToken((const char **)&p); fieldValue = p; TableAdd(&sessionP->request_headers, fieldName, fieldValue); processHeader(fieldName, fieldValue, sessionP, &httpErrorCode); } } } } } if (httpErrorCode) ResponseStatus(sessionP, httpErrorCode); else sessionP->validRequest = true; return !httpErrorCode; }
void process() { uint64_t num_errors = 0, num_valid_ops = 0, num_valid_bytes = 0; entry entry; processHeader(); level = 1; while(positions[0].offset < positions[0].size) { positions[1] = positions[0]; entry = loadEntry(); if (!entry.success) { printValid(num_valid_ops, num_valid_bytes); printErrorStack(&entry); num_errors++; num_valid_ops = 0; num_valid_bytes = 0; /* search for next valid entry */ uint64_t offset = positions[0].offset + 1; int i = 0; while (!entry.success && offset < positions[0].size) { positions[1].offset = offset; /* find 3 consecutive valid entries */ for (i = 0; i < 3; i++) { entry = loadEntry(); if (!entry.success) break; } /* check if we found 3 consecutive valid entries */ if (i < 3) { offset++; } } /* print how many bytes we have skipped to find a new valid opcode */ if (offset < positions[0].size) { printSkipped(offset - positions[0].offset, offset); } positions[0].offset = offset; } else { num_valid_ops++; num_valid_bytes += positions[1].offset - positions[0].offset; /* advance position */ positions[0] = positions[1]; } } /* because there is another potential error, * print how many valid ops we have processed */ //printValid(num_valid_ops, num_valid_bytes); db_stats.num_valid_ops = num_valid_ops; db_stats.num_valid_bytes = num_valid_bytes; /* expect an eof */ if (entry.type != REDIS_EOF) { /* last byte should be EOF, add error */ errors.level = 0; SHIFT_ERROR(positions[0].offset, "Expected EOF, got %s", types[entry.type]); /* this is an EOF error so reset type */ entry.type = -1; printErrorStack(&entry); num_errors++; } /* print summary on errors */ if (num_errors) { printf("\n"); printf("Total unprocessable opcodes: %llu\n", (unsigned long long) num_errors); } }
void transport::send(shared_ptr <vmime::message> msg, utility::progressListener* progress) { // Extract expeditor shared_ptr <mailbox> fromMbox = msg->getHeader()->findFieldValue <mailbox>(fields::FROM); if (!fromMbox) throw exceptions::no_expeditor(); mailbox expeditor = *fromMbox; // Extract sender shared_ptr <mailbox> senderMbox = msg->getHeader()->findFieldValue <mailbox>(fields::SENDER); mailbox sender; if (!senderMbox) sender = expeditor; else sender = *senderMbox; // Extract recipients mailboxList recipients; // -- "To" field shared_ptr <addressList> addresses = msg->getHeader()->findFieldValue <addressList>(fields::TO); if (addresses) extractMailboxes(recipients, *addresses); // -- "Cc" field addresses = msg->getHeader()->findFieldValue <addressList>(fields::CC); if (addresses) extractMailboxes(recipients, *addresses); // -- "Bcc" field addresses = msg->getHeader()->findFieldValue <addressList>(fields::BCC); if (addresses) extractMailboxes(recipients, *addresses); // Process message header by removing fields that should be removed // before transmitting the message to MSA, and adding missing fields // which are required/recommended by the RFCs. shared_ptr <header> hdr = vmime::clone(msg->getHeader()); processHeader(hdr); // To avoid cloning message body (too much overhead), use processed // header during the time we are generating the message to a stream. // Revert it back to original header after. struct XChangeMsgHeader { XChangeMsgHeader(shared_ptr <vmime::message> _msg, shared_ptr <vmime::header> _hdr) : msg(_msg), hdr(msg->getHeader()) { // Set new header msg->setHeader(_hdr); } ~XChangeMsgHeader() { // Revert original header msg->setHeader(hdr); } private: shared_ptr <vmime::message> msg; shared_ptr <vmime::header> hdr; } headerExchanger(msg, hdr); send(msg, expeditor, recipients, progress, sender); }
int main(int argc, char **argv) { time_t now; long length, part; int argi, isMessage; (void) time(&now); srand(rand_seed = now); partNumber = ((unsigned long) ~0) >> 1; for (argi = 1; argi < argc; argi++) { if (argv[argi][0] != '-' || (argv[argi][1] == '-' && argv[argi][2] == '\0')) break; switch (argv[argi][1]) { case 'd': maildir = argv[argi][2] == '\0' ? argv[++argi] : &argv[argi][2]; break; case 'f': /* Look for a top level message/rfc822 MIME part. */ findForward = 1; break; case 'l': listParts = 1; break; case 'm': mboxFormat = 1; break; case 'p': /* Look for the Nth top level MIME part. */ partNumber = strtol(argv[argi][2] == '\0' ? argv[++argi] : &argv[argi][2], NULL, 10); break; case 'v': debug = 1; break; default: fprintf(stderr, "invalid option -%c\n%s", argv[argi][1], usage); return 2; } } if (argi + 1 == argc && freopen(argv[argi], "r", stdin) == NULL) { fprintf(stderr, "open \"%s\" error: %s (%d)\n", argv[argi], strerror(errno), errno); return 1; } /* Read header section looking for the Content-Type. */ while (0 < HeaderInputLine(stdin, header, sizeof (header))) { processHeader(); } if (ferror(stdin)) { fprintf(stderr, "error reading message headers: %s (%d)\n", strerror(errno), errno); return 1; } if (feof(stdin)) { fprintf(stderr, "unexpected EOF during message headers\n"); return 1; } /* Fake the end of MIME part headers. */ ungetc('\n', stdin); if (atexit(atExitCleanUp)) { fprintf(stderr, "atexit error: %s (%d)\n", strerror(errno), errno); return 1; } message_out = stdout; /* For each top level MIME part... */ for (part = -1; part < partNumber; ) { /* Start of MIME part headers. */ part++; isMessage = 0; while (0 < HeaderInputLine(stdin, header, sizeof (header))) { if (listParts) fprintf(message_out, "%.3ld: %s\n", part, header); if (isMessageRfc822()) { isMessage = findForward; if (isMessage && maildir != NULL) { message_out = maildirFopen(maildir, &message_filename); if (message_out == NULL) { fprintf(stderr, "maildir open error: %s (%d)\n", strerror(errno), errno); return 1; } } } } if (mboxFormat && isMessage) { /* Read first line of forwarded message, assumes is Return-Path. */ if ((length = HeaderInputLine(stdin, header, sizeof (header))) < 0) ExitOnErrorOrEOF(stdin); if (sscanf(header, "%*[^:]: <%255[^>]>", line) == 1) fprintf(message_out, "From %s %s", line, ctime(&now)); else fprintf(message_out, "From MAILER-DAEMON %s", ctime(&now)); fprintf(message_out, "%s\n", header); } if (part != partNumber && !isMessage) { /* Skip unwanted parts until next boundary or EOF. */ for (;;) { if ((length = TextInputLine(stdin, line, sizeof (line))) < 0) ExitOnErrorOrEOF(stdin); /* Have we found our top-level boundary? */ if (line[0] == '-' && line[1] == '-' && strncmp(line+2, boundary, boundaryLength) == 0) break; } continue; } /* Write this part until next boundary or EOF. */ for (;;) { if ((length = TextInputLine(stdin, line, sizeof (line))) < 0) ExitOnErrorOrEOF(stdin); /* Have we found our top-level boundary? */ if (line[0] == '-' && line[1] == '-' && strncmp(line+2, boundary, boundaryLength) == 0) break; if (mboxFormat && strncmp(line, "From ", sizeof ("From ")-1) == 0) fprintf(message_out, ">"); fprintf(message_out, "%s\n", line); } } return 0; }
void CGMSKClientThread::receive() { resetReceiver(); // While receiving and not exitting while (m_transmit == CS_RECEIVE && !m_killed) { switch (m_state) { case RXS_LISTENING: { CHeaderData* header = m_modem->readHeader(); if (header != NULL) { bool res = processHeader(header); if (!res) { // Either the checksum failed, or this is a DD packet // wxLogInfo(wxT("Radio header invalid")); setState(RXS_LISTENING); } else { // A valid header and is a DV packet // wxLogInfo(wxT("Found valid radio header")); setState(RXS_PROCESS_DATA); } } } break; case RXS_PROCESS_DATA: { unsigned char data[GMSK_MODEM_DATA_LENGTH]; bool end; int length = m_modem->readData(data, GMSK_MODEM_DATA_LENGTH, end); if (length == -1) break; if (end) { wxLogMessage(wxT("Found end sync")); setState(RXS_LISTENING); break; } for (int i = 0; i < length; i++) { m_ambeBuffer[m_ambeLength] = data[i]; m_ambeLength++; if (m_ambeLength >= DV_FRAME_LENGTH_BYTES) { m_ambeLength = 0U; bool res = ::memcmp(m_ambeBuffer + VOICE_FRAME_LENGTH_BYTES, DATA_SYNC_BYTES, DATA_FRAME_LENGTH_BYTES) == 0; if (res) { wxLogMessage(wxT("Found data sync at frame %u"), m_syncCount); m_syncCount = 0U; processFrame(m_ambeBuffer, true); } else if (m_syncCount == 20U) { wxLogMessage(wxT("Regenerating data sync")); m_syncCount = 0U; processFrame(m_ambeBuffer, true); } else { m_syncCount++; processFrame(m_ambeBuffer, false); } } } } break; default: break; } Sleep(FRAME_TIME_MS / 2UL); } }