Annotation of libwww/Library/src/HTAnchor.c, revision 1.24
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;
! 278:
! 279: src->mainLink.dest = NULL;
! 280: src->mainLink.type = NULL;
! 281: src->mainLink.dest = METHOD_INVALID;
! 282:
! 283: /* Move link information for other links */
! 284: if (dest->links)
! 285: HTList_delete(dest->links);
! 286: dest->links = src->links;
! 287: src->links = NULL;
! 288: return YES;
1.17 frystyk 289: }
290:
1.24 ! frystyk 291:
! 292: /*
! 293: ** Returns a link with a given link type or NULL if nothing found
! 294: */
! 295: PUBLIC HTAnchor * HTAnchor_followTypedLink ARGS2(HTAnchor *, me,
! 296: HTLinkType *,type)
1.17 frystyk 297: {
1.24 ! frystyk 298: if (me->mainLink.type == type)
! 299: return me->mainLink.dest;
! 300: if (me->links) {
! 301: HTList *links = me->links;
! 302: HTLink *link;
! 303: while ((link = (HTLink *) HTList_nextObject (links)))
! 304: if (link->type == type)
! 305: return link->dest;
! 306: }
! 307: return NULL; /* No link of me type */
1.17 frystyk 308: }
309:
310:
1.24 ! frystyk 311: /*
! 312: ** Is this anchor a destination link of the source anchor?
! 313: ** Return YES if so, else NO
1.17 frystyk 314: */
1.24 ! frystyk 315: PUBLIC BOOL HTAnchor_isLink ARGS2(HTAnchor *, src, HTAnchor *, dest)
1.17 frystyk 316: {
1.24 ! frystyk 317: if (src && dest) {
! 318: if (src->mainLink.dest == dest)
! 319: return YES;
! 320: if (src->links) {
! 321: HTList *cur = src->links;
! 322: HTLink *pres;
! 323: while ((pres = (HTLink *) HTList_nextObject(cur)) != NULL) {
! 324: if (pres->dest == dest)
! 325: return YES;
! 326: }
! 327: }
! 328: }
! 329: return NO;
! 330: }
! 331:
1.17 frystyk 332:
1.24 ! frystyk 333: /*
! 334: ** Upgrade the link to the main destination and and downgrade the
! 335: ** current main link to the list
! 336: */
! 337: PUBLIC BOOL HTAnchor_makeMainLink ARGS2 (HTAnchor *, me, HTLink *, movingLink)
! 338: {
! 339: if (! (me && HTList_removeObject (me->links, movingLink)))
! 340: return NO;
! 341: else {
! 342: /* First push current main link onto top of links list */
! 343: HTLink *newLink = (HTLink*) malloc (sizeof (HTLink));
! 344: if (newLink == NULL) outofmem(__FILE__, "HTAnchor_makeMainLink");
! 345: memcpy (newLink, & me->mainLink, sizeof (HTLink));
! 346: HTList_addObject (me->links, newLink);
! 347:
! 348: /* Now make movingLink the new main link, and free it */
! 349: memcpy (& me->mainLink, movingLink, sizeof (HTLink));
! 350: free (movingLink);
! 351: return YES;
! 352: }
1.17 frystyk 353: }
354:
355: /* Move an anchor to the head of the list of its siblings
356: ** ------------------------------------------------------
357: **
358: ** This is to ensure that an anchor which might have already existed
359: ** is put in the correct order as we load the document.
360: */
361:
362: PUBLIC void HTAnchor_makeLastChild
363: ARGS1(HTChildAnchor *,me)
364: {
365: if (me->parent != (HTParentAnchor *) me) { /* Make sure it's a child */
366: HTList * siblings = me->parent->children;
367: HTList_removeObject (siblings, me);
368: HTList_addObject (siblings, me);
369: }
370: }
371:
372: /* ------------------------------------------------------------------------- */
373: /* Deletion Methods */
374: /* ------------------------------------------------------------------------- */
1.1 timbl 375:
376: /* Delete an anchor and possibly related things (auto garbage collection)
377: ** --------------------------------------------
378: **
379: ** The anchor is only deleted if the corresponding document is not loaded.
1.10 frystyk 380: ** All outgoing links from parent and children are deleted, and this
381: ** anchor is removed from the sources list of all its targets.
1.1 timbl 382: ** We also try to delete the targets whose documents are not loaded.
383: ** If this anchor's source list is empty, we delete it and its children.
384: */
385:
1.19 frystyk 386: /* Deletes all the memory allocated in a parent anchor and returns the
387: ** hyperdoc
388: */
389: PRIVATE HyperDoc * delete_parent ARGS1(HTParentAnchor *, me)
390: {
391: HyperDoc *doc = me->document;
392:
393: /* Remove link and address information */
394: HTList_delete (me->links);
395: HTList_delete (me->children);
396: HTList_delete (me->sources);
397: FREE(me->physical);
398: FREE(me->address);
399:
400: /* Then remove entity header information (metainformation) */
401: FREE(me->title);
402: FREE(me->derived_from);
403: FREE(me->version);
404: if (me->extra_headers) {
405: HTList *cur = me->extra_headers;
406: char *pres;
407: while ((pres = (char *) HTList_nextObject(cur)))
408: free(pres);
409: HTList_delete(me->extra_headers);
410: }
411:
412: /* @@@ TEMPORARY SOLUTION FOR CACHE - SHOULD BE PERSISTENT */
413: if (me->cacheItems) {
414: HTCacheClear(me->cacheItems);
415: }
416: free(me);
417: return doc;
418: }
419:
420:
421: /* Delete a parent anchor and all its children. If a HyperDoc is found
422: ** then it's returned
423: */
424: PRIVATE HyperDoc *delete_family ARGS1(HTAnchor *, me)
425: {
426: HTParentAnchor *parent = me->parent;
427: if (ANCH_TRACE)
428: fprintf(TDEST, "AnchorDelete Remove parent %p and children\n", parent);
429: if (!me) {
430: if (ANCH_TRACE)
431: fprintf(TDEST, "AnchorDelete No anchor found\n");
432: return NULL;
433: }
434:
435: /* Delete children */
436: if (parent->children) {
437: HTChildAnchor *child;
438: while ((child = (HTChildAnchor *)
439: HTList_removeLastObject(parent->children))) {
440: FREE(child->tag);
441: free(child);
442: }
443: }
444: return delete_parent(parent);
445: }
446:
447:
448: /* DELETE ALL ANCHORS
449: ** ------------------
450: ** Deletes all anchors and return a list of all the HyperDocs found.
451: ** It is for the application to delete any HyperDocs.
452: ** Return YES if OK, else NO
453: */
454: PUBLIC BOOL HTAnchor_deleteAll ARGS1(HTList *, documents)
455: {
456: int cnt;
457: HTList *cur;
458: if (!documents)
459: return NO;
460: for (cnt=0; cnt<HASH_SIZE; cnt++) {
461: if ((cur = adult_table[cnt])) {
462: HTParentAnchor *pres;
463: while ((pres = (HTParentAnchor *) HTList_nextObject(cur)) != NULL){
464: HyperDoc *doc = delete_family((HTAnchor *) pres);
465: if (doc) HTList_addObject(documents, (void *) doc);
466: }
467: }
468: HTList_delete(adult_table[cnt]);
469: }
1.21 frystyk 470: FREE(adult_table);
1.19 frystyk 471: return YES;
472: }
473:
474:
1.1 timbl 475: PRIVATE void deleteLinks
1.3 timbl 476: ARGS1 (HTAnchor *,me)
1.1 timbl 477: {
1.3 timbl 478: if (! me)
1.1 timbl 479: return;
480:
481: /* Recursively try to delete target anchors */
1.3 timbl 482: if (me->mainLink.dest) {
483: HTParentAnchor *parent = me->mainLink.dest->parent;
484: HTList_removeObject (parent->sources, me);
1.1 timbl 485: if (! parent->document) /* Test here to avoid calling overhead */
486: HTAnchor_delete (parent);
487: }
1.3 timbl 488: if (me->links) { /* Extra destinations */
1.1 timbl 489: HTLink *target;
1.12 frystyk 490: while ((target = (HTLink *) HTList_removeLastObject (me->links))) {
1.1 timbl 491: HTParentAnchor *parent = target->dest->parent;
1.3 timbl 492: HTList_removeObject (parent->sources, me);
1.1 timbl 493: if (! parent->document) /* Test here to avoid calling overhead */
494: HTAnchor_delete (parent);
495: }
496: }
497: }
498:
499: PUBLIC BOOL HTAnchor_delete
1.3 timbl 500: ARGS1 (HTParentAnchor *,me)
1.1 timbl 501: {
502: HTChildAnchor *child;
503:
504: /* Don't delete if document is loaded */
1.3 timbl 505: if (me->document)
1.1 timbl 506: return NO;
507:
508: /* Recursively try to delete target anchors */
1.3 timbl 509: deleteLinks ((HTAnchor *) me);
1.1 timbl 510:
1.3 timbl 511: if (! HTList_isEmpty (me->sources)) { /* There are still incoming links */
1.1 timbl 512: /* Delete all outgoing links from children, if any */
1.3 timbl 513: HTList *kids = me->children;
1.12 frystyk 514: while ((child = (HTChildAnchor *) HTList_nextObject (kids)))
1.1 timbl 515: deleteLinks ((HTAnchor *) child);
516: return NO; /* Parent not deleted */
517: }
518:
519: /* No more incoming links : kill everything */
520: /* First, recursively delete children */
1.12 frystyk 521: while ((child = (HTChildAnchor *) HTList_removeLastObject (me->children))) {
1.1 timbl 522: deleteLinks ((HTAnchor *) child);
523: free (child->tag);
524: free (child);
525: }
526:
527: /* Now kill myself */
1.19 frystyk 528: delete_parent(me);
1.1 timbl 529: return YES; /* Parent deleted */
530: }
531:
1.17 frystyk 532: /* ------------------------------------------------------------------------- */
533: /* Data Access Methods */
534: /* ------------------------------------------------------------------------- */
1.1 timbl 535:
1.17 frystyk 536: PUBLIC HTParentAnchor * HTAnchor_parent ARGS1 (HTAnchor *,me)
1.1 timbl 537: {
1.17 frystyk 538: return me ? me->parent : NULL;
1.1 timbl 539: }
540:
1.17 frystyk 541: PUBLIC void HTAnchor_setDocument ARGS2 (HTParentAnchor *, me, HyperDoc *,doc)
1.1 timbl 542: {
1.17 frystyk 543: if (me)
544: me->document = doc;
1.1 timbl 545: }
546:
1.17 frystyk 547: PUBLIC HyperDoc * HTAnchor_document ARGS1 (HTParentAnchor *,me)
1.1 timbl 548: {
1.17 frystyk 549: return me ? me->document : NULL;
1.1 timbl 550: }
551:
552:
1.10 frystyk 553: #if 0
1.17 frystyk 554: /* We might want to use this when we have a link editing application */
1.10 frystyk 555: PUBLIC void HTAnchor_setAddress
1.3 timbl 556: ARGS2 (HTAnchor *,me, char *,addr)
1.1 timbl 557: {
1.3 timbl 558: if (me)
559: StrAllocCopy (me->parent->address, addr);
1.1 timbl 560: }
1.10 frystyk 561: #endif
562:
1.17 frystyk 563: PUBLIC char * HTAnchor_address ARGS1 (HTAnchor *, me)
1.1 timbl 564: {
1.17 frystyk 565: char *addr = NULL;
566: if (me) {
567: if (((HTParentAnchor *) me == me->parent) ||
568: !((HTChildAnchor *) me)->tag) { /* it's an adult or no tag */
569: StrAllocCopy (addr, me->parent->address);
570: }
571: else { /* it's a named child */
572: addr = (char *) malloc (2 + strlen (me->parent->address)
573: + strlen (((HTChildAnchor *) me)->tag));
574: if (addr == NULL) outofmem(__FILE__, "HTAnchor_address");
575: sprintf (addr, "%s#%s", me->parent->address,
576: ((HTChildAnchor *) me)->tag);
577: }
1.1 timbl 578: }
1.17 frystyk 579: return addr;
1.1 timbl 580: }
581:
1.17 frystyk 582: PUBLIC BOOL HTAnchor_hasChildren ARGS1 (HTParentAnchor *,me)
583: {
584: return me ? ! HTList_isEmpty(me->children) : NO;
585: }
1.1 timbl 586:
1.17 frystyk 587: PUBLIC void HTAnchor_clearIndex ARGS1 (HTParentAnchor *,me)
588: {
589: if (me)
590: me->isIndex = NO;
591: }
1.1 timbl 592:
1.17 frystyk 593: PUBLIC void HTAnchor_setIndex ARGS1 (HTParentAnchor *,me)
1.1 timbl 594: {
1.3 timbl 595: if (me)
1.17 frystyk 596: me->isIndex = YES;
597: }
598:
599: PUBLIC BOOL HTAnchor_isIndex ARGS1 (HTParentAnchor *,me)
600: {
601: return me ? me->isIndex : NO;
1.1 timbl 602: }
603:
1.17 frystyk 604: /* Protocol
605: ** --------
606: */
607:
608: PUBLIC void * HTAnchor_protocol ARGS1(HTParentAnchor *, me)
1.1 timbl 609: {
1.17 frystyk 610: return me->protocol;
1.1 timbl 611: }
612:
1.17 frystyk 613: PUBLIC void HTAnchor_setProtocol ARGS2(HTParentAnchor *, me,
614: void*, protocol)
1.9 frystyk 615: {
1.17 frystyk 616: me->protocol = protocol;
1.9 frystyk 617: }
1.1 timbl 618:
1.17 frystyk 619: /* Physical Address
620: ** ----------------
621: */
622:
623: PUBLIC char * HTAnchor_physical ARGS1(HTParentAnchor *, me)
1.1 timbl 624: {
1.17 frystyk 625: return me->physical;
1.1 timbl 626: }
627:
1.17 frystyk 628: PUBLIC void HTAnchor_setPhysical ARGS2(HTParentAnchor *, me,
629: char *, physical)
1.1 timbl 630: {
1.17 frystyk 631: if (!me || !physical) {
632: if (ANCH_TRACE)
633: fprintf(TDEST, "HTAnchor.... setPhysical, called with null argument\n");
634: return;
635: }
636: StrAllocCopy(me->physical, physical);
1.1 timbl 637: }
638:
1.17 frystyk 639: /* ------------------------------------------------------------------------- */
640: /* Entity Header Information */
641: /* ------------------------------------------------------------------------- */
642:
643: /*
644: ** Media Types (Content-Type)
645: */
646: PUBLIC HTFormat HTAnchor_format ARGS1(HTParentAnchor *,me)
647: {
648: return me ? me->content_type : NULL;
649: }
1.1 timbl 650:
1.17 frystyk 651: PUBLIC void HTAnchor_setFormat ARGS2(HTParentAnchor *,me, HTFormat, form)
1.1 timbl 652: {
1.17 frystyk 653: if (me) me->content_type = form;
1.1 timbl 654: }
655:
1.17 frystyk 656: /*
657: ** Charset parameter to Content-Type
1.1 timbl 658: */
1.17 frystyk 659: PUBLIC HTCharset HTAnchor_charset ARGS1(HTParentAnchor *, me)
1.1 timbl 660: {
1.17 frystyk 661: return me ? me->charset : NULL;
1.1 timbl 662: }
663:
1.17 frystyk 664: PUBLIC void HTAnchor_setCharset ARGS2(HTParentAnchor *,me, HTCharset, charset)
1.1 timbl 665: {
1.17 frystyk 666: if (me) me->charset = charset;
1.1 timbl 667: }
668:
1.17 frystyk 669: /*
1.20 frystyk 670: ** Level parameter to Content-Type
671: */
672: PUBLIC HTLevel HTAnchor_level ARGS1(HTParentAnchor *, me)
673: {
674: return me ? me->level : NULL;
675: }
676:
677: PUBLIC void HTAnchor_setLevel ARGS2(HTParentAnchor *,me, HTLevel, level)
678: {
679: if (me) me->level = level;
680: }
681:
682: /*
1.17 frystyk 683: ** Content Encoding
684: */
685: PUBLIC HTEncoding HTAnchor_encoding ARGS1(HTParentAnchor *,me)
1.1 timbl 686: {
1.17 frystyk 687: return me ? me->content_encoding : NULL;
1.1 timbl 688: }
689:
1.17 frystyk 690: PUBLIC void HTAnchor_setEncoding ARGS2(HTParentAnchor *,me,
691: HTEncoding, encoding)
692: {
693: if (me) me->content_encoding = encoding;
694: }
695:
696: /*
1.21 frystyk 697: ** Content Language
698: ** @@@ SHOULD BE A LIST @@@
699: */
700: PUBLIC HTLanguage HTAnchor_language ARGS1(HTParentAnchor *,me)
701: {
702: return me ? me->content_language : NULL;
703: }
704:
705: PUBLIC void HTAnchor_setLanguage ARGS2(HTParentAnchor *,me,
706: HTLanguage, language)
707: {
708: if (me) me->content_language = language;
709: }
710:
711: /*
1.17 frystyk 712: ** Content Transfer Encoding
1.1 timbl 713: */
1.17 frystyk 714: PUBLIC HTCte HTAnchor_cte ARGS1(HTParentAnchor *,me)
715: {
716: return me ? me->cte : NULL;
717: }
1.1 timbl 718:
1.17 frystyk 719: PUBLIC void HTAnchor_setCte ARGS2(HTParentAnchor *,me, HTCte, cte)
720: {
721: if (me) me->cte = cte;
722: }
723:
724: /*
725: ** Content Length
726: */
727: PUBLIC long int HTAnchor_length ARGS1(HTParentAnchor *,me)
1.1 timbl 728: {
1.17 frystyk 729: return me ? me->content_length : -1;
1.1 timbl 730: }
731:
1.17 frystyk 732: PUBLIC void HTAnchor_setLength ARGS2(HTParentAnchor *,me, long int, length)
733: {
734: if (me) me->content_length = length;
735: }
1.1 timbl 736:
1.17 frystyk 737: /*
738: ** Allowed methods (Allow)
1.1 timbl 739: */
1.17 frystyk 740: PUBLIC int HTAnchor_methods ARGS1(HTParentAnchor *, me)
741: {
742: return me ? me->methods : 0;
743: }
1.1 timbl 744:
1.17 frystyk 745: PUBLIC void HTAnchor_setMethods ARGS2(HTParentAnchor *,me, int, methodset)
1.1 timbl 746: {
1.17 frystyk 747: if (me) me->methods = methodset;
1.1 timbl 748: }
749:
1.17 frystyk 750: PUBLIC void HTAnchor_appendMethods ARGS2(HTParentAnchor *,me, int, methodset)
1.1 timbl 751: {
1.17 frystyk 752: if (me) me->methods += methodset;
1.1 timbl 753: }
754:
1.17 frystyk 755: /*
756: ** Title
1.2 timbl 757: */
1.17 frystyk 758: PUBLIC CONST char * HTAnchor_title ARGS1 (HTParentAnchor *,me)
1.1 timbl 759: {
1.17 frystyk 760: return me ? me->title : NULL;
761: }
1.1 timbl 762:
1.17 frystyk 763: PUBLIC void HTAnchor_setTitle ARGS2(HTParentAnchor *,me, CONST char *, title)
764: {
765: if (me && title) StrAllocCopy(me->title, title);
1.2 timbl 766: }
767:
1.17 frystyk 768: PUBLIC void HTAnchor_appendTitle ARGS2(HTParentAnchor *,me, CONST char *,title)
769: {
770: if (me && title) StrAllocCat(me->title, title);
771: }
1.2 timbl 772:
1.17 frystyk 773: /*
774: ** Version
1.2 timbl 775: */
1.17 frystyk 776: PUBLIC CONST char * HTAnchor_version ARGS1 (HTParentAnchor *,me)
777: {
778: return me ? me->version : NULL;
779: }
1.2 timbl 780:
1.17 frystyk 781: PUBLIC void HTAnchor_setVersion ARGS2(HTParentAnchor *, me,
782: CONST char *, version)
1.2 timbl 783: {
1.17 frystyk 784: if (me && version) StrAllocCopy(me->version, version);
1.2 timbl 785: }
786:
1.17 frystyk 787: /*
788: ** Derived from
1.2 timbl 789: */
1.17 frystyk 790: PUBLIC CONST char * HTAnchor_derived ARGS1 (HTParentAnchor *,me)
791: {
792: return me ? me->derived_from : NULL;
793: }
794:
795: PUBLIC void HTAnchor_setDerived ARGS2(HTParentAnchor *, me,
796: CONST char *, derived_from)
797: {
798: if (me && derived_from) StrAllocCopy(me->derived_from, derived_from);
799: }
1.2 timbl 800:
1.17 frystyk 801: /*
802: ** Extra Header List of unknown headers
803: */
804: PUBLIC HTList * HTAnchor_Extra ARGS1 (HTParentAnchor *, me)
1.2 timbl 805: {
1.17 frystyk 806: return me ? me->extra_headers : NULL;
1.2 timbl 807: }
808:
1.17 frystyk 809: PUBLIC void HTAnchor_addExtra ARGS2(HTParentAnchor *, me,
810: CONST char * , header)
1.2 timbl 811: {
1.17 frystyk 812: if (me) {
1.18 frystyk 813: char *newhead = NULL;
814: StrAllocCopy(newhead, header);
1.17 frystyk 815: if (!me->extra_headers)
816: me->extra_headers = HTList_new();
1.18 frystyk 817: HTList_addObject(me->extra_headers, (void *) newhead);
1.17 frystyk 818: }
1.2 timbl 819: }
820:
1.23 frystyk 821: /*
822: ** Has header been parsed?
1.2 timbl 823: */
1.17 frystyk 824: PUBLIC BOOL HTAnchor_headerParsed ARGS1(HTParentAnchor *, me)
1.2 timbl 825: {
1.17 frystyk 826: return (me ? me->header_parsed : NO);
1.23 frystyk 827: }
828:
829: PUBLIC void HTAnchor_setHeaderParsed ARGS1(HTParentAnchor *, me)
830: {
831: if (me) me->header_parsed = YES;
1.2 timbl 832: }
833:
1.17 frystyk 834: /* Clear Header Information
835: ** ------------------------
836: */
837: PUBLIC void HTAnchor_clearHeader ARGS1(HTParentAnchor *, me)
1.2 timbl 838: {
1.17 frystyk 839: me->methods = METHOD_INVALID;
840: me->content_encoding = NULL;
1.21 frystyk 841: #ifdef NEW_CODE
842: /* WAIT UNTIL WE HANDLE LANGUAGE AS A LIST */
1.17 frystyk 843: if (me->content_language) {
844: HTList_delete(me->content_language);
845: me->content_language = HTList_new();
1.9 frystyk 846: }
1.21 frystyk 847: #else
848: me->content_language = NULL;
849: #endif
1.17 frystyk 850: me->content_length = -1; /* Invalid */
851: me->cte = NULL;
852: me->content_type = WWW_UNKNOWN;
853: me->charset = NULL;
1.20 frystyk 854: me->level = NULL;
1.17 frystyk 855:
856: me->date = (time_t) 0;
857: me->expires = (time_t) 0;
858: me->last_modified = (time_t) 0;
859:
1.18 frystyk 860: FREE(me->derived_from);
861: FREE(me->version);
862:
863: if (me->extra_headers) {
864: HTList *cur = me->extra_headers;
865: char *pres;
866: while ((pres = (char *) HTList_nextObject(cur)))
867: free(pres);
868: HTList_delete(me->extra_headers);
869: me->extra_headers = NULL;
870: }
1.17 frystyk 871: me->header_parsed = NO; /* All cleared */
1.1 timbl 872: }
Webmaster