/*---------------------------------------------*/ void bsPutBit ( BitStream* bs, Int32 bit ) { if (bs->buffLive == 8) { Int32 retVal = putc ( (UChar) bs->buffer, bs->handle ); if (retVal == EOF) writeError(); bytesOut++; bs->buffLive = 1; bs->buffer = bit & 0x1; } else { bs->buffer = ( (bs->buffer << 1) | (bit & 0x1) ); bs->buffLive++; }; }
bool LogType::parseUdpBufferSize() { setUdpBufferSize( human2size( iniGetValue( ini::SECTION, ini::VAR_SWA_UDPBUFFERSIZE, size2human(ini::settings::udpBufferSize) ))); if (iniGetError()) { writeError( "Can't get 'UDP Buffer Size'" ); return false; } if ( getUdpBufferSize() == 0 ) { writeError( "'UDP Buffer Size' invalid" ); return false; } writeInfo ( "UDP Buffer Size = %s (%lu bytes)", size2human(getUdpBufferSize()).c_str(), getUdpBufferSize()); return true; }
bool checkIsChar(InputStream* inputStream, char expectedChar) { char readChar = inputStream->readChar(inputStream); if (expectedChar != readChar) { writeError(IO_READER_CHECK_CHAR_PROBLEM); OutputStream* outputStream = getErrorOutputStreamLogger(); appendString(outputStream, "\nCHK:CHAR:EXP:"); append(outputStream, expectedChar); appendString(outputStream, " \t but \t find:"); append(outputStream, readChar); println(outputStream); return false; } return true; }
int Flash_Write(ioAddress offset, ioData data) { ioData status = 0; IO_Write(CommandRegister, ProgramCommand); IO_Write(offset, data); while ((status & ReadyBit) == 0) status = IO_Read(StatusRegister); if (status != ReadyBit) return writeError(status); if (data != IO_Read(offset)) return FLASH_READ_BACK_ERROR; return FLASH_SUCCESS; }
int sayQUIT(int hSocket) { unsigned char bufSend[BUF_SIZE]; memset(bufSend, 0, sizeof(bufSend)); sprintf(bufSend, "QUIT\r\n"); if (medusaSend(hSocket, bufSend, strlen(bufSend), 0) < 0) { writeError(ERR_ERROR, "%s failed: medusaSend was not successful", MODULE_NAME); } return SUCCESS; }
Timer* getTimerByCode(int timerCode) { int i; for (i = 0; i < timerList.size; i++) { Timer* timer = getTimerByIndex(i); if (timer == NULL) { writeError(TIMER_NULL); return NULL; } if (timer->timerCode == timerCode) { return timer; } } return NULL; }
void addGameTarget(GameTarget* target, char* targetName, float gain, Location* location) { unsigned char size = targets.size; if (size < MAX_TARGET) { target->name = targetName; target->status = TARGET_AVAILABLE; target->gain = gain; target->location = location; targets.targets[size] = target; targets.size++; } else { writeError(TOO_MUCH_TARGETS); } }
clientId_t *createClient(int portno, char *hostname) { clientId_t *thisClient = (clientId_t *)malloc(sizeof(clientId_t)); int iret; struct sockaddr_in serv_addr; struct hostent *server; thisClient->sockfd = socket(AF_INET, SOCK_STREAM, 0); if(thisClient->sockfd < 0) { writeError(ERROR_SOCKET_CREATE); return NULL; } server = gethostbyname(hostname); bzero((char *) &serv_addr, sizeof(serv_addr)); serv_addr.sin_family = AF_INET; bcopy((char *)server->h_addr, (char *)&serv_addr.sin_addr.s_addr,server->h_length); serv_addr.sin_port = htons(portno); while(connect(thisClient->sockfd,(struct sockaddr *) &serv_addr,sizeof(serv_addr)) < 0) { printf(" jumping\n"); } bzero((char *)&thisClient->outbuffer,256); bzero((char *)&thisClient->inputbuffer,256); thisClient->newinput = 0; thisClient->newoutput = 0; thisClient->isDisconnect = 0; iret = pthread_create(&thisClient->clientThread, NULL, handleCommunicationOutput, (void *)thisClient); if(iret < 0) { writeError(ERROR_CLIENT_THREAD); return NULL; } return thisClient; }
// The "main" of the medusa module world - this is what gets called to actually do the work int go(sLogin* logins, int argc, char *argv[]) { int i; char *strtok_ptr = NULL, *pOpt = NULL, *pOptTmp = NULL; _MYSQL_DATA *psSessionData; psSessionData = malloc(sizeof(_MYSQL_DATA)); memset(psSessionData, 0, sizeof(_MYSQL_DATA)); psSessionData->protoFlag = PROTO_NEW; if ((argc < 0) || (argc > 1)) { writeError(ERR_ERROR, "%s: Incorrect number of parameters passed to module (%d). Use \"-q\" option to display module usage.", MODULE_NAME, argc); return FAILURE; } else { writeError(ERR_DEBUG_MODULE, "OMG teh %s module has been called!!", MODULE_NAME); psSessionData->hashFlag = PASSWORD; for (i=0; i<argc; i++) { pOptTmp = malloc( strlen(argv[i]) + 1); memset(pOptTmp, 0, strlen(argv[i]) + 1); strncpy(pOptTmp, argv[i], strlen(argv[i])); writeError(ERR_DEBUG_MODULE, "Processing complete option: %s", pOptTmp); pOpt = strtok_r(pOptTmp, ":", &strtok_ptr); writeError(ERR_DEBUG_MODULE, "Processing option: %s", pOpt); if (strcmp(pOpt, "PASS") == 0) { pOpt = strtok_r(NULL, "\0", &strtok_ptr); writeError(ERR_DEBUG_MODULE, "Processing option parameter: %s", pOpt); if (pOpt == NULL) writeError(ERR_WARNING, "Method PASS requires value to be set."); else if (strcmp(pOpt, "PASSWORD") == 0) psSessionData->hashFlag = PASSWORD; else if (strcmp(pOpt, "HASH") == 0) psSessionData->hashFlag = HASH; else writeError(ERR_WARNING, "Invalid value for method PASS."); } free(pOptTmp); } initModule(logins, psSessionData); } FREE(psSessionData); return SUCCESS; }
// The "main" of the medusa module world - this is what gets called to actually do the work int go(sLogin* logins, int argc, char *argv[]) { int i; char *strtok_ptr, *pOpt, *pOptTmp; _CVS_DATA *psSessionData; psSessionData = malloc(sizeof(_CVS_DATA)); memset(psSessionData, 0, sizeof(_CVS_DATA)); if ((argc < 0) || (argc > 1)) { writeError(ERR_ERROR, "%s: Incorrect number of parameters passed to module (%d). Use \"-q\" option to display module usage.", MODULE_NAME, argc); return FAILURE; } else { writeError(ERR_DEBUG_MODULE, "OMG teh %s module has been called!!", MODULE_NAME); for (i=0; i<argc; i++) { pOptTmp = malloc( strlen(argv[i]) + 1); memset(pOptTmp, 0, strlen(argv[i]) + 1); strncpy(pOptTmp, argv[i], strlen(argv[i])); writeError(ERR_DEBUG_MODULE, "Processing complete option: %s", pOptTmp); pOpt = strtok_r(pOptTmp, ":", &strtok_ptr); writeError(ERR_DEBUG_MODULE, "Processing option: %s", pOpt); if (strcmp(pOpt, "DIR") == 0) { pOpt = strtok_r(NULL, "\0", &strtok_ptr); writeError(ERR_DEBUG_MODULE, "Processing option parameter: %s", pOpt); if ( pOpt ) { psSessionData->szDir = malloc(strlen(pOpt) + 1); memset(psSessionData->szDir, 0, (strlen(pOpt) + 1)); strncpy((char *)psSessionData->szDir, pOpt, strlen(pOpt)); } else writeError(ERR_WARNING, "Method DIR requires value to be set."); } else writeError(ERR_WARNING, "Invalid method: %s.", pOpt); free(pOptTmp); } initModule(logins, psSessionData); } FREE(psSessionData); return 0; }
// The "main" of the medusa module world - this is what gets called to actually do the work int go(sLogin* logins, int argc, char *argv[]) { int i; char *strtok_ptr, *pOpt, *pOptTmp; _MODULE_DATA *psSessionData; psSessionData = malloc(sizeof(_MODULE_DATA)); memset(psSessionData, 0, sizeof(_MODULE_DATA)); if ( !(0 <= argc <= 3) ) { // Show usage information writeError(ERR_ERROR, "%s is expecting 0 parameters, but it was passed %d", MODULE_NAME, argc); } else { writeError(ERR_DEBUG_MODULE, "OMG teh %s module has been called!!", MODULE_NAME); for (i=0; i<argc; i++) { pOptTmp = malloc( strlen(argv[i]) + 1); memset(pOptTmp, 0, strlen(argv[i]) + 1); strncpy(pOptTmp, argv[i], strlen(argv[i])); writeError(ERR_DEBUG_MODULE, "Processing complete option: %s", pOptTmp); pOpt = strtok_r(pOptTmp, ":", &strtok_ptr); writeError(ERR_DEBUG_MODULE, "Processing option: %s", pOpt); if (strcmp(pOpt, "EHLO") == 0) { pOpt = strtok_r(NULL, "\0", &strtok_ptr); writeError(ERR_DEBUG_MODULE, "Processing option parameter: %s", pOpt); if ( pOpt ) { psSessionData->szEHLO = malloc(strlen(pOpt) + 1); memset(psSessionData->szEHLO, 0, strlen(pOpt) + 1); strncpy((char *)psSessionData->szEHLO, pOpt, strlen(pOpt)); } else writeError(ERR_WARNING, "Method EHLO requires value to be set."); } else writeError(ERR_WARNING, "Invalid method: %s.", pOpt); free(pOptTmp); } initModule(logins, psSessionData); } return 0; }
LogType::LogType(LogType& copy): LogSyslog(false) { copy.closeUdp(); setVerbose(copy.getVerbose()); setConfigFile(copy.getConfigFile()); setStorageType(copy.getStorageType()); setIpAddress(copy.getIpAddress()); setRemotePort(copy.getRemotePort()); setSourcePort(copy.getSourcePort()); setUdpBufferSize(copy.getUdpBufferSize()); __swaParser = boost::make_shared<SWAParser>( boost::bind(&LogType::callbackSWA, this, _1, _2, _3)); if (!__swaParser) { writeError ("SWA Parser not allocated"); // impossible, but if something corrupt memory. throw std::runtime_error( "Wrong log priority." ); } // check if config file exists if( !iniParse(getConfigFile()) ) { writeError ("Can't parse config FILE = %s", getConfigFile().c_str()); // impossible, but if something corrupt memory. throw std::runtime_error( "Wrong log priority." ); } __threadRun = false; __swaHelloReceive = false; __terminate = false; __udp_socket = NULL; __udp_remote_endpoint = NULL; }
int32_t _terminate_all_places(){ int32_t success = -1; //tell everyone else to exit int32_t i; //writeDebug("Starting thread _terminate_all_places at place"); for (i = _max_places()-1; i >= 0 ; --i) { success = dispatcher_terminate(_toplace(i)); if (success != EXIT_SUCCESS) { writeError("ERROR: Failed thread _terminate_all_places at place"); return EXIT_FAILURE; } } writeDebug("Finished thread _terminate_all_places at place"); return success; }
/* The sender of this command REQUESTS that the receiver forcibly log off the user process at the receiver's end, or confirms that the receiver has its permission to do so. */ int processIAClogout(int hSocket, _MODULE_DATA* _psSessionData) { unsigned char bufSend[] = { 0xFF, 0xFD, 0x12 }; /* IAC DO LOGOUT */ char* bufReceive = NULL; int nReceiveBufferSize = 0; writeError(ERR_DEBUG_MODULE, "[%s] Sending IAC DO LOGOUT command.", MODULE_NAME); if (medusaSend(hSocket, bufSend, 3, 0) < 0) { writeError(ERR_ERROR, "%s failed: medusaSend was not successful", MODULE_NAME); return FAILURE; } /* Receive any remaining IAC commands */ /* bufReceive = medusaReceiveLineDelay(hSocket, &nReceiveBufferSize, RECEIVE_DELAY_1, RECEIVE_DELAY_2); if (bufReceive == NULL) return FAILURE; processIAC(hSocket, _psSessionData, &bufReceive, &nReceiveBufferSize); */ return SUCCESS; }
void startTimerList(bool enabledAll) { _initTimers(); timerList.started = true; if (enabledAll) { int i; for (i = 0; i < timerList.size; i++) { Timer* timer = getTimerByIndex(i); if (timer == NULL) { writeError(TIMER_NULL); return; } startTimer(timer); } } }
char bufferGetFirstChar(Buffer* buffer) { int isEmpty = isBufferEmpty(buffer); if (!isEmpty) { char* sPointer = (char*) buffer->s; // Shift to the right cell index sPointer += buffer->readIndex; char result = *sPointer; return result; } else { // We must log the problem writeError(IO_BUFFER_EMPTY); } return 0; }
void bufferWriteChar(Buffer* buffer, char c) { int isFull = isBufferFull(buffer); if (!isFull) { char* sPointer = (char*) buffer->s; // Shift to the right cell index sPointer += buffer->writeIndex; *sPointer = c; buffer->writeIndex++; buffer->writeIndex %= buffer->length; } else { // We must log the problem writeError(IO_BUFFER_FULL); // Print Buffer printDebugBuffer(getErrorOutputStreamLogger(), buffer); } }
unsigned char my_eeprom_read_int(Eeprom* eeprom_, unsigned long index) { if (index >= EEPROM_30F_MAX_INDEX) { writeError(EEPROM_OUT_OF_BOUNDS); return -1; } signed int value; _prog_addressT EE_addr; // initialize a variable to represent the EEPROM address _init_prog_address(EE_addr, eeData); // read value _memcpy_p2d16(&value, EE_addr + (index * _EE_WORD), _EE_WORD); return (unsigned char) value; }
char readFilteredChar(InputStream* inputStream) { char b0 = inputStream->readChar(inputStream); char result; if (filterBinaryToValueChar(b0, &result)) { return result; } else { writeError(IO_READER_READ_FILTERED_CHAR); OutputStream* debugOutputStream = getErrorOutputStreamLogger(); appendString(debugOutputStream, "Char:"); append(debugOutputStream, b0); appendString(debugOutputStream, "Hex:"); appendHex2(debugOutputStream, b0); return FILTERED_RESULT; } }
bool doGameTargetActionItem(GameTargetActionItem* gameTargetActionItem, int* context) { if (gameTargetActionItem->actionItemFunction == NULL) { writeError(TOO_MUCH_TARGET_ACTION_ITEM_FUNCTION_NULL); return false; } GameTargetActionFunction* doFunction = gameTargetActionItem->actionItemFunction; bool succeed = doFunction(context); if (succeed) { gameTargetActionItem->status = ACTION_ITEM_STATUS_DONE; } else { gameTargetActionItem->status = ACTION_ITEM_STATUS_ERROR; } return succeed; }
void my_eeprom_write_int(Eeprom* eeprom_, unsigned long index, unsigned char value) { if (index >= EEPROM_30F_MAX_INDEX) { writeError(EEPROM_OUT_OF_BOUNDS); return; } _prog_addressT EE_addr; // initialize a variable to represent the EEPROM address _init_prog_address(EE_addr, eeData); _erase_eedata(EE_addr + (index * _EE_WORD), _EE_WORD); _wait_eedata(); // write value _write_eedata_word(EE_addr + (index * _EE_WORD), value); _wait_eedata(); }
// Displays information about the module and how it must be used void summaryUsage(char **ppszSummary) { // Memory for ppszSummary will be allocated here - caller is responsible for freeing it int iLength = 0; if (*ppszSummary == NULL) { iLength = strlen(MODULE_SUMMARY_USAGE) + strlen(MODULE_VERSION) + strlen(MODULE_SUMMARY_FORMAT) + 1; *ppszSummary = (char*)malloc(iLength); memset(*ppszSummary, 0, iLength); snprintf(*ppszSummary, iLength, MODULE_SUMMARY_FORMAT, MODULE_SUMMARY_USAGE, MODULE_VERSION); } else { writeError(ERR_ERROR, "%s reports an error in summaryUsage() : ppszSummary must be NULL when called", MODULE_NAME); } }
void ConsoleText::onLogMessage(Core::LoggerMessage const& message) { switch(message.channel) { case Core::LoggerChannels::Warning: writeWarning(message.message); break; case Core::LoggerChannels::Error: // Intentional fall through case Core::LoggerChannels::Fatal: writeError(message.message); break; default: write(message.message); break; } }
void MainWindow::dataToPLC() { SerialCommunication link; link.setVars(vars); CommunicationDialog* dialog = new CommunicationDialog; link.setData(lcd->getData()); link.setFont(font); dialog->setMessage("Поиск устройства"); connect(&link,SIGNAL(searchStep(float)),dialog,SLOT(updatePercent(float))); connect(&link,SIGNAL(searchError(QString)),dialog,SLOT(setMessage(QString))); connect(&link,SIGNAL(searchOK(QString)),dialog,SLOT(setMessage(QString))); connect(&link,SIGNAL(writeStep(float)),dialog,SLOT(updatePercent(float))); connect(&link,SIGNAL(writeError(QString)),dialog,SLOT(setMessage(QString))); connect(&link,SIGNAL(writeOK(QString)),dialog,SLOT(setMessage(QString))); link.searchController(); dialog->exec(); delete dialog; }
void Save::loadSave(CIndieLib* mI, Ship*& mShip, vector<Planet*>& mPlanets) { setMI(mI); getLoadFile()->open("../SpaceGame/Saves/quickSave.txt", ios::in); if (!getLoadFile()->is_open()) { writeError(1000, 200, "Save", "Can't open file for reading!"); return; } mShip = new Ship(); mShip->setMI(getMI()); while (readLine(mShip, mPlanets)); getLoadFile()->close(); getMI()->_input->update(); getMI()->_render->beginScene(); getMI()->_entity2dManager->renderEntities2d(); getMI()->_render->endScene(); }
void addTargetActionItem(GameTargetActionItemList* targetActionItemList, GameTargetActionItem* targetActionItem, GameTargetActionFunction* actionItemFunction, char* name // float timeToAchieve, ) { unsigned char size = targetActionItemList->size; if (size < MAX_TARGET_ACTION_ITEM) { targetActionItem->actionItemFunction = actionItemFunction; targetActionItem->name = name; // targetActionItem->timeToAchieve = timeToAchieve; targetActionItem->status = ACTION_ITEM_STATUS_TODO; targetActionItemList->items[size] = targetActionItem; targetActionItemList->size++; } else { writeError(TOO_MUCH_TARGET_ACTION_ITEM); } }
void loopUntilStart(StartMatch* startMatch) { if (startMatch == NULL) { writeError(ROBOT_START_MATCH_DETECTOR_PC_NULL); return; } if (startMatch->waitForStart) { appendString(getAlwaysOutputStreamLogger(), "WAIT START..."); while (!startMatch->isMatchStartedFunction(startMatch)) { startMatch->loopUntilStartHandleFunction(startMatch); } appendString(getAlwaysOutputStreamLogger(), "OK"); println(getAlwaysOutputStreamLogger()); markStartMatch(startMatch->endMatch); } else { appendString(getAlwaysOutputStreamLogger(), "GO !"); println(getAlwaysOutputStreamLogger()); } }
/** * @private */ void _internalUpdateTimerListValues(int incrementSinceLastCall) { timerList.working = true; if (timerList.size > 0) { int i = 0; for (i = 0; i < timerList.size; i++) { Timer* currentTimer = getTimerByIndex(i); if (currentTimer == NULL) { writeError(TIMER_NULL); timerList.working = false; return; } bool enabled = currentTimer->enabled; if (!enabled) { continue; } // increments the counter and test if it is > to the timeDiviser currentTimer->timeInternalCounter += incrementSinceLastCall; if (currentTimer->timeInternalCounter >= currentTimer->timeDiviser) { // block the timer if we wait for bool lock = currentTimer->lock; if (lock) { continue; } // we only subtract and not clear to 0, so that, if the timer is locked, we will not forget // any firing currentTimer->timeInternalCounter -= currentTimer->timeDiviser; currentTimer->time++; // lock the timer to avoid concurrence problem currentTimer->working = true; if (currentTimer->callback) { currentTimer->callback(currentTimer); } // indicates the timer is not working currentTimer->working = false; } } } timerList.working = false; }
BOOL getPinValue(int pinIndex) { switch (pinIndex) { // PORT B case PIN_INDEX_RB0: return PORTBbits.RB0; case PIN_INDEX_RB1: return PORTBbits.RB1; case PIN_INDEX_RB2: return PORTBbits.RB2; case PIN_INDEX_RB3: return PORTBbits.RB3; case PIN_INDEX_RB4: return PORTBbits.RB4; case PIN_INDEX_RB5: return PORTBbits.RB5; case PIN_INDEX_RB6: return PORTBbits.RB6; case PIN_INDEX_RB7: return PORTBbits.RB7; case PIN_INDEX_RB8: return PORTBbits.RB8; case PIN_INDEX_RB9: return PORTBbits.RB9; case PIN_INDEX_RB10: return PORTBbits.RB10; case PIN_INDEX_RB11: return PORTBbits.RB11; case PIN_INDEX_RB12: return PORTBbits.RB12; // PORT C case PIN_INDEX_RC13: return PORTCbits.RC13; case PIN_INDEX_RC14: return PORTCbits.RC14; case PIN_INDEX_RC15: return PORTCbits.RC15; // PORT D case PIN_INDEX_RD0: return PORTDbits.RD0; case PIN_INDEX_RD1: return PORTDbits.RD1; case PIN_INDEX_RD2: return PORTDbits.RD2; case PIN_INDEX_RD3: return PORTDbits.RD3; case PIN_INDEX_RD8: return PORTDbits.RD8; case PIN_INDEX_RD9: return PORTDbits.RD9; // PORT A case PIN_INDEX_RA11: return PORTAbits.RA11; // PORTF case PIN_INDEX_RF0: return PORTFbits.RF0; case PIN_INDEX_RF6: return PORTFbits.RF6; } writeError(IO_PIN_INDEX_ERROR); // log the error return FALSE; }
int sendGet(int hSocket, _MODULE_DATA* _psSessionData, char* szLogin, char* szPassword) { char* bufSend = NULL; int nSendBufferSize = 0; int nRet = SUCCESS; if ((_psSessionData->szFormRest == NULL) || (_psSessionData->szFormRest[0] == 0)) nSendBufferSize = asprintf(&bufSend, "GET /%s?%s%s&%s%s HTTP/1.1\r\nHost: %s\r\nUser-Agent: %s\r\nConnection: close\r\n\r\n", _psSessionData->szDir, _psSessionData->szFormUser, szLogin, _psSessionData->szFormPass, szPassword, _psSessionData->szHostHeader, _psSessionData->szUserAgent); else nSendBufferSize = asprintf(&bufSend, "GET /%s?%s%s&%s%s&%s HTTP/1.1\r\nHost: %s\r\nUser-Agent: %s\r\nConnection: close\r\n\r\n", _psSessionData->szDir, _psSessionData->szFormUser, szLogin, _psSessionData->szFormPass, szPassword, _psSessionData->szFormRest, _psSessionData->szHostHeader, _psSessionData->szUserAgent); if (medusaSend(hSocket, bufSend, nSendBufferSize, 0) < 0) { writeError(ERR_ERROR, "%s failed: medusaSend was not successful", MODULE_NAME); nRet = FAILURE; } free(bufSend); return nRet; }