void TagPayloadByteArray::getStorageBytes(iostream& inStream){
	inStream << EndianSwapInt(length);
	for(int i = 0; i < length; i++){
		inStream << payload[i];
	}
	inStream.flush();
}
void TagPayloadCompound::getStorageBytes(iostream& inStream){
	for(vector<NBTTag>::iterator it = payload.begin(); it != payload.end(); it++) {
		it->getStorageBytes(inStream);
	}
	inStream << (unsigned char) 0; // TAG_End
	inStream.flush();
}
void TagPayloadIntArray::getStorageBytes(iostream& inStream){
	inStream << EndianSwapInt(length);
	for(int i = 0; i < length; i++){
		writeSwappedIntToStream(payload[i], inStream);
	}
	inStream.flush();
}
void TagPayloadList::getStorageBytes(iostream& inStream){
	inStream << getCharFromTag(type);
	writeSwappedIntToStream((int) payload.size(), inStream);
	for(vector<TagPayload*>::iterator it = payload.begin(); it != payload.end(); ++it) {
		(*it)->getStorageBytes(inStream);
	}
	inStream.flush();
}
Example #5
0
void httperror (iostream &sstream, int status, string s_str, string relURL) { 

	string errorFile;

	con.errorLog (s_str, relURL);

	// display error page for corresponding error
	if (status == 403)
		errorFile = "public_www/403error.html";
	else if (status == 404)
		errorFile = "public_www/404error.html";
	else if (status == 400)
		errorFile = "public_www/400error.html";
	else if (status == 501)
		errorFile = "public_www/501error.html";
	else
		errorFile = "public_www/000error.html";

	ifstream inputfile2(errorFile.c_str(), ios::in);
	
	string header = "HTTP/1.1 200 OK\r\n";
	sstream.write (header.c_str(), header.size());
	
	header = "Content-Type:text/html\r\n";
	sstream.write (header.c_str(), header.size());

	int filesize = FileSize (errorFile.c_str());
	header = "Content-Length:" + strconvert(filesize) + "\r\n";
	sstream.write (header.c_str(), header.size());

	// end with empty line
	sstream.write ("\r\n", 2);

	char c2;
				
	for (; filesize >0; filesize--) {
		c2 = inputfile2.get();
		sstream.put (c2);
		//cout.put(c2);
		if (sstream.fail()) {
			// socket stream failed. Closed by client???
			// nothing we can do, but stop
			break;
		}
	}
	sstream.flush ();

	inputfile2.close ();
}
void TagPayloadInt::getStorageBytes(iostream& inStream){
	writeSwappedIntToStream(payload, inStream);
	inStream.flush();
}
void NBTTag::getStorageBytes(iostream& inStream){
	inStream << getCharFromTag(TagType);
	name.getStorageBytes(inStream);
	Payload->getStorageBytes(inStream);
	inStream.flush();
}
void TagPayloadByte::getStorageBytes(iostream& inStream){
	inStream << payload;
	inStream.flush();
}
void TagPayloadString::getStorageBytes(iostream& inStream){
	writeSwappedShortToStream((unsigned short) payload.size(), inStream);
	inStream << payload;
	inStream.flush();
}
Example #10
0
void makeDirectory (iostream &sstream, string relURL) {
	string makedir = "make_directory.html";

	DIR *pdir;
 	struct dirent *pent;

	string requestedFile = ROOT_DIR + relURL;

 	pdir=opendir(requestedFile.c_str());

	ofstream myfile;
	myfile.open (makedir.c_str());
	myfile << "<html><head>" << endl;
	myfile << "<title>Listing Directory Contents of " << relURL << "</title>" << endl;
	myfile << "</head><body>" << endl;
	myfile << "<h1>Listing Directory Contents of " << relURL << "</h1>" << endl;


	while ((pent=readdir(pdir))){
		if (!strcmp(pent->d_name, ".") || !strcmp(pent->d_name, ".."))
			continue;
		myfile << "<a href=\"" << relURL << pent->d_name << "\">" << pent->d_name << "</a>";
		if (con.lookupAccessLog(relURL + pent->d_name) == "")
			myfile << "  <-> <-><br>" << endl;
		else
			myfile << "  " << con.lookupAccessLog(relURL + pent->d_name) << "<br>" << endl;	
	}

	myfile << "</body></html>" << endl;
	
	closedir(pdir);

	ifstream inputfile2(makedir.c_str(), ios::in);
	
	string header = "HTTP/1.1 200 OK\r\n";
	sstream.write (header.c_str(), header.size());
	
	header = "Content-Type:text/html\r\n";
	sstream.write (header.c_str(), header.size());
	
	int filesize = FileSize (makedir.c_str());
	header = "Content-Length:" + strconvert(filesize) + "\r\n";
	sstream.write (header.c_str(), header.size());
	
	// end with empty line
	sstream.write ("\r\n", 2);

	char c2;
				
	for (; filesize >0; filesize--) {
		c2 = inputfile2.get();
		sstream.put (c2);
		//cout.put(c2);
		if (sstream.fail()) {
			// socket stream failed. Closed by client???
			// nothing we can do, but stop
			break;
		}
	}
	sstream.flush ();

	inputfile2.close ();
}