- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
buf = malloc(8 * 1024);
snprintf(buf, 8 * 1024,
"{\n"
"\t\"tilejson\": \"2.0.0\",\n"
"\t\"schema\": \"xyz\",\n"
"\t\"name\": \"%s\",\n"
"\t\"description\": \"%s\",\n"
"\t\"attribution\": \"%s\",\n"
"\t\"minzoom\": %i,\n"
"\t\"maxzoom\": %i,\n"
"\t\"tiles\": [\n",
tile_config->xmlname, (tile_config->description ? tile_config->description : ""), tile_config->attribution, tile_config->minzoom, tile_config->maxzoom);
for (i = 0; i < tile_config->noHostnames; i++) {
strncat(buf, "\t\t\"", 8 * 1024 - strlen(buf) - 1);
strncat(buf, tile_config->hostnames[i], 8 * 1024 - strlen(buf) - 1);
strncat(buf, tile_config->baseuri, 8 * 1024 - strlen(buf) - 1);
strncat(buf, "{z}/{x}/{y}.", 8 * 1024 - strlen(buf) - 1);
strncat(buf, tile_config->fileExtension, 8 * 1024 - strlen(buf) - 1);
strncat(buf, "\"", 8 * 1024 - strlen(buf) - 1);
if (i < tile_config->noHostnames - 1) {
strncat(buf, ",", 8 * 1024 - strlen(buf) - 1);
}
strncat(buf, "\n", 8 * 1024 - strlen(buf) - 1);
}
strncat(buf, "\t]\n}\n", 8 * 1024 - strlen(buf) - 1);
len = strlen(buf);
/*
* Add HTTP headers. Make this file cachable for 1 week
*/
md5 = ap_md5_binary(r->pool, (unsigned char *)buf, len);
apr_table_setn(r->headers_out, "ETag",
apr_psprintf(r->pool, "\"%s\"", md5));
ap_set_content_type(r, "application/json");
ap_set_content_length(r, len);
apr_table_mergen(t, "Cache-Control",
apr_psprintf(r->pool, "max-age=%" APR_TIME_T_FMT,
maxAge));
timestr = apr_palloc(r->pool, APR_RFC822_DATE_LEN);
apr_rfc822_date(timestr, (apr_time_from_sec(maxAge) + r->request_time));
apr_table_setn(t, "Expires", timestr);
ap_rwrite(buf, len, r);
free(buf);