Atrinik Client  4.0
Macros | Functions | Variables
metaserver.c File Reference
#include <global.h>
#include <toolkit/string.h>
#include <toolkit/curl.h>
#include <libxml/parser.h>
#include <libxml/tree.h>
#include <libxml/valid.h>
#include <libxml/xmlschemas.h>
#include <openssl/sha.h>
#include <openssl/err.h>

Go to the source code of this file.

Macros

#define XML_STR_EQUAL(s1, s2)   xmlStrEqual((const xmlChar *) s1, (const xmlChar *) s2)
 

Functions

void metaserver_init (void)
 
void metaserver_disable (void)
 
static void metaserver_cert_free (server_cert_info_t *info)
 
static void metaserver_free (server_struct *server)
 
static bool parse_metaserver_cert (server_struct *server)
 
static bool parse_metaserver_data_node (xmlNodePtr node, server_struct *server)
 
static void parse_metaserver_node (xmlNodePtr node)
 
static void parse_metaserver_data_error (void *ctx, const char *format,...)
 
static void parse_metaserver_data (const char *body, size_t body_size)
 
bool metaserver_cert_verify_host (server_struct *server, const char *host)
 
server_structserver_get_id (size_t num)
 
size_t server_get_count (void)
 
int ms_connecting (int val)
 
void metaserver_clear_data (void)
 
server_structmetaserver_add (const char *hostname, int port, int port_crypto, const char *name, const char *version, const char *desc)
 
int metaserver_thread (void *dummy)
 
void metaserver_get_servers (void)
 

Variables

static int metaserver_connecting = 1
 
static SDL_mutex * metaserver_connecting_mutex
 
static server_structserver_head
 
static size_t server_count
 
static SDL_mutex * server_head_mutex
 
static uint8_t enabled = 1
 
static const char * cert_begin_str
 
static const char * cert_end_str
 

Detailed Description

Handles connection to the metaserver and receiving data from it.

Author
Alex Tokar

Definition in file metaserver.c.

Macro Definition Documentation

#define XML_STR_EQUAL (   s1,
  s2 
)    xmlStrEqual((const xmlChar *) s1, (const xmlChar *) s2)

Macro to check for XML string equality without the annoying xmlChar pointer casts.

Parameters
s1First string to compare.
s2Second string to compare.
Returns
1 if both strings are equal, 0 otherwise.

Definition at line 55 of file metaserver.c.

Function Documentation

server_struct* metaserver_add ( const char *  hostname,
int  port,
int  port_crypto,
const char *  name,
const char *  version,
const char *  desc 
)

Add a server entry to the linked list of available servers reported by metaserver.

Parameters
hostnameServer's hostname.
portServer port.
port_cryptoSecure port to use.
nameServer's name.
versionServer version.
descDescription of the server.

Definition at line 731 of file metaserver.c.

static void metaserver_cert_free ( server_cert_info_t info)
static

Free the specified server certificate information structure.

Parameters
infoWhat to free.

Definition at line 116 of file metaserver.c.

bool metaserver_cert_verify_host ( server_struct server,
const char *  host 
)

Verify resolved address of a server against the server's metaserver certificate.

Parameters
serverServer to verify.
hostHost address.
Returns
True if the resolved address is equal to the one in the certificate, false otherwise.

Definition at line 591 of file metaserver.c.

void metaserver_clear_data ( void  )

Clear all data in the linked list of servers reported by metaserver.

Definition at line 697 of file metaserver.c.

void metaserver_disable ( void  )

Disable the metaserver.

Definition at line 103 of file metaserver.c.

static void metaserver_free ( server_struct server)
static

Free the specified metaserver server node.

Parameters
serverNode to free.

Definition at line 150 of file metaserver.c.

void metaserver_get_servers ( void  )

Connect to metaserver and get the available servers.

Works in a thread using SDL_CreateThread().

Definition at line 801 of file metaserver.c.

void metaserver_init ( void  )

Initialize the metaserver data.

Definition at line 86 of file metaserver.c.

int metaserver_thread ( void *  dummy)

Threaded function to connect to metaserver.

Goes through the list of metaservers and calls metaserver_connect() until it gets a return value of 1. If if goes through all the metaservers and still fails, show an info to the user.

Parameters
dummyUnused.
Returns
Always returns 0.

Definition at line 766 of file metaserver.c.

int ms_connecting ( int  val)

Check if we're connecting to the metaserver.

Parameters
valIf not -1, set the metaserver connecting value to this.
Returns
1 if we're connecting to the metaserver, 0 otherwise.

Definition at line 678 of file metaserver.c.

static bool parse_metaserver_cert ( server_struct server)
static

Parse the metaserver certificate information.

Parameters
serverMetaserver entry.
Returns
True on success, false on failure.

Definition at line 198 of file metaserver.c.

static void parse_metaserver_data ( const char *  body,
size_t  body_size 
)
static

Parse data returned from HTTP metaserver and add it to the list of servers.

Parameters
bodyThe data to parse.
body_sizeLength of the body.

Definition at line 499 of file metaserver.c.

static void parse_metaserver_data_error ( void *  ctx,
const char *  format,
  ... 
)
static

Callback to display an error message when XML validation fails.

Parameters
ctxXML context.
formatFormat specifier.
...Variable arguments.

Definition at line 479 of file metaserver.c.

static bool parse_metaserver_data_node ( xmlNodePtr  node,
server_struct server 
)
static

Parse a single metaserver data node within a 'server' node.

Parameters
nodeThe data node.
serverAllocated server structure.
Returns
True on success, false on failure.

Definition at line 357 of file metaserver.c.

static void parse_metaserver_node ( xmlNodePtr  node)
static

Parse metaserver 'server' node.

Parameters
nodeNode to parse.

Definition at line 430 of file metaserver.c.

size_t server_get_count ( void  )

Get number of the servers in the list.

Returns
The number.

Definition at line 661 of file metaserver.c.

server_struct* server_get_id ( size_t  num)

Get server from the servers list by its ID.

Parameters
numID of the server to find.
Returns
The server if found, NULL otherwise.

Definition at line 639 of file metaserver.c.

Variable Documentation

const char* cert_begin_str
static
Initial value:
= "=========================="
" BEGIN INFORMATION "
"=========================="

The string that begins certificate information.

Definition at line 75 of file metaserver.c.

const char* cert_end_str
static
Initial value:
= "=========================="
" END INFORMATION "
"=========================="

The string that ends certificate information.

Definition at line 79 of file metaserver.c.

uint8_t enabled = 1
static

Is metaserver enabled?

Definition at line 73 of file metaserver.c.

int metaserver_connecting = 1
static

Are we connecting to the metaserver?

Definition at line 63 of file metaserver.c.

SDL_mutex* metaserver_connecting_mutex
static

Mutex to protect metaserver_connecting.

Definition at line 65 of file metaserver.c.

size_t server_count
static

Number of the servers.

Definition at line 69 of file metaserver.c.

server_struct* server_head
static

The list of the servers.

Definition at line 67 of file metaserver.c.

SDL_mutex* server_head_mutex
static

Mutex to protect server_head and server_count.

Definition at line 71 of file metaserver.c.