Skip to content

Commit fb1724b

Browse files
committed
server session NEW function for checking CH client and endpt existence
1 parent e7b6e1d commit fb1724b

2 files changed

Lines changed: 86 additions & 0 deletions

File tree

src/session_server.c

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1989,6 +1989,10 @@ nc_server_is_endpt(const char *name)
19891989
uint16_t i;
19901990
int found = 0;
19911991

1992+
if (!name) {
1993+
return found;
1994+
}
1995+
19921996
/* ENDPT READ LOCK */
19931997
pthread_rwlock_rdlock(&server_opts.endpt_lock);
19941998

@@ -2532,6 +2536,33 @@ nc_server_ch_del_client(const char *name)
25322536
return ret;
25332537
}
25342538

2539+
API int
2540+
nc_server_ch_is_client(const char *name)
2541+
{
2542+
uint16_t i;
2543+
int found = 0;
2544+
2545+
if (!name) {
2546+
return found;
2547+
}
2548+
2549+
/* READ LOCK */
2550+
pthread_rwlock_rdlock(&server_opts.ch_client_lock);
2551+
2552+
/* check name uniqueness */
2553+
for (i = 0; i < server_opts.ch_client_count; ++i) {
2554+
if (!strcmp(server_opts.ch_clients[i].name, name)) {
2555+
found = 1;
2556+
break;
2557+
}
2558+
}
2559+
2560+
/* UNLOCK */
2561+
pthread_rwlock_unlock(&server_opts.ch_client_lock);
2562+
2563+
return found;
2564+
}
2565+
25352566
API int
25362567
nc_server_ch_client_add_endpt(const char *client_name, const char *endpt_name, NC_TRANSPORT_IMPL ti)
25372568
{
@@ -2642,6 +2673,44 @@ nc_server_ch_client_del_endpt(const char *client_name, const char *endpt_name, N
26422673
return ret;
26432674
}
26442675

2676+
API int
2677+
nc_server_ch_client_is_endpt(const char *client_name, const char *endpt_name)
2678+
{
2679+
uint16_t i;
2680+
struct nc_ch_client *client = NULL;
2681+
int found = 0;
2682+
2683+
if (!client_name || !endpt_name) {
2684+
return found;
2685+
}
2686+
2687+
/* READ LOCK */
2688+
pthread_rwlock_rdlock(&server_opts.ch_client_lock);
2689+
2690+
for (i = 0; i < server_opts.ch_client_count; ++i) {
2691+
if (!strcmp(server_opts.ch_clients[i].name, client_name)) {
2692+
client = &server_opts.ch_clients[i];
2693+
break;
2694+
}
2695+
}
2696+
2697+
if (!client) {
2698+
goto cleanup;
2699+
}
2700+
2701+
for (i = 0; i < client->ch_endpt_count; ++i) {
2702+
if (!strcmp(client->ch_endpts[i].name, endpt_name)) {
2703+
found = 1;
2704+
break;
2705+
}
2706+
}
2707+
2708+
cleanup:
2709+
/* UNLOCK */
2710+
pthread_rwlock_unlock(&server_opts.ch_client_lock);
2711+
return found;
2712+
}
2713+
26452714
API int
26462715
nc_server_ch_client_endpt_set_address(const char *client_name, const char *endpt_name, const char *address)
26472716
{

src/session_server_ch.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,14 @@ int nc_server_ch_add_client(const char *name);
5151
*/
5252
int nc_server_ch_del_client(const char *name);
5353

54+
/**
55+
* @brief Check if a Call Home client exists.
56+
*
57+
* @param[in] name Client name.
58+
* @return 0 if does not exists, non-zero otherwise.
59+
*/
60+
int nc_server_ch_is_client(const char *name);
61+
5462
/**
5563
* @brief Add a new Call Home client endpoint.
5664
*
@@ -73,6 +81,15 @@ int nc_server_ch_client_add_endpt(const char *client_name, const char *endpt_nam
7381
*/
7482
int nc_server_ch_client_del_endpt(const char *client_name, const char *endpt_name, NC_TRANSPORT_IMPL ti);
7583

84+
/**
85+
* @brief Check if an endpoint of a Call Home client exists.
86+
*
87+
* @param[in] client_name Client name.
88+
* @param[in] endpt_name Endpoint name.
89+
* @return 0 if does not exists, non-zero otherwise.
90+
*/
91+
int nc_server_ch_client_is_endpt(const char *client_name, const char *endpt_name);
92+
7693
/**
7794
* @brief Change Call Home client endpoint listening address.
7895
*

0 commit comments

Comments
 (0)