2017-05-29 15:33:44 +00:00
|
|
|
|
|
|
|
/*
|
2017-07-05 12:42:49 +00:00
|
|
|
* Odissey.
|
2017-05-29 15:33:44 +00:00
|
|
|
*
|
2017-07-05 12:42:49 +00:00
|
|
|
* Advanced PostgreSQL connection pooler.
|
2017-05-29 15:33:44 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2017-05-31 15:47:15 +00:00
|
|
|
#include <inttypes.h>
|
2017-05-29 15:33:44 +00:00
|
|
|
#include <signal.h>
|
|
|
|
|
|
|
|
#include <machinarium.h>
|
2017-06-07 11:50:58 +00:00
|
|
|
#include <shapito.h>
|
2017-05-29 15:33:44 +00:00
|
|
|
|
2017-07-05 12:15:17 +00:00
|
|
|
#include "sources/macro.h"
|
|
|
|
#include "sources/version.h"
|
|
|
|
#include "sources/list.h"
|
|
|
|
#include "sources/pid.h"
|
|
|
|
#include "sources/id.h"
|
|
|
|
#include "sources/syslog.h"
|
|
|
|
#include "sources/log.h"
|
|
|
|
#include "sources/daemon.h"
|
|
|
|
#include "sources/scheme.h"
|
|
|
|
#include "sources/lex.h"
|
|
|
|
#include "sources/config.h"
|
|
|
|
#include "sources/msg.h"
|
|
|
|
#include "sources/system.h"
|
|
|
|
#include "sources/instance.h"
|
|
|
|
#include "sources/server.h"
|
|
|
|
#include "sources/server_pool.h"
|
|
|
|
#include "sources/client.h"
|
|
|
|
#include "sources/client_pool.h"
|
|
|
|
#include "sources/route_id.h"
|
|
|
|
#include "sources/route.h"
|
|
|
|
#include "sources/route_pool.h"
|
|
|
|
#include "sources/io.h"
|
|
|
|
#include "sources/router.h"
|
|
|
|
#include "sources/pooler.h"
|
|
|
|
#include "sources/relay.h"
|
|
|
|
#include "sources/frontend.h"
|
|
|
|
#include "sources/backend.h"
|
|
|
|
#include "sources/auth.h"
|
|
|
|
#include "sources/tls.h"
|
|
|
|
#include "sources/cancel.h"
|
2017-05-29 15:33:44 +00:00
|
|
|
|
2017-06-16 12:28:37 +00:00
|
|
|
int od_cancel(od_system_t *system,
|
2017-06-21 12:18:48 +00:00
|
|
|
od_schemestorage_t *server_scheme,
|
2017-07-06 13:36:14 +00:00
|
|
|
shapito_key_t *key,
|
2017-06-20 15:39:52 +00:00
|
|
|
od_id_t *server_id)
|
2017-05-29 15:33:44 +00:00
|
|
|
{
|
2017-06-16 12:28:37 +00:00
|
|
|
od_instance_t *instance = system->instance;
|
2017-06-02 13:49:20 +00:00
|
|
|
od_log_server(&instance->log, 0, "cancel",
|
2017-06-28 10:58:21 +00:00
|
|
|
"cancel for s%.*s", sizeof(server_id->id),
|
2017-06-20 15:39:52 +00:00
|
|
|
server_id->id);
|
2017-06-16 12:28:37 +00:00
|
|
|
od_server_t server;
|
|
|
|
od_server_init(&server);
|
|
|
|
server.system = system;
|
|
|
|
od_backend_connect_cancel(&server, server_scheme, key);
|
2017-06-02 13:49:20 +00:00
|
|
|
od_backend_close(&server);
|
2017-05-29 15:33:44 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2017-05-30 11:34:08 +00:00
|
|
|
|
|
|
|
static inline int
|
|
|
|
od_cancel_cmp(od_server_t *server, void *arg)
|
|
|
|
{
|
2017-07-06 13:36:14 +00:00
|
|
|
shapito_key_t *key = arg;
|
|
|
|
return shapito_key_cmp(&server->key_client, key);
|
2017-05-30 11:34:08 +00:00
|
|
|
}
|
|
|
|
|
2017-06-16 12:28:37 +00:00
|
|
|
int od_cancel_match(od_system_t *system,
|
2017-05-30 11:34:08 +00:00
|
|
|
od_routepool_t *route_pool,
|
2017-07-06 13:36:14 +00:00
|
|
|
shapito_key_t *key)
|
2017-05-30 11:34:08 +00:00
|
|
|
{
|
|
|
|
/* match server by client key (forge) */
|
|
|
|
od_server_t *server;
|
|
|
|
server = od_routepool_foreach(route_pool, OD_SACTIVE, od_cancel_cmp, key);
|
|
|
|
if (server == NULL)
|
|
|
|
return -1;
|
|
|
|
od_route_t *route = server->route;
|
2017-06-21 12:18:48 +00:00
|
|
|
od_schemestorage_t *server_scheme = route->scheme->storage;
|
2017-07-06 13:36:14 +00:00
|
|
|
shapito_key_t cancel_key = server->key;
|
2017-06-20 15:39:52 +00:00
|
|
|
return od_cancel(system, server_scheme, &cancel_key, &server->id);
|
2017-05-30 11:34:08 +00:00
|
|
|
}
|