2007-06-10 21:46:44 +04:00
|
|
|
/*
|
|
|
|
* Copyright 2007 Daniel Silverstone <dsilvers@digital-scurf.org>
|
|
|
|
* Copyright 2007 Rob Kendrick <rjek@netsurf-browser.org>
|
2007-08-08 20:16:03 +04:00
|
|
|
*
|
|
|
|
* This file is part of NetSurf, http://www.netsurf-browser.org/
|
|
|
|
*
|
|
|
|
* NetSurf is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; version 2 of the License.
|
|
|
|
*
|
|
|
|
* NetSurf is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2007-06-10 21:46:44 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
2007-06-10 22:08:22 +04:00
|
|
|
#include <stdlib.h>
|
2007-06-10 21:46:44 +04:00
|
|
|
|
2010-01-31 03:36:02 +03:00
|
|
|
#include "utils/config.h"
|
|
|
|
#include "utils/utsname.h"
|
2014-10-13 18:08:16 +04:00
|
|
|
#include "desktop/version.h"
|
2007-06-10 21:46:44 +04:00
|
|
|
#include "utils/log.h"
|
2007-06-10 22:08:22 +04:00
|
|
|
#include "utils/useragent.h"
|
2007-06-10 21:46:44 +04:00
|
|
|
|
|
|
|
static const char *core_user_agent_string = NULL;
|
|
|
|
|
2008-07-29 19:10:31 +04:00
|
|
|
#ifndef NETSURF_UA_FORMAT_STRING
|
2013-01-14 17:59:07 +04:00
|
|
|
#define NETSURF_UA_FORMAT_STRING "NetSurf/%d.%d (%s)"
|
2008-07-29 19:10:31 +04:00
|
|
|
#endif
|
2007-06-10 21:46:44 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Prepare core_user_agent_string with a string suitable for use as a
|
|
|
|
* user agent in HTTP requests.
|
|
|
|
*/
|
|
|
|
static void
|
2007-06-10 22:13:59 +04:00
|
|
|
user_agent_build_string(void)
|
2007-06-10 21:46:44 +04:00
|
|
|
{
|
2007-06-10 22:13:59 +04:00
|
|
|
struct utsname un;
|
|
|
|
const char *sysname = "Unknown";
|
|
|
|
char *ua_string;
|
|
|
|
int len;
|
2007-06-10 22:08:22 +04:00
|
|
|
|
2007-06-16 02:07:11 +04:00
|
|
|
if (uname(&un) >= 0) {
|
2007-06-10 22:13:59 +04:00
|
|
|
sysname = un.sysname;
|
|
|
|
}
|
2007-06-10 22:08:22 +04:00
|
|
|
|
2007-06-10 22:13:59 +04:00
|
|
|
len = snprintf(NULL, 0, NETSURF_UA_FORMAT_STRING,
|
|
|
|
netsurf_version_major,
|
|
|
|
netsurf_version_minor,
|
2013-01-14 17:59:07 +04:00
|
|
|
sysname);
|
2007-06-10 22:13:59 +04:00
|
|
|
ua_string = malloc(len + 1);
|
|
|
|
if (!ua_string) {
|
|
|
|
/** \todo this needs handling better */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
snprintf(ua_string, len + 1,
|
|
|
|
NETSURF_UA_FORMAT_STRING,
|
2007-06-10 21:46:44 +04:00
|
|
|
netsurf_version_major,
|
|
|
|
netsurf_version_minor,
|
2013-01-14 17:59:07 +04:00
|
|
|
sysname);
|
2007-06-10 22:08:22 +04:00
|
|
|
|
2007-06-10 22:13:59 +04:00
|
|
|
core_user_agent_string = ua_string;
|
2007-06-10 21:46:44 +04:00
|
|
|
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("Built user agent \"%s\"", core_user_agent_string);
|
2007-06-10 21:46:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* This is a function so that later we can override it trivially */
|
|
|
|
const char *
|
|
|
|
user_agent_string(void)
|
|
|
|
{
|
2007-06-10 22:13:59 +04:00
|
|
|
if (core_user_agent_string == NULL)
|
|
|
|
user_agent_build_string();
|
2008-07-29 19:36:54 +04:00
|
|
|
return core_user_agent_string;
|
2007-06-10 21:46:44 +04:00
|
|
|
}
|
2008-07-29 19:10:31 +04:00
|
|
|
|