void Writer::operator() (const string_ref &s) { if (need_indent) { need_indent = 0; write_indent(); } append (s.begin(), s.length()); }
inline size_t find_char(const string_ref& s, char c) { const char *b = s.begin(); const char *e = s.end(); const char *const p = memchr_char(b, c, e - b); return p ? (p - b) : (e - b); }
string_ref next() const { const int pos = src_.substr(pos_).find_first_of(sep_); const int old_pos = pos_; if (pos != -1) pos_ += pos + 1; else finished_ = true; return src_.substr(old_pos, pos); }
void id_value(string_ref value) { if (id_placeholder* p = state.get_placeholder(value)) { assert(!use_resolved_ids || p->check_state(id_placeholder::generated)); std::string const& id = use_resolved_ids ? p->id : p->unresolved_id; result.append(source_pos, value.begin()); result.append(id.begin(), id.end()); source_pos = value.end(); } }
void consensus::create( const string_ref cached_consensus_path, bool force_download ) { string consensus_content; bool have_valid_consensus = false; // // if no path to the cached consensus file // was provided, we have to download it. // if (cached_consensus_path.is_empty() || !io::file::exists(cached_consensus_path)) { force_download = true; } while (!have_valid_consensus) { consensus_content = force_download ? download_from_random_authority("/tor/status-vote/current/consensus") : io::file::read_to_string(cached_consensus_path); parse_consensus(consensus_content); have_valid_consensus = _valid_until >= time::now(); // // if the consensus is invalid, we have to download it anyway. // if (!have_valid_consensus) { force_download = true; } } // // save the consensus content, if the path was provided. // if (force_download && !cached_consensus_path.is_empty()) { io::file::write_from_string(cached_consensus_path, consensus_content); } }
void conn_info::append_escaped(const string_ref& rng, std::string& dst) { for(string_ref::difference_type i=0; i < rng.size(); ++i) { if(rng[i]=='\\') dst+="\\\\"; else if(rng[i]=='\'') dst+="\\\'"; else dst+=rng[i]; } }
int smtp_client::detail::read_response(buffered_file& conn, string_ref& resp_r, posix_error_callback& ec) { ssize_t len = 0; char *line = 0; while (true) { len = conn.read_line_crlf(line, ec); if (len <= 0) { resp_r.reset(); break; } DBG_SMTP(std::cout << "R: " << std::string(line, len)); if (len <= 5 || line[3] == ' ') { resp_r.set(line, len); return response_code(line, len); } } return len; /* <= 0 (unexpected eof or error) */ }
string consensus::download_from_random_authority( const string_ref path ) { net::ip_address ip; uint16_t port; auto authority = default_authority_list[ 3 // mini::crypto::random_device->get_random(default_authority_list.get_size()) ]; ip = authority.ip; port = authority.dir_port; mini_debug( "consensus::download_from_random_authority() [path: http://%s:%u%s]", ip.to_string().get_buffer(), port, path.get_buffer()); return net::http::client::get(ip.to_string(), port, path); }
size_t operator()(string_ref const& sr) const { return boost::hash_range(sr.begin(), sr.end()); }
void finish(string_ref xml) { result.append(source_pos, xml.end()); source_pos = xml.end(); }
inline void swap(string_ref& x, string_ref& y) { x.swap(y); }
inline bool operator !=(const string_ref& x, const string_ref& y) { return (x.size() != y.size()) || (::memcmp(x.begin(), y.begin(), x.size()) != 0); }
void hstcpcli::request_buf_exec_generic(size_t pst_id, const string_ref& op, const string_ref *kvs, size_t kvslen, uint32_t limit, uint32_t skip, const string_ref& mod_op, const string_ref *mvs, size_t mvslen, const hstcpcli_filter *fils, size_t filslen, int invalues_keypart, const string_ref *invalues, size_t invalueslen) { if (num_req_sent > 0 || num_req_rcvd > 0) { close(); set_error(-1, "request_buf_exec_generic: protocol out of sync"); return; } append_uint32(writebuf, pst_id); // FIXME size_t ? writebuf.append_literal("\t"); writebuf.append(op.begin(), op.end()); writebuf.append_literal("\t"); append_uint32(writebuf, kvslen); // FIXME size_t ? for (size_t i = 0; i < kvslen; ++i) { const string_ref& kv = kvs[i]; append_delim_value(writebuf, kv.begin(), kv.end()); } if (limit != 0 || skip != 0 || invalues_keypart >= 0 || mod_op.size() != 0 || filslen != 0) { /* has more option */ writebuf.append_literal("\t"); append_uint32(writebuf, limit); // FIXME size_t ? if (skip != 0 || invalues_keypart >= 0 || mod_op.size() != 0 || filslen != 0) { writebuf.append_literal("\t"); append_uint32(writebuf, skip); // FIXME size_t ? } if (invalues_keypart >= 0) { writebuf.append_literal("\t@\t"); append_uint32(writebuf, invalues_keypart); writebuf.append_literal("\t"); append_uint32(writebuf, invalueslen); for (size_t i = 0; i < invalueslen; ++i) { const string_ref& s = invalues[i]; append_delim_value(writebuf, s.begin(), s.end()); } } for (size_t i = 0; i < filslen; ++i) { const hstcpcli_filter& f = fils[i]; writebuf.append_literal("\t"); writebuf.append(f.filter_type.begin(), f.filter_type.end()); writebuf.append_literal("\t"); writebuf.append(f.op.begin(), f.op.end()); writebuf.append_literal("\t"); append_uint32(writebuf, f.ff_offset); append_delim_value(writebuf, f.val.begin(), f.val.end()); } if (mod_op.size() != 0) { writebuf.append_literal("\t"); writebuf.append(mod_op.begin(), mod_op.end()); for (size_t i = 0; i < mvslen; ++i) { const string_ref& mv = mvs[i]; append_delim_value(writebuf, mv.begin(), mv.end()); } } } writebuf.append_literal("\n"); ++num_req_bufd; }
string_ref rest() const { return src_.substr(pos_); }
template <size_t N> inline bool operator ==(const string_ref& x, const char (& y)[N]) { return (x.size() == N - 1) && (::memcmp(x.begin(), y, N - 1) == 0); }
inline bool operator ==(const string_ref& x, const string_ref& y) { return (x.size() == y.size()) && (::memcmp(x.begin(), y.begin(), x.size()) == 0); }
SECURITY_STATUS ssl_socket::client_handshake( PCredHandle phCreds, const string_ref server_name, CtxtHandle* phContext, SecBuffer* pExtraData ) { SecBufferDesc OutBuffer; SecBuffer OutBuffers[1]; DWORD dwSSPIFlags; DWORD dwSSPIOutFlags; TimeStamp tsExpiry; SECURITY_STATUS scRet; DWORD cbData; dwSSPIFlags = ISC_REQ_SEQUENCE_DETECT | ISC_REQ_REPLAY_DETECT | ISC_REQ_CONFIDENTIALITY | ISC_RET_EXTENDED_ERROR | ISC_REQ_ALLOCATE_MEMORY | ISC_REQ_STREAM; OutBuffers[0].pvBuffer = NULL; OutBuffers[0].BufferType = SECBUFFER_TOKEN; OutBuffers[0].cbBuffer = 0; OutBuffer.cBuffers = 1; OutBuffer.pBuffers = OutBuffers; OutBuffer.ulVersion = SECBUFFER_VERSION; scRet = g_sspi->InitializeSecurityContext( phCreds, NULL, (TCHAR*)server_name.get_buffer(), dwSSPIFlags, 0, SECURITY_NATIVE_DREP, NULL, 0, phContext, &OutBuffer, &dwSSPIOutFlags, &tsExpiry); if (scRet != SEC_I_CONTINUE_NEEDED) { return scRet; } if (OutBuffers[0].cbBuffer != 0 && OutBuffers[0].pvBuffer != NULL) { m_bAllowPlainText = TRUE; cbData = static_cast<DWORD>(write_impl(OutBuffers[0].pvBuffer, static_cast<size_t>(OutBuffers[0].cbBuffer))); m_bAllowPlainText = FALSE; if (cbData == SOCKET_ERROR || cbData == 0) { g_sspi->FreeContextBuffer(OutBuffers[0].pvBuffer); g_sspi->DeleteSecurityContext(phContext); return SEC_E_INTERNAL_ERROR; } g_sspi->FreeContextBuffer(OutBuffers[0].pvBuffer); OutBuffers[0].pvBuffer = NULL; } SECURITY_STATUS rc = client_handshake_loop(phCreds, phContext, TRUE, pExtraData); if (pExtraData->pvBuffer) { delete[] pExtraData->pvBuffer; } return rc; }
//------------------------------------------------------------------------------ void transitory_text_layout::reset( font_face& face , string_ref const string , int16_t const max_w , int16_t const max_h ) { constexpr auto tab_size = 20; clear(); //assume 2 bytes on average per codepoint. //overly pessimistic for mostly latin text data_.reserve(string.size() / 2); auto it = utf8::iterator<char const*> {cbegin(string), cbegin(string), cend(string)}; auto const end = utf8::iterator<char const*> {cend(string), cbegin(string), cend(string)}; record_t cur_record {}; format_tag cur_format {}; format_t const default_format { make_color(255, 255, 255, 255) , 0 , 0 }; int pos = 0; while (it != end) { auto cp = *it; switch (cp) { case token::escape : if (auto const result = parse_escape(it, end)) { cp = *result; } else { BK_TODO_FAIL(); continue; } break; case token::tag_open : cur_format = parse_tag(it, end); if (cur_format.type == format_tag::tag_type::tag_color) { if (cur_format.state == format_tag::tag_state::type_begin) { format_.emplace_back(format_t {make_color(255, 0, 0, 255), pos, pos}); } else if (cur_format.state == format_tag::tag_state::type_end) { format_.back().end = pos; } } else { BK_TODO_FAIL(); } continue; default : ++it; ++pos; break; } cur_record.codepoint = cp; data_.push_back(cur_record); } auto const line_gap = face.line_gap(); auto x = 0; auto y = face.ascender(); //-------------------------------------------------------------------------- auto const next_line = [&] { x = 0; y += line_gap; }; //-------------------------------------------------------------------------- auto const next_tab = [&] { auto const rem = x % tab_size; auto const tab = tab_size - rem; x += tab; }; //-------------------------------------------------------------------------- auto const do_escape = [&](codepoint_t const cp) { switch (cp) { case '\t' : next_tab(); return true; case '\n' : next_line(); return true; } return false; }; //-------------------------------------------------------------------------- auto left = unicode::codepoint {}; for (auto& rec : data_) { if (do_escape(rec.codepoint)) { continue; } auto const cp = unicode::codepoint {rec.codepoint}; auto const metrics = face.metrics(left, cp); left = cp; if ((max_w != unlimited) && x > max_w) { next_line(); } if ((max_h != unlimited) && y > max_h) { break; } auto& p = rec.position; p.x = static_cast<int16_t>(x + metrics.left); p.y = static_cast<int16_t>(y - metrics.top); actual_w_ = std::max(actual_w_, static_cast<int16_t>(p.x + metrics.width)); actual_h_ = std::max(actual_h_, static_cast<int16_t>(p.y + metrics.height)); x += metrics.advance_x; y -= metrics.advance_y; } }
void basic_url_base::parse_impl (string_ref s, boost::system::error_code& ec) { joyent::http_parser_url p; value_type const* const data (s.data()); int const error (joyent::http_parser_parse_url ( data, s.size(), false, &p)); if (error) { ec = boost::system::error_code ( boost::system::errc::invalid_argument, boost::system::generic_category()); return; } if ((p.field_set & (1<<joyent::UF_SCHEMA)) != 0) { m_scheme = string_ref ( data + p.field_data [joyent::UF_SCHEMA].off, p.field_data [joyent::UF_SCHEMA].len); } else { m_scheme = string_ref {}; } if ((p.field_set & (1<<joyent::UF_HOST)) != 0) { m_host = string_ref ( data + p.field_data [joyent::UF_HOST].off, p.field_data [joyent::UF_HOST].len); } else { m_host = string_ref {}; } if ((p.field_set & (1<<joyent::UF_PORT)) != 0) { m_port = p.port; m_port_string = string_ref ( data + p.field_data [joyent::UF_PORT].off, p.field_data [joyent::UF_PORT].len); } else { m_port = 0; m_port_string = string_ref {}; } if ((p.field_set & (1<<joyent::UF_PATH)) != 0) { m_path = string_ref ( data + p.field_data [joyent::UF_PATH].off, p.field_data [joyent::UF_PATH].len); } else { m_path = string_ref {}; } if ((p.field_set & (1<<joyent::UF_QUERY)) != 0) { m_query = string_ref ( data + p.field_data [joyent::UF_QUERY].off, p.field_data [joyent::UF_QUERY].len); } else { m_query = string_ref {}; } if ((p.field_set & (1<<joyent::UF_FRAGMENT)) != 0) { m_fragment = string_ref ( data + p.field_data [joyent::UF_FRAGMENT].off, p.field_data [joyent::UF_FRAGMENT].len); } else { m_fragment = string_ref {}; } if ((p.field_set & (1<<joyent::UF_USERINFO)) != 0) { m_userinfo = string_ref ( data + p.field_data [joyent::UF_USERINFO].off, p.field_data [joyent::UF_USERINFO].len); } else { m_userinfo = string_ref {}; } }
// Should be equal void interop ( const std::string &str, string_ref ref ) { // BOOST_CHECK ( str == ref ); BOOST_CHECK ( str.size () == ref.size ()); BOOST_CHECK ( std::equal ( str.begin (), str.end (), ref.begin ())); BOOST_CHECK ( std::equal ( str.rbegin (), str.rend (), ref.rbegin ())); }
void start(string_ref xml) { source_pos = xml.begin(); }
void syntax_highlight_actions::callout(parse_iterator, parse_iterator) { out << state.add_callout(qbk_value(state.current_file, marked_text.begin(), marked_text.end())); marked_text.clear(); }
void basic_url_base::parse_impl (string_ref s, boost::system::error_code& ec) { joyent::http_parser_url p; value_type const* const data (s.data()); int const error (joyent::http_parser_parse_url ( data, s.size(), false, &p)); if (error) { ec = boost::system::error_code ( boost::system::errc::invalid_argument, boost::system::generic_category()); return; } if ((p.field_set & (1<<joyent::uf_schema)) != 0) { m_scheme = string_ref ( data + p.field_data [joyent::uf_schema].off, p.field_data [joyent::uf_schema].len); } else { m_scheme = string_ref {}; } if ((p.field_set & (1<<joyent::uf_host)) != 0) { m_host = string_ref ( data + p.field_data [joyent::uf_host].off, p.field_data [joyent::uf_host].len); } else { m_host = string_ref {}; } if ((p.field_set & (1<<joyent::uf_port)) != 0) { m_port = p.port; m_port_string = string_ref ( data + p.field_data [joyent::uf_port].off, p.field_data [joyent::uf_port].len); } else { m_port = 0; m_port_string = string_ref {}; } if ((p.field_set & (1<<joyent::uf_path)) != 0) { m_path = string_ref ( data + p.field_data [joyent::uf_path].off, p.field_data [joyent::uf_path].len); } else { m_path = string_ref {}; } if ((p.field_set & (1<<joyent::uf_query)) != 0) { m_query = string_ref ( data + p.field_data [joyent::uf_query].off, p.field_data [joyent::uf_query].len); } else { m_query = string_ref {}; } if ((p.field_set & (1<<joyent::uf_fragment)) != 0) { m_fragment = string_ref ( data + p.field_data [joyent::uf_fragment].off, p.field_data [joyent::uf_fragment].len); } else { m_fragment = string_ref {}; } if ((p.field_set & (1<<joyent::uf_userinfo)) != 0) { m_userinfo = string_ref ( data + p.field_data [joyent::uf_userinfo].off, p.field_data [joyent::uf_userinfo].len); } else { m_userinfo = string_ref {}; } }