/*  The hash table is keyed by attribute name, and contains pointers to the
 *  PRCList headers.  These in turn, circularly link a set of AttrGetter_s
 *  structures.
 */
NSAPI_PUBLIC int
ACL_AttrGetterRegister(NSErr_t *errp, const char *attr, ACLAttrGetterFn_t fn,
                       ACLMethod_t m, ACLDbType_t d, int position, void *arg)
{
    ACLAttrGetter_t	*getter;
    PRHashEntry         **hep;

    if (position != ACL_AT_FRONT  &&  position != ACL_AT_END) {
	return -1;
    }

    ACL_CritEnter();
    
    hep = PR_HashTableRawLookup(ACLAttrGetterHash, ACLPR_HashCaseString(attr), attr);

    /*  Now, allocate the current entry  */
    getter = (ACLAttrGetter_t *)CALLOC(sizeof(ACLAttrGetter_t));
    if (getter == NULL) {
        ACL_CritExit();
        return -1;
    }
    getter->method	= m;
    getter->dbtype	= d;
    getter->fn	= fn;
    getter->arg = arg;

    if (*hep == 0) {	/* New entry */

	PR_INIT_CLIST(&getter->list);
        PR_HashTableAdd(ACLAttrGetterHash, attr, (void *)getter);
    }
    else {

        ACLAttrGetter_t *head = (ACLAttrGetter_t *)((*hep)->value);

        PR_INSERT_BEFORE(&getter->list, &head->list);

        if (position == ACL_AT_FRONT) {

            /* Set new head of list */
            (*hep)->value = (void *)getter;
        }
    }

    ACL_CritExit();
    return 0;
}
Beispiel #2
0
void 
jsd_JSContextUsed(JSDContext* jsdc, JSContext* context)
{
    JSDContextWrapper* wrapper;
    PRHashEntry*       he;

    wrapper = _jsd_JSDContextWrapperForJSContext(jsdc, context);
    if( wrapper )
    {
        /* error reporters are sometimes overwritten by other code... */
        JSErrorReporter oldrep = JS_SetErrorReporter(context, jsd_ErrorReporter);
        if( jsd_ErrorReporter != oldrep )
            wrapper->originalErrorReporter = oldrep;
        return;
    }

    /* else... */
    wrapper = (JSDContextWrapper*) calloc(1,sizeof(JSDContextWrapper));
    if( ! wrapper )
        return;

    JSD_LOCK();
    he = PR_HashTableAdd(jsdc->jscontexts, context, wrapper);
    JSD_UNLOCK();
    if( ! he )
    {
        free(wrapper);
        return;
    }

    wrapper->context = context;
    wrapper->jsdc    = jsdc;

    /* add our error reporter */
    wrapper->originalErrorReporter = JS_SetErrorReporter(context, jsd_ErrorReporter);

    /* add our printer */
    /* add our loader */
}
Beispiel #3
0
/*  LASDNSBuild
 *  Builds a hash table of all the hostnames provided (plus their aliases
 *  if aliasflg is true).  Wildcards are only permitted in the leftmost
 *  field.  They're represented in the hash table by a leading period.
 *  E.g. ".mcom.com".
 *
 *  RETURNS	Zero on success, else LAS_EVAL_INVALID
 */
