예제 #1
0
int 
main(int           const argc, 
     const char ** const argv) {

    xmlrpc_env env;
    xmlrpc_value * resultP;
    xmlrpc_int32 sum;
    const char * const serverUrl = "http://localhost:8080/RPC2";
    const char * const serverUrl2 = "http://localhost:8081/RPC2";
    const char * const serverUrl3 = "http://localhost:8082/RPC2";
    const char * const methodName = "sample.add";

    if (argc-1 > 0) {
        fprintf(stderr, "This program has no arguments\n");
        exit(1);
    }

    /* Initialize our error-handling environment. */
    xmlrpc_env_init(&env);

    /* Start up our XML-RPC client library. */
    xmlrpc_client_init2(&env, XMLRPC_CLIENT_NO_FLAGS, NAME, VERSION, NULL, 0);
    dieIfFaultOccurred(&env);

    printf("Making XMLRPC call to server url '%s' method '%s' "
           "to request the sum "
           "of 5 and 7...\n", serverUrl, methodName);

    /* Make the remote procedure call */
    resultP = xmlrpc_client_call(&env, methodName, "(sssii)", 1, 3, serverUrl, serverUrl2, serverUrl3, 
				(xmlrpc_int32) 5, (xmlrpc_int32) 7);
    dieIfFaultOccurred(&env);
    
    /* Get our sum and print it out. */
    xmlrpc_read_int(&env, resultP, &sum);
    dieIfFaultOccurred(&env);
    printf("The sum is %d\n", sum);
    
    /* Dispose of our result value. */
    xmlrpc_DECREF(resultP);

    /* Clean up our error-handling environment. */
    xmlrpc_env_clean(&env);
    
    /* Shutdown our XML-RPC client library. */
    xmlrpc_client_cleanup();

    return 0;
}
예제 #2
0
xmlrpc_value *
server_status(xmlrpc_env * envP, struct call_info *cip, char ** statusp)
{
  xmlrpc_value *resultP = NULL;
  struct client_method_info *cmi = NULL;
  struct meths_tab *meth = NULL;
  struct call_info *cip_status = callinfo_clone(cip);

  cip_status->files = NULL;
  cip_status->methodargs = NULL;
  cip_status->method = "status";
  if (!(meth = meths(cip_status->method, strlen(cip_status->method))))
    {
      fprintf(stderr, "oracc-client: unknown method name `%s'\n", cip_status->method);
      exit(1);
    }

  cmi = meth->info;
  meth->info->instance = cip_status;
  resultP = cmi->call(envP, cmi);
  dieIfFaultOccurred(envP);

  if (resultP)
    {
      char *str = NULL;
      xmlrpc_value *status = NULL;
      xmlrpc_struct_find_value(envP, resultP, "method-status", &status);
      if (status)
	{
	  trace();
	  xmlrpc_read_string(envP, status, (const char **)&str);
	  /* This diagnostic needs to be suppressable */
	  fprintf(stderr, "server-status: status=%s\n", str);
	  *statusp = NULL;
	  if (!strcmp(str, "completed"))
	    return resultP;
	}
      else
	{
	  fprintf(stderr, "!server-status: no method-status\n");
	  *statusp = "no method status returned by status request";
	  /* should return an error condition to caller here
	     so that when server bombs/loses session client can 
	     terminate gracefully */
	}
    }
  else
    *statusp = "!no result from status request";

  /* Dispose of our result value. */
  xmlrpc_DECREF(resultP);
  
  return NULL;
}
예제 #3
0
파일: result.c 프로젝트: oracc/oracc
char *
result_request_status(xmlrpc_env *envP, xmlrpc_value *s)
{
    char *str = NULL;
    if (s)
    {
        xmlrpc_value *status = NULL;
        xmlrpc_struct_find_value(envP, s, "status", &status);
        dieIfFaultOccurred(envP);
        if (status)
            xmlrpc_read_string(envP, status, (const char **)&str);
    }
    return str;
}
예제 #4
0
int 
main(int           const argc, 
     const char ** const argv) {

    if(argc < 2 )
    {
    fprintf(stderr,"Usage : ./client <Semantics> <No of Servers>\n");
    exit(EXIT_FAILURE);
    }

    const char const **serverUrl;
    int i = 0, port = 8080 ;
    xmlrpc_env env;
    xmlrpc_value * resultP;
    int nUrl = atoi(argv[2]);
    struct timeval start,end,diff;

    if(nUrl == 0)
    {
    fprintf(stderr,"Please enter non-zero number of servers\n");
    exit(EXIT_FAILURE);
    }

#if 0  
    serverUrl = (char **) malloc (nUrl * sizeof(char*));
    for(i = 0 ; i < nUrl ; i++){
    serverUrl[i] = (char *) malloc(50 * sizeof(char));
    sprintf(serverUrl[i],"http://localhost:%d/RPC2",port++);
    }
#endif

#if 1
    serverUrl = malloc(sizeof(char*) * 5);
    serverUrl[0] = "http://localhost:8080/RPC2";
    serverUrl[1] = "http://localhost:8081/RPC2";
    serverUrl[2] = "http://localhost:8082/RPC2";
    serverUrl[3] = "http://localhost:8083/RPC2";
    serverUrl[4] = "http://localhost:8084/RPC2"; 
#endif    
    const char * const methodName = "calculate_modexp";
    //const char * const serverUrl = "http://localhost:8080/RPC2";
    /* Initialize our error-handling environment. */
    xmlrpc_env_init(&env);

    /* Start up our XML-RPC client library. */
    xmlrpc_client_init2(&env, XMLRPC_CLIENT_NO_FLAGS, NAME, VERSION, NULL, 0);
    dieIfFaultOccurred(&env);

 //    printf("Making XMLRPC call to server url '%s' method '%s' "           "to request the sum "           "of 5 and 7...\n", serverUrl, methodName);

    /* Make the remote procedure call */
   // printf("Result is : %d\n",xmlrpc_validate_utf8("Hello World"));
   xmlrpc_value *arr = xmlrpc_array_new(&env);
        
   //resultP = xmlrpc_client_call(&env, serverUrl, methodName,"(A)", generate_request_array(&env , arr) );
   gettimeofday(&start,NULL);
   /*Call the server*/
   resultP = xmlrpc_client_call_multi_sync(atoi(argv[1]),nUrl, &env, serverUrl, methodName,"(A)", generate_request_array(&env , arr));	

   gettimeofday(&end,NULL);
   difference(&diff,end,start);
   
   printf("Time Taken With %d Server = %ld:%ld\n",nUrl,diff.tv_usec/1000000,diff.tv_usec%1000000);
  // printf("Check to see if killed\n");
   dieIfFaultOccurred(&env);
    
    /* Get our sum and print it out. */
   //xmlrpc_read_int(&env, resultP, &primeResult);
   // xmlrpc_env *   const dummy;
  // printf("Extracting Results\n");
   const char* result = extract_result ( &env , resultP);    

   dieIfFaultOccurred(&env);

  // printf("2^p/m = %s\n", result);
   
   /*Dispose of our result value. */
   xmlrpc_DECREF(resultP);

    /* Clean up our error-handling environment. */
   xmlrpc_env_clean(&env);
    
    /* Shutdown our XML-RPC client library. */
   xmlrpc_client_cleanup();

   return 0;
}
예제 #5
0
int 
main(int           const argc, 
     const char ** const argv) {

    xmlrpc_env env;
    xmlrpc_value * resultP;
    xmlrpc_int32 number_of_links;
    const char * const serverUrl = "http://localhost:4567/RPC2";
    const char * const methodName = "get_number_of_links";

    if (argc-1 > 0) {
        fprintf(stderr, "This program has no arguments\n");
        exit(1);
    }

    /* Initialize our error-handling environment. */
    xmlrpc_env_init(&env);

    /* Start up our XML-RPC client library. */
    xmlrpc_client_init2(&env, XMLRPC_CLIENT_NO_FLAGS, NAME, VERSION, NULL, 0);
    dieIfFaultOccurred(&env);

    printf("Making XMLRPC call to server url '%s' method '%s'\n", serverUrl, "get_number_of_links");

    /* Make the remote procedure call */
    resultP = xmlrpc_client_call(&env, serverUrl, "get_number_of_links",
                                 "(i)", (xmlrpc_int32) 1);
    dieIfFaultOccurred(&env);
    
    /* Get our sum and print it out. */
    xmlrpc_read_int(&env, resultP, &number_of_links);
    dieIfFaultOccurred(&env);
    printf("Number of links defined: %d\n", number_of_links);
    
    /* Dispose of our result value. */
    xmlrpc_DECREF(resultP);

    /* Make the remote procedure call */
    resultP = xmlrpc_client_call(&env, serverUrl, "get_links",
                                 "(i)", (xmlrpc_int32) 1);
    dieIfFaultOccurred(&env);

    int array_size =xmlrpc_array_size(&env, resultP);
    while(array_size>0) {
    	--array_size;
    	xmlrpc_value *value;
    	const char *link;
    	xmlrpc_array_read_item(&env, resultP, 0, &value);
    	xmlrpc_read_string(&env, value, &link);
    	printf("Link %u: %s\n", array_size, link);
    	xmlrpc_DECREF(value);
    }
    xmlrpc_DECREF(resultP);

	/* Make the remote procedure call */
	resultP = xmlrpc_client_call(&env, serverUrl, "add_target", "(i)",
			(xmlrpc_int32) 1);

	xmlrpc_int64 targetID = 0;
    xmlrpc_read_i8(&env, resultP, &targetID);

    if(targetID) {
    	printf("New target added with ID: %"PRIx64"\n", targetID);
    } else {
    	printf("Failed to add new target!\n");
    	goto done;
    }
    xmlrpc_DECREF(resultP);

	/* Make the remote procedure call */
	resultP = xmlrpc_client_call(&env, serverUrl, "remove_target", "(i)",
			(xmlrpc_int64) targetID);

	xmlrpc_int32 res;
    xmlrpc_read_int(&env, resultP, &res);
    printf("Target %"PRIx64" remove: %"PRIx32"\n", targetID, res);

    done:
    xmlrpc_DECREF(resultP);

    /* Clean up our error-handling environment. */
    xmlrpc_env_clean(&env);
    
    /* Shutdown our XML-RPC client library. */
    xmlrpc_client_cleanup();

    return 0;
}