1
/* ***** BEGIN LICENSE BLOCK *****
2
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
4
* The contents of this file are subject to the Mozilla Public License Version
5
* 1.1 (the "License"); you may not use this file except in compliance with
6
* the License. You may obtain a copy of the License at
7
* http://www.mozilla.org/MPL/
9
* Software distributed under the License is distributed on an "AS IS" basis,
10
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11
* for the specific language governing rights and limitations under the
14
* The Original Code is Mozilla IPC.
16
* The Initial Developer of the Original Code is
17
* Netscape Communications Corporation.
18
* Portions created by the Initial Developer are Copyright (C) 2002
19
* the Initial Developer. All Rights Reserved.
22
* Darin Fisher <darin@netscape.com>
24
* Alternatively, the contents of this file may be used under the terms of
25
* either the GNU General Public License Version 2 or later (the "GPL"), or
26
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27
* in which case the provisions of the GPL or the LGPL are applicable instead
28
* of those above. If you wish to allow use of your version of this file only
29
* under the terms of either the GPL or the LGPL, and not to allow others to
30
* use your version of this file under the terms of the MPL, indicate your
31
* decision by deleting the provisions above and replace them with the notice
32
* and other provisions required by the GPL or the LGPL. If you do not delete
33
* the provisions above, a recipient may use your version of this file under
34
* the terms of any one of the MPL, the GPL or the LGPL.
36
* ***** END LICENSE BLOCK ***** */
42
const nsID IPCM_TARGET =
43
{ /* 753ca8ff-c8c2-4601-b115-8c2944da1150 */
47
{0xb1, 0x15, 0x8c, 0x29, 0x44, 0xda, 0x11, 0x50}
51
IPCM_NewRequestIndex()
53
static PRInt32 sRequestIndex;
54
return (PRUint32) PR_AtomicIncrement(&sRequestIndex);
62
const PRUint32 ipcmMessagePing::MSG_TYPE = IPCM_MSG_TYPE_PING;
63
const PRUint32 ipcmMessageError::MSG_TYPE = IPCM_MSG_TYPE_ERROR;
64
const PRUint32 ipcmMessageClientHello::MSG_TYPE = IPCM_MSG_TYPE_CLIENT_HELLO;
65
const PRUint32 ipcmMessageClientID::MSG_TYPE = IPCM_MSG_TYPE_CLIENT_ID;
66
const PRUint32 ipcmMessageClientInfo::MSG_TYPE = IPCM_MSG_TYPE_CLIENT_INFO;
67
const PRUint32 ipcmMessageClientAddName::MSG_TYPE = IPCM_MSG_TYPE_CLIENT_ADD_NAME;
68
const PRUint32 ipcmMessageClientDelName::MSG_TYPE = IPCM_MSG_TYPE_CLIENT_DEL_NAME;
69
const PRUint32 ipcmMessageClientAddTarget::MSG_TYPE = IPCM_MSG_TYPE_CLIENT_ADD_TARGET;
70
const PRUint32 ipcmMessageClientDelTarget::MSG_TYPE = IPCM_MSG_TYPE_CLIENT_DEL_TARGET;
71
const PRUint32 ipcmMessageQueryClientByName::MSG_TYPE = IPCM_MSG_TYPE_QUERY_CLIENT_BY_NAME;
72
const PRUint32 ipcmMessageQueryClientInfo::MSG_TYPE = IPCM_MSG_TYPE_QUERY_CLIENT_INFO;
73
const PRUint32 ipcmMessageForward::MSG_TYPE = IPCM_MSG_TYPE_FORWARD;
74
const PRUint32 ipcmMessageClientStatus::MSG_TYPE = IPCM_MSG_TYPE_CLIENT_STATUS;
77
// CLIENT_INFO message
79
// +-----------------------------------------+
80
// | DWORD : MSG_TYPE |
81
// +--------------------+--------------------+
82
// | DWORD : clientID |
83
// +--------------------+--------------------+
84
// | DWORD : requestIndex |
85
// +--------------------+--------------------+
86
// | WORD : nameStart | WORD : nameCount |
87
// +--------------------+--------------------+
88
// | WORD : targetStart | WORD : targetCount |
89
// +--------------------+--------------------+
90
// | name[0] | (null byte) |
91
// +--------------------+--------------------+
94
// +--------------------+--------------------+
95
// | name[count - 1] | (null byte) |
96
// +--------------------+--------------------+
98
// +-----------------------------------------+
101
// +-----------------------------------------+
102
// | target[count - 1] |
103
// +-----------------------------------------+
106
struct ipcmClientInfoHeader
110
PRUint32 mRequestIndex;
113
PRUint16 mTargetStart;
114
PRUint16 mTargetCount;
117
ipcmMessageClientInfo::ipcmMessageClientInfo(PRUint32 cID, PRUint32 rIdx, const char *names[], const nsID *targets[])
119
ipcmClientInfoHeader hdr = {0};
121
hdr.mType = MSG_TYPE;
123
hdr.mRequestIndex = rIdx;
124
hdr.mNameStart = sizeof(hdr);
126
PRUint32 i, namesLen = 0;
130
namesLen += (strlen(names[i]) + 1);
142
// compute target array starting offset
144
hdr.mTargetStart = hdr.mNameStart + namesLen;
147
// compute message length
149
PRUint32 dataLen = sizeof(hdr) + namesLen + hdr.mTargetCount * sizeof(nsID);
151
Init(IPCM_TARGET, NULL, dataLen);
154
// write message data
156
SetData(0, (const char *) &hdr, sizeof(hdr));
158
PRUint32 offset = sizeof(hdr);
160
for (i = 0; names[i]; ++i) {
161
PRUint32 len = strlen(names[i]) + 1;
162
SetData(offset, names[i], len);
166
for (i = 0; targets[i]; ++i) {
167
PRUint32 len = sizeof(nsID);
168
SetData(offset, (const char *) targets[i], len);
174
ipcmMessageClientInfo::ClientID() const
176
ipcmClientInfoHeader *hdr = (ipcmClientInfoHeader *) Data();
181
ipcmMessageClientInfo::RequestIndex() const
183
ipcmClientInfoHeader *hdr = (ipcmClientInfoHeader *) Data();
184
return hdr->mRequestIndex;
188
ipcmMessageClientInfo::NameCount() const
190
ipcmClientInfoHeader *hdr = (ipcmClientInfoHeader *) Data();
191
return hdr->mNameCount;
195
ipcmMessageClientInfo::TargetCount() const
197
ipcmClientInfoHeader *hdr = (ipcmClientInfoHeader *) Data();
198
return hdr->mTargetCount;
202
ipcmMessageClientInfo::NextName(const char *name) const
204
ipcmClientInfoHeader *hdr = (ipcmClientInfoHeader *) Data();
207
return (const char *) hdr + hdr->mNameStart;
209
name += strlen(name) + 1;
210
if (name == (const char *) hdr + hdr->mTargetStart)
216
ipcmMessageClientInfo::NextTarget(const nsID *target) const
218
ipcmClientInfoHeader *hdr = (ipcmClientInfoHeader *) Data();
221
return (const nsID *) (Data() + hdr->mTargetStart);
223
if (++target == (const nsID *) (MsgBuf() + MsgLen()))
232
// +-------------------------+
233
// | DWORD : MSG_TYPE |
234
// +-------------------------+
236
// +-------------------------+
237
// | innerMsgHeader |
238
// +-------------------------+
240
// +-------------------------+
243
ipcmMessageForward::ipcmMessageForward(PRUint32 type,
249
int len = sizeof(ipcmMessageHeader) + // IPCM header
251
IPC_MSG_HEADER_SIZE + // innerMsgHeader
252
dataLen; // innerMsgData
254
Init(IPCM_TARGET, NULL, len);
256
ipcmMessageHeader ipcmHdr =
257
{ type, IPCM_NewRequestIndex() };
259
SetData(0, (char *) &ipcmHdr, sizeof(ipcmHdr));
260
SetData(sizeof(ipcmHdr), (char *) &cID, sizeof(cID));
262
ipcMessageHeader hdr;
263
hdr.mLen = IPC_MSG_HEADER_SIZE + dataLen;
264
hdr.mVersion = IPC_MSG_VERSION;
266
hdr.mTarget = target;
268
SetData(sizeof(ipcmHdr) + sizeof(cID), (char *) &hdr, IPC_MSG_HEADER_SIZE);
270
SetInnerData(0, data, dataLen);
274
ipcmMessageForward::SetInnerData(PRUint32 offset, const char *data, PRUint32 dataLen)
276
SetData(sizeof(ipcmMessageHeader) + 4 + IPC_MSG_HEADER_SIZE + offset, data, dataLen);
280
ipcmMessageForward::ClientID() const
282
return ((PRUint32 *) Data())[2];
286
ipcmMessageForward::InnerTarget() const
288
ipcMessageHeader *hdr = (ipcMessageHeader *) (Data() + 12);
293
ipcmMessageForward::InnerData() const
295
return Data() + 12 + IPC_MSG_HEADER_SIZE;
299
ipcmMessageForward::InnerDataLen() const
301
ipcMessageHeader *hdr = (ipcMessageHeader *) (Data() + 12);
302
return hdr->mLen - IPC_MSG_HEADER_SIZE;