|
a/src/pathut.cpp |
|
b/src/pathut.cpp |
|
... |
|
... |
50 |
#include <iostream>
|
50 |
#include <iostream>
|
51 |
#include <sstream>
|
51 |
#include <sstream>
|
52 |
#include <stack>
|
52 |
#include <stack>
|
53 |
#include <set>
|
53 |
#include <set>
|
54 |
#include <vector>
|
54 |
#include <vector>
|
|
|
55 |
#include <regex>
|
55 |
|
56 |
|
56 |
#include "pathut.h"
|
57 |
#include "pathut.h"
|
57 |
#include "smallut.h"
|
58 |
#include "smallut.h"
|
58 |
|
59 |
|
59 |
using namespace std;
|
60 |
using namespace std;
|
|
... |
|
... |
759 |
bool urlisfileurl(const string& url)
|
760 |
bool urlisfileurl(const string& url)
|
760 |
{
|
761 |
{
|
761 |
return url.find("file://") == 0;
|
762 |
return url.find("file://") == 0;
|
762 |
}
|
763 |
}
|
763 |
|
764 |
|
|
|
765 |
static std::regex
|
|
|
766 |
re_uriparse("^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\\?([^#]*))?(#(.*))?",
|
|
|
767 |
std::regex::extended);
|
|
|
768 |
|
|
|
769 |
ParsedUri::ParsedUri(std::string uri)
|
|
|
770 |
{
|
|
|
771 |
std::smatch mr;
|
|
|
772 |
parsed = regex_match(uri, mr, re_uriparse);
|
|
|
773 |
if (!parsed)
|
|
|
774 |
return;
|
|
|
775 |
// cf http://www.ietf.org/rfc/rfc2396.txt
|
|
|
776 |
// scheme = $2
|
|
|
777 |
// authority = $4
|
|
|
778 |
// path = $5
|
|
|
779 |
// query = $7
|
|
|
780 |
// fragment = $9
|
|
|
781 |
if (mr[2].matched) {
|
|
|
782 |
scheme = mr[2].str();
|
|
|
783 |
}
|
|
|
784 |
if (mr[4].matched) {
|
|
|
785 |
string auth = mr[4].str();
|
|
|
786 |
// user:pass@host, user@host
|
|
|
787 |
string::size_type at = auth.find_first_of('@');
|
|
|
788 |
if (at != string::npos) {
|
|
|
789 |
host = auth.substr(at+1);
|
|
|
790 |
string::size_type colon = auth.find_first_of(':');
|
|
|
791 |
if (colon != string::npos && colon < at) {
|
|
|
792 |
user = auth.substr(0, colon);
|
|
|
793 |
pass = auth.substr(colon+1, at-colon-1);
|
|
|
794 |
} else {
|
|
|
795 |
user = auth.substr(0, at);
|
|
|
796 |
}
|
|
|
797 |
} else {
|
|
|
798 |
host.swap(auth);
|
|
|
799 |
}
|
|
|
800 |
string::size_type pc = host.find_first_of(':');
|
|
|
801 |
if (pc != string::npos) {
|
|
|
802 |
port = host.substr(pc+1);
|
|
|
803 |
host = host.substr(0, pc);
|
|
|
804 |
}
|
|
|
805 |
}
|
|
|
806 |
if (mr[5].matched) {
|
|
|
807 |
path = mr[5].str();
|
|
|
808 |
}
|
|
|
809 |
if (mr[7].matched) {
|
|
|
810 |
query = mr[7].str();
|
|
|
811 |
string::size_type pos=0, amp, eq;
|
|
|
812 |
string nm, val;
|
|
|
813 |
for (;;) {
|
|
|
814 |
nm.clear();
|
|
|
815 |
val.clear();
|
|
|
816 |
amp = query.find_first_of('&', pos);
|
|
|
817 |
//cerr << "pos " << pos << " amp " << amp << endl;
|
|
|
818 |
if (amp > pos && amp != string::npos) {
|
|
|
819 |
eq = query.find_first_of('=', pos);
|
|
|
820 |
if (eq > amp || eq == string::npos) {
|
|
|
821 |
nm = query.substr(pos, amp-pos);
|
|
|
822 |
} else {
|
|
|
823 |
nm = query.substr(pos, eq-pos);
|
|
|
824 |
val = query.substr(eq+1, amp-eq-1);
|
|
|
825 |
}
|
|
|
826 |
pos = amp + 1;
|
|
|
827 |
} else if (amp == string::npos) {
|
|
|
828 |
if (pos < query.size()-1) {
|
|
|
829 |
eq = query.find_first_of('=', pos);
|
|
|
830 |
if (eq == string::npos) {
|
|
|
831 |
nm = query.substr(pos);
|
|
|
832 |
} else {
|
|
|
833 |
nm = query.substr(pos, eq-pos);
|
|
|
834 |
val = query.substr(eq+1);
|
|
|
835 |
}
|
|
|
836 |
}
|
|
|
837 |
pos = query.size()-1;
|
|
|
838 |
} else {
|
|
|
839 |
pos++;
|
|
|
840 |
}
|
|
|
841 |
if (!nm.empty()) {
|
|
|
842 |
parsedquery.push_back(pair<string,string>(nm, val));
|
|
|
843 |
}
|
|
|
844 |
if (pos >= query.size()-1) {
|
|
|
845 |
break;
|
|
|
846 |
}
|
|
|
847 |
}
|
|
|
848 |
|
|
|
849 |
}
|
|
|
850 |
if (mr[9].matched) {
|
|
|
851 |
fragment = mr[9].str();
|
|
|
852 |
}
|
|
|
853 |
}
|
|
|
854 |
|
764 |
bool readdir(const string& dir, string& reason, set<string>& entries)
|
855 |
bool readdir(const string& dir, string& reason, set<string>& entries)
|
765 |
{
|
856 |
{
|
766 |
struct stat st;
|
857 |
struct stat st;
|
767 |
int statret;
|
858 |
int statret;
|
768 |
ostringstream msg;
|
859 |
ostringstream msg;
|