mod_tile 0.9.1
Renders map tiles with Mapnik and serves them using Apache HTTP Server
Loading...
Searching...
No Matches
cache_expire.c File Reference
#include <arpa/inet.h>
#include <glib.h>
#include <netdb.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <unistd.h>
#include "cache_expire.h"
#include "g_logger.h"

Functions

static void put_u16 (char *dst, uint16_t value)
 Write a 16-bit unsigned integer in network byte order (big-endian) at an arbitrary (possibly unaligned) memory address.
static void put_u32 (char *dst, uint32_t value)
 Write a 32-bit unsigned integer in network byte order (big-endian) at an arbitrary (possibly unaligned) memory address.
static void cache_expire_url (int sock, char *url)
 Construct and send an HTCP (Hyper Text Caching Protocol) CLR (cache clear/purge) UDP datagram for a given URL.
void cache_expire (int sock, const char *host, const char *uri, int x, int y, int z)
 Format a tile URL from Z/X/Y coordinates and send an HTCP purge request.
int init_cache_expire (const char *htcphost)
 Initialize and connect a UDP socket to an HTCP caching server.

Function Documentation

◆ cache_expire()

void cache_expire ( int sock,
const char * host,
const char * uri,
int x,
int y,
int z )

Format a tile URL from Z/X/Y coordinates and send an HTCP purge request.

Constructs a URL of the form http://<host><uri><z>/<x>/<y>.png (assuming uri includes leading and trailing slashes) and passes it to cache_expire_url().

Parameters
sockConnected UDP socket descriptor returned by init_cache_expire(). If negative, the function returns immediately without action.
hostTarget cache hostname or IP address (e.g., "tile.openstreetmap.org").
uriBase URI path prefix for the tileset (e.g., "/").
xTile X coordinate.
yTile Y coordinate.
zTile zoom level.

◆ cache_expire_url()

void cache_expire_url ( int sock,
char * url )
static

Construct and send an HTCP (Hyper Text Caching Protocol) CLR (cache clear/purge) UDP datagram for a given URL.

Follows RFC 2756 packet framing:

  • 12 bytes: HTCP outer header (length, version, data length, opcode, reserved, transaction ID) + 2-byte auth trailer length (0)
  • 22 bytes: CLR specifier fixed fields (reason, method length + "HEAD", URL length, version length + "HTTP/1.1", headers length)
  • url_len bytes: Target URL string
Parameters
sockConnected UDP socket descriptor to the HTCP cache server.
urlNull-terminated URL string to purge from cache.

◆ init_cache_expire()

int init_cache_expire ( const char * htcphost)

Initialize and connect a UDP socket to an HTCP caching server.

Resolves htcphost using HTCP_EXPIRE_CACHE_PORT and attempts to create and connect a SOCK_DGRAM socket against each resolved address until one succeeds.

Parameters
htcphostHostname or IP address string of the HTCP cache server.
Returns
Connected socket file descriptor on success, or -1 on failure.

◆ put_u16()

void put_u16 ( char * dst,
uint16_t value )
static

Write a 16-bit unsigned integer in network byte order (big-endian) at an arbitrary (possibly unaligned) memory address.

Casting &buf[idx] directly to uint16_t* is undefined behavior in C and can cause alignment faults on strict-alignment architectures.

Parameters
dstDestination buffer pointer.
value16-bit value in host byte order.

◆ put_u32()

void put_u32 ( char * dst,
uint32_t value )
static

Write a 32-bit unsigned integer in network byte order (big-endian) at an arbitrary (possibly unaligned) memory address.

Casting &buf[idx] directly to uint32_t* is undefined behavior in C and can cause alignment faults on strict-alignment architectures.

Parameters
dstDestination buffer pointer.
value32-bit value in host byte order.