dmap_serv.cpp 3.3 KB
/*
 * Copyright 2007 Stephen Liu
 * For license terms, see the file COPYING along with this library.
 */

#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>
#include <assert.h>

#include <fcgi_stdio.h>
#include "dmpapacheserverrequest.h"
#include "dmpapacheserverresponse.h"
#include "dmpmainserver.h"
#include "dmpapplication.h"

void CreateEnv(CgiENV& env)
{
    env.HTTP_HOST="localhost";
    env.HTTP_CONNECTION="keep-alive";
    env.HTTP_USER_AGENT="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36 Edg/95.0.1020.53";
    env.HTTP_ACCEPT="text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9";
    env.HTTP_ACCEPT_ENCODING="gzip, deflate, br";
    env.HTTP_ACCEPT_LANGUAGE="zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6";
    env.PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin";
    env.SERVER_NAME="localhost";  
    env.SERVER_ADDR="::1";
    env.SERVER_PORT="80"; 
    env.REMOTE_ADDR="::1";  
    env.REQUEST_METHOD="GET";
    env.QUERY_STRING="REQUEST=GetCapabilities";
    env.REQUEST_URI="/DMap/Services/GDMap1/MapServer/WMTSServer";
}
void InitCgiEnv(CgiENV& env)
{
	//FCGX_GetParam("REMOTE_ADDR", );
    env.HTTP_HOST="localhost";
    env.HTTP_CONNECTION="keep-alive";
    env.HTTP_USER_AGENT="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36 Edg/95.0.1020.53";
    env.HTTP_ACCEPT="text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9";
    env.HTTP_ACCEPT_ENCODING="gzip, deflate, br";
    env.HTTP_ACCEPT_LANGUAGE="zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6";
    env.PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin";
    env.SERVER_NAME="localhost";  
    env.SERVER_ADDR="::1";
    env.SERVER_PORT="80"; 
    env.REMOTE_ADDR="::1";  
    env.REQUEST_METHOD="GET";
    env.QUERY_STRING="REQUEST=GetCapabilities";
    env.REQUEST_URI="/DMap/Services/GDMap1/MapServer/WMTSServer";
}

int main(int argc,char * argv[] )
{
	DmpApplication::Instance()->initialize();
	DmpMainServer dmpServer;
    extern char **environ;
	int nlen=0;
	int i;
	char *psz_content = NULL;
	char **pp_env;

	setuid(geteuid());
    const char *display = getenv( "DISPLAY" );
    bool withDisplay = true;
    if ( !display )
    {
		withDisplay = false;
		
    }   
	while(FCGI_Accept()>=0)
	{
		// printf("Content-type: text/html\n\n");  	   
		if(strcmp("GET",getenv("REQUEST_METHOD"))==0)
		{
			// printf("REQUEST_METHOD=GET\n");	 
			CgiENV env;
	        CreateEnv(env);
		    DmpApacheServerRequest dmpRequest(env);
            DmpApacheServerResponse dmpResponse; 
            dmpServer.HandleRequest(dmpRequest, dmpResponse);
			// printf("REQUEST_METHOD=GET END\n");	 
		}
		else
		{
			nlen=atoi(getenv("CONTENT_LENGTH"));
			psz_content=(char *)malloc(nlen+1);
			memset(psz_content,0,nlen+1);
			printf("<p>char value:</p><p>");
			for(i=0;i<nlen;i++)
			{
				//psz_content[i]=fgetc(stdin);
				//printf("%c",psz_content[i]);
			}
			printf("</p><p>string value:%s</p>",psz_content);

		}
	}
    return 0;
}