Ejemplo n.º 1
0
static int
sidfile_scandir(fa_dir_t *fd, const char *url, char *errbuf, size_t errlen)
{
  void *fh = NULL;
  char *p, *fpath = mystrdupa(url);
  char buf[128];
  char name[32];
  char turl[URL_MAX];
  int tracks, i;
  fa_dir_entry_t *fde;
  rstr_t *album, *artist;
 

  if((p = strrchr(fpath, '/')) == NULL) {
    snprintf(errbuf, errlen, "Invalid filename");
    return -1;
  }

  *p = 0;
  if((fh = fa_open(fpath, errbuf, errlen)) == NULL)
    return -1;

  if(fa_read(fh, buf, 128) != 128) {
    snprintf(errbuf, errlen, "Unable to read file");
    fa_close(fh);
    return -1;
  }

  album = rstr_alloc(utf8_from_bytes((char *)buf + 0x16, 32, NULL));
  artist = rstr_alloc(utf8_from_bytes((char *)buf + 0x36, 32, NULL));

  tracks = buf[0xf];
  for(i = 0; i < tracks; i++) {

    snprintf(name, sizeof(name), "Track %02d", i + 1);
    snprintf(turl, sizeof(turl), "sidplayer:%s/%d", fpath, i + 1);
    fde = fa_dir_add(fd, turl, name, CONTENT_AUDIO);

    fde->fde_probestatus = FDE_PROBE_DEEP;

    fde->fde_metadata = prop_create_root("metadata");
    prop_set_string(prop_create(fde->fde_metadata, "title"), name);
    prop_set_rstring(prop_create(fde->fde_metadata, "album"), album);
    prop_set_rstring(prop_create(fde->fde_metadata, "artist"), artist);
  }

  rstr_release(album);
  rstr_release(artist);

  fa_close(fh);
  return 0;
}
Ejemplo n.º 2
0
static nls_string_t *
nls_string_find(const char *key)
{
  nls_string_t *ns;

  unsigned int hash = mystrhash(key) % NLS_STRING_HASH_WIDTH;

  hts_mutex_lock(&nls_mutex);

  LIST_FOREACH(ns, &nls_strings[hash], ns_link)
    if(!strcmp(rstr_get(ns->ns_key), key))
      break;

  if(ns == NULL) {
    ns = calloc(1, sizeof(nls_string_t));
    ns->ns_key = rstr_alloc(key);
    ns->ns_prop = prop_create_root(NULL);
    prop_set_rstring(ns->ns_prop, ns->ns_key);

  } else {
    LIST_REMOVE(ns, ns_link);
  }
  LIST_INSERT_HEAD(&nls_strings[hash], ns, ns_link);

  hts_mutex_unlock(&nls_mutex);
  return ns;
}
Ejemplo n.º 3
0
int
search_class_create(prop_t *parent, prop_t **nodesp, prop_t **entriesp,
                    const char *title, const char *icon)
{
    prop_t *p = prop_create_root(NULL);
    prop_t *m = prop_create(p, "metadata");
    prop_t *n, *e;

    rstr_t *url = backend_prop_make(p, NULL);
    prop_set_rstring(prop_create(p, "url"), url);
    rstr_release(url);

    prop_set_string(prop_create(m, "title"), title);
    if(icon != NULL)
        prop_set_string(prop_create(m, "icon"), icon);
    prop_set_string(prop_create(p, "type"), "directory");

    n = prop_create(p, "nodes");
    e = prop_create(p, "entries");
    prop_set_int(e, 0);

    *nodesp = prop_ref_inc(n);
    *entriesp = prop_ref_inc(e);

    if(prop_set_parent(p, parent)) {
        prop_destroy(p);
        return 1;
    }
    return 0;
}
Ejemplo n.º 4
0
static void
settings_add_dir_sup(prop_t *root,
		     const char *url, const char *icon,
		     const char *subtype)
{
  rstr_t *url2 = backend_prop_make(root, url);
  prop_set_rstring(prop_create(root, "url"), url2);
  rstr_release(url2);

  prop_t *metadata = prop_create(root, "metadata");

  prop_set_string(prop_create(root, "subtype"), subtype);

  if(icon != NULL)
    prop_set_string(prop_create(metadata, "icon"), icon);
}
Ejemplo n.º 5
0
static nls_string_t *
nls_string_find(const char *key)
{
  nls_string_t *ns;

  LIST_FOREACH(ns, &nls_strings, ns_link)
    if(!strcmp(rstr_get(ns->ns_key), key))
      break;

  if(ns == NULL) {

    ns = calloc(1, sizeof(nls_string_t));
    ns->ns_key = rstr_alloc(key);
    ns->ns_prop = prop_create_root(NULL);
    prop_set_rstring(ns->ns_prop, ns->ns_key);

  } else {
    LIST_REMOVE(ns, ns_link);
  }
  LIST_INSERT_HEAD(&nls_strings, ns, ns_link);
  return ns;
}