CivetServer.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749
  1. /* Copyright (c) 2013-2020 the Civetweb developers
  2. * Copyright (c) 2013 No Face Press, LLC
  3. *
  4. * License http://opensource.org/licenses/mit-license.php MIT License
  5. */
  6. #include "CivetServer.h"
  7. #include <assert.h>
  8. #include <stdexcept>
  9. #include <string.h>
  10. #ifndef UNUSED_PARAMETER
  11. #define UNUSED_PARAMETER(x) (void)(x)
  12. #endif
  13. #ifndef MAX_PARAM_BODY_LENGTH
  14. // Set a default limit for parameters in a form body: 2 MB
  15. #define MAX_PARAM_BODY_LENGTH (1024 * 1024 * 2)
  16. #endif
  17. bool
  18. CivetHandler::handleGet(CivetServer *server, struct mg_connection *conn)
  19. {
  20. UNUSED_PARAMETER(server);
  21. UNUSED_PARAMETER(conn);
  22. return false;
  23. }
  24. bool
  25. CivetHandler::handleGet(CivetServer *server,
  26. struct mg_connection *conn,
  27. int *status_code)
  28. {
  29. UNUSED_PARAMETER(server);
  30. UNUSED_PARAMETER(conn);
  31. if (status_code) {
  32. *status_code = -1;
  33. }
  34. return false;
  35. }
  36. bool
  37. CivetHandler::handlePost(CivetServer *server, struct mg_connection *conn)
  38. {
  39. UNUSED_PARAMETER(server);
  40. UNUSED_PARAMETER(conn);
  41. return false;
  42. }
  43. bool
  44. CivetHandler::handlePost(CivetServer *server,
  45. struct mg_connection *conn,
  46. int *status_code)
  47. {
  48. UNUSED_PARAMETER(server);
  49. UNUSED_PARAMETER(conn);
  50. if (status_code) {
  51. *status_code = -1;
  52. }
  53. return false;
  54. }
  55. bool
  56. CivetHandler::handleHead(CivetServer *server, struct mg_connection *conn)
  57. {
  58. UNUSED_PARAMETER(server);
  59. UNUSED_PARAMETER(conn);
  60. return false;
  61. }
  62. bool
  63. CivetHandler::handleHead(CivetServer *server,
  64. struct mg_connection *conn,
  65. int *status_code)
  66. {
  67. UNUSED_PARAMETER(server);
  68. UNUSED_PARAMETER(conn);
  69. if (status_code) {
  70. *status_code = -1;
  71. }
  72. return false;
  73. }
  74. bool
  75. CivetHandler::handlePut(CivetServer *server, struct mg_connection *conn)
  76. {
  77. UNUSED_PARAMETER(server);
  78. UNUSED_PARAMETER(conn);
  79. return false;
  80. }
  81. bool
  82. CivetHandler::handlePut(CivetServer *server,
  83. struct mg_connection *conn,
  84. int *status_code)
  85. {
  86. UNUSED_PARAMETER(server);
  87. UNUSED_PARAMETER(conn);
  88. if (status_code) {
  89. *status_code = -1;
  90. }
  91. return false;
  92. }
  93. bool
  94. CivetHandler::handlePatch(CivetServer *server, struct mg_connection *conn)
  95. {
  96. UNUSED_PARAMETER(server);
  97. UNUSED_PARAMETER(conn);
  98. return false;
  99. }
  100. bool
  101. CivetHandler::handlePatch(CivetServer *server,
  102. struct mg_connection *conn,
  103. int *status_code)
  104. {
  105. UNUSED_PARAMETER(server);
  106. UNUSED_PARAMETER(conn);
  107. if (status_code) {
  108. *status_code = -1;
  109. }
  110. return false;
  111. }
  112. bool
  113. CivetHandler::handleDelete(CivetServer *server, struct mg_connection *conn)
  114. {
  115. UNUSED_PARAMETER(server);
  116. UNUSED_PARAMETER(conn);
  117. return false;
  118. }
  119. bool
  120. CivetHandler::handleDelete(CivetServer *server,
  121. struct mg_connection *conn,
  122. int *status_code)
  123. {
  124. UNUSED_PARAMETER(server);
  125. UNUSED_PARAMETER(conn);
  126. if (status_code) {
  127. *status_code = -1;
  128. }
  129. return false;
  130. }
  131. bool
  132. CivetHandler::handleOptions(CivetServer *server, struct mg_connection *conn)
  133. {
  134. UNUSED_PARAMETER(server);
  135. UNUSED_PARAMETER(conn);
  136. return false;
  137. }
  138. bool
  139. CivetHandler::handleOptions(CivetServer *server,
  140. struct mg_connection *conn,
  141. int *status_code)
  142. {
  143. UNUSED_PARAMETER(server);
  144. UNUSED_PARAMETER(conn);
  145. if (status_code) {
  146. *status_code = -1;
  147. }
  148. return false;
  149. }
  150. bool
  151. CivetWebSocketHandler::handleConnection(CivetServer *server,
  152. const struct mg_connection *conn)
  153. {
  154. UNUSED_PARAMETER(server);
  155. UNUSED_PARAMETER(conn);
  156. return true;
  157. }
  158. void
  159. CivetWebSocketHandler::handleReadyState(CivetServer *server,
  160. struct mg_connection *conn)
  161. {
  162. UNUSED_PARAMETER(server);
  163. UNUSED_PARAMETER(conn);
  164. return;
  165. }
  166. bool
  167. CivetWebSocketHandler::handleData(CivetServer *server,
  168. struct mg_connection *conn,
  169. int bits,
  170. char *data,
  171. size_t data_len)
  172. {
  173. UNUSED_PARAMETER(server);
  174. UNUSED_PARAMETER(conn);
  175. UNUSED_PARAMETER(bits);
  176. UNUSED_PARAMETER(data);
  177. UNUSED_PARAMETER(data_len);
  178. return true;
  179. }
  180. void
  181. CivetWebSocketHandler::handleClose(CivetServer *server,
  182. const struct mg_connection *conn)
  183. {
  184. UNUSED_PARAMETER(server);
  185. UNUSED_PARAMETER(conn);
  186. return;
  187. }
  188. int
  189. CivetServer::requestHandler(struct mg_connection *conn, void *cbdata)
  190. {
  191. const struct mg_request_info *request_info = mg_get_request_info(conn);
  192. assert(request_info != NULL);
  193. CivetServer *me = (CivetServer *)(request_info->user_data);
  194. assert(me != NULL);
  195. int http_status_code = -1;
  196. bool status_ok = false;
  197. // Happens when a request hits the server before the context is saved
  198. if (me->context == NULL)
  199. return 0;
  200. mg_lock_context(me->context);
  201. me->connections[conn] = CivetConnection();
  202. mg_unlock_context(me->context);
  203. CivetHandler *handler = (CivetHandler *)cbdata;
  204. if (handler) {
  205. if (strcmp(request_info->request_method, "GET") == 0) {
  206. status_ok = handler->handleGet(me, conn, &http_status_code);
  207. if (http_status_code < 0) {
  208. status_ok = handler->handleGet(me, conn);
  209. }
  210. } else if (strcmp(request_info->request_method, "POST") == 0) {
  211. status_ok = handler->handlePost(me, conn, &http_status_code);
  212. if (http_status_code < 0) {
  213. status_ok = handler->handlePost(me, conn);
  214. }
  215. } else if (strcmp(request_info->request_method, "HEAD") == 0) {
  216. status_ok = handler->handleHead(me, conn, &http_status_code);
  217. if (http_status_code < 0) {
  218. status_ok = handler->handleHead(me, conn);
  219. }
  220. } else if (strcmp(request_info->request_method, "PUT") == 0) {
  221. status_ok = handler->handlePut(me, conn, &http_status_code);
  222. if (http_status_code < 0) {
  223. status_ok = handler->handlePut(me, conn);
  224. }
  225. } else if (strcmp(request_info->request_method, "DELETE") == 0) {
  226. status_ok = handler->handleDelete(me, conn, &http_status_code);
  227. if (http_status_code < 0) {
  228. status_ok = handler->handleDelete(me, conn);
  229. }
  230. } else if (strcmp(request_info->request_method, "OPTIONS") == 0) {
  231. status_ok = handler->handleOptions(me, conn, &http_status_code);
  232. if (http_status_code < 0) {
  233. status_ok = handler->handleOptions(me, conn);
  234. }
  235. } else if (strcmp(request_info->request_method, "PATCH") == 0) {
  236. status_ok = handler->handlePatch(me, conn, &http_status_code);
  237. if (http_status_code < 0) {
  238. status_ok = handler->handlePatch(me, conn);
  239. }
  240. }
  241. }
  242. if (http_status_code < 0) {
  243. http_status_code = status_ok ? 1 : 0;
  244. }
  245. return http_status_code;
  246. }
  247. int
  248. CivetServer::authHandler(struct mg_connection *conn, void *cbdata)
  249. {
  250. const struct mg_request_info *request_info = mg_get_request_info(conn);
  251. assert(request_info != NULL);
  252. CivetServer *me = (CivetServer *)(request_info->user_data);
  253. assert(me != NULL);
  254. // Happens when a request hits the server before the context is saved
  255. if (me->context == NULL)
  256. return 0;
  257. mg_lock_context(me->context);
  258. me->connections[conn] = CivetConnection();
  259. mg_unlock_context(me->context);
  260. CivetAuthHandler *handler = (CivetAuthHandler *)cbdata;
  261. if (handler) {
  262. return handler->authorize(me, conn) ? 1 : 0;
  263. }
  264. return 0; // No handler found
  265. }
  266. int
  267. CivetServer::webSocketConnectionHandler(const struct mg_connection *conn,
  268. void *cbdata)
  269. {
  270. const struct mg_request_info *request_info = mg_get_request_info(conn);
  271. assert(request_info != NULL);
  272. CivetServer *me = (CivetServer *)(request_info->user_data);
  273. assert(me != NULL);
  274. // Happens when a request hits the server before the context is saved
  275. if (me->context == NULL)
  276. return 0;
  277. CivetWebSocketHandler *handler = (CivetWebSocketHandler *)cbdata;
  278. if (handler) {
  279. return handler->handleConnection(me, conn) ? 0 : 1;
  280. }
  281. return 1; // No handler found, close connection
  282. }
  283. void
  284. CivetServer::webSocketReadyHandler(struct mg_connection *conn, void *cbdata)
  285. {
  286. const struct mg_request_info *request_info = mg_get_request_info(conn);
  287. assert(request_info != NULL);
  288. CivetServer *me = (CivetServer *)(request_info->user_data);
  289. assert(me != NULL);
  290. // Happens when a request hits the server before the context is saved
  291. if (me->context == NULL)
  292. return;
  293. CivetWebSocketHandler *handler = (CivetWebSocketHandler *)cbdata;
  294. if (handler) {
  295. handler->handleReadyState(me, conn);
  296. }
  297. }
  298. int
  299. CivetServer::webSocketDataHandler(struct mg_connection *conn,
  300. int bits,
  301. char *data,
  302. size_t data_len,
  303. void *cbdata)
  304. {
  305. const struct mg_request_info *request_info = mg_get_request_info(conn);
  306. assert(request_info != NULL);
  307. CivetServer *me = (CivetServer *)(request_info->user_data);
  308. assert(me != NULL);
  309. // Happens when a request hits the server before the context is saved
  310. if (me->context == NULL)
  311. return 0;
  312. CivetWebSocketHandler *handler = (CivetWebSocketHandler *)cbdata;
  313. if (handler) {
  314. return handler->handleData(me, conn, bits, data, data_len) ? 1 : 0;
  315. }
  316. return 1; // No handler found
  317. }
  318. void
  319. CivetServer::webSocketCloseHandler(const struct mg_connection *conn,
  320. void *cbdata)
  321. {
  322. const struct mg_request_info *request_info = mg_get_request_info(conn);
  323. assert(request_info != NULL);
  324. CivetServer *me = (CivetServer *)(request_info->user_data);
  325. assert(me != NULL);
  326. // Happens when a request hits the server before the context is saved
  327. if (me->context == NULL)
  328. return;
  329. CivetWebSocketHandler *handler = (CivetWebSocketHandler *)cbdata;
  330. if (handler) {
  331. handler->handleClose(me, conn);
  332. }
  333. }
  334. CivetCallbacks::CivetCallbacks()
  335. {
  336. memset(this, 0, sizeof(*this));
  337. }
  338. CivetServer::CivetServer(const char **options,
  339. const struct CivetCallbacks *_callbacks,
  340. const void *UserContextIn)
  341. : context(0)
  342. {
  343. struct CivetCallbacks callbacks;
  344. memset(&callbacks, 0, sizeof(callbacks));
  345. UserContext = UserContextIn;
  346. if (_callbacks) {
  347. callbacks = *_callbacks;
  348. userCloseHandler = _callbacks->connection_close;
  349. } else {
  350. userCloseHandler = NULL;
  351. }
  352. callbacks.connection_close = closeHandler;
  353. context = mg_start(&callbacks, this, options);
  354. if (context == NULL) {
  355. throw CivetException("null context when constructing CivetServer. "
  356. "Possible problem binding to port.");
  357. }
  358. }
  359. CivetServer::CivetServer(const std::vector<std::string> &options,
  360. const struct CivetCallbacks *_callbacks,
  361. const void *UserContextIn)
  362. : context(0)
  363. {
  364. struct CivetCallbacks callbacks;
  365. memset(&callbacks, 0, sizeof(callbacks));
  366. UserContext = UserContextIn;
  367. if (_callbacks) {
  368. callbacks = *_callbacks;
  369. userCloseHandler = _callbacks->connection_close;
  370. } else {
  371. userCloseHandler = NULL;
  372. }
  373. callbacks.connection_close = closeHandler;
  374. std::vector<const char *> pointers(options.size() + 1);
  375. for (size_t i = 0; i < options.size(); i++) {
  376. pointers[i] = (options[i].c_str());
  377. }
  378. pointers.back() = NULL;
  379. context = mg_start(&callbacks, this, &pointers[0]);
  380. if (context == NULL)
  381. throw CivetException("null context when constructing CivetServer. "
  382. "Possible problem binding to port.");
  383. }
  384. CivetServer::~CivetServer()
  385. {
  386. close();
  387. }
  388. void
  389. CivetServer::closeHandler(const struct mg_connection *conn)
  390. {
  391. CivetServer *me = (CivetServer *)mg_get_user_data(mg_get_context(conn));
  392. assert(me != NULL);
  393. // Happens when a request hits the server before the context is saved
  394. if (me->context == NULL)
  395. return;
  396. if (me->userCloseHandler) {
  397. me->userCloseHandler(conn);
  398. }
  399. mg_lock_context(me->context);
  400. me->connections.erase(conn);
  401. mg_unlock_context(me->context);
  402. }
  403. void
  404. CivetServer::addHandler(const std::string &uri, CivetHandler *handler)
  405. {
  406. mg_set_request_handler(context, uri.c_str(), requestHandler, handler);
  407. }
  408. void
  409. CivetServer::addWebSocketHandler(const std::string &uri,
  410. CivetWebSocketHandler *handler)
  411. {
  412. mg_set_websocket_handler(context,
  413. uri.c_str(),
  414. webSocketConnectionHandler,
  415. webSocketReadyHandler,
  416. webSocketDataHandler,
  417. webSocketCloseHandler,
  418. handler);
  419. }
  420. void
  421. CivetServer::addAuthHandler(const std::string &uri, CivetAuthHandler *handler)
  422. {
  423. mg_set_auth_handler(context, uri.c_str(), authHandler, handler);
  424. }
  425. void
  426. CivetServer::removeHandler(const std::string &uri)
  427. {
  428. mg_set_request_handler(context, uri.c_str(), NULL, NULL);
  429. }
  430. void
  431. CivetServer::removeWebSocketHandler(const std::string &uri)
  432. {
  433. mg_set_websocket_handler(
  434. context, uri.c_str(), NULL, NULL, NULL, NULL, NULL);
  435. }
  436. void
  437. CivetServer::removeAuthHandler(const std::string &uri)
  438. {
  439. mg_set_auth_handler(context, uri.c_str(), NULL, NULL);
  440. }
  441. void
  442. CivetServer::close()
  443. {
  444. if (context) {
  445. mg_stop(context);
  446. context = 0;
  447. }
  448. }
  449. int
  450. CivetServer::getCookie(struct mg_connection *conn,
  451. const std::string &cookieName,
  452. std::string &cookieValue)
  453. {
  454. // Maximum cookie length as per microsoft is 4096.
  455. // http://msdn.microsoft.com/en-us/library/ms178194.aspx
  456. char _cookieValue[4096];
  457. const char *cookie = mg_get_header(conn, "Cookie");
  458. int lRead = mg_get_cookie(cookie,
  459. cookieName.c_str(),
  460. _cookieValue,
  461. sizeof(_cookieValue));
  462. cookieValue.clear();
  463. cookieValue.append(_cookieValue);
  464. return lRead;
  465. }
  466. const char *
  467. CivetServer::getHeader(struct mg_connection *conn,
  468. const std::string &headerName)
  469. {
  470. return mg_get_header(conn, headerName.c_str());
  471. }
  472. void
  473. CivetServer::urlDecode(const char *src,
  474. std::string &dst,
  475. bool is_form_url_encoded)
  476. {
  477. urlDecode(src, strlen(src), dst, is_form_url_encoded);
  478. }
  479. void
  480. CivetServer::urlDecode(const char *src,
  481. size_t src_len,
  482. std::string &dst,
  483. bool is_form_url_encoded)
  484. {
  485. // assign enough buffer
  486. std::vector<char> buf(src_len + 1);
  487. int r = mg_url_decode(src,
  488. static_cast<int>(src_len),
  489. &buf[0],
  490. static_cast<int>(buf.size()),
  491. is_form_url_encoded);
  492. if (r < 0) {
  493. // never reach here
  494. throw std::out_of_range("");
  495. }
  496. // dst can contain NUL characters
  497. dst.assign(buf.begin(), buf.begin() + r);
  498. }
  499. bool
  500. CivetServer::getParam(struct mg_connection *conn,
  501. const char *name,
  502. std::string &dst,
  503. size_t occurrence)
  504. {
  505. const char *formParams = NULL;
  506. const char *queryString = NULL;
  507. const struct mg_request_info *ri = mg_get_request_info(conn);
  508. assert(ri != NULL);
  509. CivetServer *me = (CivetServer *)(ri->user_data);
  510. assert(me != NULL);
  511. mg_lock_context(me->context);
  512. CivetConnection &conobj = me->connections[conn];
  513. mg_unlock_context(me->context);
  514. mg_lock_connection(conn);
  515. if (conobj.postData.empty()) {
  516. // check if there is a request body
  517. for (;;) {
  518. char buf[2048];
  519. int r = mg_read(conn, buf, sizeof(buf));
  520. try {
  521. if (r == 0) {
  522. conobj.postData.push_back('\0');
  523. break;
  524. } else if ((r < 0)
  525. || ((conobj.postData.size() + r)
  526. > MAX_PARAM_BODY_LENGTH)) {
  527. conobj.postData.assign(1, '\0');
  528. break;
  529. }
  530. conobj.postData.insert(conobj.postData.end(), buf, buf + r);
  531. } catch (...) {
  532. conobj.postData.clear();
  533. break;
  534. }
  535. }
  536. }
  537. if (!conobj.postData.empty()) {
  538. // check if form parameter are already stored
  539. formParams = &conobj.postData[0];
  540. }
  541. if (ri->query_string != NULL) {
  542. // get requests do store html <form> field values in the http
  543. // query_string
  544. queryString = ri->query_string;
  545. }
  546. mg_unlock_connection(conn);
  547. bool get_param_success = false;
  548. if (formParams != NULL) {
  549. get_param_success =
  550. getParam(formParams, strlen(formParams), name, dst, occurrence);
  551. }
  552. if (!get_param_success && queryString != NULL) {
  553. get_param_success =
  554. getParam(queryString, strlen(queryString), name, dst, occurrence);
  555. }
  556. return get_param_success;
  557. }
  558. bool
  559. CivetServer::getParam(const char *data,
  560. size_t data_len,
  561. const char *name,
  562. std::string &dst,
  563. size_t occurrence)
  564. {
  565. char buf[256];
  566. int r = mg_get_var2(data, data_len, name, buf, sizeof(buf), occurrence);
  567. if (r >= 0) {
  568. // dst can contain NUL characters
  569. dst.assign(buf, r);
  570. return true;
  571. } else if (r == -2) {
  572. // more buffer
  573. std::vector<char> vbuf(sizeof(buf) * 2);
  574. for (;;) {
  575. r = mg_get_var2(
  576. data, data_len, name, &vbuf[0], vbuf.size(), occurrence);
  577. if (r >= 0) {
  578. dst.assign(vbuf.begin(), vbuf.begin() + r);
  579. return true;
  580. } else if (r != -2) {
  581. break;
  582. }
  583. // more buffer
  584. vbuf.resize(vbuf.size() * 2);
  585. }
  586. }
  587. dst.clear();
  588. return false;
  589. }
  590. std::string
  591. CivetServer::getPostData(struct mg_connection *conn)
  592. {
  593. mg_lock_connection(conn);
  594. std::string postdata;
  595. char buf[2048];
  596. int r = mg_read(conn, buf, sizeof(buf));
  597. while (r > 0) {
  598. postdata.append(buf, r);
  599. r = mg_read(conn, buf, sizeof(buf));
  600. }
  601. mg_unlock_connection(conn);
  602. return postdata;
  603. }
  604. void
  605. CivetServer::urlEncode(const char *src, std::string &dst, bool append)
  606. {
  607. urlEncode(src, strlen(src), dst, append);
  608. }
  609. void
  610. CivetServer::urlEncode(const char *src,
  611. size_t src_len,
  612. std::string &dst,
  613. bool append)
  614. {
  615. if (!append)
  616. dst.clear();
  617. for (; src_len > 0; src++, src_len--) {
  618. if (*src == '\0') {
  619. // src and dst can contain NUL characters without encoding
  620. dst.push_back(*src);
  621. } else {
  622. char buf[2] = {*src, '\0'};
  623. char dst_buf[4];
  624. if (mg_url_encode(buf, dst_buf, sizeof(dst_buf)) < 0) {
  625. // never reach here
  626. throw std::out_of_range("");
  627. }
  628. dst.append(dst_buf);
  629. }
  630. }
  631. }
  632. std::vector<int>
  633. CivetServer::getListeningPorts()
  634. {
  635. std::vector<struct mg_server_port> server_ports = getListeningPortsFull();
  636. std::vector<int> ports(server_ports.size());
  637. for (size_t i = 0; i < server_ports.size(); i++) {
  638. ports[i] = server_ports[i].port;
  639. }
  640. return ports;
  641. }
  642. std::vector<struct mg_server_port>
  643. CivetServer::getListeningPortsFull()
  644. {
  645. std::vector<struct mg_server_port> server_ports(8);
  646. for (;;) {
  647. int size = mg_get_server_ports(context,
  648. static_cast<int>(server_ports.size()),
  649. &server_ports[0]);
  650. if (size < static_cast<int>(server_ports.size())) {
  651. server_ports.resize(size < 0 ? 0 : size);
  652. break;
  653. }
  654. server_ports.resize(server_ports.size() * 2);
  655. }
  656. return server_ports;
  657. }