Actions
Bug #1732
closedReplace buffer_append_string with BUFFER_APPEND_STRING_CONST
ASK QUESTIONS IN Forums:
Description
On http://www.xarg.org/2008/07/get-the-last-percents-out-of-lighttpd/ I've descriped how you can get a little more performance. It's quite simple, because you'll save a few strlen() calls.
Run the following commands with sed in the lighty source directory to replace the dynamic functions with the macros:
#!ShellExample $ find . -name "*.c" -exec sed -ie 's/buffer_append_string\(([a-z0-9_]\+,[[:space:]]*".*")\)/BUFFER_APPEND_STRING_CONST\1/g' {} \; $ find . -name "*.c" -exec sed -ie 's/buffer_copy_string\(([a-z0-9_]\+,[[:space:]]*".*")\)/BUFFER_COPY_STRING_CONST\1/g' {} \;
-- crypt
Files
Updated by Anonymous over 16 years ago
following patch, generated thanks two commands by moo, replaces buffer_append_string and buffer_copy_string with BUFFER_APPEND_STRING_CONST and BUFFER_COPY_STRING_CONST.
Index: src/mod_proxy_core_protocol.c =================================================================== --- src/mod_proxy_core_protocol.c (revisione 2201) +++ src/mod_proxy_core_protocol.c (copia locale) @@ -44,12 +44,12 @@ /* append protocol name to list of names. */ if(!buffer_is_empty(protocol_names)) { - buffer_append_string(protocol_names, ", '"); + BUFFER_APPEND_STRING_CONST(protocol_names, ", '"); } else { - buffer_append_string(protocol_names, "'"); + BUFFER_APPEND_STRING_CONST(protocol_names, "'"); } buffer_append_string(protocol_names, BUF_STR(protocol->name)); - buffer_append_string(protocol_names, "'"); + BUFFER_APPEND_STRING_CONST(protocol_names, "'"); } proxy_protocol *proxy_get_protocol(buffer *name) { Index: src/connections.c =================================================================== --- src/connections.c (revisione 2201) +++ src/connections.c (copia locale) @@ -317,7 +317,7 @@ " <head>\n" " <title>"); buffer_append_long(b, con->http_status); - buffer_append_string(b, " - "); + BUFFER_APPEND_STRING_CONST(b, " - "); buffer_append_string(b, get_http_status_name(con->http_status)); buffer_append_string(b, @@ -326,7 +326,7 @@ " <body>\n" " <h1>"); buffer_append_long(b, con->http_status); - buffer_append_string(b, " - "); + BUFFER_APPEND_STRING_CONST(b, " - "); buffer_append_string(b, get_http_status_name(con->http_status)); buffer_append_string(b,"</h1>\n" Index: src/mod_staticfile.c =================================================================== --- src/mod_staticfile.c (revisione 2201) +++ src/mod_staticfile.c (copia locale) @@ -251,22 +251,22 @@ b = chunkqueue_get_append_buffer(con->send); - buffer_copy_string(b, "\r\n--"); + BUFFER_COPY_STRING_CONST(b, "\r\n--"); buffer_append_string(b, boundary); /* write Content-Range */ - buffer_append_string(b, "\r\nContent-Range: bytes "); + BUFFER_APPEND_STRING_CONST(b, "\r\nContent-Range: bytes "); buffer_append_off_t(b, r->start); - buffer_append_string(b, "-"); + BUFFER_APPEND_STRING_CONST(b, "-"); buffer_append_off_t(b, r->end); - buffer_append_string(b, "/"); + BUFFER_APPEND_STRING_CONST(b, "/"); buffer_append_off_t(b, sce->st.st_size); - buffer_append_string(b, "\r\nContent-Type: "); + BUFFER_APPEND_STRING_CONST(b, "\r\nContent-Type: "); buffer_append_string_buffer(b, content_type); /* write END-OF-HEADER */ - buffer_append_string(b, "\r\n\r\n"); + BUFFER_APPEND_STRING_CONST(b, "\r\n\r\n"); con->response.content_length += b->used - 1; con->send->bytes_in += b->used - 1; Index: src/network.c =================================================================== --- src/network.c (revisione 2201) +++ src/network.c (copia locale) @@ -623,7 +623,7 @@ b = buffer_init(); buffer_copy_string_buffer(b, srv->srvconf.bindhost); - buffer_append_string(b, ":"); + BUFFER_APPEND_STRING_CONST(b, ":"); buffer_append_long(b, srv->srvconf.port); if (0 != network_server_init(srv, b, srv->config_storage[0])) { Index: src/configfile.c =================================================================== --- src/configfile.c (revisione 2201) +++ src/configfile.c (copia locale) @@ -479,7 +479,7 @@ if (t->input[t->offset + 1] == '>') { t->offset += 2; - buffer_copy_string(token, "=>"); + BUFFER_COPY_STRING_CONST(token, "=>"); tid = TK_ARRAY_ASSIGN; } else { @@ -493,13 +493,13 @@ if (t->input[t->offset + 1] == '=') { t->offset += 2; - buffer_copy_string(token, "=="); + BUFFER_COPY_STRING_CONST(token, "=="); tid = TK_EQ; } else if (t->input[t->offset + 1] == '~') { t->offset += 2; - buffer_copy_string(token, "=~"); + BUFFER_COPY_STRING_CONST(token, "=~"); tid = TK_MATCH; } else { @@ -532,13 +532,13 @@ if (t->input[t->offset + 1] == '=') { t->offset += 2; - buffer_copy_string(token, "!="); + BUFFER_COPY_STRING_CONST(token, "!="); tid = TK_NE; } else if (t->input[t->offset + 1] == '~') { t->offset += 2; - buffer_copy_string(token, "!~"); + BUFFER_COPY_STRING_CONST(token, "!~"); tid = TK_NOMATCH; } else { @@ -593,7 +593,7 @@ } t->in_key = 1; tid = TK_EOL; - buffer_copy_string(token, "(EOL)"); + BUFFER_COPY_STRING_CONST(token, "(EOL)"); } else { config_skip_newline(t); t->line_pos = 1; @@ -604,7 +604,7 @@ if (t->in_brace > 0) { tid = TK_COMMA; - buffer_copy_string(token, "(COMMA)"); + BUFFER_COPY_STRING_CONST(token, "(COMMA)"); } t->offset++; @@ -613,7 +613,7 @@ case '"': /* search for the terminating " */ start = t->input + t->offset + 1; - buffer_copy_string(token, ""); + BUFFER_COPY_STRING_CONST(token, ""); for (i = 1; t->input[t->offset + i]; i++) { if (t->input[t->offset + i] == '\\' && @@ -659,7 +659,7 @@ tid = TK_LPARAN; - buffer_copy_string(token, "("); + BUFFER_COPY_STRING_CONST(token, "("); break; case ')': t->offset++; @@ -667,7 +667,7 @@ tid = TK_RPARAN; - buffer_copy_string(token, ")"); + BUFFER_COPY_STRING_CONST(token, ")"); break; case '$': t->offset++; @@ -676,19 +676,19 @@ t->in_cond = 1; t->in_key = 0; - buffer_copy_string(token, "$"); + BUFFER_COPY_STRING_CONST(token, "$"); break; case '+': if (t->input[t->offset + 1] == '=') { t->offset += 2; - buffer_copy_string(token, "+="); + BUFFER_COPY_STRING_CONST(token, "+="); tid = TK_APPEND; } else { t->offset++; tid = TK_PLUS; - buffer_copy_string(token, "+"); + BUFFER_COPY_STRING_CONST(token, "+"); } break; @@ -697,7 +697,7 @@ tid = TK_LCURLY; - buffer_copy_string(token, "{"); + BUFFER_COPY_STRING_CONST(token, "{"); break; @@ -706,7 +706,7 @@ tid = TK_RCURLY; - buffer_copy_string(token, "}"); + BUFFER_COPY_STRING_CONST(token, "}"); break; @@ -715,7 +715,7 @@ tid = TK_LBRACKET; - buffer_copy_string(token, "["); + BUFFER_COPY_STRING_CONST(token, "["); break; @@ -724,7 +724,7 @@ tid = TK_RBRACKET; - buffer_copy_string(token, "]"); + BUFFER_COPY_STRING_CONST(token, "]"); break; case '#': Index: src/mod_scgi.c =================================================================== --- src/mod_scgi.c (revisione 2201) +++ src/mod_scgi.c (copia locale) @@ -786,7 +786,7 @@ env.ptr[env.used] = NULL; b = buffer_init(); - buffer_copy_string(b, "exec "); + BUFFER_COPY_STRING_CONST(b, "exec "); buffer_append_string_buffer(b, host->bin_path); /* exec the cgi */ Index: src/mod_ssi_expr.c =================================================================== --- src/mod_ssi_expr.c (revisione 2201) +++ src/mod_ssi_expr.c (copia locale) @@ -60,7 +60,7 @@ t->offset++; t->line_pos++; - buffer_copy_string(token, "(=)"); + BUFFER_COPY_STRING_CONST(token, "(=)"); break; case '>': @@ -70,14 +70,14 @@ tid = TK_GE; - buffer_copy_string(token, "(>=)"); + BUFFER_COPY_STRING_CONST(token, "(>=)"); } else { t->offset += 1; t->line_pos += 1; tid = TK_GT; - buffer_copy_string(token, "(>)"); + BUFFER_COPY_STRING_CONST(token, "(>)"); } break; @@ -88,14 +88,14 @@ tid = TK_LE; - buffer_copy_string(token, "(<=)"); + BUFFER_COPY_STRING_CONST(token, "(<=)"); } else { t->offset += 1; t->line_pos += 1; tid = TK_LT; - buffer_copy_string(token, "(<)"); + BUFFER_COPY_STRING_CONST(token, "(<)"); } break; @@ -107,14 +107,14 @@ tid = TK_NE; - buffer_copy_string(token, "(!=)"); + BUFFER_COPY_STRING_CONST(token, "(!=)"); } else { t->offset += 1; t->line_pos += 1; tid = TK_NOT; - buffer_copy_string(token, "(!)"); + BUFFER_COPY_STRING_CONST(token, "(!)"); } break; @@ -125,7 +125,7 @@ tid = TK_AND; - buffer_copy_string(token, "(&&)"); + BUFFER_COPY_STRING_CONST(token, "(&&)"); } else { log_error_write(srv, __FILE__, __LINE__, "sds", "pos:", t->line_pos, @@ -141,7 +141,7 @@ tid = TK_OR; - buffer_copy_string(token, "(||)"); + BUFFER_COPY_STRING_CONST(token, "(||)"); } else { log_error_write(srv, __FILE__, __LINE__, "sds", "pos:", t->line_pos, @@ -184,7 +184,7 @@ tid = TK_LPARAN; - buffer_copy_string(token, "("); + BUFFER_COPY_STRING_CONST(token, "("); break; case ')': t->offset++; @@ -192,7 +192,7 @@ tid = TK_RPARAN; - buffer_copy_string(token, ")"); + BUFFER_COPY_STRING_CONST(token, ")"); break; case '$': if (t->input[t->offset + 1] == '{') { @@ -220,7 +220,7 @@ } else if (NULL != (ds = (data_string *)array_get_element(p->ssi_vars, CONST_BUF_LEN(token)))) { buffer_copy_string_buffer(token, ds->value); } else { - buffer_copy_string(token, ""); + BUFFER_COPY_STRING_CONST(token, ""); } t->offset += i; Index: src/mod_webdav.c =================================================================== --- src/mod_webdav.c (revisione 2201) +++ src/mod_webdav.c (copia locale) @@ -503,23 +503,23 @@ UNUSED(con); if (value) { - buffer_append_string(b,"<"); + BUFFER_APPEND_STRING_CONST(b,"<"); buffer_append_string(b, prop_name); - buffer_append_string(b, " xmlns=\""); + BUFFER_APPEND_STRING_CONST(b, " xmlns=\""); buffer_append_string(b, prop_ns); - buffer_append_string(b, "\">"); + BUFFER_APPEND_STRING_CONST(b, "\">"); buffer_append_string(b, value); - buffer_append_string(b,"</"); + BUFFER_APPEND_STRING_CONST(b,"</"); buffer_append_string(b, prop_name); - buffer_append_string(b, ">"); + BUFFER_APPEND_STRING_CONST(b, ">"); } else { - buffer_append_string(b,"<"); + BUFFER_APPEND_STRING_CONST(b,"<"); buffer_append_string(b, prop_name); - buffer_append_string(b, " xmlns=\""); + BUFFER_APPEND_STRING_CONST(b, " xmlns=\""); buffer_append_string(b, prop_ns); - buffer_append_string(b, "\"/>"); + BUFFER_APPEND_STRING_CONST(b, "\"/>"); } return 0; @@ -529,12 +529,12 @@ static int webdav_gen_response_status_tag(server *srv, connection *con, physical *dst, int status, buffer *b) { UNUSED(srv); - buffer_append_string(b,"<D:response xmlns:ns0=\"urn:uuid:c2f41010-65b3-11d1-a29f-00aa00c14882/\">\n"); + BUFFER_APPEND_STRING_CONST(b,"<D:response xmlns:ns0=\"urn:uuid:c2f41010-65b3-11d1-a29f-00aa00c14882/\">\n"); - buffer_append_string(b,"<D:href>\n"); + BUFFER_APPEND_STRING_CONST(b,"<D:href>\n"); buffer_append_string_buffer(b, dst->rel_path); - buffer_append_string(b,"</D:href>\n"); - buffer_append_string(b,"<D:status>\n"); + BUFFER_APPEND_STRING_CONST(b,"</D:href>\n"); + BUFFER_APPEND_STRING_CONST(b,"<D:status>\n"); if (con->request.http_version == HTTP_VERSION_1_1) { BUFFER_COPY_STRING_CONST(b, "HTTP/1.1 "); @@ -545,8 +545,8 @@ BUFFER_APPEND_STRING_CONST(b, " "); buffer_append_string(b, get_http_status_name(status)); - buffer_append_string(b,"</D:status>\n"); - buffer_append_string(b,"</D:response>\n"); + BUFFER_APPEND_STRING_CONST(b,"</D:status>\n"); + BUFFER_APPEND_STRING_CONST(b,"</D:response>\n"); return 0; } @@ -862,12 +862,12 @@ if (0 == strcmp(prop_name, "resourcetype")) { if (S_ISDIR(sce->st.st_mode)) { - buffer_append_string(b, "<D:resourcetype><D:collection/></D:resourcetype>"); + BUFFER_APPEND_STRING_CONST(b, "<D:resourcetype><D:collection/></D:resourcetype>"); found = 1; } } else if (0 == strcmp(prop_name, "getcontenttype")) { if (S_ISDIR(sce->st.st_mode)) { - buffer_append_string(b, "<D:getcontenttype>httpd/unix-directory</D:getcontenttype>"); + BUFFER_APPEND_STRING_CONST(b, "<D:getcontenttype>httpd/unix-directory</D:getcontenttype>"); found = 1; } else if(S_ISREG(sce->st.st_mode)) { for (k = 0; k < con->conf.mimetypes->used; k++) { @@ -876,9 +876,9 @@ if (ds->key->used == 0) continue; if (buffer_is_equal_right_len(dst->path, ds->key, ds->key->used - 1)) { - buffer_append_string(b,"<D:getcontenttype>"); + BUFFER_APPEND_STRING_CONST(b,"<D:getcontenttype>"); buffer_append_string_buffer(b, ds->value); - buffer_append_string(b, "</D:getcontenttype>"); + BUFFER_APPEND_STRING_CONST(b, "</D:getcontenttype>"); found = 1; break; @@ -886,26 +886,26 @@ } } } else if (0 == strcmp(prop_name, "creationdate")) { - buffer_append_string(b, "<D:creationdate ns0:dt=\"dateTime.tz\">"); + BUFFER_APPEND_STRING_CONST(b, "<D:creationdate ns0:dt=\"dateTime.tz\">"); strftime(ctime_buf, sizeof(ctime_buf), "%Y-%m-%dT%H:%M:%SZ", gmtime(&(sce->st.st_ctime))); buffer_append_string(b, ctime_buf); - buffer_append_string(b, "</D:creationdate>"); + BUFFER_APPEND_STRING_CONST(b, "</D:creationdate>"); found = 1; } else if (0 == strcmp(prop_name, "getlastmodified")) { - buffer_append_string(b,"<D:getlastmodified ns0:dt=\"dateTime.rfc1123\">"); + BUFFER_APPEND_STRING_CONST(b,"<D:getlastmodified ns0:dt=\"dateTime.rfc1123\">"); strftime(mtime_buf, sizeof(mtime_buf), "%a, %d %b %Y %H:%M:%S GMT", gmtime(&(sce->st.st_mtime))); buffer_append_string(b, mtime_buf); - buffer_append_string(b, "</D:getlastmodified>"); + BUFFER_APPEND_STRING_CONST(b, "</D:getlastmodified>"); found = 1; } else if (0 == strcmp(prop_name, "getcontentlength")) { - buffer_append_string(b,"<D:getcontentlength>"); + BUFFER_APPEND_STRING_CONST(b,"<D:getcontentlength>"); buffer_append_off_t(b, sce->st.st_size); - buffer_append_string(b, "</D:getcontentlength>"); + BUFFER_APPEND_STRING_CONST(b, "</D:getcontentlength>"); found = 1; } else if (0 == strcmp(prop_name, "getcontentlanguage")) { - buffer_append_string(b,"<D:getcontentlanguage>"); - buffer_append_string(b, "en"); - buffer_append_string(b, "</D:getcontentlanguage>"); + BUFFER_APPEND_STRING_CONST(b,"<D:getcontentlanguage>"); + BUFFER_APPEND_STRING_CONST(b, "en"); + BUFFER_APPEND_STRING_CONST(b, "</D:getcontentlanguage>"); found = 1; } } @@ -1124,44 +1124,44 @@ b = chunkqueue_get_append_buffer(con->send); - buffer_copy_string(b, "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"); + BUFFER_COPY_STRING_CONST(b, "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"); - buffer_append_string(b,"<D:prop xmlns:D=\"DAV:\" xmlns:ns0=\"urn:uuid:c2f41010-65b3-11d1-a29f-00aa00c14882/\">\n"); - buffer_append_string(b,"<D:lockdiscovery>\n"); - buffer_append_string(b,"<D:activelock>\n"); + BUFFER_APPEND_STRING_CONST(b,"<D:prop xmlns:D=\"DAV:\" xmlns:ns0=\"urn:uuid:c2f41010-65b3-11d1-a29f-00aa00c14882/\">\n"); + BUFFER_APPEND_STRING_CONST(b,"<D:lockdiscovery>\n"); + BUFFER_APPEND_STRING_CONST(b,"<D:activelock>\n"); - buffer_append_string(b,"<D:lockscope>"); - buffer_append_string(b,"<D:"); + BUFFER_APPEND_STRING_CONST(b,"<D:lockscope>"); + BUFFER_APPEND_STRING_CONST(b,"<D:"); buffer_append_string(b, lockscope); - buffer_append_string(b, "/>"); - buffer_append_string(b,"</D:lockscope>\n"); + BUFFER_APPEND_STRING_CONST(b, "/>"); + BUFFER_APPEND_STRING_CONST(b,"</D:lockscope>\n"); - buffer_append_string(b,"<D:locktype>"); - buffer_append_string(b,"<D:"); + BUFFER_APPEND_STRING_CONST(b,"<D:locktype>"); + BUFFER_APPEND_STRING_CONST(b,"<D:"); buffer_append_string(b, locktype); - buffer_append_string(b, "/>"); - buffer_append_string(b,"</D:locktype>\n"); + BUFFER_APPEND_STRING_CONST(b, "/>"); + BUFFER_APPEND_STRING_CONST(b,"</D:locktype>\n"); - buffer_append_string(b,"<D:depth>"); + BUFFER_APPEND_STRING_CONST(b,"<D:depth>"); buffer_append_string(b, depth == 0 ? "0" : "infinity"); - buffer_append_string(b,"</D:depth>\n"); + BUFFER_APPEND_STRING_CONST(b,"</D:depth>\n"); - buffer_append_string(b,"<D:timeout>"); - buffer_append_string(b, "Second-600"); - buffer_append_string(b,"</D:timeout>\n"); + BUFFER_APPEND_STRING_CONST(b,"<D:timeout>"); + BUFFER_APPEND_STRING_CONST(b, "Second-600"); + BUFFER_APPEND_STRING_CONST(b,"</D:timeout>\n"); - buffer_append_string(b,"<D:owner>"); - buffer_append_string(b,"</D:owner>\n"); + BUFFER_APPEND_STRING_CONST(b,"<D:owner>"); + BUFFER_APPEND_STRING_CONST(b,"</D:owner>\n"); - buffer_append_string(b,"<D:locktoken>"); - buffer_append_string(b, "<D:href>"); + BUFFER_APPEND_STRING_CONST(b,"<D:locktoken>"); + BUFFER_APPEND_STRING_CONST(b, "<D:href>"); buffer_append_string_buffer(b, locktoken); - buffer_append_string(b, "</D:href>"); - buffer_append_string(b,"</D:locktoken>\n"); + BUFFER_APPEND_STRING_CONST(b, "</D:href>"); + BUFFER_APPEND_STRING_CONST(b,"</D:locktoken>\n"); - buffer_append_string(b,"</D:activelock>\n"); - buffer_append_string(b,"</D:lockdiscovery>\n"); - buffer_append_string(b,"</D:prop>\n"); + BUFFER_APPEND_STRING_CONST(b,"</D:activelock>\n"); + BUFFER_APPEND_STRING_CONST(b,"</D:lockdiscovery>\n"); + BUFFER_APPEND_STRING_CONST(b,"</D:prop>\n"); return 0; } @@ -1385,9 +1385,9 @@ b = chunkqueue_get_append_buffer(con->send); - buffer_copy_string(b, "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"); + BUFFER_COPY_STRING_CONST(b, "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"); - buffer_append_string(b,"<D:multistatus xmlns:D=\"DAV:\" xmlns:ns0=\"urn:uuid:c2f41010-65b3-11d1-a29f-00aa00c14882/\">\n"); + BUFFER_APPEND_STRING_CONST(b,"<D:multistatus xmlns:D=\"DAV:\" xmlns:ns0=\"urn:uuid:c2f41010-65b3-11d1-a29f-00aa00c14882/\">\n"); /* allprop */ @@ -1399,40 +1399,40 @@ /* Depth: 0 */ webdav_get_props(srv, con, p, &(con->physical), req_props, prop_200, prop_404); - buffer_append_string(b,"<D:response>\n"); - buffer_append_string(b,"<D:href>"); + BUFFER_APPEND_STRING_CONST(b,"<D:response>\n"); + BUFFER_APPEND_STRING_CONST(b,"<D:href>"); buffer_append_string_buffer(b, con->uri.scheme); - buffer_append_string(b,"://"); + BUFFER_APPEND_STRING_CONST(b,"://"); buffer_append_string_buffer(b, con->uri.authority); buffer_append_string_encoded(b, CONST_BUF_LEN(con->uri.path), ENCODING_REL_URI); - buffer_append_string(b,"</D:href>\n"); + BUFFER_APPEND_STRING_CONST(b,"</D:href>\n"); if (!buffer_is_empty(prop_200)) { - buffer_append_string(b,"<D:propstat>\n"); - buffer_append_string(b,"<D:prop>\n"); + BUFFER_APPEND_STRING_CONST(b,"<D:propstat>\n"); + BUFFER_APPEND_STRING_CONST(b,"<D:prop>\n"); buffer_append_string_buffer(b, prop_200); - buffer_append_string(b,"</D:prop>\n"); + BUFFER_APPEND_STRING_CONST(b,"</D:prop>\n"); - buffer_append_string(b,"<D:status>HTTP/1.1 200 OK</D:status>\n"); + BUFFER_APPEND_STRING_CONST(b,"<D:status>HTTP/1.1 200 OK</D:status>\n"); - buffer_append_string(b,"</D:propstat>\n"); + BUFFER_APPEND_STRING_CONST(b,"</D:propstat>\n"); } if (!buffer_is_empty(prop_404)) { - buffer_append_string(b,"<D:propstat>\n"); - buffer_append_string(b,"<D:prop>\n"); + BUFFER_APPEND_STRING_CONST(b,"<D:propstat>\n"); + BUFFER_APPEND_STRING_CONST(b,"<D:prop>\n"); buffer_append_string_buffer(b, prop_404); - buffer_append_string(b,"</D:prop>\n"); + BUFFER_APPEND_STRING_CONST(b,"</D:prop>\n"); - buffer_append_string(b,"<D:status>HTTP/1.1 404 Not Found</D:status>\n"); + BUFFER_APPEND_STRING_CONST(b,"<D:status>HTTP/1.1 404 Not Found</D:status>\n"); - buffer_append_string(b,"</D:propstat>\n"); + BUFFER_APPEND_STRING_CONST(b,"</D:propstat>\n"); } - buffer_append_string(b,"</D:response>\n"); + BUFFER_APPEND_STRING_CONST(b,"</D:response>\n"); break; case 1: @@ -1468,40 +1468,40 @@ webdav_get_props(srv, con, p, &d, req_props, prop_200, prop_404); - buffer_append_string(b,"<D:response>\n"); - buffer_append_string(b,"<D:href>"); + BUFFER_APPEND_STRING_CONST(b,"<D:response>\n"); + BUFFER_APPEND_STRING_CONST(b,"<D:href>"); buffer_append_string_buffer(b, con->uri.scheme); - buffer_append_string(b,"://"); + BUFFER_APPEND_STRING_CONST(b,"://"); buffer_append_string_buffer(b, con->uri.authority); buffer_append_string_encoded(b, CONST_BUF_LEN(d.rel_path), ENCODING_REL_URI); - buffer_append_string(b,"</D:href>\n"); + BUFFER_APPEND_STRING_CONST(b,"</D:href>\n"); if (!buffer_is_empty(prop_200)) { - buffer_append_string(b,"<D:propstat>\n"); - buffer_append_string(b,"<D:prop>\n"); + BUFFER_APPEND_STRING_CONST(b,"<D:propstat>\n"); + BUFFER_APPEND_STRING_CONST(b,"<D:prop>\n"); buffer_append_string_buffer(b, prop_200); - buffer_append_string(b,"</D:prop>\n"); + BUFFER_APPEND_STRING_CONST(b,"</D:prop>\n"); - buffer_append_string(b,"<D:status>HTTP/1.1 200 OK</D:status>\n"); + BUFFER_APPEND_STRING_CONST(b,"<D:status>HTTP/1.1 200 OK</D:status>\n"); - buffer_append_string(b,"</D:propstat>\n"); + BUFFER_APPEND_STRING_CONST(b,"</D:propstat>\n"); } if (!buffer_is_empty(prop_404)) { - buffer_append_string(b,"<D:propstat>\n"); - buffer_append_string(b,"<D:prop>\n"); + BUFFER_APPEND_STRING_CONST(b,"<D:propstat>\n"); + BUFFER_APPEND_STRING_CONST(b,"<D:prop>\n"); buffer_append_string_buffer(b, prop_404); - buffer_append_string(b,"</D:prop>\n"); + BUFFER_APPEND_STRING_CONST(b,"</D:prop>\n"); - buffer_append_string(b,"<D:status>HTTP/1.1 404 Not Found</D:status>\n"); + BUFFER_APPEND_STRING_CONST(b,"<D:status>HTTP/1.1 404 Not Found</D:status>\n"); - buffer_append_string(b,"</D:propstat>\n"); + BUFFER_APPEND_STRING_CONST(b,"</D:propstat>\n"); } - buffer_append_string(b,"</D:response>\n"); + BUFFER_APPEND_STRING_CONST(b,"</D:response>\n"); } closedir(dir); buffer_free(d.path); @@ -1524,7 +1524,7 @@ buffer_free(prop_200); buffer_free(prop_404); - buffer_append_string(b,"</D:multistatus>\n"); + BUFFER_APPEND_STRING_CONST(b,"</D:multistatus>\n"); if (con->conf.log_request_handling) { TRACE("sending XML: %s", @@ -1604,13 +1604,13 @@ b = chunkqueue_get_append_buffer(con->send); - buffer_copy_string(b, "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"); + BUFFER_COPY_STRING_CONST(b, "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"); - buffer_append_string(b,"<D:multistatus xmlns:D=\"DAV:\">\n"); + BUFFER_APPEND_STRING_CONST(b,"<D:multistatus xmlns:D=\"DAV:\">\n"); buffer_append_string_buffer(b, multi_status_resp); - buffer_append_string(b,"</D:multistatus>\n"); + BUFFER_APPEND_STRING_CONST(b,"</D:multistatus>\n"); if (p->conf.log_xml) { log_error_write(srv, __FILE__, __LINE__, "sb", "XML-response-body:", b); Index: src/mod_status.c =================================================================== --- src/mod_status.c (revisione 2201) +++ src/mod_status.c (copia locale) @@ -657,9 +657,9 @@ size_t ndx = st->sorted[i]; buffer_append_string_buffer(b, st->data[ndx]->key); - buffer_append_string(b, ": "); + BUFFER_APPEND_STRING_CONST(b, ": "); buffer_append_long(b, ((data_integer *)(st->data[ndx]))->value); - buffer_append_string(b, "\n"); + BUFFER_APPEND_STRING_CONST(b, "\n"); } response_header_overwrite(srv, con, CONST_STR_LEN("Content-Type"), CONST_STR_LEN("text/plain")); Index: src/http_req_test.c =================================================================== --- src/http_req_test.c (revisione 2201) +++ src/http_req_test.c (copia locale) @@ -111,11 +111,11 @@ "GE"); b = chunkqueue_get_append_buffer(cq); - buffer_copy_string(b, "T "); + BUFFER_COPY_STRING_CONST(b, "T "); b = chunkqueue_get_append_buffer(cq); - buffer_copy_string(b, "/foo"); + BUFFER_COPY_STRING_CONST(b, "/foo"); b = chunkqueue_get_append_buffer(cq); - buffer_copy_string(b, "bar HTTP/1.0\r"); + BUFFER_COPY_STRING_CONST(b, "bar HTTP/1.0\r"); b = chunkqueue_get_append_buffer(cq); buffer_copy_string(b, "\n" Index: src/mod_ssi.c =================================================================== --- src/mod_ssi.c (revisione 2201) +++ src/mod_ssi.c (copia locale) @@ -417,7 +417,7 @@ b = chunkqueue_get_append_buffer(con->send); if (0 == strftime(buf, sizeof(buf), p->timefmt->ptr, localtime(&t))) { - buffer_copy_string(b, "(none)"); + BUFFER_COPY_STRING_CONST(b, "(none)"); } else { buffer_copy_string(b, buf); } @@ -428,7 +428,7 @@ b = chunkqueue_get_append_buffer(con->send); if (0 == strftime(buf, sizeof(buf), p->timefmt->ptr, localtime(&t))) { - buffer_copy_string(b, "(none)"); + BUFFER_COPY_STRING_CONST(b, "(none)"); } else { buffer_copy_string(b, buf); } @@ -439,7 +439,7 @@ b = chunkqueue_get_append_buffer(con->send); if (0 == strftime(buf, sizeof(buf), p->timefmt->ptr, gmtime(&t))) { - buffer_copy_string(b, "(none)"); + BUFFER_COPY_STRING_CONST(b, "(none)"); } else { buffer_copy_string(b, buf); } @@ -470,7 +470,7 @@ if (NULL != (ds = (data_string *)array_get_element(p->ssi_cgi_env, var_val, strlen(var_val)))) { buffer_copy_string_buffer(b, ds->value); } else { - buffer_copy_string(b, "(none)"); + BUFFER_COPY_STRING_CONST(b, "(none)"); } break; @@ -571,7 +571,7 @@ case SSI_FLASTMOD: b = chunkqueue_get_append_buffer(con->send); if (0 == strftime(buf, sizeof(buf), p->timefmt->ptr, localtime(&t))) { - buffer_copy_string(b, "(none)"); + BUFFER_COPY_STRING_CONST(b, "(none)"); } else { buffer_copy_string(b, buf); } @@ -649,17 +649,17 @@ if (p->if_is_false) break; b = chunkqueue_get_append_buffer(con->send); - buffer_copy_string(b, "<pre>"); + BUFFER_COPY_STRING_CONST(b, "<pre>"); for (i = 0; i < p->ssi_vars->used; i++) { data_string *ds = (data_string *)p->ssi_vars->data[p->ssi_vars->sorted[i]]; buffer_append_string_buffer(b, ds->key); - buffer_append_string(b, ": "); + BUFFER_APPEND_STRING_CONST(b, ": "); buffer_append_string_buffer(b, ds->value); - buffer_append_string(b, "<br />"); + BUFFER_APPEND_STRING_CONST(b, "<br />"); } - buffer_append_string(b, "</pre>"); + BUFFER_APPEND_STRING_CONST(b, "</pre>"); break; case SSI_EXEC: { Index: src/mod_chunked.c =================================================================== --- src/mod_chunked.c (revisione 2201) +++ src/mod_chunked.c (copia locale) @@ -249,7 +249,7 @@ b = buffer_init(); if (len == 0) { - buffer_copy_string(b, "0"); + BUFFER_COPY_STRING_CONST(b, "0"); } else { for (i = 0; i < 8 && len; i++) { len >>= 4; @@ -266,7 +266,7 @@ b->ptr[b->used++] = '\0'; } - buffer_append_string(b, "\r\n"); + BUFFER_APPEND_STRING_CONST(b, "\r\n"); chunkqueue_append_buffer(cq, b); len = b->used - 1; Index: src/http-header-glue.c =================================================================== --- src/http-header-glue.c (revisione 2201) +++ src/http-header-glue.c (copia locale) @@ -115,9 +115,9 @@ o = buffer_init(); if (con->conf.is_ssl) { - buffer_copy_string(o, "https://"); + BUFFER_COPY_STRING_CONST(o, "https://"); } else { - buffer_copy_string(o, "http://"); + BUFFER_COPY_STRING_CONST(o, "http://"); } if (con->uri.authority->used) { buffer_append_string_buffer(o, con->uri.authority); @@ -183,14 +183,14 @@ if (!((con->conf.is_ssl == 0 && srv->srvconf.port == 80) || (con->conf.is_ssl == 1 && srv->srvconf.port == 443))) { - buffer_append_string(o, ":"); + BUFFER_APPEND_STRING_CONST(o, ":"); buffer_append_long(o, srv->srvconf.port); } } buffer_append_string_buffer(o, con->uri.path); - buffer_append_string(o, "/"); + BUFFER_APPEND_STRING_CONST(o, "/"); if (!buffer_is_empty(con->uri.query)) { - buffer_append_string(o, "?"); + BUFFER_APPEND_STRING_CONST(o, "?"); buffer_append_string_buffer(o, con->uri.query); } Index: src/mod_uploadprogress.c =================================================================== --- src/mod_uploadprogress.c (revisione 2201) +++ src/mod_uploadprogress.c (copia locale) @@ -494,7 +494,7 @@ BUFFER_APPEND_STRING_CONST(b, "'error', 'status' : 413"); } else if (post_con_entry->con == NULL) { /* the connection is already gone */ - buffer_append_string(b, "'done'"); + BUFFER_APPEND_STRING_CONST(b, "'done'"); } else { /* the upload is already done, but the connection might be still open */ buffer_append_string(b, post_con_entry->con->recv->is_closed ? "'done'" : "'uploading'"); Index: src/http_req_range_test.c =================================================================== --- src/http_req_range_test.c (revisione 2201) +++ src/http_req_range_test.c (copia locale) @@ -15,49 +15,49 @@ log_init(); plan_tests(7); - buffer_copy_string(b, "bytes=0-0"); + BUFFER_COPY_STRING_CONST(b, "bytes=0-0"); ok(PARSE_SUCCESS == http_request_range_parse(b, ranges), "0-0"); for (r = ranges; r; r = r->next) { diag(".. %jd - %jd", (intmax_t) r->start, (intmax_t) r->end); } http_request_range_reset(ranges); - buffer_copy_string(b, "bytes=1-2,3-4"); + BUFFER_COPY_STRING_CONST(b, "bytes=1-2,3-4"); ok(PARSE_SUCCESS == http_request_range_parse(b, ranges), "1-2,3-4"); for (r = ranges; r; r = r->next) { diag(".. %jd - %jd", (intmax_t) r->start, (intmax_t) r->end); } http_request_range_reset(ranges); - buffer_copy_string(b, "bytes=-0"); + BUFFER_COPY_STRING_CONST(b, "bytes=-0"); ok(PARSE_SUCCESS == http_request_range_parse(b, ranges), "-0"); for (r = ranges; r; r = r->next) { diag(".. %jd - %jd", (intmax_t) r->start, (intmax_t) r->end); } http_request_range_reset(ranges); - buffer_copy_string(b, "bytes=0-"); + BUFFER_COPY_STRING_CONST(b, "bytes=0-"); ok(PARSE_SUCCESS == http_request_range_parse(b, ranges), "0-"); for (r = ranges; r; r = r->next) { diag(".. %jd - %jd", (intmax_t) r->start, (intmax_t) r->end); } http_request_range_reset(ranges); - buffer_copy_string(b, "bytes=0-0,0-"); + BUFFER_COPY_STRING_CONST(b, "bytes=0-0,0-"); ok(PARSE_SUCCESS == http_request_range_parse(b, ranges), "0-0,0-"); for (r = ranges; r; r = r->next) { diag(".. %jd - %jd", (intmax_t) r->start, (intmax_t) r->end); } http_request_range_reset(ranges); - buffer_copy_string(b, "bytes=0-0,-0"); + BUFFER_COPY_STRING_CONST(b, "bytes=0-0,-0"); ok(PARSE_SUCCESS == http_request_range_parse(b, ranges), "0-0,-0"); for (r = ranges; r; r = r->next) { diag(".. %jd - %jd", (intmax_t) r->start, (intmax_t) r->end); } http_request_range_reset(ranges); - buffer_copy_string(b, "bytes=1-2,3-4,5-"); + BUFFER_COPY_STRING_CONST(b, "bytes=1-2,3-4,5-"); ok(PARSE_SUCCESS == http_request_range_parse(b, ranges), "1-2,3-4,5-"); for (r = ranges; r; r = r->next) { diag(".. %jd - %jd", (intmax_t) r->start, (intmax_t) r->end); Index: src/mod_accesslog.c =================================================================== --- src/mod_accesslog.c (revisione 2201) +++ src/mod_accesslog.c (copia locale) @@ -630,7 +630,7 @@ b = p->conf.access_logbuffer; if (b->used == 0) { - buffer_copy_string(b, ""); + BUFFER_COPY_STRING_CONST(b, ""); } for (j = 0; j < p->conf.parsed_format->used; j++) { @@ -709,9 +709,9 @@ break; case FORMAT_REQUEST_LINE: buffer_append_string(b, get_http_method_name(con->request.http_method)); - buffer_append_string(b, " "); + BUFFER_APPEND_STRING_CONST(b, " "); buffer_append_string_buffer(b, con->request.orig_uri); - buffer_append_string(b, " "); + BUFFER_APPEND_STRING_CONST(b, " "); buffer_append_string(b, get_http_version_name(con->request.http_version)); break; @@ -797,8 +797,8 @@ break; case FORMAT_CONNECTION_STATUS: switch(con->keep_alive) { - case 0: buffer_append_string(b, "-"); break; - default: buffer_append_string(b, "+"); break; + case 0: BUFFER_APPEND_STRING_CONST(b, "-"); break; + default: BUFFER_APPEND_STRING_CONST(b, "+"); break; } break; default: Index: src/http_resp_test.c =================================================================== --- src/http_resp_test.c (revisione 2201) +++ src/http_resp_test.c (copia locale) @@ -111,11 +111,11 @@ "HTTP"); b = chunkqueue_get_append_buffer(cq); - buffer_copy_string(b, "/1.0 "); + BUFFER_COPY_STRING_CONST(b, "/1.0 "); b = chunkqueue_get_append_buffer(cq); - buffer_copy_string(b, "30"); + BUFFER_COPY_STRING_CONST(b, "30"); b = chunkqueue_get_append_buffer(cq); - buffer_copy_string(b, "4 Not Modified\r"); + BUFFER_COPY_STRING_CONST(b, "4 Not Modified\r"); b = chunkqueue_get_append_buffer(cq); buffer_copy_string(b, "\n" Index: src/log.c =================================================================== --- src/log.c (revisione 2201) +++ src/log.c (copia locale) @@ -358,11 +358,11 @@ /* write b */ switch(err->mode) { case ERRORLOG_FILE: - buffer_append_string(b, "\r\n"); + BUFFER_APPEND_STRING_CONST(b, "\r\n"); write(err->fd, b->ptr, b->used - 1); break; case ERRORLOG_STDERR: - buffer_append_string(b, "\r\n"); + BUFFER_APPEND_STRING_CONST(b, "\r\n"); write(STDERR_FILENO, b->ptr, b->used - 1); break; #ifdef HAVE_SYSLOG_H Index: src/proc_open.c =================================================================== --- src/proc_open.c (revisione 2201) +++ src/proc_open.c (copia locale) @@ -184,7 +184,7 @@ buffer_append_string(cmdline, shell); } else { buffer_append_string(cmdline, windir); - buffer_append_string(cmdline, "\\system32\\cmd.exe"); + BUFFER_APPEND_STRING_CONST(cmdline, "\\system32\\cmd.exe"); } buffer_append_string_len(cmdline, CONST_STR_LEN(" /c ")); buffer_append_string(cmdline, command);
-- dierbro
Updated by stbuehler over 16 years ago
A good idea!
I didn't use the _CONST macros, i used _len(b, CONST_STR_LEN(str)) instead.
#!ShellExample $ find . -name "*.c" -exec sed -ie 's/\(buffer_append_string\|buffer_copy_string\)(\([a-zA-Z0-9_.>-]\+\),\([[:space:]]*\)\(".*"\))/\1_len(\2,\3CONST_STR_LEN(\4))/g' {} \; $ find . -name "*.c" -exec sed -ie 's/\(BUFFER_COPY_STRING_CONST\)(\([a-zA-Z0-9_.>-]\+\),\([[:space:]]*\)\(".*"\))/buffer_copy_string_len(\2,\3CONST_STR_LEN(\4))/g' {} \; $ find . -name "*.c" -exec sed -ie 's/\(BUFFER_APPEND_STRING_CONST\)(\([a-zA-Z0-9_.>-]\+\),\([[:space:]]*\)\(".*"\))/buffer_append_string_len(\2,\3CONST_STR_LEN(\4))/g' {} \;
Fixed in r2250 for 1.4, move ticket to 1.5.x
Updated by stbuehler over 16 years ago
- Status changed from New to Fixed
- Resolution set to fixed
Fixed in r2263 for 1.5
Actions
Also available in: Atom