Free the lizard

git-svn-id: svn://10.0.0.236/trunk@10 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
ltabb
1998-03-28 02:44:41 +00:00
parent 53f8de8141
commit 8ed5afe62c
5423 changed files with 1772023 additions and 0 deletions

View File

@@ -0,0 +1,29 @@
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
# compliance with the NPL. You may obtain a copy of the NPL at
# http://www.mozilla.org/NPL/
#
# Software distributed under the NPL is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
# for the specific language governing rights and limitations under the
# NPL.
#
# The Initial Developer of this code under the NPL is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
#
DEPTH = ../../..
MODULE = hook
LIBRARY_NAME = hook
CSRCS = hk_conf.c hk_file.c hk_hook.c hk_init.c hk_tag.c
REQUIRES = libxp util js img layer parse hook pref dbm nspr
LOCAL_INCLUDES = -I.
include $(DEPTH)/config/rules.mk

View File

@@ -0,0 +1,123 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "xp_core.h"
#include "xp_mcom.h"
#include "jsapi.h"
#include "hk_private.h"
/**********************************************
* These are to configuration functions registered
* with the new javascript HookConfig object.
* They are designed to maintain an array of the
* special hooks with simple booleans to tell
* if they already exist in the object or not.
**********************************************/
/*
* Called when a new object is added.
* If the object is a function then we
* add it to the existence array.
* NOTE: hk_SetFunctionExistence only keeps track of those functions
* that are known special javascript hooks.
*/
JSBool
hk_HookObjectAddProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
{
JSString *j_str;
char *str;
j_str = JS_ValueToString(cx, id);
str = JS_GetStringBytes(j_str);
if (JS_TypeOfValue(cx, *vp) == JSTYPE_FUNCTION)
{
/*
* hk_SetFunctionExistence is not allowed to change
* the contents of str or the wrong function
* will be added.
*/
hk_SetFunctionExistence(str, TRUE);
}
return JS_TRUE;
}
/*
* Called when an object is deleted.
* If the object is a function then we
* delete it from the existence array.
* NOTE: hk_SetFunctionExistence only keeps track of those functions
* that are known special javascript hooks.
*/
JSBool
hk_HookObjectDeleteProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
{
JSString *j_str;
char *str;
j_str = JS_ValueToString(cx, id);
str = JS_GetStringBytes(j_str);
if (JS_TypeOfValue(cx, *vp) == JSTYPE_FUNCTION)
{
/*
* hk_SetFunctionExistence is not allowed to change
* the contents of str or the wrong function
* will be deleted.
*/
hk_SetFunctionExistence(str, FALSE);
}
return JS_TRUE;
}
/*
* Called when an object has a new value set to it.
* The object could have been a value (like NULL) but
* now be set to a function. The object could also have once been
* set to a function and now be set to a non-function type.
* NOTE: hk_SetFunctionExistence only keeps track of those functions
* that are known special javascript hooks.
*/
JSBool
hk_HookObjectSetProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
{
JSString *j_str;
char *str;
j_str = JS_ValueToString(cx, id);
str = JS_GetStringBytes(j_str);
/*
* hk_SetFunctionExistence is not allowed to change
* the contents of str or the wrong object
* will be set.
*/
if (JS_TypeOfValue(cx, *vp) == JSTYPE_FUNCTION)
{
hk_SetFunctionExistence(str, TRUE);
}
else
{
hk_SetFunctionExistence(str, FALSE);
}
return JS_TRUE;
}

View File

