diff --git a/src/eitd/SIevents.cpp b/src/eitd/SIevents.cpp index 65cd6b850..18705d6e6 100644 --- a/src/eitd/SIevents.cpp +++ b/src/eitd/SIevents.cpp @@ -40,10 +40,6 @@ #include "SIutils.hpp" #include "SIservices.hpp" #include "SIevents.hpp" -#ifdef UPDATE_NETWORKS -#include "SIbouquets.hpp" -#include "SInetworks.hpp" -#endif #include "SIsections.hpp" #include diff --git a/src/eitd/SIsections.cpp b/src/eitd/SIsections.cpp index 3e66e1a9d..862030700 100644 --- a/src/eitd/SIsections.cpp +++ b/src/eitd/SIsections.cpp @@ -37,23 +37,13 @@ #include "SIutils.hpp" #include "SIservices.hpp" #include "SIevents.hpp" -#ifdef UPDATE_NETWORKS -#include "SIbouquets.hpp" -#include "SInetworks.hpp" -#endif #include "SIsections.hpp" -#include #include #include #ifdef ENABLE_FREESATEPG #include "FreesatTables.hpp" #endif -#define NOVA 0x3ffe -#define CANALDIGITAAL 0x3fff - -//#define DEBUG - struct descr_generic_header { unsigned descriptor_tag : 8; unsigned descriptor_length : 8; @@ -869,401 +859,3 @@ void SIsectionSDT::parse(void) parsed = 1; } -#ifdef UPDATE_NETWORKS -/************************************/ -/* -//Within the Service List all Channels of a bouquet are specified -int SIsectionBAT::parseServiceListDescriptor(const char *buf, SIbouquet &s, int section_no, int count) -{ - struct descr_generic_header *sv=(struct descr_generic_header *)buf; - buf+=sizeof(struct descr_generic_header); - unsigned short len = sv->descriptor_length; - while(len >= sizeof(struct service_list_entry)) { - struct service_list_entry *sl=(struct service_list_entry *)buf; - buf+=sizeof(struct service_list_entry); - SIbouquet bs(s); - bs.service_id=(sl->service_id_hi << 8) | sl->service_id_lo; - bs.serviceTyp=sl->service_type; - bs.position = (uint16_t) (((section_no & 0x1f) << 11) + (count & 0x7ff)); -// printf("Section Number: %d Count: %d position: %04x\n", section_no, count, bs.position); - bsv.insert(bs); - len -= sizeof(struct service_list_entry); - count++; - } - return count; -} - -void SIsectionBAT::parseBouquetNameDescriptor(const char *buf, SIbouquet &s) -{ - struct descr_generic_header *sv=(struct descr_generic_header *)buf; - buf+=sizeof(struct descr_generic_header); - if(sv->descriptor_length) { - -// if(*buf < 0x06) // other code table - // s.bouquetName=std::string(buf+1, sv->descriptor_length-1); - //else - //s.bouquetName=std::string(buf, sv->descriptor_length); - - s.bouquetName = CDVBString((const char *)(buf), sv->descriptor_length).getContent(); - } - //printf("Bouquet-Name: %s\n", s.bouquetName.c_str()); -} - -int SIsectionBAT::parseDescriptors(const char *des, unsigned len, SIbouquet &s, int section_no, int count, const char *bouquetName) -{ - struct descr_generic_header *desc; - while(len>=sizeof(struct descr_generic_header)) { - desc=(struct descr_generic_header *)des; -// printf("Type: %s\n", decode_descr(desc->descriptor_tag)); -// printf("Length: %hhu\n", desc->descriptor_length); - if(desc->descriptor_tag==0x41) { -// printf("Found service list descriptor\n"); - count = parseServiceListDescriptor((const char *)desc, s, section_no, count); - } -// else if(desc->descriptor_tag==0x47) { -// printf("Found bouquet name descriptor\n"); -// parseBouquetNameDescriptor((const char *)desc, s); -// } - len-=desc->descriptor_length+2; - des+=desc->descriptor_length+2; - } - return count; -} -*/ -// Die infos aus dem Puffer holen -void SIsectionBAT::parse(void) -{ - const char *actPos; - struct bat_service *sv; -// struct bouquet_ident bi; - struct SI_section_BAT_header *bh; - unsigned short descriptors_loop_length; - unsigned short descriptors_length; - uint32_t current_private_data_specifier; - struct loop_len *ll; -// std::string bouquetName = ""; - - if (!buffer || parsed) - return; - - if (bufferLength < sizeof(SI_section_BAT_header) + sizeof(struct bat_service)) { - printf("BAT fix?\n"); //No Services possible - length too short - bufferLength=0; - return; - } - - actPos = &buffer[0]; // We need Bouquet ID and bouquet descriptor length from header - bh = (struct SI_section_BAT_header *)actPos; // Header - t_bouquet_id bouquet_id = (bh->bouquet_id_hi << 8) | bh->bouquet_id_lo; -// printf("hi: %hu lo: %hu\n", bh->bouquet_descriptors_length_hi, bh->bouquet_descriptors_length_lo); - descriptors_loop_length = (bh->bouquet_descriptors_length_hi << 8) | bh->bouquet_descriptors_length_lo; -// SIbouquet s((bh->bouquet_id_hi << 8) | bh->bouquet_id_lo); //Create a new Bouquet entry -// printf("ident: %hu actpos: %p buf+bl: %p desclen: %hu\n", bi.bouquet_id, actPos, buffer+bufferLength, descriptors_loop_length); - int count = 0; - //Fill out Bouquet Name - //count = parseDescriptors(((const char *)bh) + sizeof(SI_section_BAT_header), descriptors_loop_length, s, bh->section_number, count); - const char *des = ((const char *)bh) + sizeof(SI_section_BAT_header); - unsigned len = descriptors_loop_length; - struct descr_generic_header *desc; - struct descr_generic_header *privdesc = NULL; - std::string bouquetName = ""; - current_private_data_specifier = 0; - while(len>=sizeof(struct descr_generic_header)) { - desc=(struct descr_generic_header *)des; - if(desc->descriptor_tag==0x47) { -// printf("Found bouquet name descriptor\n"); - //parseBouquetNameDescriptor((const char *)desc, s); - const char *buf = (const char *) desc; - //struct descr_generic_header *sv=(struct descr_generic_header *)buf; - buf+=sizeof(struct descr_generic_header); - if(desc->descriptor_length) { - /* - if(*buf < 0x06) // other code table - s.bouquetName=std::string(buf+1, sv->descriptor_length-1); - else - s.bouquetName=std::string(buf, sv->descriptor_length); - */ - //Mega stupid providers do not reserve their own bouquet_id - //So we do it for them... f*ck that's stupid too, but what else can we do... - if (bouquet_id == 0x0001) { - if (!strncmp((const char *) buf, "NOVA", 4)) - bouquet_id = NOVA; - if (!strncmp((const char *) buf, "CanalDigitaal", 13)) - bouquet_id = CANALDIGITAAL; - } - - bouquetName = CDVBString((const char *)(buf), desc->descriptor_length).getContent(); - } - } - if (desc->descriptor_tag == 0x5f) { - const char *buf = (const char *) desc; - //struct descr_generic_header *sv=(struct descr_generic_header *)buf; - buf+=sizeof(struct descr_generic_header); - struct private_data_specifier *pds=(struct private_data_specifier *)buf; - buf+=sizeof(struct private_data_specifier); - current_private_data_specifier=(((pds->byte1 << 24) | (pds->byte2 << 16)) | (pds->byte3 << 8)) | pds->byte4; - //printf("Private Data Specifier: %08x\n", current_private_data_specifier); - } - len-=desc->descriptor_length+2; - des+=desc->descriptor_length+2; - } - //s.bouquetName = bouquetName; - - actPos += sizeof(SI_section_BAT_header) + descriptors_loop_length; - - ll = (struct loop_len *)actPos; - descriptors_loop_length = (ll->descriptors_loop_length_hi << 8) | ll->descriptors_loop_length_lo; //len is not used at the moment -// printf("desclen: %hu\n", descriptors_loop_length); - actPos += sizeof(loop_len); - - if (bouquet_id != 0x0001) { - while (actPos <= &buffer[bufferLength - sizeof(struct bat_service)]) { - sv = (struct bat_service *)actPos; - //s.transport_stream_id = (sv->transport_stream_id_hi << 8) | sv->transport_stream_id_lo; - //s.original_network_id = (sv->original_network_id_hi << 8) | sv->original_network_id_lo; - // s.position = (uint16_t) (((bh->section_number & 0x1f) << 11) + (count & 0x7ff)); - // printf("Section Number: %d Count: %d position: %04x\n", bh->section_number, count, s.position); - descriptors_length = (sv->descriptors_loop_length_hi << 8) | sv->descriptors_loop_length_lo; - // Transport Stream Loop - //count = parseDescriptors(((const char *)sv) + sizeof(struct bat_service), descriptors_length, s, bh->section_number, count, - //(const char *) bouquetName[0]); - bool found = false; - int loop_count = 1; - while (loop_count >= 0) { - - const char *des_ = ((const char *)sv) + sizeof(struct bat_service); - len = descriptors_length; - - while(len>=sizeof(struct descr_generic_header)) { - desc=(struct descr_generic_header *)des_; -// printf("Type: %s\n", decode_descr(desc->descriptor_tag)); -// printf("Length: %hhu\n", desc->descriptor_length); - const char *buf = (const char *) desc; - buf+=sizeof(struct descr_generic_header); - unsigned short dlen = desc->descriptor_length; - if ((desc->descriptor_tag==0x41) && (loop_count == 0) && (current_private_data_specifier != 0x00000002)) { -// printf("Found service list descriptor\n"); - //count = parseServiceListDescriptor((const char *)desc, s, section_no, count); - //struct descr_generic_header *sv=(struct descr_generic_header *)buf; - - while(dlen >= sizeof(struct service_list_entry)) { - struct service_list_entry *sl=(struct service_list_entry *)buf; - buf+=sizeof(struct service_list_entry); - SIbouquet bs(bouquet_id); - bs.bouquetName = bouquetName; - bs.transport_stream_id = (sv->transport_stream_id_hi << 8) | sv->transport_stream_id_lo; - bs.original_network_id = (sv->original_network_id_hi << 8) | sv->original_network_id_lo; - bs.service_id=(sl->service_id_hi << 8) | sl->service_id_lo; - bs.serviceTyp=sl->service_type; - bs.position = (uint16_t) (((bh->section_number & 0x1f) << 11) + (count & 0x7ff)); - if (found) { - const char *privbuf = (const char *) privdesc; - privbuf+=sizeof(struct descr_generic_header); - unsigned short privdlen = privdesc->descriptor_length; - bool found_posi = false; - int order_entry_size; - order_entry_size = sizeof(struct digplus_order_entry); - while ((privdlen >= order_entry_size) && (!found_posi)) { - struct digplus_order_entry *oe = (struct digplus_order_entry *)privbuf; - privbuf+=order_entry_size; - /* - printf("Search: %04x Service_id: %04x Posi:%04x\n", - (sl->service_id_hi << 8) | sl->service_id_lo, - (oe->service_id_hi << 8) | oe->service_id_lo, - (oe->channel_number_hi << 8) | oe->channel_number_lo); - */ - if ( ((sl->service_id_hi << 8) | sl->service_id_lo) == - ((oe->service_id_hi << 8) | oe->service_id_lo)) { - bs.position = (oe->channel_number_hi << 8) | oe->channel_number_lo; - /* - printf("Found Search: %04x Service_id: %04x Posi:%04x\n", - (sl->service_id_hi << 8) | sl->service_id_lo, - current_service_id, - current_channel_number); - */ - found_posi=true; - } - privdlen -= order_entry_size; - } - if (!found_posi) - bs.position = 0xffff; - } -// printf("Section Number: %d Count: %d position: %04x\n", section_no, count, bs.position); - //printf("Set Position: %04x\n",bs.position); - bsv.insert(bs); - dlen -= sizeof(struct service_list_entry); - count++; - } - } - if (desc->descriptor_tag == 0x5f) { - struct private_data_specifier *pds=(struct private_data_specifier *)buf; - buf+=sizeof(struct private_data_specifier); - if ((pds->byte1 != 0) || (pds->byte2 != 0) || (pds->byte3 != 0) || (pds->byte4 != 0)) - current_private_data_specifier=(((pds->byte1 << 24) | (pds->byte2 << 16)) | - (pds->byte3 << 8)) | pds->byte4; - //printf("Private Data Specifier: %08x\n", current_private_data_specifier); - } - if (desc->descriptor_tag == 0x81) { - if (current_private_data_specifier == 0x55504300) { - //printf("UPC Bouquet ordering descriptor found!\n"); - privdesc = (struct descr_generic_header *)desc; - found = true; - } - } - if (desc->descriptor_tag == 0x82) { - if ((current_private_data_specifier == 0x00000010) || (bouquet_id == 0x0021)) { - //printf("TPS Bouquet ordering descriptor found!\n"); - privdesc = (struct descr_generic_header *)desc; - found = true; - } - } - if (desc->descriptor_tag == 0x83) { - if ((current_private_data_specifier == 0x000000c0) || (current_private_data_specifier == 0x0000003a)) { - //printf("Canal+ Bouquet ordering descriptor found!\n"); - privdesc = (struct descr_generic_header *)desc; - found = true; - } - } - if (desc->descriptor_tag == 0x93) { - if ((current_private_data_specifier == 0x00362275) || (bouquet_id == CANALDIGITAAL)) { - //printf("Irdeto Bouquet ordering descriptor found!\n"); - privdesc = (struct descr_generic_header *)desc; - found = true; - } - } - if ((desc->descriptor_tag == 0xb1) && (loop_count == 0)) { - if (current_private_data_specifier == 0x00000002) { - //printf("BSkyB Bouquet ordering descriptor found!\n"); - const char *privbuf = (const char *) desc; - privbuf+=sizeof(struct descr_generic_header); - unsigned short privdlen = desc->descriptor_length - 2; - //Nirvana 27.4.06: first 2 bytes still unknown: always 0xffff on sky italia? - //check if resulting bouquets on 28.2E look more sensible... - struct bskyb_bid *bid = (struct bskyb_bid *)privbuf; - if ((bid->unknown1 == 0xff) && (bid->unknown2 == 0xff)) { - - privbuf+=2; //first 2 bytes of each 0xb1 desc unknown - - while (privdlen >= sizeof(struct bskyb_order_entry)) { - struct bskyb_order_entry *oe = (struct bskyb_order_entry *)privbuf; - privbuf+=sizeof(struct bskyb_order_entry); - SIbouquet bs(bouquet_id); - bs.bouquetName = bouquetName; - bs.transport_stream_id = (sv->transport_stream_id_hi << 8) | - sv->transport_stream_id_lo; - bs.original_network_id = (sv->original_network_id_hi << 8) | - sv->original_network_id_lo; - bs.service_id = (oe->service_id_hi << 8) | oe->service_id_lo; - bs.serviceTyp = oe->service_type; - bs.position = (oe->channel_number_hi << 8) | oe->channel_number_lo; - bsv.insert(bs); - privdlen -= sizeof(struct bskyb_order_entry); - } - } - - } - } - len-=desc->descriptor_length+2; - des_+=desc->descriptor_length+2; - } - loop_count--; - } - - actPos += sizeof(struct bat_service) + descriptors_length; - // count++; - } - } - parsed = 1; -} - -void SIsectionNIT::copyDeliveryDescriptor(const char *buf, SInetwork &s) -{ - //struct descr_generic_header *sv=(struct descr_generic_header *)buf; - buf+=sizeof(struct descr_generic_header); - memmove(s.delivery_descriptor, buf, sizeof(struct satellite_delivery_descriptor)); //same size as cable... - //printf("Bouquet-Name: %s\n", s.bouquetName.c_str()); -} - -void SIsectionNIT::parseDescriptors(const char *des, unsigned len, SInetwork &s) -{ -// struct satellite_delivery_descriptor *sdd; -// const char *ddp; -// t_transport_stream_id tsid; -// t_original_network_id onid; -// unsigned short orbital_pos; - - struct descr_generic_header *desc; - des += sizeof(struct nit_transponder); - len -= sizeof(struct nit_transponder); - - while(len>=sizeof(struct descr_generic_header)) { - desc=(struct descr_generic_header *)des; -// printf("Type: %s\n", decode_descr(desc->descriptor_tag)); -// printf("Length: %hhu\n", desc->descriptor_length); - if ( (desc->descriptor_tag==0x43) || (desc->descriptor_tag==0x44) ) { - s.delivery_type = desc->descriptor_tag; -// printf("Found satellite_delivery_system_descriptor\n"); - copyDeliveryDescriptor((const char *)desc, s); -// ddp = &s.delivery_descriptor[0]; -// sdd = (struct satellite_delivery_descriptor *)ddp; -// tsid = s.transport_stream_id; -// onid = s.original_network_id; -// orbital_pos = (sdd->orbital_pos_hi << 8) | sdd->orbital_pos_lo; -// printf("ONID: %04x TSID: %04x Orbital Position: %d\n", onid, tsid, orbital_pos); - } - len-=desc->descriptor_length+2; - des+=desc->descriptor_length+2; - } -} - -// Die infos aus dem Puffer holen -void SIsectionNIT::parse(void) -{ - - const char *actPos; - const char *bufEnd; - struct nit_transponder *tp; - struct SI_section_NIT_header *nh; - unsigned short descriptors_loop_length; - unsigned short descriptors_length; - struct loop_len *ll; - //t_network_id network_id; - - if (!buffer || parsed) - return; - - if (bufferLength < sizeof(SI_section_NIT_header) + sizeof(struct nit_transponder)) { - printf("NIT fix?\n"); //No Services possible - length too short - bufferLength=0; - return; - } - - actPos = buffer; // We need Bouquet ID and bouquet descriptor length from header - bufEnd = buffer + bufferLength; - nh = (struct SI_section_NIT_header *)actPos; // Header -// printf("hi: %hu lo: %hu\n", bh->bouquet_descriptors_length_hi, bh->bouquet_descriptors_length_lo); - descriptors_loop_length = (nh->network_descriptors_length_hi << 8) | nh->network_descriptors_length_lo; -// SIbouquet s((bh->bouquet_id_hi << 8) | bh->bouquet_id_lo); //Create a new Bouquet entry -// printf("ident: %hu actpos: %p buf+bl: %p desclen: %hu\n", bi.bouquet_id, actPos, buffer+bufferLength, descriptors_loop_length); -// parseDescriptors(((const char *)bh) + sizeof(SI_section_BAT_header), descriptors_loop_length, s); //Fill out Bouquet Name - actPos += sizeof(SI_section_NIT_header) + descriptors_loop_length; - - ll = (struct loop_len *)actPos; - descriptors_loop_length = (ll->descriptors_loop_length_hi << 8) | ll->descriptors_loop_length_lo; //len is not used at the moment -// printf("desclen: %hu\n", descriptors_loop_length); - actPos += sizeof(loop_len); - - while (actPos <= bufEnd - sizeof(struct nit_transponder)) { - tp = (struct nit_transponder *)actPos; - SInetwork s(tp); - s.network_id = (nh->network_id_hi << 8) | nh->network_id_lo; - s.transport_stream_id = (tp->transport_stream_id_hi << 8) | tp->transport_stream_id_lo; - s.original_network_id = (tp->original_network_id_hi << 8) | tp->original_network_id_lo; - descriptors_length = sizeof(struct nit_transponder) + ((tp->descriptors_loop_length_hi << 8) | tp->descriptors_loop_length_lo); - parseDescriptors(actPos, min((unsigned)(bufEnd - actPos), descriptors_length), s); // Transport Stream Loop - ntw.insert(s); - actPos += descriptors_length; - } - parsed = 1; -} -#endif diff --git a/src/eitd/SIsections.hpp b/src/eitd/SIsections.hpp index c48e19eda..4e67b3955 100644 --- a/src/eitd/SIsections.hpp +++ b/src/eitd/SIsections.hpp @@ -26,10 +26,7 @@ // #include -#ifdef UPDATE_NETWORKS -#include "SInetworks.hpp" -#include "SIbouquets.hpp" -#endif + struct SI_section_SDT_header { unsigned table_id : 8; #if __BYTE_ORDER == __BIG_ENDIAN @@ -681,129 +678,4 @@ private: void parseNVODreferenceDescriptor(const char *buf, SIservice &s); }; -#ifdef UPDATE_NETWORKS -class SIsectionBAT : public SIsection -{ -public: - SIsectionBAT(const SIsection &s) : SIsection(s) { - parsed = 0; - parse(); - } - - // Std-Copy - SIsectionBAT(const SIsectionBAT &s) : SIsection(s) { - bsv = s.bsv; - parsed = s.parsed; - } - - // Benutzt den uebergebenen Puffer (sollte mit new char[n] allokiert sein) - SIsectionBAT(unsigned bufLength, char *buf) : SIsection(bufLength, buf) { - parsed = 0; - parse(); - } - - unsigned short bouquetID(void) const { - return buffer ? ((((struct SI_section_BAT_header *)buffer)->bouquet_id_hi << 8) | - ((struct SI_section_BAT_header *)buffer)->bouquet_id_lo) : (unsigned short) -1; - } - - struct SI_section_BAT_header const *header(void) const { - return (struct SI_section_BAT_header *)buffer; - } - - static void dump(const struct SI_section_BAT_header *header) { - if (!header) - return; - SIsection::dump1((const struct SI_section_header *)header); - printf("bouquet_id: 0x%02x%02x\n", header->bouquet_id_hi, header->bouquet_id_lo); - SIsection::dump2((const struct SI_section_header *)header); - printf("bouquet_descriptors_length %hu\n", - (header->bouquet_descriptors_length_hi << 8) | header->bouquet_descriptors_length_lo); - } - - static void dump(const SIsectionBAT &s) { - dump((struct SI_section_BAT_header *)s.buffer); - } - - void dump(void) const { - dump((struct SI_section_BAT_header *)buffer); - } - - const SIbouquets &bouquets(void) const { - //if(!parsed) - // parse(); -> nicht const - return bsv; - } - -protected: - SIbouquets bsv; - int parsed; - void parse(void); -// int parseDescriptors(const char *desc, unsigned len, SIbouquet &s, int section_no, int count, const char *bouquetName); -// void parseBouquetNameDescriptor(const char *buf, SIbouquet &s); -// int parseServiceListDescriptor(const char *buf, SIbouquet &s, int section_no, int count); -}; - -class SIsectionNIT : public SIsection -{ -public: - SIsectionNIT(const SIsection &s) : SIsection(s) { - parsed = 0; - parse(); - } - - // Std-Copy - SIsectionNIT(const SIsectionNIT &s) : SIsection(s) { - ntw = s.ntw; - parsed = s.parsed; - } - - // Benutzt den uebergebenen Puffer (sollte mit new char[n] allokiert sein) - SIsectionNIT(unsigned bufLength, char *buf) : SIsection(bufLength, buf) { - parsed = 0; - parse(); - } - - unsigned short networkID(void) const { - return buffer ? ((((struct SI_section_NIT_header *)buffer)->network_id_hi << 8) | - ((struct SI_section_NIT_header *)buffer)->network_id_lo) : (unsigned short) -1; - } - - struct SI_section_NIT_header const *header(void) const { - return (struct SI_section_NIT_header *)buffer; - } - - static void dump(const struct SI_section_NIT_header *header) { - if (!header) - return; - SIsection::dump1((const struct SI_section_header *)header); - printf("network_id: 0x%02x%02x\n", header->network_id_hi, header->network_id_lo); - SIsection::dump2((const struct SI_section_header *)header); - printf("network_descriptors_length %hu\n", - (header->network_descriptors_length_hi << 8) | header->network_descriptors_length_lo); - } - - static void dump(const SIsectionNIT &s) { - dump((struct SI_section_NIT_header *)s.buffer); - } - - void dump(void) const { - dump((struct SI_section_NIT_header *)buffer); - } - - const SInetworks &networks(void) const { - //if(!parsed) - // parse(); -> nicht const - return ntw; - } - -protected: - SInetworks ntw; - int parsed; - void parse(void); - void parseDescriptors(const char *desc, unsigned len, SInetwork &s); - void copyDeliveryDescriptor(const char *buf, SInetwork &s); -}; -#endif - #endif // SISECTIONS_HPP diff --git a/src/eitd/sectionsd.cpp b/src/eitd/sectionsd.cpp index 8bc3af35c..c5f4846de 100644 --- a/src/eitd/sectionsd.cpp +++ b/src/eitd/sectionsd.cpp @@ -80,10 +80,6 @@ #include "SIutils.hpp" #include "SIservices.hpp" #include "SIevents.hpp" -#ifdef UPDATE_NETWORKS -#include "SIbouquets.hpp" -#include "SInetworks.hpp" -#endif #include "SIsections.hpp" #include "SIlanguage.hpp" @@ -241,10 +237,6 @@ static DMX dmxEIT(0x12, 3000 /*320*/); static DMX dmxFSEIT(3842, 320); #endif static DMX dmxCN(0x12, 512, false, 1); -#ifdef UPDATE_NETWORKS -static DMX dmxSDT(0x11, 512, true, 1); -static DMX dmxNIT(0x10, 128); -#endif #ifdef ENABLE_PPT // Houdini: added for Premiere Private EPG section for Sport/Direkt Portal static DMX dmxPPT(0x00, 256); @@ -1072,45 +1064,6 @@ static void addNVODevent(const SIevent &evt) } } -#ifdef UPDATE_NETWORKS -xmlNodePtr getProvbyPosition(xmlNodePtr node, const int position) { - while (node) { - if (xmlGetSignedNumericAttribute(node, "position", 16) == position) - return node; - node = node->xmlNextNode; - } - return NULL; -} - -//Parses services.xml and delivers the node with the concerning transponder -xmlNodePtr FindTransponder(xmlNodePtr provider, const t_original_network_id onid, const t_transport_stream_id tsid) -{ - //EUTELSAT & SIRIUS: This is for you: Obey DVB rules please!!! Neither of you is allowed to use onid 0001! FIX IT! - if ( (tsid == 1) && (onid == 1) ) { - if ((getProvbyPosition(provider, 0x50) != NULL) && (getProvbyPosition(provider, 0x130) != NULL)) { - //If 5E and 13E are used together we can't determine whose SDT this is. - printf("Sirius and Eutelsat suck big time!\n"); - return NULL; - } - } - - while (provider) - { - dprintf("going to search dvb-%c provider %s\n", xmlGetName(provider)[0], xmlGetAttribute(provider, "name")); - xmlNodePtr transponder = provider->xmlChildrenNode; - - while (transponder) - { - if ((xmlGetNumericAttribute(transponder, "id", 16) == tsid) && (xmlGetNumericAttribute(transponder, "onid", 16) == onid)) - return transponder; - else - transponder = transponder->xmlNextNode; - } - provider = provider->xmlNextNode; - } - return NULL; -} -#endif static void removeOldEvents(const long seconds) { bool goodtimefound; @@ -1202,97 +1155,9 @@ static void removeDupEvents(void) } #endif -#ifdef UPDATE_NETWORKS -static void removeWasteEvents() -{ - bool haslinkage; - bool validevent; - xmlDocPtr service_parser = parseXmlFile(SERVICES_XML); - - xmlNodePtr services_tp; - xmlNodePtr node; - - t_service_id last_service_id = 0; - t_original_network_id last_original_network_id = 0; - t_transport_stream_id last_transport_stream_id = 0; - bool lastidfound = true; - - readLockEvents(); - - MySIeventsOrderUniqueKey::iterator e = mySIeventsOrderUniqueKey.begin(); - - while ((e != mySIeventsOrderUniqueKey.end()) && (!messaging_zap_detected)) { - unlockEvents(); - validevent = true; - haslinkage = false; - if ((last_original_network_id == e->second->original_network_id) && - (last_transport_stream_id == e->second->transport_stream_id) && - (last_service_id == e->second->service_id)) { - if (!lastidfound) { - validevent = false; - dprintf("Same ONID:%04x TSID:%04x SID:%04x\n",last_original_network_id, - last_transport_stream_id, - last_service_id); - } - } - else { - for (unsigned int i = 0; i < e->second->linkage_descs.size(); i++) - if ((e->second->linkage_descs[i].linkageType == 0xB0) || - (e->second->linkage_descs[i].linkageType == 0x00)) - { - haslinkage = true; - break; - } -// printf("here1\n"); - if (validevent && !haslinkage) { -// printf("here2\n"); - if (service_parser != NULL) { -// printf("here3\n"); - services_tp = FindTransponder(xmlDocGetRootElement(service_parser) - ->xmlChildrenNode,e->second->original_network_id, - e->second->transport_stream_id); - if ( services_tp ) { -// printf("here4\n"); - node = services_tp->xmlChildrenNode; - while (xmlGetNextOccurence(node, "channel") != NULL) { -// printf("here5\n"); - if (e->second->service_id != xmlGetNumericAttribute(node, - "service_id", 16)) - node = node->xmlNextNode; - else break; - } -// printf("here6\n"); - if (xmlGetNextOccurence(node, "channel") == NULL) - validevent = false; - } else validevent = false; - } else validevent = false; - lastidfound = validevent; - if (!lastidfound) - dprintf("Wasted ONID:%04x TSID:%04x SID:%04x\n", - e->second->original_network_id, - e->second->transport_stream_id, - e->second->service_id); - } else lastidfound = true; - last_service_id = e->second->service_id; - last_original_network_id = e->second->original_network_id; - last_transport_stream_id = e->second->transport_stream_id; - } - - if (!validevent) - deleteEvent((e++)->first); - else - ++e; - readLockEvents(); - } - unlockEvents(); - - xmlFreeDoc(service_parser); - return; -} -#endif // SIservicePtr; -typedef boost::shared_ptr - SIservicePtr; +// FIXME not needed +typedef boost::shared_ptr SIservicePtr; typedef std::map > MySIservicesOrderUniqueKey; static MySIservicesOrderUniqueKey mySIservicesOrderUniqueKey; @@ -1300,434 +1165,10 @@ static MySIservicesOrderUniqueKey mySIservicesOrderUniqueKey; typedef std::map > MySIservicesNVODorderUniqueKey; static MySIservicesNVODorderUniqueKey mySIservicesNVODorderUniqueKey; -// Hier sollte man die hash-funktion fuer strings der stl benutzen -// Muss mal schauen ob es die auch fuer 'ignore_case' gibt /* -struct OrderServiceName -{ - bool operator()(const SIservicePtr &p1, const SIservicePtr &p2) - { - return strcasecmp(p1->serviceName.c_str(), p2->serviceName.c_str()) < 0; - } -}; - -typedef std::set MySIservicesOrderServiceName; -static MySIservicesOrderServiceName mySIservicesOrderServiceName; -*/ -#ifdef UPDATE_NETWORKS -xmlNodePtr findBouquetByName(xmlDocPtr parser,char *name) -{ - xmlNodePtr bouquet = NULL; - if (parser) - bouquet = xmlDocGetRootElement(parser)->xmlChildrenNode; - else { - dprintf("Bouquet parsing failed!\n"); - return NULL; - } - while (xmlGetNextOccurence(bouquet, "Bouquet") != NULL) { - if ((xmlGetNumericAttribute(bouquet, "type", 8) == 2) && - (strcmp(xmlGetAttribute(bouquet, "name"), name) == 0)) - return bouquet; - bouquet = bouquet->xmlNextNode; - } - return NULL; -} - -static BouquetAdder* getNextAutoBouquet(BouquetAdder *currentAdder, const char *provname, - const t_original_network_id onid, const t_transport_stream_id tsid, - const t_service_id sid) -{ - bool found = false; - BouquetAdderEntry *currentEntry = NULL; - ExceptService *excepts = NULL; - - while ((currentAdder) && (!found)) { - currentEntry = currentAdder->bae; - while ((currentEntry) && (!found)) { - if ( ((strcmp(currentEntry->ProviderName, provname) == 0) || - ((strcmp(currentEntry->ProviderName, "") == 0))) && - ((currentEntry->onid == onid) || (currentEntry->onid == 0)) && - ((currentEntry->tsid == tsid) || (currentEntry->tsid == 0)) ) - found = true; - excepts = currentEntry->es; - while ((excepts) && (found)) { - if (excepts->sid == sid) - found = false; - excepts = excepts->next; - } - currentEntry = currentEntry->next; - } - if (!found) - currentAdder = currentAdder->next; - } - return currentAdder; -} - -static bool bouquetContainsService(const xmlNodePtr bouquet, const t_original_network_id onid, - const t_transport_stream_id tsid, const t_service_id sid) -{ - if (!bouquet) - return false; - - xmlNodePtr channel = NULL; - - channel = bouquet->xmlChildrenNode; - while (channel) { - if ((xmlGetNumericAttribute(channel, "onid", 16) == onid) && - (xmlGetNumericAttribute(channel, "tsid", 16) == tsid) && - (xmlGetNumericAttribute(channel, "serviceID", 16) == sid)) - return true; - channel = channel->xmlNextNode; - } - return false; -} - -static void write_bouquet_xml_header(FILE * fd) -{ - fprintf(fd, - "\n" - "\n" - "\n"); -} - -static void write_bouquet_xml_footer(FILE *fd) -{ - fprintf(fd, "\n"); -} - -//stolen from zapitools.cpp -std::string UTF8_to_UTF8XML(const char * s) -{ - std::string r; - - while ((*s) != 0) - { - /* cf. - * http://www.w3.org/TR/2004/REC-xml-20040204/#syntax - * and - * http://www.w3.org/TR/2004/REC-xml-20040204/#sec-predefined-ent - */ - switch (*s) - { - case '<': - r += "<"; - break; - case '>': - r += ">"; - break; - case '&': - r += "&"; - break; - case '\"': - r += """; - break; - case '\'': - r += "'"; - break; - default: - r += *s; - } - s++; - } - return r; -} - -static void writebouquetwithoutend(FILE *fd, xmlNodePtr bouquet) -{ - std::string name; - - name = xmlGetAttribute(bouquet, "name"); - - fprintf(fd, "\t\n"); - bouquet2 = bouquet2->xmlNextNode; - } - if (!bouquet_found) { - fprintf(dst, "\t\n"); - } - } - else { - if (bouquet) - writebouquetwithoutend(dst, bouquet); - else - fprintf(dst, "\t\n"); - } - write_bouquet_xml_footer(dst); - returnvalue = true; - fclose(dst); - rename(CURRENTBOUQUETS_TMP, CURRENTBOUQUETS_XML); - } - } - } - currentBouquet = currentBouquet->next; - currentBouquet = getNextAutoBouquet(currentBouquet, provname, onid, tsid, sid); - } - - return returnvalue; -} - -// Fuegt ein Service in alle Mengen ein -static bool addService(const SIservice &s, const int is_actual) -{ - bool already_exists; - bool is_new = false; - - //if (mySIservicesNVODorderUniqueKey.find(s.uniqueKey())) - readLockServices(); - MySIservicesOrderUniqueKey::iterator si = mySIservicesOrderUniqueKey.find(s.uniqueKey()); - already_exists = (si != mySIservicesOrderUniqueKey.end()); - unlockServices(); - - if ( (!already_exists) || ((is_actual & 7) && (!si->second->is_actual)) ) { - - if (already_exists) - { - writeLockServices(); - mySIservicesOrderUniqueKey.erase(s.uniqueKey()); - unlockServices(); - } - - SIservice *sp = new SIservice(s); - - if (!sp) - { - printf("[sectionsd::addService] new SIservice failed.\n"); - return false; - //throw std::bad_alloc(); - } - - SIservicePtr sptr(sp); - - // Leere Servicenamen in ServiceID in hex umbenennen -#define MAX_SIZE_SERVICENAME 50 - char servicename[MAX_SIZE_SERVICENAME]; - - if (sptr->serviceName.empty()) { - sprintf(servicename, "%04x", sptr->service_id); - servicename[sizeof(servicename) - 1] = 0; - sptr->serviceName = servicename; - } - - sptr->is_actual = is_actual; - - writeLockServices(); - mySIservicesOrderUniqueKey.insert(std::make_pair(sptr->uniqueKey(), sptr)); - unlockServices(); - - if (sptr->nvods.size()) - { - writeLockServices(); - mySIservicesNVODorderUniqueKey.insert(std::make_pair(sptr->uniqueKey(), sptr)); - unlockServices(); - } - // if(sptr->serviceID==0x01 || sptr->serviceID==0x02 || sptr->serviceID==0x04) -// mySIservicesOrderServiceName.insert(sptr); - is_new = true; - } - - return is_new; -} - -// SIsPtr; -typedef boost::shared_ptr - SIbouquetPtr; - -typedef std::map > MySIbouquetsOrderUniqueKey; -static MySIbouquetsOrderUniqueKey mySIbouquetsOrderUniqueKey; - -// Fuegt einen BouquetEntry in alle Mengen ein -static int addBouquetEntry(const SIbouquet &s/*, int section_nr, int count*/) -{ - bool already_exists; - uint16_t bouquet_id = 0; - - //s.position = (uint16_t) (((section_nr & 0x1f) << 11) + (count & 0x7ff)); - - //if (mySIservicesNVODorderUniqueKey.find(s.uniqueKey())) - readLockBouquets(); - MySIbouquetsOrderUniqueKey::iterator si = mySIbouquetsOrderUniqueKey.find(s.uniqueKey()); - already_exists = (si != mySIbouquetsOrderUniqueKey.end()); - - if (!already_exists) { - - SIbouquet *bp = new SIbouquet(s); - - if (!bp) - { - printf("[sectionsd::addBouquetEntry] new SIbouquet failed.\n"); - unlockBouquets(); - throw std::bad_alloc(); - } - - SIbouquetPtr bpptr(bp); - /* - bpptr->position = (uint16_t) (((section_nr & 0x1f) << 11) + (number & 0x7ff)); - - printf("Section Number: %d Count: %d position: %04x\n", section_nr, number, bpptr->position); - */ - unlockBouquets(); - writeLockBouquets(); - mySIbouquetsOrderUniqueKey.insert(std::make_pair(bpptr->uniqueKey(), bpptr)); - - //Because of Bouquet_Id misuse. see SIsections.cpp. IDs are introduced there - if ((bpptr->bouquet_id == 0x3ffe) || (bpptr->bouquet_id == 0x3fff)) - bouquet_id = bpptr->bouquet_id; - else - bouquet_id = 0; - - } - unlockBouquets(); - return bouquet_id << 1 | (int) !already_exists; -} - -/* - * * communication with sectionsdclient: - * */ -// SIsPtr; -typedef boost::shared_ptr - SInetworkPtr; - -typedef std::map > MySItranspondersOrderUniqueKey; -static MySItranspondersOrderUniqueKey mySItranspondersOrderUniqueKey; - -// Fuegt einen Tranponder in alle Mengen ein -static bool addTransponder(const SInetwork &s, const bool is_actual) -{ - readLockTransponders(); - MySItranspondersOrderUniqueKey::iterator si = mySItranspondersOrderUniqueKey.find(s.uniqueKey()); - bool already_exists = (si != mySItranspondersOrderUniqueKey.end()); - - if (!already_exists) { - - SInetwork *nw = new SInetwork(s); - - if (!nw) - { - printf("[sectionsd::updateNetwork] new SInetwork failed.\n"); - unlockTransponders(); - throw std::bad_alloc(); - } - - SInetworkPtr tpptr(nw); - - tpptr->is_actual = is_actual; - - unlockTransponders(); - writeLockTransponders(); - mySItranspondersOrderUniqueKey.insert(std::make_pair(tpptr->uniqueKey(), tpptr)); - } - unlockTransponders(); - return !already_exists; -} -#endif inline bool readNbytes(int fd, char *buf, const size_t numberOfBytes, const time_t timeoutInSeconds) { timeval timeout; @@ -1748,33 +1189,6 @@ inline bool writeNbytes(int fd, const char *buf, const size_t numberOfBytes, co //------------------------------------------------------------ // misc. functions //------------------------------------------------------------ -/* -static t_channel_id findServiceUniqueKeyforServiceName(const char * const serviceName) -{ - SIservice *sp = new SIservice(0, 0, 0); - - if (!sp) - { - printf("[sectionsd::findServiceUniqueKeyforServiceName] new SIservice failed.\n"); - throw std::bad_alloc(); - } - - SIservicePtr s(sp); - - s->serviceName = serviceName; - - dprintf("Search for Service '%s'\n", serviceName); - - MySIservicesOrderServiceName::iterator si = mySIservicesOrderServiceName.find(s); - - if (si != mySIservicesOrderServiceName.end()) - return (*si)->uniqueKey(); - - dputs("Service not found"); - - return 0; -} -*/ static const SIevent& findSIeventForEventUniqueKey(const event_id_t eventUniqueKey) { // Event (eventid) suchen @@ -2118,10 +1532,6 @@ static void commandPauseScanning(int connfd, char *data, const unsigned dataLeng #ifdef ENABLE_FREESATEPG dmxFSEIT.request_pause(); #endif -#ifdef UPDATE_NETWORKS - dmxNIT.request_pause(); - dmxSDT.request_pause(); -#endif #ifdef ENABLE_PPT dmxPPT.request_pause(); #endif @@ -2130,10 +1540,6 @@ static void commandPauseScanning(int connfd, char *data, const unsigned dataLeng else if (!pause && !scanning) { dmxCN.request_unpause(); -#ifdef UPDATE_NETWORKS - dmxNIT.request_unpause(); - dmxSDT.request_unpause(); -#endif dmxEIT.request_unpause(); #ifdef ENABLE_FREESATEPG dmxFSEIT.request_unpause(); @@ -2722,27 +2128,6 @@ static t_transponder_id messaging_sdt_other_sections_got_all [MAX_OTHER_SDT]; static bool messaging_sdt_other_sections_so_far [MAX_CONCURRENT_OTHER_SDT] [MAX_SECTIONS]; // 0x46 static t_transponder_id messaging_sdt_other_tid [MAX_CONCURRENT_OTHER_SDT]; // 0x46 */ -#ifdef UPDATE_NETWORKS -static int messaging_bat_last_section [MAX_BAT]; // 0x4A -static int messaging_bat_sections_so_far [MAX_BAT] [MAX_SECTIONS]; // 0x4A -static t_bouquet_id messaging_bat_bouquet_id [MAX_BAT]; // 0x4A - -//static bool sdt_backoff = true; -//static bool new_services = false; -/* -static bool nit_backoff = true; -static bool messaging_nit_actual_sections_got_all; // 0x40 -static bool messaging_nit_actual_sections_so_far [MAX_SECTIONS]; // 0x40 -static t_network_id messaging_nit_other_sections_got_all [MAX_OTHER_NIT]; // 0x41 -static bool messaging_nit_other_sections_so_far [MAX_CONCURRENT_OTHER_NIT] [MAX_SECTIONS]; // 0x41 -static t_network_id messaging_nit_other_nid [MAX_CONCURRENT_OTHER_NIT]; // 0x41 -*/ -/* nessaging_nit_nid does not need locking, because it is only used in one thread (nit thread). */ -static t_network_id messaging_nit_nid[MAX_NIDs]; // 0x40,0x41 -/* nessaging_sdt_tid does not need locking, because it is only used in one thread (sdt thread). */ -static t_transponder_id messaging_sdt_tid[MAX_SDTs]; // 0x42,0x46 -static int auto_scanning = 0; -#endif std::string epg_dir(""); static void commandserviceChanged(int connfd, char *data, const unsigned dataLength) @@ -2763,10 +2148,6 @@ static void commandserviceChanged(int connfd, char *data, const unsigned dataLen channel_is_blacklisted = true; dmxCN.request_pause(); dmxEIT.request_pause(); -#ifdef UPDATE_NETWORKS - dmxNIT.request_pause(); - dmxSDT.request_pause(); -#endif #ifdef ENABLE_PPT dmxPPT.request_pause(); #endif @@ -2779,10 +2160,6 @@ static void commandserviceChanged(int connfd, char *data, const unsigned dataLen channel_is_blacklisted = false; dmxCN.request_unpause(); dmxEIT.request_unpause(); -#ifdef UPDATE_NETWORKS - dmxNIT.request_unpause(); - dmxSDT.request_unpause(); -#endif #ifdef ENABLE_PPT dmxPPT.request_unpause(); #endif @@ -2824,14 +2201,6 @@ static void commandserviceChanged(int connfd, char *data, const unsigned dataLen messaging_have_CN = 0x00; messaging_got_CN = 0x00; messaging_zap_detected = true; -#ifdef UPDATE_NETWORKS - for ( int i = 0; i < MAX_BAT; i++) { - messaging_bat_bouquet_id[i] = 0; - messaging_bat_last_section[i] = 0; - for ( int j= 0; j < MAX_SECTIONS; j++) - messaging_bat_sections_so_far[i][j] = 0; - } -#endif messaging_need_eit_version = false; unlockMessaging(); dmxCN.setCurrentService(messaging_current_servicekey & 0xffff); @@ -3989,40 +3358,12 @@ out: } #endif -#ifdef UPDATE_NETWORKS -static void commandSetSectionsdScanMode(int connfd, char *data, const unsigned dataLength) -{ - if (dataLength != 4) - goto out; - - writeLockMessaging(); - auto_scanning = *((int*)data); - unlockMessaging(); - -out: - struct sectionsd::msgResponseHeader responseHeader; - responseHeader.dataLength = 0; - - writeNbytes(connfd, (const char *)&responseHeader, sizeof(responseHeader), WRITE_TIMEOUT_IN_SECONDS); - return ; - -} -#endif - static void commandSetConfig(int connfd, char *data, const unsigned /*dataLength*/) { struct sectionsd::msgResponseHeader responseHeader; struct sectionsd::commandSetConfig *pmsg; pmsg = (struct sectionsd::commandSetConfig *)data; -#ifdef UPDATE_NETWORKS - if (pmsg->scanMode != auto_scanning) { - dprintf("new scanMode = %d\n", pmsg->scanMode); - writeLockMessaging(); - auto_scanning = pmsg->scanMode; - unlockMessaging(); - } -#endif if (secondsToCache != (long)(pmsg->epg_cache)*24*60L*60L) { dprintf("new epg_cache = %d\n", pmsg->epg_cache); @@ -4094,16 +3435,6 @@ static void deleteSIexceptEPG() writeLockServices(); mySIservicesOrderUniqueKey.clear(); unlockServices(); -#ifdef UPDATE_NETWORKS - writeLockTransponders(); - mySItranspondersOrderUniqueKey.clear(); - unlockTransponders(); - writeLockBouquets(); - mySIbouquetsOrderUniqueKey.clear(); - unlockBouquets(); - dmxNIT.dropCachedSectionIDs(); - dmxSDT.dropCachedSectionIDs(); -#endif dmxEIT.dropCachedSectionIDs(); } @@ -4700,11 +4031,7 @@ static s_cmd_table connectionCommands[sectionsd::numberOfCommands] = { #else { commandDummy2, "commandSetPrivatePid" }, #endif -#ifdef UPDATE_NETWORKS - { commandSetSectionsdScanMode, "commandSetSectionsdScanMode" }, -#else { commandDummy2, "commandSetSectionsdScanMode" }, -#endif { commandFreeMemory, "commandFreeMemory" }, { commandReadSIfromXML, "commandReadSIfromXML" }, { commandWriteSI2XML, "commandWriteSI2XML" }, @@ -4788,1650 +4115,12 @@ bool sectionsd_parse_command(CBasicMessage::Header &rmsg, int connfd) return true; } -#ifdef UPDATE_NETWORKS -xmlNodePtr GetProvider(xmlNodePtr provider, xmlNodePtr tp_node) -{ - xmlNodePtr found = NULL; - - while (provider && !found) - { - xmlNodePtr transponder = provider->xmlChildrenNode; - - while (transponder && !found) - { - if ( (xmlGetNumericAttribute(transponder, "id", 16) == xmlGetNumericAttribute(tp_node, "id", 16)) && - (xmlGetNumericAttribute(transponder, "onid", 16) == xmlGetNumericAttribute(tp_node, "onid", 16)) ) - found = provider; - else - transponder = transponder->xmlNextNode; - } - if (!found) - provider = provider->xmlNextNode; - } - return found; -} - -static void write_xml_header(FILE * fd) -{ - fprintf(fd, - "\n" - "\n" - "\n"); -} - -static void write_xml_footer(FILE *fd) -{ - fprintf(fd, "\n"); -} - -static void write_xml_provend(FILE *dst, const bool is_sat) -{ - if (is_sat) - fprintf(dst,"\t\n"); - else - fprintf(dst,"\t\n"); -} - -//Writes transponder entry or copies all existing tps of a provider. -static bool write_xml_transponder(FILE *src, FILE *dst, const xmlNodePtr tp_node, const bool is_sat, const bool copy) -{ -#define MAX_SIZE_TP_STR 256 - char tp_str[MAX_SIZE_TP_STR] = ""; - char buffer[256] = ""; - bool tp_existed = false; - if (is_sat) { - snprintf(tp_str, MAX_SIZE_TP_STR, "\t\t\n", - (t_transport_stream_id) xmlGetNumericAttribute(tp_node, "id", 16), - (t_original_network_id) xmlGetNumericAttribute(tp_node, "onid", 16), - (uint32_t) xmlGetNumericAttribute(tp_node, "frequency", 0), - (fe_spectral_inversion_t) xmlGetNumericAttribute(tp_node, "inversion", 0), - (uint32_t) xmlGetNumericAttribute(tp_node, "symbol_rate", 0), - (fe_code_rate_t) xmlGetNumericAttribute(tp_node, "fec_inner", 0), - (uint8_t) xmlGetNumericAttribute(tp_node, "polarization", 0)); - } - else { - snprintf(tp_str, MAX_SIZE_TP_STR, "\t\t\n", - (t_transport_stream_id) xmlGetNumericAttribute(tp_node, "id", 16), - (t_original_network_id) xmlGetNumericAttribute(tp_node, "onid", 16), - (uint32_t) xmlGetNumericAttribute(tp_node, "frequency", 0), - (fe_spectral_inversion_t) xmlGetNumericAttribute(tp_node, "inversion", 0), - (uint32_t) xmlGetNumericAttribute(tp_node, "symbol_rate", 0), - (fe_code_rate_t) xmlGetNumericAttribute(tp_node, "fec_inner", 0), - (fe_modulation_t) xmlGetNumericAttribute(tp_node, "modulation", 0)); - } - - if (!copy) - fprintf(dst, tp_str); - else { - if (!feof(src)) { - fgets(buffer, 255, src); - - if (is_sat) { - //find tp in currentservices.xml - while( (!feof(src)) && (strcmp(buffer, "\t\n") != 0) && (strcmp(buffer, tp_str) != 0) ) - { - fprintf(dst, buffer); - fgets(buffer, 255, src); - } - } - else { - while( (!feof(src)) && (strcmp(buffer, "\t\n") != 0) && (strcmp(buffer, tp_str) != 0) ) - { - fprintf(dst, buffer); - fgets(buffer, 255, src); - } - } - //If the Transponder alredy existed. This isn't reached at the moment because if the transponder - //didn't exist we don't call the update function. But maybe this is to be changed: - //We should save if the update came from SDT other and update it once again, if - //we find SDT ACTUAL. So we leave it here. Save could be done through another node SDT in - //currentservices.xml. Should be easy to realize... - if ( (!feof(src)) && (!strcmp(buffer, tp_str)) ) { - while( (!feof(src)) && (strcmp(buffer, "\t\t\n") != 0) ) { - tp_existed = true; - fgets(buffer, 255, src); - } - } - } - } - return tp_existed; -} - -//return true for sat, false for cable -//The function fulfills two purposes. It writes the correct provider entry (if copy = false) or it copies -//all data including the provider entry if it existed -//Otherwise it reads to the end signalling that it didn't find the provider -static bool write_xml_provider(FILE *src, FILE *dst, const xmlNodePtr provider, const bool copy) -{ -#define MAX_SIZE_PROV_STR 256 - char prov_str[MAX_SIZE_PROV_STR] = ""; - char buffer[256] = ""; - std::string frontendType; - std::string provider_name; - std::string diseqc; - bool is_sat = false; - int position = 0; - - frontendType = xmlGetName(provider); - provider_name = xmlGetAttribute(provider, "name"); - - if (!strcmp(frontendType.c_str(), "sat")) { - diseqc = xmlGetAttribute(provider, "diseqc"); - position = xmlGetSignedNumericAttribute(provider, "position", 16); - if (position == 0) - snprintf(prov_str, MAX_SIZE_PROV_STR, "\t<%s name=\"%s\" diseqc=\"%s\">\n", frontendType.c_str(), - provider_name.c_str(), diseqc.c_str()); - else { - //east_west = xmlGetNumericAttribute(provider, "east_west", 16); - snprintf(prov_str, MAX_SIZE_PROV_STR, "\t<%s name=\"%s\" position=\"%04x\" diseqc=\"%s\">\n", - frontendType.c_str(), - provider_name.c_str(), - position, - //east_west, - diseqc.c_str()); - } - is_sat = true; - } - else { - snprintf(prov_str, MAX_SIZE_PROV_STR, "\t<%s name=\"%s\">\n", frontendType.c_str(), provider_name.c_str()); - is_sat = false; - } - - if (!copy) - fprintf(dst, prov_str); - else { - if (!feof(src)) { - fgets(buffer, 255, src); - //find prov in currentservices.xml - while( (!feof(src)) && (strcmp(buffer, "\n") != 0) && (strcmp(buffer, prov_str) != 0) ) - { - fprintf(dst, buffer); - fgets(buffer, 255, src); - } - if (strcmp(buffer, prov_str) != 0) { - while (!feof(src)) - fgets(buffer, 255, src); -// printf("reading to the end!\n"); - } else - fprintf(dst, buffer); - } - } - - return is_sat; -} - -//Determines which action (none, add, replace) should be taken for current service -//This funtion considers the entry scanType in scan.conf. -static int get_action(const xmlNodePtr tp_node, const MySIservicesOrderUniqueKey::iterator s, const int scanType) -{ - //And now node points to transponders channels first entry - xmlNodePtr node = tp_node->xmlChildrenNode; - std::string name; - - if ( ((s->second->serviceTyp == 1) && (scanType == 1)) || - ((s->second->serviceTyp == 2) && (scanType == 2)) || - (((s->second->serviceTyp == 1) || (s->second->serviceTyp == 2)) && (scanType == 0)) || - (scanType == 3) ) { - - while (xmlGetNextOccurence(node, "channel") != NULL) { - if (s->second->service_id == xmlGetNumericAttribute(node, "service_id", 16)) { - name = xmlGetAttribute(node, "name"); - if ( (s->second->serviceTyp == xmlGetNumericAttribute(node, "service_type", 16)) && - (!strcmp(s->second->serviceName.c_str(), name.c_str())) ) { - dprintf("[sectionsd] Service %s okay\n", name.c_str()); - return 0; //service okay - } - else { - if (s->second->is_actual & 7) { - dprintf("[sectionsd] Replacing Service %s\n", name.c_str()); - return 2; //replace - } - else { - dprintf("[sectionsd] Service %s changed but signalled from SDT_Other\n", name.c_str()); - return 0; //service not okay, but came from SDT_OTHER - we can't truly trust - } - } - } - node = node->xmlNextNode; - } - dprintf("[sectionsd] Adding Service %s\n", s->second->serviceName.c_str()); - return 1; //add - } - return 0; //scanType didn't match do not handle in any case -} - -//This updates the /tmp/currentservices.xml with the differences between services.xml and SDT content -//It contains two loops. Each is nested. First loop adds and replaces the services which are new in the SDT -//The second loop removes Services which are in services.xml and not in the SDT anymore. -//Returns true if the transponder needs to be updated -bool updateCurrentXML(xmlNodePtr provider, xmlNodePtr tp_node, const int scanType, const bool /*is_current*/) -{ - bool is_needed = false; - bool newprov = false; - bool is_sat = false; - bool tp_existed = false; - - std::string name; - - FILE * src = NULL; - FILE * dst = NULL; - char buffer[256] = ""; - - readLockServices(); - for (MySIservicesOrderUniqueKey::iterator s = mySIservicesOrderUniqueKey.begin(); s != mySIservicesOrderUniqueKey.end(); s++) - { - unlockServices(); - readLockMessaging(); - if (messaging_zap_detected) { - unlockMessaging(); - return false; - } - unlockMessaging(); - if ( (s->second->transport_stream_id == xmlGetNumericAttribute(tp_node, "id", 16)) && - (s->second->original_network_id == xmlGetNumericAttribute(tp_node, "onid", 16)) ) - { - int action = get_action(tp_node, s, scanType); - - if (action > 0) { - if (!is_needed) { - is_needed = true; - //create new currentservices - if (!(dst = fopen(CURRENTSERVICES_TMP, "w"))) { - dprintf("unable to open %s for writing\n", CURRENTSERVICES_TMP); - return false; - } - if (!(src = fopen(CURRENTSERVICES_XML, "r"))) { - //if currentservices doesn't yet exist - newprov = true; - write_xml_header(dst); - is_sat = write_xml_provider(src, dst, provider, false); - } else { - //if it exists. copy till provider - is_sat = write_xml_provider(src, dst, provider, true); - //if eof provider didn't exist - if (feof(src)) { - newprov = true; - write_xml_provider(src, dst, provider, false); - } - else - //copy all transponders belonging to current prov - tp_existed = write_xml_transponder(src, dst, tp_node, is_sat, true); - } - // write new transponder node - write_xml_transponder(src, dst, tp_node, is_sat, false); - } - //check which action is necessary for current service - //0 = nothing / 1 = add / 2 = replace - switch (action) - { - case 1: - fprintf(dst, - "\t\t\t\n", - "add", - s->second->service_id, - UTF8_to_UTF8XML(s->second->serviceName.c_str()).c_str(), - s->second->serviceTyp); - break; - case 2: - fprintf(dst, - "\t\t\t\n", - "replace", - s->second->service_id, - UTF8_to_UTF8XML(s->second->serviceName.c_str()).c_str(), - s->second->serviceTyp); - break; - default: - break; - } - - } - } - readLockServices(); - } - unlockServices(); - //Second loop to detect services which are not longer in SDT - //Only remove if Actual SDT. This could be changed, if all providers would send correct data - //It is pretty much the same as the first loop. Check there. Later: merge them together? - readLockServices(); - MySIservicesOrderUniqueKey::iterator s = mySIservicesOrderUniqueKey.begin(); - if (s->second->is_actual == 2) { - xmlNodePtr node = tp_node->xmlChildrenNode; - - while (xmlGetNextOccurence(node, "channel") != NULL) { - - readLockMessaging(); - if (messaging_zap_detected) { - unlockMessaging(); - return false; - } - unlockMessaging(); - - s = mySIservicesOrderUniqueKey.begin(); - while ( (s != mySIservicesOrderUniqueKey.end()) && - (s->second->service_id != xmlGetNumericAttribute(node, "service_id", 16)) ) - s++; - if (s == mySIservicesOrderUniqueKey.end()) { - if (!is_needed) { - - is_needed = true; - //create new currentservices - if (!(dst = fopen(CURRENTSERVICES_TMP, "w"))) { - dprintf("unable to open %s for writing\n", CURRENTSERVICES_TMP); - unlockServices(); - return false; - } - if (!(src = fopen(CURRENTSERVICES_XML, "r"))) { - newprov = true; - write_xml_header(dst); - is_sat = write_xml_provider(src, dst, provider, false); - } else { - - is_sat = write_xml_provider(src, dst, provider, true); - if (feof(src)) { - newprov = true; - write_xml_provider(src, dst, provider, false); - } - tp_existed = write_xml_transponder(src, dst, tp_node, is_sat, true); - } - write_xml_transponder(src, dst, tp_node, is_sat, false); - } - name = xmlGetAttribute(node, "name"); - - dprintf("[sectionsd] Removing Service %s\n", name.c_str()); - fprintf(dst, - "\t\t\t\n", - "remove", - xmlGetNumericAttribute(node, "service_id", 16), - UTF8_to_UTF8XML(name.c_str()).c_str(), - xmlGetNumericAttribute(node, "service_type", 16)); - } - node = node->xmlNextNode; - } - } - - unlockServices(); - - //If we chnged some services write the closing tags. - if (is_needed) { - - fprintf(dst,"\t\t\n"); - - if (!tp_existed) - write_xml_provend(dst, is_sat); - - if (newprov) { - write_xml_footer(dst); - } - else { - fgets(buffer, 255, src); - while(!feof(src)) - { - fprintf(dst, buffer); - fgets(buffer, 255, src); - } - fclose(src); - } - - fclose(dst); - } - - return is_needed; -} - -xmlNodePtr getProviderFromSatellitesXML(xmlNodePtr node, const int position) -{ - struct stat buf; - const char *filename = ZAPITCONFIGDIR "/" SATELLITES_XML; - if ((stat(filename, &buf) == -1) && (errno == ENOENT)) - filename = DATADIR "/" SATELLITES_XML; - - xmlDocPtr satellites_parser = parseXmlFile(filename); - if (satellites_parser == NULL) - return NULL; - xmlNodePtr satellite = xmlDocGetRootElement(satellites_parser)->xmlChildrenNode; - while (satellite) { - if (xmlGetSignedNumericAttribute(satellite, "position", 16) == position) { - while (node) { - if (!strcmp(xmlGetAttribute(satellite, "name"), xmlGetAttribute(node, "name"))) - { - xmlFreeDoc(satellites_parser); - return node; - } - node = node->xmlNextNode; - } - } - satellite = satellite->xmlNextNode; - } - xmlFreeDoc(satellites_parser); - return NULL; -} - -xmlNodePtr getProviderbyName(xmlNodePtr current_provider, xmlNodePtr provider) { - while (current_provider) { - if (!strcmp(xmlGetAttribute(current_provider, "name"), xmlGetAttribute(provider, "name"))) - return current_provider; - current_provider = current_provider->xmlNextNode; - } - return NULL; -} - -xmlNodePtr findTransponderFromProv(xmlNodePtr transponder, const t_original_network_id onid, const t_transport_stream_id tsid) { - while (transponder) { - if ((xmlGetNumericAttribute(transponder, "onid", 16) == onid) && (xmlGetNumericAttribute(transponder, "id", 16) == tsid)) - return transponder; - transponder = transponder->xmlNextNode; - } - return NULL; -} - -//SDT-Thread calls this function if it found a complete Service Description Table (SDT). Overwrite for actual = true - for other = false -//static bool updateTP(const t_original_network_id onid, const t_transport_stream_id tsid, const int scanType, const bool overwrite) -static bool updateTP(const int scanType) -{ - xmlDocPtr service_parser = parseXmlFile(SERVICES_XML); - xmlDocPtr current_parser = NULL; - bool need_update = false; - FILE * tmp = NULL; - xmlNodePtr provider = NULL; - xmlNodePtr current_provider = NULL; - t_transport_stream_id tsid = 0; - t_original_network_id onid = 0; - - if (service_parser == NULL) - return false; - - int i = 0; - while ((i < MAX_SDTs) && (messaging_sdt_tid[i] != 0)) { - readLockMessaging(); - if (messaging_zap_detected) { - unlockMessaging(); - need_update = false; - if (current_parser != NULL) - xmlFreeDoc(current_parser); - unlink(CURRENTSERVICES_TMP); - break; - } - unlockMessaging(); - onid = (t_original_network_id) (messaging_sdt_tid[i] >> 16) & 0xffff; - tsid = (t_transport_stream_id) messaging_sdt_tid[i] & 0xffff; - -//GET_ORIGINAL_NETWORK_ID_FROM_CHANNEL_ID(channel_id) ((t_original_network_id)((channel_id) >> 16)) -//GET_SERVICE_ID_FROM_CHANNEL_ID(channel_id) ((t_service_id)(channel_id)) - - xmlNodePtr services_tp = FindTransponder(xmlDocGetRootElement(service_parser)->xmlChildrenNode, onid, tsid); - - if (services_tp) - provider = GetProvider(xmlDocGetRootElement(service_parser)->xmlChildrenNode, services_tp); - else - provider = NULL; - - tmp = fopen(CURRENTSERVICES_XML, "r"); - if (tmp) { - fclose(tmp); - current_parser= parseXmlFile(CURRENTSERVICES_XML); - } - - xmlNodePtr current_tp = NULL; - - if (current_parser != NULL) { - current_tp = FindTransponder(xmlDocGetRootElement(current_parser)->xmlChildrenNode, onid, tsid); - if (provider) { - //printf("getProvbyname\n"); - current_provider = getProviderbyName(xmlDocGetRootElement(current_parser)->xmlChildrenNode, provider); - - } - else { - if (current_tp) - current_provider = GetProvider(xmlDocGetRootElement(current_parser)->xmlChildrenNode, current_tp); - } - } - - if (!current_tp) { - if (provider) { - if (current_provider) { - //printf("update with current\n"); - if (!strcmp(xmlGetAttribute(current_provider, "name"), xmlGetAttribute(provider, "name"))) - if (updateCurrentXML(current_provider, services_tp, scanType, false)) - need_update = true; - - } - else { - //printf("update with prov\n"); - if (updateCurrentXML(provider, services_tp, scanType, false)) - need_update = true; - - } - } - else - dprintf("[sectionsd] No Transponder with ONID: %04x TSID: %04x found in services.xml!\n", onid, tsid); - } - else { - if (!provider) { - //printf("update with current / current\n"); - - if (updateCurrentXML(current_provider, current_tp, scanType, false)) - need_update = true; - - } - else - dprintf("[sectionsd] No Update needed for Transponder with ONID: %04x TSID: %04x!\n", onid, tsid); - } - if (current_parser != NULL) - xmlFreeDoc(current_parser); - current_parser = NULL; - - i++; - } - - xmlFreeDoc(service_parser); - - if (need_update) - { - rename(CURRENTSERVICES_TMP, CURRENTSERVICES_XML); - - dprintf("[sectionsd] We updated at least one Transponder in currentservices.xml!\n"); - - } else - dprintf("[sectionsd] No new services found!\n"); -//printf("Finishing updateTP\n"); - return need_update; -} -//stolen from frontend.cpp please fix. -fe_code_rate_t getCodeRate(const uint8_t fec_inner) -{ - switch (fec_inner & 0x0F) { - case 0x01: - return FEC_1_2; - case 0x02: - return FEC_2_3; - case 0x03: - return FEC_3_4; - case 0x04: - return FEC_5_6; - case 0x05: - return FEC_7_8; - case 0x0F: - return FEC_NONE; - default: - return FEC_AUTO; - } -} -//also stolen from frontend.cpp. please fix. -fe_modulation_t getModulation(const uint8_t modulation) -{ - switch (modulation) { - case 0x00: - return QPSK; - case 0x01: - return QAM_16; - case 0x02: - return QAM_32; - case 0x03: - return QAM_64; - case 0x04: - return QAM_128; - case 0x05: - return QAM_256; - default: -#if 1 - return QAM_AUTO; -#else - // i do not know how to do it correctly for old API -- seife - return QAM_256; -#endif - } -} - -static void writeTransponderFromDescriptor(FILE *dst, const t_original_network_id onid, const t_transport_stream_id tsid, const char *ddp, const bool is_sat) -{ - struct satellite_delivery_descriptor *sdd; - struct cable_delivery_descriptor *cdd; - - if (is_sat) { - sdd = (struct satellite_delivery_descriptor *)ddp; - fprintf(dst,"\t\t\n", - tsid, - onid, - ((sdd->frequency_1 >> 4) * 100000000) + - ((sdd->frequency_1 & 0x0F) * 10000000) + - ((sdd->frequency_2 >> 4) * 1000000) + - ((sdd->frequency_2 & 0x0F) * 100000) + - ((sdd->frequency_3 >> 4) * 10000) + - ((sdd->frequency_3 & 0x0F) * 1000) + - ((sdd->frequency_4 >> 4) * 100) + - ((sdd->frequency_4 & 0x0F) * 10), -// sdd->modulation, - INVERSION_AUTO, - ((sdd->symbol_rate_1 >> 4) * 100000000) + - ((sdd->symbol_rate_1 & 0x0F) * 10000000) + - ((sdd->symbol_rate_2 >> 4) * 1000000) + - ((sdd->symbol_rate_2 & 0x0F) * 100000) + - ((sdd->symbol_rate_3 >> 4) * 10000) + - ((sdd->symbol_rate_3 & 0x0F) * 1000) + - ((sdd->symbol_rate_4 >> 4) * 100), - (fe_code_rate_t) getCodeRate(sdd->fec_inner & 0x0F), - sdd->polarization); - } - else { - cdd = (struct cable_delivery_descriptor *)ddp; - fprintf(dst,"\t\t\n", - tsid, - onid, - ((cdd->frequency_1 >> 4) * 1000000000) + - ((cdd->frequency_1 & 0x0F) * 100000000) + - ((cdd->frequency_2 >> 4) * 10000000) + - ((cdd->frequency_2 & 0x0F) * 1000000) + - ((cdd->frequency_3 >> 4) * 100000) + - ((cdd->frequency_3 & 0x0F) * 10000) + - ((cdd->frequency_4 >> 4) * 1000) + - ((cdd->frequency_4 & 0x0F) * 100), -// cdd->fec_outer, - INVERSION_AUTO, - ((cdd->symbol_rate_1 >> 4) * 100000000) + - ((cdd->symbol_rate_1 & 0x0F) * 10000000) + - ((cdd->symbol_rate_2 >> 4) * 1000000) + - ((cdd->symbol_rate_2 & 0x0F) * 100000) + - ((cdd->symbol_rate_3 >> 4) * 10000) + - ((cdd->symbol_rate_3 & 0x0F) * 1000) + - ((cdd->symbol_rate_4 >> 4) * 100), - (fe_code_rate_t) getCodeRate(cdd->fec_inner & 0x0F), - (fe_modulation_t) getModulation(cdd->modulation)); - } - fprintf(dst,"\t\t\n"); -} - -static void updateXMLnet(xmlNodePtr provider, const t_original_network_id onid, const t_transport_stream_id tsid, - const char *ddp, const int position) -{ - FILE * src = NULL; - FILE * dst = NULL; - bool is_new = false; - bool is_sat = false; - -#define MAX_SIZE_PROV_STR 256 - char prov_str_neu[MAX_SIZE_PROV_STR] = ""; - char buffer[256] = ""; - - std::string frontendType; - std::string provider_name; - std::string diseqc; - - if (!(dst = fopen(CURRENTSERVICES_TMP, "w"))) { - dprintf("unable to open %s for writing\n", CURRENTSERVICES_TMP); - return; - } - - frontendType = xmlGetName(provider); - provider_name = xmlGetAttribute(provider, "name"); - - if (!strcmp(frontendType.c_str(), "sat")) { - diseqc = xmlGetAttribute(provider, "diseqc"); - snprintf(prov_str_neu, MAX_SIZE_PROV_STR, "\t<%s name=\"%s\" position=\"%04x\" diseqc=\"%s\">\n", frontendType.c_str(), provider_name.c_str(), - position, diseqc.c_str()); - is_sat = true; - } - else { - snprintf(prov_str_neu, MAX_SIZE_PROV_STR, "\t<%s name=\"%s\">\n", frontendType.c_str(), provider_name.c_str()); - is_sat = false; - } - - if (!(src = fopen(CURRENTSERVICES_XML, "r"))) { - is_new = true; - write_xml_header(dst); - fprintf(dst, prov_str_neu); - if (ddp != NULL) - writeTransponderFromDescriptor(dst, onid, tsid, ddp, is_sat); - write_xml_provend(dst, is_sat); - write_xml_footer(dst); - } - else { - if (!feof(src)) { - fgets(buffer, 255, src); - //find prov in currentservices.xml - while( (!feof(src)) && (strcmp(buffer, "\n") != 0) && (strcmp(buffer, prov_str_neu) != 0) ) - { - fprintf(dst, buffer); - fgets(buffer, 255, src); - } - if (strcmp(buffer, prov_str_neu) != 0) - fprintf(dst, prov_str_neu); - if (ddp != NULL) { - while( (!feof(src)) && (strcmp(buffer, "\n") != 0) && - (strcmp(buffer, "\t\n") != 0) && (strcmp(buffer, "\t\n")) ) - { - fprintf(dst, buffer); - fgets(buffer, 255, src); - } - //if (strcmp(buffer, "\n") == 0) - writeTransponderFromDescriptor(dst, onid, tsid, ddp, is_sat); - } - if (strcmp(buffer, "\n") == 0) - write_xml_provend(dst, is_sat); - - while (!feof(src)) - { - fprintf(dst, buffer); - fgets(buffer, 255, src); - } - } - - fclose(src); - } - fclose(dst); - - rename(CURRENTSERVICES_TMP, CURRENTSERVICES_XML); - - return; -} - -static bool updateNetwork() -{ - t_transport_stream_id tsid; - t_original_network_id onid; - t_network_id network_id; - - int position = 0; - struct satellite_delivery_descriptor *sdd; - const char *ddp; - std::string frontendType; - - bool need_update = false; - bool needs_fix = false; - - xmlNodePtr provider; - xmlNodePtr tp; - - FILE * tmp; - - xmlDocPtr service_parser = parseXmlFile(SERVICES_XML); - - if (service_parser == NULL) - return false; - - xmlDocPtr current_parser = NULL; - xmlNodePtr current_tp = NULL; - xmlNodePtr current_provider = NULL; - - tmp = fopen(CURRENTSERVICES_XML, "r"); - if (tmp) { - fclose(tmp); - current_parser= parseXmlFile(CURRENTSERVICES_XML); - } - - int i = 0; - readLockMessaging(); - while ((i < MAX_NIDs) && (messaging_nit_nid[i] != 0) && (!messaging_zap_detected)) { - unlockMessaging(); - - network_id = messaging_nit_nid[i]; - - // go through all transpopnders currently cached by neutrino - I won't need them after this loop. They COULD be cleared. - for (MySItranspondersOrderUniqueKey::iterator s = mySItranspondersOrderUniqueKey.begin(); s != - mySItranspondersOrderUniqueKey.end(); s++) - { - readLockMessaging(); - if (messaging_zap_detected) { - unlockMessaging(); - break; - } - unlockMessaging(); - if (s->second->network_id == network_id) { - needs_fix = false; - tsid = s->second->transport_stream_id; - onid = s->second->original_network_id; - ddp = &s->second->delivery_descriptor[0]; - - //printf("Descriptor_type: %02x\n", s->second->delivery_type); - frontendType = xmlGetName(xmlDocGetRootElement(service_parser)->xmlChildrenNode); - switch (s->second->delivery_type) { - case 0x43: - if (!strcmp(frontendType.c_str(), "sat")) { - sdd = (struct satellite_delivery_descriptor *)ddp; - position = (sdd->orbital_pos_hi << 8) | sdd->orbital_pos_lo; - if (!sdd->west_east_flag) - position = -position; - provider = getProvbyPosition(xmlDocGetRootElement(service_parser)->xmlChildrenNode, position); - } - else { - provider = NULL; - position = 1000; - } - break; - case 0x44: - if (!strcmp(frontendType.c_str(), "cable")) { - provider = xmlDocGetRootElement(service_parser)->xmlChildrenNode; - position = 0; - } - else { - position = 1000; - provider = NULL; - } - break; - default: - position = 1000; - provider = NULL; - break; - } - - //provider with satellite position does not exist in services.xml - if ((!provider) && (position != 1000)) { - provider = getProviderFromSatellitesXML(xmlDocGetRootElement(service_parser)->xmlChildrenNode, position); - if (provider) - needs_fix = true; //backward compatibility - add position node - } - //provider also not found in satellites.xml... - if ((!provider) && (position != 1000)) { - if (current_parser != NULL) { - provider = getProvbyPosition(xmlDocGetRootElement(current_parser)->xmlChildrenNode, position); - } - } - //and finally provider not found in currentservices.xml - we give up - if (!provider) { - dprintf("[sectionsd::updateNetwork] Provider not found for Transponder ONID: %04x TSID: %04x.\n", onid, - tsid); - } - else { - //we found a valid provider node - tp = findTransponderFromProv(provider->xmlChildrenNode, onid, tsid); - if (!tp) { - dprintf("[sectionsd::updateNetwork] Transponder ONID: %04x TSID: %04x not found.\n", onid, tsid); - if (current_parser != NULL) { - - switch (s->second->delivery_type) { - case 0x43: //satellite descriptor - current_provider = - getProvbyPosition(xmlDocGetRootElement(current_parser)->xmlChildrenNode, - position); - break; - case 0x44: //cable - current_provider = xmlDocGetRootElement(current_parser)->xmlChildrenNode; - break; - default: - break; - } - if (current_provider) - current_tp = findTransponderFromProv(current_provider->xmlChildrenNode, onid, - tsid); - } - //write the new transponder to currentservices.xml - if (!current_tp) { - updateXMLnet(provider, onid, tsid, ddp, position); - xmlFreeDoc(current_parser); - current_parser= parseXmlFile(CURRENTSERVICES_XML); - } - - } else { - dprintf("[sectionsd::updateNetwork] Transponder ONID: %04x TSID: %04x found.\n", onid, tsid); - if ( (s->second->is_actual & 7) && (needs_fix) ) { - //if(!(tmp = fopen(CURRENTSERVICES_XML, "r"))) - if (current_parser == NULL) { - dprintf("[sectionsd::updateNetwork] services.xml provider needs update\n"); - updateXMLnet(provider, onid, tsid, NULL, position); - current_parser= parseXmlFile(CURRENTSERVICES_XML); - } - else { - current_provider = - getProvbyPosition(xmlDocGetRootElement(current_parser)->xmlChildrenNode, - position); - if (!current_provider) { - updateXMLnet(provider, onid, tsid, NULL, position); - xmlFreeDoc(current_parser); - current_parser= parseXmlFile(CURRENTSERVICES_XML); - } - } - } - } - } - } - //sleep(10); - } - i++; - readLockMessaging(); - } - unlockMessaging(); - if (current_parser != NULL) - xmlFreeDoc(current_parser); - xmlFreeDoc(service_parser); - - return need_update; -} - -xmlNodePtr findBouquet(xmlDocPtr parser,t_bouquet_id bouquet_id) -{ - xmlNodePtr bouquet = xmlDocGetRootElement(parser)->xmlChildrenNode; - while (xmlGetNextOccurence(bouquet, "Bouquet") != NULL) { - //printf("Checking: %04x\n", xmlGetNumericAttribute(bouquet, "bouquet_id", 16)); - if (xmlGetNumericAttribute(bouquet, "bouquet_id", 16) == bouquet_id) - return bouquet; - bouquet = bouquet->xmlNextNode; - } - return NULL; -} - -static bool compareBouquet(xmlNodePtr channel, t_bouquet_id bouquet_id) -{ - MySIbouquetsOrderUniqueKey::iterator s = mySIbouquetsOrderUniqueKey.begin(); - while (s != mySIbouquetsOrderUniqueKey.end()) { - if (s->second->bouquet_id == bouquet_id) { - if (channel) { - if ( (xmlGetNumericAttribute(channel, "serviceID", 16) != s->second->service_id) || - (xmlGetNumericAttribute(channel, "tsid", 16) != s->second->transport_stream_id) || - (xmlGetNumericAttribute(channel, "onid", 16) != s->second->original_network_id) ) { - //printf("Service: %04x\n",s->second->service_id); - return true; - } - channel = channel->xmlNextNode; - } else - return true; - } - s++; - } - if ((!channel) && (s == mySIbouquetsOrderUniqueKey.end())) - return false; - else - return true; -} - -static void write_bouquet_xml_node(FILE *fd, t_bouquet_id bouquet_id) -{ - bool found = false; - - MySIbouquetsOrderUniqueKey::iterator s = mySIbouquetsOrderUniqueKey.begin(); - while ((!found) && (s != mySIbouquetsOrderUniqueKey.end())) { - if ((s->second->bouquet_id == bouquet_id) && (s->second->bouquetName.length() != 0)) - found = true; - else - s++; - } - if (found) - fprintf(fd, "\t