Advertisement
Guest User

Untitled

a guest
Apr 18th, 2016
23
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.43 KB | None | 0 0
  1. diff --git a/src/access.c b/src/access.c
  2. index 5d2930a..656c9dc 100644
  3. --- a/src/access.c
  4. +++ b/src/access.c
  5. @@ -365,7 +365,7 @@ access_dump_a(access_t *a)
  6. int first;
  7.  
  8. tvh_strlcatf(buf, sizeof(buf), l,
  9. - "%s:%s [%c%c%c%c%c%c%c%c%c%c%c], conn=%u:s%u:r%u:l%u%s",
  10. + "%s:%s [%c%c%c%c%c%c%c%c%c%c%c], conn=%u:s%u:r%u:ms%u:mr%u:l%u%s",
  11. a->aa_representative ?: "<no-id>",
  12. a->aa_username ?: "<no-user>",
  13. a->aa_rights & ACCESS_STREAMING ? 'S' : ' ',
  14. @@ -382,6 +382,8 @@ access_dump_a(access_t *a)
  15. a->aa_conn_limit,
  16. a->aa_conn_limit_streaming,
  17. a->aa_conn_limit_dvr,
  18. + a->aa_muxes_limit_streaming,
  19. + a->aa_muxes_limit_dvr,
  20. a->aa_uilevel,
  21. a->aa_match ? ", matched" : "");
  22.  
  23. @@ -488,6 +490,12 @@ access_update(access_t *a, access_entry_t *ae)
  24. break;
  25. }
  26.  
  27. + if (a->aa_muxes_limit_streaming < ae->ae_muxes_limit_streaming)
  28. + a->aa_muxes_limit_streaming = ae->ae_muxes_limit_streaming;
  29. +
  30. + if (a->aa_muxes_limit_dvr < ae->ae_muxes_limit_dvr)
  31. + a->aa_muxes_limit_dvr = ae->ae_muxes_limit_dvr;
  32. +
  33. if(ae->ae_uilevel > a->aa_uilevel)
  34. a->aa_uilevel = ae->ae_uilevel;
  35.  
  36. @@ -1530,6 +1538,24 @@ const idclass_t access_entry_class = {
  37. .opts = PO_EXPERT
  38. },
  39. {
  40. + .type = PT_U32,
  41. + .id = "muxes_limit_streaming",
  42. + .name = N_("Limit muxes for streaming"),
  43. + .desc = N_("The number of streaming muxes this user can "
  44. + "simulteanously use on the server."),
  45. + .off = offsetof(access_entry_t, ae_muxes_limit_streaming),
  46. + .opts = PO_EXPERT
  47. + },
  48. + {
  49. + .type = PT_U32,
  50. + .id = "muxes_limit_dvr",
  51. + .name = N_("Limit muxes for DVR"),
  52. + .desc = N_("The number of DVR muxes this user can "
  53. + "simulteanously use on the server."),
  54. + .off = offsetof(access_entry_t, ae_muxes_limit_dvr),
  55. + .opts = PO_EXPERT
  56. + },
  57. + {
  58. .type = PT_S64,
  59. .intextra = CHANNEL_SPLIT,
  60. .id = "channel_min",
  61. diff --git a/src/access.h b/src/access.h
  62. index 4aabc2a..14b885a 100644
  63. --- a/src/access.h
  64. +++ b/src/access.h
  65. @@ -115,6 +115,9 @@ typedef struct access_entry {
  66. int ae_conn_limit_type;
  67. uint32_t ae_conn_limit;
  68.  
  69. + uint32_t ae_muxes_limit_streaming;
  70. + uint32_t ae_muxes_limit_dvr;
  71. +
  72. int ae_dvr;
  73. int ae_htsp_dvr;
  74. int ae_all_dvr;
  75. @@ -158,6 +161,8 @@ typedef struct access {
  76. uint32_t aa_conn_limit_dvr;
  77. uint32_t aa_conn_streaming;
  78. uint32_t aa_conn_dvr;
  79. + uint32_t aa_muxes_limit_streaming;
  80. + uint32_t aa_muxes_limit_dvr;
  81. int aa_uilevel;
  82. int aa_uilevel_nochange;
  83. char *aa_theme;
  84. diff --git a/src/dvr/dvr_rec.c b/src/dvr/dvr_rec.c
  85. index 881b7b8..574939f 100644
  86. --- a/src/dvr/dvr_rec.c
  87. +++ b/src/dvr/dvr_rec.c
  88. @@ -70,6 +70,7 @@ dvr_rec_subscribe(dvr_entry_t *de)
  89. access_t *aa;
  90. uint32_t rec_count, net_count;
  91. int c1, c2;
  92. + idnode_list_mapping_t* ilm;
  93.  
  94. assert(de->de_s == NULL);
  95. assert(de->de_chain == NULL);
  96. @@ -107,6 +108,30 @@ dvr_rec_subscribe(dvr_entry_t *de)
  97. return -EOVERFLOW;
  98. }
  99. }
  100. +
  101. + if (aa->aa_muxes_limit_dvr)
  102. + {
  103. + ilm = LIST_FIRST(&de->de_channel->ch_services);
  104. + if (ilm)
  105. + {
  106. + service_t* ch_first_service = (service_t* )ilm->ilm_in1;
  107. + if (ch_first_service)
  108. + {
  109. + source_info_t si;
  110. + int count;
  111. + ch_first_service->s_setsourceinfo(ch_first_service, &si);
  112. + count = subscription_get_user_count_on_other_muxes(de->de_creator, si.si_mux_uuid, 1);
  113. + if (count >= aa->aa_muxes_limit_dvr)
  114. + {
  115. + tvherror("htsp", "user [%s] is already using %d muxes for recording while the max is %d", de->de_creator?:"no-user", count, aa->aa_muxes_limit_dvr);
  116. + access_destroy(aa);
  117. + return -EINVAL;
  118. + }
  119. + service_source_info_free(&si);
  120. + }
  121. + }
  122. + }
  123. +
  124. access_destroy(aa);
  125.  
  126. pro = de->de_config->dvr_profile;
  127. diff --git a/src/htsp_server.c b/src/htsp_server.c
  128. index bbad29c..1eaed9f 100644
  129. --- a/src/htsp_server.c
  130. +++ b/src/htsp_server.c
  131. @@ -2333,6 +2333,7 @@ htsp_method_subscribe(htsp_connection_t *htsp, htsmsg_t *in)
  132. channel_t *ch;
  133. htsp_subscription_t *hs;
  134. profile_t *pro;
  135. + idnode_list_mapping_t* ilm;
  136.  
  137. if(htsmsg_get_u32(in, "subscriptionId", &sid))
  138. return htsp_error(htsp, N_("Invalid arguments"));
  139. @@ -2396,6 +2397,29 @@ htsp_method_subscribe(htsp_connection_t *htsp, htsmsg_t *in)
  140. if (pro->pro_prefersd)
  141. convert_channel_to_sd(ch, &ch);
  142.  
  143. + if (htsp->htsp_granted_access && htsp->htsp_granted_access->aa_muxes_limit_streaming)
  144. + {
  145. + ilm = LIST_FIRST(&ch->ch_services);
  146. + if (ilm)
  147. + {
  148. + service_t* ch_first_service = (service_t* )ilm->ilm_in1;
  149. + if (ch_first_service)
  150. + {
  151. + source_info_t si;
  152. + int count;
  153. + ch_first_service->s_setsourceinfo(ch_first_service, &si);
  154. + count = subscription_get_user_count_on_other_muxes(htsp->htsp_username, si.si_mux_uuid, 0);
  155. + if (count >= htsp->htsp_granted_access->aa_muxes_limit_streaming)
  156. + {
  157. + tvherror("htsp", "user [%s] is already using %d muxes for streaming while the max is %d", htsp->htsp_username?:"no-user", count, htsp->htsp_granted_access->aa_muxes_limit_streaming);
  158. + free(hs);
  159. + return htsp_error(htsp, "Stream setup error, reach max allowed muxes for streaming");
  160. + }
  161. + service_source_info_free(&si);
  162. + }
  163. + }
  164. + }
  165. +
  166. profile_chain_init(&hs->hs_prch, pro, ch);
  167. if (profile_chain_work(&hs->hs_prch, &hs->hs_input, timeshiftPeriod, 0)) {
  168. tvhlog(LOG_ERR, "htsp", "unable to create profile chain '%s'", profile_get_name(pro));
  169. diff --git a/src/subscriptions.c b/src/subscriptions.c
  170. index 276cade..76eae6d 100644
  171. --- a/src/subscriptions.c
  172. +++ b/src/subscriptions.c
  173. @@ -1225,3 +1225,31 @@ void subscription_log(th_subscription_t *s, int on)
  174. }
  175. }
  176.  
  177. +int subscription_get_user_count_on_other_muxes(char *username, tvh_uuid_t mux_uuid, int is_dvr)
  178. +{
  179. + th_subscription_t *s;
  180. + int count;
  181. +
  182. + count = 0;
  183. +
  184. + LIST_FOREACH(s, &subscriptions, ths_global_link) {
  185. + if (s->ths_service) {
  186. + source_info_t si;
  187. + s->ths_service->s_setsourceinfo(s->ths_service, &si);
  188. + if (s->ths_username && username && !strcmp(username, s->ths_username) && uuid_cmp(&si.si_mux_uuid, &mux_uuid)) {
  189. + if (is_dvr) {
  190. + if (strstr(s->ths_title, "DVR"))
  191. + count++;
  192. + }
  193. + else {
  194. + if (!strstr(s->ths_title, "DVR"))
  195. + count++;
  196. + }
  197. + }
  198. + service_source_info_free(&si);
  199. + }
  200. + }
  201. +
  202. + return count;
  203. +}
  204. +
  205. diff --git a/src/subscriptions.h b/src/subscriptions.h
  206. index 5fb5ecf..7209ec3 100644
  207. --- a/src/subscriptions.h
  208. +++ b/src/subscriptions.h
  209. @@ -231,4 +231,6 @@ static inline int subscriptions_active(void)
  210. struct htsmsg;
  211. struct htsmsg *subscription_create_msg(th_subscription_t *s, const char *lang);
  212.  
  213. +int subscription_get_user_count_on_other_muxes(char *username, tvh_uuid_t mux_uuid, int is_dvr);
  214. +
  215. #endif /* SUBSCRIPTIONS_H */
  216. diff --git a/src/webui/static/app/acleditor.js b/src/webui/static/app/acleditor.js
  217. index 60757dc..a20946d 100644
  218. --- a/src/webui/static/app/acleditor.js
  219. +++ b/src/webui/static/app/acleditor.js
  220. @@ -7,7 +7,7 @@ tvheadend.acleditor = function(panel, index)
  221. var list = 'enabled,username,password,prefix,' +
  222. 'lang,webui,uilevel,uilevel_nochange,admin,' +
  223. 'streaming,adv_streaming,htsp_streaming,' +
  224. - 'profile,conn_limit_type,conn_limit,' +
  225. + 'profile,conn_limit_type,conn_limit,muxes_limit_streaming,muxes_limit_dvr,' +
  226. 'dvr,htsp_dvr,all_dvr,all_rw_dvr,' +
  227. 'dvr_config,channel_min,channel_max,' +
  228. 'channel_tag_exclude,channel_tag,comment';
  229. @@ -15,7 +15,7 @@ tvheadend.acleditor = function(panel, index)
  230. var list2 = 'enabled,username,password,prefix,' +
  231. 'lang,webui,themeui,langui,uilevel,uilevel_nochange,admin,' +
  232. 'streaming,adv_streaming,htsp_streaming,' +
  233. - 'profile,conn_limit_type,conn_limit,' +
  234. + 'profile,conn_limit_type,conn_limit,muxes_limit_streaming,muxes_limit_dvr,' +
  235. 'dvr,htsp_dvr,all_dvr,all_rw_dvr,' +
  236. 'failed_dvr,htsp_anonymize,dvr_config,' +
  237. 'channel_min,channel_max,channel_tag_exclude,' +
  238. @@ -43,6 +43,8 @@ tvheadend.acleditor = function(panel, index)
  239. admin: { width: 100 },
  240. conn_limit_type:{ width: 160 },
  241. conn_limit: { width: 160 },
  242. + muxes_limit_streaming:{ width: 160 },
  243. + muxes_limit_dvr:{ width: 160 },
  244. channel_min: { width: 160 },
  245. channel_max: { width: 160 }
  246. },
  247. diff --git a/src/webui/webui.c b/src/webui/webui.c
  248. index bca4d92..c70d583 100644
  249. --- a/src/webui/webui.c
  250. +++ b/src/webui/webui.c
  251. @@ -1211,6 +1211,8 @@ http_stream_channel(http_connection_t *hc, channel_t *ch, int weight)
  252. const char *name;
  253. void *tcp_id;
  254. int res = HTTP_STATUS_SERVICE;
  255. + idnode_list_mapping_t* ilm;
  256. + service_t* ch_first_service;
  257.  
  258. if (http_access_verify_channel(hc, ACCESS_STREAMING, ch))
  259. return HTTP_STATUS_UNAUTHORIZED;
  260. @@ -1232,6 +1234,30 @@ http_stream_channel(http_connection_t *hc, channel_t *ch, int weight)
  261. else
  262. qsize = 1500000;
  263.  
  264. + if (hc->hc_access && hc->hc_access->aa_muxes_limit_streaming)
  265. + {
  266. + ilm = LIST_FIRST(&ch->ch_services);
  267. + if (ilm)
  268. + {
  269. + ch_first_service = (service_t* )ilm->ilm_in1;
  270. + if (ch_first_service)
  271. + {
  272. + source_info_t si;
  273. + int count;
  274. + ch_first_service->s_setsourceinfo(ch_first_service, &si);
  275. + count = subscription_get_user_count_on_other_muxes(hc->hc_username?:(hc->hc_access?hc->hc_access->aa_username:NULL), si.si_mux_uuid, 0);
  276. + if (count >= hc->hc_access->aa_muxes_limit_streaming)
  277. + {
  278. + tvherror("webui", "user [%s] is already using %d muxes for streaming while the max is %d",
  279. + hc->hc_username?:(hc->hc_access?hc->hc_access->aa_username:"no-user"), count, hc->hc_access->aa_muxes_limit_streaming);
  280. + http_stream_postop(tcp_id);
  281. + return HTTP_STATUS_UNAUTHORIZED;;
  282. + }
  283. + service_source_info_free(&si);
  284. + }
  285. + }
  286. + }
  287. +
  288. profile_chain_init(&prch, pro, ch);
  289. if (!profile_chain_open(&prch, NULL, 0, qsize)) {
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement