PVR_ERROR cHTSPData::AddTimer(const PVR_TIMERINFO &timerinfo) { XBMC->Log(LOG_DEBUG, "%s - id=%d", __FUNCTION__, timerinfo.index); htsmsg_t *msg = htsmsg_create_map(); htsmsg_add_str(msg, "method", "addDvrEntry"); htsmsg_add_u32(msg, "eventId", timerinfo.index); htsmsg_add_str(msg, "title", timerinfo.title); htsmsg_add_u32(msg, "starttime", timerinfo.starttime); htsmsg_add_u32(msg, "endtime", timerinfo.endtime); if ((msg = ReadResult(msg)) == NULL) { XBMC->Log(LOG_DEBUG, "%s - Failed to get addDvrEntry", __FUNCTION__); 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; }
PVR_ERROR CHTSPData::UpdateTimer(const PVR_TIMER &timer) { XBMC->Log(LOG_DEBUG, "%s - channelUid=%d title=%s epgid=%d", __FUNCTION__, timer.iClientChannelUid, timer.strTitle, timer.iEpgUid); htsmsg_t *msg = htsmsg_create_map(); htsmsg_add_str(msg, "method", "updateDvrEntry"); htsmsg_add_u32(msg, "id", timer.iClientIndex); htsmsg_add_str(msg, "title", timer.strTitle); htsmsg_add_u32(msg, "start", timer.startTime); htsmsg_add_u32(msg, "stop", timer.endTime); if ((msg = ReadResult(msg)) == NULL) { XBMC->Log(LOG_DEBUG, "%s - Failed to get updateDvrEntry", __FUNCTION__); 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_SAVED; }
static htsmsg_t * avt_GetPositionInfo(http_connection_t *hc, htsmsg_t *args, const char *myhost, int myport) { htsmsg_t *out = htsmsg_create_map(); char tbuf[16]; hts_mutex_lock(&upnp_lock); char *didl = build_didl(http_get_my_host(hc), http_get_my_port(hc)); htsmsg_add_u32(out, "Track", upnp_current_track); fmttime(tbuf, sizeof(tbuf), upnp_current_track_duration); htsmsg_add_str(out, "TrackDuration", tbuf); htsmsg_add_str(out, "TrackMetaData", didl); free(didl); htsmsg_add_str(out, "TrackURI", upnp_current_url ?: ""); fmttime(tbuf, sizeof(tbuf), upnp_current_track_time); htsmsg_add_str(out, "RelTime", tbuf); htsmsg_add_str(out, "AbsTime", tbuf); //"NOT_IMPLEMENTED"); htsmsg_add_u32(out, "RelCount", 2147483647); htsmsg_add_u32(out, "AbsCount", 2147483647); hts_mutex_unlock(&upnp_lock); return out; }
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; }
static void tvhtime_save ( void ) { htsmsg_t *m = htsmsg_create_map(); htsmsg_add_u32(m, "update_enabled", tvhtime_update_enabled); htsmsg_add_u32(m, "ntp_enabled", tvhtime_ntp_enabled); htsmsg_add_u32(m, "tolerance", tvhtime_tolerance); hts_settings_save(m, "tvhtime/config"); }
static void audio_mode_save_settings(audio_mode_t *am) { htsmsg_t *m = htsmsg_create_map(); htsmsg_add_u32(m, "phantom_center", am->am_phantom_center); htsmsg_add_u32(m, "phantom_lfe", am->am_phantom_lfe); htsmsg_add_u32(m, "small_front", am->am_small_front); htsmsg_add_u32(m, "force_downmix", am->am_force_downmix); htsmsg_add_u32(m, "swap_surround", am->am_swap_surround); htsmsg_add_s32(m, "delay", am->am_audio_delay); htsmsg_store_save(m, "audio/devices/%s", am->am_id); htsmsg_destroy(m); }
static void dismis_news(const char *message) { TRACE(TRACE_DEBUG, "news", "Dismissed news: %s", message); htsmsg_add_u32(dismissed_news_out, message, 1); htsmsg_store_save(dismissed_news_out, "dismissed_news"); }
htsmsg_t* CHTSPData::ReadResult(htsmsg_t *m) { if (!m_session->IsConnected()) return NULL; m_Mutex.Lock(); uint32_t seq = mvp_atomic_inc(&g_iPacketSequence); SMessage &message(m_queue[seq]); message.event = new cCondWait(); message.msg = NULL; m_Mutex.Unlock(); htsmsg_add_u32(m, "seq", seq); if(!m_session->SendMessage(m)) { m_queue.erase(seq); return NULL; } if(!message.event->Wait(g_iResponseTimeout * 1000)) { XBMC->Log(LOG_ERROR, "%s - request timed out after %d seconds", __FUNCTION__, g_iResponseTimeout); m_session->Close(); } m_Mutex.Lock(); m = message.msg; delete message.event; m_queue.erase(seq); m_Mutex.Unlock(); return m; }
bool CHTSPData::GetEvent(SEvent& event, uint32_t id) { if(id == 0) { event.Clear(); return false; } SEvents::iterator it = m_events.find(id); if(it != m_events.end()) { event = it->second; return true; } htsmsg_t *msg = htsmsg_create_map(); htsmsg_add_str(msg, "method", "getEvent"); htsmsg_add_u32(msg, "eventId", id); if((msg = ReadResult(msg)) == NULL) { XBMC->Log(LOG_DEBUG, "%s - failed to get event %d", __FUNCTION__, id); return false; } if (m_session->ParseEvent(msg, id, event)) { m_events[id] = event; return true; } return false; }
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; }
htsmsg_t* cHTSPData::ReadResult(htsmsg_t* m) { m_Mutex.Lock(); unsigned seq (m_session.AddSequence()); SMessage &message(m_queue[seq]); message.event = new cCondWait(); message.msg = NULL; m_Mutex.Unlock(); htsmsg_add_u32(m, "seq", seq); if(!m_session.SendMessage(m)) { m_queue.erase(seq); return NULL; } if(!message.event->Wait(2000)) { XBMC->Log(LOG_ERROR, "%s - Timeout waiting for response", __FUNCTION__); m_session.Close(); } m_Mutex.Lock(); m = message.msg; delete message.event; m_queue.erase(seq); m_Mutex.Unlock(); return m; }
static void dismis_news(const char *id) { htsmsg_add_u32(dismissed_news_out, id, 1); htsmsg_store_save(dismissed_news_out, "dismissed_news"); prop_t *root = prop_create(prop_get_global(), "news"); prop_destroy_by_name(root, id); }
static htsmsg_t * cm_GetCurrentConnectionInfo(http_connection_t *hc, htsmsg_t *args, const char *myhost, int myport) { const char *uri = htsmsg_get_str(args, "ConnectionID"); if(uri == NULL || strcmp(uri, "0")) return UPNP_CONTROL_INVALID_ARGS; htsmsg_t *out = htsmsg_create_map(); htsmsg_add_u32(out, "RcsID", 0); htsmsg_add_u32(out, "AVTransportID", 0); htsmsg_add_str(out, "ProtocolInfo", ""); htsmsg_add_str(out, "PeerConnectionManager", ""); htsmsg_add_s32(out, "PeerConnectionID", -1); htsmsg_add_str(out, "Direction", "Input"); htsmsg_add_str(out, "Status", "OK"); return out; }
PVR_ERROR CHTSPData::AddTimer(const PVR_TIMER &timer) { XBMC->Log(LOG_DEBUG, "%s - channelUid=%d title=%s epgid=%d", __FUNCTION__, timer.iClientChannelUid, timer.strTitle, timer.iEpgUid); time_t startTime = timer.startTime; if (startTime <= 0) { int iGmtOffset; GetBackendTime(&startTime, &iGmtOffset); } htsmsg_t *msg = htsmsg_create_map(); htsmsg_add_str(msg, "method", "addDvrEntry"); htsmsg_add_u32(msg, "eventId", -1); // XXX tvheadend doesn't correct epg tags with wrong start and end times, so we'll use xbmc's values htsmsg_add_str(msg, "title", timer.strTitle); htsmsg_add_u32(msg, "start", startTime); htsmsg_add_u32(msg, "stop", timer.endTime); htsmsg_add_u32(msg, "channelId", timer.iClientChannelUid); htsmsg_add_u32(msg, "priority", timer.iPriority); htsmsg_add_str(msg, "description", timer.strSummary); htsmsg_add_str(msg, "creator", "XBMC"); if ((msg = ReadResult(msg)) == NULL) { XBMC->Log(LOG_DEBUG, "%s - Failed to get addDvrEntry", __FUNCTION__); return PVR_ERROR_SERVER_ERROR; } const char *strError = NULL; if ((strError = htsmsg_get_str(msg, "error"))) { XBMC->Log(LOG_DEBUG, "%s - Error adding 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_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_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; }
PVR_ERROR cHTSPData::AddTimer(const PVR_TIMERINFO &timerinfo) { XBMC->Log(LOG_DEBUG, "%s - channelNumber=%d channelUid=%d title=%s epgid=%d", __FUNCTION__, timerinfo.channelUid, timerinfo.channelUid, timerinfo.title, timerinfo.epgid); htsmsg_t *msg = htsmsg_create_map(); htsmsg_add_str(msg, "method", "addDvrEntry"); htsmsg_add_u32(msg, "eventId", timerinfo.epgid); htsmsg_add_str(msg, "title", timerinfo.title); htsmsg_add_u32(msg, "start", timerinfo.starttime); htsmsg_add_u32(msg, "stop", timerinfo.endtime); htsmsg_add_u32(msg, "channelId", timerinfo.channelUid); htsmsg_add_u32(msg, "priority", timerinfo.priority); htsmsg_add_str(msg, "description", timerinfo.description); htsmsg_add_str(msg, "creator", "XBMC"); if ((msg = ReadResult(msg)) == NULL) { XBMC->Log(LOG_DEBUG, "%s - Failed to get addDvrEntry", __FUNCTION__); return PVR_ERROR_SERVER_ERROR; } const char *strError = NULL; if ((strError = htsmsg_get_str(msg, "error"))) { XBMC->Log(LOG_DEBUG, "%s - Error adding 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 htsp_login(htsp_connection_t *hc) { const void *ch; size_t chlen; htsmsg_t *m; m = htsmsg_create_map(); htsmsg_add_str(m, "clientname", "HTS Showtime"); htsmsg_add_u32(m, "htspversion", 1); htsmsg_add_str(m, "method", "hello"); if((m = htsp_reqreply(hc, m)) == NULL) { return -1; } if(htsmsg_get_bin(m, "challenge", &ch, &chlen) || chlen != 32) { htsmsg_destroy(m); return -1; } memcpy(hc->hc_challenge, ch, 32); htsmsg_destroy(m); m = htsmsg_create_map(); htsmsg_add_str(m, "method", "login"); htsmsg_add_u32(m, "htspversion", HTSP_PROTO_VERSION); if((m = htsp_reqreply(hc, m)) == NULL) { return -1; } htsmsg_destroy(m); return 0; }
static int api_imagecache_save ( access_t *perm, void *opaque, const char *op, htsmsg_t *args, htsmsg_t **resp ) { int b; pthread_mutex_lock(&global_lock); if (imagecache_set_config(args)) imagecache_save(); if (!htsmsg_get_bool(args, "clean", &b) && b) imagecache_clean(); pthread_mutex_unlock(&global_lock); *resp = htsmsg_create_map(); htsmsg_add_u32(*resp, "success", 1); return 0; }
/** * 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; }
/* * Save settings */ void timeshift_save ( void ) { htsmsg_t *m; timeshift_fixup(); m = htsmsg_create_map(); htsmsg_add_u32(m, "enabled", timeshift_enabled); htsmsg_add_u32(m, "ondemand", timeshift_ondemand); if (timeshift_path) htsmsg_add_str(m, "path", timeshift_path); htsmsg_add_u32(m, "unlimited_period", timeshift_unlimited_period); htsmsg_add_u32(m, "max_period", timeshift_max_period); htsmsg_add_u32(m, "unlimited_size", timeshift_unlimited_size); htsmsg_add_u32(m, "max_size", timeshift_max_size / 1048576); htsmsg_add_u32(m, "ram_size", timeshift_ram_size / 1048576); htsmsg_add_u32(m, "ram_only", timeshift_ram_only); hts_settings_save(m, "timeshift/config"); }
PVR_ERROR cHTSPData::DeleteTimer(const PVR_TIMERINFO &timerinfo, bool force) { XBMC->Log(LOG_DEBUG, "%s", __FUNCTION__); htsmsg_t *msg = htsmsg_create_map(); htsmsg_add_str(msg, "method", "deleteDvrEntry"); htsmsg_add_u32(msg, "id", timerinfo.index); if ((msg = ReadResult(msg)) == NULL) { XBMC->Log(LOG_DEBUG, "%s - Failed to get deleteDvrEntry", __FUNCTION__); 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; }
PVR_ERROR CHTSPData::DeleteRecording(const PVR_RECORDING &recording) { XBMC->Log(LOG_DEBUG, "%s", __FUNCTION__); htsmsg_t *msg = htsmsg_create_map(); htsmsg_add_str(msg, "method", "deleteDvrEntry"); htsmsg_add_u32(msg, "id", atoi(recording.strRecordingId)); if ((msg = ReadResult(msg)) == NULL) { XBMC->Log(LOG_DEBUG, "%s - Failed to get deleteDvrEntry", __FUNCTION__); 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 htsmsg_t * avt_GetMediaInfo_common(http_connection_t *hc, htsmsg_t *args, const char *myhost, int myport, int ext) { char str[256]; htsmsg_t *out = htsmsg_create_map(); hts_mutex_lock(&upnp_lock); if(ext) htsmsg_add_str(out, "CurrentType", current_mediaCategory()); htsmsg_add_u32(out, "NrTracks", upnp_current_total_tracks); fmttime(str, sizeof(str), upnp_current_track_duration); htsmsg_add_str(out, "MediaDuration", str); htsmsg_add_str(out, "CurrentURI", upnp_current_url ?: ""); char *meta = build_didl(myhost, myport); htsmsg_add_str(out, "CurrentURIMetaData", meta); free(meta); htsmsg_add_str(out, "PlayMedium", upnp_current_playstatus == NULL ? "NONE" : "NETWORK"); hts_mutex_unlock(&upnp_lock); return out; }
PVR_ERROR CHTSPData::RenameRecording(const PVR_RECORDING &recording, const char *strNewName) { XBMC->Log(LOG_DEBUG, "%s - id=%s", __FUNCTION__, recording.strRecordingId); htsmsg_t *msg = htsmsg_create_map(); htsmsg_add_str(msg, "method", "updateDvrEntry"); htsmsg_add_u32(msg, "id", atoi(recording.strRecordingId)); htsmsg_add_str(msg, "title", recording.strTitle); if ((msg = ReadResult(msg)) == NULL) { XBMC->Log(LOG_DEBUG, "%s - Failed to get updateDvrEntry", __FUNCTION__); 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_SAVED; }
htsmsg_t * tvh_input_stream_create_msg ( tvh_input_stream_t *st ) { htsmsg_t *m = htsmsg_create_map(); htsmsg_add_str(m, "uuid", st->uuid); if (st->input_name) htsmsg_add_str(m, "input", st->input_name); if (st->stream_name) htsmsg_add_str(m, "stream", st->stream_name); htsmsg_add_u32(m, "subs", st->subs_count); htsmsg_add_u32(m, "weight", st->max_weight); htsmsg_add_u32(m, "signal", st->stats.signal); htsmsg_add_u32(m, "signal_scale", st->stats.signal_scale); htsmsg_add_u32(m, "ber", st->stats.ber); htsmsg_add_u32(m, "snr", st->stats.snr); htsmsg_add_u32(m, "snr_scale", st->stats.snr_scale); htsmsg_add_u32(m, "unc", st->stats.unc); htsmsg_add_u32(m, "bps", st->stats.bps); htsmsg_add_u32(m, "te", st->stats.te); htsmsg_add_u32(m, "cc", st->stats.cc); htsmsg_add_u32(m, "ec_bit", st->stats.ec_bit); htsmsg_add_u32(m, "tc_bit", st->stats.tc_bit); htsmsg_add_u32(m, "ec_block", st->stats.ec_block); htsmsg_add_u32(m, "tc_block", st->stats.tc_block); return m; }
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++; } }
static htsmsg_t * htsp_reqreply(htsp_connection_t *hc, htsmsg_t *m) { void *buf; size_t len; uint32_t seq; int r; tcpcon_t *tc = hc->hc_tc; uint32_t noaccess; htsmsg_t *reply; htsp_msg_t *hm = NULL; int retry = 0; char id[100]; char *username; char *password; sha1_decl(shactx); uint8_t d[20]; if(tc == NULL) return NULL; /* Generate a sequence number for our message */ seq = atomic_add(&hc->hc_seq_generator, 1); htsmsg_add_u32(m, "seq", seq); again: snprintf(id, sizeof(id), "htsp://%s:%d", hc->hc_hostname, hc->hc_port); r = keyring_lookup(id, &username, &password, NULL, NULL, "TV client", "Access denied", (retry ? KEYRING_QUERY_USER : 0) | KEYRING_SHOW_REMEMBER_ME | KEYRING_REMEMBER_ME_SET); if(r == -1) { /* User rejected */ return NULL; } if(r == 0) { /* Got auth credentials */ htsmsg_delete_field(m, "username"); htsmsg_delete_field(m, "digest"); if(username != NULL) htsmsg_add_str(m, "username", username); if(password != NULL) { sha1_init(shactx); sha1_update(shactx, (const uint8_t *)password, strlen(password)); sha1_update(shactx, hc->hc_challenge, 32); sha1_final(shactx, d); htsmsg_add_bin(m, "digest", d, 20); } free(username); free(password); } if(htsmsg_binary_serialize(m, &buf, &len, -1) < 0) { htsmsg_destroy(m); return NULL; } if(hc->hc_is_async) { /* Async, set up a struct that will be signalled when we get a reply */ hm = malloc(sizeof(htsp_msg_t)); hm->hm_msg = NULL; hm->hm_seq = seq; hm->hm_error = 0; hts_mutex_lock(&hc->hc_rpc_mutex); TAILQ_INSERT_TAIL(&hc->hc_rpc_queue, hm, hm_link); hts_mutex_unlock(&hc->hc_rpc_mutex); } if(tc->write(tc, buf, len)) { free(buf); htsmsg_destroy(m); if(hm != NULL) { hts_mutex_lock(&hc->hc_rpc_mutex); TAILQ_REMOVE(&hc->hc_rpc_queue, hm, hm_link); hts_mutex_unlock(&hc->hc_rpc_mutex); free(hm); } return NULL; } free(buf); if(hm != NULL) { hts_mutex_lock(&hc->hc_rpc_mutex); while(1) { if(hm->hm_error != 0) { r = hm->hm_error; TAILQ_REMOVE(&hc->hc_rpc_queue, hm, hm_link); hts_mutex_unlock(&hc->hc_rpc_mutex); free(hm); htsmsg_destroy(m); return NULL; } if(hm->hm_msg != NULL) break; hts_cond_wait(&hc->hc_rpc_cond, &hc->hc_rpc_mutex); } TAILQ_REMOVE(&hc->hc_rpc_queue, hm, hm_link); hts_mutex_unlock(&hc->hc_rpc_mutex); reply = hm->hm_msg; free(hm); } else { if((reply = htsp_recv(hc)) == NULL) { htsmsg_destroy(m); return NULL; } } if(!htsmsg_get_u32(reply, "noaccess", &noaccess) && noaccess) { retry++; goto again; } htsmsg_destroy(m); /* Destroy original message */ return reply; }
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"); char buf[10]; uint32_t u32; int linkstate = 0; if(id == 0) { if(next == 0) { // No events at all prop_destroy_childs(events); return; } id = next; linkstate = 1; } for(i = 0; i < EPG_TAIL; i++) { snprintf(buf, sizeof(buf), "id%d", i); if(id != 0) { m = htsmsg_create_map(); htsmsg_add_str(m, "method", "getEvent"); htsmsg_add_u32(m, "eventId", id); if((m = htsp_reqreply(hc, m)) != NULL) { 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++; id = htsmsg_get_u32_or_default(m, "nextEventId", 0); continue; } else { id = 0; } } prop_destroy_by_name(events, buf); switch(linkstate) { case 0: prop_unlink(current_event); break; case 1: prop_unlink(next_event); break; } linkstate++; } }
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; }