10Sigor@sysoev.ru
20Sigor@sysoev.ru /*
30Sigor@sysoev.ru * Copyright (C) Igor Sysoev
40Sigor@sysoev.ru * Copyright (C) NGINX, Inc.
50Sigor@sysoev.ru */
60Sigor@sysoev.ru
70Sigor@sysoev.ru #include <nxt_main.h>
80Sigor@sysoev.ru
90Sigor@sysoev.ru
100Sigor@sysoev.ru static const nxt_service_t nxt_services[] = {
110Sigor@sysoev.ru
120Sigor@sysoev.ru #if (NXT_HAVE_KQUEUE)
1312Sigor@sysoev.ru { "engine", "kqueue", &nxt_kqueue_engine },
140Sigor@sysoev.ru #endif
150Sigor@sysoev.ru
160Sigor@sysoev.ru #if (NXT_HAVE_EPOLL_EDGE)
1712Sigor@sysoev.ru { "engine", "epoll", &nxt_epoll_edge_engine },
1812Sigor@sysoev.ru { "engine", "epoll_edge", &nxt_epoll_edge_engine },
1912Sigor@sysoev.ru { "engine", "epoll_level", &nxt_epoll_level_engine },
200Sigor@sysoev.ru
210Sigor@sysoev.ru #elif (NXT_HAVE_EPOLL)
2212Sigor@sysoev.ru { "engine", "epoll", &nxt_epoll_level_engine },
2312Sigor@sysoev.ru { "engine", "epoll_level", &nxt_epoll_level_engine },
240Sigor@sysoev.ru #endif
250Sigor@sysoev.ru
260Sigor@sysoev.ru #if (NXT_HAVE_EVENTPORT)
2712Sigor@sysoev.ru { "engine", "eventport", &nxt_eventport_engine },
280Sigor@sysoev.ru #endif
290Sigor@sysoev.ru
300Sigor@sysoev.ru #if (NXT_HAVE_DEVPOLL)
3112Sigor@sysoev.ru { "engine", "devpoll", &nxt_devpoll_engine },
3212Sigor@sysoev.ru { "engine", "/dev/poll", &nxt_devpoll_engine },
330Sigor@sysoev.ru #endif
340Sigor@sysoev.ru
350Sigor@sysoev.ru #if (NXT_HAVE_POLLSET)
3612Sigor@sysoev.ru { "engine", "pollset", &nxt_pollset_engine },
370Sigor@sysoev.ru #endif
380Sigor@sysoev.ru
3912Sigor@sysoev.ru { "engine", "poll", &nxt_poll_engine },
4012Sigor@sysoev.ru { "engine", "select", &nxt_select_engine },
410Sigor@sysoev.ru
420Sigor@sysoev.ru #if (NXT_HAVE_OPENSSL)
430Sigor@sysoev.ru { "SSL/TLS", "OpenSSL", &nxt_openssl_lib },
440Sigor@sysoev.ru { "SSL/TLS", "openssl", &nxt_openssl_lib },
450Sigor@sysoev.ru #endif
460Sigor@sysoev.ru
470Sigor@sysoev.ru #if (NXT_HAVE_GNUTLS)
480Sigor@sysoev.ru { "SSL/TLS", "GnuTLS", &nxt_gnutls_lib },
490Sigor@sysoev.ru { "SSL/TLS", "gnutls", &nxt_gnutls_lib },
500Sigor@sysoev.ru #endif
510Sigor@sysoev.ru
520Sigor@sysoev.ru #if (NXT_HAVE_CYASSL)
530Sigor@sysoev.ru { "SSL/TLS", "CyaSSL", &nxt_cyassl_lib },
540Sigor@sysoev.ru { "SSL/TLS", "cyassl", &nxt_cyassl_lib },
550Sigor@sysoev.ru #endif
560Sigor@sysoev.ru
570Sigor@sysoev.ru };
580Sigor@sysoev.ru
590Sigor@sysoev.ru
600Sigor@sysoev.ru nxt_array_t *
nxt_services_init(nxt_mp_t * mp)6165Sigor@sysoev.ru nxt_services_init(nxt_mp_t *mp)
620Sigor@sysoev.ru {
630Sigor@sysoev.ru nxt_uint_t n;
640Sigor@sysoev.ru nxt_array_t *services;
650Sigor@sysoev.ru nxt_service_t *s;
660Sigor@sysoev.ru const nxt_service_t *service;
670Sigor@sysoev.ru
680Sigor@sysoev.ru services = nxt_array_create(mp, 32, sizeof(nxt_service_t));
690Sigor@sysoev.ru
700Sigor@sysoev.ru if (nxt_fast_path(services != NULL)) {
710Sigor@sysoev.ru
720Sigor@sysoev.ru service = nxt_services;
730Sigor@sysoev.ru n = nxt_nitems(nxt_services);
740Sigor@sysoev.ru
750Sigor@sysoev.ru while (n != 0) {
760Sigor@sysoev.ru s = nxt_array_add(services);
770Sigor@sysoev.ru if (nxt_slow_path(s == NULL)) {
780Sigor@sysoev.ru return NULL;
790Sigor@sysoev.ru }
800Sigor@sysoev.ru
810Sigor@sysoev.ru *s = *service;
820Sigor@sysoev.ru
830Sigor@sysoev.ru service++;
840Sigor@sysoev.ru n--;
850Sigor@sysoev.ru }
860Sigor@sysoev.ru }
870Sigor@sysoev.ru
880Sigor@sysoev.ru return services;
890Sigor@sysoev.ru }
900Sigor@sysoev.ru
910Sigor@sysoev.ru
920Sigor@sysoev.ru nxt_int_t
nxt_service_add(nxt_array_t * services,const nxt_service_t * service)930Sigor@sysoev.ru nxt_service_add(nxt_array_t *services, const nxt_service_t *service)
940Sigor@sysoev.ru {
950Sigor@sysoev.ru nxt_uint_t n;
960Sigor@sysoev.ru nxt_service_t *s;
970Sigor@sysoev.ru
980Sigor@sysoev.ru s = services->elts;
990Sigor@sysoev.ru n = services->nelts;
1000Sigor@sysoev.ru
1010Sigor@sysoev.ru while (n != 0) {
1020Sigor@sysoev.ru if (nxt_strcmp(s->type, service->type) != 0) {
1030Sigor@sysoev.ru goto next;
1040Sigor@sysoev.ru }
1050Sigor@sysoev.ru
1060Sigor@sysoev.ru if (nxt_strcmp(s->name, service->name) != 0) {
1070Sigor@sysoev.ru goto next;
1080Sigor@sysoev.ru }
1090Sigor@sysoev.ru
110*564Svbart@nginx.com nxt_thread_log_alert("service \"%s:%s\" is duplicate",
1110Sigor@sysoev.ru service->type, service->name);
1120Sigor@sysoev.ru return NXT_ERROR;
1130Sigor@sysoev.ru
1140Sigor@sysoev.ru next:
1150Sigor@sysoev.ru
1160Sigor@sysoev.ru s++;
1170Sigor@sysoev.ru n--;
1180Sigor@sysoev.ru }
1190Sigor@sysoev.ru
1200Sigor@sysoev.ru s = nxt_array_add(services);
1210Sigor@sysoev.ru if (nxt_fast_path(s != NULL)) {
1220Sigor@sysoev.ru *s = *service;
1230Sigor@sysoev.ru return NXT_OK;
1240Sigor@sysoev.ru }
1250Sigor@sysoev.ru
1260Sigor@sysoev.ru return NXT_ERROR;
1270Sigor@sysoev.ru }
1280Sigor@sysoev.ru
1290Sigor@sysoev.ru
1300Sigor@sysoev.ru const void *
nxt_service_get(nxt_array_t * services,const char * type,const char * name)1310Sigor@sysoev.ru nxt_service_get(nxt_array_t *services, const char *type, const char *name)
1320Sigor@sysoev.ru {
1330Sigor@sysoev.ru nxt_uint_t n;
1340Sigor@sysoev.ru const nxt_service_t *s;
1350Sigor@sysoev.ru
1360Sigor@sysoev.ru if (services != NULL) {
1370Sigor@sysoev.ru s = services->elts;
1380Sigor@sysoev.ru n = services->nelts;
1390Sigor@sysoev.ru
1400Sigor@sysoev.ru } else {
1410Sigor@sysoev.ru s = nxt_services;
1420Sigor@sysoev.ru n = nxt_nitems(nxt_services);
1430Sigor@sysoev.ru }
1440Sigor@sysoev.ru
1450Sigor@sysoev.ru while (n != 0) {
1460Sigor@sysoev.ru if (nxt_strcmp(s->type, type) == 0) {
1470Sigor@sysoev.ru
1480Sigor@sysoev.ru if (name == NULL) {
1490Sigor@sysoev.ru return s->service;
1500Sigor@sysoev.ru }
1510Sigor@sysoev.ru
1520Sigor@sysoev.ru if (nxt_strcmp(s->name, name) == 0) {
1530Sigor@sysoev.ru return s->service;
1540Sigor@sysoev.ru }
1550Sigor@sysoev.ru }
1560Sigor@sysoev.ru
1570Sigor@sysoev.ru s++;
1580Sigor@sysoev.ru n--;
1590Sigor@sysoev.ru }
1600Sigor@sysoev.ru
161*564Svbart@nginx.com nxt_thread_log_alert("service \"%s%s%s\" not found",
1620Sigor@sysoev.ru type, (name != NULL) ? ":" : "", name);
1630Sigor@sysoev.ru
1640Sigor@sysoev.ru return NULL;
1650Sigor@sysoev.ru }
166