int main(int argc, char *argv[]) { int listenfd, connectfd; struct sockaddr_in host_addr, pin_addr; int pin_addr_size; pthread_t multiCS; ADDR_ARG *arg = NULL; createSocket(&listenfd, 0); initHostAddr(&host_addr, myport); printf(" init ipaddress: %s\n", inet_ntoa(host_addr.sin_addr)); bindPort(&listenfd, &host_addr); listenPort(&listenfd); pin_addr_size = sizeof(pin_addr); while (1) { getAccept(&listenfd, &connectfd, &pin_addr, &pin_addr_size); arg = (ADDR_ARG *)malloc(sizeof(ADDR_ARG)); arg->connectfd = connectfd; memcpy((void *)&arg->cli_addr, &pin_addr, sizeof(pin_addr)); createPthread(&multiCS, start_talk, arg); } close(listenfd); return 0; }
const char *request::operator[](const char * val) { #define op(a) (strcmp(val, a) == 0) if (op("Accept")) return getAccept(); else if (op("Accept-Charset")) return getAccept_Charset(); else if (op("Accept-Encoding")) return getAccept_Encoding(); else if (op("Accept-Language")) return getAccept_Language(); else if (op("Authorization")) return getAuthorization(); else if (op("Expect")) return getExpect(); else if (op("From")) return getFrom(); else if (op("If-Match")) return getIf_Match(); else if (op("If-Modified-Since")) return getIf_Modified_since(); else if (op("If-None-Match")) return getIf_None_Match(); else if (op("If-Range")) return getIf_Range(); else if (op("If-Unmodified-Since")) return getIf_Unmodified_Since(); else if (op("Max-Forwards")) return getMax_Forwards(); else if (op("Proxy-Authorization")) return getProxy_Authorization(); else if (op("Range")) return getRange(); else if (op("Referer")) return getReferrer(); else if (op("TE")) return getTE(); else if (op("User-Agent")) return getUser_Agent(); else if (op("URI")) return this->URI; return NULL; #undef op }
// Function: send_headers // Send HTTP headers sends all the HTTP headers down the stream. void send_headers(std::ostream& stream) const { stream << "Host: " << getHost() << "\r\n" << "User-Agent: " << getUserAgent() << "\r\n" << "Connection: close\r\n"; if(this->accept != "") { stream << getAccept(); } }