2 #include <lib/dvb/db.h>
3 #include <lib/dvb/dvb.h>
4 #include <lib/dvb/frontend.h>
5 #include <lib/dvb/epgcache.h>
6 #include <lib/base/eerror.h>
7 #include <lib/base/estring.h>
8 #include <xmlccwrap/xmlccwrap.h>
9 #include <dvbsi++/service_description_section.h>
10 #include <dvbsi++/descriptor_tag.h>
11 #include <dvbsi++/service_descriptor.h>
12 #include <dvbsi++/satellite_delivery_system_descriptor.h>
14 DEFINE_REF(eDVBService);
16 RESULT eBouquet::addService(const eServiceReference &ref, eServiceReference before)
19 std::find(m_services.begin(), m_services.end(), ref);
20 if ( it != m_services.end() )
24 it = std::find(m_services.begin(), m_services.end(), before);
25 m_services.insert(it, ref);
28 m_services.push_back(ref);
32 RESULT eBouquet::removeService(const eServiceReference &ref)
35 std::find(m_services.begin(), m_services.end(), ref);
36 if ( it == m_services.end() )
42 RESULT eBouquet::moveService(const eServiceReference &ref, unsigned int pos)
44 if ( pos < 0 || pos >= m_services.size() )
47 list::iterator source=m_services.end();
48 list::iterator dest=m_services.end();
50 for (list::iterator it(m_services.begin()); it != m_services.end(); ++it)
52 if (dest == m_services.end() && !--pos)
59 if (dest != m_services.end() && source != m_services.end())
62 if (dest == m_services.end() || source == m_services.end() || source == dest)
64 while (source != dest)
67 std::iter_swap(source++, source);
69 std::iter_swap(source--, source);
74 RESULT eBouquet::flushChanges()
76 FILE *f=fopen((CONFIGDIR"/enigma2/"+m_filename).c_str(), "w");
79 if ( fprintf(f, "#NAME %s\r\n", m_bouquet_name.c_str()) < 0 )
81 for (list::iterator i(m_services.begin()); i != m_services.end(); ++i)
83 eServiceReference tmp = *i;
84 std::string str = tmp.path;
85 if ( fprintf(f, "#SERVICE %s\r\n", tmp.toString().c_str()) < 0 )
87 if ( i->name.length() )
88 if ( fprintf(f, "#DESCRIPTION %s\r\n", i->name.c_str()) < 0 )
95 eDebug("couldn't write file %s", m_filename.c_str());
99 RESULT eBouquet::setListName(const std::string &name)
101 m_bouquet_name = name;
105 eDVBService::eDVBService()
106 :m_cache(0), m_flags(0)
110 eDVBService::~eDVBService()
115 eDVBService &eDVBService::operator=(const eDVBService &s)
117 m_service_name = s.m_service_name;
118 m_service_name_sort = s.m_service_name_sort;
119 m_provider_name = s.m_provider_name;
122 copyCache(s.m_cache);
126 void eDVBService::genSortName()
128 m_service_name_sort = removeDVBChars(m_service_name);
129 makeUpper(m_service_name_sort);
130 while ((!m_service_name_sort.empty()) && m_service_name_sort[0] == ' ')
131 m_service_name_sort.erase(0, 1);
133 /* put unnamed services at the end, not at the beginning. */
134 if (m_service_name_sort.empty())
135 m_service_name_sort = "\xFF";
138 RESULT eDVBService::getName(const eServiceReference &ref, std::string &name)
140 if (!ref.name.empty())
141 name = ref.name; // use renamed service name..
142 else if (!m_service_name.empty())
143 name = m_service_name;
149 RESULT eDVBService::getEvent(const eServiceReference &ref, ePtr<eServiceEvent> &ptr, time_t start_time)
151 return eEPGCache::getInstance()->lookupEventTime(ref, start_time, ptr);
154 int eDVBService::isPlayable(const eServiceReference &ref, const eServiceReference &ignore)
156 ePtr<eDVBResourceManager> res_mgr;
157 if ( eDVBResourceManager::getInstance( res_mgr ) )
158 eDebug("isPlayble... no res manager!!");
161 eDVBChannelID chid, chid_ignore;
162 ((const eServiceReferenceDVB&)ref).getChannelID(chid);
163 ((const eServiceReferenceDVB&)ignore).getChannelID(chid_ignore);
164 return res_mgr->canAllocateChannel(chid, chid_ignore);
169 int eDVBService::checkFilter(const eServiceReferenceDVB &ref, const eDVBChannelQuery &query)
172 switch (query.m_type)
174 case eDVBChannelQuery::tName:
175 res = m_service_name_sort.find(query.m_string) != std::string::npos;
177 case eDVBChannelQuery::tProvider:
178 res = m_provider_name.find(query.m_string) != std::string::npos;
180 case eDVBChannelQuery::tType:
181 res = ref.getServiceType() == query.m_int;
183 case eDVBChannelQuery::tBouquet:
186 case eDVBChannelQuery::tSatellitePosition:
187 res = ((unsigned int)ref.getDVBNamespace().get())>>16 == (unsigned int)query.m_int;
189 case eDVBChannelQuery::tFlags:
190 res = (m_flags & query.m_int) == query.m_int;
192 case eDVBChannelQuery::tChannelID:
195 ref.getChannelID(chid);
196 res = chid == query.m_channelid;
199 case eDVBChannelQuery::tAND:
200 res = checkFilter(ref, *query.m_p1) && checkFilter(ref, *query.m_p2);
202 case eDVBChannelQuery::tOR:
203 res = checkFilter(ref, *query.m_p1) || checkFilter(ref, *query.m_p2);
205 case eDVBChannelQuery::tAny:
216 bool eDVBService::cacheEmpty()
219 for (int i=0; i < cacheMax; ++i)
220 if (m_cache[i] != -1)
225 void eDVBService::initCache()
227 m_cache = new int[cacheMax];
228 memset(m_cache, -1, sizeof(int) * cacheMax);
231 void eDVBService::copyCache(int *source)
236 m_cache = new int[cacheMax];
237 memcpy(m_cache, source, cacheMax * sizeof(int));
246 int eDVBService::getCacheEntry(cacheID id)
248 if (id >= cacheMax || !m_cache)
253 void eDVBService::setCacheEntry(cacheID id, int pid)
263 /* THIS CODE IS BAD. it should be replaced by somethine better. */
264 void eDVBDB::reloadServicelist()
266 eDebug("---- opening lame channel db");
267 FILE *f=fopen(CONFIGDIR"/enigma2/lamedb", "rt");
271 if ( !stat("lamedb", &s) )
273 if ( !stat(CONFIGDIR"/enigma2", &s) )
275 rename("lamedb", CONFIGDIR"/enigma2/lamedb" );
282 if ((!fgets(line, 256, f)) || strncmp(line, "eDVB services", 13))
284 eDebug("not a servicefile");
288 eDebug("reading services");
289 if ((!fgets(line, 256, f)) || strcmp(line, "transponders\n"))
291 eDebug("services invalid, no transponders");
296 // clear all transponders
300 if (!fgets(line, 256, f))
302 if (!strcmp(line, "end\n"))
304 int dvb_namespace=-1, transport_stream_id=-1, original_network_id=-1;
305 sscanf(line, "%x:%x:%x", &dvb_namespace, &transport_stream_id, &original_network_id);
306 if (original_network_id == -1)
308 eDVBChannelID channelid = eDVBChannelID(
309 eDVBNamespace(dvb_namespace),
310 eTransportStreamID(transport_stream_id),
311 eOriginalNetworkID(original_network_id));
313 ePtr<eDVBFrontendParameters> feparm = new eDVBFrontendParameters;
317 if (!strcmp(line, "/\n"))
321 eDVBFrontendParametersSatellite sat;
322 int frequency, symbol_rate, polarisation, fec, orbital_position, inversion,
323 system=eDVBFrontendParametersSatellite::System::DVB_S,
324 modulation=eDVBFrontendParametersSatellite::Modulation::QPSK,
325 rolloff=eDVBFrontendParametersSatellite::RollOff::alpha_auto;
326 sscanf(line+3, "%d:%d:%d:%d:%d:%d:%d:%d:%d", &frequency, &symbol_rate, &polarisation, &fec, &orbital_position, &inversion, &system, &modulation, &rolloff);
327 sat.frequency = frequency;
328 sat.symbol_rate = symbol_rate;
329 sat.polarisation = polarisation;
331 sat.orbital_position =
332 orbital_position < 0 ? orbital_position + 3600 : orbital_position;
333 sat.inversion = inversion;
335 sat.modulation = modulation;
336 sat.roll_off = rolloff;
337 feparm->setDVBS(sat);
338 } else if (line[1]=='t')
340 eDVBFrontendParametersTerrestrial ter;
341 int frequency, bandwidth, code_rate_HP, code_rate_LP, modulation, transmission_mode, guard_interval, hierarchy, inversion;
342 sscanf(line+3, "%d:%d:%d:%d:%d:%d:%d:%d:%d", &frequency, &bandwidth, &code_rate_HP, &code_rate_LP, &modulation, &transmission_mode, &guard_interval, &hierarchy, &inversion);
343 ter.frequency = frequency;
344 ter.bandwidth = bandwidth;
345 ter.code_rate_HP = code_rate_HP;
346 ter.code_rate_LP = code_rate_LP;
347 ter.modulation = modulation;
348 ter.transmission_mode = transmission_mode;
349 ter.guard_interval = guard_interval;
350 ter.hierarchy = hierarchy;
351 ter.inversion = inversion;
352 feparm->setDVBT(ter);
353 } else if (line[1]=='c')
355 eDVBFrontendParametersCable cab;
356 int frequency, symbol_rate,
357 inversion=eDVBFrontendParametersCable::Inversion::Unknown,
358 modulation=eDVBFrontendParametersCable::Modulation::Auto,
359 fec_inner=eDVBFrontendParametersCable::FEC::fAuto;
360 sscanf(line+3, "%d:%d:%d:%d:%d", &frequency, &symbol_rate, &inversion, &modulation, &fec_inner);
361 cab.frequency = frequency;
362 cab.fec_inner = fec_inner;
363 cab.inversion = inversion;
364 cab.symbol_rate = symbol_rate;
365 cab.modulation = modulation;
366 feparm->setDVBC(cab);
369 addChannelToList(channelid, feparm);
372 if ((!fgets(line, 256, f)) || strcmp(line, "services\n"))
374 eDebug("services invalid, no services");
378 // clear all services
384 if (!fgets(line, 256, f))
386 if (!strcmp(line, "end\n"))
389 int service_id=-1, dvb_namespace, transport_stream_id=-1, original_network_id=-1, service_type=-1, service_number=-1;
390 sscanf(line, "%x:%x:%x:%x:%d:%d", &service_id, &dvb_namespace, &transport_stream_id, &original_network_id, &service_type, &service_number);
391 if (service_number == -1)
393 ePtr<eDVBService> s = new eDVBService;
394 eServiceReferenceDVB ref =
395 eServiceReferenceDVB(
396 eDVBNamespace(dvb_namespace),
397 eTransportStreamID(transport_stream_id),
398 eOriginalNetworkID(original_network_id),
399 eServiceID(service_id),
404 line[strlen(line)-1]=0;
406 s->m_service_name = line;
411 line[strlen(line)-1]=0;
412 std::string str=line;
414 if (str[1]!=':') // old ... (only service_provider)
416 s->m_provider_name=line;
418 while ((!str.empty()) && str[1]==':') // new: p:, f:, c:%02d...
420 unsigned int c=str.find(',');
423 if (c == std::string::npos)
429 v=str.substr(2, c-2);
432 // eDebug("%c ... %s", p, v.c_str());
434 s->m_provider_name=v;
437 sscanf(v.c_str(), "%x", &s->m_flags);
441 sscanf(v.c_str(), "%02d%x", &cid, &val);
442 s->setCacheEntry((eDVBService::cacheID)cid,val);
446 sscanf(v.c_str(), "%04x", &val);
447 s->m_ca.push_front((uint16_t)val);
453 eDebug("loaded %d services", count);
458 void eDVBDB::saveServicelist()
460 eDebug("---- saving lame channel db");
461 FILE *f=fopen(CONFIGDIR"/enigma2/lamedb", "w");
462 int channels=0, services=0;
464 eFatal("couldn't save lame channel db!");
465 fprintf(f, "eDVB services /3/\n");
466 fprintf(f, "transponders\n");
467 for (std::map<eDVBChannelID, channel>::const_iterator i(m_channels.begin());
468 i != m_channels.end(); ++i)
470 const eDVBChannelID &chid = i->first;
471 const channel &ch = i->second;
473 fprintf(f, "%08x:%04x:%04x\n", chid.dvbnamespace.get(),
474 chid.transport_stream_id.get(), chid.original_network_id.get());
475 eDVBFrontendParametersSatellite sat;
476 eDVBFrontendParametersTerrestrial ter;
477 eDVBFrontendParametersCable cab;
478 if (!ch.m_frontendParameters->getDVBS(sat))
480 if (sat.system == eDVBFrontendParametersSatellite::System::DVB_S2)
482 fprintf(f, "\ts %d:%d:%d:%d:%d:%d:%d:%d:%d\n",
483 sat.frequency, sat.symbol_rate,
484 sat.polarisation, sat.fec,
485 sat.orbital_position > 1800 ? sat.orbital_position - 3600 : sat.orbital_position,
493 fprintf(f, "\ts %d:%d:%d:%d:%d:%d\n",
494 sat.frequency, sat.symbol_rate,
495 sat.polarisation, sat.fec,
496 sat.orbital_position > 1800 ? sat.orbital_position - 3600 : sat.orbital_position,
500 else if (!ch.m_frontendParameters->getDVBT(ter))
502 fprintf(f, "\tt %d:%d:%d:%d:%d:%d:%d:%d:%d\n",
503 ter.frequency, ter.bandwidth, ter.code_rate_HP,
504 ter.code_rate_LP, ter.modulation, ter.transmission_mode,
505 ter.guard_interval, ter.hierarchy, ter.inversion);
507 else if (!ch.m_frontendParameters->getDVBC(cab))
509 fprintf(f, "\tc %d:%d:%d:%d:%d\n",
510 cab.frequency, cab.symbol_rate, cab.inversion, cab.modulation, cab.fec_inner);
515 fprintf(f, "end\nservices\n");
517 for (std::map<eServiceReferenceDVB, ePtr<eDVBService> >::iterator i(m_services.begin());
518 i != m_services.end(); ++i)
520 const eServiceReferenceDVB &s = i->first;
521 fprintf(f, "%04x:%08x:%04x:%04x:%d:%d\n",
522 s.getServiceID().get(), s.getDVBNamespace().get(),
523 s.getTransportStreamID().get(),s.getOriginalNetworkID().get(),
527 fprintf(f, "%s\n", i->second->m_service_name.c_str());
529 fprintf(f, "p:%s", i->second->m_provider_name.c_str());
532 for (int x=0; x < eDVBService::cacheMax; ++x)
534 int entry = i->second->getCacheEntry((eDVBService::cacheID)x);
536 fprintf(f, ",c:%02d%04x", x, entry);
539 // write cached ca pids
540 for (CAID_LIST::const_iterator ca(i->second->m_ca.begin());
541 ca != i->second->m_ca.end(); ++ca)
542 fprintf(f, ",C:%04x", *ca);
544 if (i->second->m_flags)
545 fprintf(f, ",f:%x", i->second->m_flags);
550 fprintf(f, "end\nHave a lot of bugs!\n");
551 eDebug("saved %d channels and %d services!", channels, services);
555 void eDVBDB::loadBouquet(const char *path)
557 std::string bouquet_name = path;
558 if (!bouquet_name.length())
560 eDebug("Bouquet load failed.. no path given..");
563 unsigned int pos = bouquet_name.rfind('/');
564 if ( pos != std::string::npos )
565 bouquet_name.erase(0, pos+1);
566 if (bouquet_name.empty())
568 eDebug("Bouquet load failed.. no filename given..");
571 eBouquet &bouquet = m_bouquets[bouquet_name];
572 bouquet.m_filename = bouquet_name;
573 std::list<eServiceReference> &list = bouquet.m_services;
576 std::string p = CONFIGDIR"/enigma2/";
578 eDebug("loading bouquet... %s", p.c_str());
579 FILE *fp=fopen(p.c_str(), "rt");
584 if ( !stat(path, &s) )
586 rename(path, p.c_str() );
590 eDebug("failed to open.");
591 if ( strstr(path, "bouquets.tv") )
593 eDebug("recreate bouquets.tv");
594 bouquet.m_bouquet_name="Bouquets (TV)";
595 bouquet.flushChanges();
597 else if ( strstr(path, "bouquets.radio") )
599 eDebug("recreate bouquets.radio");
600 bouquet.m_bouquet_name="Bouquets (Radio)";
601 bouquet.flushChanges();
606 bool read_descr=false;
607 eServiceReference *e = NULL;
610 if (!fgets(line, 256, fp))
612 line[strlen(line)-1]=0;
613 if (strlen(line) && line[strlen(line)-1]=='\r')
614 line[strlen(line)-1]=0;
619 if (!strncmp(line, "#SERVICE", 8))
621 int offs = line[8] == ':' ? 10 : 9;
622 eServiceReference tmp(line+offs);
623 if (tmp.type != eServiceReference::idDVB)
625 eDebug("only DVB Bouquets supported");
628 if ( tmp.flags&eServiceReference::canDescent )
630 unsigned int pos = tmp.path.rfind('/');
632 std::string path = tmp.path;
633 if ( pos != std::string::npos )
634 path.erase(0, pos+1);
637 eDebug("Bouquet load failed.. no filename given..");
640 pos = path.find("FROM BOUQUET ");
641 if (pos != std::string::npos)
643 char endchr = path[pos+13];
646 eDebug("ignore invalid bouquet '%s' (only \" are allowed)",
647 tmp.toString().c_str());
650 char *beg = &path[pos+14];
651 char *end = strchr(beg, endchr);
652 path.assign(beg, end - beg);
656 snprintf(buf, 256, "FROM BOUQUET \"%s\" ORDER BY bouquet", path.c_str());
659 loadBouquet(path.c_str());
666 else if (read_descr && !strncmp(line, "#DESCRIPTION", 12))
668 int offs = line[12] == ':' ? 14 : 13;
672 else if (!strncmp(line, "#NAME ", 6))
673 bouquet.m_bouquet_name=line+6;
678 eDebug("%d entries in Bouquet %s", entries, bouquet_name.c_str());
681 void eDVBDB::reloadBouquets()
684 loadBouquet("bouquets.tv");
685 loadBouquet("bouquets.radio");
686 // create default bouquets when missing
687 if ( m_bouquets.find("userbouquet.favourites.tv") == m_bouquets.end() )
689 eBouquet &b = m_bouquets["userbouquet.favourites.tv"];
690 b.m_filename = "userbouquet.favourites.tv";
691 b.m_bouquet_name = "Favourites (TV)";
693 eServiceReference ref;
694 memset(ref.data, 0, sizeof(ref.data));
698 ref.path="FROM BOUQUET \"userbouquet.favourites.tv\" ORDER BY bouquet";
699 eBouquet &parent = m_bouquets["bouquets.tv"];
700 parent.m_services.push_back(ref);
701 parent.flushChanges();
703 if ( m_bouquets.find("userbouquet.favourites.radio") == m_bouquets.end() )
705 eBouquet &b = m_bouquets["userbouquet.favourites.radio"];
706 b.m_filename = "userbouquet.favourites.radio";
707 b.m_bouquet_name = "Favourites (Radio)";
709 eServiceReference ref;
710 memset(ref.data, 0, sizeof(ref.data));
714 ref.path="FROM BOUQUET \"userbouquet.favourites.radio\" ORDER BY bouquet";
715 eBouquet &parent = m_bouquets["bouquets.radio"];
716 parent.m_services.push_back(ref);
717 parent.flushChanges();
721 eDVBDB *eDVBDB::instance;
723 using namespace xmlcc;
731 PyObject *eDVBDB::readSatellites(ePyObject sat_list, ePyObject sat_dict, ePyObject tp_dict)
733 if (!PyDict_Check(tp_dict)) {
734 PyErr_SetString(PyExc_StandardError,
736 eDebug("arg 2 is not a python dict");
739 else if (!PyDict_Check(sat_dict))
741 PyErr_SetString(PyExc_StandardError,
743 eDebug("arg 1 is not a python dict");
746 else if (!PyList_Check(sat_list))
748 PyErr_SetString(PyExc_StandardError,
750 eDebug("arg 0 is not a python list");
754 tree.setFilename("/etc/tuxbox/satellites.xml");
756 Element *root = tree.getRoot();
759 eDebug("couldn't open /etc/tuxbox/satellites.xml!!");
764 modulation, system, freq, sr, pol, fec;
768 const ElementList &root_elements = root->getElementList();
769 for (ElementConstIterator it(root_elements.begin()); it != root_elements.end(); ++it)
771 // eDebug("element: %s", (*it)->name().c_str());
772 const Element *el = *it;
773 const ElementList &sat_elements = el->getElementList();
774 const AttributeList &sat_attributes = el->getAttributeList();
778 for (AttributeConstIterator it(sat_attributes.begin()); it != sat_attributes.end(); ++it)
780 // eDebug("\tattr: %s", at->name().c_str());
784 sat_name = PyString_FromString(at->value().c_str());
785 else if (name == "flags")
787 tmp = strtol(at->value().c_str(), &end_ptr, 10);
789 sat_flags = PyInt_FromLong(tmp);
791 else if (name == "position")
793 tmp = strtol(at->value().c_str(), &end_ptr, 10);
798 sat_pos = PyInt_FromLong(tmp);
802 if (sat_pos && sat_name)
804 ePyObject tplist = PyList_New(0);
805 ePyObject tuple = PyTuple_New(3);
807 sat_flags = PyInt_FromLong(0);
808 PyTuple_SET_ITEM(tuple, 0, sat_pos);
809 PyTuple_SET_ITEM(tuple, 1, sat_name);
810 PyTuple_SET_ITEM(tuple, 2, sat_flags);
811 PyList_Append(sat_list, tuple);
813 PyDict_SetItem(sat_dict, sat_pos, sat_name);
814 PyDict_SetItem(tp_dict, sat_pos, tplist);
815 for (ElementConstIterator it(sat_elements.begin()); it != sat_elements.end(); ++it)
817 // eDebug("\telement: %s", (*it)->name().c_str());
818 const AttributeList &tp_attributes = (*it)->getAttributeList();
819 AttributeConstIterator end = tp_attributes.end();
820 modulation = 1; // QPSK default
821 system = 0; // DVB-S default
825 fec = 0; // AUTO default
826 for (AttributeConstIterator it(tp_attributes.begin()); it != end; ++it)
828 // eDebug("\t\tattr: %s", at->name().c_str());
831 if (name == "modulation") dest = &modulation;
832 else if (name == "system") dest = &system;
833 else if (name == "frequency") dest = &freq;
834 else if (name == "symbol_rate") dest = &sr;
835 else if (name == "polarization") dest = &pol;
836 else if (name == "fec_inner") dest = &fec;
839 tmp = strtol(at->value().c_str(), &end_ptr, 10);
844 if (freq && sr && pol != -1)
846 tuple = PyTuple_New(7);
847 PyTuple_SET_ITEM(tuple, 0, PyInt_FromLong(0));
848 PyTuple_SET_ITEM(tuple, 1, PyInt_FromLong(freq));
849 PyTuple_SET_ITEM(tuple, 2, PyInt_FromLong(sr));
850 PyTuple_SET_ITEM(tuple, 3, PyInt_FromLong(pol));
851 PyTuple_SET_ITEM(tuple, 4, PyInt_FromLong(fec));
852 PyTuple_SET_ITEM(tuple, 5, PyInt_FromLong(system));
853 PyTuple_SET_ITEM(tuple, 6, PyInt_FromLong(modulation));
854 PyList_Append(tplist, tuple);
872 PyObject *eDVBDB::readCables(ePyObject cab_list, ePyObject tp_dict)
874 if (!PyDict_Check(tp_dict)) {
875 PyErr_SetString(PyExc_StandardError,
877 eDebug("arg 1 is not a python dict");
880 else if (!PyList_Check(cab_list))
882 PyErr_SetString(PyExc_StandardError,
884 eDebug("arg 0 is not a python list");
888 tree.setFilename("/etc/tuxbox/cables.xml");
890 Element *root = tree.getRoot();
893 eDebug("couldn't open /etc/tuxbox/cables.xml!!");
899 modulation, fec, freq, sr;
902 const ElementList &root_elements = root->getElementList();
903 for (ElementConstIterator it(root_elements.begin()); it != root_elements.end(); ++it)
905 // eDebug("element: %s", el->name().c_str());
906 const Element *el = *it;
907 const ElementList &cab_elements = el->getElementList();
908 const AttributeList &cab_attributes = el->getAttributeList();
911 for (AttributeConstIterator it(cab_attributes.begin()); it != cab_attributes.end(); ++it)
913 // eDebug("\tattr: %s", at->name().c_str());
917 cab_name = PyString_FromString(at->value().c_str());
918 else if (name == "flags")
920 tmp = strtol(at->value().c_str(), &end_ptr, 10);
922 cab_flags = PyInt_FromLong(tmp);
927 ePyObject tplist = PyList_New(0);
928 ePyObject tuple = PyTuple_New(2);
930 cab_flags = PyInt_FromLong(0);
931 PyTuple_SET_ITEM(tuple, 0, cab_name);
932 PyTuple_SET_ITEM(tuple, 1, cab_flags);
933 PyList_Append(cab_list, tuple);
935 PyDict_SetItem(tp_dict, cab_name, tplist);
936 for (ElementConstIterator it(cab_elements.begin()); it != cab_elements.end(); ++it)
938 // eDebug("\telement: %s", (*it)->name().c_str());
939 const AttributeList &tp_attributes = (*it)->getAttributeList();
940 AttributeConstIterator end = tp_attributes.end();
941 modulation = 3; // QAM64 default
942 fec = 0; // AUTO default
945 for (AttributeConstIterator it(tp_attributes.begin()); it != end; ++it)
947 // eDebug("\t\tattr: %s", at->name().c_str());
951 if (name == "modulation") dest = &modulation;
952 else if (name == "frequency") dest = &freq;
953 else if (name == "symbol_rate") dest = &sr;
954 else if (name == "fec_inner") dest = &fec;
957 tmp = strtol(at->value().c_str(), &end_ptr, 10);
964 while (freq > 999999)
966 tuple = PyTuple_New(5);
967 PyTuple_SET_ITEM(tuple, 0, PyInt_FromLong(1));
968 PyTuple_SET_ITEM(tuple, 1, PyInt_FromLong(freq));
969 PyTuple_SET_ITEM(tuple, 2, PyInt_FromLong(sr));
970 PyTuple_SET_ITEM(tuple, 3, PyInt_FromLong(modulation));
971 PyTuple_SET_ITEM(tuple, 4, PyInt_FromLong(fec));
972 PyList_Append(tplist, tuple);
979 Py_DECREF(cab_flags);
985 PyObject *eDVBDB::readTerrestrials(ePyObject ter_list, ePyObject tp_dict)
987 if (!PyDict_Check(tp_dict)) {
988 PyErr_SetString(PyExc_StandardError,
990 eDebug("arg 1 is not a python dict");
993 else if (!PyList_Check(ter_list))
995 PyErr_SetString(PyExc_StandardError,
997 eDebug("arg 0 is not a python list");
1001 tree.setFilename("/etc/tuxbox/terrestrial.xml");
1003 Element *root = tree.getRoot();
1006 eDebug("couldn't open /etc/tuxbox/terrestrial.xml!!");
1007 Py_INCREF(Py_False);
1010 const Attribute *at;
1013 freq, bw, constellation, crh = 5, crl = 5, guard = 4, transm, hierarchy, inv = 2;
1015 const ElementList &root_elements = root->getElementList();
1016 for (ElementConstIterator it(root_elements.begin()); it != root_elements.end(); ++it)
1018 // eDebug("element: %s", el->name().c_str());
1019 const Element *el = *it;
1020 const ElementList &ter_elements = el->getElementList();
1021 const AttributeList &ter_attributes = el->getAttributeList();
1023 ePyObject ter_flags;
1024 for (AttributeConstIterator it(ter_attributes.begin()); it != ter_attributes.end(); ++it)
1026 // eDebug("\tattr: %s", at->name().c_str());
1030 ter_name = PyString_FromString(at->value().c_str());
1031 else if (name == "flags")
1033 tmp = strtol(at->value().c_str(), &end_ptr, 10);
1035 ter_flags = PyInt_FromLong(tmp);
1040 ePyObject tplist = PyList_New(0);
1041 ePyObject tuple = PyTuple_New(2);
1043 ter_flags = PyInt_FromLong(0);
1044 PyTuple_SET_ITEM(tuple, 0, ter_name);
1045 PyTuple_SET_ITEM(tuple, 1, ter_flags);
1046 PyList_Append(ter_list, tuple);
1048 PyDict_SetItem(tp_dict, ter_name, tplist);
1049 for (ElementConstIterator it(ter_elements.begin()); it != ter_elements.end(); ++it)
1051 // eDebug("\telement: %s", (*it)->name().c_str());
1052 const AttributeList &tp_attributes = (*it)->getAttributeList();
1053 AttributeConstIterator end = tp_attributes.end();
1056 constellation = 1; // AUTO
1061 hierarchy = 4; // AUTO
1063 for (AttributeConstIterator it(tp_attributes.begin()); it != end; ++it)
1065 // eDebug("\t\tattr: %s", at->name().c_str());
1069 if (name == "centre_frequency") dest = &freq;
1070 else if (name == "bandwidth") dest = &bw;
1071 else if (name == "constellation") dest = &constellation;
1072 else if (name == "code_rate_hp") dest = &crh;
1073 else if (name == "code_rate_lp") dest = &crl;
1074 else if (name == "guard_interval") dest = &guard;
1075 else if (name == "transmission_mode") dest = &transm;
1076 else if (name == "hierarchy_information") dest = &hierarchy;
1077 else if (name == "inversion") dest = &inv;
1080 tmp = strtol(at->value().c_str(), &end_ptr, 10);
1087 if (crh > 5) // our terrestrial.xml is buggy... 6 for AUTO
1089 if (crl > 5) // our terrestrial.xml is buggy... 6 for AUTO
1091 tuple = PyTuple_New(10);
1092 PyTuple_SET_ITEM(tuple, 0, PyInt_FromLong(2));
1093 PyTuple_SET_ITEM(tuple, 1, PyInt_FromLong(freq));
1094 PyTuple_SET_ITEM(tuple, 2, PyInt_FromLong(bw));
1095 PyTuple_SET_ITEM(tuple, 3, PyInt_FromLong(constellation));
1096 PyTuple_SET_ITEM(tuple, 4, PyInt_FromLong(crh));
1097 PyTuple_SET_ITEM(tuple, 5, PyInt_FromLong(crl));
1098 PyTuple_SET_ITEM(tuple, 6, PyInt_FromLong(guard));
1099 PyTuple_SET_ITEM(tuple, 7, PyInt_FromLong(transm));
1100 PyTuple_SET_ITEM(tuple, 8, PyInt_FromLong(hierarchy));
1101 PyTuple_SET_ITEM(tuple, 9, PyInt_FromLong(inv));
1102 PyList_Append(tplist, tuple);
1109 Py_DECREF(ter_flags);
1120 RESULT eDVBDB::removeService(const eServiceReference &ref)
1122 if (ref.type == eServiceReference::idDVB)
1124 eServiceReferenceDVB &service = (eServiceReferenceDVB&)ref;
1125 std::map<eServiceReferenceDVB, ePtr<eDVBService> >::iterator it(m_services.find(service));
1126 if (it != m_services.end())
1128 m_services.erase(it);
1135 RESULT eDVBDB::removeServices(int dvb_namespace, int tsid, int onid, unsigned int orb_pos)
1137 return removeServices(eDVBChannelID(eDVBNamespace(dvb_namespace), eTransportStreamID(tsid), eOriginalNetworkID(onid)), orb_pos);
1140 RESULT eDVBDB::removeServices(eDVBChannelID chid, unsigned int orbpos)
1144 eTransportStreamID eTsid;
1145 eOriginalNetworkID eOnid;
1146 std::map<eDVBChannelID, channel>::iterator it(m_channels.begin());
1147 std::set<eDVBChannelID> removed_chids;
1148 while (it != m_channels.end())
1150 const eDVBChannelID &ch = it->first;
1153 it->second.m_frontendParameters->getSystem(system);
1154 if ( system == iDVBFrontend::feSatellite )
1156 eDVBFrontendParametersSatellite sat;
1157 it->second.m_frontendParameters->getDVBS(sat);
1158 if ((unsigned int)sat.orbital_position != orbpos)
1161 else if (orbpos != 0xFFFFFFFF) // do not remove -C or -T transponders when a orbital position is given..
1163 if ( remove && chid.dvbnamespace != eNs && chid.dvbnamespace != ch.dvbnamespace )
1165 if ( remove && chid.original_network_id != eOnid && chid.original_network_id != ch.original_network_id )
1167 if ( remove && chid.transport_stream_id != eTsid && chid.transport_stream_id != ch.transport_stream_id )
1171 eDebug("remove %08x %04x %04x",
1172 ch.dvbnamespace.get(),
1173 ch.original_network_id.get(),
1174 ch.transport_stream_id.get());
1175 removed_chids.insert(it->first);
1176 m_channels.erase(it++);
1181 if (!removed_chids.empty())
1183 std::map<eServiceReferenceDVB, ePtr<eDVBService> >::iterator service(m_services.begin());
1184 while(service != m_services.end())
1187 service->first.getChannelID(chid);
1188 std::set<eDVBChannelID>::iterator it(removed_chids.find(chid));
1189 if (it != removed_chids.end())
1190 m_services.erase(service++);
1199 RESULT eDVBDB::addFlag(const eServiceReference &ref, unsigned int flagmask)
1201 if (ref.type == eServiceReference::idDVB)
1203 eServiceReferenceDVB &service = (eServiceReferenceDVB&)ref;
1204 std::map<eServiceReferenceDVB, ePtr<eDVBService> >::iterator it(m_services.find(service));
1205 if (it != m_services.end())
1206 it->second->m_flags |= ~flagmask;
1212 RESULT eDVBDB::removeFlag(const eServiceReference &ref, unsigned int flagmask)
1214 if (ref.type == eServiceReference::idDVB)
1216 eServiceReferenceDVB &service = (eServiceReferenceDVB&)ref;
1217 std::map<eServiceReferenceDVB, ePtr<eDVBService> >::iterator it(m_services.find(service));
1218 if (it != m_services.end())
1219 it->second->m_flags &= ~flagmask;
1225 RESULT eDVBDB::removeFlags(unsigned int flagmask, int dvb_namespace, int tsid, int onid, unsigned int orb_pos)
1227 return removeFlags(flagmask, eDVBChannelID(eDVBNamespace(dvb_namespace), eTransportStreamID(tsid), eOriginalNetworkID(onid)), orb_pos);
1230 RESULT eDVBDB::removeFlags(unsigned int flagmask, eDVBChannelID chid, unsigned int orbpos)
1233 eTransportStreamID eTsid;
1234 eOriginalNetworkID eOnid;
1235 std::map<eDVBChannelID, channel>::iterator it(m_channels.begin());
1236 std::set<eDVBChannelID> removed_chids;
1237 while (it != m_channels.end())
1239 const eDVBChannelID &ch = it->first;
1242 it->second.m_frontendParameters->getSystem(system);
1243 if ( orbpos != 0xFFFFFFFF && system == iDVBFrontend::feSatellite )
1245 eDVBFrontendParametersSatellite sat;
1246 it->second.m_frontendParameters->getDVBS(sat);
1247 if ((unsigned int)sat.orbital_position != orbpos)
1250 if ( remove && chid.dvbnamespace != eNs && chid.dvbnamespace != ch.dvbnamespace )
1252 if ( remove && chid.original_network_id != eOnid && chid.original_network_id != ch.original_network_id )
1254 if ( remove && chid.transport_stream_id != eTsid && chid.transport_stream_id != ch.transport_stream_id )
1257 removed_chids.insert(it->first);
1260 if (!removed_chids.empty())
1262 std::map<eServiceReferenceDVB, ePtr<eDVBService> >::iterator service(m_services.begin());
1263 while(service != m_services.end())
1266 service->first.getChannelID(chid);
1267 std::set<eDVBChannelID>::iterator it(removed_chids.find(chid));
1268 if (it != removed_chids.end())
1269 service->second->m_flags &= ~flagmask;
1276 RESULT eDVBDB::addChannelToList(const eDVBChannelID &id, iDVBFrontendParameters *feparm)
1280 ch.m_frontendParameters = feparm;
1281 m_channels.insert(std::pair<eDVBChannelID, channel>(id, ch));
1285 RESULT eDVBDB::removeChannel(const eDVBChannelID &id)
1287 m_channels.erase(id);
1291 RESULT eDVBDB::getChannelFrontendData(const eDVBChannelID &id, ePtr<iDVBFrontendParameters> &parm)
1293 std::map<eDVBChannelID, channel>::iterator i = m_channels.find(id);
1294 if (i == m_channels.end())
1299 parm = i->second.m_frontendParameters;
1303 RESULT eDVBDB::addService(const eServiceReferenceDVB &serviceref, eDVBService *service)
1305 std::map<eServiceReferenceDVB, ePtr<eDVBService> >::iterator it(m_services.find(serviceref));
1306 if (it == m_services.end())
1307 m_services.insert(std::pair<eServiceReferenceDVB, ePtr<eDVBService> >(serviceref, service));
1311 RESULT eDVBDB::getService(const eServiceReferenceDVB &reference, ePtr<eDVBService> &service)
1313 std::map<eServiceReferenceDVB, ePtr<eDVBService> >::iterator i;
1314 i = m_services.find(reference);
1315 if (i == m_services.end())
1320 service = i->second;
1324 RESULT eDVBDB::flush()
1330 RESULT eDVBDB::getBouquet(const eServiceReference &ref, eBouquet* &bouquet)
1332 std::string str = ref.path;
1335 eDebug("getBouquet failed.. no path given!");
1338 unsigned int pos = str.find("FROM BOUQUET \"");
1339 if ( pos != std::string::npos )
1341 str.erase(0, pos+14);
1342 pos = str.find('"');
1343 if ( pos != std::string::npos )
1350 eDebug("getBouquet failed.. couldn't parse bouquet name");
1353 std::map<std::string, eBouquet>::iterator i =
1354 m_bouquets.find(str);
1355 if (i == m_bouquets.end())
1360 bouquet = &i->second;
1364 RESULT eDVBDB::startQuery(ePtr<iDVBChannelListQuery> &query, eDVBChannelQuery *q, const eServiceReference &source)
1366 if ( source.path.find("FROM") != std::string::npos )
1368 if ( source.path.find("BOUQUET") != std::string::npos )
1369 query = new eDVBDBBouquetQuery(this, source, q);
1370 else if ( source.path.find("SATELLITES") != std::string::npos )
1371 query = new eDVBDBSatellitesQuery(this, source, q);
1372 else if ( source.path.find("PROVIDERS") != std::string::npos )
1373 query = new eDVBDBProvidersQuery(this, source, q);
1375 eFatal("invalid query %s", source.toString().c_str());
1378 query = new eDVBDBQuery(this, source, q);
1382 eServiceReference eDVBDB::searchReference(int tsid, int onid, int sid)
1384 eServiceID Sid(sid);
1385 eTransportStreamID Tsid(tsid);
1386 eOriginalNetworkID Onid(onid);
1387 for (std::map<eServiceReferenceDVB, ePtr<eDVBService> >::iterator sit(m_services.begin());
1388 sit != m_services.end(); ++sit)
1390 if (sit->first.getTransportStreamID() == Tsid &&
1391 sit->first.getOriginalNetworkID() == Onid &&
1392 sit->first.getServiceID() == Sid)
1395 return eServiceReference();
1398 DEFINE_REF(eDVBDBQueryBase);
1400 eDVBDBQueryBase::eDVBDBQueryBase(eDVBDB *db, const eServiceReference &source, eDVBChannelQuery *query)
1401 :m_db(db), m_query(query), m_source(source)
1405 int eDVBDBQueryBase::compareLessEqual(const eServiceReferenceDVB &a, const eServiceReferenceDVB &b)
1407 ePtr<eDVBService> a_service, b_service;
1408 int sortmode = m_query ? m_query->m_sort : eDVBChannelQuery::tName;
1410 if ((sortmode == eDVBChannelQuery::tName) || (sortmode == eDVBChannelQuery::tProvider))
1412 if (a.name.empty() && m_db->getService(a, a_service))
1414 if (b.name.empty() && m_db->getService(b, b_service))
1420 case eDVBChannelQuery::tName:
1424 return a_service->m_service_name_sort < b_service->m_service_name_sort;
1427 std::string str = b.name;
1429 return a_service->m_service_name_sort < str;
1434 std::string str = a.name;
1436 return str < b_service->m_service_name_sort;
1440 std::string aa = a.name, bb = b.name;
1445 case eDVBChannelQuery::tProvider:
1446 return a_service->m_provider_name < b_service->m_provider_name;
1447 case eDVBChannelQuery::tType:
1448 return a.getServiceType() < b.getServiceType();
1449 case eDVBChannelQuery::tBouquet:
1451 case eDVBChannelQuery::tSatellitePosition:
1452 return (a.getDVBNamespace().get() >> 16) < (b.getDVBNamespace().get() >> 16);
1459 eDVBDBQuery::eDVBDBQuery(eDVBDB *db, const eServiceReference &source, eDVBChannelQuery *query)
1460 :eDVBDBQueryBase(db, source, query)
1462 m_cursor = m_db->m_services.begin();
1465 RESULT eDVBDBQuery::getNextResult(eServiceReferenceDVB &ref)
1467 while (m_cursor != m_db->m_services.end())
1469 ref = m_cursor->first;
1471 int res = (!m_query) || m_cursor->second->checkFilter(ref, *m_query);
1479 ref.type = eServiceReference::idInvalid;
1484 eDVBDBBouquetQuery::eDVBDBBouquetQuery(eDVBDB *db, const eServiceReference &source, eDVBChannelQuery *query)
1485 :eDVBDBQueryBase(db, source, query), m_cursor(db->m_bouquets[query->m_bouquet_name].m_services.begin())
1489 RESULT eDVBDBBouquetQuery::getNextResult(eServiceReferenceDVB &ref)
1491 eBouquet &bouquet = m_db->m_bouquets[m_query->m_bouquet_name];
1492 std::list<eServiceReference> &list = bouquet.m_services;
1493 while (m_cursor != list.end())
1495 ref = *((eServiceReferenceDVB*)&(*m_cursor));
1497 std::map<eServiceReferenceDVB, ePtr<eDVBService> >::iterator it =
1498 m_db->m_services.find(ref);
1500 int res = (!m_query) || it == m_db->m_services.end() || it->second->checkFilter(ref, *m_query);
1508 ref.type = eServiceReference::idInvalid;
1513 eDVBDBListQuery::eDVBDBListQuery(eDVBDB *db, const eServiceReference &source, eDVBChannelQuery *query)
1514 :eDVBDBQueryBase(db, source, query), m_cursor(m_list.end())
1518 RESULT eDVBDBListQuery::getNextResult(eServiceReferenceDVB &ref)
1520 if (m_cursor != m_list.end())
1525 ref.type = eServiceReference::idInvalid;
1529 int eDVBDBListQuery::compareLessEqual(const eServiceReferenceDVB &a, const eServiceReferenceDVB &b)
1531 if ( m_query->m_sort == eDVBChannelQuery::tSatellitePosition )
1533 int x = (a.getDVBNamespace().get() >> 16);
1534 int y = (b.getDVBNamespace().get() >> 16);
1541 std::string aa = a.name, bb = b.name;
1547 eDVBDBSatellitesQuery::eDVBDBSatellitesQuery(eDVBDB *db, const eServiceReference &source, eDVBChannelQuery *query)
1548 :eDVBDBListQuery(db, source, query)
1550 std::set<unsigned int> found;
1551 for (std::map<eServiceReferenceDVB, ePtr<eDVBService> >::iterator it(m_db->m_services.begin());
1552 it != m_db->m_services.end(); ++it)
1554 int res = it->second->checkFilter(it->first, *query);
1557 unsigned int dvbnamespace = it->first.getDVBNamespace().get()&0xFFFF0000;
1558 if (found.find(dvbnamespace) == found.end())
1560 found.insert(dvbnamespace);
1561 eServiceReferenceDVB ref;
1562 ref.setDVBNamespace(dvbnamespace);
1563 ref.flags=eServiceReference::flagDirectory;
1565 snprintf(buf, 128, "(satellitePosition == %d) && ", dvbnamespace>>16);
1567 ref.path=buf+source.path;
1568 unsigned int pos=ref.path.find("FROM");
1569 ref.path.erase(pos);
1570 ref.path+="ORDER BY name";
1571 // eDebug("ref.path now %s", ref.path.c_str());
1572 m_list.push_back(ref);
1574 ref.path=buf+source.path;
1575 pos=ref.path.find("FROM");
1576 ref.path.erase(pos+5);
1577 ref.path+="PROVIDERS ORDER BY name";
1578 // eDebug("ref.path now %s", ref.path.c_str());
1579 m_list.push_back(ref);
1581 snprintf(buf, 128, "(satellitePosition == %d) && (flags == %d) && ", dvbnamespace>>16, eDVBService::dxNewFound);
1582 ref.path=buf+source.path;
1583 pos=ref.path.find("FROM");
1584 ref.path.erase(pos);
1585 ref.path+="ORDER BY name";
1586 // eDebug("ref.path now %s", ref.path.c_str());
1587 m_list.push_back(ref);
1591 m_cursor=m_list.begin();
1594 eDVBDBProvidersQuery::eDVBDBProvidersQuery(eDVBDB *db, const eServiceReference &source, eDVBChannelQuery *query)
1595 :eDVBDBListQuery(db, source, query)
1597 std::set<std::string> found;
1598 for (std::map<eServiceReferenceDVB, ePtr<eDVBService> >::iterator it(m_db->m_services.begin());
1599 it != m_db->m_services.end(); ++it)
1601 int res = it->second->checkFilter(it->first, *query);
1604 const char *provider_name = it->second->m_provider_name.length() ?
1605 it->second->m_provider_name.c_str() :
1607 if (found.find(std::string(provider_name)) == found.end())
1609 found.insert(std::string(provider_name));
1610 eServiceReferenceDVB ref;
1612 ref.name=provider_name;
1613 snprintf(buf, 64, "(provider == \"%s\") && ", provider_name);
1614 ref.path=buf+source.path;
1615 unsigned int pos = ref.path.find("FROM");
1616 ref.flags=eServiceReference::flagDirectory;
1617 ref.path.erase(pos);
1618 ref.path+="ORDER BY name";
1619 // eDebug("ref.path now %s", ref.path.c_str());
1620 m_list.push_back(ref);
1624 m_cursor=m_list.begin();
1627 /* (<name|provider|type|bouquet|satpos|chid> <==|...> <"string"|int>)[||,&& (..)] */
1629 static int decodeType(const std::string &type)
1632 return eDVBChannelQuery::tName;
1633 else if (type == "provider")
1634 return eDVBChannelQuery::tProvider;
1635 else if (type == "type")
1636 return eDVBChannelQuery::tType;
1637 else if (type == "bouquet")
1638 return eDVBChannelQuery::tBouquet;
1639 else if (type == "satellitePosition")
1640 return eDVBChannelQuery::tSatellitePosition;
1641 else if (type == "channelID")
1642 return eDVBChannelQuery::tChannelID;
1643 else if (type == "flags")
1644 return eDVBChannelQuery::tFlags;
1649 /* never, NEVER write a parser in C++! */
1650 RESULT parseExpression(ePtr<eDVBChannelQuery> &res, std::list<std::string>::const_iterator begin, std::list<std::string>::const_iterator end)
1652 std::list<std::string>::const_iterator end_of_exp;
1660 while (end_of_exp != end)
1661 if (*end_of_exp == ")")
1666 if (end_of_exp == end)
1668 eDebug("expression parse: end of expression while searching for closing brace");
1673 // begin..end_of_exp
1674 int r = parseExpression(res, begin, end_of_exp);
1679 /* we had only one sub expression */
1680 if (end_of_exp == end)
1682 // eDebug("only one sub expression");
1686 /* otherwise we have an operator here.. */
1688 ePtr<eDVBChannelQuery> r2 = res;
1689 res = new eDVBChannelQuery();
1695 if (*end_of_exp == "||")
1696 res->m_type = eDVBChannelQuery::tOR;
1697 else if (*end_of_exp == "&&")
1698 res->m_type = eDVBChannelQuery::tAND;
1701 eDebug("found operator %s, but only && and || are allowed!", end_of_exp->c_str());
1708 return parseExpression(res->m_p2, end_of_exp, end);
1711 // "begin" <op> "end"
1712 std::string type, op, val;
1714 res = new eDVBChannelQuery();
1718 while (begin != end)
1732 eDebug("malformed query: got '%s', but expected only <type> <op> <val>", begin->c_str());
1741 eDebug("malformed query: missing stuff");
1746 res->m_type = decodeType(type);
1748 if (res->m_type == -1)
1750 eDebug("malformed query: invalid type %s", type.c_str());
1757 else if (op == "!=")
1761 eDebug("invalid operator %s", op.c_str());
1766 res->m_string = val;
1768 if (res->m_type == eDVBChannelQuery::tChannelID)
1771 if (sscanf(val.c_str(), "%08x%04x%04x", &ns, &tsid, &onid) == 3)
1772 res->m_channelid = eDVBChannelID(eDVBNamespace(ns), eTransportStreamID(tsid), eOriginalNetworkID(onid));
1774 eDebug("couldn't parse channelid !! format should be hex NNNNNNNNTTTTOOOO (namespace, tsid, onid)");
1777 res->m_int = atoi(val.c_str());
1782 RESULT eDVBChannelQuery::compile(ePtr<eDVBChannelQuery> &res, std::string query)
1784 std::list<std::string> tokens;
1786 std::string current_token;
1787 std::string bouquet_name;
1789 // eDebug("splitting %s....", query.c_str());
1791 const char *splitchars="()";
1792 int quotemode = 0, lastsplit = 0, lastalnum = 0;
1793 while (i <= query.size())
1795 int c = (i < query.size()) ? query[i] : ' ';
1798 int issplit = !!strchr(splitchars, c);
1799 int isaln = isalnum(c);
1800 int iswhite = c == ' ';
1801 int isquot = c == '\"';
1805 iswhite = issplit = 0;
1809 if (issplit || iswhite || isquot || lastsplit || (lastalnum != isaln))
1811 if (current_token.size())
1812 tokens.push_back(current_token);
1813 current_token.clear();
1816 if (!(iswhite || isquot))
1820 quotemode = !quotemode;
1821 lastsplit = issplit;
1825 // for (std::list<std::string>::const_iterator a(tokens.begin()); a != tokens.end(); ++a)
1827 // printf("%s\n", a->c_str());
1830 int sort = eDVBChannelQuery::tName;
1831 /* check for "ORDER BY ..." */
1833 std::list<std::string>::iterator it = tokens.begin();
1834 while (it != tokens.end())
1839 if (it != tokens.end() && *it == "BY")
1842 sort = decodeType(*it);
1847 else if (*it == "FROM")
1850 if (it != tokens.end() && *it == "BOUQUET")
1856 else if (it != tokens.end() && *it == "SATELLITES")
1858 else if (it != tokens.end() && *it == "PROVIDERS")
1862 eDebug("FROM unknown %s", (*it).c_str());
1872 eWarning("ORDER BY .. string invalid.");
1877 // eDebug("sort by %d", sort);
1879 /* now we recursivly parse that. */
1880 int r = parseExpression(res, tokens.begin(), tokens.end());
1882 /* we have an empty (but valid!) expression */
1885 res = new eDVBChannelQuery();
1887 res->m_type = eDVBChannelQuery::tAny;
1893 res->m_bouquet_name = bouquet_name;
1896 // eDebug("return: %d", r);
1900 DEFINE_REF(eDVBChannelQuery);