From: Holger Schemel Date: Fri, 24 Sep 2021 14:08:47 +0000 (+0200) Subject: added function to create HTTP response object from buffer X-Git-Tag: 4.3.0.0~42 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=65443b1c5b18c744d5d825759307ffee0f462b1b;p=rocksndiamonds.git added function to create HTTP response object from buffer --- diff --git a/src/libgame/http.c b/src/libgame/http.c index b494ac42..a179620e 100644 --- a/src/libgame/http.c +++ b/src/libgame/http.c @@ -65,6 +65,22 @@ static void SetHttpResponseToDefaults(struct HttpResponse *response) response->status_text[0] = '\0'; } +struct HttpResponse *GetHttpResponseFromBuffer(void *buffer, int size) +{ + if (size > MAX_HTTP_BODY_SIZE) + return NULL; + + struct HttpResponse *response = checked_calloc(sizeof(struct HttpResponse)); + + SetHttpResponseToDefaults(response); + + strncpy(response->body, buffer, MAX_HTTP_BODY_SIZE); + response->body[MAX_HTTP_BODY_SIZE] = '\0'; + response->body_size = MIN(size, MAX_HTTP_BODY_SIZE); + + return response; +} + static boolean SetHTTPResponseCode(struct HttpResponse *response, char *buffer) { char *prefix = "HTTP/1.1 "; diff --git a/src/libgame/http.h b/src/libgame/http.h index 3a1dc3e3..2523bc72 100644 --- a/src/libgame/http.h +++ b/src/libgame/http.h @@ -46,6 +46,7 @@ struct HttpResponse char *GetHttpError(void); void ConvertHttpRequestBodyToServerEncoding(struct HttpRequest *); void ConvertHttpResponseBodyToClientEncoding(struct HttpResponse *); +struct HttpResponse *GetHttpResponseFromBuffer(void *, int); boolean DoHttpRequest(struct HttpRequest *, struct HttpResponse *); #endif