mirror of
https://github.com/bsnes-emu/bsnes.git
synced 2025-02-24 23:22:25 +01:00
byuu says: Changelog: - added 30 new PAL games to icarus (courtesy of Mikerochip) - new version of libco no longer requires mprotect nor W|X permissions - nall: default C compiler to -std=c11 instead of -std=c99 - nall: use `-fno-strict-aliasing` during compilation - updated nall/certificates (hopefully for the last time) - updated nall/http to newer coding conventions - nall: improve handling of range() function I didn't really work on higan at all, this is mostly just a release because lots of other things have changed. The most interesting is `-fno-strict-aliasing` ... basically, it joins `-fwrapv` as being "stop the GCC developers from doing *really* evil shit that could lead to security vulnerabilities or instabilities." For the most part, it's a ~2% speed penalty for higan. Except for the Sega Genesis, where it's a ~10% speedup. I have no idea how that's possible, but clearly something's going very wrong with strict aliasing on the Genesis core. So ... it is what it is. If you need the performance for the non-Genesis cores, you can turn it off in your builds. But I'm getting quite sick of C++'s "surprises" and clever compiler developers, so I'm keeping it on in all of my software going forward.
100 lines
2.7 KiB
C++
100 lines
2.7 KiB
C++
#pragma once
|
|
|
|
//httpMessage: base class for httpRequest and httpResponse
|
|
//provides shared functionality
|
|
|
|
namespace nall { namespace HTTP {
|
|
|
|
struct Variable {
|
|
string name;
|
|
string value;
|
|
};
|
|
|
|
struct SharedVariable {
|
|
SharedVariable(const string& name = "", const string& value = "") : shared(new Variable{name, value}) {}
|
|
|
|
explicit operator bool() const { return (bool)shared->name; }
|
|
auto operator()() const { return shared->value; }
|
|
auto& operator=(const string& value) { shared->value = value; return *this; }
|
|
|
|
auto name() const { return shared->name; }
|
|
auto value() const { return shared->value; }
|
|
|
|
auto& setName(const string& name) { shared->name = name; return *this; }
|
|
auto& setValue(const string& value = "") { shared->value = value; return *this; }
|
|
|
|
shared_pointer<Variable> shared;
|
|
};
|
|
|
|
struct Variables {
|
|
auto operator[](const string& name) const -> SharedVariable {
|
|
for(auto& variable : variables) {
|
|
if(variable.shared->name.iequals(name)) return variable;
|
|
}
|
|
return {};
|
|
}
|
|
|
|
auto operator()(const string& name) -> SharedVariable {
|
|
for(auto& variable : variables) {
|
|
if(variable.shared->name.iequals(name)) return variable;
|
|
}
|
|
return append(name);
|
|
}
|
|
|
|
auto find(const string& name) const -> vector<SharedVariable> {
|
|
vector<SharedVariable> result;
|
|
for(auto& variable : variables) {
|
|
if(variable.shared->name.iequals(name)) result.append(variable);
|
|
}
|
|
return result;
|
|
}
|
|
|
|
auto assign(const string& name, const string& value = "") -> SharedVariable {
|
|
for(auto& variable : variables) {
|
|
if(variable.shared->name.iequals(name)) {
|
|
variable.shared->value = value;
|
|
return variable;
|
|
}
|
|
}
|
|
return append(name, value);
|
|
}
|
|
|
|
auto append(const string& name, const string& value = "") -> SharedVariable {
|
|
SharedVariable variable{name, value};
|
|
variables.append(variable);
|
|
return variable;
|
|
}
|
|
|
|
auto remove(const string& name) -> void {
|
|
for(auto n : rrange(variables)) {
|
|
if(variables[n].shared->name.iequals(name)) variables.remove(n);
|
|
}
|
|
}
|
|
|
|
auto size() const { return variables.size(); }
|
|
auto begin() const { return variables.begin(); }
|
|
auto end() const { return variables.end(); }
|
|
auto begin() { return variables.begin(); }
|
|
auto end() { return variables.end(); }
|
|
|
|
vector<SharedVariable> variables;
|
|
};
|
|
|
|
struct Message {
|
|
using type = Message;
|
|
|
|
virtual auto head(const function<bool (const uint8_t* data, uint size)>& callback) const -> bool = 0;
|
|
virtual auto setHead() -> bool = 0;
|
|
|
|
virtual auto body(const function<bool (const uint8_t* data, uint size)>& callback) const -> bool = 0;
|
|
virtual auto setBody() -> bool = 0;
|
|
|
|
Variables header;
|
|
|
|
//private:
|
|
string _head;
|
|
string _body;
|
|
};
|
|
|
|
}}
|