Chapter 9. Porting open system applications to a z/TPF system 197
/* issue SSL_get_peer_certificate_subject_info() */
c_len = sizeof(country);
st_len = sizeof(state);
city_len = sizeof(city);
company_len = sizeof(company);
c_unit_len = sizeof(company_unit);
name_len = sizeof(common_name);
email_len = sizeof(email);
SSL_get_peer_certificate_subject_info(myssl, country, c_len, state, st_len, city,
city_len, company, company_len, company_unit, c_unit_len,
common_name, name_len, email, email_len);
/*Send message to the server.*/
err=SSL_write(myssl,"Hello there!!!!",sizeof("Hello there!!!!")+1);
/*Read servers response.*/
err = SSL_read (myssl, buff, sizeof(buff));
printf("Server said: %s\n",buff);
9.2 Character conversion
In this section we introduce character conversion while porting open system applications to
z/TPF, that is, converting from ASCII to EBCDIC character set. For example, take function
fopen, in stdio.h. The definition of the function is fopen(const char *filename, char *mode).
The two parameters, filename and mode, are ASCII string, while the z/TPF system expects to
be in EBCDIC. In this condition, character conversion is required.
Follow these three main steps for character conversion:
1. Take function
foobar (in foobar.h) as an example.
a. First create the a2e wrapper of function foobar, atoe_foobar, which converts the
parameter string from ASCII to EBCDIC and then call foobar.
b. Then create the header file for atoe_foobar as shown in Example 9-7.
198 z/TPF and WebSphere Application Server in a Service Oriented Architecture
Example 9-7 Header file of atoe_foobar, the a2e wrapper of function foobar
#include_next <foobar.h>
#if defined(IBM_ATOE)
#if !defined(IBM_ATOE_STDIO)
#ifdef __cplusplus
extern "C" {
int atoe_foobar (char *);
#ifdef __cplusplus
#undef foobar
#define foobar atoe_foobar
2. Second, create the real implementation of atoe_foobar, the wrapper of function foobar, in
atoe.c, as shown in Example 9-8.
Example 9-8 Implementation of atoe_foobar, the a2e wrapper of function foobar
int atoe_foobar (char *foo)
int ret;
char *e;
Log(1,"Entry: atoe_foo\n");
e = a2e_string((char *) foo);
ret = foobar(e);
return ret;
In the foregoing implementation, the wrapper atoe_foobar finally calls the real function
foobar and returns the result. The a2e_string is the function to convert the ASCII string to
an EBCDIC string. The function a2e_string is based on the iconv character conversion
function on the z/TPF system.
3. Finally, when porting the open system application to the z/TPF system, specify header file
foobar.h as the header file of wrapper function atoe_foobar, instead of that of function
foobar, to make sure that the wrapper function is called to do character conversion before
the real function foobar is called.

Get z/TPF and WebSphere Application Server in a Service Oriented Architecture now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.