]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
HTTP API: respond with uuid for create requests
authorJaroslav Kysela <perex@perex.cz>
Mon, 5 Dec 2016 12:53:21 +0000 (13:53 +0100)
committerJaroslav Kysela <perex@perex.cz>
Mon, 5 Dec 2016 12:53:21 +0000 (13:53 +0100)
src/api.h
src/api/api_access.c
src/api/api_bouquet.c
src/api/api_caclient.c
src/api/api_channel.c
src/api/api_dvr.c
src/api/api_esfilter.c
src/api/api_idnode.c
src/api/api_mpegts.c
src/api/api_profile.c

index d0d8eeea4682e3efe6969ee9ebff2d279d69322e..2a56bf356702f4ae9c0b3a9e6f7175354e7e2b71 100644 (file)
--- 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
  */
index a7b2e30214f050283adcdde3b4677a267d9bf08a..ee5fb56285cc36767de10cdef1c0a53ef0596133 100644 (file)
@@ -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;
index 7a5c4acb24a0a12bcf2858ccb3e77878e695fbfc..4f6a2a7db951c213592db4de2cf0ecad0bf94853 100644 (file)
@@ -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;
index 4b217da7e23388c0e0e567f5b612acbae4e25ecb..49b1470da3c038b4f146cdb6d9ef58f50e523b9d 100644 (file)
@@ -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);
 
index 0530ec1be07eea66564abf8681fd9d1eefb623ea..af89e2de59c3df061bd5d3efa007645f489b6bfd 100644 (file)
@@ -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;
index 315682437abafd3a18431074d3972ec31c745f03..458668d3c2b4776235ab6f6950c0d261721c8c4d 100644 (file)
@@ -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);
index ca8a7b4dc4c6306ed4f1965247ae8fb20e7fa025..7b4d526bd7afa80ac92916056cb728ee9a516ead 100644 (file)
@@ -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;
index d614ce549145fde2a448332d112d97862fffe71b..4e42e2c44da092a6edbae4ccee9d44a32a75ddf0 100644 (file)
@@ -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 )
 {
   /*
index 8d2ee15ba50197873c99a9ad237ac0d6866ac825..6e3241f50248ff5245e9068c0b21aa81dfbe339a 100644 (file)
@@ -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;
   }
index 68edeb18965fa4bbbb4688cb030319607b134452..5b296beb953aada3e36a349b004497c1e4705251 100644 (file)
@@ -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);