PreviousNext

Sample Client Code

Here is an example of an internationalized RPC client that calls the operation defined in the cs_test interface shown in Writing the Interface Definition File . The client establishes the DCE RPC evaluation routine rpc_cs_eval_without_universal( ) as the character and code sets evaluation routine to use.

#include <stdio.h>

#include <locale.h>

#include <dce/rpc.h>

#include <dce/rpcsts.h>

#include <dce/dce_error.h>

#include "cs_test.h" /* IDL generated include file */

/*

* Result check MACRO

*/

#define CHECK_STATUS(t, func, returned_st, expected_st) \

{ \

if (returned_st == expected_st) { \

/*

* Do nothing.

*/

} else { \

dce_error_inq_text(returned_st,\

(unsigned char *)unexpected, &dce_status); \

dce_error_inq_text(expected_st, \

(unsigned char *)expected, &dce_status); \

printf("FAILED %s()\nresult: %s\nexpected: %s\n\n", \

func, unexpected, expected); \

} \

} \

static unsigned char unexpected[dce_c_error_string_len];

static unsigned char expected[dce_c_error_string_len];

static int dce_status;

void

main(void)

{

rpc_binding_handle_t bind_handle;

rpc_ns_handle_t import_context;

error_status_t status;

error_status_t temp_status;

cs_byte net_string[SIZE];

cs_byte loc_string[SIZE];

unsigned char err_buf[256];

char *nsi_entry_name;

char *client_locale_name;

int i, rpc_num;

FILE *fp_in, *fp_out;

/* The environment variable I18N_SERVER_ENTRY needs

* to be set before running this program. This is

* not a DCE environment variable, so you can set up

* your own environment variable if you like.

*/

nsi_entry_name = getenv("I18N_SERVER_ENTRY");

setlocale(LC_ALL, "");

rpc_ns_binding_import_begin (

rpc_c_ns_syntax_default,

(unsigned_char_p_t)nsi_entry_name,

cs_test_v1_0_c_ifspec,

NULL,

&import_context,

&status );

CHECK_STATUS(TRUE, "rpc_ns_binding_import_begin", status, rpc_s_ok);

/*

* Add code set compatibility checking logic to the context.

*/

rpc_ns_import_ctx_add_eval (

&import_context,

rpc_c_eval_type_codesets,

(void *)nsi_entry_name,

rpc_cs_eval_without_universal,

NULL,

&status );

CHECK_STATUS(TRUE, "rpc_ns_import_ctx_add_eval", status, rpc_s_ok);

while (1) {

rpc_ns_binding_import_next (

import_context,

&bind_handle,

&status );

CHECK_STATUS(TRUE, "rpc_ns_binding_import_next", status, rpc_s_ok);

if (status == rpc_s_ok)

break;

else

{

return;

}

}

rpc_ns_binding_import_done (

&import_context,

&status );

CHECK_STATUS(TRUE, "rpc_ns_binding_import_done", status, rpc_s_ok);

rpc_ep_resolve_binding (bind_handle,

cs_test_v1_0_c_ifspec,

&temp_status);

CHECK_STATUS(TRUE, "rpc_ep_resolve_binding", temp_status, rpc_s_ok);

if(rpc_mgmt_is_server_listening(bind_handle, &status)

&& temp_status == rpc_s_ok)

{

; /* Do nothing. */

}

else

{

dce_error_inq_text ((unsigned long)status,

err_buf, (int *)&temp_status);

printf("is_server_listening error -> %s\n", err_buf);

}

/*

* This program reads the data from a file.

*/

fp_in = fopen("./i18n_input_data", "r");

if (fp_in == NULL)

{

printf("i18n_input_data open failed\n");

return;

}

fp_out = fopen("./i18n_method_fixed_result_file", "w");

if (fp_out == NULL)

{

printf("i18n_result_file open failed\n");

fclose(fp_in);

return;

}

rpc_num = 1;

while (!feof(fp_in))

{

(void)fgets((char *)net_string, SIZE, fp_in);

temp_status = cs_fixed_trans(bind_handle, net_string, loc_string);

if (temp_status != rpc_s_ok)

{

dce_error_inq_text(temp_status, err_buf, (int *)&status);

printf("FAILED %ld MSG: %s\n", (unsigned long)temp_status, err_buf);

}

else

{

printf("PASSED rpc #%d\n", rpc_num++);

(void)fputs((char *)loc_string, fp_out);

(void)fputs("\n", fp_out);

}

}

fclose(fp_in);

fclose(fp_out);

return;

}