/* tsiproxy data functions */ #ifndef DATA_H # define DATA_H #include // for uint32_t #include // for rlim_t #include // for utsdata #include "libfuncs/queue.h" #include "libfuncs/list.h" typedef enum { udp_sock, tcp_sock } channel_source; typedef struct { int stats :1, /* S - STATS | allow access to stats and info server pages /used by data collection tools/ */ reconf:1, /* F - RECONF | allow server reconfiguration request /used for sys admins/ (ex: http://XXX/{chanconf,netconf}) */ access:1; /* A - ACCESS | Allow access from this network (used for bg networks) */ } acl_t; typedef struct { uint32_t net; uint32_t mask; acl_t acl; } NETWORK; typedef struct { rlim_t rlim_cur; /* Soft limit */ rlim_t rlim_max; /* Hard limit (ceiling for rlim_cur) */ } RLIMIT; typedef struct { int fno; char *chan; char *IP; char *agent; unsigned long clientid; //from the web time_t expire; //end of the validity of the signature time_t start; time_t ts; //timestamp for staled connections unsigned pos; unsigned long long traffic_out; // How much traffic has been send to this client uint32_t ip; // Client ip acl_t acl; //ACL for the IP from netconf uint32_t start_pts; //client started on this global pts uint16_t client_port; //the udp port that client is listening to int smart_client:1, // The client has it's own reconnect logic and will be disconnected on channel reconnect (child servers) is_child_server:1, // The client is really a child server (have iptvd user agent) headers_sent:1, // headers have been sent logged:1, //connection is logged data_send:1, //The client has received at least one data packets dienow:1, //When this is set the client must be disconnected immedietly stopping:1; //The client is being stopped. This flag prevents double client_stop entry char netmsg[48]; } CLIENT; typedef struct { channel_source sproto; char *proto; char *host; char *path; unsigned int port; } CHANSRC; #define MAX_CHANNEL_SOURCES 8 typedef struct { char *name; char *source; /* Full source url */ char *sources[MAX_CHANNEL_SOURCES]; uint8_t num_src; uint8_t curr_src; } CHANNEL; typedef struct { char *name; QUEUE *queue; /* Waiting clients */ LIST *clients; /* List of clients connected to this restreamer */ CHANNEL *channel; int sock; struct sockaddr_in sockname; int reconnect; /* Set to 1 to force proxy reconnect */ int connected; /* It's set to 1 when proxy is connected and serving clients */ int dienow; /* Stop serving clients and exit now */ int freechannel; /* Free channel data on object free (this is used in chanconf) */ time_t started; int cookie; /* Used in chanconf to determine if the restreamer is alrady checked */ unsigned long connects; /* How many times the proxy has connected successfully to parent */ unsigned long served; /* How much clients has been served by this proxy */ unsigned long long traffic_in; unsigned long long traffic_out; } RESTREAMER; typedef struct { unsigned long clients; /* Number of clients requested channel and stay connected at least 3 seconds */ unsigned long child_servers; /* Number of child servers */ unsigned long clients_all; /* Number of clients + child servers + clients not watched at least 3 seconds */ unsigned long clients_current; /* Number of current clients */ unsigned long clients_gone; /* Number of stoped clients since last "readinfo" command was issued */ unsigned long errors; /* Number of error videos served */ unsigned long long traffic_in; /* How much traffic was downloaded from parent server */ unsigned long long traffic_out; /* How much traffic was served to clients and sub restreamers */ time_t start_ts; /* When the server was started */ struct utsname utsdata; } STATS; typedef struct { int client; int file; char *msg; char *content_type; } ERRMSG; channel_source get_sproto(char *url); CHANSRC *init_chansrc(char *url); void free_chansrc(CHANSRC *url); int is_valid_url(char *url); void add_channel_source(CHANNEL *c, char *src); void next_channel_source(CHANNEL *c); void set_channel_source(CHANNEL *c, uint8_t src_id); CHANNEL * new_channel(char *id, char *source); void free_channel(CHANNEL *c); int channel_search(LIST *channels_list, char *name, CHANNEL **found_channel); NETWORK * new_network(uint32_t net, uint32_t mask, acl_t acl); void free_network(NETWORK *n); int acl_search(LIST *acl_list, uint32_t search_ip, acl_t *found_acl); RESTREAMER * new_restreamer(const char *name, CHANNEL *channel); void free_restreamer(RESTREAMER *r); void restreamer_stop_all (LIST *proxys); int restreamer_stop (LIST *proxys, char *channel); int restreamer_reconnect (LIST *proxys, char *channel); int is_ext(char *path, char *ext); 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); void free_client(CLIENT *c); void stop_client(CLIENT *c, int socket_shutdown, char mark); void stop_client_noshutdown(CLIENT *c); void stop_client_shutdown_mark(CLIENT *c, char mark); void stop_client_shutdown(CLIENT *c); void client_log_connect(CLIENT *c); int control_client_stop(long clientid); int control_client_extend(unsigned long clientid, char *chan, time_t expire); int netmsg_send(long client_id, char *channel, char *netmsg); char *get_netmsg_packet(const char *msg); int is_netmsg_packet(const unsigned char *buf, int bufsize); #endif