#include #include #include #include #include using namespace std; map m; bool get_input(); int main() { cout << "Content-type: text/html\n\n" << "\n" << "\n" << "\n" << "Magnolia BBQ\n" << "\n" << "\n" << "\n" << "

Magnolia BBQ Yummy Bowl

\n\n"; if (get_input()) { string base {""}; string protein{""}; string veggies{""}; string sauce {""}; string topping{""}; auto it {m.find("base")}; if (it == end(m)) { cout << "Could not get base"; } else { base = it->second; } it = m.find("protein"); if (it == end(m)) { cout << "Could not get protein"; } else { protein = it->second; } it = m.find("veggies"); if (it == end(m)) { cout << "Could not get veggies"; } else { veggies = it->second; } it = m.find("sauce"); if (it == end(m)) { cout << "Could not get sauce"; } else { sauce = it->second; } it = m.find("topping"); if (it == end(m)) { cout << "Could not get topping"; } else { topping = it->second; } cout << "

\n" << "Your Magnolia BBQ Yummy Bowl includes:\n" << "
\n" << "Base: " << base << "\n" << "
\n" << "Protein: " << protein << "\n" << "
\n" << "Veggies: " << veggies << "\n" << "
\n" << "Sauce: " << sauce << "\n" << "
\n" << "Topping: " << topping << "\n" << "
\n" << "

\n\n"; cout << "

Enjoy your Magnolia BBQ Yummy Bowl!

\n\n"; } cout << "\n" << "\n"; return EXIT_SUCCESS; } bool get_input() { const char *const p {getenv("CONTENT_LENGTH")}; if (p == nullptr) { cout << "Environment has no CONTENT_LENGTH\n"; return false; } const int content_length {stoi(p)}; string s; s.resize(content_length); cin.read(&s[0], content_length); if (!cin) { cout << "Unable to input " << content_length << " bytes.\n"; return false; } stringstream ss {s}; string line; while (getline(ss, line, '&')) { const size_t pos {line.find('=')}; if (pos != string::npos) { string key {line.substr(0, pos)}; string value {line.substr(pos + 1)}; for (char &c : value) if (c == '+') c = ' '; m[key] = value; } } return true; }