2 Copyright (C) 2000-2005 SKYRIX Software AG
4 This file is part of SOPE.
6 SOPE is free software; you can redistribute it and/or modify it under
7 the terms of the GNU Lesser General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
11 SOPE is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14 License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with SOPE; see the file COPYING. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
23 #include "NGBufferedDescriptor.h"
25 unsigned char NGScanResponseLine(NGBufferedDescriptor *_in,
26 unsigned char *_version, int *_status,
29 if (_in == NULL) return 0;
31 if (_version) *_version = '\0';
32 if (_text) *_text = '\0';
33 if (_status) *_status = '\0';
39 /* scan HTTP Version */
41 c = NGBufferedDescriptor_readChar(_in);
43 while ((c > 0) && !apr_isspace(c) && (i < 16)) {
44 if (_version) _version[i] = c;
46 c = NGBufferedDescriptor_readChar(_in);
48 if (_version) _version[i] = '\0';
49 if (c < 1) return 0; // read error
53 while ((c > 0) && apr_isspace(c))
54 c = NGBufferedDescriptor_readChar(_in);
55 if (c < 1) return 0; // read error
61 while ((c > 0) && !apr_isspace(c) && (c != '\r') && (c != '\n') &&
65 c = NGBufferedDescriptor_readChar(_in);
68 if (_status) *_status = atoi(buf);
72 while ((c > 0) && apr_isspace(c))
73 c = NGBufferedDescriptor_readChar(_in);
74 if (c < 1) return 0; // read error
77 if (c == '\n') return 1; // response without reason
78 if (c == '\r') { // response without reason
79 c = NGBufferedDescriptor_readChar(_in); // c=='\n'
86 while ((c > 0) && !apr_isspace(c) && (c != '\r') && (c != '\n') &&
88 if (_text) _text[i] = c;
90 c = NGBufferedDescriptor_readChar(_in);
92 if (_text) _text[i] = '\0';
93 if (c < 1) return 0; // read error
96 /* scan until line end */
97 while ((c > 0) && (c != '\n'))
98 c = NGBufferedDescriptor_readChar(_in);
100 if (c < 1) return 0; // read error
105 apr_table_t *NGScanHeaders(apr_pool_t *_pool, NGBufferedDescriptor *_in) {
106 apr_table_t *headers = NULL;
108 if (_in == NULL) return NULL;
110 headers = apr_table_make(_pool, 64);
112 unsigned char name[256];
113 unsigned char value[8000];
119 c = NGBufferedDescriptor_readChar(_in);
123 // test for end of HTTP header
125 if (c == '\n') // end line '\n'
127 if (c == '\r') { // end line '\r\n'
128 c = NGBufferedDescriptor_readChar(_in);
137 while ((c > 0) && (c != ':') && (i < 255)) {
140 c = NGBufferedDescriptor_readChar(_in);
143 if (i < 1) break; // empty header name ?!
145 if (c != ':') break; // missing separator ?
147 // skip spaces following separator
148 c = NGBufferedDescriptor_readChar(_in);
149 while ((c > 0) && (apr_isspace(c)))
150 c = NGBufferedDescriptor_readChar(_in);
155 while ((c > 0) && (c != '\r') && (j < 7999)) {
158 c = NGBufferedDescriptor_readChar(_in);
161 if (j < 1) break; // empty header value ?!
164 if (c == '\n') // '\n' header end
166 else if (c == '\r') { // '\r\n' header end
167 c = NGBufferedDescriptor_readChar(_in);
168 if (c != '\n') break;
170 else // no valid header end
174 apr_table_set(headers, name, value);