From: Jaroslav Kysela Date: Mon, 5 Dec 2016 12:53:21 +0000 (+0100) Subject: HTTP API: respond with uuid for create requests X-Git-Tag: v4.2.1~194 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=69503a30a58626b39ecadd8fb0a0eca2e96d1802;p=thirdparty%2Ftvheadend.git HTTP API: respond with uuid for create requests --- diff --git a/src/api.h b/src/api.h index d0d8eeea4..2a56bf356 100644 --- a/src/api.h +++ b/src/api.h @@ -25,7 +25,7 @@ #include "redblack.h" #include "access.h" -#define TVH_API_VERSION 18 +#define TVH_API_VERSION 19 /* * Command hook @@ -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 */ diff --git a/src/api/api_access.c b/src/api/api_access.c index a7b2e3021..ee5fb5628 100644 --- a/src/api/api_access.c +++ b/src/api/api_access.c @@ -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; @@ -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; @@ -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; diff --git a/src/api/api_bouquet.c b/src/api/api_bouquet.c index 7a5c4acb2..4f6a2a7db 100644 --- a/src/api/api_bouquet.c +++ b/src/api/api_bouquet.c @@ -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; diff --git a/src/api/api_caclient.c b/src/api/api_caclient.c index 4b217da7e..49b1470da 100644 --- a/src/api/api_caclient.c +++ b/src/api/api_caclient.c @@ -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; @@ -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); diff --git a/src/api/api_channel.c b/src/api/api_channel.c index 0530ec1be..af89e2de5 100644 --- a/src/api/api_channel.c +++ b/src/api/api_channel.c @@ -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; @@ -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; diff --git a/src/api/api_dvr.c b/src/api/api_dvr.c index 315682437..458668d3c 100644 --- a/src/api/api_dvr.c +++ b/src/api/api_dvr.c @@ -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); @@ -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); @@ -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; @@ -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); @@ -245,6 +249,8 @@ api_dvr_entry_create_by_event htsmsg_destroy(entries2); + api_idnode_create_list(resp, l); + return !count ? EINVAL : 0; } @@ -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); } @@ -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; @@ -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); @@ -445,6 +455,8 @@ api_dvr_autorec_create_by_series htsmsg_destroy(entries2); + api_idnode_create_list(resp, l); + return !count ? EINVAL : 0; } @@ -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); diff --git a/src/api/api_esfilter.c b/src/api/api_esfilter.c index ca8a7b4dc..7b4d526bd 100644 --- a/src/api/api_esfilter.c +++ b/src/api/api_esfilter.c @@ -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; diff --git a/src/api/api_idnode.c b/src/api/api_idnode.c index d614ce549..4e42e2c44 100644 --- a/src/api/api_idnode.c +++ b/src/api/api_idnode.c @@ -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 ) { /* diff --git a/src/api/api_mpegts.c b/src/api/api_mpegts.c index 8d2ee15ba..6e3241f50 100644 --- a/src/api/api_mpegts.c +++ b/src/api/api_mpegts.c @@ -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; } @@ -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: @@ -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; } diff --git a/src/api/api_profile.c b/src/api/api_profile.c index 68edeb189..5b296beb9 100644 --- a/src/api/api_profile.c +++ b/src/api/api_profile.c @@ -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; @@ -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);