/*
** Licensed to the Apache Software Foundation (ASF) under one or more
** contributor license agreements. See the NOTICE file distributed with
** this work for additional information regarding copyright ownership.
** The ASF licenses this file to You under the Apache License, Version 2.0
** (the "License"); you may not use this file except in compliance with
** the License. You may obtain a copy of the License at
**
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
*/
#include <assert.h>
#include "apreq_parser.h"
#include "apreq_error.h"
#include "apreq_util.h"
return APREQ_ERROR_GENERAL; \
return APR_SUCCESS; \
return APR_INCOMPLETE; \
} while (0);
struct hdr_ctx {
enum {
} status;
};
/********************* header parsing utils ********************/
{
apreq_value_t *v;
apr_bucket *e, *f;
apr_status_t s;
char *dest;
const char *data;
if (nlen == 0)
return APR_EBADARG;
*(const apreq_value_t **)&v = ¶m->v;
e = APR_BRIGADE_FIRST(bb);
/* store name in a temporary iovec array */
while (nlen > 0) {
&len, APR_BLOCK_READ);
if (s != APR_SUCCESS)
return s;
e = APR_BUCKET_NEXT(e);
}
/* skip gap */
while (glen > 0) {
if (s != APR_SUCCESS)
return s;
e = APR_BUCKET_NEXT(e);
}
/* copy value */
while (vlen > 0) {
if (s != APR_SUCCESS)
return s;
e = APR_BUCKET_NEXT(e);
}
--dest;
dest[-1] = 0;
/* write name */
++iov;
}
*dest = 0;
while ((f = APR_BRIGADE_FIRST(bb)) != e)
*p = param;
return APR_SUCCESS;
}
{
apr_bucket *e;
}
else
/* parse the brigade for CRLF_CRLF-terminated header block,
* each time starting from the front of the brigade.
*/
for (e = APR_BUCKET_NEXT(e);
e = APR_BUCKET_NEXT(e))
{
const char *data;
apr_status_t s;
if (APR_BUCKET_IS_EOS(e)) {
return APR_SUCCESS;
}
if ( s != APR_SUCCESS ) {
return s;
}
if (dlen == 0)
continue;
/* gap nlen = 13
* vvv glen = 3
* Sample-Header: grape vlen = 5
* ^^^^^^^^^^^^^ ^^^^^
* name value
*/
case HDR_NAME:
case '\n':
apr_bucket_split(e, off);
e = APR_BUCKET_NEXT(e);
do {
return APR_SUCCESS;
case ':':
if (off > 1) {
off = 1;
e = APR_BUCKET_NEXT(e);
}
goto parse_hdr_bucket;
default:
}
}
break;
case HDR_GAP:
case ' ':
case '\t':
break;
case '\n':
goto parse_hdr_bucket;
default:
if (off > 1) {
off = 1;
e = APR_BUCKET_NEXT(e);
}
goto parse_hdr_bucket;
}
}
break;
case HDR_VALUE:
goto parse_hdr_bucket;
}
}
break;
case HDR_NEWLINE:
break;
else {
case ' ':
case '\t':
++off;
break;
default:
/* can parse brigade now */
if (off > 0)
apr_bucket_split(e, off);
if (s != APR_SUCCESS) {
return s;
}
apreq_value_table_add(¶m->v, t);
goto parse_hdr_brigade;
}
/* cases ' ', '\t' fall through to HDR_CONTINUE */
}
case HDR_CONTINUE:
case ' ':
case '\t':
break;
case '\n':
goto parse_hdr_bucket;
default:
goto parse_hdr_bucket;
}
}
break;
default:
; /* not reached */
}
}
return APR_INCOMPLETE;
}