Hi,
Proposing some fixes for the snippet section of the modguide.
Fixes compilation errors and warning, avoids a segmentation fault,
cleaned output and removed some trailing spaces.
Regards,
Petter Berntsen
(irc: sluggr)
Index: docs/manual/developer/modguide.xml
===================================================================
--- docs/manual/developer/modguide.xml (revision 1535342)
+++ docs/manual/developer/modguide.xml (working copy)
@@ -1610,7 +1610,6 @@
if (res != OK || !pairs) return NULL; /* Return NULL if we failed or if
there are is no POST data */
kvp = apr_pcalloc(r->pool, sizeof(keyValuePair) * (pairs->nelts + 1));
while (pairs && !apr_is_empty_array(pairs)) {
- i++;
ap_form_pair_t *pair = (ap_form_pair_t *) apr_array_pop(pairs);
apr_brigade_length(pair->value, 1, &len);
size = (apr_size_t) len;
@@ -1617,16 +1616,16 @@
buffer = apr_palloc(r->pool, size + 1);
apr_brigade_flatten(pair->value, buffer, &size);
buffer[len] = 0;
- kvp[i]->key = apr_pstrdup(r->pool, pair->name);
- kvp[i]->value = buffer;
+ kvp[i].key = apr_pstrdup(r->pool, pair->name);
+ kvp[i].value = buffer;
+ i++;
}
- return kvp;
+ return kvp;
}
-static int example_handler(request_rec *r)
+static int example_handler(request_rec *r)
{
/*~~~~~~~~~~~~~~~~~~~~~~*/
-
keyValuePair* formData;
/*~~~~~~~~~~~~~~~~~~~~~~*/
@@ -1633,8 +1632,16 @@
formData = readPost(r);
if (formData) {
int i;
- for (i = 0; formData[i]; i++) {
- ap_rprintf(r, "%s = %s\n", formData[i]->key,
formData[i]->value);
+ for (i = 0; &formData[i]; i++) {
+ if (formData[i].key && formData[i].value) {
+ ap_rprintf(r, "%s = %s\n", formData[i].key,
formData[i].value);
+ } else if (formData[i].key) {
+ ap_rprintf(r, "%s\n", formData[i].key);
+ } else if (formData[i].value) {
+ ap_rprintf(r, "= %s\n", formData[i].value);
+ } else {
+ break;
+ }
}
}
return OK;
@@ -1644,13 +1651,13 @@
</section>
-
+
<section id="headers_out"><title>Printing out every HTTP header
received</title>
-
+
<!-- BEGIN EXAMPLE CODE -->
<highlight language="c">
-static int example_handler(request_rec *r)
+static int example_handler(request_rec *r)
{
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
const apr_array_header_t *fields;
@@ -1661,7 +1668,7 @@
fields = apr_table_elts(r->headers_in);
e = (apr_table_entry_t *) fields->elts;
for(i = 0; i < fields->nelts; i++) {
- ap_rprintf(r, "<b>%s</b>: %s<br/>",
e[i].key, e[i].val);
+ ap_rprintf(r, "%s: %s\n", e[i].key, e[i].val);
}
return OK;
}
@@ -1670,10 +1677,10 @@
</section>
-
+
<section id="request_body"><title>Reading the request body into
memory</title>
-
+
<!-- BEGIN EXAMPLE CODE -->
<highlight language="c">
static int util_read(request_rec *r, const char **rbuf, apr_off_t *size)
@@ -1718,8 +1725,8 @@
const char *buffer;
/*~~~~~~~~~~~~~~~~*/
- if(util_read(r, &data, &size) == OK) {
- ap_rprintf(r, "We read a request body that was %u bytes
long", size);
+ if(util_read(r, &buffer, &size) == OK) {
+ ap_rprintf(r, "We read a request body that was %" APR_OFF_T_FMT "
bytes long", size);
}
return OK;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]