//------------------------------------------------------------------------------------------------- bool FIXReader::read(f8String& to) // read a complete FIX message { char msg_buf[_max_msg_len] = {}; int result(sockRead(msg_buf, _bg_sz)); if (result == static_cast<int>(_bg_sz)) { char bt; size_t offs(_bg_sz); do // get the last chrs of bodylength and ^A { if (sockRead(&bt, 1) != 1) return false; if (!isdigit(bt) && bt != default_field_separator) throw IllegalMessage(msg_buf); msg_buf[offs++] = bt; } while (bt != default_field_separator && offs < _max_msg_len); to.assign(msg_buf, offs); f8String tag, bgstr, len; unsigned result; if ((result = MessageBase::extract_element(to.data(), to.size(), tag, bgstr))) { if (tag != "8") throw IllegalMessage(to); if (bgstr != _session.get_ctx()._beginStr) // invalid FIX version throw InvalidVersion(bgstr); if ((result = MessageBase::extract_element(to.data() + result, to.size() - result, tag, len))) { if (tag != "9") throw IllegalMessage(to); const unsigned mlen(fast_atoi<unsigned>(len.c_str())); if (mlen == 0 || mlen > _max_msg_len - _bg_sz - _chksum_sz) // invalid msglen throw InvalidBodyLength(mlen); // read the body if ((result = sockRead(msg_buf, mlen) != static_cast<int>(mlen))) return false; // read the checksum if ((result = sockRead(msg_buf + mlen, _chksum_sz) != static_cast<int>(_chksum_sz))) return false; to.append(msg_buf, mlen + _chksum_sz); _session.update_received(); //string ts; //cerr << GetTimeAsStringMS(ts, &_session.get_last_received(), 9) << endl; return true; } } throw IllegalMessage(to); } return false; }
// En la base de datos se guarda el path sin la carpeta del FS bool ManejadorArchivosYMetadatos::subirArchivo (string username, string filepath, const char* data, int dataLen, string jsonMetadatos, int cuota, int nuevaVersion, bool force) { if (not validador.verificarPermisos(username, filepath)) return false; string filepathCompleto = this->pathFileSystem + "/" + filepath; if (validador.existeArchivo(filepathCompleto) and validador.existeMetadato(filepath)) { if (not force and not validador.esVersionValida(filepath, nuevaVersion)) { throw InvalidVersion("Se quiso subir " + filepath + " con version " + to_string(nuevaVersion), getLatestVersion(filepath)); } if ( force ) nuevaVersion = getLatestVersion(filepath) + 1; Logger::logDebug("Actualizando archivo con path: " + filepath); return actualizarArchivo(username, filepath, data, dataLen, cuota, nuevaVersion - 1); } if (not this->actualizarArchivo(username, filepath, data, dataLen, cuota, FIRST - 1)) { Logger::logWarn("Fallo la subida del archivo " + filepath); return false; } return manejadorMetadatos.cargarMetadato(filepath, jsonMetadatos); }
//! Decode command in text form. //! @param[in] cmd command in text form. //! @return command object. static AbstractCommand* decode(const std::string& cmd) { // Validate CRC. if (AbstractCommand::getCRC(cmd) != AbstractCommand::computeCRC(cmd, cmd.size() - c_ssc_footer_size)) throw InvalidChecksum(); // Split command. std::vector<std::string> parts; DUNE::Utils::String::split(cmd, ",", parts); // Check minimum arguments. if (parts.size() < c_ssc_min_args) throw InvalidFormat("minimum arguments not present"); // Extract prefix. if (parts[0] != c_ssc_prefix) throw InvalidFormat("invalid prefix"); // Extract version. unsigned version = 0; if (std::sscanf(parts[AbstractCommand::OFFS_VERSION].c_str(), "%u", &version) != 1) throw InvalidVersion(); // Extract flags. unsigned flags = 0; if (std::sscanf(parts[AbstractCommand::OFFS_FLAGS].c_str(), "%02X", &flags) != 1) throw InvalidFormat("invalid flags"); // Extract TTL. unsigned ttl = 0; if (std::sscanf(parts[AbstractCommand::OFFS_TTL].c_str(), "%u", &ttl) != 1) throw InvalidFormat("invalid ttl"); // Extract priority. unsigned priority = 0; if (std::sscanf(parts[AbstractCommand::OFFS_PRIORITY].c_str(), "%u", &priority) != 1) throw InvalidFormat("invalid priority"); // Extract source. unsigned src = 0; if (std::sscanf(parts[AbstractCommand::OFFS_SRC].c_str(), "%u", &src) != 1) throw InvalidFormat("invalid source"); // Extract number of destinations. unsigned dst_count = 0; if (std::sscanf(parts[AbstractCommand::OFFS_DST_COUNT].c_str(), "%u", &dst_count) != 1) throw InvalidFormat("invalid destination count"); // Extract destinations. unsigned dst = 0; std::set<unsigned> dsts; for (unsigned i = 0; i < dst_count; ++i) { // FIXME: check size. if (std::sscanf(parts[AbstractCommand::OFFS_DST + i].c_str(), "%u", &dst) != 1) throw InvalidFormat("invalid destination"); dsts.insert(dst); } // Command name. std::string name = parts[AbstractCommand::OFFS_DST + dst_count]; AbstractCommand* cmd_obj = createByName(name); if (cmd_obj == NULL) throw InvalidValue(); cmd_obj->setName(name); cmd_obj->setSource(src); cmd_obj->setDestinations(dsts); cmd_obj->setVersion(version); cmd_obj->setPriority(priority); cmd_obj->setTTL(ttl); cmd_obj->setFlags(flags); size_t args_start = AbstractCommand::OFFS_DST + dst_count + 1; cmd_obj->decodeArgs(parts, args_start); return cmd_obj; }