コード例 #1
0
static
zend_bool s_configure_from_ini_values(memcached_st *memc, zend_bool silent)
{
	memcached_return rc;

#define check_set_behavior(behavior, value) \
	if ((rc = memcached_behavior_set(memc, (behavior), (value))) != MEMCACHED_SUCCESS) { \
		if (!silent) { php_error_docref(NULL, E_WARNING, "failed to initialise session memcached configuration: %s", memcached_strerror(memc, rc)); } \
		return 0; \
	}

	if (MEMC_SESS_INI(binary_protocol_enabled)) {
		check_set_behavior(MEMCACHED_BEHAVIOR_BINARY_PROTOCOL, 1);
	}

	if (MEMC_SESS_INI(consistent_hash_enabled)) {
		check_set_behavior(MEMCACHED_BEHAVIOR_KETAMA, 1);
	}

	if (MEMC_SESS_INI(server_failure_limit)) {
		check_set_behavior(MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT, MEMC_SESS_INI(server_failure_limit));
	}

	if (MEMC_SESS_INI(number_of_replicas)) {
		check_set_behavior(MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS, MEMC_SESS_INI(number_of_replicas));
	}

	if (MEMC_SESS_INI(randomize_replica_read_enabled)) {
		check_set_behavior(MEMCACHED_BEHAVIOR_RANDOMIZE_REPLICA_READ, 1);
	}

	if (MEMC_SESS_INI(remove_failed_servers_enabled)) {
		check_set_behavior(MEMCACHED_BEHAVIOR_REMOVE_FAILED_SERVERS, 1);
	}

	if (MEMC_SESS_INI(connect_timeout)) {
		check_set_behavior(MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT, MEMC_SESS_INI(connect_timeout));
	}

	if (MEMC_SESS_STR_INI(prefix)) {
		memcached_callback_set(memc, MEMCACHED_CALLBACK_NAMESPACE, MEMC_SESS_STR_INI(prefix));
	}

	if (MEMC_SESS_STR_INI(sasl_username) && MEMC_SESS_STR_INI(sasl_password)) {
		php_memcached_user_data *user_data;

		if (!php_memc_init_sasl_if_needed()) {
			return 0;
		}

		check_set_behavior(MEMCACHED_BEHAVIOR_BINARY_PROTOCOL, 1);

		if (memcached_set_sasl_auth_data(memc, MEMC_SESS_STR_INI(sasl_username), MEMC_SESS_STR_INI(sasl_password)) == MEMCACHED_FAILURE) {
			php_error_docref(NULL, E_WARNING, "failed to set memcached session sasl credentials");
			return 0;
		}
		user_data = memcached_get_user_data(memc);
		user_data->has_sasl_data = 1;
	}

#undef safe_set_behavior

	return 1;
}
コード例 #2
0
ファイル: pgmemcache.c プロジェクト: Ormod/pgmemcache
void _PG_init(void)
{
  MemoryContext old_ctxt;

  globals.pg_ctxt = AllocSetContextCreate(TopMemoryContext,
					  "pgmemcache global context",
					  ALLOCSET_SMALL_MINSIZE,
					  ALLOCSET_SMALL_INITSIZE,
					  ALLOCSET_SMALL_MAXSIZE);

  old_ctxt = MemoryContextSwitchTo(globals.pg_ctxt);
  globals.mc = memcached_create(NULL);

  if (memcached_set_memory_allocators(globals.mc,
				      (memcached_malloc_fn) pgmemcache_malloc,
				      (memcached_free_fn) pgmemcache_free,
				      (memcached_realloc_fn) pgmemcache_realloc,
				      (memcached_calloc_fn) pgmemcache_calloc,
				      NULL) != MEMCACHED_SUCCESS) {
    elog(ERROR, "pgmemcache: unable to set memory allocators");
  }

  MemoryContextSwitchTo(old_ctxt);

  DefineCustomStringVariable("pgmemcache.default_servers",
			     "Comma-separated list of memcached servers to connect to.",
			     "Specified as a comma-separated list of host:port (port is optional).",
			     &memcache_default_servers,
			     NULL,
			     PGC_USERSET,
			     GUC_LIST_INPUT,
#if defined(PG_VERSION_NUM) && (PG_VERSION_NUM >= 90100)
			     NULL,
#endif
			     assign_default_servers_guc,
			     show_default_servers_guc);

  DefineCustomStringVariable ("pgmemcache.default_behavior",
			      "Comma-separated list of memcached behavior (optional).",
			      "Specified as a comma-separated list of behavior_flag:behavior_data.",
			      &memcache_default_behavior,
			      NULL,
			      PGC_USERSET,
			      GUC_LIST_INPUT,
#if defined(PG_VERSION_NUM) && (PG_VERSION_NUM >= 90100)
			      NULL,
#endif
			      assign_default_behavior_guc,
			      show_default_behavior_guc);

  DefineCustomStringVariable ("pgmemcache.sasl_authentication_username",
			      "pgmemcache SASL user authentication username",
			      "Simple string pgmemcache.sasl_authentication_username = '******'",
			      &memcache_sasl_authentication_username,
			      NULL,
			      PGC_USERSET,
			      GUC_LIST_INPUT,
#if defined(PG_VERSION_NUM) && (PG_VERSION_NUM >= 90100)
			      NULL,
#endif
			      NULL,
			      show_memcache_sasl_authentication_username_guc);

  DefineCustomStringVariable ("pgmemcache.sasl_authentication_password",
			      "pgmemcache SASL user authentication password",
			      "Simple string pgmemcache.sasl_authentication_password = '******'",
			      &memcache_sasl_authentication_password,
			      NULL,
			      PGC_USERSET,
			      GUC_LIST_INPUT,
#if defined(PG_VERSION_NUM) && (PG_VERSION_NUM >= 90100)
			      NULL,
#endif
			      NULL,
			      show_memcache_sasl_authentication_password_guc);
#if LIBMEMCACHED_WITH_SASL_SUPPORT
  if ((strlen(memcache_sasl_authentication_username) > 0 && strlen(memcache_sasl_authentication_password) > 0) || (memcache_sasl_authentication_username != NULL && memcache_sasl_authentication_password != NULL)) {

        rc = memcached_set_sasl_auth_data(globals.mc, memcache_sasl_authentication_username, memcache_sasl_authentication_password);
        if (rc != MEMCACHED_SUCCESS) {
	    elog(ERROR, "%s ", memcached_strerror(globals.mc, rc));
        }
        _init_sasl();
      }
#endif
}