2007-06-10 21:46:44 +04:00
|
|
|
/*
|
|
|
|
* This file is part of NetSurf, http://netsurf-browser.org/
|
|
|
|
* Licensed under the GNU General Public License,
|
|
|
|
* http://www.opensource.org/licenses/gpl-license
|
|
|
|
* Copyright 2007 Daniel Silverstone <dsilvers@digital-scurf.org>
|
|
|
|
* Copyright 2007 Rob Kendrick <rjek@netsurf-browser.org>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/utsname.h>
|
|
|
|
#include <stdio.h>
|
2007-06-10 22:08:22 +04:00
|
|
|
#include <stdlib.h>
|
2007-06-10 21:46:44 +04:00
|
|
|
|
|
|
|
#include "desktop/netsurf.h"
|
|
|
|
#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;
|
|
|
|
|
|
|
|
#define NETSURF_UA_FORMAT_STRING "NetSurf/%d.%d (%s; %s)"
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Prepare core_user_agent_string with a string suitable for use as a
|
|
|
|
* user agent in HTTP requests.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
build_user_agent(void)
|
|
|
|
{
|
|
|
|
struct utsname un;
|
|
|
|
const char *sysname = "Unknown";
|
|
|
|
const char *machine = "Unknown";
|
2007-06-10 22:08:22 +04:00
|
|
|
char *ua_string;
|
2007-06-10 21:46:44 +04:00
|
|
|
int len;
|
2007-06-10 22:08:22 +04:00
|
|
|
|
2007-06-10 21:46:44 +04:00
|
|
|
if (uname(&un) == 0) {
|
|
|
|
sysname = un.sysname;
|
|
|
|
machine = un.machine;
|
|
|
|
}
|
2007-06-10 22:08:22 +04:00
|
|
|
|
2007-06-10 21:46:44 +04:00
|
|
|
len = snprintf(NULL, 0, NETSURF_UA_FORMAT_STRING,
|
|
|
|
netsurf_version_major,
|
|
|
|
netsurf_version_minor,
|
2007-06-10 22:08:22 +04:00
|
|
|
sysname,
|
|
|
|
machine);
|
|
|
|
ua_string = malloc(len + 1);
|
|
|
|
if (!ua_string) {
|
|
|
|
/** \todo this needs handling better */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
snprintf(ua_string, len + 1,
|
2007-06-10 21:46:44 +04:00
|
|
|
NETSURF_UA_FORMAT_STRING,
|
|
|
|
netsurf_version_major,
|
|
|
|
netsurf_version_minor,
|
2007-06-10 22:08:22 +04:00
|
|
|
sysname,
|
|
|
|
machine);
|
|
|
|
|
|
|
|
core_user_agent_string = ua_string;
|
2007-06-10 21:46:44 +04:00
|
|
|
|
|
|
|
LOG(("Built user agent \"%s\"", core_user_agent_string));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This is a function so that later we can override it trivially */
|
|
|
|
const char *
|
|
|
|
user_agent_string(void)
|
|
|
|
{
|
|
|
|
if (core_user_agent_string == NULL)
|
|
|
|
build_user_agent();
|
|
|
|
return core_user_agent_string;
|
|
|
|
}
|