OpenVMS Source-Code Demos

calcclient.c

//=====================================================================================
//	calcclient.c (a sample program provided with gSOAP for OpenVMS)
//
// who when   what
// --- ------ -------------------------------------------------------------------------
// NSR 100726 1. changed URLs to test against server running under Apache via MOD_GSOAP
// NSR 120131 1. added a couple of lines to enable crude SSL support
// NSR 120731 1. added more details to the SSL support
//=====================================================================================
// caveat: OpenVMS gSOAP 0.11 (based upon gSOAP 2.8.3) does not allow you to enable
//	macros "WITH_OPENSSL" and "SOAP_DEBUG" at the same time. Hopefully this
//	(reported) problem will be fixed in the next release.
//=====================================================================================
#include "soapH.h"							//
#include "calc.nsmap"							//
//
#ifdef WITH_OPENSSL							// --- if ssl is enabled ---
char server[]		= "https://142.180.39.16/gsoap_calc_server";	// works with MOD_GSOAP (Apache)
//
//	Note: logical definition on all my VMS systems:
//		define/system  VMS_PROD_CERT_DIR  SYS$SYSDEVICE:[CERTIFICATES]
//
char certificate[]	= "VMS_PROD_CERT_DIR/client.pem";		// client certificate
char cacert[]		= "VMS_PROD_CERT_DIR/client_ca.pem";		// trusted client chain file
char capath[]		= "VMS_PROD_CERT_DIR";				// directory
char ssl_level[]	= "0";						// 0=very relaxed
#else									// --- if ssl is NOT enabled ---
const char server[]	= "http://142.180.39.16/gsoap_calc_server";	// works with MOD_GSOAP (Apache)
#endif									// -----------------------------
//
//
//
int main(int argc, char **argv) {
    struct soap soap;
    double a, b, result;
    if (argc < 4)
    { fprintf(stderr, "Usage: [add|sub|mul|div|pow] num num\n");
	exit(0);
    }
    soap_init(&soap);							//
#ifdef WITH_OPENSSL
    printf("-i-calling: soap_ssl_init()\n");
    soap_ssl_init();
    printf("-i-calling: soap_client_context()\n");
    //
    //	set ssl client context
    //
    switch (ssl_level[0]) {
    case '0':								// very relaxed (testing)
	printf("-i-starting SSL level 0 (VERY RELAXED) soap_ssl_client_context\n");
	if (soap_ssl_client_context(					//
		&soap,							//
		SOAP_SSL_NO_AUTHENTICATION,				//
		NULL,							// key file		: "client.pem"
		NULL,							// key password		: "password"
		NULL,							// trusted certifcates	: "cacerts.pem"
		NULL,							// path to cacerts	:
		NULL							// random data seed	:
	))
	{
	    soap_print_fault(&soap, stderr);
	    exit(1);
	}
	break;
    case '1':								// a little harder (needs work)
	printf("-i-starting SSL level 1 (RELAXED) soap_ssl_client_context\n");
	printf("-i-capath: %s\n",capath);				//
	if (soap_ssl_client_context(					//
		&soap,							//
		SOAP_SSL_REQUIRE_SERVER_AUTHENTICATION	|
		SOAP_SSL_SKIP_HOST_CHECK		|
		SOAP_SSL_ALLOW_EXPIRED_CERTIFICATE,			//
		NULL,							// key file		: "client.pem"
		NULL,							// key password		: "password"
		NULL,							// trusted certifcates	: "cacerts.pem"
		capath,							// path to cacerts	: "vms_prod_cert_dir"
		NULL							// random data seed	:
		))
	{
		soap_print_fault(&soap, stderr);
		exit(1);
	}
	break;
    case '2':								// a little harder (needs work)
	printf("-i-starting DEFAULT (2) soap_ssl_client_context\n");	//
	printf("-i-cert  : %s\n",certificate);				// incase they have Validate-Client enabled
	printf("-i-cacert: %s\n",cacert);				//
	printf("-i-capath: %s\n",capath);				//
	//
	//	caveat: don't just guess at these params. Do some preliminary hacking with the openssl tool like so:
	//
	//	1) openssl verify "-CApath" vms_prod_cert_dir -purpose any vms_prod_cert_dir/example.crt
	//		or
	//	2) openssl s_client -connect 142.180.221.226:443 "-CApath" vms_prod_cert_dir -cert vms_prod_cert_dir/kawc09.pem
	//
	if (soap_ssl_client_context(					//
		&soap,							//
		SOAP_SSL_DEFAULT,					//
		certificate,						// key file		: "client.pem"
		NULL,							// key password		: "password"
		cacert,							// trusted certifcates	: "cacerts.pem"
		capath,							// path to cacerts	: "vms_prod_cert_dir"
		NULL							// random data seed	:
		))
	{
		soap_print_fault(&soap, stderr);
		exit(1);
	}
	break;
    default:								//
	printf("-e-oops, %c is not a valid selection\n",ssl_level[0]);	//
    } 									//
#endif
#ifdef SOAP_DEBUG
    soap_set_recv_logfile(&soap, "recv.log");
    soap_set_sent_logfile(&soap, "sent.log");
    soap_set_test_logfile(&soap, "test.log");
#endif
    a = strtod(argv[2], NULL);
    b = strtod(argv[3], NULL);
    switch (*argv[1]) {
    case 'a':
	soap_call_ns__add(&soap, server, "", a, b, &result);
	break;
    case 's':
	soap_call_ns__sub(&soap, server, "", a, b, &result);
	break;
    case 'm':
	soap_call_ns__mul(&soap, server, "", a, b, &result);
	break;
    case 'd':
	soap_call_ns__div(&soap, server, "", a, b, &result);
	break;
    case 'p':
	soap_call_ns__pow(&soap, server, "", a, b, &result);
	break;
    default:
	fprintf(stderr, "Unknown command\n");
	exit(0);
    }
    if (soap.error)
    { soap_print_fault(&soap, stderr);
	exit(1);
    }else{
	printf("result = %g\n", result);
    }
    soap_destroy(&soap);
    soap_end(&soap);
    soap_done(&soap);
    return 0;
}