コード例 #1
0
static int adddata(HTTPCONNECTION hConnection, time_t *ptLastFill, void *p)
{
	FILE *fp;
	time_t tCur;
	static ss=0;

	fp = (FILE *)p;

	if (!feof(fp))
	{
		char ac[1024 * 6];
		int rt;
		rt = fread(ac, 1, sizeof(ac), fp);
		AddHttpBody(hConnection, ac, rt);
printf("%d %d\n", rt, ss++);
		SetSendDataOverFun(hConnection, adddata, p);
		usleep(100000);
	}
	else
	{
PTE;
		fclose(fp);
		SetSendDataOverFun(hConnection, NULL, p);
	}
	return 1;
}
コード例 #2
0
int t1(HTTPCONNECTION hConnection,
								char **ppcPostBuf,
								int *piPostBufLen,
								int *piPostDataLen,
								char *pcFillData,
								int iFillDataLen,
								int iIsMoreData/*bool*/,
								void *pParam/*other parameter for extend use*/)
{
	if (*ppcPostBuf == NULL)
	{
		*piPostBufLen = 3*1024*1024;
		*ppcPostBuf = (char *)malloc(*piPostBufLen);
		*piPostDataLen = 0;
	}

	memcpy(*ppcPostBuf + *piPostDataLen, pcFillData, iFillDataLen);
	*piPostDataLen += iFillDataLen;

	AddHttpBodyString(hConnection, "OK");
	SetHttpHeader(hConnection, 200, "OK", NULL, NULL, "text/plain", TRUE);
	return 0;

	if (!iIsMoreData)
	{
		AddHttpBody(hConnection, *ppcPostBuf, *piPostDataLen);
		SetHttpHeader(hConnection, 200, "OK", NULL, NULL, "text/plain", TRUE);
		return 1;
	}
	return 1;
}
コード例 #3
0
int tt(HTTPCONNECTION hc, void *p)
{
	static i=0;
	request *req = (request *)hc;
	printf("--->[%s]\n[%s]\n", req->pathname, req->query_string);

	//printf("-------------------->oks\n");
	if (GetHttpMethod(hc) == M_GET)
	{
		FILE *fp;
		struct stat st;
		int success = 0;
		char *pcF[] = {"/CamImg1542.jpg", "/CamImg2328.jpg"} ;
		char *pcFile;

		i++;
		i %= 2;

		pcFile = GetDocumentBasedPath(pcF[i]);
		if (pcFile)
		{
			if (stat(pcFile, &st) == 0)
			{
				fp = fopen(pcFile, "rb");
				if (fp)
				{
					char *pc;
					pc = malloc(st.st_size);
					fread(pc, st.st_size, 1, fp);
					AddHttpBody(hc, pc, st.st_size);
					SetHttpHeader(hc, 200, "OK", NULL, "Expires: 01 Jan 1970 00:00:00 GMT\r\nCache-Control: no-cache\r\n", "image/jpeg", TRUE);
					free(pc);
					fclose(fp);
					success = 1;
				}
			}
			free(pcFile);
		}
		if (!success)
			send_r_not_found(hc);

		return 0;
	}
	else
//		SetPostDataFun(hc, t1, p);
	return -1;
}
コード例 #4
0
void __SendBufferWithParam( HTTPCONNECTION hc, char *pcBuffer, int iBufLen, va_list arg )
{
	char *pcFileBuf;
	int iFileLen;
	char *pcBeginSearchPos;
	char *pcBlockBegin;
	char *pcBlockEnd;
	char *pcNextBeginSearchPos;
	char *pcFmt;
	int i, j;
	char *pcBuf;
	char *pc;

	char *pcArg;
	int iArg;
	unsigned int uiArg;
	int (*pfArg)(HTTPCONNECTION, char *);

	if ((pcBuf = (char *)malloc(1024 * 10)) == NULL)
	{
		//(CXH_MODIFY) 这儿可能会超出pcBuf,从而产生严重的问题。???How to
		PRINT_MEM_OUT;
		return;
	}

	pcFileBuf = pcBuffer;
	iFileLen = iBufLen;

	pcBeginSearchPos = pcFileBuf;
	while(SearchReplaceBlock(pcFileBuf, iFileLen,
						pcBeginSearchPos,
						&pcBlockBegin, &pcBlockEnd, &pcNextBeginSearchPos))
	{
		AddHttpBody(hc, pcBeginSearchPos, pcBlockBegin - 6 - pcBeginSearchPos);

		for (i=0,pcFmt=pcBlockBegin; pcFmt<pcBlockEnd;)
		{
			if(*pcFmt != '%')
			{
				pcBuf[i++] = *pcFmt++;
			}
			else
			{
				if (++pcFmt >= pcBlockEnd) break;
				if (*pcFmt == 's')
				{
					pcArg = va_arg(arg, char *);
					for (j=0; pcArg[j]!='\0'; j++) pcBuf[i++] = pcArg[j];
					pcFmt++;
				}
				else if (*pcFmt == 'j')	//放在javascript中的字符串
				{
					pcArg = va_arg(arg, char *);
					pc = GetWebInCString(pcArg);
					if (pc != NULL)
					{
						for (j=0; pc[j]!='\0'; j++) pcBuf[i++] = pc[j];
						free(pc);
					}
					pcFmt++;
				}
				else if (*pcFmt == 'd')