Esempio n. 1
0
int _tmain(int argc, _TCHAR* argv[])
{
#ifndef _DEBUG
	CKLog::SetDebugType( LOG_TYPE_WARNING);
#endif

	InitSocket();

	COrderApp app;
	CUdpServer udpServer;
	udpServer.SetApp( &app );

	if ( !app.Connect() )
		return -1;

	if ( !udpServer.Connect() )
	{
		app.Release();
		UninitSocket();
		return -1;
	}

	CommandProcess( app);

	udpServer.Release();

	app.Release();

	UninitSocket();

	return 0;
}
Esempio n. 2
0
void httpserver_quit(void)
{
        if(xml_rpm_server_obj) XMLRPC_ServerDestroy(xml_rpm_server_obj);
        httpParam.bKillWebserver=1;
        mwServerShutdown(&httpParam);
	UninitSocket();
}
Esempio n. 3
0
int main(int argc,char* argv[])
{
#ifndef WIN32
	signal(SIGINT, (void *) MiniWebQuit);
	signal(SIGTERM, (void *) MiniWebQuit);
	signal(SIGPIPE, SIG_IGN);
#endif

	httpParam.maxClients=32;
	httpParam.httpPort=80;
	httpParam.maxReqPerConn=99;
	httpParam.pchWebPath="webroot";
	httpParam.pxUrlHandler=urlHandlerList;
	//set web callbacks
	httpParam.pfnSubst=DefaultWebSubstCallback;
#ifndef _NO_POST
	httpParam.pfnPost = DefaultWebPostCallback;
	httpParam.pfnFileUpload = DefaultWebFileUploadCallback;
#endif
	
	InitSocket();
	//start server
	if (!mwServerStart(&httpParam)) {
		//wait
		getchar();
		//shutdown server
		mwServerShutdown(&httpParam);
	}
	UninitSocket();
	return 0;
}
Esempio n. 4
0
//DWORD WINAPI MicroWebThread(LPVOID lpParam) 
int main(int argc, char *argv[])
{
  DWORD lRetVal = 0;
  int lFuncRetVal = 0;
  int lCount = 0;
  struct stat st;
  FILE *lFH = NULL;
  
  LogMsg(DBG_INFO, "MicroWebThread() : Starting MicroWeb");



  /*
   * create 404.html if it doesn't exist
   */
  if (stat("404.html", &st) < 0)
  {
    if ((lFH = fopen("404.html", "w")) != NULL)
    {
      fprintf(lFH, "<html><body><b>OOPS!</b><br />File not found!</body></html>");
      fclose(lFH);
    }
  }


  /*
   *
   */
/*
  if ((lCancelEvent = OpenEvent(EVENT_ALL_ACCESS , FALSE, "Cancellation")) == INVALID_HANDLE_VALUE)
  {
    LogMsg(DBG_ERROR, "MicroWebThread() : OpenEvent failed (%d)", GetLastError());
    lRetVal = 1;
    goto END;
  }
*/


  /*
   * Start the  server.
   */
//  SetConsoleCtrlHandler((PHANDLER_ROUTINE) MiniWebQuit, TRUE);

  

 	if (!nInst) 
	  	nInst=1;


 	//initialize HTTP parameter structure
	 {
		  int iParamBytes = nInst * sizeof(HttpParam);
		
  		if (!(httpParam = malloc(iParamBytes))) 
		  {
   			LogMsg(DBG_ERROR, "MicroWebThread() : Out of memory");
			   return -1;
		  }
  		ZeroMemory(httpParam, iParamBytes);
	 }

 	//fill in default settings
	 {
  		int i;
		  for (i = 0; i < nInst; i++) 
		  {
   			(httpParam+i)->maxClients = 32;
			   (httpParam+i)->maxReqPerConn = 99;
   			(httpParam+i)->pchWebPath = ".\\";
			   (httpParam+i)->pxUrlHandler = urlHandlerList;
   			(httpParam+i)->flags = FLAG_DIR_LISTING;
		  }
	 }

 	//parsing command line arguments
 	{
  		int inst=0;
    (httpParam+inst)->httpPort = HTTP_PORT;
    (httpParam+inst)->pchWebPath = "/";		
	 }

 	//adjust port setting
	 {
		  int i;
	  	short int port = HTTP_PORT;
	  	for (i = 0; i < nInst; i++) 
		  {
   			if ((httpParam+i)->httpPort)
			    	port = (httpParam+i)->httpPort + 1;
   			else
			    	(httpParam+i)->httpPort = port++;
		  }
	 }


	 InitSocket();

	 if (nInst>1) 
    LogMsg(DBG_INFO, "MicroWeb() : Number of instances: %d", nInst);

	 {
		  int i;
		  int error = 0;

		  for (i = 0; i < nInst; i++) 
		  {
   			int n;

	 		  for (n=0; urlHandlerList[n].pchUrlPrefix; n++);

      LogMsg(DBG_INFO, "MicroWebThread() : Listening port: %d, web root %s, Max clients: %d, No. handlers: %d", (httpParam+i)->httpPort, (httpParam+i)->pchWebPath, (httpParam+i)->maxClients, n);


  			//register page variable substitution callback
			  //(httpParam+i)->pfnSubst=DefaultWebSubstCallback;

		 	  //start server
	   		if ((lFuncRetVal = mwServerStart(&httpParam[i])) != 0) 
   			{
  				  LogMsg(DBG_ERROR, "MicroWebThread() : Error \"%d\" starting instance #%d", lFuncRetVal, i);
			    	error++;
		   	}
  		}
	
		  if (error < nInst) 
  		{
      LogMsg(DBG_INFO, "MicroWebThread() : Waiting for micro web thread return");

      /*
       * Waiting for micro web thread returning
       */
      while (TRUE)
      {
        if (WaitForSingleObject(httpParam[0].tidHttpThread, 100) != WAIT_TIMEOUT)
        {
          LogMsg(DBG_INFO, "MicroWebThread() : Thread stopped running.");
          break;
        }

/*
        if (WaitForSingleObject(lCancelEvent, 100) != WAIT_TIMEOUT)
        {
          LogMsg(DBG_INFO, "MicroWebThread() : Cancellation event set.");
          break;
        } // if (WaitForSingleObject(...
*/
      } // while (TRUE)...
	  	} 
    else 
    {
		  	 LogMsg(DBG_ERROR, "MicroWebThread() : ailed to launch miniweb");
		  } // if (error < nInst) ...
	 }

	 //shutdown server
 	{
  		if (nInst > 1) 
		  {
   			int i;
			   for (i = 0; i < nInst; i++) 
			   {
				    LogMsg(DBG_INFO, "MicroWebThread() : Shutting down instance %d", i);
    				mwServerShutdown(&httpParam[i]);
		   	}
  		}
		  else
    {
      LogMsg(DBG_INFO, "MicroWebThread() : Shutting down single threaded server");
		   	mwServerShutdown(&httpParam[0]);		
    }
	 }

END:
	 UninitSocket();
  MiniWebQuit(1);

  if (httpParam != NULL)
    free(httpParam);

  LogMsg(DBG_INFO, "MicroWebThread() : Stopping MicroWeb");


 	return(lRetVal);
}