@@ -0,0 +1,205 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "xp_core.h"
#include "xp_mcom.h"
#include "jsapi.h"
#include "prefapi.h"
#include "fe_proto.h"
#include "hk_funcs.h"
#include "hk_private.h"
/**************************************************
* This is a special function just to read in the
* users special hook.js file and interpret it
* into the special javascript hook filter object.
**************************************************/
void
HK_JSErrorReporter(JSContext *cx, const char *message, JSErrorReport *report);
void
HK_ReadHookFile(char *filename)
{
JSErrorReporter err_reporter;
JSContext *j_context;
JSObject *hook_obj;
JSBool ret;
jsval result;
XP_File file_ptr;
XP_StatStruct stat_info;
int32 file_len;
int32 read_len;
char *read_buf;
/*
* If we can't get a valid javascript context, just return.
*/
if (!PREF_GetConfigContext(&j_context))
{
return;
}
if (j_context == NULL)
{
return;
}
/*
* If we don't have a javascript hook object, try to create one,
* if we fail, then return.
*/
hook_obj = hk_GetHookObject();
if (hook_obj == NULL)
{
if (HK_Init() == 0)
{
return;
}
else
{
hook_obj = hk_GetHookObject();
}
if (hook_obj == NULL)
{
return;
}
}
/*
* If the hook.js file doesn't exist or has
* zero size, return.
*/
if (XP_Stat(filename, &stat_info, xpJSHTMLFilters) < 0)
{
return;
}
file_len = stat_info.st_size;
if (file_len <= 1)
{
return;
}
/*
* If the hook.js cannot be opened for reading, return.
*/
file_ptr = XP_FileOpen(filename, xpJSHTMLFilters, XP_FILE_READ);
if (file_ptr == NULL)
{
return;
}
/*
* If a buffer to read hook.js cannot be allocated, return.
*/
read_buf = XP_ALLOC(file_len * sizeof(char));
if (read_buf == NULL)
{
return;
}
read_len = XP_FileRead(read_buf, file_len, file_ptr);
(void)XP_FileClose(file_ptr);
/*
* Evaluate the file in the javascript hook object.
*/
err_reporter = JS_SetErrorReporter(j_context, HK_JSErrorReporter);
ret = JS_EvaluateScript(j_context, hook_obj, read_buf, read_len,
filename, 0, &result);
JS_SetErrorReporter(j_context, err_reporter);
XP_FREE(read_buf);
}
/* copied from libpref */
/* Platform specific alert messages */
static void
hk_Alert(char* msg)
{
#if defined(XP_MAC) || defined(XP_UNIX)
#if defined(XP_UNIX)
if (getenv("NO_PREF_SPAM") == NULL)
#endif
FE_Alert(NULL, msg);
#endif
#if defined (XP_WIN)
MessageBox (NULL, msg, "Netscape -- JS Preference Warning", MB_OK);
#endif
}
/*
* Mostly copied from elsewhere, reports errors in the
* hook.js file as it is read.
*/
void
HK_JSErrorReporter(JSContext *cx, const char *message, JSErrorReport *report)
{
char *last;
int i, j, k, n;
const char *s, *t;
last = PR_sprintf_append(0, "An error occurred reading the HTML hook file.");
last = PR_sprintf_append(last, "\n\n");
if (!report)
{
last = PR_sprintf_append(last, "%s\n", message);
}
else
{
if (report->filename)
{
last = PR_sprintf_append(last, "%s, ",
report->filename);
}
if (report->lineno)
{
last = PR_sprintf_append(last, "line %u: ",
report->lineno);
}
last = PR_sprintf_append(last, "%s. ", message);
if (report->linebuf)
{
for (s = t = report->linebuf; *s != '\0'; s = t)
{
for (; t != report->tokenptr && *t != '<' && *t != '\0'; t++)
;
last = PR_sprintf_append(last, "%.*s", t - s, s);
if (*t == '\0')
{
break;
}
last = PR_sprintf_append(last, (*t == '<') ? "" : "%c", *t);
t++;
}
}
}
if (last)
{
hk_Alert(last);
XP_FREE(last);
}
}

View File

