MythTV  master
httpstatus.cpp
Go to the documentation of this file.
1 // Program Name: httpstatus.cpp
3 //
4 // Purpose - Html & XML status HttpServerExtension
5 //
6 // Created By : David Blain Created On : Oct. 24, 2005
7 // Modified By : Modified On:
8 //
10 
11 // POSIX headers
12 #include <unistd.h>
13 
14 // ANSI C headers
15 #include <cmath>
16 #include <cstdio>
17 #include <cstdlib>
18 
19 // Qt headers
20 #include <QtGlobal>
21 #if QT_VERSION >= QT_VERSION_CHECK(6,0,0)
22 #include <QStringConverter>
23 #endif
24 #include <QTextStream>
25 
26 // MythTV headers
27 #include "libmythbase/compat.h"
28 #include "libmythbase/exitcodes.h"
29 #include "libmythbase/mythconfig.h"
31 #include "libmythbase/mythdate.h"
32 #include "libmythbase/mythdbcon.h"
35 #include "libmythbase/mythversion.h"
36 #include "libmythtv/cardutil.h"
37 #include "libmythtv/jobqueue.h"
38 #include "libmythtv/tv.h"
39 #include "libmythtv/tv_rec.h"
40 #include "libmythupnp/upnp.h"
41 
42 // MythBackend
43 #include "autoexpire.h"
44 #include "encoderlink.h"
45 #include "httpstatus.h"
46 #include "mainserver.h"
47 #include "scheduler.h"
48 
50 //
52 
53 HttpStatus::HttpStatus( QMap<int, EncoderLink *> *tvList, Scheduler *sched,
54  AutoExpire *expirer, bool bIsMaster )
55  : HttpServerExtension( "HttpStatus" , QString())
56 {
57  m_pEncoders = tvList;
58  m_pSched = sched;
60  m_bIsMaster = bIsMaster;
61 
62  m_nPreRollSeconds = gCoreContext->GetNumSetting("RecordPreRoll", 0);
63 
64  m_pMainServer = nullptr;
65 }
66 
68 //
70 
72 {
73  if (sURI == "Status" ) return( HSM_GetStatusHTML );
74  if (sURI == "GetStatusHTML" ) return( HSM_GetStatusHTML );
75  if (sURI == "GetStatus" ) return( HSM_GetStatusXML );
76  if (sURI == "xml" ) return( HSM_GetStatusXML );
77 
78  return( HSM_Unknown );
79 }
80 
82 //
84 
86 {
87  return QStringList( "/Status" );
88 }
89 
91 //
93 
95 {
96  try
97  {
98  if (pRequest)
99  {
100  if ((pRequest->m_sBaseUrl != "/Status" ) &&
101  (pRequest->m_sResourceUrl != "/Status" ))
102  {
103  return( false );
104  }
105 
106  switch( GetMethod( pRequest->m_sMethod ))
107  {
108  case HSM_GetStatusXML : GetStatusXML ( pRequest ); return true;
109  case HSM_GetStatusHTML : GetStatusHTML ( pRequest ); return true;
110 
111  default:
112  {
113  pRequest->m_eResponseType = ResponseTypeHTML;
114  pRequest->m_nResponseStatus = 200;
115 
116  break;
117  }
118  }
119  }
120  }
121  catch( ... )
122  {
123  LOG(VB_GENERAL, LOG_ERR,
124  "HttpStatus::ProcessRequest() - Unexpected Exception");
125  }
126 
127  return( false );
128 }
129 
131 //
133 
135 {
136  QDomDocument doc( "Status" );
137 
138  // UTF-8 is the default, but good practice to specify it anyway
139  QDomProcessingInstruction encoding =
140  doc.createProcessingInstruction("xml",
141  R"(version="1.0" encoding="UTF-8")");
142  doc.appendChild(encoding);
143 
144  FillStatusXML( &doc );
145 
146  pRequest->m_eResponseType = ResponseTypeXML;
147  pRequest->m_mapRespHeaders[ "Cache-Control" ] = "no-cache=\"Ext\", max-age = 5000";
148 
149  QTextStream stream( &pRequest->m_response );
150 #if QT_VERSION < QT_VERSION_CHECK(6,0,0)
151  stream.setCodec("UTF-8"); // Otherwise locale default is used.
152 #else
153  stream.setEncoding(QStringConverter::Utf8);
154 #endif
155  stream << doc.toString();
156 }
157 
159 //
161 
163 {
164  pRequest->m_eResponseType = ResponseTypeHTML;
165  pRequest->m_mapRespHeaders[ "Cache-Control" ] = "no-cache=\"Ext\", max-age = 5000";
166 
167  QDomDocument doc( "Status" );
168 
169  FillStatusXML( &doc );
170 
171  QTextStream stream( &pRequest->m_response );
172  PrintStatus( stream, &doc );
173 }
174 
175 static QString setting_to_localtime(const char *setting)
176 {
177  QString origDateString = gCoreContext->GetSetting(setting);
178  QDateTime origDate = MythDate::fromString(origDateString);
180 }
181 
182 void HttpStatus::FillStatusXML( QDomDocument *pDoc )
183 {
184  QDateTime qdtNow = MythDate::current();
185 
186  // Add Root Node.
187 
188  QDomElement root = pDoc->createElement("Status");
189  pDoc->appendChild(root);
190 
191  root.setAttribute("date" , MythDate::toString(
193  root.setAttribute("time" ,
195  root.setAttribute("ISODate" , qdtNow.toString(Qt::ISODate) );
196  root.setAttribute("version" , MYTH_BINARY_VERSION );
197  root.setAttribute("protoVer", MYTH_PROTO_VERSION );
198 
199  // Add all encoders, if any
200 
201  QDomElement encoders = pDoc->createElement("Encoders");
202  root.appendChild(encoders);
203 
204  int numencoders = 0;
205  bool isLocal = true;
206 
207  TVRec::s_inputsLock.lockForRead();
208 
209  for (auto * elink : std::as_const(*m_pEncoders))
210  {
211  if (elink != nullptr)
212  {
213  TVState state = elink->GetState();
214  isLocal = elink->IsLocal();
215 
216  QDomElement encoder = pDoc->createElement("Encoder");
217  encoders.appendChild(encoder);
218 
219  encoder.setAttribute("id" , elink->GetInputID() );
220  encoder.setAttribute("local" , static_cast<int>(isLocal));
221  encoder.setAttribute("connected" , static_cast<int>(elink->IsConnected()));
222  encoder.setAttribute("state" , state );
223  encoder.setAttribute("sleepstatus" , elink->GetSleepStatus() );
224  //encoder.setAttribute("lowOnFreeSpace", elink->isLowOnFreeSpace());
225 
226  if (isLocal)
227  encoder.setAttribute("hostname", gCoreContext->GetHostName());
228  else
229  encoder.setAttribute("hostname", elink->GetHostName());
230 
231  encoder.setAttribute("devlabel",
232  CardUtil::GetDeviceLabel(elink->GetInputID()) );
233 
234  if (elink->IsConnected())
235  numencoders++;
236 
237  switch (state)
238  {
242  {
243  ProgramInfo *pInfo = elink->GetRecording();
244 
245  if (pInfo)
246  {
247  FillProgramInfo(pDoc, encoder, pInfo);
248  delete pInfo;
249  }
250 
251  break;
252  }
253 
254  default:
255  break;
256  }
257  }
258  }
259 
260  TVRec::s_inputsLock.unlock();
261 
262  encoders.setAttribute("count", numencoders);
263 
264  // Add upcoming shows
265 
266  QDomElement scheduled = pDoc->createElement("Scheduled");
267  root.appendChild(scheduled);
268 
269  RecList recordingList;
270 
271  if (m_pSched)
272  m_pSched->GetAllPending(recordingList);
273 
274  unsigned int iNum = 10;
275  unsigned int iNumRecordings = 0;
276 
277  auto itProg = recordingList.begin();
278  for (; (itProg != recordingList.end()) && iNumRecordings < iNum; ++itProg)
279  {
280  if (((*itProg)->GetRecordingStatus() <= RecStatus::WillRecord) &&
281  ((*itProg)->GetRecordingStartTime() >=
283  {
284  iNumRecordings++;
285  FillProgramInfo(pDoc, scheduled, *itProg);
286  }
287  }
288 
289  while (!recordingList.empty())
290  {
291  ProgramInfo *pginfo = recordingList.back();
292  delete pginfo;
293  recordingList.pop_back();
294  }
295 
296  scheduled.setAttribute("count", iNumRecordings);
297 
298  // Add known frontends
299 
300  QDomElement frontends = pDoc->createElement("Frontends");
301  root.appendChild(frontends);
302 
304  "urn:schemas-mythtv-org:service:MythFrontend:1");
305  if (fes)
306  {
307  EntryMap map;
308  fes->GetEntryMap(map);
309  fes->DecrRef();
310  fes = nullptr;
311 
312  frontends.setAttribute( "count", map.size() );
313  for (const auto & entry : std::as_const(map))
314  {
315  QDomElement fe = pDoc->createElement("Frontend");
316  frontends.appendChild(fe);
317  QUrl url(entry->m_sLocation);
318  fe.setAttribute("name", url.host());
319  fe.setAttribute("url", url.toString(QUrl::RemovePath));
320  entry->DecrRef();
321  }
322  }
323 
324  // Other backends
325 
326  QDomElement backends = pDoc->createElement("Backends");
327  root.appendChild(backends);
328 
329  int numbes = 0;
331  {
332  numbes++;
333  QString masterhost = gCoreContext->GetMasterHostName();
334  QString masterip = gCoreContext->GetMasterServerIP();
335  int masterport = gCoreContext->GetMasterServerStatusPort();
336 
337  QDomElement mbe = pDoc->createElement("Backend");
338  backends.appendChild(mbe);
339  mbe.setAttribute("type", "Master");
340  mbe.setAttribute("name", masterhost);
341  mbe.setAttribute("url" , masterip + ":" + QString::number(masterport));
342  }
343 
345  "urn:schemas-mythtv-org:device:SlaveMediaServer:1");
346  if (sbes)
347  {
348 
349  QString ipaddress = QString();
350  if (!UPnp::g_IPAddrList.isEmpty())
351  ipaddress = UPnp::g_IPAddrList.at(0).toString();
352 
353  EntryMap map;
354  sbes->GetEntryMap(map);
355  sbes->DecrRef();
356  sbes = nullptr;
357 
358  for (const auto & entry : std::as_const(map))
359  {
360  QUrl url(entry->m_sLocation);
361  if (url.host() != ipaddress)
362  {
363  numbes++;
364  QDomElement mbe = pDoc->createElement("Backend");
365  backends.appendChild(mbe);
366  mbe.setAttribute("type", "Slave");
367  mbe.setAttribute("name", url.host());
368  mbe.setAttribute("url" , url.toString(QUrl::RemovePath));
369  }
370  entry->DecrRef();
371  }
372  }
373 
374  backends.setAttribute("count", numbes);
375 
376  // Add Job Queue Entries
377 
378  QDomElement jobqueue = pDoc->createElement("JobQueue");
379  root.appendChild(jobqueue);
380 
381  QMap<int, JobQueueEntry> jobs;
382  QMap<int, JobQueueEntry>::Iterator it;
383 
387 
388  for (it = jobs.begin(); it != jobs.end(); ++it)
389  {
390  ProgramInfo pginfo((*it).chanid, (*it).recstartts);
391  if (!pginfo.GetChanID())
392  continue;
393 
394  QDomElement job = pDoc->createElement("Job");
395  jobqueue.appendChild(job);
396 
397  job.setAttribute("id" , (*it).id );
398  job.setAttribute("chanId" , (*it).chanid );
399  job.setAttribute("startTime" ,
400  (*it).recstartts.toString(Qt::ISODate));
401  job.setAttribute("startTs" , (*it).startts );
402  job.setAttribute("insertTime",
403  (*it).inserttime.toString(Qt::ISODate));
404  job.setAttribute("type" , (*it).type );
405  job.setAttribute("cmds" , (*it).cmds );
406  job.setAttribute("flags" , (*it).flags );
407  job.setAttribute("status" , (*it).status );
408  job.setAttribute("statusTime",
409  (*it).statustime.toString(Qt::ISODate));
410  job.setAttribute("schedTime" ,
411  (*it).schedruntime.toString(Qt::ISODate));
412  job.setAttribute("args" , (*it).args );
413 
414  if ((*it).hostname.isEmpty())
415  job.setAttribute("hostname", QObject::tr("master"));
416  else
417  job.setAttribute("hostname",(*it).hostname);
418 
419  QDomText textNode = pDoc->createTextNode((*it).comment);
420  job.appendChild(textNode);
421 
422  FillProgramInfo(pDoc, job, &pginfo);
423  }
424 
425  jobqueue.setAttribute( "count", jobs.size() );
426 
427  // Add Machine information
428 
429  QDomElement mInfo = pDoc->createElement("MachineInfo");
430  QDomElement storage = pDoc->createElement("Storage" );
431  QDomElement load = pDoc->createElement("Load" );
432  QDomElement guide = pDoc->createElement("Guide" );
433 
434  root.appendChild (mInfo );
435  mInfo.appendChild(storage);
436  mInfo.appendChild(load );
437  mInfo.appendChild(guide );
438 
439  // drive space ---------------------
440 
441  QStringList strlist;
442  QString hostname;
443  QString directory;
444  QString isLocalstr;
445  QString fsID;
446 
447  if (m_pMainServer)
449 
450  QDomElement total;
451 
452  // Make a temporary list to hold the per-filesystem elements so that the
453  // total is always the first element.
454  QList<QDomElement> fsXML;
455  QStringList::const_iterator sit = strlist.cbegin();
456  while (sit != strlist.cend())
457  {
458  hostname = *(sit++);
459  directory = *(sit++);
460  isLocalstr = *(sit++);
461  fsID = *(sit++);
462  ++sit; // ignore dirID
463  ++sit; // ignore blocksize
464  long long iTotal = (*(sit++)).toLongLong();
465  long long iUsed = (*(sit++)).toLongLong();;
466  long long iAvail = iTotal - iUsed;
467 
468  if (fsID == "-2")
469  fsID = "total";
470 
471  QDomElement group = pDoc->createElement("Group");
472 
473  group.setAttribute("id" , fsID );
474  group.setAttribute("total", (int)(iTotal>>10) );
475  group.setAttribute("used" , (int)(iUsed>>10) );
476  group.setAttribute("free" , (int)(iAvail>>10) );
477  group.setAttribute("dir" , directory );
478 
479  if (fsID == "total")
480  {
481  long long iLiveTV = -1;
482  long long iDeleted = -1;
483  long long iExpirable = -1;
484  MSqlQuery query(MSqlQuery::InitCon());
485  query.prepare("SELECT SUM(filesize) FROM recorded "
486  " WHERE recgroup = :RECGROUP;");
487 
488  query.bindValue(":RECGROUP", "LiveTV");
489  if (query.exec() && query.next())
490  {
491  iLiveTV = query.value(0).toLongLong();
492  }
493  query.bindValue(":RECGROUP", "Deleted");
494  if (query.exec() && query.next())
495  {
496  iDeleted = query.value(0).toLongLong();
497  }
498  query.prepare("SELECT SUM(filesize) FROM recorded "
499  " WHERE autoexpire = 1 "
500  " AND recgroup NOT IN ('LiveTV', 'Deleted');");
501  if (query.exec() && query.next())
502  {
503  iExpirable = query.value(0).toLongLong();
504  }
505  group.setAttribute("livetv", (int)(iLiveTV>>20) );
506  group.setAttribute("deleted", (int)(iDeleted>>20) );
507  group.setAttribute("expirable", (int)(iExpirable>>20) );
508  total = group;
509  }
510  else
511  fsXML << group;
512  }
513 
514  storage.appendChild(total);
515  int num_elements = fsXML.size();
516  for (int fs_index = 0; fs_index < num_elements; fs_index++)
517  {
518  storage.appendChild(fsXML[fs_index]);
519  }
520 
521  // load average ---------------------
522 
523 #ifdef Q_OS_ANDROID
524  load.setAttribute("avg1", 0);
525  load.setAttribute("avg2", 1);
526  load.setAttribute("avg3", 2);
527 #else
528  loadArray rgdAverages = getLoadAvgs();
529  if (rgdAverages[0] != -1)
530  {
531  load.setAttribute("avg1", rgdAverages[0]);
532  load.setAttribute("avg2", rgdAverages[1]);
533  load.setAttribute("avg3", rgdAverages[2]);
534  }
535 #endif
536 
537  // Guide Data ---------------------
538 
539  QDateTime GuideDataThrough;
540 
541  MSqlQuery query(MSqlQuery::InitCon());
542  query.prepare("SELECT MAX(endtime) FROM program WHERE manualid = 0;");
543 
544  if (query.exec() && query.next())
545  {
546  GuideDataThrough = MythDate::fromString(query.value(0).toString());
547  }
548 
549  guide.setAttribute("start",
550  setting_to_localtime("mythfilldatabaseLastRunStart"));
551  guide.setAttribute("end",
552  setting_to_localtime("mythfilldatabaseLastRunEnd"));
553  guide.setAttribute("status",
554  gCoreContext->GetSetting("mythfilldatabaseLastRunStatus"));
555  if (gCoreContext->GetBoolSetting("MythFillGrabberSuggestsTime", false))
556  {
557  guide.setAttribute("next",
558  gCoreContext->GetSetting("MythFillSuggestedRunTime"));
559  }
560 
561  if (!GuideDataThrough.isNull())
562  {
563  guide.setAttribute("guideThru",
564  GuideDataThrough.toString(Qt::ISODate));
565  guide.setAttribute("guideDays", qdtNow.daysTo(GuideDataThrough));
566  }
567 
568  // Add Miscellaneous information
569 
570  QString info_script = gCoreContext->GetSetting("MiscStatusScript");
571  if ((!info_script.isEmpty()) && (info_script != "none"))
572  {
573  QDomElement misc = pDoc->createElement("Miscellaneous");
574  root.appendChild(misc);
575 
576  uint flags = kMSRunShell | kMSStdOut;
577  MythSystemLegacy ms(info_script, flags);
578  ms.Run(10s);
579  if (ms.Wait() != GENERIC_EXIT_OK)
580  {
581  LOG(VB_GENERAL, LOG_ERR,
582  QString("Error running miscellaneous "
583  "status information script: %1").arg(info_script));
584  return;
585  }
586 
587  QByteArray input = ms.ReadAll();
588 
589  QStringList output = QString(input).split('\n',
590  Qt::SkipEmptyParts);
591  for (const auto & line : std::as_const(output))
592  {
593  QDomElement info = pDoc->createElement("Information");
594 
595  QStringList list = line.split("[]:[]");
596  unsigned int size = list.size();
597  unsigned int hasAttributes = 0;
598 
599  if ((size > 0) && (!list[0].isEmpty()))
600  {
601  info.setAttribute("display", list[0]);
602  hasAttributes++;
603  }
604  if ((size > 1) && (!list[1].isEmpty()))
605  {
606  info.setAttribute("name", list[1]);
607  hasAttributes++;
608  }
609  if ((size > 2) && (!list[2].isEmpty()))
610  {
611  info.setAttribute("value", list[2]);
612  hasAttributes++;
613  }
614 
615  if (hasAttributes > 0)
616  misc.appendChild(info);
617  }
618  }
619 }
620 
622 //
624 
625 void HttpStatus::PrintStatus( QTextStream &os, QDomDocument *pDoc )
626 {
627 #if QT_VERSION < QT_VERSION_CHECK(6,0,0)
628  os.setCodec("UTF-8");
629 #else
630  os.setEncoding(QStringConverter::Utf8);
631 #endif
632 
633  QDateTime qdtNow = MythDate::current();
634 
635  QDomElement docElem = pDoc->documentElement();
636 
637  os << "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" "
638  << "\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\r\n"
639  << "<html xmlns=\"http://www.w3.org/1999/xhtml\""
640  << " xml:lang=\"en\" lang=\"en\">\r\n"
641  << "<head>\r\n"
642  << " <meta http-equiv=\"Content-Type\""
643  << "content=\"text/html; charset=UTF-8\" />\r\n"
644  << " <link rel=\"stylesheet\" href=\"/css/Status.css\" type=\"text/css\">\r\n"
645  << " <title>MythTV Status - "
646  << docElem.attribute( "date", MythDate::toString(qdtNow, MythDate::kDateShort) )
647  << " "
648  << docElem.attribute( "time", MythDate::toString(qdtNow, MythDate::kTime) ) << " - "
649  << docElem.attribute( "version", MYTH_BINARY_VERSION ) << "</title>\r\n"
650  << "</head>\r\n"
651  << "<body bgcolor=\"#fff\">\r\n"
652  << "<div class=\"status\">\r\n"
653  << " <h1 class=\"status\">MythTV Status</h1>\r\n";
654 
655  // encoder information ---------------------
656 
657  QDomNode node = docElem.namedItem( "Encoders" );
658 
659  if (!node.isNull())
660  PrintEncoderStatus( os, node.toElement() );
661 
662  // upcoming shows --------------------------
663 
664  node = docElem.namedItem( "Scheduled" );
665 
666  if (!node.isNull())
667  PrintScheduled( os, node.toElement());
668 
669  // Frontends
670 
671  node = docElem.namedItem( "Frontends" );
672 
673  if (!node.isNull())
674  PrintFrontends (os, node.toElement());
675 
676  // Backends
677 
678  node = docElem.namedItem( "Backends" );
679 
680  if (!node.isNull())
681  PrintBackends (os, node.toElement());
682 
683  // Job Queue Entries -----------------------
684 
685  node = docElem.namedItem( "JobQueue" );
686 
687  if (!node.isNull())
688  PrintJobQueue( os, node.toElement());
689 
690  // Machine information ---------------------
691 
692  node = docElem.namedItem( "MachineInfo" );
693 
694  if (!node.isNull())
695  PrintMachineInfo( os, node.toElement());
696 
697  // Miscellaneous information ---------------
698 
699  node = docElem.namedItem( "Miscellaneous" );
700 
701  if (!node.isNull())
702  PrintMiscellaneousInfo( os, node.toElement());
703 
704  os << "\r\n</div>\r\n</body>\r\n</html>\r\n";
705 
706 }
707 
709 //
711 
712 int HttpStatus::PrintEncoderStatus( QTextStream &os, const QDomElement& encoders )
713 {
714  int nNumEncoders = 0;
715 
716  if (encoders.isNull())
717  return 0;
718 
719  os << " <div class=\"content\">\r\n"
720  << " <h2 class=\"status\">Encoder Status</h2>\r\n";
721 
722  QDomNode node = encoders.firstChild();
723 
724  while (!node.isNull())
725  {
726  QDomElement e = node.toElement();
727 
728  if (!e.isNull())
729  {
730  if (e.tagName() == "Encoder")
731  {
732  QString sIsLocal = (e.attribute( "local" , "remote" )== "1")
733  ? "local" : "remote";
734  QString sCardId = e.attribute( "id" , "0" );
735  QString sHostName = e.attribute( "hostname" , "Unknown");
736  bool bConnected= static_cast<bool>(e.attribute( "connected", "0" ).toInt());
737 
738  bool bIsLowOnFreeSpace=static_cast<bool>(e.attribute( "lowOnFreeSpace", "0").toInt());
739 
740  QString sDevlabel = e.attribute( "devlabel", "[ UNKNOWN ]");
741 
742  os << " Encoder " << sCardId << " " << sDevlabel
743  << " is " << sIsLocal << " on " << sHostName;
744 
745  if ((sIsLocal == "remote") && !bConnected)
746  {
747  SleepStatus sleepStatus =
748  (SleepStatus) e.attribute("sleepstatus",
749  QString::number(sStatus_Undefined)).toInt();
750 
751  if (sleepStatus == sStatus_Asleep)
752  os << " (currently asleep).<br />";
753  else
754  os << " (currently not connected).<br />";
755 
756  node = node.nextSibling();
757  continue;
758  }
759 
760  nNumEncoders++;
761 
762  TVState encState = (TVState) e.attribute( "state", "0").toInt();
763 
764  switch( encState )
765  {
767  os << " and is watching Live TV";
768  break;
769 
772  os << " and is recording";
773  break;
774 
775  default:
776  os << " and is not recording.";
777  break;
778  }
779 
780  // Display first Program Element listed under the encoder
781 
782  QDomNode tmpNode = e.namedItem( "Program" );
783 
784  if (!tmpNode.isNull())
785  {
786  QDomElement program = tmpNode.toElement();
787 
788  if (!program.isNull())
789  {
790  os << " '" << program.attribute( "title", "Unknown" ) << "'";
791 
792  // Get Channel information
793 
794  tmpNode = program.namedItem( "Channel" );
795 
796  if (!tmpNode.isNull())
797  {
798  QDomElement channel = tmpNode.toElement();
799 
800  if (!channel.isNull())
801  os << " on "
802  << channel.attribute( "callSign", "unknown" );
803  }
804 
805  // Get Recording Information (if any)
806 
807  tmpNode = program.namedItem( "Recording" );
808 
809  if (!tmpNode.isNull())
810  {
811  QDomElement recording = tmpNode.toElement();
812 
813  if (!recording.isNull())
814  {
815  QDateTime endTs = MythDate::fromString(
816  recording.attribute( "recEndTs", "" ));
817 
818  os << ". This recording ";
819  if (endTs < MythDate::current())
820  os << "was ";
821  else
822  os << "is ";
823 
824  os << "scheduled to end at "
825  << MythDate::toString(endTs,
827  }
828  }
829  }
830 
831  os << ".";
832  }
833 
834  if (bIsLowOnFreeSpace)
835  {
836  os << " <strong>WARNING</strong>:"
837  << " This backend is low on free disk space!";
838  }
839 
840  os << "<br />\r\n";
841  }
842  }
843 
844  node = node.nextSibling();
845  }
846 
847  os << " </div>\r\n\r\n";
848 
849  return( nNumEncoders );
850 }
851 
853 //
855 
856 int HttpStatus::PrintScheduled( QTextStream &os, const QDomElement& scheduled )
857 {
858  QDateTime qdtNow = MythDate::current();
859 
860  if (scheduled.isNull())
861  return( 0 );
862 
863  int nNumRecordings= scheduled.attribute( "count", "0" ).toInt();
864 
865  os << " <div class=\"content\">\r\n"
866  << " <h2 class=\"status\">Schedule</h2>\r\n";
867 
868  if (nNumRecordings == 0)
869  {
870  os << " There are no shows scheduled for recording.\r\n"
871  << " </div>\r\n";
872  return( 0 );
873  }
874 
875  os << " The next " << nNumRecordings << " show" << (nNumRecordings == 1 ? "" : "s" )
876  << " that " << (nNumRecordings == 1 ? "is" : "are")
877  << " scheduled for recording:\r\n";
878 
879  os << " <div class=\"schedule\">\r\n";
880 
881  // Iterate through all scheduled programs
882 
883  QDomNode node = scheduled.firstChild();
884 
885  while (!node.isNull())
886  {
887  QDomElement e = node.toElement();
888 
889  if (!e.isNull())
890  {
891  QDomNode recNode = e.namedItem( "Recording" );
892  QDomNode chanNode = e.namedItem( "Channel" );
893 
894  if ((e.tagName() == "Program") && !recNode.isNull() &&
895  !chanNode.isNull())
896  {
897  QDomElement r = recNode.toElement();
898  QDomElement c = chanNode.toElement();
899 
900  QString sTitle = e.attribute( "title" , "" );
901  QString sSubTitle = e.attribute( "subTitle", "" );
902  QDateTime airDate = MythDate::fromString( e.attribute( "airdate" ,"" ));
903  QDateTime startTs = MythDate::fromString( e.attribute( "startTime" ,"" ));
904  QDateTime endTs = MythDate::fromString( e.attribute( "endTime" ,"" ));
905  QDateTime recStartTs = MythDate::fromString( r.attribute( "recStartTs","" ));
906 // QDateTime recEndTs = MythDate::fromString( r.attribute( "recEndTs" ,"" ));
907  int nPreRollSecs = r.attribute( "preRollSeconds", "0" ).toInt();
908  int nEncoderId = r.attribute( "encoderId" , "0" ).toInt();
909  QString sProfile = r.attribute( "recProfile" , "" );
910  QString sChanName = c.attribute( "channelName" , "" );
911  QString sDesc = "";
912 
913  QDomText text = e.firstChild().toText();
914  if (!text.isNull())
915  sDesc = text.nodeValue();
916 
917  // Build Time to recording start.
918 
919  int nTotalSecs = qdtNow.secsTo( recStartTs ) - nPreRollSecs;
920 
921  //since we're not displaying seconds
922 
923  nTotalSecs -= 60;
924 
925  int nTotalDays = nTotalSecs / 86400;
926  int nTotalHours = (nTotalSecs / 3600)
927  - (nTotalDays * 24);
928  int nTotalMins = (nTotalSecs / 60) % 60;
929 
930  QString sTimeToStart = "in";
931 
932  sTimeToStart += QObject::tr(" %n day(s),", "", nTotalDays );
933  sTimeToStart += QObject::tr(" %n hour(s) and", "", nTotalHours);
934  sTimeToStart += QObject::tr(" %n minute(s)", "", nTotalMins);
935 
936  if ( nTotalHours == 0 && nTotalMins == 0)
937  sTimeToStart = QObject::tr("within one minute", "Recording starting");
938 
939  if ( nTotalSecs < 0)
940  sTimeToStart = QObject::tr("soon", "Recording starting");
941 
942  // Output HTML
943 
944  os << " <a href=\"#\">";
945  os << MythDate::toString(recStartTs.addSecs(-nPreRollSecs),
947  MythDate::kSimplify) << " "
948  << MythDate::toString(recStartTs.addSecs(-nPreRollSecs),
949  MythDate::kTime) << " - ";
950 
951  if (nEncoderId > 0)
952  os << "Encoder " << nEncoderId << " - ";
953 
954  os << sChanName << " - " << sTitle << "<br />"
955  << "<span><strong>" << sTitle << "</strong> ("
956  << MythDate::toString(startTs, MythDate::kTime) << "-"
957  << MythDate::toString(endTs, MythDate::kTime) << ")<br />";
958 
959  if ( !sSubTitle.isEmpty())
960  os << "<em>" << sSubTitle << "</em><br /><br />";
961 
962  if ( airDate.isValid())
963  {
964  os << "Orig. Airdate: "
967  << "<br /><br />";
968  }
969 
970  os << sDesc << "<br /><br />"
971  << "This recording will start " << sTimeToStart
972  << " using encoder " << nEncoderId << " with the '"
973  << sProfile << "' profile.</span></a><hr />\r\n";
974  }
975  }
976 
977  node = node.nextSibling();
978  }
979  os << " </div>\r\n";
980  os << " </div>\r\n\r\n";
981 
982  return( nNumRecordings );
983 }
984 
986 //
988 
989 int HttpStatus::PrintFrontends( QTextStream &os, const QDomElement& frontends )
990 {
991  if (frontends.isNull())
992  return( 0 );
993 
994  int nNumFES= frontends.attribute( "count", "0" ).toInt();
995 
996  if (nNumFES < 1)
997  return( 0 );
998 
999 
1000  os << " <div class=\"content\">\r\n"
1001  << " <h2 class=\"status\">Frontends</h2>\r\n";
1002 
1003  QDomNode node = frontends.firstChild();
1004  while (!node.isNull())
1005  {
1006  QDomElement e = node.toElement();
1007 
1008  if (!e.isNull())
1009  {
1010  QString name = e.attribute( "name" , "" );
1011  QString url = e.attribute( "url" , "" );
1012  os << name << "&nbsp(<a href=\"" << url << "\">Status page</a>)<br />";
1013  }
1014 
1015  node = node.nextSibling();
1016  }
1017 
1018  os << " </div>\r\n\r\n";
1019 
1020  return nNumFES;
1021 }
1022 
1024 //
1026 
1027 int HttpStatus::PrintBackends( QTextStream &os, const QDomElement& backends )
1028 {
1029  if (backends.isNull())
1030  return( 0 );
1031 
1032  int nNumBES= backends.attribute( "count", "0" ).toInt();
1033 
1034  if (nNumBES < 1)
1035  return( 0 );
1036 
1037 
1038  os << " <div class=\"content\">\r\n"
1039  << " <h2 class=\"status\">Other Backends</h2>\r\n";
1040 
1041  QDomNode node = backends.firstChild();
1042  while (!node.isNull())
1043  {
1044  QDomElement e = node.toElement();
1045 
1046  if (!e.isNull())
1047  {
1048  QString type = e.attribute( "type", "" );
1049  QString name = e.attribute( "name" , "" );
1050  QString url = e.attribute( "url" , "" );
1051  os << type << ": " << name << "&nbsp(<a href=\"" << url << "\">Status page</a>)<br />";
1052  }
1053 
1054  node = node.nextSibling();
1055  }
1056 
1057  os << " </div>\r\n\r\n";
1058 
1059  return nNumBES;
1060 }
1061 
1063 //
1065 
1066 int HttpStatus::PrintJobQueue( QTextStream &os, const QDomElement& jobs )
1067 {
1068  if (jobs.isNull())
1069  return( 0 );
1070 
1071  int nNumJobs= jobs.attribute( "count", "0" ).toInt();
1072 
1073  os << " <div class=\"content\">\r\n"
1074  << " <h2 class=\"status\">Job Queue</h2>\r\n";
1075 
1076  if (nNumJobs != 0)
1077  {
1078  QString statusColor;
1079  QString jobColor;
1080 
1081  os << " Jobs currently in Queue or recently ended:\r\n<br />"
1082  << " <div class=\"schedule\">\r\n";
1083 
1084 
1085  QDomNode node = jobs.firstChild();
1086 
1087  while (!node.isNull())
1088  {
1089  QDomElement e = node.toElement();
1090 
1091  if (!e.isNull())
1092  {
1093  QDomNode progNode = e.namedItem( "Program" );
1094 
1095  if ((e.tagName() == "Job") && !progNode.isNull() )
1096  {
1097  QDomElement p = progNode.toElement();
1098 
1099  QDomNode recNode = p.namedItem( "Recording" );
1100  QDomNode chanNode = p.namedItem( "Channel" );
1101 
1102  QDomElement r = recNode.toElement();
1103  QDomElement c = chanNode.toElement();
1104 
1105  int nType = e.attribute( "type" , "0" ).toInt();
1106  int nStatus = e.attribute( "status", "0" ).toInt();
1107 
1108  switch( nStatus )
1109  {
1110  case JOB_ABORTED:
1111  statusColor = " class=\"jobaborted\"";
1112  jobColor = "";
1113  break;
1114 
1115  case JOB_ERRORED:
1116  statusColor = " class=\"joberrored\"";
1117  jobColor = " class=\"joberrored\"";
1118  break;
1119 
1120  case JOB_FINISHED:
1121  statusColor = " class=\"jobfinished\"";
1122  jobColor = " class=\"jobfinished\"";
1123  break;
1124 
1125  case JOB_RUNNING:
1126  statusColor = " class=\"jobrunning\"";
1127  jobColor = " class=\"jobrunning\"";
1128  break;
1129 
1130  default:
1131  statusColor = " class=\"jobqueued\"";
1132  jobColor = " class=\"jobqueued\"";
1133  break;
1134  }
1135 
1136  QString sTitle = p.attribute( "title" , "" ); //.replace("\"", "&quot;");
1137  QString sSubTitle = p.attribute( "subTitle", "" );
1138  QDateTime startTs = MythDate::fromString( p.attribute( "startTime" ,"" ));
1139  QDateTime endTs = MythDate::fromString( p.attribute( "endTime" ,"" ));
1140  QDateTime recStartTs = MythDate::fromString( r.attribute( "recStartTs","" ));
1141  QDateTime statusTime = MythDate::fromString( e.attribute( "statusTime","" ));
1142  QDateTime schedRunTime = MythDate::fromString( e.attribute( "schedTime","" ));
1143  QString sHostname = e.attribute( "hostname", "master" );
1144  QString sComment = "";
1145 
1146  QDomText text = e.firstChild().toText();
1147  if (!text.isNull())
1148  sComment = text.nodeValue();
1149 
1150  os << "<a href=\"javascript:void(0)\">"
1151  << MythDate::toString(recStartTs, MythDate::kDateFull |
1153  << " - "
1154  << sTitle << " - <font" << jobColor << ">"
1155  << JobQueue::JobText( nType ) << "</font><br />"
1156  << "<span><strong>" << sTitle << "</strong> ("
1157  << MythDate::toString(startTs, MythDate::kTime) << "-"
1158  << MythDate::toString(endTs, MythDate::kTime) << ")<br />";
1159 
1160  if (!sSubTitle.isEmpty())
1161  os << "<em>" << sSubTitle << "</em><br /><br />";
1162 
1163  os << "Job: " << JobQueue::JobText( nType ) << "<br />";
1164 
1165  if (schedRunTime > MythDate::current())
1166  {
1167  os << "Scheduled Run Time: "
1168  << MythDate::toString(schedRunTime,
1171  << "<br />";
1172  }
1173 
1174  os << "Status: <font" << statusColor << ">"
1175  << JobQueue::StatusText( nStatus )
1176  << "</font><br />"
1177  << "Status Time: "
1178  << MythDate::toString(statusTime, MythDate::kDateFull |
1180  << "<br />";
1181 
1182  if ( nStatus != JOB_QUEUED)
1183  os << "Host: " << sHostname << "<br />";
1184 
1185  if (!sComment.isEmpty())
1186  os << "<br />Comments:<br />" << sComment << "<br />";
1187 
1188  os << "</span></a><hr />\r\n";
1189  }
1190  }
1191 
1192  node = node.nextSibling();
1193  }
1194  os << " </div>\r\n";
1195  }
1196  else
1197  os << " Job Queue is currently empty.\r\n\r\n";
1198 
1199  os << " </div>\r\n\r\n ";
1200 
1201  return( nNumJobs );
1202 
1203 }
1204 
1206 //
1208 
1209 int HttpStatus::PrintMachineInfo( QTextStream &os, const QDomElement& info )
1210 {
1211  QString sRep;
1212 
1213  if (info.isNull())
1214  return( 0 );
1215 
1216  os << "<div class=\"content\">\r\n"
1217  << " <h2 class=\"status\">Machine Information</h2>\r\n";
1218 
1219  // load average ---------------------
1220 
1221  QDomNode node = info.namedItem( "Load" );
1222 
1223  if (!node.isNull())
1224  {
1225  QDomElement e = node.toElement();
1226 
1227  if (!e.isNull())
1228  {
1229  double dAvg1 = e.attribute( "avg1" , "0" ).toDouble();
1230  double dAvg2 = e.attribute( "avg2" , "0" ).toDouble();
1231  double dAvg3 = e.attribute( "avg3" , "0" ).toDouble();
1232 
1233  os << " <div class=\"loadstatus\">\r\n"
1234  << " This machine's load average:"
1235  << "\r\n <ul>\r\n <li>"
1236  << "1 Minute: " << dAvg1 << "</li>\r\n"
1237  << " <li>5 Minutes: " << dAvg2 << "</li>\r\n"
1238  << " <li>15 Minutes: " << dAvg3
1239  << "</li>\r\n </ul>\r\n"
1240  << " </div>\r\n";
1241  }
1242  }
1243 
1244  // local drive space ---------------------
1245  node = info.namedItem( "Storage" );
1246  QDomElement storage = node.toElement();
1247  node = storage.firstChild();
1248 
1249  // Loop once until we find id == "total". This should be first, but a loop
1250  // separate from the per-filesystem details loop ensures total is first,
1251  // regardless.
1252  while (!node.isNull())
1253  {
1254  QDomElement g = node.toElement();
1255 
1256  if (!g.isNull() && g.tagName() == "Group")
1257  {
1258  QString id = g.attribute("id", "" );
1259 
1260  if (id == "total")
1261  {
1262  int nFree = g.attribute("free" , "0" ).toInt();
1263  int nTotal = g.attribute("total", "0" ).toInt();
1264  int nUsed = g.attribute("used" , "0" ).toInt();
1265  int nLiveTV = g.attribute("livetv" , "0" ).toInt();
1266  int nDeleted = g.attribute("deleted", "0" ).toInt();
1267  int nExpirable = g.attribute("expirable" , "0" ).toInt();
1268  QString nDir = g.attribute("dir" , "" );
1269 
1270  nDir.replace(",", ", ");
1271 
1272  os << " Disk Usage Summary:<br />\r\n";
1273  os << " <ul>\r\n";
1274 
1275  os << " <li>Total Disk Space:\r\n"
1276  << " <ul>\r\n";
1277 
1278  os << " <li>Total Space: ";
1279  sRep = QString("%L1").arg(nTotal) + " MB";
1280  os << sRep << "</li>\r\n";
1281 
1282  os << " <li>Space Used: ";
1283  sRep = QString("%L1").arg(nUsed) + " MB";
1284  os << sRep << "</li>\r\n";
1285 
1286  os << " <li>Space Free: ";
1287  sRep = QString("%L1").arg(nFree) + " MB";
1288  os << sRep << "</li>\r\n";
1289 
1290  if ((nLiveTV + nDeleted + nExpirable) > 0)
1291  {
1292  os << " <li>Space Available "
1293  "After Auto-expire: ";
1294  sRep = QString("%L1").arg(nUsed) + " MB";
1295  sRep = QString("%L1").arg(nFree + nLiveTV +
1296  nDeleted + nExpirable) + " MB";
1297  os << sRep << "\r\n";
1298  os << " <ul>\r\n";
1299  os << " <li>Space Used by LiveTV: ";
1300  sRep = QString("%L1").arg(nLiveTV) + " MB";
1301  os << sRep << "</li>\r\n";
1302  os << " <li>Space Used by "
1303  "Deleted Recordings: ";
1304  sRep = QString("%L1").arg(nDeleted) + " MB";
1305  os << sRep << "</li>\r\n";
1306  os << " <li>Space Used by "
1307  "Auto-expirable Recordings: ";
1308  sRep = QString("%L1").arg(nExpirable) + " MB";
1309  os << sRep << "</li>\r\n";
1310  os << " </ul>\r\n";
1311  os << " </li>\r\n";
1312  }
1313 
1314  os << " </ul>\r\n"
1315  << " </li>\r\n";
1316 
1317  os << " </ul>\r\n";
1318  break;
1319  }
1320  }
1321 
1322  node = node.nextSibling();
1323  }
1324 
1325  // Loop again to handle per-filesystem details.
1326  node = storage.firstChild();
1327 
1328  os << " Disk Usage Details:<br />\r\n";
1329  os << " <ul>\r\n";
1330 
1331 
1332  while (!node.isNull())
1333  {
1334  QDomElement g = node.toElement();
1335 
1336  if (!g.isNull() && g.tagName() == "Group")
1337  {
1338  int nFree = g.attribute("free" , "0" ).toInt();
1339  int nTotal = g.attribute("total", "0" ).toInt();
1340  int nUsed = g.attribute("used" , "0" ).toInt();
1341  QString nDir = g.attribute("dir" , "" );
1342  QString id = g.attribute("id" , "" );
1343 
1344  nDir.replace(",", ", ");
1345 
1346 
1347  if (id != "total")
1348  {
1349 
1350  os << " <li>MythTV Drive #" << id << ":"
1351  << "\r\n"
1352  << " <ul>\r\n";
1353 
1354  if (nDir.contains(','))
1355  os << " <li>Directories: ";
1356  else
1357  os << " <li>Directory: ";
1358 
1359  os << nDir << "</li>\r\n";
1360 
1361  os << " <li>Total Space: ";
1362  sRep = QString("%L1").arg(nTotal) + " MB";
1363  os << sRep << "</li>\r\n";
1364 
1365  os << " <li>Space Used: ";
1366  sRep = QString("%L1").arg(nUsed) + " MB";
1367  os << sRep << "</li>\r\n";
1368 
1369  os << " <li>Space Free: ";
1370  sRep = QString("%L1").arg(nFree) + " MB";
1371  os << sRep << "</li>\r\n";
1372 
1373  os << " </ul>\r\n"
1374  << " </li>\r\n";
1375  }
1376 
1377  }
1378 
1379  node = node.nextSibling();
1380  }
1381 
1382  os << " </ul>\r\n";
1383 
1384  // Guide Info ---------------------
1385 
1386  node = info.namedItem( "Guide" );
1387 
1388  if (!node.isNull())
1389  {
1390  QDomElement e = node.toElement();
1391 
1392  if (!e.isNull())
1393  {
1394  int nDays = e.attribute( "guideDays", "0" ).toInt();
1395  QString sStart = e.attribute( "start" , "" );
1396  QString sEnd = e.attribute( "end" , "" );
1397  QString sStatus = e.attribute( "status" , "" );
1398  QDateTime next = MythDate::fromString( e.attribute( "next" , "" ));
1399  QString sNext = next.isNull() ? "" :
1401  QString sMsg = "";
1402 
1403  QDateTime thru = MythDate::fromString( e.attribute( "guideThru", "" ));
1404 
1405  QDomText text = e.firstChild().toText();
1406 
1407  QString mfdblrs =
1408  gCoreContext->GetSetting("mythfilldatabaseLastRunStart");
1409  QDateTime lastrunstart = MythDate::fromString(mfdblrs);
1410 
1411  if (!text.isNull())
1412  sMsg = text.nodeValue();
1413 
1414  os << " Last mythfilldatabase run started on " << sStart
1415  << " and ";
1416 
1417  if (sEnd < sStart)
1418  os << "is ";
1419  else
1420  os << "ended on " << sEnd << ". ";
1421 
1422  os << sStatus << "<br />\r\n";
1423 
1424  if (!next.isNull() && next >= lastrunstart)
1425  {
1426  os << " Suggested next mythfilldatabase run: "
1427  << sNext << ".<br />\r\n";
1428  }
1429 
1430  if (!thru.isNull())
1431  {
1432  os << " There's guide data until "
1434 
1435  if (nDays > 0)
1436  os << " " << QObject::tr("(%n day(s))", "", nDays);
1437 
1438  os << ".";
1439 
1440  if (nDays <= 3)
1441  os << " <strong>WARNING</strong>: is mythfilldatabase running?";
1442  }
1443  else
1444  os << " There's <strong>no guide data</strong> available! "
1445  << "Have you run mythfilldatabase?";
1446  }
1447  }
1448  os << "\r\n </div>\r\n";
1449 
1450  return( 1 );
1451 }
1452 
1453 int HttpStatus::PrintMiscellaneousInfo( QTextStream &os, const QDomElement& info )
1454 {
1455  if (info.isNull())
1456  return( 0 );
1457 
1458  // Miscellaneous information
1459 
1460  QDomNodeList nodes = info.elementsByTagName("Information");
1461  uint count = nodes.count();
1462  if (count > 0)
1463  {
1464  QString display;
1465  QString linebreak;
1466  //QString name, value;
1467  os << "<div class=\"content\">\r\n"
1468  << " <h2 class=\"status\">Miscellaneous</h2>\r\n";
1469  for (unsigned int i = 0; i < count; i++)
1470  {
1471  QDomNode node = nodes.item(i);
1472  if (node.isNull())
1473  continue;
1474 
1475  QDomElement e = node.toElement();
1476  if (e.isNull())
1477  continue;
1478 
1479  display = e.attribute("display", "");
1480  //name = e.attribute("name", "");
1481  //value = e.attribute("value", "");
1482 
1483  if (display.isEmpty())
1484  continue;
1485 
1486  // Only include HTML line break if display value doesn't already
1487  // contain breaks.
1488  if (display.contains("<p>", Qt::CaseInsensitive) ||
1489  display.contains("<br", Qt::CaseInsensitive))
1490  {
1491  // matches <BR> or <br /
1492  linebreak = "\r\n";
1493  }
1494  else
1495  linebreak = "<br />\r\n";
1496 
1497  os << " " << display << linebreak;
1498  }
1499  os << "</div>\r\n";
1500  }
1501 
1502  return( 1 );
1503 }
1504 
1505 void HttpStatus::FillProgramInfo(QDomDocument *pDoc,
1506  QDomNode &node,
1507  ProgramInfo *pInfo,
1508  bool bIncChannel /* = true */,
1509  bool bDetails /* = true */)
1510 {
1511  if ((pDoc == nullptr) || (pInfo == nullptr))
1512  return;
1513 
1514  // Build Program Element
1515 
1516  QDomElement program = pDoc->createElement( "Program" );
1517  node.appendChild( program );
1518 
1519  program.setAttribute( "startTime" ,
1521  program.setAttribute( "endTime" , pInfo->GetScheduledEndTime(MythDate::ISODate));
1522  program.setAttribute( "title" , pInfo->GetTitle() );
1523  program.setAttribute( "subTitle" , pInfo->GetSubtitle());
1524  program.setAttribute( "category" , pInfo->GetCategory());
1525  program.setAttribute( "catType" , pInfo->GetCategoryTypeString());
1526  program.setAttribute( "repeat" , static_cast<int>(pInfo->IsRepeat()));
1527 
1528  if (bDetails)
1529  {
1530 
1531  program.setAttribute( "seriesId" , pInfo->GetSeriesID() );
1532  program.setAttribute( "programId" , pInfo->GetProgramID() );
1533  program.setAttribute( "stars" , pInfo->GetStars() );
1534  program.setAttribute( "fileSize" ,
1535  QString::number( pInfo->GetFilesize() ));
1536  program.setAttribute( "lastModified",
1538  program.setAttribute( "programFlags", pInfo->GetProgramFlags() );
1539  program.setAttribute( "hostname" , pInfo->GetHostname() );
1540 
1541  if (pInfo->GetOriginalAirDate().isValid())
1542  program.setAttribute(
1543  "airdate", pInfo->GetOriginalAirDate().toString());
1544 
1545  QDomText textNode = pDoc->createTextNode( pInfo->GetDescription() );
1546  program.appendChild( textNode );
1547 
1548  }
1549 
1550  if ( bIncChannel )
1551  {
1552  // Build Channel Child Element
1553 
1554  QDomElement channel = pDoc->createElement( "Channel" );
1555  program.appendChild( channel );
1556 
1557  FillChannelInfo( channel, pInfo, bDetails );
1558  }
1559 
1560  // Build Recording Child Element
1561 
1562  if ( pInfo->GetRecordingStatus() != RecStatus::Unknown )
1563  {
1564  QDomElement recording = pDoc->createElement( "Recording" );
1565  program.appendChild( recording );
1566 
1567  recording.setAttribute( "recStatus" ,
1568  pInfo->GetRecordingStatus() );
1569  recording.setAttribute( "recPriority" ,
1570  pInfo->GetRecordingPriority() );
1571  recording.setAttribute( "recStartTs" ,
1573  recording.setAttribute( "recEndTs" ,
1575 
1576  if (bDetails)
1577  {
1578  recording.setAttribute( "recordId" ,
1579  pInfo->GetRecordingRuleID() );
1580  recording.setAttribute( "recGroup" ,
1581  pInfo->GetRecordingGroup() );
1582  recording.setAttribute( "playGroup" ,
1583  pInfo->GetPlaybackGroup() );
1584  recording.setAttribute( "recType" ,
1585  pInfo->GetRecordingRuleType() );
1586  recording.setAttribute( "dupInType" ,
1587  pInfo->GetDuplicateCheckSource() );
1588  recording.setAttribute( "dupMethod" ,
1589  pInfo->GetDuplicateCheckMethod() );
1590  recording.setAttribute( "encoderId" ,
1591  pInfo->GetInputID() );
1592  const RecordingInfo ri(*pInfo);
1593  recording.setAttribute( "recProfile" ,
1595  //recording.setAttribute( "preRollSeconds", m_nPreRollSeconds );
1596  }
1597  }
1598 }
1599 
1601 //
1603 
1604 void HttpStatus::FillChannelInfo( QDomElement &channel,
1605  ProgramInfo *pInfo,
1606  bool bDetails /* = true */ )
1607 {
1608  if (pInfo)
1609  {
1610 /*
1611  QString sHostName = gCoreContext->GetHostName();
1612  QString sPort = gCoreContext->GetSettingOnHost( "BackendStatusPort",
1613  sHostName);
1614  QString sIconURL = QString( "http://%1:%2/getChannelIcon?ChanId=%3" )
1615  .arg( sHostName )
1616  .arg( sPort )
1617  .arg( pInfo->chanid );
1618 */
1619 
1620  channel.setAttribute( "chanId" , pInfo->GetChanID() );
1621  channel.setAttribute( "chanNum" , pInfo->GetChanNum());
1622  channel.setAttribute( "callSign" , pInfo->GetChannelSchedulingID());
1623  //channel.setAttribute( "iconURL" , sIconURL );
1624  channel.setAttribute( "channelName", pInfo->GetChannelName());
1625 
1626  if (bDetails)
1627  {
1628  channel.setAttribute( "chanFilters",
1629  pInfo->GetChannelPlaybackFilters() );
1630  channel.setAttribute( "sourceId" , pInfo->GetSourceID() );
1631  channel.setAttribute( "inputId" , pInfo->GetInputID() );
1632  channel.setAttribute( "commFree" ,
1633  (pInfo->IsCommercialFree()) ? 1 : 0 );
1634  }
1635  }
1636 }
1637 
1638 
1639 
1640 
1641 // vim:set shiftwidth=4 tabstop=4 expandtab:
HttpStatus::PrintStatus
static void PrintStatus(QTextStream &os, QDomDocument *pDoc)
Definition: httpstatus.cpp:625
HttpStatus::GetMethod
static HttpStatusMethod GetMethod(const QString &sURI)
Definition: httpstatus.cpp:71
Scheduler
Definition: scheduler.h:45
MSqlQuery::next
bool next(void)
Wrap QSqlQuery::next() so we can display the query results.
Definition: mythdbcon.cpp:813
MSqlQuery
QSqlQuery wrapper that fetches a DB connection from the connection pool.
Definition: mythdbcon.h:127
HTTPRequest::m_sBaseUrl
QString m_sBaseUrl
Definition: httprequest.h:127
MythDate::toString
QString toString(const QDateTime &raw_dt, uint format)
Returns formatted string representing the time.
Definition: mythdate.cpp:84
tv.h
HTTPRequest
Definition: httprequest.h:109
HttpStatus::m_pEncoders
QMap< int, EncoderLink * > * m_pEncoders
Definition: httpstatus.h:47
MythCoreContext::GetMasterHostName
QString GetMasterHostName(void)
Definition: mythcorecontext.cpp:807
ProgramInfo::GetFilesize
virtual uint64_t GetFilesize(void) const
Definition: programinfo.cpp:6425
HSM_GetStatusXML
@ HSM_GetStatusXML
Definition: httpstatus.h:25
CardUtil::GetDeviceLabel
static QString GetDeviceLabel(const QString &inputtype, const QString &videodevice)
Definition: cardutil.cpp:2634
ReferenceCounter::DecrRef
virtual int DecrRef(void)
Decrements reference count and deletes on 0.
Definition: referencecounter.cpp:125
ProgramInfo::GetHostname
QString GetHostname(void) const
Definition: programinfo.h:421
HttpStatusMethod
HttpStatusMethod
Definition: httpstatus.h:21
MythSystemLegacy
Definition: mythsystemlegacy.h:67
HttpStatus::GetStatusHTML
void GetStatusHTML(HTTPRequest *pRequest)
Definition: httpstatus.cpp:162
SleepStatus
SleepStatus
SleepStatus is an enumeration of the awake/sleep status of a slave.
Definition: tv.h:97
HttpStatus::PrintScheduled
static int PrintScheduled(QTextStream &os, const QDomElement &scheduled)
Definition: httpstatus.cpp:856
HttpStatus::m_pSched
Scheduler * m_pSched
Definition: httpstatus.h:46
HTTPRequest::m_sMethod
QString m_sMethod
Definition: httprequest.h:129
HttpStatus::m_bIsMaster
bool m_bIsMaster
Definition: httpstatus.h:50
RecordingInfo
Holds information on a TV Program one might wish to record.
Definition: recordinginfo.h:35
HTTPRequest::m_sResourceUrl
QString m_sResourceUrl
Definition: httprequest.h:128
ProgramInfo::GetChannelName
QString GetChannelName(void) const
This is the channel name in the local market, i.e.
Definition: programinfo.h:386
ProgramInfo::GetChanNum
QString GetChanNum(void) const
This is the channel "number", in the form 1, 1_2, 1-2, 1#1, etc.
Definition: programinfo.h:376
MainServer::BackendQueryDiskSpace
void BackendQueryDiskSpace(QStringList &strlist, bool consolidated, bool allHosts)
Definition: mainserver.cpp:5126
httpstatus.h
getLoadAvgs
loadArray getLoadAvgs(void)
Returns the system load averages.
Definition: mythmiscutil.cpp:175
sched
Scheduler * sched
MSqlQuery::value
QVariant value(int i) const
Definition: mythdbcon.h:204
mythdbcon.h
SSDP::Find
static SSDPCacheEntries * Find(const QString &sURI)
Definition: ssdp.h:132
ProgramInfo::GetChannelSchedulingID
QString GetChannelSchedulingID(void) const
This is the unique programming identifier of a channel.
Definition: programinfo.h:383
ProgramInfo::GetCategory
QString GetCategory(void) const
Definition: programinfo.h:369
AutoExpire
Used to expire recordings to make space for new recordings.
Definition: autoexpire.h:60
RecStatus::Unknown
@ Unknown
Definition: recordingstatus.h:31
MSqlQuery::exec
bool exec(void)
Wrap QSqlQuery::exec() so we can display SQL.
Definition: mythdbcon.cpp:619
JOB_LIST_NOT_DONE
@ JOB_LIST_NOT_DONE
Definition: jobqueue.h:69
HttpStatus::FillProgramInfo
static void FillProgramInfo(QDomDocument *pDoc, QDomNode &node, ProgramInfo *pInfo, bool bIncChannel=true, bool bDetails=true)
Definition: httpstatus.cpp:1505
ProgramInfo::GetScheduledEndTime
QDateTime GetScheduledEndTime(void) const
The scheduled end time of the program.
Definition: programinfo.h:397
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
MythSystemLegacy::ReadAll
QByteArray & ReadAll()
Definition: mythsystemlegacy.cpp:402
SSDPCacheEntries::GetEntryMap
void GetEntryMap(EntryMap &map)
Returns a copy of the EntryMap.
Definition: ssdpcache.cpp:85
ProgramInfo::GetRecordingEndTime
QDateTime GetRecordingEndTime(void) const
Approximate time the recording should have ended, did end, or is intended to end.
Definition: programinfo.h:412
GENERIC_EXIT_OK
@ GENERIC_EXIT_OK
Exited with no error.
Definition: exitcodes.h:11
HttpStatus::ProcessRequest
bool ProcessRequest(HTTPRequest *pRequest) override
Definition: httpstatus.cpp:94
ProgramInfo::GetProgramFlags
uint32_t GetProgramFlags(void) const
Definition: programinfo.h:470
ProgramInfo::GetRecordingGroup
QString GetRecordingGroup(void) const
Definition: programinfo.h:419
ProgramInfo::GetRecordingPriority
int GetRecordingPriority(void) const
Definition: programinfo.h:440
HttpStatus::GetBasePaths
QStringList GetBasePaths() override
Definition: httpstatus.cpp:85
scheduler.h
MythDate::current
QDateTime current(bool stripped)
Returns current Date and Time in UTC.
Definition: mythdate.cpp:14
MythCoreContext::GetMasterServerStatusPort
int GetMasterServerStatusPort(void)
Returns the Master Backend status port If no master server status port has been defined in the databa...
Definition: mythcorecontext.cpp:993
ProgramInfo::GetRecordingStartTime
QDateTime GetRecordingStartTime(void) const
Approximate time the recording started.
Definition: programinfo.h:404
mythsystemlegacy.h
kState_WatchingRecording
@ kState_WatchingRecording
Watching Recording is the state for when we are watching an in progress recording,...
Definition: tv.h:80
JobQueue::JobText
static QString JobText(int jobType)
Definition: jobqueue.cpp:1103
HTTPRequest::m_mapRespHeaders
QStringMap m_mapRespHeaders
Definition: httprequest.h:153
ProgramInfo::IsRepeat
bool IsRepeat(void) const
Definition: programinfo.h:487
RecStatus::WillRecord
@ WillRecord
Definition: recordingstatus.h:30
RecordingInfo::GetProgramRecordingProfile
QString GetProgramRecordingProfile(void) const
Returns recording profile name that will be, or was used, for this program, creating "record" field i...
Definition: recordinginfo.cpp:492
MythCoreContext::IsMasterBackend
bool IsMasterBackend(void)
is this the actual MBE process
Definition: mythcorecontext.cpp:695
HttpStatus::PrintBackends
static int PrintBackends(QTextStream &os, const QDomElement &backends)
Definition: httpstatus.cpp:1027
JobQueue::GetJobsInQueue
static int GetJobsInQueue(QMap< int, JobQueueEntry > &jobs, int findJobs=JOB_LIST_NOT_DONE)
Definition: jobqueue.cpp:1267
mythdate.h
autoexpire.h
upnp.h
HTTPRequest::m_nResponseStatus
long m_nResponseStatus
Definition: httprequest.h:152
ProgramInfo::GetScheduledStartTime
QDateTime GetScheduledStartTime(void) const
The scheduled start time of program.
Definition: programinfo.h:390
ProgramInfo::GetRecordingStatus
RecStatus::Type GetRecordingStatus(void) const
Definition: programinfo.h:447
hardwareprofile.config.p
p
Definition: config.py:33
MythCoreContext::GetMasterServerIP
QString GetMasterServerIP(void)
Returns the Master Backend IP address If the address is an IPv6 address, the scope Id is removed.
Definition: mythcorecontext.cpp:966
HttpStatus::m_pMainServer
MainServer * m_pMainServer
Definition: httpstatus.h:49
ProgramInfo::GetTitle
QString GetTitle(void) const
Definition: programinfo.h:361
MSqlQuery::InitCon
static MSqlQueryInfo InitCon(ConnectionReuse _reuse=kNormalConnection)
Only use this in combination with MSqlQuery constructor.
Definition: mythdbcon.cpp:551
ProgramInfo::GetDescription
QString GetDescription(void) const
Definition: programinfo.h:365
compat.h
ProgramInfo::GetSourceID
uint GetSourceID(void) const
Definition: programinfo.h:462
EntryMap
QMap< QString, DeviceLocation * > EntryMap
Key == Unique Service Name (USN)
Definition: ssdpcache.h:29
MythSystemLegacy::Wait
uint Wait(std::chrono::seconds timeout=0s)
Definition: mythsystemlegacy.cpp:243
MythDate::kDateShort
@ kDateShort
Default local time.
Definition: mythdate.h:20
sStatus_Asleep
@ sStatus_Asleep
A slave is considered asleep when it is not awake and not undefined.
Definition: tv.h:104
HSM_Unknown
@ HSM_Unknown
Definition: httpstatus.h:23
HttpStatus::PrintMachineInfo
static int PrintMachineInfo(QTextStream &os, const QDomElement &info)
Definition: httpstatus.cpp:1209
setting_to_localtime
static QString setting_to_localtime(const char *setting)
Definition: httpstatus.cpp:175
loadArray
std::array< double, 3 > loadArray
Definition: mythmiscutil.h:22
ProgramInfo::GetPlaybackGroup
QString GetPlaybackGroup(void) const
Definition: programinfo.h:420
jobqueue.h
HttpStatus::FillStatusXML
void FillStatusXML(QDomDocument *pDoc)
Definition: httpstatus.cpp:182
ProgramInfo::GetChannelPlaybackFilters
QString GetChannelPlaybackFilters(void) const
Definition: programinfo.h:387
ResponseTypeXML
@ ResponseTypeXML
Definition: httprequest.h:78
TVRec::s_inputsLock
static QReadWriteLock s_inputsLock
Definition: tv_rec.h:432
SSDPCacheEntries
Definition: ssdpcache.h:35
uint
unsigned int uint
Definition: compat.h:81
HttpStatus::PrintJobQueue
static int PrintJobQueue(QTextStream &os, const QDomElement &jobs)
Definition: httpstatus.cpp:1066
gCoreContext
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
Definition: mythcorecontext.cpp:55
ProgramInfo::GetSeriesID
QString GetSeriesID(void) const
Definition: programinfo.h:435
MythCoreContext::GetNumSetting
int GetNumSetting(const QString &key, int defaultval=0)
Definition: mythcorecontext.cpp:912
ProgramInfo::GetOriginalAirDate
QDate GetOriginalAirDate(void) const
Definition: programinfo.h:428
kMSRunShell
@ kMSRunShell
run process through shell
Definition: mythsystem.h:43
ResponseTypeHTML
@ ResponseTypeHTML
Definition: httprequest.h:79
MythDate::fromString
QDateTime fromString(const QString &dtstr)
Converts kFilename && kISODate formats to QDateTime.
Definition: mythdate.cpp:34
HSM_GetStatusHTML
@ HSM_GetStatusHTML
Definition: httpstatus.h:24
MythDate::kSimplify
@ kSimplify
Do Today/Yesterday/Tomorrow transform.
Definition: mythdate.h:26
MythCoreContext::GetBoolSetting
bool GetBoolSetting(const QString &key, bool defaultval=false)
Definition: mythcorecontext.cpp:906
ProgramInfo::GetDuplicateCheckMethod
RecordingDupMethodType GetDuplicateCheckMethod(void) const
What should be compared to determine if two programs are the same?
Definition: programinfo.h:459
ProgramInfo::GetInputID
uint GetInputID(void) const
Definition: programinfo.h:463
sStatus_Undefined
@ sStatus_Undefined
A slave's sleep status is undefined when it has never connected to the master backend or is not able ...
Definition: tv.h:117
ProgramInfo::GetChanID
uint GetChanID(void) const
This is the unique key used in the database to locate tuning information.
Definition: programinfo.h:372
ProgramInfo::GetRecordingRuleType
RecordingType GetRecordingRuleType(void) const
Definition: programinfo.h:451
ProgramInfo
Holds information on recordings and videos.
Definition: programinfo.h:67
mythmiscutil.h
HttpStatus::PrintMiscellaneousInfo
static int PrintMiscellaneousInfo(QTextStream &os, const QDomElement &info)
Definition: httpstatus.cpp:1453
TVState
TVState
TVState is an enumeration of the states used by TV and TVRec.
Definition: tv.h:50
MythDate::kAddYear
@ kAddYear
Add year to string if not included.
Definition: mythdate.h:25
ProgramInfo::GetLastModifiedTime
QDateTime GetLastModifiedTime(void) const
Definition: programinfo.h:429
mythcorecontext.h
HttpStatus::m_pExpirer
AutoExpire * m_pExpirer
Definition: httpstatus.h:48
cardutil.h
ProgramInfo::GetCategoryTypeString
QString GetCategoryTypeString(void) const
Returns catType as a string.
Definition: programinfo.cpp:1887
MSqlQuery::bindValue
void bindValue(const QString &placeholder, const QVariant &val)
Add a single binding.
Definition: mythdbcon.cpp:889
jobqueue
JobQueue * jobqueue
Definition: mythjobqueue.cpp:43
MythDate::ISODate
@ ISODate
Default UTC.
Definition: mythdate.h:17
HTTPRequest::m_eResponseType
HttpResponseType m_eResponseType
Definition: httprequest.h:149
HttpStatus::PrintEncoderStatus
static int PrintEncoderStatus(QTextStream &os, const QDomElement &encoders)
Definition: httpstatus.cpp:712
RecList
std::deque< RecordingInfo * > RecList
Definition: mythscheduler.h:12
tv_rec.h
kState_WatchingLiveTV
@ kState_WatchingLiveTV
Watching LiveTV is the state for when we are watching a recording and the user has control over the c...
Definition: tv.h:63
ProgramInfo::GetDuplicateCheckSource
RecordingDupInType GetDuplicateCheckSource(void) const
Where should we check for duplicates?
Definition: programinfo.h:455
mainserver.h
MythDate::kDatabase
@ kDatabase
Default UTC, database format.
Definition: mythdate.h:27
MythDate::kDateFull
@ kDateFull
Default local time.
Definition: mythdate.h:19
MythCoreContext::GetHostName
QString GetHostName(void)
Definition: mythcorecontext.cpp:838
Scheduler::GetAllPending
bool GetAllPending(RecList &retList, int recRuleId=0) const
Definition: scheduler.cpp:1741
JOB_LIST_RECENT
@ JOB_LIST_RECENT
Definition: jobqueue.h:71
HttpStatus::m_nPreRollSeconds
int m_nPreRollSeconds
Definition: httpstatus.h:51
ProgramInfo::GetProgramID
QString GetProgramID(void) const
Definition: programinfo.h:436
MythSystemLegacy::Run
void Run(std::chrono::seconds timeout=0s)
Runs a command inside the /bin/sh shell. Returns immediately.
Definition: mythsystemlegacy.cpp:213
expirer
AutoExpire * expirer
musicbrainzngs.caa.hostname
string hostname
Definition: caa.py:17
MythDate::kDateTimeFull
@ kDateTimeFull
Default local time.
Definition: mythdate.h:23
MythDate::kTime
@ kTime
Default local time.
Definition: mythdate.h:22
ProgramInfo::GetRecordingRuleID
uint GetRecordingRuleID(void) const
Definition: programinfo.h:449
exitcodes.h
HttpStatus::PrintFrontends
static int PrintFrontends(QTextStream &os, const QDomElement &frontends)
Definition: httpstatus.cpp:989
JOB_LIST_ERROR
@ JOB_LIST_ERROR
Definition: jobqueue.h:70
HttpServerExtension
Definition: httpserver.h:71
UPnp::g_IPAddrList
static QList< QHostAddress > g_IPAddrList
Definition: upnp.h:110
HttpStatus::FillChannelInfo
static void FillChannelInfo(QDomElement &channel, ProgramInfo *pInfo, bool bDetails=true)
Definition: httpstatus.cpp:1604
kMSStdOut
@ kMSStdOut
allow access to stdout
Definition: mythsystem.h:41
HttpStatus::HttpStatus
HttpStatus(QMap< int, EncoderLink * > *tvList, Scheduler *sched, AutoExpire *expirer, bool bIsMaster)
Definition: httpstatus.cpp:53
output
#define output
Definition: synaesthesia.cpp:220
kState_RecordingOnly
@ kState_RecordingOnly
Recording Only is a TVRec only state for when we are recording a program, but there is no one current...
Definition: tv.h:84
ProgramInfo::IsCommercialFree
bool IsCommercialFree(void) const
Definition: programinfo.h:477
HTTPRequest::m_response
QBuffer m_response
Definition: httprequest.h:157
JobQueue::StatusText
static QString StatusText(int status)
Definition: jobqueue.cpp:1126
MythCoreContext::GetSetting
QString GetSetting(const QString &key, const QString &defaultval="")
Definition: mythcorecontext.cpp:898
MSqlQuery::prepare
bool prepare(const QString &query)
QSqlQuery::prepare() is not thread safe in Qt <= 3.3.2.
Definition: mythdbcon.cpp:838
ProgramInfo::GetSubtitle
QString GetSubtitle(void) const
Definition: programinfo.h:363
ProgramInfo::GetStars
float GetStars(void) const
Definition: programinfo.h:442
HttpStatus::GetStatusXML
void GetStatusXML(HTTPRequest *pRequest)
Definition: httpstatus.cpp:134