1// pingtest.c
2//
3// Test RPC to server, with PING message, which exists for no other purpose than this test.
4
5#include <stdio.h>
6#include <stdarg.h>
7#include <stdlib.h>
8#include <malloc.h>
9
10#include "cci_debugging.h"
11#include "CredentialsCache.h"
12#include "cci_stream.h"
13#include "win-utils.h"
14
15#include "ccs_request.h"
16#define CLIENT_REQUEST_RPC_HANDLE ccs_request_IfHandle
17
18
19extern cc_int32 cci_os_ipc_thread_init (void);
20extern cc_int32 cci_os_ipc_msg( cc_int32        in_launch_server,
21                                cci_stream_t    in_request_stream,
22                                cc_int32        in_msg,
23                                cci_stream_t*   out_reply_stream);
24
25static DWORD    dwTlsIndex;
26
27DWORD GetTlsIndex()    {return dwTlsIndex;}
28
29RPC_STATUS send_test(char* endpoint) {
30    unsigned char*  pszNetworkAddress   = NULL;
31    unsigned char*  pszOptions          = NULL;
32    unsigned char*  pszStringBinding    = NULL;
33    unsigned char*  pszUuid             = NULL;
34    RPC_STATUS      status;
35
36    status = RpcStringBindingCompose(pszUuid,
37                                     (RPC_CSTR)"ncalrpc",
38                                     pszNetworkAddress,
39                                     (unsigned char*)endpoint,
40                                     pszOptions,
41                                     &pszStringBinding);
42    cci_debug_printf("%s pszStringBinding = %s", __FUNCTION__, pszStringBinding);
43    if (status) {return cci_check_error(status);}
44
45    /* Set the binding handle that will be used to bind to the RPC server [the 'client']. */
46    status = RpcBindingFromStringBinding(pszStringBinding, &CLIENT_REQUEST_RPC_HANDLE);
47    if (status) {return cci_check_error(status);}
48
49    status = RpcStringFree(&pszStringBinding);  // Temp var no longer needed.
50
51    if (!status) {
52        RpcTryExcept {
53            cci_debug_printf("%s calling remote procedure 'ccs_authenticate'", __FUNCTION__);
54            status = ccs_authenticate((CC_CHAR*)"DLLMAIN TEST!");
55            cci_debug_printf("  ccs_authenticate returned %d", status);
56            }
57        RpcExcept(1) {
58            status = cci_check_error(RpcExceptionCode());
59            }
60        RpcEndExcept
61        }
62
63    cci_check_error(RpcBindingFree(&CLIENT_REQUEST_RPC_HANDLE));
64
65    return (status);
66    }
67
68int main(   int argc, char *argv[]) {
69    cc_int32        err             = 0;
70    cc_context_t    context         = NULL;
71    cci_stream_t    send_stream     = NULL;
72    cci_stream_t    reply_stream    = NULL;
73    char*           message         = "Hello, RPC!";
74
75
76    if ((dwTlsIndex = TlsAlloc()) == TLS_OUT_OF_INDEXES) return FALSE;
77
78//    send_test("krbcc.229026.0.ep");
79
80#if 0
81    err = cc_initialize(&context, ccapi_version_7, NULL, NULL);
82#endif
83
84    if (!err) {
85        err = cci_os_ipc_thread_init();
86        }
87    if (!err) {
88        err = cci_stream_new  (&send_stream);
89        err = cci_stream_write(send_stream, message, 1+strlen(message));
90        }
91
92    if (!err) {
93        err = cci_os_ipc_msg(TRUE, send_stream, CCMSG_PING, &reply_stream);
94        }
95    Sleep(10*1000);
96    cci_debug_printf("Try finishing async call.");
97
98    Sleep(INFINITE);
99    cci_debug_printf("main: return. err == %d", err);
100
101    return 0;
102    }
103
104
105
106/*********************************************************************/
107/*                 MIDL allocate and free                            */
108/*********************************************************************/
109
110void  __RPC_FAR * __RPC_USER midl_user_allocate(size_t len) {
111    return(malloc(len));
112    }
113
114void __RPC_USER midl_user_free(void __RPC_FAR * ptr) {
115    free(ptr);
116    }
117