1 /* ccapi/common/win/tls.c */
2 /*
3 * Copyright 2008 Massachusetts Institute of Technology.
4 * All Rights Reserved.
5 *
6 * Export of this software from the United States of America may
7 * require a specific license from the United States Government.
8 * It is the responsibility of any person or organization contemplating
9 * export to obtain such a license before exporting.
10 *
11 * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
12 * distribute this software and its documentation for any purpose and
13 * without fee is hereby granted, provided that the above copyright
14 * notice appear in all copies and that both that copyright notice and
15 * this permission notice appear in supporting documentation, and that
16 * the name of M.I.T. not be used in advertising or publicity pertaining
17 * to distribution of the software without specific, written prior
18 * permission. Furthermore if you modify this software you must label
19 * your software as modified software and not distribute it in such a
20 * fashion that it might be confused with the original M.I.T. software.
21 * M.I.T. makes no representations about the suitability of
22 * this software for any purpose. It is provided "as is" without express
23 * or implied warranty.
24 */
25
26 #include "string.h"
27 #include <stdlib.h>
28 #include <malloc.h>
29
30 #include "tls.h"
31
tspdata_setUUID(struct tspdata * p,unsigned char __RPC_FAR * uuidString)32 void tspdata_setUUID(struct tspdata* p, unsigned char __RPC_FAR* uuidString) {
33 strncpy(p->_uuid, uuidString, UUID_SIZE-1);
34 };
35
tspdata_setListening(struct tspdata * p,BOOL b)36 void tspdata_setListening (struct tspdata* p, BOOL b) {p->_listening = b;}
37
tspdata_setConnected(struct tspdata * p,BOOL b)38 void tspdata_setConnected (struct tspdata* p, BOOL b) {p->_CCAPI_Connected = b;}
39
tspdata_setReplyEvent(struct tspdata * p,HANDLE h)40 void tspdata_setReplyEvent(struct tspdata* p, HANDLE h) {p->_replyEvent = h;}
41
tspdata_setRpcAState(struct tspdata * p,RPC_ASYNC_STATE * rpcState)42 void tspdata_setRpcAState (struct tspdata* p, RPC_ASYNC_STATE* rpcState) {
43 p->_rpcState = rpcState;}
44
tspdata_setSST(struct tspdata * p,time_t t)45 void tspdata_setSST (struct tspdata* p, time_t t) {p->_sst = t;}
46
tspdata_setStream(struct tspdata * p,k5_ipc_stream s)47 void tspdata_setStream (struct tspdata* p, k5_ipc_stream s) {p->_stream = s;}
48
tspdata_getListening(const struct tspdata * p)49 BOOL tspdata_getListening (const struct tspdata* p) {return p->_listening;}
50
tspdata_getConnected(const struct tspdata * p)51 BOOL tspdata_getConnected (const struct tspdata* p) {return p->_CCAPI_Connected;}
52
tspdata_getReplyEvent(const struct tspdata * p)53 HANDLE tspdata_getReplyEvent(const struct tspdata* p) {return p->_replyEvent;}
54
tspdata_getSST(const struct tspdata * p)55 time_t tspdata_getSST (const struct tspdata* p) {return p->_sst;}
56
tspdata_getStream(const struct tspdata * p)57 k5_ipc_stream tspdata_getStream (const struct tspdata* p) {return p->_stream;}
58
tspdata_getUUID(const struct tspdata * p)59 char* tspdata_getUUID (const struct tspdata* p) {return p->_uuid;}
60
tspdata_getRpcAState(const struct tspdata * p)61 RPC_ASYNC_STATE* tspdata_getRpcAState (const struct tspdata* p) {return p->_rpcState;}
62
63
GetTspData(DWORD dwTlsIndex,struct tspdata ** pdw)64 BOOL WINAPI GetTspData(DWORD dwTlsIndex, struct tspdata** pdw) {
65 struct tspdata* pData; // The stored memory pointer
66
67 pData = (struct tspdata*)TlsGetValue(dwTlsIndex);
68 if (pData == NULL) {
69 pData = malloc(sizeof(*pData));
70 if (pData == NULL)
71 return FALSE;
72 memset(pData, 0, sizeof(*pData));
73 TlsSetValue(dwTlsIndex, pData);
74 }
75 (*pdw) = pData;
76 return TRUE;
77 }
78