Esempio n. 1
0
int make_http_content(const char *command, char **buf) 
{
	char *contentbuf = NULL;
	int icontentlen = 0;

	if (command[0] == 0) //GET请求后面为空,得到默认页面内容图
	{
		icontentlen = getfilecontent("default.html", &contentbuf);
	} else
	{
		icontentlen = getfilecontent(command, &contentbuf);
	}

	if (icontentlen > 0)
	{
		char headbuf[1024];
		memset(headbuf, 0, sizeof(headbuf));
		sprintf(headbuf, HEAD, getfiletype(command), icontentlen); //设置消息头
		int iheadlen = strlen(headbuf);//得到消息头长度
		int itaillen = strlen(TAIL);//得到消息尾长度
		int isumlen = iheadlen + icontentlen + itaillen;//得到消息总长度
		*buf = (char*)malloc(isumlen);//根据消息总长度,动态分配内存
		char *tmp = *buf;
		memcpy(tmp, headbuf, iheadlen); //安装消息头
		memcpy(&tmp[iheadlen], contentbuf, icontentlen); //安装消息体
		memcpy(&tmp[iheadlen + icontentlen], TAIL, itaillen); //安装消息尾
		printf("headbuf:\n%s", headbuf);
		if (contentbuf)
			free(contentbuf);
		return isumlen;//返回消息总长度
	} else
	{
		return 0;
	}
}
Esempio n. 2
0
int Response::sendfile(File & f)
{
	char tmp[2048];
	if(client.write("HTTP/1.1 200 OK\r\n")<=0) return -1;
	sprintf(tmp,"Content-Type: %s\r\n",mime.gettype( getfiletype()) );
	if(client.write(tmp)<=0) return -1;
	if(req.keepalive)
	{if(client.write("Connection: Keep-Alive\r\n")<=0) return -1;}
	else
	{if(client.write("Connection: close\r\n")<=0) return -1;}
	sprintf(tmp,"Content-Length: %lld\r\n",f.size);
	if(client.write(tmp)<=0) return -1;
	if(client.write("\r\n")<=0) return -1;
	
	int fd=open(file,O_RDONLY),len;
	while( (len=read(fd,tmp,2048))>0 )
	{
		if(client.write(len,tmp)<=0) {close(fd);return -1;}
	}
	close(fd);
	return 0;
}
Esempio n. 3
0
//lib functions
int loadfiletopalm(std::string path){
	struct stat stat_buf;
	stat(path.c_str(), &stat_buf);
	if(stat_buf.st_size == 0)return LOCKEDFILE;
	size_t_68k size = stat_buf.st_size;
	UBYTE *mempool = new UBYTE[size];
	ifstream appfile (path,ios::in | ios::binary);
	if (appfile.is_open()){
		appfile.read((char*)mempool,size);
	}
	appfile.close();

	UWORD flags = (UWORD)mempool[0x20] << 8 | mempool[0x21];

	int pass;
	string ftype = getfiletype(path);
	//working area
	if(ftype == "prc" && (flags & dmHdrAttrResDB))pass = prcparse(mempool,size);
	else if(ftype == "pdb" && !(flags & dmHdrAttrResDB))pass = pdbparse(mempool,size);
	else if(ftype == "prc" && !(flags & dmHdrAttrResDB)){
		dbgprintf("Conflicting filetypes: name is .prc but db says it is a record database\n");
		pass = pdbparse(mempool,size);
	}
	else if(ftype == "pdb" && (flags & dmHdrAttrResDB)){
		dbgprintf("Conflicting filetypes: name is .pdb but db says it is a resource database\n");
		pass = prcparse(mempool,size);
	}
	else{
		TEMPHACK;
		//display some where other then the console
		if(ftype == "pqa")dbgprintf("PQA is just a web page.(This is not a web browser.)\n");
		else dbgprintf("Filetype:%s is not supported\n",ftype.c_str());
		pass = NOTPALMFILE;
	}

	delete[] mempool;
	return pass;
}