summaryrefslogtreecommitdiff
path: root/accel-pppd
diff options
context:
space:
mode:
authorVladislav Grishenko <themiron@mail.ru>2017-12-01 22:13:45 +0500
committerVladislav Grishenko <themiron@mail.ru>2017-12-30 22:49:09 +0500
commitc6ec453152b28ca78031145b96a21669908085d1 (patch)
tree47cbd5906877d11e996739bacea6db94a32cbfed /accel-pppd
parentae45db860e6fe628c8e2fa107ee6b7dacd3aacbe (diff)
downloadaccel-ppp-xebd-c6ec453152b28ca78031145b96a21669908085d1.tar.gz
accel-ppp-xebd-c6ec453152b28ca78031145b96a21669908085d1.zip
sstp: http: get rid of static reply buffer
Diffstat (limited to 'accel-pppd')
-rw-r--r--accel-pppd/ctrl/sstp/sstp.c34
1 files changed, 25 insertions, 9 deletions
diff --git a/accel-pppd/ctrl/sstp/sstp.c b/accel-pppd/ctrl/sstp/sstp.c
index 5953a1c..cb1cdfe 100644
--- a/accel-pppd/ctrl/sstp/sstp.c
+++ b/accel-pppd/ctrl/sstp/sstp.c
@@ -306,6 +306,26 @@ static struct buffer_t *alloc_buf(size_t size)
return buf;
}
+static struct buffer_t *alloc_buf_printf(const char* format, ...)
+{
+ struct buffer_t *buf = NULL;
+ va_list ap;
+ int len;
+
+ va_start(ap, format);
+ len = vsnprintf(NULL, 0, format, ap);
+ if (len < 0) {
+ va_end(ap);
+ return NULL;
+ }
+
+ buf = alloc_buf(len + 1);
+ if (buf)
+ vsnprintf(buf_put(buf, len), len + 1, format, ap);
+ va_end(ap);
+ return buf;
+}
+
static void free_buf(struct buffer_t *buf)
{
_free(buf);
@@ -522,28 +542,24 @@ static char *http_getline(struct sstp_conn_t *conn, int *pos, char *buf, int siz
static int http_send_response(struct sstp_conn_t *conn, char *proto, char *status, char *headers)
{
- char datetime[sizeof("aaa, dd bbb yyyy HH:MM:SS GMT")], msg[1024];
+ char datetime[sizeof("aaa, dd bbb yyyy HH:MM:SS GMT")];
struct buffer_t *buf;
time_t now = time(NULL);
- int n;
+
+ if (conf_verbose)
+ log_sstp_info2(conn, "send [HTTP <%s %s>]\n", proto, status);
strftime(datetime, sizeof(datetime), "%a, %d %b %Y %H:%M:%S GMT", gmtime(&now));
- n = snprintf(msg, sizeof(msg),
+ buf = alloc_buf_printf(
"%s %s\r\n"
/* "Server: %s\r\n" */
"Date: %s\r\n"
"%s"
"\r\n", proto, status, /* "accel-ppp",*/ datetime, headers ? : "");
-
- if (conf_verbose)
- log_sstp_info2(conn, "send [HTTP <%s %s>]\n", proto, status);
-
- buf = alloc_buf(n);
if (!buf) {
log_sstp_error(conn, "no memory\n");
return -1;
}
- buf_put_data(buf, msg, n);
return sstp_send(conn, buf);
}