added functions to convert between HTTP client and server encoding
authorHolger Schemel <info@artsoft.org>
Sat, 24 Apr 2021 22:08:21 +0000 (00:08 +0200)
committerHolger Schemel <info@artsoft.org>
Sat, 1 May 2021 13:38:30 +0000 (15:38 +0200)
src/libgame/http.c
src/libgame/http.h

index 2a41b5bb612fc5eaf0f25eebdcd4cd18ceaa6aec..74fafb379713e61b5d4d7a9edf768da73090a896 100644 (file)
@@ -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';
index b002ec65b48a39a158bd8e4bffd202bf676423bb..3a1dc3e3ca5f233b6dc44d0fe405138e9d5a7295 100644 (file)
@@ -44,6 +44,8 @@ struct HttpResponse
 
 
 char *GetHttpError(void);
+void ConvertHttpRequestBodyToServerEncoding(struct HttpRequest *);
+void ConvertHttpResponseBodyToClientEncoding(struct HttpResponse *);
 boolean DoHttpRequest(struct HttpRequest *, struct HttpResponse *);
 
 #endif