lymap.c

来自「基于rtos开发的浏览器!」· C语言 代码 · 共 591 行 · 第 1/2 页

C
591
字号
/*			Lynx Client-side Image MAP Support	       LYMap.c**			==================================****	Author: FM	Foteos Macrides (macrides@sci.wfbr.edu)***/#include "HTUtils.h"#include "tcp.h"#include "HTTP.h"#include "HTAnchor.h"#include "HTAccess.h"#include "HTFormat.h"#include "HTParse.h"#include "HTAlert.h"#include "LYUtils.h"#include "LYMap.h"#include "GridText.h"#include "LYSignal.h"#include "LYGlobalDefs.h"#include "LYKeymap.h"#include "LYCharUtils.h"#ifdef DIRED_SUPPORT#include "LYUpload.h"#include "LYLocal.h"#endif#include "LYexit.h"#include "LYLeaks.h"#define FREE(x) if (x) {free(x); x=NULL;}typedef struct _LYMapElement {   char * address;   char * title;#ifndef DONT_TRACK_INTERNAL_LINKS   BOOL   intern_flag;#endif} LYMapElement;typedef struct _LYImageMap {   char * address;   char * title;   HTList * elements;} LYImageMap;struct _HTStream{  HTStreamClass * isa;};PRIVATE HTList * LynxMaps = NULL;PUBLIC BOOL LYMapsOnly = FALSE;/* *  Utility for freeing a list of MAPs. */PUBLIC void ImageMapList_free ARGS1(    HTList *,		theList){    LYImageMap *map;    LYMapElement *element;    HTList *cur = theList;    HTList *current;    if (!cur)	return;    while (NULL != (map = (LYImageMap *)HTList_nextObject(cur))) {	FREE(map->address);	FREE(map->title);	if (map->elements) {	    current = map->elements;	    while (NULL !=		   (element = (LYMapElement *)HTList_nextObject(current))) {		FREE(element->address);		FREE(element->title);		FREE(element);	    }	    HTList_delete(map->elements);	    map->elements = NULL;	}	FREE(map);    }    HTList_delete(theList);    return;}/* *  Utility for freeing the global list of MAPs. - kw */PRIVATE void LYLynxMaps_free NOARGS{    ImageMapList_free(LynxMaps);    LynxMaps = NULL;    return;}/* *  We keep two kinds of lists: *  - A global list (LynxMaps) shared by MAPs from all documents that *    do not have POST data. *  - For each response to a POST which contains MAPs, a list specific *    to this combination of URL and post_data.  It is kept in the *    HTParentAnchor structure and is freed when the document is removed *    from memory, in the course of normal removal of anchors. *    MAPs from POST responses can only be accessed via internal links, *    i.e. from within the same document (with the same post_data). *    The notion of "same document" is extended, so that LYNXIMGMAP: *    and List Page screens are logically part of the document on which *    they are based. - kw * *  If DONT_TRACK_INTERNAL_LINKS is defined, only the global list will *  be used for all MAPs. * *//* *  Utility for creating an LYImageMap list, if it doesn't *  exist already, adding LYImageMap entry structures if needed, and *  removing any LYMapElements in a pre-existing LYImageMap entry so that *  it will have only those from AREA tags for the current analysis of *  MAP element content. - FM */PUBLIC BOOL LYAddImageMap ARGS3(	char *, 	address,	char *, 	title,	HTParentAnchor *, node_anchor){    LYImageMap *new = NULL;    LYImageMap *old = NULL;    HTList *cur = NULL;    HTList *theList = NULL;    HTList *curele = NULL;    LYMapElement *ele = NULL;    if (!(address && *address))	return FALSE;    if (!(node_anchor && node_anchor->address))	return FALSE;    /*     *	Set theList to either the global LynxMaps list or, if we     *	are associated with post data, the specific list.  The     *	list is created if it doesn't already exist. - kw     */#ifndef DONT_TRACK_INTERNAL_LINKS    if (node_anchor->post_data) {	/*	 *  We are handling a MAP element found while parsing	 *  node_anchor's stream of data, and node_anchor has	 *  post_data associated and should therefore represent	 *  a POST response, so use the specific list. - kw	 */	theList = node_anchor->imaps;	if (!theList) {	    theList = node_anchor->imaps = HTList_new();	}    } else#endif    {	if (!LynxMaps) {	    LynxMaps = HTList_new();	    atexit(LYLynxMaps_free);	}	theList = LynxMaps;    }    if (theList) {	cur = theList;	while (NULL != (old = (LYImageMap *)HTList_nextObject(cur))) {	    if (!strcmp(old->address, address)) {		FREE(old->address);		FREE(old->title);		if (old->elements) {		    curele = old->elements;		    while (NULL !=			   (ele = (LYMapElement *)HTList_nextObject(curele))) {			FREE(ele->address);			FREE(ele->title);			FREE(ele);		    }		    HTList_delete(old->elements);		    old->elements = NULL;		}		break;	    }	}    }    new = (old != NULL) ?		    old : (LYImageMap *)calloc(1, sizeof(LYImageMap));    if (new == NULL) {	perror("Out of memory in LYAddImageMap");	return FALSE;    }    StrAllocCopy(new->address, address);    if (title && *title)	StrAllocCopy(new->title, title);    if (new != old)	HTList_addObject(theList, new);    return TRUE;}/* * Utility for adding LYMapElements to LYImageMaps * in the appropriate list. - FM */PUBLIC BOOL LYAddMapElement ARGS5(	char *, 	map,	char *, 	address,	char *, 	title,	HTParentAnchor *, node_anchor,	BOOL,		intern_flag){    LYMapElement *new = NULL;    LYImageMap *theMap = NULL;    HTList *theList = NULL;    HTList *cur = NULL;    if (!(map && *map && address && *address))	return FALSE;    if (!(node_anchor && node_anchor->address))	return FALSE;    /*     *	Set theList to either the global LynxMaps list or, if we     *	are associated with post data, the specific list.  The     *	list should already exist, since this function is only called     *	if the AREA tag we are handling was within a MAP element     *	in node_anchor's stream of data, so that LYAddImageMap has     *	been called. - kw     */#ifndef DONT_TRACK_INTERNAL_LINKS    if (node_anchor->post_data) {	/*	 *  We are handling an AREA tag found while parsing	 *  node_anchor's stream of data, and node_anchor has	 *  post_data associated and should therefore represent	 *  a POST response, so use the specific list. - kw	 */	theList = node_anchor->imaps;	if (!theList)	    return FALSE;    } else#endif    {	if (!LynxMaps)	    LYAddImageMap(map, NULL, node_anchor);	theList = LynxMaps;    }    cur = theList;    while (NULL != (theMap = (LYImageMap *)HTList_nextObject(cur))) {	if (!strcmp(theMap->address, map)) {	    break;	}    }    if (!theMap)	return FALSE;    if (!theMap->elements)	theMap->elements = HTList_new();    cur = theMap->elements;    while (NULL != (new = (LYMapElement *)HTList_nextObject(cur))) {	if (!strcmp(new->address, address)) {	    FREE(new->address);	    FREE(new->title);	    HTList_removeObject(theMap->elements, new);	    FREE(new);	    break;	}    }    new = (LYMapElement *)calloc(1, sizeof(LYMapElement));    if (new == NULL) {	perror("Out of memory in LYAddMapElement");	return FALSE;    }    StrAllocCopy(new->address, address);    if (title && *title)	StrAllocCopy(new->title, title);    else	StrAllocCopy(new->title, address);#ifndef DONT_TRACK_INTERNAL_LINKS    new->intern_flag = intern_flag;#endif    HTList_appendObject(theMap->elements, new);    return TRUE;}/* *  Utility for checking whether an LYImageMap entry *  with a given address already exists in the LynxMaps *  structure. - FM

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?