Path: blob/main/crypto/krb5/src/util/profile/testmod/testmod_main.c
34907 views
/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */1/* util/profile/proftest/test.c - Test dynamic profile module */2/*3* Copyright (C) 2011 by the Massachusetts Institute of Technology.4* All rights reserved.5*6* Export of this software from the United States of America may7* require a specific license from the United States Government.8* It is the responsibility of any person or organization contemplating9* export to obtain such a license before exporting.10*11* WITHIN THAT CONSTRAINT, permission to use, copy, modify, and12* distribute this software and its documentation for any purpose and13* without fee is hereby granted, provided that the above copyright14* notice appear in all copies and that both that copyright notice and15* this permission notice appear in supporting documentation, and that16* the name of M.I.T. not be used in advertising or publicity pertaining17* to distribution of the software without specific, written prior18* permission. Furthermore if you modify this software you must label19* your software as modified software and not distribute it in such a20* fashion that it might be confused with the original M.I.T. software.21* M.I.T. makes no representations about the suitability of22* this software for any purpose. It is provided "as is" without express23* or implied warranty.24*/2526/*27* This file implements a very simple profile module which just returns the28* residual string and the number of copies in response to any query. The full29* range of vtable profile operations is tested elsewhere.30*/3132#include "k5-platform.h"33#include "profile.h"3435struct data {36char *residual;37int gen;38};3940static long41get_values(void *cbdata, const char *const *names, char ***ret_values)42{43struct data *d = cbdata;4445*ret_values = calloc(3, sizeof(*ret_values));46(*ret_values)[0] = strdup(d->residual);47asprintf(&(*ret_values)[1], "%d", d->gen);48(*ret_values)[2] = NULL;49return 0;50}5152static void53free_values(void *cbdata, char **values)54{55char **v;5657for (v = values; *v; v++)58free(*v);59free(values);60}6162static void63cleanup(void *cbdata)64{65struct data *d = cbdata;6667free(d->residual);68free(d);69}7071static long72copy(void *cbdata, void **ret_cbdata)73{74struct data *old_data = cbdata, *new_data;7576new_data = malloc(sizeof(*new_data));77new_data->residual = strdup(old_data->residual);78new_data->gen = old_data->gen + 1;79*ret_cbdata = new_data;80return 0;81}8283long84profile_module_init(const char *residual, struct profile_vtable *vtable,85void **cb_ret);8687long88profile_module_init(const char *residual, struct profile_vtable *vtable,89void **cb_ret)90{91struct data *d;9293d = malloc(sizeof(*d));94d->residual = strdup(residual);95d->gen = 0;96*cb_ret = d;9798vtable->get_values = get_values;99vtable->free_values = free_values;100vtable->cleanup = cleanup;101vtable->copy = copy;102return 0;103}104105106