Shrink principals struct back to where it was last week -- but it could go further (93043, r=shaver, sr=jst).
This commit is contained in:
Родитель
8e03c80014
Коммит
138a297e1f
|
@ -70,77 +70,73 @@ nsDestroyJSPrincipals(JSContext *cx, struct JSPrincipals *jsprin)
|
|||
}
|
||||
|
||||
JS_STATIC_DLL_CALLBACK(JSBool)
|
||||
nsDecodeJSPrincipals(JSXDRState *xdr, JSPrincipals **jsprinp)
|
||||
nsTranscodeJSPrincipals(JSXDRState *xdr, JSPrincipals **jsprinp)
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIPrincipal> prin;
|
||||
|
||||
NS_ASSERTION(JS_XDRMemDataLeft(xdr) == 0, "XDR out of sync?!");
|
||||
if (xdr->mode == JSXDR_ENCODE) {
|
||||
nsIObjectOutputStream *stream =
|
||||
NS_REINTERPRET_CAST(nsIObjectOutputStream*, xdr->userdata);
|
||||
|
||||
nsIObjectInputStream *stream = NS_REINTERPRET_CAST(nsIObjectInputStream*,
|
||||
xdr->userdata);
|
||||
// Flush xdr'ed data to the underlying object output stream.
|
||||
uint32 size;
|
||||
char *data = (char*) ::JS_XDRMemGetData(xdr, &size);
|
||||
|
||||
rv = stream->ReadObject(PR_TRUE, getter_AddRefs(prin));
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
PRUint32 size;
|
||||
rv = stream->Read32(&size);
|
||||
rv = stream->Write32(size);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
char *data = nsnull;
|
||||
if (size != 0)
|
||||
rv = stream->ReadBytes(&data, size);
|
||||
rv = stream->WriteBytes(data, size);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
char *olddata;
|
||||
uint32 oldsize;
|
||||
::JS_XDRMemResetData(xdr);
|
||||
|
||||
// Any decode-mode JSXDRState whose userdata points to an
|
||||
// nsIObjectInputStream instance must use nsMemory to allocate
|
||||
// and free its data buffer. So swap the new buffer we just
|
||||
// read for the old, exhausted data.
|
||||
// Require that GetJSPrincipals has been called already by the
|
||||
// code that compiled the script that owns the principals.
|
||||
nsJSPrincipals *nsjsprin =
|
||||
NS_STATIC_CAST(nsJSPrincipals*, *jsprinp);
|
||||
|
||||
olddata = (char*) ::JS_XDRMemGetData(xdr, &oldsize);
|
||||
nsMemory::Free(olddata);
|
||||
::JS_XDRMemSetData(xdr, data, size);
|
||||
rv = stream->WriteObject(nsjsprin->nsIPrincipalPtr, PR_TRUE);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
NS_ASSERTION(JS_XDRMemDataLeft(xdr) == 0, "XDR out of sync?!");
|
||||
nsIObjectInputStream *stream =
|
||||
NS_REINTERPRET_CAST(nsIObjectInputStream*, xdr->userdata);
|
||||
|
||||
nsCOMPtr<nsIPrincipal> prin;
|
||||
rv = stream->ReadObject(PR_TRUE, getter_AddRefs(prin));
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
PRUint32 size;
|
||||
rv = stream->Read32(&size);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
char *data = nsnull;
|
||||
if (size != 0)
|
||||
rv = stream->ReadBytes(&data, size);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
char *olddata;
|
||||
uint32 oldsize;
|
||||
|
||||
// Any decode-mode JSXDRState whose userdata points to an
|
||||
// nsIObjectInputStream instance must use nsMemory to Alloc
|
||||
// and Free its data buffer. Swap the new buffer we just
|
||||
// read for the old, exhausted data.
|
||||
olddata = (char*) ::JS_XDRMemGetData(xdr, &oldsize);
|
||||
nsMemory::Free(olddata);
|
||||
::JS_XDRMemSetData(xdr, data, size);
|
||||
|
||||
prin->GetJSPrincipals(jsprinp);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (NS_FAILED(rv)) {
|
||||
::JS_ReportError(xdr->cx, "can't decode principals (failure code %x)",
|
||||
::JS_ReportError(xdr->cx, "can't %scode principals (failure code %x)",
|
||||
(xdr->mode == JSXDR_ENCODE) ? "en" : "de",
|
||||
(unsigned int) rv);
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
prin->GetJSPrincipals(jsprinp);
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
JS_STATIC_DLL_CALLBACK(JSBool)
|
||||
nsEncodeJSPrincipals(JSXDRState *xdr, struct JSPrincipals *jsprin)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
// Flush xdr'ed data to the underlying object output stream.
|
||||
nsIObjectOutputStream *stream = NS_REINTERPRET_CAST(nsIObjectOutputStream*,
|
||||
xdr->userdata);
|
||||
uint32 size;
|
||||
char *data = (char*) ::JS_XDRMemGetData(xdr, &size);
|
||||
|
||||
rv = stream->Write32(size);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
rv = stream->WriteBytes(data, size);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
::JS_XDRMemResetData(xdr);
|
||||
|
||||
// Require that GetJSPrincipals has been called already by the code that
|
||||
// compiled the script that owns this principals instance.
|
||||
nsJSPrincipals *nsjsprin = NS_STATIC_CAST(nsJSPrincipals *, jsprin);
|
||||
nsCOMPtr<nsIPrincipal> prin = nsjsprin->nsIPrincipalPtr;
|
||||
|
||||
rv = stream->WriteObject(prin, PR_TRUE);
|
||||
return NS_SUCCEEDED(rv); // NB: guaranteed to be 0 or 1
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsJSPrincipals::Startup()
|
||||
{
|
||||
|
@ -153,9 +149,9 @@ nsJSPrincipals::Startup()
|
|||
rtsvc->GetRuntime(&rt);
|
||||
NS_ASSERTION(rt != nsnull, "no JSRuntime?!");
|
||||
|
||||
JSPrincipalsDecoder oldpd;
|
||||
oldpd = ::JS_SetPrincipalsDecoder(rt, nsDecodeJSPrincipals);
|
||||
NS_ASSERTION(oldpd == nsnull, "oops, JS_SetPrincipalsDecoder wars!");
|
||||
JSPrincipalsTranscoder oldpx;
|
||||
oldpx = ::JS_SetPrincipalsTranscoder(rt, nsTranscodeJSPrincipals);
|
||||
NS_ASSERTION(oldpx == nsnull, "oops, JS_SetPrincipalsTranscoder wars!");
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -167,7 +163,6 @@ nsJSPrincipals::nsJSPrincipals()
|
|||
globalPrivilegesEnabled = nsGlobalPrivilegesEnabled;
|
||||
refcount = 0;
|
||||
destroy = nsDestroyJSPrincipals;
|
||||
encode = nsEncodeJSPrincipals;
|
||||
nsIPrincipalPtr = nsnull;
|
||||
}
|
||||
|
||||
|
|
|
@ -2694,14 +2694,14 @@ JS_SetReservedSlot(JSContext *cx, JSObject *obj, uint32 index, jsval v)
|
|||
return JS_TRUE;
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(JSPrincipalsDecoder)
|
||||
JS_SetPrincipalsDecoder(JSRuntime *rt, JSPrincipalsDecoder pd)
|
||||
JS_PUBLIC_API(JSPrincipalsTranscoder)
|
||||
JS_SetPrincipalsTranscoder(JSRuntime *rt, JSPrincipalsTranscoder px)
|
||||
{
|
||||
JSPrincipalsDecoder oldpd;
|
||||
JSPrincipalsTranscoder oldpx;
|
||||
|
||||
oldpd = rt->principalsDecoder;
|
||||
rt->principalsDecoder = pd;
|
||||
return oldpd;
|
||||
oldpx = rt->principalsTranscoder;
|
||||
rt->principalsTranscoder = px;
|
||||
return oldpx;
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(JSFunction *)
|
||||
|
|
|
@ -1035,9 +1035,6 @@ struct JSPrincipals {
|
|||
/* Don't call "destroy"; use reference counting macros below. */
|
||||
uintN refcount;
|
||||
void (* JS_DLL_CALLBACK destroy)(JSContext *cx, struct JSPrincipals *);
|
||||
|
||||
/* XDR API extension hook; if null then this principals isn't XDRable. */
|
||||
JSBool (* JS_DLL_CALLBACK encode)(JSXDRState *xdr, JSPrincipals *);
|
||||
};
|
||||
|
||||
#define JSPRINCIPALS_HOLD(cx, principals) \
|
||||
|
@ -1047,8 +1044,8 @@ struct JSPrincipals {
|
|||
? (*(principals)->destroy)((cx), (principals)) \
|
||||
: (void) 0)
|
||||
|
||||
extern JS_PUBLIC_API(JSPrincipalsDecoder)
|
||||
JS_SetPrincipalsDecoder(JSRuntime *rt, JSPrincipalsDecoder pd);
|
||||
extern JS_PUBLIC_API(JSPrincipalsTranscoder)
|
||||
JS_SetPrincipalsTranscoder(JSRuntime *rt, JSPrincipalsTranscoder px);
|
||||
|
||||
/************************************************************************/
|
||||
|
||||
|
|
|
@ -185,7 +185,7 @@ struct JSRuntime {
|
|||
#endif
|
||||
|
||||
/* Security principals serialization support. */
|
||||
JSPrincipalsDecoder principalsDecoder;
|
||||
JSPrincipalsTranscoder principalsTranscoder;
|
||||
|
||||
#ifdef DEBUG
|
||||
/* Function invocation metering. */
|
||||
|
|
|
@ -501,10 +501,16 @@ typedef JSBool
|
|||
*/
|
||||
typedef struct JSPrincipals JSPrincipals;
|
||||
|
||||
/* NB: implementations must JSPRINCIPALS_HOLD *principalsp before returning. */
|
||||
/*
|
||||
* XDR-encode or -decode a principals instance, based on whether xdr->mode is
|
||||
* JSXDR_ENCODE, in which case *principalsp should be encoded; or JSXDR_DECODE,
|
||||
* in which case implementations must return a held (via JSPRINCIPALS_HOLD),
|
||||
* non-null *principalsp out parameter. Return true on success, false on any
|
||||
* error, which the implementation must have reported.
|
||||
*/
|
||||
typedef JSBool
|
||||
(* JS_DLL_CALLBACK JSPrincipalsDecoder)(JSXDRState *xdr,
|
||||
JSPrincipals **principalsp);
|
||||
(* JS_DLL_CALLBACK JSPrincipalsTranscoder)(JSXDRState *xdr,
|
||||
JSPrincipals **principalsp);
|
||||
|
||||
JS_END_EXTERN_C
|
||||
|
||||
|
|
|
@ -417,21 +417,23 @@ js_XDRScript(JSXDRState *xdr, JSScript **scriptp, JSBool *hasMagic)
|
|||
|
||||
if (xdr->mode == JSXDR_ENCODE) {
|
||||
principals = script->principals;
|
||||
encodeable = (principals && principals->encode);
|
||||
encodeable = (xdr->cx->runtime->principalsTranscoder != NULL);
|
||||
if (!JS_XDRUint32(xdr, &encodeable))
|
||||
goto error;
|
||||
if (encodeable && !principals->encode(xdr, principals))
|
||||
if (encodeable &&
|
||||
!xdr->cx->runtime->principalsTranscoder(xdr, &principals)) {
|
||||
goto error;
|
||||
}
|
||||
} else {
|
||||
if (!JS_XDRUint32(xdr, &encodeable))
|
||||
goto error;
|
||||
if (encodeable) {
|
||||
if (!xdr->cx->runtime->principalsDecoder) {
|
||||
if (!xdr->cx->runtime->principalsTranscoder) {
|
||||
JS_ReportErrorNumber(xdr->cx, js_GetErrorMessage, NULL,
|
||||
JSMSG_CANT_DECODE_PRINCIPALS);
|
||||
goto error;
|
||||
}
|
||||
if (!xdr->cx->runtime->principalsDecoder(xdr, &principals))
|
||||
if (!xdr->cx->runtime->principalsTranscoder(xdr, &principals))
|
||||
goto error;
|
||||
script->principals = principals;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче