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.
 
 
 
 
 
 

118 lines
4.1 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, see <http://www.gnu.org/licenses/>. *
  23. ***************************************************************************/
  24. #ifndef OPENOCD_SERVER_SERVER_H
  25. #define OPENOCD_SERVER_SERVER_H
  26. #ifdef HAVE_CONFIG_H
  27. #include "config.h"
  28. #endif
  29. #include <helper/log.h>
  30. #ifdef HAVE_NETINET_IN_H
  31. #include <netinet/in.h>
  32. #endif
  33. enum connection_type {
  34. CONNECTION_TCP,
  35. CONNECTION_PIPE,
  36. CONNECTION_STDINOUT
  37. };
  38. #define CONNECTION_LIMIT_UNLIMITED (-1)
  39. struct connection {
  40. int fd;
  41. int fd_out; /* When using pipes we're writing to a different fd */
  42. struct sockaddr_in sin;
  43. struct command_context *cmd_ctx;
  44. struct service *service;
  45. int input_pending;
  46. void *priv;
  47. struct connection *next;
  48. };
  49. typedef int (*new_connection_handler_t)(struct connection *connection);
  50. typedef int (*input_handler_t)(struct connection *connection);
  51. typedef int (*connection_closed_handler_t)(struct connection *connection);
  52. struct service {
  53. char *name;
  54. enum connection_type type;
  55. char *port;
  56. unsigned short portnumber;
  57. int fd;
  58. struct sockaddr_in sin;
  59. int max_connections;
  60. struct connection *connections;
  61. new_connection_handler_t new_connection;
  62. input_handler_t input;
  63. connection_closed_handler_t connection_closed;
  64. void *priv;
  65. struct service *next;
  66. };
  67. int add_service(char *name, const char *port,
  68. int max_connections, new_connection_handler_t new_connection_handler,
  69. input_handler_t in_handler, connection_closed_handler_t close_handler,
  70. void *priv);
  71. int remove_service(const char *name, const char *port);
  72. int server_preinit(void);
  73. int server_init(struct command_context *cmd_ctx);
  74. int server_quit(void);
  75. void exit_on_signal(int);
  76. int server_loop(struct command_context *command_context);
  77. int server_register_commands(struct command_context *context);
  78. int connection_write(struct connection *connection, const void *data, int len);
  79. int connection_read(struct connection *connection, void *data, int len);
  80. /**
  81. * Used by server_loop(), defined in server_stubs.c
  82. */
  83. void openocd_sleep_prelude(void);
  84. /**
  85. * Used by server_loop(), defined in server_stubs.c
  86. */
  87. void openocd_sleep_postlude(void);
  88. /**
  89. * Defines an extended command handler function declaration to enable
  90. * access to (and manipulation of) the server port number.
  91. * Call server_port like a normal COMMAND_HANDLER with an extra @a out parameter
  92. * to receive the specified port number.
  93. */
  94. COMMAND_HELPER(server_pipe_command, char **out);
  95. COMMAND_HELPER(server_port_command, unsigned short *out);
  96. #define ERROR_SERVER_REMOTE_CLOSED (-400)
  97. #define ERROR_CONNECTION_REJECTED (-401)
  98. #endif /* OPENOCD_SERVER_SERVER_H */