@@ -0,0 +1,177 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "xp_core.h"
#include "xp_mcom.h"
#include "jsapi.h"
#include "prefapi.h"
#include "hk_funcs.h"
#include "hk_private.h"
static JSObject *HookObject = NULL;
JSObject *
hk_GetHookObject(void)
{
return HookObject;
}
void
hk_SetHookObject(JSObject *hook_obj)
{
HookObject = hook_obj;
}
/*
* Some hooks have dynamic names and can't be in the
* fast hook array lookup, this covers looking up those
* hooks. For example, if I invented a <BLURT> tag,
* this would look for a BLURT_hook function.
*/
intn
hk_IsUnknownTagHook(void *extra)
{
const char *hook_func;
jsval tmp_val;
JSContext *j_context;
hook_func = HK_GetFunctionName(HK_TAG, extra);
if (hook_func == NULL)
{
return 0;
}
if (!PREF_GetConfigContext(&j_context))
{
return 0;
}
if ((j_context == NULL)||(HookObject == NULL))
{
return 0;
}
if ((JS_GetProperty(j_context, HookObject, hook_func, &tmp_val))&&
(JS_TypeOfValue(j_context, tmp_val) == JSTYPE_FUNCTION))
{
return 1;
}
return 0;
}
/*
* There is no guarantee that someone has checked the existence of the
* hook before calling it, so we check again here. We don't use the
* fast array lookup since it can't catch all hooks anyway, and we
* may well have to fall back to the slow method.
*/
intn
HK_CallHook(int32 hook_id, void *extra, int32 window_id,
char *hook_str, char **hook_ret)
{
const char *hook_func;
intn ok;
jsval tmp_val;
jsval argv[2];
JSContext *j_context;
JSString *str;
const char *result_str;
char *return_str;
*hook_ret = NULL;
if (hook_str == NULL)
{
return 0;
}
/*
* Make a function name form the hook_is and possibly the PA_Tag
* pointed to by extra.
*/
hook_func = HK_GetFunctionName(hook_id, extra);
if (hook_func == NULL)
{
return 0;
}
/*
* Make sure you have a javascript context and object.
*/
if (!PREF_GetConfigContext(&j_context))
{
return 0;
}
if ((j_context == NULL)||(HookObject == NULL))
{
return 0;
}
/*
* Check that there is a function to call.
*/
if ((!JS_GetProperty(j_context, HookObject, hook_func, &tmp_val))||
(JS_TypeOfValue(j_context, tmp_val) != JSTYPE_FUNCTION))
{
return 0;
}
/*
* Create the argument/parameter list, and call the function.
*/
str = JS_NewStringCopyZ(j_context, hook_str);
if (str == NULL)
{
return 0;
}
argv[0] = STRING_TO_JSVAL(str);
argv[1] = INT_TO_JSVAL(window_id);
if (!JS_CallFunctionName(j_context, HookObject, hook_func, 2, argv,
&tmp_val))
{
return 0;
}
/*
* A false return from the function means leave the
* passed string unchanged.
*/
if (tmp_val != JSVAL_FALSE)
{
str = JS_ValueToString(j_context, tmp_val);
if (str == NULL)
{
return 0;
}
result_str = JS_GetStringBytes(str);
return_str = XP_STRDUP(result_str);
if (return_str == NULL)
{
return 0;
}
*hook_ret = return_str;
}
return 1;
}

View File

