From: Holger Schemel Date: Sat, 24 Apr 2021 22:08:21 +0000 (+0200) Subject: added functions to convert between HTTP client and server encoding X-Git-Tag: 4.3.0.0~188 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=db269a1ab34d16c03e8087eaf786e7b3c9a135e4;p=rocksndiamonds.git added functions to convert between HTTP client and server encoding --- diff --git a/src/libgame/http.c b/src/libgame/http.c index 2a41b5bb..74fafb37 100644 --- a/src/libgame/http.c +++ b/src/libgame/http.c @@ -33,6 +33,24 @@ char *GetHttpError(void) return http_error; } +void ConvertHttpRequestBodyToServerEncoding(struct HttpRequest *request) +{ + char *body_utf8 = getUTF8FromLatin1(request->body); + + strcpy(request->body, body_utf8); + checked_free(body_utf8); +} + +void ConvertHttpResponseBodyToClientEncoding(struct HttpResponse *response) +{ + char *body_latin1 = getLatin1FromUTF8(response->body); + + strcpy(response->body, body_latin1); + checked_free(body_latin1); + + response->body_size = strlen(response->body); +} + static void SetHttpResponseToDefaults(struct HttpResponse *response) { response->head[0] = '\0'; diff --git a/src/libgame/http.h b/src/libgame/http.h index b002ec65..3a1dc3e3 100644 --- a/src/libgame/http.h +++ b/src/libgame/http.h @@ -44,6 +44,8 @@ struct HttpResponse char *GetHttpError(void); +void ConvertHttpRequestBodyToServerEncoding(struct HttpRequest *); +void ConvertHttpResponseBodyToClientEncoding(struct HttpResponse *); boolean DoHttpRequest(struct HttpRequest *, struct HttpResponse *); #endif