示例#1
0
文件: testSoap.c 项目: ohierro/gDrive
int __cdecl main1() {

	struct soap *soap = soap_new();
	//struct_ns1__getFilesResponse response;
	struct _ns1__getFilesResponse response;
	struct _ns1__getFiles request;

		
	request.path= "/";
	
	if (soap_call___ns1__getFiles(soap,NULL,NULL,&request,&response) == SOAP_OK) {	
		printf("Current IBM Stock Quote = %d\n", response.__sizegetFilesReturn); 
		if (response.__sizegetFilesReturn > 0) {
			int i = 0;
			for (i=0; i<response.__sizegetFilesReturn; i++) {		
				if (response.getFilesReturn[i].attributes & 2)
					printf("D");
				else
					printf(" ");
				
				printf(" %s\n", response.getFilesReturn[i].name); 
			}
		}
		
	} else {
		char buffer[1024];
		soap_sprint_fault(soap,buffer,1024);
		printf("%s",buffer);
	}
		
	return 0;
}
示例#2
0
SoapException::SoapException(soap * s) :
    code_(-1)
{
    if (s != NULL) {
        char buf[1024];
        soap_sprint_fault(s, buf, sizeof(buf));
        message().assign(buf);

        code_ = s->errnum;
    }
}
示例#3
0
void CSoapUtils::setSoapErrorInfo(const int retCode, struct soap* psoap, CBaseRetInfo* retInfo)
{
	if (NULL == retInfo)
		return;
	retInfo->setRetCode(retCode);
	if (psoap->error) {
		char st[255];
		memset(st, 0, 255);
		soap_sprint_fault(psoap, st, 255);
		retInfo->setMessage(st);
	}
}
示例#4
0
// WS_QUERY_BY_KEY (CLIENT SIDE)
void audioDB::ws_query_by_key(const char*dbName, const char *trackKey, const char* featureFileName, const char* hostport){
  struct soap soap;
  adb__queryResponse adbQueryResponse;  
  /*  JUST TRY TO USE A DATA STRUCTURE WITH PHP
      adb__sequenceQueryParms asqp;
      asqp.keyList = (char*)trackFileName;
      asqp.timesFileName = (char*)timesFileName;
      asqp.queryPoint = queryPoint;
      asqp.pointNN = pointNN;
      asqp.trackNN = trackNN;
      asqp.sequenceLength = sequenceLength;
      asqp.radius = radius;
      asqp.relative_threshold = relative_threshold;
      asqp.absolute_threshold = absolute_threshold;
      asqp.usingQueryPoint = usingQueryPoint;
      asqp.lsh_exact = lsh_exact;
  */
  VERB_LOG(1, "Calling %s query on database %s with %s=%s\n", (trackKey&&strlen(trackKey))?"KEY":"FILENAME", dbName, (trackKey&&strlen(trackKey))?"KEY":"FILENAME",(trackKey&&strlen(trackKey))?trackKey:featureFileName);
  soap_init(&soap);  
  if(queryType==O2_SEQUENCE_QUERY || queryType==O2_N_SEQUENCE_QUERY){
    if(soap_call_adb__sequenceQueryByKey(&soap,hostport,NULL,
					 (char*)dbName,
					 (char*)trackKey,
					 (char*)featureFileName,
					 queryType,
					 (char*)trackFileName, // this means keyFileName 
					 (char*)timesFileName,
					   queryPoint,
					 pointNN,
					 trackNN,
					 sequenceLength,
					 radius,
					 absolute_threshold,
					 usingQueryPoint,
					 lsh_exact,
					 no_unit_norming,
					 adbQueryResponse)==SOAP_OK){
      //std::std::cerr << "result list length:" << adbQueryResponse.result.__sizeRlist << std::std::endl;
      for(int i=0; i<adbQueryResponse.result.__sizeRlist; i++)
	std::cout << adbQueryResponse.result.Rlist[i] << " " << adbQueryResponse.result.Dist[i] 
		  << " " << adbQueryResponse.result.Qpos[i] << " " << adbQueryResponse.result.Spos[i] << std::endl;
    } else {
      char fault[MAXSTR];
      soap_sprint_fault(&soap, fault, MAXSTR);
      error(fault);
    }
  } else
    ;// FIX ME: WRITE NON-SEQUENCE QUERY BY KEY ?
  
  soap_destroy(&soap);
  soap_end(&soap);
  soap_done(&soap);
}
示例#5
0
void audioDB::ws_liszt(const char* dbName, char* Hostport){
  struct soap soap;
  adb__lisztResponse adbLisztResponse;

  soap_init(&soap);
  if(soap_call_adb__liszt(&soap, hostport, NULL, (char*)dbName, lisztOffset, lisztLength, adbLisztResponse)==SOAP_OK){
    for(int i = 0; i < adbLisztResponse.result.__sizeRkey; i++) {
      std::cout << "[" << i+lisztOffset << "] " << adbLisztResponse.result.Rkey[i] << " (" 
		<< adbLisztResponse.result.Rlen[i] << ")" << std::endl;
    }
  } else {
    char fault[MAXSTR];
    soap_sprint_fault(&soap, fault, MAXSTR);
    error(fault);
  }
  soap_destroy(&soap);
  soap_end(&soap);
  soap_done(&soap);
}
示例#6
0
void 
setErrorString(struct bes_context *context, 
               struct soap *s, 
               int error_code)
{
    switch (error_code) {
    case BESE_SOAP_ERR:
        soap_sprint_fault(s, context->error_string, MAX_ERRSTR_LEN);
        break;
        
    case BESE_SYS_ERR:
        snprintf(context->error_string, MAX_ERRSTR_LEN, "System error: %s", strerror(errno));
        break;
        
    case BESE_ENDPOINT_ERR:
        snprintf(context->error_string, MAX_ERRSTR_LEN, "%s", BESE_ENDPOINT_STRING);
        break;
        
    case BESE_MEM_ALLOC:
        snprintf(context->error_string, MAX_ERRSTR_LEN, "%s", BESE_MEM_STRING);
        break;
        
    case BESE_GETSTATUS_ERR:
        snprintf(context->error_string, MAX_ERRSTR_LEN, "%s", BESE_GETSTATUS_STRING);
        break;
        
    case BESE_BAD_ARG:
        snprintf(context->error_string, MAX_ERRSTR_LEN, "%s", BESE_BAD_ARG_STRING);
        break;
        
    case BESE_UNSUPPORTED:
        snprintf(context->error_string, MAX_ERRSTR_LEN, "%s", BESE_UNSUPPORTED_STRING);
        break;

    case BESE_XML_FORMAT:
        snprintf(context->error_string, MAX_ERRSTR_LEN, "%s", BESE_XML_FORMAT_STRING);
        break;

    default:
        break;
    }
}
示例#7
0
int BfcpService::run( int port )
{
  isRunning_ = true;
  char buf[1024];
  if (soap_valid_socket(this->master) || soap_valid_socket(bind(NULL, port, 100)))
  {	
    while (isRunning_)
    {
      if (!soap_valid_socket(accept()))
      {
        soap_sprint_fault(buf, sizeof buf);
        buf[sizeof(buf)-1] = '\0';
        LOG_WARN << buf;
        continue;
      }
      serve();
      soap_destroy(this);
      soap_end(this);
    }
  }
  return this->error;
}
示例#8
0
// FIXME: this can't propagate the sequence length argument (used for
// dudCount).  See adb__status() definition for the other half of
// this.  -- CSR, 2007-10-01
void audioDB::ws_status(const char*dbName, char* hostport){
  struct soap soap;
  adb__statusResponse adbStatusResponse;  
  
  // Query an existing adb database
  soap_init(&soap);
  if(soap_call_adb__status(&soap,hostport,NULL,(char*)dbName,adbStatusResponse)==SOAP_OK) {
    std::cout << "numFiles = " << adbStatusResponse.result.numFiles << std::endl;
    std::cout << "dim = " << adbStatusResponse.result.dim << std::endl;
    std::cout << "length = " << adbStatusResponse.result.length << std::endl;
    std::cout << "dudCount = " << adbStatusResponse.result.dudCount << std::endl;
    std::cout << "nullCount = " << adbStatusResponse.result.nullCount << std::endl;
    std::cout << "flags = " << (adbStatusResponse.result.flags & 0x00FFFFFF) << std::endl;
  } else {
    char fault[MAXSTR];
    soap_sprint_fault(&soap, fault, MAXSTR);
    error(fault);
  }
  
  soap_destroy(&soap);
  soap_end(&soap);
  soap_done(&soap);
}
示例#9
0
// WS_QUERY (CLIENT SIDE)
void audioDB::ws_query(const char*dbName, const char *featureFileName, const char* hostport){
  struct soap soap;
  adb__queryResponse adbQueryResponse;  
  VERB_LOG(1, "Calling fileName query on database %s with featureFile=%s\n", dbName, featureFileName);
  soap_init(&soap);
  if(soap_call_adb__query(&soap, hostport, NULL, (char *) dbName,
			  (char *)featureFileName, (char *)trackFileName,
			  (char *)timesFileName, (char *) powerFileName,
			  queryType, queryPoint, 
			  pointNN, trackNN, sequenceLength, 
			  radius, absolute_threshold, relative_threshold,
			  !usingQueryPoint, lsh_exact, no_unit_norming,
			  adbQueryResponse) 
     == SOAP_OK) {
    if(radius == 0) {
      for(int i=0; i<adbQueryResponse.result.__sizeRlist; i++) {
	std::cout << adbQueryResponse.result.Rlist[i] << " "
		  << adbQueryResponse.result.Dist[i] << " "
		  << adbQueryResponse.result.Qpos[i] << " " 
		  << adbQueryResponse.result.Spos[i] << std::endl;
      }
    } else {
      for(int i = 0; i < adbQueryResponse.result.__sizeRlist; i++) {
	std::cout << adbQueryResponse.result.Rlist[i] << " " 
		  << adbQueryResponse.result.Spos[i] << std::endl;
      }
    }
  } else {
    char fault[MAXSTR];
    soap_sprint_fault(&soap, fault, MAXSTR);
    error(fault);
  }

  soap_destroy(&soap);
  soap_end(&soap);
  soap_done(&soap);
}
示例#10
0
/**
 * Do the delegation
 * @param handle     The handle
 * @param url        The delegation endpoint
 * @param err_buffer Used to build the error string
 * @return NULL on failure, or an allocated string with the delegation ID
 */