@@ -0,0 +1,412 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "xp_core.h"
#include "xp_mcom.h"
#include "hk_types.h"
#include "jsapi.h"
#include "prefapi.h"
#include "ntypes.h"
#include "structs.h"
#include "pa_tags.h"
#include "hk_private.h"
#ifdef XP_MAC
#include "hk_funcs.h"
#endif
static hk_FunctionRec **FunctionList = NULL;
static int32 FunctionCount = 0;
static char *hk_FunctionStrings[HK_MAX] = {
NULL,
"location_hook",
"_hook",
"document_start_hook"};
static JSClass autoconf_class = {
"HookConfig", 0,
hk_HookObjectAddProperty, hk_HookObjectDeleteProperty,
JS_PropertyStub, hk_HookObjectSetProperty,
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub
};
/*******************************************
* This function really bugs me! It needs to
* be super fast since it will be called for every
* HTML tag ever processed. This means it should be
* self-contained, and not call off to other functions.
* Making it do that means it can't call off into
* hk_tag.c to get inside the PA_Tag structure in extra,
* and thus makes me include ntypes.h, structs.h, and pa_tags.h.
********************************************/
/*
* A FAST function existence lookup, using an array set up in
* the initialization process.
*/
intn
HK_IsHook(int32 hook_id, void *extra)
{
int32 func_id;
hk_FunctionRec *rec_ptr;
/*
* The no hook case never exists.
*/
if (hook_id == HK_NONE)
{
return 0;
}
/*
* Tag hooks map to the tag types, or alternatly
* unknown tags which are handled elsewhere.
*/
else if (hook_id == HK_TAG)
{
PA_Tag *tag;
tag = (PA_Tag *)extra;
if (tag->type != P_UNKNOWN)
{
func_id = HK_MAX - 1 + tag->type;
}
/*
* P_UNKNOWN tags must be looked up the slow
* dynamic way.
*/
else
{
return(hk_IsUnknownTagHook(extra));
}
}
else
{
func_id = hook_id - 1;
}
/*
* If we are outside the known funtion array, fail.
*/
if ((func_id < 0)||(func_id >= FunctionCount))
{
return 0;
}
/*
* If no function is registered, fail.
*/
rec_ptr = FunctionList[func_id];
if (rec_ptr == NULL)
{
return 0;
}
if (rec_ptr->func_exists == FALSE)
{
return 0;
}
else
{
return 1;
}
}
/*
* Set the existence state of a particular index in the array.
*/
static void
hk_set_function_existence(int32 indx, XP_Bool exists)
{
if ((indx < 0)||(indx >= FunctionCount))
{
return;
}
if (FunctionList[indx] != NULL)
{
FunctionList[indx]->func_exists = exists;
}
}
void
hk_SetFunctionExistence(char *func_name, XP_Bool exists)
{
int32 i, len;
char *tptr;
char *up_str;
char *ptr1, *ptr2;
int32 indx;
/*
* A NULL function one too short for the hook suffix
* cannot be a hook function.
*/
if (func_name == NULL)
{
return;
}
len = XP_STRLEN(func_name);
if (len < XP_STRLEN("_hook"))
{
return;
}
/*
* If the function has no hook suffix we just don't care.
*/
tptr = func_name + len - XP_STRLEN("_hook");
if (XP_STRCMP(tptr, "_hook") != 0)
{
return;
}
/*
* Make an all upper-case copy of the prefix.
*/
*tptr = '\0';
up_str = XP_ALLOC(XP_STRLEN(func_name) + 1);
/*
* If allocation fails, restore original and return.
*/
if (up_str == NULL)
{
*tptr = '_';
return;
}
ptr1 = func_name;
ptr2 = up_str;
while (*ptr1 != '\0')
{
*ptr2 = (char)(XP_TO_UPPER(*ptr1));
ptr1++;
ptr2++;
}
*ptr2 = '\0';
*tptr = '_';
/*
* Check if the prefix is a known TAG name.
*/
indx = hk_TagStringToIndex(up_str);
XP_FREE(up_str);
if (indx >= 0)
{
indx = HK_MAX - 1 + indx;
hk_set_function_existence(indx, exists);
return;
}
/*
* Special check for the TEXT_hook which is a tag hook but
* won't be caught by the hk_TagStringToIndex test.
*/
if (XP_STRCMP(func_name, "TEXT_hook") == 0)
{
indx = HK_MAX - 1 + 0;
hk_set_function_existence(indx, exists);
return;
}
/*
* Finally, check the array of known tag hooks.
*/
for (i=1; i<HK_MAX; i++)
{
if ((hk_FunctionStrings[i] != NULL)&&
(XP_STRCMP(func_name, hk_FunctionStrings[i]) == 0))
{
indx = i - 1;
hk_set_function_existence(indx, exists);
return;
}
}
}
/*
* Free all members of the function list array up to
* the passed index.
*/
static void
hk_free_function_list(int32 indx)
{
int32 i;
for (i=0; i<indx; i++)
{
if (FunctionList[i] != NULL)
{
if (FunctionList[i]->func_name != NULL)
{
XP_FREE(FunctionList[i]->func_name);
FunctionList[i]->func_name = NULL;
}
XP_FREE(FunctionList[i]);
FunctionList[i] = NULL;
}
}
XP_FREE(FunctionList);
FunctionList = NULL;
FunctionCount = 0;
}
/*
* Initialize the function list array to contain all the known tags
* plus all the known special hook functions.
*/
static intn
hk_initialize_function_list(void)
{
int32 i, indx;
int32 tag_cnt;
/*
* Subtract one from HK_MAX because it includes the unknown
* at 0. For the tag count, unknown is -1, so we can just
* use it as is.
*/
tag_cnt = hk_NumKnownTags();
FunctionCount = HK_MAX - 1 + tag_cnt;
FunctionList = (hk_FunctionRec **)XP_ALLOC(FunctionCount *
sizeof(hk_FunctionRec *));
if (FunctionList == NULL)
{
return 0;
}
indx = 0;
/*
* First allocate all the known special hooks.
*/
for (i=1; i < HK_MAX; i++)
{
hk_FunctionRec *rec_ptr;
rec_ptr = XP_NEW(hk_FunctionRec);
if (rec_ptr == NULL)
{
hk_free_function_list(indx);
return 0;
}
rec_ptr->func_exists = FALSE;
rec_ptr->func_name = hk_FunctionStrings[i];
FunctionList[indx] = rec_ptr;
indx++;
}
/*
* Now do all known tags.
*/
for (i=0; i < tag_cnt; i++)
{
hk_FunctionRec *rec_ptr;
rec_ptr = XP_NEW(hk_FunctionRec);
if (rec_ptr == NULL)
{
hk_free_function_list(indx);
return 0;
}
rec_ptr->func_exists = FALSE;
rec_ptr->func_name = hk_TagIndexToFunctionString(i);
FunctionList[indx] = rec_ptr;
indx++;
}
return 1;
}
/*
* Initialize all the libhook stuff. SHould only be called once.
* Usually just before reading hook.js.
*/
intn
HK_Init(void)
{
intn ret;
JSContext *j_context;
JSObject *j_object;
JSObject *hook_obj;
/*
* If a hook object does not already exist, create
* one. If you cannot create one, then return failure.
*/
hook_obj = hk_GetHookObject();
if (hook_obj == NULL)
{
if ((!PREF_GetConfigContext(&j_context))||
(!PREF_GetGlobalConfigObject(&j_object)))
{
return 0;
}
hook_obj = JS_DefineObject(j_context, j_object,
"HookConfig",
&autoconf_class,
NULL,
JSPROP_ENUMERATE|JSPROP_READONLY|JSPROP_PERMANENT);
}
if (hook_obj == NULL)
{
return 0;
}
hk_SetHookObject(hook_obj);
ret = hk_initialize_function_list();
return ret;
}
/*
* Get the hook know for the passed hook id.
*/
const char *
HK_GetFunctionName(int32 hook_id, void *extra)
{
if ((hook_id < 0)||(hook_id >= HK_MAX))
{
return NULL;
}
/*
* Special name creation for tag hooks.
*/
if (hook_id == HK_TAG)
{
const char *ret_str;
ret_str = (const char *)hk_TagFunctionString(
hk_FunctionStrings[hook_id], extra);
return ret_str;
}
else
{
return hk_FunctionStrings[hook_id];
}
}

