wb->contenttype = CT_TEXT_PLAIN;
wb->options = 0;
wb->date = 0;
+ wb->expires = 0;
buffer_overflow_check(wb);
}
void buffer_strcat(BUFFER *wb, const char *txt)
{
+ // buffer_sprintf(wb, "%s", txt);
+
if(unlikely(!txt || !*txt)) return;
buffer_need_bytes(wb, 1);
}
}
+void buffer_strcat_htmlescape(BUFFER *wb, const char *txt)
+{
+ char b[2] = { [0] = '\0', [1] = '\0' };
+
+ while(*txt) {
+ switch(*txt) {
+ case '&': buffer_strcat(wb, "&"); break;
+ case '<': buffer_strcat(wb, "<"); break;
+ case '>': buffer_strcat(wb, ">"); break;
+ case '"': buffer_strcat(wb, """); break;
+ case '/': buffer_strcat(wb, "/"); break;
+ case '\'': buffer_strcat(wb, "'"); break;
+ default: {
+ b[0] = *txt;
+ buffer_strcat(wb, b);
+ }
+ }
+ txt++;
+ }
+}
void buffer_snprintf(BUFFER *wb, size_t len, const char *fmt, ...)
{
va_end(args);
if(unlikely(wrote >= len)) {
- // there is bug in vsnprintf() and it returns
- // a number higher to len, but it does not
- // overflow the buffer.
- // our buffer overflow detector will log it
- // if it does.
+ // truncated
buffer_overflow_check(wb);
debug(D_WEB_BUFFER, "web_buffer_sprintf(): increasing web_buffer at position %zu, size = %zu\n", wb->len, wb->size);