Beispiel #1
0
static int _mapcache_cache_memcache_has_tile(mapcache_context *ctx, mapcache_cache *pcache, mapcache_tile *tile)
{
  char *key;
  char *tmpdata;
  int rv;
  size_t tmpdatasize;
  mapcache_cache_memcache *cache = (mapcache_cache_memcache*)pcache;
  mapcache_pooled_connection *pc;
  struct mapcache_memcache_pooled_connection *mpc;
  pc = _mapcache_memcache_get_conn(ctx,cache,tile);
  if(GC_HAS_ERROR(ctx))
    return MAPCACHE_FALSE;
  mpc = pc->connection;
  
  key = mapcache_util_get_tile_key(ctx, tile, NULL, " \r\n\t\f\e\a\b","#");
  if(GC_HAS_ERROR(ctx)) {
    rv = MAPCACHE_FALSE;
    goto cleanup;
  }
  rv = apr_memcache_getp(mpc->memcache,ctx->pool,key,&tmpdata,&tmpdatasize,NULL);
  if(rv != APR_SUCCESS) {
    rv = MAPCACHE_FALSE;
    goto cleanup;
  }
  if(tmpdatasize == 0) {
    rv = MAPCACHE_FALSE;
    goto cleanup;
  }
  rv = MAPCACHE_TRUE;
cleanup:
  _mapcache_memcache_release_conn(ctx,pc);
  return rv;
}
Beispiel #2
0
/**
 * \brief get content of given tile
 * 
 * fills the mapcache_tile::data of the given tile with content stored on the memcache server
 * \private \memberof mapcache_cache_memcache
 * \sa mapcache_cache::tile_get()
 */
static int _mapcache_cache_memcache_get(mapcache_context *ctx, mapcache_tile *tile) {
   char *key;
   int rv;
   mapcache_cache_memcache *cache = (mapcache_cache_memcache*)tile->tileset->cache;
   key = mapcache_util_get_tile_key(ctx, tile,NULL," \r\n\t\f\e\a\b","#");
   if(GC_HAS_ERROR(ctx)) {
      return MAPCACHE_FAILURE;
   }
   tile->encoded_data = mapcache_buffer_create(0,ctx->pool);
   rv = apr_memcache_getp(cache->memcache,ctx->pool,key,(char**)&tile->encoded_data->buf,&tile->encoded_data->size,NULL);
   if(rv != APR_SUCCESS) {
      return MAPCACHE_CACHE_MISS;
   }
   if(tile->encoded_data->size == 0) {
      ctx->set_error(ctx,500,"memcache cache returned 0-length data for tile %d %d %d\n",tile->x,tile->y,tile->z);
      return MAPCACHE_FAILURE;
   }
   /* extract the tile modification time from the end of the data returned */
   memcpy(
         &tile->mtime,
         &(((char*)tile->encoded_data->buf)[tile->encoded_data->size-sizeof(apr_time_t)]),
         sizeof(apr_time_t));
   ((char*)tile->encoded_data->buf)[tile->encoded_data->size+sizeof(apr_time_t)]='\0';
   tile->encoded_data->avail = tile->encoded_data->size;
   tile->encoded_data->size -= sizeof(apr_time_t);
   return MAPCACHE_SUCCESS;
}
Beispiel #3
0
/**
 * \brief get content of given tile
 *
 * fills the mapcache_tile::data of the given tile with content stored on the memcache server
 * \private \memberof mapcache_cache_memcache
 * \sa mapcache_cache::tile_get()
 */
static int _mapcache_cache_memcache_get(mapcache_context *ctx, mapcache_cache *pcache, mapcache_tile *tile)
{
  char *key;
  int rv;
  mapcache_cache_memcache *cache = (mapcache_cache_memcache*)pcache;
  mapcache_pooled_connection *pc;
  mapcache_buffer *encoded_data;
  struct mapcache_memcache_pooled_connection *mpc;
  pc = _mapcache_memcache_get_conn(ctx,cache,tile);
  if(GC_HAS_ERROR(ctx)) {
    return MAPCACHE_FAILURE;
  }
  mpc = pc->connection;
  key = mapcache_util_get_tile_key(ctx, tile,NULL," \r\n\t\f\e\a\b","#");
  if(GC_HAS_ERROR(ctx)) {
    rv = MAPCACHE_FAILURE;
    goto cleanup;
  }
  encoded_data = mapcache_buffer_create(0,ctx->pool);
  rv = apr_memcache_getp(mpc->memcache,ctx->pool,key,(char**)&encoded_data->buf,&encoded_data->size,NULL);
  if(rv != APR_SUCCESS) {
    rv = MAPCACHE_CACHE_MISS;
    goto cleanup;
  }
  if(encoded_data->size == 0) {
    ctx->set_error(ctx,500,"memcache cache returned 0-length data for tile %d %d %d\n",tile->x,tile->y,tile->z);
    rv = MAPCACHE_FAILURE;
    goto cleanup;
  }
  /* extract the tile modification time from the end of the data returned */
  memcpy(
    &tile->mtime,
    &(((char*)encoded_data->buf)[encoded_data->size-sizeof(apr_time_t)]),
    sizeof(apr_time_t));
  
  ((char*)encoded_data->buf)[encoded_data->size+sizeof(apr_time_t)]='\0';
  encoded_data->avail = encoded_data->size;
  encoded_data->size -= sizeof(apr_time_t);
  if(((char*)encoded_data->buf)[0] == '#' && encoded_data->size > 1) {
    tile->encoded_data = mapcache_empty_png_decode(ctx,tile->grid_link->grid->tile_sx, tile->grid_link->grid->tile_sy ,encoded_data->buf,&tile->nodata);
  } else {
    tile->encoded_data = encoded_data;
  }
  rv = MAPCACHE_SUCCESS;
  
cleanup:
  _mapcache_memcache_release_conn(ctx,pc);
  
  return rv;
}
/*
 * get a name/value pair from memcache
 */
