/src/unit/src/nxt_service.c
Line | Count | Source |
1 | | |
2 | | /* |
3 | | * Copyright (C) Igor Sysoev |
4 | | * Copyright (C) NGINX, Inc. |
5 | | */ |
6 | | |
7 | | #include <nxt_main.h> |
8 | | |
9 | | |
10 | | static const nxt_service_t nxt_services[] = { |
11 | | |
12 | | #if (NXT_HAVE_KQUEUE) |
13 | | { "engine", "kqueue", &nxt_kqueue_engine }, |
14 | | #endif |
15 | | |
16 | | #if (NXT_HAVE_EPOLL_EDGE) |
17 | | { "engine", "epoll", &nxt_epoll_edge_engine }, |
18 | | { "engine", "epoll_edge", &nxt_epoll_edge_engine }, |
19 | | { "engine", "epoll_level", &nxt_epoll_level_engine }, |
20 | | |
21 | | #elif (NXT_HAVE_EPOLL) |
22 | | { "engine", "epoll", &nxt_epoll_level_engine }, |
23 | | { "engine", "epoll_level", &nxt_epoll_level_engine }, |
24 | | #endif |
25 | | |
26 | | #if (NXT_HAVE_EVENTPORT) |
27 | | { "engine", "eventport", &nxt_eventport_engine }, |
28 | | #endif |
29 | | |
30 | | #if (NXT_HAVE_DEVPOLL) |
31 | | { "engine", "devpoll", &nxt_devpoll_engine }, |
32 | | { "engine", "/dev/poll", &nxt_devpoll_engine }, |
33 | | #endif |
34 | | |
35 | | #if (NXT_HAVE_POLLSET) |
36 | | { "engine", "pollset", &nxt_pollset_engine }, |
37 | | #endif |
38 | | |
39 | | { "engine", "poll", &nxt_poll_engine }, |
40 | | { "engine", "select", &nxt_select_engine }, |
41 | | |
42 | | #if (NXT_HAVE_OPENSSL) |
43 | | { "SSL/TLS", "OpenSSL", &nxt_openssl_lib }, |
44 | | { "SSL/TLS", "openssl", &nxt_openssl_lib }, |
45 | | #endif |
46 | | |
47 | | #if (NXT_HAVE_GNUTLS) |
48 | | { "SSL/TLS", "GnuTLS", &nxt_gnutls_lib }, |
49 | | { "SSL/TLS", "gnutls", &nxt_gnutls_lib }, |
50 | | #endif |
51 | | |
52 | | #if (NXT_HAVE_CYASSL) |
53 | | { "SSL/TLS", "CyaSSL", &nxt_cyassl_lib }, |
54 | | { "SSL/TLS", "cyassl", &nxt_cyassl_lib }, |
55 | | #endif |
56 | | |
57 | | }; |
58 | | |
59 | | |
60 | | nxt_array_t * |
61 | | nxt_services_init(nxt_mp_t *mp) |
62 | 0 | { |
63 | 0 | nxt_uint_t n; |
64 | 0 | nxt_array_t *services; |
65 | 0 | nxt_service_t *s; |
66 | 0 | const nxt_service_t *service; |
67 | |
|
68 | 0 | services = nxt_array_create(mp, 32, sizeof(nxt_service_t)); |
69 | |
|
70 | 0 | if (nxt_fast_path(services != NULL)) { |
71 | |
|
72 | 0 | service = nxt_services; |
73 | 0 | n = nxt_nitems(nxt_services); |
74 | |
|
75 | 0 | while (n != 0) { |
76 | 0 | s = nxt_array_add(services); |
77 | 0 | if (nxt_slow_path(s == NULL)) { |
78 | 0 | return NULL; |
79 | 0 | } |
80 | | |
81 | 0 | *s = *service; |
82 | |
|
83 | 0 | service++; |
84 | 0 | n--; |
85 | 0 | } |
86 | 0 | } |
87 | | |
88 | 0 | return services; |
89 | 0 | } |
90 | | |
91 | | |
92 | | nxt_int_t |
93 | | nxt_service_add(nxt_array_t *services, const nxt_service_t *service) |
94 | 0 | { |
95 | 0 | nxt_uint_t n; |
96 | 0 | nxt_service_t *s; |
97 | |
|
98 | 0 | s = services->elts; |
99 | 0 | n = services->nelts; |
100 | |
|
101 | 0 | while (n != 0) { |
102 | 0 | if (nxt_strcmp(s->type, service->type) != 0) { |
103 | 0 | goto next; |
104 | 0 | } |
105 | | |
106 | 0 | if (nxt_strcmp(s->name, service->name) != 0) { |
107 | 0 | goto next; |
108 | 0 | } |
109 | | |
110 | 0 | nxt_thread_log_alert("service \"%s:%s\" is duplicate", |
111 | 0 | service->type, service->name); |
112 | 0 | return NXT_ERROR; |
113 | | |
114 | 0 | next: |
115 | |
|
116 | 0 | s++; |
117 | 0 | n--; |
118 | 0 | } |
119 | | |
120 | 0 | s = nxt_array_add(services); |
121 | 0 | if (nxt_fast_path(s != NULL)) { |
122 | 0 | *s = *service; |
123 | 0 | return NXT_OK; |
124 | 0 | } |
125 | | |
126 | 0 | return NXT_ERROR; |
127 | 0 | } |
128 | | |
129 | | |
130 | | const void * |
131 | | nxt_service_get(nxt_array_t *services, const char *type, const char *name) |
132 | 0 | { |
133 | 0 | nxt_uint_t n; |
134 | 0 | const nxt_service_t *s; |
135 | |
|
136 | 0 | if (services != NULL) { |
137 | 0 | s = services->elts; |
138 | 0 | n = services->nelts; |
139 | |
|
140 | 0 | } else { |
141 | 0 | s = nxt_services; |
142 | 0 | n = nxt_nitems(nxt_services); |
143 | 0 | } |
144 | |
|
145 | 0 | while (n != 0) { |
146 | 0 | if (nxt_strcmp(s->type, type) == 0) { |
147 | |
|
148 | 0 | if (name == NULL) { |
149 | 0 | return s->service; |
150 | 0 | } |
151 | | |
152 | 0 | if (nxt_strcmp(s->name, name) == 0) { |
153 | 0 | return s->service; |
154 | 0 | } |
155 | 0 | } |
156 | | |
157 | 0 | s++; |
158 | 0 | n--; |
159 | 0 | } |
160 | | |
161 | 0 | nxt_thread_log_alert("service \"%s%s%s\" not found", |
162 | 0 | type, (name != NULL) ? ":" : "", name); |
163 | |
|
164 | | return NULL; |
165 | 0 | } |