Annotation of libwww/Library/src/HTProt.c, revision 2.8
2.1 frystyk 1: /* HTProt.c
2: ** ACCESS SCHEME MANAGER
3: **
4: ** (c) COPYRIGHT MIT 1995.
5: ** Please first read the full copyright statement in the file COPYRIGH.
6: **
7: **
8: ** HISTORY:
9: ** 6 July 95 HFN Spawned off from HTAccess
10: */
11:
12: /* Library Include files */
13: #include "tcp.h"
14: #include "HTUtils.h"
2.5 frystyk 15: #include "HTString.h"
2.1 frystyk 16: #include "HTParse.h"
17: #include "HTString.h"
18: #include "HTProt.h" /* Implemented here */
19:
20: /* Variables and typedefs local to this module */
2.5 frystyk 21: struct _HTProtocol {
22: char * name;
23: BOOL preemtive;
2.7 frystyk 24: HTEventCallback *callback;
2.5 frystyk 25: };
26:
2.1 frystyk 27: PRIVATE HTList * protocols = NULL; /* List of registered protocols */
28:
29: /* --------------------------------------------------------------------------*/
30: /* Management of the HTProtocol structure */
31: /* --------------------------------------------------------------------------*/
32:
33: /*
2.3 frystyk 34: ** Register a Protocol module as an active access method
2.1 frystyk 35: */
2.5 frystyk 36: PUBLIC BOOL HTProtocol_add (CONST char * name,
37: BOOL preemtive,
2.7 frystyk 38: HTEventCallback * callback)
2.1 frystyk 39: {
2.5 frystyk 40: if (name && callback) {
41: HTProtocol *newProt = (HTProtocol *) calloc(1, sizeof(HTProtocol));
42: if (newProt == NULL) outofmem(__FILE__, "HTProtocol_add");
43: StrAllocCopy(newProt->name, name);
44: newProt->preemtive = preemtive;
45: newProt->callback = callback;
46: if (!protocols) protocols = HTList_new();
47: return HTList_addObject(protocols, (void *) newProt);
48: }
49: return NO;
2.1 frystyk 50: }
51:
2.3 frystyk 52: /*
53: ** Deletes a Protocol module as an active access method
54: */
2.5 frystyk 55: PUBLIC BOOL HTProtocol_delete (CONST char * name)
2.3 frystyk 56: {
2.5 frystyk 57: if (protocols) {
58: HTList *cur = protocols;
59: HTProtocol *pres;
60: while ((pres = (HTProtocol *) HTList_nextObject(cur))) {
61: if (!strcmp(pres->name, name)) {
62: FREE(pres->name);
63: return HTList_removeObject(protocols, (void *) pres);
64: }
65: }
66: }
67: return NO;
68: }
69:
70: /*
71: ** Returns the callback function
72: */
2.7 frystyk 73: PUBLIC HTEventCallback *HTProtocol_callback (HTProtocol * protocol)
2.5 frystyk 74: {
75: return protocol ? protocol->callback : NULL;
76: }
77:
78: /*
79: ** Returns YES if preemtive else NO
80: */
81: PUBLIC BOOL HTProtocol_preemtive (HTProtocol * protocol)
82: {
83: return protocol ? protocol->preemtive : NO;
2.3 frystyk 84: }
2.1 frystyk 85:
86: /*
87: ** Delete the list of registered access methods. This is called from
2.5 frystyk 88: ** within HTLibTerminate. Thanks to Eric Sink, eric@spyglass.com
2.1 frystyk 89: */
2.5 frystyk 90: PUBLIC BOOL HTProtocol_deleteAll (void)
2.1 frystyk 91: {
92: if (protocols) {
2.5 frystyk 93: HTList *cur = protocols;
94: HTProtocol *pres;
95: while ((pres = (HTProtocol *) HTList_nextObject(cur))) {
96: FREE(pres->name);
97: free(pres);
98: }
2.1 frystyk 99: HTList_delete(protocols);
100: protocols = NULL;
2.5 frystyk 101: return YES;
2.1 frystyk 102: }
2.5 frystyk 103: return NO;
2.1 frystyk 104: }
105:
106:
107: /*
108: ** Search registered protocols to find suitable one.
109: ** Return YES if found, else NO
110: */
2.7 frystyk 111: PUBLIC BOOL HTProtocol_find (HTParentAnchor * anchor)
2.1 frystyk 112: {
113: if (anchor) {
114: char *access = HTParse(HTAnchor_physical(anchor), "", PARSE_ACCESS);
115: HTList *cur = protocols;
116: HTProtocol *p;
117: if (!cur) {
2.6 frystyk 118: if (WWWTRACE)
2.8 ! frystyk 119: TTYPrint(TDEST, "HTProtocol.. NO PROTOCOL MODULES INITIATED\n");
2.1 frystyk 120: } else {
121: while ((p = (HTProtocol *) HTList_nextObject(cur))) {
2.5 frystyk 122: if (strcasecomp(p->name, access)==0) {
2.1 frystyk 123: HTAnchor_setProtocol(anchor, p);
124: free(access);
125: return YES;
126: }
127: }
128: }
129: free(access);
130: }
131: return NO;
132: }
133:
Webmaster