Annotation of embedaddon/strongswan/src/libimcv/pts/pts_symlinks.c, revision 1.1
1.1 ! misho 1: /*
! 2: * Copyright (C) 2020 Andreas Steffen
! 3: * HSR Hochschule fuer Technik Rapperswil
! 4: *
! 5: * This program is free software; you can redistribute it and/or modify it
! 6: * under the terms of the GNU General Public License as published by the
! 7: * Free Software Foundation; either version 2 of the License, or (at your
! 8: * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
! 9: *
! 10: * This program is distributed in the hope that it will be useful, but
! 11: * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
! 12: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
! 13: * for more details.
! 14: */
! 15:
! 16: #include "pts_symlinks.h"
! 17:
! 18: #include <collections/linked_list.h>
! 19: #include <utils/debug.h>
! 20:
! 21: typedef struct private_pts_symlinks_t private_pts_symlinks_t;
! 22: typedef struct entry_t entry_t;
! 23:
! 24: /**
! 25: * Private data of a pts_symlinks_t object.
! 26: *
! 27: */
! 28: struct private_pts_symlinks_t {
! 29:
! 30: /**
! 31: * Public pts_symlinks_t interface.
! 32: */
! 33: pts_symlinks_t public;
! 34:
! 35: /**
! 36: * List of symbolic links pointing to directories
! 37: */
! 38: linked_list_t *list;
! 39:
! 40: /**
! 41: * Reference count
! 42: */
! 43: refcount_t ref;
! 44:
! 45: };
! 46:
! 47: /**
! 48: * Symlink entry
! 49: */
! 50: struct entry_t {
! 51: chunk_t symlink;
! 52: chunk_t dir;
! 53: };
! 54:
! 55: /**
! 56: * Free an entry_t object
! 57: */
! 58: static void free_entry(entry_t *entry)
! 59: {
! 60: if (entry)
! 61: {
! 62: free(entry->symlink.ptr);
! 63: free(entry->dir.ptr);
! 64: free(entry);
! 65: }
! 66: }
! 67:
! 68: METHOD(pts_symlinks_t, get_count, int,
! 69: private_pts_symlinks_t *this)
! 70: {
! 71: return this->list->get_count(this->list);
! 72: }
! 73:
! 74: METHOD(pts_symlinks_t, add, void,
! 75: private_pts_symlinks_t *this, chunk_t symlink, chunk_t dir)
! 76: {
! 77: entry_t *entry;
! 78:
! 79: entry = malloc_thing(entry_t);
! 80: entry->symlink = chunk_clone(symlink);
! 81: entry->dir = chunk_clone(dir);
! 82:
! 83: this->list->insert_last(this->list, entry);
! 84: }
! 85:
! 86: CALLBACK(symlink_filter, bool,
! 87: void *null, enumerator_t *orig, va_list args)
! 88: {
! 89: entry_t *entry;
! 90: chunk_t *symlink;
! 91: chunk_t *dir;
! 92:
! 93: VA_ARGS_VGET(args, symlink, dir);
! 94:
! 95: if (orig->enumerate(orig, &entry))
! 96: {
! 97: *symlink = entry->symlink;
! 98: *dir = entry->dir;
! 99: return TRUE;
! 100: }
! 101: return FALSE;
! 102: }
! 103:
! 104: METHOD(pts_symlinks_t, create_enumerator, enumerator_t*,
! 105: private_pts_symlinks_t *this)
! 106: {
! 107: return enumerator_create_filter(this->list->create_enumerator(this->list),
! 108: symlink_filter, NULL, NULL);
! 109: }
! 110:
! 111: METHOD(pts_symlinks_t, get_ref, pts_symlinks_t*,
! 112: private_pts_symlinks_t *this)
! 113: {
! 114: ref_get(&this->ref);
! 115: return &this->public;
! 116: }
! 117:
! 118: METHOD(pts_symlinks_t, destroy, void,
! 119: private_pts_symlinks_t *this)
! 120: {
! 121: if (ref_put(&this->ref))
! 122: {
! 123: this->list->destroy_function(this->list, (void *)free_entry);
! 124: free(this);
! 125: }
! 126: }
! 127:
! 128: /**
! 129: * See header
! 130: */
! 131: pts_symlinks_t *pts_symlinks_create()
! 132: {
! 133: private_pts_symlinks_t *this;
! 134:
! 135: INIT(this,
! 136: .public = {
! 137: .get_count = _get_count,
! 138: .add = _add,
! 139: .create_enumerator = _create_enumerator,
! 140: .get_ref = _get_ref,
! 141: .destroy = _destroy,
! 142: },
! 143: .list = linked_list_create(),
! 144: .ref = 1,
! 145: );
! 146:
! 147: return &this->public;
! 148: }
! 149:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>