static char *htext_delegate(htext_handle *handle, char *url, char *err_buffer)
{
  char                               *delegation_id = NULL;
  char                               *reqtxt  = NULL, *certtxt = NULL;
  char                               *keycert = NULL;
  struct soap                        *soap_get = NULL, *soap_put = NULL;
  struct tns__getNewProxyReqResponse  getNewProxyReqResponse;
  char                               *ucert = NULL, *ukey = NULL, *capath = NULL;
  int                                 lifetime;

  /* Get from the handle */
  ucert    = GETSTR(handle, HTEXTOP_USERCERTIFICATE);
  ukey     = GETSTR(handle, HTEXTOP_USERPRIVKEY);
  capath   = GETSTR(handle, HTEXTOP_CAPATH);
  lifetime = GETINT(handle, HTEXTOP_PROXYLIFE);

  /* Only one is needed if they are the same */
  if (ucert && !ukey) ukey  = ucert;
  if (!ucert && ukey) ucert = ukey;

  /* Cert and key need to be in the same file */
  if (strcmp(ucert, ukey) == 0) {
    keycert = strdup(ucert);
  }
  else {
    FILE *ifp, *ofp;
    int   fd;
    char  c;

    keycert = strdup("/tmp/.XXXXXX");

    fd = mkstemp(keycert);
    ofp = fdopen(fd, "w");

    ifp = fopen(ukey, "r");
    while ((c = fgetc(ifp)) != EOF) fputc(c, ofp);
    fclose(ifp);

    ifp = fopen(ukey, "r");
    while ((c = fgetc(ifp)) != EOF) fputc(c, ofp);
    fclose(ifp);

    fclose(ofp);
  }

  /* Initialize SSL */
  ERR_load_crypto_strings ();
  OpenSSL_add_all_algorithms();

  /* Request a new delegation ID */
  soap_get = soap_new();

  if (soap_ssl_client_context(soap_get, SOAP_SSL_DEFAULT, keycert, "",
                              NULL, capath, NULL) == 0) {
    soap_call_tns__getNewProxyReq(soap_get,
                                  url,
                                  "http://www.gridsite.org/namespaces/delegation-1",
                                  &getNewProxyReqResponse);

    if(soap_get->error == 0) {
      reqtxt        = getNewProxyReqResponse.getNewProxyReqReturn->proxyRequest;
      delegation_id = strdup(getNewProxyReqResponse.getNewProxyReqReturn->delegationID);

      /* Generate proxy */
      if (GRSTx509MakeProxyCert(&certtxt, stderr, reqtxt,
                                ucert, ukey, lifetime) == GRST_RET_OK) {
        /* Submit the proxy */
        soap_put = soap_new();

        if (soap_ssl_client_context(soap_put, SOAP_SSL_DEFAULT, keycert, "",
                              NULL, capath, NULL) == 0) {
            soap_call_tns__putProxy(soap_put,
                          url,
                          "http://www.gridsite.org/namespaces/delegation-1",
                          delegation_id, certtxt, NULL);
            if (soap_put->error) {
              /* Could not PUT */
#ifndef NO_SOAP_SPRINT
              soap_sprint_fault(soap_put, err_buffer, sizeof(err_buffer));
              htext_error(handle, err_buffer);
#else
              soap_print_fault(soap_put, stderr);
              handle->status = HTEXTS_FAILED;
#endif
            }
        }
        else { /* soap_put ssl error */
#ifndef NO_SOAP_SPRINT
          soap_sprint_fault(soap_put, err_buffer, sizeof(err_buffer));
          htext_error(handle, err_buffer);
#else
          soap_print_fault(soap_put, stderr);
          handle->status = HTEXTS_FAILED;
#endif
        }

        soap_free(soap_put);
      }
      else {
        htext_error(handle, "Could not generate the proxy");
      }
    }
    else { /* Could not get ID */
#ifndef NO_SOAP_SPRINT
      soap_sprint_fault(soap_get, err_buffer, sizeof(err_buffer));
      htext_error(handle, err_buffer);
#else
      soap_print_fault(soap_get, stderr);
      handle->status = HTEXTS_FAILED;
#endif
    }
  }
  else { /* soap_get ssl error */
#ifndef NO_SOAP_SPRINT
    soap_sprint_fault(soap_get, err_buffer, sizeof(err_buffer));
    htext_error(handle, err_buffer);
#else
    soap_print_fault(soap_put, stderr);
    handle->status = HTEXTS_FAILED;
#endif
  }

  /* Clean soap_get */
  soap_free(soap_get);
  free(keycert);
  free(certtxt);
  
  /* Return delegation ID */
  return delegation_id;
}
示例#11
0
/*
 * This loop listens to incoming Soap reuests and forwards them to HtiDispatcher
 */
