2 Copyright (c) 2014, McAfee, Inc.
6 Redistribution and use in source and binary forms, with or without modification,
7 are permitted provided that the following conditions are met:
9 Redistributions of source code must retain the above copyright notice, this list
10 of conditions and the following disclaimer.
12 Redistributions in binary form must reproduce the above copyright notice, this
13 list of conditions and the following disclaimer in the documentation and/or other
14 materials provided with the distribution.
16 Neither the name of McAfee, Inc. nor the names of its contributors may be used
17 to endorse or promote products derived from this software without specific prior
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
21 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
24 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
27 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
28 OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
29 OF THE POSSIBILITY OF SUCH DAMAGE.
34 * \brief Source File for structures needed by Ipc.
36 * This file implements the structures needed by IPC Client, used by Security framework.
43 #include "IpcStructs.h"
46 * Assign new fields to existing call handle.
47 * A NULL pPendingCall will not replace the existing one.
49 int _AssignToClientCallHandle(ClientCallHandle *pHandle, const char *szPrefix, dbus_uint32_t serial,
50 DBusPendingCall *pPendingCall)
59 if (0 > (iRet = snprintf(pHandle->idUnique, MSGHANDLE_LEN, TSC_MID_SVR_FORMAT, szPrefix,
64 pHandle->pPendingCall = pPendingCall;
73 int _CreateClientCallHandle(ClientCallHandle **ppHandle, const char *szPrefix, dbus_uint32_t serial,
74 DBusPendingCall *pPendingCall)
77 ClientCallHandle *pHandle = NULL;
84 pHandle = (ClientCallHandle *) malloc(sizeof(ClientCallHandle));
88 if ((iRet = _AssignToClientCallHandle(pHandle, szPrefix, serial, pPendingCall)))
105 void _FreeClientCallHandle(ClientCallHandle *pHandle)
110 void _FreeSharedData(SharedData *pSharedData)
114 pthread_mutex_destroy(&pSharedData->lock);
115 pthread_cond_destroy(&pSharedData->cond);
120 // Create the handle to monitor send completion and receive sent message details.
121 // Maintains only reference of DBusMessage; Ownership is not changed.
122 SharedData *_CreateSharedData(const char *szCallHandlePrefix, DBusMessage *pMsg)
125 SharedData *pSharedData = NULL;
132 if ((pSharedData = (SharedData *)calloc(1, sizeof(SharedData))) == NULL)
135 if (0 > snprintf(pSharedData->szCallHandlePrefix, MSGHANDLE_LEN, "%s", szCallHandlePrefix))
138 pSharedData->pMsg = pMsg;
139 pSharedData->pCallHandle = NULL;
140 pSharedData->iSent = 0;
142 if (pthread_mutex_init(&(pSharedData->lock), NULL))
145 if (pthread_cond_init(&(pSharedData->cond), NULL))
153 _FreeSharedData(pSharedData);
159 ThreadData *_AllocThreadData(DBusConnection *pConn, int timeout_milliseconds,
160 SharedData *pSharedData, TSCCallback pCallback, void *pPrivate)
162 ThreadData *pThreadData = (ThreadData *)dbus_malloc(sizeof(ThreadData));
166 pThreadData->pConn = pConn;
167 pThreadData->timeout_milliseconds = timeout_milliseconds;
168 pThreadData->pSharedData = pSharedData;
169 pThreadData->pCallBack = pCallback;
170 pThreadData->pPrivate = pPrivate;
175 void _FreeThreadData(void *pThreadData)
179 _FreeSharedData(((ThreadData*)pThreadData)->pSharedData);
181 dbus_free(pThreadData);
185 #include "IpcStructs.h"