Annotation of libwww/Library/src/HTMIMERq.c, revision 2.16
2.1 frystyk 1: /* HTMIMERq.c
2.10 frystyk 2: ** MIME ENTITY HEADERS GENERATION
2.1 frystyk 3: **
2.15 frystyk 4: ** (c) COPYRIGHT MIT 1995.
5: ** Please first read the full copyright statement in the file COPYRIGH.
2.16 ! frystyk 6: ** @(#) $Id: HTMIMERq.c,v 2.15 1996/03/19 14:22:25 frystyk State $
2.15 frystyk 7: **
2.1 frystyk 8: ** This module implements the output stream for MIME used for sending
2.10 frystyk 9: ** requests with a entity body to HTTP, NEWS, etc. or for generating
10: ** responses
2.1 frystyk 11: **
12: ** History:
13: ** Jan 95 HFN Written
14: */
15:
16: /* Library Includes */
2.14 frystyk 17: #include "sysdep.h"
2.1 frystyk 18: #include "HTUtils.h"
19: #include "HTString.h"
2.5 frystyk 20: #include "HTWWWStr.h"
2.1 frystyk 21: #include "HTParse.h"
22: #include "HTFormat.h"
2.7 frystyk 23: #include "HTAncMan.h"
2.1 frystyk 24: #include "HTNetMan.h"
25: #include "HTDNS.h"
26: #include "HTTCP.h"
27: #include "HTWriter.h"
2.2 frystyk 28: #include "HTHeader.h"
2.1 frystyk 29: #include "HTReqMan.h"
30: #include "HTTPReq.h" /* Implements */
31:
32: #define PUTBLOCK(b, l) (*me->target->isa->put_block)(me->target, b, l)
33:
34: struct _HTStream {
2.14 frystyk 35: const HTStreamClass * isa;
2.1 frystyk 36: HTStream * target;
37: HTRequest * request;
2.10 frystyk 38: BOOL endHeader;
2.1 frystyk 39: BOOL transparent;
40: };
41:
42: /* ------------------------------------------------------------------------- */
43: /* MIME Output Request Stream */
44: /* ------------------------------------------------------------------------- */
45:
46: /* MIMEMakeRequest
47: ** ---------------
2.10 frystyk 48: ** Generates the BODY parts of a MIME message.
2.1 frystyk 49: */
2.2 frystyk 50: PRIVATE int MIMEMakeRequest (HTStream * me, HTRequest * request)
2.1 frystyk 51: {
2.10 frystyk 52: char linebuf[256]; /* @@@ */
2.11 frystyk 53: HTParentAnchor *entity = request->source_anchor ?
54: request->source_anchor : request->anchor;
2.1 frystyk 55:
2.10 frystyk 56: if (request->EntityMask & HT_E_ALLOW) {
57: /* @@@@@@@@@@ */
58: }
59: if (request->EntityMask & HT_E_CONTENT_ENCODING &&
60: entity->content_encoding) {
61: sprintf(linebuf, "Content-Encoding: %s%c%c",
62: HTAtom_name(entity->content_encoding), CR, LF);
2.2 frystyk 63: PUTBLOCK(linebuf, (int) strlen(linebuf));
2.1 frystyk 64: }
2.10 frystyk 65:
66: /* @@@ SHOULD BE A LIST @@@ */
67: if (request->EntityMask & HT_E_CONTENT_LANGUAGE &&
68: entity->content_language) {
69: sprintf(linebuf, "Content-Language: %s%c%c",
70: HTAtom_name(entity->content_language), CR, LF);
2.2 frystyk 71: PUTBLOCK(linebuf, (int) strlen(linebuf));
2.1 frystyk 72: }
2.10 frystyk 73: if (request->EntityMask & HT_E_CONTENT_LENGTH) { /* Must be there!!! */
74: sprintf(linebuf, "Content-Length: %ld%c%c",
75: entity->content_length, CR, LF);
76: PUTBLOCK(linebuf, (int) strlen(linebuf));
77: }
78: if (request->EntityMask & HT_E_CTE && entity->cte) {
79: sprintf(linebuf, "Content-Transfer-Encoding: %s%c%c",
80: HTAtom_name(entity->cte), CR, LF);
2.2 frystyk 81: PUTBLOCK(linebuf, (int) strlen(linebuf));
2.1 frystyk 82: }
2.10 frystyk 83: if (request->EntityMask & HT_E_CONTENT_TYPE && entity->content_type) {
84: int len;
85: sprintf(linebuf, "Content-Type: %s",
86: HTAtom_name(entity->content_type));
87: if (entity->charset) {
88: strcat(linebuf, "; charset=");
89: strcat(linebuf, HTAtom_name(entity->charset));
90: }
91: if (entity->level) {
92: strcat(linebuf, "; level=");
93: strcat(linebuf, HTAtom_name(entity->level));
94: }
95: len = strlen(linebuf);
96: *(linebuf+len) = CR;
97: *(linebuf+len+1) = LF;
98: *(linebuf+len+2) = '\0';
99: PUTBLOCK(linebuf, (int) len+2);
100: }
101: if (request->EntityMask & HT_E_DERIVED_FROM && entity->derived_from) {
102: sprintf(linebuf, "Derived-From: %s%c%c", entity->derived_from,
103: CR, LF);
2.2 frystyk 104: PUTBLOCK(linebuf, (int) strlen(linebuf));
2.1 frystyk 105: }
2.10 frystyk 106: if (request->EntityMask & HT_E_EXPIRES) {
107: if (entity->expires != -1) {
108: sprintf(linebuf, "Expires: %s%c%c",
109: HTDateTimeStr(&entity->expires, NO), CR,LF);
2.2 frystyk 110: PUTBLOCK(linebuf, (int) strlen(linebuf));
2.1 frystyk 111: }
2.10 frystyk 112: }
113: if (request->EntityMask & HT_E_LAST_MODIFIED) {
114: if (entity->last_modified != -1) {
115: sprintf(linebuf, "Last-Modified: %s%c%c",
116: HTDateTimeStr(&entity->last_modified, NO), CR,LF);
2.2 frystyk 117: PUTBLOCK(linebuf, (int) strlen(linebuf));
2.1 frystyk 118: }
2.10 frystyk 119: }
120: if (request->EntityMask & HT_E_LINK) { /* @@@@@@@@@@ */
2.1 frystyk 121:
2.10 frystyk 122: }
123: if (request->EntityMask & HT_E_TITLE) { /* @@@@@@@@@@ */
2.1 frystyk 124:
2.10 frystyk 125: }
126: if (request->EntityMask & HT_E_URI) { /* @@@@@@@@@@ */
2.1 frystyk 127:
128: }
2.10 frystyk 129: if (request->EntityMask & HT_E_VERSION && entity->version) {
130: sprintf(linebuf, "Version: %s%c%c", entity->version, CR, LF);
131: PUTBLOCK(linebuf, (int) strlen(linebuf));
132: }
133: if (me->endHeader) {
134: sprintf(linebuf, "%c%c", CR, LF); /* Blank line means "end" */
135: PUTBLOCK(linebuf, (int) strlen(linebuf));
2.2 frystyk 136: }
2.13 eric 137: if (PROT_TRACE) HTTrace("MIME........ Generating Entity Headers\n");
2.2 frystyk 138: return HT_OK;
2.1 frystyk 139: }
140:
2.14 frystyk 141: PRIVATE int MIMERequest_put_block (HTStream * me, const char * b, int l)
2.1 frystyk 142: {
143: if (me->transparent)
144: return b ? PUTBLOCK(b, l) : HT_OK;
145: else {
146: MIMEMakeRequest(me, me->request);
2.9 frystyk 147: if (HTRequest_isDestination(me->request)) {
148: (*me->target->isa->flush)(me->target);
149: HTNet_setBytesWritten(me->request->net, 0);
2.1 frystyk 150: }
2.9 frystyk 151: me->transparent = YES;
2.2 frystyk 152: return b ? PUTBLOCK(b, l) : HT_OK;
2.1 frystyk 153: }
154: }
155:
156: PRIVATE int MIMERequest_put_character (HTStream * me, char c)
157: {
158: return MIMERequest_put_block(me, &c, 1);
159: }
160:
2.14 frystyk 161: PRIVATE int MIMERequest_put_string (HTStream * me, const char * s)
2.1 frystyk 162: {
163: return MIMERequest_put_block(me, s, strlen(s));
164: }
165:
166: /*
167: ** Flushes header but doesn't free stream object
168: */
169: PRIVATE int MIMERequest_flush (HTStream * me)
170: {
171: int status = MIMERequest_put_block(me, NULL, 0);
172: return status==HT_OK ? (*me->target->isa->flush)(me->target) : status;
173: }
174:
175: /*
176: ** Flushes data and frees stream object
177: */
178: PRIVATE int MIMERequest_free (HTStream * me)
179: {
180: int status = MIMERequest_flush(me);
181: if (status != HT_WOULD_BLOCK) {
182: if ((status = (*me->target->isa->_free)(me->target)) == HT_WOULD_BLOCK)
183: return HT_WOULD_BLOCK;
2.12 frystyk 184: HT_FREE(me);
2.1 frystyk 185: }
186: return status;
187: }
188:
2.4 frystyk 189: PRIVATE int MIMERequest_abort (HTStream * me, HTList * e)
2.1 frystyk 190: {
191: if (me->target) (*me->target->isa->abort)(me->target, e);
2.12 frystyk 192: HT_FREE(me);
2.13 eric 193: if (PROT_TRACE) HTTrace("MIMERequest. ABORTING...\n");
2.1 frystyk 194: return HT_ERROR;
195: }
196:
197: /* MIMERequest Stream
198: ** -----------------
199: */
2.14 frystyk 200: PRIVATE const HTStreamClass MIMERequestClass =
2.1 frystyk 201: {
202: "MIMERequest",
203: MIMERequest_flush,
204: MIMERequest_free,
205: MIMERequest_abort,
206: MIMERequest_put_character,
207: MIMERequest_put_string,
208: MIMERequest_put_block
209: };
210:
2.10 frystyk 211: PUBLIC HTStream * HTMIMERequest_new (HTRequest * request, HTStream * target,
212: BOOL endHeader)
2.1 frystyk 213: {
2.12 frystyk 214: HTStream * me;
215: if ((me = (HTStream *) HT_CALLOC(1, sizeof(HTStream))) == NULL)
216: HT_OUTOFMEM("HTMIMERequest_new");
2.1 frystyk 217: me->isa = &MIMERequestClass;
218: me->target = target;
219: me->request = request;
2.10 frystyk 220: me->endHeader = endHeader;
2.1 frystyk 221: me->transparent = NO;
222: return me;
223: }
Webmaster