test-server.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /*
  2. * libwebsockets-test-server - libwebsockets test implementation
  3. *
  4. * Copyright (C) 2010-2016 Andy Green <andy@warmcat.com>
  5. *
  6. * This file is made available under the Creative Commons CC0 1.0
  7. * Universal Public Domain Dedication.
  8. *
  9. * The person who associated a work with this deed has dedicated
  10. * the work to the public domain by waiving all of his or her rights
  11. * to the work worldwide under copyright law, including all related
  12. * and neighboring rights, to the extent allowed by law. You can copy,
  13. * modify, distribute and perform the work, even for commercial purposes,
  14. * all without asking permission.
  15. *
  16. * The test apps are intended to be adapted for use in your code, which
  17. * may be proprietary. So unlike the library itself, they are licensed
  18. * Public Domain.
  19. */
  20. #if defined(_WIN32) && defined(EXTERNAL_POLL)
  21. #define WINVER 0x0600
  22. #define _WIN32_WINNT 0x0600
  23. #define poll(fdArray, fds, timeout) WSAPoll((LPWSAPOLLFD)(fdArray), (ULONG)(fds), (INT)(timeout))
  24. #endif
  25. #include "lws_config.h"
  26. #include <stdio.h>
  27. #include <stdlib.h>
  28. #include <getopt.h>
  29. #include <signal.h>
  30. #include <string.h>
  31. #include <sys/stat.h>
  32. #include <fcntl.h>
  33. #include <assert.h>
  34. #include "../lib/libwebsockets.h"
  35. #ifdef _WIN32
  36. #include <io.h>
  37. #include "gettimeofday.h"
  38. #else
  39. #include <syslog.h>
  40. #include <sys/time.h>
  41. #include <unistd.h>
  42. #endif
  43. extern int close_testing;
  44. extern int max_poll_elements;
  45. #ifdef EXTERNAL_POLL
  46. extern struct lws_pollfd *pollfds;
  47. extern int *fd_lookup;
  48. extern int count_pollfds;
  49. #endif
  50. extern volatile int force_exit;
  51. extern struct lws_context *context;
  52. extern char *resource_path;
  53. #if defined(LWS_OPENSSL_SUPPORT) && defined(LWS_HAVE_SSL_CTX_set1_param)
  54. extern char crl_path[1024];
  55. #endif
  56. extern void test_server_lock(int care);
  57. extern void test_server_unlock(int care);
  58. #ifndef __func__
  59. #define __func__ __FUNCTION__
  60. #endif
  61. struct per_session_data__http {
  62. lws_fop_fd_t fop_fd;
  63. #ifdef LWS_WITH_CGI
  64. struct lws_cgi_args args;
  65. #endif
  66. #if defined(LWS_WITH_CGI) || !defined(LWS_NO_CLIENT)
  67. int reason_bf;
  68. #endif
  69. unsigned int client_finished:1;
  70. struct lws_spa *spa;
  71. char result[500 + LWS_PRE];
  72. int result_len;
  73. char filename[256];
  74. long file_length;
  75. lws_filefd_type post_fd;
  76. };
  77. /*
  78. * one of these is auto-created for each connection and a pointer to the
  79. * appropriate instance is passed to the callback in the user parameter
  80. *
  81. * for this example protocol we use it to individualize the count for each
  82. * connection.
  83. */
  84. struct per_session_data__dumb_increment {
  85. int number;
  86. };
  87. struct per_session_data__lws_mirror {
  88. struct lws *wsi;
  89. int ringbuffer_tail;
  90. };
  91. struct per_session_data__echogen {
  92. size_t total;
  93. size_t total_rx;
  94. int fd;
  95. int fragsize;
  96. int wr;
  97. };
  98. struct per_session_data__lws_status {
  99. struct per_session_data__lws_status *list;
  100. struct timeval tv_established;
  101. int last;
  102. char ip[270];
  103. char user_agent[512];
  104. const char *pos;
  105. int len;
  106. };
  107. extern int
  108. callback_http(struct lws *wsi, enum lws_callback_reasons reason, void *user,
  109. void *in, size_t len);
  110. extern int
  111. callback_lws_mirror(struct lws *wsi, enum lws_callback_reasons reason,
  112. void *user, void *in, size_t len);
  113. extern int
  114. callback_dumb_increment(struct lws *wsi, enum lws_callback_reasons reason,
  115. void *user, void *in, size_t len);
  116. extern int
  117. callback_lws_echogen(struct lws *wsi, enum lws_callback_reasons reason,
  118. void *user, void *in, size_t len);
  119. extern int
  120. callback_lws_status(struct lws *wsi, enum lws_callback_reasons reason,
  121. void *user, void *in, size_t len);
  122. extern void
  123. dump_handshake_info(struct lws *wsi);