/*1* Copyright (c) 2009 Kungliga Tekniska H�gskolan2* (Royal Institute of Technology, Stockholm, Sweden).3* All rights reserved.4*5* Portions Copyright (c) 2009 Apple Inc. All rights reserved.6*7* Redistribution and use in source and binary forms, with or without8* modification, are permitted provided that the following conditions9* are met:10*11* 1. Redistributions of source code must retain the above copyright12* notice, this list of conditions and the following disclaimer.13*14* 2. Redistributions in binary form must reproduce the above copyright15* notice, this list of conditions and the following disclaimer in the16* documentation and/or other materials provided with the distribution.17*18* 3. Neither the name of the Institute nor the names of its contributors19* may be used to endorse or promote products derived from this software20* without specific prior written permission.21*22* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND23* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE24* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE25* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE26* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL27* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS28* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)29* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT30* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY31* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF32* SUCH DAMAGE.33*/3435#include <stdio.h>36#include <stdlib.h>37#include <krb5-types.h>38#include <asn1-common.h>39#include <heim-ipc.h>40#include <getarg.h>41#include <err.h>42#include <roken.h>4344static int help_flag;45static int version_flag;4647static struct getargs args[] = {48{ "help", 'h', arg_flag, &help_flag },49{ "version", 'v', arg_flag, &version_flag }50};5152static int num_args = sizeof(args) / sizeof(args[0]);5354static void55usage(int ret)56{57arg_printusage (args, num_args, NULL, "");58exit (ret);59}6061static void62reply(void *ctx, int errorcode, heim_idata *reply, heim_icred cred)63{64printf("got reply\n");65heim_ipc_semaphore_signal((heim_isemaphore)ctx); /* tell caller we are done */66}6768static void69test_ipc(const char *service)70{71heim_isemaphore s;72heim_idata req, rep;73heim_ipc ipc;74int ret;7576ret = heim_ipc_init_context(service, &ipc);77if (ret)78errx(1, "heim_ipc_init_context: %d", ret);7980req.length = 0;81req.data = NULL;8283ret = heim_ipc_call(ipc, &req, &rep, NULL);84if (ret)85errx(1, "heim_ipc_call: %d", ret);8687s = heim_ipc_semaphore_create(0);88if (s == NULL)89errx(1, "heim_ipc_semaphore_create");9091ret = heim_ipc_async(ipc, &req, s, reply);92if (ret)93errx(1, "heim_ipc_async: %d", ret);9495heim_ipc_semaphore_wait(s, HEIM_IPC_WAIT_FOREVER); /* wait for reply to complete the work */9697heim_ipc_free_context(ipc);98}99100101int102main(int argc, char **argv)103{104int optidx = 0;105106setprogname(argv[0]);107108if (getarg(args, num_args, argc, argv, &optidx))109usage(1);110111if (help_flag)112usage(0);113114if (version_flag) {115print_version(NULL);116exit(0);117}118119#ifdef __APPLE__120test_ipc("MACH:org.h5l.test-ipc");121#endif122test_ipc("ANY:org.h5l.test-ipc");123test_ipc("UNIX:org.h5l.test-ipc");124125return 0;126}127128129