-const char jcc_rcs[] = "$Id: jcc.c,v 1.179 2008/05/20 20:13:32 fabiankeil Exp $";
+const char jcc_rcs[] = "$Id: jcc.c,v 1.180 2008/05/21 15:26:32 fabiankeil Exp $";
/*********************************************************************
*
* File : $Source: /cvsroot/ijbswa/current/jcc.c,v $
*
* Revisions :
* $Log: jcc.c,v $
+ * Revision 1.180 2008/05/21 15:26:32 fabiankeil
+ * - Mark csp as immutable for send_crunch_response().
+ * - Fix comment spelling.
+ *
* Revision 1.179 2008/05/20 20:13:32 fabiankeil
* Factor update_server_headers() out of sed(), ditch the
* first_run hack and make server_patterns_light static.
list_append_list_unique(csp->headers, headers);
destroy_list(headers);
- err = sed(client_patterns, add_client_headers, csp);
+ err = sed(csp, FILTER_CLIENT_HEADERS);
if (JB_ERR_OK != err)
{
assert(err == JB_ERR_PARSE);
return;
}
- /* we have now received the entire header.
+ /*
+ * We have now received the entire server header,
* filter it and send the result to the client
*/
- if (JB_ERR_OK != sed(server_patterns, add_server_headers, csp))
+ if (JB_ERR_OK != sed(csp, FILTER_SERVER_HEADERS))
{
log_error(LOG_LEVEL_FATAL, "Failed to parse server headers.");
}
-const char parsers_rcs[] = "$Id: parsers.c,v 1.130 2008/05/19 17:18:04 fabiankeil Exp $";
+const char parsers_rcs[] = "$Id: parsers.c,v 1.131 2008/05/20 20:13:30 fabiankeil Exp $";
/*********************************************************************
*
* File : $Source: /cvsroot/ijbswa/current/parsers.c,v $
*
* Revisions :
* $Log: parsers.c,v $
+ * Revision 1.131 2008/05/20 20:13:30 fabiankeil
+ * Factor update_server_headers() out of sed(), ditch the
+ * first_run hack and make server_patterns_light static.
+ *
* Revision 1.130 2008/05/19 17:18:04 fabiankeil
* Wrap memmove() calls in string_move()
* to document the purpose in one place.
static jb_err handle_conditional_hide_referrer_parameter(char **header,
const char *host, const int parameter_conditional_block);
-const struct parsers client_patterns[] = {
+/*
+ * List of functions to run on a list of headers.
+ */
+struct parsers
+{
+ /** The header prefix to match */
+ const char *str;
+
+ /** The length of the prefix to match */
+ const size_t len;
+
+ /** The function to apply to this line */
+ const parser_func_ptr parser;
+};
+
+static const struct parsers client_patterns[] = {
{ "referer:", 8, client_referrer },
{ "user-agent:", 11, client_uagent },
{ "ua-", 3, client_ua },
{ NULL, 0, NULL }
};
-const struct parsers server_patterns[] = {
+static const struct parsers server_patterns[] = {
{ "HTTP/", 5, server_http },
{ "set-cookie:", 11, server_set_cookie },
{ "connection:", 11, connection },
{ NULL, 0, NULL }
};
-const add_header_func_ptr add_client_headers[] = {
+static const add_header_func_ptr add_client_headers[] = {
client_host_adder,
client_xtra_adder,
/* Temporarily disabled: client_accept_encoding_adder, */
NULL
};
-const add_header_func_ptr add_server_headers[] = {
+static const add_header_func_ptr add_server_headers[] = {
connection_close_adder,
NULL
};
* header lines.
*
* Parameters :
- * 1 : pats = list of patterns to match against headers
- * 2 : more_headers = list of functions to add more
- * headers (client or server)
- * 3 : csp = Current client state (buffers, headers, etc...)
+ * 1 : csp = Current client state (buffers, headers, etc...)
+ * 2 : filter_server_headers = Boolean to switch between
+ * server and header filtering.
*
* Returns : JB_ERR_OK in case off success, or
* JB_ERR_MEMORY on out-of-memory error.
*
*********************************************************************/
-jb_err sed(const struct parsers pats[],
- const add_header_func_ptr more_headers[],
- struct client_state *csp)
+jb_err sed(struct client_state *csp, int filter_server_headers)
{
+ /* XXX: use more descriptive names. */
struct list_entry *p;
const struct parsers *v;
const add_header_func_ptr *f;
jb_err err = JB_ERR_OK;
- assert(more_headers != NULL);
+ if (filter_server_headers)
+ {
+ v = server_patterns;
+ f = add_server_headers;
+ }
+ else
+ {
+ v = client_patterns;
+ f = add_client_headers;
+ }
scan_headers(csp);
- for (v = pats; (err == JB_ERR_OK) && (v->str != NULL); v++)
+ while ((err == JB_ERR_OK) && (v->str != NULL))
{
for (p = csp->headers->first; (err == JB_ERR_OK) && (p != NULL); p = p->next)
{
err = v->parser(csp, (char **)&(p->str));
}
}
+ v++;
}
- /* place any additional headers on the csp->headers list */
- for (f = more_headers; (err == JB_ERR_OK) && (*f) ; f++)
+ /* place additional headers on the csp->headers list */
+ while ((err == JB_ERR_OK) && (*f))
{
err = (*f)(csp);
+ f++;
}
return err;
#ifndef PARSERS_H_INCLUDED
#define PARSERS_H_INCLUDED
-#define PARSERS_H_VERSION "$Id: parsers.h,v 1.44 2008/05/20 16:05:09 fabiankeil Exp $"
+#define PARSERS_H_VERSION "$Id: parsers.h,v 1.45 2008/05/20 20:13:30 fabiankeil Exp $"
/*********************************************************************
*
* File : $Source: /cvsroot/ijbswa/current/parsers.h,v $
*
* Revisions :
* $Log: parsers.h,v $
+ * Revision 1.45 2008/05/20 20:13:30 fabiankeil
+ * Factor update_server_headers() out of sed(), ditch the
+ * first_run hack and make server_patterns_light static.
+ *
* Revision 1.44 2008/05/20 16:05:09 fabiankeil
* Move parsers structure definition from project.h to parsers.h.
*
extern "C" {
#endif
-/**
- * List of functions to run on a list of headers.
- * XXX: make parsers local to parsers.c.
- */
-struct parsers
-{
- /** The header prefix to match */
- const char *str;
-
- /** The length of the prefix to match */
- const size_t len;
-
- /** The function to apply to this line */
- const parser_func_ptr parser;
-};
-
-extern const struct parsers client_patterns[];
-extern const struct parsers server_patterns[];
-
-extern const add_header_func_ptr add_client_headers[];
-extern const add_header_func_ptr add_server_headers[];
+/* Used for sed()'s second argument. */
+#define FILTER_CLIENT_HEADERS 0
+#define FILTER_SERVER_HEADERS 1
extern int flush_socket(jb_socket fd, struct iob *iob);
extern jb_err add_to_iob(struct client_state *csp, char *buf, int n);
extern jb_err decompress_iob(struct client_state *csp);
extern char *get_header(struct iob *iob);
extern char *get_header_value(const struct list *header_list, const char *header_name);
-extern jb_err sed(const struct parsers pats[], const add_header_func_ptr more_headers[], struct client_state *csp);
+extern jb_err sed(struct client_state *csp, int filter_server_headers);
extern jb_err update_server_headers(struct client_state *csp);
extern void get_http_time(int time_offset, char *buf, size_t buffer_size);
extern jb_err get_destination_from_headers(const struct list *headers, struct http_request *http);