void HttpRequest::buildRequest(const std::string &req) { std::stringstream ss; ss << req; std::string temp; std::getline(ss, temp); request = temp; while(std::getline(ss, temp) && temp.find(":") != std::string::npos) { std::string key = temp.substr(0, temp.find_first_of(":")); std::string value = temp.substr(temp.find_first_of(" ") + 1); putHeader(key, value); } if(headers.find("Content-Length") != headers.end()) { int len = std::stoi(headers["Content-Length"]); body = req.substr(req.size()-len); } else { while(std::getline(ss, temp)) { body += temp; } } putBody(body); }
bool OutPacket::fill(unsigned char *buf, int *len) { int headerLen = 0, bodyLen=0, encryptedLen = 0; unsigned char *bodyBuf; unsigned char *encrypted; bodyBuf = (unsigned char *)malloc(MAX_PACKET_SIZE* sizeof(unsigned char)); encrypted = (unsigned char *)malloc(MAX_PACKET_SIZE * sizeof(unsigned char)); headerLen = putHead(buf); bodyLen = putBody(bodyBuf); encryptedLen = bodyLen; encryptBody(bodyBuf, bodyLen, encrypted, &encryptedLen); memcpy(buf+headerLen, encrypted, encryptedLen); buf[ headerLen + encryptedLen ] = QQ_PACKET_TAIL; (*len) = headerLen + encryptedLen + 1; if(!isUDP()) { short tmp2 = htons(*len); memcpy(buf, &tmp2, 2); } free(bodyBuf); free(encrypted); return true; }