示例#1
0
文件: server.C 项目: Safe3/workspace
		void handleStatic(staticPage* Sp) {
			Response& resp(*this->resp);
			(_staticPage=Sp)->retain();
			try {
				int bufferL = resp.buffer.length();
				if(Sp->mime.length()>0)resp.headers["Content-Type"]=Sp->mime;
				{
					char* tmps = sp.beginAdd(22);
					int l = itoa64(Sp->fileLen, tmps);
					sp.endAdd(l);
					resp.headers.insert({"Content-Length", { tmps, l }});
					StreamWriter sw(resp.buffer);
					resp.serializeHeaders(sw);
				}
				if(Sp->fileLen>=CPPSP_SENDFILE_MIN_SIZE) {
					_sendFileOffset=0;
					s.sendAll(resp.buffer.data()+bufferL,resp.buffer.length()-bufferL,
						MSG_MORE, { &handler::sendHeadersCB, this });
				} else {
					String data=Sp->data;
					iov[0]= {resp.buffer.data()+bufferL, (size_t)(resp.buffer.length()-bufferL)};
					iov[1]= {data.data(), (size_t)data.length()};
					resp.outputStream->writevAll(iov, data.length()<=0?1:2, { &handler::writevCB, this });
				}
			} catch(exception& ex) {
				Sp->release();
				server->handleError(req,resp,ex,{&handler::finalize,this});
			}
		}
示例#2
0
	String urlDecode(const char* in, int inLen, StringPool& sp) {
		//XXX: dangerous (potentially exploitable) codepath; please audit
		char* ch = sp.beginAdd(inLen); //output size will never exceed input size
		int len = doURLDecode(in, inLen, ch);
		sp.endAdd(len);
		return {ch,len};
	}
示例#3
0
		void handleStatic(staticPage* Sp) {
			Response& resp(*this->resp);
			try {
				String data=Sp->data;
				int bufferL = resp.buffer.length();
				if(Sp->mime.length()>0)resp.headers["Content-Type"]=Sp->mime;
				{
					char* tmps = sp.beginAdd(16);
					int l = itoa(data.length(), tmps);
					sp.endAdd(l);
					resp.headers.insert({"Content-Length", { tmps, l }});
					StreamWriter sw(resp.buffer);
					resp.serializeHeaders(sw);
				}
				iov[0]= {resp.buffer.data()+bufferL, (size_t)(resp.buffer.length()-bufferL)};
				iov[1]= {data.data(), (size_t)data.length()};
				resp.outputStream->writevAll(iov, 2, { &handler::writevCB, this });
			} catch(exception& ex) {
				thr.handleError(req,resp,ex,{&handler::finalize,this});
			}
		}
示例#4
0
	String combinePathChroot(String p1, String p2, StringPool& sp) {
		char* tmp = sp.beginAdd(p1.length() + p2.length());
		int l = combinePathChroot(p1.data(), p2.data(), tmp);
		sp.endAdd(l);
		return {tmp,l};
	}