Example #1
0
int run_serve(int port)
{ struct soap *soap = soap_new1(SOAP_ENC_MTOM); /* enable MTOM */
  int ret;
  if (!soap_valid_socket(soap_bind(soap, NULL, port, 100)))
    soap_print_fault(soap, stderr);
  else
  { fprintf(stderr, "Bind to port %d successful\n", port);
    soap->accept_timeout = 3600; /* let server time out after one hour */
    for (;;)
    { int sock = soap_accept(soap);
      if (!soap_valid_socket(sock))
      { if (soap->errnum)
          soap_print_fault(soap, stderr);
        else
          fprintf(stderr, "Server timed out\n");
        break;
      }
      fprintf(stderr, "Accepting socket %d connection from IP %d.%d.%d.%d... ", sock, (int)(soap->ip>>24)&0xFF, (int)(soap->ip>>16)&0xFF, (int)(soap->ip>>8)&0xFF, (int)soap->ip&0xFF);
      if (soap_serve(soap))
        soap_print_fault(soap, stderr);
      fprintf(stderr, "done\n");
      soap_destroy(soap);
      soap_end(soap);
    } 
  }
  ret = soap->error;
  soap_free(soap); /* done and free */
  return ret;
}
Example #2
0
//监听指定端口,事件参考event.c
//用于监听IPC上线或下线、或响应客户探测
//timeout设置超时时间,>0单位为秒 =0 用不超时 <0单位为微秒
static int listenPort(int port,int timeout)
{
	struct soap *serv = soap_new1(SOAP_IO_UDP); // to invoke messages
	int ret;
	//绑定端口号
	if (!soap_valid_socket(soap_bind(serv,NULL,port, 100)))
	{ 
		soap_print_fault(serv, stderr);
		printf("soap_bind error\n");
  		ret = -1;
		goto ERR0;
	}
	//加入多播地址
	struct ip_mreq mreq;
    mreq.imr_multiaddr.s_addr = inet_addr("239.255.255.250");
    mreq.imr_interface.s_addr = htonl(INADDR_ANY);
    if (setsockopt(serv->socket, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq)) < 0)
    {
		printf("add multiaddr is error\n");
    	goto ERR0;
    }
	//监听
	ret = soap_wsdd_listen(serv,timeout);
	if(ret!=SOAP_OK)
	{
		soap_print_fault(serv, stderr);
		printf("soap_wsdd_listen error,ret=%d\n",ret);
		goto ERR0;
	}
	printf("soap_wsdd_listen return\n");
