Changeset View
Changeset View
Standalone View
Standalone View
lib/libcasper/libcaspermock/libcasper.c
- This file was added.
/*- | |||||
* Copyright (c) 2016 Mariusz Zaborski <oshogbo@FreeBSD.org> | |||||
* All rights reserved. | |||||
* | |||||
* Redistribution and use in source and binary forms, with or without | |||||
* modification, are permitted provided that the following conditions | |||||
* are met: | |||||
* 1. Redistributions of source code must retain the above copyright | |||||
* notice, this list of conditions and the following disclaimer. | |||||
* 2. Redistributions in binary form must reproduce the above copyright | |||||
* notice, this list of conditions and the following disclaimer in the | |||||
* documentation and/or other materials provided with the distribution. | |||||
* | |||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND | |||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE | |||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||||
* SUCH DAMAGE. | |||||
*/ | |||||
#include <sys/cdefs.h> | |||||
__FBSDID("$FreeBSD$"); | |||||
#include <sys/types.h> | |||||
#include <sys/socket.h> | |||||
#include <sys/nv.h> | |||||
#include <sys/procdesc.h> | |||||
#include <assert.h> | |||||
#include <errno.h> | |||||
#include <stdbool.h> | |||||
#include <stdlib.h> | |||||
#include <string.h> | |||||
#include <unistd.h> | |||||
#include "libcasper.h" | |||||
#define CAP_CHANNEL_MAGIC 0xcac8b42 | |||||
struct cap_channel { | |||||
/* | |||||
* Magic value helps to ensure that a pointer to the right structure is | |||||
* passed to our functions. | |||||
*/ | |||||
int cch_magic; | |||||
}; | |||||
cap_channel_t * | |||||
cap_init(void) | |||||
{ | |||||
return (cap_wrap(-1)); | |||||
} | |||||
cap_channel_t * | |||||
cap_wrap(int sock __unused) | |||||
{ | |||||
cap_channel_t *chan; | |||||
chan = malloc(sizeof(*chan)); | |||||
if (chan != NULL) | |||||
chan->cch_magic = CAP_CHANNEL_MAGIC; | |||||
return (chan); | |||||
} | |||||
int | |||||
cap_unwrap(cap_channel_t *chan) | |||||
{ | |||||
assert(chan != NULL); | |||||
assert(chan->cch_magic == CAP_CHANNEL_MAGIC); | |||||
chan->cch_magic = 0; | |||||
free(chan); | |||||
return (-1); | |||||
} | |||||
cap_channel_t * | |||||
cap_clone(const cap_channel_t *chan __unused) | |||||
{ | |||||
return (cap_wrap(-1)); | |||||
} | |||||
void | |||||
cap_close(cap_channel_t *chan) | |||||
{ | |||||
assert(chan != NULL); | |||||
assert(chan->cch_magic == CAP_CHANNEL_MAGIC); | |||||
chan->cch_magic = 0; | |||||
free(chan); | |||||
} | |||||
int | |||||
cap_sock(const cap_channel_t *chan) | |||||
{ | |||||
assert(chan != NULL); | |||||
assert(chan->cch_magic == CAP_CHANNEL_MAGIC); | |||||
return (-1); | |||||
} | |||||
int | |||||
cap_limit_set(const cap_channel_t *chan, nvlist_t *limits __unused) | |||||
{ | |||||
assert(chan != NULL); | |||||
assert(chan->cch_magic == CAP_CHANNEL_MAGIC); | |||||
return (0); | |||||
} | |||||
int | |||||
cap_limit_get(const cap_channel_t *chan, nvlist_t **limitsp) | |||||
{ | |||||
assert(chan != NULL); | |||||
assert(chan->cch_magic == CAP_CHANNEL_MAGIC); | |||||
*limitsp = nvlist_create(0); | |||||
return (0); | |||||
} | |||||
int | |||||
cap_send_nvlist(const cap_channel_t *chan, const nvlist_t *nvl __unused) | |||||
{ | |||||
assert(chan != NULL); | |||||
assert(chan->cch_magic == CAP_CHANNEL_MAGIC); | |||||
return (0); | |||||
} | |||||
nvlist_t * | |||||
cap_recv_nvlist(const cap_channel_t *chan, int flags __unused) | |||||
{ | |||||
assert(chan != NULL); | |||||
assert(chan->cch_magic == CAP_CHANNEL_MAGIC); | |||||
return (0); | |||||
} | |||||
nvlist_t * | |||||
cap_xfer_nvlist(const cap_channel_t *chan, nvlist_t *nvl, int flags __unused) | |||||
{ | |||||
assert(chan != NULL); | |||||
assert(chan->cch_magic == CAP_CHANNEL_MAGIC); | |||||
nvlist_destroy(nvl); | |||||
return (nvlist_create(0)); | |||||
} | |||||
cap_channel_t * | |||||
cap_service_open(const cap_channel_t *chan __unused, const char *name __unused) | |||||
{ | |||||
return (cap_wrap(-1)); | |||||
} | |||||
int | |||||
cap_service_limit(const cap_channel_t *chan, const char * const *names __unused, | |||||
size_t nnames __unused) | |||||
{ | |||||
assert(chan != NULL); | |||||
assert(chan->cch_magic == CAP_CHANNEL_MAGIC); | |||||
return (0); | |||||
} | |||||
bool | |||||
cap_enable(const cap_channel_t *chan) | |||||
{ | |||||
if (chan != NULL) | |||||
assert(chan->cch_magic == CAP_CHANNEL_MAGIC); | |||||
return (false); | |||||
} |