#define ACCESS_ADVANCED_STREAMING (1<<1)
#define ACCESS_HTSP_STREAMING (1<<2)
#define ACCESS_WEB_INTERFACE (1<<3)
-#define ACCESS_RECORDER (1<<4)
-#define ACCESS_HTSP_RECORDER (1<<5)
-#define ACCESS_ALL_RECORDER (1<<6)
-#define ACCESS_ALL_RW_RECORDER (1<<7)
-#define ACCESS_FAILED_RECORDER (1<<8)
-#define ACCESS_ADMIN (1<<9)
+#define ACCESS_HTSP_INTERFACE (1<<4)
+#define ACCESS_RECORDER (1<<5)
+#define ACCESS_HTSP_RECORDER (1<<6)
+#define ACCESS_ALL_RECORDER (1<<7)
+#define ACCESS_ALL_RW_RECORDER (1<<8)
+#define ACCESS_FAILED_RECORDER (1<<9)
+#define ACCESS_ADMIN (1<<10)
#define ACCESS_OR (1<<30)
#define ACCESS_FULL \
api_config_init ( void )
{
static api_hook_t ah[] = {
- { "config/capabilities", ACCESS_WEB_INTERFACE, api_config_capabilities, NULL },
+ { "config/capabilities", ACCESS_OR|ACCESS_WEB_INTERFACE|ACCESS_HTSP_INTERFACE, api_config_capabilities, NULL },
{ "config/load", ACCESS_ADMIN, api_idnode_load_simple, &config },
{ "config/save", ACCESS_ADMIN, api_idnode_save_simple, &config },
{ "tvhlog/config/load", ACCESS_ADMIN, api_idnode_load_simple, &tvhlog_conf },
#include "tvheadend.h"
#include "atomic.h"
#include "config.h"
+#include "api.h"
#include "channels.h"
#include "subscriptions.h"
#include "tcp.h"
/* Capabilities */
htsmsg_add_msg(r, "servercapability", tvheadend_capabilities_list(1));
+ htsmsg_add_u32(r, "api_version", TVH_API_VERSION);
/* Set version to lowest num */
htsp->htsp_version = MIN(HTSP_PROTO_VERSION, v);
return r;
}
+/**
+ * Try to authenticate
+ */
+static htsmsg_t *
+htsp_method_api(htsp_connection_t *htsp, htsmsg_t *in)
+{
+ htsmsg_t *resp = NULL, *ret = htsmsg_create_map();
+ htsmsg_t *args, *args2 = NULL;
+ const char *remain;
+ int r;
+
+ args = htsmsg_get_map(in, "args");
+ remain = htsmsg_get_str(in, "path");
+
+ if (args == NULL)
+ args = args2 = htsmsg_create_map();
+
+ /* Call */
+ r = api_exec(htsp->htsp_granted_access, remain, args, &resp);
+
+ /* Convert error */
+ if (r) {
+ switch (r) {
+ case EPERM:
+ case EACCES:
+ htsmsg_add_u32(ret, "noaccess", 1);
+ break;
+ case ENOENT:
+ case ENOSYS:
+ break;
+ default:
+ htsmsg_destroy(args2);
+ htsmsg_destroy(ret);
+ return htsp_error("Bad request");
+ }
+ } else if (resp) {
+ /* Output response */
+ htsmsg_add_msg(ret, "response", resp);
+ }
+
+ htsmsg_destroy(args2);
+ return ret;
+}
+
/**
* Get total and free disk space on configured path
*/
} htsp_methods[] = {
{ "hello", htsp_method_hello, ACCESS_ANONYMOUS},
{ "authenticate", htsp_method_authenticate, ACCESS_ANONYMOUS},
+ { "api", htsp_method_api, ACCESS_ANONYMOUS},
{ "getDiskSpace", htsp_method_getDiskSpace, ACCESS_HTSP_STREAMING},
{ "getSysTime", htsp_method_getSysTime, ACCESS_HTSP_STREAMING},
{ "enableAsyncMetadata", htsp_method_async, ACCESS_HTSP_STREAMING},
return 0;
}
+ rights->aa_rights |= ACCESS_HTSP_INTERFACE;
privgain = (rights->aa_rights |
htsp->htsp_granted_access->aa_rights) !=
htsp->htsp_granted_access->aa_rights;
htsp->htsp_granted_access =
access_get_by_addr((struct sockaddr *)htsp->htsp_peer);
+ htsp->htsp_granted_access->aa_rights |= ACCESS_HTSP_INTERFACE;
tcp_id = tcp_connection_launch(htsp->htsp_fd, htsp_server_status,
htsp->htsp_granted_access);