void SimpleProperties::Reader::printAll(NdbOut& ndbout){ char tmp[1024]; for(first(); valid(); next()){ switch(getValueType()){ case SimpleProperties::Uint32Value: ndbout << "Key: " << getKey() << " value(" << getValueLen() << ") : " << getUint32() << endl; break; case SimpleProperties::BinaryValue: case SimpleProperties::StringValue: if(getValueLen() < 1024){ getString(tmp); ndbout << "Key: " << getKey() << " value(" << getValueLen() << ") : " << "\"" << tmp << "\"" << endl; } else { ndbout << "Key: " << getKey() << " value(" << getValueLen() << ") : " << "\"" << "<TOO LONG>" << "\"" << endl; } break; default: ndbout << "Unknown type for key: " << getKey() << " type: " << (Uint32)getValueType() << endl; } } }
uint64_t TraderApi::insertOrder(dict req, uint64_t sessionid) { XTPOrderInsertInfo myreq = XTPOrderInsertInfo(); memset(&myreq, 0, sizeof(myreq)); getDouble(req, "stop_price", &myreq.stop_price); getDouble(req, "price", &myreq.price); getStr(req, "ticker", myreq.ticker); getUint32(req, "order_client_id", &myreq.order_client_id); getUint64(req, "order_xtp_id", &myreq.order_xtp_id); getInt64(req, "quantity", &myreq.quantity); int price_type; int side; int market; int business_type; getInt(req, "price_type", &price_type); getInt(req, "side", &side); getInt(req, "market", &market); getInt(req, "business_type", &business_type); myreq.price_type = (XTP_PRICE_TYPE)price_type; myreq.side = (XTP_SIDE_TYPE)side; myreq.market = (XTP_MARKET_TYPE)market; myreq.business_type = (XTP_BUSINESS_TYPE)business_type; return this->api->InsertOrder(&myreq, sessionid); };
// Defined by the WebCrypto spec as: // // dictionary RsaKeyGenParams : Algorithm { // unsigned long modulusLength; // BigInteger publicExponent; // }; bool parseRsaKeyGenParams(const Dictionary& raw, uint32_t& modulusLength, RefPtr<Uint8Array>& publicExponent, const ErrorContext& context, String& errorDetails) { if (!getUint32(raw, "modulusLength", modulusLength, context, errorDetails)) return false; if (!getBigInteger(raw, "publicExponent", publicExponent, context, errorDetails)) return false; return true; }
bool ApplyTag::applyTagToBuffer() { quint32 peHeader = getUint32(kPEHeaderOffset); quint32 certDirAddressOffset = 152; // Read certificate directory info. quint32 certDirOffset = getUint32(peHeader + certDirAddressOffset); if (certDirOffset == 0) return false; quint32 certDirSize = getUint32(peHeader + certDirAddressOffset + 4); // Increase the size of certificate directory. int newCertSize = certDirSize + m_tagBuffer.size(); putUint32(newCertSize, peHeader + certDirAddressOffset + 4); // Increase the certificate struct size. putUint32(newCertSize, certDirOffset); return true; }
QByteArray MRAData::getBinaryString() { int len = getUint32(); if (m_data.size() >= (m_pointer + len)) { if (len == 0) { return QByteArray(); } QByteArray result = m_data.mid(m_pointer, len); m_pointer += len; return result; } else { return QByteArray(); } }
void printCell(Cell *cell){ switch(cell->ctype){ case INT32: printf("%d\t",getInt32(cell->value)); break; case UINT32: printf("%d\t",getUint32(cell->value)); break; case INT64: printf("%ld\t",getInt64(cell->value)); break; case UINT64: printf("%lu\t",getUint64(cell->value)); break; case INT8: printf("%d",getInt8(cell->value)); break; case INT16: printf("%d",getInt16(cell->value)); break; case FLOAT: printf("%f\t",getFloat(cell->value)); break; case DOUBLE: printf("%f\t",getDouble(cell->value)); break; case STRING: //MySQL type BINARY may be STRING { char *value =(char *) cell->value; printf("%s\t",(char*)value); break; } case BINARY: printf("BINARY\t"); break; default: printf("UNKNOW\t"); break; } }
QString MRAData::getUnicodeString() { int len = getUint32(); if (m_data.size() >= (m_pointer + len)) { if (len == 0) { return QString(); } CodecHolder holder("UTF-16LE"); QString result = QString::fromAscii( m_data.mid(m_pointer, len).constData(), len ); m_pointer += len; return result; } else { return QString(); } }
bool Babuino::withInt32() { STACKPTR location, index; int32_t rhs, lhs; switch (_regs.opCode) { case OP_ASHIFT: case OP_LSHIFT: { int8_t shift; popUint8(_stack, (uint8_t*)&shift); popUint32(_stack, (uint32_t*)&lhs); if (shift >= 0) pushUint32(_stack, (uint32_t)(lhs << shift)); else pushUint32(_stack, (uint32_t)(lhs >> -shift)); return true; } case OP_SET: //Serial.println("---set---"); popStackPtr(_stack, &location); popUint32(_stack, (uint32_t*)&rhs); setUint32(_stack, location, (uint32_t)rhs); return true; case OP_GET: //Serial.println("---get---"); popStackPtr(_stack, &location); getUint32(_stack, location, (uint32_t*)&rhs); pushUint32(_stack, (uint32_t)rhs); return true; case OP_ASET: //Serial.println("---aset---"); popStackPtr(_stack, &location); popStackPtr(_stack, &index); popUint32(_stack, (uint32_t*)&rhs); setUint32(_stack, location + index * sizeof(int32_t), (uint32_t)rhs); return true; case OP_AGET: //Serial.println("---aget---"); popStackPtr(_stack, &location); popStackPtr(_stack, &index); getUint32(_stack, location + index * sizeof(int32_t), (uint32_t*)&rhs); pushUint32(_stack, (uint32_t)rhs); return true; case OP_OUTPUT: { //Serial.print("output "); popUint32(_stack, (uint32_t*)&rhs); // The return value // point to where the arguments size is on the stack. location = getArgsLocation(); uint8_t argsSize; getUint8(_stack, location - sizeof(uint8_t), &argsSize); // Get size of args. // If the size > 0 then step over the size location too. // Otherwise keep pointing to the same place because the return // value should overwrite where the arguments size would be. if (argsSize > 0) argsSize += sizeof(uint8_t); setUint32(_stack, location - (STACKPTR)argsSize - sizeof(int32_t), (uint32_t)rhs); } return true; case OP_SEND: { //Serial.println("---send---"); popUint32(_stack, (uint32_t*)&rhs); uint8_t buf[sizeof(int32_t)]; hton(rhs, buf); //_defaultStream->write(nbuf, sizeof(int32_t)); // Replaced for debugging _defaultStream->print(rhs); } return true; case OP_SENDN: { //Serial.println("---sendn---"); uint8_t items; uint8_t port; STACKPTR bufLoc; popUint8(_stack, &items); popUint8(_stack, &port); popStackPtr(_stack, &bufLoc); int32_t* buf = (int32_t*)getStackAddress(_stack, bufLoc); uint8_t nbuf[sizeof(int32_t)]; for (int i = 0; i < items; i++) { rhs = *buf; hton(rhs, nbuf); //_defaultStream->write(nbuf, sizeof(int32_t)); // Replaced for debugging _defaultStream->print(rhs); buf++; } } return true; #ifdef SUPPORT_STRING case OP_TOSTR: { //Serial.println("---tostr---"); popUint32(_stack, (uint32_t*)&rhs); // ***KLUDGE WARNING*** // Borrowing unused (hopefully) stack space as a buffer! // just to avoid having to allocate another buffer. char* psz = (char *)getTopAddress(_stack); itoa((int) rhs, psz, 10); // Logically this is wrong because I'm apparently // pushing a string to a location that it already // occupies. However, the stack implementation // pushes strings onto a separate stack, then // pushes the location onto the main stack. So // the string doesn't get copied over itself, and // is already copied before the first characters are // overwritten by pushing the said location onto the // main stack. pushString(_stack, (uint8_t*)psz); } return true; #endif case OP_FOREACH: { //Serial.print("foreach "); PROGPTR blockAddr; popProgPtr(_stack, &blockAddr); // Block address popStackPtr(_stack, &location); // Iterator variable location (Variable contains a 'pointer') uint8_t itemsRemaining; popUint8(_stack, &itemsRemaining); // Number of items remaining // If we've gone through the block then we need to pop the // previous list item off the stack if (hasBlockExecuted()) { uint32_t tmpUint32; popUint32(_stack, &tmpUint32); } if (itemsRemaining > 0) // Any items remaining { // Set the value of the variable to the location on the // stack of the next list item (ie the top) setStackPtr(_stack, location, getTop(_stack) - sizeof(int32_t)); _regs.pc = blockAddr; // Point to the top of the block for the next iteration itemsRemaining--; // Decrement the number of items remaining pushUint8(_stack, itemsRemaining); // Save number of items remaining for next time pushStackPtr(_stack, location); // Save iterator variable location for next time pushProgPtr(_stack, blockAddr); // Save block address for next time } else { ascendBlock(); // Leaving. Pop the block. } } return true; } popUint32(_stack, (uint32_t*)&rhs); switch (_regs.opCode) { case OP_BITNOT: pushUint32(_stack, (uint32_t)~rhs); return true; case OP_ABS: pushUint32(_stack, (uint32_t)abs(rhs)); return true; case OP_NEG: pushUint32(_stack, (uint32_t)-rhs); return true; } popUint32(_stack, (uint32_t*)&lhs); switch (_regs.opCode) { case OP_ADD: pushUint32(_stack, (uint32_t)(lhs + rhs)); return true; case OP_SUB: pushUint32(_stack, (uint32_t)(lhs - rhs)); return true; case OP_MUL: pushUint32(_stack, (uint32_t)(lhs * rhs)); return true; case OP_DIV: pushUint32(_stack, (uint32_t)(lhs / rhs)); return true; case OP_MOD: pushUint32(_stack, (uint32_t)(lhs % rhs)); return true; case OP_EQ: pushUint8(_stack, (uint8_t)(lhs == rhs)); return true; case OP_GT: pushUint8(_stack, (uint8_t)(lhs > rhs)); return true; case OP_LT: pushUint8(_stack, (uint8_t)(lhs < rhs)); return true; case OP_LE: pushUint8(_stack, (uint8_t)(lhs <= rhs)); return true; case OP_GE: pushUint8(_stack, (uint8_t)(lhs >= rhs)); return true; case OP_NE: pushUint8(_stack, (uint8_t)(lhs != rhs)); return true; case OP_BITAND: pushUint32(_stack, (uint32_t)(lhs & rhs)); return true; case OP_BITOR: pushUint32(_stack, (uint32_t)(lhs | rhs)); return true; case OP_BITXOR: pushUint32(_stack, (uint32_t)(lhs ^ rhs)); return true; case OP_MIN: pushUint32(_stack, (uint32_t)min(lhs, rhs)); return true; case OP_MAX: pushUint32(_stack, (uint32_t)max(lhs, rhs)); return true; } return false; }
static void handleAggDataUpdate(DDTypedBufferMsg_t *msg, PS_DataBuffer_t *data) { char *ptr = data->buf; AccountDataExt_t aggData; PStask_ID_t logger; /* get logger's task ID */ getInt32(&ptr, &logger); if (!findJobByLogger(logger)) { mlog("%s: update unknown logger %s\n", __func__, PSC_printTID(logger)); return; } getUint64(&ptr, &aggData.maxThreadsTotal); getUint64(&ptr, &aggData.maxVsizeTotal); getUint64(&ptr, &aggData.maxRssTotal); getUint64(&ptr, &aggData.maxThreads); getUint64(&ptr, &aggData.maxVsize); getUint64(&ptr, &aggData.maxRss); getUint64(&ptr, &aggData.avgThreadsTotal); getUint64(&ptr, &aggData.avgThreadsCount); getUint64(&ptr, &aggData.avgVsizeTotal); getUint64(&ptr, &aggData.avgVsizeCount); getUint64(&ptr, &aggData.avgRssTotal); getUint64(&ptr, &aggData.avgRssCount); getUint64(&ptr, &aggData.cutime); getUint64(&ptr, &aggData.cstime); getUint64(&ptr, &aggData.minCputime); getUint64(&ptr, &aggData.pageSize); getUint32(&ptr, &aggData.numTasks); getUint64(&ptr, &aggData.maxMajflt); getUint64(&ptr, &aggData.totMajflt); getUint64(&ptr, &aggData.totCputime); getUint64(&ptr, &aggData.cpuFreq); getDouble(&ptr, &aggData.maxDiskRead); getDouble(&ptr, &aggData.totDiskRead); getDouble(&ptr, &aggData.maxDiskWrite); getDouble(&ptr, &aggData.totDiskWrite); getInt32(&ptr, &aggData.taskIds[ACCID_MAX_VSIZE]); getInt32(&ptr, &aggData.taskIds[ACCID_MAX_RSS]); getInt32(&ptr, &aggData.taskIds[ACCID_MAX_PAGES]); getInt32(&ptr, &aggData.taskIds[ACCID_MIN_CPU]); getInt32(&ptr, &aggData.taskIds[ACCID_MAX_DISKREAD]); getInt32(&ptr, &aggData.taskIds[ACCID_MAX_DISKWRITE]); getTime(&ptr, &aggData.rusage.ru_utime.tv_sec); getTime(&ptr, &aggData.rusage.ru_utime.tv_usec); getTime(&ptr, &aggData.rusage.ru_stime.tv_sec); getTime(&ptr, &aggData.rusage.ru_stime.tv_usec); setAggData(msg->header.sender, logger, &aggData); mdbg(PSACC_LOG_UPDATE_MSG, "%s: from %s maxThreadsTot %lu maxVsizeTot %lu" " maxRsstot %lu maxThreads %lu maxVsize %lu maxRss %lu numTasks %u\n", __func__, PSC_printTID(msg->header.sender), aggData.maxThreadsTotal, aggData.maxVsizeTotal, aggData.maxRssTotal, aggData.maxThreads, aggData.maxVsize, aggData.maxRss, aggData.numTasks); }
// Login request (http://mc.kev009.com/wiki/Protocol#Login_Request_.280x01.29) int PacketHandler::login_request(User *user) { //Check that we have enought data in the buffer if(user->buffer.size() < 12) return PACKET_NEED_MORE_DATA; uint32 curpos = 0; int i; //Client protocol version uint8 tmpIntArray[4] = {0}; for(i = 0; i < 4; i++) tmpIntArray[i] = user->buffer[curpos+i]; int version = getUint32(&tmpIntArray[0]); curpos += 4; //Player name length uint8 tmpShortArray[2] = {0}; for(i = 0; i < 2; i++) tmpShortArray[i] = user->buffer[curpos+i]; int len = getUint16(&tmpShortArray[0]); curpos += 2; //Check for data if(user->buffer.size() < curpos+len+2) return PACKET_NEED_MORE_DATA; std::string player; //Read player name for(int pos = 0; pos < len; pos++) { player += user->buffer[curpos+pos]; } curpos += len; //Password length for(i = 0; i < 2; i++) tmpShortArray[i] = user->buffer[curpos+i]; len = getUint16(&tmpShortArray[0]); curpos += 2; std::string passwd; //Check for data if(user->buffer.size() < curpos+len) return PACKET_NEED_MORE_DATA; //Read password for(int pos = 0; pos < len; pos++) { passwd += user->buffer[curpos+pos]; } curpos += len; //Package completely received, remove from buffer user->buffer.erase(user->buffer.begin(), user->buffer.begin()+curpos); std::cout << "Player " << user->UID << " login v." << version <<" : " << player <<":"<< passwd << std::endl; // If version is not 2 or 3 if(version != 4 && version != 3 && version != 2) { user->kick(Conf::get().sValue("wrong_protocol_message")); return curpos; } // If userlimit is reached if((int)Users.size() >= Conf::get().iValue("userlimit")) { user->kick(Conf::get().sValue("server_full_message")); return curpos; } user->changeNick(player); //Load user data user->loadData(); //Login OK package char data[9] = {0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; putSint32((uint8 *)&data[1], user->UID); bufferevent_write(user->buf_ev, (char *)&data[0], 9); //Send server time (after dawn) uint8 data3[9] = {0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00}; bufferevent_write(user->buf_ev, (char *)&data3[0], 9); //Inventory uint8 data4[7+36*5]; data4[0] = 0x05; putSint32(&data4[1], -1); data4[5] = 0; data4[6] = 36; int curpos2 = 7; //Send main inventory for(i = 0; i < 36; i++) { if(user->inv.main[i].count) { putSint16(&data4[curpos2], user->inv.main[i].type); //Type curpos2 += 2; data4[curpos2] = user->inv.main[i].count; //Count curpos2++; putSint16(&data4[curpos2], user->inv.main[i].health); //Health curpos2 += 2; } else { //Empty slot putSint16(&data4[curpos2], -1); curpos2 += 2; } } bufferevent_write(user->buf_ev, (char *)&data4[0], curpos2); //Send equipped inventory putSint32(&data4[1], -3); data4[6] = 4; curpos2 = 7; for(i = 0; i < 4; i++) { if(user->inv.equipped[i].count) { putSint16(&data4[curpos2], user->inv.equipped[i].type); //Type curpos2 += 2; data4[curpos2] = user->inv.equipped[i].count; //Count curpos2++; putSint16(&data4[curpos2], user->inv.equipped[i].health); //Health curpos2 += 2; } else { //Empty slot putSint16(&data4[curpos2], -1); curpos2 += 2; } } bufferevent_write(user->buf_ev, (char *)&data4[0], curpos2); //Send crafting inventory putSint32(&data4[1], -2); data4[6] = 4; curpos2 = 7; for(i = 0; i < 4; i++) { if(user->inv.crafting[i].count) { putSint16(&data4[curpos2], user->inv.crafting[i].type); //Type curpos2 += 2; data4[curpos2] = user->inv.crafting[i].count; //Count curpos2++; putSint16(&data4[curpos2], user->inv.crafting[i].health); //Health curpos2 += 2; } else { //Empty slot putSint16(&data4[curpos2], -1); curpos2 += 2; } } bufferevent_write(user->buf_ev, (char *)&data4[0], curpos2); // Send motd std::ifstream motdfs( MOTDFILE.c_str()); std::string temp; while(getline( motdfs, temp )) { // If not commentline if(temp[0] != COMMENTPREFIX) Chat::get().sendMsg(user, temp, Chat::USER); } motdfs.close(); //Teleport player user->teleport(user->pos.x, user->pos.y+2, user->pos.z); //Put nearby chunks to queue for(int x = -user->viewDistance; x <= user->viewDistance; x++) { for(int z = -user->viewDistance; z <= user->viewDistance; z++) { user->addQueue((sint32)user->pos.x/16+x, (sint32)user->pos.z/16+z); } } // Push chunks to user user->pushMap(); //Spawn this user to others user->spawnUser((sint32)user->pos.x*32, ((sint32)user->pos.y+2)*32, (sint32)user->pos.z*32); //Spawn other users for connected user user->spawnOthers(); //Send "On Ground" signal char data6[2] = {0x0A, 0x01}; bufferevent_write(user->buf_ev, (char *)&data6[0], 2); user->logged = true; Chat::get().sendMsg(user, player+" connected!", Chat::ALL); return curpos; }
luabridge::LuaRef CLuaBinary::getStruct(luabridge::LuaRef objAttr) { assert(objAttr.isTable()); DataType emType; int iSize = Q_INIT_NUMBER; std::string strName; luabridge::LuaRef objVal = luabridge::newTable(m_pLua); for (int i = 1; i <= objAttr.length(); i++) { luabridge::LuaRef objTmp = objAttr[i]; if (!objTmp.isTable() || STATTRTAB_MINLENS > objTmp.length()) { break; } luabridge::LuaRef objChildStAttr = getStructAttr(objTmp, strName, emType, iSize); switch(emType) { case DTYPE_SINT8: { objVal[strName] = getSint8(); } break; case DTYPE_UINT8: { objVal[strName] = getUint8(); } break; case DTYPE_BOOL: { objVal[strName] = getBool(); } break; case DTYPE_SINT16: { objVal[strName] = getSint16(); } break; case DTYPE_UINT16: { objVal[strName] = getUint16(); } break; case DTYPE_SINT32: { objVal[strName] = getSint32(); } break; case DTYPE_UINT32: { objVal[strName] = getUint32(); } break; case DTYPE_SINT64: { objVal[strName] = getSint64(); } break; case DTYPE_UINT64: { objVal[strName] = getUint64(); } break; case DTYPE_FLOAT: { objVal[strName] = getFloat(); } break; case DTYPE_DOUBLE: { objVal[strName] = getDouble(); } break; case DTYPE_STRING: { std::string strVal = getString(); objVal[strName] = strVal; skipRead((unsigned int)(iSize - (strVal.size() + 1))); } break; case DTYPE_BYTE: { objVal[strName] = getByte(iSize); } break; case DTYPE_STRUCT: { objVal[strName] = getStruct(objChildStAttr); } break; case DTYPE_SKIP: { if (iSize > Q_INIT_NUMBER) { skipRead(iSize); } } break; default: break; } } return objVal; }
static void handlePrintChildMsg(Forwarder_Data_t *fwdata, char *ptr) { Step_t *step = fwdata->userData; uint8_t type; uint32_t rank, lrank, i; size_t len; static IO_Msg_Buf_t *lineBuf; int32_t myNodeID = step->localNodeId; static int initBuf = 0; /* read message */ getUint8(&ptr, &type); getUint32(&ptr, &rank); char *msg = getDataM(&ptr, &len); /* get local rank from rank */ lrank = getLocalRankID(rank, step, myNodeID); if (lrank == (uint32_t )-1) { mlog("%s: invalid node rank for rank %i myNodeID %i step %u:%u\n", __func__, rank, myNodeID, step->jobid, step->stepid); ufree(msg); return; } /* track I/O channels */ if (!len) { if (type == STDOUT && step->outChannels) { if (step->outChannels[lrank] == 0) { ufree(msg); return; } step->outChannels[lrank] = 0; } if (type == STDERR && step->errChannels) { if (step->errChannels[lrank] == 0) { ufree(msg); return; } step->errChannels[lrank] = 0; } } /* handle unbuffered IO */ if (type == STDERR || (!(step->taskFlags & LAUNCH_LABEL_IO) && !(step->taskFlags & LAUNCH_BUFFERED_IO)) || step->taskFlags & LAUNCH_PTY) { writeIOmsg(msg, len, rank, type, fwdata, step, lrank); ufree(msg); return; } /* handle buffered IO */ if (!initBuf) { lineBuf = umalloc(sizeof(IO_Msg_Buf_t) * step->globalTaskIdsLen[myNodeID]); for (i=0; i<step->globalTaskIdsLen[myNodeID]; i++) { lineBuf[i].out.buf = lineBuf[i].err.buf = NULL; lineBuf[i].out.bufUsed = lineBuf[i].err.bufUsed = 0; } initBuf = 1; } handleBufferedMsg(msg, len, type == STDOUT ? &lineBuf[lrank].out : &lineBuf[lrank].err, fwdata, step, rank, type, lrank); ufree(msg); }
/*EventCousor reader*/ static uint32_t readUint32(EventCursor *evcur){ uint32_t v = getUint32(evcur->ev+evcur->cur); evcur->cur += 4; return v; }
uint32_t MachOFile::readUint32() { unsigned int temp; readBytes((char*)&temp, sizeof(temp)); return getUint32(temp); }
unsigned int KPaquet::timestamp(void) { return getUint32(_data.data(), 4); }
unsigned int KPaquet::bodySize() const { return getUint32(_data.data()); }
uint32_t ClientMessage::get() { return getUint32(); }