From: Stephan Bosch Date: Wed, 23 Nov 2022 01:05:02 +0000 (+0100) Subject: lib-master: master-service - Add master_service_connection_get_type(). X-Git-Tag: 2.4.0~3305 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=272b8c9eba79c8e530363eaa86038ebb0d104947;p=thirdparty%2Fdovecot%2Fcore.git lib-master: master-service - Add master_service_connection_get_type(). --- diff --git a/src/lib-master/master-service.c b/src/lib-master/master-service.c index 266e2ac29e..926dd8f6c1 100644 --- a/src/lib-master/master-service.c +++ b/src/lib-master/master-service.c @@ -1426,6 +1426,30 @@ void master_service_client_connection_destroyed(struct master_service *service) } } +const char * +master_service_connection_get_type(const struct master_service_connection *conn) +{ + i_assert(conn->type != NULL); + if (*conn->type != '\0') + return conn->type; + + const char *name, *suffix; + + name = strrchr(conn->name, '/'); + if (name == NULL) + name = conn->name; + else + name++; + + suffix = strrchr(name, '-'); + if (suffix == NULL) + suffix = name; + else + suffix++; + + return suffix; +} + static void master_service_set_login_state(struct master_service *service, enum master_login_state state) { diff --git a/src/lib-master/master-service.h b/src/lib-master/master-service.h index 61059ddbc8..a6e1b6f825 100644 --- a/src/lib-master/master-service.h +++ b/src/lib-master/master-service.h @@ -267,6 +267,13 @@ void master_service_client_connection_accept(struct master_service_connection *c void master_service_client_connection_created(struct master_service *service); /* Call whenever a client connection is destroyed. */ void master_service_client_connection_destroyed(struct master_service *service); +/* Returns the listener type for this connection. If the type is unassigned, the + connection name is parsed for a "-suffix" which is returned instead to easily + implement backwards compatibility for custom listeners that are still + configured without an explicit type. */ +const char * +master_service_connection_get_type( + const struct master_service_connection *conn); /* Deinitialize the service. */ void master_service_deinit(struct master_service **service);