# include # include # include # include # include // getenv # define CR "\r" # define LF "\n" # define CRLF CR LF # define NPOS std::string::npos std::string trim(std::string str, char del) { size_t pos; // delete leadings del pos = str.find_first_not_of(del); if (pos == NPOS) pos = str.size(); str = str.substr(pos); // delete trailing del pos = str.find_last_not_of(del); if (pos != NPOS) str = str.substr(0, pos + 1); return str; } std::vector split(const std::string & input, std::string delim, char ctrim = '\0') { std::vector split_str; std::string tmp; size_t start = 0; size_t end = 0; size_t len = 0; while (end != NPOS) { end = input.find(delim, start); len = end - start; if (end == NPOS) len = end; tmp = input.substr(start, len); if (ctrim != '\0') tmp = trim(tmp, ctrim); if (tmp.size() != 0) split_str.push_back( tmp ); start = end + delim.size(); } return split_str; } int main (int ac, char **av, char **en) { std::vector split_str; std::vector sub_split_str; std::vector::const_iterator it; char * tmp; std::string output; std::ostringstream strs; size_t pos; std::cout << "Content-Type: text/html; charset=UTF-8" << CRLF CRLF; std::cout << "" << "" << "" << " CGI" << "" << "" << "

cgi

" << "

"; tmp = getenv("REQUEST_METHOD"); if (tmp != NULL) output = tmp; else output = "method not foud"; std::cout << output << "

" << "

http-request-body-message content :

"; std::cin >> output; split_str = split(output, "&"); output.clear(); for (it = split_str.begin(); it != split_str.end(); ++it) { sub_split_str = split(*it, "="); std::cout << "

" << sub_split_str[0] << " : " << sub_split_str[1] << "

"; } tmp = getenv("QUERY_STRING"); if (tmp == NULL) std::cout << "query not foud"; std::cout << "

http-uri-query content :

"; output = tmp; split_str = split(output, "&"); output.clear(); for (it = split_str.begin(); it != split_str.end(); ++it) { sub_split_str = split(*it, "="); std::cout << "

" << sub_split_str[0] << "

" << "

" << sub_split_str[1] << "

"; } std::cout << "" << ""; return 0; }