Tor  0.4.7.0-alpha-dev
Macros | Functions | Variables
versions.c File Reference

Code to manipulate, parse, and compare Tor versions. More...

#include "core/or/or.h"
#include "core/or/protover.h"
#include "core/or/versions.h"
#include "lib/crypt_ops/crypto_util.h"
#include "core/or/tor_version_st.h"

Go to the source code of this file.

Macros

#define NUMBER(m)
 
#define DOT()
 
#define CMP(field)
 

Functions

time_t tor_get_approx_release_date (void)
 
version_status_t tor_version_is_obsolete (const char *myversion, const char *versionlist)
 
int tor_version_parse_platform (const char *platform, tor_version_t *router_version, int strict)
 
int tor_version_as_new_as (const char *platform, const char *cutoff)
 
int tor_version_parse (const char *s, tor_version_t *out)
 
int tor_version_compare (tor_version_t *a, tor_version_t *b)
 
int tor_version_same_series (tor_version_t *a, tor_version_t *b)
 
static int compare_tor_version_str_ptr_ (const void **_a, const void **_b)
 
void sort_version_list (smartlist_t *versions, int remove_duplicates)
 
static void memoize_protover_summary (protover_summary_flags_t *out, const char *protocols)
 
void summarize_protover_flags (protover_summary_flags_t *out, const char *protocols, const char *version)
 
void protover_summary_cache_free_all (void)
 

Variables

static const int MAX_PROTOVER_SUMMARY_MAP_LEN = 1024
 
static strmap_t * protover_summary_map = NULL
 

Detailed Description

Code to manipulate, parse, and compare Tor versions.

Definition in file versions.c.

Macro Definition Documentation

◆ CMP

#define CMP (   field)
Value:
do { \
unsigned aval = (unsigned) a->field; \
unsigned bval = (unsigned) b->field; \
int result = (int) (aval - bval); \
if (result < 0) \
return -1; \
else if (result > 0) \
return 1; \
} while (0)

◆ DOT

#define DOT ( )
Value:
do { \
if (*cp != '.') \
return -1; \
++cp; \
} while (0)

◆ NUMBER

#define NUMBER (   m)
Value:
do { \
if (!cp || *cp < '0' || *cp > '9') \
return -1; \
out->m = (int)tor_parse_uint64(cp, 10, 0, INT32_MAX, &ok, &eos); \
if (!ok) \
return -1; \
if (!eos || eos == cp) \
return -1; \
cp = eos; \
} while (0)
uint64_t tor_parse_uint64(const char *s, int base, uint64_t min, uint64_t max, int *ok, char **next)
Definition: parse_int.c:110

Function Documentation

◆ compare_tor_version_str_ptr_()

static int compare_tor_version_str_ptr_ ( const void **  _a,
const void **  _b 
)
static

Helper: Given pointers to two strings describing tor versions, return -1 if _a precedes _b, 1 if _b precedes _a, and 0 if they are equivalent. Used to sort a list of versions.

Definition at line 369 of file versions.c.

Referenced by sort_version_list().

◆ memoize_protover_summary()

static void memoize_protover_summary ( protover_summary_flags_t out,
const char *  protocols 
)
static

Helper. Given a non-NULL protover string protocols, set out to its summary, and memoize the result in protover_summary_map.

If the protover string does not contain any recognised protocols, sets protocols_known, but does not set any other flags. (Empty strings are also treated this way.)

Definition at line 417 of file versions.c.

Referenced by summarize_protover_flags().

◆ protover_summary_cache_free_all()

void protover_summary_cache_free_all ( void  )

Free all space held in the protover_summary_map.

Definition at line 531 of file versions.c.

Referenced by memoize_protover_summary().

◆ sort_version_list()

void sort_version_list ( smartlist_t versions,
int  remove_duplicates 
)

Sort a list of string-representations of versions in ascending order.

Definition at line 391 of file versions.c.

◆ summarize_protover_flags()

void summarize_protover_flags ( protover_summary_flags_t out,
const char *  protocols,
const char *  version 
)

Summarize the protocols listed in protocols into out, falling back or correcting them based on version as appropriate.

If protocols and version are both NULL or "", returns a summary with no flags set.

If the protover string does not contain any recognised protocols, and the version is not recognised, sets protocols_known, but does not set any other flags. (Empty strings are also treated this way.)

Definition at line 501 of file versions.c.

◆ tor_get_approx_release_date()

time_t tor_get_approx_release_date ( void  )

Return the approximate date when this release came out, or was scheduled to come out, according to the APPROX_RELEASE_DATE set in configure.ac

Definition at line 25 of file versions.c.

Referenced by networkstatus_check_required_protocols().

◆ tor_version_as_new_as()

int tor_version_as_new_as ( const char *  platform,
const char *  cutoff 
)

Parse the Tor version of the platform string platform, and compare it to the version in cutoff. Return 1 if the router is at least as new as the cutoff, else return 0.

Definition at line 171 of file versions.c.

Referenced by dirserv_rejects_tor_version(), protover_compute_for_old_tor(), and summarize_protover_flags().

◆ tor_version_compare()

int tor_version_compare ( tor_version_t a,
tor_version_t b 
)

Compare two tor versions; Return <0 if a < b; 0 if a ==b, >0 if a > b.

Definition at line 315 of file versions.c.

Referenced by compare_tor_version_str_ptr_().

◆ tor_version_is_obsolete()

version_status_t tor_version_is_obsolete ( const char *  myversion,
const char *  versionlist 
)

Return VS_RECOMMENDED if myversion is contained in versionlist. Else, return VS_EMPTY if versionlist has no entries. Else, return VS_OLD if every member of versionlist is newer than myversion. Else, return VS_NEW_IN_SERIES if there is at least one member of versionlist in the same series (major.minor.micro) as myversion, but no such member is newer than myversion.. Else, return VS_NEW if every member of versionlist is older than myversion. Else, return VS_UNRECOMMENDED.

(versionlist is a comma-separated list of version strings, optionally prefixed with "Tor". Versions that can't be parsed are ignored.)

Definition at line 53 of file versions.c.

◆ tor_version_parse()

int tor_version_parse ( const char *  s,
tor_version_t out 
)

Parse a tor version from s, and store the result in out. Return 0 on success, -1 on failure.

Definition at line 206 of file versions.c.

Referenced by compare_tor_version_str_ptr_(), and tor_version_as_new_as().

◆ tor_version_parse_platform()

int tor_version_parse_platform ( const char *  platform,
tor_version_t router_version,
int  strict 
)

Extract a Tor version from a platform line from a router descriptor, and place the result in router_version.

Return 1 on success, -1 on parsing failure, and 0 if the platform line does not indicate some version of Tor.

If strict is non-zero, finding any weird version components (like negative numbers) counts as a parsing failure.

Definition at line 127 of file versions.c.

◆ tor_version_same_series()

int tor_version_same_series ( tor_version_t a,
tor_version_t b 
)

Return true iff versions a and b belong to the same series.

Definition at line 356 of file versions.c.

Variable Documentation

◆ MAX_PROTOVER_SUMMARY_MAP_LEN

const int MAX_PROTOVER_SUMMARY_MAP_LEN = 1024
static

If there are more than this many entries, we're probably under some kind of weird DoS.

Definition at line 401 of file versions.c.

Referenced by memoize_protover_summary().

◆ protover_summary_map

strmap_t* protover_summary_map = NULL
static

Map from protover string to protover_summary_flags_t.

Definition at line 406 of file versions.c.

Referenced by memoize_protover_summary().