1*ae771770SStanislav Sedov /*
2*ae771770SStanislav Sedov * Copyright (c) 2009 Kungliga Tekniska H�gskolan
3*ae771770SStanislav Sedov * (Royal Institute of Technology, Stockholm, Sweden).
4*ae771770SStanislav Sedov * All rights reserved.
5*ae771770SStanislav Sedov *
6*ae771770SStanislav Sedov * Portions Copyright (c) 2009 Apple Inc. All rights reserved.
7*ae771770SStanislav Sedov *
8*ae771770SStanislav Sedov * Redistribution and use in source and binary forms, with or without
9*ae771770SStanislav Sedov * modification, are permitted provided that the following conditions
10*ae771770SStanislav Sedov * are met:
11*ae771770SStanislav Sedov *
12*ae771770SStanislav Sedov * 1. Redistributions of source code must retain the above copyright
13*ae771770SStanislav Sedov * notice, this list of conditions and the following disclaimer.
14*ae771770SStanislav Sedov *
15*ae771770SStanislav Sedov * 2. Redistributions in binary form must reproduce the above copyright
16*ae771770SStanislav Sedov * notice, this list of conditions and the following disclaimer in the
17*ae771770SStanislav Sedov * documentation and/or other materials provided with the distribution.
18*ae771770SStanislav Sedov *
19*ae771770SStanislav Sedov * 3. Neither the name of the Institute nor the names of its contributors
20*ae771770SStanislav Sedov * may be used to endorse or promote products derived from this software
21*ae771770SStanislav Sedov * without specific prior written permission.
22*ae771770SStanislav Sedov *
23*ae771770SStanislav Sedov * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
24*ae771770SStanislav Sedov * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25*ae771770SStanislav Sedov * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26*ae771770SStanislav Sedov * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
27*ae771770SStanislav Sedov * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28*ae771770SStanislav Sedov * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29*ae771770SStanislav Sedov * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30*ae771770SStanislav Sedov * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31*ae771770SStanislav Sedov * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32*ae771770SStanislav Sedov * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33*ae771770SStanislav Sedov * SUCH DAMAGE.
34*ae771770SStanislav Sedov */
35*ae771770SStanislav Sedov
36*ae771770SStanislav Sedov #include <stdio.h>
37*ae771770SStanislav Sedov #include <stdlib.h>
38*ae771770SStanislav Sedov #include <krb5-types.h>
39*ae771770SStanislav Sedov #include <asn1-common.h>
40*ae771770SStanislav Sedov #include <heim-ipc.h>
41*ae771770SStanislav Sedov #include <getarg.h>
42*ae771770SStanislav Sedov #include <err.h>
43*ae771770SStanislav Sedov #include <roken.h>
44*ae771770SStanislav Sedov
45*ae771770SStanislav Sedov static int help_flag;
46*ae771770SStanislav Sedov static int version_flag;
47*ae771770SStanislav Sedov
48*ae771770SStanislav Sedov static struct getargs args[] = {
49*ae771770SStanislav Sedov { "help", 'h', arg_flag, &help_flag },
50*ae771770SStanislav Sedov { "version", 'v', arg_flag, &version_flag }
51*ae771770SStanislav Sedov };
52*ae771770SStanislav Sedov
53*ae771770SStanislav Sedov static int num_args = sizeof(args) / sizeof(args[0]);
54*ae771770SStanislav Sedov
55*ae771770SStanislav Sedov static void
usage(int ret)56*ae771770SStanislav Sedov usage(int ret)
57*ae771770SStanislav Sedov {
58*ae771770SStanislav Sedov arg_printusage (args, num_args, NULL, "");
59*ae771770SStanislav Sedov exit (ret);
60*ae771770SStanislav Sedov }
61*ae771770SStanislav Sedov
62*ae771770SStanislav Sedov static void
reply(void * ctx,int errorcode,heim_idata * reply,heim_icred cred)63*ae771770SStanislav Sedov reply(void *ctx, int errorcode, heim_idata *reply, heim_icred cred)
64*ae771770SStanislav Sedov {
65*ae771770SStanislav Sedov printf("got reply\n");
66*ae771770SStanislav Sedov heim_ipc_semaphore_signal((heim_isemaphore)ctx); /* tell caller we are done */
67*ae771770SStanislav Sedov }
68*ae771770SStanislav Sedov
69*ae771770SStanislav Sedov static void
test_ipc(const char * service)70*ae771770SStanislav Sedov test_ipc(const char *service)
71*ae771770SStanislav Sedov {
72*ae771770SStanislav Sedov heim_isemaphore s;
73*ae771770SStanislav Sedov heim_idata req, rep;
74*ae771770SStanislav Sedov heim_ipc ipc;
75*ae771770SStanislav Sedov int ret;
76*ae771770SStanislav Sedov
77*ae771770SStanislav Sedov ret = heim_ipc_init_context(service, &ipc);
78*ae771770SStanislav Sedov if (ret)
79*ae771770SStanislav Sedov errx(1, "heim_ipc_init_context: %d", ret);
80*ae771770SStanislav Sedov
81*ae771770SStanislav Sedov req.length = 0;
82*ae771770SStanislav Sedov req.data = NULL;
83*ae771770SStanislav Sedov
84*ae771770SStanislav Sedov ret = heim_ipc_call(ipc, &req, &rep, NULL);
85*ae771770SStanislav Sedov if (ret)
86*ae771770SStanislav Sedov errx(1, "heim_ipc_call: %d", ret);
87*ae771770SStanislav Sedov
88*ae771770SStanislav Sedov s = heim_ipc_semaphore_create(0);
89*ae771770SStanislav Sedov if (s == NULL)
90*ae771770SStanislav Sedov errx(1, "heim_ipc_semaphore_create");
91*ae771770SStanislav Sedov
92*ae771770SStanislav Sedov ret = heim_ipc_async(ipc, &req, s, reply);
93*ae771770SStanislav Sedov if (ret)
94*ae771770SStanislav Sedov errx(1, "heim_ipc_async: %d", ret);
95*ae771770SStanislav Sedov
96*ae771770SStanislav Sedov heim_ipc_semaphore_wait(s, HEIM_IPC_WAIT_FOREVER); /* wait for reply to complete the work */
97*ae771770SStanislav Sedov
98*ae771770SStanislav Sedov heim_ipc_free_context(ipc);
99*ae771770SStanislav Sedov }
100*ae771770SStanislav Sedov
101*ae771770SStanislav Sedov
102*ae771770SStanislav Sedov int
main(int argc,char ** argv)103*ae771770SStanislav Sedov main(int argc, char **argv)
104*ae771770SStanislav Sedov {
105*ae771770SStanislav Sedov int optidx = 0;
106*ae771770SStanislav Sedov
107*ae771770SStanislav Sedov setprogname(argv[0]);
108*ae771770SStanislav Sedov
109*ae771770SStanislav Sedov if (getarg(args, num_args, argc, argv, &optidx))
110*ae771770SStanislav Sedov usage(1);
111*ae771770SStanislav Sedov
112*ae771770SStanislav Sedov if (help_flag)
113*ae771770SStanislav Sedov usage(0);
114*ae771770SStanislav Sedov
115*ae771770SStanislav Sedov if (version_flag) {
116*ae771770SStanislav Sedov print_version(NULL);
117*ae771770SStanislav Sedov exit(0);
118*ae771770SStanislav Sedov }
119*ae771770SStanislav Sedov
120*ae771770SStanislav Sedov #ifdef __APPLE__
121*ae771770SStanislav Sedov test_ipc("MACH:org.h5l.test-ipc");
122*ae771770SStanislav Sedov #endif
123*ae771770SStanislav Sedov test_ipc("ANY:org.h5l.test-ipc");
124*ae771770SStanislav Sedov test_ipc("UNIX:org.h5l.test-ipc");
125*ae771770SStanislav Sedov
126*ae771770SStanislav Sedov return 0;
127*ae771770SStanislav Sedov }
128