Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
dvr: rewrite to use the idnode system
  • Loading branch information
perexg committed Sep 8, 2014
1 parent ca742e0 commit 2208332
Show file tree
Hide file tree
Showing 47 changed files with 4,923 additions and 3,543 deletions.
3 changes: 2 additions & 1 deletion Makefile
Expand Up @@ -156,7 +156,8 @@ SRCS += \
src/api/api_imagecache.c \
src/api/api_esfilter.c \
src/api/api_intlconv.c \
src/api/api_access.c
src/api/api_access.c \
src/api/api_dvr.c

SRCS += \
src/parsers/parsers.c \
Expand Down
13 changes: 12 additions & 1 deletion src/access.c
Expand Up @@ -37,6 +37,7 @@
#include "access.h"
#include "settings.h"
#include "channels.h"
#include "tcp.h"

struct access_entry_queue access_entries;
struct access_ticket_queue access_tickets;
Expand Down Expand Up @@ -158,6 +159,8 @@ access_ticket_verify(const char *id, const char *resource)
void
access_destroy(access_t *a)
{
free(a->aa_username);
free(a->aa_representative);
htsmsg_destroy(a->aa_chtags);
free(a);
}
Expand Down Expand Up @@ -310,6 +313,14 @@ access_get(const char *username, const char *password, struct sockaddr *src)
access_t *a = calloc(1, sizeof(*a));
access_entry_t *ae;

if (username) {
a->aa_username = strdup(username);
a->aa_representative = strdup(username);
} else {
a->aa_representative = malloc(50);
tcp_get_ip_str((struct sockaddr*)src, a->aa_representative, 50);
}

if (access_noacl) {
a->aa_rights = ACCESS_FULL;
return a;
Expand Down Expand Up @@ -645,7 +656,7 @@ access_entry_destroy(access_entry_t *ae)
/**
*
*/
static void
void
access_entry_save(access_entry_t *ae)
{
htsmsg_t *c = htsmsg_create_map();
Expand Down
11 changes: 11 additions & 0 deletions src/access.h
Expand Up @@ -82,6 +82,8 @@ typedef struct access_ticket {
} access_ticket_t;

typedef struct access {
char *aa_username;
char *aa_representative;
uint32_t aa_rights;
uint32_t aa_chmin;
uint32_t aa_chmax;
Expand Down Expand Up @@ -129,6 +131,9 @@ void access_destroy(access_t *a);
int access_verify(const char *username, const char *password,
struct sockaddr *src, uint32_t mask);

static inline int access_verify2(access_t *a, uint32_t mask)
{ return (a->aa_rights & mask) == mask ? 0 : -1; }

/**
* Get the access structure
*/
Expand All @@ -154,6 +159,12 @@ access_get_by_addr(struct sockaddr *src);
access_entry_t *
access_entry_create(const char *uuid, htsmsg_t *conf);

/**
*
*/
void
access_entry_save(access_entry_t *ae);

/**
*
*/
Expand Down
8 changes: 5 additions & 3 deletions src/api.c
Expand Up @@ -61,7 +61,8 @@ api_register_all ( const api_hook_t *hooks )
}

int
api_exec ( const char *subsystem, htsmsg_t *args, htsmsg_t **resp )
api_exec ( access_t *perm, const char *subsystem,
htsmsg_t *args, htsmsg_t **resp )
{
api_hook_t h;
api_link_t *ah, skel;
Expand Down Expand Up @@ -90,12 +91,12 @@ api_exec ( const char *subsystem, htsmsg_t *args, htsmsg_t **resp )
// Note: this is not required (so no final validation)

/* Execute */
return ah->hook->ah_callback(ah->hook->ah_opaque, op, args, resp);
return ah->hook->ah_callback(perm, ah->hook->ah_opaque, op, args, resp);
}

static int
api_serverinfo
( void *opaque, const char *op, htsmsg_t *args, htsmsg_t **resp )
( access_t *perm, void *opaque, const char *op, htsmsg_t *args, htsmsg_t **resp )
{
*resp = htsmsg_create_map();
htsmsg_add_str(*resp, "sw_version", tvheadend_version);
Expand Down Expand Up @@ -128,6 +129,7 @@ void api_init ( void )
api_esfilter_init();
api_intlconv_init();
api_access_init();
api_dvr_init();
}

void api_done ( void )
Expand Down
25 changes: 16 additions & 9 deletions src/api.h
Expand Up @@ -23,15 +23,17 @@
#include "htsmsg.h"
#include "idnode.h"
#include "redblack.h"
#include "access.h"

#define TVH_API_VERSION 12
#define TVH_API_VERSION 14

/*
* Command hook
*/

typedef int (*api_callback_t)
( void *opaque, const char *op, htsmsg_t *args, htsmsg_t **resp );
( access_t *perm, void *opaque, const char *op,
htsmsg_t *args, htsmsg_t **resp );

typedef struct api_hook
{
Expand All @@ -50,7 +52,8 @@ void api_register_all ( const api_hook_t *hooks );
/*
* Execute
*/
int api_exec ( const char *subsystem, htsmsg_t *args, htsmsg_t **resp );
int api_exec ( access_t *perm, const char *subsystem,
htsmsg_t *args, htsmsg_t **resp );

/*
* Initialise
Expand All @@ -70,6 +73,7 @@ void api_imagecache_init ( void );
void api_esfilter_init ( void );
void api_intlconv_init ( void );
void api_access_init ( void );
void api_dvr_init ( void );

/*
* IDnode
Expand All @@ -84,21 +88,24 @@ typedef struct api_idnode_grid_conf
} api_idnode_grid_conf_t;

typedef void (*api_idnode_grid_callback_t)
(idnode_set_t*, api_idnode_grid_conf_t*, htsmsg_t *args);
(access_t *perm, idnode_set_t*, api_idnode_grid_conf_t*, htsmsg_t *args);
typedef idnode_set_t *(*api_idnode_tree_callback_t)
(void);
(access_t *perm);

int api_idnode_grid
( void *opaque, const char *op, htsmsg_t *args, htsmsg_t **resp );
( access_t *perm, void *opaque, const char *op, htsmsg_t *args, htsmsg_t **resp );

int api_idnode_class
( void *opaque, const char *op, htsmsg_t *args, htsmsg_t **resp );
( access_t *perm, void *opaque, const char *op, htsmsg_t *args, htsmsg_t **resp );

int api_idnode_tree
( void *opaque, const char *op, htsmsg_t *args, htsmsg_t **resp );
( access_t *perm, void *opaque, const char *op, htsmsg_t *args, htsmsg_t **resp );

int api_idnode_load_by_class
( void *opaque, const char *op, htsmsg_t *args, htsmsg_t **resp );
( access_t *perm, void *opaque, const char *op, htsmsg_t *args, htsmsg_t **resp );

int api_idnode_handler
( access_t *perm, htsmsg_t *args, htsmsg_t **resp, void (*handler)(access_t *perm, idnode_t *in) );

/*
* Service mapper
Expand Down
8 changes: 5 additions & 3 deletions src/api/api_access.c
Expand Up @@ -23,7 +23,7 @@

static void
api_access_entry_grid
( idnode_set_t *ins, api_idnode_grid_conf_t *conf, htsmsg_t *args )
( access_t *perm, idnode_set_t *ins, api_idnode_grid_conf_t *conf, htsmsg_t *args )
{
access_entry_t *ae;

Expand All @@ -33,15 +33,17 @@ api_access_entry_grid

static int
api_access_entry_create
( void *opaque, const char *op, htsmsg_t *args, htsmsg_t **resp )
( access_t *perm, void *opaque, const char *op, htsmsg_t *args, htsmsg_t **resp )
{
htsmsg_t *conf;
access_entry_t *ae;

if (!(conf = htsmsg_get_map(args, "conf")))
return EINVAL;

pthread_mutex_lock(&global_lock);
access_entry_create(NULL, conf);
if ((ae = access_entry_create(NULL, conf)) != NULL)
access_entry_save(ae);
pthread_mutex_unlock(&global_lock);

return 0;
Expand Down
12 changes: 6 additions & 6 deletions src/api/api_channel.c
Expand Up @@ -28,7 +28,7 @@
// TODO: this will need converting to an idnode system
static int
api_channel_list
( void *opaque, const char *op, htsmsg_t *args, htsmsg_t **resp )
( access_t *perm, void *opaque, const char *op, htsmsg_t *args, htsmsg_t **resp )
{
channel_t *ch;
htsmsg_t *l, *e;
Expand All @@ -50,7 +50,7 @@ api_channel_list

static void
api_channel_grid
( idnode_set_t *ins, api_idnode_grid_conf_t *conf )
( access_t *perm, idnode_set_t *ins, api_idnode_grid_conf_t *conf )
{
channel_t *ch;

Expand All @@ -60,7 +60,7 @@ api_channel_grid

static int
api_channel_create
( void *opaque, const char *op, htsmsg_t *args, htsmsg_t **resp )
( access_t *perm, void *opaque, const char *op, htsmsg_t *args, htsmsg_t **resp )
{
htsmsg_t *conf;
channel_t *ch;
Expand All @@ -79,7 +79,7 @@ api_channel_create

static int
api_channel_tag_list
( void *opaque, const char *op, htsmsg_t *args, htsmsg_t **resp )
( access_t *perm, void *opaque, const char *op, htsmsg_t *args, htsmsg_t **resp )
{
channel_tag_t *ct;
htsmsg_t *l, *e;
Expand All @@ -98,7 +98,7 @@ api_channel_tag_list

static void
api_channel_tag_grid
( idnode_set_t *ins, api_idnode_grid_conf_t *conf )
( access_t *perm, idnode_set_t *ins, api_idnode_grid_conf_t *conf )
{
channel_tag_t *ct;

Expand All @@ -108,7 +108,7 @@ api_channel_tag_grid

static int
api_channel_tag_create
( void *opaque, const char *op, htsmsg_t *args, htsmsg_t **resp )
( access_t *perm, void *opaque, const char *op, htsmsg_t *args, htsmsg_t **resp )
{
htsmsg_t *conf;
channel_tag_t *ct;
Expand Down

0 comments on commit 2208332

Please sign in to comment.