You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

111 lines
3.9 KiB

  1. /***************************************************************************
  2. * Copyright (C) 2005 by Dominic Rath *
  3. * Dominic.Rath@gmx.de *
  4. * *
  5. * Copyright (C) 2007,2008 √ėyvind Harboe *
  6. * oyvind.harboe@zylin.com *
  7. * *
  8. * Copyright (C) 2008 by Spencer Oliver *
  9. * spen@spen-soft.co.uk *
  10. * *
  11. * This program is free software; you can redistribute it and/or modify *
  12. * it under the terms of the GNU General Public License as published by *
  13. * the Free Software Foundation; either version 2 of the License, or *
  14. * (at your option) any later version. *
  15. * *
  16. * This program is distributed in the hope that it will be useful, *
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  19. * GNU General Public License for more details. *
  20. * *
  21. * You should have received a copy of the GNU General Public License *
  22. * along with this program; if not, write to the *
  23. * Free Software Foundation, Inc., *
  24. * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
  25. ***************************************************************************/
  26. #ifndef SERVER_H
  27. #define SERVER_H
  28. #include <helper/log.h>
  29. #ifdef HAVE_NETINET_IN_H
  30. #include <netinet/in.h>
  31. #endif
  32. enum connection_type
  33. {
  34. CONNECTION_TCP,
  35. CONNECTION_PIPE
  36. };
  37. struct connection
  38. {
  39. int fd;
  40. struct sockaddr_in sin;
  41. struct command_context *cmd_ctx;
  42. struct service *service;
  43. int input_pending;
  44. void *priv;
  45. struct connection *next;
  46. };
  47. typedef int (*new_connection_handler_t)(struct connection *connection);
  48. typedef int (*input_handler_t)(struct connection *connection);
  49. typedef int (*connection_closed_handler_t)(struct connection *connection);
  50. struct service
  51. {
  52. char *name;
  53. enum connection_type type;
  54. unsigned short port;
  55. int fd;
  56. struct sockaddr_in sin;
  57. int max_connections;
  58. struct connection *connections;
  59. new_connection_handler_t new_connection;
  60. input_handler_t input;
  61. connection_closed_handler_t connection_closed;
  62. void *priv;
  63. struct service *next;
  64. };
  65. int add_service(char *name, enum connection_type type, unsigned short port,
  66. int max_connections, new_connection_handler_t new_connection_handler,
  67. input_handler_t in_handler, connection_closed_handler_t close_handler,
  68. void *priv);
  69. int server_preinit(void);
  70. int server_init(struct command_context *cmd_ctx);
  71. int server_quit(void);
  72. int server_loop(struct command_context *command_context);
  73. int server_register_commands(struct command_context *context);
  74. /**
  75. * Used by server_loop(), defined in server_stubs.c, httpd.c, or ecosboard.c
  76. */
  77. void openocd_sleep_prelude(void);
  78. /**
  79. * Used by server_loop(), defined in server_stubs.c, httpd.c, or ecosboard.c
  80. */
  81. void openocd_sleep_postlude(void);
  82. /**
  83. * Defines an extended command handler function declaration to enable
  84. * access to (and manipulation of) the server port number.
  85. * Call server_port like a normal COMMAND_HANDLER with an extra @a out parameter
  86. * to receive the specified port number.
  87. */
  88. #define SERVER_PORT_COMMAND() \
  89. COMMAND_HELPER(server_port_command, unsigned short *out)
  90. SERVER_PORT_COMMAND();
  91. extern int server_use_pipes;
  92. #define ERROR_SERVER_REMOTE_CLOSED (-400)
  93. #define ERROR_CONNECTION_REJECTED (-401)
  94. #endif /* SERVER_H */