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