]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
introduce tvh_str_default()
authorJaroslav Kysela <perex@perex.cz>
Mon, 9 Oct 2017 12:56:49 +0000 (14:56 +0200)
committerJaroslav Kysela <perex@perex.cz>
Mon, 9 Oct 2017 12:56:49 +0000 (14:56 +0200)
17 files changed:
src/access.c
src/channels.c
src/config.c
src/dvr/dvr.h
src/dvr/dvr_autorec.c
src/dvr/dvr_config.c
src/dvr/dvr_db.c
src/dvr/dvr_rec.c
src/epggrab/module.c
src/http.c
src/httpc.c
src/input/mpegts/mpegts_network.c
src/profile.c
src/transcoding/codec/codec.c
src/transcoding/transcode/hwaccels/vaapi.c
src/tvheadend.h
src/udp.c

index 06b791ca9fa8ae965e4f99d982a4a1e8721ab398..b29550be6e457b9e5899df504656a0a5ecbe5edc 100644 (file)
@@ -300,10 +300,10 @@ access_get_theme(access_t *a)
 {
   if (a == NULL)
     return "blue";
-  if (a->aa_theme == NULL || a->aa_theme[0] == '\0') {
-    if (config.theme_ui == NULL || config.theme_ui[0] == '\0')
+  if (tvh_str_default(a->aa_theme, NULL) == NULL) {
+    if (tvh_str_default(config.theme_ui, NULL) == NULL)
       return "blue";
-     return config.theme_ui;
+    return config.theme_ui;
   }
   return a->aa_theme;
 }
@@ -685,7 +685,7 @@ access_get(struct sockaddr_storage *src, const char *username, verify_callback_t
 {
   access_t *a = access_alloc();
   access_entry_t *ae;
-  int nouser = username == NULL || username[0] == '\0';
+  int nouser = tvh_str_default(username, NULL) == NULL;
 
   if (!access_noacl && access_ip_blocked(src))
     return a;
index 5d2dc88348a0f622f783aa72b55b0277f79669b4..1c9edf3cb42ec6d9d0bced3a043b2c29f5d5bc53 100644 (file)
@@ -119,7 +119,7 @@ channel_class_autoname_set ( void *obj, const void *p )
   const char *s;
   int b = *(int *)p;
   if (ch->ch_autoname != b) {
-    if (b == 0 && (!ch->ch_name || *ch->ch_name == '\0')) {
+    if (b == 0 && tvh_str_default(ch->ch_name, NULL) == NULL) {
       s = channel_get_name(ch, NULL);
       if (s) {
         free(ch->ch_name);
@@ -811,7 +811,7 @@ channel_get_icon ( channel_t *ch )
   uint32_t id, i, pick, prefer = config.prefer_picon ? 1 : 0;
   char c;
 
-  if (icon && *icon == '\0')
+  if (tvh_str_default(icon, NULL) == NULL)
     icon = NULL;
 
   /*
@@ -1549,7 +1549,7 @@ channel_tag_find_by_name(const char *name, int create)
 {
   channel_tag_t *ct;
 
-  if (name == NULL || *name == '\0')
+  if (tvh_str_default(name, NULL) == NULL)
     return NULL;
 
   TAILQ_FOREACH(ct, &channel_tags, ct_link)
index e932b17af01ce3996c0b6334482a5227287fb669..12423b56f42af941b32ad65c2c74ace2893382d1 100644 (file)
@@ -1752,11 +1752,11 @@ config_boot ( const char *path, gid_t gid, uid_t uid )
 #endif
   }
   htsmsg_destroy(config2);
-  if (config.server_name == NULL || config.server_name[0] == '\0')
+  if (tvh_str_default(config.server_name, NULL) == NULL)
     config.server_name = strdup("Tvheadend");
-  if (config.realm == NULL || config.realm[0] == '\0')
+  if (tvh_str_default(config.realm, NULL) == NULL)
     config.realm = strdup("tvheadend");
-  if (config.http_server_name == NULL || config.http_server_name[0] == '\0')
+  if (tvh_str_default(config.http_server_name, NULL) == NULL)
     config.http_server_name = strdup("HTS/tvheadend");
   if (!config_scanfile_ok)
     config_muxconfpath_notify(&config.idnode, NULL);
@@ -2455,21 +2455,15 @@ const idclass_t config_class = {
 
 const char *config_get_server_name ( void )
 {
-  return config.server_name ?: "Tvheadend";
+  return tvh_str_default(config.server_name, "Tvheadend");
 }
 
 const char *config_get_language ( void )
 {
-  const char *s = config.language;
-  if (s == NULL || *s == '\0')
-    return "eng";
-  return s;
+  return tvh_str_default(config.language, "eng");
 }
 
 const char *config_get_language_ui ( void )
 {
-  const char *s = config.language_ui;
-  if (s == NULL || *s == '\0')
-    return NULL;
-  return s;
+  return tvh_str_default(config.language_ui, NULL);
 }
index 925b023a409f638e6bab7b2a392a9954bea6c8bc..26246e630d800b0891552696f9f8cf9ccc7b38b4 100644 (file)
@@ -448,7 +448,7 @@ static inline int dvr_config_is_valid(dvr_config_t *cfg)
   { return cfg->dvr_valid; }
 
 static inline int dvr_config_is_default(dvr_config_t *cfg)
-  { return cfg->dvr_config_name == NULL || cfg->dvr_config_name[0] == '\0'; }
+  { return tvh_str_default(cfg->dvr_config_name, NULL)  == NULL; }
 
 dvr_config_t *dvr_config_find_by_name(const char *name);
 
index 1eb628d1ea6282a4f388c9243850bf0a95596a51..f729b1114c8a42ccf80494ecd147f3e12732e5d9 100644 (file)
@@ -829,8 +829,7 @@ dvr_autorec_entry_class_brand_set(void *o, const void *v)
   int save;
   epg_brand_t *brand;
 
-  if (v && *(char *)v == '\0')
-    v = NULL;
+  v = tvh_str_default(v, NULL);
   brand = v ? epg_brand_find_by_uri(v, NULL, 1, &save, NULL) : NULL;
   if (brand && dae->dae_brand != brand) {
     if (dae->dae_brand)
@@ -863,8 +862,7 @@ dvr_autorec_entry_class_season_set(void *o, const void *v)
   int save;
   epg_season_t *season;
 
-  if (v && *(char *)v == '\0')
-    v = NULL;
+  v = tvh_str_default(v, NULL);
   season = v ? epg_season_find_by_uri(v, NULL, 1, &save, NULL) : NULL;
   if (season && dae->dae_season != season) {
     if (dae->dae_season)
@@ -897,8 +895,7 @@ dvr_autorec_entry_class_series_link_set(void *o, const void *v)
   int save;
   epg_serieslink_t *sl;
 
-  if (v && *(char *)v == '\0')
-    v = NULL;
+  v = tvh_str_default(v, NULL);
   sl = v ? epg_serieslink_find_by_uri(v, NULL, 1, &save, NULL) : NULL;
   if (sl && dae->dae_serieslink != sl) {
     if (dae->dae_serieslink)
index 4847649ddd295f76d3aa7f76e0423cf7c0e914dd..f673c086a7186e2103eb482398bd0846e8af3343 100644 (file)
@@ -78,13 +78,13 @@ dvr_config_find_by_name_default(const char *name)
     dvrdefaultconfig = cfg;
   }
 
-  if (name == NULL || *name == '\0')
+  if (tvh_str_default(name, NULL) == NULL)
     return dvrdefaultconfig;
 
   cfg = dvr_config_find_by_name(name);
 
   if (cfg == NULL) {
-    if (name && *name)
+    if (tvh_str_default(name, NULL))
       tvhwarn(LS_DVR, "Configuration '%s' not found, using default", name);
     cfg = dvrdefaultconfig;
   } else if (!cfg->dvr_enabled) {
@@ -625,7 +625,7 @@ dvr_config_class_name_set(void *o, const void *v)
   if (dvr_config_is_default(cfg) && dvr_config_is_valid(cfg))
     return 0;
   if (strcmp(cfg->dvr_config_name, v ?: "")) {
-    if (dvr_config_is_valid(cfg) && (v == NULL || *(char *)v == '\0'))
+    if (dvr_config_is_valid(cfg) && tvh_str_default(v, NULL) == NULL)
       return 0;
     free(cfg->dvr_config_name);
     cfg->dvr_config_name = strdup(v ?: "");
index fb25c6cd42afc05eb3885eaea087d19c72262c9d..7d401e0ffe2f4da8042aa5e511c5834dc7e5c4a5 100644 (file)
@@ -2430,11 +2430,11 @@ dvr_entry_class_get_title (idnode_t *self, const char *lang)
   dvr_entry_t *de = (dvr_entry_t *)self;
   const char *s;
   s = lang_str_get(de->de_title, lang);
-  if (s == NULL || s[0] == '\0') {
+  if (tvh_str_default(s, NULL) == NULL) {
     s = lang ? lang_str_get(de->de_title, NULL) : NULL;
-    if (s == NULL || s[0] == '\0') {
+    if (tvh_str_default(s, NULL) == NULL) {
       s = lang ? lang_str_get(de->de_desc, lang) : NULL;
-      if (s == NULL || s[0] == '\0')
+      if (tvh_str_default(s, NULL) == NULL)
         s = lang_str_get(de->de_desc, NULL);
     }
   }
@@ -2929,8 +2929,7 @@ dvr_entry_class_disp_title_set(void *o, const void *v)
   dvr_entry_t *de = (dvr_entry_t *)o;
   const char *lang = idnode_lang(&de->de_id);
   const char *s = "";
-  if (v == NULL || *((char *)v) == '\0')
-    v = "UnknownTitle";
+  v = tvh_str_default(v, "UnknownTitle");
   if (de->de_title)
     s = lang_str_get(de->de_title, lang);
   if (strcmp(s, v)) {
@@ -2959,8 +2958,7 @@ dvr_entry_class_disp_subtitle_set(void *o, const void *v)
   dvr_entry_t *de = (dvr_entry_t *)o;
   const char *lang = idnode_lang(o);
   const char *s = "";
-  if (v == NULL || *((char *)v) == '\0')
-    v = "UnknownSubtitle";
+  v = tvh_str_default(v, "UnknownSubtitle");
   if (de->de_subtitle)
     s = lang_str_get(de->de_subtitle, lang);
   if (strcmp(s, v)) {
index 37e01f0fff7a7a2e25ee1c9e3191dcc5819f4ffc..b120b143ca783d2baff0a0d3c8aaf7bb5ef7bf6e 100644 (file)
@@ -690,7 +690,7 @@ pvr_generate_filename(dvr_entry_t *de, const streaming_start_t *ss)
     return -1;
 
   cfg = de->de_config;
-  if (cfg->dvr_storage == NULL || *(cfg->dvr_storage) == '\0')
+  if (tvh_str_default(cfg->dvr_storage, NULL) == NULL)
     return -1;
 
   dir_dosubs = de->de_directory == NULL ||
@@ -758,7 +758,7 @@ pvr_generate_filename(dvr_entry_t *de, const streaming_start_t *ss)
   filename[j = 0] = '\0';
   while (1) {
     dirsep = dvr_find_next_path_component(x);
-    if (dirsep == NULL || *dirsep == '\0')
+    if (tvh_str_default(dirsep, NULL) == NULL)
       break;
     *(dirsep - 1) = '\0';
     if (*x) {
index af352cb5fd16f131a3e28bb5dae19be3fbf66e95..fc9fa1e3e92c8905c1be38743bddefab25b4b077 100644 (file)
@@ -77,9 +77,7 @@ static const char *epggrab_mod_class_title(idnode_t *self, const char *lang)
 {
   epggrab_module_t *mod = (epggrab_module_t *)self;
   const char *s1 = tvh_gettext_lang(lang, epggrab_module_type(mod));
-  const char *s2 = mod->name;
-  if (s2 == NULL || s2[0] == '\0')
-    s2 = mod->id;
+  const char *s2 = tvh_str_default(mod->name, mod->id);
   snprintf(prop_sbuf, PROP_SBUF_LEN, "%s: %s", s1, s2);
   return prop_sbuf;
 }
index 8040a00c522c93cd522bb4be36192343d5c934f8..eafd3023428f87cb42ea0c9f35eddfe5c9784dc2 100644 (file)
@@ -379,9 +379,7 @@ http_send_header(http_connection_t *hc, int rc, const char *content,
   }
 
   if(rc == HTTP_STATUS_UNAUTHORIZED) {
-    const char *realm = config.realm;
-    if (realm == NULL || realm[0] == '\0')
-      realm = "tvheadend";
+    const char *realm = tvh_str_default(config.realm, "tvheadend");
     if (config.digest) {
       if (hc->hc_nonce == NULL)
         hc->hc_nonce = http_get_nonce();
@@ -1012,7 +1010,7 @@ http_verify_prepare(http_connection_t *hc, struct http_verify_structure *v)
     }
 
     m = md5sum(all, 1);
-    if (qop == NULL || *qop == '\0') {
+    if (tvh_str_default(qop, NULL) == NULL) {
       snprintf(all, sizeof(all), "%s:%s", hc->hc_nonce, m);
       goto set;
     } else {
index 65d6ac79e6be921db0c24e432f80ef0d4df7159f..8427ceeb2589e993ec945da276c8cf8c24d31930 100644 (file)
@@ -619,7 +619,7 @@ error:
   }
   htsbuf_append_str(&q, s);
   htsbuf_append(&q, " ", 1);
-  if (path == NULL || path[0] == '\0')
+  if (tvh_str_default(path, NULL) == NULL)
     path = "/";
   htsbuf_append_str(&q, path);
   if (query && query[0] != '\0') {
@@ -1284,8 +1284,8 @@ http_client_simple_reconnect ( http_client_t *hc, const url_t *u,
 
   lock_assert(&hc->hc_mutex);
 
-  if (u->scheme == NULL || u->scheme[0] == '\0' ||
-      u->host == NULL || u->host[0] == '\0' ||
+  if (tvh_str_default(u->scheme, NULL) == NULL ||
+      tvh_str_default(u->host, NULL) == NULL ||
       u->port < 0) {
     tvherror(LS_HTTPC, "Invalid url '%s'", u->raw);
     return -EINVAL;
@@ -2019,7 +2019,7 @@ http_client_testsuite_run( void )
     } else if (strncmp(s, "Command=", 8) == 0) {
       if (strcmp(s + 8, "EXIT") == 0)
         break;
-      if (u1.host == NULL || u1.host[0] == '\0') {
+      if (tvh_str_default(u1.host, NULL) == NULL) {
         fprintf(stderr, "HTTPCTS: Define URL\n");
         goto fatal;
       }
index c19d9874cdf358bbc6fe31f9231943e1124719bf..1f3e367250b08a6b7fefe832911e34f656e23f8a 100644 (file)
@@ -343,7 +343,7 @@ static void
 mpegts_network_display_name
   ( mpegts_network_t *mn, char *buf, size_t len )
 {
-  strncpy(buf, mn->mn_network_name ?: "unknown", len);
+  strncpy(buf, tvh_str_default(mn->mn_network_name, "unknown"), len);
 }
 
 static bouquet_t *
@@ -399,7 +399,7 @@ static int
 mpegts_network_bouquet_comment
   ( mpegts_network_t *mn, char *comment, size_t len)
 {
-  if (!mn->mn_provider_network_name || mn->mn_provider_network_name[0] == '\0')
+  if (tvh_str_default(mn->mn_provider_network_name, NULL) == NULL)
     return -1;
   snprintf(comment, len, "%s", mn->mn_provider_network_name);
   return 0;
@@ -577,7 +577,7 @@ mpegts_network_set_network_name
 {
   char buf[256];
   int save = 0;
-  if (mn->mn_network_name == NULL || mn->mn_network_name[0] == '\0') {
+  if (tvh_str_default(mn->mn_network_name, NULL) == NULL) {
     if (name && name[0] && strcmp(name, mn->mn_network_name ?: "")) {
       tvh_str_update(&mn->mn_network_name, name);
       mn->mn_display_name(mn, buf, sizeof(buf));
index ab654bcbc2412120314b75422914f1ddc8b39a49..d1a312aa8a2fb292a739d062252628165a16d3c8 100644 (file)
@@ -2556,7 +2556,7 @@ transcoder_create:
         (void)profile_create(NULL, e, 1);
       } else if (pro && idnode_is_instance(&pro->pro_id, &profile_transcode_class)) {
         profile_transcode_t *prot = (profile_transcode_t *)pro;
-        if (prot->pro_vcodec == NULL || prot->pro_vcodec[0] == '\0') {
+        if (tvh_str_default(prot->pro_vcodec, NULL) == NULL) {
           profile_delete(pro, 1);
           goto transcoder_create;
         }
index eee2956e15d557f5812c7f68d33754bdb026b1b3..5b5bc60125ffcb86751cad883004aa00c6ad016a 100644 (file)
@@ -159,7 +159,7 @@ tvh_codec_register(TVHCodec *self)
     static const size_t min_size = sizeof(TVHCodecProfile);
     AVCodec *codec = NULL;
 
-    if (!self->name || self->name[0] == '\0' ||
+    if (tvh_str_default(self->name, NULL) == NULL ||
         self->size < min_size || !self->idclass) {
         tvherror(LS_CODEC, "incomplete/wrong definition for '%s' codec",
                  self->name ? self->name : "<missing name>");
index b0ee51eb36be1bea242eb3fca3bb8463702ada36..b3db8dffa530992d17167b764b0f90cc0011d2e9 100644 (file)
@@ -57,7 +57,7 @@ tvhva_init(const char *device)
 {
     TVHVADevice *vad;
 
-    if (device == NULL || *device == '\0')
+    if (tvh_str_default(device, NULL) == NULL)
         device = "/dev/dri/renderD128";
     LIST_FOREACH(vad, &tvhva_devices, link) {
         if (strcmp(vad->hw_device_name, device) == 0)
index 6e379221f741d83680c4f34106bbf39d94f326ca..9de142b35e98867e2191e41336dd044562728e6b 100644 (file)
@@ -666,6 +666,10 @@ static inline unsigned int tvh_strhash(const char *s, unsigned int mod)
 #define MINMAX(a,mi,ma) MAX(mi, MIN(ma, a))
 #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
 
+static inline const char *tvh_str_default(const char *s, const char *dflt)
+{
+  return s && s[0] ? s : dflt;
+}
 void tvh_str_set(char **strp, const char *src);
 int tvh_str_update(char **strp, const char *src);
 
index 2db18e05d7cdcc655bb94739bf1cb7c64563b24d..74273ddae9af674f21c5c17fc8fc8569db4f3cce 100644 (file)
--- a/src/udp.c
+++ b/src/udp.c
@@ -110,7 +110,8 @@ static int
 udp_get_ifindex( const char *ifname )
 {
   unsigned int r;
-  if (ifname == NULL || *ifname == '\0')
+
+  if (tvh_str_default(ifname, NULL) == NULL)
     return 0;
 
   r = if_nametoindex(ifname);
@@ -124,7 +125,7 @@ udp_get_ifaddr( int fd, const char *ifname, struct in_addr *addr )
 {
   struct ifreq ifreq;
 
-  if (ifname == NULL || *ifname == '\0')
+  if (tvh_str_default(ifname, NULL) == NULL)
     return -1;
   
   memset(&ifreq, 0, sizeof(ifreq));