/**
 * Initializes this task database
 *
 * @return	true if successful
 */
bool FTestTrackProvider::Init()
{
	TDLOG( TEXT( "TestTrack: Initializing TestTrack provider" ) );


	// Allocate SOAP interface to TestTrack Pro
	TestTrackSoap = new ttsoapcgi();
	check( TestTrackSoap != NULL );


	// @todo: Are there any other SOAP options we want to be configuring here?


	// Disable multi-referenced strings (href="#_12").  This makes the XML structures larger but
	// TestTrack doesn't support resolving graph references.  This effectively changes the graph
	// to a tree with duplicated strings where needed.
	soap_clr_omode( TestTrackSoap->soap, SOAP_XML_GRAPH );
	soap_set_omode( TestTrackSoap->soap, SOAP_XML_TREE );


	// Set timeouts for SOAP network I/O
	TestTrackSoap->soap->recv_timeout = 10000;		/* when > 0, gives socket recv timeout in seconds, < 0 in usec */
	TestTrackSoap->soap->send_timeout = 4000;		/* when > 0, gives socket send timeout in seconds, < 0 in usec */
	TestTrackSoap->soap->connect_timeout = 4000;	/* when > 0, gives socket connect() timeout in seconds, < 0 in usec */
	TestTrackSoap->soap->accept_timeout = 4000;		/* when > 0, gives socket accept() timeout in seconds, < 0 in usec */


	TDLOG( TEXT( "TestTrack: TestTrack provider finished initializing" ) );

	return true;
}
Beispiel #2
0
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;
}
Beispiel #3
0
std::ostream &operator<<(std::ostream &o, const MultiXTpm__ConfigData &p) 
{ 
	if (!p.soap) 
		return o; // need a gSOAP environment to serialize 

	std::ostream *os = p.soap->os; 
	p.soap->os = &o; 
	soap_omode(p.soap, SOAP_XML_GRAPH); // XML tree or graph 
	p.soap_serialize(p.soap); 
  soap_begin_send(p.soap); 
  p.soap_put(p.soap, "ConfigData", NULL);
	soap_end_send(p.soap);
	p.soap->os = os; 
	soap_clr_omode(p.soap, SOAP_XML_GRAPH); 
	return o; 
} 
Beispiel #4
0
int main()
{
  struct soap *ctx = soap_new1(SOAP_XML_INDENT);

  soap_set_namespaces(ctx, nosoap_nsmap);

  // a tree:
  Graph tree;
  // with 5 branches:
  for (int i = 0; i < 4; ++i)
  {
    Graph *branch = soap_new_Graph(ctx);
    tree.edges.push_back(branch);
    // each branch has a couple of leaves:
    for (int j = 0; j < i; ++j)
      branch->edges.push_back(soap_new_Graph(ctx));
  }

  std::cout << "**** XML TREE FROM C++ TREE ****" << std::endl;
  soap_write_Graph(ctx, &tree);
  std::cout << std::endl << std::endl;

  std::cout << "**** XML TREE FROM C++ DIGRAPH ****" << std::endl;
  tree.edges[0] = tree.edges[1]; // first pair of edges point to shared node
  tree.edges[2] = tree.edges[3]; // second pair of edges point to shared node
  soap_write_Graph(ctx, &tree);
  std::cout << std::endl << std::endl;

  std::cout << "**** XML ID-REF DIGRAPH FROM C++ DIGRAPH ****" << std::endl;
  soap_set_omode(ctx, SOAP_XML_GRAPH);
  soap_write_Graph(ctx, &tree);
  std::cout << std::endl << std::endl;
  soap_clr_omode(ctx, SOAP_XML_GRAPH);

  std::cout << "**** XML ID-REF DIGRAPH FROM C++ CYCLIC GRAPH ****" << std::endl;
  tree.edges[0]->edges = tree.edges;   // create cycle
  soap_set_omode(ctx, SOAP_XML_GRAPH);
  soap_write_Graph(ctx, &tree);
  std::cout << std::endl << std::endl;
  soap_clr_omode(ctx, SOAP_XML_GRAPH);

  std::cout << "**** XML TREE (PRUNED CYCLIC BRANCHES) FROM C++ CYCLIC GRAPH ****" << std::endl;
  soap_set_omode(ctx, SOAP_XML_TREE);
  soap_write_Graph(ctx, &tree);
  std::cout << std::endl << std::endl;
  soap_clr_omode(ctx, SOAP_XML_TREE);

  std::cout << "**** SOAP 1.1 ENCODED GRAPH FROM C++ CYCLIC GRAPH ****" << std::endl;
  soap_set_namespaces(ctx, soap11_nsmap);
  soap_set_version(ctx, 1);        // enable SOAP 1.1
  soap_write_Graph(ctx, &tree);
  std::cout << std::endl << std::endl;

  std::cout << "**** SOAP 1.2 ENCODED GRAPH FROM C++ CYCLIC GRAPH ****" << std::endl;
  soap_set_namespaces(ctx, soap12_nsmap);
  soap_set_version(ctx, 2);        // enable SOAP 1.2
  soap_write_Graph(ctx, &tree);
  std::cout << std::endl << std::endl;

  soap_destroy(ctx); // delete objects
  soap_end(ctx);     // free temp data
  soap_free(ctx);    // release context

  return 0;
}
Beispiel #5
0
messages_t* getMessages(struct soap* soap, char* date) {
   struct _ns1__messageResponseTypeDef* msgs = getMessage(soap, new_reqList(soap, "getMessageAll", "sent", "greaterthan", date));

   if (msgs) {
     int old_fd = soap->sendfd;
     messages_t* msg_t = NULL;

     msg_t = (messages_t*) malloc(sizeof(messages_t));
     if (!msg_t) {
       perror("Error converting alerts to text. Out of memory [0]");
       return NULL;
     }

     msg_t->size = msgs->__sizealert;
     msg_t->alerts = (char**) malloc(sizeof(char*)*(msg_t->size));
     if (!msg_t->alerts) {
       perror("Error converting alerts to text. Out of memory [1]");
       free(msg_t);
       return NULL;
     } 

     msg_t->ids = (char**) malloc(sizeof(char*)*(msg_t->size));
     if (!msg_t->ids) {
       perror("Error converting alerts to text. Out of memory [2]");
       free(msg_t->alerts);
       free(msg_t);
       return NULL;
     }

     msg_t->expires = (time_t**) malloc(sizeof(time_t*)*(msg_t->size));
     if (!msg_t->ids) {
       perror("Error converting alerts to text. Out of memory [3]");
       free(msg_t->ids);
       free(msg_t->alerts);
       free(msg_t);
       return NULL;
     }

     for (unsigned int i = 0; i < msg_t->size; i++) {
       msg_t->alerts[i] = NULL;
       msg_t->ids[i] = NULL;
       msg_t->expires[i] = NULL;
     }

     for (int i = 0; i < msgs->__sizealert; i++) {
       FILE* tmpf = tmpfile();
       struct stat stbuf;

       soap->sendfd = fileno(tmpf);
       soap_set_omode(soap, SOAP_ENC_XML);
       soap_begin_send(soap);
       soap_serialize__ns4__alert(soap, &(msgs->ns4__alert[i]));
       soap_put__ns4__alert(soap, &(msgs->ns4__alert[i]), NULL, NULL);
       soap_end_send(soap);
       soap_clr_omode(soap, SOAP_ENC_XML);
       soap->sendfd = old_fd;

       if ( fstat(fileno(tmpf), &stbuf) == -1 ) {
	 perror("Encountered error converting alert to text");
	 goto error_inconsistent_msg_t;
       }

       msg_t->alerts[i] = (char*) malloc(stbuf.st_size+1);
       if (msg_t->alerts[i]) {
	 rewind(tmpf);
	 if (fread(msg_t->alerts[i], stbuf.st_size, 1, tmpf) < 1) {
	   perror("Incomplete conversion of alert to text. Discarding");
	   free(msg_t->alerts[i]);
	   goto error_inconsistent_msg_t;
	 }
	 msg_t->alerts[i][stbuf.st_size] = '\0';
	 fclose(tmpf);

	 msg_t->ids[i] = strdup(msgs->ns4__alert[i].identifier);
	 if (!msg_t->ids[i]) {
	   perror("Incomplete conversion of alert to text, discarding");
	   free(msg_t->alerts[i]);
	   goto error_inconsistent_msg_t;
	 }

	 // Get the latest expiration date
	 for(int j = 0; j < msgs->ns4__alert[i].__sizeinfo; j++) {
	   if (msg_t->expires[i] == NULL) { // Don't alloc more than once
	     msg_t->expires[i] = malloc(sizeof(time_t));
	     if (msg_t->expires[i]) {
	       if (msgs->ns4__alert[i].info) {
		 if (msgs->ns4__alert[i].info[j].expires) {
		   *(msg_t->expires[i]) = *(msgs->ns4__alert[i].info[j].expires);
		 } else {
		   error(0, 0, "Allocated info doesn't have expires field");
		   free(msg_t->expires[i]);
		   msg_t->expires[i] = NULL;
		 } 
	       } else {
		 error(0, 0, "Despite the sizeinfo %d, no allocation at info %d", msgs->ns4__alert[i].__sizeinfo, j);
	       }
	     } else {
	       perror("Incomplete conversion of alert to text, discarding");
	       free(msg_t->alerts[i]);
	       free(msg_t->ids[i]);
	       goto error_inconsistent_msg_t;
	     }
	   } else {
	     if (difftime(*msg_t->expires[i],*(msgs->ns4__alert[i].info[j].expires)) < 0.) {
	       *(msg_t->expires[i]) = *(msgs->ns4__alert[i].info[j].expires);
	     }
	   }
	 }

	 // If there was no info block, make it expire in a week.
	 if (msg_t->expires[i] == NULL) {
	   msg_t->expires[i] = malloc(sizeof(time_t));
	   if (msg_t->expires[i])
	     *(msg_t->expires[i]) = msgs->ns4__alert[i].sent + 60*60*24*7;
	   else {
	     perror("Incomplete conversion of alert to text, discarding");
	     free(msg_t->alerts[i]);
	     free(msg_t->ids[i]);
	     goto error_inconsistent_msg_t;
	   }
	 }
       } else {
	 perror("Ran out of memory converting alert to text");
	 goto error_inconsistent_msg_t;
       }

       continue;
     error_inconsistent_msg_t:
       fclose(tmpf);
       if ( i > 0 ) {
	 msg_t->size = i;
	 return msg_t;
       } else {
	 perror("Unable to convert alerts to text [2]");
	 free(msg_t->expires);
	 free(msg_t->ids);
	 free(msg_t->alerts);
	 free(msg_t);
	 return NULL;
       }
     }

     return msg_t;
   } else {
     perror("Error retreiving alerts");
     return NULL;
   }
}