void DataGatewaySOAPServerThread::Run()
{
	struct soap soap;
 	//Initializes a static/stack-allocated runtime environment 
	soap_init(&soap);
	//soap_init2(&soap, SOAP_IO_KEEPALIVE, SOAP_IO_KEEPALIVE);
	//_CrtDbgReport(_CRT_ERROR, _CRTDBG_MODE_WNDW);
/*
#ifdef _DEBUG
   HANDLE hLogFile;
   hLogFile = CreateFile("c:\\log.txt", GENERIC_WRITE, FILE_SHARE_WRITE,
      NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
   _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE);
   _CrtSetReportFile(_CRT_WARN, hLogFile);

#endif
*/
	while (m_Running)
	{
		int m, s; // master and slave sockets
		Util::Debug("soap_init");

		//Returns master socket (backlog = max. queue size for requests). When host==NULL: host is the machine on which the service runs 
		m = soap_bind(&soap, NULL, m_TcpPort, 100);
		if (m < 0)
		{
			//Util::Error("Failed to open socket", m_TcpPort);
			//soap_print_fault(&soap, stderr);
			char temp[512];
			soap_sprint_fault(&soap, temp);
			Util::Error(temp);
			break;
		}
		else
		{
			Util::Debug("Socket connection successful");
/*
#ifdef _DEBUG
			_CrtMemState startMem, endMem, diffMem;
			//Sleep(5000);
#endif
*/
			for (int i = 1; ; i++)
			{
				//_RPT1(_CRT_WARN, "---++++=======Iter %d=======++++---\n", i);
				//_RPT0(_CRT_WARN, "---Start dump---\n");

				//_CrtMemCheckpoint(&startMem);
				//_CrtMemDumpStatistics(&startMem);
				//Returns slave socket
				s = soap_accept(&soap);
				if (s < 0)
				{
					//soap_print_fault(&soap, stderr);
					char temp[512];
					soap_sprint_fault(&soap, temp);
					Util::Error(temp);

					break;
				}
				Util::Debug(" accepted connection");

				//start of my dispatching code
				if ( !m_HtiDispatcher->DispatchSoapServe( &soap ) ) // process RPC request
				{
					//soap_print_fault(&soap, stderr); // print error
					// clean up class instances
					soap_destroy(&soap);
					// clean up everything and close socket
					soap_end(&soap); 
				}
				else
				{
					// clean up allcated data
					soap_dealloc(&soap, NULL);
					// clean up class instances
					soap_destroy(&soap); 
					//cleanup temp data
					soap_free(&soap); 

					//soap_end(&soap); // clean up everything and close socket
				}
/*
#ifdef _DEBUG
				//Sleep(2000); //wait when hadler thread is over

				//copy
				memcpy( &startMem, &endMem, sizeof(_CrtMemState) );
				_CrtMemCheckpoint(&endMem);
				_CrtMemDumpStatistics(&endMem);

				_RPT0(_CRT_WARN, "==========End diff==========\n");

				if (_CrtMemDifference( &diffMem, &startMem, &endMem ) )
				{

					_CrtMemDumpStatistics(&diffMem);
					_RPT0(_CRT_WARN, "########## Objects #############\n");
					//_CrtMemDumpAllObjectsSince( &diffMem );
					_RPT0(_CRT_WARN, "++++++End dump++++++\n");
				}
#endif
*/
				Util::Debug("request dispatched");
			}
		}
	}
	// Clean up deserialized data (except class instances) and temporary data 
	soap_end(&soap);
	// close master socket and detach environment
	soap_done(&soap); 
	Stop();
//#ifdef _DEBUG
//   CloseHandle(hLogFile);
//#endif
}