No Description
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.

data.h 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /* tsiproxy data functions */
  2. #ifndef DATA_H
  3. # define DATA_H
  4. #include <netdb.h> // for uint32_t
  5. #include <sys/resource.h> // for rlim_t
  6. #include <sys/utsname.h> // for utsdata
  7. #include "libfuncs/queue.h"
  8. #include "libfuncs/list.h"
  9. typedef enum { udp_sock, tcp_sock } channel_source;
  10. typedef struct {
  11. int stats :1, /* S - STATS | allow access to stats and info server pages /used by data collection tools/ */
  12. reconf:1, /* F - RECONF | allow server reconfiguration request /used for sys admins/ (ex: http://XXX/{chanconf,netconf}) */
  13. access:1; /* A - ACCESS | Allow access from this network (used for bg networks) */
  14. } acl_t;
  15. typedef struct {
  16. uint32_t net;
  17. uint32_t mask;
  18. acl_t acl;
  19. } NETWORK;
  20. typedef struct {
  21. rlim_t rlim_cur; /* Soft limit */
  22. rlim_t rlim_max; /* Hard limit (ceiling for rlim_cur) */
  23. } RLIMIT;
  24. typedef struct {
  25. int fno;
  26. char *chan;
  27. char *IP;
  28. char *agent;
  29. unsigned long clientid; //from the web
  30. time_t expire; //end of the validity of the signature
  31. time_t start;
  32. time_t ts; //timestamp for staled connections
  33. unsigned pos;
  34. unsigned long long traffic_out; // How much traffic has been send to this client
  35. uint32_t ip; // Client ip
  36. acl_t acl; //ACL for the IP from netconf
  37. uint32_t start_pts; //client started on this global pts
  38. uint16_t client_port; //the udp port that client is listening to
  39. int
  40. smart_client:1, // The client has it's own reconnect logic and will be disconnected on channel reconnect (child servers)
  41. is_child_server:1, // The client is really a child server (have iptvd user agent)
  42. headers_sent:1, // headers have been sent
  43. logged:1, //connection is logged
  44. data_send:1, //The client has received at least one data packets
  45. dienow:1, //When this is set the client must be disconnected immedietly
  46. stopping:1; //The client is being stopped. This flag prevents double client_stop entry
  47. char netmsg[48];
  48. } CLIENT;
  49. typedef struct {
  50. channel_source sproto;
  51. char *proto;
  52. char *host;
  53. char *path;
  54. unsigned int port;
  55. } CHANSRC;
  56. #define MAX_CHANNEL_SOURCES 8
  57. typedef struct {
  58. char *name;
  59. char *source; /* Full source url */
  60. char *sources[MAX_CHANNEL_SOURCES];
  61. uint8_t num_src;
  62. uint8_t curr_src;
  63. } CHANNEL;
  64. typedef struct {
  65. char *name;
  66. QUEUE *queue; /* Waiting clients */
  67. LIST *clients; /* List of clients connected to this restreamer */
  68. CHANNEL *channel;
  69. int sock;
  70. struct sockaddr_in sockname;
  71. int reconnect; /* Set to 1 to force proxy reconnect */
  72. int connected; /* It's set to 1 when proxy is connected and serving clients */
  73. int dienow; /* Stop serving clients and exit now */
  74. int freechannel; /* Free channel data on object free (this is used in chanconf) */
  75. time_t started;
  76. int cookie; /* Used in chanconf to determine if the restreamer is alrady checked */
  77. unsigned long connects; /* How many times the proxy has connected successfully to parent */
  78. unsigned long served; /* How much clients has been served by this proxy */
  79. unsigned long long traffic_in;
  80. unsigned long long traffic_out;
  81. } RESTREAMER;
  82. typedef struct {
  83. unsigned long clients; /* Number of clients requested channel and stay connected at least 3 seconds */
  84. unsigned long child_servers; /* Number of child servers */
  85. unsigned long clients_all; /* Number of clients + child servers + clients not watched at least 3 seconds */
  86. unsigned long clients_current; /* Number of current clients */
  87. unsigned long clients_gone; /* Number of stoped clients since last "readinfo" command was issued */
  88. unsigned long errors; /* Number of error videos served */
  89. unsigned long long traffic_in; /* How much traffic was downloaded from parent server */
  90. unsigned long long traffic_out; /* How much traffic was served to clients and sub restreamers */
  91. time_t start_ts; /* When the server was started */
  92. struct utsname utsdata;
  93. } STATS;
  94. typedef struct {
  95. int client;
  96. int file;
  97. char *msg;
  98. char *content_type;
  99. } ERRMSG;
  100. channel_source get_sproto(char *url);
  101. CHANSRC *init_chansrc(char *url);
  102. void free_chansrc(CHANSRC *url);
  103. int is_valid_url(char *url);
  104. void add_channel_source(CHANNEL *c, char *src);
  105. void next_channel_source(CHANNEL *c);
  106. void set_channel_source(CHANNEL *c, uint8_t src_id);
  107. CHANNEL * new_channel(char *id, char *source);
  108. void free_channel(CHANNEL *c);
  109. int channel_search(LIST *channels_list, char *name, CHANNEL **found_channel);
  110. NETWORK * new_network(uint32_t net, uint32_t mask, acl_t acl);
  111. void free_network(NETWORK *n);
  112. int acl_search(LIST *acl_list, uint32_t search_ip, acl_t *found_acl);
  113. RESTREAMER * new_restreamer(const char *name, CHANNEL *channel);
  114. void free_restreamer(RESTREAMER *r);
  115. void restreamer_stop_all (LIST *proxys);
  116. int restreamer_stop (LIST *proxys, char *channel);
  117. int restreamer_reconnect (LIST *proxys, char *channel);
  118. int is_ext(char *path, char *ext);
  119. CLIENT * new_client(int fd, time_t expire, char *chan, char *IP, char *agent, unsigned long clientid, acl_t acl, uint16_t client_port, int smart_client);
  120. void free_client(CLIENT *c);
  121. void stop_client(CLIENT *c, int socket_shutdown, char mark);
  122. void stop_client_noshutdown(CLIENT *c);
  123. void stop_client_shutdown_mark(CLIENT *c, char mark);
  124. void stop_client_shutdown(CLIENT *c);
  125. void client_log_connect(CLIENT *c);
  126. int control_client_stop(long clientid);
  127. int control_client_extend(unsigned long clientid, char *chan, time_t expire);
  128. int netmsg_send(long client_id, char *channel, char *netmsg);
  129. char *get_netmsg_packet(const char *msg);
  130. int is_netmsg_packet(const unsigned char *buf, int bufsize);
  131. #endif