// Implicit conversion to long function. numeric::operator long() const { return toLong(); }
void printAttributes(std::ostream & out, const Node * n) { out << "["; auto names = n->attributeNames(); int i = 0; for(auto name : names) { if(i++ > 0) out << ", "; out << name.toString() <<"="; switch(n->kindOf(name)) { case AttributeKind::f: out << n->f(name); break; case AttributeKind::fs: printPrimList(out,n->fs(name)); break; case AttributeKind::i: out << n->i(name); break; case AttributeKind::is: printPrimList(out,n->is(name)); break; case AttributeKind::s: out << n->s(name); break; case AttributeKind::ss: printPrimList(out,n->ss(name)); break; case AttributeKind::t: { at::Tensor t = n->t(name); // 1-elem tensors are usually boxed scalars, so print them like it if (t.numel() == 1) { auto scalar = at::Scalar(t.view({})).local(); out << "{"; if (scalar.isFloatingPoint()) { out << scalar.toDouble(); } else { out << scalar.toLong(); } out << "}"; } else if (t.numel() <= max_tensor_display_size) { // TODO: This is awful code. Also it doesn't work on Windows. std::ostringstream tensor_ss; tensor_ss << t; std::string tensor_s{tensor_ss.str()}; // Remove newlines std::replace(tensor_s.begin(), tensor_s.end(), '\n', ' '); out << tensor_s; } else { out << "<Tensor>"; } break; } case AttributeKind::ts: out << "[<Tensors>]"; break; case AttributeKind::g: out << "<Graph>"; break; case AttributeKind::gs: out << "[<Graphs>]"; break; } } out << "]"; }
float TimeValue::toFloat(long n) const { return static_cast<float>(toLong(n)); }
Rational TimeValue::toRational(long n) const { return Rational(toLong(n), 1); }
/** * Scan packet buffer */ int scan(JNIEnv *env, jobject obj, jobject jpacket, scanner_t *scanner, packet_state_t *p_packet, int first_id, char *buf, int buf_len, uint32_t wirelen) { scan_t scan; // Our current in progress scan's state information scan_t *pscan = &scan; scan.env = env; scan.jscanner = obj; scan.jpacket = jpacket; scan.scanner = scanner; scan.packet = p_packet; scan.header = &p_packet->pkt_headers[0]; scan.buf = buf; scan.buf_len = buf_len; // Changing buffer length, reduced by 'postfix' scan.mem_len = buf_len; // Constant in memory buffer length scan.wire_len = wirelen; scan.offset = 0; scan.length = 0; scan.id = first_id; scan.next_id = PAYLOAD_ID; scan.flags = 0; scan.stack_index = 0; scan.hdr_count = 0; scan.hdr_flags = 0; scan.hdr_prefix = 0; scan.hdr_gap = 0; scan.hdr_payload = 0; scan.hdr_postfix = 0; memset(scan.header, 0, sizeof(header_t)); // Point jscan setJMemoryPhysical(env, scanner->sc_jscan, toLong(&scan)); // Local temp variables register uint64_t mask; #ifdef DEBUG debug_enter("scan"); debug_trace("processing packet", "#%d", p_packet->pkt_frame_num); #endif /* * Main scanner loop, 1st scans for builtin header types then * reverts to calling on JBinding objects to provide the binding chain */ while (scan.id != END_OF_HEADERS) { #ifdef DEBUG debug_trace("", ""); debug_trace("processing header", id2str(scan.id)); debug_scan("loop-top", &scan); #endif /* A flag that keeps track of header recording. Set in record_header()*/ scan.is_recorded = 0; /* * If debugging is compiled in, we can also call on each protocols * debug_* function to print out details about the protocol header * structure. */ #ifdef DEBUG if (native_debug[scan.id]) { native_debug[scan.id](scan.buf + scan.offset); } #endif /* * Scan of each protocol is done through a dispatch function table. * Each protocol that has a protocol header scanner attached, a scanner * designed specifically for that protocol. The protocol id is also the * index into the table. There are 2 types of scanners both have exactly * the same signature and thus both are set in this table. The first is * the native scanner that only performs a direct scan of the header. * The second scanner is a java header scanner. It is based on * JHeaderScanner class. A single dispatch method callJavaHeaderScanner * uses the protocol ID to to dispatch to the appropriate java scanner. * Uses a separate java specific table: sc_java_header_scanners[]. The * java scanner is capable of calling the native scan method from java * but also adds the ability to check all the attached JBinding[] for * any additional registered bindings. Interesting fact is that if the * java scanner doesn't have any bindings nor does it override the * default scan method to perform a scan in java and is also setup to * dispatch to native scanner, it is exactly same thing as if the * native scanner was dispatched directly from here, but round * about way through java land. */ if (scanner->sc_scan_table[scan.id] != NULL) { scanner->sc_scan_table[scan.id](&scan); // Dispatch to scanner } #ifdef DEBUG debug_scan("loop-middle", &scan); #endif if (scan.length == 0) { #ifdef DEBUG debug_scan("loop-length==0", &scan); #endif if (scan.id == PAYLOAD_ID) { if (scan.stack_index == 0) { scan.next_id = END_OF_HEADERS; } else { scan.stack_index --; scan.next_id = scan.stack[scan.stack_index].next_id; scan.offset = scan.stack[scan.stack_index].offset; } } else { scan.next_id = PAYLOAD_ID; } } else { // length != 0 #ifdef DEBUG debug_scan("loop-length > 0", &scan); #endif /****************************************************** * **************************************************** * * If override flag is set, then we reset the * * discovered next protocol. If that is what the user * * wants then that is what he gets. * **************************************************** ******************************************************/ if (scanner->sc_flags[scan.id] & FLAG_OVERRIDE_BINDING) { #ifdef DEBUG debug_scan("TCP OVERRIDE", &scan); #endif scan.next_id = PAYLOAD_ID; } /****************************************************** * **************************************************** * * Now do HEURISTIC discovery scans if the appropriate * * flags are set. Heuristics allow us to provide nxt * * protocol binding, using discovery (an educated * * guess). * **************************************************** ******************************************************/ if (scanner->sc_flags[scan.id] & FLAG_HEURISTIC_BINDING) { /* * Save these critical properties, in case heuristic changes them * for this current header, not the next one its supposed to * check for. */ int saved_offset = scan.offset; int saved_length = scan.length; /* Advance offset to next header, so that heuristics can get a * peek. It will be restored at the end of heuristics block. */ scan.offset += scan.length + scan.hdr_gap; /* * 2 types of heuristic bindings. Pre and post. * Pre - heuristics are run before the direct discovery method * in scanner. Only after the pre-heuristic fail do we * utilize the directly discovered binding. * * Post - heuristics are run after the direct discovery method * didn't produce a binding. * * ------------------------------------------------------------ * * In our case, since we have already ran the direct discovery * in the header scanner, we save scan.next_id value, reset it, * call the heuristic function, check its scan.next_id if it * was set, if it was, then use that instead. Otherwise if it * wasn't restore the original next_id and continue on normally. */ if (scanner->sc_flags[scan.id] & FLAG_HEURISTIC_PRE_BINDING) { #ifdef DEBUG debug_scan("heurists_pre", &scan); #endif int saved_next_id = scan.next_id; scan.next_id = PAYLOAD_ID; for (int i = 0; i < MAX_ID_COUNT; i++) { native_validate_func_t validate_func; validate_func = scanner->sc_heuristics_table[scan.id][i]; if (validate_func == NULL) { break; } if ((scan.next_id = validate_func(&scan)) != INVALID) { break; } } if (scan.next_id == PAYLOAD_ID) { scan.next_id = saved_next_id; } } else if (scan.next_id == PAYLOAD_ID) { #ifdef DEBUG debug_scan("heurists_post", &scan); #endif for (int i = 0; i < MAX_ID_COUNT; i++) { native_validate_func_t validate_func; validate_func = scanner->sc_heuristics_table[scan.id][i]; if (validate_func == NULL) { break; } #ifdef DEBUG debug_trace("heurists_post", "[%d]", i); #endif if ((scan.next_id = validate_func(&scan)) != INVALID) { #ifdef DEBUG debug_scan("heurists_post::found", &scan); #endif break; } } } /* Restore these 2 critical properties */ scan.offset = saved_offset; scan.length = saved_length; } /****************************************************** * **************************************************** * * Now record discovered information in structures * **************************************************** ******************************************************/ record_header(&scan); #ifdef DEBUG debug_header("header_t", scan.header - 1); #endif } // End if len != 0 #ifdef DEBUG debug_scan("loop-bottom", &scan); #endif scan.id = scan.next_id; scan.offset += scan.length + scan.hdr_gap; scan.length = 0; scan.next_id = PAYLOAD_ID; if (scan.offset >= scan.buf_len) { scan.id = END_OF_HEADERS; } } // End for loop /* record number of header entries found */ // scan.packet->pkt_header_count = count; process_flow_key(&scan); #ifdef DEBUG debug_trace("loop-finished", "header_count=%d offset=%d header_map=0x%X", scan.packet->pkt_header_count, scan.offset, scan.packet->pkt_header_map); debug_exit("scan()"); #endif return scan.offset; } // End scan()
int Q3CString::toInt(bool *ok) const { return (int)toLong(ok); }
//-------------------------------------------------------------------------------- int main(int argc, const char * argv[]) { // We handle options early because the later code may // depend on them (-verbose, -testing, -help, --file) SFString cmdFile=EMPTY; for (int i=0;i<argc;i++) { SFString arg = argv[i]; if (arg.startsWith("--file:")) { cmdFile = arg.Substitute("--file:",EMPTY); cmdFile.Replace("~/",getHomeFolder()); if (!SFos::fileExists(cmdFile)) return usage("--file: '" + cmdFile + "' not found. Quitting."); } else if (arg == "-h" || arg == "-help" || arg == "--help") { return usage(); } else if (arg.startsWith("-v") || arg.startsWith("-verbose")) { verbose = TRUE; arg.Replace("-verbose",EMPTY); arg.Replace("-v", EMPTY); arg.Replace(":", EMPTY); if (!arg.IsEmpty()) verbose = toLong(arg); } else if (arg=="-t" || arg=="-test" || arg=="-titles") { // During testing, we send all output (including error messages) // to the screen so it can be re-directed to a file outErr = outScreen; isTesting = TRUE; } } // If we have a command file, we will use it, if not we will create // one and pretend we had one. This makes the processing code easier. SFString commandList; if (cmdFile.IsEmpty()) { for (int i=1;i<argc;i++) // we know the program's name commandList += (SFString(argv[i]) + " "); commandList += '\n'; } else { commandList = asciiFileToString(cmdFile).Substitute("\t", " ").Substitute(" ", " "); } // We keep only a single slurper. If the user is using the --file option and they // are reading the same account repeatedly, we only need to read the cache once. CSlurperApp slurper; // For each command we first parse the options (expanding them if neceassary), then setup // the sluper, then read from either cache or the blockchain, then display the results. while (!commandList.IsEmpty()) { SFString command = StripAny(nextTokenClear(commandList, '\n'),"\t\r\n "); if (!command.IsEmpty() && !command.startsWith(";")) // ignore comments { outErr << "Processing: " << command << "\n"; SFInt32 nArgs=0; SFString args[40]; // safe enough while (!command.IsEmpty()) { SFString arg = nextTokenClear(command, ' '); while (!arg.IsEmpty()) args[nArgs++] = expandOption(arg); // handles case of -rf for example } SFString message; // Parse the command line COptions options; options.cmdFile=!cmdFile.IsEmpty(); if (!options.parseArguments(nArgs, args)) return FALSE; // Setup the slurper if (!slurper.Initialize(options, message)) return usage(message); // Slurp the address... if (!slurper.Slurp(options, message)) return usage(message); // Apply the filters if any... if (!slurper.Filter(options, message)) return usage(message); // Report on the address... if (!slurper.Display(options, message)) return usage(message); } } return FALSE; }
/* * Function: setPcapDumper * Description: store the peering structure point within the PcapDumper object. * Can be later retrieved using getPcapDumper function. */ void setPcapDumper(JNIEnv *env, jobject obj, pcap_dumper_t *dumper) { jlong physical = toLong(dumper); env->SetLongField(obj, pcapDumperPhysicalFID, physical); }
void HTTPResourceRequest::onRequestFinished() { Q_ASSERT(_state == InProgress); Q_ASSERT(_reply); cleanupTimer(); // Content-Range headers have the form: // // Content-Range: <unit> <range-start>-<range-end>/<size> // Content-Range: <unit> <range-start>-<range-end>/* // Content-Range: <unit> */<size> // auto parseContentRangeHeader = [](QString contentRangeHeader) -> std::pair<bool, uint64_t> { auto unitRangeParts = contentRangeHeader.split(' '); if (unitRangeParts.size() != 2) { return { false, 0 }; } auto rangeSizeParts = unitRangeParts[1].split('/'); if (rangeSizeParts.size() != 2) { return { false, 0 }; } auto sizeStr = rangeSizeParts[1]; if (sizeStr == "*") { return { true, 0 }; } else { bool ok; auto size = sizeStr.toLong(&ok); return { ok, size }; } }; switch(_reply->error()) { case QNetworkReply::NoError: _data = _reply->readAll(); _loadedFromCache = _reply->attribute(QNetworkRequest::SourceIsFromCacheAttribute).toBool(); _result = Success; if (_byteRange.isSet()) { auto statusCode = _reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); if (statusCode == 206) { _rangeRequestSuccessful = true; auto contentRangeHeader = _reply->rawHeader("Content-Range"); bool success; uint64_t size; std::tie(success, size) = parseContentRangeHeader(contentRangeHeader); if (success) { _totalSizeOfResource = size; } else { qWarning(networking) << "Error parsing content-range header: " << contentRangeHeader; _totalSizeOfResource = 0; } } else { _rangeRequestSuccessful = false; _totalSizeOfResource = _data.size(); } } recordBytesDownloadedInStats(STAT_HTTP_RESOURCE_TOTAL_BYTES, _data.size()); break; case QNetworkReply::TimeoutError: _result = Timeout; break; case QNetworkReply::ContentNotFoundError: // Script.include('https://httpbin.org/status/404') _result = NotFound; break; case QNetworkReply::ProtocolInvalidOperationError: // Script.include('https://httpbin.org/status/400') _result = InvalidURL; break; case QNetworkReply::UnknownContentError: // Script.include('QUrl("https://httpbin.org/status/402")') case QNetworkReply::ContentOperationNotPermittedError: //Script.include('https://httpbin.org/status/403') case QNetworkReply::AuthenticationRequiredError: // Script.include('https://httpbin.org/basic-auth/user/passwd') _result = AccessDenied; break; case QNetworkReply::RemoteHostClosedError: // Script.include('http://127.0.0.1:22') case QNetworkReply::ConnectionRefusedError: // Script.include(http://127.0.0.1:1') case QNetworkReply::HostNotFoundError: // Script.include('http://foo.bar.highfidelity.io') case QNetworkReply::ServiceUnavailableError: // Script.include('QUrl("https://httpbin.org/status/503")') _result = ServerUnavailable; break; case QNetworkReply::UnknownServerError: // Script.include('QUrl("https://httpbin.org/status/504")') case QNetworkReply::InternalServerError: // Script.include('QUrl("https://httpbin.org/status/500")') default: qCDebug(networking) << "HTTPResourceRequest error:" << QMetaEnum::fromType<QNetworkReply::NetworkError>().valueToKey(_reply->error()); _result = Error; break; } _reply->disconnect(this); _reply->deleteLater(); _reply = nullptr; _state = Finished; emit finished(); auto statTracker = DependencyManager::get<StatTracker>(); if (_result == Success) { statTracker->incrementStat(STAT_HTTP_REQUEST_SUCCESS); if (loadedFromCache()) { statTracker->incrementStat(STAT_HTTP_REQUEST_CACHE); } } else { statTracker->incrementStat(STAT_HTTP_REQUEST_FAILED); } }
ArbitraryInteger ArbitraryInteger::operator -=(long v){ cout << "-= long value " << toLong() << " same as "; resize(sizeof(long)); cout << toLong() << endl; }
long long popLong(){ unsigned int al,ah; al=pop(); ah=pop(); return toLong(ah,al); }