int
LASDnsBuild(NSErr_t *errp, char *attr_pattern, LASDnsContext_t *context, int aliasflg)
{
    size_t delimiter; /* length of valid tokeni */
    char token[256];  /* max length dns name */
    int i;
    char **p;
    pool_handle_t *pool;
    PRStatus error=PR_SUCCESS;
    char	buffer[PR_NETDB_BUF_SIZE];
#ifdef	UTEST
    struct hostent *he, host;
#else
    PRHostEnt *he, host;
#endif
    char *end_attr_pattern;

    if (attr_pattern == NULL) {
        nserrGenerate(errp, ACLERRINVAL, ACLERR4770, ACL_Program, 1,
                      XP_GetAdminStr(DBT_lasdnsbuildInvalidAttributePattern_));
        return LAS_EVAL_INVALID;
    }

    context->Table = PR_NewHashTable(0,
                                     PR_HashCaseString,
                                     PR_CompareCaseStrings,
                                     PR_CompareValues,
                                     &ACLPermAllocOps,
                                     NULL);
    pool = pool_create();
    context->pool = pool;
    if ((!context->Table) || (!context->pool)) {
        nserrGenerate(errp, ACLERRNOMEM, ACLERR4700, ACL_Program, 1,
                      XP_GetAdminStr(DBT_lasdnsbuildUnableToAllocateHashT_));
        return LAS_EVAL_INVALID;
    }

    end_attr_pattern = attr_pattern + strlen(attr_pattern);
    do {
        size_t maxsize = sizeof(token);
        /*  Get a single hostname from the pattern string        */
        delimiter = strcspn(attr_pattern, ", \t");
        if (delimiter >= maxsize) {
            delimiter = maxsize-1;
        }
        PL_strncpyz(token, attr_pattern, delimiter + 1);
        token[delimiter] = '\0';

        /*  Skip any white space after the token                 */
        attr_pattern += delimiter;
        if (attr_pattern < end_attr_pattern) {
            attr_pattern += strspn(attr_pattern, ", \t");
        }

        /*  If there's a wildcard, strip it off but leave the "."
         *  Can't have aliases for a wildcard pattern.
         *  Treat "*" as a special case.  If so, go ahead and hash it.
         */
        if (token[0] == '*') {
            if (token[1] != '\0') {
                if (!PR_HashTableAdd(context->Table, pool_strdup(pool, &token[1]), (void *)-1)) {
                    nserrGenerate(errp, ACLERRFAIL, ACLERR4710, ACL_Program, 2,
                                  XP_GetAdminStr(DBT_lasdnsbuildUnableToAddKeySN_), token);
                    return LAS_EVAL_INVALID;
                }
            } else {
                if (!PR_HashTableAdd(context->Table, pool_strdup(pool, token), (void *)-1)) {
                    nserrGenerate(errp, ACLERRFAIL, ACLERR4720, ACL_Program, 2, XP_GetAdminStr(DBT_lasdnsbuildUnableToAddKeySN_), token);
                    return LAS_EVAL_INVALID;
                }
            }
        } else  {
            /*  This is a single hostname add it to the hash table        */
            if (!PR_HashTableAdd(context->Table, pool_strdup(pool, &token[0]), (void *)-1)) {
                nserrGenerate(errp, ACLERRFAIL, ACLERR4730, ACL_Program, 2, XP_GetAdminStr(DBT_lasdnsbuildUnableToAddKeySN_), token);
                return LAS_EVAL_INVALID;
            }

            if (aliasflg) {
                void *iter = NULL;
                int addrcnt = 0;
                PRNetAddr *netaddr = (PRNetAddr *)PERM_CALLOC(sizeof(PRNetAddr));
                PRAddrInfo *infop = PR_GetAddrInfoByName(token,
                                    PR_AF_UNSPEC, (PR_AI_ADDRCONFIG|PR_AI_NOCANONNAME));
                if (!netaddr) {
                    if (infop) {
                        PR_FreeAddrInfo(infop);
                    }
                    return LAS_EVAL_NEED_MORE_INFO; /* hostname not known to dns? */
                }
                if (!infop) {
                    if (netaddr) {
                        PERM_FREE(netaddr);
                    }
                    return LAS_EVAL_NEED_MORE_INFO; /* hostname not known to dns? */
                }
                /* need to count the address, first */
                while ((iter = PR_EnumerateAddrInfo(iter, infop, 0, netaddr))) {
                    addrcnt++;
                }
                if (0 == addrcnt) {
                    PERM_FREE(netaddr);
                    PR_FreeAddrInfo(infop);
                    return LAS_EVAL_NEED_MORE_INFO; /* hostname not known to dns? */
                }
                iter = NULL; /* from the beginning */
                memset(netaddr, 0, sizeof(PRNetAddr));
                for (i = 0; i < addrcnt; i++) {
                    iter = PR_EnumerateAddrInfo( iter, infop, 0, netaddr );
                    if (NULL == iter) {
                        break;
                    }
                    error = PR_GetHostByAddr(netaddr, buffer,
                                             PR_NETDB_BUF_SIZE, &host);
                    if (error == PR_SUCCESS) {
                        he = &host;
                    } else {
                        continue;
                    }
                    if (he->h_name) {
                        /* Add it to the hash table */
                        if (!PR_HashTableAdd(context->Table,
                                             pool_strdup(pool, he->h_name),
                                             (void *)-1)) {
                            nserrGenerate(errp, ACLERRFAIL, ACLERR4750,
                                          ACL_Program, 2,
                                          XP_GetAdminStr(DBT_lasdnsbuildUnableToAddKeySN_),
                                          he->h_name);
                            PERM_FREE(netaddr);
                            PR_FreeAddrInfo(infop);
                            return LAS_EVAL_INVALID;
                        }
                    }

                    if (he->h_aliases && he->h_aliases[0]) {
                        for (p = he->h_aliases; *p; ++p) {
                            /* Add it to the hash table */
                            if (!PR_HashTableAdd(context->Table,
                                                 pool_strdup(pool, *p),
                                                 (void *)-1)) {
                                nserrGenerate(errp, ACLERRFAIL, ACLERR4760,
                                              ACL_Program, 2,
                                              XP_GetAdminStr(DBT_lasdnsbuildUnableToAddKeySN_),
                                              *p);
                                PERM_FREE(netaddr);
                                PR_FreeAddrInfo(infop);
                                return LAS_EVAL_INVALID;
                            }
                        }
                    }
                } /* for (i = 0; i < addrcnt; i++) */
                PERM_FREE(netaddr);
                PR_FreeAddrInfo(infop);
            } /* if aliasflg */
        } /* else - single hostname */
    } while ((attr_pattern != NULL) &&
             (attr_pattern[0] != '\0') &&
             (delimiter != 0));

    return 0;
}
Beispiel #4
0
Assertion
setldaparg1 (RDF_Resource u, Assertion as)
{
	return (Assertion) PR_HashTableAdd(ldap2rdfHash, u, as);
}
Beispiel #5
0
/* this calls MozillaEmbedContext to reflect the embed by
 * calling into mocha... yow! */
