Annotation of libwww/Library/src/HTAnchor.c, revision 1.25
1.14 frystyk 1: /* HTAnchor.c
2: ** HYPERTEXT "ANCHOR" OBJECT
1.1 timbl 3: **
1.22 frystyk 4: ** (c) COPYRIGHT MIT 1995.
1.14 frystyk 5: ** Please first read the full copyright statement in the file COPYRIGH.
6: **
7: ** An anchor represents a region of a hypertext document which is
8: ** linked to another anchor in the same or a different document.
1.1 timbl 9: **
10: ** History
11: ** Nov 1990 Written in Objective-C for the NeXT browser (TBL)
12: ** 24-Oct-1991 (JFG), written in C, browser-independant
13: ** 21-Nov-1991 (JFG), first complete version
1.17 frystyk 14: ** 3-May-1995 (HF), Added a lot of methods and other stuff
1.1 timbl 15: */
16:
1.16 frystyk 17: /* Library include files */
18: #include "tcp.h"
19: #include "HTUtils.h"
20: #include "HTString.h"
1.7 luotonen 21: #include "HTFormat.h"
1.1 timbl 22: #include "HTParse.h"
1.24 frystyk 23: #include "HTMethod.h"
1.16 frystyk 24: #include "HTFWrite.h" /* for cache stuff */
1.11 frystyk 25: #include "HTAnchor.h" /* Implemented here */
26:
27: #define HASH_SIZE 101 /* Arbitrary prime. Memory/speed tradeoff */
1.1 timbl 28:
29: typedef struct _HyperDoc Hyperdoc;
1.16 frystyk 30: #ifdef VMS
1.1 timbl 31: struct _HyperDoc {
1.16 frystyk 32: int junk; /* VMS cannot handle pointers to undefined structs */
1.1 timbl 33: };
34: #endif
35:
36: PRIVATE HTList **adult_table=0; /* Point to table of lists of all parents */
37:
1.17 frystyk 38: /* ------------------------------------------------------------------------- */
39: /* Creation Methods */
40: /* ------------------------------------------------------------------------- */
41:
42: /*
1.1 timbl 43: ** Do not use "new" by itself outside this module. In order to enforce
44: ** consistency, we insist that you furnish more information about the
45: ** anchor you are creating : use newWithParent or newWithAddress.
46: */
1.16 frystyk 47: PRIVATE HTParentAnchor * HTParentAnchor_new NOARGS
1.1 timbl 48: {
1.16 frystyk 49: HTParentAnchor *newAnchor =
50: (HTParentAnchor *) calloc(1, sizeof (HTParentAnchor));
51: newAnchor->parent = newAnchor;
1.17 frystyk 52: newAnchor->content_type = WWW_UNKNOWN;
1.24 frystyk 53: newAnchor->mainLink.method = METHOD_INVALID;
1.16 frystyk 54: return newAnchor;
1.1 timbl 55: }
56:
1.16 frystyk 57:
58: PRIVATE HTChildAnchor * HTChildAnchor_new NOARGS
1.1 timbl 59: {
1.16 frystyk 60: return (HTChildAnchor *) calloc (1, sizeof (HTChildAnchor));
1.1 timbl 61: }
62:
63:
1.17 frystyk 64: /* Create new or find old child anchor
65: ** -----------------------------------
1.1 timbl 66: **
1.3 timbl 67: ** Me one is for a new anchor being edited into an existing
1.17 frystyk 68: ** document. The parent anchor must already exist. All
69: ** children without tags (no NAME attribut) points to the same NULL
70: ** child.
1.1 timbl 71: */
1.17 frystyk 72: PUBLIC HTChildAnchor * HTAnchor_findChild ARGS2 (HTParentAnchor *, parent,
73: CONST char *,tag)
1.1 timbl 74: {
1.17 frystyk 75: HTChildAnchor *child;
76: HTList *kids;
77:
78: if (!parent) {
79: if (ANCH_TRACE)
80: fprintf(TDEST, "Find Child.. called with NULL parent.\n");
81: return NULL;
82: }
1.1 timbl 83:
1.17 frystyk 84: /* First search list of children to see if tag is already there */
85: if ((kids = parent->children)) {
86: if (tag && *tag) { /* TBL */
87: while ((child = (HTChildAnchor *) HTList_nextObject(kids))) {
1.19 frystyk 88: if (child->tag && !strcasecomp(child->tag, tag)) {
1.17 frystyk 89: if (ANCH_TRACE)
90: fprintf (TDEST,
91: "Find Child.. %p of parent %p with name `%s' already exists.\n",
92: (void *) child, (void *) parent, tag);
93: return child;
94: }
1.1 timbl 95: }
96: }
1.17 frystyk 97: } else /* Create new list of children */
98: parent->children = HTList_new ();
99:
100: /* Did't find it so we need to create a new one */
101: child = HTChildAnchor_new();
102: HTList_addObject(parent->children, child);
103: child->parent = parent;
104: StrAllocCopy(child->tag, tag);
105: if (ANCH_TRACE)
106: fprintf(TDEST,"Find Child.. New Anchor %p named `%s' is child of %p\n",
107: (void *) child, tag ? tag : (CONST char *) "", (void *)parent);
108: return child;
1.1 timbl 109: }
110:
111:
112: /* Create new or find old named anchor
113: ** -----------------------------------
114: **
1.3 timbl 115: ** Me one is for a reference which is found in a document, and might
1.1 timbl 116: ** not be already loaded.
117: ** Note: You are not guaranteed a new anchor -- you might get an old one,
118: ** like with fonts.
119: */
1.16 frystyk 120: PUBLIC HTAnchor * HTAnchor_findAddress ARGS1 (CONST char *, address)
1.1 timbl 121: {
1.16 frystyk 122: char *tag = HTParse (address, "", PARSE_ANCHOR); /* Any tags? */
123: char *newaddr=NULL;
1.1 timbl 124:
1.17 frystyk 125: StrAllocCopy(newaddr, address); /* Get our own copy */
1.16 frystyk 126: if (!HTImProxy)
1.19 frystyk 127: newaddr = HTSimplify(&newaddr); /* Proxy has already simplified */
1.16 frystyk 128:
129: /* If the address represents a sub-anchor, we recursively load its parent,
130: then we create a child anchor within that document. */
131: if (*tag) {
132: char *docAddress = HTParse(newaddr, "", PARSE_ACCESS | PARSE_HOST |
133: PARSE_PATH | PARSE_PUNCTUATION);
134: HTParentAnchor * foundParent =
135: (HTParentAnchor *) HTAnchor_findAddress (docAddress);
136: HTChildAnchor * foundAnchor = HTAnchor_findChild (foundParent, tag);
137: free (docAddress);
138: free (tag);
1.19 frystyk 139: free (newaddr);
1.16 frystyk 140: return (HTAnchor *) foundAnchor;
141: } else { /* Else check whether we have this node */
142: int hash;
143: CONST char *p;
144: HTList * adults;
145: HTList *grownups;
146: HTParentAnchor * foundAnchor;
147: free (tag);
148:
149: /* Select list from hash table */
150: for(p=newaddr, hash=0; *p; p++)
151: hash = (int) ((hash * 3 + (*(unsigned char*)p)) % HASH_SIZE);
152: if (!adult_table)
153: adult_table = (HTList**) calloc(HASH_SIZE, sizeof(HTList*));
154: if (!adult_table[hash]) adult_table[hash] = HTList_new();
155: adults = adult_table[hash];
156:
157: /* Search list for anchor */
158: grownups = adults;
159: while ((foundAnchor = (HTParentAnchor *) HTList_nextObject(grownups))){
1.17 frystyk 160: if (!strcasecomp(foundAnchor->address, newaddr)) {
1.16 frystyk 161: if (ANCH_TRACE)
1.17 frystyk 162: fprintf(TDEST, "Find Parent. %p with address `%s' already exists.\n",
1.16 frystyk 163: (void*) foundAnchor, newaddr);
1.19 frystyk 164: free(newaddr); /* We already have it */
1.16 frystyk 165: return (HTAnchor *) foundAnchor;
166: }
167: }
168:
169: /* Node not found : create new anchor. */
170: foundAnchor = HTParentAnchor_new();
171: foundAnchor->address = newaddr; /* Remember our copy */
172: HTList_addObject (adults, foundAnchor);
1.17 frystyk 173: if (ANCH_TRACE) fprintf(TDEST, "Find Parent. %p with hash %d and address `%s' created\n", (void*)foundAnchor, hash, newaddr);
1.1 timbl 174: return (HTAnchor *) foundAnchor;
175: }
176: }
177:
1.17 frystyk 178: /* ------------------------------------------------------------------------- */
179: /* Link Methods */
180: /* ------------------------------------------------------------------------- */
181:
182: /* Create or find a child anchor with a possible link
183: ** --------------------------------------------------
184: **
185: ** Create new anchor with a given parent and possibly
186: ** a name, and possibly a link to a _relatively_ named anchor.
187: ** (Code originally in ParseHTML.h)
188: */
189: PUBLIC HTChildAnchor * HTAnchor_findChildAndLink
190: ARGS4(
191: HTParentAnchor *,parent, /* May not be 0 */
192: CONST char *,tag, /* May be "" or 0 */
193: CONST char *,href, /* May be "" or 0 */
194: HTLinkType *,ltype /* May be 0 */
195: )
196: {
197: HTChildAnchor * child = HTAnchor_findChild(parent, tag);
198: if (href && *href) {
199: char * relative_to = HTAnchor_address((HTAnchor *) parent);
200: char * parsed_address = HTParse(href, relative_to, PARSE_ALL);
201: HTAnchor * dest = HTAnchor_findAddress(parsed_address);
1.24 frystyk 202: HTAnchor_link((HTAnchor *) child, dest, ltype, METHOD_INVALID);
1.17 frystyk 203: free(parsed_address);
204: free(relative_to);
205: }
206: return child;
207: }
208:
209: /* Link me Anchor to another given one
210: ** -------------------------------------
211: */
1.24 frystyk 212: PUBLIC BOOL HTAnchor_link ARGS4(HTAnchor *, source,
213: HTAnchor *, destination,
214: HTLinkType *, type,
215: HTMethod, method)
1.17 frystyk 216: {
217: if (!(source && destination))
218: return NO; /* Can't link to/from non-existing anchor */
219: if (ANCH_TRACE)
220: fprintf(TDEST, "Link Anchors anchor %p to anchor %p\n",
221: (void *) source, (void *) destination);
222: if (!source->mainLink.dest) {
223: source->mainLink.dest = destination;
224: source->mainLink.type = type;
1.24 frystyk 225: source->mainLink.method = method;
1.17 frystyk 226: } else {
227: HTLink * newLink = (HTLink *) calloc(1, sizeof (HTLink));
228: if (newLink == NULL) outofmem(__FILE__, "HTAnchor_link");
229: newLink->dest = destination;
230: newLink->type = type;
1.24 frystyk 231: newLink->method = method;
232: if (!source->links)
233: source->links = HTList_new();
1.17 frystyk 234: HTList_addObject (source->links, newLink);
235: }
236: if (!destination->parent->sources)
237: destination->parent->sources = HTList_new ();
238: HTList_addObject (destination->parent->sources, source);
239: return YES;
240: }
241:
242:
1.24 frystyk 243: /*
244: ** Returns the main destination of this anchor
245: */
246: PUBLIC HTAnchor * HTAnchor_followMainLink ARGS1(HTAnchor *, me)
247: {
248: return me ? me->mainLink.dest : NULL;
249: }
250:
251:
252: /*
253: ** Returns the methods registered for the main destination of this
254: ** anchor
1.17 frystyk 255: */
1.24 frystyk 256: PUBLIC HTMethod HTAnchor_mainLinkMethod ARGS1(HTAnchor *, me)
257: {
258: return me ? me->mainLink.method : METHOD_INVALID;
259: }
260:
1.17 frystyk 261:
1.24 frystyk 262: /*
263: ** Moves all link information from one anchor to another.
264: ** This is used in redirection etc.
265: ** Returns YES if OK, else NO
266: */
267: PUBLIC BOOL HTAnchor_moveLinks ARGS2(HTAnchor *, src, HTAnchor *, dest)
1.17 frystyk 268: {
1.24 frystyk 269: if (!src || !dest) return NO;
270: if (ANCH_TRACE)
271: fprintf(TDEST, "Move Links.. from anchor %p to anchor %p\n",
272: (void *) src, (void *) dest);
273:
274: /* Move main link information */
275: dest->mainLink.dest = src->mainLink.dest;
276: dest->mainLink.type = src->mainLink.type;
277: dest->mainLink.method = src->mainLink.method;
1.25 ! frystyk 278: dest->mainLink.result = src->mainLink.result;
1.24 frystyk 279:
280: src->mainLink.dest = NULL;
281: src->mainLink.type = NULL;
1.25 ! frystyk 282: src->mainLink.method = METHOD_INVALID;
! 283: src->mainLink.result = HT_OK;
1.24 frystyk 284:
285: /* Move link information for other links */
286: if (dest->links)
287: HTList_delete(dest->links);
288: dest->links = src->links;
289: src->links = NULL;
290: return YES;
1.17 frystyk 291: }
292:
1.24 frystyk 293:
294: /*
295: ** Returns a link with a given link type or NULL if nothing found
296: */
297: PUBLIC HTAnchor * HTAnchor_followTypedLink ARGS2(HTAnchor *, me,
298: HTLinkType *,type)
1.17 frystyk 299: {
1.24 frystyk 300: if (me->mainLink.type == type)
301: return me->mainLink.dest;
302: if (me->links) {
303: HTList *links = me->links;
304: HTLink *link;
305: while ((link = (HTLink *) HTList_nextObject (links)))
306: if (link->type == type)
307: return link->dest;
308: }
309: return NULL; /* No link of me type */
1.17 frystyk 310: }
311:
312:
1.24 frystyk 313: /*
314: ** Is this anchor a destination link of the source anchor?
315: ** Return YES if so, else NO
1.17 frystyk 316: */
1.24 frystyk 317: PUBLIC BOOL HTAnchor_isLink ARGS2(HTAnchor *, src, HTAnchor *, dest)
1.17 frystyk 318: {
1.24 frystyk 319: if (src && dest) {
320: if (src->mainLink.dest == dest)
321: return YES;
322: if (src->links) {
323: HTList *cur = src->links;
324: HTLink *pres;
325: while ((pres = (HTLink *) HTList_nextObject(cur)) != NULL) {
326: if (pres->dest == dest)
327: return YES;
328: }
329: }
330: }
331: return NO;
332: }
333:
1.17 frystyk 334:
1.24 frystyk 335: /*
336: ** Upgrade the link to the main destination and and downgrade the
337: ** current main link to the list
338: */
339: PUBLIC BOOL HTAnchor_makeMainLink ARGS2 (HTAnchor *, me, HTLink *, movingLink)
340: {
341: if (! (me && HTList_removeObject (me->links, movingLink)))
342: return NO;
343: else {
344: /* First push current main link onto top of links list */
345: HTLink *newLink = (HTLink*) malloc (sizeof (HTLink));
346: if (newLink == NULL) outofmem(__FILE__, "HTAnchor_makeMainLink");
347: memcpy (newLink, & me->mainLink, sizeof (HTLink));
348: HTList_addObject (me->links, newLink);
349:
350: /* Now make movingLink the new main link, and free it */
351: memcpy (& me->mainLink, movingLink, sizeof (HTLink));
352: free (movingLink);
353: return YES;
354: }
1.17 frystyk 355: }
356:
357: /* Move an anchor to the head of the list of its siblings
358: ** ------------------------------------------------------
359: **
360: ** This is to ensure that an anchor which might have already existed
361: ** is put in the correct order as we load the document.
362: */
363:
364: PUBLIC void HTAnchor_makeLastChild
365: ARGS1(HTChildAnchor *,me)
366: {
367: if (me->parent != (HTParentAnchor *) me) { /* Make sure it's a child */
368: HTList * siblings = me->parent->children;
369: HTList_removeObject (siblings, me);
370: HTList_addObject (siblings, me);
371: }
372: }
373:
374: /* ------------------------------------------------------------------------- */
375: /* Deletion Methods */
376: /* ------------------------------------------------------------------------- */
1.1 timbl 377:
378: /* Delete an anchor and possibly related things (auto garbage collection)
379: ** --------------------------------------------
380: **
381: ** The anchor is only deleted if the corresponding document is not loaded.
1.10 frystyk 382: ** All outgoing links from parent and children are deleted, and this
383: ** anchor is removed from the sources list of all its targets.
1.1 timbl 384: ** We also try to delete the targets whose documents are not loaded.
385: ** If this anchor's source list is empty, we delete it and its children.
386: */
387:
1.19 frystyk 388: /* Deletes all the memory allocated in a parent anchor and returns the
389: ** hyperdoc
390: */
391: PRIVATE HyperDoc * delete_parent ARGS1(HTParentAnchor *, me)
392: {
393: HyperDoc *doc = me->document;
394:
395: /* Remove link and address information */
396: HTList_delete (me->links);
397: HTList_delete (me->children);
398: HTList_delete (me->sources);
399: FREE(me->physical);
400: FREE(me->address);
401:
402: /* Then remove entity header information (metainformation) */
403: FREE(me->title);
404: FREE(me->derived_from);
405: FREE(me->version);
406: if (me->extra_headers) {
407: HTList *cur = me->extra_headers;
408: char *pres;
409: while ((pres = (char *) HTList_nextObject(cur)))
410: free(pres);
411: HTList_delete(me->extra_headers);
412: }
413:
414: /* @@@ TEMPORARY SOLUTION FOR CACHE - SHOULD BE PERSISTENT */
415: if (me->cacheItems) {
416: HTCacheClear(me->cacheItems);
417: }
418: free(me);
419: return doc;
420: }
421:
422:
423: /* Delete a parent anchor and all its children. If a HyperDoc is found
424: ** then it's returned
425: */
426: PRIVATE HyperDoc *delete_family ARGS1(HTAnchor *, me)
427: {
428: HTParentAnchor *parent = me->parent;
429: if (ANCH_TRACE)
430: fprintf(TDEST, "AnchorDelete Remove parent %p and children\n", parent);
431: if (!me) {
432: if (ANCH_TRACE)
433: fprintf(TDEST, "AnchorDelete No anchor found\n");
434: return NULL;
435: }
436:
437: /* Delete children */
438: if (parent->children) {
439: HTChildAnchor *child;
440: while ((child = (HTChildAnchor *)
441: HTList_removeLastObject(parent->children))) {
442: FREE(child->tag);
443: free(child);
444: }
445: }
446: return delete_parent(parent);
447: }
448:
449:
450: /* DELETE ALL ANCHORS
451: ** ------------------
452: ** Deletes all anchors and return a list of all the HyperDocs found.
453: ** It is for the application to delete any HyperDocs.
454: ** Return YES if OK, else NO
455: */
456: PUBLIC BOOL HTAnchor_deleteAll ARGS1(HTList *, documents)
457: {
458: int cnt;
459: HTList *cur;
460: if (!documents)
461: return NO;
462: for (cnt=0; cnt<HASH_SIZE; cnt++) {
463: if ((cur = adult_table[cnt])) {
464: HTParentAnchor *pres;
465: while ((pres = (HTParentAnchor *) HTList_nextObject(cur)) != NULL){
466: HyperDoc *doc = delete_family((HTAnchor *) pres);
467: if (doc) HTList_addObject(documents, (void *) doc);
468: }
469: }
470: HTList_delete(adult_table[cnt]);
471: }
1.21 frystyk 472: FREE(adult_table);
1.19 frystyk 473: return YES;
474: }
475:
476:
1.1 timbl 477: PRIVATE void deleteLinks
1.3 timbl 478: ARGS1 (HTAnchor *,me)
1.1 timbl 479: {
1.3 timbl 480: if (! me)
1.1 timbl 481: return;
482:
483: /* Recursively try to delete target anchors */
1.3 timbl 484: if (me->mainLink.dest) {
485: HTParentAnchor *parent = me->mainLink.dest->parent;
486: HTList_removeObject (parent->sources, me);
1.1 timbl 487: if (! parent->document) /* Test here to avoid calling overhead */
488: HTAnchor_delete (parent);
489: }
1.3 timbl 490: if (me->links) { /* Extra destinations */
1.1 timbl 491: HTLink *target;
1.12 frystyk 492: while ((target = (HTLink *) HTList_removeLastObject (me->links))) {
1.1 timbl 493: HTParentAnchor *parent = target->dest->parent;
1.3 timbl 494: HTList_removeObject (parent->sources, me);
1.1 timbl 495: if (! parent->document) /* Test here to avoid calling overhead */
496: HTAnchor_delete (parent);
497: }
498: }
499: }
500:
501: PUBLIC BOOL HTAnchor_delete
1.3 timbl 502: ARGS1 (HTParentAnchor *,me)
1.1 timbl 503: {
504: HTChildAnchor *child;
505:
506: /* Don't delete if document is loaded */
1.3 timbl 507: if (me->document)
1.1 timbl 508: return NO;
509:
510: /* Recursively try to delete target anchors */
1.3 timbl 511: deleteLinks ((HTAnchor *) me);
1.1 timbl 512:
1.3 timbl 513: if (! HTList_isEmpty (me->sources)) { /* There are still incoming links */
1.1 timbl 514: /* Delete all outgoing links from children, if any */
1.3 timbl 515: HTList *kids = me->children;
1.12 frystyk 516: while ((child = (HTChildAnchor *) HTList_nextObject (kids)))
1.1 timbl 517: deleteLinks ((HTAnchor *) child);
518: return NO; /* Parent not deleted */
519: }
520:
521: /* No more incoming links : kill everything */
522: /* First, recursively delete children */
1.12 frystyk 523: while ((child = (HTChildAnchor *) HTList_removeLastObject (me->children))) {
1.1 timbl 524: deleteLinks ((HTAnchor *) child);
525: free (child->tag);
526: free (child);
527: }
528:
529: /* Now kill myself */
1.19 frystyk 530: delete_parent(me);
1.1 timbl 531: return YES; /* Parent deleted */
532: }
533:
1.17 frystyk 534: /* ------------------------------------------------------------------------- */
535: /* Data Access Methods */
536: /* ------------------------------------------------------------------------- */
1.1 timbl 537:
1.17 frystyk 538: PUBLIC HTParentAnchor * HTAnchor_parent ARGS1 (HTAnchor *,me)
1.1 timbl 539: {
1.17 frystyk 540: return me ? me->parent : NULL;
1.1 timbl 541: }
542:
1.17 frystyk 543: PUBLIC void HTAnchor_setDocument ARGS2 (HTParentAnchor *, me, HyperDoc *,doc)
1.1 timbl 544: {
1.17 frystyk 545: if (me)
546: me->document = doc;
1.1 timbl 547: }
548:
1.17 frystyk 549: PUBLIC HyperDoc * HTAnchor_document ARGS1 (HTParentAnchor *,me)
1.1 timbl 550: {
1.17 frystyk 551: return me ? me->document : NULL;
1.1 timbl 552: }
553:
554:
1.10 frystyk 555: #if 0
1.17 frystyk 556: /* We might want to use this when we have a link editing application */
1.10 frystyk 557: PUBLIC void HTAnchor_setAddress
1.3 timbl 558: ARGS2 (HTAnchor *,me, char *,addr)
1.1 timbl 559: {
1.3 timbl 560: if (me)
561: StrAllocCopy (me->parent->address, addr);
1.1 timbl 562: }
1.10 frystyk 563: #endif
564:
1.17 frystyk 565: PUBLIC char * HTAnchor_address ARGS1 (HTAnchor *, me)
1.1 timbl 566: {
1.17 frystyk 567: char *addr = NULL;
568: if (me) {
569: if (((HTParentAnchor *) me == me->parent) ||
570: !((HTChildAnchor *) me)->tag) { /* it's an adult or no tag */
571: StrAllocCopy (addr, me->parent->address);
572: }
573: else { /* it's a named child */
574: addr = (char *) malloc (2 + strlen (me->parent->address)
575: + strlen (((HTChildAnchor *) me)->tag));
576: if (addr == NULL) outofmem(__FILE__, "HTAnchor_address");
577: sprintf (addr, "%s#%s", me->parent->address,
578: ((HTChildAnchor *) me)->tag);
579: }
1.1 timbl 580: }
1.17 frystyk 581: return addr;
1.1 timbl 582: }
583:
1.17 frystyk 584: PUBLIC BOOL HTAnchor_hasChildren ARGS1 (HTParentAnchor *,me)
585: {
586: return me ? ! HTList_isEmpty(me->children) : NO;
587: }
1.1 timbl 588:
1.17 frystyk 589: PUBLIC void HTAnchor_clearIndex ARGS1 (HTParentAnchor *,me)
590: {
591: if (me)
592: me->isIndex = NO;
593: }
1.1 timbl 594:
1.17 frystyk 595: PUBLIC void HTAnchor_setIndex ARGS1 (HTParentAnchor *,me)
1.1 timbl 596: {
1.3 timbl 597: if (me)
1.17 frystyk 598: me->isIndex = YES;
599: }
600:
601: PUBLIC BOOL HTAnchor_isIndex ARGS1 (HTParentAnchor *,me)
602: {
603: return me ? me->isIndex : NO;
1.1 timbl 604: }
605:
1.17 frystyk 606: /* Protocol
607: ** --------
608: */
609:
610: PUBLIC void * HTAnchor_protocol ARGS1(HTParentAnchor *, me)
1.1 timbl 611: {
1.17 frystyk 612: return me->protocol;
1.1 timbl 613: }
614:
1.17 frystyk 615: PUBLIC void HTAnchor_setProtocol ARGS2(HTParentAnchor *, me,
616: void*, protocol)
1.9 frystyk 617: {
1.17 frystyk 618: me->protocol = protocol;
1.9 frystyk 619: }
1.1 timbl 620:
1.17 frystyk 621: /* Physical Address
622: ** ----------------
623: */
624:
625: PUBLIC char * HTAnchor_physical ARGS1(HTParentAnchor *, me)
1.1 timbl 626: {
1.17 frystyk 627: return me->physical;
1.1 timbl 628: }
629:
1.17 frystyk 630: PUBLIC void HTAnchor_setPhysical ARGS2(HTParentAnchor *, me,
631: char *, physical)
1.1 timbl 632: {
1.17 frystyk 633: if (!me || !physical) {
634: if (ANCH_TRACE)
635: fprintf(TDEST, "HTAnchor.... setPhysical, called with null argument\n");
636: return;
637: }
638: StrAllocCopy(me->physical, physical);
1.1 timbl 639: }
640:
1.17 frystyk 641: /* ------------------------------------------------------------------------- */
642: /* Entity Header Information */
643: /* ------------------------------------------------------------------------- */
644:
645: /*
646: ** Media Types (Content-Type)
647: */
648: PUBLIC HTFormat HTAnchor_format ARGS1(HTParentAnchor *,me)
649: {
650: return me ? me->content_type : NULL;
651: }
1.1 timbl 652:
1.17 frystyk 653: PUBLIC void HTAnchor_setFormat ARGS2(HTParentAnchor *,me, HTFormat, form)
1.1 timbl 654: {
1.17 frystyk 655: if (me) me->content_type = form;
1.1 timbl 656: }
657:
1.17 frystyk 658: /*
659: ** Charset parameter to Content-Type
1.1 timbl 660: */
1.17 frystyk 661: PUBLIC HTCharset HTAnchor_charset ARGS1(HTParentAnchor *, me)
1.1 timbl 662: {
1.17 frystyk 663: return me ? me->charset : NULL;
1.1 timbl 664: }
665:
1.17 frystyk 666: PUBLIC void HTAnchor_setCharset ARGS2(HTParentAnchor *,me, HTCharset, charset)
1.1 timbl 667: {
1.17 frystyk 668: if (me) me->charset = charset;
1.1 timbl 669: }
670:
1.17 frystyk 671: /*
1.20 frystyk 672: ** Level parameter to Content-Type
673: */
674: PUBLIC HTLevel HTAnchor_level ARGS1(HTParentAnchor *, me)
675: {
676: return me ? me->level : NULL;
677: }
678:
679: PUBLIC void HTAnchor_setLevel ARGS2(HTParentAnchor *,me, HTLevel, level)
680: {
681: if (me) me->level = level;
682: }
683:
684: /*
1.17 frystyk 685: ** Content Encoding
686: */
687: PUBLIC HTEncoding HTAnchor_encoding ARGS1(HTParentAnchor *,me)
1.1 timbl 688: {
1.17 frystyk 689: return me ? me->content_encoding : NULL;
1.1 timbl 690: }
691:
1.17 frystyk 692: PUBLIC void HTAnchor_setEncoding ARGS2(HTParentAnchor *,me,
693: HTEncoding, encoding)
694: {
695: if (me) me->content_encoding = encoding;
696: }
697:
698: /*
1.21 frystyk 699: ** Content Language
700: ** @@@ SHOULD BE A LIST @@@
701: */
702: PUBLIC HTLanguage HTAnchor_language ARGS1(HTParentAnchor *,me)
703: {
704: return me ? me->content_language : NULL;
705: }
706:
707: PUBLIC void HTAnchor_setLanguage ARGS2(HTParentAnchor *,me,
708: HTLanguage, language)
709: {
710: if (me) me->content_language = language;
711: }
712:
713: /*
1.17 frystyk 714: ** Content Transfer Encoding
1.1 timbl 715: */
1.17 frystyk 716: PUBLIC HTCte HTAnchor_cte ARGS1(HTParentAnchor *,me)
717: {
718: return me ? me->cte : NULL;
719: }
1.1 timbl 720:
1.17 frystyk 721: PUBLIC void HTAnchor_setCte ARGS2(HTParentAnchor *,me, HTCte, cte)
722: {
723: if (me) me->cte = cte;
724: }
725:
726: /*
727: ** Content Length
728: */
729: PUBLIC long int HTAnchor_length ARGS1(HTParentAnchor *,me)
1.1 timbl 730: {
1.17 frystyk 731: return me ? me->content_length : -1;
1.1 timbl 732: }
733:
1.17 frystyk 734: PUBLIC void HTAnchor_setLength ARGS2(HTParentAnchor *,me, long int, length)
735: {
736: if (me) me->content_length = length;
737: }
1.1 timbl 738:
1.17 frystyk 739: /*
740: ** Allowed methods (Allow)
1.1 timbl 741: */
1.17 frystyk 742: PUBLIC int HTAnchor_methods ARGS1(HTParentAnchor *, me)
743: {
744: return me ? me->methods : 0;
745: }
1.1 timbl 746:
1.17 frystyk 747: PUBLIC void HTAnchor_setMethods ARGS2(HTParentAnchor *,me, int, methodset)
1.1 timbl 748: {
1.17 frystyk 749: if (me) me->methods = methodset;
1.1 timbl 750: }
751:
1.17 frystyk 752: PUBLIC void HTAnchor_appendMethods ARGS2(HTParentAnchor *,me, int, methodset)
1.1 timbl 753: {
1.17 frystyk 754: if (me) me->methods += methodset;
1.1 timbl 755: }
756:
1.17 frystyk 757: /*
758: ** Title
1.2 timbl 759: */
1.17 frystyk 760: PUBLIC CONST char * HTAnchor_title ARGS1 (HTParentAnchor *,me)
1.1 timbl 761: {
1.17 frystyk 762: return me ? me->title : NULL;
763: }
1.1 timbl 764:
1.17 frystyk 765: PUBLIC void HTAnchor_setTitle ARGS2(HTParentAnchor *,me, CONST char *, title)
766: {
767: if (me && title) StrAllocCopy(me->title, title);
1.2 timbl 768: }
769:
1.17 frystyk 770: PUBLIC void HTAnchor_appendTitle ARGS2(HTParentAnchor *,me, CONST char *,title)
771: {
772: if (me && title) StrAllocCat(me->title, title);
773: }
1.2 timbl 774:
1.17 frystyk 775: /*
776: ** Version
1.2 timbl 777: */
1.17 frystyk 778: PUBLIC CONST char * HTAnchor_version ARGS1 (HTParentAnchor *,me)
779: {
780: return me ? me->version : NULL;
781: }
1.2 timbl 782:
1.17 frystyk 783: PUBLIC void HTAnchor_setVersion ARGS2(HTParentAnchor *, me,
784: CONST char *, version)
1.2 timbl 785: {
1.17 frystyk 786: if (me && version) StrAllocCopy(me->version, version);
1.2 timbl 787: }
788:
1.17 frystyk 789: /*
790: ** Derived from
1.2 timbl 791: */
1.17 frystyk 792: PUBLIC CONST char * HTAnchor_derived ARGS1 (HTParentAnchor *,me)
793: {
794: return me ? me->derived_from : NULL;
795: }
796:
797: PUBLIC void HTAnchor_setDerived ARGS2(HTParentAnchor *, me,
798: CONST char *, derived_from)
799: {
800: if (me && derived_from) StrAllocCopy(me->derived_from, derived_from);
801: }
1.2 timbl 802:
1.17 frystyk 803: /*
804: ** Extra Header List of unknown headers
805: */
806: PUBLIC HTList * HTAnchor_Extra ARGS1 (HTParentAnchor *, me)
1.2 timbl 807: {
1.17 frystyk 808: return me ? me->extra_headers : NULL;
1.2 timbl 809: }
810:
1.17 frystyk 811: PUBLIC void HTAnchor_addExtra ARGS2(HTParentAnchor *, me,
812: CONST char * , header)
1.2 timbl 813: {
1.17 frystyk 814: if (me) {
1.18 frystyk 815: char *newhead = NULL;
816: StrAllocCopy(newhead, header);
1.17 frystyk 817: if (!me->extra_headers)
818: me->extra_headers = HTList_new();
1.18 frystyk 819: HTList_addObject(me->extra_headers, (void *) newhead);
1.17 frystyk 820: }
1.2 timbl 821: }
822:
1.23 frystyk 823: /*
824: ** Has header been parsed?
1.2 timbl 825: */
1.17 frystyk 826: PUBLIC BOOL HTAnchor_headerParsed ARGS1(HTParentAnchor *, me)
1.2 timbl 827: {
1.17 frystyk 828: return (me ? me->header_parsed : NO);
1.23 frystyk 829: }
830:
831: PUBLIC void HTAnchor_setHeaderParsed ARGS1(HTParentAnchor *, me)
832: {
833: if (me) me->header_parsed = YES;
1.2 timbl 834: }
835:
1.17 frystyk 836: /* Clear Header Information
837: ** ------------------------
838: */
839: PUBLIC void HTAnchor_clearHeader ARGS1(HTParentAnchor *, me)
1.2 timbl 840: {
1.17 frystyk 841: me->methods = METHOD_INVALID;
842: me->content_encoding = NULL;
1.21 frystyk 843: #ifdef NEW_CODE
844: /* WAIT UNTIL WE HANDLE LANGUAGE AS A LIST */
1.17 frystyk 845: if (me->content_language) {
846: HTList_delete(me->content_language);
847: me->content_language = HTList_new();
1.9 frystyk 848: }
1.21 frystyk 849: #else
850: me->content_language = NULL;
851: #endif
1.17 frystyk 852: me->content_length = -1; /* Invalid */
853: me->cte = NULL;
854: me->content_type = WWW_UNKNOWN;
855: me->charset = NULL;
1.20 frystyk 856: me->level = NULL;
1.17 frystyk 857:
858: me->date = (time_t) 0;
859: me->expires = (time_t) 0;
860: me->last_modified = (time_t) 0;
861:
1.18 frystyk 862: FREE(me->derived_from);
863: FREE(me->version);
864:
865: if (me->extra_headers) {
866: HTList *cur = me->extra_headers;
867: char *pres;
868: while ((pres = (char *) HTList_nextObject(cur)))
869: free(pres);
870: HTList_delete(me->extra_headers);
871: me->extra_headers = NULL;
872: }
1.17 frystyk 873: me->header_parsed = NO; /* All cleared */
1.1 timbl 874: }
Webmaster