public_server.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624
  1. /* Copyright (c) 2015 the Civetweb developers
  2. *
  3. * Permission is hereby granted, free of charge, to any person obtaining a copy
  4. * of this software and associated documentation files (the "Software"), to deal
  5. * in the Software without restriction, including without limitation the rights
  6. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. * copies of the Software, and to permit persons to whom the Software is
  8. * furnished to do so, subject to the following conditions:
  9. *
  10. * The above copyright notice and this permission notice shall be included in
  11. * all copies or substantial portions of the Software.
  12. *
  13. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  19. * THE SOFTWARE.
  20. */
  21. #ifdef _MSC_VER
  22. #define _CRT_SECURE_NO_WARNINGS
  23. #endif
  24. #include <stdlib.h>
  25. #include <stdio.h>
  26. #include <time.h>
  27. #include <sys/types.h>
  28. #include <sys/stat.h>
  29. #include "public_server.h"
  30. #include <civetweb.h>
  31. #if defined(_WIN32)
  32. #include <Windows.h>
  33. #define mg_Sleep(x) (Sleep(x * 1000))
  34. #else
  35. #include <unistd.h>
  36. #define mg_Sleep(x) (sleep(x))
  37. #endif
  38. /* This unit test file uses the excellent Check unit testing library.
  39. * The API documentation is available here:
  40. * http://check.sourceforge.net/doc/check_html/index.html
  41. */
  42. START_TEST(test_the_test_environment)
  43. {
  44. char wd[300];
  45. char buf[500];
  46. FILE *f;
  47. struct stat st;
  48. int ret;
  49. memset(wd, 0, sizeof(wd));
  50. memset(buf, 0, sizeof(buf));
  51. /* Get the current working directory */
  52. #ifdef _WIN32
  53. (void)GetCurrentDirectoryA(sizeof(wd), wd);
  54. wd[sizeof(wd) - 1] = 0;
  55. #else
  56. (void)getcwd(wd, sizeof(wd));
  57. wd[sizeof(wd) - 1] = 0;
  58. #endif
  59. /* Check the pem file */
  60. #ifdef _WIN32
  61. strcpy(buf, wd);
  62. strcat(buf, "..\\..\\..\\resources\\ssl_cert.pem");
  63. f = fopen(buf, "rb");
  64. #else
  65. strcpy(buf, wd);
  66. strcat(buf, "../../resources/ssl_cert.pem");
  67. f = fopen(buf, "r");
  68. #endif
  69. if (f) {
  70. fclose(f);
  71. } else {
  72. fprintf(stderr, "%s not found", buf);
  73. }
  74. /* Check the test dir */
  75. #ifdef _WIN32
  76. strcpy(buf, wd);
  77. strcat(buf, "\\test");
  78. #else
  79. strcpy(buf, wd);
  80. strcat(buf, "/test");
  81. #endif
  82. memset(&st, 0, sizeof(st));
  83. ret = stat(buf, &st);
  84. if (ret) {
  85. fprintf(stderr, "%s not found", buf);
  86. }
  87. }
  88. END_TEST
  89. static int log_msg_func(const struct mg_connection *conn, const char *message)
  90. {
  91. struct mg_context *ctx;
  92. char *ud;
  93. ck_assert(conn != NULL);
  94. ctx = mg_get_context(conn);
  95. ck_assert(ctx != NULL);
  96. ud = (char *)mg_get_user_data(ctx);
  97. strncpy(ud, message, 255);
  98. ud[255] = 0;
  99. return 1;
  100. }
  101. START_TEST(test_mg_start_stop_http_server)
  102. {
  103. struct mg_context *ctx;
  104. const char *OPTIONS[] = {
  105. "document_root", ".", "listening_ports", "8080", NULL,
  106. };
  107. size_t ports_cnt;
  108. int ports[16];
  109. int ssl[16];
  110. struct mg_callbacks callbacks;
  111. char errmsg[256];
  112. memset(ports, 0, sizeof(ports));
  113. memset(ssl, 0, sizeof(ssl));
  114. memset(&callbacks, 0, sizeof(callbacks));
  115. memset(errmsg, 0, sizeof(errmsg));
  116. callbacks.log_message = log_msg_func;
  117. ctx = mg_start(&callbacks, (void *)errmsg, OPTIONS);
  118. mg_Sleep(1);
  119. ck_assert_str_eq(errmsg, "");
  120. ck_assert(ctx != NULL);
  121. ports_cnt = mg_get_ports(ctx, 16, ports, ssl);
  122. ck_assert_uint_eq(ports_cnt, 1);
  123. ck_assert_int_eq(ports[0], 8080);
  124. ck_assert_int_eq(ssl[0], 0);
  125. ck_assert_int_eq(ports[1], 0);
  126. ck_assert_int_eq(ssl[1], 0);
  127. mg_Sleep(1);
  128. mg_stop(ctx);
  129. }
  130. END_TEST
  131. START_TEST(test_mg_start_stop_https_server)
  132. {
  133. struct mg_context *ctx;
  134. const char *OPTIONS[] = {
  135. "document_root",
  136. ".",
  137. "listening_ports",
  138. "8080,8443s",
  139. "ssl_certificate",
  140. #ifdef _WIN32
  141. "..\\..\\..\\resources/ssl_cert.pem", // TODO: the different paths used in the different test system is an unsolved problem
  142. #else
  143. "../../resources/ssl_cert.pem", // TODO: fix path in CI test environment
  144. #endif
  145. NULL,
  146. };
  147. size_t ports_cnt;
  148. int ports[16];
  149. int ssl[16];
  150. struct mg_callbacks callbacks;
  151. char errmsg[256];
  152. memset(ports, 0, sizeof(ports));
  153. memset(ssl, 0, sizeof(ssl));
  154. memset(&callbacks, 0, sizeof(callbacks));
  155. memset(errmsg, 0, sizeof(errmsg));
  156. callbacks.log_message = log_msg_func;
  157. ctx = mg_start(&callbacks, (void *)errmsg, OPTIONS);
  158. mg_Sleep(1);
  159. ck_assert_str_eq(errmsg, "");
  160. ck_assert(ctx != NULL);
  161. ports_cnt = mg_get_ports(ctx, 16, ports, ssl);
  162. ck_assert_uint_eq(ports_cnt, 2);
  163. ck_assert_int_eq(ports[0], 8080);
  164. ck_assert_int_eq(ssl[0], 0);
  165. ck_assert_int_eq(ports[1], 8443);
  166. ck_assert_int_eq(ssl[1], 1);
  167. ck_assert_int_eq(ports[2], 0);
  168. ck_assert_int_eq(ssl[2], 0);
  169. mg_Sleep(1);
  170. mg_stop(ctx);
  171. }
  172. END_TEST
  173. static struct mg_context *g_ctx;
  174. static int request_test_handler(struct mg_connection *conn, void *cbdata)
  175. {
  176. int i;
  177. char chunk_data[32];
  178. const struct mg_request_info *ri;
  179. struct mg_context *ctx;
  180. void *ud, *cud;
  181. ctx = mg_get_context(conn);
  182. ud = mg_get_user_data(ctx);
  183. ri = mg_get_request_info(conn);
  184. ck_assert(ri != NULL);
  185. ck_assert(ctx == g_ctx);
  186. ck_assert(ud == &g_ctx);
  187. mg_set_user_connection_data(conn, (void *)6543);
  188. cud = mg_get_user_connection_data(conn);
  189. ck_assert(cud == (void *)6543);
  190. ck_assert(cbdata == (void *)7);
  191. strcpy(chunk_data, "123456789A123456789B123456789C");
  192. mg_printf(conn,
  193. "HTTP/1.1 200 OK\r\n"
  194. "Transfer-Encoding: chunked\r\n"
  195. "Content-Type: text/plain\r\n\r\n");
  196. for (i = 1; i <= 10; i++) {
  197. mg_printf(conn, "%x\r\n", i);
  198. mg_write(conn, chunk_data, (unsigned)i);
  199. mg_printf(conn, "\r\n");
  200. }
  201. mg_printf(conn, "0\r\n\r\n");
  202. return 1;
  203. }
  204. START_TEST(test_request_handlers)
  205. {
  206. char ebuf[100];
  207. struct mg_context *ctx;
  208. struct mg_connection *conn;
  209. const struct mg_request_info *ri;
  210. char uri[64];
  211. char buf[1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 8];
  212. const char *expected =
  213. "112123123412345123456123456712345678123456789123456789A";
  214. int i;
  215. const char *request = "GET /U7 HTTP/1.0\r\n\r\n";
  216. #if defined(USE_IPV6) && defined(NO_SSL)
  217. const char *HTTP_PORT = "8084,[::]:8086";
  218. short ipv4_port = 8084;
  219. short ipv6_port = 8086;
  220. #elif !defined(USE_IPV6) && defined(NO_SSL)
  221. const char *HTTP_PORT = "8084";
  222. short ipv4_port = 8084;
  223. #elif defined(USE_IPV6) && !defined(NO_SSL)
  224. const char *HTTP_PORT = "8084,[::]:8086,8194r,[::]:8196r,8094s,[::]:8096s";
  225. short ipv4_port = 8084;
  226. short ipv4s_port = 8094;
  227. short ipv4r_port = 8194;
  228. short ipv6_port = 8086;
  229. short ipv6s_port = 8096;
  230. short ipv6r_port = 8196;
  231. #elif !defined(USE_IPV6) && !defined(NO_SSL)
  232. const char *HTTP_PORT = "8084,8194r,8094s";
  233. short ipv4_port = 8084;
  234. short ipv4s_port = 8094;
  235. short ipv4r_port = 8194;
  236. #endif
  237. const char *OPTIONS[8]; /* initializer list here is rejected by CI test */
  238. const char *opt;
  239. FILE *f;
  240. memset((void *)OPTIONS, 0, sizeof(OPTIONS));
  241. OPTIONS[0] = "listening_ports";
  242. OPTIONS[1] = HTTP_PORT;
  243. OPTIONS[2] = "document_root";
  244. OPTIONS[3] = ".";
  245. #ifndef NO_SSL
  246. OPTIONS[4] = "ssl_certificate";
  247. #ifdef _WIN32
  248. OPTIONS[5] = "..\\..\\..\\resources/ssl_cert.pem"; // TODO: the different paths used in the different test system is an unsolved problem
  249. #else
  250. OPTIONS[5] = "../../resources/ssl_cert.pem"; // TODO: fix path in CI test environment
  251. #endif
  252. #endif
  253. ck_assert(OPTIONS[sizeof(OPTIONS) / sizeof(OPTIONS[0]) - 1] == NULL);
  254. ck_assert(OPTIONS[sizeof(OPTIONS) / sizeof(OPTIONS[0]) - 2] == NULL);
  255. ctx = mg_start(NULL, &g_ctx, OPTIONS);
  256. ck_assert(ctx != NULL);
  257. g_ctx = ctx;
  258. opt = mg_get_option(ctx, "listening_ports");
  259. ck_assert_str_eq(opt, HTTP_PORT);
  260. opt = mg_get_option(ctx, "cgi_environment");
  261. ck_assert_str_eq(opt, "");
  262. opt = mg_get_option(ctx, "unknown_option_name");
  263. ck_assert(opt == NULL);
  264. for (i = 0; i < 1000; i++) {
  265. sprintf(uri, "/U%u", i);
  266. mg_set_request_handler(ctx, uri, request_test_handler, NULL);
  267. }
  268. for (i = 500; i < 800; i++) {
  269. sprintf(uri, "/U%u", i);
  270. mg_set_request_handler(ctx, uri, NULL, (void *)1);
  271. }
  272. for (i = 600; i >= 0; i--) {
  273. sprintf(uri, "/U%u", i);
  274. mg_set_request_handler(ctx, uri, NULL, (void *)2);
  275. }
  276. for (i = 750; i <= 1000; i++) {
  277. sprintf(uri, "/U%u", i);
  278. mg_set_request_handler(ctx, uri, NULL, (void *)3);
  279. }
  280. for (i = 5; i < 9; i++) {
  281. sprintf(uri, "/U%u", i);
  282. mg_set_request_handler(
  283. ctx, uri, request_test_handler, (void *)(ptrdiff_t)i);
  284. }
  285. /* Try to load non existing file */
  286. conn = mg_download("localhost",
  287. ipv4_port,
  288. 0,
  289. ebuf,
  290. sizeof(ebuf),
  291. "%s",
  292. "GET /file/not/found HTTP/1.0\r\n\r\n");
  293. ck_assert(conn != NULL);
  294. ri = mg_get_request_info(conn);
  295. ck_assert(ri != NULL);
  296. ck_assert_str_eq(ri->uri, "404");
  297. mg_close_connection(conn);
  298. /* Get data from callback */
  299. conn = mg_download(
  300. "localhost", ipv4_port, 0, ebuf, sizeof(ebuf), "%s", request);
  301. ck_assert(conn != NULL);
  302. ri = mg_get_request_info(conn);
  303. ck_assert(ri != NULL);
  304. ck_assert_str_eq(ri->uri, "200");
  305. i = mg_read(conn, buf, sizeof(buf));
  306. ck_assert_int_eq(i, (int)strlen(expected));
  307. buf[i] = 0;
  308. ck_assert_str_eq(buf, expected);
  309. mg_close_connection(conn);
  310. /* Get data from callback using http://127.0.0.1 */
  311. conn = mg_download(
  312. "127.0.0.1", ipv4_port, 0, ebuf, sizeof(ebuf), "%s", request);
  313. ck_assert(conn != NULL);
  314. ri = mg_get_request_info(conn);
  315. ck_assert(ri != NULL);
  316. ck_assert_str_eq(ri->uri, "200");
  317. i = mg_read(conn, buf, sizeof(buf));
  318. ck_assert_int_eq(i, (int)strlen(expected));
  319. buf[i] = 0;
  320. ck_assert_str_eq(buf, expected);
  321. mg_close_connection(conn);
  322. #if defined(USE_IPV6)
  323. /* Get data from callback using http://[::1] */
  324. conn =
  325. mg_download("[::1]", ipv6_port, 0, ebuf, sizeof(ebuf), "%s", request);
  326. ck_assert(conn != NULL);
  327. ri = mg_get_request_info(conn);
  328. ck_assert(ri != NULL);
  329. ck_assert_str_eq(ri->uri, "200");
  330. i = mg_read(conn, buf, sizeof(buf));
  331. ck_assert_int_eq(i, (int)strlen(expected));
  332. buf[i] = 0;
  333. ck_assert_str_eq(buf, expected);
  334. mg_close_connection(conn);
  335. #endif
  336. #if !defined(NO_SSL)
  337. /* Get data from callback using https://127.0.0.1 */
  338. conn = mg_download(
  339. "127.0.0.1", ipv4s_port, 1, ebuf, sizeof(ebuf), "%s", request);
  340. ck_assert(conn != NULL);
  341. ri = mg_get_request_info(conn);
  342. ck_assert(ri != NULL);
  343. ck_assert_str_eq(ri->uri, "200");
  344. i = mg_read(conn, buf, sizeof(buf));
  345. ck_assert_int_eq(i, (int)strlen(expected));
  346. buf[i] = 0;
  347. ck_assert_str_eq(buf, expected);
  348. mg_close_connection(conn);
  349. /* Get redirect from callback using http://127.0.0.1 */
  350. conn = mg_download(
  351. "127.0.0.1", ipv4r_port, 0, ebuf, sizeof(ebuf), "%s", request);
  352. ck_assert(conn != NULL);
  353. ri = mg_get_request_info(conn);
  354. ck_assert(ri != NULL);
  355. ck_assert_str_eq(ri->uri, "302");
  356. i = mg_read(conn, buf, sizeof(buf));
  357. ck_assert_int_eq(i, -1);
  358. mg_close_connection(conn);
  359. #endif
  360. #if defined(USE_IPV6) && !defined(NO_SSL)
  361. /* Get data from callback using https://[::1] */
  362. conn =
  363. mg_download("[::1]", ipv6s_port, 1, ebuf, sizeof(ebuf), "%s", request);
  364. ck_assert(conn != NULL);
  365. ri = mg_get_request_info(conn);
  366. ck_assert(ri != NULL);
  367. ck_assert_str_eq(ri->uri, "200");
  368. i = mg_read(conn, buf, sizeof(buf));
  369. ck_assert_int_eq(i, (int)strlen(expected));
  370. buf[i] = 0;
  371. ck_assert_str_eq(buf, expected);
  372. mg_close_connection(conn);
  373. /* Get redirect from callback using http://127.0.0.1 */
  374. conn =
  375. mg_download("[::1]", ipv6r_port, 0, ebuf, sizeof(ebuf), "%s", request);
  376. ck_assert(conn != NULL);
  377. ri = mg_get_request_info(conn);
  378. ck_assert(ri != NULL);
  379. ck_assert_str_eq(ri->uri, "302");
  380. i = mg_read(conn, buf, sizeof(buf));
  381. ck_assert_int_eq(i, -1);
  382. mg_close_connection(conn);
  383. #endif
  384. /* It seems to be impossible to find out what the actual working
  385. * directory of the CI test environment is. Before breaking another
  386. * dozen of builds by trying blindly with different paths, just
  387. * create the file here */
  388. #ifdef _WIN32
  389. f = fopen("test.txt", "wb");
  390. #else
  391. f = fopen("test.txt", "w");
  392. #endif
  393. fwrite("simple text file\n", 17, 1, f);
  394. fclose(f);
  395. /* Get static data */
  396. conn = mg_download("localhost",
  397. ipv4_port,
  398. 0,
  399. ebuf,
  400. sizeof(ebuf),
  401. "%s",
  402. "GET /test.txt HTTP/1.0\r\n\r\n");
  403. ck_assert(conn != NULL);
  404. ri = mg_get_request_info(conn);
  405. ck_assert(ri != NULL);
  406. ck_assert_str_eq(ri->uri, "200");
  407. i = mg_read(conn, buf, sizeof(buf));
  408. ck_assert_int_eq(i, 17);
  409. if ((i >= 0) && (i < (int)sizeof(buf))) {
  410. buf[i] = 0;
  411. }
  412. ck_assert_str_eq(buf, "simple text file\n");
  413. mg_close_connection(conn);
  414. /* Get directory listing */
  415. conn = mg_download("localhost",
  416. ipv4_port,
  417. 0,
  418. ebuf,
  419. sizeof(ebuf),
  420. "%s",
  421. "GET / HTTP/1.0\r\n\r\n");
  422. ck_assert(conn != NULL);
  423. ri = mg_get_request_info(conn);
  424. ck_assert(ri != NULL);
  425. ck_assert_str_eq(ri->uri, "200");
  426. i = mg_read(conn, buf, sizeof(buf));
  427. ck_assert(i > 6);
  428. buf[6] = 0;
  429. ck_assert_str_eq(buf, "<html>");
  430. mg_close_connection(conn);
  431. /* POST to static file (will not work) */
  432. conn = mg_download("localhost",
  433. ipv4_port,
  434. 0,
  435. ebuf,
  436. sizeof(ebuf),
  437. "%s",
  438. "POST /test.txt HTTP/1.0\r\n\r\n");
  439. ck_assert(conn != NULL);
  440. ri = mg_get_request_info(conn);
  441. ck_assert(ri != NULL);
  442. ck_assert_str_eq(ri->uri, "405");
  443. i = mg_read(conn, buf, sizeof(buf));
  444. ck_assert(i >= 29);
  445. buf[29] = 0;
  446. ck_assert_str_eq(buf, "Error 405: Method Not Allowed");
  447. mg_close_connection(conn);
  448. /* PUT to static file (will not work) */
  449. conn = mg_download("localhost",
  450. ipv4_port,
  451. 0,
  452. ebuf,
  453. sizeof(ebuf),
  454. "%s",
  455. "PUT /test.txt HTTP/1.0\r\n\r\n");
  456. ck_assert(conn != NULL);
  457. ri = mg_get_request_info(conn);
  458. ck_assert(ri != NULL);
  459. ck_assert_str_eq(ri->uri, "401"); /* not authorized */
  460. mg_close_connection(conn);
  461. /* TODO: Test websockets */
  462. /* Close the server */
  463. g_ctx = NULL;
  464. mg_stop(ctx);
  465. mg_Sleep(1);
  466. }
  467. END_TEST
  468. Suite *make_public_server_suite(void)
  469. {
  470. Suite *const suite = suite_create("PublicServer");
  471. TCase *const checktestenv = tcase_create("Check test environment");
  472. TCase *const startstophttp = tcase_create("Start Stop HTTP Server");
  473. TCase *const startstophttps = tcase_create("Start Stop HTTPS Server");
  474. TCase *const serverrequests = tcase_create("Server Requests");
  475. tcase_add_test(checktestenv, test_the_test_environment);
  476. suite_add_tcase(suite, checktestenv);
  477. tcase_add_test(startstophttp, test_mg_start_stop_http_server);
  478. suite_add_tcase(suite, startstophttp);
  479. tcase_add_test(startstophttps, test_mg_start_stop_https_server);
  480. suite_add_tcase(suite, startstophttps);
  481. tcase_add_test(serverrequests, test_request_handlers);
  482. suite_add_tcase(suite, serverrequests);
  483. return suite;
  484. }
  485. #ifdef REPLACE_CHECK_FOR_LOCAL_DEBUGGING
  486. /* Used to debug test cases without using the check framework */
  487. static int chk_ok = 0;
  488. static int chk_failed = 0;
  489. void main(void)
  490. {
  491. test_the_test_environment(0);
  492. test_mg_start_stop_http_server(0);
  493. test_mg_start_stop_https_server(0);
  494. test_request_handlers(0);
  495. printf("\nok: %i\nfailed: %i\n\n", chk_ok, chk_failed);
  496. }
  497. void _ck_assert_failed(const char *file, int line, const char *expr, ...)
  498. {
  499. va_list va;
  500. va_start(va, expr);
  501. fprintf(stderr, "Error: %s, line %i\n", file, line); /* breakpoint here ! */
  502. vfprintf(stderr, expr, va);
  503. va_end(va);
  504. chk_failed++;
  505. }
  506. void _mark_point(const char *file, int line) { chk_ok++; }
  507. void tcase_fn_start(const char *fname, const char *file, int line) {}
  508. void suite_add_tcase(Suite *s, TCase *tc){};
  509. void _tcase_add_test(TCase *tc,
  510. TFun tf,
  511. const char *fname,
  512. int _signal,
  513. int allowed_exit_value,
  514. int start,
  515. int end){};
  516. TCase *tcase_create(const char *name) { return NULL; };
  517. Suite *suite_create(const char *name) { return NULL; };
  518. #endif