static JSObject *
lm_ReallyReflectEmbed(MWContext *context, LO_EmbedStruct *lo_embed,
                      int32 layer_id, uint32 index)
{
    JSObject *obj;
    MochaDecoder *decoder;
    JSContext *cx;
    jref jembed;
    NPEmbeddedApp* embed;
    lo_TopState *top_state;
    PRHashTable *map;
    PR_LOG(Moja, debug, ("really reflect embed 0x%x\n", lo_embed));

    if ((obj = lo_embed->mocha_object) != NULL)
        return obj;

    decoder = LM_GetMochaDecoder(context);
    if (!decoder)
	return NULL;
    cx = decoder->js_context;

    top_state = lo_GetMochaTopState(context);
    if (top_state->resize_reload) {
        map = lm_GetIdToObjectMap(decoder);
        
        if (map)
            obj = (JSObject *)PR_HashTableLookup(map,
                             LM_GET_MAPPING_KEY(LM_EMBEDS, layer_id, index));
        if (obj) {
            lo_embed->mocha_object = obj;
            return obj;
        }
    }

    /* set the element to something bad if we can't get the java obj */
    if (!JSJ_IsEnabled()) {
        PR_LOG(Moja, debug, ("reflected embed 0x%x as null\n",
                             lo_embed));
        return lo_embed->mocha_object = lm_DummyObject;
    }

    embed = (NPEmbeddedApp*) lo_embed->FE_Data;
    if (embed) {
        np_data *ndata = (np_data*) embed->np_data;
        np_instance *instance;

        /* XXX this comes from npglue.c, it should be put
         * in one of the plugin header files */
        extern jref npn_getJavaPeer(NPP npp);

        if (!ndata || ndata->state == NPDataSaved) {
            PR_LOG(Moja, warn, ("embed 0x%x is missing or suspended\n",
                                lo_embed));
            return NULL;
        }
        instance = ndata->instance;
	if (!instance) return NULL;
        jembed = npn_getJavaPeer(instance->npp);

        obj = js_ReflectJObjectToJSObject(decoder->js_context,
				          (HObject *)jembed);
        PR_LOG(Moja, debug, ("reflected embed 0x%x (java 0x%x) to 0x%x ok\n",
                             lo_embed, jembed, obj));

        map = lm_GetIdToObjectMap(decoder);
        if (map)
            PR_HashTableAdd(map, 
                            LM_GET_MAPPING_KEY(LM_EMBEDS, layer_id, index),
                            obj);

        return lo_embed->mocha_object = obj;
    } else {
        PR_LOG(Moja, warn, ("failed to reflect embed 0x%x\n", lo_embed));
        return NULL;
    }
}
Beispiel #6
0
JSObject *
LM_ReflectNamedAnchor(MWContext *context, lo_NameList *name_rec,
                      PA_Tag * tag, int32 layer_id, uint index)
{
    JSObject *obj, *array_obj, *document;
    MochaDecoder *decoder;
    JSContext *cx;
    JSObjectArray *array;
    JSAnchor *named_anchor;
    lo_TopState *top_state;
    PRHashTable *map;
    JSString *str;

    obj = name_rec->mocha_object;
    if (obj)
        return obj;

    decoder = LM_GetMochaDecoder(context);
    if (!decoder)
        return NULL;
    cx = decoder->js_context;

    top_state = lo_GetMochaTopState(context);
    if (top_state->resize_reload) {
        map = lm_GetIdToObjectMap(decoder);

        if (map)
            obj = (JSObject *)PR_HashTableLookup(map,
                                         LM_GET_MAPPING_KEY(LM_NAMEDANCHORS,
                                                            layer_id, index));
        if (obj) {
            name_rec->mocha_object = obj;
            LM_PutMochaDecoder(decoder);
            return obj;
        }
    }

    /* Get the document object that will hold this anchor */
    document = lm_GetDocumentFromLayerId(decoder, layer_id);
    if (!document) {
	LM_PutMochaDecoder(decoder);
	return NULL;
    }

    array_obj = lm_GetNameArray(decoder, document);
    if (!array_obj) {
        LM_PutMochaDecoder(decoder);
        return NULL;
    }
    array = JS_GetPrivate(cx, array_obj);
    if (!array) {
        LM_PutMochaDecoder(decoder);
	return NULL;
    }

    named_anchor = JS_malloc(cx, sizeof *named_anchor);
    if (!named_anchor) {
        LM_PutMochaDecoder(decoder);
        return NULL;
    }
    XP_BZERO(named_anchor, sizeof *named_anchor);

    obj = JS_NewObject(cx, &lm_anchor_class, decoder->anchor_prototype,
		       document);

    if (!obj || !JS_SetPrivate(cx, obj, named_anchor)) {
        JS_free(cx, named_anchor);
        LM_PutMochaDecoder(decoder);
        return NULL;
    }

    /* Put obj into the document.anchors array. */
    JS_DefineProperty(cx, array_obj, (char *) name_rec->name,
		      OBJECT_TO_JSVAL(obj), NULL, NULL,
		      JSPROP_ENUMERATE|JSPROP_READONLY);
    JS_AliasElement(cx, array_obj, (char *) name_rec->name, index);

    /* Put it in the index to object hash table */
    map = lm_GetIdToObjectMap(decoder);
    if (map) {
        PR_HashTableAdd(map,
                        LM_GET_MAPPING_KEY(LM_NAMEDANCHORS, layer_id, index),
                        obj);
    }
    if ((jsint) index >= array->length)
	array->length = index + 1;

    named_anchor->decoder = HOLD_BACK_COUNT(decoder);
    named_anchor->layer_id = layer_id;
    named_anchor->index = index;
    if (name_rec->element && name_rec->element->type == LO_TEXT) {
	str = lm_LocalEncodingToStr(context, 
				    (char *) name_rec->element->lo_text.text);
	if (!str || !JS_LockGCThing(cx, str)) {
	    LM_PutMochaDecoder(decoder);
	    return NULL;
	}
	named_anchor->text = str;
    }
    str = JS_NewStringCopyZ(cx, (char *) name_rec->name);
    if (!str || !JS_LockGCThing(cx, str)) {
        LM_PutMochaDecoder(decoder);
	return NULL;
    }
    named_anchor->name = str;

    name_rec->mocha_object = obj;

    /* see if there are any attributes for event handlers */
    if(tag) {
        PA_Block onlocate, id;

	/* don't hold the layout lock across compiles */
	LO_UnlockLayout();

        onlocate = lo_FetchParamValue(context, tag, PARAM_ONLOCATE);
        id = lo_FetchParamValue(context, tag, PARAM_ID);
        if (onlocate) {
	    (void) lm_CompileEventHandler(decoder, id, tag->data,
					  tag->newline_count, obj,
					  PARAM_ONLOCATE, onlocate);
            PA_FREE(onlocate);
        }
	if (id)
	    PA_FREE(id);
	LO_LockLayout();
    }

    LM_PutMochaDecoder(decoder);
    return obj;
}
Beispiel #7
0
JSObject *
LM_ReflectLink(MWContext *context, LO_AnchorData *anchor_data, PA_Tag * tag,
               int32 layer_id, uint index)
{
    JSObject *obj, *array_obj, *document;
    MochaDecoder *decoder;
    JSContext *cx;
    JSURL *url;
    lo_TopState *top_state;
    PRHashTable *map;

    anchor_data = LO_GetLinkByIndex(context, layer_id, index);
    if (!anchor_data)
	return NULL;

    obj = anchor_data->mocha_object;
    if (obj)
	return obj;

    decoder = LM_GetMochaDecoder(context);
    if (!decoder)
	return NULL;
    cx = decoder->js_context;

    top_state = lo_GetMochaTopState(context);
    if (top_state->resize_reload) {
        map = lm_GetIdToObjectMap(decoder);

        if (map)
            obj = (JSObject *)PR_HashTableLookup(map,
                             LM_GET_MAPPING_KEY(LM_LINKS, layer_id, index));
        if (obj) {
            anchor_data->mocha_object = obj;
            LM_PutMochaDecoder(decoder);
            return obj;
        }
    }

    /* Get the document object that will hold this link */
    document = lm_GetDocumentFromLayerId(decoder, layer_id);
    if (!document) {
	LM_PutMochaDecoder(decoder);
	return NULL;
    }

    array_obj = lm_GetLinkArray(decoder, document);
    if (!array_obj) {
	LM_PutMochaDecoder(decoder);
	return NULL;
    }

    url = lm_NewURL(cx, decoder, anchor_data, document);

    if (!url) {
	LM_PutMochaDecoder(decoder);
	return NULL;
    }
    url->index = index;
    url->layer_id = layer_id;
    obj = url->url_object;

    /* XXX should find a name/id to pass in */
    /* put it in the links array */
    if (!lm_AddObjectToArray(cx, array_obj, NULL, index, obj)) {
	LM_PutMochaDecoder(decoder);
    	return NULL;
    }

    /* Put it in the index to object hash table */
    map = lm_GetIdToObjectMap(decoder);
    if (map)
        PR_HashTableAdd(map, LM_GET_MAPPING_KEY(LM_LINKS, layer_id, index),
                        obj);

    anchor_data->mocha_object = obj;
    LM_PutMochaDecoder(decoder);

    /* see if there are any event handlers we need to reflect */
    if(tag) {

	PA_Block onclick, onmouseover, onmouseout, onmousedown, onmouseup, ondblclick, id;

	/* don't hold the layout lock across compiles */
	LO_UnlockLayout();

	onclick = lo_FetchParamValue(context, tag, PARAM_ONCLICK);
	onmouseover = lo_FetchParamValue(context, tag, PARAM_ONMOUSEOVER);
	onmouseout  = lo_FetchParamValue(context, tag, PARAM_ONMOUSEOUT);
	onmousedown = lo_FetchParamValue(context, tag, PARAM_ONMOUSEDOWN);
	onmouseup   = lo_FetchParamValue(context, tag, PARAM_ONMOUSEUP);
	ondblclick  = lo_FetchParamValue(context, tag, PARAM_ONDBLCLICK);
        id = lo_FetchParamValue(context, tag, PARAM_ID);

	if (onclick) {
	    (void) lm_CompileEventHandler(decoder, id, tag->data,
					  tag->newline_count, url->url_object,
				          PARAM_ONCLICK, onclick);
	    PA_FREE(onclick);
	    anchor_data->event_handler_present = TRUE;
	}
	if (onmouseover) {
	    (void) lm_CompileEventHandler(decoder, id, tag->data,
					  tag->newline_count, url->url_object,
					  PARAM_ONMOUSEOVER, onmouseover);
	    PA_FREE(onmouseover);
	    anchor_data->event_handler_present = TRUE;
	}
	if (onmouseout) {
	    (void) lm_CompileEventHandler(decoder, id, tag->data,
					  tag->newline_count, url->url_object,
					  PARAM_ONMOUSEOUT, onmouseout);
	    PA_FREE(onmouseout);
	    anchor_data->event_handler_present = TRUE;
	}
	if (onmousedown) {
	    (void) lm_CompileEventHandler(decoder, id, tag->data,
					  tag->newline_count, url->url_object,
					  PARAM_ONMOUSEDOWN, onmousedown);
	    PA_FREE(onmousedown);
	    anchor_data->event_handler_present = TRUE;
	}
	if (onmouseup) {
	    (void) lm_CompileEventHandler(decoder, id, tag->data,
					  tag->newline_count, url->url_object,
					  PARAM_ONMOUSEUP, onmouseup);
	    PA_FREE(onmouseup);
	    anchor_data->event_handler_present = TRUE;
	}
	if (ondblclick) {
	    (void) lm_CompileEventHandler(decoder, id, tag->data,
					  tag->newline_count, url->url_object,
					  PARAM_ONDBLCLICK, ondblclick);
	    PA_FREE(ondblclick);
	    anchor_data->event_handler_present = TRUE;
	}
	if (id)
	    PA_FREE(id);
        LO_LockLayout();
    }

    return obj;
}