int api_exec ( const char *subsystem, htsmsg_t *args, htsmsg_t **resp ) { api_hook_t h; api_link_t *ah, skel; const char *op; /* Args and response must be set */ if (!args || !resp || !subsystem) return EINVAL; // Note: there is no locking while checking the hook tree, its assumed // this is all setup during init (if this changes the code will // need updating) h.ah_subsystem = subsystem; skel.hook = &h; ah = RB_FIND(&api_hook_tree, &skel, link, ah_cmp); if (!ah) { tvhwarn("api", "failed to find subsystem [%s]", subsystem); return ENOSYS; // TODO: is this really the right error code? } /* Extract method */ op = htsmsg_get_str(args, "method"); if (!op) op = htsmsg_get_str(args, "op"); // Note: this is not required (so no final validation) /* Execute */ return ah->hook->ah_callback(ah->hook->ah_opaque, op, args, resp); }
static int stroke_rect_element(svg_state_t *s, htsmsg_t *attribs) { const char *str_width = htsmsg_get_str(attribs, "width"); const char *str_height = htsmsg_get_str(attribs, "height"); const char *str_x = htsmsg_get_str(attribs, "x"); const char *str_y = htsmsg_get_str(attribs, "y"); if(str_width == NULL || str_height == NULL || str_x == NULL || str_y == NULL) return -1; float width = my_str2double(str_width, NULL); float height = my_str2double(str_height, NULL); float x = my_str2double(str_x, NULL); float y = my_str2double(str_y, NULL); float v[2]; v[0] = x; v[1] = y; cmd_move_abs(s, v); v[0] += width; cmd_lineto_abs(s, v); v[1] += height; cmd_lineto_abs(s, v); v[0] = x; cmd_lineto_abs(s, v); cmd_close(s); return 0; }
/** * Parse a <channel> tag from xmltv */ static int _xmltv_parse_channel (epggrab_module_t *mod, htsmsg_t *body, epggrab_stats_t *stats) { int save =0; htsmsg_t *attribs, *tags, *subtag; const char *id, *name, *icon; epggrab_channel_t *ch; if(body == NULL) return 0; if((attribs = htsmsg_get_map(body, "attrib")) == NULL) return 0; if((id = htsmsg_get_str(attribs, "id")) == NULL) return 0; if((tags = htsmsg_get_map(body, "tags")) == NULL) return 0; if((ch = _xmltv_channel_find(id, 1, &save)) == NULL) return 0; stats->channels.total++; if (save) stats->channels.created++; if((name = htsmsg_xml_get_cdata_str(tags, "display-name")) != NULL) { save |= epggrab_channel_set_name(ch, name); } if((subtag = htsmsg_get_map(tags, "icon")) != NULL && (attribs = htsmsg_get_map(subtag, "attrib")) != NULL && (icon = htsmsg_get_str(attribs, "src")) != NULL) { save |= epggrab_channel_set_icon(ch, icon); } if (save) { epggrab_channel_updated(ch); stats->channels.modified++; } return save; }
/** * Parse a <programme> tag from xmltv */ static int _xmltv_parse_programme (epggrab_module_t *mod, htsmsg_t *body, epggrab_stats_t *stats) { int save = 0; htsmsg_t *attribs, *tags; const char *s, *chid; time_t start, stop; epggrab_channel_t *ch; epggrab_channel_link_t *ecl; if(body == NULL) return 0; if((attribs = htsmsg_get_map(body, "attrib")) == NULL) return 0; if((tags = htsmsg_get_map(body, "tags")) == NULL) return 0; if((chid = htsmsg_get_str(attribs, "channel")) == NULL) return 0; if((ch = _xmltv_channel_find(chid, 0, NULL)) == NULL) return 0; if (!LIST_FIRST(&ch->channels)) return 0; if((s = htsmsg_get_str(attribs, "start")) == NULL) return 0; start = _xmltv_str2time(s); if((s = htsmsg_get_str(attribs, "stop")) == NULL) return 0; stop = _xmltv_str2time(s); if(stop <= start || stop <= dispatch_clock) return 0; LIST_FOREACH(ecl, &ch->channels, link) save |= _xmltv_parse_programme_tags(mod, ecl->channel, tags, start, stop, stats); return save; }
static void tmdb_insert_movie_cast(void *db, int64_t itemid, htsmsg_t *doc) { char url[300]; char id[64]; htsmsg_field_t *f; const char *s; htsmsg_t *cast = htsmsg_get_list(doc, "cast"); HTSMSG_FOREACH(f, cast) { htsmsg_t *p = htsmsg_get_map_by_field(f); if(p == NULL) continue; s = htsmsg_get_str(p, "profile_path"); if(s) snprintf(url, sizeof(url), "tmdb:image:profile:%s", s); else url[0] = 0; snprintf(id, sizeof(id), "%d", htsmsg_get_u32_or_default(p, "id", 0)); metadb_insert_videocast(db, itemid, htsmsg_get_str(p, "name"), htsmsg_get_str(p, "character"), "Cast", "Actor", htsmsg_get_u32_or_default(p, "order", 0), url[0] ? url : NULL, 0, 0, id); }
static htsmsg_t * avt_SetAVTransportURI(http_connection_t *hc, htsmsg_t *args, const char *myhost, int myport) { const char *uri = htsmsg_get_str(args, "CurrentURI"); const char *metaxml = htsmsg_get_str(args, "CurrentURIMetaData"); char errbuf[200]; htsmsg_t *meta; if(uri == NULL) return NULL; if(metaxml == NULL) { playqueue_play(uri, prop_create_root(NULL), 1); return NULL; } meta = htsmsg_xml_deserialize_cstr(metaxml, errbuf, sizeof(errbuf)); if(meta == NULL) { TRACE(TRACE_ERROR, "UPNP", "SetAVTransportURI: Unable to parse metadata -- %s", errbuf); return NULL; } if(play_with_context(uri, meta)) { // Failed to play from context // TODO: Fix metadata here playqueue_play(uri, prop_create_root(NULL), 1); } htsmsg_release(meta); return NULL; }
static int api_dvr_autorec_create ( access_t *perm, void *opaque, const char *op, htsmsg_t *args, htsmsg_t **resp ) { htsmsg_t *conf; dvr_config_t *cfg; dvr_autorec_entry_t *dae; const char *s1; if (!(conf = htsmsg_get_map(args, "conf"))) return EINVAL; htsmsg_set_str(conf, "owner", perm->aa_username ?: ""); htsmsg_set_str(conf, "creator", perm->aa_representative ?: ""); s1 = htsmsg_get_str(conf, "config_uuid"); if (s1 == NULL) s1 = htsmsg_get_str(conf, "config_name"); pthread_mutex_lock(&global_lock); cfg = dvr_config_find_by_list(perm->aa_dvrcfgs, s1); if (cfg) { htsmsg_set_str(conf, "config_name", idnode_uuid_as_str(&cfg->dvr_id)); dae = dvr_autorec_create(NULL, conf); if (dae) { dvr_autorec_save(dae); dvr_autorec_changed(dae, 1); } } pthread_mutex_unlock(&global_lock); return 0; }
static JSBool js_appendItem(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { const char *url; const char *type = NULL; JSObject *metaobj = NULL; js_model_t *model = JS_GetPrivate(cx, obj); const char *canonical_url = NULL; htsmsg_t *m = NULL; JSBool r; if(!JS_ConvertArguments(cx, argc, argv, "s/so", &url, &type, &metaobj)) return JS_FALSE; if(!strncmp(url, "videoparams:", strlen("videoparams:"))) { m = htsmsg_json_deserialize(url + strlen("videoparams:")); if(m != NULL) { canonical_url = htsmsg_get_str(m, "canonicalUrl"); if(canonical_url == NULL) { htsmsg_t *sources; if((sources = htsmsg_get_list(m, "sources")) == NULL) { htsmsg_field_t *f; HTSMSG_FOREACH(f, sources) { htsmsg_t *src = &f->hmf_msg; canonical_url = htsmsg_get_str(src, "url"); if(canonical_url != NULL) break; }
static void http_callback(http_req_aux_t *req, void *opaque) { char errbuf[128]; tracker_torrent_t *tt = opaque; torrent_t *to = tt->tt_torrent; htsmsg_t *msg; net_addr_t na; assert(tt->tt_http_req != NULL); tt->tt_http_req = NULL; buf_t *b = http_req_get_result(req); tt->tt_interval = MIN(3600, tt->tt_interval * 2); if(b != NULL) { msg = bencode_deserialize(buf_cstr(b), buf_cstr(b) + buf_size(b), errbuf, sizeof(errbuf), NULL, NULL); if(msg != NULL) { const char *err = htsmsg_get_str(msg, "failure reason"); if(err != NULL) { tracker_trace(tt->tt_tracker, "%s for %s", err, to->to_title); goto done; } const char *trackerid = htsmsg_get_str(msg, "trackerid"); if(trackerid != NULL) mystrset(&tt->tt_trackerid, trackerid); tt->tt_interval = htsmsg_get_u32_or_default(msg, "min interval", htsmsg_get_u32_or_default(msg, "interval", 1800)); htsmsg_t *peers = htsmsg_get_list(msg, "peers"); if(peers != NULL) { htsmsg_field_t *f; HTSMSG_FOREACH(f, peers) { htsmsg_t *sub = htsmsg_get_map_by_field(f); if(sub == NULL) continue; const char *ip = htsmsg_get_str(sub, "ip"); if(ip == NULL) continue; if(net_resolve_numeric(ip, &na)) continue; na.na_port = htsmsg_get_u32_or_default(sub, "port", 0); if(na.na_port == 0) continue; peer_add(to, &na); } }
static int _pyepg_parse_broadcast ( epggrab_module_t *mod, htsmsg_t *data, channel_t *channel, epggrab_stats_t *stats ) { int save = 0; htsmsg_t *attr, *tags; epg_episode_t *episode; epg_broadcast_t *broadcast; const char *id, *start, *stop; time_t tm_start, tm_stop; uint32_t u32; if ( data == NULL || channel == NULL ) return 0; if ((attr = htsmsg_get_map(data, "attrib")) == NULL) return 0; if ((id = htsmsg_get_str(attr, "episode")) == NULL) return 0; if ((start = htsmsg_get_str(attr, "start")) == NULL ) return 0; if ((stop = htsmsg_get_str(attr, "stop")) == NULL ) return 0; if ((tags = htsmsg_get_map(data, "tags")) == NULL) return 0; /* Parse times */ if (!_pyepg_parse_time(start, &tm_start)) return 0; if (!_pyepg_parse_time(stop, &tm_stop)) return 0; /* Find broadcast */ broadcast = epg_broadcast_find_by_time(channel, tm_start, tm_stop, 0, 1, &save); if ( broadcast == NULL ) return 0; stats->broadcasts.total++; if ( save ) stats->broadcasts.created++; /* Quality */ u32 = htsmsg_get_map(tags, "hd") ? 1 : 0; save |= epg_broadcast_set_is_hd(broadcast, u32, mod); u32 = htsmsg_get_map(tags, "widescreen") ? 1 : 0; save |= epg_broadcast_set_is_widescreen(broadcast, u32, mod); // TODO: lines, aspect /* Accessibility */ // Note: reuse XMLTV parse code as this is the same xmltv_parse_accessibility(mod, broadcast, tags); /* New/Repeat */ u32 = htsmsg_get_map(tags, "new") || htsmsg_get_map(tags, "premiere"); save |= epg_broadcast_set_is_new(broadcast, u32, mod); u32 = htsmsg_get_map(tags, "repeat") ? 1 : 0; save |= epg_broadcast_set_is_repeat(broadcast, u32, mod); /* Set episode */ if ((episode = epg_episode_find_by_uri(id, 1, &save)) == NULL) return 0; save |= epg_broadcast_set_episode(broadcast, episode, mod); if (save) stats->broadcasts.modified++; return save; }
static void bookmark_load(htsmsg_t *m) { if((m = htsmsg_get_map(m, "model")) == NULL) return; bookmark_add(htsmsg_get_str(m, "title"), htsmsg_get_str(m, "url"), htsmsg_get_str(m, "svctype")); }
static int _pyepg_parse_season ( epggrab_module_t *mod, htsmsg_t *data, epggrab_stats_t *stats ) { int save = 0; htsmsg_t *attr, *tags; epg_season_t *season; epg_brand_t *brand; const char *str; uint32_t u32; if ( data == NULL ) return 0; if ((attr = htsmsg_get_map(data, "attrib")) == NULL) return 0; if ((str = htsmsg_get_str(attr, "id")) == NULL) return 0; if ((tags = htsmsg_get_map(data, "tags")) == NULL) return 0; /* Find series */ if ((season = epg_season_find_by_uri(str, 1, &save)) == NULL) return 0; stats->seasons.total++; if (save) stats->seasons.created++; /* Set brand */ if ((str = htsmsg_get_str(attr, "brand"))) { if ((brand = epg_brand_find_by_uri(str, 0, NULL))) { save |= epg_season_set_brand(season, brand, mod); } } /* Set summary */ if ((str = htsmsg_xml_get_cdata_str(tags, "summary"))) { save |= epg_season_set_summary(season, str, NULL, mod); } /* Set image */ if ((str = htsmsg_xml_get_cdata_str(tags, "image"))) { save |= epg_season_set_image(season, str, mod); } else if ((str = htsmsg_xml_get_cdata_str(tags, "thumb"))) { save |= epg_season_set_image(season, str, mod); } /* Set season number */ if (htsmsg_xml_get_cdata_u32(tags, "number", &u32) == 0) { save |= epg_season_set_number(season, u32, mod); } /* Set episode count */ if (htsmsg_xml_get_cdata_u32(tags, "episode-count", &u32) == 0) { save |= epg_season_set_episode_count(season, u32, mod); } if(save) stats->seasons.modified++; return save; }
static int api_dvr_entry_create ( access_t *perm, void *opaque, const char *op, htsmsg_t *args, htsmsg_t **resp ) { dvr_entry_t *de; dvr_config_t *cfg; htsmsg_t *conf, *m; char *s, *lang; const char *s1; int res = EPERM; if (!(conf = htsmsg_get_map(args, "conf"))) return EINVAL; pthread_mutex_lock(&global_lock); s1 = htsmsg_get_str(conf, "config_name"); cfg = dvr_config_find_by_list(perm->aa_dvrcfgs, s1); if (cfg) { htsmsg_set_str(conf, "config_name", idnode_uuid_as_str(&cfg->dvr_id)); htsmsg_set_str(conf, "owner", perm->aa_username ?: ""); htsmsg_set_str(conf, "creator", perm->aa_representative ?: ""); lang = access_get_lang(perm, htsmsg_get_str(conf, "lang")); if (lang) { for (s = (char *)lang; *s && *s != ','; s++); *s = '\0'; } else { lang = strdup(lang_code_preferred()); } s1 = htsmsg_get_str(conf, "disp_title"); if (s1 && !htsmsg_get_map(conf, "title")) { m = htsmsg_create_map(); htsmsg_add_str(m, lang, s1); htsmsg_add_msg(conf, "title", m); } s1 = htsmsg_get_str(conf, "disp_subtitle"); if (s1 && !htsmsg_get_map(conf, "subtitle")) { m = htsmsg_create_map(); htsmsg_add_str(m, lang, s1); htsmsg_add_msg(conf, "subtitle", m); } if ((de = dvr_entry_create(NULL, conf))) dvr_entry_save(de); res = 0; free(lang); } pthread_mutex_unlock(&global_lock); return res; }
static void htsp_channelAddUpdate(htsp_connection_t *hc, htsmsg_t *m, int create) { uint32_t id, next; int chnum; char txt[200]; const char *title, *icon; htsp_channel_t *ch; if(htsmsg_get_u32(m, "channelId", &id)) return; title = htsmsg_get_str(m, "channelName"); icon = htsmsg_get_str(m, "channelIcon"); chnum = htsmsg_get_s32_or_default(m, "channelNumber", -1); snprintf(txt, sizeof(txt), "%d", id); hts_mutex_lock(&hc->hc_meta_mutex); if(create) { ch = htsp_channel_get(hc, id, 1); if(prop_set_parent(ch->ch_root, hc->hc_channels_nodes)) abort(); } else { ch = htsp_channel_get(hc, id, 0); if(ch == NULL) { TRACE(TRACE_ERROR, "HTSP", "Got update for unknown channel %d", id); hts_mutex_unlock(&hc->hc_meta_mutex); return; } } hts_mutex_unlock(&hc->hc_meta_mutex); if(icon != NULL) prop_set_string(ch->ch_prop_icon, icon); if(title != NULL) { mystrset(&ch->ch_title, title); prop_set_string(ch->ch_prop_title, title); } if(chnum != -1) prop_set_int(ch->ch_prop_channelNumber, chnum); if(htsmsg_get_u32(m, "eventId", &id)) id = 0; if(htsmsg_get_u32(m, "nextEventId", &next)) next = 0; update_events(hc, ch->ch_prop_events, id, next); }
static int api_dvr_autorec_create_by_series ( access_t *perm, void *opaque, const char *op, htsmsg_t *args, htsmsg_t **resp ) { dvr_autorec_entry_t *dae; epg_broadcast_t *e; htsmsg_t *entries, *entries2 = NULL, *m; htsmsg_field_t *f; const char *config_uuid, *s; int count = 0; if (!(entries = htsmsg_get_list(args, "entries"))) { entries = entries2 = api_dvr_entry_create_from_single(args); if (!entries) return EINVAL; } HTSMSG_FOREACH(f, entries) { if (!(m = htsmsg_get_map_by_field(f))) continue; if (!(s = htsmsg_get_str(m, "event_id"))) continue; config_uuid = htsmsg_get_str(m, "config_uuid"); pthread_mutex_lock(&global_lock); if ((e = epg_broadcast_find_by_id(strtoll(s, NULL, 10)))) { dvr_config_t *cfg = dvr_config_find_by_list(perm->aa_dvrcfgs, config_uuid); if (cfg) { dae = dvr_autorec_add_series_link(idnode_uuid_as_str(&cfg->dvr_id), e, perm->aa_username, perm->aa_representative, "Created from EPG query"); if (dae) { dvr_autorec_save(dae); dvr_autorec_changed(dae, 1); } } } pthread_mutex_unlock(&global_lock); count++; } htsmsg_destroy(entries2); return !count ? EINVAL : 0; }
PVR_ERROR CHTSPData::DeleteTimer(const PVR_TIMER &timer, bool bForce) { XBMC->Log(LOG_DEBUG, "%s", __FUNCTION__); htsmsg_t *msg = htsmsg_create_map(); htsmsg_add_str(msg, "method", "cancelDvrEntry"); htsmsg_add_u32(msg, "id", timer.iClientIndex); if ((msg = ReadResult(msg)) == NULL) { XBMC->Log(LOG_DEBUG, "%s - Failed to get cancelDvrEntry", __FUNCTION__); return PVR_ERROR_SERVER_ERROR; } const char *strError = NULL; if ((strError = htsmsg_get_str(msg, "error"))) { XBMC->Log(LOG_DEBUG, "%s - Error deleting timer: '%s'", __FUNCTION__, strError); return PVR_ERROR_SERVER_ERROR; } unsigned int success; if (htsmsg_get_u32(msg, "success", &success) != 0) { XBMC->Log(LOG_DEBUG, "%s - Failed to parse param", __FUNCTION__); return PVR_ERROR_SERVER_ERROR; } return success > 0 ? PVR_ERROR_NO_ERROR : PVR_ERROR_NOT_DELETED; }
static int xmlrpc_parse_struct(htsmsg_t *dst, htsmsg_t *params, char *errbuf, size_t errlen) { htsmsg_field_t *f, *g; htsmsg_t *c, *c2; const char *name; HTSMSG_FOREACH(f, params) { if(strcmp(f->hmf_name, "member") || (c = htsmsg_get_map_by_field(f)) == NULL) continue; if((name = htsmsg_get_str(c, "name")) == NULL) continue; if((c2 = htsmsg_get_map(c, "value")) == NULL) continue; g = TAILQ_FIRST(&c2->hm_fields); if(g == NULL) continue; if(xmlrpc_parse_value(dst, g, name, errbuf, errlen)) return -1; } return 0; }
/* * Intialise global file manager */ void timeshift_init ( void ) { htsmsg_t *m; const char *str; uint32_t u32; timeshift_filemgr_init(); /* Defaults */ timeshift_enabled = 0; // Disabled timeshift_ondemand = 0; // Permanent timeshift_path = NULL; // setting dir timeshift_unlimited_period = 0; timeshift_max_period = 3600; // 1Hr timeshift_unlimited_size = 0; timeshift_max_size = 10000 * (size_t)1048576; // 10G /* Load settings */ if ((m = hts_settings_load("timeshift/config"))) { if (!htsmsg_get_u32(m, "enabled", &u32)) timeshift_enabled = u32 ? 1 : 0; if (!htsmsg_get_u32(m, "ondemand", &u32)) timeshift_ondemand = u32 ? 1 : 0; if ((str = htsmsg_get_str(m, "path"))) timeshift_path = strdup(str); if (!htsmsg_get_u32(m, "unlimited_period", &u32)) timeshift_unlimited_period = u32 ? 1 : 0; htsmsg_get_u32(m, "max_period", ×hift_max_period); if (!htsmsg_get_u32(m, "unlimited_size", &u32)) timeshift_unlimited_size = u32 ? 1 : 0; if (!htsmsg_get_u32(m, "max_size", &u32)) timeshift_max_size = 1048576LL * u32; htsmsg_destroy(m); } }
static int api_dvr_entry_create ( access_t *perm, void *opaque, const char *op, htsmsg_t *args, htsmsg_t **resp ) { dvr_entry_t *de; dvr_config_t *cfg; htsmsg_t *conf; const char *s1; int res = EPERM; if (!(conf = htsmsg_get_map(args, "conf"))) return EINVAL; pthread_mutex_lock(&global_lock); s1 = htsmsg_get_str(conf, "config_name"); cfg = dvr_config_find_by_list(perm->aa_dvrcfgs, s1); if (cfg) { htsmsg_set_str(conf, "config_name", idnode_uuid_as_str(&cfg->dvr_id)); if (perm->aa_representative) htsmsg_set_str(conf, "creator", perm->aa_representative); if ((de = dvr_entry_create(NULL, conf))) dvr_entry_save(de); res = 0; } pthread_mutex_unlock(&global_lock); return res; }
static int _pyepg_parse_channel ( epggrab_module_t *mod, htsmsg_t *data, epggrab_stats_t *stats ) { int save = 0; epggrab_channel_t *ch; htsmsg_t *attr, *tags; const char *str; uint32_t u32; if ( data == NULL ) return 0; if ((attr = htsmsg_get_map(data, "attrib")) == NULL) return 0; if ((str = htsmsg_get_str(attr, "id")) == NULL) return 0; if ((tags = htsmsg_get_map(data, "tags")) == NULL) return 0; if (!(ch = _pyepg_channel_find(str, 1, &save))) return 0; stats->channels.total++; if (save) stats->channels.created++; /* Update data */ if ((str = htsmsg_xml_get_cdata_str(tags, "name"))) save |= epggrab_channel_set_name(ch, str); if ((str = htsmsg_xml_get_cdata_str(tags, "image"))) save |= epggrab_channel_set_icon(ch, str); if ((!htsmsg_xml_get_cdata_u32(tags, "number", &u32))) save |= epggrab_channel_set_number(ch, u32, 0); /* Update */ if (save) { epggrab_channel_updated(ch); stats->channels.modified++; } return save; }
static int _pyepg_parse_schedule ( epggrab_module_t *mod, htsmsg_t *data, epggrab_stats_t *stats ) { int save = 0; htsmsg_t *attr, *tags; htsmsg_field_t *f; epggrab_channel_t *ec; const char *str; epggrab_channel_link_t *ecl; if ( data == NULL ) return 0; if ((attr = htsmsg_get_map(data, "attrib")) == NULL) return 0; if ((str = htsmsg_get_str(attr, "channel")) == NULL) return 0; if ((ec = _pyepg_channel_find(str, 0, NULL)) == NULL) return 0; if ((tags = htsmsg_get_map(data, "tags")) == NULL) return 0; HTSMSG_FOREACH(f, tags) { if (strcmp(f->hmf_name, "broadcast") == 0) { LIST_FOREACH(ecl, &ec->channels, ecl_epg_link) save |= _pyepg_parse_broadcast(mod, htsmsg_get_map_by_field(f), ecl->ecl_channel, stats); } } return save; }
/** * TTML docs here: http://www.w3.org/TR/ttaf1-dfxp/ */ static ext_subtitles_t * load_ttml(const char *url, buf_t *buf) { char errbuf[256]; htsmsg_t *subs; htsmsg_field_t *f; htsmsg_t *xml = htsmsg_xml_deserialize_buf(buf, errbuf, sizeof(errbuf)); if(xml == NULL) { TRACE(TRACE_INFO, "Subtitles", "Unable to load TTML: %s", errbuf); return NULL; } subs = htsmsg_get_map_multi(xml, "tt", "body", "div", NULL); if(subs == NULL) { htsmsg_release(xml); return NULL; } ext_subtitles_t *es = calloc(1, sizeof(ext_subtitles_t)); TAILQ_INIT(&es->es_entries); HTSMSG_FOREACH(f, subs) { if(f->hmf_type == HMF_STR && f->hmf_childs != NULL) { htsmsg_t *n = f->hmf_childs; const char *str, *txt; int64_t start, end; txt = f->hmf_str; if((str = htsmsg_get_str(n, "begin")) == NULL) continue; if((start = ttml_time_expression(str)) == -1) continue; if((str = htsmsg_get_str(n, "end")) == NULL) continue; if((end = ttml_time_expression(str)) == -1) continue; es_insert_text(es, txt, start, end, 0); } } return es; }
/* * Parse a series of language strings */ static void _xmltv_parse_lang_str ( lang_str_t **ls, htsmsg_t *tags, const char *tname ) { htsmsg_t *e, *attrib; htsmsg_field_t *f; const char *lang; HTSMSG_FOREACH(f, tags) { if (!strcmp(f->hmf_name, tname) && (e = htsmsg_get_map_by_field(f))) { if (!*ls) *ls = lang_str_create(); lang = NULL; if ((attrib = htsmsg_get_map(e, "attrib"))) lang = htsmsg_get_str(attrib, "lang"); lang_str_add(*ls, htsmsg_get_str(e, "cdata"), lang, 0); } } }
rstr_t * htsmsg_store_get_str(const char *store, const char *key) { hts_mutex_lock(&loaded_msg_mutex); loaded_msg_t *lm = htsmsg_store_obtain(store, 1); rstr_t *r = rstr_alloc(htsmsg_get_str(lm->lm_msg, key)); hts_mutex_unlock(&loaded_msg_mutex); return r; }
static int stroke_path_element(svg_state_t *s, htsmsg_t *attribs) { const char *d = htsmsg_get_str(attribs, "d"); if(d == NULL) return -1; stroke_path(s, d); return 0; }
static int dotdoozer_parse(job_t *j, htsmsg_t *target) { SHA_CTX ctx; uint8_t digest[20]; const char *buildenv = htsmsg_get_str(target, "buildenv"); if(buildenv == NULL) return 0; cfg_root(root); const char *source = cfg_get_str(root, CFG("buildenvs", buildenv, "source"), NULL); if(source == NULL) { snprintf(j->errmsg, sizeof(j->errmsg), "Don't know about buildenv: %s", buildenv); return DOOZER_PERMANENT_FAIL; } // We are going to build in a chroot j->projectdir_internal = "/project"; j->buildenv_source = tstrdup(source); // Compute SHA1 of source URL, this is the source ID SHA1((void *)source, strlen(source), digest); bin2hex(j->buildenv_source_id, sizeof(j->buildenv_source_id), digest, sizeof(digest)); // Compute SHA1 of source URL + all build deps, this is the modified ID SHA1_Init(&ctx); SHA1_Update(&ctx, source, strlen(source)); htsmsg_t *builddeps = htsmsg_get_list(target, "builddeps"); if(builddeps != NULL) { htsmsg_field_t *f; int count = 0; HTSMSG_FOREACH(f, builddeps) { if(f->hmf_type != HMF_STR) { snprintf(j->errmsg, sizeof(j->errmsg), "Not all builddeps are strings"); return DOOZER_PERMANENT_FAIL; } count++; } j->num_builddeps = count; const char **bds = talloc_zalloc(count * sizeof(char *)); count = 0; HTSMSG_FOREACH(f, builddeps) { bds[count++] = tstrdup(f->hmf_str); SHA1_Update(&ctx, f->hmf_str, strlen(f->hmf_str)); }
static ext_subtitles_t * load_timedtext(const char *url, buf_t *buf) { char errbuf[256]; htsmsg_field_t *f; htsmsg_t *xml = htsmsg_xml_deserialize_buf(buf, errbuf, sizeof(errbuf)); if(xml == NULL) { TRACE(TRACE_INFO, "Subtitles", "Unable to load timed text: %s", errbuf); return NULL; } htsmsg_t *transcript = htsmsg_get_map_multi(xml, "transcript", NULL); if(transcript == NULL) { htsmsg_release(xml); return NULL; } ext_subtitles_t *es = calloc(1, sizeof(ext_subtitles_t)); TAILQ_INIT(&es->es_entries); HTSMSG_FOREACH(f, transcript) { if(f->hmf_type == HMF_STR && f->hmf_childs != NULL) { htsmsg_t *n = f->hmf_childs; const char *str; int64_t start, end; if((str = htsmsg_get_str(n, "start")) == NULL) continue; start = my_str2double(str, NULL) * 1000000.0; if((str = htsmsg_get_str(n, "dur")) == NULL) continue; end = start + my_str2double(str, NULL) * 1000000.0; char *txt = strdup(f->hmf_str); html_entities_decode(txt); es_insert_text(es, txt, start, end, 0); free(txt); } } return es; }
static htsmsg_t * api_dvr_entry_create_from_single(htsmsg_t *args) { htsmsg_t *entries, *m; const char *s1, *s2, *s3; if (!(s1 = htsmsg_get_str(args, "config_uuid"))) return NULL; if (!(s2 = htsmsg_get_str(args, "event_id"))) return NULL; s3 = htsmsg_get_str(args, "comment"); entries = htsmsg_create_list(); m = htsmsg_create_map(); htsmsg_add_str(m, "config_uuid", s1); htsmsg_add_str(m, "event_id", s2); if (s3) htsmsg_add_str(m, "comment", s3); htsmsg_add_msg(entries, NULL, m); return entries; }
static void htsp_tagAddUpdate(htsp_connection_t *hc, htsmsg_t *m, int create) { const char *id; htsmsg_t *members; htsmsg_field_t *f; prop_t *metadata, *before, *nodes; char txt[200]; int num = 0, i; htsp_tag_t *ht, *n; const char *title; if((id = htsmsg_get_str(m, "tagId")) == NULL) return; title = htsmsg_get_str(m, "tagName"); hts_mutex_lock(&hc->hc_meta_mutex); if(create) { ht = calloc(1, sizeof(htsp_tag_t)); ht->ht_id = strdup(id); ht->ht_title = strdup(title ?: ""); LIST_INSERT_SORTED(&hc->hc_tags, ht, ht_link, tag_compar); n = LIST_NEXT(ht, ht_link); ht->ht_root = prop_create_root(id); snprintf(txt, sizeof(txt), "htsp://%s:%d/tag/%s", hc->hc_hostname, hc->hc_port, id); prop_set_string(prop_create(ht->ht_root, "url"), txt); prop_set_string(prop_create(ht->ht_root, "type"), "directory"); if(prop_set_parent_ex(ht->ht_root, hc->hc_tags_nodes, n ? n->ht_root : NULL, NULL)) abort(); } else {
HTSMSG_FOREACH(f, crew) { htsmsg_t *p = htsmsg_get_map_by_field(f); if(p == NULL) continue; s = htsmsg_get_str(p, "profile_path"); if(s) snprintf(url, sizeof(url), "tmdb:image:profile:%s", s); else url[0] = 0; snprintf(id, sizeof(id), "%d", htsmsg_get_u32_or_default(p, "id", 0)); metadb_insert_videocast(db, itemid, htsmsg_get_str(p, "name"), NULL, htsmsg_get_str(p, "department"), htsmsg_get_str(p, "job"), o++, url[0] ? url : NULL, 0, 0, id); }