-const char jcc_rcs[] = "$Id: jcc.c,v 1.177 2008/05/10 11:51:12 fabiankeil Exp $";
+const char jcc_rcs[] = "$Id: jcc.c,v 1.178 2008/05/10 13:23:38 fabiankeil Exp $";
/*********************************************************************
*
* File : $Source: /cvsroot/ijbswa/current/jcc.c,v $
*
* Revisions :
* $Log: jcc.c,v $
+ * Revision 1.178 2008/05/10 13:23:38 fabiankeil
+ * Don't provide get_header() with the whole client state
+ * structure when it only needs access to csp->iob.
+ *
* Revision 1.177 2008/05/10 11:51:12 fabiankeil
* Make the "read the rest of the headers" loop a bit more readable.
*
csp->content_length = (size_t)(csp->iob->eod - csp->iob->cur);
}
- if (JB_ERR_OK != sed(server_patterns_light, NULL, csp))
+ if (JB_ERR_OK != update_server_headers(csp))
{
- log_error(LOG_LEVEL_FATAL, "Failed to parse server headers.");
+ log_error(LOG_LEVEL_FATAL,
+ "Failed to update server headers. after filtering.");
}
hdr = list_to_text(csp->headers);
log_error(LOG_LEVEL_FATAL, "Out of memory parsing server header");
}
- /*
- * Shouldn't happen because this was the second sed run
- * and tags are only created for the first one.
- */
- assert(!crunch_response_triggered(csp, crunchers_all));
-
if (write_socket(csp->cfd, hdr, strlen(hdr))
|| write_socket(csp->cfd, p != NULL ? p : csp->iob->cur, csp->content_length))
{
-const char parsers_rcs[] = "$Id: parsers.c,v 1.129 2008/05/17 14:02:07 fabiankeil Exp $";
+const char parsers_rcs[] = "$Id: parsers.c,v 1.130 2008/05/19 17:18:04 fabiankeil Exp $";
/*********************************************************************
*
* File : $Source: /cvsroot/ijbswa/current/parsers.c,v $
*
* Revisions :
* $Log: parsers.c,v $
+ * Revision 1.130 2008/05/19 17:18:04 fabiankeil
+ * Wrap memmove() calls in string_move()
+ * to document the purpose in one place.
+ *
* Revision 1.129 2008/05/17 14:02:07 fabiankeil
* Normalize linear header white space.
*
{ NULL, 0, NULL }
};
-const struct parsers server_patterns_light[] = {
- { "Content-Length:", 15, server_content_length },
- { "Transfer-Encoding:", 18, server_transfer_coding },
-#ifdef FEATURE_ZLIB
- { "Content-Encoding:", 17, server_content_encoding },
-#endif /* def FEATURE_ZLIB */
- { NULL, 0, NULL }
-};
-
const add_header_func_ptr add_client_headers[] = {
client_host_adder,
client_xtra_adder,
* As a side effect it frees the space used by the original
* header lines.
*
- * XXX: should be split to remove the first_run hack.
- *
* Parameters :
* 1 : pats = list of patterns to match against headers
* 2 : more_headers = list of functions to add more
const struct parsers *v;
const add_header_func_ptr *f;
jb_err err = JB_ERR_OK;
- int first_run;
- /*
- * If filtering is enabled, sed is run twice,
- * but most of the work needs to be done only once.
- */
- first_run = (more_headers != NULL ) ? 1 : 0;
+ assert(more_headers != NULL);
- if (first_run) /* Parse and print */
- {
- scan_headers(csp);
+ scan_headers(csp);
- for (v = pats; (err == JB_ERR_OK) && (v->str != NULL) ; v++)
+ for (v = pats; (err == JB_ERR_OK) && (v->str != NULL); v++)
+ {
+ for (p = csp->headers->first; (err == JB_ERR_OK) && (p != NULL); p = p->next)
{
- for (p = csp->headers->first; (err == JB_ERR_OK) && (p != NULL) ; p = p->next)
- {
- /* Header crunch()ed in previous run? -> ignore */
- if (p->str == NULL) continue;
+ /* Header crunch()ed in previous run? -> ignore */
+ if (p->str == NULL) continue;
- /* Does the current parser handle this header? */
- if ((strncmpic(p->str, v->str, v->len) == 0) || (v->len == CHECK_EVERY_HEADER_REMAINING))
- {
- err = v->parser(csp, (char **)&(p->str));
- }
+ /* Does the current parser handle this header? */
+ if ((strncmpic(p->str, v->str, v->len) == 0) ||
+ (v->len == CHECK_EVERY_HEADER_REMAINING))
+ {
+ err = v->parser(csp, (char **)&(p->str));
}
}
- /* place any additional headers on the csp->headers list */
- for (f = more_headers; (err == JB_ERR_OK) && (*f) ; f++)
- {
- err = (*f)(csp);
- }
}
- else /* Parse only */
+
+ /* place any additional headers on the csp->headers list */
+ for (f = more_headers; (err == JB_ERR_OK) && (*f) ; f++)
{
- /*
- * The second run is only needed if the body was modified
- * and the content-lenght has changed.
- */
- if (strncmpic(csp->http->cmd, "HEAD", 4))
+ err = (*f)(csp);
+ }
+
+ return err;
+}
+
+
+/*********************************************************************
+ *
+ * Function : update_server_headers
+ *
+ * Description : Updates server headers after the body has been modified.
+ *
+ * Parameters :
+ * 1 : csp = Current client state (buffers, headers, etc...)
+ *
+ * Returns : JB_ERR_OK in case off success, or
+ * JB_ERR_MEMORY on out-of-memory error.
+ *
+ *********************************************************************/
+jb_err update_server_headers(struct client_state *csp)
+{
+ jb_err err = JB_ERR_OK;
+
+ static const struct parsers server_patterns_light[] = {
+ { "Content-Length:", 15, server_content_length },
+ { "Transfer-Encoding:", 18, server_transfer_coding },
+#ifdef FEATURE_ZLIB
+ { "Content-Encoding:", 17, server_content_encoding },
+#endif /* def FEATURE_ZLIB */
+ { NULL, 0, NULL }
+ };
+
+ if (strncmpic(csp->http->cmd, "HEAD", 4))
+ {
+ const struct parsers *v;
+ struct list_entry *p;
+
+ for (v = server_patterns_light; (err == JB_ERR_OK) && (v->str != NULL); v++)
{
- /*XXX: Code duplication */
- for (v = pats; (err == JB_ERR_OK) && (v->str != NULL) ; v++)
+ for (p = csp->headers->first; (err == JB_ERR_OK) && (p != NULL); p = p->next)
{
- for (p = csp->headers->first; (err == JB_ERR_OK) && (p != NULL) ; p = p->next)
- {
- /* Header crunch()ed in previous run? -> ignore */
- if (p->str == NULL) continue;
+ /* Header crunch()ed in previous run? -> ignore */
+ if (p->str == NULL) continue;
- /* Does the current parser handle this header? */
- if (strncmpic(p->str, v->str, v->len) == 0)
- {
- err = v->parser(csp, (char **)&(p->str));
- }
+ /* Does the current parser handle this header? */
+ if (strncmpic(p->str, v->str, v->len) == 0)
+ {
+ err = v->parser(csp, (char **)&(p->str));
}
}
}
}
-
/*********************************************************************
*
* Function : header_tagger
#ifndef PARSERS_H_INCLUDED
#define PARSERS_H_INCLUDED
-#define PARSERS_H_VERSION "$Id: parsers.h,v 1.43 2008/05/10 13:23:38 fabiankeil Exp $"
+#define PARSERS_H_VERSION "$Id: parsers.h,v 1.44 2008/05/20 16:05:09 fabiankeil Exp $"
/*********************************************************************
*
* File : $Source: /cvsroot/ijbswa/current/parsers.h,v $
*
* Revisions :
* $Log: parsers.h,v $
+ * Revision 1.44 2008/05/20 16:05:09 fabiankeil
+ * Move parsers structure definition from project.h to parsers.h.
+ *
* Revision 1.43 2008/05/10 13:23:38 fabiankeil
* Don't provide get_header() with the whole client state
* structure when it only needs access to csp->iob.
extern const struct parsers client_patterns[];
extern const struct parsers server_patterns[];
-extern const struct parsers server_patterns_light[];
extern const add_header_func_ptr add_client_headers[];
extern const add_header_func_ptr add_server_headers[];
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 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);