Ejemplo n.º 1
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;
}
Ejemplo n.º 2
0
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;
}
Ejemplo n.º 3
0
void grisu_auth_header(void)
{
/* CURRENT - fixing crappy windows soap failure */
/* WINDOWS seems to require a reinit EVERY time - or it forgets stuff and soap calls fail */
/* TODO - test if this bollocks up linux or not ... */
soap_init1(&soap, SOAP_ENC_MTOM);

if (soap_ssl_client_context(&soap, SOAP_SSL_SKIP_HOST_CHECK, NULL, NULL, NULL, grisu_cert_path, NULL))
  printf("grisu_auth_header(): SSL init failed.\n");

/* allocate if necessary */
if (!grisu_soap_header)
  grisu_soap_header = g_malloc(sizeof(struct SOAP_ENV__Header));

/* fill out the header with current values */
grisu_soap_header->username = grisu_username;
grisu_soap_header->password = grisu_password;
grisu_soap_header->myproxyserver = grisu_server;
grisu_soap_header->myproxyport = grisu_port;

#if DEBUG_GRISU_AUTH_HEADER
printf("SOAP Header:      ptr = %p\n", grisu_soap_header);
printf("SOAP Header: username = %s\n", grisu_soap_header->username);
printf("SOAP Header: password = %s\n", grisu_soap_header->password);
printf("SOAP Header:   server = %s\n", grisu_soap_header->myproxyserver);
printf("SOAP Header:     port = %s\n", grisu_soap_header->myproxyport);
#endif

/* use the header if auth is turned on */
if (grisu_auth)
  soap.header = grisu_soap_header;
else
  soap.header = NULL;
}
int main(int argc, char **argv)
{ struct soap soap;
  double a, b, result;
  if (argc < 4)
  { fprintf(stderr, "Usage: [setAuto] num[Sentido] num[Direccion]\n");
    exit(0);
  }
  soap_init1(&soap, SOAP_XML_INDENT);
  a = strtod(argv[2], NULL);
  b = strtod(argv[3], NULL);
  switch (*argv[1])
  { case 's':
      soap_call_ns__setAuto(&soap, server, "", a, b, &result);
      break;
    default:
      fprintf(stderr, "Unknown command\n");
      exit(0);
  }
  if (soap.error)
  { soap_print_fault(&soap, stderr);
    exit(1);
  }
  else
    printf("result = %g\n", result);
  soap_destroy(&soap);
  soap_end(&soap);
  soap_done(&soap);
  return 0;
}
Ejemplo n.º 5
0
int save_options(const char *file, const char *name, struct option *options)
{ struct soap soap;
  soap_init1(&soap, SOAP_XML_TREE);
  soap.namespaces = NULL;
  soap.encodingStyle = NULL;
  if (file)
  { soap.sendfd = open(file, O_CREAT | O_WRONLY);
    if (soap.sendfd < 0)
    { soap_done(&soap);
      return EOF;
    }
  }
  if (!soap_begin_send(&soap) && !soap_element_begin_out(&soap, name, 0, NULL))
  { struct option *p;
    struct t__Option t;
    for (p = options; p->name; p++)
    { t.val = NULL;
      if (!p->name[0])
      { if (!p->value)
          continue;
	t.key = NULL;
	t.val = p->value;
      }
      else if (p->name[1] == '.')
        t.key = (char*)p->name + 2;
      else
        t.key = (char*)p->name;
      if (p->selections && strchr(p->selections, ' '))
      { const char *s = p->selections - 1;
        char *r;
	int i;
        for (i = p->selected; i > 0; i--)
        { s = strchr(s + 1, ' ');
	  if (!s)
	    break;
	}
        if (s)
	{ t.val = soap_strdup(&soap, s + 1);
          r = strchr(t.val, ' ');
	  if (r)
	    *r = '\0';
        }
      }
      else if (p->value)
        t.val = p->value;
      else if (!p->selected)
        continue;
      if (soap_out_t__Option(&soap, "option", 0, &t, NULL))
        break;
    }
    if (!soap_element_end_out(&soap, name))
      soap_end_send(&soap);
  }
  if (file)
    close(soap.sendfd);
  soap_end(&soap);
  soap_done(&soap);
  return soap.error;
}
Ejemplo n.º 6
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; 
}
Ejemplo n.º 7
0
int run_client(int argc, char **argv)
{ struct soap soap;
  int ret = 0;
#ifdef WITH_GZIP
  soap_init1(&soap, SOAP_ENC_MTOM | SOAP_ENC_ZLIB); /* Enable MTOM */
#else
  soap_init1(&soap, SOAP_ENC_MTOM); /* Enable MTOM */
#endif
  /* Set the MIME callbacks */
  soap.fmimereadopen = mime_read_open;
  soap.fmimereadclose = mime_read_close;
  soap.fmimeread = mime_read;
  soap.fmimewriteopen = mime_client_write_open;
  soap.fmimewriteclose = mime_client_write_close;
  soap.fmimewrite = mime_client_write;
  /* Connect timeout value (sec) (not supported by Linux) */
  soap.connect_timeout = 10;
  /* IO timeouts (sec) */
  soap.send_timeout = 30;
  soap.recv_timeout = 30;
  /* 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)
  */
  switch (argv[1][1])
  { case 'p':
      ret = client_putData(&soap, argc, argv);
      break;
    case 'g':
      ret = client_getData(&soap, argc, argv);
      break;
    default:
      fprintf(stderr, "Usage: mtom-stream-test -p file1 file2 file3 ...\n");
      fprintf(stderr, "       mtom-stream-test -g key1 key2 key3 ...\n");
  }
  soap_destroy(&soap);
  soap_end(&soap);
  soap_done(&soap);
  return ret;
}
int main(int argc, char **argv)
{ struct soap soap;
  // use HTTP 1.1 chunking
  // HTTP chunking allows streaming of DIME content without requiring DIME attachment size to be set
  // DIME attachments can be streamed without chunking ONLY if the attachment size is set
  soap_init1(&soap, SOAP_IO_CHUNK);
  // set DIME callbacks
  soap.fdimereadopen = dime_read_open;
  soap.fdimereadclose = dime_read_close;
  soap.fdimeread = dime_read;
  soap.fdimewriteopen = dime_write_open;
  soap.fdimewriteclose = dime_write_close;
  soap.fdimewrite = dime_write;
  // connect timeout value (not supported by Linux)
  soap.connect_timeout = 10;
  // IO timeouts
  soap.send_timeout = 30;
  soap.recv_timeout = 30;
  // 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 (portable)
  if (argc < 3)
  { char *name;
    if (argc < 2)
      name = "image.jpg";
    else
      name = argv[1];
    getImage(&soap, name);
  }
  else
  { switch (argv[1][1])
    { case 'p':
	endpoint = localhost;
        putData(&soap, argc, argv);
        break;
      case 'g':
	endpoint = localhost;
        getData(&soap, argc, argv);
        break;
      default:
        fprintf(stderr, "Usage: [-p] [-g] name ...\n");
	exit(0);
    }
  }
  soap_destroy(&soap);
  soap_end(&soap);
  soap_done(&soap);
  return SOAP_OK;
}
Ejemplo n.º 9
0
int main()
{ struct soap soap;
  init_received();
  soap_init1(&soap, SOAP_IO_UDP);
  if (!soap_valid_socket(soap_bind(&soap, NULL, 10000, 100)))
  { soap_print_fault(&soap, stderr);
    exit(1);
  }
  for (;;)
  { printf("Accepting requests...\n");
    if (soap_serve(&soap))
      soap_print_fault(&soap, stderr);
    soap_destroy(&soap);
    soap_end(&soap);
  }
  soap_done(&soap);
  return 0;
}
Ejemplo n.º 10
0
int main(int argc, char * argv[]) {
	SOAP_SOCKET m, s;
	struct soap soap;

	soap_init1(&soap, SOAP_IO_UDP);

	m = soap_bind(&soap, NULL,  PORT, 100);
 	/* reuse address */
 	soap.bind_flags = SO_REUSEADDR;
	if (!soap_valid_socket(m)) {
		soap_print_fault(&soap, stderr);
		exit(-1);
	}
	/* optionally join a multicast group */
	if (MULTICAST_GROUP) { 
		struct ip_mreq mreq;
		mreq.imr_multiaddr.s_addr = inet_addr(MULTICAST_GROUP);
		mreq.imr_interface.s_addr = htonl(INADDR_ANY);
		if (setsockopt(soap.socket, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq)) < 0) {
			printf("setsockopt failed\n");
	      		exit(-1);
		}
	}
	printf("socket bind success %d\n", m);
	for (;;) {
		printf("socket connect %d\n", s);
		s = soap_accept(&soap);
		if (!soap_valid_socket(s)) {
			soap_print_fault(&soap, stderr);
			exit(-1);
		}
		if (soap_serve(&soap) != SOAP_OK) {
			soap_print_fault(&soap, stderr);
		}
		soap_destroy(&soap);
		soap_end(&soap);
		
	}

	soap_done(&soap);
	return 0;
}
Ejemplo n.º 11
0
int main(int argc, char **argv)
{ struct soap soap;
  double a, b, result;
  if (argc < 4)
  { fprintf(stderr, "Usage: [add|sub|mul|div|pow] num num\n");
    exit(0);
  }
  soap_init1(&soap, SOAP_XML_INDENT);
  a = strtod(argv[2], NULL);
  b = strtod(argv[3], NULL);
  switch (*argv[1])
  { case 'a':
      soap_call_ns__add(&soap, server, "", a, b, &result);
      break;
    case 's':
      soap_call_ns__sub(&soap, server, "", a, b, &result);
      break;
    case 'm':
      soap_call_ns__mul(&soap, server, "", a, b, &result);
      break;
    case 'd':
      soap_call_ns__div(&soap, server, "", a, b, &result);
      break;
    case 'p':
      soap_call_ns__pow(&soap, server, "", a, b, &result);
      break;
    default:
      fprintf(stderr, "Unknown command\n");
      exit(0);
  }
  if (soap.error)
  { soap_print_fault(&soap, stderr);
    exit(1);
  }
  else
    printf("result = %g\n", result);
  soap_destroy(&soap);
  soap_end(&soap);
  soap_done(&soap);
  return 0;
}
Ejemplo n.º 12
0
int main(int argc, char * argv[]) {
	SOAP_SOCKET m, s;
	struct soap soap;

	soap_init1(&soap, SOAP_ENC_MTOM);


	m = soap_bind(&soap, NULL, PORT, 100);
	if (!soap_valid_socket(m)) {
		soap_print_fault(&soap, stderr);
		exit(-1);
	}

	printf("socket bind success %d\n", m);

	soap.fmimewriteopen = mime_server_write_open;
	soap.fmimewriteclose = mime_server_write_close;
	soap.fmimewrite = mime_server_write;

	for (;;) {
		printf("socket connect %d\n", s);
		s = soap_accept(&soap);
		if (!soap_valid_socket(s)) {
			soap_print_fault(&soap, stderr);
			exit(-1);
		}
		if (soap_serve(&soap) != SOAP_OK) {
			soap_print_fault(&soap, stderr);
		}
		soap_destroy(&soap);
		soap_end(&soap);

	}

	soap_done(&soap);
	return 0;
}
Ejemplo n.º 13
0
int soap_parser_decode(void *handle, const char *xml)
{
    SoapParser *parser = (SoapParser *)handle;
    struct soap *soap;
    int fd[2];

    if (parser == NULL) {
        return -1;
    }
    if (xml == NULL) {
        LOGE(LOG_TAG, "input xml is empty");
        return -1;
    }

    soap = parser->soap;
    pipe(fd);

    /*soap_init(soap);*/
    soap_init1(soap, SOAP_XML_IGNORENS);
    soap_set_namespaces(soap, namespaces);

    soap->socket = -1;
    soap->recvfd = fd[0];
    write(fd[1], xml, strlen(xml));
    close(fd[1]);

    if (soap_begin_recv(soap) != 0
        || soap_envelope_begin_in(soap) != 0) {
        LOGE(LOG_TAG, "begin decode failed, error=%d", soap->error);
        return -1;
    }

    if (soap_recv_header(soap) != 0) {
        LOGE(LOG_TAG, "decode soap header failed, %d", soap->error);
        return -1;
    }
    _soap_header_parse(soap->header,
                       &(parser->id),
                       &(parser->hold_requests),
                       &(parser->session_timeout),
                       &(parser->supported_cwmp_versions),
                       &(parser->use_cwmp_version));

    if (soap_body_begin_in(soap) != 0) {
        LOGE(LOG_TAG, "decode soap body failed, %d", soap->error);
        return -1;
    }

    parser->_namespaces = _soap_namespaces_parse(soap);
    parser->namespaces = parser->_namespaces;
    parser->version = _soap_version_parse(xml, parser->namespaces);
    if (parser->version == CWMP_VERSION_1_2) {
        if (parser->supported_cwmp_versions != 0 && parser->use_cwmp_version != 0) {
            parser->version = CWMP_VERSION_1_4;
        } else if (parser->session_timeout > 0) {
            parser->version = CWMP_VERSION_1_3;
        }
    }

    if (soap_recv_fault(soap, 1) != 0) {
        parser->type = CWMP_MSG_FAULT;
        _soap_fault_dump(soap->fault);
        if (soap->fault != NULL
            && soap->fault->detail != NULL
            && soap->fault->detail->__type == SOAP_TYPE__cwmp__Fault) {
            struct _cwmp__Fault *cwmp_fault;
            cwmp_fault = (struct _cwmp__Fault *)soap->fault->detail->fault;
            if (cwmp_fault != NULL) {
                if (cwmp_fault->FaultCode != NULL) {
                    parser->fault_code = atoi(cwmp_fault->FaultCode);
                }
                parser->fault_string = cwmp_fault->FaultString;
                parser->fault_body = cwmp_fault;
                parser->body = cwmp_fault;
            }
        }
        return 0;
    }

    int gsoap_type;
    parser->body = soap_getelement(soap, &gsoap_type);
    parser->type = _get_cwmp_type(gsoap_type);
    if (soap->error) {
        LOGE(LOG_TAG, "get cwmp body failed, error=%d", soap->error);
        return -1;
    }

    if (soap_body_end_in(soap)
        || soap_envelope_end_in(soap)
        || soap_end_recv(soap)) {
        LOGE(LOG_TAG, "end decode failed, %d", soap->error);
        return -1;
    }
    close(fd[0]);

    return 0;
}
/**
 * Constructor for DataLocationInterface
 *
 * @param endpoint SOAP endpoint (URL) of the remote catalogue
 *                 example: http://localhost:8085/
 */