View File

@@ -0,0 +1,40 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
typedef struct hk_FunctionRecStruct {
XP_Bool func_exists;
char *func_name;
} hk_FunctionRec;
extern int32 hk_NumKnownTags(void);
extern int32 hk_TagStringToIndex(char *tag_str);
extern char *hk_TagIndexToFunctionString(int32 indx);
extern char *hk_TagFunctionString(const char *func_name, void *extra);
extern JSObject *hk_GetHookObject(void);
extern void hk_SetHookObject(JSObject *hook_obj);
extern intn hk_IsUnknownTagHook(void *extra);
extern void hk_SetFunctionExistence(char *func_name, XP_Bool exists);
extern JSBool hk_HookObjectAddProperty(JSContext *cx, JSObject *obj,
jsval id, jsval *vp);
extern JSBool hk_HookObjectDeleteProperty(JSContext *cx, JSObject *obj,
jsval id, jsval *vp);
extern JSBool hk_HookObjectSetProperty(JSContext *cx, JSObject *obj,
jsval id, jsval *vp);

View File

@@ -0,0 +1,180 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "xp_core.h"
#include "xp_mcom.h"
#include "ntypes.h"
#include "structs.h"
#include "pa_tags.h"
#include "proto.h"
#ifdef XP_MAC
int32 hk_NumKnownTags(void);
char *hk_TagIndexToFunctionString(int32 indx);
char *hk_TagFunctionString(const char *func_name, void *extra);
int32 hk_TagStringToIndex(char *tag_str);
#endif
/*
* No need for everyone to include pa_tags.h
*/
int32
hk_NumKnownTags(void)
{
return(P_MAX);
}
char *
hk_TagIndexToFunctionString(int32 tag_indx)
{
char *total_name;
total_name = NULL;
if (tag_indx == P_TEXT)
{
total_name = XP_STRDUP("TEXT_hook");
}
else if (tag_indx == P_UNKNOWN)
{
total_name = NULL;
}
else if (tag_indx >= P_MAX)
{
total_name = NULL;
}
else
{
const char *tag_name;
tag_name = PA_TagString(tag_indx);
if (tag_name == NULL)
{
total_name = NULL;
}
else
{
int32 len;
len = XP_STRLEN(tag_name) + XP_STRLEN("_hook") + 1;
total_name = XP_ALLOC(len);
if (total_name != NULL)
{
XP_STRCPY(total_name, tag_name);
XP_STRCAT(total_name, "_hook");
}
}
}
return(total_name);
}
/*
* Unlike hk_TagIndexToFunctionString (above) this function is passed
* a PA_Tag inside extra, so it can even make the dynamic hook
* name for UNKNOWN HTML tags.
*/
char *
hk_TagFunctionString(const char *func_name, void *extra)
{
PA_Tag *tag;
char *tag_text;
char *total_name;
tag_text = NULL;
tag = (PA_Tag *)extra;
if ((tag == NULL)||(func_name == NULL))
{
return NULL;
}
if (tag->type == P_TEXT)
{
tag_text = XP_STRDUP("TEXT");
}
else if (tag->type == P_UNKNOWN)
{
char *tptr;
int32 cnt;
tptr = (char *)tag->data;
cnt = 0;
while ((*tptr != '>')&&(!XP_IS_SPACE(*tptr))&&
(cnt < tag->data_len))
{
tptr++;
cnt++;
}
if ((cnt > 0)&&(cnt < tag->data_len))
{
char tchar;
tchar = *tptr;
*tptr = '\0';
tag_text = XP_STRDUP((char *)tag->data);
*tptr = tchar;
}
else
{
tag_text = XP_STRDUP("UNKNOWN");
}
}
else
{
const char *tag_name;
tag_name = PA_TagString((int32)tag->type);
if (tag_name == NULL)
{
tag_text = XP_STRDUP("UNKNOWN");
}
else
{
tag_text = XP_STRDUP(tag_name);
}
}
if (tag_text != NULL)
{
int32 total_len;
total_len = XP_STRLEN(func_name) + XP_STRLEN(tag_text) + 3;
total_name = XP_ALLOC(total_len);
if (total_name == NULL)
{
XP_FREE(tag_text);
return NULL;
}
XP_STRCPY(total_name, tag_text);
XP_STRCAT(total_name, func_name);
return total_name;
}
else
{
return NULL;
}
}
int32
hk_TagStringToIndex(char *tag_str)
{
return(PA_TagIndex(tag_str));
}