static apr_byte_t oidc_cache_memcache_get(request_rec *r, const char *section,
		const char *key, const char **value) {

	oidc_cfg *cfg = ap_get_module_config(r->server->module_config,
			&auth_openidc_module);
	oidc_cache_cfg_memcache_t *context =
			(oidc_cache_cfg_memcache_t *) cfg->cache_cfg;

	apr_size_t len = 0;

	/* get it */
	apr_status_t rv = apr_memcache_getp(context->cache_memcache, r->pool,
			oidc_cache_memcache_get_key(r->pool, section, key), (char **) value,
			&len, NULL);

	if (rv == APR_NOTFOUND) {

		/*
		 * NB: workaround the fact that the apr_memcache returns APR_NOTFOUND if a server has been marked dead
		 */
		if (oidc_cache_memcache_status(r, context) == FALSE) {

			oidc_cache_memcache_log_status_error(r, "apr_memcache_getp", rv);

			return FALSE;
		}

		oidc_debug(r, "apr_memcache_getp: key %s not found in cache",
				oidc_cache_memcache_get_key(r->pool, section, key));

		return TRUE;

	} else if (rv != APR_SUCCESS) {

		oidc_cache_memcache_log_status_error(r, "apr_memcache_getp", rv);

		return FALSE;
	}

	/* do sanity checking on the string value */
	if ((*value) && (strlen(*value) != len)) {
		oidc_error(r,
				"apr_memcache_getp returned less bytes than expected: strlen(value) [%zu] != len [%" APR_SIZE_T_FMT "]",
				strlen(*value), len);
		return FALSE;
	}

	return TRUE;
}
Beispiel #5
0
static int _mapcache_cache_memcache_has_tile(mapcache_context *ctx, mapcache_tile *tile) {
   char *key;
   char *tmpdata;
   int rv;
   size_t tmpdatasize;
   mapcache_cache_memcache *cache = (mapcache_cache_memcache*)tile->tileset->cache;
   key = mapcache_util_get_tile_key(ctx, tile,NULL," \r\n\t\f\e\a\b","#");
   if(GC_HAS_ERROR(ctx)) {
      return MAPCACHE_FALSE;
   }
   rv = apr_memcache_getp(cache->memcache,ctx->pool,key,&tmpdata,&tmpdatasize,NULL);
   if(rv != APR_SUCCESS) {
      return MAPCACHE_FALSE;
   }
   if(tmpdatasize == 0) {
      return MAPCACHE_FALSE;
   }
   return MAPCACHE_TRUE;
}
Beispiel #6
0
/* Core functionality of our getter functions: fetch DATA from the memcached
 * given by CACHE_VOID and identified by KEY. Indicate success in FOUND and
 * use a tempoary sub-pool of POOL for allocations.
 */
static svn_error_t *
memcache_internal_get(char **data,
                      apr_size_t *size,
                      svn_boolean_t *found,
                      void *cache_void,
                      const void *key,
                      apr_pool_t *pool)
{
  memcache_t *cache = cache_void;
  apr_status_t apr_err;
  const char *mc_key;
  apr_pool_t *subpool;

  if (key == NULL)
    {
      *found = FALSE;
      return SVN_NO_ERROR;
    }

  subpool = svn_pool_create(pool);
  SVN_ERR(build_key(&mc_key, cache, key, subpool));

  apr_err = apr_memcache_getp(cache->memcache,
                              pool,
                              mc_key,
                              data,
                              size,
                              NULL /* ignore flags */);
  if (apr_err == APR_NOTFOUND)
    {
      *found = FALSE;
      svn_pool_destroy(subpool);
      return SVN_NO_ERROR;
    }
  else if (apr_err != APR_SUCCESS || !*data)
    return svn_error_wrap_apr(apr_err,
                              _("Unknown memcached error while reading"));

  *found = TRUE;

  svn_pool_destroy(subpool);
  return SVN_NO_ERROR;
}
/*
 * get a name/value pair from memcache
 */
static apr_byte_t oidc_cache_memcache_get(request_rec *r, const char *section,
		const char *key, const char **value) {

	oidc_debug(r, "enter, section=\"%s\", key=\"%s\"", section, key);

	oidc_cfg *cfg = ap_get_module_config(r->server->module_config,
			&auth_openidc_module);
	oidc_cache_cfg_memcache_t *context =
			(oidc_cache_cfg_memcache_t *) cfg->cache_cfg;

	apr_size_t len = 0;

	/* get it */
	apr_status_t rv = apr_memcache_getp(context->cache_memcache, r->pool,
			oidc_cache_memcache_get_key(r->pool, section, key), (char **) value,
			&len, NULL);

	if (rv == APR_NOTFOUND) {
		oidc_debug(r, "apr_memcache_getp: key %s not found in cache",
				oidc_cache_memcache_get_key(r->pool, section, key));
		return FALSE;
	} else if (rv != APR_SUCCESS) {
		// TODO: error strings ?
		oidc_error(r, "apr_memcache_getp returned an error; perhaps your memcache server is not available?");
		return FALSE;
	}

	/* do sanity checking on the string value */
	if ((*value) && (strlen(*value) != len)) {
		oidc_error(r,
				"apr_memcache_getp returned less bytes than expected: strlen(value) [%zu] != len [%" APR_SIZE_T_FMT "]",
				strlen(*value), len);
		return FALSE;
	}

	return TRUE;
}