http-mserv: add SRB2-specific user agent string

This commit is contained in:
Eidolon 2022-12-12 16:17:20 -06:00
parent fdb6f2aff9
commit 003ee55ccd

View file

@ -65,6 +65,8 @@ static I_mutex hms_api_mutex;
static char *hms_server_token; static char *hms_server_token;
static char hms_useragent[512];
struct HMS_buffer struct HMS_buffer
{ {
CURL *curl; 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 static size_t
HMS_on_read (char *s, size_t _1, size_t n, void *userdata) 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); I_lock_mutex(&hms_api_mutex);
#endif #endif
init_user_agent_once();
seek = strlen(hms_api) + 1;/* + '/' */ seek = strlen(hms_api) + 1;/* + '/' */
va_start (ap, format); 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_WRITEFUNCTION, HMS_on_read);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, buffer); curl_easy_setopt(curl, CURLOPT_WRITEDATA, buffer);
curl_easy_setopt(curl, CURLOPT_USERAGENT, hms_useragent);
curl_free(quack_token); curl_free(quack_token);
free(url); free(url);