Lines Matching refs:conn

24 auth_server_connection_reconnect(struct auth_server_connection *conn,
28 auth_server_input_mech(struct auth_server_connection *conn,
33 if (conn->handshake_received) {
43 mech_desc.name = p_strdup(conn->pool, args[0]);
46 conn->has_plain_mech = TRUE;
64 array_append(&conn->available_auth_mechs, &mech_desc, 1);
69 auth_server_input_spid(struct auth_server_connection *conn,
72 if (conn->handshake_received) {
77 if (str_to_uint(args[0], &conn->server_pid) < 0) {
85 auth_server_input_cuid(struct auth_server_connection *conn,
88 if (conn->handshake_received) {
93 str_to_uint(args[0], &conn->connect_uid) < 0) {
101 auth_server_input_cookie(struct auth_server_connection *conn,
104 if (conn->cookie != NULL) {
108 conn->cookie = p_strdup(conn->pool, args[0]);
112 static int auth_server_input_done(struct auth_server_connection *conn)
114 if (array_count(&conn->available_auth_mechs) == 0) {
118 if (conn->cookie == NULL) {
123 timeout_remove(&conn->to);
125 conn->handshake_received = TRUE;
126 if (conn->client->connect_notify_callback != NULL) {
127 conn->client->connect_notify_callback(conn->client, TRUE,
128 conn->client->connect_notify_context);
134 auth_server_lookup_request(struct auth_server_connection *conn,
146 request = hash_table_lookup(conn->requests, POINTER_CAST(id));
152 hash_table_remove(conn->requests, POINTER_CAST(id));
159 auth_server_input_ok(struct auth_server_connection *conn,
164 if (auth_server_lookup_request(conn, args[0], TRUE, &request) < 0)
171 static int auth_server_input_cont(struct auth_server_connection *conn,
181 if (auth_server_lookup_request(conn, args[0], FALSE, &request) < 0)
188 static int auth_server_input_fail(struct auth_server_connection *conn,
193 if (auth_server_lookup_request(conn, args[0], TRUE, &request) < 0)
201 auth_server_connection_input_line(struct auth_server_connection *conn,
206 if (conn->client->debug)
215 return auth_server_input_ok(conn, args + 1);
217 return auth_server_input_cont(conn, args + 1);
219 return auth_server_input_fail(conn, args + 1);
221 return auth_server_input_mech(conn, args + 1);
223 return auth_server_input_spid(conn, args + 1);
225 return auth_server_input_cuid(conn, args + 1);
227 return auth_server_input_cookie(conn, args + 1);
229 return auth_server_input_done(conn);
236 static void auth_server_connection_input(struct auth_server_connection *conn)
242 switch (i_stream_read(conn->input)) {
247 error = conn->input->stream_errno != 0 ?
248 strerror(conn->input->stream_errno) : "EOF";
249 auth_server_connection_reconnect(conn, error);
255 auth_server_connection_disconnect(conn, "buffer full");
259 if (!conn->version_received) {
260 line = i_stream_next_line(conn->input);
270 auth_server_connection_disconnect(conn,
274 conn->version_received = TRUE;
277 input = conn->input;
281 ret = auth_server_connection_input_line(conn, line);
285 auth_server_connection_disconnect(conn, t_strdup_printf(
296 struct auth_server_connection *conn;
300 conn = p_new(pool, struct auth_server_connection, 1);
301 conn->pool = pool;
303 conn->client = client;
304 conn->fd = -1;
305 hash_table_create_direct(&conn->requests, pool, 100);
306 i_array_init(&conn->available_auth_mechs, 8);
307 return conn;
311 auth_server_connection_remove_requests(struct auth_server_connection *conn,
321 if (hash_table_count(conn->requests) == 0)
324 iter = hash_table_iterate_init(conn->requests);
325 while (hash_table_iterate(iter, conn->requests, &key, &request)) {
338 hash_table_clear(conn->requests, FALSE);
348 void auth_server_connection_disconnect(struct auth_server_connection *conn,
351 if (!conn->connected)
353 conn->connected = FALSE;
354 conn->handshake_received = FALSE;
355 conn->version_received = FALSE;
356 conn->has_plain_mech = FALSE;
357 conn->server_pid = 0;
358 conn->connect_uid = 0;
359 conn->cookie = NULL;
360 array_clear(&conn->available_auth_mechs);
362 timeout_remove(&conn->to);
363 io_remove(&conn->io);
364 if (conn->fd != -1) {
365 i_stream_destroy(&conn->input);
366 o_stream_destroy(&conn->output);
368 if (close(conn->fd) < 0)
370 conn->fd = -1;
373 auth_server_connection_remove_requests(conn, reason);
375 if (conn->client->connect_notify_callback != NULL) {
376 conn->client->connect_notify_callback(conn->client, FALSE,
377 conn->client->connect_notify_context);
381 static void auth_server_reconnect_timeout(struct auth_server_connection *conn)
383 (void)auth_server_connection_connect(conn);
387 auth_server_connection_reconnect(struct auth_server_connection *conn,
392 auth_server_connection_disconnect(conn, disconnect_reason);
394 next_connect = conn->last_connect + AUTH_SERVER_RECONNECT_TIMEOUT_SECS;
395 conn->to = timeout_add(ioloop_time >= next_connect ? 0 :
397 auth_server_reconnect_timeout, conn);
402 struct auth_server_connection *conn = *_conn;
406 auth_server_connection_disconnect(conn, "deinitializing");
407 i_assert(hash_table_count(conn->requests) == 0);
408 hash_table_destroy(&conn->requests);
409 array_free(&conn->available_auth_mechs);
410 pool_unref(&conn->pool);
413 static void auth_client_handshake_timeout(struct auth_server_connection *conn)
417 conn->client->client_pid, conn->input->v_offset);
418 auth_server_connection_reconnect(conn, "auth server timeout");
421 int auth_server_connection_connect(struct auth_server_connection *conn)
426 i_assert(!conn->connected);
427 i_assert(conn->fd == -1);
429 conn->last_connect = ioloop_time;
430 timeout_remove(&conn->to);
433 fd = net_connect_unix_with_retries(conn->client->auth_socket_path,
439 conn->client->auth_socket_path));
442 conn->client->auth_socket_path);
446 conn->fd = fd;
447 conn->io = io_add(fd, IO_READ, auth_server_connection_input, conn);
448 conn->input = i_stream_create_fd(fd, AUTH_SERVER_CONN_MAX_LINE_LENGTH);
449 conn->output = o_stream_create_fd(fd, (size_t)-1);
450 conn->connected = TRUE;
455 conn->client->client_pid);
456 if (o_stream_send_str(conn->output, handshake) < 0) {
458 o_stream_get_error(conn->output));
459 auth_server_connection_disconnect(conn,
460 o_stream_get_error(conn->output));
464 conn->to = timeout_add(AUTH_HANDSHAKE_TIMEOUT,
465 auth_client_handshake_timeout, conn);
470 auth_server_connection_add_request(struct auth_server_connection *conn,
475 i_assert(conn->handshake_received);
477 id = ++conn->client->request_id_counter;
480 id = ++conn->client->request_id_counter;
482 i_assert(hash_table_lookup(conn->requests, POINTER_CAST(id)) == NULL);
483 hash_table_insert(conn->requests, POINTER_CAST(id), request);
487 void auth_server_connection_remove_request(struct auth_server_connection *conn,
490 i_assert(conn->handshake_received);
491 hash_table_remove(conn->requests, POINTER_CAST(id));