diff --git a/.clang-format b/.clang-format new file mode 100644 index 00000000..afe622a1 --- /dev/null +++ b/.clang-format @@ -0,0 +1,12 @@ +--- +# Taken from "style similar to the Linux Kernel style": +# https://clang.llvm.org/docs/ClangFormatStyleOptions.html#examples +BasedOnStyle: LLVM + +AllowShortIfStatementsOnASingleLine: false +BreakBeforeBraces: Linux +ColumnLimit: 0 +IndentCaseLabels: false +IndentWidth: 8 +InsertNewlineAtEOF: true +UseTab: Always diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index e466327b..bca2f9d7 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -6,59 +6,50 @@ on: push: jobs: - astyle: - env: - ASTYLE_CMD: >- - astyle - --break-blocks - --indent-switches - --indent=force-tab=8 - --lineend=linux - --options=none - --pad-header - --pad-oper - --style=1tbs - --suffix=none - --unpad-paren - includes/*.h includes/*.hpp src/*.c src/*.cpp - name: Lint with `Artistic Style` + clang-format: + container: + env: + CLANG_FORMAT_CMD: >- + clang-format -i + includes/*.h includes/*.hpp src/*.c src/*.cpp + image: archlinux + name: Lint with `Clang Format` runs-on: ubuntu-latest steps: - name: Checkout code uses: actions/checkout@v4 - name: Provision environment - uses: ./.github/actions/dependencies/install/apt-get - with: - packages: astyle - - name: Check if any modifications were made by `astyle` run: | - ASTYLE_OUTPUT=$(${ASTYLE_CMD} --dry-run) - if [ -n "$(echo "${ASTYLE_OUTPUT}" | grep -v "Unchanged")" ]; then + pacman --sync --refresh --noconfirm clang + - name: Check if any modifications were made by `clang-format` + run: | + CLANG_FORMAT_OUTPUT=$(${CLANG_FORMAT_CMD} --dry-run) + if [ -n "$(echo "${CLANG_FORMAT_OUTPUT}" | grep -v "Unchanged")" ]; then echo "The following files are in need of formatting:" - echo "${ASTYLE_OUTPUT}" | grep -v "Unchanged" | awk '{print "`"$2"`"}' + echo "${CLANG_FORMAT_OUTPUT}" | grep -v "Unchanged" | awk '{print "`"$2"`"}' echo "" echo "Run the following command before submitting a pull request:" - echo '`'"${ASTYLE_CMD}"'`' + echo '`'"${CLANG_FORMAT_CMD}"'`' exit 1 fi - - name: Write `$ASTYLE_OUTPUT` to `$GITHUB_STEP_SUMMARY` + - name: Write `$CLANG_FORMAT_OUTPUT` to `$GITHUB_STEP_SUMMARY` run: | - ASTYLE_OUTPUT=$(${ASTYLE_CMD} --dry-run) + CLANG_FORMAT_OUTPUT=$(${CLANG_FORMAT_CMD} --dry-run) echo "### The following files are in need of formatting:" >> ${GITHUB_STEP_SUMMARY} - echo "${ASTYLE_OUTPUT}" | grep -v "Unchanged" | awk '{print "- `"$2"`"}' >> ${GITHUB_STEP_SUMMARY} + echo "${CLANG_FORMAT_OUTPUT}" | grep -v "Unchanged" | awk '{print "- `"$2"`"}' >> ${GITHUB_STEP_SUMMARY} echo "### Run the following command before submitting a pull request:" >> ${GITHUB_STEP_SUMMARY} - echo -e '```shell\n'"${ASTYLE_CMD}"'\n```' >> ${GITHUB_STEP_SUMMARY} + echo -e '```shell\n'"${CLANG_FORMAT_CMD}"'\n```' >> ${GITHUB_STEP_SUMMARY} if: failure() - - name: Generate `ArtisticStyleFormattingFixes.patch` file + - name: Generate `ClangFormat.patch` file run: | - ${ASTYLE_CMD} - git diff --patch > ArtisticStyleFormattingFixes.patch + ${CLANG_FORMAT_CMD} + git diff --patch > ClangFormat.patch if: failure() - - name: Upload `ArtisticStyleFormattingFixes.patch` file + - name: Upload `ClangFormat.patch` file uses: actions/upload-artifact@v4 with: - name: ArtisticStyleFormattingFixes.patch - path: ArtisticStyleFormattingFixes.patch + name: ClangFormat.patch + path: ClangFormat.patch if: failure() cmakelint: diff --git a/includes/gen_tile.h b/includes/gen_tile.h index e617bf82..03eaa2c7 100644 --- a/includes/gen_tile.h +++ b/includes/gen_tile.h @@ -31,7 +31,7 @@ enum queueEnum { queueRequest, queueRender, queueDuplicate, queueRequestLow - }; +}; struct item { struct item *next; diff --git a/includes/metatile.h b/includes/metatile.h index 5f3e1848..b87fe4c0 100644 --- a/includes/metatile.h +++ b/includes/metatile.h @@ -41,8 +41,8 @@ struct meta_layout { int count; // METATILE ^ 2 int x, y, z; // lowest x,y of this metatile, plus z struct entry index[]; // count entries - // Followed by the tile data - // The index offsets are measured from the start of the file + // Followed by the tile data + // The index offsets are measured from the start of the file }; #ifdef __cplusplus @@ -50,7 +50,7 @@ struct meta_layout { class metaTile { -public: + public: metaTile(const std::string &xmlconfig, const std::string &options, int x, int y, int z); void clear(); void set(int x, int y, const std::string &data); @@ -59,7 +59,7 @@ class metaTile void save(struct storage_backend *store); void expire_tiles(int sock, const char *host, const char *uri); -private: + private: int x_, y_, z_; std::string xmlconfig_; std::string options_; diff --git a/includes/mod_tile.h b/includes/mod_tile.h index d0e1aa46..64ad5433 100644 --- a/includes/mod_tile.h +++ b/includes/mod_tile.h @@ -152,6 +152,6 @@ enum tileState { tileMissing, tileOld, tileVeryOld, tileCurrent - }; +}; #endif diff --git a/includes/protocol.h b/includes/protocol.h index cb61fd93..09ed6ae4 100644 --- a/includes/protocol.h +++ b/includes/protocol.h @@ -55,7 +55,7 @@ enum protoCmd { cmdIgnore, cmdRenderPrio, cmdRenderBulk, cmdRenderLow - }; +}; struct protocol { int ver; diff --git a/includes/store.h b/includes/store.h index 3d2f65b3..67c1e86c 100644 --- a/includes/store.h +++ b/includes/store.h @@ -36,7 +36,7 @@ struct stat_info { struct storage_backend { int (*tile_read)(struct storage_backend *store, const char *xmlconfig, const char *options, int x, int y, int z, char *buf, size_t sz, int *compressed, char *err_msg); - struct stat_info(*tile_stat)(struct storage_backend *store, const char *xmlconfig, const char *options, int x, int y, int z); + struct stat_info (*tile_stat)(struct storage_backend *store, const char *xmlconfig, const char *options, int x, int y, int z); int (*metatile_write)(struct storage_backend *store, const char *xmlconfig, const char *options, int x, int y, int z, const char *buf, int sz); int (*metatile_delete)(struct storage_backend *store, const char *xmlconfig, int x, int y, int z); int (*metatile_expire)(struct storage_backend *store, const char *xmlconfig, int x, int y, int z); diff --git a/src/cache_expire.c b/src/cache_expire.c index ff128882..0d172f57 100644 --- a/src/cache_expire.c +++ b/src/cache_expire.c @@ -32,9 +32,9 @@ * URL. * RFC for HTCP can be found at http://www.htcp.org/ */ -static void cache_expire_url(int sock, char * url) +static void cache_expire_url(int sock, char *url) { - char * buf; + char *buf; if (sock < 0) { return; @@ -44,7 +44,7 @@ static void cache_expire_url(int sock, char * url) int url_len; url_len = strlen(url); - buf = (char *) malloc(12 + 22 + url_len); + buf = (char *)malloc(12 + 22 + url_len); if (!buf) { return; @@ -52,58 +52,58 @@ static void cache_expire_url(int sock, char * url) idx = 0; - //16 bit: Overall length of the datagram packet, including this header + // 16 bit: Overall length of the datagram packet, including this header *((uint16_t *)(&buf[idx])) = htons(12 + 22 + url_len); idx += 2; - //HTCP version. Currently at 0.0 - buf[idx++] = 0; //Major version - buf[idx++] = 0; //Minor version + // HTCP version. Currently at 0.0 + buf[idx++] = 0; // Major version + buf[idx++] = 0; // Minor version - //Length of HTCP data, including this field + // Length of HTCP data, including this field *((uint16_t *)(&buf[idx])) = htons(8 + 22 + url_len); idx += 2; - //HTCP opcode CLR=4 + // HTCP opcode CLR=4 buf[idx++] = 4; - //Reserved + // Reserved buf[idx++] = 0; - //32 bit transaction id; + // 32 bit transaction id; *((uint32_t *)(&buf[idx])) = htonl(255); idx += 4; buf[idx++] = 0; - buf[idx++] = 0; //HTCP reason + buf[idx++] = 0; // HTCP reason - //Length of the Method string + // Length of the Method string *((uint16_t *)(&buf[idx])) = htons(4); idx += 2; - ///Method string + /// Method string memcpy(&buf[idx], "HEAD", 4); idx += 4; - //Length of the url string + // Length of the url string *((uint16_t *)(&buf[idx])) = htons(url_len); idx += 2; - //Url string + // Url string memcpy(&buf[idx], url, url_len); idx += url_len; - //Length of version string + // Length of version string *((uint16_t *)(&buf[idx])) = htons(8); idx += 2; - //version string + // version string memcpy(&buf[idx], "HTTP/1.1", 8); idx += 8; - //Length of request headers. Currently 0 as we don't have any headers to send + // Length of request headers. Currently 0 as we don't have any headers to send *((uint16_t *)(&buf[idx])) = htons(0); - if (send(sock, (void *) buf, (12 + 22 + url_len), 0) < (12 + 22 + url_len)) { + if (send(sock, (void *)buf, (12 + 22 + url_len), 0) < (12 + 22 + url_len)) { g_logger(G_LOG_LEVEL_ERROR, "Failed to send HTCP purge for %s", url); }; @@ -117,13 +117,13 @@ void cache_expire(int sock, const char *host, const char *uri, int x, int y, int return; } - char * url = (char *)malloc(1024); + char *url = (char *)malloc(1024); snprintf(url, 1024, "http://%s%s%i/%i/%i.png", host, uri, z, x, y); cache_expire_url(sock, url); free(url); } -int init_cache_expire(const char * htcphost) +int init_cache_expire(const char *htcphost) { struct addrinfo hints; struct addrinfo *result, *rp; @@ -132,7 +132,7 @@ int init_cache_expire(const char * htcphost) /* Obtain address(es) matching host/port */ memset(&hints, 0, sizeof(struct addrinfo)); - hints.ai_family = AF_UNSPEC; /* Allow IPv4 or IPv6 */ + hints.ai_family = AF_UNSPEC; /* Allow IPv4 or IPv6 */ hints.ai_socktype = SOCK_DGRAM; /* Datagram socket */ hints.ai_flags = 0; hints.ai_protocol = 0; /* Any protocol */ @@ -157,7 +157,7 @@ int init_cache_expire(const char * htcphost) } if (connect(sfd, rp->ai_addr, rp->ai_addrlen) != -1) { - break; /* Success */ + break; /* Success */ } close(sfd); @@ -171,5 +171,4 @@ int init_cache_expire(const char * htcphost) freeaddrinfo(result); /* No longer needed */ return sfd; - } diff --git a/src/convert_meta.c b/src/convert_meta.c index ca6fcf3d..735a1770 100644 --- a/src/convert_meta.c +++ b/src/convert_meta.c @@ -17,28 +17,27 @@ #define _GNU_SOURCE +#include "dir_utils.h" +#include "render_config.h" +#include "store.h" +#include +#include +#include +#include +#include +#include +#include +#include #include #include -#include -#include +#include #include #include #include +#include #include -#include -#include -#include -#include #include -#include -#include -#include -#include -#include -#include -#include "render_config.h" -#include "dir_utils.h" -#include "store.h" +#include char *tile_dir = RENDERD_TILE_DIR; @@ -63,7 +62,7 @@ void display_rate(struct timeval start, struct timeval end, int num) int d_s, d_us; float sec; - d_s = end.tv_sec - start.tv_sec; + d_s = end.tv_sec - start.tv_sec; d_us = end.tv_usec - start.tv_usec; sec = d_s + d_us / 1000000.0; @@ -79,7 +78,7 @@ static void descend(const char *search) char path[PATH_MAX]; if (!tiles) { - //fprintf(stderr, "Unable to open directory: %s\n", search); + // fprintf(stderr, "Unable to open directory: %s\n", search); return; } @@ -87,7 +86,7 @@ static void descend(const char *search) struct stat b; char *p; - //check_load(); + // check_load(); if (!strcmp(entry->d_name, ".") || !strcmp(entry->d_name, "..")) { continue; @@ -122,7 +121,6 @@ static void descend(const char *search) closedir(tiles); } - int main(int argc, char **argv) { int z, c; @@ -131,15 +129,14 @@ int main(int argc, char **argv) while (1) { int option_index = 0; static struct option long_options[] = { - {"map", 1, 0, 'm'}, - {"min-zoom", 1, 0, 'z'}, - {"max-zoom", 1, 0, 'Z'}, - {"unpack", 0, 0, 'u'}, - {"tile-dir", 1, 0, 't'}, - {"verbose", 0, 0, 'v'}, - {"help", 0, 0, 'h'}, - {0, 0, 0, 0} - }; + {"map", 1, 0, 'm'}, + {"min-zoom", 1, 0, 'z'}, + {"max-zoom", 1, 0, 'Z'}, + {"unpack", 0, 0, 'u'}, + {"tile-dir", 1, 0, 't'}, + {"verbose", 0, 0, 'v'}, + {"help", 0, 0, 'h'}, + {0, 0, 0, 0}}; c = getopt_long(argc, argv, "uhvz:Z:m:t:", long_options, &option_index); @@ -148,55 +145,55 @@ int main(int argc, char **argv) } switch (c) { - case 'z': - minZoom = atoi(optarg); + case 'z': + minZoom = atoi(optarg); - if (minZoom < 0 || minZoom > MAX_ZOOM) { - fprintf(stderr, "Invalid minimum zoom selected, must be between 0 and %d\n", MAX_ZOOM); - return 1; - } + if (minZoom < 0 || minZoom > MAX_ZOOM) { + fprintf(stderr, "Invalid minimum zoom selected, must be between 0 and %d\n", MAX_ZOOM); + return 1; + } - break; + break; - case 'Z': - maxZoom = atoi(optarg); + case 'Z': + maxZoom = atoi(optarg); - if (maxZoom < 0 || maxZoom > MAX_ZOOM) { - fprintf(stderr, "Invalid maximum zoom selected, must be between 0 and %d\n", MAX_ZOOM); - return 1; - } + if (maxZoom < 0 || maxZoom > MAX_ZOOM) { + fprintf(stderr, "Invalid maximum zoom selected, must be between 0 and %d\n", MAX_ZOOM); + return 1; + } - break; - - case 'm': - map = strdup(optarg); - break; - - case 't': - tile_dir = strdup(optarg); - break; - - case 'u': - unpack = 1; - break; - - case 'v': - verbose = 1; - break; - - case 'h': - fprintf(stderr, "Usage: convert_meta [OPTION] ...\n"); - fprintf(stderr, "Convert the rendered PNGs into the more efficient .meta format\n"); - fprintf(stderr, " -m, --map convert tiles in this map (default is 'default')\n"); - fprintf(stderr, " -t, --tile-dir tile cache directory (default is '" RENDERD_TILE_DIR "')\n"); - fprintf(stderr, " -u, --unpack unpack the .meta files back to PNGs\n"); - fprintf(stderr, " -z, --min-zoom only process tiles greater or equal to this zoom level (default is 0)\n"); - fprintf(stderr, " -Z, --max-zoom only process tiles less than or equal to this zoom level (default is %d)\n", MAX_ZOOM); - return -1; - - default: - fprintf(stderr, "unhandled char '%c'\n", c); - break; + break; + + case 'm': + map = strdup(optarg); + break; + + case 't': + tile_dir = strdup(optarg); + break; + + case 'u': + unpack = 1; + break; + + case 'v': + verbose = 1; + break; + + case 'h': + fprintf(stderr, "Usage: convert_meta [OPTION] ...\n"); + fprintf(stderr, "Convert the rendered PNGs into the more efficient .meta format\n"); + fprintf(stderr, " -m, --map convert tiles in this map (default is 'default')\n"); + fprintf(stderr, " -t, --tile-dir tile cache directory (default is '" RENDERD_TILE_DIR "')\n"); + fprintf(stderr, " -u, --unpack unpack the .meta files back to PNGs\n"); + fprintf(stderr, " -z, --min-zoom only process tiles greater or equal to this zoom level (default is 0)\n"); + fprintf(stderr, " -Z, --max-zoom only process tiles less than or equal to this zoom level (default is %d)\n", MAX_ZOOM); + return -1; + + default: + fprintf(stderr, "unhandled char '%c'\n", c); + break; } } diff --git a/src/daemon_compat.c b/src/daemon_compat.c index e6d8ebce..c51458b1 100644 --- a/src/daemon_compat.c +++ b/src/daemon_compat.c @@ -36,8 +36,8 @@ #include #include -#include #include +#include #include #ifdef HAVE_PATHS_H #include @@ -46,8 +46,7 @@ #define _PATH_DEVNULL "/dev/null" #endif -int -daemon(nochdir, noclose) +int daemon(nochdir, noclose) int nochdir, noclose; { struct sigaction osa, sa; @@ -63,14 +62,14 @@ int nochdir, noclose; osa_ok = sigaction(SIGHUP, &sa, &osa); switch (fork()) { - case -1: - return (-1); + case -1: + return (-1); - case 0: - break; + case 0: + break; - default: - exit(0); + default: + exit(0); } newgrp = setsid(); diff --git a/src/g_logger.c b/src/g_logger.c index bd882044..a57c3c9a 100644 --- a/src/g_logger.c +++ b/src/g_logger.c @@ -27,26 +27,26 @@ int foreground = 0; const char *g_logger_level_name(int log_level) { switch (log_level) { - case G_LOG_LEVEL_ERROR: - return "ERROR"; + case G_LOG_LEVEL_ERROR: + return "ERROR"; - case G_LOG_LEVEL_CRITICAL: - return "CRITICAL"; + case G_LOG_LEVEL_CRITICAL: + return "CRITICAL"; - case G_LOG_LEVEL_WARNING: - return "WARNING"; + case G_LOG_LEVEL_WARNING: + return "WARNING"; - case G_LOG_LEVEL_MESSAGE: - return "MESSAGE"; + case G_LOG_LEVEL_MESSAGE: + return "MESSAGE"; - case G_LOG_LEVEL_INFO: - return "INFO"; + case G_LOG_LEVEL_INFO: + return "INFO"; - case G_LOG_LEVEL_DEBUG: - return "DEBUG"; + case G_LOG_LEVEL_DEBUG: + return "DEBUG"; - default: - return "UNKNOWN"; + default: + return "UNKNOWN"; } } @@ -77,61 +77,61 @@ void g_logger(int log_level, const char *format, ...) if (foreground == 1) { switch (log_level) { - // Levels >= G_LOG_LEVEL_ERROR will terminate the program - case G_LOG_LEVEL_ERROR: - g_log_writer_standard_streams(log_level, log_fields, 1, NULL); - break; - - // Levels <= G_LOG_LEVEL_INFO will only show when using G_MESSAGES_DEBUG - case G_LOG_LEVEL_INFO: - g_log_writer_standard_streams(log_level, log_fields, 1, NULL); - break; - - default: - g_log_writer_default(log_level, log_fields, 1, NULL); + // Levels >= G_LOG_LEVEL_ERROR will terminate the program + case G_LOG_LEVEL_ERROR: + g_log_writer_standard_streams(log_level, log_fields, 1, NULL); + break; + + // Levels <= G_LOG_LEVEL_INFO will only show when using G_MESSAGES_DEBUG + case G_LOG_LEVEL_INFO: + g_log_writer_standard_streams(log_level, log_fields, 1, NULL); + break; + + default: + g_log_writer_default(log_level, log_fields, 1, NULL); } } else if (g_log_writer_is_journald(fileno(stderr))) { switch (log_level) { - // Levels >= G_LOG_LEVEL_ERROR will terminate the program - case G_LOG_LEVEL_ERROR: - g_log_writer_journald(log_level, log_fields, 1, NULL); - break; - - // Levels <= G_LOG_LEVEL_INFO will only show when using G_MESSAGES_DEBUG - case G_LOG_LEVEL_INFO: - g_log_writer_journald(log_level, log_fields, 1, NULL); - break; - - default: - g_log_writer_default(log_level, log_fields, 1, NULL); + // Levels >= G_LOG_LEVEL_ERROR will terminate the program + case G_LOG_LEVEL_ERROR: + g_log_writer_journald(log_level, log_fields, 1, NULL); + break; + + // Levels <= G_LOG_LEVEL_INFO will only show when using G_MESSAGES_DEBUG + case G_LOG_LEVEL_INFO: + g_log_writer_journald(log_level, log_fields, 1, NULL); + break; + + default: + g_log_writer_default(log_level, log_fields, 1, NULL); } } else { setlogmask(LOG_UPTO(LOG_INFO)); switch (log_level) { - case G_LOG_LEVEL_ERROR: - syslog(LOG_ERR, log_message_prefixed, NULL); - break; + case G_LOG_LEVEL_ERROR: + syslog(LOG_ERR, log_message_prefixed, NULL); + break; - case G_LOG_LEVEL_CRITICAL: - syslog(LOG_CRIT, log_message_prefixed, NULL); - break; + case G_LOG_LEVEL_CRITICAL: + syslog(LOG_CRIT, log_message_prefixed, NULL); + break; - case G_LOG_LEVEL_WARNING: - syslog(LOG_WARNING, log_message_prefixed, NULL); - break; + case G_LOG_LEVEL_WARNING: + syslog(LOG_WARNING, log_message_prefixed, NULL); + break; - case G_LOG_LEVEL_MESSAGE: - syslog(LOG_INFO, log_message_prefixed, NULL); - break; + case G_LOG_LEVEL_MESSAGE: + syslog(LOG_INFO, log_message_prefixed, NULL); + break; - case G_LOG_LEVEL_INFO: - syslog(LOG_INFO, log_message_prefixed, NULL); - break; + case G_LOG_LEVEL_INFO: + syslog(LOG_INFO, log_message_prefixed, NULL); + break; - case G_LOG_LEVEL_DEBUG: - syslog(LOG_DEBUG, log_message_prefixed, NULL); - break; + case G_LOG_LEVEL_DEBUG: + syslog(LOG_DEBUG, log_message_prefixed, NULL); + break; } } diff --git a/src/gen_tile.cpp b/src/gen_tile.cpp index 855d7c25..a4ffb0cb 100644 --- a/src/gen_tile.cpp +++ b/src/gen_tile.cpp @@ -329,7 +329,7 @@ static enum protoCmd render(Map &m, const char *tile_dir, char *xmlname, project mapnik::image_view vw(128, 128, 256, 256, buf.data()); g_logger(G_LOG_LEVEL_DEBUG, "Render %i %i %i %s", z, x, y, filename) - mapnik::save_to_file(vw, tmp, outputFormat); + mapnik::save_to_file(vw, tmp, outputFormat); if (rename(tmp, filename)) { perror(tmp); diff --git a/src/metatile.cpp b/src/metatile.cpp index 4560da45..77816f44 100644 --- a/src/metatile.cpp +++ b/src/metatile.cpp @@ -28,8 +28,7 @@ #include "render_config.h" #include "store.h" -metaTile::metaTile(const std::string &xmlconfig, const std::string &options, int x, int y, int z): - x_(x), y_(y), z_(z), xmlconfig_(xmlconfig), options_(options) +metaTile::metaTile(const std::string &xmlconfig, const std::string &options, int x, int y, int z) : x_(x), y_(y), z_(z), xmlconfig_(xmlconfig), options_(options) { clear(); } @@ -59,13 +58,13 @@ int metaTile::xyz_to_meta_offset(int x, int y, int z) return (x & mask) * METATILE + (y & mask); } -void metaTile::save(struct storage_backend * store) +void metaTile::save(struct storage_backend *store) { int ox, oy, limit; ssize_t offset; struct meta_layout m; struct entry offsets[METATILE * METATILE]; - char * metatilebuffer; + char *metatilebuffer; char *tmp; memset(&m, 0, sizeof(m)); @@ -88,12 +87,12 @@ void metaTile::save(struct storage_backend * store) for (oy = 0; oy < limit; oy++) { int mt = xyz_to_meta_offset(x_ + ox, y_ + oy, z_); offsets[mt].offset = offset; - offsets[mt].size = tile[ox][oy].size(); + offsets[mt].size = tile[ox][oy].size(); offset += offsets[mt].size; } } - metatilebuffer = (char *) malloc(offset); + metatilebuffer = (char *)malloc(offset); if (metatilebuffer == 0) { g_logger(G_LOG_LEVEL_WARNING, "Failed to write metatile. Out of memory"); @@ -120,7 +119,6 @@ void metaTile::save(struct storage_backend * store) free(metatilebuffer); } - void metaTile::expire_tiles(int sock, const char *host, const char *uri) { if (sock < 0) { diff --git a/src/mod_tile.c b/src/mod_tile.c index d3fc76ed..af813097 100644 --- a/src/mod_tile.c +++ b/src/mod_tile.c @@ -16,63 +16,61 @@ */ #include -#include -#include /* for RLIMIT stuff */ -#include #include #include +#include #include +#include +#include /* for RLIMIT stuff */ #define APR_WANT_STRFUNC #define APR_WANT_MEMFUNC #include -#include #include -#include +#include #include -#include #include -#include -#include #include -#include -#include -#include +#include +#include +#include +#include #include +#include +#include #include +#include module AP_MODULE_DECLARE_DATA tile_module; +#include +#include +#include +#include +#include +#include +#include +#include +#include #include #include #include #include -#include -#include #include -#include #include -#include -#include -#include -#include +#include +#include #include -#include -#include -#include -#include -#include - +#include #include "gen_tile.h" +#include "mod_tile.h" #include "protocol.h" #include "render_config.h" #include "store.h" -#include "mod_tile.h" #include "sys_utils.h" - #if !defined(OS2) && !defined(WIN32) && !defined(BEOS) && !defined(NETWARE) #include "unixd.h" #define MOD_TILE_SET_MUTEX_PERMS /* XXX Apache should define something */ @@ -96,12 +94,12 @@ int layerCount = 0; int global_max_zoom = 0; struct storage_backends { - struct storage_backend ** stores; + struct storage_backend **stores; int noBackends; }; static int error_message(request_rec *r, const char *format, ...) -__attribute__((format(printf, 2, 3))); + __attribute__((format(printf, 2, 3))); static int error_message(request_rec *r, const char *format, ...) { @@ -113,7 +111,7 @@ static int error_message(request_rec *r, const char *format, ...) if (msg) { vsnprintf(msg, 1000, format, ap); - //ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, "%s", msg); + // ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, "%s", msg); ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, r, "%s", msg); r->content_type = "text/plain"; @@ -143,10 +141,10 @@ static int socket_init(request_rec *r) ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "Connecting to renderd on %s:%i via TCP", scfg->renderd_socket_name, scfg->renderd_socket_port); memset(&hints, 0, sizeof(struct addrinfo)); - hints.ai_family = AF_UNSPEC; /* Allow IPv4 or IPv6 */ + hints.ai_family = AF_UNSPEC; /* Allow IPv4 or IPv6 */ hints.ai_socktype = SOCK_STREAM; /* TCP socket */ hints.ai_flags = 0; - hints.ai_protocol = 0; /* Any protocol */ + hints.ai_protocol = 0; /* Any protocol */ hints.ai_canonname = NULL; hints.ai_addr = NULL; hints.ai_next = NULL; @@ -163,17 +161,17 @@ static int socket_init(request_rec *r) Try each address until we successfully connect. */ for (rp = result; rp != NULL; rp = rp->ai_next) { switch (rp->ai_family) { - case AF_INET: - inet_ntop(AF_INET, &(((struct sockaddr_in *)rp->ai_addr)->sin_addr), ipstring, rp->ai_addrlen); - break; + case AF_INET: + inet_ntop(AF_INET, &(((struct sockaddr_in *)rp->ai_addr)->sin_addr), ipstring, rp->ai_addrlen); + break; - case AF_INET6: - inet_ntop(AF_INET6, &(((struct sockaddr_in6 *)rp->ai_addr)->sin6_addr), ipstring, rp->ai_addrlen); - break; + case AF_INET6: + inet_ntop(AF_INET6, &(((struct sockaddr_in6 *)rp->ai_addr)->sin6_addr), ipstring, rp->ai_addrlen); + break; - default: - snprintf(ipstring, sizeof(ipstring), "address family %d", rp->ai_family); - break; + default: + snprintf(ipstring, sizeof(ipstring), "address family %d", rp->ai_family); + break; } ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "Connecting TCP socket to rendering daemon at %s", ipstring); @@ -215,7 +213,7 @@ static int socket_init(request_rec *r) addr.sun_family = AF_UNIX; strncpy(addr.sun_path, scfg->renderd_socket_name, sizeof(addr.sun_path) - sizeof(char)); - if (connect(fd, (struct sockaddr *) &addr, sizeof(addr)) < 0) { + if (connect(fd, (struct sockaddr *)&addr, sizeof(addr)) < 0) { ap_log_rerror(APLOG_MARK, APLOG_WARNING, 0, r, "socket connect failed for: %s with reason: %s", scfg->renderd_socket_name, strerror(errno)); close(fd); return FD_INVALID; @@ -244,25 +242,25 @@ static int request_tile(request_rec *r, struct protocol *cmd, int renderImmediat // cmd has already been partial filled, fill in the rest switch (renderImmediately) { - case 0: { - cmd->cmd = cmdDirty; - break; - } + case 0: { + cmd->cmd = cmdDirty; + break; + } - case 1: { - cmd->cmd = cmdRenderLow; - break; - } + case 1: { + cmd->cmd = cmdRenderLow; + break; + } - case 2: { - cmd->cmd = cmdRender; - break; - } + case 2: { + cmd->cmd = cmdRender; + break; + } - case 3: { - cmd->cmd = cmdRenderPrio; - break; - } + case 3: { + cmd->cmd = cmdRenderPrio; + break; + } } if (scfg->bulkMode) { @@ -273,13 +271,13 @@ static int request_tile(request_rec *r, struct protocol *cmd, int renderImmediat do { switch (cmd->ver) { - case 2: - ret = send(fd, cmd, sizeof(struct protocol_v2), 0); - break; + case 2: + ret = send(fd, cmd, sizeof(struct protocol_v2), 0); + break; - case 3: - ret = send(fd, cmd, sizeof(struct protocol), 0); - break; + case 3: + ret = send(fd, cmd, sizeof(struct protocol), 0); + break; } if ((ret == sizeof(struct protocol_v2)) || (ret == sizeof(struct protocol))) { @@ -319,12 +317,12 @@ static int request_tile(request_rec *r, struct protocol *cmd, int renderImmediat if (ret != sizeof(struct protocol_v2)) { ap_log_rerror(APLOG_MARK, APLOG_WARNING, 0, r, "request_tile: Failed to read response from rendering socket. Got %d bytes but expected %d. Errno %d (%s)", - ret, (int) sizeof(struct protocol_v2), errno, strerror(errno)); + ret, (int)sizeof(struct protocol_v2), errno, strerror(errno)); break; } if (resp.ver == 3) { - ret += recv(fd, ((void*)&resp) + sizeof(struct protocol_v2), sizeof(struct protocol) - sizeof(struct protocol_v2), 0); + ret += recv(fd, ((void *)&resp) + sizeof(struct protocol_v2), sizeof(struct protocol) - sizeof(struct protocol_v2), 0); } if (cmd->x == resp.x && cmd->y == resp.y && cmd->z == resp.z && !strcmp(cmd->xmlname, resp.xmlname)) { @@ -360,9 +358,9 @@ static int request_tile(request_rec *r, struct protocol *cmd, int renderImmediat return 0; } -static apr_status_t cleanup_storage_backend(void * data) +static apr_status_t cleanup_storage_backend(void *data) { - struct storage_backends * stores = (struct storage_backends *)data; + struct storage_backends *stores = (struct storage_backends *)data; int i; for (i = 0; i < stores->noBackends; i++) { @@ -374,27 +372,27 @@ static apr_status_t cleanup_storage_backend(void * data) return APR_SUCCESS; } -static struct storage_backend * get_storage_backend(request_rec *r, int tile_layer) +static struct storage_backend *get_storage_backend(request_rec *r, int tile_layer) { - struct storage_backends * stores = NULL; + struct storage_backends *stores = NULL; ap_conf_vector_t *sconf = r->server->module_config; tile_server_conf *scfg = ap_get_module_config(sconf, &tile_module); - tile_config_rec *tile_configs = (tile_config_rec *) scfg->configs->elts; + tile_config_rec *tile_configs = (tile_config_rec *)scfg->configs->elts; tile_config_rec *tile_config = &tile_configs[tile_layer]; - apr_thread_t * current_thread = r->connection->current_thread; + apr_thread_t *current_thread = r->connection->current_thread; apr_pool_t *lifecycle_pool = apr_thread_pool_get(current_thread); - char * memkey = apr_psprintf(r->pool, "mod_tile_storage_backends"); + char *memkey = apr_psprintf(r->pool, "mod_tile_storage_backends"); apr_os_thread_t os_thread = apr_os_thread_current(); ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "get_storage_backend: Retrieving storage back end for tile layer %i in pool %pp and thread %li", - tile_layer, lifecycle_pool, (unsigned long) os_thread); + tile_layer, lifecycle_pool, (unsigned long)os_thread); if (apr_pool_userdata_get((void **)&stores, memkey, lifecycle_pool) != APR_SUCCESS) { ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, r, "get_storage_backend: Failed horribly!"); } if (stores == NULL) { - ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "get_storage_backend: No storage backends for this lifecycle %pp, creating it in thread %li", lifecycle_pool, (unsigned long) os_thread); + ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "get_storage_backend: No storage backends for this lifecycle %pp, creating it in thread %li", lifecycle_pool, (unsigned long)os_thread); stores = apr_pcalloc(lifecycle_pool, sizeof(struct storage_backends)); stores->stores = apr_pcalloc(lifecycle_pool, sizeof(struct storage_backend *) * scfg->configs->nelts); stores->noBackends = scfg->configs->nelts; @@ -403,16 +401,16 @@ static struct storage_backend * get_storage_backend(request_rec *r, int tile_lay ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, "get_storage_backend: Failed horribly to set user_data!"); } } else { - ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "get_storage_backend: Found backends (%pp) for this lifecycle %pp in thread %li", stores, lifecycle_pool, (unsigned long) os_thread); + ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "get_storage_backend: Found backends (%pp) for this lifecycle %pp in thread %li", stores, lifecycle_pool, (unsigned long)os_thread); } if (stores->stores[tile_layer] == NULL) { ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "get_storage_backend: No storage backend in current lifecycle %pp in thread %li for current tile layer %i", - lifecycle_pool, (unsigned long) os_thread, tile_layer); + lifecycle_pool, (unsigned long)os_thread, tile_layer); stores->stores[tile_layer] = init_storage_backend(tile_config->store); } else { ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "get_storage_backend: Storage backend found in current lifecycle %pp for current tile layer %i in thread %li", - lifecycle_pool, tile_layer, (unsigned long) os_thread); + lifecycle_pool, tile_layer, (unsigned long)os_thread); } return stores->stores[tile_layer]; @@ -424,7 +422,7 @@ static enum tileState tile_state(request_rec *r, struct protocol *cmd) tile_server_conf *scfg = ap_get_module_config(sconf, &tile_module); struct stat_info stat; - struct tile_request_data * rdata = (struct tile_request_data *)ap_get_module_config(r->request_config, &tile_module); + struct tile_request_data *rdata = (struct tile_request_data *)ap_get_module_config(r->request_config, &tile_module); stat = rdata->store->tile_stat(rdata->store, cmd->xmlname, cmd->options, cmd->x, cmd->y, cmd->z); @@ -454,10 +452,10 @@ static enum tileState tile_state(request_rec *r, struct protocol *cmd) * Add CORS ( Cross-origin resource sharing ) headers. http://www.w3.org/TR/cors/ * CORS allows requests that would otherwise be forbidden under the same origin policy. */ -static int add_cors(request_rec *r, const char * cors) +static int add_cors(request_rec *r, const char *cors) { - const char* headers; - const char* origin = apr_table_get(r->headers_in, "Origin"); + const char *headers; + const char *origin = apr_table_get(r->headers_in, "Origin"); ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "Checking if CORS headers need to be added: Origin: %s Policy: %s", origin, cors); if (!origin) { @@ -474,11 +472,10 @@ static int add_cors(request_rec *r, const char * cors) apr_psprintf(r->pool, "%s", origin)); apr_table_setn(r->headers_out, "Vary", apr_psprintf(r->pool, "%s", "Origin")); - } if (strcmp(r->method, "OPTIONS") == 0 && - apr_table_get(r->headers_in, "Access-Control-Request-Method")) { + apr_table_get(r->headers_in, "Access-Control-Request-Method")) { headers = apr_table_get(r->headers_in, "Access-Control-Request-Headers"); if (headers) { @@ -499,7 +496,7 @@ static int add_cors(request_rec *r, const char * cors) } } -static void add_expiry(request_rec *r, struct protocol * cmd) +static void add_expiry(request_rec *r, struct protocol *cmd) { apr_time_t holdoff; apr_table_t *t = r->headers_out; @@ -510,8 +507,8 @@ static void add_expiry(request_rec *r, struct protocol * cmd) ap_conf_vector_t *sconf = r->server->module_config; tile_server_conf *scfg = ap_get_module_config(sconf, &tile_module); - struct tile_request_data * rdata = (struct tile_request_data *)ap_get_module_config(r->request_config, &tile_module); - tile_config_rec *tile_configs = (tile_config_rec *) scfg->configs->elts; + struct tile_request_data *rdata = (struct tile_request_data *)ap_get_module_config(r->request_config, &tile_module); + tile_config_rec *tile_configs = (tile_config_rec *)scfg->configs->elts; tile_config_rec *tile_config = &tile_configs[rdata->layerNumber]; ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "expires(%s), uri(%s),, path_info(%s)\n", @@ -519,14 +516,13 @@ static void add_expiry(request_rec *r, struct protocol * cmd) /* If the hostname matches the "extended caching hostname" then set the cache age accordingly */ if ((scfg->cache_extended_hostname[0] != 0) && (strstr(r->hostname, - scfg->cache_extended_hostname) != NULL)) { + scfg->cache_extended_hostname) != NULL)) { maxAge = scfg->cache_extended_duration; } else { /* Test if the tile we are serving is out of date, then set a low maxAge*/ if (state == tileOld) { - holdoff = (scfg->cache_duration_dirty / 2.0) * (rand() / (RAND_MAX - + 1.0)); + holdoff = (scfg->cache_duration_dirty / 2.0) * (rand() / (RAND_MAX + 1.0)); maxAge = scfg->cache_duration_dirty + holdoff; } else { // cache heuristic based on zoom level @@ -539,27 +535,25 @@ static void add_expiry(request_rec *r, struct protocol * cmd) } // Time to the next known complete rerender - //planetTimestamp = apr_time_sec(getPlanetTime(r) + // planetTimestamp = apr_time_sec(getPlanetTime(r) // + apr_time_from_sec(PLANET_INTERVAL) - r->request_time); // Time since the last render of this tile - lastModified = (int)(((double) apr_time_sec(r->request_time - - finfo->mtime)) - * scfg->cache_duration_last_modified_factor); + lastModified = (int)(((double)apr_time_sec(r->request_time - finfo->mtime)) * scfg->cache_duration_last_modified_factor); // Add a random jitter of 3 hours to space out cache expiry holdoff = (3 * 60 * 60) * (rand() / (RAND_MAX + 1.0)); - //maxAge = MAX(minCache, planetTimestamp); + // maxAge = MAX(minCache, planetTimestamp); maxAge = minCache; maxAge = MAX(maxAge, lastModified); maxAge += holdoff; ap_log_rerror( - APLOG_MARK, - APLOG_DEBUG, - 0, - r, - "caching heuristics: zoom level based %ld; last modified %ld\n", - minCache, lastModified); + APLOG_MARK, + APLOG_DEBUG, + 0, + r, + "caching heuristics: zoom level based %ld; last modified %ld\n", + minCache, lastModified); } maxAge = MIN(maxAge, scfg->cache_duration_max); @@ -574,9 +568,7 @@ static void add_expiry(request_rec *r, struct protocol * cmd) apr_table_setn(t, "Expires", timestr); } - - -static int get_global_lock(request_rec *r, apr_global_mutex_t * mutex) +static int get_global_lock(request_rec *r, apr_global_mutex_t *mutex) { apr_status_t rs; int camped; @@ -608,7 +600,7 @@ static int get_global_lock(request_rec *r, apr_global_mutex_t * mutex) return 0; } -static int incRespCounter(int resp, request_rec *r, struct protocol * cmd, int layerNumber) +static int incRespCounter(int resp, request_rec *r, struct protocol *cmd, int layerNumber) { stats_data *stats; @@ -628,48 +620,47 @@ static int incRespCounter(int resp, request_rec *r, struct protocol * cmd, int l stats = (stats_data *)apr_shm_baseaddr_get(stats_shm); switch (resp) { - case OK: { - stats->noResp200++; + case OK: { + stats->noResp200++; - if (cmd != NULL) { - stats->noRespZoom[cmd->z]++; - stats->noResp200Layer[layerNumber]++; - } - - break; + if (cmd != NULL) { + stats->noRespZoom[cmd->z]++; + stats->noResp200Layer[layerNumber]++; } - case HTTP_NOT_MODIFIED: { - stats->noResp304++; + break; + } - if (cmd != NULL) { - stats->noRespZoom[cmd->z]++; - stats->noResp200Layer[layerNumber]++; - } + case HTTP_NOT_MODIFIED: { + stats->noResp304++; - break; + if (cmd != NULL) { + stats->noRespZoom[cmd->z]++; + stats->noResp200Layer[layerNumber]++; } - case HTTP_NOT_FOUND: { - stats->noResp404++; - stats->noResp404Layer[layerNumber]++; - break; - } + break; + } - case HTTP_SERVICE_UNAVAILABLE: { - stats->noResp503++; - break; - } + case HTTP_NOT_FOUND: { + stats->noResp404++; + stats->noResp404Layer[layerNumber]++; + break; + } - case HTTP_INTERNAL_SERVER_ERROR: { - stats->noResp5XX++; - break; - } + case HTTP_SERVICE_UNAVAILABLE: { + stats->noResp503++; + break; + } - default: { - stats->noRespOther++; - } + case HTTP_INTERNAL_SERVER_ERROR: { + stats->noResp5XX++; + break; + } + default: { + stats->noRespOther++; + } } apr_global_mutex_unlock(stats_mutex); @@ -702,36 +693,35 @@ static int incFreshCounter(int status, request_rec *r) stats = (stats_data *)apr_shm_baseaddr_get(stats_shm); switch (status) { - case FRESH: { - stats->noFreshCache++; - break; - } - - case FRESH_RENDER: { - stats->noFreshRender++; - break; - } + case FRESH: { + stats->noFreshCache++; + break; + } - case OLD: { - stats->noOldCache++; - break; - } + case FRESH_RENDER: { + stats->noFreshRender++; + break; + } - case VERYOLD: { - stats->noVeryOldCache++; - break; - } + case OLD: { + stats->noOldCache++; + break; + } - case OLD_RENDER: { - stats->noOldRender++; - break; - } + case VERYOLD: { + stats->noVeryOldCache++; + break; + } - case VERYOLD_RENDER: { - stats->noVeryOldRender++; - break; - } + case OLD_RENDER: { + stats->noOldRender++; + break; + } + case VERYOLD_RENDER: { + stats->noVeryOldRender++; + break; + } } apr_global_mutex_unlock(stats_mutex); @@ -778,12 +768,12 @@ static int incTimingCounter(apr_uint64_t duration, int z, request_rec *r) static int delay_allowed(request_rec *r, enum tileState state) { - delaypool * delayp; + delaypool *delayp; int delay = 0; int i, j; - char * strtok_state; - char * tmp; - const char * ip_addr = NULL; + char *strtok_state; + char *tmp; + const char *ip_addr = NULL; apr_time_t now; int tiles_topup; int render_topup; @@ -797,18 +787,18 @@ static int delay_allowed(request_rec *r, enum tileState state) ip_addr = r->useragent_ip; if (scfg->enableTileThrottlingXForward) { - char * ip_addrs = apr_pstrdup(r->pool, apr_table_get(r->headers_in, "X-Forwarded-For")); + char *ip_addrs = apr_pstrdup(r->pool, apr_table_get(r->headers_in, "X-Forwarded-For")); if (ip_addrs) { ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "Checking throttling delays: Found X-Forwarded-For header \"%s\", forwarded by %s", ip_addrs, r->connection->client_ip); - //X-Forwarded-For can be a chain of proxies deliminated by , The first entry in the list is the client, the last entry is the remote address seen by the proxy - //closest to the tileserver. + // X-Forwarded-For can be a chain of proxies deliminated by , The first entry in the list is the client, the last entry is the remote address seen by the proxy + // closest to the tileserver. strtok_state = NULL; tmp = apr_strtok(ip_addrs, ", ", &strtok_state); ip_addr = tmp; - //Use the last entry in the chain of X-Forwarded-For instead of the client, i.e. the entry added by the proxy closest to the tileserver - //If this is a reverse proxy under our control, its X-Forwarded-For can be trusted. + // Use the last entry in the chain of X-Forwarded-For instead of the client, i.e. the entry added by the proxy closest to the tileserver + // If this is a reverse proxy under our control, its X-Forwarded-For can be trusted. if (scfg->enableTileThrottlingXForward == 2) { while ((tmp = apr_strtok(NULL, ", ", &strtok_state)) != NULL) { ip_addr = tmp; @@ -819,9 +809,8 @@ static int delay_allowed(request_rec *r, enum tileState state) } } - if (inet_pton(AF_INET, ip_addr, &sin_addr) > 0) { - //ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "Checking delays: for IP %s appears to be an IPv4 address", ip_addr); + // ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "Checking delays: for IP %s appears to be an IPv4 address", ip_addr); memset(ip.s6_addr, 0, 16); memcpy(&(ip.s6_addr[12]), &(sin_addr.s_addr), 4); hashkey = sin_addr.s_addr % DELAY_HASHTABLE_WHITELIST_SIZE; @@ -853,7 +842,7 @@ static int delay_allowed(request_rec *r, enum tileState state) /* Repeat the process to determine if we have tockens in the bucket, as the fillup only runs once a client hits an empty bucket, so in the mean time, the bucket might have been filled */ for (j = 0; j < 3; j++) { - //ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "Checking delays: Current poolsize: %i tiles and %i renders\n", delayp->users[hashkey].available_tiles, delayp->users[hashkey].available_render_req); + // ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "Checking delays: Current poolsize: %i tiles and %i renders\n", delayp->users[hashkey].available_tiles, delayp->users[hashkey].available_render_req); delay = 0; if (delayp->users[hashkey].available_tiles > 0) { @@ -888,7 +877,7 @@ static int delay_allowed(request_rec *r, enum tileState state) tiles_topup = (now - delayp->last_tile_fillup) / scfg->delaypoolTileRate; render_topup = (now - delayp->last_render_fillup) / scfg->delaypoolRenderRate; - //ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "Filling up pools with %i tiles and %i renders\n", tiles_topup, render_topup); + // ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "Filling up pools with %i tiles and %i renders\n", tiles_topup, render_topup); if ((tiles_topup > 0) || (render_topup > 0)) { delayp->locked = 1; @@ -937,8 +926,8 @@ static int tile_handler_dirty(request_rec *r) { ap_conf_vector_t *sconf; tile_server_conf *scfg; - struct tile_request_data * rdata; - struct protocol * cmd; + struct tile_request_data *rdata; + struct protocol *cmd; if (strcmp(r->handler, "tile_dirty")) { return DECLINED; @@ -970,14 +959,14 @@ static int tile_handler_dirty(request_rec *r) static int tile_storage_hook(request_rec *r) { -// char abs_path[PATH_MAX]; + // char abs_path[PATH_MAX]; double avg; int renderPrio = 0; enum tileState state; ap_conf_vector_t *sconf; tile_server_conf *scfg; - struct tile_request_data * rdata; - struct protocol * cmd; + struct tile_request_data *rdata; + struct protocol *cmd; if (!r->handler) { return DECLINED; @@ -987,8 +976,7 @@ static int tile_storage_hook(request_rec *r) r->handler, r->uri); // Any status request is OK. tile_dirty also doesn't need to be handled, as tile_handler_dirty will take care of it - if (!strcmp(r->handler, "tile_status") || !strcmp(r->handler, "tile_dirty") || !strcmp(r->handler, "tile_mod_stats") - || !(strcmp(r->handler, "tile_json"))) { + if (!strcmp(r->handler, "tile_status") || !strcmp(r->handler, "tile_dirty") || !strcmp(r->handler, "tile_mod_stats") || !(strcmp(r->handler, "tile_json"))) { return OK; } @@ -1019,54 +1007,54 @@ static int tile_storage_hook(request_rec *r) } switch (state) { - case tileCurrent: - if (!incFreshCounter(FRESH, r)) { + case tileCurrent: + if (!incFreshCounter(FRESH, r)) { + ap_log_rerror(APLOG_MARK, APLOG_WARNING, 0, r, + "Failed to increase fresh stats counter"); + } + + return OK; + break; + + case tileOld: + case tileVeryOld: + if (scfg->bulkMode) { + return OK; + } else if (avg > scfg->max_load_old) { + // Too much load to render it now, mark dirty but return old tile + request_tile(r, cmd, 0); + ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "Load (%f) greater than max_load_old (%d). Mark dirty and deliver from cache.", avg, scfg->max_load_old); + + if (!incFreshCounter((state == tileVeryOld) ? VERYOLD : OLD, r)) { ap_log_rerror(APLOG_MARK, APLOG_WARNING, 0, r, "Failed to increase fresh stats counter"); } return OK; - break; + } - case tileOld: - case tileVeryOld: - if (scfg->bulkMode) { - return OK; - } else if (avg > scfg->max_load_old) { - // Too much load to render it now, mark dirty but return old tile - request_tile(r, cmd, 0); - ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "Load (%f) greater than max_load_old (%d). Mark dirty and deliver from cache.", avg, scfg->max_load_old); + renderPrio = (state == tileVeryOld) ? 2 : 1; + break; - if (!incFreshCounter((state == tileVeryOld) ? VERYOLD : OLD, r)) { - ap_log_rerror(APLOG_MARK, APLOG_WARNING, 0, r, - "Failed to increase fresh stats counter"); - } + case tileMissing: + if (avg > scfg->max_load_missing) { + request_tile(r, cmd, 0); + ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, r, "Load (%f) greater than max_load_missing (%d). Return HTTP_NOT_FOUND.", avg, scfg->max_load_missing); - return OK; + if (!incRespCounter(HTTP_NOT_FOUND, r, cmd, rdata->layerNumber)) { + ap_log_rerror(APLOG_MARK, APLOG_WARNING, 0, r, + "Failed to increase response stats counter"); } - renderPrio = (state == tileVeryOld) ? 2 : 1; - break; - - case tileMissing: - if (avg > scfg->max_load_missing) { - request_tile(r, cmd, 0); - ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, r, "Load (%f) greater than max_load_missing (%d). Return HTTP_NOT_FOUND.", avg, scfg->max_load_missing); - - if (!incRespCounter(HTTP_NOT_FOUND, r, cmd, rdata->layerNumber)) { - ap_log_rerror(APLOG_MARK, APLOG_WARNING, 0, r, - "Failed to increase response stats counter"); - } - - return HTTP_NOT_FOUND; - } + return HTTP_NOT_FOUND; + } - renderPrio = 3; - break; + renderPrio = 3; + break; } if (request_tile(r, cmd, renderPrio)) { - //TODO: update finfo + // TODO: update finfo if (!incFreshCounter(FRESH_RENDER, r)) { ap_log_rerror(APLOG_MARK, APLOG_WARNING, 0, r, "Failed to increase fresh stats counter"); @@ -1111,8 +1099,8 @@ static int tile_handler_status(request_rec *r) char mtime_str[APR_CTIME_LEN]; char atime_str[APR_CTIME_LEN]; char storage_id[PATH_MAX]; - struct tile_request_data * rdata; - struct protocol * cmd; + struct tile_request_data *rdata; + struct protocol *cmd; if (strcmp(r->handler, "tile_status")) { return DECLINED; @@ -1145,8 +1133,8 @@ static int tile_handler_status(request_rec *r) apr_ctime(atime_str, r->finfo.atime); return error_message(r, "Tile is %s. Last rendered at %s. Last accessed at %s. Stored in %s\n\n" - "(Dates might not be accurate. Rendering time might be reset to an old date for tile expiry." - " Access times might not be updated on all file systems)\n", + "(Dates might not be accurate. Rendering time might be reset to an old date for tile expiry." + " Access times might not be updated on all file systems)\n", (state == tileOld) ? "due to be rendered" : "clean", mtime_str, atime_str, rdata->store->tile_storage_id(rdata->store, cmd->xmlname, cmd->options, cmd->x, cmd->y, cmd->z, storage_id)); } @@ -1164,7 +1152,7 @@ static int tile_handler_json(request_rec *r) apr_table_t *t = r->headers_out; int i; char *md5; - struct tile_request_data * rdata; + struct tile_request_data *rdata; ap_conf_vector_t *sconf; tile_server_conf *scfg; tile_config_rec *tile_configs; @@ -1179,7 +1167,7 @@ static int tile_handler_json(request_rec *r) rdata = (struct tile_request_data *)ap_get_module_config(r->request_config, &tile_module); sconf = r->server->module_config; scfg = ap_get_module_config(sconf, &tile_module); - tile_configs = (tile_config_rec *) scfg->configs->elts; + tile_configs = (tile_config_rec *)scfg->configs->elts; tile_config = &tile_configs[rdata->layerNumber]; ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "Handling tile json request for layer %s\n", tile_config->xmlname); @@ -1244,7 +1232,7 @@ static int tile_handler_json(request_rec *r) static int tile_handler_mod_stats(request_rec *r) { - stats_data * stats; + stats_data *stats; stats_data local_stats; int i; ap_conf_vector_t *sconf; @@ -1257,17 +1245,17 @@ static int tile_handler_mod_stats(request_rec *r) sconf = r->server->module_config; scfg = ap_get_module_config(sconf, &tile_module); - tile_configs = (tile_config_rec *) scfg->configs->elts; + tile_configs = (tile_config_rec *)scfg->configs->elts; if (!scfg->enableGlobalStats) { return error_message(r, "Stats are not enabled for this server"); } if (get_global_lock(r, stats_mutex) != 0) { - //Copy over the global counter variable into - //local variables, that we can immediately - //release the lock again - stats = (stats_data *) apr_shm_baseaddr_get(stats_shm); + // Copy over the global counter variable into + // local variables, that we can immediately + // release the lock again + stats = (stats_data *)apr_shm_baseaddr_get(stats_shm); memcpy(&local_stats, stats, sizeof(stats_data)); local_stats.noResp200Layer = malloc(sizeof(apr_uint64_t) * scfg->configs->nelts); memcpy(local_stats.noResp200Layer, stats->noResp200Layer, sizeof(apr_uint64_t) * scfg->configs->nelts); @@ -1316,7 +1304,7 @@ static int tile_handler_mod_stats(request_rec *r) static int tile_handler_metrics(request_rec *r) { - stats_data * stats; + stats_data *stats; stats_data local_stats; int i; ap_conf_vector_t *sconf; @@ -1329,17 +1317,17 @@ static int tile_handler_metrics(request_rec *r) sconf = r->server->module_config; scfg = ap_get_module_config(sconf, &tile_module); - tile_configs = (tile_config_rec *) scfg->configs->elts; + tile_configs = (tile_config_rec *)scfg->configs->elts; if (!scfg->enableGlobalStats) { return error_message(r, "Stats are not enabled for this server"); } if (get_global_lock(r, stats_mutex) != 0) { - //Copy over the global counter variable into - //local variables, that we can immediately - //release the lock again - stats = (stats_data *) apr_shm_baseaddr_get(stats_shm); + // Copy over the global counter variable into + // local variables, that we can immediately + // release the lock again + stats = (stats_data *)apr_shm_baseaddr_get(stats_shm); memcpy(&local_stats, stats, sizeof(stats_data)); local_stats.noResp200Layer = malloc(sizeof(apr_uint64_t) * scfg->configs->nelts); memcpy(local_stats.noResp200Layer, stats->noResp200Layer, sizeof(apr_uint64_t) * scfg->configs->nelts); @@ -1375,7 +1363,6 @@ static int tile_handler_metrics(request_rec *r) ap_rprintf(r, "modtile_zoom_responses_total{zoom=\"%02i\"} %" APR_UINT64_T_FMT "\n", i, local_stats.noRespZoom[i]); } - ap_rprintf(r, "# HELP modtile_tile_reads_total Tiles served from the tile buffer\n"); ap_rprintf(r, "# TYPE modtile_tile_reads_total counter\n"); @@ -1416,8 +1403,8 @@ static int tile_handler_serve(request_rec *r) struct timeval start, end; char *md5; tile_config_rec *tile_configs; - struct tile_request_data * rdata; - struct protocol * cmd; + struct tile_request_data *rdata; + struct protocol *cmd; ap_conf_vector_t *sconf = r->server->module_config; tile_server_conf *scfg = ap_get_module_config(sconf, &tile_module); @@ -1442,7 +1429,7 @@ static int tile_handler_serve(request_rec *r) ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "tile_handler_serve: xml(%s) z(%d) x(%d) y(%d)", cmd->xmlname, cmd->z, cmd->x, cmd->y); - tile_configs = (tile_config_rec *) scfg->configs->elts; + tile_configs = (tile_config_rec *)scfg->configs->elts; if (tile_configs[rdata->layerNumber].cors) { int resp = add_cors(r, tile_configs[rdata->layerNumber].cors); @@ -1474,14 +1461,14 @@ static int tile_handler_serve(request_rec *r) if (len > 0) { if (compressed) { - const char* accept_encoding = apr_table_get(r->headers_in, "Accept-Encoding"); + const char *accept_encoding = apr_table_get(r->headers_in, "Accept-Encoding"); if (accept_encoding && strstr(accept_encoding, "gzip")) { r->content_encoding = "gzip"; } else { ap_log_rerror(APLOG_MARK, APLOG_WARNING, 0, r, "Tile data is compressed, but user agent doesn't support Content-Encoding and we don't know how to decompress it server side"); - //TODO: decompress the output stream before sending it to client + // TODO: decompress the output stream before sending it to client } } @@ -1547,7 +1534,7 @@ static int tile_translate(request_rec *r) ap_conf_vector_t *sconf = r->server->module_config; tile_server_conf *scfg = ap_get_module_config(sconf, &tile_module); - tile_config_rec *tile_configs = (tile_config_rec *) scfg->configs->elts; + tile_config_rec *tile_configs = (tile_config_rec *)scfg->configs->elts; ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "tile_translate: uri(%s)", r->uri); @@ -1579,11 +1566,10 @@ static int tile_translate(request_rec *r) ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "tile_translate: testing baseuri(%s) name(%s) extension(%s)", tile_config->baseuri, tile_config->xmlname, tile_config->fileExtension); - if (!strncmp(tile_config->baseuri, r->uri, strlen(tile_config->baseuri))) { - struct tile_request_data * rdata = (struct tile_request_data *) apr_pcalloc(r->pool, sizeof(struct tile_request_data)); - struct protocol * cmd = (struct protocol *) apr_pcalloc(r->pool, sizeof(struct protocol)); + struct tile_request_data *rdata = (struct tile_request_data *)apr_pcalloc(r->pool, sizeof(struct tile_request_data)); + struct protocol *cmd = (struct protocol *)apr_pcalloc(r->pool, sizeof(struct protocol)); bzero(cmd, sizeof(struct protocol)); bzero(rdata, sizeof(struct tile_request_data)); @@ -1635,8 +1621,8 @@ static int tile_translate(request_rec *r) if (oob) { ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "tile_translate: request for %s was outside of allowed bounds", tile_config->xmlname); sleep(CLIENT_PENALTY); - //Don't increase stats counter here, - //As we are interested in valid tiles only + // Don't increase stats counter here, + // As we are interested in valid tiles only return HTTP_NOT_FOUND; } @@ -1711,7 +1697,7 @@ static int mod_tile_post_config(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_userdata_get(&data, userdata_key, s->process->pool); if (!data) { - apr_pool_userdata_set((const void *) 1, userdata_key, + apr_pool_userdata_set((const void *)1, userdata_key, apr_pool_cleanup_null, s->process->pool); return OK; } /* Kilroy was here */ @@ -1731,7 +1717,7 @@ static int mod_tile_post_config(apr_pool_t *pconf, apr_pool_t *plog, * not seem to be set at this stage, so rely on previously set layerCount */ rs = apr_shm_create(&stats_shm, sizeof(stats_data) + layerCount * 2 * sizeof(apr_uint64_t), - (const char *) shmfilename, pconf); + (const char *)shmfilename, pconf); if (rs != APR_SUCCESS) { ap_log_error(APLOG_MARK, APLOG_ERR, rs, s, @@ -1741,7 +1727,7 @@ static int mod_tile_post_config(apr_pool_t *pconf, apr_pool_t *plog, } rs = apr_shm_create(&delaypool_shm, sizeof(delaypool), - (const char *) shmfilename_delaypool, pconf); + (const char *)shmfilename_delaypool, pconf); if (rs != APR_SUCCESS) { ap_log_error(APLOG_MARK, APLOG_ERR, rs, s, @@ -1780,8 +1766,8 @@ static int mod_tile_post_config(apr_pool_t *pconf, apr_pool_t *plog, * followed by two arrays with one element each per layer. All of this sits * in one shared memory block, and for ease of use, pointers from inside the * struct point to the arrays. */ - stats->noResp404Layer = (apr_uint64_t *)((char *) stats + sizeof(stats_data)); - stats->noResp200Layer = (apr_uint64_t *)((char *) stats + sizeof(stats_data) + sizeof(apr_uint64_t) * layerCount); + stats->noResp404Layer = (apr_uint64_t *)((char *)stats + sizeof(stats_data)); + stats->noResp200Layer = (apr_uint64_t *)((char *)stats + sizeof(stats_data) + sizeof(apr_uint64_t) * layerCount); /* zero out all the non-fixed-length stuff */ for (i = 0; i < layerCount; i++) { @@ -1806,7 +1792,6 @@ static int mod_tile_post_config(apr_pool_t *pconf, apr_pool_t *plog, /* TODO: need a way to initialise the delaypool whitelist */ - /* Create global mutex */ /* @@ -1815,9 +1800,9 @@ static int mod_tile_post_config(apr_pool_t *pconf, apr_pool_t *plog, * may or may not be actually created. */ mutexfilename = apr_psprintf(pconf, "/tmp/httpd_mutex.%ld", - (long int) getpid()); + (long int)getpid()); - rs = apr_global_mutex_create(&stats_mutex, (const char *) mutexfilename, + rs = apr_global_mutex_create(&stats_mutex, (const char *)mutexfilename, APR_LOCK_DEFAULT, pconf); if (rs != APR_SUCCESS) { @@ -1845,9 +1830,9 @@ static int mod_tile_post_config(apr_pool_t *pconf, apr_pool_t *plog, * may or may not be actually created. */ mutexfilename = apr_psprintf(pconf, "/tmp/httpd_mutex_delay.%ld", - (long int) getpid()); + (long int)getpid()); - rs = apr_global_mutex_create(&delay_mutex, (const char *) mutexfilename, + rs = apr_global_mutex_create(&delay_mutex, (const char *)mutexfilename, APR_LOCK_DEFAULT, pconf); if (rs != APR_SUCCESS) { @@ -1872,7 +1857,6 @@ static int mod_tile_post_config(apr_pool_t *pconf, apr_pool_t *plog, return OK; } - /* * This routine gets called when a child inits. We use it to attach * to the shared memory segment, and reinitialize the mutex and setup @@ -1891,7 +1875,7 @@ static void mod_tile_child_init(apr_pool_t *p, server_rec *s) * the mutex pointer global here. */ rs = apr_global_mutex_child_init(&stats_mutex, - (const char *) mutexfilename, + (const char *)mutexfilename, p); if (rs != APR_SUCCESS) { @@ -1920,8 +1904,8 @@ static void register_hooks(__attribute__((unused)) apr_pool_t *p) static const char *_add_tile_config(cmd_parms *cmd, void *mconfig, const char *baseuri, const char *name, int minzoom, int maxzoom, int aspect_x, int aspect_y, - const char * fileExtension, const char *mimeType, const char *description, const char * attribution, - int noHostnames, char ** hostnames, const char * cors, const char * tile_dir, const int parameterize) + const char *fileExtension, const char *mimeType, const char *description, const char *attribution, + int noHostnames, char **hostnames, const char *cors, const char *tile_dir, const int parameterize) { int i; int urilen; @@ -1968,7 +1952,6 @@ static const char *_add_tile_config(cmd_parms *cmd, void *mconfig, global_max_zoom = maxzoom; } - scfg = ap_get_module_config(cmd->server->module_config, &tile_module); tilecfg = apr_array_push(scfg->configs); @@ -2011,7 +1994,7 @@ static const char *_add_tile_config(cmd_parms *cmd, void *mconfig, return NULL; } -static const char *add_tile_mime_config(cmd_parms *cmd, void *mconfig, const char *baseuri, const char *name, const char * fileExtension) +static const char *add_tile_mime_config(cmd_parms *cmd, void *mconfig, const char *baseuri, const char *name, const char *fileExtension) { char *cors = NULL; char *mimeType = "image/png"; @@ -2072,21 +2055,21 @@ static const char *add_tile_config(cmd_parms *cmd, void *mconfig, int argc, char static const char *load_tile_config(cmd_parms *cmd, void *mconfig, const char *conffile) { - FILE * hini ; + FILE *hini; char filename[PATH_MAX]; char url[PATH_MAX]; char xmlname[XMLCONFIG_MAX]; char line[INILINE_MAX]; char key[INILINE_MAX]; char value[INILINE_MAX]; - const char * result; + const char *result; char fileExtension[INILINE_MAX]; char mimeType[INILINE_MAX]; char outputFormat[INILINE_MAX]; - char * description = NULL; - char * attribution = NULL; - char * cors = NULL; - char * tile_dir = NULL; + char *description = NULL; + char *attribution = NULL; + char *cors = NULL; + char *tile_dir = NULL; char **hostnames = NULL; char **hostnames_tmp; int noHostnames = 0; @@ -2206,8 +2189,7 @@ static const char *load_tile_config(cmd_parms *cmd, void *mconfig, const char *c aspect_x = 1; aspect_y = 1; parameterize = 0; - } else if (sscanf(line, "%[^=]=%[^;#]", key, value) == 2 - || sscanf(line, "%[^=]=\"%[^\"]\"", key, value) == 2) { + } else if (sscanf(line, "%[^=]=%[^;#]", key, value) == 2 || sscanf(line, "%[^=]=\"%[^\"]\"", key, value) == 2) { if (!strcmp(key, "URI")) { if (strlen(value) >= PATH_MAX) { @@ -2379,8 +2361,8 @@ static const char *load_tile_config(cmd_parms *cmd, void *mconfig, const char *c } if (tilelayer == 1) { - //ap_log_error(APLOG_MARK, APLOG_DEBUG, APR_SUCCESS, cmd->server, - // "Committing tile config %s", xmlname); + // ap_log_error(APLOG_MARK, APLOG_DEBUG, APR_SUCCESS, cmd->server, + // "Committing tile config %s", xmlname); result = _add_tile_config(cmd, mconfig, url, xmlname, minzoom, maxzoom, aspect_x, aspect_y, fileExtension, mimeType, description, attribution, noHostnames, hostnames, cors, tile_dir, parameterize); @@ -2522,7 +2504,7 @@ static const char *mod_tile_cache_lastmod_factor_config(cmd_parms *cmd, void *mc { float modified_factor; tile_server_conf *scfg = ap_get_module_config(cmd->server->module_config, - &tile_module); + &tile_module); if (sscanf(modified_factor_string, "%f", &modified_factor) != 1) { return "ModTileCacheLastModifiedFactor needs float argument"; @@ -2536,7 +2518,7 @@ static const char *mod_tile_cache_duration_max_config(cmd_parms *cmd, void *mcon { int cache_duration; tile_server_conf *scfg = ap_get_module_config(cmd->server->module_config, - &tile_module); + &tile_module); if (sscanf(cache_duration_string, "%d", &cache_duration) != 1) { return "ModTileCacheDurationMax needs integer argument"; @@ -2550,7 +2532,7 @@ static const char *mod_tile_cache_duration_dirty_config(cmd_parms *cmd, void *mc { int cache_duration; tile_server_conf *scfg = ap_get_module_config(cmd->server->module_config, - &tile_module); + &tile_module); if (sscanf(cache_duration_string, "%d", &cache_duration) != 1) { return "ModTileCacheDurationDirty needs integer argument"; @@ -2564,7 +2546,7 @@ static const char *mod_tile_cache_duration_minimum_config(cmd_parms *cmd, void * { int cache_duration; tile_server_conf *scfg = ap_get_module_config(cmd->server->module_config, - &tile_module); + &tile_module); if (sscanf(cache_duration_string, "%d", &cache_duration) != 1) { return "ModTileCacheDurationMinimum needs integer argument"; @@ -2627,7 +2609,7 @@ static const char *mod_tile_enable_throttling(cmd_parms *cmd, void *mconfig, int return NULL; } -static const char *mod_tile_enable_throttling_xforward(cmd_parms *cmd, void *mconfig, const char * enableThrottlingXForward) +static const char *mod_tile_enable_throttling_xforward(cmd_parms *cmd, void *mconfig, const char *enableThrottlingXForward) { int throttle_xforward; tile_server_conf *scfg = ap_get_module_config(cmd->server->module_config, &tile_module); @@ -2713,7 +2695,7 @@ static const char *mod_tile_delaypool_render_config(cmd_parms *cmd, void *mconfi static void *create_tile_config(apr_pool_t *p, server_rec *s) { - tile_server_conf * scfg = (tile_server_conf *) apr_pcalloc(p, sizeof(tile_server_conf)); + tile_server_conf *scfg = (tile_server_conf *)apr_pcalloc(p, sizeof(tile_server_conf)); scfg->configs = apr_array_make(p, 4, sizeof(tile_config_rec)); scfg->request_timeout = REQUEST_TIMEOUT; @@ -2747,16 +2729,15 @@ static void *create_tile_config(apr_pool_t *p, server_rec *s) scfg->enableStatusUrl = 1; scfg->enableDirtyUrl = 1; - return scfg; } static void *merge_tile_config(apr_pool_t *p, void *basev, void *overridesv) { int i; - tile_server_conf * scfg = (tile_server_conf *) apr_pcalloc(p, sizeof(tile_server_conf)); - tile_server_conf * scfg_base = (tile_server_conf *) basev; - tile_server_conf * scfg_over = (tile_server_conf *) overridesv; + tile_server_conf *scfg = (tile_server_conf *)apr_pcalloc(p, sizeof(tile_server_conf)); + tile_server_conf *scfg_base = (tile_server_conf *)basev; + tile_server_conf *scfg_over = (tile_server_conf *)overridesv; scfg->configs = apr_array_append(p, scfg_base->configs, scfg_over->configs); scfg->request_timeout = scfg_over->request_timeout; @@ -2791,7 +2772,7 @@ static void *merge_tile_config(apr_pool_t *p, void *basev, void *overridesv) scfg->enableStatusUrl = scfg_over->enableStatusUrl; scfg->enableDirtyUrl = scfg_over->enableDirtyUrl; - //Construct a table of minimum cache times per zoom level + // Construct a table of minimum cache times per zoom level for (i = 0; i <= MAX_ZOOM_SERVER; i++) { if (i <= scfg->cache_level_low_zoom) { scfg->mincachetime[i] = scfg->cache_duration_low_zoom; @@ -2806,204 +2787,203 @@ static void *merge_tile_config(apr_pool_t *p, void *basev, void *overridesv) } static const command_rec tile_cmds[] = { - AP_INIT_TAKE1( - "LoadTileConfigFile", /* directive name */ - load_tile_config, /* config action routine */ - NULL, /* argument to include in call */ - OR_OPTIONS, /* where available */ - "load an entire renderd config file" /* directive description */ + AP_INIT_TAKE1( + "LoadTileConfigFile", /* directive name */ + load_tile_config, /* config action routine */ + NULL, /* argument to include in call */ + OR_OPTIONS, /* where available */ + "load an entire renderd config file" /* directive description */ ), - AP_INIT_TAKE_ARGV( - "AddTileConfig", /* directive name */ - add_tile_config, /* config action routine */ - NULL, /* argument to include in call */ - OR_OPTIONS, /* where available */ - "path, name of renderd config and optional key-value pairs to use" /* directive description */ + AP_INIT_TAKE_ARGV( + "AddTileConfig", /* directive name */ + add_tile_config, /* config action routine */ + NULL, /* argument to include in call */ + OR_OPTIONS, /* where available */ + "path, name of renderd config and optional key-value pairs to use" /* directive description */ ), - AP_INIT_TAKE3( - "AddTileMimeConfig", /* directive name */ - add_tile_mime_config, /* config action routine */ - NULL, /* argument to include in call */ - OR_OPTIONS, /* where available */ - "path, name of renderd config and file extension to use" /* directive description */ + AP_INIT_TAKE3( + "AddTileMimeConfig", /* directive name */ + add_tile_mime_config, /* config action routine */ + NULL, /* argument to include in call */ + OR_OPTIONS, /* where available */ + "path, name of renderd config and file extension to use" /* directive description */ ), - AP_INIT_TAKE1( - "ModTileRequestTimeout", /* directive name */ - mod_tile_request_timeout_config, /* config action routine */ - NULL, /* argument to include in call */ - OR_OPTIONS, /* where available */ - "Set timeout in seconds on mod_tile requests" /* directive description */ + AP_INIT_TAKE1( + "ModTileRequestTimeout", /* directive name */ + mod_tile_request_timeout_config, /* config action routine */ + NULL, /* argument to include in call */ + OR_OPTIONS, /* where available */ + "Set timeout in seconds on mod_tile requests" /* directive description */ ), - AP_INIT_TAKE1( - "ModTileMissingRequestTimeout", /* directive name */ - mod_tile_request_timeout_missing_config, /* config action routine */ - NULL, /* argument to include in call */ - OR_OPTIONS, /* where available */ - "Set timeout in seconds on missing mod_tile requests" /* directive description */ + AP_INIT_TAKE1( + "ModTileMissingRequestTimeout", /* directive name */ + mod_tile_request_timeout_missing_config, /* config action routine */ + NULL, /* argument to include in call */ + OR_OPTIONS, /* where available */ + "Set timeout in seconds on missing mod_tile requests" /* directive description */ ), - AP_INIT_TAKE1( - "ModTileMaxLoadOld", /* directive name */ - mod_tile_max_load_old_config, /* config action routine */ - NULL, /* argument to include in call */ - OR_OPTIONS, /* where available */ - "Set max load for rendering old tiles" /* directive description */ + AP_INIT_TAKE1( + "ModTileMaxLoadOld", /* directive name */ + mod_tile_max_load_old_config, /* config action routine */ + NULL, /* argument to include in call */ + OR_OPTIONS, /* where available */ + "Set max load for rendering old tiles" /* directive description */ ), - AP_INIT_TAKE1( - "ModTileMaxLoadMissing", /* directive name */ - mod_tile_max_load_missing_config, /* config action routine */ - NULL, /* argument to include in call */ - OR_OPTIONS, /* where available */ - "Set max load for rendering missing tiles" /* directive description */ + AP_INIT_TAKE1( + "ModTileMaxLoadMissing", /* directive name */ + mod_tile_max_load_missing_config, /* config action routine */ + NULL, /* argument to include in call */ + OR_OPTIONS, /* where available */ + "Set max load for rendering missing tiles" /* directive description */ ), - AP_INIT_TAKE1( - "ModTileVeryOldThreshold", /* directive name */ - mod_tile_veryold_threshold_config, /* config action routine */ - NULL, /* argument to include in call */ - OR_OPTIONS, /* where available */ - "set the time threshold from when an outdated tile ist considered very old and rendered with slightly higher priority." /* directive description */ + AP_INIT_TAKE1( + "ModTileVeryOldThreshold", /* directive name */ + mod_tile_veryold_threshold_config, /* config action routine */ + NULL, /* argument to include in call */ + OR_OPTIONS, /* where available */ + "set the time threshold from when an outdated tile ist considered very old and rendered with slightly higher priority." /* directive description */ ), - AP_INIT_TAKE1( - "ModTileRenderdSocketName", /* directive name */ - mod_tile_renderd_socket_name_config, /* config action routine */ - NULL, /* argument to include in call */ - OR_OPTIONS, /* where available */ - "Set name of unix domain socket for connecting to rendering daemon" /* directive description */ + AP_INIT_TAKE1( + "ModTileRenderdSocketName", /* directive name */ + mod_tile_renderd_socket_name_config, /* config action routine */ + NULL, /* argument to include in call */ + OR_OPTIONS, /* where available */ + "Set name of unix domain socket for connecting to rendering daemon" /* directive description */ ), - AP_INIT_TAKE2( - "ModTileRenderdSocketAddr", /* directive name */ - mod_tile_renderd_socket_addr_config, /* config action routine */ - NULL, /* argument to include in call */ - OR_OPTIONS, /* where available */ - "Set address and port of the TCP socket for connecting to rendering daemon" /* directive description */ + AP_INIT_TAKE2( + "ModTileRenderdSocketAddr", /* directive name */ + mod_tile_renderd_socket_addr_config, /* config action routine */ + NULL, /* argument to include in call */ + OR_OPTIONS, /* where available */ + "Set address and port of the TCP socket for connecting to rendering daemon" /* directive description */ ), - AP_INIT_TAKE1( - "ModTileTileDir", /* directive name */ - mod_tile_tile_dir_config, /* config action routine */ - NULL, /* argument to include in call */ - OR_OPTIONS, /* where available */ - "Set name of tile cache directory" /* directive description */ + AP_INIT_TAKE1( + "ModTileTileDir", /* directive name */ + mod_tile_tile_dir_config, /* config action routine */ + NULL, /* argument to include in call */ + OR_OPTIONS, /* where available */ + "Set name of tile cache directory" /* directive description */ ), - AP_INIT_TAKE1( - "ModTileCacheExtendedHostName", /* directive name */ - mod_tile_cache_extended_host_name_config, /* config action routine */ - NULL, /* argument to include in call */ - OR_OPTIONS, /* where available */ - "set hostname for extended period caching" /* directive description */ + AP_INIT_TAKE1( + "ModTileCacheExtendedHostName", /* directive name */ + mod_tile_cache_extended_host_name_config, /* config action routine */ + NULL, /* argument to include in call */ + OR_OPTIONS, /* where available */ + "set hostname for extended period caching" /* directive description */ ), - AP_INIT_TAKE1( - "ModTileCacheExtendedDuration", /* directive name */ - mod_tile_cache_extended_duration_config, /* config action routine */ - NULL, /* argument to include in call */ - OR_OPTIONS, /* where available */ - "set length of extended period caching" /* directive description */ + AP_INIT_TAKE1( + "ModTileCacheExtendedDuration", /* directive name */ + mod_tile_cache_extended_duration_config, /* config action routine */ + NULL, /* argument to include in call */ + OR_OPTIONS, /* where available */ + "set length of extended period caching" /* directive description */ ), - AP_INIT_TAKE1( - "ModTileCacheDurationMax", /* directive name */ - mod_tile_cache_duration_max_config, /* config action routine */ - NULL, /* argument to include in call */ - OR_OPTIONS, /* where available */ - "Set the maximum cache expiry in seconds" /* directive description */ + AP_INIT_TAKE1( + "ModTileCacheDurationMax", /* directive name */ + mod_tile_cache_duration_max_config, /* config action routine */ + NULL, /* argument to include in call */ + OR_OPTIONS, /* where available */ + "Set the maximum cache expiry in seconds" /* directive description */ ), - AP_INIT_TAKE1( - "ModTileCacheDurationDirty", /* directive name */ - mod_tile_cache_duration_dirty_config, /* config action routine */ - NULL, /* argument to include in call */ - OR_OPTIONS, /* where available */ - "Set the cache expiry for serving dirty tiles" /* directive description */ + AP_INIT_TAKE1( + "ModTileCacheDurationDirty", /* directive name */ + mod_tile_cache_duration_dirty_config, /* config action routine */ + NULL, /* argument to include in call */ + OR_OPTIONS, /* where available */ + "Set the cache expiry for serving dirty tiles" /* directive description */ ), - AP_INIT_TAKE1( - "ModTileCacheDurationMinimum", /* directive name */ - mod_tile_cache_duration_minimum_config, /* config action routine */ - NULL, /* argument to include in call */ - OR_OPTIONS, /* where available */ - "Set the minimum cache expiry" /* directive description */ + AP_INIT_TAKE1( + "ModTileCacheDurationMinimum", /* directive name */ + mod_tile_cache_duration_minimum_config, /* config action routine */ + NULL, /* argument to include in call */ + OR_OPTIONS, /* where available */ + "Set the minimum cache expiry" /* directive description */ ), - AP_INIT_TAKE1( - "ModTileCacheLastModifiedFactor", /* directive name */ - mod_tile_cache_lastmod_factor_config, /* config action routine */ - NULL, /* argument to include in call */ - OR_OPTIONS, /* where available */ - "Set the factor by which the last modified determines cache expiry" /* directive description */ + AP_INIT_TAKE1( + "ModTileCacheLastModifiedFactor", /* directive name */ + mod_tile_cache_lastmod_factor_config, /* config action routine */ + NULL, /* argument to include in call */ + OR_OPTIONS, /* where available */ + "Set the factor by which the last modified determines cache expiry" /* directive description */ ), - AP_INIT_TAKE2( - "ModTileCacheDurationLowZoom", /* directive name */ - mod_tile_cache_duration_low_config, /* config action routine */ - NULL, /* argument to include in call */ - OR_OPTIONS, /* where available */ - "Set the minimum cache duration and zoom level for low zoom tiles" /* directive description */ + AP_INIT_TAKE2( + "ModTileCacheDurationLowZoom", /* directive name */ + mod_tile_cache_duration_low_config, /* config action routine */ + NULL, /* argument to include in call */ + OR_OPTIONS, /* where available */ + "Set the minimum cache duration and zoom level for low zoom tiles" /* directive description */ ), - AP_INIT_TAKE2( - "ModTileCacheDurationMediumZoom", /* directive name */ - mod_tile_cache_duration_medium_config, /* config action routine */ - NULL, /* argument to include in call */ - OR_OPTIONS, /* where available */ - "Set the minimum cache duration and zoom level for medium zoom tiles" /* directive description */ + AP_INIT_TAKE2( + "ModTileCacheDurationMediumZoom", /* directive name */ + mod_tile_cache_duration_medium_config, /* config action routine */ + NULL, /* argument to include in call */ + OR_OPTIONS, /* where available */ + "Set the minimum cache duration and zoom level for medium zoom tiles" /* directive description */ ), - AP_INIT_FLAG( - "ModTileEnableStats", /* directive name */ - mod_tile_enable_stats, /* config action routine */ - NULL, /* argument to include in call */ - OR_OPTIONS, /* where available */ - "On Off - enable of keeping stats about what mod_tile is serving" /* directive description */ + AP_INIT_FLAG( + "ModTileEnableStats", /* directive name */ + mod_tile_enable_stats, /* config action routine */ + NULL, /* argument to include in call */ + OR_OPTIONS, /* where available */ + "On Off - enable of keeping stats about what mod_tile is serving" /* directive description */ ), - AP_INIT_FLAG( - "ModTileEnableTileThrottling", /* directive name */ - mod_tile_enable_throttling, /* config action routine */ - NULL, /* argument to include in call */ - OR_OPTIONS, /* where available */ - "On Off - enable of throttling of IPs that excessively download tiles such as scrapers" /* directive description */ + AP_INIT_FLAG( + "ModTileEnableTileThrottling", /* directive name */ + mod_tile_enable_throttling, /* config action routine */ + NULL, /* argument to include in call */ + OR_OPTIONS, /* where available */ + "On Off - enable of throttling of IPs that excessively download tiles such as scrapers" /* directive description */ ), - AP_INIT_TAKE1( - "ModTileEnableTileThrottlingXForward", /* directive name */ - mod_tile_enable_throttling_xforward, /* config action routine */ - NULL, /* argument to include in call */ - OR_OPTIONS, /* where available */ - "0 1 2 - use X-Forwarded-For http header to determin IP for throttling when available. 0 => off, 1 => use first entry, 2 => use last entry of the caching chain" /* directive description */ + AP_INIT_TAKE1( + "ModTileEnableTileThrottlingXForward", /* directive name */ + mod_tile_enable_throttling_xforward, /* config action routine */ + NULL, /* argument to include in call */ + OR_OPTIONS, /* where available */ + "0 1 2 - use X-Forwarded-For http header to determin IP for throttling when available. 0 => off, 1 => use first entry, 2 => use last entry of the caching chain" /* directive description */ ), - AP_INIT_TAKE2( - "ModTileThrottlingTiles", /* directive name */ - mod_tile_delaypool_tiles_config, /* config action routine */ - NULL, /* argument to include in call */ - OR_OPTIONS, /* where available */ - "Set the initial bucket size (number of tiles) and top up rate (tiles per second) for throttling tile request per IP" /* directive description */ + AP_INIT_TAKE2( + "ModTileThrottlingTiles", /* directive name */ + mod_tile_delaypool_tiles_config, /* config action routine */ + NULL, /* argument to include in call */ + OR_OPTIONS, /* where available */ + "Set the initial bucket size (number of tiles) and top up rate (tiles per second) for throttling tile request per IP" /* directive description */ ), - AP_INIT_TAKE2( - "ModTileThrottlingRenders", /* directive name */ - mod_tile_delaypool_render_config,/* config action routine */ - NULL, /* argument to include in call */ - OR_OPTIONS, /* where available */ - "Set the initial bucket size (number of tiles) and top up rate (tiles per second) for throttling tile request per IP" /* directive description */ + AP_INIT_TAKE2( + "ModTileThrottlingRenders", /* directive name */ + mod_tile_delaypool_render_config, /* config action routine */ + NULL, /* argument to include in call */ + OR_OPTIONS, /* where available */ + "Set the initial bucket size (number of tiles) and top up rate (tiles per second) for throttling tile request per IP" /* directive description */ ), - AP_INIT_FLAG( - "ModTileBulkMode", /* directive name */ - mod_tile_bulk_mode, /* config action routine */ - NULL, /* argument to include in call */ - OR_OPTIONS, /* where available */ - "On Off - make all requests to renderd with bulk render priority, never mark tiles dirty" /* directive description */ + AP_INIT_FLAG( + "ModTileBulkMode", /* directive name */ + mod_tile_bulk_mode, /* config action routine */ + NULL, /* argument to include in call */ + OR_OPTIONS, /* where available */ + "On Off - make all requests to renderd with bulk render priority, never mark tiles dirty" /* directive description */ ), - AP_INIT_FLAG( - "ModTileEnableStatusURL", /* directive name */ - mod_tile_enable_status_url, /* config action routine */ - NULL, /* argument to include in call */ - OR_OPTIONS, /* where available */ - "On Off - whether to handle .../status urls " /* directive description */ + AP_INIT_FLAG( + "ModTileEnableStatusURL", /* directive name */ + mod_tile_enable_status_url, /* config action routine */ + NULL, /* argument to include in call */ + OR_OPTIONS, /* where available */ + "On Off - whether to handle .../status urls " /* directive description */ ), - AP_INIT_FLAG( - "ModTileEnableDirtyURL", /* directive name */ - mod_tile_enable_dirty_url, /* config action routine */ - NULL, /* argument to include in call */ - OR_OPTIONS, /* where available */ - "On Off - whether to handle .../dirty urls " /* directive description */ + AP_INIT_FLAG( + "ModTileEnableDirtyURL", /* directive name */ + mod_tile_enable_dirty_url, /* config action routine */ + NULL, /* argument to include in call */ + OR_OPTIONS, /* where available */ + "On Off - whether to handle .../dirty urls " /* directive description */ ), - {NULL} -}; + {NULL}}; module AP_MODULE_DECLARE_DATA tile_module = { -STANDARD20_MODULE_STUFF, -NULL, /* dir config creater */ -NULL, /* dir merger --- default is to override */ -create_tile_config, /* server config */ -merge_tile_config, /* merge server config */ -tile_cmds, /* command apr_table_t */ -register_hooks /* register hooks */ + STANDARD20_MODULE_STUFF, + NULL, /* dir config creater */ + NULL, /* dir merger --- default is to override */ + create_tile_config, /* server config */ + merge_tile_config, /* merge server config */ + tile_cmds, /* command apr_table_t */ + register_hooks /* register hooks */ }; diff --git a/src/mysql2file.c b/src/mysql2file.c index 5ac2dbed..38ba3a4f 100644 --- a/src/mysql2file.c +++ b/src/mysql2file.c @@ -15,34 +15,32 @@ * along with this program; If not, see http://www.gnu.org/licenses/. */ +#include +#include +#include +#include #include #include #include -#include -#include -#include #include +#include +#include #include -#include -#include -#include -#include #include +#include #include - +#include #include #include #include -#include #include -#include +#include #define WWW_ROOT "/var/www/html" // TILE_PATH must have tile z directory z(0..18)/x/y.png #define TILE_PATH "/osm_tiles2" - // Build parent directories for the specified file name // Note: the part following the trailing / is ignored // e.g. mkdirp("/a/b/foo.png") == shell mkdir -p /a/b @@ -146,7 +144,7 @@ int main(int argc, char **argv) assert(mysql_num_fields(res) == 5); - //printf("x(%s) y(%s) z(%s) data_length(%lu): %s\n", row[0], row[1], row[2], lengths[3], row[4]); + // printf("x(%s) y(%s) z(%s) data_length(%lu): %s\n", row[0], row[1], row[2], lengths[3], row[4]); x = strtoul(row[0], NULL, 10); y = strtoul(row[1], NULL, 10); @@ -156,7 +154,7 @@ int main(int argc, char **argv) parseDate(&date, row[4]); created_at = mktime(&date); - //printf("x(%lu) y(%lu) z(%lu) data_length(%lu): %s", x,y,z,length,ctime(&created_at)); + // printf("x(%lu) y(%lu) z(%lu) data_length(%lu): %s", x,y,z,length,ctime(&created_at)); if (!length) { printf("skipping empty tile x(%lu) y(%lu) z(%lu) data_length(%lu): %s", x, y, z, length, ctime(&created_at)); @@ -180,7 +178,7 @@ int main(int argc, char **argv) } close(fd); - utb.actime = created_at; + utb.actime = created_at; utb.modtime = created_at; if (utime(path, &utb) < 0) { @@ -189,9 +187,9 @@ int main(int argc, char **argv) } } - printf("Number of rows: %lu\n", (unsigned long) mysql_num_rows(res)); + printf("Number of rows: %lu\n", (unsigned long)mysql_num_rows(res)); mysql_free_result(res); - mysql_close(&mysql); /* Close & free connection */ + mysql_close(&mysql); /* Close & free connection */ return 0; } diff --git a/src/protocol_helper.c b/src/protocol_helper.c index 71a1ff09..d36b5f07 100644 --- a/src/protocol_helper.c +++ b/src/protocol_helper.c @@ -16,15 +16,15 @@ */ #include "protocol.h" -#include -#include -#include -#include #include +#include +#include +#include +#include #include "g_logger.h" -int send_cmd(struct protocol * cmd, int fd) +int send_cmd(struct protocol *cmd, int fd) { int ret; g_logger(G_LOG_LEVEL_DEBUG, "Sending render cmd(%i %s %i/%i/%i) with protocol version %i to fd %i", cmd->cmd, cmd->xmlname, cmd->z, cmd->x, cmd->y, cmd->ver, fd); @@ -35,17 +35,17 @@ int send_cmd(struct protocol * cmd, int fd) } switch (cmd->ver) { - case 1: - ret = send(fd, cmd, sizeof(struct protocol_v1), 0); - break; + case 1: + ret = send(fd, cmd, sizeof(struct protocol_v1), 0); + break; - case 2: - ret = send(fd, cmd, sizeof(struct protocol_v2), 0); - break; + case 2: + ret = send(fd, cmd, sizeof(struct protocol_v2), 0); + break; - case 3: - ret = send(fd, cmd, sizeof(struct protocol), 0); - break; + case 3: + ret = send(fd, cmd, sizeof(struct protocol), 0); + break; } if ((ret != sizeof(struct protocol)) && (ret != sizeof(struct protocol_v2)) && (ret != sizeof(struct protocol_v1))) { @@ -56,7 +56,7 @@ int send_cmd(struct protocol * cmd, int fd) return ret; } -int recv_cmd(struct protocol * cmd, int fd, int block) +int recv_cmd(struct protocol *cmd, int fd, int block) { int ret, ret2; memset(cmd, 0, sizeof(*cmd)); @@ -78,17 +78,17 @@ int recv_cmd(struct protocol * cmd, int fd, int block) g_logger(G_LOG_LEVEL_DEBUG, "Got incoming request with protocol version %i", cmd->ver); switch (cmd->ver) { - case 1: - ret2 = 0; - break; + case 1: + ret2 = 0; + break; - case 2: - ret2 = recv(fd, ((void*)cmd) + sizeof(struct protocol_v1), sizeof(struct protocol_v2) - sizeof(struct protocol_v1), block ? MSG_WAITALL : MSG_DONTWAIT); - break; + case 2: + ret2 = recv(fd, ((void *)cmd) + sizeof(struct protocol_v1), sizeof(struct protocol_v2) - sizeof(struct protocol_v1), block ? MSG_WAITALL : MSG_DONTWAIT); + break; - case 3: - ret2 = recv(fd, ((void*)cmd) + sizeof(struct protocol_v1), sizeof(struct protocol) - sizeof(struct protocol_v1), block ? MSG_WAITALL : MSG_DONTWAIT); - break; + case 3: + ret2 = recv(fd, ((void *)cmd) + sizeof(struct protocol_v1), sizeof(struct protocol) - sizeof(struct protocol_v1), block ? MSG_WAITALL : MSG_DONTWAIT); + break; } if ((cmd->ver > 1) && (ret2 < 1)) { diff --git a/src/render_expired.c b/src/render_expired.c index 92f8747d..73ef1b0f 100644 --- a/src/render_expired.c +++ b/src/render_expired.c @@ -131,23 +131,22 @@ int main(int argc, char **argv) while (1) { int option_index = 0; static struct option long_options[] = { - {"config", required_argument, 0, 'c'}, - {"delete-from", required_argument, 0, 'd'}, - {"map", required_argument, 0, 'm'}, - {"max-load", required_argument, 0, 'l'}, - {"max-zoom", required_argument, 0, 'Z'}, - {"min-zoom", required_argument, 0, 'z'}, - {"no-progress", no_argument, 0, 'N'}, - {"num-threads", required_argument, 0, 'n'}, - {"socket", required_argument, 0, 's'}, - {"tile-dir", required_argument, 0, 't'}, - {"touch-from", required_argument, 0, 'T'}, - {"verbose", no_argument, 0, 'v'}, - - {"help", no_argument, 0, 'h'}, - {"version", no_argument, 0, 'V'}, - {0, 0, 0, 0} - }; + {"config", required_argument, 0, 'c'}, + {"delete-from", required_argument, 0, 'd'}, + {"map", required_argument, 0, 'm'}, + {"max-load", required_argument, 0, 'l'}, + {"max-zoom", required_argument, 0, 'Z'}, + {"min-zoom", required_argument, 0, 'z'}, + {"no-progress", no_argument, 0, 'N'}, + {"num-threads", required_argument, 0, 'n'}, + {"socket", required_argument, 0, 's'}, + {"tile-dir", required_argument, 0, 't'}, + {"touch-from", required_argument, 0, 'T'}, + {"verbose", no_argument, 0, 'v'}, + + {"help", no_argument, 0, 'h'}, + {"version", no_argument, 0, 'V'}, + {0, 0, 0, 0}}; int c = getopt_long(argc, argv, "c:d:m:l:Z:z:Nn:s:t:T:vhV", long_options, &option_index); @@ -156,106 +155,106 @@ int main(int argc, char **argv) } switch (c) { - case 'c': /* -c, --config */ - config_file_name = strndup(optarg, PATH_MAX); - config_file_name_passed = 1; + case 'c': /* -c, --config */ + config_file_name = strndup(optarg, PATH_MAX); + config_file_name_passed = 1; - struct stat buffer; + struct stat buffer; - if (stat(config_file_name, &buffer) != 0) { - g_logger(G_LOG_LEVEL_CRITICAL, "Config file '%s' does not exist, please specify a valid file", config_file_name); - return 1; - } + if (stat(config_file_name, &buffer) != 0) { + g_logger(G_LOG_LEVEL_CRITICAL, "Config file '%s' does not exist, please specify a valid file", config_file_name); + return 1; + } - break; + break; - case 'd': /* -d, --delete-from */ - delete_from = min_max_int_opt(optarg, "delete-from", 0, MAX_ZOOM); - delete_from_passed = 1; - break; + case 'd': /* -d, --delete-from */ + delete_from = min_max_int_opt(optarg, "delete-from", 0, MAX_ZOOM); + delete_from_passed = 1; + break; - case 'm': /* -m, --map */ - mapname = strndup(optarg, XMLCONFIG_MAX); - mapname_passed = 1; - break; + case 'm': /* -m, --map */ + mapname = strndup(optarg, XMLCONFIG_MAX); + mapname_passed = 1; + break; - case 'l': /* -l, --max-load */ - max_load = min_max_int_opt(optarg, "maximum load", 0, -1); - max_load_passed = 1; - break; + case 'l': /* -l, --max-load */ + max_load = min_max_int_opt(optarg, "maximum load", 0, -1); + max_load_passed = 1; + break; - case 'Z': /* -Z, --max-zoom */ - max_zoom = min_max_int_opt(optarg, "maximum zoom", 0, MAX_ZOOM); - max_zoom_passed = 1; - break; + case 'Z': /* -Z, --max-zoom */ + max_zoom = min_max_int_opt(optarg, "maximum zoom", 0, MAX_ZOOM); + max_zoom_passed = 1; + break; - case 'z': /* -z, --min-zoom */ - min_zoom = min_max_int_opt(optarg, "minimum zoom", 0, MAX_ZOOM); - min_zoom_passed = 1; - break; + case 'z': /* -z, --min-zoom */ + min_zoom = min_max_int_opt(optarg, "minimum zoom", 0, MAX_ZOOM); + min_zoom_passed = 1; + break; - case 'N': /* -N, --no-progress */ - progress = 0; - break; + case 'N': /* -N, --no-progress */ + progress = 0; + break; - case 'n': /* -n, --num-threads */ - num_threads = min_max_int_opt(optarg, "number of threads", 1, -1); - num_threads_passed = 1; - break; + case 'n': /* -n, --num-threads */ + num_threads = min_max_int_opt(optarg, "number of threads", 1, -1); + num_threads_passed = 1; + break; - case 's': /* -s, --socket */ - socketname = strndup(optarg, PATH_MAX); - socketname_passed = 1; - break; + case 's': /* -s, --socket */ + socketname = strndup(optarg, PATH_MAX); + socketname_passed = 1; + break; - case 't': /* -t, --tile-dir */ - tile_dir = strndup(optarg, PATH_MAX); - tile_dir_passed = 1; - break; + case 't': /* -t, --tile-dir */ + tile_dir = strndup(optarg, PATH_MAX); + tile_dir_passed = 1; + break; - case 'T': /* -T, --touch-from */ - touch_from = min_max_int_opt(optarg, "touch-from", 0, MAX_ZOOM); - touch_from_passed = 1; - break; + case 'T': /* -T, --touch-from */ + touch_from = min_max_int_opt(optarg, "touch-from", 0, MAX_ZOOM); + touch_from_passed = 1; + break; - case 'v': /* -v, --verbose */ - verbose = 1; - break; + case 'v': /* -v, --verbose */ + verbose = 1; + break; - case 'h': /* -h, --help */ - fprintf(stderr, "Usage: render_expired [OPTION] ...\n"); - fprintf(stderr, " -c, --config=CONFIG specify the renderd config file (default is off)\n"); - fprintf(stderr, " -d, --delete-from=ZOOM when expiring tiles of ZOOM or higher, delete them instead of re-rendering (default is off)\n"); - fprintf(stderr, " -l, --max-load=LOAD sleep if load is this high (default is '%d')\n", max_load_default); - fprintf(stderr, " -m, --map=MAP render tiles in this map (default is '%s')\n", mapname_default); - fprintf(stderr, " -N, --no-progress disable display of progress messages (default is off)\n"); - fprintf(stderr, " -n, --num-threads=N the number of parallel request threads (default is '%d')\n", num_threads_default); - fprintf(stderr, " -s, --socket=SOCKET|HOSTNAME:PORT unix domain socket name or hostname and port for contacting renderd (default is '%s')\n", socketname_default); - fprintf(stderr, " -t, --tile-dir=TILE_DIR tile cache directory (default is '%s')\n", tile_dir_default); - fprintf(stderr, " -T, --touch-from=ZOOM when expiring tiles of ZOOM or higher, touch them instead of re-rendering (default is off)\n"); - fprintf(stderr, " -Z, --max-zoom=ZOOM filter input to only render tiles less than or equal to this zoom level (default is '%d')\n", max_zoom_default); - fprintf(stderr, " -z, --min-zoom=ZOOM filter input to only render tiles greater than or equal to this zoom level (default is '%d')\n", min_zoom_default); - fprintf(stderr, "\n"); - fprintf(stderr, " -h, --help display this help and exit\n"); - fprintf(stderr, " -V, --version display the version number and exit\n"); - fprintf(stderr, "\n"); - fprintf(stderr, "Send a list of tiles to be rendered from STDIN in the format:\n"); - fprintf(stderr, " z/x/y\n"); - fprintf(stderr, "e.g.\n"); - fprintf(stderr, " 1/0/1\n"); - fprintf(stderr, " 1/1/1\n"); - fprintf(stderr, " 1/0/0\n"); - fprintf(stderr, " 1/1/0\n"); - fprintf(stderr, "The above would cause all 4 tiles at zoom 1 to be rendered\n"); - return 0; - - case 'V': /* -V, --version */ - fprintf(stdout, "%s\n", VERSION); - return 0; - - default: - g_logger(G_LOG_LEVEL_CRITICAL, "unhandled char '%c'", c); - return 1; + case 'h': /* -h, --help */ + fprintf(stderr, "Usage: render_expired [OPTION] ...\n"); + fprintf(stderr, " -c, --config=CONFIG specify the renderd config file (default is off)\n"); + fprintf(stderr, " -d, --delete-from=ZOOM when expiring tiles of ZOOM or higher, delete them instead of re-rendering (default is off)\n"); + fprintf(stderr, " -l, --max-load=LOAD sleep if load is this high (default is '%d')\n", max_load_default); + fprintf(stderr, " -m, --map=MAP render tiles in this map (default is '%s')\n", mapname_default); + fprintf(stderr, " -N, --no-progress disable display of progress messages (default is off)\n"); + fprintf(stderr, " -n, --num-threads=N the number of parallel request threads (default is '%d')\n", num_threads_default); + fprintf(stderr, " -s, --socket=SOCKET|HOSTNAME:PORT unix domain socket name or hostname and port for contacting renderd (default is '%s')\n", socketname_default); + fprintf(stderr, " -t, --tile-dir=TILE_DIR tile cache directory (default is '%s')\n", tile_dir_default); + fprintf(stderr, " -T, --touch-from=ZOOM when expiring tiles of ZOOM or higher, touch them instead of re-rendering (default is off)\n"); + fprintf(stderr, " -Z, --max-zoom=ZOOM filter input to only render tiles less than or equal to this zoom level (default is '%d')\n", max_zoom_default); + fprintf(stderr, " -z, --min-zoom=ZOOM filter input to only render tiles greater than or equal to this zoom level (default is '%d')\n", min_zoom_default); + fprintf(stderr, "\n"); + fprintf(stderr, " -h, --help display this help and exit\n"); + fprintf(stderr, " -V, --version display the version number and exit\n"); + fprintf(stderr, "\n"); + fprintf(stderr, "Send a list of tiles to be rendered from STDIN in the format:\n"); + fprintf(stderr, " z/x/y\n"); + fprintf(stderr, "e.g.\n"); + fprintf(stderr, " 1/0/1\n"); + fprintf(stderr, " 1/1/1\n"); + fprintf(stderr, " 1/0/0\n"); + fprintf(stderr, " 1/1/0\n"); + fprintf(stderr, "The above would cause all 4 tiles at zoom 1 to be rendered\n"); + return 0; + + case 'V': /* -V, --version */ + fprintf(stdout, "%s\n", VERSION); + return 0; + + default: + g_logger(G_LOG_LEVEL_CRITICAL, "unhandled char '%c'", c); + return 1; } } diff --git a/src/render_list.c b/src/render_list.c index 1540c3ae..b5d6496c 100644 --- a/src/render_list.c +++ b/src/render_list.c @@ -134,30 +134,29 @@ int main(int argc, char **argv) while (1) { int option_index = 0; static struct option long_options[] = { - {"all", no_argument, 0, 'a'}, - {"config", required_argument, 0, 'c'}, - {"force", no_argument, 0, 'f'}, - {"map", required_argument, 0, 'm'}, - {"max-lat", required_argument, 0, 'G'}, - {"max-load", required_argument, 0, 'l'}, - {"max-lon", required_argument, 0, 'W'}, - {"max-x", required_argument, 0, 'X'}, - {"max-y", required_argument, 0, 'Y'}, - {"max-zoom", required_argument, 0, 'Z'}, - {"min-lat", required_argument, 0, 'g'}, - {"min-lon", required_argument, 0, 'w'}, - {"min-x", required_argument, 0, 'x'}, - {"min-y", required_argument, 0, 'y'}, - {"min-zoom", required_argument, 0, 'z'}, - {"num-threads", required_argument, 0, 'n'}, - {"socket", required_argument, 0, 's'}, - {"tile-dir", required_argument, 0, 't'}, - {"verbose", no_argument, 0, 'v'}, - - {"help", no_argument, 0, 'h'}, - {"version", no_argument, 0, 'V'}, - {0, 0, 0, 0} - }; + {"all", no_argument, 0, 'a'}, + {"config", required_argument, 0, 'c'}, + {"force", no_argument, 0, 'f'}, + {"map", required_argument, 0, 'm'}, + {"max-lat", required_argument, 0, 'G'}, + {"max-load", required_argument, 0, 'l'}, + {"max-lon", required_argument, 0, 'W'}, + {"max-x", required_argument, 0, 'X'}, + {"max-y", required_argument, 0, 'Y'}, + {"max-zoom", required_argument, 0, 'Z'}, + {"min-lat", required_argument, 0, 'g'}, + {"min-lon", required_argument, 0, 'w'}, + {"min-x", required_argument, 0, 'x'}, + {"min-y", required_argument, 0, 'y'}, + {"min-zoom", required_argument, 0, 'z'}, + {"num-threads", required_argument, 0, 'n'}, + {"socket", required_argument, 0, 's'}, + {"tile-dir", required_argument, 0, 't'}, + {"verbose", no_argument, 0, 'v'}, + + {"help", no_argument, 0, 'h'}, + {"version", no_argument, 0, 'V'}, + {0, 0, 0, 0}}; int c = getopt_long(argc, argv, "ac:fm:G:l:W:X:Y:Z:g:w:x:y:z:n:s:t:vhV", long_options, &option_index); @@ -166,150 +165,150 @@ int main(int argc, char **argv) } switch (c) { - case 'a': /* -a, --all */ - all = 1; - break; - - case 'c': /* -c, --config */ - config_file_name = strndup(optarg, PATH_MAX); - config_file_name_passed = 1; + case 'a': /* -a, --all */ + all = 1; + break; - struct stat buffer; + case 'c': /* -c, --config */ + config_file_name = strndup(optarg, PATH_MAX); + config_file_name_passed = 1; - if (stat(config_file_name, &buffer) != 0) { - g_logger(G_LOG_LEVEL_CRITICAL, "Config file '%s' does not exist, please specify a valid file", config_file_name); - return 1; - } + struct stat buffer; - break; - - case 'f': /* -f, --force */ - force = 1; - break; - - case 'm': /* -m, --map */ - mapname = strndup(optarg, XMLCONFIG_MAX); - mapname_passed = 1; - break; - - case 'G': /* -G, --max-lat */ - max_lat = min_max_double_opt(optarg, "maximum latitute", -85.0511, 85.0511); - max_lat_passed = 1; - break; - - case 'l': /* -l, --max-load */ - max_load = min_max_int_opt(optarg, "maximum load", 0, -1); - max_load_passed = 1; - break; - - case 'W': /* -W, --max-lon */ - max_lon = min_max_double_opt(optarg, "maximum longitude", -180, 180); - max_lon_passed = 1; - break; - - case 'X': /* -X, --max-x */ - max_x = min_max_int_opt(optarg, "maximum X tile coordinate", 0, -1); - max_x_passed = 1; - break; - - case 'Y': /* -Y, --max-y */ - max_y = min_max_int_opt(optarg, "maximum Y tile coordinate", 0, -1); - max_y_passed = 1; - break; - - case 'Z': /* -Z, --max-zoom */ - max_zoom = min_max_int_opt(optarg, "maximum zoom", 0, MAX_ZOOM); - max_zoom_passed = 1; - break; - - case 'g': /* -g, --min-lat */ - min_lat = min_max_double_opt(optarg, "minimum latitute", -85.0511, 85.0511); - min_lat_passed = 1; - break; - - case 'w': /* -w, --min-lon */ - min_lon = min_max_double_opt(optarg, "minimum longitude", -180, 180); - min_lon_passed = 1; - break; - - case 'x': /* -x, --min-x */ - min_x = min_max_int_opt(optarg, "minimum X tile coordinate", 0, -1); - min_x_passed = 1; - break; - - case 'y': /* -y, --min-y */ - min_y = min_max_int_opt(optarg, "minimum Y tile coordinate", 0, -1); - min_y_passed = 1; - break; - - case 'z': /* -z, --min-zoom */ - min_zoom = min_max_int_opt(optarg, "minimum zoom", 0, MAX_ZOOM); - min_zoom_passed = 1; - break; - - case 'n': /* -n, --num-threads */ - num_threads = min_max_int_opt(optarg, "number of threads", 1, -1); - num_threads_passed = 1; - break; - - case 's': /* -s, --socket */ - socketname = strndup(optarg, PATH_MAX); - socketname_passed = 1; - break; - - case 't': /* -t, --tile-dir */ - tile_dir = strndup(optarg, PATH_MAX); - tile_dir_passed = 1; - break; - - case 'v': /* -v, --verbose */ - verbose = 1; - break; - - case 'h': /* -h, --help */ - fprintf(stderr, "Usage: render_list [OPTION] ...\n"); - fprintf(stderr, " -a, --all render all tiles in given zoom level range instead of reading from STDIN\n"); - fprintf(stderr, " -c, --config=CONFIG specify the renderd config file (default is off)\n"); - fprintf(stderr, " -f, --force render tiles even if they seem current\n"); - fprintf(stderr, " -l, --max-load=LOAD sleep if load is this high (default is '%d')\n", max_load_default); - fprintf(stderr, " -m, --map=MAP render tiles in this map (default is '%s')\n", mapname_default); - fprintf(stderr, " -n, --num-threads=N the number of parallel request threads (default is '%i')\n", num_threads_default); - fprintf(stderr, " -s, --socket=SOCKET|HOSTNAME:PORT unix domain socket name or hostname and port for contacting renderd (default is '%s')\n", socketname_default); - fprintf(stderr, " -t, --tile-dir=TILE_DIR tile cache directory (default is '%s')\n", tile_dir_default); - fprintf(stderr, " -Z, --max-zoom=ZOOM filter input to only render tiles less than or equal to this zoom level (default is '%d')\n", max_zoom_default); - fprintf(stderr, " -z, --min-zoom=ZOOM filter input to only render tiles greater than or equal to this zoom level (default is '%d')\n", min_zoom_default); - fprintf(stderr, "\n"); - fprintf(stderr, " -h, --help display this help and exit\n"); - fprintf(stderr, " -V, --version display the version number and exit\n"); - fprintf(stderr, "\n"); - fprintf(stderr, "If you are using --all, you can restrict the tile range by adding these options:\n"); - fprintf(stderr, "(please note that tile coordinates must be positive integers and are not latitude and longitude values)\n"); - fprintf(stderr, " -G, --max-lat=LATITUDE maximum latitude\n"); - fprintf(stderr, " -g, --min-lat=LATITUDE minimum latitude\n"); - fprintf(stderr, " -W, --max-lon=LONGITUDE maximum longitude\n"); - fprintf(stderr, " -w, --min-lon=LONGITUDE minimum longitude\n"); - fprintf(stderr, " -X, --max-x=X maximum X tile coordinate\n"); - fprintf(stderr, " -x, --min-x=X minimum X tile coordinate\n"); - fprintf(stderr, " -Y, --max-y=Y maximum Y tile coordinate\n"); - fprintf(stderr, " -y, --min-y=Y minimum Y tile coordinate\n"); - fprintf(stderr, "\n"); - fprintf(stderr, "Without --all, send a list of tiles to be rendered from STDIN in the format:\n"); - fprintf(stderr, " X Y Z\n"); - fprintf(stderr, "e.g.\n"); - fprintf(stderr, " 0 0 1\n"); - fprintf(stderr, " 0 1 1\n"); - fprintf(stderr, " 1 0 1\n"); - fprintf(stderr, " 1 1 1\n"); - fprintf(stderr, "The above would cause all 4 tiles at zoom 1 to be rendered\n"); - return 0; - - case 'V': /* -V, --version */ - fprintf(stdout, "%s\n", VERSION); - return 0; - - default: - g_logger(G_LOG_LEVEL_CRITICAL, "unhandled char '%c'", c); + if (stat(config_file_name, &buffer) != 0) { + g_logger(G_LOG_LEVEL_CRITICAL, "Config file '%s' does not exist, please specify a valid file", config_file_name); return 1; + } + + break; + + case 'f': /* -f, --force */ + force = 1; + break; + + case 'm': /* -m, --map */ + mapname = strndup(optarg, XMLCONFIG_MAX); + mapname_passed = 1; + break; + + case 'G': /* -G, --max-lat */ + max_lat = min_max_double_opt(optarg, "maximum latitute", -85.0511, 85.0511); + max_lat_passed = 1; + break; + + case 'l': /* -l, --max-load */ + max_load = min_max_int_opt(optarg, "maximum load", 0, -1); + max_load_passed = 1; + break; + + case 'W': /* -W, --max-lon */ + max_lon = min_max_double_opt(optarg, "maximum longitude", -180, 180); + max_lon_passed = 1; + break; + + case 'X': /* -X, --max-x */ + max_x = min_max_int_opt(optarg, "maximum X tile coordinate", 0, -1); + max_x_passed = 1; + break; + + case 'Y': /* -Y, --max-y */ + max_y = min_max_int_opt(optarg, "maximum Y tile coordinate", 0, -1); + max_y_passed = 1; + break; + + case 'Z': /* -Z, --max-zoom */ + max_zoom = min_max_int_opt(optarg, "maximum zoom", 0, MAX_ZOOM); + max_zoom_passed = 1; + break; + + case 'g': /* -g, --min-lat */ + min_lat = min_max_double_opt(optarg, "minimum latitute", -85.0511, 85.0511); + min_lat_passed = 1; + break; + + case 'w': /* -w, --min-lon */ + min_lon = min_max_double_opt(optarg, "minimum longitude", -180, 180); + min_lon_passed = 1; + break; + + case 'x': /* -x, --min-x */ + min_x = min_max_int_opt(optarg, "minimum X tile coordinate", 0, -1); + min_x_passed = 1; + break; + + case 'y': /* -y, --min-y */ + min_y = min_max_int_opt(optarg, "minimum Y tile coordinate", 0, -1); + min_y_passed = 1; + break; + + case 'z': /* -z, --min-zoom */ + min_zoom = min_max_int_opt(optarg, "minimum zoom", 0, MAX_ZOOM); + min_zoom_passed = 1; + break; + + case 'n': /* -n, --num-threads */ + num_threads = min_max_int_opt(optarg, "number of threads", 1, -1); + num_threads_passed = 1; + break; + + case 's': /* -s, --socket */ + socketname = strndup(optarg, PATH_MAX); + socketname_passed = 1; + break; + + case 't': /* -t, --tile-dir */ + tile_dir = strndup(optarg, PATH_MAX); + tile_dir_passed = 1; + break; + + case 'v': /* -v, --verbose */ + verbose = 1; + break; + + case 'h': /* -h, --help */ + fprintf(stderr, "Usage: render_list [OPTION] ...\n"); + fprintf(stderr, " -a, --all render all tiles in given zoom level range instead of reading from STDIN\n"); + fprintf(stderr, " -c, --config=CONFIG specify the renderd config file (default is off)\n"); + fprintf(stderr, " -f, --force render tiles even if they seem current\n"); + fprintf(stderr, " -l, --max-load=LOAD sleep if load is this high (default is '%d')\n", max_load_default); + fprintf(stderr, " -m, --map=MAP render tiles in this map (default is '%s')\n", mapname_default); + fprintf(stderr, " -n, --num-threads=N the number of parallel request threads (default is '%i')\n", num_threads_default); + fprintf(stderr, " -s, --socket=SOCKET|HOSTNAME:PORT unix domain socket name or hostname and port for contacting renderd (default is '%s')\n", socketname_default); + fprintf(stderr, " -t, --tile-dir=TILE_DIR tile cache directory (default is '%s')\n", tile_dir_default); + fprintf(stderr, " -Z, --max-zoom=ZOOM filter input to only render tiles less than or equal to this zoom level (default is '%d')\n", max_zoom_default); + fprintf(stderr, " -z, --min-zoom=ZOOM filter input to only render tiles greater than or equal to this zoom level (default is '%d')\n", min_zoom_default); + fprintf(stderr, "\n"); + fprintf(stderr, " -h, --help display this help and exit\n"); + fprintf(stderr, " -V, --version display the version number and exit\n"); + fprintf(stderr, "\n"); + fprintf(stderr, "If you are using --all, you can restrict the tile range by adding these options:\n"); + fprintf(stderr, "(please note that tile coordinates must be positive integers and are not latitude and longitude values)\n"); + fprintf(stderr, " -G, --max-lat=LATITUDE maximum latitude\n"); + fprintf(stderr, " -g, --min-lat=LATITUDE minimum latitude\n"); + fprintf(stderr, " -W, --max-lon=LONGITUDE maximum longitude\n"); + fprintf(stderr, " -w, --min-lon=LONGITUDE minimum longitude\n"); + fprintf(stderr, " -X, --max-x=X maximum X tile coordinate\n"); + fprintf(stderr, " -x, --min-x=X minimum X tile coordinate\n"); + fprintf(stderr, " -Y, --max-y=Y maximum Y tile coordinate\n"); + fprintf(stderr, " -y, --min-y=Y minimum Y tile coordinate\n"); + fprintf(stderr, "\n"); + fprintf(stderr, "Without --all, send a list of tiles to be rendered from STDIN in the format:\n"); + fprintf(stderr, " X Y Z\n"); + fprintf(stderr, "e.g.\n"); + fprintf(stderr, " 0 0 1\n"); + fprintf(stderr, " 0 1 1\n"); + fprintf(stderr, " 1 0 1\n"); + fprintf(stderr, " 1 1 1\n"); + fprintf(stderr, "The above would cause all 4 tiles at zoom 1 to be rendered\n"); + return 0; + + case 'V': /* -V, --version */ + fprintf(stdout, "%s\n", VERSION); + return 0; + + default: + g_logger(G_LOG_LEVEL_CRITICAL, "unhandled char '%c'", c); + return 1; } } diff --git a/src/render_old.c b/src/render_old.c index 2c5ff088..a904f315 100644 --- a/src/render_old.c +++ b/src/render_old.c @@ -211,21 +211,20 @@ int main(int argc, char **argv) while (1) { int option_index = 0; static struct option long_options[] = { - {"config", required_argument, 0, 'c'}, - {"map", required_argument, 0, 'm'}, - {"max-load", required_argument, 0, 'l'}, - {"max-zoom", required_argument, 0, 'Z'}, - {"min-zoom", required_argument, 0, 'z'}, - {"num-threads", required_argument, 0, 'n'}, - {"socket", required_argument, 0, 's'}, - {"tile-dir", required_argument, 0, 't'}, - {"timestamp", required_argument, 0, 'T'}, - {"verbose", no_argument, 0, 'v'}, - - {"help", no_argument, 0, 'h'}, - {"version", no_argument, 0, 'V'}, - {0, 0, 0, 0} - }; + {"config", required_argument, 0, 'c'}, + {"map", required_argument, 0, 'm'}, + {"max-load", required_argument, 0, 'l'}, + {"max-zoom", required_argument, 0, 'Z'}, + {"min-zoom", required_argument, 0, 'z'}, + {"num-threads", required_argument, 0, 'n'}, + {"socket", required_argument, 0, 's'}, + {"tile-dir", required_argument, 0, 't'}, + {"timestamp", required_argument, 0, 'T'}, + {"verbose", no_argument, 0, 'v'}, + + {"help", no_argument, 0, 'h'}, + {"version", no_argument, 0, 'V'}, + {0, 0, 0, 0}}; int c = getopt_long(argc, argv, "c:m:l:Z:z:n:s:t:T:vhV", long_options, &option_index); @@ -234,106 +233,106 @@ int main(int argc, char **argv) } switch (c) { - case 'c': /* -c, --config */ - config_file_name = strndup(optarg, PATH_MAX); - config_file_name_passed = 1; + case 'c': /* -c, --config */ + config_file_name = strndup(optarg, PATH_MAX); + config_file_name_passed = 1; - struct stat buffer; + struct stat buffer; - if (stat(config_file_name, &buffer) != 0) { - g_logger(G_LOG_LEVEL_CRITICAL, "Config file '%s' does not exist, please specify a valid file", config_file_name); - return 1; + if (stat(config_file_name, &buffer) != 0) { + g_logger(G_LOG_LEVEL_CRITICAL, "Config file '%s' does not exist, please specify a valid file", config_file_name); + return 1; + } + + break; + + case 'm': /* -m, --map */ + mapname = strndup(optarg, XMLCONFIG_MAX); + mapname_passed = 1; + break; + + case 'l': /* -l, --max-load */ + max_load = min_max_int_opt(optarg, "maximum load", 0, -1); + max_load_passed = 1; + break; + + case 'Z': /* -Z, --max-zoom */ + max_zoom = min_max_int_opt(optarg, "maximum zoom", 0, MAX_ZOOM); + max_zoom_passed = 1; + break; + + case 'z': /* -z, --min-zoom */ + min_zoom = min_max_int_opt(optarg, "minimum zoom", 0, MAX_ZOOM); + min_zoom_passed = 1; + break; + + case 'n': /* -n, --num-threads */ + num_threads = min_max_int_opt(optarg, "number of threads", 1, -1); + num_threads_passed = 1; + break; + + case 's': /* -s, --socket */ + socketname = strndup(optarg, PATH_MAX); + socketname_passed = 1; + break; + + case 't': /* -t, --tile-dir */ + tile_dir = strndup(optarg, PATH_MAX); + tile_dir_passed = 1; + break; + + case 'T': + if (sscanf(optarg, "%d/%d/%d", &dd, &mm, &yy) == 3) { + if (yy > 100) { + yy -= 1900; } - break; - - case 'm': /* -m, --map */ - mapname = strndup(optarg, XMLCONFIG_MAX); - mapname_passed = 1; - break; - - case 'l': /* -l, --max-load */ - max_load = min_max_int_opt(optarg, "maximum load", 0, -1); - max_load_passed = 1; - break; - - case 'Z': /* -Z, --max-zoom */ - max_zoom = min_max_int_opt(optarg, "maximum zoom", 0, MAX_ZOOM); - max_zoom_passed = 1; - break; - - case 'z': /* -z, --min-zoom */ - min_zoom = min_max_int_opt(optarg, "minimum zoom", 0, MAX_ZOOM); - min_zoom_passed = 1; - break; - - case 'n': /* -n, --num-threads */ - num_threads = min_max_int_opt(optarg, "number of threads", 1, -1); - num_threads_passed = 1; - break; - - case 's': /* -s, --socket */ - socketname = strndup(optarg, PATH_MAX); - socketname_passed = 1; - break; - - case 't': /* -t, --tile-dir */ - tile_dir = strndup(optarg, PATH_MAX); - tile_dir_passed = 1; - break; - - case 'T': - if (sscanf(optarg, "%d/%d/%d", &dd, &mm, &yy) == 3) { - if (yy > 100) { - yy -= 1900; - } - - if (yy < 70) { - yy += 100; - } - - memset(&tm, 0, sizeof(tm)); - tm.tm_mday = dd; - tm.tm_mon = mm - 1; - tm.tm_year = yy; - planet_timestamp = mktime(&tm); - } else if (sscanf(optarg, "%d", &dd) == 1) { - planet_timestamp = dd; - } else { - g_logger(G_LOG_LEVEL_CRITICAL, "Invalid planet timestamp, must be a unix timestamp or in the format dd/mm/yyyy"); - return 1; + if (yy < 70) { + yy += 100; } - break; - - case 'v': /* -v, --verbose */ - verbose = 1; - break; - - case 'h': /* -h, --help */ - fprintf(stderr, "Usage: render_old [OPTION] ...\n"); - fprintf(stderr, "Search the rendered tiles and re-render tiles which are older then the last planet import\n"); - fprintf(stderr, " -c, --config=CONFIG specify the renderd config file (default is '%s')\n", config_file_name_default); - fprintf(stderr, " -l, --max-load=LOAD sleep if load is this high (default is '%d')\n", max_load_default); - fprintf(stderr, " -m, --map=STYLE Instead of going through all styles of CONFIG, only use a specific map-style\n"); - fprintf(stderr, " -n, --num-threads=N the number of parallel request threads (default is '%d')\n", num_threads_default); - fprintf(stderr, " -s, --socket=SOCKET|HOSTNAME:PORT unix domain socket name or hostname and port for contacting renderd (default is '%s')\n", socketname_default); - fprintf(stderr, " -t, --tile-dir=TILE_DIR tile cache directory (default is '%s')\n", tile_dir_default); - fprintf(stderr, " -T, --timestamp=DD/MM/YY Overwrite the assumed data of the planet import\n"); - fprintf(stderr, " -Z, --max-zoom=ZOOM filter input to only render tiles less than or equal to this zoom level (default is '%d')\n", max_zoom_default); - fprintf(stderr, " -z, --min-zoom=ZOOM filter input to only render tiles greater than or equal to this zoom level (default is '%d')\n", min_zoom_default); - fprintf(stderr, "\n"); - fprintf(stderr, " -h, --help display this help and exit\n"); - fprintf(stderr, " -V, --version display the version number and exit\n"); - return 0; - - case 'V': /* -V, --version */ - fprintf(stdout, "%s\n", VERSION); - return 0; - - default: - g_logger(G_LOG_LEVEL_CRITICAL, "unhandled char '%c'", c); + memset(&tm, 0, sizeof(tm)); + tm.tm_mday = dd; + tm.tm_mon = mm - 1; + tm.tm_year = yy; + planet_timestamp = mktime(&tm); + } else if (sscanf(optarg, "%d", &dd) == 1) { + planet_timestamp = dd; + } else { + g_logger(G_LOG_LEVEL_CRITICAL, "Invalid planet timestamp, must be a unix timestamp or in the format dd/mm/yyyy"); return 1; + } + + break; + + case 'v': /* -v, --verbose */ + verbose = 1; + break; + + case 'h': /* -h, --help */ + fprintf(stderr, "Usage: render_old [OPTION] ...\n"); + fprintf(stderr, "Search the rendered tiles and re-render tiles which are older then the last planet import\n"); + fprintf(stderr, " -c, --config=CONFIG specify the renderd config file (default is '%s')\n", config_file_name_default); + fprintf(stderr, " -l, --max-load=LOAD sleep if load is this high (default is '%d')\n", max_load_default); + fprintf(stderr, " -m, --map=STYLE Instead of going through all styles of CONFIG, only use a specific map-style\n"); + fprintf(stderr, " -n, --num-threads=N the number of parallel request threads (default is '%d')\n", num_threads_default); + fprintf(stderr, " -s, --socket=SOCKET|HOSTNAME:PORT unix domain socket name or hostname and port for contacting renderd (default is '%s')\n", socketname_default); + fprintf(stderr, " -t, --tile-dir=TILE_DIR tile cache directory (default is '%s')\n", tile_dir_default); + fprintf(stderr, " -T, --timestamp=DD/MM/YY Overwrite the assumed data of the planet import\n"); + fprintf(stderr, " -Z, --max-zoom=ZOOM filter input to only render tiles less than or equal to this zoom level (default is '%d')\n", max_zoom_default); + fprintf(stderr, " -z, --min-zoom=ZOOM filter input to only render tiles greater than or equal to this zoom level (default is '%d')\n", min_zoom_default); + fprintf(stderr, "\n"); + fprintf(stderr, " -h, --help display this help and exit\n"); + fprintf(stderr, " -V, --version display the version number and exit\n"); + return 0; + + case 'V': /* -V, --version */ + fprintf(stdout, "%s\n", VERSION); + return 0; + + default: + g_logger(G_LOG_LEVEL_CRITICAL, "unhandled char '%c'", c); + return 1; } } diff --git a/src/render_speedtest.cpp b/src/render_speedtest.cpp index f198c332..c8a74fbd 100644 --- a/src/render_speedtest.cpp +++ b/src/render_speedtest.cpp @@ -75,7 +75,7 @@ class GoogleProjection { double *Ac, *Bc, *Cc, *zc; -public: + public: GoogleProjection(int levels = 18) { Ac = new double[levels]; @@ -156,17 +156,16 @@ int main(int argc, char **argv) while (1) { int option_index = 0; static struct option long_options[] = { - {"config", required_argument, 0, 'c'}, - {"map", required_argument, 0, 'm'}, - {"max-zoom", required_argument, 0, 'Z'}, - {"min-zoom", required_argument, 0, 'z'}, - {"num-threads", required_argument, 0, 'n'}, - {"socket", required_argument, 0, 's'}, - - {"help", no_argument, 0, 'h'}, - {"version", no_argument, 0, 'V'}, - {0, 0, 0, 0} - }; + {"config", required_argument, 0, 'c'}, + {"map", required_argument, 0, 'm'}, + {"max-zoom", required_argument, 0, 'Z'}, + {"min-zoom", required_argument, 0, 'z'}, + {"num-threads", required_argument, 0, 'n'}, + {"socket", required_argument, 0, 's'}, + + {"help", no_argument, 0, 'h'}, + {"version", no_argument, 0, 'V'}, + {0, 0, 0, 0}}; int c = getopt_long(argc, argv, "c:m:Z:z:n:s:hV", long_options, &option_index); @@ -175,64 +174,64 @@ int main(int argc, char **argv) } switch (c) { - case 'c': /* -c, --config */ - config_file_name = strndup(optarg, PATH_MAX); - config_file_name_passed = 1; - - struct stat buffer; - - if (stat(config_file_name, &buffer) != 0) { - g_logger(G_LOG_LEVEL_CRITICAL, "Config file '%s' does not exist, please specify a valid file", config_file_name); - return 1; - } - - break; - - case 'm': /* -m, --map */ - mapname = strndup(optarg, XMLCONFIG_MAX); - mapname_passed = 1; - break; - - case 'Z': /* -Z, --max-zoom */ - max_zoom = min_max_int_opt(optarg, "maximum zoom", 0, MAX_ZOOM); - max_zoom_passed = 1; - break; - - case 'z': /* -z, --min-zoom */ - min_zoom = min_max_int_opt(optarg, "minimum zoom", 0, MAX_ZOOM); - min_zoom_passed = 1; - break; - - case 'n': /* -n, --num-threads */ - num_threads = min_max_int_opt(optarg, "number of threads", 1, -1); - num_threads_passed = 1; - break; - - case 's': /* -s, --socket */ - socketname = strndup(optarg, PATH_MAX); - socketname_passed = 1; - break; - - case 'h': /* -h, --help */ - fprintf(stderr, "Usage: render_speedtest [OPTION] ...\n"); - fprintf(stderr, " -c, --config=CONFIG specify the renderd config file (default is off)\n"); - fprintf(stderr, " -m, --map=MAP render tiles in this map (default is '%s')\n", mapname_default); - fprintf(stderr, " -n, --num-threads=N the number of parallel request threads (default is '%d')\n", num_threads_default); - fprintf(stderr, " -s, --socket=SOCKET|HOSTNAME:PORT unix domain socket name or hostname and port for contacting renderd (default is '%s')\n", socketname_default); - fprintf(stderr, " -Z, --max-zoom=ZOOM only render tiles less than or equal to this zoom level (default is '%d')\n", max_zoom_default); - fprintf(stderr, " -z, --min-zoom=ZOOM only render tiles greater than or equal to this zoom level (default is '%d')\n", min_zoom_default); - fprintf(stderr, "\n"); - fprintf(stderr, " -h, --help display this help and exit\n"); - fprintf(stderr, " -V, --version display the version number and exit\n"); - return 0; - - case 'V': /* -V, --version */ - fprintf(stdout, "%s\n", VERSION); - return 0; - - default: - g_logger(G_LOG_LEVEL_CRITICAL, "unhandled char '%c'", c); + case 'c': /* -c, --config */ + config_file_name = strndup(optarg, PATH_MAX); + config_file_name_passed = 1; + + struct stat buffer; + + if (stat(config_file_name, &buffer) != 0) { + g_logger(G_LOG_LEVEL_CRITICAL, "Config file '%s' does not exist, please specify a valid file", config_file_name); return 1; + } + + break; + + case 'm': /* -m, --map */ + mapname = strndup(optarg, XMLCONFIG_MAX); + mapname_passed = 1; + break; + + case 'Z': /* -Z, --max-zoom */ + max_zoom = min_max_int_opt(optarg, "maximum zoom", 0, MAX_ZOOM); + max_zoom_passed = 1; + break; + + case 'z': /* -z, --min-zoom */ + min_zoom = min_max_int_opt(optarg, "minimum zoom", 0, MAX_ZOOM); + min_zoom_passed = 1; + break; + + case 'n': /* -n, --num-threads */ + num_threads = min_max_int_opt(optarg, "number of threads", 1, -1); + num_threads_passed = 1; + break; + + case 's': /* -s, --socket */ + socketname = strndup(optarg, PATH_MAX); + socketname_passed = 1; + break; + + case 'h': /* -h, --help */ + fprintf(stderr, "Usage: render_speedtest [OPTION] ...\n"); + fprintf(stderr, " -c, --config=CONFIG specify the renderd config file (default is off)\n"); + fprintf(stderr, " -m, --map=MAP render tiles in this map (default is '%s')\n", mapname_default); + fprintf(stderr, " -n, --num-threads=N the number of parallel request threads (default is '%d')\n", num_threads_default); + fprintf(stderr, " -s, --socket=SOCKET|HOSTNAME:PORT unix domain socket name or hostname and port for contacting renderd (default is '%s')\n", socketname_default); + fprintf(stderr, " -Z, --max-zoom=ZOOM only render tiles less than or equal to this zoom level (default is '%d')\n", max_zoom_default); + fprintf(stderr, " -z, --min-zoom=ZOOM only render tiles greater than or equal to this zoom level (default is '%d')\n", min_zoom_default); + fprintf(stderr, "\n"); + fprintf(stderr, " -h, --help display this help and exit\n"); + fprintf(stderr, " -V, --version display the version number and exit\n"); + return 0; + + case 'V': /* -V, --version */ + fprintf(stdout, "%s\n", VERSION); + return 0; + + default: + g_logger(G_LOG_LEVEL_CRITICAL, "unhandled char '%c'", c); + return 1; } } diff --git a/src/renderd.c b/src/renderd.c index 9119cbc9..a8b6fe0c 100644 --- a/src/renderd.c +++ b/src/renderd.c @@ -44,8 +44,8 @@ #include "renderd_config.h" #include "request_queue.h" -#define PFD_LISTEN 0 -#define PFD_EXIT_PIPE 1 +#define PFD_LISTEN 0 +#define PFD_EXIT_PIPE 1 #define PFD_SPECIAL_COUNT 2 #ifndef MAIN_ALREADY_DEFINED @@ -57,43 +57,40 @@ static pthread_t stats_thread; static int exit_pipe_fd; -struct request_queue * render_request_queue; +struct request_queue *render_request_queue; static const char *cmdStr(enum protoCmd c) { switch (c) { - case cmdIgnore: - return "Ignore"; + case cmdIgnore: + return "Ignore"; - case cmdRender: - return "Render"; + case cmdRender: + return "Render"; - case cmdRenderPrio: - return "RenderPrio"; + case cmdRenderPrio: + return "RenderPrio"; - case cmdRenderLow: - return "RenderLow"; + case cmdRenderLow: + return "RenderLow"; - case cmdRenderBulk: - return "RenderBulk"; + case cmdRenderBulk: + return "RenderBulk"; - case cmdDirty: - return "Dirty"; + case cmdDirty: + return "Dirty"; - case cmdDone: - return "Done"; + case cmdDone: + return "Done"; - case cmdNotDone: - return "NotDone"; + case cmdNotDone: + return "NotDone"; - default: - return "Unknown"; + default: + return "Unknown"; } } - - - void send_response(struct item *item, enum protoCmd rsp, int render_time) { request_queue_remove_request(render_request_queue, item, render_time); @@ -107,7 +104,6 @@ void send_response(struct item *item, enum protoCmd rsp, int render_time) g_logger(G_LOG_LEVEL_DEBUG, "Sending message %s to %d", cmdStr(rsp), item->fd); send_cmd(req, item->fd); - } prev = item; @@ -118,7 +114,7 @@ void send_response(struct item *item, enum protoCmd rsp, int render_time) enum protoCmd rx_request(struct protocol *req, int fd) { - struct item *item; + struct item *item; // Upgrade version 1 and 2 to version 3 if (req->ver == 1) { @@ -222,7 +218,7 @@ void process_loop(int listen_fd) g_logger(G_LOG_LEVEL_DEBUG, "Data is available now on %d fds", num); if (pfd[PFD_LISTEN].revents & POLLIN) { - incoming = accept(listen_fd, (struct sockaddr *) &in_addr, &in_addrlen); + incoming = accept(listen_fd, (struct sockaddr *)&in_addr, &in_addrlen); if (incoming < 0) { g_logger(G_LOG_LEVEL_ERROR, "accept(): %s", strerror(errno)); @@ -252,7 +248,7 @@ void process_loop(int listen_fd) if (add) { pfd[i + PFD_SPECIAL_COUNT].fd = incoming; pfd[i + PFD_SPECIAL_COUNT].events = POLLIN; - num_conns ++; + num_conns++; g_logger(G_LOG_LEVEL_DEBUG, "Got incoming connection, fd %d, number %d, total conns %d, total slots %d", incoming, i, num_conns, num_cslots); } } @@ -275,7 +271,7 @@ void process_loop(int listen_fd) request_queue_clear_requests_by_fd(render_request_queue, fd); close(fd); pfd[i + PFD_SPECIAL_COUNT].fd = -1; - } else { + } else { enum protoCmd rsp = rx_request(&cmd, fd); if (rsp == cmdNotDone) { @@ -296,7 +292,7 @@ void process_loop(int listen_fd) * Periodically write out current stats to a stats file. This information * can then be used to monitor performance of renderd e.g. with a munin plugin */ -void *stats_writeout_thread(void * arg) +void *stats_writeout_thread(void *arg) { stats_struct lStats; int dirtQueueLength; @@ -311,7 +307,7 @@ void *stats_writeout_thread(void * arg) snprintf(tmpName, sizeof(tmpName), "%s.tmp", config.stats_filename); - g_logger(G_LOG_LEVEL_DEBUG, "Starting stats writeout thread: %lu", (unsigned long) pthread_self()); + g_logger(G_LOG_LEVEL_DEBUG, "Starting stats writeout thread: %lu", (unsigned long)pthread_self()); while (1) { request_queue_copy_stats(render_request_queue, &lStats); @@ -322,7 +318,7 @@ void *stats_writeout_thread(void * arg) dirtQueueLength = request_queue_no_requests_queued(render_request_queue, cmdDirty); reqBulkQueueLength = request_queue_no_requests_queued(render_request_queue, cmdRenderBulk); - FILE * statfile = fopen(tmpName, "w"); + FILE *statfile = fopen(tmpName, "w"); if (statfile == NULL) { g_logger(G_LOG_LEVEL_WARNING, "Failed to open stats file: %i", errno); @@ -381,10 +377,10 @@ void *stats_writeout_thread(void * arg) return NULL; } -int client_socket_init(renderd_config * sConfig) +int client_socket_init(renderd_config *sConfig) { int fd, s; - struct sockaddr_un * addrU; + struct sockaddr_un *addrU; struct addrinfo hints; struct addrinfo *result, *rp; char portnum[16]; @@ -394,10 +390,10 @@ int client_socket_init(renderd_config * sConfig) g_logger(G_LOG_LEVEL_INFO, "Initialising TCP/IP client socket to %s:%i", sConfig->iphostname, sConfig->ipport); memset(&hints, 0, sizeof(struct addrinfo)); - hints.ai_family = AF_UNSPEC; /* Allow IPv4 or IPv6 */ + hints.ai_family = AF_UNSPEC; /* Allow IPv4 or IPv6 */ hints.ai_socktype = SOCK_STREAM; /* TCP socket */ hints.ai_flags = 0; - hints.ai_protocol = 0; /* Any protocol */ + hints.ai_protocol = 0; /* Any protocol */ hints.ai_canonname = NULL; hints.ai_addr = NULL; hints.ai_next = NULL; @@ -414,17 +410,17 @@ int client_socket_init(renderd_config * sConfig) Try each address until we successfully connect. */ for (rp = result; rp != NULL; rp = rp->ai_next) { switch (rp->ai_family) { - case AF_INET: - inet_ntop(AF_INET, &(((struct sockaddr_in *)rp->ai_addr)->sin_addr), ipstring, rp->ai_addrlen); - break; + case AF_INET: + inet_ntop(AF_INET, &(((struct sockaddr_in *)rp->ai_addr)->sin_addr), ipstring, rp->ai_addrlen); + break; - case AF_INET6: - inet_ntop(AF_INET6, &(((struct sockaddr_in6 *)rp->ai_addr)->sin6_addr), ipstring, rp->ai_addrlen); - break; + case AF_INET6: + inet_ntop(AF_INET6, &(((struct sockaddr_in6 *)rp->ai_addr)->sin6_addr), ipstring, rp->ai_addrlen); + break; - default: - snprintf(ipstring, sizeof(ipstring), "address family %d", rp->ai_family); - break; + default: + snprintf(ipstring, sizeof(ipstring), "address family %d", rp->ai_family); + break; } g_logger(G_LOG_LEVEL_DEBUG, "Connecting TCP socket to rendering daemon at %s", ipstring); @@ -468,7 +464,7 @@ int client_socket_init(renderd_config * sConfig) addrU->sun_family = AF_UNIX; strncpy(addrU->sun_path, sConfig->socketname, sizeof(addrU->sun_path) - 1); - if (connect(fd, (struct sockaddr *) addrU, sizeof(struct sockaddr_un)) < 0) { + if (connect(fd, (struct sockaddr *)addrU, sizeof(struct sockaddr_un)) < 0) { g_logger(G_LOG_LEVEL_WARNING, "socket connect failed for: %s", sConfig->socketname); close(fd); @@ -506,7 +502,7 @@ int server_socket_init(renderd_config *sConfig) addrI.sin6_addr = in6addr_any; addrI.sin6_port = htons(sConfig->ipport); - if (bind(fd, (struct sockaddr *) &addrI, sizeof(addrI)) < 0) { + if (bind(fd, (struct sockaddr *)&addrI, sizeof(addrI)) < 0) { g_logger(G_LOG_LEVEL_CRITICAL, "socket bind failed for: %s:%i", sConfig->iphostname, sConfig->ipport); close(fd); @@ -531,7 +527,7 @@ int server_socket_init(renderd_config *sConfig) old = umask(0); // Need daemon socket to be writeable by apache - if (bind(fd, (struct sockaddr *) &addrU, sizeof(addrU)) < 0) { + if (bind(fd, (struct sockaddr *)&addrU, sizeof(addrU)) < 0) { g_logger(G_LOG_LEVEL_CRITICAL, "socket bind failed for: %s", sConfig->socketname); close(fd); exit(3); @@ -549,7 +545,6 @@ int server_socket_init(renderd_config *sConfig) g_logger(G_LOG_LEVEL_DEBUG, "Created server socket %i", fd); return fd; - } /** @@ -561,23 +556,23 @@ int server_socket_init(renderd_config *sConfig) * rendererd immediately. Thus overall, requests should be nicely load balanced between * all the rendering threads available both locally and in the slaves. */ -void *slave_thread(void * arg) +void *slave_thread(void *arg) { - renderd_config * sConfig = (renderd_config *) arg; + renderd_config *sConfig = (renderd_config *)arg; int pfd = FD_INVALID; int retry, seconds = 30; size_t ret_size; - struct protocol * resp; - struct protocol * req_slave; + struct protocol *resp; + struct protocol *req_slave; req_slave = (struct protocol *)malloc(sizeof(struct protocol)); resp = (struct protocol *)malloc(sizeof(struct protocol)); bzero(req_slave, sizeof(struct protocol)); bzero(resp, sizeof(struct protocol)); - g_logger(G_LOG_LEVEL_DEBUG, "Starting slave thread: %lu", (unsigned long) pthread_self()); + g_logger(G_LOG_LEVEL_DEBUG, "Starting slave thread: %lu", (unsigned long)pthread_self()); while (1) { if (pfd == FD_INVALID) { @@ -622,7 +617,7 @@ void *slave_thread(void * arg) ret_size = send_cmd(req_slave, pfd); if (ret_size == sizeof(struct protocol)) { - //correctly sent command to slave + // correctly sent command to slave break; } @@ -654,8 +649,7 @@ void *slave_thread(void * arg) retry = 10; while ((ret_size < sizeof(struct protocol)) && (retry > 0)) { - ret_size = recv(pfd, resp + ret_size, (sizeof(struct protocol) - - ret_size), 0); + ret_size = recv(pfd, resp + ret_size, (sizeof(struct protocol) - ret_size), 0); if ((errno == EPIPE) || ret_size == 0) { close(pfd); @@ -689,9 +683,9 @@ void *slave_thread(void * arg) g_logger(G_LOG_LEVEL_ERROR, "Request from Renderd slave at %s did not complete correctly", sConfig->socketname); } - //Sleep for a while to make sure we don't overload the renderer - //This only happens if it didn't correctly block on the rendering - //request + // Sleep for a while to make sure we don't overload the renderer + // This only happens if it didn't correctly block on the rendering + // request sleep(seconds); } } @@ -725,14 +719,13 @@ int main(int argc, char **argv) while (1) { int option_index = 0; static struct option long_options[] = { - {"config", required_argument, 0, 'c'}, - {"foreground", no_argument, 0, 'f'}, - {"slave", required_argument, 0, 's'}, + {"config", required_argument, 0, 'c'}, + {"foreground", no_argument, 0, 'f'}, + {"slave", required_argument, 0, 's'}, - {"help", no_argument, 0, 'h'}, - {"version", no_argument, 0, 'V'}, - {0, 0, 0, 0} - }; + {"help", no_argument, 0, 'h'}, + {"version", no_argument, 0, 'V'}, + {0, 0, 0, 0}}; c = getopt_long(argc, argv, "c:fs:hV", long_options, &option_index); @@ -741,46 +734,46 @@ int main(int argc, char **argv) } switch (c) { - case 'c': /* -c, --config */ - config_file_name = strndup(optarg, PATH_MAX); - config_file_name_passed = 1; + case 'c': /* -c, --config */ + config_file_name = strndup(optarg, PATH_MAX); + config_file_name_passed = 1; - struct stat buffer; + struct stat buffer; - if (stat(config_file_name, &buffer) != 0) { - g_logger(G_LOG_LEVEL_CRITICAL, "Config file '%s' does not exist, please specify a valid file", config_file_name); - return 1; - } + if (stat(config_file_name, &buffer) != 0) { + g_logger(G_LOG_LEVEL_CRITICAL, "Config file '%s' does not exist, please specify a valid file", config_file_name); + return 1; + } - break; + break; - case 'f': /* -f, --foreground */ - foreground = 1; - break; + case 'f': /* -f, --foreground */ + foreground = 1; + break; - case 's': /* -s, --slave */ - active_renderd_section_num = min_max_int_opt(optarg, "active renderd section", 0, -1); - active_renderd_section_num_passed = 1; - break; + case 's': /* -s, --slave */ + active_renderd_section_num = min_max_int_opt(optarg, "active renderd section", 0, -1); + active_renderd_section_num_passed = 1; + break; - case 'h': /* -h, --help */ - fprintf(stderr, "Usage: renderd [OPTION] ...\n"); - fprintf(stderr, "Mapnik rendering daemon\n"); - fprintf(stderr, " -c, --config=CONFIG specify the renderd config file (default is '%s')\n", config_file_name_default); - fprintf(stderr, " -f, --foreground run in foreground\n"); - fprintf(stderr, " -s, --slave=CONFIG_SECTION_NR set which renderd section to use (default is '%i')\n", active_renderd_section_num_default); - fprintf(stderr, "\n"); - fprintf(stderr, " -h, --help display this help and exit\n"); - fprintf(stderr, " -V, --version display the version number and exit\n"); - return 0; - - case 'V': /* -V, --version */ - fprintf(stdout, "%s\n", VERSION); - return 0; + case 'h': /* -h, --help */ + fprintf(stderr, "Usage: renderd [OPTION] ...\n"); + fprintf(stderr, "Mapnik rendering daemon\n"); + fprintf(stderr, " -c, --config=CONFIG specify the renderd config file (default is '%s')\n", config_file_name_default); + fprintf(stderr, " -f, --foreground run in foreground\n"); + fprintf(stderr, " -s, --slave=CONFIG_SECTION_NR set which renderd section to use (default is '%i')\n", active_renderd_section_num_default); + fprintf(stderr, "\n"); + fprintf(stderr, " -h, --help display this help and exit\n"); + fprintf(stderr, " -V, --version display the version number and exit\n"); + return 0; + + case 'V': /* -V, --version */ + fprintf(stdout, "%s\n", VERSION); + return 0; - default: - fprintf(stderr, "unknown config option '%c'\n", c); - return 1; + default: + fprintf(stderr, "unknown config option '%c'\n", c); + return 1; } } @@ -820,7 +813,7 @@ int main(int argc, char **argv) return 6; } - sigExitAction.sa_handler = (void *) request_exit; + sigExitAction.sa_handler = (void *)request_exit; sigaction(SIGHUP, &sigExitAction, NULL); @@ -842,8 +835,8 @@ int main(int argc, char **argv) FILE *pidfile = fopen(config.pid_filename, "w"); if (pidfile) { - (void) fprintf(pidfile, "%d\n", getpid()); - (void) fclose(pidfile); + (void)fprintf(pidfile, "%d\n", getpid()); + (void)fclose(pidfile); } } @@ -857,7 +850,7 @@ int main(int argc, char **argv) g_logger(G_LOG_LEVEL_INFO, "No stats file specified in config. Stats reporting disabled"); } - render_threads = (pthread_t *) malloc(sizeof(pthread_t) * config.num_threads); + render_threads = (pthread_t *)malloc(sizeof(pthread_t) * config.num_threads); for (i = 0; i < config.num_threads; i++) { if (pthread_create(&render_threads[i], NULL, render_thread, (void *)maps)) { @@ -870,11 +863,11 @@ int main(int argc, char **argv) if (active_renderd_section_num == 0) { // Only the master renderd opens connections to its slaves k = 0; - slave_threads = (pthread_t *) malloc(sizeof(pthread_t) * num_slave_threads); + slave_threads = (pthread_t *)malloc(sizeof(pthread_t) * num_slave_threads); for (i = 1; i < MAX_SLAVES; i++) { for (j = 0; j < config_slaves[i].num_threads; j++) { - if (pthread_create(&slave_threads[k++], NULL, slave_thread, (void *) &config_slaves[i])) { + if (pthread_create(&slave_threads[k++], NULL, slave_thread, (void *)&config_slaves[i])) { g_logger(G_LOG_LEVEL_CRITICAL, "Could not spawn slave thread"); close(fd); return 7; diff --git a/src/renderd_config.c b/src/renderd_config.c index 85d7c21c..4d843a96 100644 --- a/src/renderd_config.c +++ b/src/renderd_config.c @@ -276,21 +276,21 @@ void process_map_sections(const char *config_file_name, xmlconfigitem *maps_dest while ((ini_type_part = strtok_r(ini_type_copy, " ", &ini_type_copy))) { switch (ini_type_part_num) { - case 0: - copy_string(ini_type_part, &maps_dest[map_section_num].file_extension, ini_type_part_maxlen); - break; + case 0: + copy_string(ini_type_part, &maps_dest[map_section_num].file_extension, ini_type_part_maxlen); + break; - case 1: - copy_string(ini_type_part, &maps_dest[map_section_num].mime_type, ini_type_part_maxlen); - break; + case 1: + copy_string(ini_type_part, &maps_dest[map_section_num].mime_type, ini_type_part_maxlen); + break; - case 2: - copy_string(ini_type_part, &maps_dest[map_section_num].output_format, ini_type_part_maxlen); - break; + case 2: + copy_string(ini_type_part, &maps_dest[map_section_num].output_format, ini_type_part_maxlen); + break; - default: - g_logger(G_LOG_LEVEL_CRITICAL, "Specified type (%s) has too many parts, there must be no more than 3, e.g., 'png image/png png256'.", ini_type); - exit(7); + default: + g_logger(G_LOG_LEVEL_CRITICAL, "Specified type (%s) has too many parts, there must be no more than 3, e.g., 'png image/png png256'.", ini_type); + exit(7); } ini_type_part_num++; diff --git a/src/request_queue.c b/src/request_queue.c index 91a1358a..1a660e20 100644 --- a/src/request_queue.c +++ b/src/request_queue.c @@ -15,16 +15,16 @@ * along with this program; If not, see http://www.gnu.org/licenses/. */ +#include +#include #include #include -#include -#include #include -#include +#include +#include "g_logger.h" #include "render_config.h" #include "request_queue.h" -#include "g_logger.h" static int calcHashKey(struct request_queue *queue, struct item *item) { @@ -39,10 +39,10 @@ static int calcHashKey(struct request_queue *queue, struct item *item) return key % queue->hashidxSize; } -static struct item * lookup_item_idx(struct request_queue * queue, struct item * item) +static struct item *lookup_item_idx(struct request_queue *queue, struct item *item) { - struct item_idx * nextItem; - struct item * test; + struct item_idx *nextItem; + struct item *test; int key = calcHashKey(queue, item); @@ -54,9 +54,7 @@ static struct item * lookup_item_idx(struct request_queue * queue, struct item * while (nextItem != NULL) { test = nextItem->item; - if ((item->mx == test->mx) && (item->my == test->my) - && (item->req.z == test->req.z) && (!strcmp( - item->req.xmlname, test->req.xmlname))) { + if ((item->mx == test->mx) && (item->my == test->my) && (item->req.z == test->req.z) && (!strcmp(item->req.xmlname, test->req.xmlname))) { return test; } else { nextItem = nextItem->next; @@ -67,10 +65,10 @@ static struct item * lookup_item_idx(struct request_queue * queue, struct item * return NULL; } -static void insert_item_idx(struct request_queue * queue, struct item *item) +static void insert_item_idx(struct request_queue *queue, struct item *item) { - struct item_idx * nextItem; - struct item_idx * prevItem; + struct item_idx *nextItem; + struct item_idx *prevItem; int key = calcHashKey(queue, item); @@ -92,15 +90,15 @@ static void insert_item_idx(struct request_queue * queue, struct item *item) } } -static void remove_item_idx(struct request_queue * queue, struct item * item) +static void remove_item_idx(struct request_queue *queue, struct item *item) { int key = calcHashKey(queue, item); - struct item_idx * nextItem; - struct item_idx * prevItem; - struct item * test; + struct item_idx *nextItem; + struct item_idx *prevItem; + struct item *test; if (queue->item_hashidx[key].item == NULL) { - //item not in index; + // item not in index; return; } @@ -110,9 +108,7 @@ static void remove_item_idx(struct request_queue * queue, struct item * item) while (nextItem != NULL) { test = nextItem->item; - if ((item->mx == test->mx) && (item->my == test->my) && (item->req.z - == test->req.z) && (!strcmp(item->req.xmlname, - test->req.xmlname))) { + if ((item->mx == test->mx) && (item->my == test->my) && (item->req.z == test->req.z) && (!strcmp(item->req.xmlname, test->req.xmlname))) { /* * Found item, removing it from list */ @@ -143,7 +139,7 @@ static void remove_item_idx(struct request_queue * queue, struct item * item) } } -static enum protoCmd pending(struct request_queue * queue, struct item *test) +static enum protoCmd pending(struct request_queue *queue, struct item *test) { // check all queues and render list to see if this request already queued // If so, add this new request as a duplicate @@ -166,7 +162,7 @@ static enum protoCmd pending(struct request_queue * queue, struct item *test) return cmdRender; } -struct item *request_queue_fetch_request(struct request_queue * queue) +struct item *request_queue_fetch_request(struct request_queue *queue) { struct item *item = NULL; @@ -202,7 +198,7 @@ struct item *request_queue_fetch_request(struct request_queue * queue) item->next->prev = item->prev; item->prev->next = item->next; - //Add item to render queue + // Add item to render queue item->prev = &(queue->renderHead); item->next = queue->renderHead.next; queue->renderHead.next->prev = item; @@ -218,7 +214,7 @@ struct item *request_queue_fetch_request(struct request_queue * queue) /* If a fd becomes invalid for returning request information, remove it from all * requests to not send feedback to invalid FDs */ -void request_queue_clear_requests_by_fd(struct request_queue * queue, int fd) +void request_queue_clear_requests_by_fd(struct request_queue *queue, int fd) { struct item *item, *dupes, *queueHead; @@ -230,25 +226,25 @@ void request_queue_clear_requests_by_fd(struct request_queue * queue, int fd) for (int i = 0; i < 4; i++) { switch (i) { - case 0: { - queueHead = &(queue->reqHead); - break; - } + case 0: { + queueHead = &(queue->reqHead); + break; + } - case 1: { - queueHead = &(queue->renderHead); - break; - } + case 1: { + queueHead = &(queue->renderHead); + break; + } - case 2: { - queueHead = &(queue->reqPrioHead); - break; - } + case 2: { + queueHead = &(queue->reqPrioHead); + break; + } - case 3: { - queueHead = &(queue->reqBulkHead); - break; - } + case 3: { + queueHead = &(queue->reqBulkHead); + break; + } } item = queueHead->next; @@ -275,7 +271,7 @@ void request_queue_clear_requests_by_fd(struct request_queue * queue, int fd) pthread_mutex_unlock(&(queue->qLock)); } -enum protoCmd request_queue_add_request(struct request_queue * queue, struct item *item) +enum protoCmd request_queue_add_request(struct request_queue *queue, struct item *item) { enum protoCmd status; const struct protocol *req; @@ -360,7 +356,7 @@ enum protoCmd request_queue_add_request(struct request_queue * queue, struct ite return (list == &(queue->dirtyHead)) ? cmdNotDone : cmdIgnore; } -void request_queue_remove_request(struct request_queue * queue, struct item * request, int render_time) +void request_queue_remove_request(struct request_queue *queue, struct item *request, int render_time) { pthread_mutex_lock(&(queue->qLock)); @@ -370,33 +366,33 @@ void request_queue_remove_request(struct request_queue * queue, struct item * re if (render_time > 0) { switch (request->originatedQueue) { - case queueRequestPrio: { - queue->stats.timeReqPrioRender += render_time; - break; - } + case queueRequestPrio: { + queue->stats.timeReqPrioRender += render_time; + break; + } - case queueRequest: { - queue->stats.timeReqRender += render_time; - break; - } + case queueRequest: { + queue->stats.timeReqRender += render_time; + break; + } - case queueRequestLow: { - queue->stats.timeReqLowRender += render_time; - break; - } + case queueRequestLow: { + queue->stats.timeReqLowRender += render_time; + break; + } - case queueDirty: { - queue->stats.timeReqDirty += render_time; - break; - } + case queueDirty: { + queue->stats.timeReqDirty += render_time; + break; + } - case queueRequestBulk: { - queue->stats.timeReqBulkRender += render_time; - break; - } + case queueRequestBulk: { + queue->stats.timeReqBulkRender += render_time; + break; + } - default: - break; + default: + break; } queue->stats.noZoomRender[request->req.z]++; @@ -409,51 +405,51 @@ void request_queue_remove_request(struct request_queue * queue, struct item * re pthread_mutex_unlock(&(queue->qLock)); } -int request_queue_no_requests_queued(struct request_queue * queue, enum protoCmd priority) +int request_queue_no_requests_queued(struct request_queue *queue, enum protoCmd priority) { int noReq = -1; pthread_mutex_lock(&(queue->qLock)); switch (priority) { - case cmdRenderPrio: - noReq = queue->reqPrioNum; - break; + case cmdRenderPrio: + noReq = queue->reqPrioNum; + break; - case cmdRender: - noReq = queue->reqNum; - break; + case cmdRender: + noReq = queue->reqNum; + break; - case cmdRenderLow: - noReq = queue->reqLowNum; - break; + case cmdRenderLow: + noReq = queue->reqLowNum; + break; - case cmdDirty: - noReq = queue->dirtyNum; - break; + case cmdDirty: + noReq = queue->dirtyNum; + break; - case cmdRenderBulk: - noReq = queue->reqBulkNum; - break; + case cmdRenderBulk: + noReq = queue->reqBulkNum; + break; - default: - break; + default: + break; } pthread_mutex_unlock(&queue->qLock); return noReq; } -void request_queue_copy_stats(struct request_queue * queue, stats_struct * stats) +void request_queue_copy_stats(struct request_queue *queue, stats_struct *stats) { pthread_mutex_lock(&(queue->qLock)); memcpy(stats, &(queue->stats), sizeof(stats_struct)); pthread_mutex_unlock(&queue->qLock); } -struct request_queue * request_queue_init() +struct request_queue *request_queue_init() { int res; - struct request_queue * queue = calloc(1, sizeof(struct request_queue)); + struct request_queue *queue = calloc(1, sizeof(struct request_queue)); if (queue == NULL) { return NULL; @@ -490,15 +486,15 @@ struct request_queue * request_queue_init() queue->dirtyHead.next = queue->dirtyHead.prev = &(queue->dirtyHead); queue->renderHead.next = queue->renderHead.prev = &(queue->renderHead); queue->hashidxSize = HASHIDX_SIZE; - queue->item_hashidx = (struct item_idx *) malloc(sizeof(struct item_idx) * queue->hashidxSize); + queue->item_hashidx = (struct item_idx *)malloc(sizeof(struct item_idx) * queue->hashidxSize); bzero(queue->item_hashidx, sizeof(struct item_idx) * queue->hashidxSize); return queue; } -void request_queue_close(struct request_queue * queue) +void request_queue_close(struct request_queue *queue) { - //TODO: Free items if the queues are not empty at closing time + // TODO: Free items if the queues are not empty at closing time pthread_mutex_destroy(&(queue->qLock)); free(queue->item_hashidx); free(queue); diff --git a/src/store.c b/src/store.c index b25a09c2..b361f722 100644 --- a/src/store.c +++ b/src/store.c @@ -1,28 +1,27 @@ /* wrapper for storage engines */ +#include +#include +#include #include #include -#include -#include #include -#include -#include -#include #include +#include +#include #ifdef HAVE_PTHREAD #include #endif - +#include "g_logger.h" #include "store.h" #include "store_file.h" #include "store_memcached.h" +#include "store_null.h" #include "store_rados.h" -#include "store_ro_http_proxy.h" #include "store_ro_composite.h" -#include "store_null.h" -#include "g_logger.h" +#include "store_ro_http_proxy.h" /** * In Apache 2.2, we call the init_storage_backend once per process. For mpm_worker and mpm_event multiple threads therefore use the same @@ -30,12 +29,12 @@ * * In Apache 2.4, we call the init_storage_backend once per thread, and therefore each thread has its own storage context to work with. */ -struct storage_backend * init_storage_backend(const char * options) +struct storage_backend *init_storage_backend(const char *options) { struct stat st; - struct storage_backend * store = NULL; + struct storage_backend *store = NULL; - //Determine the correct storage backend based on the options string + // Determine the correct storage backend based on the options string if (strlen(options) == 0) { g_logger(G_LOG_LEVEL_ERROR, "init_storage_backend: Options string was empty"); return NULL; diff --git a/src/store_file.c b/src/store_file.c index b1409aa7..bd51d005 100644 --- a/src/store_file.c +++ b/src/store_file.c @@ -23,29 +23,28 @@ * utilisation of disk space. */ +#include +#include +#include +#include +#include #include #include -#include -#include #include -#include #include +#include +#include #include -#include -#include -#include -#include -#include "store.h" +#include "g_logger.h" #include "metatile.h" +#include "protocol.h" #include "render_config.h" +#include "store.h" #include "store_file.h" #include "store_file_utils.h" -#include "protocol.h" -#include "g_logger.h" - -static time_t getPlanetTime(const char * tile_dir, const char * xmlname) +static time_t getPlanetTime(const char *tile_dir, const char *xmlname) { struct stat st_stat; char filename[PATH_MAX]; @@ -64,7 +63,7 @@ static time_t getPlanetTime(const char * tile_dir, const char * xmlname) return st_stat.st_mtime; } -static int file_tile_read(struct storage_backend * store, const char *xmlconfig, const char *options, int x, int y, int z, char *buf, size_t sz, int * compressed, char * log_msg) +static int file_tile_read(struct storage_backend *store, const char *xmlconfig, const char *options, int x, int y, int z, char *buf, size_t sz, int *compressed, char *log_msg) { char path[PATH_MAX]; @@ -88,7 +87,7 @@ static int file_tile_read(struct storage_backend * store, const char *xmlconfig, while (pos < header_len) { size_t len = header_len - pos; - int got = read(fd, ((unsigned char *) m) + pos, len); + int got = read(fd, ((unsigned char *)m) + pos, len); if (got < 0) { snprintf(log_msg, PATH_MAX - 1, "Failed to read complete header for metatile %s Reason: %s\n", path, strerror(errno)); @@ -131,7 +130,7 @@ static int file_tile_read(struct storage_backend * store, const char *xmlconfig, } file_offset = m->index[meta_offset].offset; - tile_size = m->index[meta_offset].size; + tile_size = m->index[meta_offset].size; free(m); @@ -169,7 +168,7 @@ static int file_tile_read(struct storage_backend * store, const char *xmlconfig, return pos; } -static struct stat_info file_tile_stat(struct storage_backend * store, const char *xmlconfig, const char *options, int x, int y, int z) +static struct stat_info file_tile_stat(struct storage_backend *store, const char *xmlconfig, const char *options, int x, int y, int z) { struct stat_info tile_stat; struct stat st_stat; @@ -198,7 +197,7 @@ static struct stat_info file_tile_stat(struct storage_backend * store, const cha return tile_stat; } -static char * file_tile_storage_id(struct storage_backend * store, const char *xmlconfig, const char *options, int x, int y, int z, char * string) +static char *file_tile_storage_id(struct storage_backend *store, const char *xmlconfig, const char *options, int x, int y, int z, char *string) { char meta_path[PATH_MAX]; @@ -207,26 +206,24 @@ static char * file_tile_storage_id(struct storage_backend * store, const char *x return string; } - -static int file_metatile_write(struct storage_backend * store, const char *xmlconfig, const char *options, int x, int y, int z, const char *buf, int sz) +static int file_metatile_write(struct storage_backend *store, const char *xmlconfig, const char *options, int x, int y, int z, const char *buf, int sz) { int fd; char meta_path[PATH_MAX]; - char * tmp; + char *tmp; int res; xyzo_to_meta(meta_path, sizeof(meta_path), (char *)(store->storage_ctx), xmlconfig, options, x, y, z); g_logger(G_LOG_LEVEL_DEBUG, "Creating and writing a metatile to %s", meta_path); tmp = malloc(sizeof(char) * strlen(meta_path) + 24); - snprintf(tmp, strlen(meta_path) + 24, "%s.%lu", meta_path, (unsigned long) pthread_self()); + snprintf(tmp, strlen(meta_path) + 24, "%s.%lu", meta_path, (unsigned long)pthread_self()); if (mkdirp(tmp)) { free(tmp); return -1; } - fd = open(tmp, O_WRONLY | O_TRUNC | O_CREAT, 0666); if (fd < 0) { @@ -251,17 +248,17 @@ static int file_metatile_write(struct storage_backend * store, const char *xmlco return sz; } -static int file_metatile_delete(struct storage_backend * store, const char *xmlconfig, int x, int y, int z) +static int file_metatile_delete(struct storage_backend *store, const char *xmlconfig, int x, int y, int z) { char meta_path[PATH_MAX]; - //TODO: deal with options + // TODO: deal with options xyz_to_meta(meta_path, sizeof(meta_path), (char *)(store->storage_ctx), xmlconfig, x, y, z); g_logger(G_LOG_LEVEL_DEBUG, "Deleting metatile from %s", meta_path); return unlink(meta_path); } -static int file_metatile_expire(struct storage_backend * store, const char *xmlconfig, int x, int y, int z) +static int file_metatile_expire(struct storage_backend *store, const char *xmlconfig, int x, int y, int z) { char name[PATH_MAX]; @@ -269,17 +266,17 @@ static int file_metatile_expire(struct storage_backend * store, const char *xmlc static struct tm touchCalendar; struct utimbuf touchTime; - //TODO: deal with options + // TODO: deal with options xyz_to_meta(name, sizeof(name), store->storage_ctx, xmlconfig, x, y, z); - if (stat(name, &s) == 0) {// 0 is success + if (stat(name, &s) == 0) { // 0 is success // tile exists on disk; mark it as expired if (!gmtime_r(&(s.st_mtime), &touchCalendar)) { touchTime.modtime = 315558000; } else { - if (touchCalendar.tm_year > 105) { // Tile hasn't already been marked as expired - touchCalendar.tm_year -= 20; //Set back by 20 years, to keep the creation time as reference. + if (touchCalendar.tm_year > 105) { // Tile hasn't already been marked as expired + touchCalendar.tm_year -= 20; // Set back by 20 years, to keep the creation time as reference. touchTime.modtime = mktime(&touchCalendar); } else { touchTime.modtime = s.st_mtime; @@ -296,17 +293,17 @@ static int file_metatile_expire(struct storage_backend * store, const char *xmlc return 0; } -static int file_close_storage(struct storage_backend * store) +static int file_close_storage(struct storage_backend *store) { free(store->storage_ctx); store->storage_ctx = NULL; return 0; } -struct storage_backend * init_storage_file(const char * tile_dir) +struct storage_backend *init_storage_file(const char *tile_dir) { - struct storage_backend * store = malloc(sizeof(struct storage_backend)); + struct storage_backend *store = malloc(sizeof(struct storage_backend)); if (store == NULL) { g_logger(G_LOG_LEVEL_ERROR, "init_storage_file: Failed to allocate memory for storage backend"); diff --git a/src/store_file_utils.c b/src/store_file_utils.c index 6c46efa3..bafd285b 100644 --- a/src/store_file_utils.c +++ b/src/store_file_utils.c @@ -15,20 +15,20 @@ * along with this program; If not, see http://www.gnu.org/licenses/. */ +#include +#include #include #include -#include -#include #include -#include #include -#include +#include +#include +#include "g_logger.h" #include "protocol.h" #include "render_config.h" #include "store_file.h" #include "store_file_utils.h" -#include "g_logger.h" // Build parent directories for the specified file name // Note: the part following the trailing / is ignored @@ -90,8 +90,6 @@ int mkdirp(const char *path) return 0; } - - /* File path hashing. Used by both mod_tile and render daemon * The two must both agree on the file layout for meta-tiling * to work @@ -230,7 +228,7 @@ void xyz_to_path(char *path, size_t len, const char *tile_dir, const char *xmlco } snprintf(path, len, "%s/%s/%d/%u/%u/%u/%u/%u.png", tile_dir, xmlconfig, z, hash[4], hash[3], hash[2], hash[1], hash[0]); -#else // DIRECTORY_HASH +#else // DIRECTORY_HASH snprintf(path, len, TILE_PATH "/%s/%d/%d/%d.png", xmlconfig, z, x, y); #endif // DIRECTORY_HASH return; diff --git a/src/store_memcached.c b/src/store_memcached.c index 2353e085..c620aad6 100644 --- a/src/store_memcached.c +++ b/src/store_memcached.c @@ -24,27 +24,26 @@ */ #include "config.h" +#include #include #include -#include -#include #include #include #include +#include #ifdef HAVE_LIBMEMCACHED #include #endif -#include "store.h" +#include "g_logger.h" #include "metatile.h" -#include "render_config.h" #include "protocol.h" -#include "g_logger.h" - +#include "render_config.h" +#include "store.h" #ifdef HAVE_LIBMEMCACHED -static char * memcached_xyzo_to_storagekey(const char *xmlconfig, const char *options, int x, int y, int z, char * key) +static char *memcached_xyzo_to_storagekey(const char *xmlconfig, const char *options, int x, int y, int z, char *key) { int mask; @@ -61,12 +60,12 @@ static char * memcached_xyzo_to_storagekey(const char *xmlconfig, const char *op return key; } -static char * memcached_xyz_to_storagekey(const char *xmlconfig, int x, int y, int z, char * key) +static char *memcached_xyz_to_storagekey(const char *xmlconfig, int x, int y, int z, char *key) { return memcached_xyzo_to_storagekey(xmlconfig, "", x, y, z, key); } -static int memcached_tile_read(struct storage_backend * store, const char *xmlconfig, const char *options, int x, int y, int z, char *buf, size_t sz, int * compressed, char * log_msg) +static int memcached_tile_read(struct storage_backend *store, const char *xmlconfig, const char *options, int x, int y, int z, char *buf, size_t sz, int *compressed, char *log_msg) { char meta_path[PATH_MAX]; @@ -78,7 +77,7 @@ static int memcached_tile_read(struct storage_backend * store, const char *xmlco uint32_t flags; size_t len; memcached_return_t rc; - char * buf_raw; + char *buf_raw; mask = METATILE - 1; meta_offset = (x & mask) * METATILE + (y & mask); @@ -113,7 +112,7 @@ static int memcached_tile_read(struct storage_backend * store, const char *xmlco } file_offset = m->index[meta_offset].offset + sizeof(struct stat_info); - tile_size = m->index[meta_offset].size; + tile_size = m->index[meta_offset].size; free(m); @@ -128,13 +127,13 @@ static int memcached_tile_read(struct storage_backend * store, const char *xmlco return tile_size; } -static struct stat_info memcached_tile_stat(struct storage_backend * store, const char *xmlconfig, const char *options, int x, int y, int z) +static struct stat_info memcached_tile_stat(struct storage_backend *store, const char *xmlconfig, const char *options, int x, int y, int z) { struct stat_info tile_stat; char meta_path[PATH_MAX]; unsigned int header_len = sizeof(struct meta_layout) + METATILE * METATILE * sizeof(struct entry); struct meta_layout *m = (struct meta_layout *)malloc(header_len); - char * buf; + char *buf; size_t len; uint32_t flags; memcached_return_t rc; @@ -165,21 +164,20 @@ static struct stat_info memcached_tile_stat(struct storage_backend * store, cons return tile_stat; } - -static char * memcached_tile_storage_id(struct storage_backend * store, const char *xmlconfig, const char *options, int x, int y, int z, char * string) +static char *memcached_tile_storage_id(struct storage_backend *store, const char *xmlconfig, const char *options, int x, int y, int z, char *string) { snprintf(string, PATH_MAX - 1, "memcached:///%s/%d/%d/%d.meta", xmlconfig, x, y, z); return string; } -static int memcached_metatile_write(struct storage_backend * store, const char *xmlconfig, const char *options, int x, int y, int z, const char *buf, int sz) +static int memcached_metatile_write(struct storage_backend *store, const char *xmlconfig, const char *options, int x, int y, int z, const char *buf, int sz) { char meta_path[PATH_MAX]; char tmp[PATH_MAX]; struct stat_info tile_stat; int sz2 = sz + sizeof(struct stat_info); - char * buf2 = malloc(sz2); + char *buf2 = malloc(sz2); memcached_return_t rc; if (buf2 == NULL) { @@ -210,13 +208,12 @@ static int memcached_metatile_write(struct storage_backend * store, const char * return sz; } - -static int memcached_metatile_delete(struct storage_backend * store, const char *xmlconfig, int x, int y, int z) +static int memcached_metatile_delete(struct storage_backend *store, const char *xmlconfig, int x, int y, int z) { char meta_path[PATH_MAX]; memcached_return_t rc; - //TODO: deal with options + // TODO: deal with options memcached_xyz_to_storagekey(xmlconfig, x, y, z, meta_path); rc = memcached_delete(store->storage_ctx, meta_path, strlen(meta_path), 0); @@ -228,17 +225,17 @@ static int memcached_metatile_delete(struct storage_backend * store, const char return 0; } -static int memcached_metatile_expire(struct storage_backend * store, const char *xmlconfig, int x, int y, int z) +static int memcached_metatile_expire(struct storage_backend *store, const char *xmlconfig, int x, int y, int z) { char meta_path[PATH_MAX]; - char * buf; + char *buf; size_t len; uint32_t flags; uint64_t cas; memcached_return_t rc; - //TODO: deal with options + // TODO: deal with options memcached_xyz_to_storagekey(xmlconfig, x, y, z, meta_path); buf = memcached_get(store->storage_ctx, meta_path, strlen(meta_path), &len, &flags, &rc); @@ -246,7 +243,7 @@ static int memcached_metatile_expire(struct storage_backend * store, const char return -1; } - //cas = memcached_result_cas(&rc); + // cas = memcached_result_cas(&rc); ((struct stat_info *)buf)->expired = 1; @@ -261,23 +258,23 @@ static int memcached_metatile_expire(struct storage_backend * store, const char return 0; } -static int memcached_close_storage(struct storage_backend * store) +static int memcached_close_storage(struct storage_backend *store) { memcached_free(store->storage_ctx); return 0; } -#endif //Have memcached +#endif // Have memcached -struct storage_backend * init_storage_memcached(const char * connection_string) +struct storage_backend *init_storage_memcached(const char *connection_string) { #ifndef HAVE_LIBMEMCACHED g_logger(G_LOG_LEVEL_ERROR, "init_storage_memcached: Support for memcached has not been compiled into this program"); return NULL; #else - struct storage_backend * store = malloc(sizeof(struct storage_backend)); - memcached_st * ctx; - char * connection_str = "--server=localhost"; + struct storage_backend *store = malloc(sizeof(struct storage_backend)); + memcached_st *ctx; + char *connection_str = "--server=localhost"; if (store == NULL) { g_logger(G_LOG_LEVEL_ERROR, "init_storage_memcached: Failed to allocate memory for storage backend"); diff --git a/src/store_null.c b/src/store_null.c index 1d8730c0..aed7d630 100644 --- a/src/store_null.c +++ b/src/store_null.c @@ -24,18 +24,18 @@ #include "store.h" #include "store_null.h" -static int tile_read(struct storage_backend * store, +static int tile_read(struct storage_backend *store, const char *xmlconfig, const char *options, int x, int y, int z, char *buf, size_t sz, - int * compressed, char * err_msg) + int *compressed, char *err_msg) { snprintf(err_msg, PATH_MAX - 1, "Cannot read from NULL storage."); return -1; } -static struct stat_info tile_stat(struct storage_backend * store, +static struct stat_info tile_stat(struct storage_backend *store, const char *xmlconfig, const char *options, int x, int y, int z) @@ -49,7 +49,7 @@ static struct stat_info tile_stat(struct storage_backend * store, return tile_stat; } -static int metatile_write(struct storage_backend * store, +static int metatile_write(struct storage_backend *store, const char *xmlconfig, const char *options, int x, int y, int z, @@ -59,38 +59,38 @@ static int metatile_write(struct storage_backend * store, return sz; } -static int metatile_delete(struct storage_backend * store, +static int metatile_delete(struct storage_backend *store, const char *xmlconfig, int x, int y, int z) { return 0; } -static int metatile_expire(struct storage_backend * store, +static int metatile_expire(struct storage_backend *store, const char *xmlconfig, int x, int y, int z) { return 0; } -static char * tile_storage_id(struct storage_backend * store, - const char *xmlconfig, - const char *options, - int x, int y, int z, - char * string) +static char *tile_storage_id(struct storage_backend *store, + const char *xmlconfig, + const char *options, + int x, int y, int z, + char *string) { snprintf(string, PATH_MAX - 1, "null://"); return string; } -static int close_storage(struct storage_backend * store) +static int close_storage(struct storage_backend *store) { return 0; } struct storage_backend *init_storage_null() { - struct storage_backend *store = malloc(sizeof * store); + struct storage_backend *store = malloc(sizeof *store); if (store == NULL) { g_logger(G_LOG_LEVEL_ERROR, "init_storage_null: Failed to allocate memory for storage backend"); diff --git a/src/store_rados.c b/src/store_rados.c index 4d3cd16a..88f18d37 100644 --- a/src/store_rados.c +++ b/src/store_rados.c @@ -24,46 +24,45 @@ */ #include "config.h" +#include +#include +#include #include #include -#include -#include #include #include #include -#include -#include +#include #ifdef HAVE_LIBRADOS #include #endif -#include "store.h" -#include "store_rados.h" +#include "g_logger.h" #include "metatile.h" -#include "render_config.h" #include "protocol.h" -#include "g_logger.h" - +#include "render_config.h" +#include "store.h" +#include "store_rados.h" #ifdef HAVE_LIBRADOS static pthread_mutex_t qLock; struct metadata_cache { - char * data; + char *data; int x, y, z; char xmlname[XMLCONFIG_MAX]; }; struct rados_ctx { - char * pool; + char *pool; rados_t cluster; rados_ioctx_t io; struct metadata_cache metadata_cache; }; -static char * rados_xyzo_to_storagekey(const char *xmlconfig, const char *options, int x, int y, int z, char * key) +static char *rados_xyzo_to_storagekey(const char *xmlconfig, const char *options, int x, int y, int z, char *key) { int mask; @@ -80,12 +79,12 @@ static char * rados_xyzo_to_storagekey(const char *xmlconfig, const char *option return key; } -static char * read_meta_data(struct storage_backend * store, const char *xmlconfig, const char *options, int x, int y, int z) +static char *read_meta_data(struct storage_backend *store, const char *xmlconfig, const char *options, int x, int y, int z) { int mask; int err; char meta_path[PATH_MAX]; - struct rados_ctx * ctx = (struct rados_ctx *)store->storage_ctx; + struct rados_ctx *ctx = (struct rados_ctx *)store->storage_ctx; unsigned int header_len = sizeof(struct stat_info) + sizeof(struct meta_layout) + METATILE * METATILE * sizeof(struct entry); mask = METATILE - 1; @@ -121,8 +120,7 @@ static char * read_meta_data(struct storage_backend * store, const char *xmlconf } } - -static int rados_tile_read(struct storage_backend * store, const char *xmlconfig, const char *options, int x, int y, int z, char *buf, size_t sz, int * compressed, char * log_msg) +static int rados_tile_read(struct storage_backend *store, const char *xmlconfig, const char *options, int x, int y, int z, char *buf, size_t sz, int *compressed, char *log_msg) { char meta_path[PATH_MAX]; @@ -132,7 +130,7 @@ static int rados_tile_read(struct storage_backend * store, const char *xmlconfig size_t file_offset, tile_size; int mask; int err; - char * buf_raw; + char *buf_raw; mask = METATILE - 1; meta_offset = (x & mask) * METATILE + (y & mask); @@ -169,7 +167,7 @@ static int rados_tile_read(struct storage_backend * store, const char *xmlconfig } file_offset = m->index[meta_offset].offset + sizeof(struct stat_info); - tile_size = m->index[meta_offset].size; + tile_size = m->index[meta_offset].size; free(m); @@ -189,10 +187,10 @@ static int rados_tile_read(struct storage_backend * store, const char *xmlconfig return tile_size; } -static struct stat_info rados_tile_stat(struct storage_backend * store, const char *xmlconfig, const char *options, int x, int y, int z) +static struct stat_info rados_tile_stat(struct storage_backend *store, const char *xmlconfig, const char *options, int x, int y, int z) { struct stat_info tile_stat; - char * buf; + char *buf; int offset, mask; mask = METATILE - 1; @@ -215,8 +213,7 @@ static struct stat_info rados_tile_stat(struct storage_backend * store, const ch return tile_stat; } - -static char * rados_tile_storage_id(struct storage_backend * store, const char *xmlconfig, const char *options, int x, int y, int z, char * string) +static char *rados_tile_storage_id(struct storage_backend *store, const char *xmlconfig, const char *options, int x, int y, int z, char *string) { char meta_path[PATH_MAX]; @@ -225,13 +222,13 @@ static char * rados_tile_storage_id(struct storage_backend * store, const char * return string; } -static int rados_metatile_write(struct storage_backend * store, const char *xmlconfig, const char *options, int x, int y, int z, const char *buf, int sz) +static int rados_metatile_write(struct storage_backend *store, const char *xmlconfig, const char *options, int x, int y, int z, const char *buf, int sz) { char meta_path[PATH_MAX]; char tmp[PATH_MAX]; struct stat_info tile_stat; int sz2 = sz + sizeof(struct stat_info); - char * buf2 = malloc(sz2); + char *buf2 = malloc(sz2); int err; tile_stat.expired = 0; @@ -259,19 +256,18 @@ static int rados_metatile_write(struct storage_backend * store, const char *xmlc return sz; } - -static int rados_metatile_delete(struct storage_backend * store, const char *xmlconfig, int x, int y, int z) +static int rados_metatile_delete(struct storage_backend *store, const char *xmlconfig, int x, int y, int z) { - struct rados_ctx * ctx = (struct rados_ctx *)store->storage_ctx; + struct rados_ctx *ctx = (struct rados_ctx *)store->storage_ctx; char meta_path[PATH_MAX]; char tmp[PATH_MAX]; int err; - //TODO: deal with options + // TODO: deal with options const char *options = ""; rados_xyzo_to_storagekey(xmlconfig, options, x, y, z, meta_path); - err = rados_remove(ctx->io, meta_path); + err = rados_remove(ctx->io, meta_path); if (err < 0) { g_logger(G_LOG_LEVEL_ERROR, "failed to delete %s: %s", rados_tile_storage_id(store, xmlconfig, options, x, y, z, tmp), strerror(-err)); @@ -281,16 +277,16 @@ static int rados_metatile_delete(struct storage_backend * store, const char *xml return 0; } -static int rados_metatile_expire(struct storage_backend * store, const char *xmlconfig, int x, int y, int z) +static int rados_metatile_expire(struct storage_backend *store, const char *xmlconfig, int x, int y, int z) { struct stat_info tile_stat; - struct rados_ctx * ctx = (struct rados_ctx *)store->storage_ctx; + struct rados_ctx *ctx = (struct rados_ctx *)store->storage_ctx; char meta_path[PATH_MAX]; char tmp[PATH_MAX]; int err; - //TODO: deal with options + // TODO: deal with options const char *options = ""; rados_xyzo_to_storagekey(xmlconfig, options, x, y, z, meta_path); err = rados_read(ctx->io, meta_path, (char *)&tile_stat, sizeof(struct stat_info), 0); @@ -318,10 +314,9 @@ static int rados_metatile_expire(struct storage_backend * store, const char *xml return 0; } - -static int rados_close_storage(struct storage_backend * store) +static int rados_close_storage(struct storage_backend *store) { - struct rados_ctx * ctx = (struct rados_ctx *)store->storage_ctx; + struct rados_ctx *ctx = (struct rados_ctx *)store->storage_ctx; rados_ioctx_destroy(ctx->io); rados_shutdown(ctx->cluster); @@ -332,22 +327,19 @@ static int rados_close_storage(struct storage_backend * store) return 0; } +#endif // Have rados -#endif //Have rados - - - -struct storage_backend * init_storage_rados(const char * connection_string) +struct storage_backend *init_storage_rados(const char *connection_string) { #ifndef HAVE_LIBRADOS g_logger(G_LOG_LEVEL_ERROR, "init_storage_rados: Support for rados has not been compiled into this program"); return NULL; #else - struct rados_ctx * ctx = malloc(sizeof(struct rados_ctx)); - struct storage_backend * store = malloc(sizeof(struct storage_backend)); - char * conf = NULL; - const char * tmp; + struct rados_ctx *ctx = malloc(sizeof(struct rados_ctx)); + struct storage_backend *store = malloc(sizeof(struct storage_backend)); + char *conf = NULL; + const char *tmp; int err; int i; @@ -426,7 +418,6 @@ struct storage_backend * init_storage_rados(const char * connection_string) ctx->metadata_cache.z = -1; ctx->metadata_cache.xmlname[0] = 0; - store->storage_ctx = ctx; store->tile_read = &rados_tile_read; diff --git a/src/store_ro_composite.c b/src/store_ro_composite.c index 998be917..167495a2 100644 --- a/src/store_ro_composite.c +++ b/src/store_ro_composite.c @@ -18,10 +18,10 @@ #include "config.h" #include #include -#include #include +#include -//TODO: need to create an appropriate configure check. +// TODO: need to create an appropriate configure check. #ifdef HAVE_CAIRO #define WANT_STORE_COMPOSITE #endif @@ -30,26 +30,25 @@ #include #endif +#include "g_logger.h" +#include "protocol.h" +#include "render_config.h" #include "store.h" #include "store_ro_composite.h" -#include "render_config.h" -#include "protocol.h" -#include "g_logger.h" - #ifdef WANT_STORE_COMPOSITE struct tile_cache { struct stat_info st_stat; - char * tile; + char *tile; int x, y, z; char xmlname[XMLCONFIG_MAX]; }; struct ro_composite_ctx { - struct storage_backend * store_primary; + struct storage_backend *store_primary; char xmlconfig_primary[XMLCONFIG_MAX]; - struct storage_backend * store_secondary; + struct storage_backend *store_secondary; char xmlconfig_secondary[XMLCONFIG_MAX]; struct tile_cache cache; int render_size; @@ -63,7 +62,7 @@ typedef struct { static cairo_status_t write_png_stream_to_byte_array(void *in_closure, const unsigned char *data, unsigned int length) { - png_stream_to_byte_array_closure_t *closure = (png_stream_to_byte_array_closure_t *) in_closure; + png_stream_to_byte_array_closure_t *closure = (png_stream_to_byte_array_closure_t *)in_closure; g_logger(G_LOG_LEVEL_DEBUG, "ro_composite_tile: writing to byte array: pos: %i, length: %i", closure->pos, length); @@ -79,7 +78,7 @@ static cairo_status_t write_png_stream_to_byte_array(void *in_closure, const uns static cairo_status_t read_png_stream_from_byte_array(void *in_closure, unsigned char *data, unsigned int length) { - png_stream_to_byte_array_closure_t *closure = (png_stream_to_byte_array_closure_t *) in_closure; + png_stream_to_byte_array_closure_t *closure = (png_stream_to_byte_array_closure_t *)in_closure; g_logger(G_LOG_LEVEL_DEBUG, "ro_composite_tile: reading from byte array: pos: %i, length: %i", closure->pos, length); @@ -93,10 +92,9 @@ static cairo_status_t read_png_stream_from_byte_array(void *in_closure, unsigned return CAIRO_STATUS_SUCCESS; } - -static int ro_composite_tile_read(struct storage_backend * store, const char *xmlconfig, const char *options, int x, int y, int z, char *buf, size_t sz, int * compressed, char * log_msg) +static int ro_composite_tile_read(struct storage_backend *store, const char *xmlconfig, const char *options, int x, int y, int z, char *buf, size_t sz, int *compressed, char *log_msg) { - struct ro_composite_ctx * ctx = (struct ro_composite_ctx *)(store->storage_ctx); + struct ro_composite_ctx *ctx = (struct ro_composite_ctx *)(store->storage_ctx); cairo_surface_t *imageA; cairo_surface_t *imageB; cairo_surface_t *imageC; @@ -144,7 +142,7 @@ static int ro_composite_tile_read(struct storage_backend * store, const char *xm return -1; } - //Create the cairo context + // Create the cairo context cr = cairo_create(imageC); cairo_set_source_surface(cr, imageA, 0, 0); cairo_paint(cr); @@ -165,43 +163,40 @@ static int ro_composite_tile_read(struct storage_backend * store, const char *xm return closure.pos; } -static struct stat_info ro_composite_tile_stat(struct storage_backend * store, const char *xmlconfig, const char *options, int x, int y, int z) +static struct stat_info ro_composite_tile_stat(struct storage_backend *store, const char *xmlconfig, const char *options, int x, int y, int z) { - struct ro_composite_ctx * ctx = (struct ro_composite_ctx *)(store->storage_ctx); + struct ro_composite_ctx *ctx = (struct ro_composite_ctx *)(store->storage_ctx); return ctx->store_primary->tile_stat(ctx->store_primary, ctx->xmlconfig_primary, options, x, y, z); } - -static char * ro_composite_tile_storage_id(struct storage_backend * store, const char *xmlconfig, const char *options, int x, int y, int z, char * string) +static char *ro_composite_tile_storage_id(struct storage_backend *store, const char *xmlconfig, const char *options, int x, int y, int z, char *string) { return "Coposite tile"; } -static int ro_composite_metatile_write(struct storage_backend * store, const char *xmlconfig, const char *options, int x, int y, int z, const char *buf, int sz) +static int ro_composite_metatile_write(struct storage_backend *store, const char *xmlconfig, const char *options, int x, int y, int z, const char *buf, int sz) { g_logger(G_LOG_LEVEL_ERROR, "ro_composite_metatile_write: This is a readonly storage backend. Write functionality isn't implemented"); return -1; } - -static int ro_composite_metatile_delete(struct storage_backend * store, const char *xmlconfig, int x, int y, int z) +static int ro_composite_metatile_delete(struct storage_backend *store, const char *xmlconfig, int x, int y, int z) { g_logger(G_LOG_LEVEL_ERROR, "ro_composite_metatile_expire: This is a readonly storage backend. Write functionality isn't implemented"); return -1; } -static int ro_composite_metatile_expire(struct storage_backend * store, const char *xmlconfig, int x, int y, int z) +static int ro_composite_metatile_expire(struct storage_backend *store, const char *xmlconfig, int x, int y, int z) { g_logger(G_LOG_LEVEL_ERROR, "ro_composite_metatile_expire: This is a readonly storage backend. Write functionality isn't implemented"); return -1; } - -static int ro_composite_close_storage(struct storage_backend * store) +static int ro_composite_close_storage(struct storage_backend *store) { - struct ro_composite_ctx * ctx = (struct ro_composite_ctx *)(store->storage_ctx); + struct ro_composite_ctx *ctx = (struct ro_composite_ctx *)(store->storage_ctx); ctx->store_primary->close_storage(ctx->store_primary); ctx->store_secondary->close_storage(ctx->store_secondary); @@ -214,22 +209,20 @@ static int ro_composite_close_storage(struct storage_backend * store) return 0; } -#endif //WANT_COMPOSITE - - +#endif // WANT_COMPOSITE -struct storage_backend * init_storage_ro_composite(const char * connection_string) +struct storage_backend *init_storage_ro_composite(const char *connection_string) { #ifndef WANT_STORE_COMPOSITE g_logger(G_LOG_LEVEL_ERROR, "init_storage_ro_coposite: Support for compositing storage has not been compiled into this program"); return NULL; #else - struct storage_backend * store = malloc(sizeof(struct storage_backend)); - struct ro_composite_ctx * ctx = malloc(sizeof(struct ro_composite_ctx)); - char * connection_string_primary; - char * connection_string_secondary; - char * tmp; + struct storage_backend *store = malloc(sizeof(struct storage_backend)); + struct ro_composite_ctx *ctx = malloc(sizeof(struct ro_composite_ctx)); + char *connection_string_primary; + char *connection_string_secondary; + char *tmp; g_logger(G_LOG_LEVEL_DEBUG, "init_storage_ro_composite: initialising compositing storage backend for %s", connection_string); diff --git a/src/store_ro_http_proxy.c b/src/store_ro_http_proxy.c index dabcf6ca..13ca2e29 100644 --- a/src/store_ro_http_proxy.c +++ b/src/store_ro_http_proxy.c @@ -16,25 +16,24 @@ */ #include "config.h" +#include +#include #include #include -#include -#include #include #include -#include +#include #ifdef HAVE_LIBCURL #include #include #endif +#include "g_logger.h" +#include "protocol.h" +#include "render_config.h" #include "store.h" #include "store_ro_http_proxy.h" -#include "render_config.h" -#include "protocol.h" -#include "g_logger.h" - #ifdef HAVE_LIBCURL @@ -43,14 +42,14 @@ static int done_global_init = 0; struct tile_cache { struct stat_info st_stat; - char * tile; + char *tile; int x, y, z; char xmlname[XMLCONFIG_MAX]; }; struct ro_http_proxy_ctx { - CURL * ctx; - char * baseurl; + CURL *ctx; + char *baseurl; struct tile_cache cache; }; @@ -59,11 +58,10 @@ struct MemoryStruct { size_t size; }; - static size_t write_memory_callback(void *contents, size_t size, size_t nmemb, void *userp) { size_t realsize = size * nmemb; - struct MemoryStruct * chunk = userp; + struct MemoryStruct *chunk = userp; if (chunk->memory) { chunk->memory = realloc(chunk->memory, chunk->size + realsize); @@ -79,21 +77,21 @@ static size_t write_memory_callback(void *contents, size_t size, size_t nmemb, v return realsize; } -static char * ro_http_proxy_xyz_to_storagekey(struct storage_backend * store, int x, int y, int z, char * key) +static char *ro_http_proxy_xyz_to_storagekey(struct storage_backend *store, int x, int y, int z, char *key) { snprintf(key, PATH_MAX - 1, "http://%s/%i/%i/%i.png", ((struct ro_http_proxy_ctx *)(store->storage_ctx))->baseurl, z, x, y); return key; } -static int ro_http_proxy_tile_retrieve(struct storage_backend * store, const char *xmlconfig, const char *options, int x, int y, int z) +static int ro_http_proxy_tile_retrieve(struct storage_backend *store, const char *xmlconfig, const char *options, int x, int y, int z) { - struct ro_http_proxy_ctx * ctx = (struct ro_http_proxy_ctx *)(store->storage_ctx); - char * path; + struct ro_http_proxy_ctx *ctx = (struct ro_http_proxy_ctx *)(store->storage_ctx); + char *path; CURLcode res; struct MemoryStruct chunk; long httpCode; - //TODO: Deal with options + // TODO: Deal with options if ((ctx->cache.x == x) && (ctx->cache.y == y) && (ctx->cache.z == z) && (strcmp(ctx->cache.xmlname, xmlconfig) == 0)) { g_logger(G_LOG_LEVEL_DEBUG, "ro_http_proxy_tile_fetch: Got a cached tile"); return 1; @@ -133,31 +131,30 @@ static int ro_http_proxy_tile_retrieve(struct storage_backend * store, const cha } switch (httpCode) { - case 200: { - if (ctx->cache.tile != NULL) { - free(ctx->cache.tile); - } - - ctx->cache.tile = chunk.memory; - ctx->cache.st_stat.size = chunk.size; - ctx->cache.st_stat.expired = 0; - res = curl_easy_getinfo(ctx->ctx, CURLINFO_FILETIME, &(ctx->cache.st_stat.mtime)); - ctx->cache.st_stat.atime = 0; - g_logger(G_LOG_LEVEL_DEBUG, "ro_http_proxy_tile_read: Read file of size %lu", chunk.size); - break; + case 200: { + if (ctx->cache.tile != NULL) { + free(ctx->cache.tile); } - case 404: { - if (ctx->cache.tile != NULL) { - free(ctx->cache.tile); - } + ctx->cache.tile = chunk.memory; + ctx->cache.st_stat.size = chunk.size; + ctx->cache.st_stat.expired = 0; + res = curl_easy_getinfo(ctx->ctx, CURLINFO_FILETIME, &(ctx->cache.st_stat.mtime)); + ctx->cache.st_stat.atime = 0; + g_logger(G_LOG_LEVEL_DEBUG, "ro_http_proxy_tile_read: Read file of size %lu", chunk.size); + break; + } - ctx->cache.st_stat.size = -1; - ctx->cache.st_stat.expired = 0; - break; + case 404: { + if (ctx->cache.tile != NULL) { + free(ctx->cache.tile); } - } + ctx->cache.st_stat.size = -1; + ctx->cache.st_stat.expired = 0; + break; + } + } ctx->cache.x = x; ctx->cache.y = y; @@ -167,9 +164,9 @@ static int ro_http_proxy_tile_retrieve(struct storage_backend * store, const cha } } -static int ro_http_proxy_tile_read(struct storage_backend * store, const char *xmlconfig, const char *options, int x, int y, int z, char *buf, size_t sz, int * compressed, char * log_msg) +static int ro_http_proxy_tile_read(struct storage_backend *store, const char *xmlconfig, const char *options, int x, int y, int z, char *buf, size_t sz, int *compressed, char *log_msg) { - struct ro_http_proxy_ctx * ctx = (struct ro_http_proxy_ctx *)(store->storage_ctx); + struct ro_http_proxy_ctx *ctx = (struct ro_http_proxy_ctx *)(store->storage_ctx); if (ro_http_proxy_tile_retrieve(store, xmlconfig, options, x, y, z) > 0) { if (ctx->cache.st_stat.size > sz) { @@ -185,10 +182,10 @@ static int ro_http_proxy_tile_read(struct storage_backend * store, const char *x } } -static struct stat_info ro_http_proxy_tile_stat(struct storage_backend * store, const char *xmlconfig, const char *options, int x, int y, int z) +static struct stat_info ro_http_proxy_tile_stat(struct storage_backend *store, const char *xmlconfig, const char *options, int x, int y, int z) { struct stat_info tile_stat; - struct ro_http_proxy_ctx * ctx = (struct ro_http_proxy_ctx *)(store->storage_ctx); + struct ro_http_proxy_ctx *ctx = (struct ro_http_proxy_ctx *)(store->storage_ctx); if (ro_http_proxy_tile_retrieve(store, xmlconfig, options, x, y, z) > 0) { return ctx->cache.st_stat; @@ -202,37 +199,34 @@ static struct stat_info ro_http_proxy_tile_stat(struct storage_backend * store, } } - -static char * ro_http_proxy_tile_storage_id(struct storage_backend * store, const char *xmlconfig, const char *options, int x, int y, int z, char * string) +static char *ro_http_proxy_tile_storage_id(struct storage_backend *store, const char *xmlconfig, const char *options, int x, int y, int z, char *string) { return ro_http_proxy_xyz_to_storagekey(store, x, y, z, string); } -static int ro_http_proxy_metatile_write(struct storage_backend * store, const char *xmlconfig, const char *options, int x, int y, int z, const char *buf, int sz) +static int ro_http_proxy_metatile_write(struct storage_backend *store, const char *xmlconfig, const char *options, int x, int y, int z, const char *buf, int sz) { g_logger(G_LOG_LEVEL_ERROR, "ro_http_proxy_metatile_write: This is a readonly storage backend. Write functionality isn't implemented"); return -1; } - -static int ro_http_proxy_metatile_delete(struct storage_backend * store, const char *xmlconfig, int x, int y, int z) +static int ro_http_proxy_metatile_delete(struct storage_backend *store, const char *xmlconfig, int x, int y, int z) { g_logger(G_LOG_LEVEL_ERROR, "ro_http_proxy_metatile_delete: This is a readonly storage backend. Write functionality isn't implemented"); return -1; } -static int ro_http_proxy_metatile_expire(struct storage_backend * store, const char *xmlconfig, int x, int y, int z) +static int ro_http_proxy_metatile_expire(struct storage_backend *store, const char *xmlconfig, int x, int y, int z) { g_logger(G_LOG_LEVEL_ERROR, "ro_http_proxy_metatile_expire: This is a readonly storage backend. Write functionality isn't implemented"); return -1; } - -static int ro_http_proxy_close_storage(struct storage_backend * store) +static int ro_http_proxy_close_storage(struct storage_backend *store) { - struct ro_http_proxy_ctx * ctx = (struct ro_http_proxy_ctx *)(store->storage_ctx); + struct ro_http_proxy_ctx *ctx = (struct ro_http_proxy_ctx *)(store->storage_ctx); free(ctx->baseurl); @@ -247,20 +241,17 @@ static int ro_http_proxy_close_storage(struct storage_backend * store) return 0; } +#endif // Have curl -#endif //Have curl - - - -struct storage_backend * init_storage_ro_http_proxy(const char * connection_string) +struct storage_backend *init_storage_ro_http_proxy(const char *connection_string) { #ifndef HAVE_LIBCURL g_logger(G_LOG_LEVEL_ERROR, "init_storage_ro_http_proxy: Support for curl and therefore the http proxy storage has not been compiled into this program"); return NULL; #else - struct storage_backend * store = malloc(sizeof(struct storage_backend)); - struct ro_http_proxy_ctx * ctx = malloc(sizeof(struct ro_http_proxy_ctx)); + struct storage_backend *store = malloc(sizeof(struct storage_backend)); + struct ro_http_proxy_ctx *ctx = malloc(sizeof(struct ro_http_proxy_ctx)); CURLcode res; g_logger(G_LOG_LEVEL_DEBUG, "init_storage_ro_http_proxy: initialising proxy storage backend for %s", connection_string);