]> 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 13:42:48 +0000 (15:42 +0200)
14 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/tvheadend.h
src/udp.c

index d3ed8f70b7332cf3d0e432e819e0c50af3a80353..17d1a2987594b9988d1a978a8156a4be47c3fa81 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 bff30fed035fb645f7982c864c90411f386b3498..8dff4bda0ca0c794b023cf0fa80aed6d6744be5e 100644 (file)
@@ -113,7 +113,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);
       free(ch->ch_name);
       ch->ch_name = strdup(s);
@@ -797,7 +797,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;
 
   /*
@@ -1533,7 +1533,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 f61b32418c753bcfd5c9389024280095cc9e70fd..eecbdb74a024e32d2e6baffd609b4224817b9c33 100644 (file)
@@ -1751,7 +1751,7 @@ 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_scanfile_ok)
     config_muxconfpath_notify(&config.idnode, NULL);
@@ -2406,21 +2406,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 d4a9ca13e7df45aced6623dcf55f97b09bfe5326..b6d50c3e23e73f0b18983b0c07693e3ea845ec84 100644 (file)
@@ -444,7 +444,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 152186d197159919d2438c71727d9030b292ec41..239d3b7a7d738fc23c729bc8a86a3a7ef2caf6a4 100644 (file)
@@ -817,8 +817,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)
@@ -851,8 +850,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)
@@ -885,8 +883,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 5c290791cd80642a7ce8eb0924227c055b794cf8..19bd0dad6a69b603d4f16c0ba6062bd17a7c3dd0 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) {
@@ -624,7 +624,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 d972212f938af0a75b2e0818292347329e3033d6..e5e005841b5bc463f1b007fef07e82605e0f928b 100644 (file)
@@ -2414,11 +2414,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);
     }
   }
@@ -2910,8 +2910,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)) {
@@ -2940,8 +2939,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 f3538bbd3d09dabfadb0737787c353230819496a..1a901585aea5a9be333fe411664aa063bb66e66b 100644 (file)
@@ -688,7 +688,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 ||
@@ -756,7 +756,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 73d9a0c50f0edb040b0bdfb33e488de000a992c6..453fc6f844d7d12625a480e58072bd97c3843a25 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 f336ccebc2d7c65e421697cd452372fc30e0c405..100cbe43d8a5d1e0e15fb04f5ea5b3efd1535b93 100644 (file)
@@ -367,9 +367,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();
@@ -927,7 +925,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 d929ead28464cddfcc280a96418a13ea522deff3..da613d62bed731b818511c3bdf908ff234735033 100644 (file)
@@ -317,7 +317,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 htsmsg_t *
@@ -485,7 +485,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 d65cac47c7d7f945ddf363ea75d7060485b43d75..f5b6ddc014f3e11557edc5717aae283f4d381131 100644 (file)
@@ -648,6 +648,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));