예제 #1
0
파일: math_cgi.c 프로젝트: know-/tiny_httpd
int main()
{
	char method[1024];
	char query_string[1024];
	char post_data[1024];
	int content_length = 0;
	memset(method, 0 ,sizeof(method));
	memset(query_string, 0, sizeof(query_string));
	
	printf("<html>\n");
	printf("<head><title>MATH CAL</title>\n");
	strcpy(method, getenv("REQUEST_METHOD"));
	write(2, method, strlen(method));
	if(strcasecmp("GET", method) == 0){
		strcpy(query_string, getenv("QUERY_STRING"));
		write(2, query_string, strlen(query_string));
		math_add(query_string);//data1=xx&data2=xx
	}else if(strcasecmp("POST", method) == 0){
		content_length = atoi(getenv("CONTENT_LENGTH"));
		int i = 0;
		for(; i<content_length; ++i){
			read(0, &post_data[i], 1);
		}
		post_data[i] = '\0';
		math_add(post_data);
	}else{
		return 1;
	}
	
	printf("</head>\n");
	printf("</html>\n");
	
	return 0;
}
예제 #2
0
int main()
{
	int content_length = -1;
	char method[COMM_SIZE];
	char query_string[COMM_SIZE];
	char post_data[4*COMM_SIZE];
	char *tmp;
	bzero(method,sizeof(method));
	bzero(query_string,sizeof(query_string));
	bzero(post_data,sizeof(post_data));

	printf("<html>\n");
	printf("<body>\n");
	printf("\t<n>method world</n>\t");
	printf("<p>method : %s<br>",method);

	tmp = getenv("REQUEST_METHOD");
	if (tmp == NULL)
		exit(1);
	strcpy(method,tmp);
	if (strcasecmp(method,"GET") == 0)
	{
		tmp = getenv("QUERY_STRING");
		if (tmp != NULL)
			strcpy(query_string,tmp);
		math_add(query_string);
	}
	else if (strcasecmp(method,"POST") == 0)
	{
		tmp = getenv("CONTENT_LENGTH");
		if (tmp == NULL)
			exit(1);
		content_length = atoi(tmp);
		int i = 0;
		for (;i < content_length;i++)
		{
			read(0,&post_data[i],1);
		}
		post_data[i] = '\0';
		math_add(post_data);
	}
	printf("</body>\n");
	printf("</html>\n");


}
예제 #3
0
int main()
{
	int content_length = -1;
	char method[1024];
	char query_string[1024];
	char post_data[4096];
	
	memset(method, '\0', sizeof(method));
	memset(query_string, '\0', sizeof(query_string));
	memset(post_data, '\0', sizeof(post_data));

	printf("<html>\n");
	printf("<head>MATH YUNSUAN</head>\n");
	printf("<body>\n");
	strcpy(method, getenv("REQUEST_METHOD"));
	if( strcasecmp("GET", method) == 0 )
	{
		strcpy(query_string, getenv("QUERY_STRING"));
		math_add(query_string);
	//	math_mul(query_string);
	}
	else if( strcasecmp("POST", method) == 0 )
	{
		content_length = atoi(getenv("CONTENT_LENGTH"));
		int i = 0; 
		for(; i < content_length; i++ ){
			read(0, &post_data[i], 1);
		}
		post_data[i] = '\0';
		math_add(post_data);
	//	math_mul(post_data);
	}
	else
	{
		//DO NOTHING
		return 1;
	}

	printf("</body>\n");
	printf("</html>\n");
}
예제 #4
0
int main()
{
	int content_length  = -1;
	char method[1024];
	char query_string[1024];
	char post_data[4096];
	memset(method, '\0', sizeof(method));
	memset(query_string, '\0', sizeof(query_string));
	memset(post_data, '\0', sizeof(post_data));

	printf("<html>\n");
	printf("<head>MATH</head>\n");
	printf("<body>\n");
	strcpy(method, getenv("REQUEST_METHOD"));
	if(strcasecmp(method, "GET") == 0){
		strcpy(query_string, getenv("QUERY_STRING"));
		printf("<p>query_string : %s</p>\n", query_string);
		printf("get query_string to math\n");
		math_add(query_string);

	}else if(strcasecmp("POST", method) == 0){// post
		content_length = atoi(getenv("CONTENT_LENGTH"));
		int i = 0;
		for(; i<content_length; i++){
			read(0,&post_data[i], 1);
		}
		post_data[i] =  '\0';
		printf("<p>post_data ; %s</p>\n", post_data);
		printf("post post_data to math\n");
		math_add(post_data);
	}else{
		//do nothing
		return 1;
	}
	printf("</body>\n");
	printf("</html>\n");
	return 0;
}
예제 #5
0
파일: Sum.cpp 프로젝트: Mr-Yuxuan/LinuxCode
int main()
{
	char method[1024];
	char vals[1024];
	memset(method,'\0',sizeof(method));
	memset(vals,'\0',sizeof(vals));

	printf("<html>\n");
	printf("<head><h1>MATH_ADD</h1></head>\n");
	printf("<body>\n");

	strcpy(method,getenv("METHOD"));
	if(strcmp(method,"GET")==0)
	{
		strcpy(vals,getenv("VAL"));
	}
	else
	{
		int i=0;
		char c='\0';
		int lenth=atoi(getenv("CONTENT_LENTH"));
		for(;i<lenth;++i)
		{
			read(0,&c,1);
			vals[i]=c;
		}
		
	}
	//printf("<html>\n");
	//printf("<head>MATH_ADD</head>\n");
	//printf("<body>\n");

	math_add(vals);
	printf("</body>\n");
	printf("</html>\n");


	return 0;
}