/*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 <heim-ipc.h>39#include <getarg.h>40#include <roken.h>4142static int help_flag;43static int version_flag;4445static struct getargs args[] = {46{ "help", 'h', arg_flag, &help_flag },47{ "version", 'v', arg_flag, &version_flag }48};4950static int num_args = sizeof(args) / sizeof(args[0]);5152static void53usage(int ret)54{55arg_printusage (args, num_args, NULL, "");56exit (ret);57}5859static void60test_service(void *ctx, const heim_idata *req,61const heim_icred cred,62heim_ipc_complete complete,63heim_sipc_call cctx)64{65heim_idata rep;66printf("got request\n");67rep.length = 3;68rep.data = strdup("hej");69(*complete)(cctx, 0, &rep);70}717273static void74setup_sockets(void)75{76struct addrinfo hints, *res, *res0;77int ret, s;78heim_sipc u;7980memset(&hints, 0, sizeof(hints));81hints.ai_family = PF_UNSPEC;82hints.ai_socktype = SOCK_STREAM;83hints.ai_flags = AI_PASSIVE;84ret = getaddrinfo(NULL, "8080", &hints, &res0);85if (ret)86errx(1, "%s", gai_strerror(ret));8788for (res = res0; res ; res = res->ai_next) {89s = socket(res->ai_family, res->ai_socktype, res->ai_protocol);90if (s < 0) {91warn("socket");92continue;93}94socket_set_reuseaddr(s, 1);95socket_set_ipv6only(s, 1);9697if (bind(s, res->ai_addr, res->ai_addrlen) < 0) {98warn("bind");99close(s);100continue;101}102listen(s, 5);103ret = heim_sipc_stream_listener(s, HEIM_SIPC_TYPE_HTTP,104test_service, NULL, &u);105if (ret)106errx(1, "heim_sipc_stream_listener: %d", ret);107}108freeaddrinfo(res0);109}110111112int113main(int argc, char **argv)114{115int optidx = 0;116117setprogname(argv[0]);118119if (getarg(args, num_args, argc, argv, &optidx))120usage(1);121122if (help_flag)123usage(0);124125if (version_flag) {126print_version(NULL);127exit(0);128}129130setup_sockets();131132heim_ipc_main();133134return 0;135}136137138