예제 #1
0
파일: ckserver.cpp 프로젝트: allenway/onvif
int main(int argc, char **argv)
{ int m, s;
  struct soap soap;
  soap_init(&soap);
  // cookie domain for CGI must be the current host name:
  // soap.cookie_domain = "www.cs.fsu.edu";
  // Cookie domain for stand-alone server:
  soap.cookie_domain = "localhost:8080";
  // the path which is used to filter/set cookies with this destination
  soap.cookie_path = "/";
  if (argc < 2)
  { // CGI app: grab cookies from 'HTTP_COOKIE' env var
    soap_getenv_cookies(&soap);
    soap_serve(&soap);
  }
  else
  { int port;
    char buf[100];
    port = atoi(argv[1]);
    m = soap_bind(&soap, NULL, port, 100);
    if (m < 0)
    { soap_print_fault(&soap, stderr);
      exit(1);
    }
    sprintf(buf, "localhost:%d", port);
    soap.cookie_domain = buf;
    fprintf(stderr, "Socket connection successful %d\n", m);
    for (int i = 1; ; i++)
    { s = soap_accept(&soap);
      if (s < 0)
        exit(-1);
      fprintf(stderr, "%d: accepted %d IP=%d.%d.%d.%d ... ", i, s, (int)(soap.ip>>24)&0xFF, (int)(soap.ip>>16)&0xFF, (int)(soap.ip>>8)&0xFF, (int)soap.ip&0xFF);
      if (!soap_serve(&soap))
        fprintf(stderr, "served\n");
      else
        soap_print_fault(&soap, stderr);
      // clean up 
      soap_destroy(&soap);
      soap_end(&soap);
      // remove all old cookies from database so no interference when new
      // requests with new cookies arrive
      soap_free_cookies(&soap);
      // Note: threads can have their own cookie DB which they need to cleanup
      // before they terminate
    }
  }
  return 0;
}
예제 #2
0
int main(int argc, char **argv) 
{ 
   /*
   rapidjson::Document document;
   document.SetObject();
   rapidjson::Value key1("key1");
   rapidjson::Value value1("value1");
   document.AddMember(key1, value1,
		      document.GetAllocator());
   rapidjson::StringBuffer buffer;
   rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
   document.Accept(writer);
  
   std::cout << buffer.GetString() << std::endl;
   std::cout << buffer.GetSize() << std::endl;
   */

   struct soap soap, *tsoap;
   pthread_t tid;
   int m, s;
   //soap_init2(&soap, SOAP_IO_KEEPALIVE, SOAP_IO_KEEPALIVE);
   //soap.max_keep_alive = 10;
   //soap.accept_timeout = 15;
   soap.cookie_domain = ".."; 
   soap.cookie_path = "/"; // the path which is used to filter/set cookies with this destination 
   int count = 0; 
   if (argc < 2)
   { 

      std::cout << "It should contain config file. Please checkout the config examples in config_template" << std::endl;
      exit(1);

      soap_getenv_cookies(&soap); // CGI app: grab cookies from 'HTTP_COOKIE' env var 
      soap_serve(&soap);

   }
   else
   {  
      std::string path_config = argv[1];
      if(!config.LoadFromFile(path_config))
      {
	exit(1);
      }


      m = soap_bind(&soap, NULL, config.GSOAP_SERVER_PORT, 100); 
      if (m < 0)
         exit(1);

      for (count = 0; count >= 0; count++) 
      { 
         soap.socket_flags = MSG_NOSIGNAL; // use this 
         //soap.accept_flags = SO_NOSIGPIPE; // or this to prevent sigpipe 
         s = soap_accept(&soap); 
         if (s < 0) 
         { 
            if (soap.errnum) 
               soap_print_fault(&soap, stderr); 
            else
               fprintf(stderr, "Server timed out\n"); // Assume timeout is long enough for threads to complete serving requests 
            break; 
         } 
         fprintf(stderr, "Accepts socket %d connection from IP %d.%d.%d.%d\n", s, (int)(soap.ip >> 24)&0xFF, (int)(soap.ip >> 16)&0xFF, (int)(soap.ip >> 8)&0xFF, (int)soap.ip&0xFF); 
         tsoap = soap_copy(&soap); 
         pthread_create(&tid, NULL, (void*(*)(void*))process_request, (void*)tsoap); 
      } 

   }
   return 0; 
}