1226031Sstas/* 2226031Sstas * Copyright (c) 2009 Kungliga Tekniska H�gskolan 3226031Sstas * (Royal Institute of Technology, Stockholm, Sweden). 4226031Sstas * All rights reserved. 5226031Sstas * 6226031Sstas * Portions Copyright (c) 2009 Apple Inc. All rights reserved. 7226031Sstas * 8226031Sstas * Redistribution and use in source and binary forms, with or without 9226031Sstas * modification, are permitted provided that the following conditions 10226031Sstas * are met: 11226031Sstas * 12226031Sstas * 1. Redistributions of source code must retain the above copyright 13226031Sstas * notice, this list of conditions and the following disclaimer. 14226031Sstas * 15226031Sstas * 2. Redistributions in binary form must reproduce the above copyright 16226031Sstas * notice, this list of conditions and the following disclaimer in the 17226031Sstas * documentation and/or other materials provided with the distribution. 18226031Sstas * 19226031Sstas * 3. Neither the name of the Institute nor the names of its contributors 20226031Sstas * may be used to endorse or promote products derived from this software 21226031Sstas * without specific prior written permission. 22226031Sstas * 23226031Sstas * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 24226031Sstas * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25226031Sstas * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26226031Sstas * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 27226031Sstas * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28226031Sstas * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29226031Sstas * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30226031Sstas * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31226031Sstas * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32226031Sstas * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33226031Sstas * SUCH DAMAGE. 34226031Sstas */ 35226031Sstas 36226031Sstas#include <stdio.h> 37226031Sstas#include <stdlib.h> 38226031Sstas#include <krb5-types.h> 39226031Sstas#include <asn1-common.h> 40226031Sstas#include <heim-ipc.h> 41226031Sstas#include <getarg.h> 42226031Sstas#include <err.h> 43226031Sstas#include <roken.h> 44226031Sstas 45226031Sstasstatic int help_flag; 46226031Sstasstatic int version_flag; 47226031Sstas 48226031Sstasstatic struct getargs args[] = { 49226031Sstas { "help", 'h', arg_flag, &help_flag }, 50226031Sstas { "version", 'v', arg_flag, &version_flag } 51226031Sstas}; 52226031Sstas 53226031Sstasstatic int num_args = sizeof(args) / sizeof(args[0]); 54226031Sstas 55226031Sstasstatic void 56226031Sstasusage(int ret) 57226031Sstas{ 58226031Sstas arg_printusage (args, num_args, NULL, ""); 59226031Sstas exit (ret); 60226031Sstas} 61226031Sstas 62226031Sstasstatic void 63226031Sstasreply(void *ctx, int errorcode, heim_idata *reply, heim_icred cred) 64226031Sstas{ 65226031Sstas printf("got reply\n"); 66226031Sstas heim_ipc_semaphore_signal((heim_isemaphore)ctx); /* tell caller we are done */ 67226031Sstas} 68226031Sstas 69226031Sstasstatic void 70226031Sstastest_ipc(const char *service) 71226031Sstas{ 72226031Sstas heim_isemaphore s; 73226031Sstas heim_idata req, rep; 74226031Sstas heim_ipc ipc; 75226031Sstas int ret; 76226031Sstas 77226031Sstas ret = heim_ipc_init_context(service, &ipc); 78226031Sstas if (ret) 79226031Sstas errx(1, "heim_ipc_init_context: %d", ret); 80226031Sstas 81226031Sstas req.length = 0; 82226031Sstas req.data = NULL; 83226031Sstas 84226031Sstas ret = heim_ipc_call(ipc, &req, &rep, NULL); 85226031Sstas if (ret) 86226031Sstas errx(1, "heim_ipc_call: %d", ret); 87226031Sstas 88226031Sstas s = heim_ipc_semaphore_create(0); 89226031Sstas if (s == NULL) 90226031Sstas errx(1, "heim_ipc_semaphore_create"); 91226031Sstas 92226031Sstas ret = heim_ipc_async(ipc, &req, s, reply); 93226031Sstas if (ret) 94226031Sstas errx(1, "heim_ipc_async: %d", ret); 95226031Sstas 96226031Sstas heim_ipc_semaphore_wait(s, HEIM_IPC_WAIT_FOREVER); /* wait for reply to complete the work */ 97226031Sstas 98226031Sstas heim_ipc_free_context(ipc); 99226031Sstas} 100226031Sstas 101226031Sstas 102226031Sstasint 103226031Sstasmain(int argc, char **argv) 104226031Sstas{ 105226031Sstas int optidx = 0; 106226031Sstas 107226031Sstas setprogname(argv[0]); 108226031Sstas 109226031Sstas if (getarg(args, num_args, argc, argv, &optidx)) 110226031Sstas usage(1); 111226031Sstas 112226031Sstas if (help_flag) 113226031Sstas usage(0); 114226031Sstas 115226031Sstas if (version_flag) { 116226031Sstas print_version(NULL); 117226031Sstas exit(0); 118226031Sstas } 119226031Sstas 120226031Sstas#ifdef __APPLE__ 121226031Sstas test_ipc("MACH:org.h5l.test-ipc"); 122226031Sstas#endif 123226031Sstas test_ipc("ANY:org.h5l.test-ipc"); 124226031Sstas test_ipc("UNIX:org.h5l.test-ipc"); 125226031Sstas 126226031Sstas return 0; 127226031Sstas} 128