]> git.proxmox.com Git - ceph.git/blame - ceph/src/seastar/src/http/matcher.cc
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / seastar / src / http / matcher.cc
CommitLineData
11fdf7f2
TL
1/*
2 * This file is open source software, licensed to you under the terms
3 * of the Apache License, Version 2.0 (the "License"). See the NOTICE file
4 * distributed with this work for additional information regarding copyright
5 * ownership. You may not use this file except in compliance with the License.
6 *
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing,
12 * software distributed under the License is distributed on an
13 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 * KIND, either express or implied. See the License for the
15 * specific language governing permissions and limitations
16 * under the License.
17 */
18/*
19 * Copyright 2015 Cloudius Systems
20 */
21
22#include <seastar/http/matcher.hh>
23
24#include <iostream>
25
26namespace seastar {
27
28namespace httpd {
29
30using namespace std;
31
32/**
33 * Search for the end of the url parameter.
34 * @param url the url to search
35 * @param ind the position in the url
36 * @param entire_path when set to true, take all the reminaing url
37 * when set to false, search for the next slash
38 * @return the position in the url of the end of the parameter
39 */
40static size_t find_end_param(const sstring& url, size_t ind, bool entire_path) {
41 size_t pos = (entire_path) ? url.length() : url.find('/', ind + 1);
42 if (pos == sstring::npos) {
43 return url.length();
44 }
45 return pos;
46}
47
48size_t param_matcher::match(const sstring& url, size_t ind, parameters& param) {
49 size_t last = find_end_param(url, ind, _entire_path);
50 if (last == ind) {
51 /*
52 * empty parameter allows only for the case of entire_path
53 */
54 if (_entire_path) {
55 param.set(_name, "");
56 return ind;
57 }
58 return sstring::npos;
59 }
60 param.set(_name, url.substr(ind, last - ind));
61 return last;
62}
63
64size_t str_matcher::match(const sstring& url, size_t ind, parameters& param) {
65 if (url.length() >= _len + ind && (url.find(_cmp, ind) == ind)
66 && (url.length() == _len + ind || url.at(_len + ind) == '/')) {
67 return _len + ind;
68 }
69 return sstring::npos;
70}
71
72}
73
74}