/** * Get a list of supported containers */ int muxer_container_list(htsmsg_t *array) { htsmsg_t *mc; int c = 0; mc = htsmsg_create_map(); htsmsg_add_str(mc, "name", muxer_container_type2txt(MC_MATROSKA)); htsmsg_add_str(mc, "description", "Matroska"); htsmsg_add_msg(array, NULL, mc); c++; mc = htsmsg_create_map(); htsmsg_add_str(mc, "name", muxer_container_type2txt(MC_PASS)); htsmsg_add_str(mc, "description", "Same as source (pass through)"); htsmsg_add_msg(array, NULL, mc); c++; #if ENABLE_LIBAV mc = htsmsg_create_map(); htsmsg_add_str(mc, "name", muxer_container_type2txt(MC_MPEGTS)); htsmsg_add_str(mc, "description", "MPEG-TS"); htsmsg_add_msg(array, NULL, mc); c++; mc = htsmsg_create_map(); htsmsg_add_str(mc, "name", muxer_container_type2txt(MC_MPEGPS)); htsmsg_add_str(mc, "description", "MPEG-PS (DVD)"); htsmsg_add_msg(array, NULL, mc); c++; #endif return c; }
static htsmsg_t * make_usage_report(void) { extern const char *htsversion_full; htsmsg_t *out = htsmsg_create_map(); htsmsg_add_str(out, "deviceid", gconf.device_id); htsmsg_add_str(out, "version", htsversion_full); htsmsg_add_str(out, "arch", arch_get_system_type()); htsmsg_add_u32(out, "verint", app_get_version_int()); htsmsg_add_u32(out, "generated", time(NULL)); if(gconf.os_info[0]) htsmsg_add_str(out, "os" , gconf.os_info); time_t now = arch_get_ts() / 1000000LL; int runtime = now - usage_time_base; htsmsg_s32_inc(usage_counters, "runtime", runtime); usage_time_base = now; htsmsg_add_msg(out, "counters", usage_counters); usage_counters = htsmsg_create_map(); htsmsg_add_msg(out, "plugincounters", plugin_counters); plugin_counters = htsmsg_create_map(); return out; }
void influxdb_put(const char *id, double value) { char url[1024]; cfg_root(root); const char *urlprefix = cfg_get_str(root, CFG("influxdb", "url"), NULL); const char *db = cfg_get_str(root, CFG("influxdb", "db"), NULL); const char *username = cfg_get_str(root, CFG("influxdb", "username"), NULL); const char *password = cfg_get_str(root, CFG("influxdb", "password"), NULL); if(urlprefix == NULL || db == NULL || username == NULL || password == NULL) return; snprintf(url, sizeof(url), "%s/db/%s/series?u=%s&p=%s", urlprefix, db, username, password); htsmsg_t *doc = htsmsg_create_list(); htsmsg_t *item = htsmsg_create_map(); htsmsg_add_str(item, "name", id); htsmsg_t *columns = htsmsg_create_list(); htsmsg_add_str(columns, NULL, "value"); htsmsg_add_msg(item, "columns", columns); htsmsg_t *points = htsmsg_create_list(); htsmsg_t *point = htsmsg_create_list(); htsmsg_add_dbl(point, NULL, value); htsmsg_add_msg(points, NULL, point); htsmsg_add_msg(item, "points", points); htsmsg_add_msg(doc, NULL, item); char *data = htsmsg_json_serialize_to_str(doc, 0); htsmsg_destroy(doc); size_t len = strlen(data); FILE *f = fmemopen(data, len, "r"); CURL *curl = curl_easy_init(); curl_easy_setopt(curl, CURLOPT_URL, url); curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L); curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1L); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &libsvc_curl_waste_output); curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "POST"); curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L); curl_easy_setopt(curl, CURLOPT_READDATA, (void *)f); curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE, (curl_off_t)len); CURLcode result = curl_easy_perform(curl); curl_easy_cleanup(curl); if(result) trace(LOG_ERR, "CURL Failed %s error %d", url, result); fclose(f); free(data); }
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 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 int api_imagecache_load ( access_t *perm, void *opaque, const char *op, htsmsg_t *args, htsmsg_t **resp ) { htsmsg_t *l; pthread_mutex_lock(&global_lock); *resp = htsmsg_create_map(); l = htsmsg_create_list(); htsmsg_add_msg(l, NULL, imagecache_get_config()); htsmsg_add_msg(*resp, "entries", l); pthread_mutex_unlock(&global_lock); return 0; }
// TODO: this will need converting to an idnode system static int api_channel_list ( access_t *perm, void *opaque, const char *op, htsmsg_t *args, htsmsg_t **resp ) { channel_t *ch; htsmsg_t *l; int cfg = api_channel_is_all(perm, args); char buf[128], ubuf[UUID_HEX_SIZE]; l = htsmsg_create_list(); pthread_mutex_lock(&global_lock); CHANNEL_FOREACH(ch) { if (!cfg && !channel_access(ch, perm, 0)) continue; if (!ch->ch_enabled) { snprintf(buf, sizeof(buf), "{%s}", channel_get_name(ch)); api_channel_key_val(l, idnode_uuid_as_str(&ch->ch_id, ubuf), buf); } else { api_channel_key_val(l, idnode_uuid_as_str(&ch->ch_id, ubuf), channel_get_name(ch)); } } pthread_mutex_unlock(&global_lock); *resp = htsmsg_create_map(); htsmsg_add_msg(*resp, "entries", l); return 0; }
static int api_channel_tag_list ( access_t *perm, void *opaque, const char *op, htsmsg_t *args, htsmsg_t **resp ) { channel_tag_t *ct; htsmsg_t *l; int cfg = api_channel_is_all(perm, args); char buf[128], ubuf[UUID_HEX_SIZE]; l = htsmsg_create_list(); pthread_mutex_lock(&global_lock); TAILQ_FOREACH(ct, &channel_tags, ct_link) if (cfg || channel_tag_access(ct, perm, 0)) { if (ct->ct_enabled) { api_channel_key_val(l, idnode_uuid_as_str(&ct->ct_id, ubuf), ct->ct_name); } else { snprintf(buf, sizeof(buf), "{%s}", ct->ct_name); api_channel_key_val(l, idnode_uuid_as_str(&ct->ct_id, ubuf), buf); } } pthread_mutex_unlock(&global_lock); *resp = htsmsg_create_map(); htsmsg_add_msg(*resp, "entries", l); return 0; }
static htsmsg_t * codec_profile_audio_class_language_list(void *obj, const char *lang) { htsmsg_t *list = htsmsg_create_list(); lang_code_t *lc = (lang_code_t *)lang_codes; char lc_buf[128]; while (lc->code2b) { htsmsg_t *map = NULL; if (!strcmp(lc->code2b, "und")) { map = htsmsg_create_key_val("", tvh_gettext_lang(lang, N_("Use original"))); } else { memset(lc_buf, 0, sizeof(lc_buf)); if (!str_snprintf(lc_buf, sizeof(lc_buf), "%s (%s)", lc->desc, lc->code2b)) { map = htsmsg_create_key_val(lc->code2b, lc_buf); } else { htsmsg_destroy(list); list = NULL; break; } } htsmsg_add_msg(list, NULL, map); lc++; } return list; }
static void api_channel_key_val(htsmsg_t *dst, const char *key, const char *val) { htsmsg_t *e = htsmsg_create_map(); htsmsg_add_str(e, "key", key); htsmsg_add_str(e, "val", val ?: ""); htsmsg_add_msg(dst, NULL, e); }
static int api_language_enum ( access_t *perm, void *opaque, const char *op, htsmsg_t *args, htsmsg_t **resp ) { const lang_code_t *c = lang_codes; htsmsg_t *l, *e; l = htsmsg_create_list(); while (c->code2b) { e = htsmsg_create_map(); htsmsg_add_str(e, "key", c->code2b); htsmsg_add_str(e, "val", c->desc); htsmsg_add_msg(l, NULL, e); c++; } *resp = htsmsg_create_map(); htsmsg_add_msg(*resp, "entries", l); return 0; }
static int api_access_entry_userlist ( access_t *perm, void *opaque, const char *op, htsmsg_t *args, htsmsg_t **resp ) { int i; idnode_set_t *is; idnode_t *in; access_entry_t *ae; htsmsg_t *l, *e; l = htsmsg_create_list(); if (!access_verify2(perm, ACCESS_ADMIN)) goto empty; if ((is = idnode_find_all(&access_entry_class, NULL))) { for (i = 0; i < is->is_count; i++) { in = is->is_array[i]; if (idnode_perm(in, perm, NULL)) continue; ae = (access_entry_t *)in; if (ae->ae_username != NULL && ae->ae_username[0] != '\0' && ae->ae_username[0] != '*') { e = htsmsg_create_map(); htsmsg_add_str(e, "key", ae->ae_username); htsmsg_add_str(e, "val", ae->ae_username); htsmsg_add_msg(l, NULL, e); } idnode_perm_unset(in); } free(is->is_array); free(is); } empty: *resp = htsmsg_create_map(); htsmsg_add_msg(*resp, "entries", l); return 0; }
static htsmsg_t * epggrab_module_ota_scrapper_config_list ( void *o, const char *lang ) { htsmsg_t *m = htsmsg_create_list(); htsmsg_t *e = htsmsg_create_map(); htsmsg_add_str(e, "key", ""); htsmsg_add_str(e, "val", tvh_gettext_lang(lang, N_("Use default configuration"))); htsmsg_add_msg(m, NULL, e); htsmsg_t *config; /* We load all the config so we can get the names of ones that are * valid. This is a bit of overhead but we are rarely called since * this is for the configuration GUI drop-down. */ if((config = hts_settings_load_r(1, "epggrab/eit/scrape")) != NULL) { htsmsg_field_t *f; HTSMSG_FOREACH(f, config) { e = htsmsg_create_map(); htsmsg_add_str(e, "key", htsmsg_field_name(f)); htsmsg_add_str(e, "val", htsmsg_field_name(f)); htsmsg_add_msg(m, NULL, e); }
static int api_epggrab_channel_list ( access_t *perm, void *opaque, const char *op, htsmsg_t *args, htsmsg_t **resp ) { htsmsg_t *m; pthread_mutex_lock(&global_lock); m = epggrab_channel_list(0); pthread_mutex_unlock(&global_lock); *resp = htsmsg_create_map(); htsmsg_add_msg(*resp, "entries", m); return 0; }
static int api_serverinfo ( void *opaque, const char *op, htsmsg_t *args, htsmsg_t **resp ) { *resp = htsmsg_create_map(); htsmsg_add_str(*resp, "sw_version", tvheadend_version); htsmsg_add_u32(*resp, "api_version", TVH_API_VERSION); htsmsg_add_str(*resp, "name", "Tvheadend"); if (tvheadend_webroot) htsmsg_add_str(*resp, "webroot", tvheadend_webroot); htsmsg_add_msg(*resp, "capabilities", tvheadend_capabilities_list(1)); return 0; }
void linuxdvb_ca_save( linuxdvb_ca_t *lca, htsmsg_t *msg ) { char id[8]; htsmsg_t *m = htsmsg_create_map(); htsmsg_add_str(m, "uuid", idnode_uuid_as_str(&lca->lca_id)); idnode_save(&lca->lca_id, m); /* Add to list */ snprintf(id, sizeof(id), "ca%u", lca->lca_number); htsmsg_add_msg(msg, id, m); }
void usage_inc_plugin_counter(const char *plugin, const char *id, int value) { hts_mutex_lock(&usage_mutex); htsmsg_t *m = htsmsg_get_map(plugin_counters, plugin); if(m == NULL) { m = htsmsg_create_map(); htsmsg_add_msg(plugin_counters, plugin, m); m = htsmsg_get_map(plugin_counters, plugin); assert(m != NULL); } htsmsg_s32_inc(m, id, value); hts_mutex_unlock(&usage_mutex); }
/** * Get a list of supported cache schemes */ int muxer_cache_list(htsmsg_t *array) { htsmsg_t *mc; int c; const char *s; for (c = 0; c <= MC_CACHE_LAST; c++) { mc = htsmsg_create_map(); s = muxer_cache_type2txt(c); htsmsg_add_u32(mc, "index", c); htsmsg_add_str(mc, "description", s); htsmsg_add_msg(array, NULL, mc); } return c; }
static htsmsg_t * hts_settings_load_path(const char *fullpath, int depth) { char child[256]; struct filebundle_stat st; fb_dirent **namelist, *d; htsmsg_t *r, *c; int n, i; /* Invalid */ if (fb_stat(fullpath, &st)) return NULL; /* Directory */ if (st.is_dir) { /* Get file list */ if((n = fb_scandir(fullpath, &namelist)) < 0) return NULL; /* Read files */ r = htsmsg_create_map(); for(i = 0; i < n; i++) { d = namelist[i]; if(d->name[0] != '.') { snprintf(child, sizeof(child), "%s/%s", fullpath, d->name); if(d->type == FB_DIR && depth > 0) { c = hts_settings_load_path(child, depth - 1); } else { c = hts_settings_load_one(child); } if(c != NULL) htsmsg_add_msg(r, d->name, c); } free(d); } free(namelist); /* File */ } else { r = hts_settings_load_one(fullpath); } return r; }
void satip_device_save( satip_device_t *sd ) { satip_frontend_t *lfe; htsmsg_t *m, *l; m = htsmsg_create_map(); idnode_save(&sd->th_id, m); l = htsmsg_create_map(); TAILQ_FOREACH(lfe, &sd->sd_frontends, sf_link) satip_frontend_save(lfe, l); htsmsg_add_msg(m, "frontends", l); hts_settings_save(m, "input/satip/adapters/%s", idnode_uuid_as_str(&sd->th_id)); htsmsg_destroy(m); }
static void * send_report(void *aux) { htsmsg_t *m = aux; htsbuf_queue_t hq; htsbuf_queue_init(&hq, 0); htsmsg_add_msg(m, "plugins", plugins_get_installed_list()); htsmsg_json_serialize(m, &hq, 0); http_req("https://movian.tv/movian/status/v1/usage", HTTP_POSTDATA(&hq, "application/json"), NULL); htsmsg_release(m); return NULL; }
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; }
void tvhdhomerun_device_save( tvhdhomerun_device_t *hd ) { tvhdhomerun_frontend_t *lfe; htsmsg_t *m, *l; m = htsmsg_create_map(); idnode_save(&hd->th_id, m); l = htsmsg_create_map(); TAILQ_FOREACH(lfe, &hd->hd_frontends, hf_link) tvhdhomerun_frontend_save(lfe, l); htsmsg_add_msg(m, "frontends", l); htsmsg_add_str(m, "fe_override", hd->hd_override_type); hts_settings_save(m, "input/tvhdhomerun/adapters/%s", idnode_uuid_as_str(&hd->th_id)); htsmsg_destroy(m); }
static htsmsg_t * tvhdhomerun_device_class_save ( idnode_t *in, char *filename, size_t fsize ) { tvhdhomerun_device_t *hd = (tvhdhomerun_device_t *)in; tvhdhomerun_frontend_t *lfe; htsmsg_t *m, *l; char ubuf[UUID_HEX_SIZE]; m = htsmsg_create_map(); idnode_save(&hd->th_id, m); if (filename) { l = htsmsg_create_map(); TAILQ_FOREACH(lfe, &hd->hd_frontends, hf_link) tvhdhomerun_frontend_save(lfe, l); htsmsg_add_msg(m, "frontends", l); snprintf(filename, fsize, "input/tvhdhomerun/adapters/%s", idnode_uuid_as_str(&hd->th_id, ubuf)); } htsmsg_add_str(m, "fe_override", hd->hd_override_type); return m; }
int keyring_lookup(const char *id, char **username, char **password, char **domain, int query, const char *source, const char *reason, int force_temporary) { htsmsg_t *m; rstr_t *r; hts_mutex_lock(&keyring_mutex); if(query) { htsmsg_t *parent; prop_t *p = prop_create_root(NULL); prop_set_string(prop_create(p, "type"), "auth"); prop_set_string(prop_create(p, "id"), id); prop_set_string(prop_create(p, "source"), source); prop_set_string(prop_create(p, "reason"), reason); int remember = !force_temporary; prop_set_int(prop_create(p, "canRemember"), remember); prop_t *rememberMe = prop_create(p, "rememberMe"); prop_set_int(rememberMe, remember); prop_sub_t *remember_sub = prop_subscribe(0, PROP_TAG_CALLBACK_INT, set_remember, &remember, PROP_TAG_ROOT, rememberMe, NULL); prop_t *user = prop_create(p, "username"); prop_t *pass = prop_create(p, "password"); TRACE(TRACE_INFO, "keyring", "Requesting credentials for %s : %s : %s", id, source, reason); event_t *e = popup_display(p); prop_unsubscribe(remember_sub); if(remember) parent = persistent_keyring; else parent = temporary_keyring; htsmsg_delete_field(parent, id); if(event_is_action(e, ACTION_OK)) { /* OK */ m = htsmsg_create_map(); r = prop_get_string(user); htsmsg_add_str(m, "username", r ? rstr_get(r) : ""); rstr_release(r); r = prop_get_string(pass); htsmsg_add_str(m, "password", r ? rstr_get(r) : ""); rstr_release(r); htsmsg_add_msg(parent, id, m); if(parent == persistent_keyring) keyring_store(); } else { /* CANCEL, store without adding anything */ keyring_store(); } prop_destroy(p); if(event_is_action(e, ACTION_CANCEL)) { /* return CANCEL to caller */ hts_mutex_unlock(&keyring_mutex); event_release(e); return -1; } event_release(e); } if((m = htsmsg_get_map(temporary_keyring, id)) == NULL && (m = htsmsg_get_map(persistent_keyring, id)) == NULL) { hts_mutex_unlock(&keyring_mutex); return 1; } setstr(username, m, "username"); setstr(password, m, "password"); setstr(domain, m, "domain"); hts_mutex_unlock(&keyring_mutex); return 0; }
htsmsg_t * dvb_mux_preconf_get_node(int fetype, const char *node) { const struct region *r; const struct network *n; int nr, nn, i; htsmsg_t *out, *e; switch(fetype) { case FE_QAM: r = regions_DVBC; nr = sizeof(regions_DVBC) / sizeof(regions_DVBC[0]); break; case FE_QPSK: r = regions_DVBS; nr = sizeof(regions_DVBS) / sizeof(regions_DVBS[0]); break; case FE_OFDM: r = regions_DVBT; nr = sizeof(regions_DVBT) / sizeof(regions_DVBT[0]); break; case FE_ATSC: r = regions_ATSC; nr = sizeof(regions_ATSC) / sizeof(regions_ATSC[0]); break; default: tvhlog(LOG_ERR, "DVB", "No built-in config for fetype %d", fetype); return NULL; } out = htsmsg_create_list(); if(!strcmp(node, "root")) { for(i = 0; i < nr; i++) { e = htsmsg_create_map(); htsmsg_add_u32(e, "leaf", 0); htsmsg_add_str(e, "text", r[i].name); htsmsg_add_str(e, "id", r[i].name); htsmsg_add_msg(out, NULL, e); } return out; } for(i = 0; i < nr; i++) if(!strcmp(node, r[i].name)) break; if(i == nr) return out; n = r[i].networks; nn = r[i].nnetworks; for(i = 0; i < nn; i++) { e = htsmsg_create_map(); htsmsg_add_u32(e, "leaf", 1); htsmsg_add_str(e, "text", n[i].name); htsmsg_add_str(e, "id", n[i].name); htsmsg_add_msg(out, NULL, e); } return out; }
/* * Note: text in data pointer is not preserved (must be read/write) */ htsmsg_t *parse_m3u (char *data, const char *charset, const char *url) { char *p, *x, *y; char *charset_id = intlconv_charset_id(charset, 0, 1); const char *multi_name; int delim; htsmsg_t *m = htsmsg_create_map(); htsmsg_t *item = NULL, *l = NULL, *t, *key = NULL; char buf[512]; while (*data && *data <= ' ') data++; p = data; data = until_eol(data); if (strncmp(p, "#EXTM3U", 7)) { htsmsg_add_msg(m, "items", htsmsg_create_list()); return m; } while (*data) { if (strncmp(data, "#EXTINF:", 8) == 0) { if (item == NULL) item = htsmsg_create_map(); data += 8; p = data; if (*data == '-') data++; while (*data >= '0' && *data <= '9') data++; delim = *data; *data = '\0'; htsmsg_add_s64(item, "m3u-duration", strtoll(p, NULL, 10)); *data = delim; while (*data > ' ' && *data != ',') data++; while (delim && delim != ',' && delim != '\n' && delim != '\r') { while (*data && *data <= ' ') data++; if (*data == '\0' || *data == ',') break; p = data++; while (*data && *data != ',' && *data != '=') data++; if (*data == '=') { *data = '\0'; x = get_m3u_str(data + 1, &data, &delim); if (*p && *x) { y = intlconv_to_utf8safestr(charset_id, x, strlen(x)*2); htsmsg_add_str(item, p, y ?: ".invalid.charset."); free(y); } get_m3u_str_post(&data, delim); } } p = NULL; if (*data == ',') { delim = ','; data++; } if (delim == ',') { while (*data && *data <= ' ' && *data != '\n' && *data != '\r') data++; if (*data) p = data; } data = until_eol(data); if (p && *p) { y = intlconv_to_utf8safestr(charset_id, p, strlen(p)*2); htsmsg_add_str(item, "m3u-name", y ?: ".invalid.charset."); free(y); }
int keyring_lookup(const char *id, char **username, char **password, char **domain, int *remember_me, const char *source, const char *reason, int flags) { htsmsg_t *m; rstr_t *r; int remember = !!(flags & KEYRING_REMEMBER_ME_SET); hts_mutex_lock(&keyring_mutex); if(flags & KEYRING_QUERY_USER) { htsmsg_t *parent; prop_t *p = prop_create_root(NULL); prop_set_string(prop_create(p, "type"), "auth"); prop_set_string(prop_create(p, "id"), id); prop_set_string(prop_create(p, "source"), source); prop_set_string(prop_create(p, "reason"), reason); prop_set_int(prop_create(p, "disableUsername"), username == NULL); prop_set_int(prop_create(p, "canRemember"), !!(flags & KEYRING_SHOW_REMEMBER_ME)); prop_t *rememberMe = prop_create(p, "rememberMe"); prop_set_int(rememberMe, remember); prop_sub_t *remember_sub = prop_subscribe(0, PROP_TAG_CALLBACK_INT, set_remember, &remember, PROP_TAG_ROOT, rememberMe, NULL); prop_t *user = prop_create(p, "username"); prop_t *pass = prop_create(p, "password"); TRACE(TRACE_INFO, "keyring", "Requesting credentials for %s : %s : %s", id, source, reason); event_t *e = popup_display(p); prop_unsubscribe(remember_sub); if(flags & KEYRING_ONE_SHOT) parent = NULL; else if(remember) parent = persistent_keyring; else parent = temporary_keyring; if(parent != NULL) htsmsg_delete_field(parent, id); if(event_is_action(e, ACTION_OK)) { /* OK */ m = htsmsg_create_map(); if(username != NULL) { r = prop_get_string(user); htsmsg_add_str(m, "username", r ? rstr_get(r) : ""); *username = strdup(r ? rstr_get(r) : ""); rstr_release(r); } r = prop_get_string(pass); htsmsg_add_str(m, "password", r ? rstr_get(r) : ""); *password = strdup(r ? rstr_get(r) : ""); rstr_release(r); if(parent != NULL) { htsmsg_add_msg(parent, id, m); if(parent == persistent_keyring) keyring_store(); } } else { /* CANCEL */ if(parent == persistent_keyring) keyring_store(); } if(remember_me != NULL) *remember_me = remember; prop_destroy(p); if(event_is_action(e, ACTION_CANCEL)) { /* return CANCEL to caller */ hts_mutex_unlock(&keyring_mutex); event_release(e); return -1; } event_release(e); } else { if((m = htsmsg_get_map(temporary_keyring, id)) == NULL && (m = htsmsg_get_map(persistent_keyring, id)) == NULL) { hts_mutex_unlock(&keyring_mutex); return 1; } setstr(username, m, "username"); setstr(password, m, "password"); setstr(domain, m, "domain"); } hts_mutex_unlock(&keyring_mutex); return 0; }