Merge branch 'hms-useragent' into 'next'

http-mserv: add SRB2-specific user agent string

See merge request STJr/SRB2!1893
This commit is contained in:
Eidolon 2023-01-01 18:21:01 +00:00
commit fdff419818

View file

@ -65,6 +65,8 @@ static I_mutex hms_api_mutex;
static char *hms_server_token;
static char hms_useragent[512];
struct HMS_buffer
{
CURL *curl;
@ -81,6 +83,27 @@ Contact_error (void)
);
}
static void
get_user_agent(char *buf, size_t len)
{
#if defined(__STDC__) && __STDC_VERSION__ >= 201112L
if (sprintf_s(buf, len, "%s/%s (%s; %s; %i; %i) SRB2BASE/%i", SRB2APPLICATION, VERSIONSTRING, compbranch, comprevision, MODID, MODVERSION, CODEBASE) < 1)
I_Error("http-mserv: get_user_agent failed");
#else
if (sprintf(buf, "%s/%s (%s; %s; %i; %i) SRB2BASE/%i", SRB2APPLICATION, VERSIONSTRING, compbranch, comprevision, MODID, MODVERSION, CODEBASE) < 0)
I_Error("http-mserv: get_user_agent failed");
#endif
}
static void
init_user_agent_once(void)
{
if (hms_useragent[0] != '\0')
return;
get_user_agent(hms_useragent, 512);
}
static size_t
HMS_on_read (char *s, size_t _1, size_t n, void *userdata)
{
@ -156,6 +179,8 @@ HMS_connect (const char *format, ...)
I_lock_mutex(&hms_api_mutex);
#endif
init_user_agent_once();
seek = strlen(hms_api) + 1;/* + '/' */
va_start (ap, format);
@ -202,6 +227,8 @@ HMS_connect (const char *format, ...)
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, HMS_on_read);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, buffer);
curl_easy_setopt(curl, CURLOPT_USERAGENT, hms_useragent);
curl_free(quack_token);
free(url);