1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825
|
/** @file
A brief file description
@section license License
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#pragma once
#include "tscore/Arena.h"
#include "HdrToken.h"
#include "HdrHeap.h"
#include "tscore/CryptoHash.h"
#include "MIME.h"
#include <string_view>
#include "tscore/ink_apidefs.h"
typedef int64_t cache_generation_t;
enum URLType {
URL_TYPE_NONE,
URL_TYPE_HTTP,
URL_TYPE_HTTPS,
};
class URLImpl : public HdrHeapObjImpl
{
public:
// HdrHeapObjImpl is 4 bytes
uint16_t m_len_scheme;
uint16_t m_len_user;
uint16_t m_len_password;
uint16_t m_len_host;
uint16_t m_len_port;
uint16_t m_len_path;
uint16_t m_len_params;
uint16_t m_len_query;
uint16_t m_len_fragment;
uint16_t m_len_printed_string;
// 4 + 20 byte = 24, 8 bytes aligned
const char *m_ptr_scheme;
const char *m_ptr_user;
const char *m_ptr_password;
const char *m_ptr_host;
const char *m_ptr_port;
const char *m_ptr_path;
const char *m_ptr_params;
const char *m_ptr_query;
const char *m_ptr_fragment;
const char *m_ptr_printed_string;
// pointer aligned (4 or 8)
// Tokenized values
int16_t m_scheme_wks_idx;
uint16_t m_port;
uint8_t m_url_type; // e.g. HTTP
uint8_t m_type_code; // RFC 1738 limits type code to 1 char
// 6 bytes
uint32_t m_clean : 1;
/// Whether the URI had an absolutely empty path, not even an initial '/'.
uint32_t m_path_is_empty : 1;
uint32_t m_normalization_flags : 2; // Only valid if both m_clean and m_ptr_printed_sting are non-zero.
// 8 bytes + 4 bits, will result in padding
// Accessors
const char *get_scheme(int *length);
const char *set_scheme(HdrHeap *heap, const char *value, int value_wks_idx, int length, bool copy_string);
const char *get_user(int *length);
void set_user(HdrHeap *heap, const char *value, int length, bool copy_string);
const char *get_password(int *length);
void set_password(HdrHeap *heap, const char *value, int length, bool copy_string);
const char *get_host(int *length);
void set_host(HdrHeap *heap, const char *value, int length, bool copy_string);
int get_port();
void set_port(HdrHeap *heap, unsigned int port);
void set_port(HdrHeap *heap, const char *value, int length, bool copy_string);
const char *get_path(int *length);
void set_path(HdrHeap *heap, const char *value, int length, bool copy_string);
int get_type();
void set_type(int type);
int get_type_code();
void set_type_code(unsigned int typecode);
const char *get_params(int *length);
void set_params(HdrHeap *heap, const char *value, int length, bool copy_string);
const char *get_query(int *length);
void set_query(HdrHeap *heap, const char *value, int length, bool copy_string);
const char *get_fragment(int *length);
void set_fragment(HdrHeap *heap, const char *value, int length, bool copy_string);
// Marshaling Functions
int marshal(MarshalXlate *str_xlate, int num_xlate);
void unmarshal(intptr_t offset);
void move_strings(HdrStrHeap *new_heap);
void rehome_strings(HdrHeap *new_heap);
size_t strings_length();
// Sanity Check Functions
void check_strings(HeapCheck *heaps, int num_heaps);
private:
};
using URLHashContext = CryptoContext;
extern const char *URL_SCHEME_FILE;
extern const char *URL_SCHEME_FTP;
extern const char *URL_SCHEME_GOPHER;
extern const char *URL_SCHEME_HTTP;
extern const char *URL_SCHEME_HTTPS;
extern const char *URL_SCHEME_WS;
extern const char *URL_SCHEME_WSS;
extern const char *URL_SCHEME_MAILTO;
extern const char *URL_SCHEME_NEWS;
extern const char *URL_SCHEME_NNTP;
extern const char *URL_SCHEME_PROSPERO;
extern const char *URL_SCHEME_TELNET;
extern const char *URL_SCHEME_TUNNEL;
extern const char *URL_SCHEME_WAIS;
extern const char *URL_SCHEME_PNM;
extern const char *URL_SCHEME_RTSP;
extern const char *URL_SCHEME_RTSPU;
extern const char *URL_SCHEME_MMS;
extern const char *URL_SCHEME_MMSU;
extern const char *URL_SCHEME_MMST;
extern int URL_WKSIDX_FILE;
extern int URL_WKSIDX_FTP;
extern int URL_WKSIDX_GOPHER;
extern int URL_WKSIDX_HTTP;
extern int URL_WKSIDX_HTTPS;
extern int URL_WKSIDX_WS;
extern int URL_WKSIDX_WSS;
extern int URL_WKSIDX_MAILTO;
extern int URL_WKSIDX_NEWS;
extern int URL_WKSIDX_NNTP;
extern int URL_WKSIDX_PROSPERO;
extern int URL_WKSIDX_TELNET;
extern int URL_WKSIDX_TUNNEL;
extern int URL_WKSIDX_WAIS;
extern int URL_WKSIDX_PNM;
extern int URL_WKSIDX_RTSP;
extern int URL_WKSIDX_RTSPU;
extern int URL_WKSIDX_MMS;
extern int URL_WKSIDX_MMSU;
extern int URL_WKSIDX_MMST;
extern int URL_LEN_FILE;
extern int URL_LEN_FTP;
extern int URL_LEN_GOPHER;
extern int URL_LEN_HTTP;
extern int URL_LEN_HTTPS;
extern int URL_LEN_WS;
extern int URL_LEN_WSS;
extern int URL_LEN_MAILTO;
extern int URL_LEN_NEWS;
extern int URL_LEN_NNTP;
extern int URL_LEN_PROSPERO;
extern int URL_LEN_TELNET;
extern int URL_LEN_TUNNEL;
extern int URL_LEN_WAIS;
extern int URL_LEN_PNM;
extern int URL_LEN_RTSP;
extern int URL_LEN_RTSPU;
extern int URL_LEN_MMS;
extern int URL_LEN_MMSU;
extern int URL_LEN_MMST;
/* Public */
bool validate_host_name(std::string_view addr);
bool validate_scheme(std::string_view scheme);
void url_init();
URLImpl *url_create(HdrHeap *heap);
void url_clear(URLImpl *url_impl);
void url_nuke_proxy_stuff(URLImpl *d_url);
URLImpl *url_copy(URLImpl *s_url, HdrHeap *s_heap, HdrHeap *d_heap, bool inherit_strs = true);
void url_copy_onto(URLImpl *s_url, HdrHeap *s_heap, URLImpl *d_url, HdrHeap *d_heap, bool inherit_strs = true);
// Normalization flag masks.
namespace URLNormalize
{
unsigned const NONE = 0;
unsigned const IMPLIED_SCHEME = 1; // If scheme missing, add scheme implied by URL type.
unsigned const LC_SCHEME_HOST = 2; // Force scheme and host to lower case if necessary.
}; // namespace URLNormalize
int url_print(URLImpl *u, char *buf, int bufsize, int *bufindex, int *dumpoffset,
unsigned normalization_flags = URLNormalize::NONE);
void url_describe(HdrHeapObjImpl *raw, bool recurse);
int url_length_get(URLImpl *url, unsigned normalization_flags = URLNormalize::NONE);
char *url_string_get(URLImpl *url, Arena *arena, int *length, HdrHeap *heap);
void url_clear_string_ref(URLImpl *url);
char *url_string_get_ref(HdrHeap *heap, URLImpl *url, int *length, unsigned normalization_flags = URLNormalize::NONE);
void url_called_set(URLImpl *url);
char *url_string_get_buf(URLImpl *url, char *dstbuf, int dstbuf_size, int *length);
void url_CryptoHash_get(const URLImpl *url, CryptoHash *hash, cache_generation_t generation = -1);
void url_host_CryptoHash_get(URLImpl *url, CryptoHash *hash);
constexpr bool USE_STRICT_URI_PARSING = true;
ParseResult url_parse(HdrHeap *heap, URLImpl *url, const char **start, const char *end, bool copy_strings,
int strict_uri_parsing = false, bool verify_host_characters = true);
constexpr bool COPY_STRINGS = true;
ParseResult url_parse_regex(HdrHeap *heap, URLImpl *url, const char **start, const char *end, bool copy_strings);
ParseResult url_parse_internet(HdrHeap *heap, URLImpl *url, const char **start, const char *end, bool copy_strings,
bool verify_host_characters);
ParseResult url_parse_http(HdrHeap *heap, URLImpl *url, const char **start, const char *end, bool copy_strings,
bool verify_host_characters);
ParseResult url_parse_http_regex(HdrHeap *heap, URLImpl *url, const char **start, const char *end, bool copy_strings);
char *url_unescapify(Arena *arena, const char *str, int length);
void unescape_str(char *&buf, char *buf_e, const char *&str, const char *str_e, int &state);
void unescape_str_tolower(char *&buf, char *end, const char *&str, const char *str_e, int &state);
inline int
url_canonicalize_port(int type, int port)
{
if (port == 0) {
if (type == URL_TYPE_HTTP)
port = 80;
else if (type == URL_TYPE_HTTPS)
port = 443;
}
return (port);
}
class URL : public HdrHeapSDKHandle
{
public:
URLImpl *m_url_impl = nullptr;
URL();
~URL();
int valid() const;
void create(HdrHeap *h);
void copy(const URL *url);
void copy_shallow(const URL *url);
void clear();
void reset();
// Note that URL::destroy() is inherited from HdrHeapSDKHandle.
void nuke_proxy_stuff();
int print(char *buf, int bufsize, int *bufindex, int *dumpoffset, unsigned normalization_flags = URLNormalize::NONE) const;
int length_get(unsigned normalization_flags = URLNormalize::NONE) const;
void clear_string_ref();
char *string_get(Arena *arena, int *length = nullptr) const;
char *string_get_ref(int *length = nullptr, unsigned normalization_flags = URLNormalize::NONE) const;
char *string_get_buf(char *dstbuf, int dsbuf_size, int *length = nullptr) const;
void hash_get(CryptoHash *hash, cache_generation_t generation = -1) const;
void host_hash_get(CryptoHash *hash) const;
const char *scheme_get(int *length);
const std::string_view scheme_get();
int scheme_get_wksidx() const;
void scheme_set(const char *value, int length);
const char *user_get(int *length);
void user_set(const char *value, int length);
const char *password_get(int *length);
void password_set(const char *value, int length);
const char *host_get(int *length);
void host_set(const char *value, int length);
int port_get() const;
int port_get_raw() const;
void port_set(int port);
const char *path_get(int *length);
void path_set(const char *value, int length);
int type_code_get();
void type_code_set(int type);
const char *params_get(int *length);
void params_set(const char *value, int length);
const char *query_get(int *length);
void query_set(const char *value, int length);
const char *fragment_get(int *length);
void fragment_set(const char *value, int length);
/**
* Parse the given URL string and populate URL state with the parts.
*
* @param[in] url The URL to parse.
*
* @return PARSE_RESULT_DONE if parsing was successful, PARSE_RESULT_ERROR
* otherwise.
*/
ParseResult parse(std::string_view url);
/** Same as parse() but do not verify that the host has proper FQDN
* characters.
*
* This is useful for RemapConfig To targets which have "$[0-9]" references
* in their host names which will later be substituted for other text.
*/
ParseResult parse_no_host_check(std::string_view url);
ParseResult parse(const char **start, const char *end);
ParseResult parse(const char *str, int length);
/** Perform more simplified parsing that is resilient to receiving regular
* expressions.
*
* This simply looks for the first '/' in a URL and considers that the end of
* the authority and the beginning of the rest of the URL. This allows for
* the '?' character in an authority as a part of a regex without it being
* considered a query parameter and, thus, avoids confusing the parser.
*
* This is only used in RemapConfig and may have no other uses.
*/
ParseResult parse_regex(std::string_view url);
ParseResult parse_regex(const char *str, int length);
public:
static char *unescapify(Arena *arena, const char *str, int length);
// No gratuitous copies!
URL(const URL &u) = delete;
URL &operator=(const URL &u) = delete;
private:
static constexpr bool VERIFY_HOST_CHARACTERS = true;
};
/*-------------------------------------------------------------------------
-------------------------------------------------------------------------*/
inline URL::URL() {}
/*-------------------------------------------------------------------------
-------------------------------------------------------------------------*/
inline URL::~URL() {}
/*-------------------------------------------------------------------------
-------------------------------------------------------------------------*/
inline int
URL::valid() const
{
return (m_heap && m_url_impl);
}
/*-------------------------------------------------------------------------
-------------------------------------------------------------------------*/
inline void
URL::create(HdrHeap *heap)
{
if (heap) {
m_heap = heap;
} else if (!m_heap) {
m_heap = new_HdrHeap();
}
m_url_impl = url_create(m_heap);
}
/*-------------------------------------------------------------------------
-------------------------------------------------------------------------*/
inline void
URL::copy(const URL *url)
{
ink_assert(url != nullptr && url->valid());
url_copy_onto(url->m_url_impl, url->m_heap, m_url_impl, m_heap);
}
/*-------------------------------------------------------------------------
-------------------------------------------------------------------------*/
inline void
URL::copy_shallow(const URL *url)
{
ink_assert(url->valid());
this->set(url);
m_url_impl = url->m_url_impl;
}
/*-------------------------------------------------------------------------
-------------------------------------------------------------------------*/
inline void
URL::clear()
{
m_url_impl = nullptr;
HdrHeapSDKHandle::clear();
}
inline void
URL::reset()
{
m_url_impl = nullptr;
}
/*-------------------------------------------------------------------------
-------------------------------------------------------------------------*/
inline void
URL::nuke_proxy_stuff()
{
ink_assert(valid());
url_nuke_proxy_stuff(m_url_impl);
}
/*-------------------------------------------------------------------------
-------------------------------------------------------------------------*/
inline int
URL::print(char *buf, int bufsize, int *bufindex, int *dumpoffset, unsigned normalization_flags) const
{
ink_assert(valid());
return url_print(m_url_impl, buf, bufsize, bufindex, dumpoffset, normalization_flags);
}
/*-------------------------------------------------------------------------
-------------------------------------------------------------------------*/
inline int
URL::length_get(unsigned normalization_flags) const
{
ink_assert(valid());
return url_length_get(m_url_impl, normalization_flags);
}
/*-------------------------------------------------------------------------
-------------------------------------------------------------------------*/
inline char *
URL::string_get(Arena *arena_or_null_for_malloc, int *length) const
{
ink_assert(valid());
return url_string_get(m_url_impl, arena_or_null_for_malloc, length, m_heap);
}
inline char *
URL::string_get_ref(int *length, unsigned normalization_flags) const
{
ink_assert(valid());
return url_string_get_ref(m_heap, m_url_impl, length, normalization_flags);
}
inline void
URL::clear_string_ref()
{
ink_assert(valid());
url_clear_string_ref(m_url_impl);
return;
}
/*-------------------------------------------------------------------------
-------------------------------------------------------------------------*/
inline char *
URL::string_get_buf(char *dstbuf, int dsbuf_size, int *length) const
{
ink_assert(valid());
return url_string_get_buf(m_url_impl, dstbuf, dsbuf_size, length);
}
/*-------------------------------------------------------------------------
-------------------------------------------------------------------------*/
inline void
URL::hash_get(CryptoHash *hash, cache_generation_t generation) const
{
ink_assert(valid());
url_CryptoHash_get(m_url_impl, hash, generation);
}
/*-------------------------------------------------------------------------
-------------------------------------------------------------------------*/
inline void
URL::host_hash_get(CryptoHash *hash) const
{
ink_assert(valid());
url_host_CryptoHash_get(m_url_impl, hash);
}
/*-------------------------------------------------------------------------
-------------------------------------------------------------------------*/
inline const std::string_view
URL::scheme_get()
{
ink_assert(valid());
int length;
const char *scheme = m_url_impl->get_scheme(&length);
return std::string_view{scheme, static_cast<size_t>(length)};
}
inline const char *
URL::scheme_get(int *length)
{
std::string_view ret = this->scheme_get();
*length = ret.size();
return ret.data();
}
inline int
URL::scheme_get_wksidx() const
{
ink_assert(valid());
return (m_url_impl->m_scheme_wks_idx);
}
/*-------------------------------------------------------------------------
-------------------------------------------------------------------------*/
inline void
URL::scheme_set(const char *value, int length)
{
ink_assert(valid());
int scheme_wks_idx = (value ? hdrtoken_tokenize(value, length) : -1);
m_url_impl->set_scheme(m_heap, value, scheme_wks_idx, length, true);
}
/*-------------------------------------------------------------------------
-------------------------------------------------------------------------*/
inline const char *
URL::user_get(int *length)
{
ink_assert(valid());
return m_url_impl->get_user(length);
}
/*-------------------------------------------------------------------------
-------------------------------------------------------------------------*/
inline void
URL::user_set(const char *value, int length)
{
ink_assert(valid());
m_url_impl->set_user(m_heap, value, length, true);
}
/*-------------------------------------------------------------------------
-------------------------------------------------------------------------*/
inline const char *
URL::password_get(int *length)
{
ink_assert(valid());
return m_url_impl->get_password(length);
}
/*-------------------------------------------------------------------------
-------------------------------------------------------------------------*/
inline void
URL::password_set(const char *value, int length)
{
ink_assert(valid());
m_url_impl->set_password(m_heap, value, length, true);
}
/*-------------------------------------------------------------------------
-------------------------------------------------------------------------*/
inline const char *
URL::host_get(int *length)
{
ink_assert(valid());
return m_url_impl->get_host(length);
}
/*-------------------------------------------------------------------------
-------------------------------------------------------------------------*/
inline void
URL::host_set(const char *value, int length)
{
ink_assert(valid());
m_url_impl->set_host(m_heap, value, length, true);
}
/*-------------------------------------------------------------------------
-------------------------------------------------------------------------*/
inline int
URL::port_get() const
{
ink_assert(valid());
return url_canonicalize_port(m_url_impl->get_type(), m_url_impl->get_port());
}
/*-------------------------------------------------------------------------
-------------------------------------------------------------------------*/
inline int
URL::port_get_raw() const
{
ink_assert(valid());
return m_url_impl->get_port();
}
/*-------------------------------------------------------------------------
-------------------------------------------------------------------------*/
inline void
URL::port_set(int port)
{
ink_assert(valid());
m_url_impl->set_port(m_heap, port);
}
/*-------------------------------------------------------------------------
-------------------------------------------------------------------------*/
inline const char *
URL::path_get(int *length)
{
ink_assert(valid());
return m_url_impl->get_path(length);
}
/*-------------------------------------------------------------------------
-------------------------------------------------------------------------*/
inline void
URL::path_set(const char *value, int length)
{
ink_assert(valid());
m_url_impl->set_path(m_heap, value, length, true);
}
/*-------------------------------------------------------------------------
-------------------------------------------------------------------------*/
inline int
URL::type_code_get()
{
ink_assert(valid());
return m_url_impl->get_type_code();
}
/*-------------------------------------------------------------------------
-------------------------------------------------------------------------*/
inline void
URL::type_code_set(int typecode)
{
ink_assert(valid());
m_url_impl->set_type_code(typecode);
}
/*-------------------------------------------------------------------------
-------------------------------------------------------------------------*/
inline const char *
URL::params_get(int *length)
{
ink_assert(valid());
return m_url_impl->get_params(length);
}
/*-------------------------------------------------------------------------
-------------------------------------------------------------------------*/
inline void
URL::params_set(const char *value, int length)
{
ink_assert(valid());
m_url_impl->set_params(m_heap, value, length, true);
}
/*-------------------------------------------------------------------------
-------------------------------------------------------------------------*/
inline const char *
URL::query_get(int *length)
{
ink_assert(valid());
return m_url_impl->get_query(length);
}
/*-------------------------------------------------------------------------
-------------------------------------------------------------------------*/
inline void
URL::query_set(const char *value, int length)
{
ink_assert(valid());
m_url_impl->set_query(m_heap, value, length, true);
}
/*-------------------------------------------------------------------------
-------------------------------------------------------------------------*/
inline const char *
URL::fragment_get(int *length)
{
ink_assert(valid());
return m_url_impl->get_fragment(length);
}
/*-------------------------------------------------------------------------
-------------------------------------------------------------------------*/
inline void
URL::fragment_set(const char *value, int length)
{
ink_assert(valid());
m_url_impl->set_fragment(m_heap, value, length, true);
}
/**
Parser doesn't clear URL first, so if you parse over a non-clear URL,
the resulting URL may contain some of the previous data.
*/
inline ParseResult
URL::parse(std::string_view url)
{
return this->parse(url.data(), static_cast<int>(url.size()));
}
/**
Parser doesn't clear URL first, so if you parse over a non-clear URL,
the resulting URL may contain some of the previous data.
*/
inline ParseResult
URL::parse_no_host_check(std::string_view url)
{
ink_assert(valid());
const char *start = url.data();
const char *end = url.data() + url.length();
return url_parse(m_heap, m_url_impl, &start, end, COPY_STRINGS, !USE_STRICT_URI_PARSING, !VERIFY_HOST_CHARACTERS);
}
/**
Parser doesn't clear URL first, so if you parse over a non-clear URL,
the resulting URL may contain some of the previous data.
*/
inline ParseResult
URL::parse(const char **start, const char *end)
{
ink_assert(valid());
return url_parse(m_heap, m_url_impl, start, end, COPY_STRINGS);
}
/**
Parser doesn't clear URL first, so if you parse over a non-clear URL,
the resulting URL may contain some of the previous data.
*/
inline ParseResult
URL::parse(const char *str, int length)
{
ink_assert(valid());
if (length < 0)
length = (int)strlen(str);
return parse(&str, str + length);
}
/**
Parser doesn't clear URL first, so if you parse over a non-clear URL,
the resulting URL may contain some of the previous data.
*/
inline ParseResult
URL::parse_regex(std::string_view url)
{
ink_assert(valid());
const char *str = url.data();
return url_parse_regex(m_heap, m_url_impl, &str, str + url.length(), COPY_STRINGS);
}
/**
Parser doesn't clear URL first, so if you parse over a non-clear URL,
the resulting URL may contain some of the previous data.
*/
inline ParseResult
URL::parse_regex(const char *str, int length)
{
ink_assert(valid());
if (length < 0)
length = (int)strlen(str);
ink_assert(valid());
return url_parse_regex(m_heap, m_url_impl, &str, str + length, COPY_STRINGS);
}
/*-------------------------------------------------------------------------
-------------------------------------------------------------------------*/
inline char *
URL::unescapify(Arena *arena, const char *str, int length)
{
return url_unescapify(arena, str, length);
}
|