Inserts arg mapping in h_table with key src_host chaining the mapping of existing entries bound to src_host if necessary. */
| 878 | |
| 879 | */ |
| 880 | bool |
| 881 | UrlRewrite::TableInsert(std::unique_ptr<URLTable> &h_table, url_mapping *mapping, const char *src_host) |
| 882 | { |
| 883 | if (!h_table) { |
| 884 | h_table.reset(new URLTable); |
| 885 | } |
| 886 | char src_host_tmp_buf[1]; |
| 887 | UrlMappingPathIndex *ht_contents; |
| 888 | |
| 889 | if (!src_host) { |
| 890 | src_host = &src_host_tmp_buf[0]; |
| 891 | src_host_tmp_buf[0] = 0; |
| 892 | } |
| 893 | // Insert the new_mapping into hash table |
| 894 | if (auto it = h_table->find(src_host); it != h_table->end()) { |
| 895 | ht_contents = it->second; |
| 896 | // There is already a path index for this host |
| 897 | if (it->second == nullptr) { |
| 898 | // why should this happen? |
| 899 | Warning("Found entry cannot be null!"); |
| 900 | return false; |
| 901 | } |
| 902 | } else { |
| 903 | ht_contents = new UrlMappingPathIndex(); |
| 904 | h_table->emplace(src_host, ht_contents); |
| 905 | } |
| 906 | if (!ht_contents->Insert(mapping)) { |
| 907 | // Trie::Insert only fails due to an attempt to add a duplicate entry. |
| 908 | Warning("Could not insert new mapping: duplicated entry exists"); |
| 909 | return false; |
| 910 | } |
| 911 | return true; |
| 912 | } |
| 913 | |
| 914 | /** First looks up the hash table for "simple" mappings and then the |
| 915 | regex mappings. Only higher-ranked regex mappings are examined if |