Annotation of libwww/Library/src/HTTrans.c, revision 2.6
2.1 frystyk 1: /* HTTrans.c
2: ** TRANSPORT LAYER MANAGER
3: **
4: ** (c) COPYRIGHT MIT 1995.
5: ** Please first read the full copyright statement in the file COPYRIGH.
2.6 ! frystyk 6: ** @(#) $Id: HTTrans.c,v 2.5 1998/05/04 19:37:36 frystyk Exp $
2.1 frystyk 7: **
8: ** HISTORY:
9: ** Marts 96 HFN Written
10: */
11:
12: /* Library Include files */
2.5 frystyk 13: #include "wwwsys.h"
2.4 frystyk 14: #include "WWWUtil.h"
2.1 frystyk 15: #include "HTParse.h"
16: #include "HTReq.h"
17: #include "HTIOStream.h"
18: #include "HTTrans.h" /* Implemented here */
19:
20: PRIVATE HTList * transports = NULL; /* List of registered transports */
21:
22: /* --------------------------------------------------------------------------*/
23:
24: /*
25: ** Register a Transport module
26: */
27: PUBLIC BOOL HTTransport_add (const char * name,
2.4 frystyk 28: HTTransportMode mode,
2.1 frystyk 29: HTInput_new * get_input,
30: HTOutput_new * get_output)
31: {
2.3 frystyk 32: if (name && (get_input || get_output)) {
2.1 frystyk 33: HTTransport * tp;
34: if ((tp = (HTTransport *) HT_CALLOC(1, sizeof(HTTransport))) == NULL)
35: HT_OUTOFMEM("HTTransport_add");
36: StrAllocCopy(tp->name, name);
37: {
38: char *ptr = tp->name;
39: while ((*ptr = TOLOWER(*ptr))) ptr++;
40: }
41: tp->mode = mode;
42: tp->input_new = get_input;
43: tp->output_new = get_output;
44: if (!transports) transports = HTList_new();
2.2 frystyk 45: if (CORE_TRACE) HTTrace("Transport... Adding `%s'\n", name);
2.1 frystyk 46: return HTList_addObject(transports, (void *) tp);
2.3 frystyk 47: } else if (CORE_TRACE) HTTrace("Transport... Can't add this...\n");
2.1 frystyk 48: return NO;
49: }
50:
51: /*
52: ** Deletes a Transport module
53: */
54: PUBLIC BOOL HTTransport_delete (const char * name)
55: {
56: if (transports) {
57: HTList *cur = transports;
58: HTTransport *pres;
59: while ((pres = (HTTransport *) HTList_nextObject(cur))) {
60: if (!strcmp(pres->name, name)) {
61: HT_FREE(pres->name);
62: return HTList_removeObject(transports, (void *) pres);
63: }
64: }
65: }
66: return NO;
67: }
68:
69: /*
70: ** Delete the list of registered transports. This is called from
71: ** within HTLibTerminate.
72: */
73: PUBLIC BOOL HTTransport_deleteAll (void)
74: {
75: if (transports) {
76: HTList * cur = transports;
77: HTTransport * pres;
78: while ((pres = (HTTransport *) HTList_nextObject(cur))) {
79: HT_FREE(pres->name);
80: HT_FREE(pres);
81: }
82: HTList_delete(transports);
83: transports = NULL;
84: return YES;
85: }
86: return NO;
87: }
88:
89: /*
90: ** Search registered transports to find a suitable transport object.
91: ** Return transport object or NULL
92: */
93: PUBLIC HTTransport * HTTransport_find (HTRequest * request, const char * name)
94: {
2.6 ! frystyk 95: if (name) {
2.1 frystyk 96: HTList * cur = transports;
97: HTTransport * pres;
98: if (cur) {
99: while ((pres = (HTTransport *) HTList_nextObject(cur))) {
100: if (!strcmp(pres->name, name)) return pres;
101: }
102: }
2.6 ! frystyk 103: if (request)
! 104: HTRequest_addError(request, ERR_FATAL, NO, HTERR_CLASS, (char *) name,
! 105: (int) strlen(name), "HTTransport_find");
2.1 frystyk 106: }
107: return NULL;
108: }
109:
2.4 frystyk 110: PUBLIC HTTransportMode HTTransport_mode (HTTransport * tp)
2.1 frystyk 111: {
2.4 frystyk 112: return (tp ? tp->mode : HT_TP_SINGLE);
2.1 frystyk 113: }
2.4 frystyk 114:
115: PUBLIC BOOL HTTransport_setMode (HTTransport * tp, HTTransportMode mode)
116: {
117: if (tp) {
118: tp->mode = mode;
119: return YES;
120: }
121: return NO;
122: }
123:
Webmaster