ERR0:
	soap_end(serv);
	soap_free(serv);
	return ret;
}
Example #3
0
int main(int argc, char**argv)
{ 


   struct soap soap; 
   int m, s;
   size = 0;
   soap_init(&soap); 
   m = soap_bind(&soap, hostname, port, 100); 
   if (m < 0) 
      soap_print_fault(&soap, stderr); 
   else
   { 
     fprintf(stderr, "Socket connection successful: master socket = %d; port = %d\n", m, port); 
      int i;
      for (i = 1; ; i++) 
      {
         s = soap_accept(&soap); 
         if (s < 0) 
         { 
            soap_print_fault(&soap, stderr); 
            break; 
         } 
         fprintf(stderr, "%d: accepted connection from IP=%d.%d.%d.%d socket=%d", i, 
            (soap.ip >> 24)&0xFF, (soap.ip >> 16)&0xFF, (soap.ip >> 8)&0xFF, soap.ip&0xFF, s); 
         if (soap_serve(&soap) != SOAP_OK)
            soap_print_fault(&soap, stderr);
         fprintf(stderr, "request served\n"); 
         soap_destroy(&soap);
         soap_end(&soap);
      } 
   } 
   soap_done(&soap);
} 
Example #4
0
int main(int argc, char **argv)
{
int result = -1;
int id_count = 1;

struct Namespace namespaces[] =
{   // {"ns-prefix", "ns-name"}
   {"SOAP-ENV", "http://www.w3.org/2003/05/soap-envelope"}, // MUST be first
   {"d", "http://schemas.xmlsoap.org/ws/2005/04/discovery"}, 
   {"wsa", "http://schemas.xmlsoap.org/ws/2004/08/addressing"}, 
   {"dn", "http://www.onvif.org/ver10/network/wsdl"}, // given by the service description
   {NULL, NULL} // end of table
}; 
	 
	 // Get UUID
	 uuid_t uuid;
	 char szUuid[36] = {0};
	 char szMsgID[50] = {0};
	 
	 uuid_generate_time(uuid);
	 
	 uuid_unparse(uuid, szUuid);
	 
	 snprintf(szMsgID, sizeof(szMsgID), "uuid:%s", szUuid);
	 
struct soap soap;
struct SOAP_ENV__Header header; // the SOAP Header

soap_init(&soap);
soap.send_timeout = 1; // 1s timeout
soap.recv_timeout = 1; // 1s timeout

soap_set_namespaces(&soap, namespaces);

soap_default_SOAP_ENV__Header(&soap, &header); // init SOAP Header
header.wsa__MessageID = szMsgID;
header.wsa__To = "urn:schemas-xmlsoap-org:ws:2005:04:discovery";
header.wsa__Action = "http://schemas.xmlsoap.org/ws/2005/04/discovery/Probe";

soap.header = &header;

struct d__ProbeMatchType r;
// Send and receive messages over UDP:
if (soap_send_d__Probe(&soap, "soap.udp://239.255.255.250:3702", NULL, "", ""))
{
      soap_print_fault(&soap, stderr);
}

// Send and receive messages over UDP:
if (soap_send_d__ProbeMatches(&soap, "soap.udp://239.255.255.250:3702", NULL, NULL))
{
      soap_print_fault(&soap, stderr);
}

soap_destroy(&soap); // cleanup
soap_end(&soap); // cleanup
soap_done(&soap); // close connection (should not use soap struct after this) 

return 0;
}
Example #5
0
int main()
{
  struct soap soap;
  int m, s; // master and slave sockets
  int i;

  soap_init(&soap);
  m = soap_bind(&soap, "127.0.0.1", 9111, 100);
  if (m < 0)
    soap_print_fault(&soap, stderr);
  else
    {
      fprintf(stderr, "Socket connection successful: master socket = %d\n", m);
      for (i = 1; ; i++)
        {
          s = soap_accept(&soap);
          if (s < 0)
            {
              soap_print_fault(&soap, stderr);
              break;
            }

          fprintf(stderr,
                  "%d: accepted connection from IP=%d.%d.%d.%d socket=%d\n", i,
                  (soap.ip >> 24)&0xFF, (soap.ip>>16)&0xFF, (soap.ip>>8)&0xFF,
                  soap.ip&0xFF, s);
          if(soap_serve(&soap) != SOAP_OK) // process RPC request
            soap_print_fault(&soap, stderr); // print error
          fprintf(stderr,"request served\n");
          soap_destroy(&soap); // clean up class instances
          soap_end(&soap); // clean up everything and close socket
        }
    }
  soap_done(&soap); // close master socket and detach environment
}
Example #6
0
int main(int argc, char* argv[])
{
	int m, s; /**//* master and slave sockets */
	struct soap sop;
	soap_init(&sop);
	
	if (argc < 2) {
		printf("usage:%s <server_port>\n", argv[0]);
		goto failed;
	}

	m = soap_bind(&sop, NULL, atoi(argv[1]), 100);
	if (m < 0) {
		soap_print_fault(&sop, stderr);
		goto failed;
	}
	fprintf(stderr, "Socket connection successful: master socket = %d\n", m);

	for ( ; ; ) {
		s = soap_accept(&sop);
		if (s < 0) {
			soap_print_fault(&sop, stderr);
			goto failed;
		}
		fprintf(stderr, "Socket connection successful: slave socket = %d\n", s);
		soap_serve(&sop);
		soap_end(&sop);
	}
	return 0;

failed:
	return 1;
}
int main(int argc, char **argv)
{ int m, s; /* master and slave sockets */
  struct soap soap;
  soap_init(&soap);
  if (argc < 2)
    soap_serve(&soap);	/* serve as CGI application */
  else
  { m = soap_bind(&soap, NULL, atoi(argv[1]), 100);
    if (m < 0)
    { soap_print_fault(&soap, stderr);
      exit(-1);
    }
    fprintf(stderr, "Socket connection successful: master socket = %d\n", m);
    for ( ; ; )
    { s = soap_accept(&soap);
      fprintf(stderr, "Socket connection successful: slave socket = %d\n", s);
      if (s < 0)
      { soap_print_fault(&soap, stderr);
        exit(-1);
      } 
      soap_serve(&soap);
      soap_end(&soap);
    }
  }
  return 0;
} 
int main(int argc, char **argv)
{ struct soap *soap;
  int m, s;
  soap = soap_new();
  if (argc < 3)
    soap_serve(soap); // run as CGI application over the Web
  else // run as stand-alone server on machine given by argv[1] listening to port argv[2]
  { m = soap_bind(soap, argv[1], atoi(argv[2]), 100);
    if (m < 0)
    { soap_print_fault(soap, stderr);
      exit(-1);
    }
    fprintf(stderr, "Socket connection successful: master socket = %d\n", m);
    for (int i = 1; ; i++)
    { s = soap_accept(soap);
      if (s < 0)
      { soap_print_fault(soap, stderr);
        exit(-1);
      }
      fprintf(stderr, "%d: accepted connection from IP = %d.%d.%d.%d socket = %d ... ", i, (int)(soap->ip>>24)&0xFF, (int)(soap->ip>>16)&0xFF, (int)(soap->ip>>8)&0xFF, (int)soap->ip&0xFF, s);
      soap_serve(soap);		// process request
      fprintf(stderr, "request served\n");
      soap_destroy(soap);	// delete class instances
      soap_end(soap);		// clean up everything and close socket
    }
  }
  return 0;
}
Example #9
0
int main(int argc, char **argv) {
  // initialize EMBASSY info
  embInitPV("kclique", argc, argv, "KBWS", "1.0.9");

  struct soap soap;
  char*  jobid;
  char*  result;

  AjPFile    infile;
  AjPFile    outf;
  AjPStr     substr;
  AjPStr     indata = NULL;
  AjPStr     line   = NULL;

  infile = ajAcdGetInfile("infile");
  outf   = ajAcdGetOutfile("outfile");

  while (ajReadline(infile, &line)) {
    ajStrAppendS(&indata, line);
    ajStrAppendC(&indata, "\n");
  }

  soap_init(&soap);

  char* in0;
  in0 = ajCharNewS(indata);
  if ( soap_call_ns1__runClique( &soap, NULL, NULL, in0, &jobid ) == SOAP_OK ) {
  } else {
    soap_print_fault(&soap, stderr);
  }

  int check = 0;
  while ( check == 0 ) {
    if ( soap_call_ns1__checkStatus( &soap, NULL, NULL, jobid,  &check ) == SOAP_OK ) {
    } else {
      soap_print_fault(&soap, stderr);
    }
    sleep(3);
  }

  if ( soap_call_ns1__getResult( &soap, NULL, NULL, jobid,  &result ) == SOAP_OK ) {
    substr = ajStrNewC(result);
    ajFmtPrintF(outf,"%S\n",substr);
  } else {
    soap_print_fault(&soap, stderr);
  }

  soap_destroy(&soap);
  soap_end(&soap);
  soap_done(&soap);

  ajFileClose(&infile);
  ajFileClose(&outf);
  ajStrDel(&substr);

  embExit();

  return 0;
}
Example #10
0
int main(int args, char* argv[]) 
{ 
  char *s; 
  jcl_ws w;

  soap_init1(w.soap, SOAP_ENC_MTOM); // MTOM  
  
//  w.endpoint = "http://mvs.open-bpm.org/mvsserver.cgi";

  if (args==3)
  {
    w.soap->userid = argv[1]; 
    w.soap->passwd = argv[2];
  } 

  if (w.jcl_ws__Ping(s) == SOAP_OK) 
    std::cout <<  s << std::endl; 
  else
  {
    soap_print_fault(w.soap, stderr); 
    return -1;
  }

  struct jcl_data__Payload jcl;

  openReadFile(w.soap, "input.txt", &jcl);

  writeFileName = "output.txt";
  
  // Alloc return Structure
  struct jcl_ws__jclResponse response;
  response._return = soap_new_jcl_ws__output(w.soap, -1);

  std::string param = "Test";
  
  // Call EchoTest
  w.soap->userid = argv[1]; 
  w.soap->passwd = argv[2];
  w.soap->fmimereadopen = readOpenCallback;
  w.soap->fmimereadclose = readCloseCallback;
  w.soap->fmimeread = readCallback;
  w.soap->fmimewriteopen = writeOpenCallback;
  w.soap->fmimewriteclose = writeCloseCallback;
  w.soap->fmimewrite = writeCallback;

  if ( w.jcl_ws__EchoTest(param, &jcl, response) == SOAP_OK ) 
    std::cout <<  "EchoTest OK" << std::endl; 
  else
  {
    soap_print_fault(w.soap, stderr); 
    return -1;
  }

  soap_destroy(w.soap);
  soap_end(w.soap);
  soap_done(w.soap);
                        
  return 0; 
}
Example #11
0
int main()
{ struct soap soap;
  double a, b, result;
  /* Init SSL */
  soap_ssl_init();
  if (CRYPTO_thread_setup())
  { fprintf(stderr, "Cannot setup thread mutex for OpenSSL\n");
    exit(1);
  }
  a = 10.0;
  b = 20.0;
  /* Init gSOAP context */
  soap_init(&soap);
  /* The supplied server certificate "server.pem" assumes that the server is
    running on 'localhost', so clients can only connect from the same host when
    verifying the server's certificate. Use SOAP_SSL_NO_AUTHENTICATION to omit
    the authentication of the server and use encryption directly from any site.
    To verify the certificates of third-party services, they must provide a
    certificate issued by Verisign or another trusted CA. At the client-side,
    the capath parameter should point to a directory that contains these
    trusted (root) certificates or the cafile parameter should refer to one
    file will all certificates. To help you out, the supplied "cacerts.pem"
    file contains the certificates issued by various CAs. You should use this
    file for the cafile parameter instead of "cacert.pem" to connect to trusted
    servers.  Note that the client may fail to connect if the server's
    credentials have problems (e.g. expired). Use SOAP_SSL_NO_AUTHENTICATION
    and set cacert to NULL to encrypt messages if you don't care about the
    trustworthyness of the server.  Note: setting capath may not work on
    Windows.
  */
  if (soap_ssl_client_context(&soap,
    /* SOAP_SSL_NO_AUTHENTICATION, */ /* for encryption w/o authentication */
    /* SOAP_SSL_DEFAULT | SOAP_SSL_SKIP_HOST_CHECK, */	/* if we don't want the host name checks since these will change from machine to machine */
    SOAP_SSL_DEFAULT,	/* use SOAP_SSL_DEFAULT in production code */
    NULL, 		/* keyfile (cert+key): required only when client must authenticate to server (see SSL docs to create this file) */
    NULL, 		/* password to read the keyfile */
    "cacert.pem",	/* optional cacert file to store trusted certificates, use cacerts.pem for all public certificates issued by common CAs */
    NULL,		/* optional capath to directory with trusted certificates */
    NULL		/* if randfile!=NULL: use a file with random data to seed randomness */ 
  ))
  { soap_print_fault(&soap, stderr);
    exit(1);
  }
  soap.connect_timeout = 60;	/* try to connect for 1 minute */
  soap.send_timeout = soap.recv_timeout = 30;	/* if I/O stalls, then timeout after 30 seconds */
  if (soap_call_ns__add(&soap, server, "", a, b, &result) == SOAP_OK)
    fprintf(stdout, "Result: %f + %f = %f\n", a, b, result);
  else
    soap_print_fault(&soap, stderr);
  soap_destroy(&soap); /* C++ */
  soap_end(&soap);
  soap_done(&soap);
  CRYPTO_thread_cleanup();
  return 0;
}
int run_server(int port)
{ struct soap soap;
  int ret;
  /* Enable MTOM */
#ifdef WITH_GZIP
  soap_init1(&soap, SOAP_ENC_MTOM | SOAP_ENC_ZLIB); /* Enable MTOM */
#else
  soap_init1(&soap, SOAP_ENC_MTOM); 
#endif
  /* Set the MIME callbacks */
  soap.fmimereadopen = mime_read_open;
  soap.fmimereadclose = mime_read_close;
  soap.fmimeread = mime_read;
  soap.fmimewriteopen = mime_server_write_open;
  soap.fmimewriteclose = mime_server_write_close;
  soap.fmimewrite = mime_server_write;
  /* Bind socket */
  if (!soap_valid_socket(soap_bind(&soap, NULL, port, 100)))
    soap_print_fault(&soap, stderr);
  else
  { fprintf(stderr, "Bind to port %d successful\n", port);
    /* Optional: let server time out after one hour */
    soap.accept_timeout = 3600;
    /* Unix/Linux SIGPIPE, this is OS dependent:
    soap.accept_flags = SO_NOSIGPIPE;	// some systems like this
    soap.socket_flags = MSG_NOSIGNAL;	// others need this
    signal(SIGPIPE, sigpipe_handle);	// or a sigpipe handler (more portable)
    */
    /* Server loop */
    for (;;)
    { int sock = soap_accept(&soap);
      if (!soap_valid_socket(sock))
      { if (soap.errnum)
          soap_print_fault(&soap, stderr);
        else
        { fprintf(stderr, "Server timed out (see code how to change this)\n");
          break;
        }
      }
      fprintf(stderr, "Accepting socket %d connection from IP %d.%d.%d.%d... ", sock, (int)(soap.ip>>24)&0xFF, (int)(soap.ip>>16)&0xFF, (int)(soap.ip>>8)&0xFF, (int)soap.ip&0xFF);
      if (soap_serve(&soap))
        soap_print_fault(&soap, stderr);
      fprintf(stderr, "done\n");
      soap_destroy(&soap);
      soap_end(&soap);
    } 
  }
  ret = soap.error;
  soap_destroy(&soap);
  soap_end(&soap);
  soap_done(&soap);
  return ret;
}
Example #13
0
int main(int argc, char **argv)
{ struct soap *soap = soap_new();
  const char *endpoint;
  matrix a(soap, 3); // matrix with 3 rows created in current soap env.
  // set up matrix by specifying non-zero elements only (this is optional)
  a[1].resize(1,2); // 2-element vector indexed from 1 to 2
  a[1][1] = 2;
  a[1][2] = 1;
  a[2].resize(1,3); // 3-element vector
  a[2][1] = 1;
  a[2][2] = 2;
  a[2][3] = 1;
  a[3].resize(2,3); // 2-element vector indexed from 2 to 3
  a[3][2] = 1;
  a[3][3] = 2;
  cout << "* Demonstration example *" << endl;
  cout << "Matrix:" << endl;
  a.print();
  vector b(soap, 3);
  b[1] = 1;
  b[2] = 2;
  b[3] = 3;
  cout << "Vector:" << endl;
  b.print();
  vector x(soap);
  if (argc < 2)
    endpoint = luserver;
  else
    endpoint = argv[1];
  /* solve ax=b */
  if (soap_call_ns1__lusol(soap, endpoint, "", &a, &b, &x))
  { soap_print_fault(soap, stderr);
    soap_print_fault_location(soap, stderr);
  }
  else
  { cout << "Solution vector from service:" << endl;
    x.print();
  }
  matrix a1(soap);
  if (soap_call_ns1__luinv(soap, endpoint, "", &a, &a1))
  { soap_print_fault(soap, stderr);
    soap_print_fault_location(soap, stderr);
  }
  else
  { cout << "Inverse matrix matrix from service:" << endl;
    a1.print();
  }
  soap_destroy(soap);
  soap_end(soap);
  free(soap);
  return 0;
}
Example #14
0
Root::Root(const char *factory, enum t__object object, char *name)
{ soap = soap_new();
  endpoint = soap_strdup(soap, factory);
  status = FACTORY_NOTFOUND;
  if (name)
    if (soap_call_ns__lookup(soap, endpoint, "", object, name, status))
      soap_print_fault(soap, stderr);	// for demo, just print
  if (status == FACTORY_NOTFOUND)
    do
    { if (soap_call_ns__create(soap, endpoint, "", object, name, status))
        soap_print_fault(soap, stderr);	// for demo, just print
    } while (status == FACTORY_RETRY);
}
int run_server(int port)
{ struct soap soap;
  int i, ret;
  /* Enable MTOM */
#ifdef WITH_GZIP
  soap_init1(&soap, SOAP_ENC_MTOM | SOAP_ENC_ZLIB); /* Enable MTOM */
#else
  soap_init1(&soap, SOAP_ENC_MTOM); 
#endif
  /* Set the MIME callbacks */
  soap.fmimereadopen = mime_read_open;
  soap.fmimereadclose = mime_read_close;
  soap.fmimeread = mime_read;
  soap.fmimewriteopen = mime_server_write_open;
  soap.fmimewriteclose = mime_server_write_close;
  soap.fmimewrite = mime_server_write;
  /* Bind socket */
  if (!soap_valid_socket(soap_bind(&soap, NULL, port, 100)))
    soap_print_fault(&soap, stderr);
  else
  { fprintf(stderr, "Bind to port %d successful\n", port);
    /* Optional: let server time out after one hour */
    soap.accept_timeout = 3600;
    /* Unix/Linux SIGPIPE, this is OS dependent:
    soap.accept_flags = SO_NOSIGPIPE;	// some systems like this
    soap.socket_flags = MSG_NOSIGNAL;	// others need this
    signal(SIGPIPE, sigpipe_handle);	// or a sigpipe handler (more portable)
    */
    /* Main thread spawns server threads */
    for (i = 1; ; i++)
    { struct soap *tsoap;
      pthread_t tid;
      int sock = soap_accept(&soap);
      if (!soap_valid_socket(sock))
      { if (soap.errnum)
          soap_print_fault(&soap, stderr);
        else
        { fprintf(stderr, "Server timed out (see code how to change this)\n");
          break;
        }
      }
      fprintf(stderr, "Thread %d accepts socket %d connection from IP %d.%d.%d.%d\n", i, sock, (int)(soap.ip>>24)&0xFF, (int)(soap.ip>>16)&0xFF, (int)(soap.ip>>8)&0xFF, (int)soap.ip&0xFF);
      /* Copy soap environment and spawn thread */
      tsoap = soap_copy(&soap);
      pthread_create(&tid, NULL, (void*(*)(void*))process_request, (void*)tsoap);
    } 
  }
  ret = soap.error;
  soap_done(&soap);
  return ret;
}
Example #16
0
/* Server loop */
void audioDB::startServer(){
  struct soap soap;
  int m, s; // master and slave sockets
  soap_init(&soap);
  // FIXME: largely this use of SO_REUSEADDR is to make writing (and
  // running) test cases more convenient, so that multiple test runs
  // in close succession don't fail because of a bin() error.
  // Investigate whether there are any potential drawbacks in this,
  // and also whether there's a better way to write the tests.  --
  // CSR, 2007-10-03
  soap.bind_flags |= SO_REUSEADDR;
  m = soap_bind(&soap, NULL, port, 100);
  if (m < 0)
    soap_print_fault(&soap, stderr);
  else
    {
      fprintf(stderr, "Socket connection successful: master socket = %d\n", m);
      /* FIXME: we used to have a global cache of a single LSH index
       * here.  CSR removed it because it interacted badly with
       * APIification of querying, replacing it with a per-open-adb
       * cache; we should try to take advantage of that instead.
       */

      // Server-side path prefix to databases and features
      if(adb_root)
	SERVER_ADB_ROOT = (char*)adb_root; // Server-side database root
      if(adb_feature_root)
	SERVER_ADB_FEATURE_ROOT = (char*)adb_feature_root; // Server-side features root
      
      isServer = 1;  // From this point, errors are reported via SOAP to the client
      for (int i = 1; ; i++)
	{
	  s = soap_accept(&soap);
	  if (s < 0)
	    {
	      soap_print_fault(&soap, stderr);
	      break;
	    }
          /* FIXME: find a way to play nice with logging when run from
             /etc/init.d scripts: at present this just goes nowhere */
	  fprintf(stderr, "%d: accepted connection from IP=%lu.%lu.%lu.%lu socket=%d\n", i,
		  (soap.ip >> 24)&0xFF, (soap.ip >> 16)&0xFF, (soap.ip >> 8)&0xFF, soap.ip&0xFF, s);
	  if (soap_serve(&soap) != SOAP_OK) // process RPC request
	    soap_print_fault(&soap, stderr); // print error
	  fprintf(stderr, "request served\n");
	  soap_destroy(&soap); // clean up class instances
	  soap_end(&soap); // clean up everything and close socket
	}
    }
  soap_done(&soap); // close master socket and detach environment
} 
Example #17
0
int main(int argc, char **argv)
{ struct soap soap;
  struct ns__varPolyParamTestResponse r;
  int n;
  xsd__anyType *p[N];	// array of polymorphic parameters
  soap_init(&soap);
  if (argc < 2)
  { soap_serve(&soap);
    soap_destroy(&soap);
    soap_end(&soap);
    return 0;
  }
  if (argc < 3)
  { p[0] = new xsd__anyURI((char*)endpoint);
    p[1] = new xsd__string(argv[1]);
    p[2] = new xsd__boolean(true);
    p[3] = new xsd__dateTime(time(NULL));
    p[4] = new xsd__double(1234567.89);
    p[5] = new xsd__base64Binary((char*)"encoded in base64");
    p[6] = new xsd__hexBinary((char*)"encoded in hex");
    p[7] = new array(4);
    (*p[7])[0] = new xsd__int(7);
    (*p[7])[1] = NULL;
    (*p[7])[2] = new xsd__token((char*)"x");
    (*p[7])[3] = p[1];
    p[8] = p[1];
    n = 9; // actual number of parameters
    if (soap_call_ns__varPolyParamTest(&soap, endpoint, "", n, p, r))
      soap_print_fault(&soap, stderr);
    else
    { std::cout << "Server has echoed:" << std::endl;
      for (int i = 0; i < r.__size; i++)
        r.param[i]->print(std::cout);
      std::cout << std::endl;
    }
    for (int i = 0; i < n; i++)
      delete p[i];
  }
  else
  { if (soap_call_ns__varStringParamTest(&soap, endpoint, "", argc, argv, n))
      soap_print_fault(&soap, stderr);
    else
      printf("Server has responded to %d strings\n", n);
  }
  soap_destroy(&soap);
  soap_end(&soap);
  soap_done(&soap);
  return 0;
}
Example #18
0
File: event.c Project: 119-org/TND
int main()
{ struct soap soap;
  soap_init2(&soap, SOAP_IO_KEEPALIVE, SOAP_IO_KEEPALIVE | SOAP_XML_INDENT);
  /* Events A to C do not generate a response from the server */
  fprintf(stderr, "Client Sends Event: A\n");
  if (soap_send_ns__handle(&soap, event_handler_endpoint, event_handler_action, EVENT_A))
    soap_print_fault(&soap, stderr);
  if (synchronous && soap_recv_empty_response(&soap))
    soap_print_fault(&soap, stderr);
  fprintf(stderr, "Client Sends Event: B\n");
  if (soap_send_ns__handle(&soap, event_handler_endpoint, event_handler_action, EVENT_B))
    soap_print_fault(&soap, stderr);
  if (synchronous && soap_recv_empty_response(&soap))
    soap_print_fault(&soap, stderr);
  /* reset keep-alive when client needs to inform the server that it will close the connection. It may reconnect later */
  soap_clr_omode(&soap, SOAP_IO_KEEPALIVE);
  fprintf(stderr, "Client Sends Event: C\n");
  if (soap_send_ns__handle(&soap, event_handler_endpoint, event_handler_action, EVENT_C))
    soap_print_fault(&soap, stderr);
  if (synchronous && soap_recv_empty_response(&soap))
    soap_print_fault(&soap, stderr);
  /* close the socket */
  soap_closesock(&soap);
  /* re-enable keep-alive which is required to accept and execute multiple receives */
  soap_set_omode(&soap, SOAP_IO_KEEPALIVE);
  /* Events Z generates a series of response from the server */
  fprintf(stderr, "Client Sends Event: Z\n");
  if (soap_send_ns__handle(&soap, event_handler_endpoint, event_handler_action, EVENT_Z))
    soap_print_fault(&soap, stderr);
  else
  { struct ns__handle response;
    for (;;)
    { if (!soap_valid_socket(soap.socket))
      { fprintf(stderr, "Connection was terminated (keep alive disabled?)\n");
        break;
      }
      if (soap_recv_ns__handle(&soap, &response))
      { if (soap.error == SOAP_EOF)
          fprintf(stderr, "Connection was gracefully closed by server\n");
        else
	  soap_print_fault(&soap, stderr);
	break;
      }
      else
      { switch (response.event)
        { case EVENT_A: fprintf(stderr, "Client Received Event: A\n"); break;
          case EVENT_B: fprintf(stderr, "Client Received Event: B\n"); break;
          case EVENT_C: fprintf(stderr, "Client Received Event: C\n"); break;
          case EVENT_Z: fprintf(stderr, "Client Received Event: Z\n"); break;
        }
      }
    }
  }
  soap_closesock(&soap); /* soap_send operations keep the socket open to possibly accept responses, so we need to explicitly close the socket now */
  soap_end(&soap); /* this will close the socket too (if keep alive is off), just in case */
  soap_done(&soap); /* detach environment (also closes sockets even with keep-alive) */
  return 0;
}
Example #19
0
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;
}
Example #20
0
//采用单播形式发送probe,发送会马上阻塞等待一个事件响应,事件参考event.c
//只能接收一个event,用于指定地址probe,比如手动添加IPC
static int probeUnicast(const char *endpoint, const char * types, const char *scopes,int timeout)
{
	struct soap *soap = soap_new1(SOAP_IO_UDP); // to invoke messages
	int ret;
	const char *id = soap_wsa_rand_uuid(soap);
	//设置超时时间,>0单位为秒 =0 用不超时 <0单位为微秒
	soap->accept_timeout = soap->recv_timeout = soap->send_timeout = timeout;
	ret = soap_wsdd_Probe(soap,
			  SOAP_WSDD_MANAGED,//SOAP_WSDD_ADHOC,	// ad-hoc mode
			  SOAP_WSDD_TO_TS,	// to a TS
			  endpoint, // address of TS; "soap.udp://239.255.255.250:3702"
			  id,	// message ID
			  NULL, // ReplyTo,表示回应的message ID,因为是主动回发起,所以没有,填NULL
			  types, //types,搜寻的设备类型"dn:NetworkVideoTransmitter tds:Device"
			  scopes,    //scopes,指定搜索范围,无填 NULL
			  NULL);   //match by,匹配规则,无填 NULL
	if(ret!=SOAP_OK)
	{
		soap_print_fault(soap, stderr);
		printf("soap_wsdd_Probe error,ret=%d\n",ret);
	}
	soap_end(soap);
	soap_free(soap);
	return ret;
}
Example #21
0
static void ProcessRequest(void *soap)
{
    int32_t Ret;
    struct soap *tsoap = (struct soap*)soap;

    //pthread_detach(pthread_self()); //guoqiang.lu mask,11/20/2013

    l_ThreadCnt++;

    Ret = soap_serve(tsoap);
    if (SOAP_OK != Ret
            && (tsoap->error != SOAP_EOF
                || (tsoap->errnum != 0 && !(tsoap->omode & SOAP_IO_KEEPALIVE))))
    {
        fprintf(stderr, "Thread %d completed with failure %d, Ret %d\n", \
                (int)(SOAP_SOCKET)tsoap->user, tsoap->error, Ret);
        DEBUG_LOG(g_DefaultLogClient, e_DebugLogLevel_Exception, "Thread %d completed with failure %d\n", (int)(SOAP_SOCKET)tsoap->user, tsoap->error);
        soap_print_fault(tsoap, stderr);
    }

    soap_destroy(tsoap);
    soap_end(tsoap);
    soap_done(tsoap);
    soap_free(tsoap);
    close((SOAP_SOCKET)tsoap->user);

    l_ThreadCnt--;

    ONVIF_INFO("======>%s %d exit, Total ThreadCnt %d\n", __func__, __LINE__, l_ThreadCnt);    
    //mask by guoqiang.lu,2014/1/8
    //pthread_exit(NULL);
}
Example #22
0
gchar *grisu_relative_job_dir(const gchar *jobname)
{
gchar *dir=NULL;
struct _ns1__calculateRelativeJobDirectory put;
struct _ns1__calculateRelativeJobDirectoryResponse get;

g_assert(jobname != NULL);

/* prereqs */
grisu_auth_set(TRUE);
grisu_auth_header();

put.in0 = g_strdup(jobname);

if (soap_call___ns1__calculateRelativeJobDirectory(&soap, ws, "", &put, &get) == SOAP_OK)
  {
  dir = get.out;
  }
else
  {
  printf("grisu_relative_job_dir(): SOAP ERROR\n");
  soap_print_fault(&soap, stderr);
  }

g_free(put.in0);

return(dir);
}
Example #23
0
GSList *grisu_job_names(void)
{
gint i;
struct _ns1__getAllJobnames put;
struct _ns1__getAllJobnamesResponse get;
struct ns1__ArrayOfString *out; 
GSList *list=NULL;

/* prereqs */
grisu_auth_set(TRUE);
grisu_auth_header();

if (soap_call___ns1__getAllJobnames(&soap, ws, "", &put, &get) == SOAP_OK)
  {
  out = get.out;
  for (i=out->__sizestring ; i-- ; )
    list = g_slist_prepend(list, g_strdup(out->string[i]));
  }
else
  {
  printf("grisu_job_names(): SOAP ERROR\n");
  soap_print_fault(&soap, stderr);
  }

return(list);
}
Example #24
0
/* currently unused */
gboolean grisu_mount(const gchar *mount_point, const gchar *url)
{
gint value;
struct _ns1__mount put;
struct _ns1__mountResponse get;

printf("*** GRISU WS - creating mountpoint ***\n");

g_assert(mount_point != NULL);
g_assert(url != NULL);

put.in0 = g_strdup(url);
put.in1 = g_strdup(mount_point);
put.in2 = 1;

/* prereqs */
grisu_auth_set(TRUE);
grisu_auth_header();

if (soap_call___ns1__mount(&soap, ws, "", &put, &get) == SOAP_OK)
  {
  value = TRUE;
  }
else
  {
  printf("grisu_mount(): SOAP ERROR\n");
  soap_print_fault(&soap, stderr);
  value = FALSE;
  }

g_free(put.in0);
g_free(put.in1);

return(value);
}
Example #25
0
GSList *grisu_file_list(const gchar *dir)
{
GSList *list=NULL;
struct _ns1__ls_USCOREstring put;
struct _ns1__ls_USCOREstringResponse get;

g_assert(dir != NULL);

put.in0 = g_strdup(dir);
put.in1 = 1;
put.in2 = 1;

/* prereqs */
grisu_auth_set(TRUE);
grisu_auth_header();

if (soap_call___ns1__ls_USCOREstring(&soap, ws, "", &put, &get) == SOAP_OK)
  {
  list = grisu_xml_parse(get.out);
  }
else
  {
  printf("grisu_file_list(): SOAP ERROR\n");
  soap_print_fault(&soap, stderr);
  }

g_free(put.in0);

return(list);
}
Example #26
0
GSList *grisu_application_versions(const gchar *name, const gchar *site)
{
gint i;
GSList *list=NULL;
struct _ns1__getVersionsOfApplicationOnSite put;
struct _ns1__getVersionsOfApplicationOnSiteResponse get;
struct ns1__ArrayOfString *out;

g_assert(name != NULL);
g_assert(site != NULL);

put.in0 = g_strdup(name);
put.in1 = g_strdup(site);

/* prereqs */
grisu_auth_set(TRUE);
grisu_auth_header();

if (soap_call___ns1__getVersionsOfApplicationOnSite(&soap, ws, "", &put, &get) == SOAP_OK)
  {
  out = get.out;
  for (i=out->__sizestring ; i-- ; )
    list = g_slist_prepend(list, g_strdup(out->string[i]));
  }
else
  {
  printf(" *** soap error ***\n");
  soap_print_fault(&soap, stderr); 
  }

g_free(put.in0);
g_free(put.in1);

return(list);
}
Example #27
0
GSList *grisu_submit_find(const gchar *name)
{
gint i;
GSList *list=NULL;
struct _ns1__getSubmissionLocationsForApplication put;
struct _ns1__getSubmissionLocationsForApplicationResponse get;
struct ns1__ArrayOfString *out;

g_assert(name != NULL);

/* prereqs */
grisu_auth_header();

put.in0 = g_strdup(name);

if (soap_call___ns1__getSubmissionLocationsForApplication(&soap, ws, "", &put, &get) == SOAP_OK)
  {
  out = get.out;
  for (i=out->__sizestring ; i-- ; )
    list = g_slist_prepend(list, g_strdup(out->string[i]));
  }
else
  {
  printf("grisu_submit_find(): soap error\n");
  soap_print_fault(&soap, stderr); 
  }

g_free(put.in0);

return(list);
}
Example #28
0
void grisu_job_remove(const gchar *name)
{
struct _ns1__kill put;
struct _ns1__killResponse get;

/* prereq */
g_assert(name != NULL);

grisu_auth_set(TRUE);
grisu_auth_header();

put.in0 = g_strdup(name);
/* TODO - true = delete files? if so implement a stop */
/* and a stop + cleanup */
put.in1 = 1;

if (soap_call___ns1__kill(&soap, ws, "", &put, &get) == SOAP_OK)
  {
//printf("Job deleted.\n");
  }
else
  {
  printf("grisu_job_remove(): SOAP ERROR\n");
  soap_print_fault(&soap, stderr);
  }

g_free(put.in0);

}
Example #29
0
GSList *grisu_site_list(void)
{
gint i;
GSList *list=NULL;
struct _ns1__getAllSites put;
struct _ns1__getAllSitesResponse get;
struct ns1__ArrayOfString *out;

/* prereqs */
grisu_auth_set(TRUE);
grisu_auth_header();

/* query WS for available sites */
if (soap_call___ns1__getAllSites(&soap, ws, "", &put, &get) == SOAP_OK)
  {
  out = get.out;
  for (i=out->__sizestring ; i-- ; )
    list = g_slist_prepend(list, g_strdup(out->string[i]));
  }
else
  {
  printf(" *** soap error ***\n");
  soap_print_fault(&soap, stderr); 
  }

return(list);
}
Example #30
0
GSList *grisu_fqans_get(void)
{
struct _ns1__getFqans put;
struct _ns1__getFqansResponse get;
GSList *list=NULL;

/* prereqs */
grisu_auth_set(TRUE);
grisu_auth_header();

if (soap_call___ns1__getFqans(&soap, ws, "", &put, &get) == SOAP_OK)
  {
  int i;
  struct ns1__ArrayOfString *out = get.out;

  for (i=0 ; i<out->__sizestring ; i++)
    {
    list = g_slist_prepend(list, g_strdup(out->string[i]));
//    printf("[%d] %s\n", i, out->string[i]);
    }
  }
else
  {
  printf("grisu_fqans_get(): SOAP ERROR\n");
  soap_print_fault(&soap, stderr);
  }

return(list);
}