dli::DataLocationInterfaceSOAP::DataLocationInterfaceSOAP()
  : m_ctx(0)
{
  soap_init1(&m_soap, SOAP_IO_KEEPALIVE); // SOAP_IO_KEEPALIVE/SOAP_IO_CHUNK
  m_soap.namespaces = datalocationinterface_namespaces;
}
Ejemplo n.º 15
0
gpointer onvif_discovery_server_thread_func(gpointer data)
{
    IpcamIOnvifDiscovery *ionvif_discovery = IPCAM_IONVIF_DISCOVERY(data);
	SOAP_SOCKET m, s;
	struct soap soap;

	soap_init1(&soap, SOAP_IO_UDP);

    soap.user = ionvif_discovery;
    /* reuse address */
 	soap.bind_flags = SO_REUSEADDR;

	m = soap_bind(&soap, NULL,  ONVIF_DISCOVERY_PORT, 100);
    if (!soap_valid_socket(m)) {
		soap_print_fault(&soap, stderr);
		exit(-1);
	}

    /* optionally join a multicast group */
	if (ONVIF_MULTICAST_GROUP) {
        struct ifaddrs *ifaddr, *ifa;
        if (getifaddrs(&ifaddr) == -1) {
            perror("getifaddrs");
            exit(-1);
        }
        for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) {
            if (ifa->ifa_addr == NULL)
                continue;
            int family = ifa->ifa_addr->sa_family;
            if ((family == AF_PACKET) && (ifa->ifa_flags & IFF_MULTICAST)) {
                struct ifreq ifr;
                struct ip_mreqn mreqn;

                strncpy(ifr.ifr_name, ifa->ifa_name, IFNAMSIZ);
                if (ioctl(soap.socket, SIOCGIFINDEX, &ifr)) {
                    perror("ioctl");
                    continue;
                }
                mreqn.imr_multiaddr.s_addr = inet_addr(ONVIF_MULTICAST_GROUP);
                mreqn.imr_address.s_addr = htonl(INADDR_ANY);
                mreqn.imr_ifindex = ifr.ifr_ifindex;
                if (setsockopt(soap.socket, IPPROTO_IP,
                               IP_ADD_MEMBERSHIP,
                               &mreqn, sizeof(mreqn)) < 0) {
                    perror("setsockopt failed:");
                    continue;
                }
                printf("Add %s to multicast group\n", ifa->ifa_name);
            }
        }
        freeifaddrs(ifaddr);
	}

    for (;;) {
		s = soap_accept(&soap);
		if (!soap_valid_socket(s)) {
			soap_print_fault(&soap, stderr);
			exit(-1);
		}
		if (soap_serve(&soap) != SOAP_OK) {
			soap_print_fault(&soap, stderr);
		}
		soap_destroy(&soap);
		soap_end(&soap);
		
	}

	soap_done(&soap);
	return 0;
}
Ejemplo n.º 16
0
int main(int argc, char *argv[])
{
    long_t     master;
    int32_t    Signal;
    GMI_RESULT Result = GMI_SUCCESS;
    struct soap soap;
    sigset_t   NewMask;
    sigset_t   OldMask;
    struct sigaction Sa;

    //signal
    Sa.sa_handler = SignalHandler;
    sigfillset(&Sa.sa_mask);
    Sa.sa_flags = SA_NOMASK;
    sigemptyset(&NewMask);
    for (Signal = 1; Signal <= _NSIG; ++Signal)
    {
        if ( ( Signal == SIGIO )
                || ( Signal == SIGPOLL )
                || ( Signal == SIGINT )
                || ( Signal == SIGQUIT )
                || ( Signal == SIGHUP )
                || ( Signal == SIGPIPE )
                || ( Signal == SIGSEGV )
           )
        {
            sigaction(Signal, &Sa, NULL);
        }
        else
        {
            sigaddset(&NewMask, Signal);
        }
    }
    sigprocmask(SIG_BLOCK, &NewMask, &OldMask);

    //get debug opt
    const char_t *OptString = "ei";
    struct option Opts[] = {
    		{"error", no_argument, NULL, 'e'},
    		{"info", no_argument, NULL, 'i'},
    		{0, 0, 0, 0},
    	};
    int C;
    boolean_t ErrLog  = false;
    boolean_t InfoLog = false;
    while ((C = getopt_long(argc, argv, OptString, Opts, NULL)) != -1)
    {    	
    	switch (C)
    	{
    	case 'e':
    		ErrLog = true;
    		break;
    	case 'i':
    		InfoLog = true;
    		break;
    	default:
    		break;
    	}    
    	printf("opts:%d:%d\n", ErrLog, InfoLog);
    }
    //log init    
    Result = LogInitial(ErrLog, InfoLog);
    if (FAILED(Result))
    {
        ONVIF_ERROR("LogInitial fail, Result = 0x%lx\n", Result);
        return Result;
    }    
    
    //daemon register to daemon server
    Result = DaemonRegister();
    if (FAILED(Result))
    {
        ONVIF_ERROR("DaemonRegister fail, Result = 0x%lx\n", Result);
        DEBUG_LOG(g_DefaultLogClient, e_DebugLogLevel_Exception, " DaemonRegister fail, Result = 0x%lx\n", Result);
        return Result;
    }    

    //system initial
    Result = SysInitialize(GMI_ONVIF_AUTH_PORT);
    if (FAILED(Result))
    {
        DaemonUnregister();
        ONVIF_ERROR("SysInitialize fail, Result = 0x%lx\n", Result);
        DEBUG_LOG(g_DefaultLogClient, e_DebugLogLevel_Exception, " SysInitialize fail, Result = 0x%lx\n", Result);
        return Result;
    }

    //get onvif port, rtsp port
    uint16_t SessionId = 0;
    uint32_t AuthValue = 0;
    SysPkgNetworkPort SysNetworkPort;
    Result = SysGetNetworkPort(SessionId, AuthValue, &SysNetworkPort);
    if (FAILED(Result))
    {
    	g_ONVIF_Port = DEFAULT_SERVER_PORT;
    	g_RTSP_Port  = DEFAULT_RTSP_PORT;
    	ONVIF_ERROR("SysGetNetworkPort fail, Result = 0x%lx\n", Result);
    }
    else
    {
    	g_ONVIF_Port = SysNetworkPort.s_ONVIF_Port;
    	g_RTSP_Port  = SysNetworkPort.s_RTSP_Port;
    }
    ONVIF_INFO("ONVIF_Port %d, RTSP_Port %d\n", g_ONVIF_Port, g_RTSP_Port);
    
    //ptz service
    __tptz__Initialize();

    //soap server init
    soap_init1(&soap, SOAP_ENC_MTOM);
    soap.socket_flags    = MSG_NOSIGNAL;
    soap.accept_flags   |= SO_LINGER;
    soap.connect_flags  |= SO_LINGER;
    soap.linger_time     = 2;
    soap.bind_flags      = SO_REUSEADDR;
    soap.send_timeout    = 2;
    soap.recv_timeout    = 2;
    soap.accept_timeout  = 10;
    soap.connect_timeout = 10;
    soap.keep_alive      = 5;
    soap_set_mode(&soap, SOAP_C_UTFSTRING);
    master = soap_bind(&soap, NULL, g_ONVIF_Port, 30);
    if (!soap_valid_socket(master))
    {
        ONVIF_ERROR("soap_bind fail, Result = 0x%lx\n", Result);
        DEBUG_LOG(g_DefaultLogClient, e_DebugLogLevel_Exception, " soap_bind fail, Result = 0x%lx\n", Result);
        soap_print_fault(&soap, stderr);
        SysDeinitialize();
        DaemonUnregister();
        exit(1);
    }

    //main server start
    ServerLoop(&soap);

    ONVIF_INFO("soap_end start\n");
    //soap release
    soap_end(&soap);
    soap_done(&soap);
    ONVIF_INFO("soap_end stop\n");

	//ptz deinitialize
    __tptz__Deinitialize();
    ONVIF_INFO("SysDeinitialize start\n");
    SysDeinitialize();
    ONVIF_INFO("SysDeinitialize end\n");
    ONVIF_INFO("DaemonUnregister start\n");
    //daemon unregister
    DaemonUnregister();
    ONVIF_INFO("DaemonUnregister end\n");

    return 0;
}
Ejemplo n.º 17
0
////////////////////////////////////////////////////////////////////////////////
//
//	Main
//
////////////////////////////////////////////////////////////////////////////////
int main(int argc, char **argv)
{

	(void) signal(SIGINT, signalhandler_func);

#if 1
	struct soap soap;
	char *s = getenv("TMPDIR");
	if (s)
		TMPDIR = s;
	// use HTTP chunking when possible
	// chunking allows streaming of DIME content without requiring DIME attachment size to be set
	// DIME attachments can be streamed without chunking only if the attachment size is set
	soap_init1(&soap, SOAP_IO_KEEPALIVE | SOAP_IO_CHUNK);
	// set DIME callbacks
	soap.fdimereadopen = dime_read_open;
	soap.fdimereadclose = dime_read_close;
	soap.fdimeread = dime_read;
	soap.fdimewriteopen = dime_write_open;
	soap.fdimewriteclose = dime_write_close;
	soap.fdimewrite = dime_write;


#ifdef _POSIX_THREADS
	pthread_t tid;
#endif
	struct soap *tsoap;
	int port = 8085;
	int m, sk, i;


	if (soap_ssl_server_context(&soap,
								SOAP_SSL_DEFAULT | SOAP_SSL_SKIP_HOST_CHECK,	/* use SOAP_SSL_REQUIRE_CLIENT_AUTHENTICATION to verify clients: client must provide a key file e.g. "client.pem" and "password" */
								"server.pem",	/* keyfile (cert+key): see README.txt to create this file */
								"password",		/* password to read the private key in the key file */
								"cacert.pem",	/* cacert file to store trusted certificates (to authenticate clients), see README.txt */
								NULL,		/* capath */
								"dh2048.pem",	/* DH file name or DH param key len bits in string (e.g. "2048"), if NULL then RSA with 2048 bits is used instead (bits defined by SOAP_SSL_RSA_BITS) */
								NULL,		/* if randfile!=NULL: use a file with random data to seed randomness */
								"sslserver"		/* server identification for SSL session cache (unique server name, e.g. use argv[0]) */
								))
	{
		soap_print_fault(&soap, stderr);
		exit(1);
	}



	// Unix 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 (portable)

	// port is first command line argument
	//port = atoi(argv[1]);
	// bind to current host and specified port
	m = soap_bind(&soap, NULL, port, BACKLOG);
	// if we could not bind, exit
	if (m < 0)
	{ soap_print_fault(&soap, stderr);
		exit(1);
	}

	fprintf(stderr, "Socket connection successful %d, port %d \n", m, port);
	// die after 24 hrs waiting for activity on port
	soap.accept_timeout = 24*60*60;
	// IO timeouts
	soap.send_timeout = 30;
	soap.recv_timeout = 30;
	// loop through requests
	//for (i = 1; ; i++)
	while(is_main_running)
	{ // accept request
		sk = soap_accept(&soap);
		// if timeout or error, report
		if (sk < 0)
		{ if (soap.errnum)
				soap_print_fault(&soap, stderr);
			else
				fprintf(stderr, "Server timed out\n");
			break;
		}

		fprintf(stderr, "Thread %d accepts socket %d connection from IP %d.%d.%d.%d\n", i, s, (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 (if Pthreads is installed)
		tsoap = soap_copy(&soap);
#ifdef _POSIX_THREADS
		pthread_create(&tid, NULL, (void*(*)(void*))process_request, (void*)tsoap);
#else
		process_request((void*)tsoap);
#endif
	}

	// detach
	soap_done(&soap);

#endif

	return 0;
}
Ejemplo n.º 18
0
int grisu_init(void)
{
gint value=0;
const gchar *home;

/* soap setup */
//soap_init(&soap);
/* enable MTOM for file xfer -> attachment/streaming */
soap_init1(&soap, SOAP_ENC_MTOM);

/* grisu init */
if (!grisu_username)
  grisu_username = grid_random_alpha(10);
if (!grisu_password)
  grisu_password = grid_random_alphanum(12);
if (!grisu_server)
  grisu_server=g_strdup("myproxy.arcs.org.au");

// FIXME - sometimes needed when myproxy plays up also might need to setenv
// MYPROXY_SERVER_DN = /C=AU/O=APACGrid/OU=VPAC/CN=myproxy2.arcs.org.au
//  grisu_server=g_strdup("myproxy2.arcs.org.au");

if (!grisu_port)
  grisu_port=g_strdup("7512");


/* certificate path init */
home = g_get_home_dir();
if (home)
  grisu_cert_path = g_build_filename(home, ".globus", "certificates", NULL);
if (!g_file_test(grisu_cert_path, G_FILE_TEST_IS_DIR))
  {
  printf("ERROR in grisu_init(), bad certificate location: %s\n", grisu_cert_path);
  g_free(grisu_cert_path);

/* don't return if no certs - we can soldier on */
/* as it's only myproxy-init that won't work */
  grisu_cert_path=NULL;
  }

#if DEBUG_GRISU_CLIENT
printf("Using certificate location: %s\n", grisu_cert_path);
#endif

/* use SOAP_SSL_DEFAULT in production code */
/* keyfile: required only when client must authenticate to server */
/* password to read the keyfile */
/* optional cacert file to store trusted certificates */
/* optional capath to directory with trusted certificates */
/* if randfile!=NULL: use a file with random data to seed randomness */ 
/*
if (soap_ssl_client_context(&soap, SOAP_SSL_NO_AUTHENTICATION, NULL, NULL, NULL, NULL, NULL))
*/

/* CURRENT - to verify server we use the standard (CA signed) certificates */

/* CURRENT - if no certs is this secure? */
/*
if (soap_ssl_client_context(&soap, SOAP_SSL_DEFAULT, NULL, NULL, NULL, path, NULL))
*/


/* CURRENT - this has to be done before all calls anyway ... */
/* create header for soap struct with grisu authentication info */
/*
grisu_auth_header();
*/

/*
if (soap_ssl_client_context(&soap, SOAP_SSL_SKIP_HOST_CHECK, NULL, NULL, NULL, path, NULL))
  { 
  soap_print_fault(&soap, stderr);
  value = 1;
  }
else
  {
#if DEBUG_GRISU_CLIENT
  printf("Requiring secure context.\n");
#endif
  }
*/

return(value);
}