Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
HTTP API: respond with uuid for create requests
  • Loading branch information
perexg committed Dec 5, 2016
1 parent 17b16b0 commit 69503a3
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 23 deletions.
8 changes: 7 additions & 1 deletion src/api.h
Expand Up @@ -25,7 +25,7 @@
#include "redblack.h"
#include "access.h"

#define TVH_API_VERSION 18
#define TVH_API_VERSION 19

/*
* Command hook
Expand Down Expand Up @@ -123,6 +123,12 @@ int api_idnode_load_simple
int api_idnode_save_simple
( access_t *perm, void *opaque, const char *op, htsmsg_t *args, htsmsg_t **resp );

void api_idnode_create
( htsmsg_t **resp, idnode_t *in );

void api_idnode_create_list
( htsmsg_t **resp, htsmsg_t *list );

/*
* Service mapper
*/
Expand Down
6 changes: 3 additions & 3 deletions src/api/api_access.c
Expand Up @@ -47,7 +47,7 @@ api_passwd_entry_create

pthread_mutex_lock(&global_lock);
if ((pw = passwd_entry_create(NULL, conf)) != NULL)
idnode_changed(&pw->pw_id);
api_idnode_create(resp, &pw->pw_id);
pthread_mutex_unlock(&global_lock);

return 0;
Expand Down Expand Up @@ -79,7 +79,7 @@ api_ipblock_entry_create

pthread_mutex_lock(&global_lock);
if ((ib = ipblock_entry_create(NULL, conf)) != NULL)
idnode_changed(&ib->ib_id);
api_idnode_create(resp, &ib->ib_id);
pthread_mutex_unlock(&global_lock);

return 0;
Expand Down Expand Up @@ -151,7 +151,7 @@ api_access_entry_create

pthread_mutex_lock(&global_lock);
if ((ae = access_entry_create(NULL, conf)) != NULL)
idnode_changed(&ae->ae_id);
api_idnode_create(resp, &ae->ae_id);
pthread_mutex_unlock(&global_lock);

return 0;
Expand Down
2 changes: 1 addition & 1 deletion src/api/api_bouquet.c
Expand Up @@ -71,7 +71,7 @@ api_bouquet_create
pthread_mutex_lock(&global_lock);
bq = bouquet_create(NULL, conf, NULL, NULL);
if (bq)
idnode_changed(&bq->bq_id);
api_idnode_create(resp, &bq->bq_id);
pthread_mutex_unlock(&global_lock);

return 0;
Expand Down
6 changes: 5 additions & 1 deletion src/api/api_caclient.c
Expand Up @@ -76,6 +76,7 @@ api_caclient_create
int err = 0;
const char *clazz;
htsmsg_t *conf;
caclient_t *cac;

if (!(clazz = htsmsg_get_str(args, "class")))
return EINVAL;
Expand All @@ -84,7 +85,10 @@ api_caclient_create
htsmsg_set_str(conf, "class", clazz);

pthread_mutex_lock(&global_lock);
if (caclient_create(NULL, conf, 1) == NULL)
cac = caclient_create(NULL, conf, 1);
if (cac)
api_idnode_create(resp, &cac->cac_id);
else
err = -EINVAL;
pthread_mutex_unlock(&global_lock);

Expand Down
4 changes: 2 additions & 2 deletions src/api/api_channel.c
Expand Up @@ -87,7 +87,7 @@ api_channel_create
pthread_mutex_lock(&global_lock);
ch = channel_create(NULL, conf, NULL);
if (ch)
idnode_changed(&ch->ch_id);
api_idnode_create(resp, &ch->ch_id);
pthread_mutex_unlock(&global_lock);

return 0;
Expand Down Expand Up @@ -145,7 +145,7 @@ api_channel_tag_create
pthread_mutex_lock(&global_lock);
ct = channel_tag_create(NULL, conf);
if (ct)
idnode_changed(&ct->ct_id);
api_idnode_create(resp, &ct->ct_id);
pthread_mutex_unlock(&global_lock);

return 0;
Expand Down
28 changes: 20 additions & 8 deletions src/api/api_dvr.c
Expand Up @@ -57,7 +57,7 @@ api_dvr_config_create

pthread_mutex_lock(&global_lock);
if ((cfg = dvr_config_create(NULL, NULL, conf))) {
idnode_changed(&cfg->dvr_id);
api_idnode_create(resp, &cfg->dvr_id);
dvr_config_changed(cfg);
}
pthread_mutex_unlock(&global_lock);
Expand Down Expand Up @@ -164,7 +164,7 @@ api_dvr_entry_create
htsmsg_add_msg(conf, "subtitle", m);
}
if ((de = dvr_entry_create(NULL, conf, 0)))
idnode_changed(&de->de_id);
api_idnode_create(resp, &de->de_id);

res = 0;
free(lang);
Expand Down Expand Up @@ -202,7 +202,7 @@ api_dvr_entry_create_by_event
dvr_entry_t *de;
const char *config_uuid, *comment;
epg_broadcast_t *e;
htsmsg_t *entries, *entries2 = NULL, *m;
htsmsg_t *entries, *entries2 = NULL, *m, *l = NULL;
htsmsg_field_t *f;
const char *s;
int count = 0, enabled;
Expand Down Expand Up @@ -235,8 +235,12 @@ api_dvr_entry_create_by_event
perm->aa_representative,
NULL, DVR_PRIO_NORMAL, DVR_RET_REM_DVRCONFIG,
DVR_RET_REM_DVRCONFIG, comment);
if (de)
if (de) {
if (l == NULL)
l = htsmsg_create_list();
htsmsg_add_str(l, NULL, idnode_uuid_as_str(&de->de_id, ubuf));
idnode_changed(&de->de_id);
}
}
}
pthread_mutex_unlock(&global_lock);
Expand All @@ -245,6 +249,8 @@ api_dvr_entry_create_by_event

