Generates and use a User-Agent: string based on new netsurf_version_major/minor values, and results of uname().
svn path=/trunk/netsurf/; revision=3158
This commit is contained in:
parent
7c88381a59
commit
5426a708a9
|
@ -98,7 +98,7 @@ struct cache_handle {
|
||||||
struct cache_handle *r_next; /**< Next cached handle in ring. */
|
struct cache_handle *r_next; /**< Next cached handle in ring. */
|
||||||
};
|
};
|
||||||
|
|
||||||
static const char * const user_agent = "NetSurf";
|
static char *user_agent = "NetSurf";
|
||||||
CURLM *fetch_curl_multi; /**< Global cURL multi handle. */
|
CURLM *fetch_curl_multi; /**< Global cURL multi handle. */
|
||||||
/** Curl handle with default options set; not used for transfers. */
|
/** Curl handle with default options set; not used for transfers. */
|
||||||
static CURL *fetch_blank_curl;
|
static CURL *fetch_blank_curl;
|
||||||
|
@ -212,6 +212,10 @@ static void fetch_dispatch_jobs(void);
|
||||||
void fetch_init(void)
|
void fetch_init(void)
|
||||||
{
|
{
|
||||||
CURLcode code;
|
CURLcode code;
|
||||||
|
char *ua = make_useragent();
|
||||||
|
|
||||||
|
if (ua != NULL)
|
||||||
|
user_agent = ua;
|
||||||
|
|
||||||
code = curl_global_init(CURL_GLOBAL_ALL);
|
code = curl_global_init(CURL_GLOBAL_ALL);
|
||||||
if (code != CURLE_OK)
|
if (code != CURLE_OK)
|
||||||
|
|
|
@ -12,6 +12,8 @@
|
||||||
|
|
||||||
extern bool netsurf_quit;
|
extern bool netsurf_quit;
|
||||||
extern const char * const netsurf_version;
|
extern const char * const netsurf_version;
|
||||||
|
extern const int netsurf_version_major;
|
||||||
|
extern const int netsurf_version_minor;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -1,2 +1,3 @@
|
||||||
const char * const netsurf_version = "Development Build";
|
const char * const netsurf_version = "Development Build";
|
||||||
|
const int netsurf_version_major = 0;
|
||||||
|
const int netsurf_version_minor = 0;
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
* This file is part of NetSurf, http://netsurf-browser.org/
|
* This file is part of NetSurf, http://netsurf-browser.org/
|
||||||
* Licensed under the GNU General Public License,
|
* Licensed under the GNU General Public License,
|
||||||
* http://www.opensource.org/licenses/gpl-license
|
* http://www.opensource.org/licenses/gpl-license
|
||||||
|
* Copyright 2007 Rob Kendrick <rjek@netsurf-browser.org>
|
||||||
* Copyright 2004-2007 James Bursa <bursa@users.sourceforge.net>
|
* Copyright 2004-2007 James Bursa <bursa@users.sourceforge.net>
|
||||||
* Copyright 2003 Phil Mellor <monkeyson@users.sourceforge.net>
|
* Copyright 2003 Phil Mellor <monkeyson@users.sourceforge.net>
|
||||||
* Copyright 2003 John M Bell <jmb202@ecs.soton.ac.uk>
|
* Copyright 2003 John M Bell <jmb202@ecs.soton.ac.uk>
|
||||||
|
@ -15,6 +16,8 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
#include <sys/utsname.h>
|
||||||
|
#include <sys/time.h>
|
||||||
#include <regex.h>
|
#include <regex.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include "netsurf/utils/config.h"
|
#include "netsurf/utils/config.h"
|
||||||
|
@ -23,6 +26,7 @@
|
||||||
#include "netsurf/utils/messages.h"
|
#include "netsurf/utils/messages.h"
|
||||||
#include "netsurf/utils/utf8.h"
|
#include "netsurf/utils/utf8.h"
|
||||||
#include "netsurf/utils/utils.h"
|
#include "netsurf/utils/utils.h"
|
||||||
|
#include "netsurf/desktop/netsurf.h"
|
||||||
|
|
||||||
|
|
||||||
char * strip(char * const s)
|
char * strip(char * const s)
|
||||||
|
@ -254,6 +258,37 @@ unsigned int wallclock(void)
|
||||||
return ((tv.tv_sec * 100) + (tv.tv_usec / 10000));
|
return ((tv.tv_sec * 100) + (tv.tv_usec / 10000));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Generate a string suitable for use as a user agent in HTTP requests.
|
||||||
|
*
|
||||||
|
* \return heap-allocated result string, or NULL if the allocation failed.
|
||||||
|
*/
|
||||||
|
#define UA_BUF_SIZE 128
|
||||||
|
char *make_useragent(void)
|
||||||
|
{
|
||||||
|
struct utsname un;
|
||||||
|
char ua_name[UA_BUF_SIZE];
|
||||||
|
char ua_machine[UA_BUF_SIZE];
|
||||||
|
char *r;
|
||||||
|
|
||||||
|
snprintf(ua_name, UA_BUF_SIZE, "NetSurf/%d.%d",
|
||||||
|
netsurf_version_major,
|
||||||
|
netsurf_version_minor);
|
||||||
|
|
||||||
|
if (uname(&un) != 0) {
|
||||||
|
strncpy(ua_machine, "unknown machine", UA_BUF_SIZE);
|
||||||
|
} else {
|
||||||
|
snprintf(ua_machine, UA_BUF_SIZE, "(%s; %s)", un.sysname,
|
||||||
|
un.machine);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((r = malloc(strlen(ua_name) + strlen(ua_machine) + 2)) == NULL)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
sprintf(r, "%s %s", ua_name, ua_machine);
|
||||||
|
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef __FreeBSD__
|
#ifdef __FreeBSD__
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -57,6 +57,7 @@ char *human_friendly_bytesize(unsigned long bytesize);
|
||||||
const char *rfc1123_date(time_t t);
|
const char *rfc1123_date(time_t t);
|
||||||
char *strcasestr(const char *haystack, const char *needle);
|
char *strcasestr(const char *haystack, const char *needle);
|
||||||
unsigned int wallclock(void);
|
unsigned int wallclock(void);
|
||||||
|
char *make_useragent(void);
|
||||||
#ifdef __FreeBSD__
|
#ifdef __FreeBSD__
|
||||||
/* FreeBSD lacks strndup */
|
/* FreeBSD lacks strndup */
|
||||||
char *strndup(const char *s, size_t n);
|
char *strndup(const char *s, size_t n);
|
||||||
|
|
Loading…
Reference in New Issue