static int _pyepg_parse_epg ( epggrab_module_t *mod, htsmsg_t *data, epggrab_stats_t *stats ) { int save = 0; htsmsg_t *tags; htsmsg_field_t *f; if ((tags = htsmsg_get_map(data, "tags")) == NULL) return 0; HTSMSG_FOREACH(f, tags) { if (strcmp(f->hmf_name, "channel") == 0 ) { save |= _pyepg_parse_channel(mod, htsmsg_get_map_by_field(f), stats); } else if (strcmp(f->hmf_name, "brand") == 0 ) { save |= _pyepg_parse_brand(mod, htsmsg_get_map_by_field(f), stats); } else if (strcmp(f->hmf_name, "series") == 0 ) { save |= _pyepg_parse_season(mod, htsmsg_get_map_by_field(f), stats); } else if (strcmp(f->hmf_name, "episode") == 0 ) { save |= _pyepg_parse_episode(mod, htsmsg_get_map_by_field(f), stats); } else if (strcmp(f->hmf_name, "schedule") == 0 ) { save |= _pyepg_parse_schedule(mod, htsmsg_get_map_by_field(f), stats); } } return save; }
static int xmlrpc_parse_value(htsmsg_t *dst, htsmsg_field_t *g, const char *name, char *errbuf, size_t errlen) { const char *cdata; htsmsg_t *c; htsmsg_t *sub; if(!strcmp(g->hmf_name, "struct") && (c = htsmsg_get_map_by_field(g)) != NULL) { sub = htsmsg_create_map(); if(xmlrpc_parse_struct(sub, c, errbuf, errlen)) { htsmsg_release(sub); return -1; } htsmsg_add_msg(dst, name, sub); return 0; } else if(!strcmp(g->hmf_name, "array") && (c = htsmsg_get_map_by_field(g)) != NULL) { sub = htsmsg_create_list(); if(xmlrpc_parse_array(sub, c, errbuf, errlen)) { htsmsg_release(sub); return -1; } htsmsg_add_msg(dst, name, sub); return 0; } cdata = g->hmf_type == HMF_STR ? g->hmf_str : NULL; if(!strcmp(g->hmf_name, "string")) { if(cdata != NULL) htsmsg_add_str(dst, name, cdata); } else if(!strcmp(g->hmf_name, "boolean")) { if(cdata != NULL) htsmsg_add_u32(dst, name, atoi(cdata)); } else if(!strcmp(g->hmf_name, "double")) { if(cdata != NULL) htsmsg_add_dbl(dst, name, my_str2double(cdata, NULL)); } else if(!strcmp(g->hmf_name, "int")) { if(cdata != NULL) htsmsg_add_s64(dst, name, atoll(cdata)); } else { snprintf(errbuf, errlen, "Unknown field type \"%s\" %s = %s", g->hmf_name, name, cdata); return -1; } return 0; }
static htsmsg_t * xmlrpc_convert_response(htsmsg_t *xml, char *errbuf, size_t errlen) { htsmsg_t *dst, *params; htsmsg_field_t *f, *g; htsmsg_t *c; if((params = htsmsg_get_map_multi(xml, "methodResponse", "params", NULL)) == NULL) { snprintf(errbuf, errlen, "No params in reply found"); return NULL; } dst = htsmsg_create_list(); HTSMSG_FOREACH(f, params) { if(strcmp(f->hmf_name, "param") || (c = htsmsg_get_map_by_field(f)) == NULL) continue; if((c = htsmsg_get_map(c, "value")) == NULL) continue; g = TAILQ_FIRST(&c->hm_fields); if(g == NULL || g->hmf_type != HMF_MAP) continue; if(xmlrpc_parse_value(dst, g, NULL, errbuf, errlen)) { htsmsg_release(dst); return NULL; } } return dst; }
static int xmlrpc_parse_array(htsmsg_t *dst, htsmsg_t *m, char *errbuf, size_t errlen) { htsmsg_t *c; htsmsg_field_t *f, *g; if((m = htsmsg_get_map(m, "data")) == NULL) { return 0; // Empty array } HTSMSG_FOREACH(f, m) { if(strcmp(f->hmf_name, "value") || (c = htsmsg_get_map_by_field(f)) == NULL) continue; g = TAILQ_FIRST(&c->hm_fields); if(g == NULL || g->hmf_type != HMF_MAP) continue; if(xmlrpc_parse_value(dst, g, NULL, errbuf, errlen)) { return -1; } } return 0; }
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; }
void bookmarks_init(void) { htsmsg_field_t *f; htsmsg_t *m, *n, *o; hts_mutex_init(&bookmark_mutex); bookmarks = prop_create(settings_add_dir(NULL, "Bookmarks", "bookmark", NULL), "model"); prop_set_int(prop_create(bookmarks, "mayadd"), 1); prop_subscribe(0, PROP_TAG_CALLBACK, bookmarks_callback, NULL, PROP_TAG_ROOT, prop_create(bookmarks, "nodes"), PROP_TAG_MUTEX, &bookmark_mutex, NULL); if((m = htsmsg_store_load("bookmarks")) != NULL) { n = htsmsg_get_map(m, "nodes"); HTSMSG_FOREACH(f, n) { if((o = htsmsg_get_map_by_field(f)) == NULL) continue; bookmark_load(o); } htsmsg_destroy(m); }
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 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; }
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 _xmltv_parse_tv (epggrab_module_t *mod, htsmsg_t *body, epggrab_stats_t *stats) { int save = 0; htsmsg_t *tags; htsmsg_field_t *f; if((tags = htsmsg_get_map(body, "tags")) == NULL) return 0; HTSMSG_FOREACH(f, tags) { if(!strcmp(f->hmf_name, "channel")) { save |= _xmltv_parse_channel(mod, htsmsg_get_map_by_field(f), stats); } else if(!strcmp(f->hmf_name, "programme")) { save |= _xmltv_parse_programme(mod, htsmsg_get_map_by_field(f), stats); } } return save; }
static epg_genre_list_t *_pyepg_parse_genre ( htsmsg_t *tags ) { htsmsg_t *e; htsmsg_field_t *f; epg_genre_list_t *egl = NULL; HTSMSG_FOREACH(f, tags) { if (!strcmp(f->hmf_name, "genre") && (e = htsmsg_get_map_by_field(f))) { if (!egl) { egl = calloc(1, sizeof(epg_genre_list_t)); printf("alloc %p\n", egl); } epg_genre_list_add_by_str(egl, htsmsg_get_str(e, "cdata")); } } return egl; }
/* * Parse category list */ static epg_genre_list_t *_xmltv_parse_categories ( htsmsg_t *tags ) { htsmsg_t *e; htsmsg_field_t *f; epg_genre_list_t *egl = NULL; HTSMSG_FOREACH(f, tags) { if (!strcmp(f->hmf_name, "category") && (e = htsmsg_get_map_by_field(f))) { if (!egl) egl = calloc(1, sizeof(epg_genre_list_t)); epg_genre_list_add_by_str(egl, htsmsg_get_str(e, "cdata")); } } return egl; }
static int _xmltv_parse_tv (epggrab_module_t *mod, htsmsg_t *body, epggrab_stats_t *stats) { int gsave = 0, save; htsmsg_t *tags; htsmsg_field_t *f; if((tags = htsmsg_get_map(body, "tags")) == NULL) return 0; HTSMSG_FOREACH(f, tags) { save = 0; if(!strcmp(f->hmf_name, "channel")) { pthread_mutex_lock(&global_lock); save = _xmltv_parse_channel(mod, htsmsg_get_map_by_field(f), stats); pthread_mutex_unlock(&global_lock); } else if(!strcmp(f->hmf_name, "programme")) { pthread_mutex_lock(&global_lock); save = _xmltv_parse_programme(mod, htsmsg_get_map_by_field(f), stats); if (save) epg_updated(); pthread_mutex_unlock(&global_lock); } gsave |= save; }
static void svg_parse_root(svg_state_t *s, htsmsg_t *tags) { htsmsg_field_t *f; HTSMSG_FOREACH(f, tags) { htsmsg_t *c; if((c = htsmsg_get_map_by_field(f)) == NULL) continue; if(!strcmp(f->hmf_name, "path")) svg_parse_element(s, c, stroke_path_element); else if(!strcmp(f->hmf_name, "rect")) svg_parse_element(s, c, stroke_rect_element); else if(!strcmp(f->hmf_name, "g")) svg_parse_g(s, c); }
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; }
cfg_t * cfg_find_map(cfg_t *c, const char *key, const char *value) { if(c == NULL) return NULL; htsmsg_field_t *f; HTSMSG_FOREACH(f, c) { htsmsg_t *m = htsmsg_get_map_by_field(f); if(m == NULL) continue; const char *s = htsmsg_get_str(m, key); if(s != NULL && !strcmp(value, s)) return m; }
/* * 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); } } }
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); }
/* * Parse accessibility data */ int xmltv_parse_accessibility ( epggrab_module_t *mod, epg_broadcast_t *ebc, htsmsg_t *m ) { int save = 0; htsmsg_t *tag; htsmsg_field_t *f; const char *str; HTSMSG_FOREACH(f, m) { if(!strcmp(f->hmf_name, "subtitles")) { if ((tag = htsmsg_get_map_by_field(f))) { str = htsmsg_xml_get_attr_str(tag, "type"); if (str && !strcmp(str, "teletext")) save |= epg_broadcast_set_is_subtitled(ebc, 1, mod); else if (str && !strcmp(str, "deaf-signed")) save |= epg_broadcast_set_is_deafsigned(ebc, 1, mod); } } else if (!strcmp(f->hmf_name, "audio-described")) { save |= epg_broadcast_set_is_audio_desc(ebc, 1, mod); } } return save; }
static void get_episode_info (epggrab_module_t *mod, htsmsg_t *tags, char **uri, char **suri, epg_episode_num_t *epnum ) { htsmsg_field_t *f; htsmsg_t *c, *a; const char *sys, *cdata; HTSMSG_FOREACH(f, tags) { if((c = htsmsg_get_map_by_field(f)) == NULL || strcmp(f->hmf_name, "episode-num") || (a = htsmsg_get_map(c, "attrib")) == NULL || (cdata = htsmsg_get_str(c, "cdata")) == NULL || (sys = htsmsg_get_str(a, "system")) == NULL) continue; if(!strcmp(sys, "onscreen")) epnum->text = (char*)cdata; else if(!strcmp(sys, "xmltv_ns")) parse_xmltv_ns_episode(cdata, epnum); else if(!strcmp(sys, "dd_progid")) parse_xmltv_dd_progid(mod, cdata, uri, suri, epnum); } }
static void check_upgrade(int set_news) { char url[1024]; char *result; htsmsg_t *json; char errbuf[1024]; if(inhibit_checks) return; if(upgrade_track == NULL) { prop_set_string(upgrade_error, "No release track specified"); goto err; } prop_set_string(upgrade_status, "checking"); TRACE(TRACE_DEBUG, "Upgrade", "Checking upgrades for %s-%s", upgrade_track, archname); snprintf(url, sizeof(url), "%s/%s-%s.json", ctrlbase, upgrade_track, archname); result = fa_load(url, NULL, NULL, errbuf, sizeof(errbuf), NULL, 0, NULL, NULL); if(result == NULL) { prop_set_string(upgrade_error, errbuf); err: prop_set_string(upgrade_status, "checkError"); return; } json = htsmsg_json_deserialize(result); free(result); if(json == NULL) { prop_set_string(upgrade_error, "Malformed JSON in repository"); goto err; } // Find an artifact for us const char *dlurl = NULL; const char *sha1 = NULL; int dlsize = 0; const char *ver; htsmsg_t *artifacts = htsmsg_get_list(json, "artifacts"); if(artifacts != NULL) { htsmsg_field_t *f; HTSMSG_FOREACH(f, artifacts) { htsmsg_t *a; if((a = htsmsg_get_map_by_field(f)) == NULL) continue; const char *type = htsmsg_get_str(a, "type"); if(type == NULL || strcmp(artifact_type, type)) continue; dlurl = htsmsg_get_str(a, "url"); sha1 = htsmsg_get_str(a, "sha1"); dlsize = htsmsg_get_u32_or_default(a, "size", 0); break; }
static int http_github(http_connection_t *hc, const char *remain, void *opaque) { const char *pid = http_arg_get(&hc->hc_req_args, "project"); const char *key = http_arg_get(&hc->hc_req_args, "key"); if(pid == NULL) { trace(LOG_WARNING, "github: Missing 'project' in request"); return 400; } if(key == NULL) { trace(LOG_WARNING, "github: Missing 'key' in request"); return 400; } project_cfg(pc, pid); if(pc == NULL) { trace(LOG_DEBUG, "github: Project '%s' not configured", pid); return 404; } const char *mykey = cfg_get_str(pc, CFG("github", "key"), ""); if(strcmp(mykey, key)) { trace(LOG_WARNING, "github: Invalid key received (%s) for project %s", key, pid); return 403; } project_t *p = project_get(pid); const char *json = http_arg_get(&hc->hc_req_args, "payload"); if(json == NULL) { plog(p, "github", "github: Missing payload in request"); return 400; } char errbuf[256]; htsmsg_t *msg = htsmsg_json_deserialize(json, errbuf, sizeof(errbuf)); if(msg == NULL) { plog(p, "github", "github: Malformed JSON in github request -- %s", errbuf); return 400; } const char *ref = htsmsg_get_str(msg, "ref"); if(ref != NULL && !strncmp(ref, "refs/heads/", strlen("refs/heads/"))) ref += strlen("refs/heads/"); htsmsg_t *list = htsmsg_get_list(msg, "commits"); if(ref != NULL && list != NULL) { htsmsg_field_t *f; HTSMSG_FOREACH(f, list) { htsmsg_t *c = htsmsg_get_map_by_field(f); if(c == NULL) continue; const char *url = htsmsg_get_str(c, "url"); const char *msg = htsmsg_get_str(c, "message"); htsmsg_t *a = htsmsg_get_map(c, "author"); const char *author = a ? htsmsg_get_str(a, "name") : NULL; int added = count_list(c, "added"); int removed = count_list(c, "removed"); int modified = count_list(c, "modified"); int len; char buf[512]; char ctx[128]; url = url ? urlshorten(url) : NULL; snprintf(ctx, sizeof(ctx), "changes/%s", ref); len = snprintf(buf, sizeof(buf), "Commit in '"COLOR_BLUE"%s"COLOR_OFF"' by "COLOR_PURPLE"%s"COLOR_OFF" [", ref, author ?: "???"); if(added) len += snprintf(buf + len, sizeof(buf) - len, COLOR_GREEN "%d file%s added", added, added == 1 ? "" : "s"); if(modified) len += snprintf(buf + len, sizeof(buf) - len, COLOR_YELLOW "%s%d file%s modified", added ? ", " : "", modified, modified == 1 ? "" : "s"); if(removed) len += snprintf(buf + len, sizeof(buf) - len, COLOR_RED "%s%d file%s removed", added || modified ? ", " : "", removed, removed == 1 ? "" : "s"); snprintf(buf + len, sizeof(buf) - len, COLOR_OFF"]%s%s", url ? " " : "", url ?: ""); plog(p, ctx, "%s", buf); plog(p, ctx, "%s", msg); }
void load_site_news(void) { #if ENABLE_WEBPOPUP struct http_header_list response_headers; buf_t *b; char errbuf[512]; b = fa_load("https://movian.tv/projects/movian/news.json", FA_LOAD_FLAGS(FA_DISABLE_AUTH | FA_COMPRESSION), FA_LOAD_RESPONSE_HEADERS(&response_headers), FA_LOAD_ERRBUF(errbuf, sizeof(errbuf)), NULL); if(b == NULL) { TRACE(TRACE_DEBUG, "News", "Unable to load news -- %s", errbuf); return; } const char *dateheader = http_header_get(&response_headers, "date"); if(dateheader == NULL) { buf_release(b); http_headers_free(&response_headers); return; } dateheader = mystrdupa(dateheader); http_headers_free(&response_headers); htsmsg_t *newsinfo = htsmsg_store_load("sitenews"); time_t no_news_before; if(newsinfo == NULL) newsinfo = htsmsg_create_map(); no_news_before = htsmsg_get_u32_or_default(newsinfo, "nothingbefore", 0); if(no_news_before == 0) { if(http_ctime(&no_news_before, dateheader)) { buf_release(b); htsmsg_release(newsinfo); return; } htsmsg_add_u32(newsinfo, "nothingbefore", no_news_before); htsmsg_store_save(newsinfo, "sitenews"); htsmsg_release(newsinfo); } htsmsg_t *doc = htsmsg_json_deserialize(buf_cstr(b)); buf_release(b); if(doc == NULL) { return; } hts_mutex_lock(&news_mutex); htsmsg_t *news = htsmsg_get_list(doc, "news"); if(news != NULL) { htsmsg_field_t *f; HTSMSG_FOREACH(f, news) { htsmsg_t *entry; if((entry = htsmsg_get_map_by_field(f)) == NULL) continue; const char *title = htsmsg_get_str(entry, "title"); const char *created_on = htsmsg_get_str(entry, "created_on"); int id = htsmsg_get_u32_or_default(entry, "id", 0); if(created_on == NULL || title == NULL || id == 0) continue; time_t t; if(parse_created_on_time(&t, created_on)) continue; if(t < no_news_before) continue; char idstr[64]; snprintf(idstr, sizeof(idstr), "sitenews:%d", id); prop_t *p = add_news_locked(idstr, title, NULL, "Read more", idstr); if(p != NULL) { prop_subscribe(PROP_SUB_TRACK_DESTROY, PROP_TAG_CALLBACK, open_news, p, PROP_TAG_ROOT, prop_create(p, "eventSink"), PROP_TAG_MUTEX, &news_mutex, NULL); } }
static void update_events(htsp_connection_t *hc, prop_t *metadata, int id, int next) { int i; htsmsg_t *m; prop_t *events = prop_create(metadata, "list"); prop_t *current_event = prop_create(metadata, "current"); prop_t *next_event = prop_create(metadata, "next"); int linkstate = 0; htsmsg_field_t *f; if(id == 0) { if(next == 0) { // No events at all prop_destroy_childs(events); return; } id = next; linkstate = 1; } m = htsmsg_create_map(); htsmsg_add_str(m, "method", "getEvents"); htsmsg_add_u32(m, "eventId", id); htsmsg_add_u32(m, "numFollowing", EPG_TAIL); if((m = htsp_reqreply(hc, m)) != NULL) { htsmsg_t *events = htsmsg_get_list(m, "events"); f = events ? TAILQ_FIRST(&events->hm_fields) : NULL; } else { f = NULL; } for(i = 0; i < EPG_TAIL; i++) { char buf[10]; uint32_t u32; snprintf(buf, sizeof(buf), "%d", i); if(f != NULL && f->hmf_type != HMF_MAP) f = NULL; if(f != NULL) { m = htsmsg_get_map_by_field(f); prop_t *e = prop_create(events, buf); prop_set_string(prop_create(e, "title"), htsmsg_get_str(m, "title")); prop_set_string(prop_create(e, "description"), htsmsg_get_str(m, "description")); if(!htsmsg_get_u32(m, "start", &u32)) prop_set_int(prop_create(e, "start"), u32); if(!htsmsg_get_u32(m, "stop", &u32)) prop_set_int(prop_create(e, "stop"), u32); switch(linkstate) { case 0: prop_link(e, current_event); break; case 1: prop_link(e, next_event); break; } linkstate++; f = TAILQ_NEXT(f, hmf_link); continue; } prop_destroy_by_name(events, buf); switch(linkstate) { case 0: prop_unlink(current_event); break; case 1: prop_unlink(next_event); break; } linkstate++; } }
struct pixmap * backend_imageloader(rstr_t *url0, const image_meta_t *im0, const char **vpaths, char *errbuf, size_t errlen, int *cache_control, cancellable_t *c) { const char *url = rstr_get(url0); htsmsg_t *m = NULL; if(im0->im_req_width < -1 || im0->im_req_height < -1) { snprintf(errbuf, errlen, "Invalid dimensions"); return NULL; } image_meta_t im = *im0; if(!strncmp(url, "thumb://", 8)) { url += 8; im.im_want_thumb = 1; } if(!strncmp(url, "imageset:", 9)) { m = htsmsg_json_deserialize(url+9); if(m == NULL) { snprintf(errbuf, errlen, "Invalid JSON"); return NULL; } htsmsg_field_t *f; const char *best = NULL; int best_width = -1; int best_height = -1; HTSMSG_FOREACH(f, m) { htsmsg_t *img = htsmsg_get_map_by_field(f); if(img == NULL) continue; int w = htsmsg_get_u32_or_default(img, "width", 10000); int h = htsmsg_get_u32_or_default(img, "height", 10000); const char *u = htsmsg_get_str(img, "url"); if(!u) continue; if(best != NULL) { if(im.im_req_width != -1) { if(w >= im.im_req_width && (w < best_width || best_width < im.im_req_width)) goto gotone; if(w < im.im_req_width && w > best_width) goto gotone; } else if(im.im_req_height != -1) { if(h >= im.im_req_height && (h < best_height || best_height < im.im_req_height)) goto gotone; if(h < im.im_req_height && h > best_height) goto gotone; } else { if(w > best_width) goto gotone; if(h > best_height) goto gotone; } continue; } gotone: best = u; best_width = w; best_height = h; }
int soap_exec(const char *uri, const char *service, int version, const char *method, htsmsg_t *in, htsmsg_t **outp, char *errbuf, size_t errlen) { int r; htsmsg_t *out; htsbuf_queue_t post; buf_t *result; struct http_header_list hdrs = {0}; char tmp[100]; htsbuf_queue_init(&post, 0); htsbuf_qprintf(&post, "<?xml version=\"1.0\" encoding=\"utf-8\"?>" "<s:Envelope s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">" "<s:Body><ns0:%s xmlns:ns0=\"urn:schemas-upnp-org:service:%s:%d\">", method, service, version); soap_encode_args(&post, in); htsbuf_qprintf(&post, "</ns0:%s></s:Body></s:Envelope>", method); snprintf(tmp, sizeof(tmp),"\"urn:schemas-upnp-org:service:%s:%d#%s\"", service, version, method); http_header_add(&hdrs, "SOAPACTION", tmp, 0); r = http_request(uri, NULL, &result, errbuf, errlen, &post, "text/xml; charset=\"utf-8\"", 0, NULL, &hdrs, NULL, NULL, NULL); http_headers_free(&hdrs); htsbuf_queue_flush(&post); if(r) return -1; out = htsmsg_xml_deserialize_buf2(result, errbuf, errlen); if(out == NULL) return -1; snprintf(tmp, sizeof(tmp), "urn:schemas-upnp-org:service:%s:%d%sResponse", service, version, method); htsmsg_t *outargs = htsmsg_get_map_multi(out, "tags", "http://schemas.xmlsoap.org/soap/envelope/Envelope", "tags", "http://schemas.xmlsoap.org/soap/envelope/Body", "tags", tmp, "tags", NULL); if(outargs != NULL) { htsmsg_field_t *f; htsmsg_t *out = htsmsg_create_map(); // Convert args from XML style to more compact style HTSMSG_FOREACH(f, outargs) { htsmsg_t *a; const char *s; if((a = htsmsg_get_map_by_field(f)) == NULL) continue; if((s = htsmsg_get_str(a, "cdata")) != NULL) htsmsg_add_str(out, f->hmf_name, s); }