3
* Licensed Materials - Property of IBM
5
* trousers - An open source TCG Software Stack
7
* (C) Copyright International Business Machines Corp. 2004
17
#include "trousers/tss.h"
18
#include "trousers_types.h"
20
#include "hosttable.h"
24
static struct host_table *ht = NULL;
29
ht = calloc(1, sizeof(struct host_table));
31
LogError("malloc of %zd bytes failed.", sizeof(struct host_table));
32
return TSPERR(TSS_E_OUTOFMEMORY);
35
pthread_mutex_init(&ht->lock, NULL);
40
void __attribute__ ((constructor)) my_init(void)
50
struct host_table_entry *hte, *next = NULL;
52
pthread_mutex_lock(&(ht->lock));
54
for (hte = ht->entries; hte; hte = next) {
60
pthread_mutex_unlock(&(ht->lock));
66
void __attribute__ ((destructor)) my_fini(void)
73
add_table_entry(TSS_HCONTEXT tspContext, BYTE *host, int type, struct host_table_entry **ret)
75
struct host_table_entry *entry, *tmp;
77
if ((entry = calloc(1, sizeof(struct host_table_entry))) == NULL) {
78
LogError("malloc of %zd bytes failed.", sizeof(struct host_table_entry));
79
return TSPERR(TSS_E_OUTOFMEMORY);
82
entry->tspContext = tspContext;
83
entry->hostname = host;
85
entry->comm.buf_size = TCSD_INIT_TXBUF_SIZE;
86
entry->comm.buf = calloc(1, entry->comm.buf_size);
87
if (entry->comm.buf == NULL) {
88
LogError("malloc of %u bytes failed.", entry->comm.buf_size);
90
return TSPERR(TSS_E_OUTOFMEMORY);
92
pthread_mutex_init(&entry->lock, NULL);
94
pthread_mutex_lock(&ht->lock);
96
for (tmp = ht->entries; tmp; tmp = tmp->next) {
97
if (tmp->tspContext == entry->tspContext) {
98
LogError("Tspi_Context_Connect attempted on an already connected context!");
99
pthread_mutex_unlock(&ht->lock);
100
return TSPERR(TSS_E_CONNECTION_FAILED);
104
if( ht->entries == NULL ) {
107
for (tmp = ht->entries; tmp->next; tmp = tmp->next)
112
pthread_mutex_unlock(&ht->lock);
120
remove_table_entry(TSS_HCONTEXT tspContext)
122
struct host_table_entry *hte, *prev = NULL;
124
pthread_mutex_lock(&(ht->lock));
126
for (hte = ht->entries; hte; prev = hte, hte = hte->next) {
127
if (hte->tspContext == tspContext) {
129
prev->next = hte->next;
131
ht->entries = hte->next;
138
pthread_mutex_unlock(&(ht->lock));
141
struct host_table_entry *
142
get_table_entry(TSS_HCONTEXT tspContext)
144
struct host_table_entry *index = NULL;
146
pthread_mutex_lock(&(ht->lock));
148
for (index = ht->entries; index; index = index->next) {
149
if (index->tspContext == tspContext)
154
pthread_mutex_lock(&(index->lock));
156
pthread_mutex_unlock(&(ht->lock));
162
put_table_entry(struct host_table_entry *entry)
165
pthread_mutex_unlock(&(entry->lock));