View File

@@ -0,0 +1,51 @@
#!gmake
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
# compliance with the NPL. You may obtain a copy of the NPL at
# http://www.mozilla.org/NPL/
#
# Software distributed under the NPL is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
# for the specific language governing rights and limitations under the
# NPL.
#
# The Initial Developer of this code under the NPL is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
IGNORE_MANIFEST=1
#
MODULE=hook
LIBRARY_NAME=hook
DEPTH=..\..\..
LOCAL_INCLUDES=-I.
LIBRARY=libhook.a
CSRCS=hk_conf.c hk_file.c hk_hook.c hk_init.c hk_tag.c
REQUIRES=libxp util js img layer parse hook pref dbm nspr
C_OBJS=.\$(OBJDIR)\hk_conf.obj .\$(OBJDIR)\hk_file.obj \
.\$(OBJDIR)\hk_hook.obj .\$(OBJDIR)\hk_init.obj \
.\$(OBJDIR)\hk_tag.obj
!if "$(MOZ_BITS)" != "16"
LINCS=-I$(XPDIST)\public\libxp -I$(XPDIST)\public\util \
-I$(XPDIST)\public\js -I$(XPDIST)\public\img \
-I$(XPDIST)\public\layer -I$(XPDIST)\public\parse \
-I$(XPDIST)\public\hook -I$(XPDIST)\public\pref \
-I$(XPDIST)\public\dbm -I$(XPDIST)\public\nspr
!endif
!include $(MOZ_SRC)\ns\config\rules.mak
#
# JMC doesn't install the module library that we make on windows
# Hence we have our own rule to install the library.
#
MY_INSTALL_FILE_LIST = $(LIBRARY)
MY_INSTALL_DIR = $(DIST)\lib
install::
!$(MAKE_INSTALL) $(MY_INSTALL_FILE_LIST) $(MY_INSTALL_DIR)