htsmsg_destroy(entries2);

api_idnode_create_list(resp, l);

return !count ? EINVAL : 0;
}

Expand Down Expand Up @@ -390,7 +396,7 @@ api_dvr_autorec_create
htsmsg_set_str(conf, "config_name", idnode_uuid_as_str(&cfg->dvr_id, ubuf));
dae = dvr_autorec_create(NULL, conf);
if (dae) {
idnode_changed(&dae->dae_id);
api_idnode_create(dae, &dae->dae_id);
dvr_autorec_changed(dae, 0);
dvr_autorec_completed(dae, 0);
}
Expand All @@ -406,7 +412,7 @@ api_dvr_autorec_create_by_series
{
dvr_autorec_entry_t *dae;
epg_broadcast_t *e;
htsmsg_t *entries, *entries2 = NULL, *m;
htsmsg_t *entries, *entries2 = NULL, *m, *l = NULL;
htsmsg_field_t *f;
const char *config_uuid, *s;
int count = 0;
Expand Down Expand Up @@ -435,8 +441,12 @@ api_dvr_autorec_create_by_series
perm->aa_username,
perm->aa_representative,
"Created from EPG query");
if (dae)
if (dae) {
if (l == NULL)
l = htsmsg_create_list();
htsmsg_add_str(l, NULL, idnode_uuid_as_str(&dae->dae_id, ubuf));
idnode_changed(&dae->dae_id);
}
}
}
pthread_mutex_unlock(&global_lock);
Expand All @@ -445,6 +455,8 @@ api_dvr_autorec_create_by_series

htsmsg_destroy(entries2);

api_idnode_create_list(resp, l);

return !count ? EINVAL : 0;
}

Expand Down Expand Up @@ -474,7 +486,7 @@ api_dvr_timerec_create
pthread_mutex_lock(&global_lock);
dte = dvr_timerec_create(NULL, conf);
if (dte) {
idnode_changed(&dte->dte_id);
api_idnode_create(resp, &dte->dte_id);
dvr_timerec_check(dte);
}
pthread_mutex_unlock(&global_lock);
Expand Down
5 changes: 4 additions & 1 deletion src/api/api_esfilter.c
Expand Up @@ -39,12 +39,15 @@ api_esfilter_create
esfilter_class_t cls )
{
htsmsg_t *conf;
esfilter_t *esf;

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

pthread_mutex_lock(&global_lock);
esfilter_create(cls, NULL, conf, 1);
esf = esfilter_create(cls, NULL, conf, 1);
if (esf)
api_idnode_create(resp, &esf->esf_id);
pthread_mutex_unlock(&global_lock);

return 0;
Expand Down
21 changes: 21 additions & 0 deletions src/api/api_idnode.c
Expand Up @@ -720,6 +720,27 @@ api_idnode_movedown
return api_idnode_handler(perm, args, resp, api_idnode_movedown_, "movedown", 0);
}

static void
api_idnode_create( htsmsg_t **resp, idnode_t *in )
{
char ubuf[UUID_HEX_SIZE];

idnode_changed(in);
if (*resp == NULL)
*resp = htsmsg_create_map();
htsmsg_add_str(*resp, "uuid", idnode_uuid_as_str(in, ubuf));
}

static void
api_idnode_create_list( htsmsg_t **resp, htsmsg_t *list )
{
if (list == NULL)
return;
if (*resp == NULL)
*resp = htsmsg_create_map();
htsmsg_add_str(*resp, "uuid", list);
}

void api_idnode_init ( void )
{
/*
Expand Down
8 changes: 3 additions & 5 deletions src/api/api_mpegts.c
Expand Up @@ -122,8 +122,7 @@ api_mpegts_network_create
mn = mpegts_network_build(class, conf);
if (mn) {
err = 0;
*resp = htsmsg_create_map();
idnode_changed(&mn->mn_id);
api_idnode_create(resp, &mn->mn_id);
} else {
err = EINVAL;
}
Expand Down Expand Up @@ -218,7 +217,7 @@ api_mpegts_network_muxcreate
if (!(mm = mn->mn_mux_create2(mn, conf)))
goto exit;

idnode_changed(&mm->mm_id);
api_idnode_create(resp, &mm->mm_id);
err = 0;

exit:
Expand Down Expand Up @@ -311,8 +310,7 @@ api_mpegts_mux_sched_create
mms = mpegts_mux_sched_create(NULL, conf);
if (mms) {
err = 0;
*resp = htsmsg_create_map();
idnode_changed(&mms->mms_id);
api_idnode_create(resp, &mms->mms_id);
} else {
err = EINVAL;
}
Expand Down
6 changes: 5 additions & 1 deletion src/api/api_profile.c
Expand Up @@ -108,6 +108,7 @@ api_profile_create
int err = 0;
const char *clazz;
htsmsg_t *conf;
profile_t *pro;

if (!(clazz = htsmsg_get_str(args, "class")))
return EINVAL;
Expand All @@ -116,7 +117,10 @@ api_profile_create
htsmsg_set_str(conf, "class", clazz);

pthread_mutex_lock(&global_lock);
if (profile_create(NULL, conf, 1) == NULL)
pro = profile_create(NULL, conf, 1);
if (pro)
api_idnode_create(resp, &pro->pro_id);
else
err = -EINVAL;
pthread_mutex_unlock(&global_lock);

Expand Down

0 comments on commit 69503a3

Please sign in to comment.