You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by sa...@apache.org on 2005/04/07 15:21:03 UTC

cvs commit: ws-axis/c/samples/client/array Client.cpp

samisa      2005/04/07 06:21:03

  Modified:    c/samples/client/array Client.cpp
  Log:
  add command line arg handling
  
  Revision  Changes    Path
  1.5       +27 -99    ws-axis/c/samples/client/array/Client.cpp
  
  Index: Client.cpp
  ===================================================================
  RCS file: /home/cvs/ws-axis/c/samples/client/array/Client.cpp,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- Client.cpp	7 Apr 2005 09:56:37 -0000	1.4
  +++ Client.cpp	7 Apr 2005 13:21:03 -0000	1.5
  @@ -5,10 +5,16 @@
   
   #define WSDL_DEFAULT_ENDPOINT "http://localhost:80/axis/array"
   
  -// Prototype
  -bool parse_args_for_endpoint(int *argc, char *argv[], char **endpoint);
  -void shift_args(int i, int *argc, char *argv[]);
  -void setLogOptions(const char *output_filename);
  +static void
  +usage (char *programName, char *defaultURL)
  +{
  +    cout << "\nUsage:\n"
  +	<< programName << " [-? | service_url] " << endl
  +	<< "    -?             Show this help.\n"
  +	<< "    service_url    URL of the service.\n"
  +	<< "    Default service URL is assumed to be " << defaultURL << endl;
  +}
  +
   
   // If we re-direct cout it will be to this ofstream
   ofstream output_file;
  @@ -17,24 +23,29 @@
   {
     SimpleTypeArrayWS *ws;
   
  -  char *endpoint = WSDL_DEFAULT_ENDPOINT;
  -  bool endpoint_set = false;
  -  int returnValue = 1; // Assume Failure
  +  char endpoint[256];
  +  sprintf(endpoint, "%s", WSDL_DEFAULT_ENDPOINT);
   
  -  endpoint_set = parse_args_for_endpoint(&argc, argv, &endpoint);
  +  int returnValue = 1; // Assume Failure
   
   		bool bSuccess = false;
   		int	iRetryIterationCount = 3;
   
   		do
   		{
  +			ws = new SimpleTypeArrayWS (endpoint, APTHTTP1_1);
     try {
  -    if(endpoint_set) {
  -      ws = new SimpleTypeArrayWS("http://localhost:80/axis/array", APTHTTP1_1);
  -      free(endpoint);
  -      endpoint_set = false;
  -    } else
  -      ws = new SimpleTypeArrayWS("http://localhost:80/axis/array");
  +    if (argc > 1)
  +    {
  +		// Watch for special case help request
  +		if (!strncmp (argv[1], "-", 1))	// Check for - only so that it works for
  +			//-?, -h or --help; -anything
  +		{
  +			usage (argv[0], endpoint);
  +			return 2;
  +		}
  +		sprintf (endpoint, argv[1]);
  +    }
   
       Type *input;
       Type *output;
  @@ -81,12 +92,10 @@
   			{
       cerr << e.what() << endl;
   			}
  -    if(endpoint_set)
  +    //if(endpoint_set)
         free(endpoint);
     } catch(...) {
  -    cerr << "Unknown Exception occured." << endl;
  -    if(endpoint_set)
  -      free(endpoint);
  +    cerr << "Unknown Exception occured." << endl;    
     }
     
     // clean up
  @@ -108,84 +117,3 @@
     return returnValue;
   
   }
  -
  -/* Spin through args list and check for -e -p and -s options.
  -   Option values are expected to follow the option letter as the next
  -   argument.
  - 
  -   These options and values are removed from the arg list.
  -   If both -e and -s and or -p, then -e takes priority
  -*/
  -bool parse_args_for_endpoint(int *argc, char *argv[], char **endpoint) {
  -
  -    // We need at least 2 extra arg after program name
  -    if(*argc < 3)
  -        return false;
  -
  -    char *server = "localhost";
  -    int  port = 80;
  -    bool ep_set = false;
  -    bool server_set = false;
  -    bool port_set = false;
  -
  -    for(int i=1; i<*argc; i++) {
  -        if(*argv[i] == '-') {
  -            switch(*(argv[i]+1)) {
  -            case 'e':
  -                *endpoint = strdup(argv[i+1]);
  -                ep_set = true;
  -                shift_args(i, argc, argv);
  -                i--;
  -                break;
  -            case 's':
  -                server = strdup(argv[i+1]);
  -                server_set = true;
  -                shift_args(i, argc, argv);
  -                i--;
  -                break;
  -            case 'p':
  -                port = atoi(argv[i+1]);
  -                if(port >80) port_set = true;
  -                shift_args(i, argc, argv);
  -                i--;
  -                break;
  -            case 'o':
  -                setLogOptions(argv[i+1]);
  -                shift_args(i, argc, argv);
  -                i--;
  -                break;
  -            default:
  -                break;
  -            }
  -        }
  -    }
  -
  -    // use the supplied server and/or port to build the endpoint
  -    if(ep_set == false && (server_set || port_set)) {
  -        // Set p to the location of the first '/' after the http:// (7 chars)
  -        // e.g. from http://localhost:80/axis/base gets /axis/base
  -        char *ep_context = strpbrk(&(*endpoint)[7], "/");
  -
  -        // http://:/ is 9 characters + terminating NULL character so add 10.
  -        // Allow space for port number upto 999999 6 chars
  -        *endpoint = (char *)calloc(1, 10 + strlen(ep_context) + strlen(server) + 6);
  -        sprintf(*endpoint, "http://%s:%d/%s", server, port, ep_context+1);
  -        if(server_set) free(server);
  -        ep_set = true;
  -    }
  -
  -    return ep_set;
  -}
  -
  -void shift_args(int i, int *argc, char *argv[]) {
  -    for(int j=i, k=i+2; j<*(argc)-2; j++, k++)
  -                    argv[j]=argv[k];
  -    *argc-=2;
  -}
  -
  -void setLogOptions(const char *output_filename) {
  -    output_file.open(output_filename, ios::out);
  -    if(output_file.is_open()){
  -        cout.rdbuf( output_file.rdbuf() );
  -    }
  -}