2 * Copyright (c) 2010 Your File System Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR `AS IS'' AND ANY EXPRESS OR
14 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
15 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
16 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
17 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
18 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
20 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
22 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 #include <afsconfig.h>
26 #include <afs/param.h>
29 # include <sys/types.h>
32 # include "afs/sysincludes.h"
33 # include "afsincludes.h"
37 #include <rx/rx_identity.h>
40 * Check to see if two rx identities match
47 * True if a and b are identical, otherwise false
50 rx_identity_match(struct rx_identity *a, struct rx_identity *b)
52 return (a->kind == b->kind && a->exportedName.len == b->exportedName.len
53 && (memcmp(a->exportedName.val, b->exportedName.val,
54 a->exportedName.len) == 0));
58 * Populate an identity
60 * Populate an existing identity with copies of the data passed to the
61 * function. This will replace (without freeing) any existing identity
65 * The identity to populate
67 * The type of data contained within this identity
69 * The displayName of this identity
71 * The opaque data that represents this identity
73 * The length of enameData
77 rx_identity_populate(struct rx_identity *identity, rx_identity_kind kind,
78 char *displayName, void *enameData, size_t enameLength)
80 memset(identity, 0, sizeof(struct rx_identity));
82 identity->displayName = rxi_Alloc(strlen(displayName)+1);
83 memcpy(identity->displayName, displayName, strlen(displayName)+1);
85 rx_opaque_populate(&identity->exportedName, enameData, enameLength);
92 * Copy the contents of one identity into another one. This will replace
93 * (without freeing) any existing identity contents
96 * The identity to copy to
98 * The identity to copy from
102 rx_identity_copy(struct rx_identity *to, struct rx_identity *from)
104 rx_identity_populate(to, from->kind, from->displayName,
105 from->exportedName.val, from->exportedName.len);
110 * Build a new identity
112 * Create a new identity, with copies of the data passed to this function.
115 * The type of data contained within this identity
117 * The displayName of this identity
119 * The opaque data that represents this identity
121 * The length of enameData
127 rx_identity_new(rx_identity_kind kind, char *displayName, void *enameData,
130 struct rx_identity *identity;
132 identity = rxi_Alloc(sizeof(struct rx_identity));
133 rx_identity_populate(identity, kind, displayName, enameData, enameLength);
139 * Free the contents of an identity
142 * The identity to free the contents of
146 rx_identity_freeContents(struct rx_identity *identity)
148 rxi_Free(identity->displayName, strlen(identity->displayName));
149 identity->displayName = NULL;
150 rx_opaque_freeContents(&identity->exportedName);
157 * The identity to free (passed by reference)
161 rx_identity_free(struct rx_identity **identity)
163 rx_identity_freeContents(*identity);
164 rxi_Free(*identity, sizeof(struct rx_identity));