Annotation of libwww/Library/src/HText.c, revision 2.4
2.1 frystyk 1: /*
2: ** HYPERTEXT OBJECT BUILDER
3: **
4: ** (c) COPYRIGHT MIT 1999.
5: ** Please first read the full copyright statement in the file COPYRIGH.
2.4 ! frystyk 6: ** @(#) $Id: HText.c,v 2.3 1999/01/22 13:54:17 frystyk Exp $
2.1 frystyk 7: **
8: ** This generates of a hypertext object and calls the application
9: ** via callbacks.
10: */
11:
12: /* Library include files */
13: #include "wwwsys.h"
14: #include "WWWUtil.h"
15: #include "WWWCore.h"
16: #include "HText.h"
17: #include "HTextImp.h"
18:
19: /* Default callbacks that the application can register */
20: PRIVATE HText_new * text_new;
21: PRIVATE HText_delete * text_delete;
22: PRIVATE HText_build * text_build;
23: PRIVATE HText_addText * text_addText;
24: PRIVATE HText_foundLink * text_foundLink;
25: PRIVATE HText_beginElement * text_beginElement;
26: PRIVATE HText_endElement * text_endElement;
27: PRIVATE HText_unparsedBeginElement * text_unparsedBeginElement;
28: PRIVATE HText_unparsedEndElement * text_unparsedEndElement;
29: PRIVATE HText_unparsedEntity * text_unparsedEntity;
30:
31: /* HText handler instance */
32: struct _HTextImp {
33: HText * app;
34: HText_new * text_new;
35: HText_delete * text_delete;
36: HText_build * text_build;
37: HText_addText * text_addText;
38: HText_foundLink * text_foundLink;
39: HText_beginElement * text_beginElement;
40: HText_endElement * text_endElement;
41: HText_unparsedBeginElement *text_unparsedBeginElement;
42: HText_unparsedEndElement * text_unparsedEndElement;
43: HText_unparsedEntity * text_unparsedEntity;
44: };
45:
46: /* --------------------------------------------------------------------------- */
47:
48: PUBLIC HTextImp * HTextImp_new (HTRequest * request,
49: HTParentAnchor * anchor,
50: HTStream * output_stream)
51: {
52: HTextImp * me = NULL;
53: if ((me = (HTextImp *) HT_CALLOC(1, sizeof (HTextImp))) == NULL)
54: HT_OUTOFMEM("HTextImp_new");
55: me->text_new = text_new;
56: me->text_delete = text_delete;
57: me->text_build = text_build;
58: me->text_addText = text_addText;
59: me->text_foundLink = text_foundLink;
60: me->text_beginElement = text_beginElement;
61: me->text_endElement = text_endElement;
62: me->text_unparsedBeginElement = text_unparsedBeginElement;
63: me->text_unparsedEndElement = text_unparsedEndElement;
64: me->text_unparsedEntity = text_unparsedEntity;
2.2 frystyk 65: if (me->text_new) me->app = (*me->text_new)(request, anchor, output_stream);
2.1 frystyk 66: return me;
67: }
68:
69: PUBLIC BOOL HTextImp_delete (HTextImp * me)
70: {
71: if (me) {
2.3 frystyk 72:
73: /*
74: ** Note that we do not call the delete method on the app
75: ** HText object as this normally stays around after the
76: ** request has been deleted and certainly it should be
77: ** deleted by the app and not libwww
78: */
2.1 frystyk 79: HT_FREE(me);
2.3 frystyk 80: return YES;
2.1 frystyk 81: }
82: return NO;
83: }
84:
85: PUBLIC void HTextImp_build (HTextImp * me, HTextStatus status)
86: {
87: if (me && me->text_build)
88: (*me->text_build)(me->app, status);
89: }
90:
91: PUBLIC void HTextImp_addText (HTextImp * me,
92: const char * buffer,
93: int length)
94: {
95: if (me && me->text_addText)
96: (*me->text_addText)(me->app, buffer, length);
97: }
98:
99: PUBLIC void HTextImp_foundLink (HTextImp * me,
100: int element_number,
101: int attribute_number,
102: HTChildAnchor *anchor,
103: const BOOL * present,
104: const char ** value)
105: {
106: if (me && me->text_foundLink)
107: (*me->text_foundLink)(me->app, element_number, attribute_number,
108: anchor, present, value);
109: }
110:
111: PUBLIC void HTextImp_beginElement (HTextImp * me,
112: int element_number,
113: const BOOL * present,
114: const char **value)
115: {
116: if (me && me->text_beginElement)
117: (*me->text_beginElement)(me->app, element_number, present, value);
118: }
119:
120: PUBLIC void HTextImp_endElement (HTextImp * me,
121: int element_number)
122: {
123: if (me && me->text_endElement)
124: (*me->text_endElement)(me->app, element_number);
125: }
126:
127: PUBLIC void HTextImp_unparsedBeginElement (HTextImp * me,
128: const char * buffer,
129: int length)
130: {
131: if (me && me->text_unparsedBeginElement)
132: (*me->text_unparsedBeginElement)(me->app, buffer, length);
133: }
134:
135: PUBLIC void HTextImp_unparsedEndElement (HTextImp * me,
136: const char * buffer,
137: int length)
138: {
139: if (me && me->text_unparsedEndElement)
140: (*me->text_unparsedEndElement)(me->app, buffer, length);
141: }
142:
143: PUBLIC void HTextImp_unparsedEntity (HTextImp * me,
144: const char * buffer,
145: int length)
146: {
147: if (me && me->text_unparsedEntity)
148: (*me->text_unparsedEntity)(me->app, buffer, length);
149: }
150:
151: /* --------------------------------------------------------------------------- */
152:
153: PUBLIC BOOL HText_registerCDCallback (HText_new * ncb,
154: HText_delete * dcb)
155: {
156: if (ncb && dcb) {
157: text_new = ncb;
158: text_delete = dcb;
159: return YES;
160: }
161: return NO;
162: }
163:
164: PUBLIC BOOL HText_unregisterCDCallback (void)
165: {
166: text_new = NULL;
167: text_delete = NULL;
2.4 ! frystyk 168: return YES;
! 169: }
! 170:
! 171: PUBLIC BOOL HText_registerBuildCallback (HText_build * bcb)
! 172: {
! 173: text_build = bcb;
2.1 frystyk 174: return YES;
175: }
176:
177: PUBLIC BOOL HText_registerTextCallback (HText_addText * tcb)
178: {
179: text_addText = tcb;
180: return YES;
181: }
182:
183: PUBLIC BOOL HText_unregisterTextCallback (void)
184: {
185: text_addText = NULL;
186: return YES;
187: }
188:
189: PUBLIC BOOL HText_registerLinkCallback (HText_foundLink * lcb)
190: {
191: text_foundLink = lcb;
192: return YES;
193: }
194:
195: PUBLIC BOOL HText_unregisterLinkCallback (void)
196: {
197: text_foundLink = NULL;
198: return YES;
199: }
200:
201: PUBLIC BOOL HText_registerElementCallback (HText_beginElement * bcb,
202: HText_endElement * ecb)
203: {
204: text_beginElement = bcb;
205: text_endElement = ecb;
206: return YES;
207: }
208:
209: PUBLIC BOOL HText_unregisterElementCallback (void)
210: {
211: text_beginElement = NULL;
212: return YES;
213: }
214:
215: PUBLIC BOOL HText_registerUnparsedElementCallback (HText_unparsedBeginElement * ubcb,
216: HText_unparsedBeginElement * uecb)
217: {
218: text_unparsedBeginElement = ubcb;
219: text_unparsedEndElement = uecb;
220: return YES;
221: }
222:
223: PUBLIC BOOL HText_unregisterUnparsedElementCallback (void)
224: {
225: text_unparsedBeginElement = NULL;
226: text_unparsedEndElement = NULL;
227: return YES;
228: }
229:
230: PUBLIC BOOL HText_registerUnparsedEntityCallback (HText_unparsedEntity * tcb)
231: {
232: text_unparsedEntity = tcb;
233: return YES;
234: }
235:
236: PUBLIC BOOL HText_unregisterUnparsedEntityCallback (void)
237: {
238: text_unparsedEntity = NULL;
239: return YES;
240: }
Webmaster