コード例 #1
0
ファイル: client.c プロジェクト: tudor1805/azure
int main(int argc, char *argv[])
{
    SoapCtx *req, *resp;
    herror_t err;
    
    err = soap_client_init_args(argc, argv);
    if (err != H_OK) {
        log_error4("%s():%s [%d]", herror_func(err),
                    herror_message(err), herror_code(err));
        herror_release(err);
        return 1;
    }

    err = soap_ctx_new_with_method(urn, "computePi", &req);
    if (err != H_OK) {
        log_error4("%s():%s [%d]", herror_func(err),
                    herror_message(err), herror_code(err));
        herror_release(err);
        return 1;
    }
    
    soap_env_add_item(req->env, "xsd:decimal", "precision", "10000");

    if (argc > 1)
        err = soap_client_invoke(req, &resp, argv[1], "");
    else
        err = soap_client_invoke(req, &resp, url, "");

    if (err != H_OK) {
        log_error4("[%d] %s(): %s ", herror_code(err), herror_func(err),
                   herror_message(err));
        herror_release(err);
        soap_ctx_free(req);
        return 1;
    }

    soap_xml_doc_print(resp->env->root->doc);
    soap_ctx_free(resp);
    soap_ctx_free(req);

    soap_client_destroy();

    return 0;
}
コード例 #2
0
ファイル: soap.c プロジェクト: stiks/iteliecd
int iteliec_soap_init (char *hash) {
    herror_t err;
    SoapCtx *request;
    SoapCtx *response;

    char url[1024];
    int error;

    xmlNodePtr function, node;

    /* ----------------------------------- */
    /*    Initialize SOAP Client           */
    /* ----------------------------------- */
    err = soap_client_init_args(0, NULL);
    if (err != H_OK)  {
        err_soap (err);
        
        return 1;
    }

    /* ----------------------------------- */
    /*    Create "request" envelope        */
    /* ----------------------------------- */
    err = soap_ctx_new_with_method ("", "setSystem", &request);
    if (err != H_OK) {
        err_soap(err);
        soap_client_destroy();

        return 1;
    }

    /* ----------------------------------- */
    /*    Create header element            */
    /* ----------------------------------- */

    //xmlDocFormatDump(stdout, request->env->header->doc,1);

    /* ----------------------------------- */
    /*    Start collecting data            */
    /* ----------------------------------- */
    iteliec_get_host_info (&request->env);
    iteliec_get_user_info (&request->env);
    iteliec_get_load_info (&request->env);
    iteliec_get_process_info (&request->env);
    iteliec_get_process_list (&request->env);
    iteliec_get_memory_info (&request->env);
    iteliec_get_swap_info (&request->env);
    iteliec_get_cpu_info (&request->env);

    iteliec_get_fs_info (&request->env);
    iteliec_get_disk_info (&request->env);

    iteliec_get_iface_info (&request->env);
    iteliec_get_network_info (&request->env);

    /* ----------------------------------- */
    /*    Trade for "response" envelope    */
    /* ----------------------------------- */
    sprintf (url, "http://api.iteliec.com/system/update/ws/?token=%s", hash);
    err = soap_client_invoke (request, &response, url, "");
    if (err != H_OK)  {
        err_soap(err);
        soap_ctx_free(request);
        soap_client_destroy();
        
        return ITELIEC_ERR;
    }

    function = soap_env_get_method (response->env);
    node = soap_xml_get_children (function);

    parseResponse (node->doc, node);

    /* ----------------------------------- */
    /*    Show "response" envelope          */
    /* ----------------------------------- */
/*
    xmlDocFormatDump(stdout, response->env->root->doc,1);
*/

    /* ----------------------------------- */
    /*    Destroy SOAP Client              */
    /* ----------------------------------- */
    soap_ctx_free(request);
    soap_ctx_free(response);
    soap_client_destroy();

    return 0;
}
コード例 #3
0
ファイル: soap.c プロジェクト: stiks/iteliecd
int iteliec_soap_register (char *username, char *password) {
    herror_t err;
    SoapCtx *request;
    SoapCtx *response;

    config_t cfg;
    config_setting_t *setting, *root;
    const char *cfile;

    cfile = iteliec_config_file ();
    
    config_init (&cfg);

    /* Read the file. If there is an error, report it and exit. */
    if (!config_read_file (&cfg, cfile)) {
        iteliec_log (ITELIEC_ERR, "Please ensure configuration file %s exists and is valid", cfile);
        //printf ("\n%s:%d - %s", config_error_file (&cfg), config_error_line (&cfg), config_error_text (&cfg));
        
        config_destroy (&cfg);
        
        return;
    }

    root = config_root_setting (&cfg);

    /* Init */
    err = soap_client_init_args (0, NULL);
    if (err != H_OK)  {
        err_soap (err);
        
        return ITELIEC_ERR;
    }

    err = soap_ctx_new_with_method ("", "sendAuth", &request);
    if (err != H_OK) {
        err_soap (err);
        soap_client_destroy ();

        return ITELIEC_ERR;
    }

    /* Add login details */
    soap_env_add_item (request->env, "xsd:string", "username", username);
    soap_env_add_item (request->env, "xsd:string", "password", password);

    /* Trade for response */
    err = soap_client_invoke (request, &response, "http://api.iteliec.com/register/auth/ws/", "");
    if (err != H_OK)  {
        err_soap (err);
        soap_ctx_free (request);
        soap_client_destroy ();
        
        return ITELIEC_ERR;
    }

    /* Parse response */
    auth_type* ret = parse_auth_response (response);
    if (ret->auth == true) {
        printf ("Success\n");
        
        setting = config_setting_get_member (root, "api");
        if(!setting) {
            setting = config_setting_add (root, "api", CONFIG_TYPE_GROUP);        
        }

        setting = config_setting_add (setting, "hash", CONFIG_TYPE_STRING);
        config_setting_set_string (setting, ret->token);

        /* Write out the updated configuration. */
        if(! config_write_file(&cfg, cfile)) {
            fprintf (stderr, "Error while writing file.\n");
            config_destroy (&cfg);
            
            return (ITELIEC_OK);
        }

        printf("\nConfiguration file updated. Server is ready to run.\n");

    } else {
        printf("Auth failed\n");
    }

    /* Destroy */
    soap_ctx_free (request);
    soap_ctx_free (response);
    
    soap_client_destroy ();
    config_destroy (&cfg);

    return ITELIEC_OK;
}
コード例 #4
0
ファイル: opcxmlda_client.cpp プロジェクト: daveti/pvbaddon
int main(int argc, char *argv[])
{
  SoapCtx *ctx, *ctx2;
  herror_t err;
  char *url,*method,*arg;
  int i;

  /* check the command line parameters */
  if(argc < 3)
  {
    printusage(argv[0]);
    return 1;
  }
  arg = argv[0];
  strcpy(startme,arg);
  for(i=1; i<argc; i++)
  {
    arg = argv[i];
    strcat(startme," ");
    strcat(startme,arg);
  }
  url    = argv[1];
  method = argv[2];
  for(i=3; i<argc; i++)
  {
    arg = argv[i];
    if(strlen(arg) <= MAX_PATH_LENGTH)
    {
      if(strncmp(arg,"-itemlist=",10) == 0)
      {
        sscanf(arg,"-itemlist=%s",itemlist);
      }
      if(strncmp(arg,"-shm=",5) == 0)
      {
        sscanf(arg,"-shm=%s",shm);
      }
      if(strncmp(arg,"-mbx=",5) == 0)
      {
        sscanf(arg,"-mbx=%s",mbx);
      }
      if(strncmp(arg,"-sleep=",7) == 0)
      {
        sscanf(arg,"-sleep=%d",&sleep);
        if(sleep < 10) sleep = 10;
      }
      if(strncmp(arg,"-max_name_length=",17) == 0)
      {
        sscanf(arg,"-max_name_length=%d",&max_name_length);
        if(max_name_length < 31) max_name_length = 31;
      }
      if(strncmp(arg,"-shmsize=",8) == 0)
      {
        sscanf(arg,"-shmsize=%ld",&shmsize);
        if(shmsize < 1) shmsize = 1;
      }
      if(strcmp(arg,"-debug") == 0)
      {
        debug = 1;
      }
    }
    else
    {
      printf("%s is too long.\n", arg);
      return 1;
    }
  }

  /* init cSOAP client */
  err = soap_client_init_args(argc, argv);
  if (err != H_OK)
  {
    log_error4("%s():%s [%d]", herror_func(err),
               herror_message(err), herror_code(err));
    herror_release(err);
    return 1;
  }

  if(strcmp(method,"GetStatus") == 0)
  {
    /* create a SoapCtx object */
    printf("soap_ctx_new_with_method(%s,\"GetStatus\")\n", URN);
    err = soap_ctx_new_with_method(URN, "GetStatus", &ctx);
    if (err != H_OK)
    {
      printf("err != H_OK\n");
      log_error4("%s():%s [%d]", herror_func(err),
                 herror_message(err), herror_code(err));
      herror_release(err);
      return 1;
    }

    /* invoke */
    printf("soap_client_invoke(\"%s\")\n", url);
    err = soap_client_invoke(ctx, &ctx2, url, "");
    if (err != H_OK)
    {
      printf("err != H_OK\n");
      log_error4("[%d] %s(): %s ", herror_code(err),
                 herror_func(err), herror_message(err));
      herror_release(err);
      soap_ctx_free(ctx);
      return 1;
    }

    /* print the result */
    soap_xml_doc_print(ctx2->env->root->doc);

    /* free the objects */
    printf("soap_ctx_free()\n");
    soap_ctx_free(ctx2);
    soap_ctx_free(ctx);

    /* destroy the cSOAP client */
    printf("soap_client_destroy()\n");
    soap_client_destroy();

    return 0;
  }
  else if(strcmp(method,"Browse") == 0)
  {
    printf("#%s %s %s\n",argv[0],url,method);
    printf("#\n");

    /* create a SoapCtx object */
    err = soap_ctx_new_with_method(URN, "Browse", &ctx);
    if (err != H_OK)
    {
      log_error4("%s():%s [%d]", herror_func(err),
                 herror_message(err), herror_code(err));
      herror_release(err);
      return 1;
    }

    /* invoke */
    err = soap_client_invoke(ctx, &ctx2, url, "");
    if (err != H_OK)
    {
      log_error4("[%d] %s(): %s ", herror_code(err),
                 herror_func(err), herror_message(err));
      herror_release(err);
      soap_ctx_free(ctx);
      return 1;
    }

    /* browse the childs */
    browse_childs(url, ctx2->env->cur->children);

    /* free the objects */
    soap_ctx_free(ctx2);
    soap_ctx_free(ctx);

    /* destroy the cSOAP client */
    soap_client_destroy();

    return 0;
  }
  else if(strcmp(method,"Run") == 0)
  {
    i = getMaxItemNameLength();
    if(i > 0) i = run(url,i);
    soap_client_destroy();
    return i;
  }
  else
  {
    printusage(argv[0]);
    soap_client_destroy();
  }  

  return 0;
}
コード例 #5
0
ファイル: main.c プロジェクト: bmi-forum/bmi-pyre
int main( int argc, char** argv ) {

	SoapCtx* request;
	SoapCtx* response;
	herror_t error;
	int ii;

	/* The array of parameter values to be fetched from argv. */
	char* parameters[Parameter_Num_Pos];

	xmlChar* buildID;

	if ( argc != Parameter_Num_Pos + 1 ) {
		printf( "Regresstor: Invalid Number of arguments! Num given: %d\n", argc );
		printUsage();
		return EXIT_FAILURE;
	}

	initParametersArray( parameters );
	fetchParametersFromArgv( parameters, argc, argv );

	if ( ! checkParameters( parameters ) ) {
		printUsage();
		return EXIT_FAILURE;
	}

	printf( "Regresstor: calling web service %s(), %s at %s.\n",
		Regresstor_SubmitCheckMethod,
		Regresstor_URN,
		parameters[URL_Pos]);

	/* SOAP CALL */
	error = soap_client_init_args( argc, argv );
	if ( error != H_OK ) {
		log_error4( "%s():%s [%d]", herror_func(error), herror_message(error), herror_code(error) );
		herror_release(error);
		return EXIT_FAILURE;
	}
	
	error = soap_ctx_new_with_method( Regresstor_URN, Regresstor_SubmitCheckMethod, &request );
	if ( error != H_OK ) {
		log_error4( "%s():%s [%d]", herror_func(error), herror_message(error), herror_code(error) );
		herror_release(error);
		return EXIT_FAILURE;
	}

	/* Add parameters into envelope except for the URL */
	soap_env_push_item( request->env, NULL, "parameters" );

	for ( ii = 0; ii < URL_Pos; ++ii ) {
		if ( ii == OutputLocation_Pos ) {
			/* Attach file */
			char* contents;
			char* paramName = NULL;
			int sendDummyFile = 1;

			paramName = "Output";

			if ( strcmp( parameters[ii], "none" ) != 0 ) {
				contents = getFileContents( parameters[ii] );
				if ( contents != NULL ) {
					soap_env_add_item( request->env, "xsd:string", paramName, contents );
					free( contents );
					sendDummyFile = 0;
				}
			}
			if ( sendDummyFile ) {
				soap_env_add_item( request->env, "xsd:string", paramName, "No output file" );
			}
		}
		else
		{
			soap_env_add_item( request->env, "xsd:string", parameterNames[ii], parameters[ii] );
		}
	}

	/* Check commandline to see if diff passed. If fail, add a "Diff Failed" sub test */
	if ( strcmp( parameters[Passed_Pos], "0" ) == 0 ) {
		/* Add the sub test */
		soap_env_add_item( request->env, "xsd:string", "FailedSubTests", "Error failure" );
	}
	
	soap_env_pop_item( request->env );
	
	error = soap_client_invoke( request, &response, parameters[URL_Pos], "");
                                                                                                                                    
	if ( error != H_OK ) {
		log_error4( "[%d] %s(): %s ", herror_code(error), herror_func(error), herror_message(error) );
		herror_release( error );
		soap_ctx_free( request );
		return EXIT_FAILURE;
	}

	interpretResponse( response, &buildID );

	soap_ctx_free( request );
	soap_ctx_free( response );

	soap_client_destroy();


	return EXIT_SUCCESS;
}
コード例 #6
0
ファイル: ws_in_call.c プロジェクト: millken/zhuxianB30
u_int32_t ws_umc_call(WS_ENV* ws_env, WS_REQ_RES* ws_req_res, char* method, char* end_point, char** reason)
{
    SoapCtx *ctx = NULL, *ctx2 = NULL;
    herror_t err = NULL;
    xmlNodePtr node;
    s8 url[SOAP_UMC_URL_LEN];
    s32 ret = 0;
    s8* fault_string;
    s8 umc_addr[24] = {0};
    s32 umc_port;
    s8 umc_url[30] = {0};

    /*soap client*/
    err = soap_client_init_args(0, NULL);
    if (err != H_OK)
    {
        ret = ERROR_FAIL;
        goto ret_label;
    }

    /*为soap client添加方法*/
    err = soap_ctx_new_with_method(SOAP_UMC_URN, method, &ctx);
    if (err != H_OK)
    {
        ret = ERROR_FAIL;
        goto ret_label;
    }

    /*为soap client添加请求参数*/
    ret = ws_iterate_req(ws_env, ws_req_res, ws_add_para_tosoap, (void *)ctx);
    if(ret)
    {
       goto ret_label;
    }


    ret = umc_getip(umc_addr, sizeof(umc_addr), &umc_port);
    if(ret)
    {
       goto ret_label;
    }
    if(umc_port == 0)
    {
        umc_port = 80;
    }
    snprintf(umc_url, sizeof(umc_url), "%s:%d", umc_addr, umc_port);
    
    snprintf(url, SOAP_UMC_URL_LEN, "http://%s/%s", umc_url, end_point+strlen("::/"));

    /*建立客户端, 发送请求*/
    err = soap_client_invoke_auth(ctx, &ctx2, url, "", "admin", "admin", 0);
    if (err != H_OK)
    {
         ret = ERROR_FAIL;
         goto ret_label;
    }   
    
    /*解析收到的soap应答,知道找到ret退出*/
    for (node = ctx2->env->root; node; )
    {
        if (!xmlStrcmp(node->name, BAD_CAST "Header"))
        {
            node = soap_xml_get_next(node);
        }
        else if (!xmlStrcmp(node->name, BAD_CAST "ret")
            /*|| !xmlStrstr(node->name, BAD_CAST ":ret")*/)
        {
            (void)ws_set_res_type(ws_env, ws_req_res, WS_RESULT_STRUCT);
            node = soap_xml_get_children(node);
            break;
        }
        else
        {
            node = soap_xml_get_children(node);
        }
    }

    /*此时节点指向 ret的children节点,*/
    while (node)
    {
        if (!xmlStrcmp(node->name, BAD_CAST "res_count"))
        {
            /*将总数添加res结构中*/
            ret = ws_add_res_int(ws_env, ws_req_res, (s8 *)(node->name), 
                    atoi(soap_xml_get_text(node)));
            if(ret)
            {
                break;
            }
            /*设置类型*/
            ws_set_res_type_struct_list(ws_env, 
                    ws_req_res,
                    atoi(soap_xml_get_text(node)));
                        
        }
        else if (!xmlStrcmp(node->name, BAD_CAST "umc_res"))
        {
            node = soap_xml_get_children(node);
            continue;
        }
        else if (!xmlStrcmp(node->name, BAD_CAST "res"))
        {   
            /*添加一行,每个res占用一行, 实际
                      为指针后移一行最大数*/
            ws_res_new_struct_list(ws_env, ws_req_res);
            /*添加一个res内的数据*/
            ret = umc_get_res(ws_env, ws_req_res, node);
            if(ret)
            {
                break;
            }
        }
        else
        {
            /*结构类型res的添加*/
            ret = ws_add_res_string(ws_env, ws_req_res, (s8 *)(node->name), soap_xml_get_text(node));
            if(ret)
            {
                break;
            }
        }
        node = soap_xml_get_next(node);
    }    
ret_label:
    if(ret != 0)
    {
        if(err != H_OK)
        {
            fault_string = herror_message(err);
        }
        else
        {
            fault_string = "umc get system error";
        }
        *reason = (char*)ws_strdup(ws_env, fault_string);
    }
    
    herror_release(err);
    soap_ctx_free(ctx2);
    soap_ctx_free(ctx);
    soap_client_destroy();
    
    return ret;

}