예제 #1
0
bool initialize_sasl(memcached_st *memc, char *user, char *password)
{
#ifdef LIBMEMCACHED_WITH_SASL_SUPPORT
  if (user != NULL && password != NULL)
  {
    username= user;
    passwd= password;

    if (sasl_client_init(NULL) != SASL_OK)
    {
      fprintf(stderr, "Failed to initialize sasl library!\n");
      return false;
    }
    memcached_set_sasl_callbacks(memc, sasl_callbacks);
  }
#else
  (void)memc;
  (void)user;
  (void)password;
#endif

  return true;
}
예제 #2
0
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)
			     (GucStringCheckHook) check_default_guc,
#endif
			     (GucStringAssignHook) assign_default_servers_guc,
			     (GucShowHook) 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)
			      (GucStringCheckHook) check_default_guc,
#endif
			      (GucStringAssignHook) assign_default_behavior_guc,
			      (GucShowHook) 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)
			      (GucStringCheckHook) check_default_guc,
#endif
			      NULL,
			      (GucShowHook) show_memcache_sasl_authentication_username_guc);

  DefineCustomStringVariable ("pgmemcache.sasl_authentication_password",
			      "pgmemcache SASL user authentication username",
			      "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)
			      (GucStringCheckHook) check_default_guc,
#endif
			      NULL,
			      (GucShowHook) show_memcache_sasl_authentication_password_guc);
#if 0
  if ((memcache_sasl_authentication_username != "" && memcache_sasl_authentication_password != "") || (memcache_sasl_authentication_username != NULL && memcache_sasl_authentication_password != NULL)) {
    if  (sasl_client_init(NULL) != SASL_OK)
	elog(ERROR, "Failed to initialize SASL library!");
    memcached_set_sasl_callbacks(globals.mc, sasl_callbacks